CMS 3D CMS Logo

PileUp.h
Go to the documentation of this file.
1 #ifndef Mixing_Base_PileUp_h
2 #define Mixing_Base_PileUp_h
3 
4 #include <memory>
5 #include <string>
6 #include <vector>
12 
13 #include "TRandom.h"
14 #include "TFile.h"
15 #include "TH1F.h"
16 
17 class TFile;
18 class TH1F;
19 
20 namespace CLHEP {
21  class RandPoissonQ;
22  class RandPoisson;
23  class HepRandomEngine;
24 } // namespace CLHEP
25 
26 namespace edm {
27  class SecondaryEventProvider;
28  class StreamID;
29  class ProcessContext;
30 
31  struct PileUpConfig {
32  PileUpConfig(std::string sourcename, double averageNumber, std::unique_ptr<TH1F>& histo, const bool playback)
36  std::shared_ptr<TH1F> histo_;
37  const bool playback_;
38  };
39 
40  class PileUp {
41  public:
42  explicit PileUp(ParameterSet const& pset, const std::shared_ptr<PileUpConfig>& config);
43  ~PileUp();
44 
45  template <typename T>
46  void readPileUp(edm::EventID const& signal,
47  std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
48  T eventOperator,
49  int const NumPU,
50  StreamID const&);
51 
52  template <typename T>
53  void playPileUp(std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator begin,
54  std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator end,
55  std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
56  T eventOperator);
57 
58  template <typename T>
59  void playOldFormatPileUp(std::vector<edm::EventID>::const_iterator begin,
60  std::vector<edm::EventID>::const_iterator end,
61  std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
62  T eventOperator);
63 
64  double averageNumber() const { return averageNumber_; }
65  bool poisson() const { return poisson_; }
66  bool doPileUp(int BX) {
67  if (Source_type_ != "cosmics") {
68  return none_ ? false : averageNumber_ > 0.;
69  } else {
70  return (BX >= minBunch_cosmics_ && BX <= maxBunch_cosmics_);
71  }
72  }
73  void dropUnwantedBranches(std::vector<std::string> const& wantedBranches) {
74  input_->dropUnwantedBranches(wantedBranches);
75  }
77  void endStream();
78 
79  void beginRun(const edm::Run& run, const edm::EventSetup& setup);
81 
82  void endRun(const edm::Run& run, const edm::EventSetup& setup);
84 
86 
87  void reload(const edm::EventSetup& setup);
88 
89  void CalculatePileup(int MinBunch,
90  int MaxBunch,
91  std::vector<int>& PileupSelection,
92  std::vector<float>& TrueNumInteractions,
93  StreamID const&);
94 
95  //template<typename T>
96  // void recordEventForPlayback(EventPrincipal const& eventPrincipal,
97  // std::vector<edm::SecondaryEventIDAndFileInfo> &ids, T& eventOperator);
98 
99  const unsigned int& input() const { return inputType_; }
100  void input(unsigned int s) { inputType_ = s; }
101 
102  private:
103  std::unique_ptr<CLHEP::RandPoissonQ> const& poissonDistribution(StreamID const& streamID);
104  std::unique_ptr<CLHEP::RandPoisson> const& poissonDistr_OOT(StreamID const& streamID);
105  CLHEP::HepRandomEngine* randomEngine(StreamID const& streamID);
106 
107  unsigned int inputType_;
111  int const intAverage_;
112  std::shared_ptr<TH1F> histo_;
115  bool poisson_;
116  bool fixed_;
117  bool none_;
121 
122  bool PU_Study_;
124 
127 
130 
132  std::shared_ptr<ProductRegistry> productRegistry_;
133  std::unique_ptr<VectorInputSource> const input_;
134  std::shared_ptr<ProcessConfiguration> processConfiguration_;
135  std::shared_ptr<ProcessContext> processContext_;
136  std::shared_ptr<StreamContext> streamContext_;
137  std::unique_ptr<EventPrincipal> eventPrincipal_;
138  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
139  std::shared_ptr<RunPrincipal> runPrincipal_;
140  std::unique_ptr<SecondaryEventProvider> provider_;
141  std::unique_ptr<CLHEP::RandPoissonQ> PoissonDistribution_;
142  std::unique_ptr<CLHEP::RandPoisson> PoissonDistr_OOT_;
143  CLHEP::HepRandomEngine* randomEngine_;
144 
145  //TH1F *h1f;
146  //TH1F *hprobFunction;
147  //TFile *probFileHisto;
148 
149  //playback info
150  bool playback_;
151 
152  // sequential reading
154  };
155 
156  template <typename T>
158  private:
159  std::vector<edm::SecondaryEventIDAndFileInfo>& ids_;
162 
163  public:
164  RecordEventID(std::vector<edm::SecondaryEventIDAndFileInfo>& ids, T& eventOperator)
165  : ids_(ids), eventOperator_(eventOperator), eventCount(1) {}
166  bool operator()(EventPrincipal const& eventPrincipal, size_t fileNameHash) {
167  bool used = eventOperator_(eventPrincipal, eventCount);
168  if (used) {
169  ++eventCount;
170  ids_.emplace_back(eventPrincipal.id(), fileNameHash);
171  }
172  return used;
173  }
174  };
175 
186  template <typename T>
187  void PileUp::readPileUp(edm::EventID const& signal,
188  std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
189  T eventOperator,
190  int const pileEventCnt,
191  StreamID const& streamID) {
192  // One reason PileUp is responsible for recording event IDs is
193  // that it is the one that knows how many events will be read.
194  ids.reserve(pileEventCnt);
195  RecordEventID<T> recorder(ids, eventOperator);
196  int read = 0;
197  CLHEP::HepRandomEngine* engine = (sequential_ ? nullptr : randomEngine(streamID));
198  read = input_->loopOverEvents(*eventPrincipal_, fileNameHash_, pileEventCnt, recorder, engine, &signal);
199  if (read != pileEventCnt)
200  edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt
201  << " requested.";
202  }
203 
204  template <typename T>
205  void PileUp::playPileUp(std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator begin,
206  std::vector<edm::SecondaryEventIDAndFileInfo>::const_iterator end,
207  std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
208  T eventOperator) {
209  //TrueNumInteractions.push_back( end - begin ) ;
210  RecordEventID<T> recorder(ids, eventOperator);
211  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
212  }
213 
214  template <typename T>
215  void PileUp::playOldFormatPileUp(std::vector<edm::EventID>::const_iterator begin,
216  std::vector<edm::EventID>::const_iterator end,
217  std::vector<edm::SecondaryEventIDAndFileInfo>& ids,
218  T eventOperator) {
219  //TrueNumInteractions.push_back( end - begin ) ;
220  RecordEventID<T> recorder(ids, eventOperator);
221  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
222  }
223 
224 } // namespace edm
225 
226 #endif
edm::PileUp::beginStream
void beginStream(edm::StreamID)
Definition: PileUp.cc:179
edm::PileUp::minBunch_cosmics_
int minBunch_cosmics_
Definition: PileUp.h:128
boostrapWithFamos_cff.averageNumber
averageNumber
Definition: boostrapWithFamos_cff.py:15
edm::PileUp::reload
void reload(const edm::EventSetup &setup)
Definition: PileUp.cc:234
edm::PileUp::processContext_
std::shared_ptr< ProcessContext > processContext_
Definition: PileUp.h:135
edm::StreamID
Definition: StreamID.h:30
edm::PileUp::input
void input(unsigned int s)
Definition: PileUp.h:100
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::PileUp::intAverage_
const int intAverage_
Definition: PileUp.h:111
edm::PileUp::randomEngine
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:343
edm::PileUp::fixed_OOT_
bool fixed_OOT_
Definition: PileUp.h:120
edm::PileUp::PileUp
PileUp(ParameterSet const &pset, const std::shared_ptr< PileUpConfig > &config)
Definition: PileUp.cc:66
edm::PileUp::streamContext_
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:136
edm::PileUp::readPileUp
void readPileUp(edm::EventID const &signal, std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T eventOperator, int const NumPU, StreamID const &)
Definition: PileUp.h:187
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::PileUp::poissonDistr_OOT
std::unique_ptr< CLHEP::RandPoisson > const & poissonDistr_OOT(StreamID const &streamID)
Definition: PileUp.cc:335
edm::Run
Definition: Run.h:45
edm::PileUp::probFunctionDistribution_
bool probFunctionDistribution_
Definition: PileUp.h:114
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::PileUp::poisson_
bool poisson_
Definition: PileUp.h:115
edm::PileUp::processConfiguration_
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:134
edm::PileUp::inputType_
unsigned int inputType_
Definition: PileUp.h:107
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
edm::PileUp::fixed_
bool fixed_
Definition: PileUp.h:116
edm::PileUp::maxBunch_cosmics_
int maxBunch_cosmics_
Definition: PileUp.h:129
edm::PileUp::randomEngine_
CLHEP::HepRandomEngine * randomEngine_
Definition: PileUp.h:143
edm::PileUp::PU_Study_
bool PU_Study_
Definition: PileUp.h:122
edm::PileUp::setupPileUpEvent
void setupPileUpEvent(const edm::EventSetup &setup)
Definition: PileUp.cc:225
edm::PileUp::input
const unsigned int & input() const
Definition: PileUp.h:99
edm::EventPrincipal::id
EventID const & id() const
Definition: EventPrincipal.h:92
edm::PileUp::intFixed_OOT_
int intFixed_OOT_
Definition: PileUp.h:125
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::PileUp
Definition: PileUp.h:40
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
config
Definition: config.py:1
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::PileUp::sequential_
bool sequential_
Definition: PileUp.h:153
edm::EventPrincipal
Definition: EventPrincipal.h:46
personalPlayback.playback
playback
Definition: personalPlayback.py:503
EventPrincipal.h
edm::RecordEventID::eventOperator_
T & eventOperator_
Definition: PileUp.h:160
edm::PileUp::none_
bool none_
Definition: PileUp.h:117
EventID.h
edm::RecordEventID::operator()
bool operator()(EventPrincipal const &eventPrincipal, size_t fileNameHash)
Definition: PileUp.h:166
mps_fire.end
end
Definition: mps_fire.py:242
edm::PileUp::poisson_OOT_
bool poisson_OOT_
Definition: PileUp.h:119
edm::PileUp::fileNameHash_
size_t fileNameHash_
Definition: PileUp.h:131
edm::PileUp::averageNumber_
double averageNumber_
Definition: PileUp.h:110
edm::PileUp::averageNumber
double averageNumber() const
Definition: PileUp.h:64
CLHEP
Definition: CocoaGlobals.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::PileUp::runPrincipal_
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:139
edm::PileUp::dropUnwantedBranches
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
Definition: PileUp.h:73
edm::ParameterSet
Definition: ParameterSet.h:47
edm::PileUp::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
Definition: PileUp.cc:205
edm::PileUp::~PileUp
~PileUp()
Definition: PileUp.cc:325
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
edm::PileUp::endStream
void endStream()
Definition: PileUp.cc:190
edm::PileUp::eventPrincipal_
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:137
edm::PileUp::PoissonDistr_OOT_
std::unique_ptr< CLHEP::RandPoisson > PoissonDistr_OOT_
Definition: PileUp.h:142
edm::RecordEventID::ids_
std::vector< edm::SecondaryEventIDAndFileInfo > & ids_
Definition: PileUp.h:159
edm::PileUp::endRun
void endRun(const edm::Run &run, const edm::EventSetup &setup)
Definition: PileUp.cc:214
edm::PileUp::type_
std::string type_
Definition: PileUp.h:108
edm::PileUp::productRegistry_
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:132
edm::PileUpConfig::averageNumber_
double averageNumber_
Definition: PileUp.h:35
edm::PileUp::Source_type_
std::string Source_type_
Definition: PileUp.h:109
edm::PileUp::histo_
std::shared_ptr< TH1F > histo_
Definition: PileUp.h:112
edm::EventSetup
Definition: EventSetup.h:57
edm::PileUp::manage_OOT_
bool manage_OOT_
Definition: PileUp.h:118
edm::PileUp::input_
const std::unique_ptr< VectorInputSource > input_
Definition: PileUp.h:133
edm::PileUp::endLuminosityBlock
void endLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
Definition: PileUp.cc:219
edm::PileUpConfig::histo_
std::shared_ptr< TH1F > histo_
Definition: PileUp.h:36
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
edm::PileUp::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
Definition: PileUp.cc:198
edm::PileUpConfig
Definition: PileUp.h:31
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::PileUp::playOldFormatPileUp
void playOldFormatPileUp(std::vector< edm::EventID >::const_iterator begin, std::vector< edm::EventID >::const_iterator end, std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T eventOperator)
Definition: PileUp.h:215
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::PileUp::poissonDistribution
std::unique_ptr< CLHEP::RandPoissonQ > const & poissonDistribution(StreamID const &streamID)
Definition: PileUp.cc:327
edm::RecordEventID
Definition: PileUp.h:157
edm::PileUp::intFixed_ITPU_
int intFixed_ITPU_
Definition: PileUp.h:126
L1TStage2uGTEmulatorClient_cff.BX
BX
Definition: L1TStage2uGTEmulatorClient_cff.py:9
edm::PileUp::provider_
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:140
edm::RecordEventID::eventCount
int eventCount
Definition: PileUp.h:161
edm::PileUpConfig::playback_
const bool playback_
Definition: PileUp.h:37
edm::PileUp::PoissonDistribution_
std::unique_ptr< CLHEP::RandPoissonQ > PoissonDistribution_
Definition: PileUp.h:141
edm::PileUp::doPileUp
bool doPileUp(int BX)
Definition: PileUp.h:66
edm::PileUp::poisson
bool poisson() const
Definition: PileUp.h:65
edm::EventID
Definition: EventID.h:31
edm::PileUpConfig::sourcename_
std::string sourcename_
Definition: PileUp.h:34
lumi
Definition: LumiSectionData.h:20
VectorInputSource.h
edm::PileUp::playPileUp
void playPileUp(std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator begin, std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator end, std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T eventOperator)
Definition: PileUp.h:205
edm::PileUp::Study_type_
std::string Study_type_
Definition: PileUp.h:123
edm::PileUpConfig::PileUpConfig
PileUpConfig(std::string sourcename, double averageNumber, std::unique_ptr< TH1F > &histo, const bool playback)
Definition: PileUp.h:32
edm::PileUp::histoDistribution_
bool histoDistribution_
Definition: PileUp.h:113
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::PileUp::playback_
bool playback_
Definition: PileUp.h:150
edm::RecordEventID::RecordEventID
RecordEventID(std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T &eventOperator)
Definition: PileUp.h:164
edm::PileUp::CalculatePileup
void CalculatePileup(int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions, StreamID const &)
Definition: PileUp.cc:351
edm::PileUp::lumiPrincipal_
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:138