Belle II Software  release-06-02-00
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 
30 using namespace Belle2;
31 
32 REG_MODULE(Display)
33 
34 DisplayModule::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("showBKLM2dHits", m_showBKLM2dHits,
64  "If true, BKLM2dHit objects will be shown in the display", true);
65  addParam("showEKLM2dHits", m_showEKLM2dHits,
66  "If true, EKLMHit2d objects will be shown in the display", true);
67  addParam("showARICHHits", m_showARICHHits,
68  "If true, ARICHHit objects will be shown.", false);
69  addParam("automatic", m_automatic,
70  "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.",
71  false);
72  addParam("fullGeometry", m_fullGeometry,
73  "Show full geometry instead of simplified shapes. Further details can be enabled by changing the VisLevel option for Eve -> Scenes -> Geometry Scene -> Top_1.",
74  false);
75  addParam("hideObjects", m_hideObjects,
76  "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'.)", {});
77  addParam("customGeometryExtractPath", m_customGeometryExtractPath, "Path to custom file with geometry extract.", std::string(""));
78  addParam("hideVolumes", m_hideVolumes,
79  "List of volumes to be hidden (can be re-enabled in Eve panel / Geometry scene. The volume and all its daughters will be hidden.", {});
80  addParam("deleteVolumes", m_deleteVolumes,
81  "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)", {});
82  addParam("playOnStartup", m_playOnStartup,
83  "When launching the event display, immediately start advancing through events. Useful for control room uses etc.", false);
84 
85 
86  //create gApplication so we can use graphics support. Needs to be done before ROOT has a chance to do it for us.
87  if ((!gApplication) || (gApplication->TestBit(TApplication::kDefaultApplication))) {
88  new TApplication("ROOT_application", 0, 0);
89  }
90 }
91 
92 
94 {
95  //optional inputs
96  StoreArray<MCParticle> MCParticles; MCParticles.isOptional();
97  StoreArray<MCParticleTrajectory> MCParticleTrajectorys; MCParticleTrajectorys.isOptional();
98  StoreArray<CDCSimHit> CDCSimHits; CDCSimHits.isOptional();
99  StoreArray<PXDSimHit> PXDSimHits; PXDSimHits.isOptional();
100  StoreArray<SVDSimHit> SVDSimHits; SVDSimHits.isOptional();
101  StoreArray<BKLMSimHit> BKLMSimHits; BKLMSimHits.isOptional();
102  StoreArray<EKLMSimHit> EKLMSimHits; EKLMSimHits.isOptional();
103  StoreArray<ECLCluster> ECLClusters; ECLClusters.isOptional();
104  StoreArray<KLMCluster> KLMClusters; KLMClusters.isOptional();
105  StoreArray<BKLMHit2d> BKLMHit2ds; BKLMHit2ds.isOptional();
106  StoreArray<EKLMHit2d> EKLMHit2ds; EKLMHit2ds.isOptional();
107  StoreArray<Track> Tracks; Tracks.isOptional();
108  StoreArray<TrackFitResult> TrackFitResults; TrackFitResults.isOptional();
109  StoreArray<RecoTrack> RecoTracks; RecoTracks.isOptional();
110  StoreArray<genfit::GFRaveVertex> GFRaveVertexs; GFRaveVertexs.isOptional();
111  StoreObjPtr<DisplayData> DisplayDatas; DisplayDatas.isOptional();
112  StoreArray<PXDCluster> PXDClusters; PXDClusters.isOptional();
113  StoreArray<SVDCluster> SVDClusters; SVDClusters.isOptional();
114  StoreArray<CDCHit> CDCHits; CDCHits.isOptional();
115  StoreArray<CDCTriggerSegmentHit> CDCTriggerSegmentHits; CDCTriggerSegmentHits.isOptional();
116  StoreArray<ARICHHit> ARICHHits; ARICHHits.isOptional();
117  StoreArray<TOPDigit> TOPDigits; TOPDigits.isOptional();
118  StoreArray<ROIid> ROIids; ROIids.isOptional();
119  StoreArray<RecoHitInformation::UsedPXDHit> UsedPXDHits; UsedPXDHits.isOptional();
120  StoreArray<RecoHitInformation::UsedSVDHit> UsedSVDHits; UsedSVDHits.isOptional();
121  StoreArray<RecoHitInformation::UsedCDCHit> UsedCDCHits; UsedCDCHits.isOptional();
122 
124  if (hasCondition())
126  m_display->addParameter("Show MC info", getParam<bool>("showMCInfo"), 0);
127  {
128  //MC-specific parameters
129  m_display->addParameter("Assign hits to primary particles", getParam<bool>("assignHitsToPrimaries"), 1);
130  m_display->addParameter("Show all primaries", getParam<bool>("showAllPrimaries"), 1);
131  m_display->addParameter("Show all charged particles", getParam<bool>("showCharged"), 1);
132  m_display->addParameter("Show all neutral particles", getParam<bool>("showNeutrals"), 1);
133  m_display->addParameter("Hide secondaries", getParam<bool>("hideSecondaries"), 1);
134  }
135  m_display->addParameter("Show candidates and rec. hits", getParam<bool>("showRecoTracks"), 0);
136  m_display->addParameter("Show tracks, vertices, gammas", getParam<bool>("showTrackLevelObjects"), 0);
137 
138  if (!m_fullGeometry and Gearbox::getInstance().exists("Detector/Name")) {
139  std::string detectorName = Gearbox::getInstance().getString("Detector/Name");
140  if (detectorName != "Belle2Detector") {
141  B2INFO("Non-standard detector '" << detectorName << "' used, switching to full geometry.");
142  m_fullGeometry = true;
143  }
144  }
145  if (m_fullGeometry) {
146  //pass some parameters to DisplayUI to be able to change them at run time
147  m_display->addParameter("Show full geometry", getParam<bool>("fullGeometry"), 0);
148  }
149 
151 
154 
159 }
160 
161 
162 
164 {
165  setReturnValue(false);
166  if (!gEve) {
167  //window closed?
168  B2WARNING("Display window closed, continuing with next module. (hit Ctrl+C to exit)");
169  return;
170  }
171 
173 
174  //secondaries cannot be shown if they are merged into primaries
177  B2WARNING("assignHitsToPrimaries and showCharged/showNeutrals can not be used together!");
178  }
179 
181 
182  if (m_showMCInfo) {
183  //gather MC particles
184  StoreArray<MCParticle> mcparticles;
186  for (const MCParticle& part : mcparticles) {
187  if ((m_showAllPrimaries and part.hasStatus(MCParticle::c_PrimaryParticle))
188  or (m_showCharged and TMath::Nint(part.getCharge()) != 0)
189  or (m_showNeutrals and TMath::Nint(part.getCharge()) == 0)) {
190  m_visualizer->addMCParticle(&part);
191  }
192  }
193  }
194 
195  //gather simhits
201  }
202 
203 
204  if (m_showRecoTracks) {
205  //add all possible track candidate arrays
206  const auto recoTrackArrays = StoreArray<RecoTrack>::getArrayList();
207  for (std::string colName : recoTrackArrays) {
208  StoreArray<RecoTrack> recoTracks(colName);
209  for (const RecoTrack& recoTrack : recoTracks) {
210  if (colName != "RecoTracksMpl") {
211  m_visualizer->addTrackCandidate(colName, recoTrack);
212  } else {
213  m_visualizer->addTrackCandidateImproved(colName, recoTrack);
214  }
215  }
216  }
217 
221 
222  //add remaining recohits
223  m_visualizer->addUnassignedRecoHits(pxdStoreArray);
224  m_visualizer->addUnassignedRecoHits(svdStoreArray);
225  m_visualizer->addUnassignedRecoHits(cdcStoreArray);
226 
227  StoreArray<ROIid> ROIs;
228  for (int i = 0 ; i < ROIs.getEntries(); i++)
229  m_visualizer->addROI(ROIs[i]);
230  //well, non-standard names are used for testbeams?
231  StoreArray<ROIid> testbeamROIs("ROIs");
232  for (int i = 0 ; i < testbeamROIs.getEntries(); i++)
233  m_visualizer->addROI(testbeamROIs[i]);
234  }
235 
237  StoreArray<CDCHit> cdchits;
238  for (auto& hit : cdchits)
240  }
241 
242  if (m_showTriggerObjects) {
243  const auto arrayList = StoreArray<CDCTriggerSegmentHit>::getArrayList();
244  for (const auto& i : arrayList) {
246  for (auto& hit : tshits)
248  }
249 
250  //add all possible track candidate arrays
251  const auto trgTrackArrays = StoreArray<CDCTriggerTrack>::getArrayList();
252  for (std::string colName : trgTrackArrays) {
253  StoreArray<CDCTriggerTrack> trgTracks(colName);
254  for (const CDCTriggerTrack& trgTrack : trgTracks) {
255  m_visualizer->addCDCTriggerTrack(colName, trgTrack);
256  }
257  }
258  }
259 
260  if (m_showBKLM2dHits) {
261  StoreArray<BKLMHit2d> bklmhits;
262  for (auto& hit : bklmhits)
263  m_visualizer->addBKLMHit2d(&hit);
264  }
265 
266  if (m_showEKLM2dHits) {
267  StoreArray<EKLMHit2d> eklmhits;
268  for (auto& hit : eklmhits)
269  m_visualizer->addEKLMHit2d(&hit);
270  }
271 
272  if (m_showARICHHits) {
273  StoreArray<ARICHHit> arichhits;
274  for (auto& hit : arichhits)
275  m_visualizer->addARICHHit(&hit);
276  }
277 
279  //gather track-level objects
280  StoreArray<Track> tracks;
281  for (const Track& track : tracks)
282  m_visualizer->addTrack(&track);
283 
285  const int nVertices = vertices.getEntries();
286  for (int i = 0; i < nVertices; i++) {
287  m_visualizer->addVertex(vertices[i]);
288  }
289 
290  StoreArray<ECLCluster> clusters;
291  for (const ECLCluster& cluster : clusters) {
292  if (cluster.hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) {
293  if (m_showMCInfo) {
294  //make sure we add particles producing these
295  const MCParticle* mcpart = cluster.getRelated<MCParticle>();
296  if (mcpart)
297  m_visualizer->addMCParticle(mcpart);
298  }
299 
300  m_visualizer->addECLCluster(&cluster);
301  }
302  }
303 
304  StoreArray<KLMCluster> klmclusters;
305  for (const KLMCluster& cluster : klmclusters) {
306  if (m_showMCInfo) {
307  //make sure we add particles producing these
308  const MCParticle* mcpart = cluster.getRelated<MCParticle>();
309  if (mcpart)
310  m_visualizer->addMCParticle(mcpart);
311  }
312 
313  m_visualizer->addKLMCluster(&cluster);
314  }
315 
317  }
318 
319  //all hits/tracks are added, finish visual representations
321 
322  StoreObjPtr<DisplayData> displayData;
323  if (displayData) {
324  m_visualizer->showUserData(*displayData);
325  m_display->showUserData(*displayData);
326  }
327 
328 
329  bool reshow = m_display->startDisplay();
331  if (!m_display->cumulativeIsOn()) {
332  m_visualizer->clearEvent(); //clean up internal state of visualiser
333  }
334  m_display->clearEvent(); //clean up event scene, incl. projections
335 
336  //reprocess current event (maybe some options changed)
337  if (reshow)
338  event();
339 }
340 
341 
343 {
344  if (gEve) {
345  gEve->Terminate();
346  }
347 
348  delete m_visualizer;
349  delete m_display;
350 }
Track created by the CDC trigger.
The event display module.
Definition: DisplayModule.h:38
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
bool m_showEKLM2dHits
If true, EKLMHit2d objects will be shown in the display.
Definition: DisplayModule.h:90
bool m_showRecoTracks
Whether to show RecoTracks.
Definition: DisplayModule.h:78
void initialize() override
Sets up geometry if needed.
bool m_automatic
Non-interactively save visualizations for each event.
Definition: DisplayModule.h:96
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_showBKLM2dHits
If true, BKLMHit objects will be shown in the display.
Definition: DisplayModule.h:87
bool m_fullGeometry
Show full geometry instead of simplified shapes.
Definition: DisplayModule.h:99
bool m_showARICHHits
If true, ARICHHit objects will be shown as squares, corresponding to channel pixels.
Definition: DisplayModule.h:93
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.
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:284
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:88
bool startDisplay()
Start interactive display for current event.
Definition: DisplayUI.cc:339
void showUserData(const DisplayData &displayData)
Add user-defined data (histograms, etc.).
Definition: DisplayUI.cc:833
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 BKLMHit2d *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 addEKLMHit2d(const EKLMHit2d *bklm2dhit)
Add a reconstructed 2d hit in the EKLM.
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 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
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
const ModuleCondition * getCondition() const
Return a pointer to the first condition (or nullptr, if none was set)
Definition: Module.h:314
std::string getPathString() const override
return the module name.
Definition: Module.cc:192
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:76
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
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:95
Class that bundles various TrackFitResults.
Definition: Track.h:25
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81
#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.