GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gCalcHEDISDiffXsec.cxx File Reference
#include "TMath.h"
#include "TSystem.h"
#include "TTree.h"
#include "TFile.h"
#include "Framework/EventGen/XSecAlgorithmI.h"
#include "Framework/EventGen/InteractionList.h"
#include "Framework/EventGen/EventGeneratorI.h"
#include "Framework/EventGen/GEVGDriver.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/KineUtils.h"
#include "Framework/Utils/CmdLnArgParser.h"
#include "Framework/Interaction/Interaction.h"
#include "Framework/Interaction/InitialState.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/Conventions/Units.h"
#include <fstream>
#include <iostream>
Include dependency graph for gCalcHEDISDiffXsec.cxx:

Go to the source code of this file.

Functions

void PrintSyntax (void)
 
void DecodeCommandLine (int argc, char *argv[])
 
vector< double > ReadListFromPath (string path)
 
int main (int argc, char **argv)
 

Variables

const double epsilon = 1e-5
 
int fNu = -1
 
int fTgt = -1
 
string fPathXlist = ""
 
string fPathYlist = ""
 
string fPathElist = ""
 
string fOutFileName = ""
 
bool fSaveAll = false
 

Function Documentation

void DecodeCommandLine ( int  argc,
char *  argv[] 
)

Definition at line 251 of file gCalcHEDISDiffXsec.cxx.

References genie::CmdLnArgParser::ArgAsInt(), genie::CmdLnArgParser::ArgAsString(), fNu, fOutFileName, fPathElist, fPathXlist, fPathYlist, fSaveAll, fTgt, genie::RunOpt::Instance(), LOG, genie::CmdLnArgParser::OptionExists(), pFATAL, pINFO, PrintSyntax(), and genie::RunOpt::ReadFromCommandLine().

Referenced by main().

251  {
252 
253  // Common run options. Set defaults and read.
254  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
255 
256  // Parse run options for this app
257  CmdLnArgParser parser(argc,argv);
258 
259  if( parser.OptionExists('p') ){
260  fNu = parser.ArgAsInt('p');
261  LOG("gcalchedisdiffxsec", pINFO) << "Probe = " << fNu;
262  }
263  else {
264  LOG("gcalchedisdiffxsec", pFATAL) << "Unspecified input neutrino type!";
265  PrintSyntax();
266  exit(1);
267  }
268 
269  if( parser.OptionExists('t') ){
270  fTgt = parser.ArgAsInt('t');
271  LOG("gcalchedisdiffxsec", pINFO) << "Target = " << fTgt;
272  }
273  else {
274  LOG("gcalchedisdiffxsec", pFATAL) << "Unspecified input target type!";
275  PrintSyntax();
276  exit(1);
277  }
278 
279  if( parser.OptionExists('x') ){
280  fPathXlist = parser.ArgAsString('x');
281  LOG("gcalchedisdiffxsec", pINFO) << "PathXlist = " << fPathXlist;
282  }
283  else {
284  LOG("gcalchedisdiffxsec", pFATAL) << "Unspecified input path to Xlist!";
285  PrintSyntax();
286  exit(1);
287  }
288 
289  if( parser.OptionExists('y') ){
290  fPathYlist = parser.ArgAsString('y');
291  LOG("gcalchedisdiffxsec", pINFO) << "PathYlist = " << fPathYlist;
292  }
293  else {
294  LOG("gcalchedisdiffxsec", pFATAL) << "Unspecified input path to Ylist!";
295  PrintSyntax();
296  exit(1);
297  }
298 
299  if( parser.OptionExists('e') ){
300  fPathElist = parser.ArgAsString('e');
301  LOG("gcalchedisdiffxsec", pINFO) << "PathElist = " << fPathElist;
302  }
303  else {
304  LOG("gcalchedisdiffxsec", pFATAL) << "Unspecified input path to Elist!";
305  PrintSyntax();
306  exit(1);
307  }
308 
309  if( parser.OptionExists('s') ) {
310  fSaveAll = true;
311  LOG("gcalchedisdiffxsec", pINFO) << "SaveAll = " << fSaveAll;
312  }
313 
314  if( parser.OptionExists('o') ){
315  fOutFileName = parser.ArgAsString('o');
316  LOG("gcalchedisdiffxsec", pINFO) << "OutFileName = " << fOutFileName;
317  }
318  else {
319  LOG("gcalchedisdiffxsec", pFATAL) << "Unspecified output file name!";
320  PrintSyntax();
321  exit(1);
322  }
323 
324 }
string fOutFileName
#define pFATAL
Definition: Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool fSaveAll
string fPathElist
#define pINFO
Definition: Messenger.h:62
int fTgt
int fNu
string fPathXlist
string fPathYlist
Command line argument parser.
void PrintSyntax(void)
int main ( int  argc,
char **  argv 
)

