11 #include "larrecodnn/ImagePatternAlgs/ToolInterfaces/IPointIdAlg.h" 23 #include "cetlib/container_algorithms.h" 24 #include "cetlib_except/exception.h" 36 #include <unordered_map> 44 using key = std::tuple<unsigned int, unsigned int, unsigned int>;
53 Comment(
"number of samples processed in one batch")};
57 Comment(
"tag of deconvoluted ADC on wires (recob::Wire)")};
60 Name(
"HitModuleLabel"),
61 Comment(
"tag of hits to be EM/track / Michel tagged")};
64 Name(
"ClusterModuleLabel"),
65 Comment(
"tag of clusters to be used as a source of EM/track / Michel " 66 "tagged new clusters (incl. single-hit clusters ) using " 67 "accumulated results from hits")};
70 Name(
"TrackModuleLabel"),
71 Comment(
"tag of 3D tracks to be EM/track / Michel tagged using " 72 "accumulated results from hits in the best 2D projection")};
75 Comment(
"tag clusters in selected views only, " 76 "or in all views if empty list")};
97 std::vector<char>
const& hitInFA,
109 std::vector<char>
const& hitInFA,
113 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
114 auto clu2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
118 std::vector<art::Ptr<recob::Cluster>> cluPtrList;
122 for (
auto const& c : cluPtrList) {
123 unsigned int view = c->Plane().Plane;
126 unsigned int cryo = c->Plane().Cryostat;
127 unsigned int tpc = c->Plane().TPC;
129 cluMap[{cryo, tpc, view}].push_back(c.key());
135 unsigned int cidx = 0;
137 std::vector<bool> hitUsed(hitPtrList.size(),
140 for (
auto const & [
key, clusters_keys] : cluMap)
142 auto const& [cryo, tpc, view]=
key;
146 for (
size_t c : clusters_keys)
148 auto v = hitsFromClusters.at(c);
149 if (v.empty())
continue;
151 for (
auto const&
hit : v) {
152 if (hitUsed[
hit.key()]) {
153 mf::LogWarning(
"EmTrack") <<
"hit already used in another cluster";
155 hitUsed[
hit.key()] =
true;
158 auto vout =
fMVAWriter.template getOutput<recob::Hit>(
161 float pvalue = vout[0] / (vout[0] + vout[1]);
162 mf::LogVerbatim(
"EmTrack") <<
"cluster in tpc:" << tpc <<
" view:" << view
163 <<
" size:" << v.size() <<
" p:" << pvalue;
188 v.front()->WireID().planeID()));
198 for (
size_t h : hitMap.at({cryo, tpc, view}))
200 if (hitUsed[h])
continue;
202 auto vout =
fMVAWriter.template getOutput<recob::Hit>(h);
203 float pvalue = vout[0] / (vout[0] + vout[1]);
205 mf::LogVerbatim(
"EmTrack") <<
"single hit in tpc:" << tpc <<
" view:" << view
206 <<
" wire:" << hitPtrList[h]->WireID().Wire
207 <<
" drift:" << hitPtrList[h]->PeakTime() <<
" p:" << pvalue;
234 hitPtrList[h]->
WireID().planeID()));
240 mf::LogVerbatim(
"EmTrack") <<
"...produced " << cidx - clusters_keys.size()
241 <<
" single-hit clusters.";
244 evt.
put(std::move(clusters));
245 evt.
put(std::move(clu2hit));
254 std::vector<std::vector<art::Ptr<recob::Hit>>> trkHitPtrList(trkListHandle->size());
255 for (
size_t t = 0; t < trkListHandle->size(); ++t) {
256 auto v = hitsFromTracks.at(t);
257 size_t nh[3] = {0, 0, 0};
258 for (
auto const& hptr : v) {
261 size_t best_view = 2;
262 if ((nh[0] >= nh[1]) && (nh[0] > 2 * nh[2])) best_view = 0;
263 if ((nh[1] >= nh[0]) && (nh[1] > 2 * nh[2])) best_view = 1;
267 best_view = (best_view + 1) % 3;
269 throw cet::exception(
"EmTrack") <<
"No views selected at all?" << std::endl;
273 for (
auto const& hptr : v) {
274 if (hptr->View() == best_view) trkHitPtrList[t].emplace_back(hptr);
278 auto trkID =
fMVAWriter.template initOutputs<recob::Track>(
280 for (
size_t t = 0; t < trkHitPtrList.size(); ++t)
282 auto vout =
fMVAWriter.template getOutput<recob::Hit>(
293 for (
auto const& hptr : hitPtrList) {
294 auto const& h = *hptr;
295 unsigned int view = h.WireID().Plane;
298 unsigned int cryo = h.WireID().Cryostat;
299 unsigned int tpc = h.WireID().TPC;
301 hitMap[{cryo, tpc, view}].push_back(hptr.key());
311 auto hitID =
fMVAWriter.template initOutputs<recob::Hit>(
318 std::vector<char> hitInFA(hitPtrList.size(),
321 for (
auto const& [
key,
hits] : hitMap) {
322 auto const& [cryo, tpc, view] =
key;
325 fPointIdAlgTool->setWireDriftData(clockData, detProp, *wireHandle, view, tpc, cryo);
330 std::vector<std::pair<unsigned int, float>> points;
331 std::vector<size_t> keys;
333 if (idx + k >=
hits.size()) {
break; }
335 size_t h =
hits[idx + k];
342 if (points.size() != batch_out.size()) {
343 throw cet::exception(
"EmTrack") <<
"hits processing failed" << std::endl;
346 for (
size_t k = 0; k < points.size(); ++k) {
349 if (
fPointIdAlgTool->isInsideFiducialRegion(points[k].first, points[k].second)) {
361 std::string
const& module_label,
375 art::ServiceHandle<
art::TriggerNamesService const>()->getProcessName())
377 fMVAWriter.template produces_using<recob::Hit>();
380 collector.
produces<std::vector<recob::Cluster>>();
383 fMVAWriter.template produces_using<recob::Cluster>();
395 std::vector<art::Ptr<recob::Hit>> hitPtrList;
398 const std::vector<char> hitInFA =
classify_hits(evt, hitMap, hitPtrList);
410 if (
fViews.empty())
return true;
411 return cet::search_all(
fViews, view);
const art::InputTag fTrackModuleLabel
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const art::InputTag fWireProducerLabel
std::enable_if_t< std::is_class< T >::value, tool_return_type< T > > make_tool(fhicl::ParameterSet const &pset)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
void make_tracks(art::Event const &evt, std::vector< char > const &hitInFA)
make tracks
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
Declaration of signal hit object.
std::unique_ptr< PointIdAlgTools::IPointIdAlg > fPointIdAlgTool
Set of hits with a 2D structure.
WireID_t Wire
Index of the wire within its plane.
geo::WireID const & WireID() const
Initial tdc tick for hit.
const std::vector< int > fViews
std::vector< char > classify_hits(art::Event const &evt, EmTrack::cryo_tpc_view_keymap const &hitMap, std::vector< art::Ptr< recob::Hit >> const &hitPtrList)
fhicl::Atom< art::InputTag > TrackModuleLabel
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
fhicl::Atom< art::InputTag > HitModuleLabel
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
void produce(art::Event &e)
EmTrack(Config const &c, std::string const &s, art::ProducesCollector &pc)
std::map< key, std::vector< size_t >> cryo_tpc_view_keymap
Provides recob::Track data product.
fhicl::Atom< art::InputTag > ClusterModuleLabel
const art::InputTag fHitModuleLabel
void make_clusters(art::Event &evt, std::vector< art::Ptr< recob::Hit >> const &hitPtrList, std::vector< char > const &hitInFA, EmTrack::cryo_tpc_view_keymap const &hitMap)
Declaration of cluster object.
void saveOutputs(art::Event &evt)
Check consistency and save all the results in the event.
Detector simulation of raw signals on wires.
fhicl::Atom< size_t > BatchSize
bool isViewSelected(int view) const
void addOutput(FVector_ID id, std::array< float, N > const &values)
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
float PeakTime() const
Time of the signal peak, in tick units.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Utility object to perform functions of association.
fhicl::Sequence< int > Views
const art::InputTag fNewClustersTag
fhicl::Atom< art::InputTag > WireLabel
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventNumber_t event() const
cryo_tpc_view_keymap create_hitmap(std::vector< art::Ptr< recob::Hit >> const &hitPtrList) const
2D representation of charge deposited in the TDC/wire plane
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
const art::InputTag fClusterModuleLabel
cet::coded_exception< error, detail::translate > exception
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
std::tuple< unsigned int, unsigned int, unsigned int > key