24 std::shared_ptr<edm::PileUp>
27 std::shared_ptr<edm::PileUp>
pileup;
36 TH1F *
h =
new TH1F(
"h",
"h",10,0,10);
37 std::vector<int> dataProbFunctionVar;
38 std::vector<double> dataProb;
45 edm::LogError(
"BMixingModule")<<
"Will read from DB: reset to a dummy PileUp object.";
46 pileup.reset(
new edm::PileUp(psin,sourceName,0,0,playback));
50 if (psin.
exists(
"nbPileupEvents")) {
52 if (psin_average.
exists(
"averageNumber"))
54 averageNumber=psin_average.
getParameter<
double>(
"averageNumber");
55 pileup.reset(
new edm::PileUp(psin,sourceName,averageNumber,h,playback));
58 else if (psin_average.
exists(
"fileName") && psin_average.
exists(
"histoName")) {
62 TFile *
infile =
new TFile(histoFileName.c_str());
63 TH1F *h = (TH1F*)infile->Get(histoName.c_str());
67 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram " << histoName
68 <<
"in the file " << histoFileName <<
"." << std::endl;
70 edm::LogInfo(
"MixingModule") <<
"Open a root file " << histoFileName <<
" containing the probability distribution histogram " << histoName << std::endl;
71 edm::LogInfo(
"MixingModule") <<
"The PileUp number to be added will be chosen randomly from this histogram" << std::endl;
75 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;
78 averageNumber = h->GetMean();
80 pileup.reset(
new edm::PileUp(psin,sourceName,averageNumber,h,playback));
84 else if (psin_average.
exists(
"probFunctionVariable") && psin_average.
exists(
"probValue") && psin_average.
exists(
"histoFileName"))
86 if (type_!=
"probFunction") {
87 edm::LogError(
"MisConfiguration")<<
"type is set to: "<<type_<<
" while parameters implies probFunction; changing.";
91 dataProbFunctionVar = psin_average.
getParameter<std::vector<int> >(
"probFunctionVariable");
92 dataProb = psin_average.
getParameter<std::vector<double> >(
"probValue");
95 int varSize = (int) dataProbFunctionVar.size();
96 int probSize = (int) dataProb.size();
98 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
99 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;
103 if (probSize < varSize){
104 edm::LogInfo(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
106 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
108 probSize = dataProb.size();
109 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
113 int xmin = (int) dataProbFunctionVar[0];
114 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
115 int numBins = varSize;
117 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
119 TH1F *hprob =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
121 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
123 for (
int j=0;
j < numBins ;
j++){
124 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
125 hprob->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
129 if ( ((hprob->Integral() - 1) > 1.0
e-02) && ((hprob->Integral() - 1) < -1.0
e-02)){
130 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
133 averageNumber = hprob->GetMean();
136 edm::LogInfo(
"MixingModule") <<
" The histogram created from the x, P(x) values will be written into the root file " <<
histoFileName;
138 TFile *
outfile =
new TFile(histoFileName.c_str(),
"RECREATE");
144 pileup.reset(
new edm::PileUp(psin,sourceName,averageNumber,hprob,playback));
149 else if (sourceName==
"input" && psin_average.
exists(
"Lumi") && psin_average.
exists(
"sigmaInel")) {
152 edm::PileUp(psin,sourceName,averageNumber,h,playback));
153 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb;
167 bunchSpace_(pset.getParameter<int>(
"bunchspace")),
169 minBunch_((pset.getParameter<int>(
"minBunch")*25)/pset.getParameter<int>(
"bunchspace")),
170 maxBunch_((pset.getParameter<int>(
"maxBunch")*25)/pset.getParameter<int>(
"bunchspace")),
171 mixProdStep1_(pset.getParameter<bool>(
"mixProdStep1")),
172 mixProdStep2_(pset.getParameter<bool>(
"mixProdStep2")),
181 LogInfo(
"MixingModule") <<
" ATTENTION:Mixing will be done in playback mode! \n"
182 <<
" ATTENTION:Mixing Configuration must be the same as for the original mixing!";
191 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++ ) {
230 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)
BMixingModule(const edm::ParameterSet &ps)
virtual void checkSignal(const edm::Event &e)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void put(edm::Event &e, const edm::EventSetup &c)
virtual void endRun(const edm::Run &r, const edm::EventSetup &setup) override
virtual void setBcrOffset()
virtual void createnewEDProduct()
virtual void setSourceOffset(const unsigned int s)
virtual void endJob() override
virtual void doPileUp(edm::Event &e, const edm::EventSetup &c)
virtual void initializeEvent(const edm::Event &event, const edm::EventSetup &setup)
tuple averageNumber
set the number of pileup
static const unsigned int maxNbSources_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
virtual void beginJob() override
virtual void reload(const edm::EventSetup &setup)
bool check(const edm::EventSetup &iSetup)
std::vector< std::shared_ptr< PileUp > > inputSources_
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
volatile std::atomic< bool > shutdown_flag false
std::vector< std::string > sourceNames_
virtual void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void update(edm::EventSetup const &)
void setupPileUpEvent(const edm::EventSetup &setup)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override