12 <input>TRGValidationGen.root</input>
13 <output>TRGValidation.root</output>
14 <contact>yinjh@nankai.edu.cn</contact>
15 <description>makes validation plots
for TRG</description>
21import modularAnalysis as ma
22import stdCharged
as stdc
26from ROOT
import Belle2, TH1F, TFile, TNamed, TEfficiency, TMath
27from math
import pi
as PI
30inputBits = [
"t3_0",
"ty_0",
"t2_0",
"ts_0",
"ta_0",
"typ",
"ehigh",
"elow",
"elum",
"ecl_3dbha",
"cdc_open90",
31 "clst_0",
"clst_1",
"clst_2",
"clst_3",
"klm_hit",
"klm_0",
"klm_1",
"klm_2",
"eklm_0",
"eklm_1",
"eklm_2"]
32outputBits = [
"fff",
"ffy",
"ffz",
"fzo",
"fso",
"fyo",
"ffb",
"fsb",
"ssb",
"stt",
"hie",
"c4",
"bha3d",
33 "lml1",
"mu_b2b",
"mu_eb2b",
"eklm2",
"beklm",
"cdcklm1",
"cdcklm2",
"seklm1",
"seklm2",
"ecleklm1"]
354moniInbits_expert = []
355moniOutbits_expert = []
360 Make validation histograms for trg ecl/cdc/klm
365 Sets description, check and contact to validation histogram.
366 :param histogram validation histogram
367 :param description description text
368 :param check information on what to check
in comparison
with reference
371 descr = TNamed("Description", description)
372 histogram.GetListOfFunctions().Add(descr)
373 Check = TNamed(
"Check", check)
374 histogram.GetListOfFunctions().Add(Check)
375 contact = TNamed(
"Contact",
"yinjh@nankai.edu.cn")
376 histogram.GetListOfFunctions().Add(contact)
377 Meta = TNamed(
"MetaOptions",
"shifter,pvalue-warn=0.02,pvalue-error=0.01")
378 histogram.GetListOfFunctions().Add(Meta)
382 Sets description, check and contact to validation histogram.
383 :param histogram validation histogram
384 :param description description text
385 :param check information on what to check
in comparison
with reference
388 descr = TNamed("Description", description)
389 histogram.GetListOfFunctions().Add(descr)
390 Check = TNamed(
"Check", check)
391 histogram.GetListOfFunctions().Add(Check)
392 contact = TNamed(
"Contact",
"yinjh@nankai.edu.cn")
393 histogram.GetListOfFunctions().Add(contact)
394 Meta = TNamed(
"MetaOptions",
"expert,pvalue-warn=0.02,pvalue-error=0.01")
395 histogram.GetListOfFunctions().Add(Meta)
399 Sets x-y titles, and sets histogram style.
400 :param histogram validation histogram
401 :param xtitle X-axis title
402 :param xtitle Y-axis title
405 histogram.GetXaxis().SetTitle(xtitle)
406 histogram.GetYaxis().SetTitle(ytitle)
407 histogram.GetYaxis().SetTitleOffset(1.4)
408 histogram.GetXaxis().SetTitleSize(0.045)
409 histogram.GetYaxis().SetLabelSize(0.020)
410 histogram.SetLineColor(ROOT.kBlack)
414 Get relative ratio between two hists.
415 :param hist1 numerator
416 :param hist2 denominator
417 :param title new histogram title
418 :param particle particle name
419 :param trgbit trigger bit
422 bin1 = hist1.GetXaxis().GetNbins()
423 bin2 = hist2.GetXaxis().GetNbins()
424 Xmin1 = hist1.GetXaxis().GetXmin()
425 Xmax1 = hist1.GetXaxis().GetXmax()
426 Xmin2 = hist2.GetXaxis().GetXmin()
427 Xmax2 = hist2.GetXaxis().GetXmax()
428 if bin1 != bin2
or Xmin1 != Xmin2
or Xmax1 != Xmax2:
429 print(
"warning: two histograms cannot be compared!!")
432 teff = TEfficiency(hist1, hist2)
433 htitle = f
'h_eff_{title}_{particle}_{trgbit}'
434 heff = TH1F(htitle, f
"efficiency histogram of {particle} for {trgbit}", bin1, Xmin1, Xmax1)
435 for ibin
in range(1, bin1+1):
436 binc0 = teff.GetEfficiency(ibin)
437 bine0 = (teff.GetEfficiencyErrorUp(ibin) + teff.GetEfficiencyErrorLow(ibin)) / 2.0
438 heff.SetBinContent(ibin, binc0)
439 heff.SetBinError(ibin, bine0)
440 heff.GetYaxis().SetRangeUser(0.0, 1.2)
445 initialize class members
450 self.
tfile = TFile(
"./TRGValidation.root",
"update")
457 inbitname = m_dbinput.getinbitname(i)
458 outbitname = m_dbftdl.getoutbitname(i)
459 if inbitname
in inputBits:
460 moniInbits.append({
"name": inbitname,
"index": i})
461 if outbitname
in outputBits:
462 moniOutbits.append({
"name": outbitname,
"index": i})
463 if inbitname
in inputBits_expert:
464 moniInbits_expert.append({
"name": inbitname,
"index": i})
465 if outbitname
in outputBits_expert:
466 moniOutbits_expert.append({
"name": outbitname,
"index": i})
468 mc_px =
"MCParticles.m_momentum_x"
469 mc_py =
"MCParticles.m_momentum_y"
470 trk2d_omega =
"TRGCDC2DFinderTracks.m_omega"
471 trk2d_phi =
"TRGCDC2DFinderTracks.m_phi0"
473 ROOT.gROOT.SetBatch(
True)
474 ROOT.gStyle.SetOptStat(ROOT.kFALSE)
477 n_inbit_test = len(inputBits)
478 self.
hist_inbit = TH1F(
"hin",
"trigger input bits", n_inbit_test, 0, n_inbit_test)
479 self.
hist_inbit.GetXaxis().SetRangeUser(0, n_inbit_test)
482 "Efficiency should not drop significantly for any trigger bit")
486 n_oubit_test = len(outputBits)
487 self.
hist_outbit = TH1F(
"hout",
"trigger output bits", n_oubit_test, 0, n_oubit_test)
488 self.
hist_outbit.GetXaxis().SetRangeUser(0, n_oubit_test)
492 "trigger ftdl bits for shifter",
493 "Efficiency should not drop significantly. For some output bits the efficiency is very low, close to zero.")
496 for i
in range(n_inbit_test):
498 self.
hist_inbit.GetXaxis().FindBin(i + 0.5), inputBits[i])
499 for i
in range(n_oubit_test):
501 self.
hist_outbit.GetXaxis().FindBin(i + 0.5), outputBits[i])
504 self.
h_E_ECL = TH1F(
"h_E_ECL",
"ECL cluster energy [50 MeV]", 100, 0, 5)
509 self.
h_Esum_ECL = TH1F(
"h_Esum_ECL",
"sum of ECL cluster energy [50 MeV]", 100, 0, 5)
514 self.
h_theta_ECL = TH1F(
"h_theta_ECL",
"TRG ECL cluster #theta [1.4 degrees]", 128, 0, 180)
519 self.
h_thetaID_ECL = TH1F(
"h_thetaID_ECL",
"ECL cluster TC ID", 610, 0, 610)
524 self.
h_phi_ECL = TH1F(
"h_phi_ECL",
"TRG ECL cluster phi [2.0 degrees]", 180, -180, 180)
529 self.
h_sector_BKLM = TH1F(
"h_sector_BKLM",
"BKLM TRG hit sector", 10, 0, 10)
534 self.
h_sector_EKLM = TH1F(
"h_sector_EKLM",
"EKLM TRG hit sector", 10, 0, 10)
539 n_inbit_expert = len(inputBits_expert)
540 self.
hist_inbit_expert = TH1F(
"hin_expert",
"trigger input bits", n_inbit_expert, 0, n_inbit_expert)
546 n_oubit_expert = len(outputBits_expert)
547 self.
hist_outbit_expert = TH1F(
"hout_expert",
"trigger output bits", n_oubit_expert, 0, n_oubit_expert)
552 for i
in range(n_inbit_expert):
555 for i
in range(n_oubit_expert):
559 mc =
"abs(MCParticles.m_pdg)==11&&MCParticles.m_status==11"
560 tree = ROOT.TChain(
"tree")
561 tree.Add(
"../TRGValidationGen.root")
564 self.
d_w = TH1F(
"d_w",
"#Deltaw of CDC 2D finder, w = 0.00449/p_{t}", 50, -0.02, 0.02)
565 tree.Draw(f
"({trk2d_omega} - 0.00449)/sqrt({mc_px}*{mc_px} + {mc_py}*{mc_py})>> d_w",
566 "MCParticles.m_pdg<0&&" + mc)
568 self.
d_w_2 = TH1F(
"d_w_2",
"d_w_2", 50, -0.02, 0.02)
569 tree.Draw(f
"({trk2d_omega} + 0.00449)/sqrt({mc_px}*{mc_px} + {mc_py}*{mc_py}) >> d_w_2",
570 "MCParticles.m_pdg>0 && " + mc)
572 self.
set_descr_shifter(self.
d_w,
"Comparison on w (=0.00449/pt) of a track between CDC 2D finder output and MC.",
573 "A clear peak at 0 with tail.")
577 self.
d_phi = TH1F(
"d_phi",
"#Delta#phi of CDC 2D finder", 50, -0.5, 0.5)
578 tree.Draw(f
"{trk2d_phi}-atan({mc_py}/{mc_px})>>d_phi",
579 "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
580 f
"fabs({trk2d_phi}-atan({mc_py}/{mc_px}))<{PI}&&" + mc)
583 self.
d_phi_2 = TH1F(
"d_phi_2",
"d_phi_2", 50, -0.5, 0.5)
584 tree.Draw(f
"{trk2d_phi}-atan({mc_py}/{mc_px})-{PI}>>d_phi_2",
585 "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
586 f
"{trk2d_phi}-atan({mc_py}/{mc_px})>={PI} &&" + mc)
589 self.
d_phi_3 = TH1F(
"d_phi_3",
"d_phi_3", 50, -0.5, 0.5)
590 tree.Draw(f
"{trk2d_phi}-atan({mc_py}/{mc_px})+{PI}>>d_phi_2",
591 "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
592 f
"{trk2d_phi}-atan({mc_py}/{mc_px})<=-{PI}&&" + mc)
597 "A Gaussian peak at 0.")
598 self.
set_style(self.
d_phi,
"#Delta#phi [rad]",
"Events/(0.02 rad)")
601 self.
d_z0_3d = TH1F(
"d_z0_3d",
"#Deltaz0 of CDC 3D fitter", 60, -30, 30)
602 tree.Draw(
"TRGCDC3DFitterTracks.m_z0-MCParticles.m_productionVertex_z>>d_z0_3d", mc)
604 "A Gaussian peak at 0 with small tail.")
608 self.
d_z0_nn = TH1F(
"d_z0_nn",
"#Deltaz0 of CDC Neuro", 60, -30, 30)
609 tree.Draw(
"TRGCDCNeuroTracks.m_z0-MCParticles.m_productionVertex_z>>d_z0_nn", mc)
611 "A Gaussian peak at 0 with small tail.")
615 self.
d_E_ECL = TH1F(
"d_E_ECL",
"#DeltaE of ECL clustering", 100, -6, 6)
616 tree.Draw(
"TRGECLClusters.m_edep-MCParticles.m_energy>>d_E_ECL", mc)
618 "A peak around -0.5 ~ 0 with a tail toward -6.")
623 reset all histograms at the begin of a new run
645 for bit
in moniInbits:
646 binIndex = inputBits.index(bit[
"name"])
647 bitIndex = bit[
"index"]
648 if trg_summary.testInput(bitIndex):
650 for bit
in moniOutbits:
651 binIndex = outputBits.index(bit[
"name"])
652 bitIndex = bit[
"index"]
653 if trg_summary.testFtdl(bitIndex):
656 for bit
in moniInbits_expert:
657 binIndex = inputBits_expert.index(bit[
"name"])
658 bitIndex = bit[
"index"]
659 if trg_summary.testInput(bitIndex):
661 for bit
in moniOutbits_expert:
662 binIndex = outputBits_expert.index(bit[
"name"])
663 bitIndex = bit[
"index"]
664 if trg_summary.testFtdl(bitIndex):
668 for cluster
in clusters:
669 x = cluster.getPositionX()
670 y = cluster.getPositionY()
671 z = cluster.getPositionZ()
672 e = cluster.getEnergyDep()
675 vec = ROOT.Math.XYZVector(x, y, z)
676 self.
h_theta_ECL.Fill(vec.Theta() * TMath.RadToDeg())
678 self.
h_phi_ECL.Fill(vec.Phi() * TMath.RadToDeg())
700 bits = ['ty_0',
'ehigh',
'clst_0']
702 h_gen_p = self.
tfile.Get(f
"{part}_all/p")
703 h_gen_E = self.
tfile.Get(f
"{part}_all/clusterE")
704 h_gen_theta = self.
tfile.Get(f
"{part}_all/theta")
705 h_gen_phi = self.
tfile.Get(f
"{part}_all/phi")
708 h_p = self.
tfile.Get(f
"{part}_{bit}/p")
709 h_E = self.
tfile.Get(f
"{part}_{bit}/clusterE")
710 h_theta = self.
tfile.Get(f
"{part}_{bit}/theta")
711 h_phi = self.
tfile.Get(f
"{part}_{bit}/phi")
713 h_eff_p = self.
get_relative(h_p, h_gen_p,
'p', part, bit)
714 self.
set_style(h_eff_p,
"Momentum",
"Efficiency")
715 self.
set_descr_expert(h_eff_p,
"Momentum dependent efficiency for experts",
"")
717 h_eff_E = self.
get_relative(h_E, h_gen_E,
'E', part, bit)
718 self.
set_style(h_eff_E,
"Energy",
"Efficiency")
721 "Efficiency around 40% below 1 GeV, then jump up to 100%")
722 elif bit ==
'clst_0':
724 "Turn-on curve from 40% efficiency at 0.5 GeV to nearly 100% above 1.5 GeV")
726 self.
set_descr_expert(h_eff_E,
"Energy dependent efficiency for experts",
"")
728 h_eff_theta = self.
get_relative(h_theta, h_gen_theta,
'theta', part, bit)
729 self.
set_style(h_eff_theta,
"Polar angle",
"Efficiency")
730 self.
set_descr_expert(h_eff_theta,
"polar angle dependent efficiency for experts",
"")
732 h_eff_phi = self.
get_relative(h_phi, h_gen_phi,
'phi', part, bit)
733 self.
set_style(h_eff_phi,
"phi angle",
"Efficiency")
734 self.
set_descr_expert(h_eff_phi,
"azimuth angle dependent efficiency for experts",
"")
741 bits = [
'ty_0',
'klm_0',
"klm_hit"]
743 h_gen_p = self.
tfile.Get(f
"{part}_all/p")
744 h_gen_E = self.
tfile.Get(f
"{part}_all/clusterE")
745 h_gen_theta = self.
tfile.Get(f
"{part}_all/theta")
746 h_gen_phi = self.
tfile.Get(f
"{part}_all/phi")
749 h_p = self.
tfile.Get(f
"{part}_{bit}/p")
750 h_theta = self.
tfile.Get(f
"{part}_{bit}/theta")
751 h_phi = self.
tfile.Get(f
"{part}_{bit}/phi")
753 h_eff_p = self.
get_relative(h_p, h_gen_p,
'p', part, bit)
754 self.
set_style(h_eff_p,
"Momentum",
"Efficiency")
757 "Efficiency should be above 90% for the whole momentum range")
760 "Efficiency should rise to about 90% for momenta greater than 1 GeV")
762 self.
set_descr_expert(h_eff_p,
"Momentum dependent efficiency for experts",
"")
764 h_eff_theta = self.
get_relative(h_theta, h_gen_theta,
'theta', part, bit)
765 self.
set_style(h_eff_theta,
"Polar angle",
"Efficiency")
766 self.
set_descr_expert(h_eff_theta,
"polar angle dependent efficiency for experts",
"")
768 h_eff_phi = self.
get_relative(h_phi, h_gen_phi,
'phi', part, bit)
769 self.
set_style(h_eff_phi,
"phi angle",
"Efficiency")
770 self.
set_descr_expert(h_eff_phi,
"azimuth angle dependent efficiency for experts",
"")
805ma.inputMdst(
"../TRGValidationGen.root", path=mypath)
808stdc.stdMu(listtype=
'all', path=mypath)
809stdc.stdE(listtype=
'all', path=mypath)
811ma.matchMCTruth(
'mu+:all', path=mypath)
812ma.matchMCTruth(
'e+:all', path=mypath)
814ma.cutAndCopyList(
'mu+:true',
'mu+:all', cut=
'isSignal>0 and mcPrimary>0', path=mypath)
815ma.cutAndCopyList(
'e+:true',
'e+:all', cut=
'isSignal>0 and mcPrimary>0', path=mypath)
818pvars = [
"p",
"theta",
"phi"]
819dvars = vu.create_aliases(pvars,
'daughter(0,{variable})',
"emu")
821bits = [
'ty_0',
'ehigh',
'clst_0',
'klm_0',
"klm_hit"]
824 inb_cut = f
"L1Input({bit})>0"
825 ma.cutAndCopyList(f
'mu+:{bit}',
'mu+:true', cut=inb_cut, path=mypath)
826 ma.cutAndCopyList(f
'e+:{bit}',
'e+:true', cut=inb_cut, path=mypath)
828 ma.variablesToHistogram(decayString=f
'mu+:{bit}',
829 variables=[(
'p', 50, 0.5, 3.0),
830 (
'clusterE', 50, 0.5, 3.0),
831 (
'theta', 40, 0.5, 2.5),
832 (
'phi', 40, -3.141593, 3.141593)],
833 filename=
'TRGValidation.root',
834 directory=f
'mu_{bit}',
838 ma.variablesToHistogram(decayString=f
'e+:{bit}',
839 variables=[(
'p', 50, 0.5, 3.0),
840 (
'clusterE', 50, 0.5, 3.0),
841 (
'theta', 40, 0.5, 2.5),
842 (
'phi', 40, -3.141593, 3.141593)],
843 filename=
'TRGValidation.root',
844 directory=f
'e_{bit}',
849ma.variablesToHistogram(decayString=
'mu+:true',
850 variables=[(
'p', 50, 0.5, 3.0),
851 (
'clusterE', 50, 0.5, 3.0),
852 (
'theta', 40, 0.5, 2.5),
853 (
'phi', 40, -3.141593, 3.141593)],
854 filename=
'TRGValidation.root',
859ma.variablesToHistogram(decayString=
'e+:true',
860 variables=[(
'p', 50, 0.5, 3.0),
861 (
'clusterE', 50, 0.5, 3.0),
862 (
'theta', 40, 0.5, 2.5),
863 (
'phi', 40, -3.141593, 3.141593)],
864 filename=
'TRGValidation.root',
874main = basf2.create_path()
875root_input = basf2.register_module(
"RootInput")
876root_input.param(
"inputFileName",
"../TRGValidationGen.root")
877main.add_module(root_input)
879main.add_module(
'Progress')
Class to access a DBObjPtr from Python.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
h_Esum_ECL
validation histogram
h_sector_BKLM
validation histogram
hist_outbit
validation histogram
h_E_ECL
validation histogram
def set_descr_expert(self, histogram, description, check)
hist_outbit_expert
validation histogram for experts
d_E_ECL
validation histogram
h_thetaID_ECL
validation histogram
def set_style(self, histogram, xtitle, ytitle)
def set_descr_shifter(self, histogram, description, check)
hist_inbit_expert
validation histogram for experts
d_w_2
validation histogram
d_phi_3
validation histogram
hist_inbit
validation histogram
d_z0_nn
validation histogram
h_theta_ECL
validation histogram
d_phi_2
validation histogram
def get_relative(self, hist1, hist2, title, particle, trgbit)
h_sector_EKLM
validation histogram
h_phi_ECL
validation histogram
d_z0_3d
validation histogram
d_phi
validation histogram