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