26 #include <unordered_map> 33 using key = std::tuple<unsigned int, unsigned int, unsigned int>;
44 Comment(
"number of samples processed in one batch")};
48 Comment(
"tag of deconvoluted ADC on wires (recob::Wire)")};
51 Name(
"HitModuleLabel"),
52 Comment(
"tag of hits to be EM/track / Michel tagged")};
55 Name(
"ClusterModuleLabel"),
56 Comment(
"tag of clusters to be used as a source of EM/track / Michel " 57 "tagged new clusters (incl. single-hit clusters ) using " 58 "accumulated results from hits")};
61 Name(
"TrackModuleLabel"),
62 Comment(
"tag of 3D tracks to be EM/track / Michel tagged using " 63 "accumulated results from hits in the best 2D projection")};
66 Comment(
"tag clusters in selected views only, " 67 "or in all views if empty list")};
91 std::vector<char>
const& hitInFA,
106 std::vector<char>
const& hitInFA,
110 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
111 auto clu2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
116 std::vector<art::Ptr<recob::Cluster>> cluPtrList;
120 for (
auto const&
c : cluPtrList) {
121 unsigned int view =
c->Plane().Plane;
125 unsigned int cryo =
c->Plane().Cryostat;
126 unsigned int tpc =
c->Plane().TPC;
128 cluMap[{cryo, tpc, view}].push_back(
c.key());
131 auto cluID =
fMVAWriter.template initOutputs<recob::Cluster>(
134 unsigned int cidx = 0;
135 art::FindManyP<recob::Hit> hitsFromClusters(
137 std::vector<bool> hitUsed(hitPtrList.size(),
140 for (
auto const & [
key, clusters_keys] : cluMap)
142 auto const& [cryo, tpc, view]=
key;
147 for (
size_t c : clusters_keys)
149 auto v = hitsFromClusters.at(
c);
153 for (
auto const&
hit : v) {
154 if (hitUsed[
hit.key()]) {
155 mf::LogWarning(
"EmTrack") <<
"hit already used in another cluster";
157 hitUsed[
hit.key()] =
true;
160 auto vout =
fMVAWriter.template getOutput<recob::Hit>(
162 return (
float)hitInFA[ptr.key()];
165 float pvalue = vout[0] / (vout[0] + vout[1]);
167 <<
"cluster in tpc:" << tpc <<
" view:" << view
168 <<
" size:" << v.size() <<
" p:" << pvalue;
193 v.front()->WireID().planeID()));
204 hitMap.at({cryo, tpc, view}))
209 auto vout =
fMVAWriter.template getOutput<recob::Hit>(
h);
210 float pvalue = vout[0] / (vout[0] + vout[1]);
213 <<
"single hit in tpc:" << tpc <<
" view:" << view
214 <<
" wire:" << hitPtrList[
h]->WireID().Wire
215 <<
" drift:" << hitPtrList[
h]->PeakTime() <<
" p:" << pvalue;
219 clusters->emplace_back(
243 hitPtrList[h]->
WireID().planeID()));
251 <<
"...produced " << cidx - clusters_keys.size()
252 <<
" single-hit clusters.";
263 std::vector<char>
const& hitInFA)
267 art::FindManyP<recob::Hit> hitsFromTracks(
269 std::vector<std::vector<art::Ptr<recob::Hit>>> trkHitPtrList(
270 trkListHandle->size());
271 for (
size_t t = 0;
t < trkListHandle->size(); ++
t) {
272 auto v = hitsFromTracks.at(
t);
273 size_t nh[3] = {0, 0, 0};
274 for (
auto const& hptr : v) {
277 size_t best_view = 2;
278 if ((nh[0] >= nh[1]) && (nh[0] > 2 * nh[2]))
280 if ((nh[1] >= nh[0]) && (nh[1] > 2 * nh[2]))
285 best_view = (best_view + 1) % 3;
288 <<
"No views selected at all?" <<
std::endl;
292 for (
auto const& hptr : v) {
293 if (hptr->View() == best_view)
294 trkHitPtrList[
t].emplace_back(hptr);
298 auto trkID =
fMVAWriter.template initOutputs<recob::Track>(
300 for (
size_t t = 0;
t < trkHitPtrList.size();
303 auto vout =
fMVAWriter.template getOutput<recob::Hit>(
305 return (
float)hitInFA[ptr.key()];
316 for (
auto const& hptr : hitPtrList) {
317 auto const&
h = *hptr;
318 unsigned int view =
h.WireID().Plane;
322 unsigned int cryo =
h.WireID().Cryostat;
323 unsigned int tpc =
h.WireID().TPC;
325 hitMap[{cryo, tpc, view}].push_back(hptr.key());
336 auto hitID =
fMVAWriter.template initOutputs<recob::Hit>(
339 auto const clockData =
346 std::vector<char> hitInFA(hitPtrList.size(),
349 for (
auto const& [
key, hits] : hitMap) {
350 auto const& [cryo, tpc, view] =
key;
355 clockData, detProp, *wireHandle, view, tpc, cryo);
359 for (
size_t idx = 0; idx < hits.size(); idx +=
fBatchSize) {
360 std::vector<std::pair<unsigned int, float>> points;
361 std::vector<size_t>
keys;
363 if (idx +
k >= hits.size()) {
367 size_t h = hits[idx +
k];
374 if (points.size() != batch_out.size()) {
376 <<
"hits processing failed" <<
std::endl;
379 for (
size_t k = 0;
k < points.size(); ++
k) {
411 art::ServiceHandle<
art::TriggerNamesService
const>()->getProcessName())
413 fMVAWriter.template produces_using<recob::Hit>();
416 collector.
produces<std::vector<recob::Cluster>>();
419 fMVAWriter.template produces_using<recob::Cluster>();
423 fMVAWriter.template produces_using<recob::Track>();
433 <<
"next event: " << evt.
run() <<
" / " << evt.
id().
event();
436 std::vector<art::Ptr<recob::Hit>> hitPtrList;
439 const std::vector<char> hitInFA =
classify_hits(evt, hitMap, hitPtrList);
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
geo::WireID WireID() const
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
ChannelGroupService::Name Name
std::unique_ptr< PointIdAlgTools::IPointIdAlg > fPointIdAlgTool
Set of hits with a 2D structure.
WireID_t Wire
Index of the wire within its plane.
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
art framework interface to geometry description
fhicl::Atom< art::InputTag > HitModuleLabel
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
bool search_all(FwdCont const &, Datum const &)
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)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::map< key, std::vector< size_t >> cryo_tpc_view_keymap
fhicl::Atom< art::InputTag > ClusterModuleLabel
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
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)
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)
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
fhicl::Sequence< int > Views
const art::InputTag fNewClustersTag
fhicl::Atom< art::InputTag > WireLabel
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Provides recob::Track data product.
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.
QTextStream & endl(QTextStream &s)
std::tuple< unsigned int, unsigned int, unsigned int > key