]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDcluster.cxx
Fix bugs in PID assignment
[u/mrichter/AliRoot.git] / TRD / AliTRDcluster.cxx
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 /* $Id$ */
17
18  
19 ///////////////////////////////////////////////////////////////////////////////
20 //                                                                           //
21 //  TRD cluster                                                              //
22 //                                                                           //
23 /////////////////////////////////////////////////////////////////////////////// 
24
25 #include "AliTRDcluster.h"
26 #include "AliTRDrecPoint.h"
27
28 ClassImp(AliTRDcluster)
29
30
31   //___________________________________________________________________________
32
33   AliTRDcluster::AliTRDcluster() : AliCluster() { 
34   //
35   // default constructor
36   //
37   fQ=0; 
38   fTimeBin=0; 
39   fDetector=0; 
40   fNPads=0; 
41   fX    =0;
42   for (Int_t i = 0;i<7; i++) fSignals[i]=0;
43 }
44 //_____________________________________________________________________________
45   AliTRDcluster::AliTRDcluster(const AliTRDrecPoint &p):AliCluster()
46 {
47   //
48   // Constructor from AliTRDrecPoint
49   //
50
51   fDetector   = p.GetDetector();
52   fTimeBin    = p.GetLocalTimeBin();
53
54   fTracks[0]  = p.GetTrackIndex(0);
55   fTracks[1]  = p.GetTrackIndex(1);
56   fTracks[2]  = p.GetTrackIndex(2);
57
58   fQ          = p.GetEnergy();
59
60   fY          = p.GetY();
61   fZ          = p.GetZ();
62   fSigmaY2    = p.GetSigmaY2();
63   fSigmaZ2    = p.GetSigmaZ2();  
64
65   fSigmaY2    = 0.2;
66   fSigmaZ2    = 5.;  
67   fNPads      =0;
68   fCenter     = 0;
69 }
70
71 //_____________________________________________________________________________
72 AliTRDcluster::AliTRDcluster(const AliTRDcluster &c):AliCluster()
73 {
74   //
75   // Copy constructor 
76   //
77
78   fTracks[0]  = c.GetLabel(0);
79   fTracks[1]  = c.GetLabel(1);
80   fTracks[2]  = c.GetLabel(2);
81
82   fX          = c.GetX();
83   fY          = c.GetY();
84   fZ          = c.GetZ();
85   fSigmaY2    = c.GetSigmaY2();
86   fSigmaZ2    = c.GetSigmaZ2();  
87
88   fDetector   = c.GetDetector();
89   fTimeBin    = c.GetLocalTimeBin();
90   fQ          = c.GetQ();
91   fNPads      = c.fNPads;
92   fCenter     = c.fCenter;
93   for (Int_t i=0;i<7;i++) fSignals[i] = c.fSignals[i];
94 }
95
96 //_____________________________________________________________________________
97 void AliTRDcluster::AddTrackIndex(Int_t *track)
98 {
99   //
100   // Adds track index. Currently assumed that track is an array of
101   // size 9, and up to 3 track indexes are stored in fTracks[3].
102   // Indexes are sorted according to:
103   //  1) index of max number of appearances is stored first
104   //  2) if two or more indexes appear equal number of times, the lowest
105   //     ones are stored first;
106   //
107
108   const Int_t kSize = 9;
109
110   Int_t entries[kSize][2], i, j, index;
111
112   Bool_t indexAdded;
113
114   for (i=0; i<kSize; i++) {
115     entries[i][0]=-1;
116     entries[i][1]=0;
117   }                                 
118
119   for (Int_t k=0; k<kSize; k++) {
120     index=track[k];
121     indexAdded=kFALSE; 
122     j=0;
123     if (index >= 0) {
124       while ( (!indexAdded) && ( j < kSize ) ) {
125         if ((entries[j][0]==index) || (entries[j][1]==0)) {
126           entries[j][0]=index;
127           entries[j][1]=entries[j][1]+1;
128           indexAdded=kTRUE;
129         }
130         j++;
131       }
132     }
133   }             
134
135   // sort by number of appearances and index value
136   Int_t swap=1, tmp0, tmp1;
137   while ( swap > 0) {
138     swap=0;
139     for(i=0; i<(kSize-1); i++) {
140       if ((entries[i][0] >= 0) && (entries[i+1][0] >= 0)) {
141         if ((entries[i][1] < entries[i+1][1]) ||
142             ((entries[i][1] == entries[i+1][1]) &&
143              (entries[i][0] > entries[i+1][0]))) {
144                tmp0=entries[i][0];
145                tmp1=entries[i][1];
146                entries[i][0]=entries[i+1][0];
147                entries[i][1]=entries[i+1][1];
148                entries[i+1][0]=tmp0;
149                entries[i+1][1]=tmp1;
150                swap++;
151         }
152       }
153     }
154   }               
155
156   // set track indexes
157   for(i=0; i<3; i++) SetLabel(entries[i][0],i);
158
159   return;
160
161 }          
162
163 void AliTRDcluster::SetSignals(Short_t*signals){
164   //
165   // write signals in the cluster
166   //
167   for (Int_t i = 0;i<7;i++) fSignals[i]=signals[i];
168 }
169
170 Float_t AliTRDcluster::GetSumS() const
171 {
172   //
173   // return total charge in non unfolded cluster
174   //
175   Float_t sum=0;
176   for (Int_t i = 0;i<7;i++) sum+=fSignals[i];
177   return sum;
178 }
179 Float_t AliTRDcluster::GetCenterS() const
180 {
181   //
182   //
183   //
184   Float_t sum=0;
185   Float_t sum2=0;
186   for (Int_t i = 0;i<7;i++) {    
187     sum+=fSignals[i];
188     sum2+=i*fSignals[i];
189   }
190   if (sum>0) return sum2/sum-2;
191   return 0;
192
193 }