CMS 3D CMS Logo

PreMixingPileupCopy.cc
Go to the documentation of this file.
1 #include "PreMixingPileupCopy.h"
2 
7 
9 
10 
11 #include <memory>
12 
13 namespace edm {
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  {
20  producer.produces<std::vector<PileupSummaryInfo> >();
21  producer.produces<int>("bunchSpacing");
23 
24  for(const auto& tag: genPUProtonsInputTags_) {
25  producer.produces<std::vector<reco::GenParticle> >(tag.label());
26  }
27  }
28 
31  pep.getByLabel(pileupInfoInputTag_, pileupInfoHandle);
32 
33  auto it = std::find_if(pileupInfoHandle->begin(), pileupInfoHandle->end(),
34  [](const auto& s) {
35  return s.getBunchCrossing() == 0;
36  });
37  if(it == pileupInfoHandle->end()) {
38  throw cms::Exception("LogicError") << "Did not find PileupSummaryInfo in bunch crossing 0";
39  }
40 
41  return it->getTrueNumInteractions();
42  }
43 
45 
46  LogDebug("PreMixingPileupCopy") <<"\n===============> adding pileup Info from event "<<pep.principal().id();
47 
48  // find PileupSummaryInfo, CFPlayback information, if it's there
49 
50  // Pileup info first
52  pep.getByLabel(pileupInfoInputTag_, pileupInfoHandle);
53 
54  edm::Handle<int> bsHandle;
55  pep.getByLabel(bunchSpacingInputTag_, bsHandle);
56 
57  if(pileupInfoHandle.isValid()) {
58  pileupSummaryStorage_ = *pileupInfoHandle;
59  LogDebug("PreMixingPileupCopy") << "PileupInfo Size: " << pileupSummaryStorage_.size();
60  }
61  bsStorage_ = bsHandle.isValid() ? *bsHandle : 10000;
62 
63  // Gen. PU protons
65  for(const auto& tag: genPUProtonsInputTags_) {
66  pep.getByLabel(tag, genPUProtonsHandle);
67  if(genPUProtonsHandle.isValid()) {
68  genPUProtons_.push_back(*genPUProtonsHandle);
69  genPUProtons_labels_.push_back(tag.label());
70  }
71  else {
72  edm::LogWarning("PreMixingPileupCopy") << "Missing product with label: " << tag.label();
73  }
74  }
75 
76  // Playback
78  pep.getByLabel(cfPlaybackInputTag_, playbackHandle);
79  foundPlayback_ = false;
80  if(playbackHandle.isValid()) {
81  crossingFramePlaybackStorage_ = *playbackHandle;
82  foundPlayback_ = true;
83  }
84  }
85 
87  if(foundPlayback_ ) {
88  e.put(std::make_unique<CrossingFramePlaybackInfoNew>(std::move(crossingFramePlaybackStorage_)));
89  }
90  e.put(std::make_unique<std::vector<PileupSummaryInfo> >(std::move(pileupSummaryStorage_)));
91  e.put(std::make_unique<int>(bsStorage_), "bunchSpacing");
92 
93  // Gen. PU protons
94  for(size_t idx = 0; idx < genPUProtons_.size(); ++idx){
95  e.put(std::make_unique<std::vector<reco::GenParticle> >(std::move(genPUProtons_[idx])),
97  }
98 
99  // clear local storage after this event
100  pileupSummaryStorage_.clear();
101  genPUProtons_.clear();
102  genPUProtons_labels_.clear();
103  }
104 } //edm
#define LogDebug(id)
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
PreMixingPileupCopy(const edm::ParameterSet &ps, edm::ProducerBase &producer, edm::ConsumesCollector &&iC)
std::vector< std::vector< reco::GenParticle > > genPUProtons_
EventID const & id() const
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:74
float getTrueNumInteractions(PileUpEventPrincipal const &pep) const
HLT enums.
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
def move(src, dest)
Definition: eostools.py:511