18 <input>TRGValidationGen.root</input>
19 <output>TRGValidation.root</output>
20 <contact>yinjh@nankai.edu.cn</contact>
21 <description>makes validation plots for TRG</description>
27 import modularAnalysis
as ma
28 import stdCharged
as stdc
32 from ROOT
import Belle2, TH1F, TFile, TNamed, TEfficiency
33 from math
import pi
as PI
37 inputBits = [
"t3_0",
"ty_0",
"t2_0",
"ts_0",
"ta_0",
"typ",
"ehigh",
"elow",
"elum",
"ecl_3dbha",
"cdc_open90",
38 "clst_0",
"clst_1",
"clst_2",
"clst_3",
"klm_hit",
"klm_0",
"klm_1",
"klm_2",
"eklm_0",
"eklm_1",
"eklm_2"]
39 outputBits = [
"fff",
"ffy",
"ffz",
"fzo",
"fso",
"fyo",
"ffb",
"fsb",
"ssb",
"stt",
"hie",
"c4",
"bha3d",
40 "lml1",
"mu_b2b",
"mu_eb2b",
"eklm2",
"beklm",
"cdcklm1",
"cdcklm2",
"seklm1",
"seklm2",
"ecleklm1"]
200 outputBits_expert = [
361 moniInbits_expert = []
362 moniOutbits_expert = []
367 Make validation histograms for trg ecl/cdc/klm
372 Sets description, check and contact to validation histogram.
373 :param h validation histogram
374 :param Descr description text
377 descr = TNamed(
"Description", description)
378 histogram.GetListOfFunctions().Add(descr)
379 Check = TNamed(
"Check", check)
380 histogram.GetListOfFunctions().Add(Check)
381 contact = TNamed(
"Contact",
"yinjh@nankai.edu.cn")
382 histogram.GetListOfFunctions().Add(contact)
383 Meta = TNamed(
"MetaOptions",
"shifter,pvalue-warn=0.02,pvalue-error=0.01")
384 histogram.GetListOfFunctions().Add(Meta)
388 Sets description, check and contact to validation histogram.
389 :param h validation histogram
390 :param Descr description text
393 descr = TNamed(
"Description", description)
394 histogram.GetListOfFunctions().Add(descr)
395 Check = TNamed(
"Check", check)
396 histogram.GetListOfFunctions().Add(Check)
397 contact = TNamed(
"Contact",
"yinjh@nankai.edu.cn")
398 histogram.GetListOfFunctions().Add(contact)
399 Meta = TNamed(
"MetaOptions",
"expert,pvalue-warn=0.02,pvalue-error=0.01")
400 histogram.GetListOfFunctions().Add(Meta)
404 Sets x-y titles, and sets histogram style.
405 :param xtitle X-axis title
406 :param xtitle Y-axis title
409 histogram.GetXaxis().SetTitle(xtitle)
410 histogram.GetYaxis().SetTitle(ytitle)
411 histogram.GetYaxis().SetTitleOffset(1.4)
412 histogram.GetXaxis().SetTitleSize(0.045)
413 histogram.GetYaxis().SetLabelSize(0.020)
414 histogram.SetLineColor(ROOT.kBlack)
418 Get relative ratio between two hists.
419 :param hist1 numerator
420 :param hist2 denominator
421 :param title new histogram title
424 bin1 = hist1.GetXaxis().GetNbins()
425 bin2 = hist2.GetXaxis().GetNbins()
426 Xmin1 = hist1.GetXaxis().GetXmin()
427 Xmax1 = hist1.GetXaxis().GetXmax()
428 Xmin2 = hist2.GetXaxis().GetXmin()
429 Xmax2 = hist2.GetXaxis().GetXmax()
430 if bin1 != bin2
or Xmin1 != Xmin2
or Xmax1 != Xmax2:
431 print(
"warning: two histograms cannot be compared!!")
434 teff = TEfficiency(hist1, hist2)
435 htitle = f
'h_eff_{title}_{particle}_{trgbit}'
436 heff = TH1F(htitle, f
"efficiency histogram of {particle} for {trgbit}", bin1, Xmin1, Xmax1)
437 for ibin
in range(1, bin1+1):
438 binc0 = teff.GetEfficiency(ibin)
439 bine0 = (teff.GetEfficiencyErrorUp(ibin) + teff.GetEfficiencyErrorLow(ibin)) / 2.0
440 heff.SetBinContent(ibin, binc0)
441 heff.SetBinError(ibin, bine0)
442 heff.GetYaxis().SetRangeUser(0.0, 1.2)
447 initialize class members
452 self.
tfiletfile = TFile(
"./TRGValidation.root",
"update")
459 inbitname = m_dbinput.getinbitname(i)
460 outbitname = m_dbftdl.getoutbitname(i)
461 if inbitname
in inputBits:
462 moniInbits.append({
"name": inbitname,
"index": i})
463 if outbitname
in outputBits:
464 moniOutbits.append({
"name": outbitname,
"index": i})
465 if inbitname
in inputBits_expert:
466 moniInbits_expert.append({
"name": inbitname,
"index": i})
467 if outbitname
in outputBits_expert:
468 moniOutbits_expert.append({
"name": outbitname,
"index": i})
470 mc_px =
"MCParticles.m_momentum_x"
471 mc_py =
"MCParticles.m_momentum_y"
472 trk2d_omega =
"TRGCDC2DFinderTracks.m_omega"
473 trk2d_phi =
"TRGCDC2DFinderTracks.m_phi0"
475 ROOT.gStyle.SetOptStat(ROOT.kFALSE)
478 n_inbit_test = len(inputBits)
479 self.
hist_inbithist_inbit = TH1F(
"hin",
"trigger input bits", n_inbit_test, 0, n_inbit_test)
480 self.
hist_inbithist_inbit.GetXaxis().SetRangeUser(0, n_inbit_test)
481 self.
hist_inbithist_inbit.GetXaxis().SetLabelSize(0.04)
486 n_oubit_test = len(outputBits)
487 self.
hist_outbithist_outbit = TH1F(
"hout",
"trigger output bits", n_oubit_test, 0, n_oubit_test)
488 self.
hist_outbithist_outbit.GetXaxis().SetRangeUser(0, n_oubit_test)
489 self.
hist_outbithist_outbit.GetXaxis().SetLabelSize(0.04)
493 for i
in range(n_inbit_test):
494 self.
hist_inbithist_inbit.GetXaxis().SetBinLabel(
495 self.
hist_inbithist_inbit.GetXaxis().FindBin(i + 0.5), inputBits[i])
496 for i
in range(n_oubit_test):
497 self.
hist_outbithist_outbit.GetXaxis().SetBinLabel(
498 self.
hist_outbithist_outbit.GetXaxis().FindBin(i + 0.5), outputBits[i])
501 self.
h_E_ECLh_E_ECL = TH1F(
"h_E_ECL",
"ECL cluster energy [50 MeV]", 200, 0, 10)
503 self.
set_styleset_style(self.
h_E_ECLh_E_ECL,
"ECL cluster energy (GeV)",
"Events/(50 MeV)")
506 self.
h_Esum_ECLh_Esum_ECL = TH1F(
"h_Esum_ECL",
"sum of ECL cluster energy [50 MeV]", 200, 0, 10)
508 self.
set_styleset_style(self.
h_Esum_ECLh_Esum_ECL,
"sum of ECL cluster energy (GeV)",
"Events/(50 MeV)")
511 self.
h_theta_ECLh_theta_ECL = TH1F(
"h_theta_ECL",
"TRG ECL cluster #theta [1.4 degrees]", 128, 0, 180)
513 self.
set_styleset_style(self.
h_theta_ECLh_theta_ECL,
"TRG ECL cluster polar angle (degree)",
"Events/(1.4 degree)")
516 self.
h_thetaID_ECLh_thetaID_ECL = TH1F(
"h_thetaID_ECL",
"ECL cluster TC ID", 610, 0, 610)
521 self.
h_phi_ECLh_phi_ECL = TH1F(
"h_phi_ECL",
"TRG ECL cluster phi [2.0 degrees]", 180, -180, 180)
523 self.
set_styleset_style(self.
h_phi_ECLh_phi_ECL,
"ECL cluster #phi (degree) ",
"Events/(2.0 degrees)")
526 self.
h_sector_BKLMh_sector_BKLM = TH1F(
"h_sector_BKLM",
"BKLM TRG hit sector", 10, 0, 10)
531 self.
h_sector_EKLMh_sector_EKLM = TH1F(
"h_sector_EKLM",
"EKLM TRG hit sector", 10, 0, 10)
536 n_inbit_expert = len(inputBits_expert)
537 self.
hist_inbit_experthist_inbit_expert = TH1F(
"hin_expert",
"trigger input bits", n_inbit_expert, 0, n_inbit_expert)
538 self.
hist_inbit_experthist_inbit_expert.GetXaxis().SetRangeUser(0, n_inbit_expert)
543 n_oubit_expert = len(outputBits_expert)
544 self.
hist_outbit_experthist_outbit_expert = TH1F(
"hout_expert",
"trigger output bits", n_oubit_expert, 0, n_oubit_expert)
549 for i
in range(n_inbit_expert):
551 self.
hist_inbit_experthist_inbit_expert.GetXaxis().FindBin(i + 0.5), inputBits_expert[i])
552 for i
in range(n_oubit_expert):
554 self.
hist_outbit_experthist_outbit_expert.GetXaxis().FindBin(i + 0.5), outputBits_expert[i])
556 mc =
"abs(MCParticles.m_pdg)==11&&MCParticles.m_status==11"
557 tree = ROOT.TChain(
"tree")
558 tree.Add(
"../TRGValidationGen.root")
561 self.
d_wd_w = TH1F(
"d_w",
"#Deltaw of CDC 2D finder, w = 0.00449/p_{t}", 50, -0.02, 0.02)
562 tree.Draw(f
"({trk2d_omega} - 0.00449)/sqrt({mc_px}*{mc_px} + {mc_py}*{mc_py})>> d_w",
563 "MCParticles.m_pdg<0&&" + mc)
565 self.
d_w_2d_w_2 = TH1F(
"d_w_2",
"d_w_2", 50, -0.02, 0.02)
566 tree.Draw(f
"({trk2d_omega} + 0.00449)/sqrt({mc_px}*{mc_px} + {mc_py}*{mc_py}) >> d_w_2",
567 "MCParticles.m_pdg>0 && " + mc)
569 self.
set_descr_shifterset_descr_shifter(self.
d_wd_w,
"Comparison on w (=0.00449/pt) of a track between CDC 2D finder output and MC.",
570 "A clear peak at 0 with tail.")
571 self.
set_styleset_style(self.
d_wd_w,
"#Deltaw",
"Events/(0.08)")
574 self.
d_phid_phi = TH1F(
"d_phi",
"#Delta#phi of CDC 2D finder", 50, -0.5, 0.5)
575 tree.Draw(f
"{trk2d_phi}-atan({mc_py}/{mc_px})>>d_phi",
576 "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
577 f
"fabs({trk2d_phi}-atan({mc_py}/{mc_px}))<{PI}&&" + mc)
580 self.
d_phi_2d_phi_2 = TH1F(
"d_phi_2",
"d_phi_2", 50, -0.5, 0.5)
581 tree.Draw(f
"{trk2d_phi}-atan({mc_py}/{mc_px})-{PI}>>d_phi_2",
582 "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
583 f
"{trk2d_phi}-atan({mc_py}/{mc_px})>={PI} &&" + mc)
586 self.
d_phi_3d_phi_3 = TH1F(
"d_phi_3",
"d_phi_3", 50, -0.5, 0.5)
587 tree.Draw(f
"{trk2d_phi}-atan({mc_py}/{mc_px})+{PI}>>d_phi_2",
588 "MCParticles.m_status==11&&abs(MCParticles.m_pdg)==11",
589 f
"{trk2d_phi}-atan({mc_py}/{mc_px})<=-{PI}&&" + mc)
593 self.
set_descr_shifterset_descr_shifter(self.
d_phid_phi,
"Comparison on phi_i of a track between CDC 2D finder output and MC.",
594 "A Gaussian peak at 0.")
595 self.
set_styleset_style(self.
d_phid_phi,
"#Delta#phi [rad]",
"Events/(0.02 rad)")
598 self.
d_z0_3dd_z0_3d = TH1F(
"d_z0_3d",
"#Deltaz0 of CDC 3D fitter", 60, -30, 30)
599 tree.Draw(
"TRGCDC3DFitterTracks.m_z0-MCParticles.m_productionVertex_z>>d_z0_3d", mc)
600 self.
set_descr_shifterset_descr_shifter(self.
d_z0_3dd_z0_3d,
"Comparison on z0 of a track between CDC 2D fitter output and MC.",
601 "A Gaussian peak at 0 with small tail.")
602 self.
set_styleset_style(self.
d_z0_3dd_z0_3d,
"#Deltaz0 [cm]",
"Events/(1 cm)")
605 self.
d_z0_nnd_z0_nn = TH1F(
"d_z0_nn",
"#Deltaz0 of CDC Neuro", 60, -30, 30)
606 tree.Draw(
"TRGCDCNeuroTracks.m_z0-MCParticles.m_productionVertex_z>>d_z0_nn", mc)
607 self.
set_descr_shifterset_descr_shifter(self.
d_z0_nnd_z0_nn,
"Comparison on z0 of a track between CDC Neuro output and MC.",
608 "A Gaussian peak at 0 with small tail.")
609 self.
set_styleset_style(self.
d_z0_nnd_z0_nn,
"#Deltaz0 [cm]",
"Events/(1 cm)")
612 self.
d_E_ECLd_E_ECL = TH1F(
"d_E_ECL",
"#DeltaE of ECL clustering", 100, -6, 6)
613 tree.Draw(
"TRGECLClusters.m_edep-MCParticles.m_energy>>d_E_ECL", mc)
614 self.
set_descr_shifterset_descr_shifter(self.
d_E_ECLd_E_ECL,
"Comparison on deposit energy between ECL cluster output and MC.",
615 "A peak around -0.5 ~ 0 with a tail toward -6.")
616 self.
set_styleset_style(self.
d_E_ECLd_E_ECL,
"#DeltaE [GeV]",
"Events/(0.12 GeV)")
620 reset all histograms at the begin of a new run
642 for bit
in moniInbits:
643 binIndex = inputBits.index(bit[
"name"])
644 bitIndex = bit[
"index"]
645 if trg_summary.testInput(bitIndex):
646 self.
hist_inbithist_inbit.Fill(binIndex + 0.5)
647 for bit
in moniOutbits:
648 binIndex = outputBits.index(bit[
"name"])
649 bitIndex = bit[
"index"]
650 if trg_summary.testFtdl(bitIndex):
653 for bit
in moniInbits_expert:
654 binIndex = inputBits_expert.index(bit[
"name"])
655 bitIndex = bit[
"index"]
656 if trg_summary.testInput(bitIndex):
658 for bit
in moniOutbits_expert:
659 binIndex = outputBits_expert.index(bit[
"name"])
660 bitIndex = bit[
"index"]
661 if trg_summary.testFtdl(bitIndex):
665 for cluster
in clusters:
666 x = cluster.getPositionX()
667 y = cluster.getPositionY()
668 z = cluster.getPositionZ()
669 e = cluster.getEnergyDep()
672 vec = ROOT.TVector3(x, y, z)
673 self.
h_theta_ECLh_theta_ECL.Fill(vec.Theta() * Fac)
675 self.
h_phi_ECLh_phi_ECL.Fill(vec.Phi() * Fac)
680 self.
h_sector_BKLMh_sector_BKLM.Fill(klmSummary.getBKLM_n_trg_sectors())
681 self.
h_sector_EKLMh_sector_EKLM.Fill(klmSummary.getEKLM_n_trg_sectors())
697 bits = [
'ty_0',
'ehigh',
'clst_0']
699 h_gen_p = self.
tfiletfile.Get(f
"{part}_all/p")
700 h_gen_E = self.
tfiletfile.Get(f
"{part}_all/clusterE")
701 h_gen_theta = self.
tfiletfile.Get(f
"{part}_all/theta")
702 h_gen_phi = self.
tfiletfile.Get(f
"{part}_all/phi")
705 h_p = self.
tfiletfile.Get(f
"{part}_{bit}/p")
706 h_E = self.
tfiletfile.Get(f
"{part}_{bit}/clusterE")
707 h_theta = self.
tfiletfile.Get(f
"{part}_{bit}/theta")
708 h_phi = self.
tfiletfile.Get(f
"{part}_{bit}/phi")
710 h_eff_p = self.
get_relativeget_relative(h_p, h_gen_p,
'p', part, bit)
711 self.
set_styleset_style(h_eff_p,
"Momentum",
"Efficiency")
712 if (bit ==
'ty_0' or bit ==
'klm_0')
and part ==
'mu':
713 self.
set_descr_shifterset_descr_shifter(h_eff_p,
"Momentum dependent efficiency for shifters",
"")
715 self.
set_descr_expertset_descr_expert(h_eff_p,
"Momentum dependent efficiency for shifters",
"")
717 h_eff_E = self.
get_relativeget_relative(h_E, h_gen_E,
'E', part, bit)
718 self.
set_styleset_style(h_eff_E,
"Energy",
"Efficiency")
719 if (bit ==
'ehigh' or bit ==
'clst_0')
and part ==
'e':
720 self.
set_descr_shifterset_descr_shifter(h_eff_E,
"Energy dependent efficiency for shifters",
"")
722 self.
set_descr_expertset_descr_expert(h_eff_E,
"Energy dependent efficiency for shifters",
"")
724 h_eff_theta = self.
get_relativeget_relative(h_theta, h_gen_theta,
'theta', part, bit)
725 self.
set_styleset_style(h_eff_theta,
"Polar angle",
"Efficiency")
726 self.
set_descr_expertset_descr_expert(h_eff_theta,
"polar angle dependent efficiency for shifters",
"")
728 h_eff_phi = self.
get_relativeget_relative(h_phi, h_gen_phi,
'phi', part, bit)
729 self.
set_styleset_style(h_eff_phi,
"phi angle",
"Efficiency")
730 self.
set_descr_expertset_descr_expert(h_eff_phi,
"azimuth angle dependent efficiency for shifters",
"")
737 bits = [
'ty_0',
'klm_0']
739 h_gen_p = self.
tfiletfile.Get(f
"{part}_all/p")
740 h_gen_E = self.
tfiletfile.Get(f
"{part}_all/clusterE")
741 h_gen_theta = self.
tfiletfile.Get(f
"{part}_all/theta")
742 h_gen_phi = self.
tfiletfile.Get(f
"{part}_all/phi")
745 h_p = self.
tfiletfile.Get(f
"{part}_{bit}/p")
746 h_theta = self.
tfiletfile.Get(f
"{part}_{bit}/theta")
747 h_phi = self.
tfiletfile.Get(f
"{part}_{bit}/phi")
749 h_eff_p = self.
get_relativeget_relative(h_p, h_gen_p,
'p', part, bit)
750 self.
set_styleset_style(h_eff_p,
"Momentum",
"Efficiency")
751 if (bit ==
'ty_0' or bit ==
'klm_0')
and part ==
'mu':
752 self.
set_descr_shifterset_descr_shifter(h_eff_p,
"Momentum dependent efficiency for shifters",
"")
754 self.
set_descr_expertset_descr_expert(h_eff_p,
"Momentum dependent efficiency for experts",
"")
756 h_eff_theta = self.
get_relativeget_relative(h_theta, h_gen_theta,
'theta', part, bit)
757 self.
set_styleset_style(h_eff_theta,
"Polar angle",
"Efficiency")
758 self.
set_descr_expertset_descr_expert(h_eff_theta,
"polar angle dependent efficiency for experts",
"")
760 h_eff_phi = self.
get_relativeget_relative(h_phi, h_gen_phi,
'phi', part, bit)
761 self.
set_styleset_style(h_eff_phi,
"phi angle",
"Efficiency")
762 self.
set_descr_expertset_descr_expert(h_eff_phi,
"azimuth angle dependent efficiency for experts",
"")
785 self.
d_phid_phi.Write()
789 self.
tfiletfile.Close()
794 mypath = basf2.Path()
797 ma.inputMdst(
"../TRGValidationGen.root", path=mypath)
800 stdc.stdMu(listtype=
'all', path=mypath)
801 stdc.stdE(listtype=
'all', path=mypath)
803 ma.matchMCTruth(
'mu+:all', path=mypath)
804 ma.matchMCTruth(
'e+:all', path=mypath)
806 ma.cutAndCopyList(
'mu+:true',
'mu+:all', cut=
'isSignal>0 and mcPrimary>0', path=mypath)
807 ma.cutAndCopyList(
'e+:true',
'e+:all', cut=
'isSignal>0 and mcPrimary>0', path=mypath)
810 pvars = [
"p",
"theta",
"phi"]
811 dvars = vu.create_aliases(pvars,
'daughter(0,{variable})',
"emu")
813 bits = [
'ty_0',
'ehigh',
'clst_0',
'klm_0']
816 inb_cut = f
"L1Input({bit})>0"
817 ma.cutAndCopyList(f
'mu+:{bit}',
'mu+:true', cut=inb_cut, path=mypath)
818 ma.cutAndCopyList(f
'e+:{bit}',
'e+:true', cut=inb_cut, path=mypath)
820 ma.variablesToHistogram(decayString=f
'mu+:{bit}',
821 variables=[(
'p', 50, 0.5, 3.0),
822 (
'clusterE', 50, 0.5, 3.0),
823 (
'theta', 40, 0.5, 2.5),
824 (
'phi', 40, -3.141593, 3.141593)],
825 filename=
'TRGValidation.root',
826 directory=f
'mu_{bit}',
830 ma.variablesToHistogram(decayString=f
'e+:{bit}',
831 variables=[(
'p', 50, 0.5, 3.0),
832 (
'clusterE', 50, 0.5, 3.0),
833 (
'theta', 40, 0.5, 2.5),
834 (
'phi', 40, -3.141593, 3.141593)],
835 filename=
'TRGValidation.root',
836 directory=f
'e_{bit}',
841 ma.variablesToHistogram(decayString=
'mu+:true',
842 variables=[(
'p', 50, 0.5, 3.0),
843 (
'clusterE', 50, 0.5, 3.0),
844 (
'theta', 40, 0.5, 2.5),
845 (
'phi', 40, -3.141593, 3.141593)],
846 filename=
'TRGValidation.root',
851 ma.variablesToHistogram(decayString=
'e+:true',
852 variables=[(
'p', 50, 0.5, 3.0),
853 (
'clusterE', 50, 0.5, 3.0),
854 (
'theta', 40, 0.5, 2.5),
855 (
'phi', 40, -3.141593, 3.141593)],
856 filename=
'TRGValidation.root',
863 basf2.process(mypath)
866 main = basf2.create_path()
867 root_input = basf2.register_module(
"RootInput")
868 root_input.param(
"inputFileName",
"../TRGValidationGen.root")
869 main.add_module(root_input)
871 main.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