CMS 3D CMS Logo

EcalTPGStripStatus_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 "TStyle.h"
14 #include "TLine.h"
15 #include "TLatex.h"
16 
17 #include <string>
18 
19 namespace {
20  enum {NTCC = 108, NTower = 28, NStrip = 5, NXtal = 5};
21  enum {IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100}; // endcaps lower and upper bounds on x and y
22 
23  /***********************************************
24  2d plot of ECAL TPGStripStatus of 1 IOV
25  ************************************************/
26  class EcalTPGStripStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGStripStatus> {
27 
28  public:
29  EcalTPGStripStatusPlot() : cond::payloadInspector::PlotImage<EcalTPGStripStatus>("ECAL TPGStripStatus - map ") {
30  setSingleIov(true);
31  }
32 
33  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
34  TH2F* endc_p = new TH2F("EE+","EE+ TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
35  TH2F* endc_m = new TH2F("EE-","EE- TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
36  int EEstat[2] = {0, 0};
37 
38  std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
39  std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
40  if (!f.good()) {
41  std::cout << "EcalTPGStripStatus File EEMap.txt not found" << std::endl;
42  throw cms::Exception("FileNotFound");
43  }
44 
45  uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
46  int NbrawEE[NTCC][NTower][NStrip];
47  for(int TCC = 0; TCC < NTCC; TCC++)
48  for(int TT = 0; TT < NTower; TT++)
49  for(int ST = 0; ST < NStrip; ST++)
50  NbrawEE[TCC][TT][ST] = 0;
51  while ( ! f.eof()) {
52  int ix, iy, iz, CL;
53  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
54  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
55  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip
56  >> tccid >> tower >> pseudostrip_in_TCC >> pseudostrip_in_TT ;
57  EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
58  uint32_t rawId = detid.denseIndex();
59  if(tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal)
60  std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT "<< pseudostrip_in_TT
61  <<" xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
62  else {
63  rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
64  NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
65  }
66  } // read EEMap file
67  f.close();
68  double wei[2] = {0., 0.};
69 
70  auto iov = iovs.front();
71  std::shared_ptr<EcalTPGStripStatus> payload = fetchPayload( std::get<1>(iov) );
72  unsigned int run = std::get<0>(iov);
73  if( payload.get() ){
74  const EcalTPGStripStatusMap &stripMap = (*payload).getMap();
75  // std::cout << " tower map size " << stripMap.size() << std::endl;
77  for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
78  if(itSt->second > 0) {
79  // let's decode the ID
80  int strip = itSt->first/8;
81  int pseudostrip = strip & 0x7;
82  strip /= 8;
83  int tt = strip & 0x7F;
84  strip /= 128;
85  int tccid = strip & 0x7F;
86  int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
87  if(NbXtalInStrip != NXtal) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
88  << " Nx Xtals " << NbXtalInStrip << std::endl;
89  // std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
90  // << " Nx Xtals " << NbXtalInStrip << std::endl;
91  for(int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
92  uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
93  // std::cout << " rawid " << rawId << std::endl;
95  float x = (float)detid.ix();
96  float y = (float)detid.iy();
97  int iz = detid.zside();
98  if(iz == -1) iz++;
99  if(Xtal == 0) wei[iz] += 1.;
100  if(iz == 0) {
101  endc_m->Fill(x + 0.5, y + 0.5, wei[iz]);
102  EEstat[0]++;
103  }
104  else {
105  endc_p->Fill(x + 0.5, y + 0.5, wei[iz]);
106  EEstat[1]++;
107  }
108  // std::cout << " x " << x << " y " << y << " z " << iz << std::endl;
109  }
110  }
111  }
112  } // payload
113  // std::cout << " nb strip EE- " << wei[0] << " EE+ " << wei[1] << std::endl;
114 
115  gStyle->SetPalette(1);
116  gStyle->SetOptStat(0);
117  const Int_t NRGBs = 5;
118  const Int_t NCont = 255;
119 
120  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
121  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
122  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
123  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
124  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
125  gStyle->SetNumberContours(NCont);
126  // TCanvas canvas("CC map","CC map", 1600, 450);
127  Double_t w = 1200;
128  Double_t h = 650;
129  TCanvas canvas("c", "c", w, h);
130  // canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
131 
132  TLatex t1;
133  t1.SetNDC();
134  t1.SetTextAlign(26);
135  t1.SetTextSize(0.05);
136  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGStripStatus, IOV %i", run));
137 
138  float xmi[2] = {0.0, 0.5};
139  float xma[2] = {0.5, 1.0};
140  TPad** pad = new TPad*;
141  for (int obj = 0; obj < 2; obj++) {
142  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
143  pad[obj]->Draw();
144  }
145 
146  pad[0]->cd();
147  DrawEE(endc_m, 0., wei[0]);
148  t1.SetTextSize(0.03);
149  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[0]));
150  pad[1]->cd();
151  DrawEE(endc_p, 0., wei[1]);
152  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[1]));
153 
154  std::string ImageName(m_imageFileName);
155  canvas.SaveAs(ImageName.c_str());
156  return true;
157  }// fill method
158  };
159 
160  /***************************************************************
161  2d plot of ECAL TPGStripStatus difference between 2 IOVs
162  ****************************************************************/
163  class EcalTPGStripStatusDiff : public cond::payloadInspector::PlotImage<EcalTPGStripStatus> {
164 
165  public:
166  EcalTPGStripStatusDiff() : cond::payloadInspector::PlotImage<EcalTPGStripStatus>("ECAL TPGStripStatus difference") {
167  setSingleIov(false);
168  }
169 
170  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
171  TH2F* endc_p = new TH2F("EE+","EE+ TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
172  TH2F* endc_m = new TH2F("EE-","EE- TPG Strip Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
173  int EEstat[2][2] = {{0, 0}, {0, 0}};
174 
175  std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
176  std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
177  if (!f.good()) {
178  std::cout << "EcalTPGStripStatus File EEMap.txt not found" << std::endl;
179  throw cms::Exception("FileNotFound");
180  }
181 
182  uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
183  int NbrawEE[NTCC][NTower][NStrip];
184  for(int TCC = 0; TCC < NTCC; TCC++)
185  for(int TT = 0; TT < NTower; TT++)
186  for(int ST = 0; ST < NStrip; ST++)
187  NbrawEE[TCC][TT][ST] = 0;
188  while ( ! f.eof()) {
189  int ix, iy, iz, CL;
190  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
191  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
192  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip
193  >> tccid >> tower >> pseudostrip_in_TCC >> pseudostrip_in_TT ;
194  EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
195  uint32_t rawId = detid.denseIndex();
196  if(tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal)
197  std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT "<< pseudostrip_in_TT
198  <<" xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
199  else {
200  rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
201  NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
202  }
203  } // read EEMap file
204  f.close();
205 
206  unsigned int run[2] = {0, 0}, irun = 0;
207  int vEE[100];
208  int istat = 0;
209  for ( auto const & iov: iovs) {
210  std::shared_ptr<EcalTPGStripStatus> payload = fetchPayload( std::get<1>(iov) );
211  run[irun] = std::get<0>(iov);
212  if( payload.get() ){
213  const EcalTPGStripStatusMap &stripMap = (*payload).getMap();
214  // std::cout << " tower map size " << stripMap.size() << std::endl;
216  for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
217  if(itSt->second > 0) {
218  int ID = itSt->first/8;
219  if(irun == 0 && istat < 100) {
220  vEE[istat] = ID;
221  // std::cout << " strip " << ID << " found in run 1" << std::endl;
222  istat++;
223  if(istat == 100) std::cout << " limit on number of strips reached, stop keeping others" << std::endl;
224  }
225  else {
226  bool found = false;
227  for(int is = 0; is < istat; is++) {
228  // std::cout << " checking " << ID << " against " << vEE[is] << std::endl;
229  if(vEE[is] == ID) {
230  // std::cout << " strip " << ID << " already in run 1" << std::endl;
231  found = true;
232  vEE[is] = -1;
233  break;
234  }
235  }
236  if(!found) {
237  // std::cout << " strip " << ID << " new, plot it" << std::endl;
238  // let's decode the ID
239  int strip = ID;
240  int pseudostrip = strip & 0x7;
241  strip /= 8;
242  int tt = strip & 0x7F;
243  strip /= 128;
244  int tccid = strip & 0x7F;
245  int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
246  if(NbXtalInStrip != NXtal) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
247  << " Nx Xtals " << NbXtalInStrip << std::endl;
248  for(int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
249  uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
250  // std::cout << " rawid " << rawId << std::endl;
251  EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
252  float x = (float)detid.ix();
253  float y = (float)detid.iy();
254  int iz = detid.zside();
255  if(iz == -1) iz++;
256  if(iz == 0) {
257  endc_m->Fill(x + 0.5, y + 0.5, 1.);
258  EEstat[0][0]++;
259  }
260  else {
261  endc_p->Fill(x + 0.5, y + 0.5, 1.);
262  EEstat[1][0]++;
263  }
264  // std::cout << " x " << x << " y " << y << " z " << iz << std::endl;
265  } // loop over crystals in strip
266  } // new strip
267  } // second run
268  }
269  } // loop over strips
270  } // payload
271  else return false;
272  irun++;
273  // std::cout << " nb of strips " << istat << std::endl;
274  } // loop over IOVs
275 
276  // now check if strips have disappered
277  for(int is = 0; is < istat; is++) {
278  if(vEE[is] != -1) {
279  // std::cout << " strip " << vEE[is] << " not found in run 2, plot it" << std::endl;
280  // let's decode the ID
281  int strip = vEE[is];
282  int pseudostrip = strip & 0x7;
283  strip /= 8;
284  int tt = strip & 0x7F;
285  strip /= 128;
286  int tccid = strip & 0x7F;
287  int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
288  if(NbXtalInStrip != NXtal) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
289  << " Nx Xtals " << NbXtalInStrip << std::endl;
290  for(int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
291  uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
292  // std::cout << " rawid " << rawId << std::endl;
293  EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
294  float x = (float)detid.ix();
295  float y = (float)detid.iy();
296  int iz = detid.zside();
297  if(iz == -1) iz++;
298  if(iz == 0) {
299  endc_m->Fill(x + 0.5, y + 0.5, -1.);
300  EEstat[0][1]++;
301  }
302  else {
303  endc_p->Fill(x + 0.5, y + 0.5, -1.);
304  EEstat[1][1]++;
305  }
306  // std::cout << " x " << x << " y " << y << " z " << iz << std::endl;
307  } // loop over crystals in strip
308  } // new strip
309  } // loop over run 1 strips
310 
311  gStyle->SetPalette(1);
312  gStyle->SetOptStat(0);
313  const Int_t NRGBs = 5;
314  const Int_t NCont = 255;
315 
316  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
317  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
318  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
319  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
320  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
321  gStyle->SetNumberContours(NCont);
322  // TCanvas canvas("CC map","CC map", 1600, 450);
323  Double_t w = 1200;
324  Double_t h = 650;
325  TCanvas canvas("c", "c", w, h);
326  // canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
327 
328  TLatex t1;
329  t1.SetNDC();
330  t1.SetTextAlign(26);
331  t1.SetTextSize(0.05);
332  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGStripStatus, IOV %i - %i", run[1], run[0]));
333 
334  float xmi[2] = {0.0, 0.5};
335  float xma[2] = {0.5, 1.0};
336  TPad** pad = new TPad*;
337  for (int obj = 0; obj < 2; obj++) {
338  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
339  pad[obj]->Draw();
340  }
341 
342  pad[0]->cd();
343  DrawEE(endc_m, -1.0, 1.0);
344  t1.SetTextSize(0.03);
345  t1.DrawLatex(0.15, 0.92, Form("new %i old %i", EEstat[0][0], EEstat[0][1]));
346  pad[1]->cd();
347  DrawEE(endc_p, -1.0, 1.0);
348  t1.DrawLatex(0.15, 0.92, Form("new %i old %i", EEstat[1][0], EEstat[1][1]));
349 
350  std::string ImageName(m_imageFileName);
351  canvas.SaveAs(ImageName.c_str());
352  return true;
353  }// fill method
354  };
355 
356 
357 
358 /*****************************************
359  2d plot of EcalTPGStripStatus Error Summary of 1 IOV
360  ******************************************/
361 class EcalTPGStripStatusSummaryPlot: public cond::payloadInspector::PlotImage<EcalTPGStripStatus> {
362 public:
363  EcalTPGStripStatusSummaryPlot() :
364  cond::payloadInspector::PlotImage<EcalTPGStripStatus>("Ecal TPGStrip Status Summary - map ") {
365  setSingleIov(true);
366  }
367 
368  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)override {
369 
370  auto iov = iovs.front(); //get reference to 1st element in the vector iovs
371  std::shared_ptr < EcalTPGStripStatus > payload = fetchPayload(std::get < 1 > (iov)); //std::get<1>(iov) refers to the Hash in the tuple iov
372  unsigned int run = std::get < 0 > (iov); //referes to Time_t in iov.
373  TH2F* align; //pointer to align which is a 2D histogram
374 
375  int NbRows=1;
376  int NbColumns=2;
377 
378  if (payload.get()) { //payload is an iov retrieved from payload using hash.
379  const EcalTPGStripStatusMap &stripMap=(*payload).getMap();
380 
381 
382  align =new TH2F("Ecal TPGStrip Status Summary","Total NumberOfMasked",
383  NbColumns, 0, NbColumns, NbRows, 0, NbRows);
384 
385  int NbMaskedTT = 0;
386 
387 
388  for(EcalTPGStripStatusMapIterator it = stripMap.begin(); it != stripMap.end(); ++it)
389  if((*it).second>0)
390  NbMaskedTT++;
391 
392  align->Fill(0.5, 0.5, stripMap.size());
393  align->Fill(1.5, 0.5, NbMaskedTT);
394 
395  } // if payload.get()
396  else
397  return false;
398 
399  gStyle->SetPalette(1);
400  gStyle->SetOptStat(0);
401  TCanvas canvas("CC map", "CC map", 1000, 1000);
402  TLatex t1;
403  t1.SetNDC();
404  t1.SetTextAlign(26);
405  t1.SetTextSize(0.04);
406  t1.SetTextColor(2);
407  t1.DrawLatex(0.5, 0.96,Form("Endcap:Number of masked Trigger Strips, IOV %i", run));
408 
409 
410  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
411  pad->Draw();
412  pad->cd();
413  align->Draw("TEXT");
414 
415  drawTable(NbRows, NbColumns);
416 
417  align->GetXaxis()->SetTickLength(0.);
418  align->GetXaxis()->SetLabelSize(0.);
419  align->GetYaxis()->SetTickLength(0.);
420  align->GetYaxis()->SetLabelSize(0.);
421 
422  std::string ImageName(m_imageFileName);
423  canvas.SaveAs(ImageName.c_str());
424  return true;
425  } // fill method
426 
427 };
428 
429 
430 
431 } // close namespace
432 
433 // Register the classes as boost python plugin
435  PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusPlot);
436  PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusDiff);
437  PAYLOAD_INSPECTOR_CLASS(EcalTPGStripStatusSummaryPlot);
438 }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:220
int ix() const
Definition: EEDetId.h:76
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
uint32_t ID
Definition: Definitions.h:26
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
static const int XYMODE
Definition: EEDetId.h:339
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
int zside() const
Definition: EEDetId.h:70
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
double f[11][100]
int iy() const
Definition: EEDetId.h:82
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
def green(string)
uint32_t denseIndex() const
Definition: EEDetId.h:192
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:481
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
void drawTable(int nbRows, int nbColumns)
std::map< uint32_t, uint16_t >::const_iterator EcalTPGStripStatusMapIterator