20 #include <TChainElement.h> 22 #include <TStopwatch.h> 25 #include "Framework/Conventions/GBuild.h" 53 using namespace
genie;
54 using namespace genie::flux;
72 GSimpleNtpFlux::~GSimpleNtpFlux()
98 LOG(
"Flux",
pNOTICE) <<
"GenerateNext signaled End() ";
105 if ( ! nextok )
continue;
127 <<
"** Fractional weight = " << f
128 <<
" > 1 !! Bump fMaxWeight estimate to " <<
fMaxWeight 132 double r = (f < 1.) ? rnd->
RndFlux().Rndm() : 0;
133 bool accept = ( r <
f );
136 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__ 138 <<
"Generated beam neutrino: " 162 <<
"The flux driver has not been properly configured";
171 if ( fIUse < fNUse && fIEntry >= 0 ) {
188 <<
"No more entries in input flux neutrino ntuple, cycle " 200 #ifdef USE_INDEX_FOR_META 201 int nbmeta =
fNuMetaTree->GetEntryWithIndex(metakey);
210 for (
int imeta = 0; imeta < nmeta; ++imeta ) {
217 LOG(
"Flux",
pERROR) <<
"Failed to find right metakey=" << metakey
218 <<
" (was " << oldkey <<
") out of " << nmeta
222 LOG(
"Flux",
pDEBUG) <<
"Get meta " << metakey
223 <<
" (was " << oldkey <<
") " 225 <<
" nb " << nbytes <<
" " << nbmeta;
226 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__ 230 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__ 234 <<
" ifile " << ifile <<
" nbytes " << nbytes
267 <<
"Encountered neutrino specie (" << badpdg
268 <<
") that wasn't in SetFluxParticles() list, " 269 <<
"\nDeclared list of neutrino species: " << *
fPdgCList;
286 <<
"Flux neutrino energy exceeds declared maximum neutrino energy" 287 <<
"\nEv = " << Ev <<
"(> Ev{max} = " <<
fMaxEv <<
")";
293 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__ 295 <<
"Generated neutrino: " <<
fIEntry 307 <<
"Generated neutrino had E_nu = " << Ev <<
" > " <<
fMaxEv 327 double pzusr =
fP4.Pz();
328 if ( TMath::Abs(pzusr) < 1.0
e-30 ) {
331 <<
"MoveToZ0(" << z0usr <<
") not possible due to pz_usr (" << pzusr <<
")";
335 double scale = (z0usr -
fX4.Z()) / pzusr;
367 <<
"The flux driver has not been properly configured";
380 std::vector<int> nfiles_from_pattern;
384 std::set<std::string> fnames;
386 LOG(
"Flux",
pINFO) <<
"LoadBeamSimData was passed " << patterns.size()
389 for (
size_t ipatt = 0; ipatt < patterns.size(); ++ipatt ) {
390 string pattern = patterns[ipatt];
391 nfiles_from_pattern.push_back(0);
393 <<
"Loading flux tree from ROOT file pattern [" 394 <<
std::setw(3) << ipatt <<
"] \"" << pattern <<
"\"";
397 string dirname = gSystem->UnixPathName(gSystem->WorkingDirectory());
398 size_t slashpos = pattern.find_last_of(
"/");
400 if ( slashpos != std::string::npos ) {
401 dirname = pattern.substr(0,slashpos);
402 LOG(
"Flux",
pDEBUG) <<
"Look for flux using directory " << dirname;
403 fbegin = slashpos + 1;
404 }
else { fbegin = 0; }
406 void* dirp = gSystem->OpenDirectory(gSystem->ExpandPathName(dirname.c_str()));
409 pattern.substr(fbegin,pattern.size()-fbegin);
410 TRegexp re(basename.c_str(),kTRUE);
412 while ( ( onefile = gSystem->GetDirEntry(dirp) ) ) {
413 TString afile = onefile;
414 if ( afile==
"." || afile==
".." )
continue;
415 if ( basename!=afile && afile.Index(re) == kNPOS )
continue;
416 std::string fullname = dirname +
"/" + afile.Data();
417 fnames.insert(fullname);
418 nfiles_from_pattern[ipatt]++;
420 gSystem->FreeDirectory(dirp);
426 for ( ; sitr != fnames.end(); ++sitr, ++indx) {
434 if ( ! isok )
continue;
438 TFile*
tf = TFile::Open(filename.c_str(),
"READ");
439 TTree* etree = (TTree*)tf->Get(
"flux");
441 TTree* mtree = (TTree*)tf->Get(
"meta");
443 LOG(
"Flux",
pDEBUG) <<
"AddFile " << filename
444 <<
" etree " << etree <<
" meta " << mtree;
445 this->
AddFile(etree,mtree,filename);
457 <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
459 <<
"Loaded flux tree contains " <<
fNEntries <<
" entries";
461 <<
"Was passed the file patterns: ";
462 for (
size_t ipatt = 0; ipatt < patterns.size(); ++ipatt ) {
463 string pattern = patterns[ipatt];
468 <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
471 <<
"Loaded flux tree contains " <<
fNEntries <<
" entries" 472 <<
" from " << fnames.size() <<
" unique files";
473 for (
size_t ipatt = 0; ipatt < patterns.size(); ++ipatt ) {
474 string pattern = patterns[ipatt];
476 <<
" pattern: " << pattern <<
" yielded " 477 << nfiles_from_pattern[ipatt] <<
" files";
481 int sba_status[3] = { -999, -999, -999 };
483 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0) 487 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0) 488 if ( sba_status[0] < 0 ) {
490 <<
"flux chain has no \"entry\" branch " << sba_status[0];
498 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0) 507 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0) 516 <<
" SetBranchAddress status: " 517 <<
" \"entry\"=" << sba_status[0]
518 <<
" \"numi\"=" << sba_status[1]
519 <<
" \"aux\"=" << sba_status[2];
525 <<
"Run ProcessMeta() as part of LoadBeamSimData";
536 if ( config.find(
"no-offset-index") != string::npos ) {
537 LOG(
"Flux",
pINFO) <<
"Config saw \"no-offset-index\"";
548 LOG(
"Flux",
pDEBUG) <<
"about to CalcEffPOTsPerNu";
554 std::vector<std::string>& branchClassNames,
555 std::vector<void**>& branchObjPointers)
563 branchNames.push_back(
"simple");
564 branchClassNames.push_back(
"genie::flux::GSimpleNtpEntry");
565 branchObjPointers.push_back((
void**)&
fCurEntry);
569 branchNames.push_back(
"numi");
570 branchClassNames.push_back(
"genie::flux::GSimpleNtpNuMI");
571 branchObjPointers.push_back((
void**)&
fCurNuMI);
575 branchNames.push_back(
"aux");
576 branchClassNames.push_back(
"genie::flux::GSimpleNtpAux");
577 branchObjPointers.push_back((
void**)&
fCurAux);
588 double minwgt = +1.0e10;
589 double maxwgt = -1.0e10;
596 #ifdef USE_INDEX_FOR_META 598 LOG(
"Flux",
pDEBUG) <<
"ProcessMeta() BuildIndex nindices " << nindices;
601 for (
int imeta = 0; imeta < nmeta; ++imeta ) {
603 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__ 604 LOG(
"Flux",
pNOTICE) <<
"ProcessMeta() ifile " << imeta
608 minwgt = TMath::Min(minwgt,fCurMeta->minWgt);
609 maxwgt = TMath::Max(maxwgt,fCurMeta->maxWgt);
610 maxenu = TMath::Max(maxenu,fCurMeta->maxEnergy);
612 for (
size_t i = 0; i < fCurMeta->pdglist.size(); ++i)
621 LOG(
"Flux",
pFATAL) <<
"ProcessMeta() not all files have metadata";
625 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__ 627 <<
", energy = " <<
fMaxEv 638 fMaxEv = TMath::Max(0.,Ev);
641 <<
"Declared maximum flux neutrino energy: " <<
fMaxEv;
649 fNUse = TMath::Max(1L, nuse);
678 LOG(
"Flux",
pWARN) <<
"GSimpleNtpFlux::Clear(" << opt <<
") called";
698 LOG(
"Flux",
pINFO) <<
"Initializing GSimpleNtpFlux driver";
753 LOG(
"Flux",
pINFO) <<
"Setting default GSimpleNtpFlux driver options";
773 LOG(
"Flux",
pINFO) <<
"Cleaning up...";
794 if ( ! fluxtree )
return;
796 ULong64_t
nentries = fluxtree->GetEntries();
799 if ( metatree )
fNuMetaTree->AddFile(fname.c_str());
803 <<
"flux->AddFile() of " << nentries
804 <<
" " << ((metatree)?
"[+meta]":
"[no-meta]")
805 <<
" [status=" << stat <<
"]" 806 <<
" entries in file: " <<
fname;
808 if ( stat != 1 )
return;
821 <<
"no request for \"" << name <<
"\" branch ";
825 if ( (
fNuFluxTree->GetBranch(name.c_str()) ) )
return true;
828 <<
"no \"" << name <<
"\" branch in the \"flux\" tree";
862 tpx = tpy = tpz = 0.;
864 pdpx = pdpy = pdpz = 0.;
865 pppx = pppy = pppz = 0.;
938 for (
size_t i=0; i <
pdglist.size(); ++i)
939 if (
pdglist[i] == nupdg) found =
true;
940 if ( ! found )
pdglist.push_back(nupdg);
970 stream <<
"\nGSimpleNtpEntry " 971 <<
" PDG " << entry.
pdg 972 <<
" wgt " << entry.
wgt 973 <<
" ( metakey " << entry.
metakey <<
" )" 974 <<
"\n vtx [" << entry.
vtxx <<
"," << entry.
vtxy <<
"," 975 << entry.
vtxz <<
", t=" << entry.
vtxt <<
"] dist " << entry.
dist 976 <<
"\n p4 [" << entry.
px <<
"," << entry.
py <<
"," 977 << entry.
pz <<
"," << entry.
E <<
"]";
985 stream <<
"\nGSimpleNtpNuMI " 986 <<
"run " << numi.
run 987 <<
" evtno " << numi.
evtno 989 <<
"\n ndecay " << numi.
ndecay <<
" ptype " << numi.
ptype 991 <<
"\n tp[xyz] [" << numi.
tpx <<
"," << numi.
tpy <<
"," << numi.
tpz <<
"]" 992 <<
"\n v[xyz] [" << numi.
vx <<
"," << numi.
vy <<
"," << numi.
vz <<
"]" 993 <<
"\n pd[xyz] [" << numi.
pdpx <<
"," << numi.
pdpy <<
"," << numi.
pdpz <<
"]" 994 <<
"\n pp[xyz] [" << numi.
pppx <<
"," << numi.
pppy <<
"," << numi.
pppz <<
"]" 1002 stream <<
"\nGSimpleNtpAux ";
1003 size_t nInt = aux.
auxint.size();
1004 stream <<
"\n ints: ";
1005 for (
size_t ijInt=0; ijInt < nInt; ++ijInt)
1006 stream <<
" " << aux.
auxint[ijInt];
1007 size_t nDbl = aux.
auxdbl.size();
1008 stream <<
"\n doubles: ";
1009 for (
size_t ijDbl=0; ijDbl < nDbl; ++ijDbl)
1010 stream <<
" " << aux.
auxdbl[ijDbl];
1018 size_t nf = meta.
pdglist.size();
1019 stream <<
"\nGSimpleNtpMeta " << nf <<
" flavors: ";
1020 for (
size_t i=0; i<nf; ++i) stream <<
" " << meta.
pdglist[i];
1026 stream <<
"\n maxEnergy " << meta.
maxEnergy 1028 <<
" protons " << meta.
protons 1029 <<
" metakey " << meta.
metakey 1030 <<
"\n windowBase [" << meta.
windowBase[0] <<
"," 1032 <<
"\n windowDir1 [" << meta.
windowDir1[0] <<
"," 1034 <<
"\n windowDir2 [" << meta.
windowDir2[0] <<
"," 1038 if ( nInt > 0 ) stream <<
"\n aux ints: ";
1039 for (
size_t ijInt=0; ijInt < nInt; ++ijInt)
1043 if ( nDbl > 0 ) stream <<
"\n aux doubles: ";
1044 for (
size_t ijDbl=0; ijDbl < nDbl; ++ijDbl)
1047 size_t nfiles = meta.
infiles.size();
1048 stream <<
"\n " << nfiles <<
" input files: ";
1049 UInt_t nprint = TMath::Min(UInt_t(nfiles),
1051 for (UInt_t ifiles=0; ifiles < nprint; ++ifiles)
1052 stream <<
"\n " << meta.
infiles[ifiles];
1054 stream <<
"\n input seed: " << meta.
seed;
1068 std::ostringstream
s;
1070 for ( ; itr != fPdgCList->end(); ++itr) s << (*itr) <<
" ";
1072 itr = fPdgCListRej->begin();
1073 for ( ; itr != fPdgCListRej->end(); ++itr) s << (*itr) <<
" ";
1076 std::ostringstream fpattout;
1077 for (
size_t i = 0; i < fNuFluxFilePatterns.size(); ++i)
1078 fpattout <<
"\n [" <<
std::setw(3) << i <<
"] " << fNuFluxFilePatterns[i];
1080 std::ostringstream flistout;
1081 std::vector<std::string>
flist = GetFileList();
1082 for (
size_t i = 0; i < flist.size(); ++i)
1083 flistout <<
"\n [" <<
std::setw(3) << i <<
"] " << flist[i];
1086 <<
"GSimpleNtpFlux Config:" 1087 <<
"\n Enu_max " << fMaxEv
1088 <<
"\n pdg-codes: " << s.str() <<
"\n " 1089 <<
"\"flux\" " << fNEntries <<
" entries, " 1090 <<
"\"meta\" " << fNFiles <<
" entries" 1091 <<
" (FilePOTs " << fFilePOTs <<
") in files:" 1093 <<
"\n from file patterns: " 1095 <<
"\n wgt max=" << fMaxWeight
1096 <<
"\n Z0 pushback " << fZ0
1097 <<
"\n used entry " << fIEntry <<
" " << fIUse <<
"/" << fNUse
1098 <<
" times, in " << fICycle <<
"/" << fNCycles <<
" cycles" 1099 <<
"\n SumWeight " << fSumWeight <<
" for " << fNNeutrinos <<
" neutrinos" 1100 <<
" with " << fNEntriesUsed <<
" entries read" 1101 <<
"\n EffPOTsPerNu " << fEffPOTsPerNu <<
" AccumPOTs " << fAccumPOTs
1102 <<
"\n GenWeighted \"" << (fGenWeighted?
"true":
"false") <<
"\"" 1103 <<
" AlreadyUnwgt \"" << (fAlreadyUnwgt?
"true":
"false") <<
"\"" 1104 <<
" AllFilesMeta \"" << (fAllFilesMeta?
"true":
"false") <<
"\"";
1111 std::vector<std::string>
flist;
1112 TObjArray *fileElements=fNuFluxTree->GetListOfFiles();
1113 TIter next(fileElements);
1114 TChainElement *chEl=0;
1115 while (( chEl=(TChainElement*)next() )) {
1116 flist.push_back(chEl->GetTitle());
double UsedPOTs(void) const
of protons-on-target used
void GetFluxWindow(TVector3 &p1, TVector3 &p2, TVector3 &p3) const
3 points define a plane in beam coordinate
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
code to link reconstructed objects back to the MC truth information
Double_t E
energy in lab frame
GSimpleNtpAux * fCurAux
current "aux" branch extra info
Int_t fIFileNumber
which file for the current entry
void Clear(Option_t *opt)
reset state variables based on opt
virtual long int NFluxNeutrinos() const
of rays generated
std::vector< string > fNuFluxFilePatterns
(potentially wildcarded) path(s)
string P4AsShortString(const TLorentzVector *p)
long int fNNeutrinos
number of flux neutrinos thrown so far
void AddFile(TTree *fluxtree, TTree *metatree, string fname)
void PrintCurrent(void)
print current entry from leaves
THE MAIN GENIE PROJECT NAMESPACE
GSimpleNtpMeta * fCurMeta
current meta data
Double_t pdpx
nu parent momentum at time of decay
void SetEntryReuse(long int nuse=1)
of times to use entry before moving to next
long int fIUse
current # of times an entry has been used
Double_t px
x momentum in lab frame (GeV)
static RandomGen * Instance()
Access instance.
A GENIE flux driver using a simple ntuple format.
double fSumWeight
sum of weights for nus thrown so far
Double_t vtxy
y position in lab frame
Double_t vx
vertex position of hadron/muon decay
void CalcEffPOTsPerNu(void)
bool ExistsInPDGCodeList(int pdg_code) const
Int_t tptype
parent particle type at target exit
bool End(void)
true if no more flux nu's can be thrown (eg reaching end of beam sim ntuples)
std::vector< Double_t > auxdbl
additional doubles associated w/ entry
virtual void SetNumOfCycles(long int ncycle)
limit cycling through input files
A singleton holding random number generator classes. All random number generation in GENIE should tak...
std::vector< Int_t > auxint
additional ints associated w/ entry
virtual TTree * GetMetaDataTree()
void GenerateWeighted(bool gen_weighted)
set whether to generate weighted or unweighted neutrinos
void MoveToZ0(double z0)
move ray origin to user coord Z0
virtual void SetUpstreamZ(double z0)
Double_t vtxt
time of ray start (seconds)
const genie::flux::GSimpleNtpEntry * GetCurrentEntry(void)
GSimpleNtpEntry.
Double_t pppx
nu parent momentum at production point
void ProcessMeta(void)
scan for max flux energy, weight
bool OptionalAttachBranch(std::string bname)
PDGCodeList * fPdgCList
list of neutrino pdg-codes to generate
bool fIncludeVtxt
does fX4 include CurEntry.vtxt or 0
std::vector< std::string > GetFileList()
list of files currently part of chain
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
TLorentzVector fX4
reconstituted position vector
bool fAllFilesMeta
do all files in chain have meta data
Double_t fFilePOTs
of protons-on-target represented by all files
bool fGenWeighted
does GenerateNext() give weights?
Double_t vtxz
z position in lab frame
QTextStream & flush(QTextStream &s)
GENIE interface for uniform flux exposure iterface.
Int_t ppmedium
tracking medium where parent was produced
virtual double GetTotalExposure() const
GFluxExposureI interface.
GSimpleNtpNuMI * fCurNuMICopy
current "numi" branch extra info
long int fNEntriesUsed
number of entries read from files
bool GenerateNext(void)
generate the next flux neutrino (return false in err)
long int fNCycles
times to cycle through the ntuple(s)
void PrintConfig()
print the current configuration
Double_t tpx
parent particle px at target exit
void SetMaxEnergy(double Ev)
specify maximum flx neutrino energy
GSimpleNtpNuMI * fCurNuMI
current "numi" branch extra info
int fNFiles
number of files in chain
virtual void GetBranchInfo(std::vector< std::string > &branchNames, std::vector< std::string > &branchClassNames, std::vector< void ** > &branchObjPointers)
double fMaxWeight
max flux neutrino weight in input file
Q_EXPORT QTSManip setw(int w)
PDGCodeList * fPdgCListRej
list of nu pdg-codes seen but rejected
double fWeight
current neutrino weight
TChain * fNuMetaTree
TTree // REF ONLY.
GSimpleNtpEntry * fCurEntry
current entry
TLorentzVector fP4
reconstituted p4 vector
ClassImp(EDep::TEventChangeManager) namespace
bool fAlreadyUnwgt
are input files already unweighted
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Long64_t fIEntry
current flux ntuple entry
Long64_t fNEntries
number of flux ntuple entries
Double_t vtxx
x position in lab frame (meters)
Double_t pz
z momentum in lab frame
GSimpleNtpAux * fCurAuxCopy
current "aux" branch extra info
long int fNUse
how often to use same entry in a row
Double_t dist
distance from hadron decay
GSimpleNtpEntry * fCurEntryCopy
current entry
double fEffPOTsPerNu
what a entry is worth ...
double GetDecayDist() const
dist (user units) from dk to current pos
string fNuFluxBranchRequest
list of requested branches "entry,numi,au"
bool fEnd
end condition reached
TRandom3 & RndFlux(void) const
rnd number generator used by flux drivers
string X4AsString(const TLorentzVector *x)
virtual void LoadBeamSimData(const std::vector< string > &filenames, const std::string &det_loc)
double fMaxEv
maximum energy
UInt_t metakey
key to meta data
void Print(const Option_t *opt="") const
Double_t py
y momentum in lab frame
double Weight(void)
returns the flux neutrino weight (if any)
double fAccumPOTs
POTs used so far.
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 Print(const Option_t *opt="") const
QTextStream & endl(QTextStream &s)
void push_back(int pdg_code)
TChain * fNuFluxTree
TTree // REF ONLY.
bool GenerateNext_weighted(void)
void Print(const Option_t *opt="") const
Int_t ptype
parent type (PDG)