CMS 3D CMS Logo

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

#include <RegressionHelper.h>

Classes

struct  Configuration
 

Public Member Functions

void applyCombinationRegression (reco::GsfElectron &ele) const
 
void applyEcalRegression (reco::GsfElectron &electron, const edm::Handle< reco::VertexCollection > &vertices, const edm::Handle< EcalRecHitCollection > &rechitsEB, const edm::Handle< EcalRecHitCollection > &rechitsEE) const
 
void checkSetup (const edm::EventSetup &)
 
void readEvent (const edm::Event &)
 
 RegressionHelper (const Configuration &)
 
 ~RegressionHelper ()
 

Private Member Functions

void getEcalRegression (const reco::SuperCluster &sc, const edm::Handle< reco::VertexCollection > &vertices, const edm::Handle< EcalRecHitCollection > &rechitsEB, const edm::Handle< EcalRecHitCollection > &rechitsEE, double &energyFactor, double &errorFactor) const
 

Private Attributes

const CaloGeometrycaloGeometry_
 
unsigned long long caloGeometryCacheId_
 
const CaloTopologycaloTopology_
 
unsigned long long caloTopologyCacheId_
 
const Configuration cfg_
 
const GBRForestcombinationReg_
 
bool combinationRegressionInitialized_
 
const GBRForestecalRegBarrel_
 
const GBRForestecalRegEndcap_
 
const GBRForestecalRegErrorBarrel_
 
const GBRForestecalRegErrorEndcap_
 
bool ecalRegressionInitialized_
 
unsigned long long regressionCacheId_
 

Detailed Description

Definition at line 23 of file RegressionHelper.h.

Constructor & Destructor Documentation

◆ RegressionHelper()

RegressionHelper::RegressionHelper ( const Configuration config)

Definition at line 11 of file RegressionHelper.cc.

◆ ~RegressionHelper()

RegressionHelper::~RegressionHelper ( )

Definition at line 21 of file RegressionHelper.cc.

21 { ; }

Member Function Documentation

◆ applyCombinationRegression()

void RegressionHelper::applyCombinationRegression ( reco::GsfElectron ele) const

Definition at line 152 of file RegressionHelper.cc.

152  {
153  float energy = ele.correctedEcalEnergy();
154  float energyError = ele.correctedEcalEnergyError();
155  float momentum = ele.trackMomentumAtVtx().R();
156  float momentumError = ele.trackMomentumError();
157  int elClass = -1;
158 
159  switch (ele.classification()) {
161  elClass = 0;
162  break;
164  elClass = 1;
165  break;
167  elClass = 2;
168  break;
170  elClass = 3;
171  break;
173  elClass = 4;
174  break;
175  default:
176  elClass = -1;
177  }
178 
179  bool isEcalDriven = ele.ecalDriven();
180  bool isTrackerDriven = ele.trackerDrivenSeed();
181  bool isEB = ele.isEB();
182 
183  // compute relative errors and ratio of errors
184  float energyRelError = energyError / energy;
185  float momentumRelError = momentumError / momentum;
186  float errorRatio = energyRelError / momentumRelError;
187 
188  // calculate E/p and corresponding error
189  float eOverP = energy / momentum;
190  float eOverPerror = eOverP * std::hypot(energyRelError, momentumRelError);
191 
192  // fill input variables
193  std::vector<float> regressionInputs;
194  regressionInputs.resize(11, 0.);
195 
196  regressionInputs[0] = energy;
197  regressionInputs[1] = energyRelError;
198  regressionInputs[2] = momentum;
199  regressionInputs[3] = momentumRelError;
200  regressionInputs[4] = errorRatio;
201  regressionInputs[5] = eOverP;
202  regressionInputs[6] = eOverPerror;
203  regressionInputs[7] = static_cast<float>(isEcalDriven);
204  regressionInputs[8] = static_cast<float>(isTrackerDriven);
205  regressionInputs[9] = static_cast<float>(elClass);
206  regressionInputs[10] = static_cast<float>(isEB);
207 
208  // retrieve combination weight
209  float weight = 0.;
210  if (eOverP > 0.025 &&
211  fabs(momentum - energy) < 15. * sqrt(momentumError * momentumError +
212  energyError * energyError)) // protection against crazy track measurement
213  {
214  weight = combinationReg_->GetResponse(regressionInputs.data());
215  if (weight > 1.)
216  weight = 1.;
217  else if (weight < 0.)
218  weight = 0.;
219  }
220 
221  float combinedMomentum = weight * momentum + (1. - weight) * energy;
222  float combinedMomentumError =
223  sqrt(weight * weight * momentumError * momentumError + (1. - weight) * (1. - weight) * energyError * energyError);
224 
225  // FIXME : pure tracker electrons have track momentum error of 999.
226  // If the combination try to combine such electrons then the original combined momentum is kept
227  if (momentumError != 999. || weight == 0.) {
228  math::XYZTLorentzVector oldMomentum = ele.p4();
229  math::XYZTLorentzVector newMomentum(oldMomentum.x() * combinedMomentum / oldMomentum.t(),
230  oldMomentum.y() * combinedMomentum / oldMomentum.t(),
231  oldMomentum.z() * combinedMomentum / oldMomentum.t(),
232  combinedMomentum);
233 
234  ele.setP4(reco::GsfElectron::P4_COMBINATION, newMomentum, combinedMomentumError, true);
235  }
236 }

