Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Keerthi Nakkalil
gain_measurement
Commits
216fd1d5
Commit
216fd1d5
authored
Dec 03, 2020
by
Keerthi Nakkalil
Browse files
Noise measurements added and fitted with gaussian function.
parent
afd22227
Changes
1
Hide whitespace changes
Inline
Side-by-side
gain_measurement.cpp
View file @
216fd1d5
double
xmin
=
850.0
,
xmax
=
1750.0
,
nbins
=
450.0
;
/////////////////////////////////////////////////////////////
// The function fit_1d sets the cosmetics for the histograms/
// and fits the histogram with modified erf function. /
/////////////////////////////////////////////////////////////
void
fit_1d
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
int
amplitude
,
double
fitmin
,
double
fitmax
)
void
fit_gaussian_noise
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
int
amplitude
,
double
fitmin
,
double
fitmax
)
{
hist_255
->
SetMarkerColor
(
colors
);
hist_255
->
SetMarkerStyle
(
markers
);
TF1
*
fitgauss
=
new
TF1
(
"fitgauss"
,
"([0]*exp(-0.5*((x-[1])/[2])^2))"
,
fitmin
,
fitmax
);
// cout<<"The fit parameters for the amplitude amp_0"<<amplitude<<""<<" are as follows :"<<std::endl;
//Setting parameter names
fitgauss
->
SetParNames
(
"constant"
,
"mean"
,
"noise"
);
//Assigning Initial values to the parameters
fitgauss
->
SetParameter
(
0
,
200.0
);
int
lastbin1
=
hist_255
->
FindLastBinAbove
(
200
);
double
mean
=
hist_255
->
GetBinCenter
(
lastbin1
);
// cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl;
fitgauss
->
SetParameter
(
1
,
mean
);
int
lastbin2
=
hist_255
->
FindLastBinAbove
(
150
);
int
lastbin3
=
hist_255
->
FindLastBinAbove
(
50
);
int
sigma
=
lastbin3
-
lastbin2
;
// cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl;
fitgauss
->
SetParameter
(
2
,
sigma
);
fitgauss
->
SetLineWidth
(
2
);
fitgauss
->
SetLineColor
(
2
);
hist_255
->
Fit
(
"fitgauss"
,
" R"
);
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fitgauss"
)
->
Draw
(
"same"
);
hist_255
->
SetStats
(
0
);
}
void
fit_modified_erf
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
int
amplitude
,
double
fitmin
,
double
fitmax
)
{
// hist_255->GetXaxis()->SetTitle("Threshold");
// hist_255->GetYaxis()->SetTitle("# signals above the threshold");
...
...
@@ -13,47 +43,43 @@ void fit_1d(TH1D* hist_255,int colors,int markers,int amplitude,double fitmin,do
hist_255
->
SetMarkerStyle
(
markers
);
TF1
*
fit
func
=
new
TF1
(
"fit
func
"
,
"([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))"
,
fitmin
,
fitmax
);
TF1
*
fit
erf
=
new
TF1
(
"fit
erf
"
,
"([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))"
,
fitmin
,
fitmax
);
cout
<<
"The fit parameters for the amplitude amp_0"
<<
amplitude
<<
""
<<
" are as follows :"
<<
std
::
endl
;
//
cout<<"The fit parameters for the amplitude amp_0"<<amplitude<<""<<" are as follows :"<<std::endl;
/*Setting parameter names*/
fit
func
->
SetParNames
(
"constant"
,
"mean"
,
"noise"
);
fit
erf
->
SetParNames
(
"constant"
,
"mean"
,
"noise"
);
//Assigning Initial values to the parameters
fit
func
->
SetParameter
(
0
,
200.0
);
fit
erf
->
SetParameter
(
0
,
200.0
);
int
lastbin1
=
hist_255
->
FindLastBinAbove
(
200
);
double
mean
=
hist_255
->
GetBinCenter
(
lastbin1
);
// cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl;
fit
func
->
SetParameter
(
1
,
mean
);
fit
erf
->
SetParameter
(
1
,
mean
);
int
lastbin2
=
hist_255
->
FindLastBinAbove
(
150
);
int
lastbin3
=
hist_255
->
FindLastBinAbove
(
50
);
int
sigma
=
lastbin3
-
lastbin2
;
// cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl;
fit
func
->
SetParameter
(
2
,
sigma
);
fit
erf
->
SetParameter
(
2
,
sigma
);
fit
func
->
SetLineWidth
(
2
);
fit
func
->
SetLineColor
(
2
);
fit
erf
->
SetLineWidth
(
2
);
fit
erf
->
SetLineColor
(
2
);
hist_255
->
Fit
(
"fit
func
"
,
" R"
);
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fit
func
"
)
->
Draw
(
"same"
);
hist_255
->
Fit
(
"fit
erf
"
,
" R"
);
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fit
erf
"
)
->
Draw
(
"same"
);
hist_255
->
SetStats
(
0
);
}
std
::
vector
<
TH1D
*>
gain_measurement_pixel
(
int
i
,
int
j
)
{
//double xmin=850.0,xmax = 1750.0;
std
::
vector
<
int
>
colors
=
{
kAzure
,
kTeal
+
3
,
kViolet
+
3
};
std
::
vector
<
int
>
markers
=
{
1
,
1
,
1
};
std
::
vector
<
double
>
fitmin
=
{
1220.
,
1200.
,
1150.
};
std
::
vector
<
double
>
fitmax
=
{
1700.
,
1420.
,
1240.
};
std
::
vector
<
int
>
colors
=
{
kAzure
,
kTeal
+
3
,
kViolet
+
3
,
kOrange
+
4
};
std
::
vector
<
int
>
markers
=
{
1
,
1
,
1
,
1
};
std
::
vector
<
double
>
fitmin
=
{
1220.
,
1200.
,
1150.
,
1000.0
};
std
::
vector
<
double
>
fitmax
=
{
1700.
,
1420.
,
1240.
,
1500.0
};
std
::
vector
<
TH1D
*>
hist_255
;
//The data files are named as following : 000_000.dat to 256_256.dat
...
...
@@ -65,11 +91,12 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
std
::
vector
<
std
::
string
>
filenames
=
{
std
::
string
(
"amp03/"
+
sfilename
.
str
()),
std
::
string
(
"amp02/"
+
sfilename
.
str
()),
std
::
string
(
"amp01/"
+
sfilename
.
str
())
std
::
string
(
"amp01/"
+
sfilename
.
str
()),
std
::
string
(
"amp00/"
+
sfilename
.
str
())
};
for
(
int
amp
=
0
;
amp
<
3
;
amp
++
)
{
for
(
int
amp
=
0
;
amp
<
4
;
amp
++
)
{
std
::
ifstream
amplitude_file
(
filenames
.
at
(
amp
).
c_str
());
if
(
amplitude_file
.
is_open
())
{
...
...
@@ -95,7 +122,12 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
}
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
fit_1d
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
amp
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
));
if
(
filenames
.
at
(
amp
)
==
0
||
filenames
.
at
(
amp
)
==
1
||
filenames
.
at
(
amp
)
==
2
){
fit_modified_erf
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
amp
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
));
}
else
{
fit_gaussian_noise
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
amp
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
));
}
}
return
hist_255
;
}
...
...
@@ -148,6 +180,11 @@ void gain_measurement()
if
(
pixel_histograms
.
at
(
2
)){
leg
->
AddEntry
(
pixel_histograms
.
at
(
2
),
"low amplitude"
,
"p"
);
}
if
(
pixel_histograms
.
at
(
3
)){
leg
->
AddEntry
(
pixel_histograms
.
at
(
3
),
"noise"
,
"p"
);
}
leg
->
Draw
(
"SAME"
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment