Geant4  10.02.p02
G4Event.hh
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 // $Id: G4Event.hh 97477 2016-06-03 10:13:42Z gcosmo $
28 //
29 //
30 // class description:
31 //
32 // This is the class which represents an event. A G4Event is constructed and
33 // deleted by G4RunManager (or its derived class). When a G4Event object is
34 // passed to G4EventManager, G4Event must have one or more primary verteces
35 // and primary particle(s) associated to the vertex(es) as an input of
36 // simulating an event.
37 // G4Event has trajectories, hits collections, and/or digi collections.
38 
39 #ifndef G4Event_h
40 #define G4Event_h 1
41 
42 #include "globals.hh"
43 #include "evtdefs.hh"
44 #include "G4Allocator.hh"
45 #include "G4PrimaryVertex.hh"
46 #include "G4HCofThisEvent.hh"
47 #include "G4DCofThisEvent.hh"
48 #include "G4TrajectoryContainer.hh"
50 
51 class G4VHitsCollection;
52 class G4Event
53 {
54  public:
55  G4Event();
56  G4Event(G4int evID);
57  ~G4Event();
58 
59  inline void *operator new(size_t);
60  inline void operator delete(void* anEvent);
61 
62  G4int operator==(const G4Event &right) const;
63  G4int operator!=(const G4Event &right) const;
64 
65  public: // with description
66  void Print() const;
67  // Print the event ID (starts with zero and increments by one) to G4cout.
68  void Draw() const;
69  // Invoke Draw() methods of all stored trajectories, hits, and digits.
70  // For hits and digits, Draw() methods of the concrete classes must be
71  // implemented. Otherwise nothing will be drawn.
72 
73  private:
74  // Copy constructor and = operator must not be used.
75  G4Event(const G4Event &) {;}
76  G4Event& operator=(const G4Event &) { return *this; }
77 
78  private:
79  // event ID
81 
82  // PrimaryVertex
85 
86  // HitsCollection
88 
89  // DigiCollection
91 
92  // TrajectoryContainer
94 
95  // Boolean flag which shall be set to true if the event is aborted and
96  // thus the containing information is not to be used.
98 
99  // UserEventInformation (optional)
101 
102  // Initial random number engine status before primary particle generation
105 
106  // Initial random number engine status before event processing
109 
110  // Flag to keep the event until the end of run
112  mutable G4int grips;
113 
114  public:
115  inline void SetEventID(G4int i)
116  { eventID = i; }
118  { HC = value; }
120  { DC = value; }
122  { trajectoryContainer = value; }
123  inline void SetEventAborted()
124  { eventAborted = true; }
126  {
127  randomNumberStatus = new G4String(st);
128  validRandomNumberStatus = true;
129  }
131  {
132  randomNumberStatusForProcessing = new G4String(st);
133  validRandomNumberStatusForProcessing = true;
134  }
135  inline void KeepTheEvent(G4bool vl=true)
136  { keepTheEvent = vl; }
137  inline G4bool ToBeKept() const
138  { return keepTheEvent; }
139  inline void KeepForPostProcessing() const
140  { grips++; }
141  inline void PostProcessingFinished() const
142  { grips--;
143  if(grips<0)
144  { G4Exception("G4Event::Release()","EVENT91001",FatalException,
145  "Number of grips becames negative. This cannot be correct."); }
146  }
147  inline G4int GetNumberOfGrips() const
148  { return grips; }
149 
150  public: // with description
151  inline G4int GetEventID() const
152  { return eventID; }
153  // Returns the event ID
154  inline void AddPrimaryVertex(G4PrimaryVertex* aPrimaryVertex)
155  {
156  if( thePrimaryVertex == nullptr )
157  { thePrimaryVertex = aPrimaryVertex; }
158  else
159  { thePrimaryVertex->SetNext( aPrimaryVertex ); }
160  numberOfPrimaryVertex++;
161  }
162  // This method sets a new primary vertex. This method must be invoked
163  // exclusively by G4VPrimaryGenerator concrete class.
165  { return numberOfPrimaryVertex; }
166  // Returns number of primary vertexes the G4Event object has.
168  {
169  if( i == 0 )
170  { return thePrimaryVertex; }
171  else if( i > 0 && i < numberOfPrimaryVertex )
172  {
173  G4PrimaryVertex* primaryVertex = thePrimaryVertex;
174  for( G4int j=0; j<i; j++ )
175  {
176  if( !primaryVertex ) return nullptr;
177  primaryVertex = primaryVertex->GetNext();
178  }
179  return primaryVertex;
180  }
181  else
182  { return nullptr; }
183  }
184  // Returns i-th primary vertex of the event.
186  { return HC; }
188  { return DC; }
190  { return trajectoryContainer; }
191  // These three methods returns the pointers to the G4HCofThisEvent
192  // (hits collections of this event), G4DCofThisEvent (digi collections
193  // of this event), and G4TrajectoryContainer (trajectory coonainer),
194  // respectively.
195  inline G4bool IsAborted() const { return eventAborted; }
196  // Return a boolean which indicates the event has been aborted and thus
197  // it should not be used for analysis.
198  inline void SetUserInformation(G4VUserEventInformation* anInfo) { userInfo = anInfo; }
200  // Set and Get method of G4VUserEventInformation
201  inline const G4String& GetRandomNumberStatus() const
202  {
203  if(!validRandomNumberStatus)
204  { G4Exception(
205  "G4Event::GetRandomNumberStatus","Event0701",JustWarning,
206  "Random number status is not available for this event."); }
207  return *randomNumberStatus;
208  }
210  {
211  if(!validRandomNumberStatusForProcessing)
212  { G4Exception(
213  "G4Event::GetRandomNumberStatusForProcessing","Event0702",
214  JustWarning,
215  "Random number status is not available for this event."); }
217  }
218 };
219 
221 
222 inline void* G4Event::operator new(size_t)
223 {
225  return (void*)anEventAllocator->MallocSingle();
226 }
227 
228 inline void G4Event::operator delete(void* anEvent)
229 {
230  anEventAllocator->FreeSingle((G4Event*)anEvent);
231 }
232 
233 #endif
G4VUserEventInformation * GetUserInformation() const
Definition: G4Event.hh:199
G4int grips
Definition: G4Event.hh:112
const G4String & GetRandomNumberStatusForProcessing() const
Definition: G4Event.hh:209
G4bool validRandomNumberStatusForProcessing
Definition: G4Event.hh:108
G4int GetNumberOfPrimaryVertex() const
Definition: G4Event.hh:164
#define G4EVENT_DLL
Definition: evtdefs.hh:48
G4int GetNumberOfGrips() const
Definition: G4Event.hh:147
G4int operator==(const G4Event &right) const
Definition: G4Event.cc:79
void AddPrimaryVertex(G4PrimaryVertex *aPrimaryVertex)
Definition: G4Event.hh:154
void SetRandomNumberStatusForProcessing(G4String &st)
Definition: G4Event.hh:130
void SetHCofThisEvent(G4HCofThisEvent *value)
Definition: G4Event.hh:117
void Print() const
Definition: G4Event.cc:89
G4EVENT_DLL G4ThreadLocal G4Allocator< G4Event > * anEventAllocator
Definition: G4Event.cc:40
G4bool keepTheEvent
Definition: G4Event.hh:111
~G4Event()
Definition: G4Event.cc:64
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
G4TrajectoryContainer * GetTrajectoryContainer() const
Definition: G4Event.hh:189
const G4String & GetRandomNumberStatus() const
Definition: G4Event.hh:201
G4bool eventAborted
Definition: G4Event.hh:97
G4int GetEventID() const
Definition: G4Event.hh:151
G4Event(const G4Event &)
Definition: G4Event.hh:75
G4bool ToBeKept() const
Definition: G4Event.hh:137
G4String * randomNumberStatus
Definition: G4Event.hh:103
G4int numberOfPrimaryVertex
Definition: G4Event.hh:84
void SetUserInformation(G4VUserEventInformation *anInfo)
Definition: G4Event.hh:198
G4Event()
Definition: G4Event.cc:42
bool G4bool
Definition: G4Types.hh:79
G4VUserEventInformation * userInfo
Definition: G4Event.hh:100
void KeepForPostProcessing() const
Definition: G4Event.hh:139
G4PrimaryVertex * thePrimaryVertex
Definition: G4Event.hh:83
G4DCofThisEvent * DC
Definition: G4Event.hh:90
void SetNext(G4PrimaryVertex *nv)
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:167
G4String * randomNumberStatusForProcessing
Definition: G4Event.hh:107
void SetEventAborted()
Definition: G4Event.hh:123
G4PrimaryVertex * GetNext() const
void PostProcessingFinished() const
Definition: G4Event.hh:141
void Draw() const
Definition: G4Event.cc:94
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetRandomNumberStatus(G4String &st)
Definition: G4Event.hh:125
G4Event & operator=(const G4Event &)
Definition: G4Event.hh:76
void SetDCofThisEvent(G4DCofThisEvent *value)
Definition: G4Event.hh:119
G4int eventID
Definition: G4Event.hh:80
G4bool validRandomNumberStatus
Definition: G4Event.hh:104
G4HCofThisEvent * GetHCofThisEvent() const
Definition: G4Event.hh:185
void SetTrajectoryContainer(G4TrajectoryContainer *value)
Definition: G4Event.hh:121
G4DCofThisEvent * GetDCofThisEvent() const
Definition: G4Event.hh:187
void KeepTheEvent(G4bool vl=true)
Definition: G4Event.hh:135
G4HCofThisEvent * HC
Definition: G4Event.hh:87
G4int operator!=(const G4Event &right) const
Definition: G4Event.cc:84
void SetEventID(G4int i)
Definition: G4Event.hh:115
G4TrajectoryContainer * trajectoryContainer
Definition: G4Event.hh:93
G4bool IsAborted() const
Definition: G4Event.hh:195