]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDclusterizerV0.cxx
Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of...
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizerV0.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 /*
17 $Log$
18 Revision 1.8  2001/05/07 08:06:44  cblume
19 Speedup of the code. Create only AliTRDcluster
20
21 Revision 1.7  2001/02/14 18:22:26  cblume
22 Change in the geometry of the padplane
23
24 Revision 1.6  2000/11/01 14:53:20  cblume
25 Merge with TRD-develop
26
27 Revision 1.1.4.6  2000/10/16 01:16:53  cblume
28 Changed timebin 0 to be the one closest to the readout
29
30 Revision 1.1.4.5  2000/10/15 23:40:01  cblume
31 Remove AliTRDconst
32
33 Revision 1.1.4.4  2000/10/06 16:49:46  cblume
34 Made Getters const
35
36 Revision 1.1.4.3  2000/10/04 16:34:58  cblume
37 Replace include files by forward declarations
38
39 Revision 1.1.4.2  2000/09/22 14:49:49  cblume
40 Adapted to tracking code
41
42 Revision 1.5  2000/10/02 21:28:19  fca
43 Removal of useless dependecies via forward declarations
44
45 Revision 1.4  2000/06/08 18:32:58  cblume
46 Make code compliant to coding conventions
47
48 Revision 1.3  2000/06/07 16:27:01  cblume
49 Try to remove compiler warnings on Sun and HP
50
51 Revision 1.2  2000/05/08 16:17:27  cblume
52 Merge TRD-develop
53
54 Revision 1.1.4.1  2000/05/08 15:08:41  cblume
55 Replace AliTRDcluster by AliTRDrecPoint
56
57 Revision 1.4  2000/06/08 18:32:58  cblume
58 Make code compliant to coding conventions
59
60 Revision 1.3  2000/06/07 16:27:01  cblume
61 Try to remove compiler warnings on Sun and HP
62
63 Revision 1.2  2000/05/08 16:17:27  cblume
64 Merge TRD-develop
65
66 Revision 1.1.4.1  2000/05/08 15:08:41  cblume
67 Replace AliTRDcluster by AliTRDrecPoint
68
69 Revision 1.1  2000/02/28 18:58:33  cblume
70 Add new TRD classes
71
72 */
73
74 ///////////////////////////////////////////////////////////////////////////////
75 //                                                                           //
76 // TRD cluster finder for the fast simulator. It takes the hits from the     //
77 // fast simulator (one hit per plane) and transforms them                    //
78 // into cluster, by applying position smearing and merging                   //
79 // of nearby cluster. The searing is done uniformly in z-direction           //
80 // over the length of a readout pad. In rphi-direction a Gaussian            //
81 // smearing is applied with a sigma given by fRphiSigma.                     //
82 // Clusters are considered as overlapping when they are closer in            //
83 // rphi-direction than the value defined in fRphiDist.                       //
84 // Use the macro fastClusterCreate.C to create the cluster.                  //
85 //                                                                           //
86 ///////////////////////////////////////////////////////////////////////////////
87
88 #include <TRandom.h>
89 #include <TTree.h>
90  
91 #include "AliRun.h"
92
93 #include "AliTRD.h"
94 #include "AliTRDclusterizerV0.h"
95 #include "AliTRDhit.h"
96 #include "AliTRDgeometry.h"
97 #include "AliTRDrecPoint.h"
98
99 ClassImp(AliTRDclusterizerV0)
100
101 //_____________________________________________________________________________
102 AliTRDclusterizerV0::AliTRDclusterizerV0():AliTRDclusterizer()
103 {
104   //
105   // AliTRDclusterizerV0 default constructor
106   //
107
108 }
109
110 //_____________________________________________________________________________
111 AliTRDclusterizerV0::AliTRDclusterizerV0(const Text_t* name, const Text_t* title)
112                     :AliTRDclusterizer(name,title)
113 {
114   //
115   // AliTRDclusterizerV0 default constructor
116   //
117
118   Init();
119
120 }
121
122 //_____________________________________________________________________________
123 AliTRDclusterizerV0::~AliTRDclusterizerV0()
124 {
125   //
126   // AliTRDclusterizerV0 destructor
127   //
128
129 }
130
131 //_____________________________________________________________________________
132 void AliTRDclusterizerV0::Init()
133 {
134   //
135   // Initializes the cluster finder
136   //
137
138   // Position resolution in rphi-direction
139   fRphiSigma  = 0.02;
140   // Minimum distance of non-overlapping cluster
141   fRphiDist   = 1.0;
142
143 }
144
145 //_____________________________________________________________________________
146 Bool_t AliTRDclusterizerV0::MakeClusters()
147 {
148   //
149   // Generates the cluster
150   //
151
152   if (fTRD->IsVersion() != 0) {
153     printf("AliTRDclusterizerV0::MakeCluster -- ");
154     printf("TRD must be version 0 (fast simulator).\n");
155     return kFALSE; 
156   }
157
158   // Get the geometry
159   AliTRDgeometry *geo = fTRD->GetGeometry();
160   
161   printf("AliTRDclusterizerV0::MakeCluster -- ");
162   printf("Start creating cluster.\n");
163
164   Int_t nBytes = 0;
165
166   AliTRDhit *hit;
167   
168   // Get the pointer to the hit tree
169   TTree     *hitTree      = gAlice->TreeH();
170   // Get the pointer to the reconstruction tree
171   TTree     *clusterTree  = gAlice->TreeR();
172
173   TObjArray *chamberArray = new TObjArray();
174
175   // Get the number of entries in the hit tree
176   // (Number of primary particles creating a hit somewhere)
177   Int_t nTrack = (Int_t) hitTree->GetEntries();
178
179   // Loop through all the chambers
180   for (Int_t icham = 0; icham < AliTRDgeometry::Ncham(); icham++) {
181     for (Int_t iplan = 0; iplan < AliTRDgeometry::Nplan(); iplan++) {
182       for (Int_t isect = 0; isect < AliTRDgeometry::Nsect(); isect++) {
183
184         Int_t   nColMax     = geo->GetColMax(iplan);
185         Float_t row0        = geo->GetRow0(iplan,icham,isect);
186         Float_t col0        = geo->GetCol0(iplan);
187         Float_t time0       = geo->GetTime0(iplan);
188
189         Float_t rowPadSize  = geo->GetRowPadSize(iplan,icham,isect);
190         Float_t colPadSize  = geo->GetColPadSize(iplan);
191         Float_t timeBinSize = geo->GetTimeBinSize();
192
193         // Loop through all entries in the tree
194         for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
195
196           gAlice->ResetHits();
197           nBytes += hitTree->GetEvent(iTrack);
198
199           // Get the number of hits in the TRD created by this particle
200           Int_t nHit = fTRD->Hits()->GetEntriesFast();
201
202           // Loop through the TRD hits  
203           for (Int_t iHit = 0; iHit < nHit; iHit++) {
204
205             if (!(hit = (AliTRDhit *) fTRD->Hits()->UncheckedAt(iHit))) 
206               continue;
207
208             Float_t pos[3];
209                     pos[0]   = hit->X();
210                     pos[1]   = hit->Y();
211                     pos[2]   = hit->Z();
212             Int_t   track    = hit->Track();
213             Int_t   detector = hit->GetDetector();
214             Int_t   plane    = geo->GetPlane(detector);
215             Int_t   sector   = geo->GetSector(detector);
216             Int_t   chamber  = geo->GetChamber(detector);        
217
218             if ((sector  != isect) ||
219                 (plane   != iplan) ||
220                 (chamber != icham)) 
221               continue;
222
223             // Rotate the sectors on top of each other
224             Float_t rot[3];
225             geo->Rotate(detector,pos,rot);
226
227             // Add this recPoint to the temporary array for this chamber
228             AliTRDrecPoint *recPoint = new AliTRDrecPoint();
229             recPoint->SetLocalRow(rot[2]);
230             recPoint->SetLocalCol(rot[1]);
231             recPoint->SetLocalTime(rot[0]);
232             recPoint->SetEnergy(0);
233             recPoint->SetDetector(detector);
234             recPoint->AddDigit(track);
235             chamberArray->Add(recPoint);
236
237           }
238
239         }
240   
241         // Loop through the temporary cluster-array
242         for (Int_t iClus1 = 0; iClus1 < chamberArray->GetEntries(); iClus1++) {
243
244           AliTRDrecPoint *recPoint1 = (AliTRDrecPoint *) 
245                                       chamberArray->UncheckedAt(iClus1);
246           Float_t row1  = recPoint1->GetLocalRow();
247           Float_t col1  = recPoint1->GetLocalCol();
248           Float_t time1 = recPoint1->GetLocalTime();
249
250           if (recPoint1->GetEnergy() < 0) continue;        // Skip marked cluster  
251
252           const Int_t kNsave  = 5;
253           Int_t idxSave[kNsave];
254           Int_t iSave = 0;
255
256           const Int_t kNsaveTrack = 3;
257           Int_t tracks[kNsaveTrack];
258           tracks[0] = recPoint1->GetDigit(0);
259
260           // Check the other cluster to see, whether there are close ones
261           for (Int_t iClus2 = iClus1 + 1; iClus2 < chamberArray->GetEntries(); iClus2++) {
262
263             AliTRDrecPoint *recPoint2 = (AliTRDrecPoint *) 
264                                         chamberArray->UncheckedAt(iClus2);
265             Float_t row2 = recPoint2->GetLocalRow();
266             Float_t col2 = recPoint2->GetLocalCol();
267
268             if ((TMath::Abs(row1 - row2) < rowPadSize) ||
269                 (TMath::Abs(col1 - col2) <  fRphiDist)) {
270               if (iSave == kNsave) {
271                 printf("AliTRDclusterizerV0::MakeCluster -- ");
272                 printf("Boundary error: iSave = %d, kNsave = %d.\n"
273                       ,iSave,kNsave);
274               }
275               else {                              
276                 idxSave[iSave]  = iClus2;
277                 iSave++;
278                 if (iSave < kNsaveTrack) tracks[iSave] = recPoint2->GetDigit(0);
279               }
280             }
281           }
282      
283           // Merge close cluster
284           Float_t rowMerge = row1;
285           Float_t colMerge = col1;
286           if (iSave) {
287             for (Int_t iMerge = 0; iMerge < iSave; iMerge++) {
288               AliTRDrecPoint *recPoint2 =
289                 (AliTRDrecPoint *) chamberArray->UncheckedAt(idxSave[iMerge]);
290               rowMerge += recPoint2->GetLocalRow();
291               colMerge += recPoint2->GetLocalCol();
292               recPoint2->SetEnergy(-1);     // Mark merged cluster
293             }
294             rowMerge /= (iSave + 1);
295             colMerge /= (iSave + 1);
296           }
297
298           Float_t smear[3];
299
300           // The position smearing in row-direction (uniform over pad width)            
301           Int_t row = (Int_t) ((rowMerge - row0) / rowPadSize);
302           smear[0]  = (row + gRandom->Rndm()) * rowPadSize + row0;
303
304           // The position smearing in rphi-direction (Gaussian)
305           smear[1] = 0;
306           do
307             smear[1] = gRandom->Gaus(colMerge,fRphiSigma);
308           while ((smear[1] < col0                        ) ||
309                  (smear[1] > col0 + nColMax * colPadSize));
310
311           // Time direction stays unchanged
312           smear[2] = time1;
313          
314           // Transform into local coordinates
315           smear[0] = (Int_t) ((smear[0] -  row0) /  rowPadSize);
316           smear[1] = (Int_t) ((smear[1] -  col0) /  colPadSize);
317           smear[2] = (Int_t) ((time0 - smear[2]) / timeBinSize);
318
319           // Add the smeared cluster to the output array 
320           Int_t detector  = recPoint1->GetDetector();
321           Int_t digits[3] = {0};
322           Int_t tr[9] = {-1}; 
323           fTRD->AddCluster(smear,digits,detector,0.0,tr,0,0);
324
325         }
326
327         // Clear the temporary cluster-array and delete the cluster
328         chamberArray->Delete();
329
330       }
331     }
332   }
333
334   printf("AliTRDclusterizerV0::MakeCluster -- ");
335   printf("Found %d points.\n",fTRD->RecPoints()->GetEntries());
336   printf("AliTRDclusterizerV0::MakeCluster -- ");
337   printf("Fill the cluster tree.\n");
338   clusterTree->Fill();
339
340   return kTRUE;
341
342 }