1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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/...
27 // The array of global positions of sensitive volumes fSVPositions
28 // is included to make easier the verification of the assignements
31 // Author: Ivana Hrivnacova, IPN Orsay
33 #include <Riostream.h>
34 #include <TGeoMatrix.h>
35 #include <TObjString.h>
37 #include "AliMUONGeometrySVMap.h"
40 ClassImp(AliMUONGeometrySVMap)
43 // Class AliMUONStringIntMap
46 //______________________________________________________________________________
47 AliMUONStringIntMap::AliMUONStringIntMap()
53 // Standard constructor
55 fFirstArray.SetOwner(true);
58 //______________________________________________________________________________
59 AliMUONStringIntMap::AliMUONStringIntMap(const AliMUONStringIntMap& rhs)
62 AliFatal("Copy constructor is not implemented.");
65 //______________________________________________________________________________
67 AliMUONStringIntMap::operator = (const AliMUONStringIntMap& rhs)
69 // check assignement to self
70 if (this == &rhs) return *this;
72 AliFatal("Assignment operator is not implemented.");
77 //______________________________________________________________________________
78 AliMUONStringIntMap::~AliMUONStringIntMap()
86 //______________________________________________________________________________
87 Bool_t AliMUONStringIntMap::Add(const TString& first, Int_t second)
89 // Add map element if first not yet present
92 Int_t second2 = Get(first);
94 AliError(Form("%s is already present in the map", first.Data()));
98 // Resize TArrayI if needed
99 if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
101 fFirstArray.Add(new TObjString(first));
102 fSecondArray.AddAt(second, fNofItems);
108 //______________________________________________________________________________
109 Int_t AliMUONStringIntMap::Get(const TString& first) const
111 // Find the element with specified key (first)
114 for (Int_t i=0; i<fNofItems; i++) {
115 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
116 return fSecondArray.At(i);
122 //______________________________________________________________________________
123 Int_t AliMUONStringIntMap::GetNofItems() const
125 // Returns the number of elements
131 //______________________________________________________________________________
132 void AliMUONStringIntMap::Clear()
134 // Deletes the elements
137 cout << "######### clearing map " << endl;
140 fFirstArray.Delete();
141 fSecondArray.Reset();
143 cout << "######### clearing map done " << endl;
146 //______________________________________________________________________________
147 void AliMUONStringIntMap::Print(const char* /*option*/) const
149 // Prints the map elements
151 for (Int_t i=0; i<fNofItems; i++) {
154 << ((TObjString*)fFirstArray.At(i))->GetString()
157 << fSecondArray.At(i)
162 //______________________________________________________________________________
163 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
165 // Prints the map elements
167 for (Int_t i=0; i<fNofItems; i++) {
169 << ((TObjString*)fFirstArray.At(i))->GetString()
172 << fSecondArray.At(i)
179 // Class AliMUONGeometrySVMap
182 //______________________________________________________________________________
183 AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize)
186 fSVPositions(initSize)
188 // Standard constructor
190 fSVPositions.SetOwner(true);
193 //______________________________________________________________________________
194 AliMUONGeometrySVMap::AliMUONGeometrySVMap()
199 // Default constructor
202 //______________________________________________________________________________
203 AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs)
206 AliFatal("Copy constructor is not implemented.");
209 //______________________________________________________________________________
210 AliMUONGeometrySVMap::~AliMUONGeometrySVMap() {
212 fSVPositions.Delete();
215 //______________________________________________________________________________
216 AliMUONGeometrySVMap&
217 AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs)
219 // check assignement to self
220 if (this == &rhs) return *this;
222 AliFatal("Assignment operator is not implemented.");
231 //______________________________________________________________________________
232 const TGeoCombiTrans*
233 AliMUONGeometrySVMap::FindByName(const TString& name) const
235 // Finds TGeoCombiTrans in the array of positions by name
238 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
239 TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i);
240 if ( transform && TString(transform->GetTitle()) == name )
252 //______________________________________________________________________________
253 void AliMUONGeometrySVMap::Add(const TString& volumePath,
256 // Add the specified sensitive volume path and the detElemId
260 fSVMap.Add(volumePath, detElemId);
263 //______________________________________________________________________________
264 void AliMUONGeometrySVMap::AddPosition(const TString& volumePath,
265 const TGeoTranslation& globalPosition)
267 // Add global position for the sensitive volume specified by volumePath
268 // in the array of transformations if this volumePath is not yet present.
271 TGeoTranslation* newTransform = new TGeoTranslation(globalPosition);
272 Int_t detElemId = fSVMap.Get(volumePath);
274 TString detElemIdString("");
275 detElemIdString += detElemId;
277 newTransform->SetName(detElemIdString);
278 newTransform->SetTitle(volumePath);
280 // cout << ".. adding " << volumePath << " " << detElemId << endl;
283 if ( !FindByName(volumePath )) {
285 newTransform->SetUniqueID(detElemId);
286 // Set detector element id as unique id
288 fSVPositions.Add(newTransform);
292 //______________________________________________________________________________
293 void AliMUONGeometrySVMap::Clear()
295 // Clears the sensitive volumes map
300 //______________________________________________________________________________
301 void AliMUONGeometrySVMap::ClearPositions()
303 // Clears the array of transformations
305 fSVPositions.Delete();
308 //______________________________________________________________________________
309 void AliMUONGeometrySVMap::SortPositions()
311 // Sort the array of positions by names.
314 fSVPositions.Sort(fSVPositions.GetEntriesFast());
317 //______________________________________________________________________________
318 void AliMUONGeometrySVMap::Print(const char* option) const
320 // Prints the map of sensitive volumes and detector elements
323 fSVMap.Print(option);
326 //______________________________________________________________________________
327 void AliMUONGeometrySVMap::PrintPositions() const
329 // Prints the sensitive volumes global positions
332 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
334 TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i);
336 cout << "DetElemId: " << matrix->GetUniqueID();
337 cout << " name: " << matrix->GetTitle() << endl;
339 const double* translation = matrix->GetTranslation();
340 cout << " translation: "
341 #if defined (__DECCXX)
342 << translation[0] << ", "
343 << translation[1] << ", "
344 << translation[2] << endl;
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;
354 //______________________________________________________________________________
355 void AliMUONGeometrySVMap::WriteMap(ofstream& out) const
357 // Prints the map of sensitive volumes and detector elements
358 // into specified stream
361 fSVMap.Print("SV", out);
364 //______________________________________________________________________________
365 Int_t AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const
367 // Returns detection element Id for the sensitive volume specified by path
370 return fSVMap.Get(volumePath);