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::ProducerBase &producer, 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

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

Definition at line 28 of file PreMixingCaloParticleWorker.cc.

Constructor & Destructor Documentation

PreMixingCaloParticleWorker::PreMixingCaloParticleWorker ( const edm::ParameterSet ps,
edm::ProducerBase producer,
edm::ConsumesCollector &&  iC 
)

Definition at line 46 of file PreMixingCaloParticleWorker.cc.

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

46  :
52 {
55 }
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
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
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 96 of file PreMixingCaloParticleWorker.cc.

References clusterRef_, popcon2dropbox::copy(), HTMLExport::elem(), newClusters_, newParticles_, AlCaHLTBitMon_ParallelJobs::p, and totalEnergy_.

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

96  {
97  const size_t startingIndex = newClusters_->size();
98 
99  // Copy SimClusters
100  newClusters_->reserve(newClusters_->size() + clusters.size());
101  std::copy(clusters.begin(), clusters.end(), std::back_inserter(*newClusters_));
102 
103  // Copy CaloParticles
104  newParticles_->reserve(newParticles_->size() + particles.size());
105  for(const auto& p: particles) {
106  newParticles_->push_back(p);
107  auto& particle = newParticles_->back();
108 
109  // re-key the refs to SimClusters
110  particle.clearSimClusters();
111  for(const auto& ref: p.simClusters()) {
112  particle.addSimCluster(SimClusterRef(clusterRef_, startingIndex + ref.index()));
113  }
114  }
115 
116  // Add energies
117  for(const auto elem: energy) {
118  totalEnergy_[elem.first] += elem.second;
119  }
120 }
def copy(args, dbName)
edm::Ref< SimClusterCollection > SimClusterRef
Definition: SimClusterFwd.h:10
std::unordered_map< unsigned, float > totalEnergy_
std::unique_ptr< SimClusterCollection > newClusters_
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:18
std::unique_ptr< CaloParticleCollection > newParticles_
void PreMixingCaloParticleWorker::addPileups ( PileUpEventPrincipal const &  pep,
edm::EventSetup const &  iSetup 
)
overridevirtual

Implements PreMixingWorker.

Definition at line 81 of file PreMixingCaloParticleWorker.cc.

References add(), fastPrimaryVertexProducer_cfi::clusters, PileUpEventPrincipal::getByLabel(), edm::HandleBase::isValid(), particlePileInputTag_, and HadronAndPartonSelector_cfi::particles.

81  {
83  pep.getByLabel(particlePileInputTag_, clusters);
84 
86  pep.getByLabel(particlePileInputTag_, particles);
87 
89  pep.getByLabel(particlePileInputTag_, energy);
90 
91  if(clusters.isValid() && particles.isValid() && energy.isValid()) {
92  add(*clusters, *particles, *energy);
93  }
94 }
bool isValid() const
Definition: HandleBase.h:74
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 66 of file PreMixingCaloParticleWorker.cc.

References add(), fastPrimaryVertexProducer_cfi::clusters, edm::Event::getByToken(), edm::HandleBase::isValid(), HadronAndPartonSelector_cfi::particles, sigClusterToken_, sigEnergyToken_, and sigParticleToken_.

66  {
68  iEvent.getByToken(sigClusterToken_, clusters);
69 
71  iEvent.getByToken(sigParticleToken_, particles);
72 
74  iEvent.getByToken(sigEnergyToken_, energy);
75 
76  if(clusters.isValid() && particles.isValid() && energy.isValid()) {
77  add(*clusters, *particles, *energy);
78  }
79 }
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
bool isValid() const
Definition: HandleBase.h:74
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 57 of file PreMixingCaloParticleWorker.cc.

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

57  {
58  newClusters_ = std::make_unique<SimClusterCollection>();
59  newParticles_ = std::make_unique<CaloParticleCollection>();
60 
61  // need RefProds in order to re-key the CaloParticle->SimCluster refs
62  // TODO: try to remove const_cast, requires making Event non-const in BMixingModule::initializeEvent
63  clusterRef_ = const_cast<edm::Event&>(iEvent).getRefBeforePut<SimClusterCollection>(particleCollectionDM_);
64 }
int iEvent
Definition: GenABIO.cc:230
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 122 of file PreMixingCaloParticleWorker.cc.

References SimCluster::addRecHitAndFraction(), SimCluster::clearHitsAndFractions(), DEFINE_PREMIXING_WORKER, dedxEstimators_cff::fraction, SimCluster::hits_and_fractions(), eostools::move(), newClusters_, newParticles_, particleCollectionDM_, edm::Event::put(), SimDataFormats::CaloAnalysis::sc, and totalEnergy_.

122  {
123  for (auto& sc : *newClusters_) {
124  auto hitsAndEnergies = sc.hits_and_fractions();
126  for (auto& hAndE : hitsAndEnergies) {
127  const float totalenergy = totalEnergy_[hAndE.first];
128  float fraction = 0.;
129  if (totalenergy > 0)
130  fraction = hAndE.second / totalenergy;
131  else
132  edm::LogWarning("PreMixingParticleWorker") << "TotalSimEnergy for hit " << hAndE.first
133  << " is 0! The fraction for this hit cannot be computed.";
134  sc.addRecHitAndFraction(hAndE.first, fraction);
135  }
136  }
137 
138  // clear memory
139  std::unordered_map<unsigned, float>{}.swap(totalEnergy_);
140 
141  iEvent.put(std::move(newClusters_), particleCollectionDM_);
143 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
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
std::unordered_map< unsigned, float > totalEnergy_
void clearHitsAndFractions()
clear the hits and fractions list
Definition: SimCluster.h:219
std::unique_ptr< SimClusterCollection > newClusters_
std::unique_ptr< CaloParticleCollection > newParticles_
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

SimClusterRefProd PreMixingCaloParticleWorker::clusterRef_
private

Definition at line 43 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), and initializeEvent().

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

Definition at line 41 of file PreMixingCaloParticleWorker.cc.

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

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

Definition at line 42 of file PreMixingCaloParticleWorker.cc.

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

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

Definition at line 36 of file PreMixingCaloParticleWorker.cc.

Referenced by addPileups().

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

Definition at line 32 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

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

Definition at line 34 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

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

Definition at line 33 of file PreMixingCaloParticleWorker.cc.

Referenced by addSignals().

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

Definition at line 39 of file PreMixingCaloParticleWorker.cc.

Referenced by add(), and put().