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 24 of file RegressionHelper.h.

Constructor & Destructor Documentation

RegressionHelper::RegressionHelper ( const Configuration config)

Definition at line 11 of file RegressionHelper.cc.

11  :
14 {;}
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 16 of file RegressionHelper.cc.

16 {;}

Member Function Documentation

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

Definition at line 165 of file RegressionHelper.cc.

References reco::GsfElectron::BADTRACK, reco::GsfElectron::BIGBREM, reco::GsfElectron::classification(), combinationReg_, reco::GsfElectron::correctedEcalEnergy(), reco::GsfElectron::correctedEcalEnergyError(), reco::GsfElectron::ecalDriven(), randomXiThetaGunProducer_cfi::energy, energyError(), 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().

166 {
167  float energy = ele.correctedEcalEnergy();
169  float momentum = ele.trackMomentumAtVtx().R();
170  float momentumError = ele.trackMomentumError();
171  int elClass = -1;
172 
173  switch (ele.classification()) {
175  elClass = 0;
176  break;
178  elClass = 1;
179  break;
181  elClass = 2;
182  break;
184  elClass = 3;
185  break;
187  elClass = 4;
188  break;
189  default:
190  elClass = -1;
191  }
192 
193 
194  bool isEcalDriven = ele.ecalDriven();
195  bool isTrackerDriven = ele.trackerDrivenSeed();
196  bool isEB = ele.isEB();
197 
198  // compute relative errors and ratio of errors
199  float energyRelError = energyError / energy;
200  float momentumRelError = momentumError / momentum;
201  float errorRatio = energyRelError / momentumRelError;
202 
203  // calculate E/p and corresponding error
204  float eOverP = energy / momentum;
205  float eOverPerror = eOverP*std::hypot(energyRelError,momentumRelError);
206 
207  // fill input variables
208  std::vector<float> regressionInputs ;
209  regressionInputs.resize(11,0.);
210 
211  regressionInputs[0] = energy;
212  regressionInputs[1] = energyRelError;
213  regressionInputs[2] = momentum;
214  regressionInputs[3] = momentumRelError;
215  regressionInputs[4] = errorRatio;
216  regressionInputs[5] = eOverP;
217  regressionInputs[6] = eOverPerror;
218  regressionInputs[7] = static_cast<float>(isEcalDriven);
219  regressionInputs[8] = static_cast<float>(isTrackerDriven);
220  regressionInputs[9] = static_cast<float>(elClass);
221  regressionInputs[10] = static_cast<float>(isEB);
222 
223  // retrieve combination weight
224  float weight = 0.;
225  if(eOverP>0.025
226  &&fabs(momentum-energy)<15.*sqrt(momentumError*momentumError + energyError*energyError)
227  ) // protection against crazy track measurement
228  {
229  weight = combinationReg_->GetResponse(regressionInputs.data());
230  if(weight>1.) weight = 1.;
231  else if(weight<0.) weight = 0.;
232  }
233 
234  float combinedMomentum = weight*momentum + (1.-weight)*energy;
235  float combinedMomentumError = sqrt(weight*weight*momentumError*momentumError + (1.-weight)*(1.-weight)*energyError*energyError);
236 
237  // FIXME : pure tracker electrons have track momentum error of 999.
238  // If the combination try to combine such electrons then the original combined momentum is kept
239  if(momentumError!=999. || weight==0.)
240  {
241  math::XYZTLorentzVector oldMomentum = ele.p4() ;
242  math::XYZTLorentzVector newMomentum(oldMomentum.x()*combinedMomentum/oldMomentum.t(),
243  oldMomentum.y()*combinedMomentum/oldMomentum.t(),
244  oldMomentum.z()*combinedMomentum/oldMomentum.t(),
245  combinedMomentum);
246 
247  ele.setP4(reco::GsfElectron::P4_COMBINATION,newMomentum,combinedMomentumError,true);
248  }
249 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:53
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:199
float trackMomentumError() const
Definition: GsfElectron.h:846
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:295
Definition: weight.py:1
bool isEB() const
Definition: GsfElectron.h:356
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T sqrt(T t)
Definition: SSEVec.h:18
float correctedEcalEnergy() const
Definition: GsfElectron.h:844
Classification classification() const
Definition: GsfElectron.h:767
float correctedEcalEnergyError() const
Definition: GsfElectron.h:845
bool trackerDrivenSeed() const
Definition: GsfElectron.h:189
bool ecalDriven() const
Definition: GsfElectron.cc:174
float energyError(float E, float *par)
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 18 of file RegressionHelper.cc.

References getEcalRegression(), reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), reco::GsfElectron::superCluster(), and electrons_cff::vertices.

