|
| 1 | +////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | +// Class: SBND::CRTCalibService |
| 3 | +// Module type: service |
| 4 | +// File: SBND::CRTCalibService_service.cc |
| 5 | +// Author: Henry Lay, May 2024. |
| 6 | +// |
| 7 | +// Implementation of service for inputing CRT calibration values to reconstruction |
| 8 | +/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +#include <iostream> |
| 11 | +#include <fstream> |
| 12 | +#include <sstream> |
| 13 | +#include <stdlib.h> |
| 14 | + |
| 15 | +#include "CRTCalibService.h" |
| 16 | +#include "messagefacility/MessageLogger/MessageLogger.h" |
| 17 | + |
| 18 | +SBND::CRTCalibService::CRTCalibService(fhicl::ParameterSet const& pset) |
| 19 | +{ |
| 20 | + const std::string timingOffsetFile = pset.get<std::string>("TimingOffsetFileName"); |
| 21 | + const std::string pedestalFile = pset.get<std::string>("PedestalFileName"); |
| 22 | + |
| 23 | + std::string timingOffsetPath, pedestalPath; |
| 24 | + cet::search_path sp("FW_SEARCH_PATH"); |
| 25 | + sp.find_file(timingOffsetFile, timingOffsetPath); |
| 26 | + sp.find_file(pedestalFile, pedestalPath); |
| 27 | + |
| 28 | + if(timingOffsetPath.empty()) |
| 29 | + { |
| 30 | + std::cout << "SBND::CRTCalibService Input file " << timingOffsetFile << " not found" << std::endl; |
| 31 | + throw cet::exception("File not found"); |
| 32 | + } |
| 33 | + |
| 34 | + if(pedestalPath.empty()) |
| 35 | + { |
| 36 | + std::cout << "SBND::CRTCalibService Input file " << pedestalFile << " not found" << std::endl; |
| 37 | + throw cet::exception("File not found"); |
| 38 | + } |
| 39 | + |
| 40 | + std::cout << "SBND CRT Channel Map: Building map from files...\n" |
| 41 | + << "\t Timing Offsets: " << timingOffsetFile << '\n' |
| 42 | + << "\t Pedestals: " << pedestalFile << std::endl; |
| 43 | + |
| 44 | + std::ifstream timingOffsetStream(timingOffsetPath, std::ios::in); |
| 45 | + std::string line; |
| 46 | + |
| 47 | + while(std::getline(timingOffsetStream, line)) |
| 48 | + { |
| 49 | + std::stringstream linestream(line); |
| 50 | + |
| 51 | + unsigned int mac5, offset; |
| 52 | + linestream |
| 53 | + >> mac5 |
| 54 | + >> offset; |
| 55 | + |
| 56 | + fTimingOffsetFromFEBMAC5[mac5] = offset; |
| 57 | + } |
| 58 | + |
| 59 | + timingOffsetStream.close(); |
| 60 | + |
| 61 | + std::ifstream pedestalStream(pedestalPath, std::ios::in); |
| 62 | + |
| 63 | + while(std::getline(pedestalStream, line)) |
| 64 | + { |
| 65 | + std::stringstream linestream(line); |
| 66 | + |
| 67 | + unsigned int mac5, ch, pedestal; |
| 68 | + linestream |
| 69 | + >> mac5 |
| 70 | + >> ch |
| 71 | + >> pedestal; |
| 72 | + |
| 73 | + fPedestalFromFEBMAC5AndChannel[mac5][ch] = pedestal; |
| 74 | + } |
| 75 | + |
| 76 | + pedestalStream.close(); |
| 77 | +} |
| 78 | + |
| 79 | +SBND::CRTCalibService::CRTCalibService(fhicl::ParameterSet const& pset, art::ActivityRegistry&) |
| 80 | + : SBND::CRTCalibService(pset) |
| 81 | +{ |
| 82 | +} |
| 83 | + |
| 84 | +double SBND::CRTCalibService::GetTimingOffsetFromFEBMAC5(unsigned int feb_mac5) const |
| 85 | +{ |
| 86 | + auto iter = fTimingOffsetFromFEBMAC5.find(feb_mac5); |
| 87 | + |
| 88 | + if(iter == fTimingOffsetFromFEBMAC5.end()) |
| 89 | + { |
| 90 | + mf::LogInfo("SBND CRT Calibration Service") << "Asked for FEB with MAC5: " << feb_mac5 << '\n' |
| 91 | + << "This FEB does not appear in the channel map." |
| 92 | + << std::endl; |
| 93 | + |
| 94 | + return 0.; |
| 95 | + } |
| 96 | + |
| 97 | + return iter->second; |
| 98 | +} |
| 99 | + |
| 100 | +double SBND::CRTCalibService::GetPedestalFromFEBMAC5AndChannel(unsigned int feb_mac5, unsigned int ch) const |
| 101 | +{ |
| 102 | + auto iter = fPedestalFromFEBMAC5AndChannel.find(feb_mac5); |
| 103 | + |
| 104 | + if(iter == fPedestalFromFEBMAC5AndChannel.end()) |
| 105 | + { |
| 106 | + mf::LogInfo("SBND CRT Calibration Service") << "Asked for FEB with MAC5: " << feb_mac5 << '\n' |
| 107 | + << "This FEB does not appear in the calibration service." |
| 108 | + << std::endl; |
| 109 | + |
| 110 | + return 0.; |
| 111 | + } |
| 112 | + |
| 113 | + auto subIter = iter->second.find(ch); |
| 114 | + |
| 115 | + if(subIter == iter->second.end()) |
| 116 | + { |
| 117 | + mf::LogInfo("SBND CRT Calibration Service") << "Asked for channel: " << ch << '\n' |
| 118 | + << "in FEB with MAC5: " << feb_mac5 << '\n' |
| 119 | + << "This channel does not appear in the calibration service." |
| 120 | + << std::endl; |
| 121 | + |
| 122 | + return 0.; |
| 123 | + } |
| 124 | + |
| 125 | + return subIter->second; |
| 126 | +} |
| 127 | + |
| 128 | +DEFINE_ART_SERVICE(SBND::CRTCalibService) |
0 commit comments