ATLAS Offline Software
Loading...
Searching...
No Matches
VP1MCSystem.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#include "ui_vp1mccontroller.h"
11
12#include "GaudiKernel/IClassIDSvc.h"
13#include "GaudiKernel/ISvcLocator.h"
14#include <QListWidget>
15#include <QListWidgetItem>
16#include <QTreeWidget>
17#include <QTreeWidgetItem>
18
21#include "CLHEP/Vector/ThreeVector.h"
23#include "GaudiKernel/IPartPropSvc.h"
25#include "CLHEP/Units/SystemOfUnits.h"
26#include <cmath>
27#include <stack>
28
29//____________________________________________________________________
31public:
34 Ui::VP1MCSystemControllerForm ui{};
35 QTreeWidget *tw;
36 SmartIF<IPartPropSvc> pps;
37
38 void handle(QTreeWidgetItem *item, const HepMC::GenParticle &particle);
39
40 void expand(const QString& text, QTreeWidgetItem *item);
41 void zeroFormat(QTreeWidgetItem *item);
42};
43
45
46 ISvcLocator* svcLoc = theclass->serviceLocator();
47 if (!svcLoc) {
48 theclass->message("Error: Got NULL pointer to the service locator!");
49 return;
50 }
51 pps = svcLoc->service( "PartPropSvc" );
52 if(!pps) {
53 theclass->message("Error: Could not retrieve PartPropSvc!!");
54 return;
55 }
56
57}
58
59void VP1MCSystem::Imp::expand(const QString& name, QTreeWidgetItem *item) {
60 QFont font = item->font(0);
61
62 if (item->text(0)==name) {
63 font.setBold(true);
64 for (int i=0;i<item->columnCount();++i) {
65 item->setFont(i,font);
66 }
67
68
69 QTreeWidgetItem *expandItem = item;
70 while (expandItem) {
71 expandItem->setExpanded(true);
72 expandItem=expandItem->parent();
73 if (!expandItem || expandItem->isExpanded()) break;
74 }
75 }
76 for (int i=0;i<item->childCount();++i) {
77 expand(name, item->child(i));
78 }
79}
80
81void VP1MCSystem::Imp::zeroFormat(QTreeWidgetItem *item) {
82 QFont font = item->font(0);
83 font.setBold(false);
84 for (int i=0;i<item->columnCount();++i) {
85 item->setFont(i,font);
86 }
87 for (int i=0;i<item->childCount();++i) {
88 zeroFormat(item->child(i));
89 }
90}
91
92void VP1MCSystem::Imp::handle(QTreeWidgetItem *item, const HepMC::GenParticle &theParticle) {
93
94 std::ostringstream partStream, pidStream, massStream, ptStream, etaStream, phiStream;
95
96 bool ok;
97 QString name = VP1ParticleData::particleName(theParticle.pdg_id(),ok);
98 if (ok) {
99 partStream << name.toStdString();
100 }
101 else {
102 partStream << "PDG ID = " << theParticle.pdg_id();
103 }
104
105
106 item->setText(0,partStream.str().c_str());
107
108 double eta = 0;
109 CLHEP::Hep3Vector mom=CLHEP::Hep3Vector(theParticle.momentum().x(),
110 theParticle.momentum().y(),
111 theParticle.momentum().z());
112 if (mom.x()!=0 || mom.y()!=0) {
113 eta =-log(tan(mom.theta()/2));
114 }
115 double phi = mom.phi();
116 while (phi<0) phi += 2*M_PI;
117 while (phi>2*M_PI) phi -= 2*M_PI;
118 double pt = mom.perp()/CLHEP::GeV;
119
120 pidStream << theParticle.pdg_id();
121 item->setText(1,pidStream.str().c_str());
122
123 massStream << theParticle.generated_mass()/CLHEP::GeV;
124 item->setText(2,massStream.str().c_str());
125
126 ptStream << pt;
127 item->setText(3,ptStream.str().c_str());
128
129 etaStream << eta;
130 item->setText(4,etaStream.str().c_str());
131
132 phiStream << phi;
133 item->setText(5,phiStream.str().c_str());
134
135 if (1) {
136 HepMC::ConstGenVertexPtr prodVertex = theParticle.production_vertex();
137
138 QBrush brush=item->foreground(0);
139 brush.setColor(Qt::gray);
140
141 if (prodVertex) {
142 int nParents=prodVertex->particles_in_size();
143 if (nParents==0) {
144 brush.setColor(Qt::black);
145 }
146 else if (nParents==1){
147 brush.setColor(Qt::blue);
148 }
149 else if (nParents>1) {
150 brush.setColor(Qt::red);
151 }
152 }
153
154 item->setForeground(0,brush);
155 item->setForeground(1,brush);
156 item->setForeground(2,brush);
157 item->setForeground(3,brush);
158 item->setForeground(4,brush);
159 }
160 if (1) {
161 HepMC::ConstGenVertexPtr decayVertex = theParticle.end_vertex();
162 if (decayVertex) {
163 // decayVertex->print();
164 for ( const HepMC::ConstGenParticlePtr& current : *decayVertex ) {
165 QTreeWidgetItem *newItem = new QTreeWidgetItem();
166 item->addChild(newItem);
167 handle(newItem,*current);
168 }
169 }
170 }
171}
172
173
174//____________________________________________________________________
176 : IVP1System("MC",
177 "System for browsing the MC Event",
178 "Joe Boudreau <boudreau@pitt.edu> (original), Thomas.Kittelmann@cern.ch (VP1 implementation)"),
179 m_d(new Imp(this))
180{
181}
182
183
184//____________________________________________________________________
186{
187 delete m_d; m_d=0;
188}
189
190
191
192//____________________________________________________________________
194{
195 QWidget * controller = new QWidget;
196 m_d->ui.setupUi(controller);
197 connect(m_d->ui.addButton,SIGNAL(clicked()), this, SLOT(addParticle()));
198 connect(m_d->ui.subtractButton,SIGNAL(clicked()), this, SLOT(removeParticle()));
199 connect(m_d->ui.searchButton,SIGNAL(clicked()), this, SLOT(searchParticles()));
200 connect (m_d->ui.listWidget, SIGNAL (itemDoubleClicked (QListWidgetItem *)), this, SLOT (editItem (QListWidgetItem *)));
201 registerController(controller);
202
203}
204
205//____________________________________________________________________
207{
208 //erase();
210 if (VP1SGAccessHelper(this).retrieve(iter,endColl)) {
211 for (;iter!=endColl;++iter) {
213 for (e=iter->begin();e!=iter->end(); ++e) {
214 for (const HepMC::ConstGenParticlePtr& particle : **e) {
215 if (!particle->production_vertex() || ! particle->production_vertex()->particles_in_size()) {
216 QTreeWidgetItem *item = new QTreeWidgetItem();
217 m_d->tw->insertTopLevelItem(m_d->tw->topLevelItemCount(), item);
218 m_d->handle(item,*particle);
219 }
220 }
221 }
222 }
223 }
224}
225
226
227//____________________________________________________________________
229{
230 m_d->tw->clear();
231}
232
233//____________________________________________________________________
235{
236 VP1Serialise serialise(0/*version*/,this);
237 serialise.save(IVP1System::saveState());//Info from base class
238 serialise.save(m_d->ui.listWidget->count());
239 for (int i=0;i<m_d->ui.listWidget->count();++i) {
240 m_d->ui.listWidget->setCurrentRow(i);
241 serialise.save(m_d->ui.listWidget->item(i)->text());
242 }
243 serialise.warnUnsaved(controllerWidget());
244 return serialise.result();
245
246}
247
248//____________________________________________________________________
250{
251 VP1Deserialise state(ba,this);
252 if (state.version()!=0) {
253 message("Warning: State data in .vp1 file is in wrong format - ignoring!");
254 return;
255 }
256 IVP1System::restoreFromState(state.restoreByteArray());
257 qint32 itemCount=state.restoreInt();
258 for (int i=0;i<itemCount;++i) {
259 QString text=state.restoreString();
260 m_d->ui.listWidget->addItem(text);
261 }
262 state.warnUnrestored(controllerWidget());
263}
264
265void VP1MCSystem::setTree(QTreeWidget *tw) {
266 m_d->tw=tw;
267 m_d->tw->setColumnCount(5);
268 m_d->tw->setHeaderLabels((QStringList()<<"Type"<< "ID" << "Mass (GeV) " << "Pt (GeV)"<<"Eta"<<"Phi"));
269 m_d->tw->setAlternatingRowColors ( true );
270 m_d->tw->setEditTriggers(QAbstractItemView::NoEditTriggers);
271}
273 message("Adding...");
274 m_d->ui.listWidget->addItem("<particleName>");
275 m_d->ui.listWidget->setCurrentRow(m_d->ui.listWidget->count()-1);
276 //QListWidgetItem *item =m_d->ui.listWidget->currentItem();
277 //item->setFlags(Qt::ItemIsEditable|Qt::ItemIsSelectable);
278 //m_d->ui.listWidget->editItem(item);
279}
281 message("Removing...");
282 QList<QListWidgetItem *> selectedItems =m_d->ui.listWidget->selectedItems();
283 for (int i=0;i<selectedItems.size();++i) {
284 int row = m_d->ui.listWidget->row(selectedItems[i]);
285 QListWidgetItem *item = m_d->ui.listWidget->takeItem(row);
286 delete item;
287 }
288}
290 message("Searching...");
291 m_d->tw->collapseAll();
292 for (int j=0;j<m_d->ui.listWidget->count();++j) {
293 m_d->ui.listWidget->setCurrentRow(j);
294 QString text = m_d->ui.listWidget->currentItem()->text();
295 for (int i=0;i<m_d->tw->topLevelItemCount();++i) {
296 m_d->zeroFormat(m_d->tw->topLevelItem(i));
297 }
298 }
299
300 for (int j=0;j<m_d->ui.listWidget->count();++j) {
301 m_d->ui.listWidget->setCurrentRow(j);
302 QString text = m_d->ui.listWidget->currentItem()->text();
303 for (int i=0;i<m_d->tw->topLevelItemCount();++i) {
304 m_d->expand(text,m_d->tw->topLevelItem(i));
305 }
306 }
307
308
309}
310
311void VP1MCSystem::editItem(QListWidgetItem *item) {
312 m_d->ui.listWidget->openPersistentEditor(item);
313}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
static Double_t tc
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
virtual void restoreFromState(QByteArray)
const QString & name() const
State state() const
QWidget * controllerWidget()
IVP1System(const QString &name, const QString &information, const QString &contact_info)
void message(const QString &) const
void registerController(QWidget *)
virtual QByteArray saveState()
a const_iterator facade to DataHandle.
Definition SGIterator.h:164
The Athena Transient Store API.
void handle(QTreeWidgetItem *item, const HepMC::GenParticle &particle)
Imp(VP1MCSystem *tc)
Ui::VP1MCSystemControllerForm ui
QTreeWidget * tw
void zeroFormat(QTreeWidgetItem *item)
SmartIF< IPartPropSvc > pps
void expand(const QString &text, QTreeWidgetItem *item)
VP1MCSystem * theclass
void removeParticle()
void setTree(QTreeWidget *tw)
void restoreFromState(QByteArray)
virtual ~VP1MCSystem()
void refresh(StoreGateSvc *storegate)
void create(StoreGateSvc *detstore)
QByteArray saveState()
void editItem(QListWidgetItem *)
void addParticle()
void searchParticles()
static QString particleName(const int &pdgcode, bool &ok)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24