File indexing completed on 2024-04-25 02:14:11
0001 #include "RecoTracker/MkFitCore/src/Matriplex/MatriplexCommon.h"
0002
0003
0004 #include "RecoTracker/MkFitCMS/standalone/buildtestMPlex.h"
0005
0006 #include "RecoTracker/MkFitCore/interface/HitStructures.h"
0007 #include "RecoTracker/MkFitCore/interface/MkBuilder.h"
0008 #include "RecoTracker/MkFitCore/src/MkFitter.h"
0009 #include "RecoTracker/MkFitCMS/interface/MkStdSeqs.h"
0010 #include "RecoTracker/MkFitCMS/standalone/MkStandaloneSeqs.h"
0011
0012 #include "RecoTracker/MkFitCore/interface/Config.h"
0013 #include "RecoTracker/MkFitCore/standalone/ConfigStandalone.h"
0014
0015 #include "RecoTracker/MkFitCore/standalone/Event.h"
0016
0017 #ifndef NO_ROOT
0018 #include "RecoTracker/MkFitCore/standalone/Validation.h"
0019 #include "RecoTracker/MkFitCore/standalone/RntDumper/RntDumper.h"
0020 #endif
0021
0022
0023 #include "RecoTracker/MkFitCore/src/Debug.h"
0024 #include "RecoTracker/MkFitCMS/standalone/Shell.h"
0025
0026 #include "oneapi/tbb/task_arena.h"
0027 #include "oneapi/tbb/parallel_for.h"
0028 #include <oneapi/tbb/global_control.h>
0029
0030 #if defined(USE_VTUNE_PAUSE)
0031 #include "ittnotify.h"
0032 #endif
0033
0034 #include <cstdlib>
0035 #include <limits>
0036 #include <list>
0037 #include <sstream>
0038 #include <memory>
0039
0040 using namespace mkfit;
0041
0042
0043
0044 namespace mkfit::internal {
0045
0046 std::vector<DeadVec> deadvectors;
0047 }
0048
0049 void initGeom() {
0050 std::cout << "Constructing geometry '" << Config::geomPlugin << "'\n";
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 mkfit::execTrackerInfoCreatorPlugin(Config::geomPlugin, Config::TrkInfo, Config::ItrInfo);
0069
0070 ConfigJson cj(Config::json_verbose);
0071
0072 if (Config::json_dump_before)
0073 cj.dump(Config::ItrInfo);
0074
0075 if (!Config::json_load_filenames.empty()) {
0076 ConfigJsonPatcher::PatchReport report;
0077
0078 for (auto& fn : Config::json_load_filenames) {
0079
0080
0081 cj.patchLoad_File(Config::ItrInfo, fn, &report);
0082 }
0083
0084 printf(
0085 "mkFit.cc/%s--JSON-Load read %d JSON entities from %d files, replaced %d parameters.\n"
0086 " NOTE that these changes were NOT APPLIED to actual configuration that is going to be used.\n",
0087 __func__,
0088 report.n_json_entities,
0089 report.n_files,
0090 report.n_replacements);
0091 }
0092
0093 if (!Config::json_patch_filenames.empty()) {
0094 ConfigJsonPatcher::PatchReport report;
0095
0096 cj.patch_Files(Config::ItrInfo, Config::json_patch_filenames, &report);
0097
0098 printf("mkFit.cc/%s--JOSN-Patch read %d JSON entities from %d files, replaced %d parameters.\n",
0099 __func__,
0100 report.n_json_entities,
0101 report.n_files,
0102 report.n_replacements);
0103 }
0104
0105 if (Config::json_dump_after)
0106 cj.dump(Config::ItrInfo);
0107
0108 if (!Config::json_save_iters_fname_fmt.empty()) {
0109 cj.save_Iterations(
0110 Config::ItrInfo, Config::json_save_iters_fname_fmt, Config::json_save_iters_include_iter_info_preamble);
0111 }
0112
0113 Config::ItrInfo.setupStandardFunctionsFromNames();
0114
0115
0116
0117
0118 }
0119
0120 namespace {
0121 int g_start_event = 1;
0122
0123 bool g_run_fit_std = false;
0124
0125 bool g_run_build_default = true;
0126 bool g_run_build_cmssw = false;
0127 bool g_run_build_bh = false;
0128 bool g_run_build_std = false;
0129 bool g_run_build_ce = false;
0130 bool g_run_build_mimi = false;
0131
0132 std::string g_operation = "simulate_and_process";
0133 ;
0134 std::string g_input_file = "";
0135 std::string g_output_file = "";
0136
0137 seedOptsMap g_seed_opts;
0138 void init_seed_opts() {
0139 g_seed_opts["sim"] = {simSeeds, "Use simtracks for seeds"};
0140 g_seed_opts["cmssw"] = {cmsswSeeds, "Use external CMSSW seeds"};
0141 g_seed_opts["find"] = {findSeeds, "Use mplex seed finder for seeds"};
0142 }
0143
0144 cleanOptsMap g_clean_opts;
0145 void init_clean_opts() {
0146 g_clean_opts["none"] = {noCleaning, "No cleaning applied to external CMSSW seeds"};
0147 g_clean_opts["n2"] = {cleanSeedsN2, "Apply N^2 cleaning by Mario to external CMSSW seeds"};
0148 g_clean_opts["pure"] = {
0149 cleanSeedsPure,
0150 "Only use external CMSSW seeds that have produced a CMSSW track \n must enable: --read-cmssw-tracks"};
0151 g_clean_opts["badlabel"] = {cleanSeedsBadLabel, "Remove seeds with label()<0 in external CMSSW seeds"};
0152 }
0153
0154 matchOptsMap g_match_opts;
0155 void init_match_opts() {
0156 g_match_opts["trkparam"] = {trkParamBased,
0157 "Use track parameter-based matching for validating against CMSSW tracks"};
0158 g_match_opts["hits"] = {hitBased, "Use hit-based matching for validating against CMSSW tracks"};
0159 g_match_opts["label"] = {labelBased, "Only allowed with pure seeds: stricter hit-based matching"};
0160 }
0161
0162 const char* b2a(bool b) { return b ? "true" : "false"; }
0163
0164 }
0165
0166
0167
0168
0169
0170 template <typename T, typename U>
0171 std::string getOpt(const T& c_opt, const U& g_opt_map) {
0172 static const std::string empty("");
0173
0174 for (const auto& g_opt_pair : g_opt_map) {
0175 if (g_opt_pair.second.first == c_opt)
0176 return g_opt_pair.first;
0177 }
0178 std::cerr << "No match for option " << c_opt << std::endl;
0179 return empty;
0180 }
0181
0182 template <typename T, typename U>
0183 void setOpt(const std::string& cmd_ln_str, T& c_opt, const U& g_opt_map, const std::string& ex_txt) {
0184 if (g_opt_map.count(cmd_ln_str))
0185 c_opt = g_opt_map.at(cmd_ln_str).first;
0186 else {
0187 std::cerr << cmd_ln_str << " is not a valid " << ex_txt << " option!! Exiting..." << std::endl;
0188 exit(1);
0189 }
0190 }
0191
0192 template <typename U>
0193 void listOpts(const U& g_opt_map) {
0194 for (const auto& g_opt_pair : g_opt_map) {
0195 std::cout << " " << g_opt_pair.first.c_str() << " : " << g_opt_pair.second.second.c_str() << std::endl;
0196 }
0197 }
0198
0199
0200
0201 void test_standard() {
0202 printf("Running test_standard(), operation=\"%s\", best_out_of=%d\n",
0203 g_operation.c_str(),
0204 Config::finderReportBestOutOfN);
0205
0206 if (Config::seedInput == cmsswSeeds)
0207 printf("- reading seeds from file\n");
0208
0209 initGeom();
0210
0211 if (Config::nEvents <= 0) {
0212 return;
0213 }
0214
0215 DataFile data_file;
0216 if (g_operation == "read") {
0217 int evs_in_file = data_file.openRead(g_input_file, Config::TrkInfo.n_layers());
0218 int evs_available = evs_in_file - g_start_event + 1;
0219 if (Config::nEvents == -1) {
0220 Config::nEvents = evs_available;
0221 } else if (Config::nEvents > evs_available and not Config::loopOverFile) {
0222 printf("Requested number of events %d, only %d available.\n", Config::nEvents, evs_available);
0223 Config::nEvents = evs_available;
0224 }
0225
0226 if (g_start_event > 1) {
0227 data_file.skipNEvents(g_start_event - 1);
0228 }
0229 }
0230
0231 constexpr int NT = 5;
0232 double t_sum[NT] = {0};
0233 double t_skip[NT] = {0};
0234 std::vector<double> t_sum_iter(Config::nItersCMSSW, 0.0);
0235 std::vector<double> t_skip_iter(Config::nItersCMSSW, 0.0);
0236 double time = dtime();
0237
0238 std::atomic<int> nevt{g_start_event};
0239 std::atomic<int> seedstot{0}, simtrackstot{0}, candstot{0};
0240 std::atomic<int> maxHits_all{0}, maxLayer_all{0};
0241
0242 MkBuilder::populate();
0243
0244 std::vector<std::unique_ptr<Event>> evs(Config::numThreadsEvents);
0245 std::vector<std::unique_ptr<Validation>> vals(Config::numThreadsEvents);
0246 std::vector<std::unique_ptr<MkBuilder>> mkbs(Config::numThreadsEvents);
0247 std::vector<std::shared_ptr<EventOfHits>> eohs(Config::numThreadsEvents);
0248 std::vector<std::shared_ptr<FILE>> fps;
0249 fps.reserve(Config::numThreadsEvents);
0250
0251 const std::string valfile("valtree");
0252
0253 for (int i = 0; i < Config::numThreadsEvents; ++i) {
0254 std::ostringstream serial;
0255 if (Config::numThreadsEvents > 1) {
0256 serial << "_" << i;
0257 }
0258 vals[i].reset(Validation::make_validation(valfile + serial.str() + ".root", &Config::TrkInfo));
0259 mkbs[i] = MkBuilder::make_builder(Config::silent);
0260 eohs[i].reset(new EventOfHits(Config::TrkInfo));
0261 evs[i].reset(new Event(*vals[i], 0, Config::TrkInfo.n_layers()));
0262 if (g_operation == "read") {
0263 fps.emplace_back(fopen(g_input_file.c_str(), "r"), [](FILE* fp) {
0264 if (fp)
0265 fclose(fp);
0266 });
0267 }
0268 }
0269
0270 tbb::task_arena arena(Config::numThreadsFinder);
0271
0272 dprint("parallel_for step size " << (Config::nEvents + Config::numThreadsEvents - 1) / Config::numThreadsEvents);
0273
0274 time = dtime();
0275
0276 int events_per_thread = (Config::nEvents + Config::numThreadsEvents - 1) / Config::numThreadsEvents;
0277
0278 arena.execute([&]() {
0279 tbb::parallel_for(
0280 tbb::blocked_range<int>(0, Config::numThreadsEvents, 1),
0281 [&](const tbb::blocked_range<int>& threads) {
0282 int thisthread = threads.begin();
0283
0284 assert(threads.begin() == threads.end() - 1 && thisthread < Config::numThreadsEvents);
0285
0286
0287 auto& ev = *evs[thisthread].get();
0288 auto& mkb = *mkbs[thisthread].get();
0289 auto& eoh = *eohs[thisthread].get();
0290 auto fp = fps[thisthread].get();
0291
0292 int evstart = thisthread * events_per_thread;
0293 int evend = std::min(Config::nEvents, evstart + events_per_thread);
0294
0295 dprint("thisthread " << thisthread << " events " << Config::nEvents << " events/thread " << events_per_thread
0296 << " range " << evstart << ":" << evend);
0297
0298 for (int evt = evstart; evt < evend; ++evt) {
0299 ev.reset(nevt++);
0300
0301 if (!Config::silent) {
0302 std::lock_guard<std::mutex> printlock(Event::printmutex);
0303 printf("\n");
0304 printf("Processing event %d\n", ev.evtID());
0305 }
0306
0307 ev.read_in(data_file, fp);
0308
0309
0310 if (ev.seedTracks_.empty())
0311 continue;
0312
0313
0314
0315 StdSeq::loadHitsAndBeamSpot(ev, eoh);
0316
0317 if (Config::useDeadModules) {
0318 StdSeq::loadDeads(eoh, mkfit::internal::deadvectors);
0319 }
0320
0321 double t_best[NT] = {0}, t_cur[NT] = {0};
0322 std::vector<double> t_cur_iter;
0323 simtrackstot += ev.simTracks_.size();
0324 seedstot += ev.seedTracks_.size();
0325
0326 int ncands_thisthread = 0;
0327 int maxHits_thisthread = 0;
0328 int maxLayer_thisthread = 0;
0329 for (int b = 0; b < Config::finderReportBestOutOfN; ++b) {
0330 t_cur[0] = 0;
0331 t_cur[1] = (g_run_build_bh) ? runBuildingTestPlexBestHit(ev, eoh, mkb) : 0;
0332 t_cur[2] = (g_run_build_default || g_run_build_std) ? runBuildingTestPlexStandard(ev, eoh, mkb) : 0;
0333 t_cur[3] = (g_run_build_default || g_run_build_ce) ? runBuildingTestPlexCloneEngine(ev, eoh, mkb) : 0;
0334 if (g_run_build_mimi)
0335 t_cur_iter = runBtpCe_MultiIter(ev, eoh, mkb, Config::nItersCMSSW);
0336 t_cur[4] = (g_run_build_mimi) ? t_cur_iter[Config::nItersCMSSW] : 0;
0337 if (g_run_build_cmssw)
0338 runBuildingTestPlexDumbCMSSW(ev, eoh, mkb);
0339 if (g_run_build_ce || g_run_build_mimi) {
0340 ncands_thisthread = mkb.total_cands();
0341 auto const& ln = mkb.max_hits_layer(eoh);
0342 maxHits_thisthread = ln.first;
0343 maxLayer_thisthread = ln.second;
0344 }
0345 for (int i = 0; i < NT; ++i)
0346 t_best[i] = (b == 0) ? t_cur[i] : std::min(t_cur[i], t_best[i]);
0347
0348 if (!Config::silent) {
0349 std::lock_guard<std::mutex> printlock(Event::printmutex);
0350 if (Config::finderReportBestOutOfN > 1) {
0351 printf("----------------------------------------------------------------\n");
0352 printf("Best-of-times:");
0353 for (int i = 0; i < NT; ++i)
0354 printf(" %.5f/%.5f", t_cur[i], t_best[i]);
0355 printf("\n");
0356 }
0357 printf("----------------------------------------------------------------\n");
0358 }
0359 }
0360
0361 candstot += ncands_thisthread;
0362 if (maxHits_thisthread > maxHits_all) {
0363 maxHits_all = maxHits_thisthread;
0364 maxLayer_all = maxLayer_thisthread;
0365 }
0366 if (!Config::silent) {
0367 std::lock_guard<std::mutex> printlock(Event::printmutex);
0368 printf("Matriplex fit = %.5f --- Build BHMX = %.5f STDMX = %.5f CEMX = %.5f MIMI = %.5f\n",
0369 t_best[0],
0370 t_best[1],
0371 t_best[2],
0372 t_best[3],
0373 t_best[4]);
0374 }
0375
0376 {
0377 static std::mutex sum_up_lock;
0378 std::lock_guard<std::mutex> locker(sum_up_lock);
0379
0380 for (int i = 0; i < NT; ++i)
0381 t_sum[i] += t_best[i];
0382 if (evt > 0)
0383 for (int i = 0; i < NT; ++i)
0384 t_skip[i] += t_best[i];
0385 if (g_run_build_mimi) {
0386 for (int i = 0; i < Config::nItersCMSSW; ++i)
0387 t_sum_iter[i] += t_cur_iter[i];
0388 if (evt > 0)
0389 for (int i = 0; i < Config::nItersCMSSW; ++i)
0390 t_skip_iter[i] += t_cur_iter[i];
0391 }
0392 }
0393 }
0394 },
0395 tbb::simple_partitioner());
0396 });
0397
0398 time = dtime() - time;
0399
0400 printf("\n");
0401 printf("================================================================\n");
0402 printf("=== TOTAL for %d events\n", Config::nEvents);
0403 printf("================================================================\n");
0404
0405 printf("Total Matriplex fit = %.5f --- Build BHMX = %.5f STDMX = %.5f CEMX = %.5f MIMI = %.5f\n",
0406 t_sum[0],
0407 t_sum[1],
0408 t_sum[2],
0409 t_sum[3],
0410 t_sum[4]);
0411 printf("Total event > 1 fit = %.5f --- Build BHMX = %.5f STDMX = %.5f CEMX = %.5f MIMI = %.5f\n",
0412 t_skip[0],
0413 t_skip[1],
0414 t_skip[2],
0415 t_skip[3],
0416 t_skip[4]);
0417 printf("Total event loop time %.5f simtracks %d seedtracks %d builtcands %d maxhits %d on lay %d\n",
0418 time,
0419 simtrackstot.load(),
0420 seedstot.load(),
0421 candstot.load(),
0422 maxHits_all.load(),
0423 maxLayer_all.load());
0424
0425 if (g_run_build_mimi) {
0426 printf("================================================================\n");
0427 for (int i = 0; i < Config::nItersCMSSW; ++i)
0428 std::cout << " Iteration " << i << " build time = " << t_sum_iter[i] << " \n";
0429 printf("================================================================\n");
0430 for (int i = 0; i < Config::nItersCMSSW; ++i)
0431 std::cout << " Iteration " << i << " build time (event > 1) = " << t_skip_iter[i] << " \n";
0432 printf("================================================================\n");
0433 }
0434 if (g_operation == "read") {
0435 data_file.close();
0436 }
0437
0438 for (auto& val : vals) {
0439 val->fillConfigTree();
0440 val->saveTTrees();
0441 }
0442 }
0443
0444
0445
0446
0447
0448 typedef std::list<std::string> lStr_t;
0449 typedef lStr_t::iterator lStr_i;
0450
0451 bool has_suffix(const std::string& str, const std::string& suffix) {
0452 return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
0453 }
0454
0455 void next_arg_or_die(lStr_t& args, lStr_i& i, bool allow_single_minus = false) {
0456 lStr_i j = i;
0457 if (++j == args.end() || has_suffix(*j, ".C") || ((*j)[0] == '-' && !(*j == "-" && allow_single_minus))) {
0458 std::cerr << "Error: option " << *i << " requires an argument.\n";
0459 exit(1);
0460 }
0461 i = j;
0462 }
0463
0464
0465
0466
0467
0468 #include <fenv.h>
0469
0470 int main(int argc, const char* argv[]) {
0471 #ifdef _GNU_SOURCE
0472 if (Const::nan_etc_sigs_enable) {
0473 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
0474 }
0475 #endif
0476
0477 #ifdef USE_VTUNE_PAUSE
0478 __itt_pause();
0479 #endif
0480
0481 assert(sizeof(Track::Status) == 4 &&
0482 "To make sure this is true for icc and gcc<6 when mixing bools/ints in bitfields.");
0483
0484
0485 init_seed_opts();
0486 init_clean_opts();
0487 init_match_opts();
0488
0489 lStr_t mArgs;
0490 for (int i = 1; i < argc; ++i) {
0491 mArgs.push_back(argv[i]);
0492 }
0493 bool run_shell = false;
0494
0495 lStr_i i = mArgs.begin();
0496 while (i != mArgs.end()) {
0497 lStr_i start = i;
0498
0499 if (*i == "-h" || *i == "-help" || *i == "--help") {
0500 printf(
0501 "\n"
0502 "Usage: %s [options]\n"
0503 "Options: defaults defined as (def: DEFAULT VALUE)\n"
0504 "\n----------------------------------------------------------------------------------------------------------"
0505 "\n\n"
0506 "Generic options\n\n"
0507 " --geom <str> geometry plugin to use (def: %s)\n"
0508 " --silent suppress printouts inside event loop (def: %s)\n"
0509 " --best-out-of <int> run test num times, report best time (def: %d)\n"
0510 " --input-file file name for reading (def: %s)\n"
0511 " --output-file file name for writitng (def: %s)\n"
0512 " --read-cmssw-tracks read external cmssw reco tracks if available (def: %s)\n"
0513 " --read-simtrack-states read in simTrackStates for pulls in validation (def: %s)\n"
0514 " --num-events <int> number of events to run over or simulate (def: %d)\n"
0515 " if using --input-file, must be enabled AFTER on command line\n"
0516 " --start-event <int> event number to start at when reading from a file (def: %d)\n"
0517 " --loop-over-file after reaching the end of the file, start over from the beginning until "
0518 " <num-events> events have been processed\n"
0519 " --shell start interactive shell instead of running test_standard()\n"
0520 "\n"
0521 "If no --input-file is specified, will trigger simulation\n"
0522 " --num-tracks <int> number of tracks to generate for each event (def: %d)\n"
0523 "\n----------------------------------------------------------------------------------------------------------"
0524 "\n\n"
0525 "Threading related options\n\n"
0526 " --num-thr-sim <int> number of threads for simulation (def: %d)\n"
0527 " --num-thr <int> number of threads for track finding (def: %d)\n"
0528 " --num-thr-ev <int> number of threads to run the event loop (def: %d)\n"
0529 " --seeds-per-task <int> number of seeds to process in a tbb task (def: %d)\n"
0530 " --hits-per-task <int> number of layer1 hits per task when using find seeds (def: %d)\n"
0531 "\n----------------------------------------------------------------------------------------------------------"
0532 "\n\n"
0533 "FittingTestMPlex options\n\n"
0534 " --fit-std run standard fitting test (def: %s)\n"
0535 " --cf-fitting enable conformal fit before fitting tracks to get initial estimate of track "
0536 "parameters and errors (def: %s)\n"
0537 " --fit-val enable ROOT based validation for fittingMPlex (def: %s)\n"
0538 "\n----------------------------------------------------------------------------------------------------------"
0539 "\n\n"
0540 "BuildingTestMPlex options\n\n"
0541 " **Specify which building routine you would like to run\n"
0542 " --build-cmssw run dummy validation of CMSSW tracks with MkBuilder stuff (def: %s)\n"
0543 " --build-bh run best-hit building test (def: %s)\n"
0544 " --build-std run standard combinatorial building test (def: %s)\n"
0545 " --build-ce run clone engine combinatorial building test (def: %s)\n"
0546 " --build-mimi run clone engine on multiple-iteration test (def: %s)\n"
0547 " --num-iters-cmssw <int> number of mimi iterations to run (def: set to 3 when --build-mimi is in effect, "
0548 "0 otherwise)\n"
0549 "\n"
0550 " **Seeding options\n"
0551 " --seed-input <str> which seed collecion used for building (def: %s)\n"
0552 " --seed-cleaning <str> which seed cleaning to apply if using cmssw seeds (def: %s)\n"
0553 " --cf-seeding enable conformal fit over seeds (def: %s)\n"
0554 "\n"
0555 " **Duplicate removal options\n"
0556 " --remove-dup run duplicate removal after building, using both hit and kinematic criteria (def: "
0557 "%s)\n"
0558 " --remove-dup-no-hit run duplicate removal after building, using kinematic criteria only (def: %s)\n"
0559 "\n"
0560 " **Dead module (strip) option\n"
0561 " --use-dead-modules run duplicate removal after building, using both hit and kinematic criteria "
0562 "(def: %s)\n"
0563 "\n"
0564 " **Additional options for building\n"
0565 " --use-phiq-arr use phi-Q arrays in select hit indices (def: %s)\n"
0566 " --kludge-cms-hit-errors make sure err(xy) > 15 mum, err(z) > 30 mum (def: %s)\n"
0567 " --backward-fit perform backward fit during building (def: %s)\n"
0568 " --no-backward-search do not do backward search after backward fit\n"
0569 " (def: do search if backward-fit is enabled and available in given iteration)\n"
0570 " --include-pca do the backward fit to point of closest approach, does not imply "
0571 "'--backward-fit' (def: %s)\n"
0572 "\n----------------------------------------------------------------------------------------------------------"
0573 "\n\n"
0574 "Validation options\n\n"
0575 " **Text file based options\n"
0576 " --quality-val enable printout validation for MkBuilder (def: %s)\n"
0577 " must enable: --dump-for-plots\n"
0578 " --dump-for-plots make shell printouts for plots (def: %s)\n"
0579 " --mtv-like-val configure validation to emulate CMSSW MultiTrackValidator (MTV) (def: %s)\n"
0580 " --mtv-require-seeds configure validation to emulate MTV but require sim tracks to be matched to "
0581 "seeds (def: %s)\n"
0582 "\n"
0583 " **ROOT based options\n"
0584 " --sim-val-for-cmssw enable ROOT based validation for CMSSW tracks with simtracks as reference [eff, "
0585 "FR, DR] (def: %s)\n"
0586 " --sim-val enable ROOT based validation for seeding, building, and fitting with simtracks "
0587 "as reference [eff, FR, DR] (def: %s)\n"
0588 " --cmssw-val enable ROOT based validation for building and fitting with CMSSW tracks as "
0589 "reference [eff, FR, DR] (def: %s)\n"
0590 " must enable: --geom CMS-phase1 --read-cmssw-tracks\n"
0591 " --cmssw-match-fw <str> which cmssw track matching routine to use if validating against CMSSW tracks, "
0592 "forward built tracks only (def: %s)\n"
0593 " must enable: --geom CMS-phase1 --cmssw-val --read-cmssw-tracks\n"
0594 " --cmssw-match-bk <str> which cmssw track matching routine to use if validating against CMSSW tracks, "
0595 "backward fit tracks only (def: %s)\n"
0596 " must enable: --geom CMS-phase1 --cmssw-val --read-cmssw-tracks --backward-fit "
0597 "--backward-fit-pca\n"
0598 " --inc-shorts include short reco tracks into FR (def: %s)\n"
0599 " --keep-hit-info keep vectors of hit idxs and branches in trees (def: %s)\n"
0600 " --try-to-save-sim-info two options for this flag [related to validation with simtracks as reference "
0601 "collection] (def: %s)\n"
0602 " a) IF (--read-simtrack-states is enabled)\n"
0603 " If a sim track is associated to a reco track, but it does not contain "
0604 "the last found on the reco track\n"
0605 " still save sim track kinematic info from generator position\n"
0606 " b) ELSE (--read-simtrack-states is NOT enabled)\n"
0607 " Save sim track kinematic info from generator position if matched to "
0608 "reco track\n"
0609 "\n----------------------------------------------------------------------------------------------------------"
0610 "\n\n"
0611 "Combo spaghetti, that's with cole slaw:\n\n"
0612 " **Building and fitting combo options\n"
0613 " --backward-fit-pca perform backward fit to point of closest approach during building\n"
0614 " == --backward-fit --include-pca\n"
0615 " **Seed combo options\n"
0616 " --cmssw-simseeds use CMS geom with simtracks for seeds\n"
0617 " == --geom CMS-phase1 --seed-input %s\n"
0618 " --cmssw-stdseeds use CMS geom with CMSSW seeds uncleaned\n"
0619 " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s\n"
0620 " --cmssw-n2seeds use CMS geom with CMSSW seeds cleaned with N^2 routine\n"
0621 " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s\n"
0622 " --cmssw-pureseeds use CMS geom with pure CMSSW seeds (seeds which produced CMSSW reco tracks), "
0623 "enable read of CMSSW tracks\n"
0624 " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s --read-cmssw-tracks\n"
0625 " --cmssw-goodlabelseeds use CMS geom with CMSSW seeds with label() >= 0\n"
0626 " == --geom CMS-phase1 --seed-input %s --seed-cleaning %s\n"
0627 "\n"
0628 " **CMSSW validation combo options\n"
0629 " --cmssw-val-fhit-bhit use CMSSW validation with hit based matching (50 percent after seed) for forward "
0630 "built tracks\n"
0631 " use CMSSW validation with hit based matching (50 percent after seed) for "
0632 "backward fit tracks\n"
0633 " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
0634 " must enable: --backward-fit-pca\n"
0635 " --cmssw-val-fhit-bprm use CMSSW validation with hit based matching (50 percent after seed) for forward "
0636 "built tracks\n"
0637 " use CMSSW validation with track parameter based matching for backward fit "
0638 "tracks\n"
0639 " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
0640 " must enable: --backward-fit-pca\n"
0641 " --cmssw-val-fprm-bhit use CMSSW validation with track parameter based matching for forward built "
0642 "tracks\n"
0643 " use CMSSW validation with hit based matching (50 percent after seed) for "
0644 "backward fit tracks\n"
0645 " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
0646 " must enable: --backward-fit-pca\n"
0647 " --cmssw-val-fprm-bprm use CMSSW validation with track parameter based matching for forward built "
0648 "tracks\n"
0649 " use CMSSW validation with track parameter based matching for backward fit "
0650 "tracks\n"
0651 " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
0652 " must enable: --backward-fit-pca\n"
0653 " --cmssw-val-label use CMSSW validation with stricter hit based matching for both forward built and "
0654 "backward fit tracks, enable read of CMSSW tracks\n"
0655 " == --cmssw-val --read-cmssw-tracks --cmssw-match-fw %s --cmssw-match-bk %s\n"
0656 " must enable: --cmssw-pureseeds --backward-fit-pca\n"
0657 "\n----------------------------------------------------------------------------------------------------------"
0658 "\n\n"
0659 "JSON config patcher options:\n\n"
0660 " --json-load <filename> load single IterationConfig from given JSON file (def: do not load)\n"
0661 " can be specified multiple times for several files\n"
0662 " --json-patch <filename> patch IterationsInfo from given JSON file (def: do not patch)\n"
0663 " can be specified multiple times for several files\n"
0664 " --json-save-iterations <fname-fmt> save per iteration json files\n"
0665 " %%d in fname-fmt gets replaced with iteration index\n"
0666 " %%s in fname-fmt gets replaced with iteration algorithm name\n"
0667 " exactly one of %%d and %%s must be specified\n"
0668 " --json-save-iterations-include-iter-info-preamble (def: %s)\n"
0669 " --json-verbose print each patch assignment as it is being made (def: %s)\n"
0670 " --json-dump-before print iteration config before patching (def: %s)\n"
0671 " --json-dump-after print iteration config after patching (def: %s)\n"
0672 "\n----------------------------------------------------------------------------------------------------------"
0673 "\n\n",
0674 argv[0],
0675
0676 Config::geomPlugin.c_str(),
0677 b2a(Config::silent),
0678 Config::finderReportBestOutOfN,
0679 g_input_file.c_str(),
0680 g_output_file.c_str(),
0681 b2a(Config::readCmsswTracks),
0682 b2a(Config::readSimTrackStates),
0683 Config::nEvents,
0684 g_start_event,
0685 Config::nTracks,
0686
0687 Config::numThreadsSimulation,
0688 Config::numThreadsFinder,
0689 Config::numThreadsEvents,
0690 Config::numSeedsPerTask,
0691 Config::numHitsPerTask,
0692
0693 b2a(g_run_fit_std),
0694 b2a(Config::cf_fitting),
0695 b2a(Config::fit_val),
0696
0697 b2a(g_run_build_cmssw),
0698 b2a(g_run_build_bh),
0699 b2a(g_run_build_default || g_run_build_std),
0700 b2a(g_run_build_default || g_run_build_ce),
0701 b2a(g_run_build_mimi),
0702
0703 getOpt(Config::seedInput, g_seed_opts).c_str(),
0704 getOpt(Config::seedCleaning, g_clean_opts).c_str(),
0705 b2a(Config::cf_seeding),
0706
0707 b2a(Config::removeDuplicates && Config::useHitsForDuplicates),
0708 b2a(Config::removeDuplicates && !Config::useHitsForDuplicates),
0709
0710 b2a(Config::useDeadModules),
0711
0712 b2a(Config::usePhiQArrays),
0713 b2a(Config::kludgeCmsHitErrors),
0714 b2a(Config::backwardFit),
0715 b2a(Config::includePCA),
0716
0717 b2a(Config::quality_val),
0718 b2a(Config::dumpForPlots),
0719 b2a(Config::mtvLikeValidation),
0720 b2a(Config::mtvRequireSeeds),
0721
0722 b2a(Config::sim_val_for_cmssw),
0723 b2a(Config::sim_val),
0724 b2a(Config::cmssw_val),
0725 getOpt(Config::cmsswMatchingFW, g_match_opts).c_str(),
0726 getOpt(Config::cmsswMatchingBK, g_match_opts).c_str(),
0727 b2a(Config::inclusiveShorts),
0728 b2a(Config::keepHitInfo),
0729 b2a(Config::tryToSaveSimInfo),
0730
0731 getOpt(simSeeds, g_seed_opts).c_str(),
0732 getOpt(cmsswSeeds, g_seed_opts).c_str(),
0733 getOpt(noCleaning, g_clean_opts).c_str(),
0734 getOpt(cmsswSeeds, g_seed_opts).c_str(),
0735 getOpt(cleanSeedsN2, g_clean_opts).c_str(),
0736 getOpt(cmsswSeeds, g_seed_opts).c_str(),
0737 getOpt(cleanSeedsPure, g_clean_opts).c_str(),
0738 getOpt(cmsswSeeds, g_seed_opts).c_str(),
0739 getOpt(cleanSeedsBadLabel, g_clean_opts).c_str(),
0740
0741 getOpt(hitBased, g_match_opts).c_str(),
0742 getOpt(hitBased, g_match_opts).c_str(),
0743 getOpt(hitBased, g_match_opts).c_str(),
0744 getOpt(trkParamBased, g_match_opts).c_str(),
0745 getOpt(trkParamBased, g_match_opts).c_str(),
0746 getOpt(hitBased, g_match_opts).c_str(),
0747 getOpt(trkParamBased, g_match_opts).c_str(),
0748 getOpt(trkParamBased, g_match_opts).c_str(),
0749 getOpt(labelBased, g_match_opts).c_str(),
0750 getOpt(labelBased, g_match_opts).c_str(),
0751
0752 b2a(Config::json_verbose),
0753 b2a(Config::json_save_iters_include_iter_info_preamble),
0754 b2a(Config::json_dump_before),
0755 b2a(Config::json_dump_after));
0756
0757 printf("List of options for string based inputs \n");
0758 printf(
0759 "--geom \n"
0760 " CMS-phase1 \n"
0761 " CMS-phase2 \n"
0762 " CylCowWLids \n"
0763 "\n");
0764
0765 printf("--seed-input \n");
0766 listOpts(g_seed_opts);
0767 printf("\n");
0768
0769 printf("--seed-cleaning \n");
0770 listOpts(g_clean_opts);
0771 printf("\n");
0772
0773 printf("--cmssw-matching \n");
0774 listOpts(g_match_opts);
0775 printf("\n");
0776
0777 exit(0);
0778 }
0779
0780 else if (*i == "--geom") {
0781 next_arg_or_die(mArgs, i);
0782 Config::geomPlugin = *i;
0783 } else if (*i == "--silent") {
0784 Config::silent = true;
0785 } else if (*i == "--best-out-of") {
0786 next_arg_or_die(mArgs, i);
0787 Config::finderReportBestOutOfN = atoi(i->c_str());
0788 } else if (*i == "--input-file") {
0789 next_arg_or_die(mArgs, i);
0790 g_input_file = *i;
0791 g_operation = "read";
0792 Config::nEvents = -1;
0793 } else if (*i == "--output-file") {
0794 next_arg_or_die(mArgs, i);
0795 g_output_file = *i;
0796 g_operation = "write";
0797 } else if (*i == "--read-cmssw-tracks") {
0798 Config::readCmsswTracks = true;
0799 } else if (*i == "--read-simtrack-states") {
0800 Config::readSimTrackStates = true;
0801 } else if (*i == "--num-events") {
0802 next_arg_or_die(mArgs, i);
0803 Config::nEvents = atoi(i->c_str());
0804 } else if (*i == "--start-event") {
0805 next_arg_or_die(mArgs, i);
0806 g_start_event = atoi(i->c_str());
0807 } else if (*i == "--loop-over-file") {
0808 Config::loopOverFile = true;
0809 } else if (*i == "--shell") {
0810 run_shell = true;
0811 } else if (*i == "--num-tracks") {
0812 next_arg_or_die(mArgs, i);
0813 Config::nTracks = atoi(i->c_str());
0814 } else if (*i == "--num-thr-sim") {
0815 next_arg_or_die(mArgs, i);
0816 Config::numThreadsSimulation = atoi(i->c_str());
0817 } else if (*i == "--num-thr") {
0818 next_arg_or_die(mArgs, i);
0819 Config::numThreadsFinder = atoi(i->c_str());
0820 } else if (*i == "--num-thr-ev") {
0821 next_arg_or_die(mArgs, i);
0822 Config::numThreadsEvents = atoi(i->c_str());
0823 } else if (*i == "--seeds-per-task") {
0824 next_arg_or_die(mArgs, i);
0825 Config::numSeedsPerTask = atoi(i->c_str());
0826 } else if (*i == "--hits-per-task") {
0827 next_arg_or_die(mArgs, i);
0828 Config::numHitsPerTask = atoi(i->c_str());
0829 } else if (*i == "--fit-std") {
0830 g_run_build_default = false;
0831 g_run_fit_std = true;
0832 } else if (*i == "--cf-fitting") {
0833 Config::cf_fitting = true;
0834 } else if (*i == "--fit-val") {
0835 Config::fit_val = true;
0836 } else if (*i == "--build-cmssw") {
0837 g_run_build_default = false;
0838 g_run_build_cmssw = true;
0839 } else if (*i == "--build-bh") {
0840 g_run_build_default = false;
0841 g_run_build_bh = true;
0842 } else if (*i == "--build-std") {
0843 g_run_build_default = false;
0844 g_run_build_std = true;
0845 } else if (*i == "--build-ce") {
0846 g_run_build_default = false;
0847 g_run_build_ce = true;
0848 } else if (*i == "--build-mimi") {
0849 g_run_build_default = false;
0850 g_run_build_mimi = true;
0851 if (Config::nItersCMSSW == 0)
0852 Config::nItersCMSSW = 3;
0853 } else if (*i == "--num-iters-cmssw") {
0854 next_arg_or_die(mArgs, i);
0855 Config::nItersCMSSW = atoi(i->c_str());
0856 } else if (*i == "--seed-input") {
0857 next_arg_or_die(mArgs, i);
0858 setOpt(*i, Config::seedInput, g_seed_opts, "seed input collection");
0859 } else if (*i == "--seed-cleaning") {
0860 next_arg_or_die(mArgs, i);
0861 setOpt(*i, Config::seedCleaning, g_clean_opts, "seed cleaning");
0862 } else if (*i == "--cf-seeding") {
0863 Config::cf_seeding = true;
0864 } else if (*i == "--use-phiq-arr") {
0865 #ifdef CONFIG_PhiQArrays
0866 Config::usePhiQArrays = true;
0867 #else
0868 printf("--use-phiq-arr has no effect: recompile with CONFIG_PhiQArrays\n");
0869 #endif
0870 } else if (*i == "--remove-dup") {
0871 Config::removeDuplicates = true;
0872 Config::useHitsForDuplicates = true;
0873 } else if (*i == "--remove-dup-no-hit") {
0874 Config::removeDuplicates = true;
0875 Config::useHitsForDuplicates = false;
0876 } else if (*i == "--use-dead-modules") {
0877 Config::useDeadModules = true;
0878 } else if (*i == "--kludge-cms-hit-errors") {
0879 Config::kludgeCmsHitErrors = true;
0880 } else if (*i == "--backward-fit") {
0881 Config::backwardFit = true;
0882 } else if (*i == "--no-backward-search") {
0883 Config::backwardSearch = false;
0884 } else if (*i == "--include-pca") {
0885 Config::includePCA = true;
0886 } else if (*i == "--quality-val") {
0887 Config::quality_val = true;
0888 } else if (*i == "--dump-for-plots") {
0889 Config::dumpForPlots = true;
0890 } else if (*i == "--mtv-like-val") {
0891 Config::mtvLikeValidation = true;
0892 Config::cmsSelMinLayers = 0;
0893 Config::nMinFoundHits = 0;
0894 } else if (*i == "--mtv-require-seeds") {
0895 Config::mtvLikeValidation = true;
0896 Config::cmsSelMinLayers = 0;
0897 Config::nMinFoundHits = 0;
0898 Config::mtvRequireSeeds = true;
0899 } else if (*i == "--sim-val-for-cmssw") {
0900 Config::sim_val_for_cmssw = true;
0901 } else if (*i == "--sim-val") {
0902 Config::sim_val = true;
0903 } else if (*i == "--cmssw-val") {
0904 Config::cmssw_val = true;
0905 } else if (*i == "--cmssw-match-fw") {
0906 next_arg_or_die(mArgs, i);
0907 setOpt(*i, Config::cmsswMatchingFW, g_match_opts, "CMSSW validation track matching for forward built tracks");
0908 } else if (*i == "--cmssw-match-bk") {
0909 next_arg_or_die(mArgs, i);
0910 setOpt(*i, Config::cmsswMatchingBK, g_match_opts, "CMSSW validation track matching for backward fit tracks");
0911 } else if (*i == "--inc-shorts") {
0912 Config::inclusiveShorts = true;
0913 } else if (*i == "--keep-hit-info") {
0914 Config::keepHitInfo = true;
0915 } else if (*i == "--try-to-save-sim-info") {
0916 Config::tryToSaveSimInfo = true;
0917 } else if (*i == "--backward-fit-pca") {
0918 Config::backwardFit = true;
0919 Config::includePCA = true;
0920 } else if (*i == "--cmssw-simseeds") {
0921 Config::geomPlugin = "CMS-phase1";
0922 Config::seedInput = simSeeds;
0923 } else if (*i == "--cmssw-stdseeds") {
0924 Config::geomPlugin = "CMS-phase1";
0925 Config::seedInput = cmsswSeeds;
0926 Config::seedCleaning = noCleaning;
0927 } else if (*i == "--cmssw-n2seeds") {
0928 Config::geomPlugin = "CMS-phase1";
0929 Config::seedInput = cmsswSeeds;
0930 Config::seedCleaning = cleanSeedsN2;
0931 } else if (*i == "--cmssw-pureseeds") {
0932 Config::geomPlugin = "CMS-phase1";
0933 Config::seedInput = cmsswSeeds;
0934 Config::seedCleaning = cleanSeedsPure;
0935 Config::readCmsswTracks = true;
0936 } else if (*i == "--cmssw-goodlabelseeds") {
0937 Config::geomPlugin = "CMS-phase1";
0938 Config::seedInput = cmsswSeeds;
0939 Config::seedCleaning = cleanSeedsBadLabel;
0940 } else if (*i == "--cmssw-val-fhit-bhit") {
0941 Config::cmssw_val = true;
0942 Config::readCmsswTracks = true;
0943 Config::cmsswMatchingFW = hitBased;
0944 Config::cmsswMatchingBK = hitBased;
0945 } else if (*i == "--cmssw-val-fhit-bprm") {
0946 Config::cmssw_val = true;
0947 Config::readCmsswTracks = true;
0948 Config::cmsswMatchingFW = hitBased;
0949 Config::cmsswMatchingBK = trkParamBased;
0950 } else if (*i == "--cmssw-val-fprm-bhit") {
0951 Config::cmssw_val = true;
0952 Config::readCmsswTracks = true;
0953 Config::cmsswMatchingFW = trkParamBased;
0954 Config::cmsswMatchingBK = hitBased;
0955 } else if (*i == "--cmssw-val-fprm-bprm") {
0956 Config::cmssw_val = true;
0957 Config::readCmsswTracks = true;
0958 Config::cmsswMatchingFW = trkParamBased;
0959 Config::cmsswMatchingBK = trkParamBased;
0960 } else if (*i == "--cmssw-val-label") {
0961 Config::cmssw_val = true;
0962 Config::readCmsswTracks = true;
0963 Config::cmsswMatchingFW = labelBased;
0964 Config::cmsswMatchingBK = labelBased;
0965 } else if (*i == "--json-load") {
0966 next_arg_or_die(mArgs, i);
0967 Config::json_load_filenames.push_back(*i);
0968 } else if (*i == "--json-patch") {
0969 next_arg_or_die(mArgs, i);
0970 Config::json_patch_filenames.push_back(*i);
0971 } else if (*i == "--json-save-iterations") {
0972 next_arg_or_die(mArgs, i);
0973 Config::json_save_iters_fname_fmt = *i;
0974 } else if (*i == "--json-save-iterations-include-iter-info-preamble") {
0975 Config::json_save_iters_include_iter_info_preamble = true;
0976 } else if (*i == "--json-verbose") {
0977 Config::json_verbose = true;
0978 } else if (*i == "--json-dump-before") {
0979 Config::json_dump_before = true;
0980 } else if (*i == "--json-dump-after") {
0981 Config::json_dump_after = true;
0982 } else {
0983 fprintf(stderr, "Error: Unknown option/argument '%s'.\n", i->c_str());
0984 exit(1);
0985 }
0986
0987 mArgs.erase(start, ++i);
0988 }
0989
0990
0991
0992
0993 if (Config::seedCleaning != cleanSeedsPure &&
0994 (Config::cmsswMatchingFW == labelBased || Config::cmsswMatchingBK == labelBased)) {
0995 std::cerr << "What have you done?!? Can't mix cmssw label matching without pure seeds! Exiting...\n";
0996 exit(1);
0997 } else if (Config::mtvLikeValidation && Config::inclusiveShorts) {
0998 std::cerr << "What have you done?!? Short reco tracks are already accounted for in the MTV-Like Validation! Inclusive "
0999 "shorts is only an option for the standard simval, and will break the MTV-Like simval! Exiting...\n";
1000 exit(1);
1001 }
1002
1003 Config::recalculateDependentConstants();
1004
1005 printf("mkFit configuration complete.\n"
1006 " vusize=%d, num_thr_events=%d, num_thr_finder=%d\n"
1007 " sizeof(Track)=%zu, sizeof(Hit)=%zu, sizeof(SVector3)=%zu, sizeof(SMatrixSym33)=%zu, sizeof(MCHitInfo)=%zu\n",
1008 MPT_SIZE, Config::numThreadsEvents, Config::numThreadsFinder,
1009 sizeof(Track), sizeof(Hit), sizeof(SVector3), sizeof(SMatrixSym33), sizeof(MCHitInfo));
1010
1011 if (run_shell) {
1012 tbb::global_control global_limit(tbb::global_control::max_allowed_parallelism, Config::numThreadsFinder);
1013
1014 initGeom();
1015 Shell s(mkfit::internal::deadvectors, g_input_file, g_start_event);
1016 s.Run();
1017 } else {
1018 test_standard();
1019 }
1020
1021 #ifndef NO_ROOT
1022 RntDumper::FinalizeAll();
1023 #endif
1024
1025
1026
1027 return 0;
1028 }