CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
CaloTruthAccumulator Class Reference
Inheritance diagram for CaloTruthAccumulator:
DigiAccumulatorMixMod

Classes

struct  calo_particles
 
struct  OutputCollections
 

Public Member Functions

 CaloTruthAccumulator (const edm::ParameterSet &config, edm::ProducesCollector, edm::ConsumesCollector &iC)
 
- Public Member Functions inherited from DigiAccumulatorMixMod
virtual void beginLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &setup)
 
virtual void beginRun (edm::Run const &run, edm::EventSetup const &setup)
 
 DigiAccumulatorMixMod ()
 
 DigiAccumulatorMixMod (DigiAccumulatorMixMod const &)=delete
 
virtual void endLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &setup)
 
virtual void endRun (edm::Run const &run, edm::EventSetup const &setup)
 
virtual void finalizeBunchCrossing (edm::Event &event, edm::EventSetup const &setup, int bunchCrossing)
 
virtual PileupMixingContentgetEventPileupInfo ()
 
virtual void initializeBunchCrossing (edm::Event const &event, edm::EventSetup const &setup, int bunchCrossing)
 
DigiAccumulatorMixMod const & operator= (DigiAccumulatorMixMod const &)=delete
 
virtual void StorePileupInformation (std::vector< int > &numInteractionList, std::vector< int > &bunchCrossingList, std::vector< float > &TrueInteractionList, std::vector< edm::EventID > &eventList, int bunchSpace)
 
virtual ~DigiAccumulatorMixMod ()
 

Private Member Functions

void accumulate (const edm::Event &event, const edm::EventSetup &setup) override
 
void accumulate (const PileUpEventPrincipal &event, const edm::EventSetup &setup, edm::StreamID const &) override
 
template<class T >
void accumulateEvent (const T &event, const edm::EventSetup &setup, const edm::Handle< edm::HepMCProduct > &hepMCproduct)
 Both forms of accumulate() delegate to this templated method. More...
 
template<class T >
void fillSimHits (std::vector< std::pair< DetId, const PCaloHit *>> &returnValue, std::unordered_map< int, std::map< int, float >> &simTrackDetIdEnergyMap, const T &event, const edm::EventSetup &setup)
 Fills the supplied vector with pointers to the SimHits, checking for bad modules if required. More...
 
void finalizeEvent (edm::Event &event, const edm::EventSetup &setup) override
 
void initializeEvent (const edm::Event &event, const edm::EventSetup &setup) override
 

Private Attributes

std::vector< edm::InputTagcollectionTags_
 
bool doHGCAL
 
edm::InputTag genParticleLabel_
 
int geometryType_
 
const edm::ESGetToken< CaloGeometry, CaloGeometryRecordgeomToken_
 
edm::ESWatcher< CaloGeometryRecordgeomWatcher_
 
const HcalDDDRecConstantshcddd_ = nullptr
 
edm::InputTag hepMCproductLabel_
 Needed to add HepMC::GenVertex to SimVertex. More...
 
const HGCalDDDConstantshgddd_ [3] = {nullptr, nullptr, nullptr}
 
const HGCalTopologyhgtopo_ [3] = {nullptr, nullptr, nullptr}
 
edm::Handle< std::vector< SimTrack > > hSimTracks
 
edm::Handle< std::vector< SimVertex > > hSimVertices
 
calo_particles m_caloParticles
 
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
 
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
 
const unsigned int maximumPreviousBunchCrossing_
 
const unsigned int maximumSubsequentBunchCrossing_
 
const double maxPseudoRapidity_
 
const std::string messageCategory_
 
const double minEnergy_
 
OutputCollections output_
 
const bool premixStage1_
 
const edm::InputTag simTrackLabel_
 
const edm::InputTag simVertexLabel_
 

Detailed Description

Definition at line 126 of file CaloTruthAccumulator.cc.

Constructor & Destructor Documentation

◆ CaloTruthAccumulator()

CaloTruthAccumulator::CaloTruthAccumulator ( const edm::ParameterSet config,
edm::ProducesCollector  producesCollector,
edm::ConsumesCollector iC 
)
explicit

Definition at line 361 of file CaloTruthAccumulator.cc.

References collectionTags_, edm::ConsumesCollector::consumes(), genParticleLabel_, hepMCproductLabel_, premixStage1_, edm::ProducesCollector::produces(), simTrackLabel_, simVertexLabel_, and triggerMatcherToHLTDebug_cfi::tags.

