10 #include "TVirtualFitter.h" 11 #include "TFitResult.h" 21 #include "Math/MinimizerOptions.h" 38 <<
"[CalibrationScanAlgorithm::" << __func__ <<
"]" 39 <<
" NULL pointer to base Analysis object!";
47 <<
"[CalibrationScanAlgorithm::" << __func__ <<
"]" 48 <<
" NULL pointer to derived Analysis object!";
57 std::vector<TH1*>::const_iterator ihis = histos.begin();
59 for ( ; ihis != histos.end(); ihis++,cnt++ ) {
62 if ( !(*ihis) ) {
continue; }
75 histo_temp.first = *ihis;
76 histo_temp.first->Sumw2();
77 histo_temp.second = (*ihis)->GetTitle();
79 if(
title.channel()%2 == 0)
89 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Migrad");
90 ROOT::Math::MinimizerOptions::SetDefaultStrategy(0);
94 <<
"[CalibrationScanAlgorithm::" << __func__ <<
"]" 95 <<
" NULL pointer to derived Analysis object!";
100 TFitResultPtr fit_result;
101 TF1* fit_function_turnOn =
nullptr;
102 TF1* fit_function_decay =
nullptr;
103 TF1* fit_function_deco =
nullptr;
105 fit_function_deco =
new TF1(
"fit_function_deco",
fdeconv,0,400,7);
106 fit_function_deco->SetParameters(4,25,25,50,250,25,0.75);
108 fit_function_turnOn =
new TF1(
"fit_function_turnOn",
fturnOn,0,400,4);
109 fit_function_decay =
new TF1(
"fit_function_decay",
fdecay,0,400,3);
110 fit_function_turnOn->SetParameters(50,50,40,20);
111 fit_function_decay->SetParameters(-150,-0.01,-0.1);
115 for(
auto map_element :
histo_){
121 std::vector<std::string> tokens;
123 std::istringstream tokenStream(map_element.first);
124 while (std::getline(tokenStream, token,
'_')){
125 tokens.push_back(token);
132 for(
size_t iapv = 0; iapv < 2; iapv++){
134 if ( !map_element.second[iapv].first ) {
136 <<
" NULL pointer to histogram for: "<<map_element.second[iapv].second<<
" !";
146 cal_->
tail_[map_element.first][iapv] = 0;
149 cal_->
chi2_[map_element.first][iapv] = 0;
152 if(map_element.second[iapv].first->Integral() == 0){
161 float error= (map_element.second[iapv].first->GetMaximum()*0.05);
162 for(
int i = 1;
i <= map_element.second[iapv].first->GetNbinsX(); ++
i)
163 map_element.second[iapv].first->SetBinError(
i,error);
167 fit_function_deco->SetParameters(4,25,25,50,250,25,0.75);
168 fit_result = map_element.second[iapv].first->Fit(fit_function_deco,
"QRS");
170 if(not fit_result.Get()){
176 float maximum_ampl = fit_function_deco->GetMaximum();
177 float peak_time = fit_function_deco->GetMaximumX();
178 float baseline =
baseLine(fit_function_deco);
179 float turn_on_time =
turnOn(fit_function_deco,baseline);
180 float rise_time = peak_time - turn_on_time;
183 cal_->
amplitude_[map_element.first][iapv] = maximum_ampl - baseline;
186 cal_->
turnOn_[map_element.first][iapv] = turn_on_time;
188 if(fit_function_deco->GetMinimumX() > rise_time)
189 cal_->
undershoot_[map_element.first][iapv] = 100*(fit_function_deco->GetMinimum()-baseline)/(maximum_ampl - baseline);
194 int lastBin = map_element.second[iapv].first->FindBin(peak_time + 125);
195 if(lastBin > map_element.second[iapv].first->GetNbinsX()-4)
196 lastBin = map_element.second[iapv].first->GetNbinsX()-4;
199 cal_->
tail_[map_element.first][iapv] = 100*(map_element.second[iapv].first->GetBinContent(lastBin)-baseline) / (maximum_ampl - baseline);
204 cal_->
chi2_[map_element.first][iapv] = fit_function_deco->GetChisquare()/(map_element.second[iapv].first->GetNbinsX()-fit_function_deco->GetNpar());
210 fit_function_turnOn->SetParameters(50,50,40,20);
211 fit_function_turnOn->SetRange(fit_function_turnOn->GetXmin(),map_element.second[iapv].first->GetBinCenter(map_element.second[iapv].first->GetMaximumBin()));
212 fit_result = map_element.second[iapv].first->Fit(fit_function_turnOn,
"QSR");
213 if(not fit_result.Get()){
219 float maximum_ampl = fit_function_turnOn->GetMaximum();
220 float peak_time = fit_function_turnOn->GetMaximumX();
221 float baseline =
baseLine(fit_function_turnOn);
222 float turn_on_time =
turnOn(fit_function_turnOn,baseline);
223 float rise_time = peak_time - turn_on_time;
226 cal_->
amplitude_[map_element.first][iapv] = maximum_ampl - baseline;
229 cal_->
turnOn_[map_element.first][iapv] = turn_on_time;
232 fit_function_decay->SetParameters(-150,-0.01,-0.1);
233 fit_function_decay->SetRange(map_element.second[iapv].first->GetBinCenter(map_element.second[iapv].first->GetMaximumBin())+10.,fit_function_decay->GetXmax());
234 fit_result = map_element.second[iapv].first->Fit(fit_function_decay,
"QSR+");
236 if(fit_result.Get() and fit_result->Status() >= 4){
244 int lastBin = map_element.second[iapv].first->FindBin(peak_time + 125);
245 if(lastBin > map_element.second[iapv].first->GetNbinsX()-4)
246 lastBin = map_element.second[iapv].first->GetNbinsX()-4;
249 cal_->
tail_[map_element.first][iapv] = 100*(map_element.second[iapv].first->GetBinContent(lastBin)-baseline) / (maximum_ampl - baseline);
254 cal_->
chi2_[map_element.first][iapv] = (fit_function_turnOn->GetChisquare()+fit_function_decay->GetChisquare())/(map_element.second[iapv].first->GetNbinsX()-fit_function_turnOn->GetNpar()-fit_function_decay->GetNpar());
278 cal_->
tail_[map_element.first][iapv] = 0;
281 cal_->
chi2_[map_element.first][iapv] = 0;
288 if(fit_function_deco)
delete fit_function_deco;
289 if(fit_function_decay)
delete fit_function_decay;
290 if(fit_function_turnOn)
delete fit_function_turnOn;
298 for(
int iBin = 0; iBin < histo->GetNbinsX(); iBin++){
299 histo->SetBinContent(iBin+1,-histo->GetBinContent(iBin+1)/16.);
300 histo->SetBinContent(iBin+1,histo->GetBinContent(iBin+1)/5.);
304 histo->Scale(1./histo->Integral());
309 float x = f->GetXmin();
313 for( ; x <
xmax; x += 0.1) {
314 baseline += f->Eval(x);
322 float max_amplitude = f->GetMaximum();
324 for( ; time < 100 && (f->Eval(time) - baseline) < 0.05 * (max_amplitude - baseline); time += 0.1) {}
330 float xval =
std::max(f->GetXmin(),f->GetMaximumX());
331 float max_amplitude = f->GetMaximum();
333 for(; x < 1000; x = x+0.1){
334 if(f->Eval(x) < max_amplitude*
exp(-1))
343 std::map<int,std::vector<float> > decayTime_vs_vfs;
347 for(
auto map_element :
histo_){
359 name = Form(
"%s",map_element.second[iapv].first->GetName());
360 name.ReplaceAll(
"_"+map_element.first,
"");
366 for(
auto iter : decayTime_vs_vfs)
367 sort(iter.second.begin(),iter.second.end());
369 name.ReplaceAll(
"ExpertHisto_",
"");
379 if(!decayTime_vs_vfs.empty()){
381 for(
auto map_element : decayTime_vs_vfs){
382 if(!map_element.second.empty()){
383 cal_->
decayTime_vs_vfs_.at(iapv)->SetPoint(ipoint,map_element.second.at(round(map_element.second.size()/2)),map_element.first);
398 std::map<int,std::vector<float> > riseTime_vs_isha;
401 for(
auto map_element : histo_){
405 name = Form(
"%s",map_element.second[iapv].first->GetName());
406 name.ReplaceAll(
"_"+map_element.first,
"");
412 for(
auto iter : riseTime_vs_isha)
413 sort(iter.second.begin(),iter.second.end());
414 name.ReplaceAll(
"ExpertHisto_",
"");
417 if(!riseTime_vs_isha.empty()){
419 for(
auto map_element : riseTime_vs_isha){
420 if(!map_element.second.empty()){
421 cal_->
riseTime_vs_isha_.at(iapv)->SetPoint(ipoint,map_element.second.at(round(map_element.second.size()/2)),map_element.first);
451 for(
auto map_element :
histo_){
458 name_apv = Form(
"%s",map_element.second[iapv].first->GetName());
459 name_apv.ReplaceAll(
"_"+map_element.first,
"");
464 name_apv.ReplaceAll(
"ExpertHisto_",
"");
470 TH2F* hist_decay_apv =
new TH2F(
"hist_decay_apv",
"hist_decay_apv",
474 TH2F* hist_rise_apv = (TH2F*) hist_decay_apv->Clone();
475 hist_rise_apv->SetName(
"hist_rise_apv");
476 hist_rise_apv->Reset();
478 TH2F* hist_distance = (TH2F*) hist_decay_apv->Clone();
479 hist_distance->SetName(
"hist_distance");
480 hist_distance->Reset();
482 for(
int iBin = 1; iBin <= hist_decay_apv->GetNbinsX(); iBin++){
483 for(
int jBin = 1; jBin <= hist_decay_apv->GetNbinsY(); jBin++){
486 hist_decay_apv->SetBinContent(iBin,jBin,
cal_->
decayTime_vs_isha_vfs_.at(iapv)->Interpolate(hist_decay_apv->GetXaxis()->GetBinCenter(iBin),hist_decay_apv->GetYaxis()->GetBinCenter(jBin)));
488 hist_rise_apv->SetBinContent(iBin,jBin,
cal_->
riseTime_vs_isha_vfs_.at(iapv)->Interpolate(hist_rise_apv->GetXaxis()->GetBinCenter(iBin),hist_rise_apv->GetYaxis()->GetBinCenter(jBin)));
494 hist_decay_apv->Smooth();
495 hist_rise_apv->Smooth();
497 for(
int iBin = 1; iBin <= hist_decay_apv->GetNbinsX(); iBin++){
498 for(
int jBin = 1; jBin <= hist_decay_apv->GetNbinsY(); jBin++){
499 hist_distance->SetBinContent(iBin,jBin,
sqrt(
pow((hist_decay_apv->GetBinContent(iBin,jBin)-targetDecayTime)/targetDecayTime,2)+
500 pow((hist_rise_apv->GetBinContent(iBin,jBin)-targetRiseTime)/targetRiseTime,2)));
505 hist_distance->GetMinimumBin(minx,miny,minz);
507 cal_->
isha_[iapv] = round(hist_distance->GetXaxis()->GetBinCenter(minx));
508 cal_->
vfs_[iapv] = round(hist_distance->GetYaxis()->GetBinCenter(miny));
510 delete hist_decay_apv;
511 delete hist_rise_apv;
512 delete hist_distance;
519 int distance_apv = 10000;
529 distance_apv = 10000;
const VFloat & turnOn(const std::string &key)
static const float maxDecayTimeThreshold_
static const char unexpectedTask_[]
const uint32_t & fedKey() const
std::map< std::string, VFloat > smearing_
const Histo & histo(std::string &key, int &i)
std::map< std::string, VFloat > undershoot_
double fdecay(double *x, double *par)
std::vector< TGraph * > riseTime_vs_isha_
Utility class that holds histogram title.
std::map< std::string, VFloat > decayTime_
static const float minAmplitudeThreshold_
std::pair< TH1 *, std::string > Histo
float turnOn(TF1 *, const float &)
std::map< std::string, VFloat > tail_
const VFloat & tail(const std::string &key)
std::map< std::string, VFloat > peakTime_
static const float minBaselineThreshold_
CalibrationScanAlgorithm()
const VFloat & chi2(const std::string &key)
std::vector< int > scanned_isha_
std::vector< int > scanned_vfs_
const VFloat & amplitude(const std::string &key)
static const float minDecayTimeThreshold_
std::map< std::string, VFloat > chi2_
static const float maxTurnOnThreshold_
void extract(const std::vector< TH1 * > &) override
double fturnOn(double *x, double *par)
std::map< std::string, std::vector< Histo > > histo_
std::vector< TGraph2D * > riseTime_vs_isha_vfs_
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)
uint32_t extractFedKey(const TH1 *const )
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 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)
std::map< std::string, VFloat > amplitude_
std::map< std::string, VFloat > riseTime_
void addOneCalibrationPoint(const std::string &key)
std::vector< TGraph * > decayTime_vs_vfs_
std::map< std::string, VFloat > turnOn_
std::vector< std::vector< double > > tmp
void tuneIndependently(const int &, const float &, const float &)
static const float minPeakTimeThreshold_
const VFloat & riseTime(const std::string &key)
CalibrationScanAnalysis * cal_
std::map< std::string, VBool > isvalid_
static const float minRiseTimeThreshold_
Abstract base for derived classes that provide analysis of commissioning histograms.
static const float maxBaselineThreshold_
void correctDistribution(TH1 *, const bool &) const
void tuneSimultaneously(const int &, const float &, const float &)
std::map< std::string, VFloat > baseline_
static const float minTurnOnThreshold_
Power< A, B >::type pow(const A &a, const B &b)
CommissioningAnalysis *const anal() const