CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
DDG4Builder Class Reference

#include <DDG4Builder.h>

Public Member Functions

G4LogicalVolume * BuildGeometry (SensitiveDetectorCatalog &)
 
 DDG4Builder (const DDCompactView *, G4LogicalVolumeToDDLogicalPartMap &, bool check)
 
 ~DDG4Builder ()
 

Private Member Functions

G4LogicalVolume * convertLV (const DDLogicalPart &dLogical)
 
G4Material * convertMaterial (const DDMaterial &dMaterial)
 
G4VSolid * convertSolid (const DDSolid &dSolid)
 
double getDouble (const std::string &s, const DDLogicalPart &dLogical)
 
int getInt (const std::string &s, const DDLogicalPart &dLogical)
 

Private Attributes

bool check_
 
const DDCompactViewcompactView_
 
std::map< DDLogicalPart, G4LogicalVolume * > logs_
 
G4LogicalVolumeToDDLogicalPartMapmap_
 
std::map< DDMaterial, G4Material * > mats_
 
DDG4SolidConvertersolidConverter_
 
std::map< DDSolid, G4VSolid * > sols_
 
DDG4DispContainertheVectorOfDDG4Dispatchables_
 

Detailed Description

Definition at line 23 of file DDG4Builder.h.

Constructor & Destructor Documentation

◆ DDG4Builder()

DDG4Builder::DDG4Builder ( const DDCompactView cpv,
G4LogicalVolumeToDDLogicalPartMap lvmap,
bool  check 
)

Definition at line 25 of file DDG4Builder.cc.

References theVectorOfDDG4Dispatchables_.

◆ ~DDG4Builder()

DDG4Builder::~DDG4Builder ( )

Definition at line 30 of file DDG4Builder.cc.

30 { delete solidConverter_; }

References solidConverter_.

Member Function Documentation

◆ BuildGeometry()

G4LogicalVolume * DDG4Builder::BuildGeometry ( SensitiveDetectorCatalog catalog)

Definition at line 97 of file DDG4Builder.cc.

97  {
98  G4ReflectionFactory *refFact = G4ReflectionFactory::Instance();
99  refFact->SetScalePrecision(100. * refFact->GetScalePrecision());
100 
101  using Graph = DDCompactView::Graph;
102  const auto &gra = compactView_->graph();
104  adjl_iterator git = gra.begin();
105  adjl_iterator gend = gra.end();
106 
107  Graph::index_type i = 0;
108  for (; git != gend; ++git) {
109  const DDLogicalPart &ddLP = gra.nodeData(git);
110  if (!(ddLP.isDefined().second)) {
111  throw cms::Exception("SimG4CoreGeometry",
112  " DDG4Builder::BuildGeometry() has encountered an "
113  "undefined DDLogicalPart named " +
114  ddLP.toString());
115  }
116  G4LogicalVolume *g4LV = convertLV(ddLP);
117  ++i;
118  if (!git->empty()) {
119  // ask for children of ddLP
120  Graph::edge_list::const_iterator cit = git->begin();
121  Graph::edge_list::const_iterator cend = git->end();
122  for (; cit != cend; ++cit) {
123  // fetch specific data
124  const DDLogicalPart &ddcurLP = gra.nodeData(cit->first);
125  if (!ddcurLP.isDefined().second) {
126  std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has ";
127  err += "encountered an undefined DDLogicalPart named " + ddcurLP.toString() + " is a child of " +
128  ddLP.toString();
129  throw cms::Exception("SimG4CoreGeometry", err);
130  }
131  int offset = getInt("CopyNoOffset", ddcurLP);
132  int tag = getInt("CopyNoTag", ddcurLP);
133  DDRotationMatrix rm(gra.edgeData(cit->second)->rot());
134  DD3Vector x, y, z;
135  rm.GetComponents(x, y, z);
136  if ((x.Cross(y)).Dot(z) < 0)
137  edm::LogVerbatim("SimG4CoreGeometry")
138  << "DDG4Builder: Reflection: " << gra.edgeData(cit->second)->ddrot()
139  << ">>Placement d=" << gra.nodeData(cit->first).ddname() << " m=" << ddLP.ddname()
140  << " cp=" << gra.edgeData(cit->second)->copyno() << " r=" << gra.edgeData(cit->second)->ddrot().ddname();
141  G4ThreeVector tempTran(gra.edgeData(cit->second)->trans().X(),
142  gra.edgeData(cit->second)->trans().Y(),
143  gra.edgeData(cit->second)->trans().Z());
144  G4Translate3D transl = tempTran;
145  CLHEP::HepRep3x3 temp(x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()); // matrix
146  CLHEP::HepRotation hr(temp);
147  edm::LogVerbatim("SimG4CoreGeometry")
148  << "Position " << gra.nodeData(cit->first).name().name() << ":"
149  << gra.edgeData(cit->second)->copyno() + offset + tag << " in " << g4LV->GetName() << " at " << tempTran
150  << " with rotation matrix (" << x.X() << ", " << x.Y() << ", " << x.Z() << ", " << y.X() << ", " << y.Y()
151  << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z() << ")";
152 
153  // G3 convention of defining rot-matrices ...
154  G4Transform3D trfrm = transl * G4Rotate3D(hr.inverse()); //.inverse();
155 
156  refFact->Place(trfrm, // transformation containing a possible reflection
157  gra.nodeData(cit->first).name().name(),
158  convertLV(gra.nodeData(cit->first)), // daugther
159  g4LV, // mother
160  false, // 'ONLY'
161  gra.edgeData(cit->second)->copyno() + offset + tag, // copy number
162  check_);
163  } // iterate over children
164  } // if (children)
165  } // iterate over graph nodes
166 
167  // Looking for in the G4ReflectionFactory secretly created reflected
168  // G4LogicalVolumes
169  std::map<DDLogicalPart, G4LogicalVolume *>::const_iterator ddg4_it = logs_.begin();
170  for (; ddg4_it != logs_.end(); ++ddg4_it) {
171  G4LogicalVolume *reflLogicalVolume = refFact->GetReflectedLV(ddg4_it->second);
172  if (reflLogicalVolume) {
173  DDLogicalPart ddlv = ddg4_it->first;
174  map_.insert(reflLogicalVolume, ddlv);
175  DDG4Dispatchable *disp = new DDG4Dispatchable(&(ddg4_it->first), reflLogicalVolume);
176  theVectorOfDDG4Dispatchables_->push_back(disp);
177  edm::LogVerbatim("SimG4CoreGeometry")
178  << "DDG4Builder: dd=" << ddlv.ddname() << " g4=" << reflLogicalVolume->GetName();
179  }
180  }
181 
182  G4LogicalVolume *world = logs_[compactView_->root()];
183 
184  //
185  // needed for building sensitive detectors
186  //
189 
190  return world;
191 }

