GENIEHelper.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file GENIEHelper.h
3 /// \brief Wrapper for generating neutrino interactions with GENIE
4 ///
5 /// \version $Id: GENIEHelper.h,v 1.25 2012-09-07 21:35:26 brebel Exp $
6 /// \author brebel@fnal.gov rhatcher@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 #ifndef EVGB_GENIEHELPER_H
9 #define EVGB_GENIEHELPER_H
10 
11 #include <vector>
12 #include <set>
13 
14 
15 // GENIE
16 //#include "EVGDrivers/GFluxI.h" # R-3 "Framework/EventGen/GFluxI.h"
17 //#include "EVGDrivers/GeomAnalyzerI.h" # R-3 "Framework/EventGen/GeomAnalyzerI.h"
18 //#include "EVGDrivers/GMCJDriver.h" # R-3 "Framework/EventGen/GMCJDriver.h"
19 namespace genie {
20  class GFluxI;
21  class GeomAnalyzerI;
22  class GMCJDriver;
23 }
24 
25 // ROOT
26 class TH1D;
27 class TH2D;
28 class TF1;
29 class TRandom3;
30 class TRotation;
31 class TGeoManager;
32 #include "TVector3.h"
33 
34 ///parameter set interface
35 namespace fhicl {
36  class ParameterSet;
37 }
38 
39 /// IFDH interface (data handling) ... if using bare interface
40 namespace ifdh_ns {
41  class ifdh;
42 }
43 
44 namespace simb {
45  class MCTruth;
46  class MCFlux;
47  class GTruth;
48 }
49 
50 ///GENIE neutrino interaction simulation
51 namespace genie { class EventRecord; }
52 
53 namespace evgb {
54 
55  class EvtTimeShiftI; // for shifting time within a spill
56 
57  class GENIEHelper {
58 
59  public:
60 
61  explicit GENIEHelper(fhicl::ParameterSet const& pset,
62  TGeoManager* rootGeom,
63  std::string const& rootFile,
64  double const& detectorMass);
65  ~GENIEHelper();
66 
67  void Initialize();
68  bool Stop();
69  bool Sample(simb::MCTruth &truth,
70  simb::MCFlux &flux,
71  simb::GTruth &gtruth);
72 
73  double TotalHistFlux();
74  double TotalExposure() const { return fTotalExposure; }
75 
76  // Call the following method before calling Stop, otherwise fSpillExposure
77  // will be reset to 0
78  double SpillExposure() const { return fSpillExposure; }
79  std::string FluxType() const { return fFluxType; }
80  std::string DetectorLocation() const { return fDetLocation; }
81 
82  // methods for checking the various algorithms in GENIEHelper - please
83  // do not use these in your code!!!!!
84  std::vector<TH1D*> FluxHistograms() const { return fFluxHistograms; }
85  double TotalMass() const { return fDetectorMass+fSurroundingMass; }
86 
87  genie::EventRecord * GetGenieEventRecord() { return fGenieEventRecord; }
88 
89  // access the random number generator that is supplying additional values for helper
90  TRandom3* GetHelperRandom() { return fHelperRandom; }
91 
92  // direct access to flux driver ... no ownership handover
93  // base is the "real" flux driver, might be wrapped by a flavor mixer
95  { return ( (base) ? fFluxD : fFluxD2GMCJD ); }
96 
97  // these might be updated after parsing the parameter set in init()
98  std::string GetTuneName() const { return fTuneName; }
99  std::string GetEventGeneratorList() const { return fEventGeneratorList; }
100 
101  private:
102 
103  void RegularizeFluxType();
104  void SqueezeFilePatterns();
105  void AtmoFluxCheck();
106  void HistogramFluxCheck();
107 
108  void InitializeGeometry();
109  void InitializeFiducialSelection();
110  void InitializeRockBoxSelection();
111  void InitializeFluxDriver();
112  void ConfigGeomScan();
113  void SetMaxPathOutInfo();
114 
115  void PackNuMIFlux(simb::MCFlux &flux);
116  void PackSimpleFlux(simb::MCFlux &flux);
117  void PackMCTruth(genie::EventRecord *record, simb::MCTruth &truth);
118  void PackGTruth(genie::EventRecord *record, simb::GTruth &truth);
119 
120  void BuildFluxRotation();
121  void ExpandFluxPaths();
122  void ExpandFluxFilePatternsDirect();
123  void ExpandFluxFilePatternsIFDH();
124  bool StringToBool(std::string v);
125 
126  void SetGXMLPATH();
127  void SetGMSGLAYOUT();
128  void StartGENIEMessenger(std::string prodmode);
129  void ReadXSecTable();
130 
131  TGeoManager* fGeoManager; ///< pointer to ROOT TGeoManager
132  std::string fGeoFile; ///< name of file containing the Geometry description
133 
134  genie::EventRecord* fGenieEventRecord; ///< last generated event
136  genie::GFluxI* fFluxD; ///< real flux driver
137  genie::GFluxI* fFluxD2GMCJD; ///< flux driver passed to genie GMCJDriver, might be GFluxBlender
139 
140  // for now leave this here ... but not necessary when using IFDH_service
141  ifdh_ns::ifdh* fIFDH; ///< (optional) flux file handling
142 
143  TRandom3* fHelperRandom; ///< random # generator for GENIEHelper
144  bool fUseHelperRndGen4GENIE; ///< use fHelperRandom for gRandom during Sample()
145  evgb::EvtTimeShiftI* fTimeShifter; ///< generator for time offset within a spill
146 
147  std::string fFluxType; ///< histogram, gsimple, dk2nu, ntuple/gnumi, atmos_XXXX
148  /// atmo_{FLUKA|BARTOL/BGLRS|HONDA/HAKKM}
149 
150  std::string fFluxSearchPaths; ///< colon separated set of path stems
151  std::vector<std::string> fFluxFilePatterns; ///< wildcard patterns files containing histograms or ntuples, or txt
152  std::vector<std::string> fSelectedFluxFiles; ///< flux files selected after wildcard expansion and subset selection
153  int fMaxFluxFileMB; ///< maximum size of flux files (MB)
154  int fMaxFluxFileNumber; ///< maximum # of flux files
155  std::string fFluxCopyMethod; ///< "DIRECT" = old direct access method, otherwise = ifdh approach schema ("" okay)
156  std::string fFluxCleanup; ///< "ALWAYS", "/var/tmp", "NEVER"
157  std::string fBeamName; ///< name of the beam we are simulating
158  std::string fFluxRotCfg; ///< how to interpret fFluxRotValues
159  std::vector<double> fFluxRotValues; ///< parameters for rotation
160  TRotation* fFluxRotation; ///< rotation for atmos / astro flux coord systems
161 
162  std::string fTopVolume; ///< top volume in the ROOT geometry in which to generate events
163  std::string fWorldVolume; ///< name of the world volume in the ROOT geometry
164  std::string fDetLocation; ///< name of flux window location
165  std::vector<TH1D *> fFluxHistograms; ///< histograms for each nu species
166 
167  double fFluxUpstreamZ; ///< z where flux starts from (if non-default, simple/ntuple only)
168  double fEventsPerSpill; ///< number of events to generate in each spill if not using POT/spill.
169  ///< If using Atmo, set to 1
170  double fPOTPerSpill; ///< number of pot per spill
171  double fHistEventsPerSpill;///< number of events per spill for histogram fluxes - changes each spill
172  int fSpillEvents; ///< total events for this spill
173  double fSpillExposure; ///< total exposure (i.e. pot) for this spill
174  double fTotalExposure; ///< pot used from flux ntuple
175  double fMonoEnergy; ///< energy of monoenergetic neutrinos
178  double fEmin;
179  double fEmax;
180  double fXSecMassPOT; ///< product of cross section, mass and POT/spill for histogram fluxes
181  double fTotalHistFlux; ///< total flux of neutrinos from flux histograms for used flavors
182  TVector3 fBeamDirection; ///< direction of the beam for histogram fluxes
183  TVector3 fBeamCenter; ///< center of beam for histogram fluxes - must be in meters
184  double fBeamRadius; ///< radius of cylindar for histogram fluxes - must be in meters
185  double fDetectorMass; ///< mass of the detector in kg
186  double fSurroundingMass; ///< mass of material surrounding the detector that is intercepted by
187  ///< the cylinder for the histogram flux in kg
188  double fGlobalTimeOffset; ///< overall time shift (ns) added to every particle time
189  double fRandomTimeOffset; ///< additional random time shift (ns) added to every particle time
190  std::string fSpillTimeConfig; ///< alternative to flat spill distribution
191  std::vector<int> fGenFlavors; ///< pdg codes for flavors to generate
192  double fAtmoEmin; ///< atmo: Minimum energy of neutrinos in GeV
193  double fAtmoEmax; ///< atmo: Maximum energy of neutrinos in GeV
194  double fAtmoRl; ///< atmo: radius of the sphere on where the neutrinos are generated
195  double fAtmoRt; ///< atmo: radius of the transvere (perpendicular) area on the sphere
196  ///< where the neutrinos are generated
197  std::vector<std::string> fEnvironment; ///< environmental variables and settings used by genie
198  std::string fXSecTable; ///< cross section file (was $GSPLOAD)
199  std::string fTuneName; ///< GENIE R-3 Tune name (defines model configuration)
200  std::string fEventGeneratorList;///< control over event topologies, was $GEVGL [Default]
201  std::string fGXMLPATH; ///< locations for GENIE XML files
202  std::string fGMSGLAYOUT; ///< format for GENIE log message [BASIC]|SIMPLE (SIMPLE=no timestamps)
203  std::string fGENIEMsgThresholds;///< additional XML file setting Messager level thresholds (":" separated)
204  int fGHepPrintLevel; ///< GHepRecord::SetPrintLevel(), -1=no-print
205  std::string fMixerConfig; ///< configuration string for genie GFlavorMixerI
206  double fMixerBaseline; ///< baseline distance if genie flux can't calculate it
207  std::string fFiducialCut; ///< configuration for geometry selector
208  std::string fGeomScan; ///< configuration for geometry scan to determine max pathlengths
209  std::string fMaxPathOutInfo; ///< output info if writing PathLengthList from GeomScan
210  unsigned int fDebugFlags; ///< set bits to enable debug info
211  };
212 }
213 #endif //EVGB_GENIEHELPER_H
genie::GFluxI * GetFluxDriver(bool base=true)
Definition: GENIEHelper.h:94
std::vector< std::string > fFluxFilePatterns
wildcard patterns files containing histograms or ntuples, or txt
Definition: GENIEHelper.h:151
std::string FluxType() const
Definition: GENIEHelper.h:79
bool fUseHelperRndGen4GENIE
use fHelperRandom for gRandom during Sample()
Definition: GENIEHelper.h:144
double fEventsPerSpill
Definition: GENIEHelper.h:168
std::string fDetLocation
name of flux window location
Definition: GENIEHelper.h:164
double fAtmoEmax
atmo: Maximum energy of neutrinos in GeV
Definition: GENIEHelper.h:193
int fMaxFluxFileNumber
maximum # of flux files
Definition: GENIEHelper.h:154
double fMixerBaseline
baseline distance if genie flux can&#39;t calculate it
Definition: GENIEHelper.h:206
std::string fTuneName
GENIE R-3 Tune name (defines model configuration)
Definition: GENIEHelper.h:199
IFDH interface (data handling) ... if using bare interface.
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:26
double fTotalHistFlux
total flux of neutrinos from flux histograms for used flavors
Definition: GENIEHelper.h:181
std::string string
Definition: nybbler.cc:12
ifdh_ns::ifdh * fIFDH
(optional) flux file handling
Definition: GENIEHelper.h:141
std::string fGXMLPATH
locations for GENIE XML files
Definition: GENIEHelper.h:201
std::string fFiducialCut
configuration for geometry selector
Definition: GENIEHelper.h:207
std::string DetectorLocation() const
Definition: GENIEHelper.h:80
genie::EventRecord * GetGenieEventRecord()
Definition: GENIEHelper.h:87
double fRandomTimeOffset
additional random time shift (ns) added to every particle time
Definition: GENIEHelper.h:189
TVector3 fBeamCenter
center of beam for histogram fluxes - must be in meters
Definition: GENIEHelper.h:183
double fGlobalTimeOffset
overall time shift (ns) added to every particle time
Definition: GENIEHelper.h:188
std::string fSpillTimeConfig
alternative to flat spill distribution
Definition: GENIEHelper.h:190
std::string fEventGeneratorList
control over event topologies, was $GEVGL [Default]
Definition: GENIEHelper.h:200
TGeoManager * fGeoManager
pointer to ROOT TGeoManager
Definition: GENIEHelper.h:131
std::string fGENIEMsgThresholds
additional XML file setting Messager level thresholds (":" separated)
Definition: GENIEHelper.h:203
std::vector< int > fGenFlavors
pdg codes for flavors to generate
Definition: GENIEHelper.h:191
evgb::EvtTimeShiftI * fTimeShifter
generator for time offset within a spill
Definition: GENIEHelper.h:145
genie::GMCJDriver * fDriver
Definition: GENIEHelper.h:138
double fXSecMassPOT
product of cross section, mass and POT/spill for histogram fluxes
Definition: GENIEHelper.h:180
std::vector< std::string > fSelectedFluxFiles
flux files selected after wildcard expansion and subset selection
Definition: GENIEHelper.h:152
genie::EventRecord * fGenieEventRecord
last generated event
Definition: GENIEHelper.h:134
double TotalMass() const
Definition: GENIEHelper.h:85
std::string fXSecTable
cross section file (was $GSPLOAD)
Definition: GENIEHelper.h:198
double fFluxUpstreamZ
z where flux starts from (if non-default, simple/ntuple only)
Definition: GENIEHelper.h:167
std::vector< TH1D * > fFluxHistograms
histograms for each nu species
Definition: GENIEHelper.h:165
interface for event time distribution
Definition: EvtTimeShiftI.h:29
double fSurroundingMass
Definition: GENIEHelper.h:186
A GENIE `MC Job Driver&#39;. Can be used for setting up complicated event generation cases involving deta...
Definition: GMCJDriver.h:47
double SpillExposure() const
Definition: GENIEHelper.h:78
int fGHepPrintLevel
GHepRecord::SetPrintLevel(), -1=no-print.
Definition: GENIEHelper.h:204
std::string fFluxRotCfg
how to interpret fFluxRotValues
Definition: GENIEHelper.h:158
TVector3 fBeamDirection
direction of the beam for histogram fluxes
Definition: GENIEHelper.h:182
std::string fBeamName
name of the beam we are simulating
Definition: GENIEHelper.h:157
std::string fWorldVolume
name of the world volume in the ROOT geometry
Definition: GENIEHelper.h:163
double fTotalExposure
pot used from flux ntuple
Definition: GENIEHelper.h:174
TRandom3 * fHelperRandom
random # generator for GENIEHelper
Definition: GENIEHelper.h:143
parameter set interface
std::string fTopVolume
top volume in the ROOT geometry in which to generate events
Definition: GENIEHelper.h:162
std::string GetEventGeneratorList() const
Definition: GENIEHelper.h:99
std::vector< TH1D * > FluxHistograms() const
Definition: GENIEHelper.h:84
genie::GeomAnalyzerI * fGeomD
Definition: GENIEHelper.h:135
std::string fFluxSearchPaths
colon separated set of path stems
Definition: GENIEHelper.h:150
std::string fGMSGLAYOUT
format for GENIE log message [BASIC]|SIMPLE (SIMPLE=no timestamps)
Definition: GENIEHelper.h:202
Base utilities and modules for event generation and detector simulation.
double fBeamRadius
radius of cylindar for histogram fluxes - must be in meters
Definition: GENIEHelper.h:184
std::string fMixerConfig
configuration string for genie GFlavorMixerI
Definition: GENIEHelper.h:205
genie::GFluxI * fFluxD
real flux driver
Definition: GENIEHelper.h:136
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:38
double fMonoEnergy
energy of monoenergetic neutrinos
Definition: GENIEHelper.h:175
double fDetectorMass
mass of the detector in kg
Definition: GENIEHelper.h:185
std::vector< double > fFluxRotValues
parameters for rotation
Definition: GENIEHelper.h:159
TRandom3 * GetHelperRandom()
Definition: GENIEHelper.h:90
std::vector< std::string > fEnvironment
environmental variables and settings used by genie
Definition: GENIEHelper.h:197
double TotalExposure() const
Definition: GENIEHelper.h:74
std::string fMaxPathOutInfo
output info if writing PathLengthList from GeomScan
Definition: GENIEHelper.h:209
double fSpillExposure
total exposure (i.e. pot) for this spill
Definition: GENIEHelper.h:173
double fAtmoEmin
atmo: Minimum energy of neutrinos in GeV
Definition: GENIEHelper.h:192
std::string fGeoFile
name of file containing the Geometry description
Definition: GENIEHelper.h:132
double fAtmoRl
atmo: radius of the sphere on where the neutrinos are generated
Definition: GENIEHelper.h:194
std::string GetTuneName() const
Definition: GENIEHelper.h:98
unsigned int fDebugFlags
set bits to enable debug info
Definition: GENIEHelper.h:210
Physics generators for neutrinos, cosmic rays, and others.
Definition: CRYHelper.cxx:33
std::string fFluxCopyMethod
"DIRECT" = old direct access method, otherwise = ifdh approach schema ("" okay)
Definition: GENIEHelper.h:155
std::string fFluxCleanup
"ALWAYS", "/var/tmp", "NEVER"
Definition: GENIEHelper.h:156
Defines the GENIE Geometry Analyzer Interface.
Definition: GeomAnalyzerI.h:30
Event generator information.
Definition: MCTruth.h:32
double fHistEventsPerSpill
number of events per spill for histogram fluxes - changes each spill
Definition: GENIEHelper.h:171
TRotation * fFluxRotation
rotation for atmos / astro flux coord systems
Definition: GENIEHelper.h:160
std::string fGeomScan
configuration for geometry scan to determine max pathlengths
Definition: GENIEHelper.h:208
void Initialize(void)
Definition: gEvGen.cxx:246
int fSpillEvents
total events for this spill
Definition: GENIEHelper.h:172
genie::GFluxI * fFluxD2GMCJD
flux driver passed to genie GMCJDriver, might be GFluxBlender
Definition: GENIEHelper.h:137
std::string fFunctionalFlux
Definition: GENIEHelper.h:176
int fMaxFluxFileMB
maximum size of flux files (MB)
Definition: GENIEHelper.h:153
double fPOTPerSpill
number of pot per spill
Definition: GENIEHelper.h:170
std::string fFluxType
Definition: GENIEHelper.h:147
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:37