References reco::GsfElectron::BADTRACK, reco::GsfElectron::BIGBREM, reco::GsfElectron::classification(), combinationReg_, reco::GsfElectron::correctedEcalEnergy(), reco::GsfElectron::correctedEcalEnergyError(), reco::GsfElectron::ecalDriven(), HCALHighEnergyHPDFilter_cfi::energy, EgHLTOffHistBins_cfi::eOverP, reco::GsfElectron::GAP, GBRForest::GetResponse(), reco::GsfElectron::GOLDEN, reco::GsfElectron::isEB(), reco::GsfElectron::p4(), reco::GsfElectron::P4_COMBINATION, reco::GsfElectron::setP4(), reco::GsfElectron::SHOWERING, mathSSE::sqrt(), reco::GsfElectron::trackerDrivenSeed(), reco::GsfElectron::trackMomentumAtVtx(), reco::GsfElectron::trackMomentumError(), and mps_merge::weight.

Referenced by GsfElectronAlgo::createElectron().

◆ applyEcalRegression()

void RegressionHelper::applyEcalRegression ( reco::GsfElectron electron,
const edm::Handle< reco::VertexCollection > &  vertices,
const edm::Handle< EcalRecHitCollection > &  rechitsEB,
const edm::Handle< EcalRecHitCollection > &  rechitsEE 
) const

Definition at line 23 of file RegressionHelper.cc.

26  {
27  double cor, err;
28  getEcalRegression(*ele.superCluster(), vertices, rechitsEB, rechitsEE, cor, err);
29  ele.setCorrectedEcalEnergy(cor * ele.superCluster()->correctedEnergy());
30  ele.setCorrectedEcalEnergyError(err * ele.superCluster()->correctedEnergy());
31 }

References runTheMatrix::err, getEcalRegression(), reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), reco::GsfElectron::superCluster(), and pwdgSkimBPark_cfi::vertices.

Referenced by GsfElectronAlgo::createElectron().

◆ checkSetup()

void RegressionHelper::checkSetup ( const edm::EventSetup es)

Definition at line 33 of file RegressionHelper.cc.

