CMS 3D CMS Logo

PreMixingCaloParticleWorker.cc
Go to the documentation of this file.
7 
13 
16 
18 public:
20  ~PreMixingCaloParticleWorker() override = default;
21 
22  void initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
23  void addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
24  void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override;
25  void put(edm::Event &iEvent,
26  edm::EventSetup const &iSetup,
27  std::vector<PileupSummaryInfo> const &ps,
28  int bunchSpacing) override;
29 
30 private:
31  using EnergyMap = std::vector<std::pair<unsigned, float>>;
32 
33  void add(const SimClusterCollection &clusters, const CaloParticleCollection &particles, const EnergyMap &energyMap);
34 
38 
41 
42  std::unordered_map<unsigned, float> totalEnergy_;
43 
44  std::unique_ptr<SimClusterCollection> newClusters_;
45  std::unique_ptr<CaloParticleCollection> newParticles_;
47 };
48 
50  edm::ProducesCollector producesCollector,
52  : sigClusterToken_(iC.consumes<SimClusterCollection>(ps.getParameter<edm::InputTag>("labelSig"))),
53  sigParticleToken_(iC.consumes<CaloParticleCollection>(ps.getParameter<edm::InputTag>("labelSig"))),
54  sigEnergyToken_(iC.consumes<EnergyMap>(ps.getParameter<edm::InputTag>("labelSig"))),
55  particlePileInputTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
56  particleCollectionDM_(ps.getParameter<std::string>("collectionDM")) {
59 }
60 
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 }
70 
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 }
85 
89 
92 
95 
96  if (clusters.isValid() && particles.isValid() && energy.isValid()) {
98  }
99 }
100 
103  const EnergyMap &energy) {
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 }
128 
130  edm::EventSetup const &iSetup,
131  std::vector<PileupSummaryInfo> const &ps,
132  int bunchSpacing) {
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 }
154 
edm::RefProd< SimClusterCollection >
Handle.h
SimClusterCollection
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
MessageLogger.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::EDGetTokenT< SimClusterCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PreMixingCaloParticleWorker::PreMixingCaloParticleWorker
PreMixingCaloParticleWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
Definition: PreMixingCaloParticleWorker.cc:49
CaloParticleFwd.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
SimClusterRef
edm::Ref< SimClusterCollection > SimClusterRef
Definition: SimClusterFwd.h:10
PreMixingCaloParticleWorker::~PreMixingCaloParticleWorker
~PreMixingCaloParticleWorker() override=default
edm::Handle< SimClusterCollection >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
ProducesCollector.h
PreMixingCaloParticleWorker::totalEnergy_
std::unordered_map< unsigned, float > totalEnergy_
Definition: PreMixingCaloParticleWorker.cc:42
SimCluster.h
HLTEgPhaseIITestSequence_cff.bunchSpacing
bunchSpacing
Definition: HLTEgPhaseIITestSequence_cff.py:1574
HLT_FULL_cff.fraction
fraction
Definition: HLT_FULL_cff.py:52802
PreMixingWorker.h
PreMixingCaloParticleWorker::clusterRef_
SimClusterRefProd clusterRef_
Definition: PreMixingCaloParticleWorker.cc:46
PileUpEventPrincipal.h
PreMixingCaloParticleWorker::EnergyMap
std::vector< std::pair< unsigned, float > > EnergyMap
Definition: PreMixingCaloParticleWorker.cc:31
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
CaloParticleCollection
std::vector< CaloParticle > CaloParticleCollection
Definition: CaloParticleFwd.h:8
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PreMixingCaloParticleWorker::put
void put(edm::Event &iEvent, edm::EventSetup const &iSetup, std::vector< PileupSummaryInfo > const &ps, int bunchSpacing) override
Definition: PreMixingCaloParticleWorker.cc:129
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
PreMixingCaloParticleWorker::addSignals
void addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: PreMixingCaloParticleWorker.cc:71
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PreMixingCaloParticleWorker::newParticles_
std::unique_ptr< CaloParticleCollection > newParticles_
Definition: PreMixingCaloParticleWorker.cc:45
CaloParticle.h
PreMixingCaloParticleWorker
Definition: PreMixingCaloParticleWorker.cc:17
iEvent
int iEvent
Definition: GenABIO.cc:224
PreMixingCaloParticleWorker::addPileups
void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override
Definition: PreMixingCaloParticleWorker.cc:86
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
edm::EventSetup
Definition: EventSetup.h:58
SimClusterFwd.h
PreMixingWorkerFactory.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ProducesCollector
Definition: ProducesCollector.h:43
PreMixingCaloParticleWorker::sigEnergyToken_
edm::EDGetTokenT< EnergyMap > sigEnergyToken_
Definition: PreMixingCaloParticleWorker.cc:37
DEFINE_PREMIXING_WORKER
#define DEFINE_PREMIXING_WORKER(TYPE)
Definition: PreMixingWorkerFactory.h:16
PreMixingCaloParticleWorker::particlePileInputTag_
edm::InputTag particlePileInputTag_
Definition: PreMixingCaloParticleWorker.cc:39
PreMixingCaloParticleWorker::sigClusterToken_
edm::EDGetTokenT< SimClusterCollection > sigClusterToken_
Definition: PreMixingCaloParticleWorker.cc:35
PreMixingWorker
Definition: PreMixingWorker.h:14
ConsumesCollector.h
ParameterSet.h
PileUpEventPrincipal::getByLabel
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
Definition: PileUpEventPrincipal.h:33
PreMixingCaloParticleWorker::newClusters_
std::unique_ptr< SimClusterCollection > newClusters_
Definition: PreMixingCaloParticleWorker.cc:44
edm::Event
Definition: Event.h:73
PreMixingCaloParticleWorker::sigParticleToken_
edm::EDGetTokenT< CaloParticleCollection > sigParticleToken_
Definition: PreMixingCaloParticleWorker.cc:36
PreMixingCaloParticleWorker::add
void add(const SimClusterCollection &clusters, const CaloParticleCollection &particles, const EnergyMap &energyMap)
Definition: PreMixingCaloParticleWorker.cc:101
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PreMixingCaloParticleWorker::initializeEvent
void initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: PreMixingCaloParticleWorker.cc:61
PreMixingCaloParticleWorker::particleCollectionDM_
std::string particleCollectionDM_
Definition: PreMixingCaloParticleWorker.cc:40