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