Belle II Software  release-06-02-00
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.TVector3(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.TVector3(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 # new ECL geometry contains custom objects that cannot be converted to TGeo
65 # add MagneticField off B-field (also greatly speeds up startup)
66 geometry.param('excludedComponents', ['ECL'])
67 
68 main.add_module(rootinput)
69 main.add_module(gearbox)
70 main.add_module(geometry)
71 
72 main.add_module(DisplayHLTTags())
73 
74 display = b2.register_module('Display')
75 # --- MC options ---
76 # Should Monte Carlo info be shown? (MCParticles, SimHits)
77 display.param('showMCInfo', True)
78 
79 # should hits always be assigned to a particle with c_PrimaryParticle flag?
80 display.param('assignHitsToPrimaries', False)
81 
82 # show all primary MCParticles?
83 display.param('showAllPrimaries', True)
84 
85 # show all charged MCParticles?
86 display.param('showCharged', True)
87 
88 # show all neutral MCParticles?
89 display.param('showNeutrals', True)
90 
91 
92 # --- Intermediate options ---
93 # show track candidates?
94 # You most likely don't want this unless you are a tracking developer
95 display.param('showRecoTracks', False)
96 
97 # directly show CDCHits as drift cylinders (shortened, z position = 0)
98 display.param('showCDCHits', False)
99 
100 # show trigger objects?
101 display.param('showTriggerObjects', False)
102 
103 
104 # --- Track options ---
105 # show tracks, vertices, eclgammas?
106 display.param('showTrackLevelObjects', True)
107 
108 # The options parameter is a combination of:
109 # D draw detectors - draw simple detector representation (with different size)
110 # for each hit
111 # H draw track hits
112 # M draw track markers - intersections of track with detector planes
113 # P draw detector planes
114 #
115 # Note that you can always turn off an individual detector component or track
116 # interactively by removing its checkmark in the 'Eve' tab.
117 #
118 # only makes sense when showTrackLevelObjects/showTrackCandidates is used
119 display.param('options', 'MH') # default
120 
121 # --- Other options ---
122 
123 # save events non-interactively (without showing window)?
124 display.param('automatic', False)
125 
126 # change to True to show the full TGeo geometry instead of simplified extract
127 display.param('fullGeometry', False)
128 
129 # Objects which are to be hidden (can be manually re-enabled in tree view).
130 # Names correspond to the object names in the 'Event'. (Note that this won't
131 # work for objects somewhere deep in the tree, only for those immediately
132 # below 'Event'.
133 display.param('hideObjects', [])
134 
135 # this path will only be executed for events which satfisy the trigger skim
136 triggered_event_path = b2.Path()
137 triggered_event_path.add_module(display)
138 
139 trigger_skim_module = b2.register_module("TriggerSkim")
140 # add whatever HLT/Calib trigger lines you would like to select here
141 trigger_skim_module.param('triggerLines', ['software_trigger_cut&hlt&accept_mumu_2trk',
142  'software_trigger_cut&hlt&accept_bhabha',
143  'software_trigger_cut&hlt&accept_hadron'])
144 # if any of the trigger lines are true, run the display path
145 trigger_skim_module.if_value("==1", triggered_event_path, b2.AfterConditionPath.CONTINUE)
146 
147 main.add_module(trigger_skim_module)
148 
149 b2.process(main)
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67