Belle II Software prerelease-10-00-00a
mdst.py
1#!/usr/bin/env python3
2
3
10
11from b2test_utils.datastoreprinter import DataStorePrinter, PrintObjectsModule
12
13
14MDST_OBJECTS = (
15 'ECLClusters',
16 'ECLClustersToTracksNamedBremsstrahlung',
17 'EventLevelClusteringInfo',
18 'EventLevelTrackingInfo',
19 'EventLevelTriggerTimeInfo',
20 'KLMClusters',
21 'Kinks',
22 'KlIds',
23 'PIDLikelihoods',
24 'SoftwareTriggerResult',
25 'TrackFitResults',
26 'Tracks',
27 'TRGSummary',
28 'V0s',
29)
30
31
32def add_mdst_output(
33 path,
34 mc=True,
35 filename='mdst.root',
36 additionalBranches=[],
37 dataDescription=None,
38):
39 """
40 Add the mDST output module to a path.
41 This function defines the mDST data format.
42
43 Arguments:
44 path (basf2.Path): Path to add module to
45 mc (bool): Save Monte Carlo quantities? (MCParticles and corresponding relations)
46 filename (str): Output file name.
47 additionalBranches (list): Additional objects/arrays of event durability to save
48 dataDescription (dict or None): Additional key->value pairs to be added as data description
49 fields to the output FileMetaData
50 """
51 branches = list(MDST_OBJECTS)
52 persistentBranches = ['FileMetaData']
53 if mc:
54 branches += ['MCParticles']
55 persistentBranches += ['BackgroundInfo']
56 branches += additionalBranches
57 # set dataDescription correctly
58 if dataDescription is None:
59 dataDescription = {}
60 # set dataLevel to mdst if it's not already set to something else (which
61 # might happen for udst output since that calls this function)
62 dataDescription.setdefault("dataLevel", "mdst")
63 return path.add_module("RootOutput", outputFileName=filename, branchNames=branches,
64 branchNamesPersistent=persistentBranches, additionalDataDescription=dataDescription)
65
66
67def add_mdst_dump(path, print_untested=False, print_mutable=True):
68 """
69 Add a PrintObjectsModule to a path for printing the mDST content.
70
71 Arguments:
72 path (basf2.Path): Path to add module to
73 print_untested (bool): If True print the names of all methods which are not
74 explicitly printed to make sure we don't miss addition of new members
75 print_mutable (bool): If False do not print mutable content that may differ
76 during the execution of two basf2 jobs, e.g. EventMetaData::getTime
77 """
78
79 # Always avoid the top-level 'import ROOT'.
80 from ROOT import Belle2 # noqa: make Belle2 namespace available
81 from ROOT.Belle2 import Const # noqa
82
83 # prepare a list of PID detector sets and charged stable particles
84 pid_detectors = []
85 it = Const.PIDDetectors.c_set.begin()
86 while True:
87 pid_detectors.append(Const.PIDDetectorSet(it.getDetector()))
88 it.increment()
89 if it == Const.PIDDetectors.c_set.end():
90 break
91 charged_stables = [Const.ChargedStable(Const.chargedStableSet.at(index)) for index in range(Const.chargedStableSet.size())]
92
93 # Now we define a list of all the mdst_dataobjects we want to print out and all
94 # the members we want to check
95 mdst_dataobjects = [
96 DataStorePrinter("EventMetaData", [
97 "getErrorFlag", "getEvent", "getRun", "getSubrun", "getExperiment",
98 "getProduction", "getParentLfn", "getGeneratedWeight", "isEndOfRun"] +
99 (["getTime"] if print_mutable else []),
100 array=False
101 ),
102 DataStorePrinter("Track", [
103 "getNumberOfFittedHypotheses", "getQualityIndicator", "isFlippedAndRefitted",
104 "getTrackTime", "wasRefined"
105 ], {
106 "getTrackFitResult": charged_stables,
107 "getTrackFitResultWithClosestMass": charged_stables,
108 "getRelationsWith": ["ECLClusters", "KLMClusters", "MCParticles", "PIDLikelihoods"],
109 }),
110 DataStorePrinter("V0", [
111 "getTracks", "getTrackFitResults", "getV0Hypothesis",
112 "getFittedVertexX", "getFittedVertexY", "getFittedVertexZ"
113 ], {
114 "getRelationsWith": ["MCParticles"],
115 }),
116 DataStorePrinter("Kinks", [
117 "getMotherTrackIndex", "getDaughterTrackIndex", "getTrackFitResultIndexMotherStart",
118 "getTrackFitResultIndexMotherEnd", "getTrackFitResultIndexDaughter",
119 "getFittedVertexX", "getFittedVertexY", "getFittedVertexZ", "getFilterFlag"
120 ]),
121 DataStorePrinter("TrackFitResult", [
122 "getPosition", "getMomentum", "get4Momentum", "getEnergy", "getTransverseMomentum",
123 "getCovariance6", "getParticleType", "getChargeSign", "getPValue", "getD0", "getPhi0",
124 "getPhi", "getOmega", "getZ0", "getTanLambda", "getCotTheta",
125 "getTau", "getCov", "getCovariance5", "getHitPatternCDC", "getHitPatternVXD", "getNDF", "getChi2",
126 ]),
127 DataStorePrinter("EventLevelTrackingInfo", [
128 "getNCDCHitsNotAssigned", "getNCDCHitsNotAssignedPostCleaning",
129 "getNCDCSegments", "getSVDFirstSampleTime", "hasAnErrorFlag",
130 "hasUnspecifiedTrackFindingFailure", "hasVXDTF2AbortionFlag",
131 "hasSVDCKFAbortionFlag", "hasPXDCKFAbortionFlag", "hasSVDSpacePointCreatorAbortionFlag"], {
132 "hasCDCLayer": range(56)
133 }, array=False),
134 DataStorePrinter("PIDLikelihood", ["getMostLikely", "isAvailable", "areAllAvailable"],
135 (
136 {
137 "isAvailable": pid_detectors,
138 "areAllAvailable": pid_detectors,
139 "getLogL": charged_stables,
140 "getProbability": charged_stables,
141 "getLogarithmicProbability": charged_stables,
142 } if print_mutable else {}
143 )),
144 DataStorePrinter("ECLCluster", [
145 "isTrack", "isNeutral", "getStatus", "getConnectedRegionId",
146 "getClusterId", "getUniqueClusterId", "getMinTrkDistance", "getDeltaL",
147 "getAbsZernike40", "getAbsZernike51", "getZernikeMVA", "getE1oE9",
148 "getE9oE21", "getNumberOfHadronDigits", "getR", "getHypotheses",
149 "getSecondMoment", "getLAT", "getNumberOfCrystals", "getTime",
150 "getDeltaTime99", "hasFailedFitTime", "hasFailedTimeResolution", "getPhi", "getTheta",
151 "getEnergyRaw", "getEnergyHighestCrystal", "getUncertaintyEnergy",
152 "getUncertaintyTheta", "getUncertaintyPhi", "getClusterPosition",
153 "getCovarianceMatrix3x3", "getDetectorRegion",
154 "isTriggerCluster", "hasTriggerClusterMatching", "hasPulseShapeDiscrimination",
155 "getPulseShapeDiscriminationMVA", "getMaxECellId", "getMinTrkDistanceID"
156 ], {
157 "getEnergy": [16, 32],
158 "hasHypothesis": [16, 32],
159 "getRelationsWith": ["KlIds", "MCParticles"],
160 }),
161 DataStorePrinter("EventLevelClusteringInfo", [
162 "getNECLCalDigitsOutOfTimeFWD", "getNECLCalDigitsOutOfTimeBarrel",
163 "getNECLCalDigitsOutOfTimeBWD", "getNECLCalDigitsOutOfTime",
164 "getNECLShowersRejectedFWD", "getNECLShowersRejectedBarrel",
165 "getNECLShowersRejectedBWD", "getNECLShowersRejected",
166 "getNKLMDigitsMultiStripFWD", "getNKLMDigitsMultiStripBarrel",
167 "getNKLMDigitsMultiStripBWD", "getNKLMDigitsMultiStrip",
168 "getNECLShowersFWD", "getNECLShowersBarrel",
169 "getNECLShowersBWD", "getNECLShowers",
170 "getNECLLocalMaximumsFWD", "getNECLLocalMaximumsBarrel",
171 "getNECLLocalMaximumsBWD", "getNECLLocalMaximums",
172 "getNECLTriggerCellsFWD", "getNECLTriggerCellsBarrel",
173 "getNECLTriggerCellsBWD", "getNECLTriggerCells"
174 ], array=False),
175 DataStorePrinter("KLMCluster", [
176 "getTime", "getLayers", "getInnermostLayer",
177 "getClusterPosition", "getPosition", "getMomentumMag", "getEnergy",
178 "getMomentum", "getError4x4", "getError7x7",
179 "getAssociatedEclClusterFlag", "getAssociatedTrackFlag",
180 "getClusterTrackRotationAngle", "getClusterTrackSeparationAngle",
181 "getClusterTrackSeparation",
182 "getShapeStdDev1", "getShapeStdDev2", "getShapeStdDev3"
183 ], {
184 "getRelationsWith": ["KlIds", "MCParticles"],
185 }),
186 DataStorePrinter("KlId", ["isKLM", "isECL", "getKlId"]),
187 DataStorePrinter("TRGSummary", [
188 # getter functions to be called without arguments
189 "getTimType", "getTimQuality", "isPoissonInInjectionVeto"
190 ], {
191 # getter functions to be called with arguments
192 "getTRGSummary": range(10),
193 "getPreScale": [[int(i / 32), i % 32] for i in list(range(320))],
194 "getInputBits": range(10),
195 "getFtdlBits": range(10),
196 "getPsnmBits": range(10)
197 }, array=False),
198 DataStorePrinter("SoftwareTriggerResult", ["getResults", "getNonPrescaledResults"], array=False),
199 DataStorePrinter("MCParticle", [
200 "getPDG", "getStatus", "getMass", "getCharge", "getEnergy", "hasValidVertex",
201 "getProductionTime", "getDecayTime", "getLifetime", "getVertex",
202 "getProductionVertex", "getMomentum", "get4Vector", "getDecayVertex",
203 "getIndex", "getArrayIndex",
204 "getFirstDaughter", "getLastDaughter", "getDaughters", "getNDaughters", "getMother",
205 "getSecondaryPhysicsProcess", "getSeenInDetector",
206 "isVirtual", "isInitial", "isPrimaryParticle", "getName"
207 ], {'getDaughter': [0], 'getParticleFromGeneralizedIndexString': ['0:0']}),
208 DataStorePrinter("EventLevelTriggerTimeInfo", [
209 "isValid", "hasInjection", "isHER", "isRevo2",
210 "getTimeSinceLastInjection", "getTimeSincePrevTrigger", "getBunchNumber",
211 "getTimeSinceLastInjectionInMicroSeconds", "getTimeSincePrevTriggerInMicroSeconds",
212 "getTimeSinceInjectedBunch", "getTimeSinceInjectedBunchInMicroSeconds", "getTriggeredBunchNumberGlobal",
213 "hasEventT0SourceFromSVD", "hasEventT0SourceFromCDC", "hasEventT0SourceFromECL", "hasAnyEventT0Sources",
214 "getEventT0Sources"
215 ], array=False),
216 ]
217 path.add_module(PrintObjectsModule(mdst_dataobjects, print_untested))