Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a27ee41
Adapt Calibration Service from ICARUS
asanchezcastillo Jan 27, 2025
10882cf
Merge remote-tracking branch 'origin/develop' into feature/acastill_p…
asanchezcastillo Jan 27, 2025
a0a6e8c
Add actua database variables
asanchezcastillo Mar 3, 2025
1753323
Format code
asanchezcastillo Mar 3, 2025
534c3c1
Remove .clang-format
asanchezcastillo Mar 3, 2025
98cc1c2
Fix conflicts
asanchezcastillo Mar 3, 2025
6191ff9
Remove clang.formal files
asanchezcastillo Mar 3, 2025
3ee8046
Fix typo
asanchezcastillo Mar 3, 2025
7a520f6
Undo unrequired changes
asanchezcastillo Mar 3, 2025
00e23d5
Cleanup
asanchezcastillo Mar 3, 2025
b04ca7e
Cleanup
asanchezcastillo Mar 3, 2025
9a2ea43
Include fcl and locate in calibration folder
asanchezcastillo Mar 5, 2025
606be67
Fix service provider name
asanchezcastillo Mar 5, 2025
30ebdc0
Add pmt calibration database service
asanchezcastillo Mar 5, 2025
5274002
Bump `sbnd_data` version
bear-is-asleep Mar 7, 2025
2af8ec6
Merge branch 'develop' into feature/acastill_pmtdatabaseinterface
asanchezcastillo Mar 11, 2025
e8a902b
Merge branch 'develop' into feature/acastill_pmtdatabaseinterface
asanchezcastillo Mar 26, 2025
e791f41
Fix pds_calibration.db path
asanchezcastillo Mar 27, 2025
ff442a4
Merge branch 'feature/acastill_pmtdatabaseinterface' of github.com:SB…
asanchezcastillo Mar 27, 2025
f54aefc
Merge branch 'develop' into feature/acastill_pmtdatabaseinterface
asanchezcastillo Mar 27, 2025
4fa3605
Add CalibrationDatabase to FW_SEARCH_PATH
asanchezcastillo Apr 3, 2025
cf8014a
Reference .db file to the new path in FW_SEARCH_PATH
asanchezcastillo Apr 3, 2025
62a58a6
Merge branch 'feature/acastill_pmtdatabaseinterface' of github.com:SB…
asanchezcastillo Apr 3, 2025
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
1 change: 1 addition & 0 deletions sbndcode/Calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(OpReco)
add_subdirectory(CRT)
add_subdirectory(DQM)
add_subdirectory(PDSDatabaseInterface)
28 changes: 28 additions & 0 deletions sbndcode/Calibration/PDSDatabaseInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cet_enable_asserts()

set( MODULE_LIBRARIES
art_root_io::TFileService_service
art_root_io::tfile_support
)
set( LIB_LIBRARIES
art::Framework_Services_Registry
messagefacility::MF_MessageLogger
lardata::Utilities
larevt::CalibrationDBI_IOVData
larevt::CalibrationDBI_Providers
)
set( SERVICE_LIBRARIES
sbndcode_Calibration_PDSDatabaseInterface
larcore::Geometry_Geometry_service
lardata::DetectorClocksService
)

file(GLOB lib_srcs *.cxx)

art_make_library( SOURCE ${lib_srcs} LIBRARIES PUBLIC ${LIB_LIBRARIES})

cet_build_plugin( PMTCalibrationDatabaseService art::service LIBRARIES PUBLIC ${SERVICE_LIBRARIES})

install_headers()
install_fhicl()
install_source()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file icaruscode/Timing/IPMTTimingCorrectionService.h
* @brief Wrapper class for 'PMTTimingCorrectionsProvider.h'
* @author Andrea Scarpelli (ascarpell@bnl.gov), Gianluca Petrillo (petrillo@slac.stanford.edu)
*/
// Ported to SBND by Alejandro Sanchez-Castillo, Jan. 2025

#ifndef SBNDCCODE_DATABASEINTERFACE_IPMTCALIBRATIONDATABASESERVICE_H
#define SBNDCCODE_DATABASEINTERFACE_IPMTCALIBRATIONDATABASESERVICE_H

// ICARUS libraries
#include "sbndcode/Calibration/PDSDatabaseInterface/PMTCalibrationDatabase.h"

// LArSoft libraries
#include "larcore/CoreUtils/ServiceProviderWrappers.h"

// -----------------------------------------------------------------------------
namespace sbndDB {
/// The only thing this service does is to return its service provider of type
/// `sbndDB::PMTCalibrationDatabase`.
using IPMTCalibrationDatabaseService =
lar::ServiceProviderInterfaceWrapper<PMTCalibrationDatabase>;
}

// -----------------------------------------------------------------------------
DECLARE_ART_SERVICE_INTERFACE(sbndDB::IPMTCalibrationDatabaseService, SHARED)

