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