1 //------------------------------------------------------------------------------
4 // macro to divide two TGraphs using Exponential interpolation
5 //------------------------------------------------------------------------------
9 Double_t ExtrapolateExp(Double_t x0, Double_t y0, Double_t x1, Double_t y1, Double_t x)
11 // extra/interpolates using an exponential defined by (x0,y0) and (x1,y1) to x
13 Double_t b = (TMath::Log(y0) - TMath::Log(y1)) / (x0 - x1);
14 Double_t a = TMath::Log(y0) - b * x0;
15 Double_t a2 = TMath::Log(y1) - b * x1;
17 //Printf("%f %f %f", b, a, a2);
19 return TMath::Exp(a + b * x);
23 TGraphErrors* divide(TGraph* dividend, TGraph* divisor, Bool_t exp = kTRUE)
26 cout << "---------------------------------------------------------" << endl;
27 cout << "starting macro: << divide.C >> " << endl;
28 cout << "---------------------------------------------------------" << endl;
40 divisor->GetPoint(0,x,y);
42 cout << "divisor: minx = " << minx << endl;
44 divisor->GetPoint(divisor->GetN()-1,x,y);
46 cout << "divisor: maxx = " << maxx << endl;
48 dividend->GetPoint(0,x,y);
49 if (x > minx) { minx = x; }
51 dividend->GetPoint(dividend->GetN()-1,x,y);
52 if (x < maxx) { maxx = x; }
54 cout << "minx = " << minx << endl;
55 cout << "maxx = " << maxx << endl;
59 for (int i=0; i < dividend->GetN(); i++) {
60 dividend->GetPoint(i,x,y);
61 if ((x <= maxx) && (x >= minx)) {bins++;}
64 TGraphErrors* result = new TGraphErrors(bins);
65 TGraph* errors = new TGraph(divisor->GetN(),divisor->GetX(),divisor->GetEY());
69 for (int i=0; i < dividend->GetN(); i++) {
70 dividend->GetPoint(i,x,y1);
71 if (!((x <= maxx) && (x >= minx))) { continue; }
75 for (int n=0; n < divisor->GetN(); n++) {
76 divisor->GetPoint(n,x1temp,y1temp);
78 if (x1temp >= x) break;
81 cout << "x1temp=" << x1temp;
82 if (x1temp == x) { y2 = y1temp; }
86 cout << "nfortemp=" << n << endl;
87 divisor->GetPoint(n-1,x0temp,y0temp);
88 y2 = ExtrapolateExp(x0temp,y0temp,x1temp,y1temp,x);
89 cout << "exp extrapolation used" << endl;
92 y2 = divisor->Eval(x);
96 e1 = dividend->GetErrorY(i);
97 //e2 = errors->Eval(x);
100 ey = y*sqrt((e1/y1)*(e1/y1) + (e2/y2)*(e2/y2));
101 result->SetPoint(j,x,y);
102 result->SetPointError(j,ex,ey);
104 cout << "data point # " << j << endl;
105 cout << " x= " << x << " +- " << ex <<endl;
106 cout << " y= " << y << " +- " << ey <<endl;
113 cout << "min:" << minx <<endl;
114 cout << "max:" << maxx <<endl;
116 cout << "---------------------------------------------------------" << endl;
117 cout << "finished macro: << divide.C >> " << endl;
118 cout << "---------------------------------------------------------" << endl;