LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_cluster3d::SpacePointHit3DBuilder Class Reference

SpacePointHit3DBuilder class definiton. More...

Inheritance diagram for lar_cluster3d::SpacePointHit3DBuilder:
lar_cluster3d::IHit3DBuilder

Public Types

enum  TimeValues { COLLECTARTHITS = 0, BUILDTHREEDHITS = 1, NUMTIMEVALUES }
 enumerate the possible values for time checking if monitoring timing More...
 
using RecobHitToPtrMap = std::map< const recob::Hit *, art::Ptr< recob::Hit >>
 Defines a structure mapping art representation to internal. More...
 

Public Member Functions

 SpacePointHit3DBuilder (fhicl::ParameterSet const &pset)
 Constructor. More...
 
 ~SpacePointHit3DBuilder ()
 Destructor. More...
 
void configure (const fhicl::ParameterSet &) override
 Interface for configuring the particular algorithm tool. More...
 
void Hit3DBuilder (const art::Event &evt, reco::HitPairList &hitPairList, RecobHitToPtrMap &) const override
 Given a set of recob hits, run DBscan to form 3D clusters. More...
 
float getTimeToExecute (IHit3DBuilder::TimeValues index) const override
 If monitoring, recover the time to execute a particular function. More...
 

Private Types

using Hit2DVector = std::vector< reco::ClusterHit2D >
 

Private Attributes

art::InputTag m_spacePointTag
 Data members to follow. More...
 
bool m_enableMonitoring
 
std::vector< float > m_timeVector
 
Hit2DVector m_clusterHit2DMasterVec
 
geo::Geometrym_geometry
 
const detinfo::DetectorPropertiesm_detector
 

Detailed Description

SpacePointHit3DBuilder class definiton.

Definition at line 39 of file SpacePointHit3DBuilder_tool.cc.

Member Typedef Documentation

Defines a structure mapping art representation to internal.

Definition at line 44 of file IHit3DBuilder.h.

Member Enumeration Documentation

enumerate the possible values for time checking if monitoring timing

Enumerator
COLLECTARTHITS 
BUILDTHREEDHITS 
NUMTIMEVALUES 

Definition at line 57 of file IHit3DBuilder.h.

Constructor & Destructor Documentation

lar_cluster3d::SpacePointHit3DBuilder::SpacePointHit3DBuilder ( fhicl::ParameterSet const &  pset)
explicit

Constructor.

Parameters
pset

Definition at line 88 of file SpacePointHit3DBuilder_tool.cc.

References configure().

89 {
90  this->configure(pset);
91 }
void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
lar_cluster3d::SpacePointHit3DBuilder::~SpacePointHit3DBuilder ( )

Destructor.

Definition at line 95 of file SpacePointHit3DBuilder_tool.cc.

96 {
97 }

Member Function Documentation

void lar_cluster3d::SpacePointHit3DBuilder::configure ( const fhicl::ParameterSet )
overridevirtual

Interface for configuring the particular algorithm tool.

Parameters
ParameterSetThe input set of parameters for configuration

Implements lar_cluster3d::IHit3DBuilder.

Definition at line 101 of file SpacePointHit3DBuilder_tool.cc.

References fhicl::ParameterSet::get(), m_detector, m_enableMonitoring, m_geometry, and m_spacePointTag.

Referenced by SpacePointHit3DBuilder().

102 {
103  m_spacePointTag = pset.get<art::InputTag>("SpacePointTag");
104  m_enableMonitoring = pset.get<bool> ("EnableMonitoring", true);
105 
107 
108  m_geometry = &*geometry;
109  m_detector = lar::providerFrom<detinfo::DetectorPropertiesService>();
110 }
const detinfo::DetectorProperties * m_detector
art::InputTag m_spacePointTag
Data members to follow.
float lar_cluster3d::SpacePointHit3DBuilder::getTimeToExecute ( IHit3DBuilder::TimeValues  index) const
inlineoverridevirtual

If monitoring, recover the time to execute a particular function.

Implements lar_cluster3d::IHit3DBuilder.

Definition at line 67 of file SpacePointHit3DBuilder_tool.cc.

References m_timeVector.

67 {return m_timeVector.at(index);}
void lar_cluster3d::SpacePointHit3DBuilder::Hit3DBuilder ( const art::Event evt,
reco::HitPairList hitPairList,
RecobHitToPtrMap recobHitToArtPtrMap 
) const
overridevirtual

Given a set of recob hits, run DBscan to form 3D clusters.

