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