CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Types | Private Attributes
mkfit::Shell Class Reference

#include <Shell.h>

Public Types

enum  SeedSelect_e { SS_UseAll = 0, SS_Label, SS_IndexPreCleaning, SS_IndexPostCleaning }
 

Public Member Functions

MkBuilderbuilder ()
 
bool CheckMkFitLayerPlanVsReferenceHits (const Track &mkft, const Track &reft, const std::string &name)
 
void Compare ()
 
EventOfHitseoh ()
 
Eventevent ()
 
void FillByLabelMaps_CkfBase ()
 
void GoToEvent (int eid)
 
int LabelFromHits (Track &t, bool replace, float good_frac)
 
void NextEvent (int skip=1)
 
void PrintIterations ()
 
void ProcessEvent (SeedSelect_e seed_select=SS_UseAll, int selected_seed=-1, int count=1)
 
void Run ()
 
const TrackVecseeds () const
 
void SelectIterationAlgo (int algo)
 
void SelectIterationIndex (int itidx)
 
void SetBackwardFit (bool b)
 
void SetCleanSeeds (bool b)
 
void SetDebug (bool b)
 
void SetRemoveDuplicates (bool b)
 
void SetUseDeadModules (bool b)
 
 Shell (std::vector< DeadVec > &dv, const std::string &in_file, int start_ev)
 
void Status ()
 
const TrackVectracks () const
 

Private Types

using map_i = map_t::iterator
 
using map_t = std::map< int, Track * >
 

Private Attributes

bool m_backward_fit = true
 
MkBuilderm_builder = nullptr
 
std::map< int, Track * > m_ckf_map
 
bool m_clean_seeds = true
 
DataFilem_data_file = nullptr
 
std::vector< DeadVec > & m_deadvectors
 
EventOfHitsm_eoh = nullptr
 
Eventm_event = nullptr
 
int m_evs_in_file = -1
 
int m_it_index = 0
 
std::map< int, Track * > m_mkf_map
 
bool m_remove_duplicates = true
 
std::map< int, Track * > m_seed_map
 
TrackVec m_seeds
 
std::map< int, Track * > m_sim_map
 
TrackVec m_tracks
 

Detailed Description

Definition at line 16 of file Shell.h.

Member Typedef Documentation

◆ map_i

using mkfit::Shell::map_i = map_t::iterator
private

Definition at line 75 of file Shell.h.

◆ map_t

using mkfit::Shell::map_t = std::map<int, Track *>
private

Definition at line 74 of file Shell.h.

Member Enumeration Documentation

◆ SeedSelect_e

Enumerator
SS_UseAll 
SS_Label 
SS_IndexPreCleaning 
SS_IndexPostCleaning 

Definition at line 18 of file Shell.h.

Constructor & Destructor Documentation

◆ Shell()

mkfit::Shell::Shell ( std::vector< DeadVec > &  dv,
const std::string &  in_file,
int  start_ev 
)

Definition at line 40 of file Shell.cc.

References mkfit::Config::backwardFit, GoToEvent(), runGCPTkAlMap::in_file, m_backward_fit, m_builder, m_data_file, m_eoh, m_event, m_evs_in_file, mkfit::DataFile::openRead(), mkfit::Config::silent, and mkfit::Config::TrkInfo.

41  : m_deadvectors(dv)
42  {
43  m_eoh = new EventOfHits(Config::TrkInfo);
44  m_builder = new MkBuilder(Config::silent);
45 
47 
48  m_data_file = new DataFile;
50 
51  m_event = new Event(0, Config::TrkInfo.n_layers());
52  GoToEvent(start_ev);
53  }
int openRead(const std::string &fname, int expected_n_layers)
Definition: Event.cc:926
DataFile * m_data_file
Definition: Shell.h:61
MkBuilder * m_builder
Definition: Shell.h:64
std::vector< DeadVec > & m_deadvectors
Definition: Shell.h:60
EventOfHits * m_eoh
Definition: Shell.h:63
void GoToEvent(int eid)
Definition: Shell.cc:87
bool m_backward_fit
Definition: Shell.h:68
TrackerInfo TrkInfo
Event * m_event
Definition: Shell.h:62
int m_evs_in_file
Definition: Shell.h:65

Member Function Documentation

◆ builder()

MkBuilder* mkfit::Shell::builder ( )
inline

Definition at line 41 of file Shell.h.

References m_builder.

Referenced by ProcessEvent().

41 { return m_builder; }
MkBuilder * m_builder
Definition: Shell.h:64

◆ CheckMkFitLayerPlanVsReferenceHits()

bool mkfit::Shell::CheckMkFitLayerPlanVsReferenceHits ( const Track mkft,
const Track reft,
const std::string &  name 
)

Definition at line 437 of file Shell.cc.

References mkfit::TrackBase::getEtaRegion(), mkfit::Track::getHitOnTrack(), mkfit::Config::ItrInfo, mkfit::TrackBase::label(), m_it_index, mkfit::IterationConfig::m_steering_params, Skims_PA_cff::name, mkfit::Track::nTotalHits(), runTheMatrix::ret, and x.

Referenced by Compare().

