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/...
12 // The array of global positions of sensitive volumes fSVPositions
13 // is included to make easier the verification of the assignements
16 // Author: Ivana Hrivnacova, IPN Orsay
18 #include <Riostream.h>
19 #include <TGeoMatrix.h>
20 #include <TObjString.h>
22 #include "AliMUONGeometrySVMap.h"
24 ClassImp(AliMUONGeometrySVMap)
27 // Class AliMUONStringIntMap
30 //______________________________________________________________________________
31 AliMUONStringIntMap::AliMUONStringIntMap()
37 // Standard constructor
39 fFirstArray.SetOwner(true);
42 //______________________________________________________________________________
43 AliMUONStringIntMap::AliMUONStringIntMap(const AliMUONStringIntMap& rhs)
46 Fatal("Copy constructor",
47 "Copy constructor is not implemented.");
50 //______________________________________________________________________________
52 AliMUONStringIntMap::operator = (const AliMUONStringIntMap& rhs)
54 // check assignement to self
55 if (this == &rhs) return *this;
58 "Assignment operator is not implemented.");
63 //______________________________________________________________________________
64 AliMUONStringIntMap::~AliMUONStringIntMap()
72 //______________________________________________________________________________
73 Bool_t AliMUONStringIntMap::Add(const TString& first, Int_t second)
75 // Add map element if first not yet present
78 Int_t second2 = Get(first);
80 Error("Add", "%s is already present in the map", first.Data());
84 // Resize TArrayI if needed
85 if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
87 fFirstArray.Add(new TObjString(first));
88 fSecondArray.AddAt(second, fNofItems);
94 //______________________________________________________________________________
95 Int_t AliMUONStringIntMap::Get(const TString& first) const
97 // Find the element with specified key (first)
100 for (Int_t i=0; i<fNofItems; i++) {
101 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
102 return fSecondArray.At(i);
108 //______________________________________________________________________________
109 Int_t AliMUONStringIntMap::GetNofItems() const
111 // Returns the number of elements
117 //______________________________________________________________________________
118 void AliMUONStringIntMap::Clear()
120 // Deletes the elements
123 cout << "######### clearing map " << endl;
126 fFirstArray.Delete();
127 fSecondArray.Reset();
129 cout << "######### clearing map done " << endl;
132 //______________________________________________________________________________
133 void AliMUONStringIntMap::Print(const char* /*option*/) const
135 // Prints the map elements
137 for (Int_t i=0; i<fNofItems; i++) {
140 << ((TObjString*)fFirstArray.At(i))->GetString()
143 << fSecondArray.At(i)
148 //______________________________________________________________________________
149 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
151 // Prints the map elements
153 for (Int_t i=0; i<fNofItems; i++) {
155 << ((TObjString*)fFirstArray.At(i))->GetString()
158 << fSecondArray.At(i)
165 // Class AliMUONGeometrySVMap
168 //______________________________________________________________________________
169 AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize)
172 fSVPositions(initSize)
174 // Standard constructor
176 fSVPositions.SetOwner(true);
179 //______________________________________________________________________________
180 AliMUONGeometrySVMap::AliMUONGeometrySVMap()
185 // Default constructor
188 //______________________________________________________________________________
189 AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs)
192 Fatal("Copy constructor",
193 "Copy constructor is not implemented.");
196 //______________________________________________________________________________
197 AliMUONGeometrySVMap::~AliMUONGeometrySVMap() {
199 fSVPositions.Delete();
202 //______________________________________________________________________________
203 AliMUONGeometrySVMap&
204 AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs)
206 // check assignement to self
207 if (this == &rhs) return *this;
210 "Assignment operator is not implemented.");
219 //______________________________________________________________________________
220 const TGeoCombiTrans*
221 AliMUONGeometrySVMap::FindByName(const TString& name) const
223 // Finds TGeoCombiTrans in the array of positions by name
226 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
227 TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i);
228 if ( transform && TString(transform->GetTitle()) == name )
240 //______________________________________________________________________________
241 void AliMUONGeometrySVMap::Add(const TString& volumePath,
244 // Add the specified sensitive volume path and the detElemId
248 fSVMap.Add(volumePath, detElemId);
251 //______________________________________________________________________________
252 void AliMUONGeometrySVMap::AddPosition(const TString& volumePath,
253 const TGeoTranslation& globalPosition)
255 // Add global position for the sensitive volume specified by volumePath
256 // in the array of transformations if this volumePath is not yet present.
259 TGeoTranslation* newTransform = new TGeoTranslation(globalPosition);
260 Int_t detElemId = fSVMap.Get(volumePath);
262 TString detElemIdString("");
263 detElemIdString += detElemId;
265 newTransform->SetName(detElemIdString);
266 newTransform->SetTitle(volumePath);
268 // cout << ".. adding " << volumePath << " " << detElemId << endl;
271 if ( !FindByName(volumePath )) {
273 newTransform->SetUniqueID(detElemId);
274 // Set detector element id as unique id
276 fSVPositions.Add(newTransform);
280 //______________________________________________________________________________
281 void AliMUONGeometrySVMap::Clear()
283 // Clears the sensitive volumes map
288 //______________________________________________________________________________
289 void AliMUONGeometrySVMap::ClearPositions()
291 // Clears the array of transformations
293 fSVPositions.Delete();
296 //______________________________________________________________________________
297 void AliMUONGeometrySVMap::SortPositions()
299 // Sort the array of positions by names.
302 fSVPositions.Sort(fSVPositions.GetEntriesFast());
305 //______________________________________________________________________________
306 void AliMUONGeometrySVMap::Print(const char* option) const
308 // Prints the map of sensitive volumes and detector elements
311 fSVMap.Print(option);
314 //______________________________________________________________________________
315 void AliMUONGeometrySVMap::PrintPositions() const
317 // Prints the sensitive volumes global positions
320 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
322 TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i);
324 cout << "DetElemId: " << matrix->GetUniqueID();
325 cout << " name: " << matrix->GetTitle() << endl;
327 const double* translation = matrix->GetTranslation();
328 cout << " translation: "
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;
336 //______________________________________________________________________________
337 void AliMUONGeometrySVMap::WriteMap(ofstream& out) const
339 // Prints the map of sensitive volumes and detector elements
340 // into specified stream
343 fSVMap.Print("SV", out);
346 //______________________________________________________________________________
347 Int_t AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const
349 // Returns detection element Id for the sensitive volume specified by path
352 return fSVMap.Get(volumePath);