CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
mkfit::Event Class Reference

#include <Event.h>

Classes

struct  SimLabelFromHits
 

Public Member Functions

int clean_cms_seedtracks (TrackVec *seed_ptr=nullptr)
 
int clean_cms_seedtracks_badlabel ()
 
int clean_cms_simtracks ()
 
const TrackcurrentSeed (int i) const
 
 Event (int evtID, int nLayers)
 
 Event (Validation &v, int evtID, int nLayers)
 
int evtID () const
 
void fill_hitmask_bool_vectors (int track_algo, std::vector< std::vector< bool >> &layer_masks)
 
void fill_hitmask_bool_vectors (std::vector< int > &track_algo_vec, std::vector< std::vector< bool >> &layer_masks)
 
void kludge_cms_hit_errors ()
 
void print_tracks (const TrackVec &tracks, bool print_hits) const
 
void printStats (const TrackVec &, TrackExtraVec &)
 
void read_in (DataFile &data_file, FILE *in_fp=0)
 
int read_tracks (FILE *fp, TrackVec &tracks, bool skip_reading=false)
 
void relabel_bad_seedtracks ()
 
void relabel_cmsswtracks_from_seeds ()
 
void reset (int evtID)
 
void resetCurrentSeedTracks ()
 
void resetLayerHitMap (bool resetSimHits)
 
int select_tracks_iter (unsigned int n=0)
 
void setCurrentSeedTracks (const TrackVec &seeds)
 
void setInputFromCMSSW (std::vector< HitVec > hits, TrackVec seeds)
 
SimLabelFromHits simLabelForCurrentSeed (int i) const
 
int use_seeds_from_cmsswtracks ()
 
void validate ()
 
void write_out (DataFile &data_file)
 
int write_tracks (FILE *fp, const TrackVec &tracks)
 

Public Attributes

BeamSpot beamSpot_
 
TrackVec candidateTracks_
 
TrackExtraVec candidateTracksExtra_
 
TrackVec cmsswTracks_
 
TrackExtraVec cmsswTracksExtra_
 
TrackVec fitTracks_
 
TrackExtraVec fitTracksExtra_
 
std::vector< std::vector< uint64_t > > layerHitMasks_
 
std::vector< HitVeclayerHits_
 
TrackVec seedTracks_
 
TrackExtraVec seedTracksExtra_
 
MCHitInfoVec simHitsInfo_
 
TrackVec simTracks_
 
TrackExtraVec simTracksExtra_
 
TSVec simTrackStates_
 
Validationvalidation_
 

Static Public Attributes

static std::mutex printmutex
 

Private Attributes

std::vector< SimLabelFromHitscurrentSeedSimFromHits_
 
const TrackVeccurrentSeedTracks_ = nullptr
 
int evtID_
 

Detailed Description

Definition at line 14 of file Event.h.

Constructor & Destructor Documentation

◆ Event() [1/2]

Event::Event ( int  evtID,
int  nLayers 
)
explicit

Definition at line 22 of file Event.cc.

References layerHitMasks_, layerHits_, and MuonTCMETValueMapProducer_cff::nLayers.

22  : validation_(*dummyValidation), evtID_(evtID) {
23  layerHits_.resize(nLayers);
24  layerHitMasks_.resize(nLayers);
25  }
Validation & validation_
Definition: Event.h:50
int evtID() const
Definition: Event.h:23
std::vector< HitVec > layerHits_
Definition: Event.h:70
int evtID_
Definition: Event.h:64
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

◆ Event() [2/2]

Event::Event ( Validation v,
int  evtID,
int  nLayers 
)

Definition at line 27 of file Event.cc.

References layerHitMasks_, layerHits_, MuonTCMETValueMapProducer_cff::nLayers, mkfit::Validation::resetValidationMaps(), and validation_.

27  : validation_(v), evtID_(evtID) {
28  layerHits_.resize(nLayers);
29  layerHitMasks_.resize(nLayers);
30  validation_.resetValidationMaps(); // need to reset maps for every event.
31  }
Validation & validation_
Definition: Event.h:50
virtual void resetValidationMaps()
Definition: Validation.h:50
int evtID() const
Definition: Event.h:23
std::vector< HitVec > layerHits_
Definition: Event.h:70
int evtID_
Definition: Event.h:64
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

Member Function Documentation

◆ clean_cms_seedtracks()

int Event::clean_cms_seedtracks ( TrackVec seed_ptr = nullptr)

Definition at line 592 of file Event.cc.

