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 **************************************************************************/
17 #include <Riostream.h>
18 #include <TClonesArray.h>
19 #include "AliITSpackageSSD.h"
20 #include "AliITSclusterSSD.h"
22 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
23 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
25 ClassImp(AliITSpackageSSD)
26 ////////////////////////////////////////////////////////////////////////////
27 //Class describing set of AliITSoneSideClusterSSDs, which contact each other.
28 //Piotr Krzysztof Skowronski
29 //Warsaw University of Technology
30 //skowron@if.pw.edu.pl
32 //--------------------------------------------------------------------------
33 AliITSpackageSSD::AliITSpackageSSD()
41 if (fgkDebug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
45 /*******************************************************/
47 AliITSpackageSSD::AliITSpackageSSD
48 (TClonesArray *clustersP, TClonesArray *clustersN)
55 fClusterNIndexes = new TArrayI(300);
58 fClusterPIndexes = new TArrayI(300);
61 /*******************************************************/
64 AliITSpackageSSD::AliITSpackageSSD
65 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
72 fClusterNIndexes = new TArrayI(len);
75 fClusterPIndexes = new TArrayI(len);
79 /*******************************************************/
81 AliITSpackageSSD::~AliITSpackageSSD()
84 delete fClusterNIndexes;
85 delete fClusterPIndexes;
88 /*******************************************************/
90 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package) :
95 if (this == &package) return;
96 fClustersN = package.fClustersN;
97 fClustersP = package.fClustersP;
99 fNclustersN= package.fNclustersN;
100 fNclustersP= package.fNclustersP;
102 for ( i =0; i<fNclustersN;i++)
104 fClusterNIndexes[i]= package.fClusterNIndexes[i];
107 for ( i =0; i<fNclustersP;i++)
109 fClusterPIndexes[i]= package.fClusterPIndexes[i];
112 if (fgkDebug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
117 /*******************************************************/
120 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
122 // assignment operator
126 if (this == &package) return *this;
127 fClustersN = package.fClustersN;
128 fClustersP = package.fClustersP;
130 fNclustersN= package.fNclustersN;
131 fNclustersP= package.fNclustersP;
133 for ( i =0; i<fNclustersN;i++)
135 fClusterNIndexes[i]= package.fClusterNIndexes[i];
138 for ( i =0; i<fNclustersP;i++)
140 fClusterPIndexes[i]= package.fClusterPIndexes[i];
143 if (fgkDebug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
149 /*******************************************************/
151 Int_t AliITSpackageSSD::GetNSideClusterIdx(Int_t index) const
153 // get N-side cluster
155 if ((index>-1)&&(index<fNclustersN))
156 return (*fClusterNIndexes)[index];
159 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
163 /*******************************************************/
166 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index) const
168 // get P-side cluster
170 if ((index>-1)&&(index<fNclustersP))
171 return (*fClusterPIndexes)[index];
174 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
178 /*******************************************************/
180 AliITSpackageSSD::GetPSideCluster(Int_t index)
182 // get Pside cluster from the TClonesArray of SSD clusters
184 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
187 /*******************************************************/
190 AliITSpackageSSD::GetNSideCluster(Int_t index)
192 // get Nside cluster from the TClonesArray of SSD clusters
194 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
198 /*******************************************************/
200 Bool_t AliITSpackageSSD::GetClusterWithOneCross
201 (Int_t & index, Bool_t& side)
203 // select clusters with on cross
205 if((fNclustersP==0)||(fNclustersN==0) )
207 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
213 ind =(*fClusterPIndexes)[fNclustersP-1];
214 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
217 index =fNclustersP-1;
222 ind =(*fClusterNIndexes)[fNclustersN-1];
223 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
226 index = fNclustersN-1;
232 ind =(*fClusterPIndexes)[0];
233 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
242 ind =(*fClusterNIndexes)[0];
243 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
252 //Add for to be shure
257 /*******************************************************/
259 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
261 // call DelPCluster or DelNCluster depending on side
263 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
265 /*******************************************************/
266 void AliITSpackageSSD::DelPCluster(Int_t index)
268 //it not deletes delete given cluster physically,
269 //but only complytely erase it from package
270 //all clusters are deleted automatically when TClonesArray is deleted
274 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
275 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
276 Int_t ncr = clToDel->GetCrossNo();
280 idx = clToDel->GetCross(i);
281 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
285 for (i=index;i<fNclustersP-1;i++)
287 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
290 if (fgkDebug) cout<<"Cluster P ("<<index<<") deleted\n";
293 for (i=0;i<fNclustersN;i++)
295 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
301 /*******************************************************/
302 void AliITSpackageSSD::DelNCluster(Int_t index)
304 //it not deletes delete given cluster physically,
305 //but only complytely erase it from package
306 //all clusters are deleted automatically when TClonesArray is deleted
310 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
311 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
312 Int_t ncr = clToDel->GetCrossNo();
316 idx = clToDel->GetCross(i);
317 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
321 for (i=index;i<fNclustersN-1;i++)
323 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
326 if (fgkDebug) cout<<"Cluster N ("<<index<<") deleted\n";
328 for (i=0;i<fNclustersP;i++)
330 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
336 /*******************************************************/
338 void AliITSpackageSSD::DelPClusterOI(Int_t index)
340 //This function looks like this,
341 //because probably cut cluster is
342 //on the beginning or on the end of package
344 if( ((*fClusterPIndexes)[0]) == index)
351 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
353 DelPCluster(fNclustersP-1);
358 for (i=1;i<fNclustersP-1;i++)
360 if( ((*fClusterPIndexes)[i])==index)
369 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
374 /*******************************************************/
376 void AliITSpackageSSD::DelNClusterOI(Int_t index)
378 //This function looks like this,
379 //because probably cluster to cut is
380 //on the beginning or on the end of package
383 if( ((*fClusterNIndexes)[0])==index)
390 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
392 DelNCluster(fNclustersN-1);
397 for (i=1;i<fNclustersN-1;i++)
399 if( ((*fClusterNIndexes)[i])==index)
407 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
411 /*******************************************************/
414 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
417 if (side == fgkSIDEP)
419 DelPClusterOI(index);
423 DelNClusterOI(index);
429 /**********************************************/
432 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
434 // get all combinations
435 Int_t *takenNcl = new Int_t[fNclustersN];
439 if (fgkDebug) PrintClusters();
441 for (Int_t i=0;i<fNclustersP;i++)
445 //see comment on the beginning of MakeCombin
446 if (fgkDebug) cout<<"GetAllCombinations entered";
447 MakeCombin (array,num,0,takenNcl,sizet);
451 /**********************************************/
454 void AliITSpackageSSD::MakeCombin
455 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
458 //ATTENTION: anybody watching this function
459 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
460 //however, we have pointer to that array (TClonesArray)
462 //Get?SideCluster because it takes index from local look_up_table
467 AliITSclusterSSD *cl=GetPSideCluster(np);
469 Int_t nc = cl->GetCrossNo(); //number of crosses for this cluster
470 Int_t indcro; //index of given cluster on side N that
471 // this cluster crosses with
473 if (np == fNclustersP-1) {
475 indcro=cl->GetCross(i);
476 if(IsFree(indcro,np,occup)) {
478 for(j=0;j<fNclustersP;j++)
480 if (nu<sizet) arr[nu][j]=occup[j];
486 if (nu<sizet-1) nu++;
491 indcro=cl->GetCross(i);
492 if(IsFree(indcro,np,occup)) {
494 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
495 //else printf("MakeComb - exceeding array size!\n");
503 /**********************************************/
504 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, const Int_t *lis) const
507 for (Int_t i=0;i<nn;i++)
509 if (lis[i]==idx) return kFALSE;
514 /**********************************************/
515 void AliITSpackageSSD::PrintClusters()
517 // print cluster info
520 for (i=0;i<fNclustersP;i++)
522 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
523 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
525 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
527 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
528 // else cout<<"BAD SIDE ==N\n";
534 for (i=0;i<fNclustersN;i++)
536 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
537 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
539 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
541 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
542 // else cout<<"BAD SIDE ==P\n";
548 /**********************************************/
549 void AliITSpackageSSD::ConsumeClusters()
554 for(i=0;i<fNclustersP;i++)
556 GetPSideCluster(i)->Consume();
559 for(i=0;i<fNclustersN;i++)
561 GetNSideCluster(i)->Consume();
566 /**********************************************/
568 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI) const
570 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
571 //if not egsist return -1;
572 for (Int_t i =0; i<fNclustersP-1;i++)
574 if(GetPSideClusterIdx(i) == OI)
575 return GetPSideClusterIdx(i+1);
580 /**********************************************/
581 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI) const
583 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
584 //if not egsist return -1;
586 for (Int_t i =1; i<fNclustersP;i++)
588 if(GetPSideClusterIdx(i) == OI)
589 return GetPSideClusterIdx(i-1);
593 /**********************************************/
594 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI) const
596 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
597 //if not egsist return -1;
598 for (Int_t i =0; i<fNclustersN-1;i++)
600 if(GetNSideClusterIdx(i) == OI)
601 return GetNSideClusterIdx(i+1);
606 /**********************************************/
607 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI) const
609 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
610 //if not egsist return -1;
612 for (Int_t i =1; i<fNclustersN;i++)
614 if(GetNSideClusterIdx(i) == OI)
615 return GetNSideClusterIdx(i-1);
621 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
623 // split package of clusters
626 for (i=0;i<fNclustersN;i++)
628 if((*fClusterNIndexes)[i]==ni)
635 for (i=0;i<fNclustersP;i++)
637 if((*fClusterPIndexes)[i]==pi)
644 cout<<" p = "<<p<<" n = "<<n;
646 if ((p==-1)||(n==-1)) return;
648 for (i=p;i<fNclustersP;i++)
650 pkg->AddPSideCluster(GetPSideClusterIdx(i));
654 for (i=n;i<fNclustersN;i++)
656 pkg->AddNSideCluster(GetNSideClusterIdx(i));
660 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";