ATLAS Offline Software
Loading...
Searching...
No Matches
VP1TruthVertexCollection.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
7// //
8// Implementation of class VP1TruthVertexCollection //
9// //
10// Author: Andreas.Wildauer@cern.ch //
11// Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
12// Ben Zastovnik //
13// Initial version: July 2008 //
14// //
16
25
26#include <Inventor/nodes/SoLineSet.h>
27#include <Inventor/nodes/SoVertexProperty.h>
28#include <Inventor/SoPath.h>
29#include <Inventor/nodes/SoSeparator.h>
30
31#include <QStringList>
32
34#include "AtlasHepMC/GenEvent.h"
36
37//#include "CLHEP/Units/SystemOfUnits.h"
38#include "GaudiKernel/SystemOfUnits.h"
39
40#include <sstream>
41
42//____________________________________________________________________
44{
45 QList<VP1StdCollection*> l;
46 for (const QString& key : VP1SGContentsHelper(controller->systemBase()).getKeys<McEventCollection>()) {
47 VP1TruthVertexCollection * col = new VP1TruthVertexCollection(controller,key);
48 col->init();
49 l << col;
50 }
51 return l;
52}
53
54
55//____________________________________________________________________
57public:
58 QString key;
61 std::map <SoNode *, HepMC::ConstGenVertexPtr> nodeToVertexMap;
62 SoLineSet * createCross(const double& x, const double& y, const double& z, const double& extent = 10*Gaudi::Units::mm ); // 10*CLHEP::mm );
63
65 public:
67 ~VertexHandle() { if (m_line) m_line->unref(); }
68
70 bool cutval(cut());
71 if (cutval!=m_attached) {
72 if (cutval)
73 ensureAttach(m_d->theclass->collSep());
74 else
75 ensureDetach(m_d->theclass->collSep());
76 }
77 }
78 void updateShape() {
79 if (!m_line)
80 return;
81 if (!m_attached) {
82 //invalidate...
83 }
84
85 SoVertexProperty *vertices = static_cast<SoVertexProperty *>(m_line->vertexProperty.getValue());
86 if (!vertices) {
87 vertices = new SoVertexProperty();
88 m_line->numVertices.set1Value(0,2);
89 m_line->numVertices.set1Value(1,2);
90 m_line->numVertices.set1Value(2,2);
91 m_line->vertexProperty = vertices;
92 }
93
94 QPair<VertexCommonFlags::QUANTITY,double> p = m_d->controller->truthCrossLength();
95 double extent;
96 if (p.second<0)
97 extent = -p.second;
98 else
99 extent = p.second * quantityVal(p.first);
100
101 double x(m_vertex->position().x()), y(m_vertex->position().y()), z(m_vertex->position().z());
102 vertices->vertex.set1Value ( 0,x-extent, y, z );
103 vertices->vertex.set1Value ( 1,x+extent, y,z );
104 vertices->vertex.set1Value ( 2, x,y-extent, z);
105 vertices->vertex.set1Value ( 3, x,y+extent, z );
106 vertices->vertex.set1Value ( 4, x, y,z-extent );
107 vertices->vertex.set1Value ( 5, x, y,z+extent );
108 }
110 SoLineSet * line() const { return m_line; }
111
113 //Find total 4-momentum of incoming particles
114 double px(0), py(0), pz(0), e(0);//HepMC::FourVector does NOT support operators + or += !!!!!!
115 for (const auto& PartIn: m_vertex->particles_in()){
116 px +=PartIn->momentum().px();
117 py +=PartIn->momentum().py();
118 pz +=PartIn->momentum().pz();
119 e += PartIn->momentum().e();
120 }
121 const HepMC::FourVector mom(px,py,pz,e);
122 switch(q) {
123 case VertexCommonFlags::ENERGY: return e;
124 case VertexCommonFlags::MOMENTUM: return mom.length();
125 case VertexCommonFlags::TRANSVERSE_MOM: return mom.perp();
126 default: // VertexCommonFlags::MASS:
127 return mom.m();
128 }
129 }
130 private:
131 void ensureAttach(SoSeparator * collsep) {
132 if (m_attached)
133 return;
134 m_attached = true;
135 if (!m_line) {
136 m_line = new SoLineSet;
137 m_line->ref();
138 }
139 updateShape();
140 collsep->addChild(m_line);
141 }
142 void ensureDetach(SoSeparator * collsep) {
143 if (!m_attached)
144 return;
145 m_attached = false;
146 collsep->removeChild(m_line);
147 }
148 bool cut() {
149
150 if (m_d->controller->truthCutPrimaryVertexOnly()&&this!=m_d->vertices.at(0))
151 return false;
152
153 if (!m_d->controller->truthCutAllowedEta().contains(m_vertex->position().eta()))
154 return false;
155
156 QPair<VertexCommonFlags::QUANTITY,VP1Interval> p = m_d->controller->truthCutQuantity();
157 if (!p.second.isAllR()) {
158 if (!p.second.contains(quantityVal(p.first)))
159 return false;
160 }
161
162 //We handle phi cut last:
163 double phi(m_vertex->position().phi());
164 for (const VP1Interval& i : m_d->controller->truthCutAllowedPhi()) {
165 if (i.contains(phi)||i.contains(phi+2*M_PI)||i.contains(phi-2*M_PI))
166 return true;
167 }
168 return false;
169 }
172 SoLineSet * m_line;
174 };
175
176 QList<VertexHandle*> vertices;
177};
178
179
180//____________________________________________________________________
182 : VP1StdCollection(controller->systemBase(),"VP1TruthVertexCollection_"+key), m_d(new Imp)
183{
184 m_d->key = key;
185 m_d->theclass = this;
186 m_d->controller = controller;
187 connect(controller,SIGNAL(truthCutAllowedEtaChanged(const VP1Interval&)),this,SLOT(recheckAllCuts()));
188 connect(controller,SIGNAL(truthCutAllowedPhiChanged(const QList<VP1Interval>&)),this,SLOT(recheckAllCuts()));
189 connect(controller,SIGNAL(truthCutPrimaryVertexOnlyChanged(bool)),this,SLOT(recheckAllCuts()));
190 connect(controller,SIGNAL(truthCutQuantityChanged(const QPair<VertexCommonFlags::QUANTITY,VP1Interval>&)),this,SLOT(recheckAllCuts()));
191 connect(controller,SIGNAL(truthCrossLengthChanged(QPair<VertexCommonFlags::QUANTITY,double>)),this,SLOT(updateAllShapes()));
192}
193
194//____________________________________________________________________
196{
197 for (Imp::VertexHandle*vh : m_d->vertices)
198 delete vh;
199 delete m_d;
200}
201
202//____________________________________________________________________
204{
205 return m_d->key;
206}
207
208//____________________________________________________________________
210{
211 VP1MaterialButton::setMaterialParameters( m, 0.66667/*red*/, 0.66667/*green*/, 1.0/*blue*/, 0.15 /*brightness*/ );
212}
213
214//_____________________________________________________________________________________
215SoLineSet * VP1TruthVertexCollection::Imp::createCross(const double& x, const double& y, const double& z, const double& extent )
216{
217 SoVertexProperty *vertices = new SoVertexProperty();
218 vertices->vertex.set1Value ( 0,x-extent, y, z );
219 vertices->vertex.set1Value ( 1,x+extent, y,z );
220 vertices->vertex.set1Value ( 2, x,y-extent, z);
221 vertices->vertex.set1Value ( 3, x,y+extent, z );
222 vertices->vertex.set1Value ( 4, x, y,z-extent );
223 vertices->vertex.set1Value ( 5, x, y,z+extent );
224 SoLineSet * line = new SoLineSet();
225 line->numVertices.set1Value(0,2);
226 line->numVertices.set1Value(1,2);
227 line->numVertices.set1Value(2,2);
228 line->vertexProperty = vertices;
229 return line;
230}
231
232//____________________________________________________________________
234{
235 const McEventCollection* mcEventColl;
236 if (!VP1SGAccessHelper(systemBase()).retrieve(mcEventColl, m_d->key))
237 return false;
238
239 //Fixme: Here we take the first event in the event collection. Instead we should loop!
240 if (mcEventColl->size()<1)//Fixme
241 return false;
242
243 McEventCollection::const_iterator itEvent, itEventEnd(mcEventColl->end());
244 for (itEvent = mcEventColl->begin(); itEvent != itEventEnd; ++itEvent) {
245 const HepMC::GenEvent* genEvent(*itEvent);
246 if (!genEvent)
247 continue;
248
249 for (const auto& vtx: genEvent->vertices()) {
250 if (!vtx)
251 continue;
252 m_d->vertices << new Imp::VertexHandle(vtx,m_d);
253 }
254 }
255
257
258 return true;
259}
260
261//____________________________________________________________________
262QStringList VP1TruthVertexCollection::infoOnClicked(SoPath* pickedPath)
263{
264 //Get HepMC::GenVertex pointer associated with the clicked node:
265 SoNode * pickedNode = (pickedPath ? (pickedPath->getLength()>0?pickedPath->getNodeFromTail(0):0): 0);
266
267 Imp::VertexHandle* vertexHandle(0);
268 for (Imp::VertexHandle* vh : m_d->vertices) {
269 if (vh->line()==pickedNode) {
270 vertexHandle = vh;
271 break;
272 }
273 }
274 if (!vertexHandle)
275 return QStringList() << "ERROR: Could not get truth vertex information for picked Node";
276 HepMC::ConstGenVertexPtr vtx = vertexHandle->vertex();
277
278 QStringList l;
279 if (m_d->controller->printInfoOnClick()) {
280
281 //Make output:
282 l <<"Truth vertex from collection "+text()+":" ;
283 for (const auto& PartIn: vtx->particles_in()) {
284 const int pdg = PartIn->pdg_id();
285 bool ok;
286 QString name = VP1ParticleData::particleName(pdg,ok);
287 if (!ok)
288 name = "<unknown>";
289 l << "--> In: "+name+" ("+str(pdg)+") [ P = "+str(PartIn->momentum().length()/Gaudi::Units::GeV)+" GeV ]";
290 }
291 for (const auto& PartOut: vtx->particles_out()) {
292 const int pdg = PartOut->pdg_id();
293 bool ok;
294 QString name = VP1ParticleData::particleName(pdg,ok);
295 if (!ok)
296 name = "<unknown>";
297 l << "--> Out: "+name+" ("+str(pdg)+") [ P = "+str(PartOut->momentum().length()/Gaudi::Units::GeV)+" GeV ]";
298 }
299
300 if (m_d->controller->printVerboseInfoOnClick()) {
301 l <<"======== Dump ========";
302 std::ostringstream s;
303 HepMC::Print::line(s,vtx);
304 l << QString(s.str().c_str()).split('\n');
305 l <<"======================";
306 }
307
308 }
309 if (m_d->controller->zoomOnClick()) {
310 std::set<SoCamera*> cameras = static_cast<IVP13DSystem*>(systemBase())->getCameraList();
311 std::set<SoCamera*>::iterator it,itE = cameras.end();
312 for (it=cameras.begin();it!=itE;++it)
313 VP1CameraHelper::animatedZoomToPath(*it,collSep(),pickedPath,2.0,1.0);
314 }
315
316 return l;
317}
318
319//____________________________________________________________________
321{
322 static_cast<IVP13DSystem*>(systemBase())->deselectAll();
324 for (Imp::VertexHandle* vh : m_d->vertices)
325 vh->recheckCutStatus();
327}
328
329//____________________________________________________________________
331{
333 for (Imp::VertexHandle* vh : m_d->vertices)
334 vh->updateShape();
336}
#define M_PI
Scalar phi() const
phi method
#define y
#define x
#define z
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.
size_type size() const noexcept
Returns the number of elements in the collection.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
static VP1CameraHelper * animatedZoomToPath(SoCamera *camera, SoGroup *sceneroot, SoPath *path, double duration_in_secs=1.0, double clipVolPercent=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)
IVP1System * systemBase() const
static void setMaterialParameters(SoMaterial *m, const QColor &, const double &brightness=0.0, const double &transp=0.0)
static QString particleName(const int &pdgcode, bool &ok)
QStringList getKeys() const
virtual void largeChangesEnd()
virtual void init(VP1MaterialButtonBase *button=0)
SoSeparator * collSep() const
All 3D objects from this coll.
virtual void largeChangesBegin()
QString text() const
VP1StdCollection(IVP1System *, const QString &helperClassName)
double quantityVal(const VertexCommonFlags::QUANTITY &q)
VertexHandle(HepMC::ConstGenVertexPtr v, VP1TruthVertexCollection::Imp *dd)
SoLineSet * createCross(const double &x, const double &y, const double &z, const double &extent=10 *Gaudi::Units::mm)
std::map< SoNode *, HepMC::ConstGenVertexPtr > nodeToVertexMap
void assignDefaultMaterial(SoMaterial *) const
VP1TruthVertexCollection(VertexSysController *, const QString &key)
QStringList infoOnClicked(SoPath *pickedPath)
static QList< VP1StdCollection * > createCollections(VertexSysController *)
HepMC3::FourVector FourVector
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39