ATLAS Offline Software
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 
21 #include "StoreGate/StoreGateSvc.h"
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):
95 
96  //To avoid GUI freeze-ups:
97  updateGUI();
98 
99  }
100 
101 }
102 
103 //_____________________________________________________________________________________
104 void 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 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
checkFileSG.line
line
Definition: checkFileSG.py:75
IVP13DSystemSimple
Definition: IVP13DSystemSimple.h:24
TrackParameters.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
skel.it
it
Definition: skel.GENtoEVGEN.py:423
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
TruthTest.itE
itE
Definition: TruthTest.py:25
Example3DSystem3::m_nodeToTrack
std::map< SoNode *, const Trk::Track * > m_nodeToTrack
Definition: Example3DSystem3.h:38
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
Track.h
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
Example3DSystem3::Example3DSystem3
Example3DSystem3()
Definition: Example3DSystem3.cxx:30
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Example3DSystem3::buildEventSceneGraph
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Definition: Example3DSystem3.cxx:40
TrackCollection.h
DataVector< Trk::Track >
python.selection.number
number
Definition: selection.py:20
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Example3DSystem3::userPickedNode
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
Definition: Example3DSystem3.cxx:104
IVP13DSystemSimple::updateGUI
void updateGUI()
Definition: IVP13DSystemSimple.h:89
merge.status
status
Definition: merge.py:17
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Example3DSystem3.h
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
StoreGateSvc.h
IVP1System::message
void message(const QString &) const
Definition: IVP1System.cxx:336
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.