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 'PIDLikelihoods',
23 'SoftwareTriggerResult',
24 'TrackFitResults',
25 'Tracks',
26 'TRGSummary',
27 'V0s',
28)
29
30
31def add_mdst_output(
32 path,
33 mc=True,
34 filename='mdst.root',
35 additionalBranches=[],
36 dataDescription=None,
37):
38 """
39 Add the mDST output module to a path.
40 This function defines the mDST data format.
41
42 Arguments:
43 path (basf2.Path): Path to add module to
44 mc (bool): Save Monte Carlo quantities? (MCParticles and corresponding relations)
45 filename (str): Output file name.
46 additionalBranches (list): Additional objects/arrays of event durability to save
47 dataDescription (dict or None): Additional key->value pairs to be added as data description
48 fields to the output FileMetaData
49 """
50 branches = list(MDST_OBJECTS)
51 persistentBranches = ['FileMetaData']
52 if mc:
53 branches += ['MCParticles']
54 persistentBranches += ['BackgroundInfo']
55 branches += additionalBranches
56 # set dataDescription correctly
57 if dataDescription is None:
58 dataDescription = {}
59 # set dataLevel to mdst if it's not already set to something else (which
60 # might happen for udst output since that calls this function)
61 dataDescription.setdefault("dataLevel", "mdst")
62 return path.add_module("RootOutput", outputFileName=filename, branchNames=branches,
63 branchNamesPersistent=persistentBranches, additionalDataDescription=dataDescription)
64
65
66def add_mdst_dump(path, print_untested=False, print_mutable=True):
67 """
68 Add a PrintObjectsModule to a path for printing the mDST content.
69
70 Arguments:
71 path (basf2.Path): Path to add module to
72 print_untested (bool): If True print the names of all methods which are not
73 explicitly printed to make sure we don't miss addition of new members
74 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 "getClusterTrackRotationAngle", "getClusterTrackSeparationAngle",
180 "getClusterTrackSeparation",
181 "getShapeStdDev1", "getShapeStdDev2", "getShapeStdDev3"
182 ], {
183 "getRelationsWith": ["KlIds", "MCParticles"],
184 }),
185 DataStorePrinter("KlId", ["isKLM", "isECL", "getKlId"]),
186 DataStorePrinter("TRGSummary", [
187 # getter functions to be called without arguments
188 "getTimType", "getTimQuality", "isPoissonInInjectionVeto"
189 ], {
190 # getter functions to be called with arguments
191 "getTRGSummary": range(10),
192 "getPreScale": [[int(i / 32), i % 32] for i in list(range(320))],
193 "getInputBits": range(10),
194 "getFtdlBits": range(10),
195 "getPsnmBits": range(10)
196 }, array=False),
197 DataStorePrinter("SoftwareTriggerResult", ["getResults", "getNonPrescaledResults"], array=False),
198 DataStorePrinter("MCParticle", [
199 "getPDG", "getStatus", "getMass", "getCharge", "getEnergy", "hasValidVertex",
200 "getProductionTime", "getDecayTime", "getLifetime", "getVertex",
201 "getProductionVertex", "getMomentum", "get4Vector", "getDecayVertex",
202 "getIndex", "getArrayIndex",
203 "getFirstDaughter", "getLastDaughter", "getDaughters", "getNDaughters", "getMother",
204 "getSecondaryPhysicsProcess", "getSeenInDetector",
205 "isVirtual", "isInitial", "isPrimaryParticle", "getName"
206 ], {'getDaughter': [0], 'getParticleFromGeneralizedIndexString': ['0:0']}),
207 DataStorePrinter("EventLevelTriggerTimeInfo", [
208 "isValid", "hasInjection", "isHER", "isRevo2",
209 "getTimeSinceLastInjection", "getTimeSincePrevTrigger", "getBunchNumber",
210 "getTimeSinceLastInjectionInMicroSeconds", "getTimeSincePrevTriggerInMicroSeconds",
211 "getTimeSinceInjectedBunch", "getTimeSinceInjectedBunchInMicroSeconds", "getTriggeredBunchNumberGlobal",
212 "hasEventT0SourceFromSVD", "hasEventT0SourceFromCDC", "hasEventT0SourceFromECL", "hasAnyEventT0Sources",
213 "getEventT0Sources"
214 ], array=False),
215 ]
216 path.add_module(PrintObjectsModule(mdst_dataobjects, print_untested))