+ *this = source; // copy everything
+ for(i=0;i<GetIndexMax();i++){
+ GetGeomMatrix(i)->GetIndex(id);
+ GetGeomMatrix(i)->GetMatrix(r0);
+ if(id[0]==1){ // Layer 1 is treated different from the others.
+ for(j=0;j<3;j++) for(k=0;k<3;k++){
+ r1[j][k] = 0.;
+ for(l=0;l<3;l++) r1[j][k] += a0[j][l]*r0[l][k];
+ } // end for j,k
+ }else{
+ for(j=0;j<3;j++) for(k=0;k<3;k++){
+ r1[j][k] = 0.;
+ for(l=0;l<3;l++) r1[j][k] += a1[j][l]*r0[l][k];
+ } // end for j,k
+ } // end if
+ GetGeomMatrix(i)->SetMatrix(r1);
+ } // end for i
+ this->fTrans = (this->fTrans && 0xfffe) + 1; // set bit 0 true.
+ return;
+}
+//______________________________________________________________________
+Int_t AliITSgeom::GetNearest(const Double_t g[3],Int_t lay)const{
+ // Finds the Detector (Module) that is nearest the point g [cm] in
+ // ALICE Global coordinates. If layer !=0 then the search is restricted
+ // to Detectors (Modules) in that particular layer.
+ // Inputs:
+ // Double_t g[3] The ALICE Cartesian global coordinate from which the
+ // distance is to be calculated with.
+ // Int_t lay The layer to restrict the search to. If layer=0 then
+ // all layers are searched. Default is lay=0.
+ // Output:
+ // none.
+ // Return:
+ // The module number representing the nearest module.
+ Int_t i,l,a,e,in=0;
+ Double_t d,dn=1.0e10;
+ Bool_t t=lay!=0; // skip if lay = 0 default value check all layers.
+
+ for(i=0;i<fNmodules;i++){
+ if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
+ if((d=GetGeomMatrix(i)->Distance2(g))<dn){
+ dn = d;
+ in = i;
+ } // end if
+ } // end for i
+ return in;
+}
+//______________________________________________________________________
+void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay)const{
+ // Finds 27 Detectors (Modules) that are nearest the point g [cm] in
+ // ALICE Global coordinates. If layer !=0 then the search is restricted
+ // to Detectors (Modules) in that particular layer. The number 27 comes
+ // from including the nearest detector and all those around it (up, down,
+ // left, right, forwards, backwards, and the corners).
+ // Input:
+ // Double_t g[3] The ALICE Cartesian global coordinate from which the
+ // distance is to be calculated with.
+ // Int_t lay The layer to restrict the search to. If layer=0 then
+ // all layers are searched. Default is lay=0.
+ // Output:
+ // Int_t n[27] The module number representing the nearest 27 modules
+ // in order.
+ // Return:
+ // none.
+ Int_t i,l,a,e,in[27]={0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,};
+ Double_t d,dn[27]={1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
+ 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
+ 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
+ 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,
+ 1.0e10,1.0e10,1.0e10};
+ Bool_t t=(lay!=0); // skip if lay = 0 default value check all layers.
+
+ for(i=0;i<fNmodules;i++){
+ if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;}
+ for(a=0;a<27;a++){
+ d = GetGeomMatrix(i)->Distance2(g);
+ if(d<dn[a]){
+ for(e=26;e>a;e--){dn[e] = dn[e-1];in[e] = in[e-1];}
+ dn[a] = d; in[a] = i;
+ } // end if d<dn[i]
+ } // end for a
+ } // end for i
+ for(i=0;i<27;i++) n[i] = in[i];
+}
+//----------------------------------------------------------------------
+Double_t AliITSgeom::GetAverageRadiusOfLayer(Int_t layer,Double_t &range)const{
+ // Loops over all modules for a given layer and computes the
+ // average cylindrical radius (about the z axis) and the range of
+ // radii covered by this layer. Units, [cm] the Alice default unit.
+ // Input:
+ // Int_t layer The layer for which the average radii is to be found
+ // Output:
+ // Double_t &range The range of radii covered by this layer
+ // Return:
+ // The average radii for this layer.
+ Double_t r=0.0,rmin=1.0e6,rmax=-1.0,rp,t[3],l[3],dl[3];
+ Int_t n=0,i,j,lay,lad,det;
+ AliITSDetector idet;
+
+ for(i=0;i<GetIndexMax();i++) {
+ GetModuleId(i,lay,lad,det);
+ idet = GetModuleType(i);
+ if(lay!=layer) continue;
+ dl[0] = dl[1] = dl[2] = 0.0;
+ if(IsShapeDefined((Int_t)idet)) {
+ switch(idet){
+ case kSPD:{
+ dl[0] = ((AliITSgeomSPD*)GetShape(idet))->GetDx();
+ dl[1] = ((AliITSgeomSPD*)GetShape(idet))->GetDy();
+ dl[2] = ((AliITSgeomSPD*)GetShape(idet))->GetDz();
+ } break;
+ case kSDD: case kSDDp:{
+ dl[0] = ((AliITSgeomSDD*)GetShape(idet))->GetDx();
+ dl[1] = ((AliITSgeomSDD*)GetShape(idet))->GetDy();
+ dl[2] = ((AliITSgeomSDD*)GetShape(idet))->GetDz();
+ } break;
+ case kSSD: case kSSDp:{
+ dl[0] = ((AliITSgeomSSD*)GetShape(idet))->GetDx();
+ dl[1] = ((AliITSgeomSSD*)GetShape(idet))->GetDy();
+ dl[2] = ((AliITSgeomSSD*)GetShape(idet))->GetDz();
+ } break;
+ case kND:{
+ Warning("GetAverageRadiusOfLayer",
+ "idet=kND undefined detector type");
+ continue;
+ }break;
+ default:{
+ Warning("GetAverageRadiusOfLayer",
+ "idet=%d not a defined value",(Int_t)idet);
+ continue;
+ }break;
+ }// end switch.
+ } // end of
+ n++;
+ GetTransCyln(i,t);
+ rp = t[0];
+ r += rp;
+ if(rmin>rp) rmin = rp;
+ if(rmax<rp) rmax = rp;
+ for(j=0;j<8;j++){ // loop over the corners
+ l[0] = dl[0];if(j%2==0) l[0] = -dl[0];
+ l[1] = dl[1];if(j==2||j==3||j==6||j==7) l[1] = -dl[1];
+ l[2] = dl[2];if(j>3) l[2] = -dl[2];
+ LtoG(i,l,t);
+ rp = TMath::Sqrt(t[0]*t[0]+t[1]*t[1]);
+ if(rmin>rp) rmin = rp;
+ if(rmax<rp) rmax = rp;
+ } // end for j
+ } // end for i
+ r /= (Double_t)n;
+ range = TMath::Max(rmax-r,r-rmin);
+ return r;
+}
+//_______________________________________________________________________
+void AliITSgeom::DetLToTrackingV2(Int_t md, Float_t xin, Float_t zin, Float_t &yout, Float_t &zout) {
+
+ //Conversion from local coordinates on detectors to local
+ //coordinates used for tracking ("v2")
+ Float_t x,y,z; Double_t rt[9];GetTrans(md,x,y,z);GetRotMatrix(md,rt);
+ Double_t al=TMath::ATan2(rt[1],rt[0])+TMath::Pi();
+ yout=-(-xin+(x*TMath::Cos(al)+y*TMath::Sin(al)));
+ if(md<(GetModuleIndex(2,1,1)-1))yout*=-1; zout=-zin+(Double_t)z;
+}