Skip to content

Commit 5097d9d

Browse files
Merge branch 'develop' into feature/acastill_pmt_detvar
2 parents 686564c + 5b6c372 commit 5097d9d

11 files changed

Lines changed: 212 additions & 9 deletions

File tree

sbndcode/Calibration/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory(OpReco)
22
add_subdirectory(CRT)
33
add_subdirectory(DQM)
44
add_subdirectory(PDSDatabaseInterface)
5+
add_subdirectory(TPCCalorimetry)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
set(TOOL_LIBRARIES
3+
lardataobj::RecoBase
4+
larreco::Calorimetry
5+
larcorealg::Geometry
6+
lardataalg::DetectorInfo
7+
lardata::ArtDataHelper
8+
canvas::canvas
9+
art::Framework_Services_Registry
10+
art::Utilities
11+
fhiclcpp::fhiclcpp
12+
cetlib::cetlib
13+
cetlib_except::cetlib_except
14+
ROOT::Core
15+
ROOT::Hist
16+
)
17+
18+
cet_build_plugin(NormalizeYZ art::tool LIBRARIES ${TOOL_LIBRARIES})
19+
20+
install_headers()
21+
install_fhicl()
22+
install_source()
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
2+
// Framework Includes
3+
#include "art/Framework/Core/EDProducer.h"
4+
#include "art/Framework/Principal/Event.h"
5+
#include "art/Framework/Principal/Handle.h"
6+
#include "art/Framework/Services/Registry/ServiceHandle.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 "canvas/Persistency/Common/Ptr.h"
13+
14+
// Tool include
15+
#include "larreco/Calorimetry/INormalizeCharge.h"
16+
17+
// Services
18+
#include "lardata/DetectorInfoServices/DetectorClocksService.h"
19+
20+
// ROOT includes
21+
#include "TFile.h"
22+
#include "TH2F.h"
23+
24+
// C++ includes
25+
#include <map>
26+
#include <string>
27+
#include <stdexcept>
28+
#include <iostream>
29+
30+
31+
32+
namespace sbnd {
33+
namespace calo {
34+
35+
class NormalizeYZ : public INormalizeCharge{
36+
public:
37+
explicit NormalizeYZ(fhicl::ParameterSet const& pset);
38+
39+
void configure(const fhicl::ParameterSet& pset) override;
40+
41+
double Normalize(double dQdx,
42+
const art::Event& evt,
43+
const recob::Hit& hit,
44+
const geo::Point_t& location,
45+
const geo::Vector_t& direction,
46+
double t0) override;
47+
48+
private:
49+
void reconfigure(const fhicl::ParameterSet& pset);
50+
51+
std::map<std::string, TH2F*> fCorrHists;
52+
std::string fFileName;
53+
bool fVerbose;
54+
};
55+
56+
NormalizeYZ::NormalizeYZ(fhicl::ParameterSet const& pset){
57+
reconfigure(pset); // delegate config to reusable function
58+
}
59+
60+
void NormalizeYZ::configure(const fhicl::ParameterSet& pset){
61+
reconfigure(pset);
62+
}
63+
64+
void NormalizeYZ::reconfigure(const fhicl::ParameterSet& pset){
65+
fFileName = pset.get<std::string>("FileName");
66+
fVerbose = pset.get<bool>("Verbose", false);
67+
68+
std::string fname;
69+
cet::search_path sp("FW_SEARCH_PATH");
70+
sp.find_file(fFileName, fname);
71+
72+
TFile* f = TFile::Open(fname.c_str(), "READ");
73+
if (!f || f->IsZombie()) {
74+
throw cet::exception("NormalizeYZ") << "Failed to open correction map file: " << fFileName;
75+
}
76+
77+
for (int plane = 0; plane < 3; plane++){ // planes : 2 inductions (idx : 0, 1) and 1 collection (idx : 2)
78+
for (int tpc = 0; tpc < 2; tpc++){ // tpc : east (idx : 0) and west (idx : 1) TPCs
79+
std::string histname = Form("CzyHist_%d_%d", plane, tpc);
80+
TH2F* h = (TH2F*)f->Get(histname.c_str());
81+
if (!h) {
82+
throw cet::exception("NormalizeYZ") << "Missing histogram in file: " << histname;
83+
}
84+
85+
fCorrHists[Form("plane%d_%d", plane, tpc)] = (TH2F*)h->Clone();
86+
fCorrHists[Form("plane%d_%d", plane, tpc)]->SetDirectory(nullptr);
87+
}
88+
}
89+
f->Close();
90+
}
91+
92+
double NormalizeYZ::Normalize(double dQdx,
93+
const art::Event& evt,
94+
const recob::Hit& hit,
95+
const geo::Point_t& location,
96+
const geo::Vector_t&,
97+
double){
98+
99+
int plane = hit.WireID().Plane;
100+
//int tpc = hit.WireID().TPC;
101+
102+
// just to be sure and consistent with the logic of input YZ map
103+
// seems like current setup of directly calling hit.WireID().TPC has a tolerance of 30cm
104+
// meaning - an approx region of -30<x<30 lies in both the TPCs
105+
int tpc;
106+
if(location.X()<0){
107+
tpc = 0;
108+
} else tpc = 1;
109+
110+
111+
std::string key = Form("plane%d_%d", plane, tpc);
112+
113+
auto it = fCorrHists.find(key);
114+
if (it == fCorrHists.end()) {
115+
mf::LogWarning("NormalizeYZ") << "No correction histogram for " << key << ". Returning uncorrected dQdx";
116+
return dQdx;
117+
}
118+
119+
TH2F* hCorr = it->second;
120+
int binX = hCorr->GetXaxis()->FindBin(location.Z());
121+
int binY = hCorr->GetYaxis()->FindBin(location.Y());
122+
double scale = hCorr->GetBinContent(binX, binY);
123+
124+
if (fVerbose){
125+
std::cout << "[NormalizeYZ] Plane: " << plane << ", TPC: " << tpc
126+
<< ", Y: " << location.Y() << ", Z: " << location.Z()
127+
<< ", Scale: " << scale << ", dQdx (raw): " << dQdx
128+
<< ", dQdx (corrected): " << dQdx / scale << std::endl;
129+
}
130+
131+
if (scale < 1e-3){
132+
mf::LogWarning("NormalizeYZ") << "Invalid scale at (Y,Z)=(" << location.Y() << "," << location.Z() << "). Returning uncorrected dQdx";
133+
return dQdx;
134+
}
135+
136+
return dQdx / scale;
137+
}
138+
139+
DEFINE_ART_CLASS_TOOL(NormalizeYZ)
140+
141+
} // namespace calo
142+
} // namespace sbnd
143+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
BEGIN_PROLOG
2+
3+
yznorm_hist_data: {
4+
tool_type: NormalizeYZ
5+
FileName: "YZmaps/yz_correction_map_data1e20.root"
6+
Verbose: false
7+
}
8+
9+
yznorm_hist_mc: {
10+
tool_type: NormalizeYZ
11+
FileName: "YZmaps/yz_correction_map_mcp2025b5e18.root"
12+
Verbose: false
13+
}
14+
15+
# list of normalization tools - by far only YZ correction is implemented
16+
sbnd_calonormtoolsdata: [@local::yznorm_hist_data]
17+
sbnd_calonormtoolsmc: [@local::yznorm_hist_mc]
18+
19+
END_PROLOG

