-
Notifications
You must be signed in to change notification settings - Fork 58
CRT Offline - Calib #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bear-is-asleep
merged 1 commit into
feature/hlay_crt_offline_pr
from
feature/hlay_crt_offline_calib
Sep 26, 2024
Merged
CRT Offline - Calib #502
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| install_fhicl() | ||
|
|
||
| add_subdirectory(CalibService) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| install_headers() | ||
| install_fhicl() | ||
| install_source() | ||
|
|
||
| file(GLOB calib_values_crt *.txt) | ||
| install_fw( LIST ${calib_values_crt} ) | ||
|
|
||
| art_make(SERVICE_LIBRARIES | ||
| art::Framework_Services_Registry | ||
| art::Framework_Principal | ||
| art::Framework_Core | ||
| art::Persistency_Provenance | ||
| messagefacility::MF_MessageLogger | ||
| ROOT::Core | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // Class: SBND::CRTCalibService | ||
| // Module type: service | ||
| // File: CRTCalibService.h | ||
| // Author: Henry Lay, May 2024 | ||
| // | ||
| // Service for inputing CRT calibration values to reconstruction | ||
| /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #ifndef SBNDCRTCalibService_H | ||
| #define SBNDCRTCalibService_H | ||
|
|
||
| #include <unordered_map> | ||
| #include <vector> | ||
| #include <string> | ||
|
|
||
| #include "fhiclcpp/ParameterSet.h" | ||
| #include "art/Framework/Core/ModuleMacros.h" | ||
| #include "art/Framework/Services/Registry/ServiceMacros.h" | ||
|
|
||
| namespace SBND { | ||
| class CRTCalibService; | ||
| } | ||
|
|
||
|
|
||
| class SBND::CRTCalibService { | ||
|
|
||
| public: | ||
|
|
||
| CRTCalibService(fhicl::ParameterSet const& pset); | ||
| CRTCalibService(fhicl::ParameterSet const& pset, art::ActivityRegistry&); | ||
|
|
||
| double GetTimingOffsetFromFEBMAC5(unsigned int feb_mac5) const; | ||
|
|
||
| double GetPedestalFromFEBMAC5AndChannel(unsigned int feb_mac5, unsigned int ch) const; | ||
|
|
||
| private: | ||
|
|
||
| std::unordered_map<unsigned int, double> fTimingOffsetFromFEBMAC5; | ||
|
|
||
| std::unordered_map<unsigned int, std::unordered_map<unsigned int, double>> fPedestalFromFEBMAC5AndChannel; | ||
|
|
||
| }; | ||
|
|
||
| DECLARE_ART_SERVICE(SBND::CRTCalibService, LEGACY) | ||
|
|
||
| #endif |
128 changes: 128 additions & 0 deletions
128
sbndcode/Calibration/CRT/CalibService/CRTCalibService_service.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| ////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // Class: SBND::CRTCalibService | ||
| // Module type: service | ||
| // File: SBND::CRTCalibService_service.cc | ||
| // Author: Henry Lay, May 2024. | ||
| // | ||
| // Implementation of service for inputing CRT calibration values to reconstruction | ||
| /////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #include <iostream> | ||
| #include <fstream> | ||
| #include <sstream> | ||
| #include <stdlib.h> | ||
|
|
||
| #include "CRTCalibService.h" | ||
| #include "messagefacility/MessageLogger/MessageLogger.h" | ||
|
|
||
| SBND::CRTCalibService::CRTCalibService(fhicl::ParameterSet const& pset) | ||
| { | ||
| const std::string timingOffsetFile = pset.get<std::string>("TimingOffsetFileName"); | ||
| const std::string pedestalFile = pset.get<std::string>("PedestalFileName"); | ||
|
|
||
| std::string timingOffsetPath, pedestalPath; | ||
| cet::search_path sp("FW_SEARCH_PATH"); | ||
| sp.find_file(timingOffsetFile, timingOffsetPath); | ||
| sp.find_file(pedestalFile, pedestalPath); | ||
|
|
||
| if(timingOffsetPath.empty()) | ||
| { | ||
| std::cout << "SBND::CRTCalibService Input file " << timingOffsetFile << " not found" << std::endl; | ||
| throw cet::exception("File not found"); | ||
| } | ||
|
|
||
| if(pedestalPath.empty()) | ||
| { | ||
| std::cout << "SBND::CRTCalibService Input file " << pedestalFile << " not found" << std::endl; | ||
| throw cet::exception("File not found"); | ||
| } | ||
|
|
||
| std::cout << "SBND CRT Channel Map: Building map from files...\n" | ||
| << "\t Timing Offsets: " << timingOffsetFile << '\n' | ||
| << "\t Pedestals: " << pedestalFile << std::endl; | ||
|
|
||
| std::ifstream timingOffsetStream(timingOffsetPath, std::ios::in); | ||
| std::string line; | ||
|
|
||
| while(std::getline(timingOffsetStream, line)) | ||
| { | ||
| std::stringstream linestream(line); | ||
|
|
||
| unsigned int mac5, offset; | ||
| linestream | ||
| >> mac5 | ||
| >> offset; | ||
|
|
||
| fTimingOffsetFromFEBMAC5[mac5] = offset; | ||
| } | ||
|
|
||
| timingOffsetStream.close(); | ||
|
|
||
| std::ifstream pedestalStream(pedestalPath, std::ios::in); | ||
|
|
||
| while(std::getline(pedestalStream, line)) | ||
| { | ||
| std::stringstream linestream(line); | ||
|
|
||
| unsigned int mac5, ch, pedestal; | ||
| linestream | ||
| >> mac5 | ||
| >> ch | ||
| >> pedestal; | ||
|
|
||
| fPedestalFromFEBMAC5AndChannel[mac5][ch] = pedestal; | ||
| } | ||
|
|
||
| pedestalStream.close(); | ||
| } | ||
|
|
||
| SBND::CRTCalibService::CRTCalibService(fhicl::ParameterSet const& pset, art::ActivityRegistry&) | ||
| : SBND::CRTCalibService(pset) | ||
| { | ||
| } | ||
|
|
||
| double SBND::CRTCalibService::GetTimingOffsetFromFEBMAC5(unsigned int feb_mac5) const | ||
| { | ||
| auto iter = fTimingOffsetFromFEBMAC5.find(feb_mac5); | ||
|
|
||
| if(iter == fTimingOffsetFromFEBMAC5.end()) | ||
| { | ||
| mf::LogInfo("SBND CRT Calibration Service") << "Asked for FEB with MAC5: " << feb_mac5 << '\n' | ||
| << "This FEB does not appear in the channel map." | ||
| << std::endl; | ||
|
|
||
| return 0.; | ||
| } | ||
|
|
||
| return iter->second; | ||
| } | ||
|
|
||
| double SBND::CRTCalibService::GetPedestalFromFEBMAC5AndChannel(unsigned int feb_mac5, unsigned int ch) const | ||
| { | ||
| auto iter = fPedestalFromFEBMAC5AndChannel.find(feb_mac5); | ||
|
|
||
| if(iter == fPedestalFromFEBMAC5AndChannel.end()) | ||
| { | ||
| mf::LogInfo("SBND CRT Calibration Service") << "Asked for FEB with MAC5: " << feb_mac5 << '\n' | ||
| << "This FEB does not appear in the calibration service." | ||
| << std::endl; | ||
|
|
||
| return 0.; | ||
| } | ||
|
|
||
| auto subIter = iter->second.find(ch); | ||
|
|
||
| if(subIter == iter->second.end()) | ||
| { | ||
| mf::LogInfo("SBND CRT Calibration Service") << "Asked for channel: " << ch << '\n' | ||
| << "in FEB with MAC5: " << feb_mac5 << '\n' | ||
| << "This channel does not appear in the calibration service." | ||
| << std::endl; | ||
|
|
||
| return 0.; | ||
| } | ||
|
|
||
| return subIter->second; | ||
| } | ||
|
|
||
| DEFINE_ART_SERVICE(SBND::CRTCalibService) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.