CMS 3D CMS Logo

EcalGainRatios_PayloadInspector.cc
Go to the documentation of this file.
7 
8 // the data format of the condition to be inspected
10 
11 #include "TH2F.h"
12 #include "TCanvas.h"
13 #include "TLine.h"
14 #include "TStyle.h"
15 #include "TLatex.h"
16 #include "TPave.h"
17 #include "TPaveStats.h"
18 #include <string>
19 #include <fstream>
20 
21 namespace {
22  enum {kEBChannels = 61200, kEEChannels = 14648};
23  enum {MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360}; // barrel lower and upper bounds on eta and phi
24  enum {IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100}; // endcaps lower and upper bounds on x and y
25 
26  /******************************************
27  2d plot of ECAL GainRatios of 1 IOV
28  ******************************************/
29  class EcalGainRatiosPlot : public cond::payloadInspector::PlotImage<EcalGainRatios> {
30  public:
31  EcalGainRatiosPlot() : cond::payloadInspector::PlotImage<EcalGainRatios>("ECAL Gain Ratios - map ") {
32  setSingleIov( true );
33  }
34 
35  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
36  TH2F* barrel_12O6 = new TH2F("EB_12O6","EB gain 12/6",MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
37  TH2F* endc_p_12O6 = new TH2F("EE+_12O6","EE+ gain 12/6",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
38  TH2F* endc_m_12O6 = new TH2F("EE-_12O6","EE- gain 12/6",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
39  TH2F* barrel_6O1 = new TH2F("EB_6O1","EB gain 6/1",MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
40  TH2F* endc_p_6O1 = new TH2F("EE+_6O1","EE+ gain 6/1",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
41  TH2F* endc_m_6O1 = new TH2F("EE-_6O1","EE- gain 6/1",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
42  TH1F* b_12O6 = new TH1F("b_12O6","EB gain 12/6", 50, 1.8, 2.1);
43  TH1F* e_12O6 = new TH1F("e_12O6","EE gain 12/6", 50, 1.8, 2.1);
44  TH1F* b_6O1 = new TH1F("b_6O1","EB gain 6/1", 100, 5.3, 6.3);
45  TH1F* e_6O1 = new TH1F("e_6O1","EE gain 6/1", 100, 5.3, 6.3);
46 
47  auto iov = iovs.front();
48  std::shared_ptr<EcalGainRatios> payload = fetchPayload( std::get<1>(iov) );
49  unsigned int run = std::get<0>(iov);
50  if( payload.get() ){
51  // looping over the EB channels, via the dense-index, mapped into EBDetId's
52  for(int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
53  uint32_t rawid = EBDetId::unhashIndex(cellid);
54  Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
55  Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
56  if(eta > 0.) eta = eta - 0.5; // 0.5 to 84.5
57  else eta = eta + 0.5; // -84.5 to -0.5
58  barrel_12O6->Fill(phi, eta, (*payload)[rawid].gain12Over6());
59  barrel_6O1->Fill(phi, eta, (*payload)[rawid].gain6Over1());
60  b_12O6->Fill((*payload)[rawid].gain12Over6());
61  b_6O1->Fill((*payload)[rawid].gain6Over1());
62  } // loop over cellid
63 
64  // looping over the EE channels
65  for(int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
66  if(!EEDetId::validHashIndex(cellid)) continue;
67  uint32_t rawid = EEDetId::unhashIndex(cellid);
68  EEDetId myEEId(rawid);
69  if (myEEId.zside() == 1) {
70  endc_p_12O6->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain12Over6());
71  endc_p_6O1->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain6Over1());
72  }
73  else{
74  endc_m_12O6->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain12Over6());
75  endc_m_6O1->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain6Over1());
76  }
77  e_12O6->Fill((*payload)[rawid].gain12Over6());
78  e_6O1->Fill((*payload)[rawid].gain6Over1());
79  } // validDetId
80  } // if payload.get()
81  else return false;
82 
83  gStyle->SetPalette(1);
84  gStyle->SetOptStat(0);
85  TCanvas canvas("CC map","CC map",1680,1320);
86  TLatex t1;
87  t1.SetNDC();
88  t1.SetTextAlign(26);
89  t1.SetTextSize(0.05);
90  t1.DrawLatex(0.5, 0.96, Form("Ecal Gain Ratios, IOV %i", run));
91 
92  float xmi[3] = {0.0 , 0.22, 0.78};
93  float xma[3] = {0.22, 0.78, 1.00};
94  TPad*** pad = new TPad**[2];
95  for (int gId = 0; gId < 2; gId++) {
96  pad[gId] = new TPad*[3];
97  for (int obj = 0; obj < 3; obj++) {
98  float yma = 0.94 - (0.32 * gId);
99  float ymi = yma - 0.28;
100  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
101  xmi[obj], ymi, xma[obj], yma);
102  pad[gId][obj]->Draw();
103  }
104  }
105  TPad** pad1 = new TPad*[4];
106  for (int obj = 0; obj < 4; obj++) {
107  float xmi = 0.26 * obj;
108  float xma = xmi + 0.22;
109  pad1[obj] = new TPad(Form("p1_%i", obj),Form("p1_%i", obj),
110  xmi, 0.0, xma, 0.32);
111  pad1[obj]->Draw();
112  }
113 
114  float min12O6 = 1.8, max12O6 = 2.1, min6O1 = 5.3, max6O1 = 6.3;
115  pad[0][0]->cd();
116  DrawEE(endc_m_12O6, min12O6, max12O6);
117  endc_m_12O6->SetStats(false);
118  pad[0][1]->cd();
119  DrawEB(barrel_12O6, min12O6, max12O6);
120  barrel_12O6->SetStats(false);
121  pad[0][2]->cd();
122  DrawEE(endc_p_12O6, min12O6, max12O6);
123  endc_p_12O6->SetStats(false);
124  pad[1][0]->cd();
125  DrawEE(endc_m_6O1, min6O1, max6O1);
126  endc_m_6O1->SetStats(false);
127  pad[1][1]->cd();
128  DrawEB(barrel_6O1, min6O1, max6O1);
129  barrel_6O1->SetStats(false);
130  pad[1][2]->cd();
131  DrawEE(endc_p_6O1, min6O1, max6O1);
132  endc_p_6O1->SetStats(false);
133 
134  gStyle->SetOptStat(111110);
135  pad1[0]->cd();
136  b_12O6->Draw();
137  pad1[0]->Update();
138  TPaveStats *st = (TPaveStats*)b_12O6->FindObject("stats");
139  st->SetX1NDC(0.6); //new x start position
140  st->SetY1NDC(0.75); //new y start position
141  pad1[1]->cd();
142  e_12O6->Draw();
143  pad1[0]->Update();
144  st = (TPaveStats*)e_12O6->FindObject("stats");
145  st->SetX1NDC(0.6); //new x start position
146  st->SetY1NDC(0.75); //new y start position
147  pad1[2]->cd();
148  b_6O1->Draw();
149  pad1[0]->Update();
150  st = (TPaveStats*)b_6O1->FindObject("stats");
151  st->SetX1NDC(0.6); //new x start position
152  st->SetY1NDC(0.75); //new y start position
153  pad1[3]->cd();
154  e_6O1->Draw();
155  pad1[0]->Update();
156  st = (TPaveStats*)e_6O1->FindObject("stats");
157  st->SetX1NDC(0.6); //new x start position
158  st->SetY1NDC(0.75); //new y start position
159 
160  std::string ImageName(m_imageFileName);
161  canvas.SaveAs(ImageName.c_str());
162  return true;
163  }// fill method
164  };
165 
166  /**********************************************************
167  2d plot of ECAL GainRatios difference between 2 IOVs
168  **********************************************************/
169  class EcalGainRatiosDiff : public cond::payloadInspector::PlotImage<EcalGainRatios> {
170 
171  public:
172  EcalGainRatiosDiff() : cond::payloadInspector::PlotImage<EcalGainRatios>("ECAL Gain Ratios difference") {
173  setSingleIov(false);
174  }
175 
176  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
177  TH2F* barrel_12O6 = new TH2F("EB_12O6","EB gain 12/6 difference",MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
178  TH2F* endc_p_12O6 = new TH2F("EE+_12O6","EE+ gain 12/6 difference",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
179  TH2F* endc_m_12O6 = new TH2F("EE-_12O6","EE- gain 12/6 difference",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
180  TH2F* barrel_6O1 = new TH2F("EB_6O1","EB gain 6/1 difference",MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
181  TH2F* endc_p_6O1 = new TH2F("EE+_6O1","EE+ gain 6/1 difference",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
182  TH2F* endc_m_6O1 = new TH2F("EE-_6O1","EE- gain 6/1 difference",IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
183  TH1F* b_12O6 = new TH1F("b_12O6","EB gain 12/6 difference", 50, -0.1, 0.1);
184  TH1F* e_12O6 = new TH1F("e_12O6","EE gain 12/6 difference", 50, -0.1, 0.1);
185  TH1F* b_6O1 = new TH1F("b_6O1","EB gain 6/1 difference", 100, -0.1, 0.1);
186  TH1F* e_6O1 = new TH1F("e_6O1","EE gain 6/1 difference", 100, -0.1, 0.1);
187 
188  unsigned int run[2], irun = 0;
189  float gEB[3][kEBChannels], gEE[3][kEEChannels];
190  for ( auto const & iov: iovs) {
191  std::shared_ptr<EcalGainRatios> payload = fetchPayload( std::get<1>(iov) );
192  run[irun] = std::get<0>(iov);
193  if( payload.get() ){
194  // looping over the EB channels, via the dense-index, mapped into EBDetId's
195  for(int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) { // loop on EB cells
196  uint32_t rawid = EBDetId::unhashIndex(cellid);
197  if(irun == 0) {
198  gEB[0][cellid] = (*payload)[rawid].gain12Over6();
199  gEB[1][cellid] = (*payload)[rawid].gain6Over1();
200  }
201  else {
202  Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
203  Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
204  if(eta > 0.) eta = eta - 0.5; // 0.5 to 84.5
205  else eta = eta + 0.5; // -84.5 to -0.5
206  float diff = gEB[0][cellid] - (*payload)[rawid].gain12Over6();
207  barrel_12O6->Fill(phi, eta, diff);
208  b_12O6->Fill(diff);
209  diff = gEB[1][cellid] - (*payload)[rawid].gain6Over1();
210  barrel_6O1->Fill(phi, eta, diff);
211  b_6O1->Fill(diff);
212  }
213  } // loop over cellid
214 
215  // looping over the EE channels
216  for(int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
217  if(!EEDetId::validHashIndex(cellid)) continue;
218  uint32_t rawid = EEDetId::unhashIndex(cellid);
219  EEDetId myEEId(rawid);
220  if(irun == 0) {
221  gEE[0][cellid] = (*payload)[rawid].gain12Over6();
222  gEE[1][cellid] = (*payload)[rawid].gain6Over1();
223  }
224  else {
225  float diff1 = gEE[0][cellid] - (*payload)[rawid].gain12Over6();
226  float diff2 = gEE[1][cellid] - (*payload)[rawid].gain6Over1();
227  if (myEEId.zside() == 1) {
228  endc_p_12O6->Fill(myEEId.ix(), myEEId.iy(), diff1);
229  endc_p_6O1->Fill(myEEId.ix(), myEEId.iy(), diff2);
230  }
231  else{
232  endc_m_12O6->Fill(myEEId.ix(), myEEId.iy(), diff1);
233  endc_m_6O1->Fill(myEEId.ix(), myEEId.iy(), diff2);
234  }
235  e_12O6->Fill(diff1);
236  e_6O1->Fill(diff2);
237  }
238  } // loop over cellid
239  } // if payload.get()
240  else return false;
241  irun++;
242  } // loop over IOVs
243 
244  gStyle->SetPalette(1);
245  gStyle->SetOptStat(0);
246  TCanvas canvas("CC map","CC map",1680,1320);
247  TLatex t1;
248  t1.SetNDC();
249  t1.SetTextAlign(26);
250  t1.SetTextSize(0.05);
251  t1.DrawLatex(0.5, 0.96, Form("Ecal Gain Ratios, IOV %i - %i", run[1], run[0]));
252 
253  float xmi[3] = {0.0 , 0.22, 0.78};
254  float xma[3] = {0.22, 0.78, 1.00};
255  TPad*** pad = new TPad**[2];
256  for (int gId = 0; gId < 2; gId++) {
257  pad[gId] = new TPad*[3];
258  for (int obj = 0; obj < 3; obj++) {
259  float yma = 0.94 - (0.32 * gId);
260  float ymi = yma - 0.28;
261  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
262  xmi[obj], ymi, xma[obj], yma);
263  pad[gId][obj]->Draw();
264  }
265  }
266  TPad** pad1 = new TPad*[4];
267  for (int obj = 0; obj < 4; obj++) {
268  float xmi = 0.26 * obj;
269  float xma = xmi + 0.22;
270  pad1[obj] = new TPad(Form("p1_%i", obj),Form("p1_%i", obj),
271  xmi, 0.0, xma, 0.32);
272  pad1[obj]->Draw();
273  }
274 
275  float min12O6 = -0.1, max12O6 = 0.1, min6O1 = -0.1, max6O1 = 0.1;
276  pad[0][0]->cd();
277  DrawEE(endc_m_12O6, min12O6, max12O6);
278  endc_m_12O6->SetStats(false);
279  pad[0][1]->cd();
280  DrawEB(barrel_12O6, min12O6, max12O6);
281  barrel_12O6->SetStats(false);
282  pad[0][2]->cd();
283  DrawEE(endc_p_12O6, min12O6, max12O6);
284  endc_p_12O6->SetStats(false);
285  pad[1][0]->cd();
286  DrawEE(endc_m_6O1, min6O1, max6O1);
287  endc_m_6O1->SetStats(false);
288  pad[1][1]->cd();
289  DrawEB(barrel_6O1, min6O1, max6O1);
290  barrel_6O1->SetStats(false);
291  pad[1][2]->cd();
292  DrawEE(endc_p_6O1, min6O1, max6O1);
293  endc_p_6O1->SetStats(false);
294 
295  gStyle->SetOptStat(111110);
296  pad1[0]->cd();
297  b_12O6->Draw();
298  pad1[0]->Update();
299  TPaveStats *st = (TPaveStats*)b_12O6->FindObject("stats");
300  st->SetX1NDC(0.6); //new x start position
301  st->SetY1NDC(0.75); //new y start position
302  pad1[1]->cd();
303  e_12O6->Draw();
304  pad1[0]->Update();
305  st = (TPaveStats*)e_12O6->FindObject("stats");
306  st->SetX1NDC(0.6); //new x start position
307  st->SetY1NDC(0.75); //new y start position
308  pad1[2]->cd();
309  b_6O1->Draw();
310  pad1[0]->Update();
311  st = (TPaveStats*)b_6O1->FindObject("stats");
312  st->SetX1NDC(0.6); //new x start position
313  st->SetY1NDC(0.75); //new y start position
314  pad1[3]->cd();
315  e_6O1->Draw();
316  pad1[0]->Update();
317  st = (TPaveStats*)e_6O1->FindObject("stats");
318  st->SetX1NDC(0.6); //new x start position
319  st->SetY1NDC(0.75); //new y start position
320 
321  std::string ImageName(m_imageFileName);
322  canvas.SaveAs(ImageName.c_str());
323  return true;
324  }// fill method
325  };
326 } // close namespace
327 
328  // Register the classes as boost python plugin
330  PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosPlot);
331  PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosDiff);
332 }
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
static bool validHashIndex(int i)
Definition: EEDetId.h:239
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:481