Graduation-Project/src/GeneHe3detSD.cc

63 lines
2.1 KiB
C++

#include "GeneHe3detSD.hh"
#include "G4HCofThisEvent.hh"
#include "G4Ions.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleTypes.hh"
#include "G4SDManager.hh"
#include "G4Step.hh"
#include "G4VPhysicalVolume.hh"
#include "G4ios.hh"
#include "GeneHe3detHit.hh"
GeneHe3detSD::GeneHe3detSD(G4String name) : G4VSensitiveDetector(name) {
G4String HCname = "GeneHe3detHitCollection";
collectionName.insert(HCname);
}
GeneHe3detSD::~GeneHe3detSD() {}
void GeneHe3detSD::Initialize(G4HCofThisEvent* HCE) {
scintillatorCollection = new GeneHe3detHitsCollection(SensitiveDetectorName, collectionName[0]);
static G4int HCID = -1;
if (HCID < 0) HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
HCE->AddHitsCollection(HCID, scintillatorCollection);
}
G4bool GeneHe3detSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
G4double edep = aStep->GetTotalEnergyDeposit();
if (edep == 0.) return false;
G4ParticleDefinition* particleType = aStep->GetTrack()->GetDefinition();
G4String particleName = particleType->GetParticleName();
if (particleName == "opticalphoton") return false;
G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
G4TouchableHistory* theTouchable = (G4TouchableHistory*)(preStepPoint->GetTouchable());
G4int copyNo = theTouchable->GetVolume()->GetCopyNo();
// fill in hit
GeneHe3detHit* newHit = new GeneHe3detHit();
newHit->SetCpNo(copyNo);
newHit->SetEdep(edep);
newHit->SetPos(aStep->GetPostStepPoint()->GetPosition());
newHit->SetTime(aStep->GetPostStepPoint()->GetGlobalTime());
newHit->SetParticle(particleName);
newHit->SetParticleEnergy(aStep->GetPreStepPoint()->GetKineticEnergy());
scintillatorCollection->insert(newHit);
return true;
}
void GeneHe3detSD::EndOfEvent(G4HCofThisEvent* HCE) {
G4int nHits = scintillatorCollection->entries();
if (verboseLevel >= 1) G4cout << " Si collection: " << nHits << " hits" << G4endl;
if (verboseLevel >= 2) scintillatorCollection->PrintAllHits();
}
void GeneHe3detSD::clear() {}
void GeneHe3detSD::DrawAll() {}
void GeneHe3detSD::PrintAll() {}