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