39 #include "cetlib_except/exception.h" 50 #include <unordered_map> 59 typedef std::unordered_map<unsigned int, std::vector<size_t>>
view_keymap;
69 Comment(
"number of samples processed in one batch")};
73 Comment(
"tag of deconvoluted ADC on wires (recob::Wire)")};
76 Comment(
"tag of hits to be EM/track tagged")};
79 Name(
"ClusterModuleLabel"),
80 Comment(
"tag of clusters to be used as a source of EM/track tagged new clusters (incl. " 81 "single-hit clusters ) using accumulated results from hits")};
84 Name(
"TrackModuleLabel"),
85 Comment(
"tag of 3D tracks to be EM/track tagged using accumulated results from hits in the " 86 "best 2D projection")};
90 Comment(
"tag clusters in selected views only, or in all views if empty list")};
130 ,
fViews(config().Views())
140 produces<std::vector<recob::Cluster>>();
141 produces<art::Assns<recob::Cluster, recob::Hit>>();
163 <<
"next event: " << evt.
run() <<
" / " << evt.
id().
event();
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& pcryo : hitMap) {
198 for (
auto const& ptpc : pcryo.second) {
200 for (
auto const& pview : ptpc.second) {
207 for (
size_t idx = 0; idx < pview.second.size(); idx +=
fBatchSize) {
208 std::vector<std::pair<unsigned int, float>> points;
209 std::vector<size_t> keys;
211 if (idx + k >= pview.second.size()) {
break; }
213 size_t h = pview.second[idx + k];
220 if (points.size() != batch_out.size()) {
221 throw cet::exception(
"EmTrackClusterId") <<
"hits processing failed" << std::endl;
224 for (
size_t k = 0; k < points.size(); ++k) {
239 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
240 auto clu2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
244 std::vector<art::Ptr<recob::Cluster>> cluPtrList;
248 for (
auto const& c : cluPtrList) {
249 view = c->Plane().Plane;
252 cryo = c->Plane().Cryostat;
253 tpc = c->Plane().TPC;
255 cluMap[cryo][tpc][view].push_back(c.key());
261 unsigned int cidx = 0;
263 std::vector<bool> hitUsed(hitPtrList.size(),
false);
264 for (
auto const& pcryo : cluMap) {
266 for (
auto const& ptpc : pcryo.second) {
268 for (
auto const& pview : ptpc.second) {
272 for (
size_t c : pview.second)
274 auto v = hitsFromClusters.at(c);
275 if (v.empty())
continue;
277 for (
auto const&
hit : v) {
278 if (hitUsed[
hit.key()]) {
279 mf::LogWarning(
"EmTrackClusterId2out") <<
"hit already used in another cluster";
281 hitUsed[
hit.key()] =
true;
288 <<
"cluster in tpc:" << tpc <<
" view:" << view <<
" size:" << v.size()
322 for (
size_t h : hitMap[cryo][tpc][view])
324 if (hitUsed[h])
continue;
329 <<
"single hit in tpc:" << tpc <<
" view:" << view
330 <<
" wire:" << hitPtrList[h]->WireID().Wire
331 <<
" drift:" << hitPtrList[h]->PeakTime() <<
" p:" << vout[0];
358 hitPtrList[h]->
WireID().planeID()));
365 <<
"...produced " << cidx - pview.second.size() <<
" single-hit clusters.";
370 evt.
put(std::move(clusters));
371 evt.
put(std::move(clu2hit));
378 std::vector<std::vector<art::Ptr<recob::Hit>>> trkHitPtrList(trkListHandle->size());
379 for (
size_t t = 0; t < trkListHandle->size(); ++t) {
380 auto v = hitsFromTracks.at(t);
381 size_t nh[3] = {0, 0, 0};
382 for (
auto const& hptr : v) {
385 size_t best_view = 2;
386 if ((nh[0] >= nh[1]) && (nh[0] > 2 * nh[2])) best_view = 0;
387 if ((nh[1] >= nh[0]) && (nh[1] > 2 * nh[2])) best_view = 1;
391 best_view = (best_view + 1) % 3;
394 <<
"No views selected at all?" << std::endl;
398 for (
auto const& hptr : v) {
399 if (hptr->View() == best_view) trkHitPtrList[t].emplace_back(hptr);
405 for (
size_t t = 0; t < trkHitPtrList.size(); ++t)
409 return (
float)hitInFA[ptr.key()];
426 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
EmTrackClusterId2out(Parameters const &p)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
fhicl::Atom< art::InputTag > ClusterModuleLabel
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
fhicl::Atom< size_t > BatchSize
fhicl::Atom< art::InputTag > HitModuleLabel
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.
void produce(art::Event &e) override
anab::MVAWriter< 2 > fMVAWriter
fhicl::Atom< art::InputTag > TrackModuleLabel
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,""))
bool isViewSelected(int view) const
EmTrackClusterId2out & operator=(EmTrackClusterId2out const &)=delete
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
art::InputTag fTrackModuleLabel
art::InputTag fClusterModuleLabel
std::array< float, N > getOutput(std::vector< art::Ptr< T >> const &items) const
Provides recob::Track data product.
art::InputTag fWireProducerLabel
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.
art::InputTag fHitModuleLabel
ProducesCollector & producesCollector() noexcept
void addOutput(FVector_ID id, std::array< float, N > const &values)
std::vector< int > fViews
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.
std::unordered_map< unsigned int, tpc_view_keymap > cryo_tpc_view_keymap
float PeakTime() const
Time of the signal peak, in tick units.
fhicl::Sequence< int > Views
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
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.
std::unordered_map< unsigned int, std::vector< size_t > > view_keymap
art::InputTag fNewClustersTag
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventNumber_t event() const
Declaration of basic channel signal object.
2D representation of charge deposited in the TDC/wire plane
constexpr PlaneID const & planeID() const
fhicl::Atom< art::InputTag > WireLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::unordered_map< unsigned int, view_keymap > tpc_view_keymap
std::vector< std::vector< float > > predictIdVectors(std::vector< std::pair< unsigned int, float >> points) const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception