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_.

28 }
G4LogicalVolumeToDDLogicalPartMap & map_
Definition: DDG4Builder.h:42
std::vector< DDG4Dispatchable * > DDG4DispContainer
const DDCompactView * compactView_
Definition: DDG4Builder.h:41
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:36
DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:43

◆ ~DDG4Builder()

DDG4Builder::~DDG4Builder ( )

Definition at line 30 of file DDG4Builder.cc.

References solidConverter_.

30 { delete solidConverter_; }
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:36

Member Function Documentation

◆ BuildGeometry()

G4LogicalVolume * DDG4Builder::BuildGeometry ( SensitiveDetectorCatalog catalog)

Definition at line 97 of file DDG4Builder.cc.

References getEcalConditions_orcoffint2r_cff::catalog, check_, compactView_, conv, convertLV(), DDBase< N, C >::ddname(), submitPVResolutionJobs::err, Exception, getInt(), DDCompactView::graph(), 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().

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  for (; git != gend; ++git) {
108  const DDLogicalPart &ddLP = gra.nodeData(git);
109  if (!(ddLP.isDefined().second)) {
110  throw cms::Exception("SimG4CoreGeometry",
111  " DDG4Builder::BuildGeometry() has encountered an "
112  "undefined DDLogicalPart named " +
113  ddLP.toString());
114  }
115  G4LogicalVolume *g4LV = convertLV(ddLP);
116  if (!git->empty()) {
117  // ask for children of ddLP
118  Graph::edge_list::const_iterator cit = git->begin();
119  Graph::edge_list::const_iterator cend = git->end();
120  for (; cit != cend; ++cit) {
121  // fetch specific data
122  const DDLogicalPart &ddcurLP = gra.nodeData(cit->first);
123  if (!ddcurLP.isDefined().second) {
124  std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has ";
125  err += "encountered an undefined DDLogicalPart named " + ddcurLP.toString() + " is a child of " +
126  ddLP.toString();
127  throw cms::Exception("SimG4CoreGeometry", err);
128  }
129  int offset = getInt("CopyNoOffset", ddcurLP);
130  int tag = getInt("CopyNoTag", ddcurLP);
131  DDRotationMatrix rm(gra.edgeData(cit->second)->rot());
132  DD3Vector x, y, z;
133  rm.GetComponents(x, y, z);
134  if ((x.Cross(y)).Dot(z) < 0)
135  edm::LogVerbatim("SimG4CoreGeometry")
136  << "DDG4Builder: Reflection: " << gra.edgeData(cit->second)->ddrot()
137  << ">>Placement d=" << gra.nodeData(cit->first).ddname() << " m=" << ddLP.ddname()
138  << " cp=" << gra.edgeData(cit->second)->copyno() << " r=" << gra.edgeData(cit->second)->ddrot().ddname();
139  G4ThreeVector tempTran(gra.edgeData(cit->second)->trans().X(),
140  gra.edgeData(cit->second)->trans().Y(),
141  gra.edgeData(cit->second)->trans().Z());
142  G4Translate3D transl = tempTran;
143  CLHEP::HepRep3x3 temp(x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()); // matrix
144  CLHEP::HepRotation hr(temp);
145  edm::LogVerbatim("SimG4CoreGeometry")
146  << "Position " << gra.nodeData(cit->first).name().name() << ":"
147  << gra.edgeData(cit->second)->copyno() + offset + tag << " in " << g4LV->GetName() << " at " << tempTran
148  << " with rotation matrix (" << x.X() << ", " << x.Y() << ", " << x.Z() << ", " << y.X() << ", " << y.Y()
149  << ", " << y.Z() << ", " << z.X() << ", " << z.Y() << ", " << z.Z() << ")";
150 
151  // G3 convention of defining rot-matrices ...
152  G4Transform3D trfrm = transl * G4Rotate3D(hr.inverse()); //.inverse();
153 
154  refFact->Place(trfrm, // transformation containing a possible reflection
155  gra.nodeData(cit->first).name().name(),
156  convertLV(gra.nodeData(cit->first)), // daugther
157  g4LV, // mother
158  false, // 'ONLY'
159  gra.edgeData(cit->second)->copyno() + offset + tag, // copy number
160  check_);
161  } // iterate over children
162  } // if (children)
163  } // iterate over graph nodes
164 
165  // Looking for in the G4ReflectionFactory secretly created reflected
166  // G4LogicalVolumes
167  std::map<DDLogicalPart, G4LogicalVolume *>::const_iterator ddg4_it = logs_.begin();
168  for (; ddg4_it != logs_.end(); ++ddg4_it) {
169  G4LogicalVolume *reflLogicalVolume = refFact->GetReflectedLV(ddg4_it->second);
170  if (reflLogicalVolume) {
171  DDLogicalPart ddlv = ddg4_it->first;
172  map_.insert(reflLogicalVolume, ddlv);
173  DDG4Dispatchable *disp = new DDG4Dispatchable(&(ddg4_it->first), reflLogicalVolume);
174  theVectorOfDDG4Dispatchables_->push_back(disp);
175  edm::LogVerbatim("SimG4CoreGeometry")
176  << "DDG4Builder: dd=" << ddlv.ddname() << " g4=" << reflLogicalVolume->GetName();
177  }
178  }
179 
180  G4LogicalVolume *world = logs_[compactView_->root()];
181 
182  //
183  // needed for building sensitive detectors
184  //
187 
188  return world;
189 }
Log< level::Info, true > LogVerbatim
def rm(path, rec=False)
Definition: eostools.py:363
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:39
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
G4LogicalVolume * convertLV(const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:32
G4LogicalVolumeToDDLogicalPartMap & map_
Definition: DDG4Builder.h:42
const DDCompactView * compactView_
Definition: DDG4Builder.h:41
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::string toString() const
Definition: DDBase.h:63
Graph::const_adj_iterator adjl_iterator
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
const N & ddname() const
Definition: DDBase.h:61
EPOS::IO_EPOS conv
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105
void insert(const KeyType &, const ValueType &)
insert a new key-value-pair
Definition: DDMapper.h:74
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
def_type isDefined() const
Definition: DDBase.h:90
DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:43
int getInt(const std::string &s, const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:191

◆ convertLV()

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

Definition at line 32 of file DDG4Builder.cc.

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

Referenced by BuildGeometry().

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 }
Log< level::Info, true > LogVerbatim
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:39
G4LogicalVolumeToDDLogicalPartMap & map_
Definition: DDG4Builder.h:42
G4Material * convertMaterial(const DDMaterial &dMaterial)
Definition: DDG4Builder.cc:59
part
Definition: HCALResponse.h:20
G4VSolid * convertSolid(const DDSolid &dSolid)
Definition: DDG4Builder.cc:50
void insert(const KeyType &, const ValueType &)
insert a new key-value-pair
Definition: DDMapper.h:74
DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:43

◆ convertMaterial()

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

Definition at line 59 of file DDG4Builder.cc.

References DDMaterial::a(), HltBtagPostValidation_cff::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().

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 }
Log< level::Info, true > LogVerbatim
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
G4Material * convertMaterial(const DDMaterial &dMaterial)
Definition: DDG4Builder.cc:59
std::map< DDMaterial, G4Material * > mats_
Definition: DDG4Builder.h:37

◆ convertSolid()

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

Definition at line 50 of file DDG4Builder.cc.

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

Referenced by convertLV().

50  {
51  G4VSolid *result = sols_[solid];
52  if (!result) {
53  result = solidConverter_->convert(solid);
54  sols_[solid] = result;
55  }
56  return result;
57 }
std::map< DDSolid, G4VSolid * > sols_
Definition: DDG4Builder.h:38
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:36
G4VSolid * convert(const DDSolid &)

◆ getDouble()

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

Definition at line 213 of file DDG4Builder.cc.

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

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

◆ getInt()

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

Definition at line 191 of file DDG4Builder.cc.

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

Referenced by BuildGeometry().

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

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().