10 #include "TVirtualFitter.h"
11 #include "TFitResult.h"
21 #include "Math/MinimizerOptions.h"
35 <<
" NULL pointer to base Analysis object!";
40 cal_ = dynamic_cast<CalibrationScanAnalysis*>(
tmp);
43 <<
" NULL pointer to derived Analysis object!";
53 std::vector<TH1*>::const_iterator ihis =
histos.begin();
55 for (; ihis !=
histos.end(); ihis++, cnt++) {
70 histo_temp.first = *ihis;
71 histo_temp.first->Sumw2();
72 histo_temp.second = (*ihis)->GetTitle();
74 if (
title.channel() % 2 == 0)
83 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Migrad");
84 ROOT::Math::MinimizerOptions::SetDefaultStrategy(0);
88 <<
" NULL pointer to derived Analysis object!";
93 TFitResultPtr fit_result;
94 TF1* fit_function_turnOn =
nullptr;
95 TF1* fit_function_decay =
nullptr;
96 TF1* fit_function_deco =
nullptr;
98 fit_function_deco =
new TF1(
"fit_function_deco",
fdeconv, 0, 400, 7);
99 fit_function_deco->SetParameters(4, 25, 25, 50, 250, 25, 0.75);
101 fit_function_turnOn =
new TF1(
"fit_function_turnOn",
fturnOn, 0, 400, 4);
102 fit_function_decay =
new TF1(
"fit_function_decay",
fdecay, 0, 400, 3);
103 fit_function_turnOn->SetParameters(50, 50, 40, 20);
104 fit_function_decay->SetParameters(-150, -0.01, -0.1);
108 for (
auto map_element :
histo_) {
113 std::vector<std::string> tokens;
115 std::istringstream tokenStream(map_element.first);
116 while (std::getline(tokenStream,
token,
'_')) {
117 tokens.push_back(
token);
124 for (
size_t iapv = 0; iapv < 2; iapv++) {
125 if (!map_element.second[iapv].first) {
127 <<
" NULL pointer to histogram for: " << map_element.second[iapv].second <<
" !";
137 cal_->
tail_[map_element.first][iapv] = 0;
140 cal_->
chi2_[map_element.first][iapv] = 0;
143 if (map_element.second[iapv].first->Integral() == 0) {
152 float error = (map_element.second[iapv].first->GetMaximum() * 0.05);
153 for (
int i = 1;
i <= map_element.second[iapv].first->GetNbinsX(); ++
i)
154 map_element.second[iapv].first->SetBinError(
i,
error);
158 fit_function_deco->SetParameters(4, 25, 25, 50, 250, 25, 0.75);
159 fit_result = map_element.second[iapv].first->Fit(fit_function_deco,
"QRS");
161 if (not fit_result.Get()) {
167 float maximum_ampl = fit_function_deco->GetMaximum();
168 float peak_time = fit_function_deco->GetMaximumX();
169 float baseline =
baseLine(fit_function_deco);
170 float turn_on_time =
turnOn(fit_function_deco, baseline);
171 float rise_time = peak_time - turn_on_time;
174 cal_->
amplitude_[map_element.first][iapv] = maximum_ampl - baseline;
177 cal_->
turnOn_[map_element.first][iapv] = turn_on_time;
179 if (fit_function_deco->GetMinimumX() > rise_time)
181 100 * (fit_function_deco->GetMinimum() - baseline) / (maximum_ampl - baseline);
186 int lastBin = map_element.second[iapv].first->FindBin(peak_time + 125);
187 if (lastBin > map_element.second[iapv].first->GetNbinsX() - 4)
188 lastBin = map_element.second[iapv].first->GetNbinsX() - 4;
192 100 * (map_element.second[iapv].first->GetBinContent(lastBin) - baseline) / (maximum_ampl - baseline);
198 fit_function_deco->GetChisquare() /
199 (map_element.second[iapv].first->GetNbinsX() - fit_function_deco->GetNpar());
203 fit_function_turnOn->SetParameters(50, 50, 40, 20);
204 fit_function_turnOn->SetRange(fit_function_turnOn->GetXmin(),
205 map_element.second[iapv].first->GetBinCenter(
206 map_element.second[iapv].first->GetMaximumBin()));
207 fit_result = map_element.second[iapv].first->Fit(fit_function_turnOn,
"QSR");
208 if (not fit_result.Get()) {
214 float maximum_ampl = fit_function_turnOn->GetMaximum();
215 float peak_time = fit_function_turnOn->GetMaximumX();
216 float baseline =
baseLine(fit_function_turnOn);
217 float turn_on_time =
turnOn(fit_function_turnOn, baseline);
218 float rise_time = peak_time - turn_on_time;
221 cal_->
amplitude_[map_element.first][iapv] = maximum_ampl - baseline;
224 cal_->
turnOn_[map_element.first][iapv] = turn_on_time;
227 fit_function_decay->SetParameters(-150, -0.01, -0.1);
228 fit_function_decay->SetRange(
229 map_element.second[iapv].first->GetBinCenter(map_element.second[iapv].first->GetMaximumBin()) + 10.,
230 fit_function_decay->GetXmax());
231 fit_result = map_element.second[iapv].first->Fit(fit_function_decay,
"QSR+");
233 if (fit_result.Get() and fit_result->Status() >= 4) {
241 int lastBin = map_element.second[iapv].first->FindBin(peak_time + 125);
242 if (lastBin > map_element.second[iapv].first->GetNbinsX() - 4)
243 lastBin = map_element.second[iapv].first->GetNbinsX() - 4;
247 100 * (map_element.second[iapv].first->GetBinContent(lastBin) - baseline) / (maximum_ampl - baseline);
253 (fit_function_turnOn->GetChisquare() + fit_function_decay->GetChisquare()) /
254 (map_element.second[iapv].first->GetNbinsX() - fit_function_turnOn->GetNpar() -
255 fit_function_decay->GetNpar());
291 cal_->
tail_[map_element.first][iapv] = 0;
294 cal_->
chi2_[map_element.first][iapv] = 0;
301 if (fit_function_deco)
302 delete fit_function_deco;
303 if (fit_function_decay)
304 delete fit_function_decay;
305 if (fit_function_turnOn)
306 delete fit_function_turnOn;
314 for (
int iBin = 0; iBin <
histo->GetNbinsX(); iBin++) {
315 histo->SetBinContent(iBin + 1, -
histo->GetBinContent(iBin + 1) / 16.);
316 histo->SetBinContent(iBin + 1,
histo->GetBinContent(iBin + 1) / 5.);
324 float x =
f->GetXmin();
328 for (;
x <
xmax;
x += 0.1) {
329 baseline +=
f->Eval(
x);
337 TF1*
f,
const float& baseline) {
338 float max_amplitude =
f->GetMaximum();
340 for (;
time < 100 && (
f->Eval(
time) - baseline) < 0.05 * (max_amplitude - baseline);
time += 0.1) {
348 float xval =
std::max(
f->GetXmin(),
f->GetMaximumX());
349 float max_amplitude =
f->GetMaximum();
354 if (
f->Eval(
x) < max_amplitude *
exp(-1))
364 std::map<int, std::vector<float> > decayTime_vs_vfs;
368 for (
auto map_element :
histo_) {
380 name = Form(
"%s", map_element.second[iapv].first->GetName());
381 name.ReplaceAll(
"_" + map_element.first,
"");
387 for (
auto iter : decayTime_vs_vfs)
388 sort(iter.second.begin(), iter.second.end());
390 name.ReplaceAll(
"ExpertHisto_",
"");
400 if (!decayTime_vs_vfs.empty()) {
402 for (
auto map_element : decayTime_vs_vfs) {
403 if (!map_element.second.empty()) {
405 ipoint, map_element.second.at(round(map_element.second.size() / 2)), map_element.first);
420 else if (
cal_->
vfs_[iapv] > max_apv)
424 std::map<int, std::vector<float> > riseTime_vs_isha;
427 for (
auto map_element :
histo_) {
432 name = Form(
"%s", map_element.second[iapv].first->GetName());
433 name.ReplaceAll(
"_" + map_element.first,
"");
439 for (
auto iter : riseTime_vs_isha)
440 sort(iter.second.begin(), iter.second.end());
441 name.ReplaceAll(
"ExpertHisto_",
"");
444 if (!riseTime_vs_isha.empty()) {
446 for (
auto map_element : riseTime_vs_isha) {
447 if (!map_element.second.empty()) {
449 ipoint, map_element.second.at(round(map_element.second.size() / 2)), map_element.first);
483 for (
auto map_element :
histo_) {
491 if (name_apv ==
"") {
492 name_apv = Form(
"%s", map_element.second[iapv].first->GetName());
493 name_apv.ReplaceAll(
"_" + map_element.first,
"");
498 name_apv.ReplaceAll(
"ExpertHisto_",
"");
504 TH2F* hist_decay_apv =
new TH2F(
"hist_decay_apv",
513 TH2F* hist_rise_apv = (TH2F*)hist_decay_apv->Clone();
514 hist_rise_apv->SetName(
"hist_rise_apv");
515 hist_rise_apv->Reset();
517 TH2F* hist_distance = (TH2F*)hist_decay_apv->Clone();
518 hist_distance->SetName(
"hist_distance");
519 hist_distance->Reset();
521 for (
int iBin = 1; iBin <= hist_decay_apv->GetNbinsX(); iBin++) {
522 for (
int jBin = 1; jBin <= hist_decay_apv->GetNbinsY(); jBin++) {
523 if (ipoint_apv != 0) {
525 hist_decay_apv->SetBinContent(
529 hist_decay_apv->GetYaxis()->GetBinCenter(jBin)));
531 hist_rise_apv->SetBinContent(
535 hist_rise_apv->GetYaxis()->GetBinCenter(jBin)));
541 hist_decay_apv->Smooth();
542 hist_rise_apv->Smooth();
544 for (
int iBin = 1; iBin <= hist_decay_apv->GetNbinsX(); iBin++) {
545 for (
int jBin = 1; jBin <= hist_decay_apv->GetNbinsY(); jBin++) {
546 hist_distance->SetBinContent(
554 int minx, miny,
minz;
555 hist_distance->GetMinimumBin(minx, miny,
minz);
557 cal_->
isha_[iapv] = round(hist_distance->GetXaxis()->GetBinCenter(minx));
558 cal_->
vfs_[iapv] = round(hist_distance->GetYaxis()->GetBinCenter(miny));
560 delete hist_decay_apv;
561 delete hist_rise_apv;
562 delete hist_distance;
567 int distance_apv = 10000;
577 distance_apv = 10000;