CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EpCombinationTool.cc
Go to the documentation of this file.
3 #include <TFile.h>
4 #include <TSystem.h>
5 #include <math.h>
6 #include <vector>
7 #include <iostream>
8 
9 using namespace std;
10 
11 
12 /*****************************************************************/
14  m_forest(NULL)
15 /*****************************************************************/
16 {
17 }
18 
19 
20 
21 /*****************************************************************/
23 /*****************************************************************/
24 {
25  if(m_forest) delete m_forest;
26 }
27 
28 
29 /*****************************************************************/
30 bool EpCombinationTool::init(const string& regressionFileName, const string& bdtName)
31 /*****************************************************************/
32 {
33  TFile* regressionFile = TFile::Open(regressionFileName.c_str());
34  if(!regressionFile)
35  {
36  cout<<"ERROR: Cannot open regression file "<<regressionFileName<<"\n";
37  return false;
38  }
39  m_forest = (GBRForest*) regressionFile->Get(bdtName.c_str());
40  //regressionFile->GetObject(bdtName.c_str(), m_forest);
41  if(!m_forest)
42  {
43  cout<<"ERROR: Cannot find forest "<<bdtName<<" in "<<regressionFileName<<"\n";
44  regressionFile->Close();
45  return false;
46  }
47  regressionFile->Close();
48  return true;
49 }
50 
51 
52 
53 /*****************************************************************/
55 /*****************************************************************/
56 {
57  if(!m_forest)
58  {
59  cout<<"ERROR: The combination tool is not initialized\n";
60  return;
61  }
62 
63  float energy = mySimpleElectron.getNewEnergy();
64  float energyError = mySimpleElectron.getNewEnergyError();
65  float momentum = mySimpleElectron.getTrackerMomentum();
66  float momentumError = mySimpleElectron.getTrackerMomentumError();
67  int electronClass = mySimpleElectron.getElClass();
68  bool isEcalDriven = mySimpleElectron.isEcalDriven();
69  bool isTrackerDriven = mySimpleElectron.isTrackerDriven();
70  bool isEB = mySimpleElectron.isEB();
71 
72  // compute relative errors and ratio of errors
73  float energyRelError = energyError / energy;
74  float momentumRelError = momentumError / momentum;
75  float errorRatio = energyRelError / momentumRelError;
76 
77  // calculate E/p and corresponding error
78  float eOverP = energy / momentum;
79  float eOverPerror = sqrt(
80  (energyError/momentum)*(energyError/momentum) +
81  (energy*momentumError/momentum/momentum)*
82  (energy*momentumError/momentum/momentum));
83 
84  // fill input variables
85  float* regressionInputs = new float[11];
86  regressionInputs[0] = energy;
87  regressionInputs[1] = energyRelError;
88  regressionInputs[2] = momentum;
89  regressionInputs[3] = momentumRelError;
90  regressionInputs[4] = errorRatio;
91  regressionInputs[5] = eOverP;
92  regressionInputs[6] = eOverPerror;
93  regressionInputs[7] = static_cast<float>(isEcalDriven);
94  regressionInputs[8] = static_cast<float>(isTrackerDriven);
95  regressionInputs[9] = static_cast<float>(electronClass);
96  regressionInputs[10] = static_cast<float>(isEB);
97 
98  // retrieve combination weight
99  float weight = 0.;
100  if(eOverP>0.025
101  &&fabs(momentum-energy)<15.*sqrt(momentumError*momentumError + energyError*energyError)
102  ) // protection against crazy track measurement
103  {
104  weight = m_forest->GetResponse(regressionInputs);
105  if(weight>1.) weight = 1.;
106  else if(weight<0.) weight = 0.;
107  }
108 
109  float combinedMomentum = weight*momentum + (1.-weight)*energy;
110  float combinedMomentumError = sqrt(weight*weight*momentumError*momentumError + (1.-weight)*(1.-weight)*energyError*energyError);
111 
112  // FIXME : pure tracker electrons have track momentum error of 999.
113  // If the combination try to combine such electrons then the original combined momentum is kept
114  if(momentumError!=999. || weight==0.)
115  {
116  mySimpleElectron.setCombinedMomentum(combinedMomentum);
117  mySimpleElectron.setCombinedMomentumError(combinedMomentumError);
118  }
119 
120  delete[] regressionInputs;
121 }
double GetResponse(const float *vector) const
Definition: GBRForest.h:51
bool init(const std::string &regressionFile, const std::string &bdtName="")
void setCombinedMomentum(double combinedMomentum)
bool isTrackerDriven()
void combine(SimpleElectron &mySimpleElectron)
#define NULL
Definition: scimark2.h:8
double getTrackerMomentum()
double getNewEnergyError()
double getTrackerMomentumError()
T sqrt(T t)
Definition: SSEVec.h:48
double getNewEnergy()
tuple cout
Definition: gather_cfg.py:121
int weight
Definition: histoStyle.py:50
void setCombinedMomentumError(double combinedMomentumError)
float energyError(float E, float *par)