CMS 3D CMS Logo

EcalWeightXtalGroups_PayloadInspector.cc
Go to the documentation of this file.
6 
7 // the data format of the condition to be inspected
9 
10 #include "TH2F.h"
11 #include "TCanvas.h"
12 #include "TStyle.h"
13 #include "TLine.h"
14 #include "TLatex.h"
15 
16 #include <string>
17 #include <memory>
18 #include <array>
19 
20 namespace {
21 
22  enum { kEBChannels = 61200, kEEChannels = 14648, kSides = 2, kRMS = 5, TEMPLATESAMPLES = 12 };
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 WeightXtal Groups of 1 IOV
28  *****************************************************/
29  class EcalWeightXtalGroupsPlot : public cond::payloadInspector::PlotImage<EcalWeightXtalGroups> {
30  public:
31  EcalWeightXtalGroupsPlot()
32  : cond::payloadInspector::PlotImage<EcalWeightXtalGroups>("Ecal Weight Xtal Groups - map ") {
33  setSingleIov(true);
34  }
35 
36  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
37  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
38  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
39  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
40 
41  auto iov = iovs.front();
42  std::shared_ptr<EcalWeightXtalGroups> payload = fetchPayload(std::get<1>(iov));
43  unsigned int run = std::get<0>(iov);
44 
45  if (payload.get()) {
46  if (payload->barrelItems().empty())
47  return false;
48 
49  for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
50  uint32_t rawid = EBDetId::unhashIndex(cellid);
51 
52  std::vector<EcalXtalGroupId>::const_iterator value_ptr = payload->find(rawid);
53  // unsigned int id()
54  if (value_ptr == payload->end())
55  continue; // cell absent from payload
56 
57  unsigned int weight = (unsigned int)((*value_ptr).id());
58  Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
59  Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
60 
61  if (eta > 0.)
62  eta = eta - 0.5; // 0.5 to 84.5
63  else
64  eta = eta + 0.5; // -84.5 to -0.5
65 
66  barrel->Fill(phi, eta, weight);
67  } // loop over cellid
68 
69  if (payload->endcapItems().empty())
70  return false;
71 
72  // looping over the EE channels
73  for (int iz = -1; iz < 2; iz = iz + 2) // -1 or +1
74  for (int iy = IY_MIN; iy < IY_MAX + IY_MIN; iy++)
75  for (int ix = IX_MIN; ix < IX_MAX + IX_MIN; ix++)
76  if (EEDetId::validDetId(ix, iy, iz)) {
77  EEDetId myEEId = EEDetId(ix, iy, iz, EEDetId::XYMODE);
78  uint32_t rawid = myEEId.rawId();
79 
80  std::vector<EcalXtalGroupId>::const_iterator value_ptr = payload->find(rawid);
81 
82  if (value_ptr == payload->end())
83  continue; // cell absent from payload
84 
85  unsigned int weight = (unsigned int)((*value_ptr).id());
86 
87  if (iz == 1)
88  endc_p->Fill(ix, iy, weight);
89  else
90  endc_m->Fill(ix, iy, weight);
91  } // validDetId
92  } // payload
93 
94  gStyle->SetPalette(1);
95  gStyle->SetOptStat(0);
96  TCanvas canvas("CC map", "CC map", 1600, 450);
97  TLatex t1;
98  t1.SetNDC();
99  t1.SetTextAlign(26);
100  t1.SetTextSize(0.05);
101  t1.DrawLatex(0.5, 0.96, Form("Ecal Weight Xtal Groups, IOV %i", run));
102 
103  float xmi[3] = {0.0, 0.24, 0.76};
104  float xma[3] = {0.24, 0.76, 1.00};
105  std::array<std::unique_ptr<TPad>, 3> pad;
106  for (int obj = 0; obj < 3; obj++) {
107  pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
108  pad[obj]->Draw();
109  }
110  // EcalDrawMaps ICMap;
111  pad[0]->cd();
112  // ICMap.DrawEE(endc_m, 0., 2.);
113  DrawEE(endc_m, 0., 2.5);
114  pad[1]->cd();
115  // ICMap.DrawEB(barrel, 0., 2.);
116  DrawEB(barrel, 0., 2.5);
117  pad[2]->cd();
118  // ICMap.DrawEE(endc_p, 0., 2.);
119  DrawEE(endc_p, 0., 2.5);
120 
121  std::string ImageName(m_imageFileName);
122  canvas.SaveAs(ImageName.c_str());
123  return true;
124  } // fill method
125  };
126 
127 } // namespace
128 
129 // Register the classes as boost python plugin
static const int XYMODE
Definition: EEDetId.h:335
Definition: weight.py:1
static const int kSides
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)
static const int MIN_HASH
Definition: EBDetId.h:149
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)