76 SmartRefVector<RecTofTrack> tofTrk = recTrk->
tofTrack();
77 SmartRefVector<RecTofTrack>::iterator it;
79 const std::vector<TTofTrack*>& tofTrk = recTrk->
tofTrack();
80 std::vector<TTofTrack*>::const_iterator it;
86 double p[5], betaGamma[5];
88 for (
int i = 0; i < 5; i++ )
96 HepLorentzVector ptrk = kalTrk->
p4();
98 HepLorentzVector ptrk = kalTrk->
p4(
xmass( i ) );
101 betaGamma[i] =
p[i] /
xmass( i );
109 int tofid[2] = { -9, -9 };
112 bool readFile =
false;
113 bool signal[2] = {
false,
false };
115 for ( it = tofTrk.begin(); it != tofTrk.end(); it++ )
117 unsigned int st = ( *it )->status();
119 if ( hitst->
is_raw() )
return irc;
121 bool ismrpc = hitst->
is_mrpc();
122 if ( !barrel && !ismrpc ) { zrhit[0] = extTrk->
tof1Position().rho(); }
126 int layer = hitst->
layer();
127 tofid[layer - 1] = ( *it )->tofID();
129 double tof = ( *it )->tof();
130 unsigned int ipmt = 0;
135 if ( barrel ) {
ipmt = ( ( st & 0xC0 ) >> 5 ) + ( ( ( st ^ 0x20 ) & 0x20 ) >> 5 ) - 2; }
140 if ( tofid[0] <= 47 ) {
ipmt = 7; }
145 if ( tofid[0] <= 35 ) {
ipmt = 7; }
150 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;
163 m_chiCorr[i][
ipmt] = m_dtCorr[i][
ipmt] / m_sigCorr[i][
ipmt];
174 m_chiCorr[i][0] = m_dtCorr[i][
ipmt] / m_sigCorr[i][
ipmt];
181 int strip = ( *it )->strip();
183 if ( strip < 0 || strip > 11 ) { m_sigCorr[i][0] = 0.065; }
191 else if ( strip == 1 )
196 else if ( strip == 2 )
201 else if ( strip == 3 )
206 else if ( strip == 4 )
211 else if ( strip == 5 )
216 else if ( strip == 6 )
221 else if ( strip == 7 )
226 else if ( strip == 8 )
231 else if ( strip == 9 )
236 else if ( strip == 10 )
241 else if ( strip == 11 )
246 if (
p[i] < 0.05 ) { m_sigCorr[i][0] = p0 +
p1 / 0.05; }
247 else { m_sigCorr[i][0] = p0 +
p1 /
p[i]; }
249 if ( i == 4 ) { m_sigCorr[i][0] = 1.5 * m_sigCorr[i][0]; }
250 m_chiCorr[i][0] = m_dtCorr[i][0] / m_sigCorr[i][0];
254 if ( counter && cluster )
257 for (
unsigned int i = 0; i < 5; i++ )
259 if ( ( ( *it )->texp( i ) ) > 0.0 )
263 m_offset[i] = m_dtCorr[i][
ipmt];
264 m_sigma[i] = m_sigCorr[i][
ipmt];
268 m_offset[i] = m_dtCorr[i][0];
269 m_sigma[i] = m_sigCorr[i][0];
280 for (
unsigned int i = 0; i < 5; i++ )
282 double offset = ( *it )->toffset( i );
283 double texp = ( *it )->texp( i );
284 if ( texp < 0.0 )
continue;
292 sigmaTof( i,
charge, barrel, layer + 3, &tofid[0], &zrhit[0], betaGamma[i] );
293 m_chiCorr[i][
ipmt] = m_dtCorr[i][
ipmt] / m_sigCorr[i][
ipmt];
302 int strip = ( *it )->strip();
304 if ( strip < 0 || strip > 11 ) { m_sigCorr[i][0] = 0.065; }
312 else if ( strip == 1 )
317 else if ( strip == 2 )
322 else if ( strip == 3 )
327 else if ( strip == 4 )
332 else if ( strip == 5 )
337 else if ( strip == 6 )
342 else if ( strip == 7 )
347 else if ( strip == 8 )
352 else if ( strip == 9 )
357 else if ( strip == 10 )
362 else if ( strip == 11 )
367 if (
p[i] < 0.05 ) { m_sigCorr[i][0] = p0 +
p1 / 0.05; }
368 else { m_sigCorr[i][0] = p0 +
p1 /
p[i]; }
370 if ( i == 4 ) { m_sigCorr[i][0] = 1.5 * m_sigCorr[i][0]; }
371 m_chiCorr[i][0] = m_dtCorr[i][0] / m_sigCorr[i][0];
375 cout <<
"ParticleID: TofCorr::particleIDCalculation: Endcap Scintillator TOF "
376 "have more than one end!!!"
384 for (
unsigned int i = 0; i < 5; i++ )
386 if ( ( ( *it )->texp( i ) ) > 0.0 )
390 m_offset[i] = m_dtCorr[i][
ipmt];
391 m_sigma[i] = m_sigCorr[i][
ipmt];
395 m_offset[i] = m_dtCorr[i][0];
396 m_sigma[i] = m_sigCorr[i][0];
408 for (
unsigned int i = 0; i < 5; i++ )
410 double offset = ( *it )->toffset( i );
411 double texp = ( *it )->texp( i );
412 if ( texp < 0.0 )
continue;
415 m_dtCorr[i][
ipmt] =
offsetTof( i, tofid[0], tofid[1], zrhit[0], zrhit[1],
419 m_chiCorr[i][
ipmt] = m_dtCorr[i][
ipmt] / m_sigCorr[i][
ipmt];
421 if ( signal[0] && signal[1] )
424 for (
unsigned int i = 0; i < 5; i++ )
426 m_offset[i] = m_dtCorr[i][
ipmt];
427 m_sigma[i] = m_sigCorr[i][
ipmt];
430 else if ( signal[0] && !signal[1] )
433 for (
unsigned int i = 0; i < 5; i++ )
435 m_offset[i] = m_dtCorr[i][4];
436 m_sigma[i] = m_sigCorr[i][4];
439 else if ( !signal[0] && signal[1] )
442 for (
unsigned int i = 0; i < 5; i++ )
444 m_offset[i] = m_dtCorr[i][5];
445 m_sigma[i] = m_sigCorr[i][5];
456 for (
unsigned int i = 0; i < 5; i++ )
458 m_chi[i] = m_offset[i] / m_sigma[i];
459 if ( m_chi[i] < 0. && m_chi[i] > m_chimin ) { m_chimin = m_chi[i]; }
460 if ( m_chi[i] > 0. && m_chi[i] < m_chimax ) { m_chimax = m_chi[i]; }
462 if ( fabs( ppp ) > pdftemp ) { pdftemp = fabs( ppp ); }
467 if ( ( m_chimin > -90.0 && ( 0 - m_chimin ) >
chiMinCut() ) &&
468 ( m_chimax < 90.0 && m_chimax >
chiMaxCut() ) )
470 for (
int i = 0; i < 5; i++ ) { m_prob[i] =
probCalculate( m_chi[i] * m_chi[i], 1 ); }
478 std::string filePath =
path +
"/share/TofCorrPID/";
480 filePath = filePath +
"jpsi2012";
484 if ( run > 0 ) { filePath = filePath +
"/data/"; }
485 else { filePath = filePath +
"/mc/"; }
488 std::string fileWeight = filePath +
"calib_barrel_sigma.txt";
489 ifstream inputWeight( fileWeight.c_str(), std::ios_base::in );
492 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileWeight << endl;
496 for (
unsigned int tofid = 0; tofid < 176; tofid++ )
498 for (
unsigned int readout = 0; readout < 3; readout++ )
500 for (
unsigned int p_i = 0; p_i < 5; p_i++ )
501 { inputWeight >> m_p_weight[tofid][readout][p_i]; }
507 std::string fileCommon = filePath +
"calib_barrel_common.txt";
508 ifstream inputCommon( fileCommon.c_str(), std::ios_base::in );
511 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileCommon << endl;
514 inputCommon >> m_p_common;
518 std::string fileEcSigma = filePath +
"calib_endcap_sigma.txt";
519 ifstream inputEcSigma( fileEcSigma.c_str(), std::ios_base::in );
522 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileEcSigma << endl;
526 for (
unsigned int tofid = 0; tofid < 96; tofid++ )
528 for (
unsigned int p_i = 0; p_i < 3; p_i++ ) { inputEcSigma >> m_ec_sigma[tofid][p_i]; }
533 std::string fileQ0BetaGamma = filePath +
"curve_Q0_BetaGamma.txt";
534 ifstream inputQ0BetaGamma( fileQ0BetaGamma.c_str(), std::ios_base::in );
535 if ( !inputQ0BetaGamma )
537 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileQ0BetaGamma << endl;
541 for (
unsigned int layer = 0; layer < 3; layer++ )
543 for (
unsigned int ipar = 0; ipar < 5; ipar++ )
544 { inputQ0BetaGamma >> m_q0_bg[layer][ipar]; }
549 std::string fileParAB = filePath +
"parameter_A_B.txt";
550 ifstream inputParAB( fileParAB.c_str(), std::ios_base::in );
553 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileParAB << endl;
562 for (
unsigned int ispecies = 0; ispecies < 2; ispecies++ )
566 for (
unsigned int icharge = 0; icharge < 2; icharge++ )
568 for (
unsigned int iab = 0; iab < 2; iab++ )
570 for (
unsigned int ipar = 0; ipar < 11; ipar++ )
571 { inputParAB >> m_par_ab_12[ispecies][
ipmt][icharge][iab][ipar]; }
578 std::string fileSigma = filePath +
"parameter_sigma.txt";
579 ifstream inputSigma( fileSigma.c_str(), std::ios_base::in );
582 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileSigma << endl;
590 for (
unsigned int ispecies = 0; ispecies < 4; ispecies++ )
594 for (
unsigned int ipar = 0; ipar < 12; ipar++ )
595 { inputSigma >> m_par_sigma[ispecies][
ipmt][ipar]; }
600 std::string fileProtonOffset = filePath +
"parameter_offset_proton.txt";
601 ifstream inputProtonOffset( fileProtonOffset.c_str(), std::ios_base::in );
602 if ( !inputProtonOffset )
604 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileProtonOffset << endl;
613 for (
unsigned int ispecies = 0; ispecies < 2; ispecies++ )
617 for (
unsigned int ipar = 0; ipar < 20; ipar++ )
621 for (
unsigned int jpar = 0; jpar < 46; jpar++ )
622 { inputProtonOffset >> m_p_offset_12[ispecies][
ipmt][ipar][jpar]; }
626 for (
unsigned int jpar = 0; jpar < 7; jpar++ )
627 { inputProtonOffset >> m_p_offset_ec12[ispecies][ipar][jpar]; }
635 std::string fileProtonSigma = filePath +
"parameter_sigma_proton.txt";
636 ifstream inputProtonSigma( fileProtonSigma.c_str(), std::ios_base::in );
637 if ( !inputProtonSigma )
639 cout <<
"ParticleID::TofCorrPID: Can NOT open file: " << fileProtonSigma << endl;
648 for (
unsigned int ispecies = 0; ispecies < 2; ispecies++ )
652 for (
unsigned int ipar = 0; ipar < 20; ipar++ )
656 for (
unsigned int jpar = 0; jpar < 46; jpar++ )
657 { inputProtonSigma >> m_p_sigma_12[ispecies][
ipmt][ipar][jpar]; }
661 for (
unsigned int jpar = 0; jpar < 7; jpar++ )
662 { inputProtonSigma >> m_p_sigma_ec12[ispecies][ipar][jpar]; }
673 double betaGamma,
int charge,
double zrhit,
double dt ) {
674 if ( ispecies == 0 || ispecies == 1 ) {
return dt; }
676 double deltaT = -1000.0;
677 if ( (
ipmt >= 4 && barrel ) || (
ipmt != 7 &&
ipmt != 8 && !barrel ) || betaGamma < 0.0 ||
678 abs(
charge ) != 1 || fabs( zrhit ) > 120.0 )
684 unsigned int layer = 0;
687 if (
ipmt == 0 ||
ipmt == 1 ) { layer = 0; }
688 else if (
ipmt == 2 ||
ipmt == 3 ) { layer = 1; }
693 unsigned int inumber =
ipmt;
694 if ( !barrel ) { inumber = 4; }
697 for (
unsigned int i = 0; i < 9; i++ ) { func[i] = 0.0; }
704 for (
unsigned int i = 1; i < 8; i++ ) { func[i] = func[i - 1] * zrhit; }
706 unsigned int iparticle = 0;
707 if ( ispecies == 2 || ispecies == 3 ) { iparticle = 0; }
708 else if ( ispecies == 4 ) { iparticle = 1; }
709 unsigned int icharge = 0;
710 if (
charge == 1 ) { icharge = 0; }
711 else if (
charge == -1 ) { icharge = 1; }
713 if ( ispecies != 4 || betaGamma *
xmass( 4 ) > 0.8 )
715 for (
unsigned int i = 0; i < 8; i++ )
719 parA += m_par_ab_12[iparticle][inumber][icharge][0][i] * func[i];
720 parB += m_par_ab_12[iparticle][inumber][icharge][1][i] * func[i];
724 parA += m_par_ab_12[iparticle][inumber][icharge][0][i + 3] * func[i];
725 parB += m_par_ab_12[iparticle][inumber][icharge][1][i + 3] * func[i];
728 for (
unsigned int iab = 0; iab < 2; iab++ )
730 func[8] = m_par_ab_12[iparticle][inumber][icharge][iab][5] *
731 TMath::Gaus( zrhit, m_par_ab_12[iparticle][inumber][icharge][iab][6],
732 m_par_ab_12[iparticle][inumber][icharge][iab][7] );
733 if ( iab == 0 ) { parA += func[8]; }
734 else if ( iab == 1 ) { parB += func[8]; }
738 double tcorr = parA + parB / sqrt( q0 );
742 if ( barrel && ispecies == 4 && betaGamma *
xmass( 4 ) < 0.8 )
749 double nbgbin = 20.0;
750 double bgbegin = 0.3;
753 bgstep = ( bgend - bgbegin ) / nbgbin;
755 int izbin =
static_cast<int>( ( zrhit -
zbegin ) / zstep );
756 if ( izbin < 0 ) { izbin = 0; }
757 else if ( izbin >= nzbin ) { izbin = nzbin - 1; }
758 int ibgbin =
static_cast<int>( ( betaGamma *
xmass( 4 ) - bgbegin ) / bgstep );
759 if ( ibgbin < 0 ) { ibgbin = 0; }
760 else if ( ibgbin >= nbgbin ) { ibgbin = nbgbin - 1; }
762 if (
charge == 1 ) { tcorr = m_p_offset_12[0][
ipmt][ibgbin][izbin]; }
763 else { tcorr = m_p_offset_12[1][
ipmt][ibgbin][izbin]; }
765 else if ( !barrel && ispecies == 4 && betaGamma *
xmass( 4 ) < 0.8 )
768 double rbegin = 55.0;
770 double rstep = ( rend - rbegin ) / nrbin;
772 double nbgbin = 20.0;
773 double bgbegin = 0.3;
776 bgstep = ( bgend - bgbegin ) / nbgbin;
778 int irbin =
static_cast<int>( ( zrhit - rbegin ) / rstep );
779 if ( irbin < 0 ) { irbin = 0; }
780 else if ( irbin >= nrbin ) { irbin = nrbin - 1; }
781 int ibgbin =
static_cast<int>( ( betaGamma *
xmass( 4 ) - bgbegin ) / bgstep );
782 if ( ibgbin < 0 ) { ibgbin = 0; }
783 else if ( ibgbin >= nbgbin ) { ibgbin = nbgbin - 1; }
785 if (
charge == 1 ) { tcorr = m_p_offset_ec12[0][ibgbin][irbin]; }
786 else { tcorr = m_p_offset_ec12[1][ibgbin][irbin]; }
796 if ( ispecies == 0 || ispecies == 1 ) {
return dt; }
798 double deltaT = -1000.0;
799 if ( tofid < 0 || tofid >= 176 )
801 cout <<
"Particle::TofCorrPID: offsetTof for single layer: the input parameter are NOT "
802 "correct! Please check them!"
806 int pmt[3] = { -9, -9, -9 };
807 if ( tofid >= 0 && tofid <= 87 )
820 double sigmaCorr2 = m_p_common * m_p_common;
821 double sigmaLeft =
bSigma( 0, tofid, zrhit );
822 double sigmaLeft2 = sigmaLeft * sigmaLeft;
823 double sigmaRight =
bSigma( 1, tofid, zrhit );
824 double sigmaRight2 = sigmaRight * sigmaRight;
827 ( sigmaRight2 - sigmaCorr2 ) / ( sigmaLeft2 + sigmaRight2 - 2.0 * sigmaCorr2 );
829 fraction * m_dtCorr[ispecies][pmt[0]] + ( 1.0 - fraction ) * m_dtCorr[ispecies][pmt[1]];
833 unsigned int ipmt = 4;
834 if ( tofid >= 88 && tofid < 176 ) {
ipmt = 5; }
835 if ( ispecies == 4 && betaGamma *
xmass( 4 ) < 0.8 )
842 double nbgbin = 20.0;
843 double bgbegin = 0.3;
846 bgstep = ( bgend - bgbegin ) / nbgbin;
848 int izbin =
static_cast<int>( ( zrhit -
zbegin ) / zstep );
849 if ( izbin < 0 ) { izbin = 0; }
850 else if ( izbin >= nzbin ) { izbin = nzbin - 1; }
851 int ibgbin =
static_cast<int>( ( betaGamma *
xmass( 4 ) - bgbegin ) / bgstep );
852 if ( ibgbin < 0 ) { ibgbin = 0; }
853 else if ( ibgbin >= nbgbin ) { ibgbin = nbgbin - 1; }
855 if (
charge == 1 ) { tcorr = m_p_offset_12[0][
ipmt][ibgbin][izbin]; }
856 else { tcorr = m_p_offset_12[1][
ipmt][ibgbin][izbin]; }
858 deltaT = deltaT - tcorr;
864 double zrhit2,
double betaGamma,
int charge,
double dt ) {
865 if ( ispecies == 0 || ispecies == 1 ) {
return dt; }
867 double deltaT = -1000.0;
868 if ( tofid1 < 0 || tofid1 >= 88 || tofid2 < 88 || tofid2 >= 176 )
870 cout <<
"Particle::TofCorrPID: offsetTof for double layer: the input parameter are NOT "
871 "correct! Please check them!"
876 double sigmaCorr2 = m_p_common * m_p_common;
877 double sigmaInner =
bSigma( 2, tofid1, zrhit1 );
878 double sigmaInner2 = sigmaInner * sigmaInner;
879 double sigmaOuter =
bSigma( 2, tofid2, zrhit2 );
880 double sigmaOuter2 = sigmaOuter * sigmaOuter;
881 double sigma = sqrt( ( sigmaInner2 * sigmaOuter2 - sigmaCorr2 * sigmaCorr2 ) /
882 ( sigmaInner2 + sigmaOuter2 - 2.0 * sigmaCorr2 ) );
888 ( sigmaOuter2 - sigmaCorr2 ) / ( sigmaInner2 + sigmaOuter2 - 2.0 * sigmaCorr2 );
889 deltaT = fraction * m_dtCorr[ispecies][4] + ( 1.0 - fraction ) * m_dtCorr[ispecies][5];
893 if ( ispecies == 4 && betaGamma *
xmass( 4 ) < 0.8 )
900 double nbgbin = 20.0;
901 double bgbegin = 0.3;
904 bgstep = ( bgend - bgbegin ) / nbgbin;
906 int izbin =
static_cast<int>( ( zrhit1 -
zbegin ) / zstep );
907 if ( izbin < 0 ) { izbin = 0; }
908 else if ( izbin >= nzbin ) { izbin = nzbin - 1; }
909 int ibgbin =
static_cast<int>( ( betaGamma *
xmass( 4 ) - bgbegin ) / bgstep );
910 if ( ibgbin < 0 ) { ibgbin = 0; }
911 else if ( ibgbin >= nbgbin ) { ibgbin = nbgbin - 1; }
913 if (
charge == 1 ) { tcorr = m_p_offset_12[0][6][ibgbin][izbin]; }
914 else { tcorr = m_p_offset_12[1][6][ibgbin][izbin]; }
916 deltaT = deltaT - tcorr;
922 int tofid[2],
double zrhit[2],
double betaGamma ) {
924 double sigma = 1.0e-6;
926 if ( ispecies == 0 || ispecies == 1 )
952 double zrhit,
double betaGamma ) {
957 if ( ispecies == 4 && ( betaGamma *
xmass( 4 ) ) < 0.8 )
959 double nbgbin = 20.0;
960 double bgbegin = 0.3;
963 bgstep = ( bgend - bgbegin ) / nbgbin;
964 ibgbin =
static_cast<int>( ( betaGamma *
xmass( 4 ) - bgbegin ) / bgstep );
966 if ( ibgbin < 0 ) { ibgbin = 0; }
967 else if ( ibgbin >= nbgbin ) { ibgbin = nbgbin - 1; }
976 izbin =
static_cast<int>( ( zrhit -
zbegin ) / zstep );
977 if ( izbin < 0 ) { izbin = 0; }
978 else if ( izbin >= nzbin ) { izbin = nzbin - 1; }
987 izbin =
static_cast<int>( ( zrhit -
zbegin ) / zstep );
988 if ( izbin < 0 ) { izbin = 0; }
989 else if ( izbin >= nzbin ) { izbin = nzbin - 1; }
993 unsigned int numParam = 4;
995 for (
unsigned int i = 0; i < 4; i++ )
997 if ( i == 0 ) { func[i] = 1.0; }
998 else { func[i] = func[i - 1] * zrhit; }
1000 for (
unsigned int i = 4; i < 12; i++ ) { func[i] = 0.0; }
1005 if ( ispecies == 2 || ispecies == 3 )
1007 for (
unsigned int i = 4; i < 10; i++ ) { func[i] = func[i - 1] * zrhit; }
1008 func[10] = 1.0 / ( 115.0 - zrhit ) / ( 115.0 - zrhit );
1009 func[11] = 1.0 / ( 115.0 + zrhit ) / ( 115.0 + zrhit );
1012 else if ( ispecies == 4 )
1014 for (
unsigned int i = 4; i < 12; i++ ) { func[i] = func[i - 1] * zrhit; }
1023 unsigned int inumber =
ipmt;
1024 if ( !barrel ) { inumber = 7; }
1027 if ( ispecies == 2 || ispecies == 3 )
1029 for (
unsigned int i = 0; i < numParam; i++ )
1030 {
sigma += m_par_sigma[ispecies - 2][inumber][i] * func[i]; }
1032 else if ( ispecies == 4 )
1039 if (
charge == 1 ) {
sigma = m_p_sigma_12[0][inumber][ibgbin][izbin]; }
1040 else {
sigma = m_p_sigma_12[1][inumber][ibgbin][izbin]; }
1044 if (
charge == 1 ) {
sigma = m_p_sigma_ec12[0][ibgbin][izbin]; }
1045 else {
sigma = m_p_sigma_ec12[1][ibgbin][izbin]; }
1047 if ( fabs(
sigma + 999.0 ) < 1.0e-6 ) {
sigma = 0.3; }
1051 for (
unsigned int i = 0; i < numParam; i++ )
1053 if (
charge == 1 ) {
sigma += m_par_sigma[2][inumber][i] * func[i]; }
1054 else {
sigma += m_par_sigma[3][inumber][i] * func[i]; }
1063 if ( ispecies == 2 )
1064 {
sigma =
sigma * ( TMath::Exp( ( betaGamma - 0.356345 ) / ( -0.767124 ) ) + 0.994072 ); }
double probCalculate(double chi2, int n)
double pdfCalculate(double offset, double sigma)