Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "GenericTrackerSensitiveDetector.h"
#include "G4Step.hh"
#include "G4VProcess.hh"
//#include "G4SteppingManager.hh"
#include "G4SDManager.hh"
//#include "UserTrackInformation.hh"
#include "DD4hep/DD4hepUnits.h"
GenericTrackerSensitiveDetector::GenericTrackerSensitiveDetector(const std::string& name,
dd4hep::Detector& description)
: DDG4SensitiveDetector(name, description),
m_hc(nullptr){
G4String CollName=name+"Collection";
collectionName.insert(CollName);
}
void GenericTrackerSensitiveDetector::Initialize(G4HCofThisEvent* HCE){
m_hc = new HitCollection(GetName(), collectionName[0]);
int HCID = G4SDManager::GetSDMpointer()->GetCollectionID(m_hc);
HCE->AddHitsCollection( HCID, m_hc );
}
G4bool GenericTrackerSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*){
G4TouchableHandle touchPost = step->GetPostStepPoint()->GetTouchableHandle();
G4TouchableHandle touchPre = step->GetPreStepPoint()->GetTouchableHandle();
dd4hep::sim::Geant4StepHandler h(step);
dd4hep::Position prePos = h.prePos();
dd4hep::Position postPos = h.postPos();
dd4hep::Position direction = postPos - prePos;
dd4hep::Position position = mean_direction(prePos,postPos);
double hit_len = direction.R();
if (hit_len > 0) {
double new_len = mean_length(h.preMom(),h.postMom())/hit_len;
direction *= new_len/hit_len;
}
dd4hep::sim::Geant4TrackerHit* hit = nullptr;
hit = new dd4hep::sim::Geant4TrackerHit(h.track->GetTrackID(),
h.track->GetDefinition()->GetPDGEncoding(),
step->GetTotalEnergyDeposit(),
h.track->GetGlobalTime());
if ( hit ) {
hit->cellID = getCellID( step ) ;
hit->energyDeposit = step->GetTotalEnergyDeposit();
hit->position = position;
hit->momentum = direction;
hit->length = hit_len;
m_hc->insert(hit);
return true;
}
throw std::runtime_error("new() failed: Cannot allocate hit object");
return false;
}
void GenericTrackerSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE){
}