File indexing completed on 2025-01-18 09:58:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef G4Event_hh
0041 #define G4Event_hh 1
0042
0043 #include <set>
0044 #include <map>
0045
0046 #include "globals.hh"
0047 #include "evtdefs.hh"
0048 #include "G4Allocator.hh"
0049 #include "G4PrimaryVertex.hh"
0050 #include "G4HCofThisEvent.hh"
0051 #include "G4DCofThisEvent.hh"
0052 #include "G4TrajectoryContainer.hh"
0053 #include "G4VUserEventInformation.hh"
0054 #include "G4Profiler.hh"
0055
0056 class G4VHitsCollection;
0057 class G4SubEvent;
0058
0059 class G4Event
0060 {
0061 public:
0062 using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Event>;
0063
0064 public:
0065 G4Event() = default;
0066 explicit G4Event(G4int evID);
0067 ~G4Event();
0068
0069 G4Event(const G4Event &) = delete;
0070 G4Event& operator=(const G4Event &) = delete;
0071
0072 inline void *operator new(std::size_t);
0073 inline void operator delete(void* anEvent);
0074
0075 G4bool operator==(const G4Event& right) const;
0076 G4bool operator!=(const G4Event& right) const;
0077
0078 void Print() const;
0079
0080 void Draw() const;
0081
0082
0083
0084
0085 inline void SetEventID(G4int i)
0086 { eventID = i; }
0087 inline void SetHCofThisEvent(G4HCofThisEvent* value)
0088 { HC = value; }
0089 inline void SetDCofThisEvent(G4DCofThisEvent* value)
0090 { DC = value; }
0091 inline void SetTrajectoryContainer(G4TrajectoryContainer* value)
0092 { trajectoryContainer = value; }
0093 inline void SetEventAborted()
0094 { eventAborted = true; }
0095 inline void SetRandomNumberStatus(G4String& st)
0096 {
0097 randomNumberStatus = new G4String(st);
0098 validRandomNumberStatus = true;
0099 }
0100 inline void SetRandomNumberStatusForProcessing(G4String& st)
0101 {
0102 randomNumberStatusForProcessing = new G4String(st);
0103 validRandomNumberStatusForProcessing = true;
0104 }
0105 inline void KeepTheEvent(G4bool vl=true)
0106 { keepTheEvent = vl; }
0107 inline G4bool ToBeKept() const
0108 { return keepTheEvent || GetNumberOfRemainingSubEvents()>0; }
0109 inline void KeepForPostProcessing() const
0110 { ++grips; }
0111 inline void PostProcessingFinished() const
0112 {
0113 --grips;
0114 if (grips<0)
0115 {
0116 G4Exception("G4Event::Release()", "EVENT91001", FatalException,
0117 "Number of grips is negative. This cannot be correct.");
0118 }
0119 }
0120 inline G4int GetNumberOfGrips() const
0121 { return grips; }
0122
0123 inline G4int GetEventID() const
0124 { return eventID; }
0125
0126 inline void AddPrimaryVertex(G4PrimaryVertex* aPrimaryVertex)
0127 {
0128
0129
0130
0131 if( thePrimaryVertex == nullptr )
0132 { thePrimaryVertex = aPrimaryVertex; }
0133 else
0134 { thePrimaryVertex->SetNext( aPrimaryVertex ); }
0135 ++numberOfPrimaryVertex;
0136 }
0137
0138 inline G4int GetNumberOfPrimaryVertex() const
0139 { return numberOfPrimaryVertex; }
0140
0141
0142 inline G4PrimaryVertex* GetPrimaryVertex(G4int i=0) const
0143 {
0144 if( i == 0 )
0145 { return thePrimaryVertex; }
0146 if( i > 0 && i < numberOfPrimaryVertex )
0147 {
0148 G4PrimaryVertex* primaryVertex = thePrimaryVertex;
0149 for( G4int j=0; j<i; ++j )
0150 {
0151 if( primaryVertex == nullptr ) return nullptr;
0152 primaryVertex = primaryVertex->GetNext();
0153 }
0154 return primaryVertex;
0155 }
0156
0157 return nullptr;
0158 }
0159
0160
0161 inline G4HCofThisEvent* GetHCofThisEvent() const
0162 { return HC; }
0163 inline G4DCofThisEvent* GetDCofThisEvent() const
0164 { return DC; }
0165 inline G4TrajectoryContainer* GetTrajectoryContainer() const
0166 { return trajectoryContainer; }
0167
0168
0169
0170
0171
0172 inline G4bool IsAborted() const { return eventAborted; }
0173
0174
0175
0176 inline void SetUserInformation(G4VUserEventInformation* anInfo)
0177 { userInfo = anInfo; }
0178 inline G4VUserEventInformation* GetUserInformation() const
0179 { return userInfo; }
0180
0181
0182 inline const G4String& GetRandomNumberStatus() const
0183 {
0184 if(!validRandomNumberStatus)
0185 { G4Exception(
0186 "G4Event::GetRandomNumberStatus","Event0701",JustWarning,
0187 "Random number status is not available for this event."); }
0188 return *randomNumberStatus;
0189 }
0190 inline const G4String& GetRandomNumberStatusForProcessing() const
0191 {
0192 if(!validRandomNumberStatusForProcessing)
0193 { G4Exception(
0194 "G4Event::GetRandomNumberStatusForProcessing","Event0702",
0195 JustWarning,
0196 "Random number status is not available for this event."); }
0197 return *randomNumberStatusForProcessing;
0198 }
0199
0200 private:
0201
0202
0203 G4int eventID = 0;
0204
0205
0206 G4PrimaryVertex* thePrimaryVertex = nullptr;
0207 G4int numberOfPrimaryVertex = 0;
0208
0209
0210 G4HCofThisEvent* HC = nullptr;
0211
0212
0213 G4DCofThisEvent* DC = nullptr;
0214
0215
0216 G4TrajectoryContainer* trajectoryContainer = nullptr;
0217
0218
0219
0220 G4bool eventAborted = false;
0221
0222
0223 G4VUserEventInformation* userInfo = nullptr;
0224
0225
0226 G4String* randomNumberStatus = nullptr;
0227 G4bool validRandomNumberStatus = false;
0228
0229
0230 G4String* randomNumberStatusForProcessing = nullptr;
0231 G4bool validRandomNumberStatusForProcessing = false;
0232
0233
0234 G4bool keepTheEvent = false;
0235 mutable G4int grips = 0;
0236
0237
0238
0239
0240 public:
0241 G4SubEvent* PopSubEvent(G4int);
0242
0243
0244 G4int TerminateSubEvent(G4SubEvent*);
0245
0246
0247
0248 G4int StoreSubEvent(G4int,G4SubEvent*);
0249
0250
0251
0252 G4int SpawnSubEvent(G4SubEvent*);
0253
0254 inline G4int GetNumberOfRemainingSubEvents() const
0255
0256
0257 {
0258 auto tot = (G4int)fSubEvtVector.size();
0259 for(auto& sem : fSubEvtStackMap)
0260 { tot += (G4int)sem.second->size(); }
0261 return tot;
0262 }
0263
0264 void MergeSubEventResults(const G4Event* se);
0265
0266 private:
0267 std::map<G4int,std::set<G4SubEvent*>*> fSubEvtStackMap;
0268 std::set<G4SubEvent*> fSubEvtVector;
0269
0270
0271
0272
0273
0274 private:
0275 G4Event* motherEvent = nullptr;
0276 G4int subEventType = -1;
0277
0278 public:
0279 void FlagAsSubEvent(G4Event* me, G4int ty)
0280 {
0281 motherEvent = me;
0282 subEventType = ty;
0283 }
0284 G4Event* GetMotherEvent() const
0285 { return motherEvent; }
0286 G4int GetSubEventType() const
0287 { return subEventType; }
0288 };
0289
0290 extern G4EVENT_DLL G4Allocator<G4Event>*& anEventAllocator();
0291
0292 inline void* G4Event::operator new(std::size_t)
0293 {
0294 if (anEventAllocator() == nullptr)
0295 {
0296 anEventAllocator() = new G4Allocator<G4Event>;
0297 }
0298 return (void*)anEventAllocator()->MallocSingle();
0299 }
0300
0301 inline void G4Event::operator delete(void* anEvent)
0302 {
0303 anEventAllocator()->FreeSingle((G4Event*)anEvent);
0304 }
0305
0306 #endif