GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KNOTunedQPMDISPXSec.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 
9  Extracted/adjusted this code as part of hadronization ode refactoring.
10  Marco Roda <mroda \at liverpool.ac.uk>
11  University of Liverpool
12 */
13 //____________________________________________________________________________
14 
15 #include <sstream>
16 
17 #include <TMath.h>
18 #include <TH1D.h>
19 
24 #include "Framework/Conventions/GBuild.h"
33 #include "Framework/Utils/RunOpt.h"
36 #include "Framework/Utils/Range1.h"
38 #include "Framework/Utils/Cache.h"
40 
41 using std::ostringstream;
42 
43 using namespace genie;
44 using namespace genie::constants;
45 //using namespace genie::units;
46 
47 //____________________________________________________________________________
49 XSecAlgorithmI("genie::KNOTunedQPMDISPXSec") { ; }
50 //____________________________________________________________________________
52 XSecAlgorithmI("genie::KNOTunedQPMDISPXSec", config) { ; }
53 //____________________________________________________________________________
55 {
56 
57 }
58 //____________________________________________________________________________
59 double KNOTunedQPMDISPXSec::XSec( const Interaction * interaction,
60  KinePhaseSpace_t kps) const
61 {
62 
63  double xsec = fDISModel -> XSec(interaction, kps) ;
64 
65 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
66  LOG("DISPXSec", pINFO)
67  << "d2xsec/dxdy[FreeN] (E= " << E
68  << ", x= " << x << ", y= " << y << ") = " << xsec;
69 #endif
70 
71  double R = this->DISRESJoinSuppressionFactor(interaction);
72 
73  xsec*=R;
74 
75 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
76  LOG("DISPXSec", pINFO) << "D/R Join scheme - suppression factor R = " << R;;
77  LOG("DISPXSec", pINFO) << "d2xsec/dxdy[FreeN, D/R Join] " << xsec;
78 #endif
79 
80  xsec = TMath::Max(0., xsec ) ;
81 
82  return xsec;
83 }
84 //____________________________________________________________________________
85 double KNOTunedQPMDISPXSec::Integral(const Interaction * interaction) const
86 {
87  double xsec = fXSecIntegrator->Integrate(this,interaction);
88  return xsec;
89 }
90 //____________________________________________________________________________
91 bool KNOTunedQPMDISPXSec::ValidProcess(const Interaction * interaction) const
92 {
93  return fDISModel -> ValidProcess(interaction) ;
94 }
95 //____________________________________________________________________________
97  const Interaction * in) const
98 {
99 // Computes suppression factors for the DIS xsec under the used DIS/RES join
100 // scheme. Since this is a 'low-level' algorithm that is being called many
101 // times per generated event or computed cross section spline, the suppression
102 // factors would be cached to avoid calling the hadronization model too often.
103 //
104  double R=0, Ro=0;
105 
106  const double Wmin = kNeutronMass + kPionMass + 1E-3;
107 
108  const InitialState & ist = in->InitState();
109  const ProcessInfo & pi = in->ProcInfo();
110  const bool is_EM = pi.IsEM();
111 
112  double E = ist.ProbeE(kRfHitNucRest);
113  double Mnuc = ist.Tgt().HitNucMass();
114  double x = in->Kine().x();
115  double y = in->Kine().y();
116  double Wo = utils::kinematics::XYtoW(E,Mnuc,x,y);
117 
118  TH1D * mprob = 0;
119 
120  if(!fUseCache) {
121  // ** Compute the reduction factor at each call - no caching
122  //
123  mprob = fHadronizationModel->MultiplicityProb(in,"+LowMultSuppr");
124  R = 1;
125  if(mprob) {
126  R = mprob->Integral("width");
127  delete mprob;
128  }
129  }
130  else {
131 
132  // ** Precompute/cache the reduction factors and then use the
133  // ** cache to evaluate these factors
134 
135  // Access the cache branch. The branch key is formed as:
136  // algid/DIS-RES-Join/nu-pdg:N;hit-nuc-pdg:N/inttype
137  Cache * cache = Cache::Instance();
138  string algkey = this->Id().Key() + "/DIS-RES-Join";
139 
140  ostringstream ikey;
141  ikey << "nu-pdgc:" << ist.ProbePdg()
142  << ";hit-nuc-pdg:"<< ist.Tgt().HitNucPdg() << "/"
143  << pi.InteractionTypeAsString();
144 
145  string key = cache->CacheBranchKey(algkey, ikey.str());
146 
147  CacheBranchFx * cbr =
148  dynamic_cast<CacheBranchFx *> (cache->FindCacheBranch(key));
149 
150  // If it does't exist then create a new one
151  // and cache DIS xsec suppression factors
152  bool non_zero=false;
153  if(!cbr) {
154  LOG("DISXSec", pNOTICE)
155  << "\n ** Creating cache branch - key = " << key;
156 
157  cbr = new CacheBranchFx("DIS Suppr. Factors in DIS/RES Join Scheme");
158  Interaction interaction(*in);
159 
160  const int kN = 300;
161  double WminSpl = Wmin;
162  double WmaxSpl = fWcut + 0.1; // well into the area where scaling factor = 1
163  double dW = (WmaxSpl-WminSpl)/(kN-1);
164 
165  for(int i=0; i<kN; i++) {
166  double W = WminSpl+i*dW;
167  interaction.KinePtr()->SetW(W);
168  mprob = fHadronizationModel->MultiplicityProb(&interaction,"+LowMultSuppr");
169  R = 1;
170  if(mprob) {
171  R = mprob->Integral("width");
172  delete mprob;
173  }
174  // make sure that it takes enough samples where it is non-zero:
175  // modify the step and the sample counter once I've hit the first
176  // non-zero value
177  if(!non_zero && R>0) {
178  non_zero=true;
179  WminSpl=W;
180  i = 0;
181  dW = (WmaxSpl-WminSpl)/(kN-1);
182  }
183  LOG("DISXSec", pNOTICE)
184  << "Cached DIS XSec Suppr. factor (@ W=" << W << ") = " << R;
185 
186  cbr->AddValues(W,R);
187  }
188  cbr->CreateSpline();
189 
190  cache->AddCacheBranch(key, cbr);
191  assert(cbr);
192  } // cache data
193 
194  // get the reduction factor from the cache branch
195  if(Wo > Wmin && Wo < fWcut) {
196  const CacheBranchFx & cache_branch = (*cbr);
197  R = cache_branch(Wo);
198  }
199  }
200 
201  // Now return the suppression factor
202  if (Wo > Wmin && Wo < fWcut) {
203  Ro = R;
204  if ( is_EM ) Ro *= fNRBEMScale ; // Additional scaling
205  }
206  else if (Wo <= Wmin) Ro = 0.0;
207  else Ro = 1.0;
208 
209  LOG("DISXSec", pDEBUG)
210  << "DIS/RES Join: DIS xsec suppr. (W=" << Wo << ") = " << Ro;
211 
212  return Ro;
213 }
214 //____________________________________________________________________________
216 {
217  Algorithm::Configure(config);
218  this->LoadConfig();
219 }
220 //____________________________________________________________________________
222 {
223  Algorithm::Configure(config);
224 
225  this->LoadConfig();
226 }
227 //____________________________________________________________________________
229 {
230 
231  fHadronizationModel = nullptr ;
232 
234  dynamic_cast<const AGKYLowW2019 *> (this->SubAlg("Hadronizer"));
235  assert(fHadronizationModel);
236 
237  GetParam( "Wcut", fWcut ) ;
238  GetParam( "NRB-EM-XSecScale", fNRBEMScale );
239 
240  if ( fWcut <= 0. ) {
241 
242  LOG("KNOTunedQPMDISPXSec", pFATAL)
243  << "Input configuration value for Wcut is not physical: Exiting" ;
244 
245  // From the FreeBSD Library Functions Manual
246  //
247  // EX_CONFIG (78) Something was found in an unconfigured or miscon-
248  // figured state.
249 
250  exit( 78 ) ;
251 
252  }
253 
254  // load the pure E.A.Paschos and J.Y.Yu model
255  fDISModel = nullptr ;
256  fDISModel = dynamic_cast<const QPMDISPXSec *>(this->SubAlg("DISModel") ) ;
257  assert( fDISModel ) ;
258 
259  //-- load the differential cross section integrator
261  dynamic_cast<const XSecIntegratorI *> (this->SubAlg("XSec-Integrator"));
262  assert(fXSecIntegrator);
263 
264  // Caching the reduction factors used in the DIS/RES joing scheme?
265  // In normal event generation (1 config -> many calls) it is worth caching
266  // these suppression factors.
267  // Depending on the way this algorithm is used during event reweighting,
268  // precomputing (for all W's) & caching these factors might not be efficient.
269  // Here we provide the option to turn the caching off at run-time (default: on)
270 
271  bool cache_enabled = RunOpt::Instance()->BareXSecPreCalc();
272 
273  GetParamDef( "UseCache", fUseCache, true ) ;
274  fUseCache = fUseCache && cache_enabled;
275 
276 
277  }
278 //____________________________________________________________________________
Cross Section Calculation Interface.
double fWcut
apply DIS/RES joining scheme &lt; Wcut
TH1D * MultiplicityProb(const Interaction *, Option_t *opt="") const
double fNRBEMScale
apply NRB EM Scale factor
Cross Section Integrator Interface.
const QPMDISPXSec * fDISModel
int HitNucPdg(void) const
Definition: Target.cxx:304
Kinematics * KinePtr(void) const
Definition: Interaction.h:76
A KNO-based hadronization model.
Definition: AGKYLowW2019.h:58
double Integral(const Interaction *i) const
double HitNucMass(void) const
Definition: Target.cxx:233
#define pFATAL
Definition: Messenger.h:56
double DISRESJoinSuppressionFactor(const Interaction *in) const
void CreateSpline(string type="TSpline3")
double x(bool selected=false) const
Definition: Kinematics.cxx:99
enum genie::EKinePhaseSpace KinePhaseSpace_t
Computes DIS differential cross sections. Is a concrete implementation of the XSecAlgorithmI interfac...
Definition: QPMDISPXSec.h:33
double XYtoW(double Ev, double M, double x, double y)
Definition: KineUtils.cxx:1192
void AddCacheBranch(string key, CacheBranchI *branch)
Definition: Cache.cxx:88
double y(bool selected=false) const
Definition: Kinematics.cxx:112
double W(const Interaction *const i)
Definition: KineUtils.cxx:1101
Summary information for an interaction.
Definition: Interaction.h:56
void AddValues(double x, double y)
bool BareXSecPreCalc(void) const
Definition: RunOpt.h:53
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool fUseCache
cache reduction factors used in joining scheme
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
Definition: ProcessInfo.h:46
string CacheBranchKey(string k0, string k1="", string k2="") const
Definition: Cache.cxx:93
const Kinematics & Kine(void) const
Definition: Interaction.h:71
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
int ProbePdg(void) const
Definition: InitialState.h:64
static const double kNeutronMass
string InteractionTypeAsString(void) const
#define pINFO
Definition: Messenger.h:62
double XSec(const Interaction *i, KinePhaseSpace_t k) const
Compute the cross section for the input interaction.
bool ValidProcess(const Interaction *i) const
Can this cross section algorithm handle the input process?
CacheBranchI * FindCacheBranch(string key)
finding/adding cache branches
Definition: Cache.cxx:80
bool IsEM(void) const
GENIE Cache Memory.
Definition: Cache.h:38
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:98
void SetW(double W, bool selected=false)
Definition: Kinematics.cxx:279
const XSecIntegratorI * fXSecIntegrator
diff. xsec integrator
static RunOpt * Instance(void)
Definition: RunOpt.cxx:54
void Configure(const Registry &config)
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
const InitialState & InitState(void) const
Definition: Interaction.h:69
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:70
#define pNOTICE
Definition: Messenger.h:61
bool GetParamDef(const RgKey &name, T &p, const T &def) const
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
const Target & Tgt(void) const
Definition: InitialState.h:66
static Cache * Instance(void)
Definition: Cache.cxx:67
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:49
virtual double Integrate(const XSecAlgorithmI *model, const Interaction *interaction) const =0
double ProbeE(RefFrame_t rf) const
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
string Key(void) const
Definition: AlgId.h:46
const AGKYLowW2019 * fHadronizationModel
hadronic multip. model
Initial State information.
Definition: InitialState.h:48
#define pDEBUG
Definition: Messenger.h:63
const Algorithm * SubAlg(const RgKey &registry_key) const
Definition: Algorithm.cxx:345