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 56 of file CaloTruthAccumulator.cc.

Constructor & Destructor Documentation

◆ CaloTruthAccumulator()

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

Definition at line 220 of file CaloTruthAccumulator.cc.

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

223  : messageCategory_("CaloTruthAccumulator"),
224  maximumPreviousBunchCrossing_(config.getParameter<unsigned int>("maximumPreviousBunchCrossing")),
225  maximumSubsequentBunchCrossing_(config.getParameter<unsigned int>("maximumSubsequentBunchCrossing")),
226  simTrackLabel_(config.getParameter<edm::InputTag>("simTrackCollection")),
227  simVertexLabel_(config.getParameter<edm::InputTag>("simVertexCollection")),
228  collectionTags_(),
229  genParticleLabel_(config.getParameter<edm::InputTag>("genParticleCollection")),
230  hepMCproductLabel_(config.getParameter<edm::InputTag>("HepMCProductLabel")),
231  geomToken_(iC.esConsumes()),
232  minEnergy_(config.getParameter<double>("MinEnergy")),
233  maxPseudoRapidity_(config.getParameter<double>("MaxPseudoRapidity")),
234  premixStage1_(config.getParameter<bool>("premixStage1")),
235  geometryType_(-1),
236  doHGCAL(config.getParameter<bool>("doHGCAL")) {
237  producesCollector.produces<SimClusterCollection>("MergedCaloTruth");
238  producesCollector.produces<CaloParticleCollection>("MergedCaloTruth");
239  if (premixStage1_) {
240  producesCollector.produces<std::vector<std::pair<unsigned int, float>>>("MergedCaloTruth");
241  }
242 
243  iC.consumes<std::vector<SimTrack>>(simTrackLabel_);
244  iC.consumes<std::vector<SimVertex>>(simVertexLabel_);
245  iC.consumes<std::vector<reco::GenParticle>>(genParticleLabel_);
246  iC.consumes<std::vector<int>>(genParticleLabel_);
247  iC.consumes<std::vector<int>>(hepMCproductLabel_);
248 
249  // Fill the collection tags
250  const edm::ParameterSet &simHitCollectionConfig = config.getParameterSet("simHitCollections");
251  std::vector<std::string> parameterNames = simHitCollectionConfig.getParameterNames();
252 
253  for (auto const &parameterName : parameterNames) {
254  std::vector<edm::InputTag> tags = simHitCollectionConfig.getParameter<std::vector<edm::InputTag>>(parameterName);
255  collectionTags_.insert(collectionTags_.end(), tags.begin(), tags.end());
256  }
257 
258  for (auto const &collectionTag : collectionTags_) {
259  iC.consumes<std::vector<PCaloHit>>(collectionTag);
260  }
261 }
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 315 of file CaloTruthAccumulator.cc.

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

315  {
317  event.getByLabel(hepMCproductLabel_, hepmc);
318 
319  edm::LogInfo(messageCategory_) << " CaloTruthAccumulator::accumulate (signal)";
320  accumulateEvent(event, setup, hepmc);
321 }
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 323 of file CaloTruthAccumulator.cc.

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

325  {
326  if (event.bunchCrossing() >= -static_cast<int>(maximumPreviousBunchCrossing_) &&
327  event.bunchCrossing() <= static_cast<int>(maximumSubsequentBunchCrossing_)) {
328  // simply create empty handle as we do not have a HepMCProduct in PU anyway
330  edm::LogInfo(messageCategory_) << " CaloTruthAccumulator::accumulate (pileup) bunchCrossing="
331  << event.bunchCrossing();
332  accumulateEvent(event, setup, hepmc);
333  } else {
334  edm::LogInfo(messageCategory_) << "Skipping pileup event for bunch crossing " << event.bunchCrossing();
335  }
336 }
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 393 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, pwdgSkimBPark_cfi::tracks, findQualityFiles::v, AlignmentTracksFromVertexSelector_cfi::vertices, and runTauDisplay::vis.

