CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
edm::PileUp Class Reference

#include <PileUp.h>

Public Member Functions

double averageNumber () const
 
void beginJob ()
 
void beginLuminosityBlock (const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
 
void beginRun (const edm::Run &run, const edm::EventSetup &setup)
 
void CalculatePileup (int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions, StreamID const &)
 
bool doPileUp (int BX)
 
void dropUnwantedBranches (std::vector< std::string > const &wantedBranches)
 
void endJob ()
 
void endLuminosityBlock (const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
 
void endRun (const edm::Run &run, const edm::EventSetup &setup)
 
const unsigned int & input () const
 
void input (unsigned int s)
 
 PileUp (ParameterSet const &pset, std::string sourcename, double averageNumber, TH1F *const histo, const bool playback)
 
template<typename T >
void playOldFormatPileUp (std::vector< edm::EventID >::const_iterator begin, std::vector< edm::EventID >::const_iterator end, std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T eventOperator)
 
template<typename T >
void playPileUp (std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator begin, std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator end, std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T eventOperator)
 
bool poisson () const
 
template<typename T >
void readPileUp (edm::EventID const &signal, std::vector< edm::SecondaryEventIDAndFileInfo > &ids, T eventOperator, int const NumPU, StreamID const &)
 
void reload (const edm::EventSetup &setup)
 
void setupPileUpEvent (const edm::EventSetup &setup)
 
 ~PileUp ()
 

Private Member Functions

std::unique_ptr
< CLHEP::RandPoisson > const & 
poissonDistr_OOT (StreamID const &streamID)
 
std::unique_ptr
< CLHEP::RandPoissonQ > const & 
poissonDistribution (StreamID const &streamID)
 
CLHEP::HepRandomEngine * randomEngine (StreamID const &streamID)
 

Private Attributes

double averageNumber_
 
std::unique_ptr< EventPrincipaleventPrincipal_
 
size_t fileNameHash_
 
bool fixed_
 
bool fixed_OOT_
 
TH1F * h1f
 
TH1F * histo_
 
bool histoDistribution_
 
TH1F * hprobFunction
 
std::unique_ptr
< VectorInputSource > const 
input_
 
unsigned int inputType_
 
int const intAverage_
 
int intFixed_ITPU_
 
int intFixed_OOT_
 
std::shared_ptr
< LuminosityBlockPrincipal
lumiPrincipal_
 
bool manage_OOT_
 
int maxBunch_cosmics_
 
int minBunch_cosmics_
 
bool none_
 
bool playback_
 
bool poisson_
 
bool poisson_OOT_
 
TFile * probFileHisto
 
bool probFunctionDistribution_
 
std::shared_ptr
< ProcessConfiguration
processConfiguration_
 
std::shared_ptr< ProductRegistryproductRegistry_
 
std::unique_ptr
< SecondaryEventProvider
provider_
 
bool PU_Study_
 
std::vector
< CLHEP::HepRandomEngine * > 
randomEngines_
 
std::shared_ptr< RunPrincipalrunPrincipal_
 
bool sequential_
 
std::string Source_type_
 
std::string Study_type_
 
std::string type_
 
std::vector< std::unique_ptr
< CLHEP::RandPoisson > > 
vPoissonDistr_OOT_
 
std::vector< std::unique_ptr
< CLHEP::RandPoissonQ > > 
vPoissonDistribution_
 

Detailed Description

Definition at line 30 of file PileUp.h.

Constructor & Destructor Documentation

edm::PileUp::PileUp ( ParameterSet const &  pset,
std::string  sourcename,
double  averageNumber,
TH1F *const  histo,
const bool  playback 
)
explicit

Definition at line 64 of file PileUp.cc.

References dqmPostProcessing_online::DB, edm::ParameterSet::emptyParameterSetID(), eventPrincipal_, Exception, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), fixed_, fixed_OOT_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), histoDistribution_, input_, intFixed_ITPU_, intFixed_OOT_, edm::Service< T >::isAvailable(), manage_OOT_, maxBunch_cosmics_, minBunch_cosmics_, none_, poisson_, poisson_OOT_, probFunctionDistribution_, processConfiguration_, HLT_25ns14e33_v1_cff::producers, productRegistry_, provider_, PU_Study_, Source_type_, AlCaHLTBitMon_QueryRunRegistry::string, Study_type_, and type_.

