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