]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliDielectronV0Cuts.cxx
-add PID default cuts to V0cuts
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliDielectronV0Cuts.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 ///////////////////////////////////////////////////////////////////////////
17 //   Cut class providing cuts to all infomation                          //
18 //     available for the AliVParticle interface                          //
19 //                                                                       //
20 // Authors:                                                              //
21 //   Julian Book <Julian.Book@cern.ch>                                  //
22 /*
23
24
25
26 */
27 //                                                                       //
28 ///////////////////////////////////////////////////////////////////////////
29
30
31 #include "AliDielectronV0Cuts.h"
32 #include "AliDielectronVarManager.h"
33 #include "AliDielectronTrackCuts.h"
34 #include "AliDielectronPID.h"
35 #include "AliESDv0.h"
36
37 ClassImp(AliDielectronV0Cuts)
38
39
40 AliDielectronV0Cuts::AliDielectronV0Cuts() :
41   AliDielectronVarCuts(),
42   fV0TrackArr(0),
43   fExcludeTracks(kTRUE),
44   fMotherPdg(0),
45   fNegPdg(0),
46   fPosPdg(0),
47   fPID(-1),
48   fOrbit(0),
49   fPeriod(0),
50   fBunchCross(0)
51 {
52   //
53   // Default costructor
54   //
55 }
56
57 //________________________________________________________________________
58 AliDielectronV0Cuts::AliDielectronV0Cuts(const char* name, const char* title) :
59   AliDielectronVarCuts(name,title),
60   fV0TrackArr(0),
61   fExcludeTracks(kTRUE),
62   fMotherPdg(0),
63   fNegPdg(0),
64   fPosPdg(0),
65   fPID(-1),
66   fOrbit(0),
67   fPeriod(0),
68   fBunchCross(0)
69 {
70   //
71   // Named contructor
72   //
73 }
74
75 //________________________________________________________________________
76 AliDielectronV0Cuts::~AliDielectronV0Cuts()
77 {
78   //
79   // Destructor
80   //
81
82 }
83
84 //________________________________________________________________________
85 void AliDielectronV0Cuts::InitEvent(AliVTrack *trk)
86 {
87   //
88   // Init the V0 candidates
89   //
90
91   // take current event from the track
92   // TODO: this should be simplyfied by AliVTrack::GetEvent() as soon as implemented
93   const AliVEvent *ev=0;
94   if(trk->IsA() == AliAODTrack::Class())
95     ev=static_cast<const AliVEvent*>((static_cast<const AliAODTrack*>(trk))->GetAODEvent());
96   else if(trk->IsA() == AliESDtrack::Class())
97     ev=static_cast<const AliVEvent*>((static_cast<const AliESDtrack*>(trk))->GetESDEvent());
98   else
99     return;
100
101
102   // IsNewEvent
103   if(!ev) return;
104   if(!IsNewEvent(ev)) return;
105   //  printf(" Build V0 candidates according to the applied cuts \n");
106
107   // TODO think about MCevent
108   //  Print();
109
110   // rest booleans
111   fV0TrackArr.ResetAllBits();
112
113   // basic quality cut, at least one of the V0 daughters has to fullfill
114   AliDielectronVarCuts dauQAcuts1;
115   dauQAcuts1.AddCut(AliDielectronVarManager::kEta,          -0.9,   0.9);
116   dauQAcuts1.AddCut(AliDielectronVarManager::kNclsTPC,      50.0, 160.0);
117   dauQAcuts1.AddCut(AliDielectronVarManager::kTPCchi2Cl,     0.0,   4.0);
118   AliDielectronTrackCuts dauQAcuts2;
119   //  dauQAcuts2.SetRequireITSRefit(kTRUE);
120   dauQAcuts2.SetRequireTPCRefit(kTRUE);
121   AliDielectronPID dauPIDcuts;
122   if(fPID>=0) dauPIDcuts.SetDefaults(fPID);
123
124   Int_t nV0s = 0;
125   AliDielectronPair candidate;
126   candidate.SetPdgCode(fMotherPdg);
127
128   // ESD or AOD event
129   if(ev->IsA() == AliESDEvent::Class()) {
130     const AliESDEvent *esdev = static_cast<const AliESDEvent*>(ev);
131
132     printf("there are %d V0s in the event \n",esdev->GetNumberOfV0s());
133     // loop over V0s
134     for (Int_t iv=0; iv<esdev->GetNumberOfV0s(); ++iv){
135       AliESDv0 *v = esdev->GetV0(iv);
136       if(!v) continue;
137
138       // should we make use of AliESDv0Cuts::GetPdgCode() to preselect candiadtes, e.g.:
139       // if(fMotherPdg!=v->GetPdgCode()) continue;
140
141       AliESDtrack *trNeg=esdev->GetTrack(v->GetIndex(0));
142       AliESDtrack *trPos=esdev->GetTrack(v->GetIndex(1));
143       if(!trNeg || !trPos){
144         printf("Error: Couldn't get V0 daughter: %p - %p\n",trNeg,trPos);
145         continue;
146       }
147
148       // PID default cuts
149       if(fPID>=0) {
150         if( !dauPIDcuts.IsSelected(trNeg) || !dauPIDcuts.IsSelected(trPos) ) continue;
151       }
152
153       // at least one of the daughter has to pass basic QA cuts
154       if(!(dauQAcuts1.IsSelected(trNeg) && dauQAcuts2.IsSelected(trNeg)) ||
155          !(dauQAcuts1.IsSelected(trPos) && dauQAcuts2.IsSelected(trPos))  ) continue;
156
157       if(fMotherPdg==22) candidate.SetGammaTracks(trNeg, 11, trPos, 11);
158       else candidate.SetTracks(trNeg, fNegPdg, trPos, fPosPdg);
159       // eventually take the external trackparam and build the KFparticles by hand (see AliESDv0::GetKFInfo)
160       // the folowing is not needed, because the daughters where used in the v0 vertex fit (I guess)
161       //      AliKFVertex v0vtx = *v;
162       //      candidate.SetProductionVertex(v0vtx);
163
164       if(AliDielectronVarCuts::IsSelected(&candidate)) {
165         nV0s++;
166         //printf(" gamma found for vtx %p dau1id %d dau2id %d \n",v,trNeg->GetID(),trPos->GetID());
167         fV0TrackArr.SetBitNumber(trNeg->GetID());
168         fV0TrackArr.SetBitNumber(trPos->GetID());
169       }
170     }
171
172   }
173   else if(ev->IsA() == AliAODEvent::Class()) {
174     const AliAODEvent *aodEv = static_cast<const AliAODEvent*>(ev);
175
176     //    Int_t nV0stored = 0;
177     // loop over vertices
178     for (Int_t ivertex=0; ivertex<aodEv->GetNumberOfVertices(); ++ivertex){
179       AliAODVertex *v=aodEv->GetVertex(ivertex);
180       if(v->GetType()!=AliAODVertex::kV0) continue;
181       if(v->GetNDaughters()!=2) continue;
182
183       AliAODTrack *trNeg=dynamic_cast<AliAODTrack*>(v->GetDaughter(0));
184       AliAODTrack *trPos=dynamic_cast<AliAODTrack*>(v->GetDaughter(1));
185       if(!trNeg || !trPos){
186         printf("Error: Couldn't get V0 daughter: %p - %p\n",trNeg,trPos);
187         continue;
188       }
189       //nV0stored++;
190
191       // PID default cuts
192       if(fPID>=0) {
193         if( !dauPIDcuts.IsSelected(trNeg) || !dauPIDcuts.IsSelected(trPos) ) continue;
194       }
195
196       // at least one of the daughter has to pass basic QA cuts
197       if(!(dauQAcuts1.IsSelected(trNeg) && dauQAcuts2.IsSelected(trNeg)) ||
198          !(dauQAcuts1.IsSelected(trPos) && dauQAcuts2.IsSelected(trPos))  ) continue;
199
200       AliKFVertex v0vtx = *v;
201       if(fMotherPdg==22) candidate.SetGammaTracks(trNeg, 11, trPos, 11);
202       else candidate.SetTracks(trNeg, (trNeg->Charge()<0?fNegPdg:fPosPdg), trPos, (trPos->Charge()<0?fNegPdg:fPosPdg));
203       candidate.SetProductionVertex(v0vtx);
204
205       if(AliDielectronVarCuts::IsSelected(&candidate)) {
206         nV0s++;
207         //printf(" gamma found for vtx %p dau1id %d dau2id %d \n",v,trNeg->GetID(),trPos->GetID());
208         fV0TrackArr.SetBitNumber(trNeg->GetID());
209         fV0TrackArr.SetBitNumber(trPos->GetID());
210       }
211     }
212     //printf("there are %d V0s in the event \n",nV0stored);
213   }
214   else
215     return;
216
217   //  printf(" Number of V0s candiates found %d \n",nV0s);
218
219 }
220 //________________________________________________________________________
221 Bool_t AliDielectronV0Cuts::IsSelected(TObject* track)
222 {
223   //
224   // Make cut decision
225   //
226
227   if(!track) return kFALSE;
228
229   AliVTrack *vtrack = static_cast<AliVTrack*>(track);
230   InitEvent(vtrack);
231   //printf(" track ID %d selected result %d %d \n",vtrack->GetID(),(fV0TrackArr.TestBitNumber(vtrack->GetID())),fExcludeTracks);
232   return ( (fV0TrackArr.TestBitNumber(vtrack->GetID()))^fExcludeTracks );
233 }
234
235 //________________________________________________________________________
236 Bool_t AliDielectronV0Cuts::IsNewEvent(const AliVEvent *ev)
237 {
238   //
239   // check weather we process a new event
240   //
241
242   //  printf(" current ev %d %d %d \n",fBunchCross, fOrbit, fPeriod);
243   //  printf(" new event %p %d %d %d \n",ev, ev->GetBunchCrossNumber(), ev->GetOrbitNumber(), ev->GetPeriodNumber());
244
245   if( fBunchCross == ev->GetBunchCrossNumber() ) {
246     if( fOrbit == ev->GetOrbitNumber() )         {
247       if( fPeriod == ev->GetPeriodNumber() )     {
248         return kFALSE;
249       }
250     }
251   }
252
253   fBunchCross = ev->GetBunchCrossNumber();
254   fOrbit      = ev->GetOrbitNumber();
255   fPeriod     = ev->GetPeriodNumber();
256   return kTRUE;
257 }