Skip to content

Commit bdf38e4

Browse files
committed
Reduce code duplication
1 parent cb47ee9 commit bdf38e4

2 files changed

Lines changed: 22 additions & 44 deletions

File tree

sbndcode/CRT/CRTAna/CRTAnalysis_module.cc

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
#include "sbnobj/SBND/Timing/DAQTimestamp.hh"
3838

3939
#include "sbndcode/Geometry/GeometryWrappers/CRTGeoService.h"
40-
#include "sbndcode/Geometry/GeometryWrappers/TPCGeoAlg.h"
4140
#include "sbndcode/ChannelMaps/CRT/CRTChannelMapService.h"
4241
#include "sbndcode/CRT/CRTBackTracker/CRTBackTrackerAlg.h"
4342
#include "sbndcode/CRT/CRTUtils/CRTCommonUtils.h"
4443
#include "sbndcode/CRT/CRTUtils/TPCGeoUtil.h"
4544
#include "sbndcode/Decoders/PTB/sbndptb.h"
4645
#include "sbndcode/Timing/SBNDRawTimingObj.h"
46+
#include "sbndcode/CRT/CRTReco/CRTClusterCharacterisationAlg.h"
4747

4848
namespace sbnd::crt {
4949
class CRTAnalysis;
@@ -103,16 +103,14 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
103103
art::ServiceHandle<CRTGeoService> fCRTGeoService;
104104
art::ServiceHandle<SBND::CRTChannelMapService> fCRTChannelMapService;
105105

106-
TPCGeoAlg fTPCGeoAlg;
107-
CRTBackTrackerAlg fCRTBackTrackerAlg;
106+
CRTBackTrackerAlg fCRTBackTrackerAlg;
107+
CRTClusterCharacterisationAlg fCRTClusterCharacAlg;
108108

109109
std::string fMCParticleModuleLabel, fSimDepositModuleLabel, fFEBDataModuleLabel, fCRTStripHitModuleLabel,
110110
fCRTClusterModuleLabel, fCRTSpacePointModuleLabel, fCRTTrackModuleLabel, fCRTBlobModuleLabel, fTPCTrackModuleLabel,
111111
fCRTSpacePointMatchingModuleLabel, fCRTTrackMatchingModuleLabel, fPFPModuleLabel, fPTBModuleLabel,
112112
fTDCModuleLabel, fTimingReferenceModuleLabel;
113113
bool fDebug, fDataMode, fNoTPC, fHasPTB, fHasTDC, fHasBlobs, fTruthMatch;
114-
//! Adding some of the reco parameters to save corrections
115-
double fPEAttenuation, fTimeWalkNorm, fTimeWalkScale, fPropDelay;
116114

117115
TTree* fTree;
118116

@@ -197,11 +195,11 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
197195
std::vector<uint8_t> _cl_composition;
198196
std::vector<std::vector<uint32_t>> _cl_channel_set;
199197
std::vector<std::vector<uint16_t>> _cl_adc_set;
200-
std::vector<std::vector<double>> _cl_sh_ts0_set; //! To store t0 from x-y coincidences
201-
std::vector<std::vector<double>> _cl_sh_ts1_set; //! To store t1 from x-y coincidences
202-
std::vector<std::vector<uint16_t>> _cl_sh_feb_mac5_set; //! MAC5 addresses of StripHit FEBs
203-
std::vector<std::vector<double>> _cl_sh_time_walk_set; //! Time walk correction
204-
std::vector<std::vector<double>> _cl_sh_prop_delay_set; //! Light propagation correction
198+
std::vector<std::vector<double>> _cl_sh_ts0_set;
199+
std::vector<std::vector<double>> _cl_sh_ts1_set;
200+
std::vector<std::vector<uint16_t>> _cl_sh_feb_mac5_set;
201+
std::vector<std::vector<double>> _cl_sh_time_walk_set;
202+
std::vector<std::vector<double>> _cl_sh_prop_delay_set;
205203
std::vector<int> _cl_truth_trackid;
206204
std::vector<double> _cl_truth_completeness;
207205
std::vector<double> _cl_truth_purity;
@@ -372,6 +370,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
372370
sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
373371
: EDAnalyzer{p}
374372
, fCRTBackTrackerAlg(p.get<fhicl::ParameterSet>("CRTBackTrackerAlg", fhicl::ParameterSet()))
373+
, fCRTClusterCharacAlg(p.get<fhicl::ParameterSet>("CRTClusterCharacterisationAlg", fhicl::ParameterSet()))
375374
{
376375
fMCParticleModuleLabel = p.get<std::string>("MCParticleModuleLabel", "largeant");
377376
fSimDepositModuleLabel = p.get<std::string>("SimDepositModuleLabel", "genericcrt");
@@ -395,10 +394,6 @@ sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
395394
fHasTDC = p.get<bool>("HasTDC", false);
396395
fHasBlobs = p.get<bool>("HasBlobs", false);
397396
fTruthMatch = p.get<bool>("TruthMatch", true);
398-
fPEAttenuation = p.get<double>("PEAttenuation", 1.0);
399-
fTimeWalkNorm = p.get<double>("TimeWalkNorm", 0.0);
400-
fTimeWalkScale = p.get<double>("TimeWalkScale", 0.0);
401-
fPropDelay = p.get<double>("PropDelay", 0.0);
402397

403398
if(!fDataMode && fTruthMatch)
404399
fCRTBackTrackerAlg = CRTBackTrackerAlg(p.get<fhicl::ParameterSet>("CRTBackTrackerAlg", fhicl::ParameterSet()));
@@ -1328,25 +1323,10 @@ void sbnd::crt::CRTAnalysis::AnalyseCRTClusters(const art::Event &e, const std::
13281323
_cl_sh_ts1_set[i][ii] = striphit->Ts1();
13291324
_cl_sh_feb_mac5_set[i][ii] = fCRTChannelMapService->GetMAC5FromOfflineChannelID(striphit->Channel());
13301325

1331-
/*
1332-
* The below segment reimplements the CorrectTime() method
1333-
* from CRTReco/CRTClusterCharacterisationAlg.cc .
1334-
* Because the Ts0(), Ts1() getters invoked in _cl_sp_ts*, _cl_sh_ts*_set are raw T0/1
1335-
* counters, the time walk and propagation delay are saved as explicit branches here.
1336-
*/
13371326
if(spacepoints.size() == 1)
13381327
{
1339-
double pe0 = fCRTGeoService->GetSiPM( striphit->Channel() ).gain * striphit->ADC1();
1340-
double pe1 = fCRTGeoService->GetSiPM( striphit->Channel() + 1 ).gain * striphit->ADC2();
1341-
double pe = pe0 + pe1;
1342-
1343-
double dist = fCRTGeoService->DistanceDownStrip( spacepoints[0]->Pos(), striphit->Channel() );
1344-
1345-
double corr = std::pow( dist - fPEAttenuation, 2.0 ) / std::pow( fPEAttenuation, 2.0 );
1346-
double tw_pe = pe * corr;
1347-
1348-
_cl_sh_time_walk_set[i][ii] = fTimeWalkNorm * std::exp( -fTimeWalkScale * tw_pe );
1349-
_cl_sh_prop_delay_set[i][ii] = fPropDelay * dist;
1328+
_cl_sh_time_walk_set[i][ii] = fCRTClusterCharacAlg.TimeWalk(striphit, spacepoints[0]->Pos());
1329+
_cl_sh_prop_delay_set[i][ii] = fCRTClusterCharacAlg.PropagationDelay(striphit, spacepoints[0]->Pos());
13501330

13511331
ts0_set.push_back({_cl_sh_feb_mac5_set[i][ii], _cl_sh_ts0_set[i][ii] - _cl_sh_time_walk_set[i][ii] - _cl_sh_prop_delay_set[i][ii]});
13521332
ts1_set.push_back({_cl_sh_feb_mac5_set[i][ii], _cl_sh_ts1_set[i][ii] - _cl_sh_time_walk_set[i][ii] - _cl_sh_prop_delay_set[i][ii]});
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#include "crtbacktrackeralg_sbnd.fcl"
2-
#include "crtsimmodules_sbnd.fcl"
2+
#include "crtrecoproducers_sbnd.fcl"
33

44
BEGIN_PROLOG
55

66
crtana_sbnd:
77
{
8-
CRTBackTrackerAlg: @local::crtbacktrackeralg_sbnd
9-
PEAttenuation: @local::sbnd_crtsim.DetSimParams.NpeScaleShift
10-
PropDelay: @local::sbnd_crtsim.DetSimParams.PropDelay
11-
TimeWalkNorm: @local::sbnd_crtsim.DetSimParams.TDelayNorm
12-
TimeWalkScale: @local::sbnd_crtsim.DetSimParams.TDelayScale
13-
TruthMatch: false
14-
module_type: "CRTAnalysis"
8+
CRTBackTrackerAlg: @local::crtbacktrackeralg_sbnd
9+
CRTClusterCharacterisationAlg: @local::crtclustercharacterisationalg_sbnd
10+
TruthMatch: false
11+
module_type: "CRTAnalysis"
1512
}
1613

1714
crtana_data_sbnd: @local::crtana_sbnd
18-
crtana_data_sbnd.FEBDataModuleLabel: "crtdecoder"
19-
crtana_data_sbnd.DataMode: true
20-
crtana_data_sbnd.NoTPC: false
21-
crtana_data_sbnd.HasPTB: true
22-
crtana_data_sbnd.HasTDC: true
15+
crtana_data_sbnd.FEBDataModuleLabel: "crtdecoder"
16+
crtana_data_sbnd.DataMode: true
17+
crtana_data_sbnd.NoTPC: false
18+
crtana_data_sbnd.HasPTB: true
19+
crtana_data_sbnd.HasTDC: true
20+
crtana_data_sbnd.CRTClusterCharacterisationAlg: @local::crtclustercharacterisationalg_data_sbnd
2321

2422
END_PROLOG

0 commit comments

Comments
 (0)