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