Definition at line 98 of file gCalcHEDISDiffXsec.cxx.

References genie::Interaction::AsString(), genie::RunOpt::BuildTune(), genie::units::cm2, genie::GEVGDriver::Configure(), genie::EventGeneratorI::CrossSectionAlg(), DecodeCommandLine(), e, genie::RunOpt::EventGeneratorList(), genie::Interaction::ExclTag(), genie::XclsTag::FinalQuarkPdg(), genie::GEVGDriver::FindGenerator(), fNu, fOutFileName, fPathElist, fPathXlist, fPathYlist, fSaveAll, fTgt, genie::Target::HitQrkPdg(), genie::Target::HitSeaQrk(), genie::Interaction::InitState(), genie::Interaction::InitStatePtr(), genie::RunOpt::Instance(), genie::GEVGDriver::Interactions(), genie::Interaction::KinePtr(), genie::kPSxyfE, LOG, genie::utils::app_init::MesgThresholds(), pDEBUG, pINFO, ReadListFromPath(), genie::GEVGDriver::SetEventGeneratorList(), genie::InitialState::SetProbeP4(), genie::Kinematics::Setx(), genie::Kinematics::Sety(), genie::InitialState::Tgt(), genie::utils::kinematics::UpdateWQ2FromXY(), and genie::XSecAlgorithmI::XSec().

