Hello, I usually save my GEANT4 output in ROOT files to analyse them by ROOT. Unfortunately, my new boss can’t use ROOT then he asked me to save data also in txt files.
Then, I added this code in the EventAction.cc
void B1EventAction::EndOfEventAction(const G4Event* event)
{
auto analysisManager = G4AnalysisManager::Instance();
// accumulate statistics in run action
fRunAction->AddEdep(fEdep);
analysisManager->FillNtupleDColumn(0,0, fEdep);
analysisManager->AddNtupleRow();
//save on txt file
#ifdef G4MULTITHREADED
static G4Mutex stuffMutex = G4MUTEX_INITIALIZER;
G4AutoLock al(&stuffMutex);
#endif
static bool first = true;
static std::ofstream results ("DepositedEnergyData.txt", std::ofstream::out | std::ofstream::app);
if (first) {
first = false;
results << "#,eDep/keV,..." << std::endl;
}
results<< fEdep<< G4endl;
}
to save data on a txt file. Here the EventAction and a result file example
But my boss needs the data previously binned.
Then he needs a files with two culomns:
FIRST CULOMN: The deposited energy values from 0 to maximum with binning 1keV (i.e. 0,1,2,3,4,5,…ecc)
SECOND CULOM: the number of counts
He sent me this example (notice that in the example there is also a third culomn that is a branching ratio) exampledata.txt (84.8 KB)
Is there a way to directly save data in this way on GEANT? I mean…instead of saving the deposited energy for each event, saving binned data at the end of all the
On the contray, if I don’t Include the B4analysis.hh and I write G4AnalysisManager* analysisManagertxt = G4AnalysisManager::Instance();
instead of G4AnalysisManager* analysisManagertxt = G4AnalysisManager::Instance("cvs");
I don’t get errors but at the end of the simulation:
I get a root file instead of a cvs file
The first root file (the one that I want) and the second root file (the one that should be a cvs file) looks like merged and data aren’t correctly written.
I found this @anna’s reply Making more than one .csv file - #2 by anna
in which she says that it isn’t possible to save two different files at the same time. Then I can’t save a ROOT File and a txt file.
Is there a method , at the end of the simulation to get the data from the no-binned data file and create a binned one?