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 ( const Configuration config)

Definition at line 11 of file RegressionHelper.cc.

12  : cfg_(config),
18  ;
19 }
unsigned long long caloGeometryCacheId_
unsigned long long regressionCacheId_
unsigned long long caloTopologyCacheId_
Definition: config.py:1
const Configuration cfg_
bool combinationRegressionInitialized_
RegressionHelper::~RegressionHelper ( )

Definition at line 21 of file RegressionHelper.cc.

21 { ; }

Member Function Documentation

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

Definition at line 152 of file RegressionHelper.cc.

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().

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 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:49
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:188
float trackMomentumError() const
Definition: GsfElectron.h:800
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:211
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:268
Definition: weight.py:1
bool isEB() const
Definition: GsfElectron.h:328
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T sqrt(T t)
Definition: SSEVec.h:19
float correctedEcalEnergy() const
Definition: GsfElectron.h:798
Classification classification() const
Definition: GsfElectron.h:722
float correctedEcalEnergyError() const
Definition: GsfElectron.h:799
bool trackerDrivenSeed() const
Definition: GsfElectron.h:159
bool ecalDriven() const
Definition: GsfElectron.cc:168
const GBRForest * combinationReg_
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.

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

Referenced by GsfElectronAlgo::createElectron().

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 }
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
void RegressionHelper::checkSetup ( const edm::EventSetup es)

Definition at line 33 of file RegressionHelper.cc.

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(), and regressionCacheId_.

Referenced by GsfElectronAlgo::checkSetup().

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 }
std::vector< std::string > ecalRegressionWeightFiles
unsigned long long caloGeometryCacheId_
std::vector< std::string > combinationRegressionWeightLabels
unsigned long long regressionCacheId_
const GBRForest * ecalRegEndcap_
std::vector< std::string > ecalRegressionWeightLabels
unsigned long long caloTopologyCacheId_
const Configuration cfg_
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
const CaloTopology * caloTopology_
const GBRForest * ecalRegBarrel_
const GBRForest * ecalRegErrorBarrel_
std::vector< std::string > combinationRegressionWeightFiles
const GBRForest * ecalRegErrorEndcap_
T get() const
Definition: EventSetup.h:73
bool combinationRegressionInitialized_
const CaloGeometry * caloGeometry_
const GBRForest * combinationReg_
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.

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

Referenced by applyEcalRegression().

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 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:49
const GBRForest * ecalRegEndcap_
void fill(const reco::SuperCluster &superClus, const EcalRecHitCollection *ebRecHits, const EcalRecHitCollection *eeRecHits, const CaloGeometry *geom, const CaloTopology *topology, const reco::VertexCollection *vertices)
const CaloTopology * caloTopology_
const GBRForest * ecalRegBarrel_
const GBRForest * ecalRegErrorBarrel_
void fillVec(std::vector< float > &inputVec) const
T const * product() const
Definition: Handle.h:69
const GBRForest * ecalRegErrorEndcap_
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
const CaloGeometry * caloGeometry_
void RegressionHelper::readEvent ( const edm::Event )

Definition at line 125 of file RegressionHelper.cc.

125 { ; }

Member Data Documentation

const CaloGeometry* RegressionHelper::caloGeometry_
private

Definition at line 57 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

unsigned long long RegressionHelper::caloGeometryCacheId_
private

Definition at line 62 of file RegressionHelper.h.

Referenced by checkSetup().

const CaloTopology* RegressionHelper::caloTopology_
private

Definition at line 56 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

unsigned long long RegressionHelper::caloTopologyCacheId_
private

Definition at line 61 of file RegressionHelper.h.

Referenced by checkSetup().

const Configuration RegressionHelper::cfg_
private

Definition at line 55 of file RegressionHelper.h.

Referenced by checkSetup().

const GBRForest* RegressionHelper::combinationReg_
private

Definition at line 70 of file RegressionHelper.h.

Referenced by applyCombinationRegression(), and checkSetup().

bool RegressionHelper::combinationRegressionInitialized_
private

Definition at line 59 of file RegressionHelper.h.

Referenced by checkSetup().

const GBRForest* RegressionHelper::ecalRegBarrel_
private

Definition at line 66 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegEndcap_
private

Definition at line 67 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegErrorBarrel_
private

Definition at line 68 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegErrorEndcap_
private

Definition at line 69 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

bool RegressionHelper::ecalRegressionInitialized_
private

Definition at line 58 of file RegressionHelper.h.

Referenced by checkSetup().

unsigned long long RegressionHelper::regressionCacheId_
private

Definition at line 63 of file RegressionHelper.h.

Referenced by checkSetup().