6 #include <dqm_core/AlgorithmConfig.h>
15 #include <dqm_core/AlgorithmManager.h>
39 const TObject &
object,
40 const dqm_core::AlgorithmConfig &
config )
44 if (!
object.
IsA()->InheritsFrom(
"TH1")) {
45 throw dqm_core::BadConfig(ERS_HERE,
name,
"does not inherit from TH1");
47 std::unique_ptr<TH1>
histogram(
static_cast<TH1 *
>(
object.Clone()));
49 throw dqm_core::BadConfig(ERS_HERE,
name,
"dimension > 2");
60 double t0_low_warning;
62 double t0_high_warning;
64 double tmax_low_warning;
65 double tmax_low_error;
66 double tmax_high_warning;
67 double tmax_high_error;
78 catch ( dqm_core::Exception & ex ) {
79 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
91 TF1* t0Fit =
histogram->GetFunction(
"func1");
92 TF1* tmaxFit =
histogram->GetFunction(
"func2");
94 if(!t0Fit || !tmaxFit){
98 t0 = t0Fit->GetParameter(1);
99 tmax = tmaxFit->GetParameter(1);
101 t0Err = t0Fit->GetParameter(2);
102 tmaxErr = tmaxFit->GetParameter(2);
106 ERS_DEBUG(1,
m_name <<
" TDrift " <<
" is " << tdrift );
107 ERS_DEBUG(1,
"Green threshold: "<< t0_low_warning <<
" < t0 < "<< t0_high_warning <<
" && " << tmax_low_warning <<
" < tmax < " << tmax_high_warning <<
108 " ; Red threshold : t0 < " << t0_low_error <<
"\n" <<
109 "t0 > " << t0_high_error <<
"\n" <<
110 "tmax > " << tmax_high_error <<
"\n" <<
111 "tmax < " << tmax_low_error
114 std::map<std::string,double>
tags;
116 if (t0 > t0_low_warning && t0 < t0_high_warning && tmax < tmax_high_warning && tmax > tmax_low_warning && std::abs(tdrift) < 1000) {
119 else if (t0 > t0_low_error && t0 < t0_high_error && tmax < tmax_high_error && tmax > tmax_low_error && std::abs(tdrift) < 1200) {
120 if(t0 < t0_low_warning)
tags[
"t0_low_Warning"] = t0;
121 else if(t0 > t0_high_warning)
tags[
"t0_high_Warning"] = t0;
122 else tags[
"t0"] = t0;
123 if(tmax > tmax_high_warning)
tags[
"tMax_high_Warning"] = tmax;
124 else if(tmax < tmax_low_warning)
tags[
"tMax_low_Warning"] = tmax;
125 else tags[
"tMax"] = tmax;
126 if( std::abs(tdrift) > 1200 )
tags[
"tDrift_Warning"] = tdrift;
127 else tags[
"tdrift"] = tdrift;
128 result->status_ = dqm_core::Result::Yellow;
132 if(t0 < t0_low_error)
tags[
"t0_low_Error"] = t0;
133 else if(t0 > t0_high_error)
tags[
"t0_high_Error"] = t0;
134 else tags[
"t0"] = t0;
135 if(tmax > tmax_high_error)
tags[
"tMax_high_Error"] = tmax;
136 else if(tmax < tmax_low_error)
tags[
"tMax_low_Error"] = tmax;
137 else tags[
"tMax"] = tmax;
138 if( std::abs(tdrift) > 1400 )
tags[
"tDrift_Error"] = tdrift;
139 else tags[
"tdrift"] = tdrift;
145 tags[
"tdrift"] = tdrift;
148 tags[
"t0_FitError"] = t0Err;
151 if(tmaxErr > 2.*tmax) {
152 tags[
"tmax_FitError"] = tmaxErr;
166 out <<
"Analyze pre-fitted MDTTDC spectra histograms" << std::endl;
167 out <<
"Required Parameters: name " <<
m_name <<
", t0Warning threshold" <<
", tMaxWarning threshold" << std::endl;
168 out <<
"Required parameters: t0Error" <<
", tMaxError " << std::endl;
169 out <<
"Returns yellow if t0 < t0Warning or t0 > 800 or if tMax > tMaxWarning or tMax < 800" << std::endl;
170 out <<
"Returns red if t0 < t0Error or t0 > 1000 or if tMax > tMaxError or tMax < 700" << std::endl;
171 out <<
"Returns red if t0Err > 2.*t0 or tMaxErr > 2.*tMax" << std::endl;
172 out <<
"Requires that a histogram has a function named \"func1\" for the t0 fit and \"func2\" for the tMax fit" << std::endl;
180 double up =
h->GetBinCenter(
h->GetMaximumBin()+1);
181 if(
up > 200 )
up = 200;
182 double down =
up + 650;
183 if(
up < 50 )
up = 50;
184 double parESD0 =
h->GetBinContent(
h->GetMinimumBin());
187 double parESD3 =
h->GetBinContent(
h->GetMaximumBin()) -
h->GetBinContent(
h->GetMinimumBin());
188 std::unique_ptr<TF1> func1 = std::make_unique<TF1>(
"func1",
"[0]+([3]/(1+(TMath::Exp((-x+[1])/[2]))))", 0,
up);
189 func1->SetParameters(parESD0, parESD1, parESD2, parESD3);
190 if(
h->GetEntries()>100){
191 h->Fit(
"func1",
"NRQ");
192 t0 = func1->GetParameter(1) ;
193 t0err = func1->GetParError(1);
194 double binAtT0 = (
double)
h->GetBinContent(
h->FindBin(t0));
195 if(binAtT0<1) binAtT0 = 1;
196 t0err += 10.0 * func1->GetChisquare() / (0.01*binAtT0*binAtT0*(
double)func1->GetNumberFitPoints());
199 parESD0 =
h->GetBinContent(
h->GetMinimumBin());
202 parESD3 = (
h->GetBinContent(
h->GetMaximumBin())-
h->GetBinContent(
h->GetMinimumBin()))/10.;
203 std::unique_ptr<TF1> func2 = std::make_unique<TF1>(
"func2",
"[0]+([3]/(1+(TMath::Exp((x-[1])/[2]))))", down-135, down+135);
204 func2->SetParameters(parESD0,parESD1,parESD2,parESD3);
205 if(
h->GetEntries()>100){
206 func2->SetParLimits(0, parESD0, 2.0*parESD0+1);
207 func2->SetParLimits(2, 5, 90);
208 func2->SetParLimits(3, 0.2*parESD3, 7*parESD3);
209 h->Fit(
"func2",
"WWNRQ+");
210 tmax = func2->GetParameter(1);
211 tmaxerr = func2->GetParError(1);
212 double binAtTmax = (
double)
h->GetBinContent(
h->FindBin(tmax));
213 if(binAtTmax<1) binAtTmax = 1;
214 tmaxerr += 10.0 * func2->GetChisquare() / (0.01*binAtTmax*binAtTmax*(
double)func2->GetNumberFitPoints());