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