1
0
Fork 0
mirror of https://github.com/gwm17/SabreCal.git synced 2024-11-22 18:18:52 -05:00

First commit

This commit is contained in:
Gordon McCann 2022-05-24 13:14:21 -04:00
commit 87c674d487
13 changed files with 1519 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
*.so
*.o
*.pcm
*.cxx
SabreCal
!.gitignore

View File

@ -0,0 +1,146 @@
Format: global_channel detectorID_number detectorType_identifier detectorPart_identifier
NOTE: the focal plane ionchamber is given the UNIQUE detector id of 11. All other detector id ranges should be 0 to nDetectors-1.
0 4 SABREWEDGE 0
1 4 SABREWEDGE 1
2 4 SABREWEDGE 2
3 4 SABREWEDGE 3
4 4 SABREWEDGE 4
5 4 SABREWEDGE 5
6 4 SABREWEDGE 6
7 4 SABREWEDGE 7
8 -1 UNUSED 0
9 -1 UNUSED 0
10 -1 UNUSED 0
11 -1 UNUSED 0
12 -1 UNUSED 0
13 -1 UNUSED 0
14 -1 UNUSED 0
15 -1 UNUSED 0
16 2 SABREWEDGE 0
17 2 SABREWEDGE 1
18 2 SABREWEDGE 2
19 2 SABREWEDGE 3
20 2 SABREWEDGE 4
21 2 SABREWEDGE 5
22 2 SABREWEDGE 6
23 2 SABREWEDGE 7
24 3 SABREWEDGE 0
25 3 SABREWEDGE 1
26 3 SABREWEDGE 2
27 3 SABREWEDGE 3
28 3 SABREWEDGE 4
29 3 SABREWEDGE 5
30 3 SABREWEDGE 6
31 3 SABREWEDGE 7
32 1 SABREWEDGE 0
33 1 SABREWEDGE 1
34 1 SABREWEDGE 2
35 1 SABREWEDGE 3
36 1 SABREWEDGE 4
37 1 SABREWEDGE 5
38 1 SABREWEDGE 6
39 1 SABREWEDGE 7
40 0 SABREWEDGE 0
41 0 SABREWEDGE 1
42 0 SABREWEDGE 2
43 0 SABREWEDGE 3
44 0 SABREWEDGE 4
45 0 SABREWEDGE 5
46 0 SABREWEDGE 6
47 0 SABREWEDGE 7
48 4 SABRERING 0
49 4 SABRERING 1
50 4 SABRERING 2
51 4 SABRERING 3
52 4 SABRERING 4
53 4 SABRERING 5
54 4 SABRERING 6
55 4 SABRERING 7
56 4 SABRERING 8
57 4 SABRERING 9
58 4 SABRERING 10
59 4 SABRERING 11
60 4 SABRERING 12
61 4 SABRERING 13
62 4 SABRERING 14
63 4 SABRERING 15
64 3 SABRERING 0
65 3 SABRERING 1
66 3 SABRERING 2
67 3 SABRERING 3
68 3 SABRERING 4
69 3 SABRERING 5
70 3 SABRERING 6
71 3 SABRERING 7
72 3 SABRERING 8
73 3 SABRERING 9
74 3 SABRERING 10
75 3 SABRERING 11
76 3 SABRERING 12
77 3 SABRERING 13
78 3 SABRERING 14
79 3 SABRERING 15
80 2 SABRERING 0
81 2 SABRERING 1
82 2 SABRERING 2
83 2 SABRERING 3
84 2 SABRERING 4
85 2 SABRERING 5
86 2 SABRERING 6
87 2 SABRERING 7
88 2 SABRERING 8
89 2 SABRERING 9
90 2 SABRERING 10
91 2 SABRERING 11
92 2 SABRERING 12
93 2 SABRERING 13
94 2 SABRERING 14
95 2 SABRERING 15
96 1 SABRERING 0
97 1 SABRERING 1
98 1 SABRERING 2
99 1 SABRERING 3
100 1 SABRERING 4
101 1 SABRERING 5
102 1 SABRERING 6
103 1 SABRERING 7
104 1 SABRERING 8
105 1 SABRERING 9
106 1 SABRERING 10
107 1 SABRERING 11
108 1 SABRERING 12
109 1 SABRERING 13
110 1 SABRERING 14
111 1 SABRERING 15
112 0 SABRERING 0
113 0 SABRERING 1
114 0 SABRERING 2
115 0 SABRERING 3
116 0 SABRERING 4
117 0 SABRERING 5
118 0 SABRERING 6
119 0 SABRERING 7
120 0 SABRERING 8
121 0 SABRERING 9
122 0 SABRERING 10
123 0 SABRERING 11
124 0 SABRERING 12
125 0 SABRERING 13
126 0 SABRERING 14
127 0 SABRERING 15
128 11 FOCALPLANE SCINTRIGHT
129 11 FOCALPLANE SCINTLEFT
130 -1 UNUSED 0
131 11 FOCALPLANE RF
132 -1 UNUSED 0
133 -1 UNUSED 0
134 -1 UNUSED 0
135 11 FOCALPLANE CATHODE
136 11 FOCALPLANE DELAYFL
137 11 FOCALPLANE DELAYFR
138 11 FOCALPLANE DELAYBL
139 11 FOCALPLANE DELAYBR
140 -1 UNUSED 0
141 11 FOCALPLANE ANODEFRONT
142 -1 UNUSED 0
143 11 FOCALPLANE ANODEBACK

