1 //____________________________________________________________________
5 // Script to get the various cross sections, energy loss, and ranges
6 // of a particular particle type in a particular medium.
8 // This script should be compiled to speed it up.
10 // It creates a tree on the current output file, with the relevant
13 // Note, that VMC _must_ be the TGeant3TGeo VMC.
18 gROOT->ProcessLine(".x Compile.C(\"$(ALICE_ROOT)/FMD/scripts/XSection.C\"");
19 gAlice->InitMC("$(ALICE_ROOT)/FMD/Config.C");
20 TFile* file = TFile::Open("xsec.root", "RECREATE");
21 GetXsection("FMD_Si$", "pi+");
29 #include <TVirtualMC.h>
30 #include <TDatabasePDG.h>
32 #include <TGeoManager.h>
33 #include <TGeoMedium.h>
42 /** @defgroup xsec_script X-section script
45 //____________________________________________________________________
46 /** @ingroup xsec_script
56 {{ "HADF","total hadronic x-section according to FLUKA", "cm^{1}"},
57 { "INEF","hadronic inelastic x-section according to FLUKA", "cm^{1}"},
58 { "ELAF","hadronic elastic x-section according to FLUKA", "cm^{1}"},
59 { "HADG","total hadronic x-section according to GHEISHA", "cm^{1}"},
60 { "INEG","hadronic inelastic x-section according to GHEISHA","cm^{1}"},
61 { "ELAG","hadronic elastic x-section according to GHEISHA", "cm^{1}"},
62 { "FISG","nuclear fission x-section according to GHEISHA", "cm^{1}"},
63 { "CAPG","neutron capture x-section according to GHEISHA", "cm^{1}"},
64 { "LOSS","stopping power", "cm^{1}"},
65 { "PHOT","photoelectric x-section", "MeV/cm"},
66 { "ANNI","positron annihilation x-section", "cm^{1}"},
67 { "COMP","Compton effect x-section", "cm^{1}"},
68 { "BREM","bremsstrahlung x-section", "cm^{1}"},
69 { "PAIR","photon and muon direct- pair x-section", "cm^{1}"},
70 { "DRAY","delta-rays x-section", "cm^{1}"},
71 { "PFIS","photo-fission x-section", "cm^{1}"},
72 { "RAYL","Rayleigh scattering x-section", "cm^{1}"},
73 { "MUNU","muon-nuclear interaction x-section", "cm^{1}"},
74 { "RANG","range", "cm"},
75 { "STEP","maximum step", "cm"},
78 //____________________________________________________________________
79 /** @ingroup xsec_script
83 MechValue(const Mech& m, size_t n)
84 : fMech(m), fValues(n), fStatus(0)
86 bool Get(TGeant3* mc, std::vector<float>& t,
87 std::vector<float>& c, int medNo, int pidNo)
90 g.SetName(fMech.fName);
91 g.SetTitle(fMech.fTitle);
92 g.GetXaxis()->SetTitle("p [GeV]");
93 g.GetYaxis()->SetTitle(fMech.fUnit);
95 mc->Gftmat(medNo, pidNo, fMech.fName, t.size(),
96 &(t[0]), &(fValues[0]), &(c[0]), ixst);
98 if (!fStatus) return false;
99 for (size_t i = 0; i < t.size(); i++) g.SetPoint(i, t[i], fValues[i]);
104 std::vector<float> fValues;
108 //____________________________________________________________________
109 /** @ingroup xsec_script
113 XSection(size_t n=91, float emin=1e-5, float emax=1e4)
117 float dp = 1. / log10(emax/emin);
118 float pmin = log10(emin);
120 for (size_t i = 1; i < fTKine.size(); i++) {
121 float el = pmin + i * dp;
122 fTKine[i] = pow(10, el);
124 for (float_array::iterator i = fCuts.begin(); i != fCuts.end(); ++i)
126 Mech* mech = &(fgMechs[0]);
128 while (mech->fName) {
129 fMechs.push_back(new MechValue(*mech, n));
133 void Run(const std::string& medName, const std::string& pdgName)
135 TGeant3* mc = static_cast<TGeant3*>(gMC);
137 std::cerr << "Couldn't get VMC" << std::endl;
140 TGeoMedium* medium = gGeoManager->GetMedium(medName.c_str());
142 std::cerr << "Couldn't find medium " << medName << std::endl;
145 int medNo = medium->GetMaterial()->GetUniqueID();
146 TDatabasePDG* pdgDb = TDatabasePDG::Instance();
147 TParticlePDG* pdgP = pdgDb->GetParticle(pdgName.c_str());
149 std::cerr << "Couldn't find particle " << pdgName << std::endl;
152 int pdgNo = pdgP->PdgCode();
153 int pidNo = mc->IdFromPDG(pdgNo);
155 std::stringstream vars;
159 // Loop over defined mechanisms
160 for (mech_array::iterator i = fMechs.begin(); i != fMechs.end(); ++i) {
161 if (!(*i)->Get(mc, fTKine, fCuts, medNo, pidNo))continue;
162 vars << ":" << (*i)->fMech.fName;
166 std::stringstream tName;
167 tName << medName << "_" << pdgName;
168 TTree* tree = new TTree(tName.str().c_str(), tName.str().c_str());
170 float_array cache(nOk+1);
171 tree->Branch("xsec", &(cache[0]), vars.str().c_str());
172 for (size_t i = 0; i < fTKine.size(); i++) {
173 cache[0] = fTKine[i];
175 for (mech_array::iterator j = fMechs.begin(); j != fMechs.end(); ++j) {
176 if (!(*j)->fStatus) continue;
177 cache[++k] = (*j)->fValues[i];
184 typedef std::vector<float> float_array;
185 typedef std::vector<MechValue*> mech_array;
192 //____________________________________________________________________
193 /** @ingroup xsec_script
201 GetXsection(const char* medName, const char* pdgName,
202 Int_t n=91, Float_t emin=1e-5, Float_t emax=1e4)
205 Float_t dp = 1/TMath::Log10(emax/emin);
206 Float_t pmin = TMath::Log10(emin);
208 for (Int_t i=1; i < tkine.fN; i++) {
209 Float_t el = pmin + i * dp;
210 tkine[i] = TMath::Power(10, el);
216 {{ "HADF","total hadronic x-section according to FLUKA","cm^{1}",n,0},
217 { "INEF","hadronic inelastic x-section according to FLUKA","cm^{1}",n,0},
218 { "ELAF","hadronic elastic x-section according to FLUKA","cm^{1}",n,0},
219 { "HADG","total hadronic x-section according to GHEISHA","cm^{1}",n,0},
220 { "INEG","hadronic inelastic x-section according to GHEISHA","cm^{1}",n,0},
221 { "ELAG","hadronic elastic x-section according to GHEISHA","cm^{1}",n,0},
222 { "FISG","nuclear fission x-section according to GHEISHA","cm^{1}",n,0},
223 { "CAPG","neutron capture x-section according to GHEISHA","cm^{1}",n,0},
224 { "LOSS","stopping power","cm^{1}",n,0},
225 { "PHOT","photoelectric x-section","MeV/cm",n,0},
226 { "ANNI","positron annihilation x-section","cm^{1}",n,0},
227 { "COMP","Compton effect x-section","cm^{1}",n,0},
228 { "BREM","bremsstrahlung x-section","cm^{1}",n,0},
229 { "PAIR","photon and muon direct- pair x-section","cm^{1}",n,0},
230 { "DRAY","delta-rays x-section","cm^{1}",n,0},
231 { "PFIS","photo-fission x-section","cm^{1}",n,0},
232 { "RAYL","Rayleigh scattering x-section","cm^{1}",n,0},
233 { "MUNU","muon-nuclear interaction x-section","cm^{1}",n,0},
234 { "RANG","range","cm",n,0},
235 { "STEP","maximum step","cm",n,0},
237 TGeant3* mc = (TGeant3*)gMC;
239 std::cerr << "Couldn't get VMC" << std::endl;
242 TGeoMedium* medium = gGeoManager->GetMedium(medName);
244 std::cerr << "Couldn't find medium " << medName << std::endl;
247 Int_t medNo = medium->GetMaterial()->GetUniqueID();
248 TDatabasePDG* pdgDb = TDatabasePDG::Instance();
249 TParticlePDG* pdgP = pdgDb->GetParticle(pdgName);
251 std::cerr << "Couldn't find particle " << pdgName << std::endl;
254 Int_t pdgNo = pdgP->PdgCode();
255 Int_t pidNo = mc->IdFromPDG(pdgNo);
257 Mech* mech = &(mechs[0]);
262 cout << mech->name << ": " << mech->title << " ... " << std::flush;
265 mc->Gftmat(medNo, pidNo, mech->name, n,
266 tkine.fArray, mech->values.fArray, cuts.fArray, ixst);
270 vars.Append(Form(":%s", mech->name));
271 if (!strcmp("LOSS", mech->name)) {
272 for (Int_t i = 0; i < n; i++)
273 std::cout << i << "\t" << tkine[i] << "\t"
274 << mech->values[i] << std::endl;
277 std::cout << (ixst ? "ok" : "failed") << std::endl;
280 // TFile* file = TFile::Open(Form("xsec-%d.root", pdgNo),
282 TArrayF cache(nOk+1);
283 TTree* tree = new TTree(Form("%s_%s", medName, pdgName),
284 Form("%s_%s", medName, pdgName));
285 tree->Branch("xsec", cache.fArray, vars.Data());
286 for (Int_t i = 0; i < n; i++) {
289 for (Int_t j = 0; j < nMech; j++) {
290 if (mechs[j].status) {
291 if (!strcmp(mechs[j].name, "LOSS"))
292 std::cout << tkine[i] << "\t" << mechs[j].values[i] << std::endl;
293 cache[k+1] = mechs[j].values[i];
297 std::cout << k << "\t" << (k == nOk) << std::endl;
304 //____________________________________________________________________