CMS 3D CMS Logo

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

#include <EpCombinationTool.h>

Public Member Functions

void combine (SimpleElectron &mySimpleElectron) const
 
std::pair< float, float > combine (const reco::GsfElectron &electron) const
 
 EpCombinationTool ()
 
 EpCombinationTool (const EpCombinationTool &other)=delete
 
 EpCombinationTool (const edm::ParameterSet &iConfig)
 
bool init (const GBRForest *forest)
 
bool init (const std::string &regressionFile, const std::string &bdtName)
 
EpCombinationTooloperator= (const EpCombinationTool &other)=delete
 
void setEventContent (const edm::EventSetup &iSetup)
 
 ~EpCombinationTool ()
 
 ~EpCombinationTool ()
 

Static Public Member Functions

static edm::ParameterSetDescription makePSetDescription ()
 

Private Attributes

EgammaRegressionContainer ecalTrkEnergyRegress_
 
EgammaRegressionContainer ecalTrkEnergyRegressUncert_
 
const GBRForestm_forest
 
bool m_ownForest
 
float maxEcalEnergyForComb_
 
float maxEPDiffInSigmaForComb_
 
float maxRelTrkMomErrForComb_
 
float minEOverPForComb_
 

Detailed Description

Definition at line 10 of file EpCombinationTool.h.

Constructor & Destructor Documentation

EpCombinationTool::EpCombinationTool ( )

Definition at line 12 of file EpCombinationTool.cc.

12  :
13  m_forest(nullptr), m_ownForest(false)
14 /*****************************************************************/
15 {
16 }
const GBRForest * m_forest
EpCombinationTool::~EpCombinationTool ( )

Definition at line 21 of file EpCombinationTool.cc.

References m_forest, and m_ownForest.

23 {
24  if(m_ownForest) delete m_forest;
25 }
const GBRForest * m_forest
EpCombinationTool::EpCombinationTool ( const EpCombinationTool other)
delete
EpCombinationTool::EpCombinationTool ( const edm::ParameterSet iConfig)

Definition at line 15 of file EpCombinationTool.cc.

15  :
16  ecalTrkEnergyRegress_(iConfig.getParameter<edm::ParameterSet>("ecalTrkRegressionConfig")),
17  ecalTrkEnergyRegressUncert_(iConfig.getParameter<edm::ParameterSet>("ecalTrkRegressionUncertConfig")),
18  maxEcalEnergyForComb_(iConfig.getParameter<double>("maxEcalEnergyForComb")),
19  minEOverPForComb_(iConfig.getParameter<double>("minEOverPForComb")),
20  maxEPDiffInSigmaForComb_(iConfig.getParameter<double>("maxEPDiffInSigmaForComb")),
21  maxRelTrkMomErrForComb_(iConfig.getParameter<double>("maxRelTrkMomErrForComb"))
22 {
23 
24 }
T getParameter(std::string const &) const
EgammaRegressionContainer ecalTrkEnergyRegress_
EgammaRegressionContainer ecalTrkEnergyRegressUncert_
EpCombinationTool::~EpCombinationTool ( )
inline

Definition at line 23 of file EpCombinationTool.h.

References funct::combine(), and metsig::electron.

23 {}

Member Function Documentation

void EpCombinationTool::combine ( SimpleElectron mySimpleElectron) const

Definition at line 62 of file EpCombinationTool.cc.

References gather_cfg::cout, energyError(), GBRForest::GetResponse(), m_forest, mathSSE::sqrt(), and mps_merge::weight.

Referenced by ElectronEnergyCalibrator::calCombinedMom(), ElectronEnergyCalibratorRun2::calibrate(), and ElectronEnergyCalibrator::setEnergyAndSystVarations().

