Loading...
Searching...
No Matches
Par04RunAction.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#include "Par04RunAction.hh"
27#include <G4GenericAnalysisManager.hh> // for G4GenericAnalysisManager
28#include <G4ThreeVector.hh> // for G4ThreeVector
29#include <G4Types.hh> // for G4int, G4double
30#include <G4UserRunAction.hh> // for G4UserRunAction
31#include "G4AnalysisManager.hh" // for G4AnalysisManager
32#include "Par04DetectorConstruction.hh" // for Par04DetectorConstruction
33#include "Par04EventAction.hh" // for Par04EventAction
34
35//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36
39 , fDetector(aDetector)
40 , fEventAction(aEventAction)
41{
42 // Create analysis manager
43 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
44 analysisManager->SetDefaultFileType("root");
45
46 // Default filename, can be overriden with /analysis/setFileName
47 analysisManager->SetFileName("Par04Output");
48}
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55
57{
58 // Get analysis manager
59 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
60
61 // Create directories
62 analysisManager->SetNtupleMerging(true);
63 analysisManager->SetVerboseLevel(0);
64
65 // Get detector dimensions
66 G4int cellNumZ = fDetector->GetMeshNbOfCells().z();
67 G4int cellNumRho = fDetector->GetMeshNbOfCells().x();
68 G4int cellNumPhi = fDetector->GetMeshNbOfCells().y();
69 G4double cellSizeZ = fDetector->GetMeshSizeOfCells().z();
70 G4double cellSizeRho = fDetector->GetMeshSizeOfCells().x();
71 G4double cellSizePhi = fDetector->GetMeshSizeOfCells().y();
72 // Default max value of energy stored in histogram (in GeV)
73 G4double maxEnergy = 1000;
74
75 // Creating control histograms
76 analysisManager->CreateH1("energyParticle", "Primary energy;E_{MC} (GeV);Entries", 1024, 0,
77 1.1 * maxEnergy);
78 analysisManager->CreateH1("energyDepositedInVirtual", "Deposited energy;E_{MC} (GeV);Entries",
79 1024, 0, 1.1 * maxEnergy);
80 analysisManager->CreateH1(
81 "energyRatioInVirtual", "Ratio of energy deposited to primary;E_{dep} / E_{MC};Entries",
82 1024, 0, 1);
83 analysisManager->CreateH1("time", "Simulation time; time (s);Entries", 2048, 0, 100);
84 analysisManager->CreateH1("longProfile", "Longitudinal profile;t (mm);#LTE#GT (MeV)", cellNumZ,
85 -0.5 * cellSizeZ, (cellNumZ - 0.5) * cellSizeZ);
86 analysisManager->CreateH1("transProfile", "Transverse profile;r (mm);#LTE#GT (MeV)", cellNumRho,
87 -0.5 * cellSizeRho, (cellNumRho - 0.5) * cellSizeRho);
88 analysisManager->CreateH1("longFirstMoment",
89 "First moment of longitudinal distribution;#LT#lambda#GT (mm);Entries",
90 1024, -0.5 * cellSizeZ,
91 cellNumZ * cellSizeZ / 2); // arbitrary scaling of max value on axis
92 analysisManager->CreateH1("transFirstMoment",
93 "First moment of transverse distribution;#LTr#GT "
94 "(mm);Entries",
95 1024, -0.5 * cellSizeRho,
96 cellNumRho * cellSizeRho /
97 1); // arbitrary scaling of max value on axis
98 analysisManager->CreateH1(
99 "longSecondMoment",
100 "Second moment of longitudinal distribution;#LT#lambda^{2}#GT "
101 "(mm^{2});Entries",
102 1024, 0, std::pow(cellNumZ * cellSizeZ, 2) / 25); // arbitrary scaling of max value on axis
103 analysisManager->CreateH1(
104 "transSecondMoment", "Second moment of transverse distribution;#LTr^{2}#GT (mm^{2});Entries",
105 1024, 0, std::pow(cellNumRho * cellSizeRho, 2) / 5); // arbitrary scaling of max value on axis
106 analysisManager->CreateH1("hitType", "hit type;type (0=full, 1= fast);Entries", 2, -0.5, 1.5);
107 analysisManager->CreateH1("phiProfile",
108 "Azimuthal angle profile, centred at mean;phi;#LTE#GT (MeV)",
109 cellNumPhi, - (cellNumPhi - 0.5) * cellSizePhi,
110 (cellNumPhi - 0.5) * cellSizePhi);
111 analysisManager->CreateH1("numHitsInVirtual", "Number of hits above 0.5 keV", 4048, 0, 20000);
112 analysisManager->CreateH1("cellEnergy", "Cell energy distribution;log10(E/MeV);Entries",
113 1024, -4, 2);
114 analysisManager->CreateH1("numDepositsInVirtual", "Number of deposits in all cells per event",
115 4048, 0, 40000);
116 analysisManager->CreateH1("cellDepositsInVirtual",
117 "Distribution of number of deposits per cell per event", 4048, 0, 1024);
118 analysisManager->CreateH1("energyDepositedInPhysical",
119 "Deposited energy in physical detector readout;E_{MC} (GeV);Entries",
120 1024, 0, 1.1 * maxEnergy);
121 analysisManager->CreateH1("energyRatioInPhysical",
122 "Ratio of energy deposited in physical readout to primary; E_{dep} / E_{MC};Entries",
123 1024, 0, 1);
124 analysisManager->CreateH1("numHitsInPhysical", "Number of hits in physical readout above 0.5 keV",
125 4048, 0, 5000);
126 analysisManager->CreateH1("cellEnergyInPhysical",
127 "Physical cell energy distribution;log10(E/MeV);Entries", 1024, -4, 2);
128 analysisManager->CreateH1("numDepositsInPhysical",
129 "Number of deposits in all physical cells per event", 4048, 0, 40000);
130 analysisManager->CreateH1("cellDepositsInPhysical",
131 "Distribution of number of deposits per physical cell per event",
132 4048, 0, 1024);
133
134 // Creating ntuple
135 analysisManager->CreateNtuple("global", "Event data");
136 analysisManager->CreateNtupleDColumn("EnergyMC");
137 analysisManager->CreateNtupleDColumn("SimTime");
138 analysisManager->FinishNtuple();
139
140 analysisManager->CreateNtuple("virtualReadout", "Cylindrical mesh readout");
141 analysisManager->CreateNtupleDColumn("EnergyCell", fEventAction->GetCalEdep());
142 analysisManager->CreateNtupleIColumn("rhoCell", fEventAction->GetCalRho());
143 analysisManager->CreateNtupleIColumn("phiCell", fEventAction->GetCalPhi());
144 analysisManager->CreateNtupleIColumn("zCell", fEventAction->GetCalZ());
145 analysisManager->FinishNtuple();
146
147 analysisManager->CreateNtuple("physicalReadout", "Detector physical readout");
148 analysisManager->CreateNtupleDColumn("EnergyCell", fEventAction->GetPhysicalCalEdep());
149 analysisManager->CreateNtupleIColumn("layerCell", fEventAction->GetPhysicalCalLayer());
150 analysisManager->CreateNtupleIColumn("rowCell", fEventAction->GetPhysicalCalRow());
151 analysisManager->CreateNtupleIColumn("sliceCell", fEventAction->GetPhysicalCalSlice());
152 analysisManager->FinishNtuple();
153
154 analysisManager->OpenFile();
155}
156
157//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
158
160{
161 auto analysisManager = G4AnalysisManager::Instance();
162 analysisManager->Write();
163 analysisManager->CloseFile();
164}
G4ThreeVector GetMeshSizeOfCells() const
Get size of Mesh cells in cylindrical coordinates (r, phi, z)
G4ThreeVector GetMeshNbOfCells() const
Get number of Mesh cells in cylindrical coordinates (r, phi, z)
Event action class for hits' analysis.
std::vector< G4int > & GetPhysicalCalSlice()
std::vector< G4int > & GetCalZ()
std::vector< G4int > & GetCalPhi()
std::vector< G4int > & GetCalRho()
std::vector< G4double > & GetCalEdep()
std::vector< G4int > & GetPhysicalCalRow()
std::vector< G4double > & GetPhysicalCalEdep()
std::vector< G4int > & GetPhysicalCalLayer()
virtual void BeginOfRunAction(const G4Run *) final
Open the file for the analysis.
Par04RunAction(Par04DetectorConstruction *aDetector, Par04EventAction *aEventAction)
Constructor. Defines the histograms.
virtual ~Par04RunAction()
Par04EventAction * fEventAction
Pointer to event action to save hits.
virtual void EndOfRunAction(const G4Run *) final
Write and close the file.
Par04DetectorConstruction * fDetector
Pointer to detector construction to retrieve the detector dimensions to setup the histograms.

Applications | User Support | Publications | Collaboration