update to AOD analysis
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TestAOD / AliSpectraAODHistoManager.cxx
1
2 /**************************************************************************
3  * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 //-----------------------------------------------------------------
18 //         AliSpectraAODHistoManager class
19 //-----------------------------------------------------------------
20
21 #include "TChain.h"
22 #include "TTree.h"
23 #include "TLegend.h"
24 #include "TH1.h"
25 #include "TH1F.h"
26 #include "TH2F.h"
27 #include "TCanvas.h"
28 #include "AliAnalysisTask.h"
29 #include "AliAnalysisManager.h"
30 #include "AliAODTrack.h"
31 #include "AliAODMCParticle.h"
32 #include "AliAODEvent.h"
33 #include "AliAODInputHandler.h"
34 #include "AliAnalysisTaskESDfilter.h"
35 #include "AliAnalysisDataContainer.h"
36 #include "AliSpectraAODHistoManager.h"
37 #include <iostream>
38
39 using namespace std;
40
41 ClassImp(AliSpectraAODHistoManager)
42
43
44 using namespace AliSpectraNameSpace;
45
46 AliSpectraAODHistoManager::AliSpectraAODHistoManager(const char *name): TNamed(name, "AOD Spectra Histo Manager"), fOutputList(0)
47 {
48   // ctor
49    fOutputList = new TList;
50    fOutputList->SetOwner();
51    Bool_t oldStatus = TH1::AddDirectoryStatus();
52    TH1::AddDirectory(kFALSE);
53    for (Int_t ihist  = 0; ihist < kNHist ; ihist++)
54    {
55       if (ihist <= kNPtGenHist) BookPtGenHistogram(kHistName[ihist]);  // PT histos
56       if (ihist > kNPtGenHist && ihist <= kNPtRecHist) BookPtRecHistogram(kHistName[ihist]);  // PT histos
57       if (ihist > kNPtRecHist && ihist <= kNHistPID) BookPIDHistogram(kHistName[ihist]);  // PID histos
58       if (ihist > kNHistPID && ihist <= kNHistNSig) BookNSigHistogram(kHistName[ihist]);  // NSigmaSep histos
59       if (ihist > kNHistNSig) BookqVecHistogram(kHistName[ihist]);  // qDistr histos
60    }
61    //adding quickly o plot to check the centrality distr in two different ways
62    TH2F *hist=new TH2F("CentCheck","CentCheck",1000,0,100,1000,0,100);
63    hist->SetXTitle("fAOD->GetCentrality()->GetCentralityPercentile(V0M)");
64    hist->SetYTitle("fAOD->GetHeader()->GetCentralityP()->GetCentralityPercentileUnchecked(V0M)");
65    hist->Sumw2();
66    fOutputList->Add(hist);
67    
68    TH1::AddDirectory(oldStatus);
69
70 }
71
72 //_______________________________________________________
73
74 TH2F* AliSpectraAODHistoManager::BookPtGenHistogram(const char * name)
75 {
76    // Return a pt histogram with predefined binning, set the ID and add it to the output list
77    AliInfo(Form("Booking pt histogram %s", name));
78    
79    //standard histo
80    const Double_t templBins[] = {0.05,0.1,0.12,0.14,0.16,0.18,0.20,0.25,0.30,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8,5.0};
81    Int_t nbinsTempl=52;
82    
83    TH2F * hist = new TH2F(name,Form("P_{T} distribution (%s)", name),nbinsTempl,templBins,2,-0.5,1.5);//need to be at least 1 becuase the generated are filled with (pt,IsPhysPrim)
84    hist->GetXaxis()->SetTitle("generated P_{T} (GeV / c)");
85    hist->GetYaxis()->SetTitle("DCA xy");
86    hist->SetMarkerStyle(kFullCircle);
87    hist->Sumw2();
88    fOutputList->Add(hist);
89    
90    return hist;
91 }
92
93
94 //_______________________________________________________
95 TH2F* AliSpectraAODHistoManager::BookPtRecHistogram(const char * name)
96 {
97    // Return a pt histogram with predefined binning, set the ID and add it to the output list
98    AliInfo(Form("Booking pt histogram %s", name));
99    
100    //standard histo
101    const Double_t templBins[] = {0.05,0.1,0.12,0.14,0.16,0.18,0.20,0.25,0.30,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8,5.0};
102    Int_t nbinsTempl=52;
103    
104    TH2F * hist = new TH2F(name,Form("reconstructed P_{T} distribution (%s)", name),nbinsTempl,templBins,3000,-3,3);//need to be at least 1 becuase the generated are filled with (pt,IsPhysPrim)
105    hist->GetXaxis()->SetTitle("P_{T} (GeV / c)");
106    hist->GetYaxis()->SetTitle("DCA xy");
107    hist->SetMarkerStyle(kFullCircle);
108    hist->Sumw2();
109    fOutputList->Add(hist);
110
111    return hist;
112 }
113
114 //_____________________________________________________________________________
115
116 TH2F* AliSpectraAODHistoManager::BookPIDHistogram(const char * name)
117 {
118    // Return a pt histogram with predefined binning, set the ID and add it to the output list
119    AliInfo(Form("Booking pt histogram %s", name));
120
121    TH2F * hist = new TH2F(name, Form("Particle Identification (%s)", name), 100, 0, 1.5, 2000, -1000, 1000);
122    hist->GetXaxis()->SetTitle("(GeV / c)");
123    hist->GetYaxis()->SetTitle("PID signal");
124 //  hist->Sumw2();
125    fOutputList->Add(hist);
126
127    return hist;
128 }
129
130 //_____________________________________________________________________________
131
132 TH2F* AliSpectraAODHistoManager::BookNSigHistogram(const char * name)
133 {
134   // Return a pt histogram with predefined binning, set the ID and add it to the output list
135   AliInfo(Form("Booking pt histogram %s", name));
136   
137   TH2F * hist = new TH2F(name, Form("Particle Identification (%s)", name), 200, 0, 1.5, 4000,-40, 40);
138   hist->GetXaxis()->SetTitle("P (GeV / c)");
139   hist->GetYaxis()->SetTitle("TPC");
140   //hist->Sumw2();
141   fOutputList->Add(hist);
142   
143   return hist;
144 }
145
146 //_____________________________________________________________________________
147
148 TH2F* AliSpectraAODHistoManager::BookqVecHistogram(const char * name)
149 {
150   // Return a pt histogram with predefined binning, set the ID and add it to the output list
151   AliInfo(Form("Booking q Vector histogram %s", name));
152   
153   TH2F * hist = new TH2F(name, Form("q Vector distribution vs Centrality (%s)", name), 100, 0, 10, 100, 0, 100);
154   hist->GetXaxis()->SetTitle("q vector");
155   hist->GetYaxis()->SetTitle("Centrality (V0)");
156   //  hist->Sumw2();
157   fOutputList->Add(hist);
158   
159   return hist;
160 }
161
162
163 //_____________________________________________________________________________
164
165 TH1F* AliSpectraAODHistoManager::GetPtHistogram1D(const char * name,Double_t minDCA,Double_t maxDCA)
166 {
167   //   //return the projection of the TH2 (pt,DCA) in the DCA bin range [firstDCAbin,lastDCAbin]
168   //   //if minDCA=-1 && maxDCA=-1 the projection is done using the full DCA range
169   TH2F *hist=(TH2F*)fOutputList->FindObject(name);
170   TH1F *outhist=0x0;
171   if(minDCA==-1 && maxDCA==-1)outhist=(TH1F*)hist->ProjectionX("",0,-1,"e");
172   else {
173     Int_t firstbin=hist->GetYaxis()->FindBin(minDCA);
174     Int_t lastbin=hist->GetYaxis()->FindBin(maxDCA);
175     Printf("firstbin: %d lastbin: %d",firstbin,lastbin);
176     outhist=(TH1F*)hist->ProjectionX("",firstbin,lastbin,"e");
177   }
178   Printf("Entries outhist: %.0f   Entries hist: %.0f",outhist->GetEntries(),hist->GetEntries());
179   return outhist;
180 }
181
182 //_____________________________________________________________________________
183
184 TH1F* AliSpectraAODHistoManager::GetDCAHistogram1D(const char * name,Double_t minPt,Double_t maxPt)
185 {
186   //   //return the projection of the TH2 (pt,DCA) in the DCA bin range [firstDCAbin,lastDCAbin]
187   //   //if minPt=-1 && maxPt=-1 the projection is done using the full DCA range
188   TH2F *hist=(TH2F*)fOutputList->FindObject(name);
189   TH1F *outhist=0x0;
190   if(minPt==-1 && maxPt==-1)outhist=(TH1F*)hist->ProjectionY("",0,-1,"e");
191   else {
192     Int_t firstbin=hist->GetXaxis()->FindBin(minPt);
193     Int_t lastbin=hist->GetXaxis()->FindBin(maxPt);
194     outhist=(TH1F*)hist->ProjectionY("",firstbin,lastbin,"e");
195   }
196   return outhist;
197 }
198
199 //_____________________________________________________________________________
200
201 Long64_t AliSpectraAODHistoManager::Merge(TCollection* list)
202 {
203   // Merge a list of AliSpectraAODHistoManager objects with this.
204   // Returns the number of merged objects (including this).
205
206   //  AliInfo("Merging");
207
208   if (!list)
209     return 0;
210
211   if (list->IsEmpty())
212     return 1;
213
214   TIterator* iter = list->MakeIterator();
215   TObject* obj;
216
217   // collections of all histograms
218   TList collections;
219
220   Int_t count = 0;
221
222   while ((obj = iter->Next())) {
223     AliSpectraAODHistoManager* entry = dynamic_cast<AliSpectraAODHistoManager*> (obj);
224     if (entry == 0) 
225       continue;
226
227     TList * hlist = entry->GetOutputList();      
228     collections.Add(hlist);
229     count++;
230   }
231   
232   fOutputList->Merge(&collections);
233   
234   delete iter;
235
236   return count+1;
237 }
238