ATLAS Offline Software
Loading...
Searching...
No Matches
Example3DSystem3.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 Example3DSystem3 //
8// //
9// Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10// //
11// Initial version: June 2007 //
12// //
14
16
17#include <Inventor/nodes/SoSeparator.h>
18#include <Inventor/nodes/SoLineSet.h>
19#include <Inventor/nodes/SoVertexProperty.h>
20
22#include "TrkTrack/Track.h"
25//#include "CLHEP/Units/SystemOfUnits.h"
26#include "GaudiKernel/SystemOfUnits.h"
27
28
29//_____________________________________________________________________________________
31 : IVP13DSystemSimple("Ex3DSys3",
32 "This is an illustration of a very basic 3D system.\n"
33 "It transforms track information found in storegate"
34 " into relevant 3D objects (SoLineSet's), and displays track information when tracks are selected by the cursor.",
35 "Thomas.Kittelmann@cern.ch")
36{
37}
38
39//_____________________________________________________________________________________
41{
42 //Clear node2Track info:
43 m_nodeToTrack.clear();
44
45 //1) Try to get the collection of (InDet) tracks from storegate:
46
47 //Sanity check:
48 if (!sg) {
49 message("Error: Got null storegate pointer");
50 return;
51 }
52
53 const TrackCollection *trackColl;
54 std::string trackname="Tracks";
55 StatusCode status = sg->retrieve(trackColl, trackname);
56 if (status != StatusCode::SUCCESS || !trackColl) {
57 message("Error: Could not retrieve track collection (used key="+QString(trackname.c_str())+")");
58 return;
59 }
60
61 //2) Loop over the tracks and construct a relevant 3D object for each of them (a SoLineSet):
62
63 TrackCollection::const_iterator trackItr, trackItrEnd = trackColl->end();
64
65 for ( trackItr = trackColl->begin() ; trackItr != trackItrEnd; ++trackItr) {
66 const Trk::Track *track = (*trackItr);
67 const DataVector<const Trk::TrackParameters> *params = track->trackParameters();
68
69 //Just a sanity check (we need at least two points on the track):
70 if ( !params || params->size()<2 )
71 continue;
72
73 //The list of points on this track should be set in a so-called
74 //SoVertexProperty (which one realises by reading the
75 //documentation for SoLineSet at http://doc.coin3d.org/Coin/):
76
77 SoVertexProperty *vertices = new SoVertexProperty();
78
79 int iver(0);
81 for (it = params->begin();it!=itE;++it) {
82 vertices->vertex.set1Value(iver++,(*it)->position().x(),(*it)->position().y(),(*it)->position().z());
83 }
84
85 //Create a set of lines from these vertices:
86 SoLineSet * line = new SoLineSet();
87 line->numVertices = iver;
88 line->vertexProperty = vertices;
89
90 //Add to the tree:
91 root->addChild(line);
92
93 //Bookkeep which track this 3D object corresponds to (we will need this to display track info when the user clicks):
94 m_nodeToTrack[line] = track;
95
96 //To avoid GUI freeze-ups:
97 updateGUI();
98
99 }
100
101}
102
103//_____________________________________________________________________________________
104void Example3DSystem3::userPickedNode(SoNode* pickedNode, SoPath * /*pickedPath*/) {
105
106 //User clicked on "pickedNode". We should know which track this belongs to:
107 if (m_nodeToTrack.find(pickedNode)==m_nodeToTrack.end()) {
108 message("Error: Does not have track information for picked node");
109 return;
110 }
111
112 //Get parameters:
113 const DataVector<const Trk::TrackParameters> *params = m_nodeToTrack[pickedNode]->trackParameters();
114 if ( !params || params->empty() ) {
115 message("Error: Track has no trackparameters");
116 return;
117 }
118
119 //Show some interesting information (from the first trackparameter):
120 message("===> Track info:");
121 message(" |p| = "+QString::number(params->front()->momentum().mag()/Gaudi::Units::GeV)+" GeV");
122 message(" pT = "+QString::number(params->front()->pT()/Gaudi::Units::GeV)+" GeV");
123 message(" Q = "+QString::number(params->front()->charge()));
124 message(" eta = "+QString::number(params->front()->eta()));
125
126}
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.
std::map< SoNode *, const Trk::Track * > m_nodeToTrack
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
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*.