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.;
331 std::cout <<
"rescale " << rescale << std::endl;
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;
TH1 * weightedRescaleFactor[50][250]
std::string WeightFileName_
std::vector< std::pair< calib::CalibElectron *, calib::CalibElectron * > > electrons_
std::vector< float > weight_sum_
ZIterativeAlgorithmWithFit()
Default constructor.
void getWeight(unsigned int evid, std::pair< calib::CalibElectron *, calib::CalibElectron *>, float)
unsigned int currentEvent_
virtual ~ZIterativeAlgorithmWithFit()
Destructor.
bool addEvent(calib::CalibElectron *, calib::CalibElectron *, float)
std::vector< float > optimizedCoefficients_
static void gausfit(TH1F *histoou, double *par, double *errpar, float nsigmalow, float nsigmaup, double *mychi2, int *iterations)
unsigned int numberOfIterations_
unsigned int currentIteration_
T getUntrackedParameter(std::string const &, T const &) const
TH1 * unweightedRescaleFactor[50][250]
U second(std::pair< T, U > const &p)
std::vector< int > optimizedIterations_
std::vector< float > optimizedChiSquare_
std::vector< float > calib_fac_
unsigned int totalEvents_
float getEventWeight(unsigned int event_id)
static float invMassCalc(float Energy1, float Eta1, float Phi1, float Energy2, float Eta2, float Phi2)
std::vector< float > StatWeights_
ZIterativeAlgorithmWithFitPlots * thePlots_
const reco::GsfElectron * getRecoElectron()
void getStatWeights(const std::string &file)
std::vector< float > optimizedCoefficientsError_
double phi() const final
momentum azimuthal angle
T mod(const T &a, const T &b)
SuperClusterRef superCluster() const override
reference to a SuperCluster
std::vector< float > massReco_
double eta() const final
momentum pseudorapidity