1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include <TGeoManager.h>
19 #include <TGeoVolume.h>
23 #include "AliGeomManager.h"
24 #include "AliITSsegmentationUpgrade.h"
27 //////////////////////////////////////////////////////
28 // Segmentation class for //
31 //////////////////////////////////////////////////////
33 ClassImp(AliITSsegmentationUpgrade)
35 //_____________________________________________________________________________
37 AliITSsegmentationUpgrade::AliITSsegmentationUpgrade():
47 AliDebug(2,"Default constructor is called");
48 // Default constructor
50 if(!gGeoManager) AliGeomManager::LoadGeometry("geometry.root");
51 TFile *f=TFile::Open("Segmentation.root");
57 AliError("Segmentation not available");
60 x=(TArrayD*)f->Get("CellSizeX");
61 z=(TArrayD*)f->Get("CellSizeZ");
62 nS=(TArrayD*)f->Get("nSectors");
67 while(gGeoManager->GetVolume(Form("LayerSilicon%i",i))){
68 TGeoVolume *vol = gGeoManager->GetVolume(Form("LayerSilicon%i",i));
70 AliInfo(Form("the volume %s has not been found... exiting!",Form("LayerSilicon%i",i)));
74 TGeoTube *shape = (TGeoTube*)vol->GetShape();
76 AliInfo(Form("the volume %s has not shape defined... exiting!",vol->GetName()));
79 // AliInfo(Form(" volume index %i ", i));
80 // setting the geometry parameters (needed for trasformations Global-Local)
81 fMaxRadius.Set(i+1); fMaxRadius.AddAt(shape->GetRmax(),i);
82 fMinRadius.Set(i+1); fMinRadius.AddAt(shape->GetRmin(),i);
83 fHalfLength.Set(i+1); fHalfLength.AddAt(shape->GetDz(),i);
86 fCellSizeX.AddAt(x->At(i),i);
87 fCellSizeZ.AddAt(z->At(i),i);
90 fNSectors = (Int_t)(nS->At(0));
93 //_______________________________________________________________
94 AliITSsegmentationUpgrade::AliITSsegmentationUpgrade(TArrayD radii, TArrayD widths, TArrayD Length):
103 for(Int_t i=0; i<radii.GetSize();i++){
105 fMaxRadius.AddAt(radii.At(i)+widths.At(i),i);
107 fMinRadius.AddAt(radii.At(i),i);
108 fHalfLength.Set(i+1);
109 fHalfLength.AddAt(Length.At(i),i);
112 //_____________________________________________________________________________
113 void AliITSsegmentationUpgrade::SetSegmentation(Int_t ilayer, Double_t xsize, Double_t zsize){
115 // x/z size in microns
116 if(fCellSizeX.GetSize()<ilayer+1) fCellSizeX.Set(ilayer+1);
117 if(fCellSizeZ.GetSize()<ilayer+1) fCellSizeZ.Set(ilayer+1);
118 AliDebug(10,Form("xsize %f zsize %f ilayer %i", xsize,zsize,ilayer));
119 fCellSizeX.AddAt(xsize,ilayer);
120 fCellSizeZ.AddAt(zsize,ilayer);
121 AliDebug(10,Form("fCellsizeX %f fCellSizeZ %f", fCellSizeX.At(ilayer), fCellSizeZ.At(ilayer)));
123 //_____________________________________________________________________________
124 void AliITSsegmentationUpgrade::SetFullSegmentation(TArrayD xsize, TArrayD zsize){
126 if(xsize.GetSize()!=zsize.GetSize())AliDebug(1,"Be Carefull Array Size Differ!!");
128 if(xsize.GetSize()!=fMaxRadius.GetSize())AliDebug(10,Form("Be Carefull Segmentation Array (%i) and Geometry Array Differ (%i)!!",xsize.GetSize(),fMaxRadius.GetSize()));
130 for(Int_t ilayer=0; ilayer<fMaxRadius.GetSize(); ilayer++)SetSegmentation(ilayer, xsize.At(ilayer), zsize.At(ilayer));
132 //_________________________________________________________________________________
133 void AliITSsegmentationUpgrade::GetSegmentation(Int_t ilayer, Double_t &xsize, Double_t &zsize ) const{
135 xsize = fCellSizeX.At(ilayer);
136 zsize =fCellSizeZ.At(ilayer);
138 //_____________________________________________________________________________
139 Bool_t AliITSsegmentationUpgrade::GlobalToDet(Int_t ilayer, Double_t x,Double_t y,Double_t z,Double_t &xl,Double_t &zl) const{
142 if(TMath::Abs(z)>fHalfLength.At(ilayer)) return kFALSE;
145 Double_t xyproj= TMath::Sqrt(x*x+y*y);
146 if(xyproj==0 || xyproj-0.001 > fMaxRadius.At(ilayer))return kFALSE;
147 Double_t alpha= TMath::ATan2(y,x);
148 if(x>0 && y<0)alpha=alpha+2.*(TMath::Pi());
149 if(x<0 && y<0)alpha=alpha+2.*(TMath::Pi());
154 //_____________________________________________________________________________
155 Bool_t AliITSsegmentationUpgrade::DetToGlobal(Int_t ilayer, Double_t xl,Double_t zl,Double_t &x,Double_t &y, Double_t &z) const {
157 if(TMath::Abs(z)>fHalfLength.At(ilayer)) return kFALSE;
159 Double_t alpha = xl/fMaxRadius.At(ilayer);
162 x = fMaxRadius.At(ilayer)*TMath::Cos(alpha);
163 y = fMaxRadius.At(ilayer)*TMath::Sin(alpha);
167 //_______________________________________________________________________________
168 void AliITSsegmentationUpgrade::GetNpad(Int_t ilayer, Int_t &nx, Int_t &nz){
170 if(fCellSizeX.At(ilayer)==0)AliDebug(1,"Attention! Check your X Segmentation!!");
171 if(fCellSizeZ.At(ilayer)==0)AliDebug(1,"Attention! Check your Z Segmentation!!");
173 nx=(Int_t)(2.*TMath::Pi()*fMaxRadius.At(ilayer)/fCellSizeX.At(ilayer));
174 nz=(Int_t)(2.*fHalfLength.At(ilayer)/fCellSizeZ.At(ilayer));
177 //________________________________________________________________________________
178 Int_t AliITSsegmentationUpgrade::GetNLayers(){
180 if(!gGeoManager) TGeoManager::Import("geometry.root");
184 for(Int_t ivol=0; ivol<gGeoManager->GetListOfVolumes()->GetEntries();ivol++){
185 TString volname = gGeoManager->GetListOfVolumes()->At(ivol)->GetName();
186 if(!volname.Contains("Silicon")) continue;
198 //__________________________________________________________________________________
199 Bool_t AliITSsegmentationUpgrade::DetToGlobal(Int_t ilayer, Int_t module, Double_t xl,Double_t zl,Double_t &x,Double_t &y, Double_t &z) const {
200 if(module<0){ DetToGlobal(ilayer,xl,zl, x, y, z);
204 if(TMath::Abs(z)>fHalfLength.At(ilayer)) return kFALSE;
206 Double_t alpha = (xl+module*(fMaxRadius.At(ilayer)*((TMath::Pi()*2)/fNSectors)))/fMaxRadius.At(ilayer);
209 x = fMaxRadius.At(ilayer)*TMath::Cos(alpha);
210 y = fMaxRadius.At(ilayer)*TMath::Sin(alpha);
214 //_______________________________________________________________________________________________
215 Bool_t AliITSsegmentationUpgrade::GlobalToDet(Int_t ilayer, Double_t x,Double_t y,Double_t z,Double_t &xl,Double_t &zl,Int_t &module) const {
217 GlobalToDet(ilayer,x,y,z, xl, zl);
221 if(TMath::Abs(z)>fHalfLength.At(ilayer)) return kFALSE;
225 Double_t xyproj= TMath::Sqrt(x*x+y*y);
226 if(xyproj==0 || xyproj-0.001 > fMaxRadius.At(ilayer)){
229 Double_t alpha= TMath::ATan2(y,x);
230 if(x>0 && y<0)alpha=alpha+2.*(TMath::Pi());
231 if(x<0 && y<0)alpha=alpha+2.*(TMath::Pi());
233 module = (Int_t)(alpha*(fNSectors/(TMath::Pi()*2)));
234 Double_t alphaSect= module*((TMath::Pi()*2)/fNSectors);
235 xl = xyproj*(alpha-alphaSect);//with respect the module
236 //AliInfo(Form(" globtodet con modulo x,y,z = %f, %f, %f, alpha %f module %i alpha del modulo %f xlocal %f xlocal rispettp al modulo %f ", x,y,z,alpha,module, alphaSect, xyproj*alpha, xl));
239 //____________________________________________________________________________________________________
240 Bool_t AliITSsegmentationUpgrade::DetToPixID(Double_t xl, Double_t zl,Int_t layer, Int_t &nx, Int_t &nz) const {
242 if(xl>fMaxRadius.At(layer)*(TMath::Pi()*2/fNSectors))return kFALSE;
243 if(TMath::Abs(zl)>fHalfLength.At(layer)) return kFALSE;
245 nx=(Int_t)(xl/fCellSizeX.At(layer));
246 //printf(" half %f \n ", fHalfLength.At(layer));
247 nz=(Int_t)((zl+fHalfLength.At(layer))/fCellSizeZ.At(layer));
250 //_________________________________________________________________________________________________________
251 Bool_t AliITSsegmentationUpgrade::DetToTrack2(Int_t layer,Int_t module, Double_t xl,Double_t zl, Double_t &ytr, Double_t &ztr)const {
252 //sistema di tracciamento la x=0, y è la rphi rispetto al centro del modulo
253 //sistema locale è la y=0 x è rphi rispetto all'inizio del modulo
255 //voglio andare dalle locali alle tracciamento
259 // printf( " det to track xl %f zl %f \n ", xl, zl);
262 ch=DetToGlobal(layer,module,xl,zl,x,y,z);
263 Double_t radius =fMaxRadius.At(layer);
265 phiGrad=TMath::ATan2(y,x);//cluster phi angle (rad)
266 if (phiGrad<0) phiGrad+=TMath::TwoPi();//from 0 to 360
267 else if (phiGrad>=TMath::TwoPi()) phiGrad-=TMath::TwoPi();//
269 Double_t alpha= (module*(((TMath::Pi()*2)/fNSectors))+(((TMath::Pi()*2)/fNSectors)/2));//angle at the center of the ladder (rad)
271 Double_t phiTrk= (phiGrad-alpha);// cluster angle in the rotated system (rad)
273 ytr=radius*phiTrk; // tracking system coordinate: r*phi
274 // AliInfo(Form( " det : x %f | track y %f, zeta %f ", xl, ytr,ztr));
277 //__________________________________________
278 Bool_t AliITSsegmentationUpgrade::DetToTrack(Int_t layer,Int_t module, Double_t xl,Double_t zl, Double_t &ytr, Double_t &ztr)const {
279 //sistema di tracciamento la x=0, y è la rphi rispetto al centro del modulo
280 //sistema locale è la y=0 x è rphi rispetto all'inizio del modulo
282 //voglio andare dalle locali alle tracciamento
284 Double_t radius =fMaxRadius.At(layer);
285 Double_t alphaloc = module*(TMath::Pi()*2)/fNSectors; //alpha di riferimento per il modulo locale in rad
286 Double_t xlrif = alphaloc*radius;//xlocale di riferimento per questo modulo
288 Double_t xlvera = xlrif + xl; // x locale vera rispetto a tutto il cilindro, per sapere a che angolo sto effettivamente
290 Double_t alphaGlob = xlvera/radius; //in rad
292 //da alpha vera posso ottenereinfo di tracciamento
294 Double_t alpha_track= (module*(((TMath::Pi()*2)/fNSectors))+(((TMath::Pi()*2)/fNSectors)/2));//angle at the center of the ladder (rad)
296 Double_t phiTrk= (alphaGlob-alpha_track);// cluster angle in the rotated system (rad)
298 ytr=radius*phiTrk; // tracking system coordinate: r*phi
299 // AliInfo(Form( " det : x %f | track y %f, zeta %f ", xl, ytr,ztr));
302 //_______________________
303 Int_t AliITSsegmentationUpgrade::GetModule(Double_t x,Double_t y)const{
306 Double_t alpha= TMath::ATan2(y,x);
307 if(x>0 && y<0)alpha=alpha+2.*(TMath::Pi());
308 if(x<0 && y<0)alpha=alpha+2.*(TMath::Pi());
310 return GetModule(alpha);
312 //_______________________
313 Int_t AliITSsegmentationUpgrade::GetModule(Double_t phi) const {
315 // sector corresponding to that phi [0,2Pi]
319 if(phi<0 || phi > TMath::TwoPi()) {
320 AliError(Form("Phi is not within the acceptable range [0,2Pi] %f ",phi));
323 module = (Int_t) (phi*((Double_t)fNSectors/(TMath::TwoPi())));
329 //_______________________
330 Double_t AliITSsegmentationUpgrade::GetAlpha(Int_t module)const{
332 // angle of the sector center
334 Double_t angle = TMath::DegToRad()*(360./fNSectors);
335 return module*angle+0.5*angle;