CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
ZIterativeAlgorithmWithFit Class Reference

#include <ZIterativeAlgorithmWithFit.h>

Classes

struct  ZIterativeAlgorithmWithFitPlots
 

Public Member Functions

bool addEvent (calib::CalibElectron *, calib::CalibElectron *, float)
 
const std::vector< float > & getEpsilonSum () const
 
const ZIterativeAlgorithmWithFitPlotsgetHistos () const
 
int getNumberOfChannels () const
 
int getNumberOfIterations () const
 
const std::vector< float > & getOptimizedChiSquare () const
 
const std::vector< float > & getOptimizedCoefficients () const
 
const std::vector< float > & getOptimizedCoefficientsError () const
 
const std::vector< int > & getOptimizedIterations () const
 
const std::vector< float > & getWeightSum () const
 
bool iterate ()
 
ZIterativeAlgorithmWithFitoperator= (const ZIterativeAlgorithmWithFit &r)
 Assignment operator. More...
 
bool resetIteration ()
 
 ZIterativeAlgorithmWithFit ()
 Default constructor. More...
 
 ZIterativeAlgorithmWithFit (const edm::ParameterSet &ps)
 Constructor with explicit iterations & exponent. More...
 
virtual ~ZIterativeAlgorithmWithFit ()
 Destructor. More...
 

Static Public Member Functions

static float cosTheta12 (float Eta1, float Phi1, float Eta2, float Phi2)
 
static void gausfit (TH1F *histoou, double *par, double *errpar, float nsigmalow, float nsigmaup, double *mychi2, int *iterations)
 
static float invMassCalc (float Energy1, float Eta1, float Phi1, float Energy2, float Eta2, float Phi2)
 

Private Member Functions

void addWeightsCorrections (unsigned int event_id)
 
void bookHistograms ()
 
float getEventWeight (unsigned int event_id)
 
void getStatWeights (const std::string &file)
 
void getWeight (unsigned int evid, std::pair< calib::CalibElectron *, calib::CalibElectron *>, float)
 
void getWeight (unsigned int evid, calib::CalibElectron *ele, float)
 
void recalculateMasses ()
 
void recalculateWeightsEnergies ()
 
void recalculateWeightsEnergies (calib::CalibElectron *electron)
 

Private Attributes

std::vector< float > calib_fac_
 
TString calibType_
 
unsigned int channels_
 
unsigned int currentEvent_
 
unsigned int currentIteration_
 
std::vector< std::pair< calib::CalibElectron *, calib::CalibElectron * > > electrons_
 
std::vector< float > Event_Weight_
 
std::string massMethod
 
std::vector< float > massReco_
 
int nCrystalCut_
 
unsigned int numberOfIterations_
 
std::vector< float > optimizedChiSquare_
 
std::vector< float > optimizedCoefficients_
 
std::vector< float > optimizedCoefficientsError_
 
std::vector< int > optimizedIterations_
 
std::vector< float > StatWeights_
 
ZIterativeAlgorithmWithFitPlotsthePlots_
 
unsigned int totalEvents_
 
bool UseStatWeights_
 
std::vector< float > weight_sum_
 
std::string WeightFileName_
 

Static Private Attributes

static const double M_Z_ = 91.187
 

Detailed Description

Class that implements an iterative in situ calibration algorithm using Z events
Author: paolo.nosp@m..mer.nosp@m.idian.nosp@m.i@ro.nosp@m.ma1.i.nosp@m.nfn..nosp@m.it

Definition at line 28 of file ZIterativeAlgorithmWithFit.h.

Constructor & Destructor Documentation

◆ ZIterativeAlgorithmWithFit() [1/2]

ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFit ( )

Default constructor.

Definition at line 46 of file ZIterativeAlgorithmWithFit.cc.

References calib_fac_, channels_, currentEvent_, currentIteration_, electrons_, massReco_, numberOfIterations_, optimizedChiSquare_, optimizedCoefficients_, optimizedCoefficientsError_, optimizedIterations_, totalEvents_, and weight_sum_.

46  {
47  // std::cout<< "ZIterativeAlgorithmWithFit::Called Construnctor" << std::endl;
49  channels_ = 1;
50  totalEvents_ = 0;
51  currentEvent_ = 0;
57  calib_fac_.resize(channels_);
58  weight_sum_.resize(channels_);
59  electrons_.resize(1);
60  massReco_.resize(1);
61 }
std::vector< std::pair< calib::CalibElectron *, calib::CalibElectron * > > electrons_
std::vector< float > optimizedCoefficients_
std::vector< float > optimizedCoefficientsError_

