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