]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/AliMUONGeometryModuleTransformer.cxx
files for Geant/Fluka correction in the ITS
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryModuleTransformer.cxx
... / ...
CommitLineData
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
25#include "AliMUONGeometryModuleTransformer.h"
26#include "AliMUONGeometryDetElement.h"
27
28#include "AliMpExMap.h"
29
30#include "AliLog.h"
31
32#include <TVirtualMC.h>
33#include <TGeoMatrix.h>
34#include <TObjArray.h>
35#include <TArrayI.h>
36#include <Riostream.h>
37
38using std::endl;
39/// \cond CLASSIMP
40ClassImp(AliMUONGeometryModuleTransformer)
41/// \endcond
42
43//
44// static methods
45//
46
47//______________________________________________________________________________
48const TString& AliMUONGeometryModuleTransformer::GetModuleNamePrefix()
49{
50 /// Geometry module name prefix
51 static const TString kModuleNamePrefix = "GM";
52 return kModuleNamePrefix;
53}
54
55//______________________________________________________________________________
56TString AliMUONGeometryModuleTransformer::GetModuleName(Int_t moduleId)
57{
58/// Return the module name for given moduleId
59
60 TString moduleName(GetModuleNamePrefix());
61 moduleName += moduleId;
62 return moduleName;
63}
64
65//
66// ctor, dtor
67//
68
69//______________________________________________________________________________
70AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
71 : TObject(),
72 fModuleId(moduleId),
73 fModuleName(GetModuleName(moduleId)),
74 fVolumePath(),
75 fTransformation(0),
76 fDetElements(0)
77{
78/// Standard constructor
79
80 // Chamber transformation
81 fTransformation = new TGeoHMatrix("");
82
83 // Det elements transformation stores
84 fDetElements = new AliMpExMap;
85}
86
87
88//______________________________________________________________________________
89AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(TRootIOCtor* /*ioCtor*/)
90 : TObject(),
91 fModuleId(0),
92 fModuleName(),
93 fVolumePath(),
94 fTransformation(0),
95 fDetElements(0)
96{
97/// Root IO constructor
98}
99
100
101//______________________________________________________________________________
102AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer()
103{
104/// Destructor
105
106 delete fTransformation;
107 delete fDetElements;
108}
109
110//
111// public methods
112//
113
114//______________________________________________________________________________
115void AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
116 Float_t xg, Float_t yg, Float_t zg,
117 Float_t& xl, Float_t& yl, Float_t& zl) const
118{
119/// Transform point from the global reference frame (ALIC)
120/// to the local reference frame of the detection element specified
121/// by detElemId.
122
123 // Get detection element
124 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
125 if (!detElement) return;
126
127 // Transform point
128 detElement->Global2Local(xg, yg, zg, xl, yl, zl);
129}
130
131//______________________________________________________________________________
132void AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
133 Double_t xg, Double_t yg, Double_t zg,
134 Double_t& xl, Double_t& yl, Double_t& zl) const
135{
136/// Transform point from the global reference frame (ALIC)
137/// to the local reference frame of the detection element specified
138/// by detElemId.
139
140 // Get detection element
141 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
142 if (!detElement) return;
143
144 // Transform point
145 detElement->Global2Local(xg, yg, zg, xl, yl, zl);
146}
147
148//______________________________________________________________________________
149void AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
150 Float_t xl, Float_t yl, Float_t zl,
151 Float_t& xg, Float_t& yg, Float_t& zg) const
152{
153/// Transform point from the local reference frame of the detection element
154/// specified by detElemId to the global reference frame (ALIC).
155
156 // Get detection element
157 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
158 if (!detElement) return;
159
160 // Transform point
161 detElement->Local2Global(xl, yl, zl, xg, yg, zg);
162}
163
164//______________________________________________________________________________
165void AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
166 Double_t xl, Double_t yl, Double_t zl,
167 Double_t& xg, Double_t& yg, Double_t& zg) const
168{
169/// Transform point from the local reference frame of the detection element
170/// specified by detElemId to the global reference frame (ALIC).
171
172 // Get detection element
173 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
174 if (!detElement) return;
175
176 // Transform point
177 detElement->Local2Global(xl, yl, zl, xg, yg, zg);
178}
179
180//______________________________________________________________________________
181void AliMUONGeometryModuleTransformer::SetTransformation(
182 const TGeoHMatrix& transform)
183{
184/// Set the module position wrt world.
185
186 *fTransformation = transform;
187}
188
189//______________________________________________________________________________
190TString AliMUONGeometryModuleTransformer::GetVolumeName() const
191{
192/// Extract volume name from the path
193
194 std::string volPath = fVolumePath.Data();
195 std::string::size_type first = volPath.rfind('/')+1;
196 std::string::size_type last = volPath.rfind('_');
197
198 return volPath.substr(first, last-first );
199}
200
201//______________________________________________________________________________
202TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
203{
204/// Extract mother volume name from the path
205
206 std::string volPath = fVolumePath.Data();
207 std::string::size_type first = volPath.rfind('/');
208 if ( first != std::string::npos )
209 volPath = volPath.substr(0, first);
210
211 std::string::size_type next = volPath.rfind('/')+1;
212 std::string::size_type last = volPath.rfind('_');
213
214 return volPath.substr(next, last-next );
215}
216
217//______________________________________________________________________________
218AliMUONGeometryDetElement*
219AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
220{
221/// Return the detection element specified by detElemId.
222/// Give error if detection element is not defined and warn is true.
223
224 // Get detection element
225 AliMUONGeometryDetElement* detElement
226 = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
227
228 if (!detElement) {
229 if (warn)
230 AliErrorStream()
231 << "Detection element " << detElemId
232 << " not found in module " << fModuleId << endl;
233 return 0;
234 }
235
236 return detElement;
237}