27 #include "CLHEP/Random/RandPoissonQ.h"
28 #include "CLHEP/Random/RandPoisson.h"
46 static Double_t
GetRandom(TH1* th1, CLHEP::HepRandomEngine* rng)
48 Int_t nbinsx = th1->GetNbinsX();
49 Double_t* fIntegral = th1->GetIntegral();
50 Double_t
integral = fIntegral[nbinsx];
52 if (integral == 0)
return 0;
54 Double_t
r1 = rng->flat();
55 Int_t ibin = TMath::BinarySearch(nbinsx,fIntegral,r1);
56 Double_t
x = th1->GetBinLowEdge(ibin+1);
57 if (r1 > fIntegral[ibin])
58 x += th1->GetBinWidth(ibin+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
65 type_(pset.getParameter<std::
string>(
"type")),
66 Source_type_(config->sourcename_),
67 averageNumber_(config->averageNumber_),
68 intAverage_(static_cast<int>(averageNumber_)),
69 histo_(config->histo_),
70 histoDistribution_(type_ ==
"histo"),
71 probFunctionDistribution_(type_ ==
"probFunction"),
72 poisson_(type_ ==
"poisson"),
73 fixed_(type_ ==
"fixed"),
74 none_(type_ ==
"none"),
85 PoissonDistribution_(),
88 playback_(config->playback_),
89 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)) {
95 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
104 std::make_shared<BranchIDListHelper>(),
105 std::make_shared<ThinnedAssociationsHelper>(),
111 if (pset.
exists(
"nbPileupEvents")) {
113 edm::LogWarning(
"MixingModule") <<
"Parameter nbPileupEvents.seed is not supported";
120 <<
"PileUp requires the RandomNumberGeneratorService\n"
121 "which is not present in the configuration file. You must add the service\n"
122 "in the configuration file or remove the modules that require it.";
126 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
127 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n"
128 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
150 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
153 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
158 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
159 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
162 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
163 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n"
164 <<
"Legal values are 'poisson' or 'fixed'\n";
166 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
262 std::vector<double> dataProb = config.
probValue();
264 int varSize = (int) dataProbFunctionVar.size();
265 int probSize = (int) dataProb.size();
267 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
268 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;
272 if (probSize < varSize){
273 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
275 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
277 probSize = dataProb.size();
278 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
282 int xmin = (int) dataProbFunctionVar[0];
283 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
284 int numBins = varSize;
286 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
288 histo_.reset(
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax));
290 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
292 for (
int j=0;
j < numBins ;
j++){
293 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
294 histo_->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
299 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
327 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
335 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
354 int nzero_crossing = -1;
355 double Fnzero_crossing = -1;
375 nzero_crossing = int(d);
380 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
384 PileupSelection.push_back(nzero_crossing) ;
385 TrueNumInteractions.push_back( nzero_crossing );
393 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
395 TrueNumInteractions.push_back( Fnzero_crossing );
405 PileupSelection.push_back(0);
406 TrueNumInteractions.push_back( 0. );
422 PileupSelection.push_back(
int(d));
423 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
static Double_t GetRandom(TH1 *th1, CLHEP::HepRandomEngine *rng)
void beginStream(edm::StreamID)
ModuleCallingContext const * moduleCallingContext() const
std::shared_ptr< TH1F > histo_
bool probFunctionDistribution_
void endLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &setup)
T x() const
Cartesian x coordinate.
double averageNumber() const
std::unique_ptr< VectorInputSource > const input_
Abs< T >::type abs(const T &t)
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)
Integral< F, X >::type integral(const F &f)
std::unique_ptr< CLHEP::RandPoisson > PoissonDistr_OOT_
std::string getReleaseVersion()
CLHEP::HepRandomEngine * randomEngine_
void setupPileUpEvent(const edm::EventSetup &setup)
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::unique_ptr< CLHEP::RandPoissonQ > PoissonDistribution_
std::shared_ptr< ProcessContext > processContext_
volatile std::atomic< bool > shutdown_flag false
PileUp(ParameterSet const &pset, const std::shared_ptr< PileUpConfig > &config)
std::unique_ptr< EventPrincipal > eventPrincipal_
std::shared_ptr< RunPrincipal > runPrincipal_
static ParameterSetID emptyParameterSetID()
std::shared_ptr< StreamContext > streamContext_
T get(const Candidate &c)