]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSpackageSSD.cxx
Print removed
[u/mrichter/AliRoot.git] / ITS / AliITSpackageSSD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15 /* $Id$ */
16
17 #include <Riostream.h>
18 #include <TClonesArray.h>
19 #include "AliITSpackageSSD.h"
20 #include "AliITSclusterSSD.h"
21
22 const Bool_t AliITSpackageSSD::fgkSIDEP=kTRUE;
23 const Bool_t AliITSpackageSSD::fgkSIDEN=kFALSE;
24
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
31 //
32 //--------------------------------------------------------------------------
33 AliITSpackageSSD::AliITSpackageSSD()
34 {
35   // constructor
36   fNclustersN=0;
37   fClusterNIndexes = 0; 
38                 
39   fNclustersP=0;
40   fClusterPIndexes = 0;
41   if (fgkDebug) cout<<"Default Ctor was used\n>>>>>>>>>>>>>><<<<<<<<<<<<<";
42 }
43
44
45 /*******************************************************/
46
47 AliITSpackageSSD::AliITSpackageSSD
48   (TClonesArray *clustersP, TClonesArray *clustersN)
49 {
50   // constructor
51   fClustersP=clustersP;
52   fClustersN=clustersN;
53         
54   fNclustersN=0;
55   fClusterNIndexes = new TArrayI(300); 
56         
57   fNclustersP=0;
58   fClusterPIndexes = new TArrayI(300);          
59 }
60
61 /*******************************************************/
62
63
64 AliITSpackageSSD::AliITSpackageSSD
65   ( Int_t len, TClonesArray *clustersP, TClonesArray *clustersN)
66 {       
67   // constructor
68   fClustersP=clustersP;
69   fClustersN=clustersN;
70
71   fNclustersN=0;
72   fClusterNIndexes = new TArrayI(len); 
73         
74   fNclustersP=0;
75   fClusterPIndexes = new TArrayI(len);          
76 }
77
78
79 /*******************************************************/
80
81 AliITSpackageSSD::~AliITSpackageSSD()
82 {
83   // destructor
84   delete fClusterNIndexes;
85   delete fClusterPIndexes;              
86 }
87
88 /*******************************************************/
89
90 AliITSpackageSSD::AliITSpackageSSD(const AliITSpackageSSD &package) : 
91     TObject(package){
92   // copy constractor
93   Int_t i;  //iterator
94  
95   if (this == &package) return;
96   fClustersN = package.fClustersN;
97   fClustersP = package.fClustersP;
98   
99   fNclustersN= package.fNclustersN;
100   fNclustersP= package.fNclustersP;
101   
102   for ( i =0; i<fNclustersN;i++)
103     {
104       fClusterNIndexes[i]= package.fClusterNIndexes[i]; 
105     }
106   
107   for ( i =0; i<fNclustersP;i++)
108     {
109       fClusterPIndexes[i]= package.fClusterPIndexes[i]; 
110     }
111   
112   if (fgkDebug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
113   
114   return; 
115   
116 }
117 /*******************************************************/
118
119 AliITSpackageSSD&  
120 AliITSpackageSSD::operator=( const AliITSpackageSSD & package)
121 {
122   //  assignment operator
123   //
124   Int_t i;  //iterator
125   
126   if (this == &package) return *this;
127   fClustersN = package.fClustersN;
128   fClustersP = package.fClustersP;
129   
130   fNclustersN= package.fNclustersN;
131   fNclustersP= package.fNclustersP;
132   
133   for ( i =0; i<fNclustersN;i++)
134     {
135       fClusterNIndexes[i]= package.fClusterNIndexes[i]; 
136     }
137   
138   for ( i =0; i<fNclustersP;i++)
139     {
140       fClusterPIndexes[i]= package.fClusterPIndexes[i]; 
141     }
142   
143   if (fgkDebug) cout << "Copying function was used\n<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>";
144   
145   return *this; 
146   
147 }
148
149 /*******************************************************/
150
151 Int_t AliITSpackageSSD::GetNSideClusterIdx(Int_t index) const
152 {
153   // get N-side cluster
154   // 
155   if ((index>-1)&&(index<fNclustersN))
156     return (*fClusterNIndexes)[index];
157   else 
158     {
159       cout << "AliITSpackageSSD::GetNSideClusterIdx  : Out of Range\n";
160       return -1;
161     }
162 }
163 /*******************************************************/
164
165
166 Int_t AliITSpackageSSD::GetPSideClusterIdx(Int_t index) const
167 {
168   // get P-side cluster
169   //
170   if ((index>-1)&&(index<fNclustersP))
171     return (*fClusterPIndexes)[index];
172   else 
173     {
174       cout << "AliITSpackageSSD::GetPSideClusterIdx  : Out of Range\n";
175       return -1;
176     } 
177 }
178 /*******************************************************/
179 AliITSclusterSSD*  
180 AliITSpackageSSD::GetPSideCluster(Int_t index)
181 {
182   // get Pside cluster from the TClonesArray of SSD clusters
183   //
184   return (AliITSclusterSSD*)((*fClustersP)[GetPSideClusterIdx(index)]);
185 }
186
187 /*******************************************************/
188
189 AliITSclusterSSD*  
190 AliITSpackageSSD::GetNSideCluster(Int_t index)
191 {
192   // get Nside cluster from the TClonesArray of SSD clusters
193   //
194   return (AliITSclusterSSD*)((*fClustersN)[GetNSideClusterIdx(index)]);
195 }
196
197
198 /*******************************************************/
199
200 Bool_t AliITSpackageSSD::GetClusterWithOneCross
201 (Int_t & index, Bool_t& side)
202 {
203   // select clusters with on cross 
204   //
205   if((fNclustersP==0)||(fNclustersN==0) )
206     {
207       printf("Empty package ((fNclustersP==0)||(fNclustersN==0))\n");
208       index = -2;
209       return kFALSE;
210     } 
211   Int_t ind;
212   
213   ind =(*fClusterPIndexes)[fNclustersP-1]; 
214   if (  ( ((AliITSclusterSSD*)(*fClustersP)[ind]  )->GetCrossNo()  ) ==1 )
215     {
216       //index=ind;
217       index =fNclustersP-1; 
218       side=fgkSIDEP;
219       return kTRUE;
220     }
221   
222   ind =(*fClusterNIndexes)[fNclustersN-1]; 
223   if (  (  ((AliITSclusterSSD*)(*fClustersN)[ind]  )->GetCrossNo() ) ==1  )
224     {
225       //index=ind;
226       index = fNclustersN-1;
227       side=fgkSIDEN;
228       return kTRUE;
229     }
230   
231   
232   ind =(*fClusterPIndexes)[0];
233   if (  ( ((AliITSclusterSSD*)(*fClustersP)[ind]  )->GetCrossNo() ) ==1 )
234     {
235       //index=ind;
236       index = 0;
237       side=fgkSIDEP;
238       return kTRUE;
239     }
240   
241   
242   ind =(*fClusterNIndexes)[0];
243   if (  ( ((AliITSclusterSSD*)(*fClustersN)[ind]  )->GetCrossNo()  ) ==1  )
244     {
245       //    index=ind;
246       index = 0;  
247       side=fgkSIDEN;
248       return kTRUE;
249     }
250   
251   
252   //Add for to be shure 
253   index = -1;
254   return kFALSE;
255   
256 }
257 /*******************************************************/
258
259 void AliITSpackageSSD::DelCluster(Int_t index, Bool_t side)
260 {
261   // call DelPCluster or DelNCluster depending on side
262   //
263   if(side==fgkSIDEP) DelPCluster(index); else DelNCluster(index);
264 }
265 /*******************************************************/
266 void AliITSpackageSSD::DelPCluster(Int_t index)
267 {
268   //it not deletes delete given cluster physically, 
269   //but only complytely erase it from package
270   //all clusters are deleted automatically when TClonesArray is deleted
271   
272   Int_t i;
273   Int_t idx;
274   Int_t clToDelIdx = GetPSideClusterIdx(index); //Index of cluster in TClonesArray 
275   AliITSclusterSSD *clToDel = GetPSideCluster(index); //cluster to be deleted
276   Int_t ncr = clToDel->GetCrossNo();
277   
278   for (i =0;i<ncr;i++)
279     {
280       idx = clToDel->GetCross(i);
281       ((AliITSclusterSSD *)((*fClustersN)[idx])   )->DelCross(clToDelIdx);
282     }
283   
284   
285   for (i=index;i<fNclustersP-1;i++)
286     {
287       (*fClusterPIndexes)[i]=(*fClusterPIndexes)[i+1];
288     }
289   fNclustersP--; 
290   if (fgkDebug) cout<<"Cluster P ("<<index<<") deleted\n";
291   
292   
293   for (i=0;i<fNclustersN;i++)
294     {
295       if ( (GetNSideCluster(i)->GetCrossNo())==0) DelNCluster(i);
296     }
297 }
298
299
300
301 /*******************************************************/
302 void AliITSpackageSSD::DelNCluster(Int_t index)
303 {
304   //it not deletes delete given cluster physically, 
305   //but only complytely erase it from package
306   //all clusters are deleted automatically when TClonesArray is deleted
307   
308   Int_t i;
309   Int_t idx;
310   Int_t clToDelIdx = GetNSideClusterIdx(index); //Index of cluster in TClonesArray 
311   AliITSclusterSSD *clToDel = GetNSideCluster(index); //cluster to be deleted
312   Int_t ncr = clToDel->GetCrossNo();
313   
314   for (i =0;i<ncr;i++)
315     {
316       idx = clToDel->GetCross(i);
317       ((AliITSclusterSSD *)((*fClustersP)[idx])   )->DelCross(clToDelIdx);
318     }
319   
320   
321   for (i=index;i<fNclustersN-1;i++)
322     {
323       (*fClusterNIndexes)[i]=(*fClusterNIndexes)[i+1];
324     }
325   fNclustersN--; 
326   if (fgkDebug) cout<<"Cluster N ("<<index<<") deleted\n";
327   
328   for (i=0;i<fNclustersP;i++)
329     {
330       if ( (GetPSideCluster(i)->GetCrossNo())==0) DelPCluster(i);
331     }
332   
333 }
334
335
336 /*******************************************************/
337
338 void AliITSpackageSSD::DelPClusterOI(Int_t index)
339 {
340   //This function looks like this, 
341 //because probably cut cluster is 
342 //on the beginning or on the end of package 
343  Int_t i;
344  if( ((*fClusterPIndexes)[0]) == index) 
345   {
346     DelPCluster(0);
347     return;
348   }
349  else
350   { 
351    if( ((*fClusterPIndexes)[fNclustersP-1]) ==index)
352     {
353       DelPCluster(fNclustersP-1);
354       return;
355     }
356    else
357     {
358      for (i=1;i<fNclustersP-1;i++)
359        {
360          if( ((*fClusterPIndexes)[i])==index)
361           {
362             DelPCluster(i);
363             return;
364           }
365        }
366     }
367   }
368  
369  cout<<"AliITSpackageSSD - DelPClusterOI: index "<<index<<" not found\n";
370
371 }
372
373
374 /*******************************************************/
375
376 void AliITSpackageSSD::DelNClusterOI(Int_t index)
377 {
378 //This function looks like this, 
379 //because probably cluster to cut is 
380 //on the beginning or on the end of package 
381
382  Int_t i;
383  if( ((*fClusterNIndexes)[0])==index) 
384   {
385     DelNCluster(0);
386     return;
387   }
388  else
389   { 
390    if( ((*fClusterNIndexes)[fNclustersN-1])==index)
391     {
392       DelNCluster(fNclustersN-1);
393       return;
394     }
395    else
396     {
397      for (i=1;i<fNclustersN-1;i++)
398        {
399          if( ((*fClusterNIndexes)[i])==index)
400          {
401           DelNCluster(i);
402           return;
403          }
404        }
405     }
406   }
407  cout<<"AliITSpackageSSD - DelNClusterOI: index "<<index<<" not found\n";
408 }
409
410
411 /*******************************************************/
412
413
414 void AliITSpackageSSD::DelClusterOI(Int_t index, Bool_t side)
415 {
416   // delete cluster
417  if (side == fgkSIDEP)
418   {    
419     DelPClusterOI(index);
420   } 
421   else
422   {
423     DelNClusterOI(index);
424   }
425
426 }
427
428
429 /**********************************************/
430
431
432 void  AliITSpackageSSD::GetAllCombinations(Int_t**array,Int_t &num,Int_t sizet)
433 {
434   // get all combinations
435   Int_t *takenNcl = new Int_t[fNclustersN];
436   
437   num=0;
438   
439   if (fgkDebug) PrintClusters();
440
441   for (Int_t i=0;i<fNclustersP;i++)
442    {
443      takenNcl[i]=-1;
444    }
445   //see comment on the beginning of MakeCombin
446   if (fgkDebug) cout<<"GetAllCombinations entered";
447   MakeCombin (array,num,0,takenNcl,sizet);
448
449   delete []takenNcl; 
450 }
451 /**********************************************/
452
453
454 void  AliITSpackageSSD::MakeCombin
455    (Int_t**arr,Int_t& nu, Int_t np, Int_t *occup, Int_t sizet)
456
457 {
458 //ATTENTION: anybody watching this function
459 //AliITSclusterSSD::GetCrossNo() returns index of cluster in main array belonging to AliITSmodulesSSD
460 //however, we have pointer to that array (TClonesArray)
461 //we can not use 
462 //Get?SideCluster because it takes index from local look_up_table
463  
464  Int_t i,j;
465  
466  //this cluster
467  AliITSclusterSSD *cl=GetPSideCluster(np);
468
469  Int_t nc = cl->GetCrossNo();  //number of crosses for this cluster
470  Int_t indcro;                 //index of given cluster on side N that 
471                                // this cluster crosses with
472    
473  if (np == fNclustersP-1) {
474    for (i=0;i<nc;i++) {
475      indcro=cl->GetCross(i);
476      if(IsFree(indcro,np,occup)) {
477         occup[np]=indcro;
478         for(j=0;j<fNclustersP;j++)  
479         {
480            if (nu<sizet) arr[nu][j]=occup[j];
481            else {
482                continue;}
483         }
484       
485         occup[np]=-1;
486         if (nu<sizet-1) nu++;
487      }
488    }
489   } else {
490     for (i=0;i<nc;i++) {
491        indcro=cl->GetCross(i);
492        if(IsFree(indcro,np,occup)) {
493           occup[np]=indcro;
494           if (nu<sizet) MakeCombin(arr,nu,(np+1),occup,sizet);
495           //else printf("MakeComb - exceeding array size!\n");
496        }
497     }
498     occup[np]=-1;
499   } 
500
501 }
502
503 /**********************************************/
504 Bool_t  AliITSpackageSSD::IsFree(Int_t idx, Int_t nn, const Int_t *lis) const
505 {
506   // 
507   for (Int_t i=0;i<nn;i++)
508     {
509       if (lis[i]==idx) return kFALSE;
510     }
511   return kTRUE;
512 }
513
514 /**********************************************/
515 void AliITSpackageSSD::PrintClusters()
516 {
517   // print cluster info
518 Int_t i,j;
519 cout<<"SIDE P\n";
520 for (i=0;i<fNclustersP;i++)
521  {
522    cout<<i<<".  IO="<<GetPSideClusterIdx(i)<<" NC="<<GetPSideCluster(i)->GetCrossNo()<<"     C. IDXs : ";
523    for (j=0;j<GetPSideCluster(i)->GetCrossNo();j++)
524     {
525       cout<<GetPSideCluster(i)->GetCross(j)<<" ";
526     }
527  //  if (GetPSideCluster(i)->GetSide()) cout<<" P\n";
528  //  else cout<<"BAD SIDE ==N\n";
529     cout<<"\n";
530    
531  }
532
533 cout <<"SIDE N\n";
534 for (i=0;i<fNclustersN;i++)
535  {
536    cout<<i<<".  IO="<<GetNSideClusterIdx(i)<<" NC="<<GetNSideCluster(i)->GetCrossNo()<<"     C. IDXs : ";
537    for (j=0;j<GetNSideCluster(i)->GetCrossNo();j++)
538     {
539       cout<<GetNSideCluster(i)->GetCross(j)<<" ";
540     }
541  //  if (GetNSideCluster(i)->GetSide()) cout<<" N\n";
542  //  else cout<<"BAD SIDE ==P\n";
543     cout<<"\n";   
544  }
545  
546 }
547
548 /**********************************************/
549 void AliITSpackageSSD::ConsumeClusters()
550 {
551   // consume cluster
552   register Int_t i;
553   
554   for(i=0;i<fNclustersP;i++)
555     {
556       GetPSideCluster(i)->Consume();
557     }
558   
559   for(i=0;i<fNclustersN;i++)
560     {
561       GetNSideCluster(i)->Consume();
562     }
563   
564 }
565
566 /**********************************************/
567
568 Int_t AliITSpackageSSD::GetNextPIdx(Int_t OI) const
569 {
570  //Returns index of next P cluster OI in package; OI == Original Inedx (in TClonesArray)
571  //if not egsist return -1;
572  for (Int_t i =0; i<fNclustersP-1;i++)
573   {
574     if(GetPSideClusterIdx(i) == OI)
575        return GetPSideClusterIdx(i+1);
576   }
577  return -1;
578 }
579
580 /**********************************************/
581 Int_t AliITSpackageSSD::GetPrvPIdx(Int_t OI) const
582 {
583  //Returns index of previous P cluster  OI in package; OI == Original Inedx (in TClonesArray)
584  //if not egsist return -1;
585  
586  for (Int_t i =1; i<fNclustersP;i++)
587   {
588     if(GetPSideClusterIdx(i) == OI)
589        return GetPSideClusterIdx(i-1);
590   }
591   return -1;
592 }
593 /**********************************************/
594 Int_t AliITSpackageSSD::GetNextNIdx(Int_t OI) const
595 {
596 //Returns index of next N cluster OI in package; OI == Original Inedx (in TClonesArray)
597  //if not egsist return -1;
598  for (Int_t i =0; i<fNclustersN-1;i++)
599   {
600     if(GetNSideClusterIdx(i) == OI)
601        return GetNSideClusterIdx(i+1);
602   }
603  return -1;
604
605 }
606 /**********************************************/
607 Int_t  AliITSpackageSSD::GetPrvNIdx(Int_t OI) const
608 {
609  //Returns index of previous N cluster OI in package; OI == Original Inedx (in TClonesArray)
610  //if not egsist return -1;
611  
612  for (Int_t i =1; i<fNclustersN;i++)
613   {
614     if(GetNSideClusterIdx(i) == OI)
615        return GetNSideClusterIdx(i-1);
616   }
617   return -1;
618  
619 }
620
621 void  AliITSpackageSSD::SplitPackage(Int_t pi, Int_t ni, AliITSpackageSSD* pkg)
622 {
623   // split package of clusters
624   Int_t p=-1, n=-1;
625   Int_t i;
626   for (i=0;i<fNclustersN;i++)
627    {
628      if((*fClusterNIndexes)[i]==ni) 
629       {
630         n = i;
631         break;
632       }
633     } 
634    
635   for (i=0;i<fNclustersP;i++)
636    {
637      if((*fClusterPIndexes)[i]==pi) 
638       {
639         p = i;
640         break;
641       }
642     }  
643   if (fgkDebug) {
644     cout<<" p = "<<p<<"  n = "<<n;
645   }
646   if ((p==-1)||(n==-1)) return;
647   
648   for (i=p;i<fNclustersP;i++)
649    {
650      pkg->AddPSideCluster(GetPSideClusterIdx(i));       
651    }
652   fNclustersP = p;
653   
654   for (i=n;i<fNclustersN;i++)
655    {
656      pkg->AddNSideCluster(GetNSideClusterIdx(i));       
657    }
658   fNclustersN = n;
659  
660   cout<<"  After split: fNclustersP = "<< fNclustersP<< "fNclustersN = "<< fNclustersN<<"\n";
661 }