AliPhysics  5eaf189 (5eaf189)
MultCutDrawer.C
Go to the documentation of this file.
1 #ifndef __CINT__
2 # include "SummaryDrawer.C"
3 # include "AliFMDCorrAcceptance.h"
4 # include "AliFMDCorrSecondaryMap.h"
5 # include "AliFMDCorrELossFit.h"
6 # include "AliFMDMultCuts.h"
7 # include "AliForwardUtil.h"
9 # include "AliLog.h"
10 # include <TGraphErrors.h>
11 # include <TMultiGraph.h>
12 # include <TString.h>
13 # include <TError.h>
14 #else
15 class SummaryDrawer;
16 class TObject;
17 class AliFMDMultCuts;
18 class THStack;
19 class TH1;
20 class TMultiGraph;
21 class TGraphErrors;
22 #include <TString.h>
23 #endif
24 
26 {
32  //__________________________________________________________________
37  : fMinQuality(AliFMDCorrELossFit::kDefaultQuality),
38  fCuts(),
39  fStacks(),
40  fMultiGraphs(),
41  fMC(false)
42  {
43  // Rough equvilance:
44  //
45  // Cut name | Parameter values
46  // -----------+----------------------------------------
47  // mpv | 0.85 0.7 0.4 0.15
48  // xi | 1 2.5 4.5 6.8
49  // sig | .5 1 2 2.9
50  // prob | 1e-1 2.5e-2 5e-4 2.5e-6
51  // -----------+----------------------------------------
52  // Cut name | Mean values
53  // -----------+----------------------------------------
54  // mpv | 0.43 0.36 0.20 0.08
55  // xi | 0.49 0.36 0.23 0.09
56  // sig | 0.44 0.37 0.22 0.10
57  // prob | 0.43 0.35 0.21 0.09
58  //
59  fCuts.Add(new TNamed("mpv", "0.85 0.7 0.4 0.15"));
60  fCuts.Add(new TNamed("xi", "1 2.5 4.5 6.8"));
61  fCuts.Add(new TNamed("sig", ".8 .9 1 1.5"));
62  fCuts.Add(new TNamed("prob", "0.01 0.025 0.04 0.06"));
63  // fCuts.Add(new TNamed("prob", "1e-2 1e-3 1e-5 1e-7"));
64  }
65  //__________________________________________________________________
72  : fMinQuality(o.fMinQuality),
73  fCuts(),
74  fStacks(),
75  fMultiGraphs(),
76  fMC(false)
77  {}
78  //__________________________________________________________________
87  {
88  if (&o == this) return *this;
89  fMinQuality = o.fMinQuality;
90  fCuts.AddAll(&o.fCuts);
91  fStacks.AddAll(&o.fStacks);
92  return *this;
93  }
94  //__________________________________________________________________
99  {
100  CloseCanvas();
101  }
102  //__________________________________________________________________
113  void Run(ULong_t runNo=999,
114  UShort_t sys=0,
115  UShort_t sNN=0,
116  Short_t field=999,
117  Bool_t mc=false,
118  const Char_t* local=0)
119  {
120  Bool_t sat = false;
121  if (!Init(runNo, sys, sNN, field, mc, sat, local)) return;
122 
123  Double_t savX = fParVal->GetX();
124  Double_t savY = fParVal->GetY();
125  fParVal->SetX(.4);
126  fParVal->SetY(.4);
127  // fPause = true;
128 
129  TIter iCut(&fCuts);
130  TObject* pCut = 0;
131  while ((pCut = iCut())) {
132  TString method(pCut->GetName());
133  TString sP(pCut->GetTitle());
134  TObjArray* aP = sP.Tokenize(" ");
135  TIter iP(aP);
136  TObjString* pP = 0;
137  TString tM;
138  TMultiGraph* sum = AllSummary(method, sP);
139  fBody->SetBottomMargin(0.20);
140  fBody->SetLeftMargin(0.06);
141  fBody->Divide(1, aP->GetEntries(), 0, 0);
142  Int_t iPad = 1;
143  while ((pP = static_cast<TObjString*>(iP()))) {
144  THStack* all = AllStack(iPad-1);
145  Double_t p = pP->String().Atof();
146  Double_t vP[] = { p, p, p, p, p };
147  THStack* stack = CutStack(method, vP, all, sum);
148  if (tM.IsNull()) tM = stack->GetTitle();
149  // Kill title on all but first sub-panel
150  stack->SetTitle("");
151  DrawInPad(fBody, iPad, stack, "nostack p");
152  stack->GetYaxis()->SetTitleSize(0.12);
153  stack->GetYaxis()->SetTitleOffset(0.2);
154  stack->GetYaxis()->SetLabelSize(0.07);
155  if (iPad == 1) stack->GetYaxis()->SetTitle(tM);
156  stack->GetXaxis()->SetTitle("#eta");
157  stack->GetXaxis()->SetTitleSize(0.12);
158  stack->GetXaxis()->SetTitleOffset(0.6);
159  stack->GetXaxis()->SetTitleColor(kBlack);
160  stack->GetXaxis()->SetLabelSize(0.07);
161 
162  if (iPad == 1) {
163  Color_t col = kBlack;
164  Double_t hLtx = 0.07;
165  Double_t yLtx = 7*(hLtx+.005)+0.01;
166  TLatex* nLtx = new TLatex(-0.75, yLtx, "Ring");
167  TLatex* pLtx = new TLatex(-0.7, yLtx, "Param");
168  TLatex* vLtx = new TLatex(+0, yLtx, "Mean#pmVar_{min}^{max}");
169  nLtx->SetTextAlign(31);pLtx->SetTextAlign(11);
170  nLtx->SetTextSize(hLtx);
171  pLtx->SetTextSize(hLtx);
172  vLtx->SetTextSize(hLtx);
173  nLtx->SetTextColor(col);
174  pLtx->SetTextColor(col);
175  vLtx->SetTextColor(col);
176  nLtx->Draw();
177  pLtx->Draw();
178  vLtx->Draw();
179  }
180  // if (iPad == 1) {
181  // fBody->cd(1);
182  // DrawRingLegend(0.4, 0.4, 0.7, 0.9);
183  // }
184  iPad++;
185  }
186  PrintCanvas(Form("%s X={%s}", tM.Data(), sP.Data()));
187  }
188 
189  Int_t nAll = fStacks.GetEntries();
190  fBody->SetBottomMargin(0.20);
191  fBody->SetLeftMargin(0.06);
192  fBody->Divide(1, nAll, 0, 0);
193  for (Int_t iAll = 0; iAll < nAll; iAll++) {
194  THStack* all = AllStack(iAll);
195  DrawInPad(fBody, iAll+1, all, "nostack hist p");
196  all->GetYaxis()->SetTitleSize(0.12);
197  all->GetYaxis()->SetTitleOffset(0.2);
198  all->GetYaxis()->SetLabelSize(0.07);
199  if (iAll == 0) all->GetYaxis()->SetTitle("c");
200  all->GetXaxis()->SetTitle("#eta");
201  all->GetXaxis()->SetTitleSize(0.12);
202  all->GetXaxis()->SetTitleOffset(0.6);
203  all->GetXaxis()->SetTitleColor(kBlack);
204  all->GetXaxis()->SetLabelSize(0.07);
205 
206  TVirtualPad* p = fBody->GetPad(iAll+1);
207  p->cd();
208  Double_t yT = 1-p->GetTopMargin();
209  if (iAll == 0) DrawRingLegend(p, kNorth|kCenter);
210  else if (iAll == 1) DrawMethodLegend(0.35, 0.4, 0.55,yT);
211 
212  Double_t y1 = ((iAll + 2 >= nAll) ? yT - .3 : p->GetBottomMargin());
213  Double_t y2 = ((iAll + 2 >= nAll) ? yT : 0.3);
214  DrawValueLegend(all, 0.2, y1, 0.9, y2);
215 
216  }
217  PrintCanvas("Comparisons");
218 
219  fParVal->SetX(savX);
220  fParVal->SetY(savY);
221 
222  Int_t nSum = fMultiGraphs.GetEntries();
223  fBody->Divide(1,nSum);
224  for (Int_t i = 1; i <= nSum; i++) {
225  DrawInPad(fBody, i, fMultiGraphs.At(i-1), "apl");
226  }
227  PrintCanvas("Trends");
228 
229 
230  TFile* out = TFile::Open("cutMethods.root", "RECREATE");
231  fStacks.Write("stacks", TObject::kSingleKey);
232  fMultiGraphs.Write("trends", TObject::kSingleKey);
233  TIter nextMG(&fMultiGraphs);
234  TMultiGraph* mg = 0;
235  while ((mg = static_cast<TMultiGraph*>(nextMG()))) {
236  TDirectory* dir = out->mkdir(mg->GetName());
237  dir->cd();
238  mg->GetListOfGraphs()->Write();
239  out->cd();
240  }
241  out->Write();
242  // out->Close();
243 
244  CloseCanvas();
245  }
246  //__________________________________________________________________
256  Double_t x2, Double_t y2)
257  {
258  TLegend* l = new TLegend(x1,y1,x2,y2);
259  l->SetBorderSize(0);
260  l->SetFillColor(0);
261  l->SetFillStyle(0);
262 
263  TIter iCut(&fCuts);
264  TObject* pCut = 0;
265  while ((pCut = iCut())) {
266  TString method(pCut->GetName());
269  Style_t style = CutStyle(m);
270  TLegendEntry* e = l->AddEntry("dummy", title, "p");
271  e->SetMarkerStyle(style);
272  e->SetMarkerColor(kBlack);
273  }
274  l->Draw();
275  }
276  //__________________________________________________________________
286  void DrawValueLegend(THStack* stack,
287  Double_t x1, Double_t y1,
288  Double_t x2, Double_t y2)
289  {
290  TLegend* l = new TLegend(x1,y1,x2,y2);
291  l->SetBorderSize(0);
292  l->SetFillColor(0);
293  l->SetFillStyle(0);
294 
295  TString seen;
296  TIter iHist(stack->GetHists());
297  TH1* pHist = 0;
298  Int_t nHist = 0;
299  while ((pHist = static_cast<TH1*>(iHist()))) {
300  TString name(pHist->GetName());
301  if (seen.Contains(name)) continue;
302  seen.Append(Form(" %s", name.Data()));
303  nHist++;
304 
306  Style_t s = CutStyle(m);
307  TLegendEntry* e = l->AddEntry("dummy", pHist->GetTitle(), "p");
308  e->SetMarkerStyle(s);
309  e->SetMarkerColor(kBlack);
310  }
311  if (nHist < 5) l->SetNColumns(nHist);
312  else l->SetNColumns(nHist/2);
313 
314  l->Draw();
315  }
316  //__________________________________________________________________
324  THStack* AllStack(Int_t i)
325  {
326  TObject* o = fStacks.At(i);
327  if (o) return static_cast<THStack*>(o);
328  THStack* s = new THStack(Form("all%02d", i), "");
329  fStacks.AddAt(s, i);
330  return s;
331  }
332  //__________________________________________________________________
341  TMultiGraph* AllSummary(const TString& method, const TString& title)
342  {
343  TObject* o = fMultiGraphs.FindObject(method);
344  if (o) return static_cast<TMultiGraph*>(o);
345  TMultiGraph* mg = new TMultiGraph(method, title);
346  fMultiGraphs.Add(mg);
347  return mg;
348  }
360  TGraphErrors* FindSummary(TMultiGraph* summaries,
361  const TString& n,
362  const TString& method,
363  Color_t col,
364  Style_t style)
365  {
366 
367  TObject* o = (summaries->GetListOfGraphs() ?
368  summaries->GetListOfGraphs()->FindObject(n) : 0);
369  if (o) return static_cast<TGraphErrors*>(o);
370  TGraphErrors* summary = new TGraphErrors;
371  summary->SetName(n);
372  summary->SetTitle(method);
373  summary->SetLineColor(col);
374  summary->SetMarkerColor(col);
375  summary->SetFillColor(col);
376  summary->SetMarkerStyle(style);
377  summary->SetFillStyle(0);
378  summaries->Add(summary);
379 
380  return summary;
381  }
382 
383  //__________________________________________________________________
391  static Style_t CutStyle(UShort_t m)
392  {
393  switch (m) {
394  case AliFMDMultCuts::kFixed: return kFullStar;
395  case AliFMDMultCuts::kMPVFraction: return kOpenCircle;
396  case AliFMDMultCuts::kFitRange: return 33; // Diamond
397  case AliFMDMultCuts::kLandauWidth: return 34; // Cross
398  case AliFMDMultCuts::kLandauSigmaWidth: return kOpenSquare;
399  case AliFMDMultCuts::kProbability: return kFullTriangleDown;
400  }
401  return kFullDotMedium;
402  }
403  //__________________________________________________________________
412  static void Statistics(Double_t y,
413  Int_t& cnt,
414  Double_t& mean,
415  Double_t& var)
416  {
417  cnt += 1;
418  mean += (y - mean) / cnt;
419  var += (cnt > 1 ? (TMath::Power(y-mean,2)/(cnt-1)-var/cnt) : 0);
420  }
421  //__________________________________________________________________
434  static void HistStatistics(const TH1* h,
435  Double_t& mean,
436  Double_t& var,
437  Double_t& min,
438  Double_t& max,
439  Int_t& rCnt,
440  Double_t& rMean,
441  Double_t& rVar)
442  {
443  mean = 0;
444  var = 0;
445  min = +100000;
446  max = -100000;
447  Int_t cnt = 0;
448  for (Int_t i = 1; i <= h->GetNbinsX(); i++) {
449  Double_t y = h->GetBinContent(i);
450  if (TMath::Abs(y) <= 1e-9) continue;
451  min = TMath::Min(min, y);
452  max = TMath::Max(max, y);
453  Statistics(y, cnt, mean, var);
454  Statistics(y, rCnt, rMean, rVar);
455  }
456  // Info("", "Stats for %s: mean=%f +/- %f [%f,%f]",
457  // h->GetTitle(), mean, var, min, max);
458  }
459  //__________________________________________________________________
470  THStack* CutStack(const TString& method, Double_t* param,
471  THStack* all, TMultiGraph* summaries)
472  {
474  Info("CutStack", "Method %s -> %d", method.Data(), m);
475  AliFMDMultCuts* cut = new AliFMDMultCuts(m,
476  param[0],
477  param[1],
478  param[2],
479  param[3],
480  param[4]);
481  // cut->Print();
482 
483  TH2* hist = new TH2D("cut", cut->GetMethodString(true),
484  200, -4, 6, 5, 0.5, 5.5);
485  hist->GetYaxis()->SetBinLabel(1, "FMD1i");
486  hist->GetYaxis()->SetBinLabel(2, "FMD2i");
487  hist->GetYaxis()->SetBinLabel(3, "FMD2o");
488  hist->GetYaxis()->SetBinLabel(4, "FMD3o");
489  hist->GetYaxis()->SetBinLabel(5, "FMD3i");
490 
491  // Info("DrawMultCuts", "Filling histogram");
492  cut->FillHistogram(hist);
493  // Info("DrawMultCuts", "Done filling");
494 
495  Style_t style = CutStyle(m);
496  THStack* stack = new THStack(hist, "x");
497  TList* hists = stack->GetHists();
498  Double_t rMin = +1000000;
499  Double_t rMax = -1000000;
500  Double_t rAvg = 0;
501  Double_t rVar = 0;
502  Int_t rCnt = 0;
503  printf(" %6s %7.4f | ", method.Data(), param[0]);
504  TH1* first = 0;
505  for (Int_t i = 1; i <= 5; i++) {
506  TH1* h = static_cast<TH1*>(hists->At(i-1));
507  TString n(hist->GetYaxis()->GetBinLabel(i));
508  TString nn(n); nn.Remove(0,3);
509  UShort_t det = nn.Atoi();
510  Char_t rng = nn[1];
511  Color_t col = AliForwardUtil::RingColor(det, rng);
512  if (!first) first = h;
513  h->SetName(method);
514  h->SetTitle(Form("%f", param[i-1]));
515  h->SetYTitle(cut->GetMethodString(true));
516  h->SetXTitle("#eta");
517  h->SetMarkerColor(col);
518  h->SetFillColor(col);
519  h->SetLineColor(col);
520  h->SetMarkerStyle(style);
521  h->SetFillStyle(0);
522  Double_t avg, var, min, max;
523 
524  HistStatistics(h, avg, var, min, max, rCnt, rAvg, rVar);
525  rMin = TMath::Min(min, rMin);
526  rMax = TMath::Max(max, rMax);
527  all->Add(h);
528  Double_t hLtx = 0.07;
529  Double_t yLtx = i*(hLtx+.005)+0.01;
530  TObjArray* lines = new TObjArray(3);
531  TLatex* nLtx = new TLatex(-0.75, yLtx, n);
532  TLatex* pLtx = new TLatex(-0.7, yLtx, Form("X=%g", param[i-1]));
533  TLatex* vLtx = new TLatex(+0, yLtx,
534  Form("%5.3f#pm%6.4f_{%6.4f}^{%6.4f}",
535  avg, var, max-avg, avg-min));
536  nLtx->SetTextAlign(31);pLtx->SetTextAlign(11);
537  nLtx->SetTextSize(hLtx);pLtx->SetTextSize(hLtx),vLtx->SetTextSize(hLtx);
538  nLtx->SetTextColor(col);pLtx->SetTextColor(col);vLtx->SetTextColor(col);
539  lines->Add(nLtx);lines->Add(pLtx);lines->Add(vLtx);
540  h->GetListOfFunctions()->Add(lines);
541  printf("%5.3f+/-%6.4f ", avg, var);
542 
543  TGraphErrors* summary = FindSummary(summaries, n, method, col, style);
544  Int_t nSum = summary->GetN();
545  summary->SetPoint(nSum, param[i-1], avg);
546  summary->SetPointError(nSum, 0, var);
547  }
548  TLatex* rLtx = new TLatex(6, fMC ? 0.65 : 0.55,
549  Form("All: %5.3f#pm%6.4f_{%6.4f}^{%6.4f}",
550  rAvg, rVar, rMin, rMax));
551  rLtx->SetTextSize(0.05);
552  rLtx->SetTextAlign(31);
553  first->GetListOfFunctions()->Add(rLtx);
554  Printf("-> %5.3f+/-%6.4f", rAvg, rVar);
555  stack->SetTitle(cut->GetMethodString(true)); // hist->GetTitle());
556  stack->SetMinimum(0); // 0.98*min);
557  stack->SetMaximum(fMC ? 0.7 : 0.6); // 1.02*max);
558  all->SetMinimum(0);
559  all->SetMaximum(fMC ? 0.7 : 0.6);
560 
561  summaries->SetTitle(cut->GetMethodString(true));
562  TGraphErrors* summary = FindSummary(summaries, "all", method,kBlack,style);
563  Int_t nSum = summary->GetN();
564  summary->SetPoint(nSum, param[0], rAvg);
565  summary->SetPointError(nSum, 0, rVar);
566 
567  delete hist;
568  return stack;
569  }
570  //__________________________________________________________________
584  Bool_t Init(ULong_t runNo=999,
585  UShort_t sys=0,
586  UShort_t sNN=0,
587  Short_t field=999,
588  Bool_t mc=false,
589  Bool_t sat=false,
590  const Char_t* local=0)
591  {
592  fMC = mc;
594  mgr.SetDebug(true);
596 
597  if (local && local[0] != '\0') mgr.SetELossFitsPath(local);
598 
599  if (!mgr.Init(runNo, sys, sNN, field, mc, false, flags, true)) {
600  Error("DrawMultCuts", "Failed to initialize for flags=0x%02x, "
601  "run=%lu, sys=%hu, sNN=%hu, field=%hd, mc=%s, sat=%s",
602  flags, runNo, sys, sNN, field, mc ? "true" : "false", "false");
603  return false;
604  }
605  const AliFMDCorrELossFit* cFit = mgr.GetELossFit();
606  AliFMDCorrELossFit* fit = const_cast<AliFMDCorrELossFit*>(cFit);
607  fit->CacheBins(8);
608 
609  CreateCanvas("multCuts.pdf", true);
610 
611  fBody->cd();
612 
613  Double_t y = .85;
614  TLatex* title = new TLatex(.5, y, "#Delta Cuts");
615  title->SetTextAlign(23);
616  title->SetTextFont(42);
617  title->SetTextSize(0.1);
618  title->Draw();
619 
620  y -= 0.11;
621  DrawParameter(y, "Run #", Form("%lu", runNo));
623  DrawParameter(y, "#sqrt{s_{NN}}",
625  DrawParameter(y, "L3 field", AliForwardUtil::MagneticFieldString(field));
626  DrawParameter(y, "Simulation", Form("%s", mc ? "yes" : "no"));
627  DrawParameter(y, "Satellite", Form("%s", sat ? "yes" : "no"));
628  PrintCanvas("Delta cuts");
629 
630  return true;
631  }
632 };
static EMethod String2Method(const char *str)
double Double_t
Definition: External.C:58
Base class for classes to draw summaries.
static const char * CenterOfMassEnergyString(UShort_t cms)
const char * title
Definition: MakeQAPdf.C:27
TMultiGraph * AllSummary(const TString &method, const TString &title)
void DrawMethodLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Bool_t Init(ULong_t runNo=999, UShort_t sys=0, UShort_t sNN=0, Short_t field=999, Bool_t mc=false, Bool_t sat=false, const Char_t *local=0)
char Char_t
Definition: External.C:18
MultCutDrawer & operator=(const MultCutDrawer &o)
Definition: MultCutDrawer.C:86
TLegend * DrawRingLegend(TVirtualPad *p, UInt_t flags)
THStack * CutStack(const TString &method, Double_t *param, THStack *all, TMultiGraph *summaries)
TList fMultiGraphs
Definition: MultCutDrawer.C:30
void Run(ULong_t runNo=999, UShort_t sys=0, UShort_t sNN=0, Short_t field=999, Bool_t mc=false, const Char_t *local=0)
void CacheBins(UShort_t minQuality=kDefaultQuality) const
AliStack * stack
Bool_t Init(ULong_t runNumber, UShort_t collisionSystem, UShort_t cmsNN, Short_t field, Bool_t mc=false, Bool_t satelliteCollisions=false, UInt_t what=kDefault, Bool_t force=false)
static const char * Method2String(EMethod method, Bool_t latex)
static const char * MagneticFieldString(Short_t field)
int Int_t
Definition: External.C:63
static Color_t RingColor(UShort_t d, Char_t r)
Various utilities used in PWGLF/FORWARD.
Int_t method
void DrawValueLegend(THStack *stack, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: External.C:228
unsigned long ULong_t
Definition: External.C:38
static Style_t CutStyle(UShort_t m)
virtual void SetDebug(Bool_t debug)
TGraphErrors * FindSummary(TMultiGraph *summaries, const TString &n, const TString &method, Color_t col, Style_t style)
const AliFMDCorrELossFit * GetELossFit() const
void CreateCanvas(const TString &pname, Bool_t landscape=false, Bool_t pdf=true, Bool_t useTop=true)
static void Statistics(Double_t y, Int_t &cnt, Double_t &mean, Double_t &var)
void DrawParameter(Double_t &y, const TString &name, const TString &value, Double_t size=0)
short Short_t
Definition: External.C:23
void PrintCanvas(const TString &title, Float_t size=.7)
static void HistStatistics(const TH1 *h, Double_t &mean, Double_t &var, Double_t &min, Double_t &max, Int_t &rCnt, Double_t &rMean, Double_t &rVar)
void CloseCanvas()
UShort_t fMinQuality
Definition: MultCutDrawer.C:27
TLatex * fParVal
Definition: External.C:220
MultCutDrawer(const MultCutDrawer &o)
Definition: MultCutDrawer.C:71
unsigned short UShort_t
Definition: External.C:28
static const char * CollisionSystemString(UShort_t sys)
TObject * DrawInPad(TVirtualPad *c, Int_t padNo, TObject *h, Option_t *opts="", UInt_t flags=0x0, const char *title="")
bool Bool_t
Definition: External.C:53
THStack * AllStack(Int_t i)
Definition: External.C:196
static AliForwardCorrectionManager & Instance()
TDirectoryFile * dir