Belle II Software  release-08-01-10
displaytriggered.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 #
13 # Opens a .root/.sroot file and shows MCParticles,
14 # SimHits and Tracks using the Display module. Only
15 # events which were triggered by the HLT are displayed.
16 # Usage:
17 # basf2 display/example/displaytrigger.py -i MyInputFile.root
18 
19 import basf2 as b2
20 import ROOT
21 from ROOT import Belle2
22 
23 
24 class DisplayHLTTags(b2.Module):
25  """Test DisplayData"""
26 
27  def initialize(self):
28  """reimplementation of Module::initialize()."""
29 
30  Belle2.PyStoreObj("DisplayData").registerInDataStore()
31 
32  def event(self):
33  """reimplementation of Module::event()."""
34 
35  displayData = Belle2.PyStoreObj("DisplayData")
36  displayData.create()
37 
38  print("HLT Tags:")
39  displayData.obj().addLabel('HLT Tags:', ROOT.Math.XYZVector(200, 220, -300))
40  trigger_result = Belle2.PyStoreObj('SoftwareTriggerResult')
41  dz_pos = 0
42  for name, result in trigger_result.getResults():
43  prefix = 'software_trigger_cut&hlt&accept_'
44  if result == 1 and name.startswith(prefix):
45  name = name[len(prefix):]
46  displayData.obj().addLabel(name, ROOT.Math.XYVector(200, 200 - dz_pos, -300))
47  dz_pos += 15
48  print(name)
49 
50 
51 # create paths
52 main = b2.create_path()
53 
54 # Get type of input file to decide, which input module we want to use
55 input_files = Belle2.Environment.Instance().getInputFilesOverride()
56 if not input_files.empty() and input_files.front().endswith(".sroot"):
57  rootinput = b2.register_module('SeqRootInput')
58 else:
59  rootinput = b2.register_module('RootInput')
60 
61 # create geometry
62 gearbox = b2.register_module('Gearbox')
63 geometry = b2.register_module('Geometry')
64 
65 main.add_module(rootinput)
66 main.add_module(gearbox)
67 main.add_module(geometry)
68 
69 main.add_module(DisplayHLTTags())
70 
71 display = b2.register_module('Display')
72 # --- MC options ---
73 # Should Monte Carlo info be shown? (MCParticles, SimHits)
74 display.param('showMCInfo', True)
75 
76 # should hits always be assigned to a particle with c_PrimaryParticle flag?
77 display.param('assignHitsToPrimaries', False)
78 
79 # show all primary MCParticles?
80 display.param('showAllPrimaries', True)
81 
82 # show all charged MCParticles?
83 display.param('showCharged', True)
84 
85 # show all neutral MCParticles?
86 display.param('showNeutrals', True)
87 
88 
89 # --- Intermediate options ---
90 # show track candidates?
91 # You most likely don't want this unless you are a tracking developer
92 display.param('showRecoTracks', False)
93 
94 # directly show CDCHits as drift cylinders (shortened, z position = 0)
95 display.param('showCDCHits', False)
96 
97 # show trigger objects?
98 display.param('showTriggerObjects', False)
99 
100 
101 # --- Track options ---
102 # show tracks, vertices, eclgammas?
103 display.param('showTrackLevelObjects', True)
104 
105 # The options parameter is a combination of:
106 # D draw detectors - draw simple detector representation (with different size)
107 # for each hit
108 # H draw track hits
109 # M draw track markers - intersections of track with detector planes
110 # P draw detector planes
111 #
112 # Note that you can always turn off an individual detector component or track
113 # interactively by removing its checkmark in the 'Eve' tab.
114 #
115 # only makes sense when showTrackLevelObjects/showTrackCandidates is used
116 display.param('options', 'MH') # default
117 
118 # --- Other options ---
119 
120 # save events non-interactively (without showing window)?
121 display.param('automatic', False)
122 
123 # change to True to show the full TGeo geometry instead of simplified extract
124 display.param('fullGeometry', False)
125 
126 # Objects which are to be hidden (can be manually re-enabled in tree view).
127 # Names correspond to the object names in the 'Event'. (Note that this won't
128 # work for objects somewhere deep in the tree, only for those immediately
129 # below 'Event'.
130 display.param('hideObjects', [])
131 
132 # this path will only be executed for events which satfisy the trigger skim
133 triggered_event_path = b2.Path()
134 triggered_event_path.add_module(display)
135 
136 trigger_skim_module = b2.register_module("TriggerSkim")
137 # add whatever HLT/Calib trigger lines you would like to select here
138 trigger_skim_module.param('triggerLines', ['software_trigger_cut&hlt&accept_mumu_2trk',
139  'software_trigger_cut&hlt&accept_bhabha',
140  'software_trigger_cut&hlt&accept_hadron'])
141 # if any of the trigger lines are true, run the display path
142 trigger_skim_module.if_value("==1", triggered_event_path, b2.AfterConditionPath.CONTINUE)
143 
144 main.add_module(trigger_skim_module)
145 
146 b2.process(main)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67