diff --git a/CMakeLists.txt b/CMakeLists.txt index 80139f99e85c4bf937de40c9d5a5f7f750d5c8e5..104753703c0c7ce456d764625615f2395b09c0ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ TARGET_LINK_LIBRARIES(plotHisto ${ROOT_LIBRARIES}) set(lightGuide_SCRIPTS vis.mac run1.mac + models.mac ) foreach(_script ${lightGuide_SCRIPTS}) diff --git a/include/DetectorConstruction.hh b/include/DetectorConstruction.hh index df1fd010717cc430adde0b0c5d3991b5d7a061d7..7bf50ccfc051896c5ee55a518a5f741ee220644a 100644 --- a/include/DetectorConstruction.hh +++ b/include/DetectorConstruction.hh @@ -38,6 +38,7 @@ #include "G4LogicalVolume.hh" #include "G4VUserDetectorConstruction.hh" #include "G4GDMLParser.hh" +#include "G4RunManager.hh" #include "Materials.hh" #include "DetectorMessenger.hh" @@ -62,6 +63,7 @@ class DetectorConstruction : public G4VUserDetectorConstruction void SetSurfaceType (const G4SurfaceType type); void SetSurfaceModel (const G4OpticalSurfaceModel model); void AddSurfaceMPV (const char* c, G4MaterialPropertyVector* mpv); + void AddGasMPV (const char* c, G4MaterialPropertyVector* mpv); private: @@ -91,9 +93,11 @@ class DetectorConstruction : public G4VUserDetectorConstruction G4RotationMatrix* m_rotation; Materials* materials; - G4Material* filler; + G4Material* m_filler; + G4MaterialPropertiesTable* m_GasMPT; G4GDMLParser m_Parser; + G4RunManager* m_runMan; DetectorMessenger* m_DetectorMessenger; }; diff --git a/include/DetectorMessenger.hh b/include/DetectorMessenger.hh index 714f4149870ca621a6f63661a81c1191c9b9029e..25ea192b8ad972f77c9c2142dedc421320561ab5 100644 --- a/include/DetectorMessenger.hh +++ b/include/DetectorMessenger.hh @@ -58,6 +58,8 @@ class DetectorMessenger: public G4UImessenger{ DetectorConstruction* fDetector; G4UIdirectory* flightGuideDir; + G4UIdirectory* fSurfaceDir; + G4UIdirectory* fModelDir; // the surface G4UIcmdWithAString* fSurfaceTypeCmd; @@ -65,6 +67,7 @@ class DetectorMessenger: public G4UImessenger{ G4UIcmdWithAString* fSurfaceModelCmd; G4UIcmdWithADouble* fSurfaceSigmaAlphaCmd; G4UIcmdWithAString* fSurfaceMatPropVectorCmd; + G4UIcmdWithAString* fGasPropVectorCmd; G4UIcmdWithAString* fModelCmd; G4UIcmdWith3VectorAndUnit* fModelRotationCmd; G4UIcmdWith3VectorAndUnit* fModelTranslationCmd; diff --git a/models.mac b/models.mac new file mode 100644 index 0000000000000000000000000000000000000000..c0fb7fee0f82b9cf7fd2554b730a9eddc6572633 --- /dev/null +++ b/models.mac @@ -0,0 +1,2 @@ +/lightGuide/model/CADmodel models/Winston_cone.stl +/lightGuide/model/rotate -90 0 90 diff --git a/src/DetectorConstruction.cc b/src/DetectorConstruction.cc index aebce411336f0b18340c4d456f069afa8c48b48c..3ab439b5b5ae0ce359953a79da102b4a9f5fa4f7 100644 --- a/src/DetectorConstruction.cc +++ b/src/DetectorConstruction.cc @@ -54,7 +54,9 @@ #include "G4SubtractionSolid.hh" #include "G4NistManager.hh" #include "G4VisAttributes.hh" +#include "G4VisExtent.hh" #include "G4Colour.hh" +#include "G4UImanager.hh" #include "G4GDMLParser.hh" @@ -69,10 +71,14 @@ DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction(),m_DetectorMessenger(nullptr){ materials = Materials::getInstance(); m_DetectorMessenger = new DetectorMessenger(this); + m_runMan = G4RunManager::GetRunManager(); m_WorldSizeX = m_WorldSizeZ = 0.25*m; m_WorldSizeY = 0.5*m; + m_filler = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR"); + m_GasMPT = new G4MaterialPropertiesTable(); + m_filler->SetMaterialPropertiesTable(m_GasMPT); } @@ -139,7 +145,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct(){ m_logicHalfWorld = new G4LogicalVolume(m_solidHalfWorld, //solid - Air, //material + m_filler, //material "HalfWorld"); //name m_physHalfWorld = @@ -263,8 +269,7 @@ void DetectorConstruction::SetSurfaceSigmaAlpha(G4double v){ materials->AlSurface->SetSigmaAlpha(v); G4RunManager::GetRunManager()->GeometryHasBeenModified(); - G4cout << "Surface sigma alpha set to: " << materials->AlSurface->GetSigmaAlpha() - << G4endl; + G4cout << "Surface sigma alpha set to: " << materials->AlSurface->GetSigmaAlpha() << G4endl; } /* @@ -279,7 +284,6 @@ void DetectorConstruction::UseCADModel(G4String fileName){ G4double lgHeight = 130*mm; G4String fileType = fileName.substr( fileName.last('.') + 1, fileName.size() - fileName.last('.')); - G4cout << fileType << G4endl; #ifdef CADMESH if(fileType == "stl"){ @@ -290,7 +294,7 @@ void DetectorConstruction::UseCADModel(G4String fileName){ m_logicLightGuide = new G4LogicalVolume(mesh->TessellatedMesh(), //solid - materials->Al, //material + materials->Al, //material "LightGuide"); //name } #endif @@ -303,14 +307,19 @@ void DetectorConstruction::UseCADModel(G4String fileName){ } if(m_logicLightGuide !=0 ){ + G4VisExtent extent = m_logicLightGuide->GetSolid()->GetExtent(); + G4cout << "Xmin, Xmax " << extent.GetXmin() << ", " << extent.GetXmax() << G4endl; + G4cout << "Ymin, Ymax " << extent.GetYmin() << ", " << extent.GetYmax() << G4endl; + G4cout << "Zmin, Zmax " << extent.GetZmin() << ", " << extent.GetZmax() << G4endl; m_physLightGuide = new G4PVPlacement(0, - G4ThreeVector(0,0,lgHeight), + G4ThreeVector(0,-1*m_WorldSizeY/2,0), m_logicLightGuide, "physLightGuide", m_logicHalfWorld, false, 0); + } //----------------- Define Optical Borders -----------------// @@ -325,7 +334,11 @@ void DetectorConstruction::UseCADModel(G4String fileName){ m_physLightGuide, materials->AlSurface ); - G4RunManager::GetRunManager()->GeometryHasBeenModified(); + + m_runMan->GeometryHasBeenModified(); + G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild"); + //m_runMan->BeamOn(1); + G4cout << "Replaced default light guide with CAD model" << G4endl; } /* @@ -348,7 +361,7 @@ void DetectorConstruction::OutputToGDML(G4String fileName){ */ void DetectorConstruction::SetSurfaceFinish(const G4OpticalSurfaceFinish finish){ materials->AlSurface->SetFinish(finish); - G4RunManager::GetRunManager()->GeometryHasBeenModified(); + m_runMan->GeometryHasBeenModified(); } /* @@ -356,14 +369,13 @@ void DetectorConstruction::SetSurfaceFinish(const G4OpticalSurfaceFinish finish) */ void DetectorConstruction::SetSurfaceType(const G4SurfaceType type){ materials->AlSurface->SetType(type); - G4RunManager::GetRunManager()->GeometryHasBeenModified(); + m_runMan->GeometryHasBeenModified(); } /* * */ -void DetectorConstruction::AddSurfaceMPV(const char* c, - G4MaterialPropertyVector* mpv) { +void DetectorConstruction::AddSurfaceMPV(const char* c, G4MaterialPropertyVector* mpv){ mpv->SetSpline(true); materials->GetMPTArray().at(1)->AddProperty(c, mpv); materials->AlSurface->SetMaterialPropertiesTable(materials->GetMPTArray().at(1)); @@ -372,24 +384,39 @@ void DetectorConstruction::AddSurfaceMPV(const char* c, G4cout << "............." << G4endl; } +/* + * + */ +void DetectorConstruction::AddGasMPV(const char* c, G4MaterialPropertyVector* mpv){ + mpv->SetSpline(true); + m_GasMPT->AddProperty(c, mpv); + G4cout << "The MPT for the gas is now: " << G4endl; + m_GasMPT->DumpTable(); + G4cout << "............." << G4endl; +} + /* * */ void DetectorConstruction::SetSurfaceModel(const G4OpticalSurfaceModel model){ materials->AlSurface->SetModel(model); - G4RunManager::GetRunManager()->GeometryHasBeenModified(); + m_runMan->GeometryHasBeenModified(); } /* * */ void DetectorConstruction::SetRotation(G4ThreeVector arg){ - if(!m_rotation) m_rotation = new G4RotationMatrix(); - m_rotation->rotateX(arg.x()); - m_rotation->rotateY(arg.y()); - m_rotation->rotateZ(arg.z()); + if(m_rotation) delete m_rotation; + m_rotation = new G4RotationMatrix(); + + m_rotation->rotateX(arg.x()*deg); + m_rotation->rotateY(arg.y()*deg); + m_rotation->rotateZ(arg.z()*deg); m_physLightGuide->SetRotation(m_rotation); - G4RunManager::GetRunManager()->GeometryHasBeenModified(); + + m_runMan->GeometryHasBeenModified(); + G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild"); } /* @@ -397,5 +424,7 @@ void DetectorConstruction::SetRotation(G4ThreeVector arg){ */ void DetectorConstruction::SetTranslation(G4ThreeVector arg){ m_physLightGuide->SetTranslation(arg); - G4RunManager::GetRunManager()->GeometryHasBeenModified(); + + m_runMan->GeometryHasBeenModified(); + G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild"); } diff --git a/src/DetectorMessenger.cc b/src/DetectorMessenger.cc index 0ff8bc09c83568b283195a0b5773666fcef63b41..36ec9d0e22a7c929f40f23d281f69a16f51ab8be 100644 --- a/src/DetectorMessenger.cc +++ b/src/DetectorMessenger.cc @@ -53,55 +53,71 @@ DetectorMessenger::DetectorMessenger(DetectorConstruction * Det) flightGuideDir = new G4UIdirectory("/lightGuide/"); flightGuideDir->SetGuidance("Parameters for optical simulation."); - fSurfaceTypeCmd = new G4UIcmdWithAString("/lightGuide/surfaceType", this); + fSurfaceDir = new G4UIdirectory("/lightGuide/surface/"); + fSurfaceDir->SetGuidance("Surface parameters for optical simulation."); + + fModelDir = new G4UIdirectory("/lightGuide/model/"); + fModelDir->SetGuidance("Model source, translation and rotation"); + + fSurfaceTypeCmd = new G4UIcmdWithAString("/lightGuide/surface/Type", this); fSurfaceTypeCmd->SetGuidance("Surface type."); fSurfaceTypeCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fSurfaceTypeCmd->SetToBeBroadcasted(false); - fSurfaceFinishCmd = new G4UIcmdWithAString("/lightGuide/surfaceFinish", this); + fSurfaceFinishCmd = new G4UIcmdWithAString("/lightGuide/surface/Finish", this); fSurfaceFinishCmd->SetGuidance("Surface finish."); fSurfaceFinishCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fSurfaceFinishCmd->SetToBeBroadcasted(false); fSurfaceModelCmd = - new G4UIcmdWithAString("/lightGuide/surfaceModel", this); + new G4UIcmdWithAString("/lightGuide/surface/Model", this); fSurfaceModelCmd->SetGuidance("surface model."); fSurfaceModelCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fSurfaceModelCmd->SetToBeBroadcasted(false); fSurfaceSigmaAlphaCmd = - new G4UIcmdWithADouble("/lightGuide/surfaceSigmaAlpha", this); + new G4UIcmdWithADouble("/lightGuide/surface/SigmaAlpha", this); fSurfaceSigmaAlphaCmd->SetGuidance("surface sigma alpha"); fSurfaceSigmaAlphaCmd->SetGuidance(" parameter."); fSurfaceSigmaAlphaCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fSurfaceSigmaAlphaCmd->SetToBeBroadcasted(false); fSurfaceMatPropVectorCmd = - new G4UIcmdWithAString("/lightGuide/surfaceProperty", this); + new G4UIcmdWithAString("/lightGuide/surface/Property", this); fSurfaceMatPropVectorCmd->SetGuidance("Set material property vector"); fSurfaceMatPropVectorCmd->SetGuidance(" for the surface."); fSurfaceMatPropVectorCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fSurfaceMatPropVectorCmd->SetToBeBroadcasted(false); - fModelCmd = new G4UIcmdWithAString("/lightGuide/CADmodel", this); + fGasPropVectorCmd = + new G4UIcmdWithAString("/lightGuide/gasProperty", this); + fGasPropVectorCmd->SetGuidance("Set fill gas property vector"); + fGasPropVectorCmd->AvailableForStates(G4State_PreInit, G4State_Idle); + fGasPropVectorCmd->SetToBeBroadcasted(false); + + fModelCmd = new G4UIcmdWithAString("/lightGuide/model/CADmodel", this); fModelCmd->SetGuidance("CAD model to be used"); fModelCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fModelCmd->SetToBeBroadcasted(false); + fModelCmd->SetDefaultValue("models/Winston_cone.stl"); fModelRotationCmd = - new G4UIcmdWith3VectorAndUnit("/lightGuide/rotate", this); + new G4UIcmdWith3VectorAndUnit("/lightGuide/model/rotate", this); fModelRotationCmd->SetGuidance("Set light guide first rotation"); fModelRotationCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fModelRotationCmd->SetToBeBroadcasted(false); fModelRotationCmd->SetParameterName("rotationX","rotationY","rotationZ",true); - fModelRotationCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.)); - fModelRotationCmd->SetDefaultUnit("deg"); + //fModelRotationCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.)); + //fModelRotationCmd->SetDefaultUnit("deg"); fModelTranslationCmd = - new G4UIcmdWith3VectorAndUnit("/lightGuide/translate", this); + new G4UIcmdWith3VectorAndUnit("/lightGuide/model/translate", this); fModelTranslationCmd->SetGuidance("Set light guide translation"); fModelTranslationCmd->AvailableForStates(G4State_PreInit, G4State_Idle); fModelTranslationCmd->SetToBeBroadcasted(false); + fModelRotationCmd->SetParameterName("X","Y","Z",true); + fModelRotationCmd->SetDefaultValue(G4ThreeVector(0.,0.,0.)); + fModelRotationCmd->SetDefaultUnit("mm"); } @@ -114,6 +130,7 @@ DetectorMessenger::~DetectorMessenger(){ delete fSurfaceModelCmd; delete fSurfaceSigmaAlphaCmd; delete fSurfaceMatPropVectorCmd; + delete fGasPropVectorCmd; delete fModelCmd; delete fModelRotationCmd; delete fModelTranslationCmd; @@ -322,6 +339,29 @@ void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) fDetector->SetSurfaceSigmaAlpha( G4UIcmdWithADouble::GetNewDoubleValue(newValue)); } + // SURFACE PROPERTY + else if (command == fGasPropVectorCmd) { + // Convert string to physics vector + // string format is property name, then pairs of energy, value + // space delimited + G4MaterialPropertyVector* mpv = new G4MaterialPropertyVector(); + G4cout << newValue << G4endl; + std::istringstream instring(newValue); + G4String prop; + instring >> prop; + while (instring) { + G4String tmp; + instring >> tmp; + if (tmp == "") { break; } + G4double en = G4UIcommand::ConvertToDouble(tmp); + instring >> tmp; + G4double val; + val = G4UIcommand::ConvertToDouble(tmp); + mpv->InsertValues(en, val); + } + const char* c = prop.c_str(); + fDetector->AddGasMPV(c, mpv); + } // MODEL LOCATION else if(command == fModelCmd){ fDetector->UseCADModel(newValue);