ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Atlas
G4AtlasTests
src
SimTestHisto.h
Go to the documentation of this file.
1
/* -*- C++ -*- */
2
3
/*
4
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5
*/
6
7
#ifndef G4ATLASTESTS_SIMTESTHISTO_H
8
#define G4ATLASTESTS_SIMTESTHISTO_H
9
13
14
#include "
AthenaKernel/errorcheck.h
"
15
#include "GaudiKernel/ITHistSvc.h"
16
#include "GaudiKernel/ServiceHandle.h"
17
18
#include "TH1.h"
19
#include "TH2.h"
20
class
TProfile;
21
25
class
SimTestHisto
26
{
27
28
public
:
29
30
SimTestHisto
() =
default
;
31
~SimTestHisto
() =
default
;
32
33
protected
:
34
std::string
m_path
{
"/truth/"
};
35
ServiceHandle<ITHistSvc>
m_histSvc
{
"THistSvc"
,
"SimTestHisto"
};
36
};
37
38
// note: var should be of type "TH1*" even if it is filled with a TProfile*
39
#define _TPROFILE(var,name,nbin,xmin,xmax) \
40
{ \
41
const std::string histName{name}; \
42
const std::string histPath{m_path + histName}; \
43
if (!m_histSvc->exists(histPath)) { \
44
var = new TProfile(histName.c_str(), histName.c_str(),nbin,xmin,xmax); \
45
CHECK(m_histSvc->regHist(histPath,var)); \
46
} else { \
47
CHECK(m_histSvc->getHist(histPath, var)); \
48
} \
49
}
50
51
52
#define _TH1D(var,name,nbin,xmin,xmax) \
53
{ \
54
const std::string histName{name}; \
55
const std::string histPath{m_path + histName}; \
56
if (!m_histSvc->exists(histPath)) { \
57
var = new TH1D(histName.c_str(), histName.c_str(),nbin, xmin, xmax); \
58
var->StatOverflows(); \
59
CHECK(m_histSvc->regHist(histPath, var)); \
60
} else { \
61
CHECK(m_histSvc->getHist(histPath, var)); \
62
} \
63
}
64
65
66
#define _TH1D_NOCHECK(var,name,nbin,xmin,xmax) \
67
if (!m_histSvc->exists(m_path+name)) { \
68
var = new TH1D(name,name,nbin,xmin,xmax); \
69
var->StatOverflows(); \
70
if(m_histSvc->regHist(m_path+name,var).isFailure()) \
71
std::cout<<"Cannot register histogram "<<name<<std::endl; \
72
} else { \
73
if(m_histSvc->getHist(m_path+name,var).isFailure()) \
74
std::cout<<"Cannot get histogram "<<name<<std::endl; \
75
}
76
77
#define _TH1D_WEIGHTED(var,name,nbin,xmin,xmax) \
78
_TH1D(var,name,nbin,xmin,xmax); \
79
var->Sumw2();
80
81
#define _TH2D_NOCHECK(var,name,nbinx,xmin,xmax,nbiny,ymin,ymax) \
82
if (!m_histSvc->exists(m_path+name)) { \
83
var = new TH2D(name,name,nbinx,xmin,xmax,nbiny,ymin,ymax); \
84
if(m_histSvc->regHist(m_path+name,var).isFailure()) \
85
std::cout<<"Cannot register histogram "<<name<<std::endl;\
86
} else { \
87
if(m_histSvc->getHist(m_path+name,var).isFailure()) \
88
std::cout<<"Cannot get histogram "<<name<<std::endl; \
89
}
90
91
#define _TH2D(var,name,nbinx,xmin,xmax,nbiny,ymin,ymax) \
92
{ \
93
const std::string histName{name}; \
94
const std::string histPath{m_path + histName}; \
95
if (!m_histSvc->exists(histPath)) { \
96
var = new TH2D(histName.c_str(),histName.c_str(),nbinx,xmin,xmax,nbiny,ymin,ymax); \
97
CHECK(m_histSvc->regHist(histPath,var)); \
98
} else { \
99
CHECK(m_histSvc->getHist(histPath,var)); \
100
} \
101
}
102
103
#define _TH2D_WEIGHTED(var,name,nbinx,xmin,xmax,nbiny,ymin,ymax) \
104
_TH2D(var,name,nbinx,xmin,xmax,nbiny,ymin,ymax); \
105
var->Sumw2();
106
107
#define _SET_TITLE(var,title,xaxis,yaxis) \
108
var->SetXTitle(xaxis); \
109
var->SetYTitle(yaxis); \
110
var->SetTitle((std::string(var->GetName())+" : "+title).c_str());
111
112
//#define _SET_LOGX(var)
113
//TAxis *axis = var->GetXaxis();
114
//int bins = axis->GetNbin//s();
115
116
// Axis_t from = axis->GetXmin();
117
// Axis_t to = axis->GetXmax();
118
// Axis_t width = (to - from) / bins;
119
// Axis_t *new_bins = new Axis_t[bins + 1];
120
121
// for (int i = 0; i <= bins; i++) {
122
// new_bins[i] = TMath::Power(10, from + i * width);
123
//
124
// }
125
// axis->Set(bins, new_bins);
126
// delete new_bins;
127
128
#endif
//G4ATLASTESTS_SIMTESTHISTO_H
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ServiceHandle
Definition
ClusterMakerTool.h:36
SimTestHisto::m_path
std::string m_path
Definition
SimTestHisto.h:34
SimTestHisto::SimTestHisto
SimTestHisto()=default
SimTestHisto::~SimTestHisto
~SimTestHisto()=default
SimTestHisto::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
Definition
SimTestHisto.h:35
Generated on
for ATLAS Offline Software by
1.17.0