Fork me on GitHub

source: svn/trunk/Utilities/Fastjet/plugins/CDFCones/interface/Centroid.hh@ 14

Last change on this file since 14 was 11, checked in by severine ovyn, 16 years ago

Fastjet added; CDFCones directory has been changed

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