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, edm::ConsumesCollector iC, const bool mixingConfigFromDB)
 
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_
 
edm::ESGetToken< MixingModuleConfig, MixingRcdconfigToken_
 
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 45 of file PileUp.h.

Constructor & Destructor Documentation

◆ PileUp()

edm::PileUp::PileUp ( ParameterSet const &  pset,
const std::shared_ptr< PileUpConfig > &  config,
edm::ConsumesCollector  iC,
const bool  mixingConfigFromDB 
)
explicit

Definition at line 67 of file PileUp.cc.

References edm::BeginLuminosityBlock, configToken_, dqmPostProcessing_online::DB, edm::ParameterSet::emptyParameterSetID(), edm::ConsumesCollector::esConsumes(), eventPrincipal_, Exception, fixed_, fixed_OOT_, 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_, HLT_2022v12_cff::producers, productRegistry_, provider_, muonDTDigis_cfi::pset, PU_Study_, Source_type_, AlCaHLTBitMon_QueryRunRegistry::string, Study_type_, and type_.

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

◆ ~PileUp()

edm::PileUp::~PileUp ( )

Definition at line 330 of file PileUp.cc.

330 {}

Member Function Documentation

◆ averageNumber()

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

Definition at line 72 of file PileUp.h.

References averageNumber_.

Referenced by reload().

72 { return averageNumber_; }
double averageNumber_
Definition: PileUp.h:118

◆ beginLuminosityBlock()

void edm::PileUp::beginLuminosityBlock ( const edm::LuminosityBlock lumi,
const edm::EventSetup setup 
)

Definition at line 213 of file PileUp.cc.

References lumiPrincipal_, processConfiguration_, productRegistry_, provider_, runPrincipal_, singleTopDQM_cfi::setup, and streamContext_.

