]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDcluster.cxx
510fa42ed527f89777b0019eff7d323fec1889c0
[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 "AliLog.h"
26 #include "AliTRDcluster.h"
27
28 ClassImp(AliTRDcluster)
29
30 //___________________________________________________________________________
31 AliTRDcluster::AliTRDcluster() 
32   :AliCluster() 
33   ,fPadCol(0)
34   ,fPadRow(0)
35   ,fPadTime(0)
36   ,fLocalTimeBin(0)
37   ,fNPads(0)
38   ,fClusterMasking(0)
39   ,fDetector(0)
40   ,fQ(0)
41   ,fCenter(0)
42
43   //
44   // Default constructor
45   //
46
47   for (Int_t i = 0; i < 7; i++) {
48     fSignals[i] = 0;
49   }
50
51 }
52
53 //___________________________________________________________________________
54 AliTRDcluster::AliTRDcluster(Int_t det, Float_t q
55                            , Float_t *pos, Float_t *sig
56                            , Int_t *tracks, Char_t npads, Short_t *signals
57                            , UChar_t col, UChar_t row, UChar_t time
58                            , Char_t timebin, Float_t center, UShort_t volid)
59   :AliCluster(volid,pos[0],pos[1],pos[2],sig[0],sig[1],0.0,0x0) 
60   ,fPadCol(col)
61   ,fPadRow(row)
62   ,fPadTime(time)
63   ,fLocalTimeBin(timebin)
64   ,fNPads(npads)
65   ,fClusterMasking(0)
66   ,fDetector(det)
67   ,fQ(q)
68   ,fCenter(center)
69
70   //
71   // Constructor
72   //
73
74   for (Int_t i = 0; i < 7; i++) {
75     fSignals[i] = signals[i];
76   }
77
78   if (tracks) {
79     AddTrackIndex(tracks);
80   }
81
82 }
83
84 //_____________________________________________________________________________
85 AliTRDcluster::AliTRDcluster(const AliTRDcluster &c)
86   :AliCluster(c)
87   ,fPadCol(c.fPadCol)
88   ,fPadRow(c.fPadRow)
89   ,fPadTime(c.fPadTime)
90   ,fLocalTimeBin(c.fLocalTimeBin)
91   ,fNPads(c.fNPads)
92   ,fClusterMasking(c.fClusterMasking)
93   ,fDetector(c.fDetector)
94   ,fQ(c.fQ)
95   ,fCenter(c.fCenter)
96 {
97   //
98   // Copy constructor 
99   //
100
101   SetBit(kInChamber, c.IsInChamber());
102   SetLabel(c.GetLabel(0),0);
103   SetLabel(c.GetLabel(1),1);
104   SetLabel(c.GetLabel(2),2);
105
106   SetY(c.GetY());
107   SetZ(c.GetZ());
108   SetSigmaY2(c.GetSigmaY2());
109   SetSigmaZ2(c.GetSigmaZ2());  
110
111   for (Int_t i = 0; i < 7; i++) {
112     fSignals[i] = c.fSignals[i];
113   }
114
115 }
116
117 //_____________________________________________________________________________
118 void AliTRDcluster::AddTrackIndex(Int_t *track)
119 {
120   //
121   // Adds track index. Currently assumed that track is an array of
122   // size 9, and up to 3 track indexes are stored in fTracks[3].
123   // Indexes are sorted according to:
124   //  1) index of max number of appearances is stored first
125   //  2) if two or more indexes appear equal number of times, the lowest
126   //     ones are stored first;
127   //
128
129   const Int_t kSize = 9;
130   Int_t  entries[kSize][2];
131
132   Int_t  i = 0;
133   Int_t  j = 0;
134   Int_t  k = 0;
135   Int_t  index;
136   Bool_t indexAdded;
137
138   for (i = 0; i < kSize; i++) {
139     entries[i][0] = -1;
140     entries[i][1] =  0;
141   }                                 
142
143   for (k = 0; k < kSize; k++) {
144
145     index      = track[k];
146     indexAdded = kFALSE; 
147
148     j = 0;
149     if (index >= 0) {
150       while ((!indexAdded) && (j < kSize)) {
151         if ((entries[j][0] == index) || 
152             (entries[j][1] ==     0)) {
153           entries[j][0] = index;
154           entries[j][1] = entries[j][1] + 1;
155           indexAdded    = kTRUE;
156         }
157         j++;
158       }
159     }
160
161   }
162
163   // Sort by number of appearances and index value
164   Int_t swap = 1;
165   Int_t tmp0;
166   Int_t tmp1;
167   while (swap > 0) {
168     swap = 0;
169     for (i = 0; i < (kSize - 1); i++) {
170       if ((entries[i][0]   >= 0) && 
171           (entries[i+1][0] >= 0)) {
172         if ((entries[i][1] < entries[i+1][1]) ||
173             ((entries[i][1] == entries[i+1][1]) &&
174              (entries[i][0] >  entries[i+1][0]))) {
175           tmp0            = entries[i][0];
176           tmp1            = entries[i][1];
177           entries[i][0]   = entries[i+1][0];
178           entries[i][1]   = entries[i+1][1];
179           entries[i+1][0] = tmp0;
180           entries[i+1][1] = tmp1;
181           swap++;
182         }
183       }
184     }
185   }               
186
187   // Set track indexes
188   for (i = 0; i < 3; i++) {
189     SetLabel(entries[i][0],i);
190   }
191
192   return;
193
194 }          
195
196 //_____________________________________________________________________________
197 void AliTRDcluster::Clear(Option_t *)
198 {
199   //
200   // Reset all member to the default value
201   //
202   fPadCol=0;
203   fPadRow=0;
204   fPadTime=0;
205   fLocalTimeBin=0;
206   fNPads=0;
207   fClusterMasking=0;
208   fDetector=0;
209   for (Int_t i=0; i < 7; i++) fSignals[i]=0;
210   fQ = 0;
211   fCenter = 0;
212   for (Int_t i = 0; i < 3; i++) SetLabel(0,i);
213   SetX(0);
214   SetY(0);
215   SetZ(0);
216   SetSigmaY2(0);
217   SetSigmaZ2(0);
218   SetVolumeId(0);
219 }
220
221 //_____________________________________________________________________________
222 Float_t AliTRDcluster::GetSumS() const
223 {
224   //
225   // Returns the total charge from a not unfolded cluster
226   //
227
228   Float_t sum = 0.0;
229   for (Int_t i = 0; i < 7; i++) {
230     sum += fSignals[i];
231   }
232
233   return sum;
234
235 }
236
237
238 //_____________________________________________________________________________
239 Bool_t AliTRDcluster::IsEqual(const TObject *o) const
240 {
241   //
242   // Compare relevant information of this cluster with another one
243   //
244   
245   const AliTRDcluster *inCluster = dynamic_cast<const AliTRDcluster*>(o);
246   if (!o || !inCluster) return kFALSE;
247
248   if ( AliCluster::GetX() != inCluster->GetX() ) return kFALSE;
249   if ( AliCluster::GetY() != inCluster->GetY() ) return kFALSE;
250   if ( AliCluster::GetZ() != inCluster->GetZ() ) return kFALSE;
251   if ( fQ != inCluster->fQ ) return kFALSE;
252   if ( fDetector != inCluster->fDetector ) return kFALSE;
253   if ( fPadCol != inCluster->fPadCol ) return kFALSE;
254   if ( fPadRow != inCluster->fPadRow ) return kFALSE;
255   if ( fPadTime != inCluster->fPadTime ) return kFALSE;
256   if ( fClusterMasking != inCluster->fClusterMasking ) return kFALSE;
257   if ( IsInChamber() != inCluster->IsInChamber() ) return kFALSE;
258   if ( IsShared() != inCluster->IsShared() ) return kFALSE;
259   if ( IsUsed() != inCluster->IsUsed() ) return kFALSE;
260   
261   return kTRUE;
262 }
263
264 //_____________________________________________________________________________
265 void AliTRDcluster::Print(Option_t *o) const
266 {
267   AliInfo(Form("Det[%3d] LTrC[%7.2f %7.2f %7.2f] Q[%f] Stat[in(%c) use(%c) sh(%c)]", 
268     fDetector, GetX(), GetY(), GetZ(), fQ, 
269     IsInChamber() ? 'y' : 'n', IsUsed() ? 'y' : 'n', IsShared() ? 'y' : 'n'));
270
271   if(strcmp(o, "a")!=0) return;
272   AliInfo(Form("LChC[c(%3d) r(%2d) t(%2d)] t-t0[%2d] Npad[%d] cen[%5.3f] mask[%d]", fPadCol, fPadRow, fPadTime, fLocalTimeBin, fNPads, fCenter, fClusterMasking)); 
273   AliInfo(Form("Signals[%3d %3d %3d %3d %3d %3d %3d]", fSignals[0], fSignals[1], fSignals[2], fSignals[3], fSignals[4], fSignals[5], fSignals[6]));
274 }
275
276
277 //_____________________________________________________________________________
278 void AliTRDcluster::SetPadMaskedPosition(UChar_t position)
279 {
280   //
281   // store the pad corruption position code
282   // 
283   // Code: 1 = left cluster
284   //       2 = middle cluster;
285   //       4 = right cluster
286   //
287   for(Int_t ipos = 0; ipos < 3; ipos++)
288     if(TESTBIT(position, ipos))
289       SETBIT(fClusterMasking, ipos);
290 }
291
292 //_____________________________________________________________________________
293 void AliTRDcluster::SetPadMaskedStatus(UChar_t status)
294 {
295   //
296   // store the status of the corrupted pad
297   //
298   // Code: 2 = noisy
299   //       4 = Bridged Left
300   //       8 = Bridged Right
301   //      32 = Not Connected
302   for(Int_t ipos = 0; ipos < 5; ipos++)
303     if(TESTBIT(status, ipos))
304       SETBIT(fClusterMasking, ipos + 3);
305 }