1 | // |
---|
2 | // ******************************************************************** |
---|
3 | // * License and Disclaimer * |
---|
4 | // * * |
---|
5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
7 | // * conditions of the Geant4 Software License, included in the file * |
---|
8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
9 | // * include a list of copyright holders. * |
---|
10 | // * * |
---|
11 | // * Neither the authors of this software system, nor their employing * |
---|
12 | // * institutes,nor the agencies providing financial support for this * |
---|
13 | // * work make any representation or warranty, express or implied, * |
---|
14 | // * regarding this software system or assume any liability for its * |
---|
15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
16 | // * for the full disclaimer and the limitation of liability. * |
---|
17 | // * * |
---|
18 | // * This code implementation is the result of the scientific and * |
---|
19 | // * technical work of the GEANT4 collaboration. * |
---|
20 | // * By using, copying, modifying or distributing the software (or * |
---|
21 | // * any work based on the software) you agree to acknowledge its * |
---|
22 | // * use in resulting scientific publications, and indicate your * |
---|
23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
24 | // ******************************************************************** |
---|
25 | // |
---|
26 | // |
---|
27 | // File name: RadmonTDetectorVolumesWithPinsDecorator.icc |
---|
28 | // Creation date: Sep 2005 |
---|
29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
30 | // |
---|
31 | // Id: $Id: RadmonTDetectorVolumesWithPinsDecorator.icc,v 1.1.2.2 2006/06/29 16:12:46 gunter Exp $ |
---|
32 | // Tag: $Name: geant4-09-01-patch-02 $ |
---|
33 | // |
---|
34 | |
---|
35 | #ifndef RADMONTDETECTORVOLUMESWITHPINSDECORATOR_HH |
---|
36 | #error "RadmonTDetectorVolumesWithPinsDecorator.icc cannot be included directly. Please use RadmonTDetectorVolumesWithPinsDecorator.hh" |
---|
37 | #else /* RADMONTDETECTORVOLUMESWITHPINSDECORATOR_HH */ |
---|
38 | // Include files |
---|
39 | #include "RadmonVDetectorLabelledEntityConstructor.hh" |
---|
40 | #include "RadmonDetectorLayerVolumesList.hh" |
---|
41 | #include "RadmonDetectorLayerVolumeItem.hh" |
---|
42 | #include "G4Trap.hh" |
---|
43 | #include "G4Box.hh" |
---|
44 | #include "G4UIcommand.hh" |
---|
45 | |
---|
46 | template <class LayerVolumesComponent> |
---|
47 | RadmonTDetectorVolumesWithPinsDecorator<LayerVolumesComponent> :: RadmonTDetectorVolumesWithPinsDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor) |
---|
48 | : |
---|
49 | owner(constructor), |
---|
50 | component(constructor), |
---|
51 | visAttributes(0) |
---|
52 | { |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | template <class LayerVolumesComponent> |
---|
58 | RadmonTDetectorVolumesWithPinsDecorator<LayerVolumesComponent> :: ~RadmonTDetectorVolumesWithPinsDecorator() |
---|
59 | { |
---|
60 | delete visAttributes; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | template <class LayerVolumesComponent> |
---|
68 | RadmonDetectorLayerVolumesList * RadmonTDetectorVolumesWithPinsDecorator<LayerVolumesComponent> :: GenerateVolumesList(void) |
---|
69 | { |
---|
70 | G4double width(owner->GetWidth()); |
---|
71 | if (width<0) |
---|
72 | return 0; |
---|
73 | |
---|
74 | G4double height(owner->GetHeight()); |
---|
75 | if (height<0) |
---|
76 | return 0; |
---|
77 | |
---|
78 | G4double thickness(owner->GetThickness()); |
---|
79 | if (thickness<0) |
---|
80 | return 0; |
---|
81 | |
---|
82 | G4int holesAlongWidth(owner->GetAttributeAsInteger("HolesAlongWidth", -1)); |
---|
83 | if (holesAlongWidth<0) |
---|
84 | { |
---|
85 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"HolesAlongWidth\" attribute not defined." << G4endl; |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | G4int holesAlongHeight(owner->GetAttributeAsInteger("HolesAlongHeight", -1)); |
---|
90 | if (holesAlongHeight<0) |
---|
91 | { |
---|
92 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"HolesAlongHeight\" attribute not defined." << G4endl; |
---|
93 | return 0; |
---|
94 | } |
---|
95 | |
---|
96 | if ((holesAlongWidth+holesAlongHeight)<=0) |
---|
97 | { |
---|
98 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: Both \"HolesAlongHeight\" and \"HolesAlongHeight\" attributes are 0." << G4endl; |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|
102 | G4double holesRadius(owner->GetAttributeAsMeasure("HolesRadius", "Length", -1.)); |
---|
103 | if (holesRadius<0) |
---|
104 | { |
---|
105 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"HolesRadius\" attribute not defined." << G4endl; |
---|
106 | return 0; |
---|
107 | } |
---|
108 | |
---|
109 | G4double pinLength(owner->GetAttributeAsMeasure("PinLength", "Length", -1.)); |
---|
110 | if (pinLength<0) |
---|
111 | { |
---|
112 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"PinLength\" attribute not defined." << G4endl; |
---|
113 | return 0; |
---|
114 | } |
---|
115 | |
---|
116 | if (pinLength>=width/2 || pinLength>=height/2) |
---|
117 | { |
---|
118 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"PinLength\" exceeds half width or height." << G4endl; |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|
122 | G4double holesStep(owner->GetAttributeAsMeasure("HolesStep", "Length", -1.)); |
---|
123 | if (holesStep<0) |
---|
124 | { |
---|
125 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"HolesStep\" attribute not defined." << G4endl; |
---|
126 | return 0; |
---|
127 | } |
---|
128 | |
---|
129 | G4double fullHolesStep(holesRadius*2.+holesStep); |
---|
130 | |
---|
131 | if (fullHolesStep*static_cast<G4double>(holesAlongWidth-1)>width || fullHolesStep>width) |
---|
132 | { |
---|
133 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: Holes parameters does not fit along width." << G4endl; |
---|
134 | return 0; |
---|
135 | } |
---|
136 | |
---|
137 | if (fullHolesStep*static_cast<G4double>(holesAlongHeight-1)>height || fullHolesStep>height) |
---|
138 | { |
---|
139 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: Holes parameters does not fit along height." << G4endl; |
---|
140 | return 0; |
---|
141 | } |
---|
142 | |
---|
143 | G4int markedPin(owner->GetAttributeAsInteger("MarkedPin", 0)); |
---|
144 | |
---|
145 | if (markedPin<0 || markedPin>(holesAlongWidth+holesAlongHeight)*2) |
---|
146 | { |
---|
147 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: Marked pin outside the range." << G4endl; |
---|
148 | return 0; |
---|
149 | } |
---|
150 | |
---|
151 | G4double markedPinLength(0.); |
---|
152 | if (markedPin>0) |
---|
153 | { |
---|
154 | markedPinLength=owner->GetAttributeAsMeasure("MarkedPinLength", "Length", -1.); |
---|
155 | |
---|
156 | if (markedPinLength<0.) |
---|
157 | { |
---|
158 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"MarkedPinLength\" attribute not defined." << G4endl; |
---|
159 | return 0; |
---|
160 | } |
---|
161 | |
---|
162 | if (markedPinLength<=pinLength) |
---|
163 | { |
---|
164 | G4cout << "RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: \"MarkedPinLength\" <= \"PinLength\"." << G4endl; |
---|
165 | return 0; |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | G4Material * material(owner->GetMaterial("PinsMaterial")); |
---|
170 | if (!material) |
---|
171 | return 0; |
---|
172 | |
---|
173 | visAttributes=owner->AllocateVisAttributes("PinsVisAttributes", material); |
---|
174 | |
---|
175 | RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList()); |
---|
176 | |
---|
177 | if (list==0) |
---|
178 | return 0; |
---|
179 | |
---|
180 | G4int n(list->GetNItems()); |
---|
181 | |
---|
182 | if (n==0) |
---|
183 | { |
---|
184 | delete list; |
---|
185 | return 0; |
---|
186 | } |
---|
187 | |
---|
188 | RadmonDetectorLayerVolumeItem * item; |
---|
189 | RadmonDetectorLayerVolumeItem * motherItem; |
---|
190 | |
---|
191 | while (n>0) |
---|
192 | { |
---|
193 | n--; |
---|
194 | |
---|
195 | item=list->GetItem(n); |
---|
196 | if (item->GetMotherVolumeItem()==0) |
---|
197 | { |
---|
198 | motherItem=item; |
---|
199 | break; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | if (!motherItem) |
---|
204 | G4Exception("RadmonTDetectorVolumesWithPinsDecorator::GenerateVolumesList: No mother volume found."); |
---|
205 | |
---|
206 | intersection.Initialize(motherItem); |
---|
207 | |
---|
208 | G4Box * singlePin(new G4Box("SinglePin", holesRadius, pinLength/2., thickness/2.)); |
---|
209 | |
---|
210 | G4ThreeVector offset; |
---|
211 | |
---|
212 | offset.setX((fullHolesStep/2.)*static_cast<G4double>(holesAlongWidth-1)); |
---|
213 | offset.setY(height/2.-pinLength/2.); |
---|
214 | offset.setZ(0.); |
---|
215 | |
---|
216 | G4int i(holesAlongWidth); |
---|
217 | G4int index(0); |
---|
218 | G4String indexStr; |
---|
219 | |
---|
220 | const G4double heightFraction(.999); |
---|
221 | const G4double pDx2(holesRadius); |
---|
222 | const G4double pDx1(pDx2*(1.-heightFraction)); |
---|
223 | const G4double pDy1((markedPinLength-pinLength)*heightFraction/2.); |
---|
224 | |
---|
225 | while (i>0) |
---|
226 | { |
---|
227 | index++; |
---|
228 | indexStr=G4UIcommand::ConvertToString(index); |
---|
229 | |
---|
230 | item=list->AppendItem(); |
---|
231 | item->SetSolid(intersection.ApplyTo(singlePin, offset, index==1, true)); |
---|
232 | item->SetAttributes(visAttributes); |
---|
233 | item->SetMaterial(material); |
---|
234 | item->SetName("Pin"+indexStr); |
---|
235 | item->SetMotherVolumeItem(motherItem); |
---|
236 | |
---|
237 | if (index==markedPin) |
---|
238 | { |
---|
239 | G4Trap * trap; |
---|
240 | |
---|
241 | G4ThreeVector offset2(offset); |
---|
242 | if (offset2.getY()<0) |
---|
243 | { |
---|
244 | offset2.setY(offset2.getY()+pDy1+pinLength/2); |
---|
245 | // pDz pTheta pPhi pDy1 pDx1 pDx2 pAlp1 |
---|
246 | trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, pDy1, pDx2, pDx1, 0*deg, |
---|
247 | // pDy2 pDx3 pDx4 pAlp2 |
---|
248 | pDy1, pDx2, pDx1, 0*deg); |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | offset2.setY(offset2.getY()-pDy1-pinLength/2); |
---|
253 | // pDz pTheta pPhi pDy1 pDx1 pDx2 pAlp1 |
---|
254 | trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, pDy1, pDx1, pDx2, 0*deg, |
---|
255 | // pDy2 pDx3 pDx4 pAlp2 |
---|
256 | pDy1, pDx1, pDx2, 0*deg); |
---|
257 | } |
---|
258 | |
---|
259 | item=list->AppendItem(); |
---|
260 | item->SetSolid(intersection.ApplyTo(trap, offset2, true, true)); |
---|
261 | item->SetAttributes(visAttributes); |
---|
262 | item->SetMaterial(material); |
---|
263 | item->SetName("MarkedPin"); |
---|
264 | item->SetMotherVolumeItem(motherItem); |
---|
265 | } |
---|
266 | |
---|
267 | offset.setY(-offset.getY()); |
---|
268 | if (offset.getY()>=0) |
---|
269 | { |
---|
270 | offset.setX(offset.getX()-fullHolesStep); |
---|
271 | i--; |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | offset.setX(width/2.-pinLength/2.); |
---|
276 | offset.setY((fullHolesStep/2.)*static_cast<G4double>(holesAlongHeight-1)); |
---|
277 | i=holesAlongHeight; |
---|
278 | |
---|
279 | G4RotationMatrix rotation(G4RotationMatrix::IDENTITY); |
---|
280 | rotation.setDelta(90*deg); |
---|
281 | |
---|
282 | while (i>0) |
---|
283 | { |
---|
284 | index++; |
---|
285 | indexStr=G4UIcommand::ConvertToString(index); |
---|
286 | |
---|
287 | item=list->AppendItem(); |
---|
288 | item->SetSolid(intersection.ApplyTo(singlePin, rotation, offset, index==1, true)); |
---|
289 | item->SetAttributes(visAttributes); |
---|
290 | item->SetMaterial(material); |
---|
291 | item->SetName("Pin"+indexStr); |
---|
292 | item->SetMotherVolumeItem(motherItem); |
---|
293 | |
---|
294 | if (index==markedPin) |
---|
295 | { |
---|
296 | G4Trap * trap; |
---|
297 | |
---|
298 | G4ThreeVector offset2(offset); |
---|
299 | if (offset2.getX()<0) |
---|
300 | { |
---|
301 | offset2.setX(offset2.getX()+pDy1+pinLength/2); |
---|
302 | // pDz pTheta pPhi pDy1 pDx1 pDx2 pAlp1 |
---|
303 | trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, pDy1, pDx2, pDx1, 0*deg, |
---|
304 | // pDy2 pDx3 pDx4 pAlp2 |
---|
305 | pDy1, pDx2, pDx1, 0*deg); |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | offset2.setX(offset2.getX()-pDy1-pinLength/2); |
---|
310 | // pDz pTheta pPhi pDy1 pDx1 pDx2 pAlp1 |
---|
311 | trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, pDy1, pDx1, pDx2, 0*deg, |
---|
312 | // pDy2 pDx3 pDx4 pAlp2 |
---|
313 | pDy1, pDx1, pDx2, 0*deg); |
---|
314 | } |
---|
315 | |
---|
316 | item=list->AppendItem(); |
---|
317 | item->SetSolid(intersection.ApplyTo(trap, rotation, offset2, true, true)); |
---|
318 | item->SetAttributes(visAttributes); |
---|
319 | item->SetMaterial(material); |
---|
320 | item->SetName("MarkedPin"); |
---|
321 | item->SetMotherVolumeItem(motherItem); |
---|
322 | } |
---|
323 | |
---|
324 | offset.setX(-offset.getX()); |
---|
325 | if (offset.getX()>=0) |
---|
326 | { |
---|
327 | offset.setY(offset.getY()-fullHolesStep); |
---|
328 | i--; |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | return list; |
---|
333 | } |
---|
334 | #endif /* RADMONTDETECTORVOLUMESWITHPINSDECORATOR_HH */ |
---|
335 | |
---|