References funct::abs(), mkfit::Config::c_dpt_common, mkfit::Config::c_drmax_brl, mkfit::Config::c_drmax_els, mkfit::Config::c_drmax_hpt, mkfit::Config::c_dzmax_brl, mkfit::Config::c_dzmax_els, mkfit::Config::c_dzmax_hpt, mkfit::Config::c_etamax_brl, mkfit::Config::c_ptmin_hpt, mkfit::cdist(), ALCARECOTkAlJpsiMuMu_cff::charge, mkfit::TrackBase::charge(), PVValHelper::eta, calostep_cfi::Eta1, f, mkfit::TrackBase::invpT(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, mkfit::TrackBase::momEta(), mkfit::TrackBase::momPhi(), mkfit::Track::nFoundHits(), nHits, funct::pow(), DiDispStaMuonMonitor_cfi::pt, mkfit::TrackBase::pT(), HLT_FULL_cff::seeds, seedTracks_, mathSSE::sqrt(), contentValuesCheck::ss, funct::tan(), mkfit::TrackBase::theta(), mkfit::Config::track1GeVradius, x, mkfit::TrackBase::x(), mkfit::TrackBase::y(), and mkfit::TrackBase::z().

592  {
593  const float etamax_brl = Config::c_etamax_brl;
594  const float dpt_common = Config::c_dpt_common;
595  const float dzmax_brl = Config::c_dzmax_brl;
596  const float drmax_brl = Config::c_drmax_brl;
597  const float ptmin_hpt = Config::c_ptmin_hpt;
598  const float dzmax_hpt = Config::c_dzmax_hpt;
599  const float drmax_hpt = Config::c_drmax_hpt;
600  const float dzmax_els = Config::c_dzmax_els;
601  const float drmax_els = Config::c_drmax_els;
602 
603  const float dzmax2_inv_brl = 1.f / (dzmax_brl * dzmax_brl);
604  const float drmax2_inv_brl = 1.f / (drmax_brl * drmax_brl);
605  const float dzmax2_inv_hpt = 1.f / (dzmax_hpt * dzmax_hpt);
606  const float drmax2_inv_hpt = 1.f / (drmax_hpt * drmax_hpt);
607  const float dzmax2_inv_els = 1.f / (dzmax_els * dzmax_els);
608  const float drmax2_inv_els = 1.f / (drmax_els * drmax_els);
609 
610  TrackVec &seeds = (seed_ptr != nullptr) ? *seed_ptr : seedTracks_;
611  const int ns = seeds.size();
612 
613  TrackVec cleanSeedTracks;
614  cleanSeedTracks.reserve(ns);
615  std::vector<bool> writetrack(ns, true);
616 
617  const float invR1GeV = 1.f / Config::track1GeVradius;
618 
619  std::vector<int> nHits(ns);
620  std::vector<int> charge(ns);
621  std::vector<float> oldPhi(ns);
622  std::vector<float> pos2(ns);
623  std::vector<float> eta(ns);
624  std::vector<float> ctheta(ns);
625  std::vector<float> invptq(ns);
626  std::vector<float> pt(ns);
627  std::vector<float> x(ns);
628  std::vector<float> y(ns);
629  std::vector<float> z(ns);
630 
631  for (int ts = 0; ts < ns; ts++) {
632  const Track &tk = seeds[ts];
633  nHits[ts] = tk.nFoundHits();
634  charge[ts] = tk.charge();
635  oldPhi[ts] = tk.momPhi();
636  pos2[ts] = std::pow(tk.x(), 2) + std::pow(tk.y(), 2);
637  eta[ts] = tk.momEta();
638  ctheta[ts] = 1.f / std::tan(tk.theta());
639  invptq[ts] = tk.charge() * tk.invpT();
640  pt[ts] = tk.pT();
641  x[ts] = tk.x();
642  y[ts] = tk.y();
643  z[ts] = tk.z();
644  }
645 
646  for (int ts = 0; ts < ns; ts++) {
647  if (not writetrack[ts])
648  continue; //FIXME: this speed up prevents transitive masking; check build cost!
649 
650  const float oldPhi1 = oldPhi[ts];
651  const float pos2_first = pos2[ts];
652  const float Eta1 = eta[ts];
653  const float Pt1 = pt[ts];
654  const float invptq_first = invptq[ts];
655 
656  //#pragma simd /* Vectorization via simd had issues with icc */
657  for (int tss = ts + 1; tss < ns; tss++) {
658  const float Pt2 = pt[tss];
659 
661  if (charge[tss] != charge[ts])
662  continue;
663 
664  const float thisDPt = std::abs(Pt2 - Pt1);
666  if (thisDPt > dpt_common * (Pt1))
667  continue;
668 
669  const float Eta2 = eta[tss];
670  const float deta2 = std::pow(Eta1 - Eta2, 2);
671 
672  const float oldPhi2 = oldPhi[tss];
673 
674  const float pos2_second = pos2[tss];
675  const float thisDXYSign05 = pos2_second > pos2_first ? -0.5f : 0.5f;
676 
677  const float thisDXY = thisDXYSign05 * sqrt(std::pow(x[ts] - x[tss], 2) + std::pow(y[ts] - y[tss], 2));
678 
679  const float invptq_second = invptq[tss];
680 
681  const float newPhi1 = oldPhi1 - thisDXY * invR1GeV * invptq_first;
682  const float newPhi2 = oldPhi2 + thisDXY * invR1GeV * invptq_second;
683 
684  const float dphi = cdist(std::abs(newPhi1 - newPhi2));
685 
686  const float dr2 = deta2 + dphi * dphi;
687 
688  const float thisDZ = z[ts] - z[tss] - thisDXY * (ctheta[ts] + ctheta[tss]);
689  const float dz2 = thisDZ * thisDZ;
690 
693  if (std::abs(Eta1) < etamax_brl) {
694  if (dz2 * dzmax2_inv_brl + dr2 * drmax2_inv_brl < 1.0f)
695  writetrack[tss] = false;
696  } else if (Pt1 > ptmin_hpt) {
697  if (dz2 * dzmax2_inv_hpt + dr2 * drmax2_inv_hpt < 1.0f)
698  writetrack[tss] = false;
699  } else {
700  if (dz2 * dzmax2_inv_els + dr2 * drmax2_inv_els < 1.0f)
701  writetrack[tss] = false;
702  }
703  }
704 
705  if (writetrack[ts])
706  cleanSeedTracks.emplace_back(seeds[ts]);
707  }
708 
709  seeds.swap(cleanSeedTracks);
710 
711 #ifdef DEBUG
712  {
713  const int ns2 = seeds.size();
714  printf("Number of CMS seeds before %d --> after %d cleaning\n", ns, ns2);
715 
716  for (int it = 0; it < ns2; it++) {
717  const Track &ss = seeds[it];
718  printf(" %3i q=%+i pT=%7.3f eta=% 7.3f nHits=%i label=% i\n",
719  it,
720  ss.charge(),
721  ss.pT(),
722  ss.momEta(),
723  ss.nFoundHits(),
724  ss.label());
725  }
726  }
727 #endif
728 
729  return seeds.size();
730  }
constexpr float c_drmax_els
Definition: Config.h:102
constexpr float c_dpt_common
Definition: Config.h:95
TrackVec seedTracks_
Definition: Event.h:74
float float float z
constexpr float c_dzmax_hpt
Definition: Config.h:99
constexpr float c_etamax_brl
Definition: Config.h:94
constexpr float c_ptmin_hpt
Definition: Config.h:98
T sqrt(T t)
Definition: SSEVec.h:19
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
float cdist(float a)
Definition: Config.h:32
std::vector< Track > TrackVec
constexpr float track1GeVradius
Definition: Config.h:93
constexpr float c_dzmax_els
Definition: Config.h:101
constexpr float c_dzmax_brl
Definition: Config.h:96
float x
constexpr float c_drmax_hpt
Definition: Config.h:100
constexpr float c_drmax_brl
Definition: Config.h:97
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ clean_cms_seedtracks_badlabel()

int Event::clean_cms_seedtracks_badlabel ( )

Definition at line 768 of file Event.cc.

References visDQMUpload::buf, seedTracks_, and submitPVValidationJobs::t.

768  {
769  printf("***\n*** REMOVING SEEDS WITH BAD LABEL. This is a development hack. ***\n***\n");
770  TrackVec buf;
771  seedTracks_.swap(buf);
772  std::copy_if(
773  buf.begin(), buf.end(), std::back_inserter(seedTracks_), [](const Track &t) { return t.label() >= 0; });
774  return seedTracks_.size();
775  }
TrackVec seedTracks_
Definition: Event.h:74
std::vector< Track > TrackVec

◆ clean_cms_simtracks()

int Event::clean_cms_simtracks ( )

Definition at line 511 of file Event.cc.

References mkfit::Config::cmsSelMinLayers, dprintf, mps_fire::i, simTracks_, and submitPVValidationJobs::t.

511  {
512  // Sim tracks from cmssw have the following issues:
513  // - hits are not sorted by layer;
514  // - there are tracks with too low number of hits, even 0;
515  // - even with enough hits, there can be too few layers (esp. in endcap);
516  // - tracks from secondaries can have extremely low pT.
517  // Possible further checks:
518  // - make sure enough hits exist in seeding layers.
519  //
520  // What is done:
521  // 1. Hits are sorted by layer;
522  // 2. Non-findable tracks are marked with Track::Status::not_findable flag.
523  //
524  // Returns number of passed simtracks.
525 
526  dprintf("Event::clean_cms_simtracks processing %lu simtracks.\n", simTracks_.size());
527 
528  int n_acc = 0;
529  int i = -1; //wrap in ifdef DEBUG?
530  for (Track &t : simTracks_) {
531  i++;
532 
533  t.sortHitsByLayer();
534 
535  const int lyr_cnt = t.nUniqueLayers();
536 
537  //const int lasthit = t.getLastFoundHitPos();
538  //const float eta = layerHits_[t.getHitLyr(lasthit)][t.getHitIdx(lasthit)].eta();
539 
540  if (lyr_cnt < Config::cmsSelMinLayers) // || Config::TrkInfo.is_transition(eta))
541  {
542  dprintf("Rejecting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, t.nFoundHits(), lyr_cnt, t.pT());
543  t.setNotFindable();
544  } else {
545  dprintf("Accepting simtrack %d, n_hits=%d, n_layers=%d, pT=%f\n", i, t.nFoundHits(), lyr_cnt, t.pT());
546  ++n_acc;
547  }
548  }
549 
550  return n_acc;
551  }
TrackVec simTracks_
Definition: Event.h:74
#define dprintf(...)
Definition: Debug.h:98

◆ currentSeed()

const Track & Event::currentSeed ( int  i) const

Definition at line 866 of file Event.cc.

References currentSeedTracks_, and mps_fire::i.

Referenced by mkfit::MkFinder::selectHitIndices(), and simLabelForCurrentSeed().

866 { return (*currentSeedTracks_)[i]; }
const TrackVec * currentSeedTracks_
Definition: Event.h:65

◆ evtID()

int mkfit::Event::evtID ( ) const
inline

◆ fill_hitmask_bool_vectors() [1/2]

void Event::fill_hitmask_bool_vectors ( int  track_algo,
std::vector< std::vector< bool >> &  layer_masks 
)

Definition at line 819 of file Event.cc.

References mps_fire::i, createfilelist::int, MainPageGenerator::l, layerHitMasks_, and layerHits_.

Referenced by mkfit::Shell::ProcessEvent().

819  {
820  // Convert from per-hit uint64_t to per layer bool-vectors for given
821  // iteration.
822 
823  uint64_t iter_mask = 1 << track_algo;
824 
825  const int n_lay = (int)layerHits_.size();
826  layer_masks.resize(n_lay);
827 
828  for (int l = 0; l < n_lay; ++l) {
829  const int n_hit = (int)layerHits_[l].size();
830  layer_masks[l].resize(n_hit);
831 
832  for (int i = 0; i < n_hit; ++i) {
833  layer_masks[l][i] = layerHitMasks_[l][i] & iter_mask;
834  }
835  }
836  }
size
Write out results.
std::vector< HitVec > layerHits_
Definition: Event.h:70
unsigned long long uint64_t
Definition: Time.h:13
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

◆ fill_hitmask_bool_vectors() [2/2]

void Event::fill_hitmask_bool_vectors ( std::vector< int > &  track_algo_vec,
std::vector< std::vector< bool >> &  layer_masks 
)

Definition at line 838 of file Event.cc.

References mps_fire::i, createfilelist::int, MainPageGenerator::l, layerHitMasks_, and layerHits_.

838  {
839  // Convert from per-hit uint64_t to per layer bool-vectors for a list of
840  // iterations.
841  // A hit mask is set if it is set for _all_ listed iterations.
842 
843  uint64_t iter_mask = 0;
844  for (auto ta : track_algo_vec)
845  iter_mask |= 1 << ta;
846 
847  const int n_lay = (int)layerHits_.size();
848  layer_masks.resize(n_lay);
849 
850  for (int l = 0; l < n_lay; ++l) {
851  const int n_hit = (int)layerHits_[l].size();
852  layer_masks[l].resize(n_hit);
853 
854  for (int i = 0; i < n_hit; ++i) {
855  uint64_t hitmasks = layerHitMasks_[l][i];
856  layer_masks[l][i] = ((iter_mask ^ hitmasks) & iter_mask) == 0;
857  }
858  }
859  }
size
Write out results.
std::vector< HitVec > layerHits_
Definition: Event.h:70
unsigned long long uint64_t
Definition: Time.h:13
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

◆ kludge_cms_hit_errors()

void Event::kludge_cms_hit_errors ( )

Definition at line 476 of file Event.cc.

References HltBtagPostValidation_cff::c, MillePedeFileConverter_cfg::e, relativeConstraints::empty, h, and layerHits_.

Referenced by read_in().

476  {
477  // Enforce Vxy on all layers, Vz on pixb only.
478 
479  const float Exy = 15 * 1e-4, Vxy = Exy * Exy;
480  const float Ez = 30 * 1e-4, Vz = Ez * Ez;
481 
482  int nl = layerHits_.size();
483 
484  int cnt = 0;
485 
486  for (int il = 0; il < nl; il++) {
487  if (layerHits_[il].empty())
488  continue;
489 
490  for (Hit &h : layerHits_[il]) {
491  SVector6 &c = h.error_nc();
492 
493  float vxy = c[0] + c[2];
494  if (vxy < Vxy) {
495  c[0] *= Vxy / vxy;
496  c[2] *= Vxy / vxy;
497  ++cnt;
498  }
499  if (il < 4 && c[5] < Vz) {
500  c[5] = Vz;
501  ++cnt;
502  }
503  }
504  }
505 
506  printf("Event::kludge_cms_hit_errors processed %d layers, kludged %d entries.\n", nl, cnt);
507  }
std::vector< HitVec > layerHits_
Definition: Event.h:70
ROOT::Math::SVector< float, 6 > SVector6
Definition: MatrixSTypes.h:10
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ print_tracks()

void Event::print_tracks ( const TrackVec tracks,
bool  print_hits 
) const

Definition at line 553 of file Event.cc.

References mkfit::IterationConfig::get_track_scorer(), mkfit::getScoreCand(), heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, layerHits_, nt, simHitsInfo_, submitPVValidationJobs::t, and DiMuonV_cfg::tracks.

553  {
554  const int nt = tracks.size();
555  auto score_func = IterationConfig::get_track_scorer("default");
556  //WARNING: Printouts for hits will not make any sense if mkFit is not run with a validation flag such as --quality-val
557  printf("Event::print_tracks printing %d tracks %s hits:\n", nt, (print_hits ? "with" : "without"));
558  for (int it = 0; it < nt; it++) {
559  const Track &t = tracks[it];
560  printf(" %i with q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d findable=%d score=%7.3f chi2=%7.3f\n",
561  it,
562  t.charge(),
563  t.pT(),
564  t.momEta(),
565  t.nFoundHits(),
566  t.label(),
567  t.isFindable(),
568  getScoreCand(score_func, t),
569  t.chi2());
570 
571  if (print_hits) {
572  for (int ih = 0; ih < t.nTotalHits(); ++ih) {
573  int lyr = t.getHitLyr(ih);
574  int idx = t.getHitIdx(ih);
575  if (idx >= 0) {
576  const Hit &hit = layerHits_[lyr][idx];
577  printf(" hit %2d lyr=%2d idx=%3d pos r=%7.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n",
578  ih,
579  lyr,
580  idx,
581  layerHits_[lyr][idx].r(),
582  layerHits_[lyr][idx].z(),
583  hit.mcHitID(),
584  hit.mcTrackID(simHitsInfo_));
585  } else
586  printf(" hit %2d lyr=%2d idx=%3d\n", ih, t.getHitLyr(ih), t.getHitIdx(ih));
587  }
588  }
589  }
590  }
float getScoreCand(const track_score_func &score_func, const Track &cand1, bool penalizeTailMissHits=false, bool inFindCandidates=false)
Definition: Track.h:615
float float float z
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
int nt
Definition: AMPTWrapper.h:42
std::vector< HitVec > layerHits_
Definition: Event.h:70
static track_score_func get_track_scorer(const std::string &name)

◆ printStats()

void Event::printStats ( const TrackVec trks,
TrackExtraVec trkextras 
)

Definition at line 91 of file Event.cc.

References gather_cfg::cout, newFWLiteAna::found, layerHits_, simHitsInfo_, simTracks_, and hltEgammaHLTExtra_cfi::trks.

91  {
92  int miss(0), found(0), fp_10(0), fp_20(0), hit8(0), h8_10(0), h8_20(0);
93 
94  for (auto &&trk : trks) {
95  auto &&extra = trkextras[trk.label()];
96  extra.setMCTrackIDInfo(trk, layerHits_, simHitsInfo_, simTracks_, false, true);
97  if (extra.mcTrackID() < 0) {
98  ++miss;
99  } else {
100  auto &&mctrk = simTracks_[extra.mcTrackID()];
101  auto pr = trk.pT() / mctrk.pT();
102  found++;
103  bool h8 = trk.nFoundHits() >= 8;
104  bool pt10 = pr > 0.9 && pr < 1.1;
105  bool pt20 = pr > 0.8 && pr < 1.2;
106  fp_10 += pt10;
107  fp_20 += pt20;
108  hit8 += h8;
109  h8_10 += h8 && pt10;
110  h8_20 += h8 && pt20;
111  }
112  }
113  std::cout << "found tracks=" << found << " in pT 10%=" << fp_10 << " in pT 20%=" << fp_20
114  << " no_mc_assoc=" << miss << std::endl
115  << " nH >= 8 =" << hit8 << " in pT 10%=" << h8_10 << " in pT 20%=" << h8_20 << std::endl;
116  }
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
std::vector< HitVec > layerHits_
Definition: Event.h:70
TrackVec simTracks_
Definition: Event.h:74

◆ read_in()

void Event::read_in ( DataFile data_file,
FILE *  in_fp = 0 
)

Definition at line 207 of file Event.cc.

References mkfit::DataFile::advancePosToNextEvent(), beamSpot_, mkfit::cmsswSeeds, cmsswTracks_, dumpMFGeometry_cfg::delta, relativeConstraints::empty, mkfit::DataFile::f_fp, personalPlayback::fp, mkfit::ModuleInfo::half_length, mkfit::DataFile::hasBeamSpot(), mkfit::DataFile::hasCmsswTracks(), mkfit::DataFile::hasHitIterMasks(), mkfit::DataFile::hasSeeds(), mkfit::DataFile::hasSimTrackStates(), heavyIonCSV_trainingSettings::idx, createfilelist::int, mkfit::LayerInfo::is_barrel(), mkfit::LayerInfo::is_pixel(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, kludge_cms_hit_errors(), mkfit::Config::kludgeCmsHitErrors, layerHitMasks_, layerHits_, SiStripPI::max, SiStripPI::min, mkfit::LayerInfo::module_info(), cms::cuda::nh, nt, mkfit::Config::nTracks, read_tracks(), mkfit::Config::readCmsswTracks, mkfit::Config::seedInput, seedTracks_, mkfit::Config::silent, simHitsInfo_, simTracks_, simTrackStates_, mathSSE::sqrt(), contentValuesCheck::ss, submitPVValidationJobs::t, mkfit::Config::TrkInfo, funct::void, x, hit::x, hit::y, and hit::z.

Referenced by mkfit::Shell::GoToEvent().

207  {
208  FILE *fp = in_fp ? in_fp : data_file.f_fp;
209 
210  data_file.advancePosToNextEvent(fp);
211 
212  int nt = read_tracks(fp, simTracks_);
214 
215  if (data_file.hasSimTrackStates()) {
216  int nts;
217  fread(&nts, sizeof(int), 1, fp);
218  simTrackStates_.resize(nts);
219  fread(&simTrackStates_[0], sizeof(TrackState), nts, fp);
220  }
221 
222  int nl;
223  fread(&nl, sizeof(int), 1, fp);
224  layerHits_.resize(nl);
225  layerHitMasks_.resize(nl);
226  for (int il = 0; il < nl; ++il) {
227  int nh;
228  fread(&nh, sizeof(int), 1, fp);
229  layerHits_[il].resize(nh);
230  layerHitMasks_[il].resize(nh, 0); //init to 0 by default
231  fread(&layerHits_[il][0], sizeof(Hit), nh, fp);
232  }
233 
234  if (data_file.hasHitIterMasks()) {
235  for (int il = 0; il < nl; ++il) {
236  int nh = layerHits_[il].size();
237  fread(&layerHitMasks_[il][0], sizeof(uint64_t), nh, fp);
238  }
239  }
240 
241  int nm;
242  fread(&nm, sizeof(int), 1, fp);
243  simHitsInfo_.resize(nm);
244  fread(&simHitsInfo_[0], sizeof(MCHitInfo), nm, fp);
245 
246  if (data_file.hasSeeds()) {
248  (void)ns;
249 
250 #ifdef DUMP_SEEDS
251  printf("Read %i seedtracks (neg value means actual reading was skipped)\n", ns);
252  for (int it = 0; it < ns; it++) {
253  const Track &ss = seedTracks_[it];
254  printf(" %-3i q=%+i pT=%7.3f eta=% 7.3f nHits=%i label=%4i algo=%2i\n",
255  it,
256  ss.charge(),
257  ss.pT(),
258  ss.momEta(),
259  ss.nFoundHits(),
260  ss.label(),
261  (int)ss.algorithm());
262 #ifdef DUMP_SEED_HITS
263  for (int ih = 0; ih < seedTracks_[it].nTotalHits(); ++ih) {
264  int lyr = seedTracks_[it].getHitLyr(ih);
265  int idx = seedTracks_[it].getHitIdx(ih);
266  if (idx >= 0) {
267  const Hit &hit = layerHits_[lyr][idx];
268  printf(" hit %2d lyr=%3d idx=%4d pos r=%7.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n",
269  ih,
270  lyr,
271  idx,
272  layerHits_[lyr][idx].r(),
273  layerHits_[lyr][idx].z(),
274  hit.mcHitID(),
275  hit.mcTrackID(simHitsInfo_));
276  } else
277  printf(" hit %2d idx=%i\n", ih, seedTracks_[it].getHitIdx(ih));
278  }
279 #endif
280  }
281 #endif
282  }
283 
284  int nert = -99999;
285  if (data_file.hasCmsswTracks()) {
287  (void)nert;
288  }
289 
290  /*
291  // HACK TO ONLY SELECT ONE PROBLEMATIC TRACK.
292  // Note that MC matching gets screwed.
293  // Works for MC seeding.
294  //
295  printf("************** SIM SELECTION HACK IN FORCE ********************\n");
296  TrackVec x;
297  x.push_back(simTracks_[3]);
298  simTracks_.swap(x);
299  nt = 1;
300  */
301 
302 #ifdef DUMP_TRACKS
303  printf("Read %i simtracks\n", nt);
304  for (int it = 0; it < nt; it++) {
305  const Track &t = simTracks_[it];
306  printf(" %-3i q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d\n",
307  it,
308  t.charge(),
309  t.pT(),
310  t.momEta(),
311  t.nFoundHits(),
312  t.label());
313 #ifdef DUMP_TRACK_HITS
314  for (int ih = 0; ih < t.nTotalHits(); ++ih) {
315  int lyr = t.getHitLyr(ih);
316  int idx = t.getHitIdx(ih);
317  if (idx >= 0) {
318  const Hit &hit = layerHits_[lyr][idx];
319  printf(" hit %2d lyr=%2d idx=%3d pos r=%7.3f x=% 8.3f y=% 8.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n",
320  ih,
321  lyr,
322  idx,
323  layerHits_[lyr][idx].r(),
324  layerHits_[lyr][idx].x(),
325  layerHits_[lyr][idx].y(),
326  layerHits_[lyr][idx].z(),
327  hit.mcHitID(),
328  hit.mcTrackID(simHitsInfo_));
329  } else
330  printf(" hit %2d idx=%i\n", ih, t.getHitIdx(ih));
331  }
332 #endif
333  }
334 #endif
335 #ifdef DUMP_LAYER_HITS
336  // clang-format off
337  printf("Read %i layers\n", nl);
338  int total_hits = 0;
339  float min_delta = 100, max_delta = -100;
340  for (int il = 0; il < nl; il++) {
341  if (layerHits_[il].empty())
342  continue;
343 
344  printf("Read %i hits in layer %i\n", (int)layerHits_[il].size(), il);
345  total_hits += layerHits_[il].size();
346  for (int ih = 0; ih < (int)layerHits_[il].size(); ih++) {
347  const Hit &hit = layerHits_[il][ih];
348  const LayerInfo &linfo = Config::TrkInfo[il];
349  unsigned int mid = hit.detIDinLayer();
350  const ModuleInfo &mi = linfo.module_info(mid);
351 
352  if ( ! linfo.is_pixel() && ! linfo.is_barrel()) {
353  float delta = mi.half_length - std::sqrt(3)*std::sqrt(hit.exx() + hit.eyy());
354  min_delta = std::min(min_delta, delta);
355  max_delta = std::max(max_delta, delta);
356  }
357  // continue;
358 
359  printf(" mcHitID=%5d r=%10g x=%10g y=%10g z=%10g"
360  " sx=%10.4g sy=%10.4e sz=%10.4e sxy=%10.4e, mhl=%10.4e, delta=%10.4e\n",
361  hit.mcHitID(), hit.r(), hit.x(), hit.y(), hit.z(),
362  std::sqrt(hit.exx()), std::sqrt(hit.eyy()), std::sqrt(hit.ezz()),
363  std::sqrt(hit.exx() + hit.eyy()),
364  mi.half_length,
365  mi.half_length - std::sqrt(3)*std::sqrt(hit.exx() + hit.eyy()));
366  }
367  }
368  printf("Total hits in all layers = %d; endcap strips: min_delta=%.5f max_delta=%.5f\n",
369  total_hits, min_delta, max_delta);
370  // clang-format on
371 #endif
372 #ifdef DUMP_REC_TRACKS
373  printf("Read %i rectracks\n", nert);
374  for (int it = 0; it < nert; it++) {
375  const Track &t = cmsswTracks_[it];
376  printf(" %-3i with q=%+i pT=%7.3f eta=% 7.3f nHits=%2d label=%4d algo=%2d\n",
377  it,
378  t.charge(),
379  t.pT(),
380  t.momEta(),
381  t.nFoundHits(),
382  t.label(),
383  (int)t.algorithm());
384 #ifdef DUMP_REC_TRACK_HITS
385  for (int ih = 0; ih < t.nTotalHits(); ++ih) {
386  int lyr = t.getHitLyr(ih);
387  int idx = t.getHitIdx(ih);
388  if (idx >= 0) {
389  const Hit &hit = layerHits_[lyr][idx];
390  printf(" hit %2d lyr=%2d idx=%3d pos r=%7.3f z=% 8.3f mc_hit=%3d mc_trk=%3d\n",
391  ih,
392  lyr,
393  idx,
394  hit.r(),
395  hit.z(),
396  hit.mcHitID(),
397  hit.mcTrackID(simHitsInfo_));
398  } else
399  printf(" hit %2d idx=%i\n", ih, t.getHitIdx(ih));
400  }
401 #endif
402  }
403 #endif
404 
405  if (data_file.hasBeamSpot()) {
406  fread(&beamSpot_, sizeof(BeamSpot), 1, fp);
407  }
408 
411  }
412 
413  if (!Config::silent)
414  printf("Read complete, %d simtracks on file.\n", nt);
415  }
size
Write out results.
void kludge_cms_hit_errors()
Definition: Event.cc:476
TrackVec cmsswTracks_
Definition: Event.h:75
TrackVec seedTracks_
Definition: Event.h:74
float float float z
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
BeamSpot beamSpot_
Definition: Event.h:69
T sqrt(T t)
Definition: SSEVec.h:19
TrackerInfo TrkInfo
uint32_t nh
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
int nt
Definition: AMPTWrapper.h:42
std::vector< HitVec > layerHits_
Definition: Event.h:70
TrackVec simTracks_
Definition: Event.h:74
TSVec simTrackStates_
Definition: Event.h:80
unsigned long long uint64_t
Definition: Time.h:13
float x
int read_tracks(FILE *fp, TrackVec &tracks, bool skip_reading=false)
Definition: Event.cc:443
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

◆ read_tracks()

int Event::read_tracks ( FILE *  fp,
TrackVec tracks,
bool  skip_reading = false 
)

Definition at line 443 of file Event.cc.

References personalPlayback::fp, mps_fire::i, and DiMuonV_cfg::tracks.

Referenced by read_in().

443  {
444  // Returns number of read tracks (negative if actual reading was skipped).
445 
446  int n_tracks, data_size;
447  fread(&n_tracks, sizeof(int), 1, fp);
448  fread(&data_size, sizeof(int), 1, fp);
449 
450  if (skip_reading) {
451  fseek(fp, data_size - 2 * sizeof(int), SEEK_CUR); // -2 because data_size counts itself and n_tracks too
452  n_tracks = -n_tracks;
453  } else {
454  tracks.resize(n_tracks);
455 
456  fread(tracks.data(), sizeof(Track), n_tracks, fp);
457 
458  for (int i = 0; i < n_tracks; ++i) {
459  tracks[i].resizeHitsForInput();
460  fread(tracks[i].beginHitsOnTrack_nc(), sizeof(HitOnTrack), tracks[i].nTotalHits(), fp);
461  }
462  }
463 
464  return n_tracks;
465  }

◆ relabel_bad_seedtracks()

void Event::relabel_bad_seedtracks ( )

Definition at line 792 of file Event.cc.

References seedTracks_, and HLT_2023v12_cff::track.

792  {
793  int newlabel = 0;
794  for (auto &&track : seedTracks_) {
795  if (track.label() < 0)
796  track.setLabel(--newlabel);
797  }
798  }
TrackVec seedTracks_
Definition: Event.h:74

◆ relabel_cmsswtracks_from_seeds()

void Event::relabel_cmsswtracks_from_seeds ( )

Definition at line 800 of file Event.cc.

References cmsswTracks_, iseed, label, and seedTracks_.

800  {
801  std::map<int, int> cmsswLabelMap;
802  for (size_t iseed = 0; iseed < seedTracks_.size(); iseed++) {
803  for (size_t icmssw = 0; icmssw < cmsswTracks_.size(); icmssw++) {
804  if (cmsswTracks_[icmssw].label() == static_cast<int>(iseed)) {
805  cmsswLabelMap[icmssw] = seedTracks_[iseed].label();
806  break;
807  }
808  }
809  }
810  for (size_t icmssw = 0; icmssw < cmsswTracks_.size(); icmssw++) {
811  cmsswTracks_[icmssw].setLabel(cmsswLabelMap[icmssw]);
812  }
813  }
TrackVec cmsswTracks_
Definition: Event.h:75
TrackVec seedTracks_
Definition: Event.h:74
char const * label
int iseed
Definition: AMPTWrapper.h:134

◆ reset()

void Event::reset ( int  evtID)

Definition at line 33 of file Event.cc.

References beamSpot_, candidateTracks_, candidateTracksExtra_, cmsswTracks_, cmsswTracksExtra_, evtID(), evtID_, fitTracks_, fitTracksExtra_, MainPageGenerator::l, layerHitMasks_, layerHits_, mkfit::Validation::resetValidationMaps(), seedTracks_, seedTracksExtra_, simHitsInfo_, simTracks_, simTracksExtra_, simTrackStates_, and validation_.

Referenced by mkfit::Shell::GoToEvent().

33  {
34  evtID_ = evtID;
35 
36  for (auto &&l : layerHits_) {
37  l.clear();
38  }
39  for (auto &&l : layerHitMasks_) {
40  l.clear();
41  }
42 
43  simHitsInfo_.clear();
44  simTrackStates_.clear();
45  simTracks_.clear();
46  simTracksExtra_.clear();
47  seedTracks_.clear();
48  seedTracksExtra_.clear();
49  candidateTracks_.clear();
50  candidateTracksExtra_.clear();
51  fitTracks_.clear();
52  fitTracksExtra_.clear();
53  cmsswTracks_.clear();
54  cmsswTracksExtra_.clear();
55  beamSpot_ = {};
56 
57  validation_.resetValidationMaps(); // need to reset maps for every event.
58  }
Validation & validation_
Definition: Event.h:50
virtual void resetValidationMaps()
Definition: Validation.h:50
TrackVec cmsswTracks_
Definition: Event.h:75
TrackExtraVec candidateTracksExtra_
Definition: Event.h:77
TrackVec seedTracks_
Definition: Event.h:74
int evtID() const
Definition: Event.h:23
BeamSpot beamSpot_
Definition: Event.h:69
TrackExtraVec cmsswTracksExtra_
Definition: Event.h:78
TrackExtraVec simTracksExtra_
Definition: Event.h:77
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
std::vector< HitVec > layerHits_
Definition: Event.h:70
TrackVec simTracks_
Definition: Event.h:74
TSVec simTrackStates_
Definition: Event.h:80
int evtID_
Definition: Event.h:64
TrackExtraVec fitTracksExtra_
Definition: Event.h:77
TrackExtraVec seedTracksExtra_
Definition: Event.h:77
TrackVec fitTracks_
Definition: Event.h:74
TrackVec candidateTracks_
Definition: Event.h:74
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

◆ resetCurrentSeedTracks()

void Event::resetCurrentSeedTracks ( )

Definition at line 910 of file Event.cc.

References currentSeedSimFromHits_, and currentSeedTracks_.

Referenced by mkfit::Shell::ProcessEvent().

910  {
911  currentSeedTracks_ = nullptr;
912  currentSeedSimFromHits_.clear();
913  }
const TrackVec * currentSeedTracks_
Definition: Event.h:65
std::vector< SimLabelFromHits > currentSeedSimFromHits_
Definition: Event.h:66

◆ resetLayerHitMap()

void mkfit::Event::resetLayerHitMap ( bool  resetSimHits)

◆ select_tracks_iter()

int Event::select_tracks_iter ( unsigned int  n = 0)

Definition at line 732 of file Event.cc.

References mkfit::TrackBase::algorithm(), analysisFilters_cff::algorithms, cmsswTracks_, spr::find(), createfilelist::int, dqmiodumpmetadata::n, nt, and seedTracks_.

732  {
733  if (n == 0)
734  return 1;
735 
736  unsigned int algorithms[] = {4, 22, 23, 5, 24, 7, 8, 9, 10, 6}; //to be stored somewhere common
737 
738  //saving seeds by algorithm
739  const int ns = seedTracks_.size();
740 
741  TrackVec cleanSeedTracks;
742  cleanSeedTracks.reserve(ns);
743 
744  for (int ts = 0; ts < ns; ts++) {
745  const Track &tk = seedTracks_[ts];
746  unsigned int algo = (unsigned int)tk.algorithm();
748  cleanSeedTracks.emplace_back(seedTracks_[ts]);
749  }
750  seedTracks_.swap(cleanSeedTracks);
751 
752  //saving tracks by algorithm
753  const int nt = cmsswTracks_.size();
754 
755  TrackVec cleanTracks;
756  cleanTracks.reserve(nt);
757 
758  for (int ts = 0; ts < nt; ts++) {
759  const Track &tk = cmsswTracks_[ts];
760  unsigned int algo = (unsigned int)tk.algorithm();
762  cleanTracks.emplace_back(cmsswTracks_[ts]);
763  }
764  cmsswTracks_.swap(cleanTracks);
765  return cmsswTracks_.size() + seedTracks_.size();
766  }
TrackVec cmsswTracks_
Definition: Event.h:75
TrackVec seedTracks_
Definition: Event.h:74
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int nt
Definition: AMPTWrapper.h:42
std::vector< Track > TrackVec

◆ setCurrentSeedTracks()

void Event::setCurrentSeedTracks ( const TrackVec seeds)

Definition at line 865 of file Event.cc.

References currentSeedTracks_, and HLT_FULL_cff::seeds.

Referenced by mkfit::Shell::ProcessEvent().

const TrackVec * currentSeedTracks_
Definition: Event.h:65

◆ setInputFromCMSSW()

void Event::setInputFromCMSSW ( std::vector< HitVec hits,
TrackVec  seeds 
)

Definition at line 469 of file Event.cc.

References hfClusterShapes_cfi::hits, layerHits_, eostools::move(), HLT_FULL_cff::seeds, and seedTracks_.

469  {
472  }
TrackVec seedTracks_
Definition: Event.h:74
std::vector< HitVec > layerHits_
Definition: Event.h:70
def move(src, dest)
Definition: eostools.py:511

◆ simLabelForCurrentSeed()

Event::SimLabelFromHits Event::simLabelForCurrentSeed ( int  i) const

Definition at line 868 of file Event.cc.

References cms::cuda::assert(), currentSeed(), currentSeedSimFromHits_, currentSeedTracks_, h, mps_fire::i, createfilelist::int, layerHits_, alignCSCRings::s, simHitsInfo_, and x.

Referenced by mkfit::MkFinder::selectHitIndices(), and mkfit::MkFinder::selectHitIndicesV2().

868  {
869  assert(currentSeedTracks_ != nullptr);
870 
871  if (currentSeedSimFromHits_.empty()) {
873 
874  for (int si = 0; si < (int)currentSeedTracks_->size(); ++si) {
875  const Track &s = currentSeed(si);
876  // printf("%3d (%d): [", si, s.label());
877  std::map<int, int> lab_cnt;
878  for (int hi = 0; hi < s.nTotalHits(); ++hi) {
879  auto hot = s.getHitOnTrack(hi);
880  // printf(" %d", hot.index);
881  if (hot.index < 0)
882  continue;
883  const Hit &h = layerHits_[hot.layer][hot.index];
884  int hl = simHitsInfo_[h.mcHitID()].mcTrackID_;
885  // printf(" (%d)", hl);
886  if (hl >= 0)
887  ++lab_cnt[hl];
888  }
889  int max_c = -1, max_l = -1;
890  for (auto &x : lab_cnt) {
891  if (x.second > max_c) {
892  max_l = x.first;
893  max_c = x.second;
894  } else if (x.second == max_c) {
895  max_l = -1;
896  }
897  }
898  if (max_c < 0) {
899  max_c = 0;
900  max_l = -1;
901  }
902  // printf(" ] -> %d %d => %d\n", s.nTotalHits(), max_c, max_l);
903  currentSeedSimFromHits_[si] = {s.nTotalHits(), max_c, max_l};
904  }
905  }
906 
907  return currentSeedSimFromHits_[i];
908  }
const TrackVec * currentSeedTracks_
Definition: Event.h:65
assert(be >=bs)
Definition: EPCuts.h:4
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
std::vector< HitVec > layerHits_
Definition: Event.h:70
const Track & currentSeed(int i) const
Definition: Event.cc:866
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
std::vector< SimLabelFromHits > currentSeedSimFromHits_
Definition: Event.h:66

◆ use_seeds_from_cmsswtracks()

int Event::use_seeds_from_cmsswtracks ( )

Definition at line 777 of file Event.cc.

References cmsswTracks_, and seedTracks_.

777  {
778  int ns = seedTracks_.size();
779 
780  TrackVec cleanSeedTracks;
781  cleanSeedTracks.reserve(ns);
782 
783  for (auto &&cmsswtrack : cmsswTracks_) {
784  cleanSeedTracks.emplace_back(seedTracks_[cmsswtrack.label()]);
785  }
786 
787  seedTracks_.swap(cleanSeedTracks);
788 
789  return seedTracks_.size();
790  }
TrackVec cmsswTracks_
Definition: Event.h:75
TrackVec seedTracks_
Definition: Event.h:74
std::vector< Track > TrackVec

◆ validate()

void Event::validate ( )

Definition at line 60 of file Event.cc.

References mkfit::Config::cmssw_val, mkfit::Validation::fillCMSSWEfficiencyTree(), mkfit::Validation::fillCMSSWFakeRateTree(), mkfit::Validation::fillEfficiencyTree(), mkfit::Validation::fillFakeRateTree(), mkfit::Validation::fillFitTree(), mkfit::Config::fit_val, mkfit::Validation::makeCMSSWTkToRecoTksMaps(), mkfit::Validation::makeCMSSWTkToSeedTkMap(), mkfit::Validation::makeRecoTkToRecoTkMaps(), mkfit::Validation::makeRecoTkToSeedTkMapsDumbCMSSW(), mkfit::Validation::makeSeedTkToRecoTkMaps(), mkfit::Validation::makeSimTkToRecoTksMaps(), mkfit::Validation::setTrackExtras(), mkfit::Validation::setTrackScoresDumbCMSSW(), mkfit::Config::sim_val, mkfit::Config::sim_val_for_cmssw, and validation_.

60  {
61  // special map needed for sim_val_for_cmssw + set the track scores
65  }
66 
67  // standard eff/fr/dr validation
74  }
75 
76  // special cmssw to mkfit validation
77  if (Config::cmssw_val) {
84  }
85 
86  if (Config::fit_val) { // fit val for z-phi tuning
87  validation_.fillFitTree(*this);
88  }
89  }
Validation & validation_
Definition: Event.h:50
virtual void fillEfficiencyTree(const Event &)
Definition: Validation.h:66
virtual void setTrackScoresDumbCMSSW(Event &)
Definition: Validation.h:64
virtual void makeSimTkToRecoTksMaps(Event &)
Definition: Validation.h:56
virtual void setTrackExtras(Event &ev)
Definition: Validation.h:55
virtual void fillCMSSWFakeRateTree(const Event &)
Definition: Validation.h:70
virtual void makeCMSSWTkToRecoTksMaps(Event &)
Definition: Validation.h:59
virtual void makeSeedTkToRecoTkMaps(Event &)
Definition: Validation.h:57
virtual void makeRecoTkToSeedTkMapsDumbCMSSW(Event &)
Definition: Validation.h:62
virtual void makeCMSSWTkToSeedTkMap(Event &)
Definition: Validation.h:61
virtual void makeRecoTkToRecoTkMaps(Event &)
Definition: Validation.h:58
virtual void fillFakeRateTree(const Event &)
Definition: Validation.h:67
virtual void fillCMSSWEfficiencyTree(const Event &)
Definition: Validation.h:69
virtual void fillFitTree(const Event &)
Definition: Validation.h:71

