ATLAS Offline Software
Loading...
Searching...
No Matches
AscObj_TrackState.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class AscObj_TrackState //
8// //
10
12
13#include <Inventor/nodes/SoCamera.h>
14#include <Inventor/nodes/SoCylinder.h>
15#include <Inventor/nodes/SoLineSet.h>
16#include <Inventor/nodes/SoMaterial.h>
17#include <Inventor/nodes/SoPointSet.h>
18#include <Inventor/nodes/SoRotationXYZ.h>
19#include <Inventor/nodes/SoSeparator.h>
20#include <Inventor/nodes/SoSphere.h>
21#include <Inventor/nodes/SoTransform.h>
22#include <Inventor/nodes/SoTranslation.h>
23#include <Inventor/nodes/SoVertexProperty.h>
25
26#include <set>
27
28#include "Acts/Surfaces/Surface.hpp"
29#include "Acts/EventData/ParticleHypothesis.hpp"
36#include "VP1Base/VP1Msg.h"
38#include "VP1Base/VP1QtUtils.h"
48#include "VP1Utils/VP1DetInfo.h"
51
52#include "Acts/Surfaces/ConeSurface.hpp"
53#include "Acts/Surfaces/CylinderSurface.hpp"
54#include "Acts/Surfaces/DiscSurface.hpp"
55#include "Acts/Surfaces/PerigeeSurface.hpp"
56#include "Acts/Surfaces/PlaneSurface.hpp"
57#include "Acts/Surfaces/RectangleBounds.hpp"
58#include "Acts/Surfaces/StrawSurface.hpp"
59#include "Acts/Surfaces/SurfaceBounds.hpp"
60
61static double surfaceThickness = 0.1;
62
63//____________________________________________________________________
65 TrackHandleBase* track, unsigned indexOfPointOnTrack,
66 const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy& trackstate)
68 m_parts(TrackCommonFlags::TSOS_NoObjects),
69 m_indexOfPointOnTrack(indexOfPointOnTrack),
71 m_objBrowseTree(nullptr),
72 m_trackstate(trackstate)
73{
75 if (m_trackstate.hasReferenceSurface()) {
76 if (surface().associatedDetectorElement())
78 else
80 }
81
82 if (m_trackstate.typeFlags().test(Acts::TrackStateFlag::ParameterFlag ))
84
85 if (m_trackstate.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)){
87 if (m_trackstate.typeFlags().test(Acts::TrackStateFlag::OutlierFlag ))
89 else
91 }
92
93 if (m_trackstate.typeFlags().test(Acts::TrackStateFlag::HoleFlag))
95
96 if (m_trackstate.typeFlags().test(Acts::TrackStateFlag::MaterialFlag ))
98}
99
100//____________________________________________________________________
102 // We assume this is called right after the constructor - so no need
103 // to update 3D objects.
104 m_distToNextPar = d;
105}
106
107//____________________________________________________________________
109 if (hasSurface())
110 return surface().center( common()->geometryContext().context() );
112 "AscObj_TrackState::approxCenter() WARNING: Failed to determine"
113 " position from either params or surface");
114 return Amg::Vector3D(0, 0, 0);
115}
116
117//____________________________________________________________________
120 static const double l = 30.0 * CLHEP::cm;
121 return static_cast<int>(c.z() / l) + 1000 * static_cast<int>(c.y() / l) +
122 1000000 * static_cast<int>(c.x() / l);
123}
124
125// TODO - add back getZTranslationTube
126
127//____________________________________________________________________
128void AscObj_TrackState::addTrackParamInfoToShapes(SoSeparator*& shape_simple,
129 SoSeparator*& shape_detailed,
130 bool showPars,
131 bool showParsErrors,
132 bool ) {
133 ensureInitSeps(shape_simple, shape_detailed);
134
135 SoSeparator* param_simple = new SoSeparator;
136 SoSeparator* param_detailed = new SoSeparator;
137
138 if (!m_trackstate.hasReferenceSurface()) {
139 // FIXME - do not know how to handle this yet, since I think I need the
140 // surface to get the position
142 "AscObj_TrackState::addTrackParamInfoToShapes() - no reference "
143 "surface");
144 return;
145 }
146
147 const Acts::BoundTrackParameters trackparams(
148 m_trackstate.referenceSurface().getSharedPtr(), m_trackstate.parameters(),
149 m_trackstate.covariance(), Acts::ParticleHypothesis::pion());
150 auto p1 = trackparams.position(common()->geometryContext().context());
151 if (showPars) {
152 auto u = trackparams.direction().unit();
153 double length = 15 * CLHEP::cm;
154 if (m_distToNextPar > 0)
155 length = std::min(m_distToNextPar * 0.75, length);
156 Amg::Vector3D p2 = p1 + length * u;
157 // Line:
158 SoLineSet* line = new SoLineSet();
159 SoVertexProperty* vertices = new SoVertexProperty();
160 vertices->vertex.set1Value(0, p1.x(), p1.y(), p1.z());
161 vertices->vertex.set1Value(1, p2.x(), p2.y(), p2.z());
162 line->numVertices.set1Value(0, 2);
163
164 // Point:
165 SoPointSet* points = new SoPointSet;
166 SoVertexProperty* vertices2 = new SoVertexProperty;
167 vertices2->vertex.set1Value(0, p1.x(), p1.y(), p1.z());
168 points->numPoints = 1;
169 line->vertexProperty = vertices;
170 points->vertexProperty = vertices2;
171 bool isHole = m_parts & TrackCommonFlags::TSOS_Hole;
172
173 if (trackHandle()->customColouredTSOSParts() &
175 (isHole && (trackHandle()->customColouredTSOSParts() &
177 SoMaterial* mat = isHole
180 SoSeparator* sep = new SoSeparator;
181 sep->addChild(mat);
182 sep->addChild(line);
183 sep->addChild(points);
184 param_simple->addChild(sep);
185 param_detailed->addChild(sep);
186 } else {
187 param_simple->addChild(line);
188 param_simple->addChild(points);
189 param_detailed->addChild(line);
190 param_detailed->addChild(points);
191 }
192 if (showParsErrors) {
193 // TODO
194 }
195 shape_simple->addChild(param_simple);
196 shape_detailed->addChild(param_detailed);
197 }
198}
199
200//____________________________________________________________________
201void AscObj_TrackState::addSurfaceToShapes(SoSeparator*& shape_simple,
202 SoSeparator*& shape_detailed) {
203 // VP1Msg::messageVerbose("\tAscObj_TrackState::addSurfaceToShapes() start. Type="+QString::number(surface().type())+" Bounds="+QString::number(surface().bounds().type()));
204 // Check if the TrackStateProxy has a surface
205
206 if (!m_trackstate.hasReferenceSurface())
207 return;
208
209 const Acts::Surface& surface = m_trackstate.referenceSurface();
210 if (surface.type()==Acts::Surface::SurfaceType::Straw && common()->controller()->hideTubeSurfaces())
211 return;
212
213 SoTransform* sotra = VP1LinAlgUtils::toSoTransform(surface.transform(common()->geometryContext().context()));
214 shape_detailed->addChild(sotra);
215
216 //
217 // enum SurfaceType {
218 // Cone = 0,
219 // Cylinder = 1,
220 // Disc = 2,
221 // Perigee = 3,
222 // Plane = 4,
223 // Straw = 5,
224 // Curvilinear = 6,
225 // Other = 7
226 // };
227
228 // enum BoundsType : int {
229 // eCone = 0,
230 // eCylinder = 1,
231 // eDiamond = 2,
232 // eDisc = 3,
233 // eEllipse = 4,
234 // eLine = 5,
235 // eRectangle = 6,
236 // eTrapezoid = 7,
237 // eTriangle = 8,
238 // eDiscTrapezoid = 9,
239 // eConvexPolygon = 10,
240 // eAnnulus = 11,
241 // eBoundless = 12,
242 // eOther = 13
243 // };
244
245
246
247 switch (surface.type()) {
248 case Acts::Surface::SurfaceType::Plane: {
249 addPlaneSurfaceToShapes(shape_simple, shape_detailed, surface);
250 break;
251 }
252 case Acts::Surface::SurfaceType::Straw: {
253 addCylindricalSurfaceToShapes(shape_simple, shape_detailed, surface);
254 break;
255 }
256 default:
257 VP1Msg::messageVerbose("Cannot currently handle surface of type" + QString::number(surface.type()));
258 break;
259 }
260 VP1Msg::messageVerbose("AscObj_TrackState::addSurfaceToShapes() end");
261}
262
264 SoNode*& shape_detailed) {
265 if (trackHandle()->customColouredTSOSParts()&TrackCommonFlags::TSOS_AnySurface) {
266 SoMaterial * mat = common()->controller()->customMatSurfaces();
267 if (shape_detailed->getTypeId().isDerivedFrom(SoSeparator::getClassTypeId())) {
268 // static_cast<SoSeparator*>(theSurfSepSimple)->insertChild(mat,0); TODO
269 static_cast<SoSeparator*>(shape_detailed)->insertChild(mat,0);
270 } else {
271
272 // SoSeparator * sepSimple = new SoSeparator;
273 // sepSimple->addChild(mat);
274 // sepSimple->addChild(theSurfSepSimple);
275 // nodeToAddSimple = sepSimple;
276 // TODO ^
277 SoSeparator * sep = new SoSeparator;
278 sep->addChild(mat);
279 sep->addChild(shape_detailed);
280 shape_detailed = sep;
281 }
282 }
283}
284
285void AscObj_TrackState::addPlaneSurfaceToShapes(SoSeparator*& shape_simple,
286 SoSeparator*& shape_detailed,
287 const Acts::Surface& surface) {
288
289 SoNode * nodeToAddSimple = nullptr;
290 SoNode * nodeToAddDetailed = nullptr;
291
292 // Check bounds
293 switch (surface.bounds().type()) {
294 case Acts::SurfaceBounds::BoundsType::eBoundless: {
295 const double halfX = 100.0; // FIXME - make this configurable?
296 const double halfY = 100.0;
297 SoGenericBox* box = new SoGenericBox;
298 box->setParametersForBox(halfX, halfY,
299 0.5 * surfaceThickness);
300 box->drawEdgeLines.setValue(true);
301 nodeToAddDetailed = box;
302 break;
303 }
304 case Acts::SurfaceBounds::BoundsType::eRectangle: {
305
306 const Acts::RectangleBounds& rectBounds =
307 dynamic_cast<const Acts::RectangleBounds&>(surface.bounds());
308 const double halfX = rectBounds.halfLengthX();
309 const double halfY = rectBounds.halfLengthY();
310 SoGenericBox* box = new SoGenericBox;
311 box->setParametersForBox(halfX, halfY,
312 0.5 * surfaceThickness);
313 box->drawEdgeLines.setValue(true);
314 nodeToAddDetailed = box;
315 // TODO simple
316 break;
317 }
318 default: {
319 VP1Msg::messageVerbose("Cannot currently handle surface bound of type" + QString::number(surface.bounds().type()));
320 break;
321 }
322 }
323
324 if (nodeToAddDetailed!=nullptr){
325 addMaterialToSurfaceShapes(nodeToAddSimple, nodeToAddDetailed);
326 shape_simple->addChild(nodeToAddDetailed); // FIXME
327 shape_detailed->addChild(nodeToAddDetailed);
328 }
329}
330
332 SoSeparator*& shape_detailed,
333 const Acts::Surface& surface) {
334 SoNode * nodeToAddSimple = nullptr;
335 SoNode * nodeToAddDetailed = nullptr;
336 // Check bounds
337 switch (surface.bounds().type()) {
338 case Acts::SurfaceBounds::BoundsType::eLine: {
339 const Acts::LineBounds& lineBounds =
340 dynamic_cast<const Acts::LineBounds&>(surface.bounds());
341 double hlength = lineBounds.get(Acts::LineBounds::eHalfLengthZ);
342
343 SoVertexProperty * scatVtxProperty = new SoVertexProperty();
344 scatVtxProperty->vertex.set1Value(0, 0.0,0.0,-hlength);
345 scatVtxProperty->vertex.set1Value(1, 0.0,0.0, hlength);
346 SoLineSet * lineSurface = new SoLineSet();
347 lineSurface->numVertices = 2;
348 lineSurface->vertexProperty = scatVtxProperty;
349
350 nodeToAddSimple = lineSurface;
351
352 double radius = lineBounds.get(Acts::LineBounds::eR);
353
354 SoTubs* lineSurfaceDetailed = new SoTubs();
355 (*lineSurfaceDetailed).pRMin = 0.;
356 (*lineSurfaceDetailed).pRMax = radius;
357 (*lineSurfaceDetailed).pDz = hlength;
358
359 nodeToAddDetailed = lineSurfaceDetailed;
360 break;
361 }
362 default: {
363 VP1Msg::messageVerbose("AscObj_TrackState::addCylindricalSurfaceToShapes(): Unsupported bounds type.");
364 break;
365 }
366 }
367 if (nodeToAddDetailed!=nullptr){
368 addMaterialToSurfaceShapes(nodeToAddSimple, nodeToAddDetailed);
369 shape_simple->addChild(nodeToAddDetailed);
370 shape_detailed->addChild(nodeToAddDetailed);
371 }
372}
373
374//____________________________________________________________________
376 SoSeparator*& , SoSeparator*& ) {}
377
378void AscObj_TrackState::addMeasurementToShapes(SoSeparator*& shape_simple,
379 SoSeparator*& shape_detailed) {
380
381 auto flag = m_trackstate.typeFlags();
382
383 // Check if the TrackStateProxy has a measurement
384 if (!m_trackstate.hasReferenceSurface() ||
385 !flag.test(Acts::TrackStateFlag::MeasurementFlag ||
386 !(m_trackstate.hasUncalibratedSourceLink())))
387 return;
388
389 ensureInitSeps(shape_simple, shape_detailed);
390 TrackCommonFlags::TSOSPartsFlags f(trackHandle()->shownTSOSParts() & m_parts);
391 const bool showMeas(f & TrackCommonFlags::TSOS_AnyMeasurement);
392 // const bool showMeasErrors(f & TrackCommonFlags::TSOS_MeasError);
393 if (showMeas) {
394 if (m_parts & trackHandle()->customColouredTSOSParts() &
396 SoMaterial* mat;
397 if (m_parts & trackHandle()->customColouredTSOSParts() &
400 else
402 shape_simple->addChild(mat);
403 shape_detailed->addChild(mat);
404 }
405
406 // Handle measurements
407 auto sl = m_trackstate.getUncalibratedSourceLink()
409 assert(sl != nullptr);
410 const xAOD::UncalibratedMeasurement& uncalibMeas =
412
413 const xAOD::UncalibMeasType measurementType = uncalibMeas.type();
414
415 switch (measurementType) {
417 // Drift tubes
418 break;
419 }
426 // TODO
427 break;
428 }
430 // TODO
431 break;
432 }
434 default: {
436 "AscObj_TrackState::addMeasurementToShapes: Unable to handle this "
437 "measurement type ");
438 break;
439 }
440 }
441 }
442}
443
444//____________________________________________________________________
445void AscObj_TrackState::ensureInitSeps(SoSeparator*& shape_simple,
446 SoSeparator*& shape_detailed) {
447 if (!shape_simple)
448 shape_simple = new SoSeparator;
449 if (!shape_detailed)
450 shape_detailed = new SoSeparator;
451}
452
453//____________________________________________________________________
454void AscObj_TrackState::buildShapes(SoSeparator*& shape_simple,
455 SoSeparator*& shape_detailed) {
456 VP1Msg::messageVerbose("AscObj_TrackState::buildShapes() start");
457
458 TrackCommonFlags::TSOSPartsFlags f(trackHandle()->shownTSOSParts()&m_parts);
460 VP1Msg::messageVerbose("AscObj_TrackState::buildShapes() - no objects to show with shownTSOSParts="+QString::number(trackHandle()->shownTSOSParts())+" and m_parts="+QString::number(m_parts));
461 return;
462 }
463 // TODO Implement the following
464 const bool showPars(f & TrackCommonFlags::TSOS_TrackPars);
465 // const bool showParsErrors(f & TrackCommonFlags::TSOS_AnyParsErrors);
466 // const bool showMeas(f & TrackCommonFlags::TSOS_AnyMeasRioOnTrack);
467 // const bool showCompetingRioOnTrack(f & TrackCommonFlags::TSOS_AnyMeasCompetingRioOnTrack);
468 const bool showSurfaces(f & TrackCommonFlags::TSOS_AnySurface);
469 // const bool showMaterialEffects(f & TrackCommonFlags::TSOS_AnyMaterialEffects);
470 // const bool showMeasErrors(f & TrackCommonFlags::TSOS_MeasError);
471 ensureInitSeps(shape_simple,shape_detailed);
472
473 if (showPars)
474 addTrackParamInfoToShapes( shape_simple, shape_detailed, showPars, false, false);
475
476 if (showSurfaces)
477 addSurfaceToShapes( shape_simple, shape_detailed);
478
479 // addMeasurementToShapes is crashing at the moment. Need to investigate
480 // if (showMeas)
481 // addMeasurementToShapes( shape_simple, shape_detailed);
482
483 VP1Msg::messageVerbose("AscObj_TrackState::buildShapes() end");
484
485}
486
487//____________________________________________________________________
489 QStringList l;
490 return l;
491}
492
496
498 VP1Msg::messageVerbose("AscObj_TrackState::zoomView()");
499 if ( common()->controller()->orientAndZoomOnSingleSelection() )
500 {
501 // Zoom without orientation
502 // TODO - add orientation?
503 VP1Msg::messageVerbose("AscObj_TrackState::zoomView() Zoom without orientation");
504 std::set<SoCamera*> cameras = common()->system()->getCameraList();
505 std::set<SoCamera*>::iterator it,itE = cameras.end();
506 for (it=cameras.begin();it!=itE;++it) {
507 if (common()->controller()->assocObjDetailLevel()==TrackCommonFlags::SIMPLE)
508 {
509 VP1CameraHelper::animatedZoomToSubTree(*it,common()->ascObjSelectionManager()->getAscObjAttachSep(),shapeSimple(),2.0,1.0);
510 } else
511 {
512 VP1CameraHelper::animatedZoomToSubTree(*it,common()->ascObjSelectionManager()->getAscObjAttachSep(),shapeDetailed(),2.0,1.0);
513 }
514 }
515 } else {
516 VP1Msg::messageVerbose("AscObj_TrackState::zoomView() - zooming on selection not turned on.");
517 }
518}
519
static double surfaceThickness
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
double length(const pvec &v)
void addPlaneSurfaceToShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed, const Acts::Surface &surface)
const ActsTrk::TrackStateBackend::ConstTrackStateProxy m_trackstate
void addCylindricalSurfaceToShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed, const Acts::Surface &surface)
virtual void setVisible(bool)
static void ensureInitSeps(SoSeparator *&shape_simple, SoSeparator *&shape_detailed)
void zoomView()
Depending on the controller settings, will attempt to zoom the view to this TSOS, for example in clic...
const Acts::Surface & surface() const
void setDistToNextPar(const double &)
QTreeWidgetItem * m_objBrowseTree
void buildShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed)
void addSurfaceToShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed)
Amg::Vector3D approxCenter() const
void addTrackParamInfoToShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed, bool showPars, bool showParsErrors, bool showSurfaces)
void addMaterialEffectsToShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed)
void addMaterialToSurfaceShapes(SoNode *&shape_simple, SoNode *&shape_detailed)
void addMeasurementToShapes(SoSeparator *&shape_simple, SoSeparator *&shape_detailed)
AscObj_TrackState(TrackHandleBase *, unsigned indexOfPointOnTrack, const typename ActsTrk::TrackStateBackend::ConstTrackStateProxy &state)
TrackCommonFlags::TSOSPartsFlags m_parts
TrackSysCommonData * common() const
TrackHandleBase * trackHandle() const
CamList getCameraList()
void setParametersForBox(float dx, float dy, float dz, float xcenter=0.0, float ycenter=0.0, float zcenter=0.0)
SoSFBool drawEdgeLines
static void initClass()
SoTubs - Inventor version of the G4Tubs Geant Geometry entity.
Definition SoTubs.h:52
@ TSOS_MeasRioOnTrackOutlier
bit 6
@ TSOS_MeasRioOnTrackNotOutlier
bit 4
VP1TrackSystem * system() const
TrackSystemController * controller() const
SoMaterial * customMatParameters() const
SoMaterial * customMatHoleParameters() const
SoMaterial * customMatMeasurementsOutliers() const
SoMaterial * customMatSurfaces() const
SoMaterial * customMatMeasurements() const
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)
static SoTransform * toSoTransform(const HepGeom::Transform3D &, SoTransform *t=0)
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
const xAOD::UncalibratedMeasurement & getUncalibratedMeasurement(const ATLASUncalibSourceLink &source_link)
const xAOD::UncalibratedMeasurement * ATLASUncalibSourceLink
Eigen::Matrix< double, 3, 1 > Vector3D
UncalibMeasType
Define the type of the uncalibrated measurement.
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.