Skip to content

Commit

Permalink
GateToRoot output with corr. for MultiRun
Browse files Browse the repository at this point in the history
  • Loading branch information
kochebina committed Aug 13, 2023
1 parent 68376f9 commit ab61ccb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
21 changes: 16 additions & 5 deletions source/digits_hits/include/GateToRoot.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ See LICENSE.md for further details

//OK GND 2022
#include "GateDigitizerMgr.hh"

#include "GateRunManager.hh"
/* PY Descourt 08/09/2009 */
#include "GateActions.hh"
#include "GateTrack.hh"
Expand Down Expand Up @@ -213,18 +213,29 @@ public:
GateDigitizerMgr* digitizerMgr = GateDigitizerMgr::GetInstance();

if (m_outputFlag) {
G4String treeName;

if( digitizerMgr->m_SDlist.size()==1 )
{

if(m_signlesCommands==0)
{
std::string tmp_str = m_collectionName.substr(0, m_collectionName.find("_"));
m_tree = new GateSingleTree(tmp_str);

treeName = m_collectionName.substr(0, m_collectionName.find("_"));

}
else
m_tree = new GateSingleTree(m_collectionName);
treeName = m_collectionName;
}
else
m_tree = new GateSingleTree(m_collectionName);
treeName = m_collectionName;

G4int runID=GateRunManager::GetRunManager()->GetCurrentRun()->GetRunID();
if(runID>0)
treeName = treeName+"_run"+std::to_string(runID);


m_tree = new GateSingleTree(treeName);

m_buffer.SetCCFlag(GetCCFlag());
m_tree->Init(m_buffer);
Expand Down
2 changes: 2 additions & 0 deletions source/digits_hits/src/GateOutputMgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ void GateOutputMgr::RecordEndOfRun(const G4Run* run)
if ( m_outputModules[iMod]->IsEnabled() )
m_outputModules[iMod]->RecordEndOfRun(run);
}
m_HCIDs.clear();

}
//----------------------------------------------------------------------------------

Expand Down
42 changes: 35 additions & 7 deletions source/digits_hits/src/GateToRoot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ComptonRayleighData &ComptonRayleighData::operator=(const ComptonRayleighData &a

//--------------------------------------------------------------------------
GateToRoot::GateToRoot(const G4String &name, GateOutputMgr *outputMgr, DigiMode digiMode)
: GateVOutputModule(name, outputMgr, digiMode), m_hitBuffers(0) , m_hfile(0), m_treesHit(0),
: GateVOutputModule(name, outputMgr, digiMode), m_hitBuffers(0), m_hfile(0), m_treesHit(0),
m_rootHitFlag(digiMode == kruntimeMode), m_rootNtupleFlag(true), m_saveRndmFlag(true),
m_fileName(" ") // All default output file from all output modules are set to " ".
// They are then checked in GateApplicationMgr::StartDAQ, using
Expand Down Expand Up @@ -249,23 +249,40 @@ void GateToRoot::BookBeginOfRun() {
GateDigitizerMgr* digitizerMgr = GateDigitizerMgr::GetInstance();
SetSDlistSize(digitizerMgr->m_SDlist.size() );


for (G4int i=0; i<GetSDlistSize();i++)
{
GateRootHitBuffer hitBuffer;
hitBuffer.SetCCFlag(GetRootCCFlag());
m_hitBuffers.push_back(hitBuffer);
}



for (size_t i=0; i< GetSDlistSize();i++)
{
GateHitTree *treeHit;

G4String treeName ;

if (digitizerMgr->m_SDlist.size() ==1 ) // keep the old name "Hits" if there is only one collection
treeHit = new GateHitTree("Hits");
{
treeName = "Hits";
}
else
treeHit = new GateHitTree("Hits_"+digitizerMgr->m_SDlist[i]->GetName());
treeName = "Hits_"+digitizerMgr->m_SDlist[i]->GetName();

G4int runID=GateRunManager::GetRunManager()->GetCurrentRun()->GetRunID();
if(runID>0)
treeName = treeName+"_run"+std::to_string(runID);

treeHit = new GateHitTree(treeName);

treeHit->Init(m_hitBuffers[i]);
m_treesHit.push_back(treeHit);
}


}

// v. cuplov - optical photons
for (size_t i=0; i< digitizerMgr->m_SDlist.size();i++)
Expand Down Expand Up @@ -335,6 +352,7 @@ void GateToRoot::RecordBeginOfAcquisition() {
if (nVerboseLevel > 1)
G4cout << " GateToRoot::RecordBeginOfAcquisition() Tracking Mode " << int(theMode) << Gateendl;


// PY. Descourt 11/12/2008
// NORMAL OR DETECTOR MODE
if ((theMode == TrackingMode::kBoth) || (theMode == TrackingMode::kDetector)) {
Expand Down Expand Up @@ -367,6 +385,7 @@ void GateToRoot::RecordBeginOfAcquisition() {
m_hfile = new TFile((m_fileName + ".root").c_str(), "RECREATE", "ROOT file with histograms");
// v. cuplov


break;
case kofflineMode:
// In DigiGate mode, we first check that the file does not exist. If it does, we abort as we want to make sure the ROOT file is not overwritten by accident
Expand Down Expand Up @@ -411,6 +430,9 @@ void GateToRoot::RecordBeginOfAcquisition() {
}
//! We book histos and ntuples only once per acquisition
BookBeginOfAquisition();
//BookBeginOfRun();




return;
Expand Down Expand Up @@ -633,6 +655,7 @@ void GateToRoot::RecordBeginOfRun(const G4Run *) {
}
}*/


if (nVerboseLevel > 2)
G4cout << "GateToRoot::RecordBeginOfRun\n";
BookBeginOfRun();
Expand All @@ -655,7 +678,8 @@ void GateToRoot::RecordEndOfRun(const G4Run *) {

nbPrimaries -= 1.; // Number of primaries increase too much at each end of run !


m_hitBuffers.clear();
m_treesHit.clear();
}
//--------------------------------------------------------------------------

Expand Down Expand Up @@ -765,6 +789,9 @@ void GateToRoot::RecordEndOfEvent(const G4Event *event) {
//OK GND 2022
std::vector<GateHitsCollection*> CHC_vector = GetOutputMgr()->GetHitCollections();


G4int runID=GateRunManager::GetRunManager()->GetCurrentRun()->GetRunID();

for (size_t i=0; i<CHC_vector.size();i++ )//HC_vector.size()
{
GateHitsCollection* CHC = CHC_vector[i];
Expand All @@ -787,13 +814,14 @@ void GateToRoot::RecordEndOfEvent(const G4Event *event) {
<< "> Particls PDG code : " << PDGEncoding << Gateendl;

if (aHit->GoodForAnalysis()) {
m_hitBuffers[i].Fill(aHit);
m_hitBuffers[i].Fill(aHit);

if (nVerboseLevel > 1)
G4cout << "GateToRoot::RecordEndOfEvent : m_treeHit->Fill\n";


if (m_rootHitFlag) m_treesHit[i]->Fill();


}
}

Expand Down

0 comments on commit ab61ccb

Please sign in to comment.