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 **************************************************************************/
18 Revision 1.5 2001/11/19 16:17:03 nilsen
19 Applyed fixes to bugs found by Rene Brun. With many thanks. Some additonal
20 bugs found by Rene require more work to fix. Will be fixed soon.
22 Revision 1.4 2000/07/12 05:32:20 fca
23 Correcting several syntax problem with static members
27 #include <Riostream.h>
28 #include <TClonesArray.h>
29 #include "AliITSpackageSSD.h"
31 //************************************************
32 //Piotr Krzysztof Skowronski
33 //Warsaw University of Technology
34 //skowron@if.pw.edu.pl
37 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
38 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
40 static const Int_t debug=0;
42 ClassImp(AliITSpackageSSD)
44 AliITSpackageSSD::AliITSpackageSSD()
51 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
55 /*******************************************************/
57 AliITSpackageSSD::AliITSpackageSSD
58 (TClonesArray *clustersP, TClonesArray *clustersN)
64 fClusterNIndexes = new TArrayI(300);
67 fClusterPIndexes = new TArrayI(300);
70 /*******************************************************/
73 AliITSpackageSSD::AliITSpackageSSD
74 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
81 fClusterNIndexes = new TArrayI(len);
84 fClusterPIndexes = new TArrayI(len);
88 /*******************************************************/
90 AliITSpackageSSD::~AliITSpackageSSD()
93 delete fClusterNIndexes;
94 delete fClusterPIndexes;
96 /*******************************************************/
98 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
103 if (this == &package) return;
104 fClustersN = package.fClustersN;
105 fClustersP = package.fClustersP;
107 fNclustersN= package.fNclustersN;
108 fNclustersP= package.fNclustersP;
110 for ( i =0; i<fNclustersN;i++)
112 fClusterNIndexes[i]= package.fClusterNIndexes[i];
115 for ( i =0; i<fNclustersP;i++)
117 fClusterPIndexes[i]= package.fClusterPIndexes[i];
120 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
125 /*******************************************************/
128 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
133 if (this == &package) return *this;
134 fClustersN = package.fClustersN;
135 fClustersP = package.fClustersP;
137 fNclustersN= package.fNclustersN;
138 fNclustersP= package.fNclustersP;
140 for ( i =0; i<fNclustersN;i++)
142 fClusterNIndexes[i]= package.fClusterNIndexes[i];
145 for ( i =0; i<fNclustersP;i++)
147 fClusterPIndexes[i]= package.fClusterPIndexes[i];
150 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
157 /*******************************************************/
160 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
163 if ((index>-1)&&(index<fNclustersN))
164 return (*fClusterNIndexes)[index];
167 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
171 /*******************************************************/
174 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
176 if ((index>-1)&&(index<fNclustersP))
177 return (*fClusterPIndexes)[index];
180 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
184 /*******************************************************/
186 AliITSpackageSSD::GetPSideCluster(Int_t index)
189 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
192 /*******************************************************/
195 AliITSpackageSSD::GetNSideCluster(Int_t index)
197 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
201 /*******************************************************/
206 AliITSpackageSSD::GetClusterWithOneCross
207 (Int_t & index, Bool_t& side)
211 if((fNclustersP==0)||(fNclustersN==0) )
213 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
219 ind =(*fClusterPIndexes)[fNclustersP-1];
220 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
223 index =fNclustersP-1;
228 ind =(*fClusterNIndexes)[fNclustersN-1];
229 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
232 index = fNclustersN-1;
238 ind =(*fClusterPIndexes)[0];
239 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
248 ind =(*fClusterNIndexes)[0];
249 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
258 //Add for to be shure
263 /*******************************************************/
265 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
267 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
269 /*******************************************************/
270 void AliITSpackageSSD::DelPCluster(Int_t index)
273 //it not deletes delete given cluster physically,
274 //but only complytely erase it from package
275 //all clusters are deleted automatically when TClonesArray is deleted
279 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
280 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
281 Int_t ncr = clToDel->GetCrossNo();
285 idx = clToDel->GetCross(i);
286 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
290 for (i=index;i<fNclustersP-1;i++)
292 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
295 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
298 for (i=0;i<fNclustersN;i++)
300 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
306 /*******************************************************/
307 void AliITSpackageSSD::DelNCluster(Int_t index)
310 //it not deletes delete given cluster physically,
311 //but only complytely erase it from package
312 //all clusters are deleted automatically when TClonesArray is deleted
316 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
317 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
318 Int_t ncr = clToDel->GetCrossNo();
322 idx = clToDel->GetCross(i);
323 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
327 for (i=index;i<fNclustersN-1;i++)
329 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
332 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
334 for (i=0;i<fNclustersP;i++)
336 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
342 /*******************************************************/
344 void AliITSpackageSSD::DelPClusterOI(Int_t index)
346 //This function looks like this,
347 //because probably cut cluster is
348 //on the beginning or on the end of package
350 if( ((*fClusterPIndexes)[0]) == index)
357 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
359 DelPCluster(fNclustersP-1);
364 for (i=1;i<fNclustersP-1;i++)
366 if( ((*fClusterPIndexes)[i])==index)
375 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
380 /*******************************************************/
382 void AliITSpackageSSD::DelNClusterOI(Int_t index)
384 //This function looks like this,
385 //because probably cluster to cut is
386 //on the beginning or on the end of package
389 if( ((*fClusterNIndexes)[0])==index)
396 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
398 DelNCluster(fNclustersN-1);
403 for (i=1;i<fNclustersN-1;i++)
405 if( ((*fClusterNIndexes)[i])==index)
413 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
417 /*******************************************************/
420 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
422 if (side == fgkSIDEP)
424 DelPClusterOI(index);
428 DelNClusterOI(index);
434 /**********************************************/
437 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
440 Int_t *takenNcl = new Int_t[fNclustersN];
444 if (debug) PrintClusters();
446 for (Int_t i=0;i<fNclustersP;i++)
450 //see comment on the beginning of MakeCombin
451 if (debug) cout<<"GetAllCombinations entered";
452 MakeCombin (array,num,0,takenNcl,sizet);
456 /**********************************************/
459 void AliITSpackageSSD::MakeCombin
460 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
464 //ATTENTION: anybody watching this function
465 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
466 //however, we have pointer to that array (TClonesArray)
468 //Get?SideCluster because it takes index from local look_up_table
473 AliITSclusterSSD *cl=GetPSideCluster(np);
475 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
476 Int_t indcro; //index of given cluster on side N that
477 // this cluster crosses with
479 if (np == fNclustersP-1) {
481 indcro=cl->GetCross(i);
482 if(IsFree(indcro,np,occup)) {
484 for(j=0;j<fNclustersP;j++)
486 if (nu<sizet) arr[nu][j]=occup[j];
492 if (nu<sizet-1) nu++;
497 indcro=cl->GetCross(i);
498 if(IsFree(indcro,np,occup)) {
500 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
501 //else printf("MakeComb - exceeding array size!\n");
509 /**********************************************/
510 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
513 for (Int_t i=0;i<nn;i++)
515 if (lis[i]==idx) return kFALSE;
520 /**********************************************/
521 void AliITSpackageSSD::PrintClusters()
526 for (i=0;i<fNclustersP;i++)
528 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
529 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
531 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
533 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
534 // else cout<<"BAD SIDE ==N\n";
540 for (i=0;i<fNclustersN;i++)
542 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
543 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
545 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
547 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
548 // else cout<<"BAD SIDE ==P\n";
555 /**********************************************/
556 void AliITSpackageSSD::ConsumeClusters()
560 for(i=0;i<fNclustersP;i++)
562 GetPSideCluster(i)->Consume();
565 for(i=0;i<fNclustersN;i++)
567 GetNSideCluster(i)->Consume();
572 /**********************************************/
574 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
576 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
577 //if not egsist return -1;
578 for (Int_t i =0; i<fNclustersP-1;i++)
580 if(GetPSideClusterIdx(i) == OI)
581 return GetPSideClusterIdx(i+1);
585 /**********************************************/
586 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
588 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
589 //if not egsist return -1;
591 for (Int_t i =1; i<fNclustersP;i++)
593 if(GetPSideClusterIdx(i) == OI)
594 return GetPSideClusterIdx(i-1);
598 /**********************************************/
599 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
601 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
602 //if not egsist return -1;
603 for (Int_t i =0; i<fNclustersN-1;i++)
605 if(GetNSideClusterIdx(i) == OI)
606 return GetNSideClusterIdx(i+1);
611 /**********************************************/
612 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
614 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
615 //if not egsist return -1;
617 for (Int_t i =1; i<fNclustersN;i++)
619 if(GetNSideClusterIdx(i) == OI)
620 return GetNSideClusterIdx(i-1);
626 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
628 // split package of clusters
631 for (i=0;i<fNclustersN;i++)
633 if((*fClusterNIndexes)[i]==ni)
640 for (i=0;i<fNclustersP;i++)
642 if((*fClusterPIndexes)[i]==pi)
648 if (debug) cout<<" p = "<<p<<" n = "<<n;
649 if ((p==-1)||(n==-1)) return;
651 for (i=p;i<fNclustersP;i++)
653 pkg->AddPSideCluster(GetPSideClusterIdx(i));
657 for (i=n;i<fNclustersN;i++)
659 pkg->AddNSideCluster(GetNSideClusterIdx(i));
663 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";