364  : messageCategory_("CaloTruthAccumulator"),
365  maximumPreviousBunchCrossing_(config.getParameter<unsigned int>("maximumPreviousBunchCrossing")),
366  maximumSubsequentBunchCrossing_(config.getParameter<unsigned int>("maximumSubsequentBunchCrossing")),
367  simTrackLabel_(config.getParameter<edm::InputTag>("simTrackCollection")),
368  simVertexLabel_(config.getParameter<edm::InputTag>("simVertexCollection")),
369  collectionTags_(),
370  genParticleLabel_(config.getParameter<edm::InputTag>("genParticleCollection")),
371  hepMCproductLabel_(config.getParameter<edm::InputTag>("HepMCProductLabel")),
372  geomToken_(iC.esConsumes()),
373  minEnergy_(config.getParameter<double>("MinEnergy")),
374  maxPseudoRapidity_(config.getParameter<double>("MaxPseudoRapidity")),
375  premixStage1_(config.getParameter<bool>("premixStage1")),
376  geometryType_(-1),
377  doHGCAL(config.getParameter<bool>("doHGCAL")) {
378  producesCollector.produces<SimClusterCollection>("MergedCaloTruth");
379  producesCollector.produces<CaloParticleCollection>("MergedCaloTruth");
380  if (premixStage1_) {
381  producesCollector.produces<std::vector<std::pair<unsigned int, float>>>("MergedCaloTruth");
382  }
383 
384  iC.consumes<std::vector<SimTrack>>(simTrackLabel_);
385  iC.consumes<std::vector<SimVertex>>(simVertexLabel_);
386  iC.consumes<std::vector<reco::GenParticle>>(genParticleLabel_);
387  iC.consumes<std::vector<int>>(genParticleLabel_);
388  iC.consumes<std::vector<int>>(hepMCproductLabel_);
389 
390  // Fill the collection tags
391  const edm::ParameterSet &simHitCollectionConfig = config.getParameterSet("simHitCollections");
392  std::vector<std::string> parameterNames = simHitCollectionConfig.getParameterNames();
393 
394  for (auto const &parameterName : parameterNames) {
395  std::vector<edm::InputTag> tags = simHitCollectionConfig.getParameter<std::vector<edm::InputTag>>(parameterName);
396  collectionTags_.insert(collectionTags_.end(), tags.begin(), tags.end());
397  }
398 
399  for (auto const &collectionTag : collectionTags_) {
400  iC.consumes<std::vector<PCaloHit>>(collectionTag);
401  }
402 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
const unsigned int maximumSubsequentBunchCrossing_
std::vector< edm::InputTag > collectionTags_
Definition: config.py:1
edm::InputTag hepMCproductLabel_
Needed to add HepMC::GenVertex to SimVertex.
const std::string messageCategory_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_
const edm::InputTag simVertexLabel_
const edm::InputTag simTrackLabel_
std::vector< CaloParticle > CaloParticleCollection
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
const unsigned int maximumPreviousBunchCrossing_

Member Function Documentation

◆ accumulate() [1/2]

void CaloTruthAccumulator::accumulate ( const edm::Event event,
const edm::EventSetup setup 
)
overrideprivatevirtual

Create handle to edm::HepMCProduct here because event.getByLabel with edm::HepMCProduct only works for edm::Event but not for PileUpEventPrincipal; PileUpEventPrincipal::getByLabel tries to call T::value_type and T::iterator (where T is the type of the object one wants to get a handle to) which is only implemented for container-like objects like std::vector but not for edm::HepMCProduct!

Implements DigiAccumulatorMixMod.

Definition at line 456 of file CaloTruthAccumulator.cc.

References accumulateEvent(), hepMCproductLabel_, messageCategory_, and singleTopDQM_cfi::setup.

456  {
458  event.getByLabel(hepMCproductLabel_, hepmc);
459 
460  edm::LogInfo(messageCategory_) << " CaloTruthAccumulator::accumulate (signal)";
461  accumulateEvent(event, setup, hepmc);
462 }
edm::InputTag hepMCproductLabel_
Needed to add HepMC::GenVertex to SimVertex.
const std::string messageCategory_
Log< level::Info, false > LogInfo
void accumulateEvent(const T &event, const edm::EventSetup &setup, const edm::Handle< edm::HepMCProduct > &hepMCproduct)
Both forms of accumulate() delegate to this templated method.
Definition: event.py:1

◆ accumulate() [2/2]

void CaloTruthAccumulator::accumulate ( const PileUpEventPrincipal event,
const edm::EventSetup setup,
edm::StreamID const &   
)
overrideprivatevirtual

Implements DigiAccumulatorMixMod.

Definition at line 464 of file CaloTruthAccumulator.cc.

References accumulateEvent(), maximumPreviousBunchCrossing_, maximumSubsequentBunchCrossing_, messageCategory_, and singleTopDQM_cfi::setup.

466  {
467  if (event.bunchCrossing() >= -static_cast<int>(maximumPreviousBunchCrossing_) &&
468  event.bunchCrossing() <= static_cast<int>(maximumSubsequentBunchCrossing_)) {
469  // simply create empty handle as we do not have a HepMCProduct in PU anyway
471  edm::LogInfo(messageCategory_) << " CaloTruthAccumulator::accumulate (pileup) bunchCrossing="
472  << event.bunchCrossing();
473  accumulateEvent(event, setup, hepmc);
474  } else {
475  edm::LogInfo(messageCategory_) << "Skipping pileup event for bunch crossing " << event.bunchCrossing();
476  }
477 }
const unsigned int maximumSubsequentBunchCrossing_
const std::string messageCategory_
Log< level::Info, false > LogInfo
void accumulateEvent(const T &event, const edm::EventSetup &setup, const edm::Handle< edm::HepMCProduct > &hepMCproduct)
Both forms of accumulate() delegate to this templated method.
Definition: event.py:1
const unsigned int maximumPreviousBunchCrossing_

◆ accumulateEvent()

template<class T >
void CaloTruthAccumulator::accumulateEvent ( const T event,
const edm::EventSetup setup,
const edm::Handle< edm::HepMCProduct > &  hepMCproduct 
)
private

Both forms of accumulate() delegate to this templated method.


Build the main decay graph and assign the SimTrack to each edge. The graph built here will only contain the particles that have a decay vertex associated to them. In order to recover also the particles that will not decay, we need to keep track of the SimTrack used here and add, a-posteriori, the ones not used, associating a ghost vertex (starting from the highest simulated vertex number), in order to build the edge and identify them immediately as stable (i.e. not decayed).

To take into account the multi-bremsstrahlung effects in which a single particle is emitting photons in different vertices keeping the same track index, we also collapsed those vertices into 1 unique vertex. The other approach of fully representing the decay chain keeping the same track index would have the problem of over-counting the contributions of that track, especially in terms of hits.

The 2 auxiliary vectors are structured as follow:

  1. used_sim_tracks is a vector that has the same size as the overall number of simulated tracks. The associated integer is the vertexId of the decaying vertex for that track.
  2. collapsed_vertices is a vector that has the same size as the overall number of simulated vertices. The vector's index is the vertexId itself, the associated value is the vertexId of the vertex on which this should collapse.

Definition at line 534 of file CaloTruthAccumulator.cc.

References funct::abs(), gather_cfg::cout, EdgeProperty::cumulative_simHits, DEBUG, PA_ZEESkim_cff::decay, fillSimHits(), genParticleLabel_, hSimTracks, hSimVertices, mps_fire::i, heavyIonCSV_trainingSettings::idx, IfLogDebug, m_caloParticles, m_simHitBarcodeToIndex, maxPseudoRapidity_, messageCategory_, minEnergy_, CoreSimTrack::momentum(), SimTrack::noGenpart(), hltrates_dqm_sourceclient-live_cfg::offset, output_, put(), edm::second(), singleTopDQM_cfi::setup, EdgeProperty::simTrack, simTrackLabel_, simVertexLabel_, findQualityFiles::size, submitPVValidationJobs::t, tracks, findQualityFiles::v, AlignmentTracksFromVertexSelector_cfi::vertices, and runTauDisplay::vis.

Referenced by accumulate().

536  {
538  edm::Handle<std::vector<int>> hGenParticleIndices;
539 
540  event.getByLabel(simTrackLabel_, hSimTracks);
541  event.getByLabel(simVertexLabel_, hSimVertices);
542 
543  event.getByLabel(genParticleLabel_, hGenParticles);
544  event.getByLabel(genParticleLabel_, hGenParticleIndices);
545 
546  std::vector<std::pair<DetId, const PCaloHit *>> simHitPointers;
547  std::unordered_map<int, std::map<int, float>> simTrackDetIdEnergyMap;
548  fillSimHits(simHitPointers, simTrackDetIdEnergyMap, event, setup);
549 
550  // Clear maps from previous event fill them for this one
551  m_simHitBarcodeToIndex.clear();
552  for (unsigned int i = 0; i < simHitPointers.size(); ++i) {
553  m_simHitBarcodeToIndex.emplace(simHitPointers[i].second->geantTrackId(), i);
554  }
555 
556  auto const &tracks = *hSimTracks;
557  auto const &vertices = *hSimVertices;
558  std::unordered_map<int, int> trackid_to_track_index;
560  int idx = 0;
561 
562  IfLogDebug(DEBUG, messageCategory_) << " TRACKS" << std::endl;
563  for (auto const &t : tracks) {
564  IfLogDebug(DEBUG, messageCategory_) << " " << idx << "\t" << t.trackId() << "\t" << t << std::endl;
565  trackid_to_track_index[t.trackId()] = idx;
566  idx++;
567  }
568 
595  idx = 0;
596  std::vector<int> used_sim_tracks(tracks.size(), 0);
597  std::vector<int> collapsed_vertices(vertices.size(), 0);
598  IfLogDebug(DEBUG, messageCategory_) << " VERTICES" << std::endl;
599  for (auto const &v : vertices) {
600  IfLogDebug(DEBUG, messageCategory_) << " " << idx++ << "\t" << v << std::endl;
601  if (v.parentIndex() != -1) {
602  auto trk_idx = trackid_to_track_index[v.parentIndex()];
603  auto origin_vtx = tracks[trk_idx].vertIndex();
604  if (used_sim_tracks[trk_idx]) {
605  // collapse the vertex into the original first vertex we saw associated
606  // to this track. Omit adding the edge in order to avoid double
607  // counting of the very same particles and its associated hits.
608  collapsed_vertices[v.vertexId()] = used_sim_tracks[trk_idx];
609  continue;
610  }
611  // Perform the actual vertex collapsing, if needed.
612  if (collapsed_vertices[origin_vtx])
613  origin_vtx = collapsed_vertices[origin_vtx];
614  add_edge(origin_vtx,
615  v.vertexId(),
616  EdgeProperty(&tracks[trk_idx], simTrackDetIdEnergyMap[v.parentIndex()].size(), 0),
617  decay);
618  used_sim_tracks[trk_idx] = v.vertexId();
619  }
620  }
621  // Build the motherParticle property to each vertex
622  auto const &vertexMothersProp = get(vertex_name, decay);
623  // Now recover the particles that did not decay. Append them with an index
624  // bigger than the size of the generated vertices.
625  int offset = vertices.size();
626  for (size_t i = 0; i < tracks.size(); ++i) {
627  if (!used_sim_tracks[i]) {
628  auto origin_vtx = tracks[i].vertIndex();
629  // Perform the actual vertex collapsing, if needed.
630  if (collapsed_vertices[origin_vtx])
631  origin_vtx = collapsed_vertices[origin_vtx];
632  add_edge(
633  origin_vtx, offset, EdgeProperty(&tracks[i], simTrackDetIdEnergyMap[tracks[i].trackId()].size(), 0), decay);
634  // The properties for "fake" vertices associated to stable particles have
635  // to be set inside this loop, since they do not belong to the vertices
636  // collection and would be skipped by that loop (coming next)
637  put(vertexMothersProp, offset, VertexProperty(&tracks[i], 0));
638  offset++;
639  }
640  }
641  for (auto const &v : vertices) {
642  if (v.parentIndex() != -1) {
643  // Skip collapsed_vertices
644  if (collapsed_vertices[v.vertexId()])
645  continue;
646  put(vertexMothersProp, v.vertexId(), VertexProperty(&tracks[trackid_to_track_index[v.parentIndex()]], 0));
647  }
648  }
649  SimHitsAccumulator_dfs_visitor vis;
650  depth_first_search(decay, visitor(vis));
651  CaloParticle_dfs_visitor caloParticleCreator(
652  output_,
655  simTrackDetIdEnergyMap,
656  [&](EdgeProperty &edge_property) -> bool {
657  // Apply selection on SimTracks in order to promote them to be
658  // CaloParticles. The function returns TRUE if the particle satisfies
659  // the selection, FALSE otherwise. Therefore the correct logic to select
660  // the particle is to ask for TRUE as return value.
661  return (edge_property.cumulative_simHits != 0 and !edge_property.simTrack->noGenpart() and
662  edge_property.simTrack->momentum().E() > minEnergy_ and
663  std::abs(edge_property.simTrack->momentum().Eta()) < maxPseudoRapidity_);
664  });
665  depth_first_search(decay, visitor(caloParticleCreator));
666 
667 #if DEBUG
668  boost::write_graphviz(std::cout,
669  decay,
670  make_label_writer(make_transform_value_property_map(&graphviz_vertex, get(vertex_name, decay))),
671  make_label_writer(make_transform_value_property_map(&graphviz_edge, get(edge_weight, decay))));
672 #endif
673 }
size
Write out results.
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
edm::Handle< std::vector< SimVertex > > hSimVertices
void fillSimHits(std::vector< std::pair< DetId, const PCaloHit *>> &returnValue, std::unordered_map< int, std::map< int, float >> &simTrackDetIdEnergyMap, const T &event, const edm::EventSetup &setup)
Fills the supplied vector with pointers to the SimHits, checking for bad modules if required...
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
void put(edm::Event &evt, double value, const char *instanceName)
const SimTrack * simTrack
U second(std::pair< T, U > const &p)
#define IfLogDebug(cond, cat)
const std::string messageCategory_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::InputTag simVertexLabel_
const edm::InputTag simTrackLabel_
edm::Handle< std::vector< SimTrack > > hSimTracks
auto const & tracks
cannot be loose
bool noGenpart() const
Definition: SimTrack.h:38
adjacency_list< listS, vecS, directedS, VertexMotherParticleProperty, EdgeParticleClustersProperty > DecayChain
Definition: event.py:1
#define DEBUG

◆ fillSimHits()

template<class T >
void CaloTruthAccumulator::fillSimHits ( std::vector< std::pair< DetId, const PCaloHit *>> &  returnValue,
std::unordered_map< int, std::map< int, float >> &  simTrackDetIdEnergyMap,
const T event,
const edm::EventSetup setup 
)
private

Fills the supplied vector with pointers to the SimHits, checking for bad modules if required.

Definition at line 676 of file CaloTruthAccumulator.cc.

References collectionTags_, doHGCAL, geometryType_, HcalEndcap, hcddd_, hgddd_, hgtopo_, triggerObjects_cff::id, phase1PixelTopology::layer, m_detIdToTotalSimEnergy, HcalHitRelabeller::relabel(), fileinputsource_cfi::sec, rpcPointValidation_cfi::simHit, HGCalDDDConstants::simToReco(), HcalDetId::subdet(), and HGCalTestNumbering::unpackHexagonIndex().

Referenced by accumulateEvent().

679  {
680  for (auto const &collectionTag : collectionTags_) {
682  const bool isHcal = (collectionTag.instance().find("HcalHits") != std::string::npos);
683  event.getByLabel(collectionTag, hSimHits);
684 
685  for (auto const &simHit : *hSimHits) {
686  DetId id(0);
687 
688  //Relabel as necessary for HGCAL
689  if (doHGCAL) {
690  const uint32_t simId = simHit.id();
691  if (geometryType_ == 1) {
692  // no test numbering in new geometry
693  id = simId;
694  } else if (isHcal) {
696  if (hid.subdet() == HcalEndcap)
697  id = hid;
698  } else {
699  int subdet, layer, cell, sec, subsec, zp;
700  HGCalTestNumbering::unpackHexagonIndex(simId, subdet, zp, layer, sec, subsec, cell);
701  const HGCalDDDConstants *ddd = hgddd_[subdet - 3];
702  std::pair<int, int> recoLayerCell = ddd->simToReco(cell, layer, sec, hgtopo_[subdet - 3]->detectorType());
703  cell = recoLayerCell.first;
704  layer = recoLayerCell.second;
705  // skip simhits with bad barcodes or non-existant layers
706  if (layer == -1 || simHit.geantTrackId() == 0)
707  continue;
708  id = HGCalDetId((ForwardSubdetector)subdet, zp, layer, subsec, sec, cell);
709  }
710  } else {
711  id = simHit.id();
712  //Relabel all HCAL hits
713  if (isHcal) {
715  id = hid;
716  }
717  }
718 
719  if (id == DetId(0)) {
720  continue;
721  }
722  if (simHit.geantTrackId() == 0) {
723  continue;
724  }
725 
726  returnValue.emplace_back(id, &simHit);
727  simTrackDetIdEnergyMap[simHit.geantTrackId()][id.rawId()] += simHit.energy();
728  m_detIdToTotalSimEnergy[id.rawId()] += simHit.energy();
729  }
730  } // end of loop over InputTags
731 }
const HGCalTopology * hgtopo_[3]
std::vector< edm::InputTag > collectionTags_
ForwardSubdetector
constexpr std::array< uint8_t, layerIndexSize > layer
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
DetId relabel(const uint32_t testId) const
const HGCalDDDConstants * hgddd_[3]
Definition: DetId.h:17
const HcalDDDRecConstants * hcddd_
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)

