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.2 2001/11/06 17:19:41 cblume
19 Add detailed geometry and simple simulator
21 Revision 1.1 2001/05/07 08:08:05 cblume
26 ///////////////////////////////////////////////////////////////////////////////
28 // The TRD particle identification base class //
30 // Its main purposes are: //
31 // - Provide I/O framework for all neccessary files //
32 // - Assignment of a e/pi propability to a given track //
34 ///////////////////////////////////////////////////////////////////////////////
41 #include <TObjArray.h>
44 #include <TParticle.h>
48 #include "AliTRDpid.h"
49 #include "AliTRDcluster.h"
50 #include "AliTRDtrack.h"
51 #include "AliTRDtracker.h"
52 #include "AliTRDgeometry.h"
56 //_____________________________________________________________________________
57 AliTRDpid::AliTRDpid():TNamed()
60 // AliTRDpid default constructor
69 fPIDpurePoints = kFALSE;
75 fThreePadOnly = kFALSE;
79 //_____________________________________________________________________________
80 AliTRDpid::AliTRDpid(const char* name, const char* title):TNamed(name,title)
83 // AliTRDpid constructor
97 //_____________________________________________________________________________
98 AliTRDpid::AliTRDpid(const AliTRDpid &p)
101 // AliTRDpid copy constructor
104 ((AliTRDpid &) p).Copy(*this);
108 //_____________________________________________________________________________
109 AliTRDpid::~AliTRDpid()
112 // AliTRDpid destructor
116 fClusterArray->Delete();
117 delete fClusterArray;
118 fClusterArray = NULL;
122 fTrackArray->Delete();
131 //_____________________________________________________________________________
132 AliTRDpid &AliTRDpid::operator=(const AliTRDpid &p)
135 // Assignment operator
138 if (this != &p) ((AliTRDpid &) p).Copy(*this);
143 //_____________________________________________________________________________
144 void AliTRDpid::Copy(TObject &p)
150 ((AliTRDpid &) p).fTrackArray = NULL;
151 ((AliTRDpid &) p).fClusterArray = NULL;
152 ((AliTRDpid &) p).fGeometry = NULL;
153 ((AliTRDpid &) p).fFileKine = NULL;
154 ((AliTRDpid &) p).fPIDratioMin = fPIDratioMin;
155 ((AliTRDpid &) p).fPIDpurePoints = fPIDpurePoints;
156 ((AliTRDpid &) p).fPIDindexMin = fPIDindexMin;
157 ((AliTRDpid &) p).fPIDindexMax = fPIDindexMax;
158 ((AliTRDpid &) p).fThreePadOnly = fThreePadOnly;
159 ((AliTRDpid &) p).fEvent = fEvent;
163 //_____________________________________________________________________________
164 Bool_t AliTRDpid::Init()
167 // Initializes the PID object
170 fClusterArray = new TObjArray();
171 fTrackArray = new TObjArray();
174 fPIDpurePoints = kTRUE;
178 fThreePadOnly = kFALSE;
184 //_____________________________________________________________________________
185 Bool_t AliTRDpid::AssignLikelihood()
188 // Assigns the e / pi likelihood to all tracks.
191 return AssignLikelihood(fTrackArray);
195 //_____________________________________________________________________________
196 Bool_t AliTRDpid::AssignLikelihood(TObjArray *tarray)
199 // Assigns the e / pi likelihood to all tracks in the array <tarray>.
202 Bool_t status = kTRUE;
206 TIter nextTrack(tarray);
207 while ((track = (AliTRDtrack *) nextTrack())) {
208 if (!AssignLikelihood(track)) {
218 //_____________________________________________________________________________
219 Bool_t AliTRDpid::FillSpectra()
222 // Fills the energy loss distributions with all tracks.
225 return FillSpectra(fTrackArray);
229 //_____________________________________________________________________________
230 Bool_t AliTRDpid::FillSpectra(TObjArray *tarray)
233 // Fills the energy loss distributions with all tracks in <tarray>.
236 Bool_t status = kTRUE;
240 TIter nextTrack(tarray);
241 while ((track = (AliTRDtrack *) nextTrack())) {
242 if (!FillSpectra(track)) {
252 //_____________________________________________________________________________
253 Bool_t AliTRDpid::Open(const Char_t *name, Int_t event)
256 // Opens and reads the kine tree, the geometry, the cluster array
257 // and the track array from the file <name>.
260 Bool_t status = kTRUE;
262 status = ReadCluster(name);
263 status = ReadTracks(name);
264 status = ReadKine(name,event);
270 //_____________________________________________________________________________
271 Bool_t AliTRDpid::Open(const Char_t *namekine
272 , const Char_t *namecluster
273 , const Char_t *nametracks
277 // Opens and reads the kine tree and the geometry from file <namekine>,
278 // the cluster array from file <namecluster>,
279 // and the track array from the file <nametracks>.
282 Bool_t status = kTRUE;
284 status = ReadCluster(namecluster);
285 status = ReadTracks(nametracks);
286 status = ReadKine(namekine,event);
292 //_____________________________________________________________________________
293 Bool_t AliTRDpid::ReadKine(const Char_t *name, Int_t event)
296 // Opens and reads the kine tree and the geometry from the file <name>.
299 TFile *fFileKine = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
301 printf("AliTRDpid::ReadKine -- ");
302 printf("Open file %s\n",name);
303 fFileKine = new TFile(name);
305 printf("AliTRDpid::ReadKine -- ");
306 printf("Cannot open file %s\n",name);
311 gAlice = (AliRun *) fFileKine->Get("gAlice");
313 printf("AliTRDpid::ReadKine -- ");
314 printf("No AliRun object found\n");
317 gAlice->GetEvent(event);
319 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
321 printf("AliTRDpid::ReadKine -- ");
322 printf("No TRD object found\n");
326 fGeometry = trd->GetGeometry();
328 printf("AliTRDpid::ReadKine -- ");
329 printf("No TRD geometry found\n");
339 //_____________________________________________________________________________
340 Bool_t AliTRDpid::ReadCluster(const Char_t *name)
343 // Opens and reads the cluster array from the file <name>.
346 TDirectory *savedir = gDirectory;
349 fClusterArray->Delete();
352 fClusterArray = new TObjArray();
355 printf("AliTRDpid::ReadCluster -- ");
356 printf("Open file %s\n",name);
358 AliTRDtracker *tracker = new AliTRDtracker("dummy","dummy");
359 tracker->ReadClusters(fClusterArray,name);
361 if (!fClusterArray) {
362 printf("AliTRDpid::ReadCluster -- ");
363 printf("Error reading the cluster array from file %s\n",name);
375 //_____________________________________________________________________________
376 Bool_t AliTRDpid::ReadTracks(const Char_t *name)
379 // Opens and reads the track array from the file <name>.
382 TDirectory *savedir = gDirectory;
385 fTrackArray->Delete();
388 fTrackArray = new TObjArray();
391 TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject(name);
393 printf("AliTRDpid::ReadTracks -- ");
394 printf("Open file %s\n",name);
395 file = new TFile(name);
397 printf("AliTRDpid::ReadTracks -- ");
398 printf("Cannot open file %s\n",name);
404 sprintf(treeName,"TreeT%d_TRD",fEvent);
405 TTree *trackTree = (TTree *) file->Get(treeName);
406 TBranch *trackBranch = trackTree->GetBranch("tracks");
408 Int_t nEntry = ((Int_t) trackTree->GetEntries());
409 for (Int_t iEntry = 0; iEntry < nEntry; iEntry++) {
410 AliTRDtrack *track = new AliTRDtrack();
411 trackBranch->SetAddress(&track);
412 trackTree->GetEvent(iEntry);
413 fTrackArray->AddLast(track);
424 //_____________________________________________________________________________
425 Int_t AliTRDpid::MCpid(const AliTRDtrack *t)
428 // Determines the pid of the MC track <t>.
432 const Int_t kPdgEl = 11;
433 const Int_t kPdgPi = 211;
435 AliTRDcluster *cluster;
438 Int_t nClusterEl = 0;
439 Int_t nClusterPi = 0;
440 Int_t nClusterPure = 0;
441 Int_t nClusterMix = 0;
448 if (!fClusterArray) {
449 printf("AliTRDpid::MCpid -- ");
450 printf("ClusterArray not defined. Initialize the PID object first\n");
454 // Loop through all clusters associated to this track
455 Int_t nCluster = t->GetNclusters();
456 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
459 Int_t index = t->GetClusterIndex(iCluster);
460 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
464 // Get the first two MC track indices
465 Int_t track0 = cluster->GetTrackIndex(0);
466 Int_t track1 = cluster->GetTrackIndex(1);
468 // Check on the track index to find the right primaries
469 if ((track0 > fPIDindexMin) &&
470 (track0 <= fPIDindexMax)) {
472 // Check whether it is a pure cluster, i.e. not overlapping
473 Bool_t accept = kTRUE;
474 if ((fPIDpurePoints) && (track1 != -1)) {
479 particle = gAlice->Particle(track0);
480 if (particle->GetFirstMother() == -1) {
481 switch (TMath::Abs(particle->GetPdgCode())) {
504 ratioEl = ((Float_t) nClusterEl) / ((Float_t) nCluster);
505 ratioPi = ((Float_t) nClusterPi) / ((Float_t) nCluster);
506 if (ratioEl > fPIDratioMin) {
509 else if (ratioPi > fPIDratioMin) {
513 // printf("AliTRDpid::MCpid -- ");
514 // printf("nCluster = %d, nClusterEl = %d, nClusterPi = %d\n"
515 // ,nCluster,nClusterEl,nClusterPi);
516 // printf("AliTRDpid::MCpid -- ");
517 // printf("nClusterPure = %d, nClusterMix = %d\n"
518 // ,nClusterPure,nClusterMix);
519 // printf("AliTRDpid::MCpid -- ");
520 // printf("ratioEl = %f, ratioPi = %f, ipid = %d\n",ratioEl,ratioPi,ipid);
526 //_____________________________________________________________________________
527 Int_t AliTRDpid::MCpid(const AliTRDtrack *t, Int_t *pdg
532 // Determines the pid of the MC track <t>.
533 // Returns the number of different MC particles that contribute to this
534 // track. <pdg> contains their PDG code, ordered by their frequency.
535 // <nFound> contains the corresponding number of cluster that contain
536 // contributions to this cluster.
539 const Int_t kNtrack = 3;
540 const Int_t kNpart = 200;
542 AliTRDcluster *cluster;
550 if (!fClusterArray) {
551 printf("AliTRDpid::MCpid -- ");
552 printf("ClusterArray not defined. Initialize the PID object first\n");
557 Int_t pdgTmp[kNpart];
558 Int_t nFoundTmp[kNpart];
559 Int_t indicesTmp[kNpart];
560 for (iPart = 0; iPart < kNpart; iPart++) {
565 nFoundTmp[iPart] = 0;
566 indicesTmp[iPart] = 0;
570 // Loop through all clusters associated to this track
571 Int_t nCluster = t->GetNclusters();
572 for (iCluster = 0; iCluster < nCluster; iCluster++) {
575 Int_t index = t->GetClusterIndex(iCluster);
576 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
580 // Get the MC track indices
581 for (iTrack = 0; iTrack < kNtrack; iTrack++) {
583 Int_t trackIndex = cluster->GetTrackIndex(iTrack);
584 if (trackIndex >= 0) {
585 particle = gAlice->Particle(trackIndex);
586 Int_t pdgCode = particle->GetPdgCode();
587 Bool_t newPart = kTRUE;
588 for (iPart = 0; iPart < nPart; iPart++) {
589 if (trackIndex == indicesTmp[iPart]) {
595 if ((newPart) && (nPart < kNpart)) {
596 indicesTmp[nPart] = trackIndex;
597 pdgTmp[nPart] = pdgCode;
607 // Sort the arrays by the frequency of the appearance of a MC track
608 TMath::Sort(nPart,nFoundTmp,sort,kTRUE);
609 for (iPart = 0; iPart < nPart; iPart++) {
610 pdg[iPart] = pdgTmp[sort[iPart]];
611 nFound[iPart] = nFoundTmp[sort[iPart]];
612 indices[iPart] = indicesTmp[sort[iPart]];
613 // printf(" iPart = %d, pdg = %d, nFound = %d, indices = %d\n"
614 // ,iPart,pdg[iPart],nFound[iPart],indices[iPart]);
621 //_____________________________________________________________________________
622 Bool_t AliTRDpid::SumCharge(const AliTRDtrack *t
627 // Sums up the charge in each plane for track <t>.
630 Bool_t status = kTRUE;
632 AliTRDcluster *cluster;
634 const Int_t kNplane = AliTRDgeometry::Nplan();
635 for (Int_t iPlane = 0; iPlane < kNplane; iPlane++) {
636 charge[iPlane] = 0.0;
637 nCluster[iPlane] = 0;
640 if (!fClusterArray) {
641 printf("AliTRDpid::SumCharge -- ");
642 printf("ClusterArray not defined. Initialize the PID object first\n");
646 printf("AliTRDpid::SumCharge -- ");
647 printf("TRD geometry not defined. Initialize the PID object first\n");
651 // Loop through all clusters associated to this track
652 Int_t nClus = t->GetNclusters();
653 for (Int_t iClus = 0; iClus < nClus; iClus++) {
656 Int_t index = t->GetClusterIndex(iClus);
657 if (!(cluster = (AliTRDcluster *) fClusterArray->UncheckedAt(index))) {
663 if ((!cluster->From2pad()) &&
664 (!cluster->From3pad())) continue;
668 Int_t plane = fGeometry->GetPlane(cluster->GetDetector());
669 //charge[plane] += cluster->GetQ();
671 charge[plane] += t->GetClusterdQdl(iClus);
675 // printf("AliTRDpid::SumCharge -- ");
676 // printf("charge = %d, %d, %d, %d, %d, %d\n"
677 // ,(Int_t) charge[0]
678 // ,(Int_t) charge[1]
679 // ,(Int_t) charge[2]
680 // ,(Int_t) charge[3]
681 // ,(Int_t) charge[4]
682 // ,(Int_t) charge[5]);
683 // printf("AliTRDpid::SumCharge -- ");
684 // printf("nCluster = %d, %d, %d, %d, %d, %d\n"