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

change to control merge/unmerge hits of same cell by map option

parent 8b7954ef
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
typedef G4THitsCollection<CalorimeterHit> CaloHitCollection; typedef G4THitsCollection<CalorimeterHit> CaloHitCollection;
public: public:
CaloSensitiveDetector(const std::string& name, dd4hep::Detector& description); CaloSensitiveDetector(const std::string& name, dd4hep::Detector& description, bool unmerge=true);
public: public:
// Geant4 interface // Geant4 interface
...@@ -31,6 +31,7 @@ protected: ...@@ -31,6 +31,7 @@ protected:
HitCollection* m_hc; HitCollection* m_hc;
std::map<unsigned long, CalorimeterHit*> m_hitMap; std::map<unsigned long, CalorimeterHit*> m_hitMap;
bool m_unmerge;
}; };
......
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
#include <algorithm> #include <algorithm>
CaloSensitiveDetector::CaloSensitiveDetector(const std::string& name, dd4hep::Detector& description) CaloSensitiveDetector::CaloSensitiveDetector(const std::string& name, dd4hep::Detector& description, bool unmerge)
: DDG4SensitiveDetector(name, description), : DDG4SensitiveDetector(name, description),
m_hc(nullptr) { m_hc(nullptr),
m_unmerge(unmerge){
const std::string& coll_name = m_sensitive.hitsCollection(); const std::string& coll_name = m_sensitive.hitsCollection();
collectionName.insert(coll_name); collectionName.insert(coll_name);
} }
...@@ -38,7 +39,7 @@ CaloSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) { ...@@ -38,7 +39,7 @@ CaloSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) {
unsigned long id = getCellID( step ); unsigned long id = getCellID( step );
//std::cout << name << " " << id << std::endl; //std::cout << name << " " << id << std::endl;
CalorimeterHit* hit=nullptr; CalorimeterHit* hit=nullptr;
if(name.find("Merge")==-1&&name.find("merge")==-1) find(m_hc,dd4hep::sim::HitPositionCompare<CalorimeterHit>(pos)); if(m_unmerge) hit=find(m_hc,dd4hep::sim::HitPositionCompare<CalorimeterHit>(pos));
else{ else{
std::map<unsigned long, CalorimeterHit*>::iterator it = m_hitMap.find(id); std::map<unsigned long, CalorimeterHit*>::iterator it = m_hitMap.find(id);
if(it!=m_hitMap.end()) hit = it->second; if(it!=m_hitMap.end()) hit = it->second;
...@@ -46,9 +47,9 @@ CaloSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) { ...@@ -46,9 +47,9 @@ CaloSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) {
// G4cout << "----------- Geant4GenericSD<Calorimeter>::buildHits : position : " << pos << G4endl; // G4cout << "----------- Geant4GenericSD<Calorimeter>::buildHits : position : " << pos << G4endl;
if ( !hit ) { if ( !hit ) {
hit = new CalorimeterHit(pos); hit = new CalorimeterHit(pos);
hit->cellID = getCellID( step ); hit->cellID = id; //getCellID( step );
m_hc->insert(hit); m_hc->insert(hit);
if(name.find("Merge")!=-1||name.find("merge")!=-1) m_hitMap[id] = hit; if(!m_unmerge) m_hitMap[id] = hit;
} }
hit->truth.push_back(contrib); hit->truth.push_back(contrib);
hit->energyDeposit += contrib.deposit; hit->energyDeposit += contrib.deposit;
......
...@@ -35,7 +35,15 @@ CalorimeterSensDetTool::createSD(const std::string& name) { ...@@ -35,7 +35,15 @@ CalorimeterSensDetTool::createSD(const std::string& name) {
dd4hep::Detector* dd4hep_geo = m_geosvc->lcdd(); dd4hep::Detector* dd4hep_geo = m_geosvc->lcdd();
G4VSensitiveDetector* sd = new CaloSensitiveDetector(name, *dd4hep_geo); bool flagUnmerge = false;
for(auto cal_name : m_unmergeCals){
if(cal_name==name){
flagUnmerge = true;
break;
}
}
G4VSensitiveDetector* sd = new CaloSensitiveDetector(name, *dd4hep_geo, flagUnmerge);
debug() << name << " set to merge true/false = " << !flagUnmerge << endmsg;
return sd; return sd;
} }
......
...@@ -29,6 +29,7 @@ private: ...@@ -29,6 +29,7 @@ private:
// in order to initialize SD, we need to get the lcdd() // in order to initialize SD, we need to get the lcdd()
SmartIF<IGeomSvc> m_geosvc; SmartIF<IGeomSvc> m_geosvc;
Gaudi::Property<std::vector<std::string> > m_unmergeCals{this, "UnmergedCalNames", {}};
}; };
#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