Referenced by GsfElectronAlgo::createElectron().

21  {
22  double cor, err;
23  getEcalRegression(*ele.superCluster(), vertices, rechitsEB, rechitsEE, cor, err);
24  ele.setCorrectedEcalEnergy(cor * ele.superCluster()->correctedEnergy());
25  ele.setCorrectedEcalEnergyError( err * ele.superCluster()->correctedEnergy());
26 
27 }
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 29 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, edmOneToOneComparison::file1, edmOneToOneComparison::file2, edm::EventSetup::get(), edm::eventsetup::EventSetupRecordImplementation< T >::get(), and regressionCacheId_.

Referenced by GsfElectronAlgo::checkSetup().

29  {
30 
31  // Topology
32  unsigned long long newCaloTopologyCacheId
33  = es.get<CaloTopologyRecord>().cacheIdentifier() ;
34  if (!caloTopologyCacheId_ || ( caloTopologyCacheId_ != newCaloTopologyCacheId ) )
35  {
36  caloTopologyCacheId_ = newCaloTopologyCacheId;
38  es.get<CaloTopologyRecord>().get(caloTopo);
39  caloTopology_ = &(*caloTopo);
40  }
41 
42  // Geometry
43  unsigned long long newCaloGeometryCacheId
44  = es.get<CaloGeometryRecord>().cacheIdentifier() ;
45  if (!caloGeometryCacheId_ || ( caloGeometryCacheId_ != newCaloGeometryCacheId ) )
46  {
47  caloGeometryCacheId_ = newCaloGeometryCacheId;
49  es.get<CaloGeometryRecord>().get(caloGeom);
50  caloGeometry_ = &(*caloGeom);
51  }
52 
53  // Ecal regression
54 
55  // if at least one of the set of weights come from the DB
57  {
58  unsigned long long newRegressionCacheId
59  = es.get<GBRWrapperRcd>().cacheIdentifier() ;
60  if ( !regressionCacheId_ || (newRegressionCacheId != regressionCacheId_ ) ) {
61 
62  const GBRWrapperRcd& gbrRcd = es.get<GBRWrapperRcd>();
63 
64  // ECAL barrel
65  edm::ESHandle<GBRForest> ecalRegBarrelH;
66  gbrRcd.get(cfg_.ecalRegressionWeightLabels[0].c_str(),ecalRegBarrelH);
67  ecalRegBarrel_ = &(*ecalRegBarrelH);
68 
69  // ECAL endcaps
70  edm::ESHandle<GBRForest> ecalRegEndcapH;
71  gbrRcd.get(cfg_.ecalRegressionWeightLabels[1].c_str(),ecalRegEndcapH);
72  ecalRegEndcap_= &(*ecalRegEndcapH);
73 
74  // ECAL barrel error
75  edm::ESHandle<GBRForest> ecalRegErrorBarrelH;
76  gbrRcd.get(cfg_.ecalRegressionWeightLabels[2].c_str(),ecalRegErrorBarrelH);
77  ecalRegErrorBarrel_ = &(*ecalRegErrorBarrelH);
78 
79  // ECAL endcap error
80  edm::ESHandle<GBRForest> ecalRegErrorEndcapH;
81  gbrRcd.get(cfg_.ecalRegressionWeightLabels[3].c_str(),ecalRegErrorEndcapH);
82  ecalRegErrorEndcap_ = &(*ecalRegErrorEndcapH);
83 
85  }
86  }
88  {
89 
90  // Combination
92  {
93  unsigned long long newRegressionCacheId
94  = es.get<GBRWrapperRcd>().cacheIdentifier() ;
95  if ( !regressionCacheId_ || (newRegressionCacheId != regressionCacheId_ ) ) {
96 
97  const GBRWrapperRcd& gbrRcd = es.get<GBRWrapperRcd>();
98 
99  edm::ESHandle<GBRForest> combinationRegH;
100  gbrRcd.get(cfg_.combinationRegressionWeightLabels[0].c_str(),combinationRegH);
101  combinationReg_ = &(*combinationRegH);
102 
104  }
105  }
106  }
107 
108  // read weights from file - for debugging. Even if it is one single files, 4 files should b set in the vector
110  !cfg_.ecalRegressionWeightFiles.empty() ) {
111  TFile file0 (edm::FileInPath(cfg_.ecalRegressionWeightFiles[0].c_str()).fullPath().c_str());
112  ecalRegBarrel_ = (const GBRForest*)file0.Get(cfg_.ecalRegressionWeightLabels[0].c_str());
113  file0.Close();
114  TFile file1 (edm::FileInPath(cfg_.ecalRegressionWeightFiles[1].c_str()).fullPath().c_str());
116  file1.Close();
117  TFile file2 (edm::FileInPath(cfg_.ecalRegressionWeightFiles[2].c_str()).fullPath().c_str());
119  file2.Close();
120  TFile file3 (edm::FileInPath(cfg_.ecalRegressionWeightFiles[3].c_str()).fullPath().c_str());
121  ecalRegErrorEndcap_ = (const GBRForest*)file3.Get(cfg_.ecalRegressionWeightLabels[3].c_str());
123  file3.Close();
124  }
125 
128  {
129  TFile file0 (edm::FileInPath(cfg_.combinationRegressionWeightFiles[0].c_str()).fullPath().c_str());
130  combinationReg_ = (const GBRForest*)file0.Get(cfg_.combinationRegressionWeightLabels[0].c_str());
132  file0.Close();
133  }
134 
135 }
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:71
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 139 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().

