CMS 3D CMS Logo

DataMixingPileupCopy.cc
Go to the documentation of this file.
1 // File: DataMixingPileupCopy.cc
2 // Description: see DataMixingPileupCopy.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
8 #include <map>
9 #include <memory>
10 
12 //
13 //
14 #include "DataMixingPileupCopy.h"
15 
16 using namespace std;
17 
18 namespace edm {
19 
20  // Virtual constructor
21 
22  DataMixingPileupCopy::DataMixingPileupCopy() {}
23 
24  // Constructor
25  DataMixingPileupCopy::DataMixingPileupCopy(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
26  : label_(ps.getParameter<std::string>("Label"))
27 
28  {
29  // Pileup/Playback information
30 
31  PileupInfoInputTag_ = ps.getParameter<edm::InputTag>("PileupInfoInputTag");
32  BunchSpacingInputTag_ = ps.getParameter<edm::InputTag>("BunchSpacingInputTag");
33  CFPlaybackInputTag_ = ps.getParameter<edm::InputTag>("CFPlaybackInputTag");
34 
35  GenPUProtonsInputTags_ = ps.getParameter<std::vector<edm::InputTag>>("GenPUProtonsInputTags");
36 
37  // apparently, we don't need consumes from Secondary input stream
38  // iC.consumes<std::vector<PileupSummaryInfo>>(PileupInfoInputTag_);
39  // iC.consumes<int>(BunchSpacingInputTag_);
40  // iC.consumes<CrossingFramePlaybackInfoNew>(CFPlaybackInputTag_);
41  }
42 
43  // Virtual destructor needed.
45 
47  unsigned int eventNr,
48  ModuleCallingContext const *mcc) {
49  LogDebug("DataMixingPileupCopy") << "\n===============> adding pileup Info from event " << ep->id();
50 
51  // find PileupSummaryInfo, CFPlayback information, if it's there
52 
53  // Pileup info first
54 
55  std::shared_ptr<Wrapper<std::vector<PileupSummaryInfo>> const> PileupInfoPTR =
56  getProductByTag<std::vector<PileupSummaryInfo>>(*ep, PileupInfoInputTag_, mcc);
57 
58  std::shared_ptr<Wrapper<int> const> bsPTR = getProductByTag<int>(*ep, BunchSpacingInputTag_, mcc);
59 
60  if (PileupInfoPTR) {
61  PileupSummaryStorage_ = *(PileupInfoPTR->product());
62  LogDebug("DataMixingEMWorker") << "PileupInfo Size: " << PileupSummaryStorage_.size();
63  }
64 
65  if (bsPTR) {
66  bsStorage_ = *(bsPTR->product());
67  } else {
68  bsStorage_ = 10000;
69  }
70 
71  // Gen. PU protons
72  std::shared_ptr<edm::Wrapper<std::vector<reco::GenParticle>> const> GenPUProtonsPTR;
73  for (std::vector<edm::InputTag>::const_iterator it_InputTag = GenPUProtonsInputTags_.begin();
74  it_InputTag != GenPUProtonsInputTags_.end();
75  ++it_InputTag) {
76  GenPUProtonsPTR = getProductByTag<std::vector<reco::GenParticle>>(*ep, *it_InputTag, mcc);
77  if (GenPUProtonsPTR != nullptr) {
78  GenPUProtons_.push_back(*(GenPUProtonsPTR->product()));
79  GenPUProtons_labels_.push_back(it_InputTag->label());
80  } else
81  edm::LogWarning("DataMixingPileupCopy") << "Missing product with label: " << (*it_InputTag).label();
82  }
83 
84  // Playback
85  std::shared_ptr<Wrapper<CrossingFramePlaybackInfoNew> const> PlaybackPTR =
86  getProductByTag<CrossingFramePlaybackInfoNew>(*ep, CFPlaybackInputTag_, mcc);
87  FoundPlayback_ = false;
88  if (PlaybackPTR) {
89  CrossingFramePlaybackStorage_ = *(PlaybackPTR->product());
90  FoundPlayback_ = true;
91  }
92  }
93 
95  std::unique_ptr<std::vector<PileupSummaryInfo>> PSIVector(new std::vector<PileupSummaryInfo>);
96  std::unique_ptr<int> bsInt(new int);
97 
98  std::vector<PileupSummaryInfo>::const_iterator PSiter;
99  for (PSiter = PileupSummaryStorage_.begin(); PSiter != PileupSummaryStorage_.end(); PSiter++) {
100  PSIVector->push_back(*PSiter);
101  }
102 
103  *bsInt = bsStorage_;
104 
105  if (FoundPlayback_) {
106  std::unique_ptr<CrossingFramePlaybackInfoNew> CFPlaybackInfo(
108  e.put(std::move(CFPlaybackInfo));
109  }
110  e.put(std::move(PSIVector));
111  e.put(std::move(bsInt), "bunchSpacing");
112 
113  // Gen. PU protons
114  for (size_t idx = 0; idx < GenPUProtons_.size(); ++idx) {
115  std::unique_ptr<std::vector<reco::GenParticle>> GenPUProtons_ptr(new std::vector<reco::GenParticle>());
116  std::vector<reco::GenParticle>::const_iterator it_GenParticle = GenPUProtons_.at(idx).begin();
117  std::vector<reco::GenParticle>::const_iterator it_GenParticle_end = GenPUProtons_.at(idx).end();
118  for (; it_GenParticle != it_GenParticle_end; ++it_GenParticle)
119  GenPUProtons_ptr->push_back(*it_GenParticle);
120 
121  e.put(std::move(GenPUProtons_ptr), GenPUProtons_labels_.at(idx));
122  }
123 
124  // clear local storage after this event
125  PileupSummaryStorage_.clear();
126  GenPUProtons_.clear();
127  GenPUProtons_labels_.clear();
128  }
129 } // namespace edm
std::vector< std::vector< reco::GenParticle > > GenPUProtons_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CrossingFramePlaybackInfoNew CrossingFramePlaybackStorage_
void putPileupInfo(edm::Event &e)
std::vector< PileupSummaryInfo > PileupSummaryStorage_
std::vector< std::string > GenPUProtons_labels_
std::vector< edm::InputTag > GenPUProtonsInputTags_
HLT enums.
Log< level::Warning, false > LogWarning
void addPileupInfo(const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *mcc)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)