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