◆ ZIterativeAlgorithmWithFit() [2/2]

ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFit ( const edm::ParameterSet ps)

Constructor with explicit iterations & exponent.

Definition at line 63 of file ZIterativeAlgorithmWithFit.cc.

References bookHistograms(), calib_fac_, calibType_, channels_, gather_cfg::cout, currentEvent_, currentIteration_, EcalIndexingTools::getInstance(), EcalIndexingTools::getNumberOfChannels(), getStatWeights(), edm::ParameterSet::getUntrackedParameter(), massMethod, EcalRingCalibrationTools::N_MODULES_BARREL, EcalRingCalibrationTools::N_RING_TOTAL, nCrystalCut_, numberOfIterations_, optimizedChiSquare_, optimizedCoefficients_, optimizedCoefficientsError_, optimizedIterations_, StatWeights_, AlCaHLTBitMon_QueryRunRegistry::string, thePlots_, totalEvents_, UseStatWeights_, weight_sum_, and WeightFileName_.

65 {
66  //std::cout<< "ZIterativeAlgorithmWithFit::Called Constructor" << std::endl;
67  numberOfIterations_ = ps.getUntrackedParameter<unsigned int>("maxLoops", 0);
68  massMethod = ps.getUntrackedParameter<std::string>("ZCalib_InvMass", "SCMass");
69  calibType_ = ps.getUntrackedParameter<std::string>("ZCalib_CalibType", "RING");
70 
71  if (calibType_ == "RING")
73  else if (calibType_ == "MODULE")
74 
76  else if (calibType_ == "ABS_SCALE")
77  channels_ = 1;
78  else if (calibType_ == "ETA_ET_MODE")
80 
81  std::cout << "[ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFit] channels_ = " << channels_ << std::endl;
82 
83  nCrystalCut_ = ps.getUntrackedParameter<int>("ZCalib_nCrystalCut", -1);
84 
85  //Resetting currentEvent & iteration
86  currentEvent_ = 0;
88  totalEvents_ = 0;
89 
94  calib_fac_.resize(channels_);
95  weight_sum_.resize(channels_);
96 
97  //Creating and booking histograms
98  thePlots_ = new ZIterativeAlgorithmWithFitPlots;
100 
101  //Setting up rescaling if needed
102  UseStatWeights_ = ps.getUntrackedParameter<bool>("ZCalib_UseStatWeights", false);
103  if (UseStatWeights_) {
104  WeightFileName_ = "weights.txt";
105  StatWeights_.resize(channels_);
107  // Event_Weight_.resize(events);
108  }
109 }
static constexpr short N_MODULES_BARREL
std::vector< float > optimizedCoefficients_
T getUntrackedParameter(std::string const &, T const &) const
static EcalIndexingTools * getInstance()
static constexpr short N_RING_TOTAL
ZIterativeAlgorithmWithFitPlots * thePlots_
void getStatWeights(const std::string &file)
std::vector< float > optimizedCoefficientsError_

◆ ~ZIterativeAlgorithmWithFit()

ZIterativeAlgorithmWithFit::~ZIterativeAlgorithmWithFit ( )
virtual

Destructor.

Definition at line 353 of file ZIterativeAlgorithmWithFit.cc.

353 {}

Member Function Documentation

◆ addEvent()

bool ZIterativeAlgorithmWithFit::addEvent ( calib::CalibElectron ele1,
calib::CalibElectron ele2,
float  invMassRescFactor 
)

Definition at line 250 of file ZIterativeAlgorithmWithFit.cc.

References gather_cfg::cout, currentEvent_, HLTTauDQMOffline_cfi::Electrons, reco::LeafCandidate::eta(), calib::CalibElectron::getRecoElectron(), getWeight(), invMassCalc(), massMethod, massReco_, reco::LeafCandidate::phi(), reco::GsfElectron::superCluster(), and totalEvents_.

Referenced by ZeeCalibration::duringLoop().

