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.);
156 std::ifstream statfile;
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++) {
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 auto gausa = std::make_unique<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.get(),
"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;
387 while ((chi2>1. && iter<5) || iter<2 )
389 xmin_fit=p1-nsigmalow*sigma;
390 xmax_fit=p1+nsigmaup*sigma;
395 sprintf (suffix,
"_iter_%d",iter);
396 auto fitFunc = std::make_unique<TF1>(
"FitFunc"+TString(suffix),
"gaus",xmin_fit,xmax_fit);
397 fitFunc->SetParameters(nor,p1,sigma);
398 fitFunc->SetLineColor((
int)(iter+1));
399 fitFunc->SetLineWidth(1);
401 histoou->Fit(fitFunc.get(),
"qR0+",
"");
403 histoou->GetXaxis()->SetRangeUser(xmi,xma);
404 histoou->GetXaxis()->SetLabelSize(0.055);
407 par[0]=(fitFunc->GetParameters())[0];
408 par[1]=(fitFunc->GetParameters())[1];
409 par[2]=(fitFunc->GetParameters())[2];
410 errpar[0]=(fitFunc->GetParErrors())[0];
411 errpar[1]=(fitFunc->GetParErrors())[1];
412 errpar[2]=(fitFunc->GetParErrors())[2];
413 if (fitFunc->GetNDF()!=0)
415 chi2=fitFunc->GetChisquare()/(fitFunc->GetNDF());
425 std::cout <<
"WARNING: Not enough NDF" << std::endl;
TH1 * weightedRescaleFactor[50][250]
std::string WeightFileName_
T getUntrackedParameter(std::string const &, T const &) const
std::vector< float > weight_sum_
double eta() const final
momentum pseudorapidity
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_
unsigned int currentIteration_
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_
SuperClusterRef superCluster() const override
reference to a SuperCluster
const reco::GsfElectron * getRecoElectron()
void getStatWeights(const std::string &file)
std::vector< float > optimizedCoefficientsError_
T mod(const T &a, const T &b)
double phi() const final
momentum azimuthal angle
std::vector< float > massReco_