]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryTransformStore.cxx
d42503861e3b7d8ef09d5efc6d6896263601e750
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryTransformStore.cxx
1 // $Id$
2 //
3 // Class AliMUONGeometryTransformStore
4 // ------------------------------------ 
5 // The class provides the array of transformations of the detection elements
6 // from a defined reference frame to the detection element frame.
7 // (See more in the header file.) 
8 //
9 // Author: Ivana Hrivnacova, IPN Orsay
10
11 #include <Riostream.h>
12 #include <TGeoMatrix.h>
13 #include <TObjString.h>
14
15 #include "AliMUONGeometryTransformStore.h"
16
17 ClassImp(AliMUONGeometryTransformStore)
18
19 const Int_t AliMUONGeometryTransformStore::fgkHemisphere = 50; 
20
21 //______________________________________________________________________________
22 AliMUONGeometryTransformStore::AliMUONGeometryTransformStore(
23                                   Int_t firstDetElemId, Int_t  nofDetElems,
24                                   AliMUONGeometrySVMap* svMap)
25  : TObject(),
26    fFirstDetElemId(firstDetElemId),
27    fNofDetElems(nofDetElems),
28    fDETransforms(100),
29    fSVMap(svMap)
30
31 // Standard constructor
32   
33   fDETransforms.SetOwner(true);
34   for (Int_t i=0; i<nofDetElems; i++) fDETransforms[i] = 0;
35 }
36
37 //______________________________________________________________________________
38 AliMUONGeometryTransformStore::AliMUONGeometryTransformStore()
39  : TObject(),
40    fFirstDetElemId(0),
41    fNofDetElems(0),
42    fDETransforms(),
43    fSVMap(0)
44 {
45 // Default constructor
46 }
47
48 //______________________________________________________________________________
49 AliMUONGeometryTransformStore::AliMUONGeometryTransformStore(
50                                    const AliMUONGeometryTransformStore& rhs)
51   : TObject(rhs)
52 {
53   Fatal("Copy constructor", 
54         "Copy constructor is not implemented.");
55 }
56
57 //______________________________________________________________________________
58 AliMUONGeometryTransformStore::~AliMUONGeometryTransformStore() {
59 //
60   fDETransforms.Delete();
61 }
62
63 //______________________________________________________________________________
64 AliMUONGeometryTransformStore& 
65 AliMUONGeometryTransformStore::operator = (const AliMUONGeometryTransformStore& rhs) 
66 {
67   // check assignement to self
68   if (this == &rhs) return *this;
69
70   Fatal("operator=", 
71         "Assignment operator is not implemented.");
72     
73   return *this;  
74 }
75
76 //
77 // private methods
78 //
79
80 //______________________________________________________________________________
81 Int_t AliMUONGeometryTransformStore::GetDetElementIndex(Int_t detElemId) const
82 {
83 // Returns the index of detector element specified by detElemId
84 // ---
85
86   Int_t index = detElemId - fFirstDetElemId;
87   if (index >= fgkHemisphere) 
88     index -= fgkHemisphere - fNofDetElems/2;
89
90   return index;
91 }  
92
93 //______________________________________________________________________________
94 Int_t AliMUONGeometryTransformStore::GetDetElementId(Int_t detElemIndex) const
95 {
96 // Returns the ID of detector element specified by index
97 // ---
98
99   Int_t detElemId = detElemIndex;
100   
101   if (detElemIndex >=  fNofDetElems/2) 
102     detElemId += fgkHemisphere - fNofDetElems/2; 
103
104   detElemId += fFirstDetElemId;
105
106   return detElemId;
107 }  
108
109
110 //
111 // public methods
112 //
113
114 //______________________________________________________________________________
115 void AliMUONGeometryTransformStore::Add(Int_t detElemId,
116                                         const TString& alignedVolume, 
117                                         const TGeoCombiTrans& transform)
118 {
119 // Add transformation specified by alignedVolume in the array
120 // if this alignedVolume is not yet present. 
121 // ---
122  
123   TGeoCombiTrans* newTransform = new TGeoCombiTrans(transform);
124   newTransform->SetName(alignedVolume);
125   
126   //cout << ".. adding " << detElemId 
127   //     << " index: " << GetDetElementIndex(detElemId) << endl;
128
129   // Add to the map  
130   if ( !Get(detElemId)) {
131   
132     newTransform->SetUniqueID(detElemId);
133       // Set detector element id as unique id
134  
135     fDETransforms.AddAt(newTransform, GetDetElementIndex(detElemId));
136   } 
137   else 
138     Warning("Add", "The aligned volume %s is already present", 
139             alignedVolume.Data());  
140 }                     
141     
142 //______________________________________________________________________________
143 void  AliMUONGeometryTransformStore::Print(Option_t* /*option*/) const
144 {
145 // Prints the detector elements transformations
146 // ---
147
148   for (Int_t i=0; i<fDETransforms.GetEntriesFast(); i++) {
149     
150     cout << "DetElemId: " << GetDetElementId(i);
151
152     TGeoCombiTrans* matrix = (TGeoCombiTrans*)fDETransforms.At(i);
153     cout << "  name: " << matrix->GetName() << endl;
154
155     const double* translation = matrix->GetTranslation();
156     cout << "   translation: "
157 #if defined (__DECCXX)
158          << translation[0] << ", " 
159          << translation[1] << ", "
160          << translation[2] << endl;
161 #else
162          << std::fixed
163          << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
164          << std::setw(7) << std::setprecision(4) << translation[1] << ", "
165          << std::setw(7) << std::setprecision(4) << translation[2] << endl;
166 #endif
167          
168     const double* rotation = matrix->GetRotationMatrix();
169     cout << "   rotation matrix:  "
170 #if defined (__DECCXX)
171          << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
172          << "                     "         
173          << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl       
174          << "                     "         
175          << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
176 #else
177          << std::fixed
178          << std::setw(7) << std::setprecision(4) 
179          << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
180          << "                     "         
181          << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl       
182          << "                     "         
183          << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
184 #endif
185   }
186 }     
187
188 //______________________________________________________________________________
189 const TGeoCombiTrans* 
190 AliMUONGeometryTransformStore::Get(Int_t detElemId) const
191 {
192 // Returns transformation for the specified detector element Id
193 // ---
194
195   Int_t index = GetDetElementIndex(detElemId);
196   
197   if ( index >= 0 && index < fNofDetElems )
198     return (const TGeoCombiTrans*)fDETransforms.At(index);
199   else {
200     Warning("Get","Index %d out of limits", index);
201     return 0;  
202   }  
203 }  
204
205 //______________________________________________________________________________
206 const TGeoCombiTrans* 
207 AliMUONGeometryTransformStore::FindBySensitiveVolume(const TString& sensVolume) const
208 {
209 // Finds TGeoCombiTrans for the detector element Id specified by aligned volume 
210 // ---
211
212   Int_t detElemId = fSVMap->GetDetElemId(sensVolume);
213
214   if (!detElemId) return 0; 
215         // The specified sensitive volume is not in the map   
216   
217   return Get(detElemId);
218 }  
219