Filling std::vector to ntuple in the eventaction class?

Hellow everyone,

I have a ntuple column to store the vectors containing energy deposited in different detectors for each event. (Quite similar to basic Example B5).

If I am not wrong, in Example B5, the vector filling (rather referencing) is done in the runactionclass,

analysisManager                                   // column Id = 6
      ->CreateNtupleDColumn("ECEnergyVector", fEventAction->GetEmCalEdep()); 

is it possible to achieve this in the eventaction class where the other nptuples are getting filled, like copying the above ln in EndofEvent()?

runaction.cc
#include "runaction.hh"

runaction::runaction(eventaction *eventAction){}
runaction::~runaction(){}

void runaction::BeginOfRunAction(const G4Run* run){
    G4AnalysisManager*man = G4AnalysisManager::Instance();
    G4int RunID = run->GetRunID();
    man->OpenFile("output.root");
    
    man->CreateNtupleDColumn("DetEnergyVector");
    man->FinishNtuple(0);
}
void runaction::EndOfRunAction(const G4Run*){
    G4AnalysisManager*man = G4AnalysisManager::Instance();
    man->Write();
    man->CloseFile();
}

Thanks a lot !

Hello,

The vector ntuple column is filled with the AddNtupleRow call, which happens in example B5 in EventAction.

The vector ntuple column is created with a reference to the vector, so when the vector is filled in the event action, its content is directly available to ntuple for storing the data.

The code

man->CreateNtupleDColumn("DetEnergyVector");
man->FinishNtuple(0);

should stay in the RunAction constructor as it in B5.

1 Like

Thanks a lot for the clarification.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.