]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDpidLQ.cxx
Coding conventions
[u/mrichter/AliRoot.git] / TRD / AliTRDpidLQ.cxx
CommitLineData
16bf9884 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/*
17$Log$
0a29d0f1 18Revision 1.2 2001/11/07 11:04:22 hristov
19Minor corrections needed on Sun (arrays with undefined size created by new, inline decration removed when the body was hot in the header file)
20
a3d851c2 21Revision 1.1 2001/11/06 17:19:41 cblume
22Add detailed geometry and simple simulator
23
16bf9884 24*/
25
26///////////////////////////////////////////////////////////////////////////////
27// //
28// The TRD particle identification class //
29// //
30// Its main purposes are: //
31// - Creation and bookkeeping of the propability distributions //
32// - Assignment of a e/pi propability to a given track based on //
33// the LQ method //
34// //
35///////////////////////////////////////////////////////////////////////////////
36
37#include <stdlib.h>
38#include <math.h>
39
40#include <TROOT.h>
41#include <TH1.h>
42#include <TObjArray.h>
43#include <TTree.h>
44#include <TFile.h>
45#include <TParticle.h>
46
47#include "AliRun.h"
48#include "AliTRD.h"
49#include "AliTRDpidLQ.h"
50#include "AliTRDcluster.h"
51#include "AliTRDtrack.h"
52#include "AliTRDtracker.h"
53#include "AliTRDgeometry.h"
54
55ClassImp(AliTRDpidLQ)
56
57//_____________________________________________________________________________
58AliTRDpidLQ::AliTRDpidLQ():AliTRDpid()
59{
60 //
61 // AliTRDpidLQ default constructor
62 //
63
64 fNMom = 0;
65 fMinMom = 0;
66 fMaxMom = 0;
67 fWidMom = 0;
68
69 fNLh = 0;
70 fMinLh = 0;
71 fMaxLh = 0;
72
73 fHist = NULL;
74
75 fChargeMin = 0;
76 fNClusterMin = 0;
77
78}
79
80//_____________________________________________________________________________
81AliTRDpidLQ::AliTRDpidLQ(const char* name, const char* title)
82 :AliTRDpid(name,title)
83{
84 //
85 // AliTRDpidLQ constructor
86 //
87
88 fNMom = 0;
89 fMinMom = 0;
90 fMaxMom = 0;
91 fWidMom = 0;
92
93 fNLh = 0;
94 fMinLh = 0;
95 fMaxLh = 0;
96
97 fHist = NULL;
98
99 Init();
100
101}
102
103//_____________________________________________________________________________
104AliTRDpidLQ::AliTRDpidLQ(const AliTRDpidLQ &p)
105{
106 //
107 // AliTRDpidLQ copy constructor
108 //
109
110 ((AliTRDpidLQ &) p).Copy(*this);
111
112}
113
114//_____________________________________________________________________________
115AliTRDpidLQ::~AliTRDpidLQ()
116{
117 //
118 // AliTRDpidLQ destructor
119 //
120
121 if (fHist) {
122 fHist->Delete();
123 delete fHist;
124 }
125
126}
127
128//_____________________________________________________________________________
129AliTRDpidLQ &AliTRDpidLQ::operator=(const AliTRDpidLQ &p)
130{
131 //
132 // Assignment operator
133 //
134
135 if (this != &p) ((AliTRDpidLQ &) p).Copy(*this);
136 return *this;
137
138}
139
140//_____________________________________________________________________________
141void AliTRDpidLQ::Copy(TObject &p)
142{
143 //
144 // Copy function
145 //
146
147 fHist->Copy(*((AliTRDpidLQ &) p).fHist);
148
149 ((AliTRDpidLQ &) p).fNMom = fNMom;
150 ((AliTRDpidLQ &) p).fMinMom = fMinMom;
151 ((AliTRDpidLQ &) p).fMaxMom = fMaxMom;
152 ((AliTRDpidLQ &) p).fWidMom = fWidMom;
153 ((AliTRDpidLQ &) p).fChargeMin = fChargeMin;
154 ((AliTRDpidLQ &) p).fNClusterMin = fNClusterMin;
155 ((AliTRDpidLQ &) p).fNLh = fNLh;
156 ((AliTRDpidLQ &) p).fMinLh = fMinLh;
157 ((AliTRDpidLQ &) p).fMaxLh = fMaxLh;
158
159 AliTRDpid::Copy(p);
160
161}
162
163//_____________________________________________________________________________
164Bool_t AliTRDpidLQ::Init()
165{
166 //
167 // Initializes the PID object
168 //
169
170 fChargeMin = 0.0;
171 fNClusterMin = 10;
172
173 fNLh = 100;
174 fMinLh = 0.0;
175 fMaxLh = 500.0;
176
177 return kTRUE;
178
179}
180
181//_____________________________________________________________________________
182Bool_t AliTRDpidLQ::AssignLikelihood(AliTRDtrack *t)
183{
184 //
185 // Assigns the e / pi likelihood to a given track
186 //
187
188 const Int_t kNpla = AliTRDgeometry::Nplan();
a3d851c2 189 Float_t * charge = new Float_t[kNpla];
190 Int_t * nCluster = new Int_t[kNpla];
16bf9884 191
192 Float_t lhPi = 0;
193 Float_t lhEl = 0;
194
195 Double_t pPi = 1;
196 Double_t pEl = 1;
197 Double_t pSum = 0;
198
199 Int_t indexEl;
200 Int_t indexPi;
201 TH1F *hTmpEl;
202 TH1F *hTmpPi;
203
204 t->SetLikelihoodElectron(-1.);
205 if (isnan(t->GetP())) return kFALSE;
206 Float_t mom = t->GetP();
207
208 // Calculate the total charge in each plane
209 if (!SumCharge(t,charge,nCluster)) return kFALSE;
210
211 indexEl = GetIndex(mom,kElectron);
212 indexPi = GetIndex(mom,kPion);
213 if ((indexEl > -1) && (indexPi > -1)) {
214 hTmpEl = (TH1F *) fHist->UncheckedAt(indexEl);
215 hTmpPi = (TH1F *) fHist->UncheckedAt(indexPi);
216 for (Int_t ipla = 0; ipla < kNpla; ipla++) {
217 Float_t chargePlane = charge[ipla];
218 Int_t nClusterPlane = nCluster[ipla];
219 if ((chargePlane > fChargeMin) &&
220 (nClusterPlane > fNClusterMin)){
221 Float_t chargeNorm = chargePlane / ((Float_t) nClusterPlane);
222 if (chargeNorm < fMaxLh) {
223 Int_t ibinEl = hTmpEl->FindBin(chargeNorm);
224 Float_t pElPlane = hTmpEl->GetBinContent(ibinEl);
225 if (pElPlane > 0) {
226 pEl = pEl * pElPlane;
227 }
228 Int_t ibinPi = hTmpPi->FindBin(chargeNorm);
229 Float_t pPiPlane = hTmpPi->GetBinContent(ibinPi);
230 if (pPiPlane > 0) {
231 pPi = pPi * pPiPlane;
232 }
233// printf(" ipla = %d, nCluster = %d, charge = %f\n"
234// ,ipla,nClusterPlane,chargeNorm);
235// printf("electron: pElPlane = %f, ibinEl = %d, pEl = %f\n"
236// ,pElPlane,ibinEl,pEl);
237// printf(" pion: pPiPlane = %f, ibinPi = %d, pPi = %f\n"
238// ,pPiPlane,ibinPi,pPi);
239 }
240 }
241 }
242 }
243 else {
a3d851c2 244 delete [] charge;
245 delete [] nCluster;
16bf9884 246 return kTRUE;
247 }
248
249 pSum = pEl + pPi;
a3d851c2 250 if (pSum <= 0) {
251 delete [] charge;
252 delete [] nCluster;
253 return kFALSE;
254 }
16bf9884 255 lhEl = pEl / pSum;
256 lhPi = pPi / pSum;
257
258// printf("---- mom = %f, lhEl = %f, lhPi = %f\n",mom,lhEl,lhPi);
259
260 // Assign the likelihoods
261 t->SetLikelihoodElectron(lhEl);
262
a3d851c2 263 delete [] charge;
264 delete [] nCluster;
16bf9884 265 return kTRUE;
266
267}
268
269//_____________________________________________________________________________
270Bool_t AliTRDpidLQ::CreateHistograms(const Int_t nmom
271 , const Float_t minmom
272 , const Float_t maxmom)
273{
274 //
275 // Creates the histograms
276 //
277
278 Int_t imom;
279 Int_t ipid;
280
281 fNMom = nmom;
282 fMinMom = minmom;
283 fMaxMom = maxmom;
284 fWidMom = (maxmom - minmom) / ((Float_t) nmom);
285
286 fHist = new TObjArray(kNpid * nmom);
287 for (imom = 0; imom < nmom; imom++) {
288 for (ipid = 0; ipid < kNpid; ipid++) {
289
290 Int_t index = GetIndex(imom,ipid);
291 Char_t name[10];
292 Char_t title[80];
293 sprintf(name ,"hQ%03d",index);
294 if (ipid == kElectron) {
295 sprintf(title,"Q electron p-bin %03d",imom);
296 }
297 else {
298 sprintf(title,"Q pion p-bin %03d",imom);
299 }
300 TH1F *hTmp = new TH1F(name,title,fNLh,fMinLh,fMaxLh);
301 fHist->AddAt(hTmp,index);
302
303 }
304 }
305
306 return kTRUE;
307
308}
309
310// //_____________________________________________________________________________
311// Bool_t AliTRDpidLQ::FillSpectra(const AliTRDtrack *t)
312// {
313// //
314// // Fills the energy loss distributions with track <t>.
315// //
316
317// Bool_t status = kTRUE;
318
319// if (isnan(t->GetP())) return kFALSE;
320
321// Float_t mom = t->GetP();
322// Int_t ipid = MCpid(t);
323// TH1F *hTmp = NULL;
324// AliTRDcluster *cluster = NULL;
325
326// Int_t index = GetIndex(mom,ipid);
327// if (index > -1) {
328// hTmp = (TH1F *) fHist->UncheckedAt(index);
329// // Loop through all clusters associated to this track
330// Int_t nClus = t->GetNclusters();
331// for (Int_t iClus = 0; iClus < nClus; iClus++) {
332// // Get a cluster
333// Int_t idxClus = t->GetClusterIndex(iClus);
334// if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(idxClus))) {
335// status = kFALSE;
336// break;
337// }
338// hTmp->Fill(cluster->GetQ());
339// }
340// }
341
342// return status;
343
344// }
345
346//_____________________________________________________________________________
347Bool_t AliTRDpidLQ::FillSpectra(const AliTRDtrack *t)
348{
349 //
350 // Fills the energy loss distributions with track <t>.
351 //
352
353 const Int_t kNpla = AliTRDgeometry::Nplan();
354
355 if (isnan(t->GetP())) return kFALSE;
356
a3d851c2 357 Float_t * charge = new Float_t[kNpla];
358 Int_t * nCluster = new Int_t[kNpla];
16bf9884 359 Float_t mom = t->GetP();
360 Int_t ipid = MCpid(t);
361 TH1F *hTmp = NULL;
362
a3d851c2 363 if (!SumCharge(t,charge,nCluster)) {
364 delete [] charge;
365 delete [] nCluster;
366 return kFALSE;
367 }
16bf9884 368
369 Int_t index = GetIndex(mom,ipid);
370 if (index > -1) {
371 hTmp = (TH1F *) fHist->UncheckedAt(index);
372 for (Int_t ipla = 0; ipla < kNpla; ipla++) {
373 if ((charge[ipla] > fChargeMin) &&
374 (nCluster[ipla] > fNClusterMin)){
375 hTmp->Fill(charge[ipla] / ((Float_t) nCluster[ipla]));
376 }
377 }
378 }
379
a3d851c2 380 delete [] charge;
381 delete [] nCluster;
16bf9884 382 return kTRUE;
383
384}
385
386//_____________________________________________________________________________
387Int_t AliTRDpidLQ::GetIndex(const AliTRDtrack *t)
388{
389 //
390 // Returns the histogram index
391 //
392
393 if (isnan(t->GetP())) return -1;
394 Float_t mom = t->GetP();
395 Int_t ipid = MCpid(t);
396
397 return GetIndex(mom,ipid);
398
399}
400
401//_____________________________________________________________________________
402Int_t AliTRDpidLQ::GetIndex(const Float_t mom, const Int_t ipid)
403{
404 //
405 // Returns the histogram index
406 //
407
408 if ((mom < fMinMom) || (mom > fMaxMom)) return -1;
409 Int_t imom = ((Int_t) ((mom - fMinMom) / fWidMom));
410 return GetIndex(imom,ipid);
411
412}
413
414//_____________________________________________________________________________
0a29d0f1 415Int_t AliTRDpidLQ::GetIndex(const Int_t imom, const Int_t ipid) const
16bf9884 416{
417 //
418 // Returns the histogram index
419 //
420
421 if ((ipid < 0) || (ipid >= kNpid)) return -1;
422 return imom * kNpid + ipid;
423
424}