30 #include "CLHEP/Random/RandPoissonQ.h"
31 #include "CLHEP/Random/RandPoisson.h"
49 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];
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]);
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"),
81 ->makeVectorInputSource(
90 PoissonDistribution_(),
93 playback_(
config->playback_),
94 sequential_(
pset.getUntrackedParameter<
bool>(
"sequential",
false)) {
97 processContext_->setProcessConfiguration(processConfiguration_.get());
99 if (
pset.existsAs<std::vector<ParameterSet> >(
"producers",
true)) {
100 std::vector<ParameterSet>
producers =
pset.getParameter<std::vector<ParameterSet> >(
"producers");
104 productRegistry_->setFrozen();
107 eventPrincipal_.reset(
new EventPrincipal(input_->productRegistry(),
108 std::make_shared<BranchIDListHelper>(),
109 std::make_shared<ThinnedAssociationsHelper>(),
110 *processConfiguration_,
113 bool DB = type_ ==
"readDB";
115 if (
pset.exists(
"nbPileupEvents")) {
117 edm::LogWarning(
"MixingModule") <<
"Parameter nbPileupEvents.seed is not supported";
124 <<
"PileUp requires the RandomNumberGeneratorService\n"
125 "which is not present in the configuration file. You must add the service\n"
126 "in the configuration file or remove the modules that require it.";
129 if (!(histoDistribution_ || probFunctionDistribution_ || poisson_ || fixed_ || none_) && !
DB) {
130 throw cms::Exception(
"Illegal parameter value",
"PileUp::PileUp(ParameterSet const& pset)")
131 <<
"'type' parameter (a string) has a value of '" << type_ <<
"'.\n"
132 <<
"Legal values are 'poisson', 'fixed', or 'none'\n";
136 manage_OOT_ =
pset.getUntrackedParameter<
bool>(
"manage_OOT",
false);
140 Study_type_ =
pset.getUntrackedParameter<
std::string>(
"Special_Pileup_Studies",
"");
142 if (Study_type_ ==
"Fixed_ITPU_Vary_OOTPU") {
144 intFixed_ITPU_ =
pset.getUntrackedParameter<
int>(
"intFixed_ITPU", 0);
159 intFixed_OOT_ =
pset.getUntrackedParameter<
int>(
"intFixed_OOT", -1);
160 if (intFixed_OOT_ < 0) {
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";
170 <<
" distribution. ";
174 if (Source_type_ ==
"cosmics") {
175 minBunch_cosmics_ =
pset.getUntrackedParameter<
int>(
"minBunch_cosmics", -1000);
176 maxBunch_cosmics_ =
pset.getUntrackedParameter<
int>(
"maxBunch_cosmics", 1000);
201 auto aux = std::make_shared<RunAuxiliary>(
run.runAuxiliary());
252 edm::LogError(
"MisConfiguration") <<
"type histo cannot be reloaded from DB, yet";
263 const std::vector<int>& dataProbFunctionVar =
config.probFunctionVariable();
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)))
271 <<
"Please, check the variables of the probability function! The first variable should be 0 and the "
272 "difference between two variables should be 1."
277 if (probSize < varSize) {
278 edm::LogWarning(
"MixingModule") <<
" The probability function data will be completed with "
279 << (varSize - probSize) <<
" values 0.";
281 for (
int i = 0;
i < (varSize - probSize);
i++)
282 dataProb.push_back(0);
284 probSize = dataProb.size();
285 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
289 int xmin = (
int)dataProbFunctionVar[0];
290 int xmax = (
int)dataProbFunctionVar[varSize - 1] + 1;
291 int numBins = varSize;
293 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range (" <<
xmin
294 <<
"," <<
xmax <<
")." << std::endl;
296 histo_.reset(
new TH1F(
"h",
"Histo from the user's probability function", numBins,
xmin,
xmax));
298 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
300 for (
int j = 0;
j < numBins;
j++) {
301 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j] <<
" P(x) = " << dataProb[
j];
302 histo_->Fill(dataProbFunctionVar[
j] + 0.5,
308 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
313 int oot =
config.outOfTime();
320 }
else if (oot == 2) {
330 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
338 CLHEP::HepRandomEngine& engine = *
randomEngine(streamID);
354 std::vector<int>& PileupSelection,
355 std::vector<float>& TrueNumInteractions,
360 int nzero_crossing = -1;
361 double Fnzero_crossing = -1;
381 nzero_crossing =
int(
d);
385 for (
int bx = MinBunch;
bx < MaxBunch + 1; ++
bx) {
388 PileupSelection.push_back(nzero_crossing);
389 TrueNumInteractions.push_back(nzero_crossing);
395 PileupSelection.push_back(
poissonDistr_OOT(streamID)->fire(Fnzero_crossing));
397 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);