Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
Par02Output Class Reference

Handling the saving to the file. More...

#include <Doxymodules_parameterisations.h>

Public Types

enum  SaveType {
  eNoSave , eSaveMC , eSaveTracker , eSaveEMCal ,
  eSaveHCal
}
 Indicates to which ntuple to save the information. More...
 

Public Member Functions

void SetFileName (G4String name)
 Sets the file name of the output root file.
 
G4String GetFileName ()
 Gets the file name of the output root file.
 
void AppendName (G4bool app)
 Sets fFileNameWithRunNo that indicates whether to add the run number to the file name.
 
void StartAnalysis (G4int runID)
 Calls the G4AnalysisManager::Instance().
 
void EndAnalysis ()
 Calls the G4AnalysisManager::Instance().
 
void CreateNtuples ()
 Creates Ntuples used to store information about particle (its ID, PDG code, energy deposits, etc.).
 
void CreateHistograms ()
 Creates histograms to combine information from all the events in the run.
 
void SaveTrack (SaveType aWhatToSave, G4int aPartID, G4int aPDG, G4ThreeVector aVector, G4double aResolution=0, G4double aEfficiency=1, G4double aEnergy=0)
 Saves the information about the particle (track).
 
void FillHistogram (G4int HNo, G4double value) const
 Fills the histogram.
 
 ~Par02Output ()
 

Static Public Member Functions

static Par02OutputInstance ()
 Allows the access to the unique Par02Output object.
 

Protected Member Functions

 Par02Output ()
 A default, protected constructor (due to singleton pattern).
 

Private Attributes

G4String fFileName
 A name of the output root file.
 
G4bool fFileNameWithRunNo
 If true, a run number should be added to the file. Default: false.
 

Static Private Attributes

static Par02OutputfPar02Output = nullptr
 The pointer to the only Par02Output class object.
 
static G4ThreadLocal G4int fCurrentNtupleId = 0
 Current ntuple Id.
 
static G4ThreadLocal G4int fCurrentID = 0
 A control value of particle ID to ensure that data saved to various ntuples match the same particle.
 

Detailed Description

Handling the saving to the file.

A singleton class that manages creation, writing to and closing of the Root output file.

Author
Anna Zaborowska

Definition at line 44 of file Doxymodules_parameterisations.h.

Member Enumeration Documentation

◆ SaveType

Indicates to which ntuple to save the information.

Enumerator
eNoSave 
eSaveMC 
eSaveTracker 
eSaveEMCal 
eSaveHCal 

Definition at line 46 of file Par02Output.hh.

Constructor & Destructor Documentation

◆ ~Par02Output()

Par02Output::~Par02Output ( )
default

◆ Par02Output()

Par02Output::Par02Output ( )
protected

A default, protected constructor (due to singleton pattern).

Definition at line 47 of file Par02Output.cc.

47 : fFileNameWithRunNo( false ) {
48 fFileName = "DefaultOutput.root";
49}
G4bool fFileNameWithRunNo
If true, a run number should be added to the file. Default: false.
G4String fFileName
A name of the output root file.

Member Function Documentation

◆ Instance()

Par02Output * Par02Output::Instance ( )
static

Allows the access to the unique Par02Output object.

Returns
A pointer to the Par02Output class.

Definition at line 57 of file Par02Output.cc.

57 {
58 if ( ! fPar02Output ) {
60 }
61 return fPar02Output;
62}
static Par02Output * fPar02Output
The pointer to the only Par02Output class object.
Par02Output()
A default, protected constructor (due to singleton pattern).

◆ SetFileName()

void Par02Output::SetFileName ( G4String  name)

Sets the file name of the output root file.

Parameters
nameThe name of the file.

Definition at line 66 of file Par02Output.cc.

66 {
67 fFileName = aName;
68}

◆ GetFileName()

G4String Par02Output::GetFileName ( )

Gets the file name of the output root file.

Returns
The name of the file.

Definition at line 78 of file Par02Output.cc.

78 {
79 return fFileName;
80}

◆ AppendName()

void Par02Output::AppendName ( G4bool  app)

Sets fFileNameWithRunNo that indicates whether to add the run number to the file name.

Parameters
appIf add the run number.

Definition at line 72 of file Par02Output.cc.

72 {
73 fFileNameWithRunNo = aApp;
74}

◆ StartAnalysis()

void Par02Output::StartAnalysis ( G4int  runID)

Calls the G4AnalysisManager::Instance().

It sets the file name of the output file based on fFileName and fFileNameWithRunNo and opens the file.

