Skip to content
Snippets Groups Projects
Commit 69625043 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

WIP: bookkeeping of the current track and its primary track.

parent 21c86818
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,10 @@ Edm4hepWriterAnaElemTool::EndOfRunAction(const G4Run*) { ...@@ -26,6 +26,10 @@ Edm4hepWriterAnaElemTool::EndOfRunAction(const G4Run*) {
void void
Edm4hepWriterAnaElemTool::BeginOfEventAction(const G4Event* anEvent) { Edm4hepWriterAnaElemTool::BeginOfEventAction(const G4Event* anEvent) {
msg() << "Event " << anEvent->GetEventID() << endmsg; msg() << "Event " << anEvent->GetEventID() << endmsg;
// reset
m_track2primary.clear();
} }
void void
...@@ -192,7 +196,15 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) { ...@@ -192,7 +196,15 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) {
edm_calo_contrib.setEnergy(c.deposit/CLHEP::GeV); edm_calo_contrib.setEnergy(c.deposit/CLHEP::GeV);
edm_calo_contrib.setTime(c.time/CLHEP::ns); edm_calo_contrib.setTime(c.time/CLHEP::ns);
edm_calo_contrib.setStepPosition(edm4hep::Vector3f(pos)); edm_calo_contrib.setStepPosition(edm4hep::Vector3f(pos));
edm_calo_contrib.setParticle(mcCol->at(0)); // todo
// from the track id, get the primary track
int pritrkid = m_track2primary[c.trackID];
if (pritrkid<=0) {
error() << "Failed to find the primary track for trackID #" << c.trackID << endmsg;
pritrkid = 1;
}
edm_calo_contrib.setParticle(mcCol->at(pritrkid-1)); // todo
edm_calo_hit.addToContributions(edm_calo_contrib); edm_calo_hit.addToContributions(edm_calo_contrib);
} }
} }
...@@ -214,8 +226,26 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) { ...@@ -214,8 +226,26 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) {
} }
void void
Edm4hepWriterAnaElemTool::PreUserTrackingAction(const G4Track*) { Edm4hepWriterAnaElemTool::PreUserTrackingAction(const G4Track* track) {
int curtrkid = track->GetTrackID();
int curparid = track->GetParentID();
int pritrkid = curparid;
// try to find the primary track id from the parent track id.
if (curparid) {
auto it = m_track2primary.find(curparid);
if (it == m_track2primary.end()) {
error() << "Failed to find primary track for track id " << curparid << endmsg;
} else {
pritrkid = it->second;
}
} else {
// curparid is 0, it is primary
pritrkid = curtrkid;
}
m_track2primary[curtrkid] = pritrkid;
} }
void void
......
#ifndef Edm4hepWriterAnaElemTool_h #ifndef Edm4hepWriterAnaElemTool_h
#define Edm4hepWriterAnaElemTool_h #define Edm4hepWriterAnaElemTool_h
#include <map>
#include "GaudiKernel/AlgTool.h" #include "GaudiKernel/AlgTool.h"
#include "FWCore/DataHandle.h" #include "FWCore/DataHandle.h"
#include "DetSimInterface/IAnaElemTool.h" #include "DetSimInterface/IAnaElemTool.h"
...@@ -62,6 +64,20 @@ private: ...@@ -62,6 +64,20 @@ private:
DataHandle<edm4hep::SimTrackerHitCollection> m_SETCol{"SETCollection", DataHandle<edm4hep::SimTrackerHitCollection> m_SETCol{"SETCollection",
Gaudi::DataHandle::Writer, this}; Gaudi::DataHandle::Writer, this};
private:
// in order to associate the hit contribution with the primary track,
// we have a bookkeeping of every track.
// The primary track will assign the same key/value.
// Following is an example:
// 1 -> 1,
// 2 -> 2,
// 3 -> 1,
// Now, if parent of trk #4 is trk #3, using the mapping {3->1} could
// locate the primary trk #1.
std::map<int, int> m_track2primary;
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment