Belle II Software  light-2212-foldex
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", ["getTracks", "getTrackFitResults", "getV0Hypothesis"], {
107  "getRelationsWith": ["MCParticles"],
108  }),
109  DataStorePrinter("TrackFitResult", [
110  "getPosition", "getMomentum", "get4Momentum", "getEnergy", "getTransverseMomentum",
111  "getCovariance6", "getParticleType", "getChargeSign", "getPValue", "getD0", "getPhi0",
112  "getPhi", "getOmega", "getZ0", "getTanLambda", "getCotTheta",
113  "getTau", "getCov", "getCovariance5", "getHitPatternCDC", "getHitPatternVXD", "getNDF", "getChi2",
114  ]),
115  DataStorePrinter("EventLevelTrackingInfo", [
116  "getNCDCHitsNotAssigned", "getNCDCHitsNotAssignedPostCleaning",
117  "getNCDCSegments", "getSVDFirstSampleTime", "hasAnErrorFlag",
118  "hasUnspecifiedTrackFindingFailure", "hasVXDTF2AbortionFlag",
119  "hasSVDCKFAbortionFlag", "hasPXDCKFAbortionFlag", "hasSVDSpacePointCreatorAbortionFlag"], {
120  "hasCDCLayer": range(56)
121  }, array=False),
122  DataStorePrinter("PIDLikelihood", ["getMostLikely"], {
123  "isAvailable": pid_detectors,
124  "getLogL": charged_stables,
125  "getProbability": charged_stables,
126  }),
127  DataStorePrinter("ECLCluster", [
128  "isTrack", "isNeutral", "getStatus", "getConnectedRegionId",
129  "getClusterId", "getMinTrkDistance", "getDeltaL",
130  "getAbsZernike40", "getAbsZernike51", "getZernikeMVA", "getE1oE9",
131  "getE9oE21", "getNumberOfHadronDigits", "getR", "getHypotheses",
132  "getSecondMoment", "getLAT", "getNumberOfCrystals", "getTime",
133  "getDeltaTime99", "hasFailedFitTime", "hasFailedTimeResolution", "getPhi", "getTheta",
134  "getEnergyRaw", "getEnergyHighestCrystal", "getUncertaintyEnergy",
135  "getUncertaintyTheta", "getUncertaintyPhi", "getClusterPosition",
136  "getCovarianceMatrix3x3", "getDetectorRegion",
137  "isTriggerCluster", "hasTriggerClusterMatching", "hasPulseShapeDiscrimination",
138  "getPulseShapeDiscriminationMVA", "getMaxECellId", "getMinTrkDistanceID"
139  ], {
140  "getEnergy": [16, 32],
141  "hasHypothesis": [16, 32],
142  "getRelationsWith": ["KlIds", "MCParticles"],
143  }),
144  DataStorePrinter("EventLevelClusteringInfo", [
145  "getNECLCalDigitsOutOfTimeFWD", "getNECLCalDigitsOutOfTimeBarrel",
146  "getNECLCalDigitsOutOfTimeBWD", "getNECLCalDigitsOutOfTime",
147  "getNECLShowersRejectedFWD", "getNECLShowersRejectedBarrel",
148  "getNECLShowersRejectedBWD", "getNECLShowersRejected"
149  ], array=False),
150  DataStorePrinter("KLMCluster", [
151  "getTime", "getLayers", "getInnermostLayer",
152  "getClusterPosition", "getPosition", "getMomentumMag", "getEnergy",
153  "getMomentum", "getError4x4", "getError7x7",
154  "getAssociatedEclClusterFlag", "getAssociatedTrackFlag",
155  ], {
156  "getRelationsWith": ["KlIds", "MCParticles"],
157  }),
158  DataStorePrinter("KlId", ["isKLM", "isECL", "getKlId"]),
159  DataStorePrinter("TRGSummary", [
160  # getter functions to be called without arguments
161  "getTimType", "getTimQuality", "isPoissonInInjectionVeto"
162  ], {
163  # getter functions to be called with arguments
164  "getTRGSummary": range(10),
165  "getPreScale": [[int(i / 32), i % 32] for i in list(range(320))],
166  "getInputBits": range(10),
167  "getFtdlBits": range(10),
168  "getPsnmBits": range(10)
169  }, array=False),
170  DataStorePrinter("SoftwareTriggerResult", ["getResults", "getNonPrescaledResults"], array=False),
171  DataStorePrinter("MCParticle", [
172  "getPDG", "getStatus", "getMass", "getCharge", "getEnergy", "hasValidVertex",
173  "getProductionTime", "getDecayTime", "getLifetime", "getVertex",
174  "getProductionVertex", "getMomentum", "get4Vector", "getDecayVertex",
175  "getIndex", "getArrayIndex",
176  "getFirstDaughter", "getLastDaughter", "getDaughters", "getNDaughters", "getMother",
177  "getSecondaryPhysicsProcess", "getSeenInDetector",
178  "isVirtual", "isInitial", "isPrimaryParticle", "getName"
179  ], {'getDaughter': [0], 'getParticleFromGeneralizedIndexString': ['0:0']}),
180  DataStorePrinter("EventLevelTriggerTimeInfo", [
181  "isValid", "hasInjection", "isHER", "isRevo2",
182  "getTimeSinceLastInjection", "getTimeSincePrevTrigger", "getBunchNumber",
183  "getTimeSinceLastInjectionInMicroSeconds", "getTimeSincePrevTriggerInMicroSeconds",
184  "getTimeSinceInjectedBunch", "getTimeSinceInjectedBunchInMicroSeconds", "getTriggeredBunchNumberGlobal"
185  ], array=False),
186  ]
187  path.add_module(PrintObjectsModule(mdst_dataobjects, print_untested))