AliPhysics  cc5d4fb (cc5d4fb)
plotOCDB_Temperature.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TCanvas.h>
3 #include <TDatime.h>
4 #include <TFile.h>
5 #include <TGrid.h>
6 #include <TH2F.h>
7 #include <TLegend.h>
8 #include <TLine.h>
9 #include <TMap.h>
10 #include <TNtuple.h>
11 #include <TObjArray.h>
12 #include <TProfile.h>
13 #include "TInfo.h"
14 
15 class TDraw : public TNamed {
16  public:
17  TDraw(const char *name, const char *fname="tempinfo.root");
18  virtual ~TDraw() {;}
19  TObjArray *GetArray() { return fArr; }
20  void Compute();
21  void DrawAll();
22  TCanvas *DrawT(Int_t type=3) const;
23  TCanvas *DrawT2D(Int_t type=3) const;
24  TCanvas *DrawOccRun() const;
25  TCanvas *DrawOccSensor2D() const;
26  TCanvas *DrawOcc2D() const;
27  Double_t GetMaxT(Int_t type=3) const;
28  Double_t GetMinT(Int_t type=3) const;
29  Double_t GetMaxTperS(Int_t ns, Int_t type=3) const;
30  Double_t GetMinTperS(Int_t ns, Int_t type=3) const;
32  Int_t GetBad(Int_t ns) const { return fBad.At(ns); }
33  Int_t GetNBad() const;
34  Int_t GetNRuns() const { return fArr->GetEntries(); }
35  Int_t GetNRunsValid(Int_t ns) const;
36  Int_t GetRunNo(Int_t run) const { return (static_cast<TInfo*>(fArr->At(run)))->GetRunNo(); }
37  TH1 *GetOccRun() const;
38  TH1 *GetOccSensor() const;
39  TH2 *GetOccSensor2D() const;
40  TH2 *GetOcc2D() const;
41  TH1 *GetT(Int_t ns1, Int_t ns2, Int_t type=3) const;
42  TH2 *GetT2D(Int_t type=3) const;
43  Bool_t IsGood(Int_t ns) const { return (fBad.At(ns)==0); }
44  void Print(Option_t *opt="") const;
45  void SetPrint(Bool_t b=1) { fDoPrint=b; }
46  void SetBad(Int_t ns, Bool_t b) { fBad.SetAt(ns,b); }
47  protected:
48  TH2 *GetMask() const;
49  TObjArray *fArr; // array with info
50  Bool_t fDoPrint; // if true then print canvases
51  TArrayI fBad; // list of bad channels
52  Double_t fMinFrac; // minimum fraction
53  ClassDef(TDraw, 1); // Temperature draw class
54 };
55 #endif
56 
57 TDraw::TDraw(const char *name, const char *fname) : TNamed(name,fname), fArr(0), fDoPrint(0), fBad(TInfo::NSensors()), fMinFrac(0.8)
58 {
59  TFile *inf = TFile::Open("tempinfo.root");
60  fArr = dynamic_cast<TObjArray*>(inf->Get(Form("temperatures_%s",name)));
61  delete inf;
62  fBad.SetAt(1,26);
63  fBad.SetAt(1,40);
64  fBad.SetAt(1,43);
65  fBad.SetAt(1,44);
66  fBad.SetAt(1,45);
67  fBad.SetAt(1,84);
68  fBad.SetAt(1,85);
69  fBad.SetAt(1,86);
70  fBad.SetAt(1,87);
71  fBad.SetAt(1,92);
72  fBad.SetAt(1,93);
73  fBad.SetAt(1,94);
74  fBad.SetAt(1,95);
75  fBad.SetAt(1,117);
76  fBad.SetAt(1,135);
77  fBad.SetAt(1,140);
78  fBad.SetAt(1,147);
79  fBad.SetAt(1,148);
80  fBad.SetAt(1,149);
81  fBad.SetAt(1,150);
82  fBad.SetAt(1,151);
83  fBad.SetAt(1,156);
84  fBad.SetAt(1,157);
85  fBad.SetAt(1,158);
86  fBad.SetAt(1,159);
87 }
88 
90 {
91  const Int_t nbad = GetNBad();
92  cout << "Known bad sensors: " << nbad << " (";
93  for (Int_t ns=0,first=0;ns<TInfo::NSensors();++ns) {
94  if (IsGood(ns))
95  continue;
96  if (first==0) {
97  cout << ns;
98  first = 1;
99  } else
100  cout << ", " << ns;
101  }
102  cout << ")" << endl;
103 
104  const Int_t rns=fArr->GetEntries();
105  for (Int_t i=0;i<rns;++i) {
106  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
107  if (!tinfo)
108  continue;
109  if (tinfo->GetNFaulty()!=nbad) {
110  cout << "Setting nfaulty to " << nbad << " for run " << i << endl;
111  tinfo->SetNFaulty(nbad);
112  }
113  Double_t frac = tinfo->Fraction();
114  if (frac<fMinFrac)
115  cout << "Run " << i << " with run number " << tinfo->GetRunNo() << " below threshold: " << frac << endl;
116  }
117 
118  for (Int_t ns=0;ns<TInfo::NSensors();++ns) {
119  Double_t frac=GetFraction(ns);
120  if (!IsGood(ns)) {
121  if (frac>0) {
122  cout << "Sensor " << ns << " marked bad, but has fraction: " << frac << endl;
123  }
124  continue;
125  }
126  if (frac<fMinFrac)
127  cout << "Sensor " << ns << " below threshold: " << frac << endl;
128  }
129 }
130 
132 {
133  TString cname(Form("cTempAll_%s",GetName()));
134  TCanvas *c1 = DrawOccRun();
135  c1->Print(Form("%s.pdf[",cname.Data()));
136  c1->Print(Form("%s.pdf",cname.Data()));
137  TCanvas *c2=DrawOccSensor2D();
138  c2->Print(Form("%s.pdf",cname.Data()));
139  TCanvas *c3=DrawT(3);
140  c3->Print(Form("%s.pdf",cname.Data()));
141  TString lab(Form("cTemp2D_%s_%s",TInfo::Type(3),GetName()));
142  TCanvas *c4 = new TCanvas(lab,lab,1200,800);
143  const Int_t rns=fArr->GetEntries();
144  Double_t min=-1;
145  Double_t max=30;
146  for (Int_t i=0;i<rns;++i) {
147  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
148  if (!tinfo)
149  continue;
150  TH2 *h=tinfo->GetHist(3);
151  h->SetMinimum(min);
152  h->SetMaximum(max);
153  h->Draw("colz,text");
154  TH2 *hm = GetMask();
155  hm->DrawCopy("box,same");
156  c4->Print(Form("%s.pdf",cname.Data()));
157  }
158  c4->Print(Form("%s.pdf]",cname.Data()));
159 }
160 
161 TCanvas *TDraw::DrawOccRun() const
162 {
163  TString lab(Form("cOccRun_%s",GetName()));
164  TCanvas *c = new TCanvas(lab,lab,1200,800);
165  TH1 *h = GetOccRun();
166  h->SetMinimum(0);
167  h->SetMaximum(1);
168  h->Draw("P");
169  TLine *l = new TLine(0,fMinFrac,GetNRuns(),fMinFrac);
170  l->SetLineColor(2);
171  l->SetLineWidth(2);
172  l->SetLineStyle(9);
173  l->Draw();
174  if (fDoPrint)
175  c->Print(Form("%s.pdf",c->GetName()));
176  return c;
177 }
178 
179 TCanvas *TDraw::DrawOccSensor2D() const
180 {
181  TString lab(Form("cOccSensor2D_%s",GetName()));
182  TCanvas *c = new TCanvas(lab,lab,1200,800);
183  TH2 *h2 = GetOccSensor2D();
184  h2->Draw("colz,text");
185  if (fDoPrint)
186  c->Print(Form("%s.pdf",c->GetName()));
187  return c;
188 }
189 
190 TCanvas *TDraw::DrawOcc2D() const
191 {
192  TString lab(Form("cOcc2D_%s",GetName()));
193  TCanvas *c = new TCanvas(lab,lab);
194  TH2 *h = GetOcc2D();
195  h->Draw("colz");
196  if (fDoPrint)
197  c->Print(Form("%s.pdf",c->GetName()));
198  return c;
199 }
200 
201 TCanvas *TDraw::DrawT(Int_t type) const
202 {
203  TString lab(Form("cTemp_%s_%s",TInfo::Type(type),GetName()));
204  TCanvas *c = new TCanvas(lab,lab,1200,800);
205  Double_t max=GetMaxT(type),maxp=-100;
206  Double_t min=GetMinT(type),minp=+100;
207  TLegend *leg = new TLegend(0.92,0.1,0.99,0.99);
208  TObjArray arr;
209  for (Int_t i=0,n1=0,n2=7;i<20;++i) {
210  TH1 *h=GetT(n1,n2,type);
211  n1+=8;
212  n2+=8;
213  Int_t col=i+1;
214  switch (i) {
215  case 9: col=kOrange+2; break;
216  case 10: col=kOrange+10; break;
217  case 11: col=kMagenta+2; break;
218  case 12: col=kCyan+2; break;
219  case 13: col=kYellow+2; break;
220  case 14: col=kGray+2; break;
221  case 15: col=kOrange-2; break;
222  case 16: col=kViolet+2; break;
223  case 17: col=kRed-2; break;
224  case 18: col=kGreen+2; break;
225  case 19: col=kGray+2; break;
226  }
227  h->SetMarkerStyle(20+(i%2));
228  h->SetMarkerSize(1.2);
229  h->SetMarkerColor(col);
230  h->SetLineColor(col);
231  h->SetLineWidth(3);
232  h->SetName(Form("SM%d",i));
233  //h->Draw("same, p, hist");
234  arr.Add(h);
235  Double_t minh=h->GetMinimum();
236  if (minh<minp) minp=minh;
237  Double_t maxh=h->GetMaximum();
238  if (maxh>maxp) maxp=maxh;
239  leg->AddEntry(h,h->GetName(),"p");
240  }
241  minp=0.9*minp; maxp=1.1*maxp;
242  TH2 *h2f = new TH2F("h2f",";run idx;T",1,0,GetNRuns(),1,minp,maxp);
243  h2f->SetTitle(Form("Average T per SM: run %d to %d, min=%.1f, max=%.1f",GetRunNo(0), GetRunNo(GetNRuns()-1), min, max));
244  h2f->SetStats(0);
245  h2f->Draw();
246  leg->Draw();
247  for (Int_t i=0;i<arr.GetEntries();++i)
248  arr.At(i)->Draw("same, p, hist");
249  c->SetGridx(1);
250  c->SetGridy(1);
251  if (fDoPrint)
252  c->Print(Form("%s.pdf",c->GetName()));
253  return c;
254 }
255 
256 TCanvas *TDraw::DrawT2D(Int_t type) const
257 {
258  TString lab(Form("cTemp2D%s_%s",TInfo::Type(type),GetName()));
259  TCanvas *c = new TCanvas(lab,lab);
260  TH2 *h = GetT2D(type);
261  h->Draw("colz");
262  if (fDoPrint)
263  c->Print(Form("%s.pdf",c->GetName()));
264  return c;
265 }
266 
268 {
269  static TH2F *h = 0;
270  if (h==0) {
271  h = new TH2F("hBadMask",";col;rows",8,-0.5,7.5,20,-0.5,19.5);
272  h->SetDirectory(0);
273  h->SetStats(0);
274  h->SetLineColor(0);
275  h->SetMaximum(0);
276  h->SetMinimum(-1);
277  for (Int_t i=0;i<TInfo::NSensors();++i) {
278  Double_t bin = TInfo::GetBin(i);
279  if (!IsGood(i))
280  h->SetBinContent(bin,-1);
281  else
282  h->SetBinContent(bin,-100);
283  }
284  }
285  return h;
286 }
287 
289 {
290  const Int_t rns=fArr->GetEntries();
291  TH1F *ret = new TH1F("hOccRun",Form(";run idx;fraction"),rns,0,rns);
292  ret->SetTitle(Form("Fraction of all sensors per run: run %d to %d, min.fraction=%.1f",GetRunNo(0), GetRunNo(GetNRuns()-1), fMinFrac));
293  ret->SetDirectory(0);
294  ret->SetStats(0);
295  ret->SetMarkerStyle(20);
296  ret->SetMarkerSize(1);
297  Int_t r1,r2=0;
298  for (Int_t i=0;i<rns;++i) {
299  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
300  if (!tinfo)
301  continue;
302  Double_t val=tinfo->Fraction();
303  ret->SetBinContent(i+1,val);
304  }
305  return ret;
306 }
307 
309 {
310  const Int_t rns=fArr->GetEntries();
311  TProfile *ret = new TProfile("hOccSensor",Form(";sensor id;fraction"),TInfo::NSensors(),0,TInfo::NSensors());
312  ret->SetDirectory(0);
313  ret->SetStats(0);
314  ret->SetMarkerStyle(20);
315  ret->SetMarkerSize(1);
316  for (Int_t i=0;i<rns;++i) {
317  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
318  if (!tinfo)
319  continue;
320  for (Int_t j=0;j<TInfo::NSensors();++j) {
321  Int_t val=tinfo->IsValid(j);
322  ret->Fill(j,val);
323  }
324  }
325  return ret;
326 }
327 
329 {
330  TH2F *hOcc2D = new TH2F("hOccSensor2D",";col;rows",8,-0.5,7.5,20,-0.5,19.5);
331  hOcc2D->SetTitle(Form("Fraction of all runs per sensor: run %d to %d, min.fraction=%.1f",GetRunNo(0), GetRunNo(GetNRuns()-1), fMinFrac));
332  hOcc2D->SetDirectory(0);
333  hOcc2D->SetStats(0);
334  hOcc2D->SetMinimum(-1);
335  hOcc2D->SetMaximum(+1);
336  for (Int_t ns=0;ns<TInfo::NSensors();++ns) {
337  Double_t frac = GetFraction(ns);
338  Int_t bin = TInfo::GetBin(ns);
339  if (!IsGood(ns))
340  frac = -1;
341  hOcc2D->SetBinContent(bin,frac);
342  }
343  return hOcc2D;
344 }
345 
347 {
348  const Int_t rns=fArr->GetEntries();
349  TH2F *ret = new TH2F("h2focc",Form("%s;run idx;sensor idx",GetName()),rns,0,rns,TInfo::NSensors(),0,TInfo::NSensors());
350  ret->SetDirectory(0);
351  ret->SetStats(0);
352  for (Int_t i=0;i<rns;++i) {
353  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
354  if (!tinfo)
355  continue;
356  for (Int_t j=0;j<TInfo::NSensors();++j) {
357  Int_t val=tinfo->IsValid(j);
358  ret->SetBinContent(ret->FindBin(i,j),val);
359  }
360  }
361  return ret;
362 }
363 
365 {
366  Double_t ret=-1e9;
367  const Int_t rns=fArr->GetEntries();
368  for (Int_t i=0;i<rns;++i) {
369  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
370  if (!tinfo)
371  continue;
372  Double_t v=tinfo->AbsMaxT(type);
373  if (v>ret)
374  ret=v;
375  }
376  return ret;
377 }
378 
380 {
381  Double_t ret=-1e9;
382  const Int_t rns=fArr->GetEntries();
383  for (Int_t i=0;i<rns;++i) {
384  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
385  if (!tinfo)
386  continue;
387  if (!tinfo->IsValid(ns))
388  continue;
389  Double_t v=tinfo->T(ns,type);
390  if (v>ret)
391  ret=v;
392  }
393  return ret;
394 }
395 
397 {
398  Double_t ret=1e9;
399  const Int_t rns=fArr->GetEntries();
400  for (Int_t i=0;i<rns;++i) {
401  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
402  if (!tinfo)
403  continue;
404  Double_t v=tinfo->AbsMinT(type);
405  if (v<ret)
406  ret=v;
407  }
408  return ret;
409 }
410 
412 {
413  Double_t ret=1e9;
414  const Int_t rns=fArr->GetEntries();
415  for (Int_t i=0;i<rns;++i) {
416  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
417  if (!tinfo)
418  continue;
419  if (!tinfo->IsValid(ns))
420  continue;
421  Double_t v=tinfo->T(ns,type);
422  if (v<ret)
423  ret=v;
424  }
425  return ret;
426 }
427 
429 {
430  Int_t ret=0;
431  const Int_t nbad = fBad.GetSize();
432  for (Int_t ns=0,first=0;ns<nbad;++ns) {
433  if (IsGood(ns))
434  continue;
435  ++ret;
436  }
437  return ret;
438 }
439 
440 TH1 *TDraw::GetT(Int_t ns1, Int_t ns2, Int_t type) const
441 {
442  const Int_t rns=fArr->GetEntries();
443  TProfile *ret = new TProfile(Form("h%d%d%d",ns1,ns2,type),Form(";run idx"),rns,0,rns);
444  ret->SetDirectory(0);
445  ret->SetStats(0);
446  for (Int_t i=0;i<rns;++i) {
447  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
448  if (!tinfo)
449  continue;
450  for (Int_t j=ns1;j<=ns2;++j) {
451  if (!tinfo->IsValid(j))
452  continue;
453  Double_t val = tinfo->T(j,type);
454  ret->Fill(i,val);
455  }
456  }
457  return ret;
458 }
459 
460 TH2 *TDraw::GetT2D(Int_t type) const
461 {
462  const Int_t rns=fArr->GetEntries();
463  TString title=TInfo::Type(type);
464  TH2F *ret = new TH2F(Form("h2f_%d",type),Form("%s: %s;run idx;sensor idx",GetName(),title.Data()),rns,0,rns,TInfo::NSensors(),0,TInfo::NSensors());
465  ret->SetDirectory(0);
466  ret->SetStats(0);
467  for (Int_t i=0;i<rns;++i) {
468  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
469  if (!tinfo)
470  continue;
471  for (Int_t j=0;j<TInfo::NSensors();++j) {
472  if (!tinfo->IsValid(j))
473  continue;
474  Double_t val = tinfo->T(j,type);
475  ret->SetBinContent(ret->FindBin(i,j),val);
476  }
477  }
478  return ret;
479 }
480 
482 {
483  Int_t ret = 0;
484  const Int_t rns=fArr->GetEntries();
485  for (Int_t i=0;i<rns;++i) {
486  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
487  if (!tinfo)
488  continue;
489  ret += tinfo->IsValid(ns);
490  }
491  return ret;
492 }
493 
495 {
496  const Int_t rns=fArr->GetEntries();
497  cout << "Period: " << GetName() << " with " << rns << " runs" << endl;
498  if (strlen(opt)>0)
499  for (Int_t ns=0;ns<TInfo::NSensors();++ns)
500  cout << "Channel " << ns << " " << GetFraction(ns) << endl;
501  for (Int_t i=0;i<rns;++i) {
502  TInfo *tinfo = dynamic_cast<TInfo*>(fArr->At(i));
503  if (!tinfo)
504  continue;
505  cout << "-> " << i << ": run=" << tinfo->GetRunNo() << " frac=" << tinfo->Fraction() << " minT=" << tinfo->AbsMinT()<< " maxT=" << tinfo->AbsMaxT() << endl;
506  if (strlen(opt)>0)
507  tinfo->Print();
508  }
509 }
510 
511 void plotT_period(const char *period, Bool_t doprint=0)
512 {
513  TDraw d(period);
514  d.SetPrint(doprint);
515  d.Compute();
516  d.Print();
517  if (0) {
518  d.DrawOccRun();
519  d.DrawOccSensor2D();
520  d.DrawT2D(3);
521  d.DrawT(3);
522  } else
523  d.DrawAll();
524 }
525 
526 void plotOCDB_Temperature(const char *period="lhc18d")
527 {
528  plotT_period(period);
529 }
530 
TH2 * GetOccSensor2D() const
double Double_t
Definition: External.C:58
void plotT_period(const char *period, Bool_t doprint=0)
Int_t GetBad(Int_t ns) const
Definition: External.C:236
const char * title
Definition: MakeQAPdf.C:27
Bool_t fDoPrint
Definition: TInfo.h:10
static Int_t NSensors()
Definition: TInfo.h:46
Int_t GetNFaulty() const
Definition: TInfo.h:26
TH1 * GetOccSensor() const
TH1 * GetOccRun() const
Float_t AbsMaxT(Int_t t=2) const
Definition: TInfo.cxx:23
Int_t GetNBad() const
static Int_t GetBin(Int_t ns)
Definition: TInfo.cxx:90
TCanvas * c
Definition: TestFitELoss.C:172
TObjArray * fArr
Int_t GetNRuns() const
TH1 * GetT(Int_t ns1, Int_t ns2, Int_t type=3) const
TCanvas * DrawT2D(Int_t type=3) const
TH2 * GetMask() const
TCanvas * DrawT(Int_t type=3) const
Double_t GetMinTperS(Int_t ns, Int_t type=3) const
void SetNFaulty(Int_t n)
Definition: TInfo.h:40
Double_t GetMinT(Int_t type=3) const
int Int_t
Definition: External.C:63
virtual ~TDraw()
Bool_t IsGood(Int_t ns) const
void SetBad(Int_t ns, Bool_t b)
Bool_t IsValid(Int_t ns) const
Definition: TInfo.h:30
void SetPrint(Bool_t b=1)
Double_t fMinFrac
Double_t GetFraction(Int_t ns) const
void plotOCDB_Temperature(const char *period="lhc18d")
TH2 * GetHist(Int_t type=1) const
Definition: TInfo.cxx:46
Int_t GetNRunsValid(Int_t ns) const
void Compute()
TObjArray * GetArray()
TCanvas * DrawOccRun() const
void Print(Option_t *option="") const
Definition: TInfo.cxx:66
Double_t GetMaxTperS(Int_t ns, Int_t type=3) const
TH2 * GetOcc2D() const
void Print(Option_t *opt="") const
TArrayI fBad
Definition: External.C:220
Float_t T(Int_t ns, Int_t t) const
Definition: TInfo.cxx:75
TDraw(const char *name, const char *fname="tempinfo.root")
TCanvas * DrawOccSensor2D() const
TH2 * GetT2D(Int_t type=3) const
const char Option_t
Definition: External.C:48
Float_t AbsMinT(Int_t t=1) const
Definition: TInfo.cxx:10
Double_t Fraction() const
Definition: TInfo.h:28
bool Bool_t
Definition: External.C:53
static const char * Type(Int_t t)
Definition: TInfo.cxx:314
Int_t GetRunNo() const
Definition: TInfo.h:25
TCanvas * DrawOcc2D() const
Definition: External.C:196
Int_t GetRunNo(Int_t run) const
Double_t GetMaxT(Int_t type=3) const