10 #include <phfield/PHField.h>
20 #include <TGraphErrors.h>
32 static bool inited =
false;
35 static int MaxHitsDC0;
36 static int MaxHitsDC1;
37 static int MaxHitsDC2;
38 static int MaxHitsDC3p;
39 static int MaxHitsDC3m;
42 static double SAGITTA_DUMP_CENTER;
43 static double SAGITTA_DUMP_WIDTH;
44 static double SAGITTA_TARGET_CENTER;
45 static double SAGITTA_TARGET_WIDTH;
46 static double Z_TARGET;
54 static double INVP_MAX;
55 static double INVP_MIN;
56 static double Z_KMAG_BEND;
59 static double MUID_REJECTION;
60 static double MUID_Z_REF;
61 static double MUID_R_CUT;
62 static double MUID_THE_P0;
63 static double MUID_EMP_P0;
64 static double MUID_EMP_P1;
65 static double MUID_EMP_P2;
66 static int MUID_MINHITS;
69 static double MERGE_THRES;
76 static bool COSMIC_MODE;
77 static bool COARSE_MODE;
80 void initGlobalVariables()
106 SAGITTA_TARGET_CENTER = rc->
get_DoubleFlag(
"SAGITTA_TARGET_CENTER");
107 SAGITTA_TARGET_WIDTH = rc->
get_DoubleFlag(
"SAGITTA_TARGET_WIDTH");
128 initGlobalVariables();
131 cout <<
"Initialization of KalmanFastTracking ..." << endl;
132 cout <<
"========================================" << endl;
135 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st2",
new PHTimer(
"st2")));
136 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st3",
new PHTimer(
"st3")));
137 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23",
new PHTimer(
"st23")));
138 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global",
new PHTimer(
"global")));
139 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global_st1",
new PHTimer(
"global_st1")));
140 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global_link",
new PHTimer(
"global_link")));
141 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global_kalman",
new PHTimer(
"global_kalman")));
142 _timers.insert(std::make_pair<std::string, PHTimer*>(
"kalman",
new PHTimer(
"kalman")));
148 kmfitter->setControlParameter(50, 0.001);
152 minimizer[0] = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Simplex");
153 minimizer[1] = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Combined");
154 fcn = ROOT::Math::Functor(&tracklet_curr, &
Tracklet::Eval, KMAG_ON ? 5 : 4);
156 for(
int i = 0; i < 2; ++i)
158 minimizer[i]->SetMaxFunctionCalls(1000000);
159 minimizer[i]->SetMaxIterations(100);
160 minimizer[i]->SetTolerance(1E-2);
161 minimizer[i]->SetFunction(fcn);
162 minimizer[i]->SetPrintLevel(0);
166 extern Int_t gErrorIgnoreLevel;
167 gErrorIgnoreLevel = 9999;
172 p_geomSvc->printTable();
173 p_geomSvc->printWirePosition();
174 p_geomSvc->printAlignPar();
180 costheta_plane[i] = p_geomSvc->getCostheta(i);
181 sintheta_plane[i] = p_geomSvc->getSintheta(i);
185 detectorIDs_mask[0] = p_geomSvc->getDetectorIDs(
"H1");
186 detectorIDs_mask[1] = p_geomSvc->getDetectorIDs(
"H2");
187 detectorIDs_mask[2] = p_geomSvc->getDetectorIDs(
"H3");
188 detectorIDs_mask[3] = p_geomSvc->getDetectorIDs(
"H4");
189 detectorIDs_maskX[0] = p_geomSvc->getDetectorIDs(
"H1[TB]");
190 detectorIDs_maskX[1] = p_geomSvc->getDetectorIDs(
"H2[TB]");
191 detectorIDs_maskX[2] = p_geomSvc->getDetectorIDs(
"H3[TB]");
192 detectorIDs_maskX[3] = p_geomSvc->getDetectorIDs(
"H4[TB]");
193 detectorIDs_maskY[0] = p_geomSvc->getDetectorIDs(
"H1[LR]");
194 detectorIDs_maskY[1] = p_geomSvc->getDetectorIDs(
"H2[LR]");
195 detectorIDs_maskY[2] = p_geomSvc->getDetectorIDs(
"H4Y1[LR]");
196 detectorIDs_maskY[3] = p_geomSvc->getDetectorIDs(
"H4Y2[LR]");
197 detectorIDs_muidHodoAid[0] = p_geomSvc->getDetectorIDs(
"H4[TB]");
198 detectorIDs_muidHodoAid[1] = p_geomSvc->getDetectorIDs(
"H4Y");
201 stationIDs_mask[0].push_back(1);
202 stationIDs_mask[1].push_back(1);
203 stationIDs_mask[2].push_back(2);
204 stationIDs_mask[3].push_back(3);
205 stationIDs_mask[4].push_back(3);
208 stationIDs_mask[5].push_back(2);
209 stationIDs_mask[5].push_back(3);
210 stationIDs_mask[5].push_back(4);
213 stationIDs_mask[6].push_back(1);
214 stationIDs_mask[6].push_back(2);
215 stationIDs_mask[6].push_back(3);
216 stationIDs_mask[6].push_back(4);
219 detectorIDs_muid[0][0] = p_geomSvc->getDetectorID(
"P1X1");
220 detectorIDs_muid[0][1] = p_geomSvc->getDetectorID(
"P1X2");
221 detectorIDs_muid[0][2] = p_geomSvc->getDetectorID(
"P2X1");
222 detectorIDs_muid[0][3] = p_geomSvc->getDetectorID(
"P2X2");
223 detectorIDs_muid[1][0] = p_geomSvc->getDetectorID(
"P1Y1");
224 detectorIDs_muid[1][1] = p_geomSvc->getDetectorID(
"P1Y2");
225 detectorIDs_muid[1][2] = p_geomSvc->getDetectorID(
"P2Y1");
226 detectorIDs_muid[1][3] = p_geomSvc->getDetectorID(
"P2Y2");
229 z_ref_muid[0][0] = MUID_Z_REF;
230 z_ref_muid[0][1] = MUID_Z_REF;
231 z_ref_muid[0][2] = 0.5*(p_geomSvc->getPlanePosition(detectorIDs_muid[0][0]) + p_geomSvc->getPlanePosition(detectorIDs_muid[0][1]));
232 z_ref_muid[0][3] = z_ref_muid[0][2];
234 z_ref_muid[1][0] = MUID_Z_REF;
235 z_ref_muid[1][1] = MUID_Z_REF;
236 z_ref_muid[1][2] = 0.5*(p_geomSvc->getPlanePosition(detectorIDs_muid[1][0]) + p_geomSvc->getPlanePosition(detectorIDs_muid[1][1]));
237 z_ref_muid[1][3] = z_ref_muid[1][2];
250 for(
int j = 1; j <= p_geomSvc->getPlaneNElements(i); j++)
252 double x_min, x_max, y_min, y_max;
253 p_geomSvc->get2DBoxSize(i, j, x_min, x_max, y_min, y_max);
255 x_min -= (factor*(x_max - x_min));
256 x_max += (factor*(x_max - x_min));
257 y_min -= (factor*(y_max - y_min));
258 y_max += (factor*(y_max - y_min));
268 cout <<
"========================" << endl;
269 cout <<
"Hodo. masking settings: " << endl;
270 for(
int i = 0; i < 4; i++)
272 cout <<
"For station " << i+1 << endl;
273 for(std::vector<int>::iterator iter = detectorIDs_mask[i].begin(); iter != detectorIDs_mask[i].end(); ++iter) cout <<
"All: " << *iter << endl;
274 for(std::vector<int>::iterator iter = detectorIDs_maskX[i].begin(); iter != detectorIDs_maskX[i].end(); ++iter) cout <<
"X: " << *iter << endl;
275 for(std::vector<int>::iterator iter = detectorIDs_maskY[i].begin(); iter != detectorIDs_maskY[i].end(); ++iter) cout <<
"Y: " << *iter << endl;
280 std::cout <<
"Masking stations for tracklets with stationID = " << i + 1 <<
": " << std::endl;
281 for(std::vector<int>::iterator iter = stationIDs_mask[i].begin(); iter != stationIDs_mask[i].end(); ++iter)
283 std::cout << *iter <<
" ";
285 std::cout << std::endl;
291 superIDs[0].push_back((p_geomSvc->getDetectorIDs(
"D0X")[0] + 1)/2);
292 superIDs[0].push_back((p_geomSvc->getDetectorIDs(
"D0U")[0] + 1)/2);
293 superIDs[0].push_back((p_geomSvc->getDetectorIDs(
"D0V")[0] + 1)/2);
294 superIDs[1].push_back((p_geomSvc->getDetectorIDs(
"D1X")[0] + 1)/2);
295 superIDs[1].push_back((p_geomSvc->getDetectorIDs(
"D1U")[0] + 1)/2);
296 superIDs[1].push_back((p_geomSvc->getDetectorIDs(
"D1V")[0] + 1)/2);
297 superIDs[2].push_back((p_geomSvc->getDetectorIDs(
"D2X")[0] + 1)/2);
298 superIDs[2].push_back((p_geomSvc->getDetectorIDs(
"D2U")[0] + 1)/2);
299 superIDs[2].push_back((p_geomSvc->getDetectorIDs(
"D2V")[0] + 1)/2);
300 superIDs[3].push_back((p_geomSvc->getDetectorIDs(
"D3pX")[0] + 1)/2);
301 superIDs[3].push_back((p_geomSvc->getDetectorIDs(
"D3pU")[0] + 1)/2);
302 superIDs[3].push_back((p_geomSvc->getDetectorIDs(
"D3pV")[0] + 1)/2);
303 superIDs[4].push_back((p_geomSvc->getDetectorIDs(
"D3mX")[0] + 1)/2);
304 superIDs[4].push_back((p_geomSvc->getDetectorIDs(
"D3mU")[0] + 1)/2);
305 superIDs[4].push_back((p_geomSvc->getDetectorIDs(
"D3mV")[0] + 1)/2);
307 superIDs[5].push_back((p_geomSvc->getDetectorIDs(
"P1X")[0] + 1)/2);
308 superIDs[5].push_back((p_geomSvc->getDetectorIDs(
"P2X")[0] + 1)/2);
309 superIDs[6].push_back((p_geomSvc->getDetectorIDs(
"P1Y")[0] + 1)/2);
310 superIDs[6].push_back((p_geomSvc->getDetectorIDs(
"P2Y")[0] + 1)/2);
313 cout <<
"=============" << endl;
314 cout <<
"Chamber IDs: " << endl;
315 TString stereoNames[3] = {
"X",
"U",
"V"};
318 for(
int j = 0; j < 3; j++) cout << i <<
" " << stereoNames[j].Data() <<
": " << superIDs[i][j] << endl;
321 cout <<
"Proptube IDs: " << endl;
324 for(
int j = 0; j < 2; j++) cout << i <<
" " << j <<
": " << superIDs[i][j] << endl;
328 cout <<
"======================" << endl;
329 cout <<
"U plane window sizes: " << endl;
332 double u_factor[] = {5., 5., 5., 15., 15.};
335 int xID = 2*superIDs[i][0] - 1;
336 int uID = 2*superIDs[i][1] - 1;
337 int vID = 2*superIDs[i][2] - 1;
338 double spacing = p_geomSvc->getPlaneSpacing(uID);
339 double x_span = p_geomSvc->getPlaneScaleY(uID);
341 z_plane_x[i] = 0.5*(p_geomSvc->getPlanePosition(xID) + p_geomSvc->getPlanePosition(xID+1));
342 z_plane_u[i] = 0.5*(p_geomSvc->getPlanePosition(uID) + p_geomSvc->getPlanePosition(uID+1));
343 z_plane_v[i] = 0.5*(p_geomSvc->getPlanePosition(vID) + p_geomSvc->getPlanePosition(vID+1));
345 u_costheta[i] = costheta_plane[uID];
346 u_sintheta[i] = sintheta_plane[uID];
349 u_win[i] = fabs(0.5*x_span*sintheta_plane[uID]) + TX_MAX*fabs((z_plane_u[i] - z_plane_x[i])*u_costheta[i]) + TY_MAX*fabs((z_plane_u[i] - z_plane_x[i])*u_sintheta[i]) + 2.*spacing + u_factor[i];
352 cout <<
"Station " << i <<
": " << xID <<
" " << uID <<
" " << vID <<
" " << u_win[i] << endl;
359 z_plane[i] = p_geomSvc->getPlanePosition(i);
360 slope_max[i] = costheta_plane[i]*TX_MAX + sintheta_plane[i]*TY_MAX;
361 intersection_max[i] = costheta_plane[i]*X0_MAX + sintheta_plane[i]*Y0_MAX;
364 resol_plane[i] = 3.*p_geomSvc->getPlaneSpacing(i)/sqrt(12.);
387 spacing_plane[i] = p_geomSvc->getPlaneSpacing(i);
391 cout <<
"======================================" << endl;
392 cout <<
"Maximum local slope and intersection: " << endl;
396 double d_slope = (p_geomSvc->getPlaneResolution(2*i - 1) + p_geomSvc->getPlaneResolution(2*i))/(z_plane[2*i] - z_plane[2*i-1]);
397 double d_intersection = d_slope*z_plane[2*i];
399 slope_max[2*i-1] += d_slope;
400 intersection_max[2*i-1] += d_intersection;
401 slope_max[2*i] += d_slope;
402 intersection_max[2*i] += d_intersection;
405 cout <<
"Super plane " << i <<
": " << slope_max[2*i-1] <<
" " << intersection_max[2*i-1] << endl;
410 s_detectorID[0] = p_geomSvc->getDetectorID(
"D2X");
411 s_detectorID[1] = p_geomSvc->getDetectorID(
"D2Up");
412 s_detectorID[2] = p_geomSvc->getDetectorID(
"D2Vp");
417 if(enable_KF)
delete kmfitter;
424 rawEvent = event_input;
431 for(
auto iter=_timers.begin(); iter != _timers.end(); ++iter)
433 iter->second->reset();
437 for(
int i = 0; i < 5; i++) trackletsInSt[i].clear();
441 rawEvent = event_input;
445 for(std::vector<Hit>::iterator iter = hitAll.begin(); iter != hitAll.end(); ++iter) iter->print();
449 for(
int i = 0; i < 4; i++)
452 hitIDs_mask[i].clear();
467 for(
int i = 0; i < 2; ++i)
469 for(
int j = 0; j < 4; ++j)
471 hitIDs_muid[i][j].clear();
474 hitIDs_muidHodoAid[i].clear();
481 if(propSegs[0].empty() || propSegs[1].empty())
484 LogInfo(
"Failed in prop tube segment building: " << propSegs[0].size() <<
", " << propSegs[1].size());
491 _timers[
"st2"]->restart();
493 _timers[
"st2"]->stop();
494 if(verbosity >= 2)
LogInfo(
"NTracklets in St2: " << trackletsInSt[1].size());
496 if(outputListIdx > 1 && trackletsInSt[1].empty())
499 LogInfo(
"Failed in tracklet build at station 2");
504 _timers[
"st3"]->restart();
507 _timers[
"st3"]->stop();
508 if(verbosity >= 2)
LogInfo(
"NTracklets in St3: " << trackletsInSt[2].size());
510 if(outputListIdx > 2 && trackletsInSt[2].empty())
513 LogInfo(
"Failed in tracklet build at station 3");
519 _timers[
"st23"]->restart();
521 _timers[
"st23"]->stop();
522 if(verbosity >= 2)
LogInfo(
"NTracklets St2+St3: " << trackletsInSt[3].size());
525 if(outputListIdx > 3 && trackletsInSt[3].empty())
528 LogInfo(
"Failed in connecting station-2 and 3 tracks");
534 _timers[
"global"]->restart();
536 _timers[
"global"]->stop();
537 if(verbosity >= 2)
LogInfo(
"NTracklets Global: " << trackletsInSt[4].size());
540 for(
int i = 0; i < 2; ++i)
542 std::cout <<
"=======================================================================================" << std::endl;
543 LogInfo(
"Prop tube segments in " << (i == 0 ?
"X-Z" :
"Y-Z"));
544 for(std::list<PropSegment>::iterator seg = propSegs[i].begin(); seg != propSegs[i].end(); ++seg)
548 std::cout <<
"=======================================================================================" << std::endl;
551 for(
int i = 0; i <= 4; i++)
553 std::cout <<
"=======================================================================================" << std::endl;
554 LogInfo(
"Final tracklets in station: " << i+1 <<
" is " << trackletsInSt[i].size());
555 for(std::list<Tracklet>::iterator tracklet = trackletsInSt[i].begin(); tracklet != trackletsInSt[i].end(); ++tracklet)
559 std::cout <<
"=======================================================================================" << std::endl;
567 _timers[
"kalman"]->restart();
568 for(std::list<Tracklet>::iterator tracklet = trackletsInSt[outputListIdx].begin(); tracklet != trackletsInSt[outputListIdx].end(); ++tracklet)
571 stracks.push_back(strack);
573 _timers[
"kalman"]->stop();
576 LogInfo(stracks.size() <<
" final tracks:");
577 for(std::list<SRecTrack>::iterator strack = stracks.begin(); strack != stracks.end(); ++strack)
627 int nHitsX2, nHitsX3;
628 double z_fit[4], x_fit[4];
631 for(std::list<Tracklet>::iterator tracklet3 = trackletsInSt[2].begin(); tracklet3 != trackletsInSt[2].end(); ++tracklet3)
637 for(std::list<SignedHit>::iterator ptr_hit = tracklet3->hits.begin(); ptr_hit != tracklet3->hits.end(); ++ptr_hit)
639 if(ptr_hit->hit.index < 0)
continue;
640 if(p_geomSvc->
getPlaneType(ptr_hit->hit.detectorID) == 1)
642 z_fit[nHitsX3] = z_plane[ptr_hit->hit.detectorID];
643 x_fit[nHitsX3] = ptr_hit->hit.pos;
650 for(std::list<Tracklet>::iterator tracklet2 = trackletsInSt[1].begin(); tracklet2 != trackletsInSt[1].end(); ++tracklet2)
654 if(fabs(tracklet2->tx - tracklet3->tx) > 0.15 || fabs(tracklet2->ty - tracklet3->ty) > 0.1)
continue;
658 for(std::list<SignedHit>::iterator ptr_hit = tracklet2->hits.begin(); ptr_hit != tracklet2->hits.end(); ++ptr_hit)
660 if(ptr_hit->hit.index < 0)
continue;
661 if(p_geomSvc->
getPlaneType(ptr_hit->hit.detectorID) == 1)
663 z_fit[nHitsX2] = z_plane[ptr_hit->hit.detectorID];
664 x_fit[nHitsX2] = ptr_hit->hit.pos;
670 chi2fit(nHitsX2, z_fit, x_fit, a, b);
671 if(fabs(a) > 2.*TX_MAX || fabs(b) > 2.*X0_MAX)
continue;
675 for(
int i = 0; i < 4; ++i)
677 double x_exp = a*z_mask[detectorIDs_muid[0][i] -
nChamberPlanes - 1] + b;
678 for(std::list<int>::iterator iter = hitIDs_muid[0][i].begin(); iter != hitIDs_muid[0][i].end(); ++iter)
680 if(fabs(hitAll[*iter].pos - x_exp) < 5.08)
686 if(nPropHits > 0)
break;
688 if(nPropHits == 0)
continue;
691 Tracklet tracklet_23 = (*tracklet2) + (*tracklet3);
693 LogInfo(
"Using following two tracklets:");
696 LogInfo(
"Yield this combination:");
700 if(tracklet_23.
chisq > 9000.)
704 LogInfo(
"Impossible combination!");
709 if(!COARSE_MODE && !
hodoMask(tracklet_23))
712 LogInfo(
"Hodomasking failed!");
717 LogInfo(
"Hodomasking Scucess!");
734 tracklet_best.
print();
736 LogInfo(
"Comparison: " << (tracklet_23 < tracklet_best));
743 tracklet_best = tracklet_23;
753 if(tracklet_best.
isValid() > 0) trackletsInSt[3].push_back(tracklet_best);
757 trackletsInSt[3].sort();
762 double pos_exp[3], window[3];
763 for(std::list<Tracklet>::iterator tracklet23 = trackletsInSt[3].begin(); tracklet23 != trackletsInSt[3].end(); ++tracklet23)
766 for(
int i = 0; i < 2; ++i)
768 trackletsInSt[0].clear();
781 LogInfo(
"Using this back partial: ");
783 for(
int j = 0; j < 3; j++)
LogInfo(
"Extrapo: " << pos_exp[j] <<
" " << window[j]);
786 _timers[
"global_st1"]->restart();
788 _timers[
"global_st1"]->stop();
790 _timers[
"global_link"]->restart();
791 Tracklet tracklet_best_prob, tracklet_best_vtx;
792 for(std::list<Tracklet>::iterator tracklet1 = trackletsInSt[0].begin(); tracklet1 != trackletsInSt[0].end(); ++tracklet1)
795 LogInfo(
"With this station 1 track:");
799 Tracklet tracklet_global = (*tracklet23) * (*tracklet1);
801 if(!
hodoMask(tracklet_global))
continue;
818 if(tracklet_global < tracklet_best_prob) tracklet_best_prob = tracklet_global;
824 _timers[
"global_kalman"]->restart();
826 _timers[
"global_kalman"]->stop();
834 tracklet_global.
print();
836 LogInfo(
"Current best by prob:");
837 tracklet_best_prob.
print();
839 LogInfo(
"Comparison I: " << (tracklet_global < tracklet_best_prob));
844 LogInfo(
"Current best by vtx:");
845 tracklet_best_vtx.
print();
852 _timers[
"global_link"]->stop();
855 if(enable_KF && tracklet_best_prob.
isValid() > 0 && 1./tracklet_best_prob.
invP > 18.)
857 tracklet_best[i] = tracklet_best_prob;
859 else if(enable_KF && tracklet_best_vtx.
isValid() > 0)
861 tracklet_best[i] = tracklet_best_vtx;
863 else if(tracklet_best_prob.
isValid() > 0)
865 tracklet_best[i] = tracklet_best_prob;
871 if(fabs(tracklet_best[0].getMomentum() - tracklet_best[1].getMomentum())/tracklet_best[0].
getMomentum() < MERGE_THRES)
874 tracklet_merge = tracklet_best[0].
merge(tracklet_best[1]);
878 LogInfo(
"Merging two track candidates with momentum: " << tracklet_best[0].getMomentum() <<
" " << tracklet_best[1].getMomentum());
885 if(tracklet_merge.
isValid() > 0 && tracklet_merge < tracklet_best[0] && tracklet_merge < tracklet_best[1])
888 LogInfo(
"Choose merged tracklet");
890 trackletsInSt[4].push_back(tracklet_merge);
892 else if(tracklet_best[0].isValid() > 0 && tracklet_best[0] < tracklet_best[1])
895 LogInfo(
"Choose tracklet with station-0");
897 trackletsInSt[4].push_back(tracklet_best[0]);
899 else if(tracklet_best[1].isValid() > 0)
902 LogInfo(
"Choose tracklet with station-1");
904 trackletsInSt[4].push_back(tracklet_best[1]);
908 trackletsInSt[4].sort();
914 LogInfo(
"Left right for this track..");
919 bool isUpdated =
false;
922 int possibility[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
925 int nPairs = tracklet.
hits.size()/2;
928 std::list<SignedHit>::iterator hit1 = tracklet.
hits.begin();
929 std::list<SignedHit>::iterator hit2 = tracklet.
hits.begin();
934 LogInfo(hit1->hit.index <<
" " << hit2->sign <<
" === " << hit2->hit.index <<
" " << hit2->sign);
935 int detectorID1 = hit1->hit.detectorID;
936 int detectorID2 = hit2->hit.detectorID;
937 LogInfo(
"Hit1: " << tracklet.
getExpPositionX(z_plane[detectorID1])*costheta_plane[detectorID1] + tracklet.
getExpPositionY(z_plane[detectorID1])*sintheta_plane[detectorID1] <<
" " << hit1->hit.pos + hit1->hit.driftDistance <<
" " << hit1->hit.pos - hit1->hit.driftDistance);
938 LogInfo(
"Hit2: " << tracklet.
getExpPositionX(z_plane[detectorID2])*costheta_plane[detectorID2] + tracklet.
getExpPositionY(z_plane[detectorID2])*sintheta_plane[detectorID2] <<
" " << hit2->hit.pos + hit2->hit.driftDistance <<
" " << hit2->hit.pos - hit2->hit.driftDistance);
941 if(hit1->hit.index > 0 && hit2->hit.index > 0 && hit1->sign*hit2->sign == 0)
944 double pull_min = 1E6;
945 for(
int i = 0; i < 4; i++)
947 double slope_local = (hit1->pos(possibility[i][0]) - hit2->pos(possibility[i][1]))/(z_plane[hit1->hit.detectorID] - z_plane[hit2->hit.detectorID]);
948 double inter_local = hit1->pos(possibility[i][0]) - slope_local*z_plane[hit1->hit.detectorID];
950 if(fabs(slope_local) > slope_max[hit1->hit.detectorID] || fabs(inter_local) > intersection_max[hit1->hit.detectorID])
continue;
952 double tx, ty, x0, y0;
953 double err_tx, err_ty, err_x0, err_y0;
954 if(tracklet.
stationID == 6 && hit1->hit.detectorID <= 6)
971 double slope_exp = costheta_plane[hit1->hit.detectorID]*tx + sintheta_plane[hit1->hit.detectorID]*ty;
972 double err_slope = fabs(costheta_plane[hit1->hit.detectorID]*err_tx) + fabs(sintheta_plane[hit2->hit.detectorID]*err_ty);
973 double inter_exp = costheta_plane[hit1->hit.detectorID]*x0 + sintheta_plane[hit1->hit.detectorID]*y0;
974 double err_inter = fabs(costheta_plane[hit1->hit.detectorID]*err_x0) + fabs(sintheta_plane[hit2->hit.detectorID]*err_y0);
976 double pull = sqrt((slope_exp - slope_local)*(slope_exp - slope_local)/err_slope/err_slope + (inter_exp - inter_local)*(inter_exp - inter_local)/err_inter/err_inter);
984 LogInfo(hit1->hit.detectorID <<
": " << i <<
" " << possibility[i][0] <<
" " << possibility[i][1]);
985 LogInfo(tx <<
" " << x0 <<
" " << ty <<
" " << y0);
986 LogInfo(
"Slope: " << slope_local <<
" " << slope_exp <<
" " << err_slope);
987 LogInfo(
"Intersection: " << inter_local <<
" " << inter_exp <<
" " << err_inter);
988 LogInfo(
"Current: " << pull <<
" " << index_min <<
" " << pull_min);
993 if(index_min >= 0 && pull_min < threshold)
995 hit1->sign = possibility[index_min][0];
996 hit2->sign = possibility[index_min][1];
1002 if(nResolved >= nPairs)
break;
1016 LogInfo(
"Single left right for this track..");
1021 bool isUpdated =
false;
1022 for(std::list<SignedHit>::iterator hit_sign = tracklet.
hits.begin(); hit_sign != tracklet.
hits.end(); ++hit_sign)
1024 if(hit_sign->hit.index < 0 || hit_sign->sign != 0)
continue;
1026 int detectorID = hit_sign->hit.detectorID;
1027 double pos_exp = tracklet.
getExpPositionX(z_plane[detectorID])*costheta_plane[detectorID] + tracklet.
getExpPositionY(z_plane[detectorID])*sintheta_plane[detectorID];
1028 hit_sign->sign = pos_exp > hit_sign->hit.pos ? 1 : -1;
1039 LogInfo(
"Removing hits for this track..");
1048 bool isUpdated =
true;
1056 double res_remove1 = -1.;
1057 double res_remove2 = -1.;
1058 for(std::list<SignedHit>::iterator hit_sign = tracklet.
hits.begin(); hit_sign != tracklet.
hits.end(); ++hit_sign)
1060 if(hit_sign->hit.index < 0)
continue;
1063 double res_curr = fabs(tracklet.
residual[detectorID-1]);
1064 if(res_remove1 < res_curr)
1066 res_remove1 = res_curr;
1067 res_remove2 = fabs(tracklet.
residual[detectorID-1] - 2.*hit_sign->sign*hit_sign->hit.driftDistance);
1068 hit_remove = &(*hit_sign);
1070 std::list<SignedHit>::iterator iter = hit_sign;
1071 hit_neighbour = detectorID % 2 == 0 ? &(*(--iter)) : &(*(++iter));
1074 if(hit_remove ==
nullptr)
continue;
1075 if(hit_remove->
sign == 0 && tracklet.
isValid() > 0)
continue;
1078 if(res_remove1 > cut)
1081 LogInfo(
"Dropping this hit: " << res_remove1 <<
" " << res_remove2 <<
" " << signflipflag[hit_remove->
hit.
detectorID-1] <<
" " << cut);
1087 if(res_remove2 < cut && signflipflag[hit_remove->
hit.
detectorID-1] < 2)
1089 hit_remove->
sign = -hit_remove->
sign;
1090 hit_neighbour->
sign = 0;
1093 LogInfo(
"Only changing the sign.");
1101 hit_neighbour->
sign = 0;
1107 else if(planeType == 2)
1120 LogInfo(
"Both hits in a view are missing! Will exit the bad hit removal...");
1142 if(hpair.first < 0 || hpair.second < 0)
1147 int possibility[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
1149 for(
int i = 0; i < 4; i++)
1151 if(nResolved > 1)
break;
1153 int hitID1 = hpair.first;
1154 int hitID2 = hpair.second;
1155 double slope_local = (hitAll[hitID1].pos + possibility[i][0]*hitAll[hitID1].driftDistance - hitAll[hitID2].pos - possibility[i][1]*hitAll[hitID2].driftDistance)/(z_plane[hitAll[hitID1].detectorID] - z_plane[hitAll[hitID2].detectorID]);
1156 double intersection_local = hitAll[hitID1].pos + possibility[i][0]*hitAll[hitID1].driftDistance - slope_local*z_plane[hitAll[hitID1].detectorID];
1159 if(fabs(slope_local) < slope_max[hitAll[hitID1].detectorID] && fabs(intersection_local) < intersection_max[hitAll[hitID1].detectorID])
1162 LR1 = possibility[i][0];
1163 LR2 = possibility[i][1];
1179 LogInfo(
"Building tracklets in station " << stationID);
1183 int sID = stationID - 1;
1186 std::list<SRawEvent::hit_pair> pairs_X, pairs_U, pairs_V;
1187 if(pos_exp ==
nullptr)
1202 LogInfo(
"Hit pairs in this event: ");
1203 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_X.begin(); iter != pairs_X.end(); ++iter)
LogInfo(
"X :" << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1204 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_U.begin(); iter != pairs_U.end(); ++iter)
LogInfo(
"U :" << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1205 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_V.begin(); iter != pairs_V.end(); ++iter)
LogInfo(
"V :" << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1208 if(pairs_X.empty() || pairs_U.empty() || pairs_V.empty())
1211 LogInfo(
"Not all view has hits in station " << stationID);
1217 for(std::list<SRawEvent::hit_pair>::iterator xiter = pairs_X.begin(); xiter != pairs_X.end(); ++xiter)
1220 double x_pos = xiter->second >= 0 ? 0.5*(hitAll[xiter->first].pos + hitAll[xiter->second].pos) : hitAll[xiter->first].pos;
1221 double u_min = x_pos*u_costheta[sID] - u_win[sID];
1222 double u_max = u_min + 2.*u_win[sID];
1225 LogInfo(
"Trying X hits " << xiter->first <<
" " << xiter->second <<
" " << hitAll[xiter->first].elementID <<
" at " << x_pos);
1226 LogInfo(
"U plane window:" << u_min <<
" " << u_max);
1228 for(std::list<SRawEvent::hit_pair>::iterator uiter = pairs_U.begin(); uiter != pairs_U.end(); ++uiter)
1230 double u_pos = uiter->second >= 0 ? 0.5*(hitAll[uiter->first].pos + hitAll[uiter->second].pos) : hitAll[uiter->first].pos;
1232 LogInfo(
"Trying U hits " << uiter->first <<
" " << uiter->second <<
" " << hitAll[uiter->first].elementID <<
" at " << u_pos);
1234 if(u_pos < u_min || u_pos > u_max)
continue;
1237 double z_x = xiter->second >= 0 ? z_plane_x[sID] : z_plane[hitAll[xiter->first].detectorID];
1238 double z_u = uiter->second >= 0 ? z_plane_u[sID] : z_plane[hitAll[uiter->first].detectorID];
1239 double z_v = z_plane_v[sID];
1240 double v_win1 = spacing_plane[hitAll[uiter->first].detectorID]*2.*u_costheta[sID];
1241 double v_win2 = fabs((z_u + z_v - 2.*z_x)*u_costheta[sID]*TX_MAX);
1242 double v_win3 = fabs((z_v - z_u)*u_sintheta[sID]*TY_MAX);
1243 double v_win = v_win1 + v_win2 + v_win3 + 2.*spacing_plane[hitAll[uiter->first].detectorID];
1244 double v_min = 2*x_pos*u_costheta[sID] - u_pos - v_win;
1245 double v_max = v_min + 2.*v_win;
1248 LogInfo(
"V plane window:" << v_min <<
" " << v_max);
1250 for(std::list<SRawEvent::hit_pair>::iterator viter = pairs_V.begin(); viter != pairs_V.end(); ++viter)
1252 double v_pos = viter->second >= 0 ? 0.5*(hitAll[viter->first].pos + hitAll[viter->second].pos) : hitAll[viter->first].pos;
1254 LogInfo(
"Trying V hits " << viter->first <<
" " << viter->second <<
" " << hitAll[viter->first].elementID <<
" at " << v_pos);
1256 if(v_pos < v_min || v_pos > v_max)
continue;
1265 if(xiter->first >= 0)
1267 tracklet_new.
hits.push_back(
SignedHit(hitAll[xiter->first], LR1));
1270 if(xiter->second >= 0)
1272 tracklet_new.
hits.push_back(
SignedHit(hitAll[xiter->second], LR2));
1277 if(uiter->first >= 0)
1279 tracklet_new.
hits.push_back(
SignedHit(hitAll[uiter->first], LR1));
1282 if(uiter->second >= 0)
1284 tracklet_new.
hits.push_back(
SignedHit(hitAll[uiter->second], LR2));
1289 if(viter->first >= 0)
1291 tracklet_new.
hits.push_back(
SignedHit(hitAll[viter->first], LR1));
1294 if(viter->second >= 0)
1296 tracklet_new.
hits.push_back(
SignedHit(hitAll[viter->second], LR2));
1301 if(tracklet_new.
isValid() == 0)
1311 tracklet_new.
print();
1315 trackletsInSt[listID].push_back(tracklet_new);
1329 for(std::list<Tracklet>::iterator iter = trackletsInSt[listID].begin(); iter != trackletsInSt[listID].end(); ++iter)
1331 iter->addDummyHits();
1335 if(trackletsInSt[listID].size() > 200)
1337 trackletsInSt[listID].sort();
1338 trackletsInSt[listID].resize(200);
1348 LogInfo(
"Failed in quality check!");
1353 if(COARSE_MODE)
return true;
1356 if(!
hodoMask(tracklet))
return false;
1376 for(std::vector<int>::iterator stationID = stationIDs_mask[tracklet.
stationID-1].begin(); stationID != stationIDs_mask[tracklet.
stationID-1].end(); ++stationID)
1378 bool masked =
false;
1379 for(std::list<int>::iterator iter = hitIDs_mask[*stationID-1].begin(); iter != hitIDs_mask[*stationID-1].end(); ++iter)
1381 int detectorID = hitAll[*iter].detectorID;
1382 int elementID = hitAll[*iter].elementID;
1385 int idx2 = elementID - 1;
1387 double factor = tracklet.
stationID == nChamberPlanes/6-2 ? 5. : 3.;
1388 double xfudge = tracklet.
stationID <
nStations-1 ? 0.5*(x_mask_max[idx1][idx2] - x_mask_min[idx1][idx2]) : 0.15*(x_mask_max[idx1][idx2] - x_mask_min[idx1][idx2]);
1389 double z_hodo = z_mask[idx1];
1395 double x_min = x_mask_min[idx1][idx2] - err_x;
1396 double x_max = x_mask_max[idx1][idx2] + err_x;
1397 double y_min = y_mask_min[idx1][idx2] - err_y;
1398 double y_max = y_mask_max[idx1][idx2] + err_y;
1402 hitAll[*iter].print();
1403 LogInfo(nHodoHits <<
"/" << stationIDs_mask[tracklet.
stationID-1].size() <<
": " << z_hodo <<
" " << x_hodo <<
" +/- " << err_x <<
" " << y_hodo <<
" +/-" << err_y <<
" : " << x_min <<
" " << x_max <<
" " << y_min <<
" " << y_max);
1405 if(x_hodo > x_min && x_hodo < x_max && y_hodo > y_min && y_hodo < y_max)
1414 if(!masked)
return false;
1430 double cut_the = MUID_THE_P0*tracklet.
invP;
1431 double cut_emp = MUID_EMP_P0 + MUID_EMP_P1/tracklet.
invP + MUID_EMP_P2/tracklet.
invP/tracklet.
invP;
1432 cut = MUID_REJECTION*(cut_the > cut_emp ? cut_the : cut_emp);
1435 double slope[2] = {tracklet.
tx, tracklet.
ty};
1438 for(
int i = 0; i < 2; ++i)
1444 for(
int j = 0; j < 4; ++j)
1447 double pos_ref = j < 2 ? pos_absorb[i] : segs[i]->
getPosRef(pos_absorb[i] + slope[i]*(z_ref_muid[i][j] - MUID_Z_REF));
1448 double pos_exp = slope[i]*(z_mask[index] - z_ref_muid[i][j]) + pos_ref;
1452 double win_tight = cut*(z_mask[index] - z_ref_muid[i][j]);
1453 win_tight = win_tight > 2.54 ? win_tight : 2.54;
1454 double win_loose = win_tight*2;
1455 double dist_min = 1E6;
1456 for(std::list<int>::iterator iter = hitIDs_muid[i][j].begin(); iter != hitIDs_muid[i][j].end(); ++iter)
1458 double pos = hitAll[*iter].pos;
1459 double dist = pos - pos_exp;
1460 if(dist < -win_loose)
continue;
1461 if(dist > win_loose)
break;
1463 double dist_l = fabs(pos - hitAll[*iter].driftDistance - pos_exp);
1464 double dist_r = fabs(pos + hitAll[*iter].driftDistance - pos_exp);
1465 dist = dist_l < dist_r ? dist_l : dist_r;
1469 if(dist < win_tight)
1471 segs[i]->
hits[j].
hit = hitAll[*iter];
1472 segs[i]->
hits[j].
sign = fabs(pos - hitAll[*iter].driftDistance - pos_exp) < fabs(pos + hitAll[*iter].driftDistance - pos_exp) ? -1 : 1;
1484 if(segs[0]->getNHits() + segs[1]->getNHits() >= MUID_MINHITS)
1488 else if(segs[1]->getNHits() == 1 || segs[1]->getNPlanes() == 1)
1502 double cut_the = MUID_THE_P0*tracklet.
invP;
1503 double cut_emp = MUID_EMP_P0 + MUID_EMP_P1/tracklet.
invP + MUID_EMP_P2/tracklet.
invP/tracklet.
invP;
1504 cut = MUID_REJECTION*(cut_the > cut_emp ? cut_the : cut_emp);
1507 LogInfo(
"Muon ID cut is: " << cut <<
" rad.");
1510 double slope[2] = {tracklet.
tx, tracklet.
ty};
1513 for(
int i = 0; i < 2; ++i)
1516 if(i == 0)
LogInfo(
"Working in X-Z:");
1517 if(i == 1)
LogInfo(
"Working in Y-Z:");
1521 if(segs[i]->getNHits() > 2 && segs[i]->isValid() > 0 && fabs(slope[i] - segs[i]->a) < cut && fabs(segs[i]->getExpPosition(MUID_Z_REF) - pos_ref) < MUID_R_CUT)
1524 LogInfo(
"Muon ID are already avaiable!");
1529 for(std::list<PropSegment>::iterator iter = propSegs[i].begin(); iter != propSegs[i].end(); ++iter)
1532 LogInfo(
"Testing this prop segment, with ref pos = " << pos_ref <<
", slope_ref = " << slope[i]);
1535 if(fabs(iter->a - slope[i]) < cut && fabs(iter->getExpPosition(MUID_Z_REF) - pos_ref) < MUID_R_CUT)
1545 if(segs[i]->isValid() == 0)
return false;
1548 if(segs[0]->getNHits() + segs[1]->getNHits() < MUID_MINHITS)
return false;
1558 double win_the = MUID_THE_P0*tracklet.
invP;
1559 double win_emp = MUID_EMP_P0 + MUID_EMP_P1/tracklet.
invP + MUID_EMP_P2/tracklet.
invP/tracklet.
invP;
1560 win = MUID_REJECTION*(win_the > win_emp ? win_the : win_emp);
1565 for(
int i = 0; i < 2; ++i)
1568 for(std::list<int>::iterator iter = hitIDs_muidHodoAid[i].begin(); iter != hitIDs_muidHodoAid[i].end(); ++iter)
1570 int detectorID = hitAll[*iter].detectorID;
1571 int elementID = hitAll[*iter].elementID;
1574 int idx2 = elementID - 1;
1576 double z_hodo = z_mask[idx1];
1579 double err_x = factor*tracklet.
getExpPosErrorX(z_hodo) + win*(z_hodo - MUID_Z_REF);
1580 double err_y = factor*tracklet.
getExpPosErrorY(z_hodo) + win*(z_hodo - MUID_Z_REF);
1582 err_x = err_x/(x_mask_max[idx1][idx2] - x_mask_min[idx1][idx2]) > 0.25 ? 0.25*err_x/(x_mask_max[idx1][idx2] - x_mask_min[idx1][idx2]) : err_x;
1583 err_y = err_y/(y_mask_max[idx1][idx2] - y_mask_min[idx1][idx2]) > 0.25 ? 0.25*err_y/(y_mask_max[idx1][idx2] - y_mask_min[idx1][idx2]) : err_y;
1585 double x_min = x_mask_min[idx1][idx2] - err_x;
1586 double x_max = x_mask_max[idx1][idx2] + err_x;
1587 double y_min = y_mask_min[idx1][idx2] - err_y;
1588 double y_max = y_mask_max[idx1][idx2] + err_y;
1590 if(x_hodo > x_min && x_hodo < x_max && y_hodo > y_min && y_hodo < y_max)
1593 if(segs[i]->nHodoHits > 4)
break;
1604 LogInfo(
"Building prop. tube segments");
1607 for(
int i = 0; i < 2; ++i)
1609 propSegs[i].clear();
1616 std::cout <<
"superID: " << superIDs[i+5][0] <<
", " << superIDs[i+5][1] << std::endl;
1617 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_forward.begin(); iter != pairs_forward.end(); ++iter)
1618 LogInfo(
"Forward: " << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1619 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_backward.begin(); iter != pairs_backward.end(); ++iter)
1620 LogInfo(
"Backward: " << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1623 for(std::list<SRawEvent::hit_pair>::iterator fiter = pairs_forward.begin(); fiter != pairs_forward.end(); ++fiter)
1626 LogInfo(
"Trying forward pair " << fiter->first <<
" " << fiter->second);
1628 for(std::list<SRawEvent::hit_pair>::iterator biter = pairs_backward.begin(); biter != pairs_backward.end(); ++biter)
1631 LogInfo(
"Trying backward pair " << biter->first <<
" " << biter->second);
1637 if(fiter->first >= 0) seg.
hits[1] =
SignedHit(hitAll[fiter->first], 0);
1638 if(fiter->second >= 0) seg.
hits[0] =
SignedHit(hitAll[fiter->second], 0);
1639 if(biter->first >= 0) seg.
hits[3] =
SignedHit(hitAll[biter->first], 0);
1640 if(biter->second >= 0) seg.
hits[2] =
SignedHit(hitAll[biter->second], 0);
1652 propSegs[i].push_back(seg);
1668 tracklet_curr = tracklet;
1672 #ifdef _ENABLE_MULTI_MINI
1676 minimizer[idx]->SetLimitedVariable(0,
"tx", tracklet.
tx, 0.001, -TX_MAX, TX_MAX);
1677 minimizer[idx]->SetLimitedVariable(1,
"ty", tracklet.
ty, 0.001, -TY_MAX, TY_MAX);
1678 minimizer[idx]->SetLimitedVariable(2,
"x0", tracklet.
x0, 0.1, -X0_MAX, X0_MAX);
1679 minimizer[idx]->SetLimitedVariable(3,
"y0", tracklet.
y0, 0.1, -Y0_MAX, Y0_MAX);
1682 minimizer[idx]->SetLimitedVariable(4,
"invP", tracklet.
invP, 0.001*tracklet.
invP, INVP_MIN, INVP_MAX);
1684 minimizer[idx]->Minimize();
1686 tracklet.
tx = minimizer[idx]->X()[0];
1687 tracklet.
ty = minimizer[idx]->X()[1];
1688 tracklet.
x0 = minimizer[idx]->X()[2];
1689 tracklet.
y0 = minimizer[idx]->X()[3];
1691 tracklet.
err_tx = minimizer[idx]->Errors()[0];
1692 tracklet.
err_ty = minimizer[idx]->Errors()[1];
1693 tracklet.
err_x0 = minimizer[idx]->Errors()[2];
1694 tracklet.
err_y0 = minimizer[idx]->Errors()[3];
1698 tracklet.
invP = minimizer[idx]->X()[4];
1699 tracklet.
err_invP = minimizer[idx]->Errors()[4];
1702 tracklet.
chisq = minimizer[idx]->MinValue();
1704 int status = minimizer[idx]->Status();
1710 std::list<Tracklet> targetList;
1713 while(!tracklets.empty())
1715 targetList.push_back(tracklets.front());
1716 tracklets.pop_front();
1718 #ifdef _DEBUG_ON_LEVEL_2
1719 LogInfo(
"Current best tracklet in reduce");
1720 targetList.back().print();
1723 for(std::list<Tracklet>::iterator iter = tracklets.begin(); iter != tracklets.end(); )
1725 if(iter->similarity(targetList.back()))
1727 #ifdef _DEBUG_ON_LEVEL_2
1728 LogInfo(
"Removing this tracklet: ");
1731 iter = tracklets.erase(iter);
1741 tracklets.assign(targetList.begin(), targetList.end());
1749 for(
int i = 0; i < 3; i++)
1757 for(
int i = 0; i < 3; i++)
1759 int detectorID = (st1ID-1)*6 + 2*i + 2;
1762 double z_st1 = z_plane[detectorID];
1769 window[idx] = 5.*(fabs(costheta_plane[detectorID]*err_x) + fabs(sintheta_plane[detectorID]*err_y));
1777 for(
int i = 0; i < 3; i++)
1785 double z_st3 = z_plane[tracklet.
hits.back().hit.detectorID];
1790 for(
int i = 0; i < 3; i++)
1792 int detectorID = (st1ID-1)*6 + 2*i + 2;
1795 if(!(idx >= 0 && idx <3))
continue;
1799 double z_st1 = z_plane[detectorID];
1800 double z_st2 = z_plane[s_detectorID[idx]];
1805 double s2_target = pos_st2 - pos_st3*(z_st2 - Z_TARGET)/(z_st3 - Z_TARGET);
1806 double s2_dump = pos_st2 - pos_st3*(z_st2 - Z_DUMP)/(z_st3 - Z_DUMP);
1808 double pos_exp_target = SAGITTA_TARGET_CENTER*s2_target + pos_st3*(z_st1 - Z_TARGET)/(z_st3 - Z_TARGET);
1809 double pos_exp_dump = SAGITTA_DUMP_CENTER*s2_dump + pos_st3*(z_st1 - Z_DUMP)/(z_st3 - Z_DUMP);
1810 double win_target = fabs(s2_target*SAGITTA_TARGET_WIDTH);
1811 double win_dump = fabs(s2_dump*SAGITTA_DUMP_WIDTH);
1813 double p_min = std::min(pos_exp_target - win_target, pos_exp_dump - win_dump);
1814 double p_max = std::max(pos_exp_target + win_target, pos_exp_dump + win_dump);
1816 pos_exp[idx] = 0.5*(p_max + p_min);
1817 window[idx] = 0.5*(p_max - p_min);
1825 std::vector<double> x, y, dx, dy;
1826 for(std::list<Tracklet>::iterator iter = trackletsInSt[stationID].begin(); iter != trackletsInSt[stationID].end(); ++iter)
1829 x.push_back(iter->getExpPositionX(z));
1830 y.push_back(iter->getExpPositionY(z));
1831 dx.push_back(iter->getExpPosErrorX(z));
1832 dy.push_back(iter->getExpPosErrorY(z));
1835 TGraphErrors gr(x.size(), &x[0], &y[0], &dx[0], &dy[0]);
1836 gr.SetMarkerStyle(8);
1839 std::vector<double> x_f, y_f, dx_f, dy_f;
1853 TGraphErrors gr_frame(x_f.size(), &x_f[0], &y_f[0], &dx_f[0], &dy_f[0]);
1854 gr_frame.SetLineColor(kRed);
1855 gr_frame.SetLineWidth(2);
1856 gr_frame.SetFillColor(15);
1859 gr_frame.Draw(
"A2[]");
1862 c1.SaveAs(outputFileName.c_str());
2005 bool isUpdated =
false;
2012 double x_hit = node->getSmoothed().get_x();
2013 double y_hit = node->getSmoothed().get_y();
2014 double pos_hit = p_geomSvc->
getUinStereoPlane(node->getHit().detectorID, x_hit, y_hit);
2017 if(pos_hit > node->getHit().pos)
2027 TMatrixD m(1, 1), dm(1, 1);
2028 m[0][0] = node->getHit().pos + sign*node->getHit().driftDistance;
2030 node->setMeasurement(m, dm);
2031 *hitID = sign*node->getHit().index;
2044 std::cout <<
"KalmanFastTracking::printTimers: " << std::endl;
2045 std::cout <<
"================================================================" << std::endl;
2046 std::cout <<
"Tracklet St2 "<<_timers[
"st2"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2047 std::cout <<
"Tracklet St3 "<<_timers[
"st3"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2048 std::cout <<
"Tracklet St23 "<<_timers[
"st23"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2049 std::cout <<
"Tracklet Global "<<_timers[
"global"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2050 std::cout <<
" Global St1 "<<_timers[
"global_st1"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2051 std::cout <<
" Global Link "<<_timers[
"global_link"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2052 std::cout <<
" Global Kalman "<<_timers[
"global_kalman"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2053 std::cout <<
"Tracklet Kalman "<<_timers[
"kalman"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2054 std::cout <<
"================================================================" << std::endl;
2066 for(
int i = 0; i < n; ++i)
2076 double det = sum*sxx - sx*sx;
2077 if(fabs(det) < 1E-20)
2085 a = (sum*sxy - sx*sy)/det;
2086 b = (sy*sxx - sxy*sx)/det;
int setRawEvent(SRawEvent *event_input)
virtual bool get_BoolFlag(const std::string &name) const
Double_t getChisqVertex()
std::vector< Hit > & getAllHits()
int fitTracklet(Tracklet &tracklet)
void getSagittaWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
SRecTrack getSRecTrack()
Output to SRecTrack.
void getXZErrorInSt1(double &err_tx_st1, double &err_x0_st1)
double getExpPosErrorX(double z) const
#define TFEXIT_FAIL_MULTIPLICITY
double Eval(const double *par)
double residual[nChamberPlanes]
double getPlaneCenterX(int detectorID)
virtual double get_DoubleFlag(const std::string &name) const
double getPlaneCenterY(int detectorID)
double getUinStereoPlane(int detectorID, double x, double y)
double getPlaneResolution(int detectorID) const
int isValid() const
isValid returns non zero if object contains vailid data
SRecTrack processOneTracklet(Tracklet &tracklet)
Track fitting stuff.
bool acceptTracklet(Tracklet &tracklet)
SRecTrack getSRecTrack(bool hyptest=true)
void print(std::ostream &os=std::cout) const
void chi2fit(int n, double x[], double y[], double &a, double &b)
Tool, a simple-minded chi square fit.
void setKalmanStatus(Int_t status)
double getMomentum() const
transient DST object for field storage and access
int isValid() const
isValid returns non zero if object contains vailid data
static recoConsts * instance()
void updateTrack(KalmanTrack &_track)
double getExpPositionY(double z) const
std::list< SRawEvent::hit_pair > getPartialHitPairsInSuperDetector(Short_t detectorID)
void print(std::ostream &os=std::cout)
std::list< Int_t > getHitsIndexInDetectors(std::vector< Int_t > &detectorIDs)
KalmanFastTracking(const PHField *field, const TGeoManager *geom, bool flag=true)
void resolveLeftRight(SRawEvent::hit_pair hpair, int &LR1, int &LR2)
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)
void buildTrackletsInStation(int stationID, int listID, double *pos_exp=nullptr, double *window=nullptr)
Tracklet finding stuff.
std::pair< Int_t, Int_t > hit_pair
Type of pair with two adjacent wires.
int isValid() const
isValid returns non zero if object contains vailid data
void removeBadHits(Tracklet &tracklet)
bool muonID_search(Tracklet &tracklet)
bool acceptEvent(SRawEvent *rawEvent)
Output a lot of messages.
std::list< Node > & getNodeList()
int reduceTrackletList(std::list< Tracklet > &tracklets)
void setTracklet(Tracklet &tracklet, bool wildseedcov=true)
bool isInKMAG(double x, double y)
void printAtDetectorBack(int stationID, std::string outputFileName)
#define TFEXIT_FAIL_GLOABL
double getPosRef(double default_val=-9999.)
void setNHitsInPT(Int_t nHitsX, Int_t nHitsY)
int getPlaneType(int detectorID) const
double getPlaneScaleX(int detectorID)
std::list< int > & getHitIndexList()
Get the list of hits associated.
bool muonID_hodoAid(Tracklet &tracklet)
#define TFEXIT_FAIL_ST2_TRACKLET
double getPlaneScaleY(int detectorID)
Int_t getNHitsInDetectors(std::vector< Int_t > &detectorIDs)
void buildBackPartialTracks()
static GeomSvc * instance()
singlton instance
bool fitTrack(KalmanTrack &kmtrk)
#define TFEXIT_FAIL_BACKPARTIAL
#define TFEXIT_FAIL_ST3_TRACKLET
bool muonID_comp(Tracklet &tracklet)
void setTriggerRoad(Int_t roadID)
void setRawEventDebug(SRawEvent *event_input)
bool isInPlane(int detectorID, double x, double y)
See if a point is in a plane.
void getExtrapoWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
bool isValid()
Self check to see if it is null.
double getExpPositionX(double z) const
bool hodoMask(Tracklet &tracklet)
std::list< Int_t > getHitsIndexInDetector(Short_t detectorID)
Gets.
void resolveSingleLeftRight(Tracklet &tracklet)
virtual int get_IntFlag(const std::string &name) const
Tracklet merge(Tracklet &elem)
double getPlanePosition(int detectorID) const
void getXZInfoInSt1(double &tx_st1, double &x0_st1)
int processOneTrack(KalmanTrack &_track)