◆ finalizeEvent()

void CaloTruthAccumulator::finalizeEvent ( edm::Event event,
const edm::EventSetup setup 
)
overrideprivatevirtual

Implements DigiAccumulatorMixMod.

Definition at line 479 of file CaloTruthAccumulator.cc.

References filterCSVwithJSON::copy, HLT_2022v12_cff::fraction, mps_fire::i, dqmiolumiharvest::j, m_caloParticles, m_detIdToTotalSimEnergy, m_simHitBarcodeToIndex, messageCategory_, eostools::move(), output_, CaloTruthAccumulator::OutputCollections::pCaloParticles, premixStage1_, CaloTruthAccumulator::OutputCollections::pSimClusters, CaloTruthAccumulator::calo_particles::sc_start_, CaloTruthAccumulator::calo_particles::sc_stop_, jetUpdater_cfi::sort, edm::swap(), and CaloTruthAccumulator::calo_particles::swap().

479  {
480  edm::LogInfo(messageCategory_) << "Adding " << output_.pSimClusters->size() << " SimParticles and "
481  << output_.pCaloParticles->size() << " CaloParticles to the event.";
482 
483  // We need to normalize the hits and energies into hits and fractions (since
484  // we have looped over all pileup events)
485  // For premixing stage1 we keep the energies, they will be normalized to
486  // fractions in stage2
487 
488  if (premixStage1_) {
489  auto totalEnergies = std::make_unique<std::vector<std::pair<unsigned int, float>>>();
490  totalEnergies->reserve(m_detIdToTotalSimEnergy.size());
491  std::copy(m_detIdToTotalSimEnergy.begin(), m_detIdToTotalSimEnergy.end(), std::back_inserter(*totalEnergies));
492  std::sort(totalEnergies->begin(), totalEnergies->end());
493  event.put(std::move(totalEnergies), "MergedCaloTruth");
494  } else {
495  for (auto &sc : *(output_.pSimClusters)) {
496  auto hitsAndEnergies = sc.hits_and_fractions();
497  sc.clearHitsAndFractions();
498  sc.clearHitsEnergy();
499  for (auto &hAndE : hitsAndEnergies) {
500  const float totalenergy = m_detIdToTotalSimEnergy[hAndE.first];
501  float fraction = 0.;
502  if (totalenergy > 0)
503  fraction = hAndE.second / totalenergy;
504  else
506  << "TotalSimEnergy for hit " << hAndE.first << " is 0! The fraction for this hit cannot be computed.";
507  sc.addRecHitAndFraction(hAndE.first, fraction);
508  sc.addHitEnergy(hAndE.second);
509  }
510  }
511  }
512 
513  // save the SimCluster orphan handle so we can fill the calo particles
514  auto scHandle = event.put(std::move(output_.pSimClusters), "MergedCaloTruth");
515 
516  // now fill the calo particles
517  for (unsigned i = 0; i < output_.pCaloParticles->size(); ++i) {
518  auto &cp = (*output_.pCaloParticles)[i];
519  for (unsigned j = m_caloParticles.sc_start_[i]; j < m_caloParticles.sc_stop_[i]; ++j) {
520  edm::Ref<SimClusterCollection> ref(scHandle, j);
521  cp.addSimCluster(ref);
522  }
523  }
524 
525  event.put(std::move(output_.pCaloParticles), "MergedCaloTruth");
526 
527  calo_particles().swap(m_caloParticles);
528 
529  std::unordered_map<Index_t, float>().swap(m_detIdToTotalSimEnergy);
530  std::unordered_multimap<Barcode_t, Index_t>().swap(m_simHitBarcodeToIndex);
531 }
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
const std::string messageCategory_
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
Log< level::Info, false > LogInfo
std::unique_ptr< CaloParticleCollection > pCaloParticles
std::unique_ptr< SimClusterCollection > pSimClusters
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511

