Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ITModelProcessor.cc
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 // $Id: G4ITModelProcessor.cc 71125 2013-06-11 15:39:09Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "G4ITModelProcessor.hh"
37 #include "G4VITTimeStepper.hh"
38 #include "G4VITReactionProcess.hh"
39 
40 G4ThreadLocal std::map<const G4Track*, G4bool> *G4ITModelProcessor::fHasReacted = 0;
41 
43 {
44  //ctor
45  if (!fHasReacted) fHasReacted = new std::map<const G4Track*, G4bool>;
46  fpTrack = 0;
47  fpModelHandler = 0;
48  fpModel = 0;
49  fInitialized = false;
50  fpModelManager = 0;
51  fCurrentModel.assign(G4ITType::size(), std::vector<G4VITModel*>());
52 
53  for(int i = 0 ; i < (int) G4ITType::size() ; i++)
54  {
55  fCurrentModel[i].assign(G4ITType::size(),0);
56  }
57  fUserMinTimeStep = -1.;
58 }
59 
61 {
62  //dtor
63 // if(fpModelHandler) delete fpModelHandler; deleted by G4ITStepManager
64  fCurrentModel.clear();
65  fReactionInfo.clear();
66 }
67 
68 // Should not be used
70 {
71  //copy ctorr
72  fpTrack = 0;
73  fpModelHandler = 0;
74  fpModel = 0;
75  fInitialized = false;
76  fpModelManager = 0;
77  fUserMinTimeStep = -1.;
78 }
79 
80 // Should not be used
82 {
83  if (this == &rhs) return *this; // handle self assignment
84  //assignment operator
85  return *this;
86 }
87 //______________________________________________________________________________
89 {
91  fInitialized = true;
92 }
93 
94 //______________________________________________________________________________
95 void G4ITModelProcessor::InitializeStepper(const G4double& currentGlobalTime,
96  const G4double& userMinTime)
97 {
98  // G4cout << "G4ITModelProcessor::InitializeStepper" << G4endl;
99  if(fpModelHandler==0)
100  {
101  G4ExceptionDescription exceptionDescription ;
102  exceptionDescription << "No G4ITModelHandler was passed to the modelProcessor.";
103  G4Exception("G4ITModelProcessor::InitializeStepper","ITModelProcessor002",
104  FatalErrorInArgument,exceptionDescription);
105  }
106  const std::vector<std::vector<G4ITModelManager*> >* modelManager = fpModelHandler
107  ->GetAllModelManager();
108 
109  if(modelManager==0)
110  {
111  G4ExceptionDescription exceptionDescription ;
112  exceptionDescription << "No G4ITModelManager was register to G4ITModelHandler.";
113  G4Exception("G4ITModelProcessor::InitializeStepper","ITModelProcessor003",
114  FatalErrorInArgument,exceptionDescription);
115  }
116 
117  int nbModels1 = modelManager->size() ;
118 
119  G4VITTimeStepper::SetTimes(currentGlobalTime, userMinTime) ;
120 
121  // TODO !!!
122  // if( nbModels1 != 1 || (nbModels1 == 1 && !fpModelManager) )
123  {
124  int nbModels2 = -1;
125  G4VITModel* model = 0;
126  G4ITModelManager* modman = 0;
127 
128  for(int i = 0 ; i < nbModels1 ; i++)
129  {
130  nbModels2 = (*modelManager)[i].size();
131 
132  for(int j = 0 ; j <= i ; j++)
133  {
134  modman = (*modelManager)[i][j];
135 
136  if(modman == 0) continue ;
137 
138  model = modman -> GetModel(currentGlobalTime);
139  G4VITTimeStepper* stepper = model->GetTimeStepper() ;
140 
141 // stepper -> PrepareForAllProcessors() ;
142  stepper -> Prepare() ;
143  fCurrentModel[i][j] = model;
144  }
145  }
146 
147  if(nbModels1 == 1 && nbModels2 ==1)
148  {
149  fpModelManager = modman;
150  fpModel = model;
151  }
152  else fpModel = 0;
153  }
154 }
155 
156 //______________________________________________________________________________
157 void G4ITModelProcessor::CalculateTimeStep(const G4Track* track, const G4double userMinTimeStep)
158 {
159  // G4cout << "G4ITModelProcessor::CalculateStep" << G4endl;
160  CleanProcessor();
161  if(track == 0)
162  {
163  G4ExceptionDescription exceptionDescription ;
164  exceptionDescription << "No track was passed to the method (track == 0).";
165  G4Exception("G4ITModelProcessor::CalculateStep","ITModelProcessor004",
166  FatalErrorInArgument,exceptionDescription);
167  }
168  SetTrack(track);
169  fUserMinTimeStep = userMinTimeStep ;
170 
171  DoCalculateStep();
172 }
173 
174 //______________________________________________________________________________
176 {
177  if(fpModel) // ie only one model has been declared and will be used
178  {
179  fpModel -> GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
180  }
181  else // ie many models have been declared and will be used
182  {
183  std::vector<G4VITModel*>& model = fCurrentModel[GetIT(fpTrack)->GetITType()];
184 
185  for(int i =0 ; i < (int) model.size() ; i++)
186  {
187  if(model[i] == 0) continue;
188  model[i]->GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
189  }
190  }
191 }
192 
193 //______________________________________________________________________________
194 void G4ITModelProcessor::FindReaction(std::map<G4Track*, G4TrackVectorHandle>* tracks,
195  const double currentStepTime,
196  const double previousStepTime,
197  const bool reachedUserStepTimeLimit)
198 {
199  // DEBUG
200  // G4cout << "G4ITReactionManager::FindReaction" << G4endl;
201  if(tracks == 0) return ;
202 
203  if(fpModelHandler->GetAllModelManager()->empty()) return ;
204 
205  std::map<G4Track*, G4TrackVectorHandle>::iterator tracks_i = tracks->begin();;
206 
207  for(tracks_i = tracks->begin() ; tracks_i != tracks-> end() ; tracks_i ++)
208  {
209  /// Get track A
210  G4Track* trackA = tracks_i->first;
211 
212  if(trackA == 0) continue;
213 
214  std::map<const G4Track*, G4bool>::iterator it_hasReacted = fHasReacted->find(trackA);
215  if(it_hasReacted != fHasReacted->end()) continue;
216  if(trackA->GetTrackStatus() == fStopAndKill) continue;
217 
218  G4IT* ITA = GetIT(trackA);
219  G4ITType ITypeA = ITA -> GetITType();
220 
221  const std::vector<G4VITModel*> model = fCurrentModel[ITypeA];
222 
223  G4TrackVectorHandle& trackB_vector = tracks_i->second ;
224  std::vector<G4Track*>::iterator trackB_i = trackB_vector->begin();
225 
226  G4Track* trackB = 0 ;
227  G4ITType ITypeB(-1);
228  G4VITReactionProcess* process = 0;
229  G4ITReactionChange* changes = 0;
230 
231  for(; trackB_i != trackB_vector->end() ; trackB_i++)
232  {
233  trackB = *trackB_i;
234 
235  if(trackB == 0) continue;
236  it_hasReacted = fHasReacted->find(trackB);
237  if(it_hasReacted != fHasReacted->end()) continue;
238  if(trackB->GetTrackStatus() == fStopAndKill) continue;
239 
240  // DEBUG
241  // G4cout << "Couple : " << trackA->GetParticleDefinition->GetParticleName() << " ("
242  // << trackA->GetTrackID() << ") "
243  // << trackB->GetParticleDefinition->GetParticleName() << " ("
244  // << trackB->GetTrackID() << ")"
245  // << G4endl;
246 
247  if(trackB == trackA)
248  {
249  G4ExceptionDescription exceptionDescription ;
250  exceptionDescription << "The IT reaction process sent back a reaction between trackA and trackB. ";
251  exceptionDescription << "The problem is trackA == trackB";
252  G4Exception("G4ITModelProcessor::FindReaction","ITModelProcessor005",
253  FatalErrorInArgument,exceptionDescription);
254  }
255 
256  G4IT* ITB = GetIT(trackB);
257  G4ITType ITypeBtmp = ITB -> GetITType();
258 
259  if(ITypeB != ITypeBtmp)
260  {
261  ITypeB = ITypeBtmp ;
262 
263  if(model[ITypeB])
264  process = model[ITypeB]->GetReactionProcess();
265  }
266 
267  if(process && process -> TestReactibility(*trackA, *trackB,
268  currentStepTime, previousStepTime,
269  reachedUserStepTimeLimit))
270  {
271  changes = process->MakeReaction(*trackA, *trackB);
272  }
273 
274  if(changes)
275  {
276  (*fHasReacted)[trackA] = true;
277  (*fHasReacted)[trackB] = true;
278  changes -> GetTrackA();
279  changes -> GetTrackB();
280 
281  fReactionInfo.push_back(changes);
282 
283  process->ResetChanges();
284  changes = 0;
285 
286  break;
287  }
288  }
289  }
290 
291  fHasReacted->clear();
292 }
const std::vector< std::vector< G4ITModelManager * > > * GetAllModelManager()
Definition: G4IT.hh:82
static G4ThreadLocal std::map< const G4Track *, G4bool > * fHasReacted
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void SetTrack(const G4Track *)
std::vector< G4ITReactionChange * > fReactionInfo
G4TrackStatus GetTrackStatus() const
void CalculateTimeStep(const G4Track *, const G4double)
#define G4ThreadLocal
Definition: tls.hh:52
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:48
static size_t size()
Definition: G4ITType.cc:46
const XML_Char XML_Content * model
G4VITTimeStepper * GetTimeStepper()
Definition: G4VITModel.hh:123
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4ITModelProcessor & operator=(const G4ITModelProcessor &other)
G4ITModelManager * fpModelManager
virtual const G4ITType GetITType() const =0
void FindReaction(std::map< G4Track *, G4TrackVectorHandle > *, const double currentStepTime, const double previousStepTime, const bool reachedUserStepTimeLimit)
void InitializeStepper(const G4double &currentGlobalTime, const G4double &userMinTime)
const G4Track * fpTrack
static void SetTimes(const G4double &, const G4double &)
double G4double
Definition: G4Types.hh:76
std::vector< std::vector< G4VITModel * > > fCurrentModel
virtual G4ITReactionChange * MakeReaction(const G4Track &, const G4Track &)=0
G4ITModelHandler * fpModelHandler