QwGeant4
QweakSimAnalysis.cc
Go to the documentation of this file.
1 //=============================================================================
2 //
3 // ---------------------------
4 // | Doxygen File Information |
5 // ---------------------------
6 //
7 /**
8 
9  \file QweakSimAnalysis.cc
10 
11  $Revision: 1.4 $
12  $Date: 2006/01/06 19:12:25 $
13 
14  \author Klaus Hans Grimm
15 
16 */
17 //=============================================================================
18 
19 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
20 
21 // system includes
22 #include <ctime>
23 
24 // geant4 includes
25 #include "G4Run.hh"
26 
27 // user includes
28 #include "QweakSimAnalysis.hh"
31 #include "QweakSimUserMainEvent.hh"
33 
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
36 : fRootFileStem("QwSim"),fRootFileName("")
37 {
38  G4cout << "###### Calling QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
39 
40  myUserInfo = userInfo;
41 
42  // Initialize
43  fRootEvent = NULL;
44  fRootNtuple = NULL;
45  fRootBranch = NULL;
46  fRootFile = NULL;
47 
48  // Create messenger
50 
51  // Create user run data
53 
54  G4cout << "###### Leaving QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
59 {
60  G4cout << "###### Calling QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
61 
62  // Delete ROOT objects
63  if (fRootEvent) delete fRootEvent;
64  if (fRootNtuple) delete fRootNtuple;
65  if (fRootBranch) delete fRootBranch;
66  if (fRootFile) delete fRootFile;
67 
68  // Delete messenger
70 
71  G4cout << "###### Leaving QweakSimAnalysis::QweakSimAnalysis()" << G4endl;
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
75 
76 // Get and set number of events in this run
79 }
82 }
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85 void QweakSimAnalysis::BeginOfRun(const G4Run* aRun)
86 {
87  // Get run number
88  G4int runID = aRun->GetRunID();
89 
90  // Construct file name if not set explicitly
91  if (fRootFileName.size() == 0)
92  fRootFileName = fRootFileStem + "_" + Form("%d",runID) + ".root";
93 
94  // Create ROOT file
95  G4cout << "###### Analysis: creating ROOT file " << fRootFileName << G4endl;
96  fRootFile = new TFile(fRootFileName,"RECREATE","Qweak ROOT file");
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 void QweakSimAnalysis::EndOfRun(const G4Run* /*aRun*/)
102 {
103  // Autosave one last time
105 
106  // Write the data to the ROOT file
107  G4cout << "###### Analysis: closing ROOT file " << fRootFileName << G4endl;
108  fRootFile->Write(0,TObject::kOverwrite);
109  fRootFile->Close();
110  fRootFileName = "";
111 }
112 
113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
115 {
116  // This member is called at the end of every event
117  if (!flag) return;
118 }
119 
120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
122 {
123  // Create ROOT tree
124  fRootNtuple = new TTree("QweakSimG4_Tree","Qweak Geant4 Simulation Tree");
125 
126  // Save the file after so many bytes. Avoids complete data loss after crash
127  //fRootNtuple ->SetAutoSave(1000000); //AutoSave after every 1 Mbyte written to disk
128 
129  // Instance of data structure to be written into ROOT file
131 
132  // Create a branch with the data structure defined by fRootEvent
133  int bufsize = 64000;
134  int split = 99;
135  fRootBranch = fRootNtuple->Branch("QweakSimUserMainEvent", "QweakSimUserMainEvent", &fRootEvent, bufsize, split);
136 
137  // Write run data
138  pUserRunInformation->Write();
139 }
140 
141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
142 
144 {
145  // save the current ntuple:
146  // In case your program crashes before closing the file holding this tree,
147  // the file will be automatically recovered when you will connect the file
148  // in UPDATE mode.
149  // The Tree will be recovered at the status corresponding to the last AutoSave.
150  //
151  // if option contains "SaveSelf", gDirectory->SaveSelf() is called.
152  // This allows another process to analyze the Tree while the Tree is being filled.
153  //
154  // see http://root.cern.ch/root/html/TTree.html#TTree:AutoSave
155 
156  // fRootNtuple -> AutoSave("SaveSelf");
157  fRootNtuple -> AutoSave();
158  gDirectory -> Purge(); //jpan: Purge old trees
159 }
160 
161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162 
void EndOfEvent(G4int flag)
void SetNumberOfEventToBeProcessed(G4int n)
QweakSimUserRunInformation * pUserRunInformation
void BeginOfRun(const G4Run *aRun)
QweakSimUserMainEvent * fRootEvent
QweakSimAnalysisMessenger * pAnalysisMessenger
Defines Top ROOT Tree structure of the ROOT file for each event.
virtual ~QweakSimAnalysis()
G4int GetNumberOfEventToBeProcessed() const
G4int GetNumberOfEventToBeProcessed() const
QweakSimUserInformation * myUserInfo
QweakSimAnalysis(QweakSimUserInformation *)
void EndOfRun(const G4Run *aRun)