ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1Systems
VP1TestSystems
src
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
15
#include "
VP1TestSystems/Example3DSystem4.h
"
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
23
#include "
StoreGate/StoreGateSvc.h
"
24
#include "
TrkTrack/Track.h
"
25
#include "
TrkTrack/TrackCollection.h
"
26
#include "
TrkParameters/TrackParameters.h
"
27
//#include "CLHEP/Units/SystemOfUnits.h"
28
#include "GaudiKernel/SystemOfUnits.h"
29
30
31
//_____________________________________________________________________________________
32
Example3DSystem4::Example3DSystem4
()
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
//_____________________________________________________________________________________
42
void
Example3DSystem4::buildEventSceneGraph
(
StoreGateSvc
* sg, SoSeparator *root)
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);
83
DataVector<const Trk::TrackParameters>::const_iterator
it, itE = params->end();
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
//_____________________________________________________________________________________
116
void
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
//_____________________________________________________________________________________
141
QWidget *
Example3DSystem4::buildController
()
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
//_____________________________________________________________________________________
154
void
Example3DSystem4::ptCutChanged
(
double
ptcut)
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
}
Example3DSystem4.h
GeV
#define GeV
Definition
PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
StoreGateSvc.h
TrackCollection.h
TrackCollection
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Definition
TrackCollection.h:19
TrackParameters.h
Track.h
DataVector
Derived DataVector<T>.
Definition
DataVector.h:795
DataVector< Trk::Track >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Example3DSystem4::ptCutChanged
void ptCutChanged(double)
Definition
Example3DSystem4.cxx:154
Example3DSystem4::buildEventSceneGraph
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Definition
Example3DSystem4.cxx:42
Example3DSystem4::m_switchToPt
std::map< SoSwitch *, double > m_switchToPt
Definition
Example3DSystem4.h:44
Example3DSystem4::m_ptcut
double m_ptcut
Definition
Example3DSystem4.h:45
Example3DSystem4::buildController
QWidget * buildController()
Definition
Example3DSystem4.cxx:141
Example3DSystem4::Example3DSystem4
Example3DSystem4()
Definition
Example3DSystem4.cxx:32
Example3DSystem4::m_nodeToTrack
std::map< SoNode *, const Trk::Track * > m_nodeToTrack
Definition
Example3DSystem4.h:43
Example3DSystem4::userPickedNode
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
Definition
Example3DSystem4.cxx:116
IVP13DSystemSimple::IVP13DSystemSimple
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
Definition
IVP13DSystemSimple.cxx:50
IVP13DSystemSimple::updateGUI
void updateGUI()
Definition
IVP13DSystemSimple.h:89
IVP1System::message
void message(const QString &) const
Definition
IVP1System.cxx:336
StoreGateSvc
The Athena Transient Store API.
Definition
StoreGateSvc.h:120
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
Trk::Track
The ATLAS Track class.
Definition
Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Athena::Units
Definition
Units.h:45
Gaudi
=============================================================================
Definition
CaloGPUClusterAndCellDataMonitorOptions.h:273
Generated on
for ATLAS Offline Software by
1.17.0