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 
42  // print out Parameter Set information being used
43  if (verbosity >= 0) {
44  edm::LogInfo(MsgLoggerCat) << "\n===============================\n"
45  << "Initialized as EDAnalyzer with parameter values:\n"
46  << " Name = " << fName << "\n"
47  << " Verbosity = " << verbosity << "\n"
48  << " Frequency = " << frequency << "\n"
49  << " VtxUnit = " << vtxunit << "\n"
50  << " OutputFile = " << outputfile << "\n"
51  << " DoOutput = " << doOutput << "\n"
52  << " GetProv = " << getAllProvenances << "\n"
53  << " PrintProv = " << printProvenanceInfo << "\n"
54  << "===============================\n";
55  }
56 }
57 
59  if (doOutput)
60  if (!outputfile.empty() && dbe)
62 }
63 
65 
67  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endJob";
68  if (verbosity >= 0)
69  edm::LogInfo(MsgLoggerCat) << "Terminating having processed " << count << " runs.";
70  return;
71 }
72 
74  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_beginRun";
75  // keep track of number of runs processed
76  ++count;
77 
78  int nrun = iRun.run();
79 
80  if (verbosity > 0) {
81  edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << " (" << count << " runs total)";
82  } else if (verbosity == 0) {
83  if (nrun % frequency == 0 || count == 1) {
84  edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << " (" << count << " runs total)";
85  }
86  }
87 
88  if (getAllProvenances) {
89  std::vector<const edm::StableProvenance *> AllProv;
90  iRun.getAllStableProvenance(AllProv);
91 
92  if (verbosity >= 0)
93  edm::LogInfo(MsgLoggerCat) << "Number of Provenances = " << AllProv.size();
94 
95  if (printProvenanceInfo && (verbosity >= 0)) {
96  TString eventout("\nProvenance info:\n");
97 
98  for (unsigned int i = 0; i < AllProv.size(); ++i) {
99  eventout += "\n ******************************";
100  eventout += "\n Module : ";
101  eventout += AllProv[i]->moduleLabel();
102  eventout += "\n ProductID : ";
103  eventout += AllProv[i]->productID().id();
104  eventout += "\n ClassName : ";
105  eventout += AllProv[i]->className();
106  eventout += "\n InstanceName : ";
107  eventout += AllProv[i]->productInstanceName();
108  eventout += "\n BranchName : ";
109  eventout += AllProv[i]->branchName();
110  }
111  eventout += "\n ******************************\n";
112  edm::LogInfo(MsgLoggerCat) << eventout << "\n";
113  printProvenanceInfo = false;
114  }
115  getAllProvenances = false;
116  }
117 
118  return;
119 }
120 
122  std::string MsgLoggerCat = "GlobalHitsProdHistStripper_endRun";
123 
124  edm::Handle<TH1F> histogram1D;
125  std::vector<edm::Handle<TH1F>> allhistogram1D;
126 
127  //iRun.getManyByType(allhistogram1D);
128  throw cms::Exception("UnsupportedFunction") << "GlobalHitsProdHistStripper::endRun: "
129  << "getManyByType has not been supported by the Framework since 2015. "
130  << "This module has been broken since then. Maybe it should be deleted. "
131  << "Another possibility is to upgrade to use GetterOfProducts instead.";
132 
133  me.resize(allhistogram1D.size());
134 
135  for (uint i = 0; i < allhistogram1D.size(); ++i) {
136  histogram1D = allhistogram1D[i];
137  if (!histogram1D.isValid()) {
138  edm::LogWarning(MsgLoggerCat) << "Invalid histogram extracted from event.";
139  continue;
140  }
141 
142  me[i] = nullptr;
143 
144  /*
145  std::cout << "Extracting histogram: " << std::endl
146  << " Module : "
147  << (histogram1D.provenance()->branchDescription()).moduleLabel()
148  << std::endl
149  << " ProductID : "
150  <<
151  (histogram1D.provenance()->branchDescription()).productID().id()
152  << std::endl
153  << " ClassName : "
154  << (histogram1D.provenance()->branchDescription()).className()
155  << std::endl
156  << " InstanceName : "
157  <<
158  (histogram1D.provenance()->branchDescription()).productInstanceName()
159  << std::endl
160  << " BranchName : "
161  << (histogram1D.provenance()->branchDescription()).branchName()
162  << std::endl;
163  */
164 
165  if ((histogram1D.provenance()->branchDescription()).moduleLabel() != "globalhitsprodhist")
166  continue;
167 
168  std::string histname = histogram1D->GetName();
169 
170  std::string subhist1 = histname.substr(1, 5);
171  std::string subhist2 = histname.substr(1, 4);
172 
173  if (dbe) {
174  if (subhist1 == "CaloE" || subhist1 == "CaloP") {
175  dbe->setCurrentFolder("GlobalHitsV/ECal");
176  } else if (subhist1 == "CaloH") {
177  dbe->setCurrentFolder("GlobalHitsV/HCal");
178  } else if (subhist1 == "Geant" || subhist2 == "MCG4" || subhist1 == "MCRGP") {
179  dbe->setCurrentFolder("GlobalHitsV/MCGeant");
180  } else if (subhist2 == "Muon") {
181  dbe->setCurrentFolder("GlobalHitsV/Muon");
182  } else if (subhist1 == "Track") {
183  dbe->setCurrentFolder("GlobalHitsV/Tracker");
184  }
185 
186  me[i] = dbe->book1D(histname,
187  histogram1D->GetTitle(),
188  histogram1D->GetXaxis()->GetNbins(),
189  histogram1D->GetXaxis()->GetXmin(),
190  histogram1D->GetXaxis()->GetXmax());
191  me[i]->setAxisTitle(histogram1D->GetXaxis()->GetTitle(), 1);
192  me[i]->setAxisTitle(histogram1D->GetYaxis()->GetTitle(), 2);
193  }
194 
195  std::string mename = me[i]->getName();
196 
197  // std::cout << "Extracting histogram " << histname
198  // << " into MonitorElement " << mename
199  // << std::endl;
200 
201  for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
202  Double_t binx = histogram1D->GetBinCenter(x);
203  Double_t value = histogram1D->GetBinContent(x);
204  me[i]->Fill(binx, value);
205  }
206  }
207  return;
208 }
209 /*
210 if (iter != monitorElements.end()) {
211 
212  std::string mename = iter->second->getName();
213 
214  std::cout << "Extracting histogram " << histname
215  << " into MonitorElement " << mename
216  << std::endl;
217 
218  if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
219  std::cout << "Information stored in histogram pointer:"
220  << std::endl;
221  std::cout << histname << ":" << std::endl;
222  std::cout << " Entries: " << histogram1D->GetEntries()
223  << std::endl;
224  std::cout << " Mean: " << histogram1D->GetMean() << std::endl;
225  std::cout << " RMS: " << histogram1D->GetRMS() << std::endl;
226  }
227 
228  for (Int_t x = 1; x <= histogram1D->GetXaxis()->GetNbins(); ++x) {
229  Double_t binx = histogram1D->GetBinCenter(x);
230  Double_t value = histogram1D->GetBinContent(x);
231  iter->second->Fill(binx,value);
232  }
233 
234  if (histname == "hGeantTrkE" || histname == "hGeantTrkPt") {
235  std::cout << "Information stored in monitor element:" << std::endl;
236  std::cout << mename << ":" << std::endl;
237  std::cout << " Entries: "
238  << iter->second->getEntries() << std::endl;
239  std::cout << " Mean: " << iter->second->getMean()
240  << std::endl;
241  std::cout << " RMS: " << iter->second->getRMS()
242  << std::endl;
243  }
244 } // find in map
245 } // loop through getManyByType
246 
247 return;
248 }
249 */
250 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void getAllStableProvenance(std::vector< StableProvenance const *> &provenances) const
Definition: Run.cc:38
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:656
Provenance const * provenance() const
Definition: HandleBase.h:74
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
GlobalHitsProdHistStripper(const edm::ParameterSet &)
Definition: value.py:1
std::vector< MonitorElement * > me
const int verbosity
Log< level::Info, false > LogInfo
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool isValid() const
Definition: HandleBase.h:70
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:824
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45