CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SecSourceAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SecSourceAnalyzer
4 // Class: SecSourceAnalyzer
5 //
13 //
14 // Original Author: Emilia Lubenova Becheva
15 // Created: Wed Apr 22 16:54:31 CEST 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <functional>
22 
23 // user include files
26 
30 
34 
40 
42 
44 
45 #include "SecSourceAnalyzer.h"
46 
47 #include "TH1F.h"
48 
49 //
50 // constructors and destructor
51 //
52 namespace edm {
54  : minBunch_(0), maxBunch_(0), tag_(InputTag()) {
55  // int minb = minBunch_;
56  // int maxb = maxBunch_;
57  int averageNumber = 1;
59  std::unique_ptr<TH1F> histoName(new TH1F("h", "", 10, 0, 10));
60  bool playback = false;
61 
62  auto conf = std::make_shared<PileUpConfig>("input", averageNumber, histoName, playback);
63  input_ = std::make_unique<edm::PileUp>(
64  iConfig.getParameter<edm::ParameterSet>("input"), conf, consumesCollector(), false);
65 
66  dataStep2_ = iConfig.getParameter<bool>("dataStep2");
67 
68  if (dataStep2_)
69  // The data file contain the PCrossingFrame<SimTrack>
70  label_ = iConfig.getParameter<edm::InputTag>("collPCF");
71  else
72  // The data file contain the SimTrack
73  label_ = iConfig.getParameter<edm::InputTag>("collSimTrack");
74  }
75 
77 
78  //
79  // member functions
80  //
81 
82  // ------------ method called for each event ------------
84  using namespace std::placeholders;
85  vectorEventIDs_.resize(maxBunch_ - minBunch_ + 1);
86 
87  int nevt = 0;
88  for (int ibx = minBunch_; ibx <= maxBunch_; ++ibx) {
89  if (ibx == 0) {
90  input_->readPileUp(iEvent.id(),
92  std::bind(&SecSourceAnalyzer::getBranches, this, _1, iEvent.moduleCallingContext()),
93  ibx,
94  iEvent.streamID());
95  } else {
96  input_->readPileUp(iEvent.id(),
98  std::bind(&SecSourceAnalyzer::dummyFunction, this, _1),
99  ibx,
100  iEvent.streamID());
101  }
102 
103  nevt += vectorEventIDs_[ibx - minBunch_].size();
104  }
105 
106  std::cout << "-> The std::vector<EventPrincipalVector> of the secondary source 'input' has been filled with "
107  << nevt << " element corresponding to " << maxBunch_ - minBunch_ + 1 << " bunch." << std::endl;
108  }
109 
111  InternalContext internalContext(ep.id(), mcc);
112  ParentContext parentContext(&internalContext);
113  ModuleCallingContext moduleCallingContext(&moduleDescription());
114  ModuleContextSentry moduleContextSentry(&moduleCallingContext, parentContext);
115 
116  std::cout << "-> Get the event: id " << ep.id() << std::endl;
117  std::cout << "-> dataStep2_ = " << dataStep2_ << std::endl;
118  tag_ = InputTag(label_);
119 
120  std::cout << "-> Will try to get the branch with the tag : " << tag_ << std::endl;
121  std::cout << " and the EventPrincipal ep with a size = " << ep.size() << std::endl;
122 
123  if (!dataStep2_) {
124  // Get the SimTrack collection
125 
126  // default version changed to transmit vertexoffset
127  std::shared_ptr<Wrapper<std::vector<SimTrack> > const> shPtr =
128  getProductByTag<std::vector<SimTrack> >(ep, tag_, &moduleCallingContext);
129 
130  if (shPtr)
131  std::cout << "-> Could get SimTrack !" << std::endl;
132  else
133  std::cout << "-> Could not get SimTrack !" << std::endl;
134 
135  } else {
136  // Get the PCrossingFrame collection given as signal
137 
138  // default version changed to transmit vertexoffset
139  tag_ = InputTag("CFwriter", "g4SimHits");
140  std::shared_ptr<Wrapper<PCrossingFrame<SimTrack> > const> shPtr =
141  getProductByTag<PCrossingFrame<SimTrack> >(ep, tag_, &moduleCallingContext);
142 
143  if (shPtr)
144  std::cout << "-> Could get PCrossingFrame<SimTrack> !" << std::endl;
145  else
146  std::cout << "-> Could not get PCrossingFrame<SimTrack> !" << std::endl;
147  }
148 
149  return true;
150  }
151 
152  // ------------ method called once each job just before starting event loop ------------
154 
155  // ------------ method called once each job just after ending the event loop ------------
157  if (input_)
158  input_->endStream();
159  }
160 
161 } // namespace edm
void analyze(const edm::Event &, const edm::EventSetup &) override
size_t size() const
Definition: Principal.cc:303
tuple averageNumber
set the number of pileup
ModuleDescription const & moduleDescription() const
tuple histoFileName
Definition: diJetCalib.py:108
std::unique_ptr< PileUp > input_
EventID const & id() const
bool getBranches(EventPrincipal const &ep, ModuleCallingContext const *)
bool dummyFunction(EventPrincipal const &ep)
int iEvent
Definition: GenABIO.cc:224
ModuleCallingContext const * moduleCallingContext() const
Definition: Event.h:253
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
SecSourceAnalyzer(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EventID id() const
Definition: EventBase.h:59
StreamID streamID() const
Definition: Event.h:98
std::vector< std::vector< edm::SecondaryEventIDAndFileInfo > > vectorEventIDs_
tuple cout
Definition: gather_cfg.py:144