Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackingSector.cxx
CommitLineData
a65a7e70 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/* $Id: AliTRDtrackingSector.cxx 23810 2008-02-08 09:00:27Z hristov $ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Tracking data container for one sector //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
28#include "AliTRDReconstructor.h"
29#include "AliTRDtrackingSector.h"
30#include "AliTRDtrackingChamber.h"
31
32
33ClassImp(AliTRDtrackingSector)
34
35//_____________________________________________________________________________
36AliTRDtrackingSector::AliTRDtrackingSector()
37 :fSector(-1)
38 ,fN(0)
39 ,fGeom(NULL)
40{
41 // Default constructor
42
43 memset(fChamber, 0, AliTRDgeometry::kNdets*sizeof(AliTRDtrackingChamber*));
44 memset(fStack, 0, AliTRDgeometry::kNlayer*sizeof(AliTRDtrackingChamber*));
45 memset(fIndex, -1, AliTRDgeometry::kNdets*sizeof(Char_t));
46 memset(fX0, 0, AliTRDgeometry::kNlayer*sizeof(Float_t));
47}
48
49//_____________________________________________________________________________
50AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry *geo, Int_t gs)
51 :fSector(gs)
52 ,fN(0)
53 ,fGeom(geo)
54{
55 //
56 // AliTRDtrackingSector Constructor
57 //
58
59 memset(fChamber, 0, AliTRDgeometry::kNdets*sizeof(AliTRDtrackingChamber*));
60 memset(fStack, 0, AliTRDgeometry::kNlayer*sizeof(AliTRDtrackingChamber*));
61 memset(fIndex, -1, AliTRDgeometry::kNdets*sizeof(Char_t));
62 memset(fX0, 0, AliTRDgeometry::kNlayer*sizeof(Float_t));
63}
64
65
66//_____________________________________________________________________________
67void AliTRDtrackingSector::Init(const AliTRDReconstructor *rec)
68{
69// Steer building of tracking chambers and build tracking sector.
70// Propagate radial position information (calibration/alignment aware) from chambers to sector level
71//
72
73 AliTRDchamberTimeBin *tb = NULL;
74 AliTRDtrackingChamber **tc = &fChamber[0];
75 for(Int_t ic = 0; (ic<AliTRDgeometry::kNdets) && (*tc); ic++, tc++){
76 for(Int_t itb=0; itb<AliTRDseedV1::kNtb; itb++){
77 if(!(tb = (*tc)->GetTB(itb))) continue;
78 tb->SetReconstructor(rec);
79 }
80 (*tc)->Build(fGeom, rec->IsHLT());
81 }
82
83 Int_t nl;
84 for(int il=0; il<AliTRDgeometry::kNlayer; il++){
85 fX0[il] = 0.; nl = 0;
86 for(int is=0; is<AliTRDgeometry::kNstack; is++){
87 Int_t idx = is*AliTRDgeometry::kNlayer + il;
88 if(fIndex[idx]<0) continue;
89 fX0[il] += GetChamber(fIndex[idx])->GetX();
90 nl++;
91 }
92 if(!nl){
93 //printf("Could not estimate radial position of plane %d in sector %d.\n", ip, fSector);
94 continue;
95 }
96 fX0[il] /= Float_t(nl);
97 }
98}
99
100
101
102//_____________________________________________________________________________
103void AliTRDtrackingSector::Clear(const Option_t *opt)
104{
105// Reset counters and steer chamber clear
106
107 AliTRDtrackingChamber **tc = &fChamber[0];
108 for(Int_t ich=0; ich<fN; ich++, tc++){
109 (*tc)->Clear(opt);
110 delete (*tc); (*tc) = NULL; // I would avoid
111 }
112 memset(fIndex, -1, AliTRDgeometry::kNdets*sizeof(Char_t));
113 fN = 0;
114}
115
116//_____________________________________________________________________________
117AliTRDtrackingChamber* AliTRDtrackingSector::GetChamber(Int_t stack, Int_t layer, Bool_t build)
118{
119// Return chamber at position (stack, plane) in current
120// sector or build a new one if it is not already created
121
122 Int_t ch = stack*AliTRDgeometry::kNlayer + layer;
123 if(fIndex[ch] >= 0) return fChamber[Int_t(fIndex[ch])];
124 else if(!build) return NULL;
125
126 // CHAMBER HAS TO BE BUILD
127 Int_t rch = ch;do rch--; while(rch>=0 && fIndex[rch]<0);
128 fIndex[ch] = rch >=0 ? fIndex[rch]+1 : 0;
129 fN++;
130
131 memmove(&fChamber[Int_t(fIndex[ch])+1], &fChamber[Int_t(fIndex[ch])], (AliTRDgeometry::kNdets-fIndex[ch]-1)*sizeof(void*));
132 for(Int_t ic = ch+1; ic<AliTRDgeometry::kNdets; ic++) fIndex[ic] += fIndex[ic] >= 0 ? 1 : 0;
133
134 AliTRDtrackingChamber *chmb = fChamber[Int_t(fIndex[ch])] = new AliTRDtrackingChamber();
135 chmb->SetDetector(AliTRDgeometry::GetDetector(layer, stack, fSector));
136 return chmb;
137}
138
139//_____________________________________________________________________________
140AliTRDtrackingChamber** AliTRDtrackingSector::GetStack(Int_t stack)
141{
142// Return chamber at position (stack, plane) in current
143// sector or build a new one if it is not already created
144
145 if(stack<0 || stack>=AliTRDgeometry::kNstack) return NULL;
146
147 Int_t ich, n = 0;
148 for(int il=0; il<AliTRDgeometry::kNlayer; il++){
149 ich = stack*AliTRDgeometry::kNlayer + il;
150 if(fIndex[ich] < 0) fStack[il] = NULL;
151 else{
152 fStack[il] = fChamber[Int_t(fIndex[ich])];
153 n++;
154 }
155 }
156
157 return n ? &fStack[0] : NULL;
158}
159
160//_____________________________________________________________________________
161void AliTRDtrackingSector::Print(Option_t *opt) const
162{
163// Dump info about this tracking sector and the tracking chamber within
164//
165
166 printf("\n\tSector[%2d]\n", fSector);
167 for(int il=0; il<AliTRDgeometry::kNlayer; il++){
168 for(int is =0; is<AliTRDgeometry::kNstack; is++){
169 Int_t ch = is*AliTRDgeometry::kNlayer + il;
170 if(opt) fChamber[Int_t(fIndex[ch])]->Print(opt);
171 else printf("%2d[%2d] ", fIndex[ch], fIndex[ch]>=0 ? fChamber[Int_t(fIndex[ch])]->GetNClusters() : 0);
172 }
173 if(!opt) printf("\n");
174 }
175
176}