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 beginLuminosityBlock (const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
 
void beginRun (const edm::Run &run, const edm::EventSetup &setup)
 
void beginStream (edm::StreamID)
 
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 endLuminosityBlock (const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
 
void endRun (const edm::Run &run, const edm::EventSetup &setup)
 
void endStream ()
 
const unsigned int & input () const
 
void input (unsigned int s)
 
 PileUp (ParameterSet const &pset, const std::shared_ptr< PileUpConfig > &config)
 
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_
 
std::shared_ptr< TH1F > histo_
 
bool histoDistribution_
 
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_
 
std::unique_ptr
< CLHEP::RandPoisson > 
PoissonDistr_OOT_
 
std::unique_ptr
< CLHEP::RandPoissonQ > 
PoissonDistribution_
 
bool probFunctionDistribution_
 
std::shared_ptr
< ProcessConfiguration
processConfiguration_
 
std::shared_ptr< ProcessContextprocessContext_
 
std::shared_ptr< ProductRegistryproductRegistry_
 
std::unique_ptr
< SecondaryEventProvider
provider_
 
bool PU_Study_
 
CLHEP::HepRandomEngine * randomEngine_
 
std::shared_ptr< RunPrincipalrunPrincipal_
 
bool sequential_
 
std::string Source_type_
 
std::shared_ptr< StreamContextstreamContext_
 
std::string Study_type_
 
std::string type_
 

Detailed Description

Definition at line 40 of file PileUp.h.

Constructor & Destructor Documentation

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

Definition at line 322 of file PileUp.cc.

322  {
323  }

Member Function Documentation

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

Definition at line 54 of file PileUp.h.

References averageNumber_.

Referenced by reload().

54 {return averageNumber_;}
double averageNumber_
Definition: PileUp.h:98
void edm::PileUp::beginLuminosityBlock ( const edm::LuminosityBlock lumi,
const edm::EventSetup setup 
)

Definition at line 201 of file PileUp.cc.

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

201  {
202  if (provider_.get() != nullptr) {
203  auto aux = std::make_shared<LuminosityBlockAuxiliary>(lumi.luminosityBlockAuxiliary());
204  lumiPrincipal_.reset(new LuminosityBlockPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
205  lumiPrincipal_->setRunPrincipal(runPrincipal_);
206  provider_->beginLuminosityBlock(*lumiPrincipal_, setup, lumi.moduleCallingContext(), *streamContext_);
207  }
208  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:123
ModuleCallingContext const * moduleCallingContext() const
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:127
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:121
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:128
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
void edm::PileUp::beginRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 194 of file PileUp.cc.

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

194  {
195  if (provider_.get() != nullptr) {
196  auto aux = std::make_shared<RunAuxiliary>(run.runAuxiliary());
197  runPrincipal_.reset(new RunPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
198  provider_->beginRun(*runPrincipal_, setup, run.moduleCallingContext(), *streamContext_);
199  }
200  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:123
RunAuxiliary const & runAuxiliary() const
Definition: Run.h:60
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:121
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:148
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:128
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
void edm::PileUp::beginStream ( edm::StreamID  )

Definition at line 176 of file PileUp.cc.

References eventPrincipal_, input_, processContext_, productRegistry_, provider_, and streamContext_.

176  {
177  auto iID = eventPrincipal_->streamID(); // each producer has its own workermanager, so use default streamid
178  streamContext_.reset(new StreamContext(iID, processContext_.get()));
179  input_->doBeginJob();
180  if (provider_.get() != nullptr) {
181  provider_->beginJob(*productRegistry_);
182  provider_->beginStream(iID, *streamContext_);
183  }
184  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:121
std::shared_ptr< ProcessContext > processContext_
Definition: PileUp.h:124
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
void edm::PileUp::CalculatePileup ( int  MinBunch,
int  MaxBunch,
std::vector< int > &  PileupSelection,
std::vector< float > &  TrueNumInteractions,
StreamID const &  streamID 
)

Definition at line 349 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_.

349  {
350 
351  // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
352  // crossing zero first, save it for later.
353 
354  int nzero_crossing = -1;
355  double Fnzero_crossing = -1;
356 
357  if(manage_OOT_) {
358  if (none_){
359  nzero_crossing = 0;
360  }else if (poisson_){
361  nzero_crossing = poissonDistribution(streamID)->fire() ;
362  }else if (fixed_){
363  nzero_crossing = intAverage_ ;
365  // RANDOM_NUMBER_ERROR
366  // Random number should be generated by the engines from the
367  // RandomNumberGeneratorService. This appears to use the global
368  // engine in ROOT. This is not thread safe unless the module using
369  // it is a one module and declares a shared resource and all
370  // other modules using it also declare the same shared resource.
371  // This also breaks replay.
372  double d = GetRandom(histo_.get(), randomEngine(streamID));
373  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
374  Fnzero_crossing = d;
375  nzero_crossing = int(d);
376  }
377 
378  }
379 
380  for(int bx = MinBunch; bx < MaxBunch+1; ++bx) {
381 
382  if(manage_OOT_) {
383  if(bx==0 && !poisson_OOT_) {
384  PileupSelection.push_back(nzero_crossing) ;
385  TrueNumInteractions.push_back( nzero_crossing );
386  }
387  else{
388  if(poisson_OOT_) {
389  if(PU_Study_ && (Study_type_ == "Fixed_ITPU_Vary_OOTPU" ) && bx==0 ) {
390  PileupSelection.push_back(intFixed_ITPU_) ;
391  }
392  else{
393  PileupSelection.push_back(poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
394  }
395  TrueNumInteractions.push_back( Fnzero_crossing );
396  }
397  else {
398  PileupSelection.push_back(intFixed_OOT_) ;
399  TrueNumInteractions.push_back( intFixed_OOT_ );
400  }
401  }
402  }
403  else {
404  if (none_){
405  PileupSelection.push_back(0);
406  TrueNumInteractions.push_back( 0. );
407  }else if (poisson_){
408  PileupSelection.push_back(poissonDistribution(streamID)->fire());
409  TrueNumInteractions.push_back( averageNumber_ );
410  }else if (fixed_){
411  PileupSelection.push_back(intAverage_);
412  TrueNumInteractions.push_back( intAverage_ );
414  // RANDOM_NUMBER_ERROR
415  // Random number should be generated by the engines from the
416  // RandomNumberGeneratorService. This appears to use the global
417  // engine in ROOT. This is not thread safe unless the module using
418  // it is a one module and declares a shared resource and all
419  // other modules using it also declare the same shared resource.
420  // This also breaks replay.
421  double d = GetRandom(histo_.get(), randomEngine(streamID));
422  PileupSelection.push_back(int(d));
423  TrueNumInteractions.push_back( d );
424  }
425  }
426 
427  }
428  }
bool manage_OOT_
Definition: PileUp.h:106
static Double_t GetRandom(TH1 *th1, CLHEP::HepRandomEngine *rng)
Definition: PileUp.cc:46
bool fixed_
Definition: PileUp.h:104
int const intAverage_
Definition: PileUp.h:99
std::shared_ptr< TH1F > histo_
Definition: PileUp.h:100
bool probFunctionDistribution_
Definition: PileUp.h:102
std::string Study_type_
Definition: PileUp.h:111
tuple d
Definition: ztail.py:151
bool histoDistribution_
Definition: PileUp.h:101
bool poisson_
Definition: PileUp.h:103
bool poisson_OOT_
Definition: PileUp.h:107
int intFixed_ITPU_
Definition: PileUp.h:115
std::unique_ptr< CLHEP::RandPoissonQ > const & poissonDistribution(StreamID const &streamID)
Definition: PileUp.cc:325
bool PU_Study_
Definition: PileUp.h:110
std::unique_ptr< CLHEP::RandPoisson > const & poissonDistr_OOT(StreamID const &streamID)
Definition: PileUp.cc:333
bool none_
Definition: PileUp.h:105
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:341
int intFixed_OOT_
Definition: PileUp.h:114
double averageNumber_
Definition: PileUp.h:98
bool edm::PileUp::doPileUp ( int  BX)
inline

Definition at line 56 of file PileUp.h.

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

56  {
57  if(Source_type_ != "cosmics") {
58  return none_ ? false : averageNumber_>0.;
59  }
60  else {
61  return ( BX >= minBunch_cosmics_ && BX <= maxBunch_cosmics_);
62  }
63  }
int maxBunch_cosmics_
Definition: PileUp.h:118
int minBunch_cosmics_
Definition: PileUp.h:117
std::string Source_type_
Definition: PileUp.h:97
bool none_
Definition: PileUp.h:105
double averageNumber_
Definition: PileUp.h:98
void edm::PileUp::dropUnwantedBranches ( std::vector< std::string > const &  wantedBranches)
inline

Definition at line 64 of file PileUp.h.

References input_.

64  {
65  input_->dropUnwantedBranches(wantedBranches);
66  }
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
void edm::PileUp::endLuminosityBlock ( const edm::LuminosityBlock lumi,
const edm::EventSetup setup 
)

Definition at line 215 of file PileUp.cc.

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

215  {
216  if (provider_.get() != nullptr) {
217  provider_->endLuminosityBlock(*lumiPrincipal_, setup, lumi.moduleCallingContext(), *streamContext_);
218  }
219  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
ModuleCallingContext const * moduleCallingContext() const
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:127
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
void edm::PileUp::endRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 210 of file PileUp.cc.

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

210  {
211  if (provider_.get() != nullptr) {
213  }
214  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:148
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:128
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
void edm::PileUp::endStream ( )

Definition at line 186 of file PileUp.cc.

References input_, provider_, and streamContext_.

186  {
187  if (provider_.get() != nullptr) {
188  provider_->endStream(streamContext_->streamID(), *streamContext_);
189  provider_->endJob();
190  }
191  input_->doEndJob();
192  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
const unsigned int& edm::PileUp::input ( ) const
inline

Definition at line 86 of file PileUp.h.

References inputType_.

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

Definition at line 87 of file PileUp.h.

References inputType_, and alignCSCRings::s.

87 {inputType_=s;}
unsigned int inputType_
Definition: PileUp.h:95
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 200 of file PileUp.h.

References eventPrincipal_, fileNameHash_, and input_.

200  {
201  //TrueNumInteractions.push_back( end - begin ) ;
202  RecordEventID<T> recorder(ids, eventOperator);
203  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
204  }
size_t fileNameHash_
Definition: PileUp.h:120
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
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 192 of file PileUp.h.

References eventPrincipal_, fileNameHash_, and input_.

192  {
193  //TrueNumInteractions.push_back( end - begin ) ;
194  RecordEventID<T> recorder(ids, eventOperator);
195  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
196  }
size_t fileNameHash_
Definition: PileUp.h:120
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
bool edm::PileUp::poisson ( ) const
inline

Definition at line 55 of file PileUp.h.

References poisson_.

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

Definition at line 333 of file PileUp.cc.

References PoissonDistr_OOT_, and randomEngine().

Referenced by CalculatePileup().

333  {
334  if(!PoissonDistr_OOT_) {
335  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
336  PoissonDistr_OOT_.reset(new CLHEP::RandPoisson(engine));
337  }
338  return PoissonDistr_OOT_;
339  }
std::unique_ptr< CLHEP::RandPoisson > PoissonDistr_OOT_
Definition: PileUp.h:131
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:341
std::unique_ptr< CLHEP::RandPoissonQ > const & edm::PileUp::poissonDistribution ( StreamID const &  streamID)
private

Definition at line 325 of file PileUp.cc.

References averageNumber_, PoissonDistribution_, and randomEngine().

Referenced by CalculatePileup().

325  {
326  if(!PoissonDistribution_) {
327  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
328  PoissonDistribution_.reset(new CLHEP::RandPoissonQ(engine, averageNumber_));
329  }
330  return PoissonDistribution_;
331  }
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:341
std::unique_ptr< CLHEP::RandPoissonQ > PoissonDistribution_
Definition: PileUp.h:130
double averageNumber_
Definition: PileUp.h:98
CLHEP::HepRandomEngine * edm::PileUp::randomEngine ( StreamID const &  streamID)
private

Definition at line 341 of file PileUp.cc.

References randomEngine_.

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

341  {
342  if(!randomEngine_) {
344  randomEngine_ = &rng->getEngine(streamID);
345  }
346  return randomEngine_;
347  }
CLHEP::HepRandomEngine * randomEngine_
Definition: PileUp.h:132
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 176 of file PileUp.h.

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

177  {
178 
179  // One reason PileUp is responsible for recording event IDs is
180  // that it is the one that knows how many events will be read.
181  ids.reserve(pileEventCnt);
182  RecordEventID<T> recorder(ids,eventOperator);
183  int read = 0;
184  CLHEP::HepRandomEngine* engine = (sequential_ ? nullptr : randomEngine(streamID));
185  read = input_->loopOverEvents(*eventPrincipal_, fileNameHash_, pileEventCnt, recorder, engine, &signal);
186  if (read != pileEventCnt)
187  edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt << " requested.";
188  }
size_t fileNameHash_
Definition: PileUp.h:120
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
bool sequential_
Definition: PileUp.h:142
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:341
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
void edm::PileUp::reload ( const edm::EventSetup setup)

Definition at line 230 of file PileUp.cc.

References funct::abs(), MixingInputConfig::averageNumber(), averageNumber(), averageNumber_, mps_alisetup::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_, PoissonDistribution_, probFunctionDistribution_, MixingInputConfig::probFunctionVariable(), MixingInputConfig::probValue(), MixingInputConfig::type(), type_, SiStripMonitorClusterAlca_cfi::xmax, and SiStripMonitorClusterAlca_cfi::xmin.

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

Definition at line 221 of file PileUp.cc.

References eventPrincipal_, lumiPrincipal_, provider_, and streamContext_.

221  {
222  if (provider_.get() != nullptr) {
223  // note: run and lumi numbers must be modified to match lumiPrincipal_
224  eventPrincipal_->setLuminosityBlockPrincipal(lumiPrincipal_);
225  eventPrincipal_->setRunAndLumiNumber(lumiPrincipal_->run(), lumiPrincipal_->luminosityBlock());
226  provider_->setupPileUpEvent(*eventPrincipal_, setup, *streamContext_);
227  }
228  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:127
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125

Member Data Documentation

double edm::PileUp::averageNumber_
private

Definition at line 98 of file PileUp.h.

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

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

Definition at line 120 of file PileUp.h.

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

bool edm::PileUp::fixed_
private

Definition at line 104 of file PileUp.h.

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

bool edm::PileUp::fixed_OOT_
private

Definition at line 108 of file PileUp.h.

Referenced by PileUp(), and reload().

std::shared_ptr<TH1F> edm::PileUp::histo_
private

Definition at line 100 of file PileUp.h.

Referenced by CalculatePileup(), and reload().

bool edm::PileUp::histoDistribution_
private

Definition at line 101 of file PileUp.h.

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

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

Definition at line 95 of file PileUp.h.

Referenced by input(), and reload().

int const edm::PileUp::intAverage_
private

Definition at line 99 of file PileUp.h.

Referenced by CalculatePileup().

int edm::PileUp::intFixed_ITPU_
private

Definition at line 115 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

int edm::PileUp::intFixed_OOT_
private

Definition at line 114 of file PileUp.h.

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

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

Definition at line 127 of file PileUp.h.

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

bool edm::PileUp::manage_OOT_
private

Definition at line 106 of file PileUp.h.

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

int edm::PileUp::maxBunch_cosmics_
private

Definition at line 118 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

int edm::PileUp::minBunch_cosmics_
private

Definition at line 117 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

bool edm::PileUp::none_
private

Definition at line 105 of file PileUp.h.

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

bool edm::PileUp::playback_
private

Definition at line 139 of file PileUp.h.

bool edm::PileUp::poisson_
private

Definition at line 103 of file PileUp.h.

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

bool edm::PileUp::poisson_OOT_
private

Definition at line 107 of file PileUp.h.

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

std::unique_ptr<CLHEP::RandPoisson> edm::PileUp::PoissonDistr_OOT_
private

Definition at line 131 of file PileUp.h.

Referenced by poissonDistr_OOT().

std::unique_ptr<CLHEP::RandPoissonQ> edm::PileUp::PoissonDistribution_
private

Definition at line 130 of file PileUp.h.

Referenced by poissonDistribution(), and reload().

bool edm::PileUp::probFunctionDistribution_
private

Definition at line 102 of file PileUp.h.

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

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

Definition at line 123 of file PileUp.h.

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

std::shared_ptr<ProcessContext> edm::PileUp::processContext_
private

Definition at line 124 of file PileUp.h.

Referenced by beginStream(), and PileUp().

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

Definition at line 121 of file PileUp.h.

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

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

Definition at line 110 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

CLHEP::HepRandomEngine* edm::PileUp::randomEngine_
private

Definition at line 132 of file PileUp.h.

Referenced by randomEngine().

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

Definition at line 128 of file PileUp.h.

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

bool edm::PileUp::sequential_
private

Definition at line 142 of file PileUp.h.

Referenced by readPileUp().

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

Definition at line 97 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

std::shared_ptr<StreamContext> edm::PileUp::streamContext_
private
std::string edm::PileUp::Study_type_
private

Definition at line 111 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

std::string edm::PileUp::type_
private