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