24 #include "TGraphErrors.h"
35 #define MIN_RESCALE -0.5
36 #define MAX_RESCALE 0.5
37 #define NBINS_LOWETA 100
38 #define NBINS_HIGHETA 50
81 std::cout <<
"[ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFit] channels_ = " <<
channels_ << std::endl;
118 char histoTitle[200];
121 sprintf(
histoName,
"WeightedRescaleFactor_channel_%d_Iteration_%d",
i1,
i2);
122 sprintf(histoTitle,
"WeightedRescaleFactor Channel_%d Iteration %d",
i1,
i2);
123 if (
i1 > 15 &&
i1 < 155)
133 sprintf(
histoName,
"UnweightedRescaleFactor_channel_%d_Iteration_%d",
i1,
i2);
134 sprintf(histoTitle,
"UnweightedRescaleFactor Channel_%d Iteration %d",
i1,
i2);
135 if (
i1 > 15 &&
i1 < 155)
145 sprintf(
histoName,
"Weight_channel_%d_Iteration_%d",
i1,
i2);
146 sprintf(histoTitle,
"Weight Channel_%d Iteration %d",
i1,
i2);
155 std::ifstream statfile;
156 statfile.open(
file.c_str());
158 std::cout <<
"ZIterativeAlgorithmWithFit::FATAL: stat weight file " <<
file <<
" not found" << std::endl;
197 double gausFitParameters[3], gausFitParameterErrors[3], gausFitChi2;
198 int gausFitIterations;
202 gausFitParameterErrors,
208 float peak = gausFitParameters[1];
209 float peakError = gausFitParameterErrors[1];
210 float chi2 = gausFitChi2;
212 int iters = gausFitIterations;
241 std::cout <<
"ZIterativeAlgorithmWithFit::run():Energy Rescaling Coefficient for region " <<
i <<
" is "
243 <<
" - number of events: " <<
weight_sum_[
i] << std::endl;
252 float invMassRescFactor) {
254 std::pair<calib::CalibElectron*, calib::CalibElectron*>
Electrons(ele1, ele2);
298 std::pair<calib::CalibElectron*, calib::CalibElectron*> elepair,
299 float invMassRescFactor) {
300 getWeight(event_id, elepair.first, invMassRescFactor);
301 getWeight(event_id, elepair.second, invMassRescFactor);
309 std::vector<std::pair<int, float> >
modules = (*ele).getCalibModulesWeights(
calibType_);
311 for (
int imod = 0; imod < (
int)
modules.size(); imod++) {
326 std::cout <<
"w2 " << weight2 << std::endl;
328 if (weight2 >= 0. && weight2 <= 1.) {
329 float rescale = (TMath::Power((
massReco_[event_id] / evweight), 2.) - 1) / 2.;
341 std::cout <<
"[ZIterativeAlgorithmWithFit]::[getWeight]::rescale out " <<
rescale << std::endl;
347 std::cout <<
"ZIterativeAlgorithmWithFit::FATAL:found a wrong module_id " <<
mod <<
" channels " <<
channels_
356 TH1F* histoou,
double* par,
double* errpar,
float nsigmalow,
float nsigmaup,
double* myChi2,
int* iterations) {
357 auto gausa = std::make_unique<TF1>(
358 "gausa",
"gaus", histoou->GetMean() - 3 * histoou->GetRMS(), histoou->GetMean() + 3 * histoou->GetRMS());
360 gausa->SetParameters(histoou->GetMaximum(), histoou->GetMean(), histoou->GetRMS());
362 histoou->Fit(gausa.get(),
"qR0N");
364 double p1 = gausa->GetParameter(1);
365 double sigma = gausa->GetParameter(2);
366 double nor = gausa->GetParameter(0);
368 double xmi =
p1 - 5 * sigma;
369 double xma =
p1 + 5 * sigma;
372 double xmin_fit =
p1 - nsigmalow * sigma;
373 double xmax_fit =
p1 + nsigmaup * sigma;
377 while ((
chi2 > 1. && iter < 5) || iter < 2) {
378 xmin_fit =
p1 - nsigmalow * sigma;
379 xmax_fit =
p1 + nsigmaup * sigma;
380 xmi =
p1 - 5 * sigma;
381 xma =
p1 + 5 * sigma;
384 sprintf(
suffix,
"_iter_%d", iter);
385 auto fitFunc = std::make_unique<TF1>(
"FitFunc" + TString(
suffix),
"gaus", xmin_fit, xmax_fit);
386 fitFunc->SetParameters(nor,
p1, sigma);
387 fitFunc->SetLineColor((
int)(iter + 1));
388 fitFunc->SetLineWidth(1);
390 histoou->Fit(fitFunc.get(),
"qR0+",
"");
392 histoou->GetXaxis()->SetRangeUser(xmi, xma);
393 histoou->GetXaxis()->SetLabelSize(0.055);
396 par[0] = (fitFunc->GetParameters())[0];
397 par[1] = (fitFunc->GetParameters())[1];
398 par[2] = (fitFunc->GetParameters())[2];
399 errpar[0] = (fitFunc->GetParErrors())[0];
400 errpar[1] = (fitFunc->GetParErrors())[1];
401 errpar[2] = (fitFunc->GetParErrors())[2];
402 if (fitFunc->GetNDF() != 0) {
403 chi2 = fitFunc->GetChisquare() / (fitFunc->GetNDF());
411 std::cout <<
"WARNING: Not enough NDF" << std::endl;