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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 /processes/hadronic/management/src/G4EnergyRangeManager.cc (Version 11.3.0) and /processes/hadronic/management/src/G4EnergyRangeManager.cc (Version 3.1)


                                                   >>   1 // This code implementation is the intellectual property of
                                                   >>   2 // the GEANT4 collaboration.
  1 //                                                  3 //
  2 // ******************************************* <<   4 // By copying, distributing or modifying the Program (or any work
  3 // * License and Disclaimer                    <<   5 // based on the Program) you indicate your acceptance of this statement,
  4 // *                                           <<   6 // and all its terms.
  5 // * The  Geant4 software  is  copyright of th << 
  6 // * the Geant4 Collaboration.  It is provided << 
  7 // * conditions of the Geant4 Software License << 
  8 // * LICENSE and available at  http://cern.ch/ << 
  9 // * include a list of copyright holders.      << 
 10 // *                                           << 
 11 // * Neither the authors of this software syst << 
 12 // * institutes,nor the agencies providing fin << 
 13 // * work  make  any representation or  warran << 
 14 // * regarding  this  software system or assum << 
 15 // * use.  Please see the license in the file  << 
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                           << 
 18 // * This  code  implementation is the result  << 
 19 // * technical work of the GEANT4 collaboratio << 
 20 // * By using,  copying,  modifying or  distri << 
 21 // * any work based  on the software)  you  ag << 
 22 // * use  in  resulting  scientific  publicati << 
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // ******************************************* << 
 25 //                                                  7 //
                                                   >>   8 // $Id: G4EnergyRangeManager.cc,v 1.3 1999/12/15 14:52:07 gunter Exp $
                                                   >>   9 // GEANT4 tag $Name: geant4-03-01 $
 26 //                                                 10 //
 27  // Hadronic Process: Energy Range Manager         11  // Hadronic Process: Energy Range Manager
 28  // original by H.P. Wellisch                      12  // original by H.P. Wellisch
 29  // modified by J.L. Chuma, TRIUMF, 22-Nov-199     13  // modified by J.L. Chuma, TRIUMF, 22-Nov-1996
 30  // Last modified: 24-Mar-1997                     14  // Last modified: 24-Mar-1997
 31  // fix in the counter-hndling: H.P. Wellisch      15  // fix in the counter-hndling: H.P. Wellisch 04-Apr-97
 32  // throw an exception if no model found:  J.L     16  // throw an exception if no model found:  J.L. Chuma  04-Apr-97
 33                                                    17  
 34 #include "G4EnergyRangeManager.hh"                 18 #include "G4EnergyRangeManager.hh"
 35 #include "Randomize.hh"                            19 #include "Randomize.hh"
 36 #include "G4HadronicException.hh"              <<  20  
 37 #include "G4SystemOfUnits.hh"                  <<  21  G4EnergyRangeManager::G4EnergyRangeManager(
 38                                                <<  22   const G4EnergyRangeManager &right )
 39 G4EnergyRangeManager::G4EnergyRangeManager()   <<  23   {
 40  : theHadronicInteractionCounter(0)            <<  24     if( this != &right )
 41 {}                                             <<  25     {
 42                                                <<  26       for( G4int i=0; i<theHadronicInteractionCounter; ++i )
 43 G4EnergyRangeManager::~G4EnergyRangeManager()  <<  27         theHadronicInteraction[i] = right.theHadronicInteraction[i];
 44 {}                                             <<  28       theHadronicInteractionCounter = right.theHadronicInteractionCounter;
 45                                                << 
 46 void G4EnergyRangeManager::RegisterMe(G4Hadron << 
 47 {                                              << 
 48   if(!a) { return; }                           << 
 49   if(0 < theHadronicInteractionCounter) {      << 
 50     for(G4int i=0; i<theHadronicInteractionCou << 
 51       if(a == theHadronicInteraction[i]) { ret << 
 52     }                                              29     }
 53   }                                                30   }
 54   theHadronicInteraction.push_back(a);         <<  31  
 55   ++theHadronicInteractionCounter;             <<  32  G4EnergyRangeManager &
 56 }                                              <<  33   G4EnergyRangeManager::operator=(
 57                                                <<  34    const G4EnergyRangeManager &right )
 58 G4HadronicInteraction*                         <<  35   {
 59 G4EnergyRangeManager::GetHadronicInteraction(c <<  36     if( this != &right )
 60                                              G <<  37     {
 61                                              c <<  38       for( G4int i=0; i<theHadronicInteractionCounter; ++i )
 62                                              c <<  39         theHadronicInteraction[i] =
 63 {                                              <<  40           right.theHadronicInteraction[i];
 64   // VI shortcut: if only one interaction is r <<  41       theHadronicInteractionCounter =
 65   if(1 == theHadronicInteractionCounter) { ret <<  42         right.theHadronicInteractionCounter;
 66   else if(0 == theHadronicInteractionCounter)  <<  43     }
 67     G4cout << "G4EnergyRangeManager::GetHadron <<  44     return *this;
 68      << "no models defined for a process" << G << 
 69     return nullptr;                            << 
 70   }                                                45   }
 71                                                <<  46  
 72   G4double kineticEnergy = aHadProjectile.GetK <<  47  void
 73   // For ions, get kinetic energy per nucleon  <<  48   G4EnergyRangeManager::RegisterMe(
 74   if ( std::abs( aHadProjectile.GetDefinition( <<  49    G4HadronicInteraction *a )
 75     kineticEnergy /= static_cast< G4double >(  <<  50   {
                                                   >>  51     if( theHadronicInteractionCounter+1 > MAX_NUMBER_OF_MODELS )
                                                   >>  52       G4Exception(
                                                   >>  53        "EnergyRangeManager::RegisterMe: TOO MANY MODELS");
                                                   >>  54     theHadronicInteraction[ theHadronicInteractionCounter++ ] = a;
 76   }                                                55   }
 77                                                <<  56  
 78   G4int cou = 0, memory = 0, memor2 = 0;       <<  57  G4HadronicInteraction *
 79   G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, <<  58   G4EnergyRangeManager::GetHadronicInteraction(
 80                                                <<  59    const G4double kineticEnergy,
 81   for (G4int i = 0; i<theHadronicInteractionCo <<  60    const G4Material *aMaterial,
 82     if ( theHadronicInteraction[i]->IsApplicab <<  61    const G4Element *anElement ) const
                                                   >>  62   {
                                                   >>  63     G4int counter = GetHadronicInteractionCounter();
                                                   >>  64     if( counter == 0 )
                                                   >>  65       G4Exception("GetHadronicInteraction: NO MODELS STORED");
                                                   >>  66 
                                                   >>  67     G4int cou = 0, memory = 0, memor2 = 0;
                                                   >>  68     G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, ema2 = 0.0;
                                                   >>  69     for( G4int i=0; i<counter; i++ ) {
 83       G4double low  = theHadronicInteraction[i     70       G4double low  = theHadronicInteraction[i]->GetMinEnergy( aMaterial, anElement );
                                                   >>  71       // Work-around for particles with 0 kinetic energy, which still
                                                   >>  72       // require a model to return a ParticleChange
                                                   >>  73       if (low == 0.) low = -DBL_MIN;
 84       G4double high = theHadronicInteraction[i     74       G4double high = theHadronicInteraction[i]->GetMaxEnergy( aMaterial, anElement );
 85       if (low <= kineticEnergy && high >= kine <<  75       if( low < kineticEnergy && high >= kineticEnergy )
                                                   >>  76       {
 86         ++cou;                                     77         ++cou;
 87         emi2 = emi1;                               78         emi2 = emi1;
 88         ema2 = ema1;                               79         ema2 = ema1;
 89         emi1 = low;                                80         emi1 = low;
 90         ema1 = high;                               81         ema1 = high;
 91         memor2 = memory;                           82         memor2 = memory;
 92         memory = i;                                83         memory = i;
 93       }                                            84       }
 94     }                                              85     }
 95   }                                            <<  86     G4int m;
 96                                                <<  87     G4double rand;
 97   G4HadronicInteraction* hi = nullptr;         <<  88     switch ( cou )
 98   switch (cou) {                               <<  89     {
 99     case 0:                                    <<  90      case 0:
100       G4cout << "No model found out of " << th <<  91        G4Exception("GetHadronicInteraction: No model found for this energy range");
101       for( G4int j=0; j<theHadronicInteraction <<  92        return 0;
102   G4HadronicInteraction* hint=theHadronicInter <<  93      case 1:
103   G4cout << "   "<< j << ".  Elow= " << hint-> <<  94        m = memory;
104          <<", Ehigh= " << hint->GetMaxEnergy(a <<  95        break;
105          <<"   " << hint->GetModelName() << G4 <<  96      case 2:
106       }                                        <<  97        if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) )
107       break;                                   <<  98          G4Exception(
108                                                <<  99           "GetHadronicInteraction: Energy ranges of two models fully overlapping");
109     case 1:                                    << 100        rand = G4UniformRand();
110       hi = theHadronicInteraction[memory];     << 101        if( emi1 < emi2 )
111       break;                                   << 102        {
112                                                << 103          if( (ema1-kineticEnergy)/(ema1-emi2)<rand )
113     case 2:                                    << 104            m = memor2;
114       if( (emi2<=emi1 && ema2>=ema1) || (emi2> << 105          else
115   G4cout << "Energy ranges of two models fully << 106            m = memory;
116   for( G4int j=0; j<theHadronicInteractionCoun << 107        } else {
117     G4HadronicInteraction* hint=theHadronicInt << 108          if( (ema2-kineticEnergy)/(ema2-emi1)<rand )
118     G4cout << "   "<< j << ".  Elow= " << hint << 109            m = memory;
119      <<", Ehigh= " << hint->GetMaxEnergy(aMate << 110          else
120      <<"   " << hint->GetModelName() << G4endl << 111            m = memor2;
121   }                                            << 112        }
122       } else {                                 << 113        break;
123   G4double rand = G4UniformRand();             << 114      default:
124   G4int mem;                                   << 115        G4Exception(
125   if( emi1 < emi2 ) {                          << 116         "GetHadronicInteraction: More than two competing models in this energy range");
126     if( (ema1-kineticEnergy) < rand*(ema1-emi2 << 
127       mem = memor2;                            << 
128     } else {                                   << 
129       mem = memory;                            << 
130     }                                          << 
131   } else {                                     << 
132     if( (ema2-kineticEnergy) < rand*(ema2-emi1 << 
133       mem = memory;                            << 
134     } else {                                   << 
135       mem = memor2;                            << 
136     }                                          << 
137   }                                            << 
138   hi = theHadronicInteraction[mem];            << 
139       }                                        << 
140       break;                                   << 
141                                                << 
142     default:                                   << 
143       G4cout << "More than two competing model << 
144       for( G4int j=0; j<theHadronicInteraction << 
145   G4HadronicInteraction* hint=theHadronicInter << 
146   G4cout << "   "<< j << ".  Elow= " << hint-> << 
147          <<", Ehigh= " << hint->GetMaxEnergy(a << 
148          <<"   " << hint->GetModelName() << G4 << 
149       }                                        << 
150       break;                                   << 
151   }                                            << 
152   return hi;                                   << 
153 }                                              << 
154                                                << 
155 std::vector<G4HadronicInteraction*>&           << 
156 G4EnergyRangeManager::GetHadronicInteractionLi << 
157 {                                              << 
158   return theHadronicInteraction;               << 
159 }                                              << 
160                                                << 
161 void G4EnergyRangeManager::Dump( G4int verbose << 
162 {                                              << 
163   G4cout << "G4EnergyRangeManager " << this << << 
164   for (G4int i = 0 ; i < theHadronicInteractio << 
165     G4cout << "   HadronicModel " << i <<":"   << 
166            << theHadronicInteraction[i]->GetMo << 
167     if (verbose > 0) {                         << 
168       G4cout << "      Minimum Energy "        << 
169        << theHadronicInteraction[i]->GetMinEne << 
170              << "Maximum Energy "              << 
171        << theHadronicInteraction[i]->GetMaxEne << 
172              << G4endl;                        << 
173     }                                             117     }
174   }                                            << 118     return theHadronicInteraction[m];
175 }                                              << 119   } 
176                                                << 120  
177 void                                           << 121  /* end of file */
178 G4EnergyRangeManager::BuildPhysicsTable(const  << 
179 {                                              << 
180   for (auto & hadi : theHadronicInteraction) { << 
181     hadi->BuildPhysicsTable( aParticleType );  << 
182   }                                            << 
183 }                                              << 
184                                                << 
185                                                   122  
186                                                   123