Parameters
hitPairListThe input list of 3D hits to run clustering on
clusterParametersListA list of cluster objects (parameters from associated hits)

Recover the 2D hits from art and fill out the local data structures for the 3D clustering

Implements lar_cluster3d::IHit3DBuilder.

Definition at line 113 of file SpacePointHit3DBuilder_tool.cc.

References lar_cluster3d::IHit3DBuilder::BUILDTHREEDHITS, detinfo::DetectorProperties::ConvertTicksToX(), DEFINE_ART_CLASS_TOOL, art::Ptr< T >::get(), art::DataViewImpl::getByLabel(), reco::ClusterHit2D::getHit(), detinfo::DetectorProperties::GetXTicksOffset(), art::Handle< T >::isValid(), geo::kU, geo::kV, geo::kW, m_clusterHit2DMasterVec, m_detector, m_enableMonitoring, m_geometry, m_spacePointTag, m_timeVector, geo::GeometryCore::Ncryostats(), geo::GeometryCore::NTPC(), lar_cluster3d::IHit3DBuilder::NUMTIMEVALUES, geo::PlaneID::Plane, reco::ClusterHit2D::SHAREDINTRIPLET, detinfo::DetectorProperties::TriggerOffset(), reco::ClusterHit2D::USEDINTRIPLET, weight, recob::Hit::WireID(), and recob::SpacePoint::XYZ().

