6 #include <unordered_map> 12 using namespace mkfit;
24 typedef std::list<std::string>
lStr_t;
28 if (++
j ==
args.end() || ((*j)[0] ==
'-')) {
29 std::cerr <<
"Error: option " << *
i <<
" requires an argument.\n";
37 if (++
j ==
args.end() || ((*j)[0] ==
'-')) {
46 "Usage: %s [options]\n" 48 " --input <str> input file\n" 49 " --output <str> output file\n" 50 " --geo <file> binary TrackerInfo geometry (def: CMS-2017.bin)\n" 51 " --verbosity <num> print details (0 quiet, 1 print counts, 2 print all; def: 0)\n" 52 " --maxevt <num> maxevt events to write (-1 for everything in the file def: -1)\n" 53 " --clean-sim-tracks apply sim track cleaning (def: no cleaning)\n" 54 " --write-all-events write all events (def: skip events with 0 simtracks or seeds)\n" 55 " --write-rec-tracks write rec tracks (def: not written)\n" 56 " --apply-ccc apply cluster charge cut to strip hits (def: false)\n" 57 " --all-seeds merge all seeds from the input file (def: false)\n",
62 bool haveInput =
false;
64 bool haveOutput =
false;
68 bool cleanSimTracks =
false;
69 bool writeAllEvents =
false;
70 bool writeRecTracks =
false;
71 bool writeHitIterMasks =
false;
72 bool applyCCC =
false;
73 bool allSeeds =
false;
76 long long maxevt = -1;
78 int cutValueCCC = 1620;
81 for (
int i = 1;
i <
argc; ++
i) {
82 mArgs.push_back(
argv[
i]);
86 while (
i != mArgs.end()) {
89 if (*
i ==
"-h" || *
i ==
"-help" || *
i ==
"--help") {
91 }
else if (*
i ==
"--input") {
95 }
else if (*
i ==
"--output") {
99 }
else if (*
i ==
"--geo") {
102 }
else if (*
i ==
"--verbosity") {
105 }
else if (*
i ==
"--maxevt") {
107 maxevt = std::atoi(
i->c_str());
108 }
else if (*
i ==
"--clean-sim-tracks") {
109 cleanSimTracks =
true;
110 }
else if (*
i ==
"--write-all-events") {
111 writeAllEvents =
true;
112 }
else if (*
i ==
"--write-rec-tracks") {
113 writeRecTracks =
true;
114 }
else if (*
i ==
"--write-hit-iter-masks") {
115 writeHitIterMasks =
true;
116 }
else if (*
i ==
"--apply-ccc") {
119 cutValueCCC = std::atoi(
i->c_str());
121 }
else if (*
i ==
"--all-seeds") {
124 fprintf(
stderr,
"Error: Unknown option/argument '%s'.\n",
i->c_str());
131 if (not haveOutput
or not haveInput) {
132 fprintf(
stderr,
"Error: both input and output are required\n");
142 const unsigned int nTotalLayers = lnc.
nLayers();
146 std::vector<int> nhitstot(nTotalLayers, 0);
154 TTree*
t = (TTree*)
f->Get(
"trackingNtuple/tree");
156 unsigned long long event;
157 t->SetBranchAddress(
"event", &
event);
160 std::vector<float>* sim_eta = 0;
161 std::vector<float>* sim_px = 0;
162 std::vector<float>* sim_py = 0;
163 std::vector<float>* sim_pz = 0;
164 std::vector<int>* sim_parentVtxIdx = 0;
165 std::vector<int>* sim_q = 0;
166 std::vector<int>* sim_event = 0;
167 std::vector<int>* sim_bunchCrossing = 0;
168 std::vector<int>* sim_nValid = 0;
169 t->SetBranchAddress(
"sim_eta", &sim_eta);
170 t->SetBranchAddress(
"sim_px", &sim_px);
171 t->SetBranchAddress(
"sim_py", &sim_py);
172 t->SetBranchAddress(
"sim_pz", &sim_pz);
173 t->SetBranchAddress(
"sim_parentVtxIdx", &sim_parentVtxIdx);
174 t->SetBranchAddress(
"sim_q", &sim_q);
175 t->SetBranchAddress(
"sim_event", &sim_event);
176 t->SetBranchAddress(
"sim_bunchCrossing", &sim_bunchCrossing);
177 t->SetBranchAddress(
"sim_nValid", &sim_nValid);
179 std::vector<vector<int>>* sim_trkIdx = 0;
180 t->SetBranchAddress(
"sim_trkIdx", &sim_trkIdx);
183 std::vector<float>* simvtx_x = 0;
184 std::vector<float>* simvtx_y = 0;
185 std::vector<float>* simvtx_z = 0;
186 t->SetBranchAddress(
"simvtx_x", &simvtx_x);
187 t->SetBranchAddress(
"simvtx_y", &simvtx_y);
188 t->SetBranchAddress(
"simvtx_z", &simvtx_z);
191 std::vector<short>* simhit_process = 0;
192 std::vector<int>* simhit_particle = 0;
193 std::vector<int>* simhit_simTrkIdx = 0;
194 std::vector<float>* simhit_x = 0;
195 std::vector<float>* simhit_y = 0;
196 std::vector<float>* simhit_z = 0;
197 std::vector<float>* simhit_px = 0;
198 std::vector<float>* simhit_py = 0;
199 std::vector<float>* simhit_pz = 0;
200 t->SetBranchAddress(
"simhit_process", &simhit_process);
201 t->SetBranchAddress(
"simhit_particle", &simhit_particle);
202 t->SetBranchAddress(
"simhit_simTrkIdx", &simhit_simTrkIdx);
203 t->SetBranchAddress(
"simhit_x", &simhit_x);
204 t->SetBranchAddress(
"simhit_y", &simhit_y);
205 t->SetBranchAddress(
"simhit_z", &simhit_z);
206 t->SetBranchAddress(
"simhit_px", &simhit_px);
207 t->SetBranchAddress(
"simhit_py", &simhit_py);
208 t->SetBranchAddress(
"simhit_pz", &simhit_pz);
210 std::vector<std::vector<int>>* simhit_hitIdx = 0;
211 t->SetBranchAddress(
"simhit_hitIdx", &simhit_hitIdx);
212 std::vector<std::vector<int>>* simhit_hitType = 0;
213 t->SetBranchAddress(
"simhit_hitType", &simhit_hitType);
216 std::vector<int>* trk_q = 0;
217 std::vector<unsigned int>* trk_nValid = 0;
218 std::vector<int>* trk_seedIdx = 0;
219 std::vector<unsigned long long>* trk_algoMask = 0;
220 std::vector<unsigned int>* trk_algo = 0;
221 std::vector<unsigned int>* trk_originalAlgo = 0;
222 std::vector<float>* trk_nChi2 = 0;
223 std::vector<float>* trk_px = 0;
224 std::vector<float>* trk_py = 0;
225 std::vector<float>* trk_pz = 0;
226 std::vector<float>* trk_pt = 0;
227 std::vector<float>* trk_phi = 0;
228 std::vector<float>* trk_lambda = 0;
229 std::vector<float>* trk_refpoint_x = 0;
230 std::vector<float>* trk_refpoint_y = 0;
231 std::vector<float>* trk_refpoint_z = 0;
232 std::vector<float>* trk_dxyErr = 0;
233 std::vector<float>* trk_dzErr = 0;
234 std::vector<float>* trk_ptErr = 0;
235 std::vector<float>* trk_phiErr = 0;
236 std::vector<float>* trk_lambdaErr = 0;
237 t->SetBranchAddress(
"trk_q", &trk_q);
238 t->SetBranchAddress(
"trk_nValid", &trk_nValid);
239 t->SetBranchAddress(
"trk_seedIdx", &trk_seedIdx);
240 t->SetBranchAddress(
"trk_algoMask", &trk_algoMask);
241 t->SetBranchAddress(
"trk_algo", &trk_algo);
242 t->SetBranchAddress(
"trk_originalAlgo", &trk_originalAlgo);
243 t->SetBranchAddress(
"trk_nChi2", &trk_nChi2);
244 t->SetBranchAddress(
"trk_px", &trk_px);
245 t->SetBranchAddress(
"trk_py", &trk_py);
246 t->SetBranchAddress(
"trk_pz", &trk_pz);
247 t->SetBranchAddress(
"trk_pt", &trk_pt);
248 t->SetBranchAddress(
"trk_phi", &trk_phi);
249 t->SetBranchAddress(
"trk_lambda", &trk_lambda);
250 t->SetBranchAddress(
"trk_refpoint_x", &trk_refpoint_x);
251 t->SetBranchAddress(
"trk_refpoint_y", &trk_refpoint_y);
252 t->SetBranchAddress(
"trk_refpoint_z", &trk_refpoint_z);
253 t->SetBranchAddress(
"trk_dxyErr", &trk_dxyErr);
254 t->SetBranchAddress(
"trk_dzErr", &trk_dzErr);
255 t->SetBranchAddress(
"trk_ptErr", &trk_ptErr);
256 t->SetBranchAddress(
"trk_phiErr", &trk_phiErr);
257 t->SetBranchAddress(
"trk_lambdaErr", &trk_lambdaErr);
259 std::vector<std::vector<int>>* trk_hitIdx = 0;
260 t->SetBranchAddress(
"trk_hitIdx", &trk_hitIdx);
261 std::vector<std::vector<int>>* trk_hitType = 0;
262 t->SetBranchAddress(
"trk_hitType", &trk_hitType);
265 std::vector<float>* see_stateTrajGlbX = 0;
266 std::vector<float>* see_stateTrajGlbY = 0;
267 std::vector<float>* see_stateTrajGlbZ = 0;
268 std::vector<float>* see_stateTrajGlbPx = 0;
269 std::vector<float>* see_stateTrajGlbPy = 0;
270 std::vector<float>* see_stateTrajGlbPz = 0;
271 std::vector<float>* see_eta = 0;
272 std::vector<float>* see_pt = 0;
273 std::vector<float>* see_stateCcov00 = 0;
274 std::vector<float>* see_stateCcov01 = 0;
275 std::vector<float>* see_stateCcov02 = 0;
276 std::vector<float>* see_stateCcov03 = 0;
277 std::vector<float>* see_stateCcov04 = 0;
278 std::vector<float>* see_stateCcov05 = 0;
279 std::vector<float>* see_stateCcov11 = 0;
280 std::vector<float>* see_stateCcov12 = 0;
281 std::vector<float>* see_stateCcov13 = 0;
282 std::vector<float>* see_stateCcov14 = 0;
283 std::vector<float>* see_stateCcov15 = 0;
284 std::vector<float>* see_stateCcov22 = 0;
285 std::vector<float>* see_stateCcov23 = 0;
286 std::vector<float>* see_stateCcov24 = 0;
287 std::vector<float>* see_stateCcov25 = 0;
288 std::vector<float>* see_stateCcov33 = 0;
289 std::vector<float>* see_stateCcov34 = 0;
290 std::vector<float>* see_stateCcov35 = 0;
291 std::vector<float>* see_stateCcov44 = 0;
292 std::vector<float>* see_stateCcov45 = 0;
293 std::vector<float>* see_stateCcov55 = 0;
294 std::vector<std::vector<float>>* see_stateCurvCov = 0;
295 std::vector<int>* see_q = 0;
296 std::vector<unsigned int>* see_algo = 0;
297 t->SetBranchAddress(
"see_stateTrajGlbX", &see_stateTrajGlbX);
298 t->SetBranchAddress(
"see_stateTrajGlbY", &see_stateTrajGlbY);
299 t->SetBranchAddress(
"see_stateTrajGlbZ", &see_stateTrajGlbZ);
300 t->SetBranchAddress(
"see_stateTrajGlbPx", &see_stateTrajGlbPx);
301 t->SetBranchAddress(
"see_stateTrajGlbPy", &see_stateTrajGlbPy);
302 t->SetBranchAddress(
"see_stateTrajGlbPz", &see_stateTrajGlbPz);
303 t->SetBranchAddress(
"see_eta", &see_eta);
304 t->SetBranchAddress(
"see_pt", &see_pt);
306 bool hasCartCov =
t->GetBranch(
"see_stateCcov00") !=
nullptr;
308 t->SetBranchAddress(
"see_stateCcov00", &see_stateCcov00);
309 t->SetBranchAddress(
"see_stateCcov01", &see_stateCcov01);
310 t->SetBranchAddress(
"see_stateCcov02", &see_stateCcov02);
311 t->SetBranchAddress(
"see_stateCcov03", &see_stateCcov03);
312 t->SetBranchAddress(
"see_stateCcov04", &see_stateCcov04);
313 t->SetBranchAddress(
"see_stateCcov05", &see_stateCcov05);
314 t->SetBranchAddress(
"see_stateCcov11", &see_stateCcov11);
315 t->SetBranchAddress(
"see_stateCcov12", &see_stateCcov12);
316 t->SetBranchAddress(
"see_stateCcov13", &see_stateCcov13);
317 t->SetBranchAddress(
"see_stateCcov14", &see_stateCcov14);
318 t->SetBranchAddress(
"see_stateCcov15", &see_stateCcov15);
319 t->SetBranchAddress(
"see_stateCcov22", &see_stateCcov22);
320 t->SetBranchAddress(
"see_stateCcov23", &see_stateCcov23);
321 t->SetBranchAddress(
"see_stateCcov24", &see_stateCcov24);
322 t->SetBranchAddress(
"see_stateCcov25", &see_stateCcov25);
323 t->SetBranchAddress(
"see_stateCcov33", &see_stateCcov33);
324 t->SetBranchAddress(
"see_stateCcov34", &see_stateCcov34);
325 t->SetBranchAddress(
"see_stateCcov35", &see_stateCcov35);
326 t->SetBranchAddress(
"see_stateCcov44", &see_stateCcov44);
327 t->SetBranchAddress(
"see_stateCcov45", &see_stateCcov45);
328 t->SetBranchAddress(
"see_stateCcov55", &see_stateCcov55);
330 t->SetBranchAddress(
"see_stateCurvCov", &see_stateCurvCov);
332 t->SetBranchAddress(
"see_q", &see_q);
333 t->SetBranchAddress(
"see_algo", &see_algo);
335 std::vector<std::vector<int>>* see_hitIdx = 0;
336 t->SetBranchAddress(
"see_hitIdx", &see_hitIdx);
337 std::vector<std::vector<int>>* see_hitType = 0;
338 t->SetBranchAddress(
"see_hitType", &see_hitType);
341 vector<unsigned short>* pix_det = 0;
342 vector<unsigned short>* pix_lay = 0;
343 vector<unsigned int>* pix_detId = 0;
344 vector<float>* pix_x = 0;
345 vector<float>* pix_y = 0;
346 vector<float>* pix_z = 0;
347 vector<float>* pix_xx = 0;
348 vector<float>* pix_xy = 0;
349 vector<float>* pix_yy = 0;
350 vector<float>* pix_yz = 0;
351 vector<float>* pix_zz = 0;
352 vector<float>* pix_zx = 0;
353 vector<int>* pix_csize_col = 0;
354 vector<int>* pix_csize_row = 0;
355 vector<uint64_t>* pix_usedMask = 0;
357 bool has910_det_lay =
t->GetBranch(
"pix_det") ==
nullptr;
358 if (has910_det_lay) {
359 t->SetBranchAddress(
"pix_subdet", &pix_det);
360 t->SetBranchAddress(
"pix_layer", &pix_lay);
362 t->SetBranchAddress(
"pix_det", &pix_det);
363 t->SetBranchAddress(
"pix_lay", &pix_lay);
365 t->SetBranchAddress(
"pix_detId", &pix_detId);
366 t->SetBranchAddress(
"pix_x", &pix_x);
367 t->SetBranchAddress(
"pix_y", &pix_y);
368 t->SetBranchAddress(
"pix_z", &pix_z);
369 t->SetBranchAddress(
"pix_xx", &pix_xx);
370 t->SetBranchAddress(
"pix_xy", &pix_xy);
371 t->SetBranchAddress(
"pix_yy", &pix_yy);
372 t->SetBranchAddress(
"pix_yz", &pix_yz);
373 t->SetBranchAddress(
"pix_zz", &pix_zz);
374 t->SetBranchAddress(
"pix_zx", &pix_zx);
375 t->SetBranchAddress(
"pix_clustSizeCol", &pix_csize_col);
376 t->SetBranchAddress(
"pix_clustSizeRow", &pix_csize_row);
377 if (writeHitIterMasks) {
378 t->SetBranchAddress(
"pix_usedMask", &pix_usedMask);
381 vector<vector<int>>* pix_simHitIdx = 0;
382 t->SetBranchAddress(
"pix_simHitIdx", &pix_simHitIdx);
383 vector<vector<float>>* pix_chargeFraction = 0;
384 t->SetBranchAddress(
"pix_chargeFraction", &pix_chargeFraction);
387 vector<short>* glu_isBarrel = 0;
388 vector<unsigned int>* glu_det = 0;
389 vector<unsigned int>* glu_lay = 0;
390 vector<unsigned int>* glu_detId = 0;
391 vector<int>* glu_monoIdx = 0;
392 vector<int>* glu_stereoIdx = 0;
393 vector<float>* glu_x = 0;
394 vector<float>* glu_y = 0;
395 vector<float>* glu_z = 0;
396 vector<float>* glu_xx = 0;
397 vector<float>* glu_xy = 0;
398 vector<float>* glu_yy = 0;
399 vector<float>* glu_yz = 0;
400 vector<float>* glu_zz = 0;
401 vector<float>* glu_zx = 0;
402 t->SetBranchAddress(
"glu_isBarrel", &glu_isBarrel);
403 if (has910_det_lay) {
404 t->SetBranchAddress(
"glu_subdet", &glu_det);
405 t->SetBranchAddress(
"glu_layer", &glu_lay);
407 t->SetBranchAddress(
"glu_det", &glu_det);
408 t->SetBranchAddress(
"glu_lay", &glu_lay);
410 t->SetBranchAddress(
"glu_detId", &glu_detId);
411 t->SetBranchAddress(
"glu_monoIdx", &glu_monoIdx);
412 t->SetBranchAddress(
"glu_stereoIdx", &glu_stereoIdx);
413 t->SetBranchAddress(
"glu_x", &glu_x);
414 t->SetBranchAddress(
"glu_y", &glu_y);
415 t->SetBranchAddress(
"glu_z", &glu_z);
416 t->SetBranchAddress(
"glu_xx", &glu_xx);
417 t->SetBranchAddress(
"glu_xy", &glu_xy);
418 t->SetBranchAddress(
"glu_yy", &glu_yy);
419 t->SetBranchAddress(
"glu_yz", &glu_yz);
420 t->SetBranchAddress(
"glu_zz", &glu_zz);
421 t->SetBranchAddress(
"glu_zx", &glu_zx);
423 vector<short>* str_isBarrel = 0;
424 vector<short>* str_isStereo = 0;
425 vector<unsigned int>* str_det = 0;
426 vector<unsigned int>* str_lay = 0;
427 vector<unsigned int>* str_detId = 0;
428 vector<unsigned int>* str_simType = 0;
429 vector<float>* str_x = 0;
430 vector<float>* str_y = 0;
431 vector<float>* str_z = 0;
432 vector<float>* str_xx = 0;
433 vector<float>* str_xy = 0;
434 vector<float>* str_yy = 0;
435 vector<float>* str_yz = 0;
436 vector<float>* str_zz = 0;
437 vector<float>* str_zx = 0;
438 vector<float>* str_chargePerCM = 0;
439 vector<int>* str_csize = 0;
440 vector<uint64_t>* str_usedMask = 0;
441 t->SetBranchAddress(
"str_isBarrel", &str_isBarrel);
442 t->SetBranchAddress(
"str_isStereo", &str_isStereo);
443 if (has910_det_lay) {
444 t->SetBranchAddress(
"str_subdet", &str_det);
445 t->SetBranchAddress(
"str_layer", &str_lay);
447 t->SetBranchAddress(
"str_det", &str_det);
448 t->SetBranchAddress(
"str_lay", &str_lay);
450 t->SetBranchAddress(
"str_detId", &str_detId);
451 t->SetBranchAddress(
"str_simType", &str_simType);
452 t->SetBranchAddress(
"str_x", &str_x);
453 t->SetBranchAddress(
"str_y", &str_y);
454 t->SetBranchAddress(
"str_z", &str_z);
455 t->SetBranchAddress(
"str_xx", &str_xx);
456 t->SetBranchAddress(
"str_xy", &str_xy);
457 t->SetBranchAddress(
"str_yy", &str_yy);
458 t->SetBranchAddress(
"str_yz", &str_yz);
459 t->SetBranchAddress(
"str_zz", &str_zz);
460 t->SetBranchAddress(
"str_zx", &str_zx);
461 t->SetBranchAddress(
"str_chargePerCM", &str_chargePerCM);
462 t->SetBranchAddress(
"str_clustSize", &str_csize);
463 if (writeHitIterMasks) {
464 t->SetBranchAddress(
"str_usedMask", &str_usedMask);
467 vector<vector<int>>* str_simHitIdx = 0;
468 t->SetBranchAddress(
"str_simHitIdx", &str_simHitIdx);
469 vector<vector<float>>* str_chargeFraction = 0;
470 t->SetBranchAddress(
"str_chargeFraction", &str_chargeFraction);
479 t->SetBranchAddress(
"bsp_x", &bsp_x);
480 t->SetBranchAddress(
"bsp_y", &bsp_y);
481 t->SetBranchAddress(
"bsp_z", &bsp_z);
482 t->SetBranchAddress(
"bsp_sigmax", &bsp_sigmax);
483 t->SetBranchAddress(
"bsp_sigmay", &bsp_sigmay);
484 t->SetBranchAddress(
"bsp_sigmaz", &bsp_sigmaz);
486 long long totentries =
t->GetEntries();
487 long long savedEvents = 0;
493 if (writeHitIterMasks)
501 Event EE(0, static_cast<int>(nTotalLayers));
507 for (
long long i = 0; savedEvents < maxevt &&
i < totentries &&
i < maxevt; ++
i) {
510 cout <<
"process entry i=" <<
i <<
" out of " << totentries <<
", saved so far " << savedEvents
511 <<
", with max=" << maxevt << endl;
515 cout <<
"edm event=" <<
event << endl;
517 auto&
bs =
EE.beamSpot_;
521 bs.sigmaZ = bsp_sigmaz;
522 bs.beamWidthX = bsp_sigmax;
523 bs.beamWidthY = bsp_sigmay;
526 for (
unsigned int istr = 0; istr < str_lay->size(); ++istr) {
527 if (str_chargePerCM->at(istr) < cutValueCCC)
532 auto nSims = sim_q->size();
534 cout <<
"branches not loaded" << endl;
538 std::cout << __FILE__ <<
" " << __LINE__ <<
" nSims " << nSims <<
" nSeeds " << see_q->size() <<
" nRecT " 539 << trk_q->size() << std::endl;
542 auto bestTkIdx = [&](std::vector<int>
const& shs, std::vector<float>
const& shfs,
int rhIdx,
HitType rhType) {
552 int nshs = shs.size();
553 for (
auto const sh : shs) {
555 auto tkidx = simhit_simTrkIdx->at(sh);
560 auto hpx = simhit_px->at(sh);
561 auto hpy = simhit_py->at(sh);
562 auto hpz = simhit_pz->at(sh);
563 auto hp =
sqrt(hpx * hpx + hpy * hpy + hpz * hpz);
569 auto tpx = sim_px->at(tkidx);
570 auto tpy = sim_py->at(tkidx);
571 auto tpz = sim_pz->at(tkidx);
572 auto tp =
sqrt(tpx * tpx + tpy * tpy + tpz * tpz);
579 if (maxfrac <
hp /
tp) {
591 if (nshs == 1 && ibest >= 0) {
592 auto const& srhIdxV = simhit_hitIdx->at(shbest);
593 auto const& srhTypeV = simhit_hitType->at(shbest);
595 for (
auto itype : srhTypeV) {
597 if (
HitType(itype) == rhType && srhIdxV[ih] != rhIdx) {
604 if (ibest >= 0 &&
false) {
605 std::cout <<
" best tkIdx " << ibest <<
" rh " << rhIdx <<
" for sh " << shbest <<
" out of " << shs.size()
606 <<
" hp " << hpbest <<
" chF " << hfbest <<
" tp " << tpbest <<
" process " 607 << simhit_process->at(shbest) <<
" particle " << simhit_particle->at(shbest) << std::endl;
609 std::cout <<
" sh " << simhit_x->at(shbest) <<
", " << simhit_y->at(shbest) <<
", " << simhit_z->at(shbest)
610 <<
" rh " << str_x->at(rhIdx) <<
", " << str_y->at(rhIdx) <<
", " << str_z->at(rhIdx) << std::endl;
616 vector<Track>& simTracks_ =
EE.simTracks_;
617 vector<int> simTrackIdx_(sim_q->size(), -1);
618 vector<int> seedSimIdx(see_q->size(), -1);
619 for (
unsigned int isim = 0; isim < sim_q->size(); ++isim) {
621 auto iVtx = sim_parentVtxIdx->at(isim);
622 constexpr
float largeValF = 9999.f;
623 float sim_prodx = iVtx >= 0 ? simvtx_x->at(iVtx) : largeValF;
624 float sim_prody = iVtx >= 0 ? simvtx_y->at(iVtx) : largeValF;
625 float sim_prodz = iVtx >= 0 ? simvtx_z->at(iVtx) : largeValF;
628 vector<int>
const& trkIdxV = sim_trkIdx->at(isim);
633 const int trkIdx = trkIdxV.empty() ? -1 : trkIdxV[0];
637 std::vector<int> hitlay(nTotalLayers, 0);
638 auto const&
hits = trk_hitIdx->at(trkIdx);
639 auto const& hitTypes = trk_hitType->at(trkIdx);
641 for (
auto ihit = 0
U; ihit <
nHits; ++ihit) {
642 auto ihIdx =
hits[ihit];
643 auto const ihType =
HitType(hitTypes[ihit]);
652 if (cmsswlay >= 0 && cmsswlay < static_cast<int>(nTotalLayers))
661 str_det->at(istr), str_lay->at(istr),
useMatched, str_isStereo->at(istr), str_z->at(istr) > 0);
662 if (cmsswlay >= 0 && cmsswlay < static_cast<int>(nTotalLayers))
673 if (cmsswlay >= 0 && cmsswlay < static_cast<int>(nTotalLayers))
681 throw std::logic_error(
"Track type can not be handled");
684 for (
unsigned int i = 0;
i < nTotalLayers;
i++)
692 SVector3 mom(sim_px->at(isim), sim_py->at(isim), sim_pz->at(isim));
694 err.At(0, 0) = sim_prodx * sim_prodx;
695 err.At(1, 1) = sim_prody * sim_prody;
696 err.At(2, 2) = sim_prodz * sim_prodz;
697 err.At(3, 3) = sim_px->at(isim) * sim_px->at(isim);
698 err.At(4, 4) = sim_py->at(isim) * sim_py->at(isim);
699 err.At(5, 5) = sim_pz->at(isim) * sim_pz->at(isim);
701 state.convertFromCartesianToCCS();
705 if (sim_bunchCrossing->at(isim) == 0) {
706 if (sim_event->at(isim) == 0)
714 int seedIdx = trk_seedIdx->at(trkIdx);
716 seedSimIdx[seedIdx] = simTracks_.size();
718 if (cleanSimTracks) {
722 int nRecToSimHit = 0;
728 int simTkIdxNt = bestTkIdx(pix_simHitIdx->at(ipix), pix_chargeFraction->at(ipix), ipix,
HitType::Pixel);
734 if (glu_isBarrel->at(iglu) == 0)
736 int igluMono = glu_monoIdx->at(iglu);
738 bestTkIdx(str_simHitIdx->at(igluMono), str_chargeFraction->at(igluMono), igluMono,
HitType::Strip);
746 str_det->at(istr), str_lay->at(istr),
useMatched, str_isStereo->at(istr), str_z->at(istr) > 0);
747 if (
useMatched && str_isBarrel->at(istr) == 1 && str_isStereo->at(istr))
751 int simTkIdxNt = bestTkIdx(str_simHitIdx->at(istr), str_chargeFraction->at(istr), istr,
HitType::Strip);
760 simTrackIdx_[isim] = simTracks_.size();
761 simTracks_.push_back(
track);
764 if (simTracks_.empty() and not writeAllEvents)
767 vector<Track>& seedTracks_ =
EE.seedTracks_;
768 vector<vector<int>> pixHitSeedIdx(pix_lay->size());
769 vector<vector<int>> strHitSeedIdx(str_lay->size());
770 vector<vector<int>> gluHitSeedIdx(glu_lay->size());
771 for (
unsigned int is = 0; is < see_q->size(); ++is) {
777 SVector3 pos =
SVector3(see_stateTrajGlbX->at(is), see_stateTrajGlbY->at(is), see_stateTrajGlbZ->at(is));
778 SVector3 mom =
SVector3(see_stateTrajGlbPx->at(is), see_stateTrajGlbPy->at(is), see_stateTrajGlbPz->at(is));
781 err.At(0, 0) = see_stateCcov00->at(is);
782 err.At(0, 1) = see_stateCcov01->at(is);
783 err.At(0, 2) = see_stateCcov02->at(is);
784 err.At(0, 3) = see_stateCcov03->at(is);
785 err.At(0, 4) = see_stateCcov04->at(is);
786 err.At(0, 5) = see_stateCcov05->at(is);
787 err.At(1, 1) = see_stateCcov11->at(is);
788 err.At(1, 2) = see_stateCcov12->at(is);
789 err.At(1, 3) = see_stateCcov13->at(is);
790 err.At(1, 4) = see_stateCcov14->at(is);
791 err.At(1, 5) = see_stateCcov15->at(is);
792 err.At(2, 2) = see_stateCcov22->at(is);
793 err.At(2, 3) = see_stateCcov23->at(is);
794 err.At(2, 4) = see_stateCcov24->at(is);
795 err.At(2, 5) = see_stateCcov25->at(is);
796 err.At(3, 3) = see_stateCcov33->at(is);
797 err.At(3, 4) = see_stateCcov34->at(is);
798 err.At(3, 5) = see_stateCcov35->at(is);
799 err.At(4, 4) = see_stateCcov44->at(is);
800 err.At(4, 5) = see_stateCcov45->at(is);
801 err.At(5, 5) = see_stateCcov55->at(is);
803 auto const& vCov = see_stateCurvCov->at(is);
804 assert(vCov.size() == 15);
805 auto vCovP = vCov.begin();
806 for (
int i = 0;
i < 5; ++
i)
807 for (
int j = 0;
j <=
i; ++
j)
808 err.At(
i,
j) = *(vCovP++);
812 state.convertFromCartesianToCCS();
814 state.convertFromGlbCurvilinearToCCS();
816 track.setAlgorithm(isAlgo);
817 auto const& shTypes = see_hitType->at(is);
818 auto const& shIdxs = see_hitIdx->at(is);
823 for (
unsigned int ip = 0; ip < shTypes.size(); ip++) {
824 unsigned int hidx = shIdxs[ip];
825 switch (
HitType(shTypes[ip])) {
827 pixHitSeedIdx[hidx].push_back(seedTracks_.size());
831 strHitSeedIdx[hidx].push_back(seedTracks_.size());
837 int uidx = glu_monoIdx->at(hidx);
838 strHitSeedIdx[uidx].push_back(seedTracks_.size());
839 uidx = glu_stereoIdx->at(hidx);
840 strHitSeedIdx[uidx].push_back(seedTracks_.size());
842 gluHitSeedIdx[hidx].push_back(seedTracks_.size());
849 throw std::logic_error(
"Track hit type can not be handled");
852 seedTracks_.push_back(
track);
855 if (seedTracks_.empty() and not writeAllEvents)
858 vector<Track>& cmsswTracks_ =
EE.cmsswTracks_;
859 vector<vector<int>> pixHitRecIdx(pix_lay->size());
860 vector<vector<int>> strHitRecIdx(str_lay->size());
861 vector<vector<int>> gluHitRecIdx(glu_lay->size());
862 for (
unsigned int ir = 0; ir < trk_q->size(); ++ir) {
869 <<
": mask " << trk_algoMask->at(ir) <<
" origAlgo " << trk_originalAlgo->at(ir) <<
" algo " 870 << trk_algo->at(ir) << std::endl;
888 float pt = trk_pt->at(ir);
889 float pz = trk_pz->at(ir);
890 float p2 =
pt *
pt + pz * pz;
891 float phi = trk_phi->at(ir);
894 float dxyErr2 = trk_dxyErr->at(ir);
896 float dzErr2 = trk_dzErr->at(ir);
898 float dzErrF2 = trk_dzErr->at(ir) * (
pt * pz /
p2);
900 err.At(0, 0) = dxyErr2 * sP * sP + dzErrF2 * cP * cP;
901 err.At(0, 1) = -dxyErr2 * cP * sP + dzErrF2 * cP * sP;
902 err.At(1, 1) = dxyErr2 * cP * cP + dzErrF2 * sP * sP;
903 err.At(0, 2) = -dzErrF2 * cP *
pt / pz;
904 err.At(1, 2) = -dzErrF2 * sP *
pt / pz;
909 SVector3 pos =
SVector3(trk_refpoint_x->at(ir), trk_refpoint_y->at(ir), trk_refpoint_z->at(ir));
912 Track track(
state, trk_nChi2->at(ir), trk_seedIdx->at(ir), 0,
nullptr);
914 auto const& hTypes = trk_hitType->at(ir);
915 auto const& hIdxs = trk_hitIdx->at(ir);
916 for (
unsigned int ip = 0; ip < hTypes.size(); ip++) {
917 unsigned int hidx = hIdxs[ip];
921 pixHitRecIdx[hidx].push_back(cmsswTracks_.size());
926 strHitRecIdx[hidx].push_back(cmsswTracks_.size());
931 throw std::logic_error(
"Tracks have glued hits, but matchedHit load is not configured");
933 gluHitRecIdx[hidx].push_back(cmsswTracks_.size());
939 throw std::logic_error(
"Track hit type can not be handled");
942 cmsswTracks_.push_back(
track);
945 vector<vector<Hit>>& layerHits_ =
EE.layerHits_;
946 vector<vector<uint64_t>>& layerHitMasks_ =
EE.layerHitMasks_;
947 vector<MCHitInfo>& simHitsInfo_ =
EE.simHitsInfo_;
949 layerHits_.resize(nTotalLayers);
950 layerHitMasks_.resize(nTotalLayers);
951 for (
unsigned int ipix = 0; ipix < pix_lay->size(); ++ipix) {
957 unsigned int imoduleid = tkinfo[ilay].short_id(pix_detId->at(ipix));
959 int simTkIdxNt = bestTkIdx(pix_simHitIdx->at(ipix), pix_chargeFraction->at(ipix), ipix,
HitType::Pixel);
960 int simTkIdx = simTkIdxNt >= 0 ? simTrackIdx_[simTkIdxNt] : -1;
963 SVector3 pos(pix_x->at(ipix), pix_y->at(ipix), pix_z->at(ipix));
965 err.At(0, 0) = pix_xx->at(ipix);
966 err.At(1, 1) = pix_yy->at(ipix);
967 err.At(2, 2) = pix_zz->at(ipix);
968 err.At(0, 1) = pix_xy->at(ipix);
969 err.At(0, 2) = pix_zx->at(ipix);
970 err.At(1, 2) = pix_yz->at(ipix);
972 simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
974 for (
unsigned int is = 0; is < pixHitSeedIdx[ipix].size(); is++) {
976 seedTracks_[pixHitSeedIdx[ipix][is]].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
978 for (
unsigned int ir = 0; ir < pixHitRecIdx[ipix].size(); ir++) {
980 cmsswTracks_[pixHitRecIdx[ipix][ir]].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
983 hit.setupAsPixel(imoduleid, pix_csize_row->at(ipix), pix_csize_col->at(ipix));
984 layerHits_[ilay].push_back(
hit);
985 if (writeHitIterMasks)
986 layerHitMasks_[ilay].push_back(pix_usedMask->at(ipix));
987 MCHitInfo hitInfo(simTkIdx, ilay, layerHits_[ilay].
size() - 1, totHits);
988 simHitsInfo_.push_back(hitInfo);
993 for (
unsigned int iglu = 0; iglu < glu_lay->size(); ++iglu) {
994 if (glu_isBarrel->at(iglu) == 0)
996 int igluMono = glu_monoIdx->at(iglu);
998 bestTkIdx(str_simHitIdx->at(igluMono), str_chargeFraction->at(igluMono), igluMono,
HitType::Strip);
999 int simTkIdx = simTkIdxNt >= 0 ? simTrackIdx_[simTkIdxNt] : -1;
1003 SVector3 pos(glu_x->at(iglu), glu_y->at(iglu), glu_z->at(iglu));
1005 err.At(0, 0) = glu_xx->at(iglu);
1006 err.At(1, 1) = glu_yy->at(iglu);
1007 err.At(2, 2) = glu_zz->at(iglu);
1008 err.At(0, 1) = glu_xy->at(iglu);
1009 err.At(0, 2) = glu_zx->at(iglu);
1010 err.At(1, 2) = glu_yz->at(iglu);
1011 if (simTkIdx >= 0) {
1012 simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
1014 for (
unsigned int ir = 0; ir < gluHitSeedIdx[iglu].size(); ir++) {
1016 seedTracks_[gluHitSeedIdx[iglu][ir]].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
1018 for (
unsigned int ir = 0; ir < gluHitRecIdx[iglu].size(); ir++) {
1020 cmsswTracks_[gluHitRecIdx[iglu][ir]].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
1025 assert(
false &&
"Implement module-ids, cluster adc and spans for matched hits!");
1028 layerHits_[ilay].push_back(
hit);
1029 MCHitInfo hitInfo(simTkIdx, ilay, layerHits_[ilay].
size() - 1, totHits);
1030 simHitsInfo_.push_back(hitInfo);
1036 strIdx.resize(str_lay->size());
1037 for (
unsigned int istr = 0; istr < str_lay->size(); ++istr) {
1040 str_det->at(istr), str_lay->at(istr),
useMatched, str_isStereo->at(istr), str_z->at(istr) > 0);
1041 if (
useMatched && str_isBarrel->at(istr) == 1 && str_isStereo->at(istr))
1046 unsigned int imoduleid = tkinfo[ilay].short_id(str_detId->at(istr));
1048 int simTkIdxNt = bestTkIdx(str_simHitIdx->at(istr), str_chargeFraction->at(istr), istr,
HitType::Strip);
1049 int simTkIdx = simTkIdxNt >= 0 ? simTrackIdx_[simTkIdxNt] : -1;
1051 bool passCCC = applyCCC ? (str_chargePerCM->at(istr) > cutValueCCC) :
true;
1054 SVector3 pos(str_x->at(istr), str_y->at(istr), str_z->at(istr));
1056 err.At(0, 0) = str_xx->at(istr);
1057 err.At(1, 1) = str_yy->at(istr);
1058 err.At(2, 2) = str_zz->at(istr);
1059 err.At(0, 1) = str_xy->at(istr);
1060 err.At(0, 2) = str_zx->at(istr);
1061 err.At(1, 2) = str_yz->at(istr);
1062 if (simTkIdx >= 0) {
1064 simTracks_[simTkIdx].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
1066 simTracks_[simTkIdx].addHitIdx(-9, ilay, 0);
1068 for (
unsigned int ir = 0; ir < strHitSeedIdx[istr].size(); ir++) {
1071 seedTracks_[strHitSeedIdx[istr][ir]].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
1073 seedTracks_[strHitSeedIdx[istr][ir]].addHitIdx(-9, ilay, 0);
1075 for (
unsigned int ir = 0; ir < strHitRecIdx[istr].size(); ir++) {
1078 cmsswTracks_[strHitRecIdx[istr][ir]].addHitIdx(layerHits_[ilay].
size(), ilay, 0);
1080 cmsswTracks_[strHitRecIdx[istr][ir]].addHitIdx(-9, ilay, 0);
1084 hit.setupAsStrip(imoduleid, str_chargePerCM->at(istr), str_csize->at(istr));
1085 layerHits_[ilay].push_back(
hit);
1086 if (writeHitIterMasks)
1087 layerHitMasks_[ilay].push_back(str_usedMask->at(istr));
1088 MCHitInfo hitInfo(simTkIdx, ilay, layerHits_[ilay].
size() - 1, totHits);
1089 simHitsInfo_.push_back(hitInfo);
1095 nstot += seedTracks_.size();
1096 for (
unsigned int il = 0; il < layerHits_.size(); ++il) {
1097 int nh = layerHits_[il].size();
1102 int nt = simTracks_.size();
1104 int nl = layerHits_.size();
1106 int nm = simHitsInfo_.size();
1108 int ns = seedTracks_.size();
1110 int nr = cmsswTracks_.size();
1112 printf(
"number of simTracks %i\n",
nt);
1113 printf(
"number of layerHits %i\n", nl);
1114 printf(
"number of simHitsInfo %i\n", nm);
1115 printf(
"number of seedTracks %i\n", ns);
1116 printf(
"number of recTracks %i\n",
nr);
1120 for (
int il = 0; il < nl; ++il) {
1121 int nh = layerHits_[il].size();
1122 for (
int ih = 0; ih <
nh; ++ih) {
1123 printf(
"lay=%i idx=%i mcid=%i x=(%6.3f, %6.3f, %6.3f) r=%6.3f mask=0x%lx\n",
1126 layerHits_[il][ih].mcHitID(),
1127 layerHits_[il][ih].
x(),
1128 layerHits_[il][ih].y(),
1129 layerHits_[il][ih].z(),
1130 sqrt(
pow(layerHits_[il][ih].
x(), 2) +
pow(layerHits_[il][ih].y(), 2)),
1131 writeHitIterMasks ? layerHitMasks_[il][ih] : 0);
1135 for (
int i = 0;
i <
nt; ++
i) {
1138 "sim track id=%i q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) pT=%7.4f nTotal=%i nFound=%i \n",
1148 simTracks_[
i].nTotalHits(),
1149 simTracks_[
i].nFoundHits());
1150 int nh = simTracks_[
i].nTotalHits();
1151 for (
int ih = 0; ih <
nh; ++ih) {
1152 int hidx = simTracks_[
i].getHitIdx(ih);
1153 int hlay = simTracks_[
i].getHitLyr(ih);
1154 float hx = layerHits_[hlay][hidx].x();
1155 float hy = layerHits_[hlay][hidx].y();
1156 float hz = layerHits_[hlay][hidx].z();
1157 printf(
"track #%4i hit #%2i idx=%4i lay=%2i x=(% 8.3f, % 8.3f, % 8.3f) r=%8.3f\n",
1165 sqrt(hx * hx + hy * hy));
1169 for (
int i = 0;
i < ns; ++
i) {
1170 printf(
"seed id=%i label=%i algo=%i q=%2i pT=%6.3f p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f)\n",
1175 seedTracks_[
i].
pT(),
1176 seedTracks_[
i].
px(),
1177 seedTracks_[
i].
py(),
1178 seedTracks_[
i].pz(),
1181 seedTracks_[
i].z());
1182 int nh = seedTracks_[
i].nTotalHits();
1183 for (
int ih = 0; ih <
nh; ++ih)
1184 printf(
"seed #%i hit #%i idx=%i\n",
i, ih, seedTracks_[
i].getHitIdx(ih));
1187 if (writeRecTracks) {
1188 for (
int i = 0;
i <
nr; ++
i) {
1189 float spt =
sqrt(
pow(cmsswTracks_[
i].
px(), 2) +
pow(cmsswTracks_[
i].
py(), 2));
1191 "rec track id=%i label=%i algo=%i chi2=%6.3f q=%2i p=(%6.3f, %6.3f, %6.3f) x=(%6.3f, %6.3f, %6.3f) " 1192 "pT=%7.4f nTotal=%i nFound=%i \n",
1196 cmsswTracks_[
i].
chi2(),
1198 cmsswTracks_[
i].
px(),
1199 cmsswTracks_[
i].
py(),
1200 cmsswTracks_[
i].pz(),
1201 cmsswTracks_[
i].
x(),
1202 cmsswTracks_[
i].y(),
1203 cmsswTracks_[
i].z(),
1205 cmsswTracks_[
i].nTotalHits(),
1206 cmsswTracks_[
i].nFoundHits());
1207 int nh = cmsswTracks_[
i].nTotalHits();
1208 for (
int ih = 0; ih <
nh; ++ih) {
1209 int hidx = cmsswTracks_[
i].getHitIdx(ih);
1210 int hlay = cmsswTracks_[
i].getHitLyr(ih);
1211 float hx = layerHits_[hlay][hidx].x();
1212 float hy = layerHits_[hlay][hidx].y();
1213 float hz = layerHits_[hlay][hidx].z();
1214 printf(
"track #%4i hit #%2i idx=%4i lay=%2i x=(% 8.3f, % 8.3f, % 8.3f) r=%8.3f\n",
1222 sqrt(hx * hx + hy * hy));
1229 EE.write_out(data_file);
1232 printf(
"end of event %lli\n", savedEvents);
1236 printf(
"\nSaved %lli events\n\n", savedEvents);
1238 printf(
"Average number of seeds per event %f\n",
float(nstot) /
float(savedEvents));
1239 for (
unsigned int il = 0; il < nhitstot.size(); ++il)
1240 printf(
"Average number of hits in layer %3i = %7.2f\n",
1242 float(nhitstot[il]) /
float(savedEvents));
1244 printf(
"Out of %i hits, %i failed the cut", numTotalStr, numFailCCC);
1248 printf(
"\n\n================================================================\n");
1249 printf(
"=== Max module id for %u layers\n", nTotalLayers);
1250 printf(
"================================================================\n");
1251 for (
unsigned int ii = 0;
ii < nTotalLayers; ++
ii) {
1252 printf(
"Layer%2d : %d\n",
ii, tkinfo[
ii].n_modules());
void CloseWrite(int n_written)
void next_arg_or_die(lStr_t &args, lStr_i &i)
std::list< std::string > lStr_t
ROOT::Math::SMatrix< float, 6, 6, ROOT::Math::MatRepSym< float, 6 > > SMatrixSym66
void read_bin_file(const std::string &fname)
bool next_arg_option(lStr_t &args, lStr_i &i)
Sin< T >::type sin(const T &t)
ROOT::Math::SVector< float, 3 > SVector3
constexpr bool useMatched
constexpr int cleanSimTrack_minSimHits
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
int main(int argc, char *argv[])
Cos< T >::type cos(const T &t)
TrackBase::TrackAlgorithm TrackAlgorithm
void printHelp(const char *av0)
unsigned int nLayers() const
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
void openWrite(const std::string &fname, int n_layers, int n_ev, int extra_sections=0)
constexpr int cleanSimTrack_minRecHits
TrackAlgorithm
track algorithm; copy from TrackBase.h to keep in standalone builds
std::list< std::string > lStr_t
ROOT::Math::SMatrix< float, 3, 3, ROOT::Math::MatRepSym< float, 3 > > SMatrixSym33
int convertLayerNumber(int det, int lay, bool useMatched, int isStereo, bool posZ) const
Power< A, B >::type pow(const A &a, const B &b)