ParseFluxesFile.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import SupernovaUtilities as utils
3 import ROOT
4 ROOT.gROOT.SetBatch(1)
5 import math
6 
7 # Begin
8 print "\nrun : --- Parse and a flux file into a 2-d histogram"
9 
10 # Parse command line options
11 from optparse import OptionParser
12 parser = OptionParser()
13 parser.add_option("-m", "--model",
14  help="which model to run, options are garching or livermore",
15  action="store",
16  type="str",
17  dest="model",
18  default="garching")
19 
20 parser.add_option("-f", "--fermi_dirac",
21  help="use a fermi-dirac parameterisaion",
22  action="store_true",
23  dest="fermi",
24  default=False)
25 
26 parser.add_option("-v", "--verbose_mode",
27  help="turn on verbose mode",
28  action="store_true",
29  dest="verbose",
30  default=False)
31 
32 (options, args) = parser.parse_args()
33 
34 print "run : --- Options:"
35 print "run : model: ", options.model
36 print "run : fermi-dirac: ", options.fermi
37 print "run : verbose mode: ", options.verbose
38 assert (options.model in ["garching", "livermore"]) or (
39  "SND" in options.model), "Unconfigured mode requested: %s" % options.model
40 
41 # Read logs
42 # Livermore and Garching data files contain similar information but in different formats
43 # therefore the first thing we do is to to consolodate these into a common format
44 # - a dictionary where the keys are the times and the value is an array of data:
45 # [L nue, L anti-nue, L nux, E nue, E anti-nue, E nux, alpha nue, alpha anti-nue, alpha nux]
46 # L = Luminosity, E = Energy
47 if options.model == "garching":
48  raw_data = utils.ReadGarchingFluxes()
49 
50  param = "alpha"
51  if options.fermi:
52  param = "fermi-dirac"
53 
54  histograms = utils.ParameterisedDataToHistograms(raw_data,
55  parameterisation=param,
56  verbose=options.verbose)
57 
58 elif options.model == "livermore":
59  raw_data = utils.ReadLivermoreFluxes()
60  histograms = utils.ParameterisedDataToHistograms(raw_data,
61  verbose=options.verbose)
62 
63 # Supernova database files come in a different format again. Rather than go via the intermediate
64 # dictionary step as we do above, just skip straight to filling the histograms.
65 elif "SND" in options.model:
66  if "integ" in options.model:
67  # These are time integrated so are only really useful as a cross check
68  # also, I haven't written the code for this so you'll get an assert
69  # fail here.
70  histograms = utils.ParseIntegratedSNDFile(options.model)
71  else:
72  histograms = utils.ParseSNDFile(options.model, verbose=options.verbose)
73 
74 # Write histograms to file
75 if options.fermi:
76  root_output_name = "./data/%s_FD_fluxes.root" % options.model
77 else:
78  root_output_name = "./data/%s_fluxes.root" % options.model
79 print "run : Writing histograms to file: %s" % root_output_name
80 root_file = ROOT.TFile(root_output_name, "RECREATE")
81 
82 for i in range(3):
83  # histograms["Time_Energy_Fluence_%i"%i].GetXaxis().SetRange(0,-1)
84  histograms["Time_Energy_Fluence_%i" % i].Write()
85  histograms["lumi_%i" % i].Write()
86  histograms["lumi_mev_%i" % i].Write()
87  histograms["E_%i" % i].Write()
88  histograms["alpha_%i" % i].Write()
89  histograms["eta_%i" % i].Write()
90  histograms["T_%i" % i].Write()
91 root_file.Close()
92 print "run : Done\n"
gm Write()