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

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)
T getParameter(std::string const &) const
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
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, HTMLExport::elem(), 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_
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:19
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(), bsc_activity_cfg::clusters, HCALHighEnergyHPDFilter_cfi::energy, PileUpEventPrincipal::getByLabel(), edm::HandleBase::isValid(), particlePileInputTag_, and ecalTrigSettings_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(), bsc_activity_cfg::clusters, HCALHighEnergyHPDFilter_cfi::energy, edm::Event::getByToken(), edm::HandleBase::isValid(), 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()) {
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 SimCluster::addRecHitAndFraction(), SimCluster::clearHitsAndFractions(), DEFINE_PREMIXING_WORKER, HLT_2018_cff::fraction, SimCluster::hits_and_fractions(), eostools::move(), newClusters_, newParticles_, particleCollectionDM_, edm::Event::put(), SimDataFormats::CaloAnalysis::sc, and totalEnergy_.

132  {
133  for (auto &sc : *newClusters_) {
134  auto hitsAndEnergies = sc.hits_and_fractions();
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:131
void addRecHitAndFraction(uint32_t hit, float fraction)
add rechit with fraction
Definition: SimCluster.h:175
std::unordered_map< unsigned, float > totalEnergy_
void clearHitsAndFractions()
clear the hits and fractions list
Definition: SimCluster.h:190
std::unique_ptr< SimClusterCollection > newClusters_
std::unique_ptr< CaloParticleCollection > newParticles_
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

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().