30 static bool inited =
false;
33 static GeomSvc* p_geomSvc =
nullptr;
39 static bool COARSE_MODE;
42 static double FMAGSTR;
43 static double KMAGSTR;
45 static double PT_KICK_FMAG;
46 static double PT_KICK_KMAG;
53 static double INVP_MAX;
54 static double INVP_MIN;
55 static double PROB_LOOSE;
56 static double PROB_TIGHT;
59 static double Z_KMAG_BEND;
60 static double Z_ABSORBER;
61 static double Z_FMAG_BEND;
62 static double Z_KFMAG_BEND;
63 static double ELOSS_KFMAG;
64 static double ELOSS_ABSORBER;
67 void initGlobalVariables()
119 if(
sign > 0) os <<
"L - ";
120 if(
sign > 0) os <<
"R - ";
121 if(
sign == 0) os <<
"U - ";
131 for(
int i = 0; i < 4; ++i)
hits[i].hit.index = -1;
133 initGlobalVariables();
143 for(
int i = 0; i < 4; ++i)
hits[i].hit.index = -1;
153 os <<
"a = " <<
a <<
", b = " <<
b <<
", chisq = " <<
chisq << endl;
154 os <<
"TX_MAX = " << TX_MAX <<
", X0_MAX = " << X0_MAX <<
", chisq max = " << 5 << endl;
157 for(
int i = 0; i < 4; ++i)
159 if(
hits[i].sign > 0) os <<
"L: ";
160 if(
hits[i].sign < 0) os <<
"R: ";
161 if(
hits[i].sign == 0) os <<
"U: ";
170 return (
a*z +
b - pos)/sqrt(
a*
a + 1.);
179 for(
int i = 0; i < 2; ++i)
181 if(
hits[i].hit.index < 0)
continue;
187 return pos_exp/nRefPoints;
193 for(
int i = 0; i < 4; ++i)
195 if(
hits[i].hit.index >= 0) ++nHits;
203 for(
int i = 0; i < 2; ++i)
214 if(
chisq > 5.)
return 0;
217 if(fabs(
a) > TX_MAX)
return 0;
218 if(fabs(
b) > X0_MAX)
return 0;
268 hits[0].
sign = 2*(settings & 1) - 1;
269 hits[1].
sign = 2*((settings & 2) >> 1) - 1;
270 hits[2].
sign = 2*((settings & 4) >> 1) - 1;
271 hits[3].
sign = 2*((settings & 8) >> 1) - 1;
287 while(nHits > 2 &&
chisq > 5.)
291 for(
int i = 0; i < 4; ++i)
293 if(
hits[i].hit.index < 0)
continue;
304 LogInfo(
"Invoking prop segment re-fitting...");
305 LogInfo(
"Removing hit " << index <<
" with residual = " << res_max);
306 LogInfo(
"Before removing a = " <<
a <<
", b = " <<
b <<
", chisq = " <<
chisq);
324 LogInfo(
"After removing a = " <<
a <<
", b = " <<
b <<
", chisq = " <<
chisq);
334 for(
int i = 0; i < 4; ++i)
336 if(
hits[i].hit.index < 0)
continue;
344 a = (pos[1] - pos[0])/(z[1] - z[0]);
389 for(
int i = 0; i < 4; ++i)
391 if(
hits[i].hit.index < 0)
continue;
420 double det = sum*sxx - sx*sx;
421 if(fabs(det) < 1E-20)
return;
423 a = (sum*sxy - sx*sy)/det;
424 b = (sy*sxx - sxy*sx)/det;
425 err_a = sqrt(fabs(sum/det));
426 err_b = sqrt(fabs(sxx/det));
429 for(
int i = 0; i < 4; ++i)
431 if(
hits[i].hit.index < 0)
continue;
432 chisq += ((y[i] -
a*x[i] -
b)*(y[i] -
a*x[i] -
b));
442 double x[4], y[4], r[4];
443 for(
int i = 0; i < 4; ++i)
445 if(
hits[i].hit.index < 0)
continue;
457 double a_prev = -999.;
459 while(fabs(a_prev -
a) > 1E-4 && ++iter < 100)
464 double C, D, E, F, G, H;
472 for(
int i = 0; i < len; ++i)
474 _x[i] = x[i] - r[i]*
a/sqrt(
a*
a + 1.);
475 _y[i] = y[i] + r[i]/sqrt(
a*
a + 1.);
485 double alpha = H - D*E/C;
486 double beta = F - G -D*D/C + E*E/C;
488 a = (-beta + sqrt(beta*beta + 4*alpha*alpha))/alpha/2.;
492 for(
int i = 0; i < len; ++i)
494 chisq += (
a*_x[i] +
b - _y[i])*(
a*_x[i] +
b - _y[i])/(
a*
a + 1.);
500 Tracklet::Tracklet() : stationID(-1), nXHits(0), nUHits(0), nVHits(0),
chisq(9999.), chisq_vtx(9999.), tx(0.), ty(0.), x0(0.), y0(0.), invP(0.1), err_tx(-1.), err_ty(-1.), err_x0(-1.), err_y0(-1.), err_invP(-1.)
503 initGlobalVariables();
508 if(stationID < 1 || stationID >
nStations)
return 0;
509 if(fabs(
tx) > TX_MAX || fabs(
x0) > X0_MAX)
return 0;
510 if(fabs(
ty) > TY_MAX || fabs(
y0) > Y0_MAX)
return 0;
514 if(
stationID != nStations && prob < PROB_LOOSE)
return 0;
521 if(nHits < 4)
return 0;
522 if(
chisq > 40.)
return 0;
527 int nRealHits[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
528 for(std::list<SignedHit>::const_iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
530 if(iter->hit.index < 0)
continue;
532 int idx1 = iter->hit.detectorID <= 12 ? 0 : (iter->hit.detectorID <= 18 ? 1 : 2);
533 int idx2 = p_geomSvc->
getPlaneType(iter->hit.detectorID) - 1;
535 ++nRealHits[idx1][idx2];
539 for(
int i = 1; i < 3; ++i)
541 if(nRealHits[i][0] < 1 || nRealHits[i][1] < 1 || nRealHits[i][2] < 1)
return 0;
542 if(nRealHits[i][0] + nRealHits[i][1] + nRealHits[i][2] < 4)
return 0;
548 if(nRealHits[0][0] < 1 || nRealHits[0][1] < 1 || nRealHits[0][2] < 1)
return 0;
549 if(nRealHits[0][0] + nRealHits[0][1] + nRealHits[0][2] < 4)
return 0;
551 if(prob < PROB_TIGHT)
return 0;
554 if(invP < INVP_MIN || invP > INVP_MAX)
return 0;
573 for(std::list<SignedHit>::const_iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
575 if(iter->hit.index < 0)
continue;
577 int idx = p_geomSvc->
getPlaneType(iter->hit.detectorID) - 1;
605 return TMath::Prob(
chisq, ndf);
611 double weights[40] = {0, 0, 3.1292e-05, 0.00203877, 0.0147764, 0.0417885, 0.08536, 0.152212, 0.250242, 0.322011, 0.327125, 0.275443, 0.220316, 0.189932, 0.162112, 0.131674, 0.100102, 0.0736696, 0.0510353, 0.0364215, 0.0233914, 0.0152907, 0.00992716, 0.00601322, 0.00382757, 0.00239005, 0.00137169, 0.000768309, 0.000413311, 0.00019659, 8.31216e-05, 2.77721e-05, 7.93826e-06, 7.45884e-07, 2.57648e-08, 0, 6.00088e-09, 0, 0, 0};
612 int index = int(1./
invP/2.5);
614 return (index >= 0 && index < 40) ? (weights[index] < 1.E-5 ? 1.E-5 : weights[index]) : 1.E-5;
627 double x0_st1 =
tx*Z_KMAG_BEND +
x0 - tx_st1*Z_KMAG_BEND;
629 return x0_st1 + tx_st1*z;
642 double err_kick = fabs(
err_invP*PT_KICK_KMAG);
643 double err_tx_st1 =
err_tx + err_kick;
644 double err_x0_st1 =
err_x0 + err_kick*Z_KMAG_BEND;
646 err_x = err_x0_st1 + fabs(err_tx_st1*z);
653 if(z > Z_ABSORBER) err_x += 1.;
665 if(z > Z_ABSORBER) err_y += 1.;
696 std::list<SignedHit>::const_iterator first =
hits.begin();
697 std::list<SignedHit>::const_iterator second = elem.
hits.begin();
699 while(first !=
hits.end() && second != elem.
hits.end())
701 if((*first) < (*second))
705 else if((*second) < (*first))
711 if((*first) == (*second)) nCommonHits++;
717 if(nCommonHits/
double(elem.
getNHits()) > 0.33333)
return true;
729 double c1 = Z_FMAG_BEND*PT_KICK_FMAG*charge;
730 double c2 = Z_KMAG_BEND*PT_KICK_KMAG*charge;
732 double c4 = ELOSS_KFMAG/2.;
733 double c5 = ELOSS_KFMAG;
735 double b = c1/c3 + c2/c3 - c4 - c5;
736 double c = c4*c5 - c1*c5/c3 - c2*c4/c3;
738 double disc = b*b - 4*c;
741 p = (-b + sqrt(disc))/2. - ELOSS_KFMAG;
744 if(p < 10. || p > 120. || disc < 0)
747 p = 1./(0.00832161 + 0.184186*k - 0.104132*k*k) + ELOSS_ABSORBER;
755 return x0*KMAGSTR >
tx ? 1 : -1;
763 x0_st1 =
tx*Z_KMAG_BEND +
x0 - tx_st1*Z_KMAG_BEND;
776 double err_kick = fabs(
err_invP*PT_KICK_KMAG);
777 err_tx_st1 =
err_tx + err_kick;
778 err_x0_st1 =
err_x0 + err_kick*Z_KMAG_BEND;
799 tracklet.
hits.insert(tracklet.
hits.end(), elem.
hits.begin(), elem.
hits.end());
803 tracklet.
hits.insert(tracklet.
hits.begin(), elem.
hits.begin(), elem.
hits.end());
835 tracklet.
hits.insert(tracklet.
hits.end(), elem.
hits.begin(), elem.
hits.end());
839 tracklet.
hits.insert(tracklet.
hits.begin(), elem.
hits.begin(), elem.
hits.end());
844 tracklet.
tx = elem.
tx;
845 tracklet.
ty = elem.
ty;
846 tracklet.
x0 = elem.
x0;
847 tracklet.
y0 = elem.
y0;
897 std::list<SignedHit>::iterator elemend = elem.
hits.begin();
898 for(
int i = 0; i < 6; ++i) ++elemend;
900 tracklet.
hits.insert(tracklet.
hits.begin(), elem.
hits.begin(), elemend);
901 tracklet.
hits.sort();
910 std::vector<int> detectorIDs_all;
913 std::vector<int> detectorIDs_now;
914 for(std::list<SignedHit>::const_iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
916 detectorIDs_now.push_back(iter->hit.detectorID);
919 std::vector<int> detectorIDs_miss(6);
920 std::vector<int>::iterator iter = std::set_difference(detectorIDs_all.begin(), detectorIDs_all.end(), detectorIDs_now.begin(), detectorIDs_now.end(), detectorIDs_miss.begin());
921 detectorIDs_miss.resize(iter - detectorIDs_miss.begin());
923 for(std::vector<int>::iterator iter = detectorIDs_miss.begin(); iter != detectorIDs_miss.end(); ++iter)
928 hits.push_back(dummy);
938 double tx_st1, x0_st1;
944 for(std::list<SignedHit>::const_iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
946 if(iter->hit.index < 0)
continue;
948 int detectorID = iter->hit.detectorID;
949 int index = detectorID - 1;
952 if(iter->sign == 0 || COARSE_MODE)
961 residual[index] = iter->sign*fabs(iter->hit.driftDistance) - p_geomSvc->
getDCA(detectorID, iter->hit.elementID, tx_st1,
ty, x0_st1,
y0);
966 residual[index] = iter->sign*fabs(iter->hit.driftDistance) - p_geomSvc->
getDCA(detectorID, iter->hit.elementID,
tx,
ty,
x0,
y0);
980 for(std::list<SignedHit>::const_iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
982 if(
id == index)
return *iter;
996 if(KMAG_ON)
invP = par[4];
1006 for(std::list<SignedHit>::iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
1008 if(iter->hit.index < 0)
continue;
1011 double tx_val, tx_err, x0_val, x0_err;
1012 if(iter->hit.detectorID <= 12)
1025 TMatrixD state(5, 1), covar(5, 5);
1026 state[0][0] =
getCharge()*
invP*sqrt((1. + tx_val*tx_val)/(1. + tx_val*tx_val +
ty*
ty));
1027 state[1][0] = tx_val;
1034 covar[1][1] = tx_err*tx_err;
1061 double tx_st1, x0_st1;
1064 double pz = 1./
invP/sqrt(1. + tx_st1*tx_st1);
1065 return TVector3(pz*tx_st1, pz*
ty, pz);
1070 double pz = 1./
invP/sqrt(1. +
tx*
tx);
1071 return TVector3(pz*tx, pz*
ty, pz);
1076 using namespace std;
1082 os <<
"Tracklet in station " <<
stationID << endl;
1084 os <<
"Momentum in z @st1: " << mom1.Pz() <<
" +/- " << mom1.Pz()*
err_invP/
invP << endl;
1085 os <<
"Momentum in z @st3: " << mom3.Pz() <<
" +/- " << mom3.Pz()*
err_invP/
invP << endl;
1086 os <<
"Charge: " <<
getCharge() << endl;
1087 for(std::list<SignedHit>::iterator iter =
hits.begin(); iter !=
hits.end(); ++iter)
1089 if(iter->sign > 0) os <<
"L: ";
1090 if(iter->sign < 0) os <<
"R: ";
1091 if(iter->sign == 0) os <<
"U: ";
1093 os << iter->hit.index <<
" " << iter->hit.detectorID <<
" " << iter->hit.elementID <<
" " <<
residual[iter->hit.detectorID-1] <<
" === ";
1097 os <<
"X-Z: (" <<
tx <<
" +/- " <<
err_tx <<
")*z + (" <<
x0 <<
" +/- " <<
err_x0 <<
")" << endl;
1098 os <<
"Y-Z: (" <<
ty <<
" +/- " <<
err_ty <<
")*z + (" <<
y0 <<
" +/- " <<
err_y0 <<
")" << endl;
1102 os <<
"KMAGSTR = " << KMAGSTR << endl;
1115 os <<
"TrackletVector with " <<
size() <<
" entries" << std::endl;
1120 for(
auto iter = trackletVec.begin(); iter != trackletVec.end(); ++iter)
delete (*iter);
1121 trackletVec.clear();
1126 if(index >=
size())
return nullptr;
1127 return trackletVec[index];
1132 if(index >=
size())
return nullptr;
1133 return trackletVec[index];
1138 trackletVec.push_back(tracklet->
Clone());
1145 delete trackletVec[index];
1146 trackletVec.erase(trackletVec.begin() + index);
1147 return trackletVec.size();
virtual bool get_BoolFlag(const std::string &name) const
void insertHitIndex(Int_t index)
void identify(std::ostream &os=std::cout) const
double Z_FMAG_BEND() const
void identify(std::ostream &os=std::cout) const
void linearFit_iterative()
Tracklet operator+(const Tracklet &elem) const
SignedHit getSignedHit(int index)
double getSintheta(int detectorID) const
void getXZErrorInSt1(double &err_tx_st1, double &err_x0_st1)
double getExpPosErrorX(double z) const
double Eval(const double *par)
double residual[nChamberPlanes]
double ELOSS_KFMAG() const
virtual double get_DoubleFlag(const std::string &name) const
double getExpPositionW(int detectorID)
virtual ~TrackletVector()
double getPlaneResolution(int detectorID) const
int isValid() const
isValid returns non zero if object contains vailid data
SRecTrack getSRecTrack(bool hyptest=true)
void insertStateVector(TMatrixD state)
bool operator<(const Tracklet &elem) const
double Z_ABSORBER() const
double getMomentum() const
size_t erase(const size_t index)
static recoConsts * instance()
TVector3 getMomentumSt1()
double getExpPositionY(double z) const
void insertCovariance(TMatrixD covar)
void print(std::ostream &os=std::cout)
const Tracklet * at(const size_t index) const
double Z_KFMAG_BEND() const
Definition of hit structure.
double getExpPosErrorY(double z) const
std::list< SignedHit > hits
void print(std::ostream &os=std::cout) const
void setPTSlope(Double_t slopeX, Double_t slopeY)
double ELOSS_ABSORBER() const
int isValid() const
isValid returns non zero if object contains vailid data
double getMomProb() const
TVector3 getExpMomentum(double z)
double getDCA(int detectorID, int elementID, double tx, double ty, double x0, double y0)
double getPlaneSpacing(int detectorID) const
double getPosRef(double default_val=-9999.)
void setNHitsInPT(Int_t nHitsX, Int_t nHitsY)
int getPlaneType(int detectorID) const
double getClosestApproach(double z, double pos)
TVector3 getMomentumSt3()
double getCostheta(int detectorID) const
static GeomSvc * instance()
singlton instance
void setTriggerRoad(Int_t roadID)
double Z_KMAG_BEND() const
Getter/setters for a set of fixed parameters - should not be changed unless absolutely necessary...
Tracklet operator*(const Tracklet &elem) const
double getExpPositionX(double z) const
void setChisq(Double_t chisq)
Sets.
void push_back(const Tracklet *tracklet)
Tracklet merge(Tracklet &elem)
double getPlanePosition(int detectorID) const
void swimToVertex(TVector3 *pos=nullptr, TVector3 *mom=nullptr, bool hyptest=true)
Simple swim to vertex.
void getXZInfoInSt1(double &tx_st1, double &x0_st1)
bool similarity(const Tracklet &elem) const