33  {
34  // Topology
35  unsigned long long newCaloTopologyCacheId = es.get<CaloTopologyRecord>().cacheIdentifier();
36  if (!caloTopologyCacheId_ || (caloTopologyCacheId_ != newCaloTopologyCacheId)) {
37  caloTopologyCacheId_ = newCaloTopologyCacheId;
39  es.get<CaloTopologyRecord>().get(caloTopo);
40  caloTopology_ = &(*caloTopo);
41  }
42 
43  // Geometry
44  unsigned long long newCaloGeometryCacheId = es.get<CaloGeometryRecord>().cacheIdentifier();
45  if (!caloGeometryCacheId_ || (caloGeometryCacheId_ != newCaloGeometryCacheId)) {
46  caloGeometryCacheId_ = newCaloGeometryCacheId;
48  es.get<CaloGeometryRecord>().get(caloGeom);
49  caloGeometry_ = &(*caloGeom);
50  }
51 
52  // Ecal regression
53 
54  // if at least one of the set of weights come from the DB
55  if (cfg_.ecalWeightsFromDB) {
56  unsigned long long newRegressionCacheId = es.get<GBRWrapperRcd>().cacheIdentifier();
57  if (!regressionCacheId_ || (newRegressionCacheId != regressionCacheId_)) {
58  const GBRWrapperRcd& gbrRcd = es.get<GBRWrapperRcd>();
59 
60  // ECAL barrel
61  edm::ESHandle<GBRForest> ecalRegBarrelH;
62  gbrRcd.get(cfg_.ecalRegressionWeightLabels[0].c_str(), ecalRegBarrelH);
63  ecalRegBarrel_ = &(*ecalRegBarrelH);
64 
65  // ECAL endcaps
66  edm::ESHandle<GBRForest> ecalRegEndcapH;
67  gbrRcd.get(cfg_.ecalRegressionWeightLabels[1].c_str(), ecalRegEndcapH);
68  ecalRegEndcap_ = &(*ecalRegEndcapH);
69 
70  // ECAL barrel error
71  edm::ESHandle<GBRForest> ecalRegErrorBarrelH;
72  gbrRcd.get(cfg_.ecalRegressionWeightLabels[2].c_str(), ecalRegErrorBarrelH);
73  ecalRegErrorBarrel_ = &(*ecalRegErrorBarrelH);
74 
75  // ECAL endcap error
76  edm::ESHandle<GBRForest> ecalRegErrorEndcapH;
77  gbrRcd.get(cfg_.ecalRegressionWeightLabels[3].c_str(), ecalRegErrorEndcapH);
78  ecalRegErrorEndcap_ = &(*ecalRegErrorEndcapH);
79 
81  }
82  }
84  // Combination
86  unsigned long long newRegressionCacheId = es.get<GBRWrapperRcd>().cacheIdentifier();
87  if (!regressionCacheId_ || (newRegressionCacheId != regressionCacheId_)) {
88  const GBRWrapperRcd& gbrRcd = es.get<GBRWrapperRcd>();
89 
90  edm::ESHandle<GBRForest> combinationRegH;
91  gbrRcd.get(cfg_.combinationRegressionWeightLabels[0].c_str(), combinationRegH);
92  combinationReg_ = &(*combinationRegH);
93 
95  }
96  }
97  }
98 
99  // read weights from file - for debugging. Even if it is one single files, 4 files should b set in the vector
101  TFile file0(edm::FileInPath(cfg_.ecalRegressionWeightFiles[0].c_str()).fullPath().c_str());
102  ecalRegBarrel_ = (const GBRForest*)file0.Get(cfg_.ecalRegressionWeightLabels[0].c_str());
103  file0.Close();
104  TFile file1(edm::FileInPath(cfg_.ecalRegressionWeightFiles[1].c_str()).fullPath().c_str());
106  file1.Close();
107  TFile file2(edm::FileInPath(cfg_.ecalRegressionWeightFiles[2].c_str()).fullPath().c_str());
109  file2.Close();
110  TFile file3(edm::FileInPath(cfg_.ecalRegressionWeightFiles[3].c_str()).fullPath().c_str());
111  ecalRegErrorEndcap_ = (const GBRForest*)file3.Get(cfg_.ecalRegressionWeightLabels[3].c_str());
113  file3.Close();
114  }
115 
118  TFile file0(edm::FileInPath(cfg_.combinationRegressionWeightFiles[0].c_str()).fullPath().c_str());
119  combinationReg_ = (const GBRForest*)file0.Get(cfg_.combinationRegressionWeightLabels[0].c_str());
121  file0.Close();
122  }
123 }