437  {
438  // Check if all hit-layers of a reference track reft are in the mkfit layer plan.
439  // Returns true if all layers are in the plan.
440  // String name is printed in front of label, expected to be SIMK or CKF.
441  const IterationConfig &itconf = Config::ItrInfo[m_it_index];
442  auto lp = itconf.m_steering_params[ mkft.getEtaRegion() ].m_layer_plan;
443  bool ret = true;
444  for (int hi = 0; hi < reft.nTotalHits(); ++hi) {
445  auto hot = reft.getHitOnTrack(hi);
446  if (std::find_if(lp.begin(), lp.end(), [=](auto &x){ return x.m_layer == hot.layer; }) == lp.end())
447  {
448  printf("CheckMkfLayerPlanVsCkfHits: layer %d not in layer plan for region %d, %s label=%d\n",
449  hot.layer, mkft.getEtaRegion(), name.c_str(), reft.label());
450  ret = false;
451  }
452  }
453  return ret;
454  }
ret
prodAgent to be discontinued
Definition: EPCuts.h:4
IterationsInfo ItrInfo
int m_it_index
Definition: Shell.h:66
float x

◆ Compare()

void mkfit::Shell::Compare ( )

Definition at line 460 of file Shell.cc.

References mkfit::TrackBase::algoint_to_cstr(), CheckMkFitLayerPlanVsReferenceHits(), makeMEIFBenchmarkPlots::ev, FillByLabelMaps_CkfBase(), mkfit::IterationConfig::get_seed_partitioner(), mkfit::HitOnTrack::index, mkfit::Config::ItrInfo, MainPageGenerator::l, mkfit::HitOnTrack::layer, m_ckf_map, m_eoh, m_event, m_it_index, m_mkf_map, m_seed_map, m_seeds, m_sim_map, mkfit::IterationConfig::m_track_algorithm, mkfit::print(), singleTopDQM_cfi::select, mkfit::Config::TrkInfo, and funct::void.

460  {
461  Event &ev = *m_event;
462  const IterationConfig &itconf = Config::ItrInfo[m_it_index];
463 
465 
466  printf("------------------------------------------------------\n");
467 
468  const bool print_all_def = false;
469  int mkf_cnt=0, less_hits=0, more_hits=0;
470 
471  // TOBTEC: look for rec-seeds with hits in tob1 and 2 only.
472  int tot_cnt = 0, no_mkf_cnt = 0;
473 
474  for (auto& [l, simt_ptr]: m_sim_map)
475  {
476  auto &simt = * simt_ptr;
477  auto &ckft = * m_ckf_map[l];
478  auto mi = m_mkf_map.find(l);
479 
480  bool print_all = print_all_def;
481 
482  // TOBTEC: look for rec-seeds with hits in tob1 and 2 only.
483  bool select = true;
484  {
485  auto &ckf_seed = ev.seedTracks_[ckft.label()];
486  for (int hi = 0; hi < ckf_seed.nTotalHits(); ++hi) {
487  const HitOnTrack hot = ckf_seed.getHitOnTrack(hi);
488  if (hot.index >= 0 && (hot.layer < 10 || hot.layer > 13)) {
489  select = false;
490  break;
491  }
492  }
493  }
494  if ( ! select) continue;
495 
496  ++tot_cnt;
497  //print_all = true;
498 
499  if (mi != m_mkf_map.end())
500  {
501  auto &mkft = * mi->second;
502  mkf_cnt++;
503  if (mkft.nFoundHits() < ckft.nFoundHits()) ++less_hits;
504  if (mkft.nFoundHits() > ckft.nFoundHits()) ++more_hits;
505 
506  CheckMkFitLayerPlanVsReferenceHits(mkft, ckft, "CKF");
507  // CheckMkFitLayerPlanVsReferenceHits(mkft, simt, "SIM");
508 
509  (void) print_all;
510  if (/* itconf.m_track_algorithm == 10 ||*/ print_all) {
511  // ckf label is wrong when validation is on (even quality val) for mixedTriplet, pixelless and tobtec
512  // as seed tracks get removed for non-mkfit iterations and indices from rec-tracks are no longer valid.
513  auto &ckf_seed = ev.seedTracks_[ckft.label()];
514  auto &mkf_seed = m_seeds[mkft.label()];
515  print("ckf ", 0, ckft, ev);
516  print("mkfit", 0, mkft, ev);
517  print("sim ", 0, simt, ev);
518  print("ckf seed", 0, ckf_seed, ev);
519  print("mkf seed", 0, mkf_seed, ev);
520  printf("------------------------------------------------------\n");
521 
522  TrackVec ssss;
523  ssss.push_back(mkf_seed);
524 
525  IterationSeedPartition pppp(1);
526  IterationConfig::get_seed_partitioner("phase1:1:debug")(Config::TrkInfo, ssss, *m_eoh, pppp);
527 
528  printf("------------------------------------------------------\n");
529  printf("\n");
530  }
531  }
532  else
533  {
534  printf("\n!!!!! No mkfit track with this label.\n\n");
535  ++no_mkf_cnt;
536 
537  auto &ckf_seed = ev.seedTracks_[ckft.label()];
538  print("ckf ", 0, ckft, ev);
539  print("sim ", 0, simt, ev);
540  print("ckf seed", 0, ckf_seed, ev);
541  auto smi = m_seed_map.find(l);
542  if (smi != m_seed_map.end())
543  print("seed with matching label", 0, *smi->second, ev);
544  printf("------------------------------------------------------\n");
545  }
546  }
547 
548  printf("mkFit found %d, matching_label=%d, less_hits=%d, more_hits=%d [algo=%d (%s)]\n",
549  (int) ev.fitTracks_.size(), mkf_cnt, less_hits, more_hits,
550  itconf.m_track_algorithm, TrackBase::algoint_to_cstr(itconf.m_track_algorithm));
551 
552  if (tot_cnt > 0) {
553  printf("\ntobtec tob1/2 tot=%d no_mkf=%d (%f%%)\n",
554  tot_cnt, no_mkf_cnt, 100.0 * no_mkf_cnt / tot_cnt);
555  } else {
556  printf("\nNo CKF tracks with seed hits in TOB1/2 found (need iteration idx 8, TobTec?)\n");
557  }
558 
559  printf("-------------------------------------------------------------------------------------------\n");
560  printf("-------------------------------------------------------------------------------------------\n");
561  printf("\n");
562  }
std::map< int, Track * > m_sim_map
Definition: Shell.h:77
TrackVec m_seeds
Definition: Shell.h:71
std::map< int, Track * > m_mkf_map
Definition: Shell.h:77
bool CheckMkFitLayerPlanVsReferenceHits(const Track &mkft, const Track &reft, const std::string &name)
Definition: Shell.cc:437
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
void FillByLabelMaps_CkfBase()
Definition: Shell.cc:372
EventOfHits * m_eoh
Definition: Shell.h:63
Definition: EPCuts.h:4
static partition_seeds_func get_seed_partitioner(const std::string &name)
TrackerInfo TrkInfo
IterationsInfo ItrInfo
static const char * algoint_to_cstr(int algo)
Definition: Track.cc:331
std::vector< Track > TrackVec
void print(std::string_view label, const MeasurementState &s)
Definition: Hit.cc:8
Event * m_event
Definition: Shell.h:62
int m_it_index
Definition: Shell.h:66
std::map< int, Track * > m_ckf_map
Definition: Shell.h:77
std::map< int, Track * > m_seed_map
Definition: Shell.h:77

