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