24 std::shared_ptr<edm::PileUpConfig>
27 std::shared_ptr<edm::PileUpConfig> pileupconfig;
36 std::unique_ptr<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 std::unique_ptr<TH1F>
h;
51 if (psin.
exists(
"nbPileupEvents")) {
53 if (psin_average.
exists(
"averageNumber"))
55 averageNumber=psin_average.
getParameter<
double>(
"averageNumber");
59 else if (psin_average.
exists(
"fileName") && psin_average.
exists(
"histoName")) {
63 std::unique_ptr<TFile>
infile(
new TFile(histoFileName.c_str()));
64 std::unique_ptr<TH1F>
h((TH1F*)
infile->Get(histoName.c_str()));
68 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram " << histoName
69 <<
"in the file " << histoFileName <<
"." << std::endl;
71 edm::LogInfo(
"MixingModule") <<
"Open a root file " << histoFileName <<
" containing the probability distribution histogram " << histoName << std::endl;
72 edm::LogInfo(
"MixingModule") <<
"The PileUp number to be added will be chosen randomly from this histogram" << std::endl;
76 if (
std::abs(h->Integral() - 1) > 1.0
e-02)
throw cms::Exception(
"BadHistoDistribution") <<
"The histogram should be normalized!" << std::endl;
79 averageNumber = h->GetMean();
85 else if (psin_average.
exists(
"probFunctionVariable") && psin_average.
exists(
"probValue") && psin_average.
exists(
"histoFileName"))
87 if (type_!=
"probFunction") {
88 edm::LogError(
"MisConfiguration")<<
"type is set to: "<<type_<<
" while parameters implies probFunction; changing.";
92 dataProbFunctionVar = psin_average.
getParameter<std::vector<int> >(
"probFunctionVariable");
93 dataProb = psin_average.
getParameter<std::vector<double> >(
"probValue");
96 int varSize = (int) dataProbFunctionVar.size();
97 int probSize = (int) dataProb.size();
99 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
100 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;
104 if (probSize < varSize){
105 edm::LogInfo(
"MixingModule") <<
" The probability function data will be completed with " <<(varSize - probSize) <<
" values 0.";
107 for (
int i=0;
i<(varSize - probSize);
i++) dataProb.push_back(0);
109 probSize = dataProb.size();
110 edm::LogInfo(
"MixingModule") <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
114 int xmin = (int) dataProbFunctionVar[0];
115 int xmax = (int) dataProbFunctionVar[varSize-1]+1;
116 int numBins = varSize;
118 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
120 std::unique_ptr<TH1F> hprob(
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax));
122 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
124 for (
int j=0;
j < numBins ;
j++){
125 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j ]<<
" P(x) = " << dataProb[
j];
126 hprob->Fill(dataProbFunctionVar[
j]+0.5,dataProb[
j]);
130 if (
std::abs(hprob->Integral() - 1) > 1.0
e-02){
131 throw cms::Exception(
"BadProbFunction") <<
"The probability function should be normalized!!! " << std::endl;
134 averageNumber = hprob->GetMean();
137 edm::LogInfo(
"MixingModule") <<
" The histogram created from the x, P(x) values will be written into the root file " <<
histoFileName;
139 TFile *
outfile =
new TFile(histoFileName.c_str(),
"RECREATE");
145 pileupconfig.reset(
new edm::PileUpConfig(sourceName,averageNumber,hprob,playback));
149 else if (sourceName==
"input" && psin_average.
exists(
"Lumi") && psin_average.
exists(
"sigmaInel")) {
152 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb;
166 bunchSpace_(globalConf->bunchSpace_),
168 minBunch_(globalConf->minBunch_),
169 maxBunch_(globalConf->maxBunch_),
170 mixProdStep1_(pset.getParameter<bool>(
"mixProdStep1")),
171 mixProdStep2_(pset.getParameter<bool>(
"mixProdStep2")),
173 playback_(globalConf->playback_)
177 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++ ) {
192 namespace MixingCache {
194 bunchSpace_(pset.getParameter<int>(
"bunchspace")),
195 minBunch_((pset.getParameter<int>(
"minBunch")*25)/bunchSpace_),
196 maxBunch_((pset.getParameter<int>(
"maxBunch")*25)/bunchSpace_),
197 playback_(pset.getUntrackedParameter<bool>(
"playback",
false))
201 LogInfo(
"MixingModule") <<
" ATTENTION:Mixing will be done in playback mode! \n"
202 <<
" ATTENTION:Mixing Configuration must be the same as for the original mixing!";
211 for (
size_t makeIdx = 0; makeIdx < maxNbSources; makeIdx++ ) {
251 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++ ) {
308 edm::LogWarning(
"MixingModule") <<
"BMixingModule::createnewEDProduct must be overwritten!";
312 edm::LogWarning(
"MixingModule") <<
"BMixingModule::checkSignal must be overwritten!";
316 edm::LogWarning(
"MixingModule") <<
"BMixingModule::setBcrOffset must be overwritten!";
320 edm::LogWarning(
"MixingModule") <<
"BMixingModule::setSourceOffset must be overwritten!";
324 edm::LogWarning(
"MixingModule") <<
"BMixingModule::doPileUp must be overwritten!";
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
static std::unique_ptr< MixingCache::Config > initializeGlobalCache(edm::ParameterSet const &)
virtual void addSignals(const edm::Event &e, const edm::EventSetup &c)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual void produce(edm::Event &e1, const edm::EventSetup &c) override
virtual void finalizeEvent(edm::Event &event, const edm::EventSetup &setup)
std::vector< std::string > sourceNames_
virtual void checkSignal(const edm::Event &e)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void endStream() override
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 doPileUp(edm::Event &e, const edm::EventSetup &c)
virtual void initializeEvent(const edm::Event &event, const edm::EventSetup &setup)
Config(edm::ParameterSet const &pset, unsigned int maxNbSources)
virtual void beginStream(edm::StreamID) override
tuple averageNumber
set the number of pileup
Abs< T >::type abs(const T &t)
static const unsigned int maxNbSources_
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
virtual void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void update(edm::EventSetup const &)
std::vector< std::shared_ptr< PileUpConfig > > inputConfigs_
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
BMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)