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