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++ ) {
100 HepLorentzVector ptrk = kalTrk->
p4();
102 HepLorentzVector ptrk = kalTrk->
p4(
xmass(i) );
105 betaGamma[i] =
p[i]/
xmass(i);
113 int tofid[2] = { -9, -9 };
115 bool readFile =
false;
116 bool signal[2] = {
false,
false };
118 for( it = tofTrk.begin(); it!=tofTrk.end(); it++ ) {
119 unsigned int st = (*it)->status();
121 if( hitst->
is_raw() )
return irc;
123 if( !barrel ) { zrhit[0] = extTrk->
tof1Position().rho(); }
127 int layer = hitst->
layer();
128 tofid[layer-1] = (*it)->tofID();
130 double tof = (*it)->tof();
133 unsigned int ipmt = 0;
136 if( barrel ) { ipmt = ( ( st & 0xC0 ) >> 5 ) + ( ( ( st ^ 0x20 ) & 0x20 ) >> 5 ) - 2; }
137 for(
unsigned int i=0; i<5; i++ ) {
138 double offset = (*it)->toffset(i);
139 double texp = (*it)->texp(i);
140 if( texp<0.0 )
continue;
142 m_deltaT[ipmt][i] =
offsetTof( i, barrel, ipmt, betaGamma[i],
charge, zrhit[layer-1],
dt );
144 if( counter && cluster ) {
145 for(
unsigned int i=0; i<5; i++ ) {
146 if( ((*it)->texp(i))>0.0 ) {
147 m_offset[i] = m_deltaT[ipmt][i];
148 m_sigma[i] =
sigmaTof( i,
charge, barrel, ipmt, &tofid[0], &zrhit[0], betaGamma[i] );
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;
160 m_deltaT[layer+3][i] =
offsetTof( i, tofid[layer-1], zrhit[layer-1],
dt );
161 m_offset[i] = m_deltaT[layer+3][i];
162 m_sigma[i] =
sigmaTof( i,
charge, barrel, layer+3, &tofid[0], &zrhit[0], betaGamma[i] );
168 if( signal[0] && signal[1] ) {
169 for(
unsigned int i=0; i<5; i++ ) {
170 double offset = (*it)->toffset(i);
171 double texp = (*it)->texp(i);
172 if( texp<0.0 )
continue;
174 m_deltaT[6][i] =
offsetTof( i, tofid[0], tofid[1], zrhit[0], zrhit[1],
dt );
175 m_offset[i] = m_deltaT[6][i];
176 m_sigma[i] =
sigmaTof( i,
charge, barrel, 6, &tofid[0], &zrhit[0], betaGamma[i] );
179 else if( signal[0] && !signal[1] ) {
180 for(
unsigned int i=0; i<5; i++ ) {
181 m_offset[i] = m_deltaT[4][i];
182 m_sigma[i] =
sigmaTof( i,
charge, barrel, 4, &tofid[0], &zrhit[0], betaGamma[i] );
185 else if( !signal[0] && signal[1] ) {
186 for(
unsigned int i=0; i<5; i++ ) {
187 m_offset[i] = m_deltaT[5][i];
188 m_sigma[i] =
sigmaTof( i,
charge, barrel, 5, &tofid[1], &zrhit[1], betaGamma[i] );
199 for(
unsigned int i=0; i<5; i++ ) {
200 m_chi[i] = m_offset[i]/m_sigma[i];
201 if( ( m_chi[i]>-4.0 && m_chi[i]<6.0 ) && !good ) { good =
true; }
203 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
207 if( !good )
return irc;
208 for(
int i = 0; i < 5; i++) {
218 std::string filePath =
path +
"/share/TofCorrPID/";
220 if(
abs(run)>=8093 &&
abs(run)<=9025 ) {
221 filePath = filePath +
"psip2009";
225 else if(
abs(run)>=9947 &&
abs(run)<=10878 ) {
226 filePath = filePath +
"jpsi2009";
232 filePath = filePath +
"/data/";
235 filePath = filePath +
"/mc/";
240 std::string fileWeight = filePath +
"calib_barrel_sigma.txt";
241 ifstream inputWeight( fileWeight.c_str(), std::ios_base::in );
243 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileWeight << endl;
247 for(
unsigned int tofid=0; tofid<176; tofid++ ) {
248 for(
unsigned int readout=0; readout<3; readout++ ) {
249 for(
unsigned int p_i=0; p_i<5; p_i++ ) {
250 inputWeight >> m_p_weight[tofid][readout][p_i];
257 std::string fileCommon = filePath +
"calib_barrel_common.txt";
258 ifstream inputCommon( fileCommon.c_str(), std::ios_base::in );
260 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileCommon << endl;
263 inputCommon >> m_p_common;
267 std::string fileEcSigma = filePath +
"calib_endcap_sigma.txt";
268 ifstream inputEcSigma( fileEcSigma.c_str(), std::ios_base::in );
269 if( !inputEcSigma ) {
270 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileEcSigma << endl;
274 for(
unsigned int tofid=0; tofid<96; tofid++ ) {
275 for(
unsigned int p_i=0; p_i<3; p_i++ ) {
276 inputEcSigma >> m_ec_sigma[tofid][p_i];
282 std::string fileQ0BetaGamma = filePath +
"curve_Q0_BetaGamma.txt";
283 ifstream inputQ0BetaGamma( fileQ0BetaGamma.c_str(), std::ios_base::in );
284 if( !inputQ0BetaGamma ) {
285 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileQ0BetaGamma << endl;
289 for(
unsigned int layer=0; layer<3; layer++ ) {
290 for(
unsigned int ipar=0; ipar<5; ipar++ ) {
291 inputQ0BetaGamma >> m_q0_bg[layer][ipar];
297 std::string fileParAB = filePath +
"parameter_A_B.txt";
298 ifstream inputParAB( fileParAB.c_str(), std::ios_base::in );
300 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileParAB << endl;
305 for(
unsigned int ipmt=0; ipmt<5; ipmt++ ) {
306 for(
unsigned int iab=0; iab<2; iab++ ) {
307 for(
unsigned int ipar=0; ipar<5; ipar++ ) {
308 inputParAB >> m_par_ab[ipmt][iab][ipar];
312 for(
unsigned int ipmt=0; ipmt<5; ipmt++ ) {
313 for(
unsigned int iab=0; iab<2; iab++ ) {
314 for(
unsigned int ipar=0; ipar<5; ipar++ ) {
315 inputParAB >> m_par_pbar_ab[ipmt][iab][ipar];
322 std::string fileSigma = filePath +
"parameter_sigma.txt";
323 ifstream inputSigma( fileSigma.c_str(), std::ios_base::in );
325 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileSigma << endl;
332 for(
unsigned int ispecies=0; ispecies<4; ispecies++ ) {
333 for(
unsigned int ipmt=0; ipmt<8; ipmt++ ) {
334 for(
unsigned int ipar=0; ipar<9; ipar++ ) {
335 inputSigma >> m_par_sigma[ispecies][ipmt][ipar];
363 std::string fileProtonOffset = filePath +
"parameter_offset_proton.txt";
364 ifstream inputProtonOffset( fileProtonOffset.c_str(), std::ios_base::in );
365 if( !inputProtonOffset ) {
366 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileProtonOffset << endl;
371 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
372 for(
unsigned int ipmt=0; ipmt<4; ipmt++ ) {
373 for(
unsigned int ipar=0; ipar<10; ipar++ ) {
374 for(
unsigned int jpar=0; jpar<20; jpar++ ) {
375 inputProtonOffset >> m_p_offset[ispecies][ipmt][ipar][jpar];
383 std::string fileProtonSigma = filePath +
"parameter_sigma_proton.txt";
384 ifstream inputProtonSigma( fileProtonSigma.c_str(), std::ios_base::in );
385 if( !inputProtonSigma ) {
386 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileProtonSigma << endl;
393 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
394 for(
unsigned int ipmt=0; ipmt<7; ipmt++ ) {
395 for(
unsigned int ipar=0; ipar<10; ipar++ ) {
396 for(
unsigned int jpar=0; jpar<20; jpar++ ) {
397 inputProtonSigma >> m_p_sigma[ispecies][ipmt][ipar][jpar];
409double TofCorrPID::offsetTof(
unsigned int ispecies,
bool barrel,
unsigned int ipmt,
double betaGamma,
int charge,
double zrhit,
double dt ) {
410 if( ispecies==0 || ispecies==1 ) {
return dt; }
412 double deltaT = -1000.0;
413 if( ( ipmt>= 4 && barrel ) || ( ipmt!=0 && !barrel ) || betaGamma<0.0 ||
abs(
charge)!=1 || fabs(zrhit)>120.0 ) {
414 cout <<
"Particle::TofCorrPID: offsetTof for single end: the input parameter are NOT correct! Please check them!" << endl;
417 unsigned int layer=0;
419 if( ipmt==0 || ipmt==1 ) { layer=0; }
420 else if( ipmt==2 || ipmt==3 ) { layer=1; }
425 unsigned int inumber=ipmt;
426 if( !barrel ) { inumber=4; }
431 func[2] = zrhit*zrhit;
432 func[3] = zrhit*zrhit*zrhit;
433 func[4] = zrhit*zrhit*zrhit*zrhit;
438 if( ispecies==4 &&
charge==-1 ) {
439 for(
unsigned int i=0; i<5; i++ ) {
440 parA += m_par_pbar_ab[inumber][0][i]*func[i];
441 parB += m_par_pbar_ab[inumber][1][i]*func[i];
446 for(
unsigned int i=0; i<5; i++ ) {
447 parA += m_par_ab[inumber][0][i]*func[i];
448 parB += m_par_ab[inumber][1][i]*func[i];
452 double tcorr = parA + parB/sqrt(q0);
455 if( barrel && ispecies==4 && betaGamma<0.8 ) {
461 double nbgbin = 20.0;
462 double bgbegin[2] = { 0.4, 0.55 };
463 double bgend[2] = { 0.8, 0.8 };
465 bgstep[0] = (bgend[0]-bgbegin[0])/nbgbin;
466 bgstep[1] = (bgend[1]-bgbegin[1])/nbgbin;
468 int izbin =
static_cast<int>((zrhit-
zbegin)/zstep);
469 if( izbin<0 ) { izbin=0; }
470 else if( izbin>=nzbin ) { izbin=nzbin-1; }
471 unsigned int layer=0;
472 if( ipmt==2 || ipmt==3 ) { layer=1; }
473 int ibgbin =
static_cast<int>((betaGamma-bgbegin[layer])/bgstep[layer]);
474 if( ibgbin<0 ) { ibgbin=0; }
475 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
478 tcorr += m_p_offset[0][ipmt][izbin][ibgbin];
481 tcorr += m_p_offset[1][ipmt][izbin][ibgbin];
492 if( ispecies==0 || ispecies==1 ) {
return dt; }
494 double deltaT = -1000.0;
495 if( tofid<0 || tofid>=176 ) {
496 cout <<
"Particle::TofCorrPID: offsetTof for single layer: the input parameter are NOT correct! Please check them!" << endl;
499 int pmt[3] = { -9, -9, -9 };
500 if( tofid>=0 && tofid<=87 ) {
511 double sigmaCorr2 = m_p_common*m_p_common;
512 double sigmaLeft =
bSigma( 0, tofid, zrhit );
513 double sigmaLeft2 = sigmaLeft*sigmaLeft;
514 double sigmaRight =
bSigma( 1, tofid, zrhit );
515 double sigmaRight2 = sigmaRight*sigmaRight;
517 double fraction = ( sigmaRight2 - sigmaCorr2 )/( sigmaLeft2 + sigmaRight2 - 2.0*sigmaCorr2);
518 deltaT = fraction*m_deltaT[pmt[0]][ispecies] + (1.0-fraction)*m_deltaT[pmt[1]][ispecies];
525 if( ispecies==0 || ispecies==1 ) {
return dt; }
527 double deltaT = -1000.0;
528 if( tofid1<0 || tofid1>=88 || tofid2<88 || tofid2>=176 ) {
529 cout <<
"Particle::TofCorrPID: offsetTof for double layer: the input parameter are NOT correct! Please check them!" << endl;
533 double sigmaCorr2 = m_p_common*m_p_common;
534 double sigmaInner =
bSigma( 2, tofid1, zrhit1 );
535 double sigmaInner2 = sigmaInner*sigmaInner;
536 double sigmaOuter =
bSigma( 2, tofid2, zrhit2 );
537 double sigmaOuter2 = sigmaOuter*sigmaOuter;
538 double sigma = sqrt( (sigmaInner2*sigmaOuter2-sigmaCorr2*sigmaCorr2)/(sigmaInner2+sigmaOuter2-2.0*sigmaCorr2) );
543 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
544 deltaT = fraction*m_deltaT[4][ispecies] + (1.0-fraction)*m_deltaT[5][ispecies];
550double TofCorrPID::sigmaTof(
unsigned int ispecies,
int charge,
bool barrel,
unsigned int ipmt,
int tofid[2],
double zrhit[2],
double betaGamma ) {
552 double sigma = 1.0e-6;
554 if( ispecies==0 || ispecies==1 ) {
585 if( ipmt==2 || ipmt==3 || ipmt==5 ) { iz=1; }
587 if( barrel && ispecies==4 && betaGamma<0.8 ) {
588 double nbgbin = 20.0;
589 double bgbegin[2] = { 0.4, 0.55 };
590 double bgend[2] = { 0.8, 0.8 };
592 bgstep[0] = (bgend[0]-bgbegin[0])/nbgbin;
593 bgstep[1] = (bgend[1]-bgbegin[1])/nbgbin;
595 ibgbin =
static_cast<int>((betaGamma-bgbegin[iz])/bgstep[iz]);
596 if( ibgbin<0 ) { ibgbin=0; }
597 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
607double TofCorrPID::sigmaTof(
unsigned int ispecies,
int charge,
bool barrel,
unsigned int ipmt,
double zrhit,
int ibgbin ) {
610 if( barrel && ispecies==4 && ibgbin!=-1 ) {
616 izbin =
static_cast<int>((zrhit-
zbegin)/zstep);
617 if( izbin<0 ) { izbin=0; }
618 else if( izbin>=nzbin ) { izbin=nzbin-1; }
622 for(
unsigned int i=0; i<9; i++ ) {
623 if( i==0 ) { func[i] = 1.0; }
625 func[i] = func[i-1]*zrhit;
628 func[9] = -1.0/(zrhit*zrhit-115.0*115.0);
630 unsigned int inumber = ipmt;
631 if( !barrel ) { inumber=7; }
637 if( ipmt==0 || ipmt==1 ) {
638 if( ispecies==2 || ispecies==3 ) {
639 for(
unsigned int i=0; i<5; i++ ) {
641 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
644 sigma += m_par_sigma[ispecies-2][inumber][i]*func[9];
648 else if( ispecies==4 ) {
651 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
654 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
658 for(
unsigned int i=0; i<7; i++ ) {
660 sigma += m_par_sigma[2][inumber][i]*func[i];
663 sigma += m_par_sigma[3][inumber][i]*func[i];
670 else if( ipmt==2 || ipmt==3 ) {
671 if( ispecies==2 || ispecies==3 ) {
672 for(
unsigned int i=0; i<4; i++ ) {
674 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
677 sigma += m_par_sigma[ispecies-2][inumber][i]*func[9];
681 else if( ispecies==4 ) {
684 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
687 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
691 for(
unsigned int i=0; i<5; i++ ) {
693 sigma += m_par_sigma[2][inumber][i]*func[i];
696 sigma += m_par_sigma[3][inumber][i]*func[i];
703 else if( ipmt==4 || ipmt==5 ) {
705 for(
unsigned int i=0; i<5; i++ ) {
707 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
710 sigma += m_par_sigma[ispecies-2][inumber][i]*func[9];
714 else if( ispecies==3 ) {
715 for(
unsigned int i=0; i<4; i++ ) {
716 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
719 else if( ispecies==4 ) {
722 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
725 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
729 for(
unsigned int i=0; i<9; i++ ) {
731 sigma += m_par_sigma[2][inumber][i]*func[i];
734 sigma += m_par_sigma[3][inumber][i]*func[i];
742 if( ispecies==2 || ispecies==3 ) {
743 for(
unsigned int i=0; i<5; i++ ) {
744 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
747 else if( ispecies==4 ) {
750 sigma = m_p_sigma[0][inumber][izbin][ibgbin];
753 sigma = m_p_sigma[1][inumber][izbin][ibgbin];
757 for(
unsigned int i=0; i<9; i++ ) {
759 sigma += m_par_sigma[2][inumber][i]*func[i];
762 sigma += m_par_sigma[3][inumber][i]*func[i];
771 if( ispecies==2 || ispecies==3 ) {
772 for(
unsigned int i=0; i<3; i++ ) {
773 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
776 else if( ispecies==4 ) {
777 for(
unsigned int i=0; i<4; i++ ) {
779 if(
charge==-1 ) { iparticle=5; }
781 sigma += m_par_sigma[iparticle-2][inumber][i]*func[i];
784 sigma += m_par_sigma[iparticle-2][inumber][i]*func[9];
810 if( layer>=3 || betaGamma<0.0 ) {
811 cout <<
"Particle::TofCorrPID::qCurveFunc: the input parameter are NOT correct! Please check them!" << endl;
815 double beta = betaGamma/sqrt(1.0+betaGamma*betaGamma);
816 double logterm = log( m_q0_bg[layer][2]+pow((1.0/betaGamma), m_q0_bg[layer][4] ) );
817 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] );
828 func[2] = zrhit*zrhit;
829 func[3] = zrhit*zrhit*zrhit;
830 func[4] = zrhit*zrhit*zrhit*zrhit;
833 for(
unsigned int i=0; i<5; i++ ) {
834 sigma += m_p_weight[tofid][end][i]*func[i];
843 double sigma1 =
bSigma( 2, tofid[0], zrhit[0] );
845 double sigmaCorr2 = m_p_common*m_p_common;
858 func[2] = zrhit*zrhit;
861 for(
unsigned int i=0; i<3; i++ ) {
862 sigma += m_ec_sigma[tofid][i]*func[i];
873 for(
unsigned int i=0; i<5; i++ ) {
874 m_chi[i] = m_offset[i]/m_sigma[i];
875 if( ( m_chi[i]>-4.0 && m_chi[i]<6.0 ) && !good ) { good=
true; }
877 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
881 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)