EDepSimModuleBuilder.hh
Go to the documentation of this file.
1 #ifndef EDepSim_ModuleBuilder_hh_seen
2 #define EDepSim_ModuleBuilder_hh_seen
3 
4 #include <sstream>
5 
6 #include <G4ThreeVector.hh>
7 
8 class G4LogicalVolume;
9 
10 #include "EDepSimBuilder.hh"
12 
13 /// Construct a module from components.
14 
15 namespace EDepSim {class ModuleBuilder;}
17 
18 public:
19 
21  : EDepSim::Builder(n,c) {Init();};
22 
24  : EDepSim::Builder(n,p) {
25  Init();};
26 
27  virtual ~ModuleBuilder();
28 
29  /// Construct and return a G4 volume for the object. This is a pure
30  /// virtual function, which means it must be implemented by the inheriting
31  /// classes. This returns an unplaced logical volume which faces along
32  /// the Z axis.
33  virtual G4LogicalVolume *GetPiece(void);
34 
35  /// Set the width of the module. This is the X dimension of the module.
36  void SetWidth(double w) {fWidth = w;}
37  /// Get the width of the module.
38  double GetWidth(void) {return fWidth;}
39 
40  /// Set the height of the module. This is the Y dimension of the module.
41  void SetHeight(double w) {fHeight = w;}
42  /// Get the height of the module.
43  double GetHeight(void) {return fHeight;}
44 
45  /// Get the length of the module.
46  double GetLength(void) {return fLength;};
47 
48  /// Clear the list of components to be added to the FG tracker.
49  void ClearComponentList(void);
50 
51  /// Add a new component name to the FG tracker. Components are added from
52  /// upstream (-Z) to downstream (+Z).
53  void AddComponent(G4String m);
54 
55  /// Set the number of repetitions for the last components added to the
56  /// module. This counts the total repetitions of the last component,
57  /// inclduing that component. So "1" repetition doesn't increase the
58  /// number of components. This also controls the number of previous
59  /// components to be part of the repetion.
60  void SetRepetitions(int r, int c);
61 
62  /// Translate some components inside the module in X/Y
63  /// according to module number and total components in a module.
64  /// This simulates misalignment in FGD layers.
65  void SetModuleCompTrans(int m, int cPerM, int c,
66  double transX, double transY);
67 
68  /// Set the target length of the module bounding box along the
69  /// beam axis (the Z axis). The actual length must be shorter than this.
70  /// Note that the beam goes down at at a few degrees, but the Z axis is
71  /// horizontal.
72  void SetTargetLength(double w) {fTargetLength = w;}
73  /// Get the target length of the module bounding box.
74  double GetTargetLength(void) {return fTargetLength;}
75 
76  /// Set flag to accept the TargetLength as the actual module length.
77  void SetFixLength(bool f) {fFixLength = f;}
78  /// Get flag to accept the TargetLength as the actual module length.
79  bool GetFixLength(void) {return fFixLength;}
80 
81  /// Set x position at which components are positioned inside the module.
82  void SetXPosition(double x) {xPosition = x;}
83  /// Get x position at which components are positioned inside the module.
84  double GetXPosition() {return xPosition;}
85 
86  /// Set y position at which components are positioned inside the module.
87  void SetYPosition(double y) {yPosition = y;}
88  /// Get y position at which components are positioned inside the module.
89  double GetYPosition() {return yPosition;}
90 
91  /// Get the maximum positive x translation parameter among the modules.
92  double GetXmaxTranslation() {return xmax;}
93  /// Get the minimum negative x translation parameter among the modules.
94  double GetXminTranslation() {return xmin;}
95  /// Get the maximum positive y translation parameter among the modules.
96  double GetYmaxTranslation() {return ymax;}
97  /// Get the minimum negative y translation parameter among the modules.
98  double GetYminTranslation() {return ymin;}
99 
100 private:
101 
102  /// The width of the module.
103  double fWidth;
104 
105  /// The height of the module.
106  double fHeight;
107 
108  /// The length of the module.
109  double fLength;
110 
111  /// The target length of module bounding box (parallel to the
112  /// beam axis). The actual length must be shorter than this.
114 
115  /// Logical flag to accept the target length as the module length.
117 
118  /// The x position at which components are positioned inside the module.
119  double xPosition;
120 
121  /// The y position at which components are positioned inside the module.
122  double yPosition;
123 
124  /// Default pair of translation constants.
125  std::pair<double, double> fPair;
126 
127  /// A vector of ComponentBuilders that will be added to the module.
128  typedef std::vector<EDepSim::ComponentBuilder*> PartsList;
129  PartsList* fPartsList;
130 
131  /// A vector of translation parameters in x and y for each component
132  /// in the module. Used in parallel with fPartsList (same number of
133  /// entries as fPartsList)
134  typedef std::vector<std::pair<double, double> > TransList;
135  TransList* fTransList;
136 
137  /// Collect the minimum and maximum of translations in x and y
138  G4double xmax, xmin, ymax, ymin;
139 
140  void Init(void);
141 };
142 
143 namespace EDepSim {class ModuleBuilderMessenger;}
145 private:
147  G4UIcmdWithoutParameter* fClearCMD;
148  G4UIcmdWithAString* fAddCMD;
149  G4UIcommand* fRepeatCMD;
150  G4UIcmdWithADoubleAndUnit* fWidthCMD;
151  G4UIcmdWithADoubleAndUnit* fHeightCMD;
152 
153 public:
155  const char* guide=NULL)
156  : EDepSim::BuilderMessenger(c,guide),
157  fBuilder(c) {
158  fClearCMD = new G4UIcmdWithoutParameter(CommandName("clear"),this);
159  fClearCMD->SetGuidance("Clear the component list for the FG tracker.");
160 
161  fAddCMD = new G4UIcmdWithAString(CommandName("add"),this);
162  fAddCMD->SetGuidance("Add the named component to the module."
163  " Components are added from upstream"
164  " to downstream.");
165  fAddCMD->SetParameterName("Component", false);
166 
167  fRepeatCMD = new G4UIcommand(CommandName("repeat"),this);
168  fRepeatCMD->SetGuidance("Times to repeat the last components.");
169  G4UIparameter* repParam = new G4UIparameter('i');
170  repParam->SetParameterName("Repetitions");
171  fRepeatCMD->SetParameter(repParam);
172  G4UIparameter* cntParam = new G4UIparameter('i');
173  cntParam->SetParameterName("Count");
174  fRepeatCMD->SetParameter(cntParam);
175 
176  fWidthCMD = new G4UIcmdWithADoubleAndUnit(CommandName("width"),this);
177  fWidthCMD->SetGuidance("Set the width of the module.");
178  fWidthCMD->SetParameterName("Width",false);
179  fWidthCMD->SetUnitCategory("Length");
180 
181  fHeightCMD = new G4UIcmdWithADoubleAndUnit(CommandName("height"),this);
182  fHeightCMD->SetGuidance("Set the height of the module.");
183  fHeightCMD->SetParameterName("Height",false);
184  fHeightCMD->SetUnitCategory("Length");
185  };
186 
188  delete fClearCMD;
189  delete fAddCMD;
190  delete fRepeatCMD;
191  delete fWidthCMD;
192  delete fHeightCMD;
193  };
194 
195  void SetNewValue(G4UIcommand *cmd, G4String val) {
196  if (cmd==fClearCMD) {
197  fBuilder->ClearComponentList();
198  }
199  else if (cmd==fAddCMD) {
200  fBuilder->AddComponent(val);
201  }
202  else if (cmd==fRepeatCMD) {
203  int repetitions;
204  int count = 1;
205  std::istringstream inputs((char*)val.c_str());
206  inputs >> repetitions >> count;
207  fBuilder->SetRepetitions(repetitions,count);
208  }
209  else if (cmd==fWidthCMD) {
210  fBuilder->SetWidth(fWidthCMD->GetNewDoubleValue(val));
211  }
212  else if (cmd==fHeightCMD) {
213  fBuilder->SetHeight(fHeightCMD->GetNewDoubleValue(val));
214  }
215  else {
217  }
218  };
219 };
220 
221 #endif
ModuleBuilder(G4String n, EDepSim::UserDetectorConstruction *c)
std::pair< double, double > fPair
Default pair of translation constants.
void SetNewValue(G4UIcommand *cmd, G4String val)
std::vector< EDepSim::ComponentBuilder * > PartsList
A vector of ComponentBuilders that will be added to the module.
double GetYPosition()
Get y position at which components are positioned inside the module.
G4UIcmdWithADoubleAndUnit * fHeightCMD
double GetYminTranslation()
Get the minimum negative y translation parameter among the modules.
double GetXPosition()
Get x position at which components are positioned inside the module.
void SetHeight(double w)
Set the height of the module. This is the Y dimension of the module.
double fLength
The length of the module.
double GetXminTranslation()
Get the minimum negative x translation parameter among the modules.
double yPosition
The y position at which components are positioned inside the module.
double GetTargetLength(void)
Get the target length of the module bounding box.
bool GetFixLength(void)
Get flag to accept the TargetLength as the actual module length.
void ClearComponentList(void)
Clear the list of components to be added to the FG tracker.
void SetModuleCompTrans(int m, int cPerM, int c, double transX, double transY)
bool fFixLength
Logical flag to accept the target length as the module length.
virtual G4LogicalVolume * GetPiece(void)
Construct a module from components.
Definition: TG4HitSegment.h:10
void SetNewValue(G4UIcommand *cmd, G4String val)
G4UIcmdWithADoubleAndUnit * fWidthCMD
std::void_t< T > n
ModuleBuilderMessenger(EDepSim::ModuleBuilder *c, const char *guide=NULL)
G4UIcmdWithoutParameter * fClearCMD
p
Definition: test.py:223
double GetLength(void)
Get the length of the module.
void SetRepetitions(int r, int c)
double GetWidth(void)
Get the width of the module.
double GetXmaxTranslation()
Get the maximum positive x translation parameter among the modules.
void SetYPosition(double y)
Set y position at which components are positioned inside the module.
double xPosition
The x position at which components are positioned inside the module.
double fHeight
The height of the module.
void SetFixLength(bool f)
Set flag to accept the TargetLength as the actual module length.
G4double xmax
Collect the minimum and maximum of translations in x and y.
ModuleBuilder(G4String n, EDepSim::Builder *p)
double GetYmaxTranslation()
Get the maximum positive y translation parameter among the modules.
double fWidth
The width of the module.
void SetWidth(double w)
Set the width of the module. This is the X dimension of the module.
void SetXPosition(double x)
Set x position at which components are positioned inside the module.
list x
Definition: train.py:276
std::vector< std::pair< double, double > > TransList
list cmd
Definition: getreco.py:22
double GetHeight(void)
Get the height of the module.