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