CMS 3D CMS Logo

GlobalHitsProdHistStripper.cc
Go to the documentation of this file.
1 
11 
13  : fName(""),
14  verbosity(0),
15  frequency(0),
16  vtxunit(0),
17  getAllProvenances(false),
18  printProvenanceInfo(false),
19  outputfile(""),
20  count(0) {
21  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_GlobalHitsProdHistStripper";
22 
23  // get information from parameter set
24  fName = iPSet.getUntrackedParameter<std::string>("Name");
25  verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
26  frequency = iPSet.getUntrackedParameter<int>("Frequency");
27  vtxunit = iPSet.getUntrackedParameter<int>("VtxUnit");
28  outputfile = iPSet.getParameter<std::string>("OutputFile");
29  doOutput = iPSet.getParameter<bool>("DoOutput");
30  edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
31  getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
32  printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
33 
34  // use value of first digit to determine default output level (inclusive)
35  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
36  verbosity %= 10;
37 
38  // get dqm info
39  dbe = nullptr;
41  if (dbe) {
42  if (verbosity > 0) {
43  dbe->setVerbose(1);
44  } else {
45  dbe->setVerbose(0);
46  }
47  }
48 
49  if (dbe) {
50  if (verbosity > 0)
52  }
53 
54  // print out Parameter Set information being used
55  if (verbosity >= 0) {
56  edm::LogInfo(MsgLoggerCat) << "\n===============================\n"
57  << "Initialized as EDAnalyzer with parameter values:\n"
58  << " Name = " << fName << "\n"
59  << " Verbosity = " << verbosity << "\n"
60  << " Frequency = " << frequency << "\n"
61  << " VtxUnit = " << vtxunit << "\n"
62  << " OutputFile = " << outputfile << "\n"
63  << " DoOutput = " << doOutput << "\n"
64  << " GetProv = " << getAllProvenances << "\n"
65  << " PrintProv = " << printProvenanceInfo << "\n"
66  << "===============================\n";
67  }
68 }
69 
71  if (doOutput)
72  if (!outputfile.empty() && dbe)
74 }
75 
77 
79  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endJob";
80  if (verbosity >= 0)
81  edm::LogInfo(MsgLoggerCat) << "Terminating having processed " << count << " runs.";
82  return;
83 }
84 
86  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_beginRun";
87  // keep track of number of runs processed
88  ++count;
89 
90  int nrun = iRun.run();
91 
92  if (verbosity > 0) {
93  edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << " (" << count << " runs total)";
94  } else if (verbosity == 0) {
95  if (nrun % frequency == 0 || count == 1) {
96  edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << " (" << count << " runs total)";
97  }
98  }
99 
100  if (getAllProvenances) {
101  std::vector<const edm::StableProvenance *> AllProv;
102  iRun.getAllStableProvenance(AllProv);
103 
104  if (verbosity >= 0)
105  edm::LogInfo(MsgLoggerCat) << "Number of Provenances = " << AllProv.size();
106 
107  if (printProvenanceInfo && (verbosity >= 0)) {
108  TString eventout("\nProvenance info:\n");
109 
110  for (unsigned int i = 0; i < AllProv.size(); ++i) {
111  eventout += "\n ******************************";
112  eventout += "\n Module : ";
113  eventout += AllProv[i]->moduleLabel();
114  eventout += "\n ProductID : ";
115  eventout += AllProv[i]->productID().id();
116  eventout += "\n ClassName : ";
117  eventout += AllProv[i]->className();
118  eventout += "\n InstanceName : ";
119  eventout += AllProv[i]->productInstanceName();
120  eventout += "\n BranchName : ";
121  eventout += AllProv[i]->branchName();
122  }
123  eventout += "\n ******************************\n";
124  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
125  printProvenanceInfo = false;
126  }
127  getAllProvenances = false;
128  }
129 
130  return;
131 }
132 
134  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endRun";
135 
136  edm::Handle<TH1F> histogram1D;
137  std::vector<edm::Handle<TH1F>> allhistogram1D;
138  iRun.getManyByType(allhistogram1D);
139 
140  me.resize(allhistogram1D.size());
141 
142  for (uint i = 0; i < allhistogram1D.size(); ++i) {
143  histogram1D = allhistogram1D[i];
144  if (!histogram1D.isValid()) {
145  edm::LogWarning(MsgLoggerCat) << "Invalid histogram extracted from event.";
146  continue;
147  }
148 
149  me[i] = nullptr;
150 
151  /*
152  std::cout << "Extracting histogram: " << std::endl
153  << " Module : "
154  << (histogram1D.provenance()->branchDescription()).moduleLabel()
155  << std::endl
156  << " ProductID : "
157  <<
158  (histogram1D.provenance()->branchDescription()).productID().id()
159  << std::endl
160  << " ClassName : "
161  << (histogram1D.provenance()->branchDescription()).className()
162  << std::endl
163  << " InstanceName : "
164  <<
165  (histogram1D.provenance()->branchDescription()).productInstanceName()
166  << std::endl
167  << " BranchName : "
168  << (histogram1D.provenance()->branchDescription()).branchName()
169  << std::endl;
170  */
171 
172  if ((histogram1D.provenance()->branchDescription()).moduleLabel() != "globalhitsprodhist")
173  continue;
174 
175  std::string histname = histogram1D->GetName();
176 
177  std::string subhist1 = histname.substr(1, 5);
178  std::string subhist2 = histname.substr(1, 4);
179 
180  if (dbe) {
181  if (subhist1 == "CaloE" || subhist1 == "CaloP") {
182  dbe->setCurrentFolder("GlobalHitsV/ECal");
183  } else if (subhist1 == "CaloH") {
184  dbe->setCurrentFolder("GlobalHitsV/HCal");
185  } else if (subhist1 == "Geant" || subhist2 == "MCG4" || subhist1 == "MCRGP") {
186  dbe->setCurrentFolder("GlobalHitsV/MCGeant");
187  } else if (subhist2 == "Muon") {
188  dbe->setCurrentFolder("GlobalHitsV/Muon");
189  } else if (subhist1 == "Track") {
190  dbe->setCurrentFolder("GlobalHitsV/Tracker");
191  }
192 
193  me[i] = dbe->book1D(histname,
194  histogram1D->GetTitle(),
195  histogram1D->GetXaxis()->GetNbins(),
196  histogram1D->GetXaxis()->GetXmin(),
197  histogram1D->GetXaxis()->GetXmax());
198  me[i]->setAxisTitle(histogram1D->GetXaxis()->GetTitle(), 1);
199  me[i]->setAxisTitle(histogram1D->GetYaxis()->GetTitle(), 2);
200  }
201 
202  std::string mename = me[i]->getName();
203 
204  // std::cout << "Extracting histogram " << histname
205  // << " into MonitorElement " << mename
206  // << std::endl;
207 
208  for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
209  Double_t binx = histogram1D->GetBinCenter(x);
210  Double_t value = histogram1D->GetBinContent(x);
211  me[i]->Fill(binx, value);
212  }
213  }
214  return;
215 }
216 /*
217 if (iter != monitorElements.end()) {
218 
219  std::string mename = iter->second->getName();
220 
221  std::cout << "Extracting histogram " << histname
222  << " into MonitorElement " << mename
223  << std::endl;
224 
225  if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
226  std::cout << "Information stored in histogram pointer:"
227  << std::endl;
228  std::cout << histname << ":" << std::endl;
229  std::cout << " Entries: " << histogram1D->GetEntries()
230  << std::endl;
231  std::cout << " Mean: " << histogram1D->GetMean() << std::endl;
232  std::cout << " RMS: " << histogram1D->GetRMS() << std::endl;
233  }
234 
235  for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
236  Double_t binx = histogram1D->GetBinCenter(x);
237  Double_t value = histogram1D->GetBinContent(x);
238  iter->second->Fill(binx,value);
239  }
240 
241  if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
242  std::cout << "Information stored in monitor element:" << std::endl;
243  std::cout << mename << ":" << std::endl;
244  std::cout << " Entries: "
245  << iter->second->getEntries() << std::endl;
246  std::cout << " Mean: " << iter->second->getMean()
247  << std::endl;
248  std::cout << " RMS: " << iter->second->getRMS()
249  << std::endl;
250  }
251 } // find in map
252 } // loop through getManyByType
253 
254 return;
255 }
256 */
257 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const
Definition: Run.cc:29
RunNumber_t run() const
Definition: RunBase.h:40
MonitorElement * book1D(char_string const &name, char_string const &title, int const nchX, double const lowX, double const highX)
Book 1D histogram.
Definition: DQMStore.cc:1098
int iEvent
Definition: GenABIO.cc:224
GlobalHitsProdHistStripper(const edm::ParameterSet &)
void setVerbose(unsigned level)
Definition: DQMStore.cc:531
Definition: value.py:1
bool isValid() const
Definition: HandleBase.h:74
std::vector< MonitorElement * > me
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:571
void showDirStructure() const
Definition: DQMStore.cc:3307
void getManyByType(std::vector< Handle< PROD >> &results) const
Definition: Run.h:361
def uint(string)
void beginRun(const edm::Run &, const edm::EventSetup &) override
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2465
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45
Provenance const * provenance() const
Definition: HandleBase.h:83