References caloGeometry_, caloGeometryCacheId_, caloTopology_, caloTopologyCacheId_, cfg_, combinationReg_, combinationRegressionInitialized_, RegressionHelper::Configuration::combinationRegressionWeightFiles, RegressionHelper::Configuration::combinationRegressionWeightLabels, RegressionHelper::Configuration::combinationWeightsFromDB, ecalRegBarrel_, ecalRegEndcap_, ecalRegErrorBarrel_, ecalRegErrorEndcap_, ecalRegressionInitialized_, RegressionHelper::Configuration::ecalRegressionWeightFiles, RegressionHelper::Configuration::ecalRegressionWeightLabels, RegressionHelper::Configuration::ecalWeightsFromDB, timingPdfMaker::file1, edmOneToOneComparison::file2, contentValuesFiles::fullPath, edm::EventSetup::get(), edm::eventsetup::EventSetupRecordImplementation< T >::get(), get, and regressionCacheId_.

Referenced by GsfElectronAlgo::checkSetup().

◆ getEcalRegression()

void RegressionHelper::getEcalRegression ( const reco::SuperCluster sc,
const edm::Handle< reco::VertexCollection > &  vertices,
const edm::Handle< EcalRecHitCollection > &  rechitsEB,
const edm::Handle< EcalRecHitCollection > &  rechitsEE,
double &  energyFactor,
double &  errorFactor 
) const
private

Definition at line 127 of file RegressionHelper.cc.

132  {
133  energyFactor = -999.;
134  errorFactor = -999.;
135 
136  std::vector<float> rInputs;
137  EcalRegressionData regData;
138  regData.fill(sc, rechitsEB.product(), rechitsEE.product(), caloGeometry_, caloTopology_, vertices.product());
139  regData.fillVec(rInputs);
140  if (sc.seed()->hitsAndFractions()[0].first.subdetId() == EcalBarrel) {
141  energyFactor = ecalRegBarrel_->GetResponse(&rInputs[0]);
142  errorFactor = ecalRegErrorBarrel_->GetResponse(&rInputs[0]);
143  } else if (sc.seed()->hitsAndFractions()[0].first.subdetId() == EcalEndcap) {
144  energyFactor = ecalRegEndcap_->GetResponse(&rInputs[0]);
145  errorFactor = ecalRegErrorEndcap_->GetResponse(&rInputs[0]);
146  } else {
147  throw cms::Exception("RegressionHelper::calculateRegressedEnergy")
148  << "Supercluster seed is either EB nor EE!" << std::endl;
149  }
150 }

References caloGeometry_, caloTopology_, EcalBarrel, EcalEndcap, ecalRegBarrel_, ecalRegEndcap_, ecalRegErrorBarrel_, ecalRegErrorEndcap_, Exception, EcalRegressionData::fill(), EcalRegressionData::fillVec(), GBRForest::GetResponse(), edm::Handle< T >::product(), reco::SuperCluster::seed(), and pwdgSkimBPark_cfi::vertices.

Referenced by applyEcalRegression().

◆ readEvent()

void RegressionHelper::readEvent ( const edm::Event )

Definition at line 125 of file RegressionHelper.cc.

125 { ; }

Member Data Documentation

◆ caloGeometry_

const CaloGeometry* RegressionHelper::caloGeometry_
private

Definition at line 57 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ caloGeometryCacheId_

unsigned long long RegressionHelper::caloGeometryCacheId_
private

Definition at line 62 of file RegressionHelper.h.

Referenced by checkSetup().

◆ caloTopology_

const CaloTopology* RegressionHelper::caloTopology_
private

