Fork me on GitHub

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

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

first attemp towers CMS

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 double Et,eta,phi;
14
15 Centroid(): Et(0), eta(0), phi(0) {}
16 Centroid(double centroidEt, double centroidEta, double centroidPhi): Et(centroidEt), eta(centroidEta), phi(centroidPhi) {}
17 Centroid(const Centroid& c): Et(c.Et), eta(c.eta), phi(c.phi) {}
18 void add(const Centroid& c)
19 {
20 double newEt = Et + c.Et;
21 eta = (Et*eta + c.Et*c.eta)/newEt;
22 double dPhi = c.phi - phi;
23 if(dPhi > M_PI)
24 dPhi -= 2*M_PI;
25 else if(dPhi < -M_PI)
26 dPhi += 2*M_PI;
27 phi += dPhi*c.Et/newEt;
28 while(phi < 0)
29 phi += 2*M_PI;
30 while(phi >= 2*M_PI)
31 phi -= 2*M_PI;
32 Et = newEt;
33 }
34 void subtract(const Centroid& c)
35 {
36 double newEt = Et - c.Et;
37 eta = (Et*eta - c.Et*c.eta)/newEt;
38 double dPhi = c.phi - phi;
39 if(dPhi > M_PI)
40 dPhi -= 2*M_PI;
41 else if(dPhi < -M_PI)
42 dPhi += 2*M_PI;
43 phi -= dPhi*c.Et/newEt;
44 while(phi < 0)
45 phi += 2*M_PI;
46 while(phi >= 2*M_PI)
47 phi -= 2*M_PI;
48 Et = newEt;
49 }
50 bool isEqual(const Centroid& c)
51 {
52 return Et == c.Et && eta == c.eta && phi == c.phi;
53 }
54};
55
56#endif
Note: See TracBrowser for help on using the repository browser.