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

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

369  : messageCategory_("CaloTruthAccumulator"),
371  config.getParameter<unsigned int>("maximumPreviousBunchCrossing")),
373  config.getParameter<unsigned int>("maximumSubsequentBunchCrossing")),
374  simTrackLabel_(config.getParameter<edm::InputTag>("simTrackCollection")),
375  simVertexLabel_(config.getParameter<edm::InputTag>("simVertexCollection")),
376  collectionTags_(),
377  genParticleLabel_(config.getParameter<edm::InputTag>("genParticleCollection")),
378  hepMCproductLabel_(config.getParameter<edm::InputTag>("HepMCProductLabel")),
379  minEnergy_(config.getParameter<double>("MinEnergy")),
380  maxPseudoRapidity_(config.getParameter<double>("MaxPseudoRapidity")),
381  premixStage1_(config.getParameter<bool>("premixStage1")),
382  geometryType_(-1)
383 {
384  mixMod.produces<SimClusterCollection>("MergedCaloTruth");
385  mixMod.produces<CaloParticleCollection>("MergedCaloTruth");
386  if(premixStage1_) {
387  mixMod.produces<std::vector<std::pair<unsigned int, float> > >("MergedCaloTruth");
388  }
389 
390  iC.consumes<std::vector<SimTrack> >(simTrackLabel_);
391  iC.consumes<std::vector<SimVertex> >(simVertexLabel_);
392  iC.consumes<std::vector<reco::GenParticle> >(genParticleLabel_);
393  iC.consumes<std::vector<int> >(genParticleLabel_);
394  iC.consumes<std::vector<int> >(hepMCproductLabel_);
395 
396  // Fill the collection tags
397  const edm::ParameterSet& simHitCollectionConfig = config.getParameterSet("simHitCollections");
398  std::vector<std::string> parameterNames = simHitCollectionConfig.getParameterNames();
399 
400  for (auto const& parameterName : parameterNames) {
401  std::vector<edm::InputTag> tags =
402  simHitCollectionConfig.getParameter<std::vector<edm::InputTag> >(parameterName);
403  collectionTags_.insert(collectionTags_.end(), tags.begin(), tags.end());
404  }
405 
406  for (auto const& collectionTag : collectionTags_) {
407  iC.consumes<std::vector<PCaloHit> >(collectionTag);
408  }
409 }
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 536 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().

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

412  {
414  iSetup.get<CaloGeometryRecord>().get(geom);
415  const HGCalGeometry *eegeom = nullptr, *fhgeom = nullptr, *bhgeomnew = nullptr;
416  const HcalGeometry* bhgeom = nullptr;
417 
419  //check if it's the new geometry
420  if(eegeom){
421  geometryType_ = 1;
424  }
425  else {
426  geometryType_ = 0;
427  eegeom = static_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(DetId::Forward, HGCEE));
428  fhgeom = static_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(DetId::Forward, HGCHEF));
429  bhgeom = static_cast<const HcalGeometry*>(geom->getSubdetectorGeometry(DetId::Hcal, HcalEndcap));
430  }
431  hgtopo_[0] = &(eegeom->topology());
432  hgtopo_[1] = &(fhgeom->topology());
433  if(bhgeomnew) hgtopo_[2] = &(bhgeomnew->topology());
434 
435  for (unsigned i = 0; i < 3; ++i) {
436  if(hgtopo_[i]) hgddd_[i] = &(hgtopo_[i]->dddConstants());
437  }
438 
439  if(bhgeom) hcddd_ = bhgeom->topology().dddConstants();
440 }
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 674 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().

677  {
678  for (auto const& collectionTag : collectionTags_) {
680  const bool isHcal = (collectionTag.instance().find("HcalHits") != std::string::npos);
681  event.getByLabel(collectionTag, hSimHits);
682  for (auto const& simHit : *hSimHits) {
683  DetId id(0);
684  const uint32_t simId = simHit.id();
685  if (geometryType_==1) {
686  //no test numbering in new geometry
687  id = simId;
688  }
689  else if (isHcal) {
691  if (hid.subdet() == HcalEndcap) id = hid;
692  } else {
693  int subdet, layer, cell, sec, subsec, zp;
694  HGCalTestNumbering::unpackHexagonIndex(simId, subdet, zp, layer, sec, subsec, cell);
695  const HGCalDDDConstants* ddd = hgddd_[subdet - 3];
696  std::pair<int, int> recoLayerCell =
697  ddd->simToReco(cell, layer, sec, hgtopo_[subdet - 3]->detectorType());
698  cell = recoLayerCell.first;
699  layer = recoLayerCell.second;
700  // skip simhits with bad barcodes or non-existant layers
701  if (layer == -1 || simHit.geantTrackId() == 0) continue;
702  id = HGCalDetId((ForwardSubdetector)subdet, zp, layer, subsec, sec, cell);
703  }
704 
705  if (DetId(0) == id) continue;
706 
707  uint32_t detId = id.rawId();
708  returnValue.emplace_back(id, &simHit);
709  simTrackDetIdEnergyMap[simHit.geantTrackId()][id.rawId()] += simHit.energy();
710 
711  m_detIdToTotalSimEnergy[detId] += simHit.energy();
712  }
713  } // end of loop over InputTags
714 }
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:142
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 482 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().

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

Referenced by CaloTruthAccumulator(), and fillSimHits().

edm::InputTag CaloTruthAccumulator::genParticleLabel_
private

Definition at line 175 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

int CaloTruthAccumulator::geometryType_
private

Definition at line 210 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

const HcalDDDRecConstants* CaloTruthAccumulator::hcddd_ = 0
private

Definition at line 206 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

edm::InputTag CaloTruthAccumulator::hepMCproductLabel_
private

Needed to add HepMC::GenVertex to SimVertex.

Definition at line 177 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and initializeEvent().

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

Definition at line 205 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

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

Definition at line 204 of file CaloTruthAccumulator.cc.

Referenced by beginLuminosityBlock(), and fillSimHits().

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

Definition at line 171 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

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

Definition at line 172 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

calo_particles CaloTruthAccumulator::m_caloParticles
private

Definition at line 208 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and finalizeEvent().

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

Definition at line 153 of file CaloTruthAccumulator.cc.

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

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

Definition at line 154 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 161 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 167 of file CaloTruthAccumulator.cc.

Referenced by initializeEvent().

const double CaloTruthAccumulator::maxPseudoRapidity_
private

Definition at line 179 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

const std::string CaloTruthAccumulator::messageCategory_
private

Definition at line 151 of file CaloTruthAccumulator.cc.

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

const double CaloTruthAccumulator::minEnergy_
private

Definition at line 179 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent().

OutputCollections CaloTruthAccumulator::output_
private

Definition at line 207 of file CaloTruthAccumulator.cc.

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

const bool CaloTruthAccumulator::premixStage1_
private

Definition at line 180 of file CaloTruthAccumulator.cc.

Referenced by CaloTruthAccumulator(), and finalizeEvent().

const edm::InputTag CaloTruthAccumulator::simTrackLabel_
private

Definition at line 169 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().

const edm::InputTag CaloTruthAccumulator::simVertexLabel_
private

Definition at line 170 of file CaloTruthAccumulator.cc.

Referenced by accumulateEvent(), and CaloTruthAccumulator().