200{
201 m_d->hgtdGuideRootSwitch =
nullptr;
202 m_d->hgtdHitSwitch =
nullptr;
203 m_d->hgtdTruthTrackSwitch =
nullptr;
204 m_d->hgtdPrimaryParticleSwitch =
nullptr;
205 m_d->hgtdSecondaryParticleSwitch =
nullptr;
206 m_d->hgtdUnlinkedParticleSwitch =
nullptr;
207 m_d->hgtdPrimaryParticleLabelsSwitch =
nullptr;
208 m_d->hgtdSecondaryParticleLabelsSwitch =
nullptr;
209 m_d->hgtdUnlinkedParticleLabelsSwitch =
nullptr;
210
211#ifdef BUILDVP1LIGHT
212 (void)sg;
213 (void)root;
214#else
216 return;
217
219 if (sg->
retrieve(collection,
"HGTD_Hits")!=StatusCode::SUCCESS) {
220 message(
"Unable to retrieve HGTD Hits for guide lines");
221 return;
222 }
223
224 SoSwitch* hgtdGuideRootSwitch = new SoSwitch();
225 m_d->hgtdGuideRootSwitch = hgtdGuideRootSwitch;
226 root->addChild(hgtdGuideRootSwitch);
227
228 SoVertexProperty* primaryHitVtxProperty = new SoVertexProperty();
229 SoVertexProperty* secondaryHitVtxProperty = new SoVertexProperty();
230 SoVertexProperty* unlinkedHitVtxProperty = new SoVertexProperty();
231 SoPointSet* primaryHitPointSet = new SoPointSet();
232 SoPointSet* secondaryHitPointSet = new SoPointSet();
233 SoPointSet* unlinkedHitPointSet = new SoPointSet();
234 primaryHitVtxProperty->enableNotify(FALSE);
235 secondaryHitVtxProperty->enableNotify(FALSE);
236 unlinkedHitVtxProperty->enableNotify(FALSE);
237 primaryHitPointSet->enableNotify(FALSE);
238 secondaryHitPointSet->enableNotify(FALSE);
239 unlinkedHitPointSet->enableNotify(FALSE);
240 unsigned int primaryHitCount = 0;
241 unsigned int secondaryHitCount = 0;
242 unsigned int unlinkedHitCount = 0;
243 std::vector<TruthHitLabel> primaryHitLabels;
244 std::vector<TruthHitLabel> secondaryHitLabels;
245 std::vector<TruthHitLabel> unlinkedHitLabels;
246 QMap<QString, std::vector<TruthHitPoint> > truthHitPoints;
247
248 for (
const SiHit&
hit : *collection) {
250 if(!ghit)
251 continue;
252
253 HepGeom::Point3D<double>
pos = ghit.getGlobalPosition();
254 const HepMcParticleLink& particleLink =
hit.particleLink();
256 QString particleLabel("unlinked");
257 QString trackKey;
258 if (particle) {
260 trackKey = QString("truth:%1").arg(barcode);
261 bool particleNameOK = false;
263 if (!particleNameOK || particleLabel.isEmpty())
264 particleLabel = QString(
"pdg %1").arg(
particle->pdg_id());
265 }
266
267 if (!particle) {
268 unlinkedHitVtxProperty->vertex.set1Value(unlinkedHitCount++,
pos.x(),
pos.y(),
pos.z());
269 unlinkedHitLabels.emplace_back(pos, particleLabel);
271 primaryHitVtxProperty->vertex.set1Value(primaryHitCount++,
pos.x(),
pos.y(),
pos.z());
272 primaryHitLabels.emplace_back(pos, particleLabel);
273 } else {
274 secondaryHitVtxProperty->vertex.set1Value(secondaryHitCount++,
pos.x(),
pos.y(),
pos.z());
275 secondaryHitLabels.emplace_back(pos, particleLabel);
276 }
277
278 if (!trackKey.isEmpty())
279 truthHitPoints[trackKey].emplace_back(
hit.meanTime(), pos);
280 }
281
282 SoSwitch* hitSwitch = new SoSwitch();
283 m_d->hgtdHitSwitch = hitSwitch;
284 hgtdGuideRootSwitch->addChild(hitSwitch);
285
286 auto addParticleCategory = [](SoSwitch* rootSwitch,
287 SoSwitch*& categorySwitch,
288 SoSwitch*& labelsSwitch,
289 SoVertexProperty* vertexProperty,
290 SoPointSet* pointSet,
292 const SbColor&
color,
293 const std::vector<TruthHitLabel>&
labels) {
294 categorySwitch = new SoSwitch();
295 rootSwitch->addChild(categorySwitch);
296
297 SoMaterial* hitMaterial = new SoMaterial();
298 hitMaterial->diffuseColor.setValue(
color);
299 categorySwitch->addChild(hitMaterial);
300 pointSet->numPoints=
count;
301 pointSet->vertexProperty.setValue(vertexProperty);
302 categorySwitch->addChild(pointSet);
303
304 labelsSwitch = new SoSwitch();
305 for (
const TruthHitLabel&
label : labels)
306 addHGTDLabel(labelsSwitch,
label);
307 categorySwitch->addChild(labelsSwitch);
308
309 pointSet->enableNotify(TRUE);
310 vertexProperty->enableNotify(TRUE);
311 };
312
313 addParticleCategory(hgtdGuideRootSwitch,
314 m_d->hgtdPrimaryParticleSwitch,
315 m_d->hgtdPrimaryParticleLabelsSwitch,
316 primaryHitVtxProperty,
317 primaryHitPointSet,
318 primaryHitCount,
320 primaryHitLabels);
321 addParticleCategory(hgtdGuideRootSwitch,
322 m_d->hgtdSecondaryParticleSwitch,
323 m_d->hgtdSecondaryParticleLabelsSwitch,
324 secondaryHitVtxProperty,
325 secondaryHitPointSet,
326 secondaryHitCount,
328 secondaryHitLabels);
329 addParticleCategory(hgtdGuideRootSwitch,
330 m_d->hgtdUnlinkedParticleSwitch,
331 m_d->hgtdUnlinkedParticleLabelsSwitch,
332 unlinkedHitVtxProperty,
333 unlinkedHitPointSet,
334 unlinkedHitCount,
336 unlinkedHitLabels);
337
338 SoVertexProperty* truthTrackVtxProperty = new SoVertexProperty();
339 SoLineSet* truthTrackLineSet = new SoLineSet();
340 truthTrackVtxProperty->enableNotify(FALSE);
341 truthTrackLineSet->enableNotify(FALSE);
342 unsigned int truthTrackVertexCount = 0;
343 unsigned int truthTrackCount = 0;
344 for (auto it = truthHitPoints.begin(); it != truthHitPoints.end(); ++it) {
345 std::vector<TruthHitPoint>& points =
it.value();
346 if (points.empty())
347 continue;
349 [](
const TruthHitPoint&
a,
const TruthHitPoint& b) { return a.time < b.time; });
350
351 const int verticesInTrack = points.size() == 1 ? 2 : static_cast<int>(points.size());
352 truthTrackLineSet->numVertices.set1Value(truthTrackCount++, verticesInTrack);
353 if (points.size()==1)
354 truthTrackVtxProperty->vertex.set1Value(truthTrackVertexCount++, 0.0, 0.0, 0.0);
355 for (const TruthHitPoint& point : points)
356 truthTrackVtxProperty->vertex.set1Value(truthTrackVertexCount++,
357 point.position.x(),
358 point.position.y(),
359 point.position.z());
360 }
361
362 SoSwitch* trackSwitch = new SoSwitch();
363 m_d->hgtdTruthTrackSwitch = trackSwitch;
364 hgtdGuideRootSwitch->addChild(trackSwitch);
365 if (truthTrackCount>0) {
366 SoSeparator* trackSep = new SoSeparator();
367 SoDrawStyle* trackDrawStyle = new SoDrawStyle();
368 trackDrawStyle->style.setValue(SoDrawStyle::LINES);
369 trackDrawStyle->lineWidth = 2;
370 trackSep->addChild(trackDrawStyle);
371 SoMaterial* trackMaterial = new SoMaterial();
373 trackSep->addChild(trackMaterial);
374 truthTrackLineSet->vertexProperty.setValue(truthTrackVtxProperty);
375 trackSep->addChild(truthTrackLineSet);
376 trackSwitch->addChild(trackSep);
377 truthTrackLineSet->enableNotify(TRUE);
378 truthTrackVtxProperty->enableNotify(TRUE);
379 }
380
381 m_d->updateHGTDGuideVisibility();
382#endif
383}
AtlasHitsVector< SiHit > SiHitCollection
HepMC::ConstGenParticlePtr cptr() const
Dereference.
void message(const QString &) const
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
static SbColor getSbColorFromRGB(const unsigned int r, const unsigned int g, const unsigned int b)
static bool hasHGTDGeometry()
static QString particleName(const int &pdgcode, bool &ok)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
std::string label(const std::string &format, int i)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.