Belle II Software  release-06-01-15
mdst.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 from b2test_utils.datastoreprinter import DataStorePrinter, PrintObjectsModule
13 from ROOT.Belle2 import Const
14 
15 
16 MDST_OBJECTS = (
17  'ECLClusters',
18  'ECLClustersToTracksNamedBremsstrahlung',
19  'EventLevelClusteringInfo',
20  'EventLevelTrackingInfo',
21  'EventLevelTriggerTimeInfo',
22  'KLMClusters',
23  'KlIds',
24  'PIDLikelihoods',
25  'SoftwareTriggerResult',
26  'TrackFitResults',
27  'Tracks',
28  'TRGSummary',
29  'V0s',
30 )
31 
32 
33 def add_mdst_output(
34  path,
35  mc=True,
36  filename='mdst.root',
37  additionalBranches=[],
38  dataDescription=None,
39 ):
40  """
41  Add the mDST output module to a path.
42  This function defines the mDST data format.
43 
44  Arguments:
45  path (basf2.Path): Path to add module to
46  mc (bool): Save Monte Carlo quantities? (MCParticles and corresponding relations)
47  filename (str): Output file name.
48  additionalBranches (list): Additional objects/arrays of event durability to save
49  dataDescription (dict or None): Additional key->value pairs to be added as data description
50  fields to the output FileMetaData
51  """
52  branches = list(MDST_OBJECTS)
53  persistentBranches = ['FileMetaData']
54  if mc:
55  branches += ['MCParticles']
56  persistentBranches += ['BackgroundInfo']
57  branches += additionalBranches
58  # set dataDescription correctly
59  if dataDescription is None:
60  dataDescription = {}
61  # set dataLevel to mdst if it's not already set to something else (which
62  # might happen for udst output since that calls this function)
63  dataDescription.setdefault("dataLevel", "mdst")
64  return path.add_module("RootOutput", outputFileName=filename, branchNames=branches,
65  branchNamesPersistent=persistentBranches, additionalDataDescription=dataDescription)
66 
67 
68 def add_mdst_dump(path, print_untested=False):
69  """
70  Add a PrintObjectsModule to a path for printing the mDST content.
71 
72  Arguments:
73  path (basf2.Path): Path to add module to
74  print_untested (bool): If True print the names of all methods which are not
75  explicitly printed to make sure we don't miss addition of new members
76  """
77 
78  # prepare a list of PID detector sets and charged stable particles
79  pid_detectors = [Const.PIDDetectorSet(Const.PIDDetectors.c_set[index]) for index in range(Const.PIDDetectors.c_size)]
80  charged_stables = [Const.ChargedStable(Const.chargedStableSet.at(index)) for index in range(Const.chargedStableSet.size())]
81 
82  # Now we define a list of all the mdst_dataobjects we want to print out and all
83  # the members we want to check
84  mdst_dataobjects = [
85  DataStorePrinter("EventMetaData", [
86  "getErrorFlag", "getEvent", "getRun", "getSubrun", "getExperiment",
87  "getProduction", "getTime", "getParentLfn", "getGeneratedWeight",
88  "isEndOfRun"
89  ], array=False),
90  DataStorePrinter("Track", ["getNumberOfFittedHypotheses", "getQualityIndicator"], {
91  "getTrackFitResult": charged_stables,
92  "getTrackFitResultWithClosestMass": charged_stables,
93  "getRelationsWith": ["ECLClusters", "KLMClusters", "MCParticles", "PIDLikelihoods"],
94  }),
95  DataStorePrinter("V0", ["getTracks", "getTrackFitResults", "getV0Hypothesis"], {
96  "getRelationsWith": ["MCParticles"],
97  }),
98  DataStorePrinter("TrackFitResult", [
99  "getPosition", "getMomentum", "get4Momentum", "getEnergy", "getTransverseMomentum",
100  "getCovariance6", "getParticleType", "getChargeSign", "getPValue", "getD0", "getPhi0",
101  "getPhi", "getOmega", "getZ0", "getTanLambda", "getCotTheta",
102  "getTau", "getCov", "getCovariance5", "getHitPatternCDC", "getHitPatternVXD", "getNDF", "getChi2"
103  ]),
104  DataStorePrinter("EventLevelTrackingInfo", [
105  "getNCDCHitsNotAssigned", "getNCDCHitsNotAssignedPostCleaning",
106  "getNCDCSegments", "getSVDFirstSampleTime", "hasAnErrorFlag",
107  "hasUnspecifiedTrackFindingFailure", "hasVXDTF2AbortionFlag",
108  "hasSVDCKFAbortionFlag", "hasPXDCKFAbortionFlag", "hasSVDSpacePointCreatorAbortionFlag"], {
109  "hasCDCLayer": range(56)
110  }, array=False),
111  DataStorePrinter("PIDLikelihood", ["getMostLikely"], {
112  "isAvailable": pid_detectors,
113  "getLogL": charged_stables,
114  "getProbability": charged_stables,
115  }),
116  DataStorePrinter("ECLCluster", [
117  "isTrack", "isNeutral", "getStatus", "getConnectedRegionId",
118  "getClusterId", "getMinTrkDistance", "getDeltaL",
119  "getAbsZernike40", "getAbsZernike51", "getZernikeMVA", "getE1oE9",
120  "getE9oE21", "getNumberOfHadronDigits", "getR", "getHypotheses",
121  "getSecondMoment", "getLAT", "getNumberOfCrystals", "getTime",
122  "getDeltaTime99", "hasFailedFitTime", "hasFailedTimeResolution", "getPhi", "getTheta",
123  "getEnergyRaw", "getEnergyHighestCrystal", "getUncertaintyEnergy",
124  "getUncertaintyTheta", "getUncertaintyPhi", "getClusterPosition",
125  "getCovarianceMatrix3x3", "getDetectorRegion",
126  "isTriggerCluster", "hasTriggerClusterMatching", "hasPulseShapeDiscrimination",
127  "getPulseShapeDiscriminationMVA", "getMaxECellId", "getMinTrkDistanceID"
128  ], {
129  "getEnergy": [16, 32],
130  "hasHypothesis": [16, 32],
131  "getRelationsWith": ["KlIds", "MCParticles"],
132  }),
133  DataStorePrinter("EventLevelClusteringInfo", [
134  "getNECLCalDigitsOutOfTimeFWD", "getNECLCalDigitsOutOfTimeBarrel",
135  "getNECLCalDigitsOutOfTimeBWD", "getNECLCalDigitsOutOfTime",
136  "getNECLShowersRejectedFWD", "getNECLShowersRejectedBarrel",
137  "getNECLShowersRejectedBWD", "getNECLShowersRejected"
138  ], array=False),
139  DataStorePrinter("KLMCluster", [
140  "getTime", "getLayers", "getInnermostLayer",
141  "getClusterPosition", "getPosition", "getMomentumMag", "getEnergy",
142  "getMomentum", "getError4x4", "getError7x7",
143  "getAssociatedEclClusterFlag", "getAssociatedTrackFlag",
144  ], {
145  "getRelationsWith": ["KlIds", "MCParticles"],
146  }),
147  DataStorePrinter("KlId", ["isKLM", "isECL", "getKlId"]),
148  DataStorePrinter("TRGSummary", [
149  # getter functions to be called without arguments
150  "getTimType", "getTimQuality", "isPoissonInInjectionVeto"
151  ], {
152  # getter functions to be called with arguments
153  "getTRGSummary": range(10),
154  "getPreScale": [[int(i / 32), i % 32] for i in list(range(320))],
155  "getInputBits": range(10),
156  "getFtdlBits": range(10),
157  "getPsnmBits": range(10)
158  }, array=False),
159  DataStorePrinter("SoftwareTriggerResult", ["getResults", "getNonPrescaledResults"], array=False),
160  DataStorePrinter("MCParticle", [
161  "getPDG", "getStatus", "getMass", "getCharge", "getEnergy", "hasValidVertex",
162  "getProductionTime", "getDecayTime", "getLifetime", "getVertex",
163  "getProductionVertex", "getMomentum", "get4Vector", "getDecayVertex",
164  "getIndex", "getArrayIndex",
165  "getFirstDaughter", "getLastDaughter", "getDaughters", "getNDaughters", "getMother",
166  "getSecondaryPhysicsProcess", "getSeenInDetector",
167  "isVirtual", "isInitial", "isPrimaryParticle", "getName"
168  ]),
169  DataStorePrinter("EventLevelTriggerTimeInfo", [
170  "isValid", "hasInjection", "isHER", "isRevo2",
171  "getTimeSinceLastInjection", "getTimeSincePrevTrigger", "getBunchNumber",
172  "getTimeSinceLastInjectionInMicroSeconds", "getTimeSincePrevTriggerInMicroSeconds",
173  "getTimeSinceInjectedBunch", "getTimeSinceInjectedBunchInMicroSeconds", "getTriggeredBunchNumberGlobal"
174  ], array=False),
175  ]
176  path.add_module(PrintObjectsModule(mdst_dataobjects, print_untested))