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