Fork me on GitHub

source: svn/trunk/Utilities/CDFCones/interface/Centroid.h@ 2

Last change on this file since 2 was 2, checked in by Xavier Rouby, 16 years ago

first commit

File size: 1.1 KB
Line 
1#ifndef _CENTROID_HH_
2#define _CENTROID_HH_
3
4#include <cmath>
5
6class Centroid
7{
8 public:
9
10 double Et,eta,phi;
11
12 Centroid(): Et(0), eta(0), phi(0) {}
13 Centroid(double centroidEt, double centroidEta, double centroidPhi): Et(centroidEt), eta(centroidEta), phi(centroidPhi) {}
14 Centroid(const Centroid& c): Et(c.Et), eta(c.eta), phi(c.phi) {}
15 void add(Centroid c)
16 {
17 double newEt = Et + c.Et;
18 eta = (Et*eta + c.Et*c.eta)/newEt;
19 double dPhi = c.phi - phi;
20 if(dPhi > M_PI)
21 dPhi -= 2*M_PI;
22 else if(dPhi < -M_PI)
23 dPhi += 2*M_PI;
24 phi += dPhi*c.Et/newEt;
25 while(phi < 0)
26 phi += 2*M_PI;
27 while(phi >= 2*M_PI)
28 phi -= 2*M_PI;
29 Et = newEt;
30 }
31 void subtract(Centroid c)
32 {
33 double newEt = Et - c.Et;
34 eta = (Et*eta - c.Et*c.eta)/newEt;
35 double dPhi = c.phi - phi;
36 if(dPhi > M_PI)
37 dPhi -= 2*M_PI;
38 else if(dPhi < -M_PI)
39 dPhi += 2*M_PI;
40 phi -= dPhi*c.Et/newEt;
41 while(phi < 0)
42 phi += 2*M_PI;
43 while(phi >= 2*M_PI)
44 phi -= 2*M_PI;
45 Et = newEt;
46 }
47 bool isEqual(Centroid c)
48 {
49 return Et == c.Et && eta == c.eta && phi == c.phi;
50 }
51};
52
53#endif
Note: See TracBrowser for help on using the repository browser.