ATLAS Offline Software
Loading...
Searching...
No Matches
TrackSystemDisplay.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5/***********************************************************************************
6 * @Package : VP1TriggerSystems
7 * @Class : TrackSystemDisplay
8 *
9 * @brief : Temp. Version of Track Display (for testing purposes only)
10 *
11 * @author : Manuel Proissl <mproissl@cern.ch> - University of Edinburgh
12 * @author : Thomas Kittelmann <thomas.kittelmann@cern.ch>
13 ***********************************************************************************/
14
15//Local includes
17#include "ui_tracksystemcontrollerform.h"
18
19//Track includes
21#include "TrkTrack/Track.h"
24
25//Inventor includes
26#include <Inventor/nodes/SoSeparator.h>
27#include <Inventor/nodes/SoLineSet.h>
28#include <Inventor/nodes/SoVertexProperty.h>
29#include <Inventor/nodes/SoSwitch.h>
30
31//Other includes
34#include <QTextDocument>
35#include "GaudiKernel/SystemOfUnits.h"
37
38
39//Track System Constructor
40//_____________________________________________________________________________________________
42 : IVP13DSystemSimple("TrackSystemDisplay",
43 "This is a temporary testing version of the basic 3D track display system.",
44 "Manuel Proissl, mproissl@cern.ch"), m_ptcut(0*Gaudi::Units::GeV), m_multiselection(0),
45 m_trackInfoDisplay(nullptr)
46{
47 std::cout << "INFO :: TrackSystemDisplay -> constructor" << std::endl;
48}//END: constructor
49
50
51//Building the Event Scene
52//_____________________________________________________________________________________________
54{
55 std::cout << "INFO :: TrackSystemDisplay -> building event scene graph" << std::endl;
56
57 m_nodeToTrack.clear();
58 m_switchToPt.clear();
59
60 if(!sg) {
61 message("ERROR :: Null storegate pointer received.");
62 return;
63 }
64
65 const TrackCollection *trackColl;
66 std::string trackname="Tracks";
67 StatusCode status = sg->retrieve(trackColl, trackname); //retrieve tracks from storegate
68 if (status != StatusCode::SUCCESS || !trackColl) {
69 message("ERROR :: Could not retrieve track collection (used key="+QString(trackname.c_str())+")");
70 return;
71 }
72
74 m_multiselection->policy = SoCooperativeSelection::TOGGLE;
77
78 TrackCollection::const_iterator trackItr, trackItrEnd = trackColl->end();
79
80 for(trackItr=trackColl->begin(); trackItr!=trackItrEnd; ++trackItr) {
81 const Trk::Track *track = (*trackItr);
82 const DataVector<const Trk::TrackParameters> *params = track->trackParameters();
83
84 if(!params || params->size()<2)
85 continue;
86
87 SoVertexProperty *vertices = new SoVertexProperty();
88
89 int iver(0);
91 for(it=params->begin(); it!=itE; ++it) {
92 vertices->vertex.set1Value(iver++,(*it)->position().x(),(*it)->position().y(),(*it)->position().z());
93 }
94
95 SoLineSet * line = new SoLineSet();
96 line->numVertices = iver;
97 line->vertexProperty = vertices;
98
99 SoSwitch * sw = new SoSwitch();
100 double pt = params->front()->pT();
101 sw->whichChild = pt > m_ptcut ? SO_SWITCH_ALL : SO_SWITCH_NONE;
102
103 m_switchToPt[sw] = pt;
104 sw->addChild(line);
105 m_multiselection->addChild(sw);
106 m_nodeToTrack[line] = track;
107
108 updateGUI();
109 }
110
111 root->addChild(m_multiselection);
112}//END: buildEventSceneGraph
113
114
115//Actions when user chose <single> track selection in controller and clicked on a track
116//_____________________________________________________________________________________________
117void TrackSystemDisplay::userPickedNode(SoNode* pickedNode, SoPath * /*pickedPath*/) {
118
119 if (m_nodeToTrack.find(pickedNode)==m_nodeToTrack.end()) {
120 message("ERROR :: No track information for selected node.");
121 return;
122 }
123
124 //Get track parameters [m_nodeToTrack contains all tracks]
125 const DataVector<const Trk::TrackParameters> *params = m_nodeToTrack[pickedNode]->trackParameters();
126 if (!params || params->empty()) {
127 message("ERROR :: Track has no track parameters.");
128 return;
129 }
130
131 //Load and print track parameters
132 QString title = "TriggerDisplay - Track Parameters";
133 QList<QString> paraname, paravalue;
134 paraname << QString("|p|"); paravalue << QString::number(params->front()->momentum().mag()/Gaudi::Units::GeV)+" GeV";
135 paraname << QString("pT"); paravalue << QString::number(params->front()->pT()/Gaudi::Units::GeV)+" GeV";
136 paraname << QString("Q"); paravalue << QString::number(params->front()->charge());
137 paraname << QString("Eta"); paravalue << QString::number(params->front()->eta());
138 printTrackInfo(title, paraname, paravalue);
139
140 //Update camera view
141 CamList cameras = getCameraList();
142 for (CamListItr itCam = cameras.begin(); itCam!=cameras.end(); ++itCam) {
144 }
145}//END: userPickedNode
146
147
148//Actions when user chose <multi> track selections in controller and clicked on 2 or more tracks
149//_____________________________________________________________________________________________
150void TrackSystemDisplay::userChangedSelection(SoCooperativeSelection*, const QSet<SoNode*> & nodes, QSet<SoPath*>)
151{
152 if(nodes.count()<2)
153 return;
154
155 Amg::Vector3D total3mom(0.0,0.0,0.0);
156 double totalenergy(0);
157
158 foreach (SoNode * node, nodes) {
159 //Track pointer:
160 if (m_nodeToTrack.find(node)==m_nodeToTrack.end()) {
161 message("ERROR :: Does not have track information for all nodes");
162 return;
163 }
164
165 //Parameters:
166 const DataVector<const Trk::TrackParameters> *params = m_nodeToTrack[node]->trackParameters();
167 if ( !params || params->empty() ) {
168 message("ERROR :: Track has no trackparameters");
169 return;
170 }
171
172 total3mom += params->front()->momentum();
173 totalenergy += params->front()->momentum().mag();
174 }
175
176 //Display result:
177 double invmasssq = totalenergy*totalenergy - total3mom.mag2();
178 QString invmass_str = invmasssq>=0.0 ? QString::number(sqrt(invmasssq)/Gaudi::Units::GeV) : "sqrt(-1)*"+QString::number(sqrt(-invmasssq)/Gaudi::Units::GeV);
179 QString title = "Invariant Mass";
180 QList<QString> paraname, paravalue;
181
182 paraname << QString::number(nodes.count())+" tracks";
183 paravalue << invmass_str+" GeV";
184 printTrackInfo(title, paraname, paravalue);
185}//END: userChangedSelection
186
187
188//Setup controller GUI and signals
189//_____________________________________________________________________________________________
191{
192 QWidget * controller = new QWidget(0);
193 Ui::TrackSystemControllerForm ui;
194
195 //Setup UI
196 ui.setupUi(controller);
197
198 //Setup pT Cut controller and its signal
199 m_ptcut = ui.doubleSpinBox_ptcut->value()*Gaudi::Units::GeV;
200 connect(ui.doubleSpinBox_ptcut,SIGNAL(valueChanged(double)),this,SLOT(ptCutChanged(double)));
201
202 //Setup Track Selection signal(s)
203 connect(ui.radioButton_select_single,SIGNAL(toggled(bool)),this,SLOT(updateSelectionMode(bool)));
204
205 //Setup Trigger Browser Button
206 //initDialog(ui_trig, ui.pushButton_display_TriggerBrowser);
207
208 //Setup Track Information browser
209 m_trackInfoDisplay = ui.trackInfoDisplay;
210 m_trackInfoDisplay->setReadOnly(true); //only display, no edit
211
212 return controller;
213}//END: buildController
214
215
216//Print track information to trackInfoDisplay
217//_____________________________________________________________________________________________
218void TrackSystemDisplay::printTrackInfo(QString title, QList<QString> paraname, QList<QString> paravalue)
219{
220 QString header = "<html><head><link rel='stylesheet' type='text/css' href='format.css'></head><body>", footer = "</body></html>";
221 QString css = "#design { font-family: Courier New; font-size: 12px; margin: 0px; width: 100%; text-align: left; } #design th { font-size: 13px; font-weight: normal; padding: 2px; background: #ccc; border-top: 4px solid #000; border-bottom: 1px solid #fff; color: #000; } #design td { padding: 2px; background: #000; border-bottom: 1px solid #fff; color: #fff; border-top: 1px solid transparent; }";
222 QString table_b = "<table id='design'>", table_e = "</table>";
223 QString thead_b = "<thead><tr><th COLSPAN=2>", thead_e = "</th></tr></thead>";
224 QString tbody_b = "<tbody>", tbody_e = "</tbody>";
225 QString data_tr_b = "<tr>", data_tr_e = "</tr>";
226 QString data_td_b = "<td>", data_td_e = "</td>";
227 QString data="";
228
229 //Generate layout string
230 for(int i=0; i<paraname.size(); ++i) {
231 data += data_tr_b+data_td_b+ paraname[i] +data_td_e;
232 data += data_td_b+ paravalue[i] +data_td_e+data_tr_e;
233 }
234
235 //Combine all print segments
236 QTextDocument *doc = new QTextDocument;
237 doc->addResource(QTextDocument::StyleSheetResource, QUrl("format.css"), css);
238 doc->setHtml(header+table_b+thead_b+title+thead_e+tbody_b+data+tbody_e+table_e+footer);
239
240 //Display track info
241 m_trackInfoDisplay->setDocument(doc);
242 m_trackInfoDisplay->show();
243}//END: printTrackInfo
244
245
246//Signal triggered actions when pT Cut has been changed by user
247//_____________________________________________________________________________________________
249{
250 m_ptcut = ptcut*Gaudi::Units::GeV;
251
252 std::map<SoSwitch*,double>::iterator it, itE = m_switchToPt.end();
253 for ( it = m_switchToPt.begin(); it!=itE; ++it) {
254 it->first->whichChild = ( it->second>m_ptcut ? SO_SWITCH_ALL : SO_SWITCH_NONE );
255 }
256}//END: ptCutChanged
257
258
259//Track Selection mode switch
260//_____________________________________________________________________________________________
262{
263 if(!m_multiselection || single==(m_multiselection->activePolicy.getValue()==SoCooperativeSelection::INERT))
264 return;
265
266 deselectAll();
267
268 if(single)
270 else
272}//END: updateSelectionMode
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
IVP13DSystemSimple(const QString &name, const QString &information, const QString &contact_info)
std::set< SoCamera * > CamList
virtual void deselectAll(SoCooperativeSelection *exception_sel=0)
void registerSelectionNode(SoCooperativeSelection *)
CamList getCameraList()
CamList::iterator CamListItr
void message(const QString &) const
The Athena Transient Store API.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
std::map< SoSwitch *, double > m_switchToPt
void printTrackInfo(QString title, QList< QString > paraname, QList< QString > paravalue)
void userChangedSelection(SoCooperativeSelection *, const QSet< SoNode * > &, QSet< SoPath * >)
SoCooperativeSelection * m_multiselection
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
void updateSelectionMode(bool single)
QTextBrowser * m_trackInfoDisplay
void userPickedNode(SoNode *pickedNode, SoPath *pickedPath)
std::map< SoNode *, const Trk::Track * > m_nodeToTrack
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 node.h:24
Eigen::Matrix< double, 3, 1 > Vector3D
=============================================================================