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"
29 ClassImp(AliITSClusterFinder)
31 //----------------------------------------------------------------------
32 AliITSClusterFinder::AliITSClusterFinder():
46 // default cluster finder
52 // A default constructed AliITSCulsterFinder
54 //----------------------------------------------------------------------
55 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
68 // Standard constructor for cluster finder
70 // AliITSsegmentation *seg The segmentation class to be used
71 // AliITSresponse *res The response class to be used
75 // A Standard constructed AliITSCulsterFinder
82 //----------------------------------------------------------------------
83 AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
84 TClonesArray *digits):
98 // Standard + cluster finder constructor
100 // AliITSsegmentation *seg The segmentation class to be used
101 // AliITSresponse *res The response class to be used
102 // TClonesArray *digits Array of digits to be used
106 // A Standard constructed AliITSCulsterFinder
108 fNdigits = fDigits->GetEntriesFast();
113 //______________________________________________________________________
114 AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source) {
116 // Copies are not allowed. The method is protected to avoid misuse.
117 Fatal("AliITSClusterFinder","Copy constructor not allowed\n");
120 //______________________________________________________________________
121 AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
122 // Assignment operator
123 // Assignment is not allowed. The method is protected to avoid misuse.
124 Fatal("= operator","Assignment operator not allowed\n");
128 //----------------------------------------------------------------------
129 AliITSClusterFinder::~AliITSClusterFinder(){
130 // destructor cluster finder
138 if(fMap) {delete fMap;}
139 // Zero local pointers. Other classes own these pointers.
151 //__________________________________________________________________________
152 void AliITSClusterFinder::InitGeometry(){
155 //Initialisation of ITS geometry
156 if(!fDetTypeRec->GetITSgeom()) {
157 Error("InitGeometry","ITS geom is null!");
160 Int_t mmax=fDetTypeRec->GetITSgeom()->GetIndexMax();
162 Fatal("AliITSClusterFinder","Too many ITS subdetectors !");
165 for (m=0; m<mmax; m++) {
166 Int_t lay,lad,det; fDetTypeRec->GetITSgeom()->GetModuleId(m,lay,lad,det);
167 Float_t x,y,z; fDetTypeRec->GetITSgeom()->GetTrans(lay,lad,det,x,y,z);
168 Double_t rot[9]; fDetTypeRec->GetITSgeom()->GetRotMatrix(lay,lad,det,rot);
169 Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
170 Double_t ca=TMath::Cos(alpha), sa=TMath::Sin(alpha);
171 fYshift[m] = x*ca + y*sa;
172 fZshift[m] = (Double_t)z;
173 fNdet[m] = (lad-1)*fDetTypeRec->GetITSgeom()->GetNdetectors(lay) + (det-1);
180 //----------------------------------------------------------------------
181 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
182 // Add a raw cluster copy to the list
184 // Int_t branch The branch to which the cluster is to be added to
185 // AliITSRawCluster *c The cluster to be added to the array of clusters
192 Error("AddCluster","fDetTypeRec is null!");
195 fDetTypeRec->AddCluster(branch,c);
198 //----------------------------------------------------------------------
199 void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
201 // Add a raw cluster copy to the list and the RecPoint
203 // Int_t branch The branch to which the cluster is to be added to
204 // AliITSRawCluster *c The cluster to be added to the array of clusters
205 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
211 Error("AddCluster","fDetTypeRec is null!");
215 fDetTypeRec->AddCluster(branch,c);
217 fDetTypeRec->AddRecPoint(rp);
221 //______________________________________________________________________
222 void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
223 //------------------------------------------------------------
224 // Tries to find mother's labels
225 //------------------------------------------------------------
227 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
228 // Check if simulation
229 AliMC* mc = gAlice->GetMCApp();
232 Int_t ntracks = mc->GetNtrack();
233 for (Int_t i=0;i<3;i++){
234 Int_t label = lab[i];
235 if (label>=0 && label<ntracks) {
236 TParticle *part=(TParticle*)mc->Particle(label);
237 if (part->P() < 0.005) {
238 Int_t m=part->GetFirstMother();
242 if (part->GetStatusCode()>0) {
252 //______________________________________________________________________
253 void AliITSClusterFinder::FindRawClusters(Int_t module){
254 // Default Cluster finder.
256 // Int_t module Module number for which culster are to be found.
261 const Int_t kelms = 10;
262 Int_t ndigits = fDigits->GetEntriesFast();
263 TObjArray *digs = new TObjArray(ndigits);
264 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
265 TObjArray *clust0=0; // A spacific cluster of digits
266 TObjArray *clust1=0; // A spacific cluster of digits
267 AliITSdigit *dig=0; // locat pointer to a digit
268 Int_t i=0,nc=0,j[4],k,k2=0;
270 // Copy all digits for this module into a local TObjArray.
271 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
273 // First digit is a cluster.
276 clusts->AddAt(new TObjArray(kelms),nc);
277 clust0 = (TObjArray*)(clusts->At(nc));
278 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
280 for(i=1;i<ndigits;i++){
281 if(IsNeighbor(digs,i,j)){
282 dig = (AliITSdigit*)(digs->At(j[0]));
283 // Add to existing cluster. Find which cluster this digis
285 clust0 = ((TObjArray*)(clusts->At(k)));
286 if(clust0->IndexOf(dig)>=0) break;
289 Fatal("FindRawClusters","Digit not found as expected");
292 dig = (AliITSdigit*)(digs->At(j[1]));
293 // Add to existing cluster. Find which cluster this digis
294 for(k2=0;k2<nc;k2++){
295 clust1 = ((TObjArray*)(clusts->At(k2)));
296 if(clust1->IndexOf(dig)>=0) break;
299 Fatal("FindRawClusters","Digit not found as expected");
302 // Found cluster with neighboring digits add this one to it.
303 if(clust0==clust1){ // same cluster
304 clust0->AddAtFree(digs->At(i));
305 clust0 = 0; // finished with cluster. zero for safty
306 clust1 = 0; // finished wit hcluster. zero for safty
307 }else{ // two different clusters which need to be merged.
308 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
309 for(k=0;k<clust1->GetEntriesFast();k++){
310 // move clust1 into clust0
311 //move digit to this cluster
312 clust0->AddAtFree(clust1->At(k));
313 clust1->AddAt(0,k); // zero this one
316 clusts->AddAt(0,k2); // zero array of clusters element clust1
317 clust0 = 0; // finished with cluster. zero for safty
318 clust1 = 0; // finished wit hcluster. zero for safty
319 } // end if clust0==clust1
321 clusts->AddAt(new TObjArray(kelms),nc);
322 clust0 = ((TObjArray*)(clusts->At(nc)));
323 // move owner ship from digs to clusts
324 clust0->AddAtFree(digs->At(i));
325 clust0 = 0; // finished with cluster. zero for safty
327 } // End if IsNeighbor
329 // There are now nc clusters in clusts. Each element of clust is an
330 // array of digits which are clustered together.
332 // For each cluster call detector specific CreateRecPoints
333 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
335 // clean up at the end.
337 clust0 =(TObjArray*)(clusts->At(i));
338 // Digits deleted below, so zero this TObjArray
339 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
340 delete clust0; // Delete this TObjArray
341 clusts->AddAt(0,i); // Contents deleted above, so zero it.
343 delete clusts; // Delete this TObjArray/
344 // Delete the digits then the TObjArray which containted them.
345 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
348 //______________________________________________________________________
349 Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
350 // Locagical function which checks to see if digit i has a neighbor.
351 // If so, then it returns kTRUE and its neighbor index j.
352 // This routine checks if the digits are side by side or one before the
353 // other. Requires that the array of digits be in proper order.
354 // Returns kTRUE in the following cases.
355 // ji 0j if kdiagonal j0 0i
356 // 00 0i if kdiagonal 0i j0
358 // TObjArray *digs Array to search for neighbors in
359 // Int_t i Index of digit for which we are searching for
362 // Int_t j[4] Index of one or more of the digits which is a
363 // neighbor of digit a index i.
365 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
367 const Bool_t kdiagonal=kFALSE;
370 // No neighbors found if array empty.
371 if(digs->GetEntriesFast()<=0) return kFALSE;
372 // can not be a digit with first element or elements out or range
373 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
375 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
376 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
377 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
379 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
380 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
381 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
382 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
383 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
384 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
386 if(nei[0]||nei[1]) return kTRUE;
387 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
388 // no Neighbors found.
392 //______________________________________________________________________
393 void AliITSClusterFinder::Print(ostream *os) const{
394 //Standard output format for this class
396 // ostream *os Output stream
398 // ostream *os Output stream
404 *os << fNdigits<<",";
405 *os << fNRawClusters<<",";
406 *os << fNperMax<<",";
407 *os << fDeclusterFlag<<",";
408 *os << fClusterSize<<",";
409 *os << fNPeaks<<endl;
412 //______________________________________________________________________
413 void AliITSClusterFinder::RecPoints2Clusters
414 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
415 //------------------------------------------------------------
416 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
417 // subdetector indexed by idx
418 //------------------------------------------------------------
419 if(!fDetTypeRec->GetITSgeom()) {
420 Error("RecPoints2Clusters","ITS geom is null!");
423 Int_t lastSPD1=fDetTypeRec->GetITSgeom()->GetModuleIndex(2,1,1)-1;
424 TClonesArray &cl=*clusters;
425 Int_t ncl=points->GetEntriesFast();
426 for (Int_t i=0; i<ncl; i++) {
427 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
429 lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=lastSPD1) lp[0]*=-1; //SPD1
430 lp[1]= -p->GetZ()+fZshift[idx];
431 lp[2]=p->GetSigmaX2();
432 lp[3]=p->GetSigmaZ2();
433 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
435 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
438 Int_t dummy[3]={0,0,0};
439 new (cl[i]) AliITSclusterV2(lab,lp, dummy);
443 //______________________________________________________________________
444 void AliITSClusterFinder::Read(istream *is) {
445 //Standard input for this class
447 // istream *is Input stream
449 // istream *is Input stream
456 *is >> fNRawClusters;
458 *is >> fDeclusterFlag;
462 //______________________________________________________________________
463 ostream &operator<<(ostream &os,AliITSClusterFinder &source){
464 // Standard output streaming function.
466 // ostream *os Output stream
467 // AliITSClusterFinder &source Class to be printed
469 // ostream *os Output stream
476 //______________________________________________________________________
477 istream &operator>>(istream &is,AliITSClusterFinder &source){
478 // Standard output streaming function.
480 // istream *is Input stream
481 // AliITSClusterFinder &source Class to be read in.
483 // istream *is Input stream
491 void AliITSClusterFinder::RecPoints2Clusters
492 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
493 //------------------------------------------------------------
494 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
495 // subdetector indexed by idx
496 //------------------------------------------------------------
497 TClonesArray &cl=*clusters;
498 Int_t ncl=points->GetEntriesFast();
499 for (Int_t i=0; i<ncl; i++) {
500 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
502 lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
503 lp[1]= -p->GetZ()+fZshift[idx];
504 lp[2]=p->GetSigmaX2();
505 lp[3]=p->GetSigmaZ2();
506 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
508 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
511 Int_t dummy[3]={0,0,0};
512 new (cl[i]) AliITSclusterV2(lab,lp, dummy);