CMS 3D CMS Logo

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