29 #include "CLHEP/Random/RandPoissonQ.h" 30 #include "CLHEP/Random/RandPoisson.h" 48 static Double_t
GetRandom(TH1* th1, CLHEP::HepRandomEngine* rng)
50 Int_t nbinsx = th1->GetNbinsX();
51 Double_t* fIntegral = th1->GetIntegral();
52 Double_t
integral = fIntegral[nbinsx];
54 if (integral == 0)
return 0;
56 Double_t
r1 = rng->flat();
57 Int_t ibin = TMath::BinarySearch(nbinsx,fIntegral,r1);
58 Double_t
x = th1->GetBinLowEdge(ibin+1);
59 if (r1 > fIntegral[ibin])
60 x += th1->GetBinWidth(ibin+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
67 type_(pset.getParameter<
std::
string>(
"type")),
68 Source_type_(config->sourcename_),
69 averageNumber_(config->averageNumber_),
70 intAverage_(static_cast<
int>(averageNumber_)),
71 histo_(config->histo_),
72 histoDistribution_(type_ ==
"histo"),
73 probFunctionDistribution_(type_ ==
"probFunction"),
74 poisson_(type_ ==
"poisson"),
75 fixed_(type_ ==
"fixed"),
76 none_(type_ ==
"none"),
87 PoissonDistribution_(),
90 playback_(config->playback_),
91 sequential_(pset.getUntrackedParameter<bool>(
"sequential",
false)) {
97 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
106 std::make_shared<BranchIDListHelper>(),
107 std::make_shared<ThinnedAssociationsHelper>(),
111 bool DB=
type_==
"readDB";
113 if (pset.
exists(
"nbPileupEvents")) {
115 edm::LogWarning(
"MixingModule") <<
"Parameter nbPileupEvents.seed is not supported";
122 <<
"PileUp requires the RandomNumberGeneratorService\n" 123 "which is not present in the configuration file. You must add the service\n" 124 "in the configuration file or remove the modules that require it.";
128 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
129 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n" 130 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
152 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
155 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
160 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
161 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
164 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
165 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n" 166 <<
"Legal values are 'poisson' or 'fixed'\n";
168 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
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;
290 histo_.reset(
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax));
292 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
294 for (
int j=0; j < numBins ; j++){
295 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[j ]<<
" P(x) = " << dataProb[j];
296 histo_->Fill(dataProbFunctionVar[j]+0.5,dataProb[j]);
301 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
329 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
337 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
356 int nzero_crossing = -1;
357 double Fnzero_crossing = -1;
377 nzero_crossing =
int(d);
382 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
386 PileupSelection.push_back(nzero_crossing) ;
387 TrueNumInteractions.push_back( nzero_crossing );
395 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
397 TrueNumInteractions.push_back( Fnzero_crossing );
407 PileupSelection.push_back(0);
408 TrueNumInteractions.push_back( 0. );
424 PileupSelection.push_back(
int(d));
425 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
OOT_type
manage out-of-time pileup setting this to True means that the out-of-time pileup will have a differen...
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)
def setup(process, global_tag, zero_tesla=False)
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_
PileUp(ParameterSet const &pset, const std::shared_ptr< PileUpConfig > &config)
std::unique_ptr< EventPrincipal > eventPrincipal_
std::shared_ptr< RunPrincipal > runPrincipal_
static ParameterSetID emptyParameterSetID()
const MixingInputConfig & config(unsigned int i=0) const
std::shared_ptr< StreamContext > streamContext_
T get(const Candidate &c)