Belle II Software  release-08-01-10
GenfitVisModule.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 
9 #include "tracking/modules/genfitVisModule/GenfitVisModule.h"
10 
11 #include <framework/datastore/StoreArray.h>
12 
13 #include <geometry/GeometryManager.h>
14 #include <genfit/Track.h>
15 #include <genfit/FieldManager.h>
16 #include <genfit/MaterialEffects.h>
17 
18 #include <TGeoManager.h>
19 
20 using namespace Belle2;
21 
22 //-----------------------------------------------------------------
23 // Register the Module
24 //-----------------------------------------------------------------
25 REG_MODULE(GenfitVis);
26 
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
30 
32 {
33  // Set module properties
34  setDescription("Visualize genfit::Tracks using the genfit::EventDisplay.");
35 
36  // Parameter definitions
37  addParam("onlyBadTracks", m_onlyBadTracks, "show only unfitted and unconverged tracks", false);
38 
39 }
40 
42 {
43  if (!genfit::MaterialEffects::getInstance()->isInitialized())
44  B2FATAL("No material effects setup. Please use SetupGenfitExtrapolationModule.");
45 
46  if (gGeoManager == nullptr) {
47  B2INFO("Setting up TGeo geometry for visualization.");
49  geoManager.createTGeoRepresentation();
50  }
51  if (!gGeoManager)
52  B2FATAL("Couldn't create TGeo geometry.");
53 
54  if (!genfit::FieldManager::getInstance()->isInitialized()) {
55  B2FATAL("Magnetic field not set up. Please use SetupGenfitExtrapolationModule.");
56  }
57 
58  m_display = genfit::EventDisplay::getInstance();
59 }
60 
62 {
63  StoreArray < genfit::Track > gfTracks("GF2Tracks");
64  std::vector<const genfit::Track*> tracks;
65 
66  const int nTracks = gfTracks.getEntries();
67  for (int iTrack = 0; iTrack < nTracks; ++iTrack) {
68  const genfit::Track* tr = gfTracks[iTrack];
69  if (m_onlyBadTracks &&
70  tr->getFitStatus()->isFitted() &&
72  continue;
73  //std::cout << " =============== pushing track ======= " << std::endl;
74  tracks.push_back(tr);
75  }
76 
77  if (tracks.size() > 0)
78  m_display->addEvent(tracks);
79 }
80 
82 {
83  m_display->open();
84 }
85 
87 {
88 }
89 
90 
bool m_onlyBadTracks
if true, tracks which have been fitted and the fit converged will no be shown
void initialize() override
Initialize the EventDisplay.
void event() override
Add genfit::Tracks to display.
void endRun() override
Open display.
void terminate() override
Close display.
GenfitVisModule()
Constructor: Sets the description, the properties and the parameters of the module.
genfit::EventDisplay * m_display
pointer to the genfit::EventDisplay which gets created in initialize()
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Class to manage the creation and conversion of the geometry.
static GeometryManager & getInstance()
Return a reference to the instance.
void createTGeoRepresentation()
Create a TGeo representation of the native geometry description.
void open()
Open the event display.
void addEvent(std::vector< genfit::Track * > &tracks)
Add new event.
static FieldManager * getInstance()
Get singleton instance.
Definition: FieldManager.h:119
bool isFitConverged(bool inAllPoints=true) const
Did the fit converge (in all Points or only partially)?
Definition: FitStatus.h:105
bool isFitted() const
Has the track been fitted?
Definition: FitStatus.h:94
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
Definition: Track.h:71
FitStatus * getFitStatus(const AbsTrackRep *rep=nullptr) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
Definition: Track.h:154
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.