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p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/biasing/GB01/src/GB01BOptrChangeCrossSection.cc (Version 11.3.0) and /examples/extended/biasing/GB01/src/GB01BOptrChangeCrossSection.cc (Version 10.1.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /// \file GB01/src/GB01BOptrChangeCrossSection << 
 27 /// \brief Implementation of the GB01BOptrChan << 
 28 //                                             << 
 29 #include "GB01BOptrChangeCrossSection.hh"          26 #include "GB01BOptrChangeCrossSection.hh"
 30                                                << 
 31 #include "G4BOptnChangeCrossSection.hh"        << 
 32 #include "G4BiasingProcessInterface.hh"            27 #include "G4BiasingProcessInterface.hh"
 33 #include "G4InteractionLawPhysical.hh"         <<  28 #include "G4BOptnChangeCrossSection.hh"
                                                   >>  29 
 34 #include "G4ParticleDefinition.hh"                 30 #include "G4ParticleDefinition.hh"
 35 #include "G4ParticleTable.hh"                      31 #include "G4ParticleTable.hh"
 36 #include "G4VProcess.hh"                           32 #include "G4VProcess.hh"
                                                   >>  33 
 37 #include "Randomize.hh"                            34 #include "Randomize.hh"
 38                                                    35 
 39 //....oooOO0OOooo........oooOO0OOooo........oo <<  36 #include "G4InteractionLawPhysical.hh"
 40                                                    37 
 41 GB01BOptrChangeCrossSection::GB01BOptrChangeCr <<  38 GB01BOptrChangeCrossSection::GB01BOptrChangeCrossSection(G4String particleName,
 42   : G4VBiasingOperator(name), fSetup(true)     <<  39                                                          G4String         name)
                                                   >>  40   : G4VBiasingOperator(name),
                                                   >>  41     fSetup(true)
 43 {                                                  42 {
 44   fParticleToBias = G4ParticleTable::GetPartic     43   fParticleToBias = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
 45                                                <<  44   
 46   if (fParticleToBias == 0) {                  <<  45   if ( fParticleToBias == 0 )
 47     G4ExceptionDescription ed;                 <<  46     {
 48     ed << "Particle `" << particleName << "' n <<  47       G4ExceptionDescription ed;
 49     G4Exception("GB01BOptrChangeCrossSection(. <<  48       ed << "Particle `" << particleName << "' not found !" << G4endl;
 50   }                                            <<  49       G4Exception("GB01BOptrChangeCrossSection(...)",
                                                   >>  50                   "exGB01.01",
                                                   >>  51                   JustWarning,
                                                   >>  52                   ed);
                                                   >>  53     }
 51 }                                                  54 }
 52                                                    55 
 53 //....oooOO0OOooo........oooOO0OOooo........oo << 
 54                                                << 
 55 GB01BOptrChangeCrossSection::~GB01BOptrChangeC     56 GB01BOptrChangeCrossSection::~GB01BOptrChangeCrossSection()
 56 {                                                  57 {
 57   for (std::map<const G4BiasingProcessInterfac <<  58   for ( std::map< const G4BiasingProcessInterface*, G4BOptnChangeCrossSection* >::iterator 
 58          fChangeCrossSectionOperations.begin() <<  59           it = fChangeCrossSectionOperations.begin() ;
 59        it != fChangeCrossSectionOperations.end <<  60         it != fChangeCrossSectionOperations.end() ;
 60     delete (*it).second;                       <<  61         it++ ) delete (*it).second;
 61 }                                                  62 }
 62                                                    63 
 63 //....oooOO0OOooo........oooOO0OOooo........oo << 
 64                                                    64 
 65 void GB01BOptrChangeCrossSection::StartRun()       65 void GB01BOptrChangeCrossSection::StartRun()
 66 {                                                  66 {
 67   // --------------                                67   // --------------
 68   // -- Setup stage:                               68   // -- Setup stage:
 69   // ---------------                               69   // ---------------
 70   // -- Start by collecting processes under bi     70   // -- Start by collecting processes under biasing, create needed biasing
 71   // -- operations and associate these operati     71   // -- operations and associate these operations to the processes:
 72   if (fSetup) {                                <<  72   if ( fSetup )
 73     const G4ProcessManager* processManager = f << 
 74     const G4BiasingProcessSharedData* sharedDa << 
 75       G4BiasingProcessInterface::GetSharedData << 
 76     if (sharedData)  // -- sharedData tested,  << 
 77                      // -- volume but without  << 
 78     {                                              73     {
 79       for (size_t i = 0; i < (sharedData->GetP <<  74       const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
 80         const G4BiasingProcessInterface* wrapp <<  75       const G4BiasingProcessSharedData* sharedData =
 81           (sharedData->GetPhysicsBiasingProces <<  76         G4BiasingProcessInterface::GetSharedData( processManager );
 82         G4String operationName =               <<  77       if ( sharedData ) // -- sharedData tested, as is can happen a user attaches an operator to a
 83           "XSchange-" + wrapperProcess->GetWra <<  78                         // -- volume but without defined BiasingProcessInterface processes.
 84         fChangeCrossSectionOperations[wrapperP <<  79         {
 85           new G4BOptnChangeCrossSection(operat <<  80           for ( size_t i = 0 ; i < (sharedData->GetPhysicsBiasingProcessInterfaces()).size(); i++ )
 86       }                                        <<  81             {
                                                   >>  82               const G4BiasingProcessInterface* wrapperProcess =
                                                   >>  83                 (sharedData->GetPhysicsBiasingProcessInterfaces())[i];
                                                   >>  84               G4String operationName = "XSchange-" + 
                                                   >>  85                 wrapperProcess->GetWrappedProcess()->GetProcessName();
                                                   >>  86               fChangeCrossSectionOperations[wrapperProcess] = 
                                                   >>  87                 new G4BOptnChangeCrossSection(operationName);
                                                   >>  88             }
                                                   >>  89         }
                                                   >>  90       fSetup = false;
 87     }                                              91     }
 88     fSetup = false;                            << 
 89   }                                            << 
 90 }                                                  92 }
 91                                                    93 
 92 //....oooOO0OOooo........oooOO0OOooo........oo << 
 93                                                    94 
 94 G4VBiasingOperation* GB01BOptrChangeCrossSecti <<  95 G4VBiasingOperation* 
 95   const G4Track* track, const G4BiasingProcess <<  96 GB01BOptrChangeCrossSection::ProposeOccurenceBiasingOperation(const G4Track*            track, 
                                                   >>  97                                                               const G4BiasingProcessInterface*
                                                   >>  98                                                                                callingProcess)
 96 {                                                  99 {
                                                   >> 100 
 97   // -----------------------------------------    101   // -----------------------------------------------------
 98   // -- Check if current particle type is the     102   // -- Check if current particle type is the one to bias:
 99   // -----------------------------------------    103   // -----------------------------------------------------
100   if (track->GetDefinition() != fParticleToBia << 104   if ( track->GetDefinition() != fParticleToBias ) return 0;
101                                                << 105   
                                                   >> 106   
102   // -----------------------------------------    107   // ---------------------------------------------------------------------
103   // -- select and setup the biasing operation    108   // -- select and setup the biasing operation for current callingProcess:
104   // -----------------------------------------    109   // ---------------------------------------------------------------------
105   // -- Check if the analog cross-section well    110   // -- Check if the analog cross-section well defined : for example, the conversion
106   // -- process for a gamma below e+e- creatio    111   // -- process for a gamma below e+e- creation threshold has an DBL_MAX interaction
107   // -- length. Nothing is done in this case (    112   // -- length. Nothing is done in this case (ie, let analog process to deal with the case)
108   G4double analogInteractionLength =           << 113   G4double analogInteractionLength =  
109     callingProcess->GetWrappedProcess()->GetCu    114     callingProcess->GetWrappedProcess()->GetCurrentInteractionLength();
110   if (analogInteractionLength > DBL_MAX / 10.) << 115   if ( analogInteractionLength > DBL_MAX/10. ) return 0;
111                                                   116 
112   // -- Analog cross-section is well-defined:     117   // -- Analog cross-section is well-defined:
113   G4double analogXS = 1. / analogInteractionLe << 118   G4double analogXS = 1./analogInteractionLength;
114                                                   119 
115   // -- Choose a constant cross-section bias.     120   // -- Choose a constant cross-section bias. But at this level, this factor can be made
116   // -- direction dependent, like in the expon    121   // -- direction dependent, like in the exponential transform MCNP case, or it
117   // -- can be chosen differently, depending o    122   // -- can be chosen differently, depending on the process, etc.
118   G4double XStransformation = 2.0;             << 123   G4double XStransformation = 2.0 ;
119                                                << 124   
120   // -- fetch the operation associated to this    125   // -- fetch the operation associated to this callingProcess:
121   G4BOptnChangeCrossSection* operation = fChan << 126   G4BOptnChangeCrossSection*   operation = fChangeCrossSectionOperations[callingProcess];
122   // -- get the operation that was proposed to    127   // -- get the operation that was proposed to the process in the previous step:
123   G4VBiasingOperation* previousOperation = cal    128   G4VBiasingOperation* previousOperation = callingProcess->GetPreviousOccurenceBiasingOperation();
124                                                << 129   
125   // -- now setup the operation to be returned    130   // -- now setup the operation to be returned to the process: this
126   // -- consists in setting the biased cross-s    131   // -- consists in setting the biased cross-section, and in asking
127   // -- the operation to sample its exponentia    132   // -- the operation to sample its exponential interaction law.
128   // -- To do this, to first order, the two li    133   // -- To do this, to first order, the two lines:
129   //        operation->SetBiasedCrossSection(     134   //        operation->SetBiasedCrossSection( XStransformation * analogXS );
130   //        operation->Sample();                  135   //        operation->Sample();
131   // -- are correct and sufficient.               136   // -- are correct and sufficient.
132   // -- But, to avoid having to shoot a random    137   // -- But, to avoid having to shoot a random number each time, we sample
133   // -- only on the first time the operation i    138   // -- only on the first time the operation is proposed, or if the interaction
134   // -- occured. If the interaction did not oc    139   // -- occured. If the interaction did not occur for the process in the previous,
135   // -- we update the number of interaction le    140   // -- we update the number of interaction length instead of resampling.
136   if (previousOperation == 0) {                << 141   if ( previousOperation == 0 )
137     operation->SetBiasedCrossSection(XStransfo << 142     {
138     operation->Sample();                       << 143       operation->SetBiasedCrossSection( XStransformation * analogXS );
139   }                                            << 
140   else {                                       << 
141     if (previousOperation != operation) {      << 
142       // -- should not happen !                << 
143       G4ExceptionDescription ed;               << 
144       ed << " Logic problem in operation handl << 
145       G4Exception("GB01BOptrChangeCrossSection << 
146                   JustWarning, ed);            << 
147       return 0;                                << 
148     }                                          << 
149     if (operation->GetInteractionOccured()) {  << 
150       operation->SetBiasedCrossSection(XStrans << 
151       operation->Sample();                        144       operation->Sample();
152     }                                             145     }
153     else {                                     << 146   else
154       // -- update the 'interaction length' an << 147     {
155       // -- for past step  (this takes into ac << 148       if (  previousOperation != operation )
156       operation->UpdateForStep(callingProcess- << 149         {
157       // -- update the cross-section value:    << 150           // -- should not happen !
158       operation->SetBiasedCrossSection(XStrans << 151           G4ExceptionDescription ed;
159       // -- forces recomputation of the 'inter << 152           ed << " Logic problem in operation handling !" << G4endl;
160       // -- new cross-section value [tricky :  << 153           G4Exception("GB01BOptrChangeCrossSection::ProposeOccurenceBiasingOperation(...)",
161       operation->UpdateForStep(0.0);           << 154                       "exGB01.02",
                                                   >> 155                       JustWarning,
                                                   >> 156                       ed);
                                                   >> 157           return 0;
                                                   >> 158         }
                                                   >> 159       if ( operation->GetInteractionOccured() )
                                                   >> 160         {
                                                   >> 161           operation->SetBiasedCrossSection( XStransformation * analogXS );
                                                   >> 162           operation->Sample();
                                                   >> 163         }
                                                   >> 164       else
                                                   >> 165         {
                                                   >> 166           // -- update the 'interaction length' and underneath 'number of interaction lengths'
                                                   >> 167           // -- for past step  (this takes into accout the previous step cross-section value)
                                                   >> 168           operation->UpdateForStep( callingProcess->GetPreviousStepSize() );
                                                   >> 169           // -- update the cross-section value:
                                                   >> 170           operation->SetBiasedCrossSection( XStransformation * analogXS );
                                                   >> 171           // -- forces recomputation of the 'interaction length' taking into account above
                                                   >> 172           // -- new cross-section value [tricky : to be improved]
                                                   >> 173           operation->UpdateForStep( 0.0 );
                                                   >> 174         }
162     }                                             175     }
163   }                                            << 176   
164                                                << 
165   return operation;                               177   return operation;
                                                   >> 178   
166 }                                                 179 }
167                                                   180 
168 //....oooOO0OOooo........oooOO0OOooo........oo << 
169                                                   181 
170 void GB01BOptrChangeCrossSection::OperationApp << 182 void GB01BOptrChangeCrossSection::
171                                                << 183 OperationApplied(const G4BiasingProcessInterface*           callingProcess, 
172                                                << 184                  G4BiasingAppliedCase,
173                                                << 185                  G4VBiasingOperation*             occurenceOperationApplied,
174                                                << 186                  G4double,
                                                   >> 187                  G4VBiasingOperation*,    
                                                   >> 188                  const G4VParticleChange*                                  )
175 {                                                 189 {
176   G4BOptnChangeCrossSection* operation = fChan    190   G4BOptnChangeCrossSection* operation = fChangeCrossSectionOperations[callingProcess];
177   if (operation == occurenceOperationApplied)  << 191   if ( operation ==  occurenceOperationApplied ) operation->SetInteractionOccured();
178 }                                                 192 }
179                                                   193 
180 //....oooOO0OOooo........oooOO0OOooo........oo << 
181                                                   194