CMS 3D CMS Logo

HcalSiPMParameters_PayloadInspector.cc
Go to the documentation of this file.
6 
7 // the data format of the condition to be inspected
9 
10 #include "TH2F.h"
11 #include "TCanvas.h"
12 #include "TLine.h"
13 #include "TStyle.h"
14 #include "TLatex.h"
15 #include "TPave.h"
16 #include "TPaveStats.h"
17 #include <string>
18 #include <fstream>
19 #include <boost/algorithm/string/join.hpp>
20 
21 namespace {
22 
23  /********************************************
24  printing float values of reco paramters
25  *********************************************/
26  class HcalSiPMParametersSummary : public cond::payloadInspector::PlotImage<HcalSiPMParameters> {
27  public:
28  HcalSiPMParametersSummary() : cond::payloadInspector::PlotImage<HcalSiPMParameters>("HCAL SiPMParameter Summary") {
29  setSingleIov( true );
30  }
31 
32  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
33 
34 
35  auto iov = iovs.front();
36  float fcByPE, darkCurrent1, darkCurrent2, tempVal;
37  int type1, type2;
38  std::shared_ptr<HcalSiPMParameters> payload = fetchPayload( std::get<1>(iov) );
39  if(payload.get()) {
40 
41  std::string subDetName;
42  std::vector<HcalSiPMParameter> itemsVec;
43 
44 
45  //TODO: Abstract into a function that takes valMap as the argument
46 
47  TLatex label,val;
48  std::vector<float> line;
49  TLine* ll;
50  TLine* lr;
51  TLine* lt;
52  TLine* lb;
53  TCanvas* can = new TCanvas("SiPMParametersSummary","SiPMParametersSummary", 2000, 1680);
54  //can->cd();
55  //HcalObjRepresent::drawTable(2,2);
56  can->Divide(2,2,0,0);
57  int i = 1;
58 
59 
60  label.SetNDC();
61  label.SetTextAlign(26);
62  label.SetTextSize(0.05);
63  label.SetTextColor(2);
64  label.DrawLatex(0.5, 0.96,Form("Hcal SiPM Parameters"));
65 
66  for(std::pair< std::string, std::vector<HcalSiPMParameter> > cont : (*payload).getAllContainers()){
67  subDetName = std::get<0>(cont);
68  if(subDetName[0] != 'H' || subDetName == "HT") continue;
69  itemsVec = std::get<1>(cont);
70  type1 = type2 = fcByPE = darkCurrent1 = darkCurrent2 = -1.0;
71  for(HcalSiPMParameter par : itemsVec) {
72  HcalDetId detId = HcalDetId(par.rawId());
73  int iphi = detId.iphi();
74  int ieta = detId.ieta();
75  int depth = detId.depth();
76  //std::cout << "(subDet, eta, phi, depth) : type : DarkCurrent | (" << subDetName << ", " << std::to_string(ieta) << ", " << std::to_string(iphi) << ", " << std::to_string(depth) << ") : " << std::to_string(par.getType()) << " : " << std::to_string(par.getDarkCurrent()) << std::endl;
77  if(iphi==0 && ieta==0 && depth==0) continue;
78  fcByPE = par.getFCByPE();
79  tempVal = par.getDarkCurrent();
80  if(darkCurrent1 == -1.0) {
81  darkCurrent1 = tempVal;
82  type1 = par.getType();
83  }
84  else if(darkCurrent2 == -1.0 && par.getType() != type1){
85  darkCurrent2 = tempVal;
86  type2 = par.getType();
87  //if(fcByPE != -1) break;
88  }
89  }
90  if(type1 == -1) {
91  type1 = darkCurrent1 = 0;
92  }
93  if(type2 == -1) {
94  darkCurrent2 = darkCurrent1;
95  type2 = type1;
96  }
97 
98  //Fill Grid of subsystems
99  can->cd(i);
100  ll = new TLine(0,0,0,1);
101  ll->SetLineWidth(4);
102  ll->Draw();
103  lt = new TLine(0,1,1,1);
104  lt->SetLineWidth(4);
105  lt->Draw();
106  lb = new TLine(0,0,1,0);
107  lb->SetLineWidth(4);
108  lb->Draw();
109  lr = new TLine(1,0,1,1);
110  lr->SetLineWidth(4);
111  lr->Draw();
112 
113  //label subsystem
114  label.SetNDC();
115  label.SetTextAlign(26);
116  label.SetTextSize(0.15);
117  label.SetTextColor(2);
118  label.DrawLatex(0.5, 0.85, subDetName.c_str());
119 
120  //table filling
121  float startPosY = 0.75, endPosY = 0.2;
122  float startPosX = 0.10, endPosX = 0.8;
123  std::vector<float>::iterator linEle;
124  std::vector<std::string>::iterator linStrEle;
125  int j = 0;
126  float xDiff, yDiff;
127  // Header line
128  std::stringstream lbl1, lbl2;
129  lbl1 << "(Type " << std::to_string(type1) << ")";
130  lbl2 << "(Type " << std::to_string(type2) << ")";
131  std::vector<std::string> lblline = {"fcByPE", "Dark Current", "Dark Current"};
132  xDiff = (endPosX - startPosX)/(lblline.size()-1);
133  yDiff = (startPosY - endPosY);
134 
135  //printing header
136  label.SetTextAlign(12);
137  label.SetTextSize(0.05);
138  label.SetTextColor(1);
139  //ll = new TLine(startPosX -0.2*xDiff, startPosY, startPosX - 0.2*xDiff, startPosY - 0.5*yDiff);
140  //ll->Draw();
141  for(linStrEle = lblline.begin(); linStrEle != lblline.end(); ++linStrEle) {
142  ll = new TLine(startPosX + (j+0.5)*xDiff, startPosY, startPosX + (j+0.5)*xDiff, startPosY - 0.5*yDiff);
143  label.DrawLatex(startPosX + (j==0 ? -0.1 : (j-0.4))*xDiff , startPosY - 0.25*yDiff, (*linStrEle).c_str());
144  if(j==1) label.DrawLatex(startPosX + (j==0 ? -0.1 : (j-0.31))*xDiff , startPosY - 0.34*yDiff, (lbl1.str()).c_str());
145  if(j==2) label.DrawLatex(startPosX + (j==0 ? -0.1 : (j-0.31))*xDiff , startPosY - 0.34*yDiff, (lbl2.str()).c_str());
146  if(j<2)ll->Draw();
147  j++;
148  }
149  ll = new TLine(0,startPosY, 1, startPosY);
150  ll->Draw();
151  ll = new TLine(0,startPosY - 0.5 * yDiff, 1, startPosY - 0.5 * yDiff);
152  ll->Draw();
153 
154 
155  val.SetNDC();
156  val.SetTextAlign(26);
157  val.SetTextSize(0.055);
158  line = {fcByPE, darkCurrent1, darkCurrent2};
159  //ll = new TLine(startPosX -0.2*xDiff, startPosY - 0.5*yDiff, startPosX - 0.2*xDiff, startPosY - 1.5*yDiff);
160  //ll->Draw();
161  j = 0;
162 
163  for(linEle = line.begin(); linEle != line.end(); ++linEle) {
164  ll = new TLine(startPosX + (j+0.5)*xDiff, startPosY - 0.5*yDiff, startPosX + (j+0.5)*xDiff, startPosY - 1.5*yDiff);
165  val.DrawLatex(startPosX + j*xDiff , startPosY - yDiff, HcalObjRepresent::SciNotatStr((*linEle)).c_str());
166  if(j < 2){ ll->Draw(); }
167  j++;
168  }
169 
170 
171  i++;
172  }
173 
174 
175 
176 
177  std::string ImageName(m_imageFileName);
178  can->SaveAs(ImageName.c_str());
179  return false;
180  } else return false;
181  }// fill method
182  };
183 //TODO: Add a Change Summary?
184 
185 } // close namespace
186 
187  // Register the classes as boost python plugin
189  PAYLOAD_INSPECTOR_CLASS(HcalSiPMParametersSummary);
190 }
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
char const * label
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
int depth() const
get the tower depth
Definition: HcalDetId.h:166
int ieta() const
get the cell ieta
Definition: HcalDetId.h:159
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::string SciNotatStr(float num)
int iphi() const
get the cell iphi
Definition: HcalDetId.h:161
Definition: plugin.cc:24