source: trunk/source/processes/biasing/src/G4ProcessPlacer.cc @ 1253

Last change on this file since 1253 was 1228, checked in by garnier, 14 years ago

update geant4.9.3 tag

File size: 8.4 KB
Line 
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: G4ProcessPlacer.cc,v 1.5 2008/04/21 09:10:29 ahoward Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4ProcessPlacer.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4ProcessPlacer.hh"
38#include "G4ProcessManager.hh"
39#include "G4VProcess.hh"
40#include "G4ParticleTable.hh"
41
42G4ProcessPlacer::G4ProcessPlacer(const G4String &particlename)
43  : fParticleName(particlename)
44{
45}
46
47G4ProcessPlacer::~G4ProcessPlacer()
48{
49}
50
51void G4ProcessPlacer::RemoveProcess(G4VProcess *process)
52{
53  G4cout << "=== G4ProcessPlacer::RemoveProcess: for: " <<  fParticleName
54         << G4endl;
55  G4cout << "  ProcessName: " << process->GetProcessName() 
56         << ", will be removed!" << G4endl;
57
58  G4cout << "  The initial AlongStep Vectors: " << G4endl;
59  PrintAlongStepGPILVec();
60  PrintAlongStepDoItVec();
61
62  G4cout << "  The initial PostStep Vectors: " << G4endl;
63  PrintPostStepGPILVec();
64  PrintPostStepDoItVec();
65
66  GetProcessManager()->RemoveProcess(process);
67
68  G4cout << "  The final AlongStep Vectors: " << G4endl;
69  PrintAlongStepGPILVec();
70  PrintAlongStepDoItVec();
71
72  G4cout << "  The final PostStep Vectors: " << G4endl;
73  PrintPostStepGPILVec();
74  PrintPostStepDoItVec();
75
76  G4cout << "================================================" << G4endl;
77 
78}
79
80void G4ProcessPlacer::AddProcessAs(G4VProcess *process, SecondOrLast sol)
81{
82  G4cout << "  Modifying Process Order for ProcessName: " << process->GetProcessName() << G4endl;
83
84  G4cout << "  The initial AlongStep Vectors: " << G4endl;
85  PrintAlongStepGPILVec();
86  PrintAlongStepDoItVec();
87
88  G4cout << "The initial PostStep Vectors: " << G4endl;
89  PrintPostStepGPILVec();
90  PrintPostStepDoItVec();
91
92  if (sol == eLast)
93  { 
94    GetProcessManager()->AddProcess(process, ordInActive, ordInActive, ordLast);
95  } 
96  else if (sol == eSecond)
97  {
98    // get transportation process
99    G4VProcess *transportation = 
100     (* (GetProcessManager()->GetProcessList()))[0];
101
102    if (!transportation)
103    {
104      G4Exception(" G4ProcessPlacer:: could not get process id=0");
105    }
106    if (transportation->GetProcessName() != "Transportation" && transportation->GetProcessName() != "Transportation8" && transportation->GetProcessName() != "CoupledTransportation")
107    {
108      //      G4cout << " GOT HERE CoupledTransportation" << G4endl;
109      G4cout << transportation->GetProcessName() << G4endl;
110      G4Exception(" G4ProcessPlacer:: process id=0 is not Transportation");
111    }
112
113    // place the given proces as first for the moment
114    GetProcessManager()->AddProcess(process);
115    GetProcessManager()->SetProcessOrderingToFirst(process, 
116                                                  idxAlongStep);
117    GetProcessManager()->SetProcessOrderingToFirst(process, 
118                                                  idxPostStep);
119    // xx test
120    //     if(process->GetProcessName() == "ImportanceProcess")
121    //bug31/10/07    GetProcessManager()->SetProcessOrdering(process,
122    //bug31/10/07                                           idxAlongStep, 1);
123    // place transportation first again
124    GetProcessManager()->SetProcessOrderingToFirst(transportation, 
125                                                  idxAlongStep);
126    GetProcessManager()->SetProcessOrderingToFirst(transportation, 
127                                                  idxPostStep);
128  }
129 
130  // for verification inly
131  G4cout << "  The final AlongStep Vectors: " << G4endl;
132  PrintAlongStepGPILVec();
133  PrintAlongStepDoItVec();
134
135  G4cout << "The final PostStep Vectors: " << G4endl;
136  PrintPostStepGPILVec();
137  PrintPostStepDoItVec();
138 
139  G4cout << "================================================" << G4endl;
140}
141
142void G4ProcessPlacer::AddProcessAsSecondDoIt(G4VProcess *process)
143{
144  G4cout << "=== G4ProcessPlacer::AddProcessAsSecondDoIt: for: " 
145         << fParticleName << G4endl;
146  AddProcessAs(process, eSecond);
147}
148
149void G4ProcessPlacer::AddProcessAsLastDoIt(G4VProcess *process)
150{
151  G4cout << "=== G4ProcessPlacer::AddProcessAsLastDoIt: for: " 
152         << fParticleName << G4endl;
153  AddProcessAs(process, eLast);
154}
155
156G4ProcessManager *G4ProcessPlacer::GetProcessManager()
157{ 
158  // get particle iterator to add processes ---------------------
159  G4ParticleTable* theParticleTable = 0;
160  G4ParticleTable::G4PTblDicIterator* theParticleIterator = 0;
161  theParticleTable = G4ParticleTable::GetParticleTable();
162  theParticleIterator = theParticleTable->GetIterator();
163  // -------------------------------------------------------
164  G4ProcessManager *processmanager = 0;
165  // find process manager ---------------------------
166  theParticleIterator->reset();
167  while( (*theParticleIterator)() )
168  {
169    G4ParticleDefinition* particle = theParticleIterator->value();
170    if (particle->GetParticleName() == fParticleName)
171    {
172      processmanager =  particle->GetProcessManager();
173      break;
174    }
175  }
176  // ---------------------------------------------------------
177  if (!processmanager)
178  {
179    G4Exception("G4ProcessPlacer::GetProcessManager()", "InvalidSetup",
180                FatalException, "NULL pointer to Process Manager ! Sampler.Configure() must be after PhysicsList instantiation");
181  }
182  return processmanager;
183}
184
185void G4ProcessPlacer::PrintAlongStepGPILVec()
186{
187  G4cout << "GPIL Vector: " << G4endl;
188  G4ProcessVector* processGPILVec = 
189    GetProcessManager()->GetAlongStepProcessVector(typeGPIL);
190  PrintProcVec(processGPILVec);
191} 
192
193void G4ProcessPlacer::PrintAlongStepDoItVec()
194{
195  G4cout << "DoIt Vector: " << G4endl;
196  G4ProcessVector* processDoItVec = 
197    GetProcessManager()->GetAlongStepProcessVector(typeDoIt); 
198  PrintProcVec(processDoItVec);
199}
200
201
202void G4ProcessPlacer::PrintPostStepGPILVec()
203{
204  G4cout << "GPIL Vector: " << G4endl;
205  G4ProcessVector* processGPILVec = 
206    GetProcessManager()->GetPostStepProcessVector(typeGPIL);
207  PrintProcVec(processGPILVec);
208} 
209
210void G4ProcessPlacer::PrintPostStepDoItVec()
211{
212  G4cout << "DoIt Vector: " << G4endl;
213  G4ProcessVector* processDoItVec = 
214    GetProcessManager()->GetPostStepProcessVector(typeDoIt); 
215  PrintProcVec(processDoItVec);
216}
217
218
219void G4ProcessPlacer::PrintProcVec(G4ProcessVector* processVec)
220{
221  if (!processVec)
222  {
223    G4Exception("G4ProcessPlacer::G4ProcessPlacer()", "InvalidArgument",
224                FatalException, "NULL pointer to process-vector !");
225  }
226  G4int len = processVec->length();
227  if (len==0)
228  {
229    G4Exception("G4ProcessPlacer::G4ProcessPlacer()", "InvalidSetup",
230                FatalException, "Length of process-vector is zero !");
231  }
232  for (int pi=0; pi<len; pi++)
233  {
234    G4VProcess *p = (*processVec)[pi];
235    if (p)
236    {
237      G4cout << "   " << p->GetProcessName() << G4endl;
238    } 
239    else
240    {
241      G4cout << "   " << "no process found for position: " << pi
242             << ", in vector of length: " << len << G4endl;
243    }
244  }
245}
Note: See TracBrowser for help on using the repository browser.