CMS 3D CMS Logo

EcalTPGFineGrainStripEE_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 #include <memory>
19 #include <array>
20 
21 namespace {
22  enum { NTCC = 108, NTower = 28, NStrip = 5, NXtal = 5 };
23  enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 }; // endcaps lower and upper bounds on x and y
24 
25  /***********************************************
26  2d plot of ECAL TPGStripStatus of 1 IOV
27  ************************************************/
28  class EcalTPGFineGrainStripEEPlot : public cond::payloadInspector::PlotImage<EcalTPGFineGrainStripEE> {
29  public:
30  EcalTPGFineGrainStripEEPlot()
31  : cond::payloadInspector::PlotImage<EcalTPGFineGrainStripEE>("EcalTPGFineGrainStripEE - map ") {
32  setSingleIov(true);
33  }
34 
35  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
36  TH2F* endc_thresh_p =
37  new TH2F("EE+", "EE+ TPGFineGrainStrip Threshold", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
38  TH2F* endc_thresh_m =
39  new TH2F("EE-", "EE- TPGFineGrainStrip Threshold", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
40 
41  TH2F* endc_lut_p =
42  new TH2F("EE+", "EE+ TPG Crystal Status Lut", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
43  TH2F* endc_lut_m =
44  new TH2F("EE-", "EE- TPG Crystal Status Lut", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
45  int EEcount[2] = {0, 0};
46 
47  std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
48  std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
49  if (!f.good()) {
50  std::cout << "EcalTPGFineGrainStripEE File EEMap.txt not found" << std::endl;
51  throw cms::Exception("FileNotFound");
52  }
53 
54  uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
55  int NbrawEE[NTCC][NTower][NStrip];
56  for (int TCC = 0; TCC < NTCC; TCC++)
57  for (int TT = 0; TT < NTower; TT++)
58  for (int ST = 0; ST < NStrip; ST++)
59  NbrawEE[TCC][TT][ST] = 0;
60 
61  while (!f.eof()) {
62  int ix, iy, iz, CL;
63  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
64  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
65  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
66  pseudostrip_in_TCC >> pseudostrip_in_TT;
67 
68  EEDetId detid(ix, iy, iz, EEDetId::XYMODE);
69  uint32_t rawId = detid.denseIndex();
70  if (tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal) {
71  // std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT "<< pseudostrip_in_TT
72  // <<" xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
73  } else {
74  rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
75  NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
76  }
77  } // read EEMap file
78 
79  f.close();
80  //double wei[2] = {0., 0.};
81 
82  auto iov = iovs.front();
83  std::shared_ptr<EcalTPGFineGrainStripEE> payload = fetchPayload(std::get<1>(iov));
84  unsigned int run = std::get<0>(iov);
85  double max1 = 1.0, max2 = 1.0;
86 
87  if (payload.get()) {
88  const EcalTPGFineGrainStripEEMap& stripMap = (*payload).getMap();
89  // std::cout << " tower map size " << stripMap.size() << std::endl;
91  for (itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
92  EcalTPGFineGrainStripEE::Item item = (*itSt).second;
93 
94  // let's decode the ID
95  int strip = itSt->first / 8;
96  int pseudostrip = strip & 0x7;
97  strip /= 8;
98  int tt = strip & 0x7F;
99  strip /= 128;
100  int tccid = strip & 0x7F;
101  int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
102  //if(NbXtalInStrip != NXtal) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
103  // << " Nx Xtals " << NbXtalInStrip << std::endl;
104 
105  for (int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
106  uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
107  // std::cout << " rawid " << rawId << std::endl;
109  float x = (float)detid.ix();
110  float y = (float)detid.iy();
111  int iz = detid.zside();
112  if (iz == -1)
113  iz++;
114  //if(Xtal == 0) wei[iz] += 1.;
115  if (iz == 0) {
116  endc_thresh_m->Fill(x + 0.5, y + 0.5, item.threshold);
117  endc_lut_m->Fill(x + 0.5, y + 0.5, item.lut);
118  EEcount[0]++;
119 
120  if (max1 < item.threshold)
121  max1 = item.threshold;
122 
123  if (max2 < item.lut)
124  max2 = item.lut;
125 
126  } else {
127  endc_thresh_p->Fill(x + 0.5, y + 0.5, item.threshold);
128  endc_lut_p->Fill(x + 0.5, y + 0.5, item.lut);
129  EEcount[1]++;
130 
131  if (max1 < item.threshold)
132  max1 = item.threshold;
133 
134  if (max2 < item.lut)
135  max2 = item.lut;
136  }
137  }
138  }
139  } // payload
140  // std::cout << " nb strip EE- " << wei[0] << " EE+ " << wei[1] << std::endl;
141 
142  gStyle->SetPalette(1);
143  gStyle->SetOptStat(0);
144  const Int_t NRGBs = 5;
145  const Int_t NCont = 255;
146 
147  Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
148  Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
149  Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
150  Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
151  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
152  gStyle->SetNumberContours(NCont);
153 
154  Double_t w = 1200;
155  Double_t h = 1400;
156  TCanvas canvas("c", "c", w, h);
157 
158  TLatex t1;
159  t1.SetNDC();
160  t1.SetTextAlign(26);
161  t1.SetTextSize(0.04);
162  t1.DrawLatex(0.5, 0.96, Form("Ecal TPG Fine Grain StripEE, IOV %i", run));
163 
164  float xmi[4] = {0.0, 0.5, 0.0, 0.5};
165  float xma[4] = {0.5, 1.0, 0.5, 1.0};
166 
167  float ymi[4] = {0.47, 0.47, 0.0, 0.0};
168  float yma[4] = {0.94, 0.94, 0.47, 0.47};
169  std::array<std::unique_ptr<TPad>, 4> pad;
170  for (int obj = 0; obj < 4; obj++) {
171  pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]);
172  pad[obj]->Draw();
173  }
174 
175  // t1.DrawLatex(0.2, 0.94, Form("%i crystals", EBstat));
176 
177  pad[0]->cd();
178  DrawEE(endc_thresh_m, 0., max1);
179  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[0]));
180 
181  pad[1]->cd();
182  DrawEE(endc_thresh_p, 0., max1);
183  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[1]));
184 
185  pad[2]->cd();
186  DrawEE(endc_lut_m, 0., max2);
187  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[0]));
188 
189  pad[3]->cd();
190  DrawEE(endc_lut_p, 0., max2);
191  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[1]));
192 
193  std::string ImageName(m_imageFileName);
194 
195  canvas.SaveAs(ImageName.c_str());
196 
197  delete endc_lut_p;
198  delete endc_lut_m;
199  delete endc_thresh_p;
200  delete endc_thresh_m;
201  return true;
202  } // fill method
203  };
204 
205 } // namespace
206 
207 // Register the classes as boost python plugin
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:220
std::map< uint32_t, EcalTPGFineGrainStripEE::Item > EcalTPGFineGrainStripEEMap
T w() const
static const int XYMODE
Definition: EEDetId.h:335
int ix() const
Definition: EEDetId.h:77
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: TTTypes.h:54
std::map< uint32_t, EcalTPGFineGrainStripEE::Item >::const_iterator EcalTPGFineGrainStripEEMapIterator
double f[11][100]
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
int zside() const
Definition: EEDetId.h:71
Definition: plugin.cc:23
def canvas(sub, attr)
Definition: svgfig.py:482
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
int iy() const
Definition: EEDetId.h:83