Belle II Software  release-05-01-25
eclChargedPidReader.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 description = """
5 This script loops over the particle hypotheses and feeds the NTuples
6 into the ROOT Selector for processing. Within this processing, histograms for EoP, etc.
7 are filled based on the reconstructed momentum and theta bins.
8 These histograms are later used as input for the PDF fitter.
9 """
10 
11 __author__ = "Caitlin MacQueen, Marco Milesi"
12 __email__ = "cmq.centaurus@gmail.com, marco.milesi@unimelb.edu.au"
13 __date__ = "June 2018"
14 
15 import os
16 import sys
17 import argparse
18 
19 parser = argparse.ArgumentParser(description=description)
20 
21 parser.add_argument("inputpath",
22  metavar="inputpath",
23  type=str,
24  help="Path to the directory where input NTuples are stored.")
25 parser.add_argument(
26  "-o",
27  "--outputpath",
28  dest="outputpath",
29  type=str,
30  action="store",
31  default=os.path.abspath(
32  os.path.curdir) +
33  "/HistosN1",
34  help="Path to the output directory with the histograms for each particle hypothesis. Default is current directory.")
35 
36 args = parser.parse_args()
37 
38 import ROOT
39 
40 # Silence ROOT!
41 ROOT.gROOT.SetBatch(True)
42 
43 g_hypotheses = [11, 13, 211, 321, 2212]
44 
45 if __name__ == "__main__":
46 
47  print("Creating output directory for histograms:\n{0}".format(os.path.abspath(args.outputpath)))
48  if not os.path.exists(args.outputpath):
49  os.makedirs(args.outputpath)
50 
51  print("Start selector...")
52 
53  selector = ROOT.TSelector.GetSelector("eclChargedPidSelector.C+")
54 
55  for hypo in g_hypotheses:
56 
57  print("Particle: {0}".format(hypo))
58  input_p = ROOT.TFile.Open("{0}/pdg{1}.root".format(args.inputpath, hypo), "READ")
59  selector.SetOutputDir(args.outputpath)
60  tree_p = input_p.Get("n1_tree")
61  tree_p.Process(selector)
62  input_p.Close()
63 
64  print("Antiparticle: {0}".format(hypo))
65  input_ap = ROOT.TFile.Open("{0}/pdganti{1}.root".format(args.inputpath, hypo), "READ")
66  selector.SetOutputDir(args.outputpath)
67  tree_ap = input_ap.Get("n1_tree")
68  tree_ap.Process(selector)
69  input_ap.Close()
70 
71  # Remove ROOT/ACliC by-products
72  for ext in ["_C.d", "_C.so", "_C_ACLiC_dict_rdict.pcm"]:
73  os.remove("{0}/eclChargedPidSelector{1}".format(os.path.abspath(os.path.curdir), ext))
74 
75  print("Done!")