Referenced by accumulate().

395  {
397  edm::Handle<std::vector<int>> hGenParticleIndices;
398 
399  event.getByLabel(simTrackLabel_, hSimTracks);
400  event.getByLabel(simVertexLabel_, hSimVertices);
401 
402  event.getByLabel(genParticleLabel_, hGenParticles);
403  event.getByLabel(genParticleLabel_, hGenParticleIndices);
404 
405  std::vector<std::pair<DetId, const PCaloHit *>> simHitPointers;
406  std::unordered_map<int, std::map<int, float>> simTrackDetIdEnergyMap;
407  fillSimHits(simHitPointers, simTrackDetIdEnergyMap, event, setup);
408 
409  // Clear maps from previous event fill them for this one
410  m_simHitBarcodeToIndex.clear();
411  for (unsigned int i = 0; i < simHitPointers.size(); ++i) {
412  m_simHitBarcodeToIndex.emplace(simHitPointers[i].second->geantTrackId(), i);
413  }
414 
415  auto const &tracks = *hSimTracks;
416  auto const &vertices = *hSimVertices;
417  std::unordered_map<int, int> trackid_to_track_index;
419  int idx = 0;
420 
421  IfLogDebug(DEBUG, messageCategory_) << " TRACKS" << std::endl;
422  for (auto const &t : tracks) {
423  IfLogDebug(DEBUG, messageCategory_) << " " << idx << "\t" << t.trackId() << "\t" << t << std::endl;
424  trackid_to_track_index[t.trackId()] = idx;
425  idx++;
426  }
427 
454  idx = 0;
455  std::vector<int> used_sim_tracks(tracks.size(), 0);
456  std::vector<int> collapsed_vertices(vertices.size(), 0);
457  IfLogDebug(DEBUG, messageCategory_) << " VERTICES" << std::endl;
458  for (auto const &v : vertices) {
459  IfLogDebug(DEBUG, messageCategory_) << " " << idx++ << "\t" << v << std::endl;
460  if (v.parentIndex() != -1) {
461  auto trk_idx = trackid_to_track_index[v.parentIndex()];
462  auto origin_vtx = tracks[trk_idx].vertIndex();
463  if (used_sim_tracks[trk_idx]) {
464  // collapse the vertex into the original first vertex we saw associated
465  // to this track. Omit adding the edge in order to avoid double
466  // counting of the very same particles and its associated hits.
467  collapsed_vertices[v.vertexId()] = used_sim_tracks[trk_idx];
468  continue;
469  }
470  // Perform the actual vertex collapsing, if needed.
471  if (collapsed_vertices[origin_vtx])
472  origin_vtx = collapsed_vertices[origin_vtx];
473  add_edge(origin_vtx,
474  v.vertexId(),
475  EdgeProperty(&tracks[trk_idx], simTrackDetIdEnergyMap[v.parentIndex()].size(), 0),
476  decay);
477  used_sim_tracks[trk_idx] = v.vertexId();
478  }
479  }
480  // Build the motherParticle property to each vertex
481  auto const &vertexMothersProp = get(vertex_name, decay);
482  // Now recover the particles that did not decay. Append them with an index
483  // bigger than the size of the generated vertices.
484  int offset = vertices.size();
485  for (size_t i = 0; i < tracks.size(); ++i) {
486  if (!used_sim_tracks[i]) {
487  auto origin_vtx = tracks[i].vertIndex();
488  // Perform the actual vertex collapsing, if needed.
489  if (collapsed_vertices[origin_vtx])
490  origin_vtx = collapsed_vertices[origin_vtx];
491  add_edge(
492  origin_vtx, offset, EdgeProperty(&tracks[i], simTrackDetIdEnergyMap[tracks[i].trackId()].size(), 0), decay);
493  // The properties for "fake" vertices associated to stable particles have
494  // to be set inside this loop, since they do not belong to the vertices
495  // collection and would be skipped by that loop (coming next)
496  put(vertexMothersProp, offset, VertexProperty(&tracks[i], 0));
497  offset++;
498  }
499  }
500  for (auto const &v : vertices) {
501  if (v.parentIndex() != -1) {
502  // Skip collapsed_vertices
503  if (collapsed_vertices[v.vertexId()])
504  continue;
505  put(vertexMothersProp, v.vertexId(), VertexProperty(&tracks[trackid_to_track_index[v.parentIndex()]], 0));
506  }
507  }
508  SimHitsAccumulator_dfs_visitor vis;
509  depth_first_search(decay, visitor(vis));
510  CaloParticle_dfs_visitor caloParticleCreator(
511  output_,
514  simTrackDetIdEnergyMap,
515  [&](EdgeProperty &edge_property) -> bool {
516  // Apply selection on SimTracks in order to promote them to be
517  // CaloParticles. The function returns TRUE if the particle satisfies
518  // the selection, FALSE otherwise. Therefore the correct logic to select
519  // the particle is to ask for TRUE as return value.
520  return (edge_property.cumulative_simHits != 0 and !edge_property.simTrack->noGenpart() and
521  edge_property.simTrack->momentum().E() > minEnergy_ and
522  std::abs(edge_property.simTrack->momentum().Eta()) < maxPseudoRapidity_);
523  });
524  depth_first_search(decay, visitor(caloParticleCreator));
525 
526 #if DEBUG
527  boost::write_graphviz(std::cout,
528  decay,
529  make_label_writer(make_transform_value_property_map(&graphviz_vertex, get(vertex_name, decay))),
530  make_label_writer(make_transform_value_property_map(&graphviz_edge, get(edge_weight, decay))));
531 #endif
532 }
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
Definition: DecayGraph.h:61
U second(std::pair< T, U > const &p)
#define IfLogDebug(cond, cat)
const std::string messageCategory_
adjacency_list< listS, vecS, directedS, VertexMotherParticleProperty, EdgeParticleClustersProperty > DecayChain
Definition: DecayGraph.h:77
int cumulative_simHits
Definition: DecayGraph.h:63
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
bool noGenpart() const
Definition: SimTrack.h:38
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 535 of file CaloTruthAccumulator.cc.

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

