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

Definition at line 30 of file DDG4Builder.cc.

References solidConverter_.

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

Member Function Documentation

G4LogicalVolume * DDG4Builder::BuildGeometry ( SensitiveDetectorCatalog catalog)

Definition at line 100 of file DDG4Builder.cc.

References check_, compactView_, conv, convertLV(), DDBase< N, C >::ddname(), runTheMatrix::err, Exception, getInt(), DDCompactView::graph(), AnalysisDataFormats_SUSYBSMObjects::hr, mps_fire::i, DDMapper< KeyType, ValueType >::insert(), DDBase< N, C >::isDefined(), logs_, map_, hltrates_dqm_sourceclient-live_cfg::offset, submit::rm, DDCompactView::root(), AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, groupFilesInBlocks::temp, theVectorOfDDG4Dispatchables_, DDBase< N, C >::toString(), DDG4SensitiveConverter::upDate(), x, y, and z.

Referenced by DDDWorld::DDDWorld().

100  {
101  G4ReflectionFactory *refFact = G4ReflectionFactory::Instance();
102  refFact->SetScalePrecision(100. * refFact->GetScalePrecision());
103 
104  using Graph = DDCompactView::Graph;
105  const auto &gra = compactView_->graph();
107  adjl_iterator git = gra.begin();
108  adjl_iterator gend = gra.end();
109 
110  Graph::index_type i = 0;
111  for (; git != gend; ++git) {
112  const DDLogicalPart &ddLP = gra.nodeData(git);
113  if (!(ddLP.isDefined().second)) {
114  edm::LogError("SimG4CoreGeometry") << "DDG4Builder::BuildGeometry() has encountered an undefined "
115  "DDLogicalPart named "
116  << ddLP.toString();
117  throw cms::Exception("SimG4CoreGeometry",
118  " DDG4Builder::BuildGeometry() has encountered an "
119  "undefined DDLogicalPart named " +
120  ddLP.toString());
121  }
122  G4LogicalVolume *g4LV = convertLV(ddLP);
123  ++i;
124  if (!git->empty()) {
125  // ask for children of ddLP
126  Graph::edge_list::const_iterator cit = git->begin();
127  Graph::edge_list::const_iterator cend = git->end();
128  for (; cit != cend; ++cit) {
129  // fetch specific data
130  const DDLogicalPart &ddcurLP = gra.nodeData(cit->first);
131  if (!ddcurLP.isDefined().second) {
132  std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has ";
133  err += "encountered an undefined DDLogicalPart named " + ddcurLP.toString() + " is a child of " +
134  ddLP.toString();
135  edm::LogError("SimG4CoreGeometry") << err;
136  throw cms::Exception("SimG4CoreGeometry", err);
137  }
138  int offset = getInt("CopyNoOffset", ddcurLP);
139  int tag = getInt("CopyNoTag", ddcurLP);
140  DDRotationMatrix rm(gra.edgeData(cit->second)->rot());
141  DD3Vector x, y, z;
142  rm.GetComponents(x, y, z);
143  if ((x.Cross(y)).Dot(z) < 0)
144  edm::LogVerbatim("SimG4CoreGeometry")
145  << "DDG4Builder: Reflection: " << gra.edgeData(cit->second)->ddrot()
146  << ">>Placement d=" << gra.nodeData(cit->first).ddname() << " m=" << ddLP.ddname()
147  << " cp=" << gra.edgeData(cit->second)->copyno() << " r=" << gra.edgeData(cit->second)->ddrot().ddname();
148  G4ThreeVector tempTran(gra.edgeData(cit->second)->trans().X(),
149  gra.edgeData(cit->second)->trans().Y(),
150  gra.edgeData(cit->second)->trans().Z());
151  G4Translate3D transl = tempTran;
152  CLHEP::HepRep3x3 temp(x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()); // matrix
153  CLHEP::HepRotation hr(temp);
154 
155  // G3 convention of defining rot-matrices ...
156  G4Transform3D trfrm = transl * G4Rotate3D(hr.inverse()); //.inverse();
157 
158  refFact->Place(trfrm, // transformation containing a possible reflection
159  gra.nodeData(cit->first).name().name(),
160  convertLV(gra.nodeData(cit->first)), // daugther
161  g4LV, // mother
162  false, // 'ONLY'
163  gra.edgeData(cit->second)->copyno() + offset + tag, // copy number
164  check_);
165  } // iterate over children
166  } // if (children)
167  } // iterate over graph nodes
168 
169  // Looking for in the G4ReflectionFactory secretly created reflected
170  // 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  edm::LogVerbatim("SimG4CoreGeometry")
180  << "DDG4Builder: dd=" << ddlv.ddname() << " g4=" << reflLogicalVolume->GetName();
181  }
182  }
183 
184  G4LogicalVolume *world = logs_[compactView_->root()];
185 
186  //
187  // needed for building sensitive detectors
188  //
190  conv.upDate(*theVectorOfDDG4Dispatchables_, catalog);
191 
192  return world;
193 }
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:39
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:82
def_type isDefined() const
Definition: DDBase.h:90
G4LogicalVolume * convertLV(const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:32
std::vector< double >::size_type index_type
Definition: Graph.h:15
static HepMC::IO_HEPEVT conv
G4LogicalVolumeToDDLogicalPartMap & map_
Definition: DDG4Builder.h:42
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
void upDate(const DDG4DispContainer &ddg4s, SensitiveDetectorCatalog &)
const DDCompactView * compactView_
Definition: DDG4Builder.h:41
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
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
Graph::const_adj_iterator adjl_iterator
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
std::string toString() const
Definition: DDBase.h:63
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
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
rm
Definition: submit.py:77
DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:43
int getInt(const std::string &s, const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:195
const N & ddname() const
Definition: DDBase.h:61
G4LogicalVolume * DDG4Builder::convertLV ( const DDLogicalPart dLogical)
private

Definition at line 32 of file DDG4Builder.cc.

References convertMaterial(), convertSolid(), DDBase< N, C >::ddname(), DDMapper< KeyType, ValueType >::insert(), LogDebug, logs_, map_, DDLogicalPart::material(), DDName::name(), DDBase< N, C >::name(), mps_fire::result, DDLogicalPart::solid(), and theVectorOfDDG4Dispatchables_.

Referenced by BuildGeometry().

32  {
33  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): DDLogicalPart = " << part << "\n";
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());
39  map_.insert(result, part);
40  DDG4Dispatchable *disp = new DDG4Dispatchable(&part, result);
41  theVectorOfDDG4Dispatchables_->push_back(disp);
42  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): new G4LogicalVolume " << part.name().name()
43  << "\nDDG4Builder: newEvent: dd=" << part.ddname() << " g4=" << result->GetName()
44  << "\n";
45  logs_[part] = result; // DDD -> GEANT4
46  }
47  return result;
48 }
#define LogDebug(id)
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
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, LogDebug, mats_, DDName::name(), DDBase< N, C >::name(), DDMaterial::noOfConstituents(), mps_fire::result, DDBase< N, C >::toString(), and DDMaterial::z().

