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"),
59 vPoissonDistribution_(),
63 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)),
64 samelumi_(pset.getUntrackedParameter<bool>(
"sameLumiBlock",
false)),
70 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
71 std::vector<ParameterSet> producers = pset.
getParameter<std::vector<ParameterSet> >(
"producers");
79 input_->branchIDListHelper(),
80 input_->thinnedAssociationsHelper(),
84 if (pset.
exists(
"nbPileupEvents")) {
93 <<
"PileUp requires the RandomNumberGeneratorService\n"
94 "which is not present in the configuration file. You must add the service\n"
95 "in the configuration file or remove the modules that require it.";
108 gRandom->SetSeed(
seed_);
109 LogInfo(
"MixingModule") <<
" Change seed for " <<
type_ <<
" mode. The seed is set to " <<
seed_;
112 gRandom->SetSeed(rng->
mySeed());
117 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
118 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
119 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
146 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
149 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
154 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
155 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
159 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
160 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
161 <<
"Legal values are 'poisson' or 'fixed'\n";
163 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
256 distribution.reset(
new CLHEP::RandPoissonQ(distribution->engine(),
averageNumber_));
264 std::vector<double> dataProb = config.
probValue();
266 int varSize = (int) dataProbFunctionVar.size();
267 int probSize = (int) dataProb.size();
269 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
270 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;
274 if (probSize < varSize){
275 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
277 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
279 probSize = dataProb.size();
280 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
284 int xmin = (int) dataProbFunctionVar[0];
285 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
286 int numBins = varSize;
288 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
291 histo_ =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
293 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
295 for (
int j=0;
j < numBins ;
j++){
296 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
297 histo_->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
301 if ( ((
histo_->Integral() - 1) > 1.0
e-02) && ((
histo_->Integral() - 1) < -1.0
e-02)){
302 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
337 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
352 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
353 ptr.reset(
new CLHEP::RandPoisson(engine));
368 ptr = &rng->getEngine(streamID);
379 int nzero_crossing = -1;
380 double Fnzero_crossing = -1;
397 double d =
histo_->GetRandom();
400 nzero_crossing = int(d);
405 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
409 PileupSelection.push_back(nzero_crossing) ;
410 TrueNumInteractions.push_back( nzero_crossing );
418 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
420 TrueNumInteractions.push_back( Fnzero_crossing );
430 PileupSelection.push_back(0);
431 TrueNumInteractions.push_back( 0. );
446 double d =
histo_->GetRandom();
447 PileupSelection.push_back(
int(d));
448 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)