ATLAS Offline Software
Loading...
Searching...
No Matches
Example3DSystem4.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class Example3DSystem4 //
8// //
9// Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10// //
11// Initial version: June 2007 //
12// //
14
16#include "ui_example4controllerform.h"
17
18#include <Inventor/nodes/SoSeparator.h>
19#include <Inventor/nodes/SoLineSet.h>
20#include <Inventor/nodes/SoVertexProperty.h>
21#include <Inventor/nodes/SoSwitch.h>
22
24#include "TrkTrack/Track.h"
27//#include "CLHEP/Units/SystemOfUnits.h"
28#include "GaudiKernel/SystemOfUnits.h"
29
30
31//_____________________________________________________________________________________
33 : IVP13DSystemSimple("Ex3DSys4",
34 "This is an illustration of a very basic 3D system.\n"
35 "It transforms track information found in storegate"
36 " into 3D objects, displays track information upon selection, and has a controller which allows the user to set a pt cut on tracks.",
37 "Thomas.Kittelmann@cern.ch"), m_ptcut(0*Gaudi::Units::GeV)
38{
39}
40
41//_____________________________________________________________________________________
43{
44 //Clear maps:
45 m_nodeToTrack.clear();
46 m_switchToPt.clear();
47
48 //1) Try to get the collection of (InDet) tracks from storegate:
49
50 //Sanity check:
51 if (!sg) {
52 message("Error: Got null storegate pointer");
53 return;
54 }
55
56 const TrackCollection *trackColl;
57 std::string trackname="Tracks";
58 StatusCode status = sg->retrieve(trackColl, trackname);
59 if (status != StatusCode::SUCCESS || !trackColl) {
60 message("Error: Could not retrieve track collection (used key="+QString(trackname.c_str())+")");
61 return;
62 }
63
64 //2) Loop over the tracks and construct a relevant 3D object for each of them (a SoLineSet):
65
66 TrackCollection::const_iterator trackItr, trackItrEnd = trackColl->end();
67
68 for ( trackItr = trackColl->begin() ; trackItr != trackItrEnd; ++trackItr) {
69 const Trk::Track *track = (*trackItr);
70 const DataVector<const Trk::TrackParameters> *params = track->trackParameters();
71
72 //Just a sanity check (we need at least two points on the track):
73 if ( !params || params->size()<2 )
74 continue;
75
76 //The list of points on this track should be set in a so-called
77 //SoVertexProperty (which one realises by reading the
78 //documentation for SoLineSet at http://doc.coin3d.org/Coin/):
79
80 SoVertexProperty *vertices = new SoVertexProperty();
81
82 int iver(0);
84 for (it = params->begin();it!=itE;++it) {
85 vertices->vertex.set1Value(iver++,(*it)->position().x(),(*it)->position().y(),(*it)->position().z());
86 }
87
88 //Create a set of lines from these vertices:
89 SoLineSet * line = new SoLineSet();
90 line->numVertices = iver;
91 line->vertexProperty = vertices;
92
93 //We add the line to the tree below an SoSwitch. The latter is needed to turn the track on/off:
94 SoSwitch * sw = new SoSwitch();
95
96 // initial value of switch is based on current pt cut:
97 double pt = params->front()->pT();
98 sw->whichChild = pt > m_ptcut ? SO_SWITCH_ALL : SO_SWITCH_NONE;
99
100 // the user might change the pt cut later, so we need a list of the switches and the pT of their corresponding tracks:
101 m_switchToPt[sw] = pt;
102
103 sw->addChild(line);
104 root->addChild(sw);
105
106 //Bookkeep which track this 3D object corresponds to (we will need this to display track info when the user clicks):
107 m_nodeToTrack[line] = track;
108
109 //To avoid GUI freeze-ups:
110 updateGUI();
111 }
112
113}
114
115//_____________________________________________________________________________________
116void Example3DSystem4::userPickedNode(SoNode* pickedNode, SoPath * /*pickedPath*/) {
117
118 //User clicked on "pickedNode". We should know which track this belongs to:
119 if (m_nodeToTrack.find(pickedNode)==m_nodeToTrack.end()) {
120 message("Error: Does not have track information for picked node");
121 return;
122 }
123
124 //Get parameters:
125 const DataVector<const Trk::TrackParameters> *params = m_nodeToTrack[pickedNode]->trackParameters();
126 if ( !params || params->empty() ) {
127 message("Error: Track has no trackparameters");
128 return;
129 }
130
131 //Show some interesting information (from the first trackparameter):
132 message("===> Track info:");
133 message(" |p| = "+QString::number(params->front()->momentum().mag()/Gaudi::Units::GeV)+" GeV");
134 message(" pT = "+QString::number(params->front()->pT()/Gaudi::Units::GeV)+" GeV");
135 message(" Q = "+QString::number(params->front()->charge()));
136 message(" eta = "+QString::number(params->front()->eta()));
137
138}
139
140//_____________________________________________________________________________________
142{
143 QWidget * controller = new QWidget(0);
144 Ui::Example4ControllerForm ui;
145 ui.setupUi(controller);
146
147 m_ptcut = ui.doubleSpinBox_ptcut->value()*Gaudi::Units::GeV;
148 connect(ui.doubleSpinBox_ptcut,SIGNAL(valueChanged(double)),this,SLOT(ptCutChanged(double)));
149
150 return controller;
151}
152
153//_____________________________________________________________________________________
155{
156 //Save this value since we need it when building next event:
157 m_ptcut = ptcut*Gaudi::Units::GeV;
158
159 //Update switches to display relevant tracks:
160 std::map<SoSwitch*,double>::iterator it, itE = m_switchToPt.end();
161 for ( it = m_switchToPt.begin(); it!=itE; ++it) {
162 it->first->whichChild = ( it->second>m_ptcut ? SO_SWITCH_ALL : SO_SWITCH_NONE );
163 }
164}
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void ptCutChanged(double)
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
std::map< SoSwitch *, double > m_switchToPt
QWidget * buildController()
std::map< SoNode *, const Trk::Track * > m_nodeToTrack
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
void message(const QString &) const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
=============================================================================