1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // The TRD particle identification base class //
22 // Its main purposes are: //
23 // - Provide I/O framework for all neccessary files //
24 // - Assignment of a e/pi propability to a given track //
26 ///////////////////////////////////////////////////////////////////////////////
33 #include <TObjArray.h>
36 #include <TParticle.h>
40 #include "AliTRDpid.h"
41 #include "AliTRDcluster.h"
42 #include "AliTRDtrack.h"
43 #include "AliTRDtracker.h"
44 #include "AliTRDgeometry.h"
48 //_____________________________________________________________________________
49 AliTRDpid::AliTRDpid():TNamed()
52 // AliTRDpid default constructor
61 fPIDpurePoints = kFALSE;
67 fThreePadOnly = kFALSE;
71 //_____________________________________________________________________________
72 AliTRDpid::AliTRDpid(const char* name, const char* title):TNamed(name,title)
75 // AliTRDpid constructor
89 //_____________________________________________________________________________
90 AliTRDpid::AliTRDpid(const AliTRDpid &p)
93 // AliTRDpid copy constructor
96 ((AliTRDpid &) p).Copy(*this);
100 //_____________________________________________________________________________
101 AliTRDpid::~AliTRDpid()
104 // AliTRDpid destructor
108 fClusterArray->Delete();
109 delete fClusterArray;
110 fClusterArray = NULL;
114 fTrackArray->Delete();
126 //_____________________________________________________________________________
127 AliTRDpid &AliTRDpid::operator=(const AliTRDpid &p)
130 // Assignment operator
133 if (this != &p) ((AliTRDpid &) p).Copy(*this);
138 //_____________________________________________________________________________
139 void AliTRDpid::Copy(TObject &p)
145 ((AliTRDpid &) p).fTrackArray = NULL;
146 ((AliTRDpid &) p).fClusterArray = NULL;
147 ((AliTRDpid &) p).fGeometry = NULL;
148 ((AliTRDpid &) p).fFileKine = NULL;
149 ((AliTRDpid &) p).fPIDratioMin = fPIDratioMin;
150 ((AliTRDpid &) p).fPIDpurePoints = fPIDpurePoints;
151 ((AliTRDpid &) p).fPIDindexMin = fPIDindexMin;
152 ((AliTRDpid &) p).fPIDindexMax = fPIDindexMax;
153 ((AliTRDpid &) p).fThreePadOnly = fThreePadOnly;
154 ((AliTRDpid &) p).fEvent = fEvent;
158 //_____________________________________________________________________________
159 Bool_t AliTRDpid::Init()
162 // Initializes the PID object
165 fClusterArray = new TObjArray();
166 fTrackArray = new TObjArray();
169 fPIDpurePoints = kTRUE;
173 fThreePadOnly = kFALSE;
179 //_____________________________________________________________________________
180 Bool_t AliTRDpid::AssignLikelihood()
183 // Assigns the e / pi likelihood to all tracks.
186 return AssignLikelihood(fTrackArray);
190 //_____________________________________________________________________________
191 Bool_t AliTRDpid::AssignLikelihood(TObjArray *tarray)
194 // Assigns the e / pi likelihood to all tracks in the array <tarray>.
197 Bool_t status = kTRUE;
201 TIter nextTrack(tarray);
202 while ((track = (AliTRDtrack *) nextTrack())) {
203 if (!AssignLikelihood(track)) {
213 //_____________________________________________________________________________
214 Bool_t AliTRDpid::FillSpectra()
217 // Fills the energy loss distributions with all tracks.
220 return FillSpectra(fTrackArray);
224 //_____________________________________________________________________________
225 Bool_t AliTRDpid::FillSpectra(TObjArray *tarray)
228 // Fills the energy loss distributions with all tracks in <tarray>.
231 Bool_t status = kTRUE;
235 TIter nextTrack(tarray);
236 while ((track = (AliTRDtrack *) nextTrack())) {
237 if (!FillSpectra(track)) {
247 //_____________________________________________________________________________
248 Bool_t AliTRDpid::Open(const Char_t *name, Int_t event)
251 // Opens and reads the kine tree, the geometry, the cluster array
252 // and the track array from the file <name>.
255 Bool_t status = kTRUE;
257 status = ReadCluster(name);
258 status = ReadTracks(name);
259 status = ReadKine(name,event);
265 //_____________________________________________________________________________
266 Bool_t AliTRDpid::Open(const Char_t *namekine
267 , const Char_t *namecluster
268 , const Char_t *nametracks
272 // Opens and reads the kine tree and the geometry from file <namekine>,
273 // the cluster array from file <namecluster>,
274 // and the track array from the file <nametracks>.
277 Bool_t status = kTRUE;
279 status = ReadCluster(namecluster);
280 status = ReadTracks(nametracks);
281 status = ReadKine(namekine,event);
287 //_____________________________________________________________________________
288 Bool_t AliTRDpid::ReadKine(const Char_t *name, Int_t event)
291 // Opens and reads the kine tree and the geometry from the file <name>.
294 TFile *fFileKine = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
296 printf("AliTRDpid::ReadKine -- ");
297 printf("Open file %s\n",name);
298 fFileKine = new TFile(name);
300 printf("AliTRDpid::ReadKine -- ");
301 printf("Cannot open file %s\n",name);
306 gAlice = (AliRun *) fFileKine->Get("gAlice");
308 printf("AliTRDpid::ReadKine -- ");
309 printf("No AliRun object found\n");
312 gAlice->GetEvent(event);
314 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
316 printf("AliTRDpid::ReadKine -- ");
317 printf("No TRD object found\n");
321 fGeometry = trd->GetGeometry();
323 printf("AliTRDpid::ReadKine -- ");
324 printf("No TRD geometry found\n");
334 //_____________________________________________________________________________
335 Bool_t AliTRDpid::ReadCluster(const Char_t *name)
338 // Opens and reads the cluster array from the file <name>.
341 TDirectory *savedir = gDirectory;
344 fClusterArray->Delete();
347 fClusterArray = new TObjArray();
350 printf("AliTRDpid::ReadCluster -- ");
351 printf("Open file %s\n",name);
353 AliTRDtracker *tracker = new AliTRDtracker();
354 tracker->ReadClusters(fClusterArray,name);
356 if (!fClusterArray) {
357 printf("AliTRDpid::ReadCluster -- ");
358 printf("Error reading the cluster array from file %s\n",name);
370 //_____________________________________________________________________________
371 Bool_t AliTRDpid::ReadTracks(const Char_t *name)
374 // Opens and reads the track array from the file <name>.
377 TDirectory *savedir = gDirectory;
380 fTrackArray->Delete();
383 fTrackArray = new TObjArray();
386 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
388 printf("AliTRDpid::ReadTracks -- ");
389 printf("Open file %s\n",name);
390 file = new TFile(name);
392 printf("AliTRDpid::ReadTracks -- ");
393 printf("Cannot open file %s\n",name);
399 sprintf(treeName,"TreeT%d_TRD",fEvent);
400 TTree *trackTree = (TTree *) file->Get(treeName);
401 TBranch *trackBranch = trackTree->GetBranch("tracks");
403 Int_t nEntry = ((Int_t) trackTree->GetEntries());
404 for (Int_t iEntry = 0; iEntry < nEntry; iEntry++) {
405 AliTRDtrack *track = new AliTRDtrack();
406 trackBranch->SetAddress(&track);
407 trackTree->GetEvent(iEntry);
408 fTrackArray->AddLast(track);
419 //_____________________________________________________________________________
420 Int_t AliTRDpid::MCpid(const AliTRDtrack *t)
423 // Determines the pid of the MC track <t>.
427 const Int_t kPdgEl = 11;
428 const Int_t kPdgPi = 211;
430 AliTRDcluster *cluster;
433 Int_t nClusterEl = 0;
434 Int_t nClusterPi = 0;
435 Int_t nClusterPure = 0;
436 Int_t nClusterMix = 0;
443 if (!fClusterArray) {
444 printf("AliTRDpid::MCpid -- ");
445 printf("ClusterArray not defined. Initialize the PID object first\n");
449 // Loop through all clusters associated to this track
450 Int_t nCluster = t->GetNumberOfClusters();
451 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
454 Int_t index = t->GetClusterIndex(iCluster);
455 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
459 // Get the first two MC track indices
460 Int_t track0 = cluster->GetLabel(0);
461 Int_t track1 = cluster->GetLabel(1);
463 // Check on the track index to find the right primaries
464 if ((track0 > fPIDindexMin) &&
465 (track0 <= fPIDindexMax)) {
467 // Check whether it is a pure cluster, i.e. not overlapping
468 Bool_t accept = kTRUE;
469 if ((fPIDpurePoints) && (track1 != -1)) {
474 particle = gAlice->Particle(track0);
475 if (particle->GetFirstMother() == -1) {
476 switch (TMath::Abs(particle->GetPdgCode())) {
499 ratioEl = ((Float_t) nClusterEl) / ((Float_t) nCluster);
500 ratioPi = ((Float_t) nClusterPi) / ((Float_t) nCluster);
501 if (ratioEl > fPIDratioMin) {
504 else if (ratioPi > fPIDratioMin) {
508 // printf("AliTRDpid::MCpid -- ");
509 // printf("nCluster = %d, nClusterEl = %d, nClusterPi = %d\n"
510 // ,nCluster,nClusterEl,nClusterPi);
511 // printf("AliTRDpid::MCpid -- ");
512 // printf("nClusterPure = %d, nClusterMix = %d\n"
513 // ,nClusterPure,nClusterMix);
514 // printf("AliTRDpid::MCpid -- ");
515 // printf("ratioEl = %f, ratioPi = %f, ipid = %d\n",ratioEl,ratioPi,ipid);
521 //_____________________________________________________________________________
522 Int_t AliTRDpid::MCpid(const AliTRDtrack *t, Int_t *pdg
527 // Determines the pid of the MC track <t>.
528 // Returns the number of different MC particles that contribute to this
529 // track. <pdg> contains their PDG code, ordered by their frequency.
530 // <nFound> contains the corresponding number of cluster that contain
531 // contributions to this cluster.
534 const Int_t kNtrack = 3;
535 const Int_t kNpart = 200;
537 AliTRDcluster *cluster;
545 if (!fClusterArray) {
546 printf("AliTRDpid::MCpid -- ");
547 printf("ClusterArray not defined. Initialize the PID object first\n");
552 Int_t pdgTmp[kNpart];
553 Int_t nFoundTmp[kNpart];
554 Int_t indicesTmp[kNpart];
555 for (iPart = 0; iPart < kNpart; iPart++) {
560 nFoundTmp[iPart] = 0;
561 indicesTmp[iPart] = 0;
565 // Loop through all clusters associated to this track
566 Int_t nCluster = t->GetNumberOfClusters();
567 for (iCluster = 0; iCluster < nCluster; iCluster++) {
570 Int_t index = t->GetClusterIndex(iCluster);
571 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
575 // Get the MC track indices
576 for (iTrack = 0; iTrack < kNtrack; iTrack++) {
578 Int_t trackIndex = cluster->GetLabel(iTrack);
579 if (trackIndex >= 0) {
580 particle = gAlice->Particle(trackIndex);
581 Int_t pdgCode = particle->GetPdgCode();
582 Bool_t newPart = kTRUE;
583 for (iPart = 0; iPart < nPart; iPart++) {
584 if (trackIndex == indicesTmp[iPart]) {
590 if ((newPart) && (nPart < kNpart)) {
591 indicesTmp[nPart] = trackIndex;
592 pdgTmp[nPart] = pdgCode;
602 // Sort the arrays by the frequency of the appearance of a MC track
603 TMath::Sort(nPart,nFoundTmp,sort,kTRUE);
604 for (iPart = 0; iPart < nPart; iPart++) {
605 pdg[iPart] = pdgTmp[sort[iPart]];
606 nFound[iPart] = nFoundTmp[sort[iPart]];
607 indices[iPart] = indicesTmp[sort[iPart]];
608 // printf(" iPart = %d, pdg = %d, nFound = %d, indices = %d\n"
609 // ,iPart,pdg[iPart],nFound[iPart],indices[iPart]);
616 //_____________________________________________________________________________
617 Bool_t AliTRDpid::SumCharge(const AliTRDtrack *t
622 // Sums up the charge in each plane for track <t>.
625 Bool_t status = kTRUE;
627 AliTRDcluster *cluster;
629 const Int_t kNplane = AliTRDgeometry::Nplan();
630 for (Int_t iPlane = 0; iPlane < kNplane; iPlane++) {
631 charge[iPlane] = 0.0;
632 nCluster[iPlane] = 0;
635 if (!fClusterArray) {
636 printf("AliTRDpid::SumCharge -- ");
637 printf("ClusterArray not defined. Initialize the PID object first\n");
641 printf("AliTRDpid::SumCharge -- ");
642 printf("TRD geometry not defined. Initialize the PID object first\n");
646 // Loop through all clusters associated to this track
647 Int_t nClus = t->GetNumberOfClusters();
648 for (Int_t iClus = 0; iClus < nClus; iClus++) {
651 Int_t index = t->GetClusterIndex(iClus);
652 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
658 if ((!cluster->From2pad()) &&
659 (!cluster->From3pad())) continue;
663 Int_t plane = fGeometry->GetPlane(cluster->GetDetector());
664 //charge[plane] += cluster->GetQ();
666 charge[plane] += t->GetClusterdQdl(iClus);
670 // printf("AliTRDpid::SumCharge -- ");
671 // printf("charge = %d, %d, %d, %d, %d, %d\n"
672 // ,(Int_t) charge[0]
673 // ,(Int_t) charge[1]
674 // ,(Int_t) charge[2]
675 // ,(Int_t) charge[3]
676 // ,(Int_t) charge[4]
677 // ,(Int_t) charge[5]);
678 // printf("AliTRDpid::SumCharge -- ");
679 // printf("nCluster = %d, %d, %d, %d, %d, %d\n"