Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ITReaction.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 * G4ITReactionInfo.hh
28 *
29 * Created on: 1 févr. 2015
30 * Author: matkara
31 */
32
33#ifndef G4ITREACTIONINFO_HH_
34#define G4ITREACTIONINFO_HH_
35
36#include "tls.hh"
37#include <list>
38#include <map>
39#include <G4memory.hh>
40#include "G4Track.hh"
41#include <set>
42
43typedef G4shared_ptr< std::vector<G4Track*> > G4TrackVectorHandle;
44
45#ifndef compTrackPerID__
46#define compTrackPerID__
48 {
49 bool operator()(G4Track* rhs, G4Track* lhs) const
50 {
51 return rhs->GetTrackID() < lhs->GetTrackID();
52 }
53 };
54#endif
55
56class G4Track;
57class G4ITReactionSet;
59class G4ITReaction;
60typedef G4shared_ptr<G4ITReaction> G4ITReactionPtr;
61typedef G4shared_ptr<G4ITReactionPerTrack> G4ITReactionPerTrackPtr;
62
63typedef std::list<G4ITReactionPtr> G4ITReactionList;
64typedef std::map<G4Track*,
67typedef std::list<std::pair<G4ITReactionPerTrackPtr,
68 G4ITReactionList::iterator> > G4ReactionPerTrackIt;
69
71{
73 G4ITReactionPtr lhs) const;
74};
75
76typedef std::multiset<G4ITReactionPtr, compReactionPerTime> G4ITReactionPerTime;
77typedef std::multiset<G4ITReactionPtr, compReactionPerTime>::iterator G4ITReactionPerTimeIt;
78
79class G4ITReaction : public G4enable_shared_from_this<G4ITReaction>
80{
81 G4ITReaction(double time, G4Track*, G4Track*);
82public:
83 static G4ITReactionPtr New(double time, G4Track* trackA, G4Track* trackB)
84 {
85 return G4ITReactionPtr(new G4ITReaction(time, trackA, trackB));
86 }
87 virtual ~G4ITReaction();
88
90 {
91 if(fReactants.first != trackA) return fReactants.first;
92 return fReactants.second;
93 }
94
95 std::pair<G4Track*, G4Track*> GetReactants() const{return fReactants;}
96 std::size_t GetHash() const;
97 double GetTime() { return fTime; }
98
99 void RemoveMe();
100
102 G4ITReactionList::iterator it)
103 {
104 fReactionPerTrack.push_back(std::make_pair(reactionPerTrack, it));
105 }
106
108 {
110 }
111
112 double fTime;
113 std::pair<G4Track*, G4Track*> fReactants;
116
117 //static G4ThreadLocal std::set<G4ITReaction*>* gAll;
118};
119
120class G4ITReactionPerTrack : public G4enable_shared_from_this<G4ITReactionPerTrack>
121{
123public:
125 {
127 }
128
130 {
131 fReactions.clear();
132 }
133
135 {
136 G4ITReactionList::iterator it =
137 fReactions.insert(fReactions.end(), reaction);
138 reaction->AddIterator(this->shared_from_this(), it);
139 }
140
141 void AddIterator(G4ITReactionPerTrackMap::iterator it)
142 {
143 fReactionSetIt.push_back(it);
144 }
145
146 bool RemoveThisReaction(G4ITReactionList::iterator it);
147 void RemoveMe()
148 {
149 G4ITReactionPerTrackPtr backMeUp = this->shared_from_this();
150
151 G4ITReactionList::iterator next;
152 for(G4ITReactionList::iterator it = fReactions.begin() ;
153 it != fReactions.end() ; it = next)
154 {
155 next = it;
156 ++next;
157 (*it)->RemoveMe();
158 }
159 fReactions.clear();
160 fReactionSetIt.clear();
161 }
162
164 {
165 return fReactions;
166 }
167
168 std::list<G4ITReactionPerTrackMap::iterator>& GetListOfIterators()
169 {
170 return fReactionSetIt;
171 }
172
173protected:
175 std::list<G4ITReactionPerTrackMap::iterator> fReactionSetIt;
176};
177
179{
180 G4ITReactionSet() //: fReactionPerTime(compReactionPerTime())
181 {
182 fpInstance = this;
183 fSortByTime = false;
184 }
185public:
187 {
188 fReactionPerTrack.clear();
189 fReactionPerTime.clear();
190 }
191
193 {
194 if(fpInstance == 0) new G4ITReactionSet();
195
196 return fpInstance;
197 }
198
199 //------------------------------------------------------------------------------------
200
201 void AddReaction(double time, G4Track* trackA, G4Track* trackB)
202 {
203 G4ITReactionPtr reaction(G4ITReaction::New(time, trackA, trackB));
204 AddReaction(trackA, reaction);
205 AddReaction(trackB, reaction);
206
207 if(fSortByTime)
208 {
209 G4ITReactionPerTime::iterator it = fReactionPerTime.insert(reaction);
210 reaction->AddIterator(it);
211 }
212 }
213
214 void AddReactions(double time, G4Track* trackA, G4TrackVectorHandle reactants)
215 {
216 std::vector<G4Track*>::iterator it = reactants->begin();
217 for(;it != reactants->end() ; ++it)
218 {
219 AddReaction(time, trackA, *it);
220 }
221 }
222
224 {
225 G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.find(track);
226 if(it != fReactionPerTrack.end())
227 {
228 G4ITReactionPerTrackPtr backItUp = it->second->shared_from_this();
229 backItUp->RemoveMe();
230 //fReactionPerTrack.erase(it); // not needed : once empty ==> auto-erase
231 it = fReactionPerTrack.find(track);
232 if(it != fReactionPerTrack.end())
233 {
234 fReactionPerTrack.erase(it);
235 }
236 }
237 }
238
240 {
241 reaction->RemoveMe();
242 RemoveReactionSet(reaction->GetReactants().first);
243 RemoveReactionSet(reaction->GetReactants().second);
244 }
245
247 {
248 return fReactionPerTrack;
249 }
250
252 {
253 for(std::list<G4ITReactionPerTrackMap::iterator>::iterator it =
254 reactionPerTrack->GetListOfIterators().begin() ;
255 it != reactionPerTrack->GetListOfIterators().end() ;
256 ++it)
257 {
258 fReactionPerTrack.erase(*it);
259 }
260 reactionPerTrack->GetListOfIterators().clear();
261 reactionPerTrack->GetReactionList().clear();
262 }
263
265 {
266 for(G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.begin();
267 it != fReactionPerTrack.end() ;
268 it = fReactionPerTrack.begin())
269 {
270 it->second->RemoveMe();
271 }
272 fReactionPerTrack.clear();
273 fReactionPerTime.clear();
274 }
275
276 bool Empty()
277 {
278 return fReactionPerTrack.empty();
279 }
280
282 {
283 return fReactionPerTime;
284 }
285
287 fSortByTime = true;
288 }
289
290protected:
291 void AddReaction(G4Track* track, G4ITReactionPtr reaction)
292 {
293 G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.find(track);
294
295 G4ITReactionPerTrackPtr reactionPerTrack;
296
297 if(it == fReactionPerTrack.end())
298 {
299 reactionPerTrack = G4ITReactionPerTrack::New();
300 std::pair< G4ITReactionPerTrackMap::iterator,bool> pos =
301 fReactionPerTrack.insert(std::make_pair(track, reactionPerTrack));
302 reactionPerTrack->AddIterator(pos.first);
303 }
304 else
305 {
306 reactionPerTrack = it->second;
307 }
308
309 reactionPerTrack->AddReaction(reaction);
310 }
313
316};
317
318#endif /* G4ITREACTIONINFO_HH_ */
G4shared_ptr< G4ITReactionPerTrack > G4ITReactionPerTrackPtr
Definition: G4ITReaction.hh:61
std::list< G4ITReactionPtr > G4ITReactionList
Definition: G4ITReaction.hh:63
G4shared_ptr< G4ITReaction > G4ITReactionPtr
Definition: G4ITReaction.hh:60
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
Definition: G4ITReaction.hh:43
std::multiset< G4ITReactionPtr, compReactionPerTime > G4ITReactionPerTime
Definition: G4ITReaction.hh:76
std::map< G4Track *, G4ITReactionPerTrackPtr, compTrackPerID > G4ITReactionPerTrackMap
Definition: G4ITReaction.hh:66
std::list< std::pair< G4ITReactionPerTrackPtr, G4ITReactionList::iterator > > G4ReactionPerTrackIt
Definition: G4ITReaction.hh:68
std::multiset< G4ITReactionPtr, compReactionPerTime >::iterator G4ITReactionPerTimeIt
Definition: G4ITReaction.hh:77
#define G4enable_shared_from_this
Definition: G4memory.hh:37
void AddIterator(G4ITReactionPerTrackMap::iterator it)
G4ITReactionList fReactions
std::list< G4ITReactionPerTrackMap::iterator > & GetListOfIterators()
void AddReaction(G4ITReactionPtr reaction)
G4ITReactionList & GetReactionList()
std::list< G4ITReactionPerTrackMap::iterator > fReactionSetIt
virtual ~G4ITReactionPerTrack()
static G4ITReactionPerTrackPtr New()
bool RemoveThisReaction(G4ITReactionList::iterator it)
void AddReaction(G4Track *track, G4ITReactionPtr reaction)
static G4ThreadLocal G4ITReactionSet * fpInstance
void RemoveReactionSet(G4Track *track)
virtual ~G4ITReactionSet()
void AddReactions(double time, G4Track *trackA, G4TrackVectorHandle reactants)
void RemoveReactionPerTrack(G4ITReactionPerTrackPtr reactionPerTrack)
static G4ITReactionSet * Instance()
void SelectThisReaction(G4ITReactionPtr reaction)
void CleanAllReaction()
G4ITReactionPerTime fReactionPerTime
G4ITReactionPerTrackMap & GetReactionMap()
void AddReaction(double time, G4Track *trackA, G4Track *trackB)
G4ITReactionPerTrackMap fReactionPerTrack
G4ITReactionPerTime & GetReactionsPerTime()
std::pair< G4Track *, G4Track * > GetReactants() const
Definition: G4ITReaction.hh:95
double GetTime()
Definition: G4ITReaction.hh:97
virtual ~G4ITReaction()
Definition: G4ITReaction.cc:80
std::pair< G4Track *, G4Track * > fReactants
void RemoveMe()
Definition: G4ITReaction.cc:86
G4ReactionPerTrackIt fReactionPerTrack
G4ITReactionPerTimeIt * fReactionPerTimeIt
void AddIterator(G4ITReactionPerTrackPtr reactionPerTrack, G4ITReactionList::iterator it)
static G4ITReactionPtr New(double time, G4Track *trackA, G4Track *trackB)
Definition: G4ITReaction.hh:83
std::size_t GetHash() const
Definition: G4ITReaction.cc:61
void AddIterator(G4ITReactionPerTimeIt it)
G4Track * GetReactant(G4Track *trackA)
Definition: G4ITReaction.hh:89
G4int GetTrackID() const
bool operator()(G4ITReactionPtr rhs, G4ITReactionPtr lhs) const
Definition: G4ITReaction.cc:40
bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:49
#define G4ThreadLocal
Definition: tls.hh:77