diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4578129 --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..72c1f86 --- /dev/null +++ b/src/CMakeLists.txt @@ -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} + ) + diff --git a/src/CalDict/CMakeLists.txt b/src/CalDict/CMakeLists.txt new file mode 100644 index 0000000..596b0de --- /dev/null +++ b/src/CalDict/CMakeLists.txt @@ -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 + ) diff --git a/src/Calibrator.cpp b/src/Calibrator.cpp index 945094c..4ec6852 100644 --- a/src/Calibrator.cpp +++ b/src/Calibrator.cpp @@ -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()"<SetBranchAddress("Energy", &energy); tree->SetBranchAddress("Board", &board); @@ -47,7 +53,7 @@ namespace SabreCal { for(int i=0; i 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<Close(); diff --git a/src/Calibrator.h b/src/Calibrator.h index 09bd752..6db24fe 100644 --- a/src/Calibrator.h +++ b/src/Calibrator.h @@ -27,7 +27,7 @@ namespace SabreCal { GainMap m_gainMap; std::vector 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 }; diff --git a/src/ChannelMap.cpp b/src/ChannelMap.cpp index 90ea8a4..74e7325 100644 --- a/src/ChannelMap.cpp +++ b/src/ChannelMap.cpp @@ -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; } -} \ No newline at end of file +} diff --git a/src/DataOrganizer.cpp b/src/DataOrganizer.cpp index ed0c3f2..3591397 100644 --- a/src/DataOrganizer.cpp +++ b/src/DataOrganizer.cpp @@ -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<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); } diff --git a/src/main.cpp b/src/main.cpp index e7c7981..d228faa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 "<