GENIEGenerator
Loading...
Searching...
No Matches
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-2025, 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
44TRandom3 generator(0);
45const Int_t setID = 0;
46
47//==============================================================================
48// Control
49//==============================================================================
50const int maxArray = 30;
51const int maxC = 100;
52
53//==============================================================================
54// Function Declaration
55//==============================================================================
56void InitialiseMetaBranches(TTree * meta);
57void InitialiseTreeBranches(TTree * tree);
58void FillMetaBranches(bsim::DkMeta * dkmeta);
59void FillTreeBranches(bsim::Dk2Nu * dk2nu);
60void LoopEntries(TChain* cflux, TChain* dflux, bool grid, bool debug);
61void RootifyChar( std::string rfch, char fdch[maxC] );
62void LoadDetectorPosition( bool grid, genie::GFluxI * gfluxdriver );
63
64//==============================================================================
65// Directories, locations
66//==============================================================================
67const std::string USER = std::getenv("USER") != NULL ? string(std::getenv("USER")) : "user";
68const std::string OUTDIR = std::getenv("OUTDIR") != NULL ? string(std::getenv("OUTDIR")) : string(std::getenv("PWD"));
69const std::string SAMPLEDK2NU = std::getenv("INDIR") != NULL ? string(std::getenv("INDIR"))+"/sample_dk2nu.root" : string(std::getenv("PWD"))+"/sample_dk2nu.root";
70
71const std::string INDIR_GRID = "";
72const std::string OUTDIR_GRID = "";
73
74const std::string INDIR_DEBUG = "./DEBUG";
75
76const std::string GDK2NU_PSET = "MINERVA-v10r8";
77
78//==============================================================================
79// Input files: playlist location + length
80//==============================================================================
81const 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
90TTree * dkMeta = 0;
91
92int mArSize = 0; // Size of location arrays
93int mJob = 0; // Simulation job number
94double mPots = 0.0; // Number of POT simulated
95char mBeamsim[maxC]; // Describes the simulation that generated the file
96char mPhysics[maxC]; // Describes the geant version and physics list
97char mPhyscuts[maxC]; // Describes geant4 tracking cuts
98char mTgtcfg[maxC]; // Describes target configuation
99char mHorncfg[maxC]; // Describes horn configuration
100char mDkvolcfg[maxC]; // Describes decay pipe configuration
101double mBeam0x = 0.0; // Initial x position of primary p in cm
102double mBeam0y = 0.0; // Initial y position of primary p in cm
103double mBeam0z = 0.0; // Initial z position of primary p in cm
104double mBeamhwidth = 0.0; // Beam horizontal radius (rms) in cm
105double mBeamvwidth = 0.0; // Beam vertical radius (rms) in cm
106double mBeamdxdz = 0.0; // Initial p dx/dz
107double mBeamdydz = 0.0; // Initial p dy/dz
108double mLocationDotX[maxArray]; // x position of locations in cm
109double mLocationDotY[maxArray]; // y position of locations in cm
110double mLocationDotZ[maxArray]; // z position of locations in cm
111char 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
117TTree * dkTree = 0;
118
119int dArSize = 0; // Size of location arrays
120int dAnArSize = 0; // Size of ancestor arrays
121int dTrArSize = 0; // Size of traj arrays
122// - - -
123int dJob = 0; // Simulation job number
124double dPotnum = 0.0; // N POT for this v (0 job-beginning, total POT job-end)
125double dPpvx = 0.0; // x component of v parent production vertex in cm
126double dPpvy = 0.0; // y component of v parent production vertex in cm
127double dPpvz = 0.0; // z component of v parent production vertex in cm
128// - - -
129int dDecayDotNorig = 0; // v origin (1,2,3 = tgt/baffle, muon decay, other)
130int dDecayDotNdecay = 0; // Decay code of decay that produced v
131int dDecayDotNtype = 0; // GEANT particle code of v
132double dDecayDotVx = 0.0; // x component of v vertex position in cm
133double dDecayDotVy = 0.0; // y component of v vertex position in cm
134double dDecayDotVz = 0.0; // z component of v vertex position in cm
135double dDecayDotPdpx = 0.0; // x component of final parent momentum in GeV
136double dDecayDotPdpy = 0.0; // y component of final parent momentum in GeV
137double dDecayDotPdpz = 0.0; // z component of final parent momentum in GeV
138double dDecayDotPpdxdz = 0.0; // px/pz of parent at parent production point
139double dDecayDotPpdydz = 0.0; // py/pz of parent at parent production point
140double dDecayDotPppz = 0.0; // pz of parent at parent production point in GeV
141double dDecayDotPpenergy = 0.0; // E of parent at parent production point in GeV
142int dDecayDotPpmedium = 0; // empty branch
143int dDecayDotPtype = 0; // GEANT particle code of parent
144double dDecayDotMuparpx = 0.0; // (parent == mu) ? grandparent px in GeV : -99999
145double dDecayDotMuparpy = 0.0; // (parent == mu) ? grandparent py in GeV : -99999
146double dDecayDotMuparpz = 0.0; // (parent == mu) ? grandparent pz in GeV : -99999
147double dDecayDotMupare = 0.0; // (parent == mu) ? grandparent E in GeV : -99999
148double dDecayDotNecm = 0.0; // v E in parent rest frame in GeV
149double dDecayDotNimpwt = 0.0; // Importance weight
150// - - -
151double dNurayDotPx[maxArray]; // v px in GeV for each location in meta
152double dNurayDotPy[maxArray]; // v py in GeV for each location in meta
153double dNurayDotPz[maxArray]; // v pz in GeV for each location in meta
154double dNurayDotE[maxArray]; // v E in GeV for each location in meta
155double dNurayDotWgt[maxArray]; // weights to make v flux spectra for each location in meta
156// - - -
157int dAncestorDotPdg[maxArray]; // PDG code of ancestor
158double dAncestorDotStartx[maxArray]; // x component of ancestor start position in cm
159double dAncestorDotStarty[maxArray]; // y component of ancestor start position in cm
160double dAncestorDotStartz[maxArray]; // z component of ancestor start position in cm
161double dAncestorDotStartt[maxArray]; // t component of ancestor start position in (ns ?)
162double dAncestorDotStartpx[maxArray]; // ancestor initial px in GeV
163double dAncestorDotStartpy[maxArray]; // ancestor initial py in GeV
164double dAncestorDotStartpz[maxArray]; // ancestor initial pz in GeV
165double dAncestorDotStoppx[maxArray]; // ancestor final px in GeV
166double dAncestorDotStoppy[maxArray]; // ancestor final py in GeV
167double dAncestorDotStoppz[maxArray]; // ancestor final pz in GeV
168double dAncestorDotPolx[maxArray]; // empty branch
169double dAncestorDotPoly[maxArray]; // empty branch
170double dAncestorDotPolz[maxArray]; // empty branch
171double dAncestorDotPprodpx[maxArray]; // parent px prior to secondaries production (meaning?)
172double dAncestorDotPprodpy[maxArray]; // parent py prior to secondaries production (meaning?)
173double dAncestorDotPprodpz[maxArray]; // parent pz prior to secondaries production (meaning?)
174int dAncestorDotNucleus[maxArray]; // PDG code of nucleus where the interaction happened
175char dAncestorDotProc[maxArray*maxC]; // Describes processes that created each ancestor
176char dAncestorDotIvol[maxArray*maxC]; // Describes volume where each ancestor was created
177char dAncestorDotImat[maxArray*maxC]; // Describes material where each ancestor was created
178// - - -
179double dTgtexitDotTvx = 0.0; // x position of parent target exit in cm
180double dTgtexitDotTvy = 0.0; // y position of parent target exit in cm
181double dTgtexitDotTvz = 0.0; // z position of parent target exit in cm
182double dTgtexitDotTpx = 0.0; // parent px at target exit in GeV
183double dTgtexitDotTpy = 0.0; // parent py at target exit in GeV
184double dTgtexitDotTpz = 0.0; // parent pz at target exit in GeV
185int dTgtexitDotTptype = 0; // GEANT particle code of ancestor that exited target
186int dTgtexitDotTgen = 0; // Generation number of v
187// - - -
194// - - -
195//int dFlagbits = 0; // extra user container
196//std::vector<int> dVint; // ppfx specific
197//std::vector<double> dVdbl; // ppfx specific
198
199void LoadDetectorPosition(bool grid, genie::GFluxI* gfluxdriver)
200{
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
GENIE Interface for user-defined flux classes.
Definition GFluxI.h:29
virtual void LoadBeamSimData(const std::vector< std::string > &filenames, const std::string &det_loc)=0
int dAnArSize
void RootifyChar(std::string rfch, char fdch[maxC])
double dTgtexitDotTpz
double dDecayDotMuparpz
double dDecayDotMuparpx
double dDecayDotPdpy
const int maxArray
double dAncestorDotStoppy[maxArray]
double dAncestorDotStartpy[maxArray]
char dAncestorDotProc[maxArray *maxC]
double dTrajDotTrkz[maxArray]
double mLocationDotX[maxArray]
void FillMetaBranches(bsim::DkMeta *dkmeta)
double dDecayDotNimpwt
int dTgtexitDotTptype
double dAncestorDotStartx[maxArray]
const std::string OUTDIR
double dDecayDotVy
double dTgtexitDotTvy
int dArSize
int mJob
double dTgtexitDotTpx
char mPhyscuts[maxC]
const std::string SAMPLEDK2NU
double dAncestorDotPprodpy[maxArray]
double dAncestorDotStoppx[maxArray]
int dAncestorDotNucleus[maxArray]
TRandom3 generator(0)
double dTgtexitDotTpy
double mLocationDotY[maxArray]
double dDecayDotPppz
TTree * dkTree
double dPpvz
double mBeam0x
void InitialiseTreeBranches(TTree *tree)
double dAncestorDotStartpx[maxArray]
char dAncestorDotIvol[maxArray *maxC]
int dTrArSize
double dTrajDotTrkx[maxArray]
double mBeam0z
char mLocationDotName[maxC *maxArray]
double dDecayDotVz
double dPotnum
double dAncestorDotPprodpz[maxArray]
double dPpvx
double dAncestorDotPoly[maxArray]
double dNurayDotPz[maxArray]
int dJob
double dDecayDotMuparpy
void InitialiseMetaBranches(TTree *meta)
double dDecayDotPpdydz
char mPhysics[maxC]
double dNurayDotWgt[maxArray]
double dDecayDotNecm
int dDecayDotPtype
int dDecayDotNorig
double dDecayDotPdpz
int dDecayDotNdecay
double dAncestorDotStoppz[maxArray]
double dDecayDotVx
void LoopEntries(TChain *cflux, TChain *dflux, bool grid, bool debug)
double mLocationDotZ[maxArray]
char mBeamsim[maxC]
double dDecayDotPpenergy
double dDecayDotPdpx
double mBeamdxdz
double dTgtexitDotTvx
char dAncestorDotImat[maxArray *maxC]
double mBeam0y
const std::string INDIR_DEBUG
TTree * dkMeta
double dTrajDotTrky[maxArray]
double dAncestorDotPolx[maxArray]
double dDecayDotPpdxdz
double dAncestorDotStarty[maxArray]
const std::string OUTDIR_GRID
double mPots
double dNurayDotPx[maxArray]
double dTrajDotTrkpz[maxArray]
char mDkvolcfg[maxC]
void LoadDetectorPosition(bool grid, genie::GFluxI *gfluxdriver)
const std::string INDIR_GRID
int mArSize
int dTgtexitDotTgen
const int m_maxNFiles
double dTgtexitDotTvz
const std::string USER
char mHorncfg[maxC]
const std::string GDK2NU_PSET
double dAncestorDotStartt[maxArray]
double dTrajDotTrkpx[maxArray]
const int maxC
double dDecayDotMupare
double dNurayDotE[maxArray]
double dAncestorDotPprodpx[maxArray]
char mTgtcfg[maxC]
double dAncestorDotStartz[maxArray]
int dDecayDotNtype
void FillTreeBranches(bsim::Dk2Nu *dk2nu)
double mBeamdydz
int dDecayDotPpmedium
double dNurayDotPy[maxArray]
double mBeamhwidth
const Int_t setID
double dTrajDotTrkpy[maxArray]
double dAncestorDotPolz[maxArray]
double dAncestorDotStartpz[maxArray]
int dAncestorDotPdg[maxArray]
double mBeamvwidth
double dPpvy