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
Handle.h
MessageLogger.h
PreMixingPileupCopy.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::PreMixingPileupCopy::pileupSummaryStorage_
std::vector< PileupSummaryInfo > pileupSummaryStorage_
Definition: PreMixingPileupCopy.h:55
edm::PreMixingPileupCopy::putPileupInfo
void putPileupInfo(edm::Event &e)
Definition: PreMixingPileupCopy.cc:81
edm::PreMixingPileupCopy::genPUProtonsInputTags_
std::vector< edm::InputTag > genPUProtonsInputTags_
Definition: PreMixingPileupCopy.h:51
PileUpEventPrincipal
Definition: PileUpEventPrincipal.h:19
edm::PreMixingPileupCopy::bsStorage_
int bsStorage_
Definition: PreMixingPileupCopy.h:56
edm::PreMixingPileupCopy::cfPlaybackInputTag_
edm::InputTag cfPlaybackInputTag_
Definition: PreMixingPileupCopy.h:49
edm::Handle
Definition: AssociativeIterator.h:50
training_settings.idx
idx
Definition: training_settings.py:16
edm::EventPrincipal::id
EventID const & id() const
Definition: EventPrincipal.h:92
CrossingFramePlaybackInfoNew
Definition: CrossingFramePlaybackInfoNew.h:23
GenParticle.h
edm::PreMixingPileupCopy::bunchSpacingInputTag_
edm::InputTag bunchSpacingInputTag_
Definition: PreMixingPileupCopy.h:48
edm::PreMixingPileupCopy::PreMixingPileupCopy
PreMixingPileupCopy(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC)
Definition: PreMixingPileupCopy.cc:12
alignCSCRings.s
s
Definition: alignCSCRings.py:92
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
edm::PreMixingPileupCopy::getTrueNumInteractions
float getTrueNumInteractions(PileUpEventPrincipal const &pep) const
Definition: PreMixingPileupCopy.cc:28
edm::PreMixingPileupCopy::genPUProtons_labels_
std::vector< std::string > genPUProtons_labels_
Definition: PreMixingPileupCopy.h:58
PileUpEventPrincipal::principal
edm::EventPrincipal const & principal()
Definition: PileUpEventPrincipal.h:24
edm::PreMixingPileupCopy::crossingFramePlaybackStorage_
CrossingFramePlaybackInfoNew crossingFramePlaybackStorage_
Definition: PreMixingPileupCopy.h:54
PileUpEventPrincipal.h
edm::LogWarning
Definition: MessageLogger.h:141
edm::PreMixingPileupCopy::addPileupInfo
void addPileupInfo(PileUpEventPrincipal const &pep)
Definition: PreMixingPileupCopy.cc:41
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ProducesCollector
Definition: ProducesCollector.h:43
edm::PreMixingPileupCopy::foundPlayback_
bool foundPlayback_
Definition: PreMixingPileupCopy.h:61
Exception
Definition: hltDiff.cc:246
edm::PreMixingPileupCopy::pileupInfoInputTag_
edm::InputTag pileupInfoInputTag_
Definition: PreMixingPileupCopy.h:47
PileUpEventPrincipal::getByLabel
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
Definition: PileUpEventPrincipal.h:33
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
edm::PreMixingPileupCopy::genPUProtons_
std::vector< std::vector< reco::GenParticle > > genPUProtons_
Definition: PreMixingPileupCopy.h:59
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37