Referenced by accumulateEvent().

538  {
539  for (auto const &collectionTag : collectionTags_) {
541  const bool isHcal = (collectionTag.instance().find("HcalHits") != std::string::npos);
542  event.getByLabel(collectionTag, hSimHits);
543 
544  for (auto const &simHit : *hSimHits) {
545  DetId id(0);
546 
547  //Relabel as necessary for HGCAL
548  if (doHGCAL) {
549  const uint32_t simId = simHit.id();
550  if (geometryType_ == 1) {
551  // no test numbering in new geometry
552  id = simId;
553  } else if (isHcal) {
555  if (hid.subdet() == HcalEndcap)
556  id = hid;
557  } else {
558  int subdet, layer, cell, sec, subsec, zp;
559  HGCalTestNumbering::unpackHexagonIndex(simId, subdet, zp, layer, sec, subsec, cell);
560  const HGCalDDDConstants *ddd = hgddd_[subdet - 3];
561  std::pair<int, int> recoLayerCell = ddd->simToReco(cell, layer, sec, hgtopo_[subdet - 3]->detectorType());
562  cell = recoLayerCell.first;
563  layer = recoLayerCell.second;
564  // skip simhits with bad barcodes or non-existant layers
565  if (layer == -1 || simHit.geantTrackId() == 0)
566  continue;
567  id = HGCalDetId((ForwardSubdetector)subdet, zp, layer, subsec, sec, cell);
568  }
569  } else {
570  id = simHit.id();
571  //Relabel all HCAL hits
572  if (isHcal) {
574  id = hid;
575  }
576  }
577 
578  if (id == DetId(0)) {
579  continue;
580  }
581  if (simHit.geantTrackId() == 0) {
582  continue;
583  }
584 
585  returnValue.emplace_back(id, &simHit);
586  simTrackDetIdEnergyMap[simHit.geantTrackId()][id.rawId()] += simHit.energy();
587  m_detIdToTotalSimEnergy[id.rawId()] += simHit.energy();
588  }
589  } // end of loop over InputTags
590 }
const HGCalTopology * hgtopo_[3]
std::vector< edm::InputTag > collectionTags_
ForwardSubdetector
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 338 of file CaloTruthAccumulator.cc.

