]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryModuleTransformer.cxx
- Revised comments and adapted them for Doxygen
[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 // -------------------------------------
19 // Class AliMUONGeometryModuleTransformer
20 // -------------------------------------
21 // Class for definition of the detector module transformations
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 /// \cond CLASSIMP
37 ClassImp(AliMUONGeometryModuleTransformer)
38 /// \endcond
39
40 //______________________________________________________________________________
41 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
42  : TObject(),
43    fModuleId(moduleId),
44    fVolumePath(),
45    fTransformation(0),
46    fDetElements(0)
47 {
48 /// Standard constructor
49
50   // Chamber transformation
51   fTransformation = new TGeoHMatrix("");
52
53   // Det elements transformation stores
54   fDetElements = new AliMUONGeometryStore(true);
55 }
56
57
58 //______________________________________________________________________________
59 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer()
60  : TObject(),
61    fModuleId(0),
62    fVolumePath(),
63    fTransformation(0),
64    fDetElements(0)
65 {
66 /// Default constructor
67 }
68
69
70 //______________________________________________________________________________
71 AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer() 
72 {
73 /// Destructor
74
75   delete fTransformation;
76   delete fDetElements;
77 }
78
79 //
80 // public methods
81 //
82
83 //______________________________________________________________________________
84 void  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 //______________________________________________________________________________
101 void  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 //______________________________________________________________________________
118 void  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 //______________________________________________________________________________
134 void  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 //______________________________________________________________________________
150 void  AliMUONGeometryModuleTransformer::SetTransformation(
151                                            const TGeoHMatrix& transform)
152 {
153 /// Set the module position wrt world.
154
155   *fTransformation = transform;
156 }  
157
158 //______________________________________________________________________________
159 TString 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 //______________________________________________________________________________
171 TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
172
173 /// Extract mother volume name from the path
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 //______________________________________________________________________________
186 AliMUONGeometryDetElement*
187 AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
188 {
189 /// Return the detection element specified by detElemId.
190 /// Give error if detection element is not defined and warn is true.
191
192    // Get detection element
193    AliMUONGeometryDetElement* detElement
194      = (AliMUONGeometryDetElement*) fDetElements->Get(detElemId, warn);
195
196    if (!detElement) {
197      if (warn)
198        AliErrorStream() 
199          << "Detection element " << detElemId
200          << " not found in module " << fModuleId << endl;
201      return 0;
202    }  
203
204    return detElement;
205 }