CMS 3D CMS Logo

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 {
23  kEBChannels = 61200, kEEChannels = 14648
24 };
25 enum {MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360};// barrel (EB) lower and upper bounds on eta and phi
26 enum {IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100};// endcaps (EE) lower and upper bounds on x and y
27 
28 /*****************************************
29  2d plot of ECAL Alignment of 1 IOV
30  ******************************************/
31 class EcalAlignmentPlot: public cond::payloadInspector::PlotImage<Alignments> {
32 public:
33  EcalAlignmentPlot() :
34  cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment - map ") {
35  setSingleIov(true);
36  }
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 = fetchPayload(std::get < 1 > (iov)); //std::get<1>(iov) refers to the Hash in the tuple iov
41  unsigned int run = std::get < 0 > (iov); //referes to Time_t in iov.
42  TH2F* align; //pointer to align which is a 2D histogram
43  std::string subdet;
44  int NbRows;
45  if (payload.get()) { //payload is an iov retrieved from payload using hash.
46  NbRows = (*payload).m_align.size();
47  if (NbRows == 36)
48  subdet = "EB";
49  else if (NbRows == 4)
50  subdet = "EE";
51  else if (NbRows == 8)
52  subdet = "ES";
53  else
54  subdet = "unknown";
55  // align = new TH2F("Align",Form("Alignment %s", subdet.c_str()),6, 0, 6, NbRows, 0, NbRows);
56  align =new TH2F("Align","x y z Phi Theta Psi",
57  6, 0, 6, NbRows, 0, NbRows);
58 
59  double row = NbRows - 0.5;
60  for (std::vector<AlignTransform>::const_iterator it =
61  (*payload).m_align.begin(); it != (*payload).m_align.end();it++) {
62 
63  align->Fill(0.5, row, (*it).translation().x());
64  align->Fill(1.5, row, (*it).translation().y());
65  align->Fill(2.5, row, (*it).translation().z());
66  align->Fill(3.5, row, (*it).rotation().getPhi());
67  align->Fill(4.5, row, (*it).rotation().getTheta());
68  align->Fill(5.5, row, (*it).rotation().getPsi());
69  row = row - 1.;
70  }
71  } // if payload.get()
72  else
73  return false;
74 
75  gStyle->SetPalette(1);
76  gStyle->SetOptStat(0);
77  TCanvas canvas("CC map", "CC map", 1000, 1000);
78  TLatex t1;
79  t1.SetNDC();
80  t1.SetTextAlign(26);
81  t1.SetTextSize(0.05);
82  t1.SetTextColor(2);
83  t1.DrawLatex(0.5, 0.96,Form("Ecal %s Alignment, IOV %i", subdet.c_str(), run));
84  // t1.SetTextSize(0.03);
85  // t1.DrawLatex(0.3, 0.94, "x y z Phi Theta Psi");
86 
87  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
88  pad->Draw();
89  pad->cd();
90  align->Draw("TEXT");
91  TLine* l = new TLine;
92  l->SetLineWidth(1);
93  for (int i = 1; i < NbRows; i++) {
94  double y = (double) i;
95  l = new TLine(0., y, 6., y);
96  l->Draw();
97  }
98 
99  for (int i = 1; i < 6; i++) {
100  double x = (double) i;
101  double y = (double) NbRows;
102  l = new TLine(x, 0., x, y);
103  l->Draw();
104  }
105 
106  align->GetXaxis()->SetTickLength(0.);
107  align->GetXaxis()->SetLabelSize(0.);
108  align->GetYaxis()->SetTickLength(0.);
109  align->GetYaxis()->SetLabelSize(0.);
110 
111  std::string ImageName(m_imageFileName);
112  canvas.SaveAs(ImageName.c_str());
113  return true;
114  } // fill method
115 };
116 
117 /*********************************************************
118  2d plot of ECAL Alignment difference between 2 IOVs
119  **********************************************************/
120 class EcalAlignmentDiff: public cond::payloadInspector::PlotImage<Alignments> {
121 
122 public:
123  EcalAlignmentDiff() :
124  cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment difference") {
125  setSingleIov(false);
126  }
127 
128  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)override {
129 
130  unsigned int run[2], irun = 0;
131  float val[6][36];
132  TH2F* align = new TH2F("", "", 1, 0., 1., 1, 0., 1.); // pseudo creation
133  std::string subdet;
134  int NbRows = 0;
135 
136  for (auto const & iov : iovs) {
137  std::shared_ptr < Alignments > payload = fetchPayload(std::get < 1 > (iov));
138  run[irun] = std::get < 0 > (iov);
139 
140  if (payload.get()) {
141  NbRows = (*payload).m_align.size();
142  if (irun == 1) {
143  if (NbRows == 36)
144  subdet = "EB";
145  else if (NbRows == 4)
146  subdet = "EE";
147  else if (NbRows == 8)
148  subdet = "ES";
149  else
150  subdet = "unknown";
151  delete align;
152  align =
153  new TH2F("Align","x y z Phi Theta Psi",
154  6, 0, 6, NbRows, 0, NbRows);
155  }
156 
157  double row = NbRows - 0.5;
158  int irow = 0;
159  for (std::vector<AlignTransform>::const_iterator it =(*payload).m_align.begin();
160  it != (*payload).m_align.end(); it++) {
161 
162  if (irun == 0) {
163  val[0][irow] = (*it).translation().x();
164  val[1][irow] = (*it).translation().y();
165  val[2][irow] = (*it).translation().z();
166  val[3][irow] = (*it).rotation().getPhi();
167  val[4][irow] = (*it).rotation().getTheta();
168  val[5][irow] = (*it).rotation().getPsi();
169  } else {
170  align->Fill(0.5, row,(*it).translation().x() - val[0][irow]);
171  align->Fill(1.5, row,(*it).translation().y() - val[1][irow]);
172  align->Fill(2.5, row,(*it).translation().z() - val[2][irow]);
173  align->Fill(3.5, row,(*it).rotation().getPhi() - val[3][irow]);
174  align->Fill(4.5, row,(*it).rotation().getTheta() - val[3][irow]);
175  align->Fill(5.5, row,(*it).rotation().getPsi() - val[5][irow]);
176  row = row - 1.;
177  }
178  irow++;
179  } // loop over alignment rows
180 
181  } // if payload.get()
182  else
183  return false;
184  irun++;
185  } // loop over IOVs
186 
187  gStyle->SetPalette(1);
188  gStyle->SetOptStat(0);
189  TCanvas canvas("CC map", "CC map", 1000, 1000);
190  TLatex t1;
191  t1.SetNDC();
192  t1.SetTextAlign(26);
193  t1.SetTextSize(0.05);
194  t1.SetTextColor(2);
195  t1.DrawLatex(0.5, 0.96,Form("Ecal %s Alignment, IOV %i - %i", subdet.c_str(), run[1],run[0]));
196 
197  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
198  pad->Draw();
199  pad->cd();
200  align->Draw("TEXT");
201  TLine* l = new TLine;
202  l->SetLineWidth(1);
203 
204  for (int i = 1; i < NbRows; i++) {
205  double y = (double) i;
206  l = new TLine(0., y, 6., y);
207  l->Draw();
208  }
209 
210  for (int i = 1; i < 6; i++) {
211  double x = (double) i;
212  double y = (double) NbRows;
213  l = new TLine(x, 0., x, y);
214  l->Draw();
215  }
216 
217  align->GetXaxis()->SetTickLength(0.);
218  align->GetXaxis()->SetLabelSize(0.);
219  align->GetYaxis()->SetTickLength(0.);
220  align->GetYaxis()->SetLabelSize(0.);
221 
222  std::string ImageName(m_imageFileName);
223  canvas.SaveAs(ImageName.c_str());
224  return true;
225  } // fill method
226 };
227 
228 } // close namespace
229 
230 // Register the classes as boost python plugin
231 PAYLOAD_INSPECTOR_MODULE(EcalAlignment) {
232  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentPlot);
233  PAYLOAD_INSPECTOR_CLASS (EcalAlignmentDiff);
234 }
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:482