Definition at line 56 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ caloTopologyCacheId_

unsigned long long RegressionHelper::caloTopologyCacheId_
private

Definition at line 61 of file RegressionHelper.h.

Referenced by checkSetup().

◆ cfg_

const Configuration RegressionHelper::cfg_
private

Definition at line 55 of file RegressionHelper.h.

Referenced by checkSetup().

◆ combinationReg_

const GBRForest* RegressionHelper::combinationReg_
private

Definition at line 70 of file RegressionHelper.h.

Referenced by applyCombinationRegression(), and checkSetup().

◆ combinationRegressionInitialized_

bool RegressionHelper::combinationRegressionInitialized_
private

Definition at line 59 of file RegressionHelper.h.

Referenced by checkSetup().

◆ ecalRegBarrel_

const GBRForest* RegressionHelper::ecalRegBarrel_
private

Definition at line 66 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegEndcap_

const GBRForest* RegressionHelper::ecalRegEndcap_
private

Definition at line 67 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegErrorBarrel_

const GBRForest* RegressionHelper::ecalRegErrorBarrel_
private

Definition at line 68 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegErrorEndcap_

const GBRForest* RegressionHelper::ecalRegErrorEndcap_
private

Definition at line 69 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegressionInitialized_

bool RegressionHelper::ecalRegressionInitialized_
private

Definition at line 58 of file RegressionHelper.h.

Referenced by checkSetup().

◆ regressionCacheId_

unsigned long long RegressionHelper::regressionCacheId_
private

Definition at line 63 of file RegressionHelper.h.

Referenced by checkSetup().

