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