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