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