CMS 3D CMS Logo

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