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 Int_t fNVolumes;
123 std::vector<Int_t> fVolumeStored;
124 std::vector<std::string> fVolumeStoredNames;
125 std::vector<Double_t> fVolumeDepositedEnergy;
126 std::map<std::string, std::map<std::string, std::map<std::string, double>>>
127 fEnergyInVolumePerParticlePerProcess;
128 std::vector<TRestGeant4Track> fTracks;
129
130 public:
131 void SetBoundaries();
132 void SetBoundaries(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin,
133 Double_t zMax);
134
135 Double_t GetBoundingBoxSize();
136
137 inline size_t GetNumberOfPrimaries() const { return fPrimaryParticleNames.size(); }
138
139 inline TString GetPrimaryEventParticleName(size_t n = 0) const { return fPrimaryParticleNames[n]; }
140 inline TVector3 GetPrimaryEventDirection(size_t n = 0) const { return fPrimaryDirections[n]; }
141 inline TVector3 GetPrimaryEventOrigin() const { return fPrimaryPosition; }
142 inline Double_t GetPrimaryEventEnergy(size_t n = 0) const { return fPrimaryEnergies[n]; }
143
144 inline Bool_t IsSubEvent() const { return fSubEventID > 0; }
145 inline TString GetSubEventPrimaryEventParticleName() const { return fSubEventPrimaryParticleName; }
146 inline TVector3 GetSubEventPrimaryEventDirection() const { return fSubEventPrimaryDirection; }
147 inline TVector3 GetSubEventPrimaryEventOrigin() const { return fSubEventPrimaryPosition; }
148 inline Double_t GetSubEventPrimaryEventEnergy() const { return fSubEventPrimaryEnergy; }
149
150 size_t GetNumberOfHits(Int_t volID = -1) const;
151 size_t GetNumberOfPhysicalHits(Int_t volID = -1) const;
152
153 inline const std::vector<TRestGeant4Track>& GetTracks() const { return fTracks; }
154 inline size_t GetNumberOfTracks() const { return fTracks.size(); }
155 inline Int_t GetNumberOfActiveVolumes() const { return fNVolumes; }
156
157 inline Int_t isVolumeStored(int n) const { return fVolumeStored[n]; }
158 inline const TRestGeant4Track& GetTrack(int n) const { return fTracks[n]; }
159 inline TRestGeant4Track* GetTrackPointer(int n) { return &fTracks[n]; }
160 TRestGeant4Track* GetTrackByID(Int_t trackID) const;
161
162 inline Double_t GetTotalDepositedEnergy() const { return fTotalDepositedEnergy; }
163 inline Double_t GetEnergyDepositedInVolume(Int_t volID) const { return fVolumeDepositedEnergy[volID]; }
164 inline Double_t GetSensitiveVolumeEnergy() const { return fSensitiveVolumeEnergy; }
165 TVector3 GetMeanPositionInVolume(Int_t volID) const;
166 TVector3 GetFirstPositionInVolume(Int_t volID) const;
167 TVector3 GetLastPositionInVolume(Int_t volID) const;
168 TVector3 GetPositionDeviationInVolume(Int_t volID) const;
169
170 std::map<std::string, std::map<std::string, std::map<std::string, double>>>
171 GetEnergyInVolumePerParticlePerProcessMap() const;
172 std::map<std::string, std::map<std::string, double>> GetEnergyInVolumePerProcessMap() const;
173 std::map<std::string, std::map<std::string, double>> GetEnergyInVolumePerParticleMap() const;
174 std::map<std::string, double> GetEnergyPerProcessMap() const;
175 std::map<std::string, double> GetEnergyPerParticleMap() const;
176 std::map<std::string, double> GetEnergyInVolumeMap() const;
177
178 inline Double_t GetEnergyInVolume(const std::string& volumeName) const {
179 auto energyMap = GetEnergyInVolumeMap();
180 return energyMap[volumeName];
181 }
182
183 TRestHits GetHits(Int_t volID = -1) const;
184 inline TRestHits GetHitsInVolume(Int_t volID) const { return GetHits(volID); }
185
186 Int_t GetNumberOfTracksForParticle(const TString& particleName) const;
187 Double_t GetEnergyDepositedByParticle(const TString& particleName) const;
188
189 inline void ActivateVolumeForStorage(Int_t n) { fVolumeStored[n] = 1; }
190 inline void DisableVolumeForStorage(Int_t n) { fVolumeStored[n] = 0; }
191
192 void AddActiveVolume(const std::string& volumeName);
193 void ClearVolumes();
194 inline void AddEnergyToSensitiveVolume(Double_t en) { fSensitiveVolumeEnergy += en; }
195
196 inline void SetEnergyDepositedInVolume(Int_t volID, Double_t eDep) {
197 fVolumeDepositedEnergy[volID] = eDep;
198 }
199 inline void SetSensitiveVolumeEnergy(Double_t en) { fSensitiveVolumeEnergy = en; }
200
201 inline Int_t GetLowestTrackID() const {
202 Int_t lowestID = 0;
203 if (GetNumberOfTracks() > 0) {
204 lowestID = GetTrack(0).GetTrackID();
205 }
206
207 for (unsigned int i = 0; i < GetNumberOfTracks(); i++) {
208 auto tr = GetTrack(i);
209 if (tr.GetTrackID() < lowestID) lowestID = tr.GetTrackID();
210 }
211
212 return lowestID;
213 }
214
215 std::set<std::string> GetUniqueParticles() const;
216
217 Bool_t ContainsProcessInVolume(Int_t processID, Int_t volumeID = -1) const;
218 inline Bool_t ContainsProcess(Int_t processID) const { return ContainsProcessInVolume(processID, -1); }
219
220 Bool_t ContainsProcessInVolume(const TString& processName, Int_t volumeID = -1) const;
221 inline Bool_t ContainsProcess(const TString& processName) const {
222 return ContainsProcessInVolume(processName, -1);
223 }
224
225 Bool_t ContainsParticle(const TString& particleName) const;
226 Bool_t ContainsParticleInVolume(const TString& particleName, Int_t volumeID = -1) const;
227
228 void Initialize() override;
229
230 void InitializeReferences(TRestRun* run) override;
231
232 const TRestGeant4Metadata* GetGeant4Metadata(const char* name = "TRestGeant4Metadata") const;
233
235 void PrintActiveVolumes() const;
236 void PrintEvent(int maxTracks = 0, int maxHits = 0) const;
237
238 inline TPad* DrawEvent(const TString& option = "") override { return DrawEvent(option, true); }
239 TPad* DrawEvent(const TString& option, Bool_t autoBoundaries);
240
241 // Constructor
243
244 // Destructor
245 virtual ~TRestGeant4Event();
246
247 ClassDefOverride(TRestGeant4Event, 8); // REST event superclass
248
249 // restG4
250 public:
251 TRestGeant4Event(const G4Event*);
252 bool InsertTrack(const G4Track*);
253 void UpdateTrack(const G4Track*);
254 void InsertStep(const G4Step*);
255
256 friend class OutputManager;
257
258 private:
259 std::map<Int_t, Int_t> fTrackIDToTrackIndex = {};
260 TRestGeant4Hits fInitialStep;
261
262 void AddEnergyInVolumeForParticleForProcess(Double_t energy, const std::string& volumeName,
263 const std::string& particleName,
264 const std::string& processName);
265};
266#endif
A base class for any REST event.
Definition: TRestEvent.h:38
virtual void PrintEvent() const
Definition: TRestEvent.cxx:181
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.
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