143  {
144 
145  energyFactor = -999.;
146  errorFactor = -999.;
147 
148  std::vector<float> rInputs;
149  EcalRegressionData regData;
150  regData.fill(sc,rechitsEB.product(),rechitsEE.product(),caloGeometry_,caloTopology_,vertices.product());
151  regData.fillVec(rInputs);
152  if(sc.seed()->hitsAndFractions()[0].first.subdetId()==EcalBarrel){
153  energyFactor = ecalRegBarrel_->GetResponse(&rInputs[0]);
154  errorFactor = ecalRegErrorBarrel_->GetResponse(&rInputs[0]);
155  }else if(sc.seed()->hitsAndFractions()[0].first.subdetId()==EcalEndcap){
156  energyFactor = ecalRegEndcap_->GetResponse(&rInputs[0]);
157  errorFactor = ecalRegErrorEndcap_->GetResponse(&rInputs[0]);
158  }else{
159  throw cms::Exception("RegressionHelper::calculateRegressedEnergy")
160  << "Supercluster seed is either EB nor EE!" << std::endl;
161  }
162 
163 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:53
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:74
const GBRForest * ecalRegErrorEndcap_
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
const CaloGeometry * caloGeometry_
void RegressionHelper::readEvent ( const edm::Event )

Definition at line 137 of file RegressionHelper.cc.

137 {;}

Member Data Documentation

const CaloGeometry* RegressionHelper::caloGeometry_
private

Definition at line 60 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

unsigned long long RegressionHelper::caloGeometryCacheId_
private

Definition at line 65 of file RegressionHelper.h.

Referenced by checkSetup().

const CaloTopology* RegressionHelper::caloTopology_
private

Definition at line 59 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

unsigned long long RegressionHelper::caloTopologyCacheId_
private

Definition at line 64 of file RegressionHelper.h.

Referenced by checkSetup().

const Configuration RegressionHelper::cfg_
private

Definition at line 58 of file RegressionHelper.h.

Referenced by checkSetup().

const GBRForest* RegressionHelper::combinationReg_
private

Definition at line 73 of file RegressionHelper.h.

Referenced by applyCombinationRegression(), and checkSetup().

bool RegressionHelper::combinationRegressionInitialized_
private

Definition at line 62 of file RegressionHelper.h.

Referenced by checkSetup().

const GBRForest* RegressionHelper::ecalRegBarrel_
private

Definition at line 69 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegEndcap_
private

Definition at line 70 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegErrorBarrel_
private

Definition at line 71 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegErrorEndcap_
private

Definition at line 72 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

bool RegressionHelper::ecalRegressionInitialized_
private

Definition at line 61 of file RegressionHelper.h.

Referenced by checkSetup().

unsigned long long RegressionHelper::regressionCacheId_
private

Definition at line 66 of file RegressionHelper.h.

Referenced by checkSetup().