AliPhysics  59e0e03 (59e0e03)
plotOCDB_LED.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <AliEMCALGeometry.h>
3 #include <TCanvas.h>
4 #include <TDatime.h>
5 #include <TFile.h>
6 #include <TGrid.h>
7 #include <TH2F.h>
8 #include <TKey.h>
9 #include <TLegend.h>
10 #include <TMap.h>
11 #include <TNtuple.h>
12 #include <TProfile.h>
13 #include <TROOT.h>
14 #include "LInfo.h"
15 
16 class LDraw : public TNamed {
17  public:
18  LDraw(const char *name, const char *fname="tempinfo.root");
19  virtual ~LDraw() {;}
20  TObjArray *GetArray() { return fArr; }
21  void Compute();
22  Int_t GetNRuns() const { return fArr->GetEntries(); }
23  void Print(Option_t *opt="") const {};
24  void SetPrint(Bool_t b=1) { fDoPrint=b; }
25  void DrawAll();
26  TCanvas *DrawFrac(Int_t type) const;
27  TH1 *GetFracRun(Int_t sm, Int_t t) const;
28  Int_t GetRunNo(Int_t run) const { return (static_cast<LInfo*>(fArr->At(run)))->GetRunNo(); }
29  TObjArray *fArr; // array with info
30  Bool_t fDoPrint; // if true then print canvases
31  ClassDef(LDraw, 1); // Led draw class
32 };
33 #endif
34 
35 LDraw::LDraw(const char *name, const char *fname) : TNamed(name,fname), fArr(0), fDoPrint(0)
36 {
37  TFile *inf = TFile::Open("ledinfo.root");
38  fArr = dynamic_cast<TObjArray*>(inf->Get(Form("led_%s",name)));
39  delete inf;
40 }
41 
43 {
44  const Int_t rns=fArr->GetEntries();
45  for (Int_t i=0;i<rns;++i) {
46  LInfo *linfo = dynamic_cast<LInfo*>(fArr->At(i));
47  if (!linfo)
48  continue;
49  linfo->Compute();
50  if (fDoPrint) {
51  linfo->Print();
52  cout << "fraction good strips ";
53  for (Int_t i=0;i<20;++i)
54  cout << linfo->FracStrips(i) << " ";
55  cout << endl;
56  cout << "fraction good towers ";
57  for (Int_t i=0;i<20;++i)
58  cout << linfo->FracLeds(i) << " ";
59  cout << endl;
60  }
61  }
62 }
63 
65 {
66  TString cname(Form("cLedAll_%s",GetName()));
67  TCanvas *c1 = DrawFrac(0);
68  c1->Print(Form("%s.pdf[",cname.Data()));
69  c1->Print(Form("%s.pdf",cname.Data()));
70  TCanvas *c2=DrawFrac(1);
71  c2->Print(Form("%s.pdf",cname.Data()));
72  TCanvas *c = 0;
73  const Int_t rns=fArr->GetEntries();
74  for (Int_t i=0;i<rns;++i) {
75  LInfo *linfo = dynamic_cast<LInfo*>(fArr->At(i));
76  if (!linfo)
77  continue;
78  c = linfo->DrawHist(5,1);
79  c->Print(Form("%s.pdf",cname.Data()));
80  delete c;
81  c = linfo->DrawHist(6,1);
82  c->Print(Form("%s.pdf",cname.Data()));
83  delete c;
84  c = linfo->DrawHist(0,1);
85  c->Print(Form("%s.pdf",cname.Data()));
86  delete c;
87  }
88  c2->Print(Form("%s.pdf]",cname.Data()));
89 }
90 
91 TCanvas *LDraw::DrawFrac(Int_t type) const
92 {
93  const char *tname="Led";
94  if (type==0)
95  tname = "LedMon";
96  TString lab(Form("cLedFrac_%s_%s",tname,GetName()));
97  TCanvas *c = new TCanvas(lab,lab,1200,800);
98  TLegend *leg = new TLegend(0.92,0.1,0.99,0.99);
99  TObjArray arr;
100  Double_t min=1e10,max=-1e10;
101  for (Int_t i=0;i<20;++i) {
102  TH1 *h=GetFracRun(i,type);
103  Int_t col=i+1;
104  switch (i) {
105  case 9: col=kOrange+2; break;
106  case 10: col=kOrange+10; break;
107  case 11: col=kMagenta+2; break;
108  case 12: col=kCyan+2; break;
109  case 13: col=kYellow+2; break;
110  case 14: col=kGray+2; break;
111  case 15: col=kOrange-2; break;
112  case 16: col=kViolet+2; break;
113  case 17: col=kRed-2; break;
114  case 18: col=kGreen+2; break;
115  case 19: col=kGray+2; break;
116  }
117  h->SetMarkerStyle(20+(i%2));
118  h->SetMarkerSize(1.2);
119  h->SetMarkerColor(col);
120  h->SetLineColor(col);
121  h->SetLineWidth(3);
122  h->SetName(Form("SM%d",i));
123  arr.Add(h);
124  leg->AddEntry(h,h->GetName(),"p");
125  min=TMath::Min(min,h->GetMinimum());
126  max=TMath::Max(max,h->GetMaximum());
127  }
128  TH2 *h2f = new TH2F("h2f",";run idx;T",1,0,GetNRuns(),1,-0.05,1.05);
129  h2f->SetTitle(Form("Fraction %s per SM: run %d to %d, min=%.1f, max=%.1f",tname, GetRunNo(0), GetRunNo(GetNRuns()-1), min, max));
130  h2f->SetStats(0);
131  h2f->Draw();
132  leg->Draw();
133  for (Int_t i=0;i<arr.GetEntries();++i)
134  arr.At(i)->Draw("same, p, hist");
135  c->SetGridx(1);
136  c->SetGridy(1);
137  if (fDoPrint)
138  c->Print(Form("%s.pdf",c->GetName()));
139  return c;
140 }
141 
143 {
144  const Int_t rns=fArr->GetEntries();
145  TH1F *ret = new TH1F(Form("hFracRun_%d_%d",sm,t),Form(";run idx;fraction"),rns,0,rns);
146  if (t==0)
147  ret->SetTitle(Form("Fraction of strips per run: run %d to %d",GetRunNo(0), GetRunNo(GetNRuns()-1)));
148  else
149  ret->SetTitle(Form("Fraction of leds per run: run %d to %d",GetRunNo(0), GetRunNo(GetNRuns()-1)));
150  ret->SetDirectory(0);
151  ret->SetStats(0);
152  ret->SetMarkerStyle(20);
153  ret->SetMarkerSize(1);
154  Int_t r1,r2=0;
155  for (Int_t i=0;i<rns;++i) {
156  LInfo *linfo = dynamic_cast<LInfo*>(fArr->At(i));
157  if (!linfo)
158  continue;
159  Double_t val = 0;
160  if (t==0)
161  val = linfo->FracStrips(sm);
162  else
163  val = linfo->FracLeds(sm);
164  ret->SetBinContent(i+1,val);
165  }
166  return ret;
167 }
168 
169 void plotL_period(const char *period, Bool_t doprint=0)
170 {
171  LDraw d(period);
172  d.SetPrint(doprint);
173  d.Compute();
174  d.Print();
175  if (0) {
176  d.DrawFrac(0);
177  d.DrawFrac(1);
178  } else
179  d.DrawAll();
180 }
181 
182 void plotOCDB_LED(const char *period="lhc18d")
183 {
184  plotL_period(period);
185 }
186 
188 {
189  LInfo lall;
190  TFile *fin = TFile::Open("ledinfo.root");
191  TIter next(fin->GetListOfKeys());
192  TKey *key=0;
193  TObjArray objs;
194  while ((key = (TKey*)next())) {
195  TClass *cl = gROOT->GetClass(key->GetClassName());
196  if (!cl->InheritsFrom("TObjArray"))
197  continue;
198  TObjArray *arr=dynamic_cast<TObjArray*>(key->ReadObj());
199  objs.AddAll(arr);
200  }
201  for (Int_t sm=0;sm<20;sm++) {
202  for (Int_t i=0;i<objs.GetEntries();++i) {
203  LInfo *l = (LInfo*)objs.At(i);
204  lall.GetLedHist(sm)->Add(l->GetLedHist(sm));
205  lall.GetLedMonHist(sm)->Add(l->GetLedMonHist(sm));
206  }
207  TString n(Form("c%d",sm));
208  TCanvas *c = new TCanvas(n,n,1600,600);
209  c->Divide(1,2);
210  c->cd(1);
211  lall.GetLedHist(sm)->SetStats(0);
212  lall.GetLedHist(sm)->Draw("colz");
213  c->cd(2);
214  lall.GetLedMonHist(sm)->SetStats(0);
215  lall.GetLedMonHist(sm)->Draw("colz");
216  c->Print(Form("%s.pdf",c->GetName()));
217  }
218 }
219 
220 #if 0
221 void test_geo()
222 {
223  AliEMCALGeometry *g=AliEMCALGeometry::GetInstance("EMCAL_COMPLETE12SMV1_DCAL_8SM");
224  Int_t kSM=g->GetNumberOfSuperModules();
225  cout << "Number of SM: " << kSM << endl;
226  for (Int_t i=0;i<kSM;++i) {
227  Int_t nrow = g->GetNumberOfCellsInPhiDirection(i);
228  Int_t ncol = g->GetNumberOfCellsInEtaDirection(i);
229  cout << i << ": nrow(nphi)=" << nrow << ", ncol(neta)=" << ncol << endl;
230  continue;
231  TH2 *h2f = new TH2F(Form("hsm%d",i),Form(";col;row"), ncol, -0.5, ncol-0.5, nrow, -0.5, nrow-0.5);
232  for (Int_t col=0;col<ncol;++col) {
233  for (Int_t row=0;row<nrow;++row) {
234  Int_t id = g->GetAbsCellIdFromCellIndexes(i,row,col);
235  cout << "Id " << id << " " << row << " " << col << endl;
236  Int_t bin = h2f->FindBin(col,row);
237  h2f->SetBinContent(bin,id);
238  }
239  }
240  h2f->Draw("text");
241  break;
242  }
243 
244  //row==phi, col==eta
245  Int_t sm=18;
246  Int_t nrow = g->GetNumberOfCellsInPhiDirection(sm);
247  Int_t ncol = g->GetNumberOfCellsInEtaDirection(sm);
248  cout << "sm " << sm << ": " << nrow << " " << ncol << endl;
249  for (Int_t col=0;col<ncol;++col) {
250  for (Int_t row=0;row<nrow;++row) {
251  Int_t id = g->GetAbsCellIdFromCellIndexes(sm,row,col);
252  Int_t ocol=col, orow=row;
253  g->ShiftOfflineToOnlineCellIndexes(sm, orow, ocol);
254  if ((orow!=row) || (ocol!=col))
255  cout << "SM " << sm << " id " << id << ": " << row << " " << col << " - " << orow << " " << ocol << endl;
256  }
257  }
258 }
259 #endif
double Double_t
Definition: External.C:58
Definition: External.C:236
Double_t FracLeds(Int_t sm, Int_t gain=1) const
Definition: LInfo.cxx:224
TObjArray * GetArray()
Definition: plotOCDB_LED.C:20
TCanvas * DrawHist(Int_t which, Int_t gain=1, const char *opt=0) const
Definition: LInfo.cxx:145
void Compute()
Definition: plotOCDB_LED.C:42
Bool_t fDoPrint
Definition: plotOCDB_LED.C:30
void SetPrint(Bool_t b=1)
Definition: plotOCDB_LED.C:24
virtual ~LDraw()
Definition: plotOCDB_LED.C:19
TCanvas * c
Definition: TestFitELoss.C:172
void Print(Option_t *option="") const
Definition: LInfo.cxx:272
Int_t GetRunNo(Int_t run) const
Definition: plotOCDB_LED.C:28
Definition: LInfo.h:11
int Int_t
Definition: External.C:63
void Compute()
Definition: LInfo.cxx:12
Double_t FracStrips(Int_t sm, Int_t gain=1) const
Definition: LInfo.cxx:251
Int_t GetNRuns() const
Definition: plotOCDB_LED.C:22
TObjArray * fArr
Definition: plotOCDB_LED.C:29
TProfile * GetLedMonHist(Int_t sm, Int_t gain=1) const
Definition: LInfo.h:20
TProfile2D * GetLedHist(Int_t sm, Int_t gain=1) const
Definition: LInfo.h:23
LDraw(const char *name, const char *fname="tempinfo.root")
Definition: plotOCDB_LED.C:35
Definition: External.C:220
void DrawAll()
Definition: plotOCDB_LED.C:64
void Print(Option_t *opt="") const
Definition: plotOCDB_LED.C:23
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
TH1 * GetFracRun(Int_t sm, Int_t t) const
Definition: plotOCDB_LED.C:142
void plotOCDB_LED(const char *period="lhc18d")
Definition: plotOCDB_LED.C:182
void plot_OCDB_LED_all()
Definition: plotOCDB_LED.C:187
Definition: External.C:196
TCanvas * DrawFrac(Int_t type) const
Definition: plotOCDB_LED.C:91
void plotL_period(const char *period, Bool_t doprint=0)
Definition: plotOCDB_LED.C:169