]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryModuleTransformer.cxx
hopefully the last refinements for correct type conversion in calibration
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryModuleTransformer.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17 //
18 // -------------------------------------
19 // Class AliMUONGeometryModuleTransformer
20 // -------------------------------------
21 // Class for definition of the detector module transformations
22 // Author: Ivana Hrivnacova, IPN Orsay
23
24 #include "AliMUONGeometryModuleTransformer.h"
25 #include "AliMUONGeometryDetElement.h"  
26
27 #include "AliMpExMap.h" 
28
29 #include "AliLog.h"     
30
31 #include <TVirtualMC.h>
32 #include <TGeoMatrix.h>
33 #include <TObjArray.h>
34 #include <TArrayI.h>
35 #include <Riostream.h>
36
37 /// \cond CLASSIMP
38 ClassImp(AliMUONGeometryModuleTransformer)
39 /// \endcond
40
41 const TString AliMUONGeometryModuleTransformer::fgkModuleNamePrefix = "GM";
42
43 //______________________________________________________________________________
44 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
45  : TObject(),
46    fModuleId(moduleId),
47    fModuleName(),
48    fVolumePath(),
49    fTransformation(0),
50    fDetElements(0)
51 {
52 /// Standard constructor
53
54   // Chamber transformation
55   fTransformation = new TGeoHMatrix("");
56
57   // Det elements transformation stores
58   fDetElements = new AliMpExMap(true);
59   
60   // Compose module name
61   fModuleName = fgkModuleNamePrefix;
62   fModuleName += moduleId;
63 }
64
65
66 //______________________________________________________________________________
67 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer()
68  : TObject(),
69    fModuleId(0),
70    fModuleName(),
71    fVolumePath(),
72    fTransformation(0),
73    fDetElements(0)
74 {
75 /// Default constructor
76 }
77
78
79 //______________________________________________________________________________
80 AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer() 
81 {
82 /// Destructor
83
84   delete fTransformation;
85   delete fDetElements;
86 }
87
88 //
89 // public methods
90 //
91
92 //______________________________________________________________________________
93 void  AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
94                   Float_t xg, Float_t yg, Float_t zg, 
95                   Float_t& xl, Float_t& yl, Float_t& zl) const
96 {
97 /// Transform point from the global reference frame (ALIC)
98 /// to the local reference frame of the detection element specified
99 /// by detElemId.
100
101   // Get detection element
102   AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
103   if (!detElement) return;
104    
105   // Transform point
106   detElement->Global2Local(xg, yg, zg, xl, yl, zl);
107 }
108                                   
109 //______________________________________________________________________________
110 void  AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
111                   Double_t xg, Double_t yg, Double_t zg, 
112                   Double_t& xl, Double_t& yl, Double_t& zl) const
113 {
114 /// Transform point from the global reference frame (ALIC)
115 /// to the local reference frame of the detection element specified
116 /// by detElemId.
117
118    // Get detection element
119    AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
120    if (!detElement) return;
121    
122    // Transform point
123    detElement->Global2Local(xg, yg, zg, xl, yl, zl);
124 }
125                                   
126 //______________________________________________________________________________
127 void  AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
128                  Float_t xl, Float_t yl, Float_t zl, 
129                  Float_t& xg, Float_t& yg, Float_t& zg) const
130 {
131 /// Transform point from the local reference frame of the detection element 
132 /// specified by detElemId to the global reference frame (ALIC).
133
134   // Get detection element
135   AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
136   if (!detElement) return;
137    
138    // Transform point
139   detElement->Local2Global(xl, yl, zl, xg, yg, zg);  
140 }
141
142 //______________________________________________________________________________
143 void  AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
144                  Double_t xl, Double_t yl, Double_t zl, 
145                  Double_t& xg, Double_t& yg, Double_t& zg) const
146 {
147 /// Transform point from the local reference frame of the detection element 
148 /// specified by detElemId to the global reference frame (ALIC).
149
150    // Get detection element
151    AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
152    if (!detElement) return;
153    
154    // Transform point
155    detElement->Local2Global(xl, yl, zl, xg, yg, zg); 
156 }
157
158 //______________________________________________________________________________
159 void  AliMUONGeometryModuleTransformer::SetTransformation(
160                                            const TGeoHMatrix& transform)
161 {
162 /// Set the module position wrt world.
163
164   *fTransformation = transform;
165 }  
166
167 //______________________________________________________________________________
168 TString AliMUONGeometryModuleTransformer::GetVolumeName() const
169
170 /// Extract volume name from the path
171   
172   std::string volPath = fVolumePath.Data();
173   std::string::size_type first = volPath.rfind('/')+1;
174   std::string::size_type last = volPath.rfind('_');
175   
176   return volPath.substr(first, last-first );
177 }
178
179 //______________________________________________________________________________
180 TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
181
182 /// Extract mother volume name from the path
183   
184   std::string volPath = fVolumePath.Data();
185   std::string::size_type first = volPath.rfind('/');
186   volPath = volPath.substr(0, first);
187
188   std::string::size_type next = volPath.rfind('/')+1;
189   std::string::size_type last = volPath.rfind('_');
190   
191   return volPath.substr(next, last-next );
192 }
193
194 //______________________________________________________________________________
195 AliMUONGeometryDetElement*
196 AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
197 {
198 /// Return the detection element specified by detElemId.
199 /// Give error if detection element is not defined and warn is true.
200
201    // Get detection element
202    AliMUONGeometryDetElement* detElement
203      = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
204
205    if (!detElement) {
206      if (warn)
207        AliErrorStream() 
208          << "Detection element " << detElemId
209          << " not found in module " << fModuleId << endl;
210      return 0;
211    }  
212
213    return detElement;
214 }