]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinder.cxx
Various fixes in order to compile the DA source code
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.cxx
CommitLineData
b0f5e3fc 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 **************************************************************************/
04366a57 15////////////////////////////////////////////////////////////////////////////
16// //
17// Base Class used to find //
18// the reconstructed points for ITS //
19// See also AliITSClusterFinderSPD, AliITSClusterFinderSDD, //
20// AliITSClusterFinderSDD AliITSClusterFinderV2 //
21////////////////////////////////////////////////////////////////////////////
88cb7938 22
b0f5e3fc 23#include "AliITSClusterFinder.h"
04366a57 24#include "AliITSRecPoint.h"
7d62fb64 25#include "AliITSdigit.h"
26#include "AliITSDetTypeRec.h"
aacedc3e 27#include "AliITSMap.h"
1f3e997f 28#include "AliITSgeomTGeo.h"
b0f5e3fc 29
b0f5e3fc 30ClassImp(AliITSClusterFinder)
31
9de0700b 32//----------------------------------------------------------------------
aacedc3e 33AliITSClusterFinder::AliITSClusterFinder():
34TObject(),
35fDebug(0),
36fModule(0),
37fDigits(0),
38fNdigits(0),
8ba39da9 39fDetTypeRec(0),
aacedc3e 40fClusters(0),
41fNRawClusters(0),
42fMap(0),
43fNperMax(0),
44fDeclusterFlag(0),
45fClusterSize(0),
46fNPeaks(-1){
9de0700b 47 // default cluster finder
aacedc3e 48 // Input:
49 // none.
50 // Output:
51 // none.
52 // Return:
53 // A default constructed AliITSCulsterFinder
9de0700b 54}
55//----------------------------------------------------------------------
8ba39da9 56AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
aacedc3e 57TObject(),
58fDebug(0),
59fModule(0),
60fDigits(0),
61fNdigits(0),
e56160b8 62fDetTypeRec(dettyp),
aacedc3e 63fClusters(0),
64fNRawClusters(0),
65fMap(0),
66fNperMax(0),
67fDeclusterFlag(0),
68fClusterSize(0),
69fNPeaks(-1){
70 // Standard constructor for cluster finder
71 // Input:
72 // AliITSsegmentation *seg The segmentation class to be used
73 // AliITSresponse *res The response class to be used
74 // Output:
75 // none.
76 // Return:
77 // A Standard constructed AliITSCulsterFinder
b0f5e3fc 78
79 SetNperMax();
80 SetClusterSize();
81 SetDeclusterFlag();
aacedc3e 82}
83//----------------------------------------------------------------------
8ba39da9 84AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
85 TClonesArray *digits):
aacedc3e 86TObject(),
87fDebug(0),
88fModule(0),
89fDigits(digits),
90fNdigits(0),
8ba39da9 91fDetTypeRec(dettyp),
aacedc3e 92fClusters(0),
93fNRawClusters(0),
94fMap(0),
95fNperMax(0),
96fDeclusterFlag(0),
97fClusterSize(0),
98fNPeaks(-1){
99 // Standard + cluster finder constructor
100 // Input:
101 // AliITSsegmentation *seg The segmentation class to be used
102 // AliITSresponse *res The response class to be used
103 // TClonesArray *digits Array of digits to be used
104 // Output:
105 // none.
106 // Return:
107 // A Standard constructed AliITSCulsterFinder
b0f5e3fc 108
aacedc3e 109 fNdigits = fDigits->GetEntriesFast();
110 SetNperMax();
111 SetClusterSize();
112 SetDeclusterFlag();
b0f5e3fc 113}
e56160b8 114/*
04366a57 115//______________________________________________________________________
116AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source) {
117 // Copy constructor
118 // Copies are not allowed. The method is protected to avoid misuse.
119 Fatal("AliITSClusterFinder","Copy constructor not allowed\n");
120}
e56160b8 121*/
04366a57 122
123//______________________________________________________________________
e56160b8 124//AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
04366a57 125 // Assignment operator
126 // Assignment is not allowed. The method is protected to avoid misuse.
e56160b8 127// Fatal("= operator","Assignment operator not allowed\n");
128// return *this;
129//}
04366a57 130
9de0700b 131//----------------------------------------------------------------------
132AliITSClusterFinder::~AliITSClusterFinder(){
133 // destructor cluster finder
aacedc3e 134 // Input:
135 // none.
136 // Output:
137 // none.
138 // Return:
139 // none.
b0f5e3fc 140
aacedc3e 141 if(fMap) {delete fMap;}
9de0700b 142 // Zero local pointers. Other classes own these pointers.
9de0700b 143 fMap = 0;
144 fDigits = 0;
145 fNdigits = 0;
146 fNRawClusters = 0;
147 fNperMax = 0;
148 fDeclusterFlag= 0;
149 fClusterSize = 0;
150 fNPeaks = 0;
7d62fb64 151 fDetTypeRec = 0;
04366a57 152
7d62fb64 153}
b0f5e3fc 154//__________________________________________________________________________
7d62fb64 155void AliITSClusterFinder::InitGeometry(){
1f3e997f 156 //
157 // Initialisation of ITS geometry
158 //
159 Int_t mmax=AliITSgeomTGeo::GetNModules();
160 for (Int_t m=0; m<mmax; m++) {
161 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
162 const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(m);
163 fYshift[m] = (tm->Inverse()).GetTranslation()[1];
164 fZshift[m] = (tm->Inverse()).GetTranslation()[2];
165 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
04366a57 166 fNlayer[m] = lay-1;
167 }
b0f5e3fc 168}
04366a57 169
170
7d62fb64 171
9de0700b 172//----------------------------------------------------------------------
173void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
174 // Add a raw cluster copy to the list
aacedc3e 175 // Input:
176 // Int_t branch The branch to which the cluster is to be added to
177 // AliITSRawCluster *c The cluster to be added to the array of clusters
178 // Output:
179 // none.
180 // Return:
181 // none.
b0f5e3fc 182
7d62fb64 183 if(!fDetTypeRec) {
184 Error("AddCluster","fDetTypeRec is null!");
185 return;
186 }
187 fDetTypeRec->AddCluster(branch,c);
188 fNRawClusters++;
9355b256 189}
9de0700b 190//----------------------------------------------------------------------
191void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
192 AliITSRecPoint &rp){
aacedc3e 193 // Add a raw cluster copy to the list and the RecPoint
194 // Input:
195 // Int_t branch The branch to which the cluster is to be added to
196 // AliITSRawCluster *c The cluster to be added to the array of clusters
197 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
198 // Output:
199 // none.
200 // Return:
201 // none.
7d62fb64 202 if(!fDetTypeRec) {
203 Error("AddCluster","fDetTypeRec is null!");
204 return;
205 }
9355b256 206
7d62fb64 207 fDetTypeRec->AddCluster(branch,c);
208 fNRawClusters++;
209 fDetTypeRec->AddRecPoint(rp);
04366a57 210
7d62fb64 211}
212/*
04366a57 213//______________________________________________________________________
214void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
215 //------------------------------------------------------------
216 // Tries to find mother's labels
217 //------------------------------------------------------------
218
219 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
220 // Check if simulation
221 AliMC* mc = gAlice->GetMCApp();
222 if(!mc)return;
223
224 Int_t ntracks = mc->GetNtrack();
225 for (Int_t i=0;i<3;i++){
226 Int_t label = lab[i];
227 if (label>=0 && label<ntracks) {
228 TParticle *part=(TParticle*)mc->Particle(label);
229 if (part->P() < 0.005) {
230 Int_t m=part->GetFirstMother();
231 if (m<0) {
232 continue;
233 }
234 if (part->GetStatusCode()>0) {
235 continue;
236 }
237 lab[i]=m;
238 }
239 }
240 }
241
242}
7d62fb64 243*/
f8d9a5b8 244//______________________________________________________________________
245void AliITSClusterFinder::FindRawClusters(Int_t module){
246 // Default Cluster finder.
247 // Input:
248 // Int_t module Module number for which culster are to be found.
249 // Output:
250 // none.
251 // Return:
252 // none.
253 const Int_t kelms = 10;
254 Int_t ndigits = fDigits->GetEntriesFast();
255 TObjArray *digs = new TObjArray(ndigits);
256 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
257 TObjArray *clust0=0; // A spacific cluster of digits
258 TObjArray *clust1=0; // A spacific cluster of digits
259 AliITSdigit *dig=0; // locat pointer to a digit
f824982a 260 Int_t i=0,nc=0,j[4],k,k2=0;
f8d9a5b8 261
262 // Copy all digits for this module into a local TObjArray.
aacedc3e 263 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
f8d9a5b8 264 digs->Sort();
265 // First digit is a cluster.
266 i = 0;
267 nc = 0;
268 clusts->AddAt(new TObjArray(kelms),nc);
269 clust0 = (TObjArray*)(clusts->At(nc));
270 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
271 nc++;
272 for(i=1;i<ndigits;i++){
aacedc3e 273 if(IsNeighbor(digs,i,j)){
274 dig = (AliITSdigit*)(digs->At(j[0]));
275 // Add to existing cluster. Find which cluster this digis
276 for(k=0;k<nc;k++){
277 clust0 = ((TObjArray*)(clusts->At(k)));
278 if(clust0->IndexOf(dig)>=0) break;
279 } // end for k
280 if(k>=nc){
281 Fatal("FindRawClusters","Digit not found as expected");
282 } // end if
283 if(j[1]>=0){
284 dig = (AliITSdigit*)(digs->At(j[1]));
285 // Add to existing cluster. Find which cluster this digis
286 for(k2=0;k2<nc;k2++){
287 clust1 = ((TObjArray*)(clusts->At(k2)));
288 if(clust1->IndexOf(dig)>=0) break;
289 } // end for k2
290 if(k2>=nc){
291 Fatal("FindRawClusters","Digit not found as expected");
292 } // end if
293 } // end if j[1]>=0
294 // Found cluster with neighboring digits add this one to it.
295 if(clust0==clust1){ // same cluster
296 clust0->AddAtFree(digs->At(i));
297 clust0 = 0; // finished with cluster. zero for safty
298 clust1 = 0; // finished wit hcluster. zero for safty
299 }else{ // two different clusters which need to be merged.
300 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
301 for(k=0;k<clust1->GetEntriesFast();k++){
302 // move clust1 into clust0
303 //move digit to this cluster
304 clust0->AddAtFree(clust1->At(k));
305 clust1->AddAt(0,k); // zero this one
306 } // end for k
307 delete clust1;
308 clusts->AddAt(0,k2); // zero array of clusters element clust1
309 clust0 = 0; // finished with cluster. zero for safty
310 clust1 = 0; // finished wit hcluster. zero for safty
311 } // end if clust0==clust1
312 }else{// New cluster
313 clusts->AddAt(new TObjArray(kelms),nc);
314 clust0 = ((TObjArray*)(clusts->At(nc)));
315 // move owner ship from digs to clusts
316 clust0->AddAtFree(digs->At(i));
317 clust0 = 0; // finished with cluster. zero for safty
318 nc++;
319 } // End if IsNeighbor
f8d9a5b8 320 } // end for i
321 // There are now nc clusters in clusts. Each element of clust is an
322 // array of digits which are clustered together.
323
324 // For each cluster call detector specific CreateRecPoints
325 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
326
327 // clean up at the end.
328 for(i=0;i<nc;i++){
aacedc3e 329 clust0 =(TObjArray*)(clusts->At(i));
330 // Digits deleted below, so zero this TObjArray
331 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
332 delete clust0; // Delete this TObjArray
333 clusts->AddAt(0,i); // Contents deleted above, so zero it.
f8d9a5b8 334 } // end for i
335 delete clusts; // Delete this TObjArray/
336 // Delete the digits then the TObjArray which containted them.
337 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
338 delete digs;
339}
340//______________________________________________________________________
aacedc3e 341Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
f8d9a5b8 342 // Locagical function which checks to see if digit i has a neighbor.
343 // If so, then it returns kTRUE and its neighbor index j.
344 // This routine checks if the digits are side by side or one before the
345 // other. Requires that the array of digits be in proper order.
346 // Returns kTRUE in the following cases.
347 // ji 0j if kdiagonal j0 0i
348 // 00 0i if kdiagonal 0i j0
349 // Inputs:
350 // TObjArray *digs Array to search for neighbors in
351 // Int_t i Index of digit for which we are searching for
352 // a neighbor of.
353 // Output:
354 // Int_t j[4] Index of one or more of the digits which is a
355 // neighbor of digit a index i.
356 // Return:
357 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
358 Int_t ix,jx,iz,jz,j;
359 const Bool_t kdiagonal=kFALSE;
360 Bool_t nei[4];
361
362 // No neighbors found if array empty.
363 if(digs->GetEntriesFast()<=0) return kFALSE;
364 // can not be a digit with first element or elements out or range
365 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
366
367 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
368 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
369 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
370 for(j=0;j<i;j++){
aacedc3e 371 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
372 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
373 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
374 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
375 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
376 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
f8d9a5b8 377 } // end for k
378 if(nei[0]||nei[1]) return kTRUE;
379 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
380 // no Neighbors found.
381 return kFALSE;
382}
aacedc3e 383
384//______________________________________________________________________
7d62fb64 385void AliITSClusterFinder::Print(ostream *os) const{
aacedc3e 386 //Standard output format for this class
387 // Inputs:
388 // ostream *os Output stream
389 // Output:
390 // ostream *os Output stream
391 // Return:
392 // none.
393
394 *os << fDebug<<",";
395 *os << fModule<<",";
396 *os << fNdigits<<",";
397 *os << fNRawClusters<<",";
398 *os << fNperMax<<",";
399 *os << fDeclusterFlag<<",";
400 *os << fClusterSize<<",";
401 *os << fNPeaks<<endl;
402}
403//______________________________________________________________________
7d62fb64 404void AliITSClusterFinder::Read(istream *is) {
aacedc3e 405 //Standard input for this class
406 // Inputs:
407 // istream *is Input stream
408 // Output:
409 // istream *is Input stream
410 // Return:
411 // none.
412
413 *is >> fDebug;
414 *is >> fModule;
415 *is >> fNdigits;
416 *is >> fNRawClusters;
417 *is >> fNperMax;
418 *is >> fDeclusterFlag;
419 *is >> fClusterSize;
420 *is >> fNPeaks;
421}
422//______________________________________________________________________
423ostream &operator<<(ostream &os,AliITSClusterFinder &source){
424 // Standard output streaming function.
425 // Inputs:
426 // ostream *os Output stream
427 // AliITSClusterFinder &source Class to be printed
428 // Output:
429 // ostream *os Output stream
430 // Return:
431 // none.
432
433 source.Print(&os);
434 return os;
435}
436//______________________________________________________________________
437istream &operator>>(istream &is,AliITSClusterFinder &source){
438 // Standard output streaming function.
439 // Inputs:
440 // istream *is Input stream
441 // AliITSClusterFinder &source Class to be read in.
442 // Output:
443 // istream *is Input stream
444 // Return:
445 // none.
446
447 source.Read(&is);
448 return is;
449}