ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCalib::MTT0PatternRecognition Class Reference

#include <MTT0PatternRecognition.h>

Collaboration diagram for MuonCalib::MTT0PatternRecognition:

Public Member Functions

 MTT0PatternRecognition ()
 Default constructor.
bool Initialize (TH1F *hist, const T0MTSettings *settings)
 Initialize class - returns true if pattern recognition was successfull.
double GetBackground () const
 get the background level
double GetHeight () const
 get height
double GetEstimatedT0 () const
 get estimated t0
double GetFitRangeMin () const
 get fit range
double GetFitRangeMax () const
 get fit range
bool GetError () const
 return error flag

Private Member Functions

bool estimate_background (TH1F *hist, double scale_min)
 estimates the background level
double estimate_height (TH1F *hist)
 estimates the height of the spectrum.

Private Attributes

const T0MTSettingsT0m_settings
 settings
bool m_draw_debug_graph
double m_background
 background level
double m_height
 height
double m_fit_min
 fit range
double m_fit_max
double m_t0_est
 t0 estimate
VariableBinwidthHistogram m_vbh
 Variable binwidth histogram.
bool m_error
 error flag

Detailed Description

Definition at line 35 of file MTT0PatternRecognition.h.

Constructor & Destructor Documentation

◆ MTT0PatternRecognition()

MuonCalib::MTT0PatternRecognition::MTT0PatternRecognition ( )
inline

Member Function Documentation

◆ estimate_background()

bool MuonCalib::MTT0PatternRecognition::estimate_background ( TH1F * hist,
double scale_min )
private

estimates the background level

Parameters
histinput histogram
scale_minlower end of the scale region as returned from estimate_height()

Definition at line 19 of file MTT0PatternRecognition.cxx.

19 {
20 // Get first bin in input histogram which is not empty. This avoids underestimation of the background rate if the range of
21 // the input histogram exceeds the TDC-range
22 int min(-1);
23 for (int i = 1; i <= hist->GetNbinsX(); i++) {
24 if (hist->GetBinContent(i) > 0) {
25 min = i;
26 break;
27 }
28 }
29 if (min == -1) {
30 MsgStream log(Athena::getMessageSvc(), "MTT0PattternRecognition");
31 log << MSG::WARNING << "estimate_background() - No hits in input histogram!" << endmsg;
32 m_error = true;
33 return false;
34 }
35 double maxx = scale_min - 40;
36 int max = hist->FindBin(maxx);
37 // we want 10 bins minimum for the background estimate
38 if (max - min < m_settings->MinBackgroundBins()) {
39 min = max - 128;
40 if (min < 0) min = 0;
41 }
42 // if there are still not enough bins for the background estimate we have a problem
43 if (max - min < m_settings->MinBackgroundBins()) {
44 MsgStream log(Athena::getMessageSvc(), "MTT0PattternRecognition");
45 log << MSG::WARNING << "estimate_background() - Rising edge is to glose to lower histogram range!" << endmsg;
46 m_error = true;
47 return false;
48 }
49 // calculate average bin content
50 m_background = 0.0;
51 double back_squared = 0.0;
52 double n_bins = 0.0;
53 double referece_chi2 = 0.0;
54 for (int i = min; i < max; i++) {
55 n_bins++;
56 m_background += hist->GetBinContent(i);
57 back_squared += hist->GetBinContent(i) * hist->GetBinContent(i);
58 if (n_bins == m_settings->MinBackgroundBins()) {
59 double bac = m_background / n_bins;
60 referece_chi2 = 2 * (back_squared / n_bins - bac * bac);
61 }
62 if (n_bins > m_settings->MinBackgroundBins()) {
63 double bac = m_background / n_bins;
64 double chi2 = 2 * (back_squared / n_bins - bac * bac);
65 if (chi2 > 5 * referece_chi2) break;
66 }
67 }
68 m_background /= n_bins;
69 // store lower edge of fit range
70 m_fit_min = hist->GetBinCenter(min);
71 m_t0_est = 0.5 * (scale_min + hist->GetBinCenter(max));
72 // mark selected range
74 (new TLine(hist->GetBinCenter(min), 0, hist->GetBinCenter(min), hist->GetMaximum()))->Write("t0_back_left");
75 (new TLine(hist->GetBinCenter(max), 0, hist->GetBinCenter(max), hist->GetMaximum()))->Write("t0_back_right");
76 }
77
78 return true;
79 }
#define endmsg
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
double chi2(TH1 *h0, TH1 *h1)
IMessageSvc * getMessageSvc(bool quiet=false)

