CMS 3D CMS Logo

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