CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalAlignment_PayloadInspector.cc
Go to the documentation of this file.
7 
8 // the data format of the condition to be inspected
10 
11 #include "TH2F.h" // a 2-D histogram with four bytes per cell (float)
12 #include "TCanvas.h"
13 #include "TLine.h"
14 #include "TStyle.h"
15 #include "TLatex.h" //write mathematical equations.
16 #include "TPave.h"
17 #include "TPaveStats.h"
18 #include <string>
19 #include <fstream>
20 
21 namespace {
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  }; // barrel (EB) lower and upper bounds on eta and phi
29  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 }; // endcaps (EE) lower and upper bounds on x and y
30 
31  /*****************************************
32  2d plot of ECAL Alignment of 1 IOV
33  ******************************************/
34  class EcalAlignmentPlot : public cond::payloadInspector::PlotImage<Alignments> {
35  public:
36  EcalAlignmentPlot() : cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment - map ") { setSingleIov(true); }
37 
38  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
39  auto iov = iovs.front(); //get reference to 1st element in the vector iovs
40  std::shared_ptr<Alignments> payload =
41  fetchPayload(std::get<1>(iov)); //std::get<1>(iov) refers to the Hash in the tuple iov
42  unsigned int run = std::get<0>(iov); //referes to Time_t in iov.
43  TH2F* align; //pointer to align which is a 2D histogram
44  std::string subdet;
45  int NbRows;
46  if (payload.get()) { //payload is an iov retrieved from payload using hash.
47  NbRows = (*payload).m_align.size();
48  if (NbRows == 36)
49  subdet = "EB";
50  else if (NbRows == 4)
51  subdet = "EE";
52  else if (NbRows == 8)
53  subdet = "ES";
54  else
55  subdet = "unknown";
56  // align = new TH2F("Align",Form("Alignment %s", subdet.c_str()),6, 0, 6, NbRows, 0, NbRows);
57  align = new TH2F("Align",
58  "x y z Phi Theta Psi",
59  6,
60  0,
61  6,
62  NbRows,
63  0,
64  NbRows);
65 
66  double row = NbRows - 0.5;
67  for (std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
68  it != (*payload).m_align.end();
69  it++) {
70  align->Fill(0.5, row, (*it).translation().x());
71  align->Fill(1.5, row, (*it).translation().y());
72  align->Fill(2.5, row, (*it).translation().z());
73  align->Fill(3.5, row, (*it).rotation().getPhi());
74  align->Fill(4.5, row, (*it).rotation().getTheta());
75  align->Fill(5.5, row, (*it).rotation().getPsi());
76  row = row - 1.;
77  }
78  } // if payload.get()
79  else
80  return false;
81 
82  gStyle->SetPalette(1);
83  gStyle->SetOptStat(0);
84  TCanvas canvas("CC map", "CC map", 1000, 1000);
85  TLatex t1;
86  t1.SetNDC();
87  t1.SetTextAlign(26);
88  t1.SetTextSize(0.05);
89  t1.SetTextColor(2);
90  t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i", subdet.c_str(), run));
91  // t1.SetTextSize(0.03);
92  // t1.DrawLatex(0.3, 0.94, "x y z Phi Theta Psi");
93 
94  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
95  pad->Draw();
96  pad->cd();
97  align->Draw("TEXT");
98  TLine* l = new TLine;
99  l->SetLineWidth(1);
100  for (int i = 1; i < NbRows; i++) {
101  double y = (double)i;
102  l = new TLine(0., y, 6., y);
103  l->Draw();
104  }
105 
106  for (int i = 1; i < 6; i++) {
107  double x = (double)i;
108  double y = (double)NbRows;
109  l = new TLine(x, 0., x, y);
110  l->Draw();
111  }
112 
113  align->GetXaxis()->SetTickLength(0.);
114  align->GetXaxis()->SetLabelSize(0.);
115  align->GetYaxis()->SetTickLength(0.);
116  align->GetYaxis()->SetLabelSize(0.);
117 
118  std::string ImageName(m_imageFileName);
119  canvas.SaveAs(ImageName.c_str());
120  return true;
121  } // fill method
122  };
123 
124  /*********************************************************
125  2d plot of ECAL Alignment difference between 2 IOVs
126  **********************************************************/
127  template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
128  class EcalAlignmentDiffBase : public cond::payloadInspector::PlotImage<Alignments, nIOVs, ntags> {
129  public:
130  EcalAlignmentDiffBase()
131  : cond::payloadInspector::PlotImage<Alignments, nIOVs, ntags>("ECAL Alignment difference") {}
132 
133  bool fill() override {
134  unsigned int run[2];
135  float val[6][36];
136  TH2F* align = new TH2F("", "", 1, 0., 1., 1, 0., 1.); // pseudo creation
137  std::string subdet;
138  int NbRows = 0;
139  std::string l_tagname[2];
140 
141  auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
142  l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
143  auto firstiov = iovs.front();
144  run[0] = std::get<0>(firstiov);
145  std::tuple<cond::Time_t, cond::Hash> lastiov;
146  if (ntags == 2) {
147  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
148  l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
149  lastiov = tag2iovs.front();
150  } else {
151  lastiov = iovs.back();
152  l_tagname[1] = l_tagname[0];
153  }
154  run[1] = std::get<0>(lastiov);
155 
156  for (int irun = 0; irun < nIOVs; irun++) {
157  std::shared_ptr<Alignments> payload;
158  if (irun == 0) {
159  payload = this->fetchPayload(std::get<1>(firstiov));
160  } else {
161  payload = this->fetchPayload(std::get<1>(lastiov));
162  }
163 
164  if (payload.get()) {
165  NbRows = (*payload).m_align.size();
166  if (irun == 1) {
167  if (NbRows == 36)
168  subdet = "EB";
169  else if (NbRows == 4)
170  subdet = "EE";
171  else if (NbRows == 8)
172  subdet = "ES";
173  else
174  subdet = "unknown";
175  delete align;
176  align = new TH2F("Align",
177  "x y z Phi Theta Psi",
178  6,
179  0,
180  6,
181  NbRows,
182  0,
183  NbRows);
184  }
185 
186  double row = NbRows - 0.5;
187  int irow = 0;
188  for (std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
189  it != (*payload).m_align.end();
190  it++) {
191  if (irun == 0) {
192  val[0][irow] = (*it).translation().x();
193  val[1][irow] = (*it).translation().y();
194  val[2][irow] = (*it).translation().z();
195  val[3][irow] = (*it).rotation().getPhi();
196  val[4][irow] = (*it).rotation().getTheta();
197  val[5][irow] = (*it).rotation().getPsi();
198  } else {
199  align->Fill(0.5, row, (*it).translation().x() - val[0][irow]);
200  align->Fill(1.5, row, (*it).translation().y() - val[1][irow]);
201  align->Fill(2.5, row, (*it).translation().z() - val[2][irow]);
202  align->Fill(3.5, row, (*it).rotation().getPhi() - val[3][irow]);
203  align->Fill(4.5, row, (*it).rotation().getTheta() - val[3][irow]);
204  align->Fill(5.5, row, (*it).rotation().getPsi() - val[5][irow]);
205  row = row - 1.;
206  }
207  irow++;
208  } // loop over alignment rows
209 
210  } // if payload.get()
211  else
212  return false;
213  } // loop over IOVs
214 
215  gStyle->SetPalette(1);
216  gStyle->SetOptStat(0);
217  TCanvas canvas("CC map", "CC map", 1000, 1000);
218  TLatex t1;
219  t1.SetNDC();
220  t1.SetTextAlign(26);
221  t1.SetTextColor(2);
222  int len = l_tagname[0].length() + l_tagname[1].length();
223  if (ntags == 2 && len < 58) {
224  t1.SetTextSize(0.025);
225  t1.DrawLatex(
226  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]));
227  } else {
228  t1.SetTextSize(0.05);
229  t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i - %i", subdet.c_str(), run[1], run[0]));
230  }
231  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
232  pad->Draw();
233  pad->cd();
234  align->Draw("TEXT");
235  TLine* l = new TLine;
236  l->SetLineWidth(1);
237 
238  for (int i = 1; i < NbRows; i++) {
239  double y = (double)i;
240  l = new TLine(0., y, 6., y);
241  l->Draw();
242  }
243 
244  for (int i = 1; i < 6; i++) {
245  double x = (double)i;
246  double y = (double)NbRows;
247  l = new TLine(x, 0., x, y);
248  l->Draw();
249  }
250 
251  align->GetXaxis()->SetTickLength(0.);
252  align->GetXaxis()->SetLabelSize(0.);
253  align->GetYaxis()->SetTickLength(0.);
254  align->GetYaxis()->SetLabelSize(0.);
255 
256  std::string ImageName(this->m_imageFileName);
257  canvas.SaveAs(ImageName.c_str());
258  return true;
259  } // fill method
260  }; // class EcalAlignmentDiffBase
261  using EcalAlignmentDiffOneTag = EcalAlignmentDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
262  using EcalAlignmentDiffTwoTags = EcalAlignmentDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
263 
264 } // namespace
265 
266 // Register the classes as boost python plugin
267 PAYLOAD_INSPECTOR_MODULE(EcalAlignment) {
268  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentPlot);
269  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentDiffOneTag);
270  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentDiffTwoTags);
271 }
def canvas
Definition: svgfig.py:482
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)