◆ write_out()

void Event::write_out ( DataFile data_file)

Definition at line 118 of file Event.cc.

References cms::cuda::assert(), align::BeamSpot, beamSpot_, cmsswTracks_, mkfit::DataFile::f_fp, personalPlayback::fp, mkfit::DataFile::hasBeamSpot(), mkfit::DataFile::hasCmsswTracks(), mkfit::DataFile::hasHitIterMasks(), mkfit::DataFile::hasSeeds(), mkfit::DataFile::hasSimTrackStates(), createfilelist::int, layerHitMasks_, layerHits_, mutex, cms::cuda::nh, seedTracks_, simHitsInfo_, simTracks_, simTrackStates_, and write_tracks().

118  {
119  FILE *fp = data_file.f_fp;
120 
121  static std::mutex writemutex;
122  std::lock_guard<std::mutex> writelock(writemutex);
123 
124  auto start = ftell(fp);
125  int evsize = sizeof(int);
126  fwrite(&evsize, sizeof(int), 1, fp); // this will be overwritten at the end
127 
128  evsize += write_tracks(fp, simTracks_);
129 
130  if (data_file.hasSimTrackStates()) {
131  int nts = simTrackStates_.size();
132  fwrite(&nts, sizeof(int), 1, fp);
133  fwrite(&simTrackStates_[0], sizeof(TrackState), nts, fp);
134  evsize += sizeof(int) + nts * sizeof(TrackState);
135  }
136 
137  int nl = layerHits_.size();
138  fwrite(&nl, sizeof(int), 1, fp);
139  evsize += sizeof(int);
140  for (int il = 0; il < nl; ++il) {
141  int nh = layerHits_[il].size();
142  fwrite(&nh, sizeof(int), 1, fp);
143  fwrite(&layerHits_[il][0], sizeof(Hit), nh, fp);
144  evsize += sizeof(int) + nh * sizeof(Hit);
145  }
146 
147  if (data_file.hasHitIterMasks()) {
148  //sizes are the same as in layerHits_
149  for (int il = 0; il < nl; ++il) {
150  int nh = layerHitMasks_[il].size();
151  assert(nh == (int)layerHits_[il].size());
152  fwrite(&layerHitMasks_[il][0], sizeof(uint64_t), nh, fp);
153  evsize += nh * sizeof(uint64_t);
154  }
155  }
156 
157  int nm = simHitsInfo_.size();
158  fwrite(&nm, sizeof(int), 1, fp);
159  fwrite(&simHitsInfo_[0], sizeof(MCHitInfo), nm, fp);
160  evsize += sizeof(int) + nm * sizeof(MCHitInfo);
161 
162  if (data_file.hasSeeds()) {
163  evsize += write_tracks(fp, seedTracks_);
164  }
165 
166  if (data_file.hasCmsswTracks()) {
167  evsize += write_tracks(fp, cmsswTracks_);
168  }
169 
170  if (data_file.hasBeamSpot()) {
171  fwrite(&beamSpot_, sizeof(BeamSpot), 1, fp);
172  evsize += sizeof(BeamSpot);
173  }
174 
175  fseek(fp, start, SEEK_SET);
176  fwrite(&evsize, sizeof(int), 1, fp);
177  fseek(fp, 0, SEEK_END);
178 
179  //layerHitMap_ is recreated afterwards
180 
181  /*
182  printf("write %i tracks\n",nt);
183  for (int it = 0; it<nt; it++) {
184  printf("track with pT=%5.3f\n",simTracks_[it].pT());
185  for (int ih=0; ih<simTracks_[it].nTotalHits(); ++ih) {
186  printf("hit lyr:%2d idx=%i\n", simTracks_[it].getHitLyr(ih), simTracks_[it].getHitIdx(ih));
187  }
188  }
189  printf("write %i layers\n",nl);
190  for (int il = 0; il<nl; il++) {
191  printf("write %i hits in layer %i\n",layerHits_[il].size(),il);
192  for (int ih = 0; ih<layerHits_[il].size(); ih++) {
193  printf("hit with r=%5.3f x=%5.3f y=%5.3f z=%5.3f\n",layerHits_[il][ih].r(),layerHits_[il][ih].x(),layerHits_[il][ih].y(),layerHits_[il][ih].z());
194  }
195  }
196  */
197  }
size
Write out results.
Definition: start.py:1
TrackVec cmsswTracks_
Definition: Event.h:75
static std::mutex mutex
Definition: Proxy.cc:8
TrackVec seedTracks_
Definition: Event.h:74
assert(be >=bs)
BeamSpot beamSpot_
Definition: Event.h:69
uint32_t nh
MCHitInfoVec simHitsInfo_
Definition: Event.h:72
std::vector< HitVec > layerHits_
Definition: Event.h:70
TrackVec simTracks_
Definition: Event.h:74
TSVec simTrackStates_
Definition: Event.h:80
unsigned long long uint64_t
Definition: Time.h:13
int write_tracks(FILE *fp, const TrackVec &tracks)
Definition: Event.cc:419
std::vector< std::vector< uint64_t > > layerHitMasks_
Definition: Event.h:71