64 {
65  if(!m_forest)
66  {
67  cout<<"ERROR: The combination tool is not initialized\n";
68  return;
69  }
70 
71  float energy = mySimpleElectron.getNewEnergy();
72  float energyError = mySimpleElectron.getNewEnergyError();
73  float momentum = mySimpleElectron.getTrackerMomentum();
74  float momentumError = mySimpleElectron.getTrackerMomentumError();
75  int electronClass = mySimpleElectron.getElClass();
76  bool isEcalDriven = mySimpleElectron.isEcalDriven();
77  bool isTrackerDriven = mySimpleElectron.isTrackerDriven();
78  bool isEB = mySimpleElectron.isEB();
79 
80  // compute relative errors and ratio of errors
81  float energyRelError = energyError / energy;
82  float momentumRelError = momentumError / momentum;
83  float errorRatio = energyRelError / momentumRelError;
84 
85  // calculate E/p and corresponding error
86  float eOverP = energy / momentum;
87  float eOverPerror = sqrt(
88  (energyError/momentum)*(energyError/momentum) +
89  (energy*momentumError/momentum/momentum)*
90  (energy*momentumError/momentum/momentum));
91 
92  // fill input variables
93  float regressionInputs[11];
94  regressionInputs[0] = energy;
95  regressionInputs[1] = energyRelError;
96  regressionInputs[2] = momentum;
97  regressionInputs[3] = momentumRelError;
98  regressionInputs[4] = errorRatio;
99  regressionInputs[5] = eOverP;
100  regressionInputs[6] = eOverPerror;
101  regressionInputs[7] = static_cast<float>(isEcalDriven);
102  regressionInputs[8] = static_cast<float>(isTrackerDriven);
103  regressionInputs[9] = static_cast<float>(electronClass);
104  regressionInputs[10] = static_cast<float>(isEB);
105 
106  // retrieve combination weight
107  float weight = 0.;
108  if(eOverP>0.025
109  &&fabs(momentum-energy)<15.*sqrt(momentumError*momentumError + energyError*energyError)
110  && ( (momentumError < 10.*momentum) || (energy < 200.) )
111  ) // protection against crazy track measurement
112  {
113  weight = m_forest->GetResponse(regressionInputs);
114  if(weight>1.) weight = 1.;
115  else if(weight<0.) weight = 0.;
116  }
117 
118  float combinedMomentum = weight*momentum + (1.-weight)*energy;
119  float combinedMomentumError = sqrt(weight*weight*momentumError*momentumError + (1.-weight)*(1.-weight)*energyError*energyError);
120 
121  // FIXME : pure tracker electrons have track momentum error of 999.
122  // If the combination try to combine such electrons then the original combined momentum is kept
123  if(momentumError!=999. || weight==0.)
124  {
125  mySimpleElectron.setCombinedMomentum(combinedMomentum);
126  mySimpleElectron.setCombinedMomentumError(combinedMomentumError);
127  }
128 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:59
int getElClass() const
void setCombinedMomentum(double combinedMomentum)
double getTrackerMomentum() const
const GBRForest * m_forest
Definition: weight.py:1
double getNewEnergy() const
bool isTrackerDriven() const
double getNewEnergyError() const
T sqrt(T t)
Definition: SSEVec.h:18
bool isEB() const
void setCombinedMomentumError(double combinedMomentumError)
double getTrackerMomentumError() const
bool isEcalDriven() const
float energyError(float E, float *par)
std::pair< float, float > EpCombinationTool::combine ( const reco::GsfElectron electron) const

Definition at line 45 of file EpCombinationTool.cc.

References funct::abs(), reco::GsfElectron::correctedEcalEnergy(), reco::GsfElectron::correctedEcalEnergyError(), reco::GsfElectron::ecalDrivenSeed(), ecalTrkEnergyRegress_, ecalTrkEnergyRegressUncert_, reco::GsfElectron::fbrem(), reco::GsfElectron::full5x5_showerShape(), reco::GsfElectron::gsfTrack(), reco::GsfElectron::isEB(), maxEcalEnergyForComb_, maxEPDiffInSigmaForComb_, maxRelTrkMomErrForComb_, SiStripPI::mean, minEOverPForComb_, reco::GsfElectron::nSaturatedXtals(), reco::GsfElectron::ShowerShape::r9, mathSSE::sqrt(), and reco::GsfElectron::superCluster().

46 {
47  const float scRawEnergy = ele.superCluster()->rawEnergy();
48  const float esEnergy = ele.superCluster()->preshowerEnergy();
49 
50 
51  const float corrEcalEnergy = ele.correctedEcalEnergy();
52  const float corrEcalEnergyErr = ele.correctedEcalEnergyError();
53  const float ecalMean = ele.correctedEcalEnergy() / (scRawEnergy+esEnergy);
54  const float ecalSigma = corrEcalEnergyErr / corrEcalEnergy;
55 
56  auto gsfTrk = ele.gsfTrack();
57 
58  const float trkP = gsfTrk->pMode();
59  const float trkEta = gsfTrk->etaMode();
60  const float trkPhi = gsfTrk->phiMode();
61  const float trkPErr = std::abs(gsfTrk->qoverpModeError())*trkP*trkP;
62  const float eOverP = corrEcalEnergy/trkP;
63  const float fbrem = ele.fbrem();
64 
65  if(corrEcalEnergy < maxEcalEnergyForComb_ &&
66  eOverP > minEOverPForComb_ &&
67  std::abs(corrEcalEnergy - trkP) < maxEPDiffInSigmaForComb_*std::sqrt(trkPErr*trkPErr+corrEcalEnergyErr*corrEcalEnergyErr) &&
68  trkPErr < maxRelTrkMomErrForComb_*trkP) {
69 
70  std::array<float, 9> eval;
71  eval[0] = corrEcalEnergy;
72  eval[1] = ecalSigma/ecalMean;
73  eval[2] = trkPErr/trkP;
74  eval[3] = eOverP;
75  eval[4] = ele.ecalDrivenSeed();
76  eval[5] = ele.full5x5_showerShape().r9;
77  eval[6] = fbrem;
78  eval[7] = trkEta;
79  eval[8] = trkPhi;
80 
81  const float preCombinationEt = corrEcalEnergy/std::cosh(trkEta);
82  float mean = ecalTrkEnergyRegress_(preCombinationEt,ele.isEB(),ele.nSaturatedXtals()!=0,eval.data());
83  float sigma = ecalTrkEnergyRegressUncert_(preCombinationEt,ele.isEB(),ele.nSaturatedXtals()!=0,eval.data());
84  // Final correction
85  // A negative energy means that the correction went
86  // outside the boundaries of the training. In this case uses raw.
87  // The resolution estimation, on the other hand should be ok.
88  if (mean < 0.) mean = 1.0;
89 
90  //why this differs from the defination of corrEcalEnergyErr (it misses the mean) is not clear to me
91  //still this is a direct port from EGExtraInfoModifierFromDB, potential bugs and all
92  const float ecalSigmaTimesRawEnergy = ecalSigma*(scRawEnergy+esEnergy);
93  const float rawCombEnergy = ( corrEcalEnergy*trkPErr*trkPErr +
94  trkP*ecalSigmaTimesRawEnergy*ecalSigmaTimesRawEnergy ) /
95  ( trkPErr*trkPErr +
96  ecalSigmaTimesRawEnergy*ecalSigmaTimesRawEnergy );
97 
98  return std::make_pair(mean*rawCombEnergy,sigma*rawCombEnergy);
99  }else{
100  return std::make_pair(corrEcalEnergy, corrEcalEnergyErr);
101  }
102 }
EgammaRegressionContainer ecalTrkEnergyRegress_
EgammaRegressionContainer ecalTrkEnergyRegressUncert_
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool EpCombinationTool::init ( const GBRForest forest)

Definition at line 52 of file EpCombinationTool.cc.

References m_forest, and m_ownForest.

Referenced by CalibratedElectronProducerRun2T< T >::produce().

53 {
54  if(m_ownForest) delete m_forest;
55  m_forest = forest;
56  m_ownForest = false;
57  return true;
58 }
const GBRForest * m_forest
bool EpCombinationTool::init ( const std::string &  regressionFile,
const std::string &  bdtName 
)

Definition at line 29 of file EpCombinationTool.cc.

References gather_cfg::cout, m_forest, and m_ownForest.

31 {
32  TFile* regressionFile = TFile::Open(regressionFileName.c_str());
33  if(!regressionFile)
34  {
35  cout<<"ERROR: Cannot open regression file "<<regressionFileName<<"\n";
36  return false;
37  }
38  if(m_ownForest) delete m_forest;
39  m_forest = (GBRForest*) regressionFile->Get(bdtName.c_str());
40  m_ownForest = true;
41  //regressionFile->GetObject(bdtName.c_str(), m_forest);
42  if(!m_forest)
43  {
44  cout<<"ERROR: Cannot find forest "<<bdtName<<" in "<<regressionFileName<<"\n";
45  regressionFile->Close();
46  return false;
47  }
48  regressionFile->Close();
49  return true;
50 }
const GBRForest * m_forest
edm::ParameterSetDescription EpCombinationTool::makePSetDescription ( )
static

Definition at line 26 of file EpCombinationTool.cc.

References edm::ParameterSetDescription::add(), and EgammaRegressionContainer::makePSetDescription().

Referenced by CalibratedElectronProducerT< T >::fillDescriptions().

27 {
31  desc.add<double>("maxEcalEnergyForComb",200.);
32  desc.add<double>("minEOverPForComb",0.025);
33  desc.add<double>("maxEPDiffInSigmaForComb",15.);
34  desc.add<double>("maxRelTrkMomErrForComb",10.);
35  return desc;
36 }
static edm::ParameterSetDescription makePSetDescription()
ParameterDescriptionBase * add(U const &iLabel, T const &value)
EpCombinationTool& EpCombinationTool::operator= ( const EpCombinationTool other)
delete
void EpCombinationTool::setEventContent ( const edm::EventSetup iSetup)

Definition at line 39 of file EpCombinationTool.cc.

References ecalTrkEnergyRegress_, ecalTrkEnergyRegressUncert_, and EgammaRegressionContainer::setEventContent().

Referenced by CalibratedElectronProducerT< T >::produce().

40 {
43 }
void setEventContent(const edm::EventSetup &iSetup)
EgammaRegressionContainer ecalTrkEnergyRegress_
EgammaRegressionContainer ecalTrkEnergyRegressUncert_

Member Data Documentation

EgammaRegressionContainer EpCombinationTool::ecalTrkEnergyRegress_
private

Definition at line 31 of file EpCombinationTool.h.

Referenced by combine(), and setEventContent().

EgammaRegressionContainer EpCombinationTool::ecalTrkEnergyRegressUncert_
private

Definition at line 32 of file EpCombinationTool.h.

Referenced by combine(), and setEventContent().

const GBRForest* EpCombinationTool::m_forest
private

Definition at line 25 of file EpCombinationTool.h.

Referenced by combine(), init(), and ~EpCombinationTool().

bool EpCombinationTool::m_ownForest
private

Definition at line 26 of file EpCombinationTool.h.

Referenced by init(), and ~EpCombinationTool().

float EpCombinationTool::maxEcalEnergyForComb_
private

Definition at line 33 of file EpCombinationTool.h.

Referenced by combine().

float EpCombinationTool::maxEPDiffInSigmaForComb_
private

Definition at line 35 of file EpCombinationTool.h.

Referenced by combine().

float EpCombinationTool::maxRelTrkMomErrForComb_
private

Definition at line 36 of file EpCombinationTool.h.

Referenced by combine().

float EpCombinationTool::minEOverPForComb_
private

Definition at line 34 of file EpCombinationTool.h.

Referenced by combine().