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