◆ write_tracks()

int Event::write_tracks ( FILE *  fp,
const TrackVec tracks 
)

Definition at line 419 of file Event.cc.

References personalPlayback::fp, mps_fire::i, createfilelist::int, and DiMuonV_cfg::tracks.

Referenced by write_out().

419  {
420  // Returns total number of bytes written.
421 
422  int n_tracks = tracks.size();
423  fwrite(&n_tracks, sizeof(int), 1, fp);
424 
425  auto start = ftell(fp);
426  int data_size = 2 * sizeof(int) + n_tracks * sizeof(Track);
427  fwrite(&data_size, sizeof(int), 1, fp);
428 
429  fwrite(tracks.data(), sizeof(Track), n_tracks, fp);
430 
431  for (int i = 0; i < n_tracks; ++i) {
432  fwrite(tracks[i].beginHitsOnTrack(), sizeof(HitOnTrack), tracks[i].nTotalHits(), fp);
433  data_size += tracks[i].nTotalHits() * sizeof(HitOnTrack);
434  }
435 
436  fseek(fp, start, SEEK_SET);
437  fwrite(&data_size, sizeof(int), 1, fp);
438  fseek(fp, 0, SEEK_END);
439 
440  return data_size;
441  }
Definition: start.py:1

Member Data Documentation