Parameters
runIDA run number (to be added to file name if fFileNameWithRunNo is true).

Definition at line 84 of file Par02Output.cc.

84 {
85 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
86 if ( fFileNameWithRunNo ) {
87 fFileName += "_run";
88 fFileName += G4UIcommand::ConvertToString( aRunID );
89 }
90 analysisManager->SetDefaultFileType("root");
91 analysisManager->SetVerboseLevel( 1 );
92 analysisManager->SetFileName( fFileName );
93 analysisManager->OpenFile( fFileName );
94}

◆ EndAnalysis()

void Par02Output::EndAnalysis ( )

Calls the G4AnalysisManager::Instance().

It writes to the output file and close it.

Definition at line 98 of file Par02Output.cc.

98 {
99 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
100 analysisManager->Write();
101 analysisManager->CloseFile();
102}

◆ CreateNtuples()

void Par02Output::CreateNtuples ( )

Creates Ntuples used to store information about particle (its ID, PDG code, energy deposits, etc.).

To be called for each event in Par02EventAction.

Definition at line 106 of file Par02Output.cc.

106 {
107 const G4Event* event = G4RunManager::GetRunManager()->GetCurrentEvent();
108 G4String evName = "Event_";
109 evName += G4UIcommand::ConvertToString( event->GetEventID() );
110 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
111 fCurrentNtupleId = analysisManager->CreateNtuple( evName, evName );
112
113 analysisManager->CreateNtupleIColumn( "particleID" ); // column Id = 0
114 analysisManager->CreateNtupleIColumn( "PID" ); // column Id = 1
115 analysisManager->CreateNtupleDColumn( "MC_pX" ); // column Id = 2
116 analysisManager->CreateNtupleDColumn( "MC_pY" ); // column Id = 3
117 analysisManager->CreateNtupleDColumn( "MC_pZ" ); // column Id = 4
118
119 analysisManager->CreateNtupleDColumn( "tracker_res" ); // column Id = 5
120 analysisManager->CreateNtupleDColumn( "tracker_eff" ); // column Id = 6
121 analysisManager->CreateNtupleDColumn( "tracker_pX" ); // column Id = 7
122 analysisManager->CreateNtupleDColumn( "tracker_pY" ); // column Id = 8
123 analysisManager->CreateNtupleDColumn( "tracker_pZ" ); // column Id = 9
124
125 analysisManager->CreateNtupleDColumn( "emcal_res" ); // column Id = 10
126 analysisManager->CreateNtupleDColumn( "emcal_eff" ); // column Id = 11
127 analysisManager->CreateNtupleDColumn( "emcal_X" ); // column Id = 12
128 analysisManager->CreateNtupleDColumn( "emcal_Y" ); // column Id = 13
129 analysisManager->CreateNtupleDColumn( "emcal_Z" ); // column Id = 14
130 analysisManager->CreateNtupleDColumn( "emcal_E" ); // column Id = 15
131
132 analysisManager->CreateNtupleDColumn( "hcal_res" ); // column Id = 16
133 analysisManager->CreateNtupleDColumn( "hcal_eff" ); // column Id = 17
134 analysisManager->CreateNtupleDColumn( "hcal_X" ); // column Id = 18
135 analysisManager->CreateNtupleDColumn( "hcal_Y" ); // column Id = 19
136 analysisManager->CreateNtupleDColumn( "hcal_Z" ); // column Id = 20
137 analysisManager->CreateNtupleDColumn( "hcal_E" ); // column Id = 21
138
139 analysisManager->FinishNtuple( fCurrentNtupleId );
140}
static G4ThreadLocal G4int fCurrentNtupleId
Current ntuple Id.

◆ CreateHistograms()

void Par02Output::CreateHistograms ( )

Creates histograms to combine information from all the events in the run.

To be called for each run in Par02RunAction.

Definition at line 144 of file Par02Output.cc.

145{
146 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
147 analysisManager->CreateH1( "Pdiff", "momentum smeared in tracker", 100, 0.8, 1.2 );
148 analysisManager->SetH1XAxisTitle( 0, "p_{smeared}/p_{true}" );
149 analysisManager->SetH1YAxisTitle( 0, "Entries" );
150 analysisManager->CreateH1( "EMCalEdiff", "energy smeared in EMCal", 100, 0.8, 1.2 );
151 analysisManager->SetH1XAxisTitle( 1, "E_{smeared}/E_{true}" );
152 analysisManager->SetH1YAxisTitle( 1, "Entries" );
153 analysisManager->CreateH1( "HCalEdiff", "energy smeared in HCal", 100, 0.0, 2.0 );
154 analysisManager->SetH1XAxisTitle( 2, "E_{smeared}/E_{true}" );
155 analysisManager->SetH1YAxisTitle( 2, "Entries" );
156}

