From a75e58eb71c845154af8739dcbfc987184ed35eb Mon Sep 17 00:00:00 2001 From: pbutti Date: Mon, 22 Apr 2024 14:55:16 +0200 Subject: [PATCH 1/2] Add momentum info to the MC Tracker Hit --- event/include/MCTrackerHit.h | 18 ++++++++++++++---- event/src/MCTrackerHit.cxx | 19 +++++++++++++++++++ processors/src/MCTrackerHitProcessor.cxx | 10 ++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/event/include/MCTrackerHit.h b/event/include/MCTrackerHit.h index f673d96a1..c06288186 100644 --- a/event/include/MCTrackerHit.h +++ b/event/include/MCTrackerHit.h @@ -37,10 +37,14 @@ class MCTrackerHit : public TObject { * * @param position The hit position. */ - void setPosition(const double* position, bool rotate = false); + void setPosition(const double* position, bool rotate = false); + + /** @return The hit position. */ + std::vector getPosition() const { return {x_, y_, z_}; }; - /** @return The hit position. */ - std::vector getPosition() const { return {x_, y_, z_}; }; + + void setMomentum(const double* momentum, bool rotate = false); + std::vector getMomentum() const { return {px_, py_, pz_}; }; /** @return the global X coordinate of the hit */ double getGlobalX() const {return x_;} @@ -88,7 +92,8 @@ class MCTrackerHit : public TObject { //** @return the pdg id of particle that made the hit */ int getPDG() const {return pdg_;}; - ClassDef(MCTrackerHit, 1); + + ClassDef(MCTrackerHit, 1); private: @@ -101,6 +106,11 @@ class MCTrackerHit : public TObject { /** The x position of the hit. */ double z_{-999}; + /** The truth momentum of the hit. Only MC */ + double px_{-999}; + double py_{-999}; + double pz_{-999}; + /** The hit time. */ double time_{-999}; diff --git a/event/src/MCTrackerHit.cxx b/event/src/MCTrackerHit.cxx index 2726a4d2f..f4757a19d 100644 --- a/event/src/MCTrackerHit.cxx +++ b/event/src/MCTrackerHit.cxx @@ -20,6 +20,25 @@ void MCTrackerHit::Clear(Option_t* /* options */) { TObject::Clear(); } +void MCTrackerHit::setMomentum(const double* momentum, bool rotate) { + + //svt angle: it's already with minus sign. + float svtAngle = 30.5e-3; + //Rotate the the input position automatically to match with the SVT tracker system + if (rotate) + { + //x_ = position[1]; + py_ = momentum[2]; + pz_ = momentum[1] * sin(svtAngle) + momentum[0]*cos(svtAngle); + px_ = momentum[1] * cos(svtAngle) - momentum[0]*sin(svtAngle); + } + else { + px_ = momentum[0]; + py_ = momentum[1]; + pz_ = momentum[2]; + } +} + void MCTrackerHit::setPosition(const double* position, bool rotate) { //svt angle: it's already with minus sign. diff --git a/processors/src/MCTrackerHitProcessor.cxx b/processors/src/MCTrackerHitProcessor.cxx index ff5951814..7916ebca8 100644 --- a/processors/src/MCTrackerHitProcessor.cxx +++ b/processors/src/MCTrackerHitProcessor.cxx @@ -78,7 +78,13 @@ bool MCTrackerHitProcessor::process(IEvent* ievent) { hitPos[2] = lcio_mcTracker_hit->getPosition()[2]; mc_tracker_hit->setPosition(hitPos); - // Set the energy deposit of the hit + double hitMom[3]; + hitMom[0] = lcio_mcTracker_hit->getMomentum()[0]; + hitMom[1] = lcio_mcTracker_hit->getMomentum()[1]; + hitMom[2] = lcio_mcTracker_hit->getMomentum()[2]; + mc_tracker_hit->setMomentum(hitMom); + + // Set the energy deposit of the hit mc_tracker_hit->setEdep(lcio_mcTracker_hit->getEDep()); // Set the pdg of particle generating the hit @@ -90,7 +96,7 @@ bool MCTrackerHitProcessor::process(IEvent* ievent) { //Push hit onto vector trackerhits_.push_back(mc_tracker_hit); - + } return true; From d67e8d4846ef363e7d34bc2db3b439d8c63e1636 Mon Sep 17 00:00:00 2001 From: pbutti Date: Mon, 22 Apr 2024 17:03:07 +0200 Subject: [PATCH 2/2] setMomentum gets LCIO::getMomentum in input --- event/include/MCTrackerHit.h | 13 ++++++------- event/src/MCTrackerHit.cxx | 2 +- processors/src/MCTrackerHitProcessor.cxx | 18 ++++-------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/event/include/MCTrackerHit.h b/event/include/MCTrackerHit.h index c06288186..03bd8e5d8 100644 --- a/event/include/MCTrackerHit.h +++ b/event/include/MCTrackerHit.h @@ -41,10 +41,9 @@ class MCTrackerHit : public TObject { /** @return The hit position. */ std::vector getPosition() const { return {x_, y_, z_}; }; - - void setMomentum(const double* momentum, bool rotate = false); - std::vector getMomentum() const { return {px_, py_, pz_}; }; + void setMomentum(const float* momentum, bool rotate = false); + std::vector getMomentum() const { return {px_, py_, pz_}; }; /** @return the global X coordinate of the hit */ double getGlobalX() const {return x_;} @@ -106,10 +105,10 @@ class MCTrackerHit : public TObject { /** The x position of the hit. */ double z_{-999}; - /** The truth momentum of the hit. Only MC */ - double px_{-999}; - double py_{-999}; - double pz_{-999}; + /** The truth momentum of the hit. Only MC */ + float px_{-999}; + float py_{-999}; + float pz_{-999}; /** The hit time. */ double time_{-999}; diff --git a/event/src/MCTrackerHit.cxx b/event/src/MCTrackerHit.cxx index f4757a19d..d6a158481 100644 --- a/event/src/MCTrackerHit.cxx +++ b/event/src/MCTrackerHit.cxx @@ -20,7 +20,7 @@ void MCTrackerHit::Clear(Option_t* /* options */) { TObject::Clear(); } -void MCTrackerHit::setMomentum(const double* momentum, bool rotate) { +void MCTrackerHit::setMomentum(const float* momentum, bool rotate) { //svt angle: it's already with minus sign. float svtAngle = 30.5e-3; diff --git a/processors/src/MCTrackerHitProcessor.cxx b/processors/src/MCTrackerHitProcessor.cxx index 7916ebca8..0a2cbd9bf 100644 --- a/processors/src/MCTrackerHitProcessor.cxx +++ b/processors/src/MCTrackerHitProcessor.cxx @@ -71,22 +71,12 @@ bool MCTrackerHitProcessor::process(IEvent* ievent) { mc_tracker_hit->setLayer(decoder["layer"]); mc_tracker_hit->setModule(decoder["module"]); - // Set the position of the hit - double hitPos[3]; - hitPos[0] = lcio_mcTracker_hit->getPosition()[0]; - hitPos[1] = lcio_mcTracker_hit->getPosition()[1]; - hitPos[2] = lcio_mcTracker_hit->getPosition()[2]; - mc_tracker_hit->setPosition(hitPos); - - double hitMom[3]; - hitMom[0] = lcio_mcTracker_hit->getMomentum()[0]; - hitMom[1] = lcio_mcTracker_hit->getMomentum()[1]; - hitMom[2] = lcio_mcTracker_hit->getMomentum()[2]; - mc_tracker_hit->setMomentum(hitMom); - + mc_tracker_hit->setPosition(lcio_mcTracker_hit->getPosition()); + mc_tracker_hit->setMomentum(lcio_mcTracker_hit->getMomentum()); + // Set the energy deposit of the hit mc_tracker_hit->setEdep(lcio_mcTracker_hit->getEDep()); - + // Set the pdg of particle generating the hit if(lcio_mcTracker_hit->getMCParticle()) mc_tracker_hit->setPDG(lcio_mcTracker_hit->getMCParticle()->getPDG());