CMS 3D CMS Logo

Calibratable.cc

Go to the documentation of this file.
00001 #include "RecoParticleFlow/PFClusterTools/interface/Calibratable.h"
00002 
00003 using namespace pftools;
00004 
00005 std::ostream& pftools::operator<<(std::ostream& s, const Calibratable& calib_) {
00006         s << "Calibratable summary:\n\tsim:\t\t("
00007         << calib_.sim_energyEvent_<< "),\t["<< calib_.sim_etaEcal_
00008         << ", "<< calib_.sim_phiEcal_<< "]\n";
00009         s << "\trechits:\t("<< calib_.rechits_energyEvent_<< ", "
00010         << calib_.rechits_energyEcal_<< ", "
00011         << calib_.rechits_energyHcal_<< ")\n";
00012         s << "\tcluster:\t("<< calib_.cluster_energyEvent_<< ", "
00013         << calib_.cluster_energyEcal_<< ", "
00014         << calib_.cluster_energyHcal_<< ")\n";
00015         s << "\tcands:\t\t("<< calib_.cand_energyEvent_<< ", "
00016         << calib_.cand_energyEcal_<< ", "
00017         << calib_.cand_energyHcal_<< "), ";
00018         s << "\t["<< calib_.cand_eta_<< ", "
00019         << calib_.cand_phi_<< "]\n";
00020         
00021         return s;
00022 }
00023 
00024 void Calibratable::recompute() {
00025 
00026         cluster_meanEcal_ = computeMean(cluster_ecal_);
00027         cluster_meanHcal_ = computeMean(cluster_hcal_);
00028         rechits_meanEcal_ = computeMean(rechits_ecal_);
00029         rechits_meanHcal_ = computeMean(rechits_hcal_);
00030 
00031         cluster_numEcal_ = cluster_ecal_.size();
00032         cluster_numHcal_ = cluster_hcal_.size();
00033         rechits_numEcal_ = rechits_ecal_.size();
00034         rechits_numHcal_ = rechits_hcal_.size();
00035 
00036         cluster_energyEvent_ = cluster_meanEcal_.energy_* cluster_ecal_.size()
00037                         + cluster_meanHcal_.energy_* cluster_hcal_.size();
00038         cluster_energyEcal_ = cluster_meanEcal_.energy_* cluster_ecal_.size();
00039         cluster_energyHcal_ = cluster_meanHcal_.energy_* cluster_hcal_.size();
00040 
00041         rechits_energyEvent_ = rechits_meanEcal_.energy_* rechits_ecal_.size()
00042                         + rechits_meanHcal_.energy_* rechits_hcal_.size();
00043         rechits_energyEcal_ = rechits_meanEcal_.energy_* rechits_ecal_.size();
00044         rechits_energyHcal_ = rechits_meanHcal_.energy_* rechits_hcal_.size();
00045 
00046         cands_num_ = cands_.size();
00047         cands_mean_ = computeMean(cands_);
00048 
00049         cand_energyEvent_ = cands_mean_.energy_ * cands_num_;
00050         cand_energyEcal_ = cands_mean_.energyEcal_ * cands_num_;
00051         cand_energyHcal_ = cands_mean_.energyHcal_ * cands_num_;
00052         cand_eta_ = cands_mean_.eta_;
00053         cand_phi_ = cands_mean_.phi_;
00054         cand_type_ = cands_mean_.type_ * cands_num_;
00055 
00056 }
00057 
00058 CandidateWrapper Calibratable::computeMean(
00059                 const std::vector<CandidateWrapper>& wrappers) {
00060         CandidateWrapper cw;
00061 
00062         if (wrappers.size() == 0)
00063                 return cw;
00064         for (std::vector<CandidateWrapper>::const_iterator it = wrappers.begin(); it
00065                         != cands_.end(); ++it) {
00066                 const CandidateWrapper& c = *it;
00067                 cw.energy_ += c.energy_;
00068                 cw.phi_ += c.phi_;
00069                 cw.eta_ += c.eta_;
00070                 cw.energyEcal_ += c.energyEcal_;
00071                 cw.energyHcal_ += c.energyHcal_;
00072                 cw.type_ += c.type_;
00073         }
00074 
00075         cw.energy_ /= wrappers.size();
00076         cw.phi_ /= wrappers.size();
00077         cw.eta_ /= wrappers.size();
00078         cw.energyEcal_ /= wrappers.size();
00079         cw.energyHcal_ /= wrappers.size();
00080         cw.type_ /= wrappers.size();
00081 
00082         return cw;
00083 }
00084 
00085 CalibratableElement Calibratable::computeMean(
00086                 const std::vector<CalibratableElement>& diets) {
00087         CalibratableElement dmean;
00088         if (diets.size() == 0)
00089                 return dmean;
00090         for (std::vector<CalibratableElement>::const_iterator cit = diets.begin(); cit
00091                         != diets.end(); ++cit) {
00092                 CalibratableElement d = *cit;
00093                 dmean.energy_ += d.energy_;
00094                 dmean.eta_ += d.eta_;
00095                 dmean.phi_ += d.phi_;
00096         }
00097         dmean.energy_ /= diets.size();
00098         dmean.eta_ /= diets.size();
00099         dmean.phi_ /= diets.size();
00100         return dmean;
00101 }
00102 
00103 void Calibratable::reset() {
00104 
00105         calibrations_.clear();
00106 
00107         sim_energyEvent_ = 0;
00108         sim_eta_ = 0;
00109         sim_phi_ = 0;
00110         sim_numEvent_ = 0;
00111         sim_isMC_ = false;
00112 
00113         tb_isTB_ = false;
00114 
00115         sim_etaEcal_ = 0;
00116         sim_etaHcal_ = 0;
00117         sim_phiEcal_ = 0;
00118         sim_phiHcal_ = 0;
00119 
00120         recotrk_numHits_ = 0;
00121         recotrk_quality_ = 0;
00122         recotrk_charge_ = 0;
00123         recotrk_etaEcal_ = 0;
00124         recotrk_phiEcal_ = 0;
00125         //TODO:: check this is sufficient
00126         recotrk_momentum_.SetPxPyPzE(0, 0, 0, 0);
00127         recotrk_deltaRWithSim_ = 0.0;
00128 
00129         cluster_energyEvent_ = 0;
00130         cluster_energyEcal_ = 0;
00131         cluster_energyHcal_ = 0;
00132         cluster_numEcal_ = 0;
00133         cluster_numHcal_ = 0;
00134         cluster_ecal_.clear();
00135         cluster_hcal_.clear();
00136         cluster_meanEcal_.reset();
00137         cluster_meanHcal_.reset();
00138 
00139         rechits_energyEvent_ = 0;
00140         rechits_ecal_.clear();
00141         rechits_hcal_.clear();
00142         rechits_energyEcal_ = 0;
00143         rechits_energyHcal_ = 0;
00144         rechits_meanEcal_.reset();
00145         rechits_meanHcal_.reset();
00146 
00147         cands_.clear();
00148         cands_num_ = 0;
00149         cands_mean_.reset();
00150         cand_energyEvent_ = 0;
00151         cand_energyEcal_ = 0;
00152         cand_energyHcal_ = 0;
00153         cand_eta_ = 0;
00154         cand_phi_ = 0;
00155         cand_type_ = -1;
00156 
00157         pfele_energyEvent_ = 0;
00158         pfele_energyEcal_ = 0;
00159         pfele_energyHcal_ = 0;
00160         pfele_numEcal_ = 0;
00161         pfele_numHcal_ = 0;
00162 
00163 }

Generated on Tue Jun 9 17:44:41 2009 for CMSSW by  doxygen 1.5.4