]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryModuleTransformer.cxx
In AliMUONTriggerTrack: fixing memory leak
[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
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 /// \cond CLASSIMP
39 ClassImp(AliMUONGeometryModuleTransformer)
40 /// \endcond
41
42 //
43 // static methods
44 //
45
46 //______________________________________________________________________________
47 const TString& AliMUONGeometryModuleTransformer::GetModuleNamePrefix()
48 {
49   /// Geometry module name prefix
50   static const TString kModuleNamePrefix = "GM";
51   return kModuleNamePrefix;
52 }  
53
54 //______________________________________________________________________________
55 TString AliMUONGeometryModuleTransformer::GetModuleName(Int_t moduleId)
56 {
57 /// Return the module name for given moduleId
58
59   TString moduleName(GetModuleNamePrefix());
60   moduleName += moduleId;
61   return moduleName;
62 }   
63
64 //
65 // ctor, dtor
66 //
67
68 //______________________________________________________________________________
69 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
70  : TObject(),
71    fModuleId(moduleId),
72    fModuleName(GetModuleName(moduleId)),
73    fVolumePath(),
74    fTransformation(0),
75    fDetElements(0)
76 {
77 /// Standard constructor
78
79   // Chamber transformation
80   fTransformation = new TGeoHMatrix("");
81
82   // Det elements transformation stores
83   fDetElements = new AliMpExMap;
84 }
85
86
87 //______________________________________________________________________________
88 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(TRootIOCtor* /*ioCtor*/)
89  : TObject(),
90    fModuleId(0),
91    fModuleName(),
92    fVolumePath(),
93    fTransformation(0),
94    fDetElements(0)
95 {
96 /// Root IO constructor
97 }
98
99
100 //______________________________________________________________________________
101 AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer() 
102 {
103 /// Destructor
104
105   delete fTransformation;
106   delete fDetElements;
107 }
108
109 //
110 // public methods
111 //
112
113 //______________________________________________________________________________
114 void  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 //______________________________________________________________________________
131 void  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 //______________________________________________________________________________
148 void  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 //______________________________________________________________________________
164 void  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 //______________________________________________________________________________
180 void  AliMUONGeometryModuleTransformer::SetTransformation(
181                                            const TGeoHMatrix& transform)
182 {
183 /// Set the module position wrt world.
184
185   *fTransformation = transform;
186 }  
187
188 //______________________________________________________________________________
189 TString 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 //______________________________________________________________________________
201 TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
202
203 /// Extract mother volume name from the path
204   
205   std::string volPath = fVolumePath.Data();
206   std::string::size_type first = volPath.rfind('/');
207   if ( first != std::string::npos )
208     volPath = volPath.substr(0, first);
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 //______________________________________________________________________________
217 AliMUONGeometryDetElement*
218 AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
219 {
220 /// Return the detection element specified by detElemId.
221 /// Give error if detection element is not defined and warn is true.
222
223    // Get detection element
224    AliMUONGeometryDetElement* detElement
225      = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
226
227    if (!detElement) {
228      if (warn)
229        AliErrorStream() 
230          << "Detection element " << detElemId
231          << " not found in module " << fModuleId << endl;
232      return 0;
233    }  
234
235    return detElement;
236 }