ATLAS Offline Software
Loading...
Searching...
No Matches
TrackHandle_TrackContainer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// Implementation of class TrackHandle_TrackContainer //
8// //
9// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
10// Initial version: May 2008 //
11// //
13
15
16#include "Acts/Surfaces/PerigeeSurface.hpp"
17#include "Acts/Surfaces/Surface.hpp"
20#include "CLHEP/Units/SystemOfUnits.h"
21#include "VP1Base/VP1Msg.h"
25#include "AthenaKernel/Units.h"
27#include <typeinfo>
28
29#include <Inventor/nodes/SoSeparator.h>
30#include <Inventor/nodes/SoNode.h>
31
32//____________________________________________________________________
34 TrackCollHandleBase* ch, ActsTrk::TrackContainer::ConstTrackProxy tp,
35 const ActsTrk::TrackContainer& container)
36 : TrackHandleBase(ch), m_track(tp), m_container(container) {}
37
38//____________________________________________________________________
40
41//____________________________________________________________________
43 QStringList l;
44 l << "TrackProxy:";
46 return l;
47}
48
49//____________________________________________________________________
51 const Acts::BoundTrackParameters trackparams(
52 m_track.referenceSurface().getSharedPtr(), m_track.parameters(),
53 std::nullopt, Acts::ParticleHypothesis::pion());
54 return trackparams.momentum()*1000.;
55}
56
57const std::vector<Amg::Vector3D>*
60 auto trackContainerCollHandle =
61 dynamic_cast<const TrackCollHandle_TrackContainer*>(collHandle());
62 auto points = new std::vector<Amg::Vector3D>;
63 if (!trackContainerCollHandle)[[unlikely]]{
64 VP1Msg::messageDebug("TrackHandle_TrackContainer::momentum: bad cast.");
65 return points;
66 }
67 auto ctx = trackContainerCollHandle->common()->geometryContext().context();
68 for (auto trackstate : m_trackStates) {
69 if (trackstate.hasSmoothed() && trackstate.hasReferenceSurface()) {
70 const Acts::BoundTrackParameters params(
71 trackstate.referenceSurface().getSharedPtr(), trackstate.smoothed(),
72 trackstate.smoothedCovariance(), Acts::ParticleHypothesis::pion());
73 points->push_back(params.position(ctx));
74 }
75 }
76
77 return points;
78}
79
80//____________________________________________________________________
84
85//____________________________________________________________________
87
89 QList<QTreeWidgetItem*>& listOfItems) {
90 TrackHandleBase::fillObjectBrowser(listOfItems); // Obligatory!
91
92
93 // Fill sub-data.
94 QList<AssociatedObjectHandleBase*> list = getAllAscObjHandles();
95 unsigned int listSize = list.size();
96
98
99 unsigned int trackStateNum=0;
100 for (const auto trackState : m_trackStates) {
101 QString surfaceText = QString(" ");
102 surfaceText += trackState.hasReferenceSurface()?QString::number(trackState.referenceSurface().type()):"No Surface";
103
104 // VP1Msg::messageVerbose("TrackState #"+QString::number(trackStateNum) + surfaceText);
105
106 bool visible=false;
107 QTreeWidgetItem* TSOSitem = new QTreeWidgetItem(browserTreeItem());
108
109 AscObj_TrackState* asc=nullptr;
110 if (trackStateNum<listSize) asc = dynamic_cast<AscObj_TrackState*>(list.at(trackStateNum));
111
112 if (asc) {
113 asc->setBrowserTreeItem(TSOSitem);
114 visible=asc->visible();
115 }
116
117 if (!visible) {
118 TSOSitem->setFlags(Qt::ItemFlag());// not selectable, not enabled
119 QFont itemFont = TSOSitem->font(0);
120 itemFont.setStrikeOut(true);
121 TSOSitem->setFont(0, itemFont);
122 TSOSitem->setFont(1, itemFont);
123 }
124 std::ostringstream s;
125
126 s << " | Flags: "<< trackState.typeFlags();
127 QString text = QString::number( trackStateNum )+QString(s.str().c_str());
128 TSOSitem->setText(0, QString("Track State "+text ) );
129
130 if (trackState.hasReferenceSurface()) {
131 auto& surface = trackState.referenceSurface();
132 QString surfaceText = QString(surface.toString(common()->geometryContext().context()).c_str());
133 QTreeWidgetItem* surfItem = new QTreeWidgetItem(TSOSitem);
134 surfItem->setExpanded(true);
135 surfItem->setFlags(Qt::ItemIsEnabled);
136 surfItem->setText(0, QString(surface.name().c_str()));
137 surfItem->setText(1, surfaceText );
138 }
139
140 // TSOSitem->setText(1,
141
142 QString trackStateText;
143 // bool first=true;
144
145 // const Trk::MeasurementBase* meas = (*it)->measurementOnTrack();
146 if (trackState.hasCalibrated() ){
147 QString measName = QString(TrkObjToString::typeName(measurementType(trackState)).c_str());
148 trackStateText+=measName;
149
150 QTreeWidgetItem* measItem = new QTreeWidgetItem(TSOSitem);
151 measItem->setExpanded(true); // want it opened so subparams seen easily
152 measItem->setFlags(Qt::ItemIsEnabled);
153 measItem->setText(0, measName);
154 measItem->setText(1, measurementText(trackState) ); //TODO expand this with more info
155
156 // QStringList list = TrkObjToString::fullInfo( *((*it)->measurementOnTrack ()) );
157 // for (int i = 0; i < (list.size()-1); ){
158 // QTreeWidgetItem* subparamItem = new QTreeWidgetItem(measItem);
159 // subparamItem->setText(0, list.at(i++) );
160 // subparamItem->setText(1, list.at(i++) );
161 // subparamItem->setFlags(Qt::ItemIsEnabled);
162 // }
163 }
164 // first=false;
165 // }
166 // if ( (*it)->trackParameters () ) {
167 // if (!first) trackStateText.append(" + ");
168 // trackStateText.append("Parameters");
169
170 // QTreeWidgetItem* paramItem = new QTreeWidgetItem(TSOSitem);
171 // paramItem->setExpanded(true); // want it opened so subparams seen easily
172 // paramItem->setFlags(Qt::ItemIsEnabled);
173 // paramItem->setText(0, TrkObjToString::name( *((*it)->trackParameters ()) ) );
174 // // paramItem->setText(1, TrkObjToString::shortInfo( *((*it)->trackParameters ()) ) );
175
176 // QStringList list = TrkObjToString::fullInfo( *((*it)->trackParameters ()) );
177 // for (int i = 0; i < (list.size()-1); ){
178 // QTreeWidgetItem* subparamItem = new QTreeWidgetItem(paramItem);
179 // subparamItem->setText(0, list.at(i++) );
180 // subparamItem->setText(1, list.at(i++) );
181 // subparamItem->setFlags(Qt::ItemIsEnabled);
182 // }
183 // first=false;
184 // }
185 // if ( (*it)->materialEffectsOnTrack () ){
186 // if (!first) trackStateText.append(" + ");
187 // trackStateText.append("MaterialEffectsOnTrack");
188 // QTreeWidgetItem* meItem = new QTreeWidgetItem(TSOSitem);
189 // meItem->setExpanded(true); // want it opened so subparams seen easily
190 // meItem->setFlags(Qt::ItemIsEnabled);
191
192 // meItem->setText(0, TrkObjToString::name( *((*it)->materialEffectsOnTrack ()) ) );
193 // meItem->setText(1, TrkObjToString::shortInfo( *((*it)->materialEffectsOnTrack ()) ) );
194
195 // first=false;
196 // }
197 // if ( (*it)->fitQualityOnSurface () ){
198 // if (!first) trackStateText.append(" + ");
199 // trackStateText.append("FitQuality");
200 // QTreeWidgetItem* fqItem = new QTreeWidgetItem(TSOSitem);
201 // fqItem->setExpanded(true); // want it opened so subparams seen easily
202 // fqItem->setFlags(Qt::ItemIsEnabled);
203 // fqItem->setText(0, QString("FitQuality") );
204 // fqItem->setText(1, TrkObjToString::shortInfo( (*it)->fitQualityOnSurface () ) );
205
206 // first=false;
207 // }
208 // FIXME - add information about chamber for Muon systems?
209
210 // if ( (*it)->type(Trk::TrackStateOnSurface::Outlier) ){
211 // if (!first) trackStateText.append(" + ");
212 // trackStateText.append("Outlier");
213 // }
214
215 // if ( (*it)->type(Trk::TrackStateOnSurface::InertMaterial) ){
216 // if (!first) trackStateText.append(" + ");
217 // trackStateText.append("InertMaterial");
218 // }
219
220 // if ( (*it)->type(Trk::TrackStateOnSurface::BremPoint) ){
221 // if (!first) trackStateText.append(" + ");
222 // trackStateText.append("BremPoint");
223 // }
224
225 // if ( (*it)->type(Trk::TrackStateOnSurface::Perigee) ){
226 // if (!first) trackStateText.append(" + ");
227 // trackStateText.append("Perigee");
228 // }
229
230 // if ( (*it)->type(Trk::TrackStateOnSurface::Hole) ){
231 // if (!first) trackStateText.append(" + ");
232 // trackStateText.append("Hole");
233 // }
234 TSOSitem->setText(1, trackStateText );
235 trackStateNum++;
236 }
237 // listOfItems << browserTreeItem();
238
239}
240
243 // now find matching AscObj_TSOS
244 auto trackState = m_trackStates.at(index);
245 QList<AssociatedObjectHandleBase*> list = getAllAscObjHandles();
247 "TrackHandle_TrackContainer::zoomToTSOS: checking ASC " +
248 QString::number(index) + " of " + QString::number(list.size()));
249
250 if ( (int)index < list.size()){
251 AscObj_TrackState* asc = dynamic_cast<AscObj_TrackState*>(list.at(index));
252 if (asc && asc->trackState().index()==trackState.index()) {
254 "TrackHandle_TrackContainer::zoomToTSOS: this ASC matches " +
255 QString::number(index));
256 return asc->shapeDetailed();
257 }
258 }
259
260 return nullptr;
261}
262
264 Amg::Vector3D mom = momentum();
265 mom /= CLHEP::GeV;
266
267 // format info string
268 QString l;
269 l += "|Pt|=" + VP1Msg::str(mom.perp()) + " [GeV], ";
270 l += "|P|=" + VP1Msg::str(mom.mag()) + " [GeV], ";
271 return l;
272}
273
275 VP1Msg::messageVerbose("TrackHandle_TrackContainer::updateObjectBrowser");
276
277 if (!browserTreeItem()) {
279 "TrackHandle_TrackContainer::updateObjectBrowser: No m_objBrowseTree!");
280 return;
281 }
282
283 if (!visible()) {
284 browserTreeItem()->setFlags(Qt::ItemFlag()); // not selectable, not enabled
285 } else {
286 browserTreeItem()->setFlags(Qt::ItemIsSelectable |
287 Qt::ItemIsEnabled); // selectable, enabled
288 }
289 QFont font = browserTreeItem()->font(0);
290 font.setStrikeOut(!visible());
291 browserTreeItem()->setFont(0, font);
292 browserTreeItem()->setFont(1, font);
293 // FIXME! Only do if necessary i.e. if something affecting this TSOS has
294 // changed.
295
296 QList<AssociatedObjectHandleBase*> list = getAllAscObjHandles();
297
298 if (list.empty()) {
300 "No ASC objects associated with this track - no track components "
301 "visible yet?");
302 return;
303 }
304
305 unsigned int numOfTS = 0;
306
307 for (auto trackstate : m_trackStates) {
308 // We assume that there is an ASC for every trackstate
309 AscObj_TrackState* asc = dynamic_cast<AscObj_TrackState*>(list.at(numOfTS));
310 if (!asc) {
312 "Could not cast to AscObj_TrackState, or could not find matching Asc "
313 "in list of size " +
314 QString::number(list.size()));
315 numOfTS++;
316 continue;
317 }
318
319 if (asc->trackState().index() != trackstate.index()) {
321 "WARNING! TrackHandle_TrackContainer::updateObjectBrowser: " +
322 QString::number(numOfTS) +
323 ": ASC index mismatch with trackstate from loop having " +
324 QString::number(trackstate.index()) + " and ASC TS having " +
325 QString::number(asc->trackState().index()));
326 numOfTS++;
327 continue;
328 }
329
330 if (!asc->browserTreeItem()) {
331 // not set yet - so need to do this now. Can we just use the index?
332 asc->setBrowserTreeItem(browserTreeItem()->child(numOfTS));
333 }
334
335 if (!asc->browserTreeItem()) {
336 VP1Msg::message("Could not find matching browserTreeItem");
337 numOfTS++;
338 continue;
339 }
340
341 if (!asc->visible()) {
342 asc->browserTreeItem()->setFlags(
343 Qt::ItemFlag()); // not selectable, not enabled
344 } else {
345 asc->browserTreeItem()->setFlags(
346 Qt::ItemIsSelectable | Qt::ItemIsEnabled); // selectable, enabled
347 }
348 QFont itemFont = asc->browserTreeItem()->font(0);
349 itemFont.setStrikeOut(!asc->visible());
350 asc->browserTreeItem()->setFont(0, itemFont);
351 asc->browserTreeItem()->setFont(1, itemFont);
352 numOfTS++;
353 }
354}
355
357 const QString& ) const {
358 return false;
359}
360
362 {
363 // Unfortunately actsTracks are stored in reverse order, so we need to do some
364 // gymnastics (There is certainly a more elegant way to do this, but since
365 // this will all be changed soon I don't think it matters)
366 if (!m_trackStates.empty())
367 return;
368 m_trackStates.reserve(m_track.nTrackStates());
369 for (auto trackstate : m_track.trackStatesReversed()) {
370 m_trackStates.push_back(trackstate);
371 }
372
374}
375
376
378 std::unique_ptr<std::vector<AssociatedObjectHandleBase*>>& ascobjs) {
379 if (ascobjs)
380 return;
382
383 ascobjs = std::make_unique<std::vector<AssociatedObjectHandleBase*>>();
384 unsigned int index =0;
385
386 for (const auto trackState : m_trackStates) {
387 addTrackState(trackState, ascobjs.get(), index++);
388 }
389}
390
392 const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state,
393 std::vector<AssociatedObjectHandleBase*>* ascobjs, unsigned int index) {
394
395 AscObj_TrackState* ao = new AscObj_TrackState(this, index, state);
396
398
399 ascobjs->push_back(ao);
400 if (ao->parts() & shownTSOSParts()){
401 ao->setVisible(true);
402 }
403}
404
406 const ActsTrk::TrackContainer::ConstTrackStateProxy& state) const {
408 if (state.hasReferenceSurface()) {
409 const auto *actsElement = dynamic_cast<const ActsTrk::ISurfacePlacement*>(
410 state.referenceSurface().surfacePlacement());
411 if (actsElement && common()->muonIdHelperSvc().get()) {
412 auto& idhelper = common()->muonIdHelperSvc()->mdtIdHelper(); // This is a lazy way to get an AtlasID helper. Not ideal if muon geometry is off.
413 if (idhelper.is_mdt(actsElement->identify())) {
415 } else if (idhelper.is_tgc(actsElement->identify())) {
417 } else if (idhelper.is_rpc(actsElement->identify())) {
419 } else if (idhelper.is_csc(actsElement->identify())) {
421 } else if (idhelper.is_stgc(actsElement->identify())) {
423 } else if (idhelper.is_mm(actsElement->identify())) {
425 }
426 }
427 return type;
428 }
430}
431
433 const ActsTrk::TrackContainer::ConstTrackStateProxy& state) const {
434 QString text("Unknown Measurement");
435 if (state.hasReferenceSurface()) {
436 const auto* actsElement = getActsDetectorElement(state.referenceSurface());
437 if (actsElement) {
438 auto& helperSvc = common()->muonIdHelperSvc();
439 if (helperSvc->isMuon(actsElement->identify()))
440 text = QString(helperSvc->toString(actsElement->identify()).c_str());
441 }
442 }
443 return text;
444}
const ActsDetectorElement * getActsDetectorElement(const Acts::Surface &surf)
Attempts to retrieve the ActsDetectorElement associated to the passed ActsSurface.
Wrapper to avoid constant divisions when using units.
Acts::GeometryContext context() const
Extension of the interface of the Acts::SurfacePlacementBase for ATLAS.
virtual void setVisible(bool)
virtual QTreeWidgetItem * browserTreeItem() const
virtual TrackCommonFlags::TSOSPartsFlags parts() const
const ActsTrk::TrackStateBackend::ConstTrackStateProxy trackState() const
virtual void setBrowserTreeItem(QTreeWidgetItem *obt)
TrackSysCommonData * common() const
virtual void fillObjectBrowser(QList< QTreeWidgetItem * > &list)
Called in child classes.
virtual void visibleStateChanged()
override if need to take action in this case.
QTreeWidgetItem * browserTreeItem() const
friend class TrackCollHandleBase
TrackHandleBase(TrackCollHandleBase *)
TrackCommonFlags::TSOSPartsFlags shownTSOSParts() const
QStringList baseInfo() const
bool visible() const
TrackCollHandleBase * collHandle() const
TrackSysCommonData * common() const
const QList< AssociatedObjectHandleBase * > & getAllAscObjHandles() const
override if need to take action in this case.
void registerAssocObject(AssociatedObjectHandleBase *)
Trackhandle assumes ownership.
SoNode * zoomToTSOS(unsigned int index)
Depending on controller configuration attempt to zoom to the corresponding TSOS & returned detailed n...
QString measurementText(const ActsTrk::TrackContainer::ConstTrackStateProxy &state) const
virtual const std::vector< Amg::Vector3D > * provide_pathInfoPoints()
virtual void fillObjectBrowser(QList< QTreeWidgetItem * > &list)
Called in child classes.
ActsTrk::TrackContainer::ConstTrackProxy m_track
void ensureInitTrackStateCache()
Ensure that the track state cache is initialized.
std::vector< ActsTrk::TrackContainer::ConstTrackStateProxy > m_trackStates
virtual QString shortInfo() const
returns mom and hit information about track
virtual Amg::Vector3D momentum() const
virtual bool containsDetElement(const QString &) const
TrkObjToString::MeasurementType measurementType(const ActsTrk::TrackStateBackend::ConstTrackStateProxy &state) const
const ActsTrk::TrackContainer & m_container
virtual void ensureInitTSOSs(std::unique_ptr< std::vector< AssociatedObjectHandleBase * > > &ascobjs)
Ensure that the TSOSs are initialized.
virtual QStringList clicked() const
Called when user selects the node (stringlist is displayed in messagebox).
TrackHandle_TrackContainer(TrackCollHandleBase *, ActsTrk::TrackContainer::ConstTrackProxy, const ActsTrk::TrackContainer &)
void addTrackState(const typename ActsTrk::TrackContainer::ConstTrackStateProxy &state, std::vector< AssociatedObjectHandleBase * > *ascobjs, unsigned int index)
virtual QString type() const
return very short word with type (maybe link with collection type?)
void visibleStateChanged()
override if need to take action in this case.
ServiceHandle< Muon::IMuonIdHelperSvc > & muonIdHelperSvc()
const ActsTrk::GeometryContext & geometryContext() const
static std::string typeName(MeasurementType type)
Returns a very short summary of the object type.
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
static QString str(const QString &s)
Definition VP1String.h:49
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
Eigen::Matrix< double, 3, 1 > Vector3D
Definition index.py:1
void reverse(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of reverse for DataVector/List.
#define unlikely(x)