GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Functions | Variables
gtestAxialFormFactor.cxx File Reference
#include <string>
#include <sstream>
#include <TFile.h>
#include <TTree.h>
#include "Framework/Algorithm/Algorithm.h"
#include "Framework/Algorithm/AlgFactory.h"
#include "Framework/Algorithm/AlgConfigPool.h"
#include "Framework/Conventions/Constants.h"
#include "Framework/GHEP/GHepParticle.h"
#include "Physics/QuasiElastic/XSection/AxialFormFactorModelI.h"
#include "Physics/QuasiElastic/XSection/AxialFormFactor.h"
#include "Framework/Interaction/Interaction.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/ParticleData/PDGUtils.h"
#include "Framework/Utils/CmdLnArgParser.h"
#include "Framework/Utils/StringUtils.h"
Include dependency graph for gtestAxialFormFactor.cxx:

Go to the source code of this file.

Classes

struct  tdata
 

Macros

#define MAX_COEF   3
 Program used for testing / debugging the axial form factor. More...
 
#define Q2_LIN   4
 
#define Q2_LOG_MIN   0.1
 
#define Q2_LOG_MAX   100
 
#define N_TREE   100
 

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void CalculateFormFactor (AxialFormFactor axff, TTree *affnt, tdata params, AlgFactory *algf, Registry *r, const Registry *gc, Interaction *interaction, double t0)
 
bool IncrementCoefficients (double *coefmin, double *coefmax, double *coefinc, int kmaxinc, tdata params, AlgFactory *algf, Registry *r, const Registry *gc)
 
int main (int argc, char **argv)
 

Variables

string kDefOptEvFilePrefix = "test.axialff"
 
string gOptEvFilePrefix
 
bool gOptDoLogarithmicQ2
 
double gOptCoeffMin [MAX_COEF] = {0.}
 
double gOptCoeffMax [MAX_COEF] = {0.}
 
double gOptCoeffInc [MAX_COEF] = {0.}
 
int gOptKmaxInc = 0
 

Macro Definition Documentation

#define MAX_COEF   3

Program used for testing / debugging the axial form factor.

gtestAxialFormFactor

Author
Aaron Meyer <asmeyer2012 uchicago.edu> based off testElFormFactors by Costas Andreopoulos <c.andreopoulos cern.ch> University of Liverpool
Created:
August 20, 2013

gtestAxialFormFactor [-l] [-o output_filename_prefix] [-c min,max,inc[,min,max,inc...]]

[] denotes an optionan argument -l switch which evaluates over logarithmic Q^2 -o output filename prefix for root file output -c allows scanning over z-expansion coefficients – must give a multiple of 3 numbers as arguments: min, max, increment – will scan over at most MAX_COEF coefficients and fill ntuple tree with all entries – can change MAX_COEF and recompile as necessary – to skip scanning over a coefficient, put max < min for that coefficient note that Kmax in UserPhysicsOptions should match the number of scanned coeffs

License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 57 of file gtestAxialFormFactor.cxx.

Referenced by main().

#define N_TREE   100

Definition at line 62 of file gtestAxialFormFactor.cxx.

Referenced by CalculateFormFactor().

#define Q2_LIN   4

Definition at line 59 of file gtestAxialFormFactor.cxx.

Referenced by CalculateFormFactor().

#define Q2_LOG_MAX   100

Definition at line 61 of file gtestAxialFormFactor.cxx.

Referenced by CalculateFormFactor().

#define Q2_LOG_MIN   0.1

Definition at line 60 of file gtestAxialFormFactor.cxx.

Referenced by CalculateFormFactor().

Function Documentation

void CalculateFormFactor ( AxialFormFactor  axff,
TTree *  affnt,
tdata  params,
AlgFactory algf,
Registry r,
const Registry gc,
Interaction interaction,
double  t0 
)

Definition at line 227 of file gtestAxialFormFactor.cxx.

References genie::AxialFormFactor::Calculate(), genie::AxialFormFactor::FA(), genie::AlgFactory::GetAlgorithm(), gOptDoLogarithmicQ2, genie::Interaction::KinePtr(), genie::constants::kPi0Mass, LOG, N_TREE, pERROR, tdata::pFA, tdata::pmod, tdata::pQ2, tdata::pz, genie::Kinematics::q2(), genie::utils::kinematics::Q2(), Q2_LIN, Q2_LOG_MAX, Q2_LOG_MIN, genie::AxialFormFactor::SetModel(), and genie::Kinematics::SetQ2().

Referenced by main().

