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::ProducerBase &mixMod, edm::ConsumesCollector &iC)
 
- Public Member Functions inherited from DigiAccumulatorMixMod
virtual void accumulate (edm::Event const &event, edm::EventSetup const &setup)=0
 
virtual void accumulate (PileUpEventPrincipal const &event, edm::EventSetup const &setup, edm::StreamID const &)=0
 
virtual void beginRun (edm::Run const &run, edm::EventSetup const &setup)
 
 DigiAccumulatorMixMod ()
 
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 void finalizeEvent (edm::Event &event, edm::EventSetup const &setup)=0
 
virtual PileupMixingContentgetEventPileupInfo ()
 
virtual void initializeBunchCrossing (edm::Event const &event, edm::EventSetup const &setup, int bunchCrossing)
 
virtual void initializeEvent (edm::Event const &event, edm::EventSetup const &setup)=0
 
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...
 
void beginLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) override
 
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_
 
edm::InputTag genParticleLabel_
 
int geometryType_
 
const HcalDDDRecConstantshcddd_ = 0
 
edm::InputTag hepMCproductLabel_
 Needed to add HepMC::GenVertex to SimVertex. More...
 
const HGCalDDDConstantshgddd_ [3] = { 0 , 0 , 0 }
 
const HGCalTopologyhgtopo_ [3] = { 0 , 0 , 0 }
 
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 124 of file CaloTruthAccumulator.cc.

Constructor & Destructor Documentation

CaloTruthAccumulator::CaloTruthAccumulator ( const edm::ParameterSet config,
edm::ProducerBase mixMod,
edm::ConsumesCollector iC 
)
explicit

Definition at line 357 of file CaloTruthAccumulator.cc.

References collectionTags_, edm::ConsumesCollector::consumes(), genParticleLabel_, edm::ParameterSet::getParameterNames(), edm::ParameterSet::getParameterSet(), hepMCproductLabel_, premixStage1_, edm::ProductRegistryHelper::produces(), simTrackLabel_, and simVertexLabel_.

360  : messageCategory_("CaloTruthAccumulator"),
361  maximumPreviousBunchCrossing_(config.getParameter<unsigned int>("maximumPreviousBunchCrossing")),
362  maximumSubsequentBunchCrossing_(config.getParameter<unsigned int>("maximumSubsequentBunchCrossing")),
363  simTrackLabel_(config.getParameter<edm::InputTag>("simTrackCollection")),
364  simVertexLabel_(config.getParameter<edm::InputTag>("simVertexCollection")),
365  collectionTags_(),
366  genParticleLabel_(config.getParameter<edm::InputTag>("genParticleCollection")),
367  hepMCproductLabel_(config.getParameter<edm::InputTag>("HepMCProductLabel")),
368  minEnergy_(config.getParameter<double>("MinEnergy")),
369  maxPseudoRapidity_(config.getParameter<double>("MaxPseudoRapidity")),
370  premixStage1_(config.getParameter<bool>("premixStage1")),
371  geometryType_(-1) {
372  mixMod.produces<SimClusterCollection>("MergedCaloTruth");
373  mixMod.produces<CaloParticleCollection>("MergedCaloTruth");
374  if (premixStage1_) {
375  mixMod.produces<std::vector<std::pair<unsigned int, float>>>("MergedCaloTruth");
376  }
377 
378  iC.consumes<std::vector<SimTrack>>(simTrackLabel_);
379  iC.consumes<std::vector<SimVertex>>(simVertexLabel_);
380  iC.consumes<std::vector<reco::GenParticle>>(genParticleLabel_);
381  iC.consumes<std::vector<int>>(genParticleLabel_);
382  iC.consumes<std::vector<int>>(hepMCproductLabel_);
383 
384  // Fill the collection tags
385  const edm::ParameterSet &simHitCollectionConfig = config.getParameterSet("simHitCollections");
386  std::vector<std::string> parameterNames = simHitCollectionConfig.getParameterNames();
387 
388  for (auto const &parameterName : parameterNames) {
389  std::vector<edm::InputTag> tags = simHitCollectionConfig.getParameter<std::vector<edm::InputTag>>(parameterName);
390  collectionTags_.insert(collectionTags_.end(), tags.begin(), tags.end());
391  }
392 
393  for (auto const &collectionTag : collectionTags_) {
394  iC.consumes<std::vector<PCaloHit>>(collectionTag);
395  }
396 }
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const unsigned int maximumSubsequentBunchCrossing_
std::vector< edm::InputTag > collectionTags_
edm::InputTag hepMCproductLabel_
Needed to add HepMC::GenVertex to SimVertex.
const std::string messageCategory_
const edm::InputTag simVertexLabel_
std::vector< std::string > getParameterNames() const
const edm::InputTag simTrackLabel_
ParameterSet const & getParameterSet(std::string const &) const
std::vector< CaloParticle > CaloParticleCollection
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
const unsigned int maximumPreviousBunchCrossing_

