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