CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
< SimClusterCollection
newClusters_
 
std::unique_ptr
< CaloParticleCollection
newParticles_
 
std::string particleCollectionDM_
 
edm::InputTag particlePileInputTag_
 
edm::EDGetTokenT
< SimClusterCollection
sigClusterToken_
 
edm::EDGetTokenT< EnergyMapsigEnergyToken_
 
edm::EDGetTokenT
< CaloParticleCollection
sigParticleToken_
 
std::unordered_map< unsigned,
float > 
totalEnergy_
 

Detailed Description

Definition at line 17 of file PreMixingCaloParticleWorker.cc.

Member Typedef Documentation

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

Definition at line 31 of file PreMixingCaloParticleWorker.cc.

Constructor & Destructor Documentation

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)
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< CaloParticle > CaloParticleCollection
std::vector< std::pair< unsigned, float >> EnergyMap
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
PreMixingCaloParticleWorker::~PreMixingCaloParticleWorker ( )
overridedefault

Member Function Documentation

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

Definition at line 101 of file PreMixingCaloParticleWorker.cc.

References clusterRef_, filterCSVwithJSON::copy, newClusters_, newParticles_, AlCaHLTBitMon_ParallelJobs::p, 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_
void PreMixingCaloParticleWorker::addPileups ( PileUpEventPrincipal const &  pep,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 86 of file PreMixingCaloParticleWorker.cc.

References add(), HLT_FULL_cff::clusters, relval_parameters_module::energy, PileUpEventPrincipal::getByLabel(), edm::HandleBase::isValid(), particlePileInputTag_, and HLT_FULL_cff::particles.

86  {
88  pep.getByLabel(particlePileInputTag_, clusters);
89 
91  pep.getByLabel(particlePileInputTag_, particles);
92 
94  pep.getByLabel(particlePileInputTag_, energy);
95 
96  if (clusters.isValid() && particles.isValid() && energy.isValid()) {
97  add(*clusters, *particles, *energy);
98  }
99 }
bool isValid() const
Definition: HandleBase.h:70
void add(const SimClusterCollection &clusters, const CaloParticleCollection &particles, const EnergyMap &energyMap)
void PreMixingCaloParticleWorker::addSignals ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 71 of file PreMixingCaloParticleWorker.cc.

References add(), HLT_FULL_cff::clusters, relval_parameters_module::energy, edm::Event::getByToken(), edm::HandleBase::isValid(), HLT_FULL_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()) {
82  add(*clusters, *particles, *energy);
83  }
84 }
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
bool isValid() const
Definition: HandleBase.h:70
void add(const SimClusterCollection &clusters, const CaloParticleCollection &particles, const EnergyMap &energyMap)
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_
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_FULL_cff::fraction, eostools::move(), newClusters_, newParticles_, particleCollectionDM_, edm::Event::put(), 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 
151  iEvent.put(std::move(newClusters_), particleCollectionDM_);
153 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::unordered_map< unsigned, float > totalEnergy_
def move
Definition: eostools.py:511
std::unique_ptr< SimClusterCollection > newClusters_
Log< level::Warning, false > LogWarning
std::unique_ptr< CaloParticleCollection > newParticles_

Member Data Documentation

SimClusterRefProd PreMixingCaloParticleWorker::clusterRef_
private

Definition at line 46 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), and initializeEvent().

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

Definition at line 44 of file PreMixingCaloParticleWorker.cc.

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

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

Definition at line 45 of file PreMixingCaloParticleWorker.cc.

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

std::string PreMixingCaloParticleWorker::particleCollectionDM_
private
edm::InputTag PreMixingCaloParticleWorker::particlePileInputTag_
private

Definition at line 39 of file PreMixingCaloParticleWorker.cc.

Referenced by addPileups().

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

Definition at line 35 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

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

Definition at line 37 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

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

Definition at line 36 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

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

Definition at line 42 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), and put().