Referenced by convertLV().

59  {
60  LogDebug("SimG4CoreGeometry") << "DDDetConstr::ConvertMaterial: material=" << material << "\n";
61  G4Material *result = nullptr;
62  if (material) {
63  // only if it's a valid DDD-material
64  if ((result = mats_[material])) {
65  LogDebug("SimG4CoreGeometry") << " is already converted"
66  << "\n";
67  return result;
68  }
69  } else {
70  // only if it's NOT a valid DDD-material
71  edm::LogError("SimG4CoreGeometry") << "DDG4Builder:: material " << material.toString()
72  << " is not valid (in the DDD sense!)";
73  throw cms::Exception("SimG4CoreGeometry",
74  " material is not valid from the Detector Description: " + material.toString());
75  }
76  int c = 0;
77  if ((c = material.noOfConstituents())) {
78  // it's a composite material
79  LogDebug("SimG4CoreGeometry") << " creating a G4-composite material. c=" << c
80  << " d=" << material.density() / g * mole << "\n";
81  result = new G4Material(material.name().name(), material.density(), c);
82  for (int i = 0; i < c; ++i) {
83  // recursive building of constituents
84  LogDebug("SimG4CoreGeometry") << " adding the composite=" << material.name()
85  << " fm=" << material.constituent(i).second << "\n";
86  result->AddMaterial(convertMaterial(material.constituent(i).first),
87  material.constituent(i).second); // fractionmass
88  }
89  } else {
90  // it's an elementary material
91  LogDebug("SimG4CoreGeometry") << " building an elementary material"
92  << " z=" << material.z() << " a=" << material.a() / g * mole
93  << " d=" << material.density() / g * cm3 << "\n";
94  result = new G4Material(material.name().name(), material.z(), material.a(), material.density());
95  }
96  mats_[material] = result;
97  return result;
98 }
#define LogDebug(id)
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
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 &)
double DDG4Builder::getDouble ( const std::string &  s,
const DDLogicalPart dLogical 
)
private

Definition at line 218 of file DDG4Builder.cc.

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

218  {
219  DDValue val(ss);
220  std::vector<const DDsvalues_type *> result = part.specifics();
221  bool foundIt = false;
222  for (auto stype : result) {
223  foundIt = DDfetch(stype, val);
224  if (foundIt)
225  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 " << ss;
231  throw cms::Exception("SimG4CoreGeometry",
232  " DDG4Builder::getDouble() Problem with Region tags "
233  "- one and only one allowed: " +
234  ss);
235  }
236  double v;
238  std::istringstream is(temp[0]);
239  is >> v >> unit;
240  v = v * G4UnitDefinition::GetValueOf(unit.substr(1, unit.size()));
241  return v;
242  } else
243  return 0;
244 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
part
Definition: HCALResponse.h:20
Basic3DVector unit() const
int DDG4Builder::getInt ( const std::string &  s,
const DDLogicalPart dLogical 
)
private

Definition at line 195 of file DDG4Builder.cc.

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

Referenced by BuildGeometry().

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

bool DDG4Builder::check_
private

Definition at line 44 of file DDG4Builder.h.

Referenced by BuildGeometry().

const DDCompactView* DDG4Builder::compactView_
private

Definition at line 41 of file DDG4Builder.h.

Referenced by BuildGeometry().

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

Definition at line 39 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

G4LogicalVolumeToDDLogicalPartMap& DDG4Builder::map_
private

Definition at line 42 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

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

Definition at line 37 of file DDG4Builder.h.

Referenced by convertMaterial().

DDG4SolidConverter* DDG4Builder::solidConverter_
private

Definition at line 36 of file DDG4Builder.h.

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

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

Definition at line 38 of file DDG4Builder.h.

Referenced by convertSolid().

DDG4DispContainer* DDG4Builder::theVectorOfDDG4Dispatchables_
private

Definition at line 43 of file DDG4Builder.h.

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