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"
25 ClassImp(AliMUONGeometrySVMap)
28 // Class AliMUONStringIntMap
31 //______________________________________________________________________________
32 AliMUONStringIntMap::AliMUONStringIntMap()
38 // Standard constructor
40 fFirstArray.SetOwner(true);
43 //______________________________________________________________________________
44 AliMUONStringIntMap::AliMUONStringIntMap(const AliMUONStringIntMap& rhs)
47 AliFatal("Copy constructor is not implemented.");
50 //______________________________________________________________________________
52 AliMUONStringIntMap::operator = (const AliMUONStringIntMap& rhs)
54 // check assignement to self
55 if (this == &rhs) return *this;
57 AliFatal("Assignment operator is not implemented.");
62 //______________________________________________________________________________
63 AliMUONStringIntMap::~AliMUONStringIntMap()
71 //______________________________________________________________________________
72 Bool_t AliMUONStringIntMap::Add(const TString& first, Int_t second)
74 // Add map element if first not yet present
77 Int_t second2 = Get(first);
79 AliError(Form("%s is already present in the map", first.Data()));
83 // Resize TArrayI if needed
84 if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
86 fFirstArray.Add(new TObjString(first));
87 fSecondArray.AddAt(second, fNofItems);
93 //______________________________________________________________________________
94 Int_t AliMUONStringIntMap::Get(const TString& first) const
96 // Find the element with specified key (first)
99 for (Int_t i=0; i<fNofItems; i++) {
100 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
101 return fSecondArray.At(i);
107 //______________________________________________________________________________
108 Int_t AliMUONStringIntMap::GetNofItems() const
110 // Returns the number of elements
116 //______________________________________________________________________________
117 void AliMUONStringIntMap::Clear()
119 // Deletes the elements
122 cout << "######### clearing map " << endl;
125 fFirstArray.Delete();
126 fSecondArray.Reset();
128 cout << "######### clearing map done " << endl;
131 //______________________________________________________________________________
132 void AliMUONStringIntMap::Print(const char* /*option*/) const
134 // Prints the map elements
136 for (Int_t i=0; i<fNofItems; i++) {
139 << ((TObjString*)fFirstArray.At(i))->GetString()
142 << fSecondArray.At(i)
147 //______________________________________________________________________________
148 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
150 // Prints the map elements
152 for (Int_t i=0; i<fNofItems; i++) {
154 << ((TObjString*)fFirstArray.At(i))->GetString()
157 << fSecondArray.At(i)
164 // Class AliMUONGeometrySVMap
167 //______________________________________________________________________________
168 AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize)
171 fSVPositions(initSize)
173 // Standard constructor
175 fSVPositions.SetOwner(true);
178 //______________________________________________________________________________
179 AliMUONGeometrySVMap::AliMUONGeometrySVMap()
184 // Default constructor
187 //______________________________________________________________________________
188 AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs)
191 AliFatal("Copy constructor is not implemented.");
194 //______________________________________________________________________________
195 AliMUONGeometrySVMap::~AliMUONGeometrySVMap() {
197 fSVPositions.Delete();
200 //______________________________________________________________________________
201 AliMUONGeometrySVMap&
202 AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs)
204 // check assignement to self
205 if (this == &rhs) return *this;
207 AliFatal("Assignment operator is not implemented.");
216 //______________________________________________________________________________
217 const TGeoCombiTrans*
218 AliMUONGeometrySVMap::FindByName(const TString& name) const
220 // Finds TGeoCombiTrans in the array of positions by name
223 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
224 TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i);
225 if ( transform && TString(transform->GetTitle()) == name )
237 //______________________________________________________________________________
238 void AliMUONGeometrySVMap::Add(const TString& volumePath,
241 // Add the specified sensitive volume path and the detElemId
245 fSVMap.Add(volumePath, detElemId);
248 //______________________________________________________________________________
249 void AliMUONGeometrySVMap::AddPosition(const TString& volumePath,
250 const TGeoTranslation& globalPosition)
252 // Add global position for the sensitive volume specified by volumePath
253 // in the array of transformations if this volumePath is not yet present.
256 TGeoTranslation* newTransform = new TGeoTranslation(globalPosition);
257 Int_t detElemId = fSVMap.Get(volumePath);
259 TString detElemIdString("");
260 detElemIdString += detElemId;
262 newTransform->SetName(detElemIdString);
263 newTransform->SetTitle(volumePath);
265 // cout << ".. adding " << volumePath << " " << detElemId << endl;
268 if ( !FindByName(volumePath )) {
270 newTransform->SetUniqueID(detElemId);
271 // Set detector element id as unique id
273 fSVPositions.Add(newTransform);
277 //______________________________________________________________________________
278 void AliMUONGeometrySVMap::Clear()
280 // Clears the sensitive volumes map
285 //______________________________________________________________________________
286 void AliMUONGeometrySVMap::ClearPositions()
288 // Clears the array of transformations
290 fSVPositions.Delete();
293 //______________________________________________________________________________
294 void AliMUONGeometrySVMap::SortPositions()
296 // Sort the array of positions by names.
299 fSVPositions.Sort(fSVPositions.GetEntriesFast());
302 //______________________________________________________________________________
303 void AliMUONGeometrySVMap::Print(const char* option) const
305 // Prints the map of sensitive volumes and detector elements
308 fSVMap.Print(option);
311 //______________________________________________________________________________
312 void AliMUONGeometrySVMap::PrintPositions() const
314 // Prints the sensitive volumes global positions
317 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
319 TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i);
321 cout << "DetElemId: " << matrix->GetUniqueID();
322 cout << " name: " << matrix->GetTitle() << endl;
324 const double* translation = matrix->GetTranslation();
325 cout << " translation: "
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;
333 //______________________________________________________________________________
334 void AliMUONGeometrySVMap::WriteMap(ofstream& out) const
336 // Prints the map of sensitive volumes and detector elements
337 // into specified stream
340 fSVMap.Print("SV", out);
343 //______________________________________________________________________________
344 Int_t AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const
346 // Returns detection element Id for the sensitive volume specified by path
349 return fSVMap.Get(volumePath);