GENIEGenerator
Loading...
Searching...
No Matches
ReinSehgalRESXSecWithCacheFast.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*
3 Copyright (c) 2003-2025, The GENIE Collaboration
4 For the full text of the license visit http://copyright.genie-mc.org
5
6 Igor Kakorin <kakorin@jinr.ru>
7 Joint Institute for Nuclear Research
8
9 based on code of
10 Costas Andreopoulos <c.andreopoulos \at cern.ch>
11 University of Liverpool
12*/
13//____________________________________________________________________________
14
15#include <sstream>
16#include <cassert>
17
18#include <TMath.h>
19#include <Math/IFunction.h>
20#include <Math/IntegratorMultiDim.h>
21
24#include "Framework/Conventions/GBuild.h"
42
43
44
45
46
47
48
49using std::ostringstream;
50
51using namespace genie;
52using namespace genie::controls;
53using namespace genie::constants;
54//using namespace genie::units;
55
56//____________________________________________________________________________
62//____________________________________________________________________________
68//____________________________________________________________________________
74//____________________________________________________________________________
79//____________________________________________________________________________
81 const Interaction * in) const
82{
83// Cache resonance neutrino production data from free nucleons
84
85 Cache * cache = Cache::Instance();
86
87 assert(fSingleResXSecModel);
88// assert(fIntegrator);
89
90 // Compute the number of spline knots - use at least 10 knots per decade
91 // && at least 40 knots in the full energy range
92 const double Emin = 0.01;
93 const int nknots_min = (int) (10*(TMath::Log(fEMax)-TMath::Log(Emin)));
94 const int nknots = TMath::Max(100, nknots_min);
95 double * E = new double[nknots]; // knot 'x'
96
97 TLorentzVector p4(0,0,0,0);
98
99 int nu_code = in->InitState().ProbePdg();
100 int nuc_code = in->InitState().Tgt().HitNucPdg();
101 int tgt_code = (nuc_code==kPdgProton) ? kPdgTgtFreeP : kPdgTgtFreeN;
102
103 Interaction * interaction = new Interaction(*in);
104 interaction->InitStatePtr()->SetPdgs(tgt_code, nu_code);
105 interaction->InitStatePtr()->TgtPtr()->SetHitNucPdg(nuc_code);
106
107 InteractionType_t wkcur = interaction->ProcInfo().InteractionTypeId();
108 unsigned int nres = fResList.NResonances();
109 for(unsigned int ires = 0; ires < nres; ires++) {
110
111 // Get next resonance from the resonance list
112 Resonance_t res = fResList.ResonanceId(ires);
113
114 interaction->ExclTagPtr()->SetResonance(res);
115
116 // Get a unique cache branch name
117 string key = this->CacheBranchName(res, wkcur, nu_code, nuc_code);
118
119 // Make sure the cache branch does not already exists
120 CacheBranchFx * cache_branch =
121 dynamic_cast<CacheBranchFx *> (cache->FindCacheBranch(key));
122 assert(!cache_branch);
123
124 // Create the new cache branch
125 LOG("ReinSehgalResCF", pNOTICE)
126 << "\n ** Creating cache branch - key = " << key;
127 cache_branch = new CacheBranchFx("RES Excitation XSec");
128 cache->AddCacheBranch(key, cache_branch);
129 assert(cache_branch);
130
131 const KPhaseSpace & kps = interaction->PhaseSpace();
132 double Ethr = kps.Threshold();
133 LOG("ReinSehgalResCF", pNOTICE) << "E threshold = " << Ethr;
134
135 // Distribute the knots in the energy range as is being done in the
136 // XSecSplineList so that the energy threshold is treated correctly
137 // in the spline - see comments there in.
138 int nkb = (Ethr>Emin) ? 5 : 0; // number of knots < threshold
139 int nka = nknots-nkb; // number of knots >= threshold
140 // knots < energy threshold
141 double dEb = (Ethr>Emin) ? (Ethr - Emin) / nkb : 0;
142 for(int i=0; i<nkb; i++) {
143 E[i] = Emin + i*dEb;
144 }
145 // knots >= energy threshold
146 double E0 = TMath::Max(Ethr,Emin);
147 double dEa = (TMath::Log10(fEMax) - TMath::Log10(E0)) /(nka-1);
148 for(int i=0; i<nka; i++) {
149 E[i+nkb] = TMath::Power(10., TMath::Log10(E0) + i * dEa);
150 }
151
152 // Compute cross sections at the given set of energies
153 for(int ie=0; ie<nknots; ie++) {
154 double xsec = 0.;
155 double Ev = E[ie];
156 p4.SetPxPyPzE(0,0,Ev,Ev);
157 interaction->InitStatePtr()->SetProbeP4(p4);
158
159 if(Ev>Ethr+kASmallNum) {
160 // Get integration ranges
161 Range1D_t rW = Range1D_t(0.0,1.0);
162 Range1D_t rQ2 = Range1D_t(0.0,1.0);
163
164 LOG("ReinSehgalResCF", pINFO)
165 << "*** Integrating d^2 XSec/dWdQ^2 for R: "
166 << utils::res::AsString(res) << " at Ev = " << Ev;
167 LOG("ReinSehgalResCF", pINFO)
168 << "{W} = " << rW.min << ", " << rW.max;
169 LOG("ReinSehgalResCF", pINFO)
170 << "{Q^2} = " << rQ2.min << ", " << rQ2.max;
171
172 if(rW.max<rW.min || rQ2.max<rQ2.min || rW.min<0 || rQ2.min<0) {
173 LOG("ReinSehgalResCF", pINFO)
174 << "** Not allowed kinematically, xsec=0";
175 } else {
176 ROOT::Math::IBaseFunctionMultiDim * func= new utils::gsl::d2XSecRESFast_dWQ2_E(fSingleResXSecModel, interaction);
177 ROOT::Math::IntegrationMultiDim::Type ig_type = utils::gsl::IntegrationNDimTypeFromString(fGSLIntgType);
178 ROOT::Math::IntegratorMultiDim ig(ig_type,0,fGSLRelTol,fGSLMaxEval);
179 ig.SetFunction(*func);
180 double kine_min[2] = { rW.min, rQ2.min };
181 double kine_max[2] = { rW.max, rQ2.max };
182 xsec = ig.Integral(kine_min, kine_max) * (1E-38 * units::cm2);
183 delete func;
184 }
185 } else {
186 LOG("ReinSehgalResCF", pINFO)
187 << "** Below threshold E = " << Ev << " <= " << Ethr;
188 }
189 cache_branch->AddValues(Ev,xsec);
190 SLOG("ReinSehgalResCF", pNOTICE)
191 << "RES XSec (R:" << utils::res::AsString(res)
192 << ", E="<< Ev << ") = "<< xsec/(1E-38 *genie::units::cm2)
193 << " x 1E-38 cm^2";
194 }//spline knots
195
196 // Build the spline
197 cache_branch->CreateSpline();
198 }//ires
199
200 delete [] E;
201 delete interaction;
202}
203//____________________________________________________________________________
205 Resonance_t res, InteractionType_t it, int nupdgc, int nucleonpdgc) const
206{
207// Build a unique name for the cache branch
208
209 Cache * cache = Cache::Instance();
210 string res_name = utils::res::AsString(res);
211 string it_name = InteractionType::AsString(it);
212 string nc_nuc = ((nucleonpdgc==kPdgProton) ? "p" : "n");
213
214 ostringstream intk;
215 intk << "ResExcitationXSec/R:" << res_name << ";nu:" << nupdgc
216 << ";int:" << it_name << nc_nuc;
217
218 string algkey = fSingleResXSecModel->Id().Key();
219 string ikey = intk.str();
220 string key = cache->CacheBranchKey(algkey, ikey);
221
222 return key;
223}
224//____________________________________________________________________________
225// GSL wrappers
226//____________________________________________________________________________
228 const XSecAlgorithmI * m, const Interaction * i) :
229ROOT::Math::IBaseFunctionMultiDim(),
230fModel(m),
232{
233 kps = fInteraction->PhaseSpacePtr();
234 Range1D_t Wl = kps->WLim();
235 fWmin = Wl.min;
236 fWmax = Wl.max;
237 Registry fConfig = (const_cast<XSecAlgorithmI *>(fModel))->GetConfig();
238 bool fUsingDisResJoin = fConfig.GetBool("UseDRJoinScheme");
239 double fWcut = 999999;
240 if(fUsingDisResJoin)
241 {
242 fWcut = fConfig.GetDouble("Wcut");
243 }
244 fWmax=TMath::Min(fWcut, fWmax);
245 if (fWcut<fWmin)
246 isfWcutLessfWmin=true;
247 else
248 isfWcutLessfWmin=false;
249 bool fNormBW = fConfig.GetBoolDef("BreitWignerNorm", true);
250 if (fNormBW)
251 {
252 double fN2ResMaxNWidths = fConfig.GetDoubleDef("MaxNWidthForN2Res", 2.0);
253 double fN0ResMaxNWidths = fConfig.GetDoubleDef("MaxNWidthForN0Res", 6.0);
254 double fGNResMaxNWidths = fConfig.GetDoubleDef("MaxNWidthForGNRes", 4.0);
255 Resonance_t resonance = fInteraction->ExclTag().Resonance();
256 int IR = utils::res::ResonanceIndex (resonance);
257 double MR = utils::res::Mass (resonance);
258 double WR = utils::res::Width (resonance);
259 if (IR==0)
260 fWcut = MR + fN0ResMaxNWidths * WR;
261 else if (IR==2)
262 fWcut = MR + fN2ResMaxNWidths * WR;
263 else
264 fWcut = MR + fGNResMaxNWidths * WR;
265 fWmax=TMath::Min(fWcut, fWmax);
266 if (fWcut<fWmin)
267 isfWcutLessfWmin=true;
268 }
269
270}
276{
277 return 2;
278}
280{
281// inputs:
282// W
283// Q2
284// outputs:
285// differential cross section [10^-38 cm^2/GeV^3] for Resonance production
286//
287
289 return 0;
290 double W = fWmin+(fWmax-fWmin)*xin[0];
291 fInteraction->KinePtr()->SetW(W);
292 Range1D_t Q2l = kps->Q2Lim_W();
293 if (Q2l.min<0 || Q2l.max<0)
294 return 0.0;
295 double Q2 = Q2l.min+(Q2l.max-Q2l.min)*xin[1];
296 fInteraction->KinePtr()->SetQ2(Q2);
297 double xsec = fModel->XSec(fInteraction, kPSWQ2fE)*(fWmax-fWmin)*(Q2l.max-Q2l.min);
298 return xsec/(1E-38 * units::cm2);
299}
300ROOT::Math::IBaseFunctionMultiDim *
306//____________________________________________________________________________
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition Messenger.h:84
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils.
A simple cache branch storing the cached data in a TNtuple.
void CreateSpline(string type="TSpline3")
void AddValues(double x, double y)
GENIE Cache Memory.
Definition Cache.h:39
string CacheBranchKey(string k0, string k1="", string k2="") const
Definition Cache.cxx:93
void AddCacheBranch(string key, CacheBranchI *branch)
Definition Cache.cxx:88
static Cache * Instance(void)
Definition Cache.cxx:67
CacheBranchI * FindCacheBranch(string key)
finding/adding cache branches
Definition Cache.cxx:80
void SetPdgs(int tgt_pdgc, int probe_pdgc)
const Target & Tgt(void) const
void SetProbeP4(const TLorentzVector &P4)
int ProbePdg(void) const
Target * TgtPtr(void) const
static string AsString(InteractionType_t type)
Summary information for an interaction.
Definition Interaction.h:56
InitialState * InitStatePtr(void) const
Definition Interaction.h:74
XclsTag * ExclTagPtr(void) const
Definition Interaction.h:77
const ProcessInfo & ProcInfo(void) const
Definition Interaction.h:70
const KPhaseSpace & PhaseSpace(void) const
Definition Interaction.h:73
const InitialState & InitState(void) const
Definition Interaction.h:69
Kinematical phase space.
Definition KPhaseSpace.h:33
double Threshold(void) const
Energy threshold.
InteractionType_t InteractionTypeId(void) const
A simple [min,max] interval for doubles.
Definition Range1.h:43
A registry. Provides the container for algorithm configuration parameters.
Definition Registry.h:65
RgDbl GetDouble(RgKey key) const
Definition Registry.cxx:474
RgBool GetBoolDef(RgKey key, RgBool def_opt, bool set_def=true)
Definition Registry.cxx:525
RgBool GetBool(RgKey key) const
Definition Registry.cxx:460
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
Definition Registry.cxx:535
void CacheResExcitationXSec(const Interaction *interaction) const
string CacheBranchName(Resonance_t r, InteractionType_t it, int nu, int nuc) const
int HitNucPdg(void) const
Definition Target.cxx:304
void SetHitNucPdg(int pdgc)
Definition Target.cxx:171
Cross Section Calculation Interface.
string fGSLIntgType
name of GSL numerical integrator
int fGSLMaxEval
GSL max evaluations.
double fGSLRelTol
required relative tolerance (error)
void SetResonance(Resonance_t res)
Definition XclsTag.cxx:128
ROOT::Math::IBaseFunctionMultiDim * Clone(void) const
d2XSecRESFast_dWQ2_E(const XSecAlgorithmI *m, const Interaction *i)
double func(double x, double y)
Basic constants.
Misc GENIE control constants.
static const double kASmallNum
Definition Controls.h:40
static constexpr double cm2
Definition Units.h:69
ROOT::Math::IntegrationMultiDim::Type IntegrationNDimTypeFromString(string type)
Definition GSLUtils.cxx:59
double Width(Resonance_t res)
resonance width (GeV)
double Mass(Resonance_t res)
resonance mass (GeV)
int ResonanceIndex(Resonance_t res)
resonance idx, quark model / SU(6)
const char * AsString(Resonance_t res)
resonance id -> string
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
const int kPdgProton
Definition PDGCodes.h:81
enum genie::EInteractionType InteractionType_t
enum genie::EResonance Resonance_t
const int kPdgTgtFreeN
Definition PDGCodes.h:200
const int kPdgTgtFreeP
Definition PDGCodes.h:199