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