Functions | Variables
gEvGenLArDM.cxx File Reference
#include <cassert>
#include <cstdlib>
#include <csignal>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include <TSystem.h>
#include <TError.h>
#include <TTree.h>
#include <TFile.h>
#include <TH1D.h>
#include <TMath.h>
#include <TGeoVolume.h>
#include <TGeoShape.h>
#include "Framework/Algorithm/AlgConfigPool.h"
#include "Framework/Conventions/Units.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/EventGen/GFluxI.h"
#include "Framework/EventGen/GMCJDriver.h"
#include "Framework/EventGen/GMCJMonitor.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/Ntuple/NtpWriter.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/ParticleData/PDGCodeList.h"
#include "Framework/Ntuple/NtpMCFormat.h"
#include "Framework/Utils/XSecSplineList.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/UnitUtils.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/CmdLnArgParser.h"
#include "Framework/Utils/PrintUtils.h"
#include "Framework/Utils/SystemUtils.h"

Go to the source code of this file.

Functions

void LoadExtraOptions (void)
 
void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
void CreateFidSelection (string fidcut, GeomAnalyzerI *geom_driver)
 
void CreateRockBoxSelection (string fidcut, GeomAnalyzerI *geom_driver)
 
void DetermineFluxDriver (string fopt)
 
void ParseFluxHst (string fopt)
 
void ParseFluxFileConfig (string fopt)
 
static void gsSIGTERMhandler (int)
 
int main (int argc, char **argv)
 

Variables

string kDefOptGeomLUnits = "mm"
 
string kDefOptGeomDUnits = "g_cm3"
 
NtpMCFormat_t kDefOptNtpFormat = kNFGHEP
 
string kDefOptEvFilePrefix = "gntp"
 
double gOptZpCoupling
 
double gOptDMMass
 
double gOptMedRatio
 
Long_t gOptRunNu
 
bool gOptUsingRootGeom = false
 
map< int, double > gOptTgtMix
 
string gOptRootGeom
 
string gOptRootGeomTopVol = ""
 
string gOptRootGeomMasterVol = ""
 
double gOptGeomLUnits = 0
 
double gOptGeomDUnits = 0
 
string gOptExtMaxPlXml = ""
 
bool gOptWriteMaxPlXml = false
 
string gOptFluxFile
 
int gOptNev
 
string gOptFidCut
 
int gOptNScan = 0
 
double gOptZmin = -2.0e30
 
string gOptEvFilePrefix
 
int gOptDebug = 0
 
long int gOptRanSeed
 
string gOptInpXSecFile
 
bool gSigTERM = false
 

Function Documentation

void CreateFidSelection ( string  fidcut,
GeomAnalyzerI geom_driver 
)

User defined fiducial volume cut [0][M]<SHAPE>:val1,val2,... "0" means reverse the cut (i.e. exclude the volume) "M" means the coordinates are given in the ROOT geometry "master" system and need to be transformed to "top vol" system <SHAPE> can be any of "zcyl" "box" "zpoly" "sphere" [each takes different # of args] This must be followed by a ":" and a list of values separated by punctuation (allowed separators: commas , parentheses () braces {} or brackets [] ) Value mapping: zcly:x0,y0,radius,zmin,zmax - cylinder along z at (x0,y0) capped at z's box:xmin,ymin,zmin,xmax,ymax,zmax - box w/ upper & lower extremes zpoly:nfaces,x0,y0,r_in,phi,zmin,zmax - nfaces sided polygon in x-y plane

Examples: 1) 0mbox:0,0,0.25,1,1,8.75 exclude (i.e. reverse) a box in master coordinates w/ corners (0,0,0.25) (1,1,8.75) 2) mzpoly:6,(2,-1),1.75,0,{0.25,8.75} six sided polygon in x-y plane, centered at x,y=(2,-1) w/ inscribed radius 1.75 no rotation (so first face is in y-z plane +r from center, i.e. hex sits on point) limited to the z range of {0.25,8.75} in the master ROOT geom coordinates 3) zcly:(3,4),5.5,-2,10 a cylinder oriented parallel to the z axis in the "top vol" coordinates at x,y=(3,4) with radius 5.5 and z range of {-2,10}

Definition at line 1117 of file gEvGenLArDM.cxx.

