Skip to content

Commit e0afaa2

Browse files
gputnamMichael Carrigan
authored andcommitted
Update calibrations for 2D+DNN signal processing for Run 2.
1 parent 1bd2d04 commit e0afaa2

6 files changed

Lines changed: 299 additions & 7 deletions

File tree

fcl/configurations/calibration_database_GlobalTags_icarus.fcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
BEGIN_PROLOG
66

77
ICARUS_Calibration_GlobalTags: {
8-
@table::TPC_CalibrationTags_Jan2025
8+
@table::TPC_CalibrationTags_Jul2025
99
@table::PMT_CalibrationTags_Run3_Feb2025
1010
@table::CRT_CalibrationTags_Oct2023
1111
}

fcl/configurations/calibration_database_TPC_TagSets_icarus.fcl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,15 @@ TPC_CalibrationTags_Jan2025: {
3737

3838
}
3939

40+
## TPC_CalibrationTags_Jul2024
41+
# Update to 2D deconv tags. Change TPC equalization to be per-plane
42+
TPC_CalibrationTags_Jul2025: {
43+
44+
tpc_channelstatus_data: "v3r4"
45+
tpc_elifetime_data: "v3r0"
46+
tpc_dqdxcalibration_allplanes_data: "v1r0"
47+
tpc_yz_correction_allplanes_data: "v2r0"
48+
49+
}
50+
4051
END_PROLOG

icaruscode/TPC/Calorimetry/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ cet_build_plugin(NormalizeDriftSQLite art::tool LIBRARIES ${TOOL_LIBRARIES})
4747
cet_build_plugin(NormalizeDrift art::tool LIBRARIES ${TOOL_LIBRARIES})
4848
cet_build_plugin(NormalizeTPCSQL art::tool LIBRARIES ${TOOL_LIBRARIES})
4949
cet_build_plugin(NormalizeTPC art::tool LIBRARIES ${TOOL_LIBRARIES})
50+
cet_build_plugin(NormalizeTPCPerPlaneSQL art::tool LIBRARIES ${TOOL_LIBRARIES})
51+
cet_build_plugin(NormalizeTPCPerPlane art::tool LIBRARIES ${TOOL_LIBRARIES})
5052
cet_build_plugin(NormalizeTPCLocal art::tool LIBRARIES ${TOOL_LIBRARIES})
5153
cet_build_plugin(NormalizeWire art::tool LIBRARIES ${TOOL_LIBRARIES})
5254
cet_build_plugin(NormalizeYZSQL art::tool LIBRARIES ${TOOL_LIBRARIES})
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Framework Includes
2+
#include "art/Framework/Core/EDProducer.h"
3+
#include "art/Framework/Principal/Event.h"
4+
#include "art/Framework/Principal/Handle.h"
5+
#include "art/Framework/Services/Registry/ServiceHandle.h"
6+
#include "art/Persistency/Common/PtrMaker.h"
7+
#include "art/Utilities/ToolMacros.h"
8+
#include "cetlib/cpu_timer.h"
9+
#include "fhiclcpp/ParameterSet.h"
10+
#include "messagefacility/MessageLogger/MessageLogger.h"
11+
12+
#include "larevt/CalibrationDBI/Providers/DBFolder.h"
13+
14+
// Tool include
15+
#include "larreco/Calorimetry/INormalizeCharge.h"
16+
17+
// Services
18+
#include "lardata/DetectorInfoServices/DetectorClocksService.h"
19+
20+
// Lab helpers
21+
#include "wda.h"
22+
23+
// C++
24+
#include <string>
25+
26+
namespace icarus {
27+
namespace calo {
28+
29+
class NormalizeTPCPerPlaneSQL : public INormalizeCharge
30+
{
31+
public:
32+
NormalizeTPCPerPlaneSQL(fhicl::ParameterSet const &pset);
33+
34+
void configure(const fhicl::ParameterSet& pset) override;
35+
double Normalize(double dQdx, const art::Event &e, const recob::Hit &h, const geo::Point_t &location, const geo::Vector_t &direction, double t0) override;
36+
37+
private:
38+
// Configuration
39+
std::string fDBFileName;
40+
std::string fDBTag;
41+
bool fVerbose;
42+
43+
lariov::DBFolder fDB;
44+
45+
// Class to hold data from DB
46+
class ScaleInfo {
47+
public:
48+
std::map<unsigned, double> scale;
49+
};
50+
51+
// Helpers
52+
ScaleInfo GetScaleInfo(uint64_t run);
53+
54+
// Cache run requests
55+
std::map<uint64_t, ScaleInfo> fScaleInfos;
56+
};
57+
58+
DEFINE_ART_CLASS_TOOL(NormalizeTPCPerPlaneSQL)
59+
60+
} // end namespace calo
61+
} // end namespace icarus
62+
63+
64+
icarus::calo::NormalizeTPCPerPlaneSQL::NormalizeTPCPerPlaneSQL(fhicl::ParameterSet const &pset):
65+
fDBFileName(pset.get<std::string>("DBFileName")),
66+
fDBTag(pset.get<std::string>("DBTag")),
67+
fVerbose(pset.get<bool>("Verbose", false)),
68+
fDB(fDBFileName, "", "", fDBTag, true, false) {}
69+
70+
void icarus::calo::NormalizeTPCPerPlaneSQL::configure(const fhicl::ParameterSet& pset) {}
71+
72+
icarus::calo::NormalizeTPCPerPlaneSQL::ScaleInfo icarus::calo::NormalizeTPCPerPlaneSQL::GetScaleInfo(uint64_t run) {
73+
// check the cache
74+
if (fScaleInfos.count(run)) {
75+
return fScaleInfos.at(run);
76+
}
77+
78+
// Look up the run
79+
//
80+
// Translate the run into a fake "timestamp"
81+
fDB.UpdateData((run+1000000000)*1000000000);
82+
83+
// Collect the run info
84+
ScaleInfo thisscale;
85+
86+
// Iterate over the rows
87+
for (unsigned ch = 0; ch < 12; ch++) {
88+
double scale;
89+
fDB.GetNamedChannelData(ch, "scale", scale);
90+
91+
thisscale.scale[ch] = scale;
92+
}
93+
// Set the cache
94+
fScaleInfos[run] = thisscale;
95+
96+
return thisscale;
97+
}
98+
99+
double icarus::calo::NormalizeTPCPerPlaneSQL::Normalize(double dQdx, const art::Event &e,
100+
const recob::Hit &hit, const geo::Point_t &location, const geo::Vector_t &direction, double t0) {
101+
// Get the info
102+
ScaleInfo i = GetScaleInfo(e.id().runID().run());
103+
104+
// Lookup the TPC, cryo
105+
unsigned tpc = hit.WireID().TPC;
106+
unsigned cryo = hit.WireID().Cryostat;
107+
unsigned plane = hit.WireID().Plane;
108+
109+
// Get the TPC-Plane index
110+
unsigned itpc_plane = 2*cryo + tpc/2 + plane*4;
111+
112+
double scale = 1;
113+
114+
// TODO: what to do if no scale is found? throw an exception??
115+
if (i.scale.count(itpc_plane)) scale = i.scale.at(itpc_plane);
116+
117+
if (fVerbose) std::cout << "NormalizeTPCPerPlaneSQL Tool -- Data at Cryo: " << cryo << " TPC: " << tpc << " Plane: " << plane << " itpc_plane: " << itpc_plane << " scale: " << scale << std::endl;
118+
119+
return dQdx * scale;
120+
}
121+
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Framework Includes
2+
#include "art/Framework/Core/EDProducer.h"
3+
#include "art/Framework/Principal/Event.h"
4+
#include "art/Framework/Principal/Handle.h"
5+
#include "art/Framework/Services/Registry/ServiceHandle.h"
6+
#include "art/Persistency/Common/PtrMaker.h"
7+
#include "art/Utilities/ToolMacros.h"
8+
#include "cetlib/cpu_timer.h"
9+
#include "fhiclcpp/ParameterSet.h"
10+
#include "messagefacility/MessageLogger/MessageLogger.h"
11+
12+
// Tool include
13+
#include "larreco/Calorimetry/INormalizeCharge.h"
14+
15+
// Services
16+
#include "lardata/DetectorInfoServices/DetectorClocksService.h"
17+
18+
// Lab helpers
19+
#include "wda.h"
20+
21+
// C++
22+
#include <string>
23+
24+
namespace icarus {
25+
namespace calo {
26+
27+
class NormalizeTPC : public INormalizeCharge
28+
{
29+
public:
30+
NormalizeTPC(fhicl::ParameterSet const &pset);
31+
32+
void configure(const fhicl::ParameterSet& pset) override;
33+
double Normalize(double dQdx, const art::Event &e, const recob::Hit &h, const geo::Point_t &location, const geo::Vector_t &direction, double t0) override;
34+
35+
private:
36+
// Configuration
37+
int fTimeout;
38+
std::string fURL;
39+
bool fVerbose;
40+
41+
// Class to hold data from DB
42+
class ScaleInfo {
43+
public:
44+
std::map<unsigned, double> scale;
45+
};
46+
47+
// Helpers
48+
ScaleInfo GetScaleInfo(uint64_t run);
49+
std::string URL(uint64_t run);
50+
51+
// Cache run requests
52+
std::map<uint64_t, ScaleInfo> fScaleInfos;
53+
};
54+
55+
DEFINE_ART_CLASS_TOOL(NormalizeTPC)
56+
57+
} // end namespace calo
58+
} // end namespace icarus
59+
60+
61+
icarus::calo::NormalizeTPC::NormalizeTPC(fhicl::ParameterSet const &pset) {
62+
this->configure(pset);
63+
}
64+
65+
void icarus::calo::NormalizeTPC::configure(const fhicl::ParameterSet& pset) {
66+
fURL = pset.get<std::string>("URL");
67+
fTimeout = pset.get<unsigned>("Timeout");
68+
fVerbose = pset.get<bool>("Verbose", false);
69+
}
70+
71+
std::string icarus::calo::NormalizeTPC::URL(uint64_t run) {
72+
return fURL + std::to_string(run);
73+
}
74+
75+
icarus::calo::NormalizeTPC::ScaleInfo icarus::calo::NormalizeTPC::GetScaleInfo(uint64_t run) {
76+
// check the cache
77+
if (fScaleInfos.count(run)) {
78+
return fScaleInfos.at(run);
79+
}
80+
81+
// Otherwise, look it up
82+
int error = 0;
83+
std::string url = URL(run);
84+
85+
if (fVerbose) std::cout << "NormalizeTPC Tool -- New Scale info, requesting data from url:\n" << url << std::endl;
86+
87+
Dataset d = getDataWithTimeout(url.c_str(), "", fTimeout, &error);
88+
if (error) {
89+
throw cet::exception("NormalizeTPC") << "Calibration Database access failed. URL: (" << url << ") Error Code: " << error;
90+
}
91+
92+
if (fVerbose) std::cout << "NormalizeTPC Tool -- Received HTTP response:\n" << getHTTPmessage(d) << std::endl;
93+
94+
if (getHTTPstatus(d) != 200) {
95+
throw cet::exception("NormalizeTPC")
96+
<< "Calibration Database access failed. URL: (" << url
97+
<< "). HTTP error status: " << getHTTPstatus(d) << ". HTTP error message: " << getHTTPmessage(d);
98+
}
99+
100+
// Collect the run info
101+
ScaleInfo thisscale;
102+
103+
// Number of rows
104+
int n_tuple = getNtuples(d);
105+
if (n_tuple < 0) {
106+
throw cet::exception("NormalizeTPC") << "Calibration Database access failed. URL: (" << url << ") Bad Tuple Number: " << n_tuple;
107+
}
108+
109+
// Iterate over the rows
110+
// The first 4 are metadata
111+
for (unsigned row = 4; row < (unsigned)n_tuple; row++) {
112+
Tuple tup = getTuple(d, row);
113+
114+
int err = 0;
115+
// Get the itpc number
116+
int ch = getLongValue(tup, 0, &err);
117+
if (error) {
118+
throw cet::exception("NormalizeTPC") << "Calibration Database access failed. URL: (" << url << ") Failed on tuple access, row: " << row << ", col 0. Error Code: " << error;
119+
}
120+
121+
// and the scale
122+
double scale = getDoubleValue(tup, 3, &err);
123+
if (error) {
124+
throw cet::exception("NormalizeTPC") << "Calibration Database access failed. URL: (" << url << ") Failed on tuple access, row: " << row << ", col 1. Error Code: " << error;
125+
}
126+
127+
thisscale.scale[ch] = scale;
128+
}
129+
130+
// Set the cache
131+
fScaleInfos[run] = thisscale;
132+
133+
return thisscale;
134+
}
135+
136+
double icarus::calo::NormalizeTPC::Normalize(double dQdx, const art::Event &e,
137+
const recob::Hit &hit, const geo::Point_t &location, const geo::Vector_t &direction, double t0) {
138+
// Get the info
139+
ScaleInfo i = GetScaleInfo(e.id().runID().run());
140+
141+
// Lookup the TPC, cryo
142+
unsigned tpc = hit.WireID().TPC;
143+
unsigned cryo = hit.WireID().Cryostat;
144+
unsigned plane = hit.WireID().Plane;
145+
146+
// Get the TPC-Plane index
147+
unsigned itpc_plane = 2*cryo + tpc/2 + plane*4;
148+
149+
double scale = 1;
150+
151+
// TODO: what to do if no scale is found? throw an exception??
152+
if (i.scale.count(itpc_plane)) scale = i.scale.at(itpc_plane);
153+
154+
if (fVerbose) std::cout << "NormalizeTPCPerPlaneSQL Tool -- Data at Cryo: " << cryo << " TPC: " << tpc << " Plane: " << plane << " itpc_plane: " << itpc_plane << " scale: " << scale << std::endl;
155+
156+
return dQdx * scale;
157+
}
158+

