CMS 3D CMS Logo

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< LuminosityBlockPrincipallumiPrincipal_
 
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< ProcessConfigurationprocessConfiguration_
 
std::shared_ptr< ProcessContextprocessContext_
 
std::shared_ptr< ProductRegistryproductRegistry_
 
std::unique_ptr< SecondaryEventProviderprovider_
 
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 66 of file PileUp.cc.

References 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_, mix_2012_lumiLevel_15_20_50ns_PoissonOOTPU_cfi::OOT_type, poisson_, poisson_OOT_, probFunctionDistribution_, processConfiguration_, processContext_, particleFlowRecHitECAL_cfi::producers, productRegistry_, provider_, PU_Study_, Source_type_, AlCaHLTBitMon_QueryRunRegistry::string, Study_type_, and type_.

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

324  {
325  }

Member Function Documentation

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

Definition at line 54 of file PileUp.h.

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 203 of file PileUp.cc.

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

203  {
204  if (provider_.get() != nullptr) {
205  auto aux = std::make_shared<LuminosityBlockAuxiliary>(lumi.luminosityBlockAuxiliary());
206  lumiPrincipal_.reset(new LuminosityBlockPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
207  lumiPrincipal_->setRunPrincipal(runPrincipal_);
208  provider_->beginLuminosityBlock(*lumiPrincipal_, setup, lumi.moduleCallingContext(), *streamContext_);
209  }
210  }
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 196 of file PileUp.cc.

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

196  {
197  if (provider_.get() != nullptr) {
198  auto aux = std::make_shared<RunAuxiliary>(run.runAuxiliary());
199  runPrincipal_.reset(new RunPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
200  provider_->beginRun(*runPrincipal_, setup, run.moduleCallingContext(), *streamContext_);
201  }
202  }
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:59
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:121
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:139
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 178 of file PileUp.cc.

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

178  {
179  auto iID = eventPrincipal_->streamID(); // each producer has its own workermanager, so use default streamid
180  streamContext_.reset(new StreamContext(iID, processContext_.get()));
181  input_->doBeginJob();
182  if (provider_.get() != nullptr) {
183  provider_->beginJob(*productRegistry_);
184  provider_->beginStream(iID, *streamContext_);
185  }
186  }
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 351 of file PileUp.cc.

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

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

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 Ecal2004TBTDCRanges_v1_cff::endRun, findQualityFiles::run, and GeneralSetup::setup().

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 217 of file PileUp.cc.

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

217  {
218  if (provider_.get() != nullptr) {
219  provider_->endLuminosityBlock(*lumiPrincipal_, setup, lumi.moduleCallingContext(), *streamContext_);
220  }
221  }
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 212 of file PileUp.cc.

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

212  {
213  if (provider_.get() != nullptr) {
215  }
216  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:139
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 188 of file PileUp.cc.

References input_, provider_, and streamContext_.

188  {
189  if (provider_.get() != nullptr) {
190  provider_->endStream(streamContext_->streamID(), *streamContext_);
191  provider_->endJob();
192  }
193  input_->doEndJob();
194  }
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.

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 randomEngine, 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.

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.

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.

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 335 of file PileUp.cc.

References PoissonDistr_OOT_, and randomEngine().

Referenced by CalculatePileup().

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

Definition at line 327 of file PileUp.cc.

References averageNumber_, PoissonDistribution_, and randomEngine().

Referenced by CalculatePileup().

327  {
328  if(!PoissonDistribution_) {
329  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
330  PoissonDistribution_.reset(new CLHEP::RandPoissonQ(engine, averageNumber_));
331  }
332  return PoissonDistribution_;
333  }
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:343
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 343 of file PileUp.cc.

References randomEngine_.

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

343  {
344  if(!randomEngine_) {
346  randomEngine_ = &rng->getEngine(streamID);
347  }
348  return randomEngine_;
349  }
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 randomEngine.

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:343
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
void edm::PileUp::reload ( const edm::EventSetup setup)

Definition at line 232 of file PileUp.cc.

References funct::abs(), MixingInputConfig::averageNumber(), averageNumber(), averageNumber_, MixingModuleConfig::config(), MillePedeFileConverter_cfg::e, Exception, fixed_, fixed_OOT_, MixingInputConfig::fixedOutOfTime(), edm::EventSetup::get(), histo_, histoDistribution_, mps_fire::i, inputType_, createfilelist::int, intFixed_OOT_, LogDebug, manage_OOT_, none_, MixingInputConfig::outOfTime(), poisson_, poisson_OOT_, PoissonDistribution_, probFunctionDistribution_, MixingInputConfig::probFunctionVariable(), MixingInputConfig::probValue(), MixingInputConfig::type(), type_, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

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

Definition at line 223 of file PileUp.cc.

References eventPrincipal_, lumiPrincipal_, provider_, and streamContext_.

223  {
224  if (provider_.get() != nullptr) {
225  // note: run and lumi numbers must be modified to match lumiPrincipal_
226  eventPrincipal_->setLuminosityBlockPrincipal(lumiPrincipal_);
227  eventPrincipal_->setRunAndLumiNumber(lumiPrincipal_->run(), lumiPrincipal_->luminosityBlock());
228  provider_->setupPileUpEvent(*eventPrincipal_, setup, *streamContext_);
229  }
230  }
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 CalculatePileup(), poissonDistribution(), and reload().

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

Definition at line 126 of file PileUp.h.

Referenced by beginStream(), PileUp(), and setupPileUpEvent().

size_t edm::PileUp::fileNameHash_
private

Definition at line 120 of file PileUp.h.

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

Definition at line 122 of file PileUp.h.

Referenced by beginStream(), endStream(), and PileUp().

unsigned int edm::PileUp::inputType_
private

Definition at line 95 of file PileUp.h.

Referenced by 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 PileUp().

int edm::PileUp::minBunch_cosmics_
private

Definition at line 117 of file PileUp.h.

Referenced by PileUp().

bool edm::PileUp::none_
private

Definition at line 105 of file PileUp.h.

Referenced by CalculatePileup(), 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(), 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.

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

Definition at line 97 of file PileUp.h.

Referenced by 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