10 #include "TVirtualFitter.h" 11 #include "TFitResult.h" 21 #include "Math/MinimizerOptions.h" 35 <<
" NULL pointer to base Analysis object!";
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) {
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;
const VFloat & turnOn(const std::string &key)
CommissioningAnalysis *const anal() const
static const float maxDecayTimeThreshold_
static const char unexpectedTask_[]
const Histo & histo(std::string &key, int &i)
__constant__ float const minz[nPairs]
double fdecay(double *x, double *par)
std::vector< TGraph * > riseTime_vs_isha_
Utility class that holds histogram title.
static const float minAmplitudeThreshold_
std::map< std::string, VFloat > turnOn_
float turnOn(TF1 *, const float &)
std::map< std::string, VFloat > tail_
const VFloat & tail(const std::string &key)
static const float minBaselineThreshold_
CalibrationScanAlgorithm()
const VFloat & chi2(const std::string &key)
std::map< std::string, VFloat > decayTime_
std::vector< int > scanned_isha_
std::vector< int > scanned_vfs_
const VFloat & amplitude(const std::string &key)
static const float minDecayTimeThreshold_
static const float maxTurnOnThreshold_
std::map< std::string, VFloat > amplitude_
std::map< std::string, std::vector< Histo > > histo_
double fturnOn(double *x, double *par)
std::map< std::string, VBool > isvalid_
std::vector< TGraph2D * > riseTime_vs_isha_vfs_
uint32_t extractFedKey(const TH1 *const)
const VBool isValid(const std::string &key)
static const float maxISHAforVFSTune_
static const float maxPeakTimeThreshold_
static const char mlCommissioning_[]
const VFloat & baseline(const std::string &key)
static const float maxChi2Threshold_
const VFloat & decayTime(const std::string &key)
std::map< std::string, VFloat > riseTime_
Analysis for calibration scans.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
std::vector< TGraph2D * > decayTime_vs_isha_vfs_
virtual void addErrorCode(const std::string &error)
static const float VFSrange_
static const float maxRiseTimeThreshold_
const uint32_t & fedKey() const
const VFloat & peakTime(const std::string &key)
static const float minISHAforVFSTune_
const VFloat & undershoot(const std::string &key)
void fillTunedObservables(const int &)
const VFloat & smearing(const std::string &key)
double fdeconv(double *x, double *par)
void correctDistribution(TH1 *, const bool &) const
std::pair< TH1 *, std::string > Histo
void addOneCalibrationPoint(const std::string &key)
std::vector< TGraph * > decayTime_vs_vfs_
std::map< std::string, VFloat > smearing_
void tuneIndependently(const int &, const float &, const float &)
std::map< std::string, VFloat > baseline_
static const float minPeakTimeThreshold_
const VFloat & riseTime(const std::string &key)
CalibrationScanAnalysis * cal_
std::map< std::string, VFloat > peakTime_
static const float minRiseTimeThreshold_
std::map< std::string, VFloat > undershoot_
Abstract base for derived classes that provide analysis of commissioning histograms.
Log< level::Warning, false > LogWarning
static const float maxBaselineThreshold_
std::map< std::string, VFloat > chi2_
void extract(const std::vector< TH1 *> &) override
void tuneSimultaneously(const int &, const float &, const float &)
static const float minTurnOnThreshold_
Power< A, B >::type pow(const A &a, const B &b)