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

WIP: Add the DriftChamberSensitiveDetector.

parent fba931eb
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ set(DetSimSD_srcs ...@@ -18,6 +18,7 @@ set(DetSimSD_srcs
src/CaloSensitiveDetector.cpp src/CaloSensitiveDetector.cpp
src/DriftChamberSensDetTool.cpp src/DriftChamberSensDetTool.cpp
src/DriftChamberSensitiveDetector.cpp
) )
gaudi_add_module(DetSimSD ${DetSimSD_srcs} gaudi_add_module(DetSimSD ${DetSimSD_srcs}
......
#include "DriftChamberSensitiveDetector.h"
#include "G4SDManager.hh"
DriftChamberSensitiveDetector::DriftChamberSensitiveDetector(const std::string& name,
dd4hep::Detector& description)
: DDG4SensitiveDetector(name, description),
m_hc(nullptr) {
const std::string& coll_name = m_sensitive.hitsCollection();
collectionName.insert(coll_name);
}
void
DriftChamberSensitiveDetector::Initialize(G4HCofThisEvent* HCE) {
const std::string& coll_name = collectionName[0];
m_hc = new HitCollection(GetName(), coll_name);
int HCID = -1;
if(HCID<0) HCID = G4SDManager::GetSDMpointer()->GetCollectionID(m_hc);
HCE->AddHitsCollection( HCID, m_hc );
}
G4bool
DriftChamberSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) {
// Refer to: DDG4/legacy/Geant4TrackerSD.cpp (note: there's bug in momentum calculation)
// DDCore/include/DD4hep/Objects.h (mean_direction and mean_length)
dd4hep::sim::Geant4StepHandler h(step);
dd4hep::Position prePos = h.prePos();
dd4hep::Position postPos = h.postPos();
dd4hep::Position direction = postPos - prePos;
dd4hep::Position position = mean_direction(prePos,postPos); // (pre+post)/2
double hit_len = direction.R();
HitContribution contrib = dd4hep::sim::Geant4Hit::extractContribution(step);
// Now, invokes the dE/dx simulator
double dedx = 0.0;
double de = hit_len * dedx;
// contrib.deposit = de; // if need the de from dedx simulator
// create a new hit
TrackerHit* hit = new TrackerHit(
h.track->GetTrackID(),
h.track->GetDefinition()->GetPDGEncoding(),
de, // not the Geant4's deposit energy. from dE/dx simulator
h.track->GetGlobalTime()
);
hit->cellID = getCellID(step);
hit->energyDeposit = de; // FIXME: also use the dedx
hit->position = position;
hit->momentum = (h.preMom() + h.postMom() )/2;
hit->length = hit_len;
m_hc->insert(hit);
return true;
}
void
DriftChamberSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) {
}
#ifndef DriftChamberSensitiveDetector_h
#define DriftChamberSensitiveDetector_h
/*
* DriftChamberSensitiveDetector is used in Drift Chamber with dE/dx simulator.
*
* 19 Sept. 2020, Tao Lin <lintao@ihep.ac.cn>
*/
#include "DetSimSD/DDG4SensitiveDetector.h"
class DriftChamberSensitiveDetector: public DDG4SensitiveDetector {
public:
typedef dd4hep::sim::Geant4TrackerHit TrackerHit;
typedef G4THitsCollection<TrackerHit> TrackerHitCollection;
public:
DriftChamberSensitiveDetector(const std::string& name, dd4hep::Detector& description);
public:
// Geant4 interface
virtual void Initialize(G4HCofThisEvent* HCE);
virtual G4bool ProcessHits(G4Step* step,G4TouchableHistory* history);
virtual void EndOfEvent(G4HCofThisEvent* HCE);
protected:
HitCollection* m_hc;
};
#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