ATLAS Offline Software
TrackingSurfacesSystem.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-20235 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class TrackingSurfacesSystem //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: June 2007 //
12 // //
14 
16 #include "ui_trackingsurfacescontrollerform.h"
17 
18 #include "StoreGate/StoreGateSvc.h"
19 #include "TrkSurfaces/Surface.h"
22 #include "GaudiKernel/SystemOfUnits.h"
23 
24 #include <Inventor/nodes/SoSeparator.h>
25 #include <Inventor/nodes/SoLineSet.h>
26 #include <Inventor/nodes/SoVertexProperty.h>
27 #include <Inventor/nodes/SoSwitch.h>
28 #include <Inventor/nodes/SoMaterial.h>
29 
33 
34 //_____________________________________________________________________________________
36  : IVP13DSystemSimple("TrackingSurfacesSystem","This is an illustration of a very basic 3D system.","edward.moyse@gmail.com"), m_multiselection(0)
37 {
38 }
39 
40 //_____________________________________________________________________________________
42 {
43  //Clear maps:
44  m_nodeToSurface.clear();
45  // std::cout<<&m_surfConvertor<<std::endl;
46  //1) Try to get the collection of (InDet) tracks from storegate:
47 
48  //Sanity check:
49  if (!sg) {
50  message("Error: Got null storegate pointer");
51  return;
52  }
53 
54 
55  // SurfaceCollection* testsrfcol;
56  // StatusCode sc2 = evtStore()->retrieve(testsrfcol,"SurfaceCollection");
57  // if ( sc2.isFailure() )
58  // ATH_MSG_ERROR("Could not retrieve SurfaceCollection in StoreGate");
59  // else
60  // ATH_MSG_INFO("SurfaceCollection with " << testsrfcol->size() << " elements successfully retrieved in StoreGate");
61  //
62 
63  const SurfaceCollection *surfColl;
64  std::string surfname="SurfaceCollection";
65  StatusCode status = sg->retrieve(surfColl, surfname);
66  if (status != StatusCode::SUCCESS || !surfColl) {
67  message("Error: Could not retrieve SurfaceCollection (used key="+QString(surfname.c_str())+")");
68  return;
69  }
70  message( "Loaded SurfaceCollection with key [" +QString(surfname.c_str())+"] and which contains [" + QString::number(surfColl->size()) + "] surfaces.");
71  //2) Add SoCooperativeSelection node under which we will put all the
72  //tracks. Register it and put its policy to TOGGLE (i.e. clicking
73  //adds or removes tracks from selection). In updateSelectionMode we
74  //will update its ACTIVE/INERT status depending on whether multiple
75  //selections are enabled: If ACTIVE, we get lists of selected nodes
76  //in the userChangedSelection(...) method, otherwise we get single
77  //nodes in the userPickedNode(...) method as always. We could also
78  //simply have changed its policy and gotten information about the
79  //clicks in a userSelectedSingleNode(...) method instead (the
80  //reason for the two available ways of doing this is that you might
81  //want to have several different selection nodes in your graph in
82  //the case where you have different types of physics objects
83  //displayed from the same system):
85  m_multiselection->policy = SoCooperativeSelection::TOGGLE;
86  registerSelectionNode(m_multiselection);//Always do this for SoCooperativeSelection nodes in your graph.
87  updateSelectionMode( true );//Since our controller starts with the single mode selected, we init like that also.
88 
89  //2) Loop over the tracks and construct a relevant 3D object for each of them (a SoLineSet):
90 
91  SurfaceCollection::const_iterator surfItr, surfItrEnd = surfColl->end();
92  SurfaceToSoNode surfCnv;
93  for ( surfItr = surfColl->begin() ; surfItr != surfItrEnd; ++surfItr) {
94  const Trk::Surface* surf = (*surfItr);
95 
96  SoNode* node = surfCnv.translateSurface(*surf, false);
97  SoMaterial *material = new SoMaterial;
98  if(surf->isActive()){
99  material->diffuseColor.setValue(0.6, 0., 0.6);
100  } else {
101  material->diffuseColor.setValue(1., 0., 1.);
102  }
103 
104  m_multiselection->addChild(material);
105  m_multiselection->addChild(node);
106 
107  //Bookkeep which track this 3D object corresponds to (we will need this to display surface info when the user clicks):
108  m_nodeToSurface[node] = surf;
109 
110  //To avoid GUI freeze-ups:
111  updateGUI();
112  }
113 
114  //Add the selection node under the root:
115  root->addChild(m_multiselection);
116 
117 
118 }
119 
120 //_____________________________________________________________________________________
121 void TrackingSurfacesSystem::userPickedNode(SoNode* pickedNode, SoPath * /*pickedPath*/) {
122 
123  //User clicked on "pickedNode". We should know which track this belongs to:
124 
125  messageDebug("TrackingSurfacesSystem::userPickedNode - have been passed node ["+QString("0x%1").arg((quintptr)pickedNode,
126  QT_POINTER_SIZE * 2, 16, QChar('0'))+"] and have ["+QString::number(m_nodeToSurface.size())+"] nodes.");
127 
128  if (m_nodeToSurface.find(pickedNode)==m_nodeToSurface.end()) {
129  message("Error: Do not have surface information for picked node");
130  return;
131  }
132  const Trk::Surface * matchedSurface=m_nodeToSurface.find(pickedNode)->second;
133 
134  //Show some interesting information (from the first surface):
135  message("===> Surface info:");
136  QStringList l;
137  std::ostringstream s;
138  s << *(matchedSurface);
139  l << QString(s.str().c_str()).split('\n');
140  message(l);
141 
142  //Zoom to surf:
143  CamList cameras = getCameraList();
144  for (CamListItr itCam = cameras.begin(); itCam!=cameras.end(); ++itCam) {
145  VP1CameraHelper::animatedZoomToSubTree(*itCam,m_multiselection,pickedNode,2.0,1.0);
146  }
147 }
148 
149 //_____________________________________________________________________________________
150 void TrackingSurfacesSystem::userChangedSelection(SoCooperativeSelection*, const QSet<SoNode*> & nodes, QSet<SoPath*>)
151 {
152  for (SoNode * node : nodes) {
153  //Surface pointer:
154  if (m_nodeToSurface.find(node)==m_nodeToSurface.end()) {
155  message("Error: Does not have surface information for all nodes");
156  return;
157  }
158  }
159 }
160 
161 //_____________________________________________________________________________________
163 {
164  QWidget * controller = new QWidget(0);
165  Ui::TrackingSurfacesControllerForm ui;
166  ui.setupUi(controller);
167 
168  connect(ui.radioButton_select_single,SIGNAL(toggled(bool)),this,SLOT(updateSelectionMode(bool)));
169 
170  return controller;
171 }
172 
173 //_____________________________________________________________________________________
175 {
176  //If multiselection not created or if we dont need to change anything - abort:
178  return;
179 
180  //When we change selection mode we deselect everything - always a good idea to avoid hard to debug problems later:
181  deselectAll();
182 
183  if (single)
185  else
187 
188 }
SoCooperativeSelection::INERT
@ INERT
Definition: SoCooperativeSelection.h:41
TrackingSurfacesSystem::buildEventSceneGraph
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Definition: TrackingSurfacesSystem.cxx:41
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
IVP13DSystemSimple
Definition: IVP13DSystemSimple.h:24
Surface.h
VP1CameraHelper.h
SurfaceToSoNode
Definition: SurfaceToSoNode.h:30
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
SoCooperativeSelection::activePolicy
SoSFEnum activePolicy
Definition: SoCooperativeSelection.h:49
SurfaceCollection.h
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
GeoPrimitives.h
IVP13DSystem::registerSelectionNode
void registerSelectionNode(SoCooperativeSelection *)
Definition: IVP13DSystem.cxx:257
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
TrackingSurfacesSystem::m_nodeToSurface
std::map< SoNode *, const Trk::Surface * > m_nodeToSurface
Definition: TrackingSurfacesSystem.h:35
IVP13DSystem::CamList
std::set< SoCamera * > CamList
Definition: IVP13DSystem.h:90
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrackingSurfacesSystem::userPickedNode
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
Definition: TrackingSurfacesSystem.cxx:121
IVP13DSystem::CamListItr
CamList::iterator CamListItr
Definition: IVP13DSystem.h:91
TrackingSurfacesSystem::TrackingSurfacesSystem
TrackingSurfacesSystem()
Definition: TrackingSurfacesSystem.cxx:35
SurfaceToSoNode::translateSurface
SoNode * translateSurface(const Trk::Surface &sf, const bool &simple=false) const
Definition: SurfaceToSoNode.cxx:57
PyPoolBrowser.node
node
Definition: PyPoolBrowser.py:131
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
SoCooperativeSelection::ACTIVE
@ ACTIVE
Definition: SoCooperativeSelection.h:41
SoCooperativeSelection.h
IVP1System::messageDebug
void messageDebug(const QString &) const
Definition: IVP1System.cxx:347
python.selection.number
number
Definition: selection.py:20
TrackingSurfacesSystem::m_multiselection
SoCooperativeSelection * m_multiselection
Definition: TrackingSurfacesSystem.h:36
Trk::Surface::isActive
bool isActive() const
Return 'true' if this surface is owned by the detector element.
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
IVP13DSystem::getCameraList
CamList getCameraList()
Definition: IVP13DSystem.cxx:395
TrackingSurfacesSystem::userChangedSelection
void userChangedSelection(SoCooperativeSelection *, const QSet< SoNode * > &, QSet< SoPath * >)
Definition: TrackingSurfacesSystem.cxx:150
merge.status
status
Definition: merge.py:17
SurfaceToSoNode.h
TrackingSurfacesSystem.h
TrackingSurfacesSystem::buildController
QWidget * buildController()
Definition: TrackingSurfacesSystem.cxx:162
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
VP1CameraHelper::animatedZoomToSubTree
static VP1CameraHelper * animatedZoomToSubTree(SoCamera *camera, SoGroup *sceneroot, SoNode *subtreeroot, double duration_in_secs=1.0, double clipVolPercent=100.0, double lastClipVolPercent=100.0, double slack=1.0, const SbVec3f &lookat=SbVec3f(999, 999, 999), const SbVec3f &upvec=SbVec3f(999, 999, 999), bool varySpeed=true, bool forceCircular=false)
Definition: VP1CameraHelper.cxx:413
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
IVP1System::message
void message(const QString &) const
Definition: IVP1System.cxx:336
IVP13DSystem::deselectAll
virtual void deselectAll(SoCooperativeSelection *exception_sel=0)
Definition: IVP13DSystem.cxx:331
node
Definition: node.h:21
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TrackingSurfacesSystem::updateSelectionMode
void updateSelectionMode(bool single)
Definition: TrackingSurfacesSystem.cxx:174
SoCooperativeSelection
Definition: SoCooperativeSelection.h:29