]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSURecoDet.cxx
Correct treatment of tracks with pT<pTmin
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSURecoDet.cxx
1 #include <TGeoVolume.h>
2 #include <TGeoTube.h>
3 #include <TGeoManager.h>
4 #include <TTree.h>
5 #include "AliITSURecoDet.h"
6 #include "AliITSUGeomTGeo.h"
7 #include "AliITSsegmentation.h"
8 #include "AliITSUSegmentationPix.h"
9 #include "AliITSUClusterPix.h"
10 #include "AliITSUReconstructor.h"
11
12
13
14 ClassImp(AliITSURecoDet)
15
16
17 const Char_t* AliITSURecoDet::fgkBeamPipeVolName = "IP_PIPE";
18
19 //______________________________________________________
20 AliITSURecoDet::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 }
32
33 //______________________________________________________
34 AliITSURecoDet::AliITSURecoDet(AliITSUGeomTGeo* geom, const char* name)
35 :  fNLayers(0)
36   ,fNLayersActive(0)
37   ,fRMax(-1)
38   ,fRMin(-1)
39   ,fRITSTPCRef(-1)
40   ,fLayers(0)
41   ,fLayersActive(0)
42   ,fGeom(geom)
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
48   Build();
49 }
50
51 //______________________________________________________
52 AliITSURecoDet::~AliITSURecoDet()
53 {
54   // def. d-tor
55   fLayersActive.Clear(); 
56   fLayers.Clear();         // owned!
57 }
58
59 //______________________________________________________
60 void 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();
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   }
69 }
70
71 //______________________________________________________
72 void 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 //______________________________________________________
84 Bool_t AliITSURecoDet::Build()
85 {
86   // build detector from TGeo
87   //
88   if (!fGeom) AliFatal("Geometry interface is not set");
89   int nlr = fGeom->GetNLayers();
90   if (!nlr) AliFatal("No geometry loaded");
91   //
92   // build active ITS layers
93   for (int ilr=0;ilr<nlr;ilr++) {
94     int lrTyp = fGeom->GetLayerChipTypeID(ilr);
95     // name layer according its active id, detector type and segmentation tyoe
96     AliITSURecoLayer* lra = new AliITSURecoLayer(Form("Lr%d%s%d",ilr,fGeom->GetChipTypeName(lrTyp),
97                                                       lrTyp%AliITSUGeomTGeo::kMaxSegmPerChipType),
98                                                  ilr,fGeom);
99     lra->SetPassive(kFALSE);
100     AddLayer(lra);
101   }
102   //
103   // build passive ITS layers
104   //
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");
110   else {
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
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   }
143   //
144   IndexLayers();
145   Print("lr");
146   return kTRUE;
147 }
148
149 //______________________________________________________
150 void AliITSURecoDet::IndexLayers()
151 {
152   // sort and index layers
153   const Double_t kRMargin = 1e-2; // 100 micron margin
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);
158   if (fNLayers>0) {
159     SetRMin(GetLayer(0)->GetRMin()-kRMargin);
160     SetRMax(GetLayer(fNLayers-1)->GetRMax()+kRMargin);
161   }
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   //
178 }
179
180 //______________________________________________________
181 Int_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     }
192     return --ilr;  // -1 will correspond to point below the smalles layer
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 //______________________________________________________
206 Int_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
223     }
224     return ilr; // -1 will correspond to point below inner layer
225   }
226   //
227 }
228
229 //______________________________________________________
230 void 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);
236     int tpDet = fGeom->GetLayerChipTypeID(ilr)/AliITSUGeomTGeo::kMaxSegmPerChipType;
237     //
238     if (tpDet == AliITSUGeomTGeo::kChipTypePix) {
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 //_____________________________________________________________________________
250 Int_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 }