References filterCSVwithJSON::copy, HLT_2023v12_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().

338  {
339  edm::LogInfo(messageCategory_) << "Adding " << output_.pSimClusters->size() << " SimParticles and "
340  << output_.pCaloParticles->size() << " CaloParticles to the event.";
341 
342  // We need to normalize the hits and energies into hits and fractions (since
343  // we have looped over all pileup events)
344  // For premixing stage1 we keep the energies, they will be normalized to
345  // fractions in stage2
346 
347  if (premixStage1_) {
348  auto totalEnergies = std::make_unique<std::vector<std::pair<unsigned int, float>>>();
349  totalEnergies->reserve(m_detIdToTotalSimEnergy.size());
350  std::copy(m_detIdToTotalSimEnergy.begin(), m_detIdToTotalSimEnergy.end(), std::back_inserter(*totalEnergies));
351  std::sort(totalEnergies->begin(), totalEnergies->end());
352  event.put(std::move(totalEnergies), "MergedCaloTruth");
353  } else {
354  for (auto &sc : *(output_.pSimClusters)) {
355  auto hitsAndEnergies = sc.hits_and_fractions();
356  sc.clearHitsAndFractions();
357  sc.clearHitsEnergy();
358  for (auto &hAndE : hitsAndEnergies) {
359  const float totalenergy = m_detIdToTotalSimEnergy[hAndE.first];
360  float fraction = 0.;
361  if (totalenergy > 0)
362  fraction = hAndE.second / totalenergy;
363  else
365  << "TotalSimEnergy for hit " << hAndE.first << " is 0! The fraction for this hit cannot be computed.";
366  sc.addRecHitAndFraction(hAndE.first, fraction);
367  sc.addHitEnergy(hAndE.second);
368  }
369  }
370  }
371 
372  // save the SimCluster orphan handle so we can fill the calo particles
373  auto scHandle = event.put(std::move(output_.pSimClusters), "MergedCaloTruth");
374 
375  // now fill the calo particles
376  for (unsigned i = 0; i < output_.pCaloParticles->size(); ++i) {
377  auto &cp = (*output_.pCaloParticles)[i];
378  for (unsigned j = m_caloParticles.sc_start_[i]; j < m_caloParticles.sc_stop_[i]; ++j) {
379  edm::Ref<SimClusterCollection> ref(scHandle, j);
380  cp.addSimCluster(ref);
381  }
382  }
383 
384  event.put(std::move(output_.pCaloParticles), "MergedCaloTruth");
385 
386  calo_particles().swap(m_caloParticles);
387 
388  std::unordered_map<Index_t, float>().swap(m_detIdToTotalSimEnergy);
389  std::unordered_multimap<Barcode_t, Index_t>().swap(m_simHitBarcodeToIndex);
390 }
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 263 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().

