Skip to content

Commit cd2b105

Browse files
authored
Merge branch 'develop' into feature/fp_bugFix
2 parents d4847d5 + be46110 commit cd2b105

20 files changed

Lines changed: 3090 additions & 36 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
1717

1818
find_package(cetmodules 3.20.00 REQUIRED)
19-
project(sbncode VERSION 10.04.08 LANGUAGES CXX)
19+
project(sbncode VERSION 10.06.00 LANGUAGES CXX)
2020

2121
message(STATUS "\n\n ========================== ${PROJECT_NAME} ==========================")
2222

sbncode/CAFMaker/CAFMakerParams.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ namespace caf
4444
Atom<bool> SaveGENIEEventRecord { Name("SaveGENIEEventRecord"),
4545
Comment("Whether to produce GENIE event record to the output file"), false
4646
};
47+
48+
Atom<bool> OverrideRealData { Name("OverrideRealData"),
49+
Comment("when true, some algorithms (e.g. PoT count) treat events as MC rather than real data -- e.g. set it if the event is an overlay"), false
50+
};
4751

4852
Atom<float> PrescaleFactor { Name("PrescaleFactor"),
4953
Comment("Factor by which to prescale unblind events"), 10
@@ -274,6 +278,12 @@ namespace caf
274278
"pandoraTrackCRTHit"
275279
};
276280

