CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes

DDG4Builder Class Reference

#include <DDG4Builder.h>

List of all members.

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 25 of file DDG4Builder.h.


Constructor & Destructor Documentation

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

Definition at line 39 of file DDG4Builder.cc.

References solidConverter_.

                          { 
  delete solidConverter_; 
}

Member Function Documentation

DDGeometryReturnType DDG4Builder::BuildGeometry ( )

Definition at line 108 of file DDG4Builder.cc.

References validate_alignment_devdb10_cfg::catalog, check_, compactView, convertLV(), DDBase< N, C >::ddname(), Exception, getInt(), DDCompactView::graph(), i, DDMapper< KeyType, ValueType >::insert(), DDBase< N, C >::isDefined(), LogDebug, logs_, map_, evf::evtn::offset(), submit::rm, DDCompactView::root(), GlobalPosition_Frontier_DevDB_cff::tag, groupFilesInBlocks::temp, theVectorOfDDG4Dispatchables_, DDBase< N, C >::toString(), DDG4SensitiveConverter::upDate(), x, detailsBasic3DVector::y, and z.

                                                {
  G4ReflectionFactory * refFact = G4ReflectionFactory::Instance();
  refFact->SetScalePrecision(100.*refFact->GetScalePrecision());

  typedef DDCompactView::graph_type graph_type;
  const graph_type & gra = compactView->graph();
  typedef graph_type::const_adj_iterator adjl_iterator;
  adjl_iterator git = gra.begin();
  adjl_iterator gend = gra.end();    

  graph_type::index_type i=0;
  for (; git != gend; ++git) {
    const DDLogicalPart & ddLP = gra.nodeData(git);
    if ( !(ddLP.isDefined().second) ) {
      edm::LogError("SimG4CoreGeometry") << "DDG4Builder::BuildGeometry() has encountered an undefined DDLogicalPart named " << ddLP.toString();
      throw cms::Exception("SimG4CoreGeometry", " DDG4Builder::BuildGeometry() has encountered an undefined DDLogicalPart named " + ddLP.toString());
    }
    G4LogicalVolume * g4LV = convertLV(ddLP);
    ++i;        
    if (git->size()) {
      // ask for children of ddLP  
      graph_type::edge_list::const_iterator cit  = git->begin();
      graph_type::edge_list::const_iterator cend = git->end();
      for (; cit != cend; ++cit) {
        // fetch specific data
        const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
        if ( !ddcurLP.isDefined().second ) {
          std::string err = " DDG4Builder::BuildGeometry() in processing \"children\" has ";
          err += "encountered an undefined DDLogicalPart named " + ddLP.toString();
          edm::LogError("SimG4CoreGeometry") << err;
          throw cms::Exception("SimG4CoreGeometry", err) ;
        }
        int offset = getInt("CopyNoOffset",ddcurLP);
        int tag = getInt("CopyNoTag",ddcurLP);                          
        DDRotationMatrix rm(gra.edgeData(cit->second)->rot());
        DD3Vector x, y, z;
        rm.GetComponents(x, y, z);
        if ((x.Cross(y)).Dot(z)<0)
          LogDebug("SimG4CoreGeometry") << ">>Reflection encountered: " << gra.edgeData(cit->second)->rot_ ;
        LogDebug("SimG4CoreGeometry") << ">>Placement d=" << gra.nodeData(cit->first).ddname() 
                                      << " m=" << ddLP.ddname() << " cp=" << gra.edgeData(cit->second)->copyno_
                                      << " r=" << gra.edgeData(cit->second)->rot_.ddname() ;          
        G4ThreeVector tempTran(gra.edgeData(cit->second)->trans_.X(), gra.edgeData(cit->second)->trans_.Y(), gra.edgeData(cit->second)->trans_.Z());
        G4Translate3D transl = tempTran;
        CLHEP::HepRep3x3 temp( x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z() ); //matrix representation
        CLHEP::HepRotation hr ( temp );
            
        // G3 convention of defining rot-matrices ...
        G4Transform3D trfrm  = transl * G4Rotate3D(hr.inverse());//.inverse();

        refFact->Place(trfrm, // transformation containing a possible reflection
                       gra.nodeData(cit->first).name().name(),
                       convertLV(gra.nodeData(cit->first)),             // daugther
                       g4LV,                                            // mother
                       false,                                           // 'ONLY'
                       gra.edgeData(cit->second)->copyno_+offset+tag,   // copy number
                       check_);
      } // iterate over children
    } // if (children)
  } // iterate over graph nodes  
    
  // Looking for in the G4ReflectionFactory secretly created reflected G4LogicalVolumes
  std::map<DDLogicalPart, G4LogicalVolume*>::const_iterator  ddg4_it = logs_.begin();
  for (; ddg4_it != logs_.end(); ++ddg4_it) {
    G4LogicalVolume * reflLogicalVolume = refFact->GetReflectedLV(ddg4_it->second);
    if (reflLogicalVolume) {
      DDLogicalPart ddlv = ddg4_it->first;
      map_.insert(reflLogicalVolume,ddlv);
      DDG4Dispatchable * disp = new DDG4Dispatchable(&(ddg4_it->first),reflLogicalVolume);
      theVectorOfDDG4Dispatchables_->push_back(disp);
      LogDebug("SimG4CoreGeometry") << "DDG4Builder: newEvent: dd=" 
                                    << ddlv.ddname() << " g4=" 
                                    << reflLogicalVolume->GetName();
    }  
  }
      
  G4LogicalVolume * world = logs_[compactView->root()];

  //
  //  needed for building sensitive detectors
  //
  DDG4SensitiveConverter conv_;
  SensitiveDetectorCatalog catalog = conv_.upDate(*theVectorOfDDG4Dispatchables_);

  return DDGeometryReturnType(world,map_,catalog);    
}
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(), query::result, alignCSCRings::s, DDLogicalPart::solid(), and theVectorOfDDG4Dispatchables_.

