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