CMS 3D CMS Logo

EcalTimeCalibConstants_PayloadInspector.cc
Go to the documentation of this file.
8 // the data format of the condition to be inspected
10 
11 #include "TH2F.h"
12 #include "TCanvas.h"
13 #include "TStyle.h"
14 #include "TLine.h"
15 #include "TLatex.h"
16 
17 #include <memory>
18 #include <sstream>
19 
20 namespace {
21 
22 
23  enum {kEBChannels = 61200, kEEChannels = 14648};
24  enum {MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360, EBhistEtaMax = 171}; // barrel lower and upper bounds on eta and phi
25  enum {IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100, EEhistXMax = 220}; // endcaps lower and upper bounds on x and y
26 
27  /*******************************************************
28 
29  2d histogram of ECAL barrel Time Calib Constants of 1 IOV
30 
31  *******************************************************/
32 
33  // inherit from one of the predefined plot class: Histogram2D
34  class EcalTimeCalibConstantsEBMap : public cond::payloadInspector::Histogram2D<EcalTimeCalibConstants> {
35 
36  public:
37  EcalTimeCalibConstantsEBMap() : cond::payloadInspector::Histogram2D<EcalTimeCalibConstants>("ECAL Barrel Time Calib Constants - map ",
38  "iphi", MAX_IPHI, MIN_IPHI, MAX_IPHI + 1,
39  "ieta", EBhistEtaMax, -MAX_IETA, MAX_IETA + 1) {
40  Base::setSingleIov( true );
41  }
42 
43  // Histogram2D::fill (virtual) needs be overridden - the implementation should use fillWithValue
44  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
45 
46  for (auto const & iov: iovs) {
47  std::shared_ptr<EcalTimeCalibConstants> payload = Base::fetchPayload( std::get<1>(iov) );
48  if( payload.get() ){
49  // looping over the EB channels, via the dense-index, mapped into EBDetId's
50  if (payload->barrelItems().empty()) return false;
51  // set to -1 for ieta 0 (no crystal)
52  for(int iphi = MIN_IPHI; iphi < MAX_IPHI+1; iphi++) fillWithValue(iphi, 0, -1);
53 
54  for(int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
55  uint32_t rawid = EBDetId::unhashIndex(cellid);
56 
57  // check the existence of ECAL Time Calib Constants, for a given ECAL barrel channel
58  EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
59  if (value_ptr == payload->end())
60  continue; // cell absent from payload
61 
62  float weight = (float)(*value_ptr);
63 
64  // fill the Histogram2D here
65  fillWithValue( (EBDetId(rawid)).iphi() , (EBDetId(rawid)).ieta(), weight);
66  }// loop over cellid
67  }// if payload.get()
68  }// loop over IOV's (1 in this case)
69 
70  return true;
71 
72  }//fill method
73  };
74 
75 
76  /*******************************************************
77 
78  2d histogram of ECAL EndCaps Time Calib Constants of 1 IOV
79 
80  *******************************************************/
81 
82  class EcalTimeCalibConstantsEEMap : public cond::payloadInspector::Histogram2D<EcalTimeCalibConstants> {
83 
84  private:
85  int EEhistSplit = 20;
86 
87  public:
88  EcalTimeCalibConstantsEEMap() : cond::payloadInspector::Histogram2D<EcalTimeCalibConstants>( "ECAL Endcap Time Calib Constants - map ",
89  "ix", EEhistXMax, IX_MIN, EEhistXMax + 1,
90  "iy", IY_MAX, IY_MIN, IY_MAX + 1) {
91  Base::setSingleIov( true );
92  }
93 
94  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
95 
96  for (auto const & iov: iovs) {
97  std::shared_ptr<EcalTimeCalibConstants> payload = Base::fetchPayload( std::get<1>(iov) );
98  if( payload.get() ){
99  if (payload->endcapItems().empty()) return false;
100 
101  // set to -1 everywhwere
102  for(int ix = IX_MIN; ix < EEhistXMax + 1; ix++)
103  for(int iy = IY_MAX; iy < IY_MAX + 1; iy++)
104  fillWithValue(ix, iy, -1);
105 
106  for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid){ // loop on EE cells
107  if (EEDetId::validHashIndex(cellid)){
108  uint32_t rawid = EEDetId::unhashIndex(cellid);
109  EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
110  if (value_ptr == payload->end())
111  continue; // cell absent from payload
112 
113  float weight = (float)(*value_ptr);
114  EEDetId myEEId(rawid);
115  if(myEEId.zside() == -1)
116  fillWithValue(myEEId.ix(), myEEId.iy(), weight);
117  else
118  fillWithValue(myEEId.ix() + IX_MAX + EEhistSplit, myEEId.iy(), weight);
119  } // validDetId
120  } // loop over cellid
121 
122  } // payload
123  } // loop over IOV's (1 in this case)
124  return true;
125  }// fill method
126 
127  };
128 
129 
130  /*************************************************
131  2d plot of Ecal Time Calib Constants of 1 IOV
132  *************************************************/
133  class EcalTimeCalibConstantsPlot : public cond::payloadInspector::PlotImage<EcalTimeCalibConstants> {
134 
135  public:
136  EcalTimeCalibConstantsPlot() : cond::payloadInspector::PlotImage<EcalTimeCalibConstants>("Ecal Time Calib Constants- map ") {
137  setSingleIov( true );
138  }
139 
140  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
141  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
142  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
143  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
144 
145  auto iov = iovs.front();
146  std::shared_ptr<EcalTimeCalibConstants> payload = fetchPayload( std::get<1>(iov) );
147  unsigned int run = std::get<0>(iov);
148 
149  if( payload.get() ){
150 
151  if (payload->barrelItems().empty())
152  return false;
153 
154  fillEBMap_SingleIOV<EcalTimeCalibConstants>(payload, barrel);
155 
156 
157  if (payload->endcapItems().empty())
158  return false;
159 
160  fillEEMap_SingleIOV<EcalTimeCalibConstants>(payload, endc_m, endc_p);
161 
162  } // payload
163 
164  gStyle->SetPalette(1);
165  gStyle->SetOptStat(0);
166  TCanvas canvas("CC map","CC map", 1600, 450);
167  TLatex t1;
168  t1.SetNDC();
169  t1.SetTextAlign(26);
170  t1.SetTextSize(0.05);
171  t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Constants, IOV %i", run));
172 
173  float xmi[3] = {0.0 , 0.24, 0.76};
174  float xma[3] = {0.24, 0.76, 1.00};
175  TPad** pad = new TPad*;
176  for (int obj = 0; obj < 3; obj++) {
177  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
178  pad[obj]->Draw();
179  }
180  // EcalDrawMaps ICMap;
181  pad[0]->cd();
182  // ICMap.DrawEE(endc_m, 0., 2.);
183  DrawEE(endc_m, -2.5, 2.5);
184  pad[1]->cd();
185  // ICMap.DrawEB(barrel, 0., 2.);
186  DrawEB(barrel, -2.5, 2.5);
187  pad[2]->cd();
188  // ICMap.DrawEE(endc_p, 0., 2.);
189  DrawEE(endc_p, -2.5, 2.5);
190 
191  std::string ImageName(m_imageFileName);
192  canvas.SaveAs(ImageName.c_str());
193  return true;
194  }// fill method
195  };
196 
197 
198  /*****************************************************************
199  2d plot of Ecal Time Calib Constants difference between 2 IOVs
200  *****************************************************************/
201  class EcalTimeCalibConstantsDiff : public cond::payloadInspector::PlotImage<EcalTimeCalibConstants> {
202 
203  public:
204  EcalTimeCalibConstantsDiff() : cond::payloadInspector::PlotImage<EcalTimeCalibConstants>("Ecal Time Calib Constants difference ") {
205  setSingleIov(false);
206  }
207 
208  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
209  TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
210  TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
211  TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
212  float pEBmin, pEEmin, pEBmax, pEEmax;
213  pEBmin = 10.;
214  pEEmin = 10.;
215  pEBmax = -10.;
216  pEEmax = -10.;
217 
218  unsigned int run[2], irun = 0;
219  float pEB[kEBChannels], pEE[kEEChannels];
220  for ( auto const & iov: iovs) {
221  std::shared_ptr<EcalTimeCalibConstants> payload = fetchPayload( std::get<1>(iov) );
222  run[irun] = std::get<0>(iov);
223 
224  if( payload.get() ){
225 
226  if (payload->barrelItems().empty())
227  return false;
228 
229  fillEBMap_DiffIOV<EcalTimeCalibConstants>(payload, barrel, irun, pEB, pEBmin, pEBmax);
230 
231  if (payload->endcapItems().empty())
232  return false;
233 
234  fillEEMap_DiffIOV<EcalTimeCalibConstants>(payload, endc_m, endc_p, irun, pEE, pEEmin, pEEmax);
235 
236  }// payload
237  irun++;
238 
239  }// loop over IOVs
240 
241  gStyle->SetPalette(1);
242  gStyle->SetOptStat(0);
243  TCanvas canvas("CC map","CC map", 1600, 450);
244  TLatex t1;
245  t1.SetNDC();
246  t1.SetTextAlign(26);
247  t1.SetTextSize(0.05);
248  t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Constants Diff, IOV %i - %i", run[1], run[0]));
249 
250  float xmi[3] = {0.0 , 0.24, 0.76};
251  float xma[3] = {0.24, 0.76, 1.00};
252  TPad** pad = new TPad*;
253 
254  for (int obj = 0; obj < 3; obj++) {
255  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
256  pad[obj]->Draw();
257  }
258 
259  pad[0]->cd();
260  DrawEE(endc_m, pEEmin, pEEmax);
261  pad[1]->cd();
262  DrawEB(barrel, pEBmin, pEBmax);
263  pad[2]->cd();
264  DrawEE(endc_p, pEEmin, pEEmax);
265 
266  std::string ImageName(m_imageFileName);
267  canvas.SaveAs(ImageName.c_str());
268  return true;
269  }// fill method
270  };
271 
272 
273 
274 /*******************************************************
275  2d plot of Ecal Time Calib Constants Summary of 1 IOV
276  *******************************************************/
277 class EcalTimeCalibConstantsSummaryPlot: public cond::payloadInspector::PlotImage<EcalTimeCalibConstants>{
278  public:
279  EcalTimeCalibConstantsSummaryPlot():
280  cond::payloadInspector::PlotImage<EcalTimeCalibConstants>("Ecal Time Calib Constants Summary- map "){
281  setSingleIov(true);
282  }
283 
284  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)override {
285  auto iov=iovs.front();
286  std::shared_ptr <EcalTimeCalibConstants> payload = fetchPayload(std::get<1> (iov));
287  unsigned int run=std::get<0> (iov);
288  TH2F* align;
289  int NbRows;
290 
291  if(payload.get()){
292  NbRows=2;
293  align=new TH2F("", "", 0, 0, 0, 0, 0, 0);
294 
295 
296  float mean_x_EB=0.0f;
297  float mean_x_EE=0.0f;
298 
299  float rms_EB=0.0f;
300  float rms_EE=0.0f;
301 
302  int num_x_EB=0;
303  int num_x_EE=0;
304 
305 
306  payload->summary(mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
307  fillTableWithSummary(align, "Ecal Time Calib Constants", mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
308  }else
309  return false;
310 
311  gStyle->SetPalette(1);
312  gStyle->SetOptStat(0);
313  TCanvas canvas("CC map", "CC map", 1000, 1000);
314  TLatex t1;
315  t1.SetNDC();
316  t1.SetTextAlign(26);
317  t1.SetTextSize(0.04);
318  t1.SetTextColor(2);
319  t1.DrawLatex(0.5, 0.96,Form("Ecal Time Calib Constants Summary, IOV %i", run));
320 
321 
322  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
323  pad->Draw();
324  pad->cd();
325  align->Draw("TEXT");
326 
327  drawTable(NbRows,4);
328 
329  std::string ImageName(m_imageFileName);
330  canvas.SaveAs(ImageName.c_str());
331 
332  return true;
333  }
334 };
335 
336 }
337 
338 
339 // Register the classes as boost python plugin
341  PAYLOAD_INSPECTOR_CLASS( EcalTimeCalibConstantsEBMap );
342  PAYLOAD_INSPECTOR_CLASS( EcalTimeCalibConstantsEEMap );
343  PAYLOAD_INSPECTOR_CLASS( EcalTimeCalibConstantsPlot );
344  PAYLOAD_INSPECTOR_CLASS( EcalTimeCalibConstantsDiff );
345  PAYLOAD_INSPECTOR_CLASS( EcalTimeCalibConstantsSummaryPlot );
346 }
void fillTableWithSummary(TH2F *&align, std::string title, const float &mean_x_EB, const float &rms_EB, const int &num_x_EB, const float &mean_x_EE, const float &rms_EE, const int &num_x_EE)
Definition: weight.py:1
void fillWithValue(float xvalue, float yvalue, float weight=1)
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:65
static bool validHashIndex(int i)
Definition: EEDetId.h:239
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
void DrawEB(TH2F *ebmap, float min, float max)
Definition: EcalDrawUtils.h:4
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
static const int MIN_HASH
Definition: EBDetId.h:149
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::vector< Item >::const_iterator const_iterator
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:110
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
void drawTable(int nbRows, int nbColumns)