References getEcalConditions_orcoffint2r_cff::catalog, check_, compactView_, conv, convertLV(), DDBase< N, C >::ddname(), submitPVResolutionJobs::err, Exception, getInt(), DDCompactView::graph(), mps_fire::i, DDMapper< KeyType, ValueType >::insert(), DDBase< N, C >::isDefined(), logs_, map_, hltrates_dqm_sourceclient-live_cfg::offset, eostools::rm(), DDCompactView::root(), AlCaHLTBitMon_QueryRunRegistry::string, makeGlobalPositionRcd_cfg::tag, groupFilesInBlocks::temp, theVectorOfDDG4Dispatchables_, DDBase< N, C >::toString(), x, y, and z.

Referenced by DDDWorld::DDDWorld().

◆ convertLV()

G4LogicalVolume * DDG4Builder::convertLV ( const DDLogicalPart dLogical)
private

Definition at line 32 of file DDG4Builder.cc.

32  {
33  edm::LogVerbatim("SimG4CoreGeometry") << "DDG4Builder::convertLV(): DDLogicalPart = " << part;
34  G4LogicalVolume *result = logs_[part];
35  if (!result) {
36  G4VSolid *g4s = convertSolid(part.solid());
37  G4Material *g4m = convertMaterial(part.material());
38  result = new G4LogicalVolume(g4s, g4m, part.name().name());
41  theVectorOfDDG4Dispatchables_->push_back(disp);
42  edm::LogVerbatim("SimG4CoreGeometry")
43  << "DDG4Builder::convertLV(): new G4LogicalVolume " << part.name().name()
44  << "\nDDG4Builder: newEvent: dd=" << part.ddname() << " g4=" << result->GetName();
45  logs_[part] = result; // DDD -> GEANT4
46  }
47  return result;
48 }

References convertMaterial(), convertSolid(), DDMapper< KeyType, ValueType >::insert(), logs_, map_, mps_fire::result, and theVectorOfDDG4Dispatchables_.

Referenced by BuildGeometry().

◆ convertMaterial()

G4Material * DDG4Builder::convertMaterial ( const DDMaterial dMaterial)
private

Definition at line 59 of file DDG4Builder.cc.