sbndcode/LArSoftConfigurations/calorimetry_sbnd.fcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "calorimetry.fcl"
2+
#include "normtools_sbnd.fcl"
23

34
BEGIN_PROLOG
45

@@ -21,11 +22,13 @@ sbnd_gnewcalomc: @local::standard_gnocchicalo
2122
sbnd_gnewcalomc.CaloAlg: @local::sbnd_calorimetryalgmc
2223
sbnd_gnewcalomc.ChargeMethod: 3
2324
sbnd_gnewcalomc.SpacePointModuleLabel: @erase
25+
sbnd_gnewcalomc.NormTools: @local::sbnd_calonormtoolsmc # YZ normalization for MC
2426

2527
sbnd_gnewcalodata: @local::standard_gnocchicalo
2628
sbnd_gnewcalodata.CaloAlg: @local::sbnd_calorimetryalgdata
2729
sbnd_gnewcalodata.ChargeMethod: 3
2830
sbnd_gnewcalodata.SpacePointModuleLabel: @erase
31+
sbnd_gnewcalodata.NormTools: @local::sbnd_calonormtoolsdata # YZ normalization for Data
2932

3033
# gputnam 19Aug2024: Upate calibration to EMB
3134
# Values from: https://arxiv.org/abs/2407.12969

sbndcode/WireCell/cfg/pgrapher/experiment/sbnd/chndb-base.jsonnet

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function(params, anode, field, n, rms_cuts=[])
8686
roi_min_max_ratio: 0.8, // default 0.8
8787
min_rms_cut: 1.0, // units???
8888
max_rms_cut: 30.0, // units???
89+
protection_factor: 2.0,
8990

