]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSURecoDet.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSURecoDet.cxx
CommitLineData
173b3073 1#include <TGeoVolume.h>
2#include <TGeoTube.h>
3#include <TGeoManager.h>
ee52e7b5 4#include <TTree.h>
a11ef2e4 5#include "AliITSURecoDet.h"
6#include "AliITSUGeomTGeo.h"
7#include "AliITSsegmentation.h"
8#include "AliITSUSegmentationPix.h"
ee52e7b5 9#include "AliITSUClusterPix.h"
173b3073 10#include "AliITSUReconstructor.h"
11
a11ef2e4 12
ee52e7b5 13
a11ef2e4 14ClassImp(AliITSURecoDet)
15
173b3073 16
17const Char_t* AliITSURecoDet::fgkBeamPipeVolName = "IP_PIPE";
18
6121e5c5 19//______________________________________________________
20AliITSURecoDet::AliITSURecoDet()
21: fNLayers(0)
22 ,fNLayersActive(0)
23 ,fRMax(-1)
24 ,fRMin(-1)
25 ,fRITSTPCRef(-1)
26 ,fLayers(0)
27 ,fLayersActive(0)
28 ,fGeom(0)
29{
30 // def. c-tor
31}
173b3073 32
a11ef2e4 33//______________________________________________________
32d38de2 34AliITSURecoDet::AliITSURecoDet(AliITSUGeomTGeo* geom, const char* name)
a11ef2e4 35: fNLayers(0)
36 ,fNLayersActive(0)
37 ,fRMax(-1)
38 ,fRMin(-1)
70cb7fe4 39 ,fRITSTPCRef(-1)
a11ef2e4 40 ,fLayers(0)
41 ,fLayersActive(0)
32d38de2 42 ,fGeom(geom)
a11ef2e4 43{
44 // def. c-tor
45 SetNameTitle(name,name);
46 fLayers.SetOwner(kTRUE); // layers belong to this array
47 fLayersActive.SetOwner(kFALSE); // this one just points on active layers in fLayers
32d38de2 48 Build();
a11ef2e4 49}
50
51//______________________________________________________
52AliITSURecoDet::~AliITSURecoDet()
53{
54 // def. d-tor
55 fLayersActive.Clear();
56 fLayers.Clear(); // owned!
a11ef2e4 57}
58
59//______________________________________________________
60void AliITSURecoDet::Print(Option_t* opt) const
61{
62 //print
63 printf("Detector %s, %d layers, %d active layers\n",GetName(),GetNLayers(),GetNLayersActive());
64 TString opts = opt; opts.ToLower();
70cb7fe4 65 if (opts.Contains("lr")) {
66 for (int i=0;i<GetNLayers();i++) GetLayer(i)->Print(opt);
67 printf("ITS-TPC matching reference R: %.3f\n",fRITSTPCRef);
68 }
a11ef2e4 69}
70
71//______________________________________________________
72void AliITSURecoDet::AddLayer(const AliITSURecoLayer* lr)
73{
74 //add new layer
75 fLayers.AddLast((TObject*)lr);
76 fNLayers++;
77 if (lr->IsActive()) {
78 fLayersActive.AddLast((TObject*)lr);
79 fNLayersActive++;
80 }
81}
82
83//______________________________________________________
84Bool_t AliITSURecoDet::Build()
85{
86 // build detector from TGeo
87 //
32d38de2 88 if (!fGeom) AliFatal("Geometry interface is not set");
89 int nlr = fGeom->GetNLayers();
a11ef2e4 90 if (!nlr) AliFatal("No geometry loaded");
a11ef2e4 91 //
92 // build active ITS layers
93 for (int ilr=0;ilr<nlr;ilr++) {
852af72e 94 int lrTyp = fGeom->GetLayerChipTypeID(ilr);
a11ef2e4 95 // name layer according its active id, detector type and segmentation tyoe
852af72e 96 AliITSURecoLayer* lra = new AliITSURecoLayer(Form("Lr%d%s%d",ilr,fGeom->GetChipTypeName(lrTyp),
97 lrTyp%AliITSUGeomTGeo::kMaxSegmPerChipType),
32d38de2 98 ilr,fGeom);
173b3073 99 lra->SetPassive(kFALSE);
a11ef2e4 100 AddLayer(lra);
101 }
dde91d5d 102 //
103 // build passive ITS layers
104 //
173b3073 105 double rMin,rMax,zMin,zMax;
106 // beam pipe
107 TGeoVolume *v = gGeoManager->GetVolume(fgkBeamPipeVolName);
108 AliITSURecoLayer* lrp = 0;
109 if (!v) AliWarning("No beam pipe found in geometry");
24e3f48c 110 else {
173b3073 111 TGeoTube *t=(TGeoTube*)v->GetShape();
112 rMin = t->GetRmin();
113 rMax = t->GetRmax();
114 zMin =-t->GetDz();
115 zMax = t->GetDz();
116 lrp = new AliITSURecoLayer("BeamPipe");
117 lrp->SetRMin(rMin);
118 lrp->SetRMax(rMax);
119 lrp->SetR(0.5*(rMin+rMax));
120 lrp->SetZMin(zMin);
121 lrp->SetZMax(zMax);
122 lrp->SetPassive(kTRUE);
123 AddLayer(lrp);
124 //
125 }
126 //
127 // TPC-ITS wall
c92b1537 128 const AliITSURecoParam* recopar = AliITSUReconstructor::GetRecoParam();
129 if (recopar) {
130 lrp = new AliITSURecoLayer("TPC-ITSwall");
131 lrp->SetRMin(AliITSUReconstructor::GetRecoParam()->GetTPCITSWallRMin());
132 lrp->SetRMax(AliITSUReconstructor::GetRecoParam()->GetTPCITSWallRMax());
133 lrp->SetR(0.5*(lrp->GetRMin()+lrp->GetRMax()));
134 lrp->SetZMin(-AliITSUReconstructor::GetRecoParam()->GetTPCITSWallZSpanH());
135 lrp->SetZMax( AliITSUReconstructor::GetRecoParam()->GetTPCITSWallZSpanH());
136 lrp->SetMaxStep( AliITSUReconstructor::GetRecoParam()->GetTPCITSWallMaxStep());
137 lrp->SetPassive(kTRUE);
138 AddLayer(lrp);
139 }
140 else {
141 AliWarning("RecoParam is not available, TPC-ITS wall is not set");
142 }
173b3073 143 //
dde91d5d 144 IndexLayers();
145 Print("lr");
a11ef2e4 146 return kTRUE;
147}
32d38de2 148
dde91d5d 149//______________________________________________________
150void AliITSURecoDet::IndexLayers()
151{
c51c3124 152 // sort and index layers
153 const Double_t kRMargin = 1e-2; // 100 micron margin
dde91d5d 154 fLayersActive.Sort();
155 for (int i=0;i<fNLayersActive;i++) GetLayerActive(i)->SetActiveID(i);
156 fLayers.Sort();
157 for (int i=0;i<fNLayers;i++) GetLayer(i)->SetID(i);
c51c3124 158 if (fNLayers>0) {
159 SetRMin(GetLayer(0)->GetRMin()-kRMargin);
160 SetRMax(GetLayer(fNLayers-1)->GetRMax()+kRMargin);
161 }
70cb7fe4 162 //
163 // define the reference R for ITS/TPC matching: outside of last layer but before TPC materials
164 const double kOffsLastActR = 5.; // offset of reference layer wrt last active R
165 int lastActive = GetLrIDActive(fNLayersActive-1);
166 AliITSURecoLayer* lrA = GetLayer(lastActive); // last active
167 double rref = lrA->GetRMax() + kOffsLastActR;
168 //
169 if (lastActive < fNLayers-1) { // there are material layers outside ...
170 AliITSURecoLayer* lrL = GetLayer(lastActive+1);
171 if (lrL->GetRMin()<=rref) rref = lrL->GetRMin();
172 if (rref - lrA->GetRMax()<kOffsLastActR) {
173 AliError(Form("The ITS-TPC matching reference R=%.2f is too close to last active R=%.3f",rref,lrA->GetRMax()));
174 }
175 }
176 SetRITSTPCRef(rref);
177 //
dde91d5d 178}
8b16dbae 179
180//______________________________________________________
181Int_t AliITSURecoDet::FindLastLayerID(Double_t r, int dir) const
182{
183 // find the last layer which the particle moving in direction dir (1:outward,-1:inward)
184 // will traverse on its way to radius r
185 int ilr;
186 //
187 if (dir>0) {
188 for (ilr=0;ilr<fNLayers;ilr++) {
189 AliITSURecoLayer* lr = GetLayer(ilr);
190 if ( r<lr->GetR(-dir) ) break; // this layer at least entered
191 }
e2d2481c 192 return --ilr; // -1 will correspond to point below the smalles layer
8b16dbae 193 }
194 else {
195 for (ilr=fNLayers;ilr--;) {
196 AliITSURecoLayer* lr = GetLayer(ilr);
197 if ( r>lr->GetR(-dir) ) break; // this layer at least entered
198 }
199 ilr++;
200 return ilr<fNLayers ? ilr:-1; // -1 will correspond to point above outer layer
201 }
202 //
203}
204
205//______________________________________________________
206Int_t AliITSURecoDet::FindFirstLayerID(Double_t r, int dir) const
207{
208 // find the first layer which the particle moving in direction dir (1:outward,-1:inward)
209 // will traverse starting from radius r
210 int ilr;
211 //
212 if (dir>0) {
213 for (ilr=0;ilr<fNLayers;ilr++) {
214 AliITSURecoLayer* lr = GetLayer(ilr);
215 if ( r<lr->GetR(dir) ) break; // this layer at least entered
216 }
217 return ilr<fNLayers ? ilr:-1; // -1 will correspond to point above outer leayer
218 }
219 else {
220 for (ilr=fNLayers;ilr--;) {
221 AliITSURecoLayer* lr = GetLayer(ilr);
222 if ( r>lr->GetR(dir) ) break; // this layer at least entered
8b16dbae 223 }
224 return ilr; // -1 will correspond to point below inner layer
225 }
226 //
227}
ee52e7b5 228
229//______________________________________________________
230void AliITSURecoDet::CreateClusterArrays()
231{
232 // create cluster arrays for active layers
233 for (int ilr=0;ilr<fNLayersActive;ilr++) {
234 AliITSURecoLayer* lr = GetLayerActive(ilr);
235 lr->SetOwnsClusterArray(kTRUE);
852af72e 236 int tpDet = fGeom->GetLayerChipTypeID(ilr)/AliITSUGeomTGeo::kMaxSegmPerChipType;
ee52e7b5 237 //
852af72e 238 if (tpDet == AliITSUGeomTGeo::kChipTypePix) {
ee52e7b5 239 lr->SetClusters(new TClonesArray(AliITSUClusterPix::Class()));
240 }
241 else {
242 AliFatal(Form("Unknown detector type %d",tpDet));
243 }
244 //
245 }
246 //
247}
248
249//_____________________________________________________________________________
250Int_t AliITSURecoDet::LoadClusters(TTree* treeRP)
251{
252 // read clusters from the tree, if it is provided
253 if (!treeRP) return 0;
254 for (int ilr=fNLayersActive;ilr--;) {
255 TBranch* br = treeRP->GetBranch(Form("ITSRecPoints%d",ilr));
256 if (!br) AliFatal(Form("Provided cluster tree does not contain branch for layer %d",ilr));
257 br->SetAddress( GetLayerActive(ilr)->GetClustersAddress() );
258 }
259 return treeRP->GetEntry(0); // we are still in 1 ev/tree mode...
260}