CMS 3D CMS Logo

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