16 #include <phfield/PHField.h>
27 #include <TGraphErrors.h>
38 const TGeoManager *geom,
41 const std::string sim_db_name,
42 const std::string pattern_db_name
45 ,_enable_KF(enable_KF)
47 ,_sim_db_name(sim_db_name)
48 ,_pattern_db_name(pattern_db_name)
49 , _pattern_db(nullptr)
54 cout <<
"Initialization of KalmanDSTrk ..." << endl;
55 cout <<
"========================================" << endl;
58 _timers.insert(std::make_pair<std::string, PHTimer*>(
"build_db",
new PHTimer(
"build_db")));
59 _timers.insert(std::make_pair<std::string, PHTimer*>(
"load_db",
new PHTimer(
"load_db")));
61 _timers.insert(std::make_pair<std::string, PHTimer*>(
"event",
new PHTimer(
"event")));
62 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st2",
new PHTimer(
"st2")));
63 _timers.insert(std::make_pair<std::string, PHTimer*>(
"search_db_2",
new PHTimer(
"search_db_2")));
64 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st3",
new PHTimer(
"st3")));
66 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23",
new PHTimer(
"st23")));
67 _timers.insert(std::make_pair<std::string, PHTimer*>(
"search_db_23",
new PHTimer(
"search_db_23")));
68 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_fit1",
new PHTimer(
"st23_fit1")));
69 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_prop",
new PHTimer(
"st23_prop")));
70 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_fit2",
new PHTimer(
"st23_fit2")));
71 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_hodo",
new PHTimer(
"st23_hodo")));
72 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_lr40",
new PHTimer(
"st23_lr40")));
73 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_lr150",
new PHTimer(
"st23_lr150")));
74 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_rm_hits",
new PHTimer(
"st23_rm_hits")));
75 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_acc",
new PHTimer(
"st23_acc")));
76 _timers.insert(std::make_pair<std::string, PHTimer*>(
"st23_reduce",
new PHTimer(
"st23_reduce")));
78 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global",
new PHTimer(
"global")));
79 _timers.insert(std::make_pair<std::string, PHTimer*>(
"search_db_glb",
new PHTimer(
"search_db_glb")));
80 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global_st1",
new PHTimer(
"global_st1")));
81 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global_link",
new PHTimer(
"global_link")));
82 _timers.insert(std::make_pair<std::string, PHTimer*>(
"global_kalman",
new PHTimer(
"global_kalman")));
84 _timers.insert(std::make_pair<std::string, PHTimer*>(
"kalman",
new PHTimer(
"kalman")));
87 p_jobOptsSvc = JobOptsSvc::instance();
93 kmfitter->setControlParameter(50, 0.001);
101 if(_pattern_db_name !=
"") {
102 std::cout <<
"KalmanDSTrk::KalmanDSTrk: load DB from pattern db: "<< _pattern_db_name << std::endl;
103 _timers[
"load_db"]->restart();
105 _timers[
"load_db"]->stop();
106 }
else if(_sim_db_name !=
"") {
107 std::cout <<
"KalmanDSTrk::KalmanDSTrk: load DB from sim db: "<< _sim_db_name << std::endl;
108 _timers[
"build_db"]->restart();
111 _timers[
"build_db"]->stop();
113 std::cout <<
"KalmanDSTrk::KalmanDSTrk: no sim or pattern DB" << std::endl;
117 std::cout <<
"KalmanDSTrk::KalmanDSTrk: DB loaded. St23 size: "<< _pattern_db->St23.size() << std::endl;
118 std::cout <<
"================================================================" << std::endl;
119 std::cout <<
"Build DB "<<_timers[
"build_db"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
120 std::cout <<
"Load DB "<<_timers[
"load_db"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
121 std::cout <<
"================================================================" << std::endl;
123 std::cout <<
"KalmanDSTrk::KalmanDSTrk: DB NOT loaded - _DS_level set to 0 " << std::endl;
129 minimizer[0] = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Simplex");
130 minimizer[1] = ROOT::Math::Factory::CreateMinimizer(
"Minuit2",
"Combined");
131 fcn = ROOT::Math::Functor(&tracklet_curr, &
Tracklet::Eval, p_jobOptsSvc->m_enableKMag ? 5 : 4);
133 for(
int i = 0; i < 2; ++i)
135 minimizer[i]->SetMaxFunctionCalls(1000000);
136 minimizer[i]->SetMaxIterations(100);
137 minimizer[i]->SetTolerance(1E-2);
138 minimizer[i]->SetFunction(fcn);
139 minimizer[i]->SetPrintLevel(0);
143 extern Int_t gErrorIgnoreLevel;
144 gErrorIgnoreLevel = 9999;
149 p_geomSvc->printTable();
150 p_geomSvc->printWirePosition();
151 p_geomSvc->printAlignPar();
157 costheta_plane[i] = p_geomSvc->getCostheta(i);
158 sintheta_plane[i] = p_geomSvc->getSintheta(i);
162 detectorIDs_mask[0] = p_geomSvc->getDetectorIDs(
"H1");
163 detectorIDs_mask[1] = p_geomSvc->getDetectorIDs(
"H2");
164 detectorIDs_mask[2] = p_geomSvc->getDetectorIDs(
"H3");
165 detectorIDs_mask[3] = p_geomSvc->getDetectorIDs(
"H4");
166 detectorIDs_maskX[0] = p_geomSvc->getDetectorIDs(
"H1[TB]");
167 detectorIDs_maskX[1] = p_geomSvc->getDetectorIDs(
"H2[TB]");
168 detectorIDs_maskX[2] = p_geomSvc->getDetectorIDs(
"H3[TB]");
169 detectorIDs_maskX[3] = p_geomSvc->getDetectorIDs(
"H4[TB]");
170 detectorIDs_maskY[0] = p_geomSvc->getDetectorIDs(
"H1[LR]");
171 detectorIDs_maskY[1] = p_geomSvc->getDetectorIDs(
"H2[LR]");
172 detectorIDs_maskY[2] = p_geomSvc->getDetectorIDs(
"H4Y1[LR]");
173 detectorIDs_maskY[3] = p_geomSvc->getDetectorIDs(
"H4Y2[LR]");
174 detectorIDs_muidHodoAid[0] = p_geomSvc->getDetectorIDs(
"H4[TB]");
175 detectorIDs_muidHodoAid[1] = p_geomSvc->getDetectorIDs(
"H4Y");
178 stationIDs_mask[0].push_back(1);
179 stationIDs_mask[1].push_back(1);
180 stationIDs_mask[2].push_back(2);
181 stationIDs_mask[3].push_back(3);
182 stationIDs_mask[4].push_back(3);
185 stationIDs_mask[5].push_back(2);
186 stationIDs_mask[5].push_back(3);
187 stationIDs_mask[5].push_back(4);
190 stationIDs_mask[6].push_back(1);
191 stationIDs_mask[6].push_back(2);
192 stationIDs_mask[6].push_back(3);
193 stationIDs_mask[6].push_back(4);
196 detectorIDs_muid[0][0] = p_geomSvc->getDetectorID(
"P1X1");
197 detectorIDs_muid[0][1] = p_geomSvc->getDetectorID(
"P1X2");
198 detectorIDs_muid[0][2] = p_geomSvc->getDetectorID(
"P2X1");
199 detectorIDs_muid[0][3] = p_geomSvc->getDetectorID(
"P2X2");
200 detectorIDs_muid[1][0] = p_geomSvc->getDetectorID(
"P1Y1");
201 detectorIDs_muid[1][1] = p_geomSvc->getDetectorID(
"P1Y2");
202 detectorIDs_muid[1][2] = p_geomSvc->getDetectorID(
"P2Y1");
203 detectorIDs_muid[1][3] = p_geomSvc->getDetectorID(
"P2Y2");
206 z_ref_muid[0][0] = MUID_Z_REF;
207 z_ref_muid[0][1] = MUID_Z_REF;
208 z_ref_muid[0][2] = 0.5*(p_geomSvc->getPlanePosition(detectorIDs_muid[0][0]) + p_geomSvc->getPlanePosition(detectorIDs_muid[0][1]));
209 z_ref_muid[0][3] = z_ref_muid[0][2];
211 z_ref_muid[1][0] = MUID_Z_REF;
212 z_ref_muid[1][1] = MUID_Z_REF;
213 z_ref_muid[1][2] = 0.5*(p_geomSvc->getPlanePosition(detectorIDs_muid[1][0]) + p_geomSvc->getPlanePosition(detectorIDs_muid[1][1]));
214 z_ref_muid[1][3] = z_ref_muid[1][2];
227 for(
int j = 1; j <= p_geomSvc->getPlaneNElements(i); j++)
229 double x_min, x_max, y_min, y_max;
230 p_geomSvc->get2DBoxSize(i, j, x_min, x_max, y_min, y_max);
232 x_min -= (factor*(x_max - x_min));
233 x_max += (factor*(x_max - x_min));
234 y_min -= (factor*(y_max - y_min));
235 y_max += (factor*(y_max - y_min));
245 cout <<
"========================" << endl;
246 cout <<
"Hodo. masking settings: " << endl;
247 for(
int i = 0; i < 4; i++)
249 cout <<
"For station " << i+1 << endl;
250 for(std::vector<int>::iterator iter = detectorIDs_mask[i].begin(); iter != detectorIDs_mask[i].end(); ++iter) cout <<
"All: " << *iter << endl;
251 for(std::vector<int>::iterator iter = detectorIDs_maskX[i].begin(); iter != detectorIDs_maskX[i].end(); ++iter) cout <<
"X: " << *iter << endl;
252 for(std::vector<int>::iterator iter = detectorIDs_maskY[i].begin(); iter != detectorIDs_maskY[i].end(); ++iter) cout <<
"Y: " << *iter << endl;
257 std::cout <<
"Masking stations for tracklets with stationID = " << i + 1 <<
": " << std::endl;
258 for(std::vector<int>::iterator iter = stationIDs_mask[i].begin(); iter != stationIDs_mask[i].end(); ++iter)
260 std::cout << *iter <<
" ";
262 std::cout << std::endl;
268 superIDs[0].push_back((p_geomSvc->getDetectorIDs(
"D0X")[0] + 1)/2);
269 superIDs[0].push_back((p_geomSvc->getDetectorIDs(
"D0U")[0] + 1)/2);
270 superIDs[0].push_back((p_geomSvc->getDetectorIDs(
"D0V")[0] + 1)/2);
271 superIDs[1].push_back((p_geomSvc->getDetectorIDs(
"D1X")[0] + 1)/2);
272 superIDs[1].push_back((p_geomSvc->getDetectorIDs(
"D1U")[0] + 1)/2);
273 superIDs[1].push_back((p_geomSvc->getDetectorIDs(
"D1V")[0] + 1)/2);
274 superIDs[2].push_back((p_geomSvc->getDetectorIDs(
"D2X")[0] + 1)/2);
275 superIDs[2].push_back((p_geomSvc->getDetectorIDs(
"D2U")[0] + 1)/2);
276 superIDs[2].push_back((p_geomSvc->getDetectorIDs(
"D2V")[0] + 1)/2);
277 superIDs[3].push_back((p_geomSvc->getDetectorIDs(
"D3pX")[0] + 1)/2);
278 superIDs[3].push_back((p_geomSvc->getDetectorIDs(
"D3pU")[0] + 1)/2);
279 superIDs[3].push_back((p_geomSvc->getDetectorIDs(
"D3pV")[0] + 1)/2);
280 superIDs[4].push_back((p_geomSvc->getDetectorIDs(
"D3mX")[0] + 1)/2);
281 superIDs[4].push_back((p_geomSvc->getDetectorIDs(
"D3mU")[0] + 1)/2);
282 superIDs[4].push_back((p_geomSvc->getDetectorIDs(
"D3mV")[0] + 1)/2);
284 superIDs[5].push_back((p_geomSvc->getDetectorIDs(
"P1X")[0] + 1)/2);
285 superIDs[5].push_back((p_geomSvc->getDetectorIDs(
"P2X")[0] + 1)/2);
286 superIDs[6].push_back((p_geomSvc->getDetectorIDs(
"P1Y")[0] + 1)/2);
287 superIDs[6].push_back((p_geomSvc->getDetectorIDs(
"P2Y")[0] + 1)/2);
290 cout <<
"=============" << endl;
291 cout <<
"Chamber IDs: " << endl;
292 TString stereoNames[3] = {
"X",
"U",
"V"};
295 for(
int j = 0; j < 3; j++) cout << i <<
" " << stereoNames[j].Data() <<
": " << superIDs[i][j] << endl;
298 cout <<
"Proptube IDs: " << endl;
301 for(
int j = 0; j < 2; j++) cout << i <<
" " << j <<
": " << superIDs[i][j] << endl;
305 cout <<
"======================" << endl;
306 cout <<
"U plane window sizes: " << endl;
309 double u_factor[] = {5., 5., 5., 15., 15.};
312 int xID = 2*superIDs[i][0] - 1;
313 int uID = 2*superIDs[i][1] - 1;
314 int vID = 2*superIDs[i][2] - 1;
315 double spacing = p_geomSvc->getPlaneSpacing(uID);
316 double x_span = p_geomSvc->getPlaneScaleY(uID);
318 z_plane_x[i] = 0.5*(p_geomSvc->getPlanePosition(xID) + p_geomSvc->getPlanePosition(xID+1));
319 z_plane_u[i] = 0.5*(p_geomSvc->getPlanePosition(uID) + p_geomSvc->getPlanePosition(uID+1));
320 z_plane_v[i] = 0.5*(p_geomSvc->getPlanePosition(vID) + p_geomSvc->getPlanePosition(vID+1));
322 u_costheta[i] = costheta_plane[uID];
323 u_sintheta[i] = sintheta_plane[uID];
326 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];
329 cout <<
"Station " << i <<
": " << xID <<
" " << uID <<
" " << vID <<
" " << u_win[i] << endl;
332 <<
"x_span = " << x_span << endl
333 <<
"sintheta_plane = " << sintheta_plane[uID] << endl
334 <<
"u_sintheta = " << u_sintheta[i] << endl
335 <<
"z_plane_u[i] - z_plane_x[i] = " << z_plane_u[i] - z_plane_x[i] << endl
336 <<
"fabs(0.5*x_span*sintheta_plane[uID]) = " << fabs(0.5*x_span*sintheta_plane[uID]) << endl
337 <<
"TX_MAX*fabs((z_plane_u[i] - z_plane_x[i])*u_costheta[i]) = " << TX_MAX*fabs((z_plane_u[i] - z_plane_x[i])*u_costheta[i]) << endl
338 <<
"TY_MAX*fabs((z_plane_u[i] - z_plane_x[i])*u_sintheta[i]) = " << TY_MAX*fabs((z_plane_u[i] - z_plane_x[i])*u_sintheta[i]) << endl
339 <<
"2.*spacing = " << 2.*spacing << endl
340 <<
"u_factor[i] = " << u_factor[i] << endl;
347 z_plane[i] = p_geomSvc->getPlanePosition(i);
348 slope_max[i] = costheta_plane[i]*TX_MAX + sintheta_plane[i]*TY_MAX;
349 intersection_max[i] = costheta_plane[i]*X0_MAX + sintheta_plane[i]*Y0_MAX;
352 resol_plane[i] = 3.*p_geomSvc->getPlaneSpacing(i)/sqrt(12.);
356 resol_plane[i] = p_jobOptsSvc->m_st0_reject;
360 resol_plane[i] = p_jobOptsSvc->m_st1_reject;
364 resol_plane[i] = p_jobOptsSvc->m_st2_reject;
368 resol_plane[i] = p_jobOptsSvc->m_st3p_reject;
372 resol_plane[i] = p_jobOptsSvc->m_st3m_reject;
375 spacing_plane[i] = p_geomSvc->getPlaneSpacing(i);
379 cout <<
"======================================" << endl;
380 cout <<
"Maximum local slope and intersection: " << endl;
384 double d_slope = (p_geomSvc->getPlaneResolution(2*i - 1) + p_geomSvc->getPlaneResolution(2*i))/(z_plane[2*i] - z_plane[2*i-1]);
385 double d_intersection = d_slope*z_plane[2*i];
387 slope_max[2*i-1] += d_slope;
388 intersection_max[2*i-1] += d_intersection;
389 slope_max[2*i] += d_slope;
390 intersection_max[2*i] += d_intersection;
393 cout <<
"Super plane " << i <<
": " << slope_max[2*i-1] <<
" " << intersection_max[2*i-1] << endl;
398 s_detectorID[0] = p_geomSvc->getDetectorID(
"D2X");
399 s_detectorID[1] = p_geomSvc->getDetectorID(
"D2Up");
400 s_detectorID[2] = p_geomSvc->getDetectorID(
"D2Vp");
404 _fana = TFile::Open(
"ktracker_ana.root",
"recreate");
405 _tana_Event =
new TNtuple(
"Event",
"Event",
406 "NSt2:NSt3:NSt23:NSt1:NGlobal:NKalman:"
407 "TSt2:TSt3:TSt23:TGKalman:TGlobal:TKalman:"
410 _tana_St1 =
new TNtuple(
"St1",
"St1",
"in:DS:out");
411 _tana_St2 =
new TNtuple(
"St2",
"St2",
"in:DS:out");
412 _tana_St3 =
new TNtuple(
"St3",
"St3",
"in:DS:out");
413 _tana_St23 =
new TNtuple(
"St23",
"St23",
"in:DS:out:time");
414 _tana_St123 =
new TNtuple(
"St123",
"St123",
"in:DS:out:time");
422 if(_enable_KF)
delete kmfitter;
428 _tana_Event->Write();
433 _tana_St123->Write();
440 rawEvent = event_input;
448 for(
auto iter=_timers.begin(); iter!=_timers.end();++iter) {
449 iter->second->reset();
452 _timers[
"event"]->restart();
454 _timers[
"event"]->stop();
459 static_cast<float>(trackletsInSt[1].size()),
460 static_cast<float>(trackletsInSt[2].size()),
461 static_cast<float>(trackletsInSt[3].size()),
462 static_cast<float>(trackletsInSt[0].size()),
463 static_cast<float>(trackletsInSt[4].size()),
464 static_cast<float>(stracks.size()),
465 static_cast<float>(_timers[
"st2"]->get_accumulated_time()/1000.),
466 static_cast<float>(_timers[
"st3"]->get_accumulated_time()/1000.),
467 static_cast<float>(_timers[
"st23"]->get_accumulated_time()/1000.),
468 static_cast<float>(_timers[
"global_kalman"]->get_accumulated_time()/1000.),
469 static_cast<float>(_timers[
"global"]->get_accumulated_time()/1000.),
470 static_cast<float>(_timers[
"kalman"]->get_accumulated_time()/1000.),
471 static_cast<float>(_timers[
"event"]->get_accumulated_time()/1000.),
474 _tana_Event->Fill(data);
485 for(
int i = 0; i < 5; i++) trackletsInSt[i].clear();
489 rawEvent = event_input;
493 for(std::vector<Hit>::iterator iter = hitAll.begin(); iter != hitAll.end(); ++iter) iter->print();
497 for(
int i = 0; i < 4; i++)
500 hitIDs_mask[i].clear();
515 for(
int i = 0; i < 2; ++i)
517 for(
int j = 0; j < 4; ++j)
519 hitIDs_muid[i][j].clear();
522 hitIDs_muidHodoAid[i].clear();
526 #ifndef ALIGNMENT_MODE
531 if(propSegs[0].empty() || propSegs[1].empty())
534 LogInfo(
"Failed in prop tube segment building: " << propSegs[0].size() <<
", " << propSegs[1].size());
541 _timers[
"st2"]->restart();
543 _timers[
"st2"]->stop();
546 LogInfo(
"NTracklets in St2: " << trackletsInSt[1].size());
549 if(trackletsInSt[1].empty())
552 LogInfo(
"Failed in tracklet build at station 2");
557 _timers[
"st3"]->restart();
560 _timers[
"st3"]->stop();
563 LogInfo(
"NTracklets in St3: " << trackletsInSt[2].size());
566 if(trackletsInSt[2].empty())
569 LogInfo(
"Failed in tracklet build at station 3");
578 LogInfo(
"NTracklets St2+St3: " << trackletsInSt[3].size());
581 if(trackletsInSt[3].empty())
584 LogInfo(
"Failed in connecting station-2 and 3 tracks");
593 LogInfo(
"NTracklets Global: " << trackletsInSt[4].size());
597 for(
int i = 0; i < 2; ++i)
599 std::cout <<
"=======================================================================================" << std::endl;
600 LogInfo(
"Prop tube segments in " << (i == 0 ?
"X-Z" :
"Y-Z"));
601 for(std::list<PropSegment>::iterator seg = propSegs[i].begin(); seg != propSegs[i].end(); ++seg)
605 std::cout <<
"=======================================================================================" << std::endl;
608 for(
int i = 0; i <= 4; i++)
610 std::cout <<
"=======================================================================================" << std::endl;
611 LogInfo(
"Final tracklets in station: " << i+1 <<
" is " << trackletsInSt[i].size());
612 for(std::list<Tracklet>::iterator tracklet = trackletsInSt[i].begin(); tracklet != trackletsInSt[i].end(); ++tracklet)
616 std::cout <<
"=======================================================================================" << std::endl;
624 _timers[
"kalman"]->restart();
625 for(std::list<Tracklet>::iterator tracklet = trackletsInSt[4].begin(); tracklet != trackletsInSt[4].end(); ++tracklet)
628 stracks.push_back(strack);
630 _timers[
"kalman"]->stop();
633 LogInfo(stracks.size() <<
" final tracks:");
634 for(std::list<SRecTrack>::iterator strack = stracks.begin(); strack != stracks.end(); ++strack)
683 _timers[
"st23"]->restart();
684 #ifndef ALIGNMENT_MODE
686 int nHitsX2, nHitsX3;
687 double z_fit[4], x_fit[4];
692 std::map<std::string, int> counter = {
699 for(std::list<Tracklet>::iterator tracklet3 = trackletsInSt[2].begin(); tracklet3 != trackletsInSt[2].end(); ++tracklet3)
701 #ifndef ALIGNMENT_MODE
704 for(std::list<SignedHit>::iterator ptr_hit = tracklet3->hits.begin(); ptr_hit != tracklet3->hits.end(); ++ptr_hit)
706 if(ptr_hit->hit.index < 0)
continue;
707 if(p_geomSvc->
getPlaneType(ptr_hit->hit.detectorID) == 1)
709 z_fit[nHitsX3] = z_plane[ptr_hit->hit.detectorID];
710 x_fit[nHitsX3] = ptr_hit->hit.pos;
716 for(std::list<Tracklet>::iterator tracklet2 = trackletsInSt[1].begin(); tracklet2 != trackletsInSt[1].end(); ++tracklet2)
718 if(fabs(tracklet2->tx - tracklet3->tx) > 0.15 || fabs(tracklet2->ty - tracklet3->ty) > 0.1)
continue;
724 _timers[
"search_db_23"]->restart();
725 bool matched =
false;
737 if(_pattern_db->
St23.find(key23)!=_pattern_db->
St23.end()) matched =
true;
739 _timers[
"search_db_23"]->stop();
742 LogInfo(
"St23 Pattern NOT Found!");
752 #ifndef ALIGNMENT_MODE
755 for(std::list<SignedHit>::iterator ptr_hit = tracklet2->hits.begin(); ptr_hit != tracklet2->hits.end(); ++ptr_hit)
757 if(ptr_hit->hit.index < 0)
continue;
758 if(p_geomSvc->
getPlaneType(ptr_hit->hit.detectorID) == 1)
760 z_fit[nHitsX2] = z_plane[ptr_hit->hit.detectorID];
761 x_fit[nHitsX2] = ptr_hit->hit.pos;
766 if(verbosity>2) _timers[
"st23_fit1"]->restart();
768 chi2fit(nHitsX2, z_fit, x_fit, a, b);
769 if(verbosity>2) _timers[
"st23_fit1"]->stop();
770 if(fabs(a) > 2.*TX_MAX || fabs(b) > 2.*X0_MAX)
continue;
772 if(verbosity>2) _timers[
"st23_prop"]->restart();
775 for(
int i = 0; i < 4; ++i)
777 double x_exp = a*z_mask[detectorIDs_muid[0][i] -
nChamberPlanes - 1] + b;
778 for(std::list<int>::iterator iter = hitIDs_muid[0][i].begin(); iter != hitIDs_muid[0][i].end(); ++iter)
780 if(fabs(hitAll[*iter].pos - x_exp) < 5.08)
786 if(nPropHits > 0)
break;
788 if(verbosity>2) _timers[
"st23_prop"]->stop();
789 if(nPropHits == 0)
continue;
792 Tracklet tracklet_23 = (*tracklet2) + (*tracklet3);
794 LogInfo(
"Using following two tracklets:");
797 LogInfo(
"Yield this combination:");
800 if(verbosity>2) _timers[
"st23_fit2"]->restart();
802 if(verbosity>2) _timers[
"st23_fit2"]->stop();
804 if(tracklet_23.
chisq > 9000.)
808 LogInfo(
"Impossible combination!");
813 if(verbosity>2) _timers[
"st23_hodo"]->restart();
816 if(verbosity>2) _timers[
"st23_hodo"]->stop();
818 LogInfo(
"Hodomasking failed!");
823 LogInfo(
"Hodomasking Scucess!");
827 if(verbosity>2) _timers[
"st23_lr40"]->restart();
829 if(verbosity>2) _timers[
"st23_lr40"]->stop();
830 if(verbosity>2) _timers[
"st23_lr150"]->restart();
832 if(verbosity>2) _timers[
"st23_lr150"]->stop();
834 if(verbosity>2) _timers[
"st23_rm_hits"]->restart();
837 if(verbosity>2) _timers[
"st23_rm_hits"]->stop();
844 tracklet_best.
print();
846 LogInfo(
"Comparison: " << (tracklet_23 < tracklet_best));
850 if(verbosity>2) _timers[
"st23_acc"]->restart();
854 tracklet_best = tracklet_23;
859 if(verbosity>2) _timers[
"st23_acc"]->stop();
868 if(verbosity>2) _timers[
"st23_reduce"]->restart();
869 if(tracklet_best.
isValid()) trackletsInSt[3].push_back(tracklet_best);
870 if(verbosity>2) _timers[
"st23_reduce"]->stop();
874 trackletsInSt[3].sort();
876 _timers[
"st23"]->stop();
882 << counter[
"in"] <<
" => "
883 << counter[
"DS"] <<
" => "
884 << counter[
"out"] << std::endl;
888 float tana_data[] = {
889 static_cast<float>(counter[
"in"]),
890 static_cast<float>(counter[
"DS"]),
891 static_cast<float>(counter[
"out"]),
892 static_cast<float>(_timers[
"st23"]->get_accumulated_time()/1000.)
894 _tana_St23->Fill(tana_data);
901 _timers[
"global"]->restart();
904 std::map<std::string, int> counter = {
911 double pos_exp[3], window[3];
912 for(std::list<Tracklet>::iterator tracklet23 = trackletsInSt[3].begin(); tracklet23 != trackletsInSt[3].end(); ++tracklet23)
915 for(
int i = 0; i < 2; ++i)
917 trackletsInSt[0].clear();
920 if(p_jobOptsSvc->m_enableKMag)
930 LogInfo(
"Using this back partial: ");
932 for(
int j = 0; j < 3; j++)
LogInfo(
"Extrapo: " << pos_exp[j] <<
" " << window[j]);
935 _timers[
"global_st1"]->restart();
937 _timers[
"global_st1"]->stop();
939 _timers[
"global_link"]->restart();
940 Tracklet tracklet_best_prob, tracklet_best_vtx;
941 for(std::list<Tracklet>::iterator tracklet1 = trackletsInSt[0].begin(); tracklet1 != trackletsInSt[0].end(); ++tracklet1)
944 LogInfo(
"With this station 1 track:");
953 _timers[
"search_db_glb"]->restart();
954 bool matched =
false;
975 if(_pattern_db->
St123.find(key123)!=_pattern_db->
St123.end()) matched =
true;
977 _timers[
"search_db_glb"]->stop();
983 std::cout<<
"St123 Pattern Found!";
985 std::cout<<
"St123 Pattern NOT Found!";
987 std::cout << std::endl;
999 Tracklet tracklet_global = (*tracklet23) * (*tracklet1);
1001 if(!
hodoMask(tracklet_global))
continue;
1016 if(tracklet_global < tracklet_best_prob) tracklet_best_prob = tracklet_global;
1018 #if !defined(ALIGNMENT_MODE) && defined(_ENABLE_KF)
1019 _timers[
"global_kalman"]->restart();
1022 _timers[
"global_kalman"]->stop();
1030 tracklet_global.
print();
1032 LogInfo(
"Current best by prob:");
1033 tracklet_best_prob.
print();
1035 LogInfo(
"Comparison I: " << (tracklet_global < tracklet_best_prob));
1038 #if !defined(ALIGNMENT_MODE) && defined(_ENABLE_KF)
1039 LogInfo(
"Current best by vtx:");
1040 tracklet_best_vtx.
print();
1047 _timers[
"global_link"]->stop();
1050 #if !defined(ALIGNMENT_MODE) && defined(_ENABLE_KF)
1052 if(tracklet_best_prob.
isValid() && 1./tracklet_best_prob.
invP > 18.)
1054 tracklet_best[i] = tracklet_best_prob;
1056 else if(tracklet_best_vtx.
isValid())
1058 tracklet_best[i] = tracklet_best_vtx;
1060 else if(tracklet_best_prob.
isValid())
1062 tracklet_best[i] = tracklet_best_prob;
1065 if(tracklet_best_prob.
isValid())
1067 tracklet_best[i] = tracklet_best_prob;
1074 if(fabs(tracklet_best[0].getMomentum() - tracklet_best[1].getMomentum())/tracklet_best[0].
getMomentum() < MERGE_THRES)
1077 tracklet_merge = tracklet_best[0].
merge(tracklet_best[1]);
1081 LogInfo(
"Merging two track candidates with momentum: " << tracklet_best[0].getMomentum() <<
" " << tracklet_best[1].getMomentum());
1088 if(tracklet_merge.
isValid() && tracklet_merge < tracklet_best[0] && tracklet_merge < tracklet_best[1])
1091 LogInfo(
"Choose merged tracklet");
1096 trackletsInSt[4].push_back(tracklet_merge);
1098 else if(tracklet_best[0].isValid() && tracklet_best[0] < tracklet_best[1])
1101 LogInfo(
"Choose tracklet with station-0");
1106 trackletsInSt[4].push_back(tracklet_best[0]);
1108 else if(tracklet_best[1].isValid())
1111 LogInfo(
"Choose tracklet with station-1");
1116 trackletsInSt[4].push_back(tracklet_best[1]);
1120 trackletsInSt[4].sort();
1122 _timers[
"global"]->stop();
1128 << counter[
"in"] <<
" => "
1129 << counter[
"DS"] <<
" => "
1130 << counter[
"out"] << std::endl;
1134 float tana_data[] = {
1135 static_cast<float>(counter[
"in"]),
1136 static_cast<float>(counter[
"DS"]),
1137 static_cast<float>(counter[
"out"]),
1138 static_cast<float>(_timers[
"global"]->get_accumulated_time()/1000.)
1140 _tana_St123->Fill(tana_data);
1148 LogInfo(
"Left right for this track..");
1153 bool isUpdated =
false;
1156 int possibility[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
1159 int nPairs = tracklet.
hits.size()/2;
1162 std::list<SignedHit>::iterator hit1 = tracklet.
hits.begin();
1163 std::list<SignedHit>::iterator hit2 = tracklet.
hits.begin();
1168 LogInfo(hit1->hit.index <<
" " << hit2->sign <<
" === " << hit2->hit.index <<
" " << hit2->sign);
1169 int detectorID1 = hit1->hit.detectorID;
1170 int detectorID2 = hit2->hit.detectorID;
1171 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);
1172 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);
1175 if(hit1->hit.index > 0 && hit2->hit.index > 0 && hit1->sign*hit2->sign == 0)
1178 double pull_min = 1E6;
1179 for(
int i = 0; i < 4; i++)
1181 double slope_local = (hit1->pos(possibility[i][0]) - hit2->pos(possibility[i][1]))/(z_plane[hit1->hit.detectorID] - z_plane[hit2->hit.detectorID]);
1182 double inter_local = hit1->pos(possibility[i][0]) - slope_local*z_plane[hit1->hit.detectorID];
1184 if(fabs(slope_local) > slope_max[hit1->hit.detectorID] || fabs(inter_local) > intersection_max[hit1->hit.detectorID])
continue;
1186 double tx, ty, x0, y0;
1187 double err_tx, err_ty, err_x0, err_y0;
1188 if(tracklet.
stationID == 6 && hit1->hit.detectorID <= 6)
1197 err_tx = tracklet.
err_tx;
1198 err_x0 = tracklet.
err_x0;
1202 err_ty = tracklet.
err_ty;
1203 err_y0 = tracklet.
err_y0;
1205 double slope_exp = costheta_plane[hit1->hit.detectorID]*tx + sintheta_plane[hit1->hit.detectorID]*ty;
1206 double err_slope = fabs(costheta_plane[hit1->hit.detectorID]*err_tx) + fabs(sintheta_plane[hit2->hit.detectorID]*err_ty);
1207 double inter_exp = costheta_plane[hit1->hit.detectorID]*x0 + sintheta_plane[hit1->hit.detectorID]*y0;
1208 double err_inter = fabs(costheta_plane[hit1->hit.detectorID]*err_x0) + fabs(sintheta_plane[hit2->hit.detectorID]*err_y0);
1210 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);
1218 LogInfo(hit1->hit.detectorID <<
": " << i <<
" " << possibility[i][0] <<
" " << possibility[i][1]);
1219 LogInfo(tx <<
" " << x0 <<
" " << ty <<
" " << y0);
1220 LogInfo(
"Slope: " << slope_local <<
" " << slope_exp <<
" " << err_slope);
1221 LogInfo(
"Intersection: " << inter_local <<
" " << inter_exp <<
" " << err_inter);
1222 LogInfo(
"Current: " << pull <<
" " << index_min <<
" " << pull_min);
1227 if(index_min >= 0 && pull_min < threshold)
1230 hit1->sign = possibility[index_min][0];
1231 hit2->sign = possibility[index_min][1];
1237 if(nResolved >= nPairs)
break;
1256 LogInfo(
"Single left right for this track..");
1261 bool isUpdated =
false;
1262 for(std::list<SignedHit>::iterator hit_sign = tracklet.
hits.begin(); hit_sign != tracklet.
hits.end(); ++hit_sign)
1264 if(hit_sign->hit.index < 0 || hit_sign->sign != 0)
continue;
1266 int detectorID = hit_sign->hit.detectorID;
1267 double pos_exp = tracklet.
getExpPositionX(z_plane[detectorID])*costheta_plane[detectorID] + tracklet.
getExpPositionY(z_plane[detectorID])*sintheta_plane[detectorID];
1268 hit_sign->sign = pos_exp > hit_sign->hit.pos ? 1 : -1;
1279 LogInfo(
"Removing hits for this track..");
1288 bool isUpdated =
true;
1296 double res_remove1 = -1.;
1297 double res_remove2 = -1.;
1298 for(std::list<SignedHit>::iterator hit_sign = tracklet.
hits.begin(); hit_sign != tracklet.
hits.end(); ++hit_sign)
1300 if(hit_sign->hit.index < 0)
continue;
1302 int detectorID = hit_sign->hit.detectorID;
1303 double res_curr = fabs(tracklet.
residual[detectorID-1]);
1304 if(res_remove1 < res_curr)
1306 res_remove1 = res_curr;
1307 res_remove2 = fabs(tracklet.
residual[detectorID-1] - 2.*hit_sign->sign*hit_sign->hit.driftDistance);
1308 hit_remove = &(*hit_sign);
1310 std::list<SignedHit>::iterator iter = hit_sign;
1311 hit_neighbour = detectorID % 2 == 0 ? &(*(--iter)) : &(*(++iter));
1314 if(hit_remove ==
NULL)
continue;
1315 if(hit_remove->
sign == 0 && tracklet.
isValid())
continue;
1318 if(res_remove1 > cut)
1321 LogInfo(
"Dropping this hit: " << res_remove1 <<
" " << res_remove2 <<
" " << signflipflag[hit_remove->
hit.
detectorID-1] <<
" " << cut);
1327 if(res_remove2 < cut && signflipflag[hit_remove->
hit.
detectorID-1] < 2)
1329 hit_remove->
sign = -hit_remove->
sign;
1330 hit_neighbour->
sign = 0;
1333 LogInfo(
"Only changing the sign.");
1341 hit_neighbour->
sign = 0;
1347 else if(planeType == 2)
1360 LogInfo(
"Both hits in a view are missing! Will exit the bad hit removal...");
1382 if(hpair.first < 0 || hpair.second < 0)
1387 int possibility[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
1389 for(
int i = 0; i < 4; i++)
1391 if(nResolved > 1)
break;
1393 int hitID1 = hpair.first;
1394 int hitID2 = hpair.second;
1395 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]);
1396 double intersection_local = hitAll[hitID1].pos + possibility[i][0]*hitAll[hitID1].driftDistance - slope_local*z_plane[hitAll[hitID1].detectorID];
1399 if(fabs(slope_local) < slope_max[hitAll[hitID1].detectorID] && fabs(intersection_local) < intersection_max[hitAll[hitID1].detectorID])
1402 LR1 = possibility[i][0];
1403 LR2 = possibility[i][1];
1419 LogInfo(
"Building tracklets in station " << stationID);
1423 int sID = stationID - 1;
1426 std::list<SRawEvent::hit_pair> pairs_X, pairs_U, pairs_V;
1442 LogInfo(
"Hit pairs in this event: ");
1443 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));
1444 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));
1445 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));
1448 if(pairs_X.empty() || pairs_U.empty() || pairs_V.empty())
1451 LogInfo(
"Not all view has hits in station " << stationID);
1457 std::map<std::string, int> counter = {
1465 for(std::list<SRawEvent::hit_pair>::iterator xiter = pairs_X.begin(); xiter != pairs_X.end(); ++xiter)
1468 double x_pos = xiter->second >= 0 ? 0.5*(hitAll[xiter->first].pos + hitAll[xiter->second].pos) : hitAll[xiter->first].pos;
1469 double u_min = x_pos*u_costheta[sID] - u_win[sID];
1470 double u_max = u_min + 2.*u_win[sID];
1473 LogInfo(
"Trying X hits " << xiter->first <<
" " << xiter->second <<
" " << hitAll[xiter->first].elementID <<
" at " << x_pos);
1474 LogInfo(
"U plane window:" << u_min <<
" " << u_max);
1476 for(std::list<SRawEvent::hit_pair>::iterator uiter = pairs_U.begin(); uiter != pairs_U.end(); ++uiter)
1478 double u_pos = uiter->second >= 0 ? 0.5*(hitAll[uiter->first].pos + hitAll[uiter->second].pos) : hitAll[uiter->first].pos;
1480 LogInfo(
"Trying U hits " << uiter->first <<
" " << uiter->second <<
" " << hitAll[uiter->first].elementID <<
" at " << u_pos);
1482 if(u_pos < u_min || u_pos > u_max)
continue;
1485 double z_x = xiter->second >= 0 ? z_plane_x[sID] : z_plane[hitAll[xiter->first].detectorID];
1486 double z_u = uiter->second >= 0 ? z_plane_u[sID] : z_plane[hitAll[uiter->first].detectorID];
1487 double z_v = z_plane_v[sID];
1488 double v_win1 = spacing_plane[hitAll[uiter->first].detectorID]*2.*u_costheta[sID];
1489 double v_win2 = fabs((z_u + z_v - 2.*z_x)*u_costheta[sID]*TX_MAX);
1490 double v_win3 = fabs((z_v - z_u)*u_sintheta[sID]*TY_MAX);
1491 double v_win = v_win1 + v_win2 + v_win3 + 2.*spacing_plane[hitAll[uiter->first].detectorID];
1492 double v_min = 2*x_pos*u_costheta[sID] - u_pos - v_win;
1493 double v_max = v_min + 2.*v_win;
1496 LogInfo(
"V plane window:" << v_min <<
" " << v_max);
1499 <<
"v_win1 = " << v_win1 << std::endl
1500 <<
"v_win2 = " << v_win2 << std::endl
1501 <<
"v_win3 = " << v_win3 << std::endl
1502 <<
"2.*spacing_plane[hitAll[uiter->first].detectorID] = " << 2.*spacing_plane[hitAll[uiter->first].detectorID] << std::endl;
1504 for(std::list<SRawEvent::hit_pair>::iterator viter = pairs_V.begin(); viter != pairs_V.end(); ++viter)
1511 _timers[
"search_db_2"]->restart();
1518 bool matched =
false;
1520 std::vector< std::pair<unsigned int, unsigned int> > det_elem_pairs;
1522 det_elem_pairs.push_back({hitAll[xiter->first].detectorID, hitAll[xiter->first].elementID});
1523 det_elem_pairs.push_back({hitAll[xiter->second].detectorID, hitAll[xiter->second].elementID});
1524 det_elem_pairs.push_back({hitAll[uiter->first].detectorID, hitAll[uiter->first].elementID});
1525 det_elem_pairs.push_back({hitAll[uiter->second].detectorID, hitAll[uiter->second].elementID});
1526 det_elem_pairs.push_back({hitAll[viter->first].detectorID, hitAll[viter->first].elementID});
1527 det_elem_pairs.push_back({hitAll[viter->second].detectorID, hitAll[viter->second].elementID});
1532 and _pattern_db->
St1.find(key)!=_pattern_db->
St1.end()) matched =
true;
1534 and _pattern_db->
St2.find(key)!=_pattern_db->
St2.end()) matched =
true;
1536 and _pattern_db->
St3.find(key)!=_pattern_db->
St3.end()) matched =
true;
1539 _timers[
"search_db_2"]->stop();
1543 << hitAll[xiter->first].index <<
", "
1544 << hitAll[xiter->second].index <<
", "
1545 << hitAll[uiter->first].index <<
", "
1546 << hitAll[uiter->second].index <<
", "
1547 << hitAll[viter->first].index <<
", "
1548 << hitAll[viter->second].index
1553 std::cout<<
"St" << station <<
" Pattern Found!";
1555 std::cout<<
"St" << station <<
" Pattern NOT Found!";
1557 std::cout << std::endl;
1569 double v_pos = viter->second >= 0 ? 0.5*(hitAll[viter->first].pos + hitAll[viter->second].pos) : hitAll[viter->first].pos;
1571 LogInfo(
"Trying V hits " << viter->first <<
" " << viter->second <<
" " << hitAll[viter->first].elementID <<
" at " << v_pos);
1573 if(v_pos < v_min || v_pos > v_max)
continue;
1582 if(xiter->first >= 0)
1584 tracklet_new.
hits.push_back(
SignedHit(hitAll[xiter->first], LR1));
1587 if(xiter->second >= 0)
1589 tracklet_new.
hits.push_back(
SignedHit(hitAll[xiter->second], LR2));
1594 if(uiter->first >= 0)
1596 tracklet_new.
hits.push_back(
SignedHit(hitAll[uiter->first], LR1));
1599 if(uiter->second >= 0)
1601 tracklet_new.
hits.push_back(
SignedHit(hitAll[uiter->second], LR2));
1606 if(viter->first >= 0)
1608 tracklet_new.
hits.push_back(
SignedHit(hitAll[viter->first], LR1));
1611 if(viter->second >= 0)
1613 tracklet_new.
hits.push_back(
SignedHit(hitAll[viter->second], LR2));
1628 tracklet_new.
print();
1633 trackletsInSt[listID].push_back(tracklet_new);
1652 << counter[
"in"] <<
" => "
1653 << counter[
"DS"] <<
" => "
1654 << counter[
"out"] << std::endl;
1658 float tana_data[] = {
1659 static_cast<float>(counter[
"in"]),
1660 static_cast<float>(counter[
"DS"]),
1661 static_cast<float>(counter[
"out"])
1663 if(stationID==2) _tana_St1->Fill(tana_data);
1664 if(stationID==3) _tana_St2->Fill(tana_data);
1665 if(stationID==4||stationID==5) _tana_St3->Fill(tana_data);
1671 for(std::list<Tracklet>::iterator iter = trackletsInSt[listID].begin(); iter != trackletsInSt[listID].end(); ++iter)
1673 iter->addDummyHits();
1677 if(trackletsInSt[listID].size() > 200)
1679 trackletsInSt[listID].sort();
1680 trackletsInSt[listID].resize(200);
1690 LogInfo(
"Failed in quality check!");
1696 if(!
hodoMask(tracklet))
return false;
1702 #ifndef ALIGNMENT_MODE
1718 for(std::vector<int>::iterator stationID = stationIDs_mask[tracklet.
stationID-1].begin(); stationID != stationIDs_mask[tracklet.
stationID-1].end(); ++stationID)
1720 bool masked =
false;
1721 for(std::list<int>::iterator iter = hitIDs_mask[*stationID-1].begin(); iter != hitIDs_mask[*stationID-1].end(); ++iter)
1723 int detectorID = hitAll[*iter].detectorID;
1724 int elementID = hitAll[*iter].elementID;
1727 int idx2 = elementID - 1;
1729 double factor = tracklet.
stationID == nChamberPlanes/6-2 ? 5. : 3.;
1730 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]);
1731 double z_hodo = z_mask[idx1];
1737 double x_min = x_mask_min[idx1][idx2] - err_x;
1738 double x_max = x_mask_max[idx1][idx2] + err_x;
1739 double y_min = y_mask_min[idx1][idx2] - err_y;
1740 double y_max = y_mask_max[idx1][idx2] + err_y;
1744 hitAll[*iter].print();
1745 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);
1747 if(x_hodo > x_min && x_hodo < x_max && y_hodo > y_min && y_hodo < y_max)
1756 if(!masked)
return false;
1772 double cut_the = MUID_THE_P0*tracklet.
invP;
1773 double cut_emp = MUID_EMP_P0 + MUID_EMP_P1/tracklet.
invP + MUID_EMP_P2/tracklet.
invP/tracklet.
invP;
1774 cut = MUID_REJECT*(cut_the > cut_emp ? cut_the : cut_emp);
1777 double slope[2] = {tracklet.
tx, tracklet.
ty};
1780 for(
int i = 0; i < 2; ++i)
1786 for(
int j = 0; j < 4; ++j)
1789 double pos_ref = j < 2 ? pos_absorb[i] : segs[i]->
getPosRef(pos_absorb[i] + slope[i]*(z_ref_muid[i][j] - MUID_Z_REF));
1790 double pos_exp = slope[i]*(z_mask[index] - z_ref_muid[i][j]) + pos_ref;
1794 double win_tight = cut*(z_mask[index] - z_ref_muid[i][j]);
1795 win_tight = win_tight > 2.54 ? win_tight : 2.54;
1796 double win_loose = win_tight*2;
1797 double dist_min = 1E6;
1798 for(std::list<int>::iterator iter = hitIDs_muid[i][j].begin(); iter != hitIDs_muid[i][j].end(); ++iter)
1800 double pos = hitAll[*iter].pos;
1801 double dist = pos - pos_exp;
1802 if(dist < -win_loose)
continue;
1803 if(dist > win_loose)
break;
1805 double dist_l = fabs(pos - hitAll[*iter].driftDistance - pos_exp);
1806 double dist_r = fabs(pos + hitAll[*iter].driftDistance - pos_exp);
1807 dist = dist_l < dist_r ? dist_l : dist_r;
1811 if(dist < win_tight)
1813 segs[i]->
hits[j].
hit = hitAll[*iter];
1814 segs[i]->
hits[j].
sign = fabs(pos - hitAll[*iter].driftDistance - pos_exp) < fabs(pos + hitAll[*iter].driftDistance - pos_exp) ? -1 : 1;
1826 if(segs[0]->getNHits() + segs[1]->getNHits() >= 5)
1830 else if(segs[1]->getNHits() == 1 || segs[1]->getNPlanes() == 1)
1844 double cut_the = MUID_THE_P0*tracklet.
invP;
1845 double cut_emp = MUID_EMP_P0 + MUID_EMP_P1/tracklet.
invP + MUID_EMP_P2/tracklet.
invP/tracklet.
invP;
1846 cut = MUID_REJECT*(cut_the > cut_emp ? cut_the : cut_emp);
1849 LogInfo(
"Muon ID cut is: " << cut <<
" rad.");
1852 double slope[2] = {tracklet.
tx, tracklet.
ty};
1855 for(
int i = 0; i < 2; ++i)
1858 if(i == 0)
LogInfo(
"Working in X-Z:");
1859 if(i == 1)
LogInfo(
"Working in Y-Z:");
1863 if(segs[i]->getNHits() > 2 && segs[i]->isValid() && fabs(slope[i] - segs[i]->a) < cut && fabs(segs[i]->getExpPosition(MUID_Z_REF) - pos_ref) < MUID_R_CUT)
1866 LogInfo(
"Muon ID are already avaiable!");
1871 for(std::list<PropSegment>::iterator iter = propSegs[i].begin(); iter != propSegs[i].end(); ++iter)
1874 LogInfo(
"Testing this prop segment, with ref pos = " << pos_ref <<
", slope_ref = " << slope[i]);
1877 if(fabs(iter->a - slope[i]) < cut && fabs(iter->getExpPosition(MUID_Z_REF) - pos_ref) < MUID_R_CUT)
1887 if(!segs[i]->isValid())
return false;
1890 if(segs[0]->getNHits() + segs[1]->getNHits() < 5)
return false;
1900 double win_the = MUID_THE_P0*tracklet.
invP;
1901 double win_emp = MUID_EMP_P0 + MUID_EMP_P1/tracklet.
invP + MUID_EMP_P2/tracklet.
invP/tracklet.
invP;
1902 win = MUID_REJECT*(win_the > win_emp ? win_the : win_emp);
1907 for(
int i = 0; i < 2; ++i)
1910 for(std::list<int>::iterator iter = hitIDs_muidHodoAid[i].begin(); iter != hitIDs_muidHodoAid[i].end(); ++iter)
1912 int detectorID = hitAll[*iter].detectorID;
1913 int elementID = hitAll[*iter].elementID;
1916 int idx2 = elementID - 1;
1918 double z_hodo = z_mask[idx1];
1921 double err_x = factor*tracklet.
getExpPosErrorX(z_hodo) + win*(z_hodo - MUID_Z_REF);
1922 double err_y = factor*tracklet.
getExpPosErrorY(z_hodo) + win*(z_hodo - MUID_Z_REF);
1924 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;
1925 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;
1927 double x_min = x_mask_min[idx1][idx2] - err_x;
1928 double x_max = x_mask_max[idx1][idx2] + err_x;
1929 double y_min = y_mask_min[idx1][idx2] - err_y;
1930 double y_max = y_mask_max[idx1][idx2] + err_y;
1932 if(x_hodo > x_min && x_hodo < x_max && y_hodo > y_min && y_hodo < y_max)
1935 if(segs[i]->nHodoHits > 4)
break;
1946 LogInfo(
"Building prop. tube segments");
1949 for(
int i = 0; i < 2; ++i)
1951 propSegs[i].clear();
1958 std::cout <<
"superID: " << superIDs[i+5][0] <<
", " << superIDs[i+5][1] << std::endl;
1959 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_forward.begin(); iter != pairs_forward.end(); ++iter)
1960 LogInfo(
"Forward: " << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1961 for(std::list<SRawEvent::hit_pair>::iterator iter = pairs_backward.begin(); iter != pairs_backward.end(); ++iter)
1962 LogInfo(
"Backward: " << iter->first <<
" " << iter->second <<
" " << hitAll[iter->first].index <<
" " << (iter->second < 0 ? -1 : hitAll[iter->second].index));
1965 for(std::list<SRawEvent::hit_pair>::iterator fiter = pairs_forward.begin(); fiter != pairs_forward.end(); ++fiter)
1968 LogInfo(
"Trying forward pair " << fiter->first <<
" " << fiter->second);
1970 for(std::list<SRawEvent::hit_pair>::iterator biter = pairs_backward.begin(); biter != pairs_backward.end(); ++biter)
1973 LogInfo(
"Trying backward pair " << biter->first <<
" " << biter->second);
1979 if(fiter->first >= 0) seg.
hits[1] =
SignedHit(hitAll[fiter->first], 0);
1980 if(fiter->second >= 0) seg.
hits[0] =
SignedHit(hitAll[fiter->second], 0);
1981 if(biter->first >= 0) seg.
hits[3] =
SignedHit(hitAll[biter->first], 0);
1982 if(biter->second >= 0) seg.
hits[2] =
SignedHit(hitAll[biter->second], 0);
1994 propSegs[i].push_back(seg);
2010 tracklet_curr = tracklet;
2014 #ifdef _ENABLE_MULTI_MINI
2018 minimizer[idx]->SetLimitedVariable(0,
"tx", tracklet.
tx, 0.001, -TX_MAX, TX_MAX);
2019 minimizer[idx]->SetLimitedVariable(1,
"ty", tracklet.
ty, 0.001, -TY_MAX, TY_MAX);
2020 minimizer[idx]->SetLimitedVariable(2,
"x0", tracklet.
x0, 0.1, -X0_MAX, X0_MAX);
2021 minimizer[idx]->SetLimitedVariable(3,
"y0", tracklet.
y0, 0.1, -Y0_MAX, Y0_MAX);
2022 if(p_jobOptsSvc->m_enableKMag)
2024 minimizer[idx]->SetLimitedVariable(4,
"invP", tracklet.
invP, 0.001*tracklet.
invP, INVP_MIN, INVP_MAX);
2026 minimizer[idx]->Minimize();
2028 tracklet.
tx = minimizer[idx]->X()[0];
2029 tracklet.
ty = minimizer[idx]->X()[1];
2030 tracklet.
x0 = minimizer[idx]->X()[2];
2031 tracklet.
y0 = minimizer[idx]->X()[3];
2033 tracklet.
err_tx = minimizer[idx]->Errors()[0];
2034 tracklet.
err_ty = minimizer[idx]->Errors()[1];
2035 tracklet.
err_x0 = minimizer[idx]->Errors()[2];
2036 tracklet.
err_y0 = minimizer[idx]->Errors()[3];
2040 tracklet.
invP = minimizer[idx]->X()[4];
2041 tracklet.
err_invP = minimizer[idx]->Errors()[4];
2044 tracklet.
chisq = minimizer[idx]->MinValue();
2046 int status = minimizer[idx]->Status();
2052 std::list<Tracklet> targetList;
2055 while(!tracklets.empty())
2057 targetList.push_back(tracklets.front());
2058 tracklets.pop_front();
2060 #ifdef _DEBUG_ON_LEVEL_2
2061 LogInfo(
"Current best tracklet in reduce");
2062 targetList.back().print();
2065 for(std::list<Tracklet>::iterator iter = tracklets.begin(); iter != tracklets.end(); )
2067 if(iter->similarity(targetList.back()))
2069 #ifdef _DEBUG_ON_LEVEL_2
2070 LogInfo(
"Removing this tracklet: ");
2073 iter = tracklets.erase(iter);
2083 tracklets.assign(targetList.begin(), targetList.end());
2091 for(
int i = 0; i < 3; i++)
2099 for(
int i = 0; i < 3; i++)
2101 int detectorID = (st1ID-1)*6 + 2*i + 2;
2104 double z_st1 = z_plane[detectorID];
2111 window[idx] = 5.*(fabs(costheta_plane[detectorID]*err_x) + fabs(sintheta_plane[detectorID]*err_y));
2119 for(
int i = 0; i < 3; i++)
2127 double z_st3 = z_plane[tracklet.
hits.back().hit.detectorID];
2132 for(
int i = 0; i < 3; i++)
2134 int detectorID = (st1ID-1)*6 + 2*i + 2;
2137 if(!(idx >= 0 && idx <3))
continue;
2141 double z_st1 = z_plane[detectorID];
2142 double z_st2 = z_plane[s_detectorID[idx]];
2147 double s2_target = pos_st2 - pos_st3*(z_st2 - Z_TARGET)/(z_st3 - Z_TARGET);
2148 double s2_dump = pos_st2 - pos_st3*(z_st2 - Z_DUMP)/(z_st3 - Z_DUMP);
2150 double pos_exp_target = SAGITTA_TARGET_CENTER*s2_target + pos_st3*(z_st1 - Z_TARGET)/(z_st3 - Z_TARGET);
2151 double pos_exp_dump = SAGITTA_DUMP_CENTER*s2_dump + pos_st3*(z_st1 - Z_DUMP)/(z_st3 - Z_DUMP);
2152 double win_target = fabs(s2_target*SAGITTA_TARGET_WIN);
2153 double win_dump = fabs(s2_dump*SAGITTA_DUMP_WIN);
2155 double p_min = std::min(pos_exp_target - win_target, pos_exp_dump - win_dump);
2156 double p_max = std::max(pos_exp_target + win_target, pos_exp_dump + win_dump);
2158 pos_exp[idx] = 0.5*(p_max + p_min);
2159 window[idx] = 0.5*(p_max - p_min);
2167 std::vector<double> x, y, dx, dy;
2168 for(std::list<Tracklet>::iterator iter = trackletsInSt[stationID].begin(); iter != trackletsInSt[stationID].end(); ++iter)
2171 x.push_back(iter->getExpPositionX(z));
2172 y.push_back(iter->getExpPositionY(z));
2173 dx.push_back(iter->getExpPosErrorX(z));
2174 dy.push_back(iter->getExpPosErrorY(z));
2177 TGraphErrors gr(x.size(), &x[0], &y[0], &dx[0], &dy[0]);
2178 gr.SetMarkerStyle(8);
2181 std::vector<double> x_f, y_f, dx_f, dy_f;
2195 TGraphErrors gr_frame(x_f.size(), &x_f[0], &y_f[0], &dx_f[0], &dy_f[0]);
2196 gr_frame.SetLineColor(kRed);
2197 gr_frame.SetLineWidth(2);
2198 gr_frame.SetFillColor(15);
2201 gr_frame.Draw(
"A2[]");
2204 c1.SaveAs(outputFileName.c_str());
2213 for(std::list<SignedHit>::iterator iter = tracklet.
hits.begin(); iter != tracklet.
hits.end(); ++iter)
2215 if(iter->hit.index < 0)
continue;
2217 Node node_add(*iter);
2240 kmtrk.
getNodeList().back().getPredicted() = trkpar_curr;
2246 LogInfo(
"!fitTrack(kmtrk) - try flip charge");
2250 kmtrk.
getNodeList().back().getPredicted() = trkpar_curr;
2254 LogInfo(
"!fitTrack(kmtrk) - failed flip charge also");
2264 LogInfo(
"!kmtrk.isValid() Chi2 = " << kmtrk.
getChisq() <<
" - try flip charge");
2268 kmtrk.
getNodeList().back().getPredicted() = trkpar_curr;
2272 LogInfo(
"!fitTrack(kmtrk) - failed flip charge also");
2282 LogInfo(
"flip charge worked!");
2290 LogInfo(
"kmtrk.printNodes()");
2339 bool isUpdated =
false;
2346 double x_hit = node->getSmoothed().get_x();
2347 double y_hit = node->getSmoothed().get_y();
2348 double pos_hit = p_geomSvc->
getUinStereoPlane(node->getHit().detectorID, x_hit, y_hit);
2351 if(pos_hit > node->getHit().pos)
2361 TMatrixD m(1, 1), dm(1, 1);
2362 m[0][0] = node->getHit().pos + sign*node->getHit().driftDistance;
2364 node->setMeasurement(m, dm);
2365 *hitID = sign*node->getHit().index;
2379 <<
"KalmanDSTrk::printTimers: event: " << _event
2380 <<
": " << _timers[
"event"]->get_accumulated_time()/1000. <<
" sec" << std::endl;
2381 std::cout <<
"================================================================" << std::endl;
2382 std::cout <<
"Tracklet St2 "<<_timers[
"st2"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2383 std::cout <<
" Search DB "<<_timers[
"search_db_2"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2385 std::cout <<
"Tracklet St3 "<<_timers[
"st3"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2387 std::cout <<
"Tracklet St23 "<<_timers[
"st23"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2388 std::cout <<
" Search DB "<<_timers[
"search_db_23"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2389 std::cout <<
" st23_fit1 "<<_timers[
"st23_fit1"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2390 std::cout <<
" st23_prop "<<_timers[
"st23_prop"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2391 std::cout <<
" st23_fit2 "<<_timers[
"st23_fit2"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2392 std::cout <<
" st23_hodo "<<_timers[
"st23_hodo"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2393 std::cout <<
" st23_lr40 "<<_timers[
"st23_lr40"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2394 std::cout <<
" st23_lr150 "<<_timers[
"st23_lr150"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2395 std::cout <<
" st23_rm_hits "<<_timers[
"st23_rm_hits"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2396 std::cout <<
" st23_acc "<<_timers[
"st23_acc"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2397 std::cout <<
" st23_reduce "<<_timers[
"st23_reduce"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2398 std::cout <<
" st23_prop "<<_timers[
"st23_prop"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2400 std::cout <<
"Tracklet Global "<<_timers[
"global"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2401 std::cout <<
" Global St1 "<<_timers[
"global_st1"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2402 std::cout <<
" Search DB "<<_timers[
"search_db_glb"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2403 std::cout <<
" Global Link "<<_timers[
"global_link"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2404 std::cout <<
" Link Kalman "<<_timers[
"global_kalman"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2405 std::cout <<
"Tracklet Kalman "<<_timers[
"kalman"]->get_accumulated_time()/1000. <<
" sec" <<std::endl;
2406 std::cout <<
"================================================================" << std::endl;
2418 for(
int i = 0; i < n; ++i)
2428 double det = sum*sxx - sx*sx;
2429 if(fabs(det) < 1E-20)
2437 a = (sum*sxy - sx*sy)/det;
2438 b = (sy*sxx - sxy*sx)/det;
void removeBadHits(Tracklet &tracklet)
void setCurrTrkpar(TrkPar &_trkpar)
set the current track parameter
PatternDB interface objects.
Double_t getChisqVertex()
void getExtrapoWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
std::vector< Hit > & getAllHits()
SRecTrack getSRecTrack()
Output to SRecTrack.
int setRawEvent(SRawEvent *event_input)
void getXZErrorInSt1(double &err_tx_st1, double &err_x0_st1)
bool muonID_search(Tracklet &tracklet)
double getExpPosErrorX(double z) const
void print()
Debugging print.
#define TFEXIT_FAIL_MULTIPLICITY
double Eval(const double *par)
double residual[nChamberPlanes]
double getPlaneCenterX(int detectorID)
std::set< PartTrackKey > St23
double getPlaneCenterY(int detectorID)
double getUinStereoPlane(int detectorID, double x, double y)
void setRawEventDebug(SRawEvent *event_input)
static int BuildPatternDB(const std::string &fin, const std::string &fout, PatternDB &db)
double getPlaneResolution(int detectorID) const
int isValid() const
isValid returns non zero if object contains vailid data
static TrackletKey GetTrackletKey(const Tracklet tracklet, const PatternDB::STATION station)
SRecTrack getSRecTrack(bool hyptest=true)
void print(std::ostream &os=std::cout) const
int reduceTrackletList(std::list< Tracklet > &tracklets)
void setKalmanStatus(Int_t status)
double getMomentum() const
transient DST object for field storage and access
bool muonID_hodoAid(Tracklet &tracklet)
int isValid() const
isValid returns non zero if object contains vailid data
void updateTrack(KalmanTrack &_track)
double getExpPositionY(double z) const
bool muonID_comp(Tracklet &tracklet)
std::list< SRawEvent::hit_pair > getPartialHitPairsInSuperDetector(Short_t detectorID)
void print(std::ostream &os=std::cout)
void getSagittaWindowsInSt1(Tracklet &tracklet, double *pos_exp, double *window, int st1ID)
std::list< Int_t > getHitsIndexInDetectors(std::vector< Int_t > &detectorIDs)
static PatternDB * LoadPatternDB(const std::string &fin)
static const TrackletKey ERR_KEY
SRecTrack processOneTracklet(Tracklet &tracklet)
Track fitting stuff.
double getExpPosErrorY(double z) const
void buildBackPartialTracks()
void resolveLeftRight(SRawEvent::hit_pair hpair, int &LR1, int &LR2)
std::list< SignedHit > hits
void print(std::ostream &os=std::cout) const
void setPTSlope(Double_t slopeX, Double_t slopeY)
int setRawEventWorker(SRawEvent *event_input)
int fitTracklet(Tracklet &tracklet)
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
Output a lot of messages.
std::list< Node > & getNodeList()
bool acceptEvent(SRawEvent *rawEvent)
std::set< TrackletKey > St3
bool isInKMAG(double x, double y)
TMatrixD _state_kf
State vectors and its covariance.
#define TFEXIT_FAIL_GLOABL
bool acceptTracklet(Tracklet &tracklet)
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.
#define TFEXIT_FAIL_ST2_TRACKLET
bool fitTrack(KalmanTrack &kmtrk)
void printAtDetectorBack(int stationID, std::string outputFileName)
double getPlaneScaleY(int detectorID)
Int_t getNHitsInDetectors(std::vector< Int_t > &detectorIDs)
void resolveSingleLeftRight(Tracklet &tracklet)
KalmanDSTrk(const PHField *field, const TGeoManager *geom, bool enable_KF=true, int DS_level=KalmanDSTrk::NO_DS, const std::string sim_db_name="", const std::string pattern_db_name="")
void buildTrackletsInStation(int stationID, int listID, double *pos_exp=NULL, double *window=NULL)
Tracklet finding stuff.
static GeomSvc * instance()
singlton instance
std::set< GlobTrackKey > St123
#define TFEXIT_FAIL_BACKPARTIAL
#define TFEXIT_FAIL_ST3_TRACKLET
std::set< TrackletKey > St2
std::set< TrackletKey > St1
void chi2fit(int n, double x[], double y[], double &a, double &b)
void setTriggerRoad(Int_t roadID)
bool hodoMask(Tracklet &tracklet)
bool isInPlane(int detectorID, double x, double y)
See if a point is in a plane.
bool isValid()
Self check to see if it is null.
double getExpPositionX(double z) const
std::list< Int_t > getHitsIndexInDetector(Short_t detectorID)
Gets.
Tracklet merge(Tracklet &elem)
double getPlanePosition(int detectorID) const
void getXZInfoInSt1(double &tx_st1, double &x0_st1)
int processOneTrack(KalmanTrack &_track)