CMS 3D CMS Logo

EcalIntercalibConstantsMC_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 MC of 1 IOV
40 
41  *******************************************************/
42 
43  // inherit from one of the predefined plot class: Histogram2D
44  class EcalIntercalibConstantsMCEBMap : public cond::payloadInspector::Histogram2D<EcalIntercalibConstantsMC> {
45  public:
46  EcalIntercalibConstantsMCEBMap()
47  : cond::payloadInspector::Histogram2D<EcalIntercalibConstantsMC>("ECAL Barrel Intercalib Constants MC- 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<EcalIntercalibConstantsMC> 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 
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 Intercalib 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 
87  } // if payload.get()
88  } // loop over IOV's (1 in this case)
89 
90  return true;
91 
92  } //fill method
93  };
94 
95  /*******************************************************
96 
97  2d histogram of ECAL EndCaps Intercalib Constants MC of 1 IOV
98 
99  *******************************************************/
100 
101  class EcalIntercalibConstantsMCEEMap : public cond::payloadInspector::Histogram2D<EcalIntercalibConstantsMC> {
102  private:
103  int EEhistSplit = 20;
104 
105  public:
106  EcalIntercalibConstantsMCEEMap()
107  : cond::payloadInspector::Histogram2D<EcalIntercalibConstantsMC>("ECAL Endcap Intercalib Constants MC- map ",
108  "ix",
109  EEhistXMax,
110  IX_MIN,
111  EEhistXMax + 1,
112  "iy",
113  IY_MAX,
114  IY_MIN,
115  IY_MAX + 1) {
116  Base::setSingleIov(true);
117  }
118 
119  bool fill() override {
120  auto tag = PlotBase::getTag<0>();
121  for (auto const& iov : tag.iovs) {
122  std::shared_ptr<EcalIntercalibConstantsMC> payload = Base::fetchPayload(std::get<1>(iov));
123  if (payload.get()) {
124  if (payload->endcapItems().empty())
125  return false;
126 
127  // set to -1 everywhwere
128  for (int ix = IX_MIN; ix < EEhistXMax + 1; ix++)
129  for (int iy = IY_MAX; iy < IY_MAX + 1; iy++)
130  fillWithValue(ix, iy, -1);
131 
132  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) { // loop on EE cells
133  if (EEDetId::validHashIndex(cellid)) {
134  uint32_t rawid = EEDetId::unhashIndex(cellid);
135  EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
136  if (value_ptr == payload->end())
137  continue; // cell absent from payload
138 
139  float weight = (float)(*value_ptr);
140  EEDetId myEEId(rawid);
141  if (myEEId.zside() == -1)
142  fillWithValue(myEEId.ix(), myEEId.iy(), weight);
143  else
144  fillWithValue(myEEId.ix() + IX_MAX + EEhistSplit, myEEId.iy(), weight);
145  } // validDetId
146  } // loop over cellid
147 
148  } // payload
149  } // loop over IOV's (1 in this case)
150  return true;
151  } // fill method
152  };
153 
154  /*************************************************
155  2d plot of ECAL IntercalibConstantsMC of 1 IOV
156  *************************************************/
157  class EcalIntercalibConstantsMCPlot : public cond::payloadInspector::PlotImage<EcalIntercalibConstantsMC> {
158  public:
159  EcalIntercalibConstantsMCPlot()
160  : cond::payloadInspector::PlotImage<EcalIntercalibConstantsMC>("ECAL Intercalib Constants MC - map ") {
161  setSingleIov(true);
162  }
163 
164  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
165  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
166  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
167  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
168 
169  auto iov = iovs.front();
170  std::shared_ptr<EcalIntercalibConstantsMC> payload = fetchPayload(std::get<1>(iov));
171  unsigned int run = std::get<0>(iov);
172 
173  if (payload.get()) {
174  if (payload->barrelItems().empty())
175  return false;
176 
177  fillEBMap_SingleIOV<EcalIntercalibConstantsMC>(payload, barrel);
178 
179  if (payload->endcapItems().empty())
180  return false;
181 
182  fillEEMap_SingleIOV<EcalIntercalibConstantsMC>(payload, endc_m, endc_p);
183 
184  } // payload
185 
186  gStyle->SetPalette(1);
187  gStyle->SetOptStat(0);
188  TCanvas canvas("CC map", "CC map", 1600, 450);
189  TLatex t1;
190  t1.SetNDC();
191  t1.SetTextAlign(26);
192  t1.SetTextSize(0.04);
193  t1.DrawLatex(0.5, 0.96, Form("Ecal IntercalibConstants MC, IOV %i", run));
194 
195  float xmi[3] = {0.0, 0.24, 0.76};
196  float xma[3] = {0.24, 0.76, 1.00};
197  TPad** pad = new TPad*;
198  for (int obj = 0; obj < 3; obj++) {
199  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
200  pad[obj]->Draw();
201  }
202  // EcalDrawMaps ICMap;
203  pad[0]->cd();
204  // ICMap.DrawEE(endc_m, 0., 2.);
205  DrawEE(endc_m, 0., 2.5);
206  pad[1]->cd();
207  // ICMap.DrawEB(barrel, 0., 2.);
208  DrawEB(barrel, 0., 2.5);
209  pad[2]->cd();
210  // ICMap.DrawEE(endc_p, 0., 2.);
211  DrawEE(endc_p, 0., 2.5);
212 
213  std::string ImageName(m_imageFileName);
214  canvas.SaveAs(ImageName.c_str());
215  return true;
216  } // fill method
217  };
218 
219  /*****************************************************************
220  2d plot of ECAL IntercalibConstantsMC difference between 2 IOVs
221  *****************************************************************/
222  class EcalIntercalibConstantsMCDiff : public cond::payloadInspector::PlotImage<EcalIntercalibConstantsMC> {
223  public:
224  EcalIntercalibConstantsMCDiff()
225  : cond::payloadInspector::PlotImage<EcalIntercalibConstantsMC>("ECAL Intercalib Constants MC difference ") {
226  setSingleIov(false);
227  }
228 
229  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
230  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
231  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
232  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
233  float pEBmin, pEEmin, pEBmax, pEEmax;
234  pEBmin = 10.;
235  pEEmin = 10.;
236  pEBmax = -10.;
237  pEEmax = -10.;
238 
239  unsigned int run[2], irun = 0;
240  float pEB[kEBChannels], pEE[kEEChannels];
241  for (auto const& iov : iovs) {
242  std::shared_ptr<EcalIntercalibConstantsMC> payload = fetchPayload(std::get<1>(iov));
243  run[irun] = std::get<0>(iov);
244 
245  if (payload.get()) {
246  if (payload->barrelItems().empty())
247  return false;
248 
249  fillEBMap_DiffIOV<EcalIntercalibConstantsMC>(payload, barrel, irun, pEB, pEBmin, pEBmax);
250 
251  if (payload->endcapItems().empty())
252  return false;
253 
254  fillEEMap_DiffIOV<EcalIntercalibConstantsMC>(payload, endc_m, endc_p, irun, pEE, pEEmin, pEEmax);
255 
256  } // payload
257  irun++;
258 
259  } // loop over IOVs
260 
261  gStyle->SetPalette(1);
262  gStyle->SetOptStat(0);
263  TCanvas canvas("CC map", "CC map", 1600, 450);
264  TLatex t1;
265  t1.SetNDC();
266  t1.SetTextAlign(26);
267  t1.SetTextSize(0.04);
268  t1.DrawLatex(0.5, 0.96, Form("Ecal IntercalibConstants MC Diff, IOV %i - %i", run[1], run[0]));
269 
270  float xmi[3] = {0.0, 0.24, 0.76};
271  float xma[3] = {0.24, 0.76, 1.00};
272  TPad** pad = new TPad*;
273 
274  for (int obj = 0; obj < 3; obj++) {
275  pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
276  pad[obj]->Draw();
277  }
278 
279  pad[0]->cd();
280  DrawEE(endc_m, pEEmin, pEEmax);
281  pad[1]->cd();
282  DrawEB(barrel, pEBmin, pEBmax);
283  pad[2]->cd();
284  DrawEE(endc_p, pEEmin, pEEmax);
285 
286  std::string ImageName(m_imageFileName);
287  canvas.SaveAs(ImageName.c_str());
288  return true;
289  } // fill method
290  };
291 
292  /*******************************************************
293  2d plot of Ecal Intercalib Constants MC Summary of 1 IOV
294  *******************************************************/
295  class EcalIntercalibConstantsMCSummaryPlot : public cond::payloadInspector::PlotImage<EcalIntercalibConstantsMC> {
296  public:
297  EcalIntercalibConstantsMCSummaryPlot()
298  : cond::payloadInspector::PlotImage<EcalIntercalibConstantsMC>("Ecal Intercalib Constants MC Summary - map ") {
299  setSingleIov(true);
300  }
301 
302  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
303  auto iov = iovs.front();
304  std::shared_ptr<EcalIntercalibConstantsMC> payload = fetchPayload(std::get<1>(iov));
305  unsigned int run = std::get<0>(iov);
306  TH2F* align;
307  int NbRows;
308 
309  if (payload.get()) {
310  NbRows = 2;
311  align = new TH2F("", "", 0, 0, 0, 0, 0, 0);
312 
313  float mean_x_EB = 0.0f;
314  float mean_x_EE = 0.0f;
315 
316  float rms_EB = 0.0f;
317  float rms_EE = 0.0f;
318 
319  int num_x_EB = 0;
320  int num_x_EE = 0;
321 
322  payload->summary(mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
324  align, "Ecal Intercalib Constants MC", mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
325 
326  } else
327  return false;
328 
329  gStyle->SetPalette(1);
330  gStyle->SetOptStat(0);
331  TCanvas canvas("CC map", "CC map", 1000, 1000);
332  TLatex t1;
333  t1.SetNDC();
334  t1.SetTextAlign(26);
335  t1.SetTextSize(0.04);
336  t1.SetTextColor(2);
337  t1.DrawLatex(0.5, 0.96, Form("Ecal Intercalib Constants MC Summary, IOV %i", run));
338 
339  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
340  pad->Draw();
341  pad->cd();
342  align->Draw("TEXT");
343 
344  drawTable(NbRows, 4);
345 
346  std::string ImageName(m_imageFileName);
347  canvas.SaveAs(ImageName.c_str());
348 
349  return true;
350  }
351  };
352 
353 } // namespace
354 
355 // Register the classes as boost python plugin
357  PAYLOAD_INSPECTOR_CLASS(EcalIntercalibConstantsMCEBMap);
358  PAYLOAD_INSPECTOR_CLASS(EcalIntercalibConstantsMCEEMap);
359  PAYLOAD_INSPECTOR_CLASS(EcalIntercalibConstantsMCPlot);
360  PAYLOAD_INSPECTOR_CLASS(EcalIntercalibConstantsMCDiff);
361  PAYLOAD_INSPECTOR_CLASS(EcalIntercalibConstantsMCSummaryPlot);
362 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
EcalIntercalibConstantsMC.h
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
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