114 {
115  m_timeVector.resize(NUMTIMEVALUES, 0.);
116 
117  cet::cpu_timer theClockMakeHits;
118 
119  if (m_enableMonitoring) theClockMakeHits.start();
120 
125  // Start by recovering the associations between space points and hits
127  evt.getByLabel(m_spacePointTag, hitSpacePointAssnsHandle);
128 
129  if (!hitSpacePointAssnsHandle.isValid()) return;
130 
131  // First step is to loop through and get a mapping between space points and associated hits
132  // and, importantly, a list of unique hits (and mapping between art ptr and hit)
133  using SpacePointHitVecMap = std::map<const recob::SpacePoint*, std::vector<const recob::Hit*>>;
134  using RecobHitSet = std::set<const recob::Hit*>;
135 
136  SpacePointHitVecMap spacePointHitVecMap;
137  RecobHitSet recobHitSet;
138 
139  for(auto& assnPair : *hitSpacePointAssnsHandle)
140  {
141  const art::Ptr<recob::SpacePoint> spacePoint = assnPair.second;
142  const art::Ptr<recob::Hit>& recobHit = assnPair.first;
143 
144  spacePointHitVecMap[spacePoint.get()].push_back(recobHit.get());
145  recobHitSet.insert(recobHit.get());
146  recobHitToArtPtrMap[recobHit.get()] = recobHit;
147  }
148 
149  // We'll want to correct the hit times for the plane offsets
150  // (note this is already taken care of when converting to position)
151  std::map<geo::PlaneID, double> planeOffsetMap;
152 
153  // Initialize the plane to hit vector map
154  for(size_t cryoIdx = 0; cryoIdx < m_geometry->Ncryostats(); cryoIdx++)
155  {
156  for(size_t tpcIdx = 0; tpcIdx < m_geometry->NTPC(); tpcIdx++)
157  {
158  // What we want here are the relative offsets between the planes
159  // Note that plane 0 is assumed the "first" plane and is the reference
160  planeOffsetMap[geo::PlaneID(cryoIdx,tpcIdx,0)] = 0.;
161  planeOffsetMap[geo::PlaneID(cryoIdx,tpcIdx,1)] = m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,1))
162  - m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,0));
163  planeOffsetMap[geo::PlaneID(cryoIdx,tpcIdx,2)] = m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,2))
164  - m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,0));
165 
166  std::cout << "***> plane 0 offset: " << planeOffsetMap[geo::PlaneID(cryoIdx,tpcIdx,0)] << ", plane 1: " << planeOffsetMap[geo::PlaneID(cryoIdx,tpcIdx,1)] << ", plane 2: " << planeOffsetMap[geo::PlaneID(cryoIdx,tpcIdx,2)] << std::endl;
167  std::cout << " Det prop plane 0: " << m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,0)) << ", plane 1: " << m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,1)) << ", plane 2: " << m_detector->GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,2)) << ", Trig: " << m_detector->TriggerOffset() << std::endl;
168  }
169  }
170 
171  // We need temporary mapping from recob::Hit's to our 2D hits
172  using RecobHitTo2DHitMap = std::map<const recob::Hit*,const reco::ClusterHit2D*>;
173 
174  RecobHitTo2DHitMap recobHitTo2DHitMap;
175 
176  // Set the size of the container for our hits
177  m_clusterHit2DMasterVec.clear();
178  m_clusterHit2DMasterVec.reserve(recobHitSet.size());
179 
180  // Now go throught the list of unique hits and create the 2D hits we'll use
181  for(auto& recobHit : recobHitSet)
182  {
183  const geo::WireID& hitWireID(recobHit->WireID());
184 
185  double hitPeakTime(recobHit->PeakTime() - planeOffsetMap[hitWireID.planeID()]);
186  double xPosition(m_detector->ConvertTicksToX(recobHit->PeakTime(), hitWireID.Plane, hitWireID.TPC, hitWireID.Cryostat));
187 
188  m_clusterHit2DMasterVec.emplace_back(0, 0., 0., xPosition, hitPeakTime, *recobHit);
189 
190  recobHitTo2DHitMap[recobHit] = &m_clusterHit2DMasterVec.back();
191  }
192 
193  // Now we can go through the space points and build our 3D hits
194  for(auto& pointPair : spacePointHitVecMap)
195  {
196  const recob::SpacePoint* spacePoint = pointPair.first;
197  const std::vector<const recob::Hit*>& recobHitVec = pointPair.second;
198 
199  if (recobHitVec.size() != 3)
200  {
201  std::cout << "************>>>>>> do not have 3 hits associated to space point! " << recobHitVec.size() << " ***************" << std::endl;
202  continue;
203  }
204 
205  std::vector<const reco::ClusterHit2D*> hit2DVec(recobHitVec.size());
206 
207  for(const auto& recobHit : recobHitVec)
208  {
209  const reco::ClusterHit2D* hit2D = recobHitTo2DHitMap.at(recobHit);
210 
211  hit2DVec[hit2D->getHit().WireID().Plane] = hit2D;
212  }
213 
214  // Weighted average, delta, sigmas, chisquare, kitchen sink, refrigerator for beer, etc.
215  float avePeakTime(0.);
216  float weightSum(0.);
217 
218  for(const auto& hit2D : hit2DVec)
219  {
220  float hitSigma = hit2D->getHit().RMS();
221  float weight = 1. / (hitSigma * hitSigma);
222 
223  avePeakTime += weight * hit2D->getTimeTicks();
224  weightSum += weight;
225  }
226 
227  avePeakTime /= weightSum;
228 
229  // Armed with the average peak time, now get hitChiSquare and the sig vec
230  float hitChiSquare(0.);
231  float sigmaPeakTime(std::sqrt(1./weightSum));
232 
233  for(const auto& hit2D : hit2DVec)
234  {
235  float hitRMS = hit2D->getHit().RMS();
236  float combRMS = std::sqrt(hitRMS*hitRMS - sigmaPeakTime*sigmaPeakTime);
237  float peakTime = hit2D->getTimeTicks();
238  float deltaTime = peakTime - avePeakTime;
239  float hitSig = deltaTime / combRMS;
240 
241  hitChiSquare += hitSig * hitSig;
242  }
243 
244  // The x position is a weighted sum but the y-z position is simply the average
245  float position[] = { float(spacePoint->XYZ()[0]), float(spacePoint->XYZ()[1]), float(spacePoint->XYZ()[2])};
246  float totalCharge = hit2DVec[0]->getHit().Integral() + hit2DVec[1]->getHit().Integral() + hit2DVec[2]->getHit().Integral();
247 
248  reco::ClusterHit2DVec hitVector;
249 
250  hitVector.resize(3,NULL);
251 
252  // Make sure we have the hits
253  hitVector.at(hit2DVec[0]->getHit().WireID().Plane) = hit2DVec[0];
254  hitVector.at(hit2DVec[1]->getHit().WireID().Plane) = hit2DVec[1];
255  hitVector.at(hit2DVec[2]->getHit().WireID().Plane) = hit2DVec[2];
256 
257  // And get the wire IDs
258  std::vector<geo::WireID> wireIDVec = {geo::WireID(0,0,geo::kU,0), geo::WireID(0,0,geo::kV,0), geo::WireID(0,0,geo::kW,0)};
259 
260  for(const auto& hit : hitVector)
261  {
262  wireIDVec[hit->getHit().WireID().Plane] = hit->getHit().WireID();
263 
264  if (hit->getStatusBits() & reco::ClusterHit2D::USEDINTRIPLET) hit->setStatusBit(reco::ClusterHit2D::SHAREDINTRIPLET);
265 
266  hit->setStatusBit(reco::ClusterHit2D::USEDINTRIPLET);
267  }
268 
269  unsigned int statusBits(0x7);
270 
271  // For compiling at the moment
272  std::vector<float> hitDelTSigVec = {0.,0.,0.};
273 
274  hitDelTSigVec[0] = std::fabs(hitVector[0]->getTimeTicks() - 0.5 * (hitVector[1]->getTimeTicks() + hitVector[2]->getTimeTicks()));
275  hitDelTSigVec[1] = std::fabs(hitVector[1]->getTimeTicks() - 0.5 * (hitVector[2]->getTimeTicks() + hitVector[0]->getTimeTicks()));
276  hitDelTSigVec[2] = std::fabs(hitVector[2]->getTimeTicks() - 0.5 * (hitVector[0]->getTimeTicks() + hitVector[1]->getTimeTicks()));
277 
278  float deltaPeakTime = *std::min_element(hitDelTSigVec.begin(),hitDelTSigVec.end());
279 
280  // Create the 3D cluster hit
281  hitPairList.emplace_back(new reco::ClusterHit3D(0,
282  statusBits,
283  position,
284  totalCharge,
285  avePeakTime,
286  deltaPeakTime,
287  sigmaPeakTime,
288  hitChiSquare,
289  0.,
290  0.,
291  hitVector,
292  hitDelTSigVec,
293  wireIDVec));
294  }
295 
296  if (m_enableMonitoring)
297  {
298  theClockMakeHits.stop();
299 
300  m_timeVector[BUILDTHREEDHITS] = theClockMakeHits.accumulated_real_time();
301  }
302 
303  mf::LogDebug("Cluster3D") << ">>>>> 3D hit building done, found " << hitPairList.size() << " 3D Hits" << std::endl;
304 
305  return;
306 }
const detinfo::DetectorProperties * m_detector
float getTimeTicks() const
Definition: Cluster3D.h:72
virtual int TriggerOffset() const =0
art::InputTag m_spacePointTag
Data members to follow.
Planes which measure V.
Definition: geo_types.h:77
geo::WireID WireID() const
Initial tdc tick for hit.
Definition: Hit.h:234
float RMS() const
RMS of the hit shape, in tick units.
Definition: Hit.h:221
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
bool isValid() const
Definition: Handle.h:190
Planes which measure U.
Definition: geo_types.h:76
const recob::Hit & getHit() const
Definition: Cluster3D.h:73
const Double32_t * XYZ() const
Definition: SpacePoint.h:65
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
Detector simulation of raw signals on wires.
std::vector< const reco::ClusterHit2D * > ClusterHit2DVec
Definition: Cluster3D.h:85
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
virtual double ConvertTicksToX(double ticks, int p, int t, int c) const =0
double weight
Definition: plottest35.C:25
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:219
T const * get() const
Definition: Ptr.h:321
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Planes which measure W (third view for Bo, MicroBooNE, etc).
Definition: geo_types.h:78
recob::tracking::Plane Plane
Definition: TrackState.h:17
virtual double GetXTicksOffset(int p, int t, int c) const =0

