1 #include <TGeoVolume.h>
3 #include <TGeoManager.h>
5 #include "AliITSURecoDet.h"
6 #include "AliITSUGeomTGeo.h"
7 #include "AliITSsegmentation.h"
8 #include "AliITSUClusterPix.h"
9 #include "AliITSUReconstructor.h"
13 ClassImp(AliITSURecoDet)
16 const Char_t* AliITSURecoDet::fgkBeamPipeVolName = "IP_PIPE";
18 //______________________________________________________
19 AliITSURecoDet::AliITSURecoDet()
32 //______________________________________________________
33 AliITSURecoDet::AliITSURecoDet(AliITSUGeomTGeo* geom, const char* name)
44 SetNameTitle(name,name);
45 fLayers.SetOwner(kTRUE); // layers belong to this array
46 fLayersActive.SetOwner(kFALSE); // this one just points on active layers in fLayers
50 //______________________________________________________
51 AliITSURecoDet::~AliITSURecoDet()
54 fLayersActive.Clear();
55 fLayers.Clear(); // owned!
58 //______________________________________________________
59 void AliITSURecoDet::Print(Option_t* opt) const
62 printf("Detector %s, %d layers, %d active layers\n",GetName(),GetNLayers(),GetNLayersActive());
63 TString opts = opt; opts.ToLower();
64 if (opts.Contains("lr")) {
65 for (int i=0;i<GetNLayers();i++) GetLayer(i)->Print(opt);
66 printf("ITS-TPC matching reference R: %.3f\n",fRITSTPCRef);
70 //______________________________________________________
71 void AliITSURecoDet::AddLayer(const AliITSURecoLayer* lr)
74 fLayers.AddLast((TObject*)lr);
77 fLayersActive.AddLast((TObject*)lr);
82 //______________________________________________________
83 Bool_t AliITSURecoDet::Build()
85 // build detector from TGeo
87 if (!fGeom) AliFatal("Geometry interface is not set");
88 int nlr = fGeom->GetNLayers();
89 if (!nlr) AliFatal("No geometry loaded");
91 // build active ITS layers
92 for (int ilr=0;ilr<nlr;ilr++) {
93 int lrTyp = fGeom->GetLayerChipTypeID(ilr);
94 // name layer according its active id, detector type and segmentation tyoe
95 AliITSURecoLayer* lra = new AliITSURecoLayer(Form("Lr%d%s%d",ilr,fGeom->GetChipTypeName(lrTyp),
96 lrTyp%AliITSUGeomTGeo::kMaxSegmPerChipType),
98 lra->SetPassive(kFALSE);
102 // build passive ITS layers
104 double rMin,rMax,zMin,zMax;
106 TGeoVolume *v = gGeoManager->GetVolume(fgkBeamPipeVolName);
107 AliITSURecoLayer* lrp = 0;
108 if (!v) AliWarning("No beam pipe found in geometry");
110 TGeoTube *t=(TGeoTube*)v->GetShape();
115 lrp = new AliITSURecoLayer("BeamPipe");
118 lrp->SetR(0.5*(rMin+rMax));
121 lrp->SetPassive(kTRUE);
127 const AliITSURecoParam* recopar = AliITSUReconstructor::GetRecoParam();
129 lrp = new AliITSURecoLayer("TPC-ITSwall");
130 lrp->SetRMin(AliITSUReconstructor::GetRecoParam()->GetTPCITSWallRMin());
131 lrp->SetRMax(AliITSUReconstructor::GetRecoParam()->GetTPCITSWallRMax());
132 lrp->SetR(0.5*(lrp->GetRMin()+lrp->GetRMax()));
133 lrp->SetZMin(-AliITSUReconstructor::GetRecoParam()->GetTPCITSWallZSpanH());
134 lrp->SetZMax( AliITSUReconstructor::GetRecoParam()->GetTPCITSWallZSpanH());
135 lrp->SetMaxStep( AliITSUReconstructor::GetRecoParam()->GetTPCITSWallMaxStep());
136 lrp->SetPassive(kTRUE);
140 AliWarning("RecoParam is not available, TPC-ITS wall is not set");
148 //______________________________________________________
149 void AliITSURecoDet::IndexLayers()
151 // sort and index layers
152 const Double_t kRMargin = 1e-2; // 100 micron margin
153 fLayersActive.Sort();
154 for (int i=0;i<fNLayersActive;i++) GetLayerActive(i)->SetActiveID(i);
156 for (int i=0;i<fNLayers;i++) GetLayer(i)->SetID(i);
158 SetRMin(GetLayer(0)->GetRMin()-kRMargin);
159 SetRMax(GetLayer(fNLayers-1)->GetRMax()+kRMargin);
162 // define the reference R for ITS/TPC matching: outside of last layer but before TPC materials
163 const double kOffsLastActR = 5.; // offset of reference layer wrt last active R
164 int lastActive = GetLrIDActive(fNLayersActive-1);
165 AliITSURecoLayer* lrA = GetLayer(lastActive); // last active
166 double rref = lrA->GetRMax() + kOffsLastActR;
168 if (lastActive < fNLayers-1) { // there are material layers outside ...
169 AliITSURecoLayer* lrL = GetLayer(lastActive+1);
170 if (lrL->GetRMin()<=rref) rref = lrL->GetRMin();
171 if (rref - lrA->GetRMax()<kOffsLastActR) {
172 AliError(Form("The ITS-TPC matching reference R=%.2f is too close to last active R=%.3f",rref,lrA->GetRMax()));
179 //______________________________________________________
180 Int_t AliITSURecoDet::FindLastLayerID(Double_t r, int dir) const
182 // find the last layer which the particle moving in direction dir (1:outward,-1:inward)
183 // will traverse on its way to radius r
187 for (ilr=0;ilr<fNLayers;ilr++) {
188 AliITSURecoLayer* lr = GetLayer(ilr);
189 if ( r<lr->GetR(-dir) ) break; // this layer at least entered
191 return --ilr; // -1 will correspond to point below the smalles layer
194 for (ilr=fNLayers;ilr--;) {
195 AliITSURecoLayer* lr = GetLayer(ilr);
196 if ( r>lr->GetR(-dir) ) break; // this layer at least entered
199 return ilr<fNLayers ? ilr:-1; // -1 will correspond to point above outer layer
204 //______________________________________________________
205 Int_t AliITSURecoDet::FindFirstLayerID(Double_t r, int dir) const
207 // find the first layer which the particle moving in direction dir (1:outward,-1:inward)
208 // will traverse starting from radius r
212 for (ilr=0;ilr<fNLayers;ilr++) {
213 AliITSURecoLayer* lr = GetLayer(ilr);
214 if ( r<lr->GetR(dir) ) break; // this layer at least entered
216 return ilr<fNLayers ? ilr:-1; // -1 will correspond to point above outer leayer
219 for (ilr=fNLayers;ilr--;) {
220 AliITSURecoLayer* lr = GetLayer(ilr);
221 if ( r>lr->GetR(dir) ) break; // this layer at least entered
223 return ilr; // -1 will correspond to point below inner layer
228 //______________________________________________________
229 void AliITSURecoDet::CreateClusterArrays()
231 // create cluster arrays for active layers
232 for (int ilr=0;ilr<fNLayersActive;ilr++) {
233 AliITSURecoLayer* lr = GetLayerActive(ilr);
234 lr->SetOwnsClusterArray(kTRUE);
235 int tpDet = fGeom->GetLayerChipTypeID(ilr)/AliITSUGeomTGeo::kMaxSegmPerChipType;
237 if (tpDet == AliITSUGeomTGeo::kChipTypePix) {
238 lr->SetClusters(new TClonesArray(AliITSUClusterPix::Class()));
241 AliFatal(Form("Unknown detector type %d",tpDet));
248 //_____________________________________________________________________________
249 Int_t AliITSURecoDet::LoadClusters(TTree* treeRP)
251 // read clusters from the tree, if it is provided
252 if (!treeRP) return 0;
253 for (int ilr=fNLayersActive;ilr--;) {
254 TBranch* br = treeRP->GetBranch(Form("ITSRecPoints%d",ilr));
255 if (!br) AliFatal(Form("Provided cluster tree does not contain branch for layer %d",ilr));
256 br->SetAddress( GetLayerActive(ilr)->GetClustersAddress() );
258 return treeRP->GetEntry(0); // we are still in 1 ev/tree mode...
261 Int_t FindIndex(AliITSUClusterPix **parr, Int_t i, AliITSUClusterPix *c) {
263 AliITSUClusterPix *cc=parr[b];
264 if (c->Compare(cc) <= 0) return b;
268 if (c->Compare(cc) > 0) return e+1;
271 for (; b<e; m=(b+e)/2) {
273 if (c->Compare(cc) > 0) b=m+1;
279 //______________________________________________________
280 void AliITSURecoDet::SortClusters(AliITSUClusterPix::SortMode_t mode)
282 // process clsuters according to requested mode
283 AliITSUClusterPix::SetSortMode( mode );
284 for (int ilr=fNLayersActive;ilr--;) {
285 TClonesArray *arr=GetLayerActive(ilr)->GetClusters();
287 const Int_t kNcl=arr->GetEntriesFast();
288 AliITSUClusterPix **parr=new AliITSUClusterPix*[kNcl];
289 parr[0]=(AliITSUClusterPix *)arr->UncheckedAt(0);
290 for (Int_t j=1; j<kNcl; j++) {
291 AliITSUClusterPix *c=(AliITSUClusterPix*)arr->UncheckedAt(j);
292 Int_t i=FindIndex(parr,j,c);
294 memmove(parr+i+1 ,parr+i,k*sizeof(AliITSUClusterPix*));
298 TObject **cont=arr->GetObjectRef();
299 for (Int_t i=0; i<kNcl; i++) cont[i]=parr[i];