15 #include <TGraphAsymmErrors.h>
19 #include <dqm_core/AlgorithmManager.h>
34 m_func = std::make_unique<TF1> (
"fermi",
"[0]/(1+exp(([1]-x)/[2]))" );
37 m_func = std::make_unique<TF1> (
"erf",
"[0]*TMath::Erf((x-[1])/(sqrt(2.)*[2]))" );
40 m_func = std::make_unique<TF1> (
"flat",
"[0]" );
48 (void)m_func.release();
60 const TObject &
object,
61 const dqm_core::AlgorithmConfig &
config )
66 if(
object.
IsA()->InheritsFrom(
"TGraph" ))
68 graph =
static_cast<const TGraph*
>(&
object);
71 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TGraph" );
95 if (graph->GetN() < minpoint || graph->GetN()==0) {
96 if(
verbose)std::cout <<
name <<
" number of points are too small " << graph->GetN() << std::endl;
98 result->tags_[
"InsufficientN"] = graph->GetN();
101 if(
verbose)std::cout <<
name <<
" enough number of points " << graph->GetN() << std::endl;
103 TAxis *
x = graph->GetXaxis();
104 int nbins =
x->GetNbins();
105 double high =
x->GetBinUpEdge(
nbins);
106 double low =
x->GetBinUpEdge(0);
109 if (
xmin>high || xmin<low || xmax>high ||
xmax<low) {
110 throw dqm_core::BadConfig( ERS_HERE,
name,
"xmin and/or xmax value not in graph bin range" );
128 if ( minSig != 0 ) option +=
"E";
129 if ( improve ) option +=
"M";
132 std::cout <<
" graph name " << graph->GetName() << std::endl;
133 std::cout <<
" fit option " << option << std::endl;
136 if (m_name ==
"fermi") {
137 if(
verbose)std::cout <<
"set "<<
name<<
" parameters" << std::endl;
138 m_func->SetParameter(0,
ymax*0.9);
139 m_func->SetParameter(1,xaxismean);
140 m_func->SetParameter(2,xdiff/50.);
141 m_func->SetParNames(
"Plateau",
"Threshold",
"Resolution");
143 m_func->SetParLimits(0,
ymin - 0.1 * ydiff,
ymax + 0.1 * ydiff );
144 m_func->SetParLimits(1,
xmin,
xmax );
145 m_func->SetParLimits(2, 0., xdiff/4. );
147 else if(m_name ==
"erf") {
148 if(
verbose)std::cout <<
"set "<<
name<<
" parameters" << std::endl;
149 m_func->SetParameter(0,
ymax*0.9);
150 m_func->SetParameter(1,xaxismean);
151 m_func->SetParameter(2,xdiff/50.);
152 m_func->SetParNames(
"Plateau",
"Threshold",
"Resolution");
154 m_func->SetParLimits(0,
ymin - 0.1 * ydiff,
ymax + 0.1 * ydiff );
155 m_func->SetParLimits(1,
xmin,
xmax );
156 m_func->SetParLimits(2, 0., xdiff/4. );
158 else if(m_name ==
"flat") {
159 if(
verbose)std::cout <<
"set "<<
name<<
" parameters" << std::endl;
160 m_func->SetParNames(
"Height");
171 if(
verbose)std::cout <<
"fit "<<
name<<
" with interval cut " <<
xmin <<
" - " <<
xmax << std::endl;
172 const_cast<TGraph*
>(graph)->Fit( m_func.get(), option.c_str(),
"",
xmin,
xmax );
174 const int numsig = m_func->GetParNumber(
"Sigma");
176 double sigma=m_func->GetParameter(numsig);
177 m_func->SetParameter(numsig,std::abs(
sigma));
184 catch ( dqm_core::Exception & ex ) {
185 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
192 out<<
"Simple_"+m_name+
"_Fit_Graph: Does simple "+m_name+
" fit to graph and checks fit parameters against thresholds\n"<<std::endl;
193 if (m_name ==
"fermi" ) {
194 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;
195 out<<
"Green/Red Threshold: Plateau : Plateau fit value to give Green/Red Result"<<std::endl;
196 out<<
"Green/Red Threshold: Threshold : Fermi energy fit value to give Green/Red Result"<<std::endl;
197 out<<
"Green/Red Threshold: Resolution : Templature fit value to give Green/Red Result\n"<<std::endl;
198 }
else if (m_name ==
"erf" ) {
199 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;
200 out<<
"Green/Red Threshold: Plateau : Plateau fit value to give Green/Red Result"<<std::endl;
201 out<<
"Green/Red Threshold: Threshold : mean of gaussian fit value to give Green/Red Result"<<std::endl;
202 out<<
"Green/Red Threshold: Resolution : sigma of gaussian fit value to give Green/Red Result\n"<<std::endl;
204 out<<
"Optional Parameter: Verbose: Write out fit results to log file (set to 1)"<<std::endl;
205 out<<
"Optional Parameter: MinPoint: Minimum graph point needed to perform Algorithm"<<std::endl;
206 out<<
"Optional Parameter: MinSignificance : Minimum multiple of the error in fit paramenter by which the parameter must exceed the thresholds"<<std::endl;
207 out<<
"Optional Parameter: ImproveFit : IMPROVE is used to avoid local minima"<<std::endl;
208 out<<
"Optional Parameter: xmin: minimum x range"<<std::endl;
209 out<<
"Optional Parameter: xmax: maximum x range"<<std::endl;
210 out<<
"Optional Parameter: SubtractFromMean: value subtracted from XMean before test is applied: allows using AbsXMean for non-zero expected mean"<<std::endl;