2 #include <TClonesArray.h>
4 #include "AliITSpackageSSD.h"
6 //************************************************
7 //Piotr Krzysztof Skowronski
8 //Warsaw University of Technology
14 ClassImp(AliITSpackageSSD)
16 AliITSpackageSSD::AliITSpackageSSD()
19 fClusterNIndexes = new TArrayI(300);
22 fClusterPIndexes = new TArrayI(300);
23 if (debug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
27 /*******************************************************/
29 AliITSpackageSSD::AliITSpackageSSD
30 (TClonesArray *clustersP, TClonesArray *clustersN)
36 fClusterNIndexes = new TArrayI(300);
39 fClusterPIndexes = new TArrayI(300);
42 /*******************************************************/
45 AliITSpackageSSD::AliITSpackageSSD
46 ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
53 fClusterNIndexes = new TArrayI(len);
56 fClusterPIndexes = new TArrayI(len);
60 /*******************************************************/
62 AliITSpackageSSD::~AliITSpackageSSD()
65 delete fClusterNIndexes;
66 delete fClusterPIndexes;
68 /*******************************************************/
70 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package)
75 if (this == &package) return;
76 fClustersN = package.fClustersN;
77 fClustersP = package.fClustersP;
79 fNclustersN= package.fNclustersN;
80 fNclustersP= package.fNclustersP;
82 for ( i =0; i<fNclustersN;i++)
84 fClusterNIndexes[i]= package.fClusterNIndexes[i];
87 for ( i =0; i<fNclustersP;i++)
89 fClusterPIndexes[i]= package.fClusterPIndexes[i];
92 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
97 /*******************************************************/
100 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
105 if (this == &package) return *this;
106 fClustersN = package.fClustersN;
107 fClustersP = package.fClustersP;
109 fNclustersN= package.fNclustersN;
110 fNclustersP= package.fNclustersP;
112 for ( i =0; i<fNclustersN;i++)
114 fClusterNIndexes[i]= package.fClusterNIndexes[i];
117 for ( i =0; i<fNclustersP;i++)
119 fClusterPIndexes[i]= package.fClusterPIndexes[i];
122 if (debug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
129 /*******************************************************/
132 AliITSpackageSSD::GetNSideClusterIdx(Int_t index)
135 if ((index>-1)&&(index<fNclustersN))
136 return (*fClusterNIndexes)[index];
139 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
143 /*******************************************************/
146 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index)
148 if ((index>-1)&&(index<fNclustersP))
149 return (*fClusterPIndexes)[index];
152 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
156 /*******************************************************/
158 AliITSpackageSSD::GetPSideCluster(Int_t index)
161 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
164 /*******************************************************/
167 AliITSpackageSSD::GetNSideCluster(Int_t index)
169 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
173 /*******************************************************/
178 AliITSpackageSSD::GetClusterWithOneCross
179 (Int_t & index, Bool_t& side)
183 if((fNclustersP==0)||(fNclustersN==0) )
185 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
191 ind =(*fClusterPIndexes)[fNclustersP-1];
192 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
195 index =fNclustersP-1;
200 ind =(*fClusterNIndexes)[fNclustersN-1];
201 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
204 index = fNclustersN-1;
210 ind =(*fClusterPIndexes)[0];
211 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
220 ind =(*fClusterNIndexes)[0];
221 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
230 //Add for to be shure
235 /*******************************************************/
237 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
239 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
241 /*******************************************************/
242 void AliITSpackageSSD::DelPCluster(Int_t index)
245 //it not deletes delete given cluster physically,
246 //but only complytely erase it from package
247 //all clusters are deleted automatically when TClonesArray is deleted
251 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
252 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
253 Int_t ncr = clToDel->GetCrossNo();
257 idx = clToDel->GetCross(i);
258 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
262 for (i=index;i<fNclustersP-1;i++)
264 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
267 if (debug) cout<<"Cluster P ("<<index<<") deleted\n";
270 for (i=0;i<fNclustersN;i++)
272 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
278 /*******************************************************/
279 void AliITSpackageSSD::DelNCluster(Int_t index)
282 //it not deletes delete given cluster physically,
283 //but only complytely erase it from package
284 //all clusters are deleted automatically when TClonesArray is deleted
288 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
289 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
290 Int_t ncr = clToDel->GetCrossNo();
294 idx = clToDel->GetCross(i);
295 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
299 for (i=index;i<fNclustersN-1;i++)
301 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
304 if (debug) cout<<"Cluster N ("<<index<<") deleted\n";
306 for (i=0;i<fNclustersP;i++)
308 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
314 /*******************************************************/
316 void AliITSpackageSSD::DelPClusterOI(Int_t index)
318 //This function looks like this,
319 //because probably cut cluster is
320 //on the beginning or on the end of package
322 if( ((*fClusterPIndexes)[0]) == index)
329 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
331 DelPCluster(fNclustersP-1);
336 for (i=1;i<fNclustersP-1;i++)
338 if( ((*fClusterPIndexes)[i])==index)
347 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
352 /*******************************************************/
354 void AliITSpackageSSD::DelNClusterOI(Int_t index)
356 //This function looks like this,
357 //because probably cluster to cut is
358 //on the beginning or on the end of package
361 if( ((*fClusterNIndexes)[0])==index)
368 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
370 DelNCluster(fNclustersN-1);
375 for (i=1;i<fNclustersN-1;i++)
377 if( ((*fClusterNIndexes)[i])==index)
385 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
389 /*******************************************************/
392 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
394 if (side == fgkSIDEP)
396 DelPClusterOI(index);
400 DelNClusterOI(index);
406 /**********************************************/
409 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
412 Int_t *takenNcl = new Int_t[fNclustersN];
416 if (debug) PrintClusters();
418 for (Int_t i=0;i<fNclustersP;i++)
422 //see comment on the beginning of MakeCombin
423 if (debug) cout<<"GetAllCombinations entered";
424 MakeCombin (array,num,0,takenNcl,sizet);
428 /**********************************************/
431 void AliITSpackageSSD::MakeCombin
432 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
436 //ATTENTION: anybody watching this function
437 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
438 //however, we have pointer to that array (TClonesArray)
440 //Get?SideCluster because it takes index from local look_up_table
445 AliITSclusterSSD *cl=GetPSideCluster(np);
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 if (np == fNclustersP-1) {
453 indcro=cl->GetCross(i);
454 if(IsFree(indcro,np,occup)) {
456 for(j=0;j<fNclustersP;j++)
458 if (nu<sizet) arr[nu][j]=occup[j];
464 if (nu<sizet-1) nu++;
469 indcro=cl->GetCross(i);
470 if(IsFree(indcro,np,occup)) {
472 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
473 //else printf("MakeComb - exceeding array size!\n");
481 /**********************************************/
482 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, Int_t *lis)
485 for (Int_t i=0;i<nn;i++)
487 if (lis[i]==idx) return kFALSE;
492 /**********************************************/
493 void AliITSpackageSSD::PrintClusters()
498 for (i=0;i<fNclustersP;i++)
500 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
501 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
503 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
505 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
506 // else cout<<"BAD SIDE ==N\n";
512 for (i=0;i<fNclustersN;i++)
514 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
515 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
517 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
519 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
520 // else cout<<"BAD SIDE ==P\n";
527 /**********************************************/
528 void AliITSpackageSSD::ConsumeClusters()
532 for(i=0;i<fNclustersP;i++)
534 GetPSideCluster(i)->Consume();
537 for(i=0;i<fNclustersN;i++)
539 GetNSideCluster(i)->Consume();
544 /**********************************************/
546 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI)
548 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
549 //if not egsist return -1;
550 for (Int_t i =0; i<fNclustersP-1;i++)
552 if(GetPSideClusterIdx(i) == OI)
553 return GetPSideClusterIdx(i+1);
557 /**********************************************/
558 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI)
560 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
561 //if not egsist return -1;
563 for (Int_t i =1; i<fNclustersP;i++)
565 if(GetPSideClusterIdx(i) == OI)
566 return GetPSideClusterIdx(i-1);
570 /**********************************************/
571 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI)
573 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
574 //if not egsist return -1;
575 for (Int_t i =0; i<fNclustersN-1;i++)
577 if(GetNSideClusterIdx(i) == OI)
578 return GetNSideClusterIdx(i+1);
583 /**********************************************/
584 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI)
586 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
587 //if not egsist return -1;
589 for (Int_t i =1; i<fNclustersN;i++)
591 if(GetNSideClusterIdx(i) == OI)
592 return GetNSideClusterIdx(i-1);
598 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
600 // split package of clusters
603 for (i=0;i<fNclustersN;i++)
605 if((*fClusterNIndexes)[i]==ni)
612 for (i=0;i<fNclustersP;i++)
614 if((*fClusterPIndexes)[i]==pi)
620 if (debug) cout<<" p = "<<p<<" n = "<<n;
621 if ((p==-1)||(n==-1)) return;
623 for (i=p;i<fNclustersP;i++)
625 pkg->AddPSideCluster(GetPSideClusterIdx(i));
629 for (i=n;i<fNclustersN;i++)
631 pkg->AddNSideCluster(GetNSideClusterIdx(i));
635 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";