#include <SimG4Core/Geometry/interface/DDG4Builder.h>
Public Member Functions | |
DDGeometryReturnType | BuildGeometry () |
DDG4Builder (const DDCompactView *, bool check=false) | |
~DDG4Builder () | |
Static Public Member Functions | |
static DDG4DispContainer * | theVectorOfDDG4Dispatchables () |
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_ |
DDG4SolidConverter * | solidConverter_ |
std::map< DDSolid, G4VSolid * > | sols_ |
Private Attributes | |
bool | check_ |
const DDCompactView * | compactView |
G4LogicalVolumeToDDLogicalPartMap | map_ |
Static Private Attributes | |
static DDG4DispContainer * | theVectorOfDDG4Dispatchables_ = 0 |
Definition at line 25 of file DDG4Builder.h.
DDG4Builder::DDG4Builder | ( | const DDCompactView * | cpv, | |
bool | check = false | |||
) |
Definition at line 34 of file DDG4Builder.cc.
References theVectorOfDDG4Dispatchables_.
00034 : 00035 solidConverter_(new DDG4SolidConverter), compactView(cpv), check_(check) { 00036 theVectorOfDDG4Dispatchables_ = new DDG4DispContainer(); 00037 }
DDG4Builder::~DDG4Builder | ( | ) |
Definition at line 39 of file DDG4Builder.cc.
References solidConverter_.
00039 { 00040 delete solidConverter_; 00041 }
DDGeometryReturnType DDG4Builder::BuildGeometry | ( | ) |
Definition at line 108 of file DDG4Builder.cc.
References graph< N, E >::begin(), TestMuL1L2Filter_cff::catalog, check_, compactView, convertLV(), DDBase< N, C >::ddname(), graph< N, E >::edgeData(), graph< N, E >::end(), err, Exception, getInt(), DDCompactView::graph(), i, DDMapper< KeyType, ValueType >::insert(), DDBase< N, C >::isDefined(), LogDebug, logs_, map_, graph< N, E >::nodeData(), offset, DDCompactView::root(), ecalRecalibSequence_cff::tag, pyDBSRunClass::temp, theVectorOfDDG4Dispatchables_, DDBase< N, C >::toString(), DDG4SensitiveConverter::upDate(), x, y, and z.
00108 { 00109 G4ReflectionFactory * refFact = G4ReflectionFactory::Instance(); 00110 refFact->SetScalePrecision(100.*refFact->GetScalePrecision()); 00111 00112 const graph_type & gra = compactView->graph(); 00113 typedef graph_type::const_adj_iterator adjl_iterator; 00114 adjl_iterator git = gra.begin(); 00115 adjl_iterator gend = gra.end(); 00116 00117 graph_type::index_type i=0; 00118 for (; git != gend; ++git) { 00119 const DDLogicalPart & ddLP = gra.nodeData(git); 00120 if ( !(ddLP.isDefined().second) ) { 00121 edm::LogError("SimG4CoreGeometry") << "DDG4Builder::BuildGeometry() has encountered an undefined DDLogicalPart named " << ddLP.toString(); 00122 throw cms::Exception("SimG4CoreGeometry", " DDG4Builder::BuildGeometry() has encountered an undefined DDLogicalPart named " + ddLP.toString()); 00123 } 00124 G4LogicalVolume * g4LV = convertLV(ddLP); 00125 ++i; 00126 if (git->size()) { 00127 // ask for children of ddLP 00128 graph_type::edge_list::const_iterator cit = git->begin(); 00129 graph_type::edge_list::const_iterator cend = git->end(); 00130 for (; cit != cend; ++cit) { 00131 // fetch specific data 00132 const DDLogicalPart & ddcurLP = gra.nodeData(cit->first); 00133 if ( !ddcurLP.isDefined().second ) { 00134 std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has "; 00135 err += "encountered an undefined DDLogicalPart named " + ddLP.toString(); 00136 edm::LogError("SimG4CoreGeometry") << err; 00137 throw cms::Exception("SimG4CoreGeometry", err) ; 00138 } 00139 int offset = getInt("CopyNoOffset",ddcurLP); 00140 int tag = getInt("CopyNoTag",ddcurLP); 00141 DDRotationMatrix rm(gra.edgeData(cit->second)->rot()); 00142 DD3Vector x, y, z; 00143 rm.GetComponents(x, y, z); 00144 if ((x.Cross(y)).Dot(z)<0) 00145 LogDebug("SimG4CoreGeometry") << ">>Reflection encountered: " << gra.edgeData(cit->second)->rot_ ; 00146 LogDebug("SimG4CoreGeometry") << ">>Placement d=" << gra.nodeData(cit->first).ddname() 00147 << " m=" << ddLP.ddname() << " cp=" << gra.edgeData(cit->second)->copyno_ 00148 << " r=" << gra.edgeData(cit->second)->rot_.ddname() ; 00149 G4ThreeVector tempTran(gra.edgeData(cit->second)->trans_.X(), gra.edgeData(cit->second)->trans_.Y(), gra.edgeData(cit->second)->trans_.Z()); 00150 G4Translate3D transl = tempTran; 00151 HepRep3x3 temp( x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z() ); //matrix representation 00152 HepRotation hr ( temp ); 00153 00154 // G3 convention of defining rot-matrices ... 00155 G4Transform3D trfrm = transl * G4Rotate3D(hr.inverse());//.inverse(); 00156 00157 refFact->Place(trfrm, // transformation containing a possible reflection 00158 gra.nodeData(cit->first).name().name(), 00159 convertLV(gra.nodeData(cit->first)), // daugther 00160 g4LV, // mother 00161 false, // 'ONLY' 00162 gra.edgeData(cit->second)->copyno_+offset+tag, // copy number 00163 check_); 00164 } // iterate over children 00165 } // if (children) 00166 } // iterate over graph nodes 00167 00168 // Looking for in the G4ReflectionFactory secretly created reflected G4LogicalVolumes 00169 std::map<DDLogicalPart, G4LogicalVolume*>::const_iterator ddg4_it = logs_.begin(); 00170 for (; ddg4_it != logs_.end(); ++ddg4_it) { 00171 G4LogicalVolume * reflLogicalVolume = refFact->GetReflectedLV(ddg4_it->second); 00172 if (reflLogicalVolume) { 00173 DDLogicalPart ddlv = ddg4_it->first; 00174 map_.insert(reflLogicalVolume,ddlv); 00175 DDG4Dispatchable * disp = new DDG4Dispatchable(&(ddg4_it->first),reflLogicalVolume); 00176 theVectorOfDDG4Dispatchables_->push_back(disp); 00177 LogDebug("SimG4CoreGeometry") << "DDG4Builder: newEvent: dd=" 00178 << ddlv.ddname() << " g4=" 00179 << reflLogicalVolume->GetName(); 00180 } 00181 } 00182 00183 G4LogicalVolume * world = logs_[compactView->root()]; 00184 00185 // 00186 // needed for building sensitive detectors 00187 // 00188 DDG4SensitiveConverter conv_; 00189 SensitiveDetectorCatalog catalog = conv_.upDate(*theVectorOfDDG4Dispatchables_); 00190 00191 return DDGeometryReturnType(world,map_,catalog); 00192 }
G4LogicalVolume * DDG4Builder::convertLV | ( | const DDLogicalPart & | dLogical | ) | [protected] |
Definition at line 43 of file DDG4Builder.cc.
References convertMaterial(), convertSolid(), DDBase< N, C >::ddname(), DDMapper< KeyType, ValueType >::insert(), LogDebug, logs_, m, map_, DDLogicalPart::material(), DDName::name(), DDBase< N, C >::name(), HLT_VtxMuL3::result, s, DDLogicalPart::solid(), and theVectorOfDDG4Dispatchables_.
Referenced by BuildGeometry().
00043 { 00044 LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): DDLogicalPart = " << part; 00045 G4LogicalVolume * result = logs_[part]; 00046 if (!result) { 00047 G4VSolid * s = convertSolid(part.solid()); 00048 G4Material * m = convertMaterial(part.material()); 00049 result = new G4LogicalVolume(s,m,part.name().name()); 00050 map_.insert(result,part); 00051 DDG4Dispatchable * disp = new DDG4Dispatchable(&part,result); 00052 theVectorOfDDG4Dispatchables_->push_back(disp); 00053 LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): new G4LogicalVolume " << part.name().name() 00054 << "\nDDG4Builder: newEvent: dd=" << part.ddname() << " g4=" << result->GetName(); 00055 logs_[part] = result; // DDD -> GEANT4 00056 } 00057 return result; 00058 }
G4Material * DDG4Builder::convertMaterial | ( | const DDMaterial & | dMaterial | ) | [protected] |
Definition at line 68 of file DDG4Builder.cc.
References DDMaterial::a(), c, DDMaterial::constituent(), DDMaterial::density(), Exception, g, i, LogDebug, mats_, DDName::name(), DDBase< N, C >::name(), DDMaterial::noOfConstituents(), HLT_VtxMuL3::result, DDBase< N, C >::toString(), and DDMaterial::z().
Referenced by convertLV().
00068 { 00069 LogDebug("SimG4CoreGeometry") << "DDDetConstr::ConvertMaterial: material=" << material; 00070 G4Material * result = 0; 00071 if (material) { 00072 // only if it's a valid DDD-material 00073 if ((result = mats_[material])) { 00074 LogDebug("SimG4CoreGeometry") << " is already converted"; 00075 return result; } 00076 } else { 00077 // only if it's NOT a valid DDD-material 00078 edm::LogError("SimG4CoreGeometry") << "DDG4Builder:: material " << material.toString() << " is not valid (in the DDD sense!)"; 00079 throw cms::Exception("SimG4CoreGeometry", " material is not valid from the Detector Description: " + material.toString()); 00080 } 00081 int c = 0; 00082 if ((c = material.noOfConstituents())) { 00083 // it's a composite material 00084 LogDebug("SimG4CoreGeometry") << " creating a G4-composite material. c=" << c 00085 << " d=" << material.density()/g*mole ; 00086 result = new G4Material(material.name().name(),material.density(),c); 00087 for (int i=0 ; i<c; ++i) { 00088 // recursive building of constituents 00089 LogDebug("SimG4CoreGeometry") << " adding the composite=" << material.name() 00090 << " fm=" << material.constituent(i).second; 00091 result->AddMaterial 00092 (convertMaterial(material.constituent(i).first), 00093 material.constituent(i).second);// fractionmass 00094 } 00095 } else { 00096 // it's an elementary material 00097 LogDebug("SimG4CoreGeometry") << " building an elementary material" 00098 << " z=" << material.z() 00099 << " a=" << material.a()/g*mole 00100 << " d=" << material.density()/g*cm3 ; 00101 result = new G4Material 00102 (material.name().name(),material.z(),material.a(),material.density()); 00103 } 00104 mats_[material] = result; 00105 return result; 00106 }
G4VSolid * DDG4Builder::convertSolid | ( | const DDSolid & | dSolid | ) | [protected] |
Definition at line 60 of file DDG4Builder.cc.
References DDG4SolidConverter::convert(), HLT_VtxMuL3::result, solidConverter_, and sols_.
Referenced by convertLV().
00060 { 00061 G4VSolid * result = sols_[solid]; 00062 if (!result) { 00063 result = solidConverter_->convert(solid); sols_[solid] = result; 00064 } 00065 return result; 00066 }
double DDG4Builder::getDouble | ( | const std::string & | s, | |
const DDLogicalPart & | dLogical | |||
) | [protected] |
Definition at line 215 of file DDG4Builder.cc.
References DDfetch(), it, HLT_VtxMuL3::result, DDLogicalPart::specifics(), DDValue::strings(), pyDBSRunClass::temp, and v.
00216 { 00217 DDValue val(s); 00218 std::vector<const DDsvalues_type *> result = part.specifics(); 00219 std::vector<const DDsvalues_type *>::iterator it = result.begin(); 00220 bool foundIt = false; 00221 for (; it != result.end(); ++it) { 00222 foundIt = DDfetch(*it,val); 00223 if (foundIt) break; 00224 } 00225 if (foundIt) { 00226 std::vector<std::string> temp = val.strings(); 00227 if (temp.size() != 1) { 00228 edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << s ; 00229 throw SimG4Exception("DDG4Builder: Problem with Region tags - one and only one allowed"); 00230 } 00231 double v; 00232 std::string unit; 00233 std::istringstream is(temp[0].c_str()); 00234 is >> v >> unit; 00235 v = v*G4UnitDefinition::GetValueOf(unit.substr(1,unit.size())); 00236 return v; 00237 } 00238 else return 0; 00239 }
int DDG4Builder::getInt | ( | const std::string & | s, | |
const DDLogicalPart & | dLogical | |||
) | [protected] |
Definition at line 194 of file DDG4Builder.cc.
References DDfetch(), DDValue::doubles(), int, it, HLT_VtxMuL3::result, DDLogicalPart::specifics(), and pyDBSRunClass::temp.
Referenced by BuildGeometry().
00195 { 00196 DDValue val(s); 00197 std::vector<const DDsvalues_type *> result = part.specifics(); 00198 std::vector<const DDsvalues_type *>::iterator it = result.begin(); 00199 bool foundIt = false; 00200 for (; it != result.end(); ++it) { 00201 foundIt = DDfetch(*it,val); 00202 if (foundIt) break; 00203 } 00204 if (foundIt) { 00205 std::vector<double> temp = val.doubles(); 00206 if (temp.size() != 1) { 00207 edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << s ; 00208 throw SimG4Exception("DDG4Builder: Problem with Region tags - one and only one allowed"); 00209 } 00210 return int(temp[0]); 00211 } 00212 else return 0; 00213 }
DDG4DispContainer * DDG4Builder::theVectorOfDDG4Dispatchables | ( | ) | [static] |
Definition at line 30 of file DDG4Builder.cc.
References theVectorOfDDG4Dispatchables_.
00030 { 00031 return theVectorOfDDG4Dispatchables_; 00032 }
bool DDG4Builder::check_ [private] |
const DDCompactView* DDG4Builder::compactView [private] |
std::map<DDLogicalPart,G4LogicalVolume*> DDG4Builder::logs_ [protected] |
std::map<DDMaterial,G4Material*> DDG4Builder::mats_ [protected] |
DDG4SolidConverter* DDG4Builder::solidConverter_ [protected] |
std::map<DDSolid,G4VSolid*> DDG4Builder::sols_ [protected] |
DDG4DispContainer * DDG4Builder::theVectorOfDDG4Dispatchables_ = 0 [static, private] |
Definition at line 48 of file DDG4Builder.h.
Referenced by BuildGeometry(), convertLV(), DDG4Builder(), and theVectorOfDDG4Dispatchables().