From 6aba070258ce2ae5205a0101fdfb96714e529db0 Mon Sep 17 00:00:00 2001 From: CoralieNeubueser Date: Thu, 21 Dec 2017 11:40:55 +0100 Subject: [PATCH] re-named files --- .../DetSensitive/FullParticleAbsorptionSD.h | 57 +++++++++++++++++ .../src/FullParticleAbsorptionSD.cpp | 49 +++++++++++++++ .../testDd4hepFullParticleAbsorptionSD.py | 63 +++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 Detector/DetSensitive/DetSensitive/FullParticleAbsorptionSD.h create mode 100644 Detector/DetSensitive/src/FullParticleAbsorptionSD.cpp create mode 100644 Detector/DetSensitive/tests/options/testDd4hepFullParticleAbsorptionSD.py diff --git a/Detector/DetSensitive/DetSensitive/FullParticleAbsorptionSD.h b/Detector/DetSensitive/DetSensitive/FullParticleAbsorptionSD.h new file mode 100644 index 000000000..bc68f2e6a --- /dev/null +++ b/Detector/DetSensitive/DetSensitive/FullParticleAbsorptionSD.h @@ -0,0 +1,57 @@ +#ifndef DETSENSITIVE_FULLPARTICLEABSORPTIONSD_H +#define DETSENSITIVE_FULLPARTICLEABSORPTIONSD_H + +// DD4hep +#include "DDG4/Geant4Hits.h" +#include "DDSegmentation/Segmentation.h" + +// Geant +#include "G4THitsCollection.hh" +#include "G4VSensitiveDetector.hh" + +/** FullParticleAbsD DetectorDescription/DetSensitive/src/FullParticleAbsSD.h FullParticleAbsSD.h + * + * Sensitive detector to fully stop the incoming particles. + * The position of the hit is set to G4Step::GetPreStepPoint() position. + * New hit is created for each incoming particle, the energy is stored and the track is removed. + * No timing information is saved. + * + * @author Coralie Neubueser + */ + +namespace det { +class FullParticleAbsorptionSD : public G4VSensitiveDetector { +public: + /** Constructor. + * @param aDetectorName Name of the detector + * @param aReadoutName Name of the readout (used to name the collection) + * @param aSeg Segmentation of the detector (used to retrieve the cell ID) + */ + FullParticleAbsorptionSD(const std::string& aDetectorName, + const std::string& aReadoutName, + const DD4hep::Geometry::Segmentation& aSeg); + /// Destructor + virtual ~FullParticleAbsorptionSD(); + /** Initialization. + * Creates the hit collection with the name passed in the constructor. + * The hit collection is registered in Geant. + * @param aHitsCollections Geant hits collection. + */ + virtual void Initialize(G4HCofThisEvent* aHitsCollections) final; + /** Process hit once the particle hit the sensitive volume. + * Gets the kinetic energy from the particle track, calculates the position and cellID, + * saves that into the hit collection. + * New hit is created for first track of each particle within sensitive detector. + * @param aStep Step in which particle deposited the energy. + */ + virtual bool ProcessHits(G4Step* aStep, G4TouchableHistory*) final; + +private: + /// Collection of calorimeter hits + G4THitsCollection* m_calorimeterCollection; + /// Segmentation of the detector used to retrieve the cell Ids + DD4hep::Geometry::Segmentation m_seg; +}; +} + +#endif /* DETSENSITIVE_FULLPARTICLEPABSORPTIONSD_H */ diff --git a/Detector/DetSensitive/src/FullParticleAbsorptionSD.cpp b/Detector/DetSensitive/src/FullParticleAbsorptionSD.cpp new file mode 100644 index 000000000..bb28bc255 --- /dev/null +++ b/Detector/DetSensitive/src/FullParticleAbsorptionSD.cpp @@ -0,0 +1,49 @@ +#include "DetSensitive/FullParticleAbsorptionSD.h" + +// FCCSW +#include "DetCommon/DetUtils.h" + +// DD4hep +#include "DDG4/Geant4Mapping.h" +#include "DDG4/Geant4VolumeManager.h" + +// CLHEP +#include "CLHEP/Vector/ThreeVector.h" + +// Geant4 +#include "G4SDManager.hh" + +namespace det { +FullParticleAbsorptionSD::FullParticleAbsorptionSD(const std::string& aDetectorName, + const std::string& aReadoutName, + const DD4hep::Geometry::Segmentation& aSeg) + : G4VSensitiveDetector(aDetectorName), m_calorimeterCollection(nullptr), m_seg(aSeg) { + // name of the collection of hits is determined byt the readout name (from XML) + collectionName.insert(aReadoutName); +} + +FullParticleAbsorptionSD::~FullParticleAbsorptionSD() {} + +void FullParticleAbsorptionSD::Initialize(G4HCofThisEvent* aHitsCollections) { + // create a collection of hits and add it to G4HCofThisEvent + // deleted in ~G4Event + m_calorimeterCollection = + new G4THitsCollection(SensitiveDetectorName, collectionName[0]); + aHitsCollections->AddHitsCollection(G4SDManager::GetSDMpointer()->GetCollectionID(m_calorimeterCollection), + m_calorimeterCollection); +} + +bool FullParticleAbsorptionSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { + CLHEP::Hep3Vector prePos = aStep->GetPreStepPoint()->GetPosition(); + G4Track* aTrack = aStep->GetTrack(); + G4double kineticEnergy = aTrack->GetKineticEnergy(); + DD4hep::Simulation::Position pos(prePos.x(), prePos.y(), prePos.z()); + auto hit = new DD4hep::Simulation::Geant4CalorimeterHit(pos); + hit->cellID = utils::cellID(m_seg, *aStep); + hit->energyDeposit = kineticEnergy; + m_calorimeterCollection->insert(hit); + // kill the track to ensure no double counting + aTrack->SetTrackStatus(fStopAndKill); + return true; +} +} diff --git a/Detector/DetSensitive/tests/options/testDd4hepFullParticleAbsorptionSD.py b/Detector/DetSensitive/tests/options/testDd4hepFullParticleAbsorptionSD.py new file mode 100644 index 000000000..765597366 --- /dev/null +++ b/Detector/DetSensitive/tests/options/testDd4hepFullParticleAbsorptionSD.py @@ -0,0 +1,63 @@ +from Gaudi.Configuration import * + +from Configurables import GenAlg, MomentumRangeParticleGun, Gaudi__ParticlePropertySvc +pgun = MomentumRangeParticleGun("PGun", + PdgCodes=[11], # electron + MomentumMin = 10, # GeV + MomentumMax = 10, # GeV + ThetaMin = -0.45, # rad + ThetaMax = -0.45, # rad + PhiMin = 1.6, # rad + PhiMax = 1.6) # rad +gen = GenAlg("ParticleGun", SignalProvider=pgun) +gen.hepmc.Path = "hepmc" +ppservice = Gaudi__ParticlePropertySvc("ParticlePropertySvc", ParticlePropertiesFile="../../../Generation/data/ParticleTable.txt") + +from Configurables import HepMCToEDMConverter +hepmc_converter = HepMCToEDMConverter("Converter") +hepmc_converter.hepmc.Path="hepmc" +hepmc_converter.genparticles.Path="allGenParticles" +hepmc_converter.genvertices.Path="allGenVertices" + +from Configurables import HepMCDumper +hepmc_dump = HepMCDumper("hepmc") +hepmc_dump.hepmc.Path="hepmc" + +from Configurables import GeoSvc +geoservice = GeoSvc("GeoSvc", detectors=['file:compact/Box_dd4hepStopParticleSD.xml'], OutputLevel = DEBUG) + +from Configurables import SimG4Svc +geantservice = SimG4Svc("SimG4Svc", + detector='SimG4DD4hepDetector', + physicslist="SimG4FtfpBert", + actions="SimG4FullSimActions") + +from Configurables import SimG4Alg, SimG4SaveCalHits, SimG4PrimariesFromEdmTool, InspectHitsCollectionsTool +inspecttool = InspectHitsCollectionsTool("inspect", readoutNames=["Hits"], OutputLevel = DEBUG) + +saveParticletool = SimG4SaveCalHits("saveParticles", readoutNames = ["Hits"]) +saveParticletool.positionedCaloHits.Path = "positionedCaloHits" +saveParticletool.caloHits.Path = "caloHits" + +particle_converter = SimG4PrimariesFromEdmTool("EdmConverter") +particle_converter.genParticles.Path = "allGenParticles" +geantsim = SimG4Alg("SimG4Alg", + outputs=["SimG4SaveCalHits/saveParticles", + "InspectHitsCollectionsTool/inspect"], + eventProvider=particle_converter) + +from Configurables import FCCDataSvc, PodioOutput +podiosvc = FCCDataSvc("EventDataSvc") +out = PodioOutput("out", OutputLevel=DEBUG, filename="out_dd4hepStopParticleSD.root") +out.outputCommands = ["keep *"] + + +# ApplicationMgr +from Configurables import ApplicationMgr +ApplicationMgr( TopAlg = [gen, hepmc_converter, hepmc_dump, geantsim, out], + EvtSel = 'NONE', + EvtMax = 1, + # order is important, as GeoSvc is needed by SimG4Svc + ExtSvc = [podiosvc, ppservice, geoservice, geantservice], + OutputLevel=DEBUG + )