]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDclusterizerV0.cxx
Changed timebin 0 to be the one closest to the readout
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizerV0.cxx
CommitLineData
f7336fa3 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$
94de3818 18Revision 1.4 2000/06/08 18:32:58 cblume
19Make code compliant to coding conventions
20
8230f242 21Revision 1.3 2000/06/07 16:27:01 cblume
22Try to remove compiler warnings on Sun and HP
23
9d0b222b 24Revision 1.2 2000/05/08 16:17:27 cblume
25Merge TRD-develop
26
6f1e466d 27Revision 1.1.4.1 2000/05/08 15:08:41 cblume
28Replace AliTRDcluster by AliTRDrecPoint
29
30Revision 1.1 2000/02/28 18:58:33 cblume
31Add new TRD classes
32
f7336fa3 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>
94de3818 50#include <TTree.h>
f7336fa3 51
52#include "AliTRDclusterizerV0.h"
53#include "AliTRDconst.h"
54#include "AliTRDgeometry.h"
55#include "AliTRDrecPoint.h"
56
57ClassImp(AliTRDclusterizerV0)
58
59//_____________________________________________________________________________
60AliTRDclusterizerV0::AliTRDclusterizerV0():AliTRDclusterizer()
61{
62 //
63 // AliTRDclusterizerV0 default constructor
64 //
65
66}
67
68//_____________________________________________________________________________
69AliTRDclusterizerV0::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//_____________________________________________________________________________
81AliTRDclusterizerV0::~AliTRDclusterizerV0()
82{
8230f242 83 //
84 // AliTRDclusterizerV0 destructor
85 //
f7336fa3 86
87}
88
89//_____________________________________________________________________________
90void 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//_____________________________________________________________________________
104Bool_t AliTRDclusterizerV0::MakeCluster()
105{
106 //
107 // Generates the cluster
108 //
109
110 // Get the pointer to the detector class and check for version 1
8230f242 111 AliTRD *trd = (AliTRD*) gAlice->GetDetector("TRD");
112 if (trd->IsVersion() != 0) {
f7336fa3 113 printf("AliTRDclusterizerV0::MakeCluster -- ");
114 printf("TRD must be version 0 (fast simulator).\n");
115 return kFALSE;
116 }
117
118 // Get the geometry
8230f242 119 AliTRDgeometry *geo = trd->GetGeometry();
f7336fa3 120
121 printf("AliTRDclusterizerV0::MakeCluster -- ");
122 printf("Start creating cluster.\n");
123
124 Int_t nBytes = 0;
125
8230f242 126 AliTRDhit *hit;
f7336fa3 127
128 // Get the pointer to the hit tree
8230f242 129 TTree *hitTree = gAlice->TreeH();
f7336fa3 130 // Get the pointer to the reconstruction tree
8230f242 131 TTree *clusterTree = gAlice->TreeR();
f7336fa3 132
8230f242 133 TObjArray *chamberArray = new TObjArray();
f7336fa3 134
135 // Get the number of entries in the hit tree
136 // (Number of primary particles creating a hit somewhere)
8230f242 137 Int_t nTrack = (Int_t) hitTree->GetEntries();
f7336fa3 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
8230f242 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);
f7336fa3 148
8230f242 149 Float_t rowPadSize = geo->GetRowPadSize();
150 Float_t colPadSize = geo->GetColPadSize();
151 Float_t timeBinSize = geo->GetTimeBinSize();
f7336fa3 152
153 // Loop through all entries in the tree
154 for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) {
155
156 gAlice->ResetHits();
8230f242 157 nBytes += hitTree->GetEvent(iTrack);
f7336fa3 158
159 // Get the number of hits in the TRD created by this particle
8230f242 160 Int_t nHit = trd->Hits()->GetEntriesFast();
f7336fa3 161
162 // Loop through the TRD hits
163 for (Int_t iHit = 0; iHit < nHit; iHit++) {
164
8230f242 165 if (!(hit = (AliTRDhit *) trd->Hits()->UncheckedAt(iHit)))
f7336fa3 166 continue;
167
168 Float_t pos[3];
94de3818 169 pos[0] = hit->X();
170 pos[1] = hit->Y();
171 pos[2] = hit->Z();
172 Int_t track = hit->Track();
8230f242 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);
f7336fa3 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];
8230f242 185 geo->Rotate(detector,pos,rot);
f7336fa3 186
6f1e466d 187 // Add this recPoint to the temporary array for this chamber
8230f242 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);
f7336fa3 196
197 }
198
199 }
200
201 // Loop through the temporary cluster-array
8230f242 202 for (Int_t iClus1 = 0; iClus1 < chamberArray->GetEntries(); iClus1++) {
f7336fa3 203
8230f242 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();
f7336fa3 209
8230f242 210 if (recPoint1->GetEnergy() < 0) continue; // Skip marked cluster
f7336fa3 211
8230f242 212 const Int_t kNsave = 5;
213 Int_t idxSave[kNsave];
f7336fa3 214 Int_t iSave = 0;
215
8230f242 216 const Int_t kNsaveTrack = 3;
217 Int_t tracks[kNsaveTrack];
218 tracks[0] = recPoint1->GetDigit(0);
f7336fa3 219
220 // Check the other cluster to see, whether there are close ones
8230f242 221 for (Int_t iClus2 = iClus1 + 1; iClus2 < chamberArray->GetEntries(); iClus2++) {
6f1e466d 222
8230f242 223 AliTRDrecPoint *recPoint2 = (AliTRDrecPoint *)
224 chamberArray->UncheckedAt(iClus2);
225 Float_t row2 = recPoint2->GetLocalRow();
226 Float_t col2 = recPoint2->GetLocalCol();
6f1e466d 227
228 if ((TMath::Abs(row1 - row2) < rowPadSize) ||
229 (TMath::Abs(col1 - col2) < fRphiDist)) {
8230f242 230 if (iSave == kNsave) {
f7336fa3 231 printf("AliTRDclusterizerV0::MakeCluster -- ");
8230f242 232 printf("Boundary error: iSave = %d, kNsave = %d.\n"
233 ,iSave,kNsave);
f7336fa3 234 }
6f1e466d 235 else {
f7336fa3 236 idxSave[iSave] = iClus2;
6f1e466d 237 iSave++;
8230f242 238 if (iSave < kNsaveTrack) tracks[iSave] = recPoint2->GetDigit(0);
f7336fa3 239 }
f7336fa3 240 }
241 }
242
243 // Merge close cluster
6f1e466d 244 Float_t rowMerge = row1;
245 Float_t colMerge = col1;
f7336fa3 246 if (iSave) {
247 for (Int_t iMerge = 0; iMerge < iSave; iMerge++) {
8230f242 248 AliTRDrecPoint *recPoint2 =
249 (AliTRDrecPoint *) chamberArray->UncheckedAt(idxSave[iMerge]);
250 rowMerge += recPoint2->GetLocalRow();
251 colMerge += recPoint2->GetLocalCol();
252 recPoint2->SetEnergy(-1); // Mark merged cluster
f7336fa3 253 }
6f1e466d 254 rowMerge /= (iSave + 1);
255 colMerge /= (iSave + 1);
f7336fa3 256 }
257
258 Float_t smear[3];
259
6f1e466d 260 // The position smearing in row-direction (uniform over pad width)
261 Int_t row = (Int_t) ((rowMerge - row0) / rowPadSize);
f7336fa3 262 smear[0] = (row + gRandom->Rndm()) * rowPadSize + row0;
263
264 // The position smearing in rphi-direction (Gaussian)
265 smear[1] = 0;
266 do
6f1e466d 267 smear[1] = gRandom->Gaus(colMerge,fRphiSigma);
f7336fa3 268 while ((smear[1] < col0 ) ||
269 (smear[1] > col0 + nColMax * colPadSize));
270
271 // Time direction stays unchanged
6f1e466d 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);
f7336fa3 278
279 // Add the smeared cluster to the output array
8230f242 280 Int_t detector = recPoint1->GetDetector();
f7336fa3 281 Int_t digits[3] = {0};
8230f242 282 trd->AddRecPoint(smear,digits,detector,0.0);
f7336fa3 283
284 }
285
286 // Clear the temporary cluster-array and delete the cluster
8230f242 287 chamberArray->Delete();
f7336fa3 288
289 }
290 }
291 }
292
293 printf("AliTRDclusterizerV0::MakeCluster -- ");
8230f242 294 printf("Found %d points.\n",trd->RecPoints()->GetEntries());
f7336fa3 295 printf("AliTRDclusterizerV0::MakeCluster -- ");
296 printf("Fill the cluster tree.\n");
8230f242 297 clusterTree->Fill();
f7336fa3 298
299 return kTRUE;
300
301}