-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTResonanceFinder.C
142 lines (104 loc) · 4.4 KB
/
TResonanceFinder.C
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
#define TResonanceFinder_cxx
#include "TResonanceFinder.hh"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TMath.h>
//==============================================================================
TResonanceFinder::TResonanceFinder()
{
//
grSpinRes = new TGraphErrors();
grSpinRes->SetNameTitle("grSpinRes", ";f=(1-G#gamma)f_{cyc} [kHz];Spin Oscilation [Hz]");
grSpinRes->GetXaxis()->SetNdivisions(505);
lOffset = new TLine();
lOffset->SetLineWidth(2);
lOffset->SetLineColor(kBlue+2);
lOffset->SetHorizontal();
lOffset->SetX1( grSpinRes->GetXaxis()->GetXmin() );
lOffset->SetX2( grSpinRes->GetXaxis()->GetXmax() );
lMeanFreq = new TLine();
lMeanFreq->SetLineWidth(2);
lMeanFreq->SetLineColor(kGreen+1);
lMeanFreq->SetVertical();
lMeanFreq->SetY1( grSpinRes->GetYaxis()->GetXmin() );
lMeanFreq->SetY2( grSpinRes->GetYaxis()->GetXmax() );
// grSpinRes->SetPoint(0,1000*0.871433,2.30328);
// grSpinRes->SetPointError(0,8.71433e-9,0.230328);
// grSpinRes->SetPoint(1,1000*0.871432,1.83941);
// grSpinRes->SetPointError(1,8.71432e-9,0.183941);
// grSpinRes->SetPoint(2,1000*0.871431,1.53676);
// grSpinRes->SetPointError(2,8.71431e-9,0.153676);
// grSpinRes->SetPoint(3,1000*0.87143,1.823);
// grSpinRes->SetPointError(3,8.7143e-9,0.1823);
// grSpinRes->SetPoint(4,1000*0.871429,2.54106);
// grSpinRes->SetPointError(4,8.71429e-9,0.254106);
//
fFitFunc = new TF1("fFitFunc", this, &TResonanceFinder::MyPol2, 0, 1, 3, "TResonanceFinder", "MyPol2");
fFitFunc->SetNpx(2000); // increased resolution
fFitFunc->SetParName(0,"Curvature");
fFitFunc->SetParName(1,"Minimum");
fFitFunc->SetParName(2,"Offset");
} // end TResonanceFinder()
//==============================================================================
TResonanceFinder::~TResonanceFinder()
{
// virtual kaputmacher
}
//==============================================================================
Double_t TResonanceFinder::MyPol2(Double_t *x, Double_t *par) {
return (par[0]*TMath::Power((par[1]-x[0]),2) + par[2]);
} // end MyPol2
//==============================================================================
void TResonanceFinder::DoFit() {
fFitFunc->SetRange( grSpinRes->GetXaxis()->GetXmin(),
grSpinRes->GetXaxis()->GetXmax() ); // x-axis range
// fFitFunc->SetParameters(1.14128e+07, 871.4278, 0.15); //
fFitFunc->SetParameters( 8.5e+06, 871.4278, 0.051); //
fFitFunc->SetParLimits(0, 1, 1e+11); // parabolic
fFitFunc->SetParLimits(1, 800, 900); // kHz resonance freq.
fFitFunc->SetParLimits(2, 0.001, 20); // Hz oscillation
grSpinRes->Fit(fFitFunc, "+R0", "");
lOffset->SetY1( fFitFunc->GetParameter(2) );
lOffset->SetY2( fFitFunc->GetParameter(2) );
lMeanFreq->SetX1( fFitFunc->GetParameter(1) );
lMeanFreq->SetX2( fFitFunc->GetParameter(1) );
grSpinRes->SetTitle( Form("Minimum Freq : %10.6f [kHz];f=(1-G#gamma)f_{cyc} [kHz];Spin Oscilation [Hz]",
fFitFunc->GetParameter(1) ) );
cout << Form("\n -- Minimum RF-Freq : %15.10f", fFitFunc->GetParameter(1) ) << endl;
} // end DoFit()
//==============================================================================
void TResonanceFinder::DoPrint()
{
gSystem->Exec("mkdir -p pictures"); // creating dir
// int size = strFileName.Sizeof(); // get size
// TString strRun = strFileName(size-10, 4);
// TString strCanvasName = Form("pictures/Canvas_Run_%s", strRun.Data() ); // extract run number
TString strCanvasName = Form("pictures/cMinimum" ); // extract run number
TPostScript ps(strCanvasName+".ps", 111); // portrait
ps.Range(16, 10); // x,y
DoDraw();
ps.Close();
//
// cout << " -- Output Canvas Name : " << strCanvasName+".pdf" << endl;
cMain->SaveAs(strCanvasName+".pdf");
gSystem->Exec( Form("lpr -p %s", (strCanvasName+".ps").Data() ) );
} // end DoPrint()
//==============================================================================
void TResonanceFinder::DoDraw()
{
//
grSpinRes->SetMarkerStyle(20);
grSpinRes->GetXaxis()->SetNdivisions(505);
grSpinRes->Draw("AP");
fFitFunc->Draw("same");
// draw lines
lOffset->SetX1( grSpinRes->GetXaxis()->GetXmin() );
lOffset->SetX2( grSpinRes->GetXaxis()->GetXmax() );
lOffset->Draw();
lMeanFreq->SetY1( grSpinRes->GetYaxis()->GetXmin() );
lMeanFreq->SetY2( grSpinRes->GetYaxis()->GetXmax() );
lMeanFreq->Draw();
cout << lOffset->GetX1() << " "
<< lMeanFreq->GetY1() << endl;
} // end DoDraw()