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
64 auto ctx = trackContainerCollHandle->common()->geometryContext().context();
65 for (auto trackstate : m_trackStates) {
66 if (trackstate.hasSmoothed() && trackstate.hasReferenceSurface()) {
67 const Acts::BoundTrackParameters params(
68 trackstate.referenceSurface().getSharedPtr(), trackstate.smoothed(),
69 trackstate.smoothedCovariance(), Acts::ParticleHypothesis::pion());
70 points->push_back(params.position(ctx));
71 }
72 }
73
74 return points;
75}
76
77//____________________________________________________________________
81
82//____________________________________________________________________
84
86 QList<QTreeWidgetItem*>& listOfItems) {
87 TrackHandleBase::fillObjectBrowser(listOfItems); // Obligatory!
88
89
90 // Fill sub-data.
91 QList<AssociatedObjectHandleBase*> list = getAllAscObjHandles();
92 unsigned int listSize = list.size();
93
95
96 unsigned int trackStateNum=0;
97 for (const auto trackState : m_trackStates) {
98 QString surfaceText = QString(" ");
99 surfaceText += trackState.hasReferenceSurface()?QString::number(trackState.referenceSurface().type()):"No Surface";
100
101 // VP1Msg::messageVerbose("TrackState #"+QString::number(trackStateNum) + surfaceText);
102
103 bool visible=false;
104 QTreeWidgetItem* TSOSitem = new QTreeWidgetItem(browserTreeItem());
105
106 AscObj_TrackState* asc=nullptr;
107 if (trackStateNum<listSize) asc = dynamic_cast<AscObj_TrackState*>(list.at(trackStateNum));
108
109 if (asc) {
110 asc->setBrowserTreeItem(TSOSitem);
111 visible=asc->visible();
112 }
113
114 if (!visible) {
115 TSOSitem->setFlags(Qt::ItemFlag());// not selectable, not enabled
116 QFont itemFont = TSOSitem->font(0);
117 itemFont.setStrikeOut(true);
118 TSOSitem->setFont(0, itemFont);
119 TSOSitem->setFont(1, itemFont);
120 }
121 std::ostringstream s;
122
123 s << " | Flags: "<< trackState.typeFlags();
124 QString text = QString::number( trackStateNum )+QString(s.str().c_str());
125 TSOSitem->setText(0, QString("Track State "+text ) );
126
127 if (trackState.hasReferenceSurface()) {
128 auto& surface = trackState.referenceSurface();
129 QString surfaceText = QString(surface.toString(common()->geometryContext().context()).c_str());
130 QTreeWidgetItem* surfItem = new QTreeWidgetItem(TSOSitem);
131 surfItem->setExpanded(true);
132 surfItem->setFlags(Qt::ItemIsEnabled);
133 surfItem->setText(0, QString(surface.name().c_str()));
134 surfItem->setText(1, surfaceText );
135 }
136
137 // TSOSitem->setText(1,
138
139 QString trackStateText;
140 // bool first=true;
141
142 // const Trk::MeasurementBase* meas = (*it)->measurementOnTrack();
143 if (trackState.hasCalibrated() ){
144 QString measName = QString(TrkObjToString::typeName(measurementType(trackState)).c_str());
145 trackStateText+=measName;
146
147 QTreeWidgetItem* measItem = new QTreeWidgetItem(TSOSitem);
148 measItem->setExpanded(true); // want it opened so subparams seen easily
149 measItem->setFlags(Qt::ItemIsEnabled);
150 measItem->setText(0, measName);
151 measItem->setText(1, measurementText(trackState) ); //TODO expand this with more info
152
153 // QStringList list = TrkObjToString::fullInfo( *((*it)->measurementOnTrack ()) );
154 // for (int i = 0; i < (list.size()-1); ){
155 // QTreeWidgetItem* subparamItem = new QTreeWidgetItem(measItem);
156 // subparamItem->setText(0, list.at(i++) );
157 // subparamItem->setText(1, list.at(i++) );
158 // subparamItem->setFlags(Qt::ItemIsEnabled);
159 // }
160 }
161 // first=false;
162 // }
163 // if ( (*it)->trackParameters () ) {
164 // if (!first) trackStateText.append(" + ");
165 // trackStateText.append("Parameters");
166
167 // QTreeWidgetItem* paramItem = new QTreeWidgetItem(TSOSitem);
168 // paramItem->setExpanded(true); // want it opened so subparams seen easily
169 // paramItem->setFlags(Qt::ItemIsEnabled);
170 // paramItem->setText(0, TrkObjToString::name( *((*it)->trackParameters ()) ) );
171 // // paramItem->setText(1, TrkObjToString::shortInfo( *((*it)->trackParameters ()) ) );
172
173 // QStringList list = TrkObjToString::fullInfo( *((*it)->trackParameters ()) );
174 // for (int i = 0; i < (list.size()-1); ){
175 // QTreeWidgetItem* subparamItem = new QTreeWidgetItem(paramItem);
176 // subparamItem->setText(0, list.at(i++) );
177 // subparamItem->setText(1, list.at(i++) );
178 // subparamItem->setFlags(Qt::ItemIsEnabled);
179 // }
180 // first=false;
181 // }
182 // if ( (*it)->materialEffectsOnTrack () ){
183 // if (!first) trackStateText.append(" + ");
184 // trackStateText.append("MaterialEffectsOnTrack");
185 // QTreeWidgetItem* meItem = new QTreeWidgetItem(TSOSitem);
186 // meItem->setExpanded(true); // want it opened so subparams seen easily
187 // meItem->setFlags(Qt::ItemIsEnabled);
188
189 // meItem->setText(0, TrkObjToString::name( *((*it)->materialEffectsOnTrack ()) ) );
190 // meItem->setText(1, TrkObjToString::shortInfo( *((*it)->materialEffectsOnTrack ()) ) );
191
192 // first=false;
193 // }
194 // if ( (*it)->fitQualityOnSurface () ){
195 // if (!first) trackStateText.append(" + ");
196 // trackStateText.append("FitQuality");
197 // QTreeWidgetItem* fqItem = new QTreeWidgetItem(TSOSitem);
198 // fqItem->setExpanded(true); // want it opened so subparams seen easily
199 // fqItem->setFlags(Qt::ItemIsEnabled);
200 // fqItem->setText(0, QString("FitQuality") );
201 // fqItem->setText(1, TrkObjToString::shortInfo( (*it)->fitQualityOnSurface () ) );
202
203 // first=false;
204 // }
205 // FIXME - add information about chamber for Muon systems?
206
207 // if ( (*it)->type(Trk::TrackStateOnSurface::Outlier) ){
208 // if (!first) trackStateText.append(" + ");
209 // trackStateText.append("Outlier");
210 // }
211
212 // if ( (*it)->type(Trk::TrackStateOnSurface::InertMaterial) ){
213 // if (!first) trackStateText.append(" + ");
214 // trackStateText.append("InertMaterial");
215 // }
216
217 // if ( (*it)->type(Trk::TrackStateOnSurface::BremPoint) ){
218 // if (!first) trackStateText.append(" + ");
219 // trackStateText.append("BremPoint");
220 // }
221
222 // if ( (*it)->type(Trk::TrackStateOnSurface::Perigee) ){
223 // if (!first) trackStateText.append(" + ");
224 // trackStateText.append("Perigee");
225 // }
226
227 // if ( (*it)->type(Trk::TrackStateOnSurface::Hole) ){
228 // if (!first) trackStateText.append(" + ");
229 // trackStateText.append("Hole");
230 // }
231 TSOSitem->setText(1, trackStateText );
232 trackStateNum++;
233 }
234 // listOfItems << browserTreeItem();
235
236}
237
240 // now find matching AscObj_TSOS
241 auto trackState = m_trackStates.at(index);
242 QList<AssociatedObjectHandleBase*> list = getAllAscObjHandles();
244 "TrackHandle_TrackContainer::zoomToTSOS: checking ASC " +
245 QString::number(index) + " of " + QString::number(list.size()));
246
247 if ( (int)index < list.size()){
248 AscObj_TrackState* asc = dynamic_cast<AscObj_TrackState*>(list.at(index));
249 if (asc && asc->trackState().index()==trackState.index()) {
251 "TrackHandle_TrackContainer::zoomToTSOS: this ASC matches " +
252 QString::number(index));
253 return asc->shapeDetailed();
254 }
255 }
256
257 return nullptr;
258}
259
261 Amg::Vector3D mom = momentum();
262 mom /= CLHEP::GeV;
263
264 // format info string
265 QString l;
266 l += "|Pt|=" + VP1Msg::str(mom.perp()) + " [GeV], ";
267 l += "|P|=" + VP1Msg::str(mom.mag()) + " [GeV], ";
268 return l;
269}
270
272 VP1Msg::messageVerbose("TrackHandle_TrackContainer::updateObjectBrowser");
273
274 if (!browserTreeItem()) {
276 "TrackHandle_TrackContainer::updateObjectBrowser: No m_objBrowseTree!");
277 return;
278 }
279
280 if (!visible()) {
281 browserTreeItem()->setFlags(Qt::ItemFlag()); // not selectable, not enabled
282 } else {
283 browserTreeItem()->setFlags(Qt::ItemIsSelectable |
284 Qt::ItemIsEnabled); // selectable, enabled
285 }
286 QFont font = browserTreeItem()->font(0);
287 font.setStrikeOut(!visible());
288 browserTreeItem()->setFont(0, font);
289 browserTreeItem()->setFont(1, font);
290 // FIXME! Only do if necessary i.e. if something affecting this TSOS has
291 // changed.
292
293 QList<AssociatedObjectHandleBase*> list = getAllAscObjHandles();
294
295 if (list.empty()) {
297 "No ASC objects associated with this track - no track components "
298 "visible yet?");
299 return;
300 }
301
302 unsigned int numOfTS = 0;
303
304 for (auto trackstate : m_trackStates) {
305 // We assume that there is an ASC for every trackstate
306 AscObj_TrackState* asc = dynamic_cast<AscObj_TrackState*>(list.at(numOfTS));
307 if (!asc) {
309 "Could not cast to AscObj_TrackState, or could not find matching Asc "
310 "in list of size " +
311 QString::number(list.size()));
312 numOfTS++;
313 continue;
314 }
315
316 if (asc->trackState().index() != trackstate.index()) {
318 "WARNING! TrackHandle_TrackContainer::updateObjectBrowser: " +
319 QString::number(numOfTS) +
320 ": ASC index mismatch with trackstate from loop having " +
321 QString::number(trackstate.index()) + " and ASC TS having " +
322 QString::number(asc->trackState().index()));
323 numOfTS++;
324 continue;
325 }
326
327 if (!asc->browserTreeItem()) {
328 // not set yet - so need to do this now. Can we just use the index?
329 asc->setBrowserTreeItem(browserTreeItem()->child(numOfTS));
330 }
331
332 if (!asc->browserTreeItem()) {
333 VP1Msg::message("Could not find matching browserTreeItem");
334 numOfTS++;
335 continue;
336 }
337
338 if (!asc->visible()) {
339 asc->browserTreeItem()->setFlags(
340 Qt::ItemFlag()); // not selectable, not enabled
341 } else {
342 asc->browserTreeItem()->setFlags(
343 Qt::ItemIsSelectable | Qt::ItemIsEnabled); // selectable, enabled
344 }
345 QFont itemFont = asc->browserTreeItem()->font(0);
346 itemFont.setStrikeOut(!asc->visible());
347 asc->browserTreeItem()->setFont(0, itemFont);
348 asc->browserTreeItem()->setFont(1, itemFont);
349 numOfTS++;
350 }
351}
352
354 const QString& ) const {
355 return false;
356}
357
359 {
360 // Unfortunately actsTracks are stored in reverse order, so we need to do some
361 // gymnastics (There is certainly a more elegant way to do this, but since
362 // this will all be changed soon I don't think it matters)
363 if (!m_trackStates.empty())
364 return;
365 m_trackStates.reserve(m_track.nTrackStates());
366 for (auto trackstate : m_track.trackStatesReversed()) {
367 m_trackStates.push_back(trackstate);
368 }
369
371}
372
373
375 std::unique_ptr<std::vector<AssociatedObjectHandleBase*>>& ascobjs) {
376 if (ascobjs)
377 return;
379
380 ascobjs = std::make_unique<std::vector<AssociatedObjectHandleBase*>>();
381 unsigned int index =0;
382
383 for (const auto trackState : m_trackStates) {
384 addTrackState(trackState, ascobjs.get(), index++);
385 }
386}
387
389 const typename ActsTrk::TrackContainer::ConstTrackStateProxy& state,
390 std::vector<AssociatedObjectHandleBase*>* ascobjs, unsigned int index) {
391
392 AscObj_TrackState* ao = new AscObj_TrackState(this, index, state);
393
395
396 ascobjs->push_back(ao);
397 if (ao->parts() & shownTSOSParts()){
398 ao->setVisible(true);
399 }
400}
401
403 const ActsTrk::TrackContainer::ConstTrackStateProxy& state) const {
405 if (state.hasReferenceSurface()) {
406 const auto *actsElement = dynamic_cast<const ActsDetectorElement *>(
407 state.referenceSurface().surfacePlacement());
408 if (actsElement && common()->muonIdHelperSvc().get()) {
409 auto& idhelper = common()->muonIdHelperSvc()->mdtIdHelper(); // This is a lazy way to get an AtlasID helper. Not ideal if muon geometry is off.
410 if (idhelper.is_mdt(actsElement->identify())) {
412 } else if (idhelper.is_tgc(actsElement->identify())) {
414 } else if (idhelper.is_rpc(actsElement->identify())) {
416 } else if (idhelper.is_csc(actsElement->identify())) {
418 } else if (idhelper.is_stgc(actsElement->identify())) {
420 } else if (idhelper.is_mm(actsElement->identify())) {
422 }
423 }
424 return type;
425 }
427}
428
430 const ActsTrk::TrackContainer::ConstTrackStateProxy& state) const {
431 QString text("Unknown Measurement");
432 if (state.hasReferenceSurface()) {
433 const auto* actsElement = dynamic_cast<const ActsDetectorElement*>(
434 state.referenceSurface().surfacePlacement());
435 if (actsElement) {
436 auto& helperSvc = common()->muonIdHelperSvc();
437 if (helperSvc->isMuon(actsElement->identify()))
438 text = QString(helperSvc->toString(actsElement->identify()).c_str());
439 }
440 }
441 return text;
442}
Wrapper to avoid constant divisions when using units.
Acts::GeometryContext context() const
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 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.