From 748fb491c5eee9d4fb3c86ed7a88d5118253c231 Mon Sep 17 00:00:00 2001 From: Lorenzo Pezzotti Date: Tue, 7 Apr 2026 21:30:53 +0200 Subject: [PATCH] Add PDGID in calo hit contributions And make hands-on 6 only the root macro part. --- DD4hepTutorials/scripts/readEdm4hep.cc | 4 ++++ .../sdaction/src/simplecaloSDAction.cpp | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/DD4hepTutorials/scripts/readEdm4hep.cc b/DD4hepTutorials/scripts/readEdm4hep.cc index ade65da..a6b8ed1 100644 --- a/DD4hepTutorials/scripts/readEdm4hep.cc +++ b/DD4hepTutorials/scripts/readEdm4hep.cc @@ -17,6 +17,10 @@ * limitations under the License. */ +// This is Hands-on 6, a more complex analysis for simplecalo2 +// Follow the code and complete the six questions along the code. +// Solutions and at the end of this file. + // load required libraries for ROOT interpreter R__LOAD_LIBRARY(libDDCore.so) R__LOAD_LIBRARY(libpodio.so) diff --git a/DD4hepTutorials/sdaction/src/simplecaloSDAction.cpp b/DD4hepTutorials/sdaction/src/simplecaloSDAction.cpp index a9040d7..838e925 100644 --- a/DD4hepTutorials/sdaction/src/simplecaloSDAction.cpp +++ b/DD4hepTutorials/sdaction/src/simplecaloSDAction.cpp @@ -139,32 +139,36 @@ namespace sim { hit->position = HitCellPos; // this should be assigned only once hit->energyDeposit = aStep->GetTotalEnergyDeposit(); - // Hands-on 6: add calo hit contributions + // Add calo hit contributions // // Crete the first contribution associated to this hit - /*Geant4Calorimeter::Hit::Contribution contrib; + Geant4Calorimeter::Hit::Contribution contrib; contrib.trackID = aStep->GetTrack()->GetTrackID(); + contrib.pdgID = aStep->GetTrack()->GetParticleDefinition()->GetPDGEncoding(); contrib.deposit = aStep->GetTotalEnergyDeposit(); contrib.time = aStep->GetPreStepPoint()->GetGlobalTime(); - contrib.x = HitCellPos.x(); contrib.y = HitCellPos.y(); contrib.z = HitCellPos.z(); - hit->truth.emplace_back(contrib);*/ - // end on Hands-on 6 + contrib.x = HitCellPos.x(); + contrib.y = HitCellPos.y(); + contrib.z = HitCellPos.z(); + hit->truth.emplace_back(contrib); coll->add(VolID, hit); // add the hit to the hit collection } else { // if the hit exists already, increment its fields hit->energyDeposit += aStep->GetTotalEnergyDeposit(); - // Hands-on 6: add calo hit contributions + // Add calo hit contributions // // Add a new contribution associated to this hit - /*Geant4Calorimeter::Hit::Contribution contrib; + Geant4Calorimeter::Hit::Contribution contrib; contrib.trackID = aStep->GetTrack()->GetTrackID(); + contrib.pdgID = aStep->GetTrack()->GetParticleDefinition()->GetPDGEncoding(); contrib.deposit = aStep->GetTotalEnergyDeposit(); contrib.time = aStep->GetPreStepPoint()->GetGlobalTime(); Position HitCellPos(CellPos.x() / 10, CellPos.y() / 10, CellPos.z() / 10); - contrib.x = HitCellPos.x(); contrib.y = HitCellPos.y(); contrib.z = HitCellPos.z(); - hit->truth.emplace_back(contrib);*/ - // end on Hands-on 6 + contrib.x = HitCellPos.x(); + contrib.y = HitCellPos.y(); + contrib.z = HitCellPos.z(); + hit->truth.emplace_back(contrib); } return true;