CMS 3D CMS Logo

DDG4Builder.cc
Go to the documentation of this file.
2 
4 
9 
10 #include "G4VSolid.hh"
11 #include "G4Box.hh"
12 #include "G4Tubs.hh"
13 #include "G4Cons.hh"
14 #include "G4Trap.hh"
15 #include "G4Material.hh"
16 #include "G4LogicalVolume.hh"
17 #include "G4VPhysicalVolume.hh"
18 #include "G4PVPlacement.hh"
19 #include "G4ReflectionFactory.hh"
20 
21 #include "G4UnitsTable.hh"
22 #include "G4SystemOfUnits.hh"
23 
24 #include <sstream>
25 
27 
29 
32 }
33 
37 }
38 
40  delete solidConverter_;
41 }
42 
43 G4LogicalVolume * DDG4Builder::convertLV(const DDLogicalPart & part) {
44  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): DDLogicalPart = " << part << "\n";
45  G4LogicalVolume * result = logs_[part];
46  if (!result) {
47  G4VSolid * s = convertSolid(part.solid());
48  G4Material * m = convertMaterial(part.material());
49  result = new G4LogicalVolume(s,m,part.name().name());
50  map_.insert(result,part);
51  DDG4Dispatchable * disp = new DDG4Dispatchable(&part,result);
52  theVectorOfDDG4Dispatchables_->push_back(disp);
53  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): new G4LogicalVolume " << part.name().name()
54  << "\nDDG4Builder: newEvent: dd=" << part.ddname() << " g4=" << result->GetName() << "\n";
55  logs_[part] = result; // DDD -> GEANT4
56  }
57  return result;
58 }
59 
60 G4VSolid * DDG4Builder::convertSolid(const DDSolid & solid) {
61  G4VSolid * result = sols_[solid];
62  if (!result) {
63  result = solidConverter_->convert(solid); sols_[solid] = result;
64  }
65  return result;
66 }
67 
68 G4Material * DDG4Builder::convertMaterial(const DDMaterial & material) {
69  LogDebug("SimG4CoreGeometry") << "DDDetConstr::ConvertMaterial: material=" << material << "\n";
70  G4Material * result = nullptr;
71  if (material) {
72  // only if it's a valid DDD-material
73  if ((result = mats_[material])) {
74  LogDebug("SimG4CoreGeometry") << " is already converted" << "\n";
75  return result; }
76  } else {
77  // only if it's NOT a valid DDD-material
78  edm::LogError("SimG4CoreGeometry") << "DDG4Builder:: material " << material.toString() << " is not valid (in the DDD sense!)";
79  throw cms::Exception("SimG4CoreGeometry", " material is not valid from the Detector Description: " + material.toString());
80  }
81  int c = 0;
82  if ((c = material.noOfConstituents())) {
83  // it's a composite material
84  LogDebug("SimG4CoreGeometry") << " creating a G4-composite material. c=" << c
85  << " d=" << material.density()/g*mole << "\n";
86  result = new G4Material(material.name().name(),material.density(),c);
87  for (int i=0 ; i<c; ++i) {
88  // recursive building of constituents
89  LogDebug("SimG4CoreGeometry") << " adding the composite=" << material.name()
90  << " fm=" << material.constituent(i).second << "\n";
91  result->AddMaterial
92  (convertMaterial(material.constituent(i).first),
93  material.constituent(i).second);// fractionmass
94  }
95  } else {
96  // it's an elementary material
97  LogDebug("SimG4CoreGeometry") << " building an elementary material"
98  << " z=" << material.z()
99  << " a=" << material.a()/g*mole
100  << " d=" << material.density()/g*cm3 << "\n";
101  result = new G4Material
102  (material.name().name(),material.z(),material.a(),material.density());
103  }
104  mats_[material] = result;
105  return result;
106 }
107 
109  G4ReflectionFactory * refFact = G4ReflectionFactory::Instance();
110  refFact->SetScalePrecision(100.*refFact->GetScalePrecision());
111 
112  typedef DDCompactView::graph_type graph_type;
113  const graph_type & gra = compactView->graph();
114  typedef graph_type::const_adj_iterator adjl_iterator;
115  adjl_iterator git = gra.begin();
116  adjl_iterator gend = gra.end();
117 
118  graph_type::index_type i=0;
119  for (; git != gend; ++git) {
120  const DDLogicalPart & ddLP = gra.nodeData(git);
121  if ( !(ddLP.isDefined().second) ) {
122  edm::LogError("SimG4CoreGeometry") << "DDG4Builder::BuildGeometry() has encountered an undefined DDLogicalPart named " << ddLP.toString();
123  throw cms::Exception("SimG4CoreGeometry", " DDG4Builder::BuildGeometry() has encountered an undefined DDLogicalPart named " + ddLP.toString());
124  }
125  G4LogicalVolume * g4LV = convertLV(ddLP);
126  ++i;
127  if (!git->empty()) {
128  // ask for children of ddLP
129  graph_type::edge_list::const_iterator cit = git->begin();
130  graph_type::edge_list::const_iterator cend = git->end();
131  for (; cit != cend; ++cit) {
132  // fetch specific data
133  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
134  if ( !ddcurLP.isDefined().second ) {
135  std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has ";
136  err += "encountered an undefined DDLogicalPart named " + ddcurLP.toString()
137  + " is a child of " + ddLP.toString();
138  edm::LogError("SimG4CoreGeometry") << err;
139  throw cms::Exception("SimG4CoreGeometry", err) ;
140  }
141  int offset = getInt("CopyNoOffset",ddcurLP);
142  int tag = getInt("CopyNoTag",ddcurLP);
143  DDRotationMatrix rm(gra.edgeData(cit->second)->rot());
144  DD3Vector x, y, z;
145  rm.GetComponents(x, y, z);
146  if ((x.Cross(y)).Dot(z)<0)
147  edm::LogInfo("SimG4CoreGeometry") << ">>Reflection encountered: "
148  << gra.edgeData(cit->second)->ddrot()
149  << ">>Placement d=" << gra.nodeData(cit->first).ddname()
150  << " m=" << ddLP.ddname() << " cp=" << gra.edgeData(cit->second)->copyno()
151  << " r=" << gra.edgeData(cit->second)->ddrot().ddname();
152  G4ThreeVector tempTran(gra.edgeData(cit->second)->trans().X(), gra.edgeData(cit->second)->trans().Y(), gra.edgeData(cit->second)->trans().Z());
153  G4Translate3D transl = tempTran;
154  CLHEP::HepRep3x3 temp( x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z() ); //matrix representation
155  CLHEP::HepRotation hr ( temp );
156 
157  // G3 convention of defining rot-matrices ...
158  G4Transform3D trfrm = transl * G4Rotate3D(hr.inverse());//.inverse();
159 
160  refFact->Place(trfrm, // transformation containing a possible reflection
161  gra.nodeData(cit->first).name().name(),
162  convertLV(gra.nodeData(cit->first)), // daugther
163  g4LV, // mother
164  false, // 'ONLY'
165  gra.edgeData(cit->second)->copyno()+offset+tag, // copy number
166  check_);
167  } // iterate over children
168  } // if (children)
169  } // iterate over graph nodes
170 
171  // Looking for in the G4ReflectionFactory secretly created reflected G4LogicalVolumes
172  std::map<DDLogicalPart, G4LogicalVolume*>::const_iterator ddg4_it = logs_.begin();
173  for (; ddg4_it != logs_.end(); ++ddg4_it) {
174  G4LogicalVolume * reflLogicalVolume = refFact->GetReflectedLV(ddg4_it->second);
175  if (reflLogicalVolume) {
176  DDLogicalPart ddlv = ddg4_it->first;
177  map_.insert(reflLogicalVolume,ddlv);
178  DDG4Dispatchable * disp = new DDG4Dispatchable(&(ddg4_it->first),reflLogicalVolume);
179  theVectorOfDDG4Dispatchables_->push_back(disp);
180  edm::LogInfo("SimG4CoreGeometry")<< "DDG4Builder: newEvent: dd="
181  << ddlv.ddname() << " g4="
182  << reflLogicalVolume->GetName();
183  }
184  }
185 
186  G4LogicalVolume * world = logs_[compactView->root()];
187 
188  //
189  // needed for building sensitive detectors
190  //
193 
194  return DDGeometryReturnType(world,map_,catalog);
195 }
196 
198 {
199  DDValue val(s);
200  std::vector<const DDsvalues_type *> result = part.specifics();
201  std::vector<const DDsvalues_type *>::iterator it = result.begin();
202  bool foundIt = false;
203  for (; it != result.end(); ++it) {
204  foundIt = DDfetch(*it,val);
205  if (foundIt) break;
206  }
207  if (foundIt) {
208  std::vector<double> temp = val.doubles();
209  if (temp.size() != 1) {
210  edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << s;
211  throw cms::Exception("SimG4CoreGeometry", " DDG4Builder::getInt() Problem with Region tags - one and only one allowed: " + s);
212  }
213  return int(temp[0]);
214  }
215  else return 0;
216 }
217 
219  const DDLogicalPart & part) {
220  DDValue val(s);
221  std::vector<const DDsvalues_type *> result = part.specifics();
222  std::vector<const DDsvalues_type *>::iterator it = result.begin();
223  bool foundIt = false;
224  for (; it != result.end(); ++it) {
225  foundIt = DDfetch(*it,val);
226  if (foundIt) break;
227  }
228  if (foundIt) {
229  std::vector<std::string> temp = val.strings();
230  if (temp.size() != 1) {
231  edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << s ;
232  throw cms::Exception("SimG4CoreGeometry", " DDG4Builder::getDouble() Problem with Region tags - one and only one allowed: " + s);
233  }
234  double v;
236  std::istringstream is(temp[0]);
237  is >> v >> unit;
238  v = v*G4UnitDefinition::GetValueOf(unit.substr(1,unit.size()));
239  return v;
240  }
241  else return 0;
242 }
#define LogDebug(id)
double a() const
returns the atomic mass
Definition: DDMaterial.cc:96
std::vector< DDG4Dispatchable * > DDG4DispContainer
def_type isDefined() const
Definition: DDBase.h:110
G4LogicalVolume * convertLV(const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:43
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:140
const N & name() const
Definition: DDBase.h:78
std::map< DDSolid, G4VSolid * > sols_
Definition: DDG4Builder.h:40
double getDouble(const std::string &s, const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:218
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:41
const DDCompactView * compactView
Definition: DDG4Builder.h:44
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
static DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:45
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
type of data representation of DDCompactView
Definition: DDCompactView.h:90
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
std::vector< const DDsvalues_type * > specifics(void) const
returns the specific-data attached to the LogicalPart only (not to a DDExpandedNode) ...
double z() const
retruns the atomic number
Definition: DDMaterial.cc:102
G4Material * convertMaterial(const DDMaterial &dMaterial)
Definition: DDG4Builder.cc:68
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
susybsm::HSCParticleRef hr
Definition: classes.h:26
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
Definition: DDMaterial.cc:90
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:61
static DDG4DispContainer * theVectorOfDDG4Dispatchables()
Definition: DDG4Builder.cc:30
std::string toString() const
Definition: DDBase.h:82
double density() const
returns the density
Definition: DDMaterial.cc:108
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:38
part
Definition: HCALResponse.h:20
G4VSolid * convert(const DDSolid &)
SensitiveDetectorCatalog upDate(const DDG4DispContainer &ddg4s)
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
Definition: DDMaterial.cc:84
DDGeometryReturnType BuildGeometry()
Definition: DDG4Builder.cc:108
adj_iterator begin()
Definition: Graph.h:192
G4VSolid * convertSolid(const DDSolid &dSolid)
Definition: DDG4Builder.cc:60
DDG4Builder(const DDCompactView *, bool check=false)
Definition: DDG4Builder.cc:34
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
std::map< DDMaterial, G4Material * > mats_
Definition: DDG4Builder.h:39
void insert(const KeyType &, const ValueType &)
insert a new key-value-pair
Definition: DDMapper.h:77
rm
Definition: submit.py:76
def check(config)
Definition: trackerTree.py:14
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
G4LogicalVolumeToDDLogicalPartMap map_
Definition: DDG4Builder.h:46
int getInt(const std::string &s, const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:197
const N & ddname() const
Definition: DDBase.h:80