Belle II Software development
DisplayModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <display/modules/display/DisplayModule.h>
9
10#include <framework/dataobjects/DisplayData.h>
11#include <display/DisplayUI.h>
12#include <display/EVEVisualization.h>
13#include <display/EveGeometry.h>
14#include <mdst/dataobjects/Track.h>
15#include <mdst/dataobjects/TrackFitResult.h>
16#include <simulation/dataobjects/MCParticleTrajectory.h>
17
18#include <framework/datastore/StoreArray.h>
19#include <framework/datastore/StoreObjPtr.h>
20#include <framework/gearbox/Gearbox.h>
21#include <framework/core/Path.h>
22
23#include <tracking/dataobjects/RecoTrack.h>
24#include <tracking/dataobjects/RecoHitInformation.h>
25#include <genfit/GFRaveVertex.h>
26
27#include <TApplication.h>
28#include <TEveManager.h>
29
30using namespace Belle2;
31
32REG_MODULE(Display);
33
34DisplayModule::DisplayModule() : Module(), m_display(0), m_visualizer(0)
35{
36 setDescription("Interactive visualisation of Monte Carlo, intermediate and reconstructed objects, plus geometry. See https://confluence.desy.de/display/BI/Software+/EventDisplay for detailed documentation.");
37
38 addParam("options", m_options,
39 "Drawing options for RecoTracks, a combination of DHMP. See EVEVisualization::setOptions or the display.py example for an explanation.",
40 std::string("MH"));
41 addParam("showMCInfo", m_showMCInfo, "Show Monte Carlo information (MCParticles, SimHits)", true);
42 addParam("assignHitsToPrimaries", m_assignToPrimaries,
43 "If true, hits created by secondary particles (after scattering, decay-in-flight, ...) will be assigned to the original primary particle.",
44 false);
45 addParam("showAllPrimaries", m_showAllPrimaries,
46 "If true, all primary MCParticles will be shown, regardless of wether hits are produced.", true);
47 addParam("hideSecondaries", m_hideSecondaries, "If true, secondary MCParticles (and hits created by them) will not be shown.",
48 false);
49 addParam("showCharged", m_showCharged,
50 "If true, all charged MCParticles will be shown, including secondaries (implies disabled assignHitsToPrimaries). May be slow.",
51 true);
52 addParam("showNeutrals", m_showNeutrals,
53 "If true, all neutral MCParticles will be shown, including secondaries (implies disabled assignHitsToPrimaries). May be slow.",
54 true);
55 addParam("showTrackLevelObjects", m_showTrackLevelObjects,
56 "If true, fitted Tracks, GFRave Vertices and ECLCluster objects will be shown in the display.", true);
57 addParam("showRecoTracks", m_showRecoTracks,
58 "If true, track candidates (RecoTracks) and reconstructed hits will be shown in the display.", false);
59 addParam("showCDCHits", m_showCDCHits,
60 "If true, CDCHit objects will be shown as drift cylinders (shortened, z position set to zero).", false);
61 addParam("showTriggerObjects", m_showTriggerObjects,
62 "If true, CDCHit objects will be assigned to trigger segments and trigger tracks will be shown.", false);
63 addParam("showKLM2dHits", m_showKLM2dHits,
64 "If true, KLMHit2d objects will be shown in the display.", true);
65 addParam("showARICHHits", m_showARICHHits,
66 "If true, ARICHHit objects will be shown.", false);
67 addParam("automatic", m_automatic,
68 "Non-interactively save visualisations for each event. Note that this still requires an X server, but you can use the 'Xvfb' dummy server by running basf2 using 'xvfb-run -s \"-screen 0 640x480x24\" basf2 ...' to run headless.",
69 false);
70 addParam("fullGeometry", m_fullGeometry,
71 "Show full geometry instead of simplified shapes. Further details can be enabled by changing the VisLevel option for Eve -> Scenes -> Geometry Scene -> Top_1.",
72 false);
73 addParam("hideObjects", m_hideObjects,
74 "Objects which are to be hidden (can be manually re-enabled in tree view). Names correspond to the object names in the 'Event'. (Note that this won't work for objects somewhere deep in the tree, only for those immediately below 'Event'.)", {});
75 addParam("customGeometryExtractPath", m_customGeometryExtractPath, "Path to custom file with geometry extract.", std::string(""));
76 addParam("hideVolumes", m_hideVolumes,
77 "List of volumes to be hidden (can be re-enabled in Eve panel / Geometry scene. The volume and all its daughters will be hidden.", {});
78 addParam("deleteVolumes", m_deleteVolumes,
79 "List of volumes to be deleted. The volume and all its daughters will be deleted completely. Uses Regular Expressions (RE)! If the expression starts with '#', only daughters are removed (# is removed for RE)", {});
80 addParam("playOnStartup", m_playOnStartup,
81 "When launching the event display, immediately start advancing through events. Useful for control room uses etc.", false);
82
83
84 //create gApplication so we can use graphics support. Needs to be done before ROOT has a chance to do it for us.
85 if ((!gApplication) || (gApplication->TestBit(TApplication::kDefaultApplication))) {
86 new TApplication("ROOT_application", 0, 0);
87 }
88}
89
90
92{
93 //optional inputs
94 StoreArray<MCParticle> MCParticles; MCParticles.isOptional();
95 StoreArray<MCParticleTrajectory> MCParticleTrajectorys; MCParticleTrajectorys.isOptional();
96 StoreArray<CDCSimHit> CDCSimHits; CDCSimHits.isOptional();
97 StoreArray<PXDSimHit> PXDSimHits; PXDSimHits.isOptional();
98 StoreArray<SVDSimHit> SVDSimHits; SVDSimHits.isOptional();
99 StoreArray<KLMSimHit> KLMSimHits; KLMSimHits.isOptional();
100 StoreArray<ECLCluster> ECLClusters; ECLClusters.isOptional();
101 StoreArray<KLMCluster> KLMClusters; KLMClusters.isOptional();
102 StoreArray<KLMHit2d> KLMHit2ds; KLMHit2ds.isOptional();
103 StoreArray<Track> Tracks; Tracks.isOptional();
104 StoreArray<TrackFitResult> TrackFitResults; TrackFitResults.isOptional();
105 StoreArray<RecoTrack> RecoTracks; RecoTracks.isOptional();
106 StoreArray<genfit::GFRaveVertex> GFRaveVertexs; GFRaveVertexs.isOptional();
107 StoreObjPtr<DisplayData> DisplayDatas; DisplayDatas.isOptional();
108 StoreArray<PXDCluster> PXDClusters; PXDClusters.isOptional();
109 StoreArray<SVDCluster> SVDClusters; SVDClusters.isOptional();
110 StoreArray<CDCHit> CDCHits; CDCHits.isOptional();
111 StoreArray<CDCTriggerSegmentHit> CDCTriggerSegmentHits; CDCTriggerSegmentHits.isOptional();
112 StoreArray<ARICHHit> ARICHHits; ARICHHits.isOptional();
113 StoreArray<TOPDigit> TOPDigits; TOPDigits.isOptional();
114 StoreArray<ROIid> ROIids; ROIids.isOptional();
118
120 if (hasCondition())
122 m_display->addParameter("Show MC info", getParam<bool>("showMCInfo"), 0);
123 {
124 //MC-specific parameters
125 m_display->addParameter("Assign hits to primary particles", getParam<bool>("assignHitsToPrimaries"), 1);
126 m_display->addParameter("Show all primaries", getParam<bool>("showAllPrimaries"), 1);
127 m_display->addParameter("Show all charged particles", getParam<bool>("showCharged"), 1);
128 m_display->addParameter("Show all neutral particles", getParam<bool>("showNeutrals"), 1);
129 m_display->addParameter("Hide secondaries", getParam<bool>("hideSecondaries"), 1);
130 }
131 m_display->addParameter("Show candidates and rec. hits", getParam<bool>("showRecoTracks"), 0);
132 m_display->addParameter("Show tracks, vertices, gammas", getParam<bool>("showTrackLevelObjects"), 0);
133
134 if (!m_fullGeometry and Gearbox::getInstance().exists("Detector/Name")) {
135 std::string detectorName = Gearbox::getInstance().getString("Detector/Name");
136 if (detectorName != "Belle2Detector") {
137 B2INFO("Non-standard detector '" << detectorName << "' used, switching to full geometry.");
138 m_fullGeometry = true;
139 }
140 }
141 if (m_fullGeometry) {
142 //pass some parameters to DisplayUI to be able to change them at run time
143 m_display->addParameter("Show full geometry", getParam<bool>("fullGeometry"), 0);
144 }
145
147
150
155}
156
157
158
160{
161 setReturnValue(false);
162 if (!gEve) {
163 //window closed?
164 B2WARNING("Display window closed, continuing with next module. (hit Ctrl+C to exit)");
165 return;
166 }
167
169
170 //secondaries cannot be shown if they are merged into primaries
173 B2WARNING("assignHitsToPrimaries and showCharged/showNeutrals can not be used together!");
174 }
175
177
178 if (m_showMCInfo) {
179 //gather MC particles
180 StoreArray<MCParticle> mcparticles;
182 for (const MCParticle& part : mcparticles) {
183 if ((m_showAllPrimaries and part.hasStatus(MCParticle::c_PrimaryParticle))
184 or (m_showCharged and TMath::Nint(part.getCharge()) != 0)
185 or (m_showNeutrals and TMath::Nint(part.getCharge()) == 0)) {
187 }
188 }
189 }
190
191 //gather simhits
196 }
197
198
199 if (m_showRecoTracks) {
200 //add all possible track candidate arrays
201 const auto recoTrackArrays = StoreArray<RecoTrack>::getArrayList();
202 for (std::string colName : recoTrackArrays) {
203 StoreArray<RecoTrack> recoTracks(colName);
204 for (const RecoTrack& recoTrack : recoTracks) {
205 if (colName != "RecoTracksMpl") {
206 m_visualizer->addTrackCandidate(colName, recoTrack);
207 } else {
208 m_visualizer->addTrackCandidateImproved(colName, recoTrack);
209 }
210 }
211 }
212
216
217 //add remaining recohits
218 m_visualizer->addUnassignedRecoHits(pxdStoreArray);
219 m_visualizer->addUnassignedRecoHits(svdStoreArray);
220 m_visualizer->addUnassignedRecoHits(cdcStoreArray);
221
223 for (int i = 0 ; i < ROIs.getEntries(); i++)
224 m_visualizer->addROI(ROIs[i]);
225 //well, non-standard names are used for testbeams?
226 StoreArray<ROIid> testbeamROIs("ROIs");
227 for (int i = 0 ; i < testbeamROIs.getEntries(); i++)
228 m_visualizer->addROI(testbeamROIs[i]);
229 }
230
232 StoreArray<CDCHit> cdchits;
233 for (auto& hit : cdchits)
235 }
236
238 const auto arrayList = StoreArray<CDCTriggerSegmentHit>::getArrayList();
239 for (const auto& i : arrayList) {
241 for (auto& hit : tshits)
243 }
244
245 //add all possible track candidate arrays
246 const auto trgTrackArrays = StoreArray<CDCTriggerTrack>::getArrayList();
247 for (std::string colName : trgTrackArrays) {
248 StoreArray<CDCTriggerTrack> trgTracks(colName);
249 for (const CDCTriggerTrack& trgTrack : trgTracks) {
250 m_visualizer->addCDCTriggerTrack(colName, trgTrack);
251 }
252 }
253 }
254
255 if (m_showKLM2dHits) {
256 StoreArray<KLMHit2d> klmHits;
257 for (auto& hit : klmHits) {
258 if (hit.getSubdetector() == KLMElementNumbers::c_BKLM)
260 else
262 }
263 }
264
265 if (m_showARICHHits) {
266 StoreArray<ARICHHit> arichhits;
267 for (auto& hit : arichhits)
269 }
270
272 //gather track-level objects
273 StoreArray<Track> tracks;
274 for (const Track& track : tracks)
275 m_visualizer->addTrack(&track);
276
278 const int nVertices = vertices.getEntries();
279 for (int i = 0; i < nVertices; i++) {
280 m_visualizer->addVertex(vertices[i]);
281 }
282
283 StoreArray<ECLCluster> clusters;
284 for (const ECLCluster& cluster : clusters) {
285 if (cluster.hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) {
286 if (m_showMCInfo) {
287 //make sure we add particles producing these
288 const MCParticle* mcpart = cluster.getRelated<MCParticle>();
289 if (mcpart)
291 }
292
293 m_visualizer->addECLCluster(&cluster);
294 }
295 }
296
297 StoreArray<KLMCluster> klmclusters;
298 for (const KLMCluster& cluster : klmclusters) {
299 if (m_showMCInfo) {
300 //make sure we add particles producing these
301 const MCParticle* mcpart = cluster.getRelated<MCParticle>();
302 if (mcpart)
304 }
305
306 m_visualizer->addKLMCluster(&cluster);
307 }
308
310 }
311
312 //all hits/tracks are added, finish visual representations
314
315 StoreObjPtr<DisplayData> displayData;
316 if (displayData) {
317 m_visualizer->showUserData(*displayData);
318 m_display->showUserData(*displayData);
319 }
320
321
322 bool reshow = m_display->startDisplay();
324 if (!m_display->cumulativeIsOn()) {
325 m_visualizer->clearEvent(); //clean up internal state of visualiser
326 }
327 m_display->clearEvent(); //clean up event scene, incl. projections
328
329 //reprocess current event (maybe some options changed)
330 if (reshow)
331 event();
332}
333
334
336{
337 if (gEve) {
338 gEve->Terminate();
339 }
340
341 delete m_visualizer;
342 delete m_display;
343}
Track created by the CDC trigger.
bool m_showCDCHits
If true, CDCHit objects will be shown as drift cylinders (shortened, z position set to zero).
Definition: DisplayModule.h:81
bool m_showTriggerObjects
If true, CDCHit objects will be assigned to trigger segments and trigger tracks will be shown.
Definition: DisplayModule.h:84
bool m_showTrackLevelObjects
If true, fitted RecoTracks, GFRave Vertices and ECLGamma objects will be shown in the display.
Definition: DisplayModule.h:75
DisplayModule()
Constructor. Sets all the module parameters.
bool m_showRecoTracks
Whether to show RecoTracks.
Definition: DisplayModule.h:78
bool m_showKLM2dHits
If true, KLMHit2d objects will be shown in the display.
Definition: DisplayModule.h:87
void initialize() override
Sets up geometry if needed.
bool m_automatic
Non-interactively save visualizations for each event.
Definition: DisplayModule.h:93
void event() override
Show various reconstructed or simulated objects in the event viewer until the next event is requested...
std::vector< std::string > m_deleteVolumes
List of volumes to be deleted.
void terminate() override
Terminate gEve to avoid problems with root's cleanup.
bool m_showAllPrimaries
If true, all primary MCParticles will be shown, regardless of wether hits are produced.
Definition: DisplayModule.h:63
bool m_showNeutrals
If true, all neutral primary and secondary MCParticles will be shown, regardless of wether hits are p...
Definition: DisplayModule.h:72
bool m_showCharged
If true, all charged primary and secondary MCParticles will be shown, regardless of wether hits are p...
Definition: DisplayModule.h:69
EVEVisualization * m_visualizer
Pointer to visualizer.
bool m_showMCInfo
Show Monte Carlo information (MCParticles, SimHits).
Definition: DisplayModule.h:57
bool m_fullGeometry
Show full geometry instead of simplified shapes.
Definition: DisplayModule.h:96
bool m_showARICHHits
If true, ARICHHit objects will be shown as squares, corresponding to channel pixels.
Definition: DisplayModule.h:90
std::string m_options
List of drawing options, see EVEVisualization::setOptions()
Definition: DisplayModule.h:54
DisplayUI * m_display
pointer to actual display
bool m_hideSecondaries
If true, secondary MCParticles (and hits created by them) will not be shown.
Definition: DisplayModule.h:66
bool m_playOnStartup
Start the module advancing through events.
Definition: DisplayModule.h:99
std::vector< std::string > m_hideVolumes
List of volumes to be hidden (can be re-enabled in Eve panel / Geometry scene.
bool m_assignToPrimaries
If true, hits created by secondary particles (e.g.
Definition: DisplayModule.h:60
std::string m_customGeometryExtractPath
Path to custom file with geometry extract.
std::vector< std::string > m_hideObjects
objects which are to be hidden (can be manually re-enabled in tree view).
Control TEve browser user interface.
Definition: DisplayUI.h:41
void clearEvent()
remove all event data in current event.
Definition: DisplayUI.cc:282
void hideObjects(const std::vector< std::string > &names)
hide objects with the given names.
Definition: DisplayUI.h:112
bool getReturnValue() const
Return value for current event, only makes sense if allowFlaggingEvents(true) was called.
Definition: DisplayUI.cc:134
bool cumulativeIsOn() const
If true, DisplayModule shouldn't clear previous data (i.e.
Definition: DisplayUI.h:148
void addParameter(const std::string &label, ModuleParam< bool > &param, int level)
Generate UI elements so the given module parameter can be changed at run time.
Definition: DisplayUI.cc:87
bool startDisplay()
Start interactive display for current event.
Definition: DisplayUI.cc:337
void showUserData(const DisplayData &displayData)
Add user-defined data (histograms, etc.).
Definition: DisplayUI.cc:831
void allowFlaggingEvents(const std::string &description="")
Show control for flagging events (to set module return value).
Definition: DisplayUI.cc:124
ECL cluster data.
Definition: ECLCluster.h:27
@ c_nPhotons
CR is split into n photons (N1)
Produces visualisation for MCParticles, simhits, genfit::Tracks, geometry and other things.
void clearEvent()
clear event data.
void setOptions(const std::string &opts)
Set the display options.
void addSimHits(const StoreArray< T > &hits)
Add all entries in the given 'hits' array (and the corresponding MCParticles) to the event scene.
void setHideSecondaries(bool on)
If true, secondary MCParticles (and hits created by them) will not be shown.
void setAssignToPrimaries(bool on)
If true, hits created by secondary particles (e.g.
void addTrackCandidateImproved(const std::string &collectionName, const RecoTrack &recoTrack)
Add a RecoTrack, but use stored genfit track representation to make visualisation objects.
void addCDCHit(const CDCHit *hit, bool showTriggerHits=false)
show CDCHits directly.
void addBKLMHit2d(const KLMHit2d *bklm2dhit)
Add a reconstructed 2d hit in the BKLM.
void addVertex(const genfit::GFRaveVertex *vertex)
Add a vertex point and its covariance matrix.
void addCDCTriggerTrack(const std::string &collectionName, const CDCTriggerTrack &track)
Add a CDCTriggerTrack.
void addCDCTriggerSegmentHit(const std::string &collectionName, const CDCTriggerSegmentHit *hit)
show outline of track segments.
void addECLCluster(const ECLCluster *cluster)
Add a reconstructed cluster in the ECL.
void makeTracks()
Create visual representation of all tracks.
void addUnassignedRecoHits(const StoreArray< T > &hits)
After adding recohits for tracks/candidates, this function adds the remaining hits in a global collec...
void addTrack(const Belle2::Track *belle2Track)
Add this genfit::Track to event data.
void addEKLMHit2d(const KLMHit2d *eklm2dhit)
Add a reconstructed 2d hit in the EKLM.
void addARICHHit(const ARICHHit *hit)
Add recontructed hit in ARICH.
void showUserData(const DisplayData &displayData)
Add user-defined data (labels, points, etc.)
void addTOPDigits(const StoreArray< TOPDigit > &digits)
Add TOPDigits (shown aggregated per module).
void addROI(const ROIid *roi)
Add a Region Of Interest, computed by the PXDDataReduction module.
void addKLMCluster(const KLMCluster *cluster)
Add a reconstructed cluster in the KLM.
MCTrack * addMCParticle(const MCParticle *particle)
Return MCTrack for given particle, add it if it doesn't exist yet.
void addTrackCandidate(const std::string &collectionName, const RecoTrack &recoTrack)
Add a RecoTrack, to evaluate track finding.
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
Definition: Gearbox.h:123
KLM cluster data.
Definition: KLMCluster.h:28
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
Base class for Modules.
Definition: Module.h:72
const ModuleCondition * getCondition() const
Return a pointer to the first condition (or nullptr, if none was set)
Definition: Module.h:314
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
bool hasCondition() const
Returns true if at least one condition was set for the module.
Definition: Module.h:311
std::string getPathString() const override
return the module name.
Definition: Module.cc:192
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
static std::vector< std::string > getArrayList(DataStore::EDurability durability=DataStore::c_Event)
Return list of array names with matching type.
Definition: StoreArray.h:275
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Class that bundles various TrackFitResults.
Definition: Track.h:25
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void addGeometry(EType visMode)
Add TGeo geometry to Eve (only needs to be done once.)
Definition: EveGeometry.cc:36
void setDeleteVolumes(const std::vector< std::string > &volumes)
List of volumes to be removed.
Definition: EveGeometry.cc:228
void setVisualisationMode(EType visMode)
switch to given visualisation mode.
Definition: EveGeometry.cc:139
void setCustomExtractPath(const std::string &extractPath)
Set custom path to the geometry extract (to change originally hard-coded value)
Definition: EveGeometry.cc:218
void setHideVolumes(const std::vector< std::string > &volumes)
List of volumes to be hidden (can be re-enabled in Eve panel / Geometry scene.
Definition: EveGeometry.cc:223
@ c_Full
Full geometry converted from Geant4 (use this for non-standard Belle II setups!).
Definition: EveGeometry.h:26
@ c_Simplified
a simplified Belle II geometry.
Definition: EveGeometry.h:27
Abstract base class for different kinds of events.