test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CalibCompare.cc
Go to the documentation of this file.
12 
13 #include <TFile.h>
14 #include <TTree.h>
15 #include <TH3F.h>
16 #include <TF2.h>
17 #include <TH1F.h>
18 #include <TGraph.h>
19 #include <TF1.h>
20 #include <vector>
21 #include <TROOT.h>
22 
23 using namespace pftools;
24 
26 }
27 
29  withOffset_(false), target_(CLUSTER), options_(options), debug_(0),
30  mlpOffset_(0.0), mlpSlope_(1.0) {
31 
32  options_->GetOpt("exercises", "withOffset", withOffset_);
33  options_->GetOpt("exercises", "debug", debug_);
34 
35  /* Initialise PFClusterCalibration appropriately. */
36  double g0, g1, e0, e1;
37  options_->GetOpt("correction", "globalP0", g0);
38  options_->GetOpt("correction", "globalP1", g1);
39  options_->GetOpt("correction", "lowEP0", e0);
40  options_->GetOpt("correction", "lowEP1", e1);
41  clusterCalibration_.setCorrections(e0, e1, g0, g1);
42 
43  double ecalECut, hcalECut;
44  options_->GetOpt("evolution", "ecalECut", ecalECut);
45  options_->GetOpt("evolution", "hcalECut", hcalECut);
46  clusterCalibration_.setEcalHcalEnergyCuts(ecalECut, hcalECut);
47 
48  int allowNegative(0);
49  options_->GetOpt("correction", "allowNegativeEnergy", allowNegative);
51 
52  int doCorrection(1);
53  options_->GetOpt("correction", "doCorrection", doCorrection);
55 
56  int doEtaCorrection(0);
57  options_->GetOpt("correction", "doEtaCorrection", doEtaCorrection);
58  clusterCalibration_.setDoEtaCorrection(doEtaCorrection);
59 
60  double barrelEta;
61  options_->GetOpt("evolution", "barrelEndcapEtaDiv", barrelEta);
63 
64  double maxEToCorrect(100.0);
65  options_->GetOpt("correction", "maxEToCorrect", maxEToCorrect);
67 
68  std::vector<std::string>* names = clusterCalibration_.getKnownSectorNames();
69  for (std::vector<std::string>::iterator i = names->begin(); i
70  != names->end(); ++i) {
71  std::string sector = *i;
72  std::vector<double> params;
73  options_->GetOpt("evolution", sector.c_str(), params);
75  }
76 
77  std::vector<double> etaParams;
78  options_->GetOpt("evolution", "etaCorrection", etaParams);
80 
81  std::cout << clusterCalibration_ << "\n";
82 
83  options_->GetOpt("correction", "mlpOffset", mlpOffset_);
84  options_->GetOpt("correction", "mlpSlope", mlpSlope_);
85 
87 
88  if (debug_ > 0)
89  std::cout << __PRETTY_FUNCTION__ << ": finished.\n";
90 
91 }
92 
93 void CalibCompare::calibrateCalibratables(TChain& sourceTree,
94  const std::string& exercisefile) {
95 
96  if (debug_ > 0) {
97  std::cout << "Welcome to " << __PRETTY_FUNCTION__ << "\n";
98  std::cout << "Opening TTree...\n";
99  }
100 
101  TreeUtility tu;
102  std::vector<Calibratable> calibVec;
103 
104  tu.getCalibratablesFromRootFile(sourceTree, calibVec);
105 
106  std::cout << "Moving on... " << std::endl;
107  TFile* exercises = new TFile(exercisefile.c_str(), "recreate");
108  TTree tree("CalibratedParticles", "");
109  Calibratable* calibrated = new Calibratable();
110  tree.Branch("Calibratable", "pftools::Calibratable", &calibrated, 32000, 2);
111 
112  evaluateCalibrations(tree, calibrated, calibVec);
113 
114  //save results
115  std::cout << "Writing output tree...\n";
116  tree.Write();
117  //gaussianFits(*exercises, calibVec);
118  exercises->Write();
119  exercises->Close();
120  std::cout << "Done." << std::endl;
121  delete calibrated;
122 
123 }
124 
126  const std::vector<Calibratable>& calibVec) {
127 
128  unsigned count(0);
129  for (std::vector<Calibratable>::const_iterator zit = calibVec.begin(); zit
130  != calibVec.end(); ++zit) {
131 
132  const Calibratable& calib = *zit;
133 
134  calibrated->reset();
135 
137  crwPre.ecalEnergy_ = calib.cluster_energyEcal_;
138  crwPre.hcalEnergy_ = calib.cluster_energyHcal_;
139  crwPre.particleEnergy_ = calib.cluster_energyEcal_
140  + calib.cluster_energyHcal_;
141  crwPre.truthEnergy_ = calib.sim_energyEvent_;
142  crwPre.provenance_ = UNCALIBRATED;
143  crwPre.targetFuncContrib_ = 0;
144  crwPre.target_ = target_;
145  crwPre.compute();
146  calibrated->calibrations_.push_back(crwPre);
147 
149 
151  crwPre.hcalEnergy_, calib.cluster_numEcal_,
152  calib.cluster_numHcal_, fabs(calib.cluster_meanEcal_.eta_)
153  / 2.0, crwPre.ecalEnergy_ / (crwPre.particleEnergy_),
154  (calib.cluster_meanEcal_.phi_ + 3.14) / 6.3);
155  crwErl.ecalEnergy_ = crwErl.particleEnergy_
157  crwPre.hcalEnergy_, calib.cluster_numEcal_,
158  calib.cluster_numHcal_, fabs(
159  calib.cluster_meanEcal_.eta_) / 2.0,
160  crwPre.ecalEnergy_ / (crwPre.particleEnergy_),
161  (calib.cluster_meanEcal_.phi_ + 3.14) / 6.3);
162 
163  crwErl.hcalEnergy_ = crwErl.particleEnergy_ - crwErl.ecalEnergy_;
164  crwErl.b_ = crwErl.ecalEnergy_ / crwPre.ecalEnergy_;
165  crwErl.c_ = crwErl.hcalEnergy_ / crwPre.hcalEnergy_;
166 
167  crwErl.truthEnergy_ = calib.sim_energyEvent_;
168  crwErl.provenance_ = BAYESIAN;
169  crwErl.target_ = target_;
170  crwErl.compute();
171  calibrated->calibrations_.push_back(crwErl);
172 
173  CalibrationResultWrapper crwCorr;
174 
176  crwPre.ecalEnergy_, crwPre.hcalEnergy_,
179  crwPre.ecalEnergy_, crwPre.hcalEnergy_,
182  crwPre.ecalEnergy_, crwPre.hcalEnergy_, calib.sim_etaEcal_,
183  calib.sim_phiEcal_);
184 
185  crwCorr.truthEnergy_ = calib.sim_energyEvent_;
186  crwCorr.provenance_ = LINEAR;
187  crwCorr.targetFuncContrib_ = 0;;
188  crwCorr.target_ = target_;
189  crwCorr.compute();
190  calibrated->calibrations_.push_back(crwCorr);
191 
192  calibrated->recompute();
193 
194  tree.Fill();
195 
196  ++count;
197  }
198 
199 }
200 
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > * getKnownSectorNames()
Wraps essential single particle calibration data ready for export to a Root file. ...
Definition: Calibratable.h:122
static const HistoName names[]
CalibratableElement cluster_meanEcal_
Definition: Calibratable.h:186
void calibrateCalibratables(TChain &sourceTree, const std::string &exercisefile)
Definition: CalibCompare.cc:93
void setBarrelBoundary(const double &eta)
void setOffsetAndSlope(const double offset, const double slope)
Definition: Erl_mlp.h:15
std::vector< CalibrationResultWrapper > calibrations_
Definition: Calibratable.h:206
double ecalFraction(const double t1=0.0, const double t2=0.0, const double t3=0.0, const double t4=0.0, const double t5=0.0, const double t6=0.0, const double t7=0.0)
Definition: Erl_mlp.h:34
bool GetOpt(const char *tag, const char *key, std::vector< T > &values) const
reads a vector of T
Definition: IO.h:108
double getCalibratedEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
CalibCompare(IO *options)
Definition: CalibCompare.cc:28
void evaluateCalibrations(TTree &tree, pftools::Calibratable *calibrated, const std::vector< pftools::Calibratable > &calibVec)
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
void setEcalHcalEnergyCuts(const double &ecalCut, const double &hcalCut)
double getCalibratedHcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double evaluate(const double t1=0.0, const double t2=0.0, const double t3=0.0, const double t4=0.0, const double t5=0.0, const double t6=0.0, const double t7=0.0)
Definition: Erl_mlp.h:20
unsigned getCalibratablesFromRootFile(TChain &tree, std::vector< Calibratable > &toBeFilled)
Definition: TreeUtility.cc:21
void setEvolutionParameters(const std::string &sector, const std::vector< double > &params)
double getCalibratedEcalEnergy(const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
virtual void reset()
CalibrationTarget target_
Definition: CalibCompare.h:48
Float e1
Definition: deltaR.h:20
A small class designed to hold the result of a calibration of a SingleParticleWrapper.
virtual void recompute()
Definition: Calibratable.cc:45
Definition: IO.h:29
CalibratableElement cluster_meanHcal_
Definition: Calibratable.h:186
void setDoCorrection(const int &doCorrection)
void setCorrections(const double &lowEP0, const double &lowEP1, const double &globalP0, const double &globalP1)
void setAllowNegativeEnergy(const bool &allowIt)
Utility class to create particles and detector elements from a Root file.
Definition: TreeUtility.h:27
tuple cout
Definition: gather_cfg.py:145
volatile std::atomic< bool > shutdown_flag false
void setEtaCorrectionParameters(const std::vector< double > &params)
PFClusterCalibration clusterCalibration_
Definition: CalibCompare.h:54
void setDoEtaCorrection(const int doEtaCorrection)
tuple g0
Definition: corrVsCorr.py:108