// -----------------------------------------------------------------------------

#endif
39 changes: 39 additions & 0 deletions sbndcode/Calibration/PDSDatabaseInterface/PMTCalibrationDatabase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////
///
/// Interface class between the calibration database and the PMT time corrections
///
/// A. Scarpelli
///
/// \mailto ascarpell@bnl.gov
///
////////////////////////////////////////////////////////////////////////
// Ported to SBND by Alejandro Sanchez-Castillo, Jan. 2025

#ifndef SBNDCCODE_DATABASEINTERFACE_PMTCALIBRATIONDATABASE_H
#define SBNDCCODE_DATABASEINTERFACE_PMTCALIBRATIONDATABASE_H

#include "larcorealg/CoreUtils/UncopiableAndUnmovableClass.h"

#include "art/Framework/Principal/Run.h"
#include "art/Framework/Services/Registry/ServiceDeclarationMacros.h"

namespace sbndDB {

class PMTCalibrationDatabase : lar::UncopiableClass {
public:
virtual ~PMTCalibrationDatabase() noexcept = default;
virtual int getBreakoutBox(unsigned int channelID) const = 0;
virtual int getCAENDigitizer(unsigned int channelID) const = 0;
virtual int getCAENDigitizerChannel(unsigned int channelID) const = 0;
virtual double getTotalTransitTime(unsigned int channelID) const = 0;
virtual double getSPEAmplitude(unsigned int channelID) const = 0;
virtual double getGaussFilterPower(unsigned int channelID) const = 0;
virtual double getGaussFilterWC(unsigned int channelID) const = 0;
virtual std::vector<double> getSER(unsigned int channelID) const = 0;
}; // end class

} // end of namespace

DECLARE_ART_SERVICE_INTERFACE(sbndDB::PMTCalibrationDatabase, SHARED)

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* Service for the PMT Calibration Database.
* Andrea Scarpelli (ascarpell@bnl.gov), Matteo Vicenzi (mvicenzi@bnl.gov)
*/
// Ported from icaruscode to SBND by Alejandro Sanchez-Castillo, Jan. 2025

// Framework includes
#include "art/Framework/Principal/Run.h"
#include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
#include "cetlib_except/exception.h"
#include "messagefacility/MessageLogger/MessageLogger.h"

// Local
#include "sbndcode/Calibration/PDSDatabaseInterface/PMTCalibrationDatabase.h"
#include "sbndcode/Calibration/PDSDatabaseInterface/PMTCalibrationDatabaseProvider.h"

// Database interface helpers
#include "larevt/CalibrationDBI/IOVData/TimeStampDecoder.h"
#include "larevt/CalibrationDBI/Providers/DBFolder.h"

// C/C++ standard libraries
#include <string>
#include <vector>

//--------------------------------------------------------------------------------

sbndDB::PMTCalibrationDatabaseProvider::PMTCalibrationDatabaseProvider(
const fhicl::ParameterSet& pset)
: fVerbose{pset.get<bool>("Verbose", false)}
, fLogCategory{pset.get<std::string>("LogCategory", "PMTTimingCorrection")}
{
fhicl::ParameterSet const tags{pset.get<fhicl::ParameterSet>("CorrectionTags")};
fPMTCalibrationDatabaseTag = tags.get<std::string>("PMTCalibrationDatabaseTag");
fDatabaseTimeStamp = tags.get<long>("DatabaseTimeStamp");
fTableName = tags.get<std::string>("TableName");
fSERLength = tags.get<size_t>("SERLength");
if (fVerbose)
mf::LogInfo(fLogCategory) << "Database tags for timing corrections:\n"
<< "Cables corrections " << fPMTCalibrationDatabaseTag << "\n";
}

// -------------------------------------------------------------------------------

uint64_t sbndDB::PMTCalibrationDatabaseProvider::RunToDatabaseTimestamp(uint32_t run) const
{

// Run number to timestamp used in the db
// DBFolder.h only takes 19 digit (= timestamp in nano second),
// but SBND tables are currently using run numbers
// Step 1) Add 1000000000 to the run number; e.g., run XXXXX -> 10000XXXXX
// Step 2) Multiply 1000000000
uint64_t runNum = uint64_t(run);
uint64_t timestamp = runNum + 1000000000;
timestamp *= 1000000000;

if (fVerbose)
mf::LogInfo(fLogCategory) << "Run " << runNum << " corrections from DB timestamp " << timestamp;

return timestamp;
}

// -------------------------------------------------------------------------------

