24 #include "TGraphErrors.h"
36 #define MIN_RESCALE -0.5
37 #define MAX_RESCALE 0.5
38 #define NBINS_LOWETA 100
39 #define NBINS_HIGHETA 50
73 if (calibType_ ==
"RING")
75 else if (calibType_ ==
"MODULE")
79 else if (calibType_ ==
"ABS_SCALE")
81 else if(calibType_ ==
"ETA_ET_MODE")
84 std::cout <<
"[ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFit] channels_ = " <<
channels_ << std::endl;
121 for (
unsigned int i1 = 0; i1 <
channels_; i1++) {
123 char histoTitle[200];
126 sprintf(histoName,
"WeightedRescaleFactor_channel_%d_Iteration_%d",i1, i2);
127 sprintf(histoTitle,
"WeightedRescaleFactor Channel_%d Iteration %d",i1, i2);
136 sprintf(histoName,
"UnweightedRescaleFactor_channel_%d_Iteration_%d",i1, i2);
137 sprintf(histoTitle,
"UnweightedRescaleFactor Channel_%d Iteration %d",i1, i2);
146 sprintf(histoName,
"Weight_channel_%d_Iteration_%d",i1, i2);
147 sprintf(histoTitle,
"Weight Channel_%d Iteration %d",i1, i2);
148 thePlots_->
weight[i2][i1] =
new TH1F(histoName, histoTitle, 100, 0., 1.);
157 statfile.open(file.c_str());
159 std::cout <<
"ZIterativeAlgorithmWithFit::FATAL: stat weight file " << file <<
" not found" << std::endl;
205 double gausFitParameters[3], gausFitParameterErrors[3], gausFitChi2;
206 int gausFitIterations;
210 float peak=gausFitParameters[1];
211 float peakError=gausFitParameterErrors[1];
212 float chi2 = gausFitChi2;
214 int iters = gausFitIterations;
244 std::cout <<
"ZIterativeAlgorithmWithFit::run():Energy Rescaling Coefficient for region "
256 std::pair<calib::CalibElectron*, calib::CalibElectron*> Electrons(ele1, ele2);
292 getWeight(event_id, elepair.first, invMassRescFactor);
293 getWeight(event_id, elepair.second, invMassRescFactor);
304 std::vector< std::pair<int,float> > modules=(*ele).getCalibModulesWeights(
calibType_);
306 for (
int imod=0; imod< (int) modules.size(); imod++) {
308 int mod = (int) modules[imod].
first;
312 if (modules[imod].
second >= 0.12 && modules[imod].
second < 10000.)
327 std::cout <<
"w2 " << weight2 << std::endl;
329 if (weight2>=0. && weight2<=1.)
332 float rescale = (TMath::Power((
massReco_[event_id] / evweight), 2.) - 1) / 2.;
334 std::cout <<
"rescale " << rescale << std::endl;
347 std::cout <<
"[ZIterativeAlgorithmWithFit]::[getWeight]::rescale out " << rescale << std::endl;
356 std::cout <<
"ZIterativeAlgorithmWithFit::FATAL:found a wrong module_id " << mod <<
" channels " <<
channels_ << std::endl;
368 TF1 *gausa =
new TF1(
"gausa",
"gaus",histoou->GetMean()-3*histoou->GetRMS(),histoou->GetMean()+3*histoou->GetRMS());
370 gausa->SetParameters(histoou->GetMaximum(),histoou->GetMean(),histoou->GetRMS());
372 histoou->Fit(
"gausa",
"qR0N");
374 double p1 = gausa->GetParameter(1);
375 double sigma = gausa->GetParameter(2);
376 double nor = gausa->GetParameter(0);
378 double xmi=p1-5*sigma;
379 double xma=p1+5*sigma;
382 double xmin_fit=p1-nsigmalow*sigma;
383 double xmax_fit=p1+nsigmaup*sigma;
388 while ((chi2>1. && iter<5) || iter<2 )
390 xmin_fit=p1-nsigmalow*sigma;
391 xmax_fit=p1+nsigmaup*sigma;
396 sprintf (suffix,
"_iter_%d",iter);
397 fitFunc =
new TF1(
"FitFunc"+TString(suffix),
"gaus",xmin_fit,xmax_fit);
398 fitFunc->SetParameters(nor,p1,sigma);
399 fitFunc->SetLineColor((
int)(iter+1));
400 fitFunc->SetLineWidth(1);
402 histoou->Fit(
"FitFunc"+TString(suffix),
"qR0+",
"");
404 histoou->GetXaxis()->SetRangeUser(xmi,xma);
405 histoou->GetXaxis()->SetLabelSize(0.055);
408 par[0]=(fitFunc->GetParameters())[0];
409 par[1]=(fitFunc->GetParameters())[1];
410 par[2]=(fitFunc->GetParameters())[2];
411 errpar[0]=(fitFunc->GetParErrors())[0];
412 errpar[1]=(fitFunc->GetParErrors())[1];
413 errpar[2]=(fitFunc->GetParErrors())[2];
414 if (fitFunc->GetNDF()!=0)
416 chi2=fitFunc->GetChisquare()/(fitFunc->GetNDF());
426 std::cout <<
"WARNING: Not enough NDF" << std::endl;
std::string WeightFileName_
T getUntrackedParameter(std::string const &, T const &) const
std::vector< float > weight_sum_
void getWeight(unsigned int evid, std::pair< calib::CalibElectron *, calib::CalibElectron * >, float)
ZIterativeAlgorithmWithFit()
Default constructor.
std::vector< std::pair< calib::CalibElectron *, calib::CalibElectron * > > electrons_
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_
TH1 * unweightedRescaleFactor[nMaxIterations][nMaxChannels]
unsigned int currentIteration_
U second(std::pair< T, U > const &p)
std::vector< int > optimizedIterations_
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
std::vector< float > optimizedChiSquare_
TH1 * weight[nMaxIterations][nMaxChannels]
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
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)
TH1 * weightedRescaleFactor[nMaxIterations][nMaxChannels]
std::vector< float > optimizedCoefficientsError_
T mod(const T &a, const T &b)
std::vector< float > massReco_