REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestGeant4Event.h
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
23#ifndef RestCore_TRestGeant4Event
24#define RestCore_TRestGeant4Event
25
26#include <TGraph.h>
27#include <TGraph2D.h>
28#include <TH1D.h>
29#include <TH2F.h>
30#include <TLegend.h>
31#include <TMultiGraph.h>
32#include <TRestEvent.h>
33#include <TVector3.h>
34
35#include <iostream>
36#include <map>
37#include <utility>
38
39#include "TRestGeant4Track.h"
40
41class G4Event;
42class G4Track;
43class G4Step;
45
48 private:
49#ifndef __CINT__
50 Double_t fMinX, fMaxX;
51 Double_t fMinY, fMaxY;
52 Double_t fMinZ, fMaxZ;
53 Double_t fMinEnergy, fMaxEnergy;
54#endif
55
56 void AddEnergyDepositToVolume(Int_t volID, Double_t eDep);
57
58 protected:
59#ifndef __CINT__
60
61 // TODO These graphs should be placed in TRestTrack?
62 // (following GetGraph implementation in TRestDetectorSignal)
63 TGraph* fXZHitGraph;
64 TGraph* fYZHitGraph;
65 TGraph* fXYHitGraph;
66 // TGraph2D *fXYZHitGraph; //! (TODO to implement XYZ visualization)
67
68 std::vector<TGraph*> fXYPcsMarker;
69 std::vector<TGraph*> fYZPcsMarker;
70 std::vector<TGraph*> fXZPcsMarker;
71
72 TMultiGraph* fXZMultiGraph;
73 TMultiGraph* fYZMultiGraph;
74 TMultiGraph* fXYMultiGraph;
75 // TMultiGraph *fXYZMultiGraph; //! (TODO to implement XYZ visualization)
76
77 TH2F* fXYHisto;
78 TH2F* fXZHisto;
79 TH2F* fYZHisto;
80
81 TH1D* fXHisto;
82 TH1D* fYHisto;
83 TH1D* fZHisto;
84
85 TLegend* fLegend_XY;
86 TLegend* fLegend_XZ;
87 TLegend* fLegend_YZ;
88
89 std::vector<Int_t> legendAdded;
90
91 Int_t fTotalHits;
92
93 TMultiGraph* GetXZMultiGraph(Int_t gridElement, std::vector<TString> pcsList, Double_t minPointSize = 0.4,
94 Double_t maxPointSize = 4);
95 TMultiGraph* GetYZMultiGraph(Int_t gridElement, std::vector<TString> pcsList, Double_t minPointSize = 0.4,
96 Double_t maxPointSize = 4);
97 TMultiGraph* GetXYMultiGraph(Int_t gridElement, std::vector<TString> pcsList, Double_t minPointSize = 0.4,
98 Double_t maxPointSize = 4);
99
100 TH2F* GetXYHistogram(Int_t gridElement, std::vector<TString> optList);
101 TH2F* GetXZHistogram(Int_t gridElement, std::vector<TString> optList);
102 TH2F* GetYZHistogram(Int_t gridElement, std::vector<TString> optList);
103
104 TH1D* GetXHistogram(Int_t gridElement, std::vector<TString> optList);
105 TH1D* GetYHistogram(Int_t gridElement, std::vector<TString> optList);
106 TH1D* GetZHistogram(Int_t gridElement, std::vector<TString> optList);
107#endif
108
109 TVector3 fPrimaryPosition;
110 std::vector<TString> fPrimaryParticleNames;
111 std::vector<Double_t> fPrimaryEnergies;
112 std::vector<TVector3> fPrimaryDirections;
113
114 TString fSubEventPrimaryParticleName;
115 Double_t fSubEventPrimaryEnergy;
116 TVector3 fSubEventPrimaryPosition;
117 TVector3 fSubEventPrimaryDirection;
118
119 Double_t fTotalDepositedEnergy = 0;
120 Double_t fSensitiveVolumeEnergy = 0;
121
122 double fEventTimeWall = 0;
123 double fEventTimeWallPrimaryGeneration = 0;
124
125 Int_t fNVolumes;
126 std::vector<Int_t> fVolumeStored;
127 std::vector<std::string> fVolumeStoredNames;
128 std::vector<Double_t> fVolumeDepositedEnergy;
129 std::map<std::string, std::map<std::string, std::map<std::string, double>>>
130 fEnergyInVolumePerParticlePerProcess;
131 std::vector<TRestGeant4Track> fTracks;
132
133 public:
134 void SetBoundaries();
135 void SetBoundaries(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin,
136 Double_t zMax);
137
138 Double_t GetBoundingBoxSize();
139
140 inline size_t GetNumberOfPrimaries() const { return fPrimaryParticleNames.size(); }
141
142 inline TString GetPrimaryEventParticleName(size_t n = 0) const { return fPrimaryParticleNames[n]; }
143 inline TVector3 GetPrimaryEventDirection(size_t n = 0) const { return fPrimaryDirections[n]; }
144 inline TVector3 GetPrimaryEventOrigin() const { return fPrimaryPosition; }
145 inline Double_t GetPrimaryEventEnergy(size_t n = 0) const { return fPrimaryEnergies[n]; }
146
147 inline Bool_t IsSubEvent() const { return fSubEventID > 0; }
148 inline TString GetSubEventPrimaryEventParticleName() const { return fSubEventPrimaryParticleName; }
149 inline TVector3 GetSubEventPrimaryEventDirection() const { return fSubEventPrimaryDirection; }
150 inline TVector3 GetSubEventPrimaryEventOrigin() const { return fSubEventPrimaryPosition; }
151 inline Double_t GetSubEventPrimaryEventEnergy() const { return fSubEventPrimaryEnergy; }
152
153 size_t GetNumberOfHits(Int_t volID = -1) const;
154 size_t GetNumberOfPhysicalHits(Int_t volID = -1) const;
155
156 double GetEventTimeWall() const { return fEventTimeWall; }
157 double GetEventTimeWallPrimaryGeneration() const { return fEventTimeWallPrimaryGeneration; }
158
159 inline const std::vector<TRestGeant4Track>& GetTracks() const { return fTracks; }
160 inline size_t GetNumberOfTracks() const { return fTracks.size(); }
161 inline Int_t GetNumberOfActiveVolumes() const { return fNVolumes; }
162
163 inline Int_t isVolumeStored(int n) const { return fVolumeStored[n]; }
164 inline const TRestGeant4Track& GetTrack(int n) const { return fTracks[n]; }
165 inline TRestGeant4Track* GetTrackPointer(int n) { return &fTracks[n]; }
166 TRestGeant4Track* GetTrackByID(Int_t trackID) const;
167
168 inline Double_t GetTotalDepositedEnergy() const { return fTotalDepositedEnergy; }
169
170 inline Double_t GetSensitiveVolumeEnergy() const { return fSensitiveVolumeEnergy; }
171 TVector3 GetMeanPositionInVolume(Int_t volID) const;
172 TVector3 GetFirstPositionInVolume(Int_t volID) const;
173 TVector3 GetLastPositionInVolume(Int_t volID) const;
174 TVector3 GetPositionDeviationInVolume(Int_t volID) const;
175
176 std::map<std::string, std::map<std::string, std::map<std::string, double>>>
177 GetEnergyInVolumePerParticlePerProcessMap() const;
178 std::map<std::string, std::map<std::string, double>> GetEnergyInVolumePerProcessMap() const;
179 std::map<std::string, std::map<std::string, double>> GetEnergyInVolumePerParticleMap() const;
180 std::map<std::string, double> GetEnergyPerProcessMap() const;
181 std::map<std::string, double> GetEnergyPerParticleMap() const;
182 std::map<std::string, double> GetEnergyInVolumeMap() const;
183
184 inline Double_t GetEnergyInVolume(const std::string& volumeName) const {
185 auto energyMap = GetEnergyInVolumeMap();
186 return energyMap[volumeName];
187 }
188
189 std::pair<double, double> GetTimeRangeOfIonizationInVolume(const std::string& volumeName) const;
190
191 inline void ClearTracks() { fTracks.clear(); }
192
193 TRestHits GetHits(Int_t volID = -1) const;
194 inline TRestHits GetHitsInVolume(Int_t volID) const { return GetHits(volID); }
195
196 Int_t GetNumberOfTracksForParticle(const TString& particleName) const;
197 Double_t GetEnergyDepositedByParticle(const TString& particleName) const;
198
199 inline void ActivateVolumeForStorage(Int_t n) { fVolumeStored[n] = 1; }
200 inline void DisableVolumeForStorage(Int_t n) { fVolumeStored[n] = 0; }
201
202 void AddActiveVolume(const std::string& volumeName);
203 void ClearVolumes();
204 inline void AddEnergyToSensitiveVolume(Double_t en) { fSensitiveVolumeEnergy += en; }
205
206 inline void SetEnergyDepositedInVolume(Int_t volID, Double_t eDep) {
207 fVolumeDepositedEnergy[volID] = eDep;
208 }
209 inline void SetSensitiveVolumeEnergy(Double_t en) { fSensitiveVolumeEnergy = en; }
210
211 inline Int_t GetLowestTrackID() const {
212 Int_t lowestID = 0;
213 if (GetNumberOfTracks() > 0) {
214 lowestID = GetTrack(0).GetTrackID();
215 }
216
217 for (unsigned int i = 0; i < GetNumberOfTracks(); i++) {
218 auto tr = GetTrack(i);
219 if (tr.GetTrackID() < lowestID) lowestID = tr.GetTrackID();
220 }
221
222 return lowestID;
223 }
224
225 std::set<std::string> GetUniqueParticles() const;
226
227 Bool_t ContainsProcessInVolume(Int_t processID, Int_t volumeID = -1) const;
228 inline Bool_t ContainsProcess(Int_t processID) const { return ContainsProcessInVolume(processID, -1); }
229
230 Bool_t ContainsProcessInVolume(const TString& processName, Int_t volumeID = -1) const;
231 inline Bool_t ContainsProcess(const TString& processName) const {
232 return ContainsProcessInVolume(processName, -1);
233 }
234
235 Bool_t ContainsParticle(const TString& particleName) const;
236 Bool_t ContainsParticleInVolume(const TString& particleName, Int_t volumeID = -1) const;
237
238 void Initialize() override;
239
240 void InitializeReferences(TRestRun* run) override;
241
242 const TRestGeant4Metadata* GetGeant4Metadata() const;
243
245 void PrintActiveVolumes() const;
246 void PrintEvent(int maxTracks = 0, int maxHits = 0) const;
247 void PrintEventFilterVolumes(const std::set<std::string>& volumeNames) const;
248
249 inline TPad* DrawEvent(const TString& option = "") override { return DrawEvent(option, true); }
250 TPad* DrawEvent(const TString& option, Bool_t autoBoundaries);
251
252 // Constructor
254
255 // Destructor
256 virtual ~TRestGeant4Event();
257
258 ClassDefOverride(TRestGeant4Event, 9); // REST event superclass
259
260 // restG4
261 public:
262 TRestGeant4Event(const G4Event*);
263 bool InsertTrack(const G4Track*);
264 void UpdateTrack(const G4Track*);
265 void InsertStep(const G4Step*);
266
267 friend class OutputManager;
268 friend class TRestGeant4QuenchingProcess;
269
270 private:
271 std::map<Int_t, Int_t> fTrackIDToTrackIndex = {};
272 TRestGeant4Hits fInitialStep;
273
274 void AddEnergyInVolumeForParticleForProcess(Double_t energy, const std::string& volumeName,
275 const std::string& particleName,
276 const std::string& processName);
277};
278#endif
A base class for any REST event.
Definition: TRestEvent.h:38
virtual void PrintEvent() const
Definition: TRestEvent.cxx:187
Int_t fSubEventID
Sub-Event identification number.
Definition: TRestEvent.h:43
An event class to store geant4 generated event information.
TVector3 GetFirstPositionInVolume(Int_t volID) const
Function to get the position (TVector3) of the first track that deposits energy in specified volume....
void InitializeReferences(TRestRun *run) override
Initialize dynamical references when loading the event from a root file.
TPad * DrawEvent(const TString &option="") override
Draw the event.
size_t GetNumberOfHits(Int_t volID=-1) const
Function that returns the total number of hits in the Geant4 event. If a specific volume is given as ...
size_t GetNumberOfPhysicalHits(Int_t volID=-1) const
Function that returns the total number of hits with energy > 0 in the Geant4 event....
Double_t GetBoundingBoxSize()
This method returns the event size as the size of the bounding box enclosing all hits.
TVector3 GetPositionDeviationInVolume(Int_t volID) const
A method that gets the standard deviation from the hits happening at a particular volumeId inside the...
void Initialize() override
void PrintActiveVolumes() const
maxTracks : number of tracks to print, 0 = all
TVector3 GetLastPositionInVolume(Int_t volID) const
Function to get the position (TVector3) of the last track that deposits energy in specified volume....
TRestHits GetHits(Int_t volID=-1) const
Function that returns all the hit depositions in the Geant4 event. If a specific volume is given as a...
bool InsertTrack(const G4Track *)
// Implemented in restG4
The main class to store the Geant4 simulation conditions that will be used by restG4.
Recomputes visible hit energies using hit/contained-recoil Lindhard and Birks quenching models.
It saves a 3-coordinate position and an energy for each punctual deposition.
Definition: TRestHits.h:39
Data provider and manager in REST.
Definition: TRestRun.h:18