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

add navagation help to get data from collection

parent d828193c
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ find_package(EDM4HEP REQUIRED) ...@@ -4,7 +4,7 @@ find_package(EDM4HEP REQUIRED)
gaudi_depends_on_subdirs() gaudi_depends_on_subdirs()
set(DataHelperLib_srcs src/*.cc) set(DataHelperLib_srcs src/*.cc src/*.cpp)
#gaudi_install_headers(DataHelper) #gaudi_install_headers(DataHelper)
......
#ifndef Navagation_h
#define Navagation_h
//#include "FWCore/DataHandle.h"
//#include "podio/CollectionBase.h"
#include "edm4hep/MCRecoTrackerAssociationCollection.h"
#include "edm4hep/TrackerHitCollection.h"
#include <map>
class Navagation{
public:
static Navagation* Instance();
Navagation();
~Navagation();
void Initialize();
//void AddDataHandle(DataHandle* hdl){if(hdl)m_hdlVec.push_back(hdl);};
void AddTrackerHitCollection(const edm4hep::TrackerHitCollection* col){m_hitColVec.push_back(col);};
void AddTrackerAssociationCollection(const edm4hep::MCRecoTrackerAssociationCollection* col){m_assColVec.push_back(col);};
edm4hep::TrackerHit* GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true);
std::vector<edm4hep::ConstSimTrackerHit> GetRelatedTrackerHit(const edm4hep::ObjectID& id);
std::vector<edm4hep::ConstSimTrackerHit> GetRelatedTrackerHit(const edm4hep::TrackerHit& hit);
//static Navagation* m_fNavagation;
private:
static Navagation* m_fNavagation;
//DataHandle<edm4hep::MCRecoTrackerAssociationCollection> _inHitAssColHdl{"FTDStripTrackerHitsAssociation", Gaudi::DataHandle::Reader, this};
std::vector<const edm4hep::TrackerHitCollection*> m_hitColVec;
std::vector<const edm4hep::MCRecoTrackerAssociationCollection*> m_assColVec;
std::map<int, edm4hep::TrackerHit*> m_trkHits;
};
#endif
#include "DataHelper/Navagation.h"
#include "edm4hep/SimTrackerHit.h"
#include "edm4hep/TrackerHit.h"
Navagation* Navagation::m_fNavagation = nullptr;
Navagation* Navagation::Instance(){
if(!m_fNavagation) m_fNavagation = new Navagation();
return m_fNavagation;
}
Navagation::Navagation(){
}
Navagation::~Navagation(){
}
void Navagation::Initialize(){
m_hitColVec.clear();
m_assColVec.clear();
for(std::map<int, edm4hep::TrackerHit*>::iterator it=m_trkHits.begin();it!=m_trkHits.end();it++){
delete it->second;
}
m_trkHits.clear();
}
edm4hep::TrackerHit* Navagation::GetTrackerHit(const edm4hep::ObjectID& obj_id, bool delete_by_caller){
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();
if(rec_id.collectionID!=id.collectionID)break;
else if(rec_id.index==id.index){
m_trkHits.push_back(ass.getRec());
return &(m_trkHits.back());
}
}
}
*/
for(int i=0;i<m_hitColVec.size();i++){
for(auto hit : *m_hitColVec[i]){
edm4hep::ObjectID this_id = hit.getObjectID();
if(this_id.collectionID!=obj_id.collectionID)break;
else if(this_id.index==obj_id.index){
edm4hep::TrackerHit* hit_copy = new edm4hep::TrackerHit(hit);
if(!delete_by_caller) m_trkHits[id] = hit_copy;
return hit_copy;//&(m_trkHits[id]);
}
}
}
throw std::runtime_error("Not found TrackerHit");
}
std::vector<edm4hep::ConstSimTrackerHit> Navagation::GetRelatedTrackerHit(const edm4hep::ObjectID& id){
std::vector<edm4hep::ConstSimTrackerHit> hits;
for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[i]){
edm4hep::ObjectID this_id = ass.getRec().getObjectID();
if(this_id.collectionID!=id.collectionID)break;
else if(this_id.index==id.index) hits.push_back(ass.getSim());
}
}
return hits;
}
std::vector<edm4hep::ConstSimTrackerHit> Navagation::GetRelatedTrackerHit(const edm4hep::TrackerHit& hit){
std::vector<edm4hep::ConstSimTrackerHit> hits;
for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[i]){
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