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 "AliITSclusterV2.h"
25 #include "AliITSRecPoint.h"
26 #include "AliITSdigitSPD.h"
27 #include "AliITSdigitSDD.h"
28 #include "AliITSdigitSSD.h"
29 #include "AliITSgeom.h"
30 #include "AliITSMap.h"
34 #include "TParticle.h"
36 ClassImp(AliITSClusterFinder)
38 //----------------------------------------------------------------------
39 AliITSClusterFinder::AliITSClusterFinder():
54 // default cluster finder
60 // A default constructed AliITSCulsterFinder
63 //----------------------------------------------------------------------
64 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
80 // Standard constructor for cluster finder
82 // AliITSsegmentation *seg The segmentation class to be used
83 // AliITSresponse *res The response class to be used
87 // A Standard constructed AliITSCulsterFinder
94 //----------------------------------------------------------------------
95 AliITSClusterFinder::AliITSClusterFinder(AliITSsegmentation *seg,
96 AliITSresponse *response,
97 TClonesArray *digits):
112 // Standard + cluster finder constructor
114 // AliITSsegmentation *seg The segmentation class to be used
115 // AliITSresponse *res The response class to be used
116 // TClonesArray *digits Array of digits to be used
120 // A Standard constructed AliITSCulsterFinder
122 fNdigits = fDigits->GetEntriesFast();
128 //______________________________________________________________________
129 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source) {
131 // Copies are not allowed. The method is protected to avoid misuse.
132 Fatal("AliITSClusterFinder","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.
168 //__________________________________________________________________________
169 void AliITSClusterFinder::Init(){
171 //Initialisation of ITS geometry
173 fITS = (AliITS*)gAlice->GetModule("ITS");
174 AliITSgeom *geom=(AliITSgeom*)fITS->GetITSgeom();
176 Int_t mmax=geom->GetIndexMax();
178 Fatal("AliITSClusterFinder","Too many ITS subdetectors !");
181 for (m=0; m<mmax; m++) {
182 Int_t lay,lad,det; geom->GetModuleId(m,lay,lad,det);
183 Float_t x,y,z; geom->GetTrans(lay,lad,det,x,y,z);
184 Double_t rot[9]; geom->GetRotMatrix(lay,lad,det,rot);
185 Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
186 Double_t ca=TMath::Cos(alpha), sa=TMath::Sin(alpha);
187 fYshift[m] = x*ca + y*sa;
188 fZshift[m] = (Double_t)z;
189 fNdet[m] = (lad-1)*geom->GetNdetectors(lay) + (det-1);
196 //----------------------------------------------------------------------
197 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
198 // Add a raw cluster copy to the list
200 // Int_t branch The branch to which the cluster is to be added to
201 // AliITSRawCluster *c The cluster to be added to the array of clusters
207 fITS->AddCluster(branch,c);
210 //----------------------------------------------------------------------
211 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
213 // Add a raw cluster copy to the list and the RecPoint
215 // Int_t branch The branch to which the cluster is to be added to
216 // AliITSRawCluster *c The cluster to be added to the array of clusters
217 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
223 fITS->AddCluster(branch,c);
225 fITS->AddRecPoint(rp);
228 //______________________________________________________________________
229 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
230 //------------------------------------------------------------
231 // Tries to find mother's labels
232 //------------------------------------------------------------
234 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
235 // Check if simulation
236 AliMC* mc = gAlice->GetMCApp();
239 Int_t ntracks = mc->GetNtrack();
240 for (Int_t i=0;i<3;i++){
241 Int_t label = lab[i];
242 if (label>=0 && label<ntracks) {
243 TParticle *part=(TParticle*)mc->Particle(label);
244 if (part->P() < 0.005) {
245 Int_t m=part->GetFirstMother();
249 if (part->GetStatusCode()>0) {
259 //______________________________________________________________________
260 void AliITSClusterFinder::FindRawClusters(Int_t module){
261 // Default Cluster finder.
263 // Int_t module Module number for which culster are to be found.
268 const Int_t kelms = 10;
269 Int_t ndigits = fDigits->GetEntriesFast();
270 TObjArray *digs = new TObjArray(ndigits);
271 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
272 TObjArray *clust0=0; // A spacific cluster of digits
273 TObjArray *clust1=0; // A spacific cluster of digits
274 AliITSdigit *dig=0; // locat pointer to a digit
275 Int_t i=0,nc=0,j[4],k,k2=0;
277 // Copy all digits for this module into a local TObjArray.
278 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
280 // First digit is a cluster.
283 clusts->AddAt(new TObjArray(kelms),nc);
284 clust0 = (TObjArray*)(clusts->At(nc));
285 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
287 for(i=1;i<ndigits;i++){
288 if(IsNeighbor(digs,i,j)){
289 dig = (AliITSdigit*)(digs->At(j[0]));
290 // Add to existing cluster. Find which cluster this digis
292 clust0 = ((TObjArray*)(clusts->At(k)));
293 if(clust0->IndexOf(dig)>=0) break;
296 Fatal("FindRawClusters","Digit not found as expected");
299 dig = (AliITSdigit*)(digs->At(j[1]));
300 // Add to existing cluster. Find which cluster this digis
301 for(k2=0;k2<nc;k2++){
302 clust1 = ((TObjArray*)(clusts->At(k2)));
303 if(clust1->IndexOf(dig)>=0) break;
306 Fatal("FindRawClusters","Digit not found as expected");
309 // Found cluster with neighboring digits add this one to it.
310 if(clust0==clust1){ // same cluster
311 clust0->AddAtFree(digs->At(i));
312 clust0 = 0; // finished with cluster. zero for safty
313 clust1 = 0; // finished wit hcluster. zero for safty
314 }else{ // two different clusters which need to be merged.
315 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
316 for(k=0;k<clust1->GetEntriesFast();k++){
317 // move clust1 into clust0
318 //move digit to this cluster
319 clust0->AddAtFree(clust1->At(k));
320 clust1->AddAt(0,k); // zero this one
323 clusts->AddAt(0,k2); // zero array of clusters element clust1
324 clust0 = 0; // finished with cluster. zero for safty
325 clust1 = 0; // finished wit hcluster. zero for safty
326 } // end if clust0==clust1
328 clusts->AddAt(new TObjArray(kelms),nc);
329 clust0 = ((TObjArray*)(clusts->At(nc)));
330 // move owner ship from digs to clusts
331 clust0->AddAtFree(digs->At(i));
332 clust0 = 0; // finished with cluster. zero for safty
334 } // End if IsNeighbor
336 // There are now nc clusters in clusts. Each element of clust is an
337 // array of digits which are clustered together.
339 // For each cluster call detector specific CreateRecPoints
340 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
342 // clean up at the end.
344 clust0 =(TObjArray*)(clusts->At(i));
345 // Digits deleted below, so zero this TObjArray
346 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
347 delete clust0; // Delete this TObjArray
348 clusts->AddAt(0,i); // Contents deleted above, so zero it.
350 delete clusts; // Delete this TObjArray/
351 // Delete the digits then the TObjArray which containted them.
352 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
355 //______________________________________________________________________
356 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
357 // Locagical function which checks to see if digit i has a neighbor.
358 // If so, then it returns kTRUE and its neighbor index j.
359 // This routine checks if the digits are side by side or one before the
360 // other. Requires that the array of digits be in proper order.
361 // Returns kTRUE in the following cases.
362 // ji 0j if kdiagonal j0 0i
363 // 00 0i if kdiagonal 0i j0
365 // TObjArray *digs Array to search for neighbors in
366 // Int_t i Index of digit for which we are searching for
369 // Int_t j[4] Index of one or more of the digits which is a
370 // neighbor of digit a index i.
372 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
374 const Bool_t kdiagonal=kFALSE;
377 // No neighbors found if array empty.
378 if(digs->GetEntriesFast()<=0) return kFALSE;
379 // can not be a digit with first element or elements out or range
380 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
382 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
383 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
384 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
386 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
387 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
388 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
389 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
390 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
391 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
393 if(nei[0]||nei[1]) return kTRUE;
394 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
395 // no Neighbors found.
399 //______________________________________________________________________
400 void AliITSClusterFinder::Print(ostream *os){
401 //Standard output format for this class
403 // ostream *os Output stream
405 // ostream *os Output stream
411 *os << fNdigits<<",";
412 *os << fNRawClusters<<",";
413 *os << fNperMax<<",";
414 *os << fDeclusterFlag<<",";
415 *os << fClusterSize<<",";
416 *os << fNPeaks<<endl;
418 //______________________________________________________________________
419 void AliITSClusterFinder::RecPoints2Clusters
420 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
421 //------------------------------------------------------------
422 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
423 // subdetector indexed by idx
424 //------------------------------------------------------------
425 AliITSgeom* geom = (AliITSgeom*)fITS->GetITSgeom();
426 Int_t lastSPD1=geom->GetModuleIndex(2,1,1)-1;
427 TClonesArray &cl=*clusters;
428 Int_t ncl=points->GetEntriesFast();
429 for (Int_t i=0; i<ncl; i++) {
430 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
432 lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=lastSPD1) lp[0]*=-1; //SPD1
433 lp[1]= -p->GetZ()+fZshift[idx];
434 lp[2]=p->GetSigmaX2();
435 lp[3]=p->GetSigmaZ2();
436 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
438 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
441 Int_t dummy[3]={0,0,0};
442 new (cl[i]) AliITSclusterV2(lab,lp, dummy);
446 //______________________________________________________________________
447 void AliITSClusterFinder::Read(istream *is){
448 //Standard input for this class
450 // istream *is Input stream
452 // istream *is Input stream
459 *is >> fNRawClusters;
461 *is >> fDeclusterFlag;
465 //______________________________________________________________________
466 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
467 // Standard output streaming function.
469 // ostream *os Output stream
470 // AliITSClusterFinder &source Class to be printed
472 // ostream *os Output stream
479 //______________________________________________________________________
480 istream &operator>>(istream &is,AliITSClusterFinder &source){
481 // Standard output streaming function.
483 // istream *is Input stream
484 // AliITSClusterFinder &source Class to be read in.
486 // istream *is Input stream
494 void AliITSClusterFinder::RecPoints2Clusters
495 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
496 //------------------------------------------------------------
497 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
498 // subdetector indexed by idx
499 //------------------------------------------------------------
500 TClonesArray &cl=*clusters;
501 Int_t ncl=points->GetEntriesFast();
502 for (Int_t i=0; i<ncl; i++) {
503 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
505 lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
506 lp[1]= -p->GetZ()+fZshift[idx];
507 lp[2]=p->GetSigmaX2();
508 lp[3]=p->GetSigmaZ2();
509 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
511 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
514 Int_t dummy[3]={0,0,0};
515 new (cl[i]) AliITSclusterV2(lab,lp, dummy);