BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
calib_endcap_atten.cxx
Go to the documentation of this file.
1#include "tofcalgsec/calib_endcap_atten.h"
2#include "TF1.h"
3
4//Q fit function
5static double endcapQFunc(double *x, double *par) {
6 double xx = x[0];
7 double f = par[0] + par[1]*(xx-44.5) + par[2]*(xx-44.5)*(xx-44.5);
8
9 return f;
10}
11
12
14
15 nKind = 1; // pulse height
16 nBinPerCounter = nrbin + 1;
17
20 CanvasPerCounterName.push_back( static_cast<string>("Pulse Height Most Probable Value") );
21 CanvasPerCounterName.push_back( static_cast<string>("Pulse Height Sigma") );
22 nGraphPerCanvasPerCounter.push_back(1);
23 nGraphPerCanvasPerCounter.push_back(1);
24
25 nHistogram = 0;
26 nCanvas = 2;
27 CanvasName.push_back( static_cast<string>("Pulse Height Most Probable Value vs TOF Counter Number") );
28 CanvasName.push_back( static_cast<string>("Pulse Height Sigma vs TOF Counter Number") );
29 nGraphPerCanvas.push_back(1);
30 nGraphPerCanvas.push_back(1);
31
32 int numGraphs1 = 0;
33 std::vector<unsigned int>::iterator iter = nGraphPerCanvasPerCounter.begin();
34 for( ; iter!=nGraphPerCanvasPerCounter.end(); iter++ ) {
35 numGraphs1 = numGraphs1 + (*iter);
36 }
37 if( numGraphs1 != nGraphEcAtten ) {
38 cout << "tofcalgsec::calib_endcap_atten: the number of Graphs is NOT reasonable!!!" << endl;
39 exit(0);
40 }
41 int numGraphs2 = 0;
42 iter = nGraphPerCanvas.begin();
43 for( ; iter!=nGraphPerCanvas.end(); iter++ ) {
44 numGraphs2 = numGraphs2 + (*iter);
45 }
46 if( numGraphs2 != nGraphEcAtten ) {
47 cout << "tofcalgsec::calib_endcap_atten: the number of Graphs is NOT reasonable!!!" << endl;
48 exit(0);
49 }
50
51 m_name = string("calib_endcap_atten");
52
53 const int qbin = 100;
54 const double qbegin = 0.0;
55 const double qend = 5000.0;
56
57 // histograms per counter
58 char hname[256];
59 for( unsigned int i=0; i<NEndcap; i++ ) {
60 m_result.push_back( HepVector(nEndcapAtten,0) );
61 for( unsigned int k=0; k<nrbin; k++ ) {
62 sprintf( hname, "Q-id%i-r%i", i, k);
63 m_histograms.push_back( new TH1F( hname, hname, qbin, qbegin, qend ) );
64 m_fitresult.push_back( HepVector(nParEcAtten,0) );
65 }
66 sprintf( hname, "Q0-id%i", i );
67 m_histograms.push_back( new TH1F( hname, hname, qbin, qbegin, qend ) );
68 m_fitresult.push_back( HepVector(nParEcAtten,0) );
69 }
70
71 rpos.resize( nrbin );
72 rposerr.resize( nrbin );
73 rstep = ( rend - rbegin )/nrbin;
74 for( unsigned int i=0; i<nrbin; i++ ) {
75 rpos[i] = rbegin + ( i+0.5 )*rstep;
76 rposerr[i] = 0.5*rstep;
77 }
78 itofid.resize( NEndcap );
79 itofiderr.resize( NEndcap );
80 itofidstep = 1.0;
81 for( unsigned int i=0; i<NEndcap; i++ ) {
82 itofid[i] = i*1.0;
83 itofiderr[i] = 0.5;
84 }
85
86}
87
88
90 m_fitresult.clear();
91 rpos.clear();
92 rposerr.clear();
93 itofid.clear();
94 itofiderr.clear();
95}
96
97
98void calib_endcap_atten::calculate( RecordSet*& data, unsigned int icounter ) {
99
100 std::cout << setiosflags(ios::left) << setw(10) << icounter << setw(8) << data->size() << setw(30) << name() << std::endl;
101
102 if( data->size() > 0 ) {
103 std::vector<Record*>::iterator iter = data->begin();
104 for( ; iter!=data->end(); iter++ ) {
105 fillRecord( (*iter), icounter );
106 }
107 fitHistogram( icounter );
108 fillGraph( icounter );
109 fitGraph( icounter );
110 }
111 else {
112 fillGraph( icounter ); // keep the m_graphs is not empty()
113 }
114
115 if( data->size() > 0 ) {
116 std::vector<Record*>::iterator iter = data->begin();
117 for( ; iter!=data->end(); iter++ ) {
118 updateData( (*iter), icounter );
119 fillRecordQ0( (*iter), icounter );
120 }
121 fitHistogramQ0( icounter );
122 }
123
124 if( icounter==(NEndcap-1) ) {
125 fillGraphQ0();
126 }
127
128 return;
129}
130
131
132void calib_endcap_atten::fillRecord( const Record* r, unsigned int icounter ) {
133
134 double rhit = r->zrhit();
135 if( rhit<rbegin || rhit>rend ) return;
136 int rbin = static_cast<int>((rhit-rbegin)/rstep);
137 if( rbin<0 ) { rbin = 0; }
138 else if( rbin>static_cast<int>(nBinPerCounter-1-1) ) {
139 cout << "tofcalgsec::calib_endcap_atten:fillRecord: rhit is out of range, rhit=" << rhit << " rbin=" << rbin << endl;
140 return;
141 }
142
143 std::vector<TH1F*>::iterator iter = m_histograms.begin() + icounter*nKind*nBinPerCounter + rbin;
144 (*iter)->Fill( r->qleft()*abs(r->theta()) );
145
146 return;
147}
148
149
150void calib_endcap_atten::fitHistogram( unsigned int icounter ) {
151 TF1* ld = new TF1("ld", "landau");
152 ld->SetLineColor(2);
153 ld->SetLineWidth(1);
154
155 std::vector<TH1F*>::iterator iter1 = m_histograms.begin() + icounter*nKind*nBinPerCounter;
156 std::vector<HepVector>::iterator iter2 = m_fitresult.begin() + icounter*nKind*nBinPerCounter;
157 for( unsigned int j=0; j<nBinPerCounter-1; j++, iter1++, iter2++ ) {
158 (*iter1)->Fit( ld, "Q");
159 (*iter2)[0] = ld->GetParameter(1);
160 (*iter2)[1] = ld->GetParError(1);
161 (*iter2)[2] = ld->GetParameter(2);
162 (*iter2)[3] = ld->GetParError(2);
163 }
164
165 return;
166
167}
168
169
170void calib_endcap_atten::fillGraph( unsigned int icounter ) {
171
172 char gname1[256], gname2[256];
173
174 // fill graphs
175 // 2 canvas per counter,
176 // 1. Q MPV vs z
177 // 2. Q sigma vs z
178 std::vector<double> toffset, toffseterr;
179 std::vector<double> tsigma, tsigmaerr;
180 toffset.resize( nBinPerCounter-1 );
181 toffseterr.resize( nBinPerCounter-1 );
182 tsigma.resize( nBinPerCounter-1 );
183 tsigmaerr.resize( nBinPerCounter-1 );
184
185 std::vector<HepVector>::iterator iter = m_fitresult.begin() + icounter*nKind*nBinPerCounter;
186 for( unsigned int k=0; k<nBinPerCounter-1; k++ ) {
187 toffset[k] = log((*(iter+k))[0]);
188 toffseterr[k] = log((*(iter+k))[0])*((*(iter+k))[1])/((*(iter+k))[0]);
189 tsigma[k] = (*(iter+k))[2];
190 tsigmaerr[k] = (*(iter+k))[3];
191 }
192
193 sprintf( gname1, "Q MPV-tofid-%i", icounter );
194 m_graphs.push_back( new TH1F( gname1, gname1, nBinPerCounter-1, rbegin, rend ) );
195 std::vector<TH1F*>::iterator itgraph = m_graphs.end() - 1;
196 (*itgraph)->SetMarkerSize(1.5);
197 (*itgraph)->SetMarkerStyle(20);
198 (*itgraph)->SetMarkerColor(2);
199 for( unsigned int k=0; k<nBinPerCounter-1; k++ ) {
200 (*itgraph)->SetBinContent( k+1, toffset[k] );
201 (*itgraph)->SetBinError( k+1, toffseterr[k] );
202 }
203
204 sprintf( gname2, "Q sigma-tofid-%i", icounter );
205 m_graphs.push_back( new TH1F( gname2, gname2, nBinPerCounter-1, rbegin, rend ) );
206 itgraph = m_graphs.end() - 1;
207 (*itgraph)->SetMarkerSize(1.5);
208 (*itgraph)->SetMarkerStyle(21);
209 (*itgraph)->SetMarkerColor(4);
210 for( unsigned int k=0; k<nBinPerCounter-1; k++ ) {
211 (*itgraph)->SetBinContent( k+1, tsigma[k] );
212 (*itgraph)->SetBinError( k+1, tsigmaerr[k] );
213 }
214
215 return;
216}
217
218
219void calib_endcap_atten::fitGraph( unsigned int icounter ) {
220
221 TF1 *fsingleq = new TF1( "fsingleq", endcapQFunc, rbegin, rend, 3 );
222 fsingleq->SetLineColor(1);
223 fsingleq->SetLineWidth(1);
224 fsingleq->SetParameters( 6.5, 0.0, 0.0 );
225
226 std::vector<TH1F*>::iterator itgraph = m_graphs.begin() + icounter*nGraphEcAtten;
227
228 (*itgraph)->Fit( "fsingleq", "Q", "", rbegin, rend );
229 X = HepVector( m_npar, 0 );
230 X[0] = fsingleq->GetParameter(0);
231 X[1] = fsingleq->GetParameter(1);
232 X[2] = fsingleq->GetParameter(2);
233 X[3] = 0.;
234 X[4] = 0.;
235 X[5] = 0.;
236
237 std::vector<HepVector>::iterator iter = m_result.begin() + icounter;
238 (*iter) = X;
239
240 return;
241}
242
243
244void calib_endcap_atten::updateData( Record* r, unsigned int icounter ) {
245 double rhit = r->zrhit();
246 double q = r->qleft();
247 double costheta = abs(r->theta());
248
249 double par[3];
250 std::vector<HepVector>::iterator iter = m_result.begin() + icounter;
251 for( unsigned int i=0; i<3; i++ ) {
252 par[i] = (*iter)[i];
253 }
254
255 par[0] = 0.;
256 double q0 = q*costheta/exp(endcapQFunc(&rhit,par));
257 r->setQ0( q0 );
258
259 return;
260}
261
262
263void calib_endcap_atten::fillRecordQ0( const Record* r, unsigned int icounter ) {
264 std::vector<TH1F*>::iterator iter = m_histograms.begin() + icounter*nKind*nBinPerCounter + nBinPerCounter - 1;
265 (*iter)->Fill( r->q0() );
266
267 return;
268}
269
270
271void calib_endcap_atten::fitHistogramQ0( unsigned int icounter ) {
272 TF1* ld = new TF1("ld", "landau");
273 ld->SetLineColor(2);
274 ld->SetLineWidth(1);
275
276 std::vector<TH1F*>::iterator iter1 = m_histograms.begin() + icounter*nKind*nBinPerCounter + nBinPerCounter - 1;
277 std::vector<HepVector>::iterator iter2 = m_fitresult.begin() + icounter*nKind*nBinPerCounter + nBinPerCounter - 1;
278 (*iter1)->Fit( ld, "Q");
279 (*iter2)[0] = ld->GetParameter(1);
280 (*iter2)[1] = ld->GetParError(1);
281 (*iter2)[2] = ld->GetParameter(2);
282 (*iter2)[3] = ld->GetParError(2);
283
284 return;
285}
286
287
288void calib_endcap_atten::fillGraphQ0() {
289 char gname1[256], gname2[256];
290
291 // fill graphs
292 // 2 canvas per counter,
293 // 1. Q0 MPV vs z
294 // 2. Q0 sigma vs z
295 std::vector<double> toffset, toffseterr;
296 std::vector<double> tsigma, tsigmaerr;
297 toffset.resize( NEndcap );
298 toffseterr.resize( NEndcap );
299 tsigma.resize( NEndcap );
300 tsigmaerr.resize( NEndcap );
301
302 unsigned int number = 0;
303 std::vector<HepVector>::iterator iter1 = m_fitresult.begin() + nBinPerCounter - 1;
304 std::vector<HepVector>::iterator iter2 = m_result.begin();
305 for( unsigned int i=0; i<NEndcap; i++ ) {
306 number = i*nBinPerCounter;
307 toffset[i] = (*(iter1+number))[0];
308 toffseterr[i] = (*(iter1+number))[1];
309 tsigma[i] = (*(iter1+number))[2];
310 tsigmaerr[i] = (*(iter1+number))[3];
311
312
313 (*(iter2+i))[3] = toffset[i]/toffset[0];
314 (*(iter2+i))[4] = toffset[i];
315 }
316
317 sprintf( gname1, "Q0 MPV vs TOF Counter Number" );
318 m_graphs.push_back( new TH1F( gname1, gname1, NEndcap, -0.5, NEndcap-0.5 ) );
319 std::vector<TH1F*>::iterator itgraph = m_graphs.end() - 1;
320 (*itgraph)->SetMarkerSize(1.5);
321 (*itgraph)->SetMarkerStyle(20);
322 (*itgraph)->SetMarkerColor(2);
323 for( unsigned int k=0; k<nBinPerCounter-1; k++ ) {
324 (*itgraph)->SetBinContent( k+1, tsigma[k] );
325 (*itgraph)->SetBinError( k+1, tsigmaerr[k] );
326 }
327 for( unsigned int i=0; i<NEndcap; i++ ) {
328 (*itgraph)->SetBinContent( i+1, toffset[i] );
329 (*itgraph)->SetBinError( i+1, toffseterr[i] );
330 }
331
332 sprintf( gname2, "Q0 Sigma vs TOF Counter Number" );
333 m_graphs.push_back( new TH1F( gname2, gname2, NEndcap, -0.5, NEndcap-0.5 ) );
334 itgraph = m_graphs.end() - 1;
335 (*itgraph)->SetTitle(gname2);
336 (*itgraph)->SetMarkerSize(1.5);
337 (*itgraph)->SetMarkerStyle(21);
338 (*itgraph)->SetMarkerColor(4);
339 for( unsigned int i=0; i<NEndcap; i++ ) {
340 (*itgraph)->SetBinContent( i+1, tsigma[i] );
341 (*itgraph)->SetBinError( i+1, tsigmaerr[i] );
342 }
343
344 return;
345}
TTree * data
Double_t x[10]
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< Record * > RecordSet
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition: KKsem.h:33
std::vector< unsigned int > nGraphPerCanvasPerCounter
calib_endcap_atten(const unsigned int nrbin)
void calculate(RecordSet *&data, unsigned int icounter)
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")