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