Newer
Older
Markus Frank
committed
//==========================================================================
Markus Frank
committed
//--------------------------------------------------------------------------
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
Markus Frank
committed
// All rights reserved.
Markus Frank
committed
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Markus Frank
committed
// Author : M.Frank
//
//==========================================================================
#ifndef DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
#define DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H
Markus Frank
committed
// Framework include files
#include <DD4hep/DetElement.h>
#include <DDG4/Geant4SensDetAction.h>
#include <DDG4/Geant4SteppingAction.h>
/// Namespace for the AIDA detector description toolkit
/// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit
/// Class to measure the energy of escaping tracks
Markus Frank
committed
/** Class to measure the energy of escaping tracks of a detector using Geant 4
* \author M.Frank
* \version 1.0
* \ingroup DD4HEP_SIMULATION
*/
class Geant4EscapeCounter : /* virtual public Geant4SteppingAction, virtual */ public Geant4Sensitive {
/// Collection identifiers
size_t m_collectionID;
Markus Frank
committed
/// Detector name set
Geant4EscapeCounter(Geant4Context* ctxt, const std::string& name, DetElement det, Detector& description);
/// Default destructor
virtual ~Geant4EscapeCounter();
/// G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
Markus Frank
committed
virtual bool process(const G4Step* step, G4TouchableHistory* history) override;
} // End namespace sim
} // End namespace dd4hep
#endif /* DD4HEP_DDG4_GEANT4ESCAPECOUNTER_H */
//====================================================================
//--------------------------------------------------------------------
Markus Frank
committed
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// All rights reserved.
//
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
Markus Frank
committed
// Author : M.Frank
//
//====================================================================
// Framework include files
#include <DD4hep/Printout.h>
#include <DD4hep/InstanceCount.h>
#include <DDG4/Geant4TouchableHandler.h>
#include <DDG4/Geant4TrackHandler.h>
#include <DDG4/Geant4StepHandler.h>
#include <DDG4/Geant4Mapping.h>
#include <DDG4/Geant4Data.h>
#include <CLHEP/Units/SystemOfUnits.h>
#include <G4VProcess.hh>
Geant4EscapeCounter::Geant4EscapeCounter(Geant4Context* ctxt, const std::string& nam, DetElement det, Detector& description_ref)
: Geant4Sensitive(ctxt, nam, det, description_ref)
std::string coll_name = name()+"Hits";
m_needsControl = true;
declareProperty("Shells",m_detectorNames);
m_collectionID = defineCollection<SimpleTracker::Hit>(coll_name);
InstanceCount::increment(this);
}
/// Default destructor
Geant4EscapeCounter::~Geant4EscapeCounter() {
InstanceCount::decrement(this);
}
/// G4VSensitiveDetector interface: Method for generating hit(s) using the information of G4Step object.
Markus Frank
committed
bool Geant4EscapeCounter::process(const G4Step* step, G4TouchableHistory* /* history */) {
Geant4TrackHandler th(h.track);
Geant4TouchableHandler handler(step);
std::string hdlr_path = handler.path();
Geant4HitCollection* coll = collection(m_collectionID);
Markus Frank
committed
SimpleTracker::Hit* hit = new SimpleTracker::Hit();
hit->g4ID = th.id();
hit->energyDeposit = h.deposit();
hit->cellID = volumeID(step);
hit->energyDeposit = th.energy();
hit->position = prePos;
hit->momentum = h.trkMom();
Markus Frank
committed
hit->truth.trackID = th.id();
hit->truth.deposit = h.deposit();
hit->truth.pdgID = th.pdgID();
hit->truth.deposit = h.deposit();
hit->truth.time = th.time();
hit->truth.length = hit->length;
hit->truth.x = hit->position.x();
hit->truth.y = hit->position.y();
hit->truth.z = hit->position.z();
Markus Frank
committed
print("+++ Track:%4d %8.2f MeV [%s] %s Geant4 path:%s",
Markus Frank
committed
h.trkID(),h.trkEnergy()/CLHEP::MeV,th.name().c_str(),
Markus Frank
committed
th.creatorName().c_str(),hdlr_path.c_str());
// Kill track, so that it does no longer participate in the propagation
Markus Frank
committed
step->GetTrack()->SetTrackStatus(fStopAndKill);
#include <DDG4/Factories.h>
DECLARE_GEANT4SENSITIVE(Geant4EscapeCounter)