9091
// parameter used to make "rcrc" spectrum
9192
rcrc: 0.5 * wc.millisecond, // 1.1 for collection, 3.3 for induction
@@ -117,8 +118,9 @@ function(params, anode, field, n, rms_cuts=[])
117118
/// this uses hard-coded waveform.
118119
response: { waveform: handmade.u_resp, waveformid: wc.Ulayer },
119120
response_offset: 125.6, // offset of the negative peak
120-
pad_window_front: 20,
121-
decon_limit: 0.02,
121+
pad_window_front: 120, // 20,
122+
pad_window_back: 25, // 20
123+
decon_limit: 0.002, // 0.02,
122124
decon_limit1: 0.07,
123125
roi_min_max_ratio: 3.0,
124126
},
@@ -137,7 +139,9 @@ function(params, anode, field, n, rms_cuts=[])
137139
/// this uses hard-coded waveform.
138140
response: { waveform: handmade.v_resp, waveformid: wc.Vlayer },
139141
response_offset: 129.5,
140-
decon_limit: 0.01,
142+
pad_window_front: 40, // 20
143+
pad_window_back: 30, // 20
144+
decon_limit: 0.002, // 0.01,
141145
decon_limit1: 0.08,
142146
roi_min_max_ratio: 1.5,
143147
},
@@ -151,10 +155,14 @@ function(params, anode, field, n, rms_cuts=[])
151155

152156
{
153157
//channels: { wpid: wc.WirePlaneId(wc.Wlayer) },
154-
// channels: std.range(n * 2560 + 1600, n * 2560 + 2560- 1),
158+
// channels: std.range(n * 2560 + 1600, n * 2560 + 2560- 1),
155159
channels: std.range(n * 5638 + 3968, n * 5638 + 5638-1),
160+
response: { waveform: handmade.w_resp, waveformid: wc.Wlayer },
161+
response_offset: 129,
156162
nominal_baseline: 650,
157-
decon_limit: 0.05,
163+
pad_window_front: 30, // 20
164+
pad_window_back: 30, // 20
165+
decon_limit: 0.0025,
158166
decon_limit1: 0.08,
159167
freqmasks: freqbinner.freqmasks(harmonic_freqs, 5.0*wc.kilohertz),
160168
},

