EDepSimBuilder.cc
Go to the documentation of this file.
1 #include "EDepSimBuilder.hh"
2 #include "EDepSimException.hh"
4 #include "EDepSimSDFactory.hh"
5 #include "EDepSimSegmentSD.hh"
6 
7 #include <sstream>
8 #include <algorithm>
9 #include <functional>
10 
13  : fLocalName(n), fName(n), fConstruction(c), fParent(NULL),
14  fMessenger(NULL), fSensitiveDetector(NULL),
15  fOpacity(0.0), fCheck(false) {
17 }
18 
20  : fLocalName(n), fName(n), fConstruction(NULL), fParent(p),
21  fMessenger(NULL), fSensitiveDetector(NULL),
22  fOpacity(0.0), fCheck(false) {
23  fName = fParent->GetName() + "/" + fLocalName;
25  // Provide a reasonable default. This will (hopefully) be overridden in
26  // Init().
28 }
29 
31 
32 G4LogicalVolume *EDepSim::Builder::GetPiece(void) {
33  EDepSimThrow("EDepSim::Builder::GetPiece(): Not implemented");
34  return NULL;
35 }
36 
37 G4Material* EDepSim::Builder::FindMaterial(G4String name) {
38  G4Material* material = G4Material::GetMaterial(name,true);
39  return material;
40 }
41 
42 G4String EDepSim::Builder::GetName(void) {
43  return fName;
44 }
45 
46 /// Set the local name of the object to be built. The local name of the
47 /// logical volume being set, and also sets the full name of the volume.
48 void EDepSim::Builder::SetLocalName(const G4String& name) {
49  fLocalName = name;
50  fName = name;
51  if (fParent) fName = fParent->GetName() + "/" + fName;
52 }
53 
54 
55 /// Set the visibility of the constructed object.
57  if (fOpacity != v) {
58  EDepSimLog("Set relative opacity for " << GetName()
59  << " from " << fOpacity << " to " << v);
60  }
61  fOpacity = v;
62 }
63 
64 /// Set the visibility of the constructed object.
67  = fSubBuilders.begin();
68  p!=fSubBuilders.end();
69  ++p) {
70  (*p).second->SetOpacity(v);
71  (*p).second->SetDaughterOpacity(v);
72  }
73 }
74 
76  const char* guide) {
77  fBuilder = c;
78  fDirName = c->GetName() + "/";
79  fDirectory = new G4UIdirectory(fDirName);
80  if (guide) {
81  fDirectory->SetGuidance(guide);
82  }
83  else {
84  std::string guidance = "Commands for the " + c->GetName() + " Builder";
85  fDirectory->SetGuidance(guidance.c_str());
86  }
87 
88  fOpacityCMD = new G4UIcmdWithADouble(CommandName("opacity"),this);
89  fOpacityCMD->SetGuidance("Set the log of the relative opacity."
90  " Useful values are between [-0.5, 0.5], and"
91  " +/-10 makes the object opague or transparent."
92  " A value of 0 leaves the opacity unchanged.");
93  fOpacityCMD->SetParameterName("opacity",false);
94 
95  fDaughterOpacityCMD = new G4UIcmdWithADouble(
96  CommandName("daughterOpacity"),this);
97  fDaughterOpacityCMD->SetGuidance(
98  "Set the log of the relative opacity of the daughters.");
99  fDaughterOpacityCMD->SetParameterName("opacity",false);
100 
101  fCheckCMD = new G4UIcmdWithABool(CommandName("check"),this);
102  fCheckCMD->SetGuidance("If this is true then check for overlaps");
103  fCheckCMD->SetParameterName("check",false);
104 
105  fSensitiveCMD = new G4UIcommand(CommandName("sensitive"),this);
106  fSensitiveCMD->SetGuidance("Set the name of the sensitive detector");
107  G4UIparameter* nameParam = new G4UIparameter('s');
108  nameParam->SetParameterName("Name");
109  fSensitiveCMD->SetParameter(nameParam);
110  G4UIparameter* typeParam = new G4UIparameter('s');
111  typeParam->SetParameterName("Type");
112  fSensitiveCMD->SetParameter(typeParam);
113 
114  fMaximumHitSagittaCMD
115  = new G4UIcmdWithADoubleAndUnit(CommandName("maxHitSagitta"),this);
116  fMaximumHitSagittaCMD->SetGuidance("Set the maximum sagitta for a hit.");
117  fMaximumHitSagittaCMD->SetParameterName("Sagitta",false);
118  fMaximumHitSagittaCMD->SetUnitCategory("Length");
119 
120  fMaximumHitLengthCMD
121  = new G4UIcmdWithADoubleAndUnit(CommandName("maxHitLength"),this);
122  fMaximumHitLengthCMD->SetGuidance("Set the maximum length for a hit.");
123  fMaximumHitLengthCMD->SetParameterName("HitLength",false);
124  fMaximumHitLengthCMD->SetUnitCategory("Length");
125 }
126 
127 void EDepSim::BuilderMessenger::SetNewValue(G4UIcommand *cmd, G4String val) {
128  if (cmd == fOpacityCMD) {
129  fBuilder->SetOpacity(fOpacityCMD->GetNewDoubleValue(val));
130  }
131  else if (cmd == fDaughterOpacityCMD) {
132  fBuilder->SetDaughterOpacity(
133  fDaughterOpacityCMD->GetNewDoubleValue(val));
134  }
135  else if (cmd == fCheckCMD) {
136  fBuilder->SetCheck(fCheckCMD->GetNewBoolValue(val));
137  }
138  else if (cmd==fSensitiveCMD) {
139  std::istringstream buf(val.c_str());
141  buf >> name;
142  buf >> type;
143  fBuilder->SetSensitiveDetector(name,type);
144  }
145  else if (cmd==fMaximumHitSagittaCMD) {
146  fBuilder->
148  fMaximumHitSagittaCMD->GetNewDoubleValue(val));
149  }
150  else if (cmd==fMaximumHitLengthCMD) {
151  fBuilder->
153  fMaximumHitLengthCMD->GetNewDoubleValue(val));
154  }
155 }
156 
158  delete fDirectory;
159  delete fOpacityCMD;
160  delete fDaughterOpacityCMD;
161  delete fCheckCMD;
162  delete fSensitiveCMD;
163  delete fMaximumHitSagittaCMD;
164  delete fMaximumHitLengthCMD;
165 }
166 
167 G4VisAttributes EDepSim::Builder::GetColor(G4Material* mat, double opacity) {
169  // Check if the opacity has been over-ruled by the macro...
170  if (fOpacity < -9.9) return G4VisAttributes::Invisible;
171  opacity += fOpacity;
172  if (opacity < -9.9) return G4VisAttributes::Invisible;
173  G4Color color = geoMan->GetG4Color(mat);
174  double red = color.GetRed();
175  double green = color.GetGreen();
176  double blue = color.GetBlue();
177  double alpha = std::max(0.0,color.GetAlpha());
178  if (opacity > 9.9) alpha = 1.0;
179  else if (fOpacity > 9.9) alpha = 1.0;
180  else alpha = std::min(1.0, alpha*std::exp(opacity));
181  return G4VisAttributes(G4Color(red,green,blue,alpha));
182 }
183 
184 G4VisAttributes EDepSim::Builder::GetColor(G4LogicalVolume* vol, double opacity) {
185  G4Material* mat = vol->GetMaterial();
186  return GetColor(mat,opacity);
187 }
188 
189 /// Set the sensitive detector for this component by name.
191  EDepSim::SDFactory factory(type);
192  SetSensitiveDetector(factory.MakeSD(name));
193 }
194 
196  if (!fSensitiveDetector) {
197  EDepSimError("Maximum hit sagitta must be set after the sensitive"
198  " detector is defined.");
199  EDepSimThrow("Builder does not have sensitive detector defined");
200  return;
201  }
203  if (!segSD) {
204  EDepSimThrow("Sensitive detector not derived from EDepSim::SegmentSD");
205  return;
206  }
207  segSD->SetMaximumHitSagitta(sagitta);
208 }
209 
211  if (!fSensitiveDetector) {
212  EDepSimError("Maximum hit length must be set after the sensitive"
213  " detector is defined.");
214  EDepSimThrow("Builder does not have sensitive detector defined");
215  return;
216  }
218  if (!segSD) {
219  EDepSimThrow("Sensitive detector not derived from EDepSim::SegmentSD");
220  return;
221  }
222  segSD->SetMaximumHitLength(length);
223 }
224 
225 
static QCString name
Definition: declinfo.cpp:673
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
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.
void SetNewValue(G4UIcommand *cmd, G4String val)
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.
G4Color GetG4Color(G4Material *material)
std::string string
Definition: nybbler.cc:12
bool fCheck
If this is true, then check the constructed object for overlaps.
virtual EDepSim::DetectorMessenger * GetMessenger(void)
Return the detector construction messenger.
EDepSim::UserDetectorConstruction * fConstruction
The G4VUserDetectorConstruction class that this is cooperating with.
G4String fName
The name of the constructor.
G4Material * FindMaterial(G4String m)
void SetMaximumHitLength(double length)
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
virtual void SetMaximumHitSagitta(double sagitta)
G4VSensitiveDetector * MakeSD(G4String name)
BuilderMessenger(EDepSim::Builder *c, const char *guide=NULL)
Builder(G4String n, EDepSim::UserDetectorConstruction *c)
std::void_t< T > n
void SetOpacity(double v)
Set the relative opacity of the constructed object.
double alpha
Definition: doAna.cpp:15
p
Definition: test.py:223
EDepSim::Builder * fParent
The parent of this constructor.
G4VSensitiveDetector * fSensitiveDetector
The sensitive detector for this tracking component.
static int max(int a, int b)
std::size_t color(std::string const &procname)
#define EDepSimError(outStream)
Definition: EDepSimLog.hh:503
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
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)
static QCString type
Definition: declinfo.cpp:672
void SetMaximumHitSagitta(double sagitta)
list cmd
Definition: getreco.py:22
void SetDaughterOpacity(double v)
Set the relative opacity of the object daughters.
G4UImessenger * GetMessenger(void)
Return the messenger for this constructor.
static EDepSim::RootGeometryManager * Get(void)
If a persistency manager has not been created, create one.