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(Option_t* /*option*/)
134 // Deletes the elements
138 fFirstArray.Delete();
139 fSecondArray.Reset();
142 //______________________________________________________________________________
143 void AliMUONStringIntMap::Print(const char* /*option*/) const
145 // Prints the map elements
147 for (Int_t i=0; i<fNofItems; i++) {
150 << ((TObjString*)fFirstArray.At(i))->GetString()
153 << fSecondArray.At(i)
158 //______________________________________________________________________________
159 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
161 // Prints the map elements
163 for (Int_t i=0; i<fNofItems; i++) {
165 << ((TObjString*)fFirstArray.At(i))->GetString()
168 << fSecondArray.At(i)
175 // Class AliMUONGeometrySVMap
178 //______________________________________________________________________________
179 AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize)
182 fSVPositions(initSize)
184 // Standard constructor
186 fSVPositions.SetOwner(true);
189 //______________________________________________________________________________
190 AliMUONGeometrySVMap::AliMUONGeometrySVMap()
195 // Default constructor
198 //______________________________________________________________________________
199 AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs)
202 AliFatal("Copy constructor is not implemented.");
205 //______________________________________________________________________________
206 AliMUONGeometrySVMap::~AliMUONGeometrySVMap() {
208 fSVPositions.Delete();
211 //______________________________________________________________________________
212 AliMUONGeometrySVMap&
213 AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs)
215 // check assignement to self
216 if (this == &rhs) return *this;
218 AliFatal("Assignment operator is not implemented.");
227 //______________________________________________________________________________
228 const TGeoCombiTrans*
229 AliMUONGeometrySVMap::FindByName(const TString& name) const
231 // Finds TGeoCombiTrans in the array of positions by name
234 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
235 TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i);
236 if ( transform && TString(transform->GetTitle()) == name )
248 //______________________________________________________________________________
249 void AliMUONGeometrySVMap::Add(const TString& volumePath,
252 // Add the specified sensitive volume path and the detElemId
256 fSVMap.Add(volumePath, detElemId);
259 //______________________________________________________________________________
260 void AliMUONGeometrySVMap::AddPosition(const TString& volumePath,
261 const TGeoTranslation& globalPosition)
263 // Add global position for the sensitive volume specified by volumePath
264 // in the array of transformations if this volumePath is not yet present.
267 TGeoTranslation* newTransform = new TGeoTranslation(globalPosition);
268 Int_t detElemId = fSVMap.Get(volumePath);
270 TString detElemIdString("");
271 detElemIdString += detElemId;
273 newTransform->SetName(detElemIdString);
274 newTransform->SetTitle(volumePath);
276 // cout << ".. adding " << volumePath << " " << detElemId << endl;
279 if ( !FindByName(volumePath )) {
281 newTransform->SetUniqueID(detElemId);
282 // Set detector element id as unique id
284 fSVPositions.Add(newTransform);
288 //______________________________________________________________________________
289 void AliMUONGeometrySVMap::Clear(Option_t* /*option*/)
291 // Clears the sensitive volumes map
296 //______________________________________________________________________________
297 void AliMUONGeometrySVMap::ClearPositions()
299 // Clears the array of transformations
301 fSVPositions.Delete();
304 //______________________________________________________________________________
305 void AliMUONGeometrySVMap::SortPositions()
307 // Sort the array of positions by names.
310 fSVPositions.Sort(fSVPositions.GetEntriesFast());
313 //______________________________________________________________________________
314 void AliMUONGeometrySVMap::Print(const char* option) const
316 // Prints the map of sensitive volumes and detector elements
319 fSVMap.Print(option);
322 //______________________________________________________________________________
323 void AliMUONGeometrySVMap::PrintPositions() const
325 // Prints the sensitive volumes global positions
328 for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
330 TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i);
332 cout << "DetElemId: " << matrix->GetUniqueID();
333 cout << " name: " << matrix->GetTitle() << endl;
335 const double* translation = matrix->GetTranslation();
336 cout << " translation: "
337 #if defined (__DECCXX)
338 << translation[0] << ", "
339 << translation[1] << ", "
340 << translation[2] << endl;
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;
350 //______________________________________________________________________________
351 void AliMUONGeometrySVMap::WriteMap(ofstream& out) const
353 // Prints the map of sensitive volumes and detector elements
354 // into specified stream
357 fSVMap.Print("SV", out);
360 //______________________________________________________________________________
361 Int_t AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const
363 // Returns detection element Id for the sensitive volume specified by path
366 return fSVMap.Get(volumePath);