◆ beamSpot_

BeamSpot mkfit::Event::beamSpot_

Definition at line 69 of file Event.h.

Referenced by read_in(), reset(), and write_out().

◆ candidateTracks_

TrackVec mkfit::Event::candidateTracks_

Definition at line 74 of file Event.h.

Referenced by reset().

◆ candidateTracksExtra_

TrackExtraVec mkfit::Event::candidateTracksExtra_
mutable

Definition at line 77 of file Event.h.

Referenced by reset().

◆ cmsswTracks_

TrackVec mkfit::Event::cmsswTracks_

◆ cmsswTracksExtra_

TrackExtraVec mkfit::Event::cmsswTracksExtra_
mutable

Definition at line 78 of file Event.h.

Referenced by reset().

◆ currentSeedSimFromHits_

std::vector<SimLabelFromHits> mkfit::Event::currentSeedSimFromHits_
mutableprivate

Definition at line 66 of file Event.h.

Referenced by resetCurrentSeedTracks(), and simLabelForCurrentSeed().

◆ currentSeedTracks_

const TrackVec* mkfit::Event::currentSeedTracks_ = nullptr
private

◆ evtID_

int mkfit::Event::evtID_
private

Definition at line 64 of file Event.h.

Referenced by evtID(), and reset().

◆ fitTracks_

