CMS 3D CMS Logo

PreMixingPileupCopy.cc
Go to the documentation of this file.
1 #include "PreMixingPileupCopy.h"
2 
6 
8 
9 #include <memory>
10 
11 namespace edm {
13  edm::ProducesCollector producesCollector,
15  : pileupInfoInputTag_(ps.getParameter<edm::InputTag>("PileupInfoInputTag")),
16  bunchSpacingInputTag_(ps.getParameter<edm::InputTag>("BunchSpacingInputTag")),
17  cfPlaybackInputTag_(ps.getParameter<edm::InputTag>("CFPlaybackInputTag")),
18  genPUProtonsInputTags_(ps.getParameter<std::vector<edm::InputTag>>("GenPUProtonsInputTags")) {
19  producesCollector.produces<std::vector<PileupSummaryInfo>>();
20  producesCollector.produces<int>("bunchSpacing");
21  producesCollector.produces<CrossingFramePlaybackInfoNew>();
22 
23  for (const auto& tag : genPUProtonsInputTags_) {
24  producesCollector.produces<std::vector<reco::GenParticle>>(tag.label());
25  }
26  }
27 
30  pep.getByLabel(pileupInfoInputTag_, pileupInfoHandle);
31 
32  auto it = std::find_if(
33  pileupInfoHandle->begin(), pileupInfoHandle->end(), [](const auto& s) { return s.getBunchCrossing() == 0; });
34  if (it == pileupInfoHandle->end()) {
35  throw cms::Exception("LogicError") << "Did not find PileupSummaryInfo in bunch crossing 0";
36  }
37 
38  return it->getTrueNumInteractions();
39  }
40 
42  LogDebug("PreMixingPileupCopy") << "\n===============> adding pileup Info from event " << pep.principal().id();
43 
44  // find PileupSummaryInfo, CFPlayback information, if it's there
45 
46  // Pileup info first
48  pep.getByLabel(pileupInfoInputTag_, pileupInfoHandle);
49 
50  edm::Handle<int> bsHandle;
51  pep.getByLabel(bunchSpacingInputTag_, bsHandle);
52 
53  if (pileupInfoHandle.isValid()) {
54  pileupSummaryStorage_ = *pileupInfoHandle;
55  LogDebug("PreMixingPileupCopy") << "PileupInfo Size: " << pileupSummaryStorage_.size();
56  }
57  bsStorage_ = bsHandle.isValid() ? *bsHandle : 10000;
58 
59  // Gen. PU protons
61  for (const auto& tag : genPUProtonsInputTags_) {
62  pep.getByLabel(tag, genPUProtonsHandle);
63  if (genPUProtonsHandle.isValid()) {
64  genPUProtons_.push_back(*genPUProtonsHandle);
65  genPUProtons_labels_.push_back(tag.label());
66  } else {
67  edm::LogWarning("PreMixingPileupCopy") << "Missing product with label: " << tag.label();
68  }
69  }
70 
71  // Playback
73  pep.getByLabel(cfPlaybackInputTag_, playbackHandle);
74  foundPlayback_ = false;
75  if (playbackHandle.isValid()) {
76  crossingFramePlaybackStorage_ = *playbackHandle;
77  foundPlayback_ = true;
78  }
79  }
80 
82  if (foundPlayback_) {
83  e.put(std::make_unique<CrossingFramePlaybackInfoNew>(std::move(crossingFramePlaybackStorage_)));
84  }
85  e.put(std::make_unique<std::vector<PileupSummaryInfo>>(std::move(pileupSummaryStorage_)));
86  e.put(std::make_unique<int>(bsStorage_), "bunchSpacing");
87 
88  // Gen. PU protons
89  for (size_t idx = 0; idx < genPUProtons_.size(); ++idx) {
90  e.put(std::make_unique<std::vector<reco::GenParticle>>(std::move(genPUProtons_[idx])), genPUProtons_labels_[idx]);
91  }
92 
93  // clear local storage after this event
94  pileupSummaryStorage_.clear();
95  genPUProtons_.clear();
96  genPUProtons_labels_.clear();
97  }
98 } // namespace edm
std::vector< std::vector< reco::GenParticle > > genPUProtons_
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
void putPileupInfo(edm::Event &e)
CrossingFramePlaybackInfoNew crossingFramePlaybackStorage_
std::vector< std::string > genPUProtons_labels_
void addPileupInfo(PileUpEventPrincipal const &pep)
edm::EventPrincipal const & principal()
std::vector< PileupSummaryInfo > pileupSummaryStorage_
std::vector< edm::InputTag > genPUProtonsInputTags_
bool isValid() const
Definition: HandleBase.h:70
float getTrueNumInteractions(PileUpEventPrincipal const &pep) const
HLT enums.
Log< level::Warning, false > LogWarning
EventID const & id() const
def move(src, dest)
Definition: eostools.py:511
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
PreMixingPileupCopy(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
#define LogDebug(id)