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