Skip to content

Commit

Permalink
HitTupleAction: use Data* because that does not segfault in the test …
Browse files Browse the repository at this point in the history
…when filling the tree
  • Loading branch information
andresailer committed Dec 10, 2024
1 parent 5a4c7c1 commit 721ccbd
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions examples/DDG4/src/HitTupleAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace myanalysis {
/// We want to write a separate branch for all deposits of one container(sub-detector)
typedef std::pair<double, std::vector<double> > Data;
/// The intermediate storage of the hit deposits to be written to ROOT
std::map<std::string, std::pair<TBranch*, Data> > m_deposits;
std::map<std::string, std::pair<TBranch*, Data*> > m_deposits;

public:
/// Standard constructor
Expand Down Expand Up @@ -162,13 +162,13 @@ void myanalysis::HitTupleAction::end(const G4Event* event) {
// Seperate loop. We need fixed addresses when creating the branches
for(const auto& c : m_containers) {
m_deposits[c].first = 0;
m_deposits[c].second.first = 0e0;
m_deposits[c].second.second.clear();
m_deposits[c].second = new Data();
m_deposits[c].second->first = 0e0;
m_deposits[c].second->second.clear();
}
for(const auto& c : m_containers) {
std::pair<TBranch*, Data>& e = m_deposits[c];
TClass* cl = gROOT->GetClass(typeid(Data));
e.first = m_outTree->Branch(c.c_str(), cl->GetName(), (void*)0);
std::pair<TBranch*, Data*>& e = m_deposits[c];
e.first = m_outTree->Branch(c.c_str(), &e.second);
e.first->SetAutoDelete(false);
printout(ALWAYS,"HitTupleAction","+++ Prepare hit branch %s in root file.",c.c_str());
}
Expand All @@ -186,13 +186,12 @@ void myanalysis::HitTupleAction::end(const G4Event* event) {
if ( find(m_containers.begin(),m_containers.end(),nam) != m_containers.end() ) {
Geant4HitCollection* coll = dynamic_cast<Geant4HitCollection*>(hc);
if ( coll ) {
std::pair<TBranch*, Data>& e = m_deposits[nam];
std::pair<TBranch*, Data*>& e = m_deposits[nam];
size_t nhits = coll->GetSize();
Data* d = &e.second;
Data* d = e.second;
d->first = 0e0;
d->second.clear();

e.second.first = 0e0;
e.second.second.clear();
e.first->SetAddress(&d);
for ( size_t j=0; j<nhits; ++j ) {
double dep = 0e0;
Geant4HitData* h = coll->hit(j);
Expand All @@ -208,8 +207,8 @@ void myanalysis::HitTupleAction::end(const G4Event* event) {
continue;
}
if ( dep > 0 ) {
e.second.first += dep;
e.second.second.push_back(dep);
d->first += dep;
d->second.push_back(dep);
}
}
}
Expand Down

0 comments on commit 721ccbd

Please sign in to comment.