Skip to content

Commit

Permalink
Merge pull request #262 from fucd/update-id
Browse files Browse the repository at this point in the history
edm4hep version control for ObjectID
  • Loading branch information
mirguest authored Feb 22, 2024
2 parents 1938074 + 6630fea commit 23b8021
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Utilities/DataHelper/include/DataHelper/Navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
#include "edm4hep/TrackerHitCollection.h"
#include <map>

#if __has_include("edm4hep/EDM4hepVersion.h")
#include "edm4hep/EDM4hepVersion.h"
#else
// Copy the necessary parts from the header above to make whatever we need to work here
#define EDM4HEP_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch)))
// v00-09 is the last version without the capitalization change of the track vector members
#define EDM4HEP_BUILD_VERSION EDM4HEP_VERSION(0, 9, 0)
#endif

class Navigation{
public:
static Navigation* Instance();
Expand All @@ -17,9 +26,15 @@ class Navigation{
void AddTrackerHitCollection(const edm4hep::TrackerHitCollection* col){m_hitColVec.push_back(col);};
void AddTrackerAssociationCollection(const edm4hep::MCRecoTrackerAssociationCollection* col){m_assColVec.push_back(col);};

#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4)
edm4hep::TrackerHit GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::ObjectID& id);
#else
edm4hep::TrackerHit GetTrackerHit(const podio::ObjectID& id, bool delete_by_caller=true);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const podio::ObjectID& id);
#endif
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::TrackerHit& hit);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col);

//static Navigation* m_fNavigation;
private:
Expand Down
23 changes: 20 additions & 3 deletions Utilities/DataHelper/src/Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ void Navigation::Initialize(){
m_trkHits.clear();
}

#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4)
edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, bool delete_by_caller){
#else
edm4hep::TrackerHit Navigation::GetTrackerHit(const podio::ObjectID& obj_id, bool delete_by_caller){
#endif
int id = obj_id.collectionID * 10000000 + obj_id.index;
if(!delete_by_caller){
if(m_trkHits.find(id)!=m_trkHits.end()) return m_trkHits[id];
}
/*
for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[i]){
edm4hep::ObjectID rec_id = ass.getRec().getObjectID();
auto rec_id = ass.getRec().getObjectID();
if(rec_id.collectionID!=id.collectionID)break;
else if(rec_id.index==id.index){
m_trkHits.push_back(ass.getRec());
Expand All @@ -44,7 +48,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
*/
for(int i=0;i<m_hitColVec.size();i++){
for(auto hit : *m_hitColVec[i]){
edm4hep::ObjectID this_id = hit.getObjectID();
auto this_id = hit.getObjectID();
if(this_id.collectionID!=obj_id.collectionID)break;
else if(this_id.index==obj_id.index){
edm4hep::TrackerHit hit_copy = edm4hep::TrackerHit(hit);
Expand All @@ -57,11 +61,15 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
throw std::runtime_error("Not found TrackerHit");
}

#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4)
std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4hep::ObjectID& id){
#else
std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const podio::ObjectID& id){
#endif
std::vector<edm4hep::SimTrackerHit> hits;
for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[i]){
edm4hep::ObjectID this_id = ass.getRec().getObjectID();
auto this_id = ass.getRec().getObjectID();
if(this_id.collectionID!=id.collectionID)break;
else if(this_id.index==id.index) hits.push_back(ass.getSim());
}
Expand All @@ -79,3 +87,12 @@ std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4h
}
return hits;
}

std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col){
std::vector<edm4hep::SimTrackerHit> hits;
for(auto ass : *col){
if(ass.getRec().getObjectID().collectionID != hit.getObjectID().collectionID) break;
else if(ass.getRec()==hit) hits.push_back(ass.getSim());
}
return hits;
}

0 comments on commit 23b8021

Please sign in to comment.