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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 9.4.p4)


  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 //                                                 26 //
                                                   >>  27 // $Id: G4EnergyRangeManager.cc,v 1.16 2010-11-22 07:45:45 dennis Exp $
                                                   >>  28 // GEANT4 tag $Name: not supported by cvs2svn $
                                                   >>  29 //
 27  // Hadronic Process: Energy Range Manager         30  // Hadronic Process: Energy Range Manager
 28  // original by H.P. Wellisch                      31  // original by H.P. Wellisch
 29  // modified by J.L. Chuma, TRIUMF, 22-Nov-199     32  // modified by J.L. Chuma, TRIUMF, 22-Nov-1996
 30  // Last modified: 24-Mar-1997                     33  // Last modified: 24-Mar-1997
 31  // fix in the counter-hndling: H.P. Wellisch      34  // fix in the counter-hndling: H.P. Wellisch 04-Apr-97
 32  // throw an exception if no model found:  J.L     35  // throw an exception if no model found:  J.L. Chuma  04-Apr-97
 33                                                    36  
 34 #include "G4EnergyRangeManager.hh"                 37 #include "G4EnergyRangeManager.hh"
 35 #include "Randomize.hh"                            38 #include "Randomize.hh"
 36 #include "G4HadronicException.hh"                  39 #include "G4HadronicException.hh"
 37 #include "G4SystemOfUnits.hh"                  <<  40 
 38                                                    41 
 39 G4EnergyRangeManager::G4EnergyRangeManager()       42 G4EnergyRangeManager::G4EnergyRangeManager()
 40  : theHadronicInteractionCounter(0)                43  : theHadronicInteractionCounter(0)
 41 {}                                             <<  44 {
                                                   >>  45   for (G4int i = 0; i < G4EnergyRangeManager::MAX_NUMBER_OF_MODELS; i++)
                                                   >>  46     theHadronicInteraction[i] = 0;
                                                   >>  47 }
 42                                                    48 
 43 G4EnergyRangeManager::~G4EnergyRangeManager()  << 
 44 {}                                             << 
 45                                                    49 
 46 void G4EnergyRangeManager::RegisterMe(G4Hadron <<  50 G4EnergyRangeManager::G4EnergyRangeManager(const G4EnergyRangeManager& right)
 47 {                                                  51 {
 48   if(!a) { return; }                           <<  52   if (this != &right) {
 49   if(0 < theHadronicInteractionCounter) {      <<  53     for (G4int i=0; i<theHadronicInteractionCounter; ++i)
 50     for(G4int i=0; i<theHadronicInteractionCou <<  54       theHadronicInteraction[i] = right.theHadronicInteraction[i];
 51       if(a == theHadronicInteraction[i]) { ret <<  55     theHadronicInteractionCounter = right.theHadronicInteractionCounter;
 52     }                                          << 
 53   }                                                56   }
 54   theHadronicInteraction.push_back(a);         << 
 55   ++theHadronicInteractionCounter;             << 
 56 }                                                  57 }
                                                   >>  58  
 57                                                    59 
 58 G4HadronicInteraction*                         <<  60 G4EnergyRangeManager&G4EnergyRangeManager::operator=(
 59 G4EnergyRangeManager::GetHadronicInteraction(c <<  61    const G4EnergyRangeManager &right )
 60                                              G << 
 61                                              c << 
 62                                              c << 
 63 {                                                  62 {
 64   // VI shortcut: if only one interaction is r <<  63   if (this != &right) {
 65   if(1 == theHadronicInteractionCounter) { ret <<  64     for (G4int i=0; i<theHadronicInteractionCounter; ++i)
 66   else if(0 == theHadronicInteractionCounter)  <<  65       theHadronicInteraction[i] = right.theHadronicInteraction[i];
 67     G4cout << "G4EnergyRangeManager::GetHadron <<  66     theHadronicInteractionCounter = right.theHadronicInteractionCounter;
 68      << "no models defined for a process" << G << 
 69     return nullptr;                            << 
 70   }                                                67   }
                                                   >>  68   return *this;
                                                   >>  69 }
 71                                                    70 
 72   G4double kineticEnergy = aHadProjectile.GetK << 
 73   // For ions, get kinetic energy per nucleon  << 
 74   if ( std::abs( aHadProjectile.GetDefinition( << 
 75     kineticEnergy /= static_cast< G4double >(  << 
 76   }                                            << 
 77                                                    71 
 78   G4int cou = 0, memory = 0, memor2 = 0;       <<  72 void G4EnergyRangeManager::RegisterMe(G4HadronicInteraction* a)
 79   G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, <<  73 {
                                                   >>  74     if( theHadronicInteractionCounter+1 > MAX_NUMBER_OF_MODELS )
                                                   >>  75     {
                                                   >>  76       throw G4HadronicException(__FILE__, __LINE__,"RegisterMe: TOO MANY MODELS");
                                                   >>  77     }
                                                   >>  78     theHadronicInteraction[ theHadronicInteractionCounter++ ] = a;
                                                   >>  79 }
 80                                                    80 
 81   for (G4int i = 0; i<theHadronicInteractionCo <<  81  
 82     if ( theHadronicInteraction[i]->IsApplicab <<  82 G4HadronicInteraction*
                                                   >>  83   G4EnergyRangeManager::GetHadronicInteraction(
                                                   >>  84    const G4double kineticEnergy,
                                                   >>  85    const G4Material *aMaterial,
                                                   >>  86    const G4Element *anElement ) const
                                                   >>  87   {
                                                   >>  88     G4int counter = GetHadronicInteractionCounter();
                                                   >>  89     if( counter == 0 )
                                                   >>  90       throw G4HadronicException(__FILE__, __LINE__,
                                                   >>  91                                "GetHadronicInteraction: NO MODELS STORED");
                                                   >>  92 
                                                   >>  93     G4int cou = 0, memory = 0, memor2 = 0;
                                                   >>  94     G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, ema2 = 0.0;
                                                   >>  95     for( G4int i=0; i<counter; i++ )
                                                   >>  96     {
 83       G4double low  = theHadronicInteraction[i     97       G4double low  = theHadronicInteraction[i]->GetMinEnergy( aMaterial, anElement );
                                                   >>  98       // Work-around for particles with 0 kinetic energy, which still
                                                   >>  99       // require a model to return a ParticleChange
                                                   >> 100       if (low == 0.) low = -DBL_MIN;
 84       G4double high = theHadronicInteraction[i    101       G4double high = theHadronicInteraction[i]->GetMaxEnergy( aMaterial, anElement );
 85       if (low <= kineticEnergy && high >= kine << 102       if( low < kineticEnergy && high >= kineticEnergy )
                                                   >> 103       {
 86         ++cou;                                    104         ++cou;
 87         emi2 = emi1;                              105         emi2 = emi1;
 88         ema2 = ema1;                              106         ema2 = ema1;
 89         emi1 = low;                               107         emi1 = low;
 90         ema1 = high;                              108         ema1 = high;
 91         memor2 = memory;                          109         memor2 = memory;
 92         memory = i;                               110         memory = i;
 93       }                                           111       }
 94     }                                             112     }
 95   }                                            << 113     G4int m=-1;
 96                                                << 114     G4double rand;
 97   G4HadronicInteraction* hi = nullptr;         << 115     switch ( cou )
 98   switch (cou) {                               << 116     {
 99     case 0:                                    << 117      case 0:
100       G4cout << "No model found out of " << th << 118        G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="<<counter<<", Ek="
101       for( G4int j=0; j<theHadronicInteraction << 119              <<kineticEnergy<<", Material = "<<aMaterial->GetName()<<", Element = "
102   G4HadronicInteraction* hint=theHadronicInter << 120              <<anElement->GetName()<<G4endl;
103   G4cout << "   "<< j << ".  Elow= " << hint-> << 121        for( G4int j=0; j<counter; j++ )
104          <<", Ehigh= " << hint->GetMaxEnergy(a << 122        {
105          <<"   " << hint->GetModelName() << G4 << 123          G4HadronicInteraction* HInt=theHadronicInteraction[j];
106       }                                        << 124          G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement)
107       break;                                   << 125                <<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl;
108                                                << 126        }
109     case 1:                                    << 127        throw G4HadronicException(__FILE__, __LINE__,
110       hi = theHadronicInteraction[memory];     << 128           "GetHadronicInteraction: No Model found");
111       break;                                   << 129        return 0;
112                                                << 130      case 1:
113     case 2:                                    << 131        m = memory;
114       if( (emi2<=emi1 && ema2>=ema1) || (emi2> << 132        break;
115   G4cout << "Energy ranges of two models fully << 133      case 2:
116   for( G4int j=0; j<theHadronicInteractionCoun << 134        if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) )
117     G4HadronicInteraction* hint=theHadronicInt << 135        {
118     G4cout << "   "<< j << ".  Elow= " << hint << 136          G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="<<counter<<", Ek="
119      <<", Ehigh= " << hint->GetMaxEnergy(aMate << 137                <<kineticEnergy<<", Material = "<<aMaterial->GetName()<<", Element = "
120      <<"   " << hint->GetModelName() << G4endl << 138                <<anElement->GetName()<<G4endl;
121   }                                            << 139          if(counter) for( G4int j=0; j<counter; j++ )
122       } else {                                 << 140          {
123   G4double rand = G4UniformRand();             << 141            G4HadronicInteraction* HInt=theHadronicInteraction[j];
124   G4int mem;                                   << 142            G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement)
125   if( emi1 < emi2 ) {                          << 143                <<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl;
126     if( (ema1-kineticEnergy) < rand*(ema1-emi2 << 144          }
127       mem = memor2;                            << 145          throw G4HadronicException(__FILE__, __LINE__,
128     } else {                                   << 146                "GetHadronicInteraction: Energy ranges of two models fully overlapping");
129       mem = memory;                            << 147        }
130     }                                          << 148        rand = G4UniformRand();
131   } else {                                     << 149        if( emi1 < emi2 )
132     if( (ema2-kineticEnergy) < rand*(ema2-emi1 << 150        {
133       mem = memory;                            << 151          if( (ema1-kineticEnergy)/(ema1-emi2)<rand )
134     } else {                                   << 152            m = memor2;
135       mem = memor2;                            << 153          else
136     }                                          << 154            m = memory;
137   }                                            << 155        } else {
138   hi = theHadronicInteraction[mem];            << 156          if( (ema2-kineticEnergy)/(ema2-emi1)<rand )
139       }                                        << 157            m = memory;
140       break;                                   << 158          else
141                                                << 159            m = memor2;
142     default:                                   << 160        }
143       G4cout << "More than two competing model << 161        break;
144       for( G4int j=0; j<theHadronicInteraction << 162      default:
145   G4HadronicInteraction* hint=theHadronicInter << 163       throw G4HadronicException(__FILE__, __LINE__,
146   G4cout << "   "<< j << ".  Elow= " << hint-> << 164         "GetHadronicInteraction: More than two competing models in this energy range");
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     }                                             165     }
174   }                                            << 166     return theHadronicInteraction[m];
175 }                                              << 167   } 
176                                                << 168  
177 void                                           << 169  /* end of file */
178 G4EnergyRangeManager::BuildPhysicsTable(const  << 
179 {                                              << 
180   for (auto & hadi : theHadronicInteraction) { << 
181     hadi->BuildPhysicsTable( aParticleType );  << 
182   }                                            << 
183 }                                              << 
184                                                << 
185                                                   170  
186                                                   171