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