#include <Fireworks/Geometry/interface/TGeoMgrFromDdd.h>
Public Types | |
typedef boost::shared_ptr < TGeoManager > | ReturnType |
Public Member Functions | |
ReturnType | produce (const DisplayGeomRecord &) |
TGeoMgrFromDdd (const edm::ParameterSet &) | |
virtual | ~TGeoMgrFromDdd () |
Private Member Functions | |
TGeoManager * | createManager (int level) |
TGeoMaterial * | createMaterial (const DDMaterial &iMaterial) |
TGeoShape * | createShape (const std::string &iName, const DDSolid &iSolid) |
TGeoVolume * | createVolume (const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial) |
const TGeoMgrFromDdd & | operator= (const TGeoMgrFromDdd &) |
TGeoMgrFromDdd (const TGeoMgrFromDdd &) | |
Private Attributes | |
int | m_level |
bool | m_verbose |
std::map< std::string, TGeoMaterial * > | nameToMaterial_ |
std::map< std::string, TGeoMedium * > | nameToMedium_ |
std::map< std::string, TGeoShape * > | nameToShape_ |
std::map< std::string, TGeoVolume * > | nameToVolume_ |
Description: [one line class summary]
Usage: <usage>
Definition at line 48 of file TGeoMgrFromDdd.h.
typedef boost::shared_ptr<TGeoManager> TGeoMgrFromDdd::ReturnType |
Definition at line 54 of file TGeoMgrFromDdd.h.
TGeoMgrFromDdd::TGeoMgrFromDdd | ( | const edm::ParameterSet & | pset | ) |
Definition at line 48 of file TGeoMgrFromDdd.cc.
References edm::ESProducer::setWhatProduced().
: m_level( pset.getUntrackedParameter<int> ( "level", 10 )), m_verbose( pset.getUntrackedParameter<bool>( "verbose", false )) { // The following line is needed to tell the framework what data is // being produced. setWhatProduced( this ); }
TGeoMgrFromDdd::~TGeoMgrFromDdd | ( | void | ) | [virtual] |
Definition at line 57 of file TGeoMgrFromDdd.cc.
{}
TGeoMgrFromDdd::TGeoMgrFromDdd | ( | const TGeoMgrFromDdd & | ) | [private] |
TGeoManager* TGeoMgrFromDdd::createManager | ( | int | level | ) | [private] |
TGeoMaterial * TGeoMgrFromDdd::createMaterial | ( | const DDMaterial & | iMaterial | ) | [private] |
Definition at line 647 of file TGeoMgrFromDdd.cc.
References DDMaterial::a(), DDMaterial::constituent(), DDMaterial::density(), DDName::fullname(), g, i, reco_application_tbsim_DetSim-Digi_cfg::mix, DDBase< N, C >::name(), nameToMaterial_, DDMaterial::noOfConstituents(), and DDMaterial::z().
Referenced by createVolume().
{ std::string mat_name = iMaterial.name().fullname(); TGeoMaterial *mat = nameToMaterial_[mat_name]; if (mat == 0) { if (iMaterial.noOfConstituents() > 0) { TGeoMixture *mix = new TGeoMixture(mat_name.c_str(), iMaterial.noOfConstituents(), iMaterial.density()*cm3/g); for (int i = 0; i < iMaterial.noOfConstituents(); ++i) { mix->AddElement(createMaterial(iMaterial.constituent(i).first), iMaterial.constituent(i).second); } mat = mix; } else { mat = new TGeoMaterial(mat_name.c_str(), iMaterial.a()*mole/g, iMaterial.z(), iMaterial.density()*cm3/g); } nameToMaterial_[mat_name] = mat; } return mat; }
TGeoShape * TGeoMgrFromDdd::createShape | ( | const std::string & | iName, |
const DDSolid & | iSolid | ||
) | [private] |
Definition at line 222 of file TGeoMgrFromDdd.cc.
References abs, alpha, DDPseudoTrap::atMinusZ(), dtNoiseDBValidation_cfg::cerr, filterCSVwithJSON::copy, funct::cos(), DDTruncTubs::cutAtDelta(), DDTruncTubs::cutAtStart(), DDTruncTubs::cutInside(), ddbox, ddcons, ddintersection, ddpolycone_rrz, ddpolyhedra_rrz, ddpseudotrap, ddsubtraction, ddtorus, ddtrap, ddtrunctubs, ddtubs, ddunion, delta, DDTorus::deltaPhi(), SiPixelRawToDigiRegional_cfi::deltaPhi, DDTruncTubs::deltaPhi(), Exception, DDName::fullname(), h, DDPseudoTrap::halfZ(), LogDebug, DDRotation::matrix(), DDName::name(), DDBase< N, C >::name(), mergeVDriftHistosByStation::name, nameToShape_, dttmaxenums::R, alignCSCRings::r, DDPseudoTrap::radius(), DDTruncTubs::rIn(), DDTorus::rMax(), DDTorus::rMin(), makeMuonMisalignmentScenario::rot, DDBooleanSolid::rotation(), DDTruncTubs::rOut(), DDTorus::rTorus(), alignCSCRings::s, funct::sin(), DDBooleanSolid::solidA(), DDBooleanSolid::solidB(), mathSSE::sqrt(), DDTruncTubs::startPhi(), DDTorus::startPhi(), groupFilesInBlocks::temp, DDBooleanSolid::translation(), groupFilesInBlocks::tt, x, DDPseudoTrap::x1(), DDPseudoTrap::x2(), DDPseudoTrap::y1(), DDPseudoTrap::y2(), and DDTruncTubs::zHalf().
Referenced by createVolume().
{ LogDebug("TGeoMgrFromDdd::createShape") << "with name: " << iName << " and solid: " << iSolid; DDBase<DDName, DDI::Solid*>::def_type defined( iSolid.isDefined()); if( !defined.first ) throw cms::Exception("TGeoMgrFromDdd::createShape * solid " + iName + " is not declared * " ); if( !defined.second ) throw cms::Exception("TGeoMgrFromDdd::createShape * solid " + defined.first->name() + " is not defined *" ); TGeoShape* rSolid= nameToShape_[iName]; if (rSolid == 0) { const std::vector<double>& params = iSolid.parameters(); switch(iSolid.shape()) { case ddbox: rSolid = new TGeoBBox( iName.c_str(), params[0]/cm, params[1]/cm, params[2]/cm); break; case ddcons: rSolid = new TGeoConeSeg( iName.c_str(), params[0]/cm, params[1]/cm, params[2]/cm, params[3]/cm, params[4]/cm, params[5]/deg, params[6]/deg+params[5]/deg ); break; case ddtubs: //Order in params is zhalf,rIn,rOut,startPhi,deltaPhi rSolid= new TGeoTubeSeg( iName.c_str(), params[1]/cm, params[2]/cm, params[0]/cm, params[3]/deg, params[3]/deg + params[4]/deg); break; case ddtrap: rSolid =new TGeoTrap( iName.c_str(), params[0]/cm, //dz params[1]/deg, //theta params[2]/deg, //phi params[3]/cm, //dy1 params[4]/cm, //dx1 params[5]/cm, //dx2 params[6]/deg, //alpha1 params[7]/cm, //dy2 params[8]/cm, //dx3 params[9]/cm, //dx4 params[10]/deg);//alpha2 break; case ddpolycone_rrz: rSolid = new TGeoPcon( iName.c_str(), params[0]/deg, params[1]/deg, (params.size()-2)/3) ; { std::vector<double> temp(params.size()+1); temp.reserve(params.size()+1); temp[0]=params[0]/deg; temp[1]=params[1]/deg; temp[2]=(params.size()-2)/3; std::copy(params.begin()+2,params.end(),temp.begin()+3); for(std::vector<double>::iterator it=temp.begin()+3; it != temp.end(); ++it) { *it /=cm; } rSolid->SetDimensions(&(*(temp.begin()))); } break; case ddpolyhedra_rrz: rSolid = new TGeoPgon( iName.c_str(), params[1]/deg, params[2]/deg, static_cast<int>(params[0]), (params.size()-3)/3); { std::vector<double> temp(params.size()+1); temp[0]=params[1]/deg; temp[1]=params[2]/deg; temp[2]=params[0]; temp[3]=(params.size()-3)/3; std::copy(params.begin()+3,params.end(),temp.begin()+4); for(std::vector<double>::iterator it=temp.begin()+4; it != temp.end(); ++it) { *it /=cm; } rSolid->SetDimensions(&(*(temp.begin()))); } break; case ddpseudotrap: { //implementation taken from SimG4Core/Geometry/src/DDG4SolidConverter.cc static DDRotationMatrix s_rot( ROOT::Math::RotationX( 90.*deg )); DDPseudoTrap pt( iSolid ); double r = pt.radius(); bool atMinusZ = pt.atMinusZ(); double x = 0; double h = 0; bool intersec = false; // union or intersection solid if( atMinusZ ) { x = pt.x1(); // tubs radius } else { x = pt.x2(); // tubs radius } double halfOpeningAngle = asin( x / abs( r ))/deg; double displacement = 0; double startPhi = 0; /* calculate the displacement of the tubs w.r.t. to the trap, determine the opening angle of the tubs */ double delta = sqrt( r * r - x * x ); if( r < 0 && abs( r ) >= x ) { intersec = true; // intersection solid h = pt.y1() < pt.y2() ? pt.y2() : pt.y1(); // tubs half height h += h/20.; // enlarge a bit - for subtraction solid if( atMinusZ ) { displacement = - pt.halfZ() - delta; startPhi = 90. - halfOpeningAngle; } else { displacement = pt.halfZ() + delta; startPhi = -90.- halfOpeningAngle; } } else if( r > 0 && abs( r ) >= x ) { if( atMinusZ ) { displacement = - pt.halfZ() + delta; startPhi = 270.- halfOpeningAngle; h = pt.y1(); } else { displacement = pt.halfZ() - delta; startPhi = 90. - halfOpeningAngle; h = pt.y2(); } } else { throw cms::Exception( "Check parameters of the PseudoTrap! name=" + pt.name().name()); } std::auto_ptr<TGeoShape> trap( new TGeoTrd2( pt.name().name().c_str(), pt.x1()/cm, pt.x2()/cm, pt.y1()/cm, pt.y2()/cm, pt.halfZ()/cm )); std::auto_ptr<TGeoShape> tubs( new TGeoTubeSeg( pt.name().name().c_str(), 0., abs(r)/cm, // radius cannot be negative!!! h/cm, startPhi, startPhi + halfOpeningAngle * 2. )); if( intersec ) { TGeoSubtraction* sub = new TGeoSubtraction( trap.release(), tubs.release(), 0, createPlacement( s_rot, DDTranslation( 0., 0., displacement ))); rSolid = new TGeoCompositeShape( iName.c_str(), sub ); } else { std::auto_ptr<TGeoShape> box( new TGeoBBox( 1.1*x/cm, 1.1*h/cm, sqrt(r*r-x*x)/cm )); TGeoSubtraction* sub = new TGeoSubtraction( tubs.release(), box.release(), 0, createPlacement( s_rot, DDTranslation( 0., 0., 0. ))); std::auto_ptr<TGeoShape> tubicCap( new TGeoCompositeShape( iName.c_str(), sub )); TGeoUnion* boolS = new TGeoUnion( trap.release(), tubicCap.release(), 0, createPlacement( s_rot, DDTranslation( 0., 0., displacement ))); rSolid = new TGeoCompositeShape( iName.c_str(), boolS ); } break; } case ddtorus: { DDTorus solid( iSolid ); rSolid = new TGeoTorus( iName.c_str(), solid.rTorus()/cm, solid.rMin()/cm, solid.rMax()/cm, solid.startPhi()/deg, solid.deltaPhi()/deg); break; } case ddsubtraction: { DDBooleanSolid boolSolid(iSolid); if(!boolSolid) { throw cms::Exception("GeomConvert") <<"conversion to DDBooleanSolid failed"; } std::auto_ptr<TGeoShape> left( createShape(boolSolid.solidA().name().fullname(), boolSolid.solidA()) ); std::auto_ptr<TGeoShape> right( createShape(boolSolid.solidB().name().fullname(), boolSolid.solidB())); if( 0 != left.get() && 0 != right.get() ) { TGeoSubtraction* sub = new TGeoSubtraction(left.release(),right.release(), 0, createPlacement( *(boolSolid.rotation().matrix()), boolSolid.translation())); rSolid = new TGeoCompositeShape(iName.c_str(), sub); } break; } case ddtrunctubs: { DDTruncTubs tt( iSolid ); if( !tt ) { throw cms::Exception( "GeomConvert" ) << "conversion to DDTruncTubs failed"; } double rIn( tt.rIn()); double rOut( tt.rOut()); double zHalf( tt.zHalf()); double startPhi( tt.startPhi()); double deltaPhi( tt.deltaPhi()); double cutAtStart( tt.cutAtStart()); double cutAtDelta( tt.cutAtDelta()); bool cutInside( bool( tt.cutInside())); std::string name = tt.name().name(); // check the parameters if( rIn <= 0 || rOut <=0 || cutAtStart <=0 || cutAtDelta <= 0 ) { std::string s = "TruncTubs " + std::string( tt.name().fullname()) + ": 0 <= rIn,cutAtStart,rOut,cutAtDelta,rOut violated!"; throw cms::Exception( s ); } if( rIn >= rOut ) { std::string s = "TruncTubs " + std::string( tt.name().fullname()) + ": rIn<rOut violated!"; throw cms::Exception(s); } if( startPhi != 0. ) { std::string s= "TruncTubs " + std::string( tt.name().fullname()) + ": startPhi != 0 not supported!"; throw cms::Exception( s ); } startPhi = 0.; double r( cutAtStart ); double R( cutAtDelta ); // Note: startPhi is always 0.0 std::auto_ptr<TGeoShape> tubs( new TGeoTubeSeg( name.c_str(), rIn/cm, rOut/cm, zHalf/cm, startPhi, deltaPhi/deg )); double boxX( rOut ), boxY( rOut ); // exaggerate dimensions - does not matter, it's subtracted! // width of the box > width of the tubs double boxZ( 1.1 * zHalf ); // angle of the box w.r.t. tubs double cath = r - R * cos( deltaPhi ); double hypo = sqrt( r * r + R * R - 2. * r * R * cos( deltaPhi )); double cos_alpha = cath / hypo; double alpha = -acos( cos_alpha ); // rotationmatrix of box w.r.t. tubs TGeoRotation rot; rot.RotateX( 90 ); rot.RotateZ( alpha/deg ); // center point of the box double xBox; if( !cutInside ) { xBox = r + boxX / sin( fabs( alpha )); } else { xBox = - ( boxX / sin( fabs( alpha )) - r ); } std::auto_ptr<TGeoShape> box( new TGeoBBox( name.c_str(), boxX/cm, boxZ/cm, boxY/cm )); TGeoTranslation trans( xBox/cm, 0., 0.); TGeoSubtraction* sub = new TGeoSubtraction( tubs.release(), box.release(), 0, new TGeoCombiTrans( trans, rot )); rSolid = new TGeoCompositeShape( iName.c_str(), sub ); break; } case ddunion: { DDBooleanSolid boolSolid(iSolid); if(!boolSolid) { throw cms::Exception("GeomConvert") <<"conversion to DDBooleanSolid failed"; } std::auto_ptr<TGeoShape> left( createShape(boolSolid.solidA().name().fullname(), boolSolid.solidA()) ); std::auto_ptr<TGeoShape> right( createShape(boolSolid.solidB().name().fullname(), boolSolid.solidB())); //DEBUGGING //break; if( 0 != left.get() && 0 != right.get() ) { TGeoUnion* boolS = new TGeoUnion(left.release(),right.release(), 0, createPlacement( *(boolSolid.rotation().matrix()), boolSolid.translation())); rSolid = new TGeoCompositeShape(iName.c_str(), boolS); } break; } case ddintersection: { DDBooleanSolid boolSolid(iSolid); if(!boolSolid) { throw cms::Exception("GeomConvert") <<"conversion to DDBooleanSolid failed"; } std::auto_ptr<TGeoShape> left( createShape(boolSolid.solidA().name().fullname(), boolSolid.solidA()) ); std::auto_ptr<TGeoShape> right( createShape(boolSolid.solidB().name().fullname(), boolSolid.solidB())); if( 0 != left.get() && 0 != right.get() ) { TGeoIntersection* boolS = new TGeoIntersection(left.release(), right.release(), 0, createPlacement( *(boolSolid.rotation().matrix()), boolSolid.translation())); rSolid = new TGeoCompositeShape(iName.c_str(), boolS); } break; } default: break; } nameToShape_[iName]=rSolid; } if (rSolid == 0) { std::cerr <<"COULD NOT MAKE "<<iName<<" of a shape "<<iSolid<<std::endl; } LogDebug("TGeoMgrFromDdd::createShape") << "solid " << iName << " has been created."; return rSolid; }
TGeoVolume * TGeoMgrFromDdd::createVolume | ( | const std::string & | iName, |
const DDSolid & | iSolid, | ||
const DDMaterial & | iMaterial | ||
) | [private] |
Definition at line 618 of file TGeoMgrFromDdd.cc.
References createMaterial(), createShape(), DDName::fullname(), DDBase< N, C >::name(), nameToMedium_, nameToVolume_, and v.
Referenced by produce().
{ TGeoVolume* v=nameToVolume_[iName]; if (v == 0) { TGeoShape* solid = createShape(iSolid.name().fullname(), iSolid); std::string mat_name = iMaterial.name().fullname(); TGeoMedium *geo_med = nameToMedium_[mat_name]; if (geo_med == 0) { TGeoMaterial *geo_mat = createMaterial(iMaterial); geo_med = new TGeoMedium(mat_name.c_str(), 0, geo_mat); nameToMedium_[mat_name] = geo_med; } if (solid) { v = new TGeoVolume(iName.c_str(), solid, geo_med); } nameToVolume_[iName] = v; } return v; }
const TGeoMgrFromDdd& TGeoMgrFromDdd::operator= | ( | const TGeoMgrFromDdd & | ) | [private] |
TGeoMgrFromDdd::ReturnType TGeoMgrFromDdd::produce | ( | const DisplayGeomRecord & | iRecord | ) |
Definition at line 89 of file TGeoMgrFromDdd.cc.
References gather_cfg::cout, createVolume(), edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::getRecord(), i, info, m_level, m_verbose, mergeVDriftHistosByStation::name, nameToMaterial_, nameToMedium_, nameToShape_, and nameToVolume_.
{ using namespace edm; ESTransientHandle<DDCompactView> viewH; iRecord.getRecord<IdealGeometryRecord>().get(viewH); if ( ! viewH.isValid()) { return boost::shared_ptr<TGeoManager>(); } TGeoManager *geo_mgr = new TGeoManager("cmsGeo","CMS Detector"); // NOTE: the default constructor does not create the identity matrix if (gGeoIdentity == 0) { gGeoIdentity = new TGeoIdentity("Identity"); } std::cout << "about to initialize the DDCompactView walker" << std::endl; DDCompactView::walker_type walker(viewH->graph()); DDCompactView::walker_type::value_type info = walker.current(); // The top most item is actually the volume holding both the // geometry AND the magnetic field volumes! walker.firstChild(); if( ! walker.firstChild()) { return boost::shared_ptr<TGeoManager>(); } TGeoVolume *top = createVolume(info.first.name().fullname(), info.first.solid(), info.first.material()); if (top == 0) { return boost::shared_ptr<TGeoManager>(); } geo_mgr->SetTopVolume(top); // ROOT chokes unless colors are assigned top->SetVisibility(kFALSE); top->SetLineColor(kBlue); std::vector<TGeoVolume*> parentStack; parentStack.push_back(top); do { DDCompactView::walker_type::value_type info = walker.current(); if (m_verbose) { for(unsigned int i=0; i<parentStack.size();++i) { std::cout <<" "; } std::cout << info.first.name()<<" "<<info.second->copyno_<<" " << DDSolidShapesName::name(info.first.solid().shape())<<std::endl; } bool childAlreadyExists = (0 != nameToVolume_[info.first.name().fullname()]); TGeoVolume *child = createVolume(info.first.name().fullname(), info.first.solid(), info.first.material()); if (0!=child && info.second != 0) { parentStack.back()->AddNode(child, info.second->copyno_, createPlacement(info.second->rotation(), info.second->translation())); child->SetLineColor(kBlue); } else { if ( info.second == 0 ) { break; } } if (0 == child || childAlreadyExists || m_level == int(parentStack.size())) { if (0!=child) { child->SetLineColor(kRed); } //stop descending if ( ! walker.nextSibling()) { while (walker.parent()) { parentStack.pop_back(); if (walker.nextSibling()) { break; } } } } else { if (walker.firstChild()) { parentStack.push_back(child); } else { if ( ! walker.nextSibling()) { while (walker.parent()) { parentStack.pop_back(); if (walker.nextSibling()) { break; } } } } } } while ( ! parentStack.empty()); geo_mgr->CloseGeometry(); geo_mgr->DefaultColors(); nameToShape_.clear(); nameToVolume_.clear(); nameToMaterial_.clear(); nameToMedium_.clear(); return boost::shared_ptr<TGeoManager>(geo_mgr); }
int TGeoMgrFromDdd::m_level [private] |
Definition at line 80 of file TGeoMgrFromDdd.h.
Referenced by produce().
bool TGeoMgrFromDdd::m_verbose [private] |
Definition at line 81 of file TGeoMgrFromDdd.h.
Referenced by produce().
std::map<std::string, TGeoMaterial*> TGeoMgrFromDdd::nameToMaterial_ [private] |
Definition at line 85 of file TGeoMgrFromDdd.h.
Referenced by createMaterial(), and produce().
std::map<std::string, TGeoMedium*> TGeoMgrFromDdd::nameToMedium_ [private] |
Definition at line 86 of file TGeoMgrFromDdd.h.
Referenced by createVolume(), and produce().
std::map<std::string, TGeoShape*> TGeoMgrFromDdd::nameToShape_ [private] |
Definition at line 83 of file TGeoMgrFromDdd.h.
Referenced by createShape(), and produce().
std::map<std::string, TGeoVolume*> TGeoMgrFromDdd::nameToVolume_ [private] |
Definition at line 84 of file TGeoMgrFromDdd.h.
Referenced by createVolume(), and produce().