77 SmartRefVector<RecTofTrack> tofTrk = recTrk->
tofTrack();
78 SmartRefVector<RecTofTrack>::iterator it;
80 const std::vector<TTofTrack* >& tofTrk = recTrk->
tofTrack();
81 std::vector<TTofTrack* >::const_iterator it;
87 double p[5], betaGamma[5];
89 for(
int i=0; i<5; i++ ) {
106 HepLorentzVector
ptrk = kalTrk->
p4();
111 betaGamma[i] =
p[i]/
xmass(i);
119 int tofid[2] = { -9, -9 };
122 bool readFile =
false;
123 bool signal[2] = {
false,
false };
125 for( it = tofTrk.begin(); it!=tofTrk.end(); it++ ) {
126 unsigned int st = (*it)->status();
128 if( hitst->
is_raw() )
return irc;
130 bool ismrpc = hitst->
is_mrpc();
131 if( !barrel && !ismrpc ) { zrhit[0] = extTrk->
tof1Position().rho(); }
135 int layer = hitst->
layer();
136 tofid[layer-1] = (*it)->tofID();
138 double tof = (*it)->tof();
139 unsigned int ipmt = 0;
143 if( barrel ) {
ipmt = ( ( st & 0xC0 ) >> 5 ) + ( ( ( st ^ 0x20 ) & 0x20 ) >> 5 ) - 2; }
146 if( tofid[0]<=47 ) {
ipmt = 7; }
150 if( tofid[0]<=35 ) {
ipmt = 7; }
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;
164 m_chiCorr[i][
ipmt] = m_dtCorr[i][
ipmt]/m_sigCorr[i][
ipmt];
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];
177 int strip = (*it)->strip();
179 if( strip<0 || strip>11 ) { m_sigCorr[i][0] = 0.065; }
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]; }
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];
201 if( counter && cluster ) {
203 for(
unsigned int i=0; i<5; i++ ) {
204 if( ((*it)->texp(i))>0.0 ) {
206 m_offset[i] = m_dtCorr[i][
ipmt];
207 m_sigma[i] = m_sigCorr[i][
ipmt];
210 m_offset[i] = m_dtCorr[i][0];
211 m_sigma[i] = m_sigCorr[i][0];
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;
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];
236 int strip = (*it)->strip();
238 if( strip<0 || strip>11 ) { m_sigCorr[i][0] = 0.065; }
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]; }
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];
259 cout <<
"ParticleID: TofCorr::particleIDCalculation: Endcap Scintillator TOF have more than one end!!!" << endl;
265 for(
unsigned int i=0; i<5; i++ ) {
266 if( ((*it)->texp(i))>0.0 ) {
268 m_offset[i] = m_dtCorr[i][
ipmt];
269 m_sigma[i] = m_sigCorr[i][
ipmt];
272 m_offset[i] = m_dtCorr[i][0];
273 m_sigma[i] = m_sigCorr[i][0];
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;
291 m_dtCorr[i][
ipmt] =
offsetTof( i, tofid[0], tofid[1], zrhit[0], zrhit[1], betaGamma[i],
charge,
dt );
293 m_chiCorr[i][
ipmt] = m_dtCorr[i][
ipmt]/m_sigCorr[i][
ipmt];
295 if( signal[0] && signal[1] ) {
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];
302 else if( signal[0] && !signal[1] ) {
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];
309 else if( !signal[0] && signal[1] ) {
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];
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]; }
329 if( fabs(ppp) > pdftemp) { pdftemp = fabs(ppp); }
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++) {
346 std::string filePath =
path +
"/share/TofCorrPID/";
348 filePath = filePath +
"jpsi2012";
353 filePath = filePath +
"/data/";
356 filePath = filePath +
"/mc/";
361 std::string fileWeight = filePath +
"calib_barrel_sigma.txt";
362 ifstream inputWeight( fileWeight.c_str(), std::ios_base::in );
364 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileWeight << endl;
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];
378 std::string fileCommon = filePath +
"calib_barrel_common.txt";
379 ifstream inputCommon( fileCommon.c_str(), std::ios_base::in );
381 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileCommon << endl;
384 inputCommon >> m_p_common;
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;
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];
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;
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];
418 std::string fileParAB = filePath +
"parameter_A_B.txt";
419 ifstream inputParAB( fileParAB.c_str(), std::ios_base::in );
421 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileParAB << endl;
430 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
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];
443 std::string fileSigma = filePath +
"parameter_sigma.txt";
444 ifstream inputSigma( fileSigma.c_str(), std::ios_base::in );
446 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileSigma << endl;
454 for(
unsigned int ispecies=0; ispecies<4; ispecies++ ) {
456 for(
unsigned int ipar=0; ipar<12; ipar++ ) {
457 inputSigma >> m_par_sigma[ispecies][
ipmt][ipar];
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;
475 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
477 for(
unsigned int ipar=0; ipar<20; ipar++ ) {
479 for(
unsigned int jpar=0; jpar<46; jpar++ ) {
480 inputProtonOffset >> m_p_offset_12[ispecies][
ipmt][ipar][jpar];
484 for(
unsigned int jpar=0; jpar<7; jpar++ ) {
485 inputProtonOffset >> m_p_offset_ec12[ispecies][ipar][jpar];
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;
506 for(
unsigned int ispecies=0; ispecies<2; ispecies++ ) {
508 for(
unsigned int ipar=0; ipar<20; ipar++ ) {
510 for(
unsigned int jpar=0; jpar<46; jpar++ ) {
511 inputProtonSigma >> m_p_sigma_12[ispecies][
ipmt][ipar][jpar];
515 for(
unsigned int jpar=0; jpar<7; jpar++ ) {
516 inputProtonSigma >> m_p_sigma_ec12[ispecies][ipar][jpar];
529 if( ispecies==0 || ispecies==1 ) {
return dt; }
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 ) {
536 unsigned int layer=0;
538 if(
ipmt==0 ||
ipmt==1 ) { layer=0; }
539 else if(
ipmt==2 ||
ipmt==3 ) { layer=1; }
544 unsigned int inumber=
ipmt;
545 if( !barrel ) { inumber=4; }
548 for(
unsigned int i=0; i<9; i++ ) {
557 for(
unsigned int i=1; i<8; i++ ) {
558 func[i] = func[i-1]*zrhit;
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; }
568 if( ispecies!=4 || betaGamma*
xmass(4)>0.8 ) {
569 for(
unsigned int i=0; i<8; i++ ) {
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];
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];
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]);
590 double tcorr = parA + parB/sqrt(q0);
594 if( barrel && ispecies==4 && betaGamma*
xmass(4)<0.8 ) {
600 double nbgbin = 20.0;
601 double bgbegin = 0.3;
604 bgstep = (bgend-bgbegin)/nbgbin;
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; }
614 tcorr = m_p_offset_12[0][
ipmt][ibgbin][izbin];
617 tcorr = m_p_offset_12[1][
ipmt][ibgbin][izbin];
620 else if( !barrel && ispecies==4 && betaGamma*
xmass(4)<0.8 ) {
626 double nbgbin = 20.0;
627 double bgbegin = 0.3;
630 bgstep = (bgend-bgbegin)/nbgbin;
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; }
640 tcorr = m_p_offset_ec12[0][ibgbin][irbin];
643 tcorr = m_p_offset_ec12[1][ibgbin][irbin];
654 if( ispecies==0 || ispecies==1 ) {
return dt; }
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;
661 int pmt[3] = { -9, -9, -9 };
662 if( tofid>=0 && tofid<=87 ) {
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;
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]];
684 unsigned int ipmt = 4;
685 if( tofid>=88 && tofid<176 ) {
ipmt = 5; }
686 if( ispecies==4 && betaGamma*
xmass(4)<0.8 ) {
692 double nbgbin = 20.0;
693 double bgbegin = 0.3;
696 bgstep = (bgend-bgbegin)/nbgbin;
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; }
706 tcorr = m_p_offset_12[0][
ipmt][ibgbin][izbin];
709 tcorr = m_p_offset_12[1][
ipmt][ibgbin][izbin];
712 deltaT = deltaT - tcorr;
719 if( ispecies==0 || ispecies==1 ) {
return dt; }
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;
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) );
737 double fraction = ( sigmaOuter2 - sigmaCorr2 )/( sigmaInner2 + sigmaOuter2 - 2.0*sigmaCorr2);
738 deltaT = fraction*m_dtCorr[ispecies][4] + (1.0-fraction)*m_dtCorr[ispecies][5];
742 if( ispecies==4 && betaGamma*
xmass(4)<0.8 ) {
748 double nbgbin = 20.0;
749 double bgbegin = 0.3;
752 bgstep = (bgend-bgbegin)/nbgbin;
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; }
762 tcorr = m_p_offset_12[0][6][ibgbin][izbin];
765 tcorr = m_p_offset_12[1][6][ibgbin][izbin];
768 deltaT = deltaT - tcorr;
774double TofCorrPID::sigmaTof(
unsigned int ispecies,
int charge,
bool barrel,
unsigned int ipmt,
int tofid[2],
double zrhit[2],
double betaGamma ) {
776 double sigma = 1.0e-6;
778 if( ispecies==0 || ispecies==1 ) {
822 if( ispecies==4 && (betaGamma*
xmass(4))<0.8 ) {
823 double nbgbin = 20.0;
824 double bgbegin = 0.3;
827 bgstep = (bgend-bgbegin)/nbgbin;
828 ibgbin =
static_cast<int>((betaGamma*
xmass(4)-bgbegin)/bgstep);
830 if( ibgbin<0 ) { ibgbin=0; }
831 else if( ibgbin>=nbgbin ) { ibgbin=nbgbin-1; }
839 izbin =
static_cast<int>((zrhit-
zbegin)/zstep);
840 if( izbin<0 ) { izbin=0; }
841 else if( izbin>=nzbin ) { izbin=nzbin-1; }
849 izbin =
static_cast<int>((zrhit-
zbegin)/zstep);
850 if( izbin<0 ) { izbin=0; }
851 else if( izbin>=nzbin ) { izbin=nzbin-1; }
855 unsigned int numParam = 4;
857 for(
unsigned int i=0; i<4; i++ ) {
858 if( i==0 ) { func[i] = 1.0; }
860 func[i] = func[i-1]*zrhit;
863 for(
unsigned int i=4; i<12; i++ ) {
869 if( ispecies==2 || ispecies==3 ) {
870 for(
unsigned int i=4; i<10; i++ ) {
871 func[i] = func[i-1]*zrhit;
873 func[10] = 1.0/(115.0-zrhit)/(115.0-zrhit);
874 func[11] = 1.0/(115.0+zrhit)/(115.0+zrhit);
877 else if( ispecies==4 ) {
878 for(
unsigned int i=4; i<12; i++ ) {
879 func[i] = func[i-1]*zrhit;
888 unsigned int inumber =
ipmt;
889 if( !barrel ) { inumber=7; }
892 if( ispecies==2 || ispecies==3 ) {
893 for(
unsigned int i=0; i<numParam; i++ ) {
894 sigma += m_par_sigma[ispecies-2][inumber][i]*func[i];
897 else if( ispecies==4 ) {
902 sigma = m_p_sigma_12[0][inumber][ibgbin][izbin];
905 sigma = m_p_sigma_12[1][inumber][ibgbin][izbin];
910 sigma = m_p_sigma_ec12[0][ibgbin][izbin];
913 sigma = m_p_sigma_ec12[1][ibgbin][izbin];
916 if( fabs(
sigma+999.0)<1.0e-6 ) {
921 for(
unsigned int i=0; i<numParam; i++ ) {
923 sigma += m_par_sigma[2][inumber][i]*func[i];
926 sigma += m_par_sigma[3][inumber][i]*func[i];
936 sigma =
sigma*(TMath::Exp((betaGamma-0.356345)/(-0.767124))+0.994072);
double pdfCalculate(double offset, double sigma)