252  {
253  totalEvents_++;
254  std::pair<calib::CalibElectron*, calib::CalibElectron*> Electrons(ele1, ele2);
255 #ifdef DEBUG
256  std::cout << "In addEvent ";
257  std::cout << ele1->getRecoElectron()->superCluster()->rawEnergy() << " ";
258  std::cout << ele1->getRecoElectron()->superCluster()->position().eta() << " ";
259  std::cout << ele2->getRecoElectron()->superCluster()->rawEnergy() << " ";
260  std::cout << ele2->getRecoElectron()->superCluster()->position().eta() << " ";
261  std::cout << std::endl;
262 #endif
263 
264  if (massMethod == "SCTRMass") {
265  massReco_.push_back(invMassCalc(ele1->getRecoElectron()->superCluster()->energy(),
266  ele1->getRecoElectron()->eta(),
267  ele1->getRecoElectron()->phi(),
268  ele2->getRecoElectron()->superCluster()->energy(),
269  ele2->getRecoElectron()->eta(),
270  ele2->getRecoElectron()->phi()));
271  }
272 
273  else if (massMethod == "SCMass") {
274  massReco_.push_back(invMassCalc(ele1->getRecoElectron()->superCluster()->energy(),
275  ele1->getRecoElectron()->superCluster()->position().eta(),
276  ele1->getRecoElectron()->superCluster()->position().phi(),
277  ele2->getRecoElectron()->superCluster()->energy(),
278  ele2->getRecoElectron()->superCluster()->position().eta(),
279  ele2->getRecoElectron()->superCluster()->position().phi()));
280  }
281 
282 #ifdef DEBUG
283  std::cout << "Mass calculated " << massReco_[currentEvent_] << std::endl;
284 #endif
285 
286  if ((ele2->getRecoElectron()->superCluster()->position().eta() > -10.) &&
287  (ele2->getRecoElectron()->superCluster()->position().eta() < 10.) &&
288  (ele2->getRecoElectron()->superCluster()->position().phi() > -10.) &&
289  (ele2->getRecoElectron()->superCluster()->position().phi() < 10.)) {
290  getWeight(currentEvent_, Electrons, invMassRescFactor);
291  }
292 
293  currentEvent_++;
294  return kTRUE;
295 }
void getWeight(unsigned int evid, std::pair< calib::CalibElectron *, calib::CalibElectron *>, float)
static float invMassCalc(float Energy1, float Eta1, float Phi1, float Energy2, float Eta2, float Phi2)
const reco::GsfElectron * getRecoElectron()
Definition: CalibElectron.h:24
double phi() const final
momentum azimuthal angle
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155
double eta() const final
momentum pseudorapidity

◆ addWeightsCorrections()

void ZIterativeAlgorithmWithFit::addWeightsCorrections ( unsigned int  event_id)
private

◆ bookHistograms()

void ZIterativeAlgorithmWithFit::bookHistograms ( )
private

Definition at line 111 of file ZIterativeAlgorithmWithFit.cc.

References channels_, HltBtagPostValidation_cff::histoName, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, MAX_RESCALE, MIN_RESCALE, NBINS_HIGHETA, NBINS_LOWETA, numberOfIterations_, thePlots_, ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::unweightedRescaleFactor, ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::weight, and ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::weightedRescaleFactor.

Referenced by ZIterativeAlgorithmWithFit().

111  {
112  if (!thePlots_)
113  return;
114 
115  for (unsigned int i2 = 0; i2 < numberOfIterations_; i2++) {
116  for (unsigned int i1 = 0; i1 < channels_; i1++) {
117  char histoName[200];
118  char histoTitle[200];
119 
120  //WeightedRescaling factor
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)
125  new TH1F(histoName, histoTitle, NBINS_LOWETA, MIN_RESCALE, MAX_RESCALE);
126  else
128  new TH1F(histoName, histoTitle, NBINS_HIGHETA, MIN_RESCALE, MAX_RESCALE);
129  thePlots_->weightedRescaleFactor[i2][i1]->GetXaxis()->SetTitle("Rescale factor");
130  thePlots_->weightedRescaleFactor[i2][i1]->GetYaxis()->SetTitle("a.u.");
131 
132  //UnweightedRescaling factor
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)
137  new TH1F(histoName, histoTitle, NBINS_LOWETA, MIN_RESCALE, MAX_RESCALE);
138  else
140  new TH1F(histoName, histoTitle, NBINS_HIGHETA, MIN_RESCALE, MAX_RESCALE);
141  thePlots_->unweightedRescaleFactor[i2][i1]->GetXaxis()->SetTitle("Rescale factor");
142  thePlots_->unweightedRescaleFactor[i2][i1]->GetYaxis()->SetTitle("a.u.");
143 
144  //Weights
145  sprintf(histoName, "Weight_channel_%d_Iteration_%d", i1, i2);
146  sprintf(histoTitle, "Weight Channel_%d Iteration %d", i1, i2);
147  thePlots_->weight[i2][i1] = new TH1F(histoName, histoTitle, 100, 0., 1.);
148  thePlots_->weight[i2][i1]->GetXaxis()->SetTitle("Weight");
149  thePlots_->weight[i2][i1]->GetYaxis()->SetTitle("a.u.");
150  }
151  }
152 }
#define MAX_RESCALE
#define NBINS_HIGHETA
#define MIN_RESCALE
#define NBINS_LOWETA
ZIterativeAlgorithmWithFitPlots * thePlots_

