25 #include "CLHEP/Random/RandPoissonQ.h"
26 #include "CLHEP/Random/RandPoisson.h"
28 #include "boost/shared_ptr.hpp"
34 type_(pset.getParameter<std::
string>(
"type")),
35 averageNumber_(averageNumber),
36 intAverage_(static_cast<int>(averageNumber)),
38 histoDistribution_(type_ ==
"histo"),
39 probFunctionDistribution_(type_ ==
"probFunction"),
40 poisson_(type_ ==
"poisson"),
41 fixed_(type_ ==
"fixed"),
42 none_(type_ ==
"none"),
57 vPoissonDistribution_(),
61 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)),
62 samelumi_(pset.getUntrackedParameter<bool>(
"sameLumiBlock",
false)),
68 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
69 std::vector<ParameterSet> producers = pset.
getParameter<std::vector<ParameterSet> >(
"producers");
77 input_->branchIDListHelper(),
81 if (pset.
exists(
"nbPileupEvents")) {
90 <<
"PileUp requires the RandomNumberGeneratorService\n"
91 "which is not present in the configuration file. You must add the service\n"
92 "in the configuration file or remove the modules that require it.";
105 gRandom->SetSeed(
seed_);
106 LogInfo(
"MixingModule") <<
" Change seed for " <<
type_ <<
" mode. The seed is set to " <<
seed_;
109 gRandom->SetSeed(rng->
mySeed());
114 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
115 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
116 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
143 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
146 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
151 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
152 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
156 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
157 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
158 <<
"Legal values are 'poisson' or 'fixed'\n";
160 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
241 distribution.reset(
new CLHEP::RandPoissonQ(distribution->engine(),
averageNumber_));
249 std::vector<double> dataProb = config.
probValue();
251 int varSize = (int) dataProbFunctionVar.size();
252 int probSize = (int) dataProb.size();
254 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
255 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;
259 if (probSize < varSize){
260 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
262 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
264 probSize = dataProb.size();
265 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
269 int xmin = (int) dataProbFunctionVar[0];
270 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
271 int numBins = varSize;
273 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
276 histo_ =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
278 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
280 for (
int j=0;
j < numBins ;
j++){
281 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
282 histo_->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
286 if ( ((
histo_->Integral() - 1) > 1.0
e-02) && ((
histo_->Integral() - 1) < -1.0
e-02)){
287 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
322 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
337 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
338 ptr.reset(
new CLHEP::RandPoisson(engine));
353 ptr = &rng->getEngine(streamID);
364 int nzero_crossing = -1;
365 double Fnzero_crossing = -1;
382 double d =
histo_->GetRandom();
385 nzero_crossing = int(d);
390 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
394 PileupSelection.push_back(nzero_crossing) ;
395 TrueNumInteractions.push_back( nzero_crossing );
403 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
405 TrueNumInteractions.push_back( Fnzero_crossing );
415 PileupSelection.push_back(0);
416 TrueNumInteractions.push_back( 0. );
431 double d =
histo_->GetRandom();
432 PileupSelection.push_back(
int(d));
433 TrueNumInteractions.push_back( d );
boost::shared_ptr< RunPrincipal > runPrincipal_
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
bool exists(std::string const ¶meterName) const
checks if a parameter exists
ModuleCallingContext const * moduleCallingContext() const
PileUp(ParameterSet const &pset, double averageNumber, TH1F *const histo, const bool playback)
std::vector< CLHEP::HepRandomEngine * > randomEngines_
bool probFunctionDistribution_
boost::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
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
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
boost::shared_ptr< ProductRegistry > productRegistry_
void endRun(const edm::Run &run, const edm::EventSetup &setup)
RunAuxiliary const & runAuxiliary() const
boost::shared_ptr< ProcessConfiguration > processConfiguration_
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_
static ParameterSetID emptyParameterSetID()
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)