- Added static mathod GetDEName(detElemId)
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryModuleTransformer.cxx
CommitLineData
4f8b0abb 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//
f7006443 18// -------------------------------------
4f8b0abb 19// Class AliMUONGeometryModuleTransformer
20// -------------------------------------
21// Class for definition of the detector module transformations
4f8b0abb 22// Author: Ivana Hrivnacova, IPN Orsay
23
ab488200 24#include "AliMUONGeometryModuleTransformer.h"
25#include "AliMUONGeometryDetElement.h"
fa66b479 26
27#include "AliMpExMap.h"
ab488200 28
29#include "AliLog.h"
30
4f8b0abb 31#include <TVirtualMC.h>
32#include <TGeoMatrix.h>
33#include <TObjArray.h>
34#include <TArrayI.h>
35#include <Riostream.h>
36
a9aad96e 37/// \cond CLASSIMP
4f8b0abb 38ClassImp(AliMUONGeometryModuleTransformer)
a9aad96e 39/// \endcond
4f8b0abb 40
eb288296 41const TString AliMUONGeometryModuleTransformer::fgkModuleNamePrefix = "GM";
42
4f8b0abb 43//______________________________________________________________________________
44AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
45 : TObject(),
46 fModuleId(moduleId),
eb288296 47 fModuleName(),
ab488200 48 fVolumePath(),
4f8b0abb 49 fTransformation(0),
50 fDetElements(0)
51{
52/// Standard constructor
53
54 // Chamber transformation
ab488200 55 fTransformation = new TGeoHMatrix("");
4f8b0abb 56
57 // Det elements transformation stores
fa66b479 58 fDetElements = new AliMpExMap(true);
eb288296 59
60 // Compose module name
61 fModuleName = fgkModuleNamePrefix;
62 fModuleName += moduleId;
4f8b0abb 63}
64
65
66//______________________________________________________________________________
67AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer()
68 : TObject(),
69 fModuleId(0),
eb288296 70 fModuleName(),
ab488200 71 fVolumePath(),
4f8b0abb 72 fTransformation(0),
73 fDetElements(0)
74{
75/// Default constructor
76}
77
78
79//______________________________________________________________________________
4f8b0abb 80AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer()
81{
82/// Destructor
83
84 delete fTransformation;
85 delete fDetElements;
86}
87
4f8b0abb 88//
89// public methods
90//
91
92//______________________________________________________________________________
93void 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//______________________________________________________________________________
110void 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//______________________________________________________________________________
127void 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//______________________________________________________________________________
143void 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//______________________________________________________________________________
159void AliMUONGeometryModuleTransformer::SetTransformation(
ab488200 160 const TGeoHMatrix& transform)
4f8b0abb 161{
162/// Set the module position wrt world.
163
164 *fTransformation = transform;
165}
166
167//______________________________________________________________________________
ab488200 168TString 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//______________________________________________________________________________
180TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
181{
a9aad96e 182/// Extract mother volume name from the path
ab488200 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//______________________________________________________________________________
4f8b0abb 195AliMUONGeometryDetElement*
b75f649b 196AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
4f8b0abb 197{
198/// Return the detection element specified by detElemId.
a9aad96e 199/// Give error if detection element is not defined and warn is true.
4f8b0abb 200
201 // Get detection element
202 AliMUONGeometryDetElement* detElement
fa66b479 203 = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
4f8b0abb 204
205 if (!detElement) {
b75f649b 206 if (warn)
207 AliErrorStream()
208 << "Detection element " << detElemId
209 << " not found in module " << fModuleId << endl;
4f8b0abb 210 return 0;
211 }
212
213 return detElement;
214}