23 #include "boost/shared_ptr.hpp"
29 type_(pset.getParameter<std::
string>(
"type")),
30 averageNumber_(averageNumber),
31 intAverage_(static_cast<int>(averageNumber)),
33 histoDistribution_(type_ ==
"histo"),
34 probFunctionDistribution_(type_ ==
"probFunction"),
35 poisson_(type_ ==
"poisson"),
36 fixed_(type_ ==
"fixed"),
37 none_(type_ ==
"none"),
48 poissonDistribution_(),
51 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)),
52 samelumi_(pset.getUntrackedParameter<bool>(
"sameLumiBlock",
false)),
60 input_->productRegistry()->setFrozen();
64 input_->branchIDListHelper(),
68 if (pset.
exists(
"nbPileupEvents")) {
72 bool DB=
type_==
"readDB";
77 <<
"PileUp requires the RandomNumberGeneratorService\n"
78 "which is not present in the configuration file. You must add the service\n"
79 "in the configuration file or remove the modules that require it.";
82 CLHEP::HepRandomEngine& engine = rng->
getEngine();
88 gRandom->SetSeed(
seed_);
89 LogInfo(
"MixingModule") <<
" Change seed for " <<
type_ <<
" mode. The seed is set to " <<
seed_;
92 gRandom->SetSeed(engine.getSeed());
98 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
99 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
100 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
127 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
131 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
136 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
137 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
141 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
142 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
143 <<
"Legal values are 'poisson' or 'fixed'\n";
145 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
176 CLHEP::HepRandomEngine& engine = rng->
getEngine();
183 std::vector<double> dataProb = config.
probValue();
185 int varSize = (int) dataProbFunctionVar.size();
186 int probSize = (int) dataProb.size();
188 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
189 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;
193 if (probSize < varSize){
194 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
196 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
198 probSize = dataProb.size();
199 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
203 int xmin = (int) dataProbFunctionVar[0];
204 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
205 int numBins = varSize;
207 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
210 histo_ =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
212 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
214 for (
int j=0;
j < numBins ;
j++){
215 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
216 histo_->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
220 if ( ((
histo_->Integral() - 1) > 1.0
e-02) && ((
histo_->Integral() - 1) < -1.0
e-02)){
221 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
244 CLHEP::HepRandomEngine& engine = rng->
getEngine();
254 void PileUp::CalculatePileup(
int MinBunch,
int MaxBunch, std::vector<int>& PileupSelection, std::vector<float>& TrueNumInteractions) {
259 int nzero_crossing = -1;
260 double Fnzero_crossing = -1;
270 double d =
histo_->GetRandom();
273 nzero_crossing = int(d);
278 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
282 PileupSelection.push_back(nzero_crossing) ;
283 TrueNumInteractions.push_back( nzero_crossing );
293 TrueNumInteractions.push_back( Fnzero_crossing );
303 PileupSelection.push_back(0);
304 TrueNumInteractions.push_back( 0. );
312 double d =
histo_->GetRandom();
313 PileupSelection.push_back(
int(d));
314 TrueNumInteractions.push_back( d );
void CalculatePileup(int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< CLHEP::RandPoisson > poissonDistr_OOT_
ParameterSetID id() const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
PileUp(ParameterSet const &pset, double averageNumber, TH1F *const histo, const bool playback)
bool probFunctionDistribution_
std::unique_ptr< ProcessConfiguration > processConfiguration_
double averageNumber() const
std::unique_ptr< VectorInputSource > const input_
tuple averageNumber
set the number of pileup
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
std::string getReleaseVersion()
void reload(const edm::EventSetup &setup)
std::unique_ptr< CLHEP::RandPoissonQ > poissonDistribution_
std::unique_ptr< EventPrincipal > eventPrincipal_
ParameterSet const & registerIt()
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)