source: trunk/examples/advanced/radiation_monitor/detector/include/RadmonTDetectorVolumesWithKeyMarksDecorator.icc @ 1288

Last change on this file since 1288 was 807, checked in by garnier, 16 years ago

update

File size: 11.6 KB
Line 
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:     RadmonTDetectorVolumesWithKeyMarksDecorator.icc
28// Creation date: Sep 2005
29// Main author:   Riccardo Capra <capra@ge.infn.it>
30//
31// Id:            $Id: RadmonTDetectorVolumesWithKeyMarksDecorator.icc,v 1.1.2.2 2006/06/29 16:12:38 gunter Exp $
32// Tag:           $Name: geant4-09-01-patch-02 $
33//
34
35#ifndef   RADMONTDETECTORVOLUMESWITHKEYMARKSDECORATOR_HH
36 #error "RadmonTDetectorVolumesWithKeyMarksDecorator.icc cannot be included directly. Please use RadmonTDetectorVolumesWithKeyMarksDecorator.hh"
37#else  /* RADMONTDETECTORVOLUMESWITHKEYMARKSDECORATOR_HH */
38 // Include files
39 #include "RadmonVDetectorLabelledEntityConstructor.hh"
40 #include "RadmonDetectorLayerVolumesList.hh"
41 #include "RadmonDetectorLayerVolumeItem.hh"
42 #include "G4Tubs.hh"
43 #include "G4SubtractionSolid.hh"
44 #include "G4Box.hh"
45 #include "G4UIcommand.hh"
46 
47 template <class LayerVolumesComponent>
48                                                RadmonTDetectorVolumesWithKeyMarksDecorator<LayerVolumesComponent> :: RadmonTDetectorVolumesWithKeyMarksDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor)
49 :
50  owner(constructor),
51  component(constructor),
52  visAttributes(0),
53  box(0),
54  tub(0),
55  identity(G4RotationMatrix::IDENTITY)
56 {
57 }
58 
59 
60 
61 template <class LayerVolumesComponent>
62                                                RadmonTDetectorVolumesWithKeyMarksDecorator<LayerVolumesComponent> :: ~RadmonTDetectorVolumesWithKeyMarksDecorator()
63 {
64  delete box;
65  delete tub;
66  delete visAttributes;
67 }
68 
69 
70 
71 
72 
73 template <class LayerVolumesComponent>
74 RadmonDetectorLayerVolumesList *               RadmonTDetectorVolumesWithKeyMarksDecorator<LayerVolumesComponent> :: GenerateVolumesList(void)
75 {
76  G4double width(owner->GetWidth());
77  if (width<0)
78   return 0;
79
80  G4double height(owner->GetHeight());
81  if (height<0)
82   return 0;
83 
84  G4double thickness(owner->GetThickness());
85  if (thickness<0)
86   return 0;
87 
88  G4int holesAlongWidth(owner->GetAttributeAsInteger("HolesAlongWidth", -1));
89  if (holesAlongWidth<0)
90  {
91   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesAlongWidth\" attribute not defined." << G4endl;
92   return 0;
93  }
94
95  G4int holesAlongHeight(owner->GetAttributeAsInteger("HolesAlongHeight", -1));
96  if (holesAlongHeight<0)
97  {
98   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesAlongHeight\" attribute not defined." << G4endl;
99   return 0;
100  }
101 
102  if ((holesAlongWidth+holesAlongHeight)<=0)
103  {
104   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Both \"HolesAlongHeight\" and \"HolesAlongHeight\" attributes are 0." << G4endl;
105   return 0;
106  }
107
108  G4double holesRadius(owner->GetAttributeAsMeasure("HolesRadius", "Length", -1.));
109  if (holesRadius<0)
110  {
111   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesRadius\" attribute not defined." << G4endl;
112   return 0;
113  }
114 
115  G4double holesStep(owner->GetAttributeAsMeasure("HolesStep", "Length", -1.));
116  if (holesStep<0)
117  {
118   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesStep\" attribute not defined." << G4endl;
119   return 0;
120  }
121 
122  G4double fullHolesStep(holesRadius*2.+holesStep);
123 
124  if (fullHolesStep*static_cast<G4double>(holesAlongWidth-1)>width || fullHolesStep>width)
125  {
126   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Holes parameters does not fit along width." << G4endl;
127   return 0;
128  }
129 
130  if (fullHolesStep*static_cast<G4double>(holesAlongHeight-1)>height || fullHolesStep>height)
131  {
132   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Holes parameters does not fit along height." << G4endl;
133   return 0;
134  }
135 
136  G4int markedPin(owner->GetAttributeAsInteger("MarkedPin", 0));
137 
138  if (markedPin<0 || markedPin>(holesAlongWidth+holesAlongHeight)*2)
139  {
140   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Marked pin outside the range." << G4endl;
141   return 0;
142  }
143 
144  G4double markedPinRadius;
145  G4double markedPinStep;
146 
147  if (markedPin>0)
148  {
149   markedPinRadius=owner->GetAttributeAsMeasure("MarkedPinRadius", "Length", -1.);
150   if (markedPinRadius<0)
151   {
152    G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"MarkedPinRadius\" attribute not defined." << G4endl;
153    return 0;
154   }
155 
156   markedPinStep=owner->GetAttributeAsMeasure("MarkedPinStep", "Length", -1.);
157   if (markedPinStep<0)
158   {
159    G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"MarkedPinStep\" attribute not defined." << G4endl;
160    return 0;
161   }
162  }
163 
164  G4double groundWidth(owner->GetAttributeAsMeasure("GroundWidth", "Length", -1.));
165  if (groundWidth<0)
166  {
167   groundWidth=owner->GetAttributeAsDouble("GroundScaleWidth", -1.);
168   
169   if (groundWidth<0)
170   {
171    G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Neither \"GroundWidth\" nor \"GroundScaleWidth\" attributes are defined." << G4endl;
172    return 0;
173   }
174   
175   groundWidth*=width;
176  }
177 
178  if (width<groundWidth)
179  {
180   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Ground width exceeds layer width." << G4endl;
181   return 0;
182  }
183 
184  G4double groundHeight(owner->GetAttributeAsMeasure("GroundHeight", "Length", -1.));
185  if (groundHeight<0)
186  {
187   groundHeight=owner->GetAttributeAsDouble("GroundScaleHeight", -1.);
188   
189   if (groundHeight<0)
190   {
191    G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Neither \"GroundHeight\" nor \"GroundScaleHeight attributes are defined." << G4endl;
192    return 0;
193   }
194   
195   groundHeight*=height;
196  }
197 
198  if (height<groundHeight)
199  {
200   G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Ground height exceeds layer height." << G4endl;
201   return 0;
202  }
203 
204  G4Material * material(owner->GetMaterial("GroundMaterial"));
205  if (!material)
206   return 0;
207 
208  visAttributes=owner->AllocateVisAttributes("GroundVisAttributes", material);
209 
210  RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList());
211 
212  if (list==0)
213   return 0;
214   
215  G4int n(list->GetNItems());
216 
217  if (n==0)
218  {
219   delete list;
220   return 0;
221  }
222 
223  RadmonDetectorLayerVolumeItem * item;
224  RadmonDetectorLayerVolumeItem * motherItem;
225 
226  while (n>0)
227  {
228   n--;
229
230   item=list->GetItem(n);
231   if (item->GetMotherVolumeItem()==0)
232   {
233    motherItem=item;
234    break;
235   }
236  }
237
238  if (!motherItem)
239   G4Exception("RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: No mother volume found.");
240
241  intersection.Initialize(motherItem);
242 
243  G4bool markAlongWidth;
244  G4ThreeVector offset;
245 
246  if (markedPin==0)
247   markAlongWidth=true;
248  else if (markedPin <= holesAlongWidth*2)
249  {
250   markAlongWidth=true;
251 
252   G4double size((height-groundHeight)/2.-markedPinStep);
253 
254   box=new G4Box("Mark", holesRadius, size/2., thickness/2.);
255   tub=new G4Tubs("Hole", 0, markedPinRadius, (thickness/2.)*1.01, 0, 360.*deg);
256   
257   G4ThreeVector offset2;
258   offset2.setX(0);
259   offset2.setY(size/2);
260   offset2.setZ(0.);
261
262   offset.setX((fullHolesStep/2.)*static_cast<G4double>(holesAlongWidth-1)-fullHolesStep*((markedPin-1)/2));
263   offset.setY(height/2.-size/2-markedPinStep);
264   offset.setZ(0.);
265   
266   if (markedPin%2!=1)
267   {
268    offset.setY(-offset.getY());
269    offset2.setY(-offset2.getY());
270   }
271   
272   G4VSolid * solid(new G4SubtractionSolid("Mark - Hole", box, tub, &identity, offset2));
273   
274   item=list->AppendItem();
275   item->SetSolid(intersection.ApplyTo(solid, offset, true, true));
276   item->SetAttributes(visAttributes);
277   item->SetMaterial(material);
278   item->SetName("Mark");
279   item->SetMotherVolumeItem(motherItem);
280  }
281  else
282  {
283   markAlongWidth=false;
284 
285   G4double size((width-groundWidth)/2.-markedPinStep);
286 
287   box=new G4Box("Mark", size/2., holesRadius, thickness/2.);
288   tub=new G4Tubs("Hole", 0, markedPinRadius, (thickness/2.)*1.01, 0, 360.*deg);
289   
290   G4ThreeVector offset2;
291   offset2.setX(size/2);
292   offset2.setY(0);
293   offset2.setZ(0.);
294
295   offset.setX(width/2.-size/2-markedPinStep);
296   offset.setY((fullHolesStep/2.)*static_cast<G4double>(holesAlongHeight-1)-fullHolesStep*((markedPin-1)/2-holesAlongWidth));
297   offset.setZ(0.);
298   
299   if (markedPin%2!=1)
300   {
301    offset.setX(-offset.getX());
302    offset2.setX(-offset2.getX());
303   }
304
305   G4VSolid * solid(new G4SubtractionSolid("Mark - Hole", box, tub, &identity, offset2));
306   
307   item=list->AppendItem();
308   item->SetSolid(intersection.ApplyTo(solid, offset, true, true));
309   item->SetAttributes(visAttributes);
310   item->SetMaterial(material);
311   item->SetName("Mark");
312   item->SetMotherVolumeItem(motherItem);
313  }
314 
315  if (markAlongWidth)
316  {
317   G4Box * thick(new G4Box("Mark", (width-groundWidth)/4., holesStep/2., thickness/2.));
318   
319   offset.setX((groundWidth+width)/4.);
320   offset.setY(0.);
321   offset.setZ(0.);
322   
323   item=list->AppendItem();
324   item->SetSolid(intersection.ApplyTo(thick, offset, true, true));
325   item->SetAttributes(visAttributes);
326   item->SetMaterial(material);
327   item->SetName("Mark");
328   item->SetMotherVolumeItem(motherItem);
329
330   offset.setX(-offset.getX());
331   
332   item=list->AppendItem();
333   item->SetSolid(intersection.ApplyTo(thick, offset, false, true));
334   item->SetAttributes(visAttributes);
335   item->SetMaterial(material);
336   item->SetName("Mark");
337   item->SetMotherVolumeItem(motherItem);
338  }
339  else
340  {
341   G4Box * thick(new G4Box("Mark", holesStep/2., (height-groundHeight)/4., thickness/2.));
342   
343   offset.setX(0.);
344   offset.setY((groundHeight-height)/4.);
345   offset.setZ(0.);
346   
347   item=list->AppendItem();
348   item->SetSolid(intersection.ApplyTo(thick, offset, true, true));
349   item->SetAttributes(visAttributes);
350   item->SetMaterial(material);
351   item->SetName("Mark");
352   item->SetMotherVolumeItem(motherItem);
353
354   offset.setY(-offset.getY());
355   
356   item=list->AppendItem();
357   item->SetSolid(intersection.ApplyTo(thick, offset, false, true));
358   item->SetAttributes(visAttributes);
359   item->SetMaterial(material);
360   item->SetName("Mark");
361   item->SetMotherVolumeItem(motherItem);
362  }
363
364  return list;
365 }
366#endif /* RADMONTDETECTORVOLUMESWITHKEYMARKSDECORATOR_HH */
367 
Note: See TracBrowser for help on using the repository browser.