CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoParticleFlow/PFClusterTools/src/ParticleDeposit.cc

Go to the documentation of this file.
00001 #include "RecoParticleFlow/PFClusterTools/interface/ParticleDeposit.h"
00002 #include <cassert>
00003 #include <iostream>
00004 #include <cmath>
00005 #include "RecoParticleFlow/PFClusterTools/interface/DetectorElementType.h"
00006 using namespace pftools;
00007 
00008 unsigned ParticleDeposit::count = 0;
00009 
00010 ParticleDeposit::ParticleDeposit(double truthEnergy, double eta, double phi) :
00011         myId(count), myTruthEnergy(truthEnergy), myEta(eta), myPhi(phi) {
00012         ++count;
00013 }
00014 
00015 ParticleDeposit::~ParticleDeposit() {
00016 }
00017 
00018 void ParticleDeposit::addRecDeposition(const Deposition& rec) {
00019         myRecDepositions.push_back(rec);
00020 }
00021 
00022 void ParticleDeposit::addTruthDeposition(const Deposition& truth) {
00023         myTruthDepositions.push_back(truth);
00024 }
00025 
00026 std::vector<Deposition> ParticleDeposit::getTruthDepositions() const {
00027         return myTruthDepositions;
00028 }
00029 
00030 const std::vector<Deposition>& ParticleDeposit::getRecDepositions() const {
00031         return myRecDepositions;
00032 }
00033 
00034 double ParticleDeposit::getRecEnergy(const DetectorElementPtr de) const {
00035         double energy(0);
00036         for (std::vector<Deposition>::const_iterator cit = myRecDepositions.begin(); cit
00037                         != myRecDepositions.end(); ++cit) {
00038                 Deposition d = *cit;
00039 
00040                 if (d.getDetectorElement()->getType() == de->getType()) {
00041                         energy += de->getCalib(d.getEta(), d.getPhi()) * d.getEnergy();
00042                 }
00043 
00044         }
00045         return energy;
00046 }
00047 
00048 void ParticleDeposit::setRecEnergy(const DetectorElementPtr de, double energy) {
00049         for (std::vector<Deposition>::const_iterator cit = myRecDepositions.begin(); cit
00050                         != myRecDepositions.end(); ++cit) {
00051                 Deposition d = *cit;
00052 
00053                 if (d.getDetectorElement()->getType() == de->getType()) {
00054                         d.setEnergy(energy);
00055                 }
00056 
00057         }
00058 }
00059 
00060 double ParticleDeposit::getTruthEnergy(const DetectorElementPtr de) const {
00061         double energy(0);
00062         for (std::vector<Deposition>::const_iterator
00063                         cit = myTruthDepositions.begin(); cit!= myTruthDepositions.end(); ++cit) {
00064                 Deposition d = *cit;
00065                 if (d.getDetectorElement() == de) {
00066                         energy += d.getEnergy();
00067                 }
00068         }
00069         assert(!(energy > 0));
00070         return energy;
00071 
00072 }
00073 
00074 double ParticleDeposit::getRecEnergy() const {
00075         double energy(0);
00076         for (std::vector<Deposition>::const_iterator cit = myRecDepositions.begin(); cit
00077                         != myRecDepositions.end(); ++cit) {
00078                 Deposition d = *cit;
00079 //              if (d.getDetectorElement()->getType() == OFFSET && d.getDetectorElement()->getCalib() == 1.0) {
00080 //                      //don't add a tiny amount!
00081 //              } else {
00082                         energy += d.getDetectorElement()->getCalib(d.getEta(), d.getPhi()) * d.getEnergy();
00083 //              }
00084         }
00085 
00086         //assert(!(energy < 0));
00087         return energy;
00088 
00089 }
00090 
00091 double ParticleDeposit::getEnergyResolution() const {
00092         //assert(!(getRecEnergy() / myTruthEnergy < 0.0));
00093         return fabs((getRecEnergy() - myTruthEnergy) / sqrt(myTruthEnergy));
00094 }
00095 
00096 double ParticleDeposit::getTargetFunctionContrib() const {
00097         //assert(!(getRecEnergy() / myTruthEnergy < 0.0));
00098         return pow((getRecEnergy() - myTruthEnergy), 2);
00099 }
00100 
00101 std::ostream& pftools::operator<<(std::ostream& s, const pftools::ParticleDeposit& p) {
00102         s << "Particle id:\t" << p.getId() << ", \t trueEnergy: " << p.getTruthEnergy() << "\n";
00103         s.width(3);
00104         s << "\tEta:\t" << p.getEta() << ",\tphi:\t" << p.getPhi() << "\n";
00105         for (std::vector<Deposition>::const_iterator cit = p.getRecDepositions().begin(); cit
00106                         != p.getRecDepositions().end(); ++cit) {
00107                 Deposition d = *cit;
00108                 DetectorElementPtr de(d.getDetectorElement());
00109                 s << "\t" << *de << ": \t=> E_contrib = ";
00110                 s << de->getCalib(d.getEta(), d.getPhi()) * d.getEnergy() << "\n";
00111         }
00112         s << "\tTotalRecEnergy: " << p.getRecEnergy() << ",\t res: " << p.getEnergyResolution() * 100 << "%\n";
00113         return s;
00114 }