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