CMS 3D CMS Logo

EcalTPGTowerStatus_PayloadInspector.cc
Go to the documentation of this file.
8 
9 // the data format of the condition to be inspected
11 
12 #include "TH2F.h"
13 #include "TCanvas.h"
14 #include "TStyle.h"
15 #include "TLine.h"
16 #include "TLatex.h"
17 
18 #include <string>
19 
20 namespace {
21  enum {kEBTotalTowers = 2448, kEETotalTowers = 1584};
22  enum {MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 17, MAX_IPHI = 72}; // barrel lower and upper bounds on eta and phi
23 
24  /***********************************************
25  2d plot of ECAL TPGTowerStatus of 1 IOV
26  ************************************************/
27  class EcalTPGTowerStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
28 
29  public:
30  EcalTPGTowerStatusPlot() : cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("ECAL TPGTowerStatus - map ") {
31  setSingleIov(true);
32  }
33 
34  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
35  TH2F* barrel = new TH2F("EB","EB TPG Tower Status", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
36  int EBstat = 0, EEstat = 0;
37 
38  auto iov = iovs.front();
39  std::shared_ptr<EcalTPGTowerStatus> payload = fetchPayload( std::get<1>(iov) );
40  unsigned int run = std::get<0>(iov);
41  if( payload.get() ){
42  const EcalTPGTowerStatusMap &towerMap = (*payload).getMap();
43  // std::cout << " tower map size " << towerMap.size() << std::endl;
45  for(it = towerMap.begin(); it != towerMap.end(); ++it) {
46  if((*it).second > 0) {
47  EcalTrigTowerDetId ttId((*it).first);
48  int ieta = ttId.ieta();
49  // if(ieta < 0) ieta--; // -1 to -17
50  int iphi = ttId.iphi() - 1; // 0 to 71
51  // std::cout << " sub det " << ttId.subDet() << " phi " << iphi << " eta " << ieta << std::endl;
52  // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
53  ieta--;
54  if(ttId.subDet() == 1) { // barrel
55  barrel->Fill(iphi, ieta, (*it).second);
56  EBstat++;
57  }
58  else EEstat++;
59  }
60  }
61  } // payload
62 
63  gStyle->SetPalette(1);
64  gStyle->SetOptStat(0);
65  // TCanvas canvas("CC map","CC map", 1600, 450);
66  Double_t w = 1400;
67  Double_t h = 1200;
68  TCanvas canvas("c", "c", w, h);
69  // canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
70 
71  TLatex t1;
72  t1.SetNDC();
73  t1.SetTextAlign(26);
74  t1.SetTextSize(0.05);
75  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGTowerStatus, IOV %i", run));
76 
77  TPad** pad = new TPad*;
78  for (int obj = 0; obj < 1; obj++) {
79  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), 0.0, 0.04, 1.0, 0.94);
80  pad[obj]->Draw();
81  }
82  t1.SetTextSize(0.03);
83  t1.DrawLatex(0.2, 0.88, Form("%i towers", EBstat));
84  t1.DrawLatex(0.5, 0.02, Form("EE : %i tower(s)", EEstat));
85  // canvas.cd();
86  pad[0]->cd();
87  // barrel->SetStats(false);
88  barrel->Draw("col");
89  TLine* l = new TLine(0., 0., 0., 0.);
90  l->SetLineWidth(1);
91  for(int i = 0; i < MAX_IETA; i++) {
92  Double_t x = 4.+ (i * 4);
93  l = new TLine(x, -MAX_IETA, x, MAX_IETA);
94  l->Draw();
95  }
96  l = new TLine(0., 0., 72., 0.);
97  l->Draw();
98 
99  std::string ImageName(m_imageFileName);
100  canvas.SaveAs(ImageName.c_str());
101  return true;
102  }// fill method
103  };
104 
105  /************************************************************************
106  2d plot of ECAL TPGTowerStatus difference between 2 IOVs
107  ************************************************************************/
108  class EcalTPGTowerStatusDiff : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
109 
110  public:
111  EcalTPGTowerStatusDiff() : cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("ECAL TPGTowerStatus difference") {
112  setSingleIov(false);
113  }
114 
115  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
116  TH2F* barrel = new TH2F("EB","EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
117  // int EBstat[2] = {0, 0};
118  int EBstat = 0, EEstat = 0;
119 
120  unsigned int run[2] = {0, 0}, irun = 0, vEB[kEBTotalTowers];
121  // EcalTrigTowerDetId EBId[kEBTotalTowers];
122  for ( auto const & iov: iovs) {
123  std::shared_ptr<EcalTPGTowerStatus> payload = fetchPayload( std::get<1>(iov) );
124  run[irun] = std::get<0>(iov);
125  if( payload.get() ){
126  const EcalTPGTowerStatusMap &towerMap = (*payload).getMap();
127  // std::cout << " tower map size " << towerMap.size() << std::endl;
129  for(it = towerMap.begin(); it != towerMap.end(); ++it) {
130  EcalTrigTowerDetId ttId((*it).first);
131  int ieta = ttId.ieta();
132  if(ieta < 0) ieta--; // 1 to 17
133  int iphi = ttId.iphi() - 1; // 0 to 71
134  int towerId = ttId.hashedIndex();
135  int stat = (*it).second;
136  if(irun == 0) {
137  if(ttId.subDet() == 1) { // barrel
138  vEB[towerId] = stat;
139  if(stat > 0) { // bad tower
140  if(towerId >= kEBTotalTowers) std::cout << " strange tower Id " << towerId << std::endl;
141  else {
142  // std::cout << " phi " << iphi << " eta " << ieta << std::endl;
143  // EBId[towerId] = ttId;
144  }
145  }
146  } // barrel
147  else if(stat > 0) {
148  // std::cout << " EE phi " << iphi << " eta " << ieta << std::endl;
149  EEstat--;
150  }
151  } // 1st run
152  else { // 2nd run
153  if(ttId.subDet() == 1) { // barrel
154  if(stat > 0) { // bad tower
155  if(towerId >= kEBTotalTowers) std::cout << " strange tower Id " << towerId << std::endl;
156  // else std::cout << " phi " << iphi << " eta " << ieta << std::endl;
157  } // bad tower
158  int diff = stat - vEB[towerId];
159  // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
160  ieta--;
161  if(diff != 0) barrel->Fill(iphi, ieta, diff);
162  // vEB[towerId] = 0;
163  EBstat += diff;
164  } // barrel
165  else if(stat > 0) {
166  // std::cout << " EE phi " << iphi << " eta " << ieta << std::endl;
167  EEstat++;
168  }
169  } // 2nd run
170  } // loop over towers
171  } // payload
172  else return false;
173  irun++;
174  } // loop over IOVs
175  /*
176  // now check if towers have disappered
177  for(int it = 0; it < kEBTotalTowers; it++) {
178  if(vEB[it] != 0) {
179  std::cout << " tower " << vEB[it] << " not found in run 2, plot it" << std::endl;
180  EcalTrigTowerDetId ttId = EBId[it];
181  int ieta = ttId.ieta();
182  // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
183  ieta--;
184  int iphi = ttId.iphi() - 1; // 0 to 71
185  barrel->Fill(iphi, ieta, vEB[it]);
186  }
187  }
188  */
189  gStyle->SetPalette(1);
190  gStyle->SetOptStat(0);
191  Double_t w = 1400;
192  Double_t h = 1200;
193  TCanvas canvas("c", "c", w, h);
194  // canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
195 
196  TLatex t1;
197  t1.SetNDC();
198  t1.SetTextAlign(26);
199  t1.SetTextSize(0.05);
200  t1.DrawLatex(0.5, 0.96, Form("Ecal TPGTowerStatus, IOV %i - %i", run[1], run[0]));
201 
202  TPad** pad = new TPad*;
203  for (int obj = 0; obj < 1; obj++) {
204  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), 0.0, 0.04, 1.0, 0.94);
205  pad[obj]->Draw();
206  }
207  t1.SetTextSize(0.03);
208  t1.DrawLatex(0.2, 0.88, Form("%i tower(s)", EBstat));
209  t1.DrawLatex(0.5, 0.02, Form("EE : %i tower(s)", EEstat));
210 
211  pad[0]->cd();
212  // barrel->SetStats(false);
213  barrel->Draw("col");
214  TLine* l = new TLine(0., 0., 0., 0.);
215  l->SetLineWidth(1);
216  for(int i = 0; i < MAX_IETA; i++) {
217  Double_t x = 4.+ (i * 4);
218  l = new TLine(x, -MAX_IETA, x, MAX_IETA);
219  l->Draw();
220  }
221  l = new TLine(0., 0., 72., 0.);
222  l->Draw();
223 
224  std::string ImageName(m_imageFileName);
225  canvas.SaveAs(ImageName.c_str());
226  return true;
227  }// fill method
228  };
229 
230 
231 
232 /*****************************************
233  2d plot of EcalTPGTowerStatus Error Summary of 1 IOV
234  ******************************************/
235 class EcalTPGTowerStatusSummaryPlot: public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
236 public:
237  EcalTPGTowerStatusSummaryPlot() :
238  cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("Ecal TPGTower Status Summary - map ") {
239  setSingleIov(true);
240  }
241 
242  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs)override {
243 
244  auto iov = iovs.front(); //get reference to 1st element in the vector iovs
245  std::shared_ptr < EcalTPGTowerStatus > payload = fetchPayload(std::get < 1 > (iov)); //std::get<1>(iov) refers to the Hash in the tuple iov
246  unsigned int run = std::get < 0 > (iov); //referes to Time_t in iov.
247  TH2F* align; //pointer to align which is a 2D histogram
248 
249  int NbRows=1;
250  int NbColumns=2;
251 
252  if (payload.get()) { //payload is an iov retrieved from payload using hash.
253  const EcalTPGTowerStatusMap &towerMap=(*payload).getMap();
254 
255 
256  align =new TH2F("Ecal TPGTower Status Summary","Total NumberOfMasked",
257  NbColumns, 0, NbColumns, NbRows, 0, NbRows);
258 
259  int NbMaskedTT = 0;
260 
261 
262  for(EcalTPGTowerStatusMapIterator it = towerMap.begin(); it != towerMap.end(); ++it)
263  if((*it).second>0)
264  NbMaskedTT++;
265 
266  align->Fill(0.5, 0.5, towerMap.size());
267  align->Fill(1.5, 0.5, NbMaskedTT);
268 
269  } // if payload.get()
270  else
271  return false;
272 
273  gStyle->SetPalette(1);
274  gStyle->SetOptStat(0);
275  TCanvas canvas("CC map", "CC map", 1000, 1000);
276  TLatex t1;
277  t1.SetNDC();
278  t1.SetTextAlign(26);
279  t1.SetTextSize(0.04);
280  t1.SetTextColor(2);
281  t1.DrawLatex(0.5, 0.96,Form("Barrel masked Trigger Towers, IOV %i", run));
282 
283 
284  TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
285  pad->Draw();
286  pad->cd();
287  align->Draw("TEXT");
288 
289  drawTable(NbRows, NbColumns);
290 
291  align->GetXaxis()->SetTickLength(0.);
292  align->GetXaxis()->SetLabelSize(0.);
293  align->GetYaxis()->SetTickLength(0.);
294  align->GetYaxis()->SetLabelSize(0.);
295 
296  std::string ImageName(m_imageFileName);
297  canvas.SaveAs(ImageName.c_str());
298  return true;
299  } // fill method
300 
301 };
302 
303 
304 
305 } // close namespace
306 
307 // Register the classes as boost python plugin
309  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusPlot);
310  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusDiff);
311  PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusSummaryPlot);
312 }
std::map< uint32_t, uint16_t >::const_iterator EcalTPGTowerStatusMapIterator
std::map< uint32_t, uint16_t > EcalTPGTowerStatusMap
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
unsigned ttId(DetId const &)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
l1t::HGCalTowerID towerId
Definition: classes.h:36
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:482
void drawTable(int nbRows, int nbColumns)