1118 {
1119  ///
1120  /// User defined fiducial volume cut
1121  /// [0][M]<SHAPE>:val1,val2,...
1122  /// "0" means reverse the cut (i.e. exclude the volume)
1123  /// "M" means the coordinates are given in the ROOT geometry
1124  /// "master" system and need to be transformed to "top vol" system
1125  /// <SHAPE> can be any of "zcyl" "box" "zpoly" "sphere"
1126  /// [each takes different # of args]
1127  /// This must be followed by a ":" and a list of values separated by punctuation
1128  /// (allowed separators: commas , parentheses () braces {} or brackets [] )
1129  /// Value mapping:
1130  /// zcly:x0,y0,radius,zmin,zmax - cylinder along z at (x0,y0) capped at z's
1131  /// box:xmin,ymin,zmin,xmax,ymax,zmax - box w/ upper & lower extremes
1132  /// zpoly:nfaces,x0,y0,r_in,phi,zmin,zmax - nfaces sided polygon in x-y plane
1133  // sphere:x0,y0,z0,radius - sphere of fixed radius at (x0,y0,z0)
1134  /// Examples:
1135  /// 1) 0mbox:0,0,0.25,1,1,8.75
1136  /// exclude (i.e. reverse) a box in master coordinates w/ corners (0,0,0.25) (1,1,8.75)
1137  /// 2) mzpoly:6,(2,-1),1.75,0,{0.25,8.75}
1138  /// six sided polygon in x-y plane, centered at x,y=(2,-1) w/ inscribed radius 1.75
1139  /// no rotation (so first face is in y-z plane +r from center, i.e. hex sits on point)
1140  /// limited to the z range of {0.25,8.75} in the master ROOT geom coordinates
1141  /// 3) zcly:(3,4),5.5,-2,10
1142  /// a cylinder oriented parallel to the z axis in the "top vol" coordinates
1143  /// at x,y=(3,4) with radius 5.5 and z range of {-2,10}
1144  ///
1145  geometry::ROOTGeomAnalyzer * rgeom =
1146  dynamic_cast<geometry::ROOTGeomAnalyzer *>(geom_driver);
1147  if ( ! rgeom ) {
1148  LOG("gevgen_lardm", pWARN)
1149  << "Can not create GeomVolSelectorFiduction,"
1150  << " geometry driver is not ROOTGeomAnalyzer";
1151  return;
1152  }
1153 
1154  LOG("gevgen_lardm", pNOTICE) << "-F " << fidcut;
1155 
1158 
1159  fidsel->SetRemoveEntries(true); // drop segments that won't be considered
1160 
1161  // convert string to lowercase
1162  std::transform(fidcut.begin(),fidcut.end(),fidcut.begin(),::tolower);
1163 
1164  vector<string> strtok = genie::utils::str::Split(fidcut,":");
1165  if ( strtok.size() != 2 ) {
1166  LOG("gevgen_lardm", pWARN)
1167  << "Can not create GeomVolSelectorFiduction,"
1168  << " no \":\" separating type from values. nsplit=" << strtok.size();
1169  for ( unsigned int i=0; i < strtok.size(); ++i )
1170  LOG("gevgen_lardm",pNOTICE)
1171  << "strtok[" << i << "] = \"" << strtok[i] << "\"";
1172  return;
1173  }
1174 
1175  // parse out optional "x" and "m"
1176  string stype = strtok[0];
1177  bool reverse = ( stype.find("0") != string::npos );
1178  bool master = ( stype.find("m") != string::npos ); // action after values are set
1179 
1180  // parse out values
1181  vector<double> vals;
1182  vector<string> valstrs = genie::utils::str::Split(strtok[1]," ,;(){}[]");
1183  vector<string>::const_iterator iter = valstrs.begin();
1184  for ( ; iter != valstrs.end(); ++iter ) {
1185  const string& valstr1 = *iter;
1186  if ( valstr1 != "" ) vals.push_back(atof(valstr1.c_str()));
1187  }
1188  size_t nvals = vals.size();
1189 
1190  std::cout << "ivals = [";
1191  for (unsigned int i=0; i < nvals; ++i) {
1192  if (i>0) cout << ",";
1193  std::cout << vals[i];
1194  }
1195  std::cout << "]" << std::endl;
1196 
1197  // std::vector elements are required to be adjacent so we can treat address as ptr
1198 
1199  if ( stype.find("zcyl") != string::npos ) {
1200  // cylinder along z direction at (x0,y0) radius zmin zmax
1201  if ( nvals < 5 )
1202  LOG("gevgen_lardm", pFATAL) << "MakeZCylinder needs 5 values, not " << nvals
1203  << " fidcut=\"" << fidcut << "\"";
1204  fidsel->MakeZCylinder(vals[0],vals[1],vals[2],vals[3],vals[4]);
1205 
1206  } else if ( stype.find("box") != string::npos ) {
1207  // box (xmin,ymin,zmin) (xmax,ymax,zmax)
1208  if ( nvals < 6 )
1209  LOG("gevgen_lardm", pFATAL) << "MakeBox needs 6 values, not " << nvals
1210  << " fidcut=\"" << fidcut << "\"";
1211  double xyzmin[3] = { vals[0], vals[1], vals[2] };
1212  double xyzmax[3] = { vals[3], vals[4], vals[5] };
1213  fidsel->MakeBox(xyzmin,xyzmax);
1214 
1215  } else if ( stype.find("zpoly") != string::npos ) {
1216  // polygon along z direction nfaces at (x0,y0) radius phi zmin zmax
1217  if ( nvals < 7 )
1218  LOG("gevgen_lardm", pFATAL) << "MakeZPolygon needs 7 values, not " << nvals
1219  << " fidcut=\"" << fidcut << "\"";
1220  int nfaces = (int)vals[0];
1221  if ( nfaces < 3 )
1222  LOG("gevgen_lardm", pFATAL) << "MakeZPolygon needs nfaces>=3, not " << nfaces
1223  << " fidcut=\"" << fidcut << "\"";
1224  fidsel->MakeZPolygon(nfaces,vals[1],vals[2],vals[3],vals[4],vals[5],vals[6]);
1225 
1226  } else if ( stype.find("sphere") != string::npos ) {
1227  // sphere at (x0,y0,z0) radius
1228  if ( nvals < 4 )
1229  LOG("gevgen_lardm", pFATAL) << "MakeZSphere needs 4 values, not " << nvals
1230  << " fidcut=\"" << fidcut << "\"";
1231  fidsel->MakeSphere(vals[0],vals[1],vals[2],vals[3]);
1232 
1233  } else {
1234  LOG("gevgen_lardm", pFATAL)
1235  << "Can not create GeomVolSelectorFiduction for shape \"" << stype << "\"";
1236  }
1237 
1238  if ( master ) {
1239  fidsel->ConvertShapeMaster2Top(rgeom);
1240  LOG("gevgen_lardm", pNOTICE) << "Convert fiducial volume from master to topvol coords";
1241  }
1242  if ( reverse ) {
1243  fidsel->SetReverseFiducial(true);
1244  LOG("gevgen_lardm", pNOTICE) << "Reverse sense of fiducial volume cut";
1245  }
1246  rgeom->AdoptGeomVolSelector(fidsel);
1247 
1248 }
void MakeSphere(Double_t x0, Double_t y0, Double_t z0, Double_t radius)
GENIE Interface for user-defined volume selector functors Trim path segments based on the intersectio...
virtual GeomVolSelectorI * AdoptGeomVolSelector(GeomVolSelectorI *selector)
configure processing to perform path segment trimming
void MakeZCylinder(Double_t x0, Double_t y0, Double_t radius, Double_t zmin, Double_t zmax)
#define pFATAL
Definition: Messenger.h:56
virtual void ConvertShapeMaster2Top(const ROOTGeomAnalyzer *rgeom)
intermediate_table::const_iterator const_iterator
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
size_t size
Definition: lodepng.cpp:55
void MakeZPolygon(Int_t n, Double_t x0, Double_t y0, Double_t inradius, Double_t phi0deg, Double_t zmin, Double_t zmax)
A ROOT/GEANT4 geometry driver.
#define pWARN
Definition: Messenger.h:60
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Definition: qstring.cpp:11649
#define pNOTICE
Definition: Messenger.h:61
void MakeBox(Double_t *xyzmin, Double_t *xyzmax)
QTextStream & endl(QTextStream &s)
void CreateRockBoxSelection ( string  fidcut,
GeomAnalyzerI geom_driver 
)

Definition at line 1250 of file gEvGenLArDM.cxx.

1251 {
1252 
1253  if( fidcut.find_first_not_of(" \t\n") != 0) // trim any leading whitespace
1254  fidcut.erase( 0, fidcut.find_first_not_of(" \t\n") );
1255 
1256  // convert string to lowercase
1257  std::transform(fidcut.begin(),fidcut.end(),fidcut.begin(),::tolower);
1258 
1260  dynamic_cast<genie::geometry::ROOTGeomAnalyzer *>(geom_driver);
1261  if ( ! rgeom ) {
1262  LOG("gevgen_numi", pWARN)
1263  << "Can not create GeomVolSelectorRockBox,"
1264  << " geometry driver is not ROOTGeomAnalyzer";
1265  return;
1266  }
1267 
1268  LOG("gevgen_numi", pWARN) << "fiducial (rock) cut: " << fidcut;
1269 
1270  // for now, only fiducial no "rock box"
1273 
1274  vector<string> strtok = genie::utils::str::Split(fidcut,":");
1275  if ( strtok.size() != 2 ) {
1276  LOG("gevgen_numi", pWARN)
1277  << "Can not create GeomVolSelectorRockBox,"
1278  << " no \":\" separating type from values. nsplit=" << strtok.size();
1279  for ( unsigned int i=0; i < strtok.size(); ++i )
1280  LOG("gevgen_numi", pWARN)
1281  << "strtok[" << i << "] = \"" << strtok[i] << "\"";
1282  return;
1283  }
1284 
1285  string stype = strtok[0];
1286 
1287  // parse out values
1288  vector<double> vals;
1289  vector<string> valstrs = genie::utils::str::Split(strtok[1]," ,;(){}[]\t\n\r");
1290  vector<string>::const_iterator iter = valstrs.begin();
1291  for ( ; iter != valstrs.end(); ++iter ) {
1292  const string& valstr1 = *iter;
1293  if ( valstr1 != "" ) {
1294  double aval = atof(valstr1.c_str());
1295  LOG("gevgen_numi", pWARN) << "rock value [" << vals.size() << "] "
1296  << aval;
1297  vals.push_back(aval);
1298  }
1299  }
1300  size_t nvals = vals.size();
1301 
1302  rocksel->SetRemoveEntries(true); // drop segments that won't be considered
1303 
1304  // assume coordinates are in the *master* (not "top volume") system
1305  // need to set fTopVolume to fWorldVolume
1306  //fTopVolume = fWorldVolume;
1307  //rgeom->SetTopVolName(fTopVolume.c_str());
1309  rgeom->SetTopVolName(gOptRootGeomMasterVol);
1310 
1311  if ( nvals < 6 ) {
1312  LOG("gevgen_numi", pFATAL) << "rockbox needs at "
1313  << "least 6 values, found "
1314  << nvals << "in \""
1315  << strtok[1] << "\"";
1316  exit(1);
1317 
1318  }
1319  double xyzmin[3] = { vals[0], vals[1], vals[2] };
1320  double xyzmax[3] = { vals[3], vals[4], vals[5] };
1321 
1322  bool rockonly = true;
1323  double wallmin = 800.; // geometry in cm, ( 8 meter buffer)
1324  double dedx = 2.5 * 1.7e-3; // GeV/cm, rho=2.5, 1.7e-3 ~ rock like loss
1325  double fudge = 1.05;
1326 
1327  if ( nvals >= 7 ) rockonly = vals[6];
1328  if ( nvals >= 8 ) wallmin = vals[7];
1329  if ( nvals >= 9 ) dedx = vals[8];
1330  if ( nvals >= 10 ) fudge = vals[9];
1331 
1332  rocksel->SetRockBoxMinimal(xyzmin,xyzmax);
1333  rocksel->SetMinimumWall(wallmin);
1334  rocksel->SetDeDx(dedx/fudge);
1335 
1336  if ( nvals >= 11 ) rocksel->SetExpandFromInclusion((int)vals[10]);
1337 
1338  // if not rock-only then make a tiny exclusion bubble
1339  // call to MakeBox shouldn't be necessary
1340  // should be done by SetRockBoxMinimal but for some GENIE versions isn't
1341  if ( ! rockonly ) rocksel->MakeSphere(0,0,0,1.0e-10);
1342  else rocksel->MakeBox(xyzmin,xyzmax);
1343 
1344  rgeom->AdoptGeomVolSelector(rocksel);
1345 
1346 }
void MakeSphere(Double_t x0, Double_t y0, Double_t z0, Double_t radius)
string gOptRootGeomMasterVol
#define pFATAL
Definition: Messenger.h:56
intermediate_table::const_iterator const_iterator
const double e
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
size_t size
Definition: lodepng.cpp:55
GENIE Interface for limiting vertex selection in the rock to a volume that depends (in part) on the n...
A ROOT/GEANT4 geometry driver.
#define pWARN
Definition: Messenger.h:60
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void SetRockBoxMinimal(Double_t *xyzmin, Double_t *xyzmax)
void MakeBox(Double_t *xyzmin, Double_t *xyzmax)
string gOptRootGeomTopVol
void DetermineFluxDriver ( string  fopt)