◆ cosTheta12()

static float ZIterativeAlgorithmWithFit::cosTheta12 ( float  Eta1,
float  Phi1,
float  Eta2,
float  Phi2 
)
inlinestatic

Definition at line 79 of file ZIterativeAlgorithmWithFit.h.

References funct::cos().

Referenced by invMassCalc().

79  {
80  return ((cos(Phi1 - Phi2) + sinh(Eta1) * sinh(Eta2)) / (cosh(Eta1) * cosh(Eta2)));
81  }
Cos< T >::type cos(const T &t)
Definition: Cos.h:22

◆ gausfit()

void ZIterativeAlgorithmWithFit::gausfit ( TH1F *  histoou,
double *  par,
double *  errpar,
float  nsigmalow,
float  nsigmaup,
double *  mychi2,
int *  iterations 
)
static

Definition at line 355 of file ZIterativeAlgorithmWithFit.cc.

References hltPixelTracks_cff::chi2, gather_cfg::cout, LaserDQM_cfg::p1, and makePlotsFromDump::suffix.

Referenced by ZeeCalibration::endOfLoop(), and iterate().

356  {
357  auto gausa = std::make_unique<TF1>(
358  "gausa", "gaus", histoou->GetMean() - 3 * histoou->GetRMS(), histoou->GetMean() + 3 * histoou->GetRMS());
359 
360  gausa->SetParameters(histoou->GetMaximum(), histoou->GetMean(), histoou->GetRMS());
361 
362  histoou->Fit(gausa.get(), "qR0N");
363 
364  double p1 = gausa->GetParameter(1);
365  double sigma = gausa->GetParameter(2);
366  double nor = gausa->GetParameter(0);
367 
368  double xmi, xma, xmin_fit, xmax_fit;
369  double chi2 = 100;
370  int iter = 0;
371 
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;
377 
378  char suffix[20];
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);
384  //histoou->Fit("FitFunc","lR+","");
385  histoou->Fit(fitFunc.get(), "qR0+", "");
386 
387  histoou->GetXaxis()->SetRangeUser(xmi, xma);
388  histoou->GetXaxis()->SetLabelSize(0.055);
389 
390  // std::cout << fitFunc->GetParameters() << "," << par << std::endl;
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());
399  *myChi2 = chi2;
400 
401  } else {
402  chi2 = 100.;
403  // par[0]=-99;
404  // par[1]=-99;
405  // par[2]=-99;
406  std::cout << "WARNING: Not enough NDF" << std::endl;
407  // return 0;
408  }
409 
410  // Non visualizzare
411  // histoou->Draw();
412  // c1->Update();
413 
414  // std::cout << "iter " << iter << " chi2 " << chi2 << std::endl;
415  nor = par[0];
416  p1 = par[1];
417  sigma = par[2];
418  iter++;
419  *iterations = iter;
420  }
421  return;
422 }

◆ getEpsilonSum()

const std::vector<float>& ZIterativeAlgorithmWithFit::getEpsilonSum ( ) const
inline

Definition at line 71 of file ZIterativeAlgorithmWithFit.h.

References calib_fac_.

71 { return calib_fac_; }

◆ getEventWeight()

float ZIterativeAlgorithmWithFit::getEventWeight ( unsigned int  event_id)
private

Definition at line 304 of file ZIterativeAlgorithmWithFit.cc.

304 { return 1.; }

◆ getHistos()

const ZIterativeAlgorithmWithFitPlots* ZIterativeAlgorithmWithFit::getHistos ( ) const
inline

Definition at line 55 of file ZIterativeAlgorithmWithFit.h.

