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, xma, xmin_fit, xmax_fit;
372 while ((
chi2 > 1. && iter < 5) || iter < 2) {
373 xmin_fit =
p1 - nsigmalow * sigma;
374 xmax_fit =
p1 + nsigmaup * sigma;
375 xmi =
p1 - 5 * sigma;
376 xma =
p1 + 5 * sigma;
379 sprintf(
suffix,
"_iter_%d", iter);
380 auto fitFunc = std::make_unique<TF1>(
"FitFunc" + TString(
suffix),
"gaus", xmin_fit, xmax_fit);
381 fitFunc->SetParameters(nor,
p1, sigma);
382 fitFunc->SetLineColor((
int)(iter + 1));
383 fitFunc->SetLineWidth(1);
385 histoou->Fit(fitFunc.get(),
"qR0+",
"");
387 histoou->GetXaxis()->SetRangeUser(xmi, xma);
388 histoou->GetXaxis()->SetLabelSize(0.055);
391 par[0] = (fitFunc->GetParameters())[0];
392 par[1] = (fitFunc->GetParameters())[1];
393 par[2] = (fitFunc->GetParameters())[2];
394 errpar[0] = (fitFunc->GetParErrors())[0];
395 errpar[1] = (fitFunc->GetParErrors())[1];
396 errpar[2] = (fitFunc->GetParErrors())[2];
397 if (fitFunc->GetNDF() != 0) {
398 chi2 = fitFunc->GetChisquare() / (fitFunc->GetNDF());
406 std::cout <<
"WARNING: Not enough NDF" << std::endl;