30 #include "CLHEP/Random/RandPoissonQ.h" 31 #include "CLHEP/Random/RandPoisson.h" 49 static Double_t
GetRandom(TH1* th1, CLHEP::HepRandomEngine* rng)
51 Int_t nbinsx = th1->GetNbinsX();
52 Double_t* fIntegral = th1->GetIntegral();
53 Double_t
integral = fIntegral[nbinsx];
55 if (integral == 0)
return 0;
57 Double_t
r1 = rng->flat();
58 Int_t ibin = TMath::BinarySearch(nbinsx,fIntegral,r1);
59 Double_t
x = th1->GetBinLowEdge(ibin+1);
60 if (r1 > fIntegral[ibin])
61 x += th1->GetBinWidth(ibin+1)*(r1-fIntegral[ibin])/(fIntegral[ibin+1] - fIntegral[ibin]);
68 type_(pset.getParameter<
std::
string>(
"type")),
69 Source_type_(config->sourcename_),
70 averageNumber_(config->averageNumber_),
71 intAverage_(static_cast<
int>(averageNumber_)),
72 histo_(
std::make_shared<TH1F>(*config->histo_)),
73 histoDistribution_(type_ ==
"histo"),
74 probFunctionDistribution_(type_ ==
"probFunction"),
75 poisson_(type_ ==
"poisson"),
76 fixed_(type_ ==
"fixed"),
77 none_(type_ ==
"none"),
88 PoissonDistribution_(),
91 playback_(config->playback_),
92 sequential_(pset.getUntrackedParameter<
bool>(
"sequential",
false)) {
98 if(pset.
existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
107 std::make_shared<BranchIDListHelper>(),
108 std::make_shared<ThinnedAssociationsHelper>(),
112 bool DB=
type_==
"readDB";
114 if (pset.
exists(
"nbPileupEvents")) {
116 edm::LogWarning(
"MixingModule") <<
"Parameter nbPileupEvents.seed is not supported";
123 <<
"PileUp requires the RandomNumberGeneratorService\n" 124 "which is not present in the configuration file. You must add the service\n" 125 "in the configuration file or remove the modules that require it.";
129 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
130 <<
"'type' parameter (a string) has a value of '" <<
type_ <<
"'.\n" 131 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
153 if(OOT_type ==
"Poisson" || OOT_type ==
"poisson") {
156 else if(OOT_type ==
"Fixed" || OOT_type ==
"fixed") {
161 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
162 <<
" Fixed out-of-time pileup requested, but no fixed value given ";
165 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
166 <<
"'OOT_type' parameter (a string) has a value of '" << OOT_type <<
"'.\n" 167 <<
"Legal values are 'poisson' or 'fixed'\n";
169 edm::LogInfo(
"MixingModule") <<
" Out-of-time pileup will be generated with a " << OOT_type <<
" distribution. " ;
266 std::vector<double> dataProb = config.
probValue();
268 int varSize = (
int) dataProbFunctionVar.size();
269 int probSize = (
int) dataProb.size();
271 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
272 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;
276 if (probSize < varSize){
277 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
279 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
281 probSize = dataProb.size();
282 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
286 int xmin = (
int) dataProbFunctionVar[0];
287 int xmax = (
int) dataProbFunctionVar[varSize-1]+1;
288 int numBins = varSize;
290 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
292 histo_.reset(
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax));
294 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
296 for (
int j=0; j < numBins ; j++){
297 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[j ]<<
" P(x) = " << dataProb[j];
298 histo_->Fill(dataProbFunctionVar[j]+0.5,dataProb[j]);
303 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
331 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
339 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
358 int nzero_crossing = -1;
359 double Fnzero_crossing = -1;
379 nzero_crossing =
int(d);
384 for(
int bx = MinBunch; bx < MaxBunch+1; ++bx) {
388 PileupSelection.push_back(nzero_crossing) ;
389 TrueNumInteractions.push_back( nzero_crossing );
397 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing)) ;
399 TrueNumInteractions.push_back( Fnzero_crossing );
409 PileupSelection.push_back(0);
410 TrueNumInteractions.push_back( 0. );
426 PileupSelection.push_back(
int(d));
427 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)
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const override
double averageNumber() const
std::unique_ptr< VectorInputSource > const input_
Abs< T >::type abs(const T &t)
RunAuxiliary const & runAuxiliary() const override
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_
edm::EventSetupImpl const & impl() const
T const & get(Event const &event, InputTag const &tag)(false)
void endRun(const edm::Run &run, const edm::EventSetup &setup)
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_