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"
12 #include "TCanvas.h"
13 #include "TLine.h"
14 #include "TStyle.h"
15 #include "TLatex.h"
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 {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 Alignment of 1 IOV
28  ******************************************/
29  class EcalAlignmentPlot : public cond::payloadInspector::PlotImage<Alignments> {
30  public:
31  EcalAlignmentPlot() : cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment - map ") {
32  setSingleIov( true );
33  }
34 
35  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
36  auto iov = iovs.front();
37  std::shared_ptr<Alignments> payload = fetchPayload( std::get<1>(iov) );
38  unsigned int run = std::get<0>(iov);
39  TH2F* align;
40  std::string subdet;
41  int NbRows;
42  if(payload.get()) {
43  NbRows = (*payload).m_align.size();
44  if(NbRows == 36) subdet = "EB";
45  else if(NbRows == 4) subdet = "EE";
46  else if(NbRows == 8) subdet = "ES";
47  else subdet = "unknown";
48  // align = new TH2F("Align",Form("Alignment %s", subdet.c_str()),6, 0, 6, NbRows, 0, NbRows);
49  align = new TH2F("Align","x y z Phi Theta Psi",
50  6, 0, 6, NbRows, 0, NbRows);
51  double row = NbRows - 0.5;
52  for(std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
53  it != (*payload).m_align.end(); it++ ) {
54  align->Fill(0.5, row, (*it).translation().x());
55  align->Fill(1.5, row, (*it).translation().y());
56  align->Fill(2.5, row, (*it).translation().z());
57  align->Fill(3.5, row, (*it).rotation().getPhi());
58  align->Fill(4.5, row, (*it).rotation().getTheta());
59  align->Fill(5.5, row, (*it).rotation().getPsi());
60  row = row - 1.;
61  }
62  } // if payload.get()
63  else return false;
64 
65  gStyle->SetPalette(1);
66  gStyle->SetOptStat(0);
67  TCanvas canvas("CC map","CC map",1000,1000);
68  TLatex t1;
69  t1.SetNDC();
70  t1.SetTextAlign(26);
71  t1.SetTextSize(0.05);
72  t1.SetTextColor(2);
73  t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i", subdet.c_str(), run));
74  // t1.SetTextSize(0.03);
75  // t1.DrawLatex(0.3, 0.94, "x y z Phi Theta Psi");
76 
77  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
78  pad->Draw();
79  pad->cd();
80  align->Draw("TEXT");
81  TLine* l = new TLine;
82  l->SetLineWidth(1);
83  for(int i = 1; i < NbRows; i++) {
84  double y = (double)i;
85  l = new TLine(0., y, 6., y);
86  l->Draw();
87  }
88  for(int i = 1; i < 6; i++) {
89  double x = (double)i;
90  double y = (double)NbRows;
91  l = new TLine(x, 0., x, y);
92  l->Draw();
93  }
94  align->GetXaxis()->SetTickLength(0.);
95  align->GetXaxis()->SetLabelSize(0.);
96  align->GetYaxis()->SetTickLength(0.);
97  align->GetYaxis()->SetLabelSize(0.);
98 
99  std::string ImageName(m_imageFileName);
100  canvas.SaveAs(ImageName.c_str());
101  return true;
102  }// fill method
103  };
104 
105  /*********************************************************
106  2d plot of ECAL Alignment difference between 2 IOVs
107  **********************************************************/
108  class EcalAlignmentDiff : public cond::payloadInspector::PlotImage<Alignments> {
109 
110  public:
111  EcalAlignmentDiff() : cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment difference") {
112  setSingleIov(false);
113  }
114 
115  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
116  unsigned int run[2], irun = 0;
117  float val[6][36];
118  TH2F* align = new TH2F("","", 1, 0., 1., 1, 0., 1.); // pseudo creation
119  std::string subdet;
120  int NbRows = 0;
121  for (auto const & iov: iovs) {
122  std::shared_ptr<Alignments> payload = fetchPayload( std::get<1>(iov) );
123  run[irun] = std::get<0>(iov);
124  if( payload.get() ){
125  NbRows = (*payload).m_align.size();
126  if(irun == 1) {
127  if(NbRows == 36) subdet = "EB";
128  else if(NbRows == 4) subdet = "EE";
129  else if(NbRows == 8) subdet = "ES";
130  else subdet = "unknown";
131  delete align;
132  align = new TH2F("Align","x y z Phi Theta Psi",
133  6, 0, 6, NbRows, 0, NbRows);
134  }
135  double row = NbRows - 0.5;
136  int irow = 0;
137  for(std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
138  it != (*payload).m_align.end(); it++ ) {
139  if(irun == 0) {
140  val[0][irow] = (*it).translation().x();
141  val[1][irow] = (*it).translation().y();
142  val[2][irow] = (*it).translation().z();
143  val[3][irow] = (*it).rotation().getPhi();
144  val[4][irow] = (*it).rotation().getTheta();
145  val[5][irow] = (*it).rotation().getPsi();
146  }
147  else {
148  align->Fill(0.5, row, (*it).translation().x()- val[0][irow]);
149  align->Fill(1.5, row, (*it).translation().y() - val[1][irow]);
150  align->Fill(2.5, row, (*it).translation().z() - val[2][irow]);
151  align->Fill(3.5, row, (*it).rotation().getPhi() - val[3][irow]);
152  align->Fill(4.5, row, (*it).rotation().getTheta() - val[3][irow]);
153  align->Fill(5.5, row, (*it).rotation().getPsi() - val[5][irow]);
154  row = row - 1.;
155  }
156  irow++;
157  } // loop over alignment rows
158  } // if payload.get()
159  else return false;
160  irun++;
161  } // loop over IOVs
162 
163  gStyle->SetPalette(1);
164  gStyle->SetOptStat(0);
165  TCanvas canvas("CC map","CC map",1000,1000);
166  TLatex t1;
167  t1.SetNDC();
168  t1.SetTextAlign(26);
169  t1.SetTextSize(0.05);
170  t1.SetTextColor(2);
171  t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i - %i", subdet.c_str(), run[1], run[0]));
172 
173  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
174  pad->Draw();
175  pad->cd();
176  align->Draw("TEXT");
177  TLine* l = new TLine;
178  l->SetLineWidth(1);
179  for(int i = 1; i < NbRows; i++) {
180  double y = (double)i;
181  l = new TLine(0., y, 6., y);
182  l->Draw();
183  }
184  for(int i = 1; i < 6; i++) {
185  double x = (double)i;
186  double y = (double)NbRows;
187  l = new TLine(x, 0., x, y);
188  l->Draw();
189  }
190  align->GetXaxis()->SetTickLength(0.);
191  align->GetXaxis()->SetLabelSize(0.);
192  align->GetYaxis()->SetTickLength(0.);
193  align->GetYaxis()->SetLabelSize(0.);
194 
195  std::string ImageName(m_imageFileName);
196  canvas.SaveAs(ImageName.c_str());
197  return true;
198  }// fill method
199  };
200 } // close namespace
201 
202  // Register the classes as boost python plugin
204  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentPlot);
205  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentDiff);
206 }
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:481