10 #include "TVirtualFitter.h" 11 #include "TFitResultPtr.h" 12 #include "TFitResult.h" 17 #include "Math/MinimizerOptions.h" 35 <<
"[CalibrationAlgorithm::" << __func__ <<
"]" 36 <<
" NULL pointer to base Analysis object!";
45 <<
"[CalibrationAlgorithm::" << __func__ <<
"]" 46 <<
" NULL pointer to derived Analysis object!";
54 std::vector<TH1*>::const_iterator ihis = histos.begin();
56 for ( ; ihis != histos.end(); ihis++,cnt++ ) {
59 if ( !(*ihis) ) {
continue; }
71 std::vector<std::string> tokens;
73 std::istringstream tokenStream(
title.extraInfo());
74 while (std::getline(tokenStream, token,
'_')){
75 tokens.push_back(token);
80 histo_temp.first = *ihis;
81 histo_temp.second = (*ihis)->GetTitle();
82 histo_temp.first->Sumw2();
83 histo_.push_back(histo_temp);
85 stripId_.push_back(std::stoi(tokens.at(1))*16+std::stoi(tokens.at(3)));
86 calChan_.push_back(std::stoi(tokens.at(1)));
94 ROOT::Math::MinimizerOptions::SetDefaultMinimizer(
"Minuit2",
"Migrad");
95 ROOT::Math::MinimizerOptions::SetDefaultStrategy(0);
99 <<
"[CalibrationAlgorithm::" << __func__ <<
"]" 100 <<
" NULL pointer to derived Analysis object!";
104 float Amean[2] = {-1.,-1.};
105 float Amin[2] = {-1.,-1.};
106 float Amax[2] = {-1.,-1.};
107 float Aspread[2] = {-1.,-1.};
108 float Tmean[2] = {-1.,-1.};
109 float Tmin[2] = {-1.,-1.};
110 float Tmax[2] = {-1.,-1.};
111 float Tspread[2] = {-1.,-1.};
112 float Rmean[2] = {-1.,-1.};
113 float Rmin[2] = {-1.,-1.};
114 float Rmax[2] = {-1.,-1.};
115 float Rspread[2] = {-1.,-1.};
116 float Cmean[2] = {-1.,-1.};
117 float Cmin[2] = {-1.,-1.};
118 float Cmax[2] = {-1.,-1.};
119 float Cspread[2] = {-1.,-1.};
120 float Smean[2] = {-1.,-1.};
121 float Smin[2] = {-1.,-1.};
122 float Smax[2] = {-1.,-1.};
123 float Sspread[2] = {-1.,-1.};
124 float Kmean[2] = {-1.,-1.};
125 float Kmin[2] = {-1.,-1.};
126 float Kmax[2] = {-1.,-1.};
127 float Kspread[2] = {-1.,-1.};
129 float Omean[2] = {-1.,-1.};
130 float Omin[2] = {-1.,-1.};
131 float Omax[2] = {-1.,-1.};
132 float Ospread[2] = {-1.,-1.};
134 float Mmean[2] = {-1.,-1.};
135 float Mmin[2] = {-1.,-1.};
136 float Mmax[2] = {-1.,-1.};
137 float Mspread[2] = {-1.,-1.};
139 float Umean[2] = {-1.,-1.};
140 float Umin[2] = {-1.,-1.};
141 float Umax[2] = {-1.,-1.};
142 float Uspread[2] = {-1.,-1.};
144 float Bmean[2] = {-1.,-1.};
145 float Bmin[2] = {-1.,-1.};
146 float Bmax[2] = {-1.,-1.};
147 float Bspread[2] = {-1.,-1.};
150 TFitResultPtr fit_result;
151 TF1* fit_function =
nullptr;
153 fit_function =
new TF1(
"fit_function_deco",
fdeconv,0,400,7);
154 fit_function->SetParameters(4,25,25,50,250,25,0.75);
156 fit_function =
new TF1(
"fit_function_peak",
fpeak,0,400,6);
157 fit_function->SetParameters(4,50,50,70,250,20);
161 std::vector<unsigned int> nStrips (2,0.);
163 for(
size_t ihist = 0; ihist <
histo_.size(); ihist++){
167 <<
" NULL pointer to histogram for: "<<
histo_[ihist].second<<
" !";
183 if(
histo_[ihist].first->Integral() == 0){
192 float error =
histo_[ihist].first->GetMaximum()*0.05;
193 for(
int i = 1;
i<=
histo_[ihist].first->GetNbinsX(); ++
i)
194 histo_[ihist].first->SetBinError(
i,error);
198 fit_function->SetParameters(10,15,30,10,350,50,0.75);
200 fit_function->SetParameters(6,40,40,70,350,20);
202 fit_result =
histo_[ihist].first->Fit(fit_function,
"QS");
205 if(not fit_result.Get())
continue;
207 float maximum_ampl = fit_function->GetMaximum();
208 float peak_time = fit_function->GetMaximumX();
209 float baseline =
baseLine(fit_function);
210 float turn_on_time =
turnOn(fit_function,baseline);
211 float rise_time = peak_time - turn_on_time;
220 if (
cal_->
deconv_ and fit_function->GetMinimumX() > peak_time)
221 cal_->
undershoot_[
apvId_[ihist]][stripId_[ihist]] = 100*(fit_function->GetMinimum()-baseline)/(maximum_ampl - baseline);
226 int lastBin =
histo_[ihist].first->FindBin(peak_time + 125);
227 if(lastBin >
histo_[ihist].first->GetNbinsX()-4)
228 lastBin =
histo_[ihist].first->GetNbinsX()-4;
231 cal_->
tail_[
apvId_[ihist]][stripId_[ihist]] = 100*(
histo_[ihist].first->GetBinContent(lastBin)-baseline) / (maximum_ampl - baseline);
236 cal_->
chi2_[
apvId_[ihist]][stripId_[ihist]] = fit_function->GetChisquare()/(
histo_[ihist].first->GetNbinsX()-fit_function->GetNpar());
261 if(fit_function->GetMinimumX() < peak_time) isvalid =
false;
299 Amean[apvId_[ihist]] +=
cal_->
amplitude_[apvId_[ihist]][stripId_[ihist]];
300 Amin[apvId_[ihist]] = Amin[apvId_[ihist]]<
cal_->
amplitude_[apvId_[ihist]][stripId_[ihist]] ? Amin[apvId_[ihist]] :
cal_->
amplitude_[apvId_[ihist]][stripId_[ihist]];
301 Amax[apvId_[ihist]] = Amax[apvId_[ihist]]>
cal_->
amplitude_[apvId_[ihist]][stripId_[ihist]] ? Amax[apvId_[ihist]] :
cal_->
amplitude_[apvId_[ihist]][stripId_[ihist]];
304 Tmean[apvId_[ihist]] +=
cal_->
tail_[apvId_[ihist]][stripId_[ihist]];
305 Tmin[apvId_[ihist]] = Tmin[apvId_[ihist]]<
cal_->
tail_[apvId_[ihist]][stripId_[ihist]] ? Tmin[apvId_[ihist]] :
cal_->
tail_[apvId_[ihist]][stripId_[ihist]];
306 Tmax[apvId_[ihist]] = Tmax[apvId_[ihist]]>
cal_->
tail_[apvId_[ihist]][stripId_[ihist]] ? Tmax[apvId_[ihist]] :
cal_->
tail_[apvId_[ihist]][stripId_[ihist]];
307 Tspread[apvId_[ihist]] +=
cal_->
tail_[apvId_[ihist]][stripId_[ihist]]*
cal_->
tail_[apvId_[ihist]][stripId_[ihist]];
309 Rmean[apvId_[ihist]] +=
cal_->
riseTime_[apvId_[ihist]][stripId_[ihist]];
310 Rmin[apvId_[ihist]] = Rmin[apvId_[ihist]]<
cal_->
riseTime_[apvId_[ihist]][stripId_[ihist]] ? Rmin[apvId_[ihist]] :
cal_->
riseTime_[apvId_[ihist]][stripId_[ihist]];
311 Rmax[apvId_[ihist]] = Rmax[apvId_[ihist]]>
cal_->
riseTime_[apvId_[ihist]][stripId_[ihist]] ? Rmax[apvId_[ihist]] :
cal_->
riseTime_[apvId_[ihist]][stripId_[ihist]];
314 Cmean[apvId_[ihist]] +=
cal_->
decayTime_[apvId_[ihist]][stripId_[ihist]];
315 Cmin[apvId_[ihist]] = Cmin[apvId_[ihist]]<
cal_->
decayTime_[apvId_[ihist]][stripId_[ihist]] ? Cmin[apvId_[ihist]] :
cal_->
decayTime_[apvId_[ihist]][stripId_[ihist]];
316 Cmax[apvId_[ihist]] = Cmax[apvId_[ihist]]>
cal_->
decayTime_[apvId_[ihist]][stripId_[ihist]] ? Cmax[apvId_[ihist]] :
cal_->
decayTime_[apvId_[ihist]][stripId_[ihist]];
319 Smean[apvId_[ihist]] +=
cal_->
smearing_[apvId_[ihist]][stripId_[ihist]];
320 Smin[apvId_[ihist]] = Smin[apvId_[ihist]]<
cal_->
smearing_[apvId_[ihist]][stripId_[ihist]] ? Smin[apvId_[ihist]] :
cal_->
smearing_[apvId_[ihist]][stripId_[ihist]];
321 Smax[apvId_[ihist]] = Smax[apvId_[ihist]]>
cal_->
smearing_[apvId_[ihist]][stripId_[ihist]] ? Smax[apvId_[ihist]] :
cal_->
smearing_[apvId_[ihist]][stripId_[ihist]];
324 Kmean[apvId_[ihist]] +=
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]];
325 Kmin[apvId_[ihist]] = Kmin[apvId_[ihist]]<
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]] ? Kmin[apvId_[ihist]] :
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]];
326 Kmax[apvId_[ihist]] = Kmax[apvId_[ihist]]>
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]] ? Kmax[apvId_[ihist]] :
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]];
327 Kspread[apvId_[ihist]] +=
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]]*
cal_->
chi2_[apvId_[ihist]][stripId_[ihist]];
329 Omean[apvId_[ihist]] +=
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]];
330 Omin[apvId_[ihist]] = Omin[apvId_[ihist]]<
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]] ? Omin[apvId_[ihist]] :
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]];
331 Omax[apvId_[ihist]] = Omax[apvId_[ihist]]>
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]] ? Omax[apvId_[ihist]] :
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]];
332 Ospread[apvId_[ihist]] +=
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]]*
cal_->
turnOn_[apvId_[ihist]][stripId_[ihist]];
334 Mmean[apvId_[ihist]] +=
cal_->
peakTime_[apvId_[ihist]][stripId_[ihist]];
335 Mmin[apvId_[ihist]] = Mmin[apvId_[ihist]]<
cal_->
peakTime_[apvId_[ihist]][stripId_[ihist]] ? Mmin[apvId_[ihist]] :
cal_->
peakTime_[apvId_[ihist]][stripId_[ihist]];
336 Mmax[apvId_[ihist]] = Mmax[apvId_[ihist]]>
cal_->
peakTime_[apvId_[ihist]][stripId_[ihist]] ? Mmax[apvId_[ihist]] :
cal_->
peakTime_[apvId_[ihist]][stripId_[ihist]];
339 Umean[apvId_[ihist]] +=
cal_->
undershoot_[apvId_[ihist]][stripId_[ihist]];
340 Umin[apvId_[ihist]] = Umin[apvId_[ihist]]<
cal_->
undershoot_[apvId_[ihist]][stripId_[ihist]] ? Umin[apvId_[ihist]] :
cal_->
undershoot_[apvId_[ihist]][stripId_[ihist]];
341 Umax[apvId_[ihist]] = Umax[apvId_[ihist]]>
cal_->
undershoot_[apvId_[ihist]][stripId_[ihist]] ? Umax[apvId_[ihist]] :
cal_->
undershoot_[apvId_[ihist]][stripId_[ihist]];
344 Bmean[apvId_[ihist]] +=
cal_->
baseline_[apvId_[ihist]][stripId_[ihist]];
345 Bmin[apvId_[ihist]] = Bmin[apvId_[ihist]]<
cal_->
baseline_[apvId_[ihist]][stripId_[ihist]] ? Bmin[apvId_[ihist]] :
cal_->
baseline_[apvId_[ihist]][stripId_[ihist]];
346 Bmax[apvId_[ihist]] = Bmax[apvId_[ihist]]>
cal_->
baseline_[apvId_[ihist]][stripId_[ihist]] ? Bmax[apvId_[ihist]] :
cal_->
baseline_[apvId_[ihist]][stripId_[ihist]];
352 for(
int i=0;
i < 2;
i++){
354 Amean[
i] = Amean[
i]/nStrips[
i];
355 Tmean[
i] = Tmean[
i]/nStrips[
i];
356 Rmean[
i] = Rmean[
i]/nStrips[
i];
357 Cmean[
i] = Cmean[
i]/nStrips[
i];
358 Omean[
i] = Omean[
i]/nStrips[
i];
359 Mmean[
i] = Mmean[
i]/nStrips[
i];
360 Umean[
i] = Umean[
i]/nStrips[
i];
361 Bmean[
i] = Bmean[
i]/nStrips[
i];
362 Smean[
i] = Smean[
i]/nStrips[
i];
363 Kmean[
i] = Kmean[
i]/nStrips[
i];
365 Aspread[
i] = Aspread[
i]/nStrips[
i];
366 Tspread[
i] = Tspread[
i]/nStrips[
i];
367 Rspread[
i] = Rspread[
i]/nStrips[
i];
368 Cspread[
i] = Cspread[
i]/nStrips[
i];
369 Ospread[
i] = Ospread[
i]/nStrips[
i];
370 Mspread[
i] = Mspread[
i]/nStrips[
i];
371 Uspread[
i] = Uspread[
i]/nStrips[
i];
372 Bspread[
i] = Bspread[
i]/nStrips[
i];
373 Sspread[
i] = Sspread[
i]/nStrips[
i];
374 Kspread[
i] = Kspread[
i]/nStrips[
i];
379 for(
int i=0;
i < 2; ++
i) {
426 if(fit_function)
delete fit_function;
432 for(
int iBin = 0; iBin < histo->GetNbinsX(); iBin++){
433 histo->SetBinContent(iBin+1,-histo->GetBinContent(iBin+1)/20.);
442 float x = f->GetXmin();
443 for( ; x <
xmax; x += 0.1) {
444 baseline += f->Eval(x);
453 float max_amplitude = f->GetMaximum();
455 for( ; time < 100 && (f->Eval(time) - baseline) < 0.05 * (max_amplitude - baseline); time += 0.1) {}
461 float xval = f->GetMaximumX();
462 float max_amplitude = f->GetMaximum();
464 for(; x < 1000; x = x+0.1){
465 if(f->Eval(x) < max_amplitude*
exp(-1))
static const char unexpectedTask_[]
static const float minRiseTimeThresholdDeco_
static const float maxTurnOnThreshold_
static const float maxRiseTimeThresholdDeco_
static const float minPeakTimeThreshold_
static const float maxDecayTimeThresholdDeco_
const uint32_t & fedKey() const
Utility class that holds histogram title.
static const float maxRiseTimeThreshold_
std::pair< TH1 *, std::string > Histo
void extract(const std::vector< TH1 * > &) override
static const float maxBaselineThreshold_
std::vector< int > calChan_
CalibrationAnalysis * cal_
static const float minDecayTimeThresholdDeco_
static const float minAmplitudeThreshold_
const Histo & histo(int &i)
static const float maxDecayTimeThreshold_
Analysis for calibration runs.
static const float minTurnOnThresholdDeco_
static const float minDecayTimeThreshold_
static const char mlCommissioning_[]
std::vector< int > apvId_
uint32_t extractFedKey(const TH1 *const )
static const float minPeakTimeThresholdDeco_
virtual void addErrorCode(const std::string &error)
static const float minBaselineThreshold_
std::vector< Histo > histo_
static const float maxTurnOnThresholdDeco_
VFloat spread_undershoot_
std::vector< int > stripId_
static const float minRiseTimeThreshold_
double fdeconv(double *x, double *par)
void correctDistribution(TH1 *) const
static const float minTurnOnThreshold_
static const float maxChi2Threshold_
std::vector< std::vector< double > > tmp
static const float maxPeakTimeThresholdDeco_
double fpeak(double *x, double *par)
float turnOn(TF1 *, const float &)
static const float maxPeakTimeThreshold_
const double Rmax[kNumberCalorimeter]
Abstract base for derived classes that provide analysis of commissioning histograms.
const double Rmin[kNumberCalorimeter]
CommissioningAnalysis *const anal() const