DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Data.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DDG4_GEANT4DATA_H
15 #define DDG4_GEANT4DATA_H
16 
17 // Framework include files
18 #include <Math/Vector3D.h>
19 
20 // C/C++ include files
21 #include <set>
22 #include <vector>
23 #include <memory>
24 
25 // Forward declarations
26 class G4Step;
27 class G4StepPoint;
28 
30 namespace dd4hep {
31 
32  // Forward type definitions
33  typedef ROOT::Math::XYZVector Position;
34  typedef ROOT::Math::XYZVector Direction;
35 
37  namespace sim {
38 
39  // Forward declarations
40  class Geant4FastSimSpot;
41 
43 
50  class SimpleRun {
51  public:
53  int runID { -1 };
55  int numEvents { 0 };
57  SimpleRun();
59  virtual ~SimpleRun();
60  };
61 
63 
70  class SimpleEvent {
71  public:
72  typedef std::vector<long> Seeds;
74  int runID { -1 };
76  int eventID { -1 };
78  Seeds seeds { };
80  SimpleEvent();
82  virtual ~SimpleEvent();
83  };
84 
86 
91  class DataExtension {
92  public:
96  virtual ~DataExtension();
97  };
98 
100  /*
101  * Base class for geant4 hit structures created by the
102  * example sensitive detectors. This is a generic class
103  * only dealing with the cellID. Users may add an extension
104  * object, which normally should not be necessary.
105  *
106  * \author M.Frank
107  * \version 1.0
108  * \ingroup DD4HEP_SIMULATION
109  */
111  public:
112  enum HitFlags {
121  HIT_ENDED_OUTSIDE = 1<<15
122  };
124  long long int cellID = 0;
126  long flag = 0;
128  long g4ID = -1;
130  std::unique_ptr<DataExtension> extension;
131 
133 
139  public:
141  int trackID = -1;
143  int pdgID = -1;
145  double deposit = 0.0;
147  double time;
149  double length = 0.0;
151  float x = 0.0, y = 0.0, z = 0.0;
153  float px = 0.0, py = 0.0, pz = 0.0;
154 
156  MonteCarloContrib() = default;
161 #if 0
162  MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len)
164  : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len) {
165  }
166 #endif
167  MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, float* pos, float* mom)
169  : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len),
170  x(pos[0]), y(pos[1]), z(pos[2]), px(mom[0]), py(mom[1]), pz(mom[2])
171  {
172  }
174  MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, double* pos, double* mom)
175  : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len),
176  x(float(pos[0])), y(float(pos[1])), z(float(pos[2])),
177  px(float(mom[0])), py(float(mom[1])), pz(float(mom[2]))
178  {
179  }
181  MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, const Position& pos, const Direction& mom)
182  : trackID(track_id), pdgID(pdg), deposit(dep), time(time_stamp), length(len),
183  x(float(pos.x())), y(float(pos.y())), z(float(pos.z())),
184  px(float(mom.x())), py(float(mom.y())), pz(float(mom.z()))
185  {
186  }
192  void clear() {
193  x = y = z = 0.0;
194  px = py = pz = 0.0;
195  time = deposit = length = 0.0;
196  pdgID = trackID = -1;
197  }
199  Position position() const {
200  return Position(x, y, z);
201  }
203  void setPosition(const Position& pos) {
204  x = pos.x();
205  y = pos.y();
206  z = pos.z();
207  }
209  void setPosition(double pos_x, double pos_y, double pos_z) {
210  x = float(pos_x);
211  y = float(pos_y);
212  z = float(pos_z);
213  }
215  Direction momentum() const {
216  return Direction(px, py, pz);
217  }
219  void setMomentum(const Direction& dir) {
220  px = dir.x();
221  py = dir.y();
222  pz = dir.z();
223  }
225  void setMomentum(double mom_x, double mom_y, double mom_z) {
226  px = float(mom_x);
227  py = float(mom_y);
228  pz = float(mom_z);
229  }
230  };
232  typedef std::vector<MonteCarloContrib> Contributions;
233  public:
235  Geant4HitData();
237  virtual ~Geant4HitData();
239  static Contribution extractContribution(const G4Step* step);
241  static Contribution extractContribution(const G4Step* step, bool ApplyBirksLaw);
244  };
245 
247 
253  public:
255 
263  class Hit : public Geant4HitData {
264  public:
266 
272  double length { 0e0 };
274  double energyDeposit { 0e0 };
277  public:
279  Hit();
281  Hit(Hit&& c) = delete;
283  Hit(const Hit& c) = delete;
285  Hit(int track_id, int pdg_id, double deposit, double time_stamp, double len=0.0, const Position& p={0.0, 0.0, 0.0}, const Direction& d={0.0, 0.0, 0.0});
287  Hit(const Geant4HitData::Contribution& contrib, const Direction& mom, double deposit);
289  virtual ~Hit();
291  Hit& operator=(Hit&& c) = delete;
293  Hit& operator=(const Hit& c) = delete;
295  void copyFrom(const Hit& c);
297  Hit& clear();
299  Hit& storePoint(const G4Step* step, const G4StepPoint* point);
301  Hit& storePoint(const Geant4FastSimSpot* spot);
302  };
303  };
304 
306 
312  public:
313 
315 
323  class Hit : public Geant4HitData {
324  public:
326 
332  double energyDeposit { 0e0 };
333  public:
335  Hit();
337  Hit(Hit&& c) = delete;
339  Hit(const Hit& c) = delete;
341  Hit(const Position& cell_pos);
343  virtual ~Hit();
345  Hit& operator=(Hit&& c) = delete;
347  Hit& operator=(const Hit& c) = delete;
348  };
349  };
350 
355 
356  } // End namespace sim
357 } // End namespace dd4hep
358 #endif // DDG4_GEANT4DATA_H
dd4hep::sim::Geant4Tracker::Hit::momentum
Direction momentum
Hit direction.
Definition: Geant4Data.h:270
dd4hep::sim::SimpleRun::SimpleRun
SimpleRun()
Default constructor.
Definition: Geant4Data.cpp:30
dd4hep::sim::Geant4Tracker::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:268
dd4hep::sim::Geant4HitData::MonteCarloContrib::MonteCarloContrib
MonteCarloContrib(MonteCarloContrib &&c)=default
Move constructor.
dd4hep::sim::Geant4HitData::MonteCarloContrib::px
float px
Proper particle momentum when generating the hit of the contributing particle.
Definition: Geant4Data.h:153
dd4hep::sim::Geant4HitData::HIT_ENDED_OUTSIDE
@ HIT_ENDED_OUTSIDE
Definition: Geant4Data.h:121
dd4hep::sim::DataExtension
Generic user-extendible data extension class.
Definition: Geant4Data.h:91
dd4hep::sim::Geant4HitData::flag
long flag
User flag to classify hits.
Definition: Geant4Data.h:126
dd4hep::sim::Geant4HitData::HIT_ENDED_SURFACE
@ HIT_ENDED_SURFACE
Definition: Geant4Data.h:120
dd4hep::sim::Geant4HitData::Contribution
MonteCarloContrib Contribution
Definition: Geant4Data.h:231
dd4hep::sim::Geant4HitData::MonteCarloContrib::momentum
Direction momentum() const
Access momentum.
Definition: Geant4Data.h:215
dd4hep::sim::Geant4HitData::MonteCarloContrib::pdgID
int pdgID
Particle ID from the PDG table.
Definition: Geant4Data.h:143
dd4hep::sim::Geant4Calorimeter::Hit::~Hit
virtual ~Hit()
Default destructor.
Definition: Geant4Data.cpp:208
dd4hep::sim::Geant4HitData::MonteCarloContrib::y
float y
Definition: Geant4Data.h:151
dd4hep::sim::SimpleEvent::seeds
Seeds seeds
Random number generator seeds.
Definition: Geant4Data.h:78
dd4hep::sim::Geant4Calorimeter::Hit::Hit
Hit(Hit &&c)=delete
Move constructor.
dd4hep::sim::DataExtension::DataExtension
DataExtension()
Default constructor.
Definition: Geant4Data.h:94
dd4hep::sim::Geant4HitData::MonteCarloContrib::length
double length
Length of this step.
Definition: Geant4Data.h:149
dd4hep::sim::SimpleRun::runID
int runID
Run identifiers.
Definition: Geant4Data.h:53
dd4hep::sim::Geant4HitData::MonteCarloContrib::operator=
MonteCarloContrib & operator=(MonteCarloContrib &&c)=default
Assignment operator (move)
dd4hep::sim::Geant4HitData::MonteCarloContrib::position
Position position() const
Access position.
Definition: Geant4Data.h:199
dd4hep::sim::SimpleCalorimeter
Geant4Calorimeter SimpleCalorimeter
Definition: Geant4Data.h:354
dd4hep::sim::Geant4HitData::extension
std::unique_ptr< DataExtension > extension
User data extension if required.
Definition: Geant4Data.h:130
dd4hep::sim::Geant4HitData::HIT_NEW_TRACK
@ HIT_NEW_TRACK
Definition: Geant4Data.h:115
dd4hep::sim::Geant4HitData::MonteCarloContrib::MonteCarloContrib
MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, const Position &pos, const Direction &mom)
Initializing constructor.
Definition: Geant4Data.h:181
dd4hep::sim::Geant4Tracker::Hit::base_t
Geant4HitData base_t
Definition: Geant4Data.h:265
dd4hep::sim::SimpleEvent
Simple event description structure. Used in the default I/O mechanism.
Definition: Geant4Data.h:70
dd4hep::sim::Geant4HitData::HIT_KILLED_TRACK
@ HIT_KILLED_TRACK
Definition: Geant4Data.h:113
dd4hep::sim::Geant4Tracker::Hit::Hit
Hit(const Hit &c)=delete
copy constructor
dd4hep::sim::Geant4HitData::MonteCarloContrib::setPosition
void setPosition(const Position &pos)
Set position of the contribution.
Definition: Geant4Data.h:203
dd4hep::sim::Geant4Tracker::Hit::copyFrom
void copyFrom(const Hit &c)
Explicit assignment operation.
Definition: Geant4Data.cpp:133
dd4hep::sim::Direction
Position Direction
Definition: Defs.h:26
dd4hep::sim::Geant4Tracker::Hit::~Hit
virtual ~Hit()
Default destructor.
Definition: Geant4Data.cpp:128
dd4hep::Direction
Position Direction
Definition: Fields.h:28
dd4hep::sim::Geant4HitData::MonteCarloContrib::MonteCarloContrib
MonteCarloContrib(int track_id, int pdg, double dep, double time_stamp, double len, double *pos, double *mom)
Initializing constructor.
Definition: Geant4Data.h:174
dd4hep::sim::Geant4HitData::HIT_SECONDARY_TRACK
@ HIT_SECONDARY_TRACK
Definition: Geant4Data.h:114
dd4hep::sim::Geant4HitData::cellID
long long int cellID
cellID
Definition: Geant4Data.h:124
dd4hep::sim::Geant4FastSimSpot
Spot definition for fast simulation and GFlash.
Definition: Geant4FastSimSpot.h:71
dd4hep::sim::Geant4HitData::HitFlags
HitFlags
Definition: Geant4Data.h:112
dd4hep::sim::Geant4HitData::~Geant4HitData
virtual ~Geant4HitData()
Default destructor.
Definition: Geant4Data.cpp:59
dd4hep::sim::Geant4Tracker::Hit::operator=
Hit & operator=(const Hit &c)=delete
Copy assignment operator.
dd4hep::sim::Geant4HitData::Contributions
std::vector< MonteCarloContrib > Contributions
Definition: Geant4Data.h:232
dd4hep::sim::Geant4HitData::HIT_ENDED_INSIDE
@ HIT_ENDED_INSIDE
Definition: Geant4Data.h:119
dd4hep::sim::Geant4HitData::MonteCarloContrib::MonteCarloContrib
MonteCarloContrib(const MonteCarloContrib &c)=default
Copy constructor.
dd4hep::sim::Geant4HitData::MonteCarloContrib::py
float py
Definition: Geant4Data.h:153
dd4hep::sim::Geant4Tracker::Hit
DDG4 tracker hit class used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:263
dd4hep::sim::SimpleEvent::SimpleEvent
SimpleEvent()
Default constructor.
Definition: Geant4Data.cpp:40
dd4hep::sim::Geant4Tracker::Hit::length
double length
Length of the track segment contributing to this hit.
Definition: Geant4Data.h:272
dd4hep::sim::Geant4HitData::g4ID
long g4ID
Original Geant 4 track identifier of the creating track (debugging)
Definition: Geant4Data.h:128
dd4hep::sim::Geant4Tracker::Hit::Hit
Hit()
Default constructor.
Definition: Geant4Data.cpp:104
dd4hep::sim::Geant4HitData::MonteCarloContrib::deposit
double deposit
Total energy deposit in this hit.
Definition: Geant4Data.h:145
dd4hep::sim::Geant4Tracker::Hit::operator=
Hit & operator=(Hit &&c)=delete
Move assignment operator.
dd4hep::sim::Geant4HitData
Base class for geant4 hit structures used by the default DDG4 sensitive detector implementations.
Definition: Geant4Data.h:110
dd4hep::sim::SimpleRun::~SimpleRun
virtual ~SimpleRun()
Default destructor.
Definition: Geant4Data.cpp:35
dd4hep::sim::Geant4Calorimeter::Hit::Hit
Hit()
Default constructor (for ROOT)
Definition: Geant4Data.cpp:198
dd4hep::sim::Geant4Calorimeter::Hit::base_t
Geant4HitData base_t
Definition: Geant4Data.h:325
dd4hep::sim::Geant4Calorimeter
Helper class to define structures used by the generic DDG4 calorimeter sensitive detector.
Definition: Geant4Data.h:311
dd4hep::sim::Geant4HitData::HIT_STARTED_OUTSIDE
@ HIT_STARTED_OUTSIDE
Definition: Geant4Data.h:118
dd4hep::sim::Geant4HitData::MonteCarloContrib::MonteCarloContrib
MonteCarloContrib()=default
Default constructor.
dd4hep::sim::Geant4HitData::MonteCarloContrib::pz
float pz
Definition: Geant4Data.h:153
dd4hep::sim::Geant4Calorimeter::Hit::operator=
Hit & operator=(const Hit &c)=delete
Copy assignment operator.
dd4hep::sim::Geant4Tracker::Hit::truth
Contribution truth
Monte Carlo / Geant4 information.
Definition: Geant4Data.h:276
dd4hep::sim::Geant4HitData::Geant4HitData
Geant4HitData()
Default constructor.
Definition: Geant4Data.cpp:54
dd4hep::sim::Geant4Tracker
Helper class to define structures used by the generic DDG4 tracker sensitive detector.
Definition: Geant4Data.h:252
dd4hep::sim::Geant4HitData::MonteCarloContrib::setMomentum
void setMomentum(const Direction &dir)
Set memonetum of the contribution.
Definition: Geant4Data.h:219
dd4hep::sim::Geant4Calorimeter::Hit::energyDeposit
double energyDeposit
Total energy deposit.
Definition: Geant4Data.h:332
dd4hep::sim::Geant4Calorimeter::Hit
DDG4 calorimeter hit class used by the generic DDG4 calorimeter sensitive detector.
Definition: Geant4Data.h:323
dd4hep::sim::Geant4Tracker::Hit::Hit
Hit(Hit &&c)=delete
Move constructor.
dd4hep::sim::Geant4HitData::MonteCarloContrib::trackID
int trackID
Geant 4 Track identifier.
Definition: Geant4Data.h:141
dd4hep::sim::Geant4HitData::MonteCarloContrib::clear
void clear()
Clear data content.
Definition: Geant4Data.h:192
dd4hep::sim::SimpleRun::numEvents
int numEvents
Number of events in this run.
Definition: Geant4Data.h:55
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::sim::SimpleHit
Geant4HitData SimpleHit
Backward compatibility definitions.
Definition: Geant4Data.h:352
dd4hep::sim::SimpleTracker
Geant4Tracker SimpleTracker
Definition: Geant4Data.h:353
dd4hep::sim::Geant4HitData::MonteCarloContrib::x
float x
Proper position of the hit contribution.
Definition: Geant4Data.h:151
dd4hep::sim::DataExtension::~DataExtension
virtual ~DataExtension()
Default destructor.
Definition: Geant4Data.cpp:50
dd4hep::sim::Geant4HitData::MonteCarloContrib::setPosition
void setPosition(double pos_x, double pos_y, double pos_z)
Set position of the contribution.
Definition: Geant4Data.h:209
dd4hep::sim::Geant4Calorimeter::Hit::truth
Contributions truth
Hit contributions by individual particles.
Definition: Geant4Data.h:330
dd4hep::sim::SimpleEvent::Seeds
std::vector< long > Seeds
Definition: Geant4Data.h:72
dd4hep::sim::SimpleEvent::runID
int runID
Run identifiers.
Definition: Geant4Data.h:74
dd4hep::sim::Geant4Calorimeter::Hit::Hit
Hit(const Hit &c)=delete
copy constructor
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4HitData::extractContribution
static Contribution extractContribution(const G4Step *step)
Extract the MC contribution for a given hit from the step information.
Definition: Geant4Data.cpp:64
dd4hep::sim::Geant4HitData::HIT_STARTED_INSIDE
@ HIT_STARTED_INSIDE
Definition: Geant4Data.h:116
dd4hep::sim::Geant4Tracker::Hit::storePoint
Hit & storePoint(const G4Step *step, const G4StepPoint *point)
Store Geant4 point and step information into tracker hit structure.
Definition: Geant4Data.cpp:154
dd4hep::sim::Geant4HitData::MonteCarloContrib
Utility class describing the monte carlo contribution of a given particle to a hit.
Definition: Geant4Data.h:138
dd4hep::sim::Geant4Tracker::Hit::energyDeposit
double energyDeposit
Energy deposit in the tracker hit.
Definition: Geant4Data.h:274
dd4hep::sim::Geant4HitData::HIT_STARTED_SURFACE
@ HIT_STARTED_SURFACE
Definition: Geant4Data.h:117
dd4hep::sim::Geant4Calorimeter::Hit::operator=
Hit & operator=(Hit &&c)=delete
Move assignment operator.
dd4hep::sim::SimpleEvent::eventID
int eventID
Event identifier.
Definition: Geant4Data.h:76
dd4hep::sim::Geant4HitData::MonteCarloContrib::z
float z
Definition: Geant4Data.h:151
dd4hep::sim::Geant4Tracker::Hit::clear
Hit & clear()
Clear hit content.
Definition: Geant4Data.cpp:144
dd4hep::sim::SimpleRun
Simple run description structure. Used in the default I/O mechanism.
Definition: Geant4Data.h:50
dd4hep::sim::Geant4HitData::MonteCarloContrib::operator=
MonteCarloContrib & operator=(const MonteCarloContrib &c)=default
Assignment operator (copy)
dd4hep::sim::Geant4HitData::MonteCarloContrib::time
double time
Timestamp when this energy was deposited.
Definition: Geant4Data.h:147
dd4hep::sim::Geant4Calorimeter::Hit::position
Position position
Hit position.
Definition: Geant4Data.h:328
dd4hep::sim::Geant4HitData::MonteCarloContrib::setMomentum
void setMomentum(double mom_x, double mom_y, double mom_z)
Set memonetum of the contribution.
Definition: Geant4Data.h:225
dd4hep::sim::SimpleEvent::~SimpleEvent
virtual ~SimpleEvent()
Default destructor.
Definition: Geant4Data.cpp:45