]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryModule.cxx
Additional protection in case of negative indexes. More investigation is needed
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryModule.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 AliMUONGeometryModule
19 // -----------------------------
20 // Class for definition of the detector module parameters
21 // (the transformations of detection elements, mapping between
22 //  sensitive volumes and detection elements).
23 //
24 // Author: Ivana Hrivnacova, IPN Orsay
25
26 #include "AliMUONGeometryModule.h"
27 #include "AliMUONGeometryModuleTransformer.h"
28 #include "AliMUONGeometryEnvelope.h"
29 #include "AliMUONGeometryEnvelopeStore.h"
30 #include "AliMUONGeometryDetElement.h"  
31 #include "AliMUONGeometryStore.h"       
32 #include "AliMUONStringIntMap.h"        
33
34 #include "AliLog.h"     
35
36 #include <TVirtualMC.h>
37 #include <TGeoMatrix.h>
38 #include <TObjArray.h>
39 #include <TArrayI.h>
40 #include <Riostream.h>
41
42 ClassImp(AliMUONGeometryModule)
43
44 //______________________________________________________________________________
45 AliMUONGeometryModule::AliMUONGeometryModule(Int_t moduleId)
46  : TObject(),
47    fIsVirtual(true),
48    fNofSVs(0),
49    fSVVolumeIds(0),
50    fEnvelopes(0),
51    fSVMap(0),
52    fTransformer(0)
53 {
54 /// Standard constructor
55
56   // Arrays of volumes Ids
57   fSVVolumeIds = new TArrayI(20);
58
59   // Sensitive volumes map
60   fSVMap = new AliMUONStringIntMap();
61
62   // Geometry parametrisation
63   fTransformer = new AliMUONGeometryModuleTransformer(moduleId);
64     
65   // Envelope store
66   fEnvelopes = new AliMUONGeometryEnvelopeStore(
67                              fTransformer->GetDetElementStore());  
68 }
69
70
71 //______________________________________________________________________________
72 AliMUONGeometryModule::AliMUONGeometryModule()
73  : TObject(),
74    fIsVirtual(true),
75    fNofSVs(0),
76    fSVVolumeIds(0),
77    fEnvelopes(0),
78    fSVMap(0),
79    fTransformer(0)
80 {
81 /// Default constructor
82 }
83
84
85 //______________________________________________________________________________
86 AliMUONGeometryModule::AliMUONGeometryModule(const AliMUONGeometryModule& rhs)
87   : TObject(rhs)
88 {
89 /// Protected copy constructor
90
91   AliFatal("Copy constructor is not implemented.");
92 }
93
94 //______________________________________________________________________________
95 AliMUONGeometryModule::~AliMUONGeometryModule() 
96 {
97 /// Destructor
98
99   delete fSVVolumeIds;
100   delete fEnvelopes;
101   delete fSVMap;
102   delete fTransformer;
103 }
104
105 //______________________________________________________________________________
106 AliMUONGeometryModule& 
107 AliMUONGeometryModule::operator = (const AliMUONGeometryModule& rhs) 
108 {
109 /// Protected assignement operator
110
111   // check assignement to self
112   if (this == &rhs) return *this;
113
114   AliFatal("Assignment operator is not implemented.");
115     
116   return *this;  
117 }
118
119 //
120 // private methods
121 //
122
123 //______________________________________________________________________________
124 Int_t AliMUONGeometryModule::GetSVIndex(Int_t svVolId) const
125 {
126 /// Return the index of the volume specified by volId
127 /// if it is present in the list of sensitive volumes 
128 /// (or -1 if not present).
129  
130   for (Int_t i=0; i<fNofSVs; i++) {
131       if (fSVVolumeIds->At(i) == svVolId) return i;
132   }
133   return -1;
134 }
135
136 //
137 // public methods
138 //
139
140 //______________________________________________________________________________
141 void  AliMUONGeometryModule::SetTransformation(const TGeoCombiTrans& transform)
142 {
143 /// Set the module position wrt world.
144
145   fTransformer->SetTransformation(transform);
146 }  
147
148 //______________________________________________________________________________
149 void AliMUONGeometryModule::SetVolumePath(const TString& volumePath)
150
151 /// Set the volume path to transformer
152
153   fTransformer->SetVolumePath(volumePath);
154 }
155
156 //______________________________________________________________________________
157 void  AliMUONGeometryModule::SetSensitiveVolume(Int_t svVolId)
158 {
159 /// Add the volume specified by volId to the list of sensitive
160 /// volumes
161   
162   // Resize TArrayI if needed
163   if (fSVVolumeIds->GetSize() == fNofSVs) fSVVolumeIds->Set(2*fNofSVs);
164
165   fSVVolumeIds->AddAt(svVolId, fNofSVs++);
166 }      
167
168 //______________________________________________________________________________
169 void  AliMUONGeometryModule::SetSensitiveVolume(const TString& volName)
170 {
171 /// Add the volume specified by volName to the list of sensitive
172 /// volumes
173
174   SetSensitiveVolume(gMC->VolId(volName));
175 }      
176
177 //______________________________________________________________________________
178 void  AliMUONGeometryModule::SetAlign(Bool_t align)
179 {
180 /// Set alignement option to envelope store.
181   
182   fEnvelopes->SetAlign(align);
183 }  
184
185 //______________________________________________________________________________
186 AliMUONGeometryDetElement* 
187 AliMUONGeometryModule::FindBySensitiveVolume(const TString& sensVolume) const
188 {
189 /// Find TGeoCombiTrans for the detector element Id specified by aligned volume 
190
191   Int_t detElemId = fSVMap->Get(sensVolume);
192
193   if (!detElemId) return 0; 
194         // The specified sensitive volume is not in the map   
195   
196   return fTransformer->GetDetElement(detElemId);
197 }  
198
199 //______________________________________________________________________________
200 Bool_t AliMUONGeometryModule::IsSensitiveVolume(Int_t volId) const
201 {
202 /// Check if the volume specified by volId is present in the list
203 /// of sensitive volumes.
204
205   for (Int_t i=0; i<fNofSVs; i++) {
206       if (fSVVolumeIds->At(i) == volId) return kTRUE;
207   }
208   return kFALSE;
209 }
210
211 //______________________________________________________________________________
212 Bool_t AliMUONGeometryModule::IsSensitiveVolume(const TString& volName) const
213 {
214 /// Check if the volume specified by volName  is present in the list
215 /// of sensitive volumes.
216
217   return IsSensitiveVolume(gMC->VolId(volName));
218 }