BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
TofCorrPID.cxx
Go to the documentation of this file.
1#include <cmath>
2#include "TMath.h"
3
5
6#ifndef BEAN
13#else
14#include "TofHitStatus.h"
15#endif
16#include <fstream>
17
18
19TofCorrPID * TofCorrPID::m_pointer = 0;
21 if(!m_pointer) m_pointer = new TofCorrPID();
22 return m_pointer;
23}
24
25TofCorrPID::TofCorrPID():ParticleIDBase() {
26 m_runBegin = 0;
27 m_runEnd = 0;
28}
29
31
32 for(int i = 0; i < 5; i++) {
33 m_chi[i] = -100.0;
34 m_prob[i] = -1.0;
35 m_sigma[i] = 10.0;
36 m_offset[i] = -1000.0;
37 }
38 m_chimin = -99.0;
39 m_chimax = 99.0;
40 m_pdfmin = 99.;
41 m_ndof = 0;
42
43 m_ipmt = -1;
44 for( unsigned int i=0; i<5; i++ ) {
45 for( unsigned int j=0; j<7; j++ ) {
46 m_dt[i][j] = -1000.0;
47 m_dtCorr[i][j] = -1000.0;
48 m_sigCorr[i][j] = 10.0;
49 m_chiCorr[i][j] = 100.0;
50 }
51 }
52
53 int run = getRunNo();
54 if( !( abs(run)>=m_runBegin && abs(run)<=m_runEnd ) ) {
56 }
57
58 return;
59}
60
61
63 if(particleIDCalculation() == 0) m_ndof=1;
64}
65
66
68 int irc=-1;
69
70 EvtRecTrack* recTrk = PidTrk();
71 if(!(recTrk->isMdcTrackValid())) return irc;
72 if(!(recTrk->isMdcKalTrackValid())) return irc;
73 if(!(recTrk->isExtTrackValid())) return irc;
74 if(!(recTrk->isTofTrackValid())) return irc;
75
76#ifndef BEAN
77 SmartRefVector<RecTofTrack> tofTrk = recTrk->tofTrack();
78 SmartRefVector<RecTofTrack>::iterator it;
79#else
80 const std::vector<TTofTrack* >& tofTrk = recTrk->tofTrack();
81 std::vector<TTofTrack* >::const_iterator it;
82#endif
83
84 RecMdcTrack* mdcTrk = recTrk->mdcTrack();
85 int charge = mdcTrk->charge();
86
87 double p[5], betaGamma[5];
88 RecMdcKalTrack* kalTrk = recTrk->mdcKalTrack();
89 for( int i=0; i<5; i++ ) {
90 if( i==0 ) {
92 }
93 else if( i==1 ) {
95 }
96 else if( i==2 ) {
98 }
99 else if( i==3 ) {
101 }
102 else if( i==4 ) {
104 }
105#ifndef BEAN
106 HepLorentzVector ptrk = kalTrk->p4();
107#else
108 HepLorentzVector ptrk = kalTrk->p4( xmass(i) );
109#endif
110 p[i] = ptrk.rho();
111 betaGamma[i] = p[i]/xmass(i);
112 }
113
114 double zrhit[2];
115 RecExtTrack* extTrk = recTrk->extTrack();
116 zrhit[0] = extTrk->tof1Position().z();
117 zrhit[1] = extTrk->tof2Position().z();
118
119 int tofid[2] = { -9, -9 };
120
121 m_ipmt = -1;
122 bool readFile = false;
123 bool signal[2] = { false, false };
124 TofHitStatus *hitst = new TofHitStatus;
125 for( it = tofTrk.begin(); it!=tofTrk.end(); it++ ) {
126 unsigned int st = (*it)->status();
127 hitst->setStatus(st);
128 if( hitst->is_raw() ) return irc; // TOF no hit
129 bool barrel = hitst->is_barrel();
130 bool ismrpc = hitst->is_mrpc();
131 if( !barrel && !ismrpc ) { zrhit[0] = extTrk->tof1Position().rho(); }
132 bool readout = hitst->is_readout();
133 bool counter = hitst->is_counter();
134 bool cluster = hitst->is_cluster();
135 int layer = hitst->layer();
136 tofid[layer-1] = (*it)->tofID();
137 bool east = hitst->is_east();
138 double tof = (*it)->tof();
139 unsigned int ipmt = 0;
140 if( readout ) {
141 // barrel: 0:inner east, 1:inner west, 2:outer east, 3: outer west
142 // endcap: 7:east endcap, 8:west endcap
143 if( barrel ) { ipmt = ( ( st & 0xC0 ) >> 5 ) + ( ( ( st ^ 0x20 ) & 0x20 ) >> 5 ) - 2; }
144 else {
145 if( !ismrpc ) {
146 if( tofid[0]<=47 ) { ipmt = 7; }
147 else { ipmt = 8; }
148 }
149 else {
150 if( tofid[0]<=35 ) { ipmt = 7; }
151 else { ipmt = 8; }
152 }
153 }
154
155 for( unsigned int i=0; i<5; i++ ) {
156 double offset = (*it)->toffset(i);
157 double texp = (*it)->texp(i);
158 if( texp<0.0 ) continue;
159 double dt = tof - offset - texp;
160 if( barrel ) {
161 m_dt[i][ipmt] = dt;
162 m_dtCorr[i][ipmt] = offsetTof( i, barrel, ipmt, betaGamma[i], charge, zrhit[layer-1], dt );
163 m_sigCorr[i][ipmt] = sigmaTof( i, charge, barrel, ipmt, &tofid[0], &zrhit[0], betaGamma[i] );
164 m_chiCorr[i][ipmt] = m_dtCorr[i][ipmt]/m_sigCorr[i][ipmt];
165 }
166 else {
167 if( !ismrpc ) {
168 m_dt[i][0] = dt;
169 m_dtCorr[i][0] = offsetTof( i, barrel, ipmt, betaGamma[i], charge, zrhit[layer-1], dt );
170 m_sigCorr[i][0] = sigmaTof( i, charge, barrel, ipmt, &tofid[0], &zrhit[0], betaGamma[i] );
171 m_chiCorr[i][0] = m_dtCorr[i][ipmt]/m_sigCorr[i][ipmt];
172 }
173 else {
174 m_dt[i][0] = dt;
175 m_dtCorr[i][0] = dt;
176 // m_sigCorr[i][0] = 0.065;
177 int strip = (*it)->strip();
178 double p0, p1;
179 if( strip<0 || strip>11 ) { m_sigCorr[i][0] = 0.065; }
180 else {
181 if( strip==0 ) { p0=0.16; p1=0.0; }
182 else if( strip==1 ) { p0=0.051094; p1=0.019467; }
183 else if( strip==2 ) { p0=0.056019; p1=0.012964; }
184 else if( strip==3 ) { p0=0.043901; p1=0.015933; }
185 else if( strip==4 ) { p0=0.049750; p1=0.010473; }
186 else if( strip==5 ) { p0=0.048345; p1=0.008545; }
187 else if( strip==6 ) { p0=0.046518; p1=0.009038; }
188 else if( strip==7 ) { p0=0.048803; p1=0.007251; }
189 else if( strip==8 ) { p0=0.047523; p1=0.008434; }
190 else if( strip==9 ) { p0=0.042187; p1=0.010307; }
191 else if( strip==10 ) { p0=0.050337; p1=0.005951; }
192 else if( strip==11 ) { p0=0.054740; p1=0.005629; }
193 if( p[i]<0.05 ) { m_sigCorr[i][0] = p0+p1/0.05; }
194 else { m_sigCorr[i][0] = p0+p1/p[i]; }
195 }
196 if( i==4 ) { m_sigCorr[i][0] = 1.5*m_sigCorr[i][0]; }
197 m_chiCorr[i][0] = m_dtCorr[i][0]/m_sigCorr[i][0];
198 }
199 }
200 }
201 if( counter && cluster ) {
202 m_ipmt = ipmt;
203 for( unsigned int i=0; i<5; i++ ) {
204 if( ((*it)->texp(i))>0.0 ) {
205 if( barrel ) {
206 m_offset[i] = m_dtCorr[i][ipmt];
207 m_sigma[i] = m_sigCorr[i][ipmt];
208 }
209 else {
210 m_offset[i] = m_dtCorr[i][0];
211 m_sigma[i] = m_sigCorr[i][0];
212 }
213 }
214 }
215 }
216 }
217 else {
218 if( counter ) {
219 ipmt = layer+3;
220 for( unsigned int i=0; i<5; i++ ) {
221 double offset = (*it)->toffset(i);
222 double texp = (*it)->texp(i);
223 if( texp<0.0 ) continue;
224 double dt = tof - offset - texp;
225 if( barrel ) {
226 m_dt[i][ipmt] = dt;
227 m_dtCorr[i][ipmt] = offsetTof( i, tofid[layer-1], zrhit[layer-1], betaGamma[i], charge, dt );
228 m_sigCorr[i][ipmt] = sigmaTof( i, charge, barrel, layer+3, &tofid[0], &zrhit[0], betaGamma[i] );
229 m_chiCorr[i][ipmt] = m_dtCorr[i][ipmt]/m_sigCorr[i][ipmt];
230 }
231 else {
232 if( ismrpc ) {
233 m_dt[i][0] = dt;
234 m_dtCorr[i][0] = dt;
235 // m_sigCorr[i][0] = 0.065;
236 int strip = (*it)->strip();
237 double p0, p1;
238 if( strip<0 || strip>11 ) { m_sigCorr[i][0] = 0.065; }
239 else {
240 if( strip==0 ) { p0=0.16; p1=0.0; }
241 else if( strip==1 ) { p0=0.051094; p1=0.019467; }
242 else if( strip==2 ) { p0=0.056019; p1=0.012964; }
243 else if( strip==3 ) { p0=0.043901; p1=0.015933; }
244 else if( strip==4 ) { p0=0.049750; p1=0.010473; }
245 else if( strip==5 ) { p0=0.048345; p1=0.008545; }
246 else if( strip==6 ) { p0=0.046518; p1=0.009038; }
247 else if( strip==7 ) { p0=0.048803; p1=0.007251; }
248 else if( strip==8 ) { p0=0.047523; p1=0.008434; }
249 else if( strip==9 ) { p0=0.042187; p1=0.010307; }
250 else if( strip==10 ) { p0=0.050337; p1=0.005951; }
251 else if( strip==11 ) { p0=0.054740; p1=0.005629; }
252 if( p[i]<0.05 ) { m_sigCorr[i][0] = p0+p1/0.05; }
253 else { m_sigCorr[i][0] = p0+p1/p[i]; }
254 }
255 if( i==4 ) { m_sigCorr[i][0] = 1.5*m_sigCorr[i][0]; }
256 m_chiCorr[i][0] = m_dtCorr[i][0]/m_sigCorr[i][0];
257 }
258 else {
259 cout << "ParticleID: TofCorr::particleIDCalculation: Endcap Scintillator TOF have more than one end!!!" << endl;
260 }
261 }
262 }
263 if( cluster ) {
264 m_ipmt = ipmt;
265 for( unsigned int i=0; i<5; i++ ) {
266 if( ((*it)->texp(i))>0.0 ) {
267 if( barrel ) {
268 m_offset[i] = m_dtCorr[i][ipmt];
269 m_sigma[i] = m_sigCorr[i][ipmt];
270 }
271 else {
272 m_offset[i] = m_dtCorr[i][0];
273 m_sigma[i] = m_sigCorr[i][0];
274 }
275 }
276 }
277 }
278 else {
279 signal[layer-1] = correlationCheck( ipmt );
280 }
281 }
282 else {
283 if( cluster ) {
284 ipmt = 6;
285 for( unsigned int i=0; i<5; i++ ) {
286 double offset = (*it)->toffset(i);
287 double texp = (*it)->texp(i);
288 if( texp<0.0 ) continue;
289 double dt = tof - offset - texp;
290 m_dt[i][ipmt] = dt;
291 m_dtCorr[i][ipmt] = offsetTof( i, tofid[0], tofid[1], zrhit[0], zrhit[1], betaGamma[i], charge, dt );
292 m_sigCorr[i][ipmt] = sigmaTof( i, charge, barrel, ipmt, &tofid[0], &zrhit[0], betaGamma[i] );
293 m_chiCorr[i][ipmt] = m_dtCorr[i][ipmt]/m_sigCorr[i][ipmt];
294 }
295 if( signal[0] && signal[1] ) {
296 m_ipmt = 6;
297 for( unsigned int i=0; i<5; i++ ) {
298 m_offset[i] = m_dtCorr[i][ipmt];
299 m_sigma[i] = m_sigCorr[i][ipmt];
300 }
301 }
302 else if( signal[0] && !signal[1] ) {
303 m_ipmt = 4;
304 for( unsigned int i=0; i<5; i++ ) {
305 m_offset[i] = m_dtCorr[i][4];
306 m_sigma[i] = m_sigCorr[i][4];
307 }
308 }
309 else if( !signal[0] && signal[1] ) {
310 m_ipmt = 5;
311 for( unsigned int i=0; i<5; i++ ) {
312 m_offset[i] = m_dtCorr[i][5];
313 m_sigma[i] = m_sigCorr[i][5];
314 }
315 }
316 else return irc;
317 }
318 }
319 }
320 }
321 delete hitst;
322
323 double pdftemp = 0;
324 for( unsigned int i=0; i<5; i++ ) {
325 m_chi[i] = m_offset[i]/m_sigma[i];
326 if( m_chi[i]<0. && m_chi[i]>m_chimin ) { m_chimin = m_chi[i]; }
327 if( m_chi[i]>0. && m_chi[i]<m_chimax ) { m_chimax = m_chi[i]; }
328 double ppp = pdfCalculate(m_chi[i],1);
329 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
330 }
331
332 m_pdfmin = pdftemp;
333 if( pdftemp < pdfCalculate(pdfMinSigmaCut(),1) ) return irc;
334 if( ( m_chimin > -90.0 && (0-m_chimin)>chiMinCut() ) && ( m_chimax < 90.0 && m_chimax>chiMaxCut() ) ) return irc;
335 for(int i = 0; i < 5; i++) {
336 m_prob[i] = probCalculate(m_chi[i]*m_chi[i], 1);
337 }
338
339 irc = 0;
340 return irc;
341}
342
343
345
346 std::string filePath = path + "/share/TofCorrPID/";
347
348 filePath = filePath + "jpsi2012";
349 m_runBegin = 0;
350 m_runEnd = 80000;
351
352 if( run>0 ) {
353 filePath = filePath + "/data/";
354 }
355 else {
356 filePath = filePath + "/mc/";
357 }
358
359
360 // weight from tof calibration
361 std::string fileWeight = filePath + "calib_barrel_sigma.txt";
362 ifstream inputWeight( fileWeight.c_str(), std::ios_base::in );
363 if( !inputWeight ) {
364 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileWeight << endl;
365 exit(1);
366 }
367
368 for( unsigned int tofid=0; tofid<176; tofid++ ) {
369 for( unsigned int readout=0; readout<3; readout++ ) {
370 for( unsigned int p_i=0; p_i<5; p_i++ ) {
371 inputWeight >> m_p_weight[tofid][readout][p_i];
372 }
373 }
374 }
375 // cout << "finish read " << fileWeight << endl;
376
377 // common item, from bunch size and bunch time
378 std::string fileCommon = filePath + "calib_barrel_common.txt";
379 ifstream inputCommon( fileCommon.c_str(), std::ios_base::in );
380 if( !inputCommon ) {
381 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileCommon << endl;
382 exit(1);
383 }
384 inputCommon >> m_p_common;
385 // cout << "finish read " << fileCommon << endl;
386
387 // endcap sigma
388 std::string fileEcSigma = filePath + "calib_endcap_sigma.txt";
389 ifstream inputEcSigma( fileEcSigma.c_str(), std::ios_base::in );
390 if( !inputEcSigma ) {
391 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileEcSigma << endl;
392 exit(1);
393 }
394
395 for( unsigned int tofid=0; tofid<96; tofid++ ) {
396 for( unsigned int p_i=0; p_i<3; p_i++ ) {
397 inputEcSigma >> m_ec_sigma[tofid][p_i];
398 }
399 }
400 // cout << "finish read " << fileEcSigma << endl;
401
402 // curve of betaGamma versus Q0
403 std::string fileQ0BetaGamma = filePath + "curve_Q0_BetaGamma.txt";
404 ifstream inputQ0BetaGamma( fileQ0BetaGamma.c_str(), std::ios_base::in );
405 if( !inputQ0BetaGamma ) {
406 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileQ0BetaGamma << endl;
407 exit(1);
408 }
409 // barrel layer1 layer2 and endcap
410 for( unsigned int layer=0; layer<3; layer++ ) {
411 for( unsigned int ipar=0; ipar<5; ipar++ ) {
412 inputQ0BetaGamma >> m_q0_bg[layer][ipar];
413 }
414 }
415 // cout << "finish read " << fileQ0BetaGamma << endl;
416
417 // paramter of A and B
418 std::string fileParAB = filePath + "parameter_A_B.txt";
419 ifstream inputParAB( fileParAB.c_str(), std::ios_base::in );
420 if( !inputParAB ) {
421 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileParAB << endl;
422 exit(1);
423 }
424
425 // Jpsi2012
426 // 0: pion/kaon, 1: proton/anti-proton
427 // 0: inner east, 1: inner west, 2: outer east, 3: outer west, 4: west endcap
428 // 0: plus, 1: minus
429 // 0: parameter A, 1: parameter B
430 for( unsigned int ispecies=0; ispecies<2; ispecies++ ) {
431 for( unsigned int ipmt=0; ipmt<5; ipmt++ ) {
432 for( unsigned int icharge=0; icharge<2; icharge++ ) {
433 for( unsigned int iab=0; iab<2; iab++ ) {
434 for( unsigned int ipar=0; ipar<11; ipar++ ) {
435 inputParAB >> m_par_ab_12[ispecies][ipmt][icharge][iab][ipar];
436 }
437 }
438 }
439 }
440 }
441
442 // sigma for pion, kaon and proton
443 std::string fileSigma = filePath + "parameter_sigma.txt";
444 ifstream inputSigma( fileSigma.c_str(), std::ios_base::in );
445 if( !inputSigma ) {
446 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileSigma << endl;
447 exit(1);
448 }
449 // Jpsi2009 & Jpsi2012
450 // 0: pion, 1: kaon, 2: proton, 3: anti-proton
451 // 0: inner east, 1: inner west, 2: outer east, 3: outer west
452 // 4: inner layer, 5: outer layer, 6: double layer
453 // 7: west endcap
454 for( unsigned int ispecies=0; ispecies<4; ispecies++ ) {
455 for( unsigned int ipmt=0; ipmt<8; ipmt++ ) {
456 for( unsigned int ipar=0; ipar<12; ipar++ ) {
457 inputSigma >> m_par_sigma[ispecies][ipmt][ipar];
458 }
459 }
460 }
461
462 // offset for low momentum proton and anti-proton
463 std::string fileProtonOffset = filePath + "parameter_offset_proton.txt";
464 ifstream inputProtonOffset( fileProtonOffset.c_str(), std::ios_base::in );
465 if( !inputProtonOffset ) {
466 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileProtonOffset << endl;
467 exit(1);
468 }
469
470 // Jpsi2012
471 // 0: proton, 1: anti-proton
472 // 0: inner east, 1: inner west, 2: outer east, 3: outer west
473 // 4: inner layer, 5: outer layer, 6: double layer
474 // 7: west endcap
475 for( unsigned int ispecies=0; ispecies<2; ispecies++ ) {
476 for( unsigned int ipmt=0; ipmt<8; ipmt++ ) {
477 for( unsigned int ipar=0; ipar<20; ipar++ ) {
478 if( ipmt!=7 ) {
479 for( unsigned int jpar=0; jpar<46; jpar++ ) {
480 inputProtonOffset >> m_p_offset_12[ispecies][ipmt][ipar][jpar];
481 }
482 }
483 else {
484 for( unsigned int jpar=0; jpar<7; jpar++ ) {
485 inputProtonOffset >> m_p_offset_ec12[ispecies][ipar][jpar];
486 }
487 }
488 }
489 }
490 }
491 // cout << "finish read " << fileProtonOffset << endl;
492
493 // sigma for low momentum proton and anti-proton
494 std::string fileProtonSigma = filePath + "parameter_sigma_proton.txt";
495 ifstream inputProtonSigma( fileProtonSigma.c_str(), std::ios_base::in );
496 if( !inputProtonSigma ) {
497 cout << "ParticleID::TofCorrPID: Can NOT open file: " << fileProtonSigma << endl;
498 exit(1);
499 }
500
501 // Jpsi2012
502 // 0: proton, 1: anti-proton
503 // 0: inner east, 1: inner west, 2: outer east, 3: outer west
504 // 4: inner layer, 5: outer layer, 6: double layer
505 // 7: west endcap
506 for( unsigned int ispecies=0; ispecies<2; ispecies++ ) {
507 for( unsigned int ipmt=0; ipmt<8; ipmt++ ) {
508 for( unsigned int ipar=0; ipar<20; ipar++ ) {
509 if( ipmt!=7 ) {
510 for( unsigned int jpar=0; jpar<46; jpar++ ) {
511 inputProtonSigma >> m_p_sigma_12[ispecies][ipmt][ipar][jpar];
512 }
513 }
514 else {
515 for( unsigned int jpar=0; jpar<7; jpar++ ) {
516 inputProtonSigma >> m_p_sigma_ec12[ispecies][ipar][jpar];
517 }
518 }
519 }
520 }
521 }
522 // cout << "finish read " << fileProtonSigma << endl;
523
524 return;
525}
526
527
528double TofCorrPID::offsetTof( unsigned int ispecies, bool barrel, unsigned int ipmt, double betaGamma, int charge, double zrhit, double dt ) {
529 if( ispecies==0 || ispecies==1 ) { return dt; }
530
531 double deltaT = -1000.0;
532 if( ( ipmt>= 4 && barrel ) || ( ipmt!=7 && ipmt!=8 && !barrel ) || betaGamma<0.0 || abs(charge)!=1 || fabs(zrhit)>120.0 ) {
533// cout << "Particle::TofCorrPID: offsetTof for single end: the input parameter are NOT correct! Please check them!" << endl;
534 return deltaT;
535 }
536 unsigned int layer=0;
537 if( barrel ) {
538 if( ipmt==0 || ipmt==1 ) { layer=0; }
539 else if( ipmt==2 || ipmt==3 ) { layer=1; }
540 }
541 else { layer=2; }
542 double q0 = qCurveFunc( layer, betaGamma );
543
544 unsigned int inumber=ipmt;
545 if( !barrel ) { inumber=4; }
546
547 double func[9];
548 for( unsigned int i=0; i<9; i++ ) {
549 func[i]=0.0;
550 }
551
552 double parA = 0.0;
553 double parB = 0.0;
554
555 // Jpsi2012
556 func[0] = 1.0;
557 for( unsigned int i=1; i<8; i++ ) {
558 func[i] = func[i-1]*zrhit;
559 }
560
561 unsigned int iparticle=0;
562 if( ispecies==2 || ispecies==3 ) { iparticle=0; }
563 else if( ispecies==4 ) { iparticle=1; }
564 unsigned int icharge=0;
565 if( charge==1 ) { icharge=0; }
566 else if( charge==-1 ) { icharge=1; }
567
568 if( ispecies!=4 || betaGamma*xmass(4)>0.8 ) {
569 for( unsigned int i=0; i<8; i++ ) {
570 if( i<5 ) {
571 parA += m_par_ab_12[iparticle][inumber][icharge][0][i]*func[i];
572 parB += m_par_ab_12[iparticle][inumber][icharge][1][i]*func[i];
573 }
574 else if( i>=5 ) {
575 parA += m_par_ab_12[iparticle][inumber][icharge][0][i+3]*func[i];
576 parB += m_par_ab_12[iparticle][inumber][icharge][1][i+3]*func[i];
577 }
578 }
579 for( unsigned int iab=0; iab<2; iab++ ) {
580 func[8] = m_par_ab_12[iparticle][inumber][icharge][iab][5]*TMath::Gaus(zrhit,m_par_ab_12[iparticle][inumber][icharge][iab][6], m_par_ab_12[iparticle][inumber][icharge][iab][7]);
581 if( iab==0 ) {
582 parA += func[8];
583 }
584 else if( iab==1 ) {
585 parB += func[8];
586 }
587 }
588 }
589
590 double tcorr = parA + parB/sqrt(q0);
591
592 // barrel TOF low momentum proton and anti-proton
593 // Jpsi2012
594 if( barrel && ispecies==4 && betaGamma*xmass(4)<0.8 ) {
595 int nzbin = 46;
596 double zbegin = -115.0;
597 double zend = 115.0;
598 double zstep = (zend-zbegin)/nzbin;
599
600 double nbgbin = 20.0;
601 double bgbegin = 0.3;
602 double bgend = 0.8;
603 double bgstep;
604 bgstep = (bgend-bgbegin)/nbgbin;
605
606 int izbin = static_cast<int>((zrhit-zbegin)/zstep);
607 if( izbin<0 ) { izbin=0; }
608 else if( izbin>=nzbin ) { izbin=nzbin-1; }
609 int ibgbin = static_cast<int>((betaGamma*xmass(4)-bgbegin)/bgstep);
610 if( ibgbin<0 ) { ibgbin=0; }
611 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
612
613 if( charge==1 ) {
614 tcorr = m_p_offset_12[0][ipmt][ibgbin][izbin];
615 }
616 else {
617 tcorr = m_p_offset_12[1][ipmt][ibgbin][izbin];
618 }
619 }
620 else if( !barrel && ispecies==4 && betaGamma*xmass(4)<0.8 ) {
621 int nrbin = 7;
622 double rbegin = 55.0;
623 double rend = 83.0;
624 double rstep = (rend-rbegin)/nrbin;
625
626 double nbgbin = 20.0;
627 double bgbegin = 0.3;
628 double bgend = 0.8;
629 double bgstep;
630 bgstep = (bgend-bgbegin)/nbgbin;
631
632 int irbin = static_cast<int>((zrhit-rbegin)/rstep);
633 if( irbin<0 ) { irbin=0; }
634 else if( irbin>=nrbin ) { irbin=nrbin-1; }
635 int ibgbin = static_cast<int>((betaGamma*xmass(4)-bgbegin)/bgstep);
636 if( ibgbin<0 ) { ibgbin=0; }
637 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
638
639 if( charge==1 ) {
640 tcorr = m_p_offset_ec12[0][ibgbin][irbin];
641 }
642 else {
643 tcorr = m_p_offset_ec12[1][ibgbin][irbin];
644 }
645 }
646
647 deltaT = dt - tcorr;
648
649 return deltaT;
650}
651
652
653double TofCorrPID::offsetTof( unsigned int ispecies, int tofid, double zrhit, double betaGamma, int charge, double dt ) {
654 if( ispecies==0 || ispecies==1 ) { return dt; }
655
656 double deltaT = -1000.0;
657 if( tofid<0 || tofid>=176 ) {
658 cout << "Particle::TofCorrPID: offsetTof for single layer: the input parameter are NOT correct! Please check them!" << endl;
659 exit(1);
660 }
661 int pmt[3] = { -9, -9, -9 };
662 if( tofid>=0 && tofid<=87 ) {
663 pmt[0] = 0;
664 pmt[1] = 1;
665 pmt[2] = 4;
666 }
667 else {
668 pmt[0] = 2;
669 pmt[1] = 3;
670 pmt[2] = 5;
671 }
672
673 double sigmaCorr2 = m_p_common*m_p_common;
674 double sigmaLeft = bSigma( 0, tofid, zrhit );
675 double sigmaLeft2 = sigmaLeft*sigmaLeft;
676 double sigmaRight = bSigma( 1, tofid, zrhit );
677 double sigmaRight2 = sigmaRight*sigmaRight;
678
679 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
680 deltaT = fraction*m_dtCorr[ispecies][pmt[0]] + (1.0-fraction)*m_dtCorr[ispecies][pmt[1]];
681
682 // Jpsi2012
683 double tcorr = 0.0;
684 unsigned int ipmt = 4;
685 if( tofid>=88 && tofid<176 ) { ipmt = 5; }
686 if( ispecies==4 && betaGamma*xmass(4)<0.8 ) {
687 int nzbin = 46;
688 double zbegin = -115.0;
689 double zend = 115.0;
690 double zstep = (zend-zbegin)/nzbin;
691
692 double nbgbin = 20.0;
693 double bgbegin = 0.3;
694 double bgend = 0.8;
695 double bgstep;
696 bgstep = (bgend-bgbegin)/nbgbin;
697
698 int izbin = static_cast<int>((zrhit-zbegin)/zstep);
699 if( izbin<0 ) { izbin=0; }
700 else if( izbin>=nzbin ) { izbin=nzbin-1; }
701 int ibgbin = static_cast<int>((betaGamma*xmass(4)-bgbegin)/bgstep);
702 if( ibgbin<0 ) { ibgbin=0; }
703 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
704
705 if( charge==1 ) {
706 tcorr = m_p_offset_12[0][ipmt][ibgbin][izbin];
707 }
708 else {
709 tcorr = m_p_offset_12[1][ipmt][ibgbin][izbin];
710 }
711 }
712 deltaT = deltaT - tcorr;
713
714 return deltaT;
715}
716
717
718double TofCorrPID::offsetTof( unsigned int ispecies, int tofid1, int tofid2, double zrhit1, double zrhit2, double betaGamma, int charge, double dt ) {
719 if( ispecies==0 || ispecies==1 ) { return dt; }
720
721 double deltaT = -1000.0;
722 if( tofid1<0 || tofid1>=88 || tofid2<88 || tofid2>=176 ) {
723 cout << "Particle::TofCorrPID: offsetTof for double layer: the input parameter are NOT correct! Please check them!" << endl;
724 exit(1);
725 }
726
727 double sigmaCorr2 = m_p_common*m_p_common;
728 double sigmaInner = bSigma( 2, tofid1, zrhit1 );
729 double sigmaInner2 = sigmaInner*sigmaInner;
730 double sigmaOuter = bSigma( 2, tofid2, zrhit2 );
731 double sigmaOuter2 = sigmaOuter*sigmaOuter;
732 double sigma = sqrt( (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2) );
733
734 m_sigma[0] = sigma;
735 m_sigma[1] = sigma;
736
737 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
738 deltaT = fraction*m_dtCorr[ispecies][4] + (1.0-fraction)*m_dtCorr[ispecies][5];
739
740 // Jpsi2012
741 double tcorr = 0.0;
742 if( ispecies==4 && betaGamma*xmass(4)<0.8 ) {
743 int nzbin = 46;
744 double zbegin = -115.0;
745 double zend = 115.0;
746 double zstep = (zend-zbegin)/nzbin;
747
748 double nbgbin = 20.0;
749 double bgbegin = 0.3;
750 double bgend = 0.8;
751 double bgstep;
752 bgstep = (bgend-bgbegin)/nbgbin;
753
754 int izbin = static_cast<int>((zrhit1-zbegin)/zstep);
755 if( izbin<0 ) { izbin=0; }
756 else if( izbin>=nzbin ) { izbin=nzbin-1; }
757 int ibgbin = static_cast<int>((betaGamma*xmass(4)-bgbegin)/bgstep);
758 if( ibgbin<0 ) { ibgbin=0; }
759 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
760
761 if( charge==1 ) {
762 tcorr = m_p_offset_12[0][6][ibgbin][izbin];
763 }
764 else {
765 tcorr = m_p_offset_12[1][6][ibgbin][izbin];
766 }
767 }
768 deltaT = deltaT - tcorr;
769
770 return deltaT;
771}
772
773
774double TofCorrPID::sigmaTof( unsigned int ispecies, int charge, bool barrel, unsigned int ipmt, int tofid[2], double zrhit[2], double betaGamma ) {
775
776 double sigma = 1.0e-6;
777
778 if( ispecies==0 || ispecies==1 ) {
779 if( barrel ) {
780 if( ipmt==0 ) {
781 sigma = bSigma( 0, tofid[0], zrhit[0] );
782 }
783 else if( ipmt==1 ) {
784 sigma = bSigma( 1, tofid[0], zrhit[0] );
785 }
786 else if( ipmt==2 ) {
787 sigma = bSigma( 0, tofid[1], zrhit[1] );
788 }
789 else if( ipmt==3 ) {
790 sigma = bSigma( 1, tofid[1], zrhit[1] );
791 }
792 else if( ipmt==4 ) {
793 sigma = bSigma( 2, tofid[0], zrhit[0] );
794 }
795 else if( ipmt==5 ) {
796 sigma = bSigma( 2, tofid[1], zrhit[1] );
797 }
798 else if( ipmt==6 ) {
799 sigma = bSigma( &tofid[0], &zrhit[0] );
800 }
801 }
802 else {
803 sigma = eSigma( tofid[0], zrhit[0] );
804 }
805 }
806 else {
807 unsigned int iz = 0;
808 if( ipmt==2 || ipmt==3 || ipmt==5 ) { iz=1; }
809
810 sigma = sigmaTof( ispecies, charge, barrel, ipmt, zrhit[iz], betaGamma );
811 }
812
813 return sigma;
814}
815
816
817double TofCorrPID::sigmaTof( unsigned int ispecies, int charge, bool barrel, unsigned int ipmt, double zrhit, double betaGamma ) {
818
819 int ibgbin = -1;
820 int izbin = 0;
821 // Jpsi2012
822 if( ispecies==4 && (betaGamma*xmass(4))<0.8 ) {
823 double nbgbin = 20.0;
824 double bgbegin = 0.3;
825 double bgend = 0.8;
826 double bgstep;
827 bgstep = (bgend-bgbegin)/nbgbin;
828 ibgbin = static_cast<int>((betaGamma*xmass(4)-bgbegin)/bgstep);
829
830 if( ibgbin<0 ) { ibgbin=0; }
831 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
832
833 if( barrel ) {
834 int nzbin = 46;
835 double zbegin = -115.0;
836 double zend = 115.0;
837 double zstep = (zend-zbegin)/nzbin;
838
839 izbin = static_cast<int>((zrhit-zbegin)/zstep);
840 if( izbin<0 ) { izbin=0; }
841 else if( izbin>=nzbin ) { izbin=nzbin-1; }
842 }
843 else {
844 int nzbin = 7;
845 double zbegin = 55.0;
846 double zend = 83.0;
847 double zstep = (zend-zbegin)/nzbin;
848
849 izbin = static_cast<int>((zrhit-zbegin)/zstep);
850 if( izbin<0 ) { izbin=0; }
851 else if( izbin>=nzbin ) { izbin=nzbin-1; }
852 }
853 }
854
855 unsigned int numParam = 4;
856 double func[12];
857 for( unsigned int i=0; i<4; i++ ) {
858 if( i==0 ) { func[i] = 1.0; }
859 else {
860 func[i] = func[i-1]*zrhit;
861 }
862 }
863 for( unsigned int i=4; i<12; i++ ) {
864 func[i] = 0.0;
865 }
866
867 // Jpsi2012
868 if( barrel ) { // barrel
869 if( ispecies==2 || ispecies==3 ) { // pion / kaon
870 for( unsigned int i=4; i<10; i++ ) {
871 func[i] = func[i-1]*zrhit;
872 }
873 func[10] = 1.0/(115.0-zrhit)/(115.0-zrhit);
874 func[11] = 1.0/(115.0+zrhit)/(115.0+zrhit);
875 numParam = 12;
876 }
877 else if( ispecies==4 ) { // proton / anti-proton
878 for( unsigned int i=4; i<12; i++ ) {
879 func[i] = func[i-1]*zrhit;
880 }
881 numParam = 12;
882 }
883 }
884 else { // endcap
885 numParam = 4;
886 }
887
888 unsigned int inumber = ipmt;
889 if( !barrel ) { inumber=7; }
890
891 double sigma = 0.0;
892 if( ispecies==2 || ispecies==3 ) { // pion / kaon
893 for( unsigned int i=0; i<numParam; i++ ) {
894 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
895 }
896 }
897 else if( ispecies==4 ) {
898 if( ibgbin!=-1 ) {
899 // Jpsi2012
900 if( barrel ) {
901 if( charge==1 ) {
902 sigma = m_p_sigma_12[0][inumber][ibgbin][izbin];
903 }
904 else {
905 sigma = m_p_sigma_12[1][inumber][ibgbin][izbin];
906 }
907 }
908 else {
909 if( charge==1 ) {
910 sigma = m_p_sigma_ec12[0][ibgbin][izbin];
911 }
912 else {
913 sigma = m_p_sigma_ec12[1][ibgbin][izbin];
914 }
915 }
916 if( fabs(sigma+999.0)<1.0e-6 ) {
917 sigma = 0.3;
918 }
919 }
920 else {
921 for( unsigned int i=0; i<numParam; i++ ) {
922 if( charge==1 ) {
923 sigma += m_par_sigma[2][inumber][i]*func[i];
924 }
925 else {
926 sigma += m_par_sigma[3][inumber][i]*func[i];
927 }
928 }
929 }
930 }
931
932 // Jpsi2012
933 int run = getRunNo();
934 if( run>0 ) {
935 if( ispecies==2 ) {
936 sigma = sigma*(TMath::Exp((betaGamma-0.356345)/(-0.767124))+0.994072);
937 }
938 }
939
940 return sigma;
941}
942
943
944double TofCorrPID::qCurveFunc( unsigned int layer, double betaGamma ) {
945 double q0 = -100.0;
946 if( layer>=3 || betaGamma<0.0 ) {
947 cout << "Particle::TofCorrPID::qCurveFunc: the input parameter are NOT correct! Please check them!" << endl;
948 return q0;
949 }
950
951 double beta = betaGamma/sqrt(1.0+betaGamma*betaGamma);
952 double logterm = log( m_q0_bg[layer][2]+pow((1.0/betaGamma), m_q0_bg[layer][4] ) );
953 q0 = m_q0_bg[layer][0]*( m_q0_bg[layer][1]-pow( beta, m_q0_bg[layer][3] ) - logterm )/pow( beta, m_q0_bg[layer][3] );
954
955 return q0;
956}
957
958
959double TofCorrPID::bSigma( unsigned int end, int tofid, double zrhit ) {
960
961 double func[5];
962 func[0] = 1.0;
963 func[1] = zrhit;
964 func[2] = zrhit*zrhit;
965 func[3] = zrhit*zrhit*zrhit;
966 func[4] = zrhit*zrhit*zrhit*zrhit;
967
968 double sigma = 0.0;
969 for( unsigned int i=0; i<5; i++ ) {
970 sigma += m_p_weight[tofid][end][i]*func[i];
971 }
972
973 return sigma;
974}
975
976
977double TofCorrPID::bSigma( int tofid[2], double zrhit[2] ) {
978
979 double sigma1 = bSigma( 2, tofid[0], zrhit[0] );
980 double sigma2 = bSigma( 2, tofid[1], zrhit[1] );
981 double sigmaCorr2 = m_p_common*m_p_common;
982 double sigma = ( sigma1*sigma1*sigma2*sigma2 - sigmaCorr2*sigmaCorr2 )/( sigma1*sigma1 + sigma2*sigma2 - 2.0*sigmaCorr2 );
983 sigma = sqrt(fabs(sigma));
984
985 return sigma;
986}
987
988
989double TofCorrPID::eSigma( int tofid, double zrhit ) {
990
991 double func[5];
992 func[0] = 1.0;
993 func[1] = zrhit;
994 func[2] = zrhit*zrhit;
995
996 double sigma = 0.0;
997 for( unsigned int i=0; i<3; i++ ) {
998 sigma += m_ec_sigma[tofid][i]*func[i];
999 }
1000
1001 return sigma;
1002}
1003
1004
1005bool TofCorrPID::correlationCheck( unsigned int ipmt ) {
1006 bool chiCut = false;
1007 bool good = false;
1008 double pdftemp = 0;
1009 for( unsigned int i=0; i<5; i++ ) {
1010 if( ( m_chiCorr[i][ipmt]>(0.0-chiMinCut()) && m_chiCorr[i][ipmt]<chiMaxCut() ) && !good ) { good=true; }
1011 double ppp = pdfCalculate(m_chiCorr[i][ipmt],1);
1012 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
1013 }
1014 m_pdfmin = pdftemp;
1015 if( pdftemp < pdfCalculate(pdfMinSigmaCut(),1) ) return chiCut;
1016 if( !good ) return chiCut;
1017 chiCut = true;
1018 return chiCut;
1019}
double p1[4]
TTree * sigma
const double xmass[5]
Definition Gam4pikp.cxx:50
TGraph2DErrors * dt
Definition McCor.cxx:45
const double rend
Definition TofCalibFit.h:17
const double zend
Definition TofCalibFit.h:13
const double zbegin
Definition TofCalibFit.h:12
const double rbegin
Definition TofCalibFit.h:16
const Hep3Vector tof1Position() const
Definition DstExtTrack.h:58
const Hep3Vector tof2Position() const
Definition DstExtTrack.h:94
static void setPidType(PidType pidType)
const HepLorentzVector p4() const
const int charge() const
Definition DstMdcTrack.h:53
bool isExtTrackValid()
Definition EvtRecTrack.h:49
RecExtTrack * extTrack()
Definition EvtRecTrack.h:56
bool isMdcKalTrackValid()
Definition EvtRecTrack.h:44
SmartRefVector< RecTofTrack > tofTrack()
Definition EvtRecTrack.h:57
bool isTofTrackValid()
Definition EvtRecTrack.h:46
bool isMdcTrackValid()
Definition EvtRecTrack.h:43
RecMdcTrack * mdcTrack()
Definition EvtRecTrack.h:53
RecMdcKalTrack * mdcKalTrack()
Definition EvtRecTrack.h:54
double chiMinCut() const
EvtRecTrack * PidTrk() const
double probCalculate(double chi2, int n)
double chiMaxCut() const
double getRunNo() const
double pdfCalculate(double offset, double sigma)
double pdfMinSigmaCut() const
static std::string path
void inputParameter(int run)
double qCurveFunc(unsigned int layer, double betaGamma)
void init()
int particleIDCalculation()
double offset(int n) const
Definition TofCorrPID.h:26
double sigmaTof(unsigned int ispecies, int charge, bool barrel, unsigned int ipmt, int tofid[2], double zrhit[2], double betaGamma)
double bSigma(unsigned int end, int tofid, double zrhit)
void calculate()
double offsetTof(unsigned int ispecies, bool barrel, unsigned int ipmt, double betaGamma, int charge, double zrhit, double dt)
static TofCorrPID * instance()
double eSigma(int tofid, double zrhit)
int ipmt() const
Definition TofCorrPID.h:30
bool correlationCheck(unsigned int ipmt)
bool is_barrel() const
unsigned int layer() const
bool is_cluster() const
void setStatus(unsigned int status)
bool is_mrpc() const
bool is_counter() const
bool is_east() const
bool is_readout() const
bool is_raw() const
float charge
float ptrk