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 67 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_.

67  :
68  type_(pset.getParameter<std::string>("type")),
69  Source_type_(config->sourcename_),
70  averageNumber_(config->averageNumber_),
71  intAverage_(static_cast<int>(averageNumber_)),
72  histo_(std::make_shared<TH1F>(*config->histo_)),
73  histoDistribution_(type_ == "histo"),
74  probFunctionDistribution_(type_ == "probFunction"),
75  poisson_(type_ == "poisson"),
76  fixed_(type_ == "fixed"),
77  none_(type_ == "none"),
78  fileNameHash_(0U),
80  input_(VectorInputSourceFactory::get()->makeVectorInputSource(pset, VectorInputSourceDescription(
82  processConfiguration_(new ProcessConfiguration(std::string("@MIXING"), getReleaseVersion(), getPassID())),
83  processContext_(new ProcessContext()),
86  runPrincipal_(),
87  provider_(),
90  randomEngine_(),
91  playback_(config->playback_),
92  sequential_(pset.getUntrackedParameter<bool>("sequential", false)) {
93 
94  // Use the empty parameter set for the parameter set ID of our "@MIXING" process.
96  processContext_->setProcessConfiguration(processConfiguration_.get());
97 
98  if(pset.existsAs<std::vector<ParameterSet> >("producers", true)) {
99  std::vector<ParameterSet> producers = pset.getParameter<std::vector<ParameterSet> >("producers");
100  provider_.reset(new SecondaryEventProvider(producers, *productRegistry_, processConfiguration_));
101  }
102 
103  productRegistry_->setFrozen();
104 
105  // A modified HistoryAppender must be used for unscheduled processing.
106  eventPrincipal_.reset(new EventPrincipal(input_->productRegistry(),
107  std::make_shared<BranchIDListHelper>(),
108  std::make_shared<ThinnedAssociationsHelper>(),
110  nullptr));
111 
112  bool DB=type_=="readDB";
113 
114  if (pset.exists("nbPileupEvents")) {
115  if (0 != pset.getParameter<edm::ParameterSet>("nbPileupEvents").getUntrackedParameter<int>("seed",0)) {
116  edm::LogWarning("MixingModule") << "Parameter nbPileupEvents.seed is not supported";
117  }
118  }
119 
121  if (!rng.isAvailable()) {
122  throw cms::Exception("Configuration")
123  << "PileUp requires the RandomNumberGeneratorService\n"
124  "which is not present in the configuration file. You must add the service\n"
125  "in the configuration file or remove the modules that require it.";
126  }
127 
129  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
130  << "'type' parameter (a string) has a value of '" << type_ << "'.\n"
131  << "Legal values are 'poisson', 'fixed', or 'none'\n";
132  }
133 
134  if (!DB){
135  manage_OOT_ = pset.getUntrackedParameter<bool>("manage_OOT", false);
136 
137  // Check for string describing special processing. Add these here for individual cases
138  PU_Study_ = false;
139  Study_type_ = pset.getUntrackedParameter<std::string>("Special_Pileup_Studies", "");
140 
141  if(Study_type_ == "Fixed_ITPU_Vary_OOTPU") {
142  PU_Study_ = true;
143  intFixed_ITPU_ = pset.getUntrackedParameter<int>("intFixed_ITPU", 0);
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  } else {
165  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
166  << "'OOT_type' parameter (a string) has a value of '" << OOT_type << "'.\n"
167  << "Legal values are 'poisson' or 'fixed'\n";
168  }
169  edm::LogInfo("MixingModule") <<" Out-of-time pileup will be generated with a " << OOT_type << " distribution. " ;
170  }
171  }
172 
173  if(Source_type_ == "cosmics") { // allow for some extra flexibility for mixing
174  minBunch_cosmics_ = pset.getUntrackedParameter<int>("minBunch_cosmics", -1000);
175  maxBunch_cosmics_ = pset.getUntrackedParameter<int>("maxBunch_cosmics", 1000);
176  }
177  } // 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:7
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:40
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()
Definition: ParameterSet.cc:87
double averageNumber_
Definition: PileUp.h:98
edm::PileUp::~PileUp ( )

Definition at line 326 of file PileUp.cc.

326  {
327  }

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

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

205  {
206  if (provider_.get() != nullptr) {
207  lumiPrincipal_.reset(new LuminosityBlockPrincipal(productRegistry_, *processConfiguration_, nullptr, 0));
209  lumiPrincipal_->setRunPrincipal(runPrincipal_);
210  provider_->beginLuminosityBlock(*lumiPrincipal_, setup.impl(), lumi.moduleCallingContext(), *streamContext_);
211  }
212  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:123
ModuleCallingContext const * moduleCallingContext() const
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const override
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:127
edm::EventSetupImpl const & impl() const
Definition: EventSetup.h:176
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 198 of file PileUp.cc.

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

198  {
199  if (provider_.get() != nullptr) {
200  auto aux = std::make_shared<RunAuxiliary>(run.runAuxiliary());
201  runPrincipal_.reset(new RunPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
202  provider_->beginRun(*runPrincipal_, setup.impl(), run.moduleCallingContext(), *streamContext_);
203  }
204  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:123
RunAuxiliary const & runAuxiliary() const override
Definition: Run.h:61
edm::EventSetupImpl const & impl() const
Definition: EventSetup.h:176
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:121
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:147
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 179 of file PileUp.cc.

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

179  {
180  auto iID = eventPrincipal_->streamID(); // each producer has its own workermanager, so use default streamid
181  streamContext_.reset(new StreamContext(iID, processContext_.get()));
182  input_->doBeginJob();
183  if (provider_.get() != nullptr) {
184  //TODO for now, we do not support consumes from EventSetup
185  provider_->beginJob(*productRegistry_, eventsetup::ESRecordsToProxyIndices{ {} });
186  provider_->beginStream(iID, *streamContext_);
187  }
188  }
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 353 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_.

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

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

219  {
220  if (provider_.get() != nullptr) {
221  provider_->endLuminosityBlock(*lumiPrincipal_, setup.impl(), lumi.moduleCallingContext(), *streamContext_);
222  }
223  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
ModuleCallingContext const * moduleCallingContext() const
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:127
edm::EventSetupImpl const & impl() const
Definition: EventSetup.h:176
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:125
void edm::PileUp::endRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 214 of file PileUp.cc.

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

214  {
215  if (provider_.get() != nullptr) {
216  provider_->endRun(*runPrincipal_, setup.impl(), run.moduleCallingContext(), *streamContext_);
217  }
218  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
edm::EventSetupImpl const & impl() const
Definition: EventSetup.h:176
ModuleCallingContext const * moduleCallingContext() const
Definition: Run.h:147
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 190 of file PileUp.cc.

References input_, provider_, and streamContext_.

190  {
191  if (provider_.get() != nullptr) {
192  provider_->endStream(streamContext_->streamID(), *streamContext_);
193  provider_->endJob();
194  }
195  input_->doEndJob();
196  }
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 204 of file PileUp.h.

204  {
205  //TrueNumInteractions.push_back( end - begin ) ;
206  RecordEventID<T> recorder(ids, eventOperator);
207  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
208  }
size_t fileNameHash_
Definition: PileUp.h:120
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
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 196 of file PileUp.h.

196  {
197  //TrueNumInteractions.push_back( end - begin ) ;
198  RecordEventID<T> recorder(ids, eventOperator);
199  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
200  }
size_t fileNameHash_
Definition: PileUp.h:120
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:122
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
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 337 of file PileUp.cc.

References PoissonDistr_OOT_, and randomEngine().

Referenced by CalculatePileup().

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

Definition at line 329 of file PileUp.cc.

References averageNumber_, PoissonDistribution_, and randomEngine().

Referenced by CalculatePileup().

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

References randomEngine_.

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

345  {
346  if(!randomEngine_) {
348  randomEngine_ = &rng->getEngine(streamID);
349  }
350  return randomEngine_;
351  }
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 180 of file PileUp.h.

References randomEngine.

181  {
182 
183  // One reason PileUp is responsible for recording event IDs is
184  // that it is the one that knows how many events will be read.
185  ids.reserve(pileEventCnt);
186  RecordEventID<T> recorder(ids,eventOperator);
187  int read = 0;
188  CLHEP::HepRandomEngine* engine = (sequential_ ? nullptr : randomEngine(streamID));
189  read = input_->loopOverEvents(*eventPrincipal_, fileNameHash_, pileEventCnt, recorder, engine, &signal);
190  if (read != pileEventCnt)
191  edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt << " requested.";
192  }
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:345
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:126
void edm::PileUp::reload ( const edm::EventSetup setup)

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

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

References eventPrincipal_, edm::EventSetup::impl(), lumiPrincipal_, provider_, and streamContext_.

225  {
226  if (provider_.get() != nullptr) {
227  // note: run and lumi numbers must be modified to match lumiPrincipal_
228  eventPrincipal_->setLuminosityBlockPrincipal(lumiPrincipal_.get());
229  eventPrincipal_->setRunAndLumiNumber(lumiPrincipal_->run(), lumiPrincipal_->luminosityBlock());
230  provider_->setupPileUpEvent(*eventPrincipal_, setup.impl(), *streamContext_);
231  }
232  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:129
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:127
edm::EventSetupImpl const & impl() const
Definition: EventSetup.h:176
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