41 #include "cetlib_except/exception.h" 53 #include <unordered_map> 62 typedef std::unordered_map<unsigned int, std::vector<size_t>>
view_keymap;
72 Comment(
"number of samples processed in one batch")};
76 Comment(
"tag of deconvoluted ADC on wires (recob::Wire)")};
79 Name(
"HitModuleLabel"),
80 Comment(
"tag of hits to be EM/track / Michel tagged")};
83 Name(
"ClusterModuleLabel"),
84 Comment(
"tag of clusters to be used as a source of EM/track / Michel tagged new clusters " 85 "(incl. single-hit clusters ) using accumulated results from hits")};
88 Name(
"TrackModuleLabel"),
89 Comment(
"tag of 3D tracks to be EM/track / Michel tagged using accumulated results from " 90 "hits in the best 2D projection")};
94 Comment(
"tag clusters in selected views only, or in all views if empty list")};
134 ,
fViews(config().Views())
144 produces<std::vector<recob::Cluster>>();
145 produces<art::Assns<recob::Cluster, recob::Hit>>();
170 unsigned int cryo, tpc, view;
174 std::vector<art::Ptr<recob::Hit>> hitPtrList;
178 for (
auto const& h : hitPtrList) {
179 view = h->WireID().Plane;
182 cryo = h->WireID().Cryostat;
183 tpc = h->WireID().TPC;
185 hitMap[cryo][tpc][view].push_back(h.key());
196 std::vector<char> hitInFA(
199 for (
auto const& pcryo : hitMap) {
201 for (
auto const& ptpc : pcryo.second) {
203 for (
auto const& pview : ptpc.second) {
210 for (
size_t idx = 0; idx < pview.second.size(); idx +=
fBatchSize) {
211 std::vector<std::pair<unsigned int, float>> points;
212 std::vector<size_t> keys;
214 if (idx + k >= pview.second.size()) {
break; }
216 size_t h = pview.second[idx + k];
223 if (points.size() != batch_out.size()) {
224 throw cet::exception(
"EmTrackMichelId") <<
"hits processing failed" << std::endl;
227 for (
size_t k = 0; k < points.size(); ++k) {
242 auto clusters = std::make_unique<std::vector<recob::Cluster>>();
243 auto clu2hit = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
247 std::vector<art::Ptr<recob::Cluster>> cluPtrList;
251 for (
auto const& c : cluPtrList) {
252 view = c->Plane().Plane;
255 cryo = c->Plane().Cryostat;
256 tpc = c->Plane().TPC;
258 cluMap[cryo][tpc][view].push_back(c.key());
264 unsigned int cidx = 0;
266 std::vector<bool> hitUsed(hitPtrList.size(),
false);
267 for (
auto const& pcryo : cluMap) {
269 for (
auto const& ptpc : pcryo.second) {
271 for (
auto const& pview : ptpc.second) {
275 for (
size_t c : pview.second)
277 auto v = hitsFromClusters.at(c);
278 if (v.empty())
continue;
280 for (
auto const&
hit : v) {
281 if (hitUsed[
hit.key()]) {
282 mf::LogWarning(
"EmTrackMichelId") <<
"hit already used in another cluster";
284 hitUsed[
hit.key()] =
true;
290 float pvalue = vout[0] / (vout[0] + vout[1]);
291 mf::LogVerbatim(
"EmTrackMichelId") <<
"cluster in tpc:" << tpc <<
" view:" << view
292 <<
" size:" << v.size() <<
" p:" << pvalue;
325 for (
size_t h : hitMap[cryo][tpc][view])
327 if (hitUsed[h])
continue;
330 float pvalue = vout[0] / (vout[0] + vout[1]);
333 <<
"single hit in tpc:" << tpc <<
" view:" << view
334 <<
" wire:" << hitPtrList[h]->WireID().Wire
335 <<
" drift:" << hitPtrList[h]->PeakTime() <<
" p:" << pvalue;
362 hitPtrList[h]->
WireID().planeID()));
369 <<
"...produced " << cidx - pview.second.size() <<
" single-hit clusters.";
374 evt.
put(std::move(clusters));
375 evt.
put(std::move(clu2hit));
382 std::vector<std::vector<art::Ptr<recob::Hit>>> trkHitPtrList(trkListHandle->size());
383 for (
size_t t = 0; t < trkListHandle->size(); ++t) {
384 auto v = hitsFromTracks.at(t);
385 size_t nh[3] = {0, 0, 0};
386 for (
auto const& hptr : v) {
389 size_t best_view = 2;
390 if ((nh[0] >= nh[1]) && (nh[0] > 2 * nh[2])) best_view = 0;
391 if ((nh[1] >= nh[0]) && (nh[1] > 2 * nh[2])) best_view = 1;
395 best_view = (best_view + 1) % 3;
397 throw cet::exception(
"EmTrackMichelId") <<
"No views selected at all?" << std::endl;
401 for (
auto const& hptr : v) {
402 if (hptr->View() == best_view) trkHitPtrList[t].emplace_back(hptr);
408 for (
size_t t = 0; t < trkHitPtrList.size(); ++t)
412 return (
float)hitInFA[ptr.key()];
428 bool selected =
false;
bool isInsideFiducialRegion(unsigned int wire, float drift) const
fhicl::Atom< art::InputTag > TrackModuleLabel
art::InputTag fNewClustersTag
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::unordered_map< unsigned int, std::vector< size_t > > view_keymap
fhicl::Atom< art::InputTag > WireLabel
std::vector< std::string > const & outputLabels() const
network output labels
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
art::InputTag fHitModuleLabel
void setOutput(FVector_ID id, size_t key, std::array< float, N > const &values)
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
std::vector< int > fViews
EmTrackMichelId(Parameters const &p)
art::InputTag fClusterModuleLabel
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.
EmTrackMichelId & operator=(EmTrackMichelId const &)=delete
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
fhicl::Atom< size_t > BatchSize
bool isViewSelected(int view) const
FVector_ID initOutputs(std::string const &dataTag, size_t dataSize, std::vector< std::string > const &names=std::vector< std::string >(N,""))
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
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.
void produce(art::Event &e) override
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.
anab::MVAWriter< 4 > fMVAWriter
float PeakTime() const
Time of the signal peak, in tick units.
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, tpc_view_keymap > cryo_tpc_view_keymap
fhicl::Sequence< int > Views
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
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
std::unordered_map< unsigned int, view_keymap > tpc_view_keymap
art::InputTag fTrackModuleLabel
fhicl::Atom< art::InputTag > ClusterModuleLabel
std::vector< std::vector< float > > predictIdVectors(std::vector< std::pair< unsigned int, float >> points) const
art::InputTag fWireProducerLabel
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