Skip to content

Commit 50e67df

Browse files
committed
Add a new tree to the output file, with a single entry & single branch (instance of WCSimRootOptions)
1 parent 4bdb158 commit 50e67df

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

include/WCSimRunAction.hh

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "TTree.h"
1010
#include "WCSimRootEvent.hh"
1111
#include "WCSimRootGeom.hh"
12+
#include "WCSimRootOptions.hh"
1213
#include "WCSimDetectorConstruction.hh"
1314

1415
class G4Run;
@@ -28,13 +29,11 @@ public:
2829
void FillGeoTree();
2930
TTree* GetTree(){return WCSimTree;}
3031
TTree* GetGeoTree(){return geoTree;}
32+
TTree* GetOptionsTree(){return optionsTree;}
3133
WCSimRootGeom* GetRootGeom(){return wcsimrootgeom;}
3234
WCSimRootEvent* GetRootEvent(){return wcsimrootsuperevent;}
35+
WCSimRootOptions* GetRootOptions(){return wcsimrootoptions;}
3336

34-
void SetTree(TTree* tree){WCSimTree=tree;}
35-
void SetGeoTree(TTree* tree){geoTree=tree;}
36-
void SetRootEvent(WCSimRootEvent* revent){wcsimrootsuperevent=revent;}
37-
void SetRootGeom(WCSimRootGeom* rgeom){wcsimrootgeom=rgeom;}
3837
int GetNumberOfEventsGenerated() { return numberOfEventsGenerated;}
3938
int GetNtuples(){return ntuples;}
4039

@@ -50,8 +49,10 @@ private:
5049
//
5150
TTree* WCSimTree;
5251
TTree* geoTree;
52+
TTree* optionsTree;
5353
WCSimRootEvent* wcsimrootsuperevent;
5454
WCSimRootGeom* wcsimrootgeom;
55+
WCSimRootOptions* wcsimrootoptions;
5556
WCSimDetectorConstruction* wcsimdetector;
5657

5758
int numberOfEventsGenerated;

src/WCSimEventAction.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -894,11 +894,10 @@ void WCSimEventAction::FillRootEvent(G4int event_id,
894894

895895
TTree* tree = GetRunAction()->GetTree();
896896
tree->Fill();
897-
TFile* hfile = tree->GetCurrentFile();
898897
// MF : overwrite the trees -- otherwise we have as many copies of the tree
899898
// as we have events. All the intermediate copies are incomplete, only the
900899
// last one is useful --> huge waste of disk space.
901-
hfile->Write("",TObject::kOverwrite);
900+
tree->Write("",TObject::kOverwrite);
902901

903902
// M Fechner : reinitialize the super event after the writing is over
904903
wcsimrootsuperevent->ReInitialize();

src/WCSimRunAction.cc

+13-6
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ void WCSimRunAction::BeginOfRunAction(const G4Run* /*aRun*/)
6565
hfile->SetCompressionLevel(2);
6666

6767
// Event tree
68-
TTree* tree = new TTree("wcsimT","WCSim Tree");
68+
WCSimTree = new TTree("wcsimT","WCSim Tree");
6969

70-
SetTree(tree);
7170
wcsimrootsuperevent = new WCSimRootEvent(); //empty list
7271
// wcsimrootsuperevent->AddSubEvent(); // make at least one event
7372
wcsimrootsuperevent->Initialize(); // make at least one event
@@ -76,16 +75,20 @@ void WCSimRunAction::BeginOfRunAction(const G4Run* /*aRun*/)
7675
Int_t bufsize = 64000;
7776

7877
// TBranch *branch = tree->Branch("wcsimrootsuperevent", "Jhf2kmrootsuperevent", &wcsimrootsuperevent, bufsize,0);
79-
TBranch *branch = tree->Branch("wcsimrootevent", "WCSimRootEvent", &wcsimrootsuperevent, bufsize,2);
78+
TBranch *branch = WCSimTree->Branch("wcsimrootevent", "WCSimRootEvent", &wcsimrootsuperevent, bufsize,2);
8079

8180
// Geometry tree
8281

8382
geoTree = new TTree("wcsimGeoT","WCSim Geometry Tree");
84-
SetGeoTree(geoTree);
8583
wcsimrootgeom = new WCSimRootGeom();
8684
TBranch *geoBranch = geoTree->Branch("wcsimrootgeom", "WCSimRootGeom", &wcsimrootgeom, bufsize,0);
8785

8886
FillGeoTree();
87+
88+
// Options tree
89+
optionsTree = new TTree("wcsimRootOptionsT","WCSim Options Tree");
90+
wcsimrootoptions = new WCSimRootOptions();
91+
optionsTree->Branch("wcsimrootoptions", "WCSimRootOptions", &wcsimrootoptions, bufsize, 0);
8992
}
9093

9194
void WCSimRunAction::EndOfRunAction(const G4Run*)
@@ -102,6 +105,11 @@ void WCSimRunAction::EndOfRunAction(const G4Run*)
102105
// G4cout << (float(numberOfTimesCatcherHit)/float(numberOfEventsGenerated))*100.
103106
// << "% through-going (hit Catcher)" << G4endl;
104107

108+
//Write the options tree
109+
G4cout << "EndOfRunAction" << G4endl;
110+
optionsTree->Fill();
111+
optionsTree->Write();
112+
105113
// Close the Root file at the end of the run
106114

107115
TFile* hfile = WCSimTree->GetCurrentFile();
@@ -183,6 +191,5 @@ void WCSimRunAction::FillGeoTree(){
183191
wcsimrootgeom-> SetWCNumPMT(numpmt);
184192

185193
geoTree->Fill();
186-
TFile* hfile = geoTree->GetCurrentFile();
187-
hfile->Write();
194+
geoTree->Write();
188195
}

0 commit comments

Comments
 (0)