263  {
264  output_.pSimClusters = std::make_unique<SimClusterCollection>();
265  output_.pCaloParticles = std::make_unique<CaloParticleCollection>();
266 
267  m_detIdToTotalSimEnergy.clear();
268 
269  if (geomWatcher_.check(setup)) {
270  auto const &geom = setup.getData(geomToken_);
271  const HGCalGeometry *eegeom = nullptr, *fhgeom = nullptr, *bhgeomnew = nullptr;
272  const HcalGeometry *bhgeom = nullptr;
273  bhgeom = static_cast<const HcalGeometry *>(geom.getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
274 
275  if (doHGCAL) {
276  eegeom = static_cast<const HGCalGeometry *>(
277  geom.getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty));
278  // check if it's the new geometry
279  if (eegeom) {
280  geometryType_ = 1;
281  fhgeom = static_cast<const HGCalGeometry *>(
282  geom.getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty));
283  bhgeomnew = static_cast<const HGCalGeometry *>(
284  geom.getSubdetectorGeometry(DetId::HGCalHSc, ForwardSubdetector::ForwardEmpty));
285  } else {
286  geometryType_ = 0;
287  eegeom = static_cast<const HGCalGeometry *>(geom.getSubdetectorGeometry(DetId::Forward, HGCEE));
288  fhgeom = static_cast<const HGCalGeometry *>(geom.getSubdetectorGeometry(DetId::Forward, HGCHEF));
289  bhgeom = static_cast<const HcalGeometry *>(geom.getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
290  }
291  hgtopo_[0] = &(eegeom->topology());
292  hgtopo_[1] = &(fhgeom->topology());
293  if (bhgeomnew)
294  hgtopo_[2] = &(bhgeomnew->topology());
295 
296  for (unsigned i = 0; i < 3; ++i) {
297  if (hgtopo_[i])
298  hgddd_[i] = &(hgtopo_[i]->dddConstants());
299  }
300  }
301 
302  if (bhgeom) {
303  hcddd_ = bhgeom->topology().dddConstants();
304  }
305  }
306 }
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 103 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and fillSimHits().

◆ doHGCAL

bool CaloTruthAccumulator::doHGCAL
private

Definition at line 142 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ genParticleLabel_

edm::InputTag CaloTruthAccumulator::genParticleLabel_
private

Definition at line 104 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

◆ geometryType_

int CaloTruthAccumulator::geometryType_
private

Definition at line 141 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ geomToken_

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

Definition at line 107 of file CaloTruthAccumulator.cc.

Referenced by initializeEvent().

◆ geomWatcher_

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

Definition at line 108 of file CaloTruthAccumulator.cc.

Referenced by initializeEvent().

◆ hcddd_

const HcalDDDRecConstants* CaloTruthAccumulator::hcddd_ = nullptr
private

Definition at line 137 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 106 of file CaloTruthAccumulator.cc.

Referenced by accumulate(), and CaloTruthAccumulator().

◆ hgddd_

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

Definition at line 136 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ hgtopo_

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

Definition at line 135 of file CaloTruthAccumulator.cc.

Referenced by fillSimHits(), and initializeEvent().

◆ hSimTracks

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

Definition at line 100 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ hSimVertices

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

Definition at line 101 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ m_caloParticles

calo_particles CaloTruthAccumulator::m_caloParticles
private

Definition at line 139 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and finalizeEvent().

◆ m_detIdToTotalSimEnergy

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

Definition at line 82 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 83 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 90 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 96 of file CaloTruthAccumulator.cc.

Referenced by accumulate().

◆ maxPseudoRapidity_

const double CaloTruthAccumulator::maxPseudoRapidity_
private

Definition at line 110 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ messageCategory_

const std::string CaloTruthAccumulator::messageCategory_
private

Definition at line 80 of file CaloTruthAccumulator.cc.

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

◆ minEnergy_

const double CaloTruthAccumulator::minEnergy_
private

Definition at line 110 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

◆ output_

OutputCollections CaloTruthAccumulator::output_
private

Definition at line 138 of file CaloTruthAccumulator.cc.

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

◆ premixStage1_

const bool CaloTruthAccumulator::premixStage1_
private

Definition at line 111 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and finalizeEvent().

◆ simTrackLabel_

const edm::InputTag CaloTruthAccumulator::simTrackLabel_
private

Definition at line 98 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

◆ simVertexLabel_

const edm::InputTag CaloTruthAccumulator::simVertexLabel_
private

Definition at line 99 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().