SND@LHC Software
Loading...
Searching...
No Matches
makeSNDGenieEvents.py
Go to the documentation of this file.
1#!/usr/bin/env python
2import ROOT, os, sys, time
3import argparse
4import genie_interface
5
6# NOTE: before running this script export GALGCONF env variable to extend energy to SND range. Example:
7# export GALGCONF=/eos/experiment/ship/user/aiuliano/GENIE_input_SND/config
8
9defaultfiledir = "/eos/experiment/ship/user/aiuliano/GENIE_input_SND/NeutrinoFiles/"
10defaultsplinedir = (
11 "/eos/experiment/ship/user/aiuliano/GENIE_input_SND/SplinesTungstenTP/"
12)
13names = {14: "numu", 12: "nue", 16: "nutau", -14: "anumu", -12: "anue", -16: "anutau"}
14filenames = {
15 14: "NeutMuon",
16 12: "NeutElec",
17 16: "NeutTau_filter",
18 -14: "AntiNeutMuon",
19 -12: "AntiNeutElec",
20 -16: "AntiNeutTau_filter",
21}
22
23
24def init(): # available options
25 parser = argparse.ArgumentParser(description="Run GENIE neutrino simulation")
26 subparsers = parser.add_subparsers()
27
28 ap = subparsers.add_parser("sim", help="make genie simulation file")
29
30 ap.add_argument("--nupdg", type=str, dest="nupdg", default=None)
31 ap.add_argument("-n", "--nevents", type=int, dest="nevents", default=1000)
32 ap.add_argument(
33 "-f",
34 "--filedir",
35 type=str,
36 help="directory with neutrino fluxes",
37 dest="filedir",
38 default=defaultfiledir,
39 )
40 ap.add_argument(
41 "-c",
42 "--crosssectiondir",
43 type=str,
44 help="directory with neutrino splines crosssection",
45 dest="splinedir",
46 default=defaultsplinedir,
47 )
48 ap.add_argument(
49 "-o", "--output", type=str, help="output directory", dest="outdir", default=None
50 )
51 ap.add_argument(
52 "-p",
53 "--process",
54 type=str,
55 help="which interaction process",
56 dest="process",
57 default=None,
58 )
59 ap.add_argument(
60 "-s", "--seed", type=int, dest="seed", default=65539
61 ) # default seed in $GENIE/src/Conventions/Controls.h
62 ap.add_argument(
63 "-t",
64 "--target",
65 type=str,
66 help="target material",
67 dest="target",
68 default="tungstenTP",
69 )
70
71 ap1 = subparsers.add_parser("spline", help="make a new cross section spline file")
72 ap1.add_argument("--nupdg", type=str, dest="nupdg", default=None)
73 ap1.add_argument(
74 "-t",
75 "--target",
76 type=str,
77 help="target material",
78 dest="target",
79 default="tungstenTP",
80 )
81 ap1.add_argument(
82 "-o", "--output", type=str, help="output directory", dest="outdir", default=None
83 )
84 args = parser.parse_args()
85 return args
86
87
88if __name__ == "__main__":
89 args = init()
90 if os.path.exists(
91 args.outdir
92 ): # if the directory is already there, leave a warning, otherwise create it
93 print("output directory already exists.")
94 else:
95 os.makedirs(args.outdir)
96
97 os.chdir(args.outdir)
98
99 nupdg = int(args.nupdg)
100
101 print("Neutrino PDG code: ", nupdg)
102
103 if "GALGCONF" not in os.environ:
104 sys.exit(
105 "GALGCONF is not set to a conf folder: need to configure GENIE for SND high energies!"
106 )
107
108 if nupdg == None:
109 print("Please specify the neutrino type!")
110 sys.exit("Aborting code")
111
112 if args.target == "tungstenTP":
113 targetcode = "1000741840[0.95],1000280580[0.03],1000290630[0.02]"
114 elif args.target == "tungstenEOI":
115 targetcode = "1000741840[0.9],1000280580[0.1]"
116 else:
117 print("no other cross-sections available!")
118
119 if "nevents" in args:
120
121 print("Number of events to generate: ", args.nevents)
122 print("Process to simulate: ", args.process)
123 print("Target type: ", args.target)
124 print("Seed used in this generation: ", args.seed)
125
126 nevents = int(args.nevents)
127 if args.process == None:
128 print("no process selected, generating with default GENIE processes")
129
130 # Getting input flux and spline path
131 inputfile = args.filedir + filenames[nupdg] + ".root"
132 spline = args.splinedir + names[nupdg] + "_xsec_splines.xml"
133 # setting path of outputfile
134 outputfile = names[nupdg] + "_" + args.process + "_FairShip.root"
135 # generating GENIE simulation
137 nevents=nevents,
138 nupdg=nupdg,
139 emin=0,
140 emax=5000,
141 targetcode=targetcode,
142 inputflux=inputfile,
143 spline=spline,
144 process=args.process,
145 seed=args.seed,
146 )
147 # converting GENIE simulation into FairShip compatible format
148 genie_interface.make_ntuples("gntp.0.ghep.root", outputfile)
149
150 # adding histograms
151 genie_interface.add_hists(inputflux=inputfile, simfile=outputfile, nupdg=nupdg)
152
153 else:
154 # setting path of outputfile
155 outputfile = names[nupdg] + "_xsec_splines.xml"
156 # generating new set of splines, saving them in outputdir
157 nupdglist = [nupdg]
159 nupdglist=nupdglist,
160 targetcode=targetcode,
161 emax=5000,
162 nknots=100,
163 outputfile=outputfile,
164 )
make_ntuples(inputfile, outputfile)
make_splines(nupdglist, targetcode, emax, nknots, outputfile)
generate_genie_events(nevents, nupdg, emin, emax, targetcode, inputflux, spline, process=None, seed=None, irun=None)
add_hists(inputflux, simfile, nupdg)