232 {
233  const AxialFormFactorModelI * dipole =
234  dynamic_cast<const AxialFormFactorModelI *> (
235  algf->GetAlgorithm("genie::DipoleAxialFormFactorModel", "Default"));
236  const AxialFormFactorModelI * zexp =
237  dynamic_cast<const AxialFormFactorModelI *> (
238  algf->GetAlgorithm("genie::ZExpAxialFormFactorModel", "Default"));
239 
240  interaction->KinePtr()->SetQ2(0.);
241  double t = interaction->KinePtr()->q2();
242  double tcut = 9.0 * TMath::Power(constants::kPi0Mass, 2);
243  double Q2 = 0.;
244 
245  for(int iq=0; iq<N_TREE; iq++) {
246 
248  {
249  Q2 = TMath::Exp( TMath::Log(double(Q2_LOG_MIN))
250  + (double(iq+1)/double(N_TREE))
251  * TMath::Log(double(Q2_LOG_MAX)/double(Q2_LOG_MIN)));
252  //Q2 = TMath::Exp(((iq+1)*double(Q2_RANGE_LOG/N_TREE))*TMath::Log(10.)); // logarithmic
253  } else { Q2 = (iq+1)*double(Q2_LIN)/double(N_TREE) ; } // linear
254 
255  interaction->KinePtr()->SetQ2(Q2);
256  *params.pQ2 = Q2;
257 
258  // calculate z parameter used in expansion
259  t = interaction->KinePtr()->q2();
260  double znum = TMath::Sqrt(tcut - t) - TMath::Sqrt(tcut - t0);
261  double zden = TMath::Sqrt(tcut - t) + TMath::Sqrt(tcut - t0);
262  double zpar = znum/zden;
263 
264  if (zpar != zpar) LOG("testAxialFormFactor", pERROR) << "Undefined expansion parameter";
265  *params.pz = zpar;
266 
267  axff.SetModel(dipole);
268  axff.Calculate(interaction);
269  *params.pmod = 0;
270  *params.pFA = axff.FA();
271  affnt->Fill();
272 
273  axff.SetModel(zexp);
274  axff.Calculate(interaction);
275  *params.pmod = 1;
276  *params.pFA = axff.FA();
277  affnt->Fill();
278 
279  }
280 }
#define pERROR
Definition: Messenger.h:59
double Q2(const Interaction *const i)
Definition: KineUtils.cxx:1077
void SetQ2(double Q2, bool selected=false)
Definition: Kinematics.cxx:255
Kinematics * KinePtr(void) const
Definition: Interaction.h:76
Pure abstract base class. Defines the AxialFormFactorModelI interface to be implemented by LlewellynS...
bool gOptDoLogarithmicQ2
#define Q2_LIN
void Calculate(const Interaction *interaction)
Calculate the form factors for the input interaction using the attached algorithm.
void SetModel(const AxialFormFactorModelI *model)
Attach an algorithm.
double q2(bool selected=false) const
Definition: Kinematics.cxx:141
#define Q2_LOG_MIN
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define N_TREE
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
double FA(void) const
Get the computed axial form factor.
#define Q2_LOG_MAX
void GetCommandLineArgs ( int  argc,
char **  argv 
)
bool IncrementCoefficients ( double *  coefmin,
double *  coefmax,
double *  coefinc,
int  kmaxinc,
tdata  params,
AlgFactory algf,
Registry r,
const Registry gc 
)

Definition at line 282 of file gtestAxialFormFactor.cxx.

References genie::AlgFactory::ForceReconfiguration(), LOG, tdata::pcAn, pERROR, and genie::Registry::Set().

Referenced by main().

286 {
287 
288  if (kmaxinc < 1)
289  {
290  LOG("testAxialFormFactor",pERROR) << "No coefficients to increment";
291  return false;
292  } else {
293 
294  ostringstream alg_key;
295  int ip = -1;
296  bool stopflag;
297  do
298  {
299  if (ip > -1)
300  { // a previous iteration went over max
301  params.pcAn[ip] = coefmin[ip];
302  r->Set(alg_key.str(),params.pcAn[ip]);
303  }
304  stopflag = true;
305  alg_key.str(""); // reset sstream
306  ip++; // increment index
307  if (ip == kmaxinc) return false; // stop if gone too far
308  alg_key << "QEL-Z_A" << ip+1; // get new name
309  params.pcAn[ip] += coefinc[ip]; // increment parameter
310  r->Set(alg_key.str(),params.pcAn[ip]);
311  if (params.pcAn[ip] > coefmax[ip]) stopflag=false;
312 
313  } while (! stopflag); // loop
314 
315 
316  } // if kmaxinc < 1
317 
318  algf->ForceReconfiguration();
319  return true;
320 
321 }
#define pERROR
Definition: Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ForceReconfiguration(bool ignore_alg_opt_out=false)
Definition: AlgFactory.cxx:131
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
int main ( int  argc,
char **  argv 
)

Definition at line 98 of file gtestAxialFormFactor.cxx.

