Skip to content
Snippets Groups Projects
Commit f2f0f1b2 authored by FU Chengdong's avatar FU Chengdong
Browse files

edm4hep version control for ObjectID

parent 1938074c
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,15 @@ ...@@ -5,6 +5,15 @@
#include "edm4hep/TrackerHitCollection.h" #include "edm4hep/TrackerHitCollection.h"
#include <map> #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{ class Navigation{
public: public:
static Navigation* Instance(); static Navigation* Instance();
...@@ -17,9 +26,15 @@ class Navigation{ ...@@ -17,9 +26,15 @@ class Navigation{
void AddTrackerHitCollection(const edm4hep::TrackerHitCollection* col){m_hitColVec.push_back(col);}; void AddTrackerHitCollection(const edm4hep::TrackerHitCollection* col){m_hitColVec.push_back(col);};
void AddTrackerAssociationCollection(const edm4hep::MCRecoTrackerAssociationCollection* col){m_assColVec.push_back(col);}; void AddTrackerAssociationCollection(const edm4hep::MCRecoTrackerAssociationCollection* col){m_assColVec.push_back(col);};
#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2)
edm4hep::TrackerHit GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true); edm4hep::TrackerHit GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::ObjectID& id); 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);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col);
//static Navigation* m_fNavigation; //static Navigation* m_fNavigation;
private: private:
......
...@@ -25,7 +25,11 @@ void Navigation::Initialize(){ ...@@ -25,7 +25,11 @@ void Navigation::Initialize(){
m_trkHits.clear(); m_trkHits.clear();
} }
#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2)
edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, bool delete_by_caller){ 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; int id = obj_id.collectionID * 10000000 + obj_id.index;
if(!delete_by_caller){ if(!delete_by_caller){
if(m_trkHits.find(id)!=m_trkHits.end()) return m_trkHits[id]; if(m_trkHits.find(id)!=m_trkHits.end()) return m_trkHits[id];
...@@ -33,7 +37,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b ...@@ -33,7 +37,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
/* /*
for(int i=0;i<m_assColVec.size();i++){ for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[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; if(rec_id.collectionID!=id.collectionID)break;
else if(rec_id.index==id.index){ else if(rec_id.index==id.index){
m_trkHits.push_back(ass.getRec()); m_trkHits.push_back(ass.getRec());
...@@ -44,7 +48,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b ...@@ -44,7 +48,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
*/ */
for(int i=0;i<m_hitColVec.size();i++){ for(int i=0;i<m_hitColVec.size();i++){
for(auto hit : *m_hitColVec[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; if(this_id.collectionID!=obj_id.collectionID)break;
else if(this_id.index==obj_id.index){ else if(this_id.index==obj_id.index){
edm4hep::TrackerHit hit_copy = edm4hep::TrackerHit(hit); edm4hep::TrackerHit hit_copy = edm4hep::TrackerHit(hit);
...@@ -57,11 +61,15 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b ...@@ -57,11 +61,15 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
throw std::runtime_error("Not found TrackerHit"); throw std::runtime_error("Not found TrackerHit");
} }
#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2)
std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4hep::ObjectID& id){ 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; std::vector<edm4hep::SimTrackerHit> hits;
for(int i=0;i<m_assColVec.size();i++){ for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[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; if(this_id.collectionID!=id.collectionID)break;
else if(this_id.index==id.index) hits.push_back(ass.getSim()); else if(this_id.index==id.index) hits.push_back(ass.getSim());
} }
...@@ -79,3 +87,12 @@ std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4h ...@@ -79,3 +87,12 @@ std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4h
} }
return hits; 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% 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