00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <TArrayF.h>
00016 #include <TTree.h>
00017 #include <TMath.h>
00018 #include <iostream>
00019 #include <TVirtualMC.h>
00020 #include <TDatabasePDG.h>
00021 #include <TString.h>
00022 #include <TGeoManager.h>
00023 #include <TGeoMedium.h>
00024 #include <TGeant3.h>
00028
00031 struct Mech
00032 {
00033 char* name;
00034 char* title;
00035 char* unit;
00036 TArrayF values;
00037 int status;
00038 };
00039
00040
00041
00049 void
00050 GetXsection(const char* medName, const char* pdgName,
00051 Int_t n=91, Float_t emin=1e-5, Float_t emax=1e4)
00052 {
00053 TArrayF tkine(n);
00054 Float_t dp = 1/TMath::Log10(emax/emin);
00055 Float_t pmin = TMath::Log10(emin);
00056 tkine[0] = emin;
00057 for (Int_t i=1; i < tkine.fN; i++) {
00058 Float_t el = pmin + i * dp;
00059 tkine[i] = TMath::Power(10, el);
00060 }
00061 TArrayF cuts(5);
00062 cuts.Reset(1e-4);
00063
00064 Mech mechs[] =
00065 {{ "HADF","total hadronic x-section according to FLUKA","cm^{1}",n,0},
00066 { "INEF","hadronic inelastic x-section according to FLUKA","cm^{1}",n,0},
00067 { "ELAF","hadronic elastic x-section according to FLUKA","cm^{1}",n,0},
00068 { "HADG","total hadronic x-section according to GHEISHA","cm^{1}",n,0},
00069 { "INEG","hadronic inelastic x-section according to GHEISHA","cm^{1}",n,0},
00070 { "ELAG","hadronic elastic x-section according to GHEISHA","cm^{1}",n,0},
00071 { "FISG","nuclear fission x-section according to GHEISHA","cm^{1}",n,0},
00072 { "CAPG","neutron capture x-section according to GHEISHA","cm^{1}",n,0},
00073 { "LOSS","stopping power","cm^{1}",n,0},
00074 { "PHOT","photoelectric x-section","MeV/cm",n,0},
00075 { "ANNI","positron annihilation x-section","cm^{1}",n,0},
00076 { "COMP","Compton effect x-section","cm^{1}",n,0},
00077 { "BREM","bremsstrahlung x-section","cm^{1}",n,0},
00078 { "PAIR","photon and muon direct- pair x-section","cm^{1}",n,0},
00079 { "DRAY","delta-rays x-section","cm^{1}",n,0},
00080 { "PFIS","photo-fission x-section","cm^{1}",n,0},
00081 { "RAYL","Rayleigh scattering x-section","cm^{1}",n,0},
00082 { "MUNU","muon-nuclear interaction x-section","cm^{1}",n,0},
00083 { "RANG","range","cm",n,0},
00084 { "STEP","maximum step","cm",n,0},
00085 { 0, 0, 0, 0, 0}};
00086 TGeant3* mc = (TGeant3*)gMC;
00087 if (!mc) {
00088 std::cerr << "Couldn't get VMC" << std::endl;
00089 return;
00090 }
00091 TGeoMedium* medium = gGeoManager->GetMedium(medName);
00092 if (!medium) {
00093 std::cerr << "Couldn't find medium " << medName << std::endl;
00094 return;
00095 }
00096 Int_t medNo = medium->GetMaterial()->GetUniqueID();
00097 TDatabasePDG* pdgDb = TDatabasePDG::Instance();
00098 TParticlePDG* pdgP = pdgDb->GetParticle(pdgName);
00099 if (!pdgP) {
00100 std::cerr << "Couldn't find particle " << pdgName << std::endl;
00101 return;
00102 }
00103 Int_t pdgNo = pdgP->PdgCode();
00104 Int_t pidNo = mc->IdFromPDG(pdgNo);
00105
00106 Mech* mech = &(mechs[0]);
00107 Int_t nMech = 0;
00108 Int_t nOk = 0;
00109 TString vars("T/F");
00110 while (mech->name) {
00111 cout << mech->name << ": " << mech->title << " ... " << std::flush;
00112 nMech++;
00113 Int_t ixst;
00114 mc->Gftmat(medNo, pidNo, mech->name, n,
00115 tkine.fArray, mech->values.fArray, cuts.fArray, ixst);
00116 mech->status = ixst;
00117 if (ixst) {
00118 nOk++;
00119 vars.Append(Form(":%s", mech->name));
00120 if (!strcmp("LOSS", mech->name)) {
00121 for (Int_t i = 0; i < n; i++)
00122 std::cout << i << "\t" << tkine[i] << "\t"
00123 << mech->values[i] << std::endl;
00124 }
00125 }
00126 std::cout << (ixst ? "ok" : "failed") << std::endl;
00127 mech++;
00128 }
00129
00130
00131 TArrayF cache(nOk+1);
00132 TTree* tree = new TTree(Form("%s_%s", medName, pdgName),
00133 Form("%s_%s", medName, pdgName));
00134 tree->Branch("xsec", cache.fArray, vars.Data());
00135 for (Int_t i = 0; i < n; i++) {
00136 cache[0] = tkine[i];
00137 Int_t k = 0;
00138 for (Int_t j = 0; j < nMech; j++) {
00139 if (mechs[j].status) {
00140 if (!strcmp(mechs[j].name, "LOSS"))
00141 std::cout << tkine[i] << "\t" << mechs[j].values[i] << std::endl;
00142 cache[k+1] = mechs[j].values[i];
00143 k++;
00144 }
00145 }
00146 std::cout << k << "\t" << (k == nOk) << std::endl;
00147 tree->Fill();
00148 }
00149 tree->Write();
00150 }
00151
00152
00153
00154