EgHLTOffHistBins_cfi.eOverP
eOverP
Definition: EgHLTOffHistBins_cfi.py:37
reco::GsfElectron::isEB
bool isEB() const
Definition: GsfElectron.h:336
RegressionHelper::Configuration::ecalRegressionWeightLabels
std::vector< std::string > ecalRegressionWeightLabels
Definition: RegressionHelper.h:27
edm::Handle::product
T const * product() const
Definition: Handle.h:70
RegressionHelper::ecalRegEndcap_
const GBRForest * ecalRegEndcap_
Definition: RegressionHelper.h:67
RegressionHelper::Configuration::combinationRegressionWeightLabels
std::vector< std::string > combinationRegressionWeightLabels
Definition: RegressionHelper.h:30
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
RegressionHelper::caloGeometryCacheId_
unsigned long long caloGeometryCacheId_
Definition: RegressionHelper.h:62
mps_merge.weight
weight
Definition: mps_merge.py:88
GBRForest
Definition: GBRForest.h:25
RegressionHelper::combinationReg_
const GBRForest * combinationReg_
Definition: RegressionHelper.h:70
RegressionHelper::caloTopologyCacheId_
unsigned long long caloTopologyCacheId_
Definition: RegressionHelper.h:61
reco::GsfElectron::P4_COMBINATION
Definition: GsfElectron.h:769
EcalRegressionData
Definition: EcalRegressionData.h:17
RegressionHelper::ecalRegErrorBarrel_
const GBRForest * ecalRegErrorBarrel_
Definition: RegressionHelper.h:68
CaloTopologyRecord
Definition: CaloTopologyRecord.h:10
RegressionHelper::ecalRegBarrel_
const GBRForest * ecalRegBarrel_
Definition: RegressionHelper.h:66
edmOneToOneComparison.file2
file2
Definition: edmOneToOneComparison.py:107
EcalBarrel
Definition: EcalSubdetector.h:10
RegressionHelper::Configuration::combinationWeightsFromDB
bool combinationWeightsFromDB
Definition: RegressionHelper.h:31
GBRForest::GetResponse
double GetResponse(const float *vector) const
Definition: GBRForest.h:49
reco::GsfElectron::SHOWERING
Definition: GsfElectron.h:724
config
Definition: config.py:1
edm::FileInPath
Definition: FileInPath.h:64
reco::GsfElectron::setP4
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:188
EcalRegressionData::fill
void fill(const reco::SuperCluster &superClus, const EcalRecHitCollection *ebRecHits, const EcalRecHitCollection *eeRecHits, const CaloGeometry *geom, const CaloTopology *topology, const reco::VertexCollection *vertices)
Definition: EcalRegressionData.h:82
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
RegressionHelper::cfg_
const Configuration cfg_
Definition: RegressionHelper.h:55
RegressionHelper::caloTopology_
const CaloTopology * caloTopology_
Definition: RegressionHelper.h:56
RegressionHelper::Configuration::combinationRegressionWeightFiles
std::vector< std::string > combinationRegressionWeightFiles
Definition: RegressionHelper.h:32
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::GsfElectron::trackMomentumAtVtx
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:276
reco::GsfElectron::GOLDEN
Definition: GsfElectron.h:724
edm::ESHandle< CaloTopology >
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
reco::GsfElectron::correctedEcalEnergyError
float correctedEcalEnergyError() const
Definition: GsfElectron.h:807
RegressionHelper::combinationRegressionInitialized_
bool combinationRegressionInitialized_
Definition: RegressionHelper.h:59
RegressionHelper::ecalRegErrorEndcap_
const GBRForest * ecalRegErrorEndcap_
Definition: RegressionHelper.h:69
EcalEndcap
Definition: EcalSubdetector.h:10
RegressionHelper::regressionCacheId_
unsigned long long regressionCacheId_
Definition: RegressionHelper.h:63
RegressionHelper::caloGeometry_
const CaloGeometry * caloGeometry_
Definition: RegressionHelper.h:57
reco::SuperCluster::seed
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
runTheMatrix.err
err
Definition: runTheMatrix.py:288
EcalRegressionData::fillVec
void fillVec(std::vector< float > &inputVec) const
Definition: EcalRegressionData.cc:158
reco::GsfElectron::ecalDriven
bool ecalDriven() const
Definition: GsfElectron.cc:168
get
#define get
reco::GsfElectron::p4
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:211
reco::GsfElectron::BIGBREM
Definition: GsfElectron.h:724
reco::GsfElectron::correctedEcalEnergy
float correctedEcalEnergy() const
Definition: GsfElectron.h:806
timingPdfMaker.file1
file1
Definition: timingPdfMaker.py:79
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
RegressionHelper::getEcalRegression
void getEcalRegression(const reco::SuperCluster &sc, const edm::Handle< reco::VertexCollection > &vertices, const edm::Handle< EcalRecHitCollection > &rechitsEB, const edm::Handle< EcalRecHitCollection > &rechitsEE, double &energyFactor, double &errorFactor) const
Definition: RegressionHelper.cc:127
Exception
Definition: hltDiff.cc:246
RegressionHelper::Configuration::ecalWeightsFromDB
bool ecalWeightsFromDB
Definition: RegressionHelper.h:28
reco::GsfElectron::classification
Classification classification() const
Definition: GsfElectron.h:730
RegressionHelper::ecalRegressionInitialized_
bool ecalRegressionInitialized_
Definition: RegressionHelper.h:58
GBRWrapperRcd
Definition: GBRWrapperRcd.h:24
reco::GsfElectron::GAP
Definition: GsfElectron.h:724
reco::GsfElectron::trackerDrivenSeed
bool trackerDrivenSeed() const
Definition: GsfElectron.h:167
reco::GsfElectron::trackMomentumError
float trackMomentumError() const
Definition: GsfElectron.h:808
edm::eventsetup::EventSetupRecordImplementation::get
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: EventSetupRecordImplementation.h:74
reco::GsfElectron::BADTRACK
Definition: GsfElectron.h:724
RegressionHelper::Configuration::ecalRegressionWeightFiles
std::vector< std::string > ecalRegressionWeightFiles
Definition: RegressionHelper.h:29
weight
Definition: weight.py:1
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7