References CalculateFormFactor(), genie::AlgConfigPool::FindRegistry(), genie::AlgFactory::ForceReconfiguration(), genie::AlgFactory::GetAlgorithm(), genie::Registry::GetBool(), genie::Registry::GetBoolDef(), GetCommandLineArgs(), genie::Registry::GetDouble(), genie::Registry::GetDoubleDef(), genie::Registry::GetInt(), genie::Registry::GetIntDef(), genie::AlgConfigPool::GlobalParameterList(), gOptCoeffInc, gOptCoeffMax, gOptCoeffMin, gOptEvFilePrefix, gOptKmaxInc, IncrementCoefficients(), genie::AlgFactory::Instance(), genie::AlgConfigPool::Instance(), genie::kPdgNuMu, genie::kPdgProton, genie::kPdgTgtFe56, LOG, MAX_COEF, tdata::pcAn, tdata::pFA, pINFO, tdata::pKmax, tdata::pmod, tdata::pQ2, pWARN, tdata::pz, genie::utils::kinematics::Q2(), genie::Interaction::QELCC(), genie::Registry::Set(), and genie::Registry::UnLock().

99 {
100 
101  GetCommandLineArgs(argc,argv);
102 
103  if (gOptKmaxInc > 0)
104  {
105  LOG("testAxialFormFactor", pINFO) << "Found coefficient ranges:";
106  for (int ik=0;ik<gOptKmaxInc;ik++)
107  {
108  LOG("testAxialFormFactor", pINFO) << "( min:" << gOptCoeffMin[ik] \
109  << " , max:" << gOptCoeffMax[ik] \
110  << " , inc:" << gOptCoeffInc[ik] << " )";
111  }
112  }
113 
114  TTree * affnt = new TTree("affnt","Axial Form Factor Test Tree");
115  AxialFormFactor axff;
116  AlgFactory * algf = AlgFactory::Instance();
117  AlgConfigPool * confp = AlgConfigPool::Instance();
118  const Registry * gc = confp->GlobalParameterList();
119 
120  AlgId id("genie::ZExpAxialFormFactorModel","Default");
121  const Algorithm * alg = algf->GetAlgorithm(id);
122  Registry * r = confp->FindRegistry(alg);
123 
124  int Kmax;
125  int mod;
126  double Q2;
127  double z;
128  double FA;
129  double cAn[MAX_COEF];
130  affnt = new TTree("axff","Axial Form Factor Test");
131  affnt->Branch("Kmax", &Kmax, "Kmax/I"); // number of coefficients
132  affnt->Branch("mod", &mod, "mod/I" ); // model
133  affnt->Branch("Q2", &Q2, "Q2/D" ); // Q^2
134  affnt->Branch("z" , &z , "z/D" ); // z
135  affnt->Branch("FA", &FA, "FA/D" ); // F_A axial form factor
136  affnt->Branch("cAn", cAn, "cAn[Kmax]/D"); // z-expansion coefficients
137 
138  // load all parameters into a struct to make passing them as arguments easier
139  tdata params; //defined tdata struct above
140  params.pKmax = &Kmax;
141  params.pmod = &mod;
142  params.pQ2 = &Q2;
143  params.pz = &z;
144  params.pFA = &FA;
145  params.pcAn = cAn;
146 
147  // flag for single output or loop
148  bool do_once = (gOptKmaxInc < 1);
149  bool do_Q4limit = r->GetBoolDef("QEL-Q4limit", gc->GetBool("QEL-Q4limit"));
150 
151  if (gOptKmaxInc < 1) Kmax = r->GetIntDef("QEL-Kmax", gc->GetInt("QEL-Kmax"));
152  else Kmax = gOptKmaxInc;
153  //if (do_Q4limit) Kmax = Kmax+4;
154  if (do_Q4limit) LOG("testAxialFormFactor",pWARN) \
155  << "Q4limit specified, note that coefficients will be altered";
156 
157  // initialize to zero
158  for (int ip=0;ip<MAX_COEF;ip++)
159  {
160  params.pcAn[ip] = 0.;
161  }
162 
163  // Get T0 from registry value
164  double t0 = r->GetDoubleDef("QEL-T0", gc->GetDouble("QEL-T0"));
165 
166  // make sure coefficients are getting incremented correctly
167  if (MAX_COEF < gOptKmaxInc ||
168  (gOptKmaxInc == 0 && MAX_COEF < Kmax) )
169  {
170  LOG("testAxialFormFactor",pWARN) \
171  << "Too many coefficient ranges, reducing to " << MAX_COEF;
172  Kmax = MAX_COEF;
174  }
175  LOG("testAxialFormFactor",pWARN) << "pKmax = " << *params.pKmax;
176 
177  // set up interaction
178  Interaction * interaction =
179  Interaction::QELCC(kPdgTgtFe56,kPdgProton,kPdgNuMu,0.02);
180 
181  if (do_once)
182  { // calculate once and be done with it
183 
184  // pre-load parameters
185  ostringstream alg_key;
186  for (int ip=1;ip<Kmax+1;ip++)
187  {
188  alg_key.str("");
189  alg_key << "QEL-Z_A" << ip;
190  params.pcAn[ip-1] =
191  r->GetDoubleDef(alg_key.str(), gc->GetDouble(alg_key.str()));
192  LOG("testAxialFormFactor",pINFO) << "Loading " << alg_key.str() \
193  << " : " << params.pcAn[ip-1];
194  }
195 
196  CalculateFormFactor(axff,affnt,params,algf,r,gc,interaction,t0);//,t0,Kmax);
197  } else {
198  // override and control coefficient values
199  r->UnLock();
200  r->Set("QEL-Kmax",*params.pKmax);
201 
202  ostringstream alg_key;
203  for (int ip=1;ip<gOptKmaxInc+1;ip++)
204  {
205  alg_key.str("");
206  alg_key << "QEL-Z_A" << ip;
207  r->Set(alg_key.str(),gOptCoeffMin[ip-1]);
208  params.pcAn[ip-1] = gOptCoeffMin[ip-1];
209  LOG("testAxialFormFactor",pWARN) << "Set parameter: " << params.pcAn[ip-1];
210  }
211  algf->ForceReconfiguration();
212 
213  do
214  { CalculateFormFactor(axff,affnt,params,algf,r,gc,interaction,t0); }//,t0,Kmax); }
216  params,algf,r,gc));
217 
218  }
219 
220  TFile f((gOptEvFilePrefix + ".root").c_str(),"recreate");
221  affnt->Write();
222  f.Close();
223 
224  return 0;
225 }
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
Definition: Registry.cxx:535
int gOptKmaxInc
double gOptCoeffMax[MAX_COEF]
string gOptEvFilePrefix
Definition: gAtmoEvGen.cxx:310
double Q2(const Interaction *const i)
Definition: KineUtils.cxx:1077
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:40
const int kPdgNuMu
Definition: PDGCodes.h:30
Algorithm abstract base class.
Definition: Algorithm.h:54
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:474
RgInt GetInt(RgKey key) const
Definition: Registry.cxx:467
A class holding the Axial Form Factor.
Summary information for an interaction.
Definition: Interaction.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void ForceReconfiguration(bool ignore_alg_opt_out=false)
Definition: AlgFactory.cxx:131
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
#define pINFO
Definition: Messenger.h:62
RgInt GetIntDef(RgKey key, RgInt def_opt, bool set_def=true)
Definition: Registry.cxx:530
#define MAX_COEF
Program used for testing / debugging the axial form factor.
Registry * GlobalParameterList(void) const
#define pWARN
Definition: Messenger.h:60
void CalculateFormFactor(AxialFormFactor axff, TTree *affnt, tdata params, AlgFactory *algf, Registry *r, const Registry *gc, Interaction *interaction, double t0)
void UnLock(void)
unlocks the registry (doesn&#39;t unlock items)
Definition: Registry.cxx:153
Algorithm ID (algorithm name + configuration set name)
Definition: AlgId.h:34
double gOptCoeffInc[MAX_COEF]
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
double gOptCoeffMin[MAX_COEF]
RgBool GetBool(RgKey key) const
Definition: Registry.cxx:460
const int kPdgTgtFe56
Definition: PDGCodes.h:205
Registry * FindRegistry(string key) const
const int kPdgProton
Definition: PDGCodes.h:81
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
bool IncrementCoefficients(double *coefmin, double *coefmax, double *coefinc, int kmaxinc, tdata params, AlgFactory *algf, Registry *r, const Registry *gc)
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
RgBool GetBoolDef(RgKey key, RgBool def_opt, bool set_def=true)
Definition: Registry.cxx:525

Variable Documentation

double gOptCoeffInc[MAX_COEF] = {0.}

Definition at line 94 of file gtestAxialFormFactor.cxx.

Referenced by main().

double gOptCoeffMax[MAX_COEF] = {0.}

Definition at line 93 of file gtestAxialFormFactor.cxx.

Referenced by main().

double gOptCoeffMin[MAX_COEF] = {0.}

Definition at line 92 of file gtestAxialFormFactor.cxx.

Referenced by main().

bool gOptDoLogarithmicQ2

Definition at line 91 of file gtestAxialFormFactor.cxx.

Referenced by CalculateFormFactor().

string gOptEvFilePrefix

Definition at line 90 of file gtestAxialFormFactor.cxx.

int gOptKmaxInc = 0

Definition at line 95 of file gtestAxialFormFactor.cxx.

Referenced by main().

string kDefOptEvFilePrefix = "test.axialff"

Definition at line 89 of file gtestAxialFormFactor.cxx.