ATLAS Offline Software
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 
23 #include "StoreGate/StoreGateSvc.h"
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):
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 //_____________________________________________________________________________________
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:
158 
159  //Update switches to display relevant tracks:
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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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
Example3DSystem4.h
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
skel.it
it
Definition: skel.GENtoEVGEN.py:423
test_pyathena.pt
pt
Definition: test_pyathena.py:11
Example3DSystem4::m_ptcut
double m_ptcut
Definition: Example3DSystem4.h:45
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.ptcut
float ptcut
Definition: Pythia8_A14_NNPDF23LO_forMGHT_EvtGen.py:9
Example3DSystem4::m_nodeToTrack
std::map< SoNode *, const Trk::Track * > m_nodeToTrack
Definition: Example3DSystem4.h:43
TruthTest.itE
itE
Definition: TruthTest.py:25
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
Example3DSystem4::Example3DSystem4
Example3DSystem4()
Definition: Example3DSystem4.cxx:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Example3DSystem4::ptCutChanged
void ptCutChanged(double)
Definition: Example3DSystem4.cxx:154
TrackCollection.h
Example3DSystem4::buildController
QWidget * buildController()
Definition: Example3DSystem4.cxx:141
Example3DSystem4::buildEventSceneGraph
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Definition: Example3DSystem4.cxx:42
DataVector< Trk::Track >
Example3DSystem4::m_switchToPt
std::map< SoSwitch *, double > m_switchToPt
Definition: Example3DSystem4.h:44
Athena::Units
Definition: Units.h:45
Example3DSystem4::userPickedNode
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
Definition: Example3DSystem4.cxx:116
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.
IVP13DSystemSimple::updateGUI
void updateGUI()
Definition: IVP13DSystemSimple.h:89
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
merge.status
status
Definition: merge.py:17
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
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.