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
57e13019
Commit
57e13019
authored
Nov 27, 2020
by
Keerthi Nakkalil
Browse files
histograms are plotted using files, c arrays removed completly and std::vectors are used instead.
parent
43bfa9d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
gain_measurement.cpp
View file @
57e13019
/*defining global variables*/
int
nbins
=
450
;
double
xmin
=
850.0
,
xmax
=
1750.0
;
std
::
vector
<
TH1D
*>
hist_255
;
std
::
vector
<
int
>
colors
=
{
kAzure
,
kRed
,
kViolet
};
std
::
vector
<
int
>
markers
=
{
2
,
3
,
5
};
std
::
vector
<
double
>
fitmin
=
{
1220.
,
1200.
,
1150.
};
std
::
vector
<
double
>
fitmax
=
{
1700.
,
1420.
,
1240.
};
/////////////////////////////////////////////////////////////
// The function fit_1d sets the cosmetics for the histograms/
// and fits the histogram with modified erf function. /
/////////////////////////////////////////////////////////////
TH1D
*
fit_1d
(
TH1D
*
&
hist_255
.
at
(
amp
)
,
int
&
colors
.
at
(
amp
)
,
int
&
markers
.
at
(
amp
)
,
int
amplitude
,
double
&
fitmin
.
at
(
amp
)
,
double
&
fitmax
.
at
(
amp
)
)
TH1D
*
fit_1d
(
TH1D
*
&
hist_255
,
int
colors
,
int
markers
,
int
&
amplitude
,
double
fitmin
,
double
fitmax
)
{
hist_255
.
at
(
amp
)
->
GetXaxis
()
->
SetTitle
(
"Threshold"
);
hist_255
.
at
(
amp
)
->
GetYaxis
()
->
SetTitle
(
"# s
u
gnals above the threshold"
);
hist_255
.
at
(
amp
)
->
SetMarkerColor
(
colors
.
at
(
amp
)
);
hist_255
.
at
(
amp
)
->
SetMarkerStyle
(
markers
.
at
(
amp
)
);
hist_255
->
GetXaxis
()
->
SetTitle
(
"Threshold"
);
hist_255
->
GetYaxis
()
->
SetTitle
(
"# s
i
gnals above the threshold"
);
hist_255
->
SetMarkerColor
(
colors
);
hist_255
->
SetMarkerStyle
(
markers
);
TF1
*
fitfunc
=
new
TF1
(
"fitfunc"
,
"([0]/2)*(1-TMath::Erf((x-[1])/(sqrt(2)*[2])))"
,
fitmin
.
at
(
amp
),
fitmax
.
at
(
amp
)
);
TF1
*
fitfunc
=
new
TF1
(
"fitfunc"
,
"([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
;
...
...
@@ -36,14 +22,13 @@ TH1D *fit_1d(TH1D* &hist_255.at(amp),int &colors.at(amp),int &markers.at(amp),in
//Assigning Initial values to the parameters
fitfunc
->
SetParameter
(
0
,
200.0
);
int
lastbin1
=
hist_255
.
at
(
amp
)
->
FindLastBinAbove
(
200
);
double
mean
=
hist_255
.
at
(
amp
)
->
GetBinCenter
(
lastbin1
);
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
;
fitfunc
->
SetParameter
(
1
,
mean
);
int
lastbin2
=
hist_255
.
at
(
amp
)
->
FindLastBinAbove
(
150
);
int
lastbin3
=
hist_255
.
at
(
amp
)
->
FindLastBinAbove
(
50
);
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
;
fitfunc
->
SetParameter
(
2
,
sigma
);
...
...
@@ -51,11 +36,10 @@ TH1D *fit_1d(TH1D* &hist_255.at(amp),int &colors.at(amp),int &markers.at(amp),in
fitfunc
->
SetLineWidth
(
2
);
fitfunc
->
SetLineColor
(
2
);
hist_255
.
at
(
amp
)
->
Fit
(
"fitfunc"
,
" R"
);
hist_255
.
at
(
amp
)
->
GetListOfFunctions
()
->
FindObject
(
"fitfunc"
)
->
Draw
(
"same"
);
hist_255
.
at
(
amp
)
->
SetStats
(
0
);
return
hist_255
.
at
(
amp
);
hist_255
->
Fit
(
"fitfunc"
,
" R"
);
hist_255
->
GetListOfFunctions
()
->
FindObject
(
"fitfunc"
)
->
Draw
(
"same"
);
hist_255
->
SetStats
(
0
);
return
hist_255
;
}
...
...
@@ -63,38 +47,92 @@ TH1D *fit_1d(TH1D* &hist_255.at(amp),int &colors.at(amp),int &markers.at(amp),in
void
gain_6
()
{
TTree
*
tree1
=
new
TTree
(
"tree1"
,
"tree1"
);
TTree
*
tree2
=
new
TTree
(
"tree2"
,
"tree2"
);
TTree
*
tree3
=
new
TTree
(
"tree3"
,
"tree3"
);
cout
<<
"The trees are created..."
<<
std
::
endl
;
int
x
,
y
,
nbins
=
450
;
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
;
/*Reading data from the files are storing into trees*/
amp03
.
open
(
"amp03_255_255.dat"
);
amp02
.
open
(
"amp02_255_255.dat"
);
amp01
.
open
(
"amp01_255_255.dat"
);
tree1
->
ReadFile
(
"amp03_255_255.dat"
,
"x/D:y/D"
);
tree2
->
ReadFile
(
"amp02_255_255.dat"
,
"x/D:y/D"
);
tree3
->
ReadFile
(
"amp01_255_255.dat"
,
"x/D:y/D"
);
cout
<<
"The data is stored into the trees from the file..."
<<
std
::
endl
;
if
(
amp03
.
is_open
())
{
cout
<<
"The data file 255_255 is opened..."
<<
std
::
endl
;
TH1D
*
h3
=
new
TH1D
(
"h3"
,
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
hist_255
.
push_back
(
h3
);
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
;
}
TH1D
*
hist1
=
hist_255
.
at
(
0
);
TH1D
*
hist2
=
hist_255
.
at
(
1
);
TH1D
*
hist3
=
hist_255
.
at
(
2
);
if
(
amp02
.
is_open
())
{
cout
<<
"The data file 255_255 is opened..."
<<
std
::
endl
;
TH1D
*
h2
=
new
TH1D
(
"h2"
,
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
hist_255
.
push_back
(
h2
);
while
(
!
amp02
.
eof
())
{
amp02
>>
x
>>
y
;
hist_255
.
at
(
1
)
->
Fill
(
x
,
y
);
}
hist_255
.
at
(
1
)
->
Draw
(
"HIST SAME P"
);
}
tree1
->
Draw
(
"x>>hist1"
,
"y"
,
"HIST P "
);
tree2
->
Draw
(
"x>>hist2"
,
"y"
,
"HIST SAME P "
);
tree3
->
Draw
(
"x>>hist3"
,
"y"
,
"HIST SAME P "
);
cout
<<
"The histograms are plotted.."
<<
std
::
endl
;
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
if
(
amp01
.
is_open
())
{
cout
<<
"The data file 255_255 is opened..."
<<
std
::
endl
;
TH1D
*
h1
=
new
TH1D
(
"h1"
,
"Threshold gain measurement"
,
nbins
,
xmin
,
xmax
);
hist_255
.
push_back
(
h1
);
while
(
!
amp01
.
eof
())
{
amp01
>>
x
>>
y
;
hist_255
.
at
(
2
)
->
Fill
(
x
,
y
);
}
hist_255
.
at
(
2
)
->
Draw
(
"HIST SAME P"
);
}
else
{
cout
<<
"Error opening file. Exit."
<<
std
::
endl
;
}
cout
<<
"The size of the vector is :"
<<
hist_255
.
size
()
<<
std
::
endl
;
hist_255
.
push_back
(
hist1
);
hist_255
.
push_back
(
hist2
);
hist_255
.
push_back
(
hist3
);
for
(
int
iamp
=
0
;
iamp
<
3
;
iamp
++
)
{
fit_1d
(
hist_255
.
at
(
iamp
),
colors
.
at
(
iamp
),
markers
.
at
(
iamp
),
fitmin
.
at
(
iamp
),
fitmax
.
at
(
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;
}
TLegend
*
leg
=
new
TLegend
(
0.7
,
0.7
,
0.9
,
0.9
);
leg
->
AddEntry
(
hist_255
.
at
(
0
),
"high amplitude"
,
"p"
);
leg
->
AddEntry
(
hist_255
.
at
(
1
),
"mid amplitude"
,
"p"
);
leg
->
AddEntry
(
hist_255
.
at
(
2
),
"low amplitude"
,
"p"
);
leg
->
Draw
();
cout
<<
"Done..."
<<
std
::
endl
;
}
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