CMS 3D CMS Logo

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