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