Belle II Software  release-05-01-25
mdst.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 from b2test_utils.datastoreprinter import DataStorePrinter, PrintObjectsModule
5 from ROOT.Belle2 import Const
6 
7 
8 def add_mdst_output(
9  path,
10  mc=True,
11  filename='mdst.root',
12  additionalBranches=[],
13  dataDescription=None,
14 ):
15  """
16  Add the mDST output module to a path.
17  This function defines the mDST data format.
18 
19  Arguments:
20  path (basf2.Path): Path to add module to
21  mc (bool): Save Monte Carlo quantities? (MCParticles and corresponding relations)
22  filename (str): Output file name.
23  additionalBranches (list): Additional objects/arrays of event durability to save
24  dataDescription (dict or None): Additional key->value pairs to be added as data description
25  fields to the output FileMetaData
26  """
27  branches = [
28  'Tracks',
29  'V0s',
30  'TrackFitResults',
31  'EventLevelTrackingInfo',
32  'PIDLikelihoods',
33  'TracksToPIDLikelihoods',
34  'ECLClusters',
35  'ECLClustersToTracksNamedBremsstrahlung',
36  'EventLevelClusteringInfo',
37  'TracksToECLClusters',
38  'KLMClusters',
39  'KlIds',
40  'KLMClustersToKlIds',
41  'TRGSummary',
42  'SoftwareTriggerResult',
43  ]
44  persistentBranches = ['FileMetaData']
45  if mc:
46  branches += ['MCParticles', 'TracksToMCParticles',
47  'ECLClustersToMCParticles', 'KLMClustersToMCParticles']
48  persistentBranches += ['BackgroundInfo']
49  branches += additionalBranches
50  # set dataDescription correctly
51  if dataDescription is None:
52  dataDescription = {}
53  # set dataLevel to mdst if it's not already set to something else (which
54  # might happen for udst output since that calls this function)
55  dataDescription.setdefault("dataLevel", "mdst")
56  return path.add_module("RootOutput", outputFileName=filename, branchNames=branches,
57  branchNamesPersistent=persistentBranches, additionalDataDescription=dataDescription)
58 
59 
60 def add_mdst_dump(path, print_untested=False):
61  """
62  Add a PrintObjectsModule to a path for printing the mDST content.
63 
64  Arguments:
65  path (basf2.Path): Path to add module to
66  print_untested (bool): If True print the names of all methods which are not
67  explicitly printed to make sure we don't miss addition of new members
68  """
69 
70  # prepare a list of PID detector sets and charged stable particles
71  pid_detectors = [Const.PIDDetectorSet(Const.PIDDetectors.c_set[index]) for index in range(Const.PIDDetectors.c_size)]
72  charged_stables = [Const.ChargedStable(Const.chargedStableSet.at(index)) for index in range(Const.chargedStableSet.size())]
73 
74  # Now we define a list of all the mdst_dataobjects we want to print out and all
75  # the members we want to check
76  mdst_dataobjects = [
77  DataStorePrinter("EventMetaData", [
78  "getErrorFlag", "getEvent", "getRun", "getSubrun", "getExperiment",
79  "getProduction", "getTime", "getParentLfn", "getGeneratedWeight",
80  "isEndOfRun"
81  ], array=False),
82  DataStorePrinter("Track", ["getNumberOfFittedHypotheses", "getQualityIndicator"], {
83  "getTrackFitResult": charged_stables,
84  "getTrackFitResultWithClosestMass": charged_stables,
85  "getRelationsWith": ["ECLClusters", "KLMClusters", "MCParticles", "PIDLikelihoods"],
86  }),
87  DataStorePrinter("V0", ["getTracks", "getTrackFitResults", "getV0Hypothesis"], {
88  "getRelationsWith": ["MCParticles"],
89  }),
90  DataStorePrinter("TrackFitResult", [
91  "getPosition", "getMomentum", "get4Momentum", "getEnergy", "getTransverseMomentum",
92  "getCovariance6", "getParticleType", "getChargeSign", "getPValue", "getD0", "getPhi0",
93  "getPhi", "getOmega", "getZ0", "getTanLambda", "getCotTheta",
94  "getTau", "getCov", "getCovariance5", "getHitPatternCDC", "getHitPatternVXD", "getNDF", "getChi2"
95  ]),
96  DataStorePrinter("EventLevelTrackingInfo", [
97  "getNCDCHitsNotAssigned", "getNCDCHitsNotAssignedPostCleaning",
98  "getNCDCSegments", "getSVDFirstSampleTime", "hasAnErrorFlag",
99  "hasUnspecifiedTrackFindingFailure", "hasVXDTF2AbortionFlag",
100  "hasSVDCKFAbortionFlag", "hasPXDCKFAbortionFlag"], {
101  "hasCDCLayer": range(56)
102  }, array=False),
103  DataStorePrinter("PIDLikelihood", ["getMostLikely"], {
104  "isAvailable": pid_detectors,
105  "getLogL": charged_stables,
106  "getProbability": charged_stables,
107  }),
108  DataStorePrinter("ECLCluster", [
109  "isTrack", "isNeutral", "getStatus", "getConnectedRegionId",
110  "getClusterId", "getMinTrkDistance", "getDeltaL",
111  "getAbsZernike40", "getAbsZernike51", "getZernikeMVA", "getE1oE9",
112  "getE9oE21", "getClusterHadronIntensity", "getNumberOfHadronDigits",
113  "getSecondMoment", "getLAT", "getNumberOfCrystals", "getTime",
114  "getDeltaTime99", "hasFailedFitTime", "hasFailedTimeResolution", "getPhi", "getTheta", "getR", "getHypotheses",
115  "getEnergyRaw", "getEnergyHighestCrystal", "getUncertaintyEnergy",
116  "getUncertaintyTheta", "getUncertaintyPhi", "getClusterPosition",
117  "getCovarianceMatrix3x3", "getDetectorRegion", "getUniqueId",
118  "isTriggerCluster", "hasTriggerClusterMatching", "hasPulseShapeDiscrimination",
119  "getPulseShapeDiscriminationMVA", "getMaxECellId",
120  ], {
121  "getEnergy": [16, 32],
122  "hasHypothesis": [16, 32],
123  "getRelationsWith": ["KlIds", "MCParticles"],
124  }),
125  DataStorePrinter("EventLevelClusteringInfo", [
126  "getNECLCalDigitsOutOfTimeFWD", "getNECLCalDigitsOutOfTimeBarrel",
127  "getNECLCalDigitsOutOfTimeBWD", "getNECLCalDigitsOutOfTime",
128  "getNECLShowersRejectedFWD", "getNECLShowersRejectedBarrel",
129  "getNECLShowersRejectedBWD", "getNECLShowersRejected"
130  ], array=False),
131  DataStorePrinter("KLMCluster", [
132  "getTime", "getLayers", "getInnermostLayer",
133  "getClusterPosition", "getPosition", "getMomentumMag", "getEnergy",
134  "getMomentum", "getError4x4", "getError7x7",
135  "getAssociatedEclClusterFlag", "getAssociatedTrackFlag",
136  ], {
137  "getRelationsWith": ["KlIds", "MCParticles"],
138  }),
139  DataStorePrinter("KlId", ["isKLM", "isECL", "getKlId"]),
140  DataStorePrinter("TRGSummary", [
141  "getTimType", "getTimQuality", "isPoissonInInjectionVeto"
142  ], {
143  "getTRGSummary": range(10),
144  "getPreScale": [[int(i / 32), i % 32] for i in list(range(320))],
145  "getInputBits": range(10),
146  "getFtdlBits": range(10),
147  "getPsnmBits": range(10),
148  }, array=False),
149  DataStorePrinter("SoftwareTriggerResult", ["getResults", "getNonPrescaledResults"], array=False),
150  DataStorePrinter("MCParticle", [
151  "getPDG", "getStatus", "getMass", "getCharge", "getEnergy", "hasValidVertex",
152  "getProductionTime", "getDecayTime", "getLifetime", "getVertex",
153  "getProductionVertex", "getMomentum", "get4Vector", "getDecayVertex",
154  "getIndex", "getArrayIndex",
155  "getFirstDaughter", "getLastDaughter", "getDaughters", "getNDaughters", "getMother",
156  "getSecondaryPhysicsProcess", "getSeenInDetector",
157  "isVirtual", "isInitial", "isPrimaryParticle", "getName"
158  ]),
159  ]
160  path.add_module(PrintObjectsModule(mdst_dataobjects, print_untested))
b2test_utils.datastoreprinter
Definition: datastoreprinter.py:1