Skip to content

Commit

Permalink
Merge pull request #268 from CoralieNeubueser/TailCatcher
Browse files Browse the repository at this point in the history
Missing files
  • Loading branch information
zaborowska authored Dec 21, 2017
2 parents 3e07e29 + 6aba070 commit 4c06765
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Detector/DetSensitive/DetSensitive/FullParticleAbsorptionSD.h
Original file line number Diff line number Diff line change
@@ -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<DD4hep::Simulation::Geant4CalorimeterHit>* m_calorimeterCollection;
/// Segmentation of the detector used to retrieve the cell Ids
DD4hep::Geometry::Segmentation m_seg;
};
}

#endif /* DETSENSITIVE_FULLPARTICLEPABSORPTIONSD_H */
49 changes: 49 additions & 0 deletions Detector/DetSensitive/src/FullParticleAbsorptionSD.cpp
Original file line number Diff line number Diff line change
@@ -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<DD4hep::Simulation::Geant4CalorimeterHit>(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;
}
}
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 4c06765

Please sign in to comment.