MUSIC
unknown
Analysis for the MUSIC active-target ionization chamber
Toggle main menu visibility
Loading...
Searching...
No Matches
Normalization.cpp
Go to the documentation of this file.
1
#include "
Normalization.hpp
"
2
#include <TFile.h>
3
4
Bool_t
EnergyView::Attach
(TTree *t) {
5
tree_
= t;
6
t->SetBranchAddress(
"Left_0_17_dE"
,
left_0_17_adc
);
7
t->SetBranchAddress(
"RightdE"
,
rightdE_adc
);
8
t->SetBranchAddress(
"Hits"
,
hits_adc
);
9
t->SetBranchAddress(
"Cathode"
, &
cathode_adc
);
10
t->SetBranchAddress(
"Grid"
, &
grid_adc
);
11
// Materialize the first tree so GetCurrentFile() resolves for a TChain (it is
12
// null until a tree is loaded); this makes is_normed correct right after
13
// Attach.
14
t->LoadTree(0);
15
LoadGains
();
16
loaded_tree_
= t->GetTreeNumber();
17
return
is_normed
;
18
}
19
20
void
EnergyView::LoadGains
() {
21
for
(Int_t s = 0; s < 18; s++) {
22
gain_left
[s] = 0.0f;
23
gain_right
[s] = 0.0f;
24
strip_factor
[s] = 1.0f;
25
}
26
gain_cathode
= 0.0f;
27
is_normed
= kFALSE;
28
if
(!
tree_
)
29
return
;
30
TFile *f =
tree_
->GetCurrentFile();
31
if
(!f)
32
return
;
33
TTree *cal =
static_cast<
TTree *
>
(f->Get(
"calibration"
));
34
if
(!cal || cal->GetEntries() < 1)
35
return
;
36
Float_t gl[18] = {0}, gr[18] = {0}, gc = 0.0f;
37
Float_t sf[18] = {0};
38
cal->SetBranchAddress(
"GainLeft"
, gl);
39
cal->SetBranchAddress(
"GainRight"
, gr);
40
cal->SetBranchAddress(
"GainCathode"
, &gc);
41
// StripFactor is optional (added after the initial per-channel gain write,
42
// filled in by FindStripCentroidAlignment on the second write). When absent
43
// the default factor = 1.0 (identity) is used.
44
Bool_t has_factor = cal->GetBranch(
"StripFactor"
) !=
nullptr
;
45
if
(has_factor)
46
cal->SetBranchAddress(
"StripFactor"
, sf);
47
cal->GetEntry(0);
48
for
(Int_t s = 0; s < 18; s++) {
49
gain_left
[s] = gl[s];
50
gain_right
[s] = gr[s];
51
if
(has_factor)
52
strip_factor
[s] = sf[s];
53
}
54
gain_cathode
= gc;
55
is_normed
= kTRUE;
56
}
57
58
void
EnergyView::Decode
() {
59
// A TChain advances fTreeNumber when GetEntry crosses into a new subfile;
60
// reload that file's gains when it does. Plain TTrees report -1 forever, so
61
// this never re-fires for them (gains already loaded in Attach).
62
if
(
tree_
) {
63
Int_t tn =
tree_
->GetTreeNumber();
64
if
(tn !=
loaded_tree_
) {
65
LoadGains
();
66
loaded_tree_
= tn;
67
}
68
}
69
if
(
is_normed
) {
70
for
(Int_t s = 0; s < 18; s++) {
71
left
[s] = Double_t(
gain_left
[s]) * Double_t(
left_0_17_adc
[s]);
72
right
[s] = Double_t(
gain_right
[s]) * Double_t(
rightdE_adc
[s]);
73
total
[s] =
left
[s] +
right
[s];
74
}
75
// Guard the -1 "no cathode" sentinel: uncalibrated/absent -> 0 a.u.
76
cathode
= (
cathode_adc
> 0) ? Double_t(
gain_cathode
) * Double_t(
cathode_adc
)
77
: 0.0;
78
// Grid has no calibration gain; normalize to [0, 1] by dividing by max ADC.
79
grid
= Double_t(
grid_adc
) / 16384.0;
80
}
else
{
81
for
(Int_t s = 0; s < 18; s++) {
82
left
[s] = Double_t(
left_0_17_adc
[s]);
83
right
[s] = Double_t(
rightdE_adc
[s]);
84
total
[s] =
left
[s] +
right
[s];
85
}
86
cathode
= Double_t(
cathode_adc
);
87
grid
= Double_t(
grid_adc
);
88
}
89
if
(
Constants::cfg
.IGNORE_SHORT_STRIPS) {
90
for
(Int_t s = 1; s <= 16; s++) {
91
if
((s % 2) != 0) {
92
total
[s] =
left
[s];
93
right
[s] = 0.0;
94
}
else
{
95
total
[s] =
right
[s];
96
left
[s] = 0.0;
97
}
98
}
99
}
100
// Apply per-strip multiplicative alignment factors (notebook approach).
101
// This pulls each strip's beam-peak centroid onto the pol3 reference trend
102
// and is applied after per-channel gain and IGNORE_SHORT_STRIPS.
103
if
(
is_normed
) {
104
for
(Int_t s = 0; s <= 17; s++) {
105
total
[s] *= Double_t(
strip_factor
[s]);
106
}
107
}
108
}
109
110
const
char
*
EnergyView::Unit
()
const
{
return
is_normed
?
"a.u."
:
"ADC"
; }
Normalization.hpp
Constants::cfg
const DatasetConfig & cfg
The active dataset's configuration, flat block.
EnergyView::tree_
TTree * tree_
Events tree or chain bound by Attach(). Not owned.
Definition
Normalization.hpp:50
EnergyView::Decode
void Decode()
Decode the currently loaded entry into the value members.
Definition
Normalization.cpp:58
EnergyView::rightdE_adc
UShort_t rightdE_adc[18]
Raw right-side strip ADC values.
Definition
Normalization.hpp:23
EnergyView::cathode_adc
Short_t cathode_adc
Raw cathode ADC value.
Definition
Normalization.hpp:25
EnergyView::LoadGains
void LoadGains()
Load the calibration gains for the current file.
Definition
Normalization.cpp:20
EnergyView::gain_left
Float_t gain_left[18]
Per-strip left-side gain.
Definition
Normalization.hpp:28
EnergyView::loaded_tree_
Int_t loaded_tree_
Tree number whose gains are loaded; -1 for none.
Definition
Normalization.hpp:51
EnergyView::Attach
Bool_t Attach(TTree *t)
Bind to an events tree and set up the branch addresses.
Definition
Normalization.cpp:4
EnergyView::total
Double_t total[18]
Summed energy per strip, after strip_factor.
Definition
Normalization.hpp:45
EnergyView::strip_factor
Float_t strip_factor[18]
Per-strip multiplicative alignment, pol3_reference / centroid, applied to total after the per-channel...
Definition
Normalization.hpp:38
EnergyView::is_normed
Bool_t is_normed
Whether a calibration tree was found.
Definition
Normalization.hpp:33
EnergyView::Unit
const char * Unit() const
Unit label for the decoded values, for axis titles.
Definition
Normalization.cpp:110
EnergyView::right
Double_t right[18]
Right-side energy per strip.
Definition
Normalization.hpp:44
EnergyView::left_0_17_adc
UShort_t left_0_17_adc[18]
Raw left-side strip ADC values.
Definition
Normalization.hpp:22
EnergyView::gain_right
Float_t gain_right[18]
Per-strip right-side gain.
Definition
Normalization.hpp:29
EnergyView::left
Double_t left[18]
Left-side energy per strip.
Definition
Normalization.hpp:43
EnergyView::grid_adc
Short_t grid_adc
Raw Frisch grid ADC value.
Definition
Normalization.hpp:26
EnergyView::gain_cathode
Float_t gain_cathode
Cathode gain.
Definition
Normalization.hpp:30
EnergyView::hits_adc
UShort_t hits_adc[36]
Raw per-slot hit ADC values.
Definition
Normalization.hpp:24
EnergyView::grid
Double_t grid
Grid energy.
Definition
Normalization.hpp:47
EnergyView::cathode
Double_t cathode
Cathode energy.
Definition
Normalization.hpp:46
tooling
src
Normalization.cpp
Generated by
1.17.0