CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PileUp.h
Go to the documentation of this file.
1 #ifndef Base_PileUp_h
2 #define Base_PileUp_h
3 
4 #include <string>
5 #include <vector>
6 #include <boost/bind.hpp>
12 
13 #include "CLHEP/Random/RandPoissonQ.h"
14 #include "CLHEP/Random/RandFlat.h"
15 
16 #include "TRandom.h"
17 #include "TFile.h"
18 #include "TH1F.h"
19 
20 class TFile;
21 class TH1F;
22 
23 namespace CLHEP {
24  class RandPoissonQ;
25  class RandPoisson;
26 }
27 
28 
29 
30 namespace edm {
31  class PileUp {
32  public:
33  explicit PileUp(ParameterSet const& pset, double averageNumber, TH1F* const histo, const bool playback);
34  ~PileUp();
35 
36  template<typename T>
37  void readPileUp(edm::EventID const & signal, std::vector<edm::EventID> &ids, T eventOperator, const int NumPU );
38 
39  template<typename T>
40  void playPileUp(const std::vector<edm::EventID> &ids, T eventOperator);
41 
42  double averageNumber() const {return averageNumber_;}
43  bool poisson() const {return poisson_;}
44  bool doPileUp() {return none_ ? false : averageNumber_>0.;}
45  void dropUnwantedBranches(std::vector<std::string> const& wantedBranches) {
46  input_->dropUnwantedBranches(wantedBranches);
47  }
48  void endJob () {
49  input_->doEndJob();
50  }
51 
52  void reload(const edm::EventSetup & setup);
53 
54  void CalculatePileup(int MinBunch, int MaxBunch, std::vector<int>& PileupSelection, std::vector<float>& TrueNumInteractions);
55 
56  //template<typename T>
57  // void recordEventForPlayback(EventPrincipal const& eventPrincipal,
58  // std::vector<edm::EventID> &ids, T& eventOperator);
59 
60  const unsigned int & input()const{return inputType_;}
61  void input(unsigned int s){inputType_=s;}
62 
63  private:
64  unsigned int inputType_;
65  std::string type_;
67  int const intAverage_;
68  TH1F* histo_;
71  bool poisson_;
72  bool fixed_;
73  bool none_;
76  bool fixed_OOT_;
77 
78  bool PU_Study_;
79  std::string Study_type_;
80 
83 
85  CLHEP::RandPoissonQ *poissonDistribution_;
86  CLHEP::RandPoisson *poissonDistr_OOT_;
87 
88 
89  TH1F *h1f;
91  TFile *probFileHisto;
92 
93  //playback info
94  bool playback_;
95 
96  // sequential reading
98 
99  // force reading pileup events from the same lumisection as the signal event
100  bool samelumi_;
101 
102  // read the seed for the histo and probability function cases
103  int seed_;
104  };
105 
106 
107 
108  template<typename T>
110  {
111  private:
112  std::vector<edm::EventID>& ids_;
115  public:
116  RecordEventID(std::vector<edm::EventID>& ids, T& eventOperator)
117  : ids_(ids), eventOperator_(eventOperator), eventCount( 0 ) {}
118  void operator()(EventPrincipal const& eventPrincipal) {
119  ids_.push_back(eventPrincipal.id());
120  eventOperator_(eventPrincipal, ++eventCount);
121  }
122  };
123 
124 
135  template<typename T>
136  void
137  PileUp::readPileUp(edm::EventID const & signal, std::vector<edm::EventID> &ids, T eventOperator, const int pileEventCnt) {
138 
139  // One reason PileUp is responsible for recording event IDs is
140  // that it is the one that knows how many events will be read.
141  ids.reserve(pileEventCnt);
142  RecordEventID<T> recorder(ids,eventOperator);
143  int read;
144  if (samelumi_) {
145  const edm::LuminosityBlockID lumi(signal.run(), signal.luminosityBlock());
146  if (sequential_)
147  read = input_->loopSequentialWithID(lumi, pileEventCnt, recorder);
148  else
149  read = input_->loopRandomWithID(lumi, pileEventCnt, recorder);
150  } else {
151  if (sequential_) {
152  // boost::bind creates a functor from recordEventForPlayback
153  // so that recordEventForPlayback can insert itself before
154  // the original eventOperator.
155 
156  read = input_->loopSequential(pileEventCnt, recorder);
157  //boost::bind(&PileUp::recordEventForPlayback<T>,
158  // boost::ref(*this), _1, boost::ref(ids),
159  // boost::ref(eventOperator))
160  // );
161 
162  } else {
163  read = input_->loopRandom(pileEventCnt, recorder);
164  // boost::bind(&PileUp::recordEventForPlayback<T>,
165  // boost::ref(*this), _1, boost::ref(ids),
166  // boost::ref(eventOperator))
167  // );
168  }
169  }
170  if (read != pileEventCnt)
171  edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt << " requested.";
172  }
173 
174 
175 
176  template<typename T>
177  void
178  PileUp::playPileUp(const std::vector<edm::EventID> &ids, T eventOperator) {
179  //TrueNumInteractions.push_back( ids.size() ) ;
180  input_->loopSpecified(ids,eventOperator);
181  }
182 
183 
184 
187  /* template<typename T>
188  void recordEventForPlayback(EventPrincipal const& eventPrincipal,
189  std::vector<edm::EventID> &ids, T& eventOperator)
190  {
191  ids.push_back(eventPrincipal.id());
192  eventOperator(eventPrincipal);
193  }
194  */
195 }
196 
197 
198 #endif
void playPileUp(const std::vector< edm::EventID > &ids, T eventOperator)
Definition: PileUp.h:178
RunNumber_t run() const
Definition: EventID.h:42
void CalculatePileup(int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions)
Definition: PileUp.cc:226
bool manage_OOT_
Definition: PileUp.h:74
const unsigned int & input() const
Definition: PileUp.h:60
size_t loopRandomWithID(LuminosityBlockID const &id, size_t number, T eventOperator)
bool poisson() const
Definition: PileUp.h:43
std::vector< edm::EventID > & ids_
Definition: PileUp.h:112
TH1F * h1f
Definition: PileUp.h:89
void doEndJob()
Called by framework at end of job.
Definition: InputSource.cc:235
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
unsigned int inputType_
Definition: PileUp.h:64
tuple lumi
Definition: fjr2json.py:35
size_t loopRandom(size_t number, T eventOperator)
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
Definition: PileUp.h:45
EventID const & id() const
void readPileUp(edm::EventID const &signal, std::vector< edm::EventID > &ids, T eventOperator, const int NumPU)
Definition: PileUp.h:137
void endJob()
Definition: PileUp.h:48
TH1F * histo_
Definition: PileUp.h:68
bool fixed_
Definition: PileUp.h:72
size_t loopSequential(size_t number, T eventOperator)
PileUp(ParameterSet const &pset, double averageNumber, TH1F *const histo, const bool playback)
Definition: PileUp.cc:20
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
VectorInputSource *const input_
Definition: PileUp.h:84
int const intAverage_
Definition: PileUp.h:67
bool probFunctionDistribution_
Definition: PileUp.h:70
std::string Study_type_
Definition: PileUp.h:79
bool histoDistribution_
Definition: PileUp.h:69
bool poisson_
Definition: PileUp.h:71
double averageNumber() const
Definition: PileUp.h:42
bool playback_
Definition: PileUp.h:94
bool samelumi_
Definition: PileUp.h:100
bool poisson_OOT_
Definition: PileUp.h:75
void input(unsigned int s)
Definition: PileUp.h:61
size_t loopSpecified(Collection const &events, T eventOperator)
int intFixed_ITPU_
Definition: PileUp.h:82
RecordEventID(std::vector< edm::EventID > &ids, T &eventOperator)
Definition: PileUp.h:116
bool PU_Study_
Definition: PileUp.h:78
bool fixed_OOT_
Definition: PileUp.h:76
CLHEP::RandPoisson * poissonDistr_OOT_
Definition: PileUp.h:86
std::string type_
Definition: PileUp.h:65
TFile * probFileHisto
Definition: PileUp.h:91
bool sequential_
Definition: PileUp.h:97
void reload(const edm::EventSetup &setup)
Definition: PileUp.cc:120
size_t loopSequentialWithID(LuminosityBlockID const &id, size_t number, T eventOperator)
int seed_
Definition: PileUp.h:103
bool none_
Definition: PileUp.h:73
TH1F * hprobFunction
Definition: PileUp.h:90
tuple playback
Definition: Playback_cff.py:20
int intFixed_OOT_
Definition: PileUp.h:81
bool doPileUp()
Definition: PileUp.h:44
long double T
void operator()(EventPrincipal const &eventPrincipal)
Definition: PileUp.h:118
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
CLHEP::RandPoissonQ * poissonDistribution_
Definition: PileUp.h:85
double averageNumber_
Definition: PileUp.h:66