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 ////////////////////////////////////////////////////////////////////////////
23 #include "AliITSClusterFinder.h"
24 #include "AliITSRecPoint.h"
25 #include "AliITSdigit.h"
26 #include "AliITSDetTypeRec.h"
27 #include "AliITSMap.h"
28 #include "AliITSgeomTGeo.h"
30 ClassImp(AliITSClusterFinder)
32 //----------------------------------------------------------------------
33 AliITSClusterFinder::AliITSClusterFinder():
47 // default cluster finder
53 // A default constructed AliITSCulsterFinder
55 //----------------------------------------------------------------------
56 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
70 // Standard constructor for cluster finder
72 // AliITSsegmentation *seg The segmentation class to be used
73 // AliITSresponse *res The response class to be used
77 // A Standard constructed AliITSCulsterFinder
83 //----------------------------------------------------------------------
84 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
85 TClonesArray *digits):
99 // Standard + cluster finder constructor
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
107 // A Standard constructed AliITSCulsterFinder
109 fNdigits = fDigits->GetEntriesFast();
115 //______________________________________________________________________
116 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source),
117 fDebug(source.fDebug),
118 fModule(source.fModule),
120 fNdigits(source.fNdigits),
123 fNRawClusters(source.fNRawClusters),
125 fNperMax(source.fNperMax),
126 fDeclusterFlag(source.fDeclusterFlag),
127 fClusterSize(source.fClusterSize),
128 fNPeaks(source.fNPeaks) {
130 // Copies are not allowed. The method is protected to avoid misuse.
131 AliError("Copy constructor not allowed\n");
135 //______________________________________________________________________
136 //AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
137 // Assignment operator
138 // Assignment is not allowed. The method is protected to avoid misuse.
139 // Fatal("= operator","Assignment operator not allowed\n");
143 //----------------------------------------------------------------------
144 AliITSClusterFinder::~AliITSClusterFinder(){
145 // destructor cluster finder
153 if(fMap) {delete fMap;}
154 // Zero local pointers. Other classes own these pointers.
166 //__________________________________________________________________________
167 void AliITSClusterFinder::InitGeometry(){
169 // Initialisation of ITS geometry
171 Int_t mmax=AliITSgeomTGeo::GetNModules();
172 for (Int_t m=0; m<mmax; m++) {
173 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
174 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
181 //----------------------------------------------------------------------
182 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
183 // Add a raw cluster copy to the list
185 // Int_t branch The branch to which the cluster is to be added to
186 // AliITSRawCluster *c The cluster to be added to the array of clusters
193 Error("AddCluster","fDetTypeRec is null!");
196 fDetTypeRec->AddCluster(branch,c);
199 //----------------------------------------------------------------------
200 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
202 // Add a raw cluster copy to the list and the RecPoint
204 // Int_t branch The branch to which the cluster is to be added to
205 // AliITSRawCluster *c The cluster to be added to the array of clusters
206 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
212 Error("AddCluster","fDetTypeRec is null!");
216 fDetTypeRec->AddCluster(branch,c);
218 fDetTypeRec->AddRecPoint(rp);
222 //______________________________________________________________________
223 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
224 //------------------------------------------------------------
225 // Tries to find mother's labels
226 //------------------------------------------------------------
228 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
229 // Check if simulation
230 AliMC* mc = gAlice->GetMCApp();
233 Int_t ntracks = mc->GetNtrack();
234 for (Int_t i=0;i<3;i++){
235 Int_t label = lab[i];
236 if (label>=0 && label<ntracks) {
237 TParticle *part=(TParticle*)mc->Particle(label);
238 if (part->P() < 0.005) {
239 Int_t m=part->GetFirstMother();
243 if (part->GetStatusCode()>0) {
253 //______________________________________________________________________
254 void AliITSClusterFinder::FindRawClusters(Int_t module){
255 // Default Cluster finder.
257 // Int_t module Module number for which culster are to be found.
262 const Int_t kelms = 10;
263 Int_t ndigits = fDigits->GetEntriesFast();
264 TObjArray *digs = new TObjArray(ndigits);
265 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
266 TObjArray *clust0=0; // A spacific cluster of digits
267 TObjArray *clust1=0; // A spacific cluster of digits
268 AliITSdigit *dig=0; // locat pointer to a digit
269 Int_t i=0,nc=0,j[4],k,k2=0;
271 // Copy all digits for this module into a local TObjArray.
272 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
274 // First digit is a cluster.
277 clusts->AddAt(new TObjArray(kelms),nc);
278 clust0 = (TObjArray*)(clusts->At(nc));
279 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
281 for(i=1;i<ndigits;i++){
282 if(IsNeighbor(digs,i,j)){
283 dig = (AliITSdigit*)(digs->At(j[0]));
284 // Add to existing cluster. Find which cluster this digis
286 clust0 = ((TObjArray*)(clusts->At(k)));
287 if(clust0->IndexOf(dig)>=0) break;
290 Fatal("FindRawClusters","Digit not found as expected");
293 dig = (AliITSdigit*)(digs->At(j[1]));
294 // Add to existing cluster. Find which cluster this digis
295 for(k2=0;k2<nc;k2++){
296 clust1 = ((TObjArray*)(clusts->At(k2)));
297 if(clust1->IndexOf(dig)>=0) break;
300 Fatal("FindRawClusters","Digit not found as expected");
303 // Found cluster with neighboring digits add this one to it.
304 if(clust0==clust1){ // same cluster
305 clust0->AddAtFree(digs->At(i));
306 clust0 = 0; // finished with cluster. zero for safty
307 clust1 = 0; // finished wit hcluster. zero for safty
308 }else{ // two different clusters which need to be merged.
309 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
310 for(k=0;k<clust1->GetEntriesFast();k++){
311 // move clust1 into clust0
312 //move digit to this cluster
313 clust0->AddAtFree(clust1->At(k));
314 clust1->AddAt(0,k); // zero this one
317 clusts->AddAt(0,k2); // zero array of clusters element clust1
318 clust0 = 0; // finished with cluster. zero for safty
319 clust1 = 0; // finished wit hcluster. zero for safty
320 } // end if clust0==clust1
322 clusts->AddAt(new TObjArray(kelms),nc);
323 clust0 = ((TObjArray*)(clusts->At(nc)));
324 // move owner ship from digs to clusts
325 clust0->AddAtFree(digs->At(i));
326 clust0 = 0; // finished with cluster. zero for safty
328 } // End if IsNeighbor
330 // There are now nc clusters in clusts. Each element of clust is an
331 // array of digits which are clustered together.
333 // For each cluster call detector specific CreateRecPoints
334 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
336 // clean up at the end.
338 clust0 =(TObjArray*)(clusts->At(i));
339 // Digits deleted below, so zero this TObjArray
340 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
341 delete clust0; // Delete this TObjArray
342 clusts->AddAt(0,i); // Contents deleted above, so zero it.
344 delete clusts; // Delete this TObjArray/
345 // Delete the digits then the TObjArray which containted them.
346 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
349 //______________________________________________________________________
350 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
351 // Locagical function which checks to see if digit i has a neighbor.
352 // If so, then it returns kTRUE and its neighbor index j.
353 // This routine checks if the digits are side by side or one before the
354 // other. Requires that the array of digits be in proper order.
355 // Returns kTRUE in the following cases.
356 // ji 0j if kdiagonal j0 0i
357 // 00 0i if kdiagonal 0i j0
359 // TObjArray *digs Array to search for neighbors in
360 // Int_t i Index of digit for which we are searching for
363 // Int_t j[4] Index of one or more of the digits which is a
364 // neighbor of digit a index i.
366 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
368 const Bool_t kdiagonal=kFALSE;
371 // No neighbors found if array empty.
372 if(digs->GetEntriesFast()<=0) return kFALSE;
373 // can not be a digit with first element or elements out or range
374 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
376 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
377 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
378 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
380 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
381 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
382 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
383 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
384 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
385 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
387 if(nei[0]||nei[1]) return kTRUE;
388 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
389 // no Neighbors found.
393 //______________________________________________________________________
394 void AliITSClusterFinder::Print(ostream *os) const{
395 //Standard output format for this class
397 // ostream *os Output stream
399 // ostream *os Output stream
405 *os << fNdigits<<",";
406 *os << fNRawClusters<<",";
407 *os << fNperMax<<",";
408 *os << fDeclusterFlag<<",";
409 *os << fClusterSize<<",";
410 *os << fNPeaks<<endl;
412 //______________________________________________________________________
413 void AliITSClusterFinder::Read(istream *is) {
414 //Standard input for this class
416 // istream *is Input stream
418 // istream *is Input stream
425 *is >> fNRawClusters;
427 *is >> fDeclusterFlag;
431 //______________________________________________________________________
432 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
433 // Standard output streaming function.
435 // ostream *os Output stream
436 // AliITSClusterFinder &source Class to be printed
438 // ostream *os Output stream
445 //______________________________________________________________________
446 istream &operator>>(istream &is,AliITSClusterFinder &source){
447 // Standard output streaming function.
449 // istream *is Input stream
450 // AliITSClusterFinder &source Class to be read in.
452 // istream *is Input stream