114
premake5.lua Normal file
View File

@ -0,0 +1,114 @@
workspace "SabreCal"
architecture "x64"
configurations {
"Release",
"Debug"
}
ROOTIncludeDir = "/usr/include/root/"
ROOTLibDir = "/usr/lib64/root/"
project "CalDict"
kind "SharedLib"
language "C++"
cppdialect "c++11"
targetdir "./lib/"
objdir "./objs/"
prebuildcommands {
"rootcint -f src/CalDict/cal_dict.cxx src/CalDict/DataStructs.h src/CalDict/LinkDef_CalDict.h",
"{COPY} src/CalDict/*.pcm ./lib/"
}
postbuildcommands {
"{COPY} src/CalDict/DataStructs.h ./include/"
}
files {
"src/CalDict/DataStructs.h",
"src/CalDict/*.cpp",
"src/CalDict/*.cxx"
}
includedirs {
"./",
"src/CalDict",
}
sysincludedirs {
ROOTIncludeDir
}
libdirs {
ROOTLibDir
}
links {
"Gui", "Core", "Imt", "RIO", "Net", "Hist",
"Graf", "Graf3d", "Gpad", "ROOTDataFrame", "ROOTVecOps",
"Tree", "TreePlayer", "Rint", "Postscript", "Matrix",
"Physics", "MathCore", "Thread", "MultiProc", "m", "dl"
}
filter "system:macosx or linux"
linkoptions {
"-pthread",
"-rdynamic"
}
filter "configurations:Debug"
symbols "On"
filter "configurations:Release"
optimize "On"
project "SabreCal"
kind "ConsoleApp"
language "C++"
cppdialect "c++11"
targetdir "./bin/"
objdir "./objs/"
files {
"src/*.cpp",
"src/*.h",
"src/Detectors/*.cpp",
"src/Detectors/*.h",
"src/EnergyLoss/*.cpp",
"src/EnergyLoss/*.h",
"src/CalDict/*.h"
}
includedirs {
"src/",
"src/CalDict",
"src/Detectors",
"src/EnergyLoss"
}
sysincludedirs {
ROOTIncludeDir
}
libdirs {
ROOTLibDir,
}
links {
"CalDict", "Gui", "Core", "Imt", "RIO", "Net", "Hist",
"Graf", "Graf3d", "Gpad", "ROOTDataFrame", "ROOTVecOps",
"Tree", "TreePlayer", "Rint", "Postscript", "Matrix",
"Physics", "MathCore", "Thread", "MultiProc", "m", "dl"
}
filter "system:macosx or linux"
linkoptions {
"-pthread",
"-rdynamic"
}
filter "configurations:Debug"
symbols "On"
filter "configurations:Release"
optimize "On"

8
scal2.sublime-project Normal file
View File

@ -0,0 +1,8 @@
{
"folders":
[
{
"path": "."
}
]
}

769
scal2.sublime-workspace Normal file
View File

