CMS 3D CMS Logo

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

#include <DDG4Builder.h>

Public Member Functions

DDGeometryReturnType BuildGeometry ()
 
 DDG4Builder (const DDCompactView *, bool check=false)
 
 ~DDG4Builder ()
 

Static Public Member Functions

static DDG4DispContainertheVectorOfDDG4Dispatchables ()
 

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

Protected Attributes

std::map< DDLogicalPart, G4LogicalVolume * > logs_
 
std::map< DDMaterial, G4Material * > mats_
 
DDG4SolidConvertersolidConverter_
 
std::map< DDSolid, G4VSolid * > sols_
 

Private Attributes

bool check_
 
const DDCompactViewcompactView
 
G4LogicalVolumeToDDLogicalPartMap map_
 

Static Private Attributes

static DDG4DispContainertheVectorOfDDG4Dispatchables_ = 0
 

Detailed Description

Definition at line 22 of file DDG4Builder.h.

Constructor & Destructor Documentation

DDG4Builder::DDG4Builder ( const DDCompactView cpv,
bool  check = false 
)

Definition at line 32 of file DDG4Builder.cc.

References theVectorOfDDG4Dispatchables_.

35 }
std::vector< DDG4Dispatchable * > DDG4DispContainer
const DDCompactView * compactView
Definition: DDG4Builder.h:43
static DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:44
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:37
def check(config)
Definition: trackerTree.py:14
DDG4Builder::~DDG4Builder ( )

Definition at line 37 of file DDG4Builder.cc.

References solidConverter_.

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

Member Function Documentation

DDGeometryReturnType DDG4Builder::BuildGeometry ( )

Definition at line 107 of file DDG4Builder.cc.

References getEcalConditions_orcoffint2r_cff::catalog, check_, compactView, convertLV(), DDBase< N, C >::ddname(), Exception, getInt(), DDCompactView::graph(), AnalysisDataFormats_SUSYBSMObjects::hr, mps_fire::i, DDMapper< KeyType, ValueType >::insert(), DDBase< N, C >::isDefined(), logs_, map_, PFRecoTauDiscriminationByIsolation_cfi::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.