◆ SaveTrack()

void Par02Output::SaveTrack ( SaveType  aWhatToSave,
G4int  aPartID,
G4int  aPDG,
G4ThreeVector  aVector,
G4double  aResolution = 0,
G4double  aEfficiency = 1,
G4double  aEnergy = 0 
)

Saves the information about the particle (track).

Parameters
aWhatToSaveenum indicating what kind of information to store (in which ntuple).
aPartIDA unique ID within event (taken Geant TrackID).
aPDGA PDG code of a particle.
aVectorA vector to be stored (particle momentum in tracker or position of energy deposit in calorimeter).
aResolutionA resolution of the detector that was used.
aEfficiencyAn efficiency of the detector that was used.
aEnergyAn energy deposit (for calorimeters only: Par02Output::SaveType::eEMCal or Par02Output::SaveType::eHCal).

Definition at line 160 of file Par02Output.cc.

162 {
163 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
164 switch( aWhatToSave ) {
166 break;
167 case Par02Output::eSaveMC : {
168 analysisManager->FillNtupleIColumn( fCurrentNtupleId, 0, aPartID );
169 analysisManager->FillNtupleIColumn( fCurrentNtupleId, 1, aPDG );
170 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 2, aVector.x() );
171 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 3, aVector.y() );
172 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 4, aVector.z() );
173 fCurrentID = aPartID;
174 break;
175 }
177 if ( aPartID != fCurrentID ) G4cout <<
178 " Wrong particle - trying to save Tracker information of different particle"
179 << G4endl;
180 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 5, aResolution );
181 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 6, aEfficiency );
182 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 7, aVector.x() );
183 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 8, aVector.y() );
184 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 9, aVector.z() );
185 break;
186 }
188 if ( aPartID != fCurrentID ) G4cout <<
189 " Wrong particle - trying to save EMCal information of different particle"
190 << G4endl;
191 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 10, aResolution );
192 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 11, aEfficiency );
193 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 12, aVector.x() );
194 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 13, aVector.y() );
195 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 14, aVector.z() );
196 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 15, aEnergy );
197 break;
198 }
200 if ( aPartID != fCurrentID ) G4cout <<
201 " Wrong particle - trying to save HCal information of different particle"
202 << G4endl;
203 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 16, aResolution );
204 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 17, aEfficiency );
205 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 18, aVector.x() );
206 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 19, aVector.y() );
207 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 20, aVector.z() );
208 analysisManager->FillNtupleDColumn( fCurrentNtupleId, 21, aEnergy );
209 analysisManager->AddNtupleRow( fCurrentNtupleId );
210 break;
211 }
212 }
213}
static G4ThreadLocal G4int fCurrentID
A control value of particle ID to ensure that data saved to various ntuples match the same particle.

◆ FillHistogram()

void Par02Output::FillHistogram ( G4int  HNo,
G4double  value 
) const

Fills the histogram.

Parameters
HNoNumber of a histogram (decided by the order of creation in CreateHistograms(), the first one is 0).
valueA value to be filled into the histogram.

Definition at line 217 of file Par02Output.cc.

217 {
218 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
219 analysisManager->FillH1( aHistNo, aValue );
220}

Member Data Documentation

◆ fPar02Output

Par02Output * Par02Output::fPar02Output = nullptr
staticprivate

The pointer to the only Par02Output class object.

Definition at line 114 of file Par02Output.hh.

◆ fCurrentNtupleId

G4ThreadLocal G4int Par02Output::fCurrentNtupleId = 0
staticprivate

Current ntuple Id.

Definition at line 117 of file Par02Output.hh.

◆ fFileName

G4String Par02Output::fFileName
private

A name of the output root file.

Definition at line 120 of file Par02Output.hh.

◆ fFileNameWithRunNo

G4bool Par02Output::fFileNameWithRunNo
private

If true, a run number should be added to the file. Default: false.

Definition at line 123 of file Par02Output.hh.

◆ fCurrentID

G4ThreadLocal G4int Par02Output::fCurrentID = 0
staticprivate

A control value of particle ID to ensure that data saved to various ntuples match the same particle.

It is set when Monte Carlo information is saved and checked for all the detectors.

Definition at line 128 of file Par02Output.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration