[807] | 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: RadmonTDetectorCarvedVolumesDecorator.icc |
---|
| 28 | // Creation date: Sep 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonTDetectorCarvedVolumesDecorator.icc,v 1.2.2.2 2006/06/29 16:12:15 gunter Exp $ |
---|
| 32 | // Tag: $Name: geant4-09-01-patch-02 $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | #ifndef RADMONTDETECTORCARVEDVOLUMESDECORATOR_HH |
---|
| 36 | #error "RadmonTDetectorCarvedVolumesDecorator.icc cannot be included directly. Please use RadmonTDetectorCarvedVolumesDecorator.hh" |
---|
| 37 | #else /* RADMONTDETECTORCARVEDVOLUMESDECORATOR_HH */ |
---|
| 38 | // Include files |
---|
| 39 | #include "RadmonVDetectorLabelledEntityConstructor.hh" |
---|
| 40 | #include "RadmonDetectorLayerVolumesList.hh" |
---|
| 41 | #include "RadmonDetectorLayerVolumeItem.hh" |
---|
| 42 | #include "G4VisAttributes.hh" |
---|
| 43 | #include "G4DisplacedSolid.hh" |
---|
| 44 | #include "G4UnionSolid.hh" |
---|
| 45 | #include "G4Tubs.hh" |
---|
| 46 | #include "G4UIcommand.hh" |
---|
| 47 | |
---|
| 48 | template <class LayerVolumesComponent> |
---|
| 49 | RadmonTDetectorCarvedVolumesDecorator<LayerVolumesComponent> :: RadmonTDetectorCarvedVolumesDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor) |
---|
| 50 | : |
---|
| 51 | owner(constructor), |
---|
| 52 | component(constructor), |
---|
| 53 | visAttributes(0), |
---|
| 54 | subtraction(RadmonDetectorLayerVolumeItemSubtraction::rightMinusLeft) |
---|
| 55 | { |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | template <class LayerVolumesComponent> |
---|
| 61 | RadmonTDetectorCarvedVolumesDecorator<LayerVolumesComponent> :: ~RadmonTDetectorCarvedVolumesDecorator() |
---|
| 62 | { |
---|
| 63 | while (! ownedSolids.empty()) |
---|
| 64 | { |
---|
| 65 | delete ownedSolids.top(); |
---|
| 66 | ownedSolids.pop(); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | delete visAttributes; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | template <class LayerVolumesComponent> |
---|
| 77 | RadmonDetectorLayerVolumesList * RadmonTDetectorCarvedVolumesDecorator<LayerVolumesComponent> :: GenerateVolumesList(void) |
---|
| 78 | { |
---|
| 79 | G4double width(owner->GetWidth()); |
---|
| 80 | if (width<0) |
---|
| 81 | return 0; |
---|
| 82 | |
---|
| 83 | G4double height(owner->GetHeight()); |
---|
| 84 | if (height<0) |
---|
| 85 | return 0; |
---|
| 86 | |
---|
| 87 | G4double thickness(owner->GetThickness()); |
---|
| 88 | if (thickness<0) |
---|
| 89 | return 0; |
---|
| 90 | |
---|
| 91 | G4int holesAlongWidth(owner->GetAttributeAsInteger("HolesAlongWidth", -1)); |
---|
| 92 | if (holesAlongWidth<0) |
---|
| 93 | { |
---|
| 94 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: \"HolesAlongWidth\" attribute not defined." << G4endl; |
---|
| 95 | return 0; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | G4int holesAlongHeight(owner->GetAttributeAsInteger("HolesAlongHeight", -1)); |
---|
| 99 | if (holesAlongHeight<0) |
---|
| 100 | { |
---|
| 101 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: \"HolesAlongHeight\" attribute not defined." << G4endl; |
---|
| 102 | return 0; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if ((holesAlongWidth+holesAlongHeight)<=0) |
---|
| 106 | { |
---|
| 107 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: Both \"HolesAlongHeight\" and \"HolesAlongHeight\" attributes are 0." << G4endl; |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | G4double holesRadius(owner->GetAttributeAsMeasure("HolesRadius", "Length", -1.)); |
---|
| 112 | if (holesRadius<0) |
---|
| 113 | { |
---|
| 114 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: \"HolesRadius\" attribute not defined." << G4endl; |
---|
| 115 | return 0; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | G4double holesStep(owner->GetAttributeAsMeasure("HolesStep", "Length", -1.)); |
---|
| 119 | if (holesStep<0) |
---|
| 120 | { |
---|
| 121 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: \"HolesStep\" attribute not defined." << G4endl; |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | G4double fullHolesStep(holesRadius*2.+holesStep); |
---|
| 126 | |
---|
| 127 | if (fullHolesStep*static_cast<G4double>(holesAlongWidth-1)>width || fullHolesStep>width) |
---|
| 128 | { |
---|
| 129 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: Holes parameters does not fit along width." << G4endl; |
---|
| 130 | return 0; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | if (fullHolesStep*static_cast<G4double>(holesAlongHeight-1)>height || fullHolesStep>height) |
---|
| 134 | { |
---|
| 135 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: Holes parameters does not fit along height." << G4endl; |
---|
| 136 | return 0; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | G4Material * material(0); |
---|
| 140 | G4double depositOnHolesThickness(owner->GetAttributeAsMeasure("DepositOnHolesThickness", "Length", -1.)); |
---|
| 141 | if (depositOnHolesThickness>0) |
---|
| 142 | { |
---|
| 143 | if (depositOnHolesThickness>=holesRadius) |
---|
| 144 | { |
---|
| 145 | G4cout << "RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: \"DepositOnHolesThickness\" >= \"HolesRadius\"." << G4endl; |
---|
| 146 | return 0; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | if (depositOnHolesThickness>0) |
---|
| 150 | { |
---|
| 151 | material=owner->GetMaterial("DepositOnHolesMaterial"); |
---|
| 152 | if (!material) |
---|
| 153 | return 0; |
---|
| 154 | |
---|
| 155 | visAttributes=owner->AllocateVisAttributes("DepositOnHolesVisAttributes", material); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | depositOnHolesThickness=0*mm; |
---|
| 160 | |
---|
| 161 | RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList()); |
---|
| 162 | |
---|
| 163 | if (list==0) |
---|
| 164 | return 0; |
---|
| 165 | |
---|
| 166 | G4int nItems(list->GetNItems()); |
---|
| 167 | |
---|
| 168 | if (nItems==0) |
---|
| 169 | { |
---|
| 170 | delete list; |
---|
| 171 | return 0; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | G4Tubs * holeCylinder(new G4Tubs("SingleHole", 0, holesRadius-depositOnHolesThickness, (thickness/2.)*1.01, 0, 360.*deg)); |
---|
| 175 | ownedSolids.push(holeCylinder); |
---|
| 176 | |
---|
| 177 | G4ThreeVector offset((fullHolesStep/2.)*static_cast<G4double>(holesAlongWidth-1), height/2., 0); |
---|
| 178 | G4VSolid * displacedHole(0); |
---|
| 179 | G4VSolid * holes(0); |
---|
| 180 | G4int i(holesAlongWidth); |
---|
| 181 | |
---|
| 182 | identity=G4RotationMatrix::IDENTITY; |
---|
| 183 | |
---|
| 184 | G4int index(0); |
---|
| 185 | G4String indexStr; |
---|
| 186 | |
---|
| 187 | while (i>0) |
---|
| 188 | { |
---|
| 189 | index++; |
---|
| 190 | indexStr=G4UIcommand::ConvertToString(index); |
---|
| 191 | |
---|
| 192 | displacedHole=new G4DisplacedSolid("DisplacedSingleHole"+indexStr, holeCylinder, &identity, offset); |
---|
| 193 | ownedSolids.push(displacedHole); |
---|
| 194 | |
---|
| 195 | if (holes) |
---|
| 196 | { |
---|
| 197 | holes=new G4UnionSolid("DisplacedHoles"+indexStr, holes, displacedHole); |
---|
| 198 | ownedSolids.push(holes); |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | holes=displacedHole; |
---|
| 202 | |
---|
| 203 | offset.setY(-offset.getY()); |
---|
| 204 | if (offset.getY()>=0) |
---|
| 205 | { |
---|
| 206 | offset.setX(offset.getX()-fullHolesStep); |
---|
| 207 | i--; |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | offset.setX(width/2.); |
---|
| 212 | offset.setY((fullHolesStep/2.)*static_cast<G4double>(holesAlongHeight-1)); |
---|
| 213 | i=holesAlongHeight; |
---|
| 214 | |
---|
| 215 | while (i>0) |
---|
| 216 | { |
---|
| 217 | index++; |
---|
| 218 | indexStr=G4UIcommand::ConvertToString(index); |
---|
| 219 | |
---|
| 220 | displacedHole=new G4DisplacedSolid("DisplacedSingleHole"+indexStr, holeCylinder, &identity, offset); |
---|
| 221 | ownedSolids.push(displacedHole); |
---|
| 222 | |
---|
| 223 | if (holes) |
---|
| 224 | { |
---|
| 225 | holes=new G4UnionSolid("DisplacedHoles"+indexStr, holes, displacedHole); |
---|
| 226 | ownedSolids.push(holes); |
---|
| 227 | } |
---|
| 228 | else |
---|
| 229 | holes=displacedHole; |
---|
| 230 | |
---|
| 231 | offset.setX(-offset.getX()); |
---|
| 232 | if (offset.getX()>=0) |
---|
| 233 | { |
---|
| 234 | offset.setY(offset.getY()-fullHolesStep); |
---|
| 235 | i--; |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | RadmonDetectorLayerVolumeItem * item; |
---|
| 240 | RadmonDetectorLayerVolumeItem * motherItem; |
---|
| 241 | subtraction.Initialize(holes, false); |
---|
| 242 | |
---|
| 243 | while (nItems>0) |
---|
| 244 | { |
---|
| 245 | nItems--; |
---|
| 246 | |
---|
| 247 | item=list->GetItem(nItems); |
---|
| 248 | |
---|
| 249 | if (item->GetMotherVolumeItem()==0) |
---|
| 250 | motherItem=item; |
---|
| 251 | |
---|
| 252 | subtraction.ApplyTo(item); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | if (!motherItem) |
---|
| 256 | G4Exception("RadmonTDetectorCarvedVolumesDecorator::GenerateVolumesList: No mother volume found."); |
---|
| 257 | |
---|
| 258 | if (material) |
---|
| 259 | { |
---|
| 260 | intersection.Initialize(motherItem); |
---|
| 261 | |
---|
| 262 | G4Tubs * depositTub(new G4Tubs("SingleDeposit", holesRadius-depositOnHolesThickness, holesRadius, thickness/2., 0, 360.*deg)); |
---|
| 263 | ownedSolids.push(depositTub); |
---|
| 264 | |
---|
| 265 | offset.setX((fullHolesStep/2.)*static_cast<G4double>(holesAlongWidth-1)); |
---|
| 266 | offset.setY(height/2.); |
---|
| 267 | offset.setZ(0.); |
---|
| 268 | |
---|
| 269 | i=holesAlongWidth; |
---|
| 270 | index=0; |
---|
| 271 | |
---|
| 272 | while (i>0) |
---|
| 273 | { |
---|
| 274 | index++; |
---|
| 275 | indexStr=G4UIcommand::ConvertToString(index); |
---|
| 276 | |
---|
| 277 | item=list->AppendItem(); |
---|
| 278 | item->SetSolid(intersection.ApplyTo(depositTub, offset, false, true)); |
---|
| 279 | item->SetAttributes(visAttributes); |
---|
| 280 | item->SetMaterial(material); |
---|
| 281 | item->SetName("DepositOnHole"+indexStr); |
---|
| 282 | item->SetMotherVolumeItem(motherItem); |
---|
| 283 | |
---|
| 284 | offset.setY(-offset.getY()); |
---|
| 285 | if (offset.getY()>=0) |
---|
| 286 | { |
---|
| 287 | offset.setX(offset.getX()-fullHolesStep); |
---|
| 288 | i--; |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | offset.setX(width/2.); |
---|
| 293 | offset.setY((fullHolesStep/2.)*static_cast<G4double>(holesAlongHeight-1)); |
---|
| 294 | i=holesAlongHeight; |
---|
| 295 | |
---|
| 296 | while (i>0) |
---|
| 297 | { |
---|
| 298 | index++; |
---|
| 299 | indexStr=G4UIcommand::ConvertToString(index); |
---|
| 300 | |
---|
| 301 | item=list->AppendItem(); |
---|
| 302 | item->SetSolid(intersection.ApplyTo(depositTub, offset, false, true)); |
---|
| 303 | item->SetAttributes(visAttributes); |
---|
| 304 | item->SetMaterial(material); |
---|
| 305 | item->SetName("DepositOnHole"+indexStr); |
---|
| 306 | item->SetMotherVolumeItem(motherItem); |
---|
| 307 | |
---|
| 308 | offset.setX(-offset.getX()); |
---|
| 309 | if (offset.getX()>=0) |
---|
| 310 | { |
---|
| 311 | offset.setY(offset.getY()-fullHolesStep); |
---|
| 312 | i--; |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | return list; |
---|
| 318 | } |
---|
| 319 | #endif /* RADMONTDETECTORCARVEDVOLUMESDECORATOR_HH */ |
---|