ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VModularPhysicsList.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VModularPhysicsList.cc
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 //
28 //
29 // ------------------------------------------------------------
30 // GEANT 4 class implementation file
31 // ------------------------------------------------------------
32 // - Add ReplacePhysics 14 Mar 2011 by H.Kurashige
33 // - Add RemovePhysics 2 May 2011 by H.Kurashige
34 //
35 #include "G4VModularPhysicsList.hh"
36 #include "G4StateManager.hh"
37 #include <algorithm>
38 
39 // This macros change the references to fields that are now encapsulated
40 // in the class G4VMPLData.
41 #define G4MT_physicsVector ((G4VMPLsubInstanceManager.offset[g4vmplInstanceID]).physicsVector)
42 
44 
46 {
48 }
49 
50 //G4ThreadLocal G4VModularPhysicsList::G4PhysConstVector* G4VModularPhysicsList::physicsVector = 0;
51 
54  verboseLevel(0)
55 {
57 }
58 
60 {
61  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
62  delete (*itr);
63  }
64  G4MT_physicsVector->clear();
65  delete G4MT_physicsVector;
66 }
67 
69  verboseLevel(0)
70 {
72 }
73 
75 {
76  if (this != &right) {
84  //fDisplayThreshold = static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
85  (this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold=
86  static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
87  //fIsPhysicsTableBuilt = static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
88  (this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold=
89  static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
90  //fDisplayThreshold = right.fDisplayThreshold;
92  verboseLevel = right.verboseLevel;
93 
94  if(G4MT_physicsVector !=0) {
95  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
96  delete (*itr);
97  }
98  G4MT_physicsVector->clear();
99  delete G4MT_physicsVector;
100  }
102  }
103  return *this;
104 }
105 
107 {
108  // create particles
109  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
110  (*itr)->ConstructParticle();;
111  }
112 }
113 
114 
115 //Andrea Dotti: May 6 2013
116 //Current limitation being debugged: Construction of physics processes
117 //needs to be sequential (there is at least one HAD processes creating problems)
118 //This is not yet understood and needs to be debugged since we do not want
119 //this part to be sequential (imagine when one has 100 threads)
120 //TODO: Remove this lock
121 #include "G4AutoLock.hh"
122 namespace {
123  G4Mutex constructProcessMutex = G4MUTEX_INITIALIZER;
124 }
125 
127 {
128  G4AutoLock l(&constructProcessMutex); //Protection to be removed (A.Dotti)
130 
131  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
132  (*itr)->ConstructProcess();
133  }
134 }
135 
136 
137 
139 {
141  G4ApplicationState currentState = stateManager->GetCurrentState();
142  if(!(currentState==G4State_PreInit)){
143  G4Exception("G4VModularPhysicsList::RegisterPhysics",
144  "Run0201", JustWarning,
145  "Geant4 kernel is not PreInit state : Method ignored.");
146  return;
147  }
148 
149  G4String pName = fPhysics->GetPhysicsName();
150  G4int pType = fPhysics->GetPhysicsType();
151  // If physics_type is equal to 0,
152  // following duplication check is omitted
153  // This is TEMPORAL treatment.
154  if (pType == 0) {
155  G4MT_physicsVector->push_back(fPhysics);
156 #ifdef G4VERBOSE
157  if (verboseLevel >1){
158  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
159  << pName << "with type : " << pType
160  << " is added"
161  << G4endl;
162  }
163 #endif
164  return;
165  }
166 
167  // Check if physics with the physics_type same as one of given physics
168  auto itr = G4MT_physicsVector->begin();
169  for (; itr!= G4MT_physicsVector->end(); ++itr) {
170  if ( pType == (*itr)->GetPhysicsType()) break;
171  }
172  if (itr!= G4MT_physicsVector->end()) {
173 #ifdef G4VERBOSE
174  if (verboseLevel >0){
175  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
176  << "a physics with given type already exists "
177  << G4endl;
178  G4cout << " Type = " << pType << " : "
179  << " existing physics is " << (*itr)->GetPhysicsName()
180  << G4endl;
181  G4cout << pName << " can not be registered "<<G4endl;
182  }
183 #endif
184  G4String comment ="Duplicate type for ";
185  comment += pName;
186  G4Exception("G4VModularPhysicsList::RegisterPhysics",
187  "Run0202", JustWarning, comment);
188  return;
189  }
190 
191  // register
192  G4MT_physicsVector->push_back(fPhysics);
193 
194 }
195 
197 {
199  G4ApplicationState currentState = stateManager->GetCurrentState();
200  if(!(currentState==G4State_PreInit)){
201  G4Exception("G4VModularPhysicsList::ReplacePhysics",
202  "Run0203", JustWarning,
203  "Geant4 kernel is not PreInit state : Method ignored.");
204  return;
205  }
206 
207  G4String pName = fPhysics->GetPhysicsName();
208  G4int pType = fPhysics->GetPhysicsType();
209  // If physics_type is equal to 0,
210  // duplication check is omitted and just added.
211  // This is TEMPORAL treatment.
212  if (pType == 0) {
213  // register
214  G4MT_physicsVector->push_back(fPhysics);
215 #ifdef G4VERBOSE
216  if (verboseLevel >0){
217  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
218  << pName << "with type : " << pType
219  << " is added"
220  << G4endl;
221  }
222 #endif
223  return;
224  }
225 
226  // Check if physics with the physics_type same as one of given physics
227  auto itr= G4MT_physicsVector->begin();
228  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
229  if ( pType == (*itr)->GetPhysicsType()) break;
230  }
231  if (itr == G4MT_physicsVector->end()) {
232  // register
233  G4MT_physicsVector->push_back(fPhysics);
234  } else {
235 #ifdef G4VERBOSE
236  if (verboseLevel >0){
237  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
238  << (*itr)->GetPhysicsName() << "with type : " << pType
239  << " is replaces with " << pName
240  << G4endl;
241  }
242 #endif
243 
244  // delete exsiting one
245  delete (*itr);
246  // replace with given one
247  (*itr) = fPhysics;
248 
249  }
250 
251  return;
252 }
253 
255 {
257  G4ApplicationState currentState = stateManager->GetCurrentState();
258  if(!(currentState==G4State_PreInit)){
259  G4Exception("G4VModularPhysicsList::RemovePhysics",
260  "Run0204", JustWarning,
261  "Geant4 kernel is not PreInit state : Method ignored.");
262  return;
263  }
264 
265  for (auto itr = G4MT_physicsVector->begin();
266  itr!= G4MT_physicsVector->end();) {
267  if ( pType == (*itr)->GetPhysicsType()) {
268  G4String pName = (*itr)->GetPhysicsName();
269 #ifdef G4VERBOSE
270  if (verboseLevel > 0){
271  G4cout << "G4VModularPhysicsList::RemovePhysics: "
272  << pName << " is removed"
273  << G4endl;
274  }
275 #endif
276  G4MT_physicsVector->erase(itr);
277  break;
278  } else {
279  itr++;
280  }
281  }
282 }
283 
285 {
287  G4ApplicationState currentState = stateManager->GetCurrentState();
288  if(!(currentState==G4State_PreInit)){
289  G4Exception("G4VModularPhysicsList::RemovePhysics",
290  "Run0205", JustWarning,
291  "Geant4 kernel is not PreInit state : Method ignored.");
292  return;
293  }
294 
295  for (auto itr = G4MT_physicsVector->begin();
296  itr!= G4MT_physicsVector->end();) {
297  if ( fPhysics == (*itr)) {
298  G4String pName = (*itr)->GetPhysicsName();
299 #ifdef G4VERBOSE
300  if (verboseLevel > 0 ){
301  G4cout << "G4VModularPhysicsList::RemovePhysics: "
302  << pName << " is removed"
303  << G4endl;
304  }
305 #endif
306  G4MT_physicsVector->erase(itr);
307  break;
308  } else {
309  itr++;
310  }
311  }
312 }
314 {
316  G4ApplicationState currentState = stateManager->GetCurrentState();
317  if(!(currentState==G4State_PreInit)){
318  G4Exception("G4VModularPhysicsList::RemovePhysics",
319  "Run0206", JustWarning,
320  "Geant4 kernel is not PreInit state : Method ignored.");
321  return;
322  }
323 
324  for (auto itr = G4MT_physicsVector->begin();
325  itr!= G4MT_physicsVector->end();) {
326  G4String pName = (*itr)->GetPhysicsName();
327  if ( name == pName) {
328 #ifdef G4VERBOSE
329  if (verboseLevel > 0){
330  G4cout << "G4VModularPhysicsList::RemovePhysics: "
331  << pName << " is removed"
332  << G4endl;
333  }
334 #endif
335  G4MT_physicsVector->erase(itr);
336  break;
337  } else {
338  itr++;
339  }
340  }
341 }
342 
344 {
345  G4int i;
346  auto itr= G4MT_physicsVector->begin();
347  for (i=0; i<idx && itr!= G4MT_physicsVector->end() ; ++i) ++itr;
348  if (itr!= G4MT_physicsVector->end()) return (*itr);
349  else return 0;
350 }
351 
353 {
354  auto itr = G4MT_physicsVector->begin();
355  for (; itr!= G4MT_physicsVector->end(); ++itr) {
356  if ( name == (*itr)->GetPhysicsName()) break;
357  }
358  if (itr!= G4MT_physicsVector->end()) return (*itr);
359  else return 0;
360 }
361 
363 {
364  auto itr = G4MT_physicsVector->begin();
365  for (; itr!= G4MT_physicsVector->end(); ++itr) {
366  if ( pType == (*itr)->GetPhysicsType()) break;
367  }
368  if (itr!= G4MT_physicsVector->end()) return (*itr);
369  else return 0;
370 }
371 
372 
374 {
376  // Loop over constructors
377  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
378  (*itr)->SetVerboseLevel(verboseLevel);
379  }
380 
381 }
382 
384 {
385  //See https://jira-geant4.kek.jp/browse/DEV-284
386  std::for_each( G4MT_physicsVector->begin() , G4MT_physicsVector->end() ,
387  [](G4PhysConstVector::value_type el) { el->TerminateWorker();});
389 }