64  :
65  type_(pset.getParameter<std::string>("type")),
66  Source_type_(sourcename),
68  intAverage_(static_cast<int>(averageNumber)),
69  histo_(histo),
70  histoDistribution_(type_ == "histo"),
71  probFunctionDistribution_(type_ == "probFunction"),
72  poisson_(type_ == "poisson"),
73  fixed_(type_ == "fixed"),
74  none_(type_ == "none"),
75  fileNameHash_(0U),
77  input_(VectorInputSourceFactory::get()->makeVectorInputSource(pset, VectorInputSourceDescription(
79  processConfiguration_(new ProcessConfiguration(std::string("@MIXING"), getReleaseVersion(), getPassID())),
82  runPrincipal_(),
83  provider_(),
88  sequential_(pset.getUntrackedParameter<bool>("sequential", false)) {
89 
90  // Use the empty parameter set for the parameter set ID of our "@MIXING" process.
92 
93  if(pset.existsAs<std::vector<ParameterSet> >("producers", true)) {
94  std::vector<ParameterSet> producers = pset.getParameter<std::vector<ParameterSet> >("producers");
95  provider_.reset(new SecondaryEventProvider(producers, *productRegistry_, processConfiguration_));
96  }
97 
98  productRegistry_->setFrozen();
99 
100  // A modified HistoryAppender must be used for unscheduled processing.
101  eventPrincipal_.reset(new EventPrincipal(input_->productRegistry(),
102  std::make_shared<BranchIDListHelper>(),
103  std::make_shared<ThinnedAssociationsHelper>(),
105  nullptr));
106 
107  bool DB=type_=="readDB";
108 
109  if (pset.exists("nbPileupEvents")) {
110  if (0 != pset.getParameter<edm::ParameterSet>("nbPileupEvents").getUntrackedParameter<int>("seed",0)) {
111  edm::LogWarning("MixingModule") << "Parameter nbPileupEvents.seed is not supported";
112  }
113  }
114 
116  if (!rng.isAvailable()) {
117  throw cms::Exception("Configuration")
118  << "PileUp requires the RandomNumberGeneratorService\n"
119  "which is not present in the configuration file. You must add the service\n"
120  "in the configuration file or remove the modules that require it.";
121  }
122 
124  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
125  << "'type' parameter (a string) has a value of '" << type_ << "'.\n"
126  << "Legal values are 'poisson', 'fixed', or 'none'\n";
127  }
128 
129  if (!DB){
130  manage_OOT_ = pset.getUntrackedParameter<bool>("manage_OOT", false);
131 
132  // Check for string describing special processing. Add these here for individual cases
133 
134  PU_Study_ = false;
135  Study_type_ = "";
136 
137  Study_type_ = pset.getUntrackedParameter<std::string>("Special_Pileup_Studies", "");
138 
139  if(Study_type_ == "Fixed_ITPU_Vary_OOTPU") {
140 
141  PU_Study_ = true;
142  intFixed_ITPU_ = pset.getUntrackedParameter<int>("intFixed_ITPU", 0);
143 
144  }
145 
146  if(manage_OOT_) { // figure out what the parameters are
147 
148  // if (playback_) throw cms::Exception("Illegal parameter clash","PileUp::PileUp(ParameterSet const& pset)")
149  // << " manage_OOT option not allowed with playback ";
150 
151  std::string OOT_type = pset.getUntrackedParameter<std::string>("OOT_type");
152 
153  if(OOT_type == "Poisson" || OOT_type == "poisson") {
154  poisson_OOT_ = true;
155  }
156  else if(OOT_type == "Fixed" || OOT_type == "fixed") {
157  fixed_OOT_ = true;
158  // read back the fixed number requested out-of-time
159  intFixed_OOT_ = pset.getUntrackedParameter<int>("intFixed_OOT", -1);
160  if(intFixed_OOT_ < 0) {
161  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
162  << " Fixed out-of-time pileup requested, but no fixed value given ";
163  }
164  }
165  else {
166  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
167  << "'OOT_type' parameter (a string) has a value of '" << OOT_type << "'.\n"
168  << "Legal values are 'poisson' or 'fixed'\n";
169  }
170  edm::LogInfo("MixingModule") <<" Out-of-time pileup will be generated with a " << OOT_type << " distribution. " ;
171  }
172  }
173 
174  if(Source_type_ == "cosmics") { // allow for some extra flexibility for mixing
175  minBunch_cosmics_ = pset.getUntrackedParameter<int>("minBunch_cosmics", -1000);
176  maxBunch_cosmics_ = pset.getUntrackedParameter<int>("maxBunch_cosmics", 1000);
177  }
178 
179 
180 
181  } // end of constructor
bool manage_OOT_
Definition: PileUp.h:96
size_t fileNameHash_
Definition: PileUp.h:110
T getUntrackedParameter(std::string const &, T const &) const
std::string getPassID()
Definition: GetPassID.h:8
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:113
TH1F * histo_
Definition: PileUp.h:90
bool fixed_
Definition: PileUp.h:94
std::vector< CLHEP::HepRandomEngine * > randomEngines_
Definition: PileUp.h:120
int const intAverage_
Definition: PileUp.h:89
bool probFunctionDistribution_
Definition: PileUp.h:92
int maxBunch_cosmics_
Definition: PileUp.h:108
std::string Study_type_
Definition: PileUp.h:101
bool histoDistribution_
Definition: PileUp.h:91
bool poisson_
Definition: PileUp.h:93
double averageNumber() const
Definition: PileUp.h:44
bool playback_
Definition: PileUp.h:127
std::vector< std::unique_ptr< CLHEP::RandPoissonQ > > vPoissonDistribution_
Definition: PileUp.h:118
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
bool poisson_OOT_
Definition: PileUp.h:97
bool isAvailable() const
Definition: Service.h:46
int intFixed_ITPU_
Definition: PileUp.h:105
bool PU_Study_
Definition: PileUp.h:100
bool fixed_OOT_
Definition: PileUp.h:98
int minBunch_cosmics_
Definition: PileUp.h:107
std::string getReleaseVersion()
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:115
std::string type_
Definition: PileUp.h:86
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:111
bool sequential_
Definition: PileUp.h:130
std::string Source_type_
Definition: PileUp.h:87
bool none_
Definition: PileUp.h:95
std::vector< std::unique_ptr< CLHEP::RandPoisson > > vPoissonDistr_OOT_
Definition: PileUp.h:119
int intFixed_OOT_
Definition: PileUp.h:104
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:114
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:116
static VectorInputSourceFactory const * get()
static ParameterSetID emptyParameterSetID()
double averageNumber_
Definition: PileUp.h:88
edm::PileUp::~PileUp ( )

Definition at line 332 of file PileUp.cc.

332  {
333  }

Member Function Documentation

double edm::PileUp::averageNumber ( ) const
inline

Definition at line 44 of file PileUp.h.

References averageNumber_.

Referenced by reload().

44 {return averageNumber_;}
double averageNumber_
Definition: PileUp.h:88
void edm::PileUp::beginJob ( void  )

Definition at line 187 of file PileUp.cc.

References input_, productRegistry_, and provider_.

187  {
188  input_->doBeginJob();
189  if (provider_.get() != nullptr) {
190  provider_->beginJob(*productRegistry_);
191  }
192  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:111
void edm::PileUp::beginLuminosityBlock ( const edm::LuminosityBlock lumi,
const edm::EventSetup setup 
)

Definition at line 208 of file PileUp.cc.

References printConversionInfo::aux, edm::LuminosityBlock::luminosityBlockAuxiliary(), lumiPrincipal_, edm::LuminosityBlock::moduleCallingContext(), processConfiguration_, productRegistry_, provider_, and runPrincipal_.

208  {
209  if (provider_.get() != nullptr) {
210  auto aux = std::make_shared<LuminosityBlockAuxiliary>(lumi.luminosityBlockAuxiliary());
211  lumiPrincipal_.reset(new LuminosityBlockPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
212  lumiPrincipal_->setRunPrincipal(runPrincipal_);
213  provider_->beginLuminosityBlock(*lumiPrincipal_, setup, lumi.moduleCallingContext());
214  }
215  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:113
ModuleCallingContext const * moduleCallingContext() const
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:115
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:111
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:116
void edm::PileUp::beginRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 201 of file PileUp.cc.

References printConversionInfo::aux, edm::Run::moduleCallingContext(), processConfiguration_, productRegistry_, provider_, edm::Run::runAuxiliary(), and runPrincipal_.

201  {
202  if (provider_.get() != nullptr) {
203  auto aux = std::make_shared<RunAuxiliary>(run.runAuxiliary());
204  runPrincipal_.reset(new RunPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
205  provider_->beginRun(*runPrincipal_, setup, run.moduleCallingContext());
206  }
207  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:113
RunAuxiliary const & runAuxiliary() const
Definition: Run.h:60
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:111
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:148
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:116
void edm::PileUp::CalculatePileup ( int  MinBunch,
int  MaxBunch,
std::vector< int > &  PileupSelection,
std::vector< float > &  TrueNumInteractions,
StreamID const &  streamID 
)

Definition at line 381 of file PileUp.cc.

References averageNumber_, ztail::d, fixed_, GetRandom(), histo_, histoDistribution_, intAverage_, intFixed_ITPU_, intFixed_OOT_, manage_OOT_, none_, poisson_, poisson_OOT_, poissonDistr_OOT(), poissonDistribution(), probFunctionDistribution_, PU_Study_, randomEngine(), and Study_type_.

381  {
382 
383  // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
384  // crossing zero first, save it for later.
385 
386  int nzero_crossing = -1;
387  double Fnzero_crossing = -1;
388 
389  if(manage_OOT_) {
390  if (none_){
391  nzero_crossing = 0;
392  }else if (poisson_){
393  nzero_crossing = poissonDistribution(streamID)->fire() ;
394  }else if (fixed_){
395  nzero_crossing = intAverage_ ;
397  // RANDOM_NUMBER_ERROR
398  // Random number should be generated by the engines from the
399  // RandomNumberGeneratorService. This appears to use the global
400  // engine in ROOT. This is not thread safe unless the module using
401  // it is a one module and declares a shared resource and all
402  // other modules using it also declare the same shared resource.
403  // This also breaks replay.
404  double d = GetRandom(histo_, randomEngine(streamID));
405  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
406  Fnzero_crossing = d;
407  nzero_crossing = int(d);
408  }
409 
410  }
411 
412  for(int bx = MinBunch; bx < MaxBunch+1; ++bx) {
413 
414  if(manage_OOT_) {
415  if(bx==0 && !poisson_OOT_) {
416  PileupSelection.push_back(nzero_crossing) ;
417  TrueNumInteractions.push_back( nzero_crossing );
418  }
419  else{
420  if(poisson_OOT_) {
421  if(PU_Study_ && (Study_type_ == "Fixed_ITPU_Vary_OOTPU" ) && bx==0 ) {
422  PileupSelection.push_back(intFixed_ITPU_) ;
423  }
424  else{
425  PileupSelection.push_back(poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
426  }
427  TrueNumInteractions.push_back( Fnzero_crossing );
428  }
429  else {
430  PileupSelection.push_back(intFixed_OOT_) ;
431  TrueNumInteractions.push_back( intFixed_OOT_ );
432  }
433  }
434  }
435  else {
436  if (none_){
437  PileupSelection.push_back(0);
438  TrueNumInteractions.push_back( 0. );
439  }else if (poisson_){
440  PileupSelection.push_back(poissonDistribution(streamID)->fire());
441  TrueNumInteractions.push_back( averageNumber_ );
442  }else if (fixed_){
443  PileupSelection.push_back(intAverage_);
444  TrueNumInteractions.push_back( intAverage_ );
446  // RANDOM_NUMBER_ERROR
447  // Random number should be generated by the engines from the
448  // RandomNumberGeneratorService. This appears to use the global
449  // engine in ROOT. This is not thread safe unless the module using
450  // it is a one module and declares a shared resource and all
451  // other modules using it also declare the same shared resource.
452  // This also breaks replay.
453  double d = GetRandom(histo_, randomEngine(streamID));
454  PileupSelection.push_back(int(d));
455  TrueNumInteractions.push_back( d );
456  }
457  }
458 
459  }
460  }
bool manage_OOT_
Definition: PileUp.h:96
static Double_t GetRandom(TH1 *th1, CLHEP::HepRandomEngine *rng)
Definition: PileUp.cc:45
TH1F * histo_
Definition: PileUp.h:90
bool fixed_
Definition: PileUp.h:94
int const intAverage_
Definition: PileUp.h:89
bool probFunctionDistribution_
Definition: PileUp.h:92
std::string Study_type_
Definition: PileUp.h:101
tuple d
Definition: ztail.py:151
bool histoDistribution_
Definition: PileUp.h:91
bool poisson_
Definition: PileUp.h:93
bool poisson_OOT_
Definition: PileUp.h:97
int intFixed_ITPU_
Definition: PileUp.h:105
std::unique_ptr< CLHEP::RandPoissonQ > const & poissonDistribution(StreamID const &streamID)
Definition: PileUp.cc:335
bool PU_Study_
Definition: PileUp.h:100
std::unique_ptr< CLHEP::RandPoisson > const & poissonDistr_OOT(StreamID const &streamID)
Definition: PileUp.cc:350
bool none_
Definition: PileUp.h:95
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:365
int intFixed_OOT_
Definition: PileUp.h:104
double averageNumber_
Definition: PileUp.h:88
bool edm::PileUp::doPileUp ( int  BX)
inline

Definition at line 46 of file PileUp.h.

References averageNumber_, maxBunch_cosmics_, minBunch_cosmics_, none_, and Source_type_.

46  {
47  if(Source_type_ != "cosmics") {
48  return none_ ? false : averageNumber_>0.;
49  }
50  else {
51  return ( BX >= minBunch_cosmics_ && BX <= maxBunch_cosmics_);
52  }
53  }
int maxBunch_cosmics_
Definition: PileUp.h:108
int minBunch_cosmics_
Definition: PileUp.h:107
std::string Source_type_
Definition: PileUp.h:87
bool none_
Definition: PileUp.h:95
double averageNumber_
Definition: PileUp.h:88
void edm::PileUp::dropUnwantedBranches ( std::vector< std::string > const &  wantedBranches)
inline

Definition at line 54 of file PileUp.h.

References input_.

54  {
55  input_->dropUnwantedBranches(wantedBranches);
56  }
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
void edm::PileUp::endJob ( void  )

Definition at line 194 of file PileUp.cc.

References input_, and provider_.

194  {
195  if (provider_.get() != nullptr) {
196  provider_->endJob();
197  }
198  input_->doEndJob();
199  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
void edm::PileUp::endLuminosityBlock ( const edm::LuminosityBlock lumi,
const edm::EventSetup setup 
)

Definition at line 222 of file PileUp.cc.

References lumiPrincipal_, edm::LuminosityBlock::moduleCallingContext(), and provider_.

222  {
223  if (provider_.get() != nullptr) {
224  provider_->endLuminosityBlock(*lumiPrincipal_, setup, lumi.moduleCallingContext());
225  }
226  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
ModuleCallingContext const * moduleCallingContext() const
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:115
void edm::PileUp::endRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 217 of file PileUp.cc.

References edm::Run::moduleCallingContext(), provider_, and runPrincipal_.

217  {
218  if (provider_.get() != nullptr) {
219  provider_->endRun(*runPrincipal_, setup, run.moduleCallingContext());
220  }
221  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:148
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:116
const unsigned int& edm::PileUp::input ( ) const
inline

Definition at line 76 of file PileUp.h.

References inputType_.

76 {return inputType_;}
unsigned int inputType_
Definition: PileUp.h:85
void edm::PileUp::input ( unsigned int  s)
inline

Definition at line 77 of file PileUp.h.

References inputType_, and alignCSCRings::s.

77 {inputType_=s;}
unsigned int inputType_
Definition: PileUp.h:85
template<typename T >
void edm::PileUp::playOldFormatPileUp ( std::vector< edm::EventID >::const_iterator  begin,
std::vector< edm::EventID >::const_iterator  end,
std::vector< edm::SecondaryEventIDAndFileInfo > &  ids,
T  eventOperator 
)

Definition at line 188 of file PileUp.h.

References eventPrincipal_, fileNameHash_, and input_.

188  {
189  //TrueNumInteractions.push_back( end - begin ) ;
190  RecordEventID<T> recorder(ids, eventOperator);
191  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
192  }
size_t fileNameHash_
Definition: PileUp.h:110
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:114
template<typename T >
void edm::PileUp::playPileUp ( std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator  begin,
std::vector< edm::SecondaryEventIDAndFileInfo >::const_iterator  end,
std::vector< edm::SecondaryEventIDAndFileInfo > &  ids,
T  eventOperator 
)

Definition at line 180 of file PileUp.h.

References eventPrincipal_, fileNameHash_, and input_.

180  {
181  //TrueNumInteractions.push_back( end - begin ) ;
182  RecordEventID<T> recorder(ids, eventOperator);
183  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
184  }
size_t fileNameHash_
Definition: PileUp.h:110
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:114
bool edm::PileUp::poisson ( ) const
inline

Definition at line 45 of file PileUp.h.

References poisson_.

45 {return poisson_;}
bool poisson_
Definition: PileUp.h:93
std::unique_ptr< CLHEP::RandPoisson > const & edm::PileUp::poissonDistr_OOT ( StreamID const &  streamID)
private

Definition at line 350 of file PileUp.cc.

References cmsHarvester::index, randomEngine(), edm::StreamID::value(), and vPoissonDistr_OOT_.

Referenced by CalculatePileup().

350  {
351  unsigned int index = streamID.value();
352  if(index >= vPoissonDistr_OOT_.size()) {
353  // This resizing is not thread safe and only works because
354  // this is used by a "one" type module
355  vPoissonDistr_OOT_.resize(index + 1);
356  }
357  std::unique_ptr<CLHEP::RandPoisson>& ptr = vPoissonDistr_OOT_[index];
358  if(!ptr) {
359  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
360  ptr.reset(new CLHEP::RandPoisson(engine));
361  }
362  return ptr;
363  }
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:365
std::vector< std::unique_ptr< CLHEP::RandPoisson > > vPoissonDistr_OOT_
Definition: PileUp.h:119
std::unique_ptr< CLHEP::RandPoissonQ > const & edm::PileUp::poissonDistribution ( StreamID const &  streamID)
private

Definition at line 335 of file PileUp.cc.

References averageNumber_, cmsHarvester::index, randomEngine(), edm::StreamID::value(), and vPoissonDistribution_.

Referenced by CalculatePileup().

335  {
336  unsigned int index = streamID.value();
337  if(index >= vPoissonDistribution_.size()) {
338  // This resizing is not thread safe and only works because
339  // this is used by a "one" type module
340  vPoissonDistribution_.resize(index + 1);
341  }
342  std::unique_ptr<CLHEP::RandPoissonQ>& ptr = vPoissonDistribution_[index];
343  if(!ptr) {
344  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
345  ptr.reset(new CLHEP::RandPoissonQ(engine, averageNumber_));
346  }
347  return ptr;
348  }
std::vector< std::unique_ptr< CLHEP::RandPoissonQ > > vPoissonDistribution_
Definition: PileUp.h:118
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:365
double averageNumber_
Definition: PileUp.h:88
CLHEP::HepRandomEngine * edm::PileUp::randomEngine ( StreamID const &  streamID)
private

Definition at line 365 of file PileUp.cc.

References cmsHarvester::index, randomEngines_, and edm::StreamID::value().

Referenced by CalculatePileup(), poissonDistr_OOT(), poissonDistribution(), and readPileUp().

365  {
366  unsigned int index = streamID.value();
367  if(index >= randomEngines_.size()) {
368  // This resizing is not thread safe and only works because
369  // this is used by a "one" type module
370  randomEngines_.resize(index + 1, nullptr);
371  }
372  CLHEP::HepRandomEngine* ptr = randomEngines_[index];
373  if(!ptr) {
375  ptr = &rng->getEngine(streamID);
376  randomEngines_[index] = ptr;
377  }
378  return ptr;
379  }
std::vector< CLHEP::HepRandomEngine * > randomEngines_
Definition: PileUp.h:120
template<typename T >
void edm::PileUp::readPileUp ( edm::EventID const &  signal,
std::vector< edm::SecondaryEventIDAndFileInfo > &  ids,
T  eventOperator,
int const  pileEventCnt,
StreamID const &  streamID 
)

Generates events from a VectorInputSource. This function decides which method of VectorInputSource to call: sequential, random, or pre-specified. The ids are either ids to read or ids to store while reading. eventOperator has a type that matches the eventOperator in VectorInputSource::loopRandom.

The "signal" event is optionally used to restrict the secondary events used for pileup and mixing.

Definition at line 164 of file PileUp.h.

References eventPrincipal_, fileNameHash_, input_, randomEngine(), SiPixelLorentzAngle_cfi::read, and sequential_.

165  {
166 
167  // One reason PileUp is responsible for recording event IDs is
168  // that it is the one that knows how many events will be read.
169  ids.reserve(pileEventCnt);
170  RecordEventID<T> recorder(ids,eventOperator);
171  int read = 0;
172  CLHEP::HepRandomEngine* engine = (sequential_ ? nullptr : randomEngine(streamID));
173  read = input_->loopOverEvents(*eventPrincipal_, fileNameHash_, pileEventCnt, recorder, engine, &signal);
174  if (read != pileEventCnt)
175  edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt << " requested.";
176  }
size_t fileNameHash_
Definition: PileUp.h:110
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:112
bool sequential_
Definition: PileUp.h:130
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:365
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:114
void edm::PileUp::reload ( const edm::EventSetup setup)

Definition at line 237 of file PileUp.cc.

References funct::abs(), MixingInputConfig::averageNumber(), averageNumber(), averageNumber_, HDQMDatabaseProducer::config, alignCSCRings::e, Exception, fixed_, fixed_OOT_, MixingInputConfig::fixedOutOfTime(), edm::EventSetup::get(), histo_, histoDistribution_, i, inputType_, intFixed_OOT_, j, LogDebug, manage_OOT_, none_, MixingInputConfig::outOfTime(), poisson_, poisson_OOT_, probFunctionDistribution_, MixingInputConfig::probFunctionVariable(), MixingInputConfig::probValue(), MixingInputConfig::type(), type_, vPoissonDistribution_, SiStripMonitorClusterAlca_cfi::xmax, and SiStripMonitorClusterAlca_cfi::xmin.

237  {
238  //get the required parameters from DB.
240  setup.get<MixingRcd>().get(configM);
241 
242  const MixingInputConfig & config=configM->config(inputType_);
243 
244  //get the type
245  type_=config.type();
246  //set booleans
247  histoDistribution_=type_ == "histo";
248  probFunctionDistribution_=type_ == "probFunction";
249  poisson_=type_ == "poisson";
250  fixed_=type_ == "fixed";
251  none_=type_ == "none";
252 
253  if (histoDistribution_) edm::LogError("MisConfiguration")<<"type histo cannot be reloaded from DB, yet";
254 
255  if (fixed_){
257  }
258  else if (poisson_)
259  {
260  averageNumber_=config.averageNumber();
261  for(auto & distribution : vPoissonDistribution_) {
262  if(distribution) {
263  distribution.reset(new CLHEP::RandPoissonQ(distribution->engine(), averageNumber_));
264  }
265  }
266  }
267  else if (probFunctionDistribution_)
268  {
269  //need to reload the histogram from DB
270  const std::vector<int> & dataProbFunctionVar = config.probFunctionVariable();
271  std::vector<double> dataProb = config.probValue();
272 
273  int varSize = (int) dataProbFunctionVar.size();
274  int probSize = (int) dataProb.size();
275 
276  if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
277  throw cms::Exception("BadProbFunction") << "Please, check the variables of the probability function! The first variable should be 0 and the difference between two variables should be 1." << std::endl;
278 
279  // Complete the vector containing the probability function data
280  // with the values "0"
281  if (probSize < varSize){
282  edm::LogWarning("MixingModule") << " The probability function data will be completed with " <<(varSize - probSize) <<" values 0.";
283 
284  for (int i=0; i<(varSize - probSize); i++) dataProb.push_back(0);
285 
286  probSize = dataProb.size();
287  edm::LogInfo("MixingModule") << " The number of the P(x) data set after adding the values 0 is " << probSize;
288  }
289 
290  // Create an histogram with the data from the probability function provided by the user
291  int xmin = (int) dataProbFunctionVar[0];
292  int xmax = (int) dataProbFunctionVar[varSize-1]+1; // need upper edge to be one beyond last value
293  int numBins = varSize;
294 
295  edm::LogInfo("MixingModule") << "An histogram will be created with " << numBins << " bins in the range ("<< xmin << "," << xmax << ")." << std::endl;
296 
297  if (histo_) delete histo_;
298  histo_ = new TH1F("h","Histo from the user's probability function",numBins,xmin,xmax);
299 
300  LogDebug("MixingModule") << "Filling histogram with the following data:" << std::endl;
301 
302  for (int j=0; j < numBins ; j++){
303  LogDebug("MixingModule") << " x = " << dataProbFunctionVar[j ]<< " P(x) = " << dataProb[j];
304  histo_->Fill(dataProbFunctionVar[j]+0.5,dataProb[j]); // assuming integer values for the bins, fill bin centers, not edges
305  }
306 
307  // Check if the histogram is normalized
308  if (std::abs(histo_->Integral() - 1) > 1.0e-02){
309  throw cms::Exception("BadProbFunction") << "The probability function should be normalized!!! " << std::endl;
310  }
311  averageNumber_=histo_->GetMean();
312  }
313 
314  int oot=config.outOfTime();
315  manage_OOT_=false;
316  if (oot==1)
317  {
318  manage_OOT_=true;
319  poisson_OOT_ = false;
320  fixed_OOT_ = true;
321  intFixed_OOT_=config.fixedOutOfTime();
322  }
323  else if (oot==2)
324  {
325  manage_OOT_=true;
326  poisson_OOT_ = true;
327  fixed_OOT_ = false;
328  }
329 
330 
331  }
#define LogDebug(id)
bool manage_OOT_
Definition: PileUp.h:96
int i
Definition: DBlmapReader.cc:9
unsigned int inputType_
Definition: PileUp.h:85
const int fixedOutOfTime() const
TH1F * histo_
Definition: PileUp.h:90
bool fixed_
Definition: PileUp.h:94
const std::vector< double > & probValue() const
const double averageNumber() const
bool probFunctionDistribution_
Definition: PileUp.h:92
bool histoDistribution_
Definition: PileUp.h:91
bool poisson_
Definition: PileUp.h:93
double averageNumber() const
Definition: PileUp.h:44
const int outOfTime() const
std::vector< std::unique_ptr< CLHEP::RandPoissonQ > > vPoissonDistribution_
Definition: PileUp.h:118
bool poisson_OOT_
Definition: PileUp.h:97
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
bool fixed_OOT_
Definition: PileUp.h:98
std::string type_
Definition: PileUp.h:86
const T & get() const
Definition: EventSetup.h:56
const std::vector< int > & probFunctionVariable() const
bool none_
Definition: PileUp.h:95
int intFixed_OOT_
Definition: PileUp.h:104
std::string type() const
double averageNumber_
Definition: PileUp.h:88
void edm::PileUp::setupPileUpEvent ( const edm::EventSetup setup)

Definition at line 228 of file PileUp.cc.

References eventPrincipal_, lumiPrincipal_, and provider_.

228  {
229  if (provider_.get() != nullptr) {
230  // note: run and lumi numbers must be modified to match lumiPrincipal_
231  eventPrincipal_->setLuminosityBlockPrincipal(lumiPrincipal_);
232  eventPrincipal_->setRunAndLumiNumber(lumiPrincipal_->run(), lumiPrincipal_->luminosityBlock());
233  provider_->setupPileUpEvent(*eventPrincipal_, setup);
234  }
235  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:117
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:115
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:114

Member Data Documentation

double edm::PileUp::averageNumber_
private

Definition at line 88 of file PileUp.h.

Referenced by averageNumber(), CalculatePileup(), doPileUp(), poissonDistribution(), and reload().

std::unique_ptr<EventPrincipal> edm::PileUp::eventPrincipal_
private

Definition at line 114 of file PileUp.h.

Referenced by PileUp(), playOldFormatPileUp(), playPileUp(), readPileUp(), and setupPileUpEvent().

size_t edm::PileUp::fileNameHash_
private

Definition at line 110 of file PileUp.h.

Referenced by playOldFormatPileUp(), playPileUp(), and readPileUp().

bool edm::PileUp::fixed_
private

Definition at line 94 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and reload().

bool edm::PileUp::fixed_OOT_
private

Definition at line 98 of file PileUp.h.

Referenced by PileUp(), and reload().

TH1F* edm::PileUp::h1f
private

Definition at line 122 of file PileUp.h.

TH1F* edm::PileUp::histo_
private

Definition at line 90 of file PileUp.h.

Referenced by CalculatePileup(), and reload().

bool edm::PileUp::histoDistribution_
private

Definition at line 91 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and reload().

TH1F* edm::PileUp::hprobFunction
private

Definition at line 123 of file PileUp.h.

std::unique_ptr<VectorInputSource> const edm::PileUp::input_
private
unsigned int edm::PileUp::inputType_
private

Definition at line 85 of file PileUp.h.

Referenced by input(), and reload().

int const edm::PileUp::intAverage_
private

Definition at line 89 of file PileUp.h.

Referenced by CalculatePileup().

int edm::PileUp::intFixed_ITPU_
private

Definition at line 105 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

int edm::PileUp::intFixed_OOT_
private

Definition at line 104 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and reload().

std::shared_ptr<LuminosityBlockPrincipal> edm::PileUp::lumiPrincipal_
private

Definition at line 115 of file PileUp.h.

Referenced by beginLuminosityBlock(), endLuminosityBlock(), and setupPileUpEvent().

bool edm::PileUp::manage_OOT_
private

Definition at line 96 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and reload().

int edm::PileUp::maxBunch_cosmics_
private

Definition at line 108 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

int edm::PileUp::minBunch_cosmics_
private

Definition at line 107 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

bool edm::PileUp::none_
private

Definition at line 95 of file PileUp.h.

Referenced by CalculatePileup(), doPileUp(), PileUp(), and reload().

bool edm::PileUp::playback_
private

Definition at line 127 of file PileUp.h.

bool edm::PileUp::poisson_
private

Definition at line 93 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), poisson(), and reload().

bool edm::PileUp::poisson_OOT_
private

Definition at line 97 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and reload().

TFile* edm::PileUp::probFileHisto
private

Definition at line 124 of file PileUp.h.

bool edm::PileUp::probFunctionDistribution_
private

Definition at line 92 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and reload().

std::shared_ptr<ProcessConfiguration> edm::PileUp::processConfiguration_
private

Definition at line 113 of file PileUp.h.

Referenced by beginLuminosityBlock(), beginRun(), and PileUp().

std::shared_ptr<ProductRegistry> edm::PileUp::productRegistry_
private

Definition at line 111 of file PileUp.h.

Referenced by beginJob(), beginLuminosityBlock(), beginRun(), and PileUp().

std::unique_ptr<SecondaryEventProvider> edm::PileUp::provider_
private
bool edm::PileUp::PU_Study_
private

Definition at line 100 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

std::vector<CLHEP::HepRandomEngine*> edm::PileUp::randomEngines_
private

Definition at line 120 of file PileUp.h.

Referenced by randomEngine().

std::shared_ptr<RunPrincipal> edm::PileUp::runPrincipal_
private

Definition at line 116 of file PileUp.h.

Referenced by beginLuminosityBlock(), beginRun(), and endRun().

bool edm::PileUp::sequential_
private

Definition at line 130 of file PileUp.h.

Referenced by readPileUp().

std::string edm::PileUp::Source_type_
private

Definition at line 87 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

std::string edm::PileUp::Study_type_
private

Definition at line 101 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

std::string edm::PileUp::type_
private
std::vector<std::unique_ptr<CLHEP::RandPoisson> > edm::PileUp::vPoissonDistr_OOT_
private

Definition at line 119 of file PileUp.h.

Referenced by poissonDistr_OOT().

std::vector<std::unique_ptr<CLHEP::RandPoissonQ> > edm::PileUp::vPoissonDistribution_
private

Definition at line 118 of file PileUp.h.

Referenced by poissonDistribution(), and reload().