213  {
214  if (provider_.get() != nullptr) {
215  lumiPrincipal_.reset(new LuminosityBlockPrincipal(productRegistry_, *processConfiguration_, nullptr, 0));
216  lumiPrincipal_->setAux(lumi.luminosityBlockAuxiliary());
217  lumiPrincipal_->setRunPrincipal(runPrincipal_);
218  provider_->beginLuminosityBlock(*lumiPrincipal_, setup.impl(), lumi.moduleCallingContext(), *streamContext_);
219  }
220  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:143
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:147
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:141
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:148
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

◆ beginRun()

void edm::PileUp::beginRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 206 of file PileUp.cc.

References printConversionInfo::aux, processConfiguration_, productRegistry_, provider_, writedatasetfile::run, runPrincipal_, singleTopDQM_cfi::setup, and streamContext_.

206  {
207  if (provider_.get() != nullptr) {
208  auto aux = std::make_shared<RunAuxiliary>(run.runAuxiliary());
209  runPrincipal_.reset(new RunPrincipal(aux, productRegistry_, *processConfiguration_, nullptr, 0));
210  provider_->beginRun(*runPrincipal_, setup.impl(), run.moduleCallingContext(), *streamContext_);
211  }
212  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:143
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:141
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:148
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

◆ beginStream()

void edm::PileUp::beginStream ( edm::StreamID  )

Definition at line 187 of file PileUp.cc.

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

187  {
188  auto iID = eventPrincipal_->streamID(); // each producer has its own workermanager, so use default streamid
189  streamContext_.reset(new StreamContext(iID, processContext_.get()));
190  input_->doBeginJob();
191  if (provider_.get() != nullptr) {
192  //TODO for now, we do not support consumes from EventSetup
193  provider_->beginJob(*productRegistry_, eventsetup::ESRecordsToProxyIndices{{}});
194  provider_->beginStream(iID, *streamContext_);
195  }
196  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:142
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:141
std::shared_ptr< ProcessContext > processContext_
Definition: PileUp.h:144
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:146
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

◆ CalculatePileup()

void edm::PileUp::CalculatePileup ( int  MinBunch,
int  MaxBunch,
std::vector< int > &  PileupSelection,
std::vector< float > &  TrueNumInteractions,
StreamID const &  streamID 
)

Definition at line 356 of file PileUp.cc.

References averageNumber_, simKBmtfDigis_cfi::bx, ztail::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_.

360  {
361  // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
362  // crossing zero first, save it for later.
363 
364  int nzero_crossing = -1;
365  double Fnzero_crossing = -1;
366 
367  if (manage_OOT_) {
368  if (none_) {
369  nzero_crossing = 0;
370  } else if (poisson_) {
371  nzero_crossing = poissonDistribution(streamID)->fire();
372  } else if (fixed_) {
373  nzero_crossing = intAverage_;
375  // RANDOM_NUMBER_ERROR
376  // Random number should be generated by the engines from the
377  // RandomNumberGeneratorService. This appears to use the global
378  // engine in ROOT. This is not thread safe unless the module using
379  // it is a one module and declares a shared resource and all
380  // other modules using it also declare the same shared resource.
381  // This also breaks replay.
382  double d = GetRandom(histo_.get(), randomEngine(streamID));
383  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
384  Fnzero_crossing = d;
385  nzero_crossing = int(d);
386  }
387  }
388 
389  for (int bx = MinBunch; bx < MaxBunch + 1; ++bx) {
390  if (manage_OOT_) {
391  if (bx == 0 && !poisson_OOT_) {
392  PileupSelection.push_back(nzero_crossing);
393  TrueNumInteractions.push_back(nzero_crossing);
394  } else {
395  if (poisson_OOT_) {
396  if (PU_Study_ && (Study_type_ == "Fixed_ITPU_Vary_OOTPU") && bx == 0) {
397  PileupSelection.push_back(intFixed_ITPU_);
398  } else {
399  PileupSelection.push_back(poissonDistr_OOT(streamID)->fire(Fnzero_crossing));
400  }
401  TrueNumInteractions.push_back(Fnzero_crossing);
402  } else {
403  PileupSelection.push_back(intFixed_OOT_);
404  TrueNumInteractions.push_back(intFixed_OOT_);
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  }
bool manage_OOT_
Definition: PileUp.h:126
static Double_t GetRandom(TH1 *th1, CLHEP::HepRandomEngine *rng)
Definition: PileUp.cc:49
bool fixed_
Definition: PileUp.h:124
std::unique_ptr< CLHEP::RandPoissonQ > const & poissonDistribution(StreamID const &streamID)
Definition: PileUp.cc:332
int const intAverage_
Definition: PileUp.h:119
std::shared_ptr< TH1F > histo_
Definition: PileUp.h:120
bool probFunctionDistribution_
Definition: PileUp.h:122
std::string Study_type_
Definition: PileUp.h:131
bool histoDistribution_
Definition: PileUp.h:121
bool poisson_
Definition: PileUp.h:123
bool poisson_OOT_
Definition: PileUp.h:127
int intFixed_ITPU_
Definition: PileUp.h:134
bool PU_Study_
Definition: PileUp.h:130
d
Definition: ztail.py:151
std::unique_ptr< CLHEP::RandPoisson > const & poissonDistr_OOT(StreamID const &streamID)
Definition: PileUp.cc:340
bool none_
Definition: PileUp.h:125
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:348
int intFixed_OOT_
Definition: PileUp.h:133
double averageNumber_
Definition: PileUp.h:118

◆ doPileUp()

bool edm::PileUp::doPileUp ( int  BX)
inline

Definition at line 74 of file PileUp.h.

References averageNumber_, L1TStage2uGTEmulatorClient_cff::BX, funct::false, maxBunch_cosmics_, minBunch_cosmics_, none_, and Source_type_.

74  {
75  if (Source_type_ != "cosmics") {
76  return none_ ? false : averageNumber_ > 0.;
77  } else {
78  return (BX >= minBunch_cosmics_ && BX <= maxBunch_cosmics_);
79  }
80  }
int maxBunch_cosmics_
Definition: PileUp.h:137
int minBunch_cosmics_
Definition: PileUp.h:136
std::string Source_type_
Definition: PileUp.h:117
bool none_
Definition: PileUp.h:125
double averageNumber_
Definition: PileUp.h:118

◆ dropUnwantedBranches()

void edm::PileUp::dropUnwantedBranches ( std::vector< std::string > const &  wantedBranches)
inline

Definition at line 81 of file PileUp.h.

References input_.

81  {
82  input_->dropUnwantedBranches(wantedBranches);
83  }
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:142

◆ endLuminosityBlock()

void edm::PileUp::endLuminosityBlock ( const edm::LuminosityBlock lumi,
const edm::EventSetup setup 
)

Definition at line 227 of file PileUp.cc.

References lumiPrincipal_, provider_, singleTopDQM_cfi::setup, and streamContext_.

227  {
228  if (provider_.get() != nullptr) {
229  provider_->endLuminosityBlock(*lumiPrincipal_, setup.impl(), lumi.moduleCallingContext(), *streamContext_);
230  }
231  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:147
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

◆ endRun()

void edm::PileUp::endRun ( const edm::Run run,
const edm::EventSetup setup 
)

Definition at line 222 of file PileUp.cc.

References provider_, writedatasetfile::run, runPrincipal_, singleTopDQM_cfi::setup, and streamContext_.

222  {
223  if (provider_.get() != nullptr) {
224  provider_->endRun(*runPrincipal_, setup.impl(), run.moduleCallingContext(), *streamContext_);
225  }
226  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:148
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

◆ endStream()

void edm::PileUp::endStream ( )

Definition at line 198 of file PileUp.cc.

References input_, provider_, and streamContext_.

198  {
199  if (provider_.get() != nullptr) {
200  provider_->endStream(streamContext_->streamID(), *streamContext_);
201  provider_->endJob();
202  }
203  input_->doEndJob();
204  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:142
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

◆ input() [1/2]

const unsigned int& edm::PileUp::input ( ) const
inline

Definition at line 107 of file PileUp.h.

References inputType_.

107 { return inputType_; }
unsigned int inputType_
Definition: PileUp.h:115

◆ input() [2/2]

void edm::PileUp::input ( unsigned int  s)
inline

Definition at line 108 of file PileUp.h.

References inputType_, and alignCSCRings::s.

108 { inputType_ = s; }
unsigned int inputType_
Definition: PileUp.h:115

◆ playOldFormatPileUp()

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 224 of file PileUp.h.

References mps_fire::end, eventPrincipal_, fileNameHash_, and input_.

227  {
228  //TrueNumInteractions.push_back( end - begin ) ;
229  RecordEventID<T> recorder(ids, eventOperator);
230  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
231  }
size_t fileNameHash_
Definition: PileUp.h:140
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:142
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:146

◆ playPileUp()

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 214 of file PileUp.h.

References mps_fire::end, eventPrincipal_, fileNameHash_, and input_.

217  {
218  //TrueNumInteractions.push_back( end - begin ) ;
219  RecordEventID<T> recorder(ids, eventOperator);
220  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
221  }
size_t fileNameHash_
Definition: PileUp.h:140
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:142
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:146

◆ poisson()

bool edm::PileUp::poisson ( ) const
inline

Definition at line 73 of file PileUp.h.

References poisson_.

73 { return poisson_; }
bool poisson_
Definition: PileUp.h:123

◆ poissonDistr_OOT()

std::unique_ptr< CLHEP::RandPoisson > const & edm::PileUp::poissonDistr_OOT ( StreamID const &  streamID)
private

Definition at line 340 of file PileUp.cc.

References PoissonDistr_OOT_, and randomEngine().

Referenced by CalculatePileup().

340  {
341  if (!PoissonDistr_OOT_) {
342  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
343  PoissonDistr_OOT_ = std::make_unique<CLHEP::RandPoisson>(engine);
344  }
345  return PoissonDistr_OOT_;
346  }
std::unique_ptr< CLHEP::RandPoisson > PoissonDistr_OOT_
Definition: PileUp.h:151
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:348

◆ poissonDistribution()

std::unique_ptr< CLHEP::RandPoissonQ > const & edm::PileUp::poissonDistribution ( StreamID const &  streamID)
private

Definition at line 332 of file PileUp.cc.

References averageNumber_, PoissonDistribution_, and randomEngine().

Referenced by CalculatePileup().

332  {
333  if (!PoissonDistribution_) {
334  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
335  PoissonDistribution_ = std::make_unique<CLHEP::RandPoissonQ>(engine, averageNumber_);
336  }
337  return PoissonDistribution_;
338  }
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:348
std::unique_ptr< CLHEP::RandPoissonQ > PoissonDistribution_
Definition: PileUp.h:150
double averageNumber_
Definition: PileUp.h:118

◆ randomEngine()

CLHEP::HepRandomEngine * edm::PileUp::randomEngine ( StreamID const &  streamID)
private

Definition at line 348 of file PileUp.cc.

References randomEngine_.

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

348  {
349  if (!randomEngine_) {
351  randomEngine_ = &rng->getEngine(streamID);
352  }
353  return randomEngine_;
354  }
CLHEP::HepRandomEngine * randomEngine_
Definition: PileUp.h:152

◆ readPileUp()

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 196 of file PileUp.h.

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

200  {
201  // One reason PileUp is responsible for recording event IDs is
202  // that it is the one that knows how many events will be read.
203  ids.reserve(pileEventCnt);
204  RecordEventID<T> recorder(ids, eventOperator);
205  int read = 0;
206  CLHEP::HepRandomEngine* engine = (sequential_ ? nullptr : randomEngine(streamID));
207  read = input_->loopOverEvents(*eventPrincipal_, fileNameHash_, pileEventCnt, recorder, engine, &signal);
208  if (read != pileEventCnt)
209  edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt
210  << " requested.";
211  }
size_t fileNameHash_
Definition: PileUp.h:140
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:142
bool sequential_
Definition: PileUp.h:162
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:348
Log< level::Warning, false > LogWarning
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:146

◆ reload()

void edm::PileUp::reload ( const edm::EventSetup setup)

Definition at line 242 of file PileUp.cc.

References funct::abs(), averageNumber(), averageNumber_, configToken_, MillePedeFileConverter_cfg::e, Exception, fixed_, fixed_OOT_, histo_, histoDistribution_, mps_fire::i, inputType_, createfilelist::int, intFixed_OOT_, dqmiolumiharvest::j, LogDebug, manage_OOT_, none_, poisson_, poisson_OOT_, PoissonDistribution_, probFunctionDistribution_, singleTopDQM_cfi::setup, type_, TrackerOfflineValidation_Dqm_cff::xmax, and TrackerOfflineValidation_Dqm_cff::xmin.

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

◆ setupPileUpEvent()

void edm::PileUp::setupPileUpEvent ( const edm::EventSetup setup)

Definition at line 233 of file PileUp.cc.

References eventPrincipal_, lumiPrincipal_, provider_, singleTopDQM_cfi::setup, and streamContext_.

233  {
234  if (provider_.get() != nullptr) {
235  // note: run and lumi numbers must be modified to match lumiPrincipal_
236  eventPrincipal_->setLuminosityBlockPrincipal(lumiPrincipal_.get());
237  eventPrincipal_->setRunAndLumiNumber(lumiPrincipal_->run(), lumiPrincipal_->luminosityBlock());
238  provider_->setupPileUpEvent(*eventPrincipal_, setup.impl(), *streamContext_);
239  }
240  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:149
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:147
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:146
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:145

Member Data Documentation

◆ averageNumber_

double edm::PileUp::averageNumber_
private

Definition at line 118 of file PileUp.h.

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

◆ configToken_

edm::ESGetToken<MixingModuleConfig, MixingRcd> edm::PileUp::configToken_
private

Definition at line 139 of file PileUp.h.

Referenced by PileUp(), and reload().

◆ eventPrincipal_

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

◆ fileNameHash_

size_t edm::PileUp::fileNameHash_
private

Definition at line 140 of file PileUp.h.

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

◆ fixed_

bool edm::PileUp::fixed_
private

Definition at line 124 of file PileUp.h.

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

◆ fixed_OOT_

bool edm::PileUp::fixed_OOT_
private

Definition at line 128 of file PileUp.h.

Referenced by PileUp(), and reload().

◆ histo_

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

Definition at line 120 of file PileUp.h.

Referenced by CalculatePileup(), and reload().

◆ histoDistribution_

bool edm::PileUp::histoDistribution_
private

Definition at line 121 of file PileUp.h.

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

◆ input_

std::unique_ptr<VectorInputSource> const edm::PileUp::input_
private

◆ inputType_

unsigned int edm::PileUp::inputType_
private

Definition at line 115 of file PileUp.h.

Referenced by input(), and reload().

◆ intAverage_

int const edm::PileUp::intAverage_
private

Definition at line 119 of file PileUp.h.

Referenced by CalculatePileup().

◆ intFixed_ITPU_

int edm::PileUp::intFixed_ITPU_
private

Definition at line 134 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

◆ intFixed_OOT_

int edm::PileUp::intFixed_OOT_
private

Definition at line 133 of file PileUp.h.

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

◆ lumiPrincipal_

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

Definition at line 147 of file PileUp.h.

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

◆ manage_OOT_

bool edm::PileUp::manage_OOT_
private

Definition at line 126 of file PileUp.h.

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

◆ maxBunch_cosmics_

int edm::PileUp::maxBunch_cosmics_
private

Definition at line 137 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

◆ minBunch_cosmics_

int edm::PileUp::minBunch_cosmics_
private

Definition at line 136 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

◆ none_

bool edm::PileUp::none_
private

Definition at line 125 of file PileUp.h.

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

◆ playback_

bool edm::PileUp::playback_
private

Definition at line 159 of file PileUp.h.

◆ poisson_

bool edm::PileUp::poisson_
private

Definition at line 123 of file PileUp.h.

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

◆ poisson_OOT_

bool edm::PileUp::poisson_OOT_
private

Definition at line 127 of file PileUp.h.

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

◆ PoissonDistr_OOT_

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

Definition at line 151 of file PileUp.h.

Referenced by poissonDistr_OOT().

◆ PoissonDistribution_

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

Definition at line 150 of file PileUp.h.

Referenced by poissonDistribution(), and reload().

◆ probFunctionDistribution_

bool edm::PileUp::probFunctionDistribution_
private

Definition at line 122 of file PileUp.h.

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

◆ processConfiguration_

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

Definition at line 143 of file PileUp.h.

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

◆ processContext_

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

Definition at line 144 of file PileUp.h.

Referenced by beginStream(), and PileUp().

◆ productRegistry_

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

Definition at line 141 of file PileUp.h.

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

◆ provider_

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

◆ PU_Study_

bool edm::PileUp::PU_Study_
private

Definition at line 130 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

◆ randomEngine_

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

Definition at line 152 of file PileUp.h.

Referenced by randomEngine().

◆ runPrincipal_

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

Definition at line 148 of file PileUp.h.

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

◆ sequential_

bool edm::PileUp::sequential_
private

Definition at line 162 of file PileUp.h.

Referenced by readPileUp().

◆ Source_type_

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

Definition at line 117 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

◆ streamContext_

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

◆ Study_type_

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

Definition at line 131 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

◆ type_

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