20 #include "nutools/EventGeneratorBase/GENIE/GENIE2ART.h" 21 #include "nutools/EventGeneratorBase/GENIE/EvtTimeShiftI.h" 22 #include "nutools/EventGeneratorBase/GENIE/EvtTimeShiftFactory.h" 28 #include "PDG/PDGLibrary.h" 33 #include "FluxDrivers/GNuMIFlux.h" 34 #include "FluxDrivers/GSimpleNtpFlux.h" 36 #include "GENIE/Framework/ParticleData/PDGLibrary.h" 37 #include "GENIE/Framework/GHEP/GHepRecord.h" 38 #include "GENIE/Framework/Ntuple/NtpMCFormat.h" 39 #include "GENIE/Framework/Ntuple/NtpWriter.h" 40 #include "GENIE/Framework/Ntuple/NtpMCEventRecord.h" 44 #include "GENIE/Tools/Flux/GNuMIFlux.h" 45 #include "GENIE/Tools/Flux/GSimpleNtpFlux.h" 48 #include "dk2nu/tree/dk2nu.h" 49 #include "dk2nu/tree/NuChoice.h" 53 #include "TBranchElement.h" 54 #include "TBranchObject.h" 57 #include "CLHEP/Random/RandFlat.h" 58 #include "CLHEP/Random/RandPoissonT.h" 59 #include "CLHEP/Random/RandGauss.h" 71 #include "nutools/EventGeneratorBase/GENIE/EVGBAssociationUtil.h" 86 Comment(
"list of input gntp.*.ghep.root files"),
91 Comment(
"how many events to pull \"<form>: <value> [<value>]\"" 92 " known functional forms:\n" 94 " \"flat: <nmin> <nmax>\"\n" 95 " \"poisson: <mean>\"\n" 96 " \"poisson-1: <mean>\" use Poisson, then subtract 1 (floor 0)\n" 97 " \"gauss: <mean> <rms>\" (floor 0)"),
101 Name(
"globalTimeOffset"),
102 Comment(
"fixed offset to add (in ns)"),
107 Comment(
"time distribution beyond globalTimeOffset (in ns)\n" 108 " e.g. \"flat: 1000\"\n" 110 "currently does not support modified numi parameters"),
123 Comment(
"allow module to offset global vertex (genie vtx units = m)")
127 Comment(
"attempt to fetch and fill MCFlux for each genie::EventRecord"),
131 Name(
"randomEntries"),
132 Comment(
"use random sets of entries from input files\n" 133 "rather than go through the files sequentially"),
137 Name(
"outputPrintLevel"),
138 Comment(
"print fetched genie::EventRecord -1=no, 13=max info\n" 139 "see GENIE manual for legal values"),
143 Name(
"outputDumpFileName"),
144 Comment(
"name of file to print to (if outputPrintLevel >= 0)\n" 145 "\"std::cout\" for standard out\n" 146 "otherwise string with %l replaced by module_label"),
147 "AddGenieEventsToArt_%l.txt" 206 void ParseCountConfig();
207 size_t GetNumToAdd()
const;
208 void ParseTimeConfig();
209 void ParseVtxOffsetConfig();
265 , fGlobalTimeOffset(0)
267 , fXlo(0), fYlo(0), fZlo(0)
268 , fXhi(0), fYhi(0), fZhi(0)
270 , fRandomEntries(true)
271 , fOutputPrintLevel(-1)
274 , fRndDist(kUnknownDist)
277 , fGTreeChain(new TChain(
"gtree"))
278 , fMCRec(new
genie::NtpMCEventRecord)
281 , fGNuMIFluxPassThroughInfo(0)
282 , fGSimpleNtpEntry(0)
302 <<
" ctor start " << fMyModuleLabel
316 produces< std::vector<simb::MCTruth> >();
317 produces< std::vector<simb::GTruth> >();
318 produces< art::Assns<simb::MCTruth, simb::GTruth> >();
320 produces< std::vector<simb::MCFlux> >();
322 produces< art::Assns<simb::MCTruth, simb::MCFlux> >();
330 for (
size_t i=0; i <
fFileList.size(); ++i) {
357 TObjArray* blist =
fGTreeChain->GetListOfBranches();
360 while ( ( obj = next() ) ) {
364 const TBranchElement* belement =
dynamic_cast<const TBranchElement*
>(obj);
365 const TBranchObject* bobject =
dynamic_cast<const TBranchObject*
>(obj);
366 if ( ! belement && ! bobject ) {
369 <<
"### supposed branch element '" << bname
370 <<
"' wasn't a TBranchElement/TBranchObject but instead a " 372 if ( bname ==
"gmcrec" ) {
374 <<
"### since this is '" << bname
375 <<
"' this is likely to end very badly badly" <<
std::endl;
379 std::string bclass = (belement) ? belement->GetClassName()
380 : bobject->GetClassName();
381 if ( bclass ==
"genie::NtpMCEventRecord" ) {
383 }
else if ( bclass ==
"genie::flux::GNuMIFluxPassThroughInfo" ) {
386 }
else if ( bclass ==
"genie::flux::GSimpleNtpEntry" ) {
389 }
else if ( bclass ==
"genie::flux::GSimpleNtpNuMI" ) {
392 }
else if ( bclass ==
"genie::flux::GSimpleNtpAux" ) {
395 }
else if ( bclass ==
"bsim::Dk2Nu" ) {
398 }
else if ( bclass ==
"bsim::NuChoice" ) {
403 <<
"### branch element '" << bname
404 <<
"' was unhandled '" << bclass <<
"' class" <<
std::endl;
409 <<
"chain has " <<
fNumMCRec <<
" entries" 423 if ( posl != std::string::npos ) {
427 <<
"#### AddGenieEventsToArt::ctor open " 432 std::ios_base::trunc|std::ios_base::out);
443 std::ofstream* ofs =
dynamic_cast<std::ofstream*
>(
fOutputStream);
446 <<
"#### AddGenieEventsToArt::dtor close " 461 std::unique_ptr< std::vector<simb::MCTruth> >
462 mctruthcol(
new std::vector<simb::MCTruth>);
464 std::unique_ptr< std::vector<simb::GTruth> >
465 gtruthcol(
new std::vector<simb::GTruth>);
467 std::unique_ptr< std::vector<simb::MCFlux> >
468 mcfluxcol(
new std::vector<simb::MCFlux>);
470 std::unique_ptr< art::Assns<simb::MCTruth, simb::MCFlux> >
472 std::unique_ptr< art::Assns<simb::MCTruth, simb::GTruth> >
482 std::vector<size_t> entries;
487 while ( entries.size() !=
n ) {
497 if ( std::find(entries.begin(),entries.end(),indx) != entries.end() ) {
501 entries.push_back(indx);
508 for (
size_t i=0; i<
n; ++i) {
513 size_t ientry = entries[i];
544 TLorentzVector vtxOffset(xoff,yoff,zoff,evtTimeOffset);
552 double dk2gen = -99999.;
591 mctruthcol->push_back(mctruth);
592 gtruthcol->push_back(gtruth);
595 mcfluxcol->push_back(mcflux);
607 gtruthcol->size()-1, gtruthcol->size());
611 mcfluxcol->size()-1, mcfluxcol->size());
645 std::transform(str.begin(),str.end(),str.begin(),::tolower);
647 if( str.find_first_not_of(
" \t\n") != 0)
648 str.erase( 0, str.find_first_not_of(
" \t\n") );
650 size_t i = str.find_first_of(
" \t\n");
660 <<
"ParseCountConfig " << str
661 <<
" had " << nf <<
" args, expected something '" 664 << __FILE__ <<
":" << __LINE__
665 <<
" badDist '" << str <<
"'";
668 if ( distName.find(
"fix") == 0 || distName ==
"n" || distName ==
"n:" ) {
672 <<
"ParseCountConfig " << distName
673 <<
" had 2 args, expected 1: '" 674 << str <<
"', ignoring 2nd" <<
std::endl;
677 else if ( distName.find(
"flat") == 0 ) {
683 else if ( distName.find(
"poiss") == 0 ) {
688 <<
"ParseCountConfig " << distName
689 <<
" had 2 args, expected 1: '" 690 << str <<
"', ignoring 2nd" <<
std::endl;
693 else if ( distName.find(
"gaus") == 0 ) {
697 <<
"ParseCountConfig " << distName
698 <<
" had " << nf <<
" args, expected 2: '" 701 << __FILE__ <<
":" << __LINE__
702 <<
" badDist '" << distName <<
"'";
706 <<
"ParseCountConfig unknown distName " << distName
707 <<
" had' " << nf <<
" args '" 710 << __FILE__ <<
":" << __LINE__
711 <<
" unknown '" << distName <<
"'";
716 <<
" distName='" << distName <<
"' (int)" 717 << (
int)
fRndDist <<
"; cfgstr '" << str <<
"' --> " 723 static bool first =
true;
725 CLHEP::RandFlat flatTest(
fEngine);
727 for (
int rtest = 0; rtest < 5; ++rtest ) {
728 std::cout <<
" ======= testing CLHEP::RandFlat::fireInt(" 730 for (
int i=0; i<100; ++i)
731 std::cout <<
" " << flatTest.fireInt(rtest);
760 nchosen =
fRndP1 + flat.fireInt(range);
766 CLHEP::RandPoisson poisson(
fEngine);
767 nchosen = poisson.fire(
fRndP1);
769 if ( nchosen > 0 ) --nchosen;
773 <<
"] '" <<
fParams().timeConfig() <<
"' " 774 <<
" nchosen " << nchosen
775 <<
" can't subtract 1 for kPoissonMinus1" 785 if ( tmp > 0 ) nchosen = (size_t)(tmp);
790 <<
"] '" <<
fParams().timeConfig() <<
"' " 792 <<
"; can't return < 0 for kGaussian, return 0" 802 <<
"] '" <<
fParams().timeConfig() <<
"' not handled" 822 if( timeConfig.find_first_not_of(
" \t\n") != 0)
823 timeConfig.erase( 0, timeConfig.find_first_not_of(
" \t\n") );
825 size_t i = timeConfig.find_first_of(
": \t\n");
827 timeConfig.erase(0,i);
831 <<
" name='" << timeName <<
"'" 832 <<
" cfg='" << timeConfig <<
"'" <<
std::endl;
833 if ( timeName ==
"none" ) timeName =
"evgb::EvtTimeNone";
834 if ( timeName ==
"flat" ) timeName =
"evgb::EvtTimeFlat";
835 if ( timeName ==
"numi" || timeName ==
"NuMI"||
836 timeName ==
"fnal" || timeName ==
"FNAL" )
837 timeName =
"evgb::EvtTimeFNALBeam";
846 << __FILE__ <<
":" << __LINE__
847 <<
" unknown '" << timeName <<
"'";
static void SetPrintLevel(int print_level)
base_engine_t & createEngine(seed_t seed)
Atom< std::string > timeConfig
std::vector< std::string > fFileList
THE MAIN GENIE PROJECT NAMESPACE
Atom< double > globalTimeOffset
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void FillMCFlux(genie::GFluxI *fdriver, simb::MCFlux &mcflux)
MINOS-style ntuple record. Each such ntuple record holds a generated EventRecord object. Ntuples of this type are intended for feeding GENIE events into other applications (for example the GEANT4 based MC generation framework of an experiment) if no direct interface exists.
genie::flux::GSimpleNtpEntry * fGSimpleNtpEntry
enum evg::AddGenieEventsToArt::EDistrib RndDist_t
unsigned int GetRandomNumberSeed()
Sequence< std::string > fileList
std::string fMyModuleType
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
evgb::EvtTimeShiftI * fTimeShifter
CLHEP::HepRandomEngine & fEngine
std::string fMyModuleLabel
void ParseVtxOffsetConfig()
object containing MC flux information
Atom< std::string > countConfig
interface for event time distribution
AddGenieEventsToArt(const Parameters &p)
size_t GetNumToAdd() const
genie::flux::GSimpleNtpAux * fGSimpleNtpAux
bsim::NuChoice * fNuChoice
#define DEFINE_ART_MODULE(klass)
void swap(Handle< T > &a, Handle< T > &b)
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
QTextStream & flush(QTextStream &s)
auto const & get_PSet() const
std::ostream * fOutputStream
Atom< std::string > outputDumpFileName
Q_EXPORT QTSManip setw(int w)
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Atom< bool > randomEntries
void FillMCTruth(const genie::EventRecord *grec, double spillTime, simb::MCTruth &mctruth)
static PDGLibrary * Instance(void)
genie::NtpMCEventRecord * fMCRec
genie::flux::GSimpleNtpNuMI * fGSimpleNtpNuMI
static EvtTimeShiftFactory & Instance()
Table< VtxOffsets > vtxOffsets
virtual double TimeOffset()=0
void FillGTruth(const genie::EventRecord *grec, simb::GTruth >ruth)
Event generator information.
std::string fOutputDumpFileName
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
void produce(art::Event &e) override
genie::flux::GNuMIFluxPassThroughInfo * fGNuMIFluxPassThroughInfo
Atom< int > outputPrintLevel
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
evgb::EvtTimeShiftI * GetEvtTimeShift(const std::string &name, const std::string &config="") const