Member Data Documentation

Hit2DVector lar_cluster3d::SpacePointHit3DBuilder::m_clusterHit2DMasterVec
mutableprivate

Definition at line 82 of file SpacePointHit3DBuilder_tool.cc.

Referenced by Hit3DBuilder().

const detinfo::DetectorProperties* lar_cluster3d::SpacePointHit3DBuilder::m_detector
private

Definition at line 85 of file SpacePointHit3DBuilder_tool.cc.

Referenced by configure(), and Hit3DBuilder().

bool lar_cluster3d::SpacePointHit3DBuilder::m_enableMonitoring
private

Definition at line 78 of file SpacePointHit3DBuilder_tool.cc.

Referenced by configure(), and Hit3DBuilder().

geo::Geometry* lar_cluster3d::SpacePointHit3DBuilder::m_geometry
private

Definition at line 84 of file SpacePointHit3DBuilder_tool.cc.

Referenced by configure(), and Hit3DBuilder().

art::InputTag lar_cluster3d::SpacePointHit3DBuilder::m_spacePointTag
private

Data members to follow.

Definition at line 76 of file SpacePointHit3DBuilder_tool.cc.

Referenced by configure(), and Hit3DBuilder().

std::vector<float> lar_cluster3d::SpacePointHit3DBuilder::m_timeVector
mutableprivate

Definition at line 79 of file SpacePointHit3DBuilder_tool.cc.

Referenced by getTimeToExecute(), and Hit3DBuilder().


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