Referenced by BuildGeometry().

                                                                   {
  LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): DDLogicalPart = " << part;
  G4LogicalVolume * result = logs_[part];
  if (!result) {
    G4VSolid * s   = convertSolid(part.solid());
    G4Material * m = convertMaterial(part.material());
    result = new G4LogicalVolume(s,m,part.name().name());
    map_.insert(result,part);
    DDG4Dispatchable * disp = new DDG4Dispatchable(&part,result);       
    theVectorOfDDG4Dispatchables_->push_back(disp);
    LogDebug("SimG4CoreGeometry") << "DDG4Builder::convertLV(): new G4LogicalVolume " << part.name().name()
                                  << "\nDDG4Builder: newEvent: dd=" << part.ddname() << " g4=" << result->GetName();
    logs_[part] = result;  // DDD -> GEANT4  
  }
  return result;
}
G4Material * DDG4Builder::convertMaterial ( const DDMaterial dMaterial) [protected]

Definition at line 68 of file DDG4Builder.cc.

References DDMaterial::a(), trackerHits::c, DDMaterial::constituent(), DDMaterial::density(), Exception, g, i, LogDebug, mats_, DDName::name(), DDBase< N, C >::name(), DDMaterial::noOfConstituents(), query::result, DDBase< N, C >::toString(), and DDMaterial::z().

Referenced by convertLV().

                                                                     {
  LogDebug("SimG4CoreGeometry") << "DDDetConstr::ConvertMaterial: material=" << material;
  G4Material * result = 0;
  if (material) {
    // only if it's a valid DDD-material
    if ((result = mats_[material])) {
      LogDebug("SimG4CoreGeometry") << "  is already converted"; 
      return result; }
  } else {
    // only if it's NOT a valid DDD-material
    edm::LogError("SimG4CoreGeometry") << "DDG4Builder::  material " << material.toString() << " is not valid (in the DDD sense!)";
    throw cms::Exception("SimG4CoreGeometry", " material is not valid from the Detector Description: " + material.toString()); 
  }    
  int c = 0;
  if ((c = material.noOfConstituents())) {
    // it's a composite material
    LogDebug("SimG4CoreGeometry") << "  creating a G4-composite material. c=" << c
                                  << " d=" << material.density()/g*mole ;
    result = new G4Material(material.name().name(),material.density(),c);
    for (int i=0 ; i<c; ++i) {
      // recursive building of constituents
      LogDebug("SimG4CoreGeometry") << "  adding the composite=" << material.name()
                                    << " fm=" << material.constituent(i).second;
      result->AddMaterial
        (convertMaterial(material.constituent(i).first),
         material.constituent(i).second);// fractionmass
    }
  } else {
    // it's an elementary material
    LogDebug("SimG4CoreGeometry") << "  building an elementary material"
                                  << " z=" << material.z()
                                  << " a=" << material.a()/g*mole
                                  << " d=" << material.density()/g*cm3 ;
    result = new G4Material
      (material.name().name(),material.z(),material.a(),material.density());
  }
  mats_[material] = result;
  return result;
} 
G4VSolid * DDG4Builder::convertSolid ( const DDSolid dSolid) [protected]

