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
524ef7ec
Commit
524ef7ec
authored
Dec 02, 2020
by
Keerthi Nakkalil
Browse files
Working codegit add gain_measurement.cpp git add gain_measurement.cpp
parent
4015a449
Changes
1
Hide whitespace changes
Inline
Side-by-side
gain_measurement.cpp
View file @
524ef7ec
...
...
@@ -5,7 +5,7 @@ double xmin=850.0,xmax = 1750.0,nbins=450.0;
// and fits the histogram with modified erf function. /
/////////////////////////////////////////////////////////////
TH1D
*
fit_1d
(
TH1D
*
&
hist_255
,
int
colors
,
int
markers
,
int
&
amplitude
,
double
fitmin
,
double
fitmax
)
void
fit_1d
(
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"
);
...
...
@@ -26,13 +26,13 @@ TH1D *fit_1d(TH1D* &hist_255,int colors,int markers,int &litude,double fitmin
fitfunc
->
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
;
//
cout<<"The initial mean value assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<mean<<std::endl;
fitfunc
->
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
;
//
cout<<"The initial noise assigned for the data of amp_0 "<<amplitude<<""<<" is "<<""<<sigma<<std::endl;
fitfunc
->
SetParameter
(
2
,
sigma
);
fitfunc
->
SetLineWidth
(
2
);
...
...
@@ -41,116 +41,61 @@ TH1D *fit_1d(TH1D* &hist_255,int colors,int markers,int &litude,double fitmin
hist_255
->
Fit
(
"fitfunc"
,
" R"
);
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fitfunc"
)
->
Draw
(
"same"
);
hist_255
->
SetStats
(
0
);
return
hist_255
;
}
std
::
vector
<
TH1D
*>
gain_measurement
(
int
i
,
int
j
)
std
::
vector
<
TH1D
*>
gain_measurement
_pixel
(
int
i
,
int
j
)
{
int
x
,
y
;
//double xmin=850.0,xmax = 1750.0;
std
::
vector
<
int
>
colors
=
{
kAzure
,
kTeal
+
3
,
kViolet
+
3
};
std
::
vector
<
int
>
markers
=
{
2
,
3
,
5
};
std
::
vector
<
double
>
fitmin
=
{
1220.
,
1200.
,
1150.
};
std
::
vector
<
double
>
fitmax
=
{
1700.
,
1420.
,
1240.
};
std
::
vector
<
TH1D
*>
hist_255
;
ifstream
amp03
,
amp02
,
amp01
;
std
::
vector
<
TH1D
*>
hist_255
;
stringstream
sfilename
;
sfilename
<<
std
::
setw
(
3
)
<<
std
::
setfill
(
'0'
)
<<
i
<<
"_"
<<
std
::
setw
(
3
)
<<
std
::
setfill
(
'0'
)
<<
j
<<
".dat"
;
std
::
cout
<<
sfilename
.
str
()
<<
std
::
endl
;
amp03
.
open
(
std
::
string
(
"amp03/"
+
sfilename
.
str
()).
c_str
());
amp02
.
open
(
std
::
string
(
"amp02/"
+
sfilename
.
str
()).
c_str
());
amp01
.
open
(
std
::
string
(
"amp01/"
+
sfilename
.
str
()).
c_str
());
if
(
amp03
.
is_open
())
{
cout
<<
"The data file "
<<
i
<<
"_"
<<
j
<<
" is opened..."
<<
std
::
endl
;
TH1D
*
h3
=
(
TH1D
*
)
gROOT
->
FindObject
(
"h3"
);
delete
h3
;
//to prevent memomory leak
h3
=
new
TH1D
(
"h3"
,
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
hist_255
.
push_back
(
h3
);
amp03
.
clear
();
amp03
.
seekg
(
118
,
std
::
ios_base
::
beg
);
while
(
!
amp03
.
eof
())
{
// cout<<"The values from the file amp03 is extracted..."<<std::endl;
amp03
>>
x
>>
y
;
hist_255
.
at
(
0
)
->
Fill
(
x
,
y
);
}
hist_255
.
at
(
0
)
->
Draw
(
"HIST P"
);
cout
<<
"histogram with amp03 filled..."
<<
std
::
endl
;
}
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
if
(
amp02
.
is_open
())
{
cout
<<
"The data file"
<<
i
<<
"_"
<<
j
<<
" is opened..."
<<
std
::
endl
;
TH1D
*
h2
=
(
TH1D
*
)
gROOT
->
FindObject
(
"h2"
);
delete
h2
;
h2
=
new
TH1D
(
"h2"
,
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
hist_255
.
push_back
(
h2
);
amp02
.
clear
();
amp02
.
seekg
(
118
,
std
::
ios_base
::
beg
);
while
(
!
amp02
.
eof
())
{
amp02
>>
x
>>
y
;
hist_255
.
at
(
1
)
->
Fill
(
x
,
y
);
std
::
cout
<<
"Filename: "
<<
sfilename
.
str
()
<<
std
::
endl
;
std
::
vector
<
std
::
string
>
filenames
=
{
std
::
string
(
"amp03/"
+
sfilename
.
str
()),
std
::
string
(
"amp02/"
+
sfilename
.
str
()),
std
::
string
(
"amp01/"
+
sfilename
.
str
())
};
for
(
int
amp
=
0
;
amp
<
3
;
amp
++
)
{
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
line
;
while
(
!
amplitude_file
.
eof
())
{
std
::
getline
(
amplitude_file
,
line
);
if
(
line
.
rfind
(
"#"
,
0
)
==
0
)
{
continue
;
}
hist_255
.
at
(
1
)
->
Draw
(
"HIST SAME P"
);
}
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
if
(
amp01
.
is_open
())
{
cout
<<
"The data file "
<<
i
<<
"_"
<<
j
<<
" is opened..."
<<
std
::
endl
;
TH1D
*
h1
=
(
TH1D
*
)
gROOT
->
FindObject
(
"h1"
);
delete
h1
;
h1
=
new
TH1D
(
"h1"
,
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
std
::
stringstream
s
(
line
);
int
x
,
y
;
s
>>
x
>>
y
;
h1
->
Fill
(
x
,
y
);
}
hist_255
.
push_back
(
h1
);
amp01
.
clear
();
amp01
.
seekg
(
114
,
std
::
ios_base
::
beg
);
while
(
!
amp01
.
eof
())
{
amp01
>>
x
>>
y
;
hist_255
.
at
(
2
)
->
Fill
(
x
,
y
);
}
hist_255
.
at
(
2
)
->
Draw
(
"HIST SAME P"
);
}
else
{
}
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
cout
<<
"The size of the vector is :"
<<
hist_255
.
size
()
<<
std
::
endl
;
for
(
int
iamp
=
0
;
iamp
<
3
;
iamp
++
)
{
fit_1d
(
hist_255
.
at
(
iamp
),
colors
.
at
(
iamp
),
markers
.
at
(
iamp
),
iamp
,
fitmin
.
at
(
iamp
),
fitmax
.
at
(
iamp
));
// cout<<"The mean for amplitude 0 "<<iamp<<" "<<"is :"<<mean<<std::endl;
}
fit_1d
(
hist_255
.
at
(
amp
),
colors
.
at
(
amp
),
markers
.
at
(
amp
),
amp
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
));
}
TLegend
*
leg
=
new
TLegend
(
0.7
,
0.7
,
0.9
,
0.9
);
leg
->
AddEntry
(
hist_255
.
at
(
0
),
"high amplitude"
,
"p"
);
...
...
@@ -165,20 +110,39 @@ std::vector<TH1D*> gain_measurement(int i, int j)
void
gain_measurement
()
{
TH1D
*
hist_final
=
new
TH1D
(
"hist_final"
,
"Threshold gain measurements"
,
nbins
,
xmin
,
xmax
);
std
::
vector
<
TH1D
*>
histograms
;
int
row
,
col
;
THStack
*
hs
=
new
THStack
(
"hs"
,
"Gain measurements"
);
std
::
vector
<
std
::
vector
<
TH1D
*>>
histograms
;
// std::vector<TH1D*>histograms;
for
(
int
row
=
0
;
row
<
256
;
row
++
)
for
(
row
=
0
;
row
<
256
;
row
++
)
{
for
(
col
=
0
;
col
<
256
;
col
++
)
{
if
(
row
==
col
)
{
histograms
.
push_back
(
gain_measurement_pixel
(
row
,
col
));
//cout<<"the size of histogram vector is "<<histograms.size()<<std::endl;
}
}
}
// cout<<"the size of gain measurement vector is "<<gain_measurement_pixel<<std::endl;
cout
<<
"the size of histogram vector is "
<<
histograms
.
size
()
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
histograms
.
size
();
i
++
)
{
for
(
int
col
=
0
;
col
<
256
;
col
++
)
if
(
row
==
col
)
{
histograms
.
push_back
(
gain_measurement
(
row
,
col
));
for
(
int
i
=
0
;
i
<
histograms
.
size
();
++
i
)
{
hist_final
->
Fill
(
histograms
.
at
(
i
))
;
hist_final
->
Draw
();
}
}
auto
pixel_histograms
=
histograms
.
at
(
i
);
cout
<<
"Trying to stack the histograms for pixel "
<<
i
<<
"..."
<<
std
::
endl
;
for
(
int
j
=
0
;
j
<
pixel_histograms
.
size
();
j
++
)
{
hs
->
Add
(
pixel_histograms
.
at
(
j
));
}
}
cout
<<
"The histograms are added to the stack..."
<<
std
::
endl
;
//cout<<"the size of histogram vector is "<<histograms.size()<<std::endl;
hs
->
Draw
(
"HIST P nostack"
);
}
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