1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 ////////////////////////////////////////////////////////////////////////////
17 // Base Class used to find //
18 // the reconstructed points for ITS //
19 // See also AliITSClusterFinderSPD, AliITSClusterFinderSDD, //
20 // AliITSClusterFinderSDD AliITSClusterFinderV2 //
21 ////////////////////////////////////////////////////////////////////////////
24 #include "AliITSClusterFinder.h"
25 #include "AliITSRecPoint.h"
26 #include "AliITSdigit.h"
27 #include "AliITSDetTypeRec.h"
28 #include "AliITSMap.h"
29 #include "AliITSgeomTGeo.h"
30 #include <TParticle.h>
37 ClassImp(AliITSClusterFinder)
39 extern AliRun *gAlice;
41 //----------------------------------------------------------------------
42 AliITSClusterFinder::AliITSClusterFinder():
51 fNModules(AliITSgeomTGeo::GetNModules()),
60 // default cluster finder
66 // A default constructed AliITSCulsterFinder
67 for(Int_t i=0; i<2200; i++){
72 //----------------------------------------------------------------------
73 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
82 fNModules(AliITSgeomTGeo::GetNModules()),
91 // default cluster finder
92 // Standard constructor for cluster finder
94 // AliITSsegmentation *seg The segmentation class to be used
95 // AliITSresponse *res The response class to be used
99 // A Standard constructed AliITSCulsterFinder
100 for(Int_t i=0; i<2200; i++){
105 //----------------------------------------------------------------------
106 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
107 TClonesArray *digits):
116 fNModules(AliITSgeomTGeo::GetNModules()),
125 // default cluster finder
126 // Standard + cluster finder constructor
128 // AliITSsegmentation *seg The segmentation class to be used
129 // AliITSresponse *res The response class to be used
130 // TClonesArray *digits Array of digits to be used
134 // A Standard constructed AliITSCulsterFinder
136 fNdigits = fDigits->GetEntriesFast();
137 for(Int_t i=0; i<2200; i++){
143 //______________________________________________________________________
144 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) :
146 fModule(source.fModule),
148 fNdigits(source.fNdigits),
152 fNPeaks(source.fNPeaks),
153 fNModules(source.fNModules),
154 fEvent(source.fEvent),
159 fNClusters(source.fNClusters),
160 fRawID2ClusID(source.fRawID2ClusID)
163 // Copies are not allowed. The method is protected to avoid misuse.
164 AliError("Copy constructor not allowed\n");
168 //______________________________________________________________________
169 //AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
170 // Assignment operator
171 // Assignment is not allowed. The method is protected to avoid misuse.
172 // Fatal("= operator","Assignment operator not allowed\n");
176 //----------------------------------------------------------------------
177 AliITSClusterFinder::~AliITSClusterFinder(){
178 // destructor cluster finder
186 if(fMap) {delete fMap;}
187 // Zero local pointers. Other classes own these pointers.
195 //__________________________________________________________________________
196 void AliITSClusterFinder::InitGeometry(){
198 // Initialisation of ITS geometry
200 Int_t mmax=AliITSgeomTGeo::GetNModules();
201 for (Int_t m=0; m<mmax; m++) {
202 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
203 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
211 //______________________________________________________________________
212 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
213 // Locagical function which checks to see if digit i has a neighbor.
214 // If so, then it returns kTRUE and its neighbor index j.
215 // This routine checks if the digits are side by side or one before the
216 // other. Requires that the array of digits be in proper order.
217 // Returns kTRUE in the following cases.
218 // ji 0j if kdiagonal j0 0i
219 // 00 0i if kdiagonal 0i j0
221 // TObjArray *digs Array to search for neighbors in
222 // Int_t i Index of digit for which we are searching for
225 // Int_t j[4] Index of one or more of the digits which is a
226 // neighbor of digit a index i.
228 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
230 const Bool_t kdiagonal=kFALSE;
233 // No neighbors found if array empty.
234 if(digs->GetEntriesFast()<=0) return kFALSE;
235 // can not be a digit with first element or elements out or range
236 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
238 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
239 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
240 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
242 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
243 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
244 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
245 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
246 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
247 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
249 if(nei[0]||nei[1]) return kTRUE;
250 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
251 // no Neighbors found.
255 //______________________________________________________________________
256 void AliITSClusterFinder::Print(ostream *os) const{
257 //Standard output format for this class
259 // ostream *os Output stream
261 // ostream *os Output stream
266 *os << fNdigits<<",";
267 *os << fNPeaks<<endl;
269 //______________________________________________________________________
270 void AliITSClusterFinder::Read(istream *is) {
271 //Standard input for this class
273 // istream *is Input stream
275 // istream *is Input stream
283 //______________________________________________________________________
284 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
285 // Standard output streaming function.
287 // ostream *os Output stream
288 // AliITSClusterFinder &source Class to be printed
290 // ostream *os Output stream
297 //______________________________________________________________________
298 istream &operator>>(istream &is,AliITSClusterFinder &source){
299 // Standard output streaming function.
301 // istream *is Input stream
302 // AliITSClusterFinder &source Class to be read in.
304 // istream *is Input stream
312 //______________________________________________________________________
313 void AliITSClusterFinder::CheckLabels2(Int_t lab[10])
315 //------------------------------------------------------------
316 // Tries to find mother's labels
317 //------------------------------------------------------------
318 AliRunLoader *rl = AliRunLoader::Instance();
320 TTree *trK=(TTree*)rl->TreeK();
325 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
326 for (Int_t i=0;i<10;i++) if (lab[i]>=0) labS[nlabels++] = lab[i];
327 if (nlabels==0) return;
330 for (Int_t i=0;i<nlabels;i++) {
331 Int_t label = labS[i];
333 if (label>=ntracks) continue;
334 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
336 if (part->P() < 0.02) { // reduce soft particles from the same cluster
337 Int_t m=part->GetFirstMother();
338 if (m<0) continue; // primary
340 if (part->GetStatusCode()>0) continue;
342 // if the parent is within the same cluster, reassign the label to it
343 for (int j=0;j<nlabels;j++) if (labS[j]==m) { labS[i] = m; break; }
347 if (nlabels>3) { // only 3 labels are stored in cluster, sort in decreasing momentum
348 int ind[10],labSS[10];
349 TMath::Sort(nlabels,mom,ind);
350 for (int i=nlabels;i--;) labSS[i] = labS[i];
351 for (int i=0;i<nlabels;i++) labS[i] = labSS[ind[i]];
354 //compress labels -- if multi-times the same
355 for (Int_t i=0;i<10;i++) lab[i]=-2;
357 for (int i=0;i<nlabels;i++) {
358 for (j=0;j<nlabFin;j++) if (labS[i]==lab[j]) break; // the label already there
359 if (j==nlabFin) lab[nlabFin++] = labS[i];
364 //______________________________________________________________________
365 void AliITSClusterFinder::AddLabel(Int_t lab[10], Int_t label) {
366 //add label to the cluster
367 AliRunLoader *rl = AliRunLoader::Instance();
368 TTree *trK=(TTree*)rl->TreeK();
370 if(label<0) return; // In case of no label just exit
372 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
373 if (label>ntracks) return;
374 for (Int_t i=0;i<10;i++){
375 // if (label<0) break;
376 if (lab[i]==label) break;
386 //______________________________________________________________________
387 void AliITSClusterFinder::
388 FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
389 //------------------------------------------------------------
390 // returns an array of indices of digits belonging to the cluster
391 // (needed when the segmentation is not regular)
392 //------------------------------------------------------------
393 if (n<200) idx[n++]=bins[k].GetIndex();
396 if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
397 if (bins[k-1 ].IsNotUsed()) FindCluster(k-1 ,maxz,bins,n,idx);
398 if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
399 if (bins[k+1 ].IsNotUsed()) FindCluster(k+1 ,maxz,bins,n,idx);
401 if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
402 if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
403 if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
404 if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
408 //______________________________________________________________________
409 Bool_t AliITSClusterFinder::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
410 //------------------------------------------------------------
411 //is this a local maximum ?
412 //------------------------------------------------------------
413 UShort_t q=bins[k].GetQ();
414 if (q==1023) return kFALSE;
415 if (bins[k-max].GetQ() > q) return kFALSE;
416 if (bins[k-1 ].GetQ() > q) return kFALSE;
417 if (bins[k+max].GetQ() > q) return kFALSE;
418 if (bins[k+1 ].GetQ() > q) return kFALSE;
419 if (bins[k-max-1].GetQ() > q) return kFALSE;
420 if (bins[k+max-1].GetQ() > q) return kFALSE;
421 if (bins[k+max+1].GetQ() > q) return kFALSE;
422 if (bins[k-max+1].GetQ() > q) return kFALSE;
426 //______________________________________________________________________
427 void AliITSClusterFinder::
428 FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
429 //------------------------------------------------------------
431 //------------------------------------------------------------
433 if (IsMaximum(k,max,b)) {
434 idx[n]=k; msk[n]=(2<<n);
438 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
439 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
440 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
441 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
444 //______________________________________________________________________
445 void AliITSClusterFinder::
446 MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
447 //------------------------------------------------------------
449 //------------------------------------------------------------
450 UShort_t q=bins[k].GetQ();
452 bins[k].SetMask(bins[k].GetMask()|m);
454 if (bins[k-max].GetQ() <= q)
455 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
456 if (bins[k-1 ].GetQ() <= q)
457 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
458 if (bins[k+max].GetQ() <= q)
459 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
460 if (bins[k+1 ].GetQ() <= q)
461 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
464 //______________________________________________________________________
465 void AliITSClusterFinder::
466 MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSRecPoint &c) {
467 //------------------------------------------------------------
468 //make cluster using digits of this peak
469 //------------------------------------------------------------
470 Float_t q=(Float_t)bins[k].GetQ();
471 Int_t i=k/max, j=k-i*max;
472 if(c.GetQ()<0.01){ // first entry in cluster
477 }else{ // check cluster extension
484 c.SetY(c.GetY()+i*q);
485 c.SetZ(c.GetZ()+j*q);
486 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
487 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
489 bins[k].SetMask(0xFFFFFFFE);
490 if (fRawID2ClusID) { // RS: Register cluster id in raw words list
491 int rwid = bins[k].GetRawID();
492 if (fRawID2ClusID->GetSize()<=rwid) fRawID2ClusID->Set( (rwid+10)<<1 );
493 (*fRawID2ClusID)[rwid] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
495 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
496 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
497 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
498 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);