15 #include <TEfficiency.h>
16 #include <TGraphAsymmErrors.h>
20 #include <dqm_core/AlgorithmManager.h>
35 m_func = std::make_unique<TF1> (
"fermi",
"[0]/(1+exp(([1]-x)/[2]))" );
38 m_func = std::make_unique<TF1> (
"erf",
"[0]*TMath::Erf((x-[1])/(sqrt(2.)*[2]))" );
41 m_func = std::make_unique<TF1> (
"flat",
"[0]" );
49 (void)m_func.release();
61 const TObject &
object,
62 const dqm_core::AlgorithmConfig &
config )
66 const TEfficiency *
eff;
67 if(
object.
IsA()->InheritsFrom(
"TEfficiency" ))
69 eff =
static_cast<const TEfficiency*
>(&
object);
72 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TEfficiency" );
96 const TH1* eff_hist =
eff->GetTotalHistogram();
97 const Int_t eff_points = eff_hist->GetNbinsX();
98 if (eff_points < minpoint || eff_points==0) {
99 if(
verbose)std::cout <<
name <<
" number of points are too small " << eff_points << std::endl;
101 result->tags_[
"InsufficientN"] = eff_points;
104 if(
verbose)std::cout <<
name <<
" enough number of points " << eff_points << std::endl;
106 const TAxis *
x = eff_hist->GetXaxis();
107 int nbins =
x->GetNbins();
108 double high =
x->GetBinUpEdge(
nbins);
109 double low =
x->GetBinUpEdge(0);
112 if (
xmin>high || xmin<low || xmax>high ||
xmax<low) {
113 throw dqm_core::BadConfig( ERS_HERE,
name,
"xmin and/or xmax value not in eff bin range" );
131 if ( minSig != 0 ) option +=
"E";
132 if ( improve ) option +=
"M";
135 std::cout <<
" eff name " <<
eff->GetName() << std::endl;
136 std::cout <<
" fit option " << option << std::endl;
139 if (m_name ==
"fermi") {
140 if(
verbose)std::cout <<
"set "<<
name<<
" parameters" << std::endl;
141 m_func->SetParameter(0,
ymax*0.9);
142 m_func->SetParameter(1,xaxismean);
143 m_func->SetParameter(2,xdiff/50.);
144 m_func->SetParNames(
"Plateau",
"Threshold",
"Resolution");
146 m_func->SetParLimits(0,
ymin - 0.1 * ydiff,
ymax + 0.1 * ydiff );
147 m_func->SetParLimits(1,
xmin,
xmax );
148 m_func->SetParLimits(2, 0., xdiff/4. );
150 else if(m_name ==
"erf") {
151 if(
verbose)std::cout <<
"set "<<
name<<
" parameters" << std::endl;
152 m_func->SetParameter(0,
ymax*0.9);
153 m_func->SetParameter(1,xaxismean);
154 m_func->SetParameter(2,xdiff/50.);
155 m_func->SetParNames(
"Plateau",
"Threshold",
"Resolution");
157 m_func->SetParLimits(0,
ymin - 0.1 * ydiff,
ymax + 0.1 * ydiff );
158 m_func->SetParLimits(1,
xmin,
xmax );
159 m_func->SetParLimits(2, 0., xdiff/4. );
161 else if(m_name ==
"flat") {
162 if(
verbose)std::cout <<
"set "<<
name<<
" parameters" << std::endl;
163 m_func->SetParNames(
"Height");
177 if(
verbose)std::cout <<
"fit "<<
name<<
" with interval cut " <<
xmin <<
" - " <<
xmax << std::endl;
178 std::shared_ptr<TGraphAsymmErrors> graph(
eff->CreateGraph());
179 graph->Fit( m_func.get(), option.c_str());
181 const int numsig = m_func->GetParNumber(
"Sigma");
183 double sigma=m_func->GetParameter(numsig);
184 m_func->SetParameter(numsig,std::abs(
sigma));
191 catch ( dqm_core::Exception & ex ) {
192 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
199 out<<
"Simple_"+m_name+
"_Fit_TEff: Does simple "+m_name+
" fit to eff and checks fit parameters against thresholds\n"<<std::endl;
200 if (m_name ==
"fermi" ) {
201 out<<
"The following fit Parameters can be checked with Red and Green Thresholds; only one parameter is needed to get back real result"<<std::endl;
202 out<<
"Green/Red Threshold: Plateau : Plateau fit value to give Green/Red Result"<<std::endl;
203 out<<
"Green/Red Threshold: Threshold : Fermi energy fit value to give Green/Red Result"<<std::endl;
204 out<<
"Green/Red Threshold: Resolution : Templature fit value to give Green/Red Result\n"<<std::endl;
205 }
else if (m_name ==
"erf" ) {
206 out<<
"The following fit Parameters can be checked with Red and Green Thresholds; only one parameter is needed to get back real result"<<std::endl;
207 out<<
"Green/Red Threshold: Plateau : Plateau fit value to give Green/Red Result"<<std::endl;
208 out<<
"Green/Red Threshold: Threshold : mean of gaussian fit value to give Green/Red Result"<<std::endl;
209 out<<
"Green/Red Threshold: Resolution : sigma of gaussian fit value to give Green/Red Result\n"<<std::endl;
211 out<<
"Optional Parameter: Verbose: Write out fit results to log file (set to 1)"<<std::endl;
212 out<<
"Optional Parameter: MinPoint: Minimum eff point needed to perform Algorithm"<<std::endl;
213 out<<
"Optional Parameter: MinSignificance : Minimum multiple of the error in fit paramenter by which the parameter must exceed the thresholds"<<std::endl;
214 out<<
"Optional Parameter: ImproveFit : IMPROVE is used to avoid local minima"<<std::endl;
215 out<<
"Optional Parameter: xmin: minimum x range"<<std::endl;
216 out<<
"Optional Parameter: xmax: maximum x range"<<std::endl;
217 out<<
"Optional Parameter: SubtractFromMean: value subtracted from XMean before test is applied: allows using AbsXMean for non-zero expected mean"<<std::endl;