aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2020-08-31 09:33:03 -0500
committertlatorre <tlatorre@uchicago.edu>2020-08-31 09:33:03 -0500
commitc2fea4840ee186eb87ede9f3ed91cfe60b118371 (patch)
tree085c9d4b5702067bf573fe77e148e8886d52a3f3
parent4f36a14711c1d677ea86e2f7ae68ed01a4ed2c70 (diff)
downloadsddm-c2fea4840ee186eb87ede9f3ed91cfe60b118371.tar.gz
sddm-c2fea4840ee186eb87ede9f3ed91cfe60b118371.tar.bz2
sddm-c2fea4840ee186eb87ede9f3ed91cfe60b118371.zip
add a script to convert genie reweight file from ROOT -> HDF5
-rwxr-xr-xutils/convert-genie-rw51
1 files changed, 51 insertions, 0 deletions
diff --git a/utils/convert-genie-rw b/utils/convert-genie-rw
new file mode 100755
index 0000000..d18c2a3
--- /dev/null
+++ b/utils/convert-genie-rw
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# Copyright (c) 2020, Anthony Latorre <tlatorre at uchicago>
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <https://www.gnu.org/licenses/>.
+"""
+Script to do convert GENIE reweight ROOT files into HDF5 files. To run it just
+run:
+
+ $ ./convert-genie-rw [filename] -o [output filename]
+"""
+from __future__ import print_function, division
+import ROOT
+
+if __name__ == '__main__':
+ import argparse
+ import sys
+ import h5py
+ import numpy as np
+
+ parser = argparse.ArgumentParser("convert GENIE reweight files from ROOT -> HDF5")
+ parser.add_argument("filename", help="input filename")
+ parser.add_argument("-o", "--output", required=True, help="output filename")
+ args = parser.parse_args()
+
+ f = ROOT.TFile(args.filename)
+ weights = f.Get("weights")
+
+ weights.GetEntry(0)
+ nuniverses = len(weights.weights)
+
+ data = np.empty(weights.GetEntries()*nuniverses,dtype=[('run',np.int32),('evn',np.int32),('universe',np.int32),('weight',np.float32)])
+
+ for i, event in enumerate(weights):
+ for j in range(nuniverses):
+ data[i*nuniverses+j] = event.runnum, event.eventnum, j, event.weights[j]
+
+ f.Close()
+
+ with h5py.File(args.output,"w") as fout:
+ fout.create_dataset('weights',data=data)