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():
44 /*******************************************************/
46 AliITSpackageSSD::AliITSpackageSSD
47 (TClonesArray *clustersP, TClonesArray *clustersN):
48 fClustersN(clustersN),
49 fClustersP(clustersP),
59 fClusterNIndexes = new TArrayI(300);
62 fClusterPIndexes = new TArrayI(300);
65 /*******************************************************/
68 AliITSpackageSSD::AliITSpackageSSD(Int_t len, TClonesArray *clustersP, TClonesArray *clustersN):
69 fClustersN(clustersN),
70 fClustersP(clustersP),
80 fClusterNIndexes = new TArrayI(len);
83 fClusterPIndexes = new TArrayI(len);
87 /*******************************************************/
89 AliITSpackageSSD::~AliITSpackageSSD()
92 delete fClusterNIndexes;
93 delete fClusterPIndexes;
96 /*******************************************************/
98 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package) :
100 fClustersN(package.fClustersN),
101 fClustersP(package.fClustersP),
102 fNclustersN(package.fNclustersN),
103 fNclustersP(package.fNclustersP),
109 for ( i =0; i<fNclustersN;i++)
111 fClusterNIndexes[i]= package.fClusterNIndexes[i];
114 for ( i =0; i<fNclustersP;i++)
116 fClusterPIndexes[i]= package.fClusterPIndexes[i];
121 /*******************************************************/
124 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
126 // assignment operator
130 if (this == &package) return *this;
131 fClustersN = package.fClustersN;
132 fClustersP = package.fClustersP;
134 fNclustersN= package.fNclustersN;
135 fNclustersP= package.fNclustersP;
137 for ( i =0; i<fNclustersN;i++)
139 fClusterNIndexes[i]= package.fClusterNIndexes[i];
142 for ( i =0; i<fNclustersP;i++)
144 fClusterPIndexes[i]= package.fClusterPIndexes[i];
147 if (fgkDebug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
153 /*******************************************************/
155 Int_t AliITSpackageSSD::GetNSideClusterIdx(Int_t index) const
157 // get N-side cluster
159 if ((index>-1)&&(index<fNclustersN))
160 return (*fClusterNIndexes)[index];
163 cout << "AliITSpackageSSD::GetNSideClusterIdx : Out of Range\n";
167 /*******************************************************/
170 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index) const
172 // get P-side cluster
174 if ((index>-1)&&(index<fNclustersP))
175 return (*fClusterPIndexes)[index];
178 cout << "AliITSpackageSSD::GetPSideClusterIdx : Out of Range\n";
182 /*******************************************************/
184 AliITSpackageSSD::GetPSideCluster(Int_t index)
186 // get Pside cluster from the TClonesArray of SSD clusters
188 return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
191 /*******************************************************/
194 AliITSpackageSSD::GetNSideCluster(Int_t index)
196 // get Nside cluster from the TClonesArray of SSD clusters
198 return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
202 /*******************************************************/
204 Bool_t AliITSpackageSSD::GetClusterWithOneCross
205 (Int_t & index, Bool_t& side)
207 // select clusters with on cross
209 if((fNclustersP==0)||(fNclustersN==0) )
211 printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
217 ind =(*fClusterPIndexes)[fNclustersP-1];
218 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
221 index =fNclustersP-1;
226 ind =(*fClusterNIndexes)[fNclustersN-1];
227 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
230 index = fNclustersN-1;
236 ind =(*fClusterPIndexes)[0];
237 if ( ( ((AliITSclusterSSD*)(*fClustersP)[ind] )->GetCrossNo() ) ==1 )
246 ind =(*fClusterNIndexes)[0];
247 if ( ( ((AliITSclusterSSD*)(*fClustersN)[ind] )->GetCrossNo() ) ==1 )
256 //Add for to be shure
261 /*******************************************************/
263 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
265 // call DelPCluster or DelNCluster depending on side
267 if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
269 /*******************************************************/
270 void AliITSpackageSSD::DelPCluster(Int_t index)
272 //it not deletes delete given cluster physically,
273 //but only complytely erase it from package
274 //all clusters are deleted automatically when TClonesArray is deleted
278 Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray
279 AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
280 Int_t ncr = clToDel->GetCrossNo();
284 idx = clToDel->GetCross(i);
285 ((AliITSclusterSSD *)((*fClustersN)[idx]) )->DelCross(clToDelIdx);
289 for (i=index;i<fNclustersP-1;i++)
291 (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
294 if (fgkDebug) cout<<"Cluster P ("<<index<<") deleted\n";
297 for (i=0;i<fNclustersN;i++)
299 if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
305 /*******************************************************/
306 void AliITSpackageSSD::DelNCluster(Int_t index)
308 //it not deletes delete given cluster physically,
309 //but only complytely erase it from package
310 //all clusters are deleted automatically when TClonesArray is deleted
314 Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray
315 AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
316 Int_t ncr = clToDel->GetCrossNo();
320 idx = clToDel->GetCross(i);
321 ((AliITSclusterSSD *)((*fClustersP)[idx]) )->DelCross(clToDelIdx);
325 for (i=index;i<fNclustersN-1;i++)
327 (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
330 if (fgkDebug) cout<<"Cluster N ("<<index<<") deleted\n";
332 for (i=0;i<fNclustersP;i++)
334 if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
340 /*******************************************************/
342 void AliITSpackageSSD::DelPClusterOI(Int_t index)
344 //This function looks like this,
345 //because probably cut cluster is
346 //on the beginning or on the end of package
348 if( ((*fClusterPIndexes)[0]) == index)
355 if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
357 DelPCluster(fNclustersP-1);
362 for (i=1;i<fNclustersP-1;i++)
364 if( ((*fClusterPIndexes)[i])==index)
373 cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
378 /*******************************************************/
380 void AliITSpackageSSD::DelNClusterOI(Int_t index)
382 //This function looks like this,
383 //because probably cluster to cut is
384 //on the beginning or on the end of package
387 if( ((*fClusterNIndexes)[0])==index)
394 if( ((*fClusterNIndexes)[fNclustersN-1])==index)
396 DelNCluster(fNclustersN-1);
401 for (i=1;i<fNclustersN-1;i++)
403 if( ((*fClusterNIndexes)[i])==index)
411 cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
415 /*******************************************************/
418 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
421 if (side == fgkSIDEP)
423 DelPClusterOI(index);
427 DelNClusterOI(index);
433 /**********************************************/
436 void AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
438 // get all combinations
439 Int_t *takenNcl = new Int_t[fNclustersN];
443 if (fgkDebug) PrintClusters();
445 for (Int_t i=0;i<fNclustersP;i++)
449 //see comment on the beginning of MakeCombin
450 if (fgkDebug) cout<<"GetAllCombinations entered";
451 MakeCombin (array,num,0,takenNcl,sizet);
455 /**********************************************/
458 void AliITSpackageSSD::MakeCombin
459 (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
462 //ATTENTION: anybody watching this function
463 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
464 //however, we have pointer to that array (TClonesArray)
466 //Get?SideCluster because it takes index from local look_up_table
471 AliITSclusterSSD *cl=GetPSideCluster(np);
473 Int_t nc = cl->GetCrossNo(); //number of crosses for this cluster
474 Int_t indcro; //index of given cluster on side N that
475 // this cluster crosses with
477 if (np == fNclustersP-1) {
479 indcro=cl->GetCross(i);
480 if(IsFree(indcro,np,occup)) {
482 for(j=0;j<fNclustersP;j++)
484 if (nu<sizet) arr[nu][j]=occup[j];
490 if (nu<sizet-1) nu++;
495 indcro=cl->GetCross(i);
496 if(IsFree(indcro,np,occup)) {
498 if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
499 //else printf("MakeComb - exceeding array size!\n");
507 /**********************************************/
508 Bool_t AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, const Int_t *lis) const
511 for (Int_t i=0;i<nn;i++)
513 if (lis[i]==idx) return kFALSE;
518 /**********************************************/
519 void AliITSpackageSSD::PrintClusters()
521 // print cluster info
524 for (i=0;i<fNclustersP;i++)
526 cout<<i<<". IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
527 for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
529 cout<<GetPSideCluster(i)->GetCross(j)<<" ";
531 // if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
532 // else cout<<"BAD SIDE ==N\n";
538 for (i=0;i<fNclustersN;i++)
540 cout<<i<<". IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<" C. IDXs : ";
541 for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
543 cout<<GetNSideCluster(i)->GetCross(j)<<" ";
545 // if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
546 // else cout<<"BAD SIDE ==P\n";
552 /**********************************************/
553 void AliITSpackageSSD::ConsumeClusters()
558 for(i=0;i<fNclustersP;i++)
560 GetPSideCluster(i)->Consume();
563 for(i=0;i<fNclustersN;i++)
565 GetNSideCluster(i)->Consume();
570 /**********************************************/
572 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI) const
574 //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
575 //if not egsist return -1;
576 for (Int_t i =0; i<fNclustersP-1;i++)
578 if(GetPSideClusterIdx(i) == OI)
579 return GetPSideClusterIdx(i+1);
584 /**********************************************/
585 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI) const
587 //Returns index of previous P cluster OI in package; OI == Original Inedx (in TClonesArray)
588 //if not egsist return -1;
590 for (Int_t i =1; i<fNclustersP;i++)
592 if(GetPSideClusterIdx(i) == OI)
593 return GetPSideClusterIdx(i-1);
597 /**********************************************/
598 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI) const
600 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
601 //if not egsist return -1;
602 for (Int_t i =0; i<fNclustersN-1;i++)
604 if(GetNSideClusterIdx(i) == OI)
605 return GetNSideClusterIdx(i+1);
610 /**********************************************/
611 Int_t AliITSpackageSSD::GetPrvNIdx(Int_t OI) const
613 //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
614 //if not egsist return -1;
616 for (Int_t i =1; i<fNclustersN;i++)
618 if(GetNSideClusterIdx(i) == OI)
619 return GetNSideClusterIdx(i-1);
625 void AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
627 // split package of clusters
630 for (i=0;i<fNclustersN;i++)
632 if((*fClusterNIndexes)[i]==ni)
639 for (i=0;i<fNclustersP;i++)
641 if((*fClusterPIndexes)[i]==pi)
648 cout<<" p = "<<p<<" n = "<<n;
650 if ((p==-1)||(n==-1)) return;
652 for (i=p;i<fNclustersP;i++)
654 pkg->AddPSideCluster(GetPSideClusterIdx(i));
658 for (i=n;i<fNclustersN;i++)
660 pkg->AddNSideCluster(GetNSideClusterIdx(i));
664 cout<<" After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";