CMS 3D CMS Logo

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