CMS 3D CMS Logo

EcalPulseShapes_PayloadInspector.cc
Go to the documentation of this file.
6 
7 // the data format of the condition to be inspected
9 
10 #include "TH2F.h"
11 #include "TProfile.h"
12 #include "TCanvas.h"
13 #include "TStyle.h"
14 #include "TLine.h"
15 #include "TLatex.h"
16 
17 #include <string>
18 
19 namespace {
20  enum { kEBChannels = 61200, kEEChannels = 14648, kSides = 2, kRMS = 3, TEMPLATESAMPLES = 12 };
21  enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 }; // barrel lower and upper bounds on eta and phi
22  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 }; // endcaps lower and upper bounds on x and y
23 
24  /*****************************************************
25  2d plot of ECAL PulseShapes of 1 IOV
26  *****************************************************/
27  class EcalPulseShapesPlot : public cond::payloadInspector::PlotImage<EcalPulseShapes> {
28  public:
29  EcalPulseShapesPlot() : cond::payloadInspector::PlotImage<EcalPulseShapes>("ECAL PulseShapes - map ") {
30  setSingleIov(true);
31  }
32 
33  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
34  TH2F** barrel = new TH2F*[TEMPLATESAMPLES];
35  TH2F** endc_p = new TH2F*[TEMPLATESAMPLES];
36  TH2F** endc_m = new TH2F*[TEMPLATESAMPLES];
37  double EBmean[TEMPLATESAMPLES], EBrms[TEMPLATESAMPLES], EEmean[TEMPLATESAMPLES], EErms[TEMPLATESAMPLES];
38  int EBtot[TEMPLATESAMPLES], EEtot[TEMPLATESAMPLES];
39  double pEBmin[TEMPLATESAMPLES], pEBmax[TEMPLATESAMPLES], pEEmin[TEMPLATESAMPLES], pEEmax[TEMPLATESAMPLES];
40  for (int s = 0; s < TEMPLATESAMPLES; ++s) {
41  barrel[s] = new TH2F(
42  Form("EBs%i", s), Form("sample %i EB", s), MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
43  endc_p[s] = new TH2F(
44  Form("EE+s%i", s), Form("sample %i EE+", s), IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
45  endc_m[s] = new TH2F(
46  Form("EE-s%i", s), Form("sample %i EE-", s), IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
47  EBmean[s] = 0.;
48  EBrms[s] = 0.;
49  EEmean[s] = 0.;
50  EErms[s] = 0.;
51  EBtot[s] = 0;
52  EEtot[s] = 0;
53  /* pEBmin[s] = 10.;
54  pEBmax[s] = -10.;
55  pEEmin[s] = 10.;
56  pEEmax[s] = -10.;*/
57  }
58 
59  auto iov = iovs.front();
60  std::shared_ptr<EcalPulseShapes> payload = fetchPayload(std::get<1>(iov));
61  unsigned int run = std::get<0>(iov);
62  if (payload.get()) {
63  // int chan = 0;
64  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
65  Double_t eta = (Double_t)ieta;
66  if (ieta == 0)
67  continue;
68  else if (ieta > 0.)
69  eta = eta - 0.5; // 0.5 to 84.5
70  else
71  eta = eta + 0.5; // -84.5 to -0.5
72  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
73  Double_t phi = (Double_t)iphi - 0.5;
74  EBDetId id(ieta, iphi);
75  for (int s = 0; s < TEMPLATESAMPLES; s++) {
76  double val = (*payload)[id.rawId()].pdfval[s];
77  barrel[s]->Fill(phi, eta, val);
78  EBmean[s] = EBmean[s] + val;
79  EBrms[s] = EBrms[s] + val * val;
80  EBtot[s]++;
81  // if(val < pEBmin[s]) pEBmin[s] = val;
82  // if(val > pEBmax[s]) pEBmax[s] = val;
83  }
84  }
85  }
86 
87  for (int sign = 0; sign < kSides; sign++) {
88  int thesign = sign == 1 ? 1 : -1;
89  for (int ix = 1; ix <= IX_MAX; ix++) {
90  for (int iy = 1; iy <= IY_MAX; iy++) {
91  if (!EEDetId::validDetId(ix, iy, thesign))
92  continue;
93  EEDetId id(ix, iy, thesign);
94  for (int s = 0; s < TEMPLATESAMPLES; s++) {
95  double val = (*payload)[id.rawId()].pdfval[s];
96  EEmean[s] = EEmean[s] + val;
97  EErms[s] = EErms[s] + val * val;
98  EEtot[s]++;
99  // if(val < pEEmin[s]) pEEmin[s] = val;
100  // if(val > pEEmax[s]) pEEmax[s] = val;
101  if (thesign == 1)
102  endc_p[s]->Fill(ix, iy, val);
103  else
104  endc_m[s]->Fill(ix, iy, val);
105  }
106  } // iy
107  } // ix
108  } // side
109  } // payload
110 
111  for (int s = 0; s < TEMPLATESAMPLES; s++) {
112  std::cout << "EB sample " << s << " mean " << EBmean[s] << " rms " << EBrms[s] << " entries " << EBtot[s]
113  << " EE mean " << EEmean[s] << " rms " << EErms[s] << " entries " << EEtot[s] << std::endl;
114  double vt = (double)EBtot[s];
115  EBmean[s] = EBmean[s] / vt;
116  EBrms[s] = EBrms[s] / vt - (EBmean[s] * EBmean[s]);
117  if (EBrms[s] > 0)
118  EBrms[s] = sqrt(EBrms[s]);
119  else
120  EBrms[s] = 1.e-06;
121  pEBmin[s] = EBmean[s] - kRMS * EBrms[s];
122  pEBmax[s] = EBmean[s] + kRMS * EBrms[s];
123  std::cout << "EB sample " << s << " mean " << EBmean[s] << " rms " << EBrms[s] << " entries " << EBtot[s]
124  << " min " << pEBmin[s] << " max " << pEBmax[s] << std::endl;
125  // if(pEBmin[s] <= 0.) pEBmin[s] = 1.e-06;
126  vt = (double)EEtot[s];
127  EEmean[s] = EEmean[s] / vt;
128  EErms[s] = EErms[s] / vt - (EEmean[s] * EEmean[s]);
129  if (EErms[s] > 0)
130  EErms[s] = sqrt(EErms[s]);
131  else
132  EErms[s] = 1.e-06;
133  pEEmin[s] = EEmean[s] - kRMS * EErms[s];
134  pEEmax[s] = EEmean[s] + kRMS * EErms[s];
135  std::cout << "EE sample " << s << " mean " << EEmean[s] << " rms " << EErms[s] << " entries " << EEtot[s]
136  << " min " << pEEmin[s] << " max " << pEEmax[s] << std::endl;
137  // if(pEEmin[s] <= 0.) pEEmin[s] = 1.e-06;
138  }
139 
140  // for(int s = 0; s < TEMPLATESAMPLES; s++)
141  // std::cout << " sample " << s << " EB min " << pEBmin[s] << " max " << pEBmax[s] << " EE min " << pEEmin[s] << " max " << pEEmax[s] << std::endl;
142  gStyle->SetPalette(1);
143  gStyle->SetOptStat(0);
144  TCanvas canvas("CC map", "CC map", 1600, 5600);
145  TLatex t1;
146  t1.SetNDC();
147  t1.SetTextAlign(26);
148  t1.SetTextSize(0.05);
149  t1.DrawLatex(0.5, 0.98, Form("Ecal PulseShapes, IOV %i", run));
150 
151  float xmi[3] = {0.0, 0.24, 0.76};
152  float xma[3] = {0.24, 0.76, 1.00};
153  TPad*** pad = new TPad**[6];
154  for (int s = 0; s < TEMPLATESAMPLES; s++) {
155  pad[s] = new TPad*[3];
156  for (int obj = 0; obj < 3; obj++) {
157  float yma = 0.96 - (0.08 * s);
158  float ymi = yma - 0.07;
159  pad[s][obj] = new TPad(Form("p_%i_%i", obj, s), Form("p_%i_%i", obj, s), xmi[obj], ymi, xma[obj], yma);
160  pad[s][obj]->Draw();
161  }
162  }
163 
164  int ipad = 0;
165  for (int s = 0; s < TEMPLATESAMPLES; s++) {
166  pad[ipad][0]->cd();
167  if (pEBmin[s] == pEBmax[s]) { // same values everywhere!..
168  pEBmin[s] = pEBmin[s] - 1.e-06;
169  pEBmax[s] = pEBmax[s] + 1.e-06;
170  }
171  if (pEEmin[s] == pEEmax[s]) {
172  pEEmin[s] = pEEmin[s] - 1.e-06;
173  pEEmax[s] = pEEmax[s] + 1.e-06;
174  }
175  DrawEE(endc_m[s], pEEmin[s], pEEmax[s]);
176  pad[ipad][1]->cd();
177  DrawEB(barrel[s], pEBmin[s], pEBmax[s]);
178  pad[ipad][2]->cd();
179  DrawEE(endc_p[s], pEEmin[s], pEEmax[s]);
180  ipad++;
181  }
182 
183  std::string ImageName(m_imageFileName);
184  canvas.SaveAs(ImageName.c_str());
185 
186  return true;
187  } // fill method
188  };
189 
190  /********************************************
191  profile of ECAL PulseShapes for 1 IOV
192  ********************************************/
193  class EcalPulseShapesProfile : public cond::payloadInspector::PlotImage<EcalPulseShapes> {
194  public:
195  EcalPulseShapesProfile() : cond::payloadInspector::PlotImage<EcalPulseShapes>("ECAL PulseShapes - Profile ") {
196  setSingleIov(true);
197  }
198 
199  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
200  TProfile* barrel = new TProfile("EB", "EB profile", TEMPLATESAMPLES, 0, TEMPLATESAMPLES);
201  TProfile* endcap = new TProfile("EE", "EE profile", TEMPLATESAMPLES, 0, TEMPLATESAMPLES);
202 
203  auto iov = iovs.front();
204  std::shared_ptr<EcalPulseShapes> payload = fetchPayload(std::get<1>(iov));
205  unsigned int run = std::get<0>(iov);
206  if (payload.get()) {
207  for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
208  for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
209  EBDetId id(ieta, iphi);
210  EcalPulseShape pulse = (*payload)[id.rawId()];
211  for (int s = 0; s < TEMPLATESAMPLES; s++) {
212  double val = pulse.pdfval[s];
213  barrel->Fill(s, val);
214  }
215  }
216  }
217 
218  for (int sign = 0; sign < kSides; sign++) {
219  int thesign = sign == 1 ? 1 : -1;
220  for (int ix = 1; ix <= IX_MAX; ix++) {
221  for (int iy = 1; iy <= IY_MAX; iy++) {
222  if (!EEDetId::validDetId(ix, iy, thesign))
223  continue;
224  EEDetId id(ix, iy, thesign);
225  EcalPulseShape pulse = (*payload)[id.rawId()];
226  for (int s = 0; s < TEMPLATESAMPLES; s++) {
227  double val = pulse.pdfval[s];
228  endcap->Fill(s, val);
229  }
230  } // iy
231  } // ix
232  } // side
233  } // payload
234 
235  gStyle->SetPalette(1);
236  gStyle->SetOptStat(0);
237  TCanvas canvas("CC map", "CC map", 500, 1000);
238  TLatex t1;
239  t1.SetNDC();
240  t1.SetTextAlign(26);
241  t1.SetTextSize(0.05);
242  t1.DrawLatex(0.5, 0.98, Form("Ecal PulseShapes, IOV %i", run));
243 
244  TPad** pad = new TPad*[2];
245  for (int s = 0; s < 2; s++) {
246  float yma = 0.96 - (0.47 * s);
247  float ymi = yma - 0.45;
248  pad[s] = new TPad(Form("p_%i", s), Form("p_%i", s), 0.0, ymi, 1.0, yma);
249  pad[s]->Draw();
250  }
251 
252  pad[0]->cd();
253  barrel->Draw("");
254  pad[1]->cd();
255  endcap->Draw("");
256 
257  std::string ImageName(m_imageFileName);
258  canvas.SaveAs(ImageName.c_str());
259  return true;
260  } // fill method
261  };
262 
263 } // namespace
264 
265 // Register the classes as boost python plugin
267  PAYLOAD_INSPECTOR_CLASS(EcalPulseShapesPlot);
268  PAYLOAD_INSPECTOR_CLASS(EcalPulseShapesProfile);
269 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
Reference_intrackfit_cff.barrel
list barrel
Definition: Reference_intrackfit_cff.py:37
kEEChannels
Definition: EcalFloatCondObjectContainerUtils.h:9
EcalPulseShape
Definition: EcalPulseShapes.h:8
MAX_IPHI
Definition: EcalFloatCondObjectContainerUtils.h:14
IX_MAX
Definition: EcalFloatCondObjectContainerUtils.h:20
IY_MAX
Definition: EcalFloatCondObjectContainerUtils.h:21
EBDetId
Definition: EBDetId.h:17
PayloadInspector.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId.h
EEDetId.h
pulse
double pulse(double x, double y, double z, double t)
Definition: SiStripPulseShape.cc:49
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
makeMuonMisalignmentScenario.endcap
endcap
Definition: makeMuonMisalignmentScenario.py:320
EcalCondObjectContainer< EcalPulseShape >
PayloadInspectorModule.h
DrawEE
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
alignCSCRings.s
s
Definition: alignCSCRings.py:92
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
DrawEB
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
PVValHelper::eta
Definition: PVValidationHelpers.h:69
MIN_IETA
Definition: EcalFloatCondObjectContainerUtils.h:11
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
jets_cff.payload
payload
Definition: jets_cff.py:34
PAYLOAD_INSPECTOR_MODULE
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: PayloadInspectorModule.h:8
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalPulseShapes.h
cond
Definition: plugin.cc:23
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
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
kSides
static const int kSides
Definition: EcalGeomPhiSymHelper.h:9
DDAxes::phi
heppy_batch.val
val
Definition: heppy_batch.py:351
writedatasetfile.run
run
Definition: writedatasetfile.py:27
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:829
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
kEBChannels
Definition: EcalFloatCondObjectContainerUtils.h:9
IX_MIN
Definition: EcalFloatCondObjectContainerUtils.h:18
MAX_IETA
Definition: EcalFloatCondObjectContainerUtils.h:13