References thePlots_.

Referenced by ZeeCalibration::endOfJob(), and ZeeRescaleFactorPlots::writeHistograms().

55 { return thePlots_; }
ZIterativeAlgorithmWithFitPlots * thePlots_

◆ getNumberOfChannels()

int ZIterativeAlgorithmWithFit::getNumberOfChannels ( ) const
inline

◆ getNumberOfIterations()

int ZIterativeAlgorithmWithFit::getNumberOfIterations ( ) const
inline

◆ getOptimizedChiSquare()

const std::vector<float>& ZIterativeAlgorithmWithFit::getOptimizedChiSquare ( ) const
inline

Definition at line 65 of file ZIterativeAlgorithmWithFit.h.

References optimizedChiSquare_.

Referenced by ZeeCalibration::endOfLoop().

65 { return optimizedChiSquare_; }

◆ getOptimizedCoefficients()

const std::vector<float>& ZIterativeAlgorithmWithFit::getOptimizedCoefficients ( ) const
inline

Definition at line 61 of file ZIterativeAlgorithmWithFit.h.

References optimizedCoefficients_.

Referenced by ZeeCalibration::endOfLoop().

61 { return optimizedCoefficients_; }
std::vector< float > optimizedCoefficients_

◆ getOptimizedCoefficientsError()

const std::vector<float>& ZIterativeAlgorithmWithFit::getOptimizedCoefficientsError ( ) const
inline

Definition at line 63 of file ZIterativeAlgorithmWithFit.h.

References optimizedCoefficientsError_.

Referenced by ZeeCalibration::endOfLoop().

std::vector< float > optimizedCoefficientsError_

◆ getOptimizedIterations()

const std::vector<int>& ZIterativeAlgorithmWithFit::getOptimizedIterations ( ) const
inline

Definition at line 67 of file ZIterativeAlgorithmWithFit.h.

References optimizedIterations_.

Referenced by ZeeCalibration::endOfLoop().

67 { return optimizedIterations_; }

◆ getStatWeights()

void ZIterativeAlgorithmWithFit::getStatWeights ( const std::string &  file)
private

Definition at line 154 of file ZIterativeAlgorithmWithFit.cc.

References channels_, gather_cfg::cout, beamvalidation::exit(), geometryDiff::file, mps_fire::i, and StatWeights_.

Referenced by ZIterativeAlgorithmWithFit().

154  {
155  std::ifstream statfile;
156  statfile.open(file.c_str());
157  if (!statfile) {
158  std::cout << "ZIterativeAlgorithmWithFit::FATAL: stat weight file " << file << " not found" << std::endl;
159  exit(-1);
160  }
161  for (unsigned int i = 0; i < channels_; i++) {
162  int imod;
163  statfile >> imod >> StatWeights_[i];
164  //std::cout << "Read Stat Weight for module " << imod << ": " << StatWeights_[i] << std::endl;
165  }
166 }
def exit(msg="")

◆ getWeight() [1/2]

void ZIterativeAlgorithmWithFit::getWeight ( unsigned int  evid,
std::pair< calib::CalibElectron *, calib::CalibElectron *>  elepair,
float  invMassRescFactor 
)
private

Definition at line 297 of file ZIterativeAlgorithmWithFit.cc.

Referenced by addEvent().

299  {
300  getWeight(event_id, elepair.first, invMassRescFactor);
301  getWeight(event_id, elepair.second, invMassRescFactor);
302 }
void getWeight(unsigned int evid, std::pair< calib::CalibElectron *, calib::CalibElectron *>, float)

◆ getWeight() [2/2]

void ZIterativeAlgorithmWithFit::getWeight ( unsigned int  evid,
calib::CalibElectron ele,
float  evweight 
)
private

Definition at line 306 of file ZIterativeAlgorithmWithFit.cc.

References calib_fac_, calibType_, channels_, gather_cfg::cout, currentIteration_, first, calib::CalibElectron::getRecoElectron(), createfilelist::int, massReco_, MAX_RESCALE, MIN_RESCALE, mod(), nCrystalCut_, MuonErrorMatrixAdjuster_cfi::rescale, edm::second(), reco::GsfElectron::superCluster(), thePlots_, ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::unweightedRescaleFactor, ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::weight, weight_sum_, and ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::weightedRescaleFactor.

306  {
307  // std::cout<< "getting weight for module " << module << " in electron " << ele << std::endl;
308 
309  std::vector<std::pair<int, float> > modules = (*ele).getCalibModulesWeights(calibType_);
310 
311  for (int imod = 0; imod < (int)modules.size(); imod++) {
312  int mod = (int)modules[imod].first;
313 
314  if (mod < (int)channels_ && mod >= 0) {
315  if (modules[imod].second >= 0.12 && modules[imod].second < 10000.) {
316  if ((nCrystalCut_ == -1) ||
317  ((!(mod <= nCrystalCut_ - 1)) && !((mod > (19 - nCrystalCut_)) && (mod <= (19 + nCrystalCut_))) &&
318  !((mod > (39 - nCrystalCut_)) && (mod <= (39 + nCrystalCut_))) &&
319  !((mod > (59 - nCrystalCut_)) && (mod <= (59 + nCrystalCut_))) &&
320  !((mod > (84 - nCrystalCut_)) && (mod <= (84 + nCrystalCut_))) &&
321  !((mod > (109 - nCrystalCut_)) && (mod <= (109 + nCrystalCut_))) &&
322  !((mod > (129 - nCrystalCut_)) && (mod <= (129 + nCrystalCut_))) &&
323  !((mod > (149 - nCrystalCut_)) && (mod <= (149 + nCrystalCut_))) && !(mod > (169 - nCrystalCut_)))) {
324  float weight2 = modules[imod].second / ele->getRecoElectron()->superCluster()->rawEnergy();
325 #ifdef DEBUG
326  std::cout << "w2 " << weight2 << std::endl;
327 #endif
328  if (weight2 >= 0. && weight2 <= 1.) {
329  float rescale = (TMath::Power((massReco_[event_id] / evweight), 2.) - 1) / 2.;
330 #ifdef DEBUG
331  std::cout << "rescale " << rescale << std::endl;
332 #endif
333  if (rescale >= MIN_RESCALE && rescale <= MAX_RESCALE) {
334  calib_fac_[mod] += weight2 * rescale;
335  weight_sum_[mod] += weight2;
336 
339  thePlots_->weight[currentIteration_][mod]->Fill(weight2, 1.);
340  } else {
341  std::cout << "[ZIterativeAlgorithmWithFit]::[getWeight]::rescale out " << rescale << std::endl;
342  }
343  }
344  }
345  }
346  } else {
347  std::cout << "ZIterativeAlgorithmWithFit::FATAL:found a wrong module_id " << mod << " channels " << channels_
348  << std::endl;
349  }
350  }
351 }
#define MAX_RESCALE
U second(std::pair< T, U > const &p)
#define MIN_RESCALE
ZIterativeAlgorithmWithFitPlots * thePlots_
const reco::GsfElectron * getRecoElectron()
Definition: CalibElectron.h:24
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155

◆ getWeightSum()

const std::vector<float>& ZIterativeAlgorithmWithFit::getWeightSum ( ) const
inline

Definition at line 69 of file ZIterativeAlgorithmWithFit.h.

References weight_sum_.

69 { return weight_sum_; }

◆ invMassCalc()

static float ZIterativeAlgorithmWithFit::invMassCalc ( float  Energy1,
float  Eta1,
float  Phi1,
float  Energy2,
float  Eta2,
float  Phi2 
)
inlinestatic

Definition at line 75 of file ZIterativeAlgorithmWithFit.h.

References cosTheta12(), and mathSSE::sqrt().

Referenced by addEvent(), ZeeKinematicTools::calculateZMass_noTK(), ZeeKinematicTools::calculateZMass_withTK(), ZeeKinematicTools::calculateZMassWithCorrectedElectrons_noTK(), and ZeeKinematicTools::calculateZMassWithCorrectedElectrons_withTK().

75  {
76  return (sqrt(2 * Energy1 * Energy2 * (1 - cosTheta12(Eta1, Phi1, Eta2, Phi2))));
77  }
T sqrt(T t)
Definition: SSEVec.h:19
static float cosTheta12(float Eta1, float Phi1, float Eta2, float Phi2)

◆ iterate()

bool ZIterativeAlgorithmWithFit::iterate ( )

Definition at line 182 of file ZIterativeAlgorithmWithFit.cc.

