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

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

update

File size: 9.4 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:     RadmonTDetectorVolumesWithTracksDecorator.icc
28// Creation date: Sep 2005
29// Main author:   Riccardo Capra <capra@ge.infn.it>
30//
31// Id:            $Id: RadmonTDetectorVolumesWithTracksDecorator.icc,v 1.1.2.2 2006/06/29 16:12:50 gunter Exp $
32// Tag:           $Name: geant4-09-01-patch-02 $
33//
34
35#ifndef   RADMONTDETECTORVOLUMESWITHTRACKSDECORATOR_HH
36 #error "RadmonTDetectorVolumesWithTracksDecorator.icc cannot be included directly. Please use RadmonTDetectorVolumesWithTracksDecorator.hh"
37#else  /* RADMONTDETECTORVOLUMESWITHTRACKSDECORATOR_HH */
38 // Include files
39 #include "RadmonVDetectorLabelledEntityConstructor.hh"
40 #include "RadmonDetectorLayerVolumesList.hh"
41 #include "RadmonDetectorLayerVolumeItem.hh"
42 #include "G4Trap.hh"
43 #include "G4UIcommand.hh"
44 
45 template <class LayerVolumesComponent>
46                                                RadmonTDetectorVolumesWithTracksDecorator<LayerVolumesComponent> :: RadmonTDetectorVolumesWithTracksDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor)
47 :
48  owner(constructor),
49  component(constructor),
50  visAttributes(0)
51 {
52 }
53 
54 
55 
56 template <class LayerVolumesComponent>
57                                                RadmonTDetectorVolumesWithTracksDecorator<LayerVolumesComponent> :: ~RadmonTDetectorVolumesWithTracksDecorator()
58 {
59  delete visAttributes;
60 }
61 
62 
63 
64 
65 
66 template <class LayerVolumesComponent>
67 RadmonDetectorLayerVolumesList *               RadmonTDetectorVolumesWithTracksDecorator<LayerVolumesComponent> :: GenerateVolumesList(void)
68 {
69  G4double width(owner->GetWidth());
70  if (width<0)
71   return 0;
72
73  G4double height(owner->GetHeight());
74  if (height<0)
75   return 0;
76 
77  G4double thickness(owner->GetThickness());
78  if (thickness<0)
79   return 0;
80 
81  G4int holesAlongWidth(owner->GetAttributeAsInteger("HolesAlongWidth", -1));
82  if (holesAlongWidth<0)
83  {
84   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: \"HolesAlongWidth\" attribute not defined." << G4endl;
85   return 0;
86  }
87
88  G4int holesAlongHeight(owner->GetAttributeAsInteger("HolesAlongHeight", -1));
89  if (holesAlongHeight<0)
90  {
91   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: \"HolesAlongHeight\" attribute not defined." << G4endl;
92   return 0;
93  }
94 
95  if ((holesAlongWidth+holesAlongHeight)<=0)
96  {
97   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: Both \"HolesAlongHeight\" and \"HolesAlongHeight\" attributes are 0." << G4endl;
98   return 0;
99  }
100
101  G4double holesRadius(owner->GetAttributeAsMeasure("HolesRadius", "Length", -1.));
102  if (holesRadius<0)
103  {
104   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: \"HolesRadius\" attribute not defined." << G4endl;
105   return 0;
106  }
107 
108  G4double holesStep(owner->GetAttributeAsMeasure("HolesStep", "Length", -1.));
109  if (holesStep<0)
110  {
111   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: \"HolesStep\" attribute not defined." << G4endl;
112   return 0;
113  }
114 
115  G4double fullHolesStep(holesRadius*2.+holesStep);
116 
117  if (fullHolesStep*static_cast<G4double>(holesAlongWidth-1)>width || fullHolesStep>width)
118  {
119   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: Holes parameters does not fit along width." << G4endl;
120   return 0;
121  }
122 
123  if (fullHolesStep*static_cast<G4double>(holesAlongHeight-1)>height || fullHolesStep>height)
124  {
125   G4cout << "RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: Holes parameters does not fit along height." << G4endl;
126   return 0;
127  }
128 
129  G4Material * material(owner->GetMaterial("TracksMaterial"));
130  if (!material)
131   return 0;
132 
133  visAttributes=owner->AllocateVisAttributes("TracksVisAttributes", material);
134 
135  RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList());
136 
137  if (list==0)
138   return 0;
139   
140  G4int n(list->GetNItems());
141 
142  if (n==0)
143  {
144   delete list;
145   return 0;
146  }
147 
148  RadmonDetectorLayerVolumeItem * item;
149  RadmonDetectorLayerVolumeItem * motherItem;
150 
151  while (n>0)
152  {
153   n--;
154
155   item=list->GetItem(n);
156   if (item->GetMotherVolumeItem()==0)
157   {
158    motherItem=item;
159    break;
160   }
161  }
162
163  if (!motherItem)
164   G4Exception("RadmonTDetectorVolumesWithTracksDecorator::GenerateVolumesList: No mother volume found.");
165   
166  intersection.Initialize(motherItem);
167
168  const G4double heightFraction(.999);
169
170  G4int index(0);
171  G4String indexStr;
172  fullHolesStep/=2;
173  G4double angle;
174  const G4double pDx2(holesRadius);
175  const G4double pDx1(pDx2*(1.-heightFraction));
176  G4Trap * trap;
177  G4ThreeVector offset((fullHolesStep/2.)*static_cast<G4double>(holesAlongWidth-1), height/4.*(2.-heightFraction), 0);
178  G4int i(holesAlongWidth);
179 
180  while (i>0)
181  {
182   index++;
183   indexStr=G4UIcommand::ConvertToString(index);
184   
185   if (offset.getY()>=0)
186   {
187    angle=90.*deg-offset.getPhi();
188    //                                pDz           pTheta  pPhi    pDy1                      pDx1  pDx2  pAlp1
189    trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, height/4.*heightFraction, pDx1, pDx2, angle,
190    //                                                              pDy2                      pDx3  pDx4  pAlp2
191                                                                    height/4.*heightFraction, pDx1, pDx2, angle);
192   }
193   else
194   {
195    angle=-90*deg-offset.getPhi();
196    //                                pDz           pTheta  pPhi    pDy1                      pDx1  pDx2  pAlp1
197    trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, height/4.*heightFraction, pDx2, pDx1, angle,
198    //                                                              pDy2                      pDx3  pDx4  pAlp2
199                                                                    height/4.*heightFraction, pDx2, pDx1, angle);
200   }
201
202   item=list->AppendItem();
203   item->SetSolid(intersection.ApplyTo(trap, offset, true, true));
204   item->SetAttributes(visAttributes);
205   item->SetMaterial(material);
206   item->SetName("Track"+indexStr);
207   item->SetMotherVolumeItem(motherItem);
208
209   offset.setY(-offset.getY());
210   if (offset.getY()>=0)
211   {
212    offset.setX(offset.getX()-fullHolesStep);
213    i--;
214   }
215  }
216
217  G4RotationMatrix rotation(G4RotationMatrix::IDENTITY);
218  rotation.setDelta(90*deg);
219
220  offset.setX(width/4.*(2.-heightFraction));
221  offset.setY((fullHolesStep/2.)*static_cast<G4double>(holesAlongHeight-1));
222  i=holesAlongHeight;
223 
224  while (i>0)
225  {
226   index++;
227   indexStr=G4UIcommand::ConvertToString(index);
228   
229   if (offset.getX()>=0)
230   {
231    angle=-offset.getPhi();
232    //                                pDz           pTheta  pPhi    pDy1                     pDx1  pDx2  pAlp1
233    trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, width/4.*heightFraction, pDx1, pDx2, angle,
234    //                                                              pDy2                     pDx3  pDx4  pAlp2
235                                                                    width/4.*heightFraction, pDx1, pDx2, angle);
236   }
237   else
238   {
239    angle=-offset.getPhi();
240    //                                pDz           pTheta  pPhi    pDy1                     pDx1  pDx2  pAlp1
241    trap=new G4Trap("Track"+indexStr, thickness/2., 0.*deg, 0.*deg, width/4.*heightFraction, pDx2, pDx1, angle,
242    //                                                              pDy2                     pDx3  pDx4  pAlp2
243                                                                    width/4.*heightFraction, pDx2, pDx1, angle);
244   }
245
246   item=list->AppendItem();
247   item->SetSolid(intersection.ApplyTo(trap, rotation, offset, true, true));
248   item->SetAttributes(visAttributes);
249   item->SetMaterial(material);
250   item->SetName("Track"+indexStr);
251   item->SetMotherVolumeItem(motherItem);
252
253   offset.setX(-offset.getX());
254   if (offset.getX()>=0)
255   {
256    offset.setY(offset.getY()-fullHolesStep);
257    i--;
258   }
259  }
260 
261  return list;
262 }
263#endif /* RADMONTDETECTORVOLUMESWITHTRACKSDECORATOR_HH */
264 
Note: See TracBrowser for help on using the repository browser.