107  {
108  G4ReflectionFactory *refFact = G4ReflectionFactory::Instance();
109  refFact->SetScalePrecision(100. * refFact->GetScalePrecision());
110 
111  using Graph = DDCompactView::Graph;
112  const auto &gra = compactView->graph();
114  adjl_iterator git = gra.begin();
115  adjl_iterator gend = gra.end();
116 
117  Graph::index_type i = 0;
118  for (; git != gend; ++git) {
119  const DDLogicalPart &ddLP = gra.nodeData(git);
120  if (!(ddLP.isDefined().second)) {
121  edm::LogError("SimG4CoreGeometry") << "DDG4Builder::BuildGeometry() has encountered an undefined "
122  "DDLogicalPart named "
123  << ddLP.toString();
124  throw cms::Exception("SimG4CoreGeometry",
125  " DDG4Builder::BuildGeometry() has encountered an "
126  "undefined DDLogicalPart named " +
127  ddLP.toString());
128  }
129  G4LogicalVolume *g4LV = convertLV(ddLP);
130  ++i;
131  if (!git->empty()) {
132  // ask for children of ddLP
133  Graph::edge_list::const_iterator cit = git->begin();
134  Graph::edge_list::const_iterator cend = git->end();
135  for (; cit != cend; ++cit) {
136  // fetch specific data
137  const DDLogicalPart &ddcurLP = gra.nodeData(cit->first);
138  if (!ddcurLP.isDefined().second) {
139  std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has ";
140  err += "encountered an undefined DDLogicalPart named " + ddcurLP.toString() + " is a child of " +
141  ddLP.toString();
142  edm::LogError("SimG4CoreGeometry") << err;
143  throw cms::Exception("SimG4CoreGeometry", err);
144  }
145  int offset = getInt("CopyNoOffset", ddcurLP);
146  int tag = getInt("CopyNoTag", ddcurLP);
147  DDRotationMatrix rm(gra.edgeData(cit->second)->rot());
148  DD3Vector x, y, z;
149  rm.GetComponents(x, y, z);
150  if ((x.Cross(y)).Dot(z) < 0)
151  edm::LogInfo("SimG4CoreGeometry")
152  << ">>Reflection encountered: " << gra.edgeData(cit->second)->ddrot()
153  << ">>Placement d=" << gra.nodeData(cit->first).ddname() << " m=" << ddLP.ddname()
154  << " cp=" << gra.edgeData(cit->second)->copyno() << " r=" << gra.edgeData(cit->second)->ddrot().ddname();
155  G4ThreeVector tempTran(gra.edgeData(cit->second)->trans().X(),
156  gra.edgeData(cit->second)->trans().Y(),
157  gra.edgeData(cit->second)->trans().Z());
158  G4Translate3D transl = tempTran;
159  CLHEP::HepRep3x3 temp(x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()); // matrix representation
160  CLHEP::HepRotation hr(temp);
161 
162  // G3 convention of defining rot-matrices ...
163  G4Transform3D trfrm = transl * G4Rotate3D(hr.inverse()); //.inverse();
164 
165  refFact->Place(trfrm, // transformation containing a possible reflection
166  gra.nodeData(cit->first).name().name(),
167  convertLV(gra.nodeData(cit->first)), // daugther
168  g4LV, // mother
169  false, // 'ONLY'
170  gra.edgeData(cit->second)->copyno() + offset + tag, // copy number
171  check_);
172  } // iterate over children
173  } // if (children)
174  } // iterate over graph nodes
175 
176  // Looking for in the G4ReflectionFactory secretly created reflected
177  // G4LogicalVolumes
178  std::map<DDLogicalPart, G4LogicalVolume *>::const_iterator ddg4_it = logs_.begin();
179  for (; ddg4_it != logs_.end(); ++ddg4_it) {
180  G4LogicalVolume *reflLogicalVolume = refFact->GetReflectedLV(ddg4_it->second);
181  if (reflLogicalVolume) {
182  DDLogicalPart ddlv = ddg4_it->first;
183  map_.insert(reflLogicalVolume, ddlv);
184  DDG4Dispatchable *disp = new DDG4Dispatchable(&(ddg4_it->first), reflLogicalVolume);
185  theVectorOfDDG4Dispatchables_->push_back(disp);
186  edm::LogInfo("SimG4CoreGeometry") << "DDG4Builder: newEvent: dd=" << ddlv.ddname()
187  << " g4=" << reflLogicalVolume->GetName();
188  }
189  }
190 
191  G4LogicalVolume *world = logs_[compactView->root()];
192 
193  //
194  // needed for building sensitive detectors
195  //
198 
199  return DDGeometryReturnType(world, map_, catalog);
200 }
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:40
def_type isDefined() const
Definition: DDBase.h:107
G4LogicalVolume * convertLV(const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:39
std::vector< double >::size_type index_type
Definition: Graph.h:16
const DDCompactView * compactView
Definition: DDG4Builder.h:43
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
static DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:44
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:78
SensitiveDetectorCatalog upDate(const DDG4DispContainer &ddg4s)
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:125
void insert(const KeyType &, const ValueType &)
insert a new key-value-pair
Definition: DDMapper.h:77
rm
Definition: submit.py:77
G4LogicalVolumeToDDLogicalPartMap map_
Definition: DDG4Builder.h:45
int getInt(const std::string &s, const DDLogicalPart &dLogical)
Definition: DDG4Builder.cc:202
const N & ddname() const
Definition: DDBase.h:76
G4LogicalVolume * DDG4Builder::convertLV ( const DDLogicalPart dLogical)
protected

Definition at line 39 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().

39  {
40  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): DDLogicalPart = " << part << "\n";
41  G4LogicalVolume *result = logs_[part];
42  if (!result) {
43  G4VSolid *g4s = convertSolid(part.solid());
44  G4Material *g4m = convertMaterial(part.material());
45  result = new G4LogicalVolume(g4s, g4m, part.name().name());
46  map_.insert(result, part);
47  DDG4Dispatchable *disp = new DDG4Dispatchable(&part, result);
48  theVectorOfDDG4Dispatchables_->push_back(disp);
49  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): new G4LogicalVolume " << part.name().name()
50  << "\nDDG4Builder: newEvent: dd=" << part.ddname() << " g4=" << result->GetName()
51  << "\n";
52  logs_[part] = result; // DDD -> GEANT4
53  }
54  return result;
55 }
#define LogDebug(id)
std::map< DDLogicalPart, G4LogicalVolume * > logs_
Definition: DDG4Builder.h:40
static DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:44
G4Material * convertMaterial(const DDMaterial &dMaterial)
Definition: DDG4Builder.cc:66
part
Definition: HCALResponse.h:20
G4VSolid * convertSolid(const DDSolid &dSolid)
Definition: DDG4Builder.cc:57
void insert(const KeyType &, const ValueType &)
insert a new key-value-pair
Definition: DDMapper.h:77
G4LogicalVolumeToDDLogicalPartMap map_
Definition: DDG4Builder.h:45
G4Material * DDG4Builder::convertMaterial ( const DDMaterial dMaterial)
protected

Definition at line 66 of file DDG4Builder.cc.

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

