27 boost::shared_ptr<edm::PileUp>
30 boost::shared_ptr<edm::PileUp>
pileup;
39 TH1F *
h =
new TH1F(
"h",
"h",10,0,10);
40 vector<int> dataProbFunctionVar;
41 vector<double> dataProb;
48 edm::LogError(
"BMixingModule")<<
"Will read from DB: reset to a dummy PileUp object.";
53 if (psin.
exists(
"nbPileupEvents")) {
55 if (psin_average.
exists(
"averageNumber"))
57 averageNumber=psin_average.
getParameter<
double>(
"averageNumber");
58 pileup.reset(
new edm::PileUp(psin,averageNumber,h,playback));
61 else if (psin_average.
exists(
"fileName") && psin_average.
exists(
"histoName")) {
65 TFile *
infile =
new TFile(histoFileName.c_str());
66 TH1F *h = (TH1F*)infile->Get(histoName.c_str());
70 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram " << histoName
71 <<
"in the file " << histoFileName <<
"." << std::endl;
73 edm::LogInfo(
"MixingModule") <<
"Open a root file " << histoFileName <<
" containing the probability distribution histogram " << histoName << std::endl;
74 edm::LogInfo(
"MixingModule") <<
"The PileUp number to be added will be chosen randomly from this histogram" << std::endl;
78 if (((h->Integral() - 1) > 1.0
e-02) && ((h->Integral() - 1) < -1.0
e-02))
throw cms::Exception(
"BadHistoDistribution") <<
"The histogram should be normalized!" << std::endl;
81 averageNumber = h->GetMean();
83 pileup.reset(
new edm::PileUp(psin,averageNumber,h,playback));
87 else if (psin_average.
exists(
"probFunctionVariable") && psin_average.
exists(
"probValue") && psin_average.
exists(
"histoFileName"))
89 if (type_!=
"probFunction") {
90 edm::LogError(
"MisConfiguration")<<
"type is set to: "<<type_<<
" while parameters implies probFunction; changing.";
94 dataProbFunctionVar = psin_average.
getParameter<vector<int> >(
"probFunctionVariable");
95 dataProb = psin_average.
getParameter<vector<double> >(
"probValue");
98 int varSize = (int) dataProbFunctionVar.size();
99 int probSize = (int) dataProb.size();
101 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
102 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." << endl;
106 if (probSize < varSize){
107 edm::LogInfo(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
109 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
111 probSize = dataProb.size();
112 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
116 int xmin = (int) dataProbFunctionVar[0];
117 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
118 int numBins = varSize;
120 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
122 TH1F *hprob =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
124 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
126 for (
int j=0;
j < numBins ;
j++){
127 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
128 hprob->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
132 if ( ((hprob->Integral() - 1) > 1.0
e-02) && ((hprob->Integral() - 1) < -1.0
e-02)){
133 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << endl;
136 averageNumber = hprob->GetMean();
139 edm::LogInfo(
"MixingModule") <<
" The histogram created from the x, P(x) values will be written into the root file " <<
histoFileName;
141 TFile *
outfile =
new TFile(histoFileName.c_str(),
"RECREATE");
147 pileup.reset(
new edm::PileUp(psin,averageNumber,hprob,playback));
152 else if (sourceName==
"input" && psin_average.
exists(
"Lumi") && psin_average.
exists(
"sigmaInel")) {
156 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb;
170 bunchSpace_(pset.getParameter<int>(
"bunchspace")),
171 minBunch_((pset.getParameter<int>(
"minBunch")*25)/pset.getParameter<int>(
"bunchspace")),
172 maxBunch_((pset.getParameter<int>(
"maxBunch")*25)/pset.getParameter<int>(
"bunchspace")),
173 mixProdStep1_(pset.getParameter<bool>(
"mixProdStep1")),
174 mixProdStep2_(pset.getParameter<bool>(
"mixProdStep2")),
183 LogInfo(
"MixingModule") <<
" ATTENTION:Mixing will be done in playback mode! \n"
184 <<
" ATTENTION:Mixing Configuration must be the same as for the original mixing!";
193 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++ ) {
214 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++ ) {
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::ESWatcher< MixingRcd > parameterWatcher_
virtual void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
virtual void addSignals(const edm::Event &e, const edm::EventSetup &c)
virtual void produce(edm::Event &e1, const edm::EventSetup &c) override
virtual void finalizeEvent(edm::Event &event, const edm::EventSetup &setup)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void put(edm::Event &e, const edm::EventSetup &c)
virtual void checkSignal(const edm::Event &e)
virtual void initializeEvent(const edm::Event &event, const edm::EventSetup &setup)
tuple averageNumber
set the number of pileup
static const unsigned int maxNbSources_
virtual void reload(const edm::EventSetup &setup)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
bool check(const edm::EventSetup &iSetup)
std::vector< boost::shared_ptr< PileUp > > inputSources_
virtual void doPileUp(edm::Event &e, const edm::EventSetup &c)
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
std::vector< std::string > sourceNames_
virtual void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void update(edm::EventSetup const &)
virtual void createnewEDProduct()
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")