39 #include "cetlib_except/exception.h" 51 #include <unordered_map> 60 typedef std::unordered_map<unsigned int, std::vector<size_t>>
view_keymap;
70 Comment(
"number of samples processed in one batch")};
74 Comment(
"tag of deconvoluted ADC on wires (recob::Wire)")};
77 Comment(
"tag of hits to be EM/track tagged")};
80 Name(
"ClusterModuleLabel"),
81 Comment(
"tag of clusters to be used as a source of EM/track tagged new clusters (incl. " 82 "single-hit clusters ) using accumulated results from hits")};
85 Name(
"TrackModuleLabel"),
86 Comment(
"tag of 3D tracks to be EM/track tagged using accumulated results from hits in the " 87 "best 2D projection")};
91 Comment(
"tag clusters in selected views only, or in all views if empty list")};
131 ,
fViews(config().Views())
141 produces<std::vector<recob::Cluster>>();
142 produces<art::Assns<recob::Cluster, recob::Hit>>();
167 unsigned int cryo, tpc, view;
171 std::vector<art::Ptr<recob::Hit>> hitPtrList;
175 for (
auto const& h : hitPtrList) {
176 view = h->WireID().Plane;
179 cryo = h->WireID().Cryostat;
180 tpc = h->WireID().TPC;
182 hitMap[cryo][tpc][view].push_back(h.key());
193 std::vector<char> hitInFA(
196 for (
auto const& [cryo, tpcs] : hitMap) {
197 for (
auto const& [tpc, views] : tpcs) {
198 for (
auto const& pview : views) {
205 for (
size_t idx = 0; idx < pview.second.size(); idx +=
fBatchSize) {
206 std::vector<std::pair<unsigned int, float>> points;
207 std::vector<size_t> keys;
209 if (idx + k >= pview.second.size()) {
break; }
211 size_t h = pview.second[idx + k];
218 if (points.size() != batch_out.size()) {
219 throw cet::exception(
"EmTrackClusterId") <<
"hits processing failed" << std::endl;
222 for (
size_t k = 0; k < points.size(); ++k) {
237 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
238 auto clu2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
242 std::vector<art::Ptr<recob::Cluster>> cluPtrList;
246 for (
auto const& c : cluPtrList) {
247 view = c->Plane().Plane;
250 cryo = c->Plane().Cryostat;
251 tpc = c->Plane().TPC;
253 cluMap[cryo][tpc][view].push_back(c.key());
259 unsigned int cidx = 0;
261 std::vector<bool> hitUsed(hitPtrList.size(),
false);
262 for (
auto const& pcryo : cluMap) {
264 for (
auto const& ptpc : pcryo.second) {
266 for (
auto const& pview : ptpc.second) {
270 for (
size_t c : pview.second)
272 auto v = hitsFromClusters.at(c);
273 if (v.empty())
continue;
275 for (
auto const&
hit : v) {
276 if (hitUsed[
hit.key()]) {
277 mf::LogWarning(
"EmTrackClusterId") <<
"hit already used in another cluster";
279 hitUsed[
hit.key()] =
true;
285 float pvalue = vout[0] / (vout[0] + vout[1]);
286 mf::LogVerbatim(
"EmTrackClusterId") <<
"cluster in tpc:" << tpc <<
" view:" << view
287 <<
" size:" << v.size() <<
" p:" << pvalue;
320 for (
size_t h : hitMap[cryo][tpc][view])
322 if (hitUsed[h])
continue;
325 float pvalue = vout[0] / (vout[0] + vout[1]);
328 <<
"single hit in tpc:" << tpc <<
" view:" << view
329 <<
" wire:" << hitPtrList[h]->WireID().Wire
330 <<
" drift:" << hitPtrList[h]->PeakTime() <<
" p:" << pvalue;
357 hitPtrList[h]->
WireID().planeID()));
364 <<
"...produced " << cidx - pview.second.size() <<
" single-hit clusters.";
369 evt.
put(std::move(clusters));
370 evt.
put(std::move(clu2hit));
377 std::vector<std::vector<art::Ptr<recob::Hit>>> trkHitPtrList(trkListHandle->size());
378 for (
size_t t = 0; t < trkListHandle->size(); ++t) {
379 auto v = hitsFromTracks.at(t);
380 size_t nh[3] = {0, 0, 0};
381 for (
auto const& hptr : v) {
384 size_t best_view = 2;
385 if ((nh[0] >= nh[1]) && (nh[0] > 2 * nh[2])) best_view = 0;
386 if ((nh[1] >= nh[0]) && (nh[1] > 2 * nh[2])) best_view = 1;
390 best_view = (best_view + 1) % 3;
392 throw cet::exception(
"EmTrackClusterId") <<
"No views selected at all?" << std::endl;
396 for (
auto const& hptr : v) {
397 if (hptr->View() == best_view) trkHitPtrList[t].emplace_back(hptr);
403 for (
size_t t = 0; t < trkHitPtrList.size(); ++t)
407 return (
float)hitInFA[ptr.key()];
424 if (k == view) {
return true; }
bool isInsideFiducialRegion(unsigned int wire, float drift) const
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< std::string > const & outputLabels() const
network output labels
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
art::InputTag fWireProducerLabel
fhicl::Atom< art::InputTag > WireLabel
void produce(art::Event &e) override
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.
fhicl::Atom< art::InputTag > TrackModuleLabel
art::InputTag fNewClustersTag
anab::MVAWriter< 3 > fMVAWriter
bool isViewSelected(int view) const
fhicl::Atom< size_t > BatchSize
std::vector< int > fViews
std::unordered_map< unsigned int, view_keymap > tpc_view_keymap
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
FVector_ID initOutputs(std::string const &dataTag, size_t dataSize, std::vector< std::string > const &names=std::vector< std::string >(N,""))
fhicl::Sequence< int > Views
fhicl::Atom< art::InputTag > ClusterModuleLabel
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
art::InputTag fHitModuleLabel
void push_back(Ptr< U > const &p)
std::array< float, N > getOutput(std::vector< art::Ptr< T >> const &items) const
fhicl::Atom< art::InputTag > HitModuleLabel
Provides recob::Track data product.
Declaration of cluster object.
Definition of data types for geometry description.
void saveOutputs(art::Event &evt)
Check consistency and save all the results in the event.
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
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
std::unordered_map< unsigned int, std::vector< size_t > > view_keymap
bool setWireDriftData(const detinfo::DetectorClocksData &clock_data, const detinfo::DetectorPropertiesData &det_prop, const std::vector< recob::Wire > &wires, unsigned int plane, unsigned int tpc, unsigned int cryo)
Utility object to perform functions of association.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventNumber_t event() const
Declaration of basic channel signal object.
art::InputTag fClusterModuleLabel
2D representation of charge deposited in the TDC/wire plane
constexpr PlaneID const & planeID() const
art::InputTag fTrackModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::vector< std::vector< float > > predictIdVectors(std::vector< std::pair< unsigned int, float >> points) const
EmTrackClusterId & operator=(EmTrackClusterId const &)=delete
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
EmTrackClusterId(Parameters const &p)
std::unordered_map< unsigned int, tpc_view_keymap > cryo_tpc_view_keymap
cet::coded_exception< error, detail::translate > exception