G4ComponentSAIDTotalXS.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 // GEANT4 Class file
00031 //
00032 //
00033 // File name:    G4ComponentSAIDTotalXS
00034 //
00035 // Authors:  G.Folger, V.Ivanchenko, D.Wright
00036 //
00037 // Modifications:
00038 //
00039 
00040 #include "G4ComponentSAIDTotalXS.hh"
00041 #include "G4PhysicsVector.hh"
00042 #include "G4LPhysicsFreeVector.hh"
00043 #include "G4HadronicException.hh"
00044 
00045 G4String G4ComponentSAIDTotalXS::fnames[13] = {
00046   "","pp","np","pip","pim",
00047   "pin","pie",
00048   "gp_pi0p","gp_pi+n","gn_pi-p","gn_pi0n","gp_etap","gp_etapp"
00049 };
00050 G4PhysicsVector* G4ComponentSAIDTotalXS::elastdata[13] = {0};
00051 G4PhysicsVector* G4ComponentSAIDTotalXS::inelastdata[13] = {0};
00052 
00053 G4ComponentSAIDTotalXS::G4ComponentSAIDTotalXS() 
00054   : G4VComponentCrossSection("xsSAID"),numberOfSaidXS(13)
00055 {}
00056 
00057 G4ComponentSAIDTotalXS::~G4ComponentSAIDTotalXS()
00058 {
00059   for(G4int i=0; i<numberOfSaidXS; ++i) {
00060     if(elastdata[i]) {
00061       delete elastdata[i];
00062       elastdata[i] = 0;
00063     }
00064     if(inelastdata[i]) {
00065       delete inelastdata[i];
00066       inelastdata[i] = 0;
00067     }
00068   }
00069 }
00070 
00071 G4double 
00072 G4ComponentSAIDTotalXS::GetTotalElementCrossSection(
00073       const G4ParticleDefinition* part,
00074       G4double, G4int Z, G4double N)
00075 {
00076   PrintWarning(part,0,Z,G4lrint(N),
00077                "G4ComponentSAIDTotalXS::GetTotalElementCrossSection",
00078                "Method is not implemented");
00079   return 0.0; 
00080 }
00081 
00082 G4double 
00083 G4ComponentSAIDTotalXS::GetTotalIsotopeCrossSection(
00084       const G4ParticleDefinition* part,
00085       G4double kinEnergy, G4int Z, G4int N)
00086 {
00087   return GetInelasticIsotopeCrossSection(part,kinEnergy,Z,N)
00088     + GetElasticIsotopeCrossSection(part,kinEnergy,Z,N);
00089 }
00090 
00091 G4double 
00092 G4ComponentSAIDTotalXS::GetInelasticElementCrossSection(
00093       const G4ParticleDefinition* part,
00094       G4double, G4int Z, G4double N)
00095 {
00096   PrintWarning(part,0,Z,G4lrint(N),
00097                "G4ComponentSAIDTotalXS::GetTotalElementCrossSection",
00098                "Method is not implemented");
00099   return 0.0; 
00100 }
00101 
00102 G4double 
00103 G4ComponentSAIDTotalXS::GetInelasticIsotopeCrossSection(
00104       const G4ParticleDefinition* part,
00105       G4double kinEnergy, G4int Z, G4int N)
00106 {
00107   G4double cross = 0.0;
00108   G4SAIDCrossSectionType tp = GetType(part,0,Z,N);
00109   if(saidUnknown != tp) {
00110     G4int idx = G4int(tp);
00111     if(!inelastdata[idx]) { Initialise(tp); }
00112     if(inelastdata[idx]) { 
00113       cross = (inelastdata[idx])->Value(kinEnergy);
00114     }
00115   }
00116   return cross;
00117 }
00118 
00119 G4double 
00120 G4ComponentSAIDTotalXS::GetElasticElementCrossSection(
00121       const G4ParticleDefinition* part,
00122       G4double, G4int Z, G4double N)
00123 {
00124   PrintWarning(part,0,Z,G4lrint(N),
00125                "G4ComponentSAIDTotalXS::GetTotalElementCrossSection",
00126                "Method is not implemented");
00127   return 0.0; 
00128 }
00129 
00130 G4double 
00131 G4ComponentSAIDTotalXS::GetElasticIsotopeCrossSection(
00132       const G4ParticleDefinition* part,
00133       G4double kinEnergy, G4int Z, G4int N)
00134 {
00135   G4double cross = 0.0;
00136   G4SAIDCrossSectionType tp = GetType(part,0,Z,N);
00137   if(saidUnknown != tp) {
00138     G4int idx = G4int(tp);
00139     if(!elastdata[idx]) { Initialise(tp); }
00140     if(elastdata[idx]) { 
00141       cross = (elastdata[idx])->Value(kinEnergy); 
00142     }
00143   }
00144   return cross;
00145 }
00146 
00147 G4double 
00148 G4ComponentSAIDTotalXS::GetChargeExchangeCrossSection(
00149      const G4ParticleDefinition* prim,
00150      const G4ParticleDefinition* sec,
00151      G4double kinEnergy, G4int Z, G4int N)
00152 {
00153   G4double cross = 0.0;
00154   G4SAIDCrossSectionType tp = GetType(prim,sec,Z,N);
00155   if(saidUnknown != tp) {
00156     G4int idx = G4int(tp);
00157     if(!inelastdata[idx]) { Initialise(tp); }
00158     if(inelastdata[idx]) { 
00159       cross = (inelastdata[idx])->Value(kinEnergy); 
00160     }
00161   }
00162   return cross;
00163 }
00164 
00165 void 
00166 G4ComponentSAIDTotalXS::Description() const
00167 {
00168 }
00169 
00170 G4SAIDCrossSectionType 
00171 G4ComponentSAIDTotalXS::GetType(const G4ParticleDefinition* prim,
00172                                 const G4ParticleDefinition* sec,
00173                                 G4int Z, G4int N)
00174 {
00175   G4SAIDCrossSectionType type = saidUnknown;
00176   if(1 == N && prim) {
00177     G4int code = prim->GetPDGEncoding();
00178 
00179     // only gamma + N x-sections available
00180     if(0 == Z && sec && 22 == code) {
00181       G4int code1 = sec->GetPDGEncoding();
00182       if(-211 == code1)     { type = saidGN_PINP; }
00183       else if(111 == code1) { type = saidGN_PI0N; }
00184 
00185       // x-sections off proton
00186     } else if(1 == Z) {
00187       if(sec) {
00188         G4int code1 = sec->GetPDGEncoding();
00189         if(-211 == code) {
00190           if(111 == code1)      { type = saidPINP_PI0N; }
00191           else if(221 == code1) { type = saidPINP_ETAN; }
00192 
00193         } else if(22 == code) {
00194           if(111 == code1)      { type = saidGP_PI0P; }
00195           else if(211 == code1) { type = saidGP_PIPN; }
00196           else if(221 == code1) { type = saidGP_ETAP; }
00197           else if(331 == code1) { type = saidGP_ETAPP; }
00198         }
00199       } else {
00200         if(2212 == code)        { type = saidPP; } 
00201         else if(2112 == code)   { type = saidNP; } 
00202         else if(211 == code)    { type = saidPIPP; } 
00203         else if(-211 == code)   { type = saidPINP; } 
00204       }
00205     }
00206   }
00207   //G4cout << "G4ComponentSAIDTotalXS::Type= " << type << G4endl;
00208   return type;
00209 }
00210 
00211 void G4ComponentSAIDTotalXS::Initialise(G4SAIDCrossSectionType tp)
00212 {
00213   G4int idx = G4int(tp);
00214   // check environment variable 
00215   // Build the complete string identifying the file with the data set
00216   char* path = getenv("G4SAIDXSDATA");
00217   if (!path){
00218     throw G4HadronicException(__FILE__, __LINE__, 
00219                               "G4SAIDXSDATA environment variable not defined");
00220     return;
00221   }
00222   if(idx <= 4) {
00223     elastdata[idx] = new G4LPhysicsFreeVector();
00224     inelastdata[idx] = new G4LPhysicsFreeVector();
00225     ReadData(idx,elastdata[idx],path,"_el.dat");
00226     ReadData(idx,inelastdata[idx],path,"_in.dat");
00227   } else {
00228     inelastdata[idx] = new G4LPhysicsFreeVector();
00229     ReadData(idx,inelastdata[idx],path,".dat");
00230   }
00231 }
00232 
00233 void G4ComponentSAIDTotalXS::ReadData(G4int index, 
00234                                       G4PhysicsVector* v,
00235                                       const G4String& ss1, 
00236                                       const G4String& ss2)
00237 {
00238   std::ostringstream ost;
00239   ost << ss1 << "/" << fnames[index] << ss2;
00240   std::ifstream filein(ost.str().c_str());
00241   if (!(filein)) {
00242     G4cout << ost.str() << " is not opened by G4ComponentSAIDTotalXS" 
00243            << G4endl;
00244     G4String sss(ost.str());
00245     throw G4HadronicException(__FILE__, __LINE__,
00246                               "Data file " + sss + 
00247                               " is not opened," +
00248                               "chech that G4SAIDXSDATA correctly set");
00249 
00250   } else {
00251     if(GetVerboseLevel() > 1) {
00252       G4cout << "File " << ost.str() 
00253              << " is opened by G4ComponentSAIDTotalXS" << G4endl;
00254     }
00255     // retrieve data from DB
00256     v->Retrieve(filein, true);
00257     v->ScaleVector(CLHEP::MeV,CLHEP::millibarn);
00258     v->SetSpline(true);
00259   } 
00260 }
00261 
00262 void 
00263 G4ComponentSAIDTotalXS::PrintWarning(const G4ParticleDefinition* prim,
00264                                      const G4ParticleDefinition* sec,
00265                                      G4int Z, G4int N,
00266                                      const G4String& ss1,
00267                                      const G4String& ss2)
00268 {
00269   G4cout << ss1 << ": " << ss2 << G4endl;
00270   G4cout << "For Z= " << Z << " N= " << N << " of ";
00271   if(prim) { G4cout << prim->GetParticleName() << " "; }
00272   if(sec) { G4cout << " x-section to " << sec->GetParticleName(); }
00273   G4cout << G4endl;
00274 }

Generated on Mon May 27 17:47:56 2013 for Geant4 by  doxygen 1.4.7