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 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);
172 //----------------------------------------------------------------------
173 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
174 // Add a raw cluster copy to the list
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
184 Error("AddCluster","fDetTypeRec is null!");
187 fDetTypeRec->AddCluster(branch,c);
190 //----------------------------------------------------------------------
191 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
193 // Add a raw cluster copy to the list and the RecPoint
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
203 Error("AddCluster","fDetTypeRec is null!");
207 fDetTypeRec->AddCluster(branch,c);
209 fDetTypeRec->AddRecPoint(rp);
213 //______________________________________________________________________
214 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
215 //------------------------------------------------------------
216 // Tries to find mother's labels
217 //------------------------------------------------------------
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();
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();
234 if (part->GetStatusCode()>0) {
244 //______________________________________________________________________
245 void AliITSClusterFinder::FindRawClusters(Int_t module){
246 // Default Cluster finder.
248 // Int_t module Module number for which culster are to be found.
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
260 Int_t i=0,nc=0,j[4],k,k2=0;
262 // Copy all digits for this module into a local TObjArray.
263 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
265 // First digit is a cluster.
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
272 for(i=1;i<ndigits;i++){
273 if(IsNeighbor(digs,i,j)){
274 dig = (AliITSdigit*)(digs->At(j[0]));
275 // Add to existing cluster. Find which cluster this digis
277 clust0 = ((TObjArray*)(clusts->At(k)));
278 if(clust0->IndexOf(dig)>=0) break;
281 Fatal("FindRawClusters","Digit not found as expected");
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;
291 Fatal("FindRawClusters","Digit not found as expected");
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
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
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
319 } // End if IsNeighbor
321 // There are now nc clusters in clusts. Each element of clust is an
322 // array of digits which are clustered together.
324 // For each cluster call detector specific CreateRecPoints
325 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
327 // clean up at the end.
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.
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)));
340 //______________________________________________________________________
341 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
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
350 // TObjArray *digs Array to search for neighbors in
351 // Int_t i Index of digit for which we are searching for
354 // Int_t j[4] Index of one or more of the digits which is a
355 // neighbor of digit a index i.
357 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
359 const Bool_t kdiagonal=kFALSE;
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;
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();
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;}
378 if(nei[0]||nei[1]) return kTRUE;
379 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
380 // no Neighbors found.
384 //______________________________________________________________________
385 void AliITSClusterFinder::Print(ostream *os) const{
386 //Standard output format for this class
388 // ostream *os Output stream
390 // ostream *os Output stream
396 *os << fNdigits<<",";
397 *os << fNRawClusters<<",";
398 *os << fNperMax<<",";
399 *os << fDeclusterFlag<<",";
400 *os << fClusterSize<<",";
401 *os << fNPeaks<<endl;
403 //______________________________________________________________________
404 void AliITSClusterFinder::Read(istream *is) {
405 //Standard input for this class
407 // istream *is Input stream
409 // istream *is Input stream
416 *is >> fNRawClusters;
418 *is >> fDeclusterFlag;
422 //______________________________________________________________________
423 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
424 // Standard output streaming function.
426 // ostream *os Output stream
427 // AliITSClusterFinder &source Class to be printed
429 // ostream *os Output stream
436 //______________________________________________________________________
437 istream &operator>>(istream &is,AliITSClusterFinder &source){
438 // Standard output streaming function.
440 // istream *is Input stream
441 // AliITSClusterFinder &source Class to be read in.
443 // istream *is Input stream