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++ ) {
191 namespace MixingCache {
200 LogInfo(
"MixingModule") <<
" ATTENTION:Mixing will be done in playback mode! \n" 201 <<
" ATTENTION:Mixing Configuration must be the same as for the original mixing!";
210 for (
size_t makeIdx = 0; makeIdx < maxNbSources; makeIdx++ ) {
224 for (
size_t endIdx=0; endIdx<maxNbSources_; ++endIdx) {
225 if(inputSources_[endIdx]) inputSources_[endIdx]->beginLuminosityBlock(lumi, setup);
231 for (
size_t endIdx=0; endIdx<maxNbSources_; ++endIdx) {
232 if(inputSources_[endIdx]) inputSources_[endIdx]->beginRun(run, setup);
237 for (
size_t endIdx=0; endIdx<maxNbSources_; ++endIdx) {
238 if(inputSources_[endIdx]) inputSources_[endIdx]->endLuminosityBlock(lumi, setup);
243 for (
size_t endIdx=0; endIdx<maxNbSources_; ++endIdx) {
244 if(inputSources_[endIdx]) inputSources_[endIdx]->endRun(run, setup);
249 if (readDB_ && parameterWatcher_.check(setup)){
250 for (
size_t makeIdx = 0; makeIdx < maxNbSources_; makeIdx++ ) {
251 if (inputSources_[makeIdx]) inputSources_[makeIdx]->reload(setup);
264 createnewEDProduct();
266 initializeEvent(e, setup);
276 finalizeEvent(e, setup);
283 for (
size_t dropIdx=0; dropIdx<maxNbSources_; ++dropIdx) {
284 if(inputSources_[dropIdx]) inputSources_[dropIdx]->setupPileUpEvent(setup);
289 for (
size_t dropIdx=0; dropIdx<maxNbSources_; ++dropIdx) {
290 if(inputSources_[dropIdx]) inputSources_[dropIdx]->dropUnwantedBranches(wantedBranches);
295 for (
size_t endIdx=0; endIdx<maxNbSources_; ++endIdx) {
296 if(inputSources_[endIdx]) inputSources_[endIdx]->beginStream(iID);
301 for (
size_t endIdx=0; endIdx<maxNbSources_; ++endIdx) {
302 if(inputSources_[endIdx]) inputSources_[endIdx]->endStream();
307 edm::LogWarning(
"MixingModule") <<
"BMixingModule::createnewEDProduct must be overwritten!";
311 edm::LogWarning(
"MixingModule") <<
"BMixingModule::checkSignal must be overwritten!";
315 edm::LogWarning(
"MixingModule") <<
"BMixingModule::setBcrOffset must be overwritten!";
319 edm::LogWarning(
"MixingModule") <<
"BMixingModule::setSourceOffset must be overwritten!";
323 edm::LogWarning(
"MixingModule") <<
"BMixingModule::doPileUp must be overwritten!";
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
static std::unique_ptr< MixingCache::Config > initializeGlobalCache(edm::ParameterSet const &)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual void produce(edm::Event &e1, const edm::EventSetup &c) override
std::vector< std::string > sourceNames_
virtual void checkSignal(const edm::Event &e)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
virtual void endStream() override
virtual void endRun(const edm::Run &r, const edm::EventSetup &setup) override
virtual void setBcrOffset()
void put(edm::Event &evt, double value, const char *instanceName)
virtual void createnewEDProduct()
virtual void setSourceOffset(const unsigned int s)
virtual void doPileUp(edm::Event &e, const edm::EventSetup &c)
virtual void beginStream(edm::StreamID) override
Abs< T >::type abs(const T &t)
static const unsigned int maxNbSources_
std::vector< std::shared_ptr< PileUp > > inputSources_
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
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)
virtual void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
BMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)