◆ initializeEvent()

void CaloTruthAccumulator::initializeEvent ( const edm::Event event,
const edm::EventSetup setup 
)
overrideprivatevirtual

Implements DigiAccumulatorMixMod.

Definition at line 404 of file CaloTruthAccumulator.cc.

References edm::ESWatcher< T >::check(), HGCalTopology::dddConstants(), HcalTopology::dddConstants(), doHGCAL, EcalMappingRecord_cfi::eegeom, DetId::Forward, ForwardEmpty, relativeConstraints::geom, geometryType_, geomToken_, geomWatcher_, DetId::Hcal, HcalEndcap, hcddd_, DetId::HGCalEE, DetId::HGCalHSc, DetId::HGCalHSi, HGCEE, HGCHEF, hgddd_, hgtopo_, mps_fire::i, m_detIdToTotalSimEnergy, output_, CaloTruthAccumulator::OutputCollections::pCaloParticles, CaloTruthAccumulator::OutputCollections::pSimClusters, singleTopDQM_cfi::setup, and HcalGeometry::topology().

404  {
405  output_.pSimClusters = std::make_unique<SimClusterCollection>();
406  output_.pCaloParticles = std::make_unique<CaloParticleCollection>();
407 
408  m_detIdToTotalSimEnergy.clear();
409 
410  if (geomWatcher_.check(setup)) {
411  auto const &geom = setup.getData(geomToken_);
412  const HGCalGeometry *eegeom = nullptr, *fhgeom = nullptr, *bhgeomnew = nullptr;
413  const HcalGeometry *bhgeom = nullptr;
414  bhgeom = static_cast<const HcalGeometry *>(geom.getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
415 
416  if (doHGCAL) {
417  eegeom = static_cast<const HGCalGeometry *>(
418  geom.getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty));
419  // check if it's the new geometry
420  if (eegeom) {
421  geometryType_ = 1;
422  fhgeom = static_cast<const HGCalGeometry *>(
423  geom.getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty));
424  bhgeomnew = static_cast<const HGCalGeometry *>(
425  geom.getSubdetectorGeometry(DetId::HGCalHSc, ForwardSubdetector::ForwardEmpty));
426  } else {
427  geometryType_ = 0;
428  eegeom = static_cast<const HGCalGeometry *>(geom.getSubdetectorGeometry(DetId::Forward, HGCEE));
429  fhgeom = static_cast<const HGCalGeometry *>(geom.getSubdetectorGeometry(DetId::Forward, HGCHEF));
430  bhgeom = static_cast<const HcalGeometry *>(geom.getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
431  }
432  hgtopo_[0] = &(eegeom->topology());
433  hgtopo_[1] = &(fhgeom->topology());
434  if (bhgeomnew)
435  hgtopo_[2] = &(bhgeomnew->topology());
436 
437  for (unsigned i = 0; i < 3; ++i) {
438  if (hgtopo_[i])
439  hgddd_[i] = &(hgtopo_[i]->dddConstants());
440  }
441  }
442 
443  if (bhgeom) {
444  hcddd_ = bhgeom->topology().dddConstants();
445  }
446  }
447 }
const HGCalTopology * hgtopo_[3]
edm::ESWatcher< CaloGeometryRecord > geomWatcher_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomToken_
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
const HGCalDDDConstants * hgddd_[3]
std::unique_ptr< CaloParticleCollection > pCaloParticles
const HcalDDDRecConstants * hcddd_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:164
std::unique_ptr< SimClusterCollection > pSimClusters
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:98
const HcalTopology & topology() const
Definition: HcalGeometry.h:111

