GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
write_dk2nus.h
Go to the documentation of this file.
1 //____________________________________________________________________________/*
2 /*!
3  ! This is a script to generate flat root trees from dk2nu tuples.
4  ! It copies the dk2nu structure but does away with members of bsim
5  ! so that GENIE HNL simulation can avoid having dk2nu as a compile-time package
6 
7 \author John Plows <komninos-john.plows \at physics.ox.ac.uk>
8  University of Oxford
9 
10 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
11  For the full text of the license visit http://copyright.genie-mc.org
12  */
13 //____________________________________________________________________________
14 
15 #ifndef write_dk2nus_h
16 #define write_dk2nus_h
17 
18 #include <string>
19 #include <iostream>
20 #include <iomanip>
21 #include <map>
22 #include <cstdlib>
23 #include <algorithm>
24 
25 #include "TROOT.h"
26 #include "TH1.h"
27 #include "TH2.h"
28 #include "TF1.h"
29 #include "TFile.h"
30 #include "TRandom3.h"
31 #include "TMath.h"
32 #include "TChain.h"
33 #include "TSystem.h"
34 #include "TSystemDirectory.h"
35 #include "TLorentzVector.h"
36 
37 #include "FluxDrivers/GNuMIFlux.h"
38 #include "dk2nu/genie/GDk2NuFlux.h"
39 
40 #include "tree/dk2nu.h"
41 #include "tree/calcLocationWeights.h"
42 #include "tree/dkmeta.h"
43 
44 TRandom3 generator(0);
45 const Int_t setID = 0;
46 
47 //==============================================================================
48 // Control
49 //==============================================================================
50 const int maxArray = 30;
51 const int maxC = 100;
52 
53 //==============================================================================
54 // Function Declaration
55 //==============================================================================
56 void InitialiseMetaBranches(TTree * meta);
57 void InitialiseTreeBranches(TTree * tree);
58 void FillMetaBranches(bsim::DkMeta * dkmeta);
59 void FillTreeBranches(bsim::Dk2Nu * dk2nu);
60 void LoopEntries(TChain* cflux, TChain* dflux, bool grid, bool debug);
61 void RootifyChar( std::string rfch, char fdch[maxC] );
62 void LoadDetectorPosition( bool grid, genie::GFluxI * gfluxdriver );
63 
64 //==============================================================================
65 // Directories, locations
66 //==============================================================================
67 const std::string USER = std::getenv("USER") != NULL ? string(std::getenv("USER")) : "user";
68 const std::string OUTDIR = std::getenv("OUTDIR") != NULL ? string(std::getenv("OUTDIR")) : string(std::getenv("PWD"));
69 const std::string SAMPLEDK2NU = std::getenv("INDIR") != NULL ? string(std::getenv("INDIR"))+"/sample_dk2nu.root" : string(std::getenv("PWD"))+"/sample_dk2nu.root";
70 
71 const std::string INDIR_GRID = "";
72 const std::string OUTDIR_GRID = "";
73 
74 const std::string INDIR_DEBUG = "./DEBUG";
75 
76 const std::string GDK2NU_PSET = "MINERVA-v10r8";
77 
78 //==============================================================================
79 // Input files: playlist location + length
80 //==============================================================================
81 const int m_maxNFiles = 100;
82 
83 //==============================================================================
84 // Branch names
85 // For more documentation about the meanings of these variables, visit
86 // http://cdcvs.fnal.gov/redmine/projects/lbne-beamsim/wiki/Dk2nu_ntuples
87 //==============================================================================
88 
89 // --- meta
90 TTree * dkMeta = 0;
91 
92 int mArSize = 0; // Size of location arrays
93 int mJob = 0; // Simulation job number
94 double mPots = 0.0; // Number of POT simulated
95 char mBeamsim[maxC]; // Describes the simulation that generated the file
96 char mPhysics[maxC]; // Describes the geant version and physics list
97 char mPhyscuts[maxC]; // Describes geant4 tracking cuts
98 char mTgtcfg[maxC]; // Describes target configuation
99 char mHorncfg[maxC]; // Describes horn configuration
100 char mDkvolcfg[maxC]; // Describes decay pipe configuration
101 double mBeam0x = 0.0; // Initial x position of primary p in cm
102 double mBeam0y = 0.0; // Initial y position of primary p in cm
103 double mBeam0z = 0.0; // Initial z position of primary p in cm
104 double mBeamhwidth = 0.0; // Beam horizontal radius (rms) in cm
105 double mBeamvwidth = 0.0; // Beam vertical radius (rms) in cm
106 double mBeamdxdz = 0.0; // Initial p dx/dz
107 double mBeamdydz = 0.0; // Initial p dy/dz
108 double mLocationDotX[maxArray]; // x position of locations in cm
109 double mLocationDotY[maxArray]; // y position of locations in cm
110 double mLocationDotZ[maxArray]; // z position of locations in cm
111 char mLocationDotName[maxC*maxArray]; // Location names
112 //std::vector<std::string> mLocationDotName; // works but is SLOW compared to char hack
113 //std::vector<char> mVintnames; // Names associated with Vint
114 //std::vector<char> mVdblnames; // Names associated with Vdbl
115 
116 // --- dk2nu
117 TTree * dkTree = 0;
118 
119 int dArSize = 0; // Size of location arrays
120 int dAnArSize = 0; // Size of ancestor arrays
121 int dTrArSize = 0; // Size of traj arrays
122 // - - -
123 int dJob = 0; // Simulation job number
124 double dPotnum = 0.0; // N POT for this v (0 job-beginning, total POT job-end)
125 double dPpvx = 0.0; // x component of v parent production vertex in cm
126 double dPpvy = 0.0; // y component of v parent production vertex in cm
127 double dPpvz = 0.0; // z component of v parent production vertex in cm
128 // - - -
129 int dDecayDotNorig = 0; // v origin (1,2,3 = tgt/baffle, muon decay, other)
130 int dDecayDotNdecay = 0; // Decay code of decay that produced v
131 int dDecayDotNtype = 0; // GEANT particle code of v
132 double dDecayDotVx = 0.0; // x component of v vertex position in cm
133 double dDecayDotVy = 0.0; // y component of v vertex position in cm
134 double dDecayDotVz = 0.0; // z component of v vertex position in cm
135 double dDecayDotPdpx = 0.0; // x component of final parent momentum in GeV
136 double dDecayDotPdpy = 0.0; // y component of final parent momentum in GeV
137 double dDecayDotPdpz = 0.0; // z component of final parent momentum in GeV
138 double dDecayDotPpdxdz = 0.0; // px/pz of parent at parent production point
139 double dDecayDotPpdydz = 0.0; // py/pz of parent at parent production point
140 double dDecayDotPppz = 0.0; // pz of parent at parent production point in GeV
141 double dDecayDotPpenergy = 0.0; // E of parent at parent production point in GeV
142 int dDecayDotPpmedium = 0; // empty branch
143 int dDecayDotPtype = 0; // GEANT particle code of parent
144 double dDecayDotMuparpx = 0.0; // (parent == mu) ? grandparent px in GeV : -99999
145 double dDecayDotMuparpy = 0.0; // (parent == mu) ? grandparent py in GeV : -99999
146 double dDecayDotMuparpz = 0.0; // (parent == mu) ? grandparent pz in GeV : -99999
147 double dDecayDotMupare = 0.0; // (parent == mu) ? grandparent E in GeV : -99999
148 double dDecayDotNecm = 0.0; // v E in parent rest frame in GeV
149 double dDecayDotNimpwt = 0.0; // Importance weight
150 // - - -
151 double dNurayDotPx[maxArray]; // v px in GeV for each location in meta
152 double dNurayDotPy[maxArray]; // v py in GeV for each location in meta
153 double dNurayDotPz[maxArray]; // v pz in GeV for each location in meta
154 double dNurayDotE[maxArray]; // v E in GeV for each location in meta
155 double dNurayDotWgt[maxArray]; // weights to make v flux spectra for each location in meta
156 // - - -
157 int dAncestorDotPdg[maxArray]; // PDG code of ancestor
158 double dAncestorDotStartx[maxArray]; // x component of ancestor start position in cm
159 double dAncestorDotStarty[maxArray]; // y component of ancestor start position in cm
160 double dAncestorDotStartz[maxArray]; // z component of ancestor start position in cm
161 double dAncestorDotStartt[maxArray]; // t component of ancestor start position in (ns ?)
162 double dAncestorDotStartpx[maxArray]; // ancestor initial px in GeV
163 double dAncestorDotStartpy[maxArray]; // ancestor initial py in GeV
164 double dAncestorDotStartpz[maxArray]; // ancestor initial pz in GeV
165 double dAncestorDotStoppx[maxArray]; // ancestor final px in GeV
166 double dAncestorDotStoppy[maxArray]; // ancestor final py in GeV
167 double dAncestorDotStoppz[maxArray]; // ancestor final pz in GeV
168 double dAncestorDotPolx[maxArray]; // empty branch
169 double dAncestorDotPoly[maxArray]; // empty branch
170 double dAncestorDotPolz[maxArray]; // empty branch
171 double dAncestorDotPprodpx[maxArray]; // parent px prior to secondaries production (meaning?)
172 double dAncestorDotPprodpy[maxArray]; // parent py prior to secondaries production (meaning?)
173 double dAncestorDotPprodpz[maxArray]; // parent pz prior to secondaries production (meaning?)
174 int dAncestorDotNucleus[maxArray]; // PDG code of nucleus where the interaction happened
175 char dAncestorDotProc[maxArray*maxC]; // Describes processes that created each ancestor
176 char dAncestorDotIvol[maxArray*maxC]; // Describes volume where each ancestor was created
177 char dAncestorDotImat[maxArray*maxC]; // Describes material where each ancestor was created
178 // - - -
179 double dTgtexitDotTvx = 0.0; // x position of parent target exit in cm
180 double dTgtexitDotTvy = 0.0; // y position of parent target exit in cm
181 double dTgtexitDotTvz = 0.0; // z position of parent target exit in cm
182 double dTgtexitDotTpx = 0.0; // parent px at target exit in GeV
183 double dTgtexitDotTpy = 0.0; // parent py at target exit in GeV
184 double dTgtexitDotTpz = 0.0; // parent pz at target exit in GeV
185 int dTgtexitDotTptype = 0; // GEANT particle code of ancestor that exited target
186 int dTgtexitDotTgen = 0; // Generation number of v
187 // - - -
188 double dTrajDotTrkx[maxArray]; // ?
189 double dTrajDotTrky[maxArray]; // ?
190 double dTrajDotTrkz[maxArray]; // ?
191 double dTrajDotTrkpx[maxArray]; // ?
192 double dTrajDotTrkpy[maxArray]; // ?
193 double dTrajDotTrkpz[maxArray]; // ?
194 // - - -
195 //int dFlagbits = 0; // extra user container
196 //std::vector<int> dVint; // ppfx specific
197 //std::vector<double> dVdbl; // ppfx specific
198 
199 void LoadDetectorPosition(bool grid, genie::GFluxI* gfluxdriver)
200 {
201  genie::flux::GFluxFileConfigI* gffconfig =
202  dynamic_cast<genie::flux::GFluxFileConfigI*>(gfluxdriver);
203 
204  // change FLUXFILE_GRID to your favourite grid location
205  std::string FLUXFILE_GRID = "";
206  std::string sample_rootfile = grid ? FLUXFILE_GRID : SAMPLEDK2NU;
207  sample_rootfile = gSystem->ExpandPathName(sample_rootfile.c_str());
208 
209  // this is generalized out in GFluxFileConfigI ...
210  gffconfig->LoadBeamSimData(sample_rootfile, GDK2NU_PSET);
211 
212  std::cout << "\nDetector position loaded." << std::endl;
213 }
214 
215 #endif //ifndef write_dk2nus_h
double dPpvz
Definition: write_dk2nus.h:127
double mBeam0x
Definition: write_dk2nus.h:101
int dTgtexitDotTgen
Definition: write_dk2nus.h:186
char mDkvolcfg[maxC]
Definition: write_dk2nus.h:100
virtual void LoadBeamSimData(const std::vector< std::string > &filenames, const std::string &det_loc)=0
double dAncestorDotPoly[maxArray]
Definition: write_dk2nus.h:169
double mLocationDotX[maxArray]
Definition: write_dk2nus.h:108
double dDecayDotMuparpx
Definition: write_dk2nus.h:144
const std::string GDK2NU_PSET
Definition: write_dk2nus.h:76
double dAncestorDotStartx[maxArray]
Definition: write_dk2nus.h:158
const std::string INDIR_GRID
Definition: write_dk2nus.h:71
double dAncestorDotStarty[maxArray]
Definition: write_dk2nus.h:159
int dJob
Definition: write_dk2nus.h:123
double dAncestorDotPprodpz[maxArray]
Definition: write_dk2nus.h:173
double dAncestorDotPprodpy[maxArray]
Definition: write_dk2nus.h:172
double dDecayDotVz
Definition: write_dk2nus.h:134
char mPhysics[maxC]
Definition: write_dk2nus.h:96
double mPots
Definition: write_dk2nus.h:94
char mPhyscuts[maxC]
Definition: write_dk2nus.h:97
double dDecayDotVx
Definition: write_dk2nus.h:132
TTree * dkMeta
Definition: write_dk2nus.h:90
double dDecayDotPdpx
Definition: write_dk2nus.h:135
double dDecayDotMuparpy
Definition: write_dk2nus.h:145
int dDecayDotPpmedium
Definition: write_dk2nus.h:142
double dAncestorDotPprodpx[maxArray]
Definition: write_dk2nus.h:171
double mBeamvwidth
Definition: write_dk2nus.h:105
double dDecayDotNecm
Definition: write_dk2nus.h:148
double dAncestorDotStartpy[maxArray]
Definition: write_dk2nus.h:163
const std::string INDIR_DEBUG
Definition: write_dk2nus.h:74
double dTgtexitDotTpx
Definition: write_dk2nus.h:182
double dAncestorDotStartt[maxArray]
Definition: write_dk2nus.h:161
int mJob
Definition: write_dk2nus.h:93
TTree * dkTree
Definition: write_dk2nus.h:117
double dTrajDotTrkz[maxArray]
Definition: write_dk2nus.h:190
const std::string SAMPLEDK2NU
Definition: write_dk2nus.h:69
double dTgtexitDotTvy
Definition: write_dk2nus.h:180
double mBeamdydz
Definition: write_dk2nus.h:107
double dDecayDotMuparpz
Definition: write_dk2nus.h:146
const std::string USER
Definition: write_dk2nus.h:67
double mBeam0z
Definition: write_dk2nus.h:103
double dDecayDotPdpy
Definition: write_dk2nus.h:136
char dAncestorDotImat[maxArray *maxC]
Definition: write_dk2nus.h:177
double dDecayDotPpdydz
Definition: write_dk2nus.h:139
double mBeam0y
Definition: write_dk2nus.h:102
int dTgtexitDotTptype
Definition: write_dk2nus.h:185
double dTrajDotTrkx[maxArray]
Definition: write_dk2nus.h:188
char mLocationDotName[maxC *maxArray]
Definition: write_dk2nus.h:111
double dAncestorDotStartpz[maxArray]
Definition: write_dk2nus.h:164
const Int_t setID
Definition: write_dk2nus.h:45
double mBeamhwidth
Definition: write_dk2nus.h:104
double dTrajDotTrky[maxArray]
Definition: write_dk2nus.h:189
double dPpvx
Definition: write_dk2nus.h:125
double dAncestorDotStoppx[maxArray]
Definition: write_dk2nus.h:165
TRandom3 generator(0)
double dTgtexitDotTvx
Definition: write_dk2nus.h:179
double dNurayDotPx[maxArray]
Definition: write_dk2nus.h:151
double dTrajDotTrkpz[maxArray]
Definition: write_dk2nus.h:193
double dDecayDotPdpz
Definition: write_dk2nus.h:137
int dDecayDotNdecay
Definition: write_dk2nus.h:130
int dDecayDotPtype
Definition: write_dk2nus.h:143
const int m_maxNFiles
Definition: write_dk2nus.h:81
double dAncestorDotStoppy[maxArray]
Definition: write_dk2nus.h:166
char dAncestorDotProc[maxArray *maxC]
Definition: write_dk2nus.h:175
double dAncestorDotStartz[maxArray]
Definition: write_dk2nus.h:160
int dAncestorDotNucleus[maxArray]
Definition: write_dk2nus.h:174
void FillMetaBranches(bsim::DkMeta *dkmeta)
char mBeamsim[maxC]
Definition: write_dk2nus.h:95
int dDecayDotNtype
Definition: write_dk2nus.h:131
double mBeamdxdz
Definition: write_dk2nus.h:106
const std::string OUTDIR_GRID
Definition: write_dk2nus.h:72
int dAnArSize
Definition: write_dk2nus.h:120
void FillTreeBranches(bsim::Dk2Nu *dk2nu)
char mHorncfg[maxC]
Definition: write_dk2nus.h:99
double mLocationDotY[maxArray]
Definition: write_dk2nus.h:109
double dTgtexitDotTvz
Definition: write_dk2nus.h:181
double dDecayDotPpenergy
Definition: write_dk2nus.h:141
const int maxC
Definition: write_dk2nus.h:51
double dDecayDotVy
Definition: write_dk2nus.h:133
int dTrArSize
Definition: write_dk2nus.h:121
int dDecayDotNorig
Definition: write_dk2nus.h:129
double dTgtexitDotTpy
Definition: write_dk2nus.h:183
double dAncestorDotStartpx[maxArray]
Definition: write_dk2nus.h:162
double dPotnum
Definition: write_dk2nus.h:124
void LoadDetectorPosition(bool grid, genie::GFluxI *gfluxdriver)
Definition: write_dk2nus.h:199
double dTgtexitDotTpz
Definition: write_dk2nus.h:184
void InitialiseTreeBranches(TTree *tree)
void RootifyChar(std::string rfch, char fdch[maxC])
double dNurayDotPz[maxArray]
Definition: write_dk2nus.h:153
double dDecayDotMupare
Definition: write_dk2nus.h:147
double dNurayDotWgt[maxArray]
Definition: write_dk2nus.h:155
const int maxArray
Definition: write_dk2nus.h:50
int mArSize
Definition: write_dk2nus.h:92
char mTgtcfg[maxC]
Definition: write_dk2nus.h:98
const std::string OUTDIR
Definition: write_dk2nus.h:68
double dTrajDotTrkpx[maxArray]
Definition: write_dk2nus.h:191
double dNurayDotPy[maxArray]
Definition: write_dk2nus.h:152
double dDecayDotPppz
Definition: write_dk2nus.h:140
double dDecayDotNimpwt
Definition: write_dk2nus.h:149
double dNurayDotE[maxArray]
Definition: write_dk2nus.h:154
void LoopEntries(TChain *cflux, TChain *dflux, bool grid, bool debug)
double dTrajDotTrkpy[maxArray]
Definition: write_dk2nus.h:192
char dAncestorDotIvol[maxArray *maxC]
Definition: write_dk2nus.h:176
int dArSize
Definition: write_dk2nus.h:119
double dPpvy
Definition: write_dk2nus.h:126
double dAncestorDotPolz[maxArray]
Definition: write_dk2nus.h:170
double dDecayDotPpdxdz
Definition: write_dk2nus.h:138
double dAncestorDotPolx[maxArray]
Definition: write_dk2nus.h:168
int dAncestorDotPdg[maxArray]
Definition: write_dk2nus.h:157
double mLocationDotZ[maxArray]
Definition: write_dk2nus.h:110
double dAncestorDotStoppz[maxArray]
Definition: write_dk2nus.h:167
void InitialiseMetaBranches(TTree *meta)
GENIE Interface for user-defined flux classes.
Definition: GFluxI.h:29