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