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 { 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  class EcalAlignmentDiff : public cond::payloadInspector::PlotImage<Alignments> {
128  public:
129  EcalAlignmentDiff() : cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment difference") {
130  setSingleIov(false);
131  }
132 
133  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
134  unsigned int run[2], irun = 0;
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 
140  for (auto const& iov : iovs) {
141  std::shared_ptr<Alignments> payload = fetchPayload(std::get<1>(iov));
142  run[irun] = std::get<0>(iov);
143 
144  if (payload.get()) {
145  NbRows = (*payload).m_align.size();
146  if (irun == 1) {
147  if (NbRows == 36)
148  subdet = "EB";
149  else if (NbRows == 4)
150  subdet = "EE";
151  else if (NbRows == 8)
152  subdet = "ES";
153  else
154  subdet = "unknown";
155  delete align;
156  align = new TH2F("Align",
157  "x y z Phi Theta Psi",
158  6,
159  0,
160  6,
161  NbRows,
162  0,
163  NbRows);
164  }
165 
166  double row = NbRows - 0.5;
167  int irow = 0;
168  for (std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
169  it != (*payload).m_align.end();
170  it++) {
171  if (irun == 0) {
172  val[0][irow] = (*it).translation().x();
173  val[1][irow] = (*it).translation().y();
174  val[2][irow] = (*it).translation().z();
175  val[3][irow] = (*it).rotation().getPhi();
176  val[4][irow] = (*it).rotation().getTheta();
177  val[5][irow] = (*it).rotation().getPsi();
178  } else {
179  align->Fill(0.5, row, (*it).translation().x() - val[0][irow]);
180  align->Fill(1.5, row, (*it).translation().y() - val[1][irow]);
181  align->Fill(2.5, row, (*it).translation().z() - val[2][irow]);
182  align->Fill(3.5, row, (*it).rotation().getPhi() - val[3][irow]);
183  align->Fill(4.5, row, (*it).rotation().getTheta() - val[3][irow]);
184  align->Fill(5.5, row, (*it).rotation().getPsi() - val[5][irow]);
185  row = row - 1.;
186  }
187  irow++;
188  } // loop over alignment rows
189 
190  } // if payload.get()
191  else
192  return false;
193  irun++;
194  } // loop over IOVs
195 
196  gStyle->SetPalette(1);
197  gStyle->SetOptStat(0);
198  TCanvas canvas("CC map", "CC map", 1000, 1000);
199  TLatex t1;
200  t1.SetNDC();
201  t1.SetTextAlign(26);
202  t1.SetTextSize(0.05);
203  t1.SetTextColor(2);
204  t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i - %i", subdet.c_str(), run[1], run[0]));
205 
206  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
207  pad->Draw();
208  pad->cd();
209  align->Draw("TEXT");
210  TLine* l = new TLine;
211  l->SetLineWidth(1);
212 
213  for (int i = 1; i < NbRows; i++) {
214  double y = (double)i;
215  l = new TLine(0., y, 6., y);
216  l->Draw();
217  }
218 
219  for (int i = 1; i < 6; i++) {
220  double x = (double)i;
221  double y = (double)NbRows;
222  l = new TLine(x, 0., x, y);
223  l->Draw();
224  }
225 
226  align->GetXaxis()->SetTickLength(0.);
227  align->GetXaxis()->SetLabelSize(0.);
228  align->GetYaxis()->SetTickLength(0.);
229  align->GetYaxis()->SetLabelSize(0.);
230 
231  std::string ImageName(m_imageFileName);
232  canvas.SaveAs(ImageName.c_str());
233  return true;
234  } // fill method
235  };
236 
237 } // namespace
238 
239 // Register the classes as boost python plugin
240 PAYLOAD_INSPECTOR_MODULE(EcalAlignment) {
241  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentPlot);
242  PAYLOAD_INSPECTOR_CLASS(EcalAlignmentDiff);
243 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:355
align
Definition: AlignableIndexer.h:30
kEEChannels
Definition: EcalFloatCondObjectContainerUtils.h:9
MAX_IPHI
Definition: EcalFloatCondObjectContainerUtils.h:14
IX_MAX
Definition: EcalFloatCondObjectContainerUtils.h:20
IY_MAX
Definition: EcalFloatCondObjectContainerUtils.h:21
PayloadInspector.h
EBDetId.h
EEDetId.h
Alignments.h
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
DDAxes::x
PayloadInspectorModule.h
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
MIN_IETA
Definition: EcalFloatCondObjectContainerUtils.h:11
jets_cff.payload
payload
Definition: jets_cff.py:34
PAYLOAD_INSPECTOR_MODULE
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: PayloadInspectorModule.h:8
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
Time.h
IY_MIN
Definition: EcalFloatCondObjectContainerUtils.h:19
cond::payloadInspector::PlotImage::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:840
MIN_IPHI
Definition: EcalFloatCondObjectContainerUtils.h:12
EcalDrawUtils.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
heppy_batch.val
val
Definition: heppy_batch.py:351
writedatasetfile.run
run
Definition: writedatasetfile.py:27
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:829
kEBChannels
Definition: EcalFloatCondObjectContainerUtils.h:9
IX_MIN
Definition: EcalFloatCondObjectContainerUtils.h:18
Alignments
Definition: Alignments.h:10
MAX_IETA
Definition: EcalFloatCondObjectContainerUtils.h:13