27 boost::shared_ptr<edm::PileUp>
30 boost::shared_ptr<edm::PileUp>
pileup;
33 if (
find(names.begin(), names.end(), sourceName)
40 std::string histoName =
" ";
41 TH1F *
h =
new TH1F(
"h",
"h",10,0,10);
42 vector<int> dataProbFunctionVar;
43 vector<double> dataProb;
48 if (
find(namesIn.begin(), namesIn.end(), std::string(
"nbPileupEvents"))
52 if (
find(namesAverage.begin(), namesAverage.end(), std::string(
"averageNumber"))
53 != namesAverage.end())
55 averageNumber=psin_average.
getParameter<
double>(
"averageNumber");
57 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb<<
" and averageNumber "<<averageNumber;
59 else if (
find(namesAverage.begin(), namesAverage.end(), std::string(
"fileName"))
60 != namesAverage.end() &&
find(namesAverage.begin(), namesAverage.end(), std::string(
"histoName"))
61 != namesAverage.end()){
67 TFile *
infile =
new TFile(histoFileName.c_str());
68 TH1F *h = (TH1F*)infile->Get(histoName.c_str());
72 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram " << histoName
73 <<
"in the file " << histoFileName <<
"." << std::endl;
75 edm::LogInfo(
"MixingModule") <<
"Open a root file " << histoFileName <<
" containing the probability distribution histogram " << histoName << std::endl;
76 edm::LogInfo(
"MixingModule") <<
"The PileUp number to be added will be chosen randomly from this histogram" << std::endl;
80 if (((h->Integral() - 1) > 1.0e-02) && ((h->Integral() - 1) < -1.0e-02))
throw cms::Exception(
"BadHistoDistribution") <<
"The histogram should be normalized!" << std::endl;
83 averageNumber = h->GetMean();
86 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb<<
" and averageNumber "<<averageNumber;
89 else if (
find(namesAverage.begin(), namesAverage.end(), std::string(
"probFunctionVariable"))
90 != namesAverage.end() &&
find(namesAverage.begin(), namesAverage.end(), std::string(
"probValue"))
91 != namesAverage.end() &&
find(namesAverage.begin(), namesAverage.end(), std::string(
"histoFileName"))
92 != namesAverage.end()){
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.0e-02) && ((hprob->Integral() - 1) < -1.0e-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");
148 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb<<
" and averageNumber "<<averageNumber;
152 else if (sourceName==
"input" &&
find(namesAverage.begin(), namesAverage.end(), std::string(
"Lumi"))
153 != namesAverage.end() &&
find(namesAverage.begin(), namesAverage.end(), std::string(
"sigmaInel"))
154 != namesAverage.end()) {
159 edm::LogInfo(
"MixingModule") <<
" Created source "<<sourceName<<
" with minBunch,maxBunch "<<minb<<
" "<<maxb;
160 edm::LogInfo(
"MixingModule")<<
" Luminosity configuration, average number used is "<<averageNumber;
173 bunchSpace_(pset.getParameter<int>(
"bunchspace")),
174 minBunch_((pset.getParameter<int>(
"minBunch")*25)/pset.getParameter<int>(
"bunchspace")),
175 maxBunch_((pset.getParameter<int>(
"maxBunch")*25)/pset.getParameter<int>(
"bunchspace")),
176 mixProdStep1_(pset.getParameter<bool>(
"mixProdStep1")),
177 mixProdStep2_(pset.getParameter<bool>(
"mixProdStep2"))
181 if (
find(names.begin(), names.end(),
"playback")
189 LogInfo(
"MixingModule") <<
" ATTENTION:Mixing will be done in playback mode! \n"
190 <<
" ATTENTION:Mixing Configuration must be the same as for the original mixing!";
236 LogDebug(
"MixingModule") <<
"\n\n==============================>Adding pileup to signal event "<<e.
id();
249 LogDebug(
"MixingModule") <<
"\n\n==============================>Adding cosmics to signal event "<<e.
id();
263 LogDebug(
"MixingModule") <<
"\n\n==============================>Adding beam halo+ to signal event "<<e.
id();
277 LogDebug(
"MixingModule") <<
"\n\n==============================>Adding beam halo- to signal event "<<e.
id();
293 LogDebug(
"MixingModule") <<
"For bunchcrossing "<<bcr<<
", "<<vec.size()<<
" events will be merged";
296 for (EventPrincipalVector::const_iterator it = vec.begin(); it != vec.end(); ++it) {
297 LogDebug(
"MixingModule") <<
" merging Event: id " << (*it)->id();
305 if (
input_)
input_->dropUnwantedBranches(wantedBranches);
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void addPileups(const int bcr, EventPrincipal *ep, unsigned int eventId, unsigned int worker, const edm::EventSetup &c)
virtual void addSignals(const edm::Event &e, const edm::EventSetup &c)
std::vector< EventPrincipalVector > pileup_[4]
std::vector< std::vector< edm::EventID > > vectorEventIDs_
void merge(const int bcr, const EventPrincipalVector &vec, unsigned int worker, const edm::EventSetup &c)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
virtual void put(edm::Event &e, const edm::EventSetup &c)
virtual void checkSignal(const edm::Event &e)
PileUp::EventPrincipalVector EventPrincipalVector
static const unsigned int maxNbSources_
std::vector< std::string > getParameterNames() const
std::vector< float > TrueNumInteractions_[4]
boost::shared_ptr< PileUp > cosmics_
virtual void setEventStartInfo(const unsigned int s)
boost::shared_ptr< PileUp > beamHalo_m_
virtual void getEventStartInfo(edm::Event &e, const unsigned int source)
virtual void produce(edm::Event &e1, const edm::EventSetup &c)
boost::shared_ptr< PileUp > input_
virtual void doPileUp(edm::Event &e, const edm::EventSetup &c)
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
virtual void createnewEDProduct()
static const HistoName names[]
boost::shared_ptr< PileUp > beamHalo_p_
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")