Belle II Software  release-06-02-00
TRGValidation.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
10 
11 """
12 <header>
13  <input>TRGValidationGen.root</input>
14  <output>TRGValidation.root</output>
15  <contact>yinjh2012@korea.ac.kr</contact>
16  <description>makes validation plots for TRG</description>
17 </header>
18 """
19 
20 
21 import basf2
22 import ROOT
23 from ROOT import Belle2, TH1F, TFile, TNamed
24 from math import pi as PI
25 
26 Fac = 180.0 / PI
27 
28 
29 class MakePlots(basf2.Module):
30  '''
31  Make validation histograms for trg ecl/cdc/klm
32  '''
33 
34  def set_descr(self, histogram, description, check):
35  '''
36  Sets description, check and contact to validation histogram.
37  :param h validation histogram
38  :param Descr description text
39  '''
40 
41  descr = TNamed("Description", description)
42  histogram.GetListOfFunctions().Add(descr)
43  Check = TNamed("Check", check)
44  histogram.GetListOfFunctions().Add(Check)
45  contact = TNamed("Contact", "yinjh2012@korea.ac.kr")
46  histogram.GetListOfFunctions().Add(contact)
47  Meta = TNamed("MetaOptions", "shifter")
48  histogram.GetListOfFunctions().Add(Meta)
49 
50  def set_style(self, histogram, xtitle, ytitle):
51  '''
52  Sets x-y titles, and sets histogram style.
53  :param xtitle X-axis title
54  :param xtitle Y-axis title
55  '''
56 
57  histogram.GetXaxis().SetTitle(xtitle)
58  histogram.GetYaxis().SetTitle(ytitle)
59  histogram.GetYaxis().SetTitleOffset(1.4)
60  histogram.GetXaxis().SetTitleSize(0.045)
61  histogram.GetYaxis().SetLabelSize(0.020)
62  histogram.SetLineColor(ROOT.kBlack)
63 
64  def initialize(self):
65 
66  self.tfiletfile = TFile("TRGValidation.root", "recreate")
67 
68  m_dbinput = Belle2.PyDBObj("TRGGDLDBInputBits")
69  m_dbftdl = Belle2.PyDBObj("TRGGDLDBFTDLBits")
70  n_inbit = m_dbinput.getninbit()
71  n_outbit = m_dbftdl.getnoutbit()
72 
73  mc_px = "MCParticles.m_momentum_x"
74  mc_py = "MCParticles.m_momentum_y"
75  trk2d_omega = "TRGCDC2DFinderTracks.m_omega"
76  trk2d_phi = "TRGCDC2DFinderTracks.m_phi0"
77 
78  ROOT.gStyle.SetOptStat(ROOT.kFALSE)
79 
80 
81  self.hist_inbithist_inbit = TH1F("hin", "trigger input bits", 320, 0, 320)
82  self.hist_inbithist_inbit.GetXaxis().SetRangeUser(0, n_inbit)
83  self.hist_inbithist_inbit.GetXaxis().SetLabelSize(0.02)
84 
85 
86  self.hist_outbithist_outbit = TH1F("hout", "trigger output bits", 320, 0, 320)
87  self.hist_outbithist_outbit.GetXaxis().SetRangeUser(0, n_outbit)
88  self.hist_outbithist_outbit.GetXaxis().SetLabelSize(0.02)
89 
90  for i in range(320):
91  inbitname = m_dbinput.getinbitname(i)
92  outbitname = m_dbftdl.getoutbitname(i)
93  self.hist_inbithist_inbit.GetXaxis().SetBinLabel(
94  self.hist_inbithist_inbit.GetXaxis().FindBin(i + 0.5), inbitname)
95  self.hist_outbithist_outbit.GetXaxis().SetBinLabel(
96  self.hist_outbithist_outbit.GetXaxis().FindBin(i + 0.5), outbitname)
97 
98 
99  self.h_E_ECLh_E_ECL = TH1F("h_E_ECL", "ECL cluster energy [50 MeV]", 200, 0, 10)
100  self.set_descrset_descr(self.h_E_ECLh_E_ECL, "TRG ECL cluster energy", "")
101  self.set_styleset_style(self.h_E_ECLh_E_ECL, "ECL cluster energy (GeV)", "Events/(50 MeV)")
102 
103 
104  self.h_Esum_ECLh_Esum_ECL = TH1F("h_Esum_ECL", "sum of ECL cluster energy [50 MeV]", 200, 0, 10)
105  self.set_descrset_descr(self.h_Esum_ECLh_Esum_ECL, "sum of TRG ECL cluster energy", "")
106  self.set_styleset_style(self.h_Esum_ECLh_Esum_ECL, "sum of ECL cluster energy (GeV)", "Events/(50 MeV)")
107 
108 
109  self.h_theta_ECLh_theta_ECL = TH1F("h_theta_ECL", "TRG ECL cluster #theta [1.4 degrees]", 128, 0, 180)
110  self.set_descrset_descr(self.h_theta_ECLh_theta_ECL, "TRG ECL cluster polar angle", "unform in barrel")
111  self.set_styleset_style(self.h_theta_ECLh_theta_ECL, "TRG ECL cluster polar angle (degree)", "Events/(1.4 degree)")
112 
113 
114  self.h_thetaID_ECLh_thetaID_ECL = TH1F("h_thetaID_ECL", "ECL cluster TC ID", 610, 0, 610)
115  self.set_descrset_descr(self.h_thetaID_ECLh_thetaID_ECL, "TRG ECL cluster theta ID", "unform in barrel")
116  self.set_styleset_style(self.h_thetaID_ECLh_thetaID_ECL, "ECL cluster TC ID", "Events/(1)")
117 
118 
119  self.h_phi_ECLh_phi_ECL = TH1F("h_phi_ECL", "TRG ECL cluster phi [2.0 degrees]", 180, -180, 180)
120  self.set_descrset_descr(self.h_phi_ECLh_phi_ECL, "TRG ECL cluster phi distribution", "distribute unformly")
121  self.set_styleset_style(self.h_phi_ECLh_phi_ECL, "ECL cluster #phi (degree) ", "Events/(2.0 degrees)")
122 
123 
124  self.h_sector_BKLMh_sector_BKLM = TH1F("h_sector_BKLM", "BKLM TRG hit sector", 10, 0, 10)
125  self.set_descrset_descr(self.h_sector_BKLMh_sector_BKLM, "# of BKLM TRG sector", "peak at 0")
126  self.set_styleset_style(self.h_sector_BKLMh_sector_BKLM, "# of BKLM TRG sector", "Events/(1)")
127 
128 
129  self.h_sector_EKLMh_sector_EKLM = TH1F("h_sector_EKLM", "EKLM TRG hit sector", 10, 0, 10)
130  self.set_descrset_descr(self.h_sector_EKLMh_sector_EKLM, "# of EKLM TRG sector", "peak at 0")
131  self.set_styleset_style(self.h_sector_EKLMh_sector_EKLM, "# of EKLM TRG sector", "Events/(1)")
132 
133  mc = "abs(MCParticles.m_pdg)==11&&MCParticles.m_status==11"
134  tree = ROOT.TChain("tree")
135  tree.Add("../TRGValidationGen.root")
136 
137 
138  self.d_wd_w = TH1F("d_w", "#Deltaw of CDC 2D finder, w = 0.00449/p_{t}", 50, -0.02, 0.02)
139  self.d_w_2d_w_2 = TH1F("d_w_2", "d_w_2", 50, -0.02, 0.02)
140  tree.Draw("({0} - 0.00449)/sqrt({1}*{1} + {2}*{2})>> d_w".format(trk2d_omega, mc_px, mc_py),
141  "MCParticles.m_pdg<0&&" + mc)
142  tree.Draw("({0} + 0.00449)/sqrt({1}*{1} + {2}*{2}) >> d_w_2".format(trk2d_omega, mc_px, mc_py),
143  "MCParticles.m_pdg>0 && " + mc)
144  self.d_wd_w.Add(self.d_w_2d_w_2)
145  self.set_descrset_descr(self.d_wd_w, "Comparison on w (=0.00449/pt) of a track between CDC 2D finder output and MC.",
146  "A clear peak at 0 with tail.")
147  self.set_styleset_style(self.d_wd_w, "#Deltaw", "Events/(0.08)")
148 
149 
150  self.d_phid_phi = TH1F("d_phi", "#Delta#phi of CDC 2D finder", 50, -0.5, 0.5)
151  tree.Draw("{0}-atan({1}/{2})>>d_phi".format(trk2d_phi, mc_py, mc_px),
152  "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
153  "fabs({0}-atan({1}/{2}))<{3}&&".format(trk2d_phi, mc_py, mc_px, PI) + mc)
154 
155  self.d_phi_2d_phi_2 = TH1F("d_phi_2", "d_phi_2", 50, -0.5, 0.5)
156  tree.Draw("{0}-atan({1}/{2})-{3}>>d_phi_2".format(trk2d_phi, mc_py, mc_px, PI),
157  "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
158  "{0}-atan({1}/{2})>={3} &&".format(trk2d_phi, mc_py, mc_px, PI) + mc)
159 
160  self.d_phi_3d_phi_3 = TH1F("d_phi_3", "d_phi_3", 50, -0.5, 0.5)
161  tree.Draw("{0}-atan({1}/{2})+{3}>>d_phi_2".format(trk2d_phi, mc_py, mc_px, PI),
162  "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
163  "{0}-atan({1}/{2})<=-{3}&&".format(trk2d_phi, mc_py, mc_px, PI) + mc)
164 
165  self.d_phid_phi.Add(self.d_phi_2d_phi_2)
166  self.d_phid_phi.Add(self.d_phi_3d_phi_3)
167  self.set_descrset_descr(self.d_phid_phi, "Comparison on phi_i of a track between CDC 2D finder output and MC.",
168  "A Gaussian peak at 0.")
169  self.set_styleset_style(self.d_phid_phi, "#Delta#phi [rad]", "Events/(0.02 rad)")
170 
171 
172  self.d_z0_3dd_z0_3d = TH1F("d_z0_3d", "#Deltaz0 of CDC 3D fitter", 60, -30, 30)
173  tree.Draw("TRGCDC3DFitterTracks.m_z0-MCParticles.m_productionVertex_z>>d_z0_3d", mc)
174  self.set_descrset_descr(self.d_z0_3dd_z0_3d, "Comparison on z0 of a track between CDC 2D fitter output and MC.",
175  "A Gaussian peak at 0 with small tail.")
176  self.set_styleset_style(self.d_z0_3dd_z0_3d, "#Deltaz0 [cm]", "Events/(1 cm)")
177 
178 
179  self.d_z0_nnd_z0_nn = TH1F("d_z0_nn", "#Deltaz0 of CDC Neuro", 60, -30, 30)
180  tree.Draw("TRGCDCNeuroTracks.m_z0-MCParticles.m_productionVertex_z>>d_z0_nn", mc)
181  self.set_descrset_descr(self.d_z0_nnd_z0_nn, "Comparison on z0 of a track between CDC Neuro output and MC.",
182  "A Gaussian peak at 0 with small tail.")
183  self.set_styleset_style(self.d_z0_nnd_z0_nn, "#Deltaz0 [cm]", "Events/(1 cm)")
184 
185 
186  self.d_E_ECLd_E_ECL = TH1F("d_E_ECL", "#DeltaE of ECL clustering", 100, -6, 6)
187  tree.Draw("TRGECLClusters.m_edep-MCParticles.m_energy>>d_E_ECL", mc)
188  self.set_descrset_descr(self.d_E_ECLd_E_ECL, "Comparison on deposit energy between ECL cluster output and MC.",
189  "A peak around -0.5 ~ 0 with a tail toward -6.")
190  self.set_styleset_style(self.d_E_ECLd_E_ECL, "#DeltaE [GeV]", "Events/(0.12 GeV)")
191 
192  def beginRun(self):
193  self.hist_inbithist_inbit.Reset()
194  self.hist_outbithist_outbit.Reset()
195  self.h_Esum_ECLh_Esum_ECL.Reset()
196  self.h_E_ECLh_E_ECL.Reset()
197  self.h_theta_ECLh_theta_ECL.Reset()
198  self.h_thetaID_ECLh_thetaID_ECL.Reset()
199  self.h_phi_ECLh_phi_ECL.Reset()
200 
201  def event(self):
202 
203  trg_summary = Belle2.PyStoreObj("TRGSummary")
204  clusters = Belle2.PyStoreArray("TRGECLClusters")
205  klmSummary = Belle2.PyStoreObj("KLMTrgSummary")
206 
207  for i in range(320):
208  if trg_summary.testInput(i):
209  self.hist_inbithist_inbit.Fill(i + 0.5)
210  if trg_summary.testFtdl(i):
211  self.hist_outbithist_outbit.Fill(i + 0.5)
212 
213  etot = 0
214  for cluster in clusters:
215  x = cluster.getPositionX()
216  y = cluster.getPositionY()
217  z = cluster.getPositionZ()
218  e = cluster.getEnergyDep()
219  self.h_E_ECLh_E_ECL.Fill(e)
220  etot += e
221  vec = ROOT.TVector3(x, y, z)
222  self.h_theta_ECLh_theta_ECL.Fill(vec.Theta() * Fac)
223  self.h_thetaID_ECLh_thetaID_ECL.Fill(cluster.getMaxTCId())
224  self.h_phi_ECLh_phi_ECL.Fill(vec.Phi() * Fac)
225 
226  if etot > 0:
227  self.h_Esum_ECLh_Esum_ECL.Fill(etot)
228 
229  self.h_sector_BKLMh_sector_BKLM.Fill(klmSummary.getBKLM_n_trg_sectors())
230  self.h_sector_EKLMh_sector_EKLM.Fill(klmSummary.getEKLM_n_trg_sectors())
231 
232  def endRun(self):
233  print("end")
234 
235  def terminate(self):
236 
237  self.hist_inbithist_inbit.Write()
238  self.hist_outbithist_outbit.Write()
239  self.h_Esum_ECLh_Esum_ECL.Write()
240  self.h_E_ECLh_E_ECL.Write()
241  self.h_theta_ECLh_theta_ECL.Write()
242  self.h_thetaID_ECLh_thetaID_ECL.Write()
243  self.h_phi_ECLh_phi_ECL.Write()
244  self.h_sector_BKLMh_sector_BKLM.Write()
245  self.h_sector_EKLMh_sector_EKLM.Write()
246  self.d_wd_w.Write()
247  self.d_phid_phi.Write()
248  self.d_z0_3dd_z0_3d.Write()
249  self.d_z0_nnd_z0_nn.Write()
250  self.d_E_ECLd_E_ECL.Write()
251  self.tfiletfile.Close()
252 
253 
254 # Create path
255 main = basf2.create_path()
256 
257 # INput
258 root_input = basf2.register_module("RootInput")
259 root_input.param("inputFileName", "../TRGValidationGen.root")
260 main.add_module(root_input)
261 
262 # Make plots
263 main.add_module(MakePlots())
264 
265 basf2.process(main)
Class to access a DBObjPtr from Python.
Definition: PyDBObj.h:48
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
h_Esum_ECL
validation histogram
h_sector_BKLM
validation histogram
d_w
validation histogram
hist_outbit
validation histogram
h_E_ECL
validation histogram
d_E_ECL
validation histogram
h_thetaID_ECL
validation histogram
def set_style(self, histogram, xtitle, ytitle)
hist_inbit
validation histogram
d_z0_nn
validation histogram
h_theta_ECL
validation histogram
def set_descr(self, histogram, description, check)
h_sector_EKLM
validation histogram
h_phi_ECL
validation histogram
d_z0_3d
validation histogram
d_phi
validation histogram