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
76dbc9ea
Commit
76dbc9ea
authored
Dec 07, 2020
by
Keerthi Nakkalil
Browse files
Functions added to do a linear fit on the mean values to get the slope distribution
parent
ba5e38a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
gain_measurement.cpp
View file @
76dbc9ea
double
xmin
=
850.0
,
xmax
=
1750.0
,
nbins
=
450.0
;
void
fit_gaussian_noise
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
int
amplitude
,
double
fitmin
,
double
fitmax
)
void
fit_gaussian_noise
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
double
fitmin
,
double
fitmax
,
int
pixel_address
)
{
cout
<<
"The histograms are fitted with gaussian function..."
<<
std
::
endl
;
hist_255
->
SetMarkerColor
(
colors
);
hist_255
->
SetMarkerStyle
(
markers
);
...
...
@@ -18,35 +19,33 @@ void fit_gaussian_noise(TH1D* hist_255,int colors,int markers,int amplitude,doub
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"
);
/*std::ofstream fitpars;
fitpars.open("fit_parameters.txt",std::ofstream::app);
fitpars<<pixel_address<<"_"<<pixel_address<< " "<< fitgauss->GetParameter(1)<<std::endl;*/
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fitgauss"
)
->
Draw
(
"same"
);
hist_255
->
SetStats
(
0
);
}
void
fit_modified_erf
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
int
amplitud
e
,
double
fitmin
,
double
fitmax
)
void
fit_modified_erf
(
TH1D
*
hist_255
,
int
colors
,
int
markers
,
double
injected_voltag
e
,
double
fitmin
,
double
fitmax
,
int
pixel_address
)
{
// hist_255->GetXaxis()->SetTitle("Threshold");
// hist_255->GetYaxis()->SetTitle("# signals above the threshold");
cout
<<
"The histograms are fitted with modified error function..."
<<
std
::
endl
;
hist_255
->
SetMarkerColor
(
colors
);
hist_255
->
SetMarkerStyle
(
markers
);
TF1
*
fiterf
=
new
TF1
(
"fiterf"
,
"([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;
/*Setting parameter names*/
fiterf
->
SetParNames
(
"constant"
,
"mean"
,
"noise"
);
...
...
@@ -56,22 +55,24 @@ void fit_modified_erf(TH1D* hist_255,int colors,int markers,int amplitude,double
fiterf
->
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;
fiterf
->
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;
fiterf
->
SetParameter
(
2
,
sigma
);
fiterf
->
SetLineWidth
(
2
);
fiterf
->
SetLineColor
(
2
);
hist_255
->
Fit
(
"fiterf"
,
" R"
);
std
::
ofstream
fitpars
;
fitpars
.
open
(
"fit_parameters.txt"
,
std
::
ofstream
::
app
);
fitpars
<<
std
::
setw
(
3
)
<<
std
::
setfill
(
'0'
)
<<
pixel_address
<<
"_"
<<
std
::
setw
(
3
)
<<
std
::
setfill
(
'0'
)
<<
pixel_address
<<
"
\t
"
<<
injected_voltage
<<
"
\t
"
<<
fiterf
->
GetParameter
(
1
)
<<
std
::
endl
;
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fiterf"
)
->
Draw
(
"same"
);
hist_255
->
SetStats
(
0
);
}
std
::
vector
<
TH1D
*>
gain_measurement_pixel
(
int
i
,
int
j
)
...
...
@@ -81,6 +82,8 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
std
::
vector
<
double
>
fitmin
=
{
1220.
,
1200.
,
1150.
,
1000.0
};
std
::
vector
<
double
>
fitmax
=
{
1700.
,
1420.
,
1240.
,
1500.0
};
std
::
vector
<
TH1D
*>
hist_255
;
// double amplitude[3]={298.2559,149.6258,49.1753};
std
::
vector
<
double
>
injected_voltage
=
{
298.2559
,
149.6258
,
49.1753
};
//The data files are named as following : 000_000.dat to 256_256.dat
stringstream
sfilename
;
...
...
@@ -98,12 +101,15 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
for
(
int
amp
=
0
;
amp
<
4
;
amp
++
)
{
// std::vector<std::ifstream>amplitude_file;
// amplitude_file.open(filenames.at(amp).c_str());
std
::
ifstream
amplitude_file
(
filenames
.
at
(
amp
).
c_str
());
if
(
amplitude_file
.
is_open
())
{
cout
<<
"The data file "
<<
filenames
.
at
(
amp
)
<<
" is opened..."
<<
std
::
endl
;
std
::
string
hist_name
=
"h"
+
std
::
to_string
(
amp
)
+
"_"
+
std
::
to_string
(
j
);
TH1D
*
h1
=
new
TH1D
(
hist_name
.
c_str
(),
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
std
::
string
hist_title
=
"Threshold gain measurement for the pixel "
+
std
::
to_string
(
i
)
+
"_"
+
std
::
to_string
(
i
);
TH1D
*
h1
=
new
TH1D
(
hist_name
.
c_str
(),
hist_title
.
c_str
(),
nbins
,
xmin
,
xmax
);
std
::
string
line
;
while
(
!
amplitude_file
.
eof
())
{
...
...
@@ -122,17 +128,77 @@ std::vector<TH1D*> gain_measurement_pixel(int i, int j)
}
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
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
));
if
(
amp
==
0
||
amp
==
1
||
amp
==
2
){
fit_modified_erf
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
injected_voltage
.
at
(
amp
)
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
)
,
i
);
}
else
{
fit_gaussian_noise
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
amp
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
));
fit_gaussian_noise
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
)
,
i
);
}
}
return
hist_255
;
}
void
gain_measurement
()
void
linear_fit
(
int
x
)
{
ifstream
fitpars
(
"fit_parameters.txt"
);
std
::
string
pixel_address
;
std
::
vector
<
double
>
injected_amp_vec
,
signals_vec
;
double
injected_amplitude
,
signals
;
std
::
vector
<
TGraph
*>
gr
;
if
(
fitpars
.
is_open
()){
while
(
!
fitpars
.
eof
()){
while
(
fitpars
>>
pixel_address
){
// cout<<"The injected amplitudes and the corresponding mean values for "<<pixel_address<<"are : " <<std::endl;
fitpars
>>
injected_amplitude
>>
signals
;
//cout<<injected_amplitude<<" "<<signals<<std::endl;
injected_amp_vec
.
push_back
(
injected_amplitude
);
signals_vec
.
push_back
(
signals
);
for
(
int
i
=
0
;
i
<
3
;
i
++
){
gr
.
push_back
(
new
TGraph
(
injected_amp_vec
.
size
(),
&
(
injected_amp_vec
[
i
]),
&
(
signals_vec
[
i
])));
}
}
for
(
int
j
=
0
;
j
<
256
;
j
++
){
auto
linear_fit
=
new
TF1
(
"linear_fit"
,
"[0]*x +[1]"
,
0
,
300
);
linear_fit
->
SetParNames
(
"slope"
,
"offset"
);
linear_fit
->
SetParameter
(
0
,
2
);
linear_fit
->
SetParameter
(
1
,
1200
);
linear_fit
->
SetLineColor
(
2
);
gr
.
at
(
j
)
->
Fit
(
linear_fit
);
gr
.
at
(
j
)
->
Draw
(
"AL*"
);
gr
.
at
(
j
)
->
GetXaxis
()
->
SetTitle
(
"Injected amplitude"
);
gr
.
at
(
j
)
->
GetYaxis
()
->
SetTitle
(
"mean values"
);
std
::
ofstream
slopes
;
slopes
.
open
(
"slopes.txt"
,
std
::
ofstream
::
app
);
slopes
<<
linear_fit
->
GetParameter
(
0
)
<<
" "
;
}
}
}
}
void
slope_distribution
(
int
y
)
{
ifstream
slopes
(
"slopes.txt"
);
double
slopeval
;
TH1D
*
hist
=
new
TH1D
(
"slope"
,
"slope distribution"
,
200
,
-
2.0
,
10.0
);
if
(
slopes
.
is_open
()){
while
(
!
slopes
.
eof
()){
slopes
>>
slopeval
;
hist
->
Fill
(
slopeval
);
hist
->
GetXaxis
()
->
SetTitle
(
"Slope values"
);
hist
->
GetYaxis
()
->
SetTitle
(
"#entries"
);
hist
->
Draw
();
}
}
}
void
gain_9
()
{
int
row
,
col
;
THStack
*
hs
=
new
THStack
(
"hs"
,
"Gain measurements"
);
...
...
@@ -157,10 +223,11 @@ void gain_measurement()
}
// cout<<"The size of pixel_histogram vector is"<<pixel_histograms.size()<<std::endl;
}
TCanvas
*
c1
=
new
TCanvas
(
"c1"
);
c1
->
Divide
(
2
,
2
);
c1
->
cd
(
1
);
cout
<<
"The histograms are added to the stack..."
<<
std
::
endl
;
hs
->
Draw
(
"HIST P nostack"
);
hs
->
GetXaxis
()
->
SetTitle
(
"Threshold"
);
hs
->
GetYaxis
()
->
SetTitle
(
"# signals above the threshold"
);
...
...
@@ -187,4 +254,10 @@ void gain_measurement()
leg
->
Draw
(
"SAME"
);
c1
->
cd
(
2
);
linear_fit
(
5
);
c1
->
cd
(
3
);
slope_distribution
(
5
);
}
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