76 const art::Handle<std::vector<recob::PFParticle>>& pfpHandle,
77 const art::Handle<std::vector<recob::Track>>& trackHandle,
86 ,
fGeom(lar::providerFrom<geo::Geometry>())
87 ,
fSCE(lar::providerFrom<spacecharge::SpaceChargeService>())
91 ,
fPFPLabel(p.get<std::string>(
"PFPLabel"))
93 ,
fT0Labels(p.get<std::vector<std::string>>(
"T0Labels"))
97 produces<std::vector<anab::T0>>();
98 produces<std::vector<recob::Slice>>();
99 produces<std::vector<recob::PFParticle>>();
100 produces<std::vector<recob::SpacePoint>>();
101 produces<std::vector<recob::Cluster>>();
102 produces<std::vector<recob::Vertex>>();
103 produces<std::vector<larpandoraobj::PFParticleMetadata>>();
106 produces<art::Assns<anab::T0, recob::PFParticle>>();
107 produces<art::Assns<recob::Slice, recob::Hit>>();
109 produces<art::Assns<recob::PFParticle, recob::Slice>>();
110 produces<art::Assns<recob::PFParticle, recob::SpacePoint>>();
111 produces<art::Assns<recob::PFParticle, recob::Vertex>>();
112 produces<art::Assns<recob::PFParticle, recob::Cluster>>();
113 produces<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>();
114 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
115 produces<art::Assns<recob::Cluster, recob::Hit>>();
122 auto t0Collection = std::make_unique<std::vector<anab::T0>>();
123 auto pfpCollection = std::make_unique<std::vector<recob::PFParticle>>();
124 auto clusterCollection = std::make_unique<std::vector<recob::Cluster>>();
125 auto spCollection = std::make_unique<std::vector<recob::SpacePoint>>();
126 auto vtxCollection = std::make_unique<std::vector<recob::Vertex>>();
127 auto sliceCollection = std::make_unique<std::vector<recob::Slice>>();
128 auto pfpMetaCollection = std::make_unique<std::vector<larpandoraobj::PFParticleMetadata>>();
131 auto t0PFPAssn = std::make_unique<art::Assns<anab::T0, recob::PFParticle>>();
132 auto sliceHitAssn = std::make_unique<art::Assns<recob::Slice, recob::Hit>>();
133 auto pfpSliceAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Slice>>();
134 auto pfpVtxAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Vertex>>();
135 auto pfpSPAssn = std::make_unique<art::Assns<recob::PFParticle, recob::SpacePoint>>();
136 auto pfpClusterAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Cluster>>();
138 std::make_unique<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>();
139 auto spHitAssn = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
140 auto clusterHitAssn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
152 std::vector<art::Ptr<recob::Slice>> allSlices;
157 std::vector<art::Ptr<recob::Cluster>> allClusters;
162 std::vector<art::Ptr<recob::SpacePoint>> allSpacePoints;
167 std::vector<art::Ptr<recob::PFParticle>> allPFParticles;
172 std::vector<art::Ptr<recob::Track>> allTracks;
187 if (!fmSlicePFP.isValid()) {
188 throw cet::exception(
"SCECorrection") <<
"FindMany Slice-PFP is not Valid" << std::endl;
190 if (!fmPFPSP.isValid()) {
191 throw cet::exception(
"SCECorrection") <<
"FindMany PFP-SpacePoint is not Valid" << std::endl;
193 if (!fmSPHit.isValid()) {
194 throw cet::exception(
"SCECorrection") <<
"FindMany SpacePoint-Hit is not Valid" << std::endl;
203 for (
auto const& slice : allSlices) {
207 sliceCollection->push_back(newSlice);
211 const std::vector<art::Ptr<recob::PFParticle>> slicePFPs = fmSlicePFP.at(slice.key());
213 const std::map<art::Ptr<anab::T0>,
bool> sliceT0CorrectMap =
214 getSliceT0s(evt, slicePFPs, pfpHandle, trackHandle, fmPFPTrack);
216 const std::pair<art::Ptr<anab::T0>,
bool> sliceT0CorrectPair =
219 if (sliceT0CorrectPair.first.isNull() && !
fCorrectNoT0Tag) {
continue; }
223 if (!sliceT0CorrectPair.first.isNull()) {
225 t0Offset = detProp.DriftVelocity() * sliceT0CorrectPair.first->Time() / 1e3;
227 t0Collection->push_back(*sliceT0CorrectPair.first);
228 newT0Ptr = t0PtrMaker(t0Collection->size() - 1);
233 if (fmSliceHit.isValid()) {
234 const std::vector<art::Ptr<recob::Hit>> sliceHits = fmSliceHit.at(slice.key());
236 sliceHitAssn->addSingle(newSlicePtr, hitPtr);
241 for (
auto const& pfp : slicePFPs) {
245 pfpCollection->push_back(newPFP);
247 pfpSliceAssn->addSingle(newPFPPtr, newSlicePtr);
249 if (!newT0Ptr.
isNull()) { t0PFPAssn->addSingle(newT0Ptr, newPFPPtr); }
251 std::vector<art::Ptr<recob::SpacePoint>> pfpSPs = fmPFPSP.at(pfp.key());
253 if (fmPFPVertex.isValid()) {
254 std::vector<art::Ptr<recob::Vertex>> pfpVertices = fmPFPVertex.at(pfp.key());
255 for (
auto const& pfpVertex : pfpVertices) {
260 std::vector<art::Ptr<recob::SpacePoint>> vtxSPs = pfpSPs.size() ? pfpSPs : allSpacePoints;
262 double minVtxSPDist = std::numeric_limits<double>::max();
264 for (
auto const& sp : vtxSPs) {
265 geo::Point_t spPos(sp->XYZ()[0], sp->XYZ()[1], sp->XYZ()[2]);
267 if (vtxSPDiff.Mag2() < minVtxSPDist) {
269 minVtxSPDist = vtxSPDiff.Mag2();
273 if (spPtr.
isNull())
continue;
279 if (!sliceT0CorrectPair.first.isNull() && sliceT0CorrectPair.second) {
292 vtxPos, pfpVertex->covariance(), pfpVertex->chi2(), pfpVertex->ndof(), pfpVertex->ID());
293 vtxCollection->push_back(newVtx);
295 pfpVtxAssn->addSingle(newPFPPtr, newVtxPtr);
299 for (
auto const& sp : pfpSPs) {
302 geo::Point_t spPos(sp->XYZ()[0], sp->XYZ()[1], sp->XYZ()[2]);
310 if (!sliceT0CorrectPair.first.isNull() && sliceT0CorrectPair.second) {
322 Double32_t spXYZ[3] = {spPos.X(), spPos.Y(), spPos.Z()};
325 spCollection->push_back(correctedSP);
327 pfpSPAssn->addSingle(newPFPPtr, spPtr);
328 spHitAssn->addSingle(spPtr, spHitPtr);
332 if (fmPFPCluster.isValid() && fmClusterHit.isValid()) {
333 std::vector<art::Ptr<recob::Cluster>> pfpClusters = fmPFPCluster.at(pfp.key());
334 for (
auto const& pfpCluster : pfpClusters) {
336 clusterCollection->push_back(newCluster);
339 std::vector<art::Ptr<recob::Hit>> clusterHits = fmClusterHit.at(pfpCluster.key());
340 pfpClusterAssn->addSingle(newPFPPtr, newClusterPtr);
341 for (
auto const& clusterHit : clusterHits) {
342 clusterHitAssn->addSingle(newClusterPtr, clusterHit);
348 if (fmPFPMeta.isValid()) {
349 const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>> pfpMetas =
350 fmPFPMeta.at(pfp.key());
353 pfpMetaCollection->push_back(newPFPMeta);
355 pfpMetaPtrMaker(pfpMetaCollection->size() - 1);
356 pfpMetaAssn->addSingle(newPFPPtr, newPFPMetaPtr);
365 evt.
put(std::move(t0Collection));
366 evt.
put(std::move(sliceCollection));
367 evt.
put(std::move(clusterCollection));
368 evt.
put(std::move(pfpCollection));
369 evt.
put(std::move(spCollection));
370 evt.
put(std::move(vtxCollection));
371 evt.
put(std::move(pfpMetaCollection));
373 evt.
put(std::move(t0PFPAssn));
375 evt.
put(std::move(sliceHitAssn));
376 evt.
put(std::move(pfpSPAssn));
377 evt.
put(std::move(spHitAssn));
378 evt.
put(std::move(pfpVtxAssn));
379 evt.
put(std::move(pfpSliceAssn));
380 evt.
put(std::move(pfpClusterAssn));
381 evt.
put(std::move(clusterHitAssn));
382 evt.
put(std::move(pfpMetaAssn));
393 case 1:
return geo::Vector_t{t0Offset * driftDirection, 0, 0};
394 case 2:
return geo::Vector_t{0, t0Offset * driftDirection, 0};
395 case 3:
return geo::Vector_t{0, 0, t0Offset * driftDirection};
398 <<
"Drift direction unknown: " << driftDirection << std::endl;
405 const art::Handle<std::vector<recob::PFParticle>>& pfpHandle,
406 const art::Handle<std::vector<recob::Track>>& trackHandle,
410 std::map<art::Ptr<anab::T0>,
bool> pfpT0CorrectMap;
412 for (
auto const& pfp : slicePFPs) {
416 for (
unsigned int i = 0; i <
fT0Labels.size(); i++) {
421 if (fmPFPT0.isValid()) {
422 std::vector<art::Ptr<anab::T0>> pfpT0s = fmPFPT0.at(pfp.key());
423 if (pfpT0s.size() == 1) {
429 if (!fmPFPTrack.isValid())
continue;
430 std::vector<art::Ptr<recob::Track>> pfpTracks = fmPFPTrack.at(pfp.key());
431 if (pfpTracks.size() != 1) {
continue; }
436 if (fmTrackT0.isValid()) {
437 std::vector<art::Ptr<anab::T0>> trackT0s = fmTrackT0.at(pfpTrack.
key());
438 if (trackT0s.size() == 1) {
445 return pfpT0CorrectMap;
452 if (!sliceT0CorrectMap.size()) {
return std::pair<art::Ptr<anab::T0>,
bool>(); }
454 double minT0 = std::numeric_limits<double>::max();
455 std::pair<art::Ptr<anab::T0>,
bool> sliceT0CorrectPair;
456 for (
auto const& sliceT0CorrectIter : sliceT0CorrectMap) {
457 double t0Time =
abs(sliceT0CorrectIter.first->Time());
458 if (t0Time < minT0) {
460 sliceT0CorrectPair = sliceT0CorrectIter;
463 return sliceT0CorrectPair;
code to link reconstructed objects back to the MC truth information
SCECorrection(fhicl::ParameterSet const &p)
geo::GeometryCore const * fGeom
Utilities related to art service access.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
Declaration of signal hit object.
geo::Vector_t applyT0Shift(const double &t0, const geo::TPCID &tpcId) const
EDProducer(fhicl::ParameterSet const &pset)
Geometry information for a single TPC.
constexpr auto abs(T v)
Returns the absolute value of the argument.
Set of hits with a 2D structure.
geo::WireID const & WireID() const
Initial tdc tick for hit.
CryostatGeo const & GetElement(CryostatID const &cryoid) const
Returns the specified cryostat.
Definition of vertex object for LArSoft.
void produce(art::Event &evt) override
spacecharge::SpaceCharge const * fSCE
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
std::map< art::Ptr< anab::T0 >, bool > getSliceT0s(const art::Event &evt, const std::vector< art::Ptr< recob::PFParticle >> &slicePFPs, const art::Handle< std::vector< recob::PFParticle >> &pfpHandle, const art::Handle< std::vector< recob::Track >> &trackHandle, const art::FindManyP< recob::Track > &fmPFPTrack) const
#define DEFINE_ART_MODULE(klass)
Metadata associated to PFParticles.
const std::string fPFPLabel
const std::vector< bool > fT0LabelsCorrectT0
key_type key() const noexcept
bool isNull() const noexcept
Provides recob::Track data product.
std::pair< art::Ptr< anab::T0 >, bool > getSliceBestT0(const std::map< art::Ptr< anab::T0 >, bool > &sliceT0CorrectMap) const
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
Declaration of cluster object.
constexpr TPCID const & asTPCID() const
Conversion to TPCID (for convenience of notation).
const std::string fTrackLabel
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
virtual bool EnableCalSpatialSCE() const =0
Hierarchical representation of particle flow.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
const bool fCorrectNoT0Tag
art framework interface to geometry description
const std::vector< std::string > fT0Labels
cet::coded_exception< error, detail::translate > exception
SCECorrection & operator=(SCECorrection const &)=delete