59  {
60  edm::LogVerbatim("SimG4CoreGeometry") << "DDDetConstr::ConvertMaterial: material=" << material;
61  G4Material *result = nullptr;
62  if (material) {
63  // only if it's a valid DDD-material
64  if ((result = mats_[material])) {
65  edm::LogVerbatim("SimG4CoreGeometry") << " is already converted";
66  return result;
67  }
68  } else {
69  // only if it's NOT a valid DDD-material
70  throw cms::Exception("SimG4CoreGeometry",
71  " material is not valid from the Detector Description: " + material.toString());
72  }
73  int c = 0;
74  if ((c = material.noOfConstituents())) {
75  // it's a composite material
76  edm::LogVerbatim("SimG4CoreGeometry")
77  << " creating a G4-composite material. c=" << c << " d=" << material.density() / CLHEP::g * CLHEP::mole;
78  result = new G4Material(material.name().name(), material.density(), c);
79  for (int i = 0; i < c; ++i) {
80  // recursive building of constituents
81  edm::LogVerbatim("SimG4CoreGeometry")
82  << " adding the composite=" << material.name() << " fm=" << material.constituent(i).second;
83  result->AddMaterial(convertMaterial(material.constituent(i).first),
84  material.constituent(i).second); // fractionmass
85  }
86  } else {
87  // it's an elementary material
88  edm::LogVerbatim("SimG4CoreGeometry") << " building an elementary material"
89  << " z=" << material.z() << " a=" << material.a() / CLHEP::g * CLHEP::mole
90  << " d=" << material.density() / CLHEP::g * CLHEP::cm3;
91  result = new G4Material(material.name().name(), material.z(), material.a(), material.density());
92  }
93  mats_[material] = result;
94  return result;
95 }

References DDMaterial::a(), c, DDMaterial::constituent(), DDMaterial::density(), Exception, g, mps_fire::i, mats_, DDName::name(), DDBase< N, C >::name(), DDMaterial::noOfConstituents(), mps_fire::result, DDBase< N, C >::toString(), and DDMaterial::z().

Referenced by convertLV().

◆ convertSolid()

G4VSolid * DDG4Builder::convertSolid ( const DDSolid dSolid)
private

Definition at line 50 of file DDG4Builder.cc.

50  {
51  G4VSolid *result = sols_[solid];
52  if (!result) {
53  result = solidConverter_->convert(solid);
54  sols_[solid] = result;
55  }
56  return result;
57 }

References DDG4SolidConverter::convert(), mps_fire::result, solidConverter_, and sols_.

Referenced by convertLV().

◆ getDouble()

double DDG4Builder::getDouble ( const std::string &  s,
const DDLogicalPart dLogical 
)
private

Definition at line 215 of file DDG4Builder.cc.

215  {
216  DDValue val(ss);
217  std::vector<const DDsvalues_type *> result = part.specifics();
218  bool foundIt = false;
219  for (auto stype : result) {
220  foundIt = DDfetch(stype, val);
221  if (foundIt)
222  break;
223  }
224  if (foundIt) {
225  std::vector<std::string> temp = val.strings();
226  if (temp.size() != 1) {
227  throw cms::Exception("SimG4CoreGeometry",
228  " DDG4Builder::getDouble() Problem with Region tags "
229  "- one and only one allowed: " +
230  ss);
231  }
232  double v;
234  std::istringstream is(temp[0]);
235  is >> v >> unit;
236  v = v * G4UnitDefinition::GetValueOf(unit.substr(1, unit.size()));
237  return v;
238  } else
239  return 0;
240 }

References DDfetch(), Exception, mps_fire::result, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, groupFilesInBlocks::temp, unit(), findQualityFiles::v, and heppy_batch::val.

◆ getInt()

int DDG4Builder::getInt ( const std::string &  s,
const DDLogicalPart dLogical 
)
private

Definition at line 193 of file DDG4Builder.cc.

193  {
194  DDValue val(ss);
195  std::vector<const DDsvalues_type *> result = part.specifics();
196  bool foundIt = false;
197  for (auto stype : result) {
198  foundIt = DDfetch(stype, val);
199  if (foundIt)
200  break;
201  }
202  if (foundIt) {
203  std::vector<double> temp = val.doubles();
204  if (temp.size() != 1) {
205  throw cms::Exception("SimG4CoreGeometry",
206  " DDG4Builder::getInt() Problem with Region tags - "
207  "one and only one allowed: " +
208  ss);
209  }
210  return int(temp[0]);
211  } else
212  return 0;
213 }

References DDfetch(), Exception, createfilelist::int, mps_fire::result, contentValuesCheck::ss, groupFilesInBlocks::temp, and heppy_batch::val.

Referenced by BuildGeometry().

Member Data Documentation

◆ check_

bool DDG4Builder::check_
private

Definition at line 44 of file DDG4Builder.h.

Referenced by BuildGeometry().

◆ compactView_

const DDCompactView* DDG4Builder::compactView_
private

Definition at line 41 of file DDG4Builder.h.

Referenced by BuildGeometry().

◆ logs_

