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 beginJob (eventsetup::ESRecordsToProxyIndices 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)
 
void setRandomEngine (StreamID)
 
void setRandomEngine (LuminosityBlock const &)
 

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_
 
PileupRandomNumberGeneratorrandomGenerator_ = nullptr
 
std::shared_ptr< RunPrincipalrunPrincipal_
 
bool sequential_
 
std::optional< ServiceTokenserviceToken_
 
std::string Source_type_
 
std::shared_ptr< StreamContextstreamContext_
 
std::string Study_type_
 
std::string type_
 

Detailed Description

Definition at line 43 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 69 of file PileUp.cc.

References edm::BeginLuminosityBlock, configToken_, edm::ServiceRegistry::createContaining(), dqmPostProcessing_online::DB, edm::ParameterSet::emptyParameterSetID(), edm::ConsumesCollector::esConsumes(), eventPrincipal_, Exception, fixed_, fixed_OOT_, edm::ParameterSet::getUntrackedParameter(), histoDistribution_, input_, edm::ServiceRegistry::instance(), intFixed_ITPU_, intFixed_OOT_, edm::Service< T >::isAvailable(), manage_OOT_, maxBunch_cosmics_, minBunch_cosmics_, eostools::move(), names, none_, mix_2012_lumiLevel_15_20_50ns_PoissonOOTPU_cfi::OOT_type, poisson_, poisson_OOT_, probFunctionDistribution_, processConfiguration_, processContext_, HLT_2022v15_cff::producers, productRegistry_, provider_, muonDTDigis_cfi::pset, PU_Study_, randomGenerator_, serviceToken_, Source_type_, AlCaHLTBitMon_QueryRunRegistry::string, Study_type_, HcalDetIdTransform::transform(), and type_.

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

◆ ~PileUp()

edm::PileUp::~PileUp ( )

Definition at line 357 of file PileUp.cc.

357 {}

Member Function Documentation

◆ averageNumber()

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

Definition at line 70 of file PileUp.h.

References averageNumber_.

Referenced by reload().

70 { return averageNumber_; }
double averageNumber_
Definition: PileUp.h:119

◆ beginJob()

void edm::PileUp::beginJob ( eventsetup::ESRecordsToProxyIndices const &  iES)

Definition at line 201 of file PileUp.cc.

References input_, productRegistry_, provider_, and serviceToken_.

