Line data Source code
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 :
38 : using std::endl;
39 : /// \cond CLASSIMP
40 18 : ClassImp(AliMUONGeometryModuleTransformer)
41 : /// \endcond
42 :
43 : //
44 : // static methods
45 : //
46 :
47 : //______________________________________________________________________________
48 : const TString& AliMUONGeometryModuleTransformer::GetModuleNamePrefix()
49 : {
50 : /// Geometry module name prefix
51 2113 : static const TString kModuleNamePrefix = "GM";
52 1052 : return kModuleNamePrefix;
53 0 : }
54 :
55 : //______________________________________________________________________________
56 : TString AliMUONGeometryModuleTransformer::GetModuleName(Int_t moduleId)
57 : {
58 : /// Return the module name for given moduleId
59 :
60 2104 : TString moduleName(GetModuleNamePrefix());
61 1052 : moduleName += moduleId;
62 : return moduleName;
63 2104 : }
64 :
65 : //
66 : // ctor, dtor
67 : //
68 :
69 : //______________________________________________________________________________
70 : AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
71 60 : : TObject(),
72 60 : fModuleId(moduleId),
73 60 : fModuleName(GetModuleName(moduleId)),
74 60 : fVolumePath(),
75 60 : fTransformation(0),
76 60 : fDetElements(0)
77 300 : {
78 : /// Standard constructor
79 :
80 : // Chamber transformation
81 180 : fTransformation = new TGeoHMatrix("");
82 :
83 : // Det elements transformation stores
84 180 : fDetElements = new AliMpExMap;
85 120 : }
86 :
87 :
88 : //______________________________________________________________________________
89 : AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(TRootIOCtor* /*ioCtor*/)
90 240 : : TObject(),
91 240 : fModuleId(0),
92 240 : fModuleName(),
93 240 : fVolumePath(),
94 240 : fTransformation(0),
95 240 : fDetElements(0)
96 1200 : {
97 : /// Root IO constructor
98 480 : }
99 :
100 :
101 : //______________________________________________________________________________
102 : AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer()
103 1800 : {
104 : /// Destructor
105 :
106 600 : delete fTransformation;
107 600 : delete fDetElements;
108 900 : }
109 :
110 : //
111 : // public methods
112 : //
113 :
114 : //______________________________________________________________________________
115 : void 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 0 : AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
125 0 : if (!detElement) return;
126 :
127 : // Transform point
128 0 : detElement->Global2Local(xg, yg, zg, xl, yl, zl);
129 0 : }
130 :
131 : //______________________________________________________________________________
132 : void 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 4940 : AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
142 2470 : if (!detElement) return;
143 :
144 : // Transform point
145 2470 : detElement->Global2Local(xg, yg, zg, xl, yl, zl);
146 4940 : }
147 :
148 : //______________________________________________________________________________
149 : void 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 0 : AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
158 0 : if (!detElement) return;
159 :
160 : // Transform point
161 0 : detElement->Local2Global(xl, yl, zl, xg, yg, zg);
162 0 : }
163 :
164 : //______________________________________________________________________________
165 : void 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 60554 : AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
174 30277 : if (!detElement) return;
175 :
176 : // Transform point
177 30277 : detElement->Local2Global(xl, yl, zl, xg, yg, zg);
178 60554 : }
179 :
180 : //______________________________________________________________________________
181 : void AliMUONGeometryModuleTransformer::SetTransformation(
182 : const TGeoHMatrix& transform)
183 : {
184 : /// Set the module position wrt world.
185 :
186 160 : *fTransformation = transform;
187 80 : }
188 :
189 : //______________________________________________________________________________
190 : TString AliMUONGeometryModuleTransformer::GetVolumeName() const
191 : {
192 : /// Extract volume name from the path
193 :
194 40 : std::string volPath = fVolumePath.Data();
195 20 : std::string::size_type first = volPath.rfind('/')+1;
196 20 : std::string::size_type last = volPath.rfind('_');
197 :
198 60 : return volPath.substr(first, last-first );
199 20 : }
200 :
201 : //______________________________________________________________________________
202 : TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
203 : {
204 : /// Extract mother volume name from the path
205 :
206 40 : std::string volPath = fVolumePath.Data();
207 20 : std::string::size_type first = volPath.rfind('/');
208 20 : if ( first != std::string::npos )
209 40 : volPath = volPath.substr(0, first);
210 :
211 20 : std::string::size_type next = volPath.rfind('/')+1;
212 20 : std::string::size_type last = volPath.rfind('_');
213 :
214 60 : return volPath.substr(next, last-next );
215 20 : }
216 :
217 : //______________________________________________________________________________
218 : AliMUONGeometryDetElement*
219 : AliMUONGeometryModuleTransformer::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 33948 : = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
227 :
228 33948 : if (!detElement) {
229 0 : if (warn)
230 0 : AliErrorStream()
231 0 : << "Detection element " << detElemId
232 0 : << " not found in module " << fModuleId << endl;
233 0 : return 0;
234 : }
235 :
236 33948 : return detElement;
237 33948 : }
|