Belle II Software development
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 print_mutable (bool): If False do not print mutable content that may differ
75 during the execution of two basf2 jobs, e.g. EventMetaData::getTime
76 """
77
78 # Always avoid the top-level 'import ROOT'.
79 from ROOT import Belle2 # noqa: make Belle2 namespace available
80 from ROOT.Belle2 import Const # noqa
81
82 # prepare a list of PID detector sets and charged stable particles
83 pid_detectors = []
84 it = Const.PIDDetectors.c_set.begin()
85 while True:
86 pid_detectors.append(Const.PIDDetectorSet(it.getDetector()))
87 it.increment()
88 if it == Const.PIDDetectors.c_set.end():
89 break
90 charged_stables = [Const.ChargedStable(Const.chargedStableSet.at(index)) for index in range(Const.chargedStableSet.size())]
91
92 # Now we define a list of all the mdst_dataobjects we want to print out and all
93 # the members we want to check
94 mdst_dataobjects = [
95 DataStorePrinter("EventMetaData", [
96 "getErrorFlag", "getEvent", "getRun", "getSubrun", "getExperiment",
97 "getProduction", "getParentLfn", "getGeneratedWeight", "isEndOfRun"] +
98 (["getTime"] if print_mutable else []),
99 array=False
100 ),
101 DataStorePrinter("Track", [
102 "getNumberOfFittedHypotheses", "getQualityIndicator", "isFlippedAndRefitted",
103 "getTrackTime", "wasRefined"
104 ], {
105 "getTrackFitResult": charged_stables,
106 "getTrackFitResultWithClosestMass": charged_stables,
107 "getRelationsWith": ["ECLClusters", "KLMClusters", "MCParticles", "PIDLikelihoods"],
108 }),
109 DataStorePrinter("V0", [
110 "getTracks", "getTrackFitResults", "getV0Hypothesis",
111 "getFittedVertexX", "getFittedVertexY", "getFittedVertexZ"
112 ], {
113 "getRelationsWith": ["MCParticles"],
114 }),
115 DataStorePrinter("Kinks", [
116 "getMotherTrackIndex", "getDaughterTrackIndex", "getTrackFitResultIndexMotherStart",
117 "getTrackFitResultIndexMotherEnd", "getTrackFitResultIndexDaughter",
118 "getFittedVertexX", "getFittedVertexY", "getFittedVertexZ", "getFilterFlag"
119 ]),
120 DataStorePrinter("TrackFitResult", [
121 "getPosition", "getMomentum", "get4Momentum", "getEnergy", "getTransverseMomentum",
122 "getCovariance6", "getParticleType", "getChargeSign", "getPValue", "getD0", "getPhi0",
123 "getPhi", "getOmega", "getZ0", "getTanLambda", "getCotTheta",
124 "getTau", "getCov", "getCovariance5", "getHitPatternCDC", "getHitPatternVXD", "getNDF", "getChi2",
125 ]),
126 DataStorePrinter("EventLevelTrackingInfo", [
127 "getNCDCHitsNotAssigned", "getNCDCHitsNotAssignedPostCleaning",
128 "getNCDCSegments", "getSVDFirstSampleTime", "hasAnErrorFlag",
129 "hasUnspecifiedTrackFindingFailure", "hasVXDTF2AbortionFlag",
130 "hasSVDCKFAbortionFlag", "hasPXDCKFAbortionFlag", "hasSVDSpacePointCreatorAbortionFlag"], {
131 "hasCDCLayer": range(56)
132 }, array=False),
133 DataStorePrinter("PIDLikelihood", ["getMostLikely", "isAvailable", "areAllAvailable"],
134 (
135 {
136 "isAvailable": pid_detectors,
137 "areAllAvailable": pid_detectors,
138 "getLogL": charged_stables,
139 "getProbability": charged_stables,
140 "getLogarithmicProbability": charged_stables,
141 } if print_mutable else {}
142 )),
143 DataStorePrinter("ECLCluster", [
144 "isTrack", "isNeutral", "getStatus", "getConnectedRegionId",
145 "getClusterId", "getUniqueClusterId", "getMinTrkDistance", "getDeltaL",
146 "getAbsZernike40", "getAbsZernike51", "getZernikeMVA", "getE1oE9",
147 "getE9oE21", "getNumberOfHadronDigits", "getR", "getHypotheses",
148 "getSecondMoment", "getLAT", "getNumberOfCrystals", "getTime",
149 "getDeltaTime99", "hasFailedFitTime", "hasFailedTimeResolution", "getPhi", "getTheta",
150 "getEnergyRaw", "getEnergyHighestCrystal", "getUncertaintyEnergy",
151 "getUncertaintyTheta", "getUncertaintyPhi", "getClusterPosition",
152 "getCovarianceMatrix3x3", "getDetectorRegion",
153 "isTriggerCluster", "hasTriggerClusterMatching", "hasPulseShapeDiscrimination",
154 "getPulseShapeDiscriminationMVA", "getMaxECellId", "getMinTrkDistanceID"
155 ], {
156 "getEnergy": [16, 32],
157 "hasHypothesis": [16, 32],
158 "getRelationsWith": ["KlIds", "MCParticles"],
159 }),
160 DataStorePrinter("EventLevelClusteringInfo", [
161 "getNECLCalDigitsOutOfTimeFWD", "getNECLCalDigitsOutOfTimeBarrel",
162 "getNECLCalDigitsOutOfTimeBWD", "getNECLCalDigitsOutOfTime",
163 "getNECLShowersRejectedFWD", "getNECLShowersRejectedBarrel",
164 "getNECLShowersRejectedBWD", "getNECLShowersRejected",
165 "getNKLMDigitsMultiStripFWD", "getNKLMDigitsMultiStripBarrel",
166 "getNKLMDigitsMultiStripBWD", "getNKLMDigitsMultiStrip",
167 "getNECLShowersFWD", "getNECLShowersBarrel",
168 "getNECLShowersBWD", "getNECLShowers",
169 "getNECLLocalMaximumsFWD", "getNECLLocalMaximumsBarrel",
170 "getNECLLocalMaximumsBWD", "getNECLLocalMaximums",
171 "getNECLTriggerCellsFWD", "getNECLTriggerCellsBarrel",
172 "getNECLTriggerCellsBWD", "getNECLTriggerCells"
173 ], array=False),
174 DataStorePrinter("KLMCluster", [
175 "getTime", "getLayers", "getInnermostLayer",
176 "getClusterPosition", "getPosition", "getMomentumMag", "getEnergy",
177 "getMomentum", "getError4x4", "getError7x7",
178 "getAssociatedEclClusterFlag", "getAssociatedTrackFlag",
179 ], {
180 "getRelationsWith": ["KlIds", "MCParticles"],
181 }),
182 DataStorePrinter("KlId", ["isKLM", "isECL", "getKlId"]),
183 DataStorePrinter("TRGSummary", [
184 # getter functions to be called without arguments
185 "getTimType", "getTimQuality", "isPoissonInInjectionVeto"
186 ], {
187 # getter functions to be called with arguments
188 "getTRGSummary": range(10),
189 "getPreScale": [[int(i / 32), i % 32] for i in list(range(320))],
190 "getInputBits": range(10),
191 "getFtdlBits": range(10),
192 "getPsnmBits": range(10)
193 }, array=False),
194 DataStorePrinter("SoftwareTriggerResult", ["getResults", "getNonPrescaledResults"], array=False),
195 DataStorePrinter("MCParticle", [
196 "getPDG", "getStatus", "getMass", "getCharge", "getEnergy", "hasValidVertex",
197 "getProductionTime", "getDecayTime", "getLifetime", "getVertex",
198 "getProductionVertex", "getMomentum", "get4Vector", "getDecayVertex",
199 "getIndex", "getArrayIndex",
200 "getFirstDaughter", "getLastDaughter", "getDaughters", "getNDaughters", "getMother",
201 "getSecondaryPhysicsProcess", "getSeenInDetector",
202 "isVirtual", "isInitial", "isPrimaryParticle", "getName"
203 ], {'getDaughter': [0], 'getParticleFromGeneralizedIndexString': ['0:0']}),
204 DataStorePrinter("EventLevelTriggerTimeInfo", [
205 "isValid", "hasInjection", "isHER", "isRevo2",
206 "getTimeSinceLastInjection", "getTimeSincePrevTrigger", "getBunchNumber",
207 "getTimeSinceLastInjectionInMicroSeconds", "getTimeSincePrevTriggerInMicroSeconds",
208 "getTimeSinceInjectedBunch", "getTimeSinceInjectedBunchInMicroSeconds", "getTriggeredBunchNumberGlobal"
209 ], array=False),
210 ]
211 path.add_module(PrintObjectsModule(mdst_dataobjects, print_untested))
212