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"),
60 vPoissonDistribution_(),
64 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)),
65 samelumi_(pset.getUntrackedParameter<bool>(
"sameLumiBlock",
false)),
71 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
80 input_->branchIDListHelper(),
81 input_->thinnedAssociationsHelper(),
85 if (pset.
exists(
"nbPileupEvents")) {
94 <<
"PileUp requires the RandomNumberGeneratorService\n"
95 "which is not present in the configuration file. You must add the service\n"
96 "in the configuration file or remove the modules that require it.";
109 gRandom->SetSeed(
seed_);
110 LogInfo(
"MixingModule") <<
" Change seed for " <<
type_ <<
" mode. The seed is set to " <<
seed_;
113 gRandom->SetSeed(rng->
mySeed());
118 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
119 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
120 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
147 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
150 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
155 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
156 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
160 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
161 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
162 <<
"Legal values are 'poisson' or 'fixed'\n";
164 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
257 distribution.reset(
new CLHEP::RandPoissonQ(distribution->engine(),
averageNumber_));
265 std::vector<double> dataProb = config.
probValue();
267 int varSize = (int) dataProbFunctionVar.size();
268 int probSize = (int) dataProb.size();
270 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
271 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;
275 if (probSize < varSize){
276 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
278 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
280 probSize = dataProb.size();
281 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
285 int xmin = (int) dataProbFunctionVar[0];
286 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
287 int numBins = varSize;
289 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
292 histo_ =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
294 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
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]);
302 if ( ((
histo_->Integral() - 1) > 1.0
e-02) && ((
histo_->Integral() - 1) < -1.0
e-02)){
303 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
338 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
353 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
354 ptr.reset(
new CLHEP::RandPoisson(engine));
369 ptr = &rng->getEngine(streamID);
380 int nzero_crossing = -1;
381 double Fnzero_crossing = -1;
398 double d =
histo_->GetRandom();
401 nzero_crossing = int(d);
406 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
410 PileupSelection.push_back(nzero_crossing) ;
411 TrueNumInteractions.push_back( nzero_crossing );
419 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
421 TrueNumInteractions.push_back( Fnzero_crossing );
431 PileupSelection.push_back(0);
432 TrueNumInteractions.push_back( 0. );
447 double d =
histo_->GetRandom();
448 PileupSelection.push_back(
int(d));
449 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)