-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangdist.cc
More file actions
172 lines (146 loc) · 4.65 KB
/
Copy pathangdist.cc
File metadata and controls
172 lines (146 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <cmath>
#include <iomanip>
#include <fstream>
#include "angdist.h"
#include "harmotools.h"
#include "common.h"
#include "userfcn.h"
// ROOT
#include "TCanvas.h"
#include "TGraph.h"
#include "TProfile2D.h"
#include "TStyle.h"
#include "TColor.h"
#include "TROOT.h"
#include "TLatex.h"
static char gObjName[1024];
static int gObjNumber = 0;
static char * GetObjName() {sprintf(gObjName,"Phi%d",gObjNumber++); return gObjName;}
using namespace std;
// About the TAngularDistribution class
TAngularDistribution::TAngularDistribution() : TFitFunction()
{
fExtension = ""; // no figure is the default
fPhiModulation = false;
}
void TAngularDistribution::SetOptions(double xMin, double xMax, unsigned int nBins, double chi2)
{
fDataMin = xMin;
fDataMax = xMax;
fNBins = nBins;
fChi2Limit = chi2;
}
double TAngularDistribution::GetAccAngle(double* angle) const
{
double val;
if( *angle <= fDataMin || *angle >= fDataMax ) val = 0;
else val = fFitFcn->EvalPar(angle,fPFitParameters);
return val;
}
// About the TPhiModulation class
TPhiModulation::TPhiModulation() : TAngularDistribution(),
fPhiLawFunc(0x0),
fModPhi(0x0),
fPhiLaw(0x0),
fModParams(0x0)
{
}
TPhiModulation::~TPhiModulation()
{
if( fModPhi ) delete fModPhi;
if( fPhiLaw ) delete fPhiLaw;
if( fModParams ) delete [] fModParams;
}
TF1 * TPhiModulation::SetPhiLaw(double (*f)(double *t, double *par), double thetamin, double thetamax, int npars)
{
fPhiLawFunc = f;
fThetaMin = thetamin;
fThetaMax = thetamax;
fNParsPhiLaw = npars;
fPhiLaw = new TF1(GetObjName(),fPhiLawFunc,fThetaMin,fThetaMax,fNParsPhiLaw);
return fPhiLaw;
}
void TPhiModulation::ComputePhiModulation(const vector<TEvent>& events, unsigned int nthetabins)
{
if( fModPhi != 0x0 ) delete fModPhi;
if( fPhiLaw == 0x0 )
{
cout << "Set the law to be used to fit the phi modulation by calling TPhiModulation::SetPhiLaw." << endl;
cout << "Returning." << endl;
return;
}
fPhiModulation = true;
TCanvas * cPhi = new TCanvas(GetObjName(), "Phi Modulation", 1);
fModPhi = new TH1F(GetObjName(), "Phi modulation", nthetabins, fThetaMin, fThetaMax);
DrawHisto(cPhi, fModPhi, "Zenith Angle", "#phi Modulation Coefficient", "");
vector<double> thetavals(nthetabins+1);
unsigned int nbinsphi = 9;
SetNBins(nbinsphi);
vector< vector<double> > pars;
vector< vector<double> > parserr;
vector<double> vnull(fNPars,0);
for(unsigned int i = 0; i <= nthetabins; i++) thetavals[i] = fThetaMin+(fThetaMax-fThetaMin)*i/nthetabins;
string extSave = fExtension;
// fExtension = ""; // do not draw all distributions
for(unsigned int i = 0; i < nthetabins; i++)
{
vector<double> vphi;
// fill data
for(unsigned int j = 0; j < events.size(); j++)
{
if( events[j].fTheta < thetavals[i+1] && events[j].fTheta >= thetavals[i] ) vphi.push_back(events[j].fPhi);
}
if( vphi.size() > 0 )
{
SetData(vphi);
// fit phi distribution in this zenith angle bin
Run();
pars.push_back(GetFitParameters());
parserr.push_back(GetFitParametersErrors());
fModPhi->SetBinContent(i+1,pars[i][1]);
fModPhi->SetBinError(i+1,parserr[i][1]);
}
else
{
pars.push_back(vnull);
parserr.push_back(vnull);
fModPhi->SetBinContent(i+1,pars[i][1]);
fModPhi->SetBinError(i+1,parserr[i][1]);
}
}
fExtension = extSave;
fModPhi->Fit(fPhiLaw,"Q");
if( fModParams ) delete [] fModParams;
else fModParams = new double[fNParsPhiLaw];
fPhiLaw->GetParameters(fModParams);
for(unsigned int i = 0; i < 2; i++) cout << "phi law : " << fModParams[i] << endl;
if( fExtension != "" )
{
fModPhi->Draw("E");
fPhiLaw->SetLineWidth(2);
fPhiLaw->SetLineColor(kRed);
fPhiLaw->Draw("same");
cPhi->Update();
string fileName = "phiLaw"+fExtension;
cPhi->SaveAs(fileName.c_str());
}
}
double TPhiModulation::GetAccAngle(double* angle, double * pars)
{
if( !fPhiLaw || !fFitFcn )
{
cout << "Cannot compute phi modulation, previous fit must have failed" << endl;
cout << "PhiLaw = " << fPhiLaw << " " << " FitFcn = " << fFitFcn << endl;
cout << "Exiting." << endl;
exit(0);
}
if( *angle < fDataMin || *angle > fDataMax ) return 0;
if( pars[0] < fThetaMin || pars[0] > fThetaMax ) return 0;
// fPhiLaw describes fFitFcn parameters law as a function of theta
double amplitude = fPhiLaw->EvalPar(pars,fModParams);
double thepars[2];
thepars[0] = 1;
thepars[1] = amplitude;
double modulation = fFitFcn->EvalPar(angle,thepars);
return modulation;
}