From 1a935611ba7fe9f49f5a1241902c80b04bfa194d Mon Sep 17 00:00:00 2001 From: Markus Frank <markus.frank@cern.ch> Date: Thu, 30 Jan 2014 15:16:56 +0000 Subject: [PATCH] Fix bug, which appears with earlier versions than root 5.34.10 --- DDG4/examples/run.C | 5 +++-- DDG4/plugins/Geant4SDActions.cpp | 23 +++++++++++++++++++---- DDG4/src/Geant4Converter.cpp | 3 ++- DDG4/src/Geant4VolumeManager.cpp | 3 ++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/DDG4/examples/run.C b/DDG4/examples/run.C index 954995bec..ecf14ab74 100644 --- a/DDG4/examples/run.C +++ b/DDG4/examples/run.C @@ -2,7 +2,8 @@ void run() { gInterpreter->ProcessLine(".X initAClick.C"); gInterpreter->ProcessLine(".L dictionaries.C+"); - //gInterpreter->ProcessLine(".L xmlAClick.C+"); - gInterpreter->ProcessLine(".L TEve.C+"); + //gInterpreter->ProcessLine(".L exampleAClick.C+"); + gInterpreter->ProcessLine(".L xmlAClick.C+"); + //gInterpreter->ProcessLine(".L TEve.C+"); } diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index b6cb6af0c..66a74f1ed 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -12,6 +12,8 @@ #include "DDG4/Geant4Data.h" #include "DD4hep/Printout.h" +using namespace std; + /* * DD4hep namespace declaration */ @@ -29,7 +31,7 @@ namespace DD4hep { public: typedef SimpleHit::Contribution HitContribution; /// Standard , initializing constructor - Geant4SensitiveAction(Geant4Context* context, const std::string& name, DetElement det, LCDD& lcdd); + Geant4SensitiveAction(Geant4Context* context, const string& name, DetElement det, LCDD& lcdd); /// Default destructor virtual ~Geant4SensitiveAction(); /// Define collections created by this sensitivie action object @@ -53,7 +55,7 @@ namespace DD4hep { /// Standard , initializing constructor template <typename T> Geant4SensitiveAction<T>::Geant4SensitiveAction(Geant4Context* context, - const std::string& name, + const string& name, DetElement det, LCDD& lcdd) : Geant4Sensitive(context,name,det,lcdd), m_collectionID(0) @@ -147,9 +149,13 @@ namespace DD4hep { hit->length = hit_len; collection(m_collectionID)->add(hit); mcTruthMgr().mark(h.track,true); + if ( 0 == hit->cellID ) { + hit->cellID = volumeID( step ) ; + throw runtime_error("Invalid CELL ID for hit!"); + } return true; } - throw std::runtime_error("new() failed: Cannot allocate hit object"); + throw runtime_error("new() failed: Cannot allocate hit object"); } typedef Geant4SensitiveAction<SimpleTracker> Geant4SimpleTrackerAction; @@ -175,6 +181,10 @@ namespace DD4hep { coll->add(hit) ; printout(DEBUG,"SimpleTracker","%s> CREATE hit with deposit:%f Pos:%f %f %f", c_name(),contrib.deposit,pos.X(),pos.Y(),pos.Z()); + if ( 0 == hit->cellID ) { + hit->cellID = volumeID( step ) ; + throw runtime_error("Invalid CELL ID for hit!"); + } } else { printout(DEBUG,"SimpleTracker","%s> UPDATE hit with deposit:%f Pos:%f %f %f", @@ -214,8 +224,13 @@ namespace DD4hep { Position pos = h.prePos(); Hit* hit = coll->find<Hit>(PositionCompare<Hit>(pos)); if ( !hit ) { - hit=new Hit(pos); + hit = new Hit(pos); + hit->cellID = volumeID( step ) ; coll->add(hit); + if ( 0 == hit->cellID ) { + hit->cellID = volumeID( step ) ; + throw runtime_error("Invalid CELL ID for hit!"); + } } hit->energyDeposit += contrib.deposit; hit->truth.push_back(contrib); diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp index cb7f8ae03..1f081bebb 100644 --- a/DDG4/src/Geant4Converter.cpp +++ b/DDG4/src/Geant4Converter.cpp @@ -35,6 +35,7 @@ #include "TGeoParaboloid.h" #include "TGeoCompositeShape.h" #include "TGeoShapeAssembly.h" +#include "TGeoManager.h" #include "TClass.h" #include "TMath.h" @@ -561,7 +562,7 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node) info.g4AssemblyChildren[ass_mot].push_back(make_pair(id, node)); return 0; } - else if ( 0 == g4mot ) { + else if ( node != gGeoManager->GetTopNode() && 0 == g4mot ) { throw logic_error("Geant4Converter: Invalid mother volume found!"); } else if (daughter_is_assembly) { diff --git a/DDG4/src/Geant4VolumeManager.cpp b/DDG4/src/Geant4VolumeManager.cpp index 20f141854..e110fce84 100644 --- a/DDG4/src/Geant4VolumeManager.cpp +++ b/DDG4/src/Geant4VolumeManager.cpp @@ -86,7 +86,8 @@ namespace { } for (Int_t idau = 0, ndau = node->GetNdaughters(); idau < ndau; ++idau) { TGeoNode* daughter = node->GetDaughter(idau); - if (dynamic_cast<const PlacedVolume::Object*>(daughter)) { + PlacedVolume placement(daughter); + if ( placement.data() ) { scanPhysicalVolume(daughter, ids, sd, chain); } } -- GitLab