115 unsigned evt =
e.event();
116 unsigned sub =
e.subRun();
117 unsigned run =
e.run();
119 std::cout <<
"[TrackCaloSkimmer::analyzeEvent] Run: " << run <<
", SubRun: " << sub <<
", Event: "<< evt <<
", Is Data: " <<
e.isRealData() << std::endl;
129 auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(
e);
131 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(
e, clock_data);
136 gdml = basename(gdml.c_str());
138 for(
unsigned int i = 0; i <gdml.size(); ++i) gdml[i] = std::tolower(gdml[i]);
142 const bool hasSBND = ((gdml.find(
"sbnd") != std::string::npos) ||
143 (geometry->
DetectorName().find(
"sbnd") != std::string::npos));
145 const bool hasICARUS = ((gdml.find(
"icarus") != std::string::npos) ||
146 (geometry->
DetectorName().find(
"icarus") != std::string::npos));
148 if(hasSBND == hasICARUS) {
149 std::cout <<
"TrackCaloSkimmer: Unable to automatically determine either SBND or ICARUS!" << std::endl;
153 if(hasSBND) det =
kSBND;
157 std::vector<std::vector<geo::BoxBoundedGeo>> TPCVols;
158 std::vector<geo::BoxBoundedGeo> AVs;
163 tend = geometry->
end_TPC(cryo.ID());
164 std::vector<geo::BoxBoundedGeo> this_tpc_volumes;
165 while (iTPC != tend) {
170 TPCVols.push_back(std::move(this_tpc_volumes));
173 for (
const std::vector<geo::BoxBoundedGeo> &tpcs: TPCVols) {
174 double XMin = std::min_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MinX() < rhs.MinX(); })->MinX();
175 double YMin = std::min_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MinY() < rhs.MinY(); })->MinY();
176 double ZMin = std::min_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MinZ() < rhs.MinZ(); })->MinZ();
178 double XMax = std::max_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MaxX() < rhs.MaxX(); })->MaxX();
179 double YMax = std::max_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MaxY() < rhs.MaxY(); })->MaxY();
180 double ZMax = std::max_element(tpcs.begin(), tpcs.end(), [](
auto &lhs,
auto &rhs) {
return lhs.MaxZ() < rhs.MaxZ(); })->MaxZ();
182 AVs.emplace_back(XMin, XMax, YMin, YMax, ZMin, ZMax);
186 std::vector<art::Ptr<simb::MCParticle>> mcparticles;
188 art::ValidHandle<std::vector<simb::MCParticle>> mcparticle_handle =
e.getValidHandle<std::vector<simb::MCParticle>>(
fG4producer);
189 art::fill_ptr_vector(mcparticles, mcparticle_handle);
192 std::vector<art::Ptr<sim::SimChannel>> simchannels;
194 art::ValidHandle<std::vector<sim::SimChannel>> simchannel_handle =
e.getValidHandle<std::vector<sim::SimChannel>>(
fSimChannelproducer);
195 art::fill_ptr_vector(simchannels, simchannel_handle);
199 std::vector<art::Ptr<recob::PFParticle>> PFParticleList;
201 art::ValidHandle<std::vector<recob::PFParticle>> pfparticles =
e.getValidHandle<std::vector<recob::PFParticle>>(
fPFPproducer);
202 art::fill_ptr_vector(PFParticleList, pfparticles);
212 std::vector<art::FindManyP<anab::T0>> fmT0;
213 for (
unsigned i_label = 0; i_label <
fT0producers.size(); i_label++) {
216 art::FindManyP<recob::SpacePoint> PFParticleSPs(PFParticleList,
e, fPFPproducer);
219 art::ValidHandle<std::vector<recob::Track>>
tracks =
e.getValidHandle<std::vector<recob::Track>>(
fTRKproducer);
222 art::FindManyP<recob::Track> fmTracks(PFParticleList,
e,
fTRKproducer);
225 art::FindManyP<recob::Hit, recob::TrackHitMeta> fmtrkHits(tracks,
e, thm_label);
226 art::FindManyP<anab::Calorimetry> fmCalo(tracks,
e,
fCALOproducer);
229 std::vector<art::Ptr<raw::RawDigit>> rawdigitlist;
231 art::ValidHandle<std::vector<raw::RawDigit>> thisdigits =
e.getValidHandle<std::vector<raw::RawDigit>>(t);
232 art::fill_ptr_vector(rawdigitlist, thisdigits);
236 std::map<geo::WireID, art::Ptr<raw::RawDigit>> rawdigits;
237 for (
const art::Ptr<raw::RawDigit> &d: rawdigitlist) {
239 std::vector<geo::WireID> wids;
249 if (wids.size() == 0)
continue;
252 if (rawdigits.count(wids[0]))
continue;
254 rawdigits[wids[0]] = d;
258 art::ValidHandle<std::vector<recob::Hit>> allhit_handle =
e.getValidHandle<std::vector<recob::Hit>>(
fHITproducer);
259 std::vector<art::Ptr<recob::Hit>> allHits;
260 art::fill_ptr_vector(allHits, allhit_handle);
263 art::FindManyP<recob::SpacePoint> allHitSPs(allHits,
e, fPFPproducer);
268 std::map<int, std::vector<std::pair<geo::WireID, const sim::IDE*>>> id_to_ide_map;
269 std::map<int, std::vector<art::Ptr<recob::Hit>>> id_to_truehit_map;
272 if (simchannels.size()) {
273 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
282 std::vector<GlobalTrackInfo> track_infos;
284 track_infos.push_back({
285 t.Start(), t.End(), t.StartDirection(), t.EndDirection(), t.ID()
289 for (art::Ptr<recob::PFParticle> p_pfp: PFParticleList) {
292 const std::vector<art::Ptr<recob::Track>> thisTrack = fmTracks.at(p_pfp.key());
293 if (thisTrack.size() != 1)
296 art::Ptr<recob::Track> trkPtr = thisTrack.at(0);
298 std::vector<art::Ptr<anab::Calorimetry>> emptyCaloVector;
299 const std::vector<art::Ptr<anab::Calorimetry>> &
calo = fmCalo.isValid() ? fmCalo.at(trkPtr.key()) : emptyCaloVector;
301 std::vector<art::Ptr<recob::Hit>> emptyHitVector;
302 const std::vector<art::Ptr<recob::Hit>> &trkHits = fmtrkHits.isValid() ? fmtrkHits.at(trkPtr.key()) : emptyHitVector;
304 art::FindManyP<recob::SpacePoint> fmtrkHitSPs(trkHits,
e, fPFPproducer);
306 std::vector<const recob::TrackHitMeta*> emptyTHMVector;
307 const std::vector<const recob::TrackHitMeta*> &trkHitMetas = fmtrkHits.isValid() ? fmtrkHits.data(trkPtr.key()) : emptyTHMVector;
309 art::Ptr<recob::SpacePoint> nullSP;
310 std::vector<art::Ptr<recob::SpacePoint>> trkHitSPs;
311 if (fmtrkHitSPs.isValid()) {
312 for (
unsigned i_hit = 0; i_hit < trkHits.size(); i_hit++) {
313 const std::vector<art::Ptr<recob::SpacePoint>> &h_sp = fmtrkHitSPs.at(i_hit);
315 trkHitSPs.push_back(h_sp.at(0));
318 trkHitSPs.push_back(nullSP);
324 float t0 = std::numeric_limits<float>::signaling_NaN();
325 for (
unsigned i_t0 = 0; i_t0 < fmT0.size(); i_t0++) {
326 if (fmT0[i_t0].isValid() && fmT0[i_t0].at(p_pfp.key()).
size()) {
327 t0 = fmT0[i_t0].at(p_pfp.key()).at(0)->Time();
340 if (
fVerbose)
std::cout <<
"Processing new track! ID: " << trkPtr->ID() <<
" time: " << t0 << std::endl;
350 FillTrack(*trkPtr, pfp, t0, trkHits, trkHitMetas, trkHitSPs, calo, rawdigits, track_infos, geometry, clock_data, bt, det);
358 if (simchannels.size())
FillTrackTruth(clock_data, trkHits, mcparticles, AVs, TPCVols, id_to_ide_map, id_to_truehit_map, dprop, geometry);
366 for (
const std::unique_ptr<sbn::ITCSSelectionTool> &t:
fSelectionTools) {
367 if (t->DoSelect(*
fTrack)) {
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< geo::WireID, std::pair< int, int > > fWiresToSave
art::InputTag fHITproducer
int nprescale
Prescale of the tool that selected this track.
ClusterModuleLabel join with tracks
const geo::GeometryCore * geometry
std::map< Snippet, int > fSnippetCount
void FillTrackEndHits(const geo::GeometryCore *geometry, const detinfo::DetectorPropertiesData &dprop, const recob::Track &track, const std::vector< art::Ptr< recob::Hit >> &allHits, const art::FindManyP< recob::SpacePoint > &allHitSPs)
Geometry information for a single TPC.
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
std::vector< art::InputTag > fRawDigitproducers
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::size_t size(FixedBins< T, C > const &) noexcept
void FillTrackDaughterRays(const recob::Track &trk, const recob::PFParticle &pfp, const std::vector< art::Ptr< recob::PFParticle >> &PFParticleList, const art::FindManyP< recob::SpacePoint > &PFParticleSPs)
int whicht0
Which T0 producer was used to tag.
void FillTrackTruth(const detinfo::DetectorClocksData &clock_data, const std::vector< art::Ptr< recob::Hit >> &trkHits, const std::vector< art::Ptr< simb::MCParticle >> &mcparticles, 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 detinfo::DetectorPropertiesData &dprop, const geo::GeometryCore *geo)
TPC_iterator begin_TPC() const
Returns an iterator pointing to the first TPC in the detector.
process_name can override from command line with o or output calo
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
void FillTrack(const recob::Track &track, const recob::PFParticle &pfp, float t0, const std::vector< art::Ptr< recob::Hit >> &hits, const std::vector< const recob::TrackHitMeta * > &thms, const std::vector< art::Ptr< recob::SpacePoint >> &sps, const std::vector< art::Ptr< anab::Calorimetry >> &calo, const std::map< geo::WireID, art::Ptr< raw::RawDigit >> &rawdigits, const std::vector< GlobalTrackInfo > &tracks, const geo::GeometryCore *geo, const detinfo::DetectorClocksData &clock_data, const cheat::BackTrackerService *bt_serv, const sbn::EDet det)
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
std::string fSimChannelproducer
art::InputTag fPFPproducer
art::InputTag fTRKproducer
Description of geometry of one entire detector.
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
Hierarchical representation of particle flow.
int selected
Index of the tool that selected this track.
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)
art::InputTag fCALOproducer
art::InputTag fTRKHMproducer
std::vector< art::InputTag > fT0producers
bool fSilenceMissingDataProducts
std::vector< std::unique_ptr< sbn::ITCSSelectionTool > > fSelectionTools
Forward iterator browsing all geometry elements in the detector.
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
TPC_iterator end_TPC() const
Returns an iterator pointing after the last TPC in the detector.
std::string sub(const std::string &a, const std::string &b)