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
4848namespace 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
@@ -124,7 +122,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
124122 int _crt_timing_reference_type;
125123 int _crt_timing_reference_channel;
126124
127- // mc truth
125+ // True Particles (from G4)
128126 std::vector<int16_t > _mc_trackid;
129127 std::vector<int16_t > _mc_pdg;
130128 std::vector<int16_t > _mc_status;
@@ -147,7 +145,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
147145 std::vector<double > _mc_endpz;
148146 std::vector<double > _mc_ende;
149147
150- // G4 detector id
148+ // True Energy Depositions
151149 std::vector<int16_t > _ide_trackid;
152150 std::vector<float > _ide_e;
153151 std::vector<float > _ide_entryx;
@@ -159,7 +157,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
159157 std::vector<float > _ide_exitz;
160158 std::vector<float > _ide_exitt;
161159
162- // front end mother board
160+ // Raw Readouts (FEBDatas)
163161 std::vector<uint16_t > _feb_mac5;
164162 std::vector<int16_t > _feb_tagger;
165163 std::vector<uint16_t > _feb_flags;
@@ -169,7 +167,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
169167 std::vector<std::vector<uint16_t >> _feb_adc;
170168 std::vector<uint32_t > _feb_coinc;
171169
172- // strip hit to select the strip which has ADC above threshold
170+ // Strip Hits
173171 std::vector<uint32_t > _sh_channel;
174172 std::vector<int16_t > _sh_tagger;
175173 std::vector<double > _sh_ts0;
@@ -188,7 +186,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
188186 std::vector<double > _sh_truth_energy;
189187 std::vector<double > _sh_truth_time;
190188
191- // cluster from x-y coincidence for CRTSpacePoint , this is what we normally call a CRT hit
189+ // Clusters and their corresponding SpacePoints
192190 std::vector<double > _cl_ts0;
193191 std::vector<double > _cl_ts1;
194192 std::vector<uint32_t > _cl_unixs;
@@ -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;
@@ -234,7 +232,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
234232 std::vector<double > _cl_sp_dts1;
235233 std::vector<bool > _cl_sp_complete;
236234
237- // backtrack truth information from reco level
235+ // True Deposits per particle per tagger
238236 std::vector<int > _td_tag_trackid;
239237 std::vector<int > _td_tag_pdg;
240238 std::vector<int16_t > _td_tag_tagger;
@@ -245,6 +243,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
245243 std::vector<double > _td_tag_z;
246244 std::vector<bool > _td_tag_reco_status;
247245
246+ // True Deposits per particle
248247 std::vector<int > _td_trackid;
249248 std::vector<int > _td_pdg;
250249 std::vector<double > _td_energy;
@@ -253,7 +252,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
253252 std::vector<bool > _td_reco_status;
254253 std::vector<bool > _td_reco_triple;
255254
256- // track level information
255+ // Tracks
257256 std::vector<double > _tr_start_x;
258257 std::vector<double > _tr_start_y;
259258 std::vector<double > _tr_start_z;
@@ -299,7 +298,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
299298 std::vector<double > _tr_truth_theta;
300299 std::vector<double > _tr_truth_phi;
301300
302- // crt blob information
301+ // Blobs
303302 std::vector<double > _bl_ts0;
304303 std::vector<double > _bl_ets0;
305304 std::vector<double > _bl_ts1;
@@ -308,7 +307,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
308307 std::vector<int > _bl_nsps;
309308 std::vector<std::vector<int >> _bl_nsps_per_tagger;
310309
311- // tpc track information (including crt matching)
310+ // TPC Tracks and their CRT matches
312311 std::vector<double > _tpc_start_x;
313312 std::vector<double > _tpc_start_y;
314313 std::vector<double > _tpc_start_z;
@@ -323,6 +322,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
323322 std::vector<double > _tpc_end_dir_z;
324323 std::vector<double > _tpc_length;
325324 std::vector<double > _tpc_track_score;
325+ std::vector<int > _tpc_whichtpc;
326326 std::vector<int > _tpc_truth_trackid;
327327 std::vector<int > _tpc_truth_pdg;
328328 std::vector<double > _tpc_truth_energy;
@@ -343,6 +343,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
343343 std::vector<bool > _tpc_tr_matchable;
344344 std::vector<bool > _tpc_tr_matched;
345345 std::vector<bool > _tpc_tr_good_match;
346+ std::vector<double > _tpc_tr_xshift;
346347 std::vector<double > _tpc_tr_ts0;
347348 std::vector<double > _tpc_tr_ts1;
348349 std::vector<std::vector<int >> _tpc_tr_taggers;
@@ -354,14 +355,15 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
354355 std::vector<double > _tpc_tr_end_z;
355356 std::vector<double > _tpc_tr_score;
356357
357- // ptb information (trigger board)
358+ // Penn Trigger Board HLTs
358359 std::vector<uint64_t > _ptb_hlt_trigger;
359360 std::vector<uint64_t > _ptb_hlt_timestamp;
360361
362+ // Penn Trigger Board LLTs
361363 std::vector<uint64_t > _ptb_llt_trigger;
362364 std::vector<uint64_t > _ptb_llt_timestamp;
363365
364- // spec tdc information (timing board)
366+ // SPEC TDC Timestamps
365367 std::vector<uint32_t > _tdc_channel;
366368 std::vector<uint64_t > _tdc_timestamp;
367369 std::vector<uint64_t > _tdc_offset;
@@ -371,6 +373,7 @@ class sbnd::crt::CRTAnalysis : public art::EDAnalyzer {
371373sbnd::crt::CRTAnalysis::CRTAnalysis (fhicl::ParameterSet const & p)
372374 : EDAnalyzer{p}
373375 , fCRTBackTrackerAlg (p.get<fhicl::ParameterSet>(" CRTBackTrackerAlg" , fhicl::ParameterSet()))
376+ , fCRTClusterCharacAlg (p.get<fhicl::ParameterSet>(" CRTClusterCharacterisationAlg" , fhicl::ParameterSet()))
374377{
375378 fMCParticleModuleLabel = p.get <std::string>(" MCParticleModuleLabel" , " largeant" );
376379 fSimDepositModuleLabel = p.get <std::string>(" SimDepositModuleLabel" , " genericcrt" );
@@ -394,10 +397,6 @@ sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
394397 fHasTDC = p.get <bool >(" HasTDC" , false );
395398 fHasBlobs = p.get <bool >(" HasBlobs" , false );
396399 fTruthMatch = p.get <bool >(" TruthMatch" , true );
397- fPEAttenuation = p.get <double >(" PEAttenuation" , 1.0 );
398- fTimeWalkNorm = p.get <double >(" TimeWalkNorm" , 0.0 );
399- fTimeWalkScale = p.get <double >(" TimeWalkScale" , 0.0 );
400- fPropDelay = p.get <double >(" PropDelay" , 0.0 );
401400
402401 if (!fDataMode && fTruthMatch )
403402 fCRTBackTrackerAlg = CRTBackTrackerAlg (p.get <fhicl::ParameterSet>(" CRTBackTrackerAlg" , fhicl::ParameterSet ()));
@@ -621,6 +620,7 @@ sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
621620 fTree ->Branch (" tpc_end_dir_z" , " std::vector<double>" , &_tpc_end_dir_z);
622621 fTree ->Branch (" tpc_length" , " std::vector<double>" , &_tpc_length);
623622 fTree ->Branch (" tpc_track_score" , " std::vector<double>" , &_tpc_track_score);
623+ fTree ->Branch (" tpc_whichtpc" , " std::vector<int>" , &_tpc_whichtpc);
624624 fTree ->Branch (" tpc_sp_matched" , " std::vector<bool>" , &_tpc_sp_matched);
625625 fTree ->Branch (" tpc_sp_channel_set" , " std::vector<std::vector<uint32_t>>" , &_tpc_sp_channel_set);
626626 fTree ->Branch (" tpc_sp_xshift" , " std::vector<double>" , &_tpc_sp_xshift);
@@ -633,6 +633,7 @@ sbnd::crt::CRTAnalysis::CRTAnalysis(fhicl::ParameterSet const& p)
633633 fTree ->Branch (" tpc_sp_z" , " std::vector<double>" , &_tpc_sp_z);
634634 fTree ->Branch (" tpc_sp_score" , " std::vector<double>" , &_tpc_sp_score);
635635 fTree ->Branch (" tpc_tr_matched" , " std::vector<bool>" , &_tpc_tr_matched);
636+ fTree ->Branch (" tpc_tr_xshift" , " std::vector<double>" , &_tpc_tr_xshift);
636637 fTree ->Branch (" tpc_tr_ts0" , " std::vector<double>" , &_tpc_tr_ts0);
637638 fTree ->Branch (" tpc_tr_ts1" , " std::vector<double>" , &_tpc_tr_ts1);
638639 fTree ->Branch (" tpc_tr_taggers" , " std::vector<std::vector<int>>" , &_tpc_tr_taggers);
@@ -1326,25 +1327,10 @@ void sbnd::crt::CRTAnalysis::AnalyseCRTClusters(const art::Event &e, const std::
13261327 _cl_sh_ts1_set[i][ii] = striphit->Ts1 ();
13271328 _cl_sh_feb_mac5_set[i][ii] = fCRTChannelMapService ->GetMAC5FromOfflineChannelID (striphit->Channel ());
13281329
1329- /*
1330- * The below segment reimplements the CorrectTime() method
1331- * from CRTReco/CRTClusterCharacterisationAlg.cc .
1332- * Because the Ts0(), Ts1() getters invoked in _cl_sp_ts*, _cl_sh_ts*_set are raw T0/1
1333- * counters, the time walk and propagation delay are saved as explicit branches here.
1334- */
13351330 if (spacepoints.size () == 1 )
13361331 {
1337- double pe0 = fCRTGeoService ->GetSiPM ( striphit->Channel () ).gain * striphit->ADC1 ();
1338- double pe1 = fCRTGeoService ->GetSiPM ( striphit->Channel () + 1 ).gain * striphit->ADC2 ();
1339- double pe = pe0 + pe1;
1340-
1341- double dist = fCRTGeoService ->DistanceDownStrip ( spacepoints[0 ]->Pos (), striphit->Channel () );
1342-
1343- double corr = std::pow ( dist - fPEAttenuation , 2.0 ) / std::pow ( fPEAttenuation , 2.0 );
1344- double tw_pe = pe * corr;
1345-
1346- _cl_sh_time_walk_set[i][ii] = fTimeWalkNorm * std::exp ( -fTimeWalkScale * tw_pe );
1347- _cl_sh_prop_delay_set[i][ii] = fPropDelay * dist;
1332+ _cl_sh_time_walk_set[i][ii] = fCRTClusterCharacAlg .TimeWalk (striphit, spacepoints[0 ]->Pos ());
1333+ _cl_sh_prop_delay_set[i][ii] = fCRTClusterCharacAlg .PropagationDelay (striphit, spacepoints[0 ]->Pos ());
13481334
13491335 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]});
13501336 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]});
@@ -1682,6 +1668,7 @@ void sbnd::crt::CRTAnalysis::AnalyseTPCMatching(const art::Event &e, const art::
16821668 _tpc_end_dir_z.resize (nTracks);
16831669 _tpc_length.resize (nTracks);
16841670 _tpc_track_score.resize (nTracks);
1671+ _tpc_whichtpc.resize (nTracks);
16851672 _tpc_truth_trackid.resize (nTracks);
16861673 _tpc_truth_pdg.resize (nTracks);
16871674 _tpc_truth_energy.resize (nTracks);
@@ -1702,6 +1689,7 @@ void sbnd::crt::CRTAnalysis::AnalyseTPCMatching(const art::Event &e, const art::
17021689 _tpc_tr_matchable.resize (nTracks);
17031690 _tpc_tr_matched.resize (nTracks);
17041691 _tpc_tr_good_match.resize (nTracks);
1692+ _tpc_tr_xshift.resize (nTracks);
17051693 _tpc_tr_ts0.resize (nTracks);
17061694 _tpc_tr_ts1.resize (nTracks);
17071695 _tpc_tr_taggers.resize (nTracks);
@@ -1771,6 +1759,7 @@ void sbnd::crt::CRTAnalysis::AnalyseTPCMatching(const art::Event &e, const art::
17711759 const art::Ptr<CRTTrack> crttrack = tracksToTrackMatches.at (track.key ());
17721760
17731761 const std::vector<art::Ptr<recob::Hit>> trackHits = tracksToHits.at (track.key ());
1762+ _tpc_whichtpc[nActualTracks] = TPCGeoUtil::DetectedInTPC (trackHits);
17741763
17751764 if (spacepoint.isNonnull ())
17761765 {
@@ -1813,7 +1802,11 @@ void sbnd::crt::CRTAnalysis::AnalyseTPCMatching(const art::Event &e, const art::
18131802 {
18141803 const anab::T0 trackMatch = tracksToTrackMatches.data (track.key ()).ref ();
18151804
1805+ const int driftDirection = TPCGeoUtil::DriftDirectionFromHits (geometryService, trackHits);
1806+ const double crtShiftingTime = fDataMode ? crttrack->Ts0 () * 1e-3 : crttrack->Ts1 () * 1e-3 ;
1807+
18161808 _tpc_tr_matched[nActualTracks] = true ;
1809+ _tpc_tr_xshift[nActualTracks] = driftDirection * crtShiftingTime * detProp.DriftVelocity ();
18171810 _tpc_tr_ts0[nActualTracks] = crttrack->Ts0 ();
18181811 _tpc_tr_ts1[nActualTracks] = crttrack->Ts1 ();
18191812 _tpc_tr_score[nActualTracks] = trackMatch.TriggerConfidence ();
@@ -1837,6 +1830,7 @@ void sbnd::crt::CRTAnalysis::AnalyseTPCMatching(const art::Event &e, const art::
18371830 else
18381831 {
18391832 _tpc_tr_matched[nActualTracks] = false ;
1833+ _tpc_tr_xshift[nActualTracks] = -std::numeric_limits<double >::max ();
18401834 _tpc_tr_ts0[nActualTracks] = -std::numeric_limits<double >::max ();
18411835 _tpc_tr_ts1[nActualTracks] = -std::numeric_limits<double >::max ();
18421836 _tpc_tr_score[nActualTracks] = -std::numeric_limits<double >::max ();
@@ -1915,6 +1909,7 @@ void sbnd::crt::CRTAnalysis::AnalyseTPCMatching(const art::Event &e, const art::
19151909 _tpc_end_dir_z.resize (nActualTracks);
19161910 _tpc_length.resize (nActualTracks);
19171911 _tpc_track_score.resize (nActualTracks);
1912+ _tpc_whichtpc.resize (nActualTracks);
19181913 _tpc_truth_trackid.resize (nActualTracks);
19191914 _tpc_truth_pdg.resize (nActualTracks);
19201915 _tpc_truth_energy.resize (nActualTracks);
0 commit comments