Definition at line 60 of file DDG4Builder.cc.

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

Referenced by convertLV().

                                                          {
  G4VSolid * result = sols_[solid];
  if (!result) { 
    result = solidConverter_->convert(solid); sols_[solid] = result; 
  }
  return result;
}
double DDG4Builder::getDouble ( const std::string &  s,
const DDLogicalPart dLogical 
) [protected]

Definition at line 216 of file DDG4Builder.cc.

References DDfetch(), query::result, alignCSCRings::s, DDLogicalPart::specifics(), DDValue::strings(), groupFilesInBlocks::temp, csvLumiCalc::unit, and v.

                                                          {
  DDValue val(s);
  std::vector<const DDsvalues_type *> result = part.specifics();
  std::vector<const DDsvalues_type *>::iterator it = result.begin();
  bool foundIt = false;
  for (; it != result.end(); ++it) {
    foundIt = DDfetch(*it,val);
    if (foundIt) break;
  }    
  if (foundIt) { 
    std::vector<std::string> temp = val.strings();
    if (temp.size() != 1) {
      edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << s ;
      throw SimG4Exception("DDG4Builder: Problem with Region tags - one and only one allowed");
    }
    double v;
    std::string unit;
    std::istringstream is(temp[0].c_str());
    is >> v >> unit;
    v  = v*G4UnitDefinition::GetValueOf(unit.substr(1,unit.size()));
    return v;
  }
  else return 0;
}
int DDG4Builder::getInt ( const std::string &  s,
const DDLogicalPart dLogical 
) [protected]

Definition at line 195 of file DDG4Builder.cc.

References DDfetch(), DDValue::doubles(), query::result, alignCSCRings::s, DDLogicalPart::specifics(), and groupFilesInBlocks::temp.

Referenced by BuildGeometry().

{
  DDValue val(s);
  std::vector<const DDsvalues_type *> result = part.specifics();
  std::vector<const DDsvalues_type *>::iterator it = result.begin();
  bool foundIt = false;
  for (; it != result.end(); ++it) {
    foundIt = DDfetch(*it,val);
    if (foundIt) break;
  }    
  if (foundIt) { 
    std::vector<double> temp = val.doubles();
    if (temp.size() != 1) {
      edm::LogError("SimG4CoreGeometry") << " DDG4Builder - ERROR: I need only 1 " << s ;
      throw SimG4Exception("DDG4Builder: Problem with Region tags - one and only one allowed");
    }      
    return int(temp[0]);
  }
  else return 0;
}
DDG4DispContainer * DDG4Builder::theVectorOfDDG4Dispatchables ( ) [static]

Definition at line 30 of file DDG4Builder.cc.

References theVectorOfDDG4Dispatchables_.


Member Data Documentation

bool DDG4Builder::check_ [private]

Definition at line 50 of file DDG4Builder.h.

Referenced by BuildGeometry().

Definition at line 47 of file DDG4Builder.h.

Referenced by BuildGeometry().

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

Definition at line 44 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

Definition at line 49 of file DDG4Builder.h.

Referenced by BuildGeometry(), and convertLV().

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

Definition at line 42 of file DDG4Builder.h.

Referenced by convertMaterial().

Definition at line 41 of file DDG4Builder.h.

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

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

Definition at line 43 of file DDG4Builder.h.

Referenced by convertSolid().

Definition at line 48 of file DDG4Builder.h.

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