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 430 of file gears.cc.

430  : G4VUserDetectorConstruction(), G4UImessenger(), fWorld(0)
431 {
432 #ifdef hasGDML
433  fCmdOut = new G4UIcmdWithAString("/geometry/export",this);
434  fCmdOut->SetGuidance("Export geometry gdml file name");
435  fCmdOut->SetParameterName("gdml geometry output",false);
436  fCmdOut->AvailableForStates(G4State_Idle);
437 #else
438  fCmdOut=0;
439 #endif
440 
441  fCmdSrc = new G4UIcmdWithAString("/geometry/source",this);
442  fCmdSrc->SetGuidance("Set geometry source file name");
443  fCmdSrc->SetParameterName("text geometry input",false);
444  fCmdSrc->AvailableForStates(G4State_PreInit);
445 
446  fCmdLmt = new G4UIcommand("/tracking/setStepLimit",this);
447  fCmdLmt->SetGuidance("set max step length for a logical volume");
448  fCmdLmt->AvailableForStates(G4State_Idle);
449  G4UIparameter *p0 = new G4UIparameter("logical volume name", 's', false);
450  G4UIparameter *p1 = new G4UIparameter("step length in mm", 'd', false);
451  fCmdLmt->SetParameter(p0); fCmdLmt->SetParameter(p1);
452 
453  fCmdSetB = new G4UIcmdWith3VectorAndUnit("/geometry/SetB",this);
454  fCmdSetB->SetGuidance("Set uniform magnetic field value.");
455  fCmdSetB->SetParameterName("Bx", "By", "Bz", false);
456  fCmdSetB->SetUnitCategory("Magnetic flux density");
457 }

◆ ~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 510 of file gears.cc.

511 {
512  if (fWorld==NULL) {
513  G4cout<<"GEARS: no detector specified, set to a 10x10x10 m^3 box."<<G4endl;
514  auto box = new G4Box("hall", 5*CLHEP::m, 5*CLHEP::m, 5*CLHEP::m);
515  G4NistManager *nist = G4NistManager::Instance();
516  G4Material *vacuum = nist->FindOrBuildMaterial("G4_Galactic");
517  auto v = new G4LogicalVolume(box, vacuum, "hall");
518  fWorld = new G4PVPlacement(0, G4ThreeVector(), v, "hall", 0, 0, 0);
519  }
520  return fWorld;
521 }

◆ SetNewValue()

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

for G4UI

Definition at line 468 of file gears.cc.

469 {
470  if (cmd==fCmdSetB) {
471  auto field = new G4UniformMagField(0,0,0);
472  field->SetFieldValue(fCmdSetB->GetNew3VectorValue(value));
473  G4FieldManager* mgr =
474  G4TransportationManager::GetTransportationManager()->GetFieldManager();
475  mgr->SetDetectorField(field);
476  mgr->CreateChordFinder(field);
477  G4cout<<"GEARS: Magnetic field is set to "<<value<<G4endl;
478 #ifdef hasGDML
479  } else if (cmd==fCmdOut) {
480  G4GDMLParser paser;
481  paser.Write(value, fWorld);
482 #endif
483  } else if (cmd==fCmdLmt) {
484  istringstream iss(value); G4String vlm, limit; iss>>vlm>>limit;
485  auto v = G4LogicalVolumeStore::GetInstance()->GetVolume(vlm);
486  if (v) {
487  v->SetUserLimits(new G4UserLimits(stof(limit)));
488  G4cout<<"GEARS: max step length in "<<vlm<<": "<<limit<<" mm"<<G4endl;
489  }
490  } else { // cmd==fCmdSrc
491  if (value.substr(value.length()-4)!="gdml") { // text geometry input
492  G4tgbVolumeMgr* mgr = G4tgbVolumeMgr::GetInstance();
493  mgr->AddTextFile(value);
494  auto tgb = new TextDetectorBuilder;
495  mgr->SetDetectorBuilder(tgb);
496  fWorld = mgr->ReadAndConstructDetector();
497 #ifdef hasGDML
498  } else { // GDML input
499  G4GDMLParser parser;
500  parser.Read(value);
501  fWorld=parser.GetWorldVolume();
502 #endif
503  }
504  }
505 }
Construct detector based on text geometry description.
Definition: gears.cc:328

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