CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/ParticleFlowReco/src/Calibratable.cc

Go to the documentation of this file.
00001 #include "DataFormats/ParticleFlowReco/interface/Calibratable.h"
00002 #include <algorithm>
00003 
00004 using namespace pftools;
00005 
00006 std::ostream& pftools::operator<<(std::ostream& s, const Calibratable& calib_) {
00007         s << "Calibratable summary:\n\tsim:\t\t(" << calib_.sim_energyEvent_
00008                         << "),\t[" << calib_.sim_etaEcal_ << ", " << calib_.sim_phiEcal_
00009                         << "]\n";
00010         s << "\ttestbeam:\t(" << calib_.tb_energyEvent_ << ", "
00011                         << calib_.tb_energyEcal_ << ", " << calib_.tb_energyHcal_ << "), ["
00012                         << calib_.tb_eta_ << ", " << calib_.tb_phi_ << "]\n";
00013         s << "\trechits:\t(" << calib_.rechits_energyEvent_ << ", "
00014                         << calib_.rechits_energyEcal_ << ", " << calib_.rechits_energyHcal_
00015                         << ")\n";
00016         s << "\tcluster:\t(" << calib_.cluster_energyEvent_ << ", "
00017                         << calib_.cluster_energyEcal_ << ", " << calib_.cluster_energyHcal_
00018                         << ")\n";
00019         s << "\tcands:\t\t(" << calib_.cand_energyEvent_ << ", "
00020                         << calib_.cand_energyEcal_ << ", " << calib_.cand_energyHcal_
00021                         << "), ";
00022         s << "\t[" << calib_.cand_eta_ << ", " << calib_.cand_phi_ << "], "
00023                         << calib_.cands_num_ << " of them\n";
00024         for (std::vector<CandidateWrapper>::const_iterator c =
00025                         calib_.cands_.begin(); c != calib_.cands_.end(); ++c) {
00026                 const CandidateWrapper& cw = *c;
00027                 s << "\t\t\t\tType: " << cw.type_ << ", (" << cw.energy_ << ", "
00028                                 << cw.energyEcal_ << ", " << cw.energyHcal_ << ") at [ "
00029                                 << cw.eta_ << ", " << cw.phi_ << "]\n";
00030         }
00031         s << "\t\tNeutral EM energy: " << calib_.cand_energyNeutralEM_ << "\n";
00032         s << "\t\tNeutral Had energy: " << calib_.cand_energyNeutralHad_ << "\n";
00033 
00034         return s;
00035 }
00036 
00037 std::ostream& pftools::operator<<(std::ostream& s,
00038                 const CalibratableElement& ce) {
00039         s << "CalibratableElement: (energy, eta, phi) = (" << ce.energy_ << ", "
00040                         << ce.eta_ << ", " << ce.phi_ << ")";
00041 
00042         return s;
00043 }
00044 
00045 void Calibratable::recompute() {
00046 
00047         cluster_meanEcal_ = computeMean(cluster_ecal_);
00048         cluster_meanHcal_ = computeMean(cluster_hcal_);
00049         rechits_meanEcal_ = computeMean(rechits_ecal_);
00050         rechits_meanHcal_ = computeMean(rechits_hcal_);
00051         tb_meanEcal_ = computeMean(tb_ecal_);
00052         tb_meanHcal_ = computeMean(tb_hcal_);
00053 
00054         cluster_numEcal_ = cluster_ecal_.size();
00055         cluster_numHcal_ = cluster_hcal_.size();
00056         rechits_numEcal_ = rechits_ecal_.size();
00057         rechits_numHcal_ = rechits_hcal_.size();
00058         tb_numEcal_ = tb_ecal_.size();
00059         tb_numHcal_ = tb_hcal_.size();
00060 
00061         cluster_energyEvent_ = cluster_meanEcal_.energy_ * cluster_ecal_.size()
00062                         + cluster_meanHcal_.energy_ * cluster_hcal_.size();
00063         cluster_energyEcal_ = cluster_meanEcal_.energy_ * cluster_ecal_.size();
00064         cluster_energyHcal_ = cluster_meanHcal_.energy_ * cluster_hcal_.size();
00065 
00066         rechits_energyEvent_ = rechits_meanEcal_.energy_ * rechits_ecal_.size()
00067                         + rechits_meanHcal_.energy_ * rechits_hcal_.size();
00068         rechits_energyEcal_ = rechits_meanEcal_.energy_ * rechits_ecal_.size();
00069         rechits_energyHcal_ = rechits_meanHcal_.energy_ * rechits_hcal_.size();
00070 
00071         tb_energyEvent_ = tb_meanEcal_.energy_ * tb_ecal_.size()
00072                         + tb_meanHcal_.energy_ * tb_hcal_.size();
00073         tb_energyEcal_ = tb_meanEcal_.energy_ * tb_ecal_.size();
00074         tb_energyHcal_ = tb_meanHcal_.energy_ * tb_hcal_.size();
00075 
00076         cands_num_ = cands_.size();
00077         cands_mean_ = computeMean(cands_);
00078 
00079         cand_energyEvent_ = 0;
00080         cand_energyEcal_ = 0;
00081         cand_energyHcal_ = 0;
00082         cand_energyNeutralEM_ = 0;
00083         cand_energyNeutralHad_ = 0;
00084         cand_type_ = 0;
00085         cand_eta_ = cands_mean_.eta_;
00086         cand_phi_ = cands_mean_.phi_;
00087 
00088         for (std::vector<CandidateWrapper>::iterator it = cands_.begin(); it
00089                         != cands_.end(); ++it) {
00090                 CandidateWrapper& c = *it;
00091                 if (c.type_ == 4)
00092                         cand_energyNeutralEM_ += c.energy_;
00093                 if (c.type_ == 5)
00094                         cand_energyNeutralHad_ += c.energy_;
00095                 cand_energyEvent_ += c.energy_;
00096                 cand_energyEcal_ += c.energyEcal_;
00097                 cand_energyHcal_ += c.energyHcal_;
00098                 cand_type_ += c.type_;
00099                 c.recompute();
00100         }
00101 
00102         std::sort(tb_ecal_.begin(), tb_ecal_.end());
00103         std::sort(tb_hcal_.begin(), tb_hcal_.end());
00104         std::sort(rechits_ecal_.begin(), rechits_ecal_.end());
00105         std::sort(rechits_hcal_.begin(), rechits_hcal_.end());
00106         std::sort(cluster_ecal_.begin(), cluster_ecal_.end());
00107         std::sort(cluster_hcal_.begin(), cluster_hcal_.end());
00108 
00109 }
00110 
00111 CandidateWrapper Calibratable::computeMean(
00112                 const std::vector<CandidateWrapper>& wrappers) {
00113         CandidateWrapper cw;
00114 
00115         if (wrappers.size() == 0)
00116                 return cw;
00117         for (std::vector<CandidateWrapper>::const_iterator it = wrappers.begin(); it
00118                         != wrappers.end(); ++it) {
00119                 const CandidateWrapper& c = *it;
00120                 cw.energy_ += c.energy_;
00121                 cw.phi_ += c.phi_;
00122                 cw.eta_ += c.eta_;
00123                 cw.energyEcal_ += c.energyEcal_;
00124                 cw.energyHcal_ += c.energyHcal_;
00125                 cw.type_ += c.type_;
00126         }
00127 
00128         cw.energy_ /= wrappers.size();
00129         cw.phi_ /= wrappers.size();
00130         cw.eta_ /= wrappers.size();
00131         cw.energyEcal_ /= wrappers.size();
00132         cw.energyHcal_ /= wrappers.size();
00133         cw.type_ /= wrappers.size();
00134 
00135         return cw;
00136 }
00137 
00138 CalibratableElement Calibratable::computeMean(const std::vector<
00139                 CalibratableElement>& diets) {
00140         CalibratableElement dmean;
00141         if (diets.size() == 0)
00142                 return dmean;
00143         for (std::vector<CalibratableElement>::const_iterator cit = diets.begin(); cit
00144                         != diets.end(); ++cit) {
00145                 CalibratableElement d = *cit;
00146                 dmean.energy_ += d.energy_;
00147                 dmean.eta_ += d.eta_;
00148                 dmean.phi_ += d.phi_;
00149                 dmean.extent_ += d.extent_;
00150                 dmean.time_ += d.time_;
00151         }
00152         dmean.energy_ /= diets.size();
00153         dmean.eta_ /= diets.size();
00154         dmean.phi_ /= diets.size();
00155         dmean.extent_ /= diets.size();
00156         dmean.time_ /= diets.size();
00157         return dmean;
00158 }
00159 
00160 void Calibratable::fillCaloWindow(
00161                 const std::vector<CalibratableElement>& source, CaloWindow& destination) const {
00162         std::vector<CalibratableElement>::const_iterator cit = source.begin();
00163         for (; cit != source.end(); ++cit) {
00164                 const CalibratableElement& ce = *cit;
00165                 bool ok = destination.addHit(ce.eta_, ce.phi_, ce.energy_);
00166                 if (!ok)
00167                         std::cout << __PRETTY_FUNCTION__
00168                                         << ": couldn't fill CaloWindow with " << ce << "\n";
00169         }
00170 }
00171 
00172 void Calibratable::reset() {
00173 
00174         calibrations_.clear();
00175 
00176         sim_energyEvent_ = 0;
00177         sim_energyEcal_ = 0;
00178         sim_energyHcal_ = 0;
00179         sim_eta_ = 0;
00180         sim_phi_ = 0;
00181         sim_numEvent_ = 0;
00182         sim_isMC_ = false;
00183 
00184         tb_isTB_ = false;
00185         tb_eta_ = 0.0;
00186         tb_phi_ = 0.0;
00187         tb_run_ = 0;
00188         tb_pdg_ = 0;
00189         tb_tof_ = 0;
00190         tb_ck3_ = 0;
00191         tb_ck2_ = 0;
00192         tb_vetosPassed_ = 0;
00193         tb_energyEvent_ = 0;
00194         tb_energyEcal_ = 0;
00195         tb_energyHcal_ = 0;
00196         tb_ecal_.clear();
00197         tb_hcal_.clear();
00198         tb_numEcal_ = 0;
00199         tb_numHcal_ = 0;
00200         tb_meanEcal_.reset();
00201         tb_meanHcal_.reset();
00202 
00203         sim_etaEcal_ = 0;
00204         sim_etaHcal_ = 0;
00205         sim_phiEcal_ = 0;
00206         sim_phiHcal_ = 0;
00207 
00208         recotrk_numHits_ = 0;
00209         recotrk_quality_ = 0;
00210         recotrk_charge_ = 0;
00211         recotrk_etaEcal_ = 0;
00212         recotrk_phiEcal_ = 0;
00213         //TODO:: check this is sufficient
00214         recotrk_momentum_.SetPxPyPzE(0, 0, 0, 0);
00215         recotrk_deltaRWithSim_ = 0.0;
00216 
00217         cluster_energyEvent_ = 0;
00218         cluster_energyEcal_ = 0;
00219         cluster_energyHcal_ = 0;
00220         cluster_numEcal_ = 0;
00221         cluster_numHcal_ = 0;
00222         cluster_ecal_.clear();
00223         cluster_hcal_.clear();
00224         cluster_meanEcal_.reset();
00225         cluster_meanHcal_.reset();
00226 
00227         rechits_energyEvent_ = 0;
00228         rechits_ecal_.clear();
00229         rechits_hcal_.clear();
00230         rechits_energyEcal_ = 0;
00231         rechits_energyHcal_ = 0;
00232         rechits_numEcal_ = 0;
00233         rechits_numHcal_ = 0;
00234         rechits_meanEcal_.reset();
00235         rechits_meanHcal_.reset();
00236 
00237         cands_.clear();
00238         cands_num_ = 0;
00239         cands_mean_.reset();
00240         cand_energyEvent_ = 0;
00241         cand_energyEcal_ = 0;
00242         cand_energyHcal_ = 0;
00243         cand_eta_ = 0;
00244         cand_phi_ = 0;
00245         cand_type_ = -1;
00246         cand_energyNeutralEM_ = 0;
00247         cand_energyNeutralHad_ = 0;
00248 
00249         calowindow_ecal_.reset();
00250         calowindow_hcal_.reset();
00251 
00252 }