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