Skip to content

Commit 6b6d5cf

Browse files
author
Shweta Yadav
committed
yz normalization feature
1 parent 551edf2 commit 6b6d5cf

5 files changed

Lines changed: 183 additions & 0 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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_except::cetlib_except
13+
ROOT::Core
14+
ROOT::Hist
15+
)
16+
17+
cet_build_plugin(NormalizeYZ art::tool LIBRARIES ${TOOL_LIBRARIES})
18+
19+
install_headers()
20+
install_fhicl()
21+
install_source()
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
TFile* f = TFile::Open(fFileName.c_str(), "READ");
69+
if (!f || f->IsZombie()) {
70+
throw cet::exception("NormalizeYZ") << "Failed to open correction map file: " << fFileName;
71+
}
72+
73+
for (int plane = 0; plane < 3; plane++){ // planes : 2 inductions (idx : 0, 1) and 1 collection (idx : 2)
74+
for (int tpc = 0; tpc < 2; tpc++){ // tpc : east (idx : 0) and west (idx : 1) TPCs
75+
std::string histname = Form("CzyHist_%d_%d", plane, tpc);
76+
TH2F* h = (TH2F*)f->Get(histname.c_str());
77+
if (!h) {
78+
throw cet::exception("NormalizeYZ") << "Missing histogram in file: " << histname;
79+
}
80+
81+
fCorrHists[Form("plane%d_%d", plane, tpc)] = (TH2F*)h->Clone();
82+
fCorrHists[Form("plane%d_%d", plane, tpc)]->SetDirectory(nullptr);
83+
}
84+
}
85+
f->Close();
86+
}
87+
88+
double NormalizeYZ::Normalize(double dQdx,
89+
const art::Event& evt,
90+
const recob::Hit& hit,
91+
const geo::Point_t& location,
92+
const geo::Vector_t&,
93+
double){
94+
95+
int plane = hit.WireID().Plane;
96+
//int tpc = hit.WireID().TPC;
97+
98+
// just to be sure and consistent with the logic of input YZ map
99+
// seems like current setup of directly calling hit.WireID().TPC has a tolerance of 30cm
100+
// meaning - an approx region of -30<x<30 lies in both the TPCs
101+
int tpc;
102+
if(location.X()<0){
103+
tpc = 0;
104+
} else tpc = 1;
105+
106+
107+
std::string key = Form("plane%d_%d", plane, tpc);
108+
109+
auto it = fCorrHists.find(key);
110+
if (it == fCorrHists.end()) {
111+
mf::LogWarning("NormalizeYZ") << "No correction histogram for " << key << ". Returning uncorrected dQdx";
112+
return dQdx;
113+
}
114+
115+
TH2F* hCorr = it->second;
116+
int binX = hCorr->GetXaxis()->FindBin(location.Z());
117+
int binY = hCorr->GetYaxis()->FindBin(location.Y());
118+
double scale = hCorr->GetBinContent(binX, binY);
119+
120+
if (fVerbose){
121+
std::cout << "[NormalizeYZ] Plane: " << plane << ", TPC: " << tpc
122+
<< ", Y: " << location.Y() << ", Z: " << location.Z()
123+
<< ", Scale: " << scale << ", dQdx (raw): " << dQdx
124+
<< ", dQdx (corrected): " << dQdx / scale << std::endl;
125+
}
126+
127+
if (scale < 1e-3){
128+
mf::LogWarning("NormalizeYZ") << "Invalid scale at (Y,Z)=(" << location.Y() << "," << location.Z() << "). Returning uncorrected dQdx";
129+
return dQdx;
130+
}
131+
132+
return dQdx / scale;
133+
}
134+
135+
DEFINE_ART_CLASS_TOOL(NormalizeYZ)
136+
137+
} // namespace calo
138+
} // namespace sbnd
139+
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: "root://fndcadoor.fnal.gov:1094/pnfs/fnal.gov/usr/sbnd/persistent/stash/users/yadav/yz_correction_map_data1e20.root"
6+
Verbose: false
7+
}
8+
9+
yznorm_hist_mc: {
10+
tool_type: NormalizeYZ
11+
FileName: "root://fndcadoor.fnal.gov:1094/pnfs/fnal.gov/usr/sbnd/persistent/stash/users/yadav/yz_correction_map_mcp2025b5e18.root"
12+
Verbose: false
13+
}
14+
15+
# list of normalization tools - by far only YZ
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

0 commit comments

Comments
 (0)