Public Member Functions | Private Member Functions | Private Attributes | List of all members
hit::DisambigCheater Class Reference
Inheritance diagram for hit::DisambigCheater:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 DisambigCheater (fhicl::ParameterSet const &p)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void produce (art::Event &e) override
 
void endJob () override
 
void InitHitToWids (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &ChHits)
 
void MakeDisambigHit (art::Ptr< recob::Hit > const &hit, geo::WireID const &wid, art::Ptr< recob::Wire > const &wire, recob::HitCollectionCreator &hcol)
 

Private Attributes

art::ServiceHandle< geo::Geometry const > geom
 
art::ServiceHandle< cheat::BackTrackerService const > bt_serv
 
std::string fChanHitLabel
 
std::string fWidHitLabel
 
std::map< std::pair< double, double >, std::vector< geo::WireID > > fHitToWids
 
unsigned int fFalseChanHits
 
unsigned int fBadIDENearestWire = 0
 
std::vector< unsigned int > fMaxWireShift
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 31 of file DisambigCheater_module.cc.

Constructor & Destructor Documentation

hit::DisambigCheater::DisambigCheater ( fhicl::ParameterSet const &  p)
explicit

Definition at line 62 of file DisambigCheater_module.cc.

62  : EDProducer{p}
63  {
64  fChanHitLabel = p.get<std::string>("ChanHitLabel");
65 
66  // let HitCollectionCreator declare that we are going to produce
67  // hits and associations with wires and raw digits
68  // (with no particular product label)
70 
71  // Space charge can shift true IDE postiion to far-off channels.
72  // Calculate maximum number of wires to shift hit in order to be on correct channel.
73  // Shift no more than half of the number of channels, as beyond there will
74  // have been a closer wire segment.
75  if (geom->Ncryostats() != 1 || geom->NTPC() < 1) {
76  fMaxWireShift.resize(3);
77  fMaxWireShift[0] = 1;
78  fMaxWireShift[1] = 1;
79  fMaxWireShift[2] = 1;
80  }
81  else {
82  // assume TPC 0 is typical of all in terms of number of channels
83  unsigned int np = geom->Cryostat(0).TPC(0).Nplanes();
84  fMaxWireShift.resize(np);
85  for (unsigned int p = 0; p < np; ++p) {
86  double xyz[3] = {0.};
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) {
90 
91  // for vertical planes
92  if (geom->Cryostat(0).TPC(0).Plane(p).View() == geo::kZ) {
93  fMaxWireShift[2] = geom->Cryostat(0).TPC(0).Plane(p).Nwires();
94  break;
95  }
96 
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);
99 
100  if (xyz[2] == xyz_next[2]) {
101  fMaxWireShift[p] = w;
102  break;
103  }
104  } // end wire loop
105  } // end plane loop
106 
107  for (unsigned int i = 0; i < np; i++)
108  fMaxWireShift[i] = std::floor(fMaxWireShift[i] / 2);
109  }
110  }
WireGeo const & Wire(unsigned int iwire) const
Definition: PlaneGeo.cxx:506
std::string string
Definition: nybbler.cc:12
unsigned int Nplanes() const
Number of planes in this tpc.
Definition: TPCGeo.h:165
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::vector< unsigned int > fMaxWireShift
Planes which measure Z direction.
Definition: geo_types.h:132
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
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.
Definition: HitCreator.cxx:248
art::ServiceHandle< geo::Geometry const > geom
View_t View() const
Which coordinate does this plane measure.
Definition: PlaneGeo.h:184
p
Definition: test.py:223
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
ProducesCollector & producesCollector() noexcept
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:93
unsigned int Nwires() const
Number of wires in this plane.
Definition: PlaneGeo.h:269
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Definition: TPCGeo.cxx:263
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:73

Member Function Documentation

void hit::DisambigCheater::endJob ( )
overrideprivatevirtual

Reimplemented from art::EDProducer.

Definition at line 300 of file DisambigCheater_module.cc.

301  {
302 
303  if (fFalseChanHits > 0)
304  mf::LogWarning("DisambigCheater")
305  << fFalseChanHits << " hits had no associated IDE or WireIDs";
306  }
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void hit::DisambigCheater::InitHitToWids ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit >> &  ChHits 
)
private
Todo:
: Why would an IDE xyz position be outside of a TPC?
Todo:
: Why would an IDE ossociated with a hit return a nearest wire not on the hit's channel? Usually only one off.

Definition at line 191 of file DisambigCheater_module.cc.

