GEARS
Geant4 Example Application with Rich features and Small footprints
Public Member Functions | List of all members
Detector Class Reference

Construct detector geometry. More...

Inheritance diagram for Detector:
Inheritance graph
[legend]
Collaboration diagram for Detector:
Collaboration graph
[legend]

Public Member Functions

 Detector ()
 
 ~Detector ()
 
G4VPhysicalVolume * Construct ()
 called at /run/initialize More...
 
void SetNewValue (G4UIcommand *cmd, G4String value)
 for G4UI More...
 

Detailed Description

Construct detector geometry.

This uses two types of instructions to construct a detector:

It won't work together with HP neutron simulation if Geant4 version is lower than 10 because of this bug: http://hypernews.slac.stanford.edu/HyperNews/geant4/get/hadronprocess/1242.html?inline=-1

Definition at line 413 of file gears.cc.

Constructor & Destructor Documentation

◆ Detector()

Detector::Detector ( )

Definition at line 429 of file gears.cc.

429  : G4VUserDetectorConstruction(), G4UImessenger(), fWorld(0)
430 {
431 #ifdef hasGDML
432  fCmdOut = new G4UIcmdWithAString("/geometry/export",this);
433  fCmdOut->SetGuidance("Export geometry gdml file name");
434  fCmdOut->SetParameterName("gdml geometry output",false);
435  fCmdOut->AvailableForStates(G4State_Idle);
436 #else
437  fCmdOut=0;
438 #endif
439 
440  fCmdSrc = new G4UIcmdWithAString("/geometry/source",this);
441  fCmdSrc->SetGuidance("Set geometry source file name");
442  fCmdSrc->SetParameterName("text geometry input",false);
443  fCmdSrc->AvailableForStates(G4State_PreInit);
444 
445  fCmdSetB = new G4UIcmdWith3VectorAndUnit("/geometry/SetB",this);
446  fCmdSetB->SetGuidance("Set uniform magnetic field value.");
447  fCmdSetB->SetParameterName("Bx", "By", "Bz", false);
448  fCmdSetB->SetUnitCategory("Magnetic flux density");
449 }

◆ ~Detector()

Detector::~Detector ( )
inline

Definition at line 417 of file gears.cc.

417 { delete fCmdSetB; delete fCmdSrc; delete fCmdOut; }

Member Function Documentation

◆ Construct()

G4VPhysicalVolume * Detector::Construct ( )

called at /run/initialize

Definition at line 493 of file gears.cc.

494 {
495  if (fWorld==NULL) {
496  G4cout<<"GEARS: no detector specified, set to a 10x10x10 m^3 box."<<G4endl;
497  auto box = new G4Box("hall", 5*CLHEP::m, 5*CLHEP::m, 5*CLHEP::m);
498  G4NistManager *nist = G4NistManager::Instance();
499  G4Material *vacuum = nist->FindOrBuildMaterial("G4_Galactic");
500  auto v = new G4LogicalVolume(box, vacuum, "hall");
501  fWorld = new G4PVPlacement(0, G4ThreeVector(), v, "hall", 0, 0, 0);
502  }
503  return fWorld;
504 }

◆ SetNewValue()

void Detector::SetNewValue ( G4UIcommand *  cmd,
G4String  value 
)

for G4UI

Definition at line 458 of file gears.cc.

459 {
460  if (cmd==fCmdSetB) {
461  auto field = new G4UniformMagField(0,0,0);
462  field->SetFieldValue(fCmdSetB->GetNew3VectorValue(value));
463  G4FieldManager* mgr =
464  G4TransportationManager::GetTransportationManager()->GetFieldManager();
465  mgr->SetDetectorField(field);
466  mgr->CreateChordFinder(field);
467  G4cout<<"GEARS: Magnetic field is set to "<<value<<G4endl;
468 #ifdef hasGDML
469  } else if(cmd==fCmdOut) {
470  G4GDMLParser paser;
471  paser.Write(value,fWorld);
472 #endif
473  } else { // cmd==fCmdSrc
474  if (value.substr(value.length()-4)!="gdml") { // text geometry input
475  G4tgbVolumeMgr* mgr = G4tgbVolumeMgr::GetInstance();
476  mgr->AddTextFile(value);
477  auto tgb = new TextDetectorBuilder;
478  mgr->SetDetectorBuilder(tgb);
479  fWorld = mgr->ReadAndConstructDetector();
480 #ifdef hasGDML
481  } else { // GDML input
482  G4GDMLParser parser;
483  parser.Read(value);
484  fWorld=parser.GetWorldVolume();
485 #endif
486  }
487  }
488 }
Construct detector based on text geometry description.
Definition: gears.cc:328

The documentation for this class was generated from the following file: