SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_G4_TrackerSD.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 
27 #include "SToGS_G4_TrackerSD.hh"
28 #include "SToGS_G4_TrackerHit.hh"
30 
31 #include "G4Step.hh"
32 #include "G4HCofThisEvent.hh"
33 #include "G4TouchableHistory.hh"
34 #include "G4VProcess.hh"
35 #include "G4ios.hh"
36 #include "G4OpticalPhoton.hh"
37 
38 SToGS::TrackerSD::TrackerSD(G4String name): G4VSensitiveDetector(name)
39 {
40  G4String HCname = "TrackerHits";
41  collectionName.insert(HCname);
42 
43 }
45 {
46  ;
47 }
48 void SToGS::TrackerSD::Initialize(G4HCofThisEvent* HCE)
49 {
50 // G4cout << " In SToGS::TrackerSD::Initialize " << G4endl;
51  static int HCID = -1;
52  trackerCollection = new SToGS::TrackerHitsCollection(SensitiveDetectorName,collectionName[0]);
53 
54  if ( HCID < 0 )
55  HCID = GetCollectionID(0);
56  HCE->AddHitsCollection(HCID,trackerCollection);
57 // G4cout << " Out SToGS::TrackerSD::Initialize " << G4endl;
58 }
59 
60 G4bool SToGS::TrackerSD::ProcessHits(G4Step* aStep, G4TouchableHistory * /*touch*/)
61 {
62  // G4cout << " In SToGS::TrackerSD::ProcessHits" << G4endl;
63 
64  G4String tmp; G4int temp_code;
65 
66  // avoid keeping optical
67  G4Track* theTrack = aStep->GetTrack();
68  if ( theTrack && theTrack->GetParticleDefinition() == G4OpticalPhoton::OpticalPhotonDefinition() )
69  return false ;
70 
71  // nothing to be stored if no energy
72  G4double edep = aStep->GetTotalEnergyDeposit();
73  if ( edep == 0. ) {
74  return false;
75  }
76 
77  // a new hit is created
78  SToGS::TrackerHit *newHit = new SToGS::TrackerHit();
79 
80  // set hit properties
81  newHit->SetTrackID(theTrack->GetTrackID());
82  newHit->SetParentID(theTrack->GetParentID());
83 
84  SToGS::PrimaryTrackInformation *pinfo = (SToGS::PrimaryTrackInformation *)theTrack->GetUserInformation();
85  if ( pinfo )
86  newHit->SetPrimaryID(pinfo->GetPrimaryID());
87  else
88  newHit->SetPrimaryID(theTrack->GetParentID()); // in case primary is not know, at least parent
89 
90  newHit->SetEdep( edep );
91  newHit->SetPos( aStep->GetPostStepPoint()->GetPosition() );
92  newHit->SetToF ( aStep->GetPostStepPoint()->GetGlobalTime() );
93 
94  newHit->SetDetName (aStep->GetTrack()->GetVolume()->GetName());
95 
96  const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();
97  G4int depth = touchable->GetHistoryDepth();
98 
99  G4int detector_number = touchable->GetCopyNumber(0); // get curent detector number and add offset of the on-top structure
100  if ( depth > 1 ) {
101  detector_number += touchable->GetCopyNumber(depth-1);
102  /*
103  G4cout << " 0 " << touchable->GetCopyNumber(0) << G4endl;;
104  G4cout << " 1 " << touchable->GetCopyNumber(1) << G4endl;;
105  G4cout << " 2 " << touchable->GetCopyNumber(2) << G4endl;;
106  G4cout << " 3 " << touchable->GetCopyNumber(3) << G4endl;;
107  */
108  }
109 
110  newHit->SetDetID(detector_number);
111 
112 // newHit->SetMotherDetName(touch->GetVolume()->GetName());
113  newHit->SetMotherID(aStep->GetPreStepPoint()->GetTouchableHandle()->GetReplicaNumber(1));
114 
115  tmp = aStep->GetTrack()->GetDefinition()->GetParticleName();
116  newHit->SetParticleName( tmp );
117 
118  temp_code = aStep->GetTrack()->GetDefinition()->GetPDGEncoding ();
119  newHit->SetPDGcode(temp_code);
120 
121  tmp = aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
122  newHit->SetProcessName( tmp );
123 
124  // add this hit to the collection
125  trackerCollection->insert( newHit );
126 
127 // G4cout << " Out SToGS::TrackerSD::ProcessHits" << G4endl;
128  return true;
129 }
130 
131 void SToGS::TrackerSD::EndOfEvent(G4HCofThisEvent*)
132 {
133 }
134 
136 {
137 }
138 
140 {
141 }
142 
144 {
145 }
G4THitsCollection< TrackerHit > TrackerHitsCollection
void SetParticleName(G4String name)
void EndOfEvent(G4HCofThisEvent *HCE)
void SetPos(G4ThreeVector xyz)
TrackerSD(G4String name)
void SetMotherID(G4int id)
void SetEdep(G4double de)
void SetPDGcode(G4int code)
void SetTrackID(G4int id)
void SetParentID(G4int id)
G4int GetPrimaryID() const
Get the primary ID.
void SetToF(G4double tf)
void SetDetName(G4String name)
Informations to be kept at each step if a positive energy is deposited in a sensitive detector...
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
void SetPrimaryID(G4int id)
void Initialize(G4HCofThisEvent *HCE)
void SetProcessName(G4String name)
User Track Information that kept the origine of any track.