Skip to content

Commit 33f3455

Browse files
committed
Add truth matching info to CRT hits.
1 parent 190c596 commit 33f3455

4 files changed

Lines changed: 120 additions & 3 deletions

File tree

sbncode/CAFMaker/CAFMakerParams.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ namespace caf
320320
"crthit" // icarus
321321
};
322322

323+
Atom<string> CRTSimChanLabel {
324+
Name("CRTSimChanLabel"),
325+
Comment("Label of AuxDetSimChannels."),
326+
"genericcrt" // icarus
327+
};
328+
323329
Atom<string> CRTTrackLabel {
324330
Name("CRTTrackLabel"),
325331
Comment("Label of sbn CRT tracks."),

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
#include "sbnanaobj/StandardRecord/Flat/FlatRecord.h"
140140
#include "lardataobj/RawData/ExternalTrigger.h"
141141
#include "lardataobj/RawData/TriggerData.h"
142+
#include "lardataobj/Simulation/AuxDetSimChannel.h"
142143

143144
// // CAFMaker
144145
#include "sbncode/CAFMaker/AssociationUtil.h"
@@ -286,6 +287,11 @@ class CAFMaker : public art::EDProducer {
286287
std::vector<std::vector<geo::BoxBoundedGeo>> fTPCVolumes;
287288
std::vector<geo::BoxBoundedGeo> fActiveVolumes;
288289

290+
// CRT geometry info
291+
//
292+
// ICARUS
293+
std::map<std::pair<int, int>, int> fFEBChannel2AuxDetID;
294+
289295
// random number generator for fake reco
290296
CLHEP::HepRandomEngine& fFakeRecoRandomEngine;
291297

@@ -314,6 +320,7 @@ class CAFMaker : public art::EDProducer {
314320
double GetBlindPOTScale() const;
315321

316322
void InitVolumes(); ///< Initialize volumes from Gemotry service
323+
void InitCRTMapping(); ///< Initialize CRT mapping
317324

318325
void FixPMTReferenceTimes(StandardRecord &rec, double PMT_reference_time);
319326
void FixCRTReferenceTimes(StandardRecord &rec, double CRTT0_reference_time, double CRTT1_reference_time);
@@ -422,6 +429,9 @@ class CAFMaker : public art::EDProducer {
422429
// setup volume definitions
423430
InitVolumes();
424431

432+
// setup CRT mapping
433+
InitCRTMapping();
434+
425435
fSaveGENIEEventRecord = fParams.SaveGENIEEventRecord();
426436

427437
}
@@ -595,6 +605,36 @@ void CAFMaker::FixCRTReferenceTimes(StandardRecord &rec, double CRTT0_reference_
595605

596606
}
597607

608+
void CAFMaker::InitCRTMapping() {
609+
610+
// ICARUS
611+
cet::search_path searchPath("FW_SEARCH_PATH");
612+
std::string fullFileName;
613+
searchPath.find_file("feb_map.txt",fullFileName);
614+
std::ifstream fin;
615+
fin.open(fullFileName, std::ios::in);
616+
617+
if (fin.good()) {
618+
std::string line;
619+
620+
while(std::getline(fin,line)) {
621+
std::vector<std::string> row;
622+
std::string word;
623+
624+
std::stringstream s(line);
625+
while (std::getline(s, word, ',')) {
626+
row.push_back(word);
627+
}
628+
int auxDetID = std::stoi(row[0]); // auxDetID
629+
int mac5 = std::stoi(row[1]); // FEB ID
630+
int chan = std::stoi(row[2]); // FEB channel
631+
fFEBChannel2AuxDetID[std::make_pair(mac5, chan)] = auxDetID;
632+
}
633+
634+
fin.close();
635+
}
636+
}
637+
598638
void CAFMaker::InitVolumes() {
599639
const geo::GeometryCore *geometry = lar::providerFrom<geo::Geometry>();
600640

@@ -1648,16 +1688,36 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16481688
caf::SRSBNDFrameShiftInfo srsbndframeshiftinfo;
16491689
caf::SRSBNDTimingInfo srsbndtiminginfo;
16501690

1691+
// Mapping of (feb, channel) to truth information (AuxDetSimChannel) -- filled for ICARUS
1692+
std::map<std::pair<int, int>, sim::AuxDetSimChannel> crtsimchanmap;
1693+
16511694
if(fDet == kICARUS)
16521695
{
16531696
art::Handle<std::vector<sbn::crt::CRTHit>> crthits_handle;
16541697
GetByLabelStrict(evt, fParams.CRTHitLabel(), crthits_handle);
1698+
1699+
art::Handle<std::vector<sim::AuxDetSimChannel>> auxdetsimchan_handle;
1700+
GetByLabelStrict(evt, fParams.CRTSimChanLabel(), auxdetsimchan_handle);
1701+
16551702
// fill into event
16561703
if (crthits_handle.isValid()) {
16571704
const std::vector<sbn::crt::CRTHit> &crthits = *crthits_handle;
1705+
1706+
std::vector<sim::AuxDetSimChannel> empty;
1707+
const std::vector<sim::AuxDetSimChannel> &crtsimchanvec = (auxdetsimchan_handle.isValid()) ? *auxdetsimchan_handle : empty;
1708+
// Turn the AuxDetSimChannel's into a map that can be looked up from a CRT Hit
1709+
for (const sim::AuxDetSimChannel &crtsimchan: crtsimchanvec) {
1710+
for (auto const &map_pair: fFEBChannel2AuxDetID) {
1711+
if (map_pair.second == (int)crtsimchan.AuxDetID()) {
1712+
crtsimchanmap[map_pair.first] = crtsimchan;
1713+
break;
1714+
}
1715+
}
1716+
}
1717+
16581718
for (unsigned i = 0; i < crthits.size(); i++) {
16591719
srcrthits.emplace_back();
1660-
FillCRTHit(crthits[i], fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, srcrthits.back());
1720+
FillCRTHit(crthits[i], fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, crtsimchanmap, srcrthits.back());
16611721
}
16621722
}
16631723

@@ -2328,7 +2388,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23282388
crthittagginginfo = fmCRTHitMatchInfo.at(iPart);
23292389
}
23302390

2331-
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, crthittagginginfo, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, trk);
2391+
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, crthittagginginfo, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, crtsimchanmap, trk);
23322392
}
23332393
// NOTE: SEE TODO AT fmCRTTrackMatch
23342394
if (fmCRTTrackMatch.isValid() && fDet == kICARUS) {

sbncode/CAFMaker/FillReco.cxx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace caf
6868
bool use_ts0,
6969
int64_t CRT_T0_reference_time, // ns, signed
7070
double CRT_T1_reference_time, // us
71+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
7172
caf::SRCRTHit &srhit,
7273
bool allowEmpty) {
7374

@@ -86,6 +87,52 @@ namespace caf
8687
srhit.pe = hit.peshit;
8788
srhit.plane = hit.plane;
8889

90+
// lookup truth matching information
91+
std::map<int, float> true_energy;
92+
std::set<std::pair<int, int>> checked; // keep track of what AuxDetSimChannels we have looked at
93+
for (auto const &mac_to_pes: hit.pesmap) {
94+
int mac = (int)mac_to_pes.first;
95+
for (const std::pair<int,float> &chan_pe: mac_to_pes.second) {
96+
int chan = chan_pe.first;
97+
98+
// check for the 3-pos Minos ("m") modules, or the 1-pos other modules
99+
bool is_minos_module = mac < 94;
100+
int pos = is_minos_module ? (chan/10 + 1) : 1;
101+
102+
std::pair<int, int> key {mac, pos};
103+
if (checked.count(key)) continue; // already looked here
104+
105+
checked.insert(key);
106+
107+
if (crtsimchanmap.count(key)) {
108+
const sim::AuxDetSimChannel &crtsimchan = crtsimchanmap.at(key);
109+
for (const sim::AuxDetIDE &ide: crtsimchan.AuxDetIDEs()) {
110+
double hit_time_us = srhit.time;
111+
double tru_time_us = ide.entryT/1e3; // ns -> us
112+
113+
// 1us cut on truth matching
114+
if (abs(hit_time_us - tru_time_us) < 1) {
115+
// std::cout << "Hit at time: " << (srhit.time/1e3) << " " << (srhit.t0/1e3) << " " << (srhit.t1/1e3) << " pes: " << chan_pe.second << " of " << srhit.pe << " on FEB: " << mac << " channel: " << chan << " matched to AuxDetID: " << crtsimchan.AuxDetID() << " G4ID: " << ide.trackID << " E: " << ide.energyDeposited << " T: " << (ide.entryT/1e6) << std::endl;
116+
true_energy[ide.trackID] += ide.energyDeposited;
117+
}
118+
119+
}
120+
}
121+
}
122+
}
123+
124+
// sort results by energy
125+
std::vector<std::pair<float, int>> true_energy_list;
126+
for (auto const &pair: true_energy) true_energy_list.push_back(std::make_pair(pair.second, pair.first));
127+
std::sort(true_energy_list.begin(), true_energy_list.end(), std::greater<>());
128+
129+
// Save to the SRCRTHit truth
130+
for (auto const &pair: true_energy_list) {
131+
srhit.truth.match_e.push_back(pair.first);
132+
srhit.truth.match_id.push_back(pair.second);
133+
}
134+
if (true_energy_list.size() > 0) srhit.truth.bestmatch_id = true_energy_list[0].second;
135+
89136
}
90137

91138
void FillCRTTrack(const sbn::crt::CRTTrack &track,
@@ -640,6 +687,7 @@ namespace caf
640687
bool use_ts0,
641688
int64_t CRT_T0_reference_time, // ns, signed
642689
double CRT_T1_reference_time, // us
690+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
643691
caf::SRTrack &srtrack,
644692
bool allowEmpty)
645693
{
@@ -666,7 +714,7 @@ namespace caf
666714
srtrack.crthit.hit.plane = t0match[0]->fID;
667715
}
668716
if (hitmatch.size()) {
669-
FillCRTHit(*hitmatch[0], use_ts0, CRT_T0_reference_time, CRT_T1_reference_time, srtrack.crthit.hit, allowEmpty);
717+
FillCRTHit(*hitmatch[0], use_ts0, CRT_T0_reference_time, CRT_T1_reference_time, crtsimchanmap, srtrack.crthit.hit, allowEmpty);
670718
}
671719
}
672720

sbncode/CAFMaker/FillReco.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "lardataobj/AnalysisBase/T0.h"
2626
#include "lardataobj/RecoBase/PFParticleMetadata.h"
2727
#include "lardataobj/RecoBase/MCSFitResult.h"
28+
#include "lardataobj/Simulation/AuxDetSimChannel.h"
2829
#include "larrecodnn/CVN/func/Result.h"
2930
#include "sbnobj/Common/Reco/Stub.h"
3031
#include "sbnobj/Common/Reco/RangeP.h"
@@ -175,6 +176,7 @@ namespace caf
175176
bool use_ts0,
176177
int64_t CRT_T0_reference_time, // ns, signed
177178
double CRT_T1_reference_time, // us
179+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
178180
caf::SRTrack &srtrack,
179181
bool allowEmpty = false);
180182

@@ -242,6 +244,7 @@ namespace caf
242244
bool use_ts0,
243245
int64_t CRT_T0_reference_time, // ns, signed
244246
double CRT_T1_reference_time, // us
247+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
245248
caf::SRCRTHit &srhit,
246249
bool allowEmpty = false);
247250
void FillCRTTrack(const sbn::crt::CRTTrack &track,

0 commit comments

Comments
 (0)