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