Skip to content
Snippets Groups Projects
Commit 51661e77 authored by Markus Frank's avatar Markus Frank
Browse files

Fix problem in ParticleGun spotted by Andre

parent 4a79ede0
No related branches found
No related tags found
No related merge requests found
// ADD PREDEFINED MACROS HERE!
[General]
This diff is collapsed.
DDAlign/include/DDAlign
DDCond/include/DDCond
DDCore/include/DD4hep
DDCore/include/DD4hep/objects
DDCore/include/ROOT
DDCore/include/XML
DDCore/src
DDCore/src/parsers
DDCore/src/plugins
DDCore/src/XML
DDEve/include/DDEve
DDEve/lcio
DDG4/include/DDG4
DDG4/include/DDG4Python
DDG4/lcio
DDG4/plugins
DDG4/src/python
DDRec/include/DDRec
DDRec/include/DDRec/API
DDRec/include/DDRec/Extensions
DDSegmentation/include/DDSegmentation
DDSurfaces/include/DDSurfaces
DDTest/include/DD4hep
doc/doxygen
examples/ClientTests/src
GaudiPluginService/Gaudi
GaudiPluginService/Gaudi/Details
GaudiPluginService/src
UtilityApps/src
\ No newline at end of file
...@@ -26,6 +26,10 @@ namespace DD4hep { ...@@ -26,6 +26,10 @@ namespace DD4hep {
/// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
namespace Simulation { namespace Simulation {
// Forward declarations
class Geant4PrimaryInteraction;
/// Generate particles isotrop in space around origine (0,0,0) /// Generate particles isotrop in space around origine (0,0,0)
/** /**
* \author M.Frank * \author M.Frank
...@@ -34,9 +38,6 @@ namespace DD4hep { ...@@ -34,9 +38,6 @@ namespace DD4hep {
*/ */
class Geant4ParticleGenerator: public Geant4GeneratorAction { class Geant4ParticleGenerator: public Geant4GeneratorAction {
public: public:
enum { FIRST_INTERACTION = 0UL,
LAST_INTERACTION = ~0UL
};
protected: protected:
/// Property: Shooting direction of the gun /// Property: Shooting direction of the gun
ROOT::Math::XYZVector m_direction; ROOT::Math::XYZVector m_direction;
...@@ -65,8 +66,10 @@ namespace DD4hep { ...@@ -65,8 +66,10 @@ namespace DD4hep {
*/ */
virtual void getParticleDirection(int num, ROOT::Math::XYZVector& direction, double& momentum) const; virtual void getParticleDirection(int num, ROOT::Math::XYZVector& direction, double& momentum) const;
/// Print single particle interaction identified by sequence number in primary event. Default: last one /// Print single particle interaction identified by its mask
virtual void printInteraction(size_t which=LAST_INTERACTION) const; virtual void printInteraction(int mask) const;
/// Print single particle interaction identified by it's reference
virtual void printInteraction(Geant4PrimaryInteraction* inter) const;
public: public:
......
...@@ -51,6 +51,8 @@ namespace DD4hep { ...@@ -51,6 +51,8 @@ namespace DD4hep {
bool m_isotrop; bool m_isotrop;
/// Property: Standalone mode: includes interaction merging and primary generation /// Property: Standalone mode: includes interaction merging and primary generation
bool m_standalone; bool m_standalone;
/// Property: Enable printout
bool m_print;
/// Shot number in sequence /// Shot number in sequence
int m_shotNo; int m_shotNo;
/// Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = m_energy) /// Particle modification. Caller presets defaults to: ( direction = m_direction, momentum = m_energy)
......
...@@ -62,11 +62,11 @@ namespace DD4hep { ...@@ -62,11 +62,11 @@ namespace DD4hep {
hit->cellID = volumeID( step ) ; hit->cellID = volumeID( step ) ;
except("+++ Invalid CELL ID for hit!"); except("+++ Invalid CELL ID for hit!");
} }
print("%s> Hit with deposit:%f Pos:%f %f %f ID=%016X", print("Hit with deposit:%f Pos:%f %f %f ID=%016X",
c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(), step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(),
(void*)hit->cellID); (void*)hit->cellID);
Geant4TouchableHandler handler(step); Geant4TouchableHandler handler(step);
print("%s> Geant4 path:%s",c_name(),handler.path().c_str()); print(" Geant4 path:%s",handler.path().c_str());
return true; return true;
} }
typedef Geant4SensitiveAction<Geant4Tracker> Geant4TrackerAction; typedef Geant4SensitiveAction<Geant4Tracker> Geant4TrackerAction;
...@@ -227,8 +227,8 @@ namespace DD4hep { ...@@ -227,8 +227,8 @@ namespace DD4hep {
hit = new Hit(global); hit = new Hit(global);
hit->cellID = cell; hit->cellID = cell;
coll->add(hit); coll->add(hit);
printM2("%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s", printM2("CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s",
c_name(),contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str()); contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str());
if ( 0 == hit->cellID ) { // for debugging only! if ( 0 == hit->cellID ) { // for debugging only!
hit->cellID = cellID(step); hit->cellID = cellID(step);
except("+++ Invalid CELL ID for hit!"); except("+++ Invalid CELL ID for hit!");
......
...@@ -59,29 +59,38 @@ void Geant4ParticleGenerator::getParticleMultiplicity(int& ) const { ...@@ -59,29 +59,38 @@ void Geant4ParticleGenerator::getParticleMultiplicity(int& ) const {
void Geant4ParticleGenerator::getVertexPosition(ROOT::Math::XYZVector& ) const { void Geant4ParticleGenerator::getVertexPosition(ROOT::Math::XYZVector& ) const {
} }
/// Print single particle interaction identified by sequence number in primary event /// Print single particle interaction identified by it's mask
void Geant4ParticleGenerator::printInteraction(size_t which) const { void Geant4ParticleGenerator::printInteraction(int mask) const {
Geant4PrimaryEvent* prim = context()->event().extension<Geant4PrimaryEvent>();
if ( !prim ) {
warning("printInteraction: Bad primary event [NULL-Pointer].");
return;
}
Geant4PrimaryInteraction* inter = prim->get(mask);
if ( !inter ) {
warning("printInteraction: Bad interaction identifier 0x%08X [Unknown Mask].",mask);
return;
}
printInteraction(inter);
}
/// Print single particle interaction identified by it's reference
void Geant4ParticleGenerator::printInteraction(Geant4PrimaryInteraction* inter) const {
typedef Geant4PrimaryInteraction::VertexMap _V; typedef Geant4PrimaryInteraction::VertexMap _V;
int count = 0; int count = 0;
Geant4Event& evt = context()->event(); if ( !inter ) {
Geant4PrimaryEvent* prim = evt.extension<Geant4PrimaryEvent>(); warning("printInteraction: Invalid interaction pointer [NULL-Pointer].");
return;
if ( which == LAST_INTERACTION && prim->size() > 0 ) }
which = prim->size()-1;
if ( which >= prim->size() )
except("printInteraction: Bad interaction identifier %d must be [0,%d].",
which, prim->size());
Geant4PrimaryInteraction* inter = prim->get(which);
for(_V::const_iterator iv=inter->vertices.begin(); iv!=inter->vertices.end(); ++iv) { for(_V::const_iterator iv=inter->vertices.begin(); iv!=inter->vertices.end(); ++iv) {
Geant4Vertex* v = (*iv).second; Geant4Vertex* v = (*iv).second;
printM1("+-> Interaction [%d] %.3f GeV %s pos:(%.3f %.3f %.3f)[mm]", print("+-> Interaction [%d] %.3f GeV %s pos:(%.3f %.3f %.3f)[mm]",
count, m_energy/CLHEP::GeV, m_particleName.c_str(), count, m_energy/CLHEP::GeV, m_particleName.c_str(),
v->x/CLHEP::mm, v->y/CLHEP::mm, v->z/CLHEP::mm); v->x/CLHEP::mm, v->y/CLHEP::mm, v->z/CLHEP::mm);
++count; ++count;
for(set<int>::const_iterator i=v->out.begin(); i!=v->out.end(); ++i) { for(set<int>::const_iterator i=v->out.begin(); i!=v->out.end(); ++i) {
Geant4ParticleHandle p = inter->particles[*i]; Geant4ParticleHandle p = inter->particles[*i];
p.dumpWithVertex(outputLevel()-1,name()," +->"); p.dumpWithVertex(outputLevel(),name()," +->");
} }
} }
} }
......
...@@ -41,6 +41,7 @@ Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const string& nam) ...@@ -41,6 +41,7 @@ Geant4ParticleGun::Geant4ParticleGun(Geant4Context* ctxt, const string& nam)
declareProperty("energy", m_energy); declareProperty("energy", m_energy);
declareProperty("particle", m_particleName); declareProperty("particle", m_particleName);
declareProperty("multiplicity", m_multiplicity); declareProperty("multiplicity", m_multiplicity);
declareProperty("print", m_print = true);
} }
/// Default destructor /// Default destructor
...@@ -69,8 +70,9 @@ void Geant4ParticleGun::operator()(G4Event* event) { ...@@ -69,8 +70,9 @@ void Geant4ParticleGun::operator()(G4Event* event) {
m_shotNo, m_energy/CLHEP::GeV, m_particleName.c_str(), m_shotNo, m_energy/CLHEP::GeV, m_particleName.c_str(),
m_position.X()/CLHEP::mm, m_position.Y()/CLHEP::mm, m_position.Z()/CLHEP::mm, m_position.X()/CLHEP::mm, m_position.Y()/CLHEP::mm, m_position.Z()/CLHEP::mm,
m_direction.X(),m_direction.Y(), m_direction.Z()); m_direction.X(),m_direction.Y(), m_direction.Z());
if ( m_print ) {
this->Geant4ParticleGenerator::printInteraction(); this->Geant4ParticleGenerator::printInteraction(m_mask);
}
++m_shotNo; ++m_shotNo;
if ( m_standalone ) { if ( m_standalone ) {
mergeInteractions(this,context()); mergeInteractions(this,context());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment