]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSdEdxSamples.cxx
Possibility of switching on/off tracklets to tracks references (Ruben)
[u/mrichter/AliRoot.git] / ITS / AliITSdEdxSamples.cxx
CommitLineData
9189f38b 1/**************************************************************************
2 * Copyright(c) 2009-2012, 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/* $Id$ */
16
17
18
19///////////////////////////////////////////////////////////////////
20// //
21// Class to store information for PID with ITS //
22// and truncated mean computation methods //
23// Origin: F.Prino, Torino, prino@to.infn.it //
24// //
25///////////////////////////////////////////////////////////////////
26
27#include "AliITSPidParams.h"
28#include "AliITSdEdxSamples.h"
29#include "AliLog.h"
30#include <TMath.h>
31
32ClassImp(AliITSdEdxSamples)
33
34//______________________________________________________________________
35AliITSdEdxSamples::AliITSdEdxSamples():TObject(),
36 fNSamples(0),
0d66557a 37 fClusterMap(0),
9189f38b 38 fP(0.),
0d66557a 39 fParticleSpecie(0),
40 fLayersForPid(0xFFFF)
9189f38b 41{
42 // Default constructor
92329a66 43 for(Int_t i=0; i<kMaxSamples; i++){
44 fdESamples[i]=0.;
45 fdxSamples[i]=0.;
cb0a52e0 46 fPAtSample[i]=0.;
47 }
9189f38b 48}
49
50//______________________________________________________________________
92329a66 51AliITSdEdxSamples::AliITSdEdxSamples(Int_t nSamples, Double_t* esamples, Double_t* xsamples, Double_t mom, Int_t specie) :
9189f38b 52 TObject(),
53 fNSamples(nSamples),
0d66557a 54 fClusterMap(0),
9189f38b 55 fP(mom),
0d66557a 56 fParticleSpecie(specie),
57 fLayersForPid(0xFFFF)
9189f38b 58{
59 // Standard constructor
92329a66 60 SetdESamples(nSamples,esamples);
61 SetdxSamples(nSamples,xsamples);
0d66557a 62 SetClusterMapFromdE();
92329a66 63}
64
65//______________________________________________________________________
66AliITSdEdxSamples::AliITSdEdxSamples(const AliITSdEdxSamples& source) :
67 TObject(),
68 fNSamples(source.fNSamples),
0d66557a 69 fClusterMap(source.fClusterMap),
92329a66 70 fP(source.fP),
0d66557a 71 fParticleSpecie(source.fParticleSpecie),
72 fLayersForPid(source.fLayersForPid)
92329a66 73{
74 // Copy constructor
8d91dc44 75 for(Int_t i=0; i<kMaxSamples; i++){
92329a66 76 fdESamples[i]=source.GetdESample(i);
77 fdxSamples[i]=source.GetdxSample(i);
78 fPAtSample[i]=source.GetMomentumAtSample(i);
79 }
9189f38b 80}
accb90b5 81//_____________________________________________________________________________
82AliITSdEdxSamples& AliITSdEdxSamples::operator=(const AliITSdEdxSamples &source){
83 // Assignment operator
84 if(this==&source) return *this;
85 ((TObject *)this)->operator=(source);
86 fNSamples = source.fNSamples;
87 fClusterMap = source.fClusterMap;
88 fP = source.fP;
89 fParticleSpecie = source.fParticleSpecie;
90 fLayersForPid = source.fLayersForPid;
91 for(Int_t i=0; i<kMaxSamples; i++){
92 fdESamples[i]=source.GetdESample(i);
93 fdxSamples[i]=source.GetdxSample(i);
94 fPAtSample[i]=source.GetMomentumAtSample(i);
95 }
96}
97
9189f38b 98//______________________________________________________________________
92329a66 99void AliITSdEdxSamples::SetdESamples(Int_t nSamples, Double_t* samples){
9189f38b 100 // Set the samples
101
92329a66 102 if(nSamples>kMaxSamples){
103 AliWarning(Form("Too many dE samples,only first %d will be used",kMaxSamples));
104 fNSamples=kMaxSamples;
9189f38b 105 }else{
106 fNSamples=nSamples;
107 }
92329a66 108 for(Int_t i=0; i<fNSamples; i++) fdESamples[i]=samples[i];
109 for(Int_t i=fNSamples; i<kMaxSamples; i++) fdESamples[i]=0.;
9189f38b 110 return;
111}
112//______________________________________________________________________
92329a66 113void AliITSdEdxSamples::SetdxSamples(Int_t nSamples, Double_t* samples){
9189f38b 114 // Set the samples
92329a66 115
116 if(nSamples>kMaxSamples){
13242232 117 AliWarning(Form("Too many dx samples,only first %d will be used",kMaxSamples));
92329a66 118 fNSamples=kMaxSamples;
119 }else{
120 fNSamples=nSamples;
121 }
122 for(Int_t i=0; i<fNSamples; i++) fdxSamples[i]=samples[i];
123 for(Int_t i=fNSamples; i<kMaxSamples; i++) fdxSamples[i]=0.;
124 return;
125}
126
127//______________________________________________________________________
128void AliITSdEdxSamples::SetSamplesAndMomenta(Int_t nSamples, Double_t* esamples, Double_t* xsamples, Double_t* mom){
129 // Set the samples
130 SetdESamples(nSamples,esamples);
131 SetdxSamples(nSamples,xsamples);
9189f38b 132 for(Int_t i=0; i<fNSamples; i++) fPAtSample[i]=mom[i];
92329a66 133 for(Int_t i=fNSamples; i<kMaxSamples; i++) fPAtSample[i]=0.;
9189f38b 134 return;
135}
136//______________________________________________________________________
0d66557a 137void AliITSdEdxSamples::SetLayerSample(Int_t iLayer, Bool_t haspoint, Double_t dE, Double_t dx, Double_t p){
138 // set info from single layer
139 if(haspoint){
140 SetPointOnLayer(iLayer);
141 fdESamples[iLayer]=dE;
142 fdxSamples[iLayer]=dx;
143 fPAtSample[iLayer]=p;
144 }else{
145 if(HasPointOnLayer(iLayer)) fClusterMap-=(1<<iLayer);
146 fdESamples[iLayer]=0.;
147 fdxSamples[iLayer]=0.;
148 fPAtSample[iLayer]=0.;
149
150 }
151}
152//______________________________________________________________________
9189f38b 153Double_t AliITSdEdxSamples::GetTruncatedMean(Double_t frac, Double_t mindedx) const {
154 // compute truncated mean
155
156 Int_t nc=0;
92329a66 157 Double_t dedx[kMaxSamples];
9189f38b 158 for (Int_t il=0; il<fNSamples; il++) { // count good (>0) dE/dx values
92329a66 159 Double_t dedxsamp=GetdEdxSample(il);
0d66557a 160 if(HasPointOnLayer(il) && UseLayerForPid(il) && dedxsamp>mindedx){
92329a66 161 dedx[nc]= dedxsamp;
9189f38b 162 nc++;
92329a66 163 }
9189f38b 164 }
165 if(nc<1) return 0.;
0d66557a 166
9189f38b 167 Int_t swap; // sort in ascending order
168 do {
169 swap=0;
170 for (Int_t i=0; i<nc-1; i++) {
171 if (dedx[i]<=dedx[i+1]) continue;
172 Double_t tmp=dedx[i];
173 dedx[i]=dedx[i+1];
174 dedx[i+1]=tmp;
175 swap++;
176 }
177 } while (swap);
178
179 Double_t sumamp=0,sumweight=0;
92329a66 180 Double_t weight[kMaxSamples];
181 for(Int_t iw=0; iw<kMaxSamples; iw++) weight[iw]=0.;
9189f38b 182 Int_t lastUsed=(Int_t)(frac*nc+0.00001);
183 if(lastUsed==0) lastUsed=1;
92329a66 184 if(lastUsed>kMaxSamples) lastUsed=kMaxSamples;
9189f38b 185 for(Int_t iw=0; iw<lastUsed; iw++) weight[iw]=1.;
92329a66 186 if((frac*nc-lastUsed)>0.4 && lastUsed<kMaxSamples) weight[lastUsed]=0.5;
9189f38b 187 for (Int_t i=0; i<nc; i++) {
92329a66 188 // AliDebug(5,Form("dE/dx %f weight %f",dedx[i],weight[i]));
9189f38b 189 sumamp+= dedx[i]*weight[i];
190 sumweight+=weight[i];
191 }
192 if(sumweight>0.) return sumamp/sumweight;
193 else return 0.;
194
195}
196//______________________________________________________________________
197Double_t AliITSdEdxSamples::GetWeightedMean(Double_t mindedx) const {
198 // compute generalized mean with k=-2 (used by CMS)
9189f38b 199 Int_t nc=0;
92329a66 200 Double_t dedx[kMaxSamples];
9189f38b 201 for (Int_t il=0; il<fNSamples; il++) { // count good (>0) dE/dx values
92329a66 202 Double_t dedxsamp=GetdEdxSample(il);
0d66557a 203 if(HasPointOnLayer(il) && UseLayerForPid(il) && dedxsamp>mindedx){
92329a66 204 dedx[nc]= dedxsamp;
205 nc++;
9189f38b 206 }
207 }
208 if(nc<1) return 0.;
209
210 Double_t weiSum = 0.;
211 for (Int_t i=0; i<nc; i++) {
212 weiSum+=TMath::Power(dedx[i],-2);
213 }
214 Double_t wMean=0.;
215 if(weiSum>0.) wMean= TMath::Power(weiSum/nc,-0.5);
216 return wMean;
217
218}
219//______________________________________________________________________
220void AliITSdEdxSamples::GetConditionalProbabilities(AliITSPidParams* pars, Double_t condprob[AliPID::kSPECIES], Double_t mindedx) const {
221 // compute conditional probablilities
222 const Int_t nPart = 3;
223 Double_t itsProb[nPart] = {1,1,1}; // p, K, pi
224
225 for(Int_t iS=0; iS<fNSamples; iS++){
0d66557a 226 if(!HasPointOnLayer(iS)) continue;
227 if(!UseLayerForPid(iS)) continue;
9189f38b 228 Int_t iLayer=iS+3; // to match with present ITS
229 if(iLayer>6) iLayer=6; // all extra points are treated as SSD
92329a66 230 Float_t dedx = GetdEdxSample(iS);
231 if(dedx<mindedx) continue;
9189f38b 232 Float_t layProb = pars->GetLandauGausNorm(dedx,AliPID::kProton,fP,iLayer);
233 itsProb[0] *= layProb;
234
235 layProb = pars->GetLandauGausNorm(dedx,AliPID::kKaon,fP,iLayer);
236 if (fP < 0.16) layProb=0.00001;
237 itsProb[1] *= layProb;
238
239 layProb = pars->GetLandauGausNorm(dedx,AliPID::kPion,fP,iLayer);
240 itsProb[2] *= layProb;
241 }
242
243 // Normalise probabilities
244 Double_t sumProb = 0;
245 for (Int_t iPart = 0; iPart < nPart; iPart++) {
246 sumProb += itsProb[iPart];
247 }
248 sumProb += 2*itsProb[2]; // muon and electron cannot be distinguished from pions
249
250 for (Int_t iPart = 0; iPart < nPart; iPart++) {
251 itsProb[iPart]/=sumProb;
252 }
253
254 condprob[AliPID::kElectron] = itsProb[2];
255 condprob[AliPID::kMuon] = itsProb[2];
256 condprob[AliPID::kPion] = itsProb[2];
257 condprob[AliPID::kKaon] = itsProb[1];
258 condprob[AliPID::kProton] = itsProb[0];
259 return;
260
261}
0d66557a 262//______________________________________________________________________
263void AliITSdEdxSamples::PrintAll() const{
264 // print all the infos
265 printf("Particle %d momentum %f GeV/c, number of points %d\n",
266 GetParticleSpecieMC(),
267 fP,
268 GetNumberOfEffectiveSamples());
269 for(Int_t iLay=0; iLay<fNSamples; iLay++){
270 printf(" Layer %d Point %d dE %f keV dx %f cm mom %f GeV/c\n",iLay,
271 HasPointOnLayer(iLay),
272 GetdESample(iLay),
273 GetdxSample(iLay),
274 GetMomentumAtSample(iLay));
275 }
276
277 printf("Layers used for PID:\n");
278 printf("Layer ");
279 for(Int_t iLay=0; iLay<fNSamples; iLay++){
280 printf("%d ",iLay);
281 }
282 printf("\n");
283
284 printf("Use ");
285 for(Int_t iLay=0; iLay<fNSamples; iLay++){
286 printf("%d ",UseLayerForPid(iLay));
287 }
288 printf("\n");
289 printf("Truncated mean = %f\n",GetTruncatedMean());
290}
291//______________________________________________________________________
292void AliITSdEdxSamples::PrintClusterMap() const{
293 // print the cluster map
294
295 printf("Layer ");
296 for(Int_t iLay=0; iLay<fNSamples; iLay++){
297 printf("%d ",iLay);
298 }
299 printf("\n");
300
301 printf("Point ");
302 for(Int_t iLay=0; iLay<fNSamples; iLay++){
303 printf("%d ",HasPointOnLayer(iLay));
304 }
305 printf("\n");
306}