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