24 #include "boost/shared_ptr.hpp"
30 type_(pset.getParameter<std::
string>(
"type")),
31 averageNumber_(averageNumber),
32 intAverage_(static_cast<int>(averageNumber)),
34 histoDistribution_(type_ ==
"histo"),
35 probFunctionDistribution_(type_ ==
"probFunction"),
36 poisson_(type_ ==
"poisson"),
37 fixed_(type_ ==
"fixed"),
38 none_(type_ ==
"none"),
53 poissonDistribution_(),
56 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)),
57 samelumi_(pset.getUntrackedParameter<bool>(
"sameLumiBlock",
false)),
63 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
64 std::vector<ParameterSet> producers = pset.
getParameter<std::vector<ParameterSet> >(
"producers");
72 input_->branchIDListHelper(),
76 if (pset.
exists(
"nbPileupEvents")) {
80 bool DB=
type_==
"readDB";
85 <<
"PileUp requires the RandomNumberGeneratorService\n"
86 "which is not present in the configuration file. You must add the service\n"
87 "in the configuration file or remove the modules that require it.";
90 CLHEP::HepRandomEngine& engine = rng->
getEngine();
96 gRandom->SetSeed(
seed_);
97 LogInfo(
"MixingModule") <<
" Change seed for " <<
type_ <<
" mode. The seed is set to " <<
seed_;
100 gRandom->SetSeed(engine.getSeed());
106 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
107 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
108 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
135 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
139 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
144 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
145 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
149 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
150 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
151 <<
"Legal values are 'poisson' or 'fixed'\n";
153 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
233 CLHEP::HepRandomEngine& engine = rng->
getEngine();
240 std::vector<double> dataProb = config.
probValue();
242 int varSize = (int) dataProbFunctionVar.size();
243 int probSize = (int) dataProb.size();
245 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
246 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;
250 if (probSize < varSize){
251 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
253 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
255 probSize = dataProb.size();
256 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
260 int xmin = (int) dataProbFunctionVar[0];
261 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
262 int numBins = varSize;
264 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
267 histo_ =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
269 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
271 for (
int j=0;
j < numBins ;
j++){
272 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
273 histo_->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
277 if ( ((
histo_->Integral() - 1) > 1.0
e-02) && ((
histo_->Integral() - 1) < -1.0
e-02)){
278 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
301 CLHEP::HepRandomEngine& engine = rng->
getEngine();
311 void PileUp::CalculatePileup(
int MinBunch,
int MaxBunch, std::vector<int>& PileupSelection, std::vector<float>& TrueNumInteractions) {
316 int nzero_crossing = -1;
317 double Fnzero_crossing = -1;
327 double d =
histo_->GetRandom();
330 nzero_crossing = int(d);
335 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
339 PileupSelection.push_back(nzero_crossing) ;
340 TrueNumInteractions.push_back( nzero_crossing );
350 TrueNumInteractions.push_back( Fnzero_crossing );
360 PileupSelection.push_back(0);
361 TrueNumInteractions.push_back( 0. );
369 double d =
histo_->GetRandom();
370 PileupSelection.push_back(
int(d));
371 TrueNumInteractions.push_back( d );
void CalculatePileup(int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions)
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
std::unique_ptr< CLHEP::RandPoisson > poissonDistr_OOT_
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)
bool probFunctionDistribution_
boost::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
void endLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
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...
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
void beginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
std::string getReleaseVersion()
void setupPileUpEvent(const edm::EventSetup &setup)
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_
void reload(const edm::EventSetup &setup)
std::unique_ptr< CLHEP::RandPoissonQ > poissonDistribution_
ModuleCallingContext const * moduleCallingContext() const
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)