Member Data Documentation

◆ collectionTags_

std::vector<edm::InputTag> CaloTruthAccumulator::collectionTags_
private

Definition at line 173 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and fillSimHits().

◆ doHGCAL

bool CaloTruthAccumulator::doHGCAL
private

Definition at line 212 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ genParticleLabel_

edm::InputTag CaloTruthAccumulator::genParticleLabel_
private

Definition at line 174 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

◆ geometryType_

int CaloTruthAccumulator::geometryType_
private

Definition at line 211 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ geomToken_

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> CaloTruthAccumulator::geomToken_
private

Definition at line 177 of file CaloTruthAccumulator.cc.

Referenced by initializeEvent().

◆ geomWatcher_

edm::ESWatcher<CaloGeometryRecord> CaloTruthAccumulator::geomWatcher_
private

Definition at line 178 of file CaloTruthAccumulator.cc.

Referenced by initializeEvent().

◆ hcddd_

const HcalDDDRecConstants* CaloTruthAccumulator::hcddd_ = nullptr
private

Definition at line 207 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ hepMCproductLabel_

edm::InputTag CaloTruthAccumulator::hepMCproductLabel_
private

Needed to add HepMC::GenVertex to SimVertex.

Definition at line 176 of file CaloTruthAccumulator.cc.