/// Function to look up the calibration database at the table holding the pmt hardware cables corrections
void sbndDB::PMTCalibrationDatabaseProvider::ReadPMTCalibration(uint32_t run)
{
const std::string dbname(fTableName);
lariov::DBFolder db(dbname, "", "", fPMTCalibrationDatabaseTag, true, false);

bool ret = db.UpdateData(fDatabaseTimeStamp); // select table based on timestamp (this is temporary, once we generate db based on run numbers this should be changed)
mf::LogDebug(fLogCategory) << dbname + " corrections" << (ret ? "" : " not")
<< " updated for run " << run;
mf::LogTrace(fLogCategory)
<< "Fetched IoV [ " << db.CachedStart().DBStamp() << " ; " << db.CachedEnd().DBStamp()
<< " ] to cover t=" << RunToDatabaseTimestamp(run)
<< " [=" << lariov::TimeStampDecoder::DecodeTimeStamp(RunToDatabaseTimestamp(run)).DBStamp()
<< "]";

std::vector<unsigned int> channelList;
if (int res = db.GetChannelList(channelList); res != 0) {
throw cet::exception("PMTTimingCorrectionsProvider")
<< "GetChannelList() returned " << res << " on run " << run << " query in " << dbname << "\n";
}

if (channelList.empty()) {
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Got an empty channel list for run " << run << " in " << dbname << "\n";
}

for (auto channel : channelList) {
// Read breakout box
long _breakoutbox = 0;
int error = db.GetNamedChannelData(channel, "breakout_box", _breakoutbox);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error
<< ") while trying to access 'breakout_box' on table " << dbname << "\n";
fPMTCalibrationData[channel].breakoutBox = static_cast<int>(_breakoutbox);

// Read caen digitizer
long _caen_digitizer = 0;
error = db.GetNamedChannelData(channel, "caen_digitizer", _caen_digitizer);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error
<< ") while trying to access 'caen_digitizer' on table " << dbname << "\n";
fPMTCalibrationData[channel].caenDigitizer = static_cast<int>(_caen_digitizer);

// Read caen digitizer channel
long _caen_digitizer_channel = 0;
error = db.GetNamedChannelData(channel, "caen_digitizer_channel", _caen_digitizer_channel);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error
<< ") while trying to access 'caen_digitizer_channel' on table " << dbname << "\n";
fPMTCalibrationData[channel].caenDigitizerChannel = static_cast<int>(_caen_digitizer_channel);

// Read total transit time
double _total_transit_time = 0.;
error = db.GetNamedChannelData(channel, "total_transit_time", _total_transit_time);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error
<< ") while trying to access 'total_transit_time' on table " << dbname << "\n";
fPMTCalibrationData[channel].totalTransitTime = _total_transit_time;

// Read spe amplitude
double _spe_amplitude = 0.;
error = db.GetNamedChannelData(channel, "spe_amp", _spe_amplitude);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error
<< ") while trying to access 'spe_amplitude' on table " << dbname << "\n";
fPMTCalibrationData[channel].spe_amplitude = _spe_amplitude;

// Read gauss filter power
double _gauss_w_wc_power = 0;
error = db.GetNamedChannelData(channel, "gauss_w_wc_power", _gauss_w_wc_power);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error
<< ") while trying to access 'gauss_w_wc_power' on table " << dbname << "\n";
fPMTCalibrationData[channel].gauss_wc_power = _gauss_w_wc_power;

// Read gauss filter wc
double _gauss_wc = 0.;
error = db.GetNamedChannelData(channel, "gauss_wc", _gauss_wc);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error << ") while trying to access 'gauss_wc' on table "
<< dbname << "\n";
fPMTCalibrationData[channel].gauss_wc = _gauss_wc;

// Read SER
std::vector<double> _ser;
std::string name_base = "ser_vec_";
for (size_t i = 0; i < fSERLength; i++) {
std::string entry_num = std::to_string(i);
std::string entry_name = name_base + entry_num;
double _ser_component = 0.;
error = db.GetNamedChannelData(channel, entry_name, _ser_component);
if (error)
throw cet::exception("PMTTimingCorrectionsProvider")
<< "Encountered error (code " << error << ") while trying to access 'ser_vec' on table "
<< dbname << "\n";
_ser.push_back(_ser_component);
}
fPMTCalibrationData[channel].ser = _ser;
}
}

// -----------------------------------------------------------------------------

/// Read all the corrections from the database and save them inside a map, whose index
/// is the PMT channel number
void sbndDB::PMTCalibrationDatabaseProvider::readPMTCalibrationDatabase(const art::Run& run)
{

// Clear before the run
fPMTCalibrationData.clear();

ReadPMTCalibration(run.id().run());

if (fVerbose) {
mf::LogInfo(fLogCategory) << "Dump information from database " << std::endl;
mf::LogVerbatim(fLogCategory)
<< "channel, trigger cable delay, reset cable delay, laser corrections, muons corrections"
<< std::endl;
for (auto const& [key, value] : fPMTCalibrationData) {
mf::LogVerbatim(fLogCategory) << key << " " << value.breakoutBox << "," << std::endl;
}
}
}
Loading