sbndcode/WireCell/cfg/pgrapher/experiment/sbnd/chndb-resp.jsonnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ u_resp : [
1010

1111
v_resp : [
1212
2.7027618940000003e-07,7.430170020000002e-05,0.0017782846129999997,0.00862459381,0.0221973409,0.040657049300000005,0.060399728900000005,0.07818915720000001,0.0922499172,0.1022825461,0.10893164169999998,0.11318773480000002,0.11598667989999999,0.1180232025,0.11972972550000001,0.12133833390000004,0.12295098550000003,0.12460414889999999,0.12630360959999998,0.1280483169,0.1298349458,0.1316642278,0.13353644220000002,0.1354572415,0.1374271843,0.13944674940000001,0.14151809140000005,0.1436430989,0.1458242324,0.14806054759999998,0.15035552910000002,0.1527118502,0.1551294311,0.15761171649999997,0.1601611403,0.1627785537,0.1654673482,0.16822923950000002,0.1710668477,0.1739826732,0.17697880410000005,0.1800579137,0.18322338020000004,0.1864783424,0.18982572629999997,0.1932679525,0.19680971590000002,0.20045265239999996,0.2042015633,0.20805932140000002,0.21202894579999998,0.21611615550000007,0.220323943,0.2246573756,0.2291177168,0.2337133988,0.23844773330000008,0.24332437780000002,0.24834934390000002,0.25352800480000004,0.258864417,0.2643662147,0.2700364968,0.27588170050000005,0.28190842259999993,0.28812292740000006,0.2945313196,0.3011408743,0.3079578558,0.31498868799999996,0.32224077900000003,0.329720699,0.33743578960000004,0.3453944032,0.35360318979999994,0.3620707944,0.37080522360000007,0.37981498939999997,0.3891070078,0.3986889928,0.4085703608,0.41875764209999994,0.4292590428000001,0.4400839128000001,0.45123745240000007,0.46273000900000005,0.4745681528,0.48675997019999995,0.4993126764500001,0.5122327924070001,0.5255267689700001,0.53919979141,0.5532587918199999,0.5677083587000001,0.5825553748000001,0.59780250943,0.6134535384600002,0.6295113440000001,0.6459782735,0.6628567449,0.6801454933700001,0.6978454007000001,0.7159524063999998,0.73446206694,0.7533665698999998,0.7726554934,0.7923100472000002,0.8123105539500001,0.8326239166000001,0.8532032460000001,0.8739996314000004,0.8949384066,0.9159221890000001,0.936831917,0.9575180719999998,0.9778004389999998,0.9974349629999999,1.0161374230000002,1.0371451720000002,1.1666701480000004,2.250862075000001,5.966484670999999,12.879900560800005,20.592172412000004,24.042244947,19.470110064999997,7.324775633,-8.013183978799999,-20.6681403362,-26.9779757058,-26.909867789000003,-22.7293312442,-16.9641049529,-11.418605780400002,-7.001344819210001,-3.9266593179099996,-2.0149885553699995,-0.9443304889200002,-0.4039790811,-0.16002736371299997,-0.06171746270899998,-0.025761063903399994,-0.011875130514799997,-0.0053241077502200005,-0.00205456946709,-0.00017071601423520002,-0.00010105296083399999,-0.000226570376312,-0.000186611240788,4.3499331120000015e-07,2.127716577e-07,-2.1503892200000003e-07,3.539106193e-07,3.1053418549999995e-07,6.860861525e-07,3.5306020399999996e-07,6.252263633000001e-07,1.0712758314999999e-06,6.119958957e-07,1.0622040211999998e-06,5.065312979999999e-07,5.019957054e-07,1.3872952030000004e-07,-3.9350672759999994e-07,-2.1470912190000007e-07,-4.694870873000001e-07,-1.5120308489999998e-07,-2.3398725910000005e-07,1.2323115000000001e-07,2.419257099e-07,4.929234296000001e-07,2.0110098218000002e-07,2.646059073e-07,2.846406283e-07,1.9807651430000003e-07,-5.195725465e-07,-1.4685612619999997e-07,-3.5249335800000006e-07,-1.961860523e-07,-3.288687009999998e-08,-2.3247556780000008e-07,2.5043083379999996e-07,2.8917445200000016e-08,2.0620405120000005e-07,5.135248463099998e-07,6.817383027e-07,7.477015014e-07,1.0565363060000003e-07,3.451220324999999e-07,-1.8522364699999968e-08,-6.74739324e-08,-3.388855693999999e-07,-4.1582848999999675e-09,-3.4361038109999997e-07,4.536105581e-07,1.1831662709999995e-07,5.632331215000001e-07,2.7745921349999995e-07,4.037132008e-07,4.902771950999999e-07],
13+
14+
w_resp: [
15+
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.29333333333333333,0.88,2.0533333333333332,3.813333333333333,6.746666666666666,11.44,18.186666666666664,26.986666666666665,36.666666666666664,46.05333333333333,52.8,55.43999999999999,52.8,46.05333333333333,36.666666666666664,26.986666666666665,18.186666666666664,11.44,6.746666666666666,3.813333333333333,2.0533333333333337,0.88,0.29333333333333333,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],
1316
}

sbndcode/WireCell/cfg/pgrapher/experiment/sbnd/nf-data.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function(params, anode, chndbobj, n, name='', dft=default_dft)
2828
anode: wc.tn(anode),
2929
dft: wc.tn(dft),
3030
rms_threshold: 0.0,
31+
correlation_threshold: 1.0,
32+
default_scaling: 1.0,
3133
},
3234
},
3335
local sticky = {

sbndcode/WireCell/cfg/pgrapher/experiment/sbnd/nf.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function(params, anode, chndbobj, n, name='', dft=default_dft)
2828
anode: wc.tn(anode),
2929
dft: wc.tn(dft),
3030
rms_threshold: 0.0,
31+
correlation_threshold: 1.0,
32+
default_scaling: 1.0,
3133
},
3234
},
3335
local sticky = {

sbndcode/WireCell/cfg/pgrapher/experiment/sbnd/wcls-sim-drift-depoflux-nf-sp.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ local wcls_depoflux_writer = g.pnode({
127127
anodes: [wc.tn(anode) for anode in tools.anodes],
128128
field_response: wc.tn(tools.field),
129129
tick: 0.5 * wc.us,
130-
window_start: 0.0 * wc.ms,
130+
window_start: params.sim.tick0_time, // -205 * wc.us,
131131
window_duration: self.tick * params.daq.nticks,
132132
nsigma: 3.0,
133133

134-
reference_time: -1700 * wc.us,
134+
reference_time: - 1700 * wc.us - self.window_start, // target is tick 410 should be 3400
135135

136136
//energy: 1, # equivalent to use_energy = true
137137
simchan_label: 'simpleSC',

0 commit comments

Comments
 (0)