◆ eoh()

EventOfHits* mkfit::Shell::eoh ( )
inline

Definition at line 40 of file Shell.h.

References m_eoh.

Referenced by ProcessEvent().

40 { return m_eoh; }
EventOfHits * m_eoh
Definition: Shell.h:63

◆ event()

Event* mkfit::Shell::event ( )
inline

Definition at line 39 of file Shell.h.

References m_event.

39 { return m_event; }
Event * m_event
Definition: Shell.h:62

◆ FillByLabelMaps_CkfBase()

void mkfit::Shell::FillByLabelMaps_CkfBase ( )

Definition at line 372 of file Shell.cc.

References mkfit::TrackBase::algoint_to_cstr(), makeMEIFBenchmarkPlots::ev, createfilelist::int, mkfit::Config::ItrInfo, label, LabelFromHits(), m_ckf_map, m_event, m_it_index, m_mkf_map, m_seed_map, m_seeds, m_sim_map, m_tracks, and submitPVValidationJobs::t.

Referenced by Compare().

372  {
373  Event &ev = *m_event;
374  const int track_algo = Config::ItrInfo[m_it_index].m_track_algorithm;
375 
376  m_ckf_map.clear();
377  m_sim_map.clear();
378  m_seed_map.clear();
379  m_mkf_map.clear();
380 
381  // Pick ckf tracks with right algo and a good label.
382  int rec_algo_match = 0;
383  for (auto &t : ev.cmsswTracks_) {
384  if (t.algoint() != track_algo)
385  continue;
386  ++rec_algo_match;
387  int label = LabelFromHits(t, false, 0.5);
388  if (label >= 0) {
389  m_ckf_map.insert(std::make_pair(label, &t));
390  }
391  }
392 
393  // Pick sim tracks with labels found by ckf.
394  for (auto &t : ev.simTracks_) {
395  if (t.label() >= 0 && m_ckf_map.find(t.label()) != m_ckf_map.end()) {
396  m_sim_map.insert(std::make_pair(t.label(), &t));
397  }
398  }
399 
400  // Pick seeds with right algo and a label found by ckf.
401  for (auto &t : ev.seedTracks_) {
402  if (t.algoint() == track_algo && t.label() >= 0 && m_ckf_map.find(t.label()) != m_ckf_map.end()) {
403  m_seed_map.insert(std::make_pair(t.label(), &t));
404  }
405  }
406  // Some seeds seem to be labeled -1, try fixing when not otherwise found.
407  for (auto &t : ev.seedTracks_) {
408  if (t.algoint() == track_algo && t.label() == -1) {
409  int lab = LabelFromHits(t, true, 0.5);
410  if (lab >= 0 && m_seed_map.find(lab) == m_seed_map.end()) {
411  if (m_ckf_map.find(lab) != m_ckf_map.end()) {
412  m_seed_map.insert(std::make_pair(t.label(), &t));
413  printf("Saved seed with label -1 -> %d\n", lab);
414  }
415  }
416  }
417  }
418 
419  // Pick mkfit tracks, label by
420  for (auto &t : m_tracks) {
421  int label = LabelFromHits(t, false, 0.5);
422  if (label >= 0) {
423  m_mkf_map.insert(std::make_pair(label, &t));
424  }
425  }
426 
427  printf("Shell::FillByLabelMaps reporting tracks with label >= 0, algo=%d (%s): "
428  "ckf: %d of %d (same algo=%d)), sim: %d of %d, seed: %d of %d, mkfit: %d w/label of %d\n",
429  track_algo, TrackBase::algoint_to_cstr(track_algo),
430  (int) m_ckf_map.size(), (int) ev.cmsswTracks_.size(), rec_algo_match,
431  (int) m_sim_map.size(), (int) ev.simTracks_.size(),
432  (int) m_seed_map.size(), (int) m_seeds.size(),
433  (int) m_mkf_map.size(), (int) m_tracks.size()
434  );
435  }
std::map< int, Track * > m_sim_map
Definition: Shell.h:77
TrackVec m_seeds
Definition: Shell.h:71
std::map< int, Track * > m_mkf_map
Definition: Shell.h:77
char const * label
IterationsInfo ItrInfo
static const char * algoint_to_cstr(int algo)
Definition: Track.cc:331
TrackVec m_tracks
Definition: Shell.h:72
Event * m_event
Definition: Shell.h:62
int m_it_index
Definition: Shell.h:66
int LabelFromHits(Track &t, bool replace, float good_frac)
Definition: Shell.cc:345
std::map< int, Track * > m_ckf_map
Definition: Shell.h:77
std::map< int, Track * > m_seed_map
Definition: Shell.h:77

