CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ESIntercalibConstants_PayloadInspector.cc
Go to the documentation of this file.
4 
5 // the data format of the condition to be inspected
9 
10 #include <memory>
11 #include <sstream>
12 
13 #include "TStyle.h"
14 #include "TH2F.h"
15 #include "TCanvas.h"
16 #include "TLine.h"
17 #include "TLatex.h"
18 
19 namespace {
20  enum { kESChannels = 137216 };
21  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 40, IY_MAX = 40 }; // endcaps lower and upper bounds on x and y
22 
23  /*********************************************************
24  2d plot of ES channel status of 1 IOV
25  *********************************************************/
26  class ESIntercalibConstantsPlot : public cond::payloadInspector::PlotImage<ESIntercalibConstants> {
27  public:
28  ESIntercalibConstantsPlot() : cond::payloadInspector::PlotImage<ESIntercalibConstants>("ES IntercalibConstants") {
29  setSingleIov(true);
30  }
31  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
32  TH2F*** esmap = new TH2F**[2];
33  std::string title[2][2] = {{"ES+F", "ES-F"}, {"ES+R", "ES-R"}};
34  for (int plane = 0; plane < 2; plane++) {
35  esmap[plane] = new TH2F*[2];
36  for (int side = 0; side < 2; side++)
37  esmap[plane][side] = new TH2F(
38  Form("esmap%i%i", plane, side), title[plane][side].c_str(), IX_MAX, 0, IX_MAX, IY_MAX, 0, IY_MAX);
39  }
40  unsigned int run = 0;
41  float valmin = 999.;
42  auto iov = iovs.front();
43  std::shared_ptr<ESIntercalibConstants> payload = fetchPayload(std::get<1>(iov));
44  run = std::get<0>(iov);
45  if (payload.get()) {
46  // looping over all the ES channels
47  for (int id = 0; id < kESChannels; id++)
48  if (ESDetId::validHashIndex(id)) {
49  ESDetId myESId = ESDetId::unhashIndex(id);
50  int side = myESId.zside(); // -1, 1
51  if (side < 0)
52  side = 1;
53  else
54  side = 0;
55  int plane = myESId.plane() - 1; // 1, 2
56  if (side < 0 || side > 1 || plane < 0 || plane > 1) {
57  std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane() << std::endl;
58  return false;
59  }
60  ESIntercalibConstants::const_iterator IC_it = payload->find(myESId);
61  float value = *IC_it;
62  // if(id < 64) std::cout << " channel " << id << " value " << value << std::endl;
63  if (myESId.strip() == 1) { // we get 32 times the same value, plot it only once!
64  esmap[plane][side]->Fill(myESId.six() - 1, myESId.siy() - 1, value);
65  if (value < valmin)
66  valmin = value;
67  }
68  } // validHashIndex
69  } // payload
70 
71  gStyle->SetOptStat(0);
72  gStyle->SetPalette(1);
73  TCanvas canvas("CC map", "CC map", 1680, 1320);
74  TLatex t1;
75  t1.SetNDC();
76  t1.SetTextAlign(26);
77  t1.SetTextSize(0.05);
78  t1.DrawLatex(0.5, 0.96, Form("ES Intercalib Constants, IOV %i", run));
79  t1.SetTextSize(0.025);
80 
81  float xmi[2] = {0.0, 0.5};
82  float xma[2] = {0.5, 1.0};
83  TPad*** pad = new TPad**[2];
84  for (int plane = 0; plane < 2; plane++) {
85  pad[plane] = new TPad*[2];
86  for (int side = 0; side < 2; side++) {
87  float yma = 0.94 - (0.46 * plane);
88  float ymi = yma - 0.44;
89  pad[plane][side] =
90  new TPad(Form("p_%i_%i", plane, side), Form("p_%i_%i", plane, side), xmi[side], ymi, xma[side], yma);
91  pad[plane][side]->Draw();
92  }
93  }
94 
95  int min = valmin * 10 - 1.;
96  valmin = (float)min / 10.;
97  for (int side = 0; side < 2; side++) {
98  for (int plane = 0; plane < 2; plane++) {
99  pad[plane][side]->cd();
100  esmap[plane][side]->Draw("colz1");
101  esmap[plane][side]->SetMinimum(valmin);
102  DrawES(plane, side);
103  }
104  }
105 
106  std::string ImageName(m_imageFileName);
107  canvas.SaveAs(ImageName.c_str());
108  return true;
109  } // fill method
110  };
111 
112  /************************************************************************
113  2d plot of ES channel status difference between 2 IOVs
114  ************************************************************************/
115  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
116  class ESIntercalibConstantsDiffBase : public cond::payloadInspector::PlotImage<ESIntercalibConstants, nIOVs, ntags> {
117  public:
118  ESIntercalibConstantsDiffBase()
119  : cond::payloadInspector::PlotImage<ESIntercalibConstants, nIOVs, ntags>("ES IntercalibConstants difference") {}
120  bool fill() override {
121  TH2F*** esmap = new TH2F**[2];
122  std::string title[2][2] = {{"ES+F", "ES-F"}, {"ES+R", "ES-R"}};
123  for (int plane = 0; plane < 2; plane++) {
124  esmap[plane] = new TH2F*[2];
125  for (int side = 0; side < 2; side++)
126  esmap[plane][side] = new TH2F(
127  Form("esmap%i%i", plane, side), title[plane][side].c_str(), IX_MAX, 0, IX_MAX, IY_MAX, 0, IY_MAX);
128  }
129  unsigned int run[2];
130  std::string l_tagname[2];
131  float val[kESChannels], valmin = 999.;
132  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
133  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
134  auto firstiov = iovs.front();
135  run[0] = std::get<0>(firstiov);
136  std::tuple<cond::Time_t, cond::Hash> lastiov;
137  if (ntags == 2) {
138  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
139  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
140  lastiov = tag2iovs.front();
141  } else {
142  lastiov = iovs.back();
143  l_tagname[1] = l_tagname[0];
144  }
145  run[1] = std::get<0>(lastiov);
146  for (int irun = 0; irun < nIOVs; irun++) {
147  std::shared_ptr<ESIntercalibConstants> payload;
148  if (irun == 0) {
149  payload = this->fetchPayload(std::get<1>(firstiov));
150  } else {
151  payload = this->fetchPayload(std::get<1>(lastiov));
152  }
153  if (payload.get()) {
154  for (int id = 0; id < kESChannels; id++) // looping over all the ES channels
155  if (ESDetId::validHashIndex(id)) {
156  ESDetId myESId = ESDetId::unhashIndex(id);
157  // ESIntercalibConstantsCode status_it = (payload->getMap())[myESId];
158  ESIntercalibConstants::const_iterator IC_it = payload->find(myESId);
159  float value = *IC_it;
160  // int status = status_it.getStatusCode();
161  if (irun == 0)
162  val[id] = value;
163  else {
164  int side = myESId.zside(); // -1, 1
165  if (side < 0)
166  side = 1;
167  else
168  side = 0;
169  int plane = myESId.plane() - 1; // 1, 2
170  if (side < 0 || side > 1 || plane < 0 || plane > 1) {
171  std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane()
172  << std::endl;
173  return false;
174  }
175  // int diff = status - stat[id];
176  int diff = value - val[id];
177  if (myESId.strip() == 1) { // we get 32 times the same value, plot it only once!
178  esmap[plane][side]->Fill(myESId.six() - 1, myESId.siy() - 1, diff);
179  if (diff < valmin)
180  valmin = diff;
181  }
182  } // 2nd IOV
183  } // validHashIndex
184  } // payload
185  } // loop over IOVs
186 
187  gStyle->SetOptStat(0);
188  gStyle->SetPalette(1);
189  TCanvas canvas("CC map", "CC map", 1680, 1320);
190  TLatex t1;
191  t1.SetNDC();
192  t1.SetTextAlign(26);
193  int len = l_tagname[0].length() + l_tagname[1].length();
194  if (ntags == 2 && len < 58) {
195  t1.SetTextSize(0.025);
196  t1.DrawLatex(
197  0.5, 0.96, Form("%s IOV %i - %s IOV %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
198  } else {
199  t1.SetTextSize(0.03);
200  t1.DrawLatex(0.5, 0.96, Form("ES Intercalib Constants, IOV %i - %i", run[1], run[0]));
201  }
202  float xmi[2] = {0.0, 0.5};
203  float xma[2] = {0.5, 1.0};
204  TPad*** pad = new TPad**[2];
205  for (int plane = 0; plane < 2; plane++) {
206  pad[plane] = new TPad*[2];
207  for (int side = 0; side < 2; side++) {
208  float yma = 0.94 - (0.46 * plane);
209  float ymi = yma - 0.44;
210  pad[plane][side] =
211  new TPad(Form("p_%i_%i", plane, side), Form("p_%i_%i", plane, side), xmi[side], ymi, xma[side], yma);
212  pad[plane][side]->Draw();
213  }
214  }
215 
216  int min = valmin * 10 - 1.;
217  valmin = (float)min / 10.;
218  for (int side = 0; side < 2; side++) {
219  for (int plane = 0; plane < 2; plane++) {
220  pad[plane][side]->cd();
221  esmap[plane][side]->Draw("colz1");
222  esmap[plane][side]->SetMinimum(valmin);
223  DrawES(plane, side);
224  }
225  }
226 
227  std::string ImageName(this->m_imageFileName);
228  canvas.SaveAs(ImageName.c_str());
229  return true;
230  } // fill method
231  }; // class ESIntercalibConstantsDiffBase
232  using ESIntercalibConstantsDiffOneTag = ESIntercalibConstantsDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
233  using ESIntercalibConstantsDiffTwoTags = ESIntercalibConstantsDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
234 
235 } // namespace
236 
237 // Register the classes as boost python plugin
239  PAYLOAD_INSPECTOR_CLASS(ESIntercalibConstantsPlot);
240  PAYLOAD_INSPECTOR_CLASS(ESIntercalibConstantsDiffOneTag);
241  PAYLOAD_INSPECTOR_CLASS(ESIntercalibConstantsDiffTwoTags);
242 }
int strip() const
Definition: ESDetId.h:47
uint16_t *__restrict__ id
int six() const
Definition: ESDetId.h:43
def canvas
Definition: svgfig.py:482
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
int siy() const
Definition: ESDetId.h:45
T min(T a, T b)
Definition: MathUtil.h:58
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
int zside() const
Definition: ESDetId.h:39
std::vector< Item >::const_iterator const_iterator
void DrawES(int plane, int side)
Definition: ESDrawUtils.h:4
int plane() const
Definition: ESDetId.h:41
tuple cout
Definition: gather_cfg.py:144
static ESDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: ESDetId.cc:32
static bool validHashIndex(int hi)
Definition: ESDetId.h:59
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)