]>
Commit | Line | Data |
---|---|---|
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 | |
40 | ClassImp(AliMUONGeometrySVMap) | |
41 | ||
42 | // | |
43 | // Class AliMUONStringIntMap | |
44 | // | |
45 | ||
46 | //______________________________________________________________________________ | |
47 | AliMUONStringIntMap::AliMUONStringIntMap() | |
48 | : TObject(), | |
49 | fNofItems(0), | |
50 | fFirstArray(100), | |
51 | fSecondArray(100) | |
52 | { | |
53 | // Standard constructor | |
54 | ||
55 | fFirstArray.SetOwner(true); | |
56 | } | |
57 | ||
58 | //______________________________________________________________________________ | |
59 | AliMUONStringIntMap::AliMUONStringIntMap(const AliMUONStringIntMap& rhs) | |
60 | : TObject(rhs) | |
61 | { | |
8c343c7c | 62 | AliFatal("Copy constructor is not implemented."); |
89cc3034 | 63 | } |
64 | ||
65 | //______________________________________________________________________________ | |
66 | AliMUONStringIntMap& | |
67 | AliMUONStringIntMap::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 | //______________________________________________________________________________ | |
78 | AliMUONStringIntMap::~AliMUONStringIntMap() | |
79 | { | |
80 | // Destructor | |
81 | ||
82 | fFirstArray.Delete(); | |
83 | } | |
84 | ||
85 | ||
86 | //______________________________________________________________________________ | |
87 | Bool_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 | //______________________________________________________________________________ | |
109 | Int_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 | //______________________________________________________________________________ | |
123 | Int_t AliMUONStringIntMap::GetNofItems() const | |
124 | { | |
125 | // Returns the number of elements | |
126 | // --- | |
127 | ||
128 | return fNofItems; | |
129 | } | |
130 | ||
131 | //______________________________________________________________________________ | |
4ebc2323 | 132 | void AliMUONStringIntMap::Clear(Option_t* /*option*/) |
89cc3034 | 133 | { |
134 | // Deletes the elements | |
135 | // --- | |
136 | ||
89cc3034 | 137 | fNofItems = 0; |
138 | fFirstArray.Delete(); | |
139 | fSecondArray.Reset(); | |
89cc3034 | 140 | } |
141 | ||
142 | //______________________________________________________________________________ | |
143 | void AliMUONStringIntMap::Print(const char* /*option*/) const | |
144 | { | |
145 | // Prints the map elements | |
146 | ||
147 | for (Int_t i=0; i<fNofItems; i++) { | |
148 | cout << setw(4) | |
149 | << i << " " | |
150 | << ((TObjString*)fFirstArray.At(i))->GetString() | |
151 | << " " | |
152 | << setw(5) | |
153 | << fSecondArray.At(i) | |
154 | << endl; | |
155 | } | |
156 | } | |
157 | ||
158 | //______________________________________________________________________________ | |
159 | void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const | |
160 | { | |
161 | // Prints the map elements | |
162 | ||
163 | for (Int_t i=0; i<fNofItems; i++) { | |
164 | out << key << " " | |
165 | << ((TObjString*)fFirstArray.At(i))->GetString() | |
166 | << " " | |
167 | << setw(5) | |
168 | << fSecondArray.At(i) | |
169 | << endl; | |
170 | } | |
171 | } | |
172 | ||
173 | ||
174 | // | |
175 | // Class AliMUONGeometrySVMap | |
176 | // | |
177 | ||
178 | //______________________________________________________________________________ | |
179 | AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize) | |
180 | : TObject(), | |
181 | fSVMap(), | |
182 | fSVPositions(initSize) | |
183 | { | |
184 | // Standard constructor | |
185 | ||
186 | fSVPositions.SetOwner(true); | |
187 | } | |
188 | ||
189 | //______________________________________________________________________________ | |
190 | AliMUONGeometrySVMap::AliMUONGeometrySVMap() | |
191 | : TObject(), | |
192 | fSVMap(), | |
193 | fSVPositions() | |
194 | { | |
195 | // Default constructor | |
196 | } | |
197 | ||
198 | //______________________________________________________________________________ | |
199 | AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs) | |
200 | : TObject(rhs) | |
201 | { | |
8c343c7c | 202 | AliFatal("Copy constructor is not implemented."); |
89cc3034 | 203 | } |
204 | ||
205 | //______________________________________________________________________________ | |
206 | AliMUONGeometrySVMap::~AliMUONGeometrySVMap() { | |
207 | // | |
208 | fSVPositions.Delete(); | |
209 | } | |
210 | ||
211 | //______________________________________________________________________________ | |
212 | AliMUONGeometrySVMap& | |
213 | AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs) | |
214 | { | |
215 | // check assignement to self | |
216 | if (this == &rhs) return *this; | |
217 | ||
8c343c7c | 218 | AliFatal("Assignment operator is not implemented."); |
89cc3034 | 219 | |
220 | return *this; | |
221 | } | |
222 | ||
223 | // | |
224 | // private methods | |
225 | // | |
226 | ||
227 | //______________________________________________________________________________ | |
228 | const TGeoCombiTrans* | |
229 | AliMUONGeometrySVMap::FindByName(const TString& name) const | |
230 | { | |
231 | // Finds TGeoCombiTrans in the array of positions by name | |
232 | // --- | |
233 | ||
234 | for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) { | |
235 | TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i); | |
236 | if ( transform && TString(transform->GetTitle()) == name ) | |
237 | return transform; | |
238 | } | |
239 | ||
240 | return 0; | |
241 | } | |
242 | ||
243 | ||
244 | // | |
245 | // public methods | |
246 | // | |
247 | ||
248 | //______________________________________________________________________________ | |
249 | void AliMUONGeometrySVMap::Add(const TString& volumePath, | |
250 | Int_t detElemId) | |
251 | { | |
252 | // Add the specified sensitive volume path and the detElemId | |
253 | // to the map | |
254 | // --- | |
255 | ||
256 | fSVMap.Add(volumePath, detElemId); | |
257 | } | |
258 | ||
259 | //______________________________________________________________________________ | |
260 | void AliMUONGeometrySVMap::AddPosition(const TString& volumePath, | |
261 | const TGeoTranslation& globalPosition) | |
262 | { | |
263 | // Add global position for the sensitive volume specified by volumePath | |
264 | // in the array of transformations if this volumePath is not yet present. | |
265 | // --- | |
266 | ||
267 | TGeoTranslation* newTransform = new TGeoTranslation(globalPosition); | |
268 | Int_t detElemId = fSVMap.Get(volumePath); | |
269 | ||
270 | TString detElemIdString(""); | |
271 | detElemIdString += detElemId; | |
272 | ||
273 | newTransform->SetName(detElemIdString); | |
274 | newTransform->SetTitle(volumePath); | |
275 | ||
276 | // cout << ".. adding " << volumePath << " " << detElemId << endl; | |
277 | ||
278 | // Add to the map | |
279 | if ( !FindByName(volumePath )) { | |
280 | ||
281 | newTransform->SetUniqueID(detElemId); | |
282 | // Set detector element id as unique id | |
283 | ||
284 | fSVPositions.Add(newTransform); | |
285 | } | |
286 | } | |
287 | ||
288 | //______________________________________________________________________________ | |
4ebc2323 | 289 | void AliMUONGeometrySVMap::Clear(Option_t* /*option*/) |
89cc3034 | 290 | { |
291 | // Clears the sensitive volumes map | |
292 | ||
293 | fSVMap.Clear(); | |
294 | } | |
295 | ||
296 | //______________________________________________________________________________ | |
297 | void AliMUONGeometrySVMap::ClearPositions() | |
298 | { | |
299 | // Clears the array of transformations | |
300 | ||
301 | fSVPositions.Delete(); | |
302 | } | |
303 | ||
304 | //______________________________________________________________________________ | |
305 | void AliMUONGeometrySVMap::SortPositions() | |
306 | { | |
307 | // Sort the array of positions by names. | |
308 | // --- | |
309 | ||
310 | fSVPositions.Sort(fSVPositions.GetEntriesFast()); | |
311 | } | |
312 | ||
313 | //______________________________________________________________________________ | |
314 | void AliMUONGeometrySVMap::Print(const char* option) const | |
315 | { | |
316 | // Prints the map of sensitive volumes and detector elements | |
317 | // --- | |
318 | ||
319 | fSVMap.Print(option); | |
320 | } | |
321 | ||
322 | //______________________________________________________________________________ | |
323 | void AliMUONGeometrySVMap::PrintPositions() const | |
324 | { | |
325 | // Prints the sensitive volumes global positions | |
326 | // --- | |
327 | ||
328 | for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) { | |
329 | ||
330 | TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i); | |
331 | ||
332 | cout << "DetElemId: " << matrix->GetUniqueID(); | |
333 | cout << " name: " << matrix->GetTitle() << endl; | |
334 | ||
335 | const double* translation = matrix->GetTranslation(); | |
336 | cout << " translation: " | |
e516b01d | 337 | #if defined (__DECCXX) |
338 | << translation[0] << ", " | |
339 | << translation[1] << ", " | |
340 | << translation[2] << endl; | |
341 | #else | |
89cc3034 | 342 | << std::fixed |
343 | << std::setw(7) << std::setprecision(4) << translation[0] << ", " | |
344 | << std::setw(7) << std::setprecision(4) << translation[1] << ", " | |
345 | << std::setw(7) << std::setprecision(4) << translation[2] << endl; | |
e516b01d | 346 | #endif |
89cc3034 | 347 | } |
348 | } | |
349 | ||
350 | //______________________________________________________________________________ | |
351 | void AliMUONGeometrySVMap::WriteMap(ofstream& out) const | |
352 | { | |
353 | // Prints the map of sensitive volumes and detector elements | |
354 | // into specified stream | |
355 | // --- | |
356 | ||
357 | fSVMap.Print("SV", out); | |
358 | } | |
359 | ||
360 | //______________________________________________________________________________ | |
361 | Int_t AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const | |
362 | { | |
363 | // Returns detection element Id for the sensitive volume specified by path | |
364 | // --- | |
365 | ||
366 | return fSVMap.Get(volumePath); | |
367 | } |