Class Reference for E1039 Core & Analysis Software
GenericSD.cc
Go to the documentation of this file.
1 // Based on ExN02TrackerSD.hh from ParN02 example
2 
3 #include "GenericSD.hh"
4 
5 GenericSD::GenericSD(G4String name): G4VSensitiveDetector(name)
6 {
7  G4String HCname;
8  collectionName.insert(HCname="staHitsCollection");
9 }
10 
12 {
13 }
14 
15 void GenericSD::Initialize(G4HCofThisEvent* HCE)
16 {
17  staHitsCollection = new MCHitsCollection(SensitiveDetectorName, collectionName[0]);
18  static G4int HCID = -1;
19  if(HCID<0)
20  HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
21  HCE->AddHitsCollection(HCID, staHitsCollection);
22 }
23 
24 G4bool GenericSD::ProcessHits(G4Step* aStep,G4TouchableHistory*)
25 {
26  return true;
27 
28  G4double edep = aStep->GetTotalEnergyDeposit();
29 
30  G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition();
31  if (particle->GetPDGCharge() == 0.)
32  return false;
33 
34  G4Track* theTrack = aStep->GetTrack();
35 
36  MCHit* newHit = new MCHit();
37  newHit->SetParticleID(particle->GetPDGEncoding());
38  newHit->SetParticleName(particle->GetParticleName());
39  newHit->SetPosition(aStep->GetTrack()->GetPosition());
40  newHit->SetMomentum(theTrack->GetMomentum());
41  newHit->SetVertex(theTrack->GetVertexPosition());
42  newHit->SetTime(theTrack->GetGlobalTime());
43  newHit->SetTrackID(theTrack->GetTrackID());
44  newHit->SetParentID(theTrack->GetParentID());
45  newHit->SetVertexMomentumDirection(theTrack->GetVertexMomentumDirection());
46  newHit->SetDE(edep);
47  newHit->SetVertexKineticEnergy(theTrack->GetKineticEnergy());
48 
49  G4String curVolname = theTrack->GetVolume()->GetName();
50 
51  newHit->SetVolume(curVolname);
52 
53  staHitsCollection->insert( newHit );
54 
55  return true;
56 }
57 
58 void GenericSD::EndOfEvent(G4HCofThisEvent*)
59 {
60  if (verboseLevel>0)
61  {
62  G4int NbHits = staHitsCollection->entries();
63  G4cout << "\n-------->Hits Collection: in this event there are " << NbHits
64  << " hits at detector station 1: " << G4endl;
65  for (G4int i=0;i<NbHits;i++)
66  (*staHitsCollection)[i]->Print();
67  }
68 }
G4THitsCollection< MCHit > MCHitsCollection
Definition: MCHit.hh:79
G4bool ProcessHits(G4Step *, G4TouchableHistory *)
Definition: GenericSD.cc:24
~GenericSD()
Definition: GenericSD.cc:11
GenericSD(G4String)
Definition: GenericSD.cc:5
void EndOfEvent(G4HCofThisEvent *)
Definition: GenericSD.cc:58
void Initialize(G4HCofThisEvent *)
Definition: GenericSD.cc:15
Definition: MCHit.hh:16
void SetDE(G4double de)
Definition: MCHit.hh:51
void SetVertexKineticEnergy(G4double vke)
Definition: MCHit.hh:75
void SetParentID(G4int parentID)
Definition: MCHit.hh:69
void SetVertex(G4ThreeVector v0)
Definition: MCHit.hh:60
void SetParticleID(G4int particle_id)
Definition: MCHit.hh:42
void SetVolume(G4String volume)
Definition: MCHit.hh:54
void SetTime(G4double time)
Definition: MCHit.hh:63
void SetVertexMomentumDirection(G4ThreeVector vmd)
Definition: MCHit.hh:72
void SetPosition(G4ThreeVector pos)
Definition: MCHit.hh:48
void SetTrackID(G4int tid)
Definition: MCHit.hh:66
void SetParticleName(G4String pName)
Definition: MCHit.hh:45
void SetMomentum(G4ThreeVector p)
Definition: MCHit.hh:57