Referenced by accumulate(), and CaloTruthAccumulator().

◆ hgddd_

const HGCalDDDConstants* CaloTruthAccumulator::hgddd_[3] = {nullptr, nullptr, nullptr}
private

Definition at line 206 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ hgtopo_

const HGCalTopology* CaloTruthAccumulator::hgtopo_[3] = {nullptr, nullptr, nullptr}
private

Definition at line 205 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ hSimTracks

edm::Handle<std::vector<SimTrack> > CaloTruthAccumulator::hSimTracks
private

Definition at line 170 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ hSimVertices

edm::Handle<std::vector<SimVertex> > CaloTruthAccumulator::hSimVertices
private

Definition at line 171 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ m_caloParticles

calo_particles CaloTruthAccumulator::m_caloParticles
private

Definition at line 209 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and finalizeEvent().

◆ m_detIdToTotalSimEnergy

std::unordered_map<Index_t, float> CaloTruthAccumulator::m_detIdToTotalSimEnergy
private

Definition at line 152 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), finalizeEvent(), and initializeEvent().

◆ m_simHitBarcodeToIndex

std::unordered_multimap<Barcode_t, Index_t> CaloTruthAccumulator::m_simHitBarcodeToIndex
private

Definition at line 153 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and finalizeEvent().

◆ maximumPreviousBunchCrossing_

