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"
15 
16 #include <string>
17 #include <fstream>
18 #include <sstream>
19 #include <vector>
20 
21 #include "TH1F.h"
22 #include "TH2F.h"
24 
25 #include "TROOT.h"
26 #include "TCanvas.h"
27 #include "TStyle.h"
28 #include "TColor.h"
29 #include "TLine.h"
30 #include "TLatex.h"
31 #include "TProfile.h"
32 #include "TPaveLabel.h"
33 
34 //functions for correct representation of data in summary and plot
35 namespace HcalObjRepresent {
36 
37  //used to produce all display objects for payload inspector
38  template <class Items, class Item>
40  public:
41  HcalDataContainer(std::shared_ptr<Items> payload, unsigned int run) : payload_(payload), run_(run) {
42  PlotMode_ = "Map";
43  }
44 
45  virtual ~HcalDataContainer(){};
46  // For easier channel mapping
47  typedef std::tuple<int, int, int> Coord;
48  typedef std::map<Coord, Item> tHcalValCont;
49  // mapping of pair of subdetector name (e.g, "HE") and depth number (e.g. 3) to Histogram of data for that subdetector/depth pair
50  typedef std::map<std::pair<std::string, int>, TH2F*> DepthMap;
51 
53  unsigned int GetRun() { return run_; }
54 
56 
57  std::map<std::string, int> GetSubDetDepths() { return subDetDepths_; }
58 
60  fillValConts();
61  //std::cout << "Got depths with run number = " << std::to_string(GetRun()) << std::endl;
62  return depths_;
63  }
64 
66 
67  // Fills a tHcalValCont for each subdetector, setting Topology Mode along the way
68  void fillValConts() {
69  if (!depths_.empty())
70  return;
71  int iphi, ieta, depth;
73 
74  std::string subDetName;
75  std::vector<Item> itemsVec;
76  std::pair<std::string, int> depthKey;
77  const char* histLabel;
78  for (std::pair<std::string, std::vector<Item> > cont : (*payload_).getAllContainers()) {
79  subDetName = std::get<0>(cont);
80  itemsVec = std::get<1>(cont);
81 
82  auto valContainer = getContFromString(subDetName);
83 
84  for (Item item : itemsVec) {
85  detId = HcalDetId(item.rawId());
86  iphi = detId.iphi();
87  ieta = detId.ieta();
88  depth = detId.depth();
89  Coord coord = std::make_tuple(depth, ieta, iphi);
90  //Add hist if it's not there, AND if it is one we care about: HO,HB,HE,HF, AND it's not an empty entry (depth = 0 in HO)
91  if (subDetName[0] == 'H' && depth != 0) {
92  valContainer->insert(std::pair<std::tuple<int, int, int>, Item>(coord, item));
93 
94  depthKey = std::make_pair(subDetName, depth);
95 
96  auto depthVal = depths_.find(depthKey);
97  if (depthVal == depths_.end()) {
98  histLabel = ("run" + std::to_string(run_) + "_" + subDetName + "_d" + std::to_string(depth)).c_str();
99  depths_.insert(std::make_pair(std::make_pair(subDetName, depth),
100  new TH2F(histLabel, histLabel, 83, -42.5, 41.5, 71, 0.5, 71.5)));
101  }
102  depths_[depthKey]->Fill(ieta, iphi, getValue(&item));
103  }
104  }
105  }
106 
107  //Still need to know which hists to take when done; decide now
109  }
110 
111  const std::vector<std::pair<std::string, std::vector<Item> > > getAllItems() {
112  return (*payload_).getAllContainers();
113  }
114 
116  virtual float getValue(const Item* item) {
117  throw cms::Exception("Value definition not found") << "getValue definition not found for " << payload_->myname();
118  }
119 
120  //Gets Hcal Object at given coordinate
121  //Currently unused but remains as a potentially useful function
122  Item* getItemFromValCont(std::string subDetName, int depth, int ieta, int iphi, bool throwOnFail) {
123  Item* cell = nullptr;
124  Coord coord = std::make_tuple(depth, ieta, iphi);
125  tHcalValCont* valContainer = getContFromString(subDetName);
126 
127  auto it = valContainer->find(coord);
128  if (it != valContainer->end())
129  cell = &it->second;
130 
131  if ((!cell)) {
132  if (throwOnFail) {
133  throw cms::Exception("Conditions not found")
134  << "Unavailable Conditions of type " << payload_->myname() << " for cell " << subDetName << " (" << depth
135  << ", " << ieta << ", " << iphi << ")";
136  }
137  }
138  return cell;
139  }
140 
142 
143  //TODO: remove zero entries from doing divide and subtract
144 
145  // To generate Ratios of two IOVs
146  void Divide(HcalDataContainer* dataCont2) {
147  //TODO: Do something like looping over this and that depths setting every empty bin (which I think means content=0) to -999. Then replacing the divide call with another manual loop that sets all bins with content -999 to 0
148 
149  PlotMode_ = "Ratio";
150  DepthMap::iterator depth1;
151  std::pair<std::string, int> key;
152  DepthMap myDepths = this->GetDepths();
153  DepthMap theirDepths = dataCont2->GetDepths();
154  for (depth1 = myDepths.begin(); depth1 != myDepths.end(); depth1++) {
155  key = depth1->first;
156  if (theirDepths.count(key) != 0) {
157  myDepths.at(key)->Divide((const TH1*)theirDepths.at(key));
158  } else {
159  throw cms::Exception("Unaligned Conditions")
160  << "trying to plot conditions for " << payload_->myname() << "; found value for " << std::get<0>(key)
161  << " depth " << std::to_string(std::get<1>(key)) << " in run " << GetRun() << " but not in run "
162  << dataCont2->GetRun();
163  }
164  }
165  }
166 
167  // To generate Diffs of two IOVs
168  void Subtract(HcalDataContainer* dataCont2) {
169  PlotMode_ = "Diff";
170  DepthMap::iterator depth1;
171  std::pair<std::string, int> key;
172  DepthMap myDepths = this->GetDepths();
173  DepthMap theirDepths = dataCont2->GetDepths();
174  for (depth1 = myDepths.begin(); depth1 != myDepths.end(); depth1++) {
175  key = depth1->first;
176  if (theirDepths.count(key) != 0) {
177  myDepths.at(key)->Add(myDepths.at(key), theirDepths.at(key), 1, -1);
178  } else {
179  throw cms::Exception("Unaligned Conditions")
180  << "trying to plot conditions for " << payload_->myname() << "; found value for " << std::get<0>(key)
181  << " depth " << std::to_string(std::get<1>(key)) << " in run " << GetRun() << " but not in run "
182  << dataCont2->GetRun();
183  }
184  }
185  }
186 
187  // wisely determines what range to set histogram axis to
188  std::pair<float, float> GetRange(TH1* hist) {
189  if (PlotMode_ == "Ratio") {
190  float amp;
191  Double_t adjustMin = 1;
192  Double_t tempMin;
193  int nBinsX = hist->GetXaxis()->GetNbins();
194  int nBinsY = hist->GetYaxis()->GetNbins();
195  for (int i = 0; i < nBinsX; i++) {
196  for (int j = 0; j < nBinsY; j++) {
197  tempMin = hist->GetBinContent(i, j);
198  if ((tempMin != 0) && (tempMin < adjustMin))
199  adjustMin = tempMin;
200  }
201  }
202  amp = std::max((1 - adjustMin), (hist->GetMaximum() - 1));
203  //amp = std::max((1 - hist->GetMinimum()),(hist->GetMaximum() - 1) );
204  return std::make_pair(1 - amp, 1 + amp);
205  } else if (PlotMode_ == "Diff") {
206  float amp;
207  amp = std::max((0 - hist->GetMinimum()), hist->GetMaximum());
208  return std::make_pair((-1 * amp), amp);
209  } else {
210  Double_t adjustMin = 10000;
211  Double_t tempMin;
212  int nBinsX = hist->GetXaxis()->GetNbins();
213  int nBinsY = hist->GetYaxis()->GetNbins();
214  for (int i = 0; i < nBinsX; i++) {
215  for (int j = 0; j < nBinsY; j++) {
216  tempMin = hist->GetBinContent(i, j);
217  if ((tempMin != 0) && (tempMin < adjustMin))
218  adjustMin = tempMin;
219  }
220  }
221  return std::make_pair(((adjustMin == 10000) ? hist->GetMinimum() : adjustMin), hist->GetMaximum());
222  }
223  }
224 
225  // set style
226  void initGraphics() {
227  gStyle->SetOptStat(0);
228  gStyle->SetPalette(1);
229  gStyle->SetOptFit(0);
230  gStyle->SetLabelFont(42);
231  gStyle->SetLabelFont(42);
232  gStyle->SetTitleFont(42);
233  gStyle->SetTitleFont(42);
234  gStyle->SetMarkerSize(0);
235  gStyle->SetTitleOffset(1.3, "Y");
236  gStyle->SetTitleOffset(1.0, "X");
237  gStyle->SetNdivisions(510);
238  gStyle->SetStatH(0.11);
239  gStyle->SetStatW(0.33);
240  gStyle->SetTitleW(0.4);
241  gStyle->SetTitleX(0.13);
242  gStyle->SetPadTickX(1);
243  gStyle->SetPadTickY(1);
244  }
245 
246  TH1D* GetProjection(TH2F* hist, std::string plotType, const char* newName, std::string subDetName, int depth) {
247  //TODO: Also want average for standard projection of 2DHist (not ratio or diff)?
248  //if (PlotMode_ != "Ratio") return (plotType=="EtaProfile") ? ((TH2F*)(hist->Clone("temp")))->ProjectionX(newName) : ((TH2F*)(hist->Clone("temp")))->ProjectionY(newName);
249 
250  //TH1D* projection = ((TH2F*)(depths_[std::make_pair(subDetName,depth)]->Clone("temp")))->ProjectionX(newName);
251 
252  int xBins = (plotType == "EtaProfile") ? 83 : 71;
253  int etaMin = -42, etaMax = 42, phiMin = 1, phiMax = 72;
254  int xMin = (plotType == "EtaProfile") ? etaMin : phiMin;
255  int xMax = (plotType == "EtaProfile") ? etaMax : phiMax;
256  int otherMin = (plotType == "EtaProfile") ? phiMin : etaMin;
257  int otherMax = (plotType == "EtaProfile") ? phiMax : etaMax;
258  TH1D* retHist = new TH1D(newName, newName, xBins, xMin, xMax);
259  int numChannels;
260  Double_t sumVal;
261  Double_t channelVal;
262  int ieta, iphi;
263  int bin = 0;
264  for (int i = xMin; i <= xMax; i++ && bin++) {
265  numChannels = 0;
266  sumVal = 0;
267  for (int j = otherMin; j <= otherMax; j++) {
268  ieta = (plotType == "EtaProfile") ? i : j;
269  ieta += 42;
270  iphi = (plotType == "EtaProfile") ? j : i;
271  iphi += -1;
272  channelVal = hist->GetBinContent(ieta, iphi);
273  //std::cout << "(ieta, iphi) : (" << std::to_string(ieta) << ", " << std::to_string(iphi) << ")" << std::endl;
274  if (channelVal != 0) {
275  sumVal += channelVal;
276  numChannels++;
277  }
278  }
279  //if(sumVal !=0) projection->SetBinContent(i, sumVal/((Double_t)numChannels));//retHist->Fill(i,sumVal/((Double_t)numChannels));
280  if (sumVal != 0)
281  retHist->Fill(i, sumVal / ((Double_t)numChannels));
282  }
283  return retHist;
284  //return projection;
285  }
286 
287  // fills a canvas with given subdetector information, plotting all depths
288  void FillCanv(TCanvas* canvas,
289  std::string subDetName,
290  int startDepth = 1,
291  int startCanv = 1,
292  std::string plotForm = "2DHist") {
293  const char* newName;
294  std::pair<float, float> range;
295  int padNum;
296  int maxDepth = (subDetName == "HO") ? 4 : subDetDepths_[subDetName];
297  TH1D* projection;
298  TLatex label;
299  for (int i = startDepth; i <= maxDepth; i++) {
300  //skip if data not obtained; TODO: Maybe add text on plot saying data not found?
301  if (depths_.count(std::make_pair(subDetName, i)) == 0) {
302  return;
303  }
304 
305  padNum = i + startCanv - 1;
306  if (subDetName == "HO")
307  padNum = padNum - 3;
308  canvas->cd(padNum);
309  canvas->GetPad(padNum)->SetGridx(1);
310  canvas->GetPad(padNum)->SetGridy(1);
311 
312  if (plotForm == "2DHist") {
313  canvas->GetPad(padNum)->SetRightMargin(0.13);
314  range = GetRange(depths_[std::make_pair(subDetName, i)]);
315  depths_[std::make_pair(subDetName, i)]->Draw("colz");
316  depths_[std::make_pair(subDetName, i)]->SetContour(100);
317  depths_[std::make_pair(subDetName, i)]->GetXaxis()->SetTitle("ieta");
318  depths_[std::make_pair(subDetName, i)]->GetYaxis()->SetTitle("iphi");
319  depths_[std::make_pair(subDetName, i)]->GetXaxis()->CenterTitle();
320  depths_[std::make_pair(subDetName, i)]->GetYaxis()->CenterTitle();
321  depths_[std::make_pair(subDetName, i)]->GetZaxis()->SetRangeUser(std::get<0>(range), std::get<1>(range));
322  depths_[std::make_pair(subDetName, i)]->GetYaxis()->SetTitleSize(0.06);
323  depths_[std::make_pair(subDetName, i)]->GetYaxis()->SetTitleOffset(0.80);
324  depths_[std::make_pair(subDetName, i)]->GetXaxis()->SetTitleSize(0.06);
325  depths_[std::make_pair(subDetName, i)]->GetXaxis()->SetTitleOffset(0.80);
326  depths_[std::make_pair(subDetName, i)]->GetYaxis()->SetLabelSize(0.055);
327  depths_[std::make_pair(subDetName, i)]->GetXaxis()->SetLabelSize(0.055);
328  } else {
329  canvas->GetPad(padNum)->SetLeftMargin(0.152);
330  canvas->GetPad(padNum)->SetRightMargin(0.02);
331  //gStyle->SetTitleOffset(1.6,"Y");
332  newName = ("run_" + std::to_string(run_) + "_" + subDetName + "_d" + std::to_string(i) + "_" +
333  (plotForm == "EtaProfile" ? "ieta" : "iphi"))
334  .c_str();
335  //projection = ((TH2F*)(depths_[std::make_pair(subDetName,i)]->Clone("temp")))->ProjectionX(newName);
336  projection = GetProjection(depths_[std::make_pair(subDetName, i)], plotForm, newName, subDetName, i);
337  range = GetRange(projection);
338  projection->Draw("hist");
339  projection->GetXaxis()->SetTitle((plotForm == "EtaProfile" ? "ieta" : "iphi"));
340  projection->GetXaxis()->CenterTitle();
341  projection->GetYaxis()->SetTitle(
342  (payload_->myname() + " " + (PlotMode_ == "Map" ? "" : PlotMode_) + " " + GetUnit(payload_->myname()))
343  .c_str());
344  label.SetNDC();
345  label.SetTextAlign(26);
346  label.SetTextSize(0.05);
347  label.DrawLatex(
348  0.3, 0.95, ("run_" + std::to_string(run_) + "_" + subDetName + "_d" + std::to_string(i)).c_str());
349  projection->GetYaxis()->CenterTitle();
350  projection->GetXaxis()->SetTitleSize(0.06);
351  projection->GetYaxis()->SetTitleSize(0.06);
352  projection->GetXaxis()->SetTitleOffset(0.80);
353  projection->GetXaxis()->SetLabelSize(0.055);
354  projection->GetYaxis()->SetTitleOffset(1.34);
355  projection->GetYaxis()->SetLabelSize(0.055);
356  }
357  }
358  }
359 
361 
362  // profile = "EtaProfile" || "PhiProfile"
363  TCanvas* getCanvasAll(std::string profile = "2DHist") {
364  fillValConts();
365  initGraphics();
366  TCanvas* HAll = new TCanvas("HAll", "HAll", 1680, (GetTopoMode() == "2015/2016") ? 1680 : 2500);
367  HAll->Divide(3, (GetTopoMode() == "2015/2016") ? 3 : 6, 0.02, 0.01);
368  FillCanv(HAll, "HB", 1, 1, profile);
369  FillCanv(HAll, "HO", 4, 3, profile);
370  FillCanv(HAll, "HF", 1, 4, profile);
371  FillCanv(HAll, "HE", 1, (GetTopoMode() == "2015/2016") ? 7 : 10, profile);
372  return HAll;
373  }
374 
375  TCanvas* getCanvasHF() {
376  fillValConts();
377  initGraphics();
378  TCanvas* HF = new TCanvas("HF", "HF", 1600, 1000);
379  HF->Divide(3, 2, 0.02, 0.01);
380  FillCanv(HF, "HF");
381  return HF;
382  }
383  TCanvas* getCanvasHE() {
384  fillValConts();
385  initGraphics();
386  TCanvas* HE = new TCanvas("HE", "HE", 1680, 1680);
387  HE->Divide(3, 3, 0.02, 0.01);
388  FillCanv(HE, "HE");
389  return HE;
390  }
391  TCanvas* getCanvasHBHO() {
392  fillValConts();
393  initGraphics();
394  TCanvas* HBHO = new TCanvas("HBHO", "HBHO", 1680, 1680);
395  HBHO->Divide(3, 3, 0.02, 0.01);
396  FillCanv(HBHO, "HB");
397  FillCanv(HBHO, "HO", 4, 3);
398  FillCanv(HBHO, "HB", 1, 4, "EtaProfile");
399  FillCanv(HBHO, "HO", 4, 6, "EtaProfile");
400  FillCanv(HBHO, "HB", 1, 7, "PhiProfile");
401  FillCanv(HBHO, "HO", 4, 9, "PhiProfile");
402  return HBHO;
403  }
404 
407  if (unit.empty())
408  return "";
409  else
410  return "(" + unit + ")";
411  }
412 
413  private:
415  std::shared_ptr<Items> payload_;
416  unsigned int run_;
418  // "Map", "Ratio", or "Diff"
420 
429  std::map<std::string, int> subDetDepths_;
430  std::map<std::string, std::string> units_ = {{"HcalPedestals", "ADC"},
431  {"HcalGains", ""}, //dimensionless TODO: verify
432  {"HcalL1TriggerObjects", ""}, //dimensionless TODO: Verify
433  {"HcalPedestalWidths", "ADC"},
434  {"HcalRespCorrs", ""}, //dimensionless TODO: verify
435  {"Dark Current", ""},
436  {"fcByPE", ""},
437  {"crossTalk", ""},
438  {"parLin", ""}};
439 
441  if (subDetString == "HB")
442  return &HBvalContainer;
443  else if (subDetString == "HE")
444  return &HEvalContainer;
445  else if (subDetString == "HF")
446  return &HFvalContainer;
447  else if (subDetString == "HO")
448  return &HOvalContainer;
449  else if (subDetString == "HT")
450  return &HTvalContainer;
451  else if (subDetString == "CALIB")
452  return &CALIBvalContainer;
453  else if (subDetString == "CASTOR")
454  return &CASTORvalContainer;
455  //else return &ZDCvalContainer;
456  else if (subDetString == "ZDC_EM" || subDetString == "ZDC" || subDetString == "ZDC_HAD" ||
457  subDetString == "ZDC_LUM")
458  return &ZDCvalContainer;
459  else
460  throw cms::Exception("subDetString " + subDetString + " not found in Item");
461  }
462 
463  void setTopoModeFromValConts(bool throwOnFail = false) {
464  // Check HEP17 alternate channel for 2017, just by checking if the 7th depth is there, or if HF has 4 depths
465  if (depths_.count(std::make_pair("HF", 4)) != 0 || depths_.count(std::make_pair("HE", 7)) != 0)
466  TopoMode_ = "2017";
467  // Check endcap depth unique to 2018
468  else if (HEvalContainer.count(std::make_tuple(7, -26, 63)) != 0)
469  TopoMode_ = "2018";
470  // if not 2017 or 2018, 2015 and 2016 are the same
471  else
472  TopoMode_ = "2015/2016";
473  //NOTE: HO's one depth is labeled depth 4
474  if (TopoMode_ == "2018" || TopoMode_ == "2017") {
475  subDetDepths_.insert(std::pair<std::string, int>("HB", 2));
476  subDetDepths_.insert(std::pair<std::string, int>("HE", 7));
477  subDetDepths_.insert(std::pair<std::string, int>("HF", 4));
478  subDetDepths_.insert(std::pair<std::string, int>("HO", 1));
479  } else if (TopoMode_ == "2015/2016") {
480  subDetDepths_.insert(std::pair<std::string, int>("HB", 2));
481  subDetDepths_.insert(std::pair<std::string, int>("HE", 3));
482  subDetDepths_.insert(std::pair<std::string, int>("HF", 2));
483  subDetDepths_.insert(std::pair<std::string, int>("HO", 1));
484  }
485  }
486  };
487 
488  inline void drawTable(int nbRows, int nbColumns) {
489  TLine* l = new TLine;
490  l->SetLineWidth(1);
491  for (int i = 1; i < nbRows; i++) {
492  double y = (double)i;
493  l = new TLine(0., y, nbColumns, y);
494  l->Draw();
495  }
496 
497  for (int i = 1; i < nbColumns; i++) {
498  double x = (double)i;
499  double y = (double)nbRows;
500  l = new TLine(x, 0., x, y);
501  l->Draw();
502  }
503  }
504 
505  inline std::string SciNotatStr(float num) {
506  // Create an output string stream
507  std::ostringstream streamObj2;
508 
509  if (num == -1)
510  return "NOT FOUND";
511 
512  //Add double to stream
513  streamObj2 << num;
514  // Get string from output string stream
515  std::string strObj2 = streamObj2.str();
516 
517  return strObj2;
518  }
519 
520  inline std::string IntToBinary(unsigned int number) {
521  std::stringstream ss;
522  unsigned int mask = 1 << 31;
523  for (unsigned short int i = 0; i < 32; ++i) {
524  //if (!(i % 4))
525  // ss << "_";
526  if (mask & number)
527  ss << "1";
528  else
529  ss << "0";
530  mask = mask >> 1;
531  }
532  return ss.str();
533  }
534 
535  inline const bool isBitSet(unsigned int bitnumber, unsigned int status) {
536  unsigned int statadd = 0x1 << (bitnumber);
537  return (status & statadd) ? (true) : (false);
538  }
539 
540  inline std::string getBitsSummary(uint32_t bits, std::string statusBitArray[], short unsigned int bitMap[]) {
541  std::stringstream ss;
542  for (unsigned int i = 0; i < 9; ++i) {
543  if (isBitSet(bitMap[i], bits)) {
544  ss << "[" << bitMap[i] << "]" << statusBitArray[bitMap[i]] << "; ";
545  }
546  }
547  ss << std::endl;
548  return ss.str();
549  }
550 
551  //functions for making plot:
552  inline void setBinLabels(std::vector<TH2F>& depth) {
553  // Set labels for all depth histograms
554  for (unsigned int i = 0; i < depth.size(); ++i) {
555  depth[i].SetXTitle("i#eta");
556  depth[i].SetYTitle("i#phi");
557  }
558 
559  std::stringstream label;
560 
561  // set label on every other bin
562  for (int i = -41; i <= -29; i = i + 2) {
563  label << i;
564  depth[0].GetXaxis()->SetBinLabel(i + 42, label.str().c_str());
565  depth[1].GetXaxis()->SetBinLabel(i + 42, label.str().c_str());
566  label.str("");
567  }
568  depth[0].GetXaxis()->SetBinLabel(14, "-29HE");
569  depth[1].GetXaxis()->SetBinLabel(14, "-29HE");
570 
571  // offset by one for HE
572  for (int i = -27; i <= 27; i = i + 2) {
573  label << i;
574  depth[0].GetXaxis()->SetBinLabel(i + 43, label.str().c_str());
575  label.str("");
576  }
577  depth[0].GetXaxis()->SetBinLabel(72, "29HE");
578  for (int i = 29; i <= 41; i = i + 2) {
579  label << i;
580  depth[0].GetXaxis()->SetBinLabel(i + 44, label.str().c_str());
581  label.str("");
582  }
583  for (int i = 16; i <= 28; i = i + 2) {
584  label << i - 43;
585  depth[1].GetXaxis()->SetBinLabel(i, label.str().c_str());
586  label.str("");
587  }
588  depth[1].GetXaxis()->SetBinLabel(29, "NULL");
589  for (int i = 15; i <= 27; i = i + 2) {
590  label << i;
591  depth[1].GetXaxis()->SetBinLabel(i + 15, label.str().c_str());
592  label.str("");
593  }
594 
595  depth[1].GetXaxis()->SetBinLabel(44, "29HE");
596  for (int i = 29; i <= 41; i = i + 2) {
597  label << i;
598  depth[1].GetXaxis()->SetBinLabel(i + 16, label.str().c_str());
599  label.str("");
600  }
601 
602  // HE depth 3 labels;
603  depth[2].GetXaxis()->SetBinLabel(1, "-28");
604  depth[2].GetXaxis()->SetBinLabel(2, "-27");
605  depth[2].GetXaxis()->SetBinLabel(3, "Null");
606  depth[2].GetXaxis()->SetBinLabel(4, "-16");
607  depth[2].GetXaxis()->SetBinLabel(5, "Null");
608  depth[2].GetXaxis()->SetBinLabel(6, "16");
609  depth[2].GetXaxis()->SetBinLabel(7, "Null");
610  depth[2].GetXaxis()->SetBinLabel(8, "27");
611  depth[2].GetXaxis()->SetBinLabel(9, "28");
612  }
613  // Now define functions that can be used in conjunction with EtaPhi histograms
614 
615  // This arrays the eta binning for depth 2 histograms (with a gap between -15 -> +15)
616  const int binmapd2[] = {-42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28,
617  -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -9999, 15,
618  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
619  31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42};
620 
621  // This stores eta binning in depth 3 (where HE is only present at a few ieta values)
622 
623  const int binmapd3[] = {-28, -27, -9999, -16, -9999, 16, -9999, 27, 28};
624 
625  inline int CalcEtaBin(int subdet, int ieta, int depth) {
626  // This takes the eta value from a subdetector and return an eta counter value as used by eta-phi array
627  // (ieta=-41 corresponds to bin 0, +41 to bin 85 -- there are two offsets to deal with the overlap at |ieta|=29).
628  // For HO, ieta = -15 corresponds to bin 0, and ieta=15 is bin 30
629  // For HE depth 3, things are more complicated, but feeding the ieta value will give back the corresponding counter eta value
630 
631  // The CalcEtaBin value is the value as used within our array counters, and thus starts at 0.
632  // If you are using it with getBinContent or setBinContent, you will need to add +1 to the result of this function
633 
634  int etabin = -9999; // default invalid value
635 
636  if (depth == 1) {
637  // Depth 1 is fairly straightforward -- just shift HF-, HF+ by -/+1
638  etabin = ieta + 42;
639  if (subdet == HcalForward) {
640  ieta < 0 ? etabin-- : etabin++;
641  }
642  }
643 
644  else if (depth == 2) {
645  // Depth 2 is more complicated, given that there are no cells in the range |ieta|<15
646  if (ieta < -14) {
647  etabin = ieta + 42;
648  if (subdet == HcalForward)
649  etabin--;
650  } else if (ieta > 14) {
651  etabin = ieta + 14;
652  if (subdet == HcalForward)
653  etabin++;
654  }
655 
656  }
657  // HO is also straightforward; a simple offset to the ieta value is applied
658  else if (subdet == HcalOuter && abs(ieta) < 16)
659  etabin = ieta + 15;
660  else if (subdet == HcalEndcap) {
661  // HE depth 3 has spotty coverage; hard-code the bin response
662  if (depth == 3) {
663  if (ieta == -28)
664  etabin = 0;
665  else if (ieta == -27)
666  etabin = 1;
667  else if (ieta == -16)
668  etabin = 3;
669  else if (ieta == 16)
670  etabin = 5;
671  else if (ieta == 27)
672  etabin = 7;
673  else if (ieta == 28)
674  etabin = 8;
675  }
676  }
677  return etabin;
678  }
679 
680  inline int CalcIeta(int subdet, int eta, int depth) {
681  // This function returns the 'true' ieta value given subdet, eta, and depth
682  // Here 'eta' is the index from our arrays (it starts at 0);
683  // remember that histogram bins start with bin 1, so there's an offset of 1
684  // to consider if using getBinContent(eta,phi)
685 
686  // eta runs from 0...X (X depends on depth)
687  int ieta = -9999; // default value is nonsensical
688  if (subdet == HcalBarrel) {
689  if (depth == 1) {
690  ieta = eta - 42;
691  if (ieta == 0)
692  return -9999;
693  return ieta;
694  } else if (depth == 2) {
695  ieta = binmapd2[eta];
696  if (ieta == 0)
697  return -9999;
698  if (ieta == 17 || ieta == -17)
699  return -9999; // no depth 2 cells at |ieta| = 17
700  return ieta;
701  } else
702  return -9999; // non-physical value
703  } else if (subdet == HcalForward) {
704  if (depth == 1) {
705  ieta = eta - 42;
706  if (eta < 13)
707  ieta++;
708  else if (eta > 71)
709  ieta--;
710  else
711  return -9999; // if outside forward range, return dummy
712  return ieta;
713  } else if (depth == 2) {
714  ieta = binmapd2[eta]; // special map for depth 2
715  if (ieta <= -30)
716  ieta++;
717  else if (ieta >= 30)
718  ieta--;
719  else
720  return -9999;
721  return ieta;
722  } else
723  return -9999;
724  }
725 
726  else if (subdet == HcalEndcap) {
727  if (depth == 1)
728  ieta = eta - 42;
729  else if (depth == 2) {
730  ieta = binmapd2[eta];
731  if (abs(ieta) > 29 || abs(ieta) < 18)
732  return -9999; // outside HE
733  if (ieta == 0)
734  return -9999;
735  return ieta;
736  } else if (depth == 3) {
737  if (eta < 0 || eta > 8)
738  return -9999;
739  else
740  ieta = binmapd3[eta]; // special map for depth 3
741  if (ieta == 0)
742  return -9999;
743  return ieta;
744  } else
745  return -9999;
746  } // HcalEndcap
747  else if (subdet == HcalOuter) {
748  if (depth != 4)
749  return -9999;
750  else {
751  ieta = eta - 15; // bin 0 is ieta=-15, all bins increment normally from there
752  if (abs(ieta) > 15)
753  return -9999;
754  if (ieta == 0)
755  return -9999;
756  return ieta;
757  }
758  } // HcalOuter
759  if (ieta == 0)
760  return -9999;
761  return ieta;
762  }
763 
764  inline int CalcIeta(int eta, int depth) {
765  // This version of CalcIeta does the same as the function above,
766  // but does not require that 'subdet' be specified.
767 
768  // returns ieta value give an eta counter.
769  // eta runs from 0...X (X depends on depth)
770  int ieta = -9999;
771  if (eta < 0)
772  return ieta;
773  if (depth == 1) {
774  ieta =
775  eta -
776  42; // default shift: bin 0 corresponds to a histogram ieta of -42 (which is offset by 1 from true HF value of -41)
777  if (eta < 13)
778  ieta++;
779  else if (eta > 71)
780  ieta--;
781  if (ieta == 0)
782  ieta = -9999;
783  return ieta;
784  } else if (depth == 2) {
785  if (eta > 57)
786  return -9999;
787  else {
788  ieta = binmapd2[eta];
789  if (ieta == -9999)
790  return ieta;
791  if (ieta == 0)
792  return -9999;
793  if (ieta == 17 || ieta == -17)
794  return -9999; // no depth 2 cells at |ieta| = 17
795  else if (ieta <= -30)
796  ieta++;
797  else if (ieta >= 30)
798  ieta--;
799  return ieta;
800  }
801  } else if (depth == 3) {
802  if (eta > 8)
803  return -9999;
804  else
805  ieta = binmapd3[eta];
806  if (ieta == 0)
807  return -9999;
808  return ieta;
809  } else if (depth == 4) {
810  ieta = eta - 15; // bin 0 is ieta=-15, all bins increment normally from there
811  if (abs(ieta) > 15)
812  return -9999;
813  if (ieta == 0)
814  return -9999;
815  return ieta;
816  }
817  return ieta; // avoids compilation warning
818  }
819 
820  // Functions to check whether a given (eta,depth) value is valid for a given subdetector
821 
822  inline std::vector<std::string> HcalEtaPhiHistNames() {
823  std::vector<std::string> name;
824  name.push_back("HB HE HF Depth 1 ");
825  name.push_back("HB HE HF Depth 2 ");
826  name.push_back("HE Depth 3 ");
827  name.push_back("HO Depth 4 ");
828  return name;
829  }
830 
831  inline bool isHB(int etabin, int depth) {
832  if (depth > 2)
833  return false;
834  else if (depth < 1)
835  return false;
836  else {
837  int ieta = CalcIeta(etabin, depth);
838  if (ieta == -9999)
839  return false;
840  if (depth == 1) {
841  if (abs(ieta) <= 16)
842  return true;
843  else
844  return false;
845  } else if (depth == 2) {
846  if (abs(ieta) == 15 || abs(ieta) == 16)
847  return true;
848  else
849  return false;
850  }
851  }
852  return false;
853  }
854 
855  inline bool isHE(int etabin, int depth) {
856  if (depth > 3)
857  return false;
858  else if (depth < 1)
859  return false;
860  else {
861  int ieta = CalcIeta(etabin, depth);
862  if (ieta == -9999)
863  return false;
864  if (depth == 1) {
865  if (abs(ieta) >= 17 && abs(ieta) <= 28)
866  return true;
867  if (ieta == -29 && etabin == 13)
868  return true; // HE -29
869  if (ieta == 29 && etabin == 71)
870  return true; // HE +29
871  } else if (depth == 2) {
872  if (abs(ieta) >= 17 && abs(ieta) <= 28)
873  return true;
874  if (ieta == -29 && etabin == 13)
875  return true; // HE -29
876  if (ieta == 29 && etabin == 43)
877  return true; // HE +29
878  } else if (depth == 3)
879  return true;
880  }
881  return false;
882  }
883 
884  inline bool isHF(int etabin, int depth) {
885  if (depth > 2)
886  return false;
887  else if (depth < 1)
888  return false;
889  else {
890  int ieta = CalcIeta(etabin, depth);
891  if (ieta == -9999)
892  return false;
893  if (depth == 1) {
894  if (ieta == -29 && etabin == 13)
895  return false; // HE -29
896  else if (ieta == 29 && etabin == 71)
897  return false; // HE +29
898  else if (abs(ieta) >= 29)
899  return true;
900  } else if (depth == 2) {
901  if (ieta == -29 && etabin == 13)
902  return false; // HE -29
903  else if (ieta == 29 && etabin == 43)
904  return false; // HE +29
905  else if (abs(ieta) >= 29)
906  return true;
907  }
908  }
909  return false;
910  }
911 
912  inline bool isHO(int etabin, int depth) {
913  if (depth != 4)
914  return false;
915  int ieta = CalcIeta(etabin, depth);
916  if (ieta != -9999)
917  return true;
918  return false;
919  }
920 
921  // Checks whether HO region contains SiPM
922 
923  inline bool isSiPM(int ieta, int iphi, int depth) {
924  if (depth != 4)
925  return false;
926  // HOP1
927  if (ieta >= 5 && ieta <= 10 && iphi >= 47 && iphi <= 58)
928  return true;
929  // HOP2
930  if (ieta >= 11 && ieta <= 15 && iphi >= 59 && iphi <= 70)
931  return true;
932  return false;
933  } // bool isSiPM
934 
935  // Checks whether (subdet, ieta, iphi, depth) value is a valid Hcal cell
936 
937  inline bool validDetId(HcalSubdetector sd, int ies, int ip, int dp) {
938  // inputs are (subdetector, ieta, iphi, depth)
939  // stolen from latest version of DataFormats/HcalDetId/src/HcalDetId.cc (not yet available in CMSSW_2_1_9)
940 
941  const int ie(abs(ies));
942 
943  return (
944  (ip >= 1) && (ip <= 72) && (dp >= 1) && (ie >= 1) &&
945  (((sd == HcalBarrel) && (((ie <= 14) && (dp == 1)) || (((ie == 15) || (ie == 16)) && (dp <= 2)))) ||
946  ((sd == HcalEndcap) &&
947  (((ie == 16) && (dp == 3)) || ((ie == 17) && (dp == 1)) || ((ie >= 18) && (ie <= 20) && (dp <= 2)) ||
948  ((ie >= 21) && (ie <= 26) && (dp <= 2) && (ip % 2 == 1)) ||
949  ((ie >= 27) && (ie <= 28) && (dp <= 3) && (ip % 2 == 1)) || ((ie == 29) && (dp <= 2) && (ip % 2 == 1)))) ||
950  ((sd == HcalOuter) && (ie <= 15) && (dp == 4)) ||
951  ((sd == HcalForward) && (dp <= 2) &&
952  (((ie >= 29) && (ie <= 39) && (ip % 2 == 1)) || ((ie >= 40) && (ie <= 41) && (ip % 4 == 3))))));
953 
954  } // bool validDetId(HcalSubdetector sd, int ies, int ip, int dp)
955 
956  // Sets eta, phi labels for 'summary' eta-phi plots (identical to Depth 1 Eta-Phi labelling)
957 
958  inline void SetEtaPhiLabels(TH2F& h) {
959  std::stringstream label;
960  for (int i = -41; i <= -29; i = i + 2) {
961  label << i;
962  h.GetXaxis()->SetBinLabel(i + 42, label.str().c_str());
963  label.str("");
964  }
965  h.GetXaxis()->SetBinLabel(14, "-29HE");
966 
967  // offset by one for HE
968  for (int i = -27; i <= 27; i = i + 2) {
969  label << i;
970  h.GetXaxis()->SetBinLabel(i + 43, label.str().c_str());
971  label.str("");
972  }
973  h.GetXaxis()->SetBinLabel(72, "29HE");
974  for (int i = 29; i <= 41; i = i + 2) {
975  label << i;
976  h.GetXaxis()->SetBinLabel(i + 44, label.str().c_str());
977  label.str("");
978  }
979  return;
980  }
981 
982  // Fill Unphysical bins in histograms
983  inline void FillUnphysicalHEHFBins(std::vector<TH2F>& hh) {
984  int ieta = 0;
985  int iphi = 0;
986  // First 2 depths have 5-10-20 degree corrections
987  for (unsigned int d = 0; d < 3; ++d) {
988  //BUG CAN BE HERE:
989  //if (hh[d] != 0) continue;
990 
991  for (int eta = 0; eta < hh[d].GetNbinsX(); ++eta) {
992  ieta = CalcIeta(eta, d + 1);
993  if (ieta == -9999 || abs(ieta) < 21)
994  continue;
995  for (int phi = 0; phi < hh[d].GetNbinsY(); ++phi) {
996  iphi = phi + 1;
997  if (iphi % 2 == 1 && abs(ieta) < 40 && iphi < 73) {
998  hh[d].SetBinContent(eta + 1, iphi + 1, hh[d].GetBinContent(eta + 1, iphi));
999  }
1000  // last two eta strips span 20 degrees in phi
1001  // Fill the phi cell above iphi, and the 2 below it
1002  else if (abs(ieta) > 39 && iphi % 4 == 3 && iphi < 73) {
1003  //ieta=40, iphi=3 covers iphi 3,4,5,6
1004  hh[d].SetBinContent(eta + 1, (iphi) % 72 + 1, hh[d].GetBinContent(eta + 1, iphi));
1005  hh[d].SetBinContent(eta + 1, (iphi + 1) % 72 + 1, hh[d].GetBinContent(eta + 1, iphi));
1006  hh[d].SetBinContent(eta + 1, (iphi + 2) % 72 + 1, hh[d].GetBinContent(eta + 1, iphi));
1007  }
1008  } // for (int phi...)
1009  } // for (int eta...)
1010  } // for (int d=0;...)
1011  // no corrections needed for HO (depth 4)
1012  return;
1013  } // FillUnphysicalHEHFBins(MonitorElement* hh)
1014 
1015  //Fill unphysical bins for single ME
1016  inline void FillUnphysicalHEHFBins(TH2F& hh) {
1017  // Fills unphysical HE/HF bins for Summary Histogram
1018  // Summary Histogram is binned with the same binning as the Depth 1 EtaPhiHists
1019 
1020  //CAN BE BUG HERE:
1021  //if (hh==0) return;
1022 
1023  int ieta = 0;
1024  int iphi = 0;
1025  int etabins = hh.GetNbinsX();
1026  int phibins = hh.GetNbinsY();
1027  float binval = 0;
1028  for (int eta = 0; eta < etabins; ++eta) // loop over eta bins
1029  {
1030  ieta = CalcIeta(eta, 1);
1031  if (ieta == -9999 || abs(ieta) < 21)
1032  continue; // ignore etas that don't exist, or that have 5 degree phi binning
1033 
1034  for (int phi = 0; phi < phibins; ++phi) {
1035  iphi = phi + 1;
1036  if (iphi % 2 == 1 && abs(ieta) < 40 && iphi < 73) // 10 degree phi binning condition
1037  {
1038  binval = hh.GetBinContent(eta + 1, iphi);
1039  hh.SetBinContent(eta + 1, iphi + 1, binval);
1040  } // if (iphi%2==1...)
1041  else if (abs(ieta) > 39 && iphi % 4 == 3 && iphi < 73) // 20 degree phi binning condition
1042  {
1043  // Set last two eta strips where each cell spans 20 degrees in phi
1044  // Set next phi cell above iphi, and 2 cells below the actual cell
1045  hh.SetBinContent(eta + 1, (iphi) % 72 + 1, hh.GetBinContent(eta + 1, iphi));
1046  hh.SetBinContent(eta + 1, (iphi + 1) % 72 + 1, hh.GetBinContent(eta + 1, iphi));
1047  hh.SetBinContent(eta + 1, (iphi + 2) % 72 + 1, hh.GetBinContent(eta + 1, iphi));
1048  } // else if (abs(ieta)>39 ...)
1049  } // for (int phi=0;phi<72;++phi)
1050 
1051  } // for (int eta=0; eta< (etaBins_-2);++eta)
1052 
1053  return;
1054  } // FillUnphysicalHEHFBins(std::vector<MonitorElement*> &hh)
1055 
1056  // special fill call based on detid -- eventually will need special treatment
1057  inline void Fill(HcalDetId& id, double val /*=1*/, std::vector<TH2F>& depth) {
1058  // If in HF, need to shift by 1 bin (-1 bin lower in -HF, +1 bin higher in +HF)
1059  if (id.subdet() == HcalForward)
1060  depth[id.depth() - 1].Fill(id.ieta() < 0 ? id.ieta() - 1 : id.ieta() + 1, id.iphi(), val);
1061  else
1062  depth[id.depth() - 1].Fill(id.ieta(), id.iphi(), val);
1063  }
1064 
1065  inline void Reset(std::vector<TH2F>& depth) {
1066  for (unsigned int d = 0; d < depth.size(); d++)
1067  //BUG CAN BE HERE:
1068  //if(depth[d])
1069  depth[d].Reset();
1070  } // void Reset(void)
1071 
1072  inline void setup(std::vector<TH2F>& depth, std::string name, std::string units = "") {
1073  std::string unittitle, unitname;
1074  if (units.empty()) {
1075  unitname = units;
1076  unittitle = "No Units";
1077  } else {
1078  unitname = " " + units;
1079  unittitle = units;
1080  }
1081 
1082  // Push back depth plots
1084  //1. create first plot
1085  depth.push_back(TH2F(("HB HE HF Depth 1 " + name + unitname).c_str(),
1086  (name + " Depth 1 -- HB HE HF (" + unittitle + ")").c_str(),
1087  85,
1088  -42.5,
1089  42.5,
1090  72,
1091  0.5,
1092  72.5));
1093 
1094  //2.1 prepare second plot
1095  float ybins[73];
1096  for (int i = 0; i <= 72; i++)
1097  ybins[i] = (float)(i + 0.5);
1098  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,
1099  -30.5, -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5, -19.5,
1100  -18.5, -17.5, -16.5, -15.5, -14.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
1101  21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5, 30.5, 31.5, 32.5,
1102  33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5, 40.5, 41.5, 42.5};
1103 
1104  //2.2 create second plot
1105  depth.push_back(TH2F(("HB HE HF Depth 2 " + name + unitname).c_str(),
1106  (name + " Depth 2 -- HB HE HF (" + unittitle + ")").c_str(),
1107  57,
1108  xbinsd2,
1109  72,
1110  ybins));
1111 
1112  //3.1 Set up variable-sized bins for HE depth 3 (MonitorElement also requires phi bins to be entered in array format)
1113  float xbins[] = {-28.5, -27.5, -26.5, -16.5, -15.5, 15.5, 16.5, 26.5, 27.5, 28.5};
1114  //3.2
1115  depth.push_back(TH2F(("HE Depth 3 " + name + unitname).c_str(),
1116  (name + " Depth 3 -- HE (" + unittitle + ")").c_str(),
1117  // Use variable-sized eta bins
1118  9,
1119  xbins,
1120  72,
1121  ybins));
1122 
1123  //4.1 HO bins are fixed width, but cover a smaller eta range (-15 -> 15)
1124  depth.push_back(TH2F(("HO Depth 4 " + name + unitname).c_str(),
1125  (name + " Depth 4 -- HO (" + unittitle + ")").c_str(),
1126  31,
1127  -15.5,
1128  15.5,
1129  72,
1130  0.5,
1131  72.5));
1132 
1133  for (unsigned int i = 0; i < depth.size(); ++i)
1134  depth[i].Draw("colz");
1135 
1136  setBinLabels(depth); // set axis titles, special bins
1137  }
1138 
1139  inline void fillOneGain(std::vector<TH2F>& graphData,
1140  HcalGains::tAllContWithNames& allContainers,
1141  std::string name,
1142  int id,
1143  std::string units = "") {
1144  setup(graphData, name);
1145 
1146  std::stringstream x;
1147  // Change the titles of each individual histogram
1148  for (unsigned int d = 0; d < graphData.size(); ++d) {
1149  graphData[d].Reset();
1150  x << "Gain " << id << " for HCAL depth " << d + 1;
1151 
1152  //BUG CAN BE HERE:
1153  //if (ChannelStatus->depth[d])
1154  graphData[d].SetTitle(
1155  x.str()
1156  .c_str()); // replace "setTitle" with "SetTitle", since you are using TH2F objects instead of MonitorElements
1157  x.str("");
1158  }
1159 
1160  HcalDetId hcal_id;
1161  int ieta, depth, iphi;
1162 
1163  //main loop
1164  // get all containers with names
1165  //HcalGains::tAllContWithNames allContainers = object().getAllContainers();
1166 
1167  //ITERATORS AND VALUES:
1168  HcalGains::tAllContWithNames::const_iterator iter;
1169  std::vector<HcalGain>::const_iterator contIter;
1170  float gain = 0.0;
1171 
1172  //Run trough given id gain:
1173  int i = id;
1174 
1175  //run trough all pair containers
1176  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter) {
1177  //Run trough all values:
1178  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter) {
1179  hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
1180 
1181  depth = hcal_id.depth();
1182  if (depth < 1 || depth > 4)
1183  continue;
1184 
1185  ieta = hcal_id.ieta();
1186  iphi = hcal_id.iphi();
1187 
1188  if (hcal_id.subdet() == HcalForward)
1189  ieta > 0 ? ++ieta : --ieta;
1190 
1191  //GET VALUE:
1192  gain = (*contIter).getValue(i);
1193  //logstatus = log2(1.*channelBits)+1;
1194 
1195  //FILLING GOES HERE:
1196  graphData[depth - 1].Fill(ieta, iphi, gain);
1197 
1198  //FOR DEBUGGING:
1199  //std::cout << "ieta: " << ieta << "; iphi: " << iphi << "; logstatus: " << logstatus << "; channelBits: " << channelBits<< std::endl;
1200  }
1201  }
1202  }
1203 
1204  //FillUnphysicalHEHFBins(graphData);
1205  //return ("kasdasd");
1206 
1207  class ADataRepr //Sample base class for c++ inheritance tutorial
1208  {
1209  public:
1210  ADataRepr(unsigned int d) : m_total(d){};
1211  virtual ~ADataRepr(){};
1212  unsigned int nr, id;
1213  std::stringstream filename, rootname, plotname;
1214 
1215  void fillOneGain(std::vector<TH2F>& graphData, std::string units = "") {
1216  std::stringstream ss("");
1217 
1218  if (m_total == 1)
1219  ss << rootname.str() << " for HCAL depth ";
1220  else
1221  ss << rootname.str() << nr << " for HCAL depth ";
1222 
1223  setup(graphData, ss.str());
1224 
1225  // Change the titles of each individual histogram
1226  for (unsigned int d = 0; d < graphData.size(); ++d) {
1227  graphData[d].Reset();
1228 
1229  ss.str("");
1230  if (m_total == 1)
1231  ss << plotname.str() << " for HCAL depth " << d + 1;
1232  else
1233  ss << plotname.str() << nr << " for HCAL depth " << d + 1;
1234 
1235  //BUG CAN BE HERE:
1236  //if (ChannelStatus->depth[d])
1237  graphData[d].SetTitle(
1238  ss.str()
1239  .c_str()); // replace "setTitle" with "SetTitle", since you are using TH2F objects instead of MonitorElements
1240  ss.str("");
1241  }
1242  //overload this function:
1243  doFillIn(graphData);
1244 
1245  FillUnphysicalHEHFBins(graphData);
1246 
1247  ss.str("");
1248  if (m_total == 1)
1249  ss << filename.str() << ".png";
1250  else
1251  ss << filename.str() << nr << ".png";
1252  draw(graphData, ss.str());
1253  //FOR DEBUGGING:
1254  //std::cout << "ieta: " << ieta << "; iphi: " << iphi << "; logstatus: " << logstatus << "; channelBits: " << channelBits<< std::endl;
1255  }
1256 
1257  protected:
1258  unsigned int m_total;
1260  int ieta, depth, iphi;
1261 
1262  virtual void doFillIn(std::vector<TH2F>& graphData) = 0;
1263 
1264  private:
1265  void draw(std::vector<TH2F>& graphData, std::string filename) {
1266  //Drawing...
1267  // use David's palette
1268  gStyle->SetPalette(1);
1269  const Int_t NCont = 999;
1270  gStyle->SetNumberContours(NCont);
1271  TCanvas canvas("CC map", "CC map", 840, 369 * 4);
1272 
1273  TPad pad1("pad1", "pad1", 0.0, 0.75, 1.0, 1.0);
1274  pad1.Draw();
1275  TPad pad2("pad2", "pad2", 0.0, 0.5, 1.0, 0.75);
1276  pad2.Draw();
1277  TPad pad3("pad3", "pad3", 0.0, 0.25, 1.0, 0.5);
1278  pad3.Draw();
1279  TPad pad4("pad4", "pad4", 0.0, 0.0, 1.0, 0.25);
1280  pad4.Draw();
1281 
1282  pad1.cd();
1283  graphData[0].SetStats(false);
1284  graphData[0].Draw("colz");
1285 
1286  pad2.cd();
1287  graphData[1].SetStats(false);
1288  graphData[1].Draw("colz");
1289 
1290  pad3.cd();
1291  graphData[2].SetStats(false);
1292  graphData[2].Draw("colz");
1293 
1294  pad4.cd();
1295  graphData[3].SetStats(false);
1296  graphData[3].Draw("colz");
1297 
1298  canvas.SaveAs(filename.c_str());
1299  }
1300 
1301  void setup(std::vector<TH2F>& depth, std::string name, std::string units = "") {
1302  std::string unittitle, unitname;
1303  if (units.empty()) {
1304  unitname = units;
1305  unittitle = "No Units";
1306  } else {
1307  unitname = " " + units;
1308  unittitle = units;
1309  }
1310 
1311  // Push back depth plots
1313  //1. create first plot
1314  depth.push_back(TH2F(("HB HE HF Depth 1 " + name + unitname).c_str(),
1315  (name + " Depth 1 -- HB HE HF (" + unittitle + ")").c_str(),
1316  85,
1317  -42.5,
1318  42.5,
1319  72,
1320  0.5,
1321  72.5));
1322 
1323  //2.1 prepare second plot
1324  float ybins[73];
1325  for (int i = 0; i <= 72; i++)
1326  ybins[i] = (float)(i + 0.5);
1327  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,
1328  -30.5, -29.5, -28.5, -27.5, -26.5, -25.5, -24.5, -23.5, -22.5, -21.5, -20.5, -19.5,
1329  -18.5, -17.5, -16.5, -15.5, -14.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5,
1330  21.5, 22.5, 23.5, 24.5, 25.5, 26.5, 27.5, 28.5, 29.5, 30.5, 31.5, 32.5,
1331  33.5, 34.5, 35.5, 36.5, 37.5, 38.5, 39.5, 40.5, 41.5, 42.5};
1332 
1333  //2.2 create second plot
1334  depth.push_back(TH2F(("HB HE HF Depth 2 " + name + unitname).c_str(),
1335  (name + " Depth 2 -- HB HE HF (" + unittitle + ")").c_str(),
1336  57,
1337  xbinsd2,
1338  72,
1339  ybins));
1340 
1341  //3.1 Set up variable-sized bins for HE depth 3 (MonitorElement also requires phi bins to be entered in array format)
1342  float xbins[] = {-28.5, -27.5, -26.5, -16.5, -15.5, 15.5, 16.5, 26.5, 27.5, 28.5};
1343  //3.2
1344  depth.push_back(TH2F(("HE Depth 3 " + name + unitname).c_str(),
1345  (name + " Depth 3 -- HE (" + unittitle + ")").c_str(),
1346  // Use variable-sized eta bins
1347  9,
1348  xbins,
1349  72,
1350  ybins));
1351 
1352  //4.1 HO bins are fixed width, but cover a smaller eta range (-15 -> 15)
1353  depth.push_back(TH2F(("HO Depth 4 " + name + unitname).c_str(),
1354  (name + " Depth 4 -- HO (" + unittitle + ")").c_str(),
1355  31,
1356  -15.5,
1357  15.5,
1358  72,
1359  0.5,
1360  72.5));
1361 
1362  for (unsigned int i = 0; i < depth.size(); ++i)
1363  depth[i].Draw("colz");
1364 
1365  setBinLabels(depth); // set axis titles, special bins
1366  }
1367 
1368  //functions for making plot:
1369  void setBinLabels(std::vector<TH2F>& depth) {
1370  // Set labels for all depth histograms
1371  for (unsigned int i = 0; i < depth.size(); ++i) {
1372  depth[i].SetXTitle("i#eta");
1373  depth[i].SetYTitle("i#phi");
1374  }
1375 
1376  std::stringstream label;
1377 
1378  // set label on every other bin
1379  for (int i = -41; i <= -29; i = i + 2) {
1380  label << i;
1381  depth[0].GetXaxis()->SetBinLabel(i + 42, label.str().c_str());
1382  depth[1].GetXaxis()->SetBinLabel(i + 42, label.str().c_str());
1383  label.str("");
1384  }
1385  depth[0].GetXaxis()->SetBinLabel(14, "-29HE");
1386  depth[1].GetXaxis()->SetBinLabel(14, "-29HE");
1387 
1388  // offset by one for HE
1389  for (int i = -27; i <= 27; i = i + 2) {
1390  label << i;
1391  depth[0].GetXaxis()->SetBinLabel(i + 43, label.str().c_str());
1392  label.str("");
1393  }
1394  depth[0].GetXaxis()->SetBinLabel(72, "29HE");
1395  for (int i = 29; i <= 41; i = i + 2) {
1396  label << i;
1397  depth[0].GetXaxis()->SetBinLabel(i + 44, label.str().c_str());
1398  label.str("");
1399  }
1400  for (int i = 16; i <= 28; i = i + 2) {
1401  label << i - 43;
1402  depth[1].GetXaxis()->SetBinLabel(i, label.str().c_str());
1403  label.str("");
1404  }
1405  depth[1].GetXaxis()->SetBinLabel(29, "NULL");
1406  for (int i = 15; i <= 27; i = i + 2) {
1407  label << i;
1408  depth[1].GetXaxis()->SetBinLabel(i + 15, label.str().c_str());
1409  label.str("");
1410  }
1411 
1412  depth[1].GetXaxis()->SetBinLabel(44, "29HE");
1413  for (int i = 29; i <= 41; i = i + 2) {
1414  label << i;
1415  depth[1].GetXaxis()->SetBinLabel(i + 16, label.str().c_str());
1416  label.str("");
1417  }
1418 
1419  // HE depth 3 labels;
1420  depth[2].GetXaxis()->SetBinLabel(1, "-28");
1421  depth[2].GetXaxis()->SetBinLabel(2, "-27");
1422  depth[2].GetXaxis()->SetBinLabel(3, "Null");
1423  depth[2].GetXaxis()->SetBinLabel(4, "-16");
1424  depth[2].GetXaxis()->SetBinLabel(5, "Null");
1425  depth[2].GetXaxis()->SetBinLabel(6, "16");
1426  depth[2].GetXaxis()->SetBinLabel(7, "Null");
1427  depth[2].GetXaxis()->SetBinLabel(8, "27");
1428  depth[2].GetXaxis()->SetBinLabel(9, "28");
1429  }
1430  };
1431 } // namespace HcalObjRepresent
1432 #endif
std::vector< std::string > HcalEtaPhiHistNames()
void Divide(HcalDataContainer *dataCont2)
void SetEtaPhiLabels(TH2F &h)
const double xbins[]
void Subtract(HcalDataContainer *dataCont2)
const std::vector< std::pair< std::string, std::vector< Item > > > getAllItems()
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)
bool isHE(int etabin, int depth)
void drawTable(int nbRows, int nbColumns)
string newName
Definition: mps_merge.py:86
std::tuple< int, int, int > Coord
std::string IntToBinary(unsigned int number)
void setTopoModeFromValConts(bool throwOnFail=false)
bool isHB(int etabin, int depth)
static std::string to_string(const XMLCh *ch)
void FillCanv(TCanvas *canvas, std::string subDetName, int startDepth=1, int startCanv=1, std::string plotForm="2DHist")
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
char const * label
const int binmapd3[]
std::map< std::string, int > subDetDepths_
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
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
std::map< Coord, Item > tHcalValCont
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
const bool isBitSet(unsigned int bitnumber, unsigned int status)
HcalSubdetector
Definition: HcalAssistant.h:31
TCanvas * getCanvasAll(std::string profile="2DHist")
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void draw(std::vector< TH2F > &graphData, std::string filename)
key
prepare the HTCondor submission files and eventually submit them
std::map< std::pair< std::string, int >, TH2F * > DepthMap
void fillOneGain(std::vector< TH2F > &graphData, std::string units="")
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > hh
Basic3DVector unit() const
d
Definition: ztail.py:151
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="")
std::string SciNotatStr(float num)
TH1D * GetProjection(TH2F *hist, std::string plotType, const char *newName, std::string subDetName, int depth)
HcalDataContainer(std::shared_ptr< Items > payload, unsigned int run)
Item * getItemFromValCont(std::string subDetName, int depth, int ieta, int iphi, bool throwOnFail)
bool isHF(int etabin, int depth)
void FillUnphysicalHEHFBins(std::vector< TH2F > &hh)
std::pair< float, float > GetRange(TH1 *hist)
virtual float getValue(const Item *item)
TString units(TString variable, Char_t axis)
def canvas(sub, attr)
Definition: svgfig.py:482
float x
bool isHO(int etabin, int depth)
void Reset(std::vector< TH2F > &depth)
tHcalValCont * getContFromString(std::string subDetString)
void setBinLabels(std::vector< TH2F > &depth)
std::map< std::string, std::string > units_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
cont
load Luminosity info ##
Definition: generateEDF.py:620
std::shared_ptr< Items > payload_
std::map< std::string, int > GetSubDetDepths()
const int binmapd2[]
std::string GetUnit(std::string type)
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164