// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // File name: RadmonTDetectorVolumesWithKeyMarksDecorator.icc // Creation date: Sep 2005 // Main author: Riccardo Capra // // Id: $Id: RadmonTDetectorVolumesWithKeyMarksDecorator.icc,v 1.1.2.2 2006/06/29 16:12:38 gunter Exp $ // Tag: $Name: geant4-09-01-patch-02 $ // #ifndef RADMONTDETECTORVOLUMESWITHKEYMARKSDECORATOR_HH #error "RadmonTDetectorVolumesWithKeyMarksDecorator.icc cannot be included directly. Please use RadmonTDetectorVolumesWithKeyMarksDecorator.hh" #else /* RADMONTDETECTORVOLUMESWITHKEYMARKSDECORATOR_HH */ // Include files #include "RadmonVDetectorLabelledEntityConstructor.hh" #include "RadmonDetectorLayerVolumesList.hh" #include "RadmonDetectorLayerVolumeItem.hh" #include "G4Tubs.hh" #include "G4SubtractionSolid.hh" #include "G4Box.hh" #include "G4UIcommand.hh" template RadmonTDetectorVolumesWithKeyMarksDecorator :: RadmonTDetectorVolumesWithKeyMarksDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor) : owner(constructor), component(constructor), visAttributes(0), box(0), tub(0), identity(G4RotationMatrix::IDENTITY) { } template RadmonTDetectorVolumesWithKeyMarksDecorator :: ~RadmonTDetectorVolumesWithKeyMarksDecorator() { delete box; delete tub; delete visAttributes; } template RadmonDetectorLayerVolumesList * RadmonTDetectorVolumesWithKeyMarksDecorator :: GenerateVolumesList(void) { G4double width(owner->GetWidth()); if (width<0) return 0; G4double height(owner->GetHeight()); if (height<0) return 0; G4double thickness(owner->GetThickness()); if (thickness<0) return 0; G4int holesAlongWidth(owner->GetAttributeAsInteger("HolesAlongWidth", -1)); if (holesAlongWidth<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesAlongWidth\" attribute not defined." << G4endl; return 0; } G4int holesAlongHeight(owner->GetAttributeAsInteger("HolesAlongHeight", -1)); if (holesAlongHeight<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesAlongHeight\" attribute not defined." << G4endl; return 0; } if ((holesAlongWidth+holesAlongHeight)<=0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Both \"HolesAlongHeight\" and \"HolesAlongHeight\" attributes are 0." << G4endl; return 0; } G4double holesRadius(owner->GetAttributeAsMeasure("HolesRadius", "Length", -1.)); if (holesRadius<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesRadius\" attribute not defined." << G4endl; return 0; } G4double holesStep(owner->GetAttributeAsMeasure("HolesStep", "Length", -1.)); if (holesStep<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"HolesStep\" attribute not defined." << G4endl; return 0; } G4double fullHolesStep(holesRadius*2.+holesStep); if (fullHolesStep*static_cast(holesAlongWidth-1)>width || fullHolesStep>width) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Holes parameters does not fit along width." << G4endl; return 0; } if (fullHolesStep*static_cast(holesAlongHeight-1)>height || fullHolesStep>height) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Holes parameters does not fit along height." << G4endl; return 0; } G4int markedPin(owner->GetAttributeAsInteger("MarkedPin", 0)); if (markedPin<0 || markedPin>(holesAlongWidth+holesAlongHeight)*2) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Marked pin outside the range." << G4endl; return 0; } G4double markedPinRadius; G4double markedPinStep; if (markedPin>0) { markedPinRadius=owner->GetAttributeAsMeasure("MarkedPinRadius", "Length", -1.); if (markedPinRadius<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"MarkedPinRadius\" attribute not defined." << G4endl; return 0; } markedPinStep=owner->GetAttributeAsMeasure("MarkedPinStep", "Length", -1.); if (markedPinStep<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: \"MarkedPinStep\" attribute not defined." << G4endl; return 0; } } G4double groundWidth(owner->GetAttributeAsMeasure("GroundWidth", "Length", -1.)); if (groundWidth<0) { groundWidth=owner->GetAttributeAsDouble("GroundScaleWidth", -1.); if (groundWidth<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Neither \"GroundWidth\" nor \"GroundScaleWidth\" attributes are defined." << G4endl; return 0; } groundWidth*=width; } if (widthGetAttributeAsMeasure("GroundHeight", "Length", -1.)); if (groundHeight<0) { groundHeight=owner->GetAttributeAsDouble("GroundScaleHeight", -1.); if (groundHeight<0) { G4cout << "RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: Neither \"GroundHeight\" nor \"GroundScaleHeight attributes are defined." << G4endl; return 0; } groundHeight*=height; } if (heightGetMaterial("GroundMaterial")); if (!material) return 0; visAttributes=owner->AllocateVisAttributes("GroundVisAttributes", material); RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList()); if (list==0) return 0; G4int n(list->GetNItems()); if (n==0) { delete list; return 0; } RadmonDetectorLayerVolumeItem * item; RadmonDetectorLayerVolumeItem * motherItem; while (n>0) { n--; item=list->GetItem(n); if (item->GetMotherVolumeItem()==0) { motherItem=item; break; } } if (!motherItem) G4Exception("RadmonTDetectorVolumesWithKeyMarksDecorator::GenerateVolumesList: No mother volume found."); intersection.Initialize(motherItem); G4bool markAlongWidth; G4ThreeVector offset; if (markedPin==0) markAlongWidth=true; else if (markedPin <= holesAlongWidth*2) { markAlongWidth=true; G4double size((height-groundHeight)/2.-markedPinStep); box=new G4Box("Mark", holesRadius, size/2., thickness/2.); tub=new G4Tubs("Hole", 0, markedPinRadius, (thickness/2.)*1.01, 0, 360.*deg); G4ThreeVector offset2; offset2.setX(0); offset2.setY(size/2); offset2.setZ(0.); offset.setX((fullHolesStep/2.)*static_cast(holesAlongWidth-1)-fullHolesStep*((markedPin-1)/2)); offset.setY(height/2.-size/2-markedPinStep); offset.setZ(0.); if (markedPin%2!=1) { offset.setY(-offset.getY()); offset2.setY(-offset2.getY()); } G4VSolid * solid(new G4SubtractionSolid("Mark - Hole", box, tub, &identity, offset2)); item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(solid, offset, true, true)); item->SetAttributes(visAttributes); item->SetMaterial(material); item->SetName("Mark"); item->SetMotherVolumeItem(motherItem); } else { markAlongWidth=false; G4double size((width-groundWidth)/2.-markedPinStep); box=new G4Box("Mark", size/2., holesRadius, thickness/2.); tub=new G4Tubs("Hole", 0, markedPinRadius, (thickness/2.)*1.01, 0, 360.*deg); G4ThreeVector offset2; offset2.setX(size/2); offset2.setY(0); offset2.setZ(0.); offset.setX(width/2.-size/2-markedPinStep); offset.setY((fullHolesStep/2.)*static_cast(holesAlongHeight-1)-fullHolesStep*((markedPin-1)/2-holesAlongWidth)); offset.setZ(0.); if (markedPin%2!=1) { offset.setX(-offset.getX()); offset2.setX(-offset2.getX()); } G4VSolid * solid(new G4SubtractionSolid("Mark - Hole", box, tub, &identity, offset2)); item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(solid, offset, true, true)); item->SetAttributes(visAttributes); item->SetMaterial(material); item->SetName("Mark"); item->SetMotherVolumeItem(motherItem); } if (markAlongWidth) { G4Box * thick(new G4Box("Mark", (width-groundWidth)/4., holesStep/2., thickness/2.)); offset.setX((groundWidth+width)/4.); offset.setY(0.); offset.setZ(0.); item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(thick, offset, true, true)); item->SetAttributes(visAttributes); item->SetMaterial(material); item->SetName("Mark"); item->SetMotherVolumeItem(motherItem); offset.setX(-offset.getX()); item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(thick, offset, false, true)); item->SetAttributes(visAttributes); item->SetMaterial(material); item->SetName("Mark"); item->SetMotherVolumeItem(motherItem); } else { G4Box * thick(new G4Box("Mark", holesStep/2., (height-groundHeight)/4., thickness/2.)); offset.setX(0.); offset.setY((groundHeight-height)/4.); offset.setZ(0.); item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(thick, offset, true, true)); item->SetAttributes(visAttributes); item->SetMaterial(material); item->SetName("Mark"); item->SetMotherVolumeItem(motherItem); offset.setY(-offset.getY()); item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(thick, offset, false, true)); item->SetAttributes(visAttributes); item->SetMaterial(material); item->SetName("Mark"); item->SetMotherVolumeItem(motherItem); } return list; } #endif /* RADMONTDETECTORVOLUMESWITHKEYMARKSDECORATOR_HH */