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 Revision 1.4 2001/11/19 08:44:08 cblume
19 Fix bugs reported by Rene
21 Revision 1.3 2001/11/14 10:50:46 cblume
22 Changes in digits IO. Add merging of summable digits
24 Revision 1.2 2001/11/06 17:19:41 cblume
25 Add detailed geometry and simple simulator
27 Revision 1.1 2001/05/07 08:08:05 cblume
32 ///////////////////////////////////////////////////////////////////////////////
34 // The TRD particle identification base class //
36 // Its main purposes are: //
37 // - Provide I/O framework for all neccessary files //
38 // - Assignment of a e/pi propability to a given track //
40 ///////////////////////////////////////////////////////////////////////////////
47 #include <TObjArray.h>
50 #include <TParticle.h>
54 #include "AliTRDpid.h"
55 #include "AliTRDcluster.h"
56 #include "AliTRDtrack.h"
57 #include "AliTRDtracker.h"
58 #include "AliTRDgeometry.h"
62 //_____________________________________________________________________________
63 AliTRDpid::AliTRDpid():TNamed()
66 // AliTRDpid default constructor
75 fPIDpurePoints = kFALSE;
81 fThreePadOnly = kFALSE;
85 //_____________________________________________________________________________
86 AliTRDpid::AliTRDpid(const char* name, const char* title):TNamed(name,title)
89 // AliTRDpid constructor
103 //_____________________________________________________________________________
104 AliTRDpid::AliTRDpid(const AliTRDpid &p)
107 // AliTRDpid copy constructor
110 ((AliTRDpid &) p).Copy(*this);
114 //_____________________________________________________________________________
115 AliTRDpid::~AliTRDpid()
118 // AliTRDpid destructor
122 fClusterArray->Delete();
123 delete fClusterArray;
124 fClusterArray = NULL;
128 fTrackArray->Delete();
140 //_____________________________________________________________________________
141 AliTRDpid &AliTRDpid::operator=(const AliTRDpid &p)
144 // Assignment operator
147 if (this != &p) ((AliTRDpid &) p).Copy(*this);
152 //_____________________________________________________________________________
153 void AliTRDpid::Copy(TObject &p)
159 ((AliTRDpid &) p).fTrackArray = NULL;
160 ((AliTRDpid &) p).fClusterArray = NULL;
161 ((AliTRDpid &) p).fGeometry = NULL;
162 ((AliTRDpid &) p).fFileKine = NULL;
163 ((AliTRDpid &) p).fPIDratioMin = fPIDratioMin;
164 ((AliTRDpid &) p).fPIDpurePoints = fPIDpurePoints;
165 ((AliTRDpid &) p).fPIDindexMin = fPIDindexMin;
166 ((AliTRDpid &) p).fPIDindexMax = fPIDindexMax;
167 ((AliTRDpid &) p).fThreePadOnly = fThreePadOnly;
168 ((AliTRDpid &) p).fEvent = fEvent;
172 //_____________________________________________________________________________
173 Bool_t AliTRDpid::Init()
176 // Initializes the PID object
179 fClusterArray = new TObjArray();
180 fTrackArray = new TObjArray();
183 fPIDpurePoints = kTRUE;
187 fThreePadOnly = kFALSE;
193 //_____________________________________________________________________________
194 Bool_t AliTRDpid::AssignLikelihood()
197 // Assigns the e / pi likelihood to all tracks.
200 return AssignLikelihood(fTrackArray);
204 //_____________________________________________________________________________
205 Bool_t AliTRDpid::AssignLikelihood(TObjArray *tarray)
208 // Assigns the e / pi likelihood to all tracks in the array <tarray>.
211 Bool_t status = kTRUE;
215 TIter nextTrack(tarray);
216 while ((track = (AliTRDtrack *) nextTrack())) {
217 if (!AssignLikelihood(track)) {
227 //_____________________________________________________________________________
228 Bool_t AliTRDpid::FillSpectra()
231 // Fills the energy loss distributions with all tracks.
234 return FillSpectra(fTrackArray);
238 //_____________________________________________________________________________
239 Bool_t AliTRDpid::FillSpectra(TObjArray *tarray)
242 // Fills the energy loss distributions with all tracks in <tarray>.
245 Bool_t status = kTRUE;
249 TIter nextTrack(tarray);
250 while ((track = (AliTRDtrack *) nextTrack())) {
251 if (!FillSpectra(track)) {
261 //_____________________________________________________________________________
262 Bool_t AliTRDpid::Open(const Char_t *name, Int_t event)
265 // Opens and reads the kine tree, the geometry, the cluster array
266 // and the track array from the file <name>.
269 Bool_t status = kTRUE;
271 status = ReadCluster(name);
272 status = ReadTracks(name);
273 status = ReadKine(name,event);
279 //_____________________________________________________________________________
280 Bool_t AliTRDpid::Open(const Char_t *namekine
281 , const Char_t *namecluster
282 , const Char_t *nametracks
286 // Opens and reads the kine tree and the geometry from file <namekine>,
287 // the cluster array from file <namecluster>,
288 // and the track array from the file <nametracks>.
291 Bool_t status = kTRUE;
293 status = ReadCluster(namecluster);
294 status = ReadTracks(nametracks);
295 status = ReadKine(namekine,event);
301 //_____________________________________________________________________________
302 Bool_t AliTRDpid::ReadKine(const Char_t *name, Int_t event)
305 // Opens and reads the kine tree and the geometry from the file <name>.
308 TFile *fFileKine = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
310 printf("AliTRDpid::ReadKine -- ");
311 printf("Open file %s\n",name);
312 fFileKine = new TFile(name);
314 printf("AliTRDpid::ReadKine -- ");
315 printf("Cannot open file %s\n",name);
320 gAlice = (AliRun *) fFileKine->Get("gAlice");
322 printf("AliTRDpid::ReadKine -- ");
323 printf("No AliRun object found\n");
326 gAlice->GetEvent(event);
328 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
330 printf("AliTRDpid::ReadKine -- ");
331 printf("No TRD object found\n");
335 fGeometry = trd->GetGeometry();
337 printf("AliTRDpid::ReadKine -- ");
338 printf("No TRD geometry found\n");
348 //_____________________________________________________________________________
349 Bool_t AliTRDpid::ReadCluster(const Char_t *name)
352 // Opens and reads the cluster array from the file <name>.
355 TDirectory *savedir = gDirectory;
358 fClusterArray->Delete();
361 fClusterArray = new TObjArray();
364 printf("AliTRDpid::ReadCluster -- ");
365 printf("Open file %s\n",name);
367 AliTRDtracker *tracker = new AliTRDtracker();
368 tracker->ReadClusters(fClusterArray,name);
370 if (!fClusterArray) {
371 printf("AliTRDpid::ReadCluster -- ");
372 printf("Error reading the cluster array from file %s\n",name);
384 //_____________________________________________________________________________
385 Bool_t AliTRDpid::ReadTracks(const Char_t *name)
388 // Opens and reads the track array from the file <name>.
391 TDirectory *savedir = gDirectory;
394 fTrackArray->Delete();
397 fTrackArray = new TObjArray();
400 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
402 printf("AliTRDpid::ReadTracks -- ");
403 printf("Open file %s\n",name);
404 file = new TFile(name);
406 printf("AliTRDpid::ReadTracks -- ");
407 printf("Cannot open file %s\n",name);
413 sprintf(treeName,"TreeT%d_TRD",fEvent);
414 TTree *trackTree = (TTree *) file->Get(treeName);
415 TBranch *trackBranch = trackTree->GetBranch("tracks");
417 Int_t nEntry = ((Int_t) trackTree->GetEntries());
418 for (Int_t iEntry = 0; iEntry < nEntry; iEntry++) {
419 AliTRDtrack *track = new AliTRDtrack();
420 trackBranch->SetAddress(&track);
421 trackTree->GetEvent(iEntry);
422 fTrackArray->AddLast(track);
433 //_____________________________________________________________________________
434 Int_t AliTRDpid::MCpid(const AliTRDtrack *t)
437 // Determines the pid of the MC track <t>.
441 const Int_t kPdgEl = 11;
442 const Int_t kPdgPi = 211;
444 AliTRDcluster *cluster;
447 Int_t nClusterEl = 0;
448 Int_t nClusterPi = 0;
449 Int_t nClusterPure = 0;
450 Int_t nClusterMix = 0;
457 if (!fClusterArray) {
458 printf("AliTRDpid::MCpid -- ");
459 printf("ClusterArray not defined. Initialize the PID object first\n");
463 // Loop through all clusters associated to this track
464 Int_t nCluster = t->GetNumberOfClusters();
465 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
468 Int_t index = t->GetClusterIndex(iCluster);
469 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
473 // Get the first two MC track indices
474 Int_t track0 = cluster->GetLabel(0);
475 Int_t track1 = cluster->GetLabel(1);
477 // Check on the track index to find the right primaries
478 if ((track0 > fPIDindexMin) &&
479 (track0 <= fPIDindexMax)) {
481 // Check whether it is a pure cluster, i.e. not overlapping
482 Bool_t accept = kTRUE;
483 if ((fPIDpurePoints) && (track1 != -1)) {
488 particle = gAlice->Particle(track0);
489 if (particle->GetFirstMother() == -1) {
490 switch (TMath::Abs(particle->GetPdgCode())) {
513 ratioEl = ((Float_t) nClusterEl) / ((Float_t) nCluster);
514 ratioPi = ((Float_t) nClusterPi) / ((Float_t) nCluster);
515 if (ratioEl > fPIDratioMin) {
518 else if (ratioPi > fPIDratioMin) {
522 // printf("AliTRDpid::MCpid -- ");
523 // printf("nCluster = %d, nClusterEl = %d, nClusterPi = %d\n"
524 // ,nCluster,nClusterEl,nClusterPi);
525 // printf("AliTRDpid::MCpid -- ");
526 // printf("nClusterPure = %d, nClusterMix = %d\n"
527 // ,nClusterPure,nClusterMix);
528 // printf("AliTRDpid::MCpid -- ");
529 // printf("ratioEl = %f, ratioPi = %f, ipid = %d\n",ratioEl,ratioPi,ipid);
535 //_____________________________________________________________________________
536 Int_t AliTRDpid::MCpid(const AliTRDtrack *t, Int_t *pdg
541 // Determines the pid of the MC track <t>.
542 // Returns the number of different MC particles that contribute to this
543 // track. <pdg> contains their PDG code, ordered by their frequency.
544 // <nFound> contains the corresponding number of cluster that contain
545 // contributions to this cluster.
548 const Int_t kNtrack = 3;
549 const Int_t kNpart = 200;
551 AliTRDcluster *cluster;
559 if (!fClusterArray) {
560 printf("AliTRDpid::MCpid -- ");
561 printf("ClusterArray not defined. Initialize the PID object first\n");
566 Int_t pdgTmp[kNpart];
567 Int_t nFoundTmp[kNpart];
568 Int_t indicesTmp[kNpart];
569 for (iPart = 0; iPart < kNpart; iPart++) {
574 nFoundTmp[iPart] = 0;
575 indicesTmp[iPart] = 0;
579 // Loop through all clusters associated to this track
580 Int_t nCluster = t->GetNumberOfClusters();
581 for (iCluster = 0; iCluster < nCluster; iCluster++) {
584 Int_t index = t->GetClusterIndex(iCluster);
585 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
589 // Get the MC track indices
590 for (iTrack = 0; iTrack < kNtrack; iTrack++) {
592 Int_t trackIndex = cluster->GetLabel(iTrack);
593 if (trackIndex >= 0) {
594 particle = gAlice->Particle(trackIndex);
595 Int_t pdgCode = particle->GetPdgCode();
596 Bool_t newPart = kTRUE;
597 for (iPart = 0; iPart < nPart; iPart++) {
598 if (trackIndex == indicesTmp[iPart]) {
604 if ((newPart) && (nPart < kNpart)) {
605 indicesTmp[nPart] = trackIndex;
606 pdgTmp[nPart] = pdgCode;
616 // Sort the arrays by the frequency of the appearance of a MC track
617 TMath::Sort(nPart,nFoundTmp,sort,kTRUE);
618 for (iPart = 0; iPart < nPart; iPart++) {
619 pdg[iPart] = pdgTmp[sort[iPart]];
620 nFound[iPart] = nFoundTmp[sort[iPart]];
621 indices[iPart] = indicesTmp[sort[iPart]];
622 // printf(" iPart = %d, pdg = %d, nFound = %d, indices = %d\n"
623 // ,iPart,pdg[iPart],nFound[iPart],indices[iPart]);
630 //_____________________________________________________________________________
631 Bool_t AliTRDpid::SumCharge(const AliTRDtrack *t
636 // Sums up the charge in each plane for track <t>.
639 Bool_t status = kTRUE;
641 AliTRDcluster *cluster;
643 const Int_t kNplane = AliTRDgeometry::Nplan();
644 for (Int_t iPlane = 0; iPlane < kNplane; iPlane++) {
645 charge[iPlane] = 0.0;
646 nCluster[iPlane] = 0;
649 if (!fClusterArray) {
650 printf("AliTRDpid::SumCharge -- ");
651 printf("ClusterArray not defined. Initialize the PID object first\n");
655 printf("AliTRDpid::SumCharge -- ");
656 printf("TRD geometry not defined. Initialize the PID object first\n");
660 // Loop through all clusters associated to this track
661 Int_t nClus = t->GetNumberOfClusters();
662 for (Int_t iClus = 0; iClus < nClus; iClus++) {
665 Int_t index = t->GetClusterIndex(iClus);
666 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
672 if ((!cluster->From2pad()) &&
673 (!cluster->From3pad())) continue;
677 Int_t plane = fGeometry->GetPlane(cluster->GetDetector());
678 //charge[plane] += cluster->GetQ();
680 charge[plane] += t->GetClusterdQdl(iClus);
684 // printf("AliTRDpid::SumCharge -- ");
685 // printf("charge = %d, %d, %d, %d, %d, %d\n"
686 // ,(Int_t) charge[0]
687 // ,(Int_t) charge[1]
688 // ,(Int_t) charge[2]
689 // ,(Int_t) charge[3]
690 // ,(Int_t) charge[4]
691 // ,(Int_t) charge[5]);
692 // printf("AliTRDpid::SumCharge -- ");
693 // printf("nCluster = %d, %d, %d, %d, %d, %d\n"