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