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) {
118 // Copies are not allowed. The method is protected to avoid misuse.
119 Fatal("AliITSClusterFinder","Copy constructor not allowed\n");
123 //______________________________________________________________________
124 //AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
125 // Assignment operator
126 // Assignment is not allowed. The method is protected to avoid misuse.
127 // Fatal("= operator","Assignment operator not allowed\n");
131 //----------------------------------------------------------------------
132 AliITSClusterFinder::~AliITSClusterFinder(){
133 // destructor cluster finder
141 if(fMap) {delete fMap;}
142 // Zero local pointers. Other classes own these pointers.
154 //__________________________________________________________________________
155 void AliITSClusterFinder::InitGeometry(){
157 // Initialisation of ITS geometry
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 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
169 //----------------------------------------------------------------------
170 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
171 // Add a raw cluster copy to the list
173 // Int_t branch The branch to which the cluster is to be added to
174 // AliITSRawCluster *c The cluster to be added to the array of clusters
181 Error("AddCluster","fDetTypeRec is null!");
184 fDetTypeRec->AddCluster(branch,c);
187 //----------------------------------------------------------------------
188 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
190 // Add a raw cluster copy to the list and the RecPoint
192 // Int_t branch The branch to which the cluster is to be added to
193 // AliITSRawCluster *c The cluster to be added to the array of clusters
194 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
200 Error("AddCluster","fDetTypeRec is null!");
204 fDetTypeRec->AddCluster(branch,c);
206 fDetTypeRec->AddRecPoint(rp);
210 //______________________________________________________________________
211 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
212 //------------------------------------------------------------
213 // Tries to find mother's labels
214 //------------------------------------------------------------
216 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
217 // Check if simulation
218 AliMC* mc = gAlice->GetMCApp();
221 Int_t ntracks = mc->GetNtrack();
222 for (Int_t i=0;i<3;i++){
223 Int_t label = lab[i];
224 if (label>=0 && label<ntracks) {
225 TParticle *part=(TParticle*)mc->Particle(label);
226 if (part->P() < 0.005) {
227 Int_t m=part->GetFirstMother();
231 if (part->GetStatusCode()>0) {
241 //______________________________________________________________________
242 void AliITSClusterFinder::FindRawClusters(Int_t module){
243 // Default Cluster finder.
245 // Int_t module Module number for which culster are to be found.
250 const Int_t kelms = 10;
251 Int_t ndigits = fDigits->GetEntriesFast();
252 TObjArray *digs = new TObjArray(ndigits);
253 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
254 TObjArray *clust0=0; // A spacific cluster of digits
255 TObjArray *clust1=0; // A spacific cluster of digits
256 AliITSdigit *dig=0; // locat pointer to a digit
257 Int_t i=0,nc=0,j[4],k,k2=0;
259 // Copy all digits for this module into a local TObjArray.
260 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
262 // First digit is a cluster.
265 clusts->AddAt(new TObjArray(kelms),nc);
266 clust0 = (TObjArray*)(clusts->At(nc));
267 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
269 for(i=1;i<ndigits;i++){
270 if(IsNeighbor(digs,i,j)){
271 dig = (AliITSdigit*)(digs->At(j[0]));
272 // Add to existing cluster. Find which cluster this digis
274 clust0 = ((TObjArray*)(clusts->At(k)));
275 if(clust0->IndexOf(dig)>=0) break;
278 Fatal("FindRawClusters","Digit not found as expected");
281 dig = (AliITSdigit*)(digs->At(j[1]));
282 // Add to existing cluster. Find which cluster this digis
283 for(k2=0;k2<nc;k2++){
284 clust1 = ((TObjArray*)(clusts->At(k2)));
285 if(clust1->IndexOf(dig)>=0) break;
288 Fatal("FindRawClusters","Digit not found as expected");
291 // Found cluster with neighboring digits add this one to it.
292 if(clust0==clust1){ // same cluster
293 clust0->AddAtFree(digs->At(i));
294 clust0 = 0; // finished with cluster. zero for safty
295 clust1 = 0; // finished wit hcluster. zero for safty
296 }else{ // two different clusters which need to be merged.
297 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
298 for(k=0;k<clust1->GetEntriesFast();k++){
299 // move clust1 into clust0
300 //move digit to this cluster
301 clust0->AddAtFree(clust1->At(k));
302 clust1->AddAt(0,k); // zero this one
305 clusts->AddAt(0,k2); // zero array of clusters element clust1
306 clust0 = 0; // finished with cluster. zero for safty
307 clust1 = 0; // finished wit hcluster. zero for safty
308 } // end if clust0==clust1
310 clusts->AddAt(new TObjArray(kelms),nc);
311 clust0 = ((TObjArray*)(clusts->At(nc)));
312 // move owner ship from digs to clusts
313 clust0->AddAtFree(digs->At(i));
314 clust0 = 0; // finished with cluster. zero for safty
316 } // End if IsNeighbor
318 // There are now nc clusters in clusts. Each element of clust is an
319 // array of digits which are clustered together.
321 // For each cluster call detector specific CreateRecPoints
322 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
324 // clean up at the end.
326 clust0 =(TObjArray*)(clusts->At(i));
327 // Digits deleted below, so zero this TObjArray
328 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
329 delete clust0; // Delete this TObjArray
330 clusts->AddAt(0,i); // Contents deleted above, so zero it.
332 delete clusts; // Delete this TObjArray/
333 // Delete the digits then the TObjArray which containted them.
334 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
337 //______________________________________________________________________
338 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
339 // Locagical function which checks to see if digit i has a neighbor.
340 // If so, then it returns kTRUE and its neighbor index j.
341 // This routine checks if the digits are side by side or one before the
342 // other. Requires that the array of digits be in proper order.
343 // Returns kTRUE in the following cases.
344 // ji 0j if kdiagonal j0 0i
345 // 00 0i if kdiagonal 0i j0
347 // TObjArray *digs Array to search for neighbors in
348 // Int_t i Index of digit for which we are searching for
351 // Int_t j[4] Index of one or more of the digits which is a
352 // neighbor of digit a index i.
354 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
356 const Bool_t kdiagonal=kFALSE;
359 // No neighbors found if array empty.
360 if(digs->GetEntriesFast()<=0) return kFALSE;
361 // can not be a digit with first element or elements out or range
362 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
364 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
365 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
366 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
368 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
369 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
370 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
371 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
372 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
373 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
375 if(nei[0]||nei[1]) return kTRUE;
376 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
377 // no Neighbors found.
381 //______________________________________________________________________
382 void AliITSClusterFinder::Print(ostream *os) const{
383 //Standard output format for this class
385 // ostream *os Output stream
387 // ostream *os Output stream
393 *os << fNdigits<<",";
394 *os << fNRawClusters<<",";
395 *os << fNperMax<<",";
396 *os << fDeclusterFlag<<",";
397 *os << fClusterSize<<",";
398 *os << fNPeaks<<endl;
400 //______________________________________________________________________
401 void AliITSClusterFinder::Read(istream *is) {
402 //Standard input for this class
404 // istream *is Input stream
406 // istream *is Input stream
413 *is >> fNRawClusters;
415 *is >> fDeclusterFlag;
419 //______________________________________________________________________
420 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
421 // Standard output streaming function.
423 // ostream *os Output stream
424 // AliITSClusterFinder &source Class to be printed
426 // ostream *os Output stream
433 //______________________________________________________________________
434 istream &operator>>(istream &is,AliITSClusterFinder &source){
435 // Standard output streaming function.
437 // istream *is Input stream
438 // AliITSClusterFinder &source Class to be read in.
440 // istream *is Input stream