Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VModularPhysicsList.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 //
27 // $Id$
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class implementation file
32 // ------------------------------------------------------------
33 // - Add ReplacePhysics 14 Mar 2011 by H.Kurashige
34 // - Add RemovePhysics 2 May 2011 by H.Kurashige
35 //
36 #include "G4VModularPhysicsList.hh"
37 #include "G4StateManager.hh"
38 
39 
42  verboseLevel(0)
43 {
45 }
46 
48 {
49  G4PhysConstVector::iterator itr;
50  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
51  delete (*itr);
52  }
53  physicsVector->clear();
54  delete physicsVector;
55 }
56 
58  verboseLevel(0)
59 {
61 }
62 
64 {
65  if (this != &right) {
76  verboseLevel = right.verboseLevel;
77 
78  if(physicsVector !=0) {
79  G4PhysConstVector::iterator itr;
80  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
81  delete (*itr);
82  }
83  physicsVector->clear();
84  delete physicsVector;
85  }
87  }
88  return *this;
89 }
90 
92 {
93  // create particles
94  G4PhysConstVector::iterator itr;
95  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
96  (*itr)->ConstructParticle();;
97  }
98 }
99 
100 
102 {
104 
105  G4PhysConstVector::iterator itr;
106  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
107  (*itr)->ConstructProcess();
108  }
109 }
110 
111 
112 
114 {
116  G4ApplicationState currentState = stateManager->GetCurrentState();
117  if(!(currentState==G4State_PreInit)){
118  G4Exception("G4VModularPhysicsList::RegisterPhysics",
119  "Run0201", JustWarning,
120  "Geant4 kernel is not PreInit state : Method ignored.");
121  return;
122  }
123 
124  G4String pName = fPhysics->GetPhysicsName();
125  G4int pType = fPhysics->GetPhysicsType();
126  // If physics_type is equal to 0,
127  // following duplication check is omitted
128  // This is TEMPORAL treatment.
129  if (pType == 0) {
130  physicsVector->push_back(fPhysics);
131 #ifdef G4VERBOSE
132  if (verboseLevel >1){
133  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
134  << pName << "with type : " << pType
135  << " is added"
136  << G4endl;
137  }
138 #endif
139  return;
140  }
141 
142  // Check if physics with the physics_type same as one of given physics
143  G4PhysConstVector::iterator itr;
144  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
145  if ( pType == (*itr)->GetPhysicsType()) break;
146  }
147  if (itr!= physicsVector->end()) {
148 #ifdef G4VERBOSE
149  if (verboseLevel >0){
150  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
151  << "a physics with given type already exists "
152  << G4endl;
153  G4cout << " Type = " << pType << " : "
154  << " existing physics is " << (*itr)->GetPhysicsName()
155  << G4endl;
156  G4cout << pName << " can not be registered "<<G4endl;
157  }
158 #endif
159  G4String comment ="Duplicate type for ";
160  comment += pName;
161  G4Exception("G4VModularPhysicsList::RegisterPhysics",
162  "Run0202", JustWarning, comment);
163  return;
164  }
165 
166  // register
167  physicsVector->push_back(fPhysics);
168 
169 }
170 
172 {
174  G4ApplicationState currentState = stateManager->GetCurrentState();
175  if(!(currentState==G4State_PreInit)){
176  G4Exception("G4VModularPhysicsList::ReplacePhysics",
177  "Run0203", JustWarning,
178  "Geant4 kernel is not PreInit state : Method ignored.");
179  return;
180  }
181 
182  G4String pName = fPhysics->GetPhysicsName();
183  G4int pType = fPhysics->GetPhysicsType();
184  // If physics_type is equal to 0,
185  // duplication check is omitted and just added.
186  // This is TEMPORAL treatment.
187  if (pType == 0) {
188  // register
189  physicsVector->push_back(fPhysics);
190 #ifdef G4VERBOSE
191  if (verboseLevel >0){
192  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
193  << pName << "with type : " << pType
194  << " is added"
195  << G4endl;
196  }
197 #endif
198  return;
199  }
200 
201  // Check if physics with the physics_type same as one of given physics
202  G4PhysConstVector::iterator itr= physicsVector->begin();
203  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
204  if ( pType == (*itr)->GetPhysicsType()) break;
205  }
206  if (itr == physicsVector->end()) {
207  // register
208  physicsVector->push_back(fPhysics);
209  } else {
210 #ifdef G4VERBOSE
211  if (verboseLevel >0){
212  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
213  << (*itr)->GetPhysicsName() << "with type : " << pType
214  << " is replaces with " << pName
215  << G4endl;
216  }
217 #endif
218 
219  // delete exsiting one
220  delete (*itr);
221  // replace with given one
222  (*itr) = fPhysics;
223 
224  }
225 
226  return;
227 }
228 
230 {
232  G4ApplicationState currentState = stateManager->GetCurrentState();
233  if(!(currentState==G4State_PreInit)){
234  G4Exception("G4VModularPhysicsList::RemovePhysics",
235  "Run0204", JustWarning,
236  "Geant4 kernel is not PreInit state : Method ignored.");
237  return;
238  }
239 
240  for (G4PhysConstVector::iterator itr = physicsVector->begin();
241  itr!= physicsVector->end();) {
242  if ( pType == (*itr)->GetPhysicsType()) {
243  G4String pName = (*itr)->GetPhysicsName();
244 #ifdef G4VERBOSE
245  if (verboseLevel > 0){
246  G4cout << "G4VModularPhysicsList::RemovePhysics: "
247  << pName << " is removed"
248  << G4endl;
249  }
250 #endif
251  physicsVector->erase(itr);
252  break;
253  } else {
254  itr++;
255  }
256  }
257 }
258 
260 {
262  G4ApplicationState currentState = stateManager->GetCurrentState();
263  if(!(currentState==G4State_PreInit)){
264  G4Exception("G4VModularPhysicsList::RemovePhysics",
265  "Run0205", JustWarning,
266  "Geant4 kernel is not PreInit state : Method ignored.");
267  return;
268  }
269 
270  for (G4PhysConstVector::iterator itr = physicsVector->begin();
271  itr!= physicsVector->end();) {
272  if ( fPhysics == (*itr)) {
273  G4String pName = (*itr)->GetPhysicsName();
274 #ifdef G4VERBOSE
275  if (verboseLevel > 0 ){
276  G4cout << "G4VModularPhysicsList::RemovePhysics: "
277  << pName << " is removed"
278  << G4endl;
279  }
280 #endif
281  physicsVector->erase(itr);
282  break;
283  } else {
284  itr++;
285  }
286  }
287 }
289 {
291  G4ApplicationState currentState = stateManager->GetCurrentState();
292  if(!(currentState==G4State_PreInit)){
293  G4Exception("G4VModularPhysicsList::RemovePhysics",
294  "Run0206", JustWarning,
295  "Geant4 kernel is not PreInit state : Method ignored.");
296  return;
297  }
298 
299  for (G4PhysConstVector::iterator itr = physicsVector->begin();
300  itr!= physicsVector->end();) {
301  G4String pName = (*itr)->GetPhysicsName();
302  if ( name == pName) {
303 #ifdef G4VERBOSE
304  if (verboseLevel > 0){
305  G4cout << "G4VModularPhysicsList::RemovePhysics: "
306  << pName << " is removed"
307  << G4endl;
308  }
309 #endif
310  physicsVector->erase(itr);
311  break;
312  } else {
313  itr++;
314  }
315  }
316 }
317 
319 {
320  G4int i;
321  G4PhysConstVector::iterator itr= physicsVector->begin();
322  for (i=0; i<idx && itr!= physicsVector->end() ; ++i) ++itr;
323  if (itr!= physicsVector->end()) return (*itr);
324  else return 0;
325 }
326 
328 {
329  G4PhysConstVector::iterator itr;
330  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
331  if ( name == (*itr)->GetPhysicsName()) break;
332  }
333  if (itr!= physicsVector->end()) return (*itr);
334  else return 0;
335 }
336 
338 {
339  G4PhysConstVector::iterator itr;
340  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
341  if ( pType == (*itr)->GetPhysicsType()) break;
342  }
343  if (itr!= physicsVector->end()) return (*itr);
344  else return 0;
345 }
346 
347 
349 {
351 
352  // Loop over constructors
353  G4PhysConstVector::iterator itr;
354  for (itr = physicsVector->begin(); itr!= physicsVector->end(); ++itr) {
355  (*itr)->SetVerboseLevel(verboseLevel);
356  }
357 
358 }