]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AOD/AliAODpidUtil.cxx
https://savannah.cern.ch/bugs/index.php?97149
[u/mrichter/AliRoot.git] / STEER / AOD / AliAODpidUtil.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id: AliAODpidUtil.cxx 38329 2010-01-17 19:17:24Z hristov $ */
17
18 //-----------------------------------------------------------------
19 //           Implementation of the combined PID class
20 //           For the AOD Class
21 //           containing information on the particle identification
22 //      Origin: Rosa Romita, GSI, r.romita@gsi.de
23 //-----------------------------------------------------------------
24
25 #include "TRandom.h"
26 #include "AliLog.h"
27 #include "AliPID.h"
28 #include "AliAODpidUtil.h"
29 #include "AliAODEvent.h"
30 #include "AliAODTrack.h"
31 #include "AliAODPid.h"
32 #include "AliTRDPIDResponse.h"
33 #include "AliESDtrack.h"
34 #include "AliAODMCHeader.h"
35 #include "AliAODMCParticle.h"
36
37 #include <AliDetectorPID.h>
38
39 ClassImp(AliAODpidUtil)
40
41 //_________________________________________________________________________
42 Float_t AliAODpidUtil::GetTPCsignalTunedOnData(const AliVTrack *t) const {
43     AliAODTrack *track = (AliAODTrack *) t;
44     Float_t dedx = track->GetTPCsignalTunedOnData();
45     if(dedx > 0) return dedx;
46
47     Double_t mom = t->GetTPCmomentum();
48
49     dedx = t->GetTPCsignal();
50     track->SetTPCsignalTunedOnData(dedx);
51
52     if(dedx < 20) return dedx;
53
54     
55     AliPID::EParticleType type = AliPID::kPion;
56     
57     AliAODMCHeader *mcHeader = dynamic_cast<AliAODMCHeader*>(track->GetAODEvent()->GetList()->FindObject(AliAODMCHeader::StdBranchName()));
58     if (mcHeader) {
59         TClonesArray *mcArray = (TClonesArray*)track->GetAODEvent()->GetList()->FindObject(AliAODMCParticle::StdBranchName());
60         
61         Bool_t kGood = kTRUE;
62         
63         Int_t iS = TMath::Abs(((AliAODMCParticle*)mcArray->At(TMath::Abs(t->GetLabel())))->GetPdgCode());
64         if(iS==AliPID::ParticleCode(AliPID::kElectron)){
65             type = AliPID::kElectron;
66         }
67         else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
68             type = AliPID::kMuon;
69         }
70         else if(iS==AliPID::ParticleCode(AliPID::kPion)){
71             type = AliPID::kPion;
72         }
73         else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
74             type = AliPID::kKaon;
75         }
76         else if(iS==AliPID::ParticleCode(AliPID::kProton)){
77             type = AliPID::kProton;
78         }
79         else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
80             type = AliPID::kDeuteron;
81         }
82         else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
83             type = AliPID::kTriton;
84         }
85         else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
86             type = AliPID::kHe3;
87         }
88         else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
89             type = AliPID::kAlpha;
90         }
91         else
92             kGood = kFALSE;
93
94         if(kGood){
95             Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
96             Double_t sigma=fTPCResponse.GetExpectedSigma(mom,t->GetTPCsignalN(),type);
97             dedx = gRandom->Gaus(bethe,sigma);
98
99             if(iS == AliPID::ParticleCode(AliPID::kHe3) || iS == AliPID::ParticleCode(AliPID::kAlpha)) dedx *= 5;
100         }
101
102     }
103
104     track->SetTPCsignalTunedOnData(dedx);
105     return dedx;
106 }
107 //_________________________________________________________________________
108 Float_t AliAODpidUtil::NumberOfSigmasTOF(const AliVParticle *vtrack, AliPID::EParticleType type) const
109 {
110   //
111   // Number of sigma implementation for the TOF
112   //
113   
114   AliAODTrack *track=(AliAODTrack*)vtrack;
115
116   // look for cached value first
117   if (track->GetDetectorPID()){
118     return track->GetDetectorPID()->GetNumberOfSigmas(kTOF, type);
119   }  
120   
121   Bool_t oldAod=kTRUE;
122   Double_t sigTOF;
123   AliAODPid *pidObj = track->GetDetPid();
124   if (!pidObj) return -999.;
125   Double_t tofTime=pidObj->GetTOFsignal();
126   Double_t expTime=fTOFResponse.GetExpectedSignal((AliVTrack*)vtrack,type);
127   Double_t sigmaTOFPid[AliPID::kSPECIES];
128   pidObj->GetTOFpidResolution(sigmaTOFPid);
129   AliAODEvent *event=(AliAODEvent*)track->GetAODEvent();
130   if (event) {  // protection if the user didn't call GetTrack, which sets the internal pointer
131     AliTOFHeader* tofH=(AliTOFHeader*)event->GetTOFHeader();
132     if (tofH && (TMath::Abs(sigmaTOFPid[0]) <= 1.E-16) ) { // new AOD
133         sigTOF=fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type)); //fTOFResponse is set in InitialiseEvent
134         tofTime -= fTOFResponse.GetStartTime(vtrack->P());
135         oldAod=kFALSE;
136     }
137   } else {
138     AliError("pointer to AliAODEvent not found, please call GetTrack to set it");
139     return -996.;
140   }
141   if (oldAod) { // old AOD
142     if (type <= AliPID::kProton) {
143       sigTOF=sigmaTOFPid[type];
144     } else return -998.;  // light nuclei cannot be supported on old AOD because we don't have timeZero resolution
145   }
146   if (sigTOF>0) return (tofTime - expTime)/sigTOF;
147   else return -997.;
148 }