1 #include "AliITSpackageSSD.h"
2 //************************************************
3 //Piotr Krzysztof Skowronski
4 //Warsaw University of Technology
10 ClassImp(AliITSpackageSSD)
12 AliITSpackageSSD::AliITSpackageSSD()
15 fClusterNIndexes = new TArrayI(300);
18 fClusterPIndexes = new TArrayI(300);
19 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
23 /*******************************************************/
25 AliITSpackageSSD::AliITSpackageSSD
26 (TClonesArray *clustersP, TClonesArray *clustersN)
32 fClusterNIndexes = new TArrayI(300);
35 fClusterPIndexes = new TArrayI(300);
38 /*******************************************************/
41 AliITSpackageSSD::AliITSpackageSSD
42 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
49 fClusterNIndexes = new TArrayI(len);
52 fClusterPIndexes = new TArrayI(len);
56 /*******************************************************/
58 AliITSpackageSSD::~AliITSpackageSSD()
61 delete fClusterNIndexes;
62 delete fClusterPIndexes;
64 /*******************************************************/
66 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
71 if (this == &package) return;
72 fClustersN = package.fClustersN;
73 fClustersP = package.fClustersP;
75 fNclustersN= package.fNclustersN;
76 fNclustersP= package.fNclustersP;
78 for(i =0; i<fNclustersN;i++)
80 fClusterNIndexes[i]= package.fClusterNIndexes[i];
83 for(i =0; i<fNclustersP;i++)
85 fClusterPIndexes[i]= package.fClusterPIndexes[i];
88 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
93 /*******************************************************/
96 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
101 if (this == &package) return *this;
102 fClustersN = package.fClustersN;
103 fClustersP = package.fClustersP;
105 fNclustersN= package.fNclustersN;
106 fNclustersP= package.fNclustersP;
108 for(i =0; i<fNclustersN;i++)
110 fClusterNIndexes[i]= package.fClusterNIndexes[i];
113 for(i =0; i<fNclustersP;i++)
115 fClusterPIndexes[i]= package.fClusterPIndexes[i];
118 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
125 /*******************************************************/
128 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
131 if ((index>-1)&&(index<fNclustersN))
132 return (*fClusterNIndexes)[index];
135 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
139 /*******************************************************/
142 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
144 if ((index>-1)&&(index<fNclustersP))
145 return (*fClusterPIndexes)[index];
148 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
152 /*******************************************************/
154 AliITSpackageSSD::GetPSideCluster(Int_t index)
157 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
160 /*******************************************************/
163 AliITSpackageSSD::GetNSideCluster(Int_t index)
165 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
169 /*******************************************************/
174 AliITSpackageSSD::GetClusterWithOneCross
175 (Int_t & index, Bool_t& side)
179 if((fNclustersP==0)||(fNclustersN==0) )
181 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
187 ind =(*fClusterPIndexes)[fNclustersP-1];
188 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
191 index =fNclustersP-1;
196 ind =(*fClusterNIndexes)[fNclustersN-1];
197 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
200 index = fNclustersN-1;
206 ind =(*fClusterPIndexes)[0];
207 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
216 ind =(*fClusterNIndexes)[0];
217 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
226 //Add for to be shure
231 /*******************************************************/
233 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
235 if(side==SIDEP) DelPCluster(index); else DelNCluster(index);
237 /*******************************************************/
238 void AliITSpackageSSD::DelPCluster(Int_t index)
241 //it not deletes delete given cluster physically,
242 //but only complytely erase it from package
243 //all clusters are deleted automatically when TClonesArray is deleted
247 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
248 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
249 Int_t ncr = clToDel->GetCrossNo();
253 idx = clToDel->GetCross(i);
254 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
258 for(i=index;i<fNclustersP-1;i++)
260 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
263 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
266 for(i=0;i<fNclustersN;i++)
268 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
274 /*******************************************************/
275 void AliITSpackageSSD::DelNCluster(Int_t index)
278 //it not deletes delete given cluster physically,
279 //but only complytely erase it from package
280 //all clusters are deleted automatically when TClonesArray is deleted
284 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
285 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
286 Int_t ncr = clToDel->GetCrossNo();
290 idx = clToDel->GetCross(i);
291 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
295 for(i=index;i<fNclustersN-1;i++)
297 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
300 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
302 for(i=0;i<fNclustersP;i++)
304 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
310 /*******************************************************/
312 void AliITSpackageSSD::DelPClusterOI(Int_t index)
314 //This function looks like this,
315 //because probably cut cluster is
316 //on the beginning or on the end of package
318 if( ((*fClusterPIndexes)[0]) == index)
325 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
327 DelPCluster(fNclustersP-1);
332 for(i=1;i<fNclustersP-1;i++)
334 if( ((*fClusterPIndexes)[i])==index)
343 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
348 /*******************************************************/
350 void AliITSpackageSSD::DelNClusterOI(Int_t index)
352 //This function looks like this,
353 //because probably cluster to cut is
354 //on the beginning or on the end of package
357 if( ((*fClusterNIndexes)[0])==index)
364 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
366 DelNCluster(fNclustersN-1);
371 for(i=1;i<fNclustersN-1;i++)
373 if( ((*fClusterNIndexes)[i])==index)
381 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
385 /*******************************************************/
388 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
392 DelPClusterOI(index);
396 DelNClusterOI(index);
402 /**********************************************/
405 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
408 Int_t *takenNcl = new Int_t[fNclustersN];
412 if (debug) PrintClusters();
415 for(i=0;i<fNclustersP;i++)
419 //see comment on the beginning of MakeCombin
420 if (debug) cout<<"GetAllCombinations entered";
421 MakeCombin (array,num,0,takenNcl,sizet);
425 /**********************************************/
428 void AliITSpackageSSD::MakeCombin
429 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
433 //ATTENTION: anybody watching this function
434 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
435 //however, we have pointer to that array (TClonesArray)
437 //Get?SideCluster because it takes index from local look_up_table
442 AliITSclusterSSD *cl=GetPSideCluster(np);
444 //printf("np %d cl %p\n",np,cl);
447 Int_t NC = cl->GetCrossNo(); //number of crosses for this cluster
448 Int_t indcro; //index of given cluster on side N that
449 // this cluster crosses with
451 // printf("NC %d \n",NC);
454 if (np == fNclustersP-1) {
457 indcro=cl->GetCross(i);
458 //printf("if: i indcro %d %d\n",i, indcro);
459 if(IsFree(indcro,np,occup)) {
461 //printf("if- isFree: i np occup[np] %d %d %d\n",i,np,occup[np]);
462 for(j=0;j<fNclustersP;j++)
464 //printf("if- for: j nu occup[j] %d %d %d\n",j, nu, occup[j]);
465 if (nu<sizet) arr[nu][j]=occup[j];
467 //printf("MakeComb - exceeding array size! i j %d %d\n",i,j);
469 //printf("if- for: j nu arr[nu][j] %d %d %d\n",j, nu, arr[nu][j]);
474 if (nu<sizet-1) nu++;
475 //printf("i j nu %d %d %d \n",i,j,nu);
479 // printf("else \n");
482 indcro=cl->GetCross(i);
483 //printf("else: i indcro %d %d\n",i, indcro);
484 if(IsFree(indcro,np,occup)) {
486 //printf("else:recursive call - i np occup %d %d %d\n",i,np,occup[np]);
487 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
488 //else printf("MakeComb - exceeding array size!\n");
496 /**********************************************/
497 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
503 if (lis[i]==idx) return kFALSE;
508 /**********************************************/
509 void AliITSpackageSSD::PrintClusters()
514 for(i=0;i<fNclustersP;i++)
516 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
517 for(j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
519 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
521 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
522 // else cout<<"BAD SIDE ==N\n";
528 for(i=0;i<fNclustersN;i++)
530 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
531 for(j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
533 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
535 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
536 // else cout<<"BAD SIDE ==P\n";
543 /**********************************************/
544 void AliITSpackageSSD::ConsumeClusters()
548 for(i=0;i<fNclustersP;i++)
550 GetPSideCluster(i)->Consume();
553 for(i=0;i<fNclustersN;i++)
555 GetNSideCluster(i)->Consume();
560 /**********************************************/
562 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
564 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
565 //if not egsist return -1;
567 for(i =0; i<fNclustersP-1;i++)
569 if(GetPSideClusterIdx(i) == OI)
570 return GetPSideClusterIdx(i+1);
574 /**********************************************/
575 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
577 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
578 //if not egsist return -1;
581 for(i =1; i<fNclustersP;i++)
583 if(GetPSideClusterIdx(i) == OI)
584 return GetPSideClusterIdx(i-1);
588 /**********************************************/
589 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
591 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
592 //if not egsist return -1;
594 for(i =0; i<fNclustersN-1;i++)
596 if(GetNSideClusterIdx(i) == OI)
597 return GetNSideClusterIdx(i+1);
602 /**********************************************/
603 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
605 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
606 //if not egsist return -1;
609 for(i =1; i<fNclustersN;i++)
611 if(GetNSideClusterIdx(i) == OI)
612 return GetNSideClusterIdx(i-1);
618 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
620 // split package of clusters
623 for(i=0;i<fNclustersN;i++)
625 if((*fClusterNIndexes)[i]==ni)
632 for(i=0;i<fNclustersP;i++)
634 if((*fClusterPIndexes)[i]==pi)
640 if (debug) cout<<" p = "<<p<<" n = "<<n;
641 if ((p==-1)||(n==-1)) return;
643 for(i=p;i<fNclustersP;i++)
645 pkg->AddPSideCluster(GetPSideClusterIdx(i));
649 for(i=n;i<fNclustersN;i++)
651 pkg->AddNSideCluster(GetNSideClusterIdx(i));
655 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";