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