KNOTunedQPMDISPXSec.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
7  University of Liverpool & STFC Rutherford Appleton Laboratory
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 //____________________________________________________________________________
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 //____________________________________________________________________________
86 {
87  double xsec = fXSecIntegrator->Integrate(this,interaction);
88  return xsec;
89 }
90 //____________________________________________________________________________
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 
111  double E = ist.ProbeE(kRfHitNucRest);
112  double Mnuc = ist.Tgt().HitNucMass();
113  double x = in->Kine().x();
114  double y = in->Kine().y();
115  double Wo = utils::kinematics::XYtoW(E,Mnuc,x,y);
116 
117  TH1D * mprob = 0;
118 
119  if(!fUseCache) {
120  // ** Compute the reduction factor at each call - no caching
121  //
122  mprob = fHadronizationModel->MultiplicityProb(in,"+LowMultSuppr");
123  R = 1;
124  if(mprob) {
125  R = mprob->Integral("width");
126  delete mprob;
127  }
128  }
129  else {
130 
131  // ** Precompute/cache the reduction factors and then use the
132  // ** cache to evaluate these factors
133 
134  // Access the cache branch. The branch key is formed as:
135  // algid/DIS-RES-Join/nu-pdg:N;hit-nuc-pdg:N/inttype
136  Cache * cache = Cache::Instance();
137  string algkey = this->Id().Key() + "/DIS-RES-Join";
138 
139  ostringstream ikey;
140  ikey << "nu-pdgc:" << ist.ProbePdg()
141  << ";hit-nuc-pdg:"<< ist.Tgt().HitNucPdg() << "/"
142  << pi.InteractionTypeAsString();
143 
144  string key = cache->CacheBranchKey(algkey, ikey.str());
145 
146  CacheBranchFx * cbr =
147  dynamic_cast<CacheBranchFx *> (cache->FindCacheBranch(key));
148 
149  // If it does't exist then create a new one
150  // and cache DIS xsec suppression factors
151  bool non_zero=false;
152  if(!cbr) {
153  LOG("DISXSec", pNOTICE)
154  << "\n ** Creating cache branch - key = " << key;
155 
156  cbr = new CacheBranchFx("DIS Suppr. Factors in DIS/RES Join Scheme");
158 
159  const int kN = 300;
160  double WminSpl = Wmin;
161  double WmaxSpl = fWcut + 0.1; // well into the area where scaling factor = 1
162  double dW = (WmaxSpl-WminSpl)/(kN-1);
163 
164  for(int i=0; i<kN; i++) {
165  double W = WminSpl+i*dW;
166  interaction.KinePtr()->SetW(W);
167  mprob = fHadronizationModel->MultiplicityProb(&interaction,"+LowMultSuppr");
168  R = 1;
169  if(mprob) {
170  R = mprob->Integral("width");
171  delete mprob;
172  }
173  // make sure that it takes enough samples where it is non-zero:
174  // modify the step and the sample counter once I've hit the first
175  // non-zero value
176  if(!non_zero && R>0) {
177  non_zero=true;
178  WminSpl=W;
179  i = 0;
180  dW = (WmaxSpl-WminSpl)/(kN-1);
181  }
182  LOG("DISXSec", pNOTICE)
183  << "Cached DIS XSec Suppr. factor (@ W=" << W << ") = " << R;
184 
185  cbr->AddValues(W,R);
186  }
187  cbr->CreateSpline();
188 
189  cache->AddCacheBranch(key, cbr);
190  assert(cbr);
191  } // cache data
192 
193  // get the reduction factor from the cache branch
194  if(Wo > Wmin && Wo < fWcut-1E-2) {
195  const CacheBranchFx & cache_branch = (*cbr);
196  R = cache_branch(Wo);
197  }
198  }
199 
200  // Now return the suppression factor
201  if (Wo > Wmin && Wo < fWcut-1E-2) Ro = R;
202  else if (Wo <= Wmin) Ro = 0.0;
203  else Ro = 1.0;
204 
205  LOG("DISXSec", pDEBUG)
206  << "DIS/RES Join: DIS xsec suppr. (W=" << Wo << ") = " << Ro;
207 
208  return Ro;
209 }
210 //____________________________________________________________________________
212 {
213  Algorithm::Configure(config);
214  this->LoadConfig();
215 }
216 //____________________________________________________________________________
218 {
219  Algorithm::Configure(config);
220 
221  this->LoadConfig();
222 }
223 //____________________________________________________________________________
225 {
226 
227  fHadronizationModel = nullptr ;
228 
230  dynamic_cast<const AGKYLowW2019 *> (this->SubAlg("Hadronizer"));
231  assert(fHadronizationModel);
232 
233  GetParam( "Wcut", fWcut ) ;
234 
235  if ( fWcut <= 0. ) {
236 
237  LOG("KNOTunedQPMDISPXSec", pFATAL)
238  << "Input configuration value for Wcut is not physical: Exiting" ;
239 
240  // From the FreeBSD Library Functions Manual
241  //
242  // EX_CONFIG (78) Something was found in an unconfigured or miscon-
243  // figured state.
244 
245  exit( 78 ) ;
246 
247  }
248 
249  // load the pure E.A.Paschos and J.Y.Yu model
250  fDISModel = nullptr ;
251  fDISModel = dynamic_cast<const QPMDISPXSec *>(this->SubAlg("DISModel") ) ;
252  assert( fDISModel ) ;
253 
254  //-- load the differential cross section integrator
256  dynamic_cast<const XSecIntegratorI *> (this->SubAlg("XSec-Integrator"));
257  assert(fXSecIntegrator);
258 
259  // Caching the reduction factors used in the DIS/RES joing scheme?
260  // In normal event generation (1 config -> many calls) it is worth caching
261  // these suppression factors.
262  // Depending on the way this algorithm is used during event reweighting,
263  // precomputing (for all W's) & caching these factors might not be efficient.
264  // Here we provide the option to turn the caching off at run-time (default: on)
265 
266  bool cache_enabled = RunOpt::Instance()->BareXSecPreCalc();
267 
268  GetParamDef( "UseCache", fUseCache, true ) ;
269  fUseCache = fUseCache && cache_enabled;
270 
271 
272  }
273 //____________________________________________________________________________
Cross Section Calculation Interface.
double fWcut
apply DIS/RES joining scheme < Wcut
Basic constants.
TH1D * MultiplicityProb(const Interaction *, Option_t *opt="") const
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
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
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:1179
void AddCacheBranch(string key, CacheBranchI *branch)
Definition: Cache.cxx:88
double y(bool selected=false) const
Definition: Kinematics.cxx:112
Summary information for an interaction.
Definition: Interaction.h:56
void AddValues(double x, double y)
bool BareXSecPreCalc(void) const
Definition: RunOpt.h:51
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
def key(type, name=None)
Definition: graph.py:13
bool fUseCache
cache reduction factors used in joining scheme
static Config * config
Definition: config.cpp:1054
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
Definition: Constants.h:76
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
GENIE Cache Memory.
Definition: Cache.h:38
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:97
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
static const double kPionMass
Definition: Constants.h:73
void Configure(const Registry &config)
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
virtual double Integrate(const XSecAlgorithmI *model, const Interaction *interaction) const =0
const InitialState & InitState(void) const
Definition: Interaction.h:69
const ProcessInfo & ProcInfo(void) const
Definition: Interaction.h:70
list x
Definition: train.py:276
float pi
Definition: units.py:11
#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:37
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