AliPhysics  b555aef (b555aef)
SummaryMCCorrDrawer.C
Go to the documentation of this file.
1 #include "SummaryDrawer.C"
2 
16 {
17 public:
18  enum EFlags {
19  kEventInspector = 0x001,
20  kTrackDensity = 0x002,
21  kVertexBins = 0x004,
22  kResults = 0x008,
23  kCentral = 0x010,
24  kNormal = 0x01F
25  };
27  : SummaryDrawer(),
28  fSums(0),
29  fResults(0)
30  {}
31  virtual ~SummaryMCCorrDrawer() {}
32 
33  //__________________________________________________________________
40  void Run(const char* fname, UShort_t what=kNormal)
41  {
42  // --- Open the file ---------------------------------------------
43  TString filename(fname);
44  TFile* file = TFile::Open(filename, "READ");
45  if (!file) {
46  Error("Run", "Failed to open \"%s\"", filename.Data());
47  return;
48  }
49 
50 
51  // --- Get top-level collection ----------------------------------
52  fSums = GetCollection(file, "ForwardCorrSums");
53  if (!fSums) return;
54 
55  // --- Make our canvas -------------------------------------------
56  TString pdfName(filename);
57  pdfName.ReplaceAll(".root", ".pdf");
58  CreateCanvas(pdfName, what & kLandscape);
59 
60  // --- Make a Title page -------------------------------------------
61  DrawTitlePage(file);
62 
63  // --- Possibly make a chapter here ------------------------------
64  if (what & kCentral && GetCollection(file, "CentralCorrSums"))
65  MakeChapter("Forward");
66 
67  // --- Set pause flag --------------------------------------------
68  fPause = what & kPause;
69 
70  // --- Do each sub-algorithm -------------------------------------
73  if (what & kVertexBins) DrawVertexBins(true);
74 
75  // --- Do the results ----------------------------------------------
76  fResults = GetCollection(file, "ForwardCorrResults");
77  if (!fResults) fResults = fSums; // Old-style
78 
79  if (what & kResults) DrawResults(true);
80 
81  // --- SPD clusters ----------------------------------------------
82  if (what & kCentral) {
83  // --- Get top-level collection --------------------------------
84  fSums = GetCollection(file, "CentralCorrSums");
85  if (fSums) {
86  MakeChapter("Central");
87  if (what & kEventInspector) DrawEventInspector(fSums);
88  if (what & kTrackDensity) DrawTrackDensity(fSums);
89  if (what & kVertexBins) DrawVertexBins(false);
90  }
91  else
92  Warning("", "No CentralCorrSums found");
93 
94  fResults = GetCollection(file, "CentralCorrResults");
95  if (!fResults) fResults = fSums; // Old-style
96  if (!fResults)
97  Warning("", "No CentralCorrResults found");
98 
99  if (what & kResults) DrawResults(false);
100  }
101 
102  CloseCanvas();
103  }
104 protected:
105  //____________________________________________________________________
106  void DrawTitlePage(TFile* file)
107  {
108  TCollection* c = GetCollection(file, "ForwardCorrSums");
109 
110  fBody->cd();
111 
112  Double_t y = .9;
113  TLatex* ltx = new TLatex(.5, y, "ESD+MC #rightarrow Corrections");
114  ltx->SetTextSize(0.07);
115  ltx->SetTextFont(62);
116  ltx->SetTextAlign(22);
117  ltx->SetNDC();
118  ltx->Draw();
119  y -= .075;
120 
121  TCollection* ei = GetCollection(c, "fmdEventInspector");
122  if (ei) {
123  UShort_t sys=0;
124  UShort_t sNN=0;
125  Int_t field=0;
126  ULong_t runNo=0;
127  GetParameter(ei, "sys", sys);
128  GetParameter(ei, "sNN", sNN);
129  GetParameter(ei, "field", field);
130  GetParameter(ei, "runNo", runNo);
131 
132  TString tS; SysString(sys, tS); DrawParameter(y, "System", tS);
133  TString tE; SNNString(sNN, tE); DrawParameter(y, "#sqrt{s_{NN}}", tE);
134  DrawParameter(y, "L3 B field", Form("%+2dkG", field));
135  DrawParameter(y, "Run #", Form("%6lu", runNo));
136  }
137 
138  PrintCanvas("MC Corrections");
139  }
140  //____________________________________________________________________
141  TCollection* GetVertexList(TCollection* parent, const TAxis& axis, Int_t bin)
142  {
143  TString folder = TString::Format("vtx%+05.1f_%+05.1f",
144  axis.GetBinLowEdge(bin),
145  axis.GetBinUpEdge(bin));
146  folder.ReplaceAll(".", "d");
147  folder.ReplaceAll("+", "p");
148  folder.ReplaceAll("-", "m");
149 
150  TCollection* c = GetCollection(parent, folder);
151  if (!c)
152  Warning("GetVertexList", "List %s not found", folder.Data());
153 
154  return c;
155  }
156  //____________________________________________________________________
157  void DrawVertexBins(Bool_t forward)
158  {
159  TH1* vtxHist = GetH1(fSums, "vtxAxis");
160  if (!vtxHist) return;
161 
162  Info("DrawVertexBins", "Drawing %s vertex bins - %d bins",
163  forward ? "Forward" : "Central", vtxHist->GetNbinsX());
164 
165  TAxis* vtxAxis = vtxHist->GetXaxis();
166  for (Int_t i = 1; i <= vtxAxis->GetNbins(); i++) {
167  Info("DrawVertexBins", " - Bin %d (%+5.1f - %+5.1f)", i,
168  vtxAxis->GetBinLowEdge(i), vtxAxis->GetBinUpEdge(i));
169  TCollection* c = GetVertexList(fSums, *vtxAxis, i);
170  if (!c) continue;
171 
172  if (forward) {
173  DivideForRings(true, true);
174  for (UShort_t d = 1; d <= 3; d++) {
175  for (UShort_t q = 0; q < (d == 1 ? 1 : 2); q++) {
176  Char_t r = q == 0 ? 'I' : 'O';
177  DrawInRingPad(d,r, GetH2(c, Form("FMD%d%c_cache",d,r)), "colz");
178  }
179  }
180  DrawInPad(fBody, (fLandscape ? 4: 2), GetH2(c, "primary"), "colz");
181  }
182  else {
183  fBody->Divide(1,3, 0, 0);
184 
185  DrawInPad(fBody, 1, GetH2(c, "hits"), "colz");
186  DrawInPad(fBody, 2, GetH2(c, "clusters"), "colz");
187  DrawInPad(fBody, 3, GetH2(c, "primary"), "colz");
188  }
189  PrintCanvas(Form("%s sums - IP_{z} bin %+5.1f - %+5.1f",
190  (forward ? "Forward" : "Central"),
191  vtxAxis->GetBinLowEdge(i),
192  vtxAxis->GetBinUpEdge(i)));
193  }
194  }
195  //____________________________________________________________________
196  void DrawResults(Bool_t forward)
197  {
198  Info("DrawResults", "Drawing resulting %s vertex bins",
199  forward ? "Forward" : "Central");
200  TH1* vtxHist = GetH1(fSums, "vtxAxis");
201  if (!vtxHist) return;
202 
203  TAxis* vtxAxis = vtxHist->GetXaxis();
204  for (Int_t i = 1; i <= vtxAxis->GetNbins(); i++) {
205  Info("DrawResults", " - Bin %d (%+5.1f - %+5.1f)", i,
206  vtxAxis->GetBinLowEdge(i), vtxAxis->GetBinUpEdge(i));
207  TCollection* c = GetVertexList(fResults, *vtxAxis, i);
208  if (!c) continue;
209 
210  if (forward) {
211  THStack* all = new THStack("all",
212  "2^{nd} correction averaged over #phi");
213  DivideForRings(true, true);
214  for (UShort_t d = 1; d <= 3; d++) {
215  for (UShort_t q = 0; q < (d == 1 ? 1 : 2); q++) {
216  Char_t r = q == 0 ? 'I' : 'O';
217  // TVirtualPad* p = RingPad(d, r);
218  // p->cd();
219  // p->Divide(1,2,0,0);
220  TH2* h = GetH2(c, Form("FMD%d%c_vtxbin%03d",d,r,i));
221  DrawInRingPad(d,r, h,"colz");
222  // TVirtualPad* pp = p->cd(1);
223  // TVirtualPad* ppp = p->cd(2);
224  // ppp->SetRightMargin(pp->GetRightMargin());
225  TH1* hh = h->ProjectionX();
226  hh->Scale(1./ h->GetNbinsY());
227  hh->SetFillColor(RingColor(d,r));
228  hh->SetLineColor(RingColor(d,r));
229  hh->SetMarkerColor(RingColor(d,r));
230  hh->SetFillStyle(3001);
231  hh->SetTitle(Form("#LT%s#GT", hh->GetTitle()));
232  // DrawInPad(p,2, hh, "hist e");
233  all->Add(hh, "hist e");
234  }
235  TVirtualPad* p = RingPad(0, '0');
236  p->SetBottomMargin(0.10);
237  p->SetLeftMargin(0.10);
238  p->SetRightMargin(0.05);
239  DrawInRingPad(0, 'O', all, "nostack");
240  }
241  }
242  else {
243  fBody->Divide(2,4,0,0);
244  TH2* secMap = GetH2(c, "secMap");
245  TH2* secMapAlt = GetH2(c, "secMapEff");
246  if (!secMapAlt) secMapAlt = GetH2(c, "secMapHit");
247  TH1* acc = GetH1(c, "acc");
248  TH1* accAlt = GetH1(c, "accEff");
249  if (!accAlt) accAlt = GetH1(c, "accHit");
250 
251  TH1* secMapProj = secMap->ProjectionX();
252  secMapProj->Scale(1./ secMap->GetNbinsY());
253  secMapProj->Divide(acc);
254  secMapProj->SetFillColor(kRed+1);
255  secMapProj->SetFillStyle(3001);
256  secMapProj->SetTitle(Form("#LT%s#GT/Acceptance", secMap->GetTitle()));
257 
258  TH1* secMapAltProj = secMapAlt->ProjectionX();
259  secMapAltProj->Scale(1./ secMapAlt->GetNbinsY());
260  secMapAltProj->Divide(accAlt);
261  secMapAltProj->SetFillColor(kBlue+1);
262  secMapAltProj->SetFillStyle(3001);
263  secMapAltProj->SetTitle(Form("#LT%s#GT/Acceptance",
264  secMapAlt->GetTitle()));
265 
266  Double_t secMapMax = TMath::Max(secMap->GetMaximum(),
267  secMapAlt->GetMaximum());
268  secMap->SetMaximum(secMapMax);
269  secMapAlt->SetMaximum(secMapMax);
270 
271  Double_t secMapProjMax = TMath::Max(secMapProj->GetMaximum(),
272  secMapAltProj->GetMaximum());
273  secMapProj->SetMaximum(secMapProjMax);
274  secMapAltProj->SetMaximum(secMapProjMax);
275 
276  acc->SetFillColor(kRed+1);
277  acc->SetFillStyle(3001);
278  accAlt->SetFillColor(kBlue+1);
279  accAlt->SetFillStyle(3001);
280 
281  Double_t accMax = TMath::Max(acc->GetMaximum(),accAlt->GetMaximum());
282  acc->SetMaximum(accMax);
283  accAlt->SetMaximum(accMax);
284 
285  if (secMap->GetMean(1) > 0 && secMap->GetMean(2) > 0)
286  DrawInPad(fBody, 1, secMap, "colz", kGridx);
287  if (secMapAlt->GetMean(1) > 0 && secMapAlt->GetMean(2) > 0)
288  DrawInPad(fBody, 2, secMapAlt, "colz", kGridx);
289 
290  TVirtualPad* p = fBody;
291  TVirtualPad* pp = p->cd(1);
292  TVirtualPad* ppp = p->cd(3);
293  ppp->SetRightMargin(pp->GetRightMargin());
294  DrawInPad(p,3, secMapProj, "hist", kGridx|kGridy);
295 
296  ppp = p->cd(5);
297  ppp->SetRightMargin(pp->GetRightMargin());
298  DrawInPad(fBody, 5, acc, "", kGridx|kGridy);
299 
300  pp = p->cd(2);
301  pp->SetLeftMargin(0.10);
302  ppp = p->cd(4);
303  ppp->SetRightMargin(pp->GetRightMargin());
304  ppp->SetLeftMargin(0.10);
305  DrawInPad(p,4, secMapAltProj, "hist", kGridx|kGridy);
306 
307  pp = p->cd(4);
308  pp->SetLeftMargin(0.10);
309  ppp = p->cd(6);
310  ppp->SetRightMargin(pp->GetRightMargin());
311  ppp->SetLeftMargin(0.10);
312  DrawInPad(fBody, 6, accAlt, "", kGridx|kGridy);
313 
314  TH2* diag = GetH2(c, "diagnostics");
315  if (diag->GetMean(1) > 0 && diag->GetMean(2) > 0)
316  DrawInPad(fBody, 7, diag, "colz");
317 
318  if (secMap->GetMean(1) > 0 && secMap->GetMean(2) > 0 &&
319  secMapAlt->GetMean(1) > 0 && secMapAlt->GetMean(2) > 0) {
320  TH2* ratio = static_cast<TH2*>(secMap->Clone("ratio"));
321  ratio->Add(secMapAlt, -1);
322  ratio->Divide(secMapAlt);
323  ratio->SetTitle("Relative difference between maps");
324  ratio->SetZTitle("#frac{S - S_{alt}}{S_{alt}}");
325 
326  pp = p->cd(8);
327  pp->SetLeftMargin(0.10);
328  DrawInPad(fBody, 8, ratio, "colz");
329  }
330  }
331  PrintCanvas(Form("%s results - IP_{z} bin %+5.1f - %+5.1f",
332  (forward ? "Forward" : "Central"),
333  vtxAxis->GetBinLowEdge(i),
334  vtxAxis->GetBinUpEdge(i)));
335  }
336  }
339 };
340 
341 // #endif
const char * filename
Definition: TestFCM.C:1
double Double_t
Definition: External.C:58
Base class for classes to draw summaries.
void DrawResults(Bool_t forward)
static TH1 * GetH1(const TObject *parent, const TString &name, Bool_t verb=true)
static TH2 * GetH2(const TObject *parent, const TString &name, Bool_t verb=true)
void DrawInRingPad(UShort_t d, Char_t r, TObject *h, Option_t *opts="", UShort_t flags=0x0, const char *title="")
void DrawTrackDensity(TCollection *parent, const char *folderName="mcTrackDensity")
char Char_t
Definition: External.C:18
TCanvas * c
Definition: TestFitELoss.C:172
void MakeChapter(const TString &title)
static void SysString(UShort_t sys, TString &str)
int Int_t
Definition: External.C:63
void DrawVertexBins(Bool_t forward)
void DrawTitlePage(TFile *file)
static Bool_t GetParameter(const TObject *c, const TString &name, Short_t &value, Bool_t verb=true)
TCollection * GetVertexList(TCollection *parent, const TAxis &axis, Int_t bin)
void Run(const char *fname, UShort_t what=kNormal)
unsigned long ULong_t
Definition: External.C:38
const char * pdfName
Definition: DrawAnaELoss.C:30
void CreateCanvas(const TString &pname, Bool_t landscape=false, Bool_t pdf=true, Bool_t useTop=true)
void DrawParameter(Double_t &y, const TString &name, const TString &value, Double_t size=0)
void PrintCanvas(const TString &title, Float_t size=.7)
static void SNNString(UShort_t sNN, TString &str)
void CloseCanvas()
virtual void DrawEventInspector(TCollection *parent)
void DivideForRings(Bool_t commonX, Bool_t commonY)
Definition: External.C:220
TFile * file
TList with histograms for a given trigger.
unsigned short UShort_t
Definition: External.C:28
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
TVirtualPad * RingPad(UShort_t d, Char_t r) const
static TCollection * GetCollection(const TObject *parent, const TString &name, Bool_t verb=true)
Definition: External.C:196
static Color_t RingColor(UShort_t d, Char_t r)