References calib_fac_, channels_, hltPixelTracks_cff::chi2, gather_cfg::cout, currentIteration_, gausfit(), mps_fire::i, createfilelist::int, MAX_RESCALE, MIN_RESCALE, nCrystalCut_, optimizedChiSquare_, optimizedCoefficients_, optimizedCoefficientsError_, optimizedIterations_, thePlots_, weight_sum_, and ZIterativeAlgorithmWithFit::ZIterativeAlgorithmWithFitPlots::weightedRescaleFactor.

Referenced by ZeeCalibration::endOfLoop().

182  {
183  //Found optimized coefficients
184  for (int i = 0; i < (int)channels_; i++) {
185  //RP if (weight_sum_[i]!=0. && calib_fac_[i]!=0.) {
186  if ((nCrystalCut_ == -1) ||
187  ((!(i <= nCrystalCut_ - 1)) && !((i > (19 - nCrystalCut_)) && (i <= (19 + nCrystalCut_))) &&
188  !((i > (39 - nCrystalCut_)) && (i <= (39 + nCrystalCut_))) &&
189  !((i > (59 - nCrystalCut_)) && (i <= (59 + nCrystalCut_))) &&
190  !((i > (84 - nCrystalCut_)) && (i <= (84 + nCrystalCut_))) &&
191  !((i > (109 - nCrystalCut_)) && (i <= (109 + nCrystalCut_))) &&
192  !((i > (129 - nCrystalCut_)) && (i <= (129 + nCrystalCut_))) &&
193  !((i > (149 - nCrystalCut_)) && (i <= (149 + nCrystalCut_))) && !(i > (169 - nCrystalCut_)))) {
194  if (weight_sum_[i] != 0.) {
195  //optimizedCoefficients_[i] = calib_fac_[i]/weight_sum_[i];
196 
197  double gausFitParameters[3], gausFitParameterErrors[3], gausFitChi2;
198  int gausFitIterations;
199 
201  gausFitParameters,
202  gausFitParameterErrors,
203  2.5,
204  2.5,
205  &gausFitChi2,
206  &gausFitIterations);
207 
208  float peak = gausFitParameters[1];
209  float peakError = gausFitParameterErrors[1];
210  float chi2 = gausFitChi2;
211 
212  int iters = gausFitIterations;
213 
214  optimizedCoefficientsError_[i] = peakError;
216  optimizedIterations_[i] = iters;
217 
218  if (peak >= MIN_RESCALE && peak <= MAX_RESCALE)
219  optimizedCoefficients_[i] = 1 / (1 + peak);
220  else
222 
223  } else {
226  optimizedChiSquare_[i] = -1.;
227  optimizedIterations_[i] = 0;
228  }
229 
230  }
231 
232  else {
235  optimizedChiSquare_[i] = -1.;
236  optimizedIterations_[i] = 0;
237  // EcalCalibMap::getMap()->setRingCalib(i, optimizedCoefficients_[i]);
238  // // initialCoefficients_[i] *= optimizedCoefficients_[i];
239  }
240 
241  std::cout << "ZIterativeAlgorithmWithFit::run():Energy Rescaling Coefficient for region " << i << " is "
242  << optimizedCoefficients_[i] << ", with error " << optimizedCoefficientsError_[i]
243  << " - number of events: " << weight_sum_[i] << std::endl;
244  }
245 
247  return kTRUE;
248 }
#define MAX_RESCALE
std::vector< float > optimizedCoefficients_
static void gausfit(TH1F *histoou, double *par, double *errpar, float nsigmalow, float nsigmaup, double *mychi2, int *iterations)
#define MIN_RESCALE
ZIterativeAlgorithmWithFitPlots * thePlots_
std::vector< float > optimizedCoefficientsError_

◆ operator=()

ZIterativeAlgorithmWithFit& ZIterativeAlgorithmWithFit::operator= ( const ZIterativeAlgorithmWithFit r)
inline

Assignment operator.

Definition at line 44 of file ZIterativeAlgorithmWithFit.h.

44 { return *this; }

◆ recalculateMasses()

void ZIterativeAlgorithmWithFit::recalculateMasses ( )
private

◆ recalculateWeightsEnergies() [1/2]

void ZIterativeAlgorithmWithFit::recalculateWeightsEnergies ( )
private

◆ recalculateWeightsEnergies() [2/2]

void ZIterativeAlgorithmWithFit::recalculateWeightsEnergies ( calib::CalibElectron electron)
private

◆ resetIteration()

bool ZIterativeAlgorithmWithFit::resetIteration ( )

Definition at line 168 of file ZIterativeAlgorithmWithFit.cc.

