ATLAS Offline Software
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 
6 
7 #include <cmath>
8 
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;
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  }
32  return !m_error;
33  }
34 
36  // estimate_background( TH1 *hist) //
38 
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++) {
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 
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);
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
MuonCalib::VariableBinwidthHistogram::GetBin
const VariableBinwidthHistogramBin & GetBin(unsigned int bin) const
Get a bin.
Definition: VariableBinwidthHistogram.h:71
MuonCalib::T0MTSettings::TMaxSettings
const T0MTSettingsTMax * TMaxSettings() const
get settings for the tmax-fit
Definition: T0MTSettings.h:81
generateReferenceFile.fun
fun
Definition: generateReferenceFile.py:18
MuonCalib::MTTmaxPatternRecognition::m_t0
double m_t0
t0
Definition: MTTmaxPatternRecognition.h:102
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::T0MTSettingsTMax::WidthAB
double WidthAB() const
Width of the region in which the parameters a and b are estimated.
Definition: T0MTSettingsTMax.h:77
MuonCalib::MTTmaxPatternRecognition::m_fit_max
double m_fit_max
Definition: MTTmaxPatternRecognition.h:93
plotmaker.hist
hist
Definition: plotmaker.py:148
MuonCalib::VariableBinwidthHistogram::DiffDensityGraph
TGraph * DiffDensityGraph() const
Plot graph with differential density.
Definition: VariableBinwidthHistogram.cxx:151
MuonCalib::MTTmaxPatternRecognition::m_b
double m_b
Definition: MTTmaxPatternRecognition.h:90
MuonCalib::T0MTSettingsTMax::VBHBinContent
double VBHBinContent() const
Number of hits per histogram bin for the VariableBinwidthHistogram The number is given relative to th...
Definition: T0MTSettingsTMax.h:39
MuonCalib::VariableBinwidthHistogram::DenistyGraph
TGraph * DenistyGraph() const
create density graph - density vs bin center
Definition: VariableBinwidthHistogram.cxx:113
MuonCalib::VariableBinwidthHistogram::GetNumberOfBins
unsigned int GetNumberOfBins() const
Get the number of bins
Definition: VariableBinwidthHistogram.h:85
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
x
#define x
MuonCalib::T0MTSettingsTMax::MaxBinwidth
double MaxBinwidth() const
Maximum bin width for the VariableBinwidthHistogram The bins will not be wider than this even if it m...
Definition: T0MTSettingsTMax.h:43
dqt_zlumi_pandas.bin2
bin2
Definition: dqt_zlumi_pandas.py:337
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
MuonCalib::T0MTSettingsTMax::DistAB
double DistAB() const
Distance of the a/b region from the detected falling edge.
Definition: T0MTSettingsTMax.h:73
MuonCalib::MTTmaxPatternRecognition::m_tmax_est
double m_tmax_est
t0 estimate
Definition: MTTmaxPatternRecognition.h:96
MuonCalib::VariableBinwidthHistogram::DiffBinwidthGraph
TGraph * DiffBinwidthGraph() const
Plot graph with differential binwidth.
Definition: VariableBinwidthHistogram.cxx:166
MuonCalib::T0MTSettingsTMax::DistBackground
double DistBackground() const
distance between the detected falling edge and the begin of the background region
Definition: T0MTSettingsTMax.h:59
MuonCalib::MTTmaxPatternRecognition::m_background
double m_background
background level
Definition: MTTmaxPatternRecognition.h:87
lumiFormat.i
int i
Definition: lumiFormat.py:85
MTTmaxPatternRecognition.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::VariableBinwidthHistogram::Smooth
bool Smooth(double width)
Removes steps that origin in a binning effekt.
Definition: VariableBinwidthHistogram.cxx:87
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
bin2
Definition: KillBinsByStrip.h:34
MuonCalib::MTTmaxPatternRecognition::m_settings
const T0MTSettingsTMax * m_settings
settings
Definition: MTTmaxPatternRecognition.h:83
MuonCalib::MTTmaxPatternRecognition::m_a
double m_a
parameters a, b in a*exp(b*x)
Definition: MTTmaxPatternRecognition.h:90
MuonCalib::VariableBinwidthHistogram::Initialize
bool Initialize(TH1F *hist, double binc_r, double max_bin_width, double min_x=-9e9, double max_x=9e9)
Initialize with new input histogram Returns on error false.
Definition: VariableBinwidthHistogram.cxx:22
MuonCalib::VariableBinwidthHistogramBin
Definition: VariableBinwidthHistogramBin.h:22
MuonCalib::T0MTSettingsTMax::EndMin
double EndMin() const
The range of the falling edge of the spectrum is searched in a region after t0.
Definition: T0MTSettingsTMax.h:53
MuonCalib::T0MTSettingsTMax::EndMax
double EndMax() const
Definition: T0MTSettingsTMax.h:55
MuonCalib::MTTmaxPatternRecognition::m_error
bool m_error
error flag
Definition: MTTmaxPatternRecognition.h:105
dqt_zlumi_pandas.bin1
bin1
Definition: dqt_zlumi_pandas.py:336
MuonCalib::MTTmaxPatternRecognition::m_fit_min
double m_fit_min
fit range
Definition: MTTmaxPatternRecognition.h:93
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::VariableBinwidthHistogram::BinWidthGraph
TGraph * BinWidthGraph() const
Plot binwidth graph - binwidth versus bin center.
Definition: VariableBinwidthHistogram.cxx:127
MuonCalib::MTTmaxPatternRecognition::Initialize
bool Initialize(TH1F *hist, double t0, const T0MTSettings *settings)
Initialize class.
Definition: MTTmaxPatternRecognition.cxx:20
MuonCalib::MTTmaxPatternRecognition::m_draw_debug_graph
bool m_draw_debug_graph
Definition: MTTmaxPatternRecognition.h:84
MuonCalib::VariableBinwidthHistogramBin::Right
double Right() const
Get right (upper) bin border.
Definition: VariableBinwidthHistogramBin.h:114
MuonCalib::T0MTSettings::DrawDebugGraphs
const bool & DrawDebugGraphs() const
If set to true for every tube a TDirectory will be created.
Definition: T0MTSettings.h:60
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
MuonCalib::MTTmaxPatternRecognition::m_vbh
VariableBinwidthHistogram m_vbh
Variable binwidth histogram.
Definition: MTTmaxPatternRecognition.h:99
MuonCalib::myexp
Double_t myexp(Double_t *x, Double_t *p)
Definition: MTTmaxPatternRecognition.cxx:18
MuonCalib::T0MTSettingsTMax::VBHLow
double VBHLow() const
For the pattern-recognition only a part of the drift time spectrum is used for creating the VariableB...
Definition: T0MTSettingsTMax.h:48
MuonCalib::T0MTSettings
Definition: T0MTSettings.h:28
MuonCalib::MTTmaxPatternRecognition::estimate_height
bool estimate_height(TH1F *hist)
estimates the height of the spectrum.
Definition: MTTmaxPatternRecognition.cxx:99
MuonCalib::MTTmaxPatternRecognition::estimate_background
bool estimate_background(TH1F *hist)
estimates the background level
Definition: MTTmaxPatternRecognition.cxx:39