Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VUserPhysicsList.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: G4VUserPhysicsList.cc 73604 2013-09-02 09:31:25Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // ------------------------------------------------------------
34 // History
35 // first version 09 Jan 1998 by H.Kurashige
36 // Added SetEnergyRange 18 Jun 1998 by H.Kurashige
37 // Change for short lived particles 27 Jun 1998 by H.Kurashige
38 // G4BestUnit on output 12 nov 1998 by M.Maire
39 // Added RemoveProcessManager 9 Feb 1999 by H.Kurashige
40 // Fixed RemoveProcessManager 15 Apr 1999 by H.Kurashige
41 // Removed ConstructAllParticles() 15 Apr 1999 by H.Kurashige
42 // Modified for CUTS per REGION 10 Oct 2002 by H.Kurashige
43 // Check if particle IsShortLived 18 Jun 2003 by V.Ivanchenko
44 // Modify PreparePhysicsList 18 Jan 2006 by H.Kurashige
45 // Added PhysicsListHelper 29 APr. 2011 H.Kurashige
46 // Added default impelmentation of SetCuts 10 June 2011 H.Kurashige
47 // SetCuts is not 'pure virtual' any more
48 // Transformation for G4MT 26 Mar 2013 A. Dotti
49 // PL is shared by threads. Adding a method for workers
50 // To initialize thread specific data
51 // ------------------------------------------------------------
52 
53 #include <iomanip>
54 #include <fstream>
55 
56 #include "G4PhysicsListHelper.hh"
57 #include "G4VUserPhysicsList.hh"
58 
59 //Andrea Dotti (Jan 13, 2013), transformation for G4MT
60 #include "G4VMultipleScattering.hh"
61 #include "G4VEnergyLossProcess.hh"
62 
63 
64 #include "globals.hh"
65 #include "G4SystemOfUnits.hh"
66 #include "G4ios.hh"
67 #include "G4ParticleDefinition.hh"
68 #include "G4ProcessManager.hh"
69 #include "G4ParticleTable.hh"
70 #include "G4ProductionCutsTable.hh"
71 #include "G4Material.hh"
73 #include "G4UImanager.hh"
74 #include "G4UnitsTable.hh"
75 #include "G4RegionStore.hh"
76 #include "G4Region.hh"
77 #include "G4ProductionCutsTable.hh"
78 #include "G4ProductionCuts.hh"
79 #include "G4MaterialCutsCouple.hh"
80 
81 // This static member is thread local. For each thread, it holds the array
82 // size of G4VUPLData instances.
83 //
84 template <class G4VUPLData> G4ThreadLocal
86 
87 // This static member is thread local. For each thread, it points to the
88 // array of G4VUPLData instances.
89 //
90 template <class G4VUPLData> G4ThreadLocal
92 
93 // This field helps to use the class G4VUPLManager
94 //
96 
98 {
100  _theMessenger = 0;
102  _fIsPhysicsTableBuilt = false;
103  _fDisplayThreshold = 0;
104 }
105 
106 ////////////////////////////////////////////////////////
108  :verboseLevel(1),
109  defaultCutValue(1.0 * mm),
110  isSetDefaultCutValue(false),
111  fRetrievePhysicsTable(false),
112  fStoredInAscii(true),
113  fIsCheckedForRetrievePhysicsTable(false),
114  fIsRestoredCutValues(false),
115  directoryPhysicsTable("."),
116  //fDisplayThreshold(0),
117  //fIsPhysicsTableBuilt(false),
118  fDisableCheckParticleList(false)
119 {
121  // default cut value (1.0mm)
122  defaultCutValue = 1.0*mm;
123 
124  // pointer to the particle table
126  //theParticleIterator = theParticleTable->GetIterator();
127 
128  // pointer to the cuts table
130 
131  // set energy range for SetCut calcuration
132  fCutsTable->SetEnergyRange(0.99*keV, 100*TeV);
133 
134  // UI Messenger
135  //theMessenger = new G4UserPhysicsListMessenger(this);
137 
138  // PhysicsListHelper
139  //thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper();
140  //thePLHelper->SetVerboseLevel(verboseLevel);
141  //G4MT_thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper(); //AND
142  G4MT_thePLHelper->SetVerboseLevel(verboseLevel); //AND
143 
144  fIsPhysicsTableBuilt = false;
145  fDisplayThreshold = 0;
146 
147 }
148 
150 {
151  //Remember messengers are per-thread, so this needs to be done by each worker
152  //and due to the presence of "this" cannot be done in G4VUPLData::initialize()
154 }
155 
156 ////////////////////////////////////////////////////////
158 {
159  if (G4MT_theMessenger != 0) {
160  delete G4MT_theMessenger;
161  G4MT_theMessenger = 0;
162  }
164 
165  // invoke DeleteAllParticle
167 
168 }
169 
170 ////////////////////////////////////////////////////////
172  :verboseLevel(right.verboseLevel),
173  defaultCutValue(right.defaultCutValue),
174  isSetDefaultCutValue(right.isSetDefaultCutValue),
175  fRetrievePhysicsTable(right.fRetrievePhysicsTable),
176  fStoredInAscii(right.fStoredInAscii),
177  fIsCheckedForRetrievePhysicsTable(right.fIsCheckedForRetrievePhysicsTable),
178  fIsRestoredCutValues(right.fIsRestoredCutValues),
179  directoryPhysicsTable(right.directoryPhysicsTable),
180  //fDisplayThreshold(right.fDisplayThreshold),
181  //fIsPhysicsTableBuilt(right.fIsPhysicsTableBuilt),
182  fDisableCheckParticleList(right.fDisableCheckParticleList)
183 {
185  // pointer to the particle table
188  // pointer to the cuts table
190 
191  // UI Messenger
192  //theMessenger = new G4UserPhysicsListMessenger(this);
194 
195  // PhysicsListHelper
196  //thePLHelper = G4PhysicsListHelper::GetPhysicsListHelper();
197  //thePLHelper->SetVerboseLevel(verboseLevel);
199  G4MT_thePLHelper->SetVerboseLevel(verboseLevel); //AND
200 
201  fIsPhysicsTableBuilt = right.GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
202  fDisplayThreshold = right.GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
203 }
204 
205 
206 ////////////////////////////////////////////////////////
208 {
209  if (this != &right) {
210  verboseLevel = right.verboseLevel;
218  //fDisplayThreshold = right.fDisplayThreshold;
219  fIsPhysicsTableBuilt = right.GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
220  fDisplayThreshold = right.GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
221  //fIsPhysicsTableBuilt = right.fIsPhysicsTableBuilt;
223  }
224  return *this;
225 }
226 
227 ////////////////////////////////////////////////////////
230 {
231  if (newParticle == 0) return;
232  G4Exception("G4VUserPhysicsList::AddProcessManager",
233  "Run0252", JustWarning,
234  "This method is obsolete");
235 }
236 
237 
238 ////////////////////////////////////////////////////////
240 {
241  //Request lock for particle table accesses. Some changes are inside
242  //this critical region.
243 #ifdef G4MULTITHREADED
244  G4MUTEXLOCK(&G4ParticleTable::particleTableMutex);
245  G4ParticleTable::lockCount++;
246 #endif
248 
249  // loop over all particles in G4ParticleTable
250  theParticleIterator->reset();
251  while( (*theParticleIterator)() ){
252  G4ParticleDefinition* particle = theParticleIterator->value();
253  G4ProcessManager* pmanager = particle->GetProcessManager();
254 
255  if (pmanager==0) {
256  // create process manager if the particle does not have its own.
257  pmanager = new G4ProcessManager(particle);
258  particle->SetProcessManager(pmanager);
259  if( particle->GetMasterProcessManager() == 0 ) particle->SetMasterProcessManager(pmanager);
260 #ifdef G4VERBOSE
261  if (verboseLevel >2){
262  G4cout << "G4VUserPhysicsList::InitializeProcessManager: creating ProcessManager to "
263  << particle->GetParticleName() << G4endl;
264  }
265 #endif
266  }
267  }
268 
269  if(gion)
270  {
271  G4ProcessManager* gionPM = gion->GetProcessManager();
272  // loop over all particles once again (this time, with all general ions)
273  theParticleIterator->reset(false);
274  while( (*theParticleIterator)() ){
275  G4ParticleDefinition* particle = theParticleIterator->value();
276  if(particle->IsGeneralIon())
277  {
278  particle->SetProcessManager(gionPM);
279 #ifdef G4VERBOSE
280  if (verboseLevel >2){
281  G4cout << "G4VUserPhysicsList::InitializeProcessManager: copying ProcessManager to "
282  << particle->GetParticleName() << G4endl;
283  }
284 #endif
285  }
286  }
287  }
288 
289  //release lock for particle table accesses.
290 #ifdef G4MULTITHREADED
291  G4MUTEXUNLOCK(&G4ParticleTable::particleTableMutex);
292 #endif
293 // G4cout << "Particle table is released by G4VUserPhysicsList::InitializeProcessManager" << G4endl;
294 
295 }
296 
297 /////////////////////////////////////////////////////////
299 {
300  //Request lock for particle table accesses. Some changes are inside
301  //this critical region.
302 #ifdef G4MULTITHREADED
303  G4MUTEXLOCK(&G4ParticleTable::particleTableMutex);
304  G4ParticleTable::lockCount++;
305 #endif
306 // G4cout << "Particle table is held by G4VUserPhysicsList::InitializeProcessManager" << G4endl;
307 
308  // loop over all particles in G4ParticleTable
309  theParticleIterator->reset();
310  while( (*theParticleIterator)() ){
311  G4ParticleDefinition* particle = theParticleIterator->value();
313  {
314  if(particle->GetParticleSubType()!="generic" || particle->GetParticleName()=="GenericIon")
315  {
316  G4ProcessManager* pmanager = particle->GetProcessManager();
317  if (pmanager!=0) delete pmanager;
318 #ifdef G4VERBOSE
319  if (verboseLevel >2){
320  G4cout << "G4VUserPhysicsList::RemoveProcessManager: ";
321  G4cout << "remove ProcessManager from ";
322  G4cout << particle->GetParticleName() << G4endl;
323  }
324 #endif
325  }
326  particle->SetProcessManager(0);
327  }
328  }
329 
330  //release lock for particle table accesses.
331 #ifdef G4MULTITHREADED
332  G4MUTEXUNLOCK(&G4ParticleTable::particleTableMutex);
333 #endif
334 // G4cout << "Particle table is released by G4VUserPhysicsList::InitializeProcessManager" << G4endl;
335 
336 }
337 
338 ////////////////////////////////////////////////////////
340 {
341  if ( !isSetDefaultCutValue ){
343  }
344 
345 #ifdef G4VERBOSE
346  if (verboseLevel >1){
347  G4cout << "G4VUserPhysicsList::SetCuts: " << G4endl;
348  G4cout << "Cut for gamma: " << GetCutValue("gamma")/mm
349  << "[mm]" << G4endl;
350  G4cout << "Cut for e-: " << GetCutValue("e-")/mm
351  << "[mm]" << G4endl;
352  G4cout << "Cut for e+: " << GetCutValue("e+")/mm
353  << "[mm]" << G4endl;
354  G4cout << "Cut for proton: " << GetCutValue("proton")/mm
355  << "[mm]" << G4endl;
356  }
357 #endif
358 
359  // dump Cut values if verboseLevel==3
360  if (verboseLevel>2) {
362  }
363 }
364 
365 
366 ////////////////////////////////////////////////////////
368 {
369  if (value<0.0) {
370 #ifdef G4VERBOSE
371  if (verboseLevel >0){
372  G4cout << "G4VUserPhysicsList::SetDefaultCutValue: negative cut values"
373  << " :" << value/mm << "[mm]" << G4endl;
374  }
375 #endif
376  return;
377  }
378 
380  isSetDefaultCutValue = true;
381 
382  // set cut values for gamma at first and for e- and e+
383  SetCutValue(defaultCutValue, "gamma");
386  SetCutValue(defaultCutValue, "proton");
387 
388 #ifdef G4VERBOSE
389  if (verboseLevel >1){
390  G4cout << "G4VUserPhysicsList::SetDefaultCutValue:"
391  << "default cut value is changed to :"
392  << defaultCutValue/mm << "[mm]" << G4endl;
393  }
394 #endif
395  }
396 
397 
398 ////////////////////////////////////////////////////////
400 {
401  size_t nReg = (G4RegionStore::GetInstance())->size();
402  if (nReg==0) {
403 #ifdef G4VERBOSE
404  if (verboseLevel>0){
405  G4cout << "G4VUserPhysicsList::GetCutValue "
406  <<" : No Default Region " <<G4endl;
407  }
408 #endif
409  G4Exception("G4VUserPhysicsList::GetCutValue",
410  "Run0253", FatalException,
411  "No Default Region");
412  return -1.*mm;
413  }
414  G4Region* region = (*(G4RegionStore::GetInstance()))[0];
415  return region->GetProductionCuts()->GetProductionCut(name);
416 }
417 
418 ////////////////////////////////////////////////////////
420 {
421  SetParticleCuts( aCut ,name );
422 }
423 
424 ////////////////////////////////////////////////////////
426 (G4double aCut, const G4String& pname, const G4String& rname)
427 {
428  G4Region* region = G4RegionStore::GetInstance()->GetRegion(rname);
429  if (region != 0){
430  //set cut value
431  SetParticleCuts( aCut ,pname, region );
432  } else {
433 #ifdef G4VERBOSE
434  if (verboseLevel>0){
435  G4cout << "G4VUserPhysicsList::SetCutValue "
436  <<" : No Region of " << rname << G4endl;
437  }
438 #endif
439  }
440 }
441 
442 
443 ////////////////////////////////////////////////////////
445 {
448 }
449 
450 ////////////////////////////////////////////////////////
452 {
453  // set cut values for gamma at first and for e- and e+
454  SetCutValue(aCut, "gamma", rname);
455  SetCutValue(aCut, "e-", rname);
456  SetCutValue(aCut, "e+", rname);
457  SetCutValue(aCut, "proton", rname);
458 }
459 
460 
461 
462 ////////////////////////////////////////////////////////
464 {
465  SetParticleCuts(cut, particle->GetParticleName(), region);
466 }
467 
468 ////////////////////////////////////////////////////////
469 void G4VUserPhysicsList::SetParticleCuts( G4double cut, const G4String& particleName, G4Region* region)
470 {
471  if (cut<0.0) {
472 #ifdef G4VERBOSE
473  if (verboseLevel >0){
474  G4cout << "G4VUserPhysicsList::SetParticleCuts: negative cut values"
475  << " :" << cut/mm << "[mm]"
476  << " for "<< particleName << G4endl;
477  }
478 #endif
479  return;
480  }
481 
482  if(!region){
483  size_t nReg = (G4RegionStore::GetInstance())->size();
484  if (nReg==0) {
485 #ifdef G4VERBOSE
486  if (verboseLevel>0){
487  G4cout << "G4VUserPhysicsList::SetParticleCuts "
488  <<" : No Default Region " <<G4endl;
489  }
490 #endif
491  G4Exception("G4VUserPhysicsList::SetParticleCuts ",
492  "Run0254", FatalException,
493  "No Default Region");
494  return;
495  }
496  region = (*(G4RegionStore::GetInstance()))[0];
497  }
498 
499  if ( !isSetDefaultCutValue ){
501  }
502 
503  G4ProductionCuts* pcuts = region->GetProductionCuts();
504  pcuts->SetProductionCut(cut,particleName);
505 #ifdef G4VERBOSE
506  if (verboseLevel>2){
507  G4cout << "G4VUserPhysicsList::SetParticleCuts: "
508  << " :" << cut/mm << "[mm]"
509  << " for "<< particleName << G4endl;
510  }
511 #endif
512 }
513 
514 ///////////////////////////////////////////////////////////////
516 {
517  //Prepare Physics table for all particles
518  theParticleIterator->reset();
519  while( (*theParticleIterator)() ){
520  G4ParticleDefinition* particle = theParticleIterator->value();
521  PreparePhysicsTable(particle);
522  }
523 
524  // ask processes to prepare physics table
525  if (fRetrievePhysicsTable) {
527  // check if retrieve Cut Table successfully
528  if (!fIsRestoredCutValues) {
529 #ifdef G4VERBOSE
530  if (verboseLevel>0){
531  G4cout << "G4VUserPhysicsList::BuildPhysicsTable"
532  << " Retrieve Cut Table failed !!" << G4endl;
533  }
534 #endif
535  G4Exception("G4VUserPhysicsList::BuildPhysicsTable",
536  "Run0255", RunMustBeAborted,
537  "Fail to retrieve Production Cut Table");
538  } else {
539 #ifdef G4VERBOSE
540  if (verboseLevel>2){
541  G4cout << "G4VUserPhysicsList::BuildPhysicsTable"
542  << " Retrieve Cut Table successfully " << G4endl;
543  }
544 #endif
545  }
546  } else {
547 #ifdef G4VERBOSE
548  if (verboseLevel>2){
549  G4cout << "G4VUserPhysicsList::BuildPhysicsTable"
550  << " does not retrieve Cut Table but calculate " << G4endl;
551  }
552 #endif
553  }
554 
555  // Sets a value to particle
556  // set cut values for gamma at first and for e- and e+
557  G4String particleName;
559  if(GammaP) BuildPhysicsTable(GammaP);
561  if(EMinusP) BuildPhysicsTable(EMinusP);
563  if(EPlusP) BuildPhysicsTable(EPlusP);
564  G4ParticleDefinition* ProtonP = theParticleTable->FindParticle("proton");
565  if(ProtonP) BuildPhysicsTable(ProtonP);
566 
567  theParticleIterator->reset();
568  while( (*theParticleIterator)() ){
569  G4ParticleDefinition* particle = theParticleIterator->value();
570  if( particle!=GammaP &&
571  particle!=EMinusP &&
572  particle!=EPlusP &&
573  particle!=ProtonP ){
574  BuildPhysicsTable(particle);
575  }
576  }
577 
578  // Set flag
579  fIsPhysicsTableBuilt = true;
580 
581 }
582 ///////////////////////////////////////////////////////////////
583 //Change in order to share physics tables for two kind of process.
585 {
586  if(!(particle->GetMasterProcessManager())) {
587  G4cout << "#### G4VUserPhysicsList::BuildPhysicsTable() - BuildPhysicsTable("
588  << particle->GetParticleName() << ") skipped..." << G4endl;
589  return;
590  }
591  if (fRetrievePhysicsTable) {
592  if ( !fIsRestoredCutValues){
593  // fail to retreive cut tables
594 #ifdef G4VERBOSE
595  if (verboseLevel>0){
596  G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
597  << "Physics table can not be retreived and will be calculated "
598  << G4endl;
599  }
600 #endif
601  fRetrievePhysicsTable = false;
602 
603  } else {
604 #ifdef G4VERBOSE
605  if (verboseLevel>2){
606  G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
607  << " Retrieve Physics Table for "
608  << particle->GetParticleName() << G4endl;
609  }
610 #endif
611  // Retrieve PhysicsTable from files for proccesses
613  }
614  }
615 
616 #ifdef G4VERBOSE
617  if (verboseLevel>2){
618  G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
619  << "Calculate Physics Table for "
620  << particle->GetParticleName() << G4endl;
621  }
622 #endif
623  // Rebuild the physics tables for every process for this particle type
624  // if particle is not ShortLived
625  if(!particle->IsShortLived()) {
626  G4ProcessManager* pManager = particle->GetProcessManager();
627  if (!pManager) {
628 #ifdef G4VERBOSE
629  if (verboseLevel>0){
630  G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
631  <<" : No Process Manager for "
632  << particle->GetParticleName() << G4endl;
633  G4cout << particle->GetParticleName()
634  << " should be created in your PhysicsList" <<G4endl;
635  }
636 #endif
637  G4Exception("G4VUserPhysicsList::BuildPhysicsTable",
638  "Run0271", FatalException,
639  "No process manager");
640  return;
641  }
642 
643  //Get processes from master thread;
644  G4ProcessManager* pManagerShadow = particle->GetMasterProcessManager();
645 
646  G4ProcessVector* pVector = pManager->GetProcessList();
647  if (!pVector) {
648 #ifdef G4VERBOSE
649  if (verboseLevel>0){
650  G4cout << "G4VUserPhysicsList::BuildPhysicsTable "
651  <<" : No Process Vector for "
652  << particle->GetParticleName() <<G4endl;
653  }
654 #endif
655  G4Exception("G4VUserPhysicsList::BuildPhysicsTable",
656  "Run0272", FatalException,
657  "No process Vector");
658  return;
659  }
660 #ifdef G4VERBOSE
661  if (verboseLevel>2){
662  G4cout << "G4VUserPhysicsList::BuildPhysicsTable %%%%%% " << particle->GetParticleName() << G4endl;
663  G4cout << " ProcessManager : " << pManager << " ProcessManagerShadow : " << pManagerShadow << G4endl;
664  for(G4int iv1=0;iv1<pVector->size();iv1++)
665  { G4cout << " " << iv1 << " - " << (*pVector)[iv1]->GetProcessName() << G4endl; }
666  G4cout << "--------------------------------------------------------------" << G4endl;
667  G4ProcessVector* pVectorShadow = pManagerShadow->GetProcessList();
668 
669  for(G4int iv2=0;iv2<pVectorShadow->size();iv2++)
670  { G4cout << " " << iv2 << " - " << (*pVectorShadow)[iv2]->GetProcessName() << G4endl; }
671  }
672 #endif
673  for (G4int j=0; j < pVector->size(); ++j) {
674  //Andrea July 16th 2013 : migration to new interface...
675  //Infer if we are in a worker thread or master thread
676  //Master thread is the one in which the process manager
677  // and process manager shadow pointers are the same
678  if ( pManagerShadow == pManager )
679  {
680  (*pVector)[j]->BuildPhysicsTable(*particle);
681  }
682  else
683  {
684  (*pVector)[j]->BuildWorkerPhysicsTable(*particle);
685  }
686 
687  } //End loop on processes vector
688  } //End if short-lived
689 }
690 
691 ///////////////////////////////////////////////////////////////
693 {
694  if(!(particle->GetMasterProcessManager())) {
695 //// G4cout << "#### G4VUserPhysicsList::BuildPhysicsTable() - BuildPhysicsTable("
696 //// << particle->GetParticleName() << ") skipped..." << G4endl;
697  return;
698  }
699  // Prepare the physics tables for every process for this particle type
700  // if particle is not ShortLived
701  if(!particle->IsShortLived()) {
702  G4ProcessManager* pManager = particle->GetProcessManager();
703  if (!pManager) {
704 #ifdef G4VERBOSE
705  if (verboseLevel>0) {
706  G4cout<< "G4VUserPhysicsList::PreparePhysicsTable "
707  << ": No Process Manager for "
708  << particle->GetParticleName() <<G4endl;
709  G4cout << particle->GetParticleName()
710  << " should be created in your PhysicsList" <<G4endl;
711  }
712 #endif
713  G4Exception("G4VUserPhysicsList::PreparePhysicsTable",
714  "Run0273", FatalException,
715  "No process manager");
716  return;
717  }
718 
719  //Get processes from master thread
720  G4ProcessManager* pManagerShadow = particle->GetMasterProcessManager();
721  //Andrea Dotti 15 Jan 2013: Change of interface of MSC
722  //G4ProcessVector* pVectorShadow = pManagerShadow->GetProcessList();
723 
724  G4ProcessVector* pVector = pManager->GetProcessList();
725  if (!pVector) {
726 #ifdef G4VERBOSE
727  if (verboseLevel>0) {
728  G4cout << "G4VUserPhysicsList::PreparePhysicsTable "
729  << ": No Process Vector for "
730  << particle->GetParticleName() <<G4endl;
731  }
732 #endif
733  G4Exception("G4VUserPhysicsList::PreparePhysicsTable",
734  "Run0274", FatalException,
735  "No process Vector");
736  return;
737  }
738  for (G4int j=0; j < pVector->size(); ++j) {
739 
740  //Andrea July 16th 2013 : migration to new interface...
741  //Infer if we are in a worker thread or master thread
742  //Master thread is the one in which the process manager
743  // and process manager shadow pointers are the same
744  if ( pManagerShadow == pManager )
745  {
746  (*pVector)[j]->PreparePhysicsTable(*particle);
747  }
748  else
749  {
750  (*pVector)[j]->PrepareWorkerPhysicsTable(*particle);
751  }
752  } //End loop on processes vector
753  } //End if pn ShortLived
754 }
755 
756 //TODO Should we change this function?
757 ///////////////////////////////////////////////////////////////
759  G4ParticleDefinition* particle)
760 {
761  //*********************************************************************
762  // temporary addition to make the integral schema of electromagnetic
763  // processes work.
764  //
765 
766  if ( (process->GetProcessName() == "Imsc") ||
767  (process->GetProcessName() == "IeIoni") ||
768  (process->GetProcessName() == "IeBrems") ||
769  (process->GetProcessName() == "Iannihil") ||
770  (process->GetProcessName() == "IhIoni") ||
771  (process->GetProcessName() == "IMuIoni") ||
772  (process->GetProcessName() == "IMuBrems") ||
773  (process->GetProcessName() == "IMuPairProd") ) {
774 #ifdef G4VERBOSE
775  if (verboseLevel>2){
776  G4cout << "G4VUserPhysicsList::BuildIntegralPhysicsTable "
777  << " BuildPhysicsTable is invoked for "
778  << process->GetProcessName()
779  << "(" << particle->GetParticleName() << ")" << G4endl;
780  }
781 #endif
782  process->BuildPhysicsTable(*particle);
783  }
784 }
785 
786 ///////////////////////////////////////////////////////////////
788 {
789  theParticleIterator->reset();
790  G4int idx = 0;
791  while( (*theParticleIterator)() ){
792  G4ParticleDefinition* particle = theParticleIterator->value();
793  G4cout << particle->GetParticleName();
794  if ((idx++ % 4) == 3) {
795  G4cout << G4endl;
796  } else {
797  G4cout << ", ";
798  }
799  }
800  G4cout << G4endl;
801 }
802 
803 
804 ///////////////////////////////////////////////////////////////
806 {
807  fDisplayThreshold = flag;
808 }
809 
810 ///////////////////////////////////////////////////////////////
812 {
813  if(fDisplayThreshold==0) return;
815  fDisplayThreshold = 0;
816 }
817 
818 
819 ///////////////////////////////////////////////////////////////
821 {
822  G4bool ascii = fStoredInAscii;
823  G4String dir = directory;
824  if (dir.isNull()) dir = directoryPhysicsTable;
825  else directoryPhysicsTable = dir;
826 
827  // store CutsTable info
828  if (!fCutsTable->StoreCutsTable(dir, ascii)) {
829  G4Exception("G4VUserPhysicsList::StorePhysicsTable",
830  "Run0281", JustWarning,
831  "Fail to store Cut Table");
832  return false;
833  }
834 #ifdef G4VERBOSE
835  if (verboseLevel>2){
836  G4cout << "G4VUserPhysicsList::StorePhysicsTable "
837  << " Store material and cut values successfully" << G4endl;
838  }
839 #endif
840 
841  G4bool success= true;
842 
843  // loop over all particles in G4ParticleTable
844  theParticleIterator->reset();
845  while( (*theParticleIterator)() ){
846  G4ParticleDefinition* particle = theParticleIterator->value();
847  // Store physics tables for every process for this particle type
848  G4ProcessVector* pVector = (particle->GetProcessManager())->GetProcessList();
849  G4int j;
850  for ( j=0; j < pVector->size(); ++j) {
851  if (!(*pVector)[j]->StorePhysicsTable(particle,dir,ascii)){
852  G4String comment = "Fail to store physics table for ";
853  comment += (*pVector)[j]->GetProcessName();
854  comment += "(" + particle->GetParticleName() + ")";
855  G4Exception("G4VUserPhysicsList::StorePhysicsTable",
856  "Run0282", JustWarning,
857  comment);
858  success = false;
859  }
860  }
861  // end loop over processes
862  }
863  // end loop over particles
864  return success;
865 }
866 
867 
868 
869 ///////////////////////////////////////////////////////////////
871 {
872  fRetrievePhysicsTable = true;
873  if(!directory.isNull()) {
874  directoryPhysicsTable = directory;
875  }
877  fIsRestoredCutValues = false;
878 }
879 
880 ///////////////////////////////////////////////////////////////
882  const G4String& directory,
883  G4bool ascii)
884 {
885  G4int j;
886  G4bool success[100];
887  // Retrieve physics tables for every process for this particle type
888  G4ProcessVector* pVector = (particle->GetProcessManager())->GetProcessList();
889  for ( j=0; j < pVector->size(); ++j) {
890  success[j] =
891  (*pVector)[j]->RetrievePhysicsTable(particle,directory,ascii);
892 
893  if (!success[j]) {
894 #ifdef G4VERBOSE
895  if (verboseLevel>2){
896  G4cout << "G4VUserPhysicsList::RetrievePhysicsTable "
897  << " Fail to retrieve Physics Table for "
898  << (*pVector)[j]->GetProcessName() << G4endl;
899  G4cout << "Calculate Physics Table for "
900  << particle->GetParticleName() << G4endl;
901  }
902 #endif
903  (*pVector)[j]->BuildPhysicsTable(*particle);
904  }
905  }
906  for ( j=0; j < pVector->size(); ++j) {
907  // temporary addition to make the integral schema
908  if (!success[j]) BuildIntegralPhysicsTable((*pVector)[j], particle);
909  }
910 }
911 
912 
913 ///////////////////////////////////////////////////////////////
915 {
916 #ifdef G4VERBOSE
917  if (verboseLevel>2){
918  G4cout << "G4VUserPhysicsList::SetApplyCuts for " << name << G4endl;
919  }
920 #endif
921  if(name=="all") {
926  } else {
928  }
929 }
930 
931 ///////////////////////////////////////////////////////////////
933 {
935 }
936 
937 
938 ////////////////////////////////////////////////////////
940 {
942  G4MT_thePLHelper->CheckParticleList();
943  }
944 }
945 
946 ////////////////////////////////////////////////////////
948 {
949  G4MT_thePLHelper->AddTransportation();
950 }
951 
952 ////////////////////////////////////////////////////////
954 {
955  G4MT_thePLHelper->UseCoupledTransportation(vl);
956 }
957 
958 ////////////////////////////////////////////////////////
960  G4ParticleDefinition* particle)
961 {
962  return G4MT_thePLHelper->RegisterProcess(process, particle);
963 }
964 
965 ////////////////////////////////////////////////////////
967 {
969  // set verboseLevel for G4ProductionCutsTable same as one for G4VUserPhysicsList:
971 
972  G4MT_thePLHelper->SetVerboseLevel(verboseLevel);
973 
974 #ifdef G4VERBOSE
975  if (verboseLevel >1){
976  G4cout << "G4VUserPhysicsList::SetVerboseLevel :"
977  << " Verbose level is set to " << verboseLevel << G4endl;
978  }
979 #endif
980 }
981 
982 
983 ///////////////////////////////////////////////////////////////
984 /// obsolete methods
985 
986 ///////////////////////////////////////////////////////////////
988 {
989 #ifdef G4VERBOSE
990  if (verboseLevel>0){
991  G4cout << "G4VUserPhysicsList::ResetCuts() is obsolete."
992  << " This method gives no effect and you can remove it. "<< G4endl;
993  }
994 #endif
995 }
#define G4MUTEXUNLOCK
Definition: G4Threading.hh:162
G4double GetCutValue(const G4String &pname) const
void SetDefaultCutValue(G4double newCutValue)
#define G4MT_theMessenger
void BuildIntegralPhysicsTable(G4VProcess *, G4ParticleDefinition *)
G4ProductionCuts * GetProductionCuts() const
void SetApplyCuts(G4bool value, const G4String &name)
#define G4MT_thePLHelper
G4Region * GetRegion(const G4String &name, G4bool verbose=true) const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4PhysicsListHelper * _thePLHelper
void SetProcessManager(G4ProcessManager *aProcessManager)
#define fDisplayThreshold
void SetCutValue(G4double aCut, const G4String &pname)
void SetEnergyRange(G4double lowedge, G4double highedge)
void PreparePhysicsTable(G4ParticleDefinition *)
G4bool RegisterProcess(G4VProcess *process, G4ParticleDefinition *particle)
G4ProductionCutsTable * fCutsTable
G4double GetProductionCut(G4int index) const
#define fIsPhysicsTableBuilt
G4bool fIsCheckedForRetrievePhysicsTable
const XML_Char * name
void SetProductionCut(G4double cut, G4int index=-1)
G4bool GetApplyCuts(const G4String &name) const
void SetCutsForRegion(G4double aCut, const G4String &rname)
G4ParticleTable * theParticleTable
const G4String & GetParticleSubType() const
G4ParticleDefinition * GetGenericIon() const
#define G4ThreadLocal
Definition: tls.hh:52
G4UserPhysicsListMessenger * _theMessenger
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
G4int GetInstanceID() const
const G4String & GetParticleName() const
G4bool IsGeneralIon() const
static G4RegionStore * GetInstance()
G4bool _fIsPhysicsTableBuilt
void SetPhysicsTableRetrieved(const G4String &directory="")
void SetParticleCuts(G4double cut, G4ParticleDefinition *particle, G4Region *region=0)
void DumpCutValuesTable(G4int flag=1)
void AddProcessManager(G4ParticleDefinition *newParticle, G4ProcessManager *newManager=0)
G4GLOB_DLL std::ostream G4cout
G4ProcessManager * GetMasterProcessManager() const
static G4PART_DLL G4ThreadLocal G4int slavetotalspace
void SetVerboseLevel(G4int value)
G4bool RetrieveCutsTable(const G4String &directory, G4bool ascii=false)
bool G4bool
Definition: G4Types.hh:79
G4int GetInstanceID() const
void SetVerboseLevel(G4int value)
G4ParticleTable::G4PTblDicIterator * _theParticleIterator
#define G4MUTEXLOCK
Definition: G4Threading.hh:161
G4VUserPhysicsList & operator=(const G4VUserPhysicsList &)
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
string pname
Definition: eplot.py:33
G4bool StorePhysicsTable(const G4String &directory=".")
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int size() const
static G4ProductionCutsTable * GetProductionCutsTable()
void UseCoupledTransportation(G4bool vl=true)
static G4ParticleTable * GetParticleTable()
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
Definition: G4VProcess.hh:210
static G4RUN_DLL G4ThreadLocal T * offset
static G4PhysicsListHelper * GetPhysicsListHelper()
G4bool StoreCutsTable(const G4String &directory, G4bool ascii=false)
static G4RUN_DLL G4VUPLManager subInstanceManager
static const G4VUPLManager & GetSubInstanceManager()
const XML_Char int const XML_Char * value
void ResetCuts()
obsolete methods
#define G4endl
Definition: G4ios.hh:61
G4bool GetApplyCutsFlag() const
G4int CreateSubInstance()
double G4double
Definition: G4Types.hh:76
virtual void RetrievePhysicsTable(G4ParticleDefinition *, const G4String &directory, G4bool ascii=false)
G4PTblDicIterator * GetIterator() const
G4bool isNull() const
#define theParticleIterator
void SetMasterProcessManager(G4ProcessManager *aNewPM)
G4ProcessVector * GetProcessList() const