52def calculate_samp_frac(args):
53 """Read ntuple from the Geant4 simulation and calculate FCal sampling
54 fractions.
55
56 Returns (E_init, samp_frac, samp_frac_err)
57 """
58 tree_name = "tree_AS"
59 print(
"Reading tree '{}' from file '{}'...".format(tree_name, args.infile))
60
61 aan_chain = root.TChain(tree_name)
62 aan_chain.Add(args.infile)
63
64 n_event = aan_chain.GetEntries()
65
66
67 for event in aan_chain:
68 E_init = round(event.E, 2) / 1000
69 break
70
71 samp_frac = 0
72 samp_frac_sq = 0
73
74 min_eta=1000.0
75 max_eta=0.0
76
77 if args.verbose:
78 print(
"Event Active E [MeV] Total E [MeV]")
79
80
81 for event in aan_chain:
82 if args.module.lower() == "fcal1":
83 totalE = event.Calib_FCal1Active + event.Calib_FCal1Inactive
84 activeE = event.FCal1_E
85 elif args.module.lower() == "fcal2":
86 totalE = event.Calib_FCal2Active + event.Calib_FCal2Inactive
87 activeE = event.FCal2_E
88 elif args.module.lower() == "fcal3":
89 totalE = event.Calib_FCal3Active + event.Calib_FCal3Inactive
90 activeE = event.FCal3_E
91
92 samp_frac += activeE / totalE
93 samp_frac_sq += (activeE / totalE)**2
94
95 min_eta=
min(min_eta,event.Vertex_Eta)
96 max_eta=
max(max_eta,event.Vertex_Eta)
97
98 if args.verbose:
99 print(
"{:<6} {:<15g} {:<15g}".format(event.Event, activeE, totalE))
100
101 if args.verbose:
103
104
105 samp_frac /= n_event
106 samp_frac_sq /= n_event
107
108
109 samp_frac_err = math.sqrt(samp_frac_sq - samp_frac**2) / math.sqrt(n_event)
110
111 print(
"{} sampling fraction (E = {:g} GeV): {:g} +/- {:g}".format(args.module, E_init, samp_frac, samp_frac_err))
112
113
114 outfile=root.TFile.Open("SF_LAr.root","UPDATE")
115 func=root.TF1("SF_{}_eta_{:4.2f}_{:4.2f}".format(args.module,min_eta,max_eta),"pol0",min_eta,max_eta)
116 func.SetParameter(0,samp_frac)
117 func.SetParError(0,samp_frac_err)
118 func.Write()
119 outfile.Close()
120
121 return E_init, samp_frac, samp_frac_err
122
123
void print(char *figname, TCanvas *c1)