66  {
67  LogDebug("SimG4CoreGeometry") << "DDDetConstr::ConvertMaterial: material=" << material << "\n";
68  G4Material *result = nullptr;
69  if (material) {
70  // only if it's a valid DDD-material
71  if ((result = mats_[material])) {
72  LogDebug("SimG4CoreGeometry") << " is already converted"
73  << "\n";
74  return result;
75  }
76  } else {
77  // only if it's NOT a valid DDD-material
78  edm::LogError("SimG4CoreGeometry") << "DDG4Builder:: material " << material.toString()
79  << " is not valid (in the DDD sense!)";
80  throw cms::Exception("SimG4CoreGeometry",
81  " material is not valid from the Detector Description: " + material.toString());
82  }
83  int c = 0;
84  if ((c = material.noOfConstituents())) {
85  // it's a composite material
86  LogDebug("SimG4CoreGeometry") << " creating a G4-composite material. c=" << c
87  << " d=" << material.density() / g * mole << "\n";
88  result = new G4Material(material.name().name(), material.density(), c);
89  for (int i = 0; i < c; ++i) {
90  // recursive building of constituents
91  LogDebug("SimG4CoreGeometry") << " adding the composite=" << material.name()
92  << " fm=" << material.constituent(i).second << "\n";
93  result->AddMaterial(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() << " a=" << material.a() / g * mole
100  << " d=" << material.density() / g * cm3 << "\n";
101  result = new G4Material(material.name().name(), material.z(), material.a(), material.density());
102  }
103  mats_[material] = result;
104  return result;
105 }
#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:66
std::map< DDMaterial, G4Material * > mats_
Definition: DDG4Builder.h:38
G4VSolid * DDG4Builder::convertSolid ( const DDSolid dSolid)
protected

Definition at line 57 of file DDG4Builder.cc.

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

Referenced by convertLV().

57  {
58  G4VSolid *result = sols_[solid];
59  if (!result) {
60  result = solidConverter_->convert(solid);
61  sols_[solid] = result;
62  }
63  return result;
64 }
std::map< DDSolid, G4VSolid * > sols_
Definition: DDG4Builder.h:39
DDG4SolidConverter * solidConverter_
Definition: DDG4Builder.h:37
G4VSolid * convert(const DDSolid &)
double DDG4Builder::getDouble ( const std::string &  s,
const DDLogicalPart dLogical 
)
protected

Definition at line 225 of file DDG4Builder.cc.

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

225  {
226  DDValue val(ss);
227  std::vector<const DDsvalues_type *> result = part.specifics();
228  bool foundIt = false;
229  for (auto stype : result) {
230  foundIt = DDfetch(stype, val);
231  if (foundIt)
232  break;
233  }
234  if (foundIt) {
235  std::vector<std::string> temp = val.strings();
236  if (temp.size() != 1) {
237  edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << ss;
238  throw cms::Exception("SimG4CoreGeometry",
239  " DDG4Builder::getDouble() Problem with Region tags "
240  "- one and only one allowed: " +
241  ss);
242  }
243  double v;
245  std::istringstream is(temp[0]);
246  is >> v >> unit;
247  v = v * G4UnitDefinition::GetValueOf(unit.substr(1, unit.size()));
248  return v;
249  } else
250  return 0;
251 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
part
Definition: HCALResponse.h:20
int DDG4Builder::getInt ( const std::string &  s,
const DDLogicalPart dLogical 
)
protected

Definition at line 202 of file DDG4Builder.cc.

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

Referenced by BuildGeometry().

202  {
203  DDValue val(ss);
204  std::vector<const DDsvalues_type *> result = part.specifics();
205  bool foundIt = false;
206  for (auto stype : result) {
207  foundIt = DDfetch(stype, val);
208  if (foundIt)
209  break;
210  }
211  if (foundIt) {
212  std::vector<double> temp = val.doubles();
213  if (temp.size() != 1) {
214  edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << ss;
215  throw cms::Exception("SimG4CoreGeometry",
216  " DDG4Builder::getInt() Problem with Region tags - "
217  "one and only one allowed: " +
218  ss);
219  }
220  return int(temp[0]);
221  } else
222  return 0;
223 }
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
part
Definition: HCALResponse.h:20
DDG4DispContainer * DDG4Builder::theVectorOfDDG4Dispatchables ( )
static

Definition at line 30 of file DDG4Builder.cc.

References theVectorOfDDG4Dispatchables_.

static DDG4DispContainer * theVectorOfDDG4Dispatchables_
Definition: DDG4Builder.h:44

Member Data Documentation

bool DDG4Builder::check_
private

Definition at line 46 of file DDG4Builder.h.

Referenced by BuildGeometry().

const DDCompactView* DDG4Builder::compactView
private

Definition at line 43 of file DDG4Builder.h.

Referenced by BuildGeometry().

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

Definition at line 40 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

G4LogicalVolumeToDDLogicalPartMap DDG4Builder::map_
private

Definition at line 45 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

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

Definition at line 38 of file DDG4Builder.h.

Referenced by convertMaterial().

DDG4SolidConverter* DDG4Builder::solidConverter_
protected

Definition at line 37 of file DDG4Builder.h.

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

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

Definition at line 39 of file DDG4Builder.h.

Referenced by convertSolid().

DDG4DispContainer * DDG4Builder::theVectorOfDDG4Dispatchables_ = 0
staticprivate

Definition at line 44 of file DDG4Builder.h.

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