26 #include "TDirectory.h" 28 #include "TLorentzVector.h" 29 #include "TCollection.h" 35 #include "TStopwatch.h" 36 #include "TRotation.h" 39 #include "GENIE/Conventions/GVersion.h" 40 #include "GENIE/Conventions/Units.h" 41 #include "GENIE/EVGCore/EventRecord.h" 42 #include "GENIE/EVGDrivers/GMCJDriver.h" 43 #include "GENIE/GHEP/GHepUtils.h" 44 #include "GENIE/FluxDrivers/GCylindTH1Flux.h" 45 #include "GENIE/FluxDrivers/GMonoEnergeticFlux.h" 46 #include "GENIE/FluxDrivers/GNuMIFlux.h" 47 #include "GENIE/FluxDrivers/GSimpleNtpFlux.h" 48 #include "GENIE/FluxDrivers/GFluxDriverFactory.h" 49 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 50 #include "GENIE/FluxDrivers/GBGLRSAtmoFlux.h" 51 #include "GENIE/FluxDrivers/GFLUKAAtmoFlux.h" 53 #include "GENIE/FluxDrivers/GBartolAtmoFlux.h" 54 #include "GENIE/FluxDrivers/GFlukaAtmo3DFlux.h" 56 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,12,2) 57 #include "GENIE/FluxDrivers/GHAKKMAtmoFlux.h" 59 #include "GENIE/FluxDrivers/GAtmoFlux.h" 61 #pragma GCC diagnostic push 62 #pragma GCC diagnostic ignored "-Wunused-variable" 63 #include "GENIE/Conventions/Constants.h" 64 #pragma GCC diagnostic pop 66 #include "GENIE/PDG/PDGCodes.h" 67 #ifndef GENIE_USE_ENVVAR 68 #include "GENIE/Utils/AppInit.h" 69 #include "GENIE/Utils/RunOpt.h" 72 #include "GENIE/Geo/ROOTGeomAnalyzer.h" 73 #include "GENIE/Geo/GeomVolSelectorFiducial.h" 74 #include "GENIE/Geo/GeomVolSelectorRockBox.h" 75 #include "GENIE/Utils/StringUtils.h" 76 #include "GENIE/Utils/XmlParserUtils.h" 77 #include "GENIE/Interaction/InitialState.h" 78 #include "GENIE/Interaction/Interaction.h" 79 #include "GENIE/Interaction/Kinematics.h" 80 #include "GENIE/Interaction/KPhaseSpace.h" 81 #include "GENIE/Interaction/ProcessInfo.h" 82 #include "GENIE/Interaction/XclsTag.h" 83 #include "GENIE/GHEP/GHepParticle.h" 84 #include "GENIE/PDG/PDGCodeList.h" 86 #include "GENIE/FluxDrivers/GFluxBlender.h" 87 #include "GENIE/FluxDrivers/GFlavorMixerI.h" 88 #include "GENIE/FluxDrivers/GFlavorMap.h" 89 #include "GENIE/FluxDrivers/GFlavorMixerFactory.h" 92 #include "dk2nu/tree/dk2nu.h" 93 #include "dk2nu/tree/dkmeta.h" 94 #include "dk2nu/tree/NuChoice.h" 95 #include "dk2nu/genie/GDk2NuFlux.h" 114 #include "cetlib/search_path.h" 115 #include "cetlib/getenv.h" 116 #include "cetlib/split_path.h" 117 #include "cetlib_except/exception.h" 121 #include "cetlib_except/exception.h" 128 #define USE_IFDH_SERVICE 1 130 #ifdef USE_IFDH_SERVICE 131 #include "IFDH_service.h" 137 #undef USE_IFDH_SERVICE 153 TGeoManager* geoManager,
154 std::string
const& rootFile,
155 double const& detectorMass)
156 : fGeoManager (geoManager)
157 , fGeoFile (rootFile)
158 , fGenieEventRecord (0)
165 , fUseHelperRndGen4GENIE(pset.get< bool >(
"UseHelperRndGen4GENIE",true))
167 , fFluxType (pset.get<
std::string >(
"FluxType") )
168 , fFluxSearchPaths (pset.get<
std::string >(
"FluxSearchPaths",
"") )
169 , fFluxFilePatterns (pset.get<
std::
vector<
std::string> >(
"FluxFiles") )
170 , fMaxFluxFileMB (pset.get< int >(
"MaxFluxFileMB", 2000) )
171 , fMaxFluxFileNumber (pset.get< int >(
"MaxFluxFileNumber",9999) )
172 , fFluxCopyMethod (pset.get<
std::string >(
"FluxCopyMethod",
"DIRECT"))
173 , fFluxCleanup (pset.get<
std::string >(
"FluxCleanup",
"/var/tmp") )
174 , fBeamName (pset.get<
std::string >(
"BeamName") )
175 , fFluxRotCfg (pset.get<
std::string >(
"FluxRotCfg",
"none") )
176 , fFluxRotValues (pset.get<
std::
vector<double> >(
"FluxRotValues", {} ) )
178 ,
fTopVolume (pset.get< std::string >(
"TopVolume") )
180 ,
fDetLocation (pset.get< std::string >(
"DetectorLocation") )
183 ,
fPOTPerSpill (pset.get<
double >(
"POTPerSpill", 5.e13) )
188 ,
fMonoEnergy (pset.get<
double >(
"MonoEnergy", 2.0) )
191 ,
fEmin (pset.get<
double >(
"FluxEmin", 0) )
192 ,
fEmax (pset.get<
double >(
"FluxEmax", 10) )
193 ,
fBeamRadius (pset.get<
double >(
"BeamRadius", 3.0) )
199 ,
fGenFlavors (pset.get< std::vector<int> >(
"GenFlavors") )
200 ,
fAtmoEmin (pset.get<
double >(
"AtmoEmin", 0.1) )
201 ,
fAtmoEmax (pset.get<
double >(
"AtmoEmax", 10.0) )
202 ,
fAtmoRl (pset.get<
double >(
"Rl", 20.0) )
203 ,
fAtmoRt (pset.get<
double >(
"Rt", 20.0) )
204 ,
fEnvironment (pset.get< std::vector<std::string> >(
"Environment") )
205 ,
fXSecTable (pset.get< std::string >(
"XSecTable",
"") )
207 ,
fGXMLPATH (pset.get< std::string >(
"GXMLPATH",
"") )
208 ,
fGMSGLAYOUT (pset.get< std::string >(
"GMSGLAYOUT",
"") )
211 ,
fMixerConfig (pset.get< std::string >(
"MixerConfig",
"none") )
213 ,
fFiducialCut (pset.get< std::string >(
"FiducialCut",
"none") )
214 ,
fGeomScan (pset.get< std::string >(
"GeomScan",
"default") )
215 ,
fDebugFlags (pset.get<
unsigned int >(
"DebugFlags", 0) )
219 std::vector<double> beamCenter (pset.get< std::vector<double> >(
"BeamCenter") );
220 std::vector<double> beamDirection(pset.get< std::vector<double> >(
"BeamDirection"));
221 fBeamCenter.SetXYZ(beamCenter[0], beamCenter[1], beamCenter[2]);
222 fBeamDirection.SetXYZ(beamDirection[0], beamDirection[1], beamDirection[2]);
229 const char* gseedstr = std::getenv(
"GSEED");
231 dfltseed = strtol(gseedstr,NULL,0);
235 int seedval = pset.get<
int >(
"RandomSeed", dfltseed);
237 mf::LogInfo(
"GENIEHelper") <<
"Init HelperRandom with seed " << seedval;
242 size_t ftlead =
fFluxType.find_first_not_of(
" \t\n");
243 if ( ftlead )
fFluxType.erase( 0, ftlead );
245 size_t fttrail =
fFluxType.find_last_not_of(
" \t\n");
246 if ( fttrail != ftlen )
fFluxType.erase( fttrail+1, ftlen );
266 std::copy(fluxpattset.begin(),fluxpattset.end(),
300 #ifndef GENIE_USE_ENVVAR 305 mf::LogInfo(
"GENIEHelper") <<
"Init genie::utils::app_init::RandGen() with seed " << seedval;
306 genie::utils::app_init::RandGen(seedval);
311 mf::LogInfo(
"GENIEHelper") <<
"Init GSEED env with seed " << seedval;
316 std::ostringstream envlisttext;
317 envlisttext <<
"setting GENIE environment: ";
321 gSystem->Setenv(key.c_str(), val.c_str());
322 envlisttext <<
"\n " << key <<
" to \"" << val <<
"\"";
330 mf::LogInfo(
"GENIEHelper") <<
"ERROR: The number of generated neutrino flavors (" 331 <<
fGenFlavors.size() <<
") doesn't correspond to the number of files (" 335 std::ostringstream atmofluxmatch;
336 for (
size_t indx=0; indx <
fGenFlavors.size(); ++indx ) {
340 <<
"atmo flux assignment : \n" 341 << atmofluxmatch.str();
346 <<
"ERROR: For Atmosphric Neutrino generation, EventPerSpill need to be 1!!";
350 std::ostringstream atmofluxinfo;
352 if (
fFluxType.find(
"FLUKA") != std::string::npos ){
353 atmofluxinfo <<
" The fluxes are from FLUKA";
355 else if (
fFluxType.find(
"BARTOL") != std::string::npos ||
356 fFluxType.find(
"BGLRS") != std::string::npos ){
357 atmofluxinfo <<
" The fluxes are from BARTOL/BGLRS";
359 else if (
fFluxType.find(
"HONDA") != std::string::npos ||
360 fFluxType.find(
"HAKKM") != std::string::npos ){
361 atmofluxinfo <<
" The fluxes are from HONDA/HAKKM";
369 <<
" The energy range is between: " <<
fAtmoEmin <<
" GeV and " 373 <<
" Generation surface of: (" <<
fAtmoRl <<
"," 381 if (
fFluxType.compare(
"histogram") == 0 ){
382 mf::LogInfo(
"GENIEHelper") <<
"setting beam direction and center at " 387 TDirectory *savedir = gDirectory;
395 if(*flvitr == 12)
fFluxHistograms.push_back(dynamic_cast<TH1D *>(
tf.Get(
"nue")));
396 if(*flvitr == -12)
fFluxHistograms.push_back(dynamic_cast<TH1D *>(
tf.Get(
"nuebar")));
397 if(*flvitr == 14)
fFluxHistograms.push_back(dynamic_cast<TH1D *>(
tf.Get(
"numu")));
398 if(*flvitr == -14)
fFluxHistograms.push_back(dynamic_cast<TH1D *>(
tf.Get(
"numubar")));
399 if(*flvitr == 16)
fFluxHistograms.push_back(dynamic_cast<TH1D *>(
tf.Get(
"nutau")));
400 if(*flvitr == -16)
fFluxHistograms.push_back(dynamic_cast<TH1D *>(
tf.Get(
"nutaubar")));
408 mf::LogInfo(
"GENIEHelper") <<
"total histogram flux over desired flavors = " 415 flvlist += Form(
" %d",*itr);
422 <<
" GeV) neutrinos with the following flavors: " 427 std::string fileliststr;
429 fileliststr =
"NO FLUX FILES FOUND!";
435 fileliststr +=
"\n\t";
436 fileliststr += *sitr;
440 <<
"Generating flux with the following flavors: " << flvlist
441 <<
"\nand these file patterns: " << fileliststr;
447 <<
" events for each spill";
458 timeShiftFactory.
Print();
470 genie::geometry::ROOTGeomAnalyzer* rgeom =
471 dynamic_cast<genie::geometry::ROOTGeomAnalyzer*
>(
fGeomD);
473 string filename =
"maxpathlength.xml";
475 <<
"Saving MaxPathLengths as: \"" << filename <<
"\"";
477 const genie::PathLengthList& maxpath = rgeom->GetMaxPathLengths();
479 maxpath.SaveAsXml(filename);
481 std::ofstream mpfile(filename.c_str(), std::ios_base::app);
484 <<
"<!-- this file is only relevant for a setup compatible with:" 497 <<
"~GENIEHelper called, but previously failed to construct " 498 << ( (
fDriver) ?
"":
" genie::GMCJDriver" )
499 << ( (
fFluxD) ?
"":
" genie::GFluxI" );
502 double probscale =
fDriver->GlobProbScale();
504 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 508 genie::flux::GFluxExposureI* fexposure =
509 dynamic_cast<genie::flux::GFluxExposureI*
>(
fFluxD);
511 rawpots = fexposure->GetTotalExposure();
513 genie::flux::GFluxFileConfigI* ffileconfig =
514 dynamic_cast<genie::flux::GFluxFileConfigI*
>(
fFluxD);
516 ffileconfig->PrintConfig();
520 genie::flux::GNuMIFlux* numiFlux =
dynamic_cast<genie::flux::GNuMIFlux *
>(
fFluxD);
521 rawpots = numiFlux->UsedPOTs();
522 numiFlux->PrintConfig();
524 else if (
fFluxType.compare(
"simple") == 0 ) {
525 genie::flux::GSimpleNtpFlux* simpleFlux =
dynamic_cast<genie::flux::GSimpleNtpFlux *
>(
fFluxD);
526 rawpots = simpleFlux->UsedPOTs();
527 simpleFlux->PrintConfig();
529 else if (
fFluxType.compare(
"dk2nu") == 0 ) {
530 genie::flux::GDk2NuFlux* dk2nuFlux =
dynamic_cast<genie::flux::GDk2NuFlux *
>(
fFluxD);
531 rawpots = dk2nuFlux->UsedPOTs();
532 dk2nuFlux->PrintConfig();
538 <<
" GMCJDriver GlobProbScale " << probscale
539 <<
" FluxDriver base pots " << rawpots
540 <<
" corrected POTS " << rawpots/TMath::Max(probscale,1.0
e-100);
549 #ifdef USE_IFDH_SERVICE 556 std::string
ff = *ffitr;
557 if ( ff.find(
"/var/tmp") == 0 ) {
570 std::string
ff = *ffitr;
571 if ( ff.find(
"/var/tmp") == 0 ) {
603 fDriver =
new genie::GMCJDriver();
604 #ifndef GENIE_USE_ENVVAR 621 fDriver->ForceSingleProbScale();
634 mf::LogInfo(
"GENIEHelper") <<
"Number of events per spill will be based on poisson mean of " 653 double preUsedFluxPOTs = 0;
654 bool wasCleared =
true;
655 bool doprintpre =
false;
657 genie::flux::GNuMIFlux* gnumiflux =
658 dynamic_cast<genie::flux::GNuMIFlux *
>(
fFluxD);
659 preUsedFluxPOTs = gnumiflux->UsedPOTs();
660 if ( preUsedFluxPOTs > 0 ) {
662 gnumiflux->Clear(
"CycleHistory");
663 if ( gnumiflux->UsedPOTs() != 0 ) wasCleared =
false;
665 }
else if (
fFluxType.compare(
"simple") == 0 ) {
666 genie::flux::GSimpleNtpFlux* gsimpleflux =
667 dynamic_cast<genie::flux::GSimpleNtpFlux *
>(
fFluxD);
668 preUsedFluxPOTs = gsimpleflux->UsedPOTs();
669 if ( preUsedFluxPOTs > 0 ) {
671 gsimpleflux->Clear(
"CycleHistory");
672 if ( gsimpleflux->UsedPOTs() != 0 ) wasCleared =
false;
674 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 675 }
else if (
fFluxType.compare(
"dk2nu") == 0 ) {
676 genie::flux::GDk2NuFlux* dk2nuflux =
677 dynamic_cast<genie::flux::GDk2NuFlux *
>(
fFluxD);
678 preUsedFluxPOTs = dk2nuflux->UsedPOTs();
679 if ( preUsedFluxPOTs > 0 ) {
681 dk2nuflux->Clear(
"CycleHistory");
682 if ( dk2nuflux->UsedPOTs() != 0 ) wasCleared =
false;
687 double probscale =
fDriver->GlobProbScale();
689 <<
"Pre-Event Generation: " 690 <<
" FluxDriver base " << preUsedFluxPOTs
691 <<
" / GMCJDriver GlobProbScale " << probscale
692 <<
" = used POTS " << preUsedFluxPOTs/TMath::Max(probscale,1.0
e-100)
694 << (wasCleared?
"successfully":
"failed to") <<
" cleared count for " 703 genie::geometry::ROOTGeomAnalyzer *rgeom =
704 new genie::geometry::ROOTGeomAnalyzer(
fGeoManager);
709 int keep = ( geomFlags >> 7 );
711 <<
"InitializeGeometry set debug 0x" 712 << std::hex << geomFlags << std::dec
713 <<
" keepSegPath " << keep;
714 rgeom->SetDebugFlags(geomFlags);
715 if ( keep ) rgeom->SetKeepSegPath(
true);
722 rgeom->SetLengthUnits(genie::units::centimeter);
723 rgeom->SetDensityUnits(genie::units::gram_centimeter3);
725 rgeom->SetMixtureWeightsSum(1.);
727 <<
"GENIEHelper::InitializeGeometry using TopVolume '" 739 genie::GeomAnalyzerI* geom_driver =
fGeomD;
742 if( fidcut.find_first_not_of(
" \t\n") != 0)
743 fidcut.erase( 0, fidcut.find_first_not_of(
" \t\n") );
746 std::transform(fidcut.begin(),fidcut.end(),fidcut.begin(),::tolower);
748 if (
"" == fidcut ||
"none" == fidcut )
return;
750 if ( fidcut.find(
"rock") != string::npos ) {
785 genie::geometry::ROOTGeomAnalyzer * rgeom =
786 dynamic_cast<genie::geometry::ROOTGeomAnalyzer *
>(geom_driver);
789 <<
"Can not create GeomVolSelectorFiduction," 790 <<
" geometry driver is not ROOTGeomAnalyzer";
794 mf::LogInfo(
"GENIEHelper") <<
"fiducial cut: " << fidcut;
797 genie::geometry::GeomVolSelectorFiducial* fidsel =
798 new genie::geometry::GeomVolSelectorFiducial();
800 fidsel->SetRemoveEntries(
true);
802 vector<string> strtok = genie::utils::str::Split(fidcut,
":");
803 if ( strtok.size() != 2 ) {
805 <<
"Can not create GeomVolSelectorFiduction," 806 <<
" no \":\" separating type from values. nsplit=" << strtok.size();
807 for (
unsigned int i=0; i < strtok.size(); ++i )
809 <<
"strtok[" << i <<
"] = \"" << strtok[i] <<
"\"";
814 string stype = strtok[0];
815 bool reverse = ( stype.find(
"0") != string::npos );
816 bool master = ( stype.find(
"m") != string::npos );
820 vector<string> valstrs = genie::utils::str::Split(strtok[1],
" ,;(){}[]");
822 for ( ; iter != valstrs.end(); ++iter ) {
823 const string& valstr1 = *iter;
824 if ( valstr1 !=
"" ) vals.push_back(atof(valstr1.c_str()));
826 size_t nvals = vals.size();
828 for (
size_t nadd = 0; nadd < 7-nvals; ++nadd ) vals.push_back(0);
839 if ( stype.find(
"zcyl") != string::npos ) {
842 mf::LogError(
"GENIEHelper") <<
"MakeZCylinder needs 5 values, not " << nvals
843 <<
" fidcut=\"" << fidcut <<
"\"";
844 fidsel->MakeZCylinder(vals[0],vals[1],vals[2],vals[3],vals[4]);
846 }
else if ( stype.find(
"box") != string::npos ) {
849 mf::LogError(
"GENIEHelper") <<
"MakeBox needs 6 values, not " << nvals
850 <<
" fidcut=\"" << fidcut <<
"\"";
851 double xyzmin[3] = { vals[0], vals[1], vals[2] };
852 double xyzmax[3] = { vals[3], vals[4], vals[5] };
853 fidsel->MakeBox(xyzmin,xyzmax);
855 }
else if ( stype.find(
"zpoly") != string::npos ) {
858 mf::LogError(
"GENIEHelper") <<
"MakeZPolygon needs 7 values, not " << nvals
859 <<
" fidcut=\"" << fidcut <<
"\"";
860 int nfaces = (int)vals[0];
862 mf::LogError(
"GENIEHelper") <<
"MakeZPolygon needs nfaces>=3, not " << nfaces
863 <<
" fidcut=\"" << fidcut <<
"\"";
864 fidsel->MakeZPolygon(nfaces,vals[1],vals[2],vals[3],vals[4],vals[5],vals[6]);
866 }
else if ( stype.find(
"sphere") != string::npos ) {
869 mf::LogError(
"GENIEHelper") <<
"MakeZSphere needs 4 values, not " << nvals
870 <<
" fidcut=\"" << fidcut <<
"\"";
871 fidsel->MakeSphere(vals[0],vals[1],vals[2],vals[3]);
875 <<
"Can not create GeomVolSelectorFiduction for shape \"" << stype <<
"\"";
879 fidsel->ConvertShapeMaster2Top(rgeom);
880 mf::LogInfo(
"GENIEHelper") <<
"Convert fiducial volume from master to topvol coords";
883 fidsel->SetReverseFiducial(
true);
884 mf::LogInfo(
"GENIEHelper") <<
"Reverse sense of fiducial volume cut";
887 rgeom->AdoptGeomVolSelector(fidsel);
894 genie::GeomAnalyzerI* geom_driver =
fGeomD;
897 if( fidcut.find_first_not_of(
" \t\n") != 0)
898 fidcut.erase( 0, fidcut.find_first_not_of(
" \t\n") );
901 std::transform(fidcut.begin(),fidcut.end(),fidcut.begin(),::tolower);
903 genie::geometry::ROOTGeomAnalyzer * rgeom =
904 dynamic_cast<genie::geometry::ROOTGeomAnalyzer *
>(geom_driver);
907 <<
"Can not create GeomVolSelectorRockBox," 908 <<
" geometry driver is not ROOTGeomAnalyzer";
912 mf::LogInfo(
"GENIEHelper") <<
"fiducial (rock) cut: " << fidcut;
915 genie::geometry::GeomVolSelectorRockBox* rocksel =
916 new genie::geometry::GeomVolSelectorRockBox();
918 vector<string> strtok = genie::utils::str::Split(fidcut,
":");
919 if ( strtok.size() != 2 ) {
921 <<
"Can not create GeomVolSelectorRockBox," 922 <<
" no \":\" separating type from values. nsplit=" << strtok.size();
923 for (
unsigned int i=0; i < strtok.size(); ++i )
925 <<
"strtok[" << i <<
"] = \"" << strtok[i] <<
"\"";
929 string stype = strtok[0];
933 vector<string> valstrs = genie::utils::str::Split(strtok[1],
" ,;(){}[]\t\n\r");
935 for ( ; iter != valstrs.end(); ++iter ) {
936 const string& valstr1 = *iter;
937 if ( valstr1 !=
"" ) {
938 double aval = atof(valstr1.c_str());
939 mf::LogDebug(
"GENIEHelper") <<
"rock value [" << vals.size() <<
"] " 941 vals.push_back(aval);
944 size_t nvals = vals.size();
946 rocksel->SetRemoveEntries(
true);
955 <<
"least 6 values, found " 957 << strtok[1] <<
"\"";
960 double xyzmin[3] = { vals[0], vals[1], vals[2] };
961 double xyzmax[3] = { vals[3], vals[4], vals[5] };
963 bool rockonly =
true;
964 double wallmin = 800.;
965 double dedx = 2.5 * 1.7e-3;
968 if ( nvals >= 7 ) rockonly = vals[6];
969 if ( nvals >= 8 ) wallmin = vals[7];
970 if ( nvals >= 9 ) dedx = vals[8];
971 if ( nvals >= 10 ) fudge = vals[9];
973 rocksel->SetRockBoxMinimal(xyzmin,xyzmax);
974 rocksel->SetMinimumWall(wallmin);
975 rocksel->SetDeDx(dedx/fudge);
980 if ( ! rockonly ) rocksel->MakeSphere(0,0,0,1.0
e-10);
981 else rocksel->MakeBox(xyzmin,xyzmax);
983 rgeom->AdoptGeomVolSelector(rocksel);
990 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 994 std::string fluxName =
"";
996 if (
fFluxType.find(
"genie::flux::") != std::string::npos )
998 else if (
fFluxType.compare(
"numi") == 0 )
999 fluxName =
"genie::flux::GNuMIFlux";
1000 else if (
fFluxType.compare(
"simple") == 0 )
1001 fluxName =
"genie::flux::GSimpleNtpFlux";
1002 else if (
fFluxType.compare(
"dk2nu") == 0 )
1003 fluxName =
"genie::flux::GDk2NuFlux";
1004 if ( fluxName !=
"" ) {
1006 genie::flux::GFluxDriverFactory& fluxDFactory =
1007 genie::flux::GFluxDriverFactory::Instance();
1008 fFluxD = fluxDFactory.GetFluxDriver(fluxName);
1011 <<
"genie::flux::GFluxDriverFactory had not result for '" 1012 << fluxName <<
"' (fFluxType was '" <<
fFluxType <<
"'";
1018 genie::flux::GFluxFileConfigI* ffileconfig =
1019 dynamic_cast<genie::flux::GFluxFileConfigI*
>(
fFluxD);
1020 if ( ffileconfig ) {
1022 ffileconfig->PrintConfig();
1024 genie::PDGCodeList probes;
1026 probes.push_back(*flvitr);
1027 ffileconfig->SetFluxParticles(probes);
1035 genie::flux::GNuMIFlux* numiFlux =
new genie::flux::GNuMIFlux();
1037 #ifndef GFLUX_MISSING_SETORVECTOR 1045 <<
"LoadBeamSimData could use only first of " 1051 genie::PDGCodeList probes;
1053 probes.push_back(*flvitr);
1054 numiFlux->SetFluxParticles(probes);
1068 else if (
fFluxType.compare(
"simple") == 0 ) {
1070 genie::flux::GSimpleNtpFlux* simpleFlux =
1071 new genie::flux::GSimpleNtpFlux();
1073 #ifndef GFLUX_MISSING_SETORVECTOR 1081 <<
"LoadBeamSimData could use only first of " 1087 genie::PDGCodeList probes;
1089 probes.push_back(*flvitr);
1090 simpleFlux->SetFluxParticles(probes);
1098 if (
fFluxType.compare(
"histogram") == 0 ) {
1100 genie::flux::GCylindTH1Flux* histFlux =
new genie::flux::GCylindTH1Flux();
1116 else if (
fFluxType.compare(
"mono") == 0 ) {
1121 std::map<int, double> pdgwmap;
1123 pdgwmap[*i] = weight;
1125 genie::flux::GMonoEnergeticFlux *monoflux =
new genie::flux::GMonoEnergeticFlux(
fMonoEnergy, pdgwmap);
1130 else if (
fFluxType.compare(
"function") == 0 ) {
1132 genie::flux::GCylindTH1Flux* histFlux =
new genie::flux::GCylindTH1Flux();
1135 spectrum->Add(input_func);
1138 histFlux->AddEnergySpectrum(*i, spectrum);
1151 else if (
fFluxType.find(
"FLUKA") != std::string::npos ||
1152 fFluxType.find(
"BARTOL") != std::string::npos ||
1153 fFluxType.find(
"BGLRS") != std::string::npos ||
1154 fFluxType.find(
"HONDA") != std::string::npos ||
1155 fFluxType.find(
"HAKKM") != std::string::npos ) {
1158 genie::flux::GAtmoFlux *atmo_flux_driver = 0;
1160 if (
fFluxType.compare(
"atmo_FLUKA") == 0 ) {
1161 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 1162 genie::flux::GFLUKAAtmoFlux * fluka_flux =
1163 new genie::flux::GFLUKAAtmoFlux;
1165 genie::flux::GFlukaAtmo3DFlux * fluka_flux =
1166 new genie::flux::GFlukaAtmo3DFlux;
1168 atmo_flux_driver =
dynamic_cast<genie::flux::GAtmoFlux *
>(fluka_flux);
1170 if (
fFluxType.compare(
"atmo_BARTOL") == 0 ||
1171 fFluxType.compare(
"atmo_BGLRS") == 0 ) {
1172 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 1173 genie::flux::GBGLRSAtmoFlux * bartol_flux =
1174 new genie::flux::GBGLRSAtmoFlux;
1176 genie::flux::GBartolAtmoFlux * bartol_flux =
1177 new genie::flux::GBartolAtmoFlux;
1179 atmo_flux_driver =
dynamic_cast<genie::flux::GAtmoFlux *
>(bartol_flux);
1181 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,12,2) 1182 if (
fFluxType.compare(
"atmo_HONDA") == 0 ||
1183 fFluxType.compare(
"atmo_HAKKM") == 0 ) {
1184 genie::flux::GHAKKMAtmoFlux * honda_flux =
1185 new genie::flux::GHAKKMAtmoFlux;
1186 atmo_flux_driver =
dynamic_cast<genie::flux::GAtmoFlux *
>(honda_flux);
1190 atmo_flux_driver->ForceMinEnergy(
fAtmoEmin);
1191 atmo_flux_driver->ForceMaxEnergy(
fAtmoEmax);
1194 std::ostringstream atmoCfgText;
1195 atmoCfgText <<
"Configuration for " <<
fFluxType 1197 for (
size_t j = 0; j <
fGenFlavors.size(); ++j ) {
1200 atmo_flux_driver->AddFluxFile(flavor,flxfile);
1201 atmoCfgText <<
"\n FLAVOR: " << std::setw(3) << flavor
1202 <<
" FLUX FILE: " << flxfile;
1205 const int w=13, p=6;
1206 auto old_p = atmoCfgText.precision(p);
1207 atmoCfgText <<
"\n UserCoordSystem rotation:\n" 1220 atmoCfgText.precision(old_p);
1224 atmo_flux_driver->LoadFluxData();
1227 atmo_flux_driver->SetRadii(
fAtmoRl, fAtmoRt);
1229 fFluxD = atmo_flux_driver;
1234 <<
"Failed to contruct base flux driver for FluxType '" 1237 <<
"Failed to contruct base flux driver for FluxType '" 1239 << __FILE__ <<
":" << __LINE__ <<
"\n";
1249 if ( keyword !=
"none" ) {
1251 genie::flux::GFlavorMixerI* mixer = 0;
1254 if ( keyword ==
"map" || keyword ==
"swap" || keyword ==
"fixedfrac" )
1255 mixer =
new genie::flux::GFlavorMap();
1260 genie::flux::GFlavorMixerFactory& mixerFactory =
1261 genie::flux::GFlavorMixerFactory::Instance();
1262 mixer = mixerFactory.GetFlavorMixer(keyword);
1270 const std::vector<std::string>& knownMixers =
1271 mixerFactory.AvailableFlavorMixers();
1273 <<
" GFlavorMixerFactory known mixers: ";
1274 for (
unsigned int j=0; j < knownMixers.size(); ++j ) {
1276 <<
" [" << std::setw(2) << j <<
"] " << knownMixers[j];
1284 <<
"GENIEHelper MixerConfig keyword was \"" << keyword
1285 <<
"\" but that did not map to a class; " << std::endl
1286 <<
"GFluxBlender in use, but no mixer";
1289 genie::GFluxI* realFluxD =
fFluxD;
1290 genie::flux::GFluxBlender* blender =
new genie::flux::GFluxBlender();
1292 blender->AdoptFluxGenerator(realFluxD);
1293 blender->AdoptFlavorMixer(mixer);
1296 if ( mixer ) mixer->PrintConfig();
1297 blender->PrintConfig();
1298 std::cout << std::flush;
1310 if(
fGeomScan.find_first_not_of(
" \t\n") != 0)
1313 if (
fGeomScan.find(
"default") == 0 )
return;
1315 genie::geometry::ROOTGeomAnalyzer* rgeom =
1316 dynamic_cast<genie::geometry::ROOTGeomAnalyzer*
>(
fGeomD);
1320 <<
"genie::geometry::ROOTGeomAnalyzer*";
1326 vector<string> strtok = genie::utils::str::Split(
fGeomScan,
" ");
1328 string scanmethod = strtok[0];
1331 std::transform(scanmethod.begin(),scanmethod.end(),scanmethod.begin(),::tolower);
1333 if ( scanmethod.find(
"file") == 0 ) {
1335 string filename = strtok[1];
1336 string fullname = genie::utils::xml::GetXMLFilePath(filename);
1338 <<
"ConfigGeomScan getting MaxPathLengths from \"" << fullname <<
"\"";
1339 fDriver->UseMaxPathLengths(fullname);
1343 vector<double> vals;
1344 for (
size_t indx=1; indx < strtok.size(); ++indx ) {
1345 const string& valstr1 = strtok[indx];
1346 if ( valstr1 !=
"" ) vals.push_back(atof(valstr1.c_str()));
1348 size_t nvals = vals.size();
1350 for (
size_t nadd = 0; nadd < 4-nvals; ++nadd ) vals.push_back(0);
1352 double safetyfactor = 0;
1354 if ( scanmethod.find(
"box") == 0 ) {
1356 int np = (int)vals[0];
1357 int nr = (int)vals[1];
1358 if ( nvals >= 3 ) safetyfactor = vals[2];
1359 if ( nvals >= 4 ) writeout = vals[3];
1361 if ( np <= 10 ) np = rgeom->ScannerNPoints();
1362 if ( nr <= 10 ) nr = rgeom->ScannerNRays();
1364 <<
"ConfigGeomScan scan using box " << np <<
" points, " 1366 rgeom->SetScannerNPoints(np);
1367 rgeom->SetScannerNRays(nr);
1368 }
else if ( scanmethod.find(
"flux") == 0 ) {
1370 int np = (int)vals[0];
1371 if ( nvals >= 2 ) safetyfactor = vals[1];
1372 if ( nvals >= 3 ) writeout = vals[2];
1375 if ( abs(np) <= 100 ) {
1376 int npnew = rgeom->ScannerNParticles();
1377 if ( np < 0 ) npnew = -abs(npnew);
1379 <<
"Too few rays requested for geometry scan: " << np
1380 <<
", use: " << npnew <<
"instead";
1384 <<
"ConfigGeomScan scan using " << np <<
" flux particles" 1385 << ( (np>0) ?
"" :
" with ray energy pushed to flux driver maximum" );
1386 rgeom->SetScannerFlux(
fFluxD);
1387 rgeom->SetScannerNParticles(np);
1391 throw cet::exception(
"GENIEHelper") <<
"fGeomScan unknown method: \"" 1394 if ( safetyfactor > 0 ) {
1396 <<
"ConfigGeomScan setting safety factor to " << safetyfactor;
1397 rgeom->SetMaxPlSafetyFactor(safetyfactor);
1408 mf::LogInfo(
"GENIEHelper") <<
"about to create MaxPathOutInfo";
1425 mf::LogInfo(
"GENIEHelper") <<
"MaxPathOutInfo: \"" 1441 if (
fFluxType.compare(
"atmo_FLUKA") == 0 ||
fFluxType.compare(
"atmo_BARTOL") == 0 ||
1452 if ( (
fFluxType.compare(
"numi") == 0 ||
1456 else if (
fFluxType.compare(
"histogram") == 0 ){
1494 TRandom* old_gRandom = gRandom;
1502 bool viableInteraction =
true;
1509 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 1510 genie::flux::GFluxExposureI* fexposure =
1511 dynamic_cast<genie::flux::GFluxExposureI*
>(
fFluxD);
1525 else if (
fFluxType.compare(
"simple")==0 ) {
1534 if ( ! viableInteraction )
return false;
1536 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,11,0) 1569 if(
fFluxType.compare(
"histogram") == 0){
1578 std::vector<double> fluxes(6, 0.);
1590 flux.
SetFluxGen(fluxes[kNue], fluxes[kNueBar],
1591 fluxes[kNuMu], fluxes[kNuMuBar],
1592 fluxes[kNuTau], fluxes[kNuTauBar]);
1600 else if(
fFluxType.compare(
"atmo_FLUKA") == 0 ||
fFluxType.compare(
"atmo_BARTOL") == 0 ||
1610 TLorentzVector nuray_pos =
fFluxD->Position();
1611 TVector3 ray2vtx = nuray_pos.Vect() - vertex->Vect();
1612 flux.
fgenx = nuray_pos.X();
1613 flux.
fgeny = nuray_pos.Y();
1614 flux.
fgenz = nuray_pos.Z();
1617 genie::flux::GFluxBlender* blender =
1618 dynamic_cast<genie::flux::GFluxBlender*
>(
fFluxD2GMCJD);
1620 flux.
fdk2gen = blender->TravelDist();
1626 mf::LogInfo(
"GENIEHelper") <<
"vertex loc " << vertex->X() <<
"," 1627 << vertex->Y() <<
"," << vertex->Z() << std::endl
1628 <<
" flux ray start " << nuray_pos.X() <<
"," 1629 << nuray_pos.Y() <<
"," << nuray_pos.Z() << std::endl
1631 <<
" dk2ray = " << flux.
fdk2gen;
1649 genie::flux::GNuMIFlux *gnf =
dynamic_cast<genie::flux::GNuMIFlux *
>(
fFluxD);
1650 const genie::flux::GNuMIFluxPassThroughInfo& nflux = gnf->PassThroughInfo();
1655 if(nflux.pcodes != 1 && nflux.units != 0)
1656 mf::LogWarning(
"GENIEHelper") <<
"either wrong particle codes or units " 1657 <<
"from flux object - beware!!";
1662 flux.
frun = nflux.run;
1663 flux.
fevtno = nflux.evtno;
1664 flux.
fndxdz = nflux.ndxdz;
1665 flux.
fndydz = nflux.ndydz;
1666 flux.
fnpz = nflux.npz;
1676 flux.
fnorig = nflux.norig;
1678 flux.
fntype = nflux.ntype;
1679 flux.
fvx = nflux.vx;
1680 flux.
fvy = nflux.vy;
1681 flux.
fvz = nflux.vz;
1682 flux.
fpdpx = nflux.pdpx;
1683 flux.
fpdpy = nflux.pdpy;
1684 flux.
fpdpz = nflux.pdpz;
1687 flux.
fpppz = nflux.pppz;
1690 flux.
fptype = nflux.ptype;
1691 flux.
fppvx = nflux.ppvx;
1692 flux.
fppvy = nflux.ppvy;
1693 flux.
fppvz = nflux.ppvz;
1698 flux.
fnecm = nflux.necm;
1703 flux.
ftvx = nflux.tvx;
1704 flux.
ftvy = nflux.tvy;
1705 flux.
ftvz = nflux.tvz;
1706 flux.
ftpx = nflux.tpx;
1707 flux.
ftpy = nflux.tpy;
1708 flux.
ftpz = nflux.tpz;
1710 flux.
ftgen = nflux.tgen;
1712 flux.
ftgppx = nflux.tgppx;
1713 flux.
ftgppy = nflux.tgppy;
1714 flux.
ftgppz = nflux.tgppz;
1718 flux.
fbeamx = nflux.beamx;
1719 flux.
fbeamy = nflux.beamy;
1720 flux.
fbeamz = nflux.beamz;
1725 flux.
fdk2gen = gnf->GetDecayDist();
1735 TLorentzVector *
vertex = record->Vertex();
1739 genie::Interaction *inter = record->Summary();
1742 const genie::InitialState &initState = inter->InitState();
1743 const genie::ProcessInfo &procInfo = inter->ProcInfo();
1753 TIter partitr(record);
1754 genie::GHepParticle *
part = 0;
1759 std::string primary(
"primary");
1761 while( (part = dynamic_cast<genie::GHepParticle *>(partitr.Next())) ){
1766 part->FirstMother(),
1769 double vtx[4] = {part->
Vx(), part->Vy(), part->Vz(), part->Vt()};
1771 tpart.SetRescatter(part->RescatterCode());
1775 if(part->Status() == 0 || part->Status() == 1){
1776 vtx[0] = 100.*(part->Vx()*1.e-15 + vertex->X());
1777 vtx[1] = 100.*(part->Vy()*1.e-15 + vertex->Y());
1778 vtx[2] = 100.*(part->Vz()*1.e-15 + vertex->Z());
1779 vtx[3] = part->Vt() + spillTime;
1781 TLorentzVector pos(vtx[0], vtx[1], vtx[2], vtx[3]);
1782 TLorentzVector mom(part->Px(), part->Py(), part->Pz(), part->E());
1783 tpart.AddTrajectoryPoint(pos,mom);
1784 if(part->PolzIsSet()) {
1786 part->GetPolarization(polz);
1787 tpart.SetPolarization(polz);
1796 if(procInfo.IsWeakNC()) CCNC =
simb::kNC;
1801 if (procInfo.IsQuasiElastic() ) mode =
simb::kQE;
1802 else if(procInfo.IsDeepInelastic() ) mode =
simb::kDIS;
1803 else if(procInfo.IsResonant() ) mode =
simb::kRes;
1804 else if(procInfo.IsCoherent() ) mode =
simb::kCoh;
1813 else if(procInfo.IsMEC() ) mode =
simb::kMEC;
1815 else if(procInfo.IsEM() ) mode =
simb::kEM;
1823 #ifdef OLD_KINE_CALC 1829 genie::GHepParticle * hitnucl = record->HitNucleon();
1830 TLorentzVector pdummy(0, 0, 0, 0);
1831 const TLorentzVector & k1 = *((record->Probe())->P4());
1832 const TLorentzVector & k2 = *((record->FinalStatePrimaryLepton())->P4());
1835 double M = genie::constants::kNucleonMass;
1836 TLorentzVector q = k1-k2;
1837 double Q2 = -1 * q.M2();
1838 double v = (hitnucl) ? q.Energy() : -1;
1839 double x = (hitnucl) ? 0.5*Q2/(M*v) : -1;
1840 double y = (hitnucl) ? v/k1.Energy() : -1;
1841 double W2 = (hitnucl) ? M*M + 2*M*v - Q2 : -1;
1842 double W = (hitnucl) ? std::sqrt(W2) : -1;
1850 genie::GHepParticle * hitnucl = record->HitNucleon();
1851 const TLorentzVector & k1 = *((record->Probe())->P4());
1852 const TLorentzVector & k2 = *((record->FinalStatePrimaryLepton())->P4());
1856 TLorentzVector q = k1-k2;
1858 double Q2 = -1 * q.M2();
1859 double v = q.Energy();
1860 double y = v/k1.Energy();
1864 if ( hitnucl || procInfo.IsCoherent() ) {
1865 const double M = genie::constants::kNucleonMass;
1871 W2 = M*M + 2*M*v - Q2;
1879 initState.Tgt().Pdg(),
1880 initState.Tgt().HitNucPdg(),
1881 initState.Tgt().HitQrkPdg(),
1894 genie::Interaction *inter = record->Summary();
1895 const genie::ProcessInfo &procInfo = inter->ProcInfo();
1896 truth.
fGint = (int)procInfo.InteractionTypeId();
1897 truth.
fGscatter = (int)procInfo.ScatteringTypeId();
1900 truth.
fweight = record->Weight();
1902 truth.
fXsec = record->XSec();
1906 TLorentzVector *erVtx = record->Vertex();
1907 vtx.SetXYZT(erVtx->X(), erVtx->Y(), erVtx->Z(), erVtx->T() );
1912 const genie::XclsTag &exclTag = inter->ExclTag();
1913 truth.
fIsCharm = exclTag.IsCharmEvent();
1914 truth.
fResNum = (int)exclTag.Resonance();
1925 for (
int idx = 0; idx < record->GetEntries(); idx++) {
1927 const genie::GHepParticle * particle = record->Particle(idx);
1928 if (particle->Status() != genie::kIStHadronInTheNucleus)
1931 int pdg = particle->Pdg();
1932 if (pdg == genie::kPdgPi0)
1934 else if (pdg == genie::kPdgPiP)
1936 else if (pdg == genie::kPdgPiM)
1938 else if (pdg == genie::kPdgNeutron)
1940 else if (pdg == genie::kPdgProton)
1946 const genie::Kinematics &kine = inter->Kine();
1948 truth.
fgQ2 = kine.Q2(
true);
1949 truth.
fgq2 = kine.q2(
true);
1950 truth.
fgW = kine.W(
true);
1951 if ( kine.KVSet(genie::kKVSelt) ) {
1954 truth.
fgT = kine.t(
true);
1956 truth.
fgX = kine.x(
true);
1957 truth.
fgY = kine.y(
true);
1969 const genie::InitialState &initState = inter->InitState();
1971 truth.
fProbeP4 = *initState.GetProbeP4();
1974 const genie::Target &tgt = initState.Tgt();
1977 truth.
ftgtZ = tgt.Z();
1978 truth.
ftgtA = tgt.A();
1991 genie::flux::GSimpleNtpFlux *gsf =
dynamic_cast<genie::flux::GSimpleNtpFlux *
>(
fFluxD);
1996 const genie::flux::GSimpleNtpEntry* nflux_entry = gsf->GetCurrentEntry();
1997 const genie::flux::GSimpleNtpNuMI* nflux_numi = gsf->GetCurrentNuMI();
1999 flux.
fntype = nflux_entry->pdg;
2000 flux.
fnimpwt = nflux_entry->wgt;
2001 flux.
fdk2gen = nflux_entry->dist;
2005 flux.
frun = nflux_numi->run;
2006 flux.
fevtno = nflux_numi->evtno;
2007 flux.
ftpx = nflux_numi->tpx;
2008 flux.
ftpy = nflux_numi->tpy;
2009 flux.
ftpz = nflux_numi->tpz;
2010 flux.
ftptype = nflux_numi->tptype;
2011 flux.
fvx = nflux_numi->vx;
2012 flux.
fvy = nflux_numi->vy;
2013 flux.
fvz = nflux_numi->vz;
2015 flux.
fndecay = nflux_numi->ndecay;
2018 flux.
fpdpx = nflux_numi->pdpx;
2019 flux.
fpdpy = nflux_numi->pdpy;
2020 flux.
fpdpz = nflux_numi->pdpz;
2022 double apppz = nflux_numi->pppz;
2023 if ( TMath::Abs(nflux_numi->pppz) < 1.0e-30 ) apppz = 1.0e-30;
2024 flux.
fppdxdz = nflux_numi->pppx / apppz;
2025 flux.
fppdydz = nflux_numi->pppy / apppz;
2026 flux.
fpppz = nflux_numi->pppz;
2028 flux.
fptype = nflux_numi->ptype;
2035 const genie::flux::GSimpleNtpAux* nflux_aux = gsf->GetCurrentAux();
2036 const genie::flux::GSimpleNtpMeta* nflux_meta = gsf->GetCurrentMeta();
2037 if ( nflux_aux && nflux_meta ) {
2040 const std::vector<std::string>& auxdblname = nflux_meta->auxdblname;
2041 const std::vector<std::string>& auxintname = nflux_meta->auxintname;
2042 const std::vector<int>& auxint = nflux_aux->auxint;
2043 const std::vector<double>& auxdbl = nflux_aux->auxdbl;
2045 for (
size_t id=0;
id<auxdblname.size(); ++id) {
2046 if (
"muparpx" == auxdblname[
id]) flux.
fmuparpx = auxdbl[id];
2047 if (
"muparpy" == auxdblname[
id]) flux.
fmuparpy = auxdbl[id];
2048 if (
"muparpz" == auxdblname[
id]) flux.
fmuparpz = auxdbl[id];
2049 if (
"mupare" == auxdblname[
id]) flux.
fmupare = auxdbl[id];
2050 if (
"necm" == auxdblname[
id]) flux.
fnecm = auxdbl[id];
2051 if (
"nimpwt" == auxdblname[
id]) flux.
fnimpwt = auxdbl[id];
2052 if (
"fgXYWgt" == auxdblname[
id]) {
2056 for (
size_t ii=0; ii<auxintname.size(); ++ii) {
2057 if (
"tgen" == auxintname[ii]) flux.
ftgen = auxint[ii];
2058 if (
"tgptype" == auxintname[ii]) flux.
ftgptype = auxint[ii];
2065 static bool first =
true;
2069 <<
"GSimpleNtpMeta:\n" 2070 << *nflux_meta <<
"\n";
2073 <<
"simb::MCFlux:\n" 2075 <<
"GSimpleNtpFlux:\n" 2076 << *nflux_entry <<
"\n" 2077 << *nflux_numi <<
"\n" 2078 << *nflux_aux <<
"\n";
2131 flux.
fdk2gen = gsf->GetDecayDist();
2142 (
fFluxRotCfg.find(
"none") != std::string::npos ) )
return;
2146 bool verbose = (
fFluxRotCfg.find(
"verbose") != std::string::npos );
2148 std::ostringstream indata;
2149 indata <<
"BuildFluxRotation: Cfg \"" <<
fFluxRotCfg <<
"\"\n" 2150 <<
" " << nval <<
" values\n";
2151 for (
size_t i=0; i<nval; ++i) {
2152 indata <<
" [" << std::setw(2) << i <<
"] " <<
fFluxRotValues[i] <<
"\n";
2158 if (
fFluxRotCfg.find(
"newxyz") != std::string::npos ||
2171 fTempRot.RotateAxes(newX,newY,newZ);
2178 <<
" but nval=" << nval <<
", need 9";
2183 if (
fFluxRotCfg.find(
"series") != std::string::npos ) {
2186 std::vector<std::string> strs = genie::utils::str::Split(
fFluxRotCfg,
" ,;(){}[]");
2188 for (
size_t j=0; j<strs.size(); ++j) {
2189 std::string what = strs[j];
2190 if ( what ==
"" )
continue;
2192 std::transform(what.begin(),what.end(),what.begin(),::tolower);
2193 if ( what ==
"series" )
continue;
2194 if ( what ==
"verbose" )
continue;
2195 if ( what.find(
"rot") != 0 ) {
2197 <<
"processing series rotation saw keyword \"" << what <<
"\" -- ignoring";
2200 char axis = what[3];
2202 if ( axis !=
'x' && axis !=
'y' && axis !=
'z' ) {
2205 <<
" keyword '" << what <<
"': bad axis '" << axis <<
"'";
2207 std::string units = what.substr(4);
2209 if (units.size() > 3) units.erase(3);
2210 if ( units !=
"" && units !=
"rad" && units !=
"deg" ) {
2213 <<
" keyword '" << what <<
"': bad units '" << units <<
"'";
2216 double scale = (( units ==
"rad" ) ? 1.0 : TMath::DegToRad() );
2219 if ( nrot >= nval ) {
2223 <<
" asking for rotation [" << nrot <<
"] " 2224 << what <<
" but nval=" << nval;
2227 if ( axis ==
'x' ) fTempRot.RotateX(rot);
2228 if ( axis ==
'y' ) fTempRot.RotateY(rot);
2229 if ( axis ==
'z' ) fTempRot.RotateZ(rot);
2236 if ( nrot+1 != nval ) {
2239 <<
"BuildFluxRotation only used " << nrot+1 <<
" of " 2240 << nval <<
" FluxRotValues";
2249 <<
" nval=" << nval <<
", but don't know how to interpret that";
2267 <<
"ExpandFluxPaths initially: \"" << initial <<
"\"\n" 2289 #ifndef GFLUX_MISSING_SETORVECTOR 2293 std::vector<std::string> patternsWithFiles;
2294 std::vector<int> nfilesForPattern;
2295 int nfilesSoFar = 0;
2298 bool randomizeFiles =
false;
2301 fFluxType.compare(
"dk2nu") == 0 ) randomizeFiles =
true;
2303 std::vector<std::string> dirs;
2305 if ( dirs.empty() ) dirs.push_back(std::string());
2308 int flags = GLOB_TILDE;
2310 std::ostringstream patterntext;
2311 std::ostringstream dirstext;
2317 std::string userpattern = *uitr;
2318 patterntext <<
"\n\t" << userpattern;
2321 for ( ; ditr != dirs.end(); ++ditr ) {
2322 std::string dalt = *ditr;
2324 size_t len = dalt.size();
2325 if ( len > 0 && dalt.rfind(
'/') != len-1 ) dalt.append(
"/");
2328 std::string filepatt = dalt + userpattern;
2330 glob(filepatt.c_str(),flags,NULL,&g);
2331 if ( g.gl_pathc > 0 ) flags |= GLOB_APPEND;
2333 #ifndef GFLUX_MISSING_SETORVECTOR 2337 int nresolved = g.gl_pathc - nfilesSoFar;
2338 nfilesSoFar = g.gl_pathc;
2339 if ( nresolved > 0 ) {
2340 patternsWithFiles.push_back(filepatt);
2341 nfilesForPattern.push_back(nresolved);
2348 std::ostringstream paretext;
2349 std::ostringstream flisttext;
2351 #ifndef GFLUX_MISSING_SETORVECTOR 2352 int nfiles = g.gl_pathc;
2354 if ( nfiles == 0 ) {
2355 paretext <<
"\n expansion resulted in a null list for flux files";
2357 }
else if ( ! randomizeFiles ) {
2361 paretext <<
"\n list of files will be processed in order";
2362 for (
int i=0; i<nfiles; ++i) {
2363 std::string afile(g.gl_pathv[i]);
2366 flisttext <<
"[" << setw(3) << i <<
"] " 2375 paretext <<
"list of " << nfiles
2376 <<
" will be randomized and pared down to " 2380 double* order =
new double[nfiles];
2381 int*
indices =
new int[nfiles];
2385 TMath::Sort((
int)nfiles,order,indices,
false);
2387 long long int sumBytes = 0;
2388 long long int maxBytes = (
long long int)
fMaxFluxFileMB * 1024ll * 1024ll;
2391 for (
int i=0; i < TMath::Min(nfiles,fMaxFluxFileNumber); ++i) {
2392 int indx = indices[i];
2393 std::string afile(g.gl_pathv[indx]);
2396 gSystem->GetPathInfo(afile.c_str(),fstat);
2397 sumBytes += fstat.fSize;
2400 if ( sumBytes > maxBytes && i != 0 ) keep =
false;
2402 flisttext <<
"[" << setw(3) << i <<
"] " 2403 <<
"=> g[" << setw(3) << indx <<
"] " 2404 << ((keep)?
"keep":
"skip") <<
" " 2405 << setw(6) << (sumBytes/(1024ll*1024ll)) <<
" " 2420 int npatt = patternsWithFiles.size();
2422 flisttext <<
"ExpandFluxFilePatternsDirect: " << npatt
2423 <<
" user patterns resolved to files:\n";
2425 const int* nf = &(nfilesForPattern[0]);
2426 int*
indices =
new int[npatt];
2427 TMath::Sort(npatt,nf,indices,
true);
2428 for (
int i=0; i<npatt; ++i) {
2429 int indx = indices[i];
2430 flisttext <<
"[" << i <<
"] " << nfilesForPattern[indx]
2431 <<
" files in " << patternsWithFiles[indx] <<
"\n";
2439 <<
"ExpandFluxFilePatternsDirect initially found " << nfiles
2440 <<
" files for user patterns:" 2441 << patterntext.str() <<
"\n using FluxSearchPaths of: " 2442 << dirstext.str() <<
"\n" << paretext.str();
2445 mf::LogDebug(
"GENIEHelper") <<
"\n" << flisttext.str();
2455 if ( nfiles == 0 ) {
2457 <<
"For \"dk2nu\', \"ntuple\" (\"numi\") or \"simple_flux\"," 2458 <<
" specification must resolve to at least one file" 2459 <<
"\n none were found user pattern: " 2460 << patterntext.str()
2461 <<
"\n using FluxSearchPaths of: " 2465 <<
"no flux files found for: " << patterntext.str() <<
"\n" 2466 <<
" in: " << dirstext.str();
2490 std::ostringstream fmesg;
2491 std::string marker =
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";
2493 << __FILE__ <<
":" << __LINE__
2494 <<
"\nno IFDH implemented on this platform\n" 2497 std::cout << fmesg.str() << std::flush;
2498 std::cerr << fmesg.str();
2499 throw cet::exception(
"Attempt to use ifdh class") << fmesg.str();
2505 bool randomizeFiles =
false;
2508 fFluxType.compare(
"dk2nu") == 0 ) randomizeFiles =
true;
2510 #ifdef USE_IFDH_SERVICE 2518 const char* ifdh_debug_env = std::getenv(
"IFDH_DEBUG_LEVEL");
2519 if ( ifdh_debug_env ) {
2520 mf::LogInfo(
"GENIEHelper") <<
"IFDH_DEBUG_LEVEL: " << ifdh_debug_env;
2521 fIFDH->set_debug(ifdh_debug_env);
2525 std::vector<std::pair<std::string,long>>
2526 partiallist, fulllist, selectedlist, locallist;
2528 std::ostringstream patterntext;
2529 std::ostringstream fulltext;
2530 std::ostringstream selectedtext;
2531 std::ostringstream localtext;
2532 fulltext <<
"search paths: " << spaths;
2541 std::string userpattern = *uitr;
2542 patterntext <<
"\npattern [" << std::setw(3) << ipatt <<
"] " << userpattern;
2543 fulltext <<
"\npattern [" << std::setw(3) << ipatt <<
"] " << userpattern;
2545 #ifdef USE_IFDH_SERVICE 2546 partiallist = ifdhp->findMatchingFiles(spaths,userpattern);
2548 partiallist =
fIFDH->findMatchingFiles(spaths,userpattern);
2550 fulllist.insert(fulllist.end(),partiallist.begin(),partiallist.end());
2553 fulltext <<
" found " << partiallist.size() <<
" files";
2554 for (
auto pitr = partiallist.begin(); pitr != partiallist.end(); ++pitr) {
2555 fulltext <<
"\n " << std::setw(10) << pitr->second <<
" " << pitr->first;
2558 partiallist.clear();
2561 size_t nfiles = fulllist.size();
2564 <<
"ExpandFluxFilePatternsIFDH initially found " << nfiles <<
" files";
2568 if ( nfiles == 0 ) {
2569 selectedtext <<
"\n expansion resulted in a null list for flux files";
2570 }
else if ( ! randomizeFiles ) {
2574 selectedtext <<
"\n list of files will be processed in order";
2575 selectedlist.insert(selectedlist.end(),fulllist.begin(),fulllist.end());
2584 selectedtext <<
"list of " << nfiles
2585 <<
" will be randomized and pared down to " 2589 double* order =
new double[nfiles];
2590 int*
indices =
new int[nfiles];
2594 TMath::Sort((
int)nfiles,order,indices,
false);
2596 long long int sumBytes = 0;
2597 long long int maxBytes = (
long long int)
fMaxFluxFileMB * 1024ll * 1024ll;
2599 for (
size_t i=0; i < TMath::Min(nfiles,
size_t(fMaxFluxFileNumber)); ++i) {
2600 int indx = indices[i];
2603 auto p = fulllist[indx];
2604 sumBytes += p.second;
2607 if ( sumBytes > maxBytes && i != 0 ) keep =
false;
2609 selectedtext <<
"\n[" << setw(3) << i <<
"] " 2610 <<
"=> [" << setw(3) << indx <<
"] " 2611 << ((keep)?
"keep":
"SKIP") <<
" " 2612 << std::setw(6) << (sumBytes/(1024ll*1024ll)) <<
" MB " 2615 if ( keep ) selectedlist.push_back(p);
2624 << selectedtext.str();
2628 #ifdef USE_IFDH_SERVICE 2634 localtext <<
"final list of files:";
2636 for (
auto litr = locallist.begin(); litr != locallist.end(); ++litr, ++i) {
2638 localtext <<
"\n\t[" << std::setw(3) << i <<
"]\t" << litr->first;
2649 if ( nfiles == 0 ) {
2651 <<
"For \"ntuple\" or \"simple_flux\", specification " 2652 <<
"must resolve to at least one file" 2653 <<
"\n none were found user pattern(s): " 2654 << patterntext.str()
2655 <<
"\n using FW_SEARCH_PATH of: " 2659 <<
"no flux files found for: " << patterntext.str();
2663 #endif // 'else' code only if NO_IFDH_LIB not defined 2682 int indxGXMLPATH = -1;
2692 const char* gxmlpath_env = std::getenv(
"GXMLPATH");
2693 if ( gxmlpath_env ) {
2697 const char* fwpath_env = std::getenv(
"FW_SEARCH_PATH");
2704 if ( indxGXMLPATH < 0 ) {
2715 gSystem->Setenv(
"GXMLPATH",
fGXMLPATH.c_str());
2739 gSystem->Setenv(
"GMSGLAYOUT",
fGMSGLAYOUT.c_str());
2754 int indxGPRODMODE = -1;
2755 int indxGMSGCONF = -1;
2768 if ( indxGMSGCONF >= 0 ) {
2779 if ( indxGPRODMODE >= 0 ) {
2788 #if __GENIE_RELEASE_CODE__ >= GRELCODE(2,9,0) 2789 std::string newval =
"Messenger_whisper.xml";
2791 std::string newval =
"Messenger_production.xml";
2801 if ( indxGMSGCONF >= 0 ) {
2806 <<
"StartGENIEMessenger ProdMode=" << ((prodmode)?
"yes":
"no")
2808 #ifndef GENIE_USE_ENVVAR 2812 if ( prodmode ) gSystem->Setenv(
"GPRODMODE",
"YES");
2836 mf::LogInfo(
"GENIEHelper") <<
"GENIE EventGeneratorList using \"" 2838 #ifndef GENIE_USE_ENVVAR 2861 const char* gspload_alt = std::getenv(
"GSPLOAD");
2862 if ( ! gspload_alt ) {
2863 const char* gspload_dflt =
"gxspl-FNALsmall.xml";
2864 gspload_alt = gspload_dflt;
2870 int indxGSPLOAD = -1;
2878 if ( indxGSPLOAD < 0 ) {
2897 cet::search_path spGXML(
"/:" +
fGXMLPATH );
2898 std::string fullpath;
2901 if ( fullpath ==
"" ) {
2903 <<
"could not resolve full path for spline file XSecTable/GSPLOAD " 2907 <<
"can't find XSecTable/GSPLOAD file: " <<
fXSecTable;
2913 <<
"XSecTable/GSPLOAD full path \"" <<
fXSecTable <<
"\"";
2915 #ifndef GENIE_USE_ENVVAR 2920 unsetenv(
"GSPLOAD");
2921 genie::utils::app_init::XSecTable(
fXSecTable,
true);
2925 <<
"Time to read GENIE XSecTable: " 2926 <<
" Real " << xtime.RealTime() <<
" s," 2927 <<
" CPU " << xtime.CpuTime() <<
" s" 2931 gSystem->Setenv(
"GSPLOAD",
fXSecTable.c_str());
2939 if (v ==
"true")
return true;
2940 if (v ==
"false")
return false;
2941 if (v ==
"kTRUE")
return true;
2942 if (v ==
"kFALSE")
return false;
2943 if (v ==
"TRUE")
return true;
2944 if (v ==
"FALSE")
return false;
2945 if (v ==
"True")
return true;
2946 if (v ==
"False")
return false;
2947 if (v ==
"on")
return true;
2948 if (v ==
"off")
return false;
2949 if (v ==
"On")
return true;
2950 if (v ==
"Off")
return false;
2951 if (v ==
"ON")
return true;
2952 if (v ==
"OFF")
return false;
2953 if (v ==
"YES")
return true;
2954 if (v ==
"NO")
return false;
2955 if (v ==
"Yes")
return true;
2956 if (v ==
"No")
return false;
2957 if (v ==
"yes")
return true;
2958 if (v ==
"no")
return false;
2959 if (v ==
"1")
return true;
2960 if (v ==
"0")
return false;
double E(const int i=0) const
int fGint
interaction code
std::vector< std::string > fFluxFilePatterns
wildcard patterns files containing histograms or ntuples, or txt
static const int kNuTauBar
bool fUseHelperRndGen4GENIE
use fHelperRandom for gRandom during Sample()
const simb::MCNeutrino & GetNeutrino() const
std::string fDetLocation
name of flux window location
double fAtmoEmax
atmo: Maximum energy of neutrinos in GeV
int fMaxFluxFileNumber
maximum # of flux files
double fMixerBaseline
baseline distance if genie flux can't calculate it
Full flux simulation ntuple.
void SetOrigin(simb::Origin_t origin)
neutrino electron elastic scatter
double fTotalHistFlux
total flux of neutrinos from flux histograms for used flavors
double fgen2vtx
distance from ray origin to event vtx
void PackSimpleFlux(simb::MCFlux &flux)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
ifdh_ns::ifdh * fIFDH
(optional) flux file handling
void FillMCFlux(genie::GFluxI *fdriver, simb::MCFlux &mcflux)
std::string fGXMLPATH
locations for GENIE XML files
std::string fFiducialCut
configuration for geometry selector
void PackNuMIFlux(simb::MCFlux &flux)
const simb::MCParticle & Nu() const
double fgenx
origin of ray from flux generator
bool Sample(simb::MCTruth &truth, simb::MCFlux &flux, simb::GTruth >ruth)
simb::flux_code_ fFluxType
unsigned int GetRandomNumberSeed()
double fRandomTimeOffset
additional random time shift (ns) added to every particle time
TVector3 fBeamCenter
center of beam for histogram fluxes - must be in meters
double fGlobalTimeOffset
overall time shift (ns) added to every particle time
int fNumNeutron
number of neutrons after reaction, before FSI
std::string fSpillTimeConfig
alternative to flat spill distribution
std::string fEventGeneratorList
control over event topologies, was $GEVGL [Default]
TGeoManager * fGeoManager
pointer to ROOT TGeoManager
double fXsec
cross section of interaction
void FindEventGeneratorList()
Functions for transforming GENIE objects into ART objects (and back)
std::string fGENIEMsgThresholds
additional XML file setting Messager level thresholds (":" separated)
int fNumPiPlus
number of pi pluses after reaction, before FSI
offset to account for adding in Nuance codes to this enum
int fNumPiMinus
number of pi minuses after reaction, before FSI
std::vector< int > fGenFlavors
pdg codes for flavors to generate
void SetNeutrino(int CCNC, int mode, int interactionType, int target, int nucleon, int quark, double w, double x, double y, double qsqr)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
evgb::EvtTimeShiftI * fTimeShifter
generator for time offset within a spill
double fdk2gen
distance from decay to ray origin
void Add(simb::MCParticle &part)
genie::GMCJDriver * fDriver
double fXSecMassPOT
product of cross section, mass and POT/spill for histogram fluxes
void ExpandFluxFilePatternsDirect()
std::vector< std::string > fSelectedFluxFiles
flux files selected after wildcard expansion and subset selection
object containing MC flux information
genie::EventRecord * fGenieEventRecord
last generated event
std::string fXSecTable
cross section file (was $GSPLOAD)
double fFluxUpstreamZ
z where flux starts from (if non-default, simple/ntuple only)
std::vector< TH1D * > fFluxHistograms
histograms for each nu species
Flux for positive horn focus.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
int fResNum
resonance number
int fNumProton
number of protons after reaction, before FSI
double fprobability
interaction probability
int fGHepPrintLevel
GHepRecord::SetPrintLevel(), -1=no-print.
std::string fFluxRotCfg
how to interpret fFluxRotValues
TVector3 fBeamDirection
direction of the beam for histogram fluxes
std::string fBeamName
name of the beam we are simulating
std::string fWorldVolume
name of the world volume in the ROOT geometry
int fGscatter
neutrino scattering code
void InitializeFluxDriver()
double fTotalExposure
pot used from flux ntuple
TRandom3 * fHelperRandom
random # generator for GENIEHelper
int fNumPi0
number of pi0 after reaction, before FSI
std::string fTopVolume
top volume in the ROOT geometry in which to generate events
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
virtual void PrintConfig(bool verbose=true)=0
provide a means of printing the configuration
bool fIsCharm
did the interaction produce a charmed hadron?
double fweight
event interaction weight (genie internal)
static const int kNuMuBar
genie::GeomAnalyzerI * fGeomD
std::string fFluxSearchPaths
colon separated set of path stems
Wrapper for generating neutrino interactions with GENIE.
std::string fGMSGLAYOUT
format for GENIE log message [BASIC]|SIMPLE (SIMPLE=no timestamps)
void InitializeGeometry()
double fBeamRadius
radius of cylindar for histogram fluxes - must be in meters
std::string fMixerConfig
configuration string for genie GFlavorMixerI
bool StringToBool(std::string v)
genie::GFluxI * fFluxD
real flux driver
void StartGENIEMessenger(std::string prodmode)
void SetFluxGen(double nue, double nuebar, double numu, double numubar, double nutau, double nutaubar)
double Vx(const int i=0) const
double fMonoEnergy
energy of monoenergetic neutrinos
double fDetectorMass
mass of the detector in kg
std::vector< double > fFluxRotValues
parameters for rotation
void FillMCTruth(const genie::EventRecord *grec, double spillTime, simb::MCTruth &mctruth)
void PackGTruth(genie::EventRecord *record, simb::GTruth &truth)
n.b.: this group is similar but not quite, entirely unlike GENIE ScatteringType convention ...
void InitializeFiducialSelection()
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
std::vector< std::string > fEnvironment
environmental variables and settings used by genie
int ftgtPDG
PDG of Target Nucleus, nucleon only if free.
double fgQ2
< these are for the internal (on shell) genie kinematics
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::string fMaxPathOutInfo
output info if writing PathLengthList from GeomScan
double fSpillExposure
total exposure (i.e. pot) for this spill
A class for generating concrete EvtTimeShiftI derived classes based on the factory pattern...
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TLorentzVector fFShadSystP4
double fAtmoEmin
atmo: Minimum energy of neutrinos in GeV
static EvtTimeShiftFactory & Instance()
std::string fGeoFile
name of file containing the Geometry description
void InitializeRockBoxSelection()
double fAtmoRl
atmo: radius of the sphere on where the neutrinos are generated
void ExpandFluxFilePatternsIFDH()
unsigned int fDebugFlags
set bits to enable debug info
virtual double TimeOffset()=0
Physics generators for neutrinos, cosmic rays, and others.
std::string fFluxCopyMethod
"DIRECT" = old direct access method, otherwise = ifdh approach schema ("" okay)
void FillGTruth(const genie::EventRecord *grec, simb::GTruth >ruth)
std::string fFluxCleanup
"ALWAYS", "/var/tmp", "NEVER"
Event generator information.
double fHistEventsPerSpill
number of events per spill for histogram fluxes - changes each spill
TRotation * fFluxRotation
rotation for atmos / astro flux coord systems
std::string fGeomScan
configuration for geometry scan to determine max pathlengths
int fSpillEvents
total events for this spill
genie::GFluxI * fFluxD2GMCJD
flux driver passed to genie GMCJDriver, might be GFluxBlender
double fDiffXsec
differential cross section of interaction
std::string fFunctionalFlux
int fMaxFluxFileMB
maximum size of flux files (MB)
void PackMCTruth(genie::EventRecord *record, simb::MCTruth &truth)
double fPOTPerSpill
number of pot per spill
A simplified flux ntuple for quick running.
cet::coded_exception< error, detail::translate > exception
GENIEHelper(fhicl::ParameterSet const &pset, TGeoManager *rootGeom, std::string const &rootFile, double const &detectorMass)
evgb::EvtTimeShiftI * GetEvtTimeShift(const std::string &name, const std::string &config="") const