CMS 3D CMS Logo

EcalTimeCalibConstants_PayloadInspector.cc
Go to the documentation of this file.
8 // the data format of the condition to be inspected
10 
11 #include "TH2F.h"
12 #include "TCanvas.h"
13 #include "TStyle.h"
14 #include "TLine.h"
15 #include "TLatex.h"
16 
17 #include <memory>
18 #include <sstream>
19 
20 namespace {
21 
22  enum { kEBChannels = 61200, kEEChannels = 14648 };
23  enum {
24  MIN_IETA = 1,
25  MIN_IPHI = 1,
26  MAX_IETA = 85,
27  MAX_IPHI = 360,
28  EBhistEtaMax = 171
29  }; // barrel lower and upper bounds on eta and phi
30  enum {
31  IX_MIN = 1,
32  IY_MIN = 1,
33  IX_MAX = 100,
34  IY_MAX = 100,
35  EEhistXMax = 220
36  }; // endcaps lower and upper bounds on x and y
37 
38  /*******************************************************
39 
40  2d histogram of ECAL barrel Time Calib Constants of 1 IOV
41 
42  *******************************************************/
43 
44  // inherit from one of the predefined plot class: Histogram2D
45  class EcalTimeCalibConstantsEBMap : public cond::payloadInspector::Histogram2D<EcalTimeCalibConstants> {
46  public:
47  EcalTimeCalibConstantsEBMap()
48  : cond::payloadInspector::Histogram2D<EcalTimeCalibConstants>("ECAL Barrel Time Calib Constants - map ",
49  "iphi",
50  MAX_IPHI,
51  MIN_IPHI,
52  MAX_IPHI + 1,
53  "ieta",
55  -MAX_IETA,
56  MAX_IETA + 1) {
57  Base::setSingleIov(true);
58  }
59 
60  // Histogram2D::fill (virtual) needs be overridden - the implementation should use fillWithValue
61  bool fill() override {
62  auto tag = PlotBase::getTag<0>();
63  for (auto const& iov : tag.iovs) {
64  std::shared_ptr<EcalTimeCalibConstants> payload = Base::fetchPayload(std::get<1>(iov));
65  if (payload.get()) {
66  // looping over the EB channels, via the dense-index, mapped into EBDetId's
67  if (payload->barrelItems().empty())
68  return false;
69  // set to -1 for ieta 0 (no crystal)
70  for (int iphi = MIN_IPHI; iphi < MAX_IPHI + 1; iphi++)
71  fillWithValue(iphi, 0, -1);
72 
73  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
74  uint32_t rawid = EBDetId::unhashIndex(cellid);
75 
76  // check the existence of ECAL Time Calib Constants, for a given ECAL barrel channel
78  if (value_ptr == payload->end())
79  continue; // cell absent from payload
80 
81  float weight = (float)(*value_ptr);
82 
83  // fill the Histogram2D here
84  fillWithValue((EBDetId(rawid)).iphi(), (EBDetId(rawid)).ieta(), weight);
85  } // loop over cellid
86  } // if payload.get()
87  } // loop over IOV's (1 in this case)
88 
89  return true;
90 
91  } //fill method
92  };
93 
94  /*******************************************************
95 
96  2d histogram of ECAL EndCaps Time Calib Constants of 1 IOV
97 
98  *******************************************************/
99 
100  class EcalTimeCalibConstantsEEMap : public cond::payloadInspector::Histogram2D<EcalTimeCalibConstants> {
101  private:
102  int EEhistSplit = 20;
103 
104  public:
105  EcalTimeCalibConstantsEEMap()
106  : cond::payloadInspector::Histogram2D<EcalTimeCalibConstants>("ECAL Endcap Time Calib Constants - map ",
107  "ix",
108  EEhistXMax,
109  IX_MIN,
110  EEhistXMax + 1,
111  "iy",
112  IY_MAX,
113  IY_MIN,
114  IY_MAX + 1) {
115  Base::setSingleIov(true);
116  }
117 
118  bool fill() override {
119  auto tag = PlotBase::getTag<0>();
120  for (auto const& iov : tag.iovs) {
121  std::shared_ptr<EcalTimeCalibConstants> payload = Base::fetchPayload(std::get<1>(iov));
122  if (payload.get()) {
123  if (payload->endcapItems().empty())
124  return false;
125 
126  // set to -1 everywhwere
127  for (int ix = IX_MIN; ix < EEhistXMax + 1; ix++)
128  for (int iy = IY_MAX; iy < IY_MAX + 1; iy++)
129  fillWithValue(ix, iy, -1);
130 
131  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) { // loop on EE cells
132  if (EEDetId::validHashIndex(cellid)) {
133  uint32_t rawid = EEDetId::unhashIndex(cellid);
134  EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
135  if (value_ptr == payload->end())
136  continue; // cell absent from payload
137 
138  float weight = (float)(*value_ptr);
139  EEDetId myEEId(rawid);
140  if (myEEId.zside() == -1)
141  fillWithValue(myEEId.ix(), myEEId.iy(), weight);
142  else
143  fillWithValue(myEEId.ix() + IX_MAX + EEhistSplit, myEEId.iy(), weight);
144  } // validDetId
145  } // loop over cellid
146 
147  } // payload
148  } // loop over IOV's (1 in this case)
149  return true;
150  } // fill method
151  };
152 
153  /*************************************************
154  2d plot of Ecal Time Calib Constants of 1 IOV
155  *************************************************/
156  class EcalTimeCalibConstantsPlot : public cond::payloadInspector::PlotImage<EcalTimeCalibConstants> {
157  public:
158  EcalTimeCalibConstantsPlot()
159  : cond::payloadInspector::PlotImage<EcalTimeCalibConstants>("Ecal Time Calib Constants- map ") {
160  setSingleIov(true);
161  }
162 
163  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
164  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
165  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
166  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
167 
168  auto iov = iovs.front();
169  std::shared_ptr<EcalTimeCalibConstants> payload = fetchPayload(std::get<1>(iov));
170  unsigned int run = std::get<0>(iov);
171 
172  if (payload.get()) {
173  if (payload->barrelItems().empty())
174  return false;
175 
176  fillEBMap_SingleIOV<EcalTimeCalibConstants>(payload, barrel);
177 
178  if (payload->endcapItems().empty())
179  return false;
180 
181  fillEEMap_SingleIOV<EcalTimeCalibConstants>(payload, endc_m, endc_p);
182 
183  } // payload
184 
185  gStyle->SetPalette(1);
186  gStyle->SetOptStat(0);
187  TCanvas canvas("CC map", "CC map", 1600, 450);
188  TLatex t1;
189  t1.SetNDC();
190  t1.SetTextAlign(26);
191  t1.SetTextSize(0.05);
192  t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Constants, IOV %i", run));
193 
194  float xmi[3] = {0.0, 0.24, 0.76};
195  float xma[3] = {0.24, 0.76, 1.00};
196  TPad** pad = new TPad*;
197  for (int obj = 0; obj < 3; obj++) {
198  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
199  pad[obj]->Draw();
200  }
201  // EcalDrawMaps ICMap;
202  pad[0]->cd();
203  // ICMap.DrawEE(endc_m, 0., 2.);
204  DrawEE(endc_m, -2.5, 2.5);
205  pad[1]->cd();
206  // ICMap.DrawEB(barrel, 0., 2.);
207  DrawEB(barrel, -2.5, 2.5);
208  pad[2]->cd();
209  // ICMap.DrawEE(endc_p, 0., 2.);
210  DrawEE(endc_p, -2.5, 2.5);
211 
212  std::string ImageName(m_imageFileName);
213  canvas.SaveAs(ImageName.c_str());
214  return true;
215  } // fill method
216  };
217 
218  /*****************************************************************
219  2d plot of Ecal Time Calib Constants difference between 2 IOVs
220  *****************************************************************/
221  class EcalTimeCalibConstantsDiff : public cond::payloadInspector::PlotImage<EcalTimeCalibConstants> {
222  public:
223  EcalTimeCalibConstantsDiff()
224  : cond::payloadInspector::PlotImage<EcalTimeCalibConstants>("Ecal Time Calib Constants difference ") {
225  setSingleIov(false);
226  }
227 
228  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
229  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
230  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
231  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
232  float pEBmin, pEEmin, pEBmax, pEEmax;
233  pEBmin = 10.;
234  pEEmin = 10.;
235  pEBmax = -10.;
236  pEEmax = -10.;
237 
238  unsigned int run[2], irun = 0;
239  float pEB[kEBChannels], pEE[kEEChannels];
240  for (auto const& iov : iovs) {
241  std::shared_ptr<EcalTimeCalibConstants> payload = fetchPayload(std::get<1>(iov));
242  run[irun] = std::get<0>(iov);
243 
244  if (payload.get()) {
245  if (payload->barrelItems().empty())
246  return false;
247 
248  fillEBMap_DiffIOV<EcalTimeCalibConstants>(payload, barrel, irun, pEB, pEBmin, pEBmax);
249 
250  if (payload->endcapItems().empty())
251  return false;
252 
253  fillEEMap_DiffIOV<EcalTimeCalibConstants>(payload, endc_m, endc_p, irun, pEE, pEEmin, pEEmax);
254 
255  } // payload
256  irun++;
257 
258  } // loop over IOVs
259 
260  gStyle->SetPalette(1);
261  gStyle->SetOptStat(0);
262  TCanvas canvas("CC map", "CC map", 1600, 450);
263  TLatex t1;
264  t1.SetNDC();
265  t1.SetTextAlign(26);
266  t1.SetTextSize(0.05);
267  t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Constants Diff, IOV %i - %i", run[1], run[0]));
268 
269  float xmi[3] = {0.0, 0.24, 0.76};
270  float xma[3] = {0.24, 0.76, 1.00};
271  TPad** pad = new TPad*;
272 
273  for (int obj = 0; obj < 3; obj++) {
274  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
275  pad[obj]->Draw();
276  }
277 
278  pad[0]->cd();
279  DrawEE(endc_m, pEEmin, pEEmax);
280  pad[1]->cd();
281  DrawEB(barrel, pEBmin, pEBmax);
282  pad[2]->cd();
283  DrawEE(endc_p, pEEmin, pEEmax);
284 
285  std::string ImageName(m_imageFileName);
286  canvas.SaveAs(ImageName.c_str());
287  return true;
288  } // fill method
289  };
290 
291  /*******************************************************
292  2d plot of Ecal Time Calib Constants Summary of 1 IOV
293  *******************************************************/
294  class EcalTimeCalibConstantsSummaryPlot : public cond::payloadInspector::PlotImage<EcalTimeCalibConstants> {
295  public:
296  EcalTimeCalibConstantsSummaryPlot()
297  : cond::payloadInspector::PlotImage<EcalTimeCalibConstants>("Ecal Time Calib Constants Summary- map ") {
298  setSingleIov(true);
299  }
300 
301  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
302  auto iov = iovs.front();
303  std::shared_ptr<EcalTimeCalibConstants> payload = fetchPayload(std::get<1>(iov));
304  unsigned int run = std::get<0>(iov);
305  TH2F* align;
306  int NbRows;
307 
308  if (payload.get()) {
309  NbRows = 2;
310  align = new TH2F("", "", 0, 0, 0, 0, 0, 0);
311 
312  float mean_x_EB = 0.0f;
313  float mean_x_EE = 0.0f;
314 
315  float rms_EB = 0.0f;
316  float rms_EE = 0.0f;
317 
318  int num_x_EB = 0;
319  int num_x_EE = 0;
320 
321  payload->summary(mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
323  align, "Ecal Time Calib Constants", mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
324  } else
325  return false;
326 
327  gStyle->SetPalette(1);
328  gStyle->SetOptStat(0);
329  TCanvas canvas("CC map", "CC map", 1000, 1000);
330  TLatex t1;
331  t1.SetNDC();
332  t1.SetTextAlign(26);
333  t1.SetTextSize(0.04);
334  t1.SetTextColor(2);
335  t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Constants Summary, IOV %i", run));
336 
337  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
338  pad->Draw();
339  pad->cd();
340  align->Draw("TEXT");
341 
342  drawTable(NbRows, 4);
343 
344  std::string ImageName(m_imageFileName);
345  canvas.SaveAs(ImageName.c_str());
346 
347  return true;
348  }
349  };
350 
351 } // namespace
352 
353 // Register the classes as boost python plugin
355  PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibConstantsEBMap);
356  PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibConstantsEEMap);
357  PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibConstantsPlot);
358  PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibConstantsDiff);
359  PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibConstantsSummaryPlot);
360 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
EcalFloatCondObjectContainerUtils.h
Reference_intrackfit_cff.barrel
list barrel
Definition: Reference_intrackfit_cff.py:37
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
align
Definition: AlignableIndexer.h:30
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
mps_merge.weight
weight
Definition: mps_merge.py:88
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
cond::payloadInspector::Plot3D< PayloadType, float, float, float, IOV_M, 1 >::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:491
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
EcalTimeCalibConstants.h
EcalCondObjectContainer< float >
PayloadInspectorModule.h
DrawEE
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
fillTableWithSummary
void fillTableWithSummary(TH2F *&align, std::string title, const float &mean_x_EB, const float &rms_EB, const int &num_x_EB, const float &mean_x_EE, const float &rms_EE, const int &num_x_EE)
Definition: EcalFloatCondObjectContainerUtils.h:142
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
EEDetId::kSizeForDenseIndexing
Definition: EEDetId.h:329
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
DrawEB
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
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
cond::payloadInspector::Histogram2D
Definition: PayloadInspector.h:748
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
Time.h
IY_MIN
Definition: EcalFloatCondObjectContainerUtils.h:19
cond::payloadInspector::Histogram2D::fillWithValue
void fillWithValue(float xvalue, float yvalue, float weight=1)
Definition: PayloadInspector.h:787
cond::payloadInspector::PlotImage::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:840
MIN_IPHI
Definition: EcalFloatCondObjectContainerUtils.h:12
EEhistXMax
Definition: EcalFloatCondObjectContainerUtils.h:22
EEDetId::validHashIndex
static bool validHashIndex(int i)
Definition: EEDetId.h:239
EcalDrawUtils.h
EBhistEtaMax
Definition: EcalFloatCondObjectContainerUtils.h:15
writedatasetfile.run
run
Definition: writedatasetfile.py:27
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
drawTable
void drawTable(int nbRows, int nbColumns)
Definition: EcalDrawUtils.h:91
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:829
EBDetId::kSizeForDenseIndexing
Definition: EBDetId.h:155
EcalCondObjectContainer< float >::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
EBDetId::MIN_HASH
static const int MIN_HASH
Definition: EBDetId.h:149
kEBChannels
Definition: EcalFloatCondObjectContainerUtils.h:9
IX_MIN
Definition: EcalFloatCondObjectContainerUtils.h:18
weight
Definition: weight.py:1
cond::payloadInspector::Histogram2D::fill
bool fill() override
Definition: PayloadInspector.h:797
MAX_IETA
Definition: EcalFloatCondObjectContainerUtils.h:13