CMS 3D CMS Logo

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