◆ estimate_height()

double MuonCalib::MTT0PatternRecognition::estimate_height ( TH1F * hist)
private

estimates the height of the spectrum.

It returns the lower end of the scale region

Parameters
histinput histogram

Definition at line 85 of file MTT0PatternRecognition.cxx.

85 {
86 // smooth histogram
87 if (!m_vbh.Smooth(hist->GetBinWidth(1))) {
88 m_error = true;
89 return -1;
90 }
91 if (!m_vbh.Smooth(hist->GetBinWidth(1) / 2)) {
92 m_error = true;
93 return -1;
94 }
95 // draw debug graphs
97 m_vbh.DenistyGraph()->Write("t0_density");
98 m_vbh.BinWidthGraph()->Write("t0_binwidth");
99 m_vbh.BinContentGraph()->Write("t0_bin_content");
100 m_vbh.DiffDensityGraph()->Write("t0_diff_density");
101 m_vbh.DiffDensityGraph()->Write("t0_diffbinwidth");
102 }
103 // get the range in which the smallest, and second smallest bins are
104 double lower = m_vbh.GetSortedBin(0).Width();
105 double left(9e9), right(-9e9);
106 // bool smallest_found(false);
107 for (unsigned int i = 0; i < m_vbh.GetNumberOfBins(); i++) {
108 if (m_vbh.GetSortedBin(i).Left() < left) left = m_vbh.GetSortedBin(i).Left();
109 if (m_vbh.GetSortedBin(i).Right() > right) right = m_vbh.GetSortedBin(i).Right();
110 // NOTE: For greater numerical stability m_vbh.GetSortedBin(i).Width() is considered greater only if it is greater by
111 // hist->GetBinWidth(1) / 100.0. I have seen differences in Binwidth in the order of 1e-13. On the other hand, due to the
112 // binning of the input histogram, e real difference in the binwidth of the VBH n*hist->GetBinWidth(1).
113 if ((m_vbh.GetSortedBin(i).Width() - lower) > hist->GetBinWidth(1) / 100.0) {
114 // reqire minimum distance between bins, and minimum number if significant bins
115 if (right - left > 50 && i > 20) break;
116 lower = m_vbh.GetSortedBin(i).Width();
117 }
118 }
119 // mark selected range
120 if (m_draw_debug_graph) {
121 (new TLine(left, 0, left, hist->GetMaximum()))->Write("t0_height_left");
122 (new TLine(right, 0, right, hist->GetMaximum()))->Write("t0_height_right");
123 }
124 // calcularte mean bin content of input histogram in range
125 int bleft(hist->FindBin(left)), bright(hist->FindBin(right));
126 double nbins = 0.0;
127 m_height = 0.0;
128 for (int i = bleft; i <= bright; i++) {
129 m_height += hist->GetBinContent(i);
130 nbins++;
131 }
132 if (nbins < 1) {
133 MsgStream log(Athena::getMessageSvc(), "MTT0PattternRecognition");
134 log << MSG::WARNING << "estimate_height() - top region is too small! left=" << left << " right=" << right << endmsg;
135 m_error = true;
136 return -1;
137 }
138 m_height /= nbins;
139 m_fit_max = right;
140 return left;
141 }
VariableBinwidthHistogram m_vbh
Variable binwidth histogram.

