New parametrization of the geometry and new geometry interface (Working week effort)
[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          << std::fixed
158          << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
159          << std::setw(7) << std::setprecision(4) << translation[1] << ", "
160          << std::setw(7) << std::setprecision(4) << translation[2] << endl;
161          
162     const double* rotation = matrix->GetRotationMatrix();
163     cout << "   rotation matrix:  "
164          << std::fixed
165          << std::setw(7) << std::setprecision(4) 
166          << rotation[0] << ", " << rotation[1] << ", " << rotation[2] << endl
167          << "                     "         
168          << rotation[3] << ", " << rotation[4] << ", " << rotation[5] << endl       
169          << "                     "         
170          << rotation[6] << ", " << rotation[7] << ", " << rotation[8] << endl;
171
172   }
173 }     
174
175 //______________________________________________________________________________
176 const TGeoCombiTrans* 
177 AliMUONGeometryTransformStore::Get(Int_t detElemId) const
178 {
179 // Returns transformation for the specified detector element Id
180 // ---
181
182   Int_t index = GetDetElementIndex(detElemId);
183   
184   if ( index >= 0 && index < fNofDetElems )
185     return (const TGeoCombiTrans*)fDETransforms.At(index);
186   else {
187     Warning("Get","Index %d out of limits", index);
188     return 0;  
189   }  
190 }  
191
192 //______________________________________________________________________________
193 const TGeoCombiTrans* 
194 AliMUONGeometryTransformStore::FindBySensitiveVolume(const TString& sensVolume) const
195 {
196 // Finds TGeoCombiTrans for the detector element Id specified by aligned volume 
197 // ---
198
199   Int_t detElemId = fSVMap->GetDetElemId(sensVolume);
200
201   if (!detElemId) return 0; 
202         // The specified sensitive volume is not in the map   
203   
204   return Get(detElemId);
205 }  
206