diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp index 2ed34c77f8ee2f16293f9c79c4ad1e3445a59b69..0e7be990cb770caed703e2805c57a968b285b8d4 100644 --- a/DDCore/src/LCDDImp.cpp +++ b/DDCore/src/LCDDImp.cpp @@ -231,23 +231,24 @@ void LCDDImp::endDocument() { TGeoManager* mgr = m_manager; if ( !mgr->IsClosed() ) { LCDD& lcdd = *this; + +#if 0 Region trackingRegion("TrackingRegion"); trackingRegion.setThreshold(1); trackingRegion.setStoreSecondaries(true); add(trackingRegion); m_trackingVol.setRegion(trackingRegion); - - // Set the world volume to invisible. - VisAttr worldVis("WorldVis"); - worldVis.setVisible(false); - m_worldVol.setVisAttributes(worldVis); - add(worldVis); - // Set the tracking volume to invisible. VisAttr trackingVis("TrackingVis"); trackingVis.setVisible(false); m_trackingVol.setVisAttributes(trackingVis); add(trackingVis); +#endif + // Set the world volume to invisible. + VisAttr worldVis("WorldVis"); + worldVis.setVisible(false); + m_worldVol.setVisAttributes(worldVis); + add(worldVis); /// Since we allow now for anonymous shapes, /// we will rename them to use the name of the volume they are assigned to @@ -264,21 +265,25 @@ void LCDDImp::init() { Material vacuum = material("Vacuum"); Material air = material("Air"); Volume world("world_volume",worldSolid,air); + + m_world = TopDetElement("world",world); + m_worldVol = world; + +#if 0 Tube trackingSolid("tracking_cylinder", 0., _toDouble("tracking_region_radius"), _toDouble("2*tracking_region_zmax"),2*M_PI); Volume tracking("tracking_volume",trackingSolid, air); - m_world = TopDetElement("world",world); m_trackers = TopDetElement("tracking",tracking); m_trackingVol = tracking; - m_worldVol = world; PlacedVolume pv = m_worldVol.placeVolume(tracking); m_trackers.setPlacement(pv); + m_world.add(m_trackers); +#endif m_materialAir = air; m_materialVacuum = vacuum; m_detectors.append(m_world); - m_world.add(m_trackers); m_manager->SetTopVolume(m_worldVol); m_world.setPlacement(PlacedVolume(mgr->GetTopNode())); } diff --git a/DDCore/src/Printout.cpp b/DDCore/src/Printout.cpp index 8fa08cff6ac6a7d90ddab2de45ef7cfcc24d913d..99a3ee1eeda17e46cc39d83a1e1d7b66db1fc170 100644 --- a/DDCore/src/Printout.cpp +++ b/DDCore/src/Printout.cpp @@ -42,7 +42,7 @@ int DD4hep::printout(PrintLevel severity, const char* src, const char* fmt, ...) } - /// Set new print level. Returns the old print level +/// Set new print level. Returns the old print level DD4hep::PrintLevel DD4hep::setPrintLevel(PrintLevel new_level) { PrintLevel old = print_lvl; print_lvl = new_level; diff --git a/DDCore/src/VolumeManager.cpp b/DDCore/src/VolumeManager.cpp index babf5c3110515a8eb6132656b8f549982707300a..0012ea5c264f0103dec5c17cbd5a1f7e57fa1269 100644 --- a/DDCore/src/VolumeManager.cpp +++ b/DDCore/src/VolumeManager.cpp @@ -298,7 +298,7 @@ VolumeManager VolumeManager::addSubdetector(DetElement detector, Readout ro) { } return (*i).second; } - throw runtime_error("VolumeManager::addSubdetector: Failed to add subdetector section. [Invalid Handle]"); + throw runtime_error("VolumeManager::addSubdetector: Failed to add subdetector section. [Invalid Manager Handle]"); } /// Access the volume manager by cell id @@ -314,7 +314,7 @@ VolumeManager VolumeManager::subdetector(VolumeID id) const { } throw runtime_error("VolumeManager::subdetector(VolID): Attempt to access unknown subdetector section."); } - throw runtime_error("VolumeManager::subdetector(VolID): Cannot assign ID descriptor [Invalid Handle]"); + throw runtime_error("VolumeManager::subdetector(VolID): Cannot assign ID descriptor [Invalid Manager Handle]"); } /// Assign the top level detector element to this manager @@ -328,7 +328,7 @@ void VolumeManager::setDetector(DetElement e, Readout ro) { } throw runtime_error("VolumeManager::setDetector: Cannot assign invalid detector element [Invalid Handle]"); } - throw runtime_error("VolumeManager::setDetector: Cannot assign detector element [Invalid Handle]"); + throw runtime_error("VolumeManager::setDetector: Cannot assign detector element [Invalid Manager Handle]"); } /// Access the top level detector element @@ -347,7 +347,7 @@ void VolumeManager::setIDDescriptor(IDDescriptor new_descriptor) const { return; } } - throw runtime_error("VolumeManager::setIDDescriptor: Cannot assign ID descriptor [Invalid Handle]"); + throw runtime_error("VolumeManager::setIDDescriptor: Cannot assign ID descriptor [Invalid Manager Handle]"); } /// Access IDDescription structure @@ -423,7 +423,7 @@ bool VolumeManager::adoptPlacement(Context* context) { err << "Failed to add new physical volume to detector:" << o.detector.name() << " [Invalid object]"; goto Fail; } - err << "Failed to add new physical volume [Invalid Handle]"; + err << "Failed to add new physical volume [Invalid Manager Handle]"; goto Fail; Fail: throw runtime_error(err.str()); @@ -449,7 +449,7 @@ VolumeManager::Context* VolumeManager::lookupContext(VolumeID volume_id) const } throw runtime_error("VolumeManager::lookupContext: Failed to search Volume context [Unknown identifier]"); } - throw runtime_error("VolumeManager::lookupContext: Failed to search Volume context [Invalid Handle]"); + throw runtime_error("VolumeManager::lookupContext: Failed to search Volume context [Invalid Manager Handle]"); } /// Lookup a physical (placed) volume identified by its 64 bit hit ID @@ -523,7 +523,7 @@ VolumeManager::Context* VolumeManager::lookupContext(PlacedVolume pv) const thro } throw runtime_error("VolumeManager::lookupContext: Failed to search Volume context [Unknown identifier]"); } - throw runtime_error("VolumeManager::lookupContext: Failed to search Volume context [Invalid Handle]"); + throw runtime_error("VolumeManager::lookupContext: Failed to search Volume context [Invalid Manager Handle]"); } /// Access the physical volume identifier from the placed volume diff --git a/DDExamples/CLICSiDSimu/src/SteppingAction.cpp b/DDExamples/CLICSiDSimu/src/SteppingAction.cpp index b09800aac66b751643aeafe9d0fef1d8e654ca14..5fb2e5abb942f840df4c5f971817c2919b0fb3a6 100644 --- a/DDExamples/CLICSiDSimu/src/SteppingAction.cpp +++ b/DDExamples/CLICSiDSimu/src/SteppingAction.cpp @@ -56,14 +56,14 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) { long(step.track),pos2.R()/cm,len/cm,step.sdName(step.pre,"----"), step.preStepStatus(), edep/keV); } -#if 0 + ::printf(" Track:%08ld Pos:(%8f %8f %8f) -> (%f %f %f) Mom:%7.0f %7.0f %7.0f \n", long(step.track), pos1.X(), pos1.Y(), pos1.Z(), pos2.X(), pos2.Y(), pos2.Z(), mom.X(), mom.Y(), mom.Z()); ::printf(" pre-Vol: %s Status:%s SD:%s\n", step.volName(step.pre,"----"), step.preStepStatus(), step.sdName(step.pre,"----")); ::printf(" post-Vol:%s Status:%s SD:%s\n", step.volName(step.post,"----"), step.postStepStatus(), step.sdName(step.post,"----")); -#endif + const G4VPhysicalVolume* pv = step.volume(step.post); Geometry::PlacedVolume place = mapping.placement(pv); if ( place.isValid() ) { @@ -75,4 +75,6 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) { printf(" Found Sensitive TGeoNode:%s CellID: %lld!\n",place.name(),cell_id); } } +#if 0 +#endif } diff --git a/DDExamples/ILDExDet/compact/geant4.xml b/DDExamples/ILDExDet/compact/geant4.xml index 56a194f608b9e9824b39837f17634435fb455ee8..9172429531b31209156dcb2a369cd954cd2c9adb 100644 --- a/DDExamples/ILDExDet/compact/geant4.xml +++ b/DDExamples/ILDExDet/compact/geant4.xml @@ -19,6 +19,13 @@ verbose="true" hit_aggregation="position"> </sd> + <sd name="HcalBarrel" + type="Geant4Calorimeter" + ecut="0.5*keV" + verbose="true" + hit_aggregation="position"> + </sd> + </sensitive_detectors> <properties> diff --git a/DDG4/include/DDG4/Geant4DetectorConstruction.h b/DDG4/include/DDG4/Geant4DetectorConstruction.h index 79e6ed045e2aa467a9ff174d4783ccaffe1739ef..35ba2cbe4595f7b7f3d0b105c90ca02a70af2766 100644 --- a/DDG4/include/DDG4/Geant4DetectorConstruction.h +++ b/DDG4/include/DDG4/Geant4DetectorConstruction.h @@ -10,9 +10,18 @@ #include "G4VUserDetectorConstruction.hh" + +/* + * DD4hep namespace declaration + */ namespace DD4hep { + // Forward declarations namespace Geometry { class LCDD; } + + /* + * Simulation namespace declaration + */ namespace Simulation { class Geant4DetectorConstruction : public G4VUserDetectorConstruction { diff --git a/DDG4/include/DDG4/Geant4Field.h b/DDG4/include/DDG4/Geant4Field.h index 961aacf62aae7659c0bcdc3058b4496649ab6118..ebf2c66051ab4f07ae4254198f3c8a78c49752d0 100644 --- a/DDG4/include/DDG4/Geant4Field.h +++ b/DDG4/include/DDG4/Geant4Field.h @@ -6,8 +6,8 @@ // Author : M.Frank // //==================================================================== -#ifndef DD4HEP_GEANT4FIELD_H -#define DD4HEP_GEANT4FIELD_H +#ifndef DD4HEP_DDG4_GEANT4FIELD_H +#define DD4HEP_DDG4_GEANT4FIELD_H // Framework include files #include "DD4hep/LCDD.h" @@ -51,4 +51,4 @@ namespace DD4hep { } // End namespace Simulation } // End namespace DD4hep -#endif // DD4HEP_GEANT4FIELD_H +#endif // DD4HEP_DDG4_GEANT4FIELD_H diff --git a/DDG4/include/DDG4/Geant4HierarchyDump.h b/DDG4/include/DDG4/Geant4HierarchyDump.h new file mode 100644 index 0000000000000000000000000000000000000000..5c9b48cfecfb3a9991532b98df795ccc0a4c5e35 --- /dev/null +++ b/DDG4/include/DDG4/Geant4HierarchyDump.h @@ -0,0 +1,42 @@ +//==================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +#ifndef DD4HEP_DDG4_GEANT4HIERARCHYDUMP_H +#define DD4HEP_DDG4_GEANT4HIERARCHYDUMP_H + +// Geant 4 include files +#include "G4VPhysicalVolume.hh" + +/* + * DD4hep namespace declaration + */ +namespace DD4hep { + + // Forward declarations + namespace Geometry { class LCDD; } + + /* + * Simulation namespace declaration + */ + namespace Simulation { + + struct Geant4HierarchyDump { + typedef Geometry::LCDD LCDD; + LCDD& m_lcdd; + + public: + /// Initializing Constructor + Geant4HierarchyDump(LCDD& lcdd); + /// Standard destructor + virtual ~Geant4HierarchyDump(); + /// Dump the volume hierarchy as it is known to geant 4 + virtual void dump(const std::string& indent, const G4VPhysicalVolume* vol) const; + }; + } +} + +#endif // DD4HEP_DDG4_GEANT4HIERARCHYDUMP_H diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index 03f458b75997a5a441bd866899e18b45e82dedde..977803286da5532ed0ad3d5639c7a35e21944348 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -358,8 +358,9 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume Geant4SensitiveDetector* sd = 0; G4VisAttributes* vis_attr = 0; - printout(INFO,"Geant4Converter","++ Convert Volume %-32s: %p %s/%s assembly:%s", - n.c_str(),v,s->IsA()->GetName(),v->IsA()->GetName(),(assembly ? "YES" : "NO")); + printout(DEBUG,"Geant4Converter","++ Convert Volume %-32s: %p %s/%s assembly:%s sensitive:%s", + n.c_str(),v,s->IsA()->GetName(),v->IsA()->GetName(),(assembly ? "YES" : "NO"), + (det.isValid() ? "YES" : "NO")); if ( det.isValid() ) { sd = info.g4SensDets[det.ptr()]; @@ -408,7 +409,7 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume } vol = new G4LogicalVolume(solid,medium,n,0,sd,user_limits); if ( region ) { - printout(INFO,"Geant4Converter","++ Volume + Apply REGION settings: %s to volume %s.",reg.name(),_v.name()); + printout(DEBUG,"Geant4Converter","++ Volume + Apply REGION settings: %s to volume %s.",reg.name(),_v.name()); vol->SetRegion(region); region->AddRootLogicalVolume(vol); } @@ -416,12 +417,12 @@ void* Geant4Converter::handleVolume(const string& name, const TGeoVolume* volume vol->SetVisAttributes(vis_attr); } if ( sd ) { - printout(INFO,"Geant4Converter","++ Volume: + %s <> %s Solid:%s Mat:%s SD:%s", + printout(DEBUG,"Geant4Converter","++ Volume: + %s <> %s Solid:%s Mat:%s SD:%s", name.c_str(),vol->GetName().c_str(),solid->GetName().c_str(), medium->GetName().c_str(),sd->GetName().c_str()); } info.g4Volumes[v] = vol; - printout(INFO,"Geant4Converter", "++ Volume + %s converted: %p ---> G4: %p",n.c_str(),v,vol); + printout(DEBUG,"Geant4Converter", "++ Volume + %s converted: %p ---> G4: %p",n.c_str(),v,vol); } return vol; } @@ -465,8 +466,8 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) copy = it->second ; } //-------------------------------------------------------- - G4LogicalVolume* g4vol = info.g4Volumes[vol]; - G4LogicalVolume* g4mot = info.g4Volumes[mot_vol]; + G4LogicalVolume* g4vol = info.g4Volumes[vol]; + G4LogicalVolume* g4mot = info.g4Volumes[mot_vol]; G4AssemblyVolume* ass_mot = (G4AssemblyVolume*)g4mot; G4AssemblyVolume* ass_dau = (G4AssemblyVolume*)g4vol; bool daughter_is_assembly = vol->IsA() == TGeoVolumeAssembly::Class(); diff --git a/DDG4/src/Geant4DetectorConstruction.cpp b/DDG4/src/Geant4DetectorConstruction.cpp index 9c73c9e99a5666a799952970872ab60a391f40bf..f1478c882974c5972800a31b7d4fc398d0398167 100644 --- a/DDG4/src/Geant4DetectorConstruction.cpp +++ b/DDG4/src/Geant4DetectorConstruction.cpp @@ -1,8 +1,10 @@ #include "DDG4/Geant4DetectorConstruction.h" +#include "DDG4/Geant4HierarchyDump.h" #include "DDG4/Geant4Converter.h" #include "DD4hep/LCDD.h" #include "TGeoManager.h" #include "G4PVPlacement.hh" +#include <iostream> #ifdef GEANT4_HAS_GDML #include "G4GDMLParser.hh" @@ -27,6 +29,9 @@ G4VPhysicalVolume* DD4hep::Simulation::Geant4DetectorConstruction::Construct() { Geant4Converter::G4GeometryInfo* info = conv.create(world).detach(); g4map.attach(info); m_world = g4map.g4Placement(top); + m_lcdd.apply("DD4hepVolumeManager",0,0); + //Geant4HierarchyDump dmp(m_lcdd); + //dmp.dump("",m_world); #ifdef GEANT4_HAS_GDML if ( ::getenv("DUMP_GDML") ) { G4GDMLParser parser; diff --git a/DDG4/src/Geant4HierarchyDump.cpp b/DDG4/src/Geant4HierarchyDump.cpp new file mode 100644 index 0000000000000000000000000000000000000000..212e5ab6f9ce6ba12ab14e66093746b429c6f8a3 --- /dev/null +++ b/DDG4/src/Geant4HierarchyDump.cpp @@ -0,0 +1,126 @@ +// $Id: Geant4Converter.cpp 602 2013-06-11 14:50:57Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== + +#include "DD4hep/LCDD.h" +#include "DD4hep/Volumes.h" +#include "DD4hep/Printout.h" +#include "DDG4/Geant4HierarchyDump.h" + + +#include "Reflex/PluginService.h" + +#include "G4VisAttributes.hh" +#include "G4ProductionCuts.hh" +#include "G4VUserRegionInformation.hh" +// Geant4 include files +#include "G4Element.hh" +#include "G4SDManager.hh" +#include "G4Assembly.hh" +#include "G4AssemblyVolume.hh" +#include "G4Box.hh" +#include "G4Trd.hh" +#include "G4Tubs.hh" +#include "G4Cons.hh" +#include "G4Torus.hh" +#include "G4Sphere.hh" +#include "G4Polycone.hh" +#include "G4Polyhedra.hh" +#include "G4UnionSolid.hh" +#include "G4Paraboloid.hh" +#include "G4SubtractionSolid.hh" +#include "G4IntersectionSolid.hh" + +#include "G4Region.hh" +#include "G4UserLimits.hh" +#include "G4VSensitiveDetector.hh" + +#include "G4LogicalVolume.hh" +#include "G4Material.hh" +#include "G4Element.hh" +#include "G4Isotope.hh" +#include "G4Transform3D.hh" +#include "G4ThreeVector.hh" +#include "G4PVPlacement.hh" +#include "G4ElectroMagneticField.hh" +#include "G4FieldManager.hh" + +#include <iostream> +#include <iomanip> +#include <sstream> + + +using namespace DD4hep::Simulation; +using namespace DD4hep::Geometry; +using namespace DD4hep; +using namespace std; + +static const char* _T(const std::string& s) { return s.c_str(); } +//static const char* _T(const char* s) { return s; } + +enum { G4DUMP_ALL = 0xFFFFFFFF, + G4DUMP_LOGVOL = 1<<0, + G4DUMP_SOLID = 1<<1, + G4DUMP_SENSDET = 1<<2, + G4DUMP_LIMITS = 1<<3, + G4DUMP_REGION = 1<<4, + G4DUMP_LAST +}; +static unsigned long m_flags = ~0x0UL; + +/// Initializing Constructor +Geant4HierarchyDump::Geant4HierarchyDump( LCDD& lcdd) +: m_lcdd(lcdd) +{ +} + +/// Standard destructor +Geant4HierarchyDump::~Geant4HierarchyDump() { +} + +void Geant4HierarchyDump::dump(const string& indent, const G4VPhysicalVolume* v) const { + G4LogicalVolume* lv = v->GetLogicalVolume(); + G4VSensitiveDetector* sd = lv->GetSensitiveDetector(); + G4Material* mat = lv->GetMaterial(); + G4VSolid* sol = lv->GetSolid(); + G4Region* rg = lv->GetRegion(); + G4UserLimits* ul = lv->GetUserLimits(); + G4int ndau = lv->GetNoDaughters(); + char text[32]; + stringstream str; + + m_flags &= ~G4DUMP_SOLID; + printout(INFO,"Geant4Hierarchy","%s -> Placement:%s LV:%s Material:%s Solid:%s # of Daughters:%d",indent.c_str(), + _T(v->GetName()), _T(lv->GetName()), _T(mat->GetName()), _T(sol->GetName()),ndau); + + if ( sd && (m_flags&G4DUMP_SOLID) ) { + str.str(""); + sol->StreamInfo(str); + printout(INFO,"Geant4Hierarchy","%s Solid:%s",indent.c_str(),str.str().c_str()); + } + if ( rg && (m_flags&G4DUMP_LIMITS) ) { + G4UserLimits* rg_limits = rg->GetUserLimits(); + str.str(""); + str << indent << " Region:" << rg->GetName() << " #Materials:" << rg->GetNumberOfMaterials() + << " #Volumes:" << rg->GetNumberOfRootVolumes(); + if ( rg_limits ) str << " Limits:" << rg_limits->GetType(); + printout(INFO,"Geant4Hierarchy",str.str().c_str()); + } + if ( sd && (m_flags&G4DUMP_SENSDET) ) { + printout(INFO,"Geant4Hierarchy","%s Sens.det:%p %s path:%s Active:%-3s #Coll:%d",indent.c_str(), + sd, _T(sd->GetName()), _T(sd->GetFullPathName()), sd->isActive() ? "YES" : "NO", + sd->GetNumberOfCollections()); + } + if ( ul && (m_flags&G4DUMP_LIMITS) ) { + printout(INFO,"Geant4Hierarchy","%s Limits:%s ",indent.c_str(),_T(ul->GetType())); + } + for(G4int idau = 0; idau < ndau; ++idau) { + ::sprintf(text," %-3d",idau); + dump(indent+text,lv->GetDaughter(idau)); + } +} diff --git a/DDG4/src/Geant4SensitiveDetector.cpp b/DDG4/src/Geant4SensitiveDetector.cpp index ec4850e24e3c0debe8220529c74a28df52259128..0bd1d2e76e06d8a2f9da124a65a86e92c972f2a9 100644 --- a/DDG4/src/Geant4SensitiveDetector.cpp +++ b/DDG4/src/Geant4SensitiveDetector.cpp @@ -139,11 +139,11 @@ void Geant4SensitiveDetector::dumpStep(G4Step* st, G4TouchableHistory* /* histor Position pos2 = step.postPos(); Momentum mom = step.postMom(); - printout(INFO,"G4Step"," Track:%08ld Pos:(%8f %8f %8f) -> (%f %f %f) Mom:%7.0f %7.0f %7.0f \n", + printout(INFO,"G4Step"," Track:%08ld Pos:(%8f %8f %8f) -> (%f %f %f) Mom:%7.0f %7.0f %7.0f", long(step.track), pos1.X(), pos1.Y(), pos1.Z(), pos2.X(), pos2.Y(), pos2.Z(), mom.X(), mom.Y(), mom.Z()); - printout(INFO,"G4Step"," pre-Vol: %s Status:%s\n", + printout(INFO,"G4Step"," pre-Vol: %s Status:%s", step.preVolume()->GetName().c_str(), step.preStepStatus()); - printout(INFO,"G4Step"," post-Vol:%s Status:%s\n", + printout(INFO,"G4Step"," post-Vol:%s Status:%s", step.postVolume()->GetName().c_str(), step.postStepStatus()); const G4VPhysicalVolume* pv = step.volume(step.post); diff --git a/doc/particle_gun.mac b/doc/particle_gun.mac index 824a0e66390ad355c4ba6d7428e15f5582ca6ff4..b10856c0b6db881003e021078ca58610b65b7a14 100644 --- a/doc/particle_gun.mac +++ b/doc/particle_gun.mac @@ -1,11 +1,11 @@ -/generator/select gps -/gps/pos/type Point -/gps/pos/centre 0. 0. 0. -/gps/ang/type iso -/gps/ang/mintheta 179 deg -/gps/ang/maxtheta 181 deg -/gps/ang/minphi 0 deg -/gps/ang/maxphi 360 deg -/gps/ene/type Mono -/gps/ene/mono 10 GeV -/gps/particle pi+ +##/generator/select gun +/gun/pos/type Point +/gun/pos/centre 0. 0. 0. +/gun/ang/type iso +/gun/ang/mintheta 179 deg +/gun/ang/maxtheta 181 deg +/gun/ang/minphi 0 deg +/gun/ang/maxphi 360 deg +/gun/ene/type Mono +/gun/ene/mono 10 GeV +/gun/particle pi+