281+
Atom<string> CRTHitMatchInfoLabel {
282+
Name("CRTHitMatchInfoLabel"),
283+
Comment("Base label of additional information on track to CRT hit matching producer."),
284+
"CRTT0Tagging"
285+
};
286+
277287
Atom<string> CRTTrackMatchLabel {
278288
Name("CRTTrackMatchLabel"),
279289
Comment("Base label of track to CRT track matching producer."),

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#include "nusimdata/SimulationBase/MCNeutrino.h"
102102
#include "nusimdata/SimulationBase/GTruth.h"
103103

104+
#include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh"
104105
#include "sbnobj/Common/EventGen/MeVPrtl/MeVPrtlTruth.h"
105106
#include "sbnobj/Common/Reco/RangeP.h"
106107
#include "sbnobj/Common/SBNEventWeight/EventWeightMap.h"
@@ -199,7 +200,8 @@ class CAFMaker : public art::EDProducer {
199200

200201
std::string fSourceFile;
201202
std::uint32_t fSourceFileHash;
202-
203+
204+
bool fOverrideRealData;
203205
bool fFirstInSubRun;
204206
unsigned int fIndexInFile = SRHeader::NoSourceIndex;
205207
bool fFirstBlindInSubRun;
@@ -401,6 +403,7 @@ class CAFMaker : public art::EDProducer {
401403
// Note: we will define isRealData on a per event basis in produce function [using event.isRealData()], at least for now.
402404

403405
fCafFilename = fParams.CAFFilename();
406+
fOverrideRealData = fParams.OverrideRealData();
404407
fFlatCafFilename = fParams.FlatCAFFilename();
405408

406409
// Normally CAFMaker is run wit no output ART stream, so these go
@@ -847,9 +850,18 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
847850
std::cout << std::endl;
848851
abort();
849852
}
850-
853+
if ( fOverrideRealData ) {
854+
// Expects a generator POT summary then...
855+
if(auto pot_handle = sr.getHandle<sumdata::POTSummary>(fParams.GenLabel())){
856+
fSubRunPOT = pot_handle->totgoodpot;
857+
fTotalPOT += fSubRunPOT;
858+
}else{
859+
std::cout << "Did not find MC POT info under " << fParams.GenLabel() << std::endl;
860+
if(fParams.StrictMode()) abort();
861+
}
862+
}else{
851863
if(bnb_spill){
852-
FillExposure(*bnb_spill, fBNBInfo, fSubRunPOT);
864+
FillExposure(*bnb_spill, fBNBInfo, fSubRunPOT);
853865
fTotalPOT += fSubRunPOT;
854866

855867
// Find the spill for each event and fill the event map:
@@ -908,10 +920,9 @@ void CAFMaker::beginSubRun(art::SubRun& sr) {
908920
<< std::endl;
909921
if(fParams.StrictMode()) abort();
910922
}
911-
912923
// Otherwise, if one label is blank, maybe no POT was the expected result
913924
}
914-
925+
}
915926
std::cout << "POT: " << fSubRunPOT << std::endl;
916927

917928
fFirstInSubRun = true;
@@ -1263,8 +1274,8 @@ void CAFMaker::produce(art::Event& evt) noexcept {
12631274

12641275
bool const firstInFile = (fIndexInFile++ == 0);
12651276

1266-
// is this event real data?
1267-
bool isRealData = evt.isRealData();
1277+
// is this event real data? -- BH: if fOverrideRealData, treat it as MC. Otherwise, get the info from the art event.
1278+
bool isRealData = !fOverrideRealData && evt.isRealData();
12681279

12691280
std::unique_ptr<std::vector<caf::StandardRecord>> srcol(
12701281
new std::vector<caf::StandardRecord>);
@@ -1459,7 +1470,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
14591470

14601471
int iparticle=0;
14611472
genie::GHepParticle * p = 0;
1462-
while( genie_rec->Particle(iparticle) != 0 ) {
1473+
while( (genie_rec->Particle(iparticle) != 0) && (iparticle < 250) ) {
14631474
p = genie_rec->Particle(iparticle);
14641475
fGenieEvtRec_brStdHepPdg[iparticle] = p->Pdg();
14651476
fGenieEvtRec_brStdHepStatus[iparticle] = (int) p->Status();
@@ -1654,26 +1665,50 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16541665

16551666
// Get all of the OpFlashes
16561667
std::vector<caf::SROpFlash> srflashes;
1668+
if(fDet == kICARUS)
1669+
{
1670+
for (const std::string& pandora_tag_suffix : pandora_tag_suffixes) {
1671+
art::Handle<std::vector<recob::OpFlash>> flashes_handle;
1672+
GetByLabelStrict(evt, fParams.OpFlashLabel() + pandora_tag_suffix, flashes_handle);
1673+
// fill into event
1674+
if (flashes_handle.isValid()) {
1675+
const std::vector<recob::OpFlash> &opflashes = *flashes_handle;
1676+
int cryostat = ( pandora_tag_suffix.find("W") != std::string::npos ) ? 1 : 0;
16571677

1658-
for (const std::string& pandora_tag_suffix : pandora_tag_suffixes) {
1659-
art::Handle<std::vector<recob::OpFlash>> flashes_handle;
1660-
GetByLabelStrict(evt, fParams.OpFlashLabel() + pandora_tag_suffix, flashes_handle);
1661-
// fill into event
1662-
if (flashes_handle.isValid()) {
1663-
const std::vector<recob::OpFlash> &opflashes = *flashes_handle;
1664-
int cryostat = ( pandora_tag_suffix.find("W") != std::string::npos ) ? 1 : 0;
1678+
// get associated OpHits for each OpFlash
1679+
art::FindMany<recob::OpHit> findManyHits(flashes_handle, evt, fParams.OpFlashLabel() + pandora_tag_suffix);
16651680

1666-
// get associated OpHits for each OpFlash
1667-
art::FindMany<recob::OpHit> findManyHits(flashes_handle, evt, fParams.OpFlashLabel() + pandora_tag_suffix);
1681+
int iflash=0;
1682+
for (const recob::OpFlash& flash : opflashes) {
16681683

1669-
int iflash=0;
1670-
for (const recob::OpFlash& flash : opflashes) {
1684+
std::vector<recob::OpHit const*> const& ophits = findManyHits.at(iflash);
16711685

1672-
std::vector<recob::OpHit const*> const& ophits = findManyHits.at(iflash);
1686+
srflashes.emplace_back();
1687+
FillICARUSOpFlash(flash, ophits, cryostat, srflashes.back());
1688+
iflash++;
1689+
}
1690+
}
1691+
}
1692+
}
1693+
else if(fDet == kSBND)
1694+
{
1695+
std::vector<std::string> tpc_suffixes_sbnd = {"tpc0", "tpc1"};
16731696

1674-
srflashes.emplace_back();
1675-
FillOpFlash(flash, ophits, cryostat, srflashes.back());
1676-
iflash++;
1697+
for (size_t tpc=0; tpc<tpc_suffixes_sbnd.size(); tpc++) {
1698+
art::Handle<std::vector<recob::OpFlash>> flashes_handle;
1699+
GetByLabelStrict(evt, fParams.OpFlashLabel() + tpc_suffixes_sbnd[tpc], flashes_handle);
1700+
// fill into event
1701+
if (flashes_handle.isValid()) {
1702+
const std::vector<recob::OpFlash> &opflashes = *flashes_handle;
1703+
// get associated OpHits for each OpFlash
1704+
art::FindMany<recob::OpHit> findManyHits(flashes_handle, evt, fParams.OpFlashLabel() + tpc_suffixes_sbnd[tpc]);
1705+
int iflash=0;
1706+
for (const recob::OpFlash& flash : opflashes) {
1707+
std::vector<recob::OpHit const*> const& ophits = findManyHits.at(iflash);
1708+
srflashes.emplace_back();
1709+
FillSBNDOpFlash(flash, ophits, tpc, srflashes.back());
1710+
iflash++;
1711+
}
16771712
}
16781713
}
16791714
}
@@ -1916,9 +1951,14 @@ void CAFMaker::produce(art::Event& evt) noexcept {
19161951

19171952
// NOTE: The sbn::crt::CRTHit is associated to the T0. It's a bit awkward to
19181953
// access that here, so we do it per-track (see code where fmCRTHitMatch is accessed below)
1954+
19191955
art::FindManyP<anab::T0> fmCRTHitMatch =
19201956
FindManyPStrict<anab::T0>(slcTracks, evt,
1921-
fParams.CRTHitMatchLabel() + slice_tag_suff);
1957+
fParams.CRTHitMatchLabel());
1958+
1959+
art::FindManyP<sbn::crt::CRTHitT0TaggingInfo> fmCRTHitMatchInfo =
1960+
FindManyPStrict<sbn::crt::CRTHitT0TaggingInfo>(slcTracks, evt,
1961+
fParams.CRTHitMatchInfoLabel());
19221962

19231963
// TODO: also save the sbn::crt::CRTTrack in the matching so that CAFMaker has access to it
19241964
art::FindManyP<anab::T0> fmCRTTrackMatch =
@@ -2157,14 +2197,19 @@ void CAFMaker::produce(art::Event& evt) noexcept {
21572197
fParams.TrackHitFillRRStartCut(), fParams.TrackHitFillRREndCut(),
21582198
dprop, trk);
21592199
}
2200+
21602201
if (fmCRTHitMatch.isValid() && fDet == kICARUS) {
21612202
art::FindManyP<sbn::crt::CRTHit> CRTT02Hit = FindManyPStrict<sbn::crt::CRTHit>
2162-
(fmCRTHitMatch.at(iPart), evt, fParams.CRTHitMatchLabel() + slice_tag_suff);
2203+
(fmCRTHitMatch.at(iPart), evt, fParams.CRTHitMatchLabel());
21632204

21642205
std::vector<art::Ptr<sbn::crt::CRTHit>> crthitmatch;
2165-
if (CRTT02Hit.isValid() && CRTT02Hit.size() == 1) crthitmatch = CRTT02Hit.at(0);
2166-
2167-
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, trk);
2206+
std::vector<art::Ptr<sbn::crt::CRTHitT0TaggingInfo>> crthittagginginfo;
2207+
if(CRTT02Hit.isValid() && CRTT02Hit.size() == 1){
2208+
crthitmatch = CRTT02Hit.at(0);
2209+
crthittagginginfo = fmCRTHitMatchInfo.at(iPart);
2210+
}
2211+
2212+
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, crthittagginginfo, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, trk);
21682213
}
21692214
// NOTE: SEE TODO AT fmCRTTrackMatch
21702215
if (fmCRTTrackMatch.isValid() && fDet == kICARUS) {

sbncode/CAFMaker/FillReco.cxx

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ namespace caf
179179
}
180180

181181

182-
void FillOpFlash(const recob::OpFlash &flash,
182+
void FillICARUSOpFlash(const recob::OpFlash &flash,
183183
std::vector<recob::OpHit const*> const& hits,
184184
int cryo,
185185
caf::SROpFlash &srflash,
@@ -227,6 +227,41 @@ namespace caf
227227
}
228228
}
229229

230+
void FillSBNDOpFlash(const recob::OpFlash &flash,
231+
std::vector<recob::OpHit const*> const& hits,
232+
int tpc,
233+
caf::SROpFlash &srflash,
234+
bool allowEmpty) {
235+
236+
srflash.setDefault();
237+
238+
srflash.time = flash.Time();
239+
srflash.timewidth = flash.TimeWidth();
240+
241+
double firstTime = std::numeric_limits<double>::max();
242+
for(const auto& hit: hits){
243+
double const hitTime = hit->HasStartTime()? hit->StartTime(): hit->PeakTime();
244+
if (firstTime > hitTime)
245+
firstTime = hitTime;
246+
}
247+
srflash.firsttime = firstTime;
248+
srflash.tpc = tpc;
249+
250+
srflash.totalpe = flash.TotalPE();
251+
srflash.fasttototal = flash.FastToTotal();
252+
srflash.onbeamtime = flash.OnBeamTime();
253+
254+
srflash.center.SetXYZ( -9999.f, flash.YCenter(), flash.ZCenter() );
255+
srflash.width.SetXYZ( -9999.f, flash.YWidth(), flash.ZWidth() );
256+
257+
// Checks if ( recob::OpFlash.XCenter() != std::numeric_limits<double>::max() )
258+
// See LArSoft OpFlash.h at https://nusoft.fnal.gov/larsoft/doxsvn/html/OpFlash_8h_source.html
259+
if ( flash.hasXCenter() ) {
260+
srflash.center.SetX( flash.XCenter() );
261+
srflash.width.SetX( flash.XWidth() );
262+
}
263+
}
264+
230265
std::vector<float> double_to_float_vector(const std::vector<double>& v)
231266
{
232267
std::vector<float> ret;
@@ -546,18 +581,37 @@ namespace caf
546581

547582
//......................................................................
548583

584+
549585
void FillTrackCRTHit(const std::vector<art::Ptr<anab::T0>> &t0match,
550586
const std::vector<art::Ptr<sbn::crt::CRTHit>> &hitmatch,
587+
const std::vector<art::Ptr<sbn::crt::CRTHitT0TaggingInfo>> &hitmatchinfo,
551588
bool use_ts0,
552589
int64_t CRT_T0_reference_time, // ns, signed
553590
double CRT_T1_reference_time, // us
554591
caf::SRTrack &srtrack,
555592
bool allowEmpty)
556593
{
594+
// Francesco Poppi: In the current implementation, hitmatch and hitmatchinfo are
595+
// vectors of pointers, but currently they are vector of size 1.
596+
// The reason behind the current implementation is that we only store the
597+
// best CRT candidate in the selection, eventually, we can store a vector
598+
// of "good" candidates and fill additional infos for all of them.
599+
// This is a TODO.
557600
if (t0match.size()) {
558601
assert(t0match.size() == 1);
559602
srtrack.crthit.distance = t0match[0]->fTriggerConfidence;
603+
srtrack.crthit.region = t0match[0]->fID;
604+
srtrack.crthit.sys = t0match[0]->fTriggerBits;
605+
if(hitmatchinfo.size() == 1){
606+
srtrack.crthit.deltaX = hitmatchinfo[0]->DeltaX;
607+
srtrack.crthit.deltaY = hitmatchinfo[0]->DeltaY;
608+
srtrack.crthit.deltaZ = hitmatchinfo[0]->DeltaZ;
609+
srtrack.crthit.crossX = hitmatchinfo[0]->CrossX;
610+
srtrack.crthit.crossY = hitmatchinfo[0]->CrossY;
611+
srtrack.crthit.crossZ = hitmatchinfo[0]->CrossZ;
612+
}
560613
srtrack.crthit.hit.time = t0match[0]->fTime / 1e3; /* ns -> us */
614+
srtrack.crthit.hit.plane = t0match[0]->fID;
561615
}
562616
if (hitmatch.size()) {
563617
FillCRTHit(*hitmatch[0], use_ts0, CRT_T0_reference_time, CRT_T1_reference_time, srtrack.crthit.hit, allowEmpty);

sbncode/CAFMaker/FillReco.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "sbnobj/SBND/CRT/CRTSpacePoint.hh"
4141
#include "sbnobj/SBND/CRT/CRTTrack.hh"
4242
#include "sbnobj/Common/CRT/CRTPMTMatching.hh"
43+
#include "sbnobj/Common/CRT/CRTHitT0TaggingInfo.hh"
4344
#include "nusimdata/SimulationBase/MCParticle.h"
4445
#include "nusimdata/SimulationBase/MCTruth.h"
4546

@@ -132,6 +133,7 @@ namespace caf
132133

133134
void FillTrackCRTHit(const std::vector<art::Ptr<anab::T0>> &t0match,
134135
const std::vector<art::Ptr<sbn::crt::CRTHit>> &hitmatch,
136+
const std::vector<art::Ptr<sbn::crt::CRTHitT0TaggingInfo>> &hitmatchinfo,
135137
bool use_ts0,
136138
int64_t CRT_T0_reference_time, // ns, signed
137139
double CRT_T1_reference_time, // us
@@ -217,11 +219,18 @@ namespace caf
217219
caf::SRSBNDCRTTrack &srsbndcrttrack,
218220
bool allowEmpty = false);
219221

220-
void FillOpFlash(const recob::OpFlash &flash,
222+
void FillICARUSOpFlash(const recob::OpFlash &flash,
221223
std::vector<recob::OpHit const*> const& hits,
222224
int cryo,
223225
caf::SROpFlash &srflash,
224226
bool allowEmpty = false);
227+
228+
void FillSBNDOpFlash(const recob::OpFlash &flash,
229+
std::vector<recob::OpHit const*> const& hits,
230+
int tpc,
231+
caf::SROpFlash &srflash,
232+
bool allowEmpty = false);
233+
225234
void FillCRTPMTMatch(const sbn::crt::CRTPMTMatching &match,
226235
caf::SRCRTPMTMatch &srmatch,
227236
bool allowEmpty = false);

sbncode/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_subdirectory(GeometryTools)
2020
add_subdirectory(CosmicID)
2121
add_subdirectory(DetSim)
2222
add_subdirectory(Cluster3D)
23+
add_subdirectory(HitFinder)
2324

2425
# Supera
2526
#

sbncode/Calibration/TrackCaloSkimmer_module.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void sbn::TrackCaloSkimmer::analyze(art::Event const& e)
234234

235235
// Hits (ICARUS style)
236236
art::FindManyP<anab::T0> fmT0CRTHit(tracks, e, fCRTHitT0producer);
237-
art::FindManyP<sbn::crt::CRTHitT0TaggingInfo> fmCRTHitT0TaggingInfo(PFParticleList, e, fCRTHitT0producer);
237+
art::FindManyP<sbn::crt::CRTHitT0TaggingInfo> fmCRTHitT0TaggingInfo(tracks, e, fCRTHitT0producer);
238238

239239
// Track - associated data
240240
art::FindManyP<recob::Track> fmTracks(PFParticleList, e, fTRKproducer);

0 commit comments

Comments
 (0)