10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "canvas/Persistency/Common/FindOneP.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
36 void produce(art::Event&
e)
override;
39 art::ServiceHandle<geo::Geometry const>
geom;
40 art::ServiceHandle<cheat::BackTrackerService const>
bt_serv;
45 std::map<std::pair<double, double>, std::vector<geo::WireID>>
fHitToWids;
51 art::Ptr<recob::Wire>
const& wire,
64 fChanHitLabel =
p.get<std::string>(
"ChanHitLabel");
75 if (geom->Ncryostats() != 1 || geom->NTPC() < 1) {
76 fMaxWireShift.resize(3);
83 unsigned int np = geom->Cryostat(0).TPC(0).Nplanes();
84 fMaxWireShift.resize(np);
85 for (
unsigned int p = 0;
p < np; ++
p) {
87 double xyz_next[3] = {0.};
88 unsigned int nw = geom->Cryostat(0).TPC(0).Plane(
p).Nwires();
89 for (
unsigned int w = 0;
w < nw; ++
w) {
92 if (geom->Cryostat(0).TPC(0).Plane(
p).View() ==
geo::kZ) {
93 fMaxWireShift[2] = geom->Cryostat(0).TPC(0).Plane(
p).Nwires();
97 geom->Cryostat(0).TPC(0).Plane(
p).Wire(
w).GetCenter(xyz);
98 geom->Cryostat(0).TPC(0).Plane(
p).Wire(
w + 1).GetCenter(xyz_next);
100 if (xyz[2] == xyz_next[2]) {
101 fMaxWireShift[
p] =
w;
107 for (
unsigned int i = 0; i < np; i++)
108 fMaxWireShift[i] = std::floor(fMaxWireShift[i] / 2);
117 art::Handle<std::vector<recob::Hit>> ChanHits;
119 std::vector<art::Ptr<recob::Hit>> ChHits;
120 art::fill_ptr_vector(ChHits, ChanHits);
124 const bool doRawDigitAssns =
false;
126 art::FindOneP<recob::Wire> ChannelHitWires(ChanHits, evt,
fChanHitLabel);
127 const bool doWireAssns = ChannelHitWires.isValid();
135 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
139 for (
size_t h = 0;
h < ChHits.size();
h++) {
142 art::Ptr<recob::Wire> wire;
143 if (doWireAssns) wire = ChannelHitWires.at(
h);
154 std::pair<double, double> ChanTime(ChHits[
h]->Channel() * 1., ChHits[
h]->PeakTime() * 1.);
173 art::Ptr<recob::Hit>
const& original_hit,
175 art::Ptr<recob::Wire>
const& wire,
180 mf::LogWarning(
"InvalidWireID") <<
"wid is invalid, hit not being made\n";
195 unsigned int Ucount(0), Vcount(0);
196 for (
size_t h = 0;
h < ChHits.size();
h++) {
198 if (ChHits[
h]->View() ==
geo::kZ)
continue;
201 else if (ChHits[
h]->View() ==
geo::kV)
203 std::vector<geo::WireID> cwids =
geom->ChannelToWire(chit.
Channel());
204 std::pair<double, double> ChanTime((
double)chit.
Channel(),
208 std::vector<const sim::IDE*> ides;
210 ides =
bt_serv->HitToSimIDEs_Ps(clockData, chit);
216 bool hasIDEs = !ides.empty();
226 mf::LogVerbatim(
"DisambigCheat")
229 fHitToWids[ChanTime] = std::vector<geo::WireID>();
237 std::vector<geo::WireID> widsWithIdes;
238 for (
size_t i = 0; i < ides.size(); i++) {
239 const double xyzIde[] = {ides[i]->x, ides[i]->y, ides[i]->z};
245 mf::LogWarning(
"DisambigCheat")
246 <<
"IDE at x = " << xyzIde[0] <<
", y = " << xyzIde[1] <<
", z = " << xyzIde[2]
247 <<
" does not correspond to a TPC.";
250 unsigned int tpc = tpcID.
TPC, cryo = tpcID.
Cryostat;
257 IdeWid =
geom->NearestWireID(xyzIde, cwids[0].
Plane, tpc, cryo);
262 mf::LogError(
"DisambigCheat") <<
"Detected a point out of its wire plane:\n"
263 << e.what() <<
"\nUsing suggested wire " << IdeWid <<
"\n";
266 bool foundmatch(
false);
267 for (
size_t w = 0;
w < cwids.size();
w++) {
268 if (cwids[
w].
TPC != tpc || cwids[
w].Cryostat != cryo)
continue;
269 if ((
unsigned int)
std::abs((
int)(IdeWid.
Wire) - (
int)(cwids[
w].Wire)) <=
271 storethis = cwids[
w];
277 mf::LogWarning(
"DisambigCheat")
278 <<
"IDE NearestWire return more than 1 off from channel wids: wire " << IdeWid.
Wire;
282 bool alreadyStored(
false);
283 for (
size_t wid = 0; wid < widsWithIdes.size(); wid++)
284 if (storethis == widsWithIdes[wid]) alreadyStored =
true;
285 if (!alreadyStored) widsWithIdes.push_back(storethis);
293 mf::LogWarning(
"DisambigCheat")
294 <<
"Nhits mismatch: " <<
fHitToWids.size() <<
" " << Ucount + Vcount;
304 mf::LogWarning(
"DisambigCheater")
BEGIN_PROLOG true icarus_rawdigitfilter FilterTools FilterPlane1 Plane
void produce(art::Event &e) override
DisambigCheater(fhicl::ParameterSet const &p)
art::ServiceHandle< cheat::BackTrackerService const > bt_serv
void InitHitToWids(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &ChHits)
Declaration of signal hit object.
std::vector< unsigned int > fMaxWireShift
bool isValid
Whether this ID points to a valid element.
CryostatID_t Cryostat
Index of cryostat.
std::size_t size(FixedBins< T, C > const &) noexcept
Planes which measure Z direction.
WireID_t Wire
Index of the wire within its plane.
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
art::ServiceHandle< geo::Geometry const > geom
unsigned int fBadIDENearestWire
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Class managing the creation of a new recob::Hit object.
Helper functions to create a hit.
Collection of exceptions for Geometry system.
A class handling a collection of hits and its associations.
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::map< std::pair< double, double >, std::vector< geo::WireID > > fHitToWids
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
The data type to uniquely identify a TPC.
Definition of data types for geometry description.
unsigned int fFalseChanHits
float PeakTimeMinusRMS(float sigmas=+1.) const
void put_into(art::Event &)
Moves the data into an event.
float PeakTime() const
Time of the signal peak, in tick units.
Encapsulate the construction of a single detector plane.
Contains all timing reference information for the detector.
std::string fChanHitLabel
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Exception thrown on invalid wire number.
Declaration of basic channel signal object.
2D representation of charge deposited in the TDC/wire plane
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
TPCID_t TPC
Index of the TPC within its cryostat.
void MakeDisambigHit(art::Ptr< recob::Hit > const &hit, geo::WireID const &wid, art::Ptr< recob::Wire > const &wire, recob::HitCollectionCreator &hcol)
geo::WireID suggestedWireID() const
Returns a better wire ID.
bool hasSuggestedWire() const
Returns whether we known a better wire number.
recob::Hit && move()
Prepares the constructed hit to be moved away.
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
art framework interface to geometry description
Encapsulate the construction of a single detector plane.