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