const unsigned int CaloTruthAccumulator::maximumPreviousBunchCrossing_
private

The maximum bunch crossing BEFORE the signal crossing to create TrackinParticles for. Use positive values. If set to zero no previous bunches are added and only in-time, signal and after bunches (defined by maximumSubsequentBunchCrossing_) are used.

Definition at line 160 of file CaloTruthAccumulator.cc.

Referenced by accumulate().

◆ maximumSubsequentBunchCrossing_

const unsigned int CaloTruthAccumulator::maximumSubsequentBunchCrossing_
private

The maximum bunch crossing AFTER the signal crossing to create TrackinParticles for. E.g. if set to zero only uses the signal and in time pileup (and previous bunches defined by the maximumPreviousBunchCrossing_ parameter).

Definition at line 166 of file CaloTruthAccumulator.cc.

Referenced by accumulate().

◆ maxPseudoRapidity_

const double CaloTruthAccumulator::maxPseudoRapidity_
private

Definition at line 180 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ messageCategory_

const std::string CaloTruthAccumulator::messageCategory_
private

Definition at line 150 of file CaloTruthAccumulator.cc.

Referenced by accumulate(), accumulateEvent(), and finalizeEvent().

◆ minEnergy_

const double CaloTruthAccumulator::minEnergy_
private

Definition at line 180 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ output_

OutputCollections CaloTruthAccumulator::output_
private

Definition at line 208 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), finalizeEvent(), and initializeEvent().

◆ premixStage1_

const bool CaloTruthAccumulator::premixStage1_
private

Definition at line 181 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and finalizeEvent().

◆ simTrackLabel_

const edm::InputTag CaloTruthAccumulator::simTrackLabel_
private

Definition at line 168 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

◆ simVertexLabel_

const edm::InputTag CaloTruthAccumulator::simVertexLabel_
private

Definition at line 169 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().