References calib_fac_, channels_, currentEvent_, mps_fire::i, massReco_, totalEvents_, and weight_sum_.

Referenced by ZeeCalibration::startingNewLoop().

168  {
169  totalEvents_ = 0;
170  currentEvent_ = 0;
171 
172  //Reset correction
173  massReco_.clear();
174  for (unsigned int i = 0; i < channels_; i++)
175  calib_fac_[i] = 0.;
176  for (unsigned int i = 0; i < channels_; i++)
177  weight_sum_[i] = 0.;
178 
179  return kTRUE;
180 }

Member Data Documentation

◆ calib_fac_

std::vector<float> ZIterativeAlgorithmWithFit::calib_fac_
private

◆ calibType_

TString ZIterativeAlgorithmWithFit::calibType_
private

Definition at line 140 of file ZIterativeAlgorithmWithFit.h.

Referenced by getWeight(), and ZIterativeAlgorithmWithFit().

◆ channels_

unsigned int ZIterativeAlgorithmWithFit::channels_
private

◆ currentEvent_

unsigned int ZIterativeAlgorithmWithFit::currentEvent_
private

◆ currentIteration_

unsigned int ZIterativeAlgorithmWithFit::currentIteration_
private

Definition at line 120 of file ZIterativeAlgorithmWithFit.h.

Referenced by getWeight(), iterate(), and ZIterativeAlgorithmWithFit().

◆ electrons_

std::vector<std::pair<calib::CalibElectron*, calib::CalibElectron*> > ZIterativeAlgorithmWithFit::electrons_
private

Definition at line 122 of file ZIterativeAlgorithmWithFit.h.

Referenced by ZIterativeAlgorithmWithFit().

◆ Event_Weight_

std::vector<float> ZIterativeAlgorithmWithFit::Event_Weight_
private

Definition at line 138 of file ZIterativeAlgorithmWithFit.h.

◆ M_Z_

const double ZIterativeAlgorithmWithFit::M_Z_ = 91.187
staticprivate

Definition at line 142 of file ZIterativeAlgorithmWithFit.h.

◆ massMethod

std::string ZIterativeAlgorithmWithFit::massMethod
private

Definition at line 132 of file ZIterativeAlgorithmWithFit.h.

Referenced by addEvent(), and ZIterativeAlgorithmWithFit().

◆ massReco_

std::vector<float> ZIterativeAlgorithmWithFit::massReco_
private

◆ nCrystalCut_

int ZIterativeAlgorithmWithFit::nCrystalCut_
private

Definition at line 113 of file ZIterativeAlgorithmWithFit.h.

Referenced by getWeight(), iterate(), and ZIterativeAlgorithmWithFit().

◆ numberOfIterations_

unsigned int ZIterativeAlgorithmWithFit::numberOfIterations_
private

◆ optimizedChiSquare_

std::vector<float> ZIterativeAlgorithmWithFit::optimizedChiSquare_
private

◆ optimizedCoefficients_

std::vector<float> ZIterativeAlgorithmWithFit::optimizedCoefficients_
private

◆ optimizedCoefficientsError_

std::vector<float> ZIterativeAlgorithmWithFit::optimizedCoefficientsError_
private

◆ optimizedIterations_

std::vector<int> ZIterativeAlgorithmWithFit::optimizedIterations_
private

◆ StatWeights_

std::vector<float> ZIterativeAlgorithmWithFit::StatWeights_
private

Definition at line 137 of file ZIterativeAlgorithmWithFit.h.

Referenced by getStatWeights(), and ZIterativeAlgorithmWithFit().

◆ thePlots_

ZIterativeAlgorithmWithFitPlots* ZIterativeAlgorithmWithFit::thePlots_
private

◆ totalEvents_

unsigned int ZIterativeAlgorithmWithFit::totalEvents_
private

◆ UseStatWeights_

bool ZIterativeAlgorithmWithFit::UseStatWeights_
private

Definition at line 134 of file ZIterativeAlgorithmWithFit.h.

Referenced by ZIterativeAlgorithmWithFit().

◆ weight_sum_

std::vector<float> ZIterativeAlgorithmWithFit::weight_sum_
private

◆ WeightFileName_

std::string ZIterativeAlgorithmWithFit::WeightFileName_
private

Definition at line 135 of file ZIterativeAlgorithmWithFit.h.

Referenced by ZIterativeAlgorithmWithFit().