Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sbndcode/Calibration/CRT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
install_fhicl()

add_subdirectory(CalibService)
15 changes: 15 additions & 0 deletions sbndcode/Calibration/CRT/CalibService/CMakeLists.txt
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
)
47 changes: 47 additions & 0 deletions sbndcode/Calibration/CRT/CalibService/CRTCalibService.h
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 sbndcode/Calibration/CRT/CalibService/CRTCalibService_service.cc
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);
Comment thread
henrylay97 marked this conversation as resolved.

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)
Loading