CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1THcalClient.cc
Go to the documentation of this file.
9 #include <iostream>
10 #include <stdio.h>
11 #include <string>
12 #include <sstream>
13 #include <math.h>
14 #include <TROOT.h>
15 #include <TStyle.h>
16 #include <TH1F.h>
17 #include <TH2F.h>
18 #include <TF1.h>
19 using namespace edm;
20 using namespace std;
21 
22 // Local definitions for the limits of the histograms
23 const unsigned int RTPBINS = 101;
24 const float RTPMIN = -0.5;
25 const float RTPMAX = 100.5;
26 
27 const unsigned int TPPHIBINS = 72;
28 const float TPPHIMIN = 0.5;
29 const float TPPHIMAX = 72.5;
30 
31 const unsigned int TPETABINS = 65;
32 const float TPETAMIN = -32.5;
33 const float TPETAMAX = 32.5;
34 
35 const unsigned int effBins = 50;
36 const float effMinHBHE = -0.5;
37 const float effMaxHBHE = 5.5;
38 const float effMinHF = -0.5;
39 const float effMaxHF = 2.5;
40 
41 const unsigned int ratiobins = 100;
42 const float ratiomin = 0.0;
43 const float ratiomax = 1.0;
44 
45 const unsigned int tvsrecbins = 100;
46 const float tvsrecmin = 0.0;
47 const float tvsrecmax = 100.0;
48 
49 const unsigned int effcombo = 6472;
50 const float effcombomin = -3272;
51 const float effcombomax = 3272;
52 
54 {
55  minEventsforFit = iConfig.getUntrackedParameter<int>("minEventsforFit",1000);
56  input_dir = "L1T/L1THCALTPGXAna/";
57  output_dir = "L1T/L1THCALTPGXAna/Tests/";
58 
59  dbe = edm::Service<DQMStore>().operator->();
60  // dbe->showDirStructure();
61  // dbe->setVerbose(1);
62 
63  LogInfo( "TriggerDQM");
64 }
65 
66 // ---------------------------------------------------------
67 
69 {
70 
71  LogInfo("TriggerDQM")<<"[TriggerDQM]: ending... ";
72 
73 }
74 
75 
76 // ------------ method called to for each event ------------
77 
78 
79 
80 // ------------ method called once each job just before starting event loop ------------
81 
83 {
84  LogInfo("TriggerDQM")<<"[TriggerDQM]: Begin Job";
85  // LogInfo("TriggerDQM")<<"[TriggerDQM]: Standalone = "<<stdalone;
86  nevents = 0;
87  dbe->setCurrentFolder(output_dir);
88  //2-D plots
89  hcalPlateau_ =
90  dbe->book2D("FitPlateau","HCAL Fit Plateau",TPETABINS,TPETAMIN,TPETAMAX,
92  hcalThreshold_ =
93  dbe->book2D("FitThreshold","HCAL Fit Threshold",TPETABINS,TPETAMIN,TPETAMAX,
95  hcalWidth_ =
96  dbe->book2D("FitWidth","HCAL Fit Width",TPETABINS,TPETAMIN,TPETAMAX,
98  hcalEff_1_ =
99  dbe->book1D("HcalEff1","HCAL Efficiency - 1",effBins,effMinHBHE,effMaxHBHE);
100  hcalEff_2_ =
101  dbe->book1D("HcalEff2","HCAL Efficiency - 2",effBins,effMinHBHE,effMaxHBHE);
102  hcalEff_3_ =
103  dbe->book1D("HcalEff3","HCAL Efficiency - 3",effBins,effMinHBHE,effMaxHBHE);
104  hcalEff_4_ =
105  dbe->book1D("HcalEff4","HCAL Efficiency - 4",effBins,effMinHF,effMaxHF);
106 
107 
108 
109 
110  if (0){
111  //efficiency histos for HBHE
112  for (int i=0; i < 56; i++)
113  {
114  char hname[20],htitle[20];
115  char dirname[80];
116  int ieta, iphi;
117  if (i<28) ieta = i-28;
118  else ieta = i-27;
119  sprintf(dirname,"%sEffByChannel/EtaTower%d",output_dir.c_str(),ieta);
120  dbe->setCurrentFolder(dirname);
121  for (int j=0; j < 72; j++)
122  {
123  iphi = j+1;
124  if (i<28) ieta = i-28;
125  else ieta = i-27;
126  sprintf(hname,"eff_%d_%d",ieta,iphi);
127  sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
128  hcalEff_HBHE[i][j] = dbe->book1D(hname, htitle, effBins,effMinHBHE,effMaxHBHE);
129  }
130  }
131  //efficiency histos for HF
132  for (int i=0; i < 8; i++)
133  {
134  char hname[20],htitle[20];
135  char dirname[80];
136  int ieta, iphi;
137  if (i<4) ieta = i-32;
138  else ieta = i+25;
139  sprintf(dirname,"%sEffByChannel/EtaTower%d",output_dir.c_str(),ieta);
140  dbe->setCurrentFolder(dirname);
141  for (int j=0; j < 18; j++)
142  {
143  iphi = j*4+1;
144  if (i<4) ieta = i-32;
145  else ieta = i+25;
146  sprintf(hname,"eff_%d_%d",ieta,iphi);
147  sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
148  hcalEff_HF[i][j] = dbe->book1D(hname, htitle, effBins,effMinHF,effMaxHF);
149  }
150  }
151  }
152 
153 }
154 
155 // ------------ method called once each job just after ending the event loop ------------
157 
158  LogInfo("TriggerDQM")<<"[TriggerDQM]: endJob";
159 
160 }
161 
162 void
164 {
165  using namespace edm;
166  nevents++;
167  if (nevents%10 == 0) LogInfo("TriggerDQM")<<"[TriggerDQM]: event analyzed "<<nevents;
168 
169  //}
170  // //void L1THcalClient::endLuminosityBlock(const edm::LuminosityBlock & iLumiSection, const edm::EventSetup & iSetup) {
171  // LogInfo("TriggerDQM")<<"[TriggerDQM]: end Lumi Section.";
172  //dbe->setCurrentFolder("L1T/QTests");
173  TF1 *turnon = new TF1("turnon","[0]*0.5*(TMath::Erf((x -[1])*0.5/[2])+1.)",0,30);
174  TH1F *eff_histo;
175 
176  //efficiency by region
177  //std::cout << "before eff calc \n";
178  TH1F *hcalEff_num = this->get1DHisto(input_dir+"HcalTP1",dbe);
179  if (!hcalEff_num) std::cout << "numerator not found\n";
180  TH1F *hcalEff_den = this->get1DHisto(input_dir+"HcalAll1",dbe);
181  if (!hcalEff_den) std::cout << "denominator not found\n";
182  //hcalEff_1_ =
183  // dbe->book1D("HcalEff1","HCAL Efficiency - 1",effBins,effMinHBHE,effMaxHBHE);
184  calcEff(hcalEff_num, hcalEff_den, hcalEff_1_);
185  if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
186  {
187  eff_histo = this->get1DHisto(output_dir+"HcalEff1",dbe);
188  turnon->SetParameter(0,1);
189  turnon->SetParameter(1,2);
190  turnon->SetParameter(2,6);
191  eff_histo->Fit("turnon","LL,E");
192  }
193  hcalEff_num = this->get1DHisto(input_dir+"HcalTP2",dbe);
194  if (!hcalEff_num) std::cout << "numerator not found\n";
195  hcalEff_den = this->get1DHisto(input_dir+"HcalAll2",dbe);
196  if (!hcalEff_den) std::cout << "denominator not found\n";
197  //hcalEff_2_ =
198  // dbe->book1D("HcalEff2","HCAL Efficiency - 2",effBins,effMinHBHE,effMaxHBHE);
199  calcEff(hcalEff_num, hcalEff_den, hcalEff_2_);
200  if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
201  {
202  eff_histo = this->get1DHisto(output_dir+"HcalEff2",dbe);
203  turnon->SetParameter(0,1);
204  turnon->SetParameter(1,2);
205  turnon->SetParameter(2,6);
206  eff_histo->Fit("turnon","LL,E");
207  }
208  hcalEff_num = this->get1DHisto(input_dir+"HcalTP3",dbe);
209  if (!hcalEff_num) std::cout << "numerator not found\n";
210  hcalEff_den = this->get1DHisto(input_dir+"HcalAll3",dbe);
211  if (!hcalEff_den) std::cout << "denominator not found\n";
212  //hcalEff_3_ =
213  //dbe->book1D("HcalEff3","HCAL Efficiency - 3",effBins,effMinHBHE,effMaxHBHE);
214  calcEff(hcalEff_num, hcalEff_den, hcalEff_3_);
215  if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
216  {
217  eff_histo = this->get1DHisto(output_dir+"HcalEff3",dbe);
218  turnon->SetParameter(0,1);
219  turnon->SetParameter(1,3);
220  turnon->SetParameter(2,6);
221  eff_histo->Fit("turnon","LL,E");
222  }
223  hcalEff_num = this->get1DHisto(input_dir+"HcalTP4",dbe);
224  if (!hcalEff_num) std::cout << "numerator not found\n";
225  hcalEff_den = this->get1DHisto(input_dir+"HcalAll4",dbe);
226  if (!hcalEff_den) std::cout << "denominator not found\n";
227  // hcalEff_4_ =
228  //dbe->book1D("HcalEff4","HCAL Efficiency - 4",effBins,effMinHF,effMaxHF);
229  calcEff(hcalEff_num, hcalEff_den, hcalEff_4_);
230  if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
231  {
232  eff_histo = this->get1DHisto(output_dir+"HcalEff4",dbe);
233  turnon->SetParameter(0,1);
234  turnon->SetParameter(1,1);
235  turnon->SetParameter(2,6);
236  eff_histo->Fit("turnon","LL,E");
237  }
238  double plateau, threshold, width;
239 
240 
241  if (0){
242  //efficiency histos for HBHE
243  for (int i=0; i < 56; i++)
244  {
245  char hname[20],htitle[30];
246  int ieta, iphi;
247  char subdirname[80];
248  for (int j=0; j < 72; j++)
249  {
250  iphi = j+1;
251  if (i<28) ieta = i-28;
252  else ieta = i-27;
253  sprintf(hname,"eff_%d_%d",ieta,iphi);
254  sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
255  //hcalEff_HBHE[i][j] = dbe->book1D(hname, htitle, effBins,effMinHBHE,effMaxHBHE);
256  sprintf(subdirname,"%sEffByChannel/EtaTower%d/",input_dir.c_str(),ieta);
257  hcalEff_num = this->get1DHisto((string)subdirname+(string)hname+"_num",dbe);
258  hcalEff_den = this->get1DHisto((string)subdirname+(string)hname+"_den",dbe);
259  if (!hcalEff_num) std::cout <<(string)subdirname+(string)hname+"_num" << "numerator not found\n";
260  if (!hcalEff_num) std::cout << "numerator not found\n";
261  if (!hcalEff_den) std::cout << "denominator not found\n";
262  calcEff(hcalEff_num, hcalEff_den, hcalEff_HBHE[i][j]);
263 
264  if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
265  {
266  sprintf(subdirname,"%sEffByChannel/EtaTower%d/",output_dir.c_str(),ieta);
267  eff_histo = this->get1DHisto((string)subdirname+(string)hname,dbe);
268  turnon->SetParameter(0,1);
269  turnon->SetParameter(1,3);
270  turnon->SetParameter(2,6);
271  eff_histo->Fit("turnon","LL,E");
272  plateau = turnon->GetParameter(0);
273  threshold = turnon->GetParameter(1);
274  width = turnon->GetParameter(2);
275  hcalPlateau_->Fill(ieta,iphi,plateau);
276  hcalThreshold_->Fill(ieta,iphi,threshold);
277  hcalWidth_->Fill(ieta,iphi,width);
278  }
279  }
280  }
281  //efficiency histos for HF
282  for (int i=0; i < 8; i++)
283  {
284  char hname[20],htitle[30];
285  int ieta, iphi;
286  char subdirname[80];
287  for (int j=0; j < 18; j++)
288  {
289  iphi = j*4+1;
290  if (i<4) ieta = i-32;
291  else ieta = i+25;
292  sprintf(hname,"eff_%d_%d",ieta,iphi);
293  sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
294  //hcalEff_HF[i][j] = dbe->book1D(hname, htitle, effBins,effMinHF,effMaxHF);
295  sprintf(subdirname,"%sEffByChannel/EtaTower%d/",input_dir.c_str(),ieta);
296  hcalEff_num = this->get1DHisto((string)subdirname+(string)hname+"_num",dbe);
297  hcalEff_den = this->get1DHisto((string)subdirname+(string)hname+"_den",dbe);
298  if (!hcalEff_num) std::cout <<(string)subdirname+(string)hname+"_num" << "numerator not found\n";
299  if (!hcalEff_den) std::cout << "denominator not found\n";
300  calcEff(hcalEff_num, hcalEff_den, hcalEff_HF[i][j]);
301  if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
302  {
303  sprintf(subdirname,"%sEffByChannel/EtaTower%d/",output_dir.c_str(),ieta);
304  eff_histo = this->get1DHisto((string)subdirname+(string)hname,dbe);
305  turnon->SetParameter(0,1);
306  turnon->SetParameter(1,1);
307  turnon->SetParameter(2,6);
308  eff_histo->Fit("turnon","LL,E");
309  plateau = turnon->GetParameter(0);
310  threshold = turnon->GetParameter(1);
311  width = turnon->GetParameter(2);
312  hcalPlateau_->Fill(ieta,iphi,plateau);
313  hcalThreshold_->Fill(ieta,iphi,threshold);
314  hcalWidth_->Fill(ieta,iphi,width);
315  }
316  }
317  }
318  }
319 }
320 
321 void L1THcalClient::calcEff(TH1F *num, TH1F *den, MonitorElement* me)
322 {
323  if (num->GetNbinsX() != den->GetNbinsX())
324  {
325  std::cout << "numerator and denominator do not have the same number of bins!\n";
326  return;
327  }
328  double eff;
329  for (int bin = 0; bin <= num->GetNbinsX(); bin++)
330  {
331  if (den->GetBinContent(bin) != 0) eff = num->GetBinContent(bin)/den->GetBinContent(bin);
332  else eff = 0;
333  me->setBinContent(bin,eff);
334  }
335 }
336 
337 TH1F * L1THcalClient::get1DHisto(string meName, DQMStore * dbi)
338 {
339 
340  // string mePath = "Collector/GlobalDQM/L1T/" + meName;
341 
342  // MonitorElement * me_ = dbi->get(mePath);
343  MonitorElement * me_ = dbi->get(meName);
344 
345  TH1F * meHisto = NULL;
346 
347  if (me_) {
348 
349  meHisto = me_->getTH1F();
350  }
351  else {
352 
353  LogInfo("TriggerDQM") << "ME " << meName << " NOT FOUND!";
354 
355  }
356 
357  return meHisto;
358 }
359 
360 TH2F * L1THcalClient::get2DHisto(string meName, DQMStore * dbi)
361 {
362 
363  // string mePath = "Collector/GlobalDQM/L1T/" + meName;
364 
365  MonitorElement * me_ = dbi->get(meName);
366 
367  TH2F * meHisto = NULL;
368 
369  if (me_) {
370 
371  meHisto = me_->getTH2F();
372  }
373  else {
374 
375  LogInfo("TriggerDQM") << "ME NOT FOUND.";
376 
377  }
378 
379  return meHisto;
380 }
381 
const unsigned int RTPBINS
Definition: L1TECALTPG.cc:81
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
const float effcombomax
const float TPETAMIN
Definition: L1TCompare.cc:111
void calcEff(TH1F *num, TH1F *den, MonitorElement *me)
const float effMinHF
virtual void analyze(const edm::Event &, const edm::EventSetup &)
const unsigned int TPPHIBINS
Definition: L1TCompare.cc:106
const float RTPMIN
Definition: L1TECALTPG.cc:82
#define NULL
Definition: scimark2.h:8
TH2F * get2DHisto(std::string meName, DQMStore *dbi)
const unsigned int tvsrecbins
const float TPETAMAX
Definition: L1TCompare.cc:112
const unsigned int TPETABINS
Definition: L1TCompare.cc:110
const unsigned int ratiobins
int iEvent
Definition: GenABIO.cc:243
const float effMaxHBHE
const float RTPMAX
Definition: L1TECALTPG.cc:83
int j
Definition: DBlmapReader.cc:9
int nevents
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
virtual void beginJob(void)
const float ratiomax
const float ratiomin
const float effMinHBHE
const unsigned int effBins
const float TPPHIMIN
Definition: L1TCompare.cc:107
const float TPPHIMAX
Definition: L1TCompare.cc:108
TH1F * getTH1F(void) const
long long int num
Definition: procUtils.cc:71
TH1F * get1DHisto(std::string meName, DQMStore *dbi)
const float effcombomin
string output_dir
Definition: o2o.py:33
const unsigned int effcombo
const float tvsrecmax
tuple cout
Definition: gather_cfg.py:41
virtual void endJob()
TH2F * getTH2F(void) const
const float effMaxHF
const float tvsrecmin
L1THcalClient(const edm::ParameterSet &)