CMS 3D CMS Logo

MEGeom.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <iostream>
3 #include <cstdlib>
4 #include <string>
5 using namespace std;
6 
9 
10 #include <TCanvas.h>
11 #include <TGraph.h>
12 #include <TFile.h>
13 #include <TH2.h>
14 
15 //TString MEGeom::granularity[MEGeom::iSizeG] = {
16 // "Ecal Region", "Ecal Sector", "Laser Monitoring Region", "Laser Monitoring Module", "Super-Crystal", "Crystal"
17 //};
18 
19 int MEGeom::_nbuf = 5;
20 int MEGeom::_nbinx = 2 * (MEGeom::_nbuf + 100 + 85) + 1;
21 float MEGeom::_xmin = -(0.5 + MEGeom::_nbuf + 100 + 85);
22 float MEGeom::_xmax = 0.5 + MEGeom::_nbuf + 100 + 85;
23 int MEGeom::_nbiny = 2 * (MEGeom::_nbuf + 180);
24 float MEGeom::_ymin = 180.5 - (MEGeom::_nbuf + 180);
25 float MEGeom::_ymax = 180.5 + (MEGeom::_nbuf + 180);
26 TH2* MEGeom::_h = new TH2F("globalEcal",
27  "Global representation of ECAL",
34 
35 //GHM ClassImp(MEGeom)
36 
37 TH2* MEGeom::getHist(int ilmr, int unit) {
38  int ireg;
39  int ism;
40  int idcc;
41  int side;
42  ME::regionAndSector(ilmr, ireg, ism, idcc, side);
43 
44  std::cout << "LM region=" << ilmr << " reg/sm/dcc/side " << ireg << "/" << ism << "/" << idcc << "/" << side
45  << std::endl;
46 
47  TString hname = "LMR=";
48  hname += ilmr;
49  hname += " ";
50  if (ireg == ME::iEEM || ireg == ME::iEEP) {
51  hname += MEEEGeom::smName(ism);
52  } else if (ireg == ME::iEBM || ireg == ME::iEBP) {
53  hname += MEEBGeom::smName(ism);
54  } else
55  abort();
56 
57  hname += " ";
58  hname += "DCC=";
59  hname += idcc;
60  hname += "/";
61  hname += side;
62 
63  //
64  // to produce these root files, run the runGeom executable
65  //
66  TH2* h_(nullptr);
67  TFile* rootfile(nullptr);
68  TString hn_;
69  if (ireg == ME::iEBM || ireg == ME::iEBP) {
70  rootfile = TFile::Open("ebgeom.root");
71  assert(rootfile != nullptr);
72  hn_ = "eb_loc";
73  switch (unit) {
74  case ME::iSector:
75  break;
76  case ME::iLMRegion:
77  hn_ += "_side";
78  break;
79  case ME::iLMModule:
80  hn_ += "_lmmod";
81  break;
82  case ME::iSuperCrystal:
83  hn_ += "_tt";
84  break;
85  case ME::iCrystal:
86  hn_ += "_cr";
87  break;
89  hn_ += "_elecr";
90  break;
91  case ME::iHVChannel:
92  hn_ += "_hv";
93  break;
94  case ME::iLVChannel:
95  hn_ += "_lv";
96  break;
97  }
98  } else {
99  int isect = ism;
100  if (ireg == ME::iEEM) {
101  isect -= 9;
102  rootfile = TFile::Open("eegeom_1.root");
103  }
104  if (ireg == ME::iEEP)
105  rootfile = TFile::Open("eegeom_2.root");
106  assert(rootfile != nullptr);
107  hn_ = "eem_S";
108  hn_ += isect;
109  switch (unit) {
110  case ME::iSector:
111  break;
112  case ME::iLMRegion:
113  break;
114  case ME::iLMModule:
115  hn_ += "_lmmod";
116  break;
117  case ME::iSuperCrystal:
118  hn_ += "_sc";
119  break;
120  case ME::iCrystal:
121  hn_ += "_cr";
122  break;
124  hn_ += "_cr";
125  break;
126  case ME::iHVChannel:
127  break;
128  case ME::iLVChannel:
129  break;
130  }
131  }
132  h_ = (TH2*)rootfile->Get(hn_);
133  h_->SetTitle(hname);
134  h_->GetXaxis()->SetTitle("ix");
135  h_->GetXaxis()->CenterTitle();
136  h_->GetYaxis()->SetTitle("iy");
137  h_->GetYaxis()->CenterTitle();
138  return h_;
139 }
140 
141 TGraph* MEGeom::getBoundary(int ilmr, int histtype) {
142  // for local pictures, only sector or monitoring region
143  if (histtype != ME::iSector && histtype != ME::iLMRegion)
144  histtype = ME::iSector;
145 
146  int ireg;
147  int ism;
148  int idcc;
149  int side;
150  ME::regionAndSector(ilmr, ireg, ism, idcc, side);
151 
152  //
153  // to produce these root files, run the runGeom executable
154  //
155  TGraph* g_(nullptr);
156  TFile* rootfile(nullptr);
157  TString gn_;
158  if (ireg == ME::iEBM || ireg == ME::iEBP) {
159  rootfile = TFile::Open("ebgeom.root");
160  assert(rootfile != nullptr);
161  switch (histtype) {
162  case ME::iSector:
163  gn_ = "SuperModule";
164  break;
165  case ME::iLMRegion:
166  gn_ = "Side_";
167  gn_ += side;
168  break;
169  }
170  } else {
171  int isect = ism;
172  if (ireg == ME::iEEM) {
173  isect -= 9;
174  rootfile = TFile::Open("eegeom_1.root");
175  }
176  if (ireg == ME::iEEP)
177  rootfile = TFile::Open("eegeom_2.root");
178  assert(rootfile != nullptr);
179  int lmr_ = ilmr;
180  if (ireg == ME::iEEP)
181  lmr_ -= 72;
182  else if (ireg == ME::iEEM)
183  lmr_ -= 82;
184  switch (histtype) {
185  case ME::iSector:
186  gn_ = "Sector_";
187  gn_ += isect;
188  break;
189  case ME::iLMRegion:
190  gn_ = "LMRegion_";
191  gn_ += lmr_;
192  break;
193  }
194  }
195  g_ = (TGraph*)rootfile->Get(gn_);
196  return g_;
197 }
198 
199 void MEGeom::drawHist(int ilmr, int histtype, TCanvas* canv) {
200  TH2* h = getHist(ilmr, histtype);
201  assert(h != nullptr);
202  TString tname = h->GetTitle();
203  switch (histtype) {
204  case ME::iSector:
205  break;
206  case ME::iLMRegion:
207  tname += " Monitoring Regions";
208  break;
209  case ME::iLMModule:
210  tname += " Monitoring Modules";
211  break;
212  case ME::iSuperCrystal:
213  tname += " Super Crystals";
214  break;
215  case ME::iCrystal:
216  tname += " Crystals";
217  break;
219  tname += " Electronic Channels";
220  break;
221  case ME::iHVChannel:
222  tname += " HV Channels";
223  break;
224  case ME::iLVChannel:
225  tname += " LV Channels";
226  break;
227  }
228 
229  if (canv == nullptr) {
230  TString cname = tname;
231  cname.ReplaceAll(" ", "_");
232  canv = new TCanvas(cname, cname, 10, 10, 500, 500);
233  }
234  canv->SetTitle(tname);
235  canv->cd();
236 
237  h->Draw("COLZ");
238 
239  TGraph* gsect = getBoundary(ilmr, ME::iSector);
240  assert(gsect != nullptr);
241  gsect->SetLineWidth(1);
242  gsect->Draw("LSame");
243  TGraph* gside = getBoundary(ilmr, ME::iLMRegion);
244  assert(gside != nullptr);
245  gside->SetLineWidth(2);
246  gside->Draw("LSame");
247 }
248 
249 TH2* MEGeom::getGlobalHist(const char* name) {
250  TH2* h = (TH2*)_h->Clone(name);
251  h->Reset();
252  return h;
253 }
254 
255 void MEGeom::setBinGlobalHist(TH2* h, int ix, int iy, int iz, float val) {
256  // make sure it's a global hist
257  TAxis* ax = h->GetXaxis();
258  TAxis* ay = h->GetYaxis();
259  assert(ax->GetNbins() == _nbinx && ay->GetNbins() == _nbiny);
260  assert(ax->GetXmax() == _xmax && ax->GetXmin() == _xmin);
261  assert(ay->GetXmax() == _ymax && ay->GetXmin() == _ymin);
262 
263  int ibinx(0);
264  int ibiny(0);
265 
266  if (iz == 0) {
267  int ieta = ix;
268  int iphi = iy;
269  assert(abs(ieta) >= 1 && abs(ieta) <= 85);
270  assert(iphi >= 1 && iphi <= 360);
271 
272  ibinx = ax->FindBin(ieta);
273  ibiny = ay->FindBin(iphi);
274  } else if (iz == -1) {
275  assert(ix >= 1 && ix <= 100 && iy >= 1 && iy <= 100);
276  ibinx = (_nbuf + 100 + 1) - ix;
277  ibiny = (_nbuf + 180 + 50 + 1) - iy;
278  } else if (iz == 1) {
279  assert(ix >= 1 && ix <= 100 && iy >= 1 && iy <= 100);
280  ibinx = _nbinx + 1 - ((_nbuf + 100 + 1) - ix);
281  ibiny = (_nbuf + 180 + 50 + 1) - iy;
282  }
283  h->SetBinContent(ibinx, ibiny, val);
284 }
285 
286 // fixme !!!
288  TGraph* gr(nullptr);
289  for (int ism = 1; ism <= 36; ism++) {
291  gr->SetLineWidth(2);
292  gr->SetLineColor(lineColor);
293  gr->Draw("LSame");
294  }
295  for (int isec = 1; isec <= 9; isec++) {
297  TGraph* grm = (TGraph*)gr->Clone();
298  TGraph* grp = (TGraph*)gr->Clone();
299  int n = gr->GetN();
300  // std::cout << std::endl;
301  for (int ii = 0; ii < n; ii++) {
302  double x_, y_;
303  gr->GetPoint(ii, x_, y_);
304  // std::cout << isec << " " << ii << " x=" << x_ << " y=" << y_ << std::endl;
305 
306  double xx_, yy_;
307 
308  xx_ = -85 - x_;
309  yy_ = 231 - y_;
310  // std::cout << isec << " " << 0 << " x=" << xx_ << " y=" << yy_ << std::endl;
311 
312  grm->SetPoint(ii, xx_, yy_);
313 
314  xx_ = 85 + x_;
315  yy_ = 231 - y_;
316  // std::cout << isec << " " << 1 << " x=" << xx_ << " y=" << yy_ << std::endl;
317  grp->SetPoint(ii, xx_, yy_);
318  }
319  grm->SetLineColor(lineColor);
320  grm->SetLineWidth(2);
321  grm->Draw("LSame");
322  grp->SetLineColor(lineColor);
323  grp->SetLineWidth(2);
324  grp->Draw("LSame");
325  }
326 }
static void drawHist(int ilmr, int unit, TCanvas *canv=nullptr)
Definition: MEGeom.cc:199
static void regionAndSector(int ilmr, int &ireg, int &isect, int &idcc, int &iside)
Definition: ME.cc:333
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static void drawGlobalBoundaries(int lineColor)
Definition: MEGeom.cc:287
static TString smName(int ism)
Definition: MEEBGeom.cc:79
static char const * tname
Definition: GTSchema.h:13
Definition: ME.h:14
static float _ymax
Definition: MEGeom.h:41
static float _xmax
Definition: MEGeom.h:39
Definition: ME.h:14
static float _ymin
Definition: MEGeom.h:40
static TH2 * getHist(int ilmr, int unit)
Definition: MEGeom.cc:37
static TH2 * _h
Definition: MEGeom.h:42
static TGraph * getBoundary(int ilmr, int unit)
Definition: MEGeom.cc:141
static void setBinGlobalHist(TH2 *h, int ix, int iy, int iz, float val)
Definition: MEGeom.cc:255
static TString smName(int ism)
Definition: MEEEGeom.cc:388
static int _nbiny
Definition: MEGeom.h:37
static TGraph * getGraphBoundary(int type, int num, bool global=false)
Definition: MEEBGeom.cc:346
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static int _nbuf
Definition: MEGeom.h:35
Definition: ME.h:14
ii
Definition: cuy.py:590
static TGraph * getGraphBoundary(int type, int num, int iz=-1, int xside=0)
Definition: MEEEGeom.cc:423
static TH2 * getGlobalHist(const char *name=nullptr)
Definition: MEGeom.cc:249
static float _xmin
Definition: MEGeom.h:38
static int _nbinx
Definition: MEGeom.h:36
Definition: ME.h:16
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:51
Definition: ME.h:14
Basic3DVector unit() const