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 **************************************************************************/
21 #include <TClonesArray.h>
22 #include "AliITSpackageSSD.h"
24 //************************************************
25 //Piotr Krzysztof Skowronski
26 //Warsaw University of Technology
27 //skowron@if.pw.edu.pl
30 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
31 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
33 static const Int_t debug=0;
35 ClassImp(AliITSpackageSSD)
37 AliITSpackageSSD::AliITSpackageSSD()
40 fClusterNIndexes = new TArrayI(300);
43 fClusterPIndexes = new TArrayI(300);
44 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
48 /*******************************************************/
50 AliITSpackageSSD::AliITSpackageSSD
51 (TClonesArray *clustersP, TClonesArray *clustersN)
57 fClusterNIndexes = new TArrayI(300);
60 fClusterPIndexes = new TArrayI(300);
63 /*******************************************************/
66 AliITSpackageSSD::AliITSpackageSSD
67 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
74 fClusterNIndexes = new TArrayI(len);
77 fClusterPIndexes = new TArrayI(len);
81 /*******************************************************/
83 AliITSpackageSSD::~AliITSpackageSSD()
86 delete fClusterNIndexes;
87 delete fClusterPIndexes;
89 /*******************************************************/
91 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
96 if (this == &package) return;
97 fClustersN = package.fClustersN;
98 fClustersP = package.fClustersP;
100 fNclustersN= package.fNclustersN;
101 fNclustersP= package.fNclustersP;
103 for ( i =0; i<fNclustersN;i++)
105 fClusterNIndexes[i]= package.fClusterNIndexes[i];
108 for ( i =0; i<fNclustersP;i++)
110 fClusterPIndexes[i]= package.fClusterPIndexes[i];
113 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
118 /*******************************************************/
121 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
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 (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
150 /*******************************************************/
153 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
156 if ((index>-1)&&(index<fNclustersN))
157 return (*fClusterNIndexes)[index];
160 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
164 /*******************************************************/
167 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
169 if ((index>-1)&&(index<fNclustersP))
170 return (*fClusterPIndexes)[index];
173 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
177 /*******************************************************/
179 AliITSpackageSSD::GetPSideCluster(Int_t index)
182 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
185 /*******************************************************/
188 AliITSpackageSSD::GetNSideCluster(Int_t index)
190 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
194 /*******************************************************/
199 AliITSpackageSSD::GetClusterWithOneCross
200 (Int_t & index, Bool_t& side)
204 if((fNclustersP==0)||(fNclustersN==0) )
206 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
212 ind =(*fClusterPIndexes)[fNclustersP-1];
213 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
216 index =fNclustersP-1;
221 ind =(*fClusterNIndexes)[fNclustersN-1];
222 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
225 index = fNclustersN-1;
231 ind =(*fClusterPIndexes)[0];
232 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
241 ind =(*fClusterNIndexes)[0];
242 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
251 //Add for to be shure
256 /*******************************************************/
258 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
260 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
262 /*******************************************************/
263 void AliITSpackageSSD::DelPCluster(Int_t index)
266 //it not deletes delete given cluster physically,
267 //but only complytely erase it from package
268 //all clusters are deleted automatically when TClonesArray is deleted
272 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
273 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
274 Int_t ncr = clToDel->GetCrossNo();
278 idx = clToDel->GetCross(i);
279 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
283 for (i=index;i<fNclustersP-1;i++)
285 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
288 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
291 for (i=0;i<fNclustersN;i++)
293 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
299 /*******************************************************/
300 void AliITSpackageSSD::DelNCluster(Int_t index)
303 //it not deletes delete given cluster physically,
304 //but only complytely erase it from package
305 //all clusters are deleted automatically when TClonesArray is deleted
309 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
310 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
311 Int_t ncr = clToDel->GetCrossNo();
315 idx = clToDel->GetCross(i);
316 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
320 for (i=index;i<fNclustersN-1;i++)
322 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
325 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
327 for (i=0;i<fNclustersP;i++)
329 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
335 /*******************************************************/
337 void AliITSpackageSSD::DelPClusterOI(Int_t index)
339 //This function looks like this,
340 //because probably cut cluster is
341 //on the beginning or on the end of package
343 if( ((*fClusterPIndexes)[0]) == index)
350 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
352 DelPCluster(fNclustersP-1);
357 for (i=1;i<fNclustersP-1;i++)
359 if( ((*fClusterPIndexes)[i])==index)
368 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
373 /*******************************************************/
375 void AliITSpackageSSD::DelNClusterOI(Int_t index)
377 //This function looks like this,
378 //because probably cluster to cut is
379 //on the beginning or on the end of package
382 if( ((*fClusterNIndexes)[0])==index)
389 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
391 DelNCluster(fNclustersN-1);
396 for (i=1;i<fNclustersN-1;i++)
398 if( ((*fClusterNIndexes)[i])==index)
406 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
410 /*******************************************************/
413 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
415 if (side == fgkSIDEP)
417 DelPClusterOI(index);
421 DelNClusterOI(index);
427 /**********************************************/
430 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
433 Int_t *takenNcl = new Int_t[fNclustersN];
437 if (debug) PrintClusters();
439 for (Int_t i=0;i<fNclustersP;i++)
443 //see comment on the beginning of MakeCombin
444 if (debug) cout<<"GetAllCombinations entered";
445 MakeCombin (array,num,0,takenNcl,sizet);
449 /**********************************************/
452 void AliITSpackageSSD::MakeCombin
453 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
457 //ATTENTION: anybody watching this function
458 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
459 //however, we have pointer to that array (TClonesArray)
461 //Get?SideCluster because it takes index from local look_up_table
466 AliITSclusterSSD *cl=GetPSideCluster(np);
468 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
469 Int_t indcro; //index of given cluster on side N that
470 // this cluster crosses with
472 if (np == fNclustersP-1) {
474 indcro=cl->GetCross(i);
475 if(IsFree(indcro,np,occup)) {
477 for(j=0;j<fNclustersP;j++)
479 if (nu<sizet) arr[nu][j]=occup[j];
485 if (nu<sizet-1) nu++;
490 indcro=cl->GetCross(i);
491 if(IsFree(indcro,np,occup)) {
493 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
494 //else printf("MakeComb - exceeding array size!\n");
502 /**********************************************/
503 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
506 for (Int_t i=0;i<nn;i++)
508 if (lis[i]==idx) return kFALSE;
513 /**********************************************/
514 void AliITSpackageSSD::PrintClusters()
519 for (i=0;i<fNclustersP;i++)
521 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
522 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
524 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
526 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
527 // else cout<<"BAD SIDE ==N\n";
533 for (i=0;i<fNclustersN;i++)
535 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
536 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
538 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
540 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
541 // else cout<<"BAD SIDE ==P\n";
548 /**********************************************/
549 void AliITSpackageSSD::ConsumeClusters()
553 for(i=0;i<fNclustersP;i++)
555 GetPSideCluster(i)->Consume();
558 for(i=0;i<fNclustersN;i++)
560 GetNSideCluster(i)->Consume();
565 /**********************************************/
567 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
569 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
570 //if not egsist return -1;
571 for (Int_t i =0; i<fNclustersP-1;i++)
573 if(GetPSideClusterIdx(i) == OI)
574 return GetPSideClusterIdx(i+1);
578 /**********************************************/
579 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
581 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
582 //if not egsist return -1;
584 for (Int_t i =1; i<fNclustersP;i++)
586 if(GetPSideClusterIdx(i) == OI)
587 return GetPSideClusterIdx(i-1);
591 /**********************************************/
592 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
594 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
595 //if not egsist return -1;
596 for (Int_t i =0; i<fNclustersN-1;i++)
598 if(GetNSideClusterIdx(i) == OI)
599 return GetNSideClusterIdx(i+1);
604 /**********************************************/
605 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
607 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
608 //if not egsist return -1;
610 for (Int_t i =1; i<fNclustersN;i++)
612 if(GetNSideClusterIdx(i) == OI)
613 return GetNSideClusterIdx(i-1);
619 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
621 // split package of clusters
624 for (i=0;i<fNclustersN;i++)
626 if((*fClusterNIndexes)[i]==ni)
633 for (i=0;i<fNclustersP;i++)
635 if((*fClusterPIndexes)[i]==pi)
641 if (debug) cout<<" p = "<<p<<" n = "<<n;
642 if ((p==-1)||(n==-1)) return;
644 for (i=p;i<fNclustersP;i++)
646 pkg->AddPSideCluster(GetPSideClusterIdx(i));
650 for (i=n;i<fNclustersN;i++)
652 pkg->AddNSideCluster(GetNSideClusterIdx(i));
656 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";