CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
pftools::PFClusterCalibration Class Reference

#include <PFClusterCalibration.h>

Public Member Functions

void calibrate (Calibratable &c)
 
void calibrateTree (TTree *tree)
 
double getCalibratedEcalEnergy (const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
 
double getCalibratedEnergy (const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
 
void getCalibratedEnergyEmbedAInHcal (double &ecalE, double &hcalE, const double &eta, const double &phi) const
 
double getCalibratedHcalEnergy (const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
 
void getCalibrationResultWrapper (const Calibratable &c, CalibrationResultWrapper &crw)
 
std::vector< std::string > * getKnownSectorNames ()
 
 PFClusterCalibration ()
 
void setAllowNegativeEnergy (const bool &allowIt)
 
void setBarrelBoundary (const double &eta)
 
void setCorrections (const double &lowEP0, const double &lowEP1, const double &globalP0, const double &globalP1)
 
void setDoCorrection (const int &doCorrection)
 
void setDoEtaCorrection (const int doEtaCorrection)
 
void setEcalHcalEnergyCuts (const double &ecalCut, const double &hcalCut)
 
void setEtaCorrectionParameters (const std::vector< double > &params)
 
void setEvolutionParameters (const std::string &sector, const std::vector< double > &params)
 
void setMaxEToCorrect (double maxE)
 
virtual ~PFClusterCalibration ()
 

Private Member Functions

void init ()
 

Private Attributes

int allowNegativeEnergy_
 
double barrelEndcapEtaDiv_
 
TF1 * correction_
 
double correctionLowLimit_
 
int doCorrection_
 
int doEtaCorrection_
 
double ecalOnlyDiv_
 
TF1 * etaCorrection_
 
double globalP0_
 
double globalP1_
 
double hcalOnlyDiv_
 
double lowEP0_
 
double lowEP1_
 
double maxEToCorrect_
 
std::vector< std::string > names_
 
std::map< std::string, TF1 > namesAndFunctions_
 

Friends

std::ostream & pftools::operator<< (std::ostream &s, const PFClusterCalibration &cc)
 

Detailed Description

Definition at line 40 of file PFClusterCalibration.h.

Constructor & Destructor Documentation

PFClusterCalibration::PFClusterCalibration ( )

Definition at line 104 of file PFClusterCalibration.cc.

References init().

104  :
108  globalP1_(1.0), lowEP0_(0.0), lowEP1_(1.0) {
109  // std::cout << __PRETTY_FUNCTION__ << std::endl;
110  init();
111  // std::cout
112  // << "WARNING! PFClusterCalibration evolution functions have not yet been initialised - ensure this is done.\n";
113  // std::cout << "PFClusterCalibration construction complete."<< std::endl;
114 
115 }
PFClusterCalibration::~PFClusterCalibration ( )
virtual

Definition at line 117 of file PFClusterCalibration.cc.

References correction_, and etaCorrection_.

Member Function Documentation

void PFClusterCalibration::calibrate ( Calibratable c)

Definition at line 263 of file PFClusterCalibration.cc.

References pftools::Calibratable::calibrations_, and getCalibrationResultWrapper().

Referenced by calibrateTree().

263  {
266  c.calibrations_.push_back(crw);
267 
268 }
std::vector< CalibrationResultWrapper > calibrations_
Definition: Calibratable.h:206
void getCalibrationResultWrapper(const Calibratable &c, CalibrationResultWrapper &crw)
A small class designed to hold the result of a calibration of a SingleParticleWrapper.
void PFClusterCalibration::calibrateTree ( TTree *  tree)

Definition at line 292 of file PFClusterCalibration.cc.

References calibrate(), and gather_cfg::cout.

292  {
293  std::cout << __PRETTY_FUNCTION__
294  << ": WARNING! This isn't working properly yet!\n";
295  TBranch* calibBr = input->GetBranch("Calibratable");
296  Calibratable* calib_ptr = new Calibratable();
297  calibBr->SetAddress(&calib_ptr);
298 
299  // TBranch* newBranch = input->Branch("NewCalibratable",
300  // "pftools::Calibratable", &calib_ptr, 32000, 2);
301 
302  std::cout << "Looping over tree's "<< input->GetEntries()
303  << " entries...\n";
304  for (unsigned entries(0); entries < 20000; entries++) {
305  if (entries % 10000== 0)
306  std::cout << "\tProcessing entry "<< entries << "\n";
307  input->GetEntry(entries);
308  calibrate(*calib_ptr);
309  input->Fill();
310  }
311  //input.Write("",TObject::kOverwrite);
312 }
Wraps essential single particle calibration data ready for export to a Root file. ...
Definition: Calibratable.h:122
static std::string const input
Definition: EdmProvDump.cc:44
tuple cout
Definition: gather_cfg.py:145
double PFClusterCalibration::getCalibratedEcalEnergy ( const double &  ecalE,
const double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 178 of file PFClusterCalibration.cc.

References assert(), barrelEndcapEtaDiv_, and namesAndFunctions_.

Referenced by pftools::CalibCompare::evaluateCalibrations(), pftools::Exercises3::evaluateCalibrator(), getCalibratedEnergy(), getCalibratedEnergyEmbedAInHcal(), and getCalibrationResultWrapper().

179  {
180  const TF1* theFunction(0);
181 
182  if (fabs(eta) < barrelEndcapEtaDiv_) {
183  //barrel
184  theFunction = &(namesAndFunctions_.find("ecalHcalEcalBarrel")->second);
185  } else {
186  //endcap
187  theFunction = &(namesAndFunctions_.find("ecalHcalEcalEndcap")->second);
188  }
189 
190  assert(theFunction != 0);
191  double totalE(ecalE + hcalE);
192  double bCoeff = theFunction->Eval(totalE);
193  return ecalE * bCoeff;
194 }
std::map< std::string, TF1 > namesAndFunctions_
assert(m_qm.get())
double PFClusterCalibration::getCalibratedEnergy ( const double &  ecalE,
const double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 214 of file PFClusterCalibration.cc.

References allowNegativeEnergy_, submit::answer, correction_, doCorrection_, doEtaCorrection_, etaCorrection_, getCalibratedEcalEnergy(), getCalibratedHcalEnergy(), and maxEToCorrect_.

Referenced by pftools::CalibCompare::evaluateCalibrations(), pftools::Exercises3::evaluateCalibrator(), and getCalibrationResultWrapper().

215  {
216  double totalE(ecalE + hcalE);
217  double answer(totalE);
218 
219  answer = getCalibratedEcalEnergy(ecalE, hcalE, eta, phi)
220  + getCalibratedHcalEnergy(ecalE, hcalE, eta, phi);
221  if (doEtaCorrection_)
222  answer = answer/etaCorrection_->Eval(eta);
223 
225  return correction_->Eval(answer);
226  if (doCorrection_) {
228  answer = correction_->Eval(answer);
229  else if (maxEToCorrect_ < 0) {
230  answer = correction_->Eval(answer);
231  }
232  }
233  if (!allowNegativeEnergy_ && answer < 0)
234  return 0;
235  return answer;
236 
237 }
answer
Definition: submit.py:44
double getCalibratedHcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double getCalibratedEcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
void PFClusterCalibration::getCalibratedEnergyEmbedAInHcal ( double &  ecalE,
double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 239 of file PFClusterCalibration.cc.

References a, allowNegativeEnergy_, correction_, doCorrection_, doEtaCorrection_, etaCorrection_, getCalibratedEcalEnergy(), and getCalibratedHcalEnergy().

240  {
241 
242  double ecalEOld(ecalE);
243  double hcalEOld(hcalE);
244 
245  ecalE = getCalibratedEcalEnergy(ecalEOld, hcalEOld, eta, phi);
246  hcalE = getCalibratedHcalEnergy(ecalEOld, hcalEOld, eta, phi);
247 
248  double preCorrection(ecalE + hcalE);
249  if (doEtaCorrection_)
250  preCorrection = preCorrection/etaCorrection_->Eval(eta);
251 
252  if (doCorrection_) {
253  double corrE = correction_->Eval(preCorrection);
254  //a term = difference
255  double a = corrE - preCorrection;
256  hcalE += a;
257  }
258  if (hcalE < 0 && !allowNegativeEnergy_)
259  hcalE = 0;
260 
261 }
double getCalibratedHcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double getCalibratedEcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double a
Definition: hdecay.h:121
double PFClusterCalibration::getCalibratedHcalEnergy ( const double &  ecalE,
const double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 196 of file PFClusterCalibration.cc.

References assert(), barrelEndcapEtaDiv_, and namesAndFunctions_.

Referenced by pftools::CalibCompare::evaluateCalibrations(), pftools::Exercises3::evaluateCalibrator(), getCalibratedEnergy(), getCalibratedEnergyEmbedAInHcal(), and getCalibrationResultWrapper().

197  {
198  const TF1* theFunction(0);
199 
200  if (fabs(eta) < barrelEndcapEtaDiv_) {
201  //barrel
202  theFunction = &(namesAndFunctions_.find("ecalHcalHcalBarrel")->second);
203  } else {
204  //endcap
205  theFunction = &(namesAndFunctions_.find("ecalHcalHcalEndcap")->second);
206  }
207 
208  double totalE(ecalE + hcalE);
209  assert(theFunction != 0);
210  double cCoeff = theFunction->Eval(totalE);
211  return hcalE * cCoeff;
212 }
std::map< std::string, TF1 > namesAndFunctions_
assert(m_qm.get())
void PFClusterCalibration::getCalibrationResultWrapper ( const Calibratable c,
CalibrationResultWrapper crw 
)

Definition at line 270 of file PFClusterCalibration.cc.

References pftools::CalibrationResultWrapper::b_, pftools::CalibrationResultWrapper::c_, pftools::Calibratable::cluster_energyEcal_, pftools::Calibratable::cluster_energyHcal_, pftools::Calibratable::cluster_meanEcal_, pftools::CalibrationResultWrapper::ecalEnergy_, pftools::CalibratableElement::eta_, getCalibratedEcalEnergy(), getCalibratedEnergy(), getCalibratedHcalEnergy(), pftools::CalibrationResultWrapper::hcalEnergy_, pftools::LINEARCORR, pftools::CalibrationResultWrapper::particleEnergy_, pftools::CalibratableElement::phi_, pftools::CalibrationResultWrapper::provenance_, pftools::Calibratable::sim_energyEvent_, and pftools::CalibrationResultWrapper::truthEnergy_.

Referenced by calibrate().

271  {
272 
275  fabs(c.cluster_meanEcal_.phi_));
276 
279  fabs(c.cluster_meanEcal_.phi_));
280 
283  fabs(c.cluster_meanEcal_.phi_));
284 
285  crw.provenance_ = LINEARCORR;
286  crw.b_ = crw.ecalEnergy_ / c.cluster_energyEcal_;
287  crw.c_ = crw.hcalEnergy_ / c.cluster_energyHcal_;
289 
290 }
CalibratableElement cluster_meanEcal_
Definition: Calibratable.h:186
double getCalibratedEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double getCalibratedHcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double getCalibratedEcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
std::vector<std::string>* pftools::PFClusterCalibration::getKnownSectorNames ( )
inline

Definition at line 127 of file PFClusterCalibration.h.

References names_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

127  {
128  return &names_;
129  }
std::vector< std::string > names_
void PFClusterCalibration::init ( void  )
private

Definition at line 13 of file PFClusterCalibration.cc.

References correction_, correctionLowLimit_, etaCorrection_, globalP0_, globalP1_, lowEP0_, lowEP1_, mergeVDriftHistosByStation::name, names_, namesAndFunctions_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by PFClusterCalibration().

13  {
14 
15  //std::cout << __PRETTY_FUNCTION__ << std::endl;
16  correction_ = new TF1("correction",
17  "((x-[0])/[1])*(x>[4])+((x-[2])/[3])*(x<[4])");
19  = new TF1( "etaCorrection",
20  "(1-[0]*x-[1]*x*x)*(x<[2])+([3]+[4]*x)*(x>[2]&&x<[5])+(1-[6]*x-[7]*x*x)*(x>[5])");
21 
22  correction_->FixParameter(0, globalP0_);
23  correction_->FixParameter(1, globalP1_);
24  correction_->FixParameter(2, lowEP0_);
25  correction_->FixParameter(3, lowEP1_);
26  correction_->FixParameter(4, correctionLowLimit_);
27 
28  /* These are the types of calibration I know about:
29  * ecalOnly_elementName
30  * etc. Sorry, it's not very nice, but well, neither is ROOT... */
31 
32  std::string eheb("ecalHcalEcalBarrel");
33  names_.push_back(eheb);
34  std::string ehee("ecalHcalEcalEndcap");
35  names_.push_back(ehee);
36  std::string ehhb("ecalHcalHcalBarrel");
37  names_.push_back(ehhb);
38  std::string ehhe("ecalHcalHcalEndcap");
39  names_.push_back(ehhe);
40 
41  /* char
42  * funcString("([0]*[5]*x*([1]-[5]*x)/pow(([2]+[5]*x),3)+[3]*pow([5]*x, 0.1))*([5]*x<[8] && [5]*x>[7])+[4]*([5]*x>[8])+([6]*[5]*x)*([5]*x<[7])");
43  */
44 
45  const char*
46  funcString("([0]*[5]*x)*([5]*x<=[1])+([2]+[3]*exp([4]*[5]*x))*([5]*x>[1])");
47 
48  //Create functions for each sector
49  for (std::vector<std::string>::const_iterator cit = names_.begin(); cit
50  != names_.end(); ++cit) {
51  std::string name = *cit;
52  TF1 func(name.c_str(), funcString);
53  //some sensible defaults
54  func.FixParameter(0, 1);
55  func.FixParameter(1, 0);
56  func.FixParameter(2, 1);
57  func.FixParameter(3, 0);
58  func.FixParameter(4, 0);
59  func.FixParameter(5, 1);
60 
61  func.SetMinimum(0);
62  //Store in map
63  namesAndFunctions_[name] = func;
64 
65  }
66 }
std::vector< std::string > names_
std::map< std::string, TF1 > namesAndFunctions_
void pftools::PFClusterCalibration::setAllowNegativeEnergy ( const bool &  allowIt)
inline
void pftools::PFClusterCalibration::setBarrelBoundary ( const double &  eta)
inline
void PFClusterCalibration::setCorrections ( const double &  lowEP0,
const double &  lowEP1,
const double &  globalP0,
const double &  globalP1 
)

Definition at line 157 of file PFClusterCalibration.cc.

References correction_, correctionLowLimit_, globalP0_, globalP1_, lowEP0_, and lowEP1_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

158  {
159  //'a' term is -globalP0/globalP1
160  globalP0_ = globalP0;
161  globalP1_ = globalP1;
162  //Specifically for low energies...
163  lowEP0_ = lowEP0;
164  lowEP1_ = lowEP1;
165  //Intersection of two straight lines => matching at...
167 
168  correction_->FixParameter(0, globalP0_);
169  correction_->FixParameter(1, globalP1_);
170  correction_->FixParameter(2, lowEP0_);
171  correction_->FixParameter(3, lowEP1_);
172  correction_->FixParameter(4, correctionLowLimit_);
173 
174  // std::cout << __PRETTY_FUNCTION__ << ": setting correctionLowLimit_ = "
175  // << correctionLowLimit_ << "\n";
176 }
void pftools::PFClusterCalibration::setDoCorrection ( const int &  doCorrection)
inline

Definition at line 93 of file PFClusterCalibration.h.

References doCorrection_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

93  {
94  doCorrection_ = doCorrection;
95  }
void pftools::PFClusterCalibration::setDoEtaCorrection ( const int  doEtaCorrection)
inline

Definition at line 97 of file PFClusterCalibration.h.

References doEtaCorrection_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

97  {
98  doEtaCorrection_ = doEtaCorrection;
99  }
void pftools::PFClusterCalibration::setEcalHcalEnergyCuts ( const double &  ecalCut,
const double &  hcalCut 
)
inline

Definition at line 102 of file PFClusterCalibration.h.

References ecalOnlyDiv_, and hcalOnlyDiv_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

102  {
103  //std::cout << __PRETTY_FUNCTION__ << "WARNING! These will be ignored.\n";
104  ecalOnlyDiv_ = ecalCut;
105  hcalOnlyDiv_ = hcalCut;
106  }
void PFClusterCalibration::setEtaCorrectionParameters ( const std::vector< double > &  params)

Definition at line 122 of file PFClusterCalibration.cc.

References KineDebug3::count(), gather_cfg::cout, and etaCorrection_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

122  {
123  if (params.size() != 6) {
124  std::cout << __PRETTY_FUNCTION__ << ": params is of the wrong length."
125  << std::endl;
126  return;
127  }
128  // std::cout << "Fixing eta correction:\n\t";
129  unsigned count(0);
130  for (std::vector<double>::const_iterator dit = params.begin(); dit
131  != params.end(); ++dit) {
132  //std::cout << *dit << "\t";
133  etaCorrection_->FixParameter(count, *dit);
134  ++count;
135  }
136  // std::cout << std::endl;
137  /*for(double eta(0); eta < 2.5; eta += 0.05) {
138  std::cout << "Eta = " << eta << ",\tcorr = " << etaCorrection_->Eval(eta) << "\n";
139  }*/
140 }
tuple cout
Definition: gather_cfg.py:145
void PFClusterCalibration::setEvolutionParameters ( const std::string &  sector,
const std::vector< double > &  params 
)

Definition at line 142 of file PFClusterCalibration.cc.

References KineDebug3::count(), and namesAndFunctions_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

143  {
144  TF1* func = &(namesAndFunctions_.find(sector)->second);
145  unsigned count(0);
146  //std::cout << "Fixing for "<< sector << "\n";
147  for (std::vector<double>::const_iterator dit = params.begin(); dit
148  != params.end(); ++dit) {
149  func->FixParameter(count, *dit);
150  //std::cout << "\t"<< count << ": "<< *dit;
151  ++count;
152  }
153  // std::cout << std::endl;
154  func->SetMinimum(0);
155 }
std::map< std::string, TF1 > namesAndFunctions_
void pftools::PFClusterCalibration::setMaxEToCorrect ( double  maxE)
inline

Definition at line 113 of file PFClusterCalibration.h.

References maxEToCorrect_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

113  {
114  maxEToCorrect_ = maxE;
115  }

Friends And Related Function Documentation

std::ostream& pftools::operator<< ( std::ostream &  s,
const PFClusterCalibration cc 
)
friend

Member Data Documentation

int pftools::PFClusterCalibration::allowNegativeEnergy_
private
double pftools::PFClusterCalibration::barrelEndcapEtaDiv_
private
TF1* pftools::PFClusterCalibration::correction_
private
double pftools::PFClusterCalibration::correctionLowLimit_
private

Definition at line 151 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

int pftools::PFClusterCalibration::doCorrection_
private
int pftools::PFClusterCalibration::doEtaCorrection_
private
double pftools::PFClusterCalibration::ecalOnlyDiv_
private

Definition at line 143 of file PFClusterCalibration.h.

Referenced by pftools::operator<<(), and setEcalHcalEnergyCuts().

TF1* pftools::PFClusterCalibration::etaCorrection_
private
double pftools::PFClusterCalibration::globalP0_
private

Definition at line 152 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

double pftools::PFClusterCalibration::globalP1_
private

Definition at line 153 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

double pftools::PFClusterCalibration::hcalOnlyDiv_
private

Definition at line 144 of file PFClusterCalibration.h.

Referenced by pftools::operator<<(), and setEcalHcalEnergyCuts().

double pftools::PFClusterCalibration::lowEP0_
private

Definition at line 154 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

double pftools::PFClusterCalibration::lowEP1_
private

Definition at line 155 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

double pftools::PFClusterCalibration::maxEToCorrect_
private

Definition at line 149 of file PFClusterCalibration.h.

Referenced by getCalibratedEnergy(), and setMaxEToCorrect().

std::vector<std::string> pftools::PFClusterCalibration::names_
private

Definition at line 163 of file PFClusterCalibration.h.

Referenced by getKnownSectorNames(), and init().

std::map<std::string, TF1> pftools::PFClusterCalibration::namesAndFunctions_
private