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