ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Common/MyTools.hh
Revision: 1.1
Committed: Sat Jun 4 14:09:52 2011 UTC (13 years, 11 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
new

File Contents

# Content
1 #ifndef MYTOOLS_HH
2 #define MYTOOLS_HH
3
4 #include <TGraphAsymmErrors.h>
5 #include <TH1F.h>
6 #include <iostream>
7
8 //#include "RooStats/FeldmanCousins.h"
9
10 namespace toolbox
11 {
12 //Double_t calcEff(const Int_t pass, const Int_t total, Double_t *errl=0, Double_t *errh=0, Int_t method=0);
13 //Double_t calcEff(const Double_t pass, const Double_t total, Double_t *errl=0, Double_t *errh=0, Int_t method=0);
14
15 Double_t deltaR(const Double_t eta1, const Double_t phi1, const Double_t eta2, const Double_t phi2);
16
17 Double_t deltaPhi(const Double_t phi1, const Double_t phi2);
18
19 Int_t roundToInt(const Double_t x);
20 }
21 /*
22 //------------------------------------------------------------------------------------------------------------------------
23 Double_t toolbox::calcEff(Int_t pass, Int_t total, Double_t *errl, Double_t *errh, Int_t method)
24 {
25 // method: 0 -> Bayes Divide
26 // 1 -> Feldman-Cousins
27 // 2 -> Clopper-Pearson
28
29 Double_t r = (total>0) ? (Double_t)pass/(Double_t)total : 0;
30 if(errl) *errl = 0;
31 if(errh) *errh = 0;
32
33 const Double_t conf = 0.68269;
34
35 if(method==0) {
36 TGraphAsymmErrors g;
37 Double_t mode, low, high;
38 g.Efficiency(pass,total,conf,mode,low,high);
39 if(errl) *errl = mode - low;
40 if(errh) *errh = high - mode;
41 }
42
43 if(method==1) {
44 // FeldmanCousins fc;
45 // fc.SetConfidenceLevel(conf);
46 }
47
48 if(method==2) {
49 }
50
51 return r;
52 }
53
54 Double_t toolbox::calcEff(Double_t pass, Double_t total, Double_t *errl, Double_t *errh, Int_t method)
55 {
56 // Round values to whole numbers first
57 return calcEff(roundToInt(pass),roundToInt(total),errl,errh,method);
58 }
59 */
60 //------------------------------------------------------------------------------------------------------------------------
61 Double_t toolbox::deltaR(Double_t eta1, Double_t phi1, Double_t eta2, Double_t phi2)
62 {
63 const Double_t pi = 3.14159265358979;
64 Double_t dphi = fabs(phi1-phi2);
65 while (dphi>pi)
66 dphi = fabs(dphi - 2.0*pi);
67
68 Double_t deta = eta1-eta2;
69
70 return sqrt(dphi*dphi + deta*deta);
71 }
72
73 //------------------------------------------------------------------------------------------------------------------------
74 Double_t toolbox::deltaPhi(Double_t phi1, Double_t phi2)
75 {
76 // Compute dPhi between two given angles. Results is in [0,pi].
77 const Double_t pi = 3.14159265358979;
78 Double_t dphi = fabs(phi1-phi2);
79 while (dphi>pi)
80 dphi = fabs(dphi - 2.0*pi);
81
82 return dphi;
83 }
84
85 //------------------------------------------------------------------------------------------------------------------------
86 Int_t toolbox::roundToInt(Double_t x)
87 {
88 if(x>0)
89 return ((x-floor(x)) < (ceil(x)-x)) ? (Int_t)floor(x) : (Int_t)ceil(x);
90 else
91 return ((x-floor(x)) < (ceil(x)-x)) ? (Int_t)ceil(x) : (Int_t)floor(x);
92 }
93
94 #endif