EDepSimBuilder.hh
Go to the documentation of this file.
1 #ifndef EDepSim_Builder_hh_Seen
2 #define EDepSim_Builder_hh_Seen
3 
4 namespace EDepSim {class Builder;}
5 namespace EDepSim {class UserDetectorConstruction;}
6 
8 #include "EDepSimException.hh"
9 
10 #include <G4LogicalVolume.hh>
11 #include <G4Material.hh>
12 #include <G4UImessenger.hh>
13 #include <G4UIdirectory.hh>
14 #include <G4UIcmdWithoutParameter.hh>
15 #include <G4UIcmdWithABool.hh>
16 #include <G4UIcmdWithAnInteger.hh>
17 #include <G4UIcmdWithADouble.hh>
18 #include <G4UIcmdWithAString.hh>
19 #include <G4UIcmdWith3Vector.hh>
20 #include <G4UIcmdWithADoubleAndUnit.hh>
21 #include <G4UIcmdWith3VectorAndUnit.hh>
22 #include <G4RotationMatrix.hh>
23 #include <G4VisAttributes.hh>
24 
25 #include <iostream>
26 #include <map>
27 
28 /// A Base for class to build elements of the detector. The method get
29 /// GetPiece() should construct a new unplaced element that is facing up along
30 /// the Z axis. The caller will then then rotate the object into position and
31 /// and place the object into an existing mother volume. These are designed
32 /// to be called "recursively" with one builder calling another builder. A
33 /// builder will usually use one or more sub-builders to make any new piece.
34 ///
35 /// The builders should follow a single naming convention. All builder
36 /// classes should be named "EDepSim::<thename>Builder". When builders are used in
37 /// code, they are declared using the AddBuilder() method which takes a name
38 /// (string) which is used to reference the builder, and to make macro
39 /// commands to control the object. The builder name should start with an
40 /// upper case letter.
41 ///
42 /// Most builders (all should) will define a messenger. The command names are
43 /// build with the CommandName() method. All command names should begin with
44 /// a lower case letter.
45 namespace EDepSim {class Builder;}
47 public:
49  Builder(G4String n, EDepSim::Builder* parent);
50  virtual ~Builder();
51 
52  /// Construct and return a G4 volume for the object. This is a pure
53  /// virtual function, which means it must be implemented by the inheriting
54  /// classes. This returns an unplaced logical volume which faces along
55  /// the Z axis.
56  virtual G4LogicalVolume *GetPiece(void) = 0;
57 
58  /// Return the base name of the object that this builds.
59  G4String GetName(void);
60 
61  /// Return the base name of the object that this builds.
62  G4String GetLocalName(void) {return fLocalName;};
63 
64  /// Set the base name of the logical volume that this builds.
65  void SetLocalName(const G4String& name);
66 
67  /// Set the relative opacity of the constructed object.
68  void SetOpacity(double v);
69 
70  /// Get the relative opacity of the constructed object.
71  double GetOpacity(void) const {return fOpacity;}
72 
73  /// Set the relative opacity of the object daughters
74  void SetDaughterOpacity(double v);
75 
76  /// Return the detector construction that is building this piece.
78  return fConstruction;
79  };
80 
81  /// Set the sensitive detector for this component.
82  virtual void SetSensitiveDetector(G4VSensitiveDetector* s) {
84  }
85 
86  /// Get the sensitive detector for this component.
87  virtual G4VSensitiveDetector* GetSensitiveDetector(void) {
88  return fSensitiveDetector;
89  }
90 
91  /// Set the sensitive detector for this component by name.
92  virtual void SetSensitiveDetector(G4String name, G4String type);
93 
94  /// Set the maximum sagitta for a track being added to a single hit
95  /// segment.
96  virtual void SetMaximumHitSagitta(double sagitta);
97 
98  /// Set the maximum length of a single hit segment.
99  virtual void SetMaximumHitLength(double length);
100 
101  /// Return the messenger for this constructor
102  G4UImessenger* GetMessenger(void) {return fMessenger;};
103 
104  /// Set the messenger for this constructor.
105  void SetMessenger(G4UImessenger* m) {
106  fMessenger = m;
107  };
108 
109  /// Add a new sub constructor to the current geometry constructor. This
110  /// should be done in the derived class ctor. All geometry constructors
111  /// that will be used by the derived class should be added using this
112  /// method.
114  if (fSubBuilders.find(c->GetLocalName())
115  != fSubBuilders.end()) {
116  std::cout << "Multiply defined constructor name "
117  << c->GetName()
118  << std::endl;
119  EDepSimThrow("EDepSim::Builder::AddBuilder(): Multiple defines");
120  }
121  fSubBuilders[c->GetLocalName()] = c;
122  }
123 
124  /// Get a sub constructor by name and do the dynamic cast. This will
125  /// abort with an error message if you request an undefined name.
126  template <class T> T& Get(G4String n) {
128  = fSubBuilders.find(n);
129  if (p==fSubBuilders.end()) {
130  std::cout << "Error in " << GetName() << std::endl;
131  std::cout << " Undefined constructor requested "
132  << n << std::endl;
133  std::cout << " The choices are: " << std::endl;
134  for (p = fSubBuilders.begin();
135  p != fSubBuilders.end();
136  ++p) {
137  std::cout << " \"" << (*p).first << "\""
138  << " for constructor: " << (*p).second->GetName()
139  << std::endl;
140  }
141  EDepSimThrow(" Undefined constructor");
142  }
143  T* c = dynamic_cast<T*>((*p).second);
144  if (!c) {
145  std::cout << "Error in " << GetName() << std::endl;
146  std::cout << " Cannot type cast " << n
147  << " to requested class" << std::endl;
148  EDepSimThrow("EDepSim::Builder::Get<>:"
149  " Bad typecast");
150  }
151  return *c;
152  }
153 
154  /// Find a sub constructor by name and do the dynamic cast. This returns
155  /// a pointer that will be NULL if you request an undefined name.
156  template <class T> T* Find(G4String n) {
158  = fSubBuilders.find(n);
159  if (p==fSubBuilders.end()) return NULL;
160  T* c = dynamic_cast<T*>((*p).second);
161  return c;
162  }
163 
164  /// This returns true if the interior objects should be checked for
165  /// overlaps.
166  bool Check() {return fCheck;}
167 
168  /// Set the check value.
169  void SetCheck(bool v) {fCheck = v;}
170 
171 protected:
172  G4Material* FindMaterial(G4String m);
173 
174  /// Takes logical volume and returns the visual attributes. The optional
175  /// argument specifies the log of the relative opacity used for this
176  /// specific set of attributes. If the relative opacity is 0, then the
177  /// default alpha is used. If the relative opacity is positive, then the
178  /// alpha is increased, and if it's negative, the alpha is decreased. If
179  /// the relative opacity is 10, then the object will have an alpha of 1.0.
180  /// If it's -10, then the object will have an alpha of zero
181  /// (i.e. invisible).
182  G4VisAttributes GetColor(G4LogicalVolume* volume, double opacity = 0.0);
183 
184  /// Takes a material and returns the attributes. The optional argument
185  /// specifies the log of the relative opacity used for this specific set
186  /// of attributes. If the relative opacity is 0, then the default alpha
187  /// is used. If the relative opacity is positive, then the alpha is
188  /// increased, and if it's negative, the alpha is decreased. If the
189  /// relative opacity is 10, then the object will have an alpha of 1.0. If
190  /// it's -10, then the object will have an alpha of zero (i.e. invisible).
191  G4VisAttributes GetColor(G4Material* volume, double opacity = 0.0);
192 
193 private:
194  /// The short local name of the constructor.
195  G4String fLocalName;
196 
197  /// The name of the constructor.
198  G4String fName;
199 
200  /// The G4VUserDetectorConstruction class that this is cooperating with.
202 
203  /// The parent of this constructor
205 
206  /// The user interface messenger that will provide values for this class.
207  G4UImessenger* fMessenger;
208 
209  /// The sensitive detector for this tracking component.
210  G4VSensitiveDetector* fSensitiveDetector;
211 
212  /// The relative opacity of the constructed object.
213  double fOpacity;
214 
215  /// If this is true, then check the constructed object for overlaps.
216  bool fCheck;
217 
218  /// The sub constructors that might be used in this class.
219  std::map<G4String,EDepSim::Builder*> fSubBuilders;
220 
221 };
222 
223 namespace EDepSim {class BuilderMessenger;}
224 class EDepSim::BuilderMessenger: public G4UImessenger {
225 private:
227 
228  /// The UI directory for this messenger.
229  G4UIdirectory* fDirectory;
230 
231  /// The directory name for this messenger
232  G4String fDirName;
233 
234  G4UIcmdWithADouble* fOpacityCMD;
235  G4UIcmdWithADouble* fDaughterOpacityCMD;
236  G4UIcmdWithABool* fCheckCMD;
237  G4UIcommand* fSensitiveCMD;
238  G4UIcmdWithADoubleAndUnit* fMaximumHitSagittaCMD;
239  G4UIcmdWithADoubleAndUnit* fMaximumHitLengthCMD;
240 
241 public:
242  BuilderMessenger(EDepSim::Builder* c, const char* guide=NULL);
243  virtual ~BuilderMessenger();
244 
245  /// Return the name of the directory.
246  G4String GetDirectory(void) {return fDirName;};
247 
248  /// Build a command name with the directory prefix.
249  G4String CommandName(G4String cmd) {
250  G4String name = GetDirectory() + cmd;
251  return name;
252  };
253 
254  void SetNewValue(G4UIcommand *cmd, G4String val);
255 };
256 #endif
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
EDepSim::UserDetectorConstruction * GetConstruction(void)
Return the detector construction that is building this piece.
G4String GetName(void)
Return the base name of the object that this builds.
G4String fLocalName
The short local name of the constructor.
T & Get(G4String n)
EDepSim::Builder * fBuilder
G4UImessenger * fMessenger
The user interface messenger that will provide values for this class.
virtual void SetMaximumHitLength(double length)
Set the maximum length of a single hit segment.
void SetMessenger(G4UImessenger *m)
Set the messenger for this constructor.
bool fCheck
If this is true, then check the constructed object for overlaps.
G4String GetLocalName(void)
Return the base name of the object that this builds.
virtual G4VSensitiveDetector * GetSensitiveDetector(void)
Get the sensitive detector for this component.
EDepSim::UserDetectorConstruction * fConstruction
The G4VUserDetectorConstruction class that this is cooperating with.
static const std::string volume[nvol]
G4String fName
The name of the constructor.
void SetCheck(bool v)
Set the check value.
G4Material * FindMaterial(G4String m)
void SetLocalName(const G4String &name)
Set the base name of the logical volume that this builds.
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
double fOpacity
The relative opacity of the constructed object.
virtual G4LogicalVolume * GetPiece(void)=0
G4UIcmdWithADoubleAndUnit * fMaximumHitSagittaCMD
virtual void SetMaximumHitSagitta(double sagitta)
G4UIcmdWithADoubleAndUnit * fMaximumHitLengthCMD
void AddBuilder(EDepSim::Builder *c)
Construct a module from components.
Definition: TG4HitSegment.h:10
G4UIcmdWithADouble * fDaughterOpacityCMD
Builder(G4String n, EDepSim::UserDetectorConstruction *c)
double GetOpacity(void) const
Get the relative opacity of the constructed object.
std::void_t< T > n
void SetOpacity(double v)
Set the relative opacity of the constructed object.
p
Definition: test.py:223
EDepSim::Builder * fParent
The parent of this constructor.
G4VSensitiveDetector * fSensitiveDetector
The sensitive detector for this tracking component.
G4String GetDirectory(void)
Return the name of the directory.
G4UIcmdWithABool * fCheckCMD
G4UIdirectory * fDirectory
The UI directory for this messenger.
G4String fDirName
The directory name for this messenger.
T * Find(G4String n)
virtual void SetSensitiveDetector(G4VSensitiveDetector *s)
Set the sensitive detector for this component.
std::map< G4String, EDepSim::Builder * > fSubBuilders
The sub constructors that might be used in this class.
G4VisAttributes GetColor(G4LogicalVolume *volume, double opacity=0.0)
list cmd
Definition: getreco.py:22
G4String CommandName(G4String cmd)
Build a command name with the directory prefix.
static QCString * s
Definition: config.cpp:1042
def parent(G, child, parent_type)
Definition: graph.py:67
void SetDaughterOpacity(double v)
Set the relative opacity of the object daughters.
G4UImessenger * GetMessenger(void)
Return the messenger for this constructor.
QTextStream & endl(QTextStream &s)
G4UIcmdWithADouble * fOpacityCMD