Adding name as attribute and GetDEName() method;
[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"
26#include "AliMUONGeometryStore.h"
27
28#include "AliLog.h"
29
4f8b0abb 30#include <TVirtualMC.h>
31#include <TGeoMatrix.h>
32#include <TObjArray.h>
33#include <TArrayI.h>
34#include <Riostream.h>
35
a9aad96e 36/// \cond CLASSIMP
4f8b0abb 37ClassImp(AliMUONGeometryModuleTransformer)
a9aad96e 38/// \endcond
4f8b0abb 39
40//______________________________________________________________________________
41AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
42 : TObject(),
43 fModuleId(moduleId),
ab488200 44 fVolumePath(),
4f8b0abb 45 fTransformation(0),
46 fDetElements(0)
47{
48/// Standard constructor
49
50 // Chamber transformation
ab488200 51 fTransformation = new TGeoHMatrix("");
4f8b0abb 52
53 // Det elements transformation stores
54 fDetElements = new AliMUONGeometryStore(true);
55}
56
57
58//______________________________________________________________________________
59AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer()
60 : TObject(),
61 fModuleId(0),
ab488200 62 fVolumePath(),
4f8b0abb 63 fTransformation(0),
64 fDetElements(0)
65{
66/// Default constructor
67}
68
69
70//______________________________________________________________________________
4f8b0abb 71AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer()
72{
73/// Destructor
74
75 delete fTransformation;
76 delete fDetElements;
77}
78
4f8b0abb 79//
80// public methods
81//
82
83//______________________________________________________________________________
84void AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
85 Float_t xg, Float_t yg, Float_t zg,
86 Float_t& xl, Float_t& yl, Float_t& zl) const
87{
88/// Transform point from the global reference frame (ALIC)
89/// to the local reference frame of the detection element specified
90/// by detElemId.
91
92 // Get detection element
93 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
94 if (!detElement) return;
95
96 // Transform point
97 detElement->Global2Local(xg, yg, zg, xl, yl, zl);
98}
99
100//______________________________________________________________________________
101void AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
102 Double_t xg, Double_t yg, Double_t zg,
103 Double_t& xl, Double_t& yl, Double_t& zl) const
104{
105/// Transform point from the global reference frame (ALIC)
106/// to the local reference frame of the detection element specified
107/// by detElemId.
108
109 // Get detection element
110 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
111 if (!detElement) return;
112
113 // Transform point
114 detElement->Global2Local(xg, yg, zg, xl, yl, zl);
115}
116
117//______________________________________________________________________________
118void AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
119 Float_t xl, Float_t yl, Float_t zl,
120 Float_t& xg, Float_t& yg, Float_t& zg) const
121{
122/// Transform point from the local reference frame of the detection element
123/// specified by detElemId to the global reference frame (ALIC).
124
125 // Get detection element
126 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
127 if (!detElement) return;
128
129 // Transform point
130 detElement->Local2Global(xl, yl, zl, xg, yg, zg);
131}
132
133//______________________________________________________________________________
134void AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
135 Double_t xl, Double_t yl, Double_t zl,
136 Double_t& xg, Double_t& yg, Double_t& zg) const
137{
138/// Transform point from the local reference frame of the detection element
139/// specified by detElemId to the global reference frame (ALIC).
140
141 // Get detection element
142 AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
143 if (!detElement) return;
144
145 // Transform point
146 detElement->Local2Global(xl, yl, zl, xg, yg, zg);
147}
148
149//______________________________________________________________________________
150void AliMUONGeometryModuleTransformer::SetTransformation(
ab488200 151 const TGeoHMatrix& transform)
4f8b0abb 152{
153/// Set the module position wrt world.
154
155 *fTransformation = transform;
156}
157
158//______________________________________________________________________________
ab488200 159TString AliMUONGeometryModuleTransformer::GetVolumeName() const
160{
161/// Extract volume name from the path
162
163 std::string volPath = fVolumePath.Data();
164 std::string::size_type first = volPath.rfind('/')+1;
165 std::string::size_type last = volPath.rfind('_');
166
167 return volPath.substr(first, last-first );
168}
169
170//______________________________________________________________________________
171TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
172{
a9aad96e 173/// Extract mother volume name from the path
ab488200 174
175 std::string volPath = fVolumePath.Data();
176 std::string::size_type first = volPath.rfind('/');
177 volPath = volPath.substr(0, first);
178
179 std::string::size_type next = volPath.rfind('/')+1;
180 std::string::size_type last = volPath.rfind('_');
181
182 return volPath.substr(next, last-next );
183}
184
185//______________________________________________________________________________
4f8b0abb 186AliMUONGeometryDetElement*
b75f649b 187AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
4f8b0abb 188{
189/// Return the detection element specified by detElemId.
a9aad96e 190/// Give error if detection element is not defined and warn is true.
4f8b0abb 191
192 // Get detection element
193 AliMUONGeometryDetElement* detElement
b75f649b 194 = (AliMUONGeometryDetElement*) fDetElements->Get(detElemId, warn);
4f8b0abb 195
196 if (!detElement) {
b75f649b 197 if (warn)
198 AliErrorStream()
199 << "Detection element " << detElemId
200 << " not found in module " << fModuleId << endl;
4f8b0abb 201 return 0;
202 }
203
204 return detElement;
205}