Definition at line 1563 of file gFNALExptEvGen.cxx.

1564 {
1565  // based on the -f option string determine which flux driver to use
1566  // this may take some guessing
1567 
1568  // first look for strings that look like "<proto>:..."
1569  // or ....<proto>.root,....
1570  // where "<proto>" is a key the gOptFluxShortNames map
1571 
1574  for ( ; mitr != mitr_end; ++mitr ) {
1575  string proto = mitr->first + string(":");
1576  string gproto = string("g") + proto;
1577  string protor = proto + ".root,";
1578  string full = mitr->second;
1579  if ( fopt.find(proto) == 0 ) {
1580  fopt.erase(0,proto.size());
1581  gOptFluxDriver = full;
1582  break;
1583  } else if ( fopt.find(gproto) == 0 ) {
1584  fopt.erase(0,gproto.size());
1585  gOptFluxDriver = full;
1586  break;
1587  } else if ( fopt.find(protor) != std::string::npos ) {
1588  gOptFluxDriver = full;
1589  break;
1590  }
1591  }
1592  // tested all cases where user might have specified explicitly
1593  // or been part of an extended file extension
1594  // this is where it gets messy
1595  if ( gOptFluxDriver == "" ) {
1596 
1597  // not specified ? guess from file name itself
1598  if ( fopt.find("gsimple") != std::string::npos ) {
1599  // put dk2nu after gsimple in case simple files are derived from dk2nu
1600  // then both are in name we should choose gsimple
1601  gOptFluxDriver = "genie::flux::GSimpleNtpFlux";
1602  } else if ( fopt.find("dk2nu") != std::string::npos ) {
1603  gOptFluxDriver = "genie::flux::GDk2NuFlux";
1604  } else {
1605  // does it look like the histogram format
1606  const char* hstrings[] = { ",12[", ",+12[", ",-12[",
1607  ",14[", ",+14[", ",-14[",
1608  ",16[", ",+16[", ",-16[" };
1609  size_t nh = sizeof(hstrings)/sizeof(const char*);
1610  for (size_t ih=0; ih<nh; ++ih) {
1611  if ( fopt.find(hstrings[ih]) != std::string::npos ) {
1612  // hey!
1613  gOptFluxDriver = "genie::flux::GCylindTH1Flux";
1614  break;
1615  }
1616  } // loop over possible histogram specifiers
1617  }
1618 
1619  // fall through default ... hope it works
1620  if ( gOptFluxDriver == "" ) {
1621  gOptFluxDriver = "genie::flux::GNuMIFlux";
1622  }
1623  }
1624 
1625  gOptUsingHistFlux = ( gOptFluxDriver == "genie::flux::GCylindTH1Flux" );
1626  if ( gOptUsingHistFlux ) ParseFluxHst(fopt);
1627  else ParseFluxFileConfig(fopt);
1628 }
void ParseFluxFileConfig(string fopt)
std::string string
Definition: nybbler.cc:12
intermediate_table::const_iterator const_iterator
void ParseFluxHst(string fopt)
map< string, string > gOptFluxShortNames
General LArSoft Utilities.
string gOptFluxDriver
bool gOptUsingHistFlux
void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 774 of file gEvGenLArDM.cxx.

