Skip to content
GitLab
Menu
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
326c4040
Commit
326c4040
authored
Jul 29, 2021
by
Keerthi Nakkalil
Browse files
Timewalk plots are made and fitted for one pixel
parent
d4b05e7a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Time walk correction/onepixel_tree.C
0 → 100644
View file @
326c4040
void
timewalkfit
(
TGraphErrors
*
graph
){
auto
fitmin
=
TMath
::
MinElement
(
graph
->
GetN
(),
graph
->
GetX
());
// std::cout << "fitmin" << fitmin << std::endl;
auto
fitmax
=
TMath
::
MaxElement
(
graph
->
GetN
(),
graph
->
GetX
());
// std::cout << "fitmax " << fitmax << std::endl;
TF1
*
fitfuncTOA
=
new
TF1
(
"fitfuncTOA"
,
"(([2]/(x-[0]))+ [1])"
,
fitmin
,
fitmax
);
fitfuncTOA
->
SetParNames
(
"asymtote"
,
"offset"
,
"curvature"
);
int
iymax
=
TMath
::
LocMax
(
graph
->
GetN
(),
graph
->
GetY
());
// cout << "iymax " << iymax << std::endl;
auto
ttoa
=
graph
->
GetPointX
(
iymax
);
// cout << "ttoa" << " " << ttoa << std::endl;;
fitfuncTOA
->
SetParameter
(
0
,
ttoa
);
auto
xmax
=
TMath
::
MaxElement
(
graph
->
GetN
(),
graph
->
GetX
());
auto
dtoa
=
graph
->
Eval
(
xmax
);
// cout << "dtoa" << " " << dtoa <<std::endl;
fitfuncTOA
->
SetParameter
(
1
,
dtoa
);
auto
testx
=
0
.
5
*
fitmax
;
auto
ctoa_y
=
graph
->
Eval
(
testx
);
auto
ctoa
=
(
ctoa_y
-
dtoa
)
*
(
testx
-
ttoa
);
// cout << "ctoa" << " " << ctoa <<std::endl;
fitfuncTOA
->
SetParameter
(
2
,
ctoa
);
gStyle
->
SetOptFit
(
1111
);
fitfuncTOA
->
SetLineColor
(
kRed
);
graph
->
Fit
(
fitfuncTOA
,
"R"
);
graph
->
GetXaxis
()
->
SetTitle
(
"Volatge[mV]"
);
graph
->
GetYaxis
()
->
SetTitle
(
"time difference[ns]"
);
graph
->
SetTitle
(
" "
);
graph
->
SetMarkerStyle
(
7
);
graph
->
Draw
(
"AP"
);
}
void
TreeEnergyWrite
(){
int
Ecol1
;
double
Ecol2
,
Ecol3
,
Ecol4
;
string
line_E
;
TFile
*
Efile
=
new
TFile
(
"Energy_table.root"
,
"recreate"
);
TTree
*
ETree
=
new
TTree
(
"ETree"
,
"Energy tree"
);
ETree
->
Branch
(
"Ecol1"
,
&
Ecol1
,
"Ecol1/I"
);
// ECol1 = Energy values = {200,300.....14000}
ETree
->
Branch
(
"Ecol4"
,
&
Ecol4
,
"Ecol4/D"
);
// Voltage values
std
::
ifstream
Energy_file
(
"Energy_table.dat"
);
if
(
Energy_file
.
is_open
()){
while
(
getline
(
Energy_file
,
line_E
)){
istringstream
ssE
(
line_E
);
ssE
>>
Ecol1
>>
Ecol2
>>
Ecol3
>>
Ecol4
;
ETree
->
Fill
();
}
}
ETree
->
Write
();
Efile
->
Close
();
}
void
TreeTPWrite
(){
int
energy
,
col
,
row
,
pc
;
double
voltage
,
tot
,
tot_var
,
toa
,
toa_var
,
time_ref
,
toa_cut
,
mean
,
RMS
;
string
line_TP
;
TFile
*
Efile
=
new
TFile
(
"Energy_table.root"
);
TTree
*
ETree
=
(
TTree
*
)
Efile
->
Get
(
"ETree"
);
ETree
->
SetBranchAddress
(
"Ecol1"
,
&
energy
);
ETree
->
SetBranchAddress
(
"Ecol4"
,
&
voltage
);
TFile
*
TPfile
=
new
TFile
(
"TP.root"
,
"update"
);
TTree
*
TPtree
=
new
TTree
(
"TPtree"
,
" TP tree"
);
TPtree
->
Branch
(
"col"
,
&
col
,
"col/I"
);
TPtree
->
Branch
(
"row"
,
&
row
,
"row/I"
);
TPtree
->
Branch
(
"pc"
,
&
pc
,
"pc/I"
);
TPtree
->
Branch
(
"tot"
,
&
tot
,
"tot/D"
);
TPtree
->
Branch
(
"tot_var"
,
&
tot_var
,
"tot_var/D"
);
TPtree
->
Branch
(
"toa"
,
&
toa
,
"toa/D"
);
TPtree
->
Branch
(
"toa_var"
,
&
toa_var
,
"toa_var/D"
);
TPtree
->
Branch
(
"time_ref"
,
&
time_ref
,
"time_ref/D"
);
auto
voltageBranch
=
TPtree
->
Branch
(
"voltage"
,
&
voltage
,
"voltage/D"
);
// make a new branch and connect it to the same variable as the branch address of the energy tree
auto
Branch_toacut
=
TPtree
->
Branch
(
"toa_cut"
,
&
toa_cut
,
"toa_cut/D"
);
for
(
int
i
=
0
;
i
<
ETree
->
GetEntries
();
i
++
){
ETree
->
GetEntry
(
i
);
// std:: cout << energy << " " << voltage << std::endl;
std
::
string
TPfilename
=
"tp_dat_"
+
std
::
to_string
(
energy
)
+
".dat"
;
//std:: cout << " The TPfilenames are : " << TPfilename.c_str() <<std::endl;
std
::
ifstream
TPdatafile
(
TPfilename
.
c_str
());
voltageBranch
->
Fill
();
if
(
TPdatafile
.
is_open
()){
std
::
cout
<<
" The data file "
<<
TPfilename
.
c_str
()
<<
" is opened ..."
<<
std
::
endl
;
// reading through individial tp_dat_ files
while
(
getline
(
TPdatafile
,
line_TP
)){
if
(
line_TP
.
rfind
(
"#"
,
0
)
==
0
)
{
continue
;
}
istringstream
ssTP
(
line_TP
);
ssTP
>>
col
>>
row
>>
pc
>>
tot
>>
tot_var
>>
toa
>>
toa_var
>>
time_ref
;
TPtree
->
Fill
();
}
//While loop getline
}
//if statement TPdatafile open
TPtree
->
Draw
(
"toa"
,
Form
(
"voltage==(%f)"
,
voltage
),
"goff"
);
mean
=
TMath
::
Mean
(
TPtree
->
GetSelectedRows
(),
TPtree
->
GetV1
());
RMS
=
TMath
::
RMS
(
TPtree
->
GetSelectedRows
(),
TPtree
->
GetV1
());
// std::cout <<" mean " << mean << " RMS " << RMS <<std::endl;
/* for (int isigma=0; isigma < 15; isigma++){
std::cout << " cut at " << isigma << " times the RMS leaves : "
<< 100.0*TPtree->GetEntries(Form("toa<(%f) && voltage==(%f)",mean+isigma*RMS,voltage))/TPtree->GetEntries(Form("voltage==(%f)",voltage))
<< " percentage of entries " << std::endl;
}*/
toa_cut
=
mean
+
6
*
RMS
;
Branch_toacut
->
Fill
();
}
//For loop GetEntries
//Save only the new version of the tree
TPtree
->
Write
(
""
,
TObject
::
kOverwrite
);
long
N
=
TPtree
->
Draw
(
"voltage:toa:sqrt(toa_var) "
,
"row==1 && col==10 && toa>0"
,
"goff"
);
TGraphErrors
*
gr
=
new
TGraphErrors
(
N
,
TPtree
->
GetV1
(),
TPtree
->
GetV2
(),
0
,
TPtree
->
GetV3
());
timewalkfit
(
gr
);
TPfile
->
Close
();
}
void
onepixel_tree
(){
TreeEnergyWrite
();
TreeTPWrite
();
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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