201  {
202  input_->doBeginJob();
203  if (provider_.get() != nullptr) {
205  provider_->beginJob(*productRegistry_, iES);
206  }
207  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:143
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:142

◆ beginLuminosityBlock()

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

Definition at line 235 of file PileUp.cc.

References lumiPrincipal_, processConfiguration_, productRegistry_, provider_, runPrincipal_, serviceToken_, setRandomEngine(), singleTopDQM_cfi::setup, and streamContext_.

235  {
236  if (provider_.get() != nullptr) {
237  lumiPrincipal_.reset(new LuminosityBlockPrincipal(productRegistry_, *processConfiguration_, nullptr, 0));
238  lumiPrincipal_->setAux(lumi.luminosityBlockAuxiliary());
239  lumiPrincipal_->setRunPrincipal(runPrincipal_);
242  provider_->beginLuminosityBlock(*lumiPrincipal_, setup.impl(), lumi.moduleCallingContext(), *streamContext_);
243  }
244  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:144
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:148
void setRandomEngine(StreamID)
Definition: PileUp.cc:383
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:142
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:149
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

◆ beginRun()

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

Definition at line 227 of file PileUp.cc.

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

227  {
228  if (provider_.get() != nullptr) {
229  runPrincipal_.reset(new RunPrincipal(productRegistry_, *processConfiguration_, nullptr, 0));
230  runPrincipal_->setAux(run.runAuxiliary());
232  provider_->beginRun(*runPrincipal_, setup.impl(), run.moduleCallingContext(), *streamContext_);
233  }
234  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::shared_ptr< ProcessConfiguration > processConfiguration_
Definition: PileUp.h:144
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::shared_ptr< ProductRegistry > productRegistry_
Definition: PileUp.h:142
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:149
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

◆ beginStream()

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

Definition at line 209 of file PileUp.cc.

References eventPrincipal_, processContext_, provider_, serviceToken_, and streamContext_.

209  {
210  auto iID = eventPrincipal_->streamID(); // each producer has its own workermanager, so use default streamid
211  streamContext_.reset(new StreamContext(iID, processContext_.get()));
212  if (provider_.get() != nullptr) {
214  provider_->beginStream(iID, *streamContext_);
215  }
216  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::shared_ptr< ProcessContext > processContext_
Definition: PileUp.h:145
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:147
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

◆ CalculatePileup()

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

Definition at line 390 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_, provider_, PU_Study_, randomEngine(), setRandomEngine(), and Study_type_.

394  {
395  // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
396  // crossing zero first, save it for later.
397 
398  int nzero_crossing = -1;
399  double Fnzero_crossing = -1;
400 
401  if (provider_) {
402  setRandomEngine(streamID);
403  }
404 
405  if (manage_OOT_) {
406  if (none_) {
407  nzero_crossing = 0;
408  } else if (poisson_) {
409  nzero_crossing = poissonDistribution(streamID)->fire();
410  } else if (fixed_) {
411  nzero_crossing = intAverage_;
413  // RANDOM_NUMBER_ERROR
414  // Random number should be generated by the engines from the
415  // RandomNumberGeneratorService. This appears to use the global
416  // engine in ROOT. This is not thread safe unless the module using
417  // it is a one module and declares a shared resource and all
418  // other modules using it also declare the same shared resource.
419  // This also breaks replay.
420  double d = GetRandom(histo_.get(), randomEngine(streamID));
421  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
422  Fnzero_crossing = d;
423  nzero_crossing = int(d);
424  }
425  }
426 
427  for (int bx = MinBunch; bx < MaxBunch + 1; ++bx) {
428  if (manage_OOT_) {
429  if (bx == 0 && !poisson_OOT_) {
430  PileupSelection.push_back(nzero_crossing);
431  TrueNumInteractions.push_back(nzero_crossing);
432  } else {
433  if (poisson_OOT_) {
434  if (PU_Study_ && (Study_type_ == "Fixed_ITPU_Vary_OOTPU") && bx == 0) {
435  PileupSelection.push_back(intFixed_ITPU_);
436  } else {
437  PileupSelection.push_back(poissonDistr_OOT(streamID)->fire(Fnzero_crossing));
438  }
439  TrueNumInteractions.push_back(Fnzero_crossing);
440  } else {
441  PileupSelection.push_back(intFixed_OOT_);
442  TrueNumInteractions.push_back(intFixed_OOT_);
443  }
444  }
445  } else {
446  if (none_) {
447  PileupSelection.push_back(0);
448  TrueNumInteractions.push_back(0.);
449  } else if (poisson_) {
450  PileupSelection.push_back(poissonDistribution(streamID)->fire());
451  TrueNumInteractions.push_back(averageNumber_);
452  } else if (fixed_) {
453  PileupSelection.push_back(intAverage_);
454  TrueNumInteractions.push_back(intAverage_);
456  // RANDOM_NUMBER_ERROR
457  // Random number should be generated by the engines from the
458  // RandomNumberGeneratorService. This appears to use the global
459  // engine in ROOT. This is not thread safe unless the module using
460  // it is a one module and declares a shared resource and all
461  // other modules using it also declare the same shared resource.
462  // This also breaks replay.
463  double d = GetRandom(histo_.get(), randomEngine(streamID));
464  PileupSelection.push_back(int(d));
465  TrueNumInteractions.push_back(d);
466  }
467  }
468  }
469  }
bool manage_OOT_
Definition: PileUp.h:127
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
static Double_t GetRandom(TH1 *th1, CLHEP::HepRandomEngine *rng)
Definition: PileUp.cc:51
bool fixed_
Definition: PileUp.h:125
std::unique_ptr< CLHEP::RandPoissonQ > const & poissonDistribution(StreamID const &streamID)
Definition: PileUp.cc:359
int const intAverage_
Definition: PileUp.h:120
std::shared_ptr< TH1F > histo_
Definition: PileUp.h:121
bool probFunctionDistribution_
Definition: PileUp.h:123
std::string Study_type_
Definition: PileUp.h:132
bool histoDistribution_
Definition: PileUp.h:122
bool poisson_
Definition: PileUp.h:124
bool poisson_OOT_
Definition: PileUp.h:128
int intFixed_ITPU_
Definition: PileUp.h:135
bool PU_Study_
Definition: PileUp.h:131
d
Definition: ztail.py:151
std::unique_ptr< CLHEP::RandPoisson > const & poissonDistr_OOT(StreamID const &streamID)
Definition: PileUp.cc:367
void setRandomEngine(StreamID)
Definition: PileUp.cc:383
bool none_
Definition: PileUp.h:126
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:375
int intFixed_OOT_
Definition: PileUp.h:134
double averageNumber_
Definition: PileUp.h:119

◆ doPileUp()

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

Definition at line 72 of file PileUp.h.

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

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

◆ dropUnwantedBranches()

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

Definition at line 79 of file PileUp.h.

References input_.

79  {
80  input_->dropUnwantedBranches(wantedBranches);
81  }
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:143

◆ endLuminosityBlock()

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

Definition at line 252 of file PileUp.cc.

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

252  {
253  if (provider_.get() != nullptr) {
255  provider_->endLuminosityBlock(*lumiPrincipal_, setup.impl(), lumi.moduleCallingContext(), *streamContext_);
256  }
257  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:148
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

◆ endRun()

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

Definition at line 246 of file PileUp.cc.

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

246  {
247  if (provider_.get() != nullptr) {
249  provider_->endRun(*runPrincipal_, setup.impl(), run.moduleCallingContext(), *streamContext_);
250  }
251  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::shared_ptr< RunPrincipal > runPrincipal_
Definition: PileUp.h:149
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

◆ endStream()

void edm::PileUp::endStream ( )

Definition at line 218 of file PileUp.cc.

References input_, provider_, serviceToken_, and streamContext_.

218  {
219  if (provider_.get() != nullptr) {
221  provider_->endStream(streamContext_->streamID(), *streamContext_);
222  provider_->endJob();
223  }
224  input_->doEndJob();
225  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:143
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

◆ input() [1/2]

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

Definition at line 106 of file PileUp.h.

References inputType_.

106 { return inputType_; }
unsigned int inputType_
Definition: PileUp.h:116

◆ input() [2/2]

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

Definition at line 107 of file PileUp.h.

References inputType_, and alignCSCRings::s.

107 { inputType_ = s; }
unsigned int inputType_
Definition: PileUp.h:116

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

References eventPrincipal_, fileNameHash_, and input_.

230  {
231  //TrueNumInteractions.push_back( end - begin ) ;
232  RecordEventID<T> recorder(ids, eventOperator);
233  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
234  }
size_t fileNameHash_
Definition: PileUp.h:141
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:143
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:147

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

References eventPrincipal_, fileNameHash_, and input_.

220  {
221  //TrueNumInteractions.push_back( end - begin ) ;
222  RecordEventID<T> recorder(ids, eventOperator);
223  input_->loopSpecified(*eventPrincipal_, fileNameHash_, begin, end, recorder);
224  }
size_t fileNameHash_
Definition: PileUp.h:141
std::unique_ptr< VectorInputSource > const input_
Definition: PileUp.h:143
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:147

◆ poisson()

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

Definition at line 71 of file PileUp.h.

References poisson_.

71 { return poisson_; }
bool poisson_
Definition: PileUp.h:124

◆ poissonDistr_OOT()

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

Definition at line 367 of file PileUp.cc.

References PoissonDistr_OOT_, and randomEngine().

Referenced by CalculatePileup().

367  {
368  if (!PoissonDistr_OOT_) {
369  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
370  PoissonDistr_OOT_ = std::make_unique<CLHEP::RandPoisson>(engine);
371  }
372  return PoissonDistr_OOT_;
373  }
std::unique_ptr< CLHEP::RandPoisson > PoissonDistr_OOT_
Definition: PileUp.h:154
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:375

◆ poissonDistribution()

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

Definition at line 359 of file PileUp.cc.

References averageNumber_, PoissonDistribution_, and randomEngine().

Referenced by CalculatePileup().

359  {
360  if (!PoissonDistribution_) {
361  CLHEP::HepRandomEngine& engine = *randomEngine(streamID);
362  PoissonDistribution_ = std::make_unique<CLHEP::RandPoissonQ>(engine, averageNumber_);
363  }
364  return PoissonDistribution_;
365  }
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:375
std::unique_ptr< CLHEP::RandPoissonQ > PoissonDistribution_
Definition: PileUp.h:153
double averageNumber_
Definition: PileUp.h:119

◆ randomEngine()

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

Definition at line 375 of file PileUp.cc.

References randomEngine_.

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

375  {
376  if (!randomEngine_) {
378  randomEngine_ = &rng->getEngine(streamID);
379  }
380  return randomEngine_;
381  }
CLHEP::HepRandomEngine * randomEngine_
Definition: PileUp.h:155

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

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

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

◆ reload()

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

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

269  {
270  //get the required parameters from DB.
271  const MixingInputConfig& config = setup.getData(configToken_).config(inputType_);
272 
273  //get the type
274  type_ = config.type();
275  //set booleans
276  histoDistribution_ = type_ == "histo";
277  probFunctionDistribution_ = type_ == "probFunction";
278  poisson_ = type_ == "poisson";
279  fixed_ = type_ == "fixed";
280  none_ = type_ == "none";
281 
282  if (histoDistribution_)
283  edm::LogError("MisConfiguration") << "type histo cannot be reloaded from DB, yet";
284 
285  if (fixed_) {
287  } else if (poisson_) {
288  averageNumber_ = config.averageNumber();
289  if (PoissonDistribution_) {
290  PoissonDistribution_ = std::make_unique<CLHEP::RandPoissonQ>(PoissonDistribution_->engine(), averageNumber_);
291  }
292  } else if (probFunctionDistribution_) {
293  //need to reload the histogram from DB
294  const std::vector<int>& dataProbFunctionVar = config.probFunctionVariable();
295  std::vector<double> dataProb = config.probValue();
296 
297  int varSize = (int)dataProbFunctionVar.size();
298  int probSize = (int)dataProb.size();
299 
300  if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
301  throw cms::Exception("BadProbFunction")
302  << "Please, check the variables of the probability function! The first variable should be 0 and the "
303  "difference between two variables should be 1."
304  << std::endl;
305 
306  // Complete the vector containing the probability function data
307  // with the values "0"
308  if (probSize < varSize) {
309  edm::LogWarning("MixingModule") << " The probability function data will be completed with "
310  << (varSize - probSize) << " values 0.";
311 
312  for (int i = 0; i < (varSize - probSize); i++)
313  dataProb.push_back(0);
314 
315  probSize = dataProb.size();
316  edm::LogInfo("MixingModule") << " The number of the P(x) data set after adding the values 0 is " << probSize;
317  }
318 
319  // Create an histogram with the data from the probability function provided by the user
320  int xmin = (int)dataProbFunctionVar[0];
321  int xmax = (int)dataProbFunctionVar[varSize - 1] + 1; // need upper edge to be one beyond last value
322  int numBins = varSize;
323 
324  edm::LogInfo("MixingModule") << "An histogram will be created with " << numBins << " bins in the range (" << xmin
325  << "," << xmax << ")." << std::endl;
326 
327  histo_.reset(new TH1F("h", "Histo from the user's probability function", numBins, xmin, xmax));
328 
329  LogDebug("MixingModule") << "Filling histogram with the following data:" << std::endl;
330 
331  for (int j = 0; j < numBins; j++) {
332  LogDebug("MixingModule") << " x = " << dataProbFunctionVar[j] << " P(x) = " << dataProb[j];
333  histo_->Fill(dataProbFunctionVar[j] + 0.5,
334  dataProb[j]); // assuming integer values for the bins, fill bin centers, not edges
335  }
336 
337  // Check if the histogram is normalized
338  if (std::abs(histo_->Integral() - 1) > 1.0e-02) {
339  throw cms::Exception("BadProbFunction") << "The probability function should be normalized!!! " << std::endl;
340  }
341  averageNumber_ = histo_->GetMean();
342  }
343 
344  int oot = config.outOfTime();
345  manage_OOT_ = false;
346  if (oot == 1) {
347  manage_OOT_ = true;
348  poisson_OOT_ = false;
349  fixed_OOT_ = true;
350  intFixed_OOT_ = config.fixedOutOfTime();
351  } else if (oot == 2) {
352  manage_OOT_ = true;
353  poisson_OOT_ = true;
354  fixed_OOT_ = false;
355  }
356  }
bool manage_OOT_
Definition: PileUp.h:127
double averageNumber() const
Definition: PileUp.h:70
unsigned int inputType_
Definition: PileUp.h:116
bool fixed_
Definition: PileUp.h:125
Definition: config.py:1
Log< level::Error, false > LogError
std::shared_ptr< TH1F > histo_
Definition: PileUp.h:121
bool probFunctionDistribution_
Definition: PileUp.h:123
bool histoDistribution_
Definition: PileUp.h:122
bool poisson_
Definition: PileUp.h:124
bool poisson_OOT_
Definition: PileUp.h:128
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool fixed_OOT_
Definition: PileUp.h:129
Log< level::Info, false > LogInfo
std::string type_
Definition: PileUp.h:117
bool none_
Definition: PileUp.h:126
std::unique_ptr< CLHEP::RandPoissonQ > PoissonDistribution_
Definition: PileUp.h:153
int intFixed_OOT_
Definition: PileUp.h:134
Log< level::Warning, false > LogWarning
double averageNumber_
Definition: PileUp.h:119
edm::ESGetToken< MixingModuleConfig, MixingRcd > configToken_
Definition: PileUp.h:140
#define LogDebug(id)

◆ setRandomEngine() [1/2]

void edm::PileUp::setRandomEngine ( StreamID  streamID)
private

Definition at line 383 of file PileUp.cc.

References randomEngine(), randomGenerator_, and PileupRandomNumberGenerator::setEngine().

Referenced by beginLuminosityBlock(), and CalculatePileup().

383 { randomGenerator_->setEngine(*randomEngine(streamID)); }
PileupRandomNumberGenerator * randomGenerator_
Definition: PileUp.h:150
void setEngine(CLHEP::HepRandomEngine const &)
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
Definition: PileUp.cc:375

◆ setRandomEngine() [2/2]

void edm::PileUp::setRandomEngine ( LuminosityBlock const &  iLumi)
private

Definition at line 384 of file PileUp.cc.

References edm::LuminosityBlock::index(), randomGenerator_, PileupRandomNumberGenerator::setEngine(), and PileupRandomNumberGenerator::setSeed().

384  {
386  randomGenerator_->setSeed(rng->mySeed());
387  randomGenerator_->setEngine(rng->getEngine(iLumi.index()));
388  }
PileupRandomNumberGenerator * randomGenerator_
Definition: PileUp.h:150
void setEngine(CLHEP::HepRandomEngine const &)

◆ setupPileUpEvent()

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

Definition at line 259 of file PileUp.cc.

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

259  {
260  if (provider_.get() != nullptr) {
261  // note: run and lumi numbers must be modified to match lumiPrincipal_
262  eventPrincipal_->setLuminosityBlockPrincipal(lumiPrincipal_.get());
263  eventPrincipal_->setRunAndLumiNumber(lumiPrincipal_->run(), lumiPrincipal_->luminosityBlock());
265  provider_->setupPileUpEvent(*eventPrincipal_, setup.impl(), *streamContext_);
266  }
267  }
std::unique_ptr< SecondaryEventProvider > provider_
Definition: PileUp.h:152
std::optional< ServiceToken > serviceToken_
Definition: PileUp.h:151
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: PileUp.h:148
std::unique_ptr< EventPrincipal > eventPrincipal_
Definition: PileUp.h:147
std::shared_ptr< StreamContext > streamContext_
Definition: PileUp.h:146

Member Data Documentation

◆ averageNumber_

double edm::PileUp::averageNumber_
private

Definition at line 119 of file PileUp.h.

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

◆ configToken_

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

Definition at line 140 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 141 of file PileUp.h.

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

◆ fixed_

bool edm::PileUp::fixed_
private

Definition at line 125 of file PileUp.h.

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

◆ fixed_OOT_

bool edm::PileUp::fixed_OOT_
private

Definition at line 129 of file PileUp.h.

Referenced by PileUp(), and reload().

◆ histo_

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

Definition at line 121 of file PileUp.h.

Referenced by CalculatePileup(), and reload().

◆ histoDistribution_

bool edm::PileUp::histoDistribution_
private

Definition at line 122 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 116 of file PileUp.h.

Referenced by input(), and reload().

◆ intAverage_

int const edm::PileUp::intAverage_
private

Definition at line 120 of file PileUp.h.

Referenced by CalculatePileup().

◆ intFixed_ITPU_

int edm::PileUp::intFixed_ITPU_
private

Definition at line 135 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

◆ intFixed_OOT_

int edm::PileUp::intFixed_OOT_
private

Definition at line 134 of file PileUp.h.

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

◆ lumiPrincipal_

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

Definition at line 148 of file PileUp.h.

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

◆ manage_OOT_

bool edm::PileUp::manage_OOT_
private

Definition at line 127 of file PileUp.h.

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

◆ maxBunch_cosmics_

int edm::PileUp::maxBunch_cosmics_
private

Definition at line 138 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

◆ minBunch_cosmics_

int edm::PileUp::minBunch_cosmics_
private

Definition at line 137 of file PileUp.h.

Referenced by doPileUp(), and PileUp().

◆ none_

bool edm::PileUp::none_
private

Definition at line 126 of file PileUp.h.

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

◆ playback_

bool edm::PileUp::playback_
private

Definition at line 162 of file PileUp.h.

◆ poisson_

bool edm::PileUp::poisson_
private

Definition at line 124 of file PileUp.h.

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

◆ poisson_OOT_

bool edm::PileUp::poisson_OOT_
private

Definition at line 128 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 154 of file PileUp.h.

Referenced by poissonDistr_OOT().

◆ PoissonDistribution_

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

Definition at line 153 of file PileUp.h.

Referenced by poissonDistribution(), and reload().

◆ probFunctionDistribution_

bool edm::PileUp::probFunctionDistribution_
private

Definition at line 123 of file PileUp.h.

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

◆ processConfiguration_

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

Definition at line 144 of file PileUp.h.

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

◆ processContext_

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

Definition at line 145 of file PileUp.h.

Referenced by beginStream(), and PileUp().

◆ productRegistry_

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

Definition at line 142 of file PileUp.h.

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

◆ provider_

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

◆ PU_Study_

bool edm::PileUp::PU_Study_
private

Definition at line 131 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

◆ randomEngine_

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

Definition at line 155 of file PileUp.h.

Referenced by randomEngine().

◆ randomGenerator_

PileupRandomNumberGenerator* edm::PileUp::randomGenerator_ = nullptr
private

Definition at line 150 of file PileUp.h.

Referenced by PileUp(), and setRandomEngine().

◆ runPrincipal_

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

Definition at line 149 of file PileUp.h.

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

◆ sequential_

bool edm::PileUp::sequential_
private

Definition at line 165 of file PileUp.h.

Referenced by readPileUp().

◆ serviceToken_

std::optional<ServiceToken> edm::PileUp::serviceToken_
private

◆ Source_type_

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

Definition at line 118 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 132 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

◆ type_

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