ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/joshmt/MiscUtil.cxx
(Generate patch)

Comparing UserCode/joshmt/MiscUtil.cxx (file contents):
Revision 1.7 by joshmt, Wed Jul 27 13:50:47 2011 UTC vs.
Revision 1.15 by joshmt, Fri Apr 19 10:17:30 2013 UTC

# Line 7 | Line 7 | can be easily #included into other code
7   #include "TH1D.h"
8   #include "TString.h"
9   #include <iostream>
10 + #include "TMath.h"
11 +
12 + #include <cassert>
13  
14   namespace jmt {
15  
# Line 14 | Line 17 | namespace jmt {
17    //gets rid of = > < from cuts in order to be better included in file names
18    TString fortranize(TString cut) {
19  
20 +    cut.ReplaceAll(" ",""); //remove all spaces
21 +
22      cut.ReplaceAll("==","eq");
23      cut.ReplaceAll(">=","gte");
24      cut.ReplaceAll("<=","lte");
# Line 21 | Line 26 | namespace jmt {
26      cut.ReplaceAll(">","gt");
27      cut.ReplaceAll("<","lt");
28  
29 +    cut.ReplaceAll("&&","and");
30 +    cut.ReplaceAll("||","or");
31 +
32      cut.ReplaceAll("/","Over");
33      cut.ReplaceAll("+","Plus");
34      cut.ReplaceAll("*","Times");
35  
28    cut.ReplaceAll("*","Times");
29    
36      //this is pretty ugly
37      cut.ReplaceAll("(","L");
38      cut.ReplaceAll(")","R");
# Line 60 | Line 66 | namespace jmt {
66  
67  
68    Double_t weightedMean(Int_t n, Double_t *a, Double_t *e, const bool returnError=false) {
69 +    using namespace std;
70  
71      Double_t numerator=0;
72      Double_t denominator=0;
# Line 82 | Line 89 | namespace jmt {
89  
90    }
91  
92 +  //deal with the annoyance of logical booleans that are stored in an ntuple as double
93 +  bool doubleToBool( double a) {
94 +    using namespace std;
95 +
96 +    int i = TMath::Nint(a);
97 +    if (i==0) return false;
98 +    else if (i==1) return true;
99 +    
100 +    cout<<"[doubleToBool] Something weird going on! "<<a<<"\t"<<i<<endl;
101 +    if (i>1) return true;
102 +    return false;
103 +  }
104 +
105 +  //delta phi calculations are pretty commonplace, so put it here
106 +  double deltaPhi(double phi1, double phi2) {
107 +    double result = phi1 - phi2;
108 +    while (result > TMath::Pi()) result -= 2*TMath::Pi();
109 +    while (result <= -TMath::Pi()) result += 2*TMath::Pi();
110 +    return fabs(result);
111 +  }
112 +
113 +  double deltaR2(double eta1, double phi1, double eta2, double phi2) {
114 +    double deta = eta1 - eta2;
115 +    double dphi = deltaPhi(phi1, phi2);
116 +    return deta*deta + dphi*dphi;
117 +  }
118 +
119 +  double deltaR(double eta1, double phi1, double eta2, double phi2) {
120 +    return TMath::Sqrt(deltaR2 (eta1, phi1, eta2, phi2));
121 +  }
122 +
123 +  int signOf(double a) {
124 +    return (a>= 0.0) ? 1 : -1;
125 +  }
126 +
127    // == error propagation ==
128  
129    //because not all versions of ROOT have it built in
# Line 100 | Line 142 | namespace jmt {
142  
143    //return error on a/b
144    double errAoverB(double a, double aerr, double b, double berr) {
145 <    if (b==0 || a==0) {
146 <      cout<<"Warning in errAoverB -- a or b is zero!"<<endl;
145 >    using namespace std;
146 >    if (b==0) {
147 >      cout<<"Warning in errAoverB -- b is zero!"<<endl;
148        return -1;
149      }
150 <    return (a/b)*sqrt( pow( aerr/a, 2) + pow( berr/b, 2) );
150 >    return (1/b)*sqrt( aerr*aerr + a*a*berr*berr/(b*b) );
151    }
152  
153    //return error on a*b
154    double errAtimesB(double a, double aerr, double b, double berr) {
155 <    if (b==0 || a==0) {
113 <      cout<<"Warning in errAtimesB -- a or b is zero!"<<endl;
114 <      return -1;
115 <    }
116 <    
117 <    return a*b*sqrt( pow( aerr/a, 2) + pow( berr/b, 2) );
155 >    return sqrt( b*b*aerr*aerr + a*a*berr*berr);
156    }
157  
158 +  //simple routines for addition in quadrature
159 +  double addInQuad(double a, double b) {return sqrt(a*a + b*b);  }
160 +  double addInQuad(double a, double b, double c) {return sqrt(a*a + b*b + c*c);  }
161 +  double addInQuad(double a, double b, double c, double d) {return sqrt(a*a + b*b + c*c +d*d);  }
162 +
163    //======== container for run, lumisection, event number =========
164    class eventID {
165    public:
# Line 177 | Line 220 | namespace jmt {
220      return false;
221    }
222    
223 +  
224 +  void printHist(const TH1D* h, int binlow=1, int binhigh=-1, bool withErrors=true) {
225 +    if (binhigh == -1) binhigh = h->GetNbinsX();
226 +
227 +    std::cout << h->GetName() << ": " ;
228 +    for (int i = binlow; i<= binhigh; i++) {
229 +      if(withErrors) std::cout << format_nevents(h->GetBinContent(i), h->GetBinError(i)) << ", ";
230 +      else std::cout << " " << h->GetBinContent(i);
231 +    }
232 +    std::cout << std::endl;
233 +  }
234 +
235 +  
236   } //end of namespace
237  
238  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines