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 
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 EcalTPGFineGrainStripEEPlot : public cond::payloadInspector::PlotImage<EcalTPGFineGrainStripEE> {
27 
28  public:
29  EcalTPGFineGrainStripEEPlot() : cond::payloadInspector::PlotImage<EcalTPGFineGrainStripEE>("EcalTPGFineGrainStripEE - map ") {
30  setSingleIov(true);
31  }
32 
33  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
34  TH2F* endc_thresh_p = new TH2F("EE+","EE+ TPGFineGrainStrip Threshold", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
35  TH2F* endc_thresh_m = new TH2F("EE-","EE- TPGFineGrainStrip Threshold", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
36 
37  TH2F* endc_lut_p = new TH2F("EE+","EE+ TPG Crystal Status Lut", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
38  TH2F* endc_lut_m = new TH2F("EE-","EE- TPG Crystal Status Lut", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
39  int EEcount[2] = {0, 0};
40 
41  std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
42  std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
43  if (!f.good()) {
44  std::cout << "EcalTPGFineGrainStripEE File EEMap.txt not found" << std::endl;
45  throw cms::Exception("FileNotFound");
46  }
47 
48  uint32_t rawEE[NTCC][NTower][NStrip][NXtal];
49  int NbrawEE[NTCC][NTower][NStrip];
50  for(int TCC = 0; TCC < NTCC; TCC++)
51  for(int TT = 0; TT < NTower; TT++)
52  for(int ST = 0; ST < NStrip; ST++)
53  NbrawEE[TCC][TT][ST] = 0;
54 
55  while ( ! f.eof()) {
56  int ix, iy, iz, CL;
57  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
58  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
59  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip
60  >> tccid >> tower >> pseudostrip_in_TCC >> pseudostrip_in_TT ;
61 
62  EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
63  uint32_t rawId = detid.denseIndex();
64  if(tccid > NTCC || tower > NTower || pseudostrip_in_TT > NStrip || xtal_in_pseudostrip > NXtal){
65  // std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT "<< pseudostrip_in_TT
66  // <<" xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
67  }else {
68  rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
69  NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
70  }
71  } // read EEMap file
72 
73 
74  f.close();
75  //double wei[2] = {0., 0.};
76 
77  auto iov = iovs.front();
78  std::shared_ptr<EcalTPGFineGrainStripEE> payload = fetchPayload( std::get<1>(iov) );
79  unsigned int run = std::get<0>(iov);
80  double max1=1.0, max2=1.0;
81 
82  if( payload.get() ){
83  const EcalTPGFineGrainStripEEMap &stripMap = (*payload).getMap();
84  // std::cout << " tower map size " << stripMap.size() << std::endl;
86  for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
87  EcalTPGFineGrainStripEE::Item item=(*itSt).second;
88 
89  // let's decode the ID
90  int strip = itSt->first/8;
91  int pseudostrip = strip & 0x7;
92  strip /= 8;
93  int tt = strip & 0x7F;
94  strip /= 128;
95  int tccid = strip & 0x7F;
96  int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
97  //if(NbXtalInStrip != NXtal) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
98  // << " Nx Xtals " << NbXtalInStrip << std::endl;
99 
100 
101  for(int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
102  uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
103  // std::cout << " rawid " << rawId << std::endl;
104  EEDetId detid = EEDetId::detIdFromDenseIndex(rawId);
105  float x = (float)detid.ix();
106  float y = (float)detid.iy();
107  int iz = detid.zside();
108  if(iz == -1) iz++;
109  //if(Xtal == 0) wei[iz] += 1.;
110  if(iz == 0) {
111  endc_thresh_m->Fill(x + 0.5, y + 0.5, item.threshold);
112  endc_lut_m->Fill(x + 0.5, y + 0.5, item.lut);
113  EEcount[0]++;
114 
115  if(max1<item.threshold)
116  max1=item.threshold;
117 
118  if(max2<item.lut)
119  max2=item.lut;
120 
121  }else {
122  endc_thresh_p->Fill(x + 0.5, y + 0.5, item.threshold);
123  endc_lut_p->Fill(x + 0.5, y + 0.5, item.lut);
124  EEcount[1]++;
125 
126  if(max1<item.threshold)
127  max1=item.threshold;
128 
129  if(max2<item.lut)
130  max2=item.lut;
131  }
132 
133  }
134 
135 
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 
159  TLatex t1;
160  t1.SetNDC();
161  t1.SetTextAlign(26);
162  t1.SetTextSize(0.04);
163  t1.DrawLatex(0.5, 0.96, Form("Ecal TPG Fine Grain StripEE, IOV %i", run));
164 
165 
166  float xmi[4] = {0.0, 0.5, 0.0, 0.5};
167  float xma[4] = {0.5, 1.0, 0.5, 1.0};
168 
169  float ymi[4] = {0.47, 0.47, 0.0, 0.0};
170  float yma[4] = {0.94, 0.94, 0.47, 0.47};
171  TPad** pad = new TPad*;
172  for (int obj = 0; obj < 4; obj++) {
173  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]);
174  pad[obj]->Draw();
175  }
176 
177  // t1.DrawLatex(0.2, 0.94, Form("%i crystals", EBstat));
178 
179  pad[0]->cd();
180  DrawEE(endc_thresh_m, 0., max1);
181  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[0]));
182 
183  pad[1]->cd();
184  DrawEE(endc_thresh_p, 0., max1);
185  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[1]));
186 
187 
188  pad[2]->cd();
189  DrawEE(endc_lut_m, 0., max2);
190  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[0]));
191 
192  pad[3]->cd();
193  DrawEE(endc_lut_p, 0., max2);
194  t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEcount[1]));
195 
196  std::string ImageName(m_imageFileName);
197 
198  canvas.SaveAs(ImageName.c_str());
199 
200  delete pad;
201  delete endc_lut_p;
202  delete endc_lut_m;
203  delete endc_thresh_p;
204  delete endc_thresh_m;
205  return true;
206  }// fill method
207  };
208 
209 }
210 
211 // Register the classes as boost python plugin
213  PAYLOAD_INSPECTOR_CLASS(EcalTPGFineGrainStripEEPlot);
214 }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:220
std::map< uint32_t, EcalTPGFineGrainStripEE::Item > EcalTPGFineGrainStripEEMap
int ix() const
Definition: EEDetId.h:77
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)
static const int XYMODE
Definition: EEDetId.h:335
void DrawEE(TH2F *endc, float min, float max)
Definition: EcalDrawUtils.h:29
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::map< uint32_t, EcalTPGFineGrainStripEE::Item >::const_iterator EcalTPGFineGrainStripEEMapIterator
int zside() const
Definition: EEDetId.h:71
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:83
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
def green(string)
Definition: plugin.cc:24
def canvas(sub, attr)
Definition: svgfig.py:482