ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonCalib
MdtCalib
MdtCalibT0
src
MTTmaxPatternRecognition.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
MdtCalibT0/MTTmaxPatternRecognition.h
"
6
7
#include <cmath>
8
9
#include "
AthenaKernel/getMessageSvc.h
"
10
#include "GaudiKernel/MsgStream.h"
11
#include "TF1.h"
12
#include "TGraph.h"
13
#include "TH1.h"
14
#include "TLine.h"
15
16
namespace
MuonCalib
{
17
18
inline
Double_t
myexp
(Double_t*
x
, Double_t* p) {
return
std::exp(p[0] + p[1] * (
x
[0] - p[3])) + p[2]; }
19
20
bool
MTTmaxPatternRecognition::Initialize
(TH1F* hist,
double
t0
,
const
T0MTSettings
* settings) {
21
m_settings
= settings->
TMaxSettings
();
22
m_draw_debug_graph
= settings->
DrawDebugGraphs
();
23
m_error
=
false
;
24
m_t0
=
t0
;
25
m_error
= !
m_vbh
.Initialize(hist,
m_settings
->VBHBinContent(),
m_settings
->MaxBinwidth(),
t0
+
m_settings
->VBHLow());
26
if
(
m_error
||
m_vbh
.GetNumberOfBins() < 2) {
27
MsgStream log(
Athena::getMessageSvc
(),
"MTTmaxPatternRecognition"
);
28
log << MSG::WARNING <<
"Initialize() - Initialization of VBH failed!"
<<
endmsg
;
29
}
30
if
(!
m_error
)
estimate_background
(hist);
31
if
(!
m_error
)
estimate_height
(hist);
32
return
!
m_error
;
33
}
34
36
// estimate_background( TH1 *hist) //
38
39
bool
MTTmaxPatternRecognition::estimate_background
(TH1F* hist) {
40
// smooth VBH in several steps
41
for
(
double
i = 1.0; i <= 4.0; i *= 2.0) {
42
for
(
int
j = 0; j < 2; j++)
43
if
(!
m_vbh
.Smooth(hist->GetBinWidth(1) / i)) {
44
m_error
=
true
;
45
return
false
;
46
}
47
}
48
if
(
m_draw_debug_graph
) {
49
m_vbh
.DenistyGraph()->Write(
"tmax_density"
);
50
m_vbh
.BinWidthGraph()->Write(
"tmax_binwidth"
);
51
m_vbh
.DiffDensityGraph()->Write(
"tmax_diffdensity"
);
52
m_vbh
.DiffBinwidthGraph()->Write(
"tmax_diffbinwidth"
);
53
}
54
// find falling edge - search for steepenst slope in a range of 600 to 800 ns after the t0
55
double
peak_falling(0.0), peak_falling_slope(-9e9);
56
for
(
unsigned
int
i = 0; i <
m_vbh
.GetNumberOfBins() - 1; i++) {
57
const
VariableBinwidthHistogramBin
&bin1(
m_vbh
.GetBin(i)), &
bin2
(
m_vbh
.GetBin(i + 1));
58
// select region
59
if
(bin1.Center() <
m_t0
+
m_settings
->EndMin() || bin1.Center() >
m_t0
+
m_settings
->EndMax())
continue
;
60
if
(
bin2
.Width() - bin1.Width() > peak_falling_slope &&
bin2
.Right() < hist->GetBinLowEdge(hist->GetNbinsX()) - 10) {
61
peak_falling = bin1.Right();
62
peak_falling_slope =
bin2
.Width() - bin1.Width();
63
}
64
}
65
// check region size
66
int
firstbin = hist->FindBin(peak_falling +
m_settings
->DistBackground());
67
int
lastbin = hist->FindBin(
m_vbh
.GetBin(
m_vbh
.GetNumberOfBins() - 1).Right());
68
if
(lastbin - firstbin < m_settings->MinBackgroundBins()) lastbin = hist->GetNbinsX();
69
if
(lastbin - firstbin < m_settings->MinBackgroundBins()) {
70
MsgStream log(
Athena::getMessageSvc
(),
"MTTmaxPatternRecognition"
);
71
log << MSG::WARNING <<
"estimate_background() - Falling edge is to glose to upper histogram range!"
<<
endmsg
;
72
m_error
=
true
;
73
return
false
;
74
}
75
// calcul;ate mean
76
m_background
= 0.0;
77
double
n_bins = 0.0;
78
if
(lastbin > hist->GetNbinsX()) lastbin = hist->GetNbinsX();
79
for
(
int
i = firstbin; i <= lastbin; i++) {
80
m_background
+= hist->GetBinContent(i);
81
n_bins++;
82
}
83
// mark selected range
84
if
(
m_draw_debug_graph
) {
85
(
new
TLine(hist->GetBinCenter(firstbin), 0, hist->GetBinCenter(firstbin), hist->GetMaximum()))->Write(
"tmax_back_left"
);
86
(
new
TLine(hist->GetBinCenter(lastbin), 0, hist->GetBinCenter(lastbin), hist->GetMaximum()))->Write(
"tmax_back_right"
);
87
}
88
89
m_background
/= n_bins;
90
m_tmax_est
= peak_falling;
91
m_fit_max
= hist->GetBinCenter(lastbin);
92
return
true
;
93
}
94
96
// estimate_height( TH1 *hist, double background_min) //
98
99
bool
MTTmaxPatternRecognition::estimate_height
(TH1F* hist) {
100
// get start value for fit
101
Double_t left =
m_tmax_est
-
m_settings
->DistAB() -
m_settings
->WidthAB(), right =
m_tmax_est
-
m_settings
->DistAB();
102
// fit
103
TF1* fun =
new
TF1(
"myexp"
,
myexp
, left, right, 4);
104
fun->FixParameter(2,
m_background
);
105
fun->FixParameter(3,
m_t0
);
106
hist->Fit(
"myexp"
,
"Q0+"
,
""
, left, right);
107
// store parameters
108
m_a
= fun->GetParameter(0);
109
m_b
= fun->GetParameter(1);
110
m_fit_min
=
m_tmax_est
-
m_settings
->DistAB() -
m_settings
->WidthAB();
111
// mark selected range
112
if
(
m_draw_debug_graph
) {
113
(
new
TLine(left, 0, left, hist->GetMaximum()))->Write(
"tmax_height_left"
);
114
(
new
TLine(right, 0, right, hist->GetMaximum()))->Write(
"tmax_height_right"
);
115
}
116
return
true
;
117
}
118
119
}
// namespace MuonCalib
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
t0
static Double_t t0
Definition
LArPhysWaveHECTool.cxx:38
MTTmaxPatternRecognition.h
x
#define x
MuonCalib::MTTmaxPatternRecognition::m_vbh
VariableBinwidthHistogram m_vbh
Variable binwidth histogram.
Definition
MTTmaxPatternRecognition.h:99
MuonCalib::MTTmaxPatternRecognition::m_b
double m_b
Definition
MTTmaxPatternRecognition.h:90
MuonCalib::MTTmaxPatternRecognition::m_background
double m_background
background level
Definition
MTTmaxPatternRecognition.h:87
MuonCalib::MTTmaxPatternRecognition::m_settings
const T0MTSettingsTMax * m_settings
settings
Definition
MTTmaxPatternRecognition.h:83
MuonCalib::MTTmaxPatternRecognition::m_tmax_est
double m_tmax_est
t0 estimate
Definition
MTTmaxPatternRecognition.h:96
MuonCalib::MTTmaxPatternRecognition::estimate_background
bool estimate_background(TH1F *hist)
estimates the background level
Definition
MTTmaxPatternRecognition.cxx:39
MuonCalib::MTTmaxPatternRecognition::m_t0
double m_t0
t0
Definition
MTTmaxPatternRecognition.h:102
MuonCalib::MTTmaxPatternRecognition::Initialize
bool Initialize(TH1F *hist, double t0, const T0MTSettings *settings)
Initialize class.
Definition
MTTmaxPatternRecognition.cxx:20
MuonCalib::MTTmaxPatternRecognition::m_a
double m_a
parameters a, b in a*exp(b*x)
Definition
MTTmaxPatternRecognition.h:90
MuonCalib::MTTmaxPatternRecognition::m_fit_max
double m_fit_max
Definition
MTTmaxPatternRecognition.h:93
MuonCalib::MTTmaxPatternRecognition::m_error
bool m_error
error flag
Definition
MTTmaxPatternRecognition.h:105
MuonCalib::MTTmaxPatternRecognition::m_draw_debug_graph
bool m_draw_debug_graph
Definition
MTTmaxPatternRecognition.h:84
MuonCalib::MTTmaxPatternRecognition::estimate_height
bool estimate_height(TH1F *hist)
estimates the height of the spectrum.
Definition
MTTmaxPatternRecognition.cxx:99
MuonCalib::MTTmaxPatternRecognition::m_fit_min
double m_fit_min
fit range
Definition
MTTmaxPatternRecognition.h:93
MuonCalib::T0MTSettings
Settings for the T0 calibration (histogram booking and fitting parameters) Parameters for pattern rec...
Definition
T0MTSettings.h:28
MuonCalib::T0MTSettings::DrawDebugGraphs
const bool & DrawDebugGraphs() const
If set to true for every tube a TDirectory will be created.
Definition
T0MTSettings.h:60
MuonCalib::T0MTSettings::TMaxSettings
const T0MTSettingsTMax * TMaxSettings() const
get settings for the tmax-fit
Definition
T0MTSettings.h:81
MuonCalib::VariableBinwidthHistogramBin
A bin of a VariableBinwidthHistogram.
Definition
VariableBinwidthHistogramBin.h:22
bin2
Definition
KillBinsByStrip.h:34
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition
getMessageSvc.cxx:20
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition
CscCalcPed.cxx:21
MuonCalib::myexp
Double_t myexp(Double_t *x, Double_t *p)
Definition
MTTmaxPatternRecognition.cxx:18
Generated on
for ATLAS Offline Software by
1.17.0