Member Function Documentation

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

Referenced by initializeEvent().

void CaloTruthAccumulator::accumulate ( const PileUpEventPrincipal event,
const edm::EventSetup setup,
edm::StreamID const &   
)
overrideprivate
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 523 of file CaloTruthAccumulator.cc.

References funct::abs(), gather_cfg::cout, EdgeProperty::cumulative_simHits, DEBUG, SelectingProcedure_cff::decay, fillSimHits(), genParticleLabel_, hSimTracks, hSimVertices, mps_fire::i, training_settings::idx, IfLogDebug, m_caloParticles, m_simHitBarcodeToIndex, maxPseudoRapidity_, messageCategory_, minEnergy_, CoreSimTrack::momentum(), SimTrack::noGenpart(), PFRecoTauDiscriminationByIsolation_cfi::offset, output_, put(), edm::second(), EdgeProperty::simTrack, simTrackLabel_, simVertexLabel_, findQualityFiles::size, lumiQTWidget::t, l1t::tracks, findQualityFiles::v, electrons_cff::vertices, and runTauDisplay::vis.

Referenced by initializeEvent().

525  {
527  edm::Handle<std::vector<int>> hGenParticleIndices;
528 
529  event.getByLabel(simTrackLabel_, hSimTracks);
530  event.getByLabel(simVertexLabel_, hSimVertices);
531 
532  event.getByLabel(genParticleLabel_, hGenParticles);
533  event.getByLabel(genParticleLabel_, hGenParticleIndices);
534 
535  std::vector<std::pair<DetId, const PCaloHit *>> simHitPointers;
536  std::unordered_map<int, std::map<int, float>> simTrackDetIdEnergyMap;
537  fillSimHits(simHitPointers, simTrackDetIdEnergyMap, event, setup);
538 
539  // Clear maps from previous event fill them for this one
540  m_simHitBarcodeToIndex.clear();
541  for (unsigned int i = 0; i < simHitPointers.size(); ++i) {
542  m_simHitBarcodeToIndex.emplace(simHitPointers[i].second->geantTrackId(), i);
543  }
544 
545  auto const &tracks = *hSimTracks;
546  auto const &vertices = *hSimVertices;
547  std::unordered_map<int, int> trackid_to_track_index;
549  int idx = 0;
550 
551  IfLogDebug(DEBUG, messageCategory_) << " TRACKS" << std::endl;
552  for (auto const &t : tracks) {
553  IfLogDebug(DEBUG, messageCategory_) << " " << idx << "\t" << t.trackId() << "\t" << t << std::endl;
554  trackid_to_track_index[t.trackId()] = idx;
555  idx++;
556  }
557 
584  idx = 0;
585  std::vector<int> used_sim_tracks(tracks.size(), 0);
586  std::vector<int> collapsed_vertices(vertices.size(), 0);
587  IfLogDebug(DEBUG, messageCategory_) << " VERTICES" << std::endl;
588  for (auto const &v : vertices) {
589  IfLogDebug(DEBUG, messageCategory_) << " " << idx++ << "\t" << v << std::endl;
590  if (v.parentIndex() != -1) {
591  auto trk_idx = trackid_to_track_index[v.parentIndex()];
592  auto origin_vtx = tracks[trk_idx].vertIndex();
593  if (used_sim_tracks[trk_idx]) {
594  // collapse the vertex into the original first vertex we saw associated
595  // to this track. Omit adding the edge in order to avoid double
596  // counting of the very same particles and its associated hits.
597  collapsed_vertices[v.vertexId()] = used_sim_tracks[trk_idx];
598  continue;
599  }
600  // Perform the actual vertex collapsing, if needed.
601  if (collapsed_vertices[origin_vtx])
602  origin_vtx = collapsed_vertices[origin_vtx];
603  add_edge(origin_vtx,
604  v.vertexId(),
605  EdgeProperty(&tracks[trk_idx], simTrackDetIdEnergyMap[v.parentIndex()].size(), 0),
606  decay);
607  used_sim_tracks[trk_idx] = v.vertexId();
608  }
609  }
610  // Build the motherParticle property to each vertex
611  auto const &vertexMothersProp = get(vertex_name, decay);
612  // Now recover the particles that did not decay. Append them with an index
613  // bigger than the size of the generated vertices.
614  int offset = vertices.size();
615  for (size_t i = 0; i < tracks.size(); ++i) {
616  if (!used_sim_tracks[i]) {
617  auto origin_vtx = tracks[i].vertIndex();
618  // Perform the actual vertex collapsing, if needed.
619  if (collapsed_vertices[origin_vtx])
620  origin_vtx = collapsed_vertices[origin_vtx];
621  add_edge(
622  origin_vtx, offset, EdgeProperty(&tracks[i], simTrackDetIdEnergyMap[tracks[i].trackId()].size(), 0), decay);
623  // The properties for "fake" vertices associated to stable particles have
624  // to be set inside this loop, since they do not belong to the vertices
625  // collection and would be skipped by that loop (coming next)
626  put(vertexMothersProp, offset, VertexProperty(&tracks[i], 0));
627  offset++;
628  }
629  }
630  for (auto const &v : vertices) {
631  if (v.parentIndex() != -1) {
632  // Skip collapsed_vertices
633  if (collapsed_vertices[v.vertexId()])
634  continue;
635  put(vertexMothersProp, v.vertexId(), VertexProperty(&tracks[trackid_to_track_index[v.parentIndex()]], 0));
636  }
637  }
638  SimHitsAccumulator_dfs_visitor vis;
639  depth_first_search(decay, visitor(vis));
640  CaloParticle_dfs_visitor caloParticleCreator(
641  output_,
644  simTrackDetIdEnergyMap,
645  [&](EdgeProperty &edge_property) -> bool {
646  // Apply selection on SimTracks in order to promote them to be
647  // CaloParticles. The function returns TRUE if the particle satisfies
648  // the selection, FALSE otherwise. Therefore the correct logic to select
649  // the particle is to ask for TRUE as return value.
650  return (edge_property.cumulative_simHits != 0 and !edge_property.simTrack->noGenpart() and
651  edge_property.simTrack->momentum().E() > minEnergy_ and
652  std::abs(edge_property.simTrack->momentum().Eta()) < maxPseudoRapidity_);
653  });
654  depth_first_search(decay, visitor(caloParticleCreator));
655 
656 #if DEBUG
657  boost::write_graphviz(std::cout,
658  decay,
659  make_label_writer(make_transform_value_property_map(&graphviz_vertex, get(vertex_name, decay))),
660  make_label_writer(make_transform_value_property_map(&graphviz_edge, get(edge_weight, decay))));
661 #endif
662 }
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...
void put(edm::Event &evt, double value, const char *instanceName)
const SimTrack * simTrack
U second(std::pair< T, U > const &p)
bool noGenpart() const
Definition: SimTrack.h:35
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
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
adjacency_list< listS, vecS, directedS, VertexMotherParticleProperty, EdgeParticleClustersProperty > DecayChain
#define IfLogDebug(cond, cat)
Definition: event.py:1
#define DEBUG
void CaloTruthAccumulator::beginLuminosityBlock ( edm::LuminosityBlock const &  lumi,
edm::EventSetup const &  setup 
)
overrideprivatevirtual

Reimplemented from DigiAccumulatorMixMod.

Definition at line 398 of file CaloTruthAccumulator.cc.

References HGCalTopology::dddConstants(), HcalTopology::dddConstants(), DetId::Forward, ForwardEmpty, relativeConstraints::geom, geometryType_, edm::EventSetup::get(), CaloGeometry::getSubdetectorGeometry(), DetId::Hcal, HcalEndcap, hcddd_, DetId::HGCalEE, DetId::HGCalHSc, DetId::HGCalHSi, HGCEE, HGCHEF, hgddd_, hgtopo_, mps_fire::i, HGCalGeometry::topology(), and HcalGeometry::topology().

398  {
400  iSetup.get<CaloGeometryRecord>().get(geom);
401  const HGCalGeometry *eegeom = nullptr, *fhgeom = nullptr, *bhgeomnew = nullptr;
402  const HcalGeometry *bhgeom = nullptr;
403 
404  eegeom = static_cast<const HGCalGeometry *>(
406  // check if it's the new geometry
407  if (eegeom) {
408  geometryType_ = 1;
409  fhgeom = static_cast<const HGCalGeometry *>(
411  bhgeomnew = static_cast<const HGCalGeometry *>(
413  } else {
414  geometryType_ = 0;
415  eegeom = static_cast<const HGCalGeometry *>(geom->getSubdetectorGeometry(DetId::Forward, HGCEE));
416  fhgeom = static_cast<const HGCalGeometry *>(geom->getSubdetectorGeometry(DetId::Forward, HGCHEF));
417  bhgeom = static_cast<const HcalGeometry *>(geom->getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
418  }
419  hgtopo_[0] = &(eegeom->topology());
420  hgtopo_[1] = &(fhgeom->topology());
421  if (bhgeomnew)
422  hgtopo_[2] = &(bhgeomnew->topology());
423 
424  for (unsigned i = 0; i < 3; ++i) {
425  if (hgtopo_[i])
426  hgddd_[i] = &(hgtopo_[i]->dddConstants());
427  }
428 
429  if (bhgeom)
430  hcddd_ = bhgeom->topology().dddConstants();
431 }
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:49
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:167
const HGCalTopology * hgtopo_[3]
const HcalTopology & topology() const
Definition: HcalGeometry.h:117
const HGCalTopology & topology() const
const HGCalDDDConstants * hgddd_[3]
const HGCalDDDConstants & dddConstants() const
const HcalDDDRecConstants * hcddd_
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 665 of file CaloTruthAccumulator.cc.

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

Referenced by accumulateEvent().

668  {
669  for (auto const &collectionTag : collectionTags_) {
671  const bool isHcal = (collectionTag.instance().find("HcalHits") != std::string::npos);
672  event.getByLabel(collectionTag, hSimHits);
673  for (auto const &simHit : *hSimHits) {
674  DetId id(0);
675  const uint32_t simId = simHit.id();
676  if (geometryType_ == 1) {
677  // no test numbering in new geometry
678  id = simId;
679  } else if (isHcal) {
681  if (hid.subdet() == HcalEndcap)
682  id = hid;
683  } else {
684  int subdet, layer, cell, sec, subsec, zp;
685  HGCalTestNumbering::unpackHexagonIndex(simId, subdet, zp, layer, sec, subsec, cell);
686  const HGCalDDDConstants *ddd = hgddd_[subdet - 3];
687  std::pair<int, int> recoLayerCell = ddd->simToReco(cell, layer, sec, hgtopo_[subdet - 3]->detectorType());
688  cell = recoLayerCell.first;
689  layer = recoLayerCell.second;
690  // skip simhits with bad barcodes or non-existant layers
691  if (layer == -1 || simHit.geantTrackId() == 0)
692  continue;
693  id = HGCalDetId((ForwardSubdetector)subdet, zp, layer, subsec, sec, cell);
694  }
695 
696  if (DetId(0) == id)
697  continue;
698 
699  uint32_t detId = id.rawId();
700  returnValue.emplace_back(id, &simHit);
701  simTrackDetIdEnergyMap[simHit.geantTrackId()][id.rawId()] += simHit.energy();
702 
703  m_detIdToTotalSimEnergy[detId] += simHit.energy();
704  }
705  } // end of loop over InputTags
706 }
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:146
const HGCalTopology * hgtopo_[3]
std::vector< edm::InputTag > collectionTags_
ForwardSubdetector
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
const HGCalDDDConstants * hgddd_[3]
Definition: DetId.h:18
const HcalDDDRecConstants * hcddd_
DetId relabel(const uint32_t testId) const
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
void CaloTruthAccumulator::finalizeEvent ( edm::Event event,
const edm::EventSetup setup 
)
overrideprivate

Definition at line 470 of file CaloTruthAccumulator.cc.

References SimCluster::addRecHitAndFraction(), CaloParticle::addSimCluster(), SimCluster::clearHitsAndFractions(), popcon2dropbox::copy(), SimDataFormats::CaloAnalysis::cp, dedxEstimators_cff::fraction, SimCluster::hits_and_fractions(), mps_fire::i, m_caloParticles, m_detIdToTotalSimEnergy, m_simHitBarcodeToIndex, messageCategory_, eostools::move(), output_, CaloTruthAccumulator::OutputCollections::pCaloParticles, premixStage1_, CaloTruthAccumulator::OutputCollections::pSimClusters, SimDataFormats::CaloAnalysis::sc, CaloTruthAccumulator::calo_particles::sc_start_, CaloTruthAccumulator::calo_particles::sc_stop_, edm::swap(), and CaloTruthAccumulator::calo_particles::swap().

470  {
471  edm::LogInfo(messageCategory_) << "Adding " << output_.pSimClusters->size() << " SimParticles and "
472  << output_.pCaloParticles->size() << " CaloParticles to the event.";
473 
474  // We need to normalize the hits and energies into hits and fractions (since
475  // we have looped over all pileup events)
476  // For premixing stage1 we keep the energies, they will be normalized to
477  // fractions in stage2
478 
479  if (premixStage1_) {
480  auto totalEnergies = std::make_unique<std::vector<std::pair<unsigned int, float>>>();
481  totalEnergies->reserve(m_detIdToTotalSimEnergy.size());
482  std::copy(m_detIdToTotalSimEnergy.begin(), m_detIdToTotalSimEnergy.end(), std::back_inserter(*totalEnergies));
483  std::sort(totalEnergies->begin(), totalEnergies->end());
484  event.put(std::move(totalEnergies), "MergedCaloTruth");
485  } else {
486  for (auto &sc : *(output_.pSimClusters)) {
487  auto hitsAndEnergies = sc.hits_and_fractions();
489  for (auto &hAndE : hitsAndEnergies) {
490  const float totalenergy = m_detIdToTotalSimEnergy[hAndE.first];
491  float fraction = 0.;
492  if (totalenergy > 0)
493  fraction = hAndE.second / totalenergy;
494  else
496  << "TotalSimEnergy for hit " << hAndE.first << " is 0! The fraction for this hit cannot be computed.";
497  sc.addRecHitAndFraction(hAndE.first, fraction);
498  }
499  }
500  }
501 
502  // save the SimCluster orphan handle so we can fill the calo particles
503  auto scHandle = event.put(std::move(output_.pSimClusters), "MergedCaloTruth");
504 
505  // now fill the calo particles
506  for (unsigned i = 0; i < output_.pCaloParticles->size(); ++i) {
507  auto &cp = (*output_.pCaloParticles)[i];
508  for (unsigned j = m_caloParticles.sc_start_[i]; j < m_caloParticles.sc_stop_[i]; ++j) {
509  edm::Ref<SimClusterCollection> ref(scHandle, j);
510  cp.addSimCluster(ref);
511  }
512  }
513 
514  event.put(std::move(output_.pCaloParticles), "MergedCaloTruth");
515 
516  calo_particles().swap(m_caloParticles);
517 
518  std::unordered_map<Index_t, float>().swap(m_detIdToTotalSimEnergy);
519  std::unordered_multimap<Barcode_t, Index_t>().swap(m_simHitBarcodeToIndex);
520 }
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
def copy(args, dbName)
void addRecHitAndFraction(uint32_t hit, float fraction)
add rechit with fraction
Definition: SimCluster.h:175
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
const std::string messageCategory_
void clearHitsAndFractions()
clear the hits and fractions list
Definition: SimCluster.h:190
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
void addSimCluster(const SimClusterRef &ref)
Definition: CaloParticle.h:60
std::unique_ptr< CaloParticleCollection > pCaloParticles
std::unique_ptr< SimClusterCollection > pSimClusters
def move(src, dest)
Definition: eostools.py:511
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
Definition: SimCluster.h:181
void CaloTruthAccumulator::initializeEvent ( const edm::Event event,
const edm::EventSetup setup 
)
overrideprivate

Member Data Documentation

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

Definition at line 172 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and fillSimHits().

edm::InputTag CaloTruthAccumulator::genParticleLabel_
private

Definition at line 173 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

int CaloTruthAccumulator::geometryType_
private

Definition at line 208 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

const HcalDDDRecConstants* CaloTruthAccumulator::hcddd_ = 0
private

Definition at line 204 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

edm::InputTag CaloTruthAccumulator::hepMCproductLabel_
private

Needed to add HepMC::GenVertex to SimVertex.

Definition at line 175 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and initializeEvent().

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

Definition at line 203 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

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

Definition at line 202 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

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

Definition at line 169 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

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

Definition at line 170 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

calo_particles CaloTruthAccumulator::m_caloParticles
private

Definition at line 206 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and finalizeEvent().

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

Definition at line 151 of file CaloTruthAccumulator.cc.

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

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

Definition at line 152 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and finalizeEvent().

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

Referenced by initializeEvent().

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

Referenced by initializeEvent().

const double CaloTruthAccumulator::maxPseudoRapidity_
private

Definition at line 177 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

const std::string CaloTruthAccumulator::messageCategory_
private

Definition at line 149 of file CaloTruthAccumulator.cc.

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

const double CaloTruthAccumulator::minEnergy_
private

Definition at line 177 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

OutputCollections CaloTruthAccumulator::output_
private

Definition at line 205 of file CaloTruthAccumulator.cc.

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

const bool CaloTruthAccumulator::premixStage1_
private

Definition at line 178 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and finalizeEvent().

const edm::InputTag CaloTruthAccumulator::simTrackLabel_
private

Definition at line 167 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

const edm::InputTag CaloTruthAccumulator::simVertexLabel_
private

Definition at line 168 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().