Skip to content

Commit

Permalink
Adds in-line documentation and doxygen config file to generate autodocs.
Browse files Browse the repository at this point in the history
  - Improves documentation in throughout the source.
  - Adds dox/GiBUUToStdHep.dox.cfg to build auto docs from source.
   - built by `make docs' or `make latex_docs'.
  • Loading branch information
luketpickering committed Sep 7, 2015
1 parent 2829bea commit ae91258
Show file tree
Hide file tree
Showing 6 changed files with 1,687 additions and 30 deletions.
65 changes: 45 additions & 20 deletions GiBUUToStdHep/GiBUUToStdHep.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,46 @@

#include "GiRooTracker.hxx"

namespace {

///Options relevant to the GiBUUToStdHep.exe executable.
namespace GiBUUToStdHepOpts {

///The location of the input FinalEvents.dat file which was produced by GiBUU.
std::string InpFName;

///\brief The neutrino species PDG.
///
///\note Set by
/// `GiBUUToStdHep.exe ... -u xx ...'
/// Required.
int nuType;
///\brief The target nuclei nucleon number, A.
///
///\note Set by
/// `GiBUUToStdHep.exe ... -a xx ...'
/// Required.
int TargetA;
///\brief The target nuclei proton number, Z.
///
///\note Set by
/// `GiBUUToStdHep.exe ... -z xx ...'
/// Required.
int TargetZ;
///\brief The maximum number of input entries to process.
///
///\note Set by
/// `GiBUUToStdHep.exe ... -n xx ...'
long MaxEntries;

///\brief The the debugging verbosity. From 0 (quiet) --- 4 (verbose).
///
///\note Set by
/// `GiBUUToStdHep.exe ... -v xx ...'
int Verbosity = 0;

}

int GiBUUToStdHep(){
std::ifstream ifs(InpFName);
std::ifstream ifs(GiBUUToStdHepOpts::InpFName);
std::string line;
long ctr = 0;

Expand Down Expand Up @@ -63,28 +88,28 @@ int GiBUUToStdHep(){
isHOREv = false;
}
if(!(EvNum%1000)){ std::cout << "On Ev: " << EvNum << std::endl; }
if(MaxEntries == EvNum){
if(GiBUUToStdHepOpts::MaxEntries == EvNum){
std::cout << "Finishing after " << EvNum << " entries." << std::endl;
break;
}

outRooTracker->EvtNum = EvNum;

//neutrino
outRooTracker->StdHepPdg[0] = nuType;
outRooTracker->StdHepPdg[0] = GiBUUToStdHepOpts::nuType;
outRooTracker->StdHepStatus[0] = -1;
outRooTracker->StdHepP4[0][GiRooTracker::kStdHepIdxPx] = 0;
outRooTracker->StdHepP4[0][GiRooTracker::kStdHepIdxPy] = 0;
outRooTracker->StdHepP4[0][GiRooTracker::kStdHepIdxPz] = Enu;
outRooTracker->StdHepP4[0][GiRooTracker::kStdHepIdxE] = Enu;

//target
outRooTracker->StdHepPdg[1] = GiBUUUtils::MakeNuclearPDG(TargetZ,TargetA);
outRooTracker->StdHepPdg[1] = GiBUUUtils::MakeNuclearPDG(GiBUUToStdHepOpts::TargetZ,GiBUUToStdHepOpts::TargetA);
outRooTracker->StdHepStatus[1] = -1;
outRooTracker->StdHepP4[1][GiRooTracker::kStdHepIdxPx] = 0;
outRooTracker->StdHepP4[1][GiRooTracker::kStdHepIdxPy] = 0;
outRooTracker->StdHepP4[1][GiRooTracker::kStdHepIdxPz] = 0;
outRooTracker->StdHepP4[1][GiRooTracker::kStdHepIdxE] = TargetA;
outRooTracker->StdHepP4[1][GiRooTracker::kStdHepIdxE] = GiBUUToStdHepOpts::TargetA;

outRooTracker->StdHepN = 2;
LastEvNum = EvNum;
Expand Down Expand Up @@ -115,14 +140,14 @@ int GiBUUToStdHep(){
// << outRooTracker->GiBUU2NeutCode << std::endl;
}

if(Verbosity>=1 && !outRooTracker->GiBUU2NeutCode){
if(GiBUUToStdHepOpts::Verbosity>=1 && !outRooTracker->GiBUU2NeutCode){
// std::cout << "[WARN]: Missed a GiBUU reaction code: " << Prodid
// << std::endl;
}

outRooTracker->StdHepN++;

if(Verbosity && (outRooTracker->StdHepPdg[outRooTracker->StdHepN-1]==0)){
if(GiBUUToStdHepOpts::Verbosity && (outRooTracker->StdHepPdg[outRooTracker->StdHepN-1]==0)){
std::cout << "[WARN] PDG == 0\n\t" << line << std::endl;
std::cout << "Copy: " << Run << " " << EvNum<< " " << ID << " "
<< Charge << " " << PerWeight << " " << Pos1 << " " <<
Expand All @@ -131,7 +156,7 @@ int GiBUUToStdHep(){
<< std::endl;
}

if(Verbosity>2){
if(GiBUUToStdHepOpts::Verbosity>2){
std::cout << "Line: " << line << std::endl;
std::cout << "Copy: " << Run << " " << EvNum<< " " << ID << " "
<< Charge << " " << PerWeight << " " << Pos1 << " " <<
Expand Down Expand Up @@ -160,7 +185,7 @@ void SetOpts(){
CLIUtils::OptSpec.emplace_back("-i", "--input-file", true,
[&] (std::string const &opt) -> bool {
std::cout << "\tReading GiBUU file : " << opt << std::endl;
InpFName = opt;
GiBUUToStdHepOpts::InpFName = opt;
return true;
}, true,[](){},"<File Name>");

Expand All @@ -169,7 +194,7 @@ void SetOpts(){
int vbhold;
if(GiBUUUtils::str2int(vbhold,opt.c_str()) == GiBUUUtils::STRINT_SUCCESS){
std::cout << "Nu PDG: " << vbhold << std::endl;
nuType = vbhold;
GiBUUToStdHepOpts::nuType = vbhold;
return true;
}
return false;
Expand All @@ -180,7 +205,7 @@ void SetOpts(){
int vbhold;
if(GiBUUUtils::str2int(vbhold,opt.c_str()) == GiBUUUtils::STRINT_SUCCESS){
std::cout << "Target A: " << vbhold << std::endl;
TargetA = vbhold;
GiBUUToStdHepOpts::TargetA = vbhold;
return true;
}
return false;
Expand All @@ -191,35 +216,35 @@ void SetOpts(){
int vbhold;
if(GiBUUUtils::str2int(vbhold,opt.c_str()) == GiBUUUtils::STRINT_SUCCESS){
std::cout << "Target Z: " << vbhold << std::endl;
TargetZ = vbhold;
GiBUUToStdHepOpts::TargetZ = vbhold;
return true;
}
return false;
}, true,[](){},"<Target Z>");

CLIUtils::OptSpec.emplace_back("-v", "--verbosity", true,
CLIUtils::OptSpec.emplace_back("-v", "--GiBUUToStdHepOpts::verbosity", true,
[&] (std::string const &opt) -> bool {
int vbhold;
if(GiBUUUtils::str2int(vbhold,opt.c_str()) == GiBUUUtils::STRINT_SUCCESS){
std::cout << "Verbosity: " << vbhold << std::endl;
Verbosity = vbhold;
std::cout << "GiBUUToStdHepOpts::Verbosity: " << vbhold << std::endl;
GiBUUToStdHepOpts::Verbosity = vbhold;
return true;
}
return false;
}, false,
[&](){Verbosity = 0;}, "<0-4>{default==0}");
[&](){GiBUUToStdHepOpts::Verbosity = 0;}, "<0-4>{default==0}");

CLIUtils::OptSpec.emplace_back("-n", "--nevs", true,
[&] (std::string const &opt) -> bool {
int vbhold;
if(GiBUUUtils::str2int(vbhold,opt.c_str()) == GiBUUUtils::STRINT_SUCCESS){
std::cout << "Number of events: " << vbhold << std::endl;
MaxEntries = vbhold;
GiBUUToStdHepOpts::MaxEntries = vbhold;
return true;
}
return false;
}, false,
[&](){MaxEntries = -1;}, "<Num Entries [<-1>: means all]> [default==-1]");
[&](){GiBUUToStdHepOpts::MaxEntries = -1;}, "<Num Entries [<-1>: means all]> [default==-1]");
}

int main(int argc, char const *argv[]){
Expand Down
80 changes: 72 additions & 8 deletions GiBUUToStdHep/GiBUUToStdHep_Utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,36 @@
#include <vector>
#include <iostream>

///Utilities which may be helpful for processing GiBUU specific output.
namespace GiBUUUtils {

///Returns the long-from PDG code for a nuclei with a given Z and A.
long MakeNuclearPDG(int Z, int A);

///Return codes for GiBUUUtils::str2int
enum STR2INT_ERROR { STRINT_SUCCESS,
STRINT_OVERFLOW,
STRINT_UNDERFLOW,
STRINT_INCONVERTIBLE };

///Converts a string to a long, checking for errors.
///See STR2INT_ERROR for error codes.
STR2INT_ERROR str2int (long &i, char const *s, int base=10);

///Converts a string to a int, checking for errors.
///See STR2INT_ERROR for error codes.
STR2INT_ERROR str2int (int &i, char const *s, int base=10);

///Converts an int to a std::string through std::stringstream.
std::string int2str(int i);

///Sets the first N values of a numeric array-like pointer to 0.
template<typename T>
void ClearPointer(T * &arr, size_t N){
for(size_t i = 0; i < N; ++i){
arr[i] = 0;
}
}

///Clears a 2D C++ fixed size array.
template<typename T, size_t N, size_t M>
void ClearArray2D(T (&arr)[N][M]){
for(size_t i = 0; i < N; ++i){
Expand All @@ -47,50 +51,110 @@ void ClearArray2D(T (&arr)[N][M]){
}
}

///\brief Converts a GiBUU particle code, with associated particle EM charge
///information to a PDG code.
///
/// From https://gibuu.hepforge.org/trac/wiki/ParticleIDs
///\note Returns 0 when encountering an unknown particle.
///Current codes converted:
/// - GiBUU : PDG
/// - 1 : p=2212, n=2112
/// - 101 : pi+=211, pi0=111, pi-=-211
/// - 901 : 11
/// - 902 : 13
/// - 911 : 12
/// - 912 : 14
/// - 999 : 22
/// - 32 : 3122
/// - 33 : 3222, 3212, 3112
/// - 110 : K+=321, K0=311
int GiBUUToPDG(int GiBUUCode, double GiBUUCharge);
///\brief Converts a GiBUU interaction code to the corresponding NEUT code
///where possible.
///
///Sometimes the NEUT code is dependent on the particle produced in the intial
///interaction.
///\note Current codes converted:
/// - 1 = QE
/// - 2-31 = res (specific number represents GiBUU particle id for resonance)
/// - 32,33 = 1pi
/// - 34 = DIS
/// - 35,36 = 2p2h
/// - 37 = 2pi
///
///From https://gibuu.hepforge.org/trac/wiki/LesHouches
int GiBUU2NeutReacCode(int GiBUUCode, int PDG);

}

///Contains types and functions for adding CLI options.
namespace CLIUtils {

///\brief Used to describe a CLI option.
struct Option {
///Short name for the option.
///
///For example `-c'.
std::string ShortName;
///Longer, alternative name for the option.
///
///For example `-config_file'
std::string LongName;
///
std::string ValueIdent;
///Whether an option takes a value or its presence denotes a switch.
bool HasVal;
///Whether an option is required.
///
///\note In this case it must take a value.
bool Required;
///Whether this option has been used.
bool Used;
///The function to call when this option is encountered.
///
///The value, if present is pass in to the callback.
///\note As default arguments are not available for annonymous functions this
/// version of the callback is used for options which do not take a value.
/// In this case opt is the empty string.
std::function<bool(std::string const &opt)> CallBack;
///The function to call if this option has not been 'Used'.
std::function<void()> Default;

///Default constructor; will not produce a useful Option.
Option();
///Constructor to make a useable Option.
Option(std::string shortname,std::string longname, bool hasval,
std::function<bool(std::string const &opt)> callback,
bool required=false,
std::function<void()> def=[](){},
std::string valString="Value");

///Checks if the given string corresponds to this option.
bool IsOpt(std::string const &optname) const;

friend std::ostream& operator<<(std::ostream& os, Option const &opt);
};

///Interface to adding CLI args from the entry point declaration to this module.
void AddArguments(int argc, char const * argv[]);

///\brief Processes arguments added via AddArguments through options in
///CLIUtils::OptSpec.
bool GetOpts();

///Get the value of the i'th argument.
std::string GetArg(size_t i);
///Get the number of arguments.
size_t GetNArg();

///The vector of added CLI options.
///
///Use
/// CLIUtils::OptSpec.push_back(Option(...));
///to add options.
extern std::vector<Option> OptSpec;
//I feel that this should work, but it doesn't seem to.
//You can just do OptSpec.emplace_back manually.
template<class... arguments>
void AddToOptSpec(arguments&&... args){
OptSpec.emplace_back(&args...);
}

///Writes descriptions for the Options from CLIUtils::OptSpec to std::cout.
void SayRunLike();

}
Expand Down
10 changes: 9 additions & 1 deletion GiBUUToStdHep/GiRooTracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
#include "GiRooTracker.hxx"

GiRooTracker::GiRooTracker(){
GiStdHepNPmaxstr = GiBUUUtils::int2str(kGiStdHepNPmax);
StdHepPdg = new Int_t[kGiStdHepNPmax];
StdHepStatus = new Int_t[kGiStdHepNPmax];
Reset();
}

GiRooTracker::~GiRooTracker(){
if(StdHepPdg != nullptr){ delete StdHepPdg; };
if(StdHepStatus != nullptr){ delete StdHepStatus; };
}

void GiRooTracker::Reset(){
GiBUU2NeutCode = 0;
EvtNum = 0;
Expand All @@ -19,6 +24,7 @@ void GiRooTracker::Reset(){
}

void GiRooTracker::AddBranches(TTree* &tree){

tree->Branch("GiBUU2NeutCode", &GiBUU2NeutCode, "GiBUU2NeutCode/I");

tree->Branch("EvtNum", &EvtNum,"EvtNum/I");
Expand All @@ -29,6 +35,8 @@ void GiRooTracker::AddBranches(TTree* &tree){

tree->Branch("StdHepStatus", StdHepStatus,"StdHepStatus[StdHepN]/I");

static std::string GiStdHepNPmaxstr = GiBUUUtils::int2str(kGiStdHepNPmax);

tree->Branch("StdHepP4", StdHepP4,
("StdHepP4["+GiStdHepNPmaxstr+"][4]/D").c_str());
}
Loading

0 comments on commit ae91258

Please sign in to comment.