CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_
 
EcalClusterLocal ecl_
 
unsigned long long regressionCacheId_
 

Detailed Description

Definition at line 29 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_
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(), relval_parameters_module::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 histoStyle::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  bool isEcalDriven = ele.ecalDriven();
194  bool isTrackerDriven = ele.trackerDrivenSeed();
195  bool isEB = ele.isEB();
196 
197  // compute relative errors and ratio of errors
198  float energyRelError = energyError / energy;
199  float momentumRelError = momentumError / momentum;
200  float errorRatio = energyRelError / momentumRelError;
201 
202  // calculate E/p and corresponding error
203  float eOverP = energy / momentum;
204  float eOverPerror = eOverP*std::hypot(energyRelError,momentumRelError);
205 
206  // fill input variables
207  std::vector<float> regressionInputs ;
208  regressionInputs.resize(11,0.);
209 
210  regressionInputs[0] = energy;
211  regressionInputs[1] = energyRelError;
212  regressionInputs[2] = momentum;
213  regressionInputs[3] = momentumRelError;
214  regressionInputs[4] = errorRatio;
215  regressionInputs[5] = eOverP;
216  regressionInputs[6] = eOverPerror;
217  regressionInputs[7] = static_cast<float>(isEcalDriven);
218  regressionInputs[8] = static_cast<float>(isTrackerDriven);
219  regressionInputs[9] = static_cast<float>(elClass);
220  regressionInputs[10] = static_cast<float>(isEB);
221 
222  // retrieve combination weight
223  float weight = 0.;
224  if(eOverP>0.025
225  &&fabs(momentum-energy)<15.*sqrt(momentumError*momentumError + energyError*energyError)
226  ) // protection against crazy track measurement
227  {
228  weight = combinationReg_->GetResponse(regressionInputs.data());
229  if(weight>1.) weight = 1.;
230  else if(weight<0.) weight = 0.;
231  }
232 
233  float combinedMomentum = weight*momentum + (1.-weight)*energy;
234  float combinedMomentumError = sqrt(weight*weight*momentumError*momentumError + (1.-weight)*(1.-weight)*energyError*energyError);
235 
236  // FIXME : pure tracker electrons have track momentum error of 999.
237  // If the combination try to combine such electrons then the original combined momentum is kept
238  if(momentumError!=999. || weight==0.)
239  {
240  math::XYZTLorentzVector oldMomentum = ele.p4() ;
241  math::XYZTLorentzVector newMomentum(oldMomentum.x()*combinedMomentum/oldMomentum.t(),
242  oldMomentum.y()*combinedMomentum/oldMomentum.t(),
243  oldMomentum.z()*combinedMomentum/oldMomentum.t(),
244  combinedMomentum);
245 
246  ele.setP4(reco::GsfElectron::P4_COMBINATION,newMomentum,combinedMomentumError,true);
247  }
248  }
249 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:59
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:197
float trackMomentumError() const
Definition: GsfElectron.h:759
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:223
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:289
bool isEB() const
Definition: GsfElectron.h:350
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
T sqrt(T t)
Definition: SSEVec.h:48
float correctedEcalEnergy() const
Definition: GsfElectron.h:757
Classification classification() const
Definition: GsfElectron.h:680
float correctedEcalEnergyError() const
Definition: GsfElectron.h:758
bool trackerDrivenSeed() const
Definition: GsfElectron.h:187
int weight
Definition: histoStyle.py:50
bool ecalDriven() const
Definition: GsfElectron.cc:172
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 HLT_25ns14e33_v1_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, timingPdfMaker::file1, contentValuesFiles::fullPath, edm::EventSetup::get(), edm::eventsetup::EventSetupRecord::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
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());
118  ecalRegErrorBarrel_ = (const GBRForest*)file2.Get(cfg_.ecalRegressionWeightLabels[2].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_
const CaloTopology * caloTopology_
const GBRForest * ecalRegBarrel_
const GBRForest * ecalRegErrorBarrel_
void get(HolderT &iHolder) const
std::vector< std::string > combinationRegressionWeightFiles
const T & get() const
Definition: EventSetup.h:55
const GBRForest * ecalRegErrorEndcap_
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:59
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:81
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 65 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

unsigned long long RegressionHelper::caloGeometryCacheId_
private

Definition at line 70 of file RegressionHelper.h.

Referenced by checkSetup().

const CaloTopology* RegressionHelper::caloTopology_
private

Definition at line 64 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

unsigned long long RegressionHelper::caloTopologyCacheId_
private

Definition at line 69 of file RegressionHelper.h.

Referenced by checkSetup().

const Configuration RegressionHelper::cfg_
private

Definition at line 63 of file RegressionHelper.h.

Referenced by checkSetup().

const GBRForest* RegressionHelper::combinationReg_
private

Definition at line 78 of file RegressionHelper.h.

Referenced by applyCombinationRegression(), and checkSetup().

bool RegressionHelper::combinationRegressionInitialized_
private

Definition at line 67 of file RegressionHelper.h.

Referenced by checkSetup().

const GBRForest* RegressionHelper::ecalRegBarrel_
private

Definition at line 74 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegEndcap_
private

Definition at line 75 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegErrorBarrel_
private

Definition at line 76 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

const GBRForest* RegressionHelper::ecalRegErrorEndcap_
private

Definition at line 77 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

bool RegressionHelper::ecalRegressionInitialized_
private

Definition at line 66 of file RegressionHelper.h.

Referenced by checkSetup().

EcalClusterLocal RegressionHelper::ecl_
private

Definition at line 80 of file RegressionHelper.h.

unsigned long long RegressionHelper::regressionCacheId_
private

Definition at line 71 of file RegressionHelper.h.

Referenced by checkSetup().