DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Hits.cpp
Go to the documentation of this file.
1 // $Id$
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DDG4/Geant4Hits.h"
17 
18 // Geant4 include files
19 #include "G4Allocator.hh"
20 #include "G4ParticleDefinition.hh"
21 #include "G4ChargedGeantino.hh"
22 #include "G4OpticalPhoton.hh"
23 #include "G4Geantino.hh"
24 
25 // C/C++ include files
26 #include <iostream>
27 
28 using namespace std;
29 using namespace DD4hep::Simulation;
30 
31 G4ThreadLocal G4Allocator<Geant4TrackerHit>* TrackerHitAllocator = 0;
32 G4ThreadLocal G4Allocator<Geant4CalorimeterHit>* CalorimeterHitAllocator = 0;
33 
34 
36 bool Geant4Hit::isGeantino(G4Track* track) {
37  if (track) {
38  G4ParticleDefinition* def = track->GetDefinition();
39  if (def == G4ChargedGeantino::Definition())
40  return true;
41  if (def == G4Geantino::Definition()) {
42  return true;
43  }
44  }
45  return false;
46 }
47 
48 Geant4Hit::Contribution Geant4Hit::extractContribution(G4Step* step) {
49  G4Track* trk = step->GetTrack();
50  double energy_deposit =
51  (trk->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) ?
52  trk->GetTotalEnergy() : step->GetTotalEnergyDeposit();
53  Contribution contrib(trk->GetTrackID(), trk->GetDefinition()->GetPDGEncoding(), energy_deposit, trk->GetGlobalTime());
54  return contrib;
55 }
56 
58 Geant4TrackerHit::Geant4TrackerHit()
59  : Geant4Hit(), position(), momentum(), length(0.0), truth(), energyDeposit(0.0) {
60 }
61 
63 Geant4TrackerHit::Geant4TrackerHit(int track_id, int pdg_id, double deposit, double time_stamp)
64  : Geant4Hit(), position(), momentum(), length(0.0), truth(track_id, pdg_id, deposit, time_stamp), energyDeposit(deposit) {
65 }
66 
69  if ( this != &c ) {
70  position = c.position;
71  momentum = c.momentum;
72  length = c.length;
73  truth = c.truth;
75  }
76  return *this;
77 }
78 
81  position.SetXYZ(0, 0, 0);
82  momentum.SetXYZ(0, 0, 0);
83  length = 0.0;
84  truth.clear();
85  energyDeposit = 0.0;
86  return *this;
87 }
88 
90 Geant4TrackerHit& Geant4TrackerHit::storePoint(G4Step* step, G4StepPoint* pnt) {
91  G4Track* trk = step->GetTrack();
92  G4ThreeVector pos = pnt->GetPosition();
93  G4ThreeVector mom = pnt->GetMomentum();
94 
95  truth.trackID = trk->GetTrackID();
96  truth.pdgID = trk->GetDefinition()->GetPDGEncoding();
97  truth.deposit = step->GetTotalEnergyDeposit();
98  truth.time = trk->GetGlobalTime();
99  energyDeposit = step->GetTotalEnergyDeposit();
100  position.SetXYZ(pos.x(), pos.y(), pos.z());
101  momentum.SetXYZ(mom.x(), mom.y(), mom.z());
102  length = 0;
103  return *this;
104 }
105 
107 void* Geant4TrackerHit::operator new(size_t) {
108  if ( TrackerHitAllocator )
109  return TrackerHitAllocator->MallocSingle();
110  TrackerHitAllocator = new G4Allocator<Geant4TrackerHit>;
111  return TrackerHitAllocator->MallocSingle();
112 }
113 
115 void Geant4TrackerHit::operator delete(void *p) {
116  TrackerHitAllocator->FreeSingle((Geant4TrackerHit*) p);
117 }
118 
121  : Geant4Hit(), position(pos), truth(), energyDeposit(0) {
122 }
123 
125 void* Geant4CalorimeterHit::operator new(size_t) {
127  return CalorimeterHitAllocator->MallocSingle();
128  CalorimeterHitAllocator = new G4Allocator<Geant4CalorimeterHit>;
129  return CalorimeterHitAllocator->MallocSingle();
130 }
131 
133 void Geant4CalorimeterHit::operator delete(void *p) {
135 }
136 
int pdgID
Particle ID from the PDG table.
Definition: Geant4Hits.h:91
Position position
Hit position.
Definition: Geant4Hits.h:140
Geant4TrackerHit & clear()
Clear hit content.
Definition: Geant4Hits.cpp:80
G4ThreadLocal G4Allocator< Geant4CalorimeterHit > * CalorimeterHitAllocator
Definition: Geant4Hits.cpp:32
Direction momentum
Hit direction.
Definition: Geant4Hits.h:142
double deposit
Total energy deposit in this hit.
Definition: Geant4Hits.h:93
G4ThreadLocal G4Allocator< Geant4TrackerHit > * TrackerHitAllocator
Definition: Geant4Hits.cpp:31
Deprecated: Geant4 calorimeter hit class for deprecated sensitive detectors.
Definition: Geant4Hits.h:179
Geant4TrackerHit & operator=(const Geant4TrackerHit &c)
Assignment operator.
Definition: Geant4Hits.cpp:68
Geant4TrackerHit & storePoint(G4Step *step, G4StepPoint *point)
Store Geant4 point and step information into tracker hit structure.
Definition: Geant4Hits.cpp:90
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Hits.h:146
ROOT::Math::XYZVector Position
Definition: Objects.h:75
int trackID
Geant 4 Track identifier.
Definition: Geant4Hits.h:89
Deprecated: Geant4 tracker hit class for deprecated sensitive detectors.
Definition: Geant4Hits.h:137
double length
Length of the track segment contributing to this hit.
Definition: Geant4Hits.h:144
double time
Timestamp when this energy was deposited.
Definition: Geant4Hits.h:95
Deprecated: basic geant4 hit class for deprecated sensitive detectors.
Definition: Geant4Hits.h:80
Geant4CalorimeterHit(const Position &cell_pos)
Standard constructor.
Definition: Geant4Hits.cpp:120
Geant4TrackerHit()
Default constructor.
Definition: Geant4Hits.cpp:58