]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometrySVMap.cxx
- Adding volume path attribute (moved from AliMUONGeometryModule)
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometrySVMap.cxx
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
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"
38 #include "AliLog.h"
39
40 ClassImp(AliMUONGeometrySVMap)
41
42 //______________________________________________________________________________
43 AliMUONGeometrySVMap::AliMUONGeometrySVMap(Int_t initSize)
44  : TObject(),
45    fSVMap(),
46    fSVPositions(initSize)
47
48 /// Standard constructor
49   
50   fSVPositions.SetOwner(true);
51 }
52
53 //______________________________________________________________________________
54 AliMUONGeometrySVMap::AliMUONGeometrySVMap()
55  : TObject(),
56    fSVMap(),
57    fSVPositions()
58 {
59 /// Default constructor
60 }
61
62 //______________________________________________________________________________
63 AliMUONGeometrySVMap::AliMUONGeometrySVMap(const AliMUONGeometrySVMap& rhs)
64   : TObject(rhs)
65 {
66 /// Protected copy constructor
67
68   AliFatal("Copy constructor is not implemented.");
69 }
70
71 //______________________________________________________________________________
72 AliMUONGeometrySVMap::~AliMUONGeometrySVMap() 
73 {
74 /// Destructor
75
76   fSVPositions.Delete();
77 }
78
79 //______________________________________________________________________________
80 AliMUONGeometrySVMap& 
81 AliMUONGeometrySVMap::operator = (const AliMUONGeometrySVMap& rhs) 
82 {
83 /// Protected assignement operator
84
85   // check assignement to self
86   if (this == &rhs) return *this;
87
88   AliFatal("Assignment operator is not implemented.");
89     
90   return *this;  
91 }
92
93 //
94 // private methods
95 //
96
97 //______________________________________________________________________________
98 const TGeoCombiTrans* 
99 AliMUONGeometrySVMap::FindByName(const TString& name) const
100 {
101 /// Find TGeoCombiTrans in the array of positions by name 
102
103   for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) { 
104      TGeoCombiTrans* transform = (TGeoCombiTrans*) fSVPositions.At(i);
105      if ( transform && TString(transform->GetTitle()) == name )
106        return transform;
107   }     
108        
109   return 0;
110 }  
111
112
113 //
114 // public methods
115 //
116
117 //______________________________________________________________________________
118 void AliMUONGeometrySVMap::Add(const TString& volumePath, 
119                                Int_t detElemId)
120 {
121 /// Add the specified sensitive volume path and the detElemId 
122 /// to the map
123  
124   fSVMap.Add(volumePath, detElemId);
125 }                         
126     
127 //______________________________________________________________________________
128 void AliMUONGeometrySVMap::AddPosition(const TString& volumePath, 
129                               const TGeoTranslation& globalPosition)
130 {
131 /// Add global position for the sensitive volume specified by volumePath  
132 /// in the array of transformations if this volumePath is not yet present. 
133  
134   TGeoTranslation* newTransform = new TGeoTranslation(globalPosition);
135   Int_t detElemId = fSVMap.Get(volumePath);
136
137   TString detElemIdString("");
138   detElemIdString += detElemId;
139
140   newTransform->SetName(detElemIdString);
141   newTransform->SetTitle(volumePath);
142   
143   // cout << ".. adding " << volumePath << "  " << detElemId << endl;
144
145   // Add to the map  
146   if ( !FindByName(volumePath )) {
147   
148     newTransform->SetUniqueID(detElemId);
149       // Set detector element id as unique id
150  
151     fSVPositions.Add(newTransform);
152   } 
153 }                     
154     
155 //______________________________________________________________________________
156 void AliMUONGeometrySVMap::Clear(Option_t* /*option*/)
157 {
158 // Clears the sensitive volumes map
159
160   fSVMap.Clear();
161 }  
162
163 //______________________________________________________________________________
164 void AliMUONGeometrySVMap::ClearPositions()
165 {
166 /// Clear the array of transformations
167
168   fSVPositions.Delete();
169 }  
170
171 //______________________________________________________________________________
172 void AliMUONGeometrySVMap::SortPositions()
173 {
174 /// Sort the array of positions by names.
175
176   fSVPositions.Sort(fSVPositions.GetEntriesFast());
177 }
178   
179 //______________________________________________________________________________
180 void  AliMUONGeometrySVMap::Print(const char* option) const
181 {    
182 /// Print the map of sensitive volumes and detector elements 
183
184   fSVMap.Print(option);
185 }  
186
187 //______________________________________________________________________________
188 void  AliMUONGeometrySVMap::PrintPositions() const
189 {
190 /// Print the sensitive volumes global positions
191
192   for (Int_t i=0; i<fSVPositions.GetEntriesFast(); i++) {
193     
194     TGeoTranslation* matrix = (TGeoTranslation*)fSVPositions.At(i);
195
196     cout << "DetElemId: " << matrix->GetUniqueID();
197     cout << "  name: " << matrix->GetTitle() << endl;
198
199     const double* translation = matrix->GetTranslation();
200     cout << "   translation: "
201 #if defined (__DECCXX)
202          << translation[0] << ", " 
203          << translation[1] << ", "
204          << translation[2] << endl;
205 #else
206          << std::fixed
207          << std::setw(7) << std::setprecision(4) << translation[0] << ", " 
208          << std::setw(7) << std::setprecision(4) << translation[1] << ", "
209          << std::setw(7) << std::setprecision(4) << translation[2] << endl;
210 #endif
211   }
212 }     
213
214 //______________________________________________________________________________
215 void  AliMUONGeometrySVMap::WriteMap(ofstream& out) const
216 {    
217 /// Print the map of sensitive volumes and detector elements 
218 /// into specified stream
219
220   fSVMap.Print("SV", out);
221 }  
222
223 //______________________________________________________________________________
224 Int_t  AliMUONGeometrySVMap::GetDetElemId(const TString& volumePath) const
225 {
226 /// Return detection element Id for the sensitive volume specified by path
227
228   return fSVMap.Get(volumePath);
229 }