]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/Correlations/DPhi/DiHadronPID/AliTrackDiHadronPID.cxx
DiHadronPID task update (Misha.Veldhoen@cern.ch)
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / DiHadronPID / AliTrackDiHadronPID.cxx
1 // -------------------------------------------------------------------------
2 // Copies all info that is needed for the DiHadronPID analysis.
3 // Possible Extension: At this moment the object is protected for returning
4 // pointers to the original tracks. It could at some point be beneficial to
5 // be able to access this information.
6 // -------------------------------------------------------------------------
7 // Author: Misha Veldhoen (misha.veldhoen@cern.ch)
8
9 #include <iostream>
10 using namespace std;
11
12 // AOD includes.
13 #include "AliAODTrack.h"
14 #include "AliAODEvent.h"
15 #include "AliAODVertex.h"
16 #include "AliAODMCParticle.h"
17
18 // PID includes.
19 #include "AliPID.h"
20 #include "AliPIDResponse.h"
21 #include "AliTPCPIDResponse.h"
22
23 // Objects own include.
24 #include "AliTrackDiHadronPID.h"
25
26 ClassImp(AliTrackDiHadronPID);
27
28 // -------------------------------------------------------------------------
29 AliTrackDiHadronPID::AliTrackDiHadronPID():
30         TObject(),
31         fAODTrack(0x0),
32         fAODGlobalTrack(0x0),
33         fAODEvent(0x0),
34         fAODMCParticle(0x0),
35         fPIDResponse(0x0),
36         fBasicInfoAvailable(kFALSE),
37         fFlagsAvailable(kFALSE),
38         fDCAInfoAvailable(kFALSE),
39         fITSInfoAvailable(kFALSE),
40         fTPCInfoAvailable(kFALSE),
41         fTOFInfoAvailable(kFALSE),
42         fMCInfoAvailable(kFALSE),
43         fPt(-999.),
44         fEta(-999.),
45         fPhi(-999.),
46         fFlags(0),
47         fFilterMap(0),
48         fID(0),
49         fLabel(0),
50         fCharge(0),
51         fDCAz(-999.),
52         fDCAxy(-999.),
53         fTOFsignal(-999.),
54         fIsTOFmismatch(kFALSE),
55         fTPCsignal(-999.),
56         fTPCmomentum(-999.),
57         fMCPt(-999.),
58         fMCEta(-999.),
59         fMCPhi(-999.),
60         fMCY(-999.),
61         fPdgCode(0),
62         fIsPhysicalPrimary(kFALSE),
63         fIsSecondaryFromWeakDecay(kFALSE),
64         fIsSecondaryFromMaterial(kFALSE),
65         fDebug(0)
66
67 {
68
69         //
70         // Default Constructor.
71         //
72
73         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
74
75         for (Int_t iSpecies = 0; iSpecies < 3; iSpecies++) {
76                 fTOFsignalMinusExpected[iSpecies] = -999.;
77                 fTOFNsigma[iSpecies] = -999.;
78                 fTPCsignalMinusExpected[iSpecies] = -999.;
79                 fTPCNsigma[iSpecies] = -999.;
80                 fY[iSpecies] = -999.;
81         }
82
83         for (Int_t iITSlayer = 0; iITSlayer < 6; iITSlayer++) {
84                 fITSHits[iITSlayer] = kFALSE;
85         }
86
87 }
88
89 // -------------------------------------------------------------------------
90 AliTrackDiHadronPID::AliTrackDiHadronPID(AliAODTrack* track, AliAODTrack* globaltrack, AliAODMCParticle* mcparticle, AliPIDResponse* pidresponse):
91         TObject(),
92         fAODTrack(0x0),
93         fAODGlobalTrack(0x0),
94         fAODEvent(0x0),
95         fAODMCParticle(0x0),
96         fPIDResponse(0x0),
97         fBasicInfoAvailable(kFALSE),
98         fFlagsAvailable(kFALSE),
99         fDCAInfoAvailable(kFALSE),
100         fITSInfoAvailable(kFALSE),
101         fTPCInfoAvailable(kFALSE),
102         fTOFInfoAvailable(kFALSE),
103         fMCInfoAvailable(kFALSE),
104         fPt(-999.),
105         fEta(-999.),
106         fPhi(-999.),
107         fFlags(0),
108         fFilterMap(0),
109         fID(0),
110         fLabel(0),
111         fCharge(0),
112         fDCAz(-999.),
113         fDCAxy(-999.),
114         fTOFsignal(-999.),
115         fIsTOFmismatch(kFALSE),
116         fTPCsignal(-999.),
117         fTPCmomentum(-999.),
118         fMCPt(-999.),
119         fMCEta(-999.),
120         fMCPhi(-999.),
121         fMCY(-999.),    
122         fPdgCode(0),
123         fIsPhysicalPrimary(kFALSE),
124         fIsSecondaryFromWeakDecay(kFALSE),
125         fIsSecondaryFromMaterial(kFALSE),
126         fDebug(0)
127 {
128
129         //
130         // Constructor.
131         //
132
133         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
134
135         for (Int_t iSpecies = 0; iSpecies < 3; iSpecies++) {
136                 fTOFsignalMinusExpected[iSpecies] = -999.;
137                 fTOFNsigma[iSpecies] = -999.;
138                 fTPCsignalMinusExpected[iSpecies] = -999.;
139                 fTPCNsigma[iSpecies] = -999.;
140                 fY[iSpecies] = -999.;   
141         }
142
143         for (Int_t iITSlayer = 0; iITSlayer < 6; iITSlayer++) {
144                 fITSHits[iITSlayer] = kFALSE;
145         }
146
147         if (track) {
148                 fAODTrack = track;
149                 fAODEvent = track->GetAODEvent();
150         }
151         if (globaltrack) fAODGlobalTrack = globaltrack;
152         if (mcparticle) fAODMCParticle = mcparticle;
153         if (pidresponse) fPIDResponse = pidresponse;
154
155         // Copy AOD Track info.
156         if (fAODTrack) {
157                 CopyBasicTrackInfo();
158         } else {
159                 AliError("No Track Supplied.");
160         }
161
162         // Find the Global Track.
163         if (fID >= 0) fAODGlobalTrack = fAODTrack;
164
165         // Copy DCA and PID info.
166         if (fAODGlobalTrack) {
167                 CopyFlags();
168                 if (fAODEvent) CopyDCAInfo();
169                 else AliError("Couln't find AOD Event.");
170                 CopyITSInfo();
171                 if (fPIDResponse) CopyTPCInfo();
172                 CopyTOFInfo();
173         } else {
174                 AliError("Couldn't find Global Track.");
175         } 
176
177         // Copy MC info.
178         if (fAODMCParticle) {
179                 CopyMCInfo();
180         } 
181
182         // Test 
183         /*      Double_t sigmaTOFProton = TMath::Abs(fPIDResponse->NumberOfSigmasTOF(fAODTrack, AliPID::kProton));
184                 if ( sigmaTOFProton < 1.0) {cout<<"tofsigmabelowone: "<<sigmaTOFProton<<endl;}
185         
186                 Double_t sigmaTPCProton = TMath::Abs(fPIDResponse->NumberOfSigmasTPC(fAODTrack, AliPID::kProton));
187                 if ( sigmaTPCProton < 1.0) {cout<<"tpcsigmabelowone: "<<sigmaTPCProton<<endl;}*/
188 }
189
190 // -------------------------------------------------------------------------
191 Bool_t AliTrackDiHadronPID::CopyBasicTrackInfo() {
192
193         //
194         // Copies everything available in every AOD track.
195         //
196
197         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
198
199         fPt = fAODTrack->Pt();
200         fEta = fAODTrack->Eta();
201         fPhi = fAODTrack->Phi();
202
203         fY[0] = fAODTrack->Y(AliAODTrack::kPion);
204         fY[1] = fAODTrack->Y(AliAODTrack::kKaon);
205         fY[2] = fAODTrack->Y(AliAODTrack::kProton);
206
207         //fFlags = fAODTrack->GetFlags(); // FLAGS MUST BE TAKEN FROM GLOBAL TRACKS.
208         fFilterMap = fAODTrack->GetFilterMap();
209
210         fID = fAODTrack->GetID();
211         fLabel = fAODTrack->GetLabel();
212
213         fCharge = fAODTrack->Charge();
214
215         fBasicInfoAvailable = kTRUE;
216         return fBasicInfoAvailable;
217
218 }
219
220 // -------------------------------------------------------------------------
221 Bool_t AliTrackDiHadronPID::CopyFlags() {
222
223         //
224         // Copies Flags (properly stored in global track)
225         //
226
227         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
228
229         // Copy Flags
230         fFlags = fAODGlobalTrack->GetFlags();
231
232         // Is TOF mismatch?
233         if (AliAODTrack::kTOFmismatch&fFlags) {
234                 fIsTOFmismatch = kTRUE;
235                 //cout<<"Found TOF mismatch!"<<endl;
236         }
237         else fIsTOFmismatch = kFALSE; 
238
239         fFlagsAvailable = kTRUE;
240         return fFlagsAvailable;
241
242 }
243
244 // -------------------------------------------------------------------------
245 Bool_t AliTrackDiHadronPID::CopyDCAInfo() {
246
247         //
248         // Copies DCA info. (only stored in a global track)
249         //
250
251         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
252
253         // Propagate track to DCA.
254         Double_t PosAtDCA[2] = {-999,-999};
255     Double_t covar[3] = {-999,-999,-999};
256     //cout<<fAODTrack<<" "<<fAODGlobalTrack<<endl;
257     Bool_t propagate = fAODGlobalTrack->PropagateToDCA(fAODEvent->GetPrimaryVertex(),fAODEvent->GetMagneticField(),100.,PosAtDCA,covar);
258         
259     if (propagate) {
260         fDCAxy = PosAtDCA[0];
261         fDCAz = PosAtDCA[1];
262     } else {
263         //AliError("Could not propagate track to DCA.");
264     }
265
266     if (propagate) fDCAInfoAvailable = kTRUE;
267     return fDCAInfoAvailable;
268
269 }
270
271 // -------------------------------------------------------------------------
272 Bool_t AliTrackDiHadronPID::CopyITSInfo() {
273
274         //
275         // Copies ITS info.
276         //
277
278         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
279
280     // Get the ITS clustermap
281     fITSClusterMap = fAODGlobalTrack->GetITSClusterMap();
282
283     // Copy the ITS hits.
284     for (Int_t iITSlayer = 0; iITSlayer < 6; iITSlayer++) {
285                 fITSHits[iITSlayer] = fAODGlobalTrack->HasPointOnITSLayer(iITSlayer);
286         }
287
288     fITSInfoAvailable = kTRUE;
289     return fITSInfoAvailable;
290
291 }
292
293 // -------------------------------------------------------------------------
294 Bool_t AliTrackDiHadronPID::CopyTPCInfo() {
295
296         //
297         // Copies TPC info. (needs global track and pid response)
298         //
299
300         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}      
301
302     // Get TPC signal.
303     fTPCsignal = fAODGlobalTrack->GetTPCsignal();
304
305     // Compute expected TPC signal under pi/K/p mass assumption.
306     AliTPCPIDResponse& TPCPIDResponse = fPIDResponse->GetTPCResponse();
307     fTPCmomentum = fAODGlobalTrack->GetTPCmomentum();
308
309         fTPCsignalMinusExpected[0] = fTPCsignal - TPCPIDResponse.GetExpectedSignal(fTPCmomentum,AliPID::kPion);
310         fTPCsignalMinusExpected[1] = fTPCsignal - TPCPIDResponse.GetExpectedSignal(fTPCmomentum,AliPID::kKaon);
311         fTPCsignalMinusExpected[2] = fTPCsignal - TPCPIDResponse.GetExpectedSignal(fTPCmomentum,AliPID::kProton);
312
313         fTPCNsigma[0] = fPIDResponse->NumberOfSigmasTPC(fAODGlobalTrack, AliPID::kPion);
314         fTPCNsigma[1] = fPIDResponse->NumberOfSigmasTPC(fAODGlobalTrack, AliPID::kKaon);
315         fTPCNsigma[2] = fPIDResponse->NumberOfSigmasTPC(fAODGlobalTrack, AliPID::kProton);
316
317     fTPCInfoAvailable = kTRUE;
318     return fTPCInfoAvailable;
319
320 }
321
322 // -------------------------------------------------------------------------
323 Bool_t AliTrackDiHadronPID::CopyTOFInfo() {
324
325         //
326         // Copies TOF info. (needs global track)
327         //
328
329         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
330
331     // Get TOF signal.
332     fTOFsignal = fAODGlobalTrack->GetTOFsignal();
333
334     // Compute expected TOF signal under pi/K/p mass assumption.
335     Double_t times[AliPID::kSPECIES];
336     fAODGlobalTrack->GetIntegratedTimes(times);
337     fTOFsignalMinusExpected[0] = fTOFsignal - times[AliPID::kPion];
338         fTOFsignalMinusExpected[1] = fTOFsignal - times[AliPID::kKaon];
339         fTOFsignalMinusExpected[2] = fTOFsignal - times[AliPID::kProton];
340
341         fTOFNsigma[0] = fPIDResponse->NumberOfSigmasTOF(fAODGlobalTrack, AliPID::kPion);
342         fTOFNsigma[1] = fPIDResponse->NumberOfSigmasTOF(fAODGlobalTrack, AliPID::kKaon);
343         fTOFNsigma[2] = fPIDResponse->NumberOfSigmasTOF(fAODGlobalTrack, AliPID::kProton);      
344
345         fTOFInfoAvailable = kTRUE;
346         return fTOFInfoAvailable;
347
348 }
349
350 // -------------------------------------------------------------------------
351 Bool_t AliTrackDiHadronPID::CopyMCInfo() {
352
353         // Copies MC info (needs an MC track with the same label)
354
355         // Check if the label of the current track matches the label of the
356         // generated particle. Note that the label of the AOD track can be
357         // negative. This means that the quality of this track is not awesome,
358         // but that it does correspond to the MC particle.
359
360         if (fDebug) {cout << Form("File: %s, Line: %i, Function: %s",__FILE__,__LINE__,__func__) << endl;}
361         
362         /*
363         if (fAODMCParticle->Label() != TMath::Abs(fAODTrack->GetLabel())) {
364                 cout<<"Label of supplied MC particle and reconstructed track do not match."<<endl;      
365                 return kFALSE;
366         }
367         */
368         // Note: It seems like the Label of the AOD track points to the INDEX of the
369         // MCPArticle, not to the label (See AliAnalysisTaskCompareAODTrackCuts.cxx)
370
371         fMCPt = fAODMCParticle->Pt();
372         fMCEta = fAODMCParticle->Eta();
373         fMCPhi = fAODMCParticle->Phi();
374         fMCY = fAODMCParticle->Y();
375         fPdgCode = fAODMCParticle->PdgCode();
376
377         TClonesArray* mcArray = 0x0;
378         mcArray = dynamic_cast<TClonesArray*>(fAODEvent->FindListObject(AliAODMCParticle::StdBranchName()));
379         if (!mcArray) {
380         AliFatal("No MC array found in the AOD.");
381     }
382
383         // Primary particle
384         if ( fAODMCParticle->IsPhysicalPrimary() ){
385                 fIsPhysicalPrimary = kTRUE;
386         } else {
387                 // Safety check for mother existence.
388                 if (fAODMCParticle->GetMother() >= 0){
389
390                         Int_t mcMotherPDG = -999;
391                         Int_t firstInt = -999;
392
393                         AliAODMCParticle* mcMother = (AliAODMCParticle*) mcArray->At(TMath::Abs(fAODMCParticle->GetMother()));
394                         mcMotherPDG = TMath::Abs(mcMother->GetPdgCode());
395
396                         // Need a way to get the first intiger, for now Marek's method:
397                         firstInt = Int_t (mcMotherPDG/ TMath::Power(10, Int_t(TMath::Log10(mcMotherPDG))));
398                         // cout<<"Mother PDG: "<<mcMotherPDG<<"; Firt integer: "<<firstInt<<endl;
399
400                         // Weak decay
401                         if( firstInt == 3){
402                                 fIsSecondaryFromWeakDecay = kTRUE;
403                         // Material decay
404                         } else {
405                                 fIsSecondaryFromMaterial = kTRUE;
406                         }
407                 }
408         }
409
410         fMCInfoAvailable = kTRUE;
411         return fMCInfoAvailable;
412
413 }