@ -0,0 +1,769 @@
{
"auto_complete":
{
"selected_items":
[
[
"tar",
"targ_z"
],
[
"cin",
"cstdint"
],
[
"m_eve",
"m_eventInit"
],
[
"resi",
"resid_vec"
],
[
"massDec",
"massDecayFrag"
],
[
"d",
"decayBreak_vec"
],
[
"massD",
"massDecayBreak"
],
[
"par",
"parent_vec"
],
[
"GetSabre",
"GetSabre4VectorEloss"
],
[
"resize",
"resizeColumnsToContents"
],
[
"syb",
"Symbol"
],
[
"if",
"ifmain"
],
[
"QTab",
"QTableWidget"
],
[
"fi",
"fitCanvas"
],
[
"outpu",
"output"
],
[
"Cal",
"CalculateRhoUncertainty"
],
[
"KE_eject_at",
"KE_eject_at_det"
],
[
"KE",
"KE_eject_at_det"
],
[
"myla",
"mylar_eff_thickness"
],
[
"e",
"mylar_eff_thickness"
],
[
"myl",
"mylar_s"
],
[
"MYL",
"MYLAR_THICKNESS"
],
[
"mylar",
"mylar_density"
],
[
"uex",
"uexInput"
],
[
"uxsy",
"uxsysInput"
],
[
"peak",
"peakKey"
],
[
"Sen",
"SendCalibrationPeak"
],
[
"upda",
"update_calibration"
],
[
"cali",
"calib_peaks"
],
[
"pe",
"peakName"
],
[
"Upd",
"UpdateReaction"
],
[
"poly",
"poly_order"
],
[
"y_",
"y_errors"
],
[
"x_",
"x_errors"
],
[
"Qu",
"QuadraticFit"
],
[
"x",
"x_data"
],
[
"y",
"y_errors"
],
[
"M",
"MAX_ITERS"
],
[
"chi",
"chi_lastmain"
],
[
"chisq",
"chisq"
],
[
"func",
"func_vals"
],
[
"st",
"student_resids"
],
[
"s",
"student_resids"
],
[
"sq",
"sq_diff"
],
[
"ures",
"uresid_array"
],
[
"resid",
"residualTable"
],
[
"ure",
"uresid_array"
],
[
"output",
"output"
],
[
"input",
"inputGroupBox"
],
[
"key",
"key"
],
[
"out",
"output_peaks"
],
[
"ft",
"fitTypeBox"
],
[
"uxstat",
"uxstat"
],
[
"calib",
"calib_peaks"
],
[
"reaction",
"reactionTable"
],
[
"l",
"layered_target"
],
[
"QTable",
"QTableWidgetItem"
],
[
"tabl",
"tableTab"
],
[
"ftab",
"ftableGroup"
],
[
"fitO",
"fitOptionLayout"
],
[
"fitOpti",
"fitOptionGroup"
],
[
"QD",
"QDoubleSpinBox"
],
[
"na",
"nameLabel"
],
[
"layer1",
"layer1GroupBox"
],
[
"layer1com",
"layer1ComponentsBox"
],
[
"layer",
"layer1compLayout"
],
[
"layer1comp",
"layer1compLayout"
],
[
"targe",
"targetNameBox"
],
[
"fwh",
"fwhm_x"
],
[
"fw",
"fwhm_Ex"
],
[
"Evalu",
"EvaluateFunction"
],
[
"Eva",
"EvaluateFunction"
],
[
"fit",
"fit_name"
],
[
"ux",
"ux_sys"
],
[
"cal",
"calib_peaks"
],
[
"ca",
"calib_peaks"
],
[
"Cu",
"CubicFunction"
],
[
"Line",
"LinearFunction"
],
[
"uf",
"ufwhm_x"
],
[
"Spanc",
"SpancFit"
],
[
"lin",
"linear_func"
],
[
"p_",
"p_project"
],
[
"p_ej",
"p_eject_at_rxn"
],
[
"p",
"p_project"
],
[
"BK",
"BKE_atRxn"
],
[
"GetE",
"GetEnergyLoss"
],
[
"B",
"BKE"
],
[
"K",
"KE_eject_at_det"
],
[
"KE_ej",
"KE_eject_at_det"
],
[
"Q",
"QBRHO2P"
],
[
"GetEje",
"GetEjectileKineticEnergyAtDet"
],
[
"GetRever",
"GetReverseEnergyLossTotal"
],
[
"GetEnergy",
"GetEnergyLossHalf"
],
[
"targetA",
"targetA"
],
[
"Hyd",
"HydrogenCoeff"
],
[
"Hy",
"HydrogenCoeff"
],
[
"conv",
"conversion_factor"
],
[
"i",
"i"
],
[
"xerr",
"xerr_array"
],
[
"energy",
"energyFlag"
],
[
"inp",
"inputNumberLayout"
],
[
"Levl",
"LevelDialog"
],
[
"re",
"reactionList"
],
[
"__",
"__init__"
],
[
"QDia",
"QDialog"
],
[
"react",
"reaction_params"
],
[
"reac",
"reaction_params"
],
[
"Reac",
"ReactionDialog"
],
[
"Re",
"ReadConfig"
],
[
"QDial",
"QDialogButtonBox"
],
[
"beam",
"beamKE"
],
[
"GetEJe",
"GetEjectileKineticEnergy"
],
[
"rho",
"rhoMin"
]
]
},
"buffers":
[
],
"build_system": "Packages/Python/Python.sublime-build",
"build_system_choices":
[
[
[
[
"Packages/Makefile/Make.sublime-build",
""
],
[
"Packages/Makefile/Make.sublime-build",
"Clean"
]
],
[
"Packages/Makefile/Make.sublime-build",
""
]
],
[
[
[
"Packages/Python/Python.sublime-build",
""
],
[
"Packages/Python/Python.sublime-build",
"Syntax Check"
]
],
[
"Packages/Python/Python.sublime-build",
"Syntax Check"
]
]
],
"build_varint": "",
"command_palette":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"console":
{
"height": 200.0,
"history":
[
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"expanded_folders":
[
"/home/gwm17/SabreCal2"
],
"file_history":
[
"/home/gwm17/SabreRecon2/premake5.lua",
"/home/gwm17/SabreRecon2/input.txt",
"/home/gwm17/SabreRecon2/src/CalDict/DataStructs.h",
"/home/gwm17/SabreRecon2/src/CutHandler.h",
"/home/gwm17/SabreRecon2/src/CutHandler.cpp",
"/home/gwm17/SabreRecon2/src/Reconstructor.h",
"/home/gwm17/SabreRecon2/src/RandomGenerator.cpp",
"/home/gwm17/SabreRecon2/src/RandomGenerator.h",
"/home/gwm17/SabreRecon2/src/Detectors/SabreDetector.cpp",
"/home/gwm17/SabreRecon/input.txt",
"/home/gwm17/SabreRecon2/src/Histogrammer.cpp",
"/home/gwm17/SabreRecon2/src/Histogrammer.h",
"/home/gwm17/SabreRecon2/src/Detectors/FocalPlaneDetector.cpp",
"/home/gwm17/SabreRecon2/src/Reconstructor.cpp",
"/home/gwm17/SabreRecon2/src/Detectors/FocalPlaneDetector.h",
"/home/gwm17/SabreRecon2/src/EnergyLoss/Target.h",
"/home/gwm17/SPS_SABRE_EventBuilder/premake5.lua",
"/home/gwm17/SabreRecon2/src/EnergyLoss/Target.cpp",
"/home/gwm17/SabreRecon2/src/Detectors/SabreDetector.h",
"/home/gwm17/SabreRecon2/src/CalDict/LinkDef_CalDict.h",
"/home/gwm17/SabreRecon2/src/CalDict/DataStructs.cpp",
"/home/gwm17/SabreRecon2/src/DataStructs.h",
"/home/gwm17/SabreRecon2/src/main.cpp",
"/home/gwm17/SabreRecon2/src/MassLookup.h",
"/home/gwm17/SabreRecon2/src/MassLookup.cpp",
"/home/gwm17/SabreRecon2/src/EnergyLoss/EnergyLoss.h",
"/home/gwm17/SabreRecon2/src/EnergyLoss/EnergyLoss.cpp",
"/home/gwm17/SabreRecon2/src/EnergyLoss/EnergyLossConstants.h",
"/home/gwm17/NucKage/src/RootPlotter.cpp",
"/home/gwm17/NucKage/src/RootPlotter.h",
"/home/gwm17/python_scripts/NavServer.py",
"/home/gwm17/spspy/fpcheck/NucData.py",
"/home/gwm17/spspy/fpcheck/Reaction.py",
"/home/gwm17/spspy/fpcheck/FPCheckGUI.py",
"/home/gwm17/spspy/spanc/SpancGUI.py",
"/home/gwm17/spspy/spsplot/SPSPlotGUI.py",
"/home/gwm17/spspy/spanc/Spanc.py",
"/home/gwm17/spspy/spanc/Reaction.py",
"/home/gwm17/spspy/spsplot/NucData.py",
"/home/gwm17/spspy/spanc/IngoFit.py",
"/home/gwm17/spspy/spanc/Fitter.py",
"/home/gwm17/spspy/README.md",
"/home/gwm17/spspy/.gitignore",
"/home/gwm17/spspy/spsplot/NuclearRxn.py",
"/home/gwm17/spspy/spsplot/SPSPlot.py",
"/home/gwm17/spspy/test_config.txt",
"/home/gwm17/spspy/spanc/LayeredTarget.py",
"/home/gwm17/spspy/spanc/EnergyLoss.py",
"/home/gwm17/Spanc_Redux/src/Reaction.cpp",
"/home/gwm17/Spanc_Redux/src/IngoFit.cpp",
"/home/gwm17/spspy/bin/spsplot",
"/home/gwm17/spspy/bin/spanc",
"/home/gwm17/Spanc_Redux/src/SpancRedux.cpp",
"/home/gwm17/spspy/spanc/EnergyLossData.py",
"/home/gwm17/Spanc_Redux/src/EnergyLoss.cpp",
"/home/gwm17/Spanc_Redux/include/SpancRedux.h",
"/home/gwm17/Spanc_Redux/src/TargetCreationFrame.cpp",
"/home/gwm17/Spanc_Redux/include/Reaction.h",
"/home/gwm17/Kinematics/src/LayeredTarget.cpp",
"/home/gwm17/Kinematics/src/Target.cpp",
"/home/gwm17/Kinematics/include/Target.h",
"/home/gwm17/Kinematics/include/LayeredTarget.h",
"/home/gwm17/Spanc_Redux/src/LayeredTarget.cpp",
"/home/gwm17/Spanc_Redux/include/LayeredTarget.h",
"/home/gwm17/Spanc_Redux/src/Target.cpp",
"/home/gwm17/Spanc_Redux/include/Target.h",
"/home/gwm17/Spanc_Redux/include/EnergyLoss.h",
"/home/gwm17/Spanc_Redux/tests/unittests.cpp",
"/home/gwm17/spspy/spanc/NucData.py",
"/home/gwm17/GWM_EventBuilder/etc/ChannelMap_March2020_newFormat_092020.txt",
"/home/gwm17/Spanc_Redux/include/Eloss_Tables.h",
"/home/gwm17/Spanc_Redux/include/IngoFit.h",
"/home/gwm17/spspy/SPSPlotGUI.py",
"/home/gwm17/spspy/SPSPlot.py",
"/home/gwm17/spspy/NuclearRxn.py",
"/home/gwm17/spspy/NucData.py",
"/home/gwm17/spspy/etc/mass.txt",
"/home/gwm17/Kinematics/src/Reaction.cpp",
"/home/gwm17/WiggleKiller/src/WiggleKiller.cpp"
],
"find":
{
"height": 70.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"Nucleus",
"setPrecision",
"layer1GroupBox",
"targetGroup",
"addLayout",
"H_RESTMASS",
"comp_denom",
"}",
"{",
"/*",
"print",
"energySwitch"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
"setDecimals",
"setLayout",
"]",
"["
],
"reverse": false,
"scrollbar_highlights": true,
"show_context": true,
"use_buffer2": true,
"use_gitignore": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 29.0
},
"input":
{
"height": 67.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.SublimeLinter":
{
"height": 138.0
},
"output.exec":
{
"height": 126.0
},
"output.find_results":
{
"height": 0.0
},
"output.mdpopups":
{
"height": 0.0
},
"output.unsaved_changes":
{
"height": 126.0
},
"pinned_build_system": "",
"project": "scal2.sublime-project",
"replace":
{
"height": 114.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_project":
{
"height": 500.0,
"last_filter": "",
"selected_items":
[
[
"",
"~/SPS_SABRE_EventBuilder/spsevb.sublime-project"
]
],
"width": 380.0
},
"select_symbol":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 237.0,
"status_bar_visible": true,
"template_settings":
{
}
}

View File

@ -0,0 +1,3 @@
#include "DataStructs.h"
bool EnforceDictionaryLinked() { return true; }

90
src/CalDict/DataStructs.h Normal file
View File

@ -0,0 +1,90 @@
#ifndef DATA_STRUCTS_H
#define DATA_STRUCTS_H
#include <vector>
struct DPPChannel
{
double Timestamp;
int Channel, Board, Energy, EnergyShort;
int Flags;
};
struct DetectorHit
{
double Long=-1, Short=-1, Time=-1;
int Ch=-1;
};
struct SabreDetector
{
std::vector<DetectorHit> rings;
std::vector<DetectorHit> wedges;
};
struct FPDetector
{
std::vector<DetectorHit> delayFL, delayFR, delayBL, delayBR;
std::vector<DetectorHit> anodeF, anodeB, scintL, scintR, cathode;
std::vector<DetectorHit> monitor;
};
struct CoincEvent
{
FPDetector focalPlane;
SabreDetector sabreArray[5]; //index = ChannelMap Id# -1
};
struct ProcessedEvent
{
double fp1_tdiff = -1e6, fp2_tdiff = -1e6, fp1_tsum = -1, fp2_tsum = -1,
fp1_tcheck = -1, fp2_tcheck = -1;
double fp1_y=-1, fp2_y=-1;
double anodeFront = -1, anodeBack = -1, scintRight = -1, scintLeft = -1;
double scintRightShort = -1, scintLeftShort = -1;
double cathode = -1;
double xavg = -1e6, x1 = -1e6, x2 = -1e6;
double theta = -1e6;
double sabreRingE[5] = {-1,-1,-1,-1,-1}, sabreWedgeE[5] = {-1,-1,-1,-1,-1};
double sabreRingChannel[5] = {-1,-1,-1,-1,-1}, sabreWedgeChannel[5] = {-1,-1,-1,-1,-1};
double sabreRingTime[5] = {-1,-1,-1,-1,-1}, sabreWedgeTime[5] = {-1,-1,-1,-1,-1};
double delayFrontRightE = -1, delayFrontLeftE = -1;
double delayBackRightE = -1, delayBackLeftE = -1;
double delayFrontRightShort = -1, delayFrontLeftShort = -1;
double delayBackRightShort = -1, delayBackLeftShort = -1;
double anodeFrontTime = -1, anodeBackTime = -1;
double scintRightTime = -1, scintLeftTime = -1;
double delayFrontMaxTime = -1, delayBackMaxTime = -1;
double delayFrontLeftTime = -1, delayFrontRightTime = -1;
double delayBackLeftTime = -1, delayBackRightTime = -1;
double cathodeTime = -1;
double monitorE = -1, monitorShort = -1;
double monitorTime = -1;
SabreDetector sabreArray[5]; //index = ChannelMap Id# -1
};
struct SabrePair
{
int ringch, wedgech; //global
int detID;
int local_ring, local_wedge; //local (obv.)
double ringE, wedgeE;
double ringT, wedgeT;
};
struct CalEvent
{
double xavg = -1e6, x1 = -1e6, x2 = -1e6;
double theta = -1, cathodeE = -1, scintE = -1;
double anodeFrontE = -1, anodeBackE = -1;
double scintT = -1;
std::vector<SabrePair> sabre;
};
bool EnforceDictionaryLinked();
#endif

View File

@ -0,0 +1,13 @@
#ifdef __ROOTCLING__
#pragma link C++ struct DPPChannel+;
#pragma link C++ struct DetectorHit+;
#pragma link C++ class std::vector<DetectorHit>+;
#pragma link C++ struct SabreDetector+;
#pragma link C++ struct FPDetector+;
#pragma link C++ struct CoincEvent+;
#pragma link C++ struct ProcessedEvent+;
#pragma link C++ struct SabrePair+;
#pragma link C++ struct CalEvent+;
#endif

24
src/CalibrationStructs.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef CALIBRATION_STRUCTS_H
#define CALIBRATION_STRUCTS_H
#include <vector>
#include <string>
namespace SabreCal {
struct Parameters
{
double slope = 0;
double offset = 0;
};
struct GraphData
{
std::vector<double> x;
std::vector<double> y;
std::string name = "";
std::string title = "";
};
}
#endif

83
src/ChannelMap.cpp Normal file
View File

@ -0,0 +1,83 @@
#include "ChannelMap.h"
#include <fstream>
namespace SabreCal {
ChannelMap::ChannelMap() :
m_isValid(false)
{
}
ChannelMap::ChannelMap(const std::string& mapfile) :
m_isValid(false)
{
Init(mapfile);
}
void ChannelMap::Init(const std::string& mapfile)
{
m_isValid = false;
std::ifstream input(mapfile);
std::string junk;
std::string rev_key;
Channel this_channel;
int gchan;
if(!input.is_open())
return;
std::getline(input, junk);
std::getline(input, junk);
while(input>>gchan)
{
input>>this_channel.detID>>junk>>this_channel.localChannel;
rev_key = std::to_string(this_channel.detID);
if(junk == "SABRERING")
{
this_channel.isRing = true;
this_channel.isWedge = false;
rev_key += "ring";
}
else if (junk == "SABREWEDGE")
{
this_channel.isRing = false;
this_channel.isWedge = true;
rev_key += "wedge";
}
else
continue;
m_map[gchan] = this_channel;
rev_key += std::to_string(this_channel.localChannel);
m_revmap[rev_key] = gchan;
}
m_isValid = true;
}
const Channel& ChannelMap::GetChannel(int gchan) const
{
auto iter = m_map.find(gchan);
if(iter != m_map.end())
return iter->second;
else
return m_dummy;
}
int ChannelMap::GetGlobalChannel(const Channel& channel) const
{
std::string key = std::to_string(channel.detID);
if(channel.isRing)
key += "ring";
else
key += "wedge";
key += std::to_string(channel.localChannel);
auto iter = m_revmap.find(key);
if(iter != m_revmap.end())
return iter->second;
else
return -1;
}
}

42
src/ChannelMap.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef CHANNEL_MAP_H
#define CHANNEL_MAP_H
#include <string>
#include <unordered_map>
namespace SabreCal {
struct Channel
{
Channel() {}
Channel(int id, bool ring, bool wedge, int local) :
detID(id), isRing(ring), isWedge(wedge), localChannel(local)
{}
int detID = -1;
bool isRing = false;
bool isWedge = false;
int localChannel = -1;
};
class ChannelMap
{
public:
ChannelMap();
ChannelMap(const std::string& mapfile);
~ChannelMap();
void Init(const std::string& mapfile);
const Channel& GetChannel(int gchan) const;
int GetGlobalChannel(const Channel& channel) const;
inline const bool IsValid() const { return m_isValid; }
private:
bool m_isValid;
std::unordered_map<int, Channel> m_map;
std::unordered_map<std::string, int> m_revmap; //ReverseMap takes string detID + ring/wedge + localChannel to global channel
Channel m_dummy; //for invalid results
};
}
#endif

182
src/GainMatcher.cpp Normal file
View File

@ -0,0 +1,182 @@
#include "GainMatcher.h"
#include "CalDict/DataStructs.h"
#include "TFile.h"
#include "TTree.h"
#include "TF1.h"
#include "TFitResult.h"
#include <iostream>
#include <fstream>
namespace SabreCal {
GainMatcher::GainMatcher(const std::string& mapfile, int ring_to_match, int wedge_to_match) :
m_map(mapfile), m_ringToFit(ring_to_match), m_wedgeToFit(wedge_to_match)
{
}
GainMatcher::~GainMatcher() {}
void GainMatcher::Run(const std::string& datafile, const std::string& outputfile, const std::string& graphfile)
{
if(!m_map.IsValid())
{
std::cerr<<"ERR -- GainMatcher::Run() ChannelMap is invalid."<<std::endl;
return;
}
TFile* input = TFile::Open(datafile.c_str(), "READ");
if(!input->IsOpen())
{
std::cerr<<"ERR -- GainMatcher::Run() data file is invalid."<<std::endl;
return;
}
ProcessedEvent* eventPtr = new ProcessedEvent();
TTree* tree = (TTree*) input->Get("SPSTree");
tree->SetBranchAddress("event", &eventPtr);
uint64_t nentries = tree->GetEntries();
uint64_t count=0, flushes=0;
float flush_percent = 0.1f;
uint64_t flush_val = flush_percent*nentries;
//start data loop
for(uint64_t i=0; i<nentries; i++)
{
tree->GetEntry(i);
count++;
if(count == flush_val)
{
count = 0;
flushes++;
std::cout<<"\rPercent of data processed: "<<flush_percent*flushes*100.0f<<"%"<<std::endl;
}
for(int j=0; j<5; j++)
{
SabreDetector& this_detector = eventPtr->sabreArray[j];
for(auto& ring : this_detector.rings)
{
auto& ringChannel = m_map.GetChannel(ring.Ch);
for(auto& wedge : this_detector.wedges)
{
auto& wedgeChannel = m_map.GetChannel(wedge.Ch);
if(ringChannel.localChannel == m_ringToFit && ring.Long > 200.0 && wedge.Long > 200.0)
{
m_data[wedge.Ch].x.push_back(wedge.Long);
m_data[wedge.Ch].y.push_back(ring.Long);
if(m_data[wedge.Ch].name == "")
{
m_data[wedge.Ch].name = "channel_"+std::to_string(wedge.Ch);
m_data[wedge.Ch].title = m_data[wedge.Ch].name + ";" + m_data[wedge.Ch].name + ";channel_"+std::to_string(ring.Ch);
}
}
if(wedgeChannel.localChannel == m_wedgeToFit && ring.Long > 200.0 && wedge.Long > 200.0)
{
m_data[ring.Ch].x.push_back(ring.Long);
m_data[ring.Ch].y.push_back(wedge.Long);
if(m_data[ring.Ch].name == "")
{
m_data[ring.Ch].name = "channel_"+std::to_string(ring.Ch);
m_data[ring.Ch].title = m_data[ring.Ch].name + ";" + m_data[ring.Ch].name + ";channel_"+std::to_string(wedge.Ch);
}
}
}
}
}
}
//data loop complete
std::cout<<std::endl;
std::cout<<"Matching..."<<std::endl;
DoMatching(graphfile);
std::cout<<"Writing results..."<<std::endl;
WriteParameters(outputfile);
input->Close();
}
void GainMatcher::DoMatching(const std::string& graphfile)
{
std::vector<TGraph*> graph_array;
graph_array.resize(m_totalChannels);
//Make all of the wedge graphs, and get the gain match parameters
for(size_t i=0; i<m_firstRing; i++)
{
if(m_data[i].x.size() != 0)
{
graph_array[i] = new TGraph(m_data[i].x.size(), &(m_data[i].x[0]), &(m_data[i].y[0]));
graph_array[i]->SetName(m_data[i].name.c_str());
graph_array[i]->SetTitle(m_data[i].title.c_str());
auto result = graph_array[i]->Fit("pol1","R|ROB|Q+");
m_params[i].slope = result->Parameter(1);
m_params[i].offset = result->Parameter(0);
}
else
graph_array[i] = nullptr;
}
//Now do rings, after applying parameters from wedges
for(size_t i=m_firstRing; i<m_totalChannels; i++)
{
if(m_data[i].x.size() != 0)
{
auto ringchan = m_map.GetChannel(i);
int wedge_gchan = m_map.GetGlobalChannel({ringchan.detID, false, true, m_wedgeToFit});
auto& params = m_params[wedge_gchan];
for(size_t j=0; j<m_data[i].y.size(); j++) //apply wedge results
m_data[i].y[j] = params.slope*m_data[i].y[j] + params.offset;
graph_array[i] = new TGraph(m_data[i].x.size(), &(m_data[i].x[0]), &(m_data[i].y[0]));
graph_array[i]->SetName(m_data[i].name.c_str());
graph_array[i]->SetTitle(m_data[i].title.c_str());
auto result = graph_array[i]->Fit("pol1","R|ROB|Q+");
m_params[i].slope = result->Parameter(1);
m_params[i].offset = result->Parameter(0);
}
else
graph_array[i] = nullptr;
}
if(graphfile != "")
WriteGraphs(graph_array, graphfile);
for(size_t i=0; i<graph_array.size(); i++)
delete graph_array[i];
}
void GainMatcher::WriteGraphs(const std::vector<TGraph*>& graphs, const std::string& graphfile)
{
TFile* graphout = TFile::Open(graphfile.c_str(), "RECREATE");
if(!graphout->IsOpen())
return;
for(auto graph : graphs)
{
if(graph)
graph->Write();
}
graphout->Close();
}
void GainMatcher::WriteParameters(const std::string& outputfile)
{
std::ofstream output(outputfile);
if(!output.is_open())
{
std::cerr<<"ERR -- Unable to write results at GainMatcher::WriteParameters() with filename "<<outputfile<<std::endl;
return;
}
output<<"Channel Slope Offset"<<std::endl;
for(size_t i=0; i<m_params.size(); i++)
output<<i<<" "<<m_params[i].slope<<" "<<m_params[i].offset<<std::endl;
output.close();
}
}

38
src/GainMatcher.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef GAIN_MATCHER_H
#define GAIN_MATCHER_H
#include <string>
#include <array>
#include "CalibrationStructs.h"
#include "ChannelMap.h"
#include "TGraph.h"
namespace SabreCal {
class GainMatcher
{
public:
GainMatcher(const std::string& mapfile, int ring_to_match, int wedge_to_match);
~GainMatcher();
void Run(const std::string& datafile, const std::string& outputfile, const std::string& graphfile="");
private:
void DoMatching(const std::string& graphfile);
void WriteGraphs(const std::vector<TGraph*>& graphs, const std::string& graphfile);
void WriteParameters(const std::string& outputfile);
ChannelMap m_map;
static constexpr int m_totalChannels = 128;
static constexpr int m_firstRing = 48; //Wedges are 0-47, rings 48-127
std::array<GraphData, m_totalChannels> m_data;
std::array<Parameters, m_totalChannels> m_params;
int m_ringToFit;
int m_wedgeToFit;
};
}
#endif