icaruscode/TPC/Calorimetry/normtools_icarus.fcl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ yznorm: {
2424
}
2525

2626
tpcgain: {
27-
tool_type: NormalizeTPC
27+
tool_type: NormalizeTPCPerPlane
2828
Timeout: 200
29-
URL: "https://dbdata0vm.fnal.gov:9443/icarus_con_prod/app/data?f=tpc_dqdxcalibration_data&t="
29+
URL: "https://dbdata0vm.fnal.gov:9443/icarus_con_prod/app/data?f=tpc_dqdxcalibration_allplanes_data&t="
3030
Verbose: false
3131
}
3232

@@ -38,9 +38,9 @@ driftnorm_sql: {
3838
}
3939

4040
tpcgain_sql: {
41-
tool_type: NormalizeTPCSQL
42-
DBFileName: tpc_dqdxcalibration_data
43-
DBTag: @local::ICARUS_Calibration_GlobalTags.tpc_dqdxcalibration_data
41+
tool_type: NormalizeTPCPerPlaneSQL
42+
DBFileName: tpc_dqdxcalibration_allplanes_data
43+
DBTag: @local::ICARUS_Calibration_GlobalTags.tpc_dqdxcalibration_allplanes_data
4444
Verbose: false
4545
}
4646

@@ -59,7 +59,7 @@ yznorm_sql: {
5959
}
6060

6161
#icarus_calonormtools: [@local::driftnorm, @local::yznorm, @local::tpcgain]
62-
icarus_calonormtools: [@local::driftnorm_sql, @local::yznorm_sql, @local::tpcgain_sql]
62+
icarus_calonormtools: [@local::driftnorm_sql, @local::yznorm_sql, @local::tpcgain_sql]
6363

6464
# Gain with angular dep. recombination. Measurement from: https://arxiv.org/pdf/2407.12969
6565
# Assume equal on planes -- this is __wrong__ -- will need to be fixed when they are calibrated

0 commit comments

Comments
 (0)