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