CMS 3D CMS Logo

mkFit.cc
Go to the documentation of this file.
2 
3 // CCCC #include "fittestMPlex.h"
5 
11 
14 
16 
18 
19 #ifndef NO_ROOT
21 #endif
22 
23 //#define DEBUG
26 
27 #include "oneapi/tbb/task_arena.h"
28 #include "oneapi/tbb/parallel_for.h"
29 #include <oneapi/tbb/global_control.h>
30 
31 #if defined(USE_VTUNE_PAUSE)
32 #include "ittnotify.h"
33 #endif
34 
35 #include <cstdlib>
36 #include <limits>
37 #include <list>
38 #include <sstream>
39 #include <memory>
40 
41 using namespace mkfit;
42 
43 //==============================================================================
44 
45 std::vector<DeadVec> deadvectors;
46 
48  deadvectors.resize(Config::TrkInfo.n_layers());
50 }
51 
52 void initGeom() {
53  std::cout << "Constructing geometry '" << Config::geomPlugin << "'\n";
54 
55  // NB: we currently assume that each node is a layer, and that layers
56  // are added starting from the center
57  // NB: z is just a dummy variable, VUSolid is actually infinite in size. *** Therefore, set it to the eta of simulation ***
58 
59  /*
60  // Test CMSSW loading
61  IterationsInfo ii;
62  unsigned int algorithms[]={ 4,22,23,5,24,7,8,9,10,6 }; // 10 iterations
63  ii.resize(10);
64  for (int i = 0; i < 10; ++i) {
65  ii[i].m_track_algorithm = algorithms[i];
66  }
67  auto xx = configJson_Load_File(ii, "mkfit-phase1-initialStep.json");
68  printf("%d\n", xx->m_iteration_index);
69  */
70 
72 
74 
77 
80 
81  for (auto& fn : Config::json_load_filenames) {
82  // This is for testing only ... we drop the loaded IterationConfig
83  // as further code will always use IterationsInfo[ iter_index ].
85  }
86 
87  printf(
88  "mkFit.cc/%s--JSON-Load read %d JSON entities from %d files, replaced %d parameters.\n"
89  " NOTE that these changes were NOT APPLIED to actual configuration that is going to be used.\n",
90  __func__,
91  report.n_json_entities,
92  report.n_files,
93  report.n_replacements);
94  }
95 
98 
100 
101  printf("mkFit.cc/%s--JOSN-Patch read %d JSON entities from %d files, replaced %d parameters.\n",
102  __func__,
103  report.n_json_entities,
104  report.n_files,
105  report.n_replacements);
106  }
107 
109  cj.dump(Config::ItrInfo);
110 
112  cj.save_Iterations(
114  }
115 
117 
118  // We always initialize the dead modules. Actual loading into each event is
119  // controlled via Config::useDeadModules.
121 
122  // Test functions for ConfigJsonPatcher
123  // cj.test_Direct (Config::ItrInfo[0]);
124  // cj.test_Patcher(Config::ItrInfo[0]);
125 }
126 
127 namespace {
128  int g_start_event = 1;
129 
130  bool g_run_fit_std = false;
131 
132  bool g_run_build_all = true;
133  bool g_run_build_cmssw = false;
134  bool g_run_build_bh = false;
135  bool g_run_build_std = false;
136  bool g_run_build_ce = false;
137  bool g_run_build_mimi = false;
138 
139  std::string g_operation = "simulate_and_process";
140  ;
141  std::string g_input_file = "";
142  std::string g_output_file = "";
143 
144  seedOptsMap g_seed_opts;
145  void init_seed_opts() {
146  g_seed_opts["sim"] = {simSeeds, "Use simtracks for seeds"};
147  g_seed_opts["cmssw"] = {cmsswSeeds, "Use external CMSSW seeds"};
148  g_seed_opts["find"] = {findSeeds, "Use mplex seed finder for seeds"};
149  }
150 
151  cleanOptsMap g_clean_opts;
152  void init_clean_opts() {
153  g_clean_opts["none"] = {noCleaning, "No cleaning applied to external CMSSW seeds"};
154  g_clean_opts["n2"] = {cleanSeedsN2, "Apply N^2 cleaning by Mario to external CMSSW seeds"};
155  g_clean_opts["pure"] = {
157  "Only use external CMSSW seeds that have produced a CMSSW track \n must enable: --read-cmssw-tracks"};
158  g_clean_opts["badlabel"] = {cleanSeedsBadLabel, "Remove seeds with label()<0 in external CMSSW seeds"};
159  }
160 
161  matchOptsMap g_match_opts;
162  void init_match_opts() {
163  g_match_opts["trkparam"] = {trkParamBased,
164  "Use track parameter-based matching for validating against CMSSW tracks"};
165  g_match_opts["hits"] = {hitBased, "Use hit-based matching for validating against CMSSW tracks"};
166  g_match_opts["label"] = {labelBased, "Only allowed with pure seeds: stricter hit-based matching"};
167  }
168 
169  const char* b2a(bool b) { return b ? "true" : "false"; }
170 
171 } // namespace
172 
173 //==============================================================================
174 
175 // Getters and setters of enum configs (from command line using anon. namespace above)
176 
177 template <typename T, typename U>
178 std::string getOpt(const T& c_opt, const U& g_opt_map) {
179  static const std::string empty("");
180 
181  for (const auto& g_opt_pair : g_opt_map) {
182  if (g_opt_pair.second.first == c_opt)
183  return g_opt_pair.first;
184  }
185  std::cerr << "No match for option " << c_opt << std::endl;
186  return empty;
187 }
188 
189 template <typename T, typename U>
190 void setOpt(const std::string& cmd_ln_str, T& c_opt, const U& g_opt_map, const std::string& ex_txt) {
191  if (g_opt_map.count(cmd_ln_str))
192  c_opt = g_opt_map.at(cmd_ln_str).first;
193  else {
194  std::cerr << cmd_ln_str << " is not a valid " << ex_txt << " option!! Exiting..." << std::endl;
195  exit(1);
196  }
197 }
198 
199 template <typename U>
200 void listOpts(const U& g_opt_map) {
201  for (const auto& g_opt_pair : g_opt_map) {
202  std::cout << " " << g_opt_pair.first.c_str() << " : " << g_opt_pair.second.second.c_str() << std::endl;
203  }
204 }
205 
206 //==============================================================================
207 
209  printf("Running test_standard(), operation=\"%s\", best_out_of=%d\n",
210  g_operation.c_str(),
212 
214  printf("- reading seeds from file\n");
215 
216  initGeom();
217 
218  if (Config::nEvents <= 0) {
219  return;
220  }
221 
222  DataFile data_file;
223  if (g_operation == "read") {
224  int evs_in_file = data_file.openRead(g_input_file, Config::TrkInfo.n_layers());
225  int evs_available = evs_in_file - g_start_event + 1;
226  if (Config::nEvents == -1) {
227  Config::nEvents = evs_available;
228  } else if (Config::nEvents > evs_available and not Config::loopOverFile) {
229  printf("Requested number of events %d, only %d available.\n", Config::nEvents, evs_available);
230  Config::nEvents = evs_available;
231  }
232 
233  if (g_start_event > 1) {
234  data_file.skipNEvents(g_start_event - 1);
235  }
236  }
237 
238  constexpr int NT = 5;
239  double t_sum[NT] = {0};
240  double t_skip[NT] = {0};
241  std::vector<double> t_sum_iter(Config::nItersCMSSW, 0.0);
242  std::vector<double> t_skip_iter(Config::nItersCMSSW, 0.0);
243  double time = dtime();
244 
245  std::atomic<int> nevt{g_start_event};
246  std::atomic<int> seedstot{0}, simtrackstot{0}, candstot{0};
247  std::atomic<int> maxHits_all{0}, maxLayer_all{0};
248 
250 
251  std::vector<std::unique_ptr<Event>> evs(Config::numThreadsEvents);
252  std::vector<std::unique_ptr<Validation>> vals(Config::numThreadsEvents);
253  std::vector<std::unique_ptr<MkBuilder>> mkbs(Config::numThreadsEvents);
254  std::vector<std::shared_ptr<EventOfHits>> eohs(Config::numThreadsEvents);
255  std::vector<std::shared_ptr<FILE>> fps;
256  fps.reserve(Config::numThreadsEvents);
257 
258  const std::string valfile("valtree");
259 
260  for (int i = 0; i < Config::numThreadsEvents; ++i) {
261  std::ostringstream serial;
262  if (Config::numThreadsEvents > 1) {
263  serial << "_" << i;
264  }
265  vals[i].reset(Validation::make_validation(valfile + serial.str() + ".root", &Config::TrkInfo));
267  eohs[i].reset(new EventOfHits(Config::TrkInfo));
268  evs[i].reset(new Event(*vals[i], 0, Config::TrkInfo.n_layers()));
269  if (g_operation == "read") {
270  fps.emplace_back(fopen(g_input_file.c_str(), "r"), [](FILE* fp) {
271  if (fp)
272  fclose(fp);
273  });
274  }
275  }
276 
277  tbb::task_arena arena(Config::numThreadsFinder);
278 
279  dprint("parallel_for step size " << (Config::nEvents + Config::numThreadsEvents - 1) / Config::numThreadsEvents);
280 
281  time = dtime();
282 
283  int events_per_thread = (Config::nEvents + Config::numThreadsEvents - 1) / Config::numThreadsEvents;
284 
285  arena.execute([&]() {
286  tbb::parallel_for(
287  tbb::blocked_range<int>(0, Config::numThreadsEvents, 1),
288  [&](const tbb::blocked_range<int>& threads) {
289  int thisthread = threads.begin();
290 
291  assert(threads.begin() == threads.end() - 1 && thisthread < Config::numThreadsEvents);
292 
293  // std::vector<Track> plex_tracks;
294  auto& ev = *evs[thisthread].get();
295  auto& mkb = *mkbs[thisthread].get();
296  auto& eoh = *eohs[thisthread].get();
297  auto fp = fps[thisthread].get();
298 
299  int evstart = thisthread * events_per_thread;
300  int evend = std::min(Config::nEvents, evstart + events_per_thread);
301 
302  dprint("thisthread " << thisthread << " events " << Config::nEvents << " events/thread " << events_per_thread
303  << " range " << evstart << ":" << evend);
304 
305  for (int evt = evstart; evt < evend; ++evt) {
306  ev.reset(nevt++);
307 
308  if (!Config::silent) {
309  std::lock_guard<std::mutex> printlock(Event::printmutex);
310  printf("\n");
311  printf("Processing event %d\n", ev.evtID());
312  }
313 
314  ev.read_in(data_file, fp);
315 
316  // skip events with zero seed tracks!
317  if (ev.seedTracks_.empty())
318  continue;
319 
320  // plex_tracks.resize(ev.simTracks_.size());
321 
323 
326  }
327 
328  double t_best[NT] = {0}, t_cur[NT] = {0};
329  std::vector<double> t_cur_iter;
330  simtrackstot += ev.simTracks_.size();
331  seedstot += ev.seedTracks_.size();
332 
333  int ncands_thisthread = 0;
334  int maxHits_thisthread = 0;
335  int maxLayer_thisthread = 0;
336  for (int b = 0; b < Config::finderReportBestOutOfN; ++b) {
337  t_cur[0] = 0; // t_cur[0] = (g_run_fit_std) ? runFittingTestPlex(ev, plex_tracks) : 0;
338  t_cur[1] = (g_run_build_all || g_run_build_bh) ? runBuildingTestPlexBestHit(ev, eoh, mkb) : 0;
339  t_cur[3] = (g_run_build_all || g_run_build_ce) ? runBuildingTestPlexCloneEngine(ev, eoh, mkb) : 0;
340  if (g_run_build_all || g_run_build_mimi)
341  t_cur_iter = runBtpCe_MultiIter(ev, eoh, mkb, Config::nItersCMSSW);
342  t_cur[4] = (g_run_build_all || g_run_build_mimi) ? t_cur_iter[Config::nItersCMSSW] : 0;
343  if (g_run_build_all || g_run_build_cmssw)
344  runBuildingTestPlexDumbCMSSW(ev, eoh, mkb);
345  t_cur[2] = (g_run_build_all || g_run_build_std) ? runBuildingTestPlexStandard(ev, eoh, mkb) : 0;
346  if (g_run_build_ce || g_run_build_mimi) {
347  ncands_thisthread = mkb.total_cands();
348  auto const& ln = mkb.max_hits_layer(eoh);
349  maxHits_thisthread = ln.first;
350  maxLayer_thisthread = ln.second;
351  }
352  for (int i = 0; i < NT; ++i)
353  t_best[i] = (b == 0) ? t_cur[i] : std::min(t_cur[i], t_best[i]);
354 
355  if (!Config::silent) {
356  std::lock_guard<std::mutex> printlock(Event::printmutex);
358  printf("----------------------------------------------------------------\n");
359  printf("Best-of-times:");
360  for (int i = 0; i < NT; ++i)
361  printf(" %.5f/%.5f", t_cur[i], t_best[i]);
362  printf("\n");
363  }
364  printf("----------------------------------------------------------------\n");
365  }
366  }
367 
368  candstot += ncands_thisthread;
369  if (maxHits_thisthread > maxHits_all) {
370  maxHits_all = maxHits_thisthread;
371  maxLayer_all = maxLayer_thisthread;
372  }
373  if (!Config::silent) {
374  std::lock_guard<std::mutex> printlock(Event::printmutex);
375  printf("Matriplex fit = %.5f --- Build BHMX = %.5f STDMX = %.5f CEMX = %.5f MIMI = %.5f\n",
376  t_best[0],
377  t_best[1],
378  t_best[2],
379  t_best[3],
380  t_best[4]);
381  }
382 
383  {
384  static std::mutex sum_up_lock;
385  std::lock_guard<std::mutex> locker(sum_up_lock);
386 
387  for (int i = 0; i < NT; ++i)
388  t_sum[i] += t_best[i];
389  if (evt > 0)
390  for (int i = 0; i < NT; ++i)
391  t_skip[i] += t_best[i];
392  if (g_run_build_all || g_run_build_mimi) {
393  for (int i = 0; i < Config::nItersCMSSW; ++i)
394  t_sum_iter[i] += t_cur_iter[i];
395  if (evt > 0)
396  for (int i = 0; i < Config::nItersCMSSW; ++i)
397  t_skip_iter[i] += t_cur_iter[i];
398  }
399  }
400  }
401  },
402  tbb::simple_partitioner());
403  });
404 
405  time = dtime() - time;
406 
407  printf("\n");
408  printf("================================================================\n");
409  printf("=== TOTAL for %d events\n", Config::nEvents);
410  printf("================================================================\n");
411 
412  printf("Total Matriplex fit = %.5f --- Build BHMX = %.5f STDMX = %.5f CEMX = %.5f MIMI = %.5f\n",
413  t_sum[0],
414  t_sum[1],
415  t_sum[2],
416  t_sum[3],
417  t_sum[4]);
418  printf("Total event > 1 fit = %.5f --- Build BHMX = %.5f STDMX = %.5f CEMX = %.5f MIMI = %.5f\n",
419  t_skip[0],
420  t_skip[1],
421  t_skip[2],
422  t_skip[3],
423  t_skip[4]);
424  printf("Total event loop time %.5f simtracks %d seedtracks %d builtcands %d maxhits %d on lay %d\n",
425  time,
426  simtrackstot.load(),
427  seedstot.load(),
428  candstot.load(),
429  maxHits_all.load(),
430  maxLayer_all.load());
431  //fflush(stdout);
432  if (g_run_build_all || g_run_build_mimi) {
433  printf("================================================================\n");
434  for (int i = 0; i < Config::nItersCMSSW; ++i)
435  std::cout << " Iteration " << i << " build time = " << t_sum_iter[i] << " \n";
436  printf("================================================================\n");
437  for (int i = 0; i < Config::nItersCMSSW; ++i)
438  std::cout << " Iteration " << i << " build time (event > 1) = " << t_skip_iter[i] << " \n";
439  printf("================================================================\n");
440  }
441  if (g_operation == "read") {
442  data_file.close();
443  }
444 
445  for (auto& val : vals) {
446  val->fillConfigTree();
447  val->saveTTrees();
448  }
449 }
450 
451 //==============================================================================
452 // Command line argument parsing
453 //==============================================================================
454 
455 typedef std::list<std::string> lStr_t;
456 typedef lStr_t::iterator lStr_i;
457 
459  return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
460 }
461 
462 void next_arg_or_die(lStr_t& args, lStr_i& i, bool allow_single_minus = false) {
463  lStr_i j = i;
464  if (++j == args.end() || has_suffix(*j, ".C") || ((*j)[0] == '-' && !(*j == "-" && allow_single_minus))) {
465  std::cerr << "Error: option " << *i << " requires an argument.\n";
466  exit(1);
467  }
468  i = j;
469 }
470 
471 //==============================================================================
472 // main
473 //==============================================================================
474 
475 #include <fenv.h>
476 
477 int main(int argc, const char* argv[]) {
478 #ifdef _GNU_SOURCE
480  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); //FE_ALL_EXCEPT);
481  }
482 #endif
483 
484 #ifdef USE_VTUNE_PAUSE
485  __itt_pause();
486 #endif
487 
488  assert(sizeof(Track::Status) == 4 &&
489  "To make sure this is true for icc and gcc<6 when mixing bools/ints in bitfields.");
490 
491  // init enum maps
492  init_seed_opts();
493  init_clean_opts();
494  init_match_opts();
495 
496  lStr_t mArgs;
497  for (int i = 1; i < argc; ++i) {
498  mArgs.push_back(argv[i]);
499  }
500  bool run_shell = false;
501 
502  lStr_i i = mArgs.begin();
503  while (i != mArgs.end()) {
504  lStr_i start = i;
505 
506  if (*i == "-h" || *i == "-help" || *i == "--help") {
507  printf(
508  "\n"
509  "Usage: %s [options]\n"
510  "Options: defaults defined as (def: DEFAULT VALUE)\n"
511  "\n----------------------------------------------------------------------------------------------------------"
512  "\n\n"
513  "Generic options\n\n"
514  " --geom <str> geometry plugin to use (def: %s)\n"
515  " --silent suppress printouts inside event loop (def: %s)\n"
516  " --best-out-of <int> run test num times, report best time (def: %d)\n"
517  " --input-file file name for reading (def: %s)\n"
518  " --output-file file name for writitng (def: %s)\n"
519  " --read-cmssw-tracks read external cmssw reco tracks if available (def: %s)\n"
520  " --read-simtrack-states read in simTrackStates for pulls in validation (def: %s)\n"
521  " --num-events <int> number of events to run over or simulate (def: %d)\n"
522  " if using --input-file, must be enabled AFTER on command line\n"
523  " --start-event <int> event number to start at when reading from a file (def: %d)\n"
524  " --loop-over-file after reaching the end of the file, start over from the beginning until "
525  " <num-events> events have been processed\n"
526  " --shell start interactive shell instead of running test_standard()\n"
527  "\n"
528  "If no --input-file is specified, will trigger simulation\n"
529  " --num-tracks <int> number of tracks to generate for each event (def: %d)\n"
530  "\n----------------------------------------------------------------------------------------------------------"
531  "\n\n"
532  "Threading related options\n\n"
533  " --num-thr-sim <int> number of threads for simulation (def: %d)\n"
534  " --num-thr <int> number of threads for track finding (def: %d)\n"
535  " --num-thr-ev <int> number of threads to run the event loop (def: %d)\n"
536  " --seeds-per-task <int> number of seeds to process in a tbb task (def: %d)\n"
537  " --hits-per-task <int> number of layer1 hits per task when using find seeds (def: %d)\n"
538  "\n----------------------------------------------------------------------------------------------------------"
539  "\n\n"
540  "FittingTestMPlex options\n\n"
541  " --fit-std run standard fitting test (def: %s)\n"
542  " --fit-std-only run only standard fitting test (def: %s)\n"
543  " --cf-fitting enable conformal fit before fitting tracks to get initial estimate of track "
544  "parameters and errors (def: %s)\n"
545  " --fit-val enable ROOT based validation for fittingMPlex (def: %s)\n"
546  "\n----------------------------------------------------------------------------------------------------------"
547  "\n\n"
548  "BuildingTestMPlex options\n\n"
549  " **Specify which building routine you would like to run\n"
550  " --build-cmssw run dummy validation of CMSSW tracks with MkBuilder stuff (def: %s)\n"
551  " --build-bh run best-hit building test (def: %s)\n"
552  " --build-std run standard combinatorial building test (def: %s)\n"
553  " --build-ce run clone engine combinatorial building test (def: %s)\n"
554  " --build-mimi run clone engine on multiple-iteration test (def: %s)\n"
555  " --num-iters-cmssw <int> number of mimi iterations to run (def: set to 3 when --build-mimi is in effect, "
556  "0 otherwise)\n"
557  "\n"
558  " **Seeding options\n"
559  " --seed-input <str> which seed collecion used for building (def: %s)\n"
560  " --seed-cleaning <str> which seed cleaning to apply if using cmssw seeds (def: %s)\n"
561  " --cf-seeding enable conformal fit over seeds (def: %s)\n"
562  "\n"
563  " **Duplicate removal options\n"
564  " --remove-dup run duplicate removal after building, using both hit and kinematic criteria (def: "
565  "%s)\n"
566  " --remove-dup-no-hit run duplicate removal after building, using kinematic criteria only (def: %s)\n"
567  "\n"
568  " **Dead module (strip) option\n"
569  " --use-dead-modules run duplicate removal after building, using both hit and kinematic criteria "
570  "(def: %s)\n"
571  "\n"
572  " **Additional options for building\n"
573  " --use-phiq-arr use phi-Q arrays in select hit indices (def: %s)\n"
574  " --kludge-cms-hit-errors make sure err(xy) > 15 mum, err(z) > 30 mum (def: %s)\n"
575  " --backward-fit perform backward fit during building (def: %s)\n"
576  " --no-backward-search do not do backward search after backward fit\n"
577  " (def: do search if backward-fit is enabled and available in given iteration)\n"
578  " --include-pca do the backward fit to point of closest approach, does not imply "
579  "'--backward-fit' (def: %s)\n"
580  "\n----------------------------------------------------------------------------------------------------------"
581  "\n\n"
582  "Validation options\n\n"
583  " **Text file based options\n"
584  " --quality-val enable printout validation for MkBuilder (def: %s)\n"
585  " must enable: --dump-for-plots\n"
586  " --dump-for-plots make shell printouts for plots (def: %s)\n"
587  " --mtv-like-val configure validation to emulate CMSSW MultiTrackValidator (MTV) (def: %s)\n"
588  " --mtv-require-seeds configure validation to emulate MTV but require sim tracks to be matched to "
589  "seeds (def: %s)\n"
590  "\n"
591  " **ROOT based options\n"
592  " --sim-val-for-cmssw enable ROOT based validation for CMSSW tracks with simtracks as reference [eff, "
593  "FR, DR] (def: %s)\n"
594  " --sim-val enable ROOT based validation for seeding, building, and fitting with simtracks "
595  "as reference [eff, FR, DR] (def: %s)\n"
596  " --cmssw-val enable ROOT based validation for building and fitting with CMSSW tracks as "
597  "reference [eff, FR, DR] (def: %s)\n"
598  " must enable: --geom CMS-phase1 --read-cmssw-tracks\n"
599  " --cmssw-match-fw <str> which cmssw track matching routine to use if validating against CMSSW tracks, "
600  "forward built tracks only (def: %s)\n"
601  " must enable: --geom CMS-phase1 --cmssw-val --read-cmssw-tracks\n"
602  " --cmssw-match-bk <str> which cmssw track matching routine to use if validating against CMSSW tracks, "
603  "backward fit tracks only (def: %s)\n"
604  " must enable: --geom CMS-phase1 --cmssw-val --read-cmssw-tracks --backward-fit "
605  "--backward-fit-pca\n"
606  " --inc-shorts include short reco tracks into FR (def: %s)\n"
607  " --keep-hit-info keep vectors of hit idxs and branches in trees (def: %s)\n"
608  " --try-to-save-sim-info two options for this flag [related to validation with simtracks as reference "
609  "collection] (def: %s)\n"
610  " a) IF (--read-simtrack-states is enabled)\n"
611  " If a sim track is associated to a reco track, but it does not contain "
612  "the last found on the reco track\n"
613  " still save sim track kinematic info from generator position\n"
614  " b) ELSE (--read-simtrack-states is NOT enabled)\n"
615  " Save sim track kinematic info from generator position if matched to "
616  "reco track\n"
617  "\n----------------------------------------------------------------------------------------------------------"
618  "\n\n"
619  "Combo spaghetti, that's with cole slaw:\n\n"
620  " **Building and fitting combo options\n"
621  " --backward-fit-pca perform backward fit to point of closest approach during building\n"
622  " == --backward-fit --include-pca\n"
623  " **Seed combo options\n"
624  " --cmssw-simseeds use CMS geom with simtracks for seeds\n"
625  " == --geom CMS-phase1 --seed-input %s\n"
626  " --cmssw-stdseeds use CMS geom with CMSSW seeds uncleaned\n"
627  " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s\n"
628  " --cmssw-n2seeds use CMS geom with CMSSW seeds cleaned with N^2 routine\n"
629  " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s\n"
630  " --cmssw-pureseeds use CMS geom with pure CMSSW seeds (seeds which produced CMSSW reco tracks), "
631  "enable read of CMSSW tracks\n"
632  " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s --read-cmssw-tracks\n"
633  " --cmssw-goodlabelseeds use CMS geom with CMSSW seeds with label() >= 0\n"
634  " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s\n"
635  "\n"
636  " **CMSSW validation combo options\n"
637  " --cmssw-val-fhit-bhit use CMSSW validation with hit based matching (50 percent after seed) for forward "
638  "built tracks\n"
639  " use CMSSW validation with hit based matching (50 percent after seed) for "
640  "backward fit tracks\n"
641  " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
642  " must enable: --backward-fit-pca\n"
643  " --cmssw-val-fhit-bprm use CMSSW validation with hit based matching (50 percent after seed) for forward "
644  "built tracks\n"
645  " use CMSSW validation with track parameter based matching for backward fit "
646  "tracks\n"
647  " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
648  " must enable: --backward-fit-pca\n"
649  " --cmssw-val-fprm-bhit use CMSSW validation with track parameter based matching for forward built "
650  "tracks\n"
651  " use CMSSW validation with hit based matching (50 percent after seed) for "
652  "backward fit tracks\n"
653  " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
654  " must enable: --backward-fit-pca\n"
655  " --cmssw-val-fprm-bprm use CMSSW validation with track parameter based matching for forward built "
656  "tracks\n"
657  " use CMSSW validation with track parameter based matching for backward fit "
658  "tracks\n"
659  " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
660  " must enable: --backward-fit-pca\n"
661  " --cmssw-val-label use CMSSW validation with stricter hit based matching for both forward built and "
662  "backward fit tracks, enable read of CMSSW tracks\n"
663  " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
664  " must enable: --cmssw-pureseeds --backward-fit-pca\n"
665  "\n----------------------------------------------------------------------------------------------------------"
666  "\n\n"
667  "JSON config patcher options:\n\n"
668  " --json-load <filename> load single IterationConfig from given JSON file (def: do not load)\n"
669  " can be specified multiple times for several files\n"
670  " --json-patch <filename> patch IterationsInfo from given JSON file (def: do not patch)\n"
671  " can be specified multiple times for several files\n"
672  " --json-save-iterations <fname-fmt> save per iteration json files\n"
673  " %%d in fname-fmt gets replaced with iteration index\n"
674  " %%s in fname-fmt gets replaced with iteration algorithm name\n"
675  " exactly one of %%d and %%s must be specified\n"
676  " --json-save-iterations-include-iter-info-preamble (def: %s)\n"
677  " --json-verbose print each patch assignment as it is being made (def: %s)\n"
678  " --json-dump-before print iteration config before patching (def: %s)\n"
679  " --json-dump-after print iteration config after patching (def: %s)\n"
680  "\n----------------------------------------------------------------------------------------------------------"
681  "\n\n",
682  argv[0],
683 
684  Config::geomPlugin.c_str(),
685  b2a(Config::silent),
687  g_input_file.c_str(),
688  g_output_file.c_str(),
692  g_start_event,
694 
700 
701  b2a(g_run_fit_std),
702  b2a(g_run_fit_std &&
703  !(g_run_build_all || g_run_build_cmssw || g_run_build_bh || g_run_build_std || g_run_build_ce)),
704  b2a(Config::cf_fitting),
705  b2a(Config::fit_val),
706 
707  b2a(g_run_build_all || g_run_build_cmssw),
708  b2a(g_run_build_all || g_run_build_bh),
709  b2a(g_run_build_all || g_run_build_std),
710  b2a(g_run_build_all || g_run_build_ce),
711  b2a(g_run_build_all || g_run_build_mimi),
712 
713  getOpt(Config::seedInput, g_seed_opts).c_str(),
714  getOpt(Config::seedCleaning, g_clean_opts).c_str(),
715  b2a(Config::cf_seeding),
716 
717  b2a(Config::removeDuplicates && Config::useHitsForDuplicates),
718  b2a(Config::removeDuplicates && !Config::useHitsForDuplicates),
719 
721 
724  b2a(Config::backwardFit),
725  b2a(Config::includePCA),
726 
727  b2a(Config::quality_val),
731 
733  b2a(Config::sim_val),
734  b2a(Config::cmssw_val),
735  getOpt(Config::cmsswMatchingFW, g_match_opts).c_str(),
736  getOpt(Config::cmsswMatchingBK, g_match_opts).c_str(),
738  b2a(Config::keepHitInfo),
740 
741  getOpt(simSeeds, g_seed_opts).c_str(),
742  getOpt(cmsswSeeds, g_seed_opts).c_str(),
743  getOpt(noCleaning, g_clean_opts).c_str(),
744  getOpt(cmsswSeeds, g_seed_opts).c_str(),
745  getOpt(cleanSeedsN2, g_clean_opts).c_str(),
746  getOpt(cmsswSeeds, g_seed_opts).c_str(),
747  getOpt(cleanSeedsPure, g_clean_opts).c_str(),
748  getOpt(cmsswSeeds, g_seed_opts).c_str(),
749  getOpt(cleanSeedsBadLabel, g_clean_opts).c_str(),
750 
751  getOpt(hitBased, g_match_opts).c_str(),
752  getOpt(hitBased, g_match_opts).c_str(),
753  getOpt(hitBased, g_match_opts).c_str(),
754  getOpt(trkParamBased, g_match_opts).c_str(),
755  getOpt(trkParamBased, g_match_opts).c_str(),
756  getOpt(hitBased, g_match_opts).c_str(),
757  getOpt(trkParamBased, g_match_opts).c_str(),
758  getOpt(trkParamBased, g_match_opts).c_str(),
759  getOpt(labelBased, g_match_opts).c_str(),
760  getOpt(labelBased, g_match_opts).c_str(),
761 
766 
767  printf("List of options for string based inputs \n");
768  printf(
769  "--geom \n"
770  " CMS-phase1 \n"
771  " CMS-phase2 \n"
772  " CylCowWLids \n"
773  "\n");
774 
775  printf("--seed-input \n");
776  listOpts(g_seed_opts);
777  printf("\n");
778 
779  printf("--seed-cleaning \n");
780  listOpts(g_clean_opts);
781  printf("\n");
782 
783  printf("--cmssw-matching \n");
784  listOpts(g_match_opts);
785  printf("\n");
786 
787  exit(0);
788  } // end of "help" block
789 
790  else if (*i == "--geom") {
791  next_arg_or_die(mArgs, i);
793  } else if (*i == "--silent") {
794  Config::silent = true;
795  } else if (*i == "--best-out-of") {
796  next_arg_or_die(mArgs, i);
797  Config::finderReportBestOutOfN = atoi(i->c_str());
798  } else if (*i == "--input-file") {
799  next_arg_or_die(mArgs, i);
800  g_input_file = *i;
801  g_operation = "read";
802  Config::nEvents = -1;
803  } else if (*i == "--output-file") {
804  next_arg_or_die(mArgs, i);
805  g_output_file = *i;
806  g_operation = "write";
807  } else if (*i == "--read-cmssw-tracks") {
809  } else if (*i == "--read-simtrack-states") {
811  } else if (*i == "--num-events") {
812  next_arg_or_die(mArgs, i);
813  Config::nEvents = atoi(i->c_str());
814  } else if (*i == "--start-event") {
815  next_arg_or_die(mArgs, i);
816  g_start_event = atoi(i->c_str());
817  } else if (*i == "--loop-over-file") {
818  Config::loopOverFile = true;
819  } else if (*i == "--shell") {
820  run_shell = true;
821  } else if (*i == "--num-tracks") {
822  next_arg_or_die(mArgs, i);
823  Config::nTracks = atoi(i->c_str());
824  } else if (*i == "--num-thr-sim") {
825  next_arg_or_die(mArgs, i);
826  Config::numThreadsSimulation = atoi(i->c_str());
827  } else if (*i == "--num-thr") {
828  next_arg_or_die(mArgs, i);
829  Config::numThreadsFinder = atoi(i->c_str());
830  } else if (*i == "--num-thr-ev") {
831  next_arg_or_die(mArgs, i);
832  Config::numThreadsEvents = atoi(i->c_str());
833  } else if (*i == "--seeds-per-task") {
834  next_arg_or_die(mArgs, i);
835  Config::numSeedsPerTask = atoi(i->c_str());
836  } else if (*i == "--hits-per-task") {
837  next_arg_or_die(mArgs, i);
838  Config::numHitsPerTask = atoi(i->c_str());
839  } else if (*i == "--fit-std") {
840  g_run_fit_std = true;
841  } else if (*i == "--fit-std-only") {
842  g_run_fit_std = true;
843  g_run_build_all = false;
844  g_run_build_bh = false;
845  g_run_build_std = false;
846  g_run_build_ce = false;
847  } else if (*i == "--cf-fitting") {
848  Config::cf_fitting = true;
849  } else if (*i == "--fit-val") {
850  Config::fit_val = true;
851  } else if (*i == "--build-cmssw") {
852  g_run_build_all = false;
853  g_run_build_cmssw = true;
854  g_run_build_bh = false;
855  g_run_build_std = false;
856  g_run_build_ce = false;
857  } else if (*i == "--build-bh") {
858  g_run_build_all = false;
859  g_run_build_cmssw = false;
860  g_run_build_bh = true;
861  g_run_build_std = false;
862  g_run_build_ce = false;
863  } else if (*i == "--build-std") {
864  g_run_build_all = false;
865  g_run_build_cmssw = false;
866  g_run_build_bh = false;
867  g_run_build_std = true;
868  g_run_build_ce = false;
869  } else if (*i == "--build-ce") {
870  g_run_build_all = false;
871  g_run_build_cmssw = false;
872  g_run_build_bh = false;
873  g_run_build_std = false;
874  g_run_build_ce = true;
875  } else if (*i == "--build-mimi") {
876  g_run_build_all = false;
877  g_run_build_cmssw = false;
878  g_run_build_bh = false;
879  g_run_build_std = false;
880  g_run_build_ce = false;
881  g_run_build_mimi = true;
882  if (Config::nItersCMSSW == 0)
884  } else if (*i == "--num-iters-cmssw") {
885  next_arg_or_die(mArgs, i);
886  Config::nItersCMSSW = atoi(i->c_str());
887  } else if (*i == "--seed-input") {
888  next_arg_or_die(mArgs, i);
889  setOpt(*i, Config::seedInput, g_seed_opts, "seed input collection");
890  } else if (*i == "--seed-cleaning") {
891  next_arg_or_die(mArgs, i);
892  setOpt(*i, Config::seedCleaning, g_clean_opts, "seed cleaning");
893  } else if (*i == "--cf-seeding") {
894  Config::cf_seeding = true;
895  } else if (*i == "--use-phiq-arr") {
896 #ifdef CONFIG_PhiQArrays
897  Config::usePhiQArrays = true;
898 #else
899  printf("--use-phiq-arr has no effect: recompile with CONFIG_PhiQArrays\n");
900 #endif
901  } else if (*i == "--remove-dup") {
902  Config::removeDuplicates = true;
904  } else if (*i == "--remove-dup-no-hit") {
905  Config::removeDuplicates = true;
907  } else if (*i == "--use-dead-modules") {
908  Config::useDeadModules = true;
909  } else if (*i == "--kludge-cms-hit-errors") {
911  } else if (*i == "--backward-fit") {
912  Config::backwardFit = true;
913  } else if (*i == "--no-backward-search") {
914  Config::backwardSearch = false;
915  } else if (*i == "--include-pca") {
916  Config::includePCA = true;
917  } else if (*i == "--quality-val") {
918  Config::quality_val = true;
919  } else if (*i == "--dump-for-plots") {
920  Config::dumpForPlots = true;
921  } else if (*i == "--mtv-like-val") {
925  } else if (*i == "--mtv-require-seeds") {
930  } else if (*i == "--sim-val-for-cmssw") {
932  } else if (*i == "--sim-val") {
933  Config::sim_val = true;
934  } else if (*i == "--cmssw-val") {
935  Config::cmssw_val = true;
936  } else if (*i == "--cmssw-match-fw") {
937  next_arg_or_die(mArgs, i);
938  setOpt(*i, Config::cmsswMatchingFW, g_match_opts, "CMSSW validation track matching for forward built tracks");
939  } else if (*i == "--cmssw-match-bk") {
940  next_arg_or_die(mArgs, i);
941  setOpt(*i, Config::cmsswMatchingBK, g_match_opts, "CMSSW validation track matching for backward fit tracks");
942  } else if (*i == "--inc-shorts") {
944  } else if (*i == "--keep-hit-info") {
945  Config::keepHitInfo = true;
946  } else if (*i == "--try-to-save-sim-info") {
948  } else if (*i == "--backward-fit-pca") {
949  Config::backwardFit = true;
950  Config::includePCA = true;
951  } else if (*i == "--cmssw-simseeds") {
952  Config::geomPlugin = "CMS-phase1";
954  } else if (*i == "--cmssw-stdseeds") {
955  Config::geomPlugin = "CMS-phase1";
958  } else if (*i == "--cmssw-n2seeds") {
959  Config::geomPlugin = "CMS-phase1";
962  } else if (*i == "--cmssw-pureseeds") {
963  Config::geomPlugin = "CMS-phase1";
967  } else if (*i == "--cmssw-goodlabelseeds") {
968  Config::geomPlugin = "CMS-phase1";
971  } else if (*i == "--cmssw-val-fhit-bhit") {
972  Config::cmssw_val = true;
976  } else if (*i == "--cmssw-val-fhit-bprm") {
977  Config::cmssw_val = true;
981  } else if (*i == "--cmssw-val-fprm-bhit") {
982  Config::cmssw_val = true;
986  } else if (*i == "--cmssw-val-fprm-bprm") {
987  Config::cmssw_val = true;
991  } else if (*i == "--cmssw-val-label") {
992  Config::cmssw_val = true;
996  } else if (*i == "--json-load") {
997  next_arg_or_die(mArgs, i);
998  Config::json_load_filenames.push_back(*i);
999  } else if (*i == "--json-patch") {
1000  next_arg_or_die(mArgs, i);
1001  Config::json_patch_filenames.push_back(*i);
1002  } else if (*i == "--json-save-iterations") {
1003  next_arg_or_die(mArgs, i);
1005  } else if (*i == "--json-save-iterations-include-iter-info-preamble") {
1007  } else if (*i == "--json-verbose") {
1008  Config::json_verbose = true;
1009  } else if (*i == "--json-dump-before") {
1010  Config::json_dump_before = true;
1011  } else if (*i == "--json-dump-after") {
1012  Config::json_dump_after = true;
1013  } else {
1014  fprintf(stderr, "Error: Unknown option/argument '%s'.\n", i->c_str());
1015  exit(1);
1016  }
1017 
1018  mArgs.erase(start, ++i);
1019  }
1020 
1021  // clang-format off
1022 
1023  // Do some checking of options before going...
1026  std::cerr << "What have you done?!? Can't mix cmssw label matching without pure seeds! Exiting...\n";
1027  exit(1);
1029  std::cerr << "What have you done?!? Short reco tracks are already accounted for in the MTV-Like Validation! Inclusive "
1030  "shorts is only an option for the standard simval, and will break the MTV-Like simval! Exiting...\n";
1031  exit(1);
1032  }
1033 
1035 
1036  printf("mkFit configuration complete.\n"
1037  " vusize=%d, num_thr_events=%d, num_thr_finder=%d\n"
1038  " sizeof(Track)=%zu, sizeof(Hit)=%zu, sizeof(SVector3)=%zu, sizeof(SMatrixSym33)=%zu, sizeof(MCHitInfo)=%zu\n",
1040  sizeof(Track), sizeof(Hit), sizeof(SVector3), sizeof(SMatrixSym33), sizeof(MCHitInfo));
1041 
1042  if (run_shell) {
1043  tbb::global_control global_limit(tbb::global_control::max_allowed_parallelism, Config::numThreadsFinder);
1044 
1045  initGeom();
1046  Shell s(deadvectors, g_input_file, g_start_event);
1047  s.Run();
1048  } else {
1049  test_standard();
1050  }
1051 
1052  // clang-format on
1053 
1054  return 0;
1055 }
Definition: start.py:1
void test_standard()
Definition: mkFit.cc:208
static void populate()
Definition: MkBuilder.cc:168
int openRead(const std::string &fname, int expected_n_layers)
Definition: Event.cc:852
static std::mutex mutex
Definition: Proxy.cc:8
std::map< std::string, std::pair< seedOpts, std::string > > seedOptsMap
double runBuildingTestPlexStandard(Event &ev, const EventOfHits &eoh, MkBuilder &builder)
ROOT::Math::SVector< float, 3 > SVector3
Definition: MatrixSTypes.h:14
void initGeom()
Definition: mkFit.cc:52
void setOpt(const std::string &cmd_ln_str, T &c_opt, const U &g_opt_map, const std::string &ex_txt)
Definition: mkFit.cc:190
bool has_suffix(const std::string &str, const std::string &suffix)
Definition: mkFit.cc:458
void close()
Definition: Event.cc:979
cleanOpts seedCleaning
assert(be >=bs)
std::map< std::string, std::pair< matchOpts, std::string > > matchOptsMap
std::vector< std::string > json_patch_filenames
static Validation * make_validation(const std::string &, const TrackerInfo *)
Definition: Validation.cc:5
lStr_t::iterator lStr_i
Definition: mkFit.cc:456
void execTrackerInfoCreatorPlugin(const std::string &base, TrackerInfo &ti, IterationsInfo &ii, bool verbose)
void recalculateDependentConstants()
constexpr bool usePhiQArrays
Definition: Config.h:112
void patch_Files(IterationsInfo &its_info, const std::vector< std::string > &fnames, ConfigJsonPatcher::PatchReport *report=nullptr)
matchOpts cmsswMatchingFW
std::string getOpt(const T &c_opt, const U &g_opt_map)
Definition: mkFit.cc:178
void loadHitsAndBeamSpot(Event &ev, EventOfHits &eoh)
void skipNEvents(int n_to_skip)
Definition: Event.cc:967
matchOpts cmsswMatchingBK
void setupStandardFunctionsFromNames()
void listOpts(const U &g_opt_map)
Definition: mkFit.cc:200
TrackerInfo TrkInfo
void loadDeads(EventOfHits &eoh, const std::vector< DeadVec > &deadvectors)
Definition: MkStdSeqs.cc:21
int main(int argc, const char *argv[])
Definition: mkFit.cc:477
std::unique_ptr< IterationConfig > patchLoad_File(const IterationsInfo &its_info, const std::string &fname, ConfigJsonPatcher::PatchReport *report=nullptr)
void runBuildingTestPlexDumbCMSSW(Event &ev, const EventOfHits &eoh, MkBuilder &builder)
constexpr int numThreadsFinder
Definition: Config.h:128
void save_Iterations(IterationsInfo &its_info, const std::string &fname_fmt, bool include_iter_info_preamble)
IterationsInfo ItrInfo
constexpr bool nan_etc_sigs_enable
Definition: Config.h:59
static std::mutex printmutex
Definition: Event.h:68
double runBuildingTestPlexCloneEngine(Event &ev, const EventOfHits &eoh, MkBuilder &builder)
void next_arg_or_die(lStr_t &args, lStr_i &i, bool allow_single_minus=false)
Definition: mkFit.cc:462
#define MPT_SIZE
Definition: Matrix.h:37
double b
Definition: hdecay.h:118
void dump(IterationsInfo &its_info)
double dtime()
std::map< std::string, std::pair< cleanOpts, std::string > > cleanOptsMap
bool json_save_iters_include_iter_info_preamble
std::vector< std::string > json_load_filenames
std::vector< double > runBtpCe_MultiIter(Event &ev, const EventOfHits &eoh, MkBuilder &builder, int n)
#define dprint(x)
Definition: Debug.h:95
static std::unique_ptr< MkBuilder > make_builder(bool silent=true)
Definition: MkBuilder.cc:166
constexpr int numSeedsPerTask
Definition: Config.h:130
constexpr int numThreadsEvents
Definition: Config.h:129
void init_deadvectors()
Definition: mkFit.cc:47
std::list< std::string > lStr_t
Definition: mkFit.cc:455
const bool useHitsForDuplicates
Definition: Config.h:150
std::string json_save_iters_fname_fmt
#define str(s)
ROOT::Math::SMatrix< float, 3, 3, ROOT::Math::MatRepSym< float, 3 > > SMatrixSym33
Definition: MatrixSTypes.h:13
std::string geomPlugin
long double T
std::vector< DeadVec > deadvectors
Definition: mkFit.cc:45
double runBuildingTestPlexBestHit(Event &ev, const EventOfHits &eoh, MkBuilder &builder)
def exit(msg="")