d072b48bfc97406edc31b0e793729893477924ba
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TestAOD / AliSpectraAODTrackCuts.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 //         AliSpectraAODTrackCuts class
19 //-----------------------------------------------------------------
20
21 #include "TChain.h"
22 #include "TTree.h"
23 #include "TLegend.h"
24 #include "TH1F.h"
25 #include "TH1I.h"
26 #include "TH2F.h"
27 #include "TCanvas.h"
28 #include "AliAnalysisTask.h"
29 #include "AliAnalysisManager.h"
30 #include "AliAODTrack.h"
31 #include "AliExternalTrackParam.h"
32 #include "AliAODMCParticle.h"
33 #include "AliAODEvent.h"
34 #include "AliAODInputHandler.h"
35 #include "AliAnalysisTaskESDfilter.h"
36 #include "AliAnalysisDataContainer.h"
37 #include "AliSpectraAODTrackCuts.h"
38 //#include "AliSpectraAODHistoManager.h"
39 #include <iostream>
40
41 using namespace std;
42
43 const char * AliSpectraAODTrackCuts::kBinLabel[] ={"TrkBit",
44                                                    "TrkCuts",
45                                                    "TrkEta",
46                                                    "TrkDCA",
47                                                    "TrkP",
48                                                    "TrkPt",
49                                                    "TrkPtTOF",
50                                                    "TOFMatching",
51                                                    "kTOFout",
52                                                    "kTIME",
53                                                    "kTOFpid",
54                                                    "Accepted"};
55
56
57 ClassImp(AliSpectraAODTrackCuts)
58
59
60 AliSpectraAODTrackCuts::AliSpectraAODTrackCuts(const char *name) : TNamed(name, "AOD Track Cuts"), fIsSelected(0), fTrackBits(0), fMinTPCcls(0), fEtaCutMin(0), fEtaCutMax(0), fDCACut(0), fPCut(0), fPtCut(0), fYCut(0),
61   fPtCutTOFMatching(0), fHistoCuts(0), fHistoNSelectedPos(0), fHistoNSelectedNeg(0), fHistoNMatchedPos(0), fHistoNMatchedNeg(0), fHistoEtaPhiHighPt(0), fTrack(0)
62   
63 {
64   // Constructor
65   fHistoCuts = new TH1I("fTrkCuts", "Track Cuts", kNTrkCuts, -0.5, kNTrkCuts - 0.5);
66   for(Int_t ibin=1;ibin<=kNTrkCuts;ibin++)fHistoCuts->GetXaxis()->SetBinLabel(ibin,kBinLabel[ibin-1]);
67   //standard histo
68   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};
69   Int_t nbinsTempl=52;
70   
71   fHistoNSelectedPos=new TH1F("fHistoNSelectedPos","fHistoNSelectedPos",nbinsTempl,templBins);
72   fHistoNSelectedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
73   fHistoNSelectedNeg=new TH1F("fHistoNSelectedNeg","fHistoNSelectedNeg",nbinsTempl,templBins);
74   fHistoNSelectedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
75   fHistoNMatchedPos=new TH1F("fHistoNMatchedPos","fHistoNMatchedPos",nbinsTempl,templBins);
76   fHistoNMatchedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
77   fHistoNMatchedNeg=new TH1F("fHistoNMatchedNeg","fHistoNMatchedNeg",nbinsTempl,templBins);
78   fHistoNMatchedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
79   fHistoEtaPhiHighPt=new TH2F("fHistoEtaPhiHighPt","fHistoEtaPhiHighPt",200,-1,1,400,0,7);
80   fHistoEtaPhiHighPt->SetXTitle("eta");
81   fHistoEtaPhiHighPt->SetYTitle("phi");
82   
83   fEtaCutMin = -100000.0; // default value of eta cut ~ no cut
84   fEtaCutMax = 100000.0; // default value of eta cut ~ no cut
85   fDCACut = 100000.0; // default value of dca cut ~ no cut
86   fPCut = 100000.0; // default value of p cut ~ no cut
87   fPtCut = 100000.0; // default value of pt cut ~ no cut 
88   fPtCutTOFMatching=0.6; //default value fot matching with TOF
89   fYCut       = 100000.0; // default value of y cut ~ no cut 
90   fMinTPCcls=70; // ncls in TPC
91 }
92
93 //_______________________________________________________
94 Bool_t AliSpectraAODTrackCuts::IsSelected(AliAODTrack * track,Bool_t FillHistStat)
95 {
96   // Returns true if Track Cuts are selected and applied
97   if (!track)
98     {
99       printf("ERROR: Could not receive track");
100       return kFALSE;
101     }
102   fTrack = track;
103   
104   if(!CheckTrackType()){
105     return kFALSE;
106   }
107   if(FillHistStat)fHistoCuts->Fill(kTrkBit);
108   
109   if(!CheckTrackCuts()){
110     return kFALSE;
111   }
112   if(FillHistStat)fHistoCuts->Fill(kTrkCuts);
113   if(!CheckEtaCut()){
114     return kFALSE;
115   }
116   if(FillHistStat)fHistoCuts->Fill(kTrkEta);
117   if(!CheckDCACut()){
118     return kFALSE;
119   }
120   if(FillHistStat)fHistoCuts->Fill(kTrkDCA);
121   if(!CheckPCut()){
122     return kFALSE;
123   }
124   if(FillHistStat)fHistoCuts->Fill(kTrkP);
125   if(!CheckPtCut()){
126     return kFALSE;
127   }
128   if(FillHistStat)fHistoCuts->Fill(kTrkPt);
129   if(!CheckTOFMatching(FillHistStat)){
130     return kFALSE;
131   }
132   if(FillHistStat)fHistoCuts->Fill(kAccepted);
133   //Printf("-------- %d,%d",kTOFMatching,kAccepted);
134   return kTRUE;
135 }
136 //_________________________________________________________
137
138 Bool_t AliSpectraAODTrackCuts::CheckTrackType()
139 {
140   // Check track Type
141   if (fTrack->TestFilterBit(fTrackBits)) return kTRUE;
142   return kFALSE;
143 }
144 //_________________________________________________________
145
146 Bool_t AliSpectraAODTrackCuts::CheckTrackCuts()
147 {
148   // Check additional track Cuts
149   Bool_t PassTrackCuts=kTRUE;
150   if (!fTrack->HasPointOnITSLayer(0) && !fTrack->HasPointOnITSLayer(1))PassTrackCuts=kFALSE; //FIXME 1 SPD for the moment
151   if (fTrack->GetTPCNcls()<fMinTPCcls)PassTrackCuts=kFALSE;
152   return PassTrackCuts;
153 }
154 //________________________________________________________
155 Bool_t AliSpectraAODTrackCuts::CheckEtaCut()
156 {
157    // Check eta cut
158    if (fTrack->Eta() < fEtaCutMax && fTrack->Eta() > fEtaCutMin) return kTRUE;
159     return kFALSE;
160 }
161
162 Bool_t AliSpectraAODTrackCuts::CheckYCut(AODParticleSpecies_t species) 
163 {
164   // check if the rapidity is within the set range
165   Double_t y;
166   if (species == kSpProton) { y = fTrack->Y(9.38271999999999995e-01); }
167   if ( species == kSpKaon ) { y = fTrack->Y(4.93676999999999977e-01); }
168   if ( species == kSpPion)  { y = fTrack->Y(1.39570000000000000e-01); }
169   if (TMath::Abs(y) > fYCut || y < -998.) return kFALSE;
170   return kTRUE;
171 }
172 //_______________________________________________________
173 Bool_t AliSpectraAODTrackCuts::CheckDCACut()
174 {
175    // Check DCA cut
176   if (TMath::Abs(fTrack->DCA()) < fDCACut) return kTRUE; //FIXME for newest AOD fTrack->DCA() always gives -999
177    return kFALSE;
178 }
179 //________________________________________________________
180 Bool_t AliSpectraAODTrackCuts::CheckPCut()
181 {
182    // Check P cut
183    if (fTrack->P() < fPCut) return kTRUE;
184    return kFALSE;
185 }
186 //_______________________________________________________
187 Bool_t AliSpectraAODTrackCuts::CheckPtCut()
188 {
189     // check Pt cut
190 //    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;
191    if (fTrack->Pt() < fPtCut) return kTRUE;
192     return kFALSE;
193 }
194
195 //_______________________________________________________
196 Bool_t AliSpectraAODTrackCuts::CheckTOFMatching(Bool_t FillHistStat)
197 {
198   // check Pt cut
199   //    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;
200   
201   if (fTrack->Pt() < fPtCutTOFMatching) return kTRUE;
202   else{
203     if(FillHistStat)fHistoCuts->Fill(kTrkPtTOF);
204     if(fTrack->Charge()>0)fHistoNSelectedPos->Fill(fTrack->Pt());
205     else fHistoNSelectedNeg->Fill(fTrack->Pt());
206     UInt_t status; 
207     status=fTrack->GetStatus();
208     if((status&AliAODTrack::kTOFout)&&FillHistStat)fHistoCuts->Fill(kTrTOFout);
209     if((status&AliAODTrack::kTIME)&&FillHistStat)fHistoCuts->Fill(kTrTIME);
210     if((status&AliAODTrack::kTOFpid)&&FillHistStat)fHistoCuts->Fill(kTrTOFpid);
211     
212     if((status&AliAODTrack::kTOFout)==0 || (status&AliAODTrack::kTIME)==0){//kTOFout and kTIME
213       return kFALSE; 
214     } 
215     if(FillHistStat)fHistoCuts->Fill(kTOFMatching);
216     if(fTrack->Charge()>0)fHistoNMatchedPos->Fill(fTrack->Pt());
217     else fHistoNMatchedNeg->Fill(fTrack->Pt());
218     if(fTrack->Pt()>1.5){
219       //fHistoEtaPhiHighPt->Fill(fTrack->GetOuterParam()->Eta(),fTrack->GetOuterParam()->Phi());
220       //Printf("AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();");
221       //AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();
222       fHistoEtaPhiHighPt->Fill(fTrack->Eta(),fTrack->Phi());
223       //Printf("fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());");
224       //fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());
225       //delete extpar;
226     }
227     return kTRUE;
228   }
229 }
230 //_______________________________________________________
231 void AliSpectraAODTrackCuts::PrintCuts() const
232 {
233   // Print cuts
234     cout << "Track Cuts" << endl;
235     cout << " > TrackBit\t" << fTrackBits << endl;
236     cout << " > Eta cut\t" << fEtaCutMin <<","<< fEtaCutMax << endl;
237     cout << " > DCA cut\t" << fDCACut << endl;
238     cout << " > P cut\t" << fPCut << endl;
239     cout << " > Pt cut \t" << fPtCut << endl;
240     cout << " > TPC cls \t" << fMinTPCcls << endl;
241 }
242 //_______________________________________________________
243 void AliSpectraAODTrackCuts::SetTrackType(UInt_t bit)
244 {
245    // Set the type of track to be used. The argument should be the bit number. The mask is produced automatically.
246    fTrackBits = (0x1 << (bit - 1));
247 }
248 //_______________________________________________________
249
250 Long64_t AliSpectraAODTrackCuts::Merge(TCollection* list)
251 {
252   // Merge a list of AliSpectraAODTrackCuts objects with this.
253   // Returns the number of merged objects (including this).
254
255   //  AliInfo("Merging");
256
257   if (!list)
258     return 0;
259
260   if (list->IsEmpty())
261     return 1;
262
263   TIterator* iter = list->MakeIterator();
264   TObject* obj;
265
266   // collections of all histograms
267   TList collections;//FIXME we should only 1 collection
268   TList collections_histoNSelectedPos;
269   TList collections_histoNSelectedNeg;
270   TList collections_histoNMatchedPos;
271   TList collections_histoNMatchedNeg;
272   TList collections_histoEtaPhiHighPt;
273
274   Int_t count = 0;
275
276   while ((obj = iter->Next())) {
277     AliSpectraAODTrackCuts* entry = dynamic_cast<AliSpectraAODTrackCuts*> (obj);
278     if (entry == 0) 
279       continue;
280     
281     TH1I * histo = entry->GetHistoCuts();      
282     collections.Add(histo);
283     TH1F * histoNSelectedPos = entry->GetHistoNSelectedPos();      
284     collections_histoNSelectedPos.Add(histoNSelectedPos);
285     TH1F * histoNSelectedNeg = entry->GetHistoNSelectedNeg();      
286     collections_histoNSelectedNeg.Add(histoNSelectedNeg);
287     TH1F * histoNMatchedPos = entry->GetHistoNMatchedPos();      
288     collections_histoNMatchedPos.Add(histoNMatchedPos);
289     TH1F * histoNMatchedNeg = entry->GetHistoNMatchedNeg();      
290     collections_histoNMatchedNeg.Add(histoNMatchedNeg);
291     TH2F * histoEtaPhiHighPt = entry->GetHistoEtaPhiHighPt();      
292     collections_histoEtaPhiHighPt.Add(histoEtaPhiHighPt);
293     count++;
294   }
295   
296   fHistoCuts->Merge(&collections);
297   fHistoNSelectedPos->Merge(&collections_histoNSelectedPos);
298   fHistoNSelectedNeg->Merge(&collections_histoNSelectedNeg);
299   fHistoNMatchedPos->Merge(&collections_histoNMatchedPos);
300   fHistoNMatchedNeg->Merge(&collections_histoNMatchedNeg);
301   fHistoEtaPhiHighPt->Merge(&collections_histoEtaPhiHighPt);
302   
303   delete iter;
304
305   return count+1;
306 }
307