193  {
194 
195  unsigned int Ucount(0), Vcount(0);
196  for (size_t h = 0; h < ChHits.size(); h++) {
197  recob::Hit const& chit = *(ChHits[h]);
198  if (ChHits[h]->View() == geo::kZ) continue;
199  if (ChHits[h]->View() == geo::kU)
200  Ucount++;
201  else if (ChHits[h]->View() == geo::kV)
202  Vcount++;
203  std::vector<geo::WireID> cwids = geom->ChannelToWire(chit.Channel());
204  std::pair<double, double> ChanTime((double)chit.Channel(),
205  (double)chit.PeakTime()); // hit key value
206 
207  // get hit IDEs
208  std::vector<const sim::IDE*> ides;
209  try {
210  ides = bt_serv->HitToSimIDEs_Ps(clockData, chit);
211  }
212  catch (...) {
213  };
214 
215  // catch the hits that have no IDEs
216  bool hasIDEs = !ides.empty();
217  if (hasIDEs) {
218  try {
219  bt_serv->SimIDEsToXYZ(ides);
220  } //What is this supposed to be doing? It get a vector, but never assigns it anywhere. There has to be a better way to do this check
221  catch (...) {
222  hasIDEs = false;
223  }
224  } // if
225  if (!hasIDEs) {
226  mf::LogVerbatim("DisambigCheat")
227  << "Hit on channel " << chit.Channel() << " between " << chit.PeakTimeMinusRMS()
228  << " and " << chit.PeakTimePlusRMS() << " matches no IDEs.";
229  fHitToWids[ChanTime] = std::vector<geo::WireID>();
230  continue;
231  } // if no IDEs
232 
233  // see what wire ID(s) the hit-IDEs are on
234  // if none: hit maps to empty vector
235  // if one: we have a unique hit, vector of size 1
236  // if more than one: make a vector of all wids
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};
240 
241  // Occasionally, ide position is not in TPC
242  /// \todo: Why would an IDE xyz position be outside of a TPC?
243  geo::TPCID tpcID = geom->FindTPCAtPosition(xyzIde);
244  if (!tpcID.isValid) {
245  mf::LogWarning("DisambigCheat")
246  << "IDE at x = " << xyzIde[0] << ", y = " << xyzIde[1] << ", z = " << xyzIde[2]
247  << " does not correspond to a TPC.";
248  continue;
249  }
250  unsigned int tpc = tpcID.TPC, cryo = tpcID.Cryostat;
251 
252  // NearestWire seems to be missing some correction that is applied in LArG4, and is
253  // sometimes off by one or two wires. Use it and then correct it given channel
254  /// \todo: Why would an IDE ossociated with a hit return a nearest wire not on the hit's channel? Usually only one off.
255  geo::WireID IdeWid;
256  try {
257  IdeWid = geom->NearestWireID(xyzIde, cwids[0].Plane, tpc, cryo);
258  }
259  catch (geo::InvalidWireError const& e) { // adopt suggestion if possible
260  if (!e.hasSuggestedWire()) throw;
261  IdeWid = e.suggestedWireID();
262  mf::LogError("DisambigCheat") << "Detected a point out of its wire plane:\n"
263  << e.what() << "\nUsing suggested wire " << IdeWid << "\n";
264  }
265  geo::WireID storethis = IdeWid; // default...
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)) <=
270  fMaxWireShift[cwids[0].Plane]) {
271  storethis = cwids[w]; // ...apply correction
272  foundmatch = true;
273  break;
274  }
275  }
276  if (!foundmatch) {
277  mf::LogWarning("DisambigCheat")
278  << "IDE NearestWire return more than 1 off from channel wids: wire " << IdeWid.Wire;
280  }
281 
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);
286  } // end loop through ides from HitToSimIdes
287 
288  fHitToWids[ChanTime] = widsWithIdes;
289 
290  } // end U/V channel hit loop
291 
292  if (fHitToWids.size() != Ucount + Vcount) {
293  mf::LogWarning("DisambigCheat")
294  << "Nhits mismatch: " << fHitToWids.size() << " " << Ucount + Vcount;
295  }
296  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
art::ServiceHandle< cheat::BackTrackerService const > bt_serv
AdcChannelData::View View
Planes which measure V.
Definition: geo_types.h:130
std::vector< unsigned int > fMaxWireShift
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
Planes which measure Z direction.
Definition: geo_types.h:132
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
art::ServiceHandle< geo::Geometry const > geom
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
T abs(T value)
Planes which measure U.
Definition: geo_types.h:129
const double e
std::map< std::pair< double, double >, std::vector< geo::WireID > > fHitToWids
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
float PeakTimeMinusRMS(float sigmas=+1.) const
Definition: Hit.h:239
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
Exception thrown on invalid wire number.
Definition: Exceptions.h:42
geo::WireID NearestWireID(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the ID of wire closest to position in the specified TPC.
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:236
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
geo::WireID suggestedWireID() const
Returns a better wire ID.
Definition: Exceptions.h:120
recob::tracking::Plane Plane
Definition: TrackState.h:17
bool hasSuggestedWire() const
Returns whether we known a better wire number.
Definition: Exceptions.h:114
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
void hit::DisambigCheater::MakeDisambigHit ( art::Ptr< recob::Hit > const &  hit,
geo::WireID const &  wid,
art::Ptr< recob::Wire > const &  wire,
recob::HitCollectionCreator hcol 
)
private

Definition at line 172 of file DisambigCheater_module.cc.

177  {
178 
179  if (!wid.isValid) {
180  mf::LogWarning("InvalidWireID") << "wid is invalid, hit not being made\n";
181  return;
182  }
183 
184  // create a hit copy of the original one, but with a different wire ID
185  recob::HitCreator hit(*original_hit, wid);
186  hcol.emplace_back(hit.move(), wire);
187  }
Class managing the creation of a new recob::Hit object.
Definition: HitCreator.h:83
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.
Definition: HitCreator.cxx:290
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void hit::DisambigCheater::produce ( art::Event e)
overrideprivatevirtual
Todo:
: Decide how to handle the hits with multiple-wid activity. For now, randomly choose.

Implements art::EDProducer.

Definition at line 114 of file DisambigCheater_module.cc.

115  {
116  // get hits on channels
118  evt.getByLabel(fChanHitLabel, ChanHits);
119  std::vector<art::Ptr<recob::Hit>> ChHits;
120  art::fill_ptr_vector(ChHits, ChanHits);
121 
122  // also get the associated wires and raw digits;
123  // we assume they have been created by the same module as the hits
124  const bool doRawDigitAssns = false;
125 
126  art::FindOneP<recob::Wire> ChannelHitWires(ChanHits, evt, fChanHitLabel);
127  const bool doWireAssns = ChannelHitWires.isValid();
128 
129  // this object contains the hit collection
130  // and its associations to wires and raw digits
131  // (if the original objects have them):
132  recob::HitCollectionCreator hits(evt, doWireAssns, doRawDigitAssns);
133 
134  // find the wireIDs each hit is on
135  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
136  this->InitHitToWids(clockData, ChHits);
137 
138  // make all of the hits
139  for (size_t h = 0; h < ChHits.size(); h++) {
140 
141  // get the objects associated with this hit
143  if (doWireAssns) wire = ChannelHitWires.at(h);
144 
145  // the trivial Z hits
146  if (ChHits[h]->View() == geo::kZ) {
147  this->MakeDisambigHit(ChHits[h], ChHits[h]->WireID(), wire, hits);
148  continue;
149  }
150 
151  // make U/V hits if any wire IDs are associated
152  // count hits without a wireID
153  /// \todo: Decide how to handle the hits with multiple-wid activity. For now, randomly choose.
154  std::pair<double, double> ChanTime(ChHits[h]->Channel() * 1., ChHits[h]->PeakTime() * 1.);
155  if (fHitToWids[ChanTime].size() == 1)
156  this->MakeDisambigHit(ChHits[h], fHitToWids[ChanTime][0], wire, hits);
157  else if (fHitToWids[ChanTime].size() == 0)
158  fFalseChanHits++;
159  else if (fHitToWids[ChanTime].size() > 1)
160  this->MakeDisambigHit(ChHits[h], fHitToWids[ChanTime][0], wire, hits); // same thing for now
161 
162  } // for
163 
164  // put the hit collection and associations into the event
165  hits.put_into(evt);
166 
167  fHitToWids.clear();
168  }
AdcChannelData::View View
void InitHitToWids(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &ChHits)
Planes which measure Z direction.
Definition: geo_types.h:132
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
A class handling a collection of hits and its associations.
Definition: HitCreator.h:508
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::map< std::pair< double, double >, std::vector< geo::WireID > > fHitToWids
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
void MakeDisambigHit(art::Ptr< recob::Hit > const &hit, geo::WireID const &wid, art::Ptr< recob::Wire > const &wire, recob::HitCollectionCreator &hcol)

Member Data Documentation

art::ServiceHandle<cheat::BackTrackerService const> hit::DisambigCheater::bt_serv
private

Definition at line 40 of file DisambigCheater_module.cc.

unsigned int hit::DisambigCheater::fBadIDENearestWire = 0
private

Definition at line 56 of file DisambigCheater_module.cc.

std::string hit::DisambigCheater::fChanHitLabel
private

Definition at line 42 of file DisambigCheater_module.cc.

unsigned int hit::DisambigCheater::fFalseChanHits
private
Initial value:
=
0

Definition at line 54 of file DisambigCheater_module.cc.

std::map<std::pair<double, double>, std::vector<geo::WireID> > hit::DisambigCheater::fHitToWids
private

Definition at line 45 of file DisambigCheater_module.cc.

std::vector<unsigned int> hit::DisambigCheater::fMaxWireShift
private

Definition at line 58 of file DisambigCheater_module.cc.

std::string hit::DisambigCheater::fWidHitLabel
private

Definition at line 43 of file DisambigCheater_module.cc.

art::ServiceHandle<geo::Geometry const> hit::DisambigCheater::geom
private

Definition at line 39 of file DisambigCheater_module.cc.


The documentation for this class was generated from the following file: