]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryModuleTransformer.cxx
delete the AliSurvey objs after use
[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 const TString AliMUONGeometryModuleTransformer::fgkModuleNamePrefix = "GM";
43
44 //______________________________________________________________________________
45 TString AliMUONGeometryModuleTransformer::GetModuleName(Int_t moduleId)
46 {
47 /// Return the module name for given moduleId
48
49   TString moduleName(fgkModuleNamePrefix);
50   moduleName += moduleId;
51   return moduleName;
52 }   
53
54 //______________________________________________________________________________
55 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(Int_t moduleId)
56  : TObject(),
57    fModuleId(moduleId),
58    fModuleName(GetModuleName(moduleId)),
59    fVolumePath(),
60    fTransformation(0),
61    fDetElements(0)
62 {
63 /// Standard constructor
64
65   // Chamber transformation
66   fTransformation = new TGeoHMatrix("");
67
68   // Det elements transformation stores
69   fDetElements = new AliMpExMap(true);
70 }
71
72
73 //______________________________________________________________________________
74 AliMUONGeometryModuleTransformer::AliMUONGeometryModuleTransformer(TRootIOCtor* /*ioCtor*/)
75  : TObject(),
76    fModuleId(0),
77    fModuleName(),
78    fVolumePath(),
79    fTransformation(0),
80    fDetElements(0)
81 {
82 /// Root IO constructor
83 }
84
85
86 //______________________________________________________________________________
87 AliMUONGeometryModuleTransformer::~AliMUONGeometryModuleTransformer() 
88 {
89 /// Destructor
90
91   delete fTransformation;
92   delete fDetElements;
93 }
94
95 //
96 // public methods
97 //
98
99 //______________________________________________________________________________
100 void  AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
101                   Float_t xg, Float_t yg, Float_t zg, 
102                   Float_t& xl, Float_t& yl, Float_t& zl) const
103 {
104 /// Transform point from the global reference frame (ALIC)
105 /// to the local reference frame of the detection element specified
106 /// by detElemId.
107
108   // Get detection element
109   AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
110   if (!detElement) return;
111    
112   // Transform point
113   detElement->Global2Local(xg, yg, zg, xl, yl, zl);
114 }
115                                   
116 //______________________________________________________________________________
117 void  AliMUONGeometryModuleTransformer::Global2Local(Int_t detElemId,
118                   Double_t xg, Double_t yg, Double_t zg, 
119                   Double_t& xl, Double_t& yl, Double_t& zl) const
120 {
121 /// Transform point from the global reference frame (ALIC)
122 /// to the local reference frame of the detection element specified
123 /// by detElemId.
124
125    // Get detection element
126    AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
127    if (!detElement) return;
128    
129    // Transform point
130    detElement->Global2Local(xg, yg, zg, xl, yl, zl);
131 }
132                                   
133 //______________________________________________________________________________
134 void  AliMUONGeometryModuleTransformer::Local2Global(Int_t detElemId,
135                  Float_t xl, Float_t yl, Float_t zl, 
136                  Float_t& xg, Float_t& yg, Float_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::Local2Global(Int_t detElemId,
151                  Double_t xl, Double_t yl, Double_t zl, 
152                  Double_t& xg, Double_t& yg, Double_t& zg) const
153 {
154 /// Transform point from the local reference frame of the detection element 
155 /// specified by detElemId to the global reference frame (ALIC).
156
157    // Get detection element
158    AliMUONGeometryDetElement* detElement = GetDetElement(detElemId);
159    if (!detElement) return;
160    
161    // Transform point
162    detElement->Local2Global(xl, yl, zl, xg, yg, zg); 
163 }
164
165 //______________________________________________________________________________
166 void  AliMUONGeometryModuleTransformer::SetTransformation(
167                                            const TGeoHMatrix& transform)
168 {
169 /// Set the module position wrt world.
170
171   *fTransformation = transform;
172 }  
173
174 //______________________________________________________________________________
175 TString AliMUONGeometryModuleTransformer::GetVolumeName() const
176
177 /// Extract volume name from the path
178   
179   std::string volPath = fVolumePath.Data();
180   std::string::size_type first = volPath.rfind('/')+1;
181   std::string::size_type last = volPath.rfind('_');
182   
183   return volPath.substr(first, last-first );
184 }
185
186 //______________________________________________________________________________
187 TString AliMUONGeometryModuleTransformer::GetMotherVolumeName() const
188
189 /// Extract mother volume name from the path
190   
191   std::string volPath = fVolumePath.Data();
192   std::string::size_type first = volPath.rfind('/');
193   volPath = volPath.substr(0, first);
194
195   std::string::size_type next = volPath.rfind('/')+1;
196   std::string::size_type last = volPath.rfind('_');
197   
198   return volPath.substr(next, last-next );
199 }
200
201 //______________________________________________________________________________
202 AliMUONGeometryDetElement*
203 AliMUONGeometryModuleTransformer::GetDetElement(Int_t detElemId, Bool_t warn) const
204 {
205 /// Return the detection element specified by detElemId.
206 /// Give error if detection element is not defined and warn is true.
207
208    // Get detection element
209    AliMUONGeometryDetElement* detElement
210      = (AliMUONGeometryDetElement*) fDetElements->GetValue(detElemId);
211
212    if (!detElement) {
213      if (warn)
214        AliErrorStream() 
215          << "Detection element " << detElemId
216          << " not found in module " << fModuleId << endl;
217      return 0;
218    }  
219
220    return detElement;
221 }