2a332e32a652fc94227bc3af74e746636a63abc0
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TestAOD / AliSpectraBothTrackCuts.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 //         AliSpectraBothTrackCuts 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 "AliVTrack.h"
32 #include "AliExternalTrackParam.h"
33 #include "AliAODMCParticle.h"
34 #include "AliAODEvent.h"
35 #include "AliAODInputHandler.h"
36 #include "AliAnalysisTaskESDfilter.h"
37 #include "AliAnalysisDataContainer.h"
38 #include "AliSpectraBothTrackCuts.h"
39 //#include "AliSpectraBothHistoManager.h"
40 #include <iostream>
41
42 using namespace std;
43
44 const char * AliSpectraBothTrackCuts::kBinLabel[] ={"TrkBit",
45                                                    "TrkCuts",
46                                                    "TrkEta",
47                                                    "TrkDCA",
48                                                    "TrkP",
49                                                    "TrkPt",
50                                                    "TrkPtTOF",
51                                                    "TOFMatching",
52                                                    "kTOFout",
53                                                    "kTIME",
54                                                    "kTOFpid",
55                                                    "Accepted"};
56
57
58 ClassImp(AliSpectraBothTrackCuts)
59
60
61 AliSpectraBothTrackCuts::AliSpectraBothTrackCuts(const char *name) : TNamed(name, "AOD Track Cuts"), fIsSelected(0), fTrackBits(0), fMinTPCcls(0), fEtaCutMin(0), fEtaCutMax(0), fDCACut(0), fPCut(0), fPtCut(0), fYCutMax(0),fYCutMin(0),
62   fPtCutTOFMatching(0),fAODtrack(kotherobject), fHashitinSPD1(0),fusedadditionalcuts(kTRUE),
63 fHistoCuts(0), fHistoNSelectedPos(0), fHistoNSelectedNeg(0), fHistoNMatchedPos(0), fHistoNMatchedNeg(0), fHistoEtaPhiHighPt(0), fHistoNclustersITS(0),fTrack(0),fCuts(0)
64   
65 {
66   // Constructor
67   fHistoCuts = new TH1I("fTrkCuts", "Track Cuts", kNTrkCuts, -0.5, kNTrkCuts - 0.5);
68   for(Int_t ibin=1;ibin<=kNTrkCuts;ibin++)fHistoCuts->GetXaxis()->SetBinLabel(ibin,kBinLabel[ibin-1]);
69   //standard histo
70   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};
71   Int_t nbinsTempl=52;
72   
73   fHistoNSelectedPos=new TH1F("fHistoNSelectedPos","fHistoNSelectedPos",nbinsTempl,templBins);
74   fHistoNSelectedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
75   fHistoNSelectedNeg=new TH1F("fHistoNSelectedNeg","fHistoNSelectedNeg",nbinsTempl,templBins);
76   fHistoNSelectedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
77   fHistoNMatchedPos=new TH1F("fHistoNMatchedPos","fHistoNMatchedPos",nbinsTempl,templBins);
78   fHistoNMatchedPos->GetXaxis()->SetTitle("P_{T} (GeV / c)");
79   fHistoNMatchedNeg=new TH1F("fHistoNMatchedNeg","fHistoNMatchedNeg",nbinsTempl,templBins);
80   fHistoNMatchedNeg->GetXaxis()->SetTitle("P_{T} (GeV / c)");
81   fHistoEtaPhiHighPt=new TH2F("fHistoEtaPhiHighPt","fHistoEtaPhiHighPt",200,-1,1,400,0,7);
82   fHistoEtaPhiHighPt->SetXTitle("eta");
83   fHistoEtaPhiHighPt->SetYTitle("phi");
84   fHistoNclustersITS=new TH1F("fHistoNclustersITS","fHistoNclustersITS;N;ITSLayer",6,-0.5,5.5);
85   
86   fEtaCutMin = -100000.0; // default value of eta cut ~ no cut
87   fEtaCutMax = 100000.0; // default value of eta cut ~ no cut
88   fDCACut = 100000.0; // default value of dca cut ~ no cut
89   fPCut = 100000.0; // default value of p cut ~ no cut
90   fPtCut = 100000.0; // default value of pt cut ~ no cut 
91   fPtCutTOFMatching=0.6; //default value fot matching with TOF
92   fYCutMax       = 100000.0; // default value of y cut ~ no cut 
93   fYCutMin       = -100000.0; // default value of y cut ~ no cut 
94   fMinTPCcls=70; // ncls in TPC
95 }
96
97 //_______________________________________________________
98 Bool_t AliSpectraBothTrackCuts::IsSelected(AliVTrack * track,Bool_t FillHistStat)
99 {
100 // Returns true if Track Cuts are selected and applied
101   if (!track)
102     {
103       printf("ERROR: Could not receive track");
104       return kFALSE;
105     }
106     fTrack = track;
107    TString nameoftrack(track->ClassName());  
108     if(!nameoftrack.CompareTo("AliESDtrack"))
109                 fAODtrack=kESDobject;
110         else if(!nameoftrack.CompareTo("AliAODTrack"))
111                 fAODtrack=kAODobject;
112         else
113                 fAODtrack=kotherobject;
114   if(!CheckTrackType()){
115     return kFALSE;
116   }
117   if(FillHistStat)fHistoCuts->Fill(kTrkBit);
118   if(!CheckTrackCuts()){
119     return kFALSE;
120   }
121   if(FillHistStat)fHistoCuts->Fill(kTrkCuts);
122   if(!CheckEtaCut()){
123     return kFALSE;
124   }
125   if(FillHistStat)fHistoCuts->Fill(kTrkEta);
126   if(!CheckDCACut()){
127     return kFALSE;
128   }
129   if(FillHistStat)fHistoCuts->Fill(kTrkDCA);
130   if(!CheckPCut()){
131     return kFALSE;
132   }
133   if(FillHistStat)fHistoCuts->Fill(kTrkP);
134   if(!CheckPtCut()){
135     return kFALSE;
136   }
137   if(FillHistStat)fHistoCuts->Fill(kTrkPt);
138   if(!CheckTOFMatching(FillHistStat)){
139     return kFALSE;
140   }
141   if(FillHistStat)fHistoCuts->Fill(kAccepted);
142   //Printf("-------- %d,%d",kTOFMatching,kAccepted);
143   
144   return kTRUE;
145 }
146 //_________________________________________________________
147
148 Bool_t AliSpectraBothTrackCuts::CheckTrackType()
149 {
150   // Check track Type
151   if(fAODtrack==kESDobject)
152   {
153         AliESDtrack* esdtrack=dynamic_cast<AliESDtrack*>(fTrack);
154         if(!esdtrack)
155                 return kFALSE;  
156         if(fCuts->AcceptTrack(esdtrack)) return kTRUE;
157                 return kFALSE;
158  }
159   else if(fAODtrack==kAODobject)
160   {
161         AliAODTrack* aodtrack=dynamic_cast<AliAODTrack*>(fTrack);
162         if(!aodtrack)
163                 return kFALSE;
164         if (aodtrack->TestFilterBit(fTrackBits)) return kTRUE;
165                 return kFALSE;
166   }
167
168   else
169         return kFALSE;
170   
171 }
172 //_________________________________________________________
173
174 Bool_t AliSpectraBothTrackCuts::CheckTrackCuts()
175 {
176   // Check additional track Cuts
177   Bool_t PassTrackCuts=kTRUE;
178   if(!fusedadditionalcuts)
179         return PassTrackCuts;
180   AliAODTrack* aodtrack=0;
181   AliESDtrack* esdtrack=0;
182   if(fAODtrack==kESDobject)
183   {
184         esdtrack=dynamic_cast<AliESDtrack*>(fTrack);
185         if(!esdtrack)
186                 return kFALSE;
187         if (!esdtrack->HasPointOnITSLayer(0) && !esdtrack->HasPointOnITSLayer(1))PassTrackCuts=kFALSE; //FIXME 1 SPD for the moment
188         if (fHashitinSPD1&&!esdtrack->HasPointOnITSLayer(0)) PassTrackCuts=kFALSE;              
189         if (esdtrack->GetTPCNcls()<fMinTPCcls)PassTrackCuts=kFALSE;
190         if(!esdtrack->IsOn(AliESDtrack::kTPCrefit))PassTrackCuts=kFALSE;
191         if(!esdtrack->IsOn(AliESDtrack::kITSrefit))PassTrackCuts=kFALSE;
192         if(PassTrackCuts)
193         {
194                 for(int i=0;i<6;i++)
195                         if(esdtrack->HasPointOnITSLayer(i))
196                                 fHistoNclustersITS->Fill(i);
197         }       
198   }
199   else if (fAODtrack==kAODobject)
200         {
201         aodtrack=dynamic_cast<AliAODTrack*>(fTrack);
202         if(!aodtrack)
203                 return kFALSE;
204         if (!aodtrack->HasPointOnITSLayer(0) && !aodtrack->HasPointOnITSLayer(1))PassTrackCuts=kFALSE; //FIXME 1 SPD for the moment
205         if (fHashitinSPD1&&!aodtrack->HasPointOnITSLayer(0)) PassTrackCuts=kFALSE;      
206         if (aodtrack->GetTPCNcls()<fMinTPCcls)PassTrackCuts=kFALSE;
207         if(!aodtrack->IsOn(AliAODTrack::kTPCrefit))PassTrackCuts=kFALSE;
208         if(!aodtrack->IsOn(AliAODTrack::kITSrefit))PassTrackCuts=kFALSE;
209         if(PassTrackCuts)
210         {
211                 for(int i=0;i<6;i++)
212                         if(aodtrack->HasPointOnITSLayer(i))
213                                 fHistoNclustersITS->Fill(i);
214         }       
215   }
216   else
217         return kFALSE;
218     
219   
220   
221   return PassTrackCuts;
222 }
223 //________________________________________________________
224 Bool_t AliSpectraBothTrackCuts::CheckEtaCut()
225 {
226    // Check eta cut
227    if (fTrack->Eta() < fEtaCutMax && fTrack->Eta() > fEtaCutMin) return kTRUE;
228     return kFALSE;
229 }
230
231 Bool_t AliSpectraBothTrackCuts::CheckYCut(BothParticleSpecies_t species) 
232 {
233   // check if the rapidity is within the set range
234   Double_t y;
235   
236   Double_t pz=fTrack->Pz();
237   Double_t p=fTrack->P();
238   Double_t mass=-1.0;
239   /*
240   if (species == kSpProton) { y = fTrack->Y(9.38271999999999995e-01); }
241   if ( species == kSpKaon ) { y = fTrack->Y(4.93676999999999977e-01); }
242   if ( species == kSpPion)  { y = fTrack->Y(1.39570000000000000e-01); }
243   
244   */
245     if (species == kSpProton) { mass=9.38271999999999995e-01; }
246   if ( species == kSpKaon ) { mass=4.93676999999999977e-01; }
247   if ( species == kSpPion)  { mass=1.39570000000000000e-01; }
248   if(mass<0.0)
249         y =-999.0 ;
250   else
251         y=0.5*TMath::Log((TMath::Sqrt(mass*mass+p*p)+pz)/(TMath::Sqrt(mass*mass+p*p)-pz));
252   if (y > fYCutMax || y<fYCutMin||y < -998.) return kFALSE;
253         return kTRUE;
254 }
255 //_______________________________________________________
256 Bool_t AliSpectraBothTrackCuts::CheckDCACut()
257 {
258    // Check DCA cut
259  // if (TMath::Abs(fTrack->DCA()) < fDCACut) return kTRUE; //FIXME for newest AOD fTrack->DCA() always gives -999
260    
261     AliAODTrack* aodtrack=0;
262   AliESDtrack* esdtrack=0;
263   if(fAODtrack==kESDobject)
264   {
265         esdtrack=dynamic_cast<AliESDtrack*>(fTrack);
266         if(!esdtrack)
267                 return kFALSE;
268         Float_t dcaxy=0.0; 
269         Float_t dcaz=0.0;
270         esdtrack->GetImpactParameters(dcaxy,dcaz);      
271         if (TMath::Abs(dcaxy) < fDCACut) 
272                 return kTRUE;
273         else 
274                 return kFALSE;
275    }
276   else if (fAODtrack==kAODobject)
277   {
278         aodtrack=dynamic_cast<AliAODTrack*>(fTrack);
279         if(!aodtrack)
280                 return kFALSE;
281         if (TMath::Abs(aodtrack->DCA()) < fDCACut) return kTRUE;
282         else 
283                 return kFALSE;
284                 
285    }
286         else
287         return kFALSE;
288 }
289 //________________________________________________________
290 Bool_t AliSpectraBothTrackCuts::CheckPCut()
291 {
292    // Check P cut
293    if (fTrack->P() < fPCut) return kTRUE;
294    return kFALSE;
295 }
296 //_______________________________________________________
297 Bool_t AliSpectraBothTrackCuts::CheckPtCut()
298 {
299     // check Pt cut
300 //    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;
301    if (fTrack->Pt() < fPtCut) return kTRUE;
302     return kFALSE;
303 }
304
305 //_______________________________________________________
306 Bool_t AliSpectraBothTrackCuts::CheckTOFMatching(Bool_t FillHistStat)
307 {
308   // check Pt cut
309   //    if ((fTrack->Pt() < fPtCut) && (fTrack->Pt() > 0.3 )) return kTRUE;
310   
311   if (fTrack->Pt() < fPtCutTOFMatching) return kTRUE;
312   else{
313     if(FillHistStat)fHistoCuts->Fill(kTrkPtTOF);
314     if(fTrack->Charge()>0)fHistoNSelectedPos->Fill(fTrack->Pt());
315     else fHistoNSelectedNeg->Fill(fTrack->Pt());
316     UInt_t status; 
317     status=fTrack->GetStatus();
318     if((status&AliAODTrack::kTOFout)&&FillHistStat)fHistoCuts->Fill(kTrTOFout);
319     if((status&AliAODTrack::kTIME)&&FillHistStat)fHistoCuts->Fill(kTrTIME);
320     if((status&AliAODTrack::kTOFpid)&&FillHistStat)fHistoCuts->Fill(kTrTOFpid);
321     
322     if((status&AliAODTrack::kTOFout)==0 || (status&AliAODTrack::kTIME)==0){//kTOFout and kTIME
323       return kFALSE; 
324     } 
325     if(FillHistStat)fHistoCuts->Fill(kTOFMatching);
326     if(fTrack->Charge()>0)fHistoNMatchedPos->Fill(fTrack->Pt());
327     else fHistoNMatchedNeg->Fill(fTrack->Pt());
328     if(fTrack->Pt()>1.5){
329       //fHistoEtaPhiHighPt->Fill(fTrack->GetOuterParam()->Eta(),fTrack->GetOuterParam()->Phi());
330       //Printf("AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();");
331       //AliExternalTrackParam * extpar=(AliExternalTrackParam*)fTrack->GetOuterParam();
332       fHistoEtaPhiHighPt->Fill(fTrack->Eta(),fTrack->Phi());
333       //Printf("fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());");
334       //fHistoEtaPhiHighPt->Fill(extpar->Eta(),extpar->Phi());
335       //delete extpar;
336     }
337     return kTRUE;
338   }
339 }
340 //_______________________________________________________
341 void AliSpectraBothTrackCuts::PrintCuts() const
342 {
343   // Print cuts
344     cout << "Track Cuts" << endl;
345     cout << " > TrackBit\t" << fTrackBits << endl;
346     cout << " > Eta cut\t" << fEtaCutMin <<","<< fEtaCutMax << endl;
347     cout << " > DCA cut\t" << fDCACut << endl;
348     cout << " > P cut\t" << fPCut << endl;
349     cout << " > Pt cut \t" << fPtCut << endl;
350     cout << " > TPC cls \t" << fMinTPCcls << endl;
351 }
352 //_______________________________________________________
353 void AliSpectraBothTrackCuts::SetTrackType(UInt_t bit)
354 {
355    // Set the type of track to be used. The argument should be the bit number. The mask is produced automatically.
356    fTrackBits = (0x1 << (bit - 1));
357 }
358 //_______________________________________________________
359
360 Long64_t AliSpectraBothTrackCuts::Merge(TCollection* list)
361 {
362   // Merge a list of AliSpectraBothTrackCuts objects with this.
363   // Returns the number of merged objects (including this).
364
365   //  AliInfo("Merging");
366
367
368   if (!list)
369     return 0;
370
371   if (list->IsEmpty())
372     return 1;
373
374   TIterator* iter = list->MakeIterator();
375   TObject* obj;
376
377   // collections of all histograms
378   TList collections;//FIXME we should only 1 collection
379   TList collections_histoNSelectedPos;
380   TList collections_histoNSelectedNeg;
381   TList collections_histoNMatchedPos;
382   TList collections_histoNMatchedNeg;
383   TList collections_histoEtaPhiHighPt;
384
385   Int_t count = 0;
386
387   while ((obj = iter->Next())) {
388     AliSpectraBothTrackCuts* entry = dynamic_cast<AliSpectraBothTrackCuts*> (obj);
389     if (entry == 0) 
390       continue;
391     
392     TH1I * histo = entry->GetHistoCuts();      
393     collections.Add(histo);
394     TH1F * histoNSelectedPos = entry->GetHistoNSelectedPos();      
395     collections_histoNSelectedPos.Add(histoNSelectedPos);
396     TH1F * histoNSelectedNeg = entry->GetHistoNSelectedNeg();      
397     collections_histoNSelectedNeg.Add(histoNSelectedNeg);
398     TH1F * histoNMatchedPos = entry->GetHistoNMatchedPos();      
399     collections_histoNMatchedPos.Add(histoNMatchedPos);
400     TH1F * histoNMatchedNeg = entry->GetHistoNMatchedNeg();      
401     collections_histoNMatchedNeg.Add(histoNMatchedNeg);
402     TH2F * histoEtaPhiHighPt = entry->GetHistoEtaPhiHighPt();      
403     collections_histoEtaPhiHighPt.Add(histoEtaPhiHighPt);
404     count++;
405   }
406   
407   fHistoCuts->Merge(&collections);
408   fHistoNSelectedPos->Merge(&collections_histoNSelectedPos);
409   fHistoNSelectedNeg->Merge(&collections_histoNSelectedNeg);
410   fHistoNMatchedPos->Merge(&collections_histoNMatchedPos);
411   fHistoNMatchedNeg->Merge(&collections_histoNMatchedNeg);
412   fHistoEtaPhiHighPt->Merge(&collections_histoEtaPhiHighPt);
413   
414   delete iter;
415
416   return count+1;
417 }
418