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
edm::DataMixingPileupCopy::GenPUProtonsInputTags_
std::vector< edm::InputTag > GenPUProtonsInputTags_
Definition: DataMixingPileupCopy.h:65
Handle.h
MessageLogger.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::DataMixingPileupCopy::bsStorage_
int bsStorage_
Definition: DataMixingPileupCopy.h:70
edm::DataMixingPileupCopy::FoundPlayback_
bool FoundPlayback_
Definition: DataMixingPileupCopy.h:79
edm::DataMixingPileupCopy::PileupSummaryStorage_
std::vector< PileupSummaryInfo > PileupSummaryStorage_
Definition: DataMixingPileupCopy.h:69
training_settings.idx
idx
Definition: training_settings.py:16
edm::DataMixingPileupCopy::CrossingFramePlaybackStorage_
CrossingFramePlaybackInfoNew CrossingFramePlaybackStorage_
Definition: DataMixingPileupCopy.h:67
CrossingFramePlaybackInfoNew
Definition: CrossingFramePlaybackInfoNew.h:23
GenParticle.h
edm::EventPrincipal
Definition: EventPrincipal.h:46
edm::DataMixingPileupCopy::CFPlaybackInputTag_
edm::InputTag CFPlaybackInputTag_
Definition: DataMixingPileupCopy.h:63
edm::DataMixingPileupCopy::putPileupInfo
void putPileupInfo(edm::Event &e)
Definition: DataMixingPileupCopy.cc:94
DataMixingPileupCopy.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::DataMixingPileupCopy::GenPUProtons_labels_
std::vector< std::string > GenPUProtons_labels_
Definition: DataMixingPileupCopy.h:72
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::DataMixingPileupCopy::~DataMixingPileupCopy
virtual ~DataMixingPileupCopy()
Definition: DataMixingPileupCopy.cc:44
edm::DataMixingPileupCopy::addPileupInfo
void addPileupInfo(const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *mcc)
Definition: DataMixingPileupCopy.cc:46
edm::DataMixingPileupCopy::BunchSpacingInputTag_
edm::InputTag BunchSpacingInputTag_
Definition: DataMixingPileupCopy.h:62
edm::DataMixingPileupCopy::PileupInfoInputTag_
edm::InputTag PileupInfoInputTag_
Definition: DataMixingPileupCopy.h:61
edm::Event
Definition: Event.h:73
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
edm::DataMixingPileupCopy::GenPUProtons_
std::vector< std::vector< reco::GenParticle > > GenPUProtons_
Definition: DataMixingPileupCopy.h:73
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::ModuleCallingContext
Definition: ModuleCallingContext.h:29