3636
3737#include " sbndcode/Geometry/GeometryWrappers/CRTGeoAlg.h"
3838#include " sbndcode/Geometry/GeometryWrappers/TPCGeoAlg.h"
39+ #include " sbndcode/ChannelMaps/CRT/CRTChannelMapService.h"
3940#include " sbndcode/CRT/CRTBackTracker/CRTBackTrackerAlg.h"
4041#include " sbndcode/CRT/CRTUtils/CRTCommonUtils.h"
4142#include " sbndcode/Decoders/PTB/sbndptb.h"
@@ -97,6 +98,8 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
9798 fCRTSpacePointMatchingModuleLabel , fCRTTrackMatchingModuleLabel , fPFPModuleLabel , fPTBModuleLabel ,
9899 fTDCModuleLabel , fTimingReferenceModuleLabel ;
99100 bool fDebug , fDataMode , fNoTPC , fHasPTB , fHasTDC ;
101+ // ! Adding some of the reco parameters to save corrections
102+ double fPEAttenuation , fTimeWalkNorm , fTimeWalkScale , fPropDelay ;
100103
101104 TTree* fTree ;
102105
@@ -181,6 +184,11 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
181184 std::vector<uint8_t > _cl_composition;
182185 std::vector<std::vector<uint32_t >> _cl_channel_set;
183186 std::vector<std::vector<uint16_t >> _cl_adc_set;
187+ std::vector<std::vector<uint32_t >> _cl_sh_ts0_set; // ! To store t0 from x-y coincidences
188+ std::vector<std::vector<uint32_t >> _cl_sh_ts1_set; // ! To store t1 from x-y coincidences
189+ std::vector<std::vector<uint16_t >> _cl_sh_feb_mac5_set; // ! MAC5 addresses of StripHit FEBs
190+ std::vector<std::vector<double >> _cl_sh_time_walk_set; // ! Time walk correction
191+ std::vector<std::vector<double >> _cl_sh_prop_delay_set; // ! Light propagation correction
184192 std::vector<int > _cl_truth_trackid;
185193 std::vector<double > _cl_truth_completeness;
186194 std::vector<double > _cl_truth_purity;
@@ -340,6 +348,11 @@ sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
340348 fNoTPC = p.get <bool >(" NoTPC" , false );
341349 fHasPTB = p.get <bool >(" HasPTB" , false );
342350 fHasTDC = p.get <bool >(" HasTDC" , false );
351+ // ! Adding some of the reco parameters to save corrections
352+ fPEAttenuation = p.get <double >(" PEAttenuation" , 1.0 );
353+ fTimeWalkNorm = p.get <double >(" TimeWalkNorm" , 0.0 );
354+ fTimeWalkScale = p.get <double >(" TimeWalkScale" , 0.0 );
355+ fPropDelay = p.get <double >(" PropDelay" , 0.0 );
343356
344357 if (!fDataMode )
345358 fCRTBackTrackerAlg = CRTBackTrackerAlg (p.get <fhicl::ParameterSet>(" CRTBackTrackerAlg" , fhicl::ParameterSet ()));
@@ -427,6 +440,11 @@ sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
427440 fTree ->Branch (" cl_composition" , " std::vector<uint8_t>" , &_cl_composition);
428441 fTree ->Branch (" cl_channel_set" , " std::vector<std::vector<uint32_t>>" , &_cl_channel_set);
429442 fTree ->Branch (" cl_adc_set" , " std::vector<std::vector<uint16_t>>" , &_cl_adc_set);
443+ fTree ->Branch (" cl_sh_ts0_set" , " std::vector<std::vector<uint32_t>>" , &_cl_sh_ts0_set);
444+ fTree ->Branch (" cl_sh_ts1_set" , " std::vector<std::vector<uint32_t>>" , &_cl_sh_ts1_set);
445+ fTree ->Branch (" cl_sh_feb_mac5_set" , " std::vector<std::vector<uint16_t>>" , &_cl_sh_feb_mac5_set);
446+ fTree ->Branch (" cl_sh_time_walk_set" , " std::vector<std::vector<double>>" , &_cl_sh_time_walk_set);
447+ fTree ->Branch (" cl_sh_prop_delay_set" , " std::vector<std::vector<double>>" , &_cl_sh_prop_delay_set);
430448 if (!fDataMode )
431449 {
432450 fTree ->Branch (" cl_truth_trackid" , " std::vector<int>" , &_cl_truth_trackid);
@@ -1093,6 +1111,11 @@ void sbnd::crt::CRTAnalysis::AnalyseCRTClusters(const art::Event &e, const std::
10931111 _cl_composition.resize (nClusters);
10941112 _cl_channel_set.resize (nClusters);
10951113 _cl_adc_set.resize (nClusters);
1114+ _cl_sh_ts0_set.resize (nClusters);
1115+ _cl_sh_ts1_set.resize (nClusters);
1116+ _cl_sh_feb_mac5_set.resize (nClusters);
1117+ _cl_sh_time_walk_set.resize (nClusters);
1118+ _cl_sh_prop_delay_set.resize (nClusters);
10961119 _cl_truth_trackid.resize (nClusters);
10971120 _cl_truth_completeness.resize (nClusters);
10981121 _cl_truth_purity.resize (nClusters);
@@ -1123,6 +1146,8 @@ void sbnd::crt::CRTAnalysis::AnalyseCRTClusters(const art::Event &e, const std::
11231146 _cl_sp_ets1.resize (nClusters);
11241147 _cl_sp_complete.resize (nClusters);
11251148
1149+ art::ServiceHandle<SBND ::CRTChannelMapService> ChannelMapService;
1150+
11261151 for (unsigned i = 0 ; i < nClusters; ++i)
11271152 {
11281153 const auto cluster = CRTClusterVec[i];
@@ -1134,16 +1159,52 @@ void sbnd::crt::CRTAnalysis::AnalyseCRTClusters(const art::Event &e, const std::
11341159 _cl_tagger[i] = cluster->Tagger ();
11351160 _cl_composition[i] = cluster->Composition ();
11361161
1162+ const auto spacepoints = clustersToSpacePoints.at (cluster.key ());
1163+
11371164 const auto striphits = clustersToStripHits.at (cluster.key ());
11381165 _cl_channel_set[i].resize (_cl_nhits[i]);
11391166 _cl_adc_set[i].resize (2 * _cl_nhits[i]);
1167+ _cl_sh_ts0_set[i].resize (_cl_nhits[i] );
1168+ _cl_sh_ts1_set[i].resize (_cl_nhits[i] );
1169+ _cl_sh_feb_mac5_set[i].resize (_cl_nhits[i]);
1170+ _cl_sh_time_walk_set[i].resize (_cl_nhits[i]);
1171+ _cl_sh_prop_delay_set[i].resize (_cl_nhits[i]);
11401172
11411173 for (unsigned ii = 0 ; ii < _cl_nhits[i]; ++ii)
11421174 {
11431175 const auto striphit = striphits[ii];
11441176 _cl_channel_set[i][ii] = striphit->Channel ();
11451177 _cl_adc_set[i][2 *ii] = striphit->ADC1 ();
11461178 _cl_adc_set[i][2 *ii+1 ] = striphit->ADC2 ();
1179+ _cl_sh_ts0_set[i][ii] = striphit->Ts0 ();
1180+ _cl_sh_ts1_set[i][ii] = striphit->Ts1 ();
1181+ SBND ::CRTChannelMapService::ModuleInfo_t module_info = ChannelMapService->GetModuleInfoFromOfflineID ( striphit->Channel () / 32 );
1182+ _cl_sh_feb_mac5_set[i][ii] = ( module_info.valid ) ? module_info.feb_mac5 : 0 ;
1183+
1184+ /*
1185+ * The below segment reimplements the CorrectTime() method
1186+ * from CRTReco/CRTClusterCharacterisationAlg.cc .
1187+ * Because the Ts0(), Ts1() getters invoked in _cl_sp_ts*, _cl_sh_ts*_set are raw T0/1
1188+ * counters, the time walk and propagation delay are saved as explicit branches here.
1189+ */
1190+ if (spacepoints.size () == 1 ) { // need unique position of spacepoint
1191+ double pe0 = fCRTGeoAlg .GetSiPM ( striphit->Channel () ).gain * striphit->ADC1 ();
1192+ double pe1 = fCRTGeoAlg .GetSiPM ( striphit->Channel () + 1 ).gain * striphit->ADC2 ();
1193+ double pe = pe0 + pe1;
1194+
1195+ double dist = fCRTGeoAlg .DistanceDownStrip ( spacepoints[0 ]->Pos (), striphit->Channel () );
1196+
1197+ double corr = std::pow ( dist - fPEAttenuation , 2.0 ) / std::pow ( fPEAttenuation , 2.0 );
1198+ double tw_pe = pe * corr;
1199+
1200+ _cl_sh_time_walk_set[i][ii] = fTimeWalkNorm * std::exp ( -fTimeWalkScale * tw_pe );
1201+ _cl_sh_prop_delay_set[i][ii] = fPropDelay * dist;
1202+
1203+ } else { // fill with nonsense
1204+ _cl_sh_time_walk_set[i][ii] = -999999 .;
1205+ _cl_sh_prop_delay_set[i][ii] = -999999 .;
1206+ }
1207+
11471208 }
11481209
11491210 if (!fDataMode )
@@ -1167,7 +1228,6 @@ void sbnd::crt::CRTAnalysis::AnalyseCRTClusters(const art::Event &e, const std::
11671228 _cl_truth_core_z[i] = truthMatch.deposit .coreZ ;
11681229 }
11691230
1170- const auto spacepoints = clustersToSpacePoints.at (cluster.key ());
11711231 if (spacepoints.size () == 1 )
11721232 {
11731233 const auto spacepoint = spacepoints[0 ];
0 commit comments