]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliHFEpidTOF.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEpidTOF.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 // Class for TOF PID
17 // Implements the abstract base class AliHFEpidBase
18 // IsInitialized() does the PID decision
19 // 
20 // Authors:
21 //   Markus Fasel  <M.Fasel@gsi.de>
22 //   Matus Kalisky <matus.kalisky@cern.ch>  (contact)
23 //
24
25 #include <TMath.h>
26
27 #include "AliAODTrack.h"
28 #include "AliESDtrack.h"
29 #include "AliPID.h"
30 #include "AliPIDResponse.h"
31 #include "AliTOFPIDResponse.h"
32
33 #include "AliHFEdetPIDqa.h"
34 #include "AliHFEpidTOF.h"
35 #include "AliHFEpidQAmanager.h"
36
37
38 ClassImp(AliHFEpidTOF)
39
40 //___________________________________________________________________
41 AliHFEpidTOF::AliHFEpidTOF():
42   AliHFEpidBase()
43   , fNsigmaTOF(3)
44   , fUseOnlyIfAvailable(kFALSE)
45   , fRejectMismatch(kFALSE)
46   , fGenerateTOFmismatch(kFALSE)
47   , fNmismatchTracks(0)
48 {
49   //
50   // Constructor
51   //
52   
53   memset(fSigmaBordersTOFLower, 0, sizeof(Float_t) * 12);
54   memset(fSigmaBordersTOFUpper, 0, sizeof(Float_t) * 12);
55
56
57 //___________________________________________________________________
58 AliHFEpidTOF::AliHFEpidTOF(const Char_t *name):
59   AliHFEpidBase(name)
60   , fNsigmaTOF(3)
61   , fUseOnlyIfAvailable(kFALSE)
62   , fRejectMismatch(kFALSE)
63   , fGenerateTOFmismatch(kFALSE)
64   , fNmismatchTracks(0)
65 {
66   //
67   // Constructor
68   //
69   memset(fSigmaBordersTOFLower, 0, sizeof(Float_t) * 12);
70   memset(fSigmaBordersTOFUpper, 0, sizeof(Float_t) * 12);
71
72 }
73
74 //___________________________________________________________________
75 AliHFEpidTOF::AliHFEpidTOF(const AliHFEpidTOF &c):
76   AliHFEpidBase("")
77   , fNsigmaTOF(3)
78   , fUseOnlyIfAvailable(kFALSE)
79   , fRejectMismatch(kFALSE)
80   , fGenerateTOFmismatch(c.fGenerateTOFmismatch)
81   , fNmismatchTracks(c.fNmismatchTracks)
82 {  
83   // 
84   // Copy operator
85   //
86
87   c.Copy(*this);
88 }
89 //___________________________________________________________________
90 AliHFEpidTOF &AliHFEpidTOF::operator=(const AliHFEpidTOF &ref){
91   //
92   // Assignment operator
93   //
94
95   if(this != &ref){
96     ref.Copy(*this);
97   }
98
99   return *this;
100 }
101 //___________________________________________________________________
102 AliHFEpidTOF::~AliHFEpidTOF(){
103   //
104   // Destructor
105   //
106 }
107 //___________________________________________________________________
108 void AliHFEpidTOF::Copy(TObject &ref) const {
109   //
110   // Performs the copying of the object
111   //
112   AliHFEpidTOF &target = dynamic_cast<AliHFEpidTOF &>(ref);
113
114   target.fNsigmaTOF = fNsigmaTOF;
115   target.fUseOnlyIfAvailable = fUseOnlyIfAvailable;
116   target.fRejectMismatch = fRejectMismatch;
117   target.fGenerateTOFmismatch = fGenerateTOFmismatch;
118   target.fNmismatchTracks = fNmismatchTracks;
119   memcpy(target.fSigmaBordersTOFLower, fSigmaBordersTOFLower, sizeof(Float_t) * 12);
120   memcpy(target.fSigmaBordersTOFUpper, fSigmaBordersTOFUpper, sizeof(Float_t) * 12);
121
122   AliHFEpidBase::Copy(ref);
123 }
124 //___________________________________________________________________
125 Bool_t AliHFEpidTOF::InitializePID(Int_t /*run*/){
126   //
127   // InitializePID: TOF experts have to implement code here
128   //
129   return kTRUE;
130 }
131
132 //___________________________________________________________________
133 Int_t AliHFEpidTOF::IsSelected(const AliHFEpidObject *track, AliHFEpidQAmanager *pidqa) const
134 {
135   //
136   // TOF PID based on n-Sigma cut
137   // Selects Protons and Kaons via n-sigma cut up to 3 GeV/c
138   // In addition histos for n-sigma before (all species) and after (only closest species) are filled
139   //
140   if(!fkPIDResponse) return 0;
141   AliDebug(2, "PID object available");
142
143   const AliVTrack *vtrack = dynamic_cast<const AliVTrack *>(track->GetRecTrack());
144   if(!vtrack) return 0;
145   Bool_t hasTOFpid = vtrack->GetStatus() & AliESDtrack::kTOFpid;
146   if(fUseOnlyIfAvailable && !hasTOFpid){
147     AliDebug(2, "No TOF PID, but PID required only if available");
148     return 11;   
149   } else if(!hasTOFpid){
150     AliDebug(2, "No TOF PID, and TOF PID is required always");
151     return 0;
152   }
153   AliDebug(2, "Track Has TOF PID");
154
155   if(fRejectMismatch){
156     if(IsMismatch(vtrack)) return 0;
157   }
158
159   if(pidqa) pidqa->ProcessTrack(track, AliHFEpid::kTOFpid, AliHFEdetPIDqa::kBeforePID);
160
161   // Fill before selection
162   Double_t sigEle = fkPIDResponse->NumberOfSigmasTOF(track->GetRecTrack(), AliPID::kElectron);
163   AliDebug(2, Form("Number of sigmas in TOF: %f", sigEle));
164   Int_t pdg = 0;
165   if(TestBit(kSigmaBand)){
166     Int_t centrality = track->IsPbPb() ? track->GetCentrality() + 1 : 0;
167     AliDebug(2, Form("Centrality: %d\n", centrality));
168     if(centrality > 11) return kFALSE;
169     if(sigEle > fSigmaBordersTOFLower[centrality] && sigEle < fSigmaBordersTOFUpper[centrality]) pdg = 11;
170   } else {
171     // Fixed nsigma cut
172     if(TMath::Abs(sigEle) < fNsigmaTOF) pdg = 11;
173   }
174
175   if(pdg == 11 && pidqa) pidqa->ProcessTrack(track, AliHFEpid::kTOFpid, AliHFEdetPIDqa::kAfterPID);
176  
177   return pdg;
178 }
179 //___________________________________________________________________
180 void AliHFEpidTOF::SetTOFnSigmaBand(Float_t lower, Float_t upper)
181 {
182   //
183   // Lower and higher cut independant of the centrality
184   //
185
186   for(Int_t k=0; k < 12; k++) {
187     fSigmaBordersTOFLower[k] = lower;
188     fSigmaBordersTOFUpper[k] = upper;
189   }
190
191   SetBit(kSigmaBand, kTRUE);
192
193 }
194 //___________________________________________________________________
195 void AliHFEpidTOF::SetTOFnSigmaBandCentrality(Float_t lower, Float_t upper, Int_t centralityBin)
196 {
197   //
198   // Lower and higher cut as function of centrality
199   //
200
201   if(centralityBin < 11) {
202     fSigmaBordersTOFLower[centralityBin+1] = lower;
203     fSigmaBordersTOFUpper[centralityBin+1] = upper;
204   }
205
206   SetBit(kSigmaBand, kTRUE);
207
208 }
209
210 //___________________________________________________________________
211 Bool_t AliHFEpidTOF::IsMismatch(const AliVTrack * const track) const {
212   //
213   // Check for mismatch
214   //
215   if(!fkPIDResponse) return kFALSE;
216   Double_t probs[AliPID::kSPECIESC];
217   AliPIDResponse::EDetPidStatus status = fkPIDResponse->ComputeTOFProbability(track, AliPID::kSPECIESC, probs);
218   return status == AliPIDResponse::kDetMismatch;
219 }
220
221 //___________________________________________________________________
222 void AliHFEpidTOF::GenerateTOFmismatch(const AliVTrack * const trk, int ntrk, TArrayD &sigmaEl){
223   //
224   // Function generate randomised TOF mismatch hits for a given input track. The number of generated
225   // mismatch tracks is steered by the parameter ntrk. For all mismatch tracks the number of sigmas
226   // to the electron time-of-flight hypothesis is calculated, and the resulting numbers of sigmas
227   // are stored in the array sigmaEl for further processing
228   //
229   if(sigmaEl.GetSize() < ntrk) sigmaEl.Set(ntrk);
230   sigmaEl.Reset();
231
232   // work on copy
233   AliVTrack *copytrk(NULL);
234   Bool_t isAOD = kFALSE;
235   if(dynamic_cast<const AliESDtrack *>(trk)){
236     copytrk = new AliESDtrack(*(static_cast<const AliESDtrack *>(trk)));
237   } else {
238     copytrk = new AliAODTrack(*(static_cast<const AliAODTrack *>(trk)));
239     isAOD = kTRUE;
240   }
241
242   // Generate mismatch values for number of sigmas to the electron hypothesis and store then in the 
243   // output array
244   for(int itrk = 0; itrk < ntrk; itrk++){
245     Double_t tofsignal = AliTOFPIDResponse::GetMismatchRandomValue(copytrk->Eta());
246     if(isAOD){
247       AliAODTrack *aodtrk = static_cast<AliAODTrack *>(copytrk);
248       AliAODPid *aodpid = aodtrk->GetDetPid();
249       if(aodpid) aodpid->SetTOFsignal(tofsignal);
250     } else {
251       AliESDtrack *esdtrk = static_cast<AliESDtrack *>(copytrk);
252       esdtrk->SetTOFsignal(tofsignal);
253     }
254     sigmaEl[itrk] = fkPIDResponse->NumberOfSigmasTOF(copytrk, AliPID::kElectron);
255   }
256   delete copytrk;
257 }