26 std::shared_ptr<edm::PileUpConfig> maybeConfigPileUp(
28 std::shared_ptr<edm::PileUpConfig> pileupconfig;
30 if (ps.
exists(sourceName)) {
36 std::unique_ptr<TH1F>
h(
new TH1F(
"h",
"h", 10, 0, 10));
37 std::vector<int> dataProbFunctionVar;
38 std::vector<double> dataProb;
44 edm::LogError(
"BMixingModule") <<
"Will read from DB: reset to a dummy PileUp object.";
45 std::unique_ptr<TH1F>
h;
49 if (type_ !=
"none") {
50 if (psin.
exists(
"nbPileupEvents")) {
52 if (psin_average.
exists(
"averageNumber")) {
56 }
else if (psin_average.
exists(
"fileName") && psin_average.
exists(
"histoName")) {
69 <<
"Open a root file " <<
histoFileName <<
" containing the probability distribution histogram " 72 <<
"The PileUp number to be added will be chosen randomly from this histogram" << std::endl;
77 throw cms::Exception(
"BadHistoDistribution") <<
"The histogram should be normalized!" << std::endl;
85 }
else if (psin_average.
exists(
"probFunctionVariable") && psin_average.
exists(
"probValue") &&
86 psin_average.
exists(
"histoFileName")) {
87 if (type_ !=
"probFunction") {
89 <<
"type is set to: " << type_ <<
" while parameters implies probFunction; changing.";
90 type_ =
"probFunction";
93 dataProbFunctionVar = psin_average.
getParameter<std::vector<int> >(
"probFunctionVariable");
94 dataProb = psin_average.
getParameter<std::vector<double> >(
"probValue");
97 int varSize = (
int)dataProbFunctionVar.size();
98 int probSize = (
int)dataProb.size();
100 if ((dataProbFunctionVar[0] != 0) || (dataProbFunctionVar[varSize - 1] != (varSize - 1)))
102 <<
"Please, check the variables of the probability function! The first variable should be 0 and the " 103 "difference between two variables should be 1." 108 if (probSize < varSize) {
110 <<
" The probability function data will be completed with " << (varSize - probSize) <<
" values 0.";
112 for (
int i = 0;
i < (varSize - probSize);
i++)
113 dataProb.push_back(0);
115 probSize = dataProb.size();
117 <<
" The number of the P(x) data set after adding the values 0 is " << probSize;
121 int xmin = (
int)dataProbFunctionVar[0];
122 int xmax = (
int)dataProbFunctionVar[varSize - 1] + 1;
123 int numBins = varSize;
125 edm::LogInfo(
"MixingModule") <<
"An histogram will be created with " << numBins <<
" bins in the range (" 126 <<
xmin <<
"," <<
xmax <<
")." << std::endl;
128 std::unique_ptr<TH1F> hprob(
129 new TH1F(
"h",
"Histo from the user's probability function", numBins,
xmin,
xmax));
131 LogDebug(
"MixingModule") <<
"Filling histogram with the following data:" << std::endl;
133 for (
int j = 0;
j < numBins;
j++) {
134 LogDebug(
"MixingModule") <<
" x = " << dataProbFunctionVar[
j] <<
" P(x) = " << dataProb[
j];
135 hprob->Fill(dataProbFunctionVar[
j] + 0.5,
140 if (
std::abs(hprob->Integral() - 1) > 1.0
e-02) {
142 <<
"The probability function should be normalized!!! " << std::endl;
149 <<
" The histogram created from the x, P(x) values will be written into the root file " 162 else if (sourceName ==
"input" && psin_average.
exists(
"Lumi") && psin_average.
exists(
"sigmaInel")) {
164 ps.
getParameter<
int>(
"bunchspace") / 1000 * 3564. / 2808.;
166 edm::LogInfo(
"MixingModule") <<
" Created source " << sourceName <<
" with minBunch,maxBunch " << minb
181 : bunchSpace_(globalConf->bunchSpace_),
183 minBunch_(globalConf->minBunch_),
184 maxBunch_(globalConf->maxBunch_),
185 mixProdStep1_(
pset.getParameter<
bool>(
"mixProdStep1")),
186 mixProdStep2_(
pset.getParameter<
bool>(
"mixProdStep2")),
187 readDB_(globalConf->configFromDB_),
188 playback_(globalConf->playback_) {
189 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++) {
194 std::make_shared<PileUp>(psin, globalConf->
inputConfigs_[makeIdx], consumesCollector(),
readDB_));
212 namespace MixingCache {
214 : bunchSpace_(
pset.getParameter<
int>(
"bunchspace")),
215 minBunch_((
pset.getParameter<
int>(
"minBunch") * 25) / bunchSpace_),
216 maxBunch_((
pset.getParameter<
int>(
"maxBunch") * 25) / bunchSpace_),
217 playback_(
pset.getUntrackedParameter<
bool>(
"playback",
false)) {
220 LogInfo(
"MixingModule") <<
" ATTENTION:Mixing will be done in playback mode! \n" 221 <<
" ATTENTION:Mixing Configuration must be the same as for the original mixing!";
230 for (
size_t makeIdx = 0; makeIdx < maxNbSources; makeIdx++) {
234 if (
pset.exists(
"readDB"))
275 for (
size_t makeIdx = 0; makeIdx <
maxNbSources_; makeIdx++) {
309 for (
size_t dropIdx = 0; dropIdx <
maxNbSources_; ++dropIdx) {
316 for (
size_t dropIdx = 0; dropIdx <
maxNbSources_; ++dropIdx) {
318 inputSources_[dropIdx]->dropUnwantedBranches(wantedBranches);
331 "Multiple exceptions were thrown while executing endStream and endJob for mixing modules. " 332 "An exception message follows for each.\n");
344 edm::LogWarning(
"MixingModule") <<
"BMixingModule::createnewEDProduct must be overwritten!";
348 edm::LogWarning(
"MixingModule") <<
"BMixingModule::checkSignal must be overwritten!";
352 edm::LogWarning(
"MixingModule") <<
"BMixingModule::setBcrOffset must be overwritten!";
356 edm::LogWarning(
"MixingModule") <<
"BMixingModule::setSourceOffset must be overwritten!";
360 edm::LogWarning(
"MixingModule") <<
"BMixingModule::doPileUp must be overwritten!";
edm::ESWatcher< MixingRcd > parameterWatcher_
void beginRun(const edm::Run &r, const edm::EventSetup &setup) override
T getParameter(std::string const &) const
static std::unique_ptr< MixingCache::Config > initializeGlobalCache(edm::ParameterSet const &)
virtual void addSignals(const edm::Event &e, const edm::EventSetup &c)
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_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void checkSignal(const edm::Event &e)
void endStream() override
Log< level::Error, false > LogError
virtual void put(edm::Event &e, const edm::EventSetup &c)
void endRun(const edm::Run &r, const edm::EventSetup &setup) override
virtual void setBcrOffset()
T getUntrackedParameter(std::string const &, T const &) const
virtual void createnewEDProduct()
virtual void setSourceOffset(const unsigned int s)
virtual void doPileUp(edm::Event &e, const edm::EventSetup &c)
void registerLateConsumes(eventsetup::ESRecordsToProductResolverIndices const &) override
virtual void initializeEvent(const edm::Event &event, const edm::EventSetup &setup)
Config(edm::ParameterSet const &pset, unsigned int maxNbSources)
void beginStream(edm::StreamID) override
Abs< T >::type abs(const T &t)
static const unsigned int maxNbSources_
virtual void reload(const edm::EventSetup &setup)
Log< level::Info, false > LogInfo
~BMixingModule() override
bool check(const edm::EventSetup &iSetup)
std::vector< std::shared_ptr< PileUp > > inputSources_
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
Log< level::Warning, false > LogWarning
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
void update(edm::EventSetup const &)
std::vector< std::shared_ptr< PileUpConfig > > inputConfigs_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void setupPileUpEvent(const edm::EventSetup &setup)
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &setup) override
BMixingModule(const edm::ParameterSet &ps, MixingCache::Config const *globalConf)