TrackVec mkfit::Event::fitTracks_

Definition at line 74 of file Event.h.

Referenced by reset().

◆ fitTracksExtra_

TrackExtraVec mkfit::Event::fitTracksExtra_
mutable

Definition at line 77 of file Event.h.

Referenced by reset().

◆ layerHitMasks_

std::vector<std::vector<uint64_t> > mkfit::Event::layerHitMasks_

Definition at line 71 of file Event.h.

Referenced by Event(), fill_hitmask_bool_vectors(), read_in(), reset(), and write_out().

◆ layerHits_

std::vector<HitVec> mkfit::Event::layerHits_

◆ printmutex

std::mutex Event::printmutex
static

◆ seedTracks_

TrackVec mkfit::Event::seedTracks_

◆ seedTracksExtra_

TrackExtraVec mkfit::Event::seedTracksExtra_
mutable

Definition at line 77 of file Event.h.

Referenced by reset().

◆ simHitsInfo_

MCHitInfoVec mkfit::Event::simHitsInfo_

◆ simTracks_

TrackVec mkfit::Event::simTracks_

◆ simTracksExtra_

TrackExtraVec mkfit::Event::simTracksExtra_
mutable

Definition at line 77 of file Event.h.

Referenced by reset().

◆ simTrackStates_

TSVec mkfit::Event::simTrackStates_

Definition at line 80 of file Event.h.

Referenced by read_in(), reset(), and write_out().

◆ validation_

Validation& mkfit::Event::validation_

Definition at line 50 of file Event.h.

Referenced by Event(), reset(), and validate().