◆ GoToEvent()

void mkfit::Shell::GoToEvent ( int  eid)

Definition at line 87 of file Shell.cc.

References runTauDisplay::eid, mkfit::Event::evtID(), mkfit::StdSeq::loadDeads(), mkfit::StdSeq::loadHitsAndBeamSpot(), m_data_file, m_deadvectors, m_eoh, m_event, m_evs_in_file, mkfit::Event::read_in(), mkfit::Event::reset(), mkfit::Event::resetCurrentSeedTracks(), mkfit::DataFile::rewind(), mkfit::DataFile::skipNEvents(), submitPVResolutionJobs::stderr, and mkfit::Config::useDeadModules.

Referenced by NextEvent(), and Shell().

87  {
88  if (eid < 1) {
89  fprintf(stderr, "Requested event %d is less than 1 -- 1 is the first event, %d is total number of events in file\n",
91  throw std::runtime_error("event out of range");
92  }
93  if (eid > m_evs_in_file) {
94  fprintf(stderr, "Requested event %d is grater than total number of events in file %d\n",
96  throw std::runtime_error("event out of range");
97  }
98 
99  int pos = m_event->evtID();
100  if (eid > pos) {
101  m_data_file->skipNEvents(eid - pos - 1);
102  } else {
103  m_data_file->rewind();
105  }
106  m_event->resetCurrentSeedTracks(); // left after ProcessEvent() for debugging etc
107  m_event->reset(eid);
112  }
113 
114  printf("At event %d\n", eid);
115  }
void rewind()
Definition: Event.cc:1014
void reset(int evtID)
Definition: Event.cc:33
DataFile * m_data_file
Definition: Shell.h:61
int evtID() const
Definition: Event.h:23
void resetCurrentSeedTracks()
Definition: Event.cc:917
std::vector< DeadVec > & m_deadvectors
Definition: Shell.h:60
void loadHitsAndBeamSpot(Event &ev, EventOfHits &eoh)
void skipNEvents(int n_to_skip)
Definition: Event.cc:1041
EventOfHits * m_eoh
Definition: Shell.h:63
void loadDeads(EventOfHits &eoh, const std::vector< DeadVec > &deadvectors)
Definition: MkStdSeqs.cc:21
Event * m_event
Definition: Shell.h:62
int m_evs_in_file
Definition: Shell.h:65
void read_in(DataFile &data_file, FILE *in_fp=0)
Definition: Event.cc:207

◆ LabelFromHits()

int mkfit::Shell::LabelFromHits ( Track t,
bool  replace,
float  good_frac 
)

Definition at line 345 of file Shell.cc.

References h, mkfit::Event::layerHits_, m_event, python.rootplot.root2matplotlib::replace(), mkfit::Event::simHitsInfo_, summarizeEdmComparisonLogfiles::success, submitPVValidationJobs::t, and x.

Referenced by FillByLabelMaps_CkfBase().

345  {
346  std::map<int, int> lab_cnt;
347  for (int hi = 0; hi < t.nTotalHits(); ++hi) {
348  auto hot = t.getHitOnTrack(hi);
349  if (hot.index < 0)
350  continue;
351  const Hit &h = m_event->layerHits_[hot.layer][hot.index];
352  int hl = m_event->simHitsInfo_[h.mcHitID()].mcTrackID_;
353  if (hl >= 0)
354  ++lab_cnt[hl];
355  }
356  int max_c = -1, max_l = -1;
357  for (auto& x : lab_cnt) {
358  if (x.second > max_c) {
359  max_l = x.first;
360  max_c = x.second;
361  }
362  }
363  bool success = max_c >= good_frac * t.nFoundHits();
364  int relabel = success ? max_l : -1;
365  // printf("found_hits=%d, best_lab %d (%d hits), existing label=%d (replace flag=%s)\n",
366  // t.nFoundHits(), max_l, max_c, t.label(), b2a(replace));
367  if (replace)
368  t.setLabel(relabel);
369  return relabel;
370  }
def replace(string, replacements)
Definition: EPCuts.h:4
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
std::vector< HitVec > layerHits_
Definition: Event.h:70
Event * m_event
Definition: Shell.h:62
float x
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ NextEvent()

void mkfit::Shell::NextEvent ( int  skip = 1)

Definition at line 117 of file Shell.cc.

References mkfit::Event::evtID(), GoToEvent(), m_event, and optionsL1T::skip.

117  {
118  GoToEvent(m_event->evtID() + skip);
119  }
int evtID() const
Definition: Event.h:23
void GoToEvent(int eid)
Definition: Shell.cc:87
Event * m_event
Definition: Shell.h:62

◆ PrintIterations()

void mkfit::Shell::PrintIterations ( )

Definition at line 314 of file Shell.cc.

References mkfit::TrackBase::algoint_to_cstr(), hltPFPuppi_cfi::algos, mps_fire::i, and m_it_index.

314  {
315  printf("Shell::PrintIterations selected index = %d, %d iterations hardcoded as\n",
316  m_it_index, n_algos);
317  for (int i = 0; i < n_algos; ++i)
318  printf("%d %2d %s\n", i, algos[i], TrackBase::algoint_to_cstr(algos[i]));
319  }
static const char * algoint_to_cstr(int algo)
Definition: Track.cc:331
int m_it_index
Definition: Shell.h:66

◆ ProcessEvent()

void mkfit::Shell::ProcessEvent ( SeedSelect_e  seed_select = SS_UseAll,
int  selected_seed = -1,
int  count = 1 
)

Definition at line 121 of file Shell.cc.

References mkfit::MkBuilder::backwardFit(), mkfit::MkBuilder::begin_event(), mkfit::MkBuilder::beginBkwSearch(), builder(), mkfit::MkBuilder::compactifyHitStorageForBestCand(), submitPVResolutionJobs::count, mkfit::MkBuilder::end_event(), mkfit::MkBuilder::endBkwSearch(), eoh(), mkfit::MkBuilder::export_best_comb_cands(), mkfit::Event::fill_hitmask_bool_vectors(), mkfit::MkBuilder::filter_comb_cands(), mkfit::MkBuilder::find_tracks_load_seeds(), mkfit::MkBuilder::findTracksCloneEngine(), mps_fire::i, createfilelist::int, mkfit::SteeringParams::IT_BkwSearch, mkfit::Config::ItrInfo, mkfit::IterationConfig::m_backward_drop_seed_hits, m_backward_fit, mkfit::IterationConfig::m_backward_fit_min_hits, mkfit::IterationConfig::m_backward_search, m_builder, m_clean_seeds, mkfit::IterationConfig::m_duplicate_cleaner, m_eoh, m_event, m_it_index, mkfit::IterationMaskIfc::m_mask_vector, mkfit::IterationConfig::m_post_bkfit_filter, mkfit::IterationConfig::m_pre_bkfit_filter, m_remove_duplicates, mkfit::IterationConfig::m_requires_seed_hit_sorting, mkfit::IterationConfig::m_seed_cleaner, m_seeds, mkfit::IterationConfig::m_track_algorithm, m_tracks, mkfit::MkBuilder::ref_eocc(), mkfit::EventOfHits::refBeamSpot(), alignCSCRings::s, mkfit::MkBuilder::seed_post_cleaning(), seeds(), mkfit::Event::seedTracks_, mkfit::Event::setCurrentSeedTracks(), mkfit::EventOfCombCandidates::size(), SS_IndexPostCleaning, SS_IndexPreCleaning, SS_Label, SS_UseAll, and mkfit::Config::TrkInfo.

121  {
122  // count is only used for SS_IndexPreCleaning and SS_IndexPostCleaning.
123  // There are no checks for upper bounds, ie, if requested seeds beyond the first one exist.
124 
125  const IterationConfig &itconf = Config::ItrInfo[m_it_index];
126  IterationMaskIfc mask_ifc;
127  m_event->fill_hitmask_bool_vectors(itconf.m_track_algorithm, mask_ifc.m_mask_vector);
128 
129  m_seeds.clear();
130  m_tracks.clear();
131 
132  {
133  int n_algo = 0; // seeds are grouped by algo
134  for (auto &s : m_event->seedTracks_) {
135  if (s.algoint() == itconf.m_track_algorithm) {
136  if (seed_select == SS_UseAll || seed_select == SS_IndexPostCleaning) {
137  m_seeds.push_back(s);
138  } else if (seed_select == SS_Label && s.label() == selected_seed) {
139  m_seeds.push_back(s);
140  break;
141  } else if (seed_select == SS_IndexPreCleaning && n_algo >= selected_seed) {
142  m_seeds.push_back(s);
143  if (--count <= 0)
144  break;
145  }
146  ++n_algo;
147  } else if (n_algo > 0)
148  break;
149  }
150  }
151 
152  printf("Shell::ProcessEvent running over %d seeds\n", (int) m_seeds.size());
153 
154  // Equivalent to run_OneIteration(...) without MkBuilder::release_memory().
155  // If seed_select == SS_IndexPostCleaning the given seed is picked after cleaning.
156  {
157  const TrackerInfo &trackerInfo = Config::TrkInfo;
158  const EventOfHits &eoh = *m_eoh;
159  const IterationMaskIfcBase &it_mask_ifc = mask_ifc;
160  MkBuilder &builder = *m_builder;
162  TrackVec &out_tracks = m_tracks;
163  bool do_seed_clean = m_clean_seeds;
164  bool do_backward_fit = m_backward_fit;
165  bool do_remove_duplicates = m_remove_duplicates;
166 
167  MkJob job({trackerInfo, itconf, eoh, eoh.refBeamSpot(), &it_mask_ifc});
168 
169  builder.begin_event(&job, m_event, __func__);
170 
171  // Seed cleaning not done on all iterations.
172  do_seed_clean = m_clean_seeds && itconf.m_seed_cleaner;
173 
174  if (do_seed_clean) {
175  itconf.m_seed_cleaner(seeds, itconf, eoh.refBeamSpot());
176  printf("Shell::ProcessEvent post seed-cleaning: %d seeds\n", (int) m_seeds.size());
177  } else {
178  printf("Shell::ProcessEvent no seed-cleaning\n");
179  }
180 
181  // Check nans in seeds -- this should not be needed when Slava fixes
182  // the track parameter coordinate transformation.
184 
185  if (seed_select == SS_IndexPostCleaning) {
186  int seed_size = (int) seeds.size();
187  if (selected_seed >= 0 && selected_seed < seed_size) {
188  if (selected_seed + count >= seed_size) {
189  count = seed_size - selected_seed;
190  printf(" -- selected seed_index + count > seed vector size after cleaning -- trimming count to %d\n",
191  count);
192  }
193  for (int i = 0; i < count; ++i)
194  seeds[i] = seeds[selected_seed + i];
195  seeds.resize(count);
196  } else {
197  seeds.clear();
198  }
199  }
200 
201  if (seeds.empty()) {
202  if (seed_select != SS_UseAll)
203  printf("Shell::ProcessEvent requested seed not found among seeds of the selected iteration.\n");
204  else
205  printf("Shell::ProcessEvent no seeds found.\n");
206  return;
207  }
208 
209  if (itconf.m_requires_seed_hit_sorting) {
210  for (auto &s : seeds)
211  s.sortHitsByLayer(); // sort seed hits for the matched hits (I hope it works here)
212  }
213 
215 
216  builder.find_tracks_load_seeds(seeds, do_seed_clean);
217 
219 
220  printf("Shell::ProcessEvent post fwd search: %d comb-cands\n", builder.ref_eocc().size());
221 
222  // Pre backward-fit filtering.
223  filter_candidates_func pre_filter;
224  if (do_backward_fit && itconf.m_pre_bkfit_filter)
225  pre_filter = [&](const TrackCand &tc, const MkJob &jb) -> bool {
226  return itconf.m_pre_bkfit_filter(tc, jb) && StdSeq::qfilter_nan_n_silly<TrackCand>(tc, jb);
227  };
228  else if (itconf.m_pre_bkfit_filter)
229  pre_filter = itconf.m_pre_bkfit_filter;
230  else if (do_backward_fit)
231  pre_filter = StdSeq::qfilter_nan_n_silly<TrackCand>;
232  // pre_filter can be null if we are not doing backward fit as nan_n_silly will be run below.
233  if (pre_filter)
234  builder.filter_comb_cands(pre_filter, true);
235 
236  printf("Shell::ProcessEvent post pre-bkf-filter (%s) and nan-filter (%s) filter: %d comb-cands\n",
237  b2a(bool(itconf.m_pre_bkfit_filter)), b2a(do_backward_fit), builder.ref_eocc().size());
238 
239  job.switch_to_backward();
240 
241  if (do_backward_fit) {
242  if (itconf.m_backward_search) {
243  builder.compactifyHitStorageForBestCand(itconf.m_backward_drop_seed_hits, itconf.m_backward_fit_min_hits);
244  }
245 
247 
248  if (itconf.m_backward_search) {
251  }
252 
253  printf("Shell::ProcessEvent post backward fit / search: %d comb-cands\n", builder.ref_eocc().size());
254  }
255 
256  // Post backward-fit filtering.
257  filter_candidates_func post_filter;
258  if (do_backward_fit && itconf.m_post_bkfit_filter)
259  post_filter = [&](const TrackCand &tc, const MkJob &jb) -> bool {
260  return itconf.m_post_bkfit_filter(tc, jb) && StdSeq::qfilter_nan_n_silly<TrackCand>(tc, jb);
261  };
262  else
263  post_filter = StdSeq::qfilter_nan_n_silly<TrackCand>;
264  // post_filter is always at least doing nan_n_silly filter.
265  builder.filter_comb_cands(post_filter, true);
266 
267  printf("Shell::ProcessEvent post post-bkf-filter (%s) and nan-filter (true): %d comb-cands\n",
268  b2a(do_backward_fit && itconf.m_post_bkfit_filter), builder.ref_eocc().size());
269 
270  if (do_backward_fit && itconf.m_backward_search)
272 
273  builder.export_best_comb_cands(out_tracks, true);
274 
275  if (do_remove_duplicates && itconf.m_duplicate_cleaner) {
276  itconf.m_duplicate_cleaner(out_tracks, itconf);
277  }
278 
279  printf("Shell::ProcessEvent post remove-duplicates: %d comb-cands\n", (int) out_tracks.size());
280 
281  // Do not clear ... useful for debugging / printouts!
282  // m_event->resetCurrentSeedTracks();
283 
284  builder.end_event();
285  }
286 
287  printf("Shell::ProcessEvent found %d tracks, number of seeds at end %d\n",
288  (int) m_tracks.size(), (int) m_seeds.size());
289  }
const EventOfCombCandidates & ref_eocc() const
Definition: MkBuilder.h:74
TrackVec m_seeds
Definition: Shell.h:71
const BeamSpot & refBeamSpot() const
bool m_remove_duplicates
Definition: Shell.h:69
void compactifyHitStorageForBestCand(bool remove_seed_hits, int backward_fit_min_hits)
Definition: MkBuilder.h:63
TrackVec seedTracks_
Definition: Event.h:74
void findTracksCloneEngine(SteeringParams::IterationType_e iteration_dir=SteeringParams::IT_FwdSearch)
Definition: MkBuilder.cc:948
bool m_clean_seeds
Definition: Shell.h:67
void begin_event(MkJob *job, Event *ev, const char *build_type)
Definition: MkBuilder.cc:206
EventOfHits * eoh()
Definition: Shell.h:40
MkBuilder * m_builder
Definition: Shell.h:64
std::function< filter_candidates_cf > filter_candidates_func
Definition: FunctionTypes.h:28
EventOfHits * m_eoh
Definition: Shell.h:63
void find_tracks_load_seeds(const TrackVec &in_seeds, const bool seeds_sorted)
Definition: MkBuilder.cc:621
void setCurrentSeedTracks(const TrackVec &seeds)
Definition: Event.cc:868
const TrackVec & seeds() const
Definition: Shell.h:43
bool m_backward_fit
Definition: Shell.h:68
TrackerInfo TrkInfo
void seed_post_cleaning(TrackVec &tv)
Definition: MkBuilder.cc:419
void fill_hitmask_bool_vectors(int track_algo, std::vector< std::vector< bool >> &layer_masks)
Definition: Event.cc:822
IterationsInfo ItrInfo
MkBuilder * builder()
Definition: Shell.h:41
int filter_comb_cands(filter_candidates_func filter, bool attempt_all_cands)
Definition: MkBuilder.cc:313
TrackVec m_tracks
Definition: Shell.h:72
std::vector< Track > TrackVec
void beginBkwSearch()
Definition: MkBuilder.h:67
void export_best_comb_cands(TrackVec &out_vec, bool remove_missing_hits=false)
Definition: MkBuilder.cc:396
Event * m_event
Definition: Shell.h:62
int m_it_index
Definition: Shell.h:66
void endBkwSearch()
Definition: MkBuilder.h:68

◆ Run()

void mkfit::Shell::Run ( )

Definition at line 55 of file Shell.cc.

References dir2webdir::argc, GCPpyPlots::argv, visDQMUpload::buf, and beamvalidation::exit().

55  {
56 #ifndef NO_ROOT
57  std::vector<const char *> argv = { "mkFit", "-l" };
58  int argc = argv.size();
59  TRint rint("mkFit-shell", &argc, const_cast<char**>(argv.data()));
60 
61  char buf[256];
62  sprintf(buf, "mkfit::Shell &s = * (mkfit::Shell*) %p;", this);
63  gROOT->ProcessLine(buf);
64  printf("Shell &s variable is set\n");
65 
66  rint.Run(true);
67  printf("Shell::Run finished\n");
68 #else
69  printf("Shell::Run() no root, we rot -- erroring out. Recompile with WITH_ROOT=1\n");
70  exit(1);
71 #endif
72  }
def exit(msg="")

◆ seeds()

const TrackVec& mkfit::Shell::seeds ( ) const
inline

Definition at line 43 of file Shell.h.

References m_seeds.

Referenced by ProcessEvent().

43 { return m_seeds; }
TrackVec m_seeds
Definition: Shell.h:71

◆ SelectIterationAlgo()

void mkfit::Shell::SelectIterationAlgo ( int  algo)

Definition at line 303 of file Shell.cc.

References hltPFPuppi_cfi::algos, mps_fire::i, m_it_index, and submitPVResolutionJobs::stderr.

303  {
304  for (int i = 0; i < n_algos; ++i) {
305  if (algos[i] == algo) {
306  m_it_index = i;
307  return;
308  }
309  }
310  fprintf(stderr, "Requested algo %d not found", algo);
311  throw std::runtime_error("algo not found");
312  }
int m_it_index
Definition: Shell.h:66

◆ SelectIterationIndex()

void mkfit::Shell::SelectIterationIndex ( int  itidx)

Definition at line 295 of file Shell.cc.

References m_it_index, and submitPVResolutionJobs::stderr.

295  {
296  if (itidx < 0 || itidx >= n_algos) {
297  fprintf(stderr, "Requested iteration index out of range [%d, %d)", 0, n_algos);
298  throw std::runtime_error("iteration index out of range");
299  }
300  m_it_index = itidx;
301  }
int m_it_index
Definition: Shell.h:66

◆ SetBackwardFit()

void mkfit::Shell::SetBackwardFit ( bool  b)

Definition at line 327 of file Shell.cc.

References b, and m_backward_fit.

327 { m_backward_fit = b; }
bool m_backward_fit
Definition: Shell.h:68
double b
Definition: hdecay.h:120

◆ SetCleanSeeds()

void mkfit::Shell::SetCleanSeeds ( bool  b)

Definition at line 326 of file Shell.cc.

References b, and m_clean_seeds.

326 { m_clean_seeds = b; }
bool m_clean_seeds
Definition: Shell.h:67
double b
Definition: hdecay.h:120

◆ SetDebug()

void mkfit::Shell::SetDebug ( bool  b)

Definition at line 325 of file Shell.cc.

References b, and mkfit::g_debug.

325 { g_debug = b; }
bool g_debug
Definition: Debug.cc:2
double b
Definition: hdecay.h:120

◆ SetRemoveDuplicates()

void mkfit::Shell::SetRemoveDuplicates ( bool  b)

Definition at line 328 of file Shell.cc.

References b, and m_remove_duplicates.

328 { m_remove_duplicates = b; }
bool m_remove_duplicates
Definition: Shell.h:69
double b
Definition: hdecay.h:120

◆ SetUseDeadModules()

void mkfit::Shell::SetUseDeadModules ( bool  b)

Definition at line 329 of file Shell.cc.

References b, and mkfit::Config::useDeadModules.

double b
Definition: hdecay.h:120

◆ Status()

void mkfit::Shell::Status ( )

Definition at line 74 of file Shell.cc.

References mkfit::TrackBase::algoint_to_cstr(), hltPFPuppi_cfi::algos, mkfit::Event::evtID(), mkfit::g_debug, m_backward_fit, m_clean_seeds, m_event, m_it_index, m_remove_duplicates, and mkfit::Config::useDeadModules.

74  {
75  printf("On event %d, selected iteration index %d, algo %d - %s\n"
76  " debug = %s, use_dead_modules = %s\n"
77  " clean_seeds = %s, backward_fit = %s, remove_duplicates = %s\n",
81  }
bool m_remove_duplicates
Definition: Shell.h:69
int evtID() const
Definition: Event.h:23
bool m_clean_seeds
Definition: Shell.h:67
bool g_debug
Definition: Debug.cc:2
bool m_backward_fit
Definition: Shell.h:68
static const char * algoint_to_cstr(int algo)
Definition: Track.cc:331
Event * m_event
Definition: Shell.h:62
int m_it_index
Definition: Shell.h:66

◆ tracks()

const TrackVec& mkfit::Shell::tracks ( void  ) const
inline

Definition at line 44 of file Shell.h.

References m_tracks.

44 { return m_tracks; }
TrackVec m_tracks
Definition: Shell.h:72

Member Data Documentation

◆ m_backward_fit

bool mkfit::Shell::m_backward_fit = true
private

Definition at line 68 of file Shell.h.

Referenced by ProcessEvent(), SetBackwardFit(), Shell(), and Status().

◆ m_builder

MkBuilder* mkfit::Shell::m_builder = nullptr
private

Definition at line 64 of file Shell.h.

Referenced by builder(), ProcessEvent(), and Shell().

◆ m_ckf_map

std::map<int, Track *> mkfit::Shell::m_ckf_map
private

Definition at line 77 of file Shell.h.

Referenced by Compare(), and FillByLabelMaps_CkfBase().

◆ m_clean_seeds

bool mkfit::Shell::m_clean_seeds = true
private

Definition at line 67 of file Shell.h.

Referenced by ProcessEvent(), SetCleanSeeds(), and Status().

◆ m_data_file

DataFile* mkfit::Shell::m_data_file = nullptr
private

Definition at line 61 of file Shell.h.

Referenced by GoToEvent(), and Shell().

◆ m_deadvectors

std::vector<DeadVec>& mkfit::Shell::m_deadvectors
private

Definition at line 60 of file Shell.h.

Referenced by GoToEvent().

◆ m_eoh

EventOfHits* mkfit::Shell::m_eoh = nullptr
private

Definition at line 63 of file Shell.h.

Referenced by Compare(), eoh(), GoToEvent(), ProcessEvent(), and Shell().

◆ m_event

Event* mkfit::Shell::m_event = nullptr
private

◆ m_evs_in_file

int mkfit::Shell::m_evs_in_file = -1
private

Definition at line 65 of file Shell.h.

Referenced by GoToEvent(), and Shell().

◆ m_it_index

int mkfit::Shell::m_it_index = 0
private

◆ m_mkf_map

std::map<int, Track *> mkfit::Shell::m_mkf_map
private

Definition at line 77 of file Shell.h.

Referenced by Compare(), and FillByLabelMaps_CkfBase().

◆ m_remove_duplicates

bool mkfit::Shell::m_remove_duplicates = true
private

Definition at line 69 of file Shell.h.

Referenced by ProcessEvent(), SetRemoveDuplicates(), and Status().

◆ m_seed_map

std::map<int, Track *> mkfit::Shell::m_seed_map
private

Definition at line 77 of file Shell.h.

Referenced by Compare(), and FillByLabelMaps_CkfBase().

◆ m_seeds

TrackVec mkfit::Shell::m_seeds
private

Definition at line 71 of file Shell.h.

Referenced by Compare(), FillByLabelMaps_CkfBase(), ProcessEvent(), and seeds().

◆ m_sim_map

std::map<int, Track *> mkfit::Shell::m_sim_map
private

Definition at line 77 of file Shell.h.

Referenced by Compare(), and FillByLabelMaps_CkfBase().

◆ m_tracks

TrackVec mkfit::Shell::m_tracks
private

Definition at line 72 of file Shell.h.

Referenced by FillByLabelMaps_CkfBase(), ProcessEvent(), and tracks().