]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometrySVMap.cxx
New parametrization of the geometry and new geometry interface (Working week effort)
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometrySVMap.cxx
1 // $Id$
2 //
3 // Class AliMUONGeometrySVMap
4 // ------------------------------------ 
5 // As the detection element frame is different from the
6 // frame of the sensitive volume(s) defined in Geant,
7 // the sensitive volumes have to be mapped to the detection 
8 // elements. In the map, fSVMap, the sensitive voolumes are specified
9 // by the full path in the volume hierarchy, defined as:
10 //  /volname.copyNo/volName.copyNo1/...
11 //
12 // The array of global positions of sensitive volumes fSVPositions
13 // is included to make easier the verification of the assignements 
14 // in the fSVMap.
15 //
16 // Author: Ivana Hrivnacova, IPN Orsay
17
18 #include <Riostream.h>
19 #include <TGeoMatrix.h>
20 #include <TObjString.h>
21
22 #include "AliMUONGeometrySVMap.h"
23
24 ClassImp(AliMUONGeometrySVMap)
25
26 //
27 // Class AliMUONStringIntMap
28 //
29
30 //______________________________________________________________________________
31 AliMUONStringIntMap::AliMUONStringIntMap()
32  : TObject(),
33    fNofItems(0),
34    fFirstArray(100),
35    fSecondArray(100)
36 {
37 // Standard constructor
38
39   fFirstArray.SetOwner(true);
40 }
41
42 //______________________________________________________________________________
43 AliMUONStringIntMap::AliMUONStringIntMap(const AliMUONStringIntMap& rhs)
44   : TObject(rhs)
45 {
46   Fatal("Copy constructor", 
47         "Copy constructor is not implemented.");
48 }
49
50 //______________________________________________________________________________
51 AliMUONStringIntMap& 
52 AliMUONStringIntMap::operator = (const AliMUONStringIntMap& rhs) 
53 {
54   // check assignement to self
55   if (this == &rhs) return *this;
56
57   Fatal("operator=", 
58         "Assignment operator is not implemented.");
59     
60   return *this;  
61 }
62
63 //______________________________________________________________________________
64 AliMUONStringIntMap::~AliMUONStringIntMap()
65 {
66 // Destructor
67
68   fFirstArray.Delete();
69 }
70
71
72 //______________________________________________________________________________
73 Bool_t  AliMUONStringIntMap::Add(const TString& first, Int_t second)
74 {
75 // Add map element if first not yet present
76 // ---
77
78   Int_t second2 = Get(first);
79   if ( second2 > 0 ) {
80     Error("Add", "%s is already present in the map", first.Data());
81     return false;
82   }
83   
84   // Resize TArrayI if needed
85   if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
86   
87   fFirstArray.Add(new TObjString(first)); 
88   fSecondArray.AddAt(second, fNofItems);
89   fNofItems++;
90    
91   return true;
92 }  
93
94 //______________________________________________________________________________
95 Int_t  AliMUONStringIntMap::Get(const TString& first) const
96 {
97 // Find the element with specified key (first)
98 // ---
99   
100   for (Int_t i=0; i<fNofItems; i++) {
101     if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
102       return fSecondArray.At(i);
103   }
104   
105   return 0;
106 }      
107
108 //______________________________________________________________________________
109 Int_t  AliMUONStringIntMap::GetNofItems() const
110 {
111 // Returns the number of elements
112 // ---
113
114   return fNofItems;
115 }  
116
117 //______________________________________________________________________________
118 void  AliMUONStringIntMap::Clear()
119 {
120 // Deletes the elements
121 // ---
122
123   cout << "######### clearing map " << endl;
124
125   fNofItems = 0;
126   fFirstArray.Delete();
127   fSecondArray.Reset();
128
129   cout << "######### clearing map done " << endl;
130 }  
131     
132 //______________________________________________________________________________
133 void AliMUONStringIntMap::Print(const char* /*option*/) const
134 {
135 // Prints the map elements
136
137   for (Int_t i=0; i<fNofItems; i++) {
138     cout << setw(4)
139          << i << "  "
140          << ((TObjString*)fFirstArray.At(i))->GetString()
141          << "  "
142          << setw(5)
143          << fSecondArray.At(i)
144          << endl;
145   }
146 }        
147
148 //______________________________________________________________________________
149 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
150 {
151 // Prints the map elements
152
153   for (Int_t i=0; i<fNofItems; i++) {
154     out  << key << "  "
155          << ((TObjString*)fFirstArray.At(i))->GetString()
156          << "  "
157          << setw(5)
158          << fSecondArray.At(i)
159          << endl;
160   }
161 }        
162
163
164 //
165 // Class AliMUONGeometrySVMap
166 //
167
168 //______________________________________________________________________________
169 AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize)
170  : TObject(),
171    fSVMap(),
172    fSVPositions(initSize)
173
174 // Standard constructor
175   
176   fSVPositions.SetOwner(true);
177 }
178
179 //______________________________________________________________________________
180 AliMUONGeometrySVMap::AliMUONGeometrySVMap()
181  : TObject(),
182    fSVMap(),
183    fSVPositions()
184 {
185 // Default constructor
186 }
187
188 //______________________________________________________________________________
189 AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs)
190   : TObject(rhs)
191 {
192   Fatal("Copy constructor", 
193         "Copy constructor is not implemented.");
194 }
195
196 //______________________________________________________________________________
197 AliMUONGeometrySVMap::~AliMUONGeometrySVMap() {
198 //
199   fSVPositions.Delete();
200 }
201
202 //______________________________________________________________________________
203 AliMUONGeometrySVMap& 
204 AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs) 
205 {
206   // check assignement to self
207   if (this == &rhs) return *this;
208
209   Fatal("operator=", 
210         "Assignment operator is not implemented.");
211     
212   return *this;  
213 }
214
215 //
216 // private methods
217 //
218
219 //______________________________________________________________________________
220 const TGeoCombiTrans* 
221 AliMUONGeometrySVMap::FindByName(const TString& name) const
222 {
223 // Finds TGeoCombiTrans in the array of positions by name 
224 // ---
225
226   for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) { 
227      TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i);
228      if ( transform && TString(transform->GetTitle()) == name )
229        return transform;
230   }     
231        
232   return 0;
233 }  
234
235
236 //
237 // public methods
238 //
239
240 //______________________________________________________________________________
241 void AliMUONGeometrySVMap::Add(const TString& volumePath, 
242                                Int_t detElemId)
243 {
244 // Add the specified sensitive volume path and the detElemId 
245 // to the map
246 // ---
247  
248   fSVMap.Add(volumePath, detElemId);
249 }                         
250     
251 //______________________________________________________________________________
252 void AliMUONGeometrySVMap::AddPosition(const TString& volumePath, 
253                               const TGeoTranslation& globalPosition)
254 {
255 // Add global position for the sensitive volume specified by volumePath  
256 // in the array of transformations if this volumePath is not yet present. 
257 // ---
258  
259   TGeoTranslation* newTransform = new TGeoTranslation(globalPosition);
260   Int_t detElemId = fSVMap.Get(volumePath);
261
262   TString detElemIdString("");
263   detElemIdString += detElemId;
264
265   newTransform->SetName(detElemIdString);
266   newTransform->SetTitle(volumePath);
267   
268   // cout << ".. adding " << volumePath << "  " << detElemId << endl;
269
270   // Add to the map  
271   if ( !FindByName(volumePath )) {
272   
273     newTransform->SetUniqueID(detElemId);
274       // Set detector element id as unique id
275  
276     fSVPositions.Add(newTransform);
277   } 
278 }                     
279     
280 //______________________________________________________________________________
281 void AliMUONGeometrySVMap::Clear()
282 {
283 // Clears the sensitive volumes map
284
285   fSVMap.Clear();
286 }  
287
288 //______________________________________________________________________________
289 void AliMUONGeometrySVMap::ClearPositions()
290 {
291 // Clears the array of transformations
292
293   fSVPositions.Delete();
294 }  
295
296 //______________________________________________________________________________
297 void AliMUONGeometrySVMap::SortPositions()
298 {
299 // Sort the array of positions by names.
300 // ---
301
302   fSVPositions.Sort(fSVPositions.GetEntriesFast());
303 }
304   
305 //______________________________________________________________________________
306 void  AliMUONGeometrySVMap::Print(const char* option) const
307 {    
308 // Prints the map of sensitive volumes and detector elements 
309 // ---
310
311   fSVMap.Print(option);
312 }  
313
314 //______________________________________________________________________________
315 void  AliMUONGeometrySVMap::PrintPositions() const
316 {
317 // Prints the sensitive volumes global positions
318 // ---
319
320   for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
321     
322     TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i);
323
324     cout << "DetElemId: " << matrix->GetUniqueID();
325     cout << "  name: " << matrix->GetTitle() << endl;
326
327     const double* translation = matrix->GetTranslation();
328     cout << "   translation: "
329          << std::fixed
330          << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
331          << std::setw(7) << std::setprecision(4) << translation[1] << ", "
332          << std::setw(7) << std::setprecision(4) << translation[2] << endl;
333   }
334 }     
335
336 //______________________________________________________________________________
337 void  AliMUONGeometrySVMap::WriteMap(ofstream& out) const
338 {    
339 // Prints the map of sensitive volumes and detector elements 
340 // into specified stream
341 // ---
342
343   fSVMap.Print("SV", out);
344 }  
345
346 //______________________________________________________________________________
347 Int_t  AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const
348 {
349 // Returns detection element Id for the sensitive volume specified by path
350 // ---
351
352   return fSVMap.Get(volumePath);
353 }