]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/corrs/DrawCorrCentralSecMap2.C
Fixed references from PWG2 -> PWGLF - very efficiently done using ETags.
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / corrs / DrawCorrCentralSecMap2.C
1 /**
2  * @file 
3  * 
4  * Scripts to draw energy loss fits from correction object file 
5  *
6  * @ingroup pwglf_forward_scripts_corr
7  */
8 /** 
9  * Clear canvas 
10  * 
11  * @param c Canvas to clear 
12  *
13  * @ingroup pwglf_forward_scripts_corr
14  */
15 void
16 ClearCanvas(TCanvas* c)
17 {
18   c->SetLeftMargin(.1);
19   c->SetRightMargin(.05);
20   c->SetBottomMargin(.1);
21   c->SetTopMargin(.05);
22   c->Clear();
23 }
24
25 void
26 LoadLibraries()
27 {
28   const char* test = gSystem->GetLibraries("PWGLFforward2","D",false);
29   if (test && test[0] != '\0') return;
30   gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
31 }
32
33 /** 
34  * Draw energy loss fits to a multi-page PDF. 
35  *
36  * @par Input: 
37  * The input file is expected to contain a AliFMDCorrELossFit object
38  * named @c elossfits in the top level directory.
39  * 
40  * @par Output: 
41  * A multi-page PDF.  Note, that the PDF generated by ROOT in this way
42  * is broken (cannot be read by Acrobat Reader on Windows and MacOSX)
43  * and one should pass it through a filter to correct these problems.
44  * 
45  * @param fname     File name 
46  * @param option    Drawing options 
47  * @param tracklets Tracklets flag
48  *
49  * @ingroup pwglf_forward_scripts_corr
50  */
51 void
52 DrawCorrCentralSecMap2(const char* fname, const char* option="colz", bool tracklets=true)
53 {
54   //__________________________________________________________________
55   // Load libraries and object 
56   LoadLibraries();
57
58   TFile* file = TFile::Open(fname, "READ");
59   if (!file) { 
60     Error("DrawCorrSecMap", "Failed to open %s", fname);
61     return;
62   }
63   TString pname(fname);
64   pname.ReplaceAll(".root", ".png");
65   pname = gSystem->BaseName(pname);
66
67   AliCentralMultiplicityTask::Manager* mgr = 
68     new AliCentralMultiplicityTask::Manager;
69   const char* objName = mgr->GetObjectName(0);
70   AliCentralCorrSecondaryMap* corr = 
71     static_cast<AliCentralCorrSecondaryMap*>(file->Get(objName));
72   if (!corr) { 
73     Error("DrawCorrCentralSecMap", "Object '%s' not found in %s", 
74           objName, fname);
75     file->ls();
76     return;
77   }
78
79   //__________________________________________________________________
80   // Create a canvas
81   Int_t w = 1200;
82   TCanvas* c = new TCanvas("c", "c", w, w / TMath::Sqrt(2));
83   c->SetFillColor(0);
84   c->SetBorderSize(0);
85   c->SetBorderMode(0);
86   // c->Print(Form("%s[", pname.Data()));
87   
88   gStyle->SetOptStat(0);
89   gStyle->SetTitleColor(0);
90   gStyle->SetTitleStyle(0);
91   gStyle->SetTitleBorderSize(0);
92   gStyle->SetTitleX(.1);
93   gStyle->SetTitleY(1);
94   gStyle->SetTitleW(.8);
95   gStyle->SetTitleH(.09);
96   gStyle->SetFrameFillColor(kWhite);
97   gStyle->SetFrameBorderSize(1);
98   gStyle->SetFrameBorderMode(1);
99   gStyle->SetPalette(1);
100
101   TString opt(option);
102   opt.ToLower();
103   Bool_t h2d = (opt.Contains("lego") || 
104                 opt.Contains("surf") || 
105                 opt.Contains("col"));
106   ClearCanvas(c);
107   //__________________________________________________________________
108   // Draw all corrections
109   const TAxis& vtxAxis = corr->GetVertexAxis();
110   Int_t        nVtx    = vtxAxis.GetNbins();
111   c->Divide((nVtx+2)/3, 3, 0, 0);
112   Int_t ipad = 0;
113   for (UShort_t v=1; v <= nVtx+1; v++) { 
114     ipad++;
115     if (ipad == 1) {
116       c->cd(ipad);
117       TLatex* l = new TLatex(.5, .5, 
118                              "#frac{#sum N_{ch,SPD0}}{#sum N_{ch,primary}}");
119       if (!tracklets) 
120         l->SetText(.5,.5,"#frac{dN_{ch}/d#eta}{#sum N_{ch,primary}}");
121       l->SetNDC();
122       l->SetTextAlign(22);
123       l->SetTextSize(.1);
124       l->Draw();
125       ipad++;
126     }
127     if (ipad == 12) {
128       if (!tracklets) 
129         continue;
130       c->cd(ipad);
131       TFile* f = TFile::Open("forward_mccorr.root", "READ");
132       if (!f) {
133         Warning("DrawCorrCentralSecMap2", "File forward_mccorr.root not found");
134         continue;
135       }
136       TList* l3 = static_cast<TList*>(f->Get("CentralSums"));
137       if (!l3) { 
138         Warning("DrawCorrCentralSecMap2", "No CentralSums list found");
139         f->Close();
140         continue;
141       }
142       TH1* xyz = static_cast<TH1*>(l3->FindObject("xyz"));
143       if (!xyz) {
144         Warning("DrawCorrCentralSecMap2", "no xyz histogram found");
145         f->Close();
146         continue;
147       }
148       xyz = static_cast<TH1*>(xyz->Clone());
149       xyz->SetDirectory(0);
150       xyz->Draw("ISO");
151       f->Close();
152       continue;
153     }
154     TVirtualPad* p = c->cd(ipad);
155     p->SetFillColor(kWhite);
156     p->SetGridx();
157     p->SetGridy();
158
159     TH2*   h1 = corr->GetCorrection(v);
160     if (h2d) { 
161       p->SetRightMargin(0.13);
162       h1->SetMaximum(1.9);
163       h1->Draw(option);
164       continue;
165     }
166
167     TH1D*  pr = h1->ProjectionX(Form("vtxbin%02d", v), -1, -1, "e");
168     TH1D*  nr = static_cast<TH1D*>(pr->Clone("norm"));
169     nr->SetDirectory(0);
170     pr->SetDirectory(0);
171     pr->SetTitle(Form("%+5.1f<v_{z}<%+5.1f", 
172                       vtxAxis.GetBinLowEdge(v),
173                       vtxAxis.GetBinUpEdge(v)));
174     pr->SetMarkerColor(kRed+1);
175     pr->SetFillColor(kRed+1);
176     pr->SetFillStyle(3001);
177     pr->SetMaximum(1.65);
178     pr->GetXaxis()->SetRangeUser(-3.1,3.1);
179     
180     Int_t nX = h1->GetNbinsX();
181     Int_t nY = h1->GetNbinsY();
182     nr->Reset();
183     for (Int_t i = 1; i <= nX; i++) { 
184       Int_t nonZero = 0;
185       for (Int_t j = 1; j <= nY; j++) 
186         if (h1->GetBinContent(i,j) > 0.001) nonZero++;
187       nr->SetBinContent(i, nonZero);
188     }
189     // pr->Scale(1. / nY);
190     pr->Divide(nr);
191     pr->Draw("hist"); 
192     pr->Draw("same");
193    
194   }
195   
196   //__________________________________________________________________
197   // Close output file 
198   c->SaveAs(pname.Data());
199   
200 }
201 //
202 // EOF
203 //