42 #include "ifdh_art/IFDHService/IFDH_service.h"
49 #include "TTimeStamp.h"
50 #include "TRandomGen.h"
51 #include "TObjString.h"
54 #include "art/Framework/Core/EDProducer.h"
55 #include "art/Framework/Core/FileBlock.h"
56 #include "art/Framework/Core/ModuleMacros.h"
57 #include "art/Framework/Principal/Event.h"
58 #include "art/Framework/Principal/Handle.h"
59 #include "art/Framework/Principal/SubRun.h"
60 #include "art/Framework/Services/Registry/ServiceHandle.h"
61 #include "art/Framework/Services/System/TriggerNamesService.h"
62 #include "nurandom/RandomUtils/NuRandomService.h"
68 #include "art_root_io/TFileService.h"
70 #include "canvas/Persistency/Common/FindMany.h"
71 #include "canvas/Persistency/Common/FindManyP.h"
72 #include "canvas/Persistency/Common/FindOne.h"
73 #include "canvas/Persistency/Common/FindOneP.h"
74 #include "canvas/Persistency/Common/Ptr.h"
75 #include "canvas/Persistency/Common/PtrVector.h"
77 #include "cetlib_except/exception.h"
78 #include "cetlib_except/demangle.h"
80 #include "fhiclcpp/ParameterSet.h"
82 #include "messagefacility/MessageLogger/MessageLogger.h"
92 #include "nusimdata/SimulationBase/MCFlux.h"
93 #include "nusimdata/SimulationBase/MCTruth.h"
94 #include "nusimdata/SimulationBase/MCNeutrino.h"
95 #include "nusimdata/SimulationBase/GTruth.h"
97 #include "fhiclcpp/ParameterSetRegistry.h"
112 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
119 #include "sbnanaobj/StandardRecord/Flat/FlatRecord.h"
137 os << it.first.fName <<
" " << it.first.fMean <<
" " << it.first.fWidth << std::endl <<
" ";
138 for(
float v: it.second) os <<
" " << v;
231 std::map<std::string, std::vector<sbn::evwgh::EventWeightParameterSet>>
fPrevWeightPSet;
234 const std::string& ext)
const;
238 const std::map<std::string, std::string>& metadata);
251 template <
class T,
class U>
253 const art::InputTag& label)
const;
255 template <
class T,
class D,
class U>
257 const art::Event&
evt,
258 const art::InputTag& tag)
const;
262 template <
class T,
class U>
264 const art::InputTag& label)
const;
283 template <
class EvtT,
class T>
285 art::Handle<T>& handle)
const;
291 art::Handle<T>& handle)
const;
299 const std::vector<std::string>&
name, T& ret)
const;
302 return a <= (b + precision) && a >= (b -
precision);
306 const art::Ptr<recob::Track>& b) {
307 return a->Length() > b->Length();
318 : art::EDProducer{params},
319 fParams(params()), fFile(0)
323 fCafFilename = fParams.CAFFilename();
324 fFlatCafFilename = fParams.FlatCAFFilename();
329 produces<std::vector<caf::StandardRecord>>();
336 fFakeRecoTRandom =
new TRandomMT64(art::ServiceHandle<rndm::NuRandomService>()->getSeed());
337 if (fParams.CreateBlindedCAF()) {
338 fBlindTRandom =
new TRandomMT64(art::ServiceHandle<rndm::NuRandomService>()->getSeed());
345 int slen = bstring.length();
346 std::string s1 = bstring.substr(0,
int(slen/2));
347 std::string s2 = bstring.substr(
int(slen/2));
348 double rat = stod(s1)/stod(s2);
350 rat = -1 * (
abs(rat) - 1);
362 if ( ((start.
x < -71.1 - 25 && start.
x > -369.33 + 25 ) ||
363 (start.
x > 71.1 + 25 && start.
x < 369.33 - 25 )) &&
364 (start.
y > -181.7 + 25 && start.
y < 134.8 - 25 ) &&
365 (start.
z > -895.95 + 30 && start.
z < 895.95 - 50)) {
379 if ( ((start.
x < -71.1 - 25 && start.
x > -369.33 + 25 ) ||
380 (start.
x > 71.1 + 25 && start.
x < 369.33 - 25 )) &&
381 (start.
y > -181.7 + 25 && start.
y < 134.8 - 25 ) &&
382 (start.
z > -895.95 + 30 && start.
z < 895.95 - 50)) {
395 if ( ((vtx.
x < -71.1 - 25 && vtx.
x > -369.33 + 25 ) ||
396 (vtx.
x > 71.1 + 25 && vtx.
x < 369.33 - 25 )) &&
397 (vtx.
y > -181.7 + 25 && vtx.
y < 134.8 - 25 ) &&
398 (vtx.
z > -895.95 + 30 && vtx.
z < 895.95 - 50)) {
426 tend = geometry->
end_TPC(cryo.ID());
427 std::vector<geo::BoxBoundedGeo> this_tpc_volumes;
428 while (iTPC != tend) {
433 fTPCVolumes.push_back(std::move(this_tpc_volumes));
437 for (
const std::vector<geo::BoxBoundedGeo> &tpcs:
fTPCVolumes) {
438 double XMin = std::min_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MinX() < rhs.MinX(); })->MinX();
439 double YMin = std::min_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MinY() < rhs.MinY(); })->MinY();
440 double ZMin = std::min_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MinZ() < rhs.MinZ(); })->MinZ();
442 double XMax = std::max_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MaxX() < rhs.MaxX(); })->MaxX();
443 double YMax = std::max_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MaxY() < rhs.MaxY(); })->MaxY();
444 double ZMax = std::max_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MaxZ() < rhs.MaxZ(); })->MaxZ();
480 const std::string& ext)
const
482 char* temp =
new char[inname.size()+1];
483 std::strcpy(temp, inname.c_str());
484 std::string ret = basename(temp);
486 const size_t dotpos = ret.rfind(
'.');
487 assert(dotpos != std::string::npos);
560 TTree* globalTree =
new TTree(
"globalTree",
"globalTree");
562 TBranch* br = globalTree->Branch(
"global",
"caf::SRGlobal", &pglobal);
584 gdml = basename(gdml.c_str());
585 std::cout <<
"CAFMaker: Attempting to deduce detector from GDML file name: '" << gdml
586 <<
"' and configured detector name: '" << geom->
DetectorName() <<
"'. ";
588 for(
unsigned int i = 0; i < gdml.size(); ++i) gdml[i] = std::tolower(gdml[i]);
590 const bool hasSBND = ((gdml.find(
"sbnd") != std::string::npos) ||
591 (geom->
DetectorName().find(
"sbnd") != std::string::npos));
592 const bool hasIcarus = ((gdml.find(
"icarus") != std::string::npos) ||
593 (geom->
DetectorName().find(
"icarus") != std::string::npos));
596 if(hasSBND == hasIcarus){
597 std::cout <<
"Unable to automatically determine detector!" << std::endl;
603 std::cout <<
"Detected SBND" << std::endl;
607 std::cout <<
"Detected Icarus" << std::endl;
613 std::cout <<
" based on user configuration." << std::endl;
614 if(
fDet ==
override){
615 std::cout <<
" This was redundant with the auto-detection. Suggest to not specify DetectorOverride" << std::endl;
618 std::cout <<
" This OVERRODE the auto-detection. Are you sure this is what you wanted?" << std::endl;
629 art::Handle<std::vector<sbn::evwgh::EventWeightParameterSet>> wgt_params;
634 std::cout <<
"CAFMaker: Run-level EventWeightParameterSet mismatch."
650 if (!wgt_params.isValid()){
651 std::cout <<
"CAFMaker: no EventWeightParameterSet found under label '" << label <<
"'" << std::endl;
692 std::cout <<
"Found neither BNB data POT info under '"
694 <<
"' not NuMIdata POT info under '"
696 <<
"' nor MC POT info under '"
714 std::map<std::string, std::string> envmap;
720 std::set<TString> variables;
721 variables.insert(
"USER");
722 variables.insert(
"HOSTNAME");
723 variables.insert(
"PWD");
724 for (
auto var : variables)
if(getenv(var)) envmap[var] = getenv(var);
726 for (
char** penv = environ; *penv; ++penv) {
727 const std::string pair = *penv;
728 const size_t split = pair.find(
"=");
729 if(split == std::string::npos)
continue;
730 const std::string key = pair.substr(0, split);
731 const std::string
value = pair.substr(split + 1);
737 envmap[
"date"] = TTimeStamp().AsString();
744 FILE* cmdline = fopen(
"/proc/self/cmdline",
"rb");
748 while (getdelim(&arg, &size, 0, cmdline) != -1) {
757 outfile->mkdir(
"env")->cd();
759 TTree* trenv =
new TTree(
"envtree",
"envtree");
760 std::string key,
value;
761 trenv->Branch(
"key", &key);
762 trenv->Branch(
"value", &value);
763 for(
const auto& keyval: envmap){
765 value = keyval.second;
774 outfile->mkdir(
"metadata")->cd();
776 TTree* trmeta =
new TTree(
"metatree",
"metatree");
777 std::string key,
value;
778 trmeta->Branch(
"key", &key);
779 trmeta->Branch(
"value", &value);
780 for(
const auto& keyval: metadata){
782 value = keyval.second;
793 mf::LogInfo(
"CAFMaker") <<
"Output filename is " <<
fCafFilename;
797 fRecTree =
new TTree(
"recTree",
"records");
801 fRecTree->Branch(
"rec",
"caf::StandardRecord", &rec);
808 fRecTreeb =
new TTree(
"recTree",
"records");
809 fRecTreeb->Branch(
"rec",
"caf::StandardRecord", &rec);
811 fFilep =
new TFile(fCafPrescaleFilename.c_str(),
"RECREATE");
812 fRecTreep =
new TTree(
"recTree",
"records");
813 fRecTreep->Branch(
"rec",
"caf::StandardRecord", &rec);
827 ROOT::CompressionSettings(ROOT::kLZ4, 1));
829 fFlatTree =
new TTree(
"recTree",
"recTree");
842 ROOT::CompressionSettings(ROOT::kLZ4, 1));
844 fFlatFilep =
new TFile(fFlatCafPrescaleFilename.c_str(),
"RECREATE",
"",
845 ROOT::CompressionSettings(ROOT::kLZ4, 1));
874 template <
class T,
class U>
876 const art::Event&
evt,
877 const art::InputTag& tag)
const {
878 art::FindManyP<T> ret(from, evt, tag);
882 << cet::demangle_symbol(
typeid(from).
name()) <<
"' to '"
883 << cet::demangle_symbol(
typeid(T).
name())
884 <<
"' found under label '" << tag <<
"'. "
885 <<
"Set 'StrictMode: false' to continue anyway." << std::endl;
893 template <
class T,
class D,
class U>
895 const art::Event&
evt,
896 const art::InputTag& tag)
const {
897 art::FindManyP<T, D> ret(from, evt, tag);
901 << cet::demangle_symbol(
typeid(from).
name()) <<
"' to '"
902 << cet::demangle_symbol(
typeid(T).
name())
903 <<
"' found under label '" << tag <<
"'. "
904 <<
"Set 'StrictMode: false' to continue anyway." << std::endl;
912 template <
class T,
class U>
914 const art::Event&
evt,
915 const art::InputTag& tag)
const {
916 art::FindOneP<T> ret(from, evt, tag);
920 << cet::demangle_symbol(
typeid(from).
name()) <<
"' to '"
921 << cet::demangle_symbol(
typeid(T).
name())
922 <<
"' found under label '" << tag <<
"'. "
923 <<
"Set 'StrictMode: false' to continue anyway." << std::endl;
934 if (!fm.isValid())
return false;
936 const std::vector<art::Ptr<T>> prods = fm.at(idx);
938 if (prods.empty())
return false;
946 template <
class EvtT,
class T>
948 art::Handle<T>& handle)
const {
949 evt.getByLabel(label, handle);
951 std::cout <<
"CAFMaker: No product of type '"
952 << cet::demangle_symbol(
typeid(*handle).name())
953 <<
"' found under label '" << label <<
"'. "
954 <<
"Set 'StrictMode: false' to continue anyway." << std::endl;
962 const std::string& label,
963 art::Handle<T>& handle)
const {
964 evt.getByLabel(label, handle);
966 std::cout <<
"CAFMaker: No product of type '"
967 << cet::demangle_symbol(
typeid(*handle).name())
968 <<
"' found under label '" << label <<
"'. "
969 <<
"Continuing without it." << std::endl;
976 const std::vector<std::string>&
name,
978 fhicl::ParameterSet
p = pset;
979 for (
unsigned int i = 0; i < name.size() - 1; ++i) {
980 if (!p.has_key(name[i]))
return false;
981 p = p.get<fhicl::ParameterSet>(name[i]);
983 if (!p.has_key(name.back()))
return false;
984 ret = p.get<T>(name.back());
992 bool isRealData =
evt.isRealData();
994 std::unique_ptr<std::vector<caf::StandardRecord>> srcol(
995 new std::vector<caf::StandardRecord>);
997 std::unique_ptr<art::Assns<caf::StandardRecord, recob::Slice>> srAssn(
998 new art::Assns<caf::StandardRecord, recob::Slice>);
1003 art::Handle<std::vector<simb::MCTruth>> mctruth_handle;
1004 GetByLabelStrict(
evt, fParams.GenLabel(), mctruth_handle);
1006 std::vector<art::Ptr<simb::MCTruth>> mctruths;
1007 if (mctruth_handle.isValid()) {
1008 art::fill_ptr_vector(mctruths, mctruth_handle);
1012 art::FindManyP<simb::GTruth> fmp_gtruth = FindManyPStrict<simb::GTruth>(mctruths,
evt, fParams.GenLabel());
1014 art::Handle<std::vector<simb::MCTruth>> cosmic_mctruth_handle;
1015 evt.getByLabel(fParams.CosmicGenLabel(), cosmic_mctruth_handle);
1017 art::Handle<std::vector<simb::MCTruth>> pgun_mctruth_handle;
1018 evt.getByLabel(fParams.ParticleGunGenLabel(), pgun_mctruth_handle);
1022 if (mctruth_handle.isValid() && cosmic_mctruth_handle.isValid()) {
1025 else if (mctruth_handle.isValid()) {
1028 else if (cosmic_mctruth_handle.isValid()) {
1031 else if (pgun_mctruth_handle.isValid()) {
1038 art::Handle<std::vector<evgen::ldm::MeVPrtlTruth>> mevprtltruth_handle;
1039 evt.getByLabel(fParams.GenLabel(), mevprtltruth_handle);
1041 std::vector<art::Ptr<evgen::ldm::MeVPrtlTruth>> mevprtl_truths;
1042 if (mevprtltruth_handle.isValid()) art::fill_ptr_vector(mevprtl_truths, mevprtltruth_handle);
1045 art::Handle<std::vector<sim::SimChannel>> simchannel_handle;
1046 GetByLabelStrict(evt, fParams.SimChannelLabel(), simchannel_handle);
1048 std::vector<art::Ptr<sim::SimChannel>> simchannels;
1049 if (simchannel_handle.isValid()) {
1050 art::fill_ptr_vector(simchannels, simchannel_handle);
1053 art::Handle<std::vector<simb::MCFlux>> mcflux_handle;
1054 GetByLabelStrict(evt,
"generator", mcflux_handle);
1056 std::vector<art::Ptr<simb::MCFlux>> mcfluxes;
1057 if (mcflux_handle.isValid()) {
1058 art::fill_ptr_vector(mcfluxes, mcflux_handle);
1062 art::Handle<std::vector<sim::MCTrack>> mctrack_handle;
1063 GetByLabelStrict(evt,
"mcreco", mctrack_handle);
1064 std::vector<art::Ptr<sim::MCTrack>> mctracks;
1065 if (mctrack_handle.isValid()) {
1066 art::fill_ptr_vector(mctracks, mctrack_handle);
1070 std::vector<caf::SRTrueParticle> true_particles;
1071 art::Handle<std::vector<simb::MCParticle>> mc_particles;
1072 GetByLabelStrict(evt, fParams.G4Label(), mc_particles);
1076 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
1078 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clock_data);
1082 std::vector<std::string> pandora_tag_suffixes;
1083 fParams.PandoraTagSuffixes(pandora_tag_suffixes);
1084 if (pandora_tag_suffixes.size() == 0) pandora_tag_suffixes.push_back(
"");
1087 std::vector<art::Ptr<recob::Hit>> hits;
1088 for (
unsigned i_tag = 0; i_tag < pandora_tag_suffixes.size(); i_tag++) {
1089 const std::string &pandora_tag_suffix = pandora_tag_suffixes[i_tag];
1090 art::Handle<std::vector<recob::Hit>> thisHits;
1091 GetByLabelStrict(evt, fParams.HitLabel() + pandora_tag_suffix, thisHits);
1092 if (thisHits.isValid()) {
1093 art::fill_ptr_vector(hits, thisHits);
1098 std::map<int, std::vector<std::pair<geo::WireID, const sim::IDE*>>> id_to_ide_map;
1099 std::map<int, std::vector<art::Ptr<recob::Hit>>> id_to_truehit_map;
1100 std::map<int, caf::HitsEnergy> id_to_hit_energy_map;
1102 if ( !isRealData ) {
1103 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
1106 id_to_truehit_map =
PrepTrueHits(hits, clock_data, *bt_serv);
1116 if (mc_particles.isValid()) {
1117 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
1118 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
1120 for (
const simb::MCParticle part: *mc_particles) {
1121 true_particles.emplace_back();
1131 true_particles.back());
1135 std::vector<art::FindManyP<sbn::evwgh::EventWeightMap>> fmpewm;
1138 simb::MCFlux badflux;
1140 for (
size_t i=0; i<mctruths.size(); i++) {
1141 auto const& mctruth = mctruths.at(i);
1142 const simb::MCFlux &mcflux = (mcfluxes.size()) ? *mcfluxes.at(i) : badflux;
1144 simb::GTruth gtruth;
1145 bool ok = GetAssociatedProduct(fmp_gtruth, i, gtruth);
1147 std::cout <<
"Failed to get GTruth object!" << std::endl;
1151 srtruthbranch.
nnu ++;
1153 if ( !isRealData )
FillTrueNeutrino(mctruth, mcflux, gtruth, true_particles, id_to_truehit_map, srtruthbranch.
nu.back(), i, fActiveVolumes);
1159 if(fmpewm.empty() && mctruth->NeutrinoSet()){
1160 for(
const std::string& label: fParams.SystWeightLabels()){
1161 fmpewm.push_back(FindManyPStrict<sbn::evwgh::EventWeightMap>(mctruths, evt, label));
1166 for(
auto& fm: fmpewm){
1167 if (!fm.isValid())
continue;
1170 const std::vector<art::Ptr<sbn::evwgh::EventWeightMap>> wgts = fm.at(i);
1173 for(
const art::Ptr<sbn::evwgh::EventWeightMap>& wgtmap: wgts){
1180 unsigned n_gen_evt = 0;
1181 for (
const art::ProcessConfiguration &process: evt.processHistory()) {
1182 fhicl::ParameterSet gen_config;
1183 bool success = evt.getProcessParameterSet(process.processName(), gen_config);
1184 if (success && gen_config.has_key(
"source") && gen_config.has_key(
"source.maxEvents") && gen_config.has_key(
"source.module_type") ) {
1185 int max_events = gen_config.get<
int>(
"source.maxEvents");
1186 std::string
module_type = gen_config.get<std::string>(
"source.module_type");
1187 if (module_type ==
"EmptyEvent") {
1188 n_gen_evt += max_events;
1193 std::vector<caf::SRFakeReco> srfakereco;
1194 FillFakeReco(mctruths, true_particles, mctracks, fActiveVolumes, *fFakeRecoTRandom, srfakereco);
1197 for (
unsigned i_prtl = 0; i_prtl < mevprtl_truths.size(); i_prtl++) {
1198 srtruthbranch.
prtl.emplace_back();
1200 srtruthbranch.
nprtl = srtruthbranch.
prtl.size();
1212 const auto& trig = evt.getProduct<std::vector<raw::Trigger>>(fParams.TriggerLabel());
1220 bool pass_flash_trig =
false;
1221 art::Handle<bool> flashtrig_handle;
1222 GetByLabelStrict(evt, fParams.FlashTrigLabel(), flashtrig_handle);
1224 if (flashtrig_handle.isValid()) {
1225 pass_flash_trig = *flashtrig_handle;
1231 std::vector<caf::SRCRTHit> srcrthits;
1233 art::Handle<std::vector<sbn::crt::CRTHit>> crthits_handle;
1234 GetByLabelStrict(evt, fParams.CRTHitLabel(), crthits_handle);
1236 if (crthits_handle.isValid()) {
1241 uint64_t m_gate_start_timestamp = fParams.CRTSimT0Offset();
1244 art::Handle< std::vector<raw::ExternalTrigger> > externalTrigger_handle;
1245 evt.getByLabel( fParams.TriggerLabel(), externalTrigger_handle );
1246 const std::vector<raw::ExternalTrigger> &externalTrgs = *externalTrigger_handle;
1248 art::Handle< std::vector<raw::Trigger> > trigger_handle;
1249 evt.getByLabel( fParams.TriggerLabel(), trigger_handle );
1250 const std::vector<raw::Trigger> &trgs = *trigger_handle;
1252 if(externalTrgs.size()==1 && trgs.size()==1){
1253 long long TriggerAbsoluteTime = externalTrgs[0].GetTrigTime();
1254 double BeamGateRelativeTime = trgs[0].BeamGateTime();
1255 double TriggerRelativeTime = trgs[0].TriggerTime();
1256 m_gate_start_timestamp = TriggerAbsoluteTime + (int)(BeamGateRelativeTime*1000-TriggerRelativeTime*1000);
1259 std::cout <<
"Unexpected in " << evt.id() <<
": there are " << trgs.size()
1260 <<
" triggers in '" << fParams.TriggerLabel().encode() <<
"' data product."
1261 <<
" Please contact CAFmaker maintainer." << std::endl;
1266 const std::vector<sbn::crt::CRTHit> &crthits = *crthits_handle;
1267 for (
unsigned i = 0; i < crthits.size(); i++) {
1268 srcrthits.emplace_back();
1269 FillCRTHit(crthits[i], m_gate_start_timestamp, fParams.CRTUseTS0(), srcrthits.back());
1274 std::vector<caf::SRCRTTrack> srcrttracks;
1276 art::Handle<std::vector<sbn::crt::CRTTrack>> crttracks_handle;
1277 GetByLabelStrict(evt, fParams.CRTTrackLabel(), crttracks_handle);
1279 if (crttracks_handle.isValid()) {
1280 const std::vector<sbn::crt::CRTTrack> &crttracks = *crttracks_handle;
1281 for (
unsigned i = 0; i < crttracks.size(); i++) {
1282 srcrttracks.emplace_back();
1283 FillCRTTrack(crttracks[i], fParams.CRTUseTS0(), srcrttracks.back());
1288 std::vector<caf::SROpFlash> srflashes;
1290 for (
const std::string& pandora_tag_suffix : pandora_tag_suffixes) {
1291 art::Handle<std::vector<recob::OpFlash>> flashes_handle;
1292 GetByLabelStrict(evt, fParams.OpFlashLabel() + pandora_tag_suffix, flashes_handle);
1294 if (flashes_handle.isValid()) {
1295 const std::vector<recob::OpFlash> &opflashes = *flashes_handle;
1296 int cryostat = ( pandora_tag_suffix.find(
"W") != std::string::npos ) ? 1 : 0;
1298 srflashes.emplace_back();
1305 std::vector<art::Ptr<recob::Slice>>
slices;
1306 std::vector<std::string> slice_tag_suffixes;
1307 std::vector<unsigned> slice_tag_indices;
1308 for (
unsigned i_tag = 0; i_tag < pandora_tag_suffixes.size(); i_tag++) {
1309 const std::string &pandora_tag_suffix = pandora_tag_suffixes[i_tag];
1311 art::Handle<std::vector<recob::Slice>> thisSlices;
1312 GetByLabelStrict(evt, fParams.PFParticleLabel() + pandora_tag_suffix, thisSlices);
1313 if (thisSlices.isValid()) {
1314 art::fill_ptr_vector(slices, thisSlices);
1315 for (
unsigned i = 0; i < thisSlices->size(); i++) {
1316 slice_tag_suffixes.push_back(pandora_tag_suffix);
1317 slice_tag_indices.push_back(i_tag);
1329 for (
unsigned sliceID = 0; sliceID < slices.size(); sliceID++) {
1334 art::Ptr<recob::Slice> slice = slices[sliceID];
1335 const std::string &slice_tag_suff = slice_tag_suffixes[sliceID];
1336 unsigned producer = slice_tag_indices[sliceID];
1339 std::vector<art::Ptr<recob::Slice>> sliceList {slice};
1340 art::FindManyP<recob::PFParticle> findManyPFParts =
1341 FindManyPStrict<recob::PFParticle>(sliceList,
evt, fParams.PFParticleLabel() + slice_tag_suff);
1343 std::vector<art::Ptr<recob::PFParticle>> fmPFPart;
1344 if (findManyPFParts.isValid()) {
1345 fmPFPart = findManyPFParts.at(0);
1348 art::FindManyP<recob::Hit> fmSlcHits =
1349 FindManyPStrict<recob::Hit>(sliceList,
evt, fParams.PFParticleLabel() + slice_tag_suff);
1351 std::vector<art::Ptr<recob::Hit>> slcHits;
1352 if (fmSlcHits.isValid()) {
1353 slcHits = fmSlcHits.at(0);
1356 art::FindOneP<sbn::CRUMBSResult> foSlcCRUMBS =
1357 FindOnePStrict<sbn::CRUMBSResult>(sliceList,
evt,
1358 fParams.CRUMBSLabel() + slice_tag_suff);
1360 if (foSlcCRUMBS.isValid()) {
1361 slcCRUMBS = foSlcCRUMBS.at(0).get();
1364 art::FindManyP<sbn::SimpleFlashMatch> fm_sFM =
1365 FindManyPStrict<sbn::SimpleFlashMatch>(fmPFPart,
evt,
1366 fParams.FlashMatchLabel() + slice_tag_suff);
1368 art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta =
1369 FindManyPStrict<larpandoraobj::PFParticleMetadata>(fmPFPart,
evt,
1370 fParams.PFParticleLabel() + slice_tag_suff);
1372 art::FindManyP<recob::SpacePoint> fmSpacePoint =
1373 FindManyPStrict<recob::SpacePoint>(slcHits,
evt, fParams.PFParticleLabel() + slice_tag_suff);
1375 std::vector<art::Ptr<recob::SpacePoint>> slcSpacePoints;
1376 if (fmSpacePoint.isValid()) {
1377 for (
unsigned i = 0; i < fmSpacePoint.size(); i++) {
1378 const std::vector<art::Ptr<recob::SpacePoint>> &thisSpacePoints = fmSpacePoint.at(i);
1379 if (thisSpacePoints.size() == 0) {
1380 slcSpacePoints.emplace_back();
1382 else if (thisSpacePoints.size() == 1) {
1383 slcSpacePoints.push_back(fmSpacePoint.at(i).at(0));
1389 art::FindManyP<recob::PFParticle> fmSpacePointPFPs =
1390 FindManyPStrict<recob::PFParticle>(slcSpacePoints,
evt, fParams.PFParticleLabel() + slice_tag_suff);
1392 art::FindManyP<recob::Shower> fmShower =
1393 FindManyPStrict<recob::Shower>(fmPFPart,
evt, fParams.RecoShowerLabel() + slice_tag_suff);
1396 std::vector<art::Ptr<recob::Shower>> slcShowers;
1397 if (fmShower.isValid()) {
1398 for (
unsigned i = 0; i < fmShower.size(); i++) {
1399 const std::vector<art::Ptr<recob::Shower>> &thisShowers = fmShower.at(i);
1400 if (thisShowers.size() == 0) {
1401 slcShowers.emplace_back();
1403 else if (thisShowers.size() == 1) {
1404 slcShowers.push_back(fmShower.at(i).at(0));
1410 art::FindManyP<float> fmShowerCosmicDist =
1411 FindManyPStrict<float>(slcShowers,
evt, fParams.ShowerCosmicDistLabel() + slice_tag_suff);
1413 art::FindManyP<float> fmShowerResiduals =
1414 FindManyPStrict<float>(slcShowers,
evt, fParams.RecoShowerSelectionLabel() + slice_tag_suff);
1416 art::FindManyP<sbn::ShowerTrackFit> fmShowerTrackFit =
1417 FindManyPStrict<sbn::ShowerTrackFit>(slcShowers,
evt, fParams.RecoShowerSelectionLabel() + slice_tag_suff);
1419 art::FindManyP<sbn::ShowerDensityFit> fmShowerDensityFit =
1420 FindManyPStrict<sbn::ShowerDensityFit>(slcShowers,
evt, fParams.RecoShowerSelectionLabel() + slice_tag_suff);
1422 art::FindManyP<recob::Track> fmTrack =
1423 FindManyPStrict<recob::Track>(fmPFPart,
evt,
1424 fParams.RecoTrackLabel() + slice_tag_suff);
1427 std::vector<art::Ptr<recob::Track>> slcTracks;
1428 if (fmTrack.isValid()) {
1429 for (
unsigned i = 0; i < fmTrack.size(); i++) {
1430 const std::vector<art::Ptr<recob::Track>> &thisTracks = fmTrack.at(i);
1431 if (thisTracks.size() == 0) {
1432 slcTracks.emplace_back();
1434 else if (thisTracks.size() == 1) {
1435 slcTracks.push_back(fmTrack.at(i).at(0));
1442 art::FindManyP<sbn::Stub> fmSlcStubs =
1443 FindManyPStrict<sbn::Stub>(sliceList,
evt,
1444 fParams.StubLabel() + slice_tag_suff);
1446 std::vector<art::Ptr<sbn::Stub>> fmStubs;
1447 if (fmSlcStubs.isValid()) {
1448 fmStubs = fmSlcStubs.at(0);
1452 art::FindManyP<recob::PFParticle> fmStubPFPs =
1453 FindManyPStrict<recob::PFParticle>(fmStubs,
evt,
1454 fParams.StubLabel() + slice_tag_suff);
1456 art::FindManyP<recob::Hit> fmStubHits =
1457 FindManyPStrict<recob::Hit>(fmStubs,
evt,
1458 fParams.StubLabel() + slice_tag_suff);
1460 art::FindManyP<anab::Calorimetry> fmCalo =
1461 FindManyPStrict<anab::Calorimetry>(slcTracks,
evt,
1462 fParams.TrackCaloLabel() + slice_tag_suff);
1464 art::FindManyP<anab::ParticleID> fmChi2PID =
1465 FindManyPStrict<anab::ParticleID>(slcTracks,
evt,
1466 fParams.TrackChi2PidLabel() + slice_tag_suff);
1468 art::FindManyP<sbn::ScatterClosestApproach> fmScatterClosestApproach =
1469 FindManyPStrict<sbn::ScatterClosestApproach>(slcTracks,
evt,
1470 fParams.TrackScatterClosestApproachLabel() + slice_tag_suff);
1472 art::FindManyP<sbn::StoppingChi2Fit> fmStoppingChi2Fit =
1473 FindManyPStrict<sbn::StoppingChi2Fit>(slcTracks,
evt,
1474 fParams.TrackStoppingChi2FitLabel() + slice_tag_suff);
1476 art::FindManyP<sbn::MVAPID> fmTrackDazzle =
1477 FindManyPStrict<sbn::MVAPID>(slcTracks,
evt,
1478 fParams.TrackDazzleLabel() + slice_tag_suff);
1480 art::FindManyP<sbn::MVAPID> fmShowerRazzle =
1481 FindManyPStrict<sbn::MVAPID>(slcShowers,
evt,
1482 fParams.ShowerRazzleLabel() + slice_tag_suff);
1484 art::FindManyP<recob::Vertex> fmVertex =
1485 FindManyPStrict<recob::Vertex>(fmPFPart,
evt,
1486 fParams.PFParticleLabel() + slice_tag_suff);
1488 art::FindManyP<recob::Hit> fmTrackHit =
1489 FindManyPStrict<recob::Hit>(slcTracks,
evt,
1490 fParams.RecoTrackLabel() + slice_tag_suff);
1492 art::FindManyP<recob::Hit> fmShowerHit =
1493 FindManyPStrict<recob::Hit>(slcShowers,
evt,
1494 fParams.RecoShowerLabel() + slice_tag_suff);
1497 art::FindManyP<anab::T0> fmCRTHitMatch =
1498 FindManyPStrict<anab::T0>(slcTracks,
evt,
1499 fParams.CRTHitMatchLabel() + slice_tag_suff);
1502 art::FindManyP<anab::T0> fmCRTTrackMatch =
1503 FindManyPStrict<anab::T0>(slcTracks,
evt,
1504 fParams.CRTTrackMatchLabel() + slice_tag_suff);
1506 std::vector<art::FindManyP<recob::MCSFitResult>> fmMCSs;
1507 static const std::vector<std::string> PIDnames {
"muon",
"pion",
"kaon",
"proton"};
1508 for (std::string pid: PIDnames) {
1509 art::InputTag tag(fParams.TrackMCSLabel() + slice_tag_suff, pid);
1510 fmMCSs.push_back(FindManyPStrict<recob::MCSFitResult>(slcTracks, evt, tag));
1513 std::vector<art::FindManyP<sbn::RangeP>> fmRanges;
1514 static const std::vector<std::string> rangePIDnames {
"muon",
"pion",
"proton"};
1515 for (std::string pid: rangePIDnames) {
1516 art::InputTag tag(fParams.TrackRangeLabel() + slice_tag_suff, pid);
1517 fmRanges.push_back(FindManyPStrict<sbn::RangeP>(slcTracks, evt, tag));
1525 for (iPart = 0; iPart < fmPFPart.size(); ++iPart ) {
1530 const recob::PFParticle *primary = (iPart == fmPFPart.size()) ? NULL : fmPFPart[iPart].
get();
1534 if (fm_sFM.isValid() && primary != NULL) {
1535 std::vector<art::Ptr<sbn::SimpleFlashMatch>> fmatches = fm_sFM.at(iPart);
1536 if (fmatches.size() != 0) {
1537 assert(fmatches.size() == 1);
1538 fmatch = fmatches[0].get();
1542 const recob::Vertex *
vertex = (iPart == fmPFPart.size() || !fmVertex.at(iPart).size()) ? NULL : fmVertex.at(iPart).at(0).get();
1555 if (!
SelectSlice(recslc, fParams.CutClearCosmic()))
continue;
1564 if ( !isRealData ) {
1565 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
1568 *pi_serv, clock_data, recslc);
1571 *pi_serv, clock_data, recslc, true_particles, mctracks,
1572 fActiveVolumes, *fFakeRecoTRandom);
1586 for (
size_t iStub = 0; iStub < fmStubs.size(); iStub++) {
1587 const sbn::Stub &thisStub = *fmStubs[iStub];
1589 art::Ptr<recob::PFParticle> thisStubPFP;
1590 if (!fmStubPFPs.at(iStub).empty()) thisStubPFP = fmStubPFPs.at(iStub).at(0);
1594 if ( !isRealData )
FillStubTruth(fmStubHits.at(iStub), id_to_hit_energy_map, true_particles, clock_data, rec.
reco.
stub.back());
1602 if (fParams.FillHits()) {
1603 for (
size_t iHit = 0; iHit < slcHits.size(); ++iHit ) {
1606 std::vector<art::Ptr<recob::PFParticle>> thisParticle;
1607 if (fmSpacePointPFPs.isValid()) {
1608 thisParticle = fmSpacePointPFPs.at(iHit);
1610 std::vector<art::Ptr<recob::SpacePoint>> thisPoint;
1611 if (fmSpacePoint.isValid()) {
1612 thisPoint = fmSpacePoint.at(iHit);
1614 if (!thisParticle.empty() && !thisPoint.empty()) {
1615 assert(thisParticle.size() == 1);
1616 assert(thisPoint.size() == 1);
1620 FillHitVars(thisHit, producer, *thisPoint[0], *thisParticle[0], rec.
reco.
hit.back());
1632 for (
size_t iPart = 0; iPart < fmPFPart.size(); ++iPart ) {
1635 std::vector<art::Ptr<recob::Track>> thisTrack;
1636 if (fmTrack.isValid()) {
1637 thisTrack = fmTrack.at(iPart);
1639 std::vector<art::Ptr<recob::Shower>> thisShower;
1640 if (fmShower.isValid()) {
1641 thisShower = fmShower.at(iPart);
1643 if (!thisTrack.empty()) {
1644 assert(thisTrack.size() == 1);
1645 assert(thisShower.size() == 0);
1650 std::array<std::vector<art::Ptr<recob::MCSFitResult>>, 4> trajectoryMCS;
1651 for (
unsigned index = 0; index < 4; index++) {
1652 if (fmMCSs[index].isValid()) {
1653 trajectoryMCS[index] = fmMCSs[index].at(iPart);
1656 trajectoryMCS[index] = std::vector<art::Ptr<recob::MCSFitResult>>();
1660 std::array<std::vector<art::Ptr<sbn::RangeP>>, 3> rangePs;
1661 for (
unsigned index = 0; index < 3; index++) {
1662 if (fmRanges[index].isValid()) {
1663 rangePs[index] = fmRanges[index].at(iPart);
1666 rangePs[index] = std::vector<art::Ptr<sbn::RangeP>>();
1679 if (fmChi2PID.isValid()) {
1682 if (fmScatterClosestApproach.isValid() && fmScatterClosestApproach.at(iPart).size()==1) {
1685 if (fmStoppingChi2Fit.isValid() && fmStoppingChi2Fit.at(iPart).size()==1) {
1688 if (fmTrackDazzle.isValid() && fmTrackDazzle.at(iPart).size()==1) {
1691 if (fmCalo.isValid()) {
1693 (fParams.FillHitsNeutrinoSlices() && NeutrinoSlice) || fParams.FillHitsAllSlices(),
1694 fParams.TrackHitFillRRStartCut(), fParams.TrackHitFillRREndCut(),
1695 lar::providerFrom<geo::Geometry>(), dprop, rec.
reco.
trk.back());
1697 if (fmTrackHit.isValid()) {
1698 if ( !isRealData )
FillTrackTruth(fmTrackHit.at(iPart), id_to_hit_energy_map, true_particles, clock_data, rec.
reco.
trk.back());
1701 if (fmCRTHitMatch.isValid()) {
1704 if (fmCRTTrackMatch.isValid()) {
1712 else if (!thisShower.empty()) {
1713 assert(thisTrack.size() == 0);
1714 assert(thisShower.size() == 1);
1717 FillShowerVars(*thisShower[0], vertex, fmShowerHit.at(iPart), lar::providerFrom<geo::Geometry>(), producer, rec.
reco.
shw.back());
1724 if (fmShowerRazzle.isValid() && fmShowerRazzle.at(iPart).size()==1) {
1727 if (fmShowerCosmicDist.isValid() && fmShowerCosmicDist.at(iPart).size() != 0) {
1730 if (fmShowerResiduals.isValid() && fmShowerResiduals.at(iPart).size() != 0) {
1733 if (fmShowerTrackFit.isValid() && fmShowerTrackFit.at(iPart).size() == 1) {
1736 if (fmShowerDensityFit.isValid() && fmShowerDensityFit.at(iPart).size() == 1) {
1739 if (fmShowerHit.isValid()) {
1740 if ( !isRealData )
FillShowerTruth(fmShowerHit.at(iPart), id_to_hit_energy_map, true_particles, clock_data, rec.
reco.
shw.back());
1764 rec.
slc.push_back(recslc);
1772 rec.
mc = srtruthbranch;
1782 if (fParams.FillTrueParticles()) {
1788 unsigned int run = evt.run();
1789 unsigned int subrun = evt.subRun();
1790 unsigned int evtID = evt.event();
1796 const char *process_str = std::getenv(
"PROCESS");
1799 rec.
hdr.
proc = std::stoi(process_str);
1804 const char *cluster_str = std::getenv(
"CLUSTER");
1818 rec.
hdr.
fno = fFileNumber;
1825 rec.
hdr.
pot = fSubRunPOT;
1843 fRecTree->SetBranchAddress(
"rec", &prec);
1847 fFlatRecord->Clear();
1848 fFlatRecord->Fill(rec);
1853 if (fParams.CreateBlindedCAF()) {
1854 const bool keepprescale = fBlindTRandom->Uniform() < 1/fParams.PrescaleFactor();
1858 if (fFirstPrescaleInFile) {
1859 precp->
hdr.
pot = fSubRunPOT*(1/fParams.PrescaleFactor());
1862 precp->
hdr.
nbnbinfo = fBNBInfo.size()*(1/fParams.PrescaleFactor());
1863 precp->
hdr.
nnumiinfo = fNuMIInfo.size()*(1/fParams.PrescaleFactor());
1865 precp->
hdr.
ngenevt = n_gen_evt*(1/fParams.PrescaleFactor());
1867 fRecTreep->SetBranchAddress(
"rec", &precp);
1869 fPrescaleEvents += 1;
1871 fFlatRecordp->Clear();
1872 fFlatRecordp->Fill(*precp);
1875 fFirstPrescaleInFile =
false;
1879 BlindEnergyParameters(precb);
1880 if (fFirstBlindInFile) {
1881 precb->
hdr.
pot = fSubRunPOT*(1-(1/fParams.PrescaleFactor()))*GetBlindPOTScale();
1884 precb->
hdr.
nbnbinfo = fBNBInfo.size()*(1 - (1/fParams.PrescaleFactor()));
1885 precb->
hdr.
nnumiinfo = fNuMIInfo.size()*(1-(1/fParams.PrescaleFactor()));
1887 precb->
hdr.
ngenevt = n_gen_evt*(1 - (1/fParams.PrescaleFactor()));
1889 fRecTreeb->SetBranchAddress(
"rec", &precb);
1893 fFlatRecordb->Clear();
1894 fFlatRecordb->Fill(*precb);
1897 fFirstBlindInFile =
false;
1903 fFirstInFile =
false;
1904 fFirstInSubRun =
false;
1905 srcol->push_back(rec);
1906 evt.put(std::move(srcol));
1924 TH1* hPOT =
new TH1D(
"TotalPOT",
"TotalPOT;; POT", 1, 0, 1);
1925 TH1* hEvents =
new TH1D(
"TotalEvents",
"TotalEvents;; Events", 1, 0, 1);
1930 else if (isPrescalePOT) {
1942 TH1*hBlindEvents =
new TH1D(
"BlindEvents",
"BlindEvents;; Events", 1, 0, 1);
1943 TH1* hPrescaleEvents =
new TH1D(
"PrescaleEvents",
"PrescaleEvents;; Events", 1, 0, 1);
1946 hBlindEvents->Write();
1947 hPrescaleEvents->Write();
1955 std::cerr <<
"No events processed in this file. Aborting rather than "
1956 "produce an empty CAF."
2003 std::map<std::string, std::string> metamap;
2006 art::ServiceHandle<util::MetadataSBN> meta;
2008 std::map<std::string, std::string> strs;
2009 std::map<std::string, int> ints;
2010 std::map<std::string, double> doubles;
2011 std::map<std::string, std::string> objs;
2012 meta->GetMetadataMaps(strs, ints, doubles, objs);
2014 for(
auto it: strs) metamap[it.first] =
"\""+it.second+
"\"";
2015 for(
auto it: ints) metamap[it.first] =
std::to_string(it.second);
2016 for(
auto it: doubles) metamap[it.first] =
std::to_string(it.second);
2017 for(
auto it: objs) metamap[it.first] = it.second;
2019 catch(art::Exception&
e){
2021 std::cout <<
"\n\nCAFMaker: TFileMetadataSBN service not configured -- this CAF will not have any metadata saved.\n" << std::endl;
void FillHitVars(const recob::Hit &hit, unsigned producer, const recob::SpacePoint &spacepoint, const recob::PFParticle &particle, caf::SRHit &srhit, bool allowEmpty)
void FillSliceVertex(const recob::Vertex *vertex, caf::SRSlice &slice, bool allowEmpty)
int ncrt_tracks
Number of CRT tracks in event.
void FillCRTHit(const sbn::crt::CRTHit &hit, uint64_t gate_start_timestamp, bool use_ts0, caf::SRCRTHit &srhit, bool allowEmpty)
Atom< string > UnblindFileExtension
void FillShowerRazzle(const art::Ptr< sbn::MVAPID > razzle, caf::SRShower &srshower, bool allowEmpty)
void BlindEnergyParameters(StandardRecord *brec)
std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * > > > PrepSimChannels(const std::vector< art::Ptr< sim::SimChannel >> &simchannels, const geo::GeometryCore &geo)
std::map< std::string, std::vector< sbn::evwgh::EventWeightParameterSet > > fPrevWeightPSet
Map from parameter labels to previously seen parameter set configuration.
Atom< string > FileExtension
void FillTrackCRTHit(const std::vector< art::Ptr< anab::T0 >> &t0match, caf::SRTrack &srtrack, bool allowEmpty)
A 3-vector with more efficient storage than TVector3.
Utilities related to art service access.
void FillShowerResiduals(const std::vector< art::Ptr< float > > &residuals, caf::SRShower &srshower)
SRHeader hdr
Header branch: run, subrun, etc.
Atom< string > PrescaleFileExtension
std::vector< caf::SRNuMIInfo > fNuMIInfo
Store detailed NuMI info to save into the first StandardRecord of the output file.
std::vector< SRMeVPrtl > prtl
If present – information on decay of MeV "Portal" particle.
void FillSliceVars(const recob::Slice &slice, const recob::PFParticle *primary, unsigned producer, caf::SRSlice &srslice, bool allowEmpty)
int nfake_reco
Number of Fake-Reco's in list.
const geo::GeometryCore * geometry
std::string DeriveFilename(const std::string &inname, const std::string &ext) const
BEGIN_PROLOG could also be cerr
void FillTrackRangeP(const recob::Track &track, const std::array< std::vector< art::Ptr< sbn::RangeP >>, 3 > &range_results, caf::SRTrack &srtrack, bool allowEmpty)
void FillTrueNeutrino(const art::Ptr< simb::MCTruth > mctruth, const simb::MCFlux &mcflux, const simb::GTruth >ruth, const std::vector< caf::SRTrueParticle > &srparticles, const std::map< int, std::vector< art::Ptr< recob::Hit >>> &id_to_truehit_map, caf::SRTrueInteraction &srneutrino, size_t i, const std::vector< geo::BoxBoundedGeo > &active_volumes)
void InitVolumes()
Initialize volumes from Gemotry service.
std::vector< caf::SRBNBInfo > fBNBInfo
Store detailed BNB info to save into the first StandardRecord of the output file. ...
void FillStubTruth(const std::vector< art::Ptr< recob::Hit >> &hits, const std::map< int, caf::HitsEnergy > &id_hits_map, const std::vector< caf::SRTrueParticle > &particles, const detinfo::DetectorClocksData &clockData, caf::SRStub &srstub, bool allowEmpty)
TRandom * fFakeRecoTRandom
The SRTrueInteraction is a representation of neutrino interaction information.
int nslc
Number of slices in list.
std::string fFlatCafFilename
static bool sortRBTrkLength(const art::Ptr< recob::Track > &a, const art::Ptr< recob::Track > &b)
Module to create Common Analysis Files from ART files.
std::vector< SRShower > shw
Vector of trac showers.
std::vector< SRHit > hit
Vector of hits.
void GetByLabelIfExists(const art::Event &evt, const std::string &label, art::Handle< T > &handle) const
void FillShowerDensityFit(const sbn::ShowerDensityFit &densityFit, caf::SRShower &srshower)
SRVector3D vertex
Candidate neutrino vertex in local detector coordinates [cm].
Geometry information for a single TPC.
virtual void endSubRun(art::SubRun &sr)
Atom< string > BlindFileExtension
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
Atom< std::string > DetectorOverride
SRTrueInteraction truth
Truth information on the slice.
std::size_t size(FixedBins< T, C > const &) noexcept
std::vector< SRSlice > slc
Slice branch.
void FillTrackCalo(const std::vector< art::Ptr< anab::Calorimetry >> &calos, const std::vector< art::Ptr< recob::Hit >> &hits, bool fill_calo_points, float fillhit_rrstart, float fillhit_rrend, const geo::GeometryCore *geom, const detinfo::DetectorPropertiesData &dprop, caf::SRTrack &srtrack, bool allowEmpty)
void FillTrackScatterClosestApproach(const art::Ptr< sbn::ScatterClosestApproach > closestapproach, caf::SRTrack &srtrack, bool allowEmpty)
flat::Flat< caf::StandardRecord > * fFlatRecord
void FillShowerVars(const recob::Shower &shower, const recob::Vertex *vertex, const std::vector< art::Ptr< recob::Hit >> &hits, const geo::GeometryCore *geom, unsigned producer, caf::SRShower &srshower, bool allowEmpty)
void FillStubVars(const sbn::Stub &stub, const art::Ptr< recob::PFParticle > stubpfp, caf::SRStub &srstub, bool allowEmpty)
size_t nshw
Number of trac showers.
void FillSliceTruth(const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< art::Ptr< simb::MCTruth >> &neutrinos, const caf::SRTruthBranch &srmc, const cheat::ParticleInventoryService &inventory_service, const detinfo::DetectorClocksData &clockData, caf::SRSlice &srslice, bool allowEmpty)
SRShowerPlaneInfo plane[3]
void FillExposure(const std::vector< sbn::BNBSpillInfo > &bnb_spill_info, std::vector< caf::SRBNBInfo > &BNBInfo, double &subRunPOT)
art::EDProducer::Table< CAFMakerParams > Parameters
void FillSliceFlashMatchA(const sbn::SimpleFlashMatch *fmatch, caf::SRSlice &srslice, bool allowEmpty)
Definition of vertex object for LArSoft.
MCType_t
Which type of MC?
Det_t fDet
Detector ID in caf namespace typedef.
art::FindManyP< T > FindManyPStrict(const U &from, const art::Event &evt, const art::InputTag &label) const
flat::Flat< caf::StandardRecord > * fFlatRecordb
Representation of a rb::Hit, knows hit amplitude and integral, geometric IDs, and time...
size_t nprtl
Number of portals.
std::map< int, caf::HitsEnergy > SetupIDHitEnergyMap(const std::vector< art::Ptr< recob::Hit >> &allHits, const detinfo::DetectorClocksData &clockData, const cheat::BackTrackerService &backtracker)
void FillTrackCRTTrack(const std::vector< art::Ptr< anab::T0 >> &t0match, caf::SRTrack &srtrack, bool allowEmpty)
void InitializeOutfiles()
Math::BigFloat precision(-16)
TPC_iterator begin_TPC() const
Returns an iterator pointing to the first TPC in the detector.
int ncrt_hits
Number of CRT hits in event.
Atom< string > FlatCAFFileExtension
bool SelectSlice(const caf::SRSlice &slice, bool cut_clear_cosmic)
std::string fFlatCafPrescaleFilename
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
std::vector< SRTrueInteraction > nu
Vector of true nu or cosmic.
ReweightType fRWType
Type of throws (the same for all parameters in a set)
void FillTrackVars(const recob::Track &track, unsigned producer, caf::SRTrack &srtrack, bool allowEmpty)
size_t nhit
Number of hits.
std::vector< SROpFlash > opflashes
List of OpFlashes in spill.
bool GetPsetParameter(const fhicl::ParameterSet &pset, const std::vector< std::string > &name, T &ret) const
void FillShowerTrackFit(const sbn::ShowerTrackFit &trackFit, caf::SRShower &srshower)
void FillSliceCRUMBS(const sbn::CRUMBSResult *crumbs, caf::SRSlice &slice, bool allowEmpty)
void FillTrackChi2PID(const std::vector< art::Ptr< anab::ParticleID >> particleIDs, const geo::GeometryCore *geom, caf::SRTrack &srtrack, bool allowEmpty)
void FillSliceFlashMatch(const sbn::SimpleFlashMatch *fmatch, caf::SRSlice &srslice, bool allowEmpty)
void FillShowerTruth(const std::vector< art::Ptr< recob::Hit >> &hits, const std::map< int, caf::HitsEnergy > &id_hits_map, const std::vector< caf::SRTrueParticle > &particles, const detinfo::DetectorClocksData &clockData, caf::SRShower &srshower, bool allowEmpty)
Metadata associated to PFParticles.
std::string fCafBlindFilename
size_t nstub
Number of stubs.
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
Atom< float > PrescaleFactor
float fwdP_muon
Momentum from start->end fit for muon [GeV/c].
bool is_clear_cosmic
Whether pandora marks the slice as a "clear" cosmic.
virtual void beginRun(art::Run &r)
std::vector< SRCRTHit > crt_hits
CRT hits in event.
Container for a set of reweightable parameters.
Atom< bool > CreateFlatCAF
size_t ntrk
Number of panora tracks.
SRSliceRecoBranch reco
TPC reco information for the slice.
std::vector< SRTrueParticle > true_particles
True particles in spill.
SRVector3D start
Start point of track.
void FillTrackStoppingChi2Fit(const art::Ptr< sbn::StoppingChi2Fit > stoppingChi2, caf::SRTrack &srtrack, bool allowEmpty)
std::vector< SRTrack > trk
Vector of pandora tracks.
std::map< EventWeightParameter, std::vector< float > > fParameterMap
Mapping of definitions to the set of values.
void respondToOpenInputFile(const art::FileBlock &fb)
bool IsPrimary() const
Returns whether the particle is the root of the flow.
void FillFakeReco(const std::vector< art::Ptr< simb::MCTruth >> &mctruths, const std::vector< caf::SRTrueParticle > &srparticles, const std::vector< art::Ptr< sim::MCTrack >> &mctracks, const std::vector< geo::BoxBoundedGeo > &volumes, TRandom &rand, std::vector< caf::SRFakeReco > &srfakereco)
void AddMetadataToFile(TFile *f, const std::map< std::string, std::string > &metadata)
void FillMeVPrtlTruth(const evgen::ldm::MeVPrtlTruth &truth, const std::vector< geo::BoxBoundedGeo > &active_volumes, caf::SRMeVPrtl &srtruth)
void AddEnvToFile(TFile *f)
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch fmatch
bool pass_flashtrig
Whether this Record passed the Flash Trigger requirement.
Description of geometry of one entire detector.
SRVector3D start
shower start point in detector coordinates [cm]
An SRSlice contains overarching information for a slice.
void FillCRTTrack(const sbn::crt::CRTTrack &track, bool use_ts0, caf::SRCRTTrack &srtrack, bool allowEmpty)
std::vector< SRCRTTrack > crt_tracks
CRT tracks in event.
bool fFirstPrescaleInFile
Atom< string > BNBPOTDataLabel
double GetBlindPOTScale() const
Provides recob::Track data product.
std::vector< TCSlice > slices
void FillTrueG4Particle(const simb::MCParticle &particle, const std::vector< geo::BoxBoundedGeo > &active_volumes, const std::vector< std::vector< geo::BoxBoundedGeo >> &tpc_volumes, const std::map< int, std::vector< std::pair< geo::WireID, const sim::IDE * >>> &id_to_ide_map, const std::map< int, std::vector< art::Ptr< recob::Hit >>> &id_to_truehit_map, const cheat::BackTrackerService &backtracker, const cheat::ParticleInventoryService &inventory_service, const std::vector< art::Ptr< simb::MCTruth >> &neutrinos, caf::SRTrueParticle &srparticle)
void FillOpFlash(const recob::OpFlash &flash, int cryo, caf::SROpFlash &srflash, bool allowEmpty)
float p_muon
momentum estimate from trk range (muon hypothesis)
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
int ntrue_particles
Number of true particles in list.
CAFMaker(const Parameters ¶ms)
void AddHistogramsToFile(TFile *outfile, bool isBlindPOT, bool isPrescalePOT) const
void FillSliceMetadata(const larpandoraobj::PFParticleMetadata *primary_meta, caf::SRSlice &srslice, bool allowEmpty)
The StandardRecord is the primary top-level object in the Common Analysis File trees.
std::ostream & operator<<(std::ostream &os, const sbn::evwgh::EventWeightParameterSet &p)
Atom< string > NuMIPOTDataLabel
Hierarchical representation of particle flow.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 module_type
bool GetAssociatedProduct(const art::FindManyP< T > &fm, int idx, T &ret) const
Retrieve an object from an association, with error handling.
std::vector< std::vector< geo::BoxBoundedGeo > > fTPCVolumes
void FillTrackTruth(const std::vector< art::Ptr< recob::Hit >> &hits, const std::map< int, caf::HitsEnergy > &id_hits_map, const std::vector< caf::SRTrueParticle > &particles, const detinfo::DetectorClocksData &clockData, caf::SRTrack &srtrack, bool allowEmpty)
void FillSliceFakeReco(const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< art::Ptr< simb::MCTruth >> &neutrinos, const caf::SRTruthBranch &srmc, const cheat::ParticleInventoryService &inventory_service, const detinfo::DetectorClocksData &clockData, caf::SRSlice &srslice, const std::vector< caf::SRTrueParticle > &srparticles, const std::vector< art::Ptr< sim::MCTrack >> &mctracks, const std::vector< geo::BoxBoundedGeo > &volumes, TRandom &rand)
void produce(art::Event &evt) noexcept
std::vector< SRFakeReco > fake_reco
List of fake-reco slices.
art::FindManyP< T, D > FindManyPDStrict(const U &from, const art::Event &evt, const art::InputTag &tag) const
void FillPFPVars(const recob::PFParticle &particle, const recob::PFParticle *primary, const larpandoraobj::PFParticleMetadata *pfpMeta, caf::SRPFP &srpfp, bool allowEmpty)
void FillTrackDazzle(const art::Ptr< sbn::MVAPID > dazzle, caf::SRTrack &srtrack, bool allowEmpty)
size_t nnu
Number of true nu or cosmic.
std::string to_string(WindowPattern const &pattern)
std::map< int, std::vector< art::Ptr< recob::Hit > > > PrepTrueHits(const std::vector< art::Ptr< recob::Hit >> &allHits, const detinfo::DetectorClocksData &clockData, const cheat::BackTrackerService &backtracker)
SRSliceRecoBranch reco
Slice reco branch: tracks, showers, etc.
void FillTrigger(const sbn::ExtraTriggerInfo &addltrig_info, const std::vector< raw::Trigger > &trig_info, std::vector< caf::SRTrigger > &triggerInfo)
void FillShowerCosmicDist(const std::vector< art::Ptr< float > > &cosmicDistVec, caf::SRShower &srshower)
Vectors of reconstructed vertices found by various algorithms.
std::vector< geo::BoxBoundedGeo > fActiveVolumes
float bestplane_energy
shower energy at best plane [GeV]
std::string fName
Name of the parameter set.
void AddGlobalTreeToFile(TFile *outfile, caf::SRGlobal &global) const
SRTruthBranch mc
Truth branch for all interactions.
2D representation of charge deposited in the TDC/wire plane
Atom< bool > CreateBlindedCAF
void FillExposureNuMI(const std::vector< sbn::NuMISpillInfo > &numi_spill_info, std::vector< caf::SRNuMIInfo > &NuMIInfo, double &subRunPOT)
art::FindOneP< T > FindOnePStrict(const U &from, const art::Event &evt, const art::InputTag &label) const
std::vector< caf::SRTrigger > fSRTrigger
Store trigger and beam gate information.
virtual void beginSubRun(art::SubRun &sr)
Forward iterator browsing all geometry elements in the detector.
float energy
shower calculated energy for this plane [GeV]
void FillEventWeight(const sbn::evwgh::EventWeightMap &wgtmap, caf::SRTrueInteraction &srint, const std::map< std::string, unsigned int > &weightPSetIndex)
int nopflashes
Number of OpFlashes in spill.
std::string fFlatCafBlindFilename
void FillSRGlobal(const sbn::evwgh::EventWeightParameterSet &pset, caf::SRGlobal &srglobal, std::map< std::string, unsigned int > &weightPSetIndex)
static bool EssentiallyEqual(double a, double b, double precision=0.0001)
void GetByLabelStrict(const EvtT &evt, const std::string &label, art::Handle< T > &handle) const
Sequence< std::string > SystWeightLabels
std::string fCafPrescaleFilename
flat::Flat< caf::StandardRecord > * fFlatRecordp
BEGIN_PROLOG could also be cout
std::vector< SRStub > stub
Vector of stubs.
TPC_iterator end_TPC() const
Returns an iterator pointing after the last TPC in the detector.
std::map< std::string, unsigned int > fWeightPSetIndex
What position in the vector each parameter set take.
void FillTrackMCS(const recob::Track &track, const std::array< std::vector< art::Ptr< recob::MCSFitResult >>, 4 > &mcs_results, caf::SRTrack &srtrack, bool allowEmpty)