Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMXRunAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // --------------------------------------------------------------
28 // GEANT 4 - Underground Dark Matter Detector Advanced Example
29 //
30 // For information related to this code contact: Alex Howard
31 // e-mail: alexander.howard@cern.ch
32 // --------------------------------------------------------------
33 // Comments
34 //
35 // Underground Advanced
36 // by A. Howard and H. Araujo
37 // (27th November 2001)
38 //
39 // History:
40 // 17 Jan 2002 Alex Howard Added Analysis
41 // 23 Oct 2009 Luciano Pandola Removed un-necessary calls from EndOfRun()
42 //
43 // RunAction program
44 // --------------------------------------------------------------
45 
46 #include "DMXRunActionMessenger.hh"
47 #include "DMXRunAction.hh"
48 
49 #include "G4Run.hh"
50 #include "G4ios.hh"
51 
52 #include <fstream>
53 
54 #include "DMXAnalysisManager.hh"
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
59 {
60  runMessenger = new DMXRunActionMessenger(this);
61  savehitsFile = "hits.out";
62  savepmtFile = "pmt.out";
63  savehistFile = "dmx";
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
67 
69 {
70  delete runMessenger;
71  runMessenger = 0;
72 
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
76 
78 {
79 
80  G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
81 
82  // Book histograms and ntuples
83  Book();
84 
85 }
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
88 
90 {;}
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
93 
94 void DMXRunAction::Book()
95 {
96  // Get/create analysis manager
97  G4AnalysisManager* man = G4AnalysisManager::Instance();
98 
99  // Open an output file
100  man->OpenFile(savehistFile);
101  man->SetFirstHistoId(1);
102  man->SetFirstNtupleId(1);
103 
104 
105  // ---- primary ntuple ------
106  // id==1
107  man->CreateNtuple("tree1", "Particle Source Energy");
108  man->CreateNtupleDColumn("energy");
109  man->FinishNtuple();
110 
111  // ---- secondary ntuple ------
112  //id==2
113  man->CreateNtuple("tree2", "Scintillation Hits Info");
114  man->CreateNtupleDColumn("Event");
115  man->CreateNtupleDColumn("e_prim");
116  man->CreateNtupleDColumn("tot_e");
117  man->CreateNtupleDColumn("s_hits");
118  man->CreateNtupleDColumn("xe_time");
119  man->CreateNtupleDColumn("num_ph");
120  man->CreateNtupleDColumn("avphtime");
121  man->CreateNtupleDColumn("firstpart");
122  man->CreateNtupleDColumn("firstparte");
123  man->CreateNtupleDColumn("gamma");
124  man->CreateNtupleDColumn("neutron");
125  man->CreateNtupleDColumn("posi");
126  man->CreateNtupleDColumn("elec");
127  man->CreateNtupleDColumn("other");
128  man->CreateNtupleDColumn("seed1");
129  man->CreateNtupleDColumn("seed2");
130  man->FinishNtuple();
131 
132  // ---- tertiary ntuple ------
133  //id==3
134  man->CreateNtuple("tree3", "PMT Hits Info");
135  man->CreateNtupleDColumn("event");
136  man->CreateNtupleDColumn("hits");
137  man->CreateNtupleDColumn("xpos");
138  man->CreateNtupleDColumn("ypos");
139  man->CreateNtupleDColumn("zpos");
140  man->FinishNtuple();
141 
142  // Creating 1-dimensional histograms
143  man->CreateH1("h1","Source Energy /keV", 1000,0.,10000.);
144  man->CreateH1("h2","Energy Deposit /keV", 1000,0.,1000.);
145  man->CreateH1("h3","Nuclear Recoil Edep /keV", 100,0.,100.);
146  man->CreateH1("h4","Number of Photons - LowE", 200,0.,200.);
147  man->CreateH1("h5","Number of Photons - HighE", 100,0.,10000.);
148  man->CreateH1("h6","Average Photon Arrival/ns", 200,0.,200.);
149  man->CreateH1("h7","1st event Photon Arrival", 200,0.,200.);
150  man->CreateH1("h8","Gamma Energy Deposit/keV", 1000,0.,1000.);
151  man->CreateH1("h9","Neutron Ener Deposit/keV", 1000,0.,1000.);
152  man->CreateH1("h10","Electron Ener Deposit/keV",1000,0.,1000.);
153  man->CreateH1("h11","Positron Ener Deposit/keV",1000,0.,1000.);
154  man->CreateH1("h12","Other Ener Deposit/keV", 1000,0.,1000.);
155 
156  //Creating 2-dimensional histograms
157  man->CreateH2("hh1","PMT Hit Pattern",
158  300 ,-30.,30.,300,-30.,30.);
159  man->CreateH2("hh2","1st event PMT Hit Pattern",
160  300 ,-30.,30.,300,-30.,30.);
161 
162  return;
163 
164 }
165 
166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
167 
169 {
170  // Save histograms
171  G4AnalysisManager* man = G4AnalysisManager::Instance();
172  man->Write();
173  man->CloseFile();
174  // Complete clean-up
175  delete G4AnalysisManager::Instance();
176 }
G4bool SetFirstHistoId(G4int firstId)
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
void BeginOfRunAction(const G4Run *)
Definition: DMXRunAction.cc:77
G4int CreateNtuple(const G4String &name, const G4String &title)
G4GLOB_DLL std::ostream G4cout
void EndOfRunAction(const G4Run *)
Definition: DMXRunAction.cc:89
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
G4bool SetFirstNtupleId(G4int firstId)
#define G4endl
Definition: G4ios.hh:61
G4int CreateNtupleDColumn(const G4String &name)
G4int CreateH2(const G4String &name, const G4String &title, G4int nxbins, G4double xmin, G4double xmax, G4int nybins, G4double ymin, G4double ymax, const G4String &xunitName="none", const G4String &yunitName="none", const G4String &xfcnName="none", const G4String &yfcnName="none", const G4String &xbinScheme="linear", const G4String &ybinScheme="linear")