CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParticleDeposit.cc
Go to the documentation of this file.
2 #include <cassert>
3 #include <iostream>
4 #include <cmath>
6 using namespace pftools;
7 
8 unsigned ParticleDeposit::count = 0;
9 
10 ParticleDeposit::ParticleDeposit(double truthEnergy, double eta, double phi) :
11  myId(count), myTruthEnergy(truthEnergy), myEta(eta), myPhi(phi) {
12  ++count;
13 }
14 
16 }
17 
19  myRecDepositions.push_back(rec);
20 }
21 
23  myTruthDepositions.push_back(truth);
24 }
25 
26 std::vector<Deposition> ParticleDeposit::getTruthDepositions() const {
27  return myTruthDepositions;
28 }
29 
30 const std::vector<Deposition>& ParticleDeposit::getRecDepositions() const {
31  return myRecDepositions;
32 }
33 
35  double energy(0);
36  for (std::vector<Deposition>::const_iterator cit = myRecDepositions.begin(); cit
37  != myRecDepositions.end(); ++cit) {
38  Deposition d = *cit;
39 
40  if (d.getDetectorElement()->getType() == de->getType()) {
41  energy += de->getCalib(d.getEta(), d.getPhi()) * d.getEnergy();
42  }
43 
44  }
45  return energy;
46 }
47 
49  for (std::vector<Deposition>::const_iterator cit = myRecDepositions.begin(); cit
50  != myRecDepositions.end(); ++cit) {
51  Deposition d = *cit;
52 
53  if (d.getDetectorElement()->getType() == de->getType()) {
54  d.setEnergy(energy);
55  }
56 
57  }
58 }
59 
61  double energy(0);
62  for (std::vector<Deposition>::const_iterator
63  cit = myTruthDepositions.begin(); cit!= myTruthDepositions.end(); ++cit) {
64  Deposition d = *cit;
65  if (d.getDetectorElement() == de) {
66  energy += d.getEnergy();
67  }
68  }
69  assert(!(energy > 0));
70  return energy;
71 
72 }
73 
75  double energy(0);
76  for (std::vector<Deposition>::const_iterator cit = myRecDepositions.begin(); cit
77  != myRecDepositions.end(); ++cit) {
78  Deposition d = *cit;
79 // if (d.getDetectorElement()->getType() == OFFSET && d.getDetectorElement()->getCalib() == 1.0) {
80 // //don't add a tiny amount!
81 // } else {
82  energy += d.getDetectorElement()->getCalib(d.getEta(), d.getPhi()) * d.getEnergy();
83 // }
84  }
85 
86  //assert(!(energy < 0));
87  return energy;
88 
89 }
90 
92  //assert(!(getRecEnergy() / myTruthEnergy < 0.0));
93  return fabs((getRecEnergy() - myTruthEnergy) / sqrt(myTruthEnergy));
94 }
95 
97  //assert(!(getRecEnergy() / myTruthEnergy < 0.0));
98  return pow((getRecEnergy() - myTruthEnergy), 2);
99 }
100 
101 std::ostream& pftools::operator<<(std::ostream& s, const pftools::ParticleDeposit& p) {
102  s << "Particle id:\t" << p.getId() << ", \t trueEnergy: " << p.getTruthEnergy() << "\n";
103  s.width(3);
104  s << "\tEta:\t" << p.getEta() << ",\tphi:\t" << p.getPhi() << "\n";
105  for (std::vector<Deposition>::const_iterator cit = p.getRecDepositions().begin(); cit
106  != p.getRecDepositions().end(); ++cit) {
107  Deposition d = *cit;
109  s << "\t" << *de << ": \t=> E_contrib = ";
110  s << de->getCalib(d.getEta(), d.getPhi()) * d.getEnergy() << "\n";
111  }
112  s << "\tTotalRecEnergy: " << p.getRecEnergy() << ",\t res: " << p.getEnergyResolution() * 100 << "%\n";
113  return s;
114 }
virtual const std::vector< Deposition > & getRecDepositions() const
virtual double getEnergyResolution() const
DetectorElementPtr getDetectorElement() const
Definition: Deposition.h:43
double getEnergy() const
Definition: Deposition.h:38
virtual void addTruthDeposition(Deposition truth)
T eta() const
virtual void addRecDeposition(Deposition rec)
virtual void setRecEnergy(const DetectorElementPtr de, double energy)
double getTargetFunctionContrib() const
T sqrt(T t)
Definition: SSEVec.h:46
virtual unsigned getId() const
virtual double getRecEnergy() const
boost::shared_ptr< DetectorElement > DetectorElementPtr
virtual double getTruthEnergy() const
This class holds an arbitrary energy deposition, specified in terms of angular position, energy, depth (optional) and detector element type.
Definition: Deposition.h:20
std::vector< Deposition > myTruthDepositions
std::vector< Deposition > myRecDepositions
virtual double getPhi() const
void setEnergy(double energy)
Definition: Deposition.h:23
virtual double getRecEnergy(const DetectorElementPtr de) const
ParticleDeposit(double truthEnergy=-1.0, double eta=0, double phi=0)
std::ostream & operator<<(std::ostream &s, const Calibratable &calib_)
Definition: Calibratable.cc:6
virtual std::vector< Deposition > getTruthDepositions() const
double getPhi() const
Definition: Deposition.h:33
double getEta() const
Definition: Deposition.h:28
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Definition: DDAxes.h:10