98  {
99 
100  DecodeCommandLine(argc,argv);
101 
102  RunOpt::Instance()->BuildTune();
103  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
104 
105  string fChannel = RunOpt::Instance()->EventGeneratorList();
106 
107  GEVGDriver evg_driver;
108  InitialState init_state(fTgt, fNu);
109  evg_driver.SetEventGeneratorList(fChannel);
110  evg_driver.Configure(init_state);
111 
112  vector<double> ve = ReadListFromPath(fPathElist);
113  vector<double> vx = ReadListFromPath(fPathXlist);
114  vector<double> vy = ReadListFromPath(fPathYlist);
115 
116  double widthx = (TMath::Log10(vx[1])-TMath::Log10(vx[0]));
117 
118  LOG("gcalchedisdiffxsec", pINFO) << widthx;
119 
120  int quark;
121  double ei;
122  double bx;
123  double by;
124  double dxsec;
125 
126  TString treename = Form("diffxsec_nu%d_tgt%d_%s",fNu,fTgt,fChannel.c_str());
127 
128  LOG("gcalchedisdiffxsec", pINFO) << treename;
129 
130  TTree * tree = new TTree(treename,treename);
131  tree->Branch( "Quark", &quark, "Quark/I" );
132  tree->Branch( "Ei", &ei, "Ei/D" );
133  tree->Branch( "Bx", &bx, "Bx/D" );
134  tree->Branch( "By", &by, "By/D" );
135  tree->Branch( "DiffXsec", &dxsec, "DiffXsec/D" );
136 
137  const InteractionList * intlst = evg_driver.Interactions();
138 
139  InteractionList::const_iterator intliter;
140  for(intliter = intlst->begin(); intliter != intlst->end(); ++intliter) {
141 
142  const Interaction * interaction = *intliter;
143 
144  quark = 10000 * interaction->InitState().Tgt().HitQrkPdg();
145  if (!interaction->InitState().Tgt().HitSeaQrk()) {
146  if ( quark>0 ) quark += 100;
147  else quark -= 100;
148  }
149  quark += 1 * interaction->ExclTag().FinalQuarkPdg();
150 
151  LOG("gcalchedisdiffxsec", pINFO) << "Current interaction: " << interaction->AsString();
152 
153  const XSecAlgorithmI * xsec_alg = evg_driver.FindGenerator(interaction)->CrossSectionAlg();
154 
155  for ( unsigned i=0; i<ve.size(); i++ ) {
156 
157  ei = ve[i];
158 
159  LOG("gcalchedisdiffxsec", pINFO) << "Energy: " << ei << " [GeV]";
160 
161  TLorentzVector p4(0,0,ei,ei);
162  interaction->InitStatePtr()->SetProbeP4(p4);
163 
164  for ( unsigned j=0; j<vy.size(); j++ ) {
165 
166  double z = vy[j]; // z = (eo-em)/(ei-em)
167 
168  by = (1-z)*(ei-10.)/ei; // y = 1 - eo/ei;
169 
170  LOG("gcalchedisdiffxsec", pDEBUG) << " z: " << z << " y: " << by;
171 
172  if ( by==1. ) by -= 1e-4;
173  else if ( by==0. ) {
174  by = 5./ei;
175  double by_prev = (1-vy[j-1])*(ei-10.)/ei;
176  LOG("gcalchedisdiffxsec", pDEBUG) << " by: " << by << " by_prev: " << by_prev << " " << vy[j-1];
177  if (by>by_prev) by = 1e-4;
178  }
179 
180  if ( by<0 || by>1 ) continue;
181 
182  interaction->KinePtr()->Sety(by);
183 
184  if (fSaveAll) {
185  for ( unsigned k=0; k<vx.size(); k++ ) {
186  bx = vx[k];
187  interaction->KinePtr()->Setx(bx);
189  dxsec = xsec_alg->XSec(interaction, kPSxyfE) / units::cm2;
190  LOG("gcalchedisdiffxsec", pDEBUG) << "x: " << bx << " y: " << by << " -> d2sigmadxdy[E=" << ei << "GeV] = " << dxsec << " cm2";
191  tree->Fill();
192  }
193  }
194  else {
195  dxsec = 0.;
196  for ( unsigned k=0; k<vx.size(); k++ ) {
197  bx = vx[k];
198  interaction->KinePtr()->Setx(bx);
200  dxsec += xsec_alg->XSec(interaction, kPSxyfE) * bx;
201  }
202  dxsec *= widthx*TMath::Log(10) / units::cm2;
203  LOG("gcalchedisdiffxsec", pDEBUG) << " y: " << by << " -> d2sigmady[E=" << ei << "GeV] = " << dxsec << " cm2";
204  tree->Fill();
205  }
206 
207  }
208 
209  }
210 
211  }
212 
213  TFile * outfile = new TFile(fOutFileName.c_str(),"RECREATE");
214  tree->Write(tree->GetName());
215  outfile->Close();
216 
217 }
Cross Section Calculation Interface.
string fOutFileName
bool HitSeaQrk(void) const
Definition: Target.cxx:299
void SetProbeP4(const TLorentzVector &P4)
Kinematics * KinePtr(void) const
Definition: Interaction.h:76
const EventGeneratorI * FindGenerator(const Interaction *interaction) const
Definition: GEVGDriver.cxx:357
int HitQrkPdg(void) const
Definition: Target.cxx:242
string AsString(void) const
vector< double > ReadListFromPath(string path)
Summary information for an interaction.
Definition: Interaction.h:56
const double e
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool fSaveAll
void SetEventGeneratorList(string listname)
Definition: GEVGDriver.cxx:348
string fPathElist
const InteractionList * Interactions(void) const
Definition: GEVGDriver.cxx:334
static constexpr double cm2
Definition: Units.h:69
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
#define pINFO
Definition: Messenger.h:62
int fTgt
virtual double XSec(const Interaction *i, KinePhaseSpace_t k=kPSfE) const =0
Compute the cross section for the input interaction.
int fNu
int FinalQuarkPdg(void) const
Definition: XclsTag.h:72
void Setx(double x, bool selected=false)
Definition: Kinematics.cxx:231
void UpdateWQ2FromXY(const Interaction *in)
Definition: KineUtils.cxx:1290
string fPathXlist
void Sety(double y, bool selected=false)
Definition: Kinematics.cxx:243
const XclsTag & ExclTag(void) const
Definition: Interaction.h:72
string fPathYlist
virtual const XSecAlgorithmI * CrossSectionAlg(void) const =0
void Configure(int nu_pdgc, int Z, int A)
Definition: GEVGDriver.cxx:137
A vector of Interaction objects.
InitialState * InitStatePtr(void) const
Definition: Interaction.h:74
const InitialState & InitState(void) const
Definition: Interaction.h:69
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
const Target & Tgt(void) const
Definition: InitialState.h:66
void DecodeCommandLine(int argc, char *argv[])
Initial State information.
Definition: InitialState.h:48
#define pDEBUG
Definition: Messenger.h:63
void PrintSyntax ( void  )
vector< double > ReadListFromPath ( string  path)

Definition at line 225 of file gCalcHEDISDiffXsec.cxx.

References infile, LOG, and pFATAL.

Referenced by main().

225  {
226 
227  vector<double> list;
228 
229  std::ifstream infile(path.c_str());
230 
231  //check to see that the file was opened correctly:
232  if (!infile.is_open()) {
233  LOG("gcalchedisdiffxsec", pFATAL) << "There was a problem opening the input file!";
234  exit(1);//exit or do additional error checking
235  }
236 
237  double val = 0.;
238  while (infile >> val) list.push_back(val);
239 
240  return list;
241 
242 }
#define pFATAL
Definition: Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string infile

Variable Documentation

const double epsilon = 1e-5
int fNu = -1

Definition at line 84 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().

string fOutFileName = ""

Definition at line 89 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().

string fPathElist = ""

Definition at line 88 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().

string fPathXlist = ""

Definition at line 86 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().

string fPathYlist = ""

Definition at line 87 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().

bool fSaveAll = false

Definition at line 90 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().

int fTgt = -1

Definition at line 85 of file gCalcHEDISDiffXsec.cxx.

Referenced by DecodeCommandLine(), and main().