31 for(
int i = 0; i < 5; i++) {
35 m_offset[i] = -1000.0;
41 for(
unsigned int i=0; i<5; i++ ) {
42 for(
unsigned int j=0; j<7; j++ ) {
43 m_deltaT[j][i] = -1000.0;
48 if( !(
abs(run)>=m_runBegin &&
abs(run)<=m_runEnd ) ) {
71 SmartRefVector<RecTofTrack> tofTrk = recTrk->
tofTrack();
72 SmartRefVector<RecTofTrack>::iterator it;
74 const std::vector<TTofTrack* >& tofTrk = recTrk->
tofTrack();
75 std::vector<TTofTrack* >::const_iterator it;
81 double p[5], betaGamma[5];
83 for(
int i=0; i<5; i++ ) {
99 HepLorentzVector ptrk = kalTrk->
p4();
101 betaGamma[i] =
p[i]/
xmass(i);
109 int tofid[2] = { -9, -9 };
111 bool readFile =
false;
112 bool signal[2] = {
false,
false };
114 for( it = tofTrk.begin(); it!=tofTrk.end(); it++ ) {
115 unsigned int st = (*it)->status();
117 if( hitst->
is_raw() )
return irc;
119 if( !barrel ) { zrhit[0] = extTrk->
tof1Position().rho(); }
123 int layer = hitst->
layer();
124 tofid[layer-1] = (*it)->tofID();
126 double tof = (*it)->tof();
129 unsigned int ipmt = 0;
132 if( barrel ) { ipmt = ( ( st & 0xC0 ) >> 5 ) + ( ( ( st ^ 0x20 ) & 0x20 ) >> 5 ) - 2; }
133 for(
unsigned int i=0; i<5; i++ ) {
134 double offset = (*it)->toffset(i);
135 double texp = (*it)->texp(i);
136 if( texp<0.0 )
continue;
138 m_deltaT[ipmt][i] =
offsetTof( i, barrel, ipmt, betaGamma[i],
charge, zrhit[layer-1],
dt );
140 if( counter && cluster ) {
141 for(
unsigned int i=0; i<5; i++ ) {
142 if( ((*it)->texp(i))>0.0 ) {
143 m_offset[i] = m_deltaT[ipmt][i];
144 m_sigma[i] =
sigmaTof( i,
charge, barrel, ipmt, &tofid[0], &zrhit[0], betaGamma[i] );
151 for(
unsigned int i=0; i<5; i++ ) {
152 double offset = (*it)->toffset(i);
153 double texp = (*it)->texp(i);
154 if( texp<0.0 )
continue;
156 m_deltaT[layer+3][i] =
offsetTof( i, tofid[layer-1], zrhit[layer-1],
dt );
157 m_offset[i] = m_deltaT[layer+3][i];
158 m_sigma[i] =
sigmaTof( i,
charge, barrel, layer+3, &tofid[0], &zrhit[0], betaGamma[i] );
164 if( signal[0] && signal[1] ) {
165 for(
unsigned int i=0; i<5; i++ ) {
166 double offset = (*it)->toffset(i);
167 double texp = (*it)->texp(i);
168 if( texp<0.0 )
continue;
170 m_deltaT[6][i] =
offsetTof( i, tofid[0], tofid[1], zrhit[0], zrhit[1],
dt );
171 m_offset[i] = m_deltaT[6][i];
172 m_sigma[i] =
sigmaTof( i,
charge, barrel, 6, &tofid[0], &zrhit[0], betaGamma[i] );
175 else if( signal[0] && !signal[1] ) {
176 for(
unsigned int i=0; i<5; i++ ) {
177 m_offset[i] = m_deltaT[4][i];
178 m_sigma[i] =
sigmaTof( i,
charge, barrel, 4, &tofid[0], &zrhit[0], betaGamma[i] );
181 else if( !signal[0] && signal[1] ) {
182 for(
unsigned int i=0; i<5; i++ ) {
183 m_offset[i] = m_deltaT[5][i];
184 m_sigma[i] =
sigmaTof( i,
charge, barrel, 5, &tofid[1], &zrhit[1], betaGamma[i] );
195 for(
unsigned int i=0; i<5; i++ ) {
196 m_chi[i] = m_offset[i]/m_sigma[i];
197 if( ( m_chi[i]>-4.0 && m_chi[i]<6.0 ) && !good ) { good =
true; }
199 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
203 if( !good )
return irc;
204 for(
int i = 0; i < 5; i++) {
214 std::string filePath =
path +
"/share/TofCorrPID/";
216 if(
abs(run)>=8093 &&
abs(run)<=9025 ) {
217 filePath = filePath +
"psip2009";
221 else if(
abs(run)>=9947 &&
abs(run)<=10878 ) {
222 filePath = filePath +
"jpsi2009";
228 filePath = filePath +
"/data/";
231 filePath = filePath +
"/mc/";
236 std::string fileWeight = filePath +
"calib_barrel_sigma.txt";
237 ifstream inputWeight( fileWeight.c_str(), std::ios_base::in );
239 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileWeight << endreq;
243 for(
unsigned int tofid=0; tofid<176; tofid++ ) {
244 for(
unsigned int readout=0; readout<3; readout++ ) {
245 for(
unsigned int p_i=0; p_i<5; p_i++ ) {
246 inputWeight >> m_p_weight[tofid][readout][p_i];
253 std::string fileCommon = filePath +
"calib_barrel_common.txt";
254 ifstream inputCommon( fileCommon.c_str(), std::ios_base::in );
256 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileCommon << endreq;
259 inputCommon >> m_p_common;
263 std::string fileEcSigma = filePath +
"calib_endcap_sigma.txt";
264 ifstream inputEcSigma( fileEcSigma.c_str(), std::ios_base::in );
265 if( !inputEcSigma ) {
266 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileEcSigma << endreq;
270 for(
unsigned int tofid=0; tofid<96; tofid++ ) {
271 for(
unsigned int p_i=0; p_i<3; p_i++ ) {
272 inputEcSigma >> m_ec_sigma[tofid][p_i];
278 std::string fileQ0BetaGamma = filePath +
"curve_Q0_BetaGamma.txt";
279 ifstream inputQ0BetaGamma( fileQ0BetaGamma.c_str(), std::ios_base::in );
280 if( !inputQ0BetaGamma ) {
281 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileQ0BetaGamma << endreq;
285 for(
unsigned int layer=0; layer<3; layer++ ) {
286 for(
unsigned int ipar=0; ipar<5; ipar++ ) {
287 inputQ0BetaGamma >> m_q0_bg[layer][ipar];
293 std::string fileParAB = filePath +
"parameter_A_B.txt";
294 ifstream inputParAB( fileParAB.c_str(), std::ios_base::in );
296 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileParAB << endreq;
301 for(
unsigned int ipmt=0; ipmt<5; ipmt++ ) {
302 for(
unsigned int iab=0; iab<2; iab++ ) {
303 for(
unsigned int ipar=0; ipar<5; ipar++ ) {
304 inputParAB >> m_par_ab[ipmt][iab][ipar];
308 for(
unsigned int ipmt=0; ipmt<5; ipmt++ ) {
309 for(
unsigned int iab=0; iab<2; iab++ ) {
310 for(
unsigned int ipar=0; ipar<5; ipar++ ) {
311 inputParAB >> m_par_pbar_ab[ipmt][iab][ipar];
318 std::string fileSigma = filePath +
"parameter_sigma.txt";
319 ifstream inputSigma( fileSigma.c_str(), std::ios_base::in );
321 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileSigma << endreq;
328 for(
unsigned int ispecies=0; ispecies<4; ispecies++ ) {
329 for(
unsigned int ipmt=0; ipmt<8; ipmt++ ) {
330 for(
unsigned int ipar=0; ipar<9; ipar++ ) {
331 inputSigma >> m_par_sigma[ispecies][ipmt][ipar];
359 std::string fileProtonOffset = filePath +
"parameter_offset_proton.txt";
360 ifstream inputProtonOffset( fileProtonOffset.c_str(), std::ios_base::in );
361 if( !inputProtonOffset ) {
362 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileProtonOffset << endreq;
367 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
368 for(
unsigned int ipmt=0; ipmt<4; ipmt++ ) {
369 for(
unsigned int ipar=0; ipar<10; ipar++ ) {
370 for(
unsigned int jpar=0; jpar<20; jpar++ ) {
371 inputProtonOffset >> m_p_offset[ispecies][ipmt][ipar][jpar];
379 std::string fileProtonSigma = filePath +
"parameter_sigma_proton.txt";
380 ifstream inputProtonSigma( fileProtonSigma.c_str(), std::ios_base::in );
381 if( !inputProtonSigma ) {
382 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileProtonSigma << endreq;
389 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
390 for(
unsigned int ipmt=0; ipmt<7; ipmt++ ) {
391 for(
unsigned int ipar=0; ipar<10; ipar++ ) {
392 for(
unsigned int jpar=0; jpar<20; jpar++ ) {
393 inputProtonSigma >> m_p_sigma[ispecies][ipmt][ipar][jpar];
405double TofCorrPID::offsetTof(
unsigned int ispecies,
bool barrel,
unsigned int ipmt,
double betaGamma,
int charge,
double zrhit,
double dt ) {
406 if( ispecies==0 || ispecies==1 ) {
return dt; }
408 double deltaT = -1000.0;
409 if( ( ipmt>= 4 && barrel ) || ( ipmt!=0 && !barrel ) || betaGamma<0.0 ||
abs(
charge)!=1 || fabs(zrhit)>120.0 ) {
410 cout <<
"Particle::TofCorrPID: offsetTof for single end: the input parameter are NOT correct! Please check them!" << endl;
413 unsigned int layer=0;
415 if( ipmt==0 || ipmt==1 ) { layer=0; }
416 else if( ipmt==2 || ipmt==3 ) { layer=1; }
421 unsigned int inumber=ipmt;
422 if( !barrel ) { inumber=4; }
427 func[2] = zrhit*zrhit;
428 func[3] = zrhit*zrhit*zrhit;
429 func[4] = zrhit*zrhit*zrhit*zrhit;
434 if( ispecies==4 &&
charge==-1 ) {
435 for(
unsigned int i=0; i<5; i++ ) {
436 parA += m_par_pbar_ab[inumber][0][i]*func[i];
437 parB += m_par_pbar_ab[inumber][1][i]*func[i];
442 for(
unsigned int i=0; i<5; i++ ) {
443 parA += m_par_ab[inumber][0][i]*func[i];
444 parB += m_par_ab[inumber][1][i]*func[i];
448 double tcorr = parA + parB/sqrt(q0);
451 if( barrel && ispecies==4 && betaGamma<0.8 ) {
457 double nbgbin = 20.0;
458 double bgbegin[2] = { 0.4, 0.55 };
459 double bgend[2] = { 0.8, 0.8 };
461 bgstep[0] = (bgend[0]-bgbegin[0])/nbgbin;
462 bgstep[1] = (bgend[1]-bgbegin[1])/nbgbin;
464 int izbin =
static_cast<int>((zrhit-
zbegin)/zstep);
465 if( izbin<0 ) { izbin=0; }
466 else if( izbin>=nzbin ) { izbin=nzbin-1; }
467 unsigned int layer=0;
468 if( ipmt==2 || ipmt==3 ) { layer=1; }
469 int ibgbin =
static_cast<int>((betaGamma-bgbegin[layer])/bgstep[layer]);
470 if( ibgbin<0 ) { ibgbin=0; }
471 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
474 tcorr += m_p_offset[0][ipmt][izbin][ibgbin];
477 tcorr += m_p_offset[1][ipmt][izbin][ibgbin];
488 if( ispecies==0 || ispecies==1 ) {
return dt; }
490 double deltaT = -1000.0;
491 if( tofid<0 || tofid>=176 ) {
492 cout <<
"Particle::TofCorrPID: offsetTof for single layer: the input parameter are NOT correct! Please check them!" << endl;
495 int pmt[3] = { -9, -9, -9 };
496 if( tofid>=0 && tofid<=87 ) {
507 double sigmaCorr2 = m_p_common*m_p_common;
508 double sigmaLeft =
bSigma( 0, tofid, zrhit );
509 double sigmaLeft2 = sigmaLeft*sigmaLeft;
510 double sigmaRight =
bSigma( 1, tofid, zrhit );
511 double sigmaRight2 = sigmaRight*sigmaRight;
513 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
514 deltaT = fraction*m_deltaT[pmt[0]][ispecies] + (1.0-fraction)*m_deltaT[pmt[1]][ispecies];
521 if( ispecies==0 || ispecies==1 ) {
return dt; }
523 double deltaT = -1000.0;
524 if( tofid1<0 || tofid1>=88 || tofid2<88 || tofid2>=176 ) {
525 cout <<
"Particle::TofCorrPID: offsetTof for double layer: the input parameter are NOT correct! Please check them!" << endl;
529 double sigmaCorr2 = m_p_common*m_p_common;
530 double sigmaInner =
bSigma( 2, tofid1, zrhit1 );
531 double sigmaInner2 = sigmaInner*sigmaInner;
532 double sigmaOuter =
bSigma( 2, tofid2, zrhit2 );
533 double sigmaOuter2 = sigmaOuter*sigmaOuter;
534 double sigma = sqrt( (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2) );
539 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
540 deltaT = fraction*m_deltaT[4][ispecies] + (1.0-fraction)*m_deltaT[5][ispecies];
546double TofCorrPID::sigmaTof(
unsigned int ispecies,
int charge,
bool barrel,
unsigned int ipmt,
int tofid[2],
double zrhit[2],
double betaGamma ) {
548 double sigma = 1.0e-6;
550 if( ispecies==0 || ispecies==1 ) {
581 if( ipmt==2 || ipmt==3 || ipmt==5 ) { iz=1; }
583 if( barrel && ispecies==4 && betaGamma<0.8 ) {
584 double nbgbin = 20.0;
585 double bgbegin[2] = { 0.4, 0.55 };
586 double bgend[2] = { 0.8, 0.8 };
588 bgstep[0] = (bgend[0]-bgbegin[0])/nbgbin;
589 bgstep[1] = (bgend[1]-bgbegin[1])/nbgbin;
591 ibgbin =
static_cast<int>((betaGamma-bgbegin[iz])/bgstep[iz]);
592 if( ibgbin<0 ) { ibgbin=0; }
593 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
603double TofCorrPID::sigmaTof(
unsigned int ispecies,
int charge,
bool barrel,
unsigned int ipmt,
double zrhit,
int ibgbin ) {
606 if( barrel && ispecies==4 && ibgbin!=-1 ) {
612 izbin =
static_cast<int>((zrhit-
zbegin)/zstep);
613 if( izbin<0 ) { izbin=0; }
614 else if( izbin>=nzbin ) { izbin=nzbin-1; }
618 for(
unsigned int i=0; i<9; i++ ) {
619 if( i==0 ) { func[i] = 1.0; }
621 func[i] = func[i-1]*zrhit;
624 func[9] = -1.0/(zrhit*zrhit-115.0*115.0);
626 unsigned int inumber = ipmt;
627 if( !barrel ) { inumber=7; }
633 if( ipmt==0 || ipmt==1 ) {
634 if( ispecies==2 || ispecies==3 ) {
635 for(
unsigned int i=0; i<5; i++ ) {
637 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
640 sigma += m_par_sigma[ispecies-2][inumber][i]*func[9];
644 else if( ispecies==4 ) {
647 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
650 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
654 for(
unsigned int i=0; i<7; i++ ) {
656 sigma += m_par_sigma[2][inumber][i]*func[i];
659 sigma += m_par_sigma[3][inumber][i]*func[i];
666 else if( ipmt==2 || ipmt==3 ) {
667 if( ispecies==2 || ispecies==3 ) {
668 for(
unsigned int i=0; i<4; i++ ) {
670 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
673 sigma += m_par_sigma[ispecies-2][inumber][i]*func[9];
677 else if( ispecies==4 ) {
680 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
683 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
687 for(
unsigned int i=0; i<5; i++ ) {
689 sigma += m_par_sigma[2][inumber][i]*func[i];
692 sigma += m_par_sigma[3][inumber][i]*func[i];
699 else if( ipmt==4 || ipmt==5 ) {
701 for(
unsigned int i=0; i<5; i++ ) {
703 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
706 sigma += m_par_sigma[ispecies-2][inumber][i]*func[9];
710 else if( ispecies==3 ) {
711 for(
unsigned int i=0; i<4; i++ ) {
712 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
715 else if( ispecies==4 ) {
718 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
721 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
725 for(
unsigned int i=0; i<9; i++ ) {
727 sigma += m_par_sigma[2][inumber][i]*func[i];
730 sigma += m_par_sigma[3][inumber][i]*func[i];
738 if( ispecies==2 || ispecies==3 ) {
739 for(
unsigned int i=0; i<5; i++ ) {
740 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
743 else if( ispecies==4 ) {
746 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
749 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
753 for(
unsigned int i=0; i<9; i++ ) {
755 sigma += m_par_sigma[2][inumber][i]*func[i];
758 sigma += m_par_sigma[3][inumber][i]*func[i];
767 if( ispecies==2 || ispecies==3 ) {
768 for(
unsigned int i=0; i<3; i++ ) {
769 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
772 else if( ispecies==4 ) {
773 for(
unsigned int i=0; i<4; i++ ) {
775 if(
charge==-1 ) { iparticle=5; }
777 sigma += m_par_sigma[iparticle-2][inumber][i]*func[i];
780 sigma += m_par_sigma[iparticle-2][inumber][i]*func[9];
806 if( layer>=3 || betaGamma<0.0 ) {
807 cout <<
"Particle::TofCorrPID::qCurveFunc: the input parameter are NOT correct! Please check them!" << endl;
811 double beta = betaGamma/sqrt(1.0+betaGamma*betaGamma);
812 double logterm = log( m_q0_bg[layer][2]+pow((1.0/betaGamma), m_q0_bg[layer][4] ) );
813 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] );
824 func[2] = zrhit*zrhit;
825 func[3] = zrhit*zrhit*zrhit;
826 func[4] = zrhit*zrhit*zrhit*zrhit;
829 for(
unsigned int i=0; i<5; i++ ) {
830 sigma += m_p_weight[tofid][end][i]*func[i];
839 double sigma1 =
bSigma( 2, tofid[0], zrhit[0] );
840 double sigma2 =
bSigma( 2, tofid[1], zrhit[1] );
841 double sigmaCorr2 = m_p_common*m_p_common;
842 double sigma = ( sigma1*sigma1*sigma2*sigma2 - sigmaCorr2*sigmaCorr2 )/( sigma1*sigma1 + sigma2*sigma2 - 2.0*sigmaCorr2 );
854 func[2] = zrhit*zrhit;
857 for(
unsigned int i=0; i<3; i++ ) {
858 sigma += m_ec_sigma[tofid][i]*func[i];
869 for(
unsigned int i=0; i<5; i++ ) {
870 m_chi[i] = m_offset[i]/m_sigma[i];
871 if( ( m_chi[i]>-4.0 && m_chi[i]<6.0 ) && !good ) { good=
true; }
873 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
877 if( !good )
return chiCut;
double abs(const EvtComplex &c)
const Hep3Vector tof1Position() const
const Hep3Vector tof2Position() const
static void setPidType(PidType pidType)
const HepLorentzVector p4() const
bool isMdcKalTrackValid()
SmartRefVector< RecTofTrack > tofTrack()
RecMdcKalTrack * mdcKalTrack()
EvtRecTrack * PidTrk() const
double probCalculate(double chi2, int n)
double pdfCalculate(double offset, double sigma)
double pdfMinSigmaCut() const
void inputParameter(int run)
double qCurveFunc(unsigned int layer, double betaGamma)
int particleIDCalculation()
double sigma(int n) const
double offset(int n) const
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)
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)
unsigned int layer() const
void setStatus(unsigned int status)