Skip to content

Commit 7901e41

Browse files
committed
Merge branch 'release/v10_10_05'
2 parents ff10944 + 188b9c4 commit 7901e41

20 files changed

Lines changed: 1750 additions & 8 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.10.03.02 LANGUAGES CXX)
19+
project(sbncode VERSION 10.10.05 LANGUAGES CXX)
2020

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

sbncode/CAFMaker/CAFMakerParams.h

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

324+
Atom<string> CRTSimChanLabel {
325+
Name("CRTSimChanLabel"),
326+
Comment("Label of AuxDetSimChannels."),
327+
"genericcrt" // icarus
328+
};
329+
324330
Atom<string> CRTTrackLabel {
325331
Name("CRTTrackLabel"),
326332
Comment("Label of sbn CRT tracks."),
@@ -417,6 +423,30 @@ namespace caf
417423
"emuTriggerUnshifted"
418424
};
419425

426+
Atom<art::InputTag> MonPulsesTriggerLabel {
427+
Name("MonPulsesTriggerLabel"),
428+
Comment("Label of trigger emulation product MonPulses (number of PMT pairs above threshold for all channels) for all flashes."),
429+
art::InputTag("opdaq", "MonPulses", "DetSim")
430+
};
431+
432+
Atom<art::InputTag> MonPulseSizesTriggerLabel {
433+
Name("MonPulseSizesTriggerLabel"),
434+
Comment("Label of trigger emulation product MonPulses Sizes, which gives the length of each trigger response in MonPulses."),
435+
art::InputTag("opdaq", "MonPulseSizes", "DetSim")
436+
};
437+
438+
Atom<art::InputTag> PairsTriggerLabel {
439+
Name("PairsTriggerLabel"),
440+
Comment("Label of number of PMT pairs over threshold."),
441+
art::InputTag("opdaq", "pairsOverThreshold", "DetSim")
442+
};
443+
444+
Atom<art::InputTag> EmulatedTriggerLabel {
445+
Name("EmulatedTriggerLabel"),
446+
Comment("Label of bool of passing the trigger."),
447+
art::InputTag("opdaq", "triggerEmulation", "DetSim")
448+
};
449+
420450
Atom<string> FlashTrigLabel {
421451
Name("FlashTrigLabel"),
422452
Comment("Label of bool of passing flash trigger."),

sbncode/CAFMaker/CAFMaker_module.cc

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
#include "sbnanaobj/StandardRecord/Flat/FlatRecord.h"
142142
#include "lardataobj/RawData/ExternalTrigger.h"
143143
#include "lardataobj/RawData/TriggerData.h"
144+
#include "lardataobj/Simulation/AuxDetSimChannel.h"
144145

145146
// // CAFMaker
146147
#include "sbncode/CAFMaker/AssociationUtil.h"
@@ -288,6 +289,11 @@ class CAFMaker : public art::EDProducer {
288289
std::vector<std::vector<geo::BoxBoundedGeo>> fTPCVolumes;
289290
std::vector<geo::BoxBoundedGeo> fActiveVolumes;
290291

292+
// CRT geometry info
293+
//
294+
// ICARUS
295+
std::map<std::pair<int, int>, int> fFEBChannel2AuxDetID;
296+
291297
// random number generator for fake reco
292298
CLHEP::HepRandomEngine& fFakeRecoRandomEngine;
293299

@@ -316,6 +322,7 @@ class CAFMaker : public art::EDProducer {
316322
double GetBlindPOTScale() const;
317323

318324
void InitVolumes(); ///< Initialize volumes from Gemotry service
325+
void InitCRTMapping(); ///< Initialize CRT mapping
319326

320327
void FixPMTReferenceTimes(StandardRecord &rec, double PMT_reference_time);
321328
void FixCRTReferenceTimes(StandardRecord &rec, double CRTT0_reference_time, double CRTT1_reference_time);
@@ -424,6 +431,9 @@ class CAFMaker : public art::EDProducer {
424431
// setup volume definitions
425432
InitVolumes();
426433

434+
// setup CRT mapping
435+
InitCRTMapping();
436+
427437
fSaveGENIEEventRecord = fParams.SaveGENIEEventRecord();
428438

429439
}
@@ -597,6 +607,36 @@ void CAFMaker::FixCRTReferenceTimes(StandardRecord &rec, double CRTT0_reference_
597607

598608
}
599609

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

@@ -1600,7 +1640,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16001640
//#######################################################
16011641
// Fill detector & reco
16021642
//#######################################################
1603-
1643+
16041644
//Beam gate and Trigger info
16051645
art::Handle<sbn::ExtraTriggerInfo> extratrig_handle;
16061646
GetByLabelStrict(evt, fParams.TriggerLabel().encode(), extratrig_handle);
@@ -1612,16 +1652,40 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16121652
if (!isRealData)
16131653
GetByLabelStrict(evt, fParams.UnshiftedTriggerLabel().encode(), unshifted_trig_handle);
16141654

1655+
//Trigger emulation handles
1656+
art::Handle<std::vector<int>> monpulses_handle;
1657+
GetByLabelStrict(evt, fParams.MonPulsesTriggerLabel().encode(), monpulses_handle);
1658+
1659+
art::Handle<std::vector<int>> monpulse_sizes_handle;
1660+
GetByLabelStrict(evt, fParams.MonPulseSizesTriggerLabel().encode(), monpulse_sizes_handle);
1661+
1662+
art::Handle<int> pairs_handle;
1663+
GetByLabelStrict(evt, fParams.PairsTriggerLabel().encode(), pairs_handle);
1664+
1665+
art::Handle<bool> trigemu_handle;
1666+
GetByLabelStrict(evt, fParams.EmulatedTriggerLabel().encode(), trigemu_handle);
1667+
1668+
// Check trigger handles
16151669
const bool isValidTrigger = extratrig_handle.isValid() && trig_handle.isValid() && trig_handle->size() == 1;
16161670
const bool isValidUnshiftedTrigger = unshifted_trig_handle.isValid() && unshifted_trig_handle->size() == 1;
1671+
const bool isValidEmulationTrigger = monpulses_handle.isValid() && monpulse_sizes_handle.isValid() && pairs_handle.isValid() && trigemu_handle.isValid();
16171672

16181673
const double triggerShift = (isValidUnshiftedTrigger && isValidTrigger)?
16191674
unshifted_trig_handle->at(0).TriggerTime() - trig_handle->at(0).TriggerTime() : 0.;
16201675

1676+
// Fill local ExtraTriggerInfo struct
1677+
sbn::ExtraTriggerInfo extratrig;
1678+
if (extratrig_handle.isValid()) extratrig = *extratrig_handle;
1679+
16211680
caf::SRTrigger srtrigger;
16221681
if (isValidTrigger) {
16231682
FillTrigger(*extratrig_handle, trig_handle->at(0), srtrigger, triggerShift);
16241683
}
1684+
// Fill trigger emulation information
1685+
if (isValidEmulationTrigger) {
1686+
FillTriggerEmulation(monpulses_handle, monpulse_sizes_handle, pairs_handle, trigemu_handle, srtrigger);
1687+
}
1688+
16251689
// If not real data, fill in enough of the SRTrigger to make (e.g.) the CRT
16261690
// time referencing work. TODO: add more stuff to a "MC"-Trigger?
16271691
// No longer needed with incorporation of trigger emulation in the MC.
@@ -1652,16 +1716,36 @@ void CAFMaker::produce(art::Event& evt) noexcept {
16521716
caf::SRSBNDFrameShiftInfo srsbndframeshiftinfo;
16531717
caf::SRSBNDTimingInfo srsbndtiminginfo;
16541718

1719+
// Mapping of (feb, channel) to truth information (AuxDetSimChannel) -- filled for ICARUS
1720+
std::map<std::pair<int, int>, sim::AuxDetSimChannel> crtsimchanmap;
1721+
16551722
if(fDet == kICARUS)
16561723
{
16571724
art::Handle<std::vector<sbn::crt::CRTHit>> crthits_handle;
16581725
GetByLabelStrict(evt, fParams.CRTHitLabel(), crthits_handle);
1726+
1727+
art::Handle<std::vector<sim::AuxDetSimChannel>> auxdetsimchan_handle;
1728+
GetByLabelStrict(evt, fParams.CRTSimChanLabel(), auxdetsimchan_handle);
1729+
16591730
// fill into event
16601731
if (crthits_handle.isValid()) {
16611732
const std::vector<sbn::crt::CRTHit> &crthits = *crthits_handle;
1733+
1734+
std::vector<sim::AuxDetSimChannel> empty;
1735+
const std::vector<sim::AuxDetSimChannel> &crtsimchanvec = (auxdetsimchan_handle.isValid()) ? *auxdetsimchan_handle : empty;
1736+
// Turn the AuxDetSimChannel's into a map that can be looked up from a CRT Hit
1737+
for (const sim::AuxDetSimChannel &crtsimchan: crtsimchanvec) {
1738+
for (auto const &map_pair: fFEBChannel2AuxDetID) {
1739+
if (map_pair.second == (int)crtsimchan.AuxDetID()) {
1740+
crtsimchanmap[map_pair.first] = crtsimchan;
1741+
break;
1742+
}
1743+
}
1744+
}
1745+
16621746
for (unsigned i = 0; i < crthits.size(); i++) {
16631747
srcrthits.emplace_back();
1664-
FillCRTHit(crthits[i], fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, srcrthits.back());
1748+
FillCRTHit(crthits[i], fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, crtsimchanmap, srcrthits.back());
16651749
}
16661750
}
16671751

@@ -2359,7 +2443,7 @@ void CAFMaker::produce(art::Event& evt) noexcept {
23592443
crthittagginginfo = fmCRTHitMatchInfo.at(iPart);
23602444
}
23612445

2362-
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, crthittagginginfo, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, trk);
2446+
FillTrackCRTHit(fmCRTHitMatch.at(iPart), crthitmatch, crthittagginginfo, fParams.CRTUseTS0(), CRT_T0_reference_time, CRT_T1_reference_time, crtsimchanmap, trk);
23632447
}
23642448
// NOTE: SEE TODO AT fmCRTTrackMatch
23652449
if (fmCRTTrackMatch.isValid() && fDet == kICARUS) {

sbncode/CAFMaker/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ art_make_library( LIBRARY_NAME sbncode_CAFMaker
3636
sbnobj::Common_Reco
3737
sbnobj::Common_Analysis
3838
sbnobj::Common_PMT_Data
39+
sbnobj::Common_Trigger
3940
sbnobj::SBND_CRT
4041
sbnobj::SBND_Timing
4142
lardataalg::DetectorInfo

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,
@@ -658,6 +705,7 @@ namespace caf
658705
bool use_ts0,
659706
int64_t CRT_T0_reference_time, // ns, signed
660707
double CRT_T1_reference_time, // us
708+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
661709
caf::SRTrack &srtrack,
662710
bool allowEmpty)
663711
{
@@ -684,7 +732,7 @@ namespace caf
684732
srtrack.crthit.hit.plane = t0match[0]->fID;
685733
}
686734
if (hitmatch.size()) {
687-
FillCRTHit(*hitmatch[0], use_ts0, CRT_T0_reference_time, CRT_T1_reference_time, srtrack.crthit.hit, allowEmpty);
735+
FillCRTHit(*hitmatch[0], use_ts0, CRT_T0_reference_time, CRT_T1_reference_time, crtsimchanmap, srtrack.crthit.hit, allowEmpty);
688736
}
689737
}
690738

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"
@@ -193,6 +194,7 @@ namespace caf
193194
bool use_ts0,
194195
int64_t CRT_T0_reference_time, // ns, signed
195196
double CRT_T1_reference_time, // us
197+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
196198
caf::SRTrack &srtrack,
197199
bool allowEmpty = false);
198200

@@ -260,6 +262,7 @@ namespace caf
260262
bool use_ts0,
261263
int64_t CRT_T0_reference_time, // ns, signed
262264
double CRT_T1_reference_time, // us
265+
const std::map<std::pair<int, int>, sim::AuxDetSimChannel> &crtsimchanmap,
263266
caf::SRCRTHit &srhit,
264267
bool allowEmpty = false);
265268
void FillCRTTrack(const sbn::crt::CRTTrack &track,

sbncode/CAFMaker/FillTrigger.cxx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace caf
2626
triggerInfo.trigger_count = addltrig_info.triggerCount;
2727
triggerInfo.gate_count = addltrig_info.gateCount;
2828
triggerInfo.gate_delta = addltrig_info.gateCountFromPreviousTrigger;
29+
2930
}
3031

3132
void FillTriggerMC(double absolute_time, caf::SRTrigger& triggerInfo) {
@@ -35,7 +36,6 @@ namespace caf
3536
// Set this to 0 since the "MC" trigger is (for now) always at the spill time
3637
triggerInfo.trigger_within_gate = 0.;
3738

38-
// TODO: fill others?
3939
}
4040

4141
void FillTriggerSBND(caf::SRSBNDTimingInfo& timingInfo, caf::SRTrigger& triggerInfo){
@@ -49,4 +49,17 @@ namespace caf
4949
triggerInfo.trigger_within_gate = diff_ts;
5050
}
5151

52+
void FillTriggerEmulation(art::Handle<std::vector<int>> const& monpulsesFlat,
53+
art::Handle<std::vector<int>> const& monpulseSizes,
54+
art::Handle<int> const& numPairs,
55+
art::Handle<bool> const& passedTrig,
56+
caf::SRTrigger& triggerInfo) {
57+
58+
triggerInfo.monpulses_flat = *monpulsesFlat;
59+
triggerInfo.monpulse_sizes = *monpulseSizes;
60+
triggerInfo.num_pairs_over_threshold = *numPairs;
61+
triggerInfo.passed_trigger = *passedTrig;
62+
63+
}
64+
5265
}

sbncode/CAFMaker/FillTrigger.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "sbnanaobj/StandardRecord/SRTrigger.h"
77
#include "sbnanaobj/StandardRecord/SRSBNDTimingInfo.h"
88
#include "lardataobj/RawData/TriggerData.h"
9+
#include "art/Framework/Principal/Handle.h"
910

1011
#include <vector>
1112

@@ -20,6 +21,12 @@ namespace caf
2021
void FillTriggerMC(double absolute_time, caf::SRTrigger& triggerInfo);
2122

2223
void FillTriggerSBND(caf::SRSBNDTimingInfo& timingInfo, caf::SRTrigger& triggerInfo);
24+
25+
void FillTriggerEmulation(art::Handle<std::vector<int>> const& monpulsesFlat,
26+
art::Handle<std::vector<int>> const& monpulseSizes,
27+
art::Handle<int> const& numPairs,
28+
art::Handle<bool> const& passedTrig,
29+
caf::SRTrigger& triggerInfo);
2330
}
2431

2532
#endif

0 commit comments

Comments
 (0)