AliPhysics  3337bb0 (3337bb0)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QATrender.C
Go to the documentation of this file.
1 
10 #ifndef __CINT__
11 # include <TFile.h>
12 # include <TTree.h>
13 # include <TH1.h>
14 # include <TH2.h>
15 # include <TList.h>
16 # include <TStyle.h>
17 # include <TCanvas.h>
18 # include <TPad.h>
19 # include <TLatex.h>
20 # include <TMath.h>
21 # include <THStack.h>
22 # include <TLegend.h>
23 # include <TLegendEntry.h>
24 # include <TLine.h>
25 # include <TLinearFitter.h>
26 # include <TF1.h>
27 # include <TSystem.h>
28 # include <fstream>
29 # include <TFile.h>
30 # include <TParameter.h>
31 # include "QAStructs.h"
32 # include "QARing.h"
33 # include "QABase.h"
34 #else
35 class TList;
36 class TFile;
37 class TH1;
38 class Quantity;
39 class RingQuantity;
40 class Merge;
41 class FitStatus;
42 class Correlation;
43 class QARing;
44 class QABase;
45 class Global;
46 class THStack;
47 class TLatex;
48 class TVirtualPad;
49 #endif
50 
51 
52 // --- A quantity ----------------------------------------------------
58 struct QATrender : public QABase
59 {
60 public:
61  /******************************************************************/
66  struct Ring : public QARing
67  {
74  Ring(UShort_t d, Char_t r) : QARing(d, r) {}
82  TList* GetDetectorList(const TList* parent) const
83  {
84  TObject* o = QATrender::GetSubList(parent, Form("FMD%d%c", fD, fR));
85  return static_cast<TList*>(o);
86  }
96  Bool_t ExtractYQuantity(const TList* parent, const char* name,
97  Quantity* q)
98  {
99  q->mean = 0;
100  q->var = 0;
101  q->min = 0;
102  q->max = 0;
103 
104  TH1* h = QATrender::GetHistogram(parent, name);
105  if (!h) {
106  // Warning("ExtractYQuantity", "Histogram %s not found", name);
107  return false;
108  }
109 
110  Double_t sum = 0;
111  Double_t sumw = 0;
112  Double_t min = 1e12;
113  Double_t max = 0;
114  for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
115  Double_t y = h->GetBinContent(i);
116  Double_t e = h->GetBinError(i);
117  Double_t w = 1;
118  if (y <= 1e-12) continue;
119  if (e != 0) w = 1 / (e*e);
120  sum += w * y;
121  sumw += w;
122  min = TMath::Min(min, y);
123  max = TMath::Max(max, y);
124  // Info("", " %s %3d: y=%f,\t e=%f,\t w=%f", name, i, y, e, w);
125  }
126  q->min = min;
127  q->max = max;
128  if (sumw <= 1e-6) {
129  // Warning("ExtractYQuantity",
130  // "Sum of weights for %s too small %g<1e-6",
131  // name, sumw);
132  return true;
133  }
134  q->mean = sum / sumw;
135  q->var = TMath::Sqrt(1/sumw);
136  // Info(name, " mean=%f, var=%f", q->mean, q->var);
137  return true;
138  }
147  {
148  TList* det = GetDetectorList(parent);
149  if (!det) return false;
150 
151  TList* res = QATrender::GetSubList(det, "FitResults",false);
152  if (!res) {
153  res = QATrender::GetSubList(det, "elossResults",false);
154  if (!res) {
155  Warning("ProcessEnergyLoss", "Neither FitResults nor elossResults found");
156  return false;
157  }
158  }
159 
160  ExtractYQuantity(res, Form("FMD%d%c_chi2", fD, fR), fChi2);
161  ExtractYQuantity(res, Form("FMD%d%c_c", fD, fR), fC);
162  ExtractYQuantity(res, Form("FMD%d%c_delta", fD, fR), fDelta);
163  ExtractYQuantity(res, Form("FMD%d%c_xi", fD, fR), fXi);
164  ExtractYQuantity(res, Form("FMD%d%c_sigma", fD, fR), fSigma);
165 
166  TH1* status = QATrender::GetHistogram(res, "status",false);
167  if (!status) {
168  status = QATrender::GetHistogram(res, "elossStatus",false);
169  if (!status) {
170  Warning("ProcessEnergyLoss", "Neither status nor elossStatus found");
171  return false;
172  }
173  }
174  fFitStatus->nLow = UShort_t(status->GetBinContent(3));
175  fFitStatus->nCandidates = UShort_t(status->GetBinContent(4));
176  fFitStatus->nFitted = UShort_t(status->GetBinContent(5));
177 
178  return true;
179  }
188  Bool_t ProcessNeighbors(const TList* parent, TVirtualPad* p)
189  {
190  if (!p) return true; // Case of no drawing
191 
192  TList* det = GetDetectorList(parent);
193  if (!det) return false;
194 
195  TH1* before = QATrender::GetHistogram(det, "neighborsBefore");
196  TH1* after = QATrender::GetHistogram(det, "neighborsAfter");
197  if (!before || !after) return false;
198 
199  if (before->GetMaximum() > 0) p->SetLogz();
200  p->SetFillColor(0);
201  if (fD == 3) p->SetRightMargin(0.15);
202 
203  before->SetTitle(Form("FMD%d%c",fD,fR));
204  before->Draw("colz");
205  after->Draw("same box");
206 
207  before->GetXaxis()->SetRangeUser(-.5, 2);
208  before->GetYaxis()->SetRangeUser(-.5, 2);
209 
210  TLatex* ltx = new TLatex(p->GetLeftMargin()+.01,
211  p->GetBottomMargin()+.01,
212  before->GetTitle());
213  ltx->SetNDC();
214  ltx->SetTextSize(.07);
215  ltx->Draw();
216 
217  return true;
218  }
227  Bool_t Process123(const TList* parent, TVirtualPad* p)
228  {
229  TList* det = GetDetectorList(parent);
230  if (!det) return false;
231 
232  fMerge->one = 0;
233  fMerge->two = 0;
234  fMerge->three = 0;
235 
236  TH1* one = QATrender::GetHistogram(det, "singleEloss");
237  TH1* two = QATrender::GetHistogram(det, "doubleEloss");
238  TH1* three = QATrender::GetHistogram(det, "tripleEloss");
239  if (!one || !two || !three) return false;
240 
241  Int_t nOne = one->GetEntries();
242  Int_t nTwo = two->GetEntries();
243  Int_t nThree = three->GetEntries();
244  Int_t total = nOne + nTwo + nThree;
245  if (total > 0) {
246  fMerge->one = Double_t(nOne) / total;
247  fMerge->two = Double_t(nTwo) / total;
248  fMerge->three = Double_t(nThree) / total;
249  }
250 
251  if (!p) return true;
252 
253  one->SetStats(0);
254  one->SetTitle(Form("FMD%d%c", fD, fR));
255  one->GetXaxis()->SetRangeUser(0, 8);
256 
257  if (one->GetMaximum() > 0) p->SetLogy();
258  p->SetFillColor(0);
259  if ((p->GetNumber() % 3) != 1) p->SetLeftMargin(.1);
260 
261  one->SetLineStyle(1);
262  two->SetLineStyle(2);
263  three->SetLineStyle(3);
264 
265  one->Draw();
266  two->Draw("same");
267  three->Draw("same");
268 
269  // Double_t ts = 0.03;
270  Double_t y = 1-p->GetTopMargin()-1.2*gStyle->GetTitleH(); // +ts;
271  Double_t x = p->GetLeftMargin() + .25;
272  TLatex* ltx = new TLatex(x, y, "Fraction of ...");
273  ltx->SetNDC();
274  ltx->SetTextColor(kBlue+3);
275  ltx->SetTextAlign(13);
276  // ltx->SetTextAlign(33);
277  ltx->SetTextSize(.07);
278  ltx->Draw();
279 
280  // y -= .1;
281  DrawText(ltx, x, y, "Singles:", Form("%5.2f%%", fMerge->one * 100));
282  DrawText(ltx, x, y, "Doubles:", Form("%5.2f%%", fMerge->two * 100));
283  DrawText(ltx, x, y, "Triples:", Form("%5.2f%%", fMerge->three * 100));
284 
285  p->cd();
286 
287  return true;
288  }
298  Bool_t ProcessELoss(TList* p1, TList* p2, TVirtualPad* p)
299  {
300  TList* det1 = GetDetectorList(p1);
301  if (!det1) return false;
302 
303  TList* det2 = GetDetectorList(p2);
304  if (!det2) return false;
305 
306  TH1* before = QATrender::GetHistogram(det1, "esdEloss");
307  TH1* after = QATrender::GetHistogram(det1, "anaEloss");
308  TH1* presented = QATrender::GetHistogram(det2, "eloss");
309  TH1* used = QATrender::GetHistogram(det2, "elossUsed");
310 
311  if (!before || !after || !presented || !used) return false;
312 
313  const Double_t lowCut = 0.15;
314 
315  Int_t low = before->GetXaxis()->FindBin(lowCut);
316  Int_t ib = Int_t(before->Integral(low,before->GetNbinsX()));
317  Int_t ia = Int_t(after->Integral(low,after->GetNbinsX()));
318  Int_t ip = Int_t(presented->Integral(low,presented->GetNbinsX()));
319  Int_t iu = Int_t(used->Integral(low,used->GetNbinsX()));
320 
321  Double_t dba = ib > 0 ? (100.*(ia-ib))/ib : 0;
322  Double_t dbp = ib > 0 ? (100.*(ip-ib))/ib : 0;
323  Double_t dbu = ib > 0 ? (100.*(iu-ib))/ib : 0;
324  Double_t dap = ia > 0 ? (100.*(ip-ia))/ia : 0;
325  Double_t dau = ia > 0 ? (100.*(iu-ia))/ia : 0;
326  Double_t dpu = ip > 0 ? (100.*(iu-ip))/ip : 0;
327 
328  fDataLoss->merge = dba;
329  fDataLoss->density = dau;
330  fDataLoss->full = dbu;
331 
332  if (!p) return true;
333 
334  if (before->GetMaximum() > 0) p->SetLogy();
335  p->SetFillColor(0);
336  before->SetTitle(Form("FMD%d%c",fD,fR));
337 
338  before->SetLineStyle(1);
339  after->SetLineStyle(2);
340  used->SetLineStyle(3);
341 
342  before->Draw("");
343  after->Draw("same");
344  presented->Draw("same");
345  used->Draw("same");
346 
347  Double_t ts = 0.03;
348  Double_t x = p->GetLeftMargin() + .25;
349  Double_t y = 1-p->GetTopMargin()-gStyle->GetTitleH()+ts;
350  TLatex* ltx = new TLatex(x, y, Form("FMD%d%c", fD, fR));
351  ltx->SetNDC();
352  ltx->SetTextAlign(13);
353  ltx->SetTextSize(ts);
354  ltx->SetTextColor(kBlue+3);
355  // ltx->Draw();
356  // ltx->SetTextSize(.05);
357  TString inte(Form("Integral [%4.2f,#infty]", lowCut));
358  DrawText(ltx, x, y, Form("%s before:", inte.Data()), Form("%9d", ib));
359  DrawText(ltx, x, y, Form("%s after:", inte.Data()), Form("%9d", ia));
360  DrawText(ltx, x, y, Form("%s input:", inte.Data()), Form("%9d", ip));
361  DrawText(ltx, x, y, Form("%s user:", inte.Data()), Form("%9d", iu));
362  TLine* l = new TLine;
363  l->SetLineWidth(1);
364  l->DrawLineNDC(x, y-0.9*ts, 1-p->GetRightMargin()-0.01, y-0.9*ts);
365  if (ib != 0 && ia != 0) {
366  DrawText(ltx, x, y, "Change (merging)", Form("%5.1f%%", dba));
367  DrawText(ltx, x, y, "Change (input)", Form("%5.1f%% (%5.1f%%)",
368  dap, dbp));
369  DrawText(ltx, x, y, "Change (use)", Form("%5.1f%% (%5.1f%%)",
370  dpu, dbu));
371  }
372  before->GetXaxis()->SetRangeUser(0, 4);
373  p->cd();
374 
375  return true;
376  }
385  Bool_t ProcessOccupancy(const TList* parent, TVirtualPad* p)
386  {
387  TList* det = GetDetectorList(parent);
388  if (!det) return false;
389 
390  TH1* occ = QATrender::GetHistogram(det, "occupancy");
391  if (!occ) return false;
392 
393  fOccupancy->mean = occ->GetMean();
394  fOccupancy->var = occ->GetRMS();
395  fOccupancy->min = 1;
396  fOccupancy->max = 0;
397 
398  for (Int_t i = occ->GetNbinsX(); i >= 1; i--) {
399  Double_t y = occ->GetBinContent(i);
400  if (y < 1e-6) continue;
401  fOccupancy->max = occ->GetXaxis()->GetBinUpEdge(i);
402  break;
403  }
404 
405  if (!p) return true;
406  p->SetGridy();
407  p->SetGridx();
408  if (occ->GetMaximum() > 0) p->SetLogy();
409  p->SetFillColor(0);
410  p->SetRightMargin(0.01);
411  occ->Rebin(4);
412  occ->SetTitle(Form("FMD%d%c", fD, fR));
413  occ->Draw("hist");
414 
415  // Double_t ts = 0.03;
416  Double_t y = 1-p->GetTopMargin()-1.2*gStyle->GetTitleH(); // +ts;
417  Double_t x = p->GetLeftMargin() + .25;
418  TLatex* ltx = new TLatex(x, y, "");
419  ltx->SetNDC();
420  ltx->SetTextColor(kBlue+3);
421  ltx->SetTextAlign(13);
422  // ltx->SetTextAlign(33);
423  ltx->SetTextSize(.07);
424  ltx->Draw();
425 
426  // y -= .1;
427  DrawText(ltx, x, y, "Mean:", Form("%5.2f%%", fOccupancy->mean));
428  DrawText(ltx, x, y, "Variance:", Form("%5.2f%%", fOccupancy->var));
429  DrawText(ltx, x, y, "Max:", Form("%5.2f%%", fOccupancy->max));
430 
431  p->cd();
432 
433  return true;
434  }
443  Bool_t ProcessCorrelation(const TList* parent, TVirtualPad* p)
444  {
445  TList* det = GetDetectorList(parent);
446  if (!det) return false;
447 
448  TH1* co = QATrender::GetHistogram(det, "elossVsPoisson");
449  if (!co) return false;
450  TH2* corr = static_cast<TH2*>(co);
451 
452  fCorrelation->alpha = 0;
453  fCorrelation->beta = 0;
454  fCorrelation->a = 0;
455  fCorrelation->ea = 0;
456  fCorrelation->b = 0;
457  fCorrelation->eb = 0;
458  fCorrelation->chi2 = 0;
459 
460  Double_t xmin = -1;
461  Double_t xmax = corr->GetXaxis()->GetXmax();
462 
463  if (corr->GetEntries() > 0) {
464  // Calculate the linear regression
465  // Double_t dx = (xmax-xmin);
466  // Double_t rxy = corr->GetCorrelationFactor();
467  Double_t sx = corr->GetRMS(1);
468  Double_t sy = corr->GetRMS(2);
469  Double_t sx2 = sx*sx;
470  Double_t sy2 = sy*sy;
471  Double_t cxy = corr->GetCovariance();
472  Double_t mx = corr->GetMean(1);
473  Double_t my = corr->GetMean(2);
474  Double_t delta = 1;
475  if (TMath::Abs(cxy) > 1e-6) {
476  fCorrelation->beta = ((sy2 - delta*sx2 +
477  TMath::Sqrt(TMath::Power(sy2-delta*sx2,2) +
478  4*delta*cxy*cxy)) / 2 / cxy);
479  fCorrelation->alpha = my - fCorrelation->beta * mx;
480  }
481 
482 
483 #if 0
484  TLinearFitter* fitter = new TLinearFitter(1);
485  fitter->SetFormula("1 ++ x");
486  for (Int_t i = 1; i <= corr->GetNbinsX(); i++) {
487  Double_t x = corr->GetXaxis()->GetBinCenter(i);
488  if (x < -1 || x > xmax) continue;
489  for (Int_t j = 1; j <= corr->GetNbinsY(); j++) {
490  Double_t y = corr->GetYaxis()->GetBinCenter(j);
491  if (y < -1 || y > xmax) continue;
492  Double_t c = corr->GetBinContent(i,j);
493  if (c < .1) continue;
494  fitter->AddPoint(&x, y, c);
495  }
496  }
497  fitter->Eval();
498  fCorrelation->a = fitter->GetParameter(0);
499  fCorrelation->ea = fitter->GetParError(0);
500  fCorrelation->b = fitter->GetParameter(1);
501  fCorrelation->eb = fitter->GetParError(1);
502  Double_t chi2 = fitter->GetChisquare();
503  Int_t ndf = (fitter->GetNpoints() -
504  fitter->GetNumberFreeParameters() );
505  fCorrelation->chi2 = chi2 / ndf;
506 #endif
507  }
508  if (!p) return true;
509 
510  p->SetGridy();
511  p->SetGridx();
512  if (corr->GetMaximum() > 0) p->SetLogz();
513  // if (fD == 3) p->SetRightMargin(0.15);
514  p->SetFillColor(0);
515  corr->GetXaxis()->SetRangeUser(-1,xmax);
516  corr->GetYaxis()->SetRangeUser(-1,xmax);
517  corr->SetTitle(Form("FMD%d%c",fD,fR));
518  corr->Draw("colz");
519 
520  TF1* f = new TF1("f", "[0]+[1]*x", xmin, xmax);
521  f->SetParameters(fCorrelation->alpha, fCorrelation->beta);
522  f->SetLineWidth(1);
523  f->SetLineStyle(1);
524  f->Draw("same");
525 
526  TLine* l = new TLine(-1,-1,xmax,xmax);
527  l->SetLineWidth(1);
528  l->SetLineStyle(2);
529  l->SetLineColor(kBlack);
530  l->Draw();
531 
532  Double_t x = p->GetLeftMargin() + .05;
533  Double_t y = 1-p->GetTopMargin()-gStyle->GetTitleH(); // +ts;
534  TLatex* ltx = new TLatex(x, y, "Deming regression: y=#alpha+#beta x");
535  ltx->SetNDC();
536  ltx->SetTextAlign(13);
537  ltx->SetTextSize(0.06);
538  ltx->SetTextColor(kBlue+3);
539  ltx->Draw();
540 
541  DrawText(ltx, x, y, "#alpha:", Form("%5.3f", fCorrelation->alpha));
542  DrawText(ltx, x, y, "#beta:", Form("%5.3f", fCorrelation->beta));
543 
544 #if 0
545  DrawText(ltx, x, y, "A:", Form("%5.3f#pm%5.3f",
546  fCorrelation->a,
547  fCorrelation->ea));
548  DrawText(ltx, x, y, "B:", Form("%5.3f#pm%5.3f",
549  fCorrelation->b,
550  fCorrelation->eb));
551  DrawText(ltx, x, y, "#chi^{2}/#nu:", Form("%5.3f", fCorrelation->chi2));
552 #endif
553  p->cd();
554 
555  return true;
556  }
557  };
558 
559  /******************************************************************/
568  Bool_t /*single*/,
569  Int_t prodYear,
570  char prodLetter)
571  : QABase("data", (prodYear < 2000 ? 2000 : 0) + prodYear,
572  Form("LHC%02d%c", (prodYear%2000), prodLetter), "pass0"),
573  fRunNo(-1),
574  fCurrentFile(0),
575  fSharingFilter(0),
576  fEventInspector(0),
578  fEnergyFitter(0),
579  fFiles(0),
580  fKeep(keep)
581  {
582  fFMD1i = new Ring(1, 'I');
583  fFMD2i = new Ring(2, 'I');
584  fFMD2o = new Ring(2, 'O');
585  fFMD3i = new Ring(3, 'I');
586  fFMD3o = new Ring(3, 'O');
587  }
599  const TString& dataType,
600  Int_t prodYear,
601  const TString& period,
602  const TString& pass,
603  Long_t runNo)
604  : QABase(dataType, prodYear, period, pass),
605  fRunNo(runNo),
606  fCurrentFile(0),
607  fSharingFilter(0),
608  fEventInspector(0),
610  fEnergyFitter(0),
611  fFiles(0),
612  fKeep(keep)
613  {
614  fFMD1i = new Ring(1, 'I');
615  fFMD2i = new Ring(2, 'I');
616  fFMD2o = new Ring(2, 'O');
617  fFMD3i = new Ring(3, 'I');
618  fFMD3o = new Ring(3, 'O');
619  }
623  virtual ~QATrender() {}
629  QATrender(const QATrender& o)
630  : QABase(o),
631  fRunNo(o.fRunNo),
637  fFiles(0),
638  fKeep(o.fKeep)
639  {}
645  QATrender operator=(const QATrender&) { return *this; }
646 
647 
648  // --- Interface ---------------------------------------------------
654  void AddFile(const char* filename)
655  {
656  fFiles.Add(new TObjString(filename));
657  }
664  {
665  Init(false);
666  TIter next(&fFiles);
667  TObject* o = 0;
668  Bool_t ret = true;
669  while ((o = next())) {
670  if (!ProcessOne(o->GetName())) ret = false;
671  }
672  Finish();
673  return ret;
674  }
679  void Finish()
680  {
681  if (!fOutput) return;
682  TList* l = fTree->GetUserInfo();
683  l->Add(new TNamed("period", fPeriod.Data()));
684  l->Add(new TNamed("pass", fPass.Data()));
685  l->Add(new TNamed("type", fDataType.Data()));
686  l->Add(new TParameter<Long_t>("year", fYear));
687  fOutput->Write();
688  fOutput->Close();
689  fOutput = 0;
690  fTree = 0;
691  std::ofstream doc(".doc");
692  doc << fPeriod << " " << fPass << " ("
693  << fDataType << ") " << fRunNo << std::endl;
694  doc.close();
695  gSystem->Exec(Form("chmod g+rw %s", OutputName()));
696  }
698  {
699  if (fCurrentFile) {
700  fCurrentFile->Close();
701  fCurrentFile = 0;
702  }
703 
704  fCurrentFile = TFile::Open(filename, "READ");
705  if (!fCurrentFile) {
706  Error("ProcessOne", "Failed to open %s", filename);
707  return false;
708  }
709 
710  if (!GetLists(false)) {
711  // Error("ProcessOne", "Failed to get lists from %s", filename);
712  return false;
713  }
714  return true;
715  }
724  {
725  const char* subs[] = { "",
726  "trending.root",
727  "trending_barrel.root",
728  0 };
729  const char** psub = subs;
730  Bool_t ret = false;
731  while (*psub) {
732  TString fn(filename);
733  if ((*psub)[0] != '\0') {
734  Int_t hash = fn.Index("#");
735  if (hash != kNPOS)
736  fn.Replace(hash+1,fn.Length()-hash-1,*psub);
737  else
738  fn = gSystem->ConcatFileName(gSystem->DirName(filename),
739  *psub);
740  }
741  Info("ProcessOne", "Trying %s", fn.Data());
742  ret = GetInputLists(fn);
743  if (ret) break;
744  Info("ProcessOne", "No success, try the next");
745  psub++;
746  }
747  if (!ret) return false;
748 
749  if (!ProcessGlobal()) {
750  Error("ProcessOne", "Failed to get global stuff from %s", filename);
751  return false;
752  }
753  // fTeXName = Form("qa_%09d", fGlobal->runNo);
754  TString title;
755  if (!fPeriod.IsNull() && !fPass.IsNull())
756  title.Form("QA plots for %s/%s run %ld (%s)",
757  fPeriod.Data(), fPass.Data(), fRunNo, fDataType.Data());
758  else
759  title.Form("QA plots for run %d", fGlobal->runNo);
760  MakeCanvas(title);
761  Bool_t eloss = ProcessELossFitter();
762  Bool_t merge = ProcessSharingFilter();
764  if (fTree) fTree->Fill();
765  CloseCurrent();
766 
767  return eloss && merge && dense;
768  }
769  // --- Processing member functions ---------------------------------
776  {
777  TObject* oRun = GetObject(fEventInspector, "runNo");
778  if (!oRun) return false;
779 
780  fGlobal->runNo = oRun->GetUniqueID();
781  if (fRunNo <= 0) fRunNo = fGlobal->runNo;
782 
783  TH1* oAcc = GetHistogram(fEventInspector,"nEventsAccepted");
784  if (!oAcc) return false;
785 
786  fGlobal->nAccepted = oAcc->GetEntries();
787  fGlobal->meanVz = oAcc->GetMean();
788  fGlobal->sigmaVz = oAcc->GetRMS();
789 
790  return true;
791  }
798  void CleanStack(THStack* stack, const char* what)
799  {
800  TList* l = stack->GetHists();
801  if (!l || l->GetEntries() <= 0) {
802  Warning("CleanStack", "No histograms in stack %s", stack->GetName());
803  return;
804  }
805  // Printf("Stack to clean %s", stack->GetName());
806  // l->ls();
807 
808  // Clean up list of histogram. Histograms with no entries or
809  // no functions are deleted. We have to do this using the TObjLink
810  // objects stored in the list since ROOT cannot guaranty the validity
811  // of iterators when removing from a list - tsck. Should just implement
812  // TIter::Remove().
813  TObjLink* lnk = l->FirstLink();
814  while (lnk) {
815  TObject* o = lnk->GetObject();
816  TString s(o->GetName());
817  if (s.Contains(what)) {
818  TObjLink* keep = lnk->Next();
819  l->Remove(lnk);
820  lnk = keep;
821  continue;
822  }
823  lnk = lnk->Next();
824  }
825  }
833  {
834  if (!fEnergyFitter) return true;
835 
836  MakeCanvasTitle("Summary of energy loss fits");
837 
838  THStack* chi2 = static_cast<THStack*>(GetObject(fEnergyFitter, "chi2"));
839  THStack* c = static_cast<THStack*>(GetObject(fEnergyFitter, "c"));
840  THStack* delta = static_cast<THStack*>(GetObject(fEnergyFitter, "delta"));
841  THStack* xi = static_cast<THStack*>(GetObject(fEnergyFitter, "xi"));
842  THStack* sigma = static_cast<THStack*>(GetObject(fEnergyFitter, "sigma"));
843 
844  if (!chi2) return false;
845  if (!c) return false;
846  if (!delta) return false;
847  if (!xi) return false;
848  if (!sigma) return false;
849 
850  CleanStack(chi2, "_n");
851  CleanStack(c, "status");
852  if (fCanvas) {
853  const int nL = 3;
854  THStack* stacks[] = { chi2, c, delta, xi, sigma, 0 };
855  for (int i = 0; i < 5; i++) {
856  THStack* stack = stacks[i];
857  if (!stack->GetHists() || stack->GetHists()->GetEntries() < 0) {
858  Warning("", "No histograms in stack %s", stack->GetName());
859  continue;
860  }
861  TVirtualPad* p = GetPad(i+1);
862  // stack->GetHists()->ls();
863 
864  p->SetLeftMargin(.6/nL);
865  p->SetTopMargin(.01);
866  p->SetRightMargin(.01);
867  p->SetFillColor(0);
868  p->SetFillStyle(0);
869  p->SetGridx();
870  stack->Draw("nostack");
871  stack->GetHistogram()->SetYTitle(stack->GetTitle());
872  stack->GetHistogram()->SetXTitle("#eta");
873 
874  TAxis* yaxis = stack->GetHistogram()->GetYaxis();
875  if (i == 0) yaxis->SetRangeUser(0,20); // Chi2
876  if (i == 1) stack->SetMaximum(1); // c
877  if (i == 2) stack->SetMaximum(1); // delta
878  if (i == 3) stack->SetMaximum(0.1); // xi
879  if (i == 4) stack->SetMaximum(0.5); // sigma{,n}
880  // if (i == 0) p->SetLogy();
881  yaxis->SetTitleSize(0.3/nL);
882  yaxis->SetLabelSize(0.08);
883  yaxis->SetTitleOffset(3/nL);
884  yaxis->SetNdivisions(5);
885  yaxis->SetTitleFont(42);
886  yaxis->SetLabelFont(42);
887  yaxis->SetDecimals();
888 
889  TAxis* xaxis = stack->GetHistogram()->GetXaxis();
890  xaxis->SetTitleSize(0.3/nL);
891  xaxis->SetLabelSize(0.08);
892  xaxis->SetTitleOffset(2./nL);
893  xaxis->SetNdivisions(10);
894  xaxis->SetTitleFont(42);
895  xaxis->SetLabelFont(42);
896  xaxis->SetDecimals();
897 
898  stack->Draw("nostack");
899  p->cd();
900  }
901  TVirtualPad* p = GetPad(6);
902  p->SetFillColor(kWhite);
903  Double_t x = .3;
904  Double_t y = .8;
905  TLatex* l = new TLatex(x, y, "Fits to #Delta (energy loss) spectra");
906  l->SetTextColor(kBlue+3);
907  l->SetNDC();
908  l->Draw();
909  x = .05;
910  y -= 2 * 1.2*l->GetTextSize();
911  l->DrawLatex(x, y, "F(#Delta;c,#Delta_{p},#xi,#sigma)="
912  "#frac{c}{#sqrt{2#pi}#sigma}#int_{-#infty}^{#infty}d#Delta'"
913  "L(#Delta;#Delta',#xi) G(#Delta_{p};#Delta',#sigma^{2})");
914  y -= 1.2*l->GetTextSize();
915  x += .1;
916  DrawText(l, x, y, "#chi^{2}/#nu", "Goodness of fit", .2);
917  DrawText(l, x, y, "c", "Overall constant", .2);
918  DrawText(l, x, y, "#Delta_{p}", "Most probable value", .2);
919  DrawText(l, x, y, "#xi", "'Width' of Landau (L)", .2);
920  DrawText(l, x, y, "#sigma", "'Width' of Gaussian (G)", .2);
921 
922  // stack->GetHists()->ls();
923 
924  PrintCanvas("fitResults", fGlobal->runNo);
925  }
926 
927  static_cast<Ring*>(fFMD1i)->ProcessEnergyLoss(fEnergyFitter);
928  static_cast<Ring*>(fFMD2i)->ProcessEnergyLoss(fEnergyFitter);
929  static_cast<Ring*>(fFMD2o)->ProcessEnergyLoss(fEnergyFitter);
930  static_cast<Ring*>(fFMD3i)->ProcessEnergyLoss(fEnergyFitter);
931  static_cast<Ring*>(fFMD3o)->ProcessEnergyLoss(fEnergyFitter);
932 
933  return true;
934  }
942  {
943  // --- Neighbors -------------------------------------------------
944  MakeCanvasTitle("Correlation of neighboring strips");
945 
946  for (Int_t i = 1; i <= 6; i++) {
947  TVirtualPad* p = GetPad(i);
948 
949  Ring* r = GetRing(i);
950  if (!r) continue;
951 
953  }
954  TVirtualPad* p = 0;
955  if ((p = GetPad(4))) {
956  p->SetFillColor(kWhite);
957 
958  TLatex* l = new TLatex(.2, .7, "Gradient: before merging");
959  l->SetNDC();
960  l->SetTextColor(kBlue+3);
961  l->Draw();
962  l->DrawText(.2, .6, "Boxes: after merging");
963 
964  fCanvas->cd();
965  PrintCanvas("neighbors", fGlobal->runNo);
966  }
967 
968  // --- 123 -------------------------------------------------------
969  MakeCanvasTitle("#Delta for singles, doubles, and triples");
970 
971  for (Int_t i = 1; i <= 6; i++) {
972  p = GetPad(i);
973 
974  Ring* r = GetRing(i);
975  if (!r) continue;
976 
977  r->Process123(fSharingFilter, p);
978  }
979  if ((p = GetPad(4))) {
980  TLegend* ll = new TLegend(.2, .2, .8, .8);
981  ll->SetFillColor(0);
982  ll->SetBorderSize(0);
983  TLegendEntry* e = ll->AddEntry("dummy", "Singles", "l");
984  e->SetLineStyle(1);
985  e = ll->AddEntry("dummy", "Doubles", "l");
986  e->SetLineStyle(2);
987  e = ll->AddEntry("dummy", "Triples", "l");
988  e->SetLineStyle(3);
989  ll->Draw();
990 
991  PrintCanvas("123", fGlobal->runNo);
992  }
993  return true;
994  }
1002  {
1003  // --- ELoss -----------------------------------------------------
1004  MakeCanvasTitle("Energy loss from ESD, after merging, used");
1005 
1006  for (Int_t i = 1; i <= 6; i++) {
1007  TVirtualPad* p = GetPad(i);
1008 
1009  Ring* r = GetRing(i);
1010  if (!r) continue;
1011 
1013  }
1014  TVirtualPad* p = 0;
1015  if ((p = GetPad(4))) {
1016  TLegend* ll = new TLegend(.2, .2, .8, .8);
1017  ll->SetFillColor(0);
1018  ll->SetBorderSize(0);
1019  TLegendEntry* e = ll->AddEntry("dummy", "From ESDs", "l");
1020  e->SetLineStyle(1);
1021  e = ll->AddEntry("dummy", "After Merging", "l");
1022  e->SetLineStyle(2);
1023  e = ll->AddEntry("dummy", "Used", "l");
1024  e->SetLineStyle(3);
1025  ll->Draw();
1026 
1027  PrintCanvas("recAna", fGlobal->runNo);
1028  }
1029 
1030  // --- Occupancy -------------------------------------------------
1031  MakeCanvasTitle("Occupancy");
1032 
1033  for (Int_t i = 1; i <= 6; i++) {
1034  p = GetPad(i);
1035 
1036  Ring* r = GetRing(i);
1037  if (!r) continue;
1038 
1040  }
1041  if ((p = GetPad(4))) {
1042  TLatex* ltx = new TLatex(.2, .8, "Calculated assuming Poisson stat.");
1043  ltx->SetNDC();
1044  ltx->SetTextColor(kBlue+3);
1045  ltx->Draw();
1046 
1047  TObject* etaL = GetObject(fDensityCalculator, "etaLumping");
1048  TObject* phiL = GetObject(fDensityCalculator, "phiLumping");
1049  if (etaL && phiL)
1050  ltx->DrawLatex(.2, .7, Form("Regions of %s strips #times %s sectors",
1051  etaL->GetTitle(), phiL->GetTitle()));
1052 
1053  PrintCanvas("occupancy", fGlobal->runNo);
1054  }
1055 
1056  // --- Correlation of methods ------------------------------------
1057  MakeCanvasTitle("Correlation of N_{ch} methods");
1058 
1059  for (Int_t i = 1; i <= 6; i++) {
1060  p = GetPad(i);
1061 
1062  Ring* r = GetRing(i);
1063  if (!r) continue;
1064 
1066  }
1067  if ((p = GetPad(4))) {
1068  TLatex* ltx = new TLatex(.2, .8, "Correlation of N_{ch} methods");
1069  ltx->SetNDC();
1070  ltx->SetTextColor(kBlue+3);
1071  ltx->Draw();
1072  ltx->DrawLatex(.24, .7, "From #DeltaE fits along x");
1073  ltx->DrawLatex(.24, .6, "From Poisson assumption along y");
1074  ltx->DrawLatex(.24, .4, "Solid line: regression");
1075  ltx->DrawLatex(.24, .3, "Dashed line: x=y to guide the eye");
1076 
1077  PrintCanvas("elossVsPoisson", fGlobal->runNo);
1078  }
1079 
1080  return true;
1081  }
1082 
1083  // --- Utilities ---------------------------------------------------
1089  {
1090  if (fCurrentFile) {
1091  fCurrentFile->Close();
1092  fCurrentFile = 0;
1093  fSharingFilter = 0;
1094  fEventInspector = 0;
1095  fDensityCalculator = 0;
1096  fEnergyFitter = 0;
1097  }
1098  bool keep = fKeep;
1099  // if (fSingle) keep = true;
1100 
1101  Close(!keep);
1102  }
1107  virtual void WriteLinks()
1108  {
1109  const char* lbUrl = "https://alice-logbook.cern.ch/logbook/date_online.php";
1110  const char* crUrl = "http://alimonitor.cern.ch/configuration/index.jsp";
1111  const char* rpUrl = "http://alimonitor.cern.ch/runview/?run=";
1113 
1114  TFile* results = 0;
1115  if (!gSystem->AccessPathName("QAresults.root"))
1116  results = TFile::Open("QAresults.root", "READ");
1117  if (results) {
1118  *fHtml << "<h3>QA results</h3>\n"
1119  << "<ul>\n"
1120  << "<li><a href='QAresults.root'>ROOT file</a></li>\n"
1121  << "</ul>"
1122  << std::endl;
1123  results->Close();
1124  }
1125 
1126  *fHtml << "<h3>External links</h3>\n"
1127  << "<ul>\n"
1128  << " <li><a target='_blank' href='" << lbUrl
1129  << "?p_cont=rund&p_run=" << fGlobal->runNo
1130  << "&p_tab=dqm&p_dqmagent=FMDQAshifter'>DQM plots</a>"
1131  << " (restricted)</li>\n"
1132  << " <li><a target='_blank' href='" << crUrl
1133  << "?raw_run=" << fGlobal->runNo;
1134  if (!fPeriod.IsNull())
1135  *fHtml << "&partition=" << fPeriod;
1136  *fHtml << "'>Condition Table</a></li>\n"
1137  << " <li><a target='_blank' href='" << rpUrl << fGlobal->runNo
1138  << "'>Processing Details</a></li>\n"
1139  << "</ul>" << std::endl;
1140  }
1141 
1149  Ring* GetRing(Int_t padNo)
1150  {
1151  QARing* r = 0;
1152  switch(padNo) {
1153  case 1: r = fFMD1i; break;
1154  case 2: r = fFMD2i; break;
1155  case 3: r = fFMD3i; break;
1156  case 5: r = fFMD2o; break;
1157  case 6: r = fFMD3o; break;
1158  }
1159  if (r) return static_cast<Ring*>(r);
1160  return 0;
1161  }
1169  TVirtualPad* GetPad(Int_t padNo)
1170  {
1171  if (!fCanvas) return 0;
1172  TVirtualPad* p = fCanvas->cd(padNo);
1173  if (!p) return 0;
1174  p->Clear();
1175  p->SetFillColor(kWhite);
1176  return p;
1177  }
1178 
1184  void MakeCanvasTitle(const char* what)
1185  {
1186  if (!fCanvas) return;
1187  fCanvas->cd();
1188 
1189  CanvasTitle(what);
1190  fCanvas->Divide(3,2,0,0);
1191  }
1192  // --- List utilities ----------------------------------------------
1202  static TList* GetSubList(const TList* parent, const char* name,
1203  Bool_t verbose=true)
1204  {
1205  TList* tmp = static_cast<TList*>(parent->FindObject(name));
1206  if (!tmp) {
1207  if (verbose)
1208  Error("GetSubLists", "List %s not found in %s", name,
1209  parent->GetName());
1210  return 0;
1211  }
1212  return tmp;
1213  }
1220  Bool_t GetLists(Bool_t verbose=true)
1221  {
1222  if (!fCurrentFile) return 0;
1223 
1224  const char* folder = "ForwardResults";
1225  TList* forward = static_cast<TList*>(fCurrentFile->Get(folder));
1226  if (!forward) {
1227  const char* folder2 = "ForwardQAResults";
1228  forward = static_cast<TList*>(fCurrentFile->Get(folder2));
1229  if (!forward) {
1230  const char* folder3 = "forwardQAResults";
1231  forward = static_cast<TList*>(fCurrentFile->Get(folder3));
1232  if (!forward) {
1233  if (verbose)
1234  Error("GetLists", "List %s/%s/%s not found in %s",
1235  folder, folder2, folder3, fCurrentFile->GetName());
1236  return false;
1237  }
1238  }
1239  }
1240 
1241  fEventInspector = GetSubList(forward, "fmdEventInspector");
1242  if (!fEventInspector) {
1243  const char* sfolder = "ForwardSums";
1244  forward = static_cast<TList*>(fCurrentFile->Get(sfolder));
1245  }
1246 
1247  fEventInspector = GetSubList(forward, "fmdEventInspector");
1248  fSharingFilter = GetSubList(forward, "fmdSharingFilter");
1249  fDensityCalculator = GetSubList(forward, "fmdDensityCalculator");
1250  fEnergyFitter = GetSubList(forward, "fmdEnergyFitter");
1251 
1252  if (!fSharingFilter) return false;
1253  if (!fEventInspector) return false;
1254  if (!fDensityCalculator) return false;
1255  // if (!fEnergyFitter) return false;
1256 
1257  return true;
1258  }
1268  static TObject* GetObject(const TList* list,
1269  const char* name,
1270  Bool_t verbose=true)
1271  {
1272  if (!list) return 0;
1273  TObject* o = list->FindObject(name);
1274  if (!o) {
1275  if (verbose)
1276  Error("GetObject", "Failed to find object %s in %s",
1277  name, list->GetName());
1278  return 0;
1279  }
1280  return o;
1281  }
1291  static TH1* GetHistogram(const TList* list, const char* name,
1292  Bool_t verbose=true)
1293  {
1294  return static_cast<TH1*>(GetObject(list, name, verbose));
1295  }
1306  static void
1307  DrawText(TLatex* l, Double_t x, Double_t& y, const char* c1, const char* c2,
1308  Double_t dx=.4)
1309  {
1310  y -= 1.2*l->GetTextSize();
1311  l->DrawLatex(x, y, c1);
1312  l->DrawLatex(x+dx, y, c2);
1313  }
1314 
1315 
1316  // --- Members -----------------------------------------------------
1317  Long_t fRunNo; // Run number (external)
1318  TFile* fCurrentFile; // Current input file
1319  TList* fSharingFilter; // Sharing filter list
1320  TList* fEventInspector; // Event inspector list
1321  TList* fDensityCalculator; // Density calculator list
1322  TList* fEnergyFitter; // Energy fitter list
1323  TList fFiles; // List of files to process
1324  Bool_t fKeep; // Keep PNGs
1325 };
1326 //
1327 // EOF
1328 //
1329 
1330 
1331 
FitStatus * fFitStatus
Definition: QARing.h:110
virtual void WriteLinks()
Definition: QABase.h:429
DataLoss * fDataLoss
Definition: QARing.h:112
QARing * fFMD2i
Definition: QABase.h:464
const char * filename
Definition: TestFCM.C:1
TList * fDensityCalculator
Definition: QATrender.C:1321
Double_t sigmaVz
Definition: QAStructs.h:139
static void DrawText(TLatex *l, Double_t x, Double_t &y, const char *c1, const char *c2, Double_t dx=.4)
Definition: QATrender.C:1307
Bool_t ProcessEnergyLoss(const TList *parent)
Definition: QATrender.C:146
double Double_t
Definition: External.C:58
UShort_t nFitted
Definition: QAStructs.h:180
Double_t one
Definition: QAStructs.h:242
const char * title
Definition: MakeQAPdf.C:27
static TH1 * GetHistogram(const TList *list, const char *name, Bool_t verbose=true)
Definition: QATrender.C:1291
Double_t a
Definition: QAStructs.h:368
void CleanStack(THStack *stack, const char *what)
Definition: QATrender.C:798
Bool_t ProcessDensityCalculator()
Definition: QATrender.C:1001
Double_t three
Definition: QAStructs.h:244
Bool_t ProcessGlobal()
Definition: QATrender.C:775
QATrender operator=(const QATrender &)
Definition: QATrender.C:645
static TObject * GetObject(const TList *list, const char *name, Bool_t verbose=true)
Definition: QATrender.C:1268
TSystem * gSystem
TList fFiles
Definition: QATrender.C:1323
QATrender(Bool_t keep, Bool_t, Int_t prodYear, char prodLetter)
Definition: QATrender.C:567
char Char_t
Definition: External.C:18
TList * fSharingFilter
Definition: QATrender.C:1319
TList * list
TDirectory file where lists per trigger are stored in train ouput.
Double_t beta
Definition: QAStructs.h:367
RingQuantity * fXi
Definition: QARing.h:108
Double_t eb
Definition: QAStructs.h:371
TCanvas * c
Definition: TestFitELoss.C:172
Double_t merge
Definition: QAStructs.h:304
Bool_t GetLists(Bool_t verbose=true)
Definition: QATrender.C:1220
void Close(bool deletePNGs=true)
Definition: QABase.h:391
QATrender(Bool_t keep, const TString &dataType, Int_t prodYear, const TString &period, const TString &pass, Long_t runNo)
Definition: QATrender.C:598
AliStack * stack
void PrintCanvas(const char *pngName, UInt_t)
Definition: QABase.h:314
Bool_t ProcessELossFitter()
Definition: QATrender.C:832
void CanvasTitle(const char *title)
Definition: QABase.h:261
TList * GetDetectorList(const TList *parent) const
Definition: QATrender.C:82
Bool_t GetInputLists(const char *filename)
Definition: QATrender.C:697
Bool_t Run()
Definition: QATrender.C:663
TString fPeriod
Definition: QABase.h:480
TList * fEnergyFitter
Definition: QATrender.C:1322
Double_t * sigma
QATrender(const QATrender &o)
Definition: QATrender.C:629
Bool_t ExtractYQuantity(const TList *parent, const char *name, Quantity *q)
Definition: QATrender.C:96
Long_t fRunNo
Definition: QATrender.C:1317
UInt_t runNo
Definition: QAStructs.h:136
const char * OutputName() const
Definition: QABase.h:123
Double_t density
Definition: QAStructs.h:305
static TList * GetSubList(const TList *parent, const char *name, Bool_t verbose=true)
Definition: QATrender.C:1202
int Int_t
Definition: External.C:63
TTree * fTree
Definition: QABase.h:469
Double_t max
Definition: QAStructs.h:30
Double_t alpha
Definition: QAStructs.h:366
Ring(UShort_t d, Char_t r)
Definition: QATrender.C:74
Char_t fR
Definition: QARing.h:104
Bool_t ProcessOne(const char *filename)
Definition: QATrender.C:723
virtual ~QATrender()
Definition: QATrender.C:623
Bool_t fKeep
Definition: QATrender.C:1324
Base class for QA active classes.
QARing * fFMD2o
Definition: QABase.h:465
Bool_t ProcessCorrelation(const TList *parent, TVirtualPad *p)
Definition: QATrender.C:443
std::ofstream * fHtml
Definition: QABase.h:473
UShort_t fD
Definition: QARing.h:103
UShort_t nCandidates
Definition: QAStructs.h:179
Int_t fYear
Definition: QABase.h:479
Double_t var
Definition: QAStructs.h:28
RingQuantity * fDelta
Definition: QARing.h:107
void MakeCanvasTitle(const char *what)
Definition: QATrender.C:1184
virtual void WriteLinks()
Definition: QATrender.C:1107
Double_t chi2
Definition: QAStructs.h:372
TList * fitter
Definition: DrawAnaELoss.C:26
TFile * fOutput
Definition: QABase.h:470
Double_t b
Definition: QAStructs.h:370
Ring * GetRing(Int_t padNo)
Definition: QATrender.C:1149
Double_t full
Definition: QAStructs.h:306
void CloseCurrent()
Definition: QATrender.C:1088
TList * fEventInspector
Definition: QATrender.C:1320
QARing * fFMD3i
Definition: QABase.h:466
Bool_t Process123(const TList *parent, TVirtualPad *p)
Definition: QATrender.C:227
Base class for QA rings.
QARing * fFMD1i
Definition: QABase.h:463
RingQuantity * fOccupancy
Definition: QARing.h:113
TString fPass
Definition: QABase.h:481
Definition: QABase.h:37
Bool_t ProcessELoss(TList *p1, TList *p2, TVirtualPad *p)
Definition: QATrender.C:298
Definition: External.C:220
RingQuantity * fChi2
Definition: QARing.h:105
Bool_t Init(bool read=false)
Definition: QABase.h:154
UShort_t nLow
Definition: QAStructs.h:178
Bool_t ProcessOccupancy(const TList *parent, TVirtualPad *p)
Definition: QATrender.C:385
RingQuantity * fSigma
Definition: QARing.h:109
UInt_t nAccepted
Definition: QAStructs.h:137
Double_t min
Definition: QAStructs.h:29
TFile * fCurrentFile
Definition: QATrender.C:1318
Double_t ea
Definition: QAStructs.h:369
Data structures used in QA trending tree.
Bool_t ProcessNeighbors(const TList *parent, TVirtualPad *p)
Definition: QATrender.C:188
Double_t mean
Definition: QAStructs.h:27
Double_t two
Definition: QAStructs.h:243
Merge * fMerge
Definition: QARing.h:111
unsigned short UShort_t
Definition: External.C:28
TCanvas * fCanvas
Definition: QABase.h:476
Global * fGlobal
Definition: QABase.h:468
void MakeCanvas(const char *title)
Definition: QABase.h:176
bool Bool_t
Definition: External.C:53
Definition: QARing.h:29
Bool_t ProcessSharingFilter()
Definition: QATrender.C:941
TVirtualPad * GetPad(Int_t padNo)
Definition: QATrender.C:1169
Definition: External.C:196
RingQuantity * fC
Definition: QARing.h:106
void AddFile(const char *filename)
Definition: QATrender.C:654
Correlation * fCorrelation
Definition: QARing.h:114
Double_t meanVz
Definition: QAStructs.h:138
void Finish()
Definition: QATrender.C:679
TString fDataType
Definition: QABase.h:478
QARing * fFMD3o
Definition: QABase.h:467