From dffdf86fa49976c82cbfa3fec136aa017f825742 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Mon, 6 Jul 2026 13:20:34 -0500 Subject: [PATCH 01/19] typo in path --- sbndcode/JobConfigurations/standard/reco/reco2_data.fcl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl b/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl index 9d7a95dba..40d496d7c 100755 --- a/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl +++ b/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl @@ -63,8 +63,9 @@ physics.producers.opt0finderSCE.CaloProducer: "pandoraSCECaloData" physics.producers.pandoraSCEShower.PFParticleLabel: "pandoraSCE" physics.producers.pandoraSCEShowerSBN.PFParticleLabel: "pandoraSCE" - +physics.producers.blipreco.BlipAlg.CaloAlg: @local::sbnd_calorimetryalgdata physics.caloskimana: [ caloskim, crtana ] physics.ana: @local::sbnd_reco2_analyzer_sequence +physics.ana.blipana.BlipAlg.CaloAlg: @local::sbnd_calorimetryalgdata physics.end_paths: [stream1, caloskimana, ana ] From 40b11976198901c8b7c4e5cef7d9dcf66f648636 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Mon, 6 Jul 2026 15:08:41 -0500 Subject: [PATCH 02/19] Added new blip energy records --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 18 +++++++++++------- sbndcode/BlipRecoSBND/BlipAna_module.cc | 12 ++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index 9fb94f9d3..ca48e33b2 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -272,7 +272,7 @@ namespace blip { fCalodEdx = pset.get ("CalodEdx", 2.8); fESTAR_p0 = pset.get ("ESTAR_p0", 0.01730); fESTAR_p1 = pset.get ("ESTAR_p1", 0.00003479); - fLifetimeCorr = pset.get ("LifetimeCorrection", false); + fLifetimeCorr = pset.get ("LifetimeCorrection", true); fSCECorr = pset.get ("SCECorrection", false); fYZUniformityCorr = pset.get ("YZUniformityCorrection",true); fModBoxA = pset.get ("ModBoxA", 0.93); @@ -1141,12 +1141,18 @@ namespace blip { // ================================================================================ float depEl = std::max(0.0,(double)blip.Charge); float Efield = kNominalEfield; - + float recomb = ModBoxRecomb(fCalodEdx,Efield); + blip.EnergyNoDriftCorrection = depEl * (1./recomb) * kWion; + // METHOD 2: recombination factor using dE/dx from NIST tables (dE/dx = kinetic energy / CSDA) + float energy_estar = Q_to_E_ESTAR(depEl); + float energy_pstar = Q_to_E_PSTAR(depEl); + blip.EnergyESTARNoDriftCorrection = energy_estar; + blip.EnergyPSTARNoDriftCorrection = energy_pstar; // --- Lifetime correction --- // Ddisabled by default. Without knowing real T0 of a blip, attempting to // apply this correction can do more harm than good! Note lifetime is in // units of 'ms', not microseconds, hence the 1E-3 conversion factor. - if( fLifetimeCorr && blip.Time>0 ) depEl *= exp( 1e-3*blip.Time/detProp.ElectronLifetime()); + if( fLifetimeCorr ) depEl *= exp( 1e-3*blip.Time/detProp.ElectronLifetime()); // --- SCE corrections --- geo::Point_t point( blip.Position.X(),blip.Position.Y(),blip.Position.Z() ); @@ -1178,12 +1184,10 @@ namespace blip { } // METHOD 1: recombination factor from Mod Box model with a fixed dE/dx (fCalodEdx) - float recomb = ModBoxRecomb(fCalodEdx,Efield); blip.Energy = depEl * (1./recomb) * kWion; - // METHOD 2: recombination factor using dE/dx from NIST tables (dE/dx = kinetic energy / CSDA) - float energy_estar = Q_to_E_ESTAR(depEl); - float energy_pstar = Q_to_E_PSTAR(depEl); + energy_estar = Q_to_E_ESTAR(depEl); + energy_pstar = Q_to_E_PSTAR(depEl); //reaculate after drift correction blip.EnergyESTAR = energy_estar; blip.EnergyPSTAR = energy_pstar; //std::cout<<"Calculating ESTAR energy dep... "<Branch("blip_energy",blip_energy,"blip_energy[nblips]/F"); evtTree->Branch("blip_energy_estar",blip_energy_estar,"blip_energy_estar[nblips]/F"); evtTree->Branch("blip_energy_pstar",blip_energy_pstar,"blip_energy_pstar[nblips]/F"); + evtTree->Branch("blip_energy_nodriftcorr",blip_energy_nodriftcorr,"blip_energy_nodriftcorr[nblips]/F"); + evtTree->Branch("blip_energy_estar_nodriftcorr",blip_energy_estar_nodriftcorr,"blip_energy_estar_nodriftcorr[nblips]/F"); + evtTree->Branch("blip_energy_pstar_nodriftcorr",blip_energy_pstar_nodriftcorr,"blip_energy_pstar_nodriftcorr[nblips]/F"); //evtTree->Branch("blip_yzcorr",blip_yzcorr,"blip_yzcorr[nblips]/F"); //evtTree->Branch("blip_energyTrue",blip_energyTrue,"blip_energyTrue[nblips]/F"); evtTree->Branch("blip_incylinder",blip_incylinder,"blip_incylinder[nblips]/O"); @@ -1369,6 +1378,9 @@ void BlipAna::analyze(const art::Event& evt) fData->blip_energy[i] = blp.Energy; fData->blip_energy_estar[i]= blp.EnergyESTAR; fData->blip_energy_pstar[i]= blp.EnergyPSTAR; + fData->blip_energy_nodriftcorr[i] = blp.EnergyNoDriftCorrection; + fData->blip_energy_estar_nodriftcorr[i]= blp.EnergyESTARNoDriftCorrection; + fData->blip_energy_pstar_nodriftcorr[i]= blp.EnergyPSTARNoDriftCorrection; //fData->blip_yzcorr[i] = tpcCalib.YZdqdxCorrection(fCaloPlane,blp.Position.Y(),blp.Position.Z()); From 3d01043196bdec9b0e22cf645240d8b5948a70c6 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Thu, 9 Jul 2026 16:52:19 -0500 Subject: [PATCH 03/19] turning on lifetime correction by default --- sbndcode/BlipRecoSBND/blipreco_configs.fcl | 2 +- sbndcode/OpDetSim/CMakeLists.txt | 2 +- ups/product_deps | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sbndcode/BlipRecoSBND/blipreco_configs.fcl b/sbndcode/BlipRecoSBND/blipreco_configs.fcl index 01329758a..abf03428f 100644 --- a/sbndcode/BlipRecoSBND/blipreco_configs.fcl +++ b/sbndcode/BlipRecoSBND/blipreco_configs.fcl @@ -29,7 +29,7 @@ sbnd_blipalg: CalodEdx: 2.8 #// assumed dE/dx for MeV-scale recombination corrections ESTAR_p0: 0.01730 #// p0 for electrons to energy conversion function using ESTAR table ESTAR_p1: 0.00003479 #// p1 for electrons to energy conversion function using ESTAR table - LifetimeCorrection: false #// correct blips for lifetime (assumes T0 = 0) + LifetimeCorrection: true #// correct blips for lifetime (assumes T0 = 0) SCECorrection: false #// correct blips for space charge (requires known XYZ) CaloAlg: @local::sbnd_calorimetryalgmc diff --git a/sbndcode/OpDetSim/CMakeLists.txt b/sbndcode/OpDetSim/CMakeLists.txt index 35c22cf77..78740226d 100755 --- a/sbndcode/OpDetSim/CMakeLists.txt +++ b/sbndcode/OpDetSim/CMakeLists.txt @@ -9,7 +9,7 @@ cet_build_plugin( sbndPDMapAlg art::tool lardataobj::RawData lardata::DetectorInfoServices_DetectorClocksServiceStandard_service larpandora::LArPandoraInterface - sbncode::OpDet_PDMapAlgSimple_tool + sbncode::OpDet_PDMapAlg sbndcode_Utilities_SignalShapingServiceSBND_service nurandom::RandomUtils_NuRandomService_service art::Framework_Services_Optional_RandomNumberGenerator_service diff --git a/ups/product_deps b/ups/product_deps index 4efe01d36..1b16c7d38 100644 --- a/ups/product_deps +++ b/ups/product_deps @@ -253,7 +253,7 @@ wpdir product_dir wire-cell-cfg # #################################### product version qual flags -sbncode v10_21_00 - +sbncode v10_21_02 - cetmodules v3_24_01 - only_for_build sbnd_data v01_42_00 - sbndutil v10_06_01 - optional From 0ea14ac98cf1e3a31145bb4b837e1e2e30bd5e24 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 10:05:42 -0500 Subject: [PATCH 04/19] thought I fixed this --- sbndcode/JobConfigurations/standard/reco/reco2_data.fcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl b/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl index 40d496d7c..45b5bbb0f 100755 --- a/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl +++ b/sbndcode/JobConfigurations/standard/reco/reco2_data.fcl @@ -67,5 +67,5 @@ physics.producers.blipreco.BlipAlg.CaloAlg: @local::sbnd_calorimetryalgdata physics.caloskimana: [ caloskim, crtana ] physics.ana: @local::sbnd_reco2_analyzer_sequence -physics.ana.blipana.BlipAlg.CaloAlg: @local::sbnd_calorimetryalgdata +physics.analyzers.blipana.BlipAlg.CaloAlg: @local::sbnd_calorimetryalgdata physics.end_paths: [stream1, caloskimana, ana ] From 547f42a05c287b02d2c0335bb6e0d565d0ccbfe8 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 12:43:13 -0500 Subject: [PATCH 05/19] Updated Blip Lifetime lookups --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 16 +++++++++++++--- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index ca48e33b2..85c0dda4b 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -219,6 +219,7 @@ namespace blip { BlipRecoAlg::~BlipRecoAlg() { delete fCaloAlg; + delete ElifetimeTool; } @@ -268,6 +269,7 @@ namespace blip { fCylinderRadius = pset.get ("CylinderRadius", 15); fCaloAlg = new calo::CalorimetryAlg( pset.get("CaloAlg") ); + ElifetimeTool = new sbnd::calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")) fCaloPlane = pset.get ("CaloPlane", 2); fCalodEdx = pset.get ("CalodEdx", 2.8); fESTAR_p0 = pset.get ("ESTAR_p0", 0.01730); @@ -311,7 +313,6 @@ namespace blip { std::cout<<"\n" <<"=========== BlipRecoAlg =========================\n" <<"Event "<()->DataFor(evt); //auto const& lifetime_provider = art::ServiceHandle()->GetProvider(); //auto const& tpcCalib_provider = art::ServiceHandle()->GetProvider(); + //Elifetime + ElifetimeTool->setup(evt); // -- geometry art::ServiceHandle geom; @@ -1152,7 +1155,15 @@ namespace blip { // Ddisabled by default. Without knowing real T0 of a blip, attempting to // apply this correction can do more harm than good! Note lifetime is in // units of 'ms', not microseconds, hence the 1E-3 conversion factor. - if( fLifetimeCorr ) depEl *= exp( 1e-3*blip.Time/detProp.ElectronLifetime()); + double tau = 0 + if(plist.size()==0) //Data and should use calibration db + { + EventTPCLifetimes = ElifetimeTool->GetRunInfo(evt.id().run()); + if(blip.tpc==0) tau = EventTPCLifetimes.tau_E; + else tau = EventTPCLifetimes.tau_W; //west + } + else tau = detProp.ElectronLifetime(); + if( fLifetimeCorr ) depEl *= exp( 1e-3*blip.Time/tau); // --- SCE corrections --- geo::Point_t point( blip.Position.X(),blip.Position.Y(),blip.Position.Z() ); @@ -1289,5 +1300,4 @@ namespace blip { printf("\n"); } - } diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h index 330fb9486..95ffa9de7 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h @@ -187,6 +187,8 @@ namespace blip { bool fYZUniformityCorr; float fModBoxA; float fModBoxB; + sbnd::calo::NormalizeDriftSQLite* ElifetimeTool; + sbnd::calo::NormalizeDriftSQLite::RunInfo EventTPCLifetimes; // --- Splines for calo TSpline3* spline_PSTAR; From e005f72461e3d065ca15980e91d11c528a4e845b Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 12:48:43 -0500 Subject: [PATCH 06/19] A best guess at CMAKE. This Normalize drift tool is not made to be easily shared --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h | 2 ++ sbndcode/BlipRecoSBND/Alg/CMakeLists.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h index 95ffa9de7..47708a880 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h @@ -57,6 +57,8 @@ // Blip-specific utils #include "sbndcode/BlipRecoSBND/Utils/BlipUtils.h" #include "sbnobj/SBND/Blip/BlipDataTypes.h" +//electron lifetime includes +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc" //Danger of double definition // ROOT stuff #include "TH1D.h" diff --git a/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt b/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt index 1be1ed923..4c92d3c0b 100644 --- a/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt +++ b/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt @@ -36,6 +36,7 @@ art_make_library(LIBRARY_NAME sbndcode_BlipRecoAlg sbnobj::Common_CRT sbndcode_BlipUtils sbnobj::SBND_Blip + NormalizeDriftSQLite ) install_headers() From d4ad1fe7fd0664e6b5058193f104249b87dd216f Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:06:53 -0500 Subject: [PATCH 07/19] missed a ; --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index 85c0dda4b..76c852412 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -1155,7 +1155,7 @@ namespace blip { // Ddisabled by default. Without knowing real T0 of a blip, attempting to // apply this correction can do more harm than good! Note lifetime is in // units of 'ms', not microseconds, hence the 1E-3 conversion factor. - double tau = 0 + double tau = 0; if(plist.size()==0) //Data and should use calibration db { EventTPCLifetimes = ElifetimeTool->GetRunInfo(evt.id().run()); From 4ca4634b982d7d1e6d6efa2929a255af52d003a5 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:11:50 -0500 Subject: [PATCH 08/19] Moving useful tools to public --- .../NormalizeDriftSQLite_tool.cc | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc index 1a3529c01..4462a879d 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc @@ -19,7 +19,7 @@ #include "lardata/DetectorInfoServices/DetectorClocksService.h" // Lab helpers -#include "wda.h" +//#include "wda.h" // C++ #include @@ -37,6 +37,15 @@ class NormalizeDriftSQLite : public INormalizeCharge void configure(const fhicl::ParameterSet& pset) override; void setup(const art::Event& e) override; 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; + // Class to hold data from DB + class RunInfo { + public: + double tau_E; + double tau_W; + }; + + // Helpers + RunInfo GetRunInfo(uint64_t run); private: // Configuration @@ -48,16 +57,6 @@ class NormalizeDriftSQLite : public INormalizeCharge std::optional fClockData; // need delayed construction - // Class to hold data from DB - class RunInfo { - public: - double tau_E; - double tau_W; - }; - - // Helpers - RunInfo GetRunInfo(uint64_t run); - // Cache run requests std::map fRunInfos; }; From b519cf45c8305972ebb697b4b1789142244dd4d7 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:14:33 -0500 Subject: [PATCH 09/19] fixed two typo --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index 76c852412..47d66aa41 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -269,7 +269,7 @@ namespace blip { fCylinderRadius = pset.get ("CylinderRadius", 15); fCaloAlg = new calo::CalorimetryAlg( pset.get("CaloAlg") ); - ElifetimeTool = new sbnd::calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")) + ElifetimeTool = new sbnd::calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")); fCaloPlane = pset.get ("CaloPlane", 2); fCalodEdx = pset.get ("CalodEdx", 2.8); fESTAR_p0 = pset.get ("ESTAR_p0", 0.01730); @@ -1159,7 +1159,7 @@ namespace blip { if(plist.size()==0) //Data and should use calibration db { EventTPCLifetimes = ElifetimeTool->GetRunInfo(evt.id().run()); - if(blip.tpc==0) tau = EventTPCLifetimes.tau_E; + if(blip.TPC==0) tau = EventTPCLifetimes.tau_E; else tau = EventTPCLifetimes.tau_W; //west } else tau = detProp.ElectronLifetime(); From 3e6d2ff9c8f59cfac9ce71cb16473ebd4bbfe012 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:16:42 -0500 Subject: [PATCH 10/19] Guessed wrong on camkelist. We should make the E-Lifetime database tool easier to import --- sbndcode/BlipRecoSBND/Alg/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt b/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt index 4c92d3c0b..1be1ed923 100644 --- a/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt +++ b/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt @@ -36,7 +36,6 @@ art_make_library(LIBRARY_NAME sbndcode_BlipRecoAlg sbnobj::Common_CRT sbndcode_BlipUtils sbnobj::SBND_Blip - NormalizeDriftSQLite ) install_headers() From c974ccfd81b7fff30f58c27ab06603ef921f457f Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:23:29 -0500 Subject: [PATCH 11/19] trying other cmake links --- sbndcode/BlipRecoSBND/Alg/CMakeLists.txt | 1 + sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt b/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt index 1be1ed923..7320e94fc 100644 --- a/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt +++ b/sbndcode/BlipRecoSBND/Alg/CMakeLists.txt @@ -36,6 +36,7 @@ art_make_library(LIBRARY_NAME sbndcode_BlipRecoAlg sbnobj::Common_CRT sbndcode_BlipUtils sbnobj::SBND_Blip + sbndcode_GIMME_LIFETIMES ) install_headers() diff --git a/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt b/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt index efa89c74a..8206ecd0a 100644 --- a/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt +++ b/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt @@ -19,7 +19,9 @@ set(TOOL_LIBRARIES cet_build_plugin(NormalizeDriftSQLite art::tool LIBRARIES ${TOOL_LIBRARIES}) cet_build_plugin(NormalizeYZ art::tool LIBRARIES ${TOOL_LIBRARIES}) - +art_make_library(LIBRARY_NAME sbndcode_GIMME_LIFETIMES + SOURCE NormalizeDriftSQLite_tool.cc + LIBRARIES ${TOOL_LIBRARIES}) install_headers() install_fhicl() install_source() From 36c5b2b646e242b65246f3edd1168177f959276c Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:38:35 -0500 Subject: [PATCH 12/19] sorting out compiler issues --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h | 2 +- .../NormalizeDriftSQLite_tool.cc | 69 +------------------ 2 files changed, 2 insertions(+), 69 deletions(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h index 47708a880..d98a644e8 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h @@ -58,7 +58,7 @@ #include "sbndcode/BlipRecoSBND/Utils/BlipUtils.h" #include "sbnobj/SBND/Blip/BlipDataTypes.h" //electron lifetime includes -#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc" //Danger of double definition +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h" //Danger of double definition // ROOT stuff #include "TH1D.h" diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc index 4462a879d..638ccc0f7 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc @@ -1,71 +1,4 @@ -// Framework Includes -#include "art/Framework/Core/EDProducer.h" -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Services/Registry/ServiceHandle.h" -#include "art/Persistency/Common/PtrMaker.h" -#include "art/Utilities/ToolMacros.h" -#include "cetlib_except/exception.h" -#include "cetlib/cpu_timer.h" -#include "fhiclcpp/ParameterSet.h" -#include "messagefacility/MessageLogger/MessageLogger.h" - -#include "larevt/CalibrationDBI/Providers/DBFolder.h" - -// Tool include -#include "larreco/Calorimetry/INormalizeCharge.h" - -// Services -#include "lardata/DetectorInfoServices/DetectorClocksService.h" - -// Lab helpers -//#include "wda.h" - -// C++ -#include -#include -#include - -namespace sbnd { - namespace calo { - -class NormalizeDriftSQLite : public INormalizeCharge -{ -public: - NormalizeDriftSQLite(fhicl::ParameterSet const &pset); - - void configure(const fhicl::ParameterSet& pset) override; - void setup(const art::Event& e) override; - 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; - // Class to hold data from DB - class RunInfo { - public: - double tau_E; - double tau_W; - }; - - // Helpers - RunInfo GetRunInfo(uint64_t run); - -private: - // Configuration - std::string fDBFileName; - std::string fDBTag; - bool fVerbose; - - lariov::DBFolder fDB; - - std::optional fClockData; // need delayed construction - - // Cache run requests - std::map fRunInfos; -}; - -DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) - - } // end namespace calo -} // end namespace sbnd - +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h" sbnd::calo::NormalizeDriftSQLite::NormalizeDriftSQLite(fhicl::ParameterSet const &pset): fDBFileName(pset.get("DBFileName")), From 9bc90b7c7d67e1d4a9599d200ebc51399ee18175 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:39:41 -0500 Subject: [PATCH 13/19] missed this file --- .../NormalizeDriftSQLite_tool.h | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h new file mode 100644 index 000000000..6a871aafb --- /dev/null +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h @@ -0,0 +1,70 @@ +#ifndef NORMALIZEDRIFTSQLITE_TOOL_H +#define NORMALIZEDRIFTSQLITE_TOOL_H +// Framework Includes +#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "art/Persistency/Common/PtrMaker.h" +#include "art/Utilities/ToolMacros.h" +#include "cetlib_except/exception.h" +#include "cetlib/cpu_timer.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" + +#include "larevt/CalibrationDBI/Providers/DBFolder.h" + +// Tool include +#include "larreco/Calorimetry/INormalizeCharge.h" + +// Services +#include "lardata/DetectorInfoServices/DetectorClocksService.h" + +// Lab helpers +//#include "wda.h" + +// C++ +#include +#include +#include + +namespace sbnd { + namespace calo { + + class NormalizeDriftSQLite : public INormalizeCharge + { + public: + NormalizeDriftSQLite(fhicl::ParameterSet const &pset); + + void configure(const fhicl::ParameterSet& pset) override; + void setup(const art::Event& e) override; + 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; + // Class to hold data from DB + class RunInfo { + public: + double tau_E; + double tau_W; + }; + + // Helpers + RunInfo GetRunInfo(uint64_t run); + + private: + // Configuration + std::string fDBFileName; + std::string fDBTag; + bool fVerbose; + + lariov::DBFolder fDB; + + std::optional fClockData; // need delayed construction + + // Cache run requests + std::map fRunInfos; + }; + + DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) + + } // end namespace calo +} // end namespace sbnd +#endif From c1d8197e8194060ea5e8c3871c719636418699c0 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:41:35 -0500 Subject: [PATCH 14/19] maybe this stops two objects from being made --- sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt b/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt index 8206ecd0a..297c1dfd3 100644 --- a/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt +++ b/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt @@ -17,9 +17,9 @@ set(TOOL_LIBRARIES wda::wda ) -cet_build_plugin(NormalizeDriftSQLite art::tool LIBRARIES ${TOOL_LIBRARIES}) +#cet_build_plugin(NormalizeDriftSQLite art::tool LIBRARIES ${TOOL_LIBRARIES}) cet_build_plugin(NormalizeYZ art::tool LIBRARIES ${TOOL_LIBRARIES}) -art_make_library(LIBRARY_NAME sbndcode_GIMME_LIFETIMES +cet_make_library(LIBRARY_NAME sbndcode_GIMME_LIFETIMES SOURCE NormalizeDriftSQLite_tool.cc LIBRARIES ${TOOL_LIBRARIES}) install_headers() From c0174c672d267e1a41a4b63e691433666e630b28 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Fri, 10 Jul 2026 13:59:30 -0500 Subject: [PATCH 15/19] Is it double including EDproducer? Surely not --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 2 +- sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index 47d66aa41..787dd4b10 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -269,7 +269,7 @@ namespace blip { fCylinderRadius = pset.get ("CylinderRadius", 15); fCaloAlg = new calo::CalorimetryAlg( pset.get("CaloAlg") ); - ElifetimeTool = new sbnd::calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")); + ElifetimeTool = new calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")); fCaloPlane = pset.get ("CaloPlane", 2); fCalodEdx = pset.get ("CalodEdx", 2.8); fESTAR_p0 = pset.get ("ESTAR_p0", 0.01730); diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h index 6a871aafb..aca48044c 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h @@ -1,7 +1,7 @@ #ifndef NORMALIZEDRIFTSQLITE_TOOL_H #define NORMALIZEDRIFTSQLITE_TOOL_H // Framework Includes -#include "art/Framework/Core/EDProducer.h" +//#include "art/Framework/Core/EDProducer.h" #include "art/Framework/Principal/Event.h" #include "art/Framework/Principal/Handle.h" #include "art/Framework/Services/Registry/ServiceHandle.h" From f4ff8b7af53c6c8ef76bc0c9fc1c95c8a20b3e98 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Mon, 13 Jul 2026 13:59:27 -0500 Subject: [PATCH 16/19] A scuffed working implementation. I'll try to fix in next --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 4 +- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h | 2 +- .../Calibration/TPCCalorimetry/CMakeLists.txt | 4 +- .../NormalizeDriftSQLite_class.cc | 83 +++++++++++++++++++ .../NormalizeDriftSQLite_class.h | 70 ++++++++++++++++ 5 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc create mode 100644 sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index 787dd4b10..ff6973c82 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -269,7 +269,7 @@ namespace blip { fCylinderRadius = pset.get ("CylinderRadius", 15); fCaloAlg = new calo::CalorimetryAlg( pset.get("CaloAlg") ); - ElifetimeTool = new calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")); + ElifetimeTool = new sbnd::calo::NormalizeDriftSQLite( pset.get("NormalizeDrift")); fCaloPlane = pset.get ("CaloPlane", 2); fCalodEdx = pset.get ("CalodEdx", 2.8); fESTAR_p0 = pset.get ("ESTAR_p0", 0.01730); @@ -1164,7 +1164,7 @@ namespace blip { } else tau = detProp.ElectronLifetime(); if( fLifetimeCorr ) depEl *= exp( 1e-3*blip.Time/tau); - + std::cout << "Obtained this lifetime " << tau << " us " << std::endl; // --- SCE corrections --- geo::Point_t point( blip.Position.X(),blip.Position.Y(),blip.Position.Z() ); if( fSCECorr ) { diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h index d98a644e8..aa7ece4d2 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.h @@ -58,7 +58,7 @@ #include "sbndcode/BlipRecoSBND/Utils/BlipUtils.h" #include "sbnobj/SBND/Blip/BlipDataTypes.h" //electron lifetime includes -#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h" //Danger of double definition +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h" //Danger of double definition // ROOT stuff #include "TH1D.h" diff --git a/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt b/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt index 297c1dfd3..6d5093cec 100644 --- a/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt +++ b/sbndcode/Calibration/TPCCalorimetry/CMakeLists.txt @@ -17,10 +17,10 @@ set(TOOL_LIBRARIES wda::wda ) -#cet_build_plugin(NormalizeDriftSQLite art::tool LIBRARIES ${TOOL_LIBRARIES}) +cet_build_plugin(NormalizeDriftSQLite art::tool LIBRARIES ${TOOL_LIBRARIES}) cet_build_plugin(NormalizeYZ art::tool LIBRARIES ${TOOL_LIBRARIES}) cet_make_library(LIBRARY_NAME sbndcode_GIMME_LIFETIMES - SOURCE NormalizeDriftSQLite_tool.cc + SOURCE NormalizeDriftSQLite_class.cc LIBRARIES ${TOOL_LIBRARIES}) install_headers() install_fhicl() diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc new file mode 100644 index 000000000..ee4f31f52 --- /dev/null +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc @@ -0,0 +1,83 @@ +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h" + +sbnd::calo::NormalizeDriftSQLite::NormalizeDriftSQLite(fhicl::ParameterSet const &pset): + fDBFileName(pset.get("DBFileName")), + fDBTag(pset.get("DBTag")), + fVerbose(pset.get("Verbose", false)), + fDB(fDBFileName, "", "", fDBTag, true, false) +{} + +void sbnd::calo::NormalizeDriftSQLite::configure(const fhicl::ParameterSet& pset) {} + +void sbnd::calo::NormalizeDriftSQLite::setup(const art::Event& e) { + fClockData.emplace(art::ServiceHandle()->DataFor(e)); +} + +sbnd::calo::NormalizeDriftSQLite::RunInfo sbnd::calo::NormalizeDriftSQLite::GetRunInfo(uint64_t run) { + // check the cache + if (fRunInfos.count(run)) { + return fRunInfos.at(run); + } + + // Look up the run + // + // Translate the run into a fake "timestamp" + fDB.UpdateData((run+1000000000)*1000000000); + + RunInfo thisrun; + + double this_tau_E, this_tau_W; + fDB.GetNamedChannelData(0, "etau_sce_spatial_east", this_tau_E); + fDB.GetNamedChannelData(0, "etau_sce_spatial_west", this_tau_W); + thisrun.tau_E = this_tau_E; + thisrun.tau_W = this_tau_W; + + if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Lifetime Data:" << "\nTPC East: " << thisrun.tau_E << "\nTPC West: " << thisrun.tau_W << std::endl; + + // Set the cache + fRunInfos[run] = thisrun; + + return thisrun; +} + +double sbnd::calo::NormalizeDriftSQLite::Normalize(double dQdx, const art::Event &e, + const recob::Hit &hit, const geo::Point_t &location, const geo::Vector_t &direction, double t0) { + + if (!fClockData) { + std::cout << "Error: fClockData is not valid" << std::endl; + throw cet::exception("fClockData is not valid"); + } + + // Get the info + RunInfo runelifetime = GetRunInfo(e.id().runID().run()); + + // lookup the TPC + double thiselifetime = -1; + unsigned tpc = hit.WireID().TPC; + unsigned cryo = hit.WireID().Cryostat; + + // East + if (cryo == 0 && tpc == 0) thiselifetime = runelifetime.tau_E; + + // West + if (cryo == 0 && tpc == 1) thiselifetime = runelifetime.tau_W; + + // Get the hit time + double thit = fClockData->TPCTick2TrigTime(hit.PeakTime()) - t0; + thit = thit * 1.e-3; + + if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Norm factor: " << exp(thit / thiselifetime) << " at TPC: " << tpc << " Cryo: " << cryo << " Time: " << thit << " Track T0: " << t0 << ", x: " << location.X() << std::endl; + + // Scale + if (thiselifetime > 0) { + dQdx = dQdx*exp(thit / thiselifetime); + } + // Throw exception if thiselifetime is not updated to non-zero value + else { + std::cout << "sbnd::calo::NormalizeDriftSQLite::Normalize electron lifetime is not found for run " << e.id().runID().run() << std::endl; + throw cet::exception("Electron lifetime is not found"); + } + + return dQdx; +} + diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h new file mode 100644 index 000000000..18970cb53 --- /dev/null +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h @@ -0,0 +1,70 @@ +#ifndef NORMALIZEDRIFTSQLITE_CLASS_H +#define NORMALIZEDRIFTSQLITE_CLASS_H +// Framework Includes +//#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "art/Persistency/Common/PtrMaker.h" +#include "art/Utilities/ToolMacros.h" +#include "cetlib_except/exception.h" +#include "cetlib/cpu_timer.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" + +#include "larevt/CalibrationDBI/Providers/DBFolder.h" + +// Tool include +#include "larreco/Calorimetry/INormalizeCharge.h" + +// Services +#include "lardata/DetectorInfoServices/DetectorClocksService.h" + +// Lab helpers +//#include "wda.h" + +// C++ +#include +#include +#include + +namespace sbnd { + namespace calo { + + class NormalizeDriftSQLite : public INormalizeCharge + { + public: + NormalizeDriftSQLite(fhicl::ParameterSet const &pset); + + void configure(const fhicl::ParameterSet& pset) override; + void setup(const art::Event& e) override; + 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; + // Class to hold data from DB + class RunInfo { + public: + double tau_E; + double tau_W; + }; + + // Helpers + RunInfo GetRunInfo(uint64_t run); + + private: + // Configuration + std::string fDBFileName; + std::string fDBTag; + bool fVerbose; + + lariov::DBFolder fDB; + + std::optional fClockData; // need delayed construction + + // Cache run requests + std::map fRunInfos; + }; + + //DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) + + } // end namespace calo +} // end namespace sbnd +#endif From 9819d3fa252f8be6d6c19c681804ca48799b340f Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Mon, 13 Jul 2026 14:06:54 -0500 Subject: [PATCH 17/19] trying to remove code duplication --- .../NormalizeDriftSQLite_Definitions.h | 67 +++++++++++++++ .../NormalizeDriftSQLite_Implementation.cc | 80 ++++++++++++++++++ .../NormalizeDriftSQLite_class.cc | 83 +------------------ .../NormalizeDriftSQLite_class.h | 68 +-------------- .../NormalizeDriftSQLite_tool.cc | 83 +------------------ .../NormalizeDriftSQLite_tool.h | 69 +-------------- 6 files changed, 152 insertions(+), 298 deletions(-) create mode 100644 sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h create mode 100644 sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Implementation.cc diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h new file mode 100644 index 000000000..4fae7e23a --- /dev/null +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h @@ -0,0 +1,67 @@ +// Framework Includes +//#include "art/Framework/Core/EDProducer.h" +#include "art/Framework/Principal/Event.h" +#include "art/Framework/Principal/Handle.h" +#include "art/Framework/Services/Registry/ServiceHandle.h" +#include "art/Persistency/Common/PtrMaker.h" +#include "art/Utilities/ToolMacros.h" +#include "cetlib_except/exception.h" +#include "cetlib/cpu_timer.h" +#include "fhiclcpp/ParameterSet.h" +#include "messagefacility/MessageLogger/MessageLogger.h" + +#include "larevt/CalibrationDBI/Providers/DBFolder.h" + +// Tool include +#include "larreco/Calorimetry/INormalizeCharge.h" + +// Services +#include "lardata/DetectorInfoServices/DetectorClocksService.h" + +// Lab helpers +//#include "wda.h" + +// C++ +#include +#include +#include + +namespace sbnd { + namespace calo { + + class NormalizeDriftSQLite : public INormalizeCharge + { + public: + NormalizeDriftSQLite(fhicl::ParameterSet const &pset); + + void configure(const fhicl::ParameterSet& pset) override; + void setup(const art::Event& e) override; + 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; + // Class to hold data from DB + class RunInfo { + public: + double tau_E; + double tau_W; + }; + + // Helpers + RunInfo GetRunInfo(uint64_t run); + + private: + // Configuration + std::string fDBFileName; + std::string fDBTag; + bool fVerbose; + + lariov::DBFolder fDB; + + std::optional fClockData; // need delayed construction + + // Cache run requests + std::map fRunInfos; + }; + + //DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) + + } // end namespace calo +} // end namespace sbnd \ No newline at end of file diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Implementation.cc b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Implementation.cc new file mode 100644 index 000000000..27151fcf8 --- /dev/null +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Implementation.cc @@ -0,0 +1,80 @@ +sbnd::calo::NormalizeDriftSQLite::NormalizeDriftSQLite(fhicl::ParameterSet const &pset): + fDBFileName(pset.get("DBFileName")), + fDBTag(pset.get("DBTag")), + fVerbose(pset.get("Verbose", false)), + fDB(fDBFileName, "", "", fDBTag, true, false) +{} + +void sbnd::calo::NormalizeDriftSQLite::configure(const fhicl::ParameterSet& pset) {} + +void sbnd::calo::NormalizeDriftSQLite::setup(const art::Event& e) { + fClockData.emplace(art::ServiceHandle()->DataFor(e)); +} + +sbnd::calo::NormalizeDriftSQLite::RunInfo sbnd::calo::NormalizeDriftSQLite::GetRunInfo(uint64_t run) { + // check the cache + if (fRunInfos.count(run)) { + return fRunInfos.at(run); + } + + // Look up the run + // + // Translate the run into a fake "timestamp" + fDB.UpdateData((run+1000000000)*1000000000); + + RunInfo thisrun; + + double this_tau_E, this_tau_W; + fDB.GetNamedChannelData(0, "etau_sce_spatial_east", this_tau_E); + fDB.GetNamedChannelData(0, "etau_sce_spatial_west", this_tau_W); + thisrun.tau_E = this_tau_E; + thisrun.tau_W = this_tau_W; + + if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Lifetime Data:" << "\nTPC East: " << thisrun.tau_E << "\nTPC West: " << thisrun.tau_W << std::endl; + + // Set the cache + fRunInfos[run] = thisrun; + + return thisrun; +} + +double sbnd::calo::NormalizeDriftSQLite::Normalize(double dQdx, const art::Event &e, + const recob::Hit &hit, const geo::Point_t &location, const geo::Vector_t &direction, double t0) { + + if (!fClockData) { + std::cout << "Error: fClockData is not valid" << std::endl; + throw cet::exception("fClockData is not valid"); + } + + // Get the info + RunInfo runelifetime = GetRunInfo(e.id().runID().run()); + + // lookup the TPC + double thiselifetime = -1; + unsigned tpc = hit.WireID().TPC; + unsigned cryo = hit.WireID().Cryostat; + + // East + if (cryo == 0 && tpc == 0) thiselifetime = runelifetime.tau_E; + + // West + if (cryo == 0 && tpc == 1) thiselifetime = runelifetime.tau_W; + + // Get the hit time + double thit = fClockData->TPCTick2TrigTime(hit.PeakTime()) - t0; + thit = thit * 1.e-3; + + if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Norm factor: " << exp(thit / thiselifetime) << " at TPC: " << tpc << " Cryo: " << cryo << " Time: " << thit << " Track T0: " << t0 << ", x: " << location.X() << std::endl; + + // Scale + if (thiselifetime > 0) { + dQdx = dQdx*exp(thit / thiselifetime); + } + // Throw exception if thiselifetime is not updated to non-zero value + else { + std::cout << "sbnd::calo::NormalizeDriftSQLite::Normalize electron lifetime is not found for run " << e.id().runID().run() << std::endl; + throw cet::exception("Electron lifetime is not found"); + } + + return dQdx; +} diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc index ee4f31f52..d20e8318a 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.cc @@ -1,83 +1,2 @@ #include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h" - -sbnd::calo::NormalizeDriftSQLite::NormalizeDriftSQLite(fhicl::ParameterSet const &pset): - fDBFileName(pset.get("DBFileName")), - fDBTag(pset.get("DBTag")), - fVerbose(pset.get("Verbose", false)), - fDB(fDBFileName, "", "", fDBTag, true, false) -{} - -void sbnd::calo::NormalizeDriftSQLite::configure(const fhicl::ParameterSet& pset) {} - -void sbnd::calo::NormalizeDriftSQLite::setup(const art::Event& e) { - fClockData.emplace(art::ServiceHandle()->DataFor(e)); -} - -sbnd::calo::NormalizeDriftSQLite::RunInfo sbnd::calo::NormalizeDriftSQLite::GetRunInfo(uint64_t run) { - // check the cache - if (fRunInfos.count(run)) { - return fRunInfos.at(run); - } - - // Look up the run - // - // Translate the run into a fake "timestamp" - fDB.UpdateData((run+1000000000)*1000000000); - - RunInfo thisrun; - - double this_tau_E, this_tau_W; - fDB.GetNamedChannelData(0, "etau_sce_spatial_east", this_tau_E); - fDB.GetNamedChannelData(0, "etau_sce_spatial_west", this_tau_W); - thisrun.tau_E = this_tau_E; - thisrun.tau_W = this_tau_W; - - if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Lifetime Data:" << "\nTPC East: " << thisrun.tau_E << "\nTPC West: " << thisrun.tau_W << std::endl; - - // Set the cache - fRunInfos[run] = thisrun; - - return thisrun; -} - -double sbnd::calo::NormalizeDriftSQLite::Normalize(double dQdx, const art::Event &e, - const recob::Hit &hit, const geo::Point_t &location, const geo::Vector_t &direction, double t0) { - - if (!fClockData) { - std::cout << "Error: fClockData is not valid" << std::endl; - throw cet::exception("fClockData is not valid"); - } - - // Get the info - RunInfo runelifetime = GetRunInfo(e.id().runID().run()); - - // lookup the TPC - double thiselifetime = -1; - unsigned tpc = hit.WireID().TPC; - unsigned cryo = hit.WireID().Cryostat; - - // East - if (cryo == 0 && tpc == 0) thiselifetime = runelifetime.tau_E; - - // West - if (cryo == 0 && tpc == 1) thiselifetime = runelifetime.tau_W; - - // Get the hit time - double thit = fClockData->TPCTick2TrigTime(hit.PeakTime()) - t0; - thit = thit * 1.e-3; - - if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Norm factor: " << exp(thit / thiselifetime) << " at TPC: " << tpc << " Cryo: " << cryo << " Time: " << thit << " Track T0: " << t0 << ", x: " << location.X() << std::endl; - - // Scale - if (thiselifetime > 0) { - dQdx = dQdx*exp(thit / thiselifetime); - } - // Throw exception if thiselifetime is not updated to non-zero value - else { - std::cout << "sbnd::calo::NormalizeDriftSQLite::Normalize electron lifetime is not found for run " << e.id().runID().run() << std::endl; - throw cet::exception("Electron lifetime is not found"); - } - - return dQdx; -} - +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Implementation.cc" \ No newline at end of file diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h index 18970cb53..dde2cfcc4 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_class.h @@ -1,70 +1,4 @@ #ifndef NORMALIZEDRIFTSQLITE_CLASS_H #define NORMALIZEDRIFTSQLITE_CLASS_H -// Framework Includes -//#include "art/Framework/Core/EDProducer.h" -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Services/Registry/ServiceHandle.h" -#include "art/Persistency/Common/PtrMaker.h" -#include "art/Utilities/ToolMacros.h" -#include "cetlib_except/exception.h" -#include "cetlib/cpu_timer.h" -#include "fhiclcpp/ParameterSet.h" -#include "messagefacility/MessageLogger/MessageLogger.h" - -#include "larevt/CalibrationDBI/Providers/DBFolder.h" - -// Tool include -#include "larreco/Calorimetry/INormalizeCharge.h" - -// Services -#include "lardata/DetectorInfoServices/DetectorClocksService.h" - -// Lab helpers -//#include "wda.h" - -// C++ -#include -#include -#include - -namespace sbnd { - namespace calo { - - class NormalizeDriftSQLite : public INormalizeCharge - { - public: - NormalizeDriftSQLite(fhicl::ParameterSet const &pset); - - void configure(const fhicl::ParameterSet& pset) override; - void setup(const art::Event& e) override; - 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; - // Class to hold data from DB - class RunInfo { - public: - double tau_E; - double tau_W; - }; - - // Helpers - RunInfo GetRunInfo(uint64_t run); - - private: - // Configuration - std::string fDBFileName; - std::string fDBTag; - bool fVerbose; - - lariov::DBFolder fDB; - - std::optional fClockData; // need delayed construction - - // Cache run requests - std::map fRunInfos; - }; - - //DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) - - } // end namespace calo -} // end namespace sbnd +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h" #endif diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc index 638ccc0f7..2a6bfa65e 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.cc @@ -1,83 +1,2 @@ #include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h" - -sbnd::calo::NormalizeDriftSQLite::NormalizeDriftSQLite(fhicl::ParameterSet const &pset): - fDBFileName(pset.get("DBFileName")), - fDBTag(pset.get("DBTag")), - fVerbose(pset.get("Verbose", false)), - fDB(fDBFileName, "", "", fDBTag, true, false) -{} - -void sbnd::calo::NormalizeDriftSQLite::configure(const fhicl::ParameterSet& pset) {} - -void sbnd::calo::NormalizeDriftSQLite::setup(const art::Event& e) { - fClockData.emplace(art::ServiceHandle()->DataFor(e)); -} - -sbnd::calo::NormalizeDriftSQLite::RunInfo sbnd::calo::NormalizeDriftSQLite::GetRunInfo(uint64_t run) { - // check the cache - if (fRunInfos.count(run)) { - return fRunInfos.at(run); - } - - // Look up the run - // - // Translate the run into a fake "timestamp" - fDB.UpdateData((run+1000000000)*1000000000); - - RunInfo thisrun; - - double this_tau_E, this_tau_W; - fDB.GetNamedChannelData(0, "etau_sce_spatial_east", this_tau_E); - fDB.GetNamedChannelData(0, "etau_sce_spatial_west", this_tau_W); - thisrun.tau_E = this_tau_E; - thisrun.tau_W = this_tau_W; - - if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Lifetime Data:" << "\nTPC East: " << thisrun.tau_E << "\nTPC West: " << thisrun.tau_W << std::endl; - - // Set the cache - fRunInfos[run] = thisrun; - - return thisrun; -} - -double sbnd::calo::NormalizeDriftSQLite::Normalize(double dQdx, const art::Event &e, - const recob::Hit &hit, const geo::Point_t &location, const geo::Vector_t &direction, double t0) { - - if (!fClockData) { - std::cout << "Error: fClockData is not valid" << std::endl; - throw cet::exception("fClockData is not valid"); - } - - // Get the info - RunInfo runelifetime = GetRunInfo(e.id().runID().run()); - - // lookup the TPC - double thiselifetime = -1; - unsigned tpc = hit.WireID().TPC; - unsigned cryo = hit.WireID().Cryostat; - - // East - if (cryo == 0 && tpc == 0) thiselifetime = runelifetime.tau_E; - - // West - if (cryo == 0 && tpc == 1) thiselifetime = runelifetime.tau_W; - - // Get the hit time - double thit = fClockData->TPCTick2TrigTime(hit.PeakTime()) - t0; - thit = thit * 1.e-3; - - if (fVerbose) std::cout << "NormalizeDriftSQLite Tool -- Norm factor: " << exp(thit / thiselifetime) << " at TPC: " << tpc << " Cryo: " << cryo << " Time: " << thit << " Track T0: " << t0 << ", x: " << location.X() << std::endl; - - // Scale - if (thiselifetime > 0) { - dQdx = dQdx*exp(thit / thiselifetime); - } - // Throw exception if thiselifetime is not updated to non-zero value - else { - std::cout << "sbnd::calo::NormalizeDriftSQLite::Normalize electron lifetime is not found for run " << e.id().runID().run() << std::endl; - throw cet::exception("Electron lifetime is not found"); - } - - return dQdx; -} - +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Implementation.cc" \ No newline at end of file diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h index aca48044c..fa7558d08 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h @@ -1,70 +1,5 @@ #ifndef NORMALIZEDRIFTSQLITE_TOOL_H #define NORMALIZEDRIFTSQLITE_TOOL_H -// Framework Includes -//#include "art/Framework/Core/EDProducer.h" -#include "art/Framework/Principal/Event.h" -#include "art/Framework/Principal/Handle.h" -#include "art/Framework/Services/Registry/ServiceHandle.h" -#include "art/Persistency/Common/PtrMaker.h" -#include "art/Utilities/ToolMacros.h" -#include "cetlib_except/exception.h" -#include "cetlib/cpu_timer.h" -#include "fhiclcpp/ParameterSet.h" -#include "messagefacility/MessageLogger/MessageLogger.h" - -#include "larevt/CalibrationDBI/Providers/DBFolder.h" - -// Tool include -#include "larreco/Calorimetry/INormalizeCharge.h" - -// Services -#include "lardata/DetectorInfoServices/DetectorClocksService.h" - -// Lab helpers -//#include "wda.h" - -// C++ -#include -#include -#include - -namespace sbnd { - namespace calo { - - class NormalizeDriftSQLite : public INormalizeCharge - { - public: - NormalizeDriftSQLite(fhicl::ParameterSet const &pset); - - void configure(const fhicl::ParameterSet& pset) override; - void setup(const art::Event& e) override; - 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; - // Class to hold data from DB - class RunInfo { - public: - double tau_E; - double tau_W; - }; - - // Helpers - RunInfo GetRunInfo(uint64_t run); - - private: - // Configuration - std::string fDBFileName; - std::string fDBTag; - bool fVerbose; - - lariov::DBFolder fDB; - - std::optional fClockData; // need delayed construction - - // Cache run requests - std::map fRunInfos; - }; - - DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) - - } // end namespace calo -} // end namespace sbnd +#include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h" +sbnd::calo::DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) #endif From fedb0a844517843421d1fd7e81b68ffa272d5c10 Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Mon, 13 Jul 2026 14:58:03 -0500 Subject: [PATCH 18/19] Think this is a slightly nicer implementation. Will check if it runs --- sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h index fa7558d08..25b67a3cc 100644 --- a/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h +++ b/sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_tool.h @@ -1,5 +1,5 @@ #ifndef NORMALIZEDRIFTSQLITE_TOOL_H #define NORMALIZEDRIFTSQLITE_TOOL_H #include "sbndcode/Calibration/TPCCalorimetry/NormalizeDriftSQLite_Definitions.h" -sbnd::calo::DEFINE_ART_CLASS_TOOL(NormalizeDriftSQLite) +DEFINE_ART_CLASS_TOOL(sbnd::calo::NormalizeDriftSQLite) #endif From f651fd6562e944c7f0e832e33fc000a2d82c4b6b Mon Sep 17 00:00:00 2001 From: Jacob McLaughlin Date: Mon, 13 Jul 2026 15:17:46 -0500 Subject: [PATCH 19/19] removed debug --- sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc index ff6973c82..d19210e88 100644 --- a/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc +++ b/sbndcode/BlipRecoSBND/Alg/BlipRecoAlg.cc @@ -1164,7 +1164,6 @@ namespace blip { } else tau = detProp.ElectronLifetime(); if( fLifetimeCorr ) depEl *= exp( 1e-3*blip.Time/tau); - std::cout << "Obtained this lifetime " << tau << " us " << std::endl; // --- SCE corrections --- geo::Point_t point( blip.Position.X(),blip.Position.Y(),blip.Position.Z() ); if( fSCECorr ) {