std::map<DDLogicalPart, G4LogicalVolume *> DDG4Builder::logs_
private

Definition at line 39 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

◆ map_

G4LogicalVolumeToDDLogicalPartMap& DDG4Builder::map_
private

Definition at line 42 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

◆ mats_

std::map<DDMaterial, G4Material *> DDG4Builder::mats_
private

Definition at line 37 of file DDG4Builder.h.

Referenced by convertMaterial().

◆ solidConverter_

DDG4SolidConverter* DDG4Builder::solidConverter_
private

Definition at line 36 of file DDG4Builder.h.

Referenced by convertSolid(), and ~DDG4Builder().

◆ sols_

std::map<DDSolid, G4VSolid *> DDG4Builder::sols_
private

Definition at line 38 of file DDG4Builder.h.

Referenced by convertSolid().

◆ theVectorOfDDG4Dispatchables_

DDG4DispContainer* DDG4Builder::theVectorOfDDG4Dispatchables_
private

Definition at line 43 of file DDG4Builder.h.

Referenced by BuildGeometry(), convertLV(), and DDG4Builder().

DDAxes::y
DDG4Builder::getInt
int getInt(const std::string &s, const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:193
DDG4SensitiveConverter
Definition: DDG4SensitiveConverter.h:13
mps_fire.i
i
Definition: mps_fire.py:428
DDG4Builder::logs_
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:39
getEcalConditions_orcoffint2r_cff.catalog
catalog
Definition: getEcalConditions_orcoffint2r_cff.py:40
DDG4Builder::convertLV
G4LogicalVolume * convertLV(const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:32
DDG4DispContainer
std::vector< DDG4Dispatchable * > DDG4DispContainer
Definition: DDG4DispContainer.h:8
DDG4Builder::theVectorOfDDG4Dispatchables_
DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:43
DDBase::isDefined
def_type isDefined() const
Definition: DDBase.h:90
DDG4Builder::map_
G4LogicalVolumeToDDLogicalPartMap & map_
Definition: DDG4Builder.h:42
DDG4Builder::compactView_
const DDCompactView * compactView_
Definition: DDG4Builder.h:41
DDAxes::x
findQualityFiles.v
v
Definition: findQualityFiles.py:179
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
DDG4Dispatchable
Definition: DDG4Dispatchable.h:8
DDMapper::insert
void insert(const KeyType &, const ValueType &)
insert a new key-value-pair
Definition: DDMapper.h:74
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
part
part
Definition: HCALResponse.h:20
DDCompactView::graph
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
Definition: DDCompactView.cc:59
DDBase::toString
std::string toString() const
Definition: DDBase.h:63
adjl_iterator
Graph::const_adj_iterator adjl_iterator
Definition: GeometryInfoDump.cc:19
DDAxes::z
DDG4Builder::sols_
std::map< DDSolid, G4VSolid * > sols_
Definition: DDG4Builder.h:38
DDG4Builder::check_
bool check_
Definition: DDG4Builder.h:44
DDfetch
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
DDCompactView::Graph
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
DD3Vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
Definition: PGeometricDetBuilder.cc:20
DDG4Builder::solidConverter_
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:36
DDBase::ddname
const N & ddname() const
Definition: DDBase.h:61
DDG4Builder::convertMaterial
G4Material * convertMaterial(const DDMaterial &dMaterial)
Definition: DDG4Builder.cc:59
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
createfilelist.int
int
Definition: createfilelist.py:10
DDG4Builder::mats_
std::map< DDMaterial, G4Material * > mats_
Definition: DDG4Builder.h:37
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:162
eostools.rm
def rm(path, rec=False)
Definition: eostools.py:363
DDCompactView::root
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
Definition: DDCompactView.cc:63
DDG4Builder::convertSolid
G4VSolid * convertSolid(const DDSolid &dSolid)
Definition: DDG4Builder.cc:50
heppy_batch.val
val
Definition: heppy_batch.py:351
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
DDG4SolidConverter::convert
G4VSolid * convert(const DDSolid &)
Definition: DDG4SolidConverter.cc:38
DDValue
Definition: DDValue.h:22
math::Graph< DDLogicalPart, DDPosData * >::index_type
std::vector< double >::size_type index_type
Definition: Graph.h:15
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
math::Graph< DDLogicalPart, DDPosData * >
mps_fire.result
result
Definition: mps_fire.py:311
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
edm::Log
Definition: MessageLogger.h:70
g
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
DDG4SolidConverter
Definition: DDG4SolidConverter.h:14
math::Graph< DDLogicalPart, DDPosData * >::const_adj_iterator
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105
conv
EPOS::IO_EPOS conv
Definition: ReggeGribovPartonMCHadronizer.cc:42