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

Fleshed out and tested. Switching to cmake as build system due to easier ROOT integration

This commit is contained in:
Gordon McCann 2022-06-01 09:31:39 -04:00
parent a2d6b9ffe4
commit 36790c94a3
9 changed files with 91 additions and 9 deletions

10
CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.14)
project(SabreCal)
find_package(ROOT REQUIRED Spectrum)
set(SABRECAL_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(SABRECAL_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(src)

32
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,32 @@
add_subdirectory(CalDict)
add_executable(SabreCal)
target_include_directories(SabreCal
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CalDict
SYSTEM PUBLIC ${ROOT_INCLUDE_DIRS}
)
target_sources(SabreCal PUBLIC
ChannelMap.h
ChannelMap.cpp
GainMatcher.h
GainMatcher.cpp
GainMap.h
GainMap.cpp
Calibrator.h
Calibrator.cpp
CalibrationMap.h
CalibrationMap.cpp
CalibrationStructs.h
DataOrganizer.h
DataOrganizer.cpp
main.cpp
)
target_link_libraries(SabreCal
CalDict
${ROOT_LIBRARIES}
)
set_target_properties(SabreCal PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${SABRECAL_BINARY_DIR}
)

View File

@ -0,0 +1,21 @@
add_library(CalDict SHARED)
target_include_directories(CalDict
PUBLIC ${CMAKE_CURRENT_SRC_DIR}
SYSTEM PUBLIC ${ROOT_INCLUDE_DIRS}
)
ROOT_GENERATE_DICTIONARY(cal_dict DataStructs.h
LINKDEF LinkDef_CalDict.h
MODULE CalDict
)
target_link_libraries(CalDict
${ROOT_LIBRARIES}
)
target_sources(CalDict PRIVATE DataStructs.cpp DataStructs.h)
set_target_properties(CalDict PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${SABRECAL_LIBRARY_DIR}
)
add_custom_command(TARGET CalDict POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/libCalDict_rdict.pcm
${SABRECAL_LIBRARY_DIR}/libCalDict_rdict.pcm
)

View File

@ -32,6 +32,12 @@ namespace SabreCal {
}
TTree* tree = (TTree*) input->Get("Data");
if(tree == nullptr)
{
std::cerr<<"ERR -- Unable to find tree Data at Calibrator::Run()"<<std::endl;
return;
}
uint16_t energy, board, channel;
tree->SetBranchAddress("Energy", &energy);
tree->SetBranchAddress("Board", &board);
@ -47,7 +53,7 @@ namespace SabreCal {
for(int i=0; i<s_totalChannels; i++)
{
std::string name = "channel"+std::to_string(i);
histograms.emplace_back(name.c_str(), name.c_str(), 16384, 0.0, 16384.0);
histograms.emplace_back(name.c_str(), name.c_str(), 4096, 0.0, 16384.0);
}
for(uint64_t i=0; i<nentries; i++)
@ -65,7 +71,7 @@ namespace SabreCal {
auto& params = m_gainMap.GetParameters(gchan);
if(energy > 100.0) //Reject electronic noise
histograms[i].Fill(params.slope*(energy*s_gainFactor) + params.offset);
histograms[gchan].Fill(params.slope*(energy*s_gainFactor) + params.offset);
}
std::cout<<std::endl;
input->Close();

View File

@ -27,7 +27,7 @@ namespace SabreCal {
GainMap m_gainMap;
std::vector<Parameters> m_params;
static constexpr int s_totalChannels = 127; //Total channels in SABRE
static constexpr int s_totalChannels = 128; //Total channels in SABRE
static constexpr double s_241Am_alphaKE = 5.468; //MeV
static constexpr double s_gainFactor = 1.5; //For if you're dumb and the electronics gain needs adjusted
};

View File

@ -14,6 +14,8 @@ namespace SabreCal {
Init(mapfile);
}
ChannelMap::~ChannelMap() {}
void ChannelMap::Init(const std::string& mapfile)
{
m_isValid = false;
@ -80,4 +82,4 @@ namespace SabreCal {
else
return -1;
}
}
}

View File

@ -69,11 +69,15 @@ namespace SabreCal {
//copy FP crap
outevent.xavg = inevent->xavg;
outevent.x1 = inevent->x1;
outevent.x2 = inevent->x2;
outevent.scintE = inevent->scintLeft;
outevent.cathodeE = inevent->cathode;
outevent.anodeFrontE = inevent->anodeFront;
outevent.anodeBackE = inevent->anodeBack;
outevent.scintT = inevent->scintLeftTime;
//Reset outevent SABRE data
outevent.sabre.clear();
for(int j=0; j<5; j++)
{
@ -139,6 +143,7 @@ namespace SabreCal {
}
}
}
std::sort(outevent.sabre.begin(), outevent.sabre.end(), [](const SabrePair& p1, const SabrePair& p2){ return p1.ringE > p2.ringE; });
outtree->Fill();
}
std::cout<<std::endl;
@ -155,7 +160,7 @@ namespace SabreCal {
std::cout<<"Total number of SABRE hits: "<<m_stats.totalSabreHits<<std::endl;
std::cout<<"Total number of good SABRE hits: "<<m_stats.goodSabreHits<<std::endl;
std::cout<<"Number of ring/wedge pairs made: "<<m_stats.pairsMade<<std::endl;
std::cout<<"Matching efficiency percentage: "<<((double)m_stats.pairsMade)/m_stats.goodSabreHits<<std::endl;
std::cout<<"Matching efficiency percentage: "<<((double)m_stats.pairsMade*2.0)/m_stats.goodSabreHits<<std::endl;
std::cout<<"Number of hits below threshold: "<<m_stats.sabreBelowThreshold<<std::endl;
std::cout<<"Number of wedge fragments: "<<m_stats.sabreWedgeFrags<<std::endl;
std::cout<<"Number of ring fragments: "<<m_stats.sabreRingFrags<<std::endl;

View File

@ -108,10 +108,10 @@ namespace SabreCal {
{
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] = new TGraph(m_data[i].x.size(), m_data[i].x.data(), m_data[i].y.data());
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+");
auto result = graph_array[i]->Fit("pol1","S|ROB|Q+");
m_params[i].slope = result->Parameter(1);
m_params[i].offset = result->Parameter(0);
}
@ -133,7 +133,7 @@ namespace SabreCal {
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+");
auto result = graph_array[i]->Fit("pol1","S|ROB|Q+");
m_params[i].slope = result->Parameter(1);
m_params[i].offset = result->Parameter(0);
}

View File

@ -38,7 +38,13 @@ int main(int argc, const char** argv)
option = argv[1];
}
std::ifstream input(argv[1]);
std::ifstream input(inputfile);
if(!input.is_open())
{
std::cerr<<"ERR -- Unable to open input config file "<<inputfile<<std::endl;
return 1;
}
std::string junk;
std::string gaindata, caldata, inputdata, outputdata;