Skip to content

Commit 6c64295

Browse files
committed
Add temporary calibration service for supplying pedestals & timing offsets
1 parent 8d7ec4c commit 6c64295

7 files changed

Lines changed: 3171 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
install_fhicl()
2+
3+
add_subdirectory(CalibService)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
install_headers()
2+
install_fhicl()
3+
install_source()
4+
5+
file(GLOB calib_values_crt *.txt)
6+
install_fw( LIST ${calib_values_crt} )
7+
8+
art_make(SERVICE_LIBRARIES
9+
art::Framework_Services_Registry
10+
art::Framework_Principal
11+
art::Framework_Core
12+
art::Persistency_Provenance
13+
messagefacility::MF_MessageLogger
14+
ROOT::Core
15+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
///////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Class: SBND::CRTCalibService
3+
// Module type: service
4+
// File: CRTCalibService.h
5+
// Author: Henry Lay, May 2024
6+
//
7+
// Service for inputing CRT calibration values to reconstruction
8+
///////////////////////////////////////////////////////////////////////////////////////////////////
9+
10+
#ifndef SBNDCRTCalibService_H
11+
#define SBNDCRTCalibService_H
12+
13+
#include <unordered_map>
14+
#include <vector>
15+
#include <string>
16+
17+
#include "fhiclcpp/ParameterSet.h"
18+
#include "art/Framework/Core/ModuleMacros.h"
19+
#include "art/Framework/Services/Registry/ServiceMacros.h"
20+
21+
namespace SBND {
22+
class CRTCalibService;
23+
}
24+
25+
26+
class SBND::CRTCalibService {
27+
28+
public:
29+
30+
CRTCalibService(fhicl::ParameterSet const& pset);
31+
CRTCalibService(fhicl::ParameterSet const& pset, art::ActivityRegistry&);
32+
33+
double GetTimingOffsetFromFEBMAC5(unsigned int feb_mac5) const;
34+
35+
double GetPedestalFromFEBMAC5AndChannel(unsigned int feb_mac5, unsigned int ch) const;
36+
37+
private:
38+
39+
std::unordered_map<unsigned int, double> fTimingOffsetFromFEBMAC5;
40+
41+
std::unordered_map<unsigned int, std::unordered_map<unsigned int, double>> fPedestalFromFEBMAC5AndChannel;
42+
43+
};
44+
45+
DECLARE_ART_SERVICE(SBND::CRTCalibService, LEGACY)
46+
47+
#endif
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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

Comments
 (0)