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
60
61
62
63
64
65
66
67
#include "DriftChamberSensitiveDetector.h"
#include "G4SDManager.hh"
DriftChamberSensitiveDetector::DriftChamberSensitiveDetector(const std::string& name,
dd4hep::Detector& description)
: DDG4SensitiveDetector(name, description),
m_hc(nullptr) {
const std::string& coll_name = m_sensitive.hitsCollection();
collectionName.insert(coll_name);
}
void
DriftChamberSensitiveDetector::Initialize(G4HCofThisEvent* HCE) {
const std::string& coll_name = collectionName[0];
m_hc = new HitCollection(GetName(), coll_name);
int HCID = -1;
if(HCID<0) HCID = G4SDManager::GetSDMpointer()->GetCollectionID(m_hc);
HCE->AddHitsCollection( HCID, m_hc );
}
G4bool
DriftChamberSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) {
// Refer to: DDG4/legacy/Geant4TrackerSD.cpp (note: there's bug in momentum calculation)
// DDCore/include/DD4hep/Objects.h (mean_direction and mean_length)
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); // (pre+post)/2
double hit_len = direction.R();
HitContribution contrib = dd4hep::sim::Geant4Hit::extractContribution(step);
// Now, invokes the dE/dx simulator
double dedx = 0.0;
double de = hit_len * dedx;
// contrib.deposit = de; // if need the de from dedx simulator
// create a new hit
TrackerHit* hit = new TrackerHit(
h.track->GetTrackID(),
h.track->GetDefinition()->GetPDGEncoding(),
de, // not the Geant4's deposit energy. from dE/dx simulator
h.track->GetGlobalTime()
);
hit->cellID = getCellID(step);
hit->energyDeposit = de; // FIXME: also use the dedx
hit->position = position;
hit->momentum = (h.preMom() + h.postMom() )/2;
hit->length = hit_len;
m_hc->insert(hit);
return true;
}
void
DriftChamberSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) {
}