22 #include "Framework/Conventions/GBuild.h"
39 using namespace genie;
40 using namespace genie::flux;
50 GJPARCNuFlux::~GJPARCNuFlux()
62 bool end = this->
End();
71 <<
"Got flux entry: " << this->
Index()
72 <<
" - Cycle: "<<
fICycle <<
"/ infinite";
75 <<
"Got flux entry: "<< this->
Index()
83 <<
"Curr flux neutrino fractional weight = " << f;
86 <<
"** Fractional weight = " << f <<
" > 1 !!";
88 double r = (f < 1.) ? rnd->
RndFlux().Rndm() : 0;
95 <<
"** Rejecting current flux neutrino based on the flux weight only";
111 <<
"The flux driver has not been properly configured";
122 <<
"The input jnubeam flux ntuple contains no entries for detector id "
134 <<
"No more entries in input flux neutrino ntuple";
164 LOG(
"Flux",
pERROR) <<
"Negative flux weight! Will set weight to 0.0";
174 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
176 <<
"Current flux neutrino not at specified detector location";
234 " --> unable to infer neutrino pdg! Aborting job!";
246 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
248 <<
"Current flux neutrino "
249 <<
"not at the list of neutrinos to be considered at this job.";
263 <<
"Flux neutrino energy exceeds declared maximum neutrino energy";
274 fgP4.SetPxPyPzE (pxnu, pynu, pznu, Enu);
288 fgX4.SetXYZT (xnu, ynu, znu, 0.);
290 fgX4.SetXYZT (0.,0.,0.,0.);
294 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
296 <<
"Generated neutrino: "
297 <<
"\n pdg-code: " <<
fgPdgC
307 std::string filename;
312 std::string::size_type start_pos = filename.rfind(
"/");
313 if (start_pos == std::string::npos) start_pos = 0;
else ++start_pos;
314 std::string basename(filename,start_pos);
328 <<
"The flux driver has not been properly configured";
349 <<
"The flux driver has not been properly configured";
359 double pot = (cnt/cnt1c) * this->
POT_1cycle();
385 <<
"Loading jnubeam flux tree from ROOT file: " << filename;
387 <<
"Detector location: " << detector_location;
395 string fileroot =
"";
396 int firstfile = -1, lastfile = -1;
399 if (filenamev.size() != 3) {
401 <<
"Flux filename should be specfied as either:\n"
402 <<
"\t For a single input file: /dir/root_filename.#.root\n"
403 <<
"\t For multiple input files: /dir/root_filename@#@#";
406 fileroot = filenamev[0];
407 firstfile = atoi(filenamev[1].c_str());
408 lastfile = atoi(filenamev[2].c_str());
410 <<
"Chaining beam simulation output files with stem: " << fileroot
411 <<
" and run numbers in the range: [" << firstfile <<
", " << firstfile <<
"]";
415 bool is_accessible = ! (gSystem->AccessPathName( filename.c_str() ));
416 if (!is_accessible) {
418 <<
"The input jnubeam flux file doesn't exist! Initialization failed!";
423 bool please_exit =
false;
424 for (
int i = firstfile; i < lastfile+1; i++) {
425 bool is_accessible = ! (gSystem->AccessPathName( Form(
"%s.%i.root",fileroot.c_str(),i) ));
426 if (!is_accessible) {
428 <<
"The input jnubeam flux file " << Form(
"%s.%i.root",fileroot.c_str(),i)
429 <<
"doesn't exist! Initialization failed!";
442 <<
" ** Unknown input detector location: " <<
fDetLoc;
450 string ntuple_name = (
fIsNDLoc) ?
"h3002" :
"h2000";
452 int result =
fNuFluxChain->Add( Form(
"%s.%i.root",fileroot.c_str(),firstfile), 0);
455 <<
"Could not find tree h3002 in file " << Form(
"%s.%i.root",fileroot.c_str(),firstfile)
456 <<
" Trying tree h3001";
458 ntuple_name =
"h3001";
459 fNuFluxChain =
new TChain(ntuple_name.c_str());
460 result = fNuFluxChain->Add( Form(
"%s.%i.root",fileroot.c_str(),firstfile), 0);
464 <<
"** Couldn't get flux tree: " << ntuple_name;
468 for (
int i = firstfile+1; i < lastfile+1; i++) {
469 result =
fNuFluxChain->Add( Form(
"%s.%i.root",fileroot.c_str(),i), 0 );
472 <<
"** Couldn't get flux tree " << ntuple_name <<
" in file " << Form(
"%s.%i.root",fileroot.c_str(),i);
481 string ntuple_name = (
fIsNDLoc) ?
"h3002" :
"h2000";
484 ntuple_name =
"h3001";
488 <<
"Getting flux tree: " << ntuple_name;
491 <<
"** Couldn't get flux tree: " << ntuple_name;
495 LOG(
"Flux",
pERROR) <<
"** Couldn't open: " << filename;
503 <<
"Loaded flux tree contains " <<
fNEntries <<
" entries";
506 <<
"Getting tree branches & setting leaf addresses";
510 bool missing_critical =
false;
517 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: norm";
518 missing_critical =
true;
523 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: Enu";
524 missing_critical =
true;
529 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: ppid";
530 missing_critical =
true;
535 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: mode";
536 missing_critical =
true;
541 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: rnu";
542 missing_critical =
true;
547 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: xnu";
548 missing_critical =
true;
553 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: ynu";
554 missing_critical =
true;
559 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: nnu";
560 missing_critical =
true;
565 LOG(
"Flux",
pFATAL) <<
"Cannot find flux branch: idfd";
566 missing_critical =
true;
569 if(missing_critical){
571 <<
"Unable to find critical information in the flux ntuple! Initialization failed!";
658 int result =
fNuFluxSumChain->Add( Form(
"%s.%i.root",fileroot.c_str(),firstfile), 0 );
660 for (
int i = firstfile+1; i < lastfile+1; i++) {
661 result =
fNuFluxSumChain->Add( Form(
"%s.%i.root",fileroot.c_str(),i), 0 );
687 for(
int ientry = 0; ientry <
fNEntries; ientry++) {
694 LOG(
"Flux",
pERROR) <<
"Negative flux weight! Will set weight to 0.0";
709 <<
"The input jnubeam flux ntuple contains no entries for detector id "
717 LOG(
"Flux",
pFATAL) <<
"Non-positive maximum flux weight!";
740 <<
"Declared list of neutrino species: " << *
fPdgCList;
745 fMaxEv = TMath::Max(0.,Ev);
748 <<
"Declared maximum flux neutrino energy: " <<
fMaxEv;
800 long int offset = (
long int) floor(ran_frac *
fNEntries);
801 LOG(
"Flux",
pERROR) <<
"Setting flux driver to start looping over entries "
802 <<
"with offset of "<< offset;
814 if(std::strcmp(opt,
"CycleHistory") == 0){
828 LOG(
"Flux",
pNOTICE) <<
"Initializing GJPARCNuFlux driver";
880 LOG(
"Flux",
pNOTICE) <<
"Setting default GJPARCNuFlux driver options";
903 fgP4.SetPxPyPzE (0.,0.,0.,0.);
904 fgX4.SetXYZT (0.,0.,0.,0.);
930 if(name ==
"sk" )
return -1;
933 for (
int i=1; i<51; i++) {
935 if(name == temp.Data())
return i;
967 for(
int i = 0; i<3; i++){
977 for(
int ip = 0; ip<
fNgmax; ip++){
1002 for(
int i = 0; i < 2; i++){
1010 for(
int i = 0; i < 3; i++)
hcur[i] = info.
hcur[i];
1031 for(
int i=0; i<3; i++){
1037 gpos0[i] = -999999.;
1041 for(
int ip = 0; ip<
fNgmax; ip++){
1065 for(
int i = 0; i < 2; i++){
1067 btilt[i] = -999999.;
1070 alpha[i] = -999999.;
1073 for(
int i = 0; i < 3; i++)
hcur[i] = -999999.;
1081 stream <<
"\n idfd = " << info.
idfd
1082 <<
"\n norm = " << info.
norm
1085 <<
"\n Enu = " << info.
Enu
1086 <<
"\n geant code = " << info.
ppid
1088 <<
"\n decay mode = " << info.
mode
1089 <<
"\n nvtx0 = " << info.
nvtx0
1090 <<
"\n |momentum| @ decay = " << info.
ppi
1091 <<
"\n position_vector @ decay = ("
1092 << info.
xpi[0] <<
", "
1093 << info.
xpi[1] <<
", "
1094 << info.
xpi[2] <<
")"
1095 <<
"\n direction_vector @ decay = ("
1096 << info.
npi[0] <<
", "
1097 << info.
npi[1] <<
", "
1098 << info.
npi[2] <<
")"
1099 <<
"\n |momentum| @ prod. = " << info.
ppi0
1100 <<
"\n position_vector @ prod. = ("
1101 << info.
xpi0[0] <<
", "
1102 << info.
xpi0[1] <<
", "
1103 << info.
xpi0[2] <<
")"
1104 <<
"\n direction_vector @ prod. = ("
1105 << info.
npi0[0] <<
", "
1106 << info.
npi0[1] <<
", "
1107 << info.
npi0[2] <<
")"
1108 <<
"\n cospibm = " << info.
cospibm
1109 <<
"\n cospi0bm = " << info.
cospi0bm
1110 <<
"\n Plus additional info if flux version is later than 07a"
static constexpr double cm
TTree * fNuFluxTree
input flux ntuple
double POT_curravg(void)
current average POT
int fgPdgC
running generated nu pdg-code
string P4AsShortString(const TLorentzVector *p)
double fSumWeightTot1c
total sum of weights for neutrinos to be thrown / cycle
bool LoadBeamSimData(string filename, string det_loc)
load a jnubeam root flux ntuple
bool End(void)
true if no more flux nu's can be thrown (eg reaching end of beam sim ntuples)
bool fLoadedNeutrino
set to true when GenerateNext_weighted has been called successfully
void SetUpstreamZ(double z0)
set flux neutrino initial z position (upstream of the detector)
int DLocName2Id(string name)
static RandomGen * Instance()
Access instance.
string fDetLoc
input detector location ('sk','nd1','nd2',...)
TChain * fNuFluxSumChain
input summary ntuple for flux file. This tree is only present for later flux versions > 10a ...
double POT_1cycle(void)
flux POT per cycle
bool GenerateNext_weighted(void)
bool fNuFluxUsingTree
are we using a TTree or a TChain to view the input flux file?
double fFilePOT
file POT normalization, typically 1E+21
TChain * fNuFluxChain
input flux ntuple
double Weight(void)
returns the flux neutrino weight (if any)
bool ExistsInPDGCodeList(int pdg_code) const
void GenerateWeighted(bool gen_weighted=true)
set whether to generate weighted or unweighted neutrinos
long int fOffset
start looping at entry fOffset
long int fNNeutrinos
number of flux neutrinos thrown so far
void SetFluxParticles(const PDGCodeList &particles)
specify list of flux neutrino species
A singleton holding random number generator classes. All random number generation in GENIE should tak...
GJPARCNuFluxPassThroughInfo()
TTree * fNuFluxSumTree
input summary ntuple for flux file. This tree is only present for later flux versions > 10a ...
A GENIE flux driver encapsulating the JPARC neutrino flux. It reads-in the official JPARC neutrino fl...
void SetMaxEnergy(double Ev)
specify maximum flx neutrino energy
ostream & operator<<(ostream &stream, const genie::flux::GJPARCNuFluxPassThroughInfo &info)
int GeantToPdg(int geant_code)
long int fNNeutrinosTot1c
total number of flux neutrinos to be thrown / cycle
TLorentzVector fgP4
running generated nu 4-momentum
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
int fDetLocId
input detector location id (fDetLoc -> jnubeam idfd)
void SetFilePOT(double pot)
flux file norm is in /N POT/det [ND] or /N POT/cm^2 [FD]. Specify N (typically 1E+21) ...
int fNCycles
how many times to cycle through the flux ntuple
static const double kASmallNum
int fNDetLocIdFound
per cycle keep track of the number of fDetLocId are found - if this is zero will exit job ...
long int fIEntry
current flux ntuple entry
bool fIsNDLoc
input location is a 'near' detector location?
GJPARCNuFluxPassThroughInfo * fPassThroughInfo
bool fGenerateWeighted
generate weighted/deweighted flux neutrinos (default is false)
TFile * fNuFluxFile
input flux file
double fMaxWeight
max flux neutrino weight in input file for the specified detector location
void Clear(Option_t *opt)
reset state variables based on opt
vector< string > Split(string input, string delim)
long int Index(void)
returns corresponding index for current flux neutrino (e.g. for a flux ntuple returns the current ent...
bool fIsFDLoc
input location is a 'far' detector location?
double fZ0
configurable starting z position for each flux neutrino (in detector coord system) ...
PDGCodeList * fPdgCList
list of neutrino pdg-codes
bool GenerateNext(void)
generate the next flux neutrino (return false in err)
long int fNEntries
number of flux ntuple entries
void SetNumOfCycles(int n)
set how many times to cycle through the ntuple (default: 1 / n=0 means 'infinite') ...
TLorentzVector fgX4
running generated nu 4-position
bool fUseRandomOffset
whether set random starting point when looping over flux ntuples
void RandomOffset(void)
choose a random offset as starting entry in flux ntuple
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
string X4AsString(const TLorentzVector *x)
double fNorm
current flux ntuple normalisation
static constexpr double m
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
#define FLUXDRIVERREG4(_nsa, _nsb, _name, _fqname)
void Copy(const PDGCodeList &list)
copy / print
double fSumWeight
sum of weights for neutrinos thrown so far
long int fEntriesThisCycle
keep track of number of entries used so far for this cycle
void push_back(int pdg_code)
double fMaxEv
maximum energy