CaptWorldBuilder.cc
Go to the documentation of this file.
1 #include "EDepSimBuilder.hh"
2 #include "CaptWorldBuilder.hh"
3 #include "CaptCryostatBuilder.hh"
4 
5 #include <globals.hh>
6 #include <G4Material.hh>
7 #include <G4LogicalVolume.hh>
8 #include <G4VPhysicalVolume.hh>
9 #include <G4PVPlacement.hh>
10 #include <G4VisAttributes.hh>
11 #include <G4VisExtent.hh>
12 
13 #include <G4SystemOfUnits.hh>
14 #include <G4PhysicalConstants.hh>
15 
16 #include <G4Box.hh>
17 #include <G4Tubs.hh>
18 #include <G4SubtractionSolid.hh>
19 
20 #include <EDepSimLog.hh>
21 
23  : public EDepSim::BuilderMessenger {
24 private:
26  G4UIcmdWithADoubleAndUnit* fLengthCMD;
27  G4UIcmdWithADoubleAndUnit* fWidthCMD;
28  G4UIcmdWithADoubleAndUnit* fHeightCMD;
29 
30 public:
32  : EDepSim::BuilderMessenger(c,"Control the world geometry."),
33  fBuilder(c) {
34  fLengthCMD
35  = new G4UIcmdWithADoubleAndUnit(CommandName("length"),this);
36  fLengthCMD->SetGuidance("Set the length of the world.");
37  fLengthCMD->SetParameterName("Length",false);
38  fLengthCMD->SetUnitCategory("Length");
39 
40  fWidthCMD = new G4UIcmdWithADoubleAndUnit(CommandName("width"),this);
41  fWidthCMD->SetGuidance("Set the width of the world.");
42  fWidthCMD->SetParameterName("Width",false);
43  fWidthCMD->SetUnitCategory("Length");
44 
45  fHeightCMD = new G4UIcmdWithADoubleAndUnit(CommandName("height"),this);
46  fHeightCMD->SetGuidance("Set the height of the world.");
47  fHeightCMD->SetParameterName("Height",false);
48  fHeightCMD->SetUnitCategory("Length");
49  };
50 
51  virtual ~CaptWorldMessenger() {
52  delete fLengthCMD;
53  delete fWidthCMD;
54  delete fHeightCMD;
55  };
56 
57  void SetNewValue(G4UIcommand *cmd, G4String val) {
58  if (cmd==fLengthCMD) {
59  fBuilder->SetLength(fLengthCMD->GetNewDoubleValue(val));
60  }
61  else if (cmd==fWidthCMD) {
62  fBuilder->SetWidth(fWidthCMD->GetNewDoubleValue(val));
63  }
64  else if (cmd==fHeightCMD) {
65  fBuilder->SetHeight(fHeightCMD->GetNewDoubleValue(val));
66  }
67  else {
69  }
70  };
71 };
72 
74  SetMessenger(new CaptWorldMessenger(this));
75  fLength = 10*CLHEP::m;
76  fWidth = fLength;
77  fHeight = fLength;
78 
79  AddBuilder(new CaptCryostatBuilder("Cryostat",this));
80 
81 }
82 
84 
85 G4LogicalVolume *CaptWorldBuilder::GetPiece(void) {
86 
87  EDepSimLog("##############################################");
88  EDepSimLog("# CONSTRUCT THE WORLD GEOMETRY ");
89  EDepSimLog("##############################################");
90 
91  G4LogicalVolume *logVolume
92  = new G4LogicalVolume(new G4Box(GetName(),
93  fLength/2,
94  fWidth/2,
95  fHeight/2),
96  FindMaterial("Air"),
97  GetName());
98  logVolume->SetVisAttributes(G4VisAttributes::Invisible);
99 
100  double floorThickness = 10*CLHEP::cm;
101  G4LogicalVolume *logFloor
102  = new G4LogicalVolume(new G4Box(GetName()+"/Floor",
103  fLength/2,
104  fWidth/2,
105  floorThickness/2),
106  FindMaterial("Cement"),
107  GetName()+"/Floor");
108  logFloor->SetVisAttributes(G4VisAttributes::Invisible);
109 
110  CaptCryostatBuilder& cryo
111  = Get<CaptCryostatBuilder>("Cryostat");
112  G4LogicalVolume* logCryostat = cryo.GetPiece();
113 
114  G4ThreeVector cryoCenter = G4ThreeVector(0,0,0)
115  - cryo.GetOffset() - cryo.GetTPCOffset();
116 
117  new G4PVPlacement(NULL, // rotation.
118  cryoCenter, // position
119  logCryostat, // logical volume
120  logCryostat->GetName(), // name
121  logVolume, // mother volume
122  false, // overlapping volume (not used)
123  0, // Copy number (zero)
124  Check()); // Check overlaps.
125 
126 #ifdef SHOW_FLOOR
127  G4VisExtent cryoExtent = logCryostat->GetSolid()->GetExtent();
128  G4ThreeVector centerFloor(0.0, 0.0,
129  cryoCenter.z() + cryoExtent.GetZmin()
130  - floorThickness/2 - 50*CLHEP::cm);
131 
132  new G4PVPlacement(NULL, // rotation.
133  centerFloor, // position
134  logFloor, // logical volume
135  GetName()+"/Floor", // name
136  logVolume, // mother volume
137  false, // overlapping volume (not used)
138  0, // Copy number (zero)
139  Check()); // Check overlaps.
140 
141  if (GetVisible()) {
142  logFloor->SetVisAttributes(GetColor(logFloor));
143  }
144 #endif
145 
146  return logVolume;
147 }
static constexpr double cm
Definition: Units.h:68
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
virtual ~CaptWorldBuilder()
void SetNewValue(G4UIcommand *cmd, G4String val)
G4UIcmdWithADoubleAndUnit * fHeightCMD
void SetHeight(double v)
Set the height of the world.
CaptWorldMessenger(CaptWorldBuilder *c)
Construct a module from components.
Definition: TG4HitSegment.h:10
BuilderMessenger(EDepSim::Builder *c, const char *guide=NULL)
void SetWidth(double v)
Set the width of the world.
G4ThreeVector GetTPCOffset()
G4UIcmdWithADoubleAndUnit * fLengthCMD
void SetLength(double v)
Set the length of the world.
G4ThreeVector GetOffset()
void SetNewValue(G4UIcommand *cmd, G4String val)
virtual G4LogicalVolume * GetPiece(void)
G4UIcmdWithADoubleAndUnit * fWidthCMD
list cmd
Definition: getreco.py:22
G4String CommandName(G4String cmd)
Build a command name with the directory prefix.
CaptWorldBuilder * fBuilder
virtual ~CaptWorldMessenger()
virtual G4LogicalVolume * GetPiece(void)
static TemplateFilterFactory::AutoRegister< FilterLength > fLength("length")