26 #include "CLHEP/Random/RandPoissonQ.h"
27 #include "CLHEP/Random/RandPoisson.h"
34 type_(pset.getParameter<std::
string>(
"type")),
35 Source_type_(sourcename),
36 averageNumber_(averageNumber),
37 intAverage_(static_cast<int>(averageNumber)),
39 histoDistribution_(type_ ==
"histo"),
40 probFunctionDistribution_(type_ ==
"probFunction"),
41 poisson_(type_ ==
"poisson"),
42 fixed_(type_ ==
"fixed"),
43 none_(type_ ==
"none"),
53 vPoissonDistribution_(),
57 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)),
63 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
72 std::make_shared<BranchIDListHelper>(),
73 std::make_shared<ThinnedAssociationsHelper>(),
77 if (pset.
exists(
"nbPileupEvents")) {
86 <<
"PileUp requires the RandomNumberGeneratorService\n"
87 "which is not present in the configuration file. You must add the service\n"
88 "in the configuration file or remove the modules that require it.";
101 gRandom->SetSeed(
seed_);
102 LogInfo(
"MixingModule") <<
" Change seed for " <<
type_ <<
" mode. The seed is set to " <<
seed_;
105 gRandom->SetSeed(rng->
mySeed());
110 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
111 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
112 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
139 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
142 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
147 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
148 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
152 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
153 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
154 <<
"Legal values are 'poisson' or 'fixed'\n";
156 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
249 distribution.reset(
new CLHEP::RandPoissonQ(distribution->engine(),
averageNumber_));
257 std::vector<double> dataProb = config.
probValue();
259 int varSize = (int) dataProbFunctionVar.size();
260 int probSize = (int) dataProb.size();
262 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
263 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;
267 if (probSize < varSize){
268 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
270 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
272 probSize = dataProb.size();
273 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
277 int xmin = (int) dataProbFunctionVar[0];
278 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
279 int numBins = varSize;
281 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
284 histo_ =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
286 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
288 for (
int j=0;
j < numBins ;
j++){
289 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
290 histo_->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
294 if ( ((
histo_->Integral() - 1) > 1.0
e-02) && ((
histo_->Integral() - 1) < -1.0
e-02)){
295 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
330 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
345 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
346 ptr.reset(
new CLHEP::RandPoisson(engine));
361 ptr = &rng->getEngine(streamID);
372 int nzero_crossing = -1;
373 double Fnzero_crossing = -1;
390 double d =
histo_->GetRandom();
393 nzero_crossing = int(d);
398 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
402 PileupSelection.push_back(nzero_crossing) ;
403 TrueNumInteractions.push_back( nzero_crossing );
411 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
413 TrueNumInteractions.push_back( Fnzero_crossing );
423 PileupSelection.push_back(0);
424 TrueNumInteractions.push_back( 0. );
439 double d =
histo_->GetRandom();
440 PileupSelection.push_back(
int(d));
441 TrueNumInteractions.push_back( d );
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< SecondaryEventProvider > provider_
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
std::shared_ptr< ProcessConfiguration > processConfiguration_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
PileUp(ParameterSet const &pset, std::string sourcename, double averageNumber, TH1F *const histo, const bool playback)
ModuleCallingContext const * moduleCallingContext() const
std::vector< CLHEP::HepRandomEngine * > randomEngines_
bool probFunctionDistribution_
void endLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
double averageNumber() const
virtual std::uint32_t mySeed() const =0
std::vector< std::unique_ptr< CLHEP::RandPoissonQ > > vPoissonDistribution_
std::unique_ptr< VectorInputSource > const input_
tuple averageNumber
set the number of pileup
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
std::unique_ptr< CLHEP::RandPoissonQ > const & poissonDistribution(StreamID const &streamID)
void CalculatePileup(int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions, StreamID const &)
void beginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
std::string getReleaseVersion()
void setupPileUpEvent(const edm::EventSetup &setup)
unsigned int value() const
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
void endRun(const edm::Run &run, const edm::EventSetup &setup)
RunAuxiliary const & runAuxiliary() const
std::shared_ptr< ProductRegistry > productRegistry_
std::unique_ptr< CLHEP::RandPoisson > const & poissonDistr_OOT(StreamID const &streamID)
void reload(const edm::EventSetup &setup)
ModuleCallingContext const * moduleCallingContext() const
CLHEP::HepRandomEngine * randomEngine(StreamID const &streamID)
std::vector< std::unique_ptr< CLHEP::RandPoisson > > vPoissonDistr_OOT_
volatile std::atomic< bool > shutdown_flag false
std::unique_ptr< EventPrincipal > eventPrincipal_
std::shared_ptr< RunPrincipal > runPrincipal_
static ParameterSetID emptyParameterSetID()
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)