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