775 {
776  LOG("gevgen_lardm", pINFO) << "Parsing command line arguments";
777 
778  // Common run options. Set defaults and read.
779  RunOpt::Instance()->EnableBareXSecPreCalc(true);
780  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
781 
782  // Parse run options for this app
783 
784  CmdLnArgParser parser(argc,argv);
785 
786  // help?
787  bool help = parser.OptionExists('h');
788  if(help) {
789  PrintSyntax();
790  exit(0);
791  }
792 
793  // run number:
794  if ( parser.OptionExists('r') ) {
795  LOG("gevgen_lardm", pDEBUG) << "Reading MC run number";
796  gOptRunNu = parser.ArgAsLong('r');
797  } else {
798  LOG("gevgen_lardm", pDEBUG)
799  << "Unspecified run number - Using default";
800  gOptRunNu = 0;
801  } //-r
802 
803  //
804  // *** geometry
805  //
806 
807  string geom = "";
808  string lunits, dunits;
809  if( parser.OptionExists('g') ) {
810  LOG("gevgen_lardm", pDEBUG) << "Getting input geometry";
811  geom = parser.ArgAsString('g');
812 
813  // is it a ROOT file that contains a ROOT geometry?
814  bool accessible_geom_file =
815  ! (gSystem->AccessPathName(geom.c_str()));
816  if (accessible_geom_file) {
817  gOptRootGeom = geom;
818  gOptUsingRootGeom = true;
819  }
820  } else {
821  LOG("gevgen_lardm", pFATAL)
822  << "No geometry option specified - Exiting";
823  PrintSyntax();
824  exit(1);
825  } //-g
826 
827  // dark matter mass
828  if( parser.OptionExists('M') ) {
829  LOG("gevgen_lardm", pINFO) << "Reading dark matter mass";
830  gOptDMMass = parser.ArgAsDouble('M');
831  } else {
832  LOG("gevgen_lardm", pFATAL) << "Unspecified dark matter mass - Exiting";
833  PrintSyntax();
834  exit(1);
835  } // -M
836 
837  // mediator coupling
838  if( parser.OptionExists('c') ) {
839  LOG("gevgen_lardm", pINFO) << "Reading mediator coupling";
840  gOptZpCoupling = parser.ArgAsDouble('c');
841  } else {
842  LOG("gevgen_lardm", pINFO) << "Unspecified mediator coupling - Using value from config file";
843  gOptZpCoupling = -1.;
844  } // -c
845 
846  // mediator mass ratio
847  if( parser.OptionExists('v') ) {
848  LOG("gevgen_lardm", pINFO) << "Reading mediator mass ratio";
849  gOptMedRatio = parser.ArgAsDouble('v');
850  } else {
851  LOG("gevgen_lardm", pINFO) << "Unspecified mediator mass ratio - Using default";
852  gOptMedRatio = 0.5;
853  } // -v
854 
855  if(gOptUsingRootGeom) {
856  // using a ROOT geometry - get requested geometry units
857 
858  // legth units:
859  if( parser.OptionExists('L') ) {
860  LOG("gevgen_lardm", pDEBUG)
861  << "Checking for input geometry length units";
862  lunits = parser.ArgAsString('L');
863  } else {
864  LOG("gevgen_lardm", pDEBUG) << "Using default geometry length units";
865  lunits = kDefOptGeomLUnits;
866  } // -L
867  // density units:
868  if( parser.OptionExists('D') ) {
869  LOG("gevgen_lardm", pDEBUG)
870  << "Checking for input geometry density units";
871  dunits = parser.ArgAsString('D');
872  } else {
873  LOG("gevgen_lardm", pDEBUG) << "Using default geometry density units";
874  dunits = kDefOptGeomDUnits;
875  } // -D
878 
879  // check whether an event generation volume name has been
880  // specified -- default is the 'top volume'
881  if( parser.OptionExists('t') ) {
882  LOG("gevgen_lardm", pDEBUG) << "Checking for input volume name";
883  gOptRootGeomTopVol = parser.ArgAsString('t');
884  } else {
885  LOG("gevgen_lardm", pDEBUG) << "Using the <master volume>";
886  } // -t
887 
888  // check whether an XML file with the maximum (density weighted)
889  // path lengths for each detector material is specified -
890  // otherwise will compute the max path lengths at job init
891  // if passed name starts with '+', then compute max at job init, but write out the result
892  if ( parser.OptionExists('m') ) {
893  LOG("gevgen_lardm", pDEBUG)
894  << "Checking for maximum path lengths XML file";
895  gOptExtMaxPlXml = parser.ArgAsString('m');
896  gOptWriteMaxPlXml = false;
897  if ( gOptExtMaxPlXml[0] == '+' ) {
898  gOptExtMaxPlXml = gOptExtMaxPlXml.substr(1,std::string::npos);
899  gOptWriteMaxPlXml = true;
900  LOG("gevgen_lardm", pINFO)
901  << "Will write maximum path lengths XML file: " << gOptExtMaxPlXml;
902  }
903  } else {
904  LOG("gevgen_lardm", pDEBUG)
905  << "Will compute the maximum path lengths at job init";
906  gOptExtMaxPlXml = "";
907  } // -m
908 
909  // fidcut:
910  if( parser.OptionExists('F') ) {
911  LOG("gevgen_lardm", pDEBUG) << "Using Fiducial cut?";
912  gOptFidCut = parser.ArgAsString('F');
913  } else {
914  LOG("gevgen_lardm", pDEBUG) << "No fiducial volume cut";
915  gOptFidCut = "";
916  } //-F
917 
918  // how to scan the geometry (if relevant)
919  if( parser.OptionExists('S') ) {
920  LOG("gevgen_lardm", pDEBUG) << "Reading requested geom scan count";
921  gOptNScan = parser.ArgAsInt('S');
922  } else {
923  LOG("gevgen_lardm", pDEBUG) << "No geom scan count was requested";
924  gOptNScan = 0;
925  } //-S
926 
927  // z for flux rays to start
928  if( parser.OptionExists('z') ) {
929  LOG("gevgen_lardm", pDEBUG) << "Reading requested zmin";
930  gOptZmin = parser.ArgAsDouble('z');
931  } else {
932  LOG("gevgen_lardm", pDEBUG) << "No zmin was requested";
933  gOptZmin = -2.0e30; // < -1.0e30 ==> leave it on flux window
934  } //-z
935 
936  // debug flags
937  if ( parser.OptionExists('d') ) {
938  LOG("gevgen_lardm", pDEBUG) << "Reading debug flag value";
939  gOptDebug = parser.ArgAsInt('d');
940  } else {
941  LOG("gevgen_lardm", pDEBUG) << "Unspecified debug flags - Using default";
942  gOptDebug = 0;
943  } //-d
944 
945  } // using root geom?
946 
947  else {
948  // User has specified a target mix.
949  // Decode the list of target pdf codes & their corresponding weight fraction
950  // (specified as 'pdg_code_1[fraction_1],pdg_code_2[fraction_2],...')
951  // See documentation on top section of this file.
952  //
953  gOptTgtMix.clear();
954  vector<string> tgtmix = utils::str::Split(geom,",");
955  if(tgtmix.size()==1) {
956  int pdg = atoi(tgtmix[0].c_str());
957  double wgt = 1.0;
958  gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
959  } else {
960  vector<string>::const_iterator tgtmix_iter = tgtmix.begin();
961  for( ; tgtmix_iter != tgtmix.end(); ++tgtmix_iter) {
962  string tgt_with_wgt = *tgtmix_iter;
963  string::size_type open_bracket = tgt_with_wgt.find("[");
964  string::size_type close_bracket = tgt_with_wgt.find("]");
965  if (open_bracket ==string::npos ||
966  close_bracket==string::npos)
967  {
968  LOG("gevgen_lardm", pFATAL)
969  << "You made an error in specifying the target mix";
970  PrintSyntax();
971  exit(1);
972  }
973  string::size_type ibeg = 0;
974  string::size_type iend = open_bracket;
975  string::size_type jbeg = open_bracket+1;
976  string::size_type jend = close_bracket;
977  int pdg = atoi(tgt_with_wgt.substr(ibeg,iend-ibeg).c_str());
978  double wgt = atof(tgt_with_wgt.substr(jbeg,jend-jbeg).c_str());
979  LOG("gevgen_lardm", pDEBUG)
980  << "Adding to target mix: pdg = " << pdg << ", wgt = " << wgt;
981  gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
982 
983  }// tgtmix_iter
984  } // >1 materials in mix
985  } // using tgt mix?
986 
987  //
988  // *** flux
989  //
990  if ( parser.OptionExists('f') ) {
991  LOG("gevgen_lardm", pDEBUG) << "Getting input flux";
992  gOptFluxFile = parser.ArgAsString('f');
993  } else {
994  LOG("gevgen_lardm", pFATAL) << "No flux info was specified - Exiting";
995  PrintSyntax();
996  exit(1);
997  }
998 
999  // number of events to generate
1000  if( parser.OptionExists('n') ) {
1001  LOG("gevgen_lardm", pDEBUG)
1002  << "Reading limit on number of events to generate";
1003  gOptNev = parser.ArgAsInt('n');
1004  } else {
1005  LOG("gevgen_lardm", pDEBUG)
1006  << "Will keep on generating events till the flux driver stops";
1007  gOptNev = -1;
1008  } //-n
1009 
1010  // event file prefix
1011  if( parser.OptionExists('o') ) {
1012  LOG("gevgen_lardm", pDEBUG) << "Reading the event filename prefix";
1013  gOptEvFilePrefix = parser.ArgAsString('o');
1014  } else {
1015  LOG("gevgen_lardm", pDEBUG)
1016  << "Will set the default event filename prefix";
1018  } //-o
1019 
1020 
1021  // random number seed
1022  if( parser.OptionExists("seed") ) {
1023  LOG("gevgen_lardm", pINFO) << "Reading random number seed";
1024  gOptRanSeed = parser.ArgAsLong("seed");
1025  } else {
1026  LOG("gevgen_lardm", pINFO) << "Unspecified random number seed - Using default";
1027  gOptRanSeed = -1;
1028  }
1029 
1030  // input cross-section file
1031  if( parser.OptionExists("cross-sections") ) {
1032  LOG("gevgen_lardm", pINFO) << "Reading cross-section file";
1033  gOptInpXSecFile = parser.ArgAsString("cross-sections");
1034  } else {
1035  LOG("gevgen_lardm", pINFO) << "Unspecified cross-section file";
1036  gOptInpXSecFile = "";
1037  }
1038 
1039  //
1040  // >>> print the command line options
1041  //
1042 
1043  PDGLibrary * pdglib = PDGLibrary::Instance();
1044 
1045  ostringstream gminfo;
1046  if (gOptUsingRootGeom) {
1047  gminfo << "Using ROOT geometry - file = " << gOptRootGeom
1048  << ", top volume = "
1049  << ((gOptRootGeomTopVol.size()==0) ? "<master volume>" : gOptRootGeomTopVol)
1050  << ", max{PL} file = "
1051  << ((gOptExtMaxPlXml.size()==0) ? "<none>" : gOptExtMaxPlXml)
1052  << ", length units = " << lunits
1053  << ", density units = " << dunits;
1054  } else {
1055  gminfo << "Using target mix: ";
1057  for(iter = gOptTgtMix.begin(); iter != gOptTgtMix.end(); ++iter) {
1058  int pdg_code = iter->first;
1059  double wgt = iter->second;
1060  TParticlePDG * p = pdglib->Find(pdg_code);
1061  if(p) {
1062  string name = p->GetName();
1063  gminfo << "(" << name << ") -> " << 100*wgt << "% / ";
1064  }//p?
1065  }
1066  }
1067 
1068  ostringstream fluxinfo;
1069  fluxinfo << "file = " << gOptFluxFile;
1070 
1071  ostringstream exposure;
1072  if(gOptNev > 0)
1073  exposure << "Number of events = " << gOptNev;
1074 
1075  LOG("gevgen_lardm", pNOTICE)
1076  << "\n\n"
1077  << utils::print::PrintFramedMesg("NuMI expt. event generation job configuration");
1078 
1079  LOG("gevgen_lardm", pNOTICE)
1080  << "\n - Run number: " << gOptRunNu
1081  << "\n - Random number seed: " << gOptRanSeed
1082  << "\n - Using cross-section file: " << gOptInpXSecFile
1083  << "\n - Flux @ " << fluxinfo.str()
1084  << "\n - Geometry @ " << gminfo.str()
1085  << "\n - Exposure @ " << exposure.str();
1086 
1087  LOG("gevgen_lardm", pNOTICE) << *RunOpt::Instance();
1088 }
static QCString name
Definition: declinfo.cpp:673
int gOptDebug
#define pFATAL
Definition: Messenger.h:56
int gOptNev
string gOptExtMaxPlXml
string kDefOptEvFilePrefix
string gOptInpXSecFile
double gOptZmin
int gOptNScan
intermediate_table::const_iterator const_iterator
string gOptFidCut
bool gOptWriteMaxPlXml
double gOptZpCoupling
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string kDefOptGeomLUnits
map< int, double > gOptTgtMix
double UnitFromString(string u)
Definition: UnitUtils.cxx:18
p
Definition: test.py:223
#define pINFO
Definition: Messenger.h:62
Long_t gOptRunNu
string gOptEvFilePrefix
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
Singleton class to load & serve a TDatabasePDG.
Definition: PDGLibrary.h:32
string gOptFluxFile
long int gOptRanSeed
void PrintSyntax(void)
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
string kDefOptGeomDUnits
double gOptGeomDUnits
double gOptGeomLUnits
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:75
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
string gOptRootGeom
bool gOptUsingRootGeom
string gOptRootGeomTopVol
double gOptDMMass
double gOptMedRatio
#define pDEBUG
Definition: Messenger.h:63
static void gsSIGTERMhandler ( int  )
static

Definition at line 376 of file gEvGenLArDM.cxx.

377 {
378  gSigTERM = true;
379  std::cerr << "Caught SIGTERM" << std::endl;
380 }
bool gSigTERM
QTextStream & endl(QTextStream &s)
void LoadExtraOptions ( void  )

potentially load extra libraries that might extend the list of potential flux drivers, and how to map short names to classes ...

******* done with fake "read"

Definition at line 730 of file gEvGenLArDM.cxx.

731 {
732  /// potentially load extra libraries that might extend the list of
733  /// potential flux drivers, and how to map short names to classes ...
734  // we really should at this point read some external file to get
735  // an expandable list of libraries ... but for now just hard code it
736 
737  vector<string> extraLibs;
738 
739  ///***** this part should come from reading an external file
740  /// placeholder file $GENIE/config/FluxDriverExpansion.xml
741 
742  extraLibs.push_back("libdk2nuTree");
743  extraLibs.push_back("libdk2nuGenie");
744 
745  ///******* done with fake "read"
746 
747  // see if there are any libraries to load
748  // just let ROOT do it ... check error code on return
749  // but tweak ROOT's ERROR message output so we don't see huge messages
750  // for failures
751  // gErrorIgnoreLevel to kError (from TError.h)
752 
753  Int_t prevErrorLevel = gErrorIgnoreLevel;
754  gErrorIgnoreLevel = kFatal;
755  for (size_t ilib=0; ilib < extraLibs.size(); ++ilib) {
756  // library names should be like libXYZZY without extension [e.g. .so]
757  // but with the leading "lib"
758  int loadStatus = gSystem->Load(extraLibs[ilib].c_str());
759  const char* statWords = "failed to load";
760  if ( loadStatus == 0 ) { statWords = "successfully loaded"; }
761  else if ( loadStatus == 1 ) { statWords = "already had loaded"; }
762  else if ( loadStatus == -1 ) { statWords = "couldn't find library"; }
763  else if ( loadStatus == -2 ) { statWords = "mismatched version"; }
764 
765  LOG("gevgen_lardm",pNOTICE)
766  << statWords << " (" << loadStatus << ") " << extraLibs[ilib];
767  }
768  // restore the ROOT error message level
769  gErrorIgnoreLevel = prevErrorLevel;
770 
771 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pNOTICE
Definition: Messenger.h:61
int main ( int  argc,
char **  argv 
)

Definition at line 383 of file gEvGenLArDM.cxx.

384 {
386  GetCommandLineArgs(argc,argv);
387  PDGLibrary::Instance()->AddDarkMatter(gOptDMMass,gOptMedRatio);
388  if (gOptZpCoupling > 0.) {
389  Registry * r = AlgConfigPool::Instance()->CommonList("Param", "BoostedDarkMatter");
390  r->UnLock();
391  r->Set("ZpCoupling", gOptZpCoupling);
392  r->Lock();
393  }
394 
395  if ( ! RunOpt::Instance()->Tune() ) {
396  LOG("gmkspl", pFATAL) << " No TuneId in RunOption";
397  exit(-1);
398  }
399  RunOpt::Instance()->BuildTune();
400 
401  // Initialization of random number generators, cross-section table,
402  // messenger thresholds, cache file
403  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
404  utils::app_init::CacheFile(RunOpt::Instance()->CacheFile());
407 
408  // Set GHEP print level
409  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
410 
411  // *************************************************************************
412  // * Create / configure the geometry driver
413  // *************************************************************************
414  GeomAnalyzerI * geom_driver = 0;
415 
416  if(gOptUsingRootGeom) {
417  //
418  // *** Using a realistic root-based detector geometry description
419  //
420 
421  // creating & configuring a root geometry driver
424  TGeoVolume * topvol = rgeom->GetGeometry()->GetTopVolume();
425  if ( ! topvol ) {
426  LOG("gevgen_numi", pFATAL) << "Null top ROOT geometry volume!";
427  exit(1);
428  }
429  // retrieve the master volume name
430  gOptRootGeomMasterVol = topvol->GetName();
431 
432  rgeom -> SetLengthUnits (gOptGeomLUnits);
433  rgeom -> SetDensityUnits (gOptGeomDUnits);
434  rgeom -> SetTopVolName (gOptRootGeomTopVol); // set user defined "topvol"
435 
436  // getting the bounding box dimensions along z so as to set the
437  // appropriate upstream generation surface for the NuMI flux driver
438 
439  // RWH 2010-07-16: do not try to automatically get zmin from geometry, rather
440  // by default let the flux start from the window. If the user wants to
441  // override this then they need to explicitly set a "zmin". Trying to use
442  // the geometry is fraught with problems in local vs. global coordinates and
443  // units where it can appear to work in some cases but it actually isn't really
444  // universally correct.
445  //was// TGeoShape * bounding_box = topvol->GetShape();
446  //was// bounding_box->GetAxisRange(3, zmin, zmax);
447  //was// zmin *= rgeom->LengthUnits();
448  //was// zmax *= rgeom->LengthUnits();
449 
450  // switch on/off volumes as requested
451  if ( (gOptRootGeomTopVol[0] == '+') || (gOptRootGeomTopVol[0] == '-') ) {
452  bool exhaust = (*gOptRootGeomTopVol.c_str() == '+');
454  }
455 
456  // casting to the GENIE geometry driver interface
457  geom_driver = dynamic_cast<GeomAnalyzerI *> (rgeom);
458 
459  // user specifid a fiducial volume cut ... parse that out
460  if ( gOptFidCut.find("rock") != std::string::npos )
462  else if ( gOptFidCut != "" ) CreateFidSelection(gOptFidCut,rgeom);
463 
464  }
465  else {
466  //
467  // *** Using a 'point' geometry with the specified target mix
468  // *** ( = a list of targets with their corresponding weight fraction)
469  //
470 
471  // creating & configuring a point geometry driver
474  // casting to the GENIE geometry driver interface
475  geom_driver = dynamic_cast<GeomAnalyzerI *> (pgeom);
476  }
477 
478  // *************************************************************************
479  // * Create / configure the flux driver
480  // *************************************************************************
481  GFluxI * flux_driver =
482  genie::flux::GFluxDriverFactory::Instance().GetFluxDriver("genie::flux::GSimpleNtpFlux");
483  if ( ! flux_driver ) {
484  // couldn't get the requested flux driver ?
485  std::ostringstream s;
486  s << "Known FluxDrivers:\n";
487  const std::vector<std::string>& known =
489  std::vector<std::string>::const_iterator itr = known.begin();
490  for ( ; itr != known.end(); ++itr ) s << " " << (*itr) << "\n";
491  LOG("gevgen_lardm", pFATAL)
492  << "Failed to get any flux driver from GFluxDriverFactory";
493  exit(1);
494  }
495 
496  genie::flux::GFluxFileConfigI* flux_file_config =
497  dynamic_cast<genie::flux::GFluxFileConfigI*>(flux_driver);
498  if ( ! flux_file_config ) {
499  LOG("gevgen_lardm", pFATAL)
500  << "Failed to get GFluxFileConfigI driver from GFluxDriverFactory";
501  exit(1);
502  }
503 
504  //
505  // *** Using the detailed ntuple neutrino flux description
506  //
507  flux_file_config->LoadBeamSimData(gOptFluxFile, "");
508  flux_file_config->SetUpstreamZ(gOptZmin); // was "zmin" from bounding_box
509  flux_file_config->SetNumOfCycles(0);
510  PDGCodeList dm_pdg;
511  dm_pdg.push_back(kPdgDarkMatter);
512  flux_file_config->SetFluxParticles(dm_pdg);
513 
514  // these might come in handy ... avoid repeated dynamic_cast<> calls
515  genie::flux::GFluxFileConfigI* fluxFileConfigI =
516  dynamic_cast<genie::flux::GFluxFileConfigI*>(flux_driver);
517 
518 
519  // *************************************************************************
520  // * Handle chicken/egg problem: geom analyzer vs. flux.
521  // * Need both at this point change geom scan defaults.
522  // *************************************************************************
523  if ( gOptUsingRootGeom ) {
524 
526  dynamic_cast<geometry::ROOTGeomAnalyzer *>(geom_driver);
527  if ( ! rgeom ) assert(0);
528 
529  rgeom -> SetDebugFlags(gOptDebug);
530 
531  // even if user doesn't specify gOptNScan configure to scan using flux
532  if ( gOptNScan >= 0 ) {
533  LOG("gevgen_lardm", pNOTICE)
534  << "Using ROOTGeomAnalyzer: geom scan using flux: nparticles=" << gOptNScan;
535  rgeom->SetScannerFlux(flux_driver);
536  if ( gOptNScan > 0 ) rgeom->SetScannerNParticles(gOptNScan);
537  } else {
538  int nabs = TMath::Abs(gOptNScan);
539  LOG("gevgen_lardm", pNOTICE)
540  << "Using ROOTGeomAnalyzer: geom scan using box: npoints=nrays=" << nabs;
541  rgeom->SetScannerNPoints(nabs);
542  rgeom->SetScannerNRays(nabs);
543  }
544  }
545 
546  // *************************************************************************
547  // * Create/configure the event generation driver
548  // *************************************************************************
549  GMCJDriver * mcj_driver = new GMCJDriver;
550  mcj_driver->SetEventGeneratorList(RunOpt::Instance()->EventGeneratorList());
551  mcj_driver->UseFluxDriver(flux_driver);
552  mcj_driver->UseGeomAnalyzer(geom_driver);
553  if ( ( gOptExtMaxPlXml != "" ) && ! gOptWriteMaxPlXml ) {
554  mcj_driver->UseMaxPathLengths(gOptExtMaxPlXml);
555  }
556  mcj_driver->Configure();
557  mcj_driver->UseSplines();
558  mcj_driver->ForceSingleProbScale();
559 
560  if ( ( gOptExtMaxPlXml != "" ) && gOptWriteMaxPlXml ) {
562  dynamic_cast<geometry::ROOTGeomAnalyzer *>(geom_driver);
563  if ( rgeom ) {
564  const genie::PathLengthList& maxpath = rgeom->GetMaxPathLengths();
565  std::string maxplfile = gOptExtMaxPlXml;
566  maxpath.SaveAsXml(maxplfile);
567  // append extra info to file
568  std::ofstream mpfile(maxplfile.c_str(), std::ios_base::app);
569  mpfile
570  << std::endl
571  << "<!-- this file is only relevant for a setup compatible with:"
572  << std::endl
573  << "geom: " << gOptRootGeom << " top: \"" << gOptRootGeomTopVol << "\""
574  << std::endl
575  << "flux: " << gOptFluxFile
576  << std::endl
577  << "fidcut: " << gOptFidCut
578  << std::endl
579  << "nscan: " << gOptNScan << " (0>= use flux, <0 use box |nscan| points/rays)"
580  << std::endl
581  << "zmin: " << gOptZmin << " (if |zmin| > 1e30, leave ray on flux window)"
582  << std::endl
583  << "-->"
584  << std::endl;
585  mpfile.close();
586  }
587  }
588 
589  // *************************************************************************
590  // * Prepare for writing the output event tree & status file
591  // *************************************************************************
592 
593  // Initialize an Ntuple Writer to save GHEP records into a TTree
595  ntpw.CustomizeFilenamePrefix(gOptEvFilePrefix);
596  ntpw.Initialize();
597 
598 
599  std::vector<TBranch*> extraBranches;
600  std::vector<std::string> branchNames;
601  std::vector<std::string> branchClassNames;
602  std::vector<void**> branchObjPointers;
603 
604  // Add custom branch(s) to the standard GENIE event tree so that
605  // info on the flux neutrino parent particle can be passed-through
606  if ( fluxFileConfigI ) {
607  fluxFileConfigI->GetBranchInfo(branchNames,branchClassNames,
608  branchObjPointers);
609  size_t nn = branchNames.size();
610  size_t nc = branchClassNames.size();
611  size_t np = branchObjPointers.size();
612  if ( nn != nc || nc != np ) {
613  LOG("gevgen_lardm", pERROR)
614  << "Inconsistent info back from flux driver "
615  << "for branch info: " << nn << " " << nc << " " << np;
616  } else {
617  for (size_t ii = 0; ii < nn; ++ii) {
618  const char* bname = branchNames[ii].c_str();
619  const char* cname = branchClassNames[ii].c_str();
620  void**& optr = branchObjPointers[ii]; // note critical '&' !
621  if ( ! optr || ! *optr ) continue; // no pointer supplied, skip it
622  int split = 99; // 1
623  LOG("gevgen_lardm", pNOTICE)
624  << "Adding extra branch \"" << bname << "\" of type \""
625  << cname << "\" (" << optr << ") to output tree";
626  TBranch* bptr = ntpw.EventTree()->Branch(bname,cname,optr,32000,split);
627  extraBranches.push_back(bptr);
628 
629  if ( bptr ) {
630  // don't delete this !!! we're sharing
631  bptr->SetAutoDelete(false);
632  } else {
633  LOG("gevgen_lardm", pERROR)
634  << "FAILED to add extra branch \"" << bname << "\" of type \""
635  << cname << "\" to output tree";
636  }
637  } // loop over additions
638  } // same # of entries
639  } // of genie::flux::GFluxFileConfigI type
640 
641  // Create a MC job monitor for a periodically updated status file
642  GMCJMonitor mcjmonitor(gOptRunNu);
643  mcjmonitor.SetRefreshRate(RunOpt::Instance()->MCJobStatusRefreshRate());
644 
645  // *************************************************************************
646  // * Event generation loop
647  // *************************************************************************
648 
649  // define handler to allow signal to end job gracefully
650  signal(SIGTERM,gsSIGTERMhandler);
651 
652  int ievent = 0;
653  while ( ! gSigTERM )
654  {
655  LOG("gevgen_lardm", pINFO)
656  << " *** Generating event............ " << ievent;
657 
658  // In case the required statistics was expressed as 'number of events'
659  // then quit if that number has been generated
660  if ( ievent == gOptNev ) break;
661 
662  // Generate a single event using neutrinos coming from the specified flux
663  // and hitting the specified geometry or target mix
664  EventRecord * event = mcj_driver->GenerateEvent();
665 
666  // Check whether a null event was returned due to the flux driver reaching
667  // the end of the input flux ntuple - exit the event generation loop
668  if ( ! event && flux_driver->End() ) {
669  LOG("gevgen_lardm", pWARN)
670  << "** The flux driver read all the input flux entries: End()==true";
671  break;
672  }
673  if ( ! event ) {
674  LOG("gevgen_lardm", pERROR)
675  << "Got a null generated neutino event! Retrying ...";
676  continue;
677  }
678  LOG("gevgen_lardm", pINFO)
679  << "Generated event: " << *event;
680 
681  // A valid event was generated: flux info (parent decay/prod
682  // position/kinematics) for that simulated event should already
683  // be connected to the right output tree branch
684 
685  // Add event at the output ntuple, refresh the mc job monitor & clean-up
686  ntpw.AddEventRecord(ievent, event);
687  mcjmonitor.Update(ievent,event);
688  delete event;
689  ievent++;
690 
691  } //1
692 
693  // Copy metadata tree, if available
694  if ( fluxFileConfigI ) {
695  TTree* t1 = fluxFileConfigI->GetMetaDataTree();
696  if ( t1 ) {
697  size_t nmeta = t1->GetEntries();
698  TTree* t2 = (TTree*)t1->Clone(0);
699  for (size_t i = 0; i < nmeta; ++i) {
700  t1->GetEntry(i);
701  t2->Fill();
702  }
703  t2->Write();
704  }
705  }
706 
707  LOG("gevgen_lardm", pINFO)
708  << "The GENIE MC job is done generating events - Cleaning up & exiting...";
709 
710  // *************************************************************************
711  // * Save & clean-up
712  // *************************************************************************
713 
714  // Save the generated event tree & close the output file
715  ntpw.Save();
716 
717  // Clean-up
718  delete geom_driver;
719  delete flux_driver;
720  delete mcj_driver;
721  // this list should only be histograms that have (for some reason)
722  // not been handed over to the GCylindTH1Flux driver.
723 
724  LOG("gevgen_lardm", pNOTICE) << "Done!";
725 
726  return 0;
727 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
void XSecTable(string inpfile, bool require_table)
Definition: AppInit.cxx:38
void CreateRockBoxSelection(string fidcut, GeomAnalyzerI *geom_driver)
virtual void LoadBeamSimData(const std::vector< std::string > &filenames, const std::string &det_loc)=0
#define pERROR
Definition: Messenger.h:59
int gOptDebug
string gOptRootGeomMasterVol
void SetEventGeneratorList(string listname)
Definition: GMCJDriver.cxx:66
std::string string
Definition: nybbler.cc:12
#define pFATAL
Definition: Messenger.h:56
const int kPdgDarkMatter
Definition: PDGCodes.h:218
virtual const PathLengthList & GetMaxPathLengths(void) const
int gOptNev
string gOptExtMaxPlXml
string gOptInpXSecFile
double gOptZmin
const std::vector< std::string > & AvailableFluxDrivers() const
int gOptNScan
intermediate_table::const_iterator const_iterator
string gOptFidCut
virtual void SetNumOfCycles(long int ncycle)
limit cycling through input files
virtual void SetScannerNParticles(int np)
A list of PDG codes.
Definition: PDGCodeList.h:32
bool gOptWriteMaxPlXml
void CreateFidSelection(string fidcut, GeomAnalyzerI *geom_driver)
virtual void SetUpstreamZ(double z0)
void UseFluxDriver(GFluxI *flux)
Definition: GMCJDriver.cxx:83
double gOptZpCoupling
Object to be filled with the neutrino path-length, for all detector geometry materials, when starting from a position x and travelling along the direction of the neutrino 4-momentum.
Simple class to create & update MC job status files and env. vars. This is used to be able to keep tr...
Definition: GMCJMonitor.h:31
A GENIE `MC Job Driver&#39;. Can be used for setting up complicated event generation cases involving deta...
Definition: GMCJDriver.h:46
void SaveAsXml(string filename) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, double > gOptTgtMix
void ForceSingleProbScale(void)
Definition: GMCJDriver.cxx:172
virtual void SetScannerNRays(int nr)
bool UseMaxPathLengths(string xml_filename)
Definition: GMCJDriver.cxx:99
bool gSigTERM
static void gsSIGTERMhandler(int)
void Configure(bool calc_prob_scales=true)
Definition: GMCJDriver.cxx:399
A ROOT/GEANT4 geometry driver.
#define pINFO
Definition: Messenger.h:62
void Lock(void)
locks the registry
Definition: Registry.cxx:148
Long_t gOptRunNu
#define pWARN
Definition: Messenger.h:60
EventRecord * GenerateEvent(void)
Definition: GMCJDriver.cxx:812
virtual void GetBranchInfo(std::vector< std::string > &branchNames, std::vector< std::string > &branchClassNames, std::vector< void ** > &branchObjPointers)
void UnLock(void)
unlocks the registry (doesn&#39;t unlock items)
Definition: Registry.cxx:153
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
string gOptEvFilePrefix
void LoadExtraOptions(void)
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
Definition: NtpWriter.h:39
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
virtual void SetScannerNPoints(int np)
set geometry driver&#39;s configuration options
virtual void SetScannerFlux(GFluxI *f)
static GFluxDriverFactory & Instance()
string gOptFluxFile
virtual bool End(void)=0
true if no more flux nu&#39;s can be thrown (eg reaching end of beam sim ntuples)
long int gOptRanSeed
A vector of EventGeneratorI objects.
virtual void SetFluxParticles(const PDGCodeList &particles)
specify list of flux neutrino species
double gOptGeomDUnits
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
double gOptGeomLUnits
void GetCommandLineArgs(int argc, char **argv)
#define pNOTICE
Definition: Messenger.h:61
Defines the GENIE Geometry Analyzer Interface.
Definition: GeomAnalyzerI.h:29
string gOptRootGeom
void Set(RgIMapPair entry)
Definition: Registry.cxx:267
void RecursiveExhaust(TGeoVolume *topvol, string volnames, bool exhaust)
Definition: GeoUtils.cxx:16
bool gOptUsingRootGeom
void UseGeomAnalyzer(GeomAnalyzerI *geom)
Definition: GMCJDriver.cxx:88
void UseSplines(bool useLogE=true)
Definition: GMCJDriver.cxx:93
The PointGeomAnalyzer class is the simplest implementation of the GeomAnalyserI interface and defines...
static QCString * s
Definition: config.cpp:1042
void CacheFile(string inpfile)
Definition: AppInit.cxx:117
string gOptRootGeomTopVol
double gOptDMMass
QTextStream & endl(QTextStream &s)
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
Event finding and building.
virtual TGeoManager * GetGeometry(void) const
genie::GFluxI * GetFluxDriver(const std::string &)
double gOptMedRatio
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:29
NtpMCFormat_t kDefOptNtpFormat
void ParseFluxFileConfig ( string  fopt)

Definition at line 1725 of file gFNALExptEvGen.cxx.

1726 {
1727  // Using gnumi/gsimple/dk2nu beam flux ntuples
1728  // Extract beam flux (root) file name & detector location
1729  //
1730  vector<string> fluxv = utils::str::Split(flux,",");
1731  if(fluxv.size()<2) {
1732  LOG("gevgen_fnal", pFATAL)
1733  << "You need to specify both a flux ntuple ROOT file "
1734  << " _AND_ a detector location";
1735  PrintSyntax();
1736  exit(1);
1737  }
1738  gOptFluxFile = fluxv[0];
1739  gOptDetectorLocation = fluxv[1];
1740 
1741  for ( size_t j = 2; j < fluxv.size(); ++j ) {
1742  int ipdg = atoi(fluxv[j].c_str());
1743  gOptFluxPdg.push_back(ipdg);
1744  }
1745 
1746 }
string gOptFluxFile
PDGCodeList gOptFluxPdg
#define pFATAL
Definition: Messenger.h:56
string gOptDetectorLocation
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void PrintSyntax(void)
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
void ParseFluxHst ( string  fopt)

Definition at line 1630 of file gFNALExptEvGen.cxx.

1631 {
1632  // Using flux from histograms
1633  // Extract the root file name & the list of histogram names & neutrino
1634  // species (specified as 'filename,histo1[species1],histo2[species2],...')
1635  // See documentation on top section of this file.
1636  //
1637 
1638  vector<string> fluxv = utils::str::Split(flux,",");
1639  if(fluxv.size()<2) {
1640  LOG("gevgen_fnal", pFATAL)
1641  << "You need to specify both a flux ntuple ROOT file "
1642  << " _AND_ a detector location";
1643  PrintSyntax();
1644  exit(1);
1645  }
1646  gOptFluxFile = fluxv[0];
1647  bool accessible_flux_file = !(gSystem->AccessPathName(gOptFluxFile.c_str()));
1648  if (!accessible_flux_file) {
1649  LOG("gevgen_fnal", pFATAL)
1650  << "Can not access flux file: " << gOptFluxFile;
1651  PrintSyntax();
1652  exit(1);
1653  }
1654  // Extract energy spectra for all specified neutrino species
1655  TFile flux_file(gOptFluxFile.c_str(), "read");
1656  for(unsigned int inu=1; inu<fluxv.size(); inu++) {
1657  string nutype_and_histo = fluxv[inu];
1658  string::size_type open_bracket = nutype_and_histo.find("[");
1659  string::size_type close_bracket = nutype_and_histo.find("]");
1660  if (open_bracket ==string::npos ||
1661  close_bracket==string::npos)
1662  {
1663  LOG("gevgen_fnal", pFATAL)
1664  << "You made an error in specifying the flux histograms";
1665  PrintSyntax();
1666  exit(1);
1667  }
1668  string::size_type ibeg = 0;
1669  string::size_type iend = open_bracket;
1670  string::size_type jbeg = open_bracket+1;
1671  string::size_type jend = close_bracket;
1672  string nutype = nutype_and_histo.substr(ibeg,iend-ibeg);
1673  string histo = nutype_and_histo.substr(jbeg,jend-jbeg);
1674  // access specified histogram from the input root file
1675  TH1D * ihst = (TH1D*) flux_file.Get(histo.c_str());
1676  if(!ihst) {
1677  LOG("gevgen_fnal", pFATAL)
1678  << "Can not find histogram: " << histo
1679  << " in flux file: " << gOptFluxFile;
1680  PrintSyntax();
1681  exit(1);
1682  }
1683 
1684  // Copy in the flux histogram from the root file
1685  // use Clone rather than assuming fix bin widths and rebooking
1686  TH1D* spectrum = (TH1D*)ihst->Clone();
1687  spectrum->SetNameTitle("spectrum","neutrino_flux");
1688  spectrum->SetDirectory(0);
1689  //// and remove bins outside the emin,emax range (not for gFNALExptEvGen)
1690  //for(int ibin = 1; ibin <= hst->GetNbinsX(); ibin++) {
1691  // if(hst->GetBinLowEdge(ibin) + hst->GetBinWidth(ibin) > emax ||
1692  // hst->GetBinLowEdge(ibin) < emin) {
1693  // spectrum->SetBinContent(ibin, 0);
1694  // }
1695  //}
1696 
1697  // get rid of original
1698  delete ihst;
1699 
1700  // convert neutrino name -> pdg code
1701  int pdg = atoi(nutype.c_str());
1702  if(!pdg::IsNeutrino(pdg) && !pdg::IsAntiNeutrino(pdg)) {
1703  LOG("gevgen_fnal", pFATAL)
1704  << "Unknown neutrino type: " << nutype;
1705  PrintSyntax();
1706  exit(1);
1707  }
1708  // store flux neutrino code / energy spectrum
1709  LOG("gevgen_fnal", pDEBUG)
1710  << "Adding energy spectrum for flux neutrino: pdg = " << pdg;
1711  gOptFluxHst.insert(map<int, TH1D*>::value_type(pdg, spectrum));
1712  }//inu
1713 
1714  if(gOptFluxHst.size()<1) {
1715  LOG("gevgen_fnal", pFATAL)
1716  << "You have not specified any flux histogram!";
1717  PrintSyntax();
1718  exit(1);
1719  }
1720 
1721  flux_file.Close();
1722 }
string gOptFluxFile
bool IsNeutrino(int pdgc)
Definition: PDGUtils.cxx:107
#define pFATAL
Definition: Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool IsAntiNeutrino(int pdgc)
Definition: PDGUtils.cxx:115
void PrintSyntax(void)
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
map< int, TH1D * > gOptFluxHst
#define pDEBUG
Definition: Messenger.h:63
void PrintSyntax ( void  )

Definition at line 1090 of file gEvGenLArDM.cxx.

1091 {
1092  LOG("gevgen_lardm", pFATAL)
1093  << "\n **Syntax**"
1094  << "\n gevgen_lardm [-h] [-r run#]"
1095  << "\n -f flux -g geometry -M dm_mass"
1096  << "\n [-c zp_coupling] [-v med_ratio]"
1097  << "\n [-t top_volume_name_at_geom] [-m max_path_lengths_xml_file]"
1098  << "\n [-L length_units_at_geom] [-D density_units_at_geom]"
1099  << "\n [-n n_of_events] "
1100  << "\n [-o output_event_file_prefix]"
1101  << "\n [-F fid_cut_string] [-S nrays_scan]"
1102  << "\n [-z zmin_start]"
1103  << "\n [--seed random_number_seed]"
1104  << "\n --cross-sections xml_file"
1105  << "\n [--event-generator-list list_name]"
1106  << "\n [--message-thresholds xml_file]"
1107  << "\n [--unphysical-event-mask mask]"
1108  << "\n [--event-record-print-level level]"
1109  << "\n [--mc-job-status-refresh-rate rate]"
1110  << "\n [--cache-file root_file]"
1111  << "\n"
1112  << " Please also read the detailed documentation at "
1113  << "$GENIE/src/Apps/gFNALExptEvGen.cxx"
1114  << "\n";
1115 }
#define pFATAL
Definition: Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96

Variable Documentation

int gOptDebug = 0

Definition at line 370 of file gEvGenLArDM.cxx.

double gOptDMMass

Definition at line 351 of file gEvGenLArDM.cxx.

string gOptEvFilePrefix

Definition at line 369 of file gEvGenLArDM.cxx.

string gOptExtMaxPlXml = ""

Definition at line 361 of file gEvGenLArDM.cxx.

string gOptFidCut

Definition at line 366 of file gEvGenLArDM.cxx.

string gOptFluxFile

Definition at line 364 of file gEvGenLArDM.cxx.

double gOptGeomDUnits = 0

Definition at line 360 of file gEvGenLArDM.cxx.

double gOptGeomLUnits = 0

Definition at line 359 of file gEvGenLArDM.cxx.

string gOptInpXSecFile

Definition at line 372 of file gEvGenLArDM.cxx.

double gOptMedRatio

Definition at line 352 of file gEvGenLArDM.cxx.

int gOptNev

Definition at line 365 of file gEvGenLArDM.cxx.

int gOptNScan = 0

Definition at line 367 of file gEvGenLArDM.cxx.

long int gOptRanSeed

Definition at line 371 of file gEvGenLArDM.cxx.

string gOptRootGeom

Definition at line 356 of file gEvGenLArDM.cxx.

string gOptRootGeomMasterVol = ""

Definition at line 358 of file gEvGenLArDM.cxx.

string gOptRootGeomTopVol = ""

Definition at line 357 of file gEvGenLArDM.cxx.

Long_t gOptRunNu

Definition at line 353 of file gEvGenLArDM.cxx.

map<int,double> gOptTgtMix

Definition at line 355 of file gEvGenLArDM.cxx.

bool gOptUsingRootGeom = false

Definition at line 354 of file gEvGenLArDM.cxx.

bool gOptWriteMaxPlXml = false

Definition at line 362 of file gEvGenLArDM.cxx.

double gOptZmin = -2.0e30

Definition at line 368 of file gEvGenLArDM.cxx.

double gOptZpCoupling

Definition at line 350 of file gEvGenLArDM.cxx.

bool gSigTERM = false

Definition at line 374 of file gEvGenLArDM.cxx.

string kDefOptEvFilePrefix = "gntp"

Definition at line 346 of file gEvGenLArDM.cxx.

string kDefOptGeomDUnits = "g_cm3"

Definition at line 344 of file gEvGenLArDM.cxx.

string kDefOptGeomLUnits = "mm"

Definition at line 343 of file gEvGenLArDM.cxx.

NtpMCFormat_t kDefOptNtpFormat = kNFGHEP

Definition at line 345 of file gEvGenLArDM.cxx.