CMS 3D CMS Logo

HcalObjRepresent.h
Go to the documentation of this file.
1 #ifndef HcalObjRepresent_h
2 #define HcalObjRepresent_h
3 
5 
6 //#include "CondCore/Utilities/interface/PayLoadInspector.h"
7 //#include "CondCore/Utilities/interface/InspectorPythonWrapper.h"
8 
9 #include <string>
10 #include <fstream>
11 #include <sstream>
12 #include <vector>
13 
14 #include "TH1F.h"
15 #include "TH2F.h"
18 
19 #include "TROOT.h"
20 #include "TCanvas.h"
21 #include "TStyle.h"
22 #include "TColor.h"
23 #include "TLine.h"
24 
25 //functions for correct representation of data in summary and plot
26 namespace HcalObjRepresent{
27  inline std::string IntToBinary(unsigned int number) {
28  std::stringstream ss;
29  unsigned int mask = 1<<31;
30  for (unsigned short int i = 0; i < 32; ++i){
31  //if (!(i % 4))
32  // ss << "_";
33  if (mask & number)
34  ss << "1";
35  else
36  ss << "0";
37  mask = mask >> 1;
38  }
39  return ss.str();
40  }
41 
42 
43  const bool isBitSet(unsigned int bitnumber, unsigned int status)
44  {
45  unsigned int statadd = 0x1<<(bitnumber);
46  return (status&statadd)?(true):(false);
47  }
48 
49 
50  std::string getBitsSummary(uint32_t bits, std::string statusBitArray[], short unsigned int bitMap[] ){
51  std::stringstream ss;
52  for (unsigned int i = 0; i < 9; ++i){
53  if (isBitSet(bitMap[i], bits)){
54  ss << "[" <<bitMap[i]<< "]" << statusBitArray[bitMap[i]] << "; ";
55  }
56  }
57  ss << std::endl;
58  return ss.str();
59  }
60 
61 
62  //functions for making plot:
63  void setBinLabels(std::vector<TH2F> &depth)
64  {
65  // Set labels for all depth histograms
66  for (unsigned int i=0;i<depth.size();++i)
67  {
68  depth[i].SetXTitle("i#eta");
69  depth[i].SetYTitle("i#phi");
70  }
71 
72  std::stringstream label;
73 
74  // set label on every other bin
75  for (int i=-41;i<=-29;i=i+2)
76  {
77  label<<i;
78  depth[0].GetXaxis()->SetBinLabel(i+42,label.str().c_str());
79  depth[1].GetXaxis()->SetBinLabel(i+42,label.str().c_str());
80  label.str("");
81  }
82  depth[0].GetXaxis()->SetBinLabel(14,"-29HE");
83  depth[1].GetXaxis()->SetBinLabel(14,"-29HE");
84 
85  // offset by one for HE
86  for (int i=-27;i<=27;i=i+2)
87  {
88  label<<i;
89  depth[0].GetXaxis()->SetBinLabel(i+43,label.str().c_str());
90  label.str("");
91  }
92  depth[0].GetXaxis()->SetBinLabel(72,"29HE");
93  for (int i=29;i<=41;i=i+2)
94  {
95  label<<i;
96  depth[0].GetXaxis()->SetBinLabel(i+44,label.str().c_str());
97  label.str("");
98  }
99  for (int i=16;i<=28;i=i+2)
100  {
101  label<<i-43;
102  depth[1].GetXaxis()->SetBinLabel(i,label.str().c_str());
103  label.str("");
104  }
105  depth[1].GetXaxis()->SetBinLabel(29,"NULL");
106  for (int i=15;i<=27;i=i+2)
107  {
108  label<<i;
109  depth[1].GetXaxis()->SetBinLabel(i+15,label.str().c_str());
110  label.str("");
111  }
112 
113  depth[1].GetXaxis()->SetBinLabel(44,"29HE");
114  for (int i=29;i<=41;i=i+2)
115  {
116  label<<i;
117  depth[1].GetXaxis()->SetBinLabel(i+16,label.str().c_str());
118  label.str("");
119  }
120 
121  // HE depth 3 labels;
122  depth[2].GetXaxis()->SetBinLabel(1,"-28");
123  depth[2].GetXaxis()->SetBinLabel(2,"-27");
124  depth[2].GetXaxis()->SetBinLabel(3,"Null");
125  depth[2].GetXaxis()->SetBinLabel(4,"-16");
126  depth[2].GetXaxis()->SetBinLabel(5,"Null");
127  depth[2].GetXaxis()->SetBinLabel(6,"16");
128  depth[2].GetXaxis()->SetBinLabel(7,"Null");
129  depth[2].GetXaxis()->SetBinLabel(8,"27");
130  depth[2].GetXaxis()->SetBinLabel(9,"28");
131  }
132  // Now define functions that can be used in conjunction with EtaPhi histograms
133 
134  // This arrays the eta binning for depth 2 histograms (with a gap between -15 -> +15)
135  const int binmapd2[]={-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,-32,-31,-30,
136  -29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,
137  -16,-15,-9999, 15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
138  30,31,32,33,34,35,36,37,38,39,40,41,42};
139 
140  // This stores eta binning in depth 3 (where HE is only present at a few ieta values)
141 
142  const int binmapd3[]={-28,-27,-9999,-16,-9999,16,-9999,27,28};
143 
144  inline int CalcEtaBin(int subdet, int ieta, int depth)
145  {
146  // This takes the eta value from a subdetector and return an eta counter value as used by eta-phi array
147  // (ieta=-41 corresponds to bin 0, +41 to bin 85 -- there are two offsets to deal with the overlap at |ieta|=29).
148  // For HO, ieta = -15 corresponds to bin 0, and ieta=15 is bin 30
149  // For HE depth 3, things are more complicated, but feeding the ieta value will give back the corresponding counter eta value
150 
151  // The CalcEtaBin value is the value as used within our array counters, and thus starts at 0.
152  // If you are using it with getBinContent or setBinContent, you will need to add +1 to the result of this function
153 
154  int etabin=-9999; // default invalid value
155 
156  if (depth==1)
157  {
158  // Depth 1 is fairly straightforward -- just shift HF-, HF+ by -/+1
159  etabin=ieta+42;
160  if (subdet==HcalForward)
161  {
162  ieta < 0 ? etabin-- : etabin++;
163  }
164  }
165 
166  else if (depth==2)
167  {
168  // Depth 2 is more complicated, given that there are no cells in the range |ieta|<15
169  if (ieta<-14)
170  {
171  etabin=ieta+42;
172  if (subdet==HcalForward) etabin--;
173  }
174  else if (ieta>14)
175  {
176  etabin=ieta+14;
177  if (subdet==HcalForward) etabin++;
178  }
179 
180  }
181  // HO is also straightforward; a simple offset to the ieta value is applied
182  else if (subdet==HcalOuter && abs(ieta)<16)
183  etabin=ieta+15;
184  else if (subdet==HcalEndcap)
185  {
186  // HE depth 3 has spotty coverage; hard-code the bin response
187  if (depth==3)
188  {
189  if (ieta==-28) etabin=0;
190  else if (ieta==-27) etabin=1;
191  else if (ieta==-16) etabin=3;
192  else if (ieta==16) etabin=5;
193  else if (ieta==27) etabin=7;
194  else if (ieta==28) etabin=8;
195  }
196  }
197  return etabin;
198  }
199 
200  inline int CalcIeta(int subdet, int eta, int depth)
201  {
202  // This function returns the 'true' ieta value given subdet, eta, and depth
203  // Here 'eta' is the index from our arrays (it starts at 0);
204  // remember that histogram bins start with bin 1, so there's an offset of 1
205  // to consider if using getBinContent(eta,phi)
206 
207  // eta runs from 0...X (X depends on depth)
208  int ieta=-9999; // default value is nonsensical
209  if (subdet==HcalBarrel)
210  {
211  if (depth==1)
212  {
213  ieta=eta-42;
214  if (ieta==0) return -9999;
215  return ieta;
216  }
217  else if (depth==2)
218  {
219  ieta=binmapd2[eta];
220  if (ieta==0) return -9999;
221  if (ieta==17 || ieta == -17)
222  return -9999; // no depth 2 cells at |ieta| = 17
223  return ieta;
224  }
225  else
226  return -9999; // non-physical value
227  }
228  else if (subdet==HcalForward)
229  {
230  if (depth==1)
231  {
232  ieta=eta-42;
233  if (eta<13) ieta++;
234  else if (eta>71) ieta--;
235  else return -9999; // if outside forward range, return dummy
236  return ieta;
237  }
238  else if (depth==2)
239  {
240  ieta=binmapd2[eta]; // special map for depth 2
241  if (ieta<=-30) ieta++;
242  else if (ieta>=30) ieta--;
243  else return -9999;
244  return ieta;
245  }
246  else return -9999;
247  }
248 
249  else if (subdet==HcalEndcap)
250  {
251  if (depth==1)
252  ieta=eta-42;
253  else if (depth==2)
254  {
255  ieta=binmapd2[eta];
256  if (abs(ieta)>29 || abs(ieta)<18) return -9999; // outside HE
257  if (ieta==0) return -9999;
258  return ieta;
259  }
260  else if (depth==3)
261  {
262  if (eta<0 || eta>8) return -9999;
263  else
264  ieta=binmapd3[eta]; // special map for depth 3
265  if (ieta==0) return -9999;
266  return ieta;
267  }
268  else return -9999;
269  } // HcalEndcap
270  else if ( subdet==HcalOuter)
271  {
272  if (depth!=4)
273  return -9999;
274  else
275  {
276  ieta= eta-15; // bin 0 is ieta=-15, all bins increment normally from there
277  if (abs(ieta)>15) return -9999;
278  if (ieta==0) return -9999;
279  return ieta;
280  }
281  } // HcalOuter
282  if (ieta==0) return -9999;
283  return ieta;
284  }
285 
286  inline int CalcIeta(int eta, int depth)
287  {
288  // This version of CalcIeta does the same as the function above,
289  // but does not require that 'subdet' be specified.
290 
291  // returns ieta value give an eta counter.
292  // eta runs from 0...X (X depends on depth)
293  int ieta=-9999;
294  if (eta<0) return ieta;
295  if (depth==1)
296  {
297  ieta=eta-42; // default shift: bin 0 corresponds to a histogram ieta of -42 (which is offset by 1 from true HF value of -41)
298  if (eta<13) ieta++;
299  else if (eta>71) ieta--;
300  if (ieta==0) ieta=-9999;
301  return ieta;
302  }
303  else if (depth==2)
304  {
305  if (eta>57) return -9999;
306  else
307  {
308  ieta=binmapd2[eta];
309  if (ieta==-9999) return ieta;
310  if (ieta==0) return -9999;
311  if (ieta==17 || ieta == -17) return -9999; // no depth 2 cells at |ieta| = 17
312  else if (ieta<=-30) ieta++;
313  else if (ieta>=30) ieta--;
314  return ieta;
315  }
316  }
317  else if (depth==3)
318  {
319  if (eta>8) return -9999;
320  else
321  ieta=binmapd3[eta];
322  if (ieta==0) return -9999;
323  return ieta;
324  }
325  else if (depth==4)
326  {
327  ieta= eta-15; // bin 0 is ieta=-15, all bins increment normally from there
328  if (abs(ieta)>15) return -9999;
329  if (ieta==0) return -9999;
330  return ieta;
331  }
332  return ieta; // avoids compilation warning
333  }
334 
335 
336  // Functions to check whether a given (eta,depth) value is valid for a given subdetector
337 
338  inline std::vector<std::string> HcalEtaPhiHistNames()
339  {
340  std::vector<std::string> name;
341  name.push_back("HB HE HF Depth 1 ");
342  name.push_back("HB HE HF Depth 2 ");
343  name.push_back("HE Depth 3 ");
344  name.push_back("HO Depth 4 ");
345  return name;
346  }
347 
348 
349  inline bool isHB(int etabin, int depth)
350  {
351  if (depth>2) return false;
352  else if (depth<1) return false;
353  else
354  {
355  int ieta=CalcIeta(etabin,depth);
356  if (ieta==-9999) return false;
357  if (depth==1)
358  {
359  if (abs(ieta)<=16 ) return true;
360  else return false;
361  }
362  else if (depth==2)
363  {
364  if (abs(ieta)==15 || abs(ieta)==16) return true;
365  else return false;
366  }
367  }
368  return false;
369  }
370 
371  inline bool isHE(int etabin, int depth)
372  {
373  if (depth>3) return false;
374  else if (depth<1) return false;
375  else
376  {
377  int ieta=CalcIeta(etabin,depth);
378  if (ieta==-9999) return false;
379  if (depth==1)
380  {
381  if (abs(ieta)>=17 && abs(ieta)<=28 ) return true;
382  if (ieta==-29 && etabin==13) return true; // HE -29
383  if (ieta==29 && etabin == 71) return true; // HE +29
384  }
385  else if (depth==2)
386  {
387  if (abs(ieta)>=17 && abs(ieta)<=28 ) return true;
388  if (ieta==-29 && etabin==13) return true; // HE -29
389  if (ieta==29 && etabin == 43) return true; // HE +29
390  }
391  else if (depth==3)
392  return true;
393  }
394  return false;
395  }
396 
397  inline bool isHF(int etabin, int depth)
398  {
399  if (depth>2) return false;
400  else if (depth<1) return false;
401  else
402  {
403  int ieta=CalcIeta(etabin,depth);
404  if (ieta==-9999) return false;
405  if (depth==1)
406  {
407  if (ieta==-29 && etabin==13) return false; // HE -29
408  else if (ieta==29 && etabin == 71) return false; // HE +29
409  else if (abs(ieta)>=29 ) return true;
410  }
411  else if (depth==2)
412  {
413  if (ieta==-29 && etabin==13) return false; // HE -29
414  else if (ieta==29 && etabin==43) return false; // HE +29
415  else if (abs(ieta)>=29 ) return true;
416  }
417  }
418  return false;
419  }
420 
421  inline bool isHO(int etabin, int depth)
422  {
423  if (depth!=4) return false;
424  int ieta=CalcIeta(etabin,depth);
425  if (ieta!=-9999) return true;
426  return false;
427  }
428 
429  // Checks whether HO region contains SiPM
430 
431  inline bool isSiPM(int ieta, int iphi, int depth)
432  {
433  if (depth!=4) return false;
434  // HOP1
435  if (ieta>=5 && ieta <=10 && iphi>=47 && iphi<=58) return true;
436  // HOP2
437  if (ieta>=11 && ieta<=15 && iphi>=59 && iphi<=70) return true;
438  return false;
439  } // bool isSiPM
440 
441 
442  // Checks whether (subdet, ieta, iphi, depth) value is a valid Hcal cell
443 
444  inline bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)
445  {
446  // inputs are (subdetector, ieta, iphi, depth)
447  // stolen from latest version of DataFormats/HcalDetId/src/HcalDetId.cc (not yet available in CMSSW_2_1_9)
448 
449  const int ie ( abs( ies ) ) ;
450 
451  return ( ( ip >= 1 ) &&
452  ( ip <= 72 ) &&
453  ( dp >= 1 ) &&
454  ( ie >= 1 ) &&
455  ( ( ( sd == HcalBarrel ) &&
456  ( ( ( ie <= 14 ) &&
457  ( dp == 1 ) ) ||
458  ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
459  ( dp <= 2 ) ) ) ) ||
460  ( ( sd == HcalEndcap ) &&
461  ( ( ( ie == 16 ) &&
462  ( dp == 3 ) ) ||
463  ( ( ie == 17 ) &&
464  ( dp == 1 ) ) ||
465  ( ( ie >= 18 ) &&
466  ( ie <= 20 ) &&
467  ( dp <= 2 ) ) ||
468  ( ( ie >= 21 ) &&
469  ( ie <= 26 ) &&
470  ( dp <= 2 ) &&
471  ( ip%2 == 1 ) ) ||
472  ( ( ie >= 27 ) &&
473  ( ie <= 28 ) &&
474  ( dp <= 3 ) &&
475  ( ip%2 == 1 ) ) ||
476  ( ( ie == 29 ) &&
477  ( dp <= 2 ) &&
478  ( ip%2 == 1 ) ) ) ) ||
479  ( ( sd == HcalOuter ) &&
480  ( ie <= 15 ) &&
481  ( dp == 4 ) ) ||
482  ( ( sd == HcalForward ) &&
483  ( dp <= 2 ) &&
484  ( ( ( ie >= 29 ) &&
485  ( ie <= 39 ) &&
486  ( ip%2 == 1 ) ) ||
487  ( ( ie >= 40 ) &&
488  ( ie <= 41 ) &&
489  ( ip%4 == 3 ) ) ) ) ) ) ;
490 
491 
492 
493  } // bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)
494 
495 
496  // Sets eta, phi labels for 'summary' eta-phi plots (identical to Depth 1 Eta-Phi labelling)
497 
498  inline void SetEtaPhiLabels(TH2F &h)
499  {
500  std::stringstream label;
501  for (int i=-41;i<=-29;i=i+2)
502  {
503  label<<i;
504  h.GetXaxis()->SetBinLabel(i+42,label.str().c_str());
505  label.str("");
506  }
507  h.GetXaxis()->SetBinLabel(14,"-29HE");
508 
509  // offset by one for HE
510  for (int i=-27;i<=27;i=i+2)
511  {
512  label<<i;
513  h.GetXaxis()->SetBinLabel(i+43,label.str().c_str());
514  label.str("");
515  }
516  h.GetXaxis()->SetBinLabel(72,"29HE");
517  for (int i=29;i<=41;i=i+2)
518  {
519  label<<i;
520  h.GetXaxis()->SetBinLabel(i+44,label.str().c_str());
521  label.str("");
522  }
523  return;
524  }
525 
526 
527  // Fill Unphysical bins in histograms
528  inline void FillUnphysicalHEHFBins(std::vector<TH2F> &hh)
529  {
530  int ieta=0;
531  int iphi=0;
532  // First 2 depths have 5-10-20 degree corrections
533  for (unsigned int d=0;d<3;++d)
534  {
535  //BUG CAN BE HERE:
536  //if (hh[d] != 0) continue;
537 
538  for (int eta=0;eta<hh[d].GetNbinsX();++eta)
539  {
540  ieta=CalcIeta(eta,d+1);
541  if (ieta==-9999 || abs(ieta)<21) continue;
542  for (int phi=0;phi <hh[d].GetNbinsY();++phi)
543  {
544  iphi=phi+1;
545  if (iphi%2==1 && abs(ieta)<40 && iphi<73)
546  {
547  hh[d].SetBinContent(eta+1,iphi+1,hh[d].GetBinContent(eta+1,iphi));
548  }
549  // last two eta strips span 20 degrees in phi
550  // Fill the phi cell above iphi, and the 2 below it
551  else if (abs(ieta)>39 && iphi%4==3 && iphi<73)
552  {
553  //ieta=40, iphi=3 covers iphi 3,4,5,6
554  hh[d].SetBinContent(eta+1,(iphi)%72+1, hh[d].GetBinContent(eta+1,iphi));
555  hh[d].SetBinContent(eta+1,(iphi+1)%72+1, hh[d].GetBinContent(eta+1,iphi));
556  hh[d].SetBinContent(eta+1,(iphi+2)%72+1, hh[d].GetBinContent(eta+1,iphi));
557  }
558  } // for (int phi...)
559  } // for (int eta...)
560  } // for (int d=0;...)
561  // no corrections needed for HO (depth 4)
562  return;
563  } // FillUnphysicalHEHFBins(MonitorElement* hh)
564 
565 
566  //Fill unphysical bins for single ME
567  inline void FillUnphysicalHEHFBins(TH2F &hh)
568  {
569  // Fills unphysical HE/HF bins for Summary Histogram
570  // Summary Histogram is binned with the same binning as the Depth 1 EtaPhiHists
571 
572  //CAN BE BUG HERE:
573  //if (hh==0) return;
574 
575  int ieta=0;
576  int iphi=0;
577  int etabins = hh.GetNbinsX();
578  int phibins = hh.GetNbinsY();
579  float binval=0;
580  for (int eta=0;eta<etabins;++eta) // loop over eta bins
581  {
582  ieta=CalcIeta(eta,1);
583  if (ieta==-9999 || abs(ieta)<21) continue; // ignore etas that don't exist, or that have 5 degree phi binning
584 
585  for (int phi=0;phi<phibins;++phi)
586  {
587  iphi=phi+1;
588  if (iphi%2==1 && abs(ieta)<40 && iphi<73) // 10 degree phi binning condition
589  {
590  binval=hh.GetBinContent(eta+1,iphi);
591  hh.SetBinContent(eta+1,iphi+1,binval);
592  } // if (iphi%2==1...)
593  else if (abs(ieta)>39 && iphi%4==3 && iphi<73) // 20 degree phi binning condition
594  {
595  // Set last two eta strips where each cell spans 20 degrees in phi
596  // Set next phi cell above iphi, and 2 cells below the actual cell
597  hh.SetBinContent(eta+1, (iphi)%72+1, hh.GetBinContent(eta+1,iphi));
598  hh.SetBinContent(eta+1, (iphi+1)%72+1, hh.GetBinContent(eta+1,iphi));
599  hh.SetBinContent(eta+1, (iphi+2)%72+1, hh.GetBinContent(eta+1,iphi));
600  } // else if (abs(ieta)>39 ...)
601  } // for (int phi=0;phi<72;++phi)
602 
603  } // for (int eta=0; eta< (etaBins_-2);++eta)
604 
605  return;
606  } // FillUnphysicalHEHFBins(std::vector<MonitorElement*> &hh)
607 
608 
609 
610  // special fill call based on detid -- eventually will need special treatment
611  void Fill(HcalDetId& id, double val /*=1*/, std::vector<TH2F> &depth)
612  {
613  // If in HF, need to shift by 1 bin (-1 bin lower in -HF, +1 bin higher in +HF)
614  if (id.subdet()==HcalForward)
615  depth[id.depth()-1].Fill(id.ieta()<0 ? id.ieta()-1 : id.ieta()+1, id.iphi(), val);
616  else
617  depth[id.depth()-1].Fill(id.ieta(),id.iphi(),val);
618  }
619 
620  void Reset(std::vector<TH2F> &depth)
621  {
622  for (unsigned int d=0;d<depth.size();d++)
623  //BUG CAN BE HERE:
624  //if(depth[d])
625  depth[d].Reset();
626  } // void Reset(void)
627 
628  void setup(std::vector<TH2F> &depth, std::string name, std::string units=""){
629  std::string unittitle, unitname;
630  if (units.empty())
631  {
632  unitname = units;
633  unittitle = "No Units";
634  }
635  else
636  {
637  unitname = " " + units;
638  unittitle = units;
639  }
640 
641  // Push back depth plots
643  //1. create first plot
644  depth.push_back(TH2F(("HB HE HF Depth 1 "+name+unitname).c_str(),
645  (name+" Depth 1 -- HB HE HF ("+unittitle+")").c_str(),
646  85,-42.5,42.5,
647  72,0.5,72.5));
648 
649  //2.1 prepare second plot
650  float ybins[73];
651  for (int i=0;i<=72;i++) ybins[i]=(float)(i+0.5);
652  float xbinsd2[]={-42.5,-41.5,-40.5,-39.5,-38.5,-37.5,-36.5,-35.5,-34.5,-33.5,-32.5,-31.5,-30.5,-29.5,
653  -28.5,-27.5,-26.5,-25.5,-24.5,-23.5,-22.5,-21.5,-20.5,-19.5,-18.5,-17.5,-16.5,
654  -15.5,-14.5,
655  14.5, 15.5,
656  16.5,17.5,18.5,19.5,20.5,21.5,22.5,23.5,24.5,25.5,26.5,27.5,28.5,29.5,30.5,
657  31.5,32.5,33.5,34.5,35.5,36.5,37.5,38.5,39.5,40.5,41.5,42.5};
658 
659  //2.2 create second plot
660  depth.push_back(TH2F(("HB HE HF Depth 2 "+name+unitname).c_str(),
661  (name+" Depth 2 -- HB HE HF ("+unittitle+")").c_str(),
662  57, xbinsd2, 72, ybins));
663 
664  //3.1 Set up variable-sized bins for HE depth 3 (MonitorElement also requires phi bins to be entered in array format)
665  float xbins[]={-28.5,-27.5,-26.5,-16.5,-15.5,
666  15.5,16.5,26.5,27.5,28.5};
667  //3.2
668  depth.push_back(TH2F(("HE Depth 3 "+name+unitname).c_str(),
669  (name+" Depth 3 -- HE ("+unittitle+")").c_str(),
670  // Use variable-sized eta bins
671  9, xbins, 72, ybins));
672 
673  //4.1 HO bins are fixed width, but cover a smaller eta range (-15 -> 15)
674  depth.push_back(TH2F(("HO Depth 4 "+name+unitname).c_str(),
675  (name+" Depth 4 -- HO ("+unittitle+")").c_str(),
676  31,-15.5,15.5,
677  72,0.5,72.5));
678 
679  for (unsigned int i=0;i<depth.size();++i)
680  depth[i].Draw("colz");
681 
682  setBinLabels(depth); // set axis titles, special bins
683  }
684 
685  void fillOneGain(std::vector<TH2F> &graphData, HcalGains::tAllContWithNames &allContainers, std::string name, int id, std::string units=""){
686  setup(graphData, name);
687 
688  std::stringstream x;
689  // Change the titles of each individual histogram
690  for (unsigned int d=0;d < graphData.size();++d){
691  graphData[d].Reset();
692  x << "Gain "<< id << " for HCAL depth " << d+1;
693 
694  //BUG CAN BE HERE:
695  //if (ChannelStatus->depth[d])
696  graphData[d].SetTitle(x.str().c_str()); // replace "setTitle" with "SetTitle", since you are using TH2F objects instead of MonitorElements
697  x.str("");
698  }
699 
700  HcalDetId hcal_id;
701  int ieta, depth, iphi;
702 
703  //main loop
704  // get all containers with names
705  //HcalGains::tAllContWithNames allContainers = object().getAllContainers();
706 
707  //ITERATORS AND VALUES:
708  HcalGains::tAllContWithNames::const_iterator iter;
709  std::vector<HcalGain>::const_iterator contIter;
710  float gain = 0.0;
711 
712  //Run trough given id gain:
713  int i = id;
714 
715  //run trough all pair containers
716  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
717  //Run trough all values:
718  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
719  hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
720 
721  depth = hcal_id.depth();
722  if (depth<1 || depth>4)
723  continue;
724 
725  ieta=hcal_id.ieta();
726  iphi=hcal_id.iphi();
727 
728  if (hcal_id.subdet() == HcalForward)
729  ieta>0 ? ++ieta : --ieta;
730 
731  //GET VALUE:
732  gain = (*contIter).getValue(i);
733  //logstatus = log2(1.*channelBits)+1;
734 
735  //FILLING GOES HERE:
736  graphData[depth-1].Fill(ieta,iphi, gain);
737 
738  //FOR DEBUGGING:
739  //std::cout << "ieta: " << ieta << "; iphi: " << iphi << "; logstatus: " << logstatus << "; channelBits: " << channelBits<< std::endl;
740  }
741 
742  }
743  }
744 
745 
746  //FillUnphysicalHEHFBins(graphData);
747  //return ("kasdasd");
748 
749  class ADataRepr //Sample base class for c++ inheritance tutorial
750  {
751  public:
752  ADataRepr(unsigned int d):m_total(d){};
753  unsigned int nr, id;
754  std::stringstream filename, rootname, plotname;
755 
756  void fillOneGain(std::vector<TH2F> &graphData, std::string units=""){
757  std::stringstream ss("");
758 
759  if (m_total == 1)
760  ss << rootname.str() << " for HCAL depth ";
761  else
762  ss << rootname.str() << nr << " for HCAL depth ";
763 
764  setup(graphData, ss.str());
765 
766  // Change the titles of each individual histogram
767  for (unsigned int d=0;d < graphData.size();++d){
768  graphData[d].Reset();
769 
770  ss.str("");
771  if (m_total == 1)
772  ss << plotname.str() << " for HCAL depth " << d+1;
773  else
774  ss << plotname.str() << nr << " for HCAL depth " << d+1;
775 
776 
777  //BUG CAN BE HERE:
778  //if (ChannelStatus->depth[d])
779  graphData[d].SetTitle(ss.str().c_str()); // replace "setTitle" with "SetTitle", since you are using TH2F objects instead of MonitorElements
780  ss.str("");
781  }
782  //overload this function:
783  doFillIn(graphData);
784 
785  FillUnphysicalHEHFBins(graphData);
786 
787  ss.str("");
788  if (m_total == 1)
789  ss << filename.str() << ".png";
790  else
791  ss << filename.str() << nr << ".png";
792  draw(graphData, ss.str());
793  //FOR DEBUGGING:
794  //std::cout << "ieta: " << ieta << "; iphi: " << iphi << "; logstatus: " << logstatus << "; channelBits: " << channelBits<< std::endl;
795  }
796 
797  protected:
798  unsigned int m_total;
800  int ieta, depth, iphi;
801 
802 
803  virtual void doFillIn(std::vector<TH2F> &graphData) = 0;
804 
805  private:
806 
807  void draw(std::vector<TH2F> &graphData, std::string filename) {
808  //Drawing...
809  // use David's palette
810  gStyle->SetPalette(1);
811  const Int_t NCont = 999;
812  gStyle->SetNumberContours(NCont);
813  TCanvas canvas("CC map","CC map",840,369*4);
814 
815  TPad pad1("pad1","pad1", 0.0, 0.75, 1.0, 1.0);
816  pad1.Draw();
817  TPad pad2("pad2","pad2", 0.0, 0.5, 1.0, 0.75);
818  pad2.Draw();
819  TPad pad3("pad3","pad3", 0.0, 0.25, 1.0, 0.5);
820  pad3.Draw();
821  TPad pad4("pad4","pad4", 0.0, 0.0, 1.0, 0.25);
822  pad4.Draw();
823 
824 
825  pad1.cd();
826  graphData[0].SetStats(0);
827  graphData[0].Draw("colz");
828 
829  pad2.cd();
830  graphData[1].SetStats(0);
831  graphData[1].Draw("colz");
832 
833  pad3.cd();
834  graphData[2].SetStats(0);
835  graphData[2].Draw("colz");
836 
837  pad4.cd();
838  graphData[3].SetStats(0);
839  graphData[3].Draw("colz");
840 
841  canvas.SaveAs(filename.c_str());
842  }
843 
844  void setup(std::vector<TH2F> &depth, std::string name, std::string units=""){
845  std::string unittitle, unitname;
846  if (units.empty())
847  {
848  unitname = units;
849  unittitle = "No Units";
850  }
851  else
852  {
853  unitname = " " + units;
854  unittitle = units;
855  }
856 
857  // Push back depth plots
859  //1. create first plot
860  depth.push_back(TH2F(("HB HE HF Depth 1 "+name+unitname).c_str(),
861  (name+" Depth 1 -- HB HE HF ("+unittitle+")").c_str(),
862  85,-42.5,42.5,
863  72,0.5,72.5));
864 
865  //2.1 prepare second plot
866  float ybins[73];
867  for (int i=0;i<=72;i++) ybins[i]=(float)(i+0.5);
868  float xbinsd2[]={-42.5,-41.5,-40.5,-39.5,-38.5,-37.5,-36.5,-35.5,-34.5,-33.5,-32.5,-31.5,-30.5,-29.5,
869  -28.5,-27.5,-26.5,-25.5,-24.5,-23.5,-22.5,-21.5,-20.5,-19.5,-18.5,-17.5,-16.5,
870  -15.5,-14.5,
871  14.5, 15.5,
872  16.5,17.5,18.5,19.5,20.5,21.5,22.5,23.5,24.5,25.5,26.5,27.5,28.5,29.5,30.5,
873  31.5,32.5,33.5,34.5,35.5,36.5,37.5,38.5,39.5,40.5,41.5,42.5};
874 
875  //2.2 create second plot
876  depth.push_back(TH2F(("HB HE HF Depth 2 "+name+unitname).c_str(),
877  (name+" Depth 2 -- HB HE HF ("+unittitle+")").c_str(),
878  57, xbinsd2, 72, ybins));
879 
880  //3.1 Set up variable-sized bins for HE depth 3 (MonitorElement also requires phi bins to be entered in array format)
881  float xbins[]={-28.5,-27.5,-26.5,-16.5,-15.5,
882  15.5,16.5,26.5,27.5,28.5};
883  //3.2
884  depth.push_back(TH2F(("HE Depth 3 "+name+unitname).c_str(),
885  (name+" Depth 3 -- HE ("+unittitle+")").c_str(),
886  // Use variable-sized eta bins
887  9, xbins, 72, ybins));
888 
889  //4.1 HO bins are fixed width, but cover a smaller eta range (-15 -> 15)
890  depth.push_back(TH2F(("HO Depth 4 "+name+unitname).c_str(),
891  (name+" Depth 4 -- HO ("+unittitle+")").c_str(),
892  31,-15.5,15.5,
893  72,0.5,72.5));
894 
895  for (unsigned int i=0;i<depth.size();++i)
896  depth[i].Draw("colz");
897 
898  setBinLabels(depth); // set axis titles, special bins
899  }
900 
901  //functions for making plot:
902  void setBinLabels(std::vector<TH2F> &depth)
903  {
904  // Set labels for all depth histograms
905  for (unsigned int i=0;i<depth.size();++i)
906  {
907  depth[i].SetXTitle("i#eta");
908  depth[i].SetYTitle("i#phi");
909  }
910 
911  std::stringstream label;
912 
913  // set label on every other bin
914  for (int i=-41;i<=-29;i=i+2)
915  {
916  label<<i;
917  depth[0].GetXaxis()->SetBinLabel(i+42,label.str().c_str());
918  depth[1].GetXaxis()->SetBinLabel(i+42,label.str().c_str());
919  label.str("");
920  }
921  depth[0].GetXaxis()->SetBinLabel(14,"-29HE");
922  depth[1].GetXaxis()->SetBinLabel(14,"-29HE");
923 
924  // offset by one for HE
925  for (int i=-27;i<=27;i=i+2)
926  {
927  label<<i;
928  depth[0].GetXaxis()->SetBinLabel(i+43,label.str().c_str());
929  label.str("");
930  }
931  depth[0].GetXaxis()->SetBinLabel(72,"29HE");
932  for (int i=29;i<=41;i=i+2)
933  {
934  label<<i;
935  depth[0].GetXaxis()->SetBinLabel(i+44,label.str().c_str());
936  label.str("");
937  }
938  for (int i=16;i<=28;i=i+2)
939  {
940  label<<i-43;
941  depth[1].GetXaxis()->SetBinLabel(i,label.str().c_str());
942  label.str("");
943  }
944  depth[1].GetXaxis()->SetBinLabel(29,"NULL");
945  for (int i=15;i<=27;i=i+2)
946  {
947  label<<i;
948  depth[1].GetXaxis()->SetBinLabel(i+15,label.str().c_str());
949  label.str("");
950  }
951 
952  depth[1].GetXaxis()->SetBinLabel(44,"29HE");
953  for (int i=29;i<=41;i=i+2)
954  {
955  label<<i;
956  depth[1].GetXaxis()->SetBinLabel(i+16,label.str().c_str());
957  label.str("");
958  }
959 
960  // HE depth 3 labels;
961  depth[2].GetXaxis()->SetBinLabel(1,"-28");
962  depth[2].GetXaxis()->SetBinLabel(2,"-27");
963  depth[2].GetXaxis()->SetBinLabel(3,"Null");
964  depth[2].GetXaxis()->SetBinLabel(4,"-16");
965  depth[2].GetXaxis()->SetBinLabel(5,"Null");
966  depth[2].GetXaxis()->SetBinLabel(6,"16");
967  depth[2].GetXaxis()->SetBinLabel(7,"Null");
968  depth[2].GetXaxis()->SetBinLabel(8,"27");
969  depth[2].GetXaxis()->SetBinLabel(9,"28");
970  }
971 
972  };
973 }
974 #endif
std::vector< std::string > HcalEtaPhiHistNames()
void SetEtaPhiLabels(TH2F &h)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
const double xbins[]
std::string getBitsSummary(uint32_t bits, std::string statusBitArray[], short unsigned int bitMap[])
bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)
void setBinLabels(std::vector< TH2F > &depth)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
bool isHE(int etabin, int depth)
std::string IntToBinary(unsigned int number)
bool isHB(int etabin, int depth)
T x() const
Cartesian x coordinate.
const int binmapd3[]
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
int CalcIeta(int subdet, int eta, int depth)
bool isSiPM(int ieta, int iphi, int depth)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void doFillIn(std::vector< TH2F > &graphData)=0
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
const bool isBitSet(unsigned int bitnumber, unsigned int status)
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void draw(std::vector< TH2F > &graphData, std::string filename)
void fillOneGain(std::vector< TH2F > &graphData, std::string units="")
int CalcEtaBin(int subdet, int ieta, int depth)
void fillOneGain(std::vector< TH2F > &graphData, HcalGains::tAllContWithNames &allContainers, std::string name, int id, std::string units="")
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
auto dp
Definition: deltaR.h:22
double sd
bool isHF(int etabin, int depth)
void FillUnphysicalHEHFBins(std::vector< TH2F > &hh)
TString units(TString variable, Char_t axis)
def canvas(sub, attr)
Definition: svgfig.py:481
bool isHO(int etabin, int depth)
void Reset(std::vector< TH2F > &depth)
void setBinLabels(std::vector< TH2F > &depth)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
const int binmapd2[]