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"
49 //_____________________________________________________________________________
50 AliTRDpid::AliTRDpid():TNamed()
53 // AliTRDpid default constructor
62 fPIDpurePoints = kFALSE;
68 fThreePadOnly = kFALSE;
72 //_____________________________________________________________________________
73 AliTRDpid::AliTRDpid(const char* name, const char* title):TNamed(name,title)
76 // AliTRDpid constructor
90 //_____________________________________________________________________________
91 AliTRDpid::AliTRDpid(const AliTRDpid &p):TNamed(p)
94 // AliTRDpid copy constructor
97 ((AliTRDpid &) p).Copy(*this);
101 //_____________________________________________________________________________
102 AliTRDpid::~AliTRDpid()
105 // AliTRDpid destructor
109 fClusterArray->Delete();
110 delete fClusterArray;
111 fClusterArray = NULL;
115 fTrackArray->Delete();
127 //_____________________________________________________________________________
128 AliTRDpid &AliTRDpid::operator=(const AliTRDpid &p)
131 // Assignment operator
134 if (this != &p) ((AliTRDpid &) p).Copy(*this);
139 //_____________________________________________________________________________
140 void AliTRDpid::Copy(TObject &p)
146 ((AliTRDpid &) p).fTrackArray = NULL;
147 ((AliTRDpid &) p).fClusterArray = NULL;
148 ((AliTRDpid &) p).fGeometry = NULL;
149 ((AliTRDpid &) p).fFileKine = NULL;
150 ((AliTRDpid &) p).fPIDratioMin = fPIDratioMin;
151 ((AliTRDpid &) p).fPIDpurePoints = fPIDpurePoints;
152 ((AliTRDpid &) p).fPIDindexMin = fPIDindexMin;
153 ((AliTRDpid &) p).fPIDindexMax = fPIDindexMax;
154 ((AliTRDpid &) p).fThreePadOnly = fThreePadOnly;
155 ((AliTRDpid &) p).fEvent = fEvent;
159 //_____________________________________________________________________________
160 Bool_t AliTRDpid::Init()
163 // Initializes the PID object
166 fClusterArray = new TObjArray();
167 fTrackArray = new TObjArray();
170 fPIDpurePoints = kTRUE;
174 fThreePadOnly = kFALSE;
180 //_____________________________________________________________________________
181 Bool_t AliTRDpid::AssignLikelihood()
184 // Assigns the e / pi likelihood to all tracks.
187 return AssignLikelihood(fTrackArray);
191 //_____________________________________________________________________________
192 Bool_t AliTRDpid::AssignLikelihood(TObjArray *tarray)
195 // Assigns the e / pi likelihood to all tracks in the array <tarray>.
198 Bool_t status = kTRUE;
202 TIter nextTrack(tarray);
203 while ((track = (AliTRDtrack *) nextTrack())) {
204 if (!AssignLikelihood(track)) {
214 //_____________________________________________________________________________
215 Bool_t AliTRDpid::FillSpectra()
218 // Fills the energy loss distributions with all tracks.
221 return FillSpectra(fTrackArray);
225 //_____________________________________________________________________________
226 Bool_t AliTRDpid::FillSpectra(TObjArray *tarray)
229 // Fills the energy loss distributions with all tracks in <tarray>.
232 Bool_t status = kTRUE;
236 TIter nextTrack(tarray);
237 while ((track = (AliTRDtrack *) nextTrack())) {
238 if (!FillSpectra(track)) {
248 //_____________________________________________________________________________
249 Bool_t AliTRDpid::Open(const Char_t *name, Int_t event)
252 // Opens and reads the kine tree, the geometry, the cluster array
253 // and the track array from the file <name>.
256 Bool_t status = kTRUE;
258 status = ReadCluster(name);
259 status = ReadTracks(name);
260 status = ReadKine(name,event);
266 //_____________________________________________________________________________
267 Bool_t AliTRDpid::Open(const Char_t *namekine
268 , const Char_t *namecluster
269 , const Char_t *nametracks
273 // Opens and reads the kine tree and the geometry from file <namekine>,
274 // the cluster array from file <namecluster>,
275 // and the track array from the file <nametracks>.
278 Bool_t status = kTRUE;
280 status = ReadCluster(namecluster);
281 status = ReadTracks(nametracks);
282 status = ReadKine(namekine,event);
288 //_____________________________________________________________________________
289 Bool_t AliTRDpid::ReadKine(const Char_t *name, Int_t event)
292 // Opens and reads the kine tree and the geometry from the file <name>.
295 TFile *fFileKine = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
297 printf("AliTRDpid::ReadKine -- ");
298 printf("Open file %s\n",name);
299 fFileKine = new TFile(name);
301 printf("AliTRDpid::ReadKine -- ");
302 printf("Cannot open file %s\n",name);
307 gAlice = (AliRun *) fFileKine->Get("gAlice");
309 printf("AliTRDpid::ReadKine -- ");
310 printf("No AliRun object found\n");
313 gAlice->GetEvent(event);
315 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
317 printf("AliTRDpid::ReadKine -- ");
318 printf("No TRD object found\n");
322 fGeometry = trd->GetGeometry();
324 printf("AliTRDpid::ReadKine -- ");
325 printf("No TRD geometry found\n");
335 //_____________________________________________________________________________
336 Bool_t AliTRDpid::ReadCluster(const Char_t *name)
339 // Opens and reads the cluster array from the file <name>.
342 TDirectory *savedir = gDirectory;
345 fClusterArray->Delete();
348 fClusterArray = new TObjArray();
351 printf("AliTRDpid::ReadCluster -- ");
352 printf("Open file %s\n",name);
354 AliTRDtracker *tracker = new AliTRDtracker();
355 tracker->ReadClusters(fClusterArray,name);
357 if (!fClusterArray) {
358 printf("AliTRDpid::ReadCluster -- ");
359 printf("Error reading the cluster array from file %s\n",name);
371 //_____________________________________________________________________________
372 Bool_t AliTRDpid::ReadTracks(const Char_t *name)
375 // Opens and reads the track array from the file <name>.
378 TDirectory *savedir = gDirectory;
381 fTrackArray->Delete();
384 fTrackArray = new TObjArray();
387 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
389 printf("AliTRDpid::ReadTracks -- ");
390 printf("Open file %s\n",name);
391 file = new TFile(name);
393 printf("AliTRDpid::ReadTracks -- ");
394 printf("Cannot open file %s\n",name);
400 sprintf(treeName,"TreeT%d_TRD",fEvent);
401 TTree *trackTree = (TTree *) file->Get(treeName);
402 TBranch *trackBranch = trackTree->GetBranch("tracks");
404 Int_t nEntry = ((Int_t) trackTree->GetEntries());
405 for (Int_t iEntry = 0; iEntry < nEntry; iEntry++) {
406 AliTRDtrack *track = new AliTRDtrack();
407 trackBranch->SetAddress(&track);
408 trackTree->GetEvent(iEntry);
409 fTrackArray->AddLast(track);
420 //_____________________________________________________________________________
421 Int_t AliTRDpid::MCpid(const AliTRDtrack *t)
424 // Determines the pid of the MC track <t>.
428 const Int_t kPdgEl = 11;
429 const Int_t kPdgPi = 211;
431 AliTRDcluster *cluster;
434 Int_t nClusterEl = 0;
435 Int_t nClusterPi = 0;
436 Int_t nClusterPure = 0;
437 Int_t nClusterMix = 0;
444 if (!fClusterArray) {
445 printf("AliTRDpid::MCpid -- ");
446 printf("ClusterArray not defined. Initialize the PID object first\n");
450 // Loop through all clusters associated to this track
451 Int_t nCluster = t->GetNumberOfClusters();
452 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
455 Int_t index = t->GetClusterIndex(iCluster);
456 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
460 // Get the first two MC track indices
461 Int_t track0 = cluster->GetLabel(0);
462 Int_t track1 = cluster->GetLabel(1);
464 // Check on the track index to find the right primaries
465 if ((track0 > fPIDindexMin) &&
466 (track0 <= fPIDindexMax)) {
468 // Check whether it is a pure cluster, i.e. not overlapping
469 Bool_t accept = kTRUE;
470 if ((fPIDpurePoints) && (track1 != -1)) {
475 particle = gAlice->GetMCApp()->Particle(track0);
476 if (particle->GetFirstMother() == -1) {
477 switch (TMath::Abs(particle->GetPdgCode())) {
500 ratioEl = ((Float_t) nClusterEl) / ((Float_t) nCluster);
501 ratioPi = ((Float_t) nClusterPi) / ((Float_t) nCluster);
502 if (ratioEl > fPIDratioMin) {
505 else if (ratioPi > fPIDratioMin) {
509 // printf("AliTRDpid::MCpid -- ");
510 // printf("nCluster = %d, nClusterEl = %d, nClusterPi = %d\n"
511 // ,nCluster,nClusterEl,nClusterPi);
512 // printf("AliTRDpid::MCpid -- ");
513 // printf("nClusterPure = %d, nClusterMix = %d\n"
514 // ,nClusterPure,nClusterMix);
515 // printf("AliTRDpid::MCpid -- ");
516 // printf("ratioEl = %f, ratioPi = %f, ipid = %d\n",ratioEl,ratioPi,ipid);
522 //_____________________________________________________________________________
523 Int_t AliTRDpid::MCpid(const AliTRDtrack *t, Int_t *pdg
528 // Determines the pid of the MC track <t>.
529 // Returns the number of different MC particles that contribute to this
530 // track. <pdg> contains their PDG code, ordered by their frequency.
531 // <nFound> contains the corresponding number of cluster that contain
532 // contributions to this cluster.
535 const Int_t kNtrack = 3;
536 const Int_t kNpart = 200;
538 AliTRDcluster *cluster;
546 if (!fClusterArray) {
547 printf("AliTRDpid::MCpid -- ");
548 printf("ClusterArray not defined. Initialize the PID object first\n");
553 Int_t pdgTmp[kNpart];
554 Int_t nFoundTmp[kNpart];
555 Int_t indicesTmp[kNpart];
556 for (iPart = 0; iPart < kNpart; iPart++) {
561 nFoundTmp[iPart] = 0;
562 indicesTmp[iPart] = 0;
566 // Loop through all clusters associated to this track
567 Int_t nCluster = t->GetNumberOfClusters();
568 for (iCluster = 0; iCluster < nCluster; iCluster++) {
571 Int_t index = t->GetClusterIndex(iCluster);
572 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
576 // Get the MC track indices
577 for (iTrack = 0; iTrack < kNtrack; iTrack++) {
579 Int_t trackIndex = cluster->GetLabel(iTrack);
580 if (trackIndex >= 0) {
581 particle = gAlice->GetMCApp()->Particle(trackIndex);
582 Int_t pdgCode = particle->GetPdgCode();
583 Bool_t newPart = kTRUE;
584 for (iPart = 0; iPart < nPart; iPart++) {
585 if (trackIndex == indicesTmp[iPart]) {
591 if ((newPart) && (nPart < kNpart)) {
592 indicesTmp[nPart] = trackIndex;
593 pdgTmp[nPart] = pdgCode;
603 // Sort the arrays by the frequency of the appearance of a MC track
604 TMath::Sort(nPart,nFoundTmp,sort,kTRUE);
605 for (iPart = 0; iPart < nPart; iPart++) {
606 pdg[iPart] = pdgTmp[sort[iPart]];
607 nFound[iPart] = nFoundTmp[sort[iPart]];
608 indices[iPart] = indicesTmp[sort[iPart]];
609 // printf(" iPart = %d, pdg = %d, nFound = %d, indices = %d\n"
610 // ,iPart,pdg[iPart],nFound[iPart],indices[iPart]);
617 //_____________________________________________________________________________
618 Bool_t AliTRDpid::SumCharge(const AliTRDtrack *t
623 // Sums up the charge in each plane for track <t>.
626 Bool_t status = kTRUE;
628 AliTRDcluster *cluster;
630 const Int_t kNplane = AliTRDgeometry::Nplan();
631 for (Int_t iPlane = 0; iPlane < kNplane; iPlane++) {
632 charge[iPlane] = 0.0;
633 nCluster[iPlane] = 0;
636 if (!fClusterArray) {
637 printf("AliTRDpid::SumCharge -- ");
638 printf("ClusterArray not defined. Initialize the PID object first\n");
642 printf("AliTRDpid::SumCharge -- ");
643 printf("TRD geometry not defined. Initialize the PID object first\n");
647 // Loop through all clusters associated to this track
648 Int_t nClus = t->GetNumberOfClusters();
649 for (Int_t iClus = 0; iClus < nClus; iClus++) {
652 Int_t index = t->GetClusterIndex(iClus);
653 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
659 if ((!cluster->From2pad()) &&
660 (!cluster->From3pad())) continue;
664 Int_t plane = fGeometry->GetPlane(cluster->GetDetector());
665 //charge[plane] += cluster->GetQ();
667 charge[plane] += t->GetClusterdQdl(iClus);
671 // printf("AliTRDpid::SumCharge -- ");
672 // printf("charge = %d, %d, %d, %d, %d, %d\n"
673 // ,(Int_t) charge[0]
674 // ,(Int_t) charge[1]
675 // ,(Int_t) charge[2]
676 // ,(Int_t) charge[3]
677 // ,(Int_t) charge[4]
678 // ,(Int_t) charge[5]);
679 // printf("AliTRDpid::SumCharge -- ");
680 // printf("nCluster = %d, %d, %d, %d, %d, %d\n"