CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
PreMixingCaloParticleWorker Class Reference
Inheritance diagram for PreMixingCaloParticleWorker:
PreMixingWorker

Public Member Functions

void addPileups (PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override
 
void addSignals (edm::Event const &iEvent, edm::EventSetup const &iSetup) override
 
void initializeEvent (edm::Event const &iEvent, edm::EventSetup const &iSetup) override
 
 PreMixingCaloParticleWorker (const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
 
void put (edm::Event &iEvent, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bunchSpacing) override
 
 ~PreMixingCaloParticleWorker () override=default
 
- Public Member Functions inherited from PreMixingWorker
virtual void beginLuminosityBlock (edm::LuminosityBlock const &iLumi, edm::EventSetup const &iSetup)
 
virtual void beginRun (edm::Run const &iRun, edm::EventSetup const &iSetup)
 
virtual void endRun ()
 
virtual void finalizeBunchCrossing (edm::Event &iEvent, edm::EventSetup const &iSetup, int bunchCrossing)
 
virtual void initializeBunchCrossing (edm::Event const &iEvent, edm::EventSetup const &iSetup, int bunchCrossing)
 
 PreMixingWorker ()=default
 
virtual ~PreMixingWorker ()=default
 

Private Types

using EnergyMap = std::vector< std::pair< unsigned, float > >
 

Private Member Functions

void add (const SimClusterCollection &clusters, const CaloParticleCollection &particles, const EnergyMap &energyMap)
 

Private Attributes

SimClusterRefProd clusterRef_
 
std::unique_ptr< SimClusterCollectionnewClusters_
 
std::unique_ptr< CaloParticleCollectionnewParticles_
 
std::string particleCollectionDM_
 
edm::InputTag particlePileInputTag_
 
edm::EDGetTokenT< SimClusterCollectionsigClusterToken_
 
edm::EDGetTokenT< EnergyMapsigEnergyToken_
 
edm::EDGetTokenT< CaloParticleCollectionsigParticleToken_
 
std::unordered_map< unsigned, float > totalEnergy_
 

Detailed Description

Definition at line 17 of file PreMixingCaloParticleWorker.cc.

Member Typedef Documentation

◆ EnergyMap

using PreMixingCaloParticleWorker::EnergyMap = std::vector<std::pair<unsigned, float> >
private

Definition at line 31 of file PreMixingCaloParticleWorker.cc.

Constructor & Destructor Documentation

◆ PreMixingCaloParticleWorker()

PreMixingCaloParticleWorker::PreMixingCaloParticleWorker ( const edm::ParameterSet ps,
edm::ProducesCollector  producesCollector,
edm::ConsumesCollector &&  iC 
)

Definition at line 49 of file PreMixingCaloParticleWorker.cc.

References particleCollectionDM_, and edm::ProducesCollector::produces().

56  particleCollectionDM_(ps.getParameter<std::string>("collectionDM")) {
59 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
std::vector< std::pair< unsigned, float > > EnergyMap
std::vector< CaloParticle > CaloParticleCollection
std::vector< SimCluster > SimClusterCollection

◆ ~PreMixingCaloParticleWorker()

PreMixingCaloParticleWorker::~PreMixingCaloParticleWorker ( )
overridedefault

Member Function Documentation

◆ add()

void PreMixingCaloParticleWorker::add ( const SimClusterCollection clusters,
const CaloParticleCollection particles,
const EnergyMap energyMap 
)
private

Definition at line 101 of file PreMixingCaloParticleWorker.cc.

References clusterRef_, bsc_activity_cfg::clusters, filterCSVwithJSON::copy, hcalRecHitTable_cff::energy, newClusters_, newParticles_, AlCaHLTBitMon_ParallelJobs::p, ecalTrigSettings_cff::particles, and totalEnergy_.

Referenced by addPileups(), addSignals(), and counter.Counter::register().

103  {
104  const size_t startingIndex = newClusters_->size();
105 
106  // Copy SimClusters
107  newClusters_->reserve(newClusters_->size() + clusters.size());
108  std::copy(clusters.begin(), clusters.end(), std::back_inserter(*newClusters_));
109 
110  // Copy CaloParticles
111  newParticles_->reserve(newParticles_->size() + particles.size());
112  for (const auto &p : particles) {
113  newParticles_->push_back(p);
114  auto &particle = newParticles_->back();
115 
116  // re-key the refs to SimClusters
117  particle.clearSimClusters();
118  for (const auto &ref : p.simClusters()) {
119  particle.addSimCluster(SimClusterRef(clusterRef_, startingIndex + ref.index()));
120  }
121  }
122 
123  // Add energies
124  for (const auto &elem : energy) {
125  totalEnergy_[elem.first] += elem.second;
126  }
127 }
edm::Ref< SimClusterCollection > SimClusterRef
Definition: SimClusterFwd.h:10
std::unordered_map< unsigned, float > totalEnergy_
std::unique_ptr< SimClusterCollection > newClusters_
std::unique_ptr< CaloParticleCollection > newParticles_

◆ addPileups()

void PreMixingCaloParticleWorker::addPileups ( PileUpEventPrincipal const &  pep,
edm::EventSetup const &  iSetup 
)
overridevirtual

◆ addSignals()

void PreMixingCaloParticleWorker::addSignals ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 71 of file PreMixingCaloParticleWorker.cc.

References add(), bsc_activity_cfg::clusters, hcalRecHitTable_cff::energy, iEvent, ecalTrigSettings_cff::particles, sigClusterToken_, sigEnergyToken_, and sigParticleToken_.

71  {
73  iEvent.getByToken(sigClusterToken_, clusters);
74 
76  iEvent.getByToken(sigParticleToken_, particles);
77 
79  iEvent.getByToken(sigEnergyToken_, energy);
80 
81  if (clusters.isValid() && particles.isValid() && energy.isValid()) {
83  }
84 }
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
void add(const SimClusterCollection &clusters, const CaloParticleCollection &particles, const EnergyMap &energyMap)

◆ initializeEvent()

void PreMixingCaloParticleWorker::initializeEvent ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 61 of file PreMixingCaloParticleWorker.cc.

References clusterRef_, iEvent, newClusters_, newParticles_, and particleCollectionDM_.

61  {
62  newClusters_ = std::make_unique<SimClusterCollection>();
63  newParticles_ = std::make_unique<CaloParticleCollection>();
64 
65  // need RefProds in order to re-key the CaloParticle->SimCluster refs
66  // TODO: try to remove const_cast, requires making Event non-const in
67  // BMixingModule::initializeEvent
68  clusterRef_ = const_cast<edm::Event &>(iEvent).getRefBeforePut<SimClusterCollection>(particleCollectionDM_);
69 }
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< SimClusterCollection > newClusters_
std::unique_ptr< CaloParticleCollection > newParticles_

◆ put()

void PreMixingCaloParticleWorker::put ( edm::Event iEvent,
edm::EventSetup const &  iSetup,
std::vector< PileupSummaryInfo > const &  ps,
int  bunchSpacing 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 129 of file PreMixingCaloParticleWorker.cc.

References HLT_2024v11_cff::fraction, iEvent, eostools::move(), newClusters_, newParticles_, particleCollectionDM_, and totalEnergy_.

132  {
133  for (auto &sc : *newClusters_) {
134  auto hitsAndEnergies = sc.hits_and_fractions();
135  sc.clearHitsAndFractions();
136  for (auto &hAndE : hitsAndEnergies) {
137  const float totalenergy = totalEnergy_[hAndE.first];
138  float fraction = 0.;
139  if (totalenergy > 0)
140  fraction = hAndE.second / totalenergy;
141  else
142  edm::LogWarning("PreMixingParticleWorker")
143  << "TotalSimEnergy for hit " << hAndE.first << " is 0! The fraction for this hit cannot be computed.";
144  sc.addRecHitAndFraction(hAndE.first, fraction);
145  }
146  }
147 
148  // clear memory
149  std::unordered_map<unsigned, float>{}.swap(totalEnergy_);
150 
153 }
int iEvent
Definition: GenABIO.cc:224
std::unordered_map< unsigned, float > totalEnergy_
std::unique_ptr< SimClusterCollection > newClusters_
Log< level::Warning, false > LogWarning
std::unique_ptr< CaloParticleCollection > newParticles_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ clusterRef_

SimClusterRefProd PreMixingCaloParticleWorker::clusterRef_
private

Definition at line 46 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), and initializeEvent().

◆ newClusters_

std::unique_ptr<SimClusterCollection> PreMixingCaloParticleWorker::newClusters_
private

Definition at line 44 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), initializeEvent(), and put().

◆ newParticles_

std::unique_ptr<CaloParticleCollection> PreMixingCaloParticleWorker::newParticles_
private

Definition at line 45 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), initializeEvent(), and put().

◆ particleCollectionDM_

std::string PreMixingCaloParticleWorker::particleCollectionDM_
private

◆ particlePileInputTag_

edm::InputTag PreMixingCaloParticleWorker::particlePileInputTag_
private

Definition at line 39 of file PreMixingCaloParticleWorker.cc.

Referenced by addPileups().

◆ sigClusterToken_

edm::EDGetTokenT<SimClusterCollection> PreMixingCaloParticleWorker::sigClusterToken_
private

Definition at line 35 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

◆ sigEnergyToken_

edm::EDGetTokenT<EnergyMap> PreMixingCaloParticleWorker::sigEnergyToken_
private

Definition at line 37 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

◆ sigParticleToken_

edm::EDGetTokenT<CaloParticleCollection> PreMixingCaloParticleWorker::sigParticleToken_
private

Definition at line 36 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

◆ totalEnergy_

std::unordered_map<unsigned, float> PreMixingCaloParticleWorker::totalEnergy_
private

Definition at line 42 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), and put().