◆ GetBackground()

double MuonCalib::MTT0PatternRecognition::GetBackground ( ) const
inline

get the background level

Definition at line 64 of file MTT0PatternRecognition.h.

64{ return m_background; }

◆ GetError()

bool MuonCalib::MTT0PatternRecognition::GetError ( ) const
inline

return error flag

Definition at line 79 of file MTT0PatternRecognition.h.

79{ return m_error; }

◆ GetEstimatedT0()

double MuonCalib::MTT0PatternRecognition::GetEstimatedT0 ( ) const
inline

get estimated t0

Definition at line 70 of file MTT0PatternRecognition.h.

70{ return m_t0_est; }

◆ GetFitRangeMax()

double MuonCalib::MTT0PatternRecognition::GetFitRangeMax ( ) const
inline

get fit range

Definition at line 76 of file MTT0PatternRecognition.h.

76{ return m_fit_max; }

◆ GetFitRangeMin()

double MuonCalib::MTT0PatternRecognition::GetFitRangeMin ( ) const
inline

get fit range

Definition at line 73 of file MTT0PatternRecognition.h.

73{ return m_fit_min; }

◆ GetHeight()

double MuonCalib::MTT0PatternRecognition::GetHeight ( ) const
inline

get height

Definition at line 67 of file MTT0PatternRecognition.h.

67{ return m_height; }

◆ Initialize()

bool MuonCalib::MTT0PatternRecognition::Initialize ( TH1F * hist,
const T0MTSettings * settings )
inline

Initialize class - returns true if pattern recognition was successfull.

Parameters
histHistogram which is to be fitted

Definition at line 53 of file MTT0PatternRecognition.h.

53 {
54 m_settings = settings->T0Settings();
55 m_draw_debug_graph = settings->DrawDebugGraphs();
56 m_error = !m_vbh.Initialize(hist, m_settings->VBHBinContent(), m_settings->MaxBinWidth());
57 double scale_min = 0.;
58 if (!m_error) scale_min = estimate_height(hist);
59 if (!m_error) estimate_background(hist, scale_min);
60 return !m_error;
61 }
double estimate_height(TH1F *hist)
estimates the height of the spectrum.
bool estimate_background(TH1F *hist, double scale_min)
estimates the background level

Member Data Documentation

◆ m_background

double MuonCalib::MTT0PatternRecognition::m_background
private

background level

Definition at line 88 of file MTT0PatternRecognition.h.

◆ m_draw_debug_graph

bool MuonCalib::MTT0PatternRecognition::m_draw_debug_graph
private

Definition at line 85 of file MTT0PatternRecognition.h.

◆ m_error

bool MuonCalib::MTT0PatternRecognition::m_error
private

error flag

Definition at line 103 of file MTT0PatternRecognition.h.

◆ m_fit_max

double MuonCalib::MTT0PatternRecognition::m_fit_max
private

Definition at line 94 of file MTT0PatternRecognition.h.

◆ m_fit_min

double MuonCalib::MTT0PatternRecognition::m_fit_min
private

fit range

Definition at line 94 of file MTT0PatternRecognition.h.

◆ m_height

double MuonCalib::MTT0PatternRecognition::m_height
private

height

Definition at line 91 of file MTT0PatternRecognition.h.

◆ m_settings

const T0MTSettingsT0* MuonCalib::MTT0PatternRecognition::m_settings
private

settings

Definition at line 84 of file MTT0PatternRecognition.h.

◆ m_t0_est

double MuonCalib::MTT0PatternRecognition::m_t0_est
private

t0 estimate

Definition at line 97 of file MTT0PatternRecognition.h.

◆ m_vbh

VariableBinwidthHistogram MuonCalib::MTT0PatternRecognition::m_vbh
private

Variable binwidth histogram.

Definition at line 100 of file MTT0PatternRecognition.h.


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