17 #include "canvas/Persistency/Common/FindManyP.h" 75 const art::Handle<std::vector<recob::PFParticle>>& pfpHandle,
76 const art::Handle<std::vector<recob::Track>>& trackHandle,
77 const art::FindManyP<recob::Track>& fmPFPTrack)
const;
85 ,
fGeom(lar::providerFrom<geo::Geometry>())
86 ,
fSCE(lar::providerFrom<spacecharge::SpaceChargeService>())
92 ,
fT0Labels(
p.get<std::vector<std::string>>(
"T0Labels"))
96 produces<std::vector<anab::T0>>();
97 produces<std::vector<recob::Slice>>();
98 produces<std::vector<recob::PFParticle>>();
99 produces<std::vector<recob::SpacePoint>>();
100 produces<std::vector<recob::Cluster>>();
101 produces<std::vector<recob::Vertex>>();
102 produces<std::vector<larpandoraobj::PFParticleMetadata>>();
105 produces<art::Assns<anab::T0, recob::PFParticle>>();
106 produces<art::Assns<recob::Slice, recob::Hit>>();
108 produces<art::Assns<recob::PFParticle, recob::Slice>>();
109 produces<art::Assns<recob::PFParticle, recob::SpacePoint>>();
110 produces<art::Assns<recob::PFParticle, recob::Vertex>>();
111 produces<art::Assns<recob::PFParticle, recob::Cluster>>();
112 produces<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>();
113 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
114 produces<art::Assns<recob::Cluster, recob::Hit>>();
121 auto t0Collection = std::make_unique<std::vector<anab::T0>>();
122 auto pfpCollection = std::make_unique<std::vector<recob::PFParticle>>();
123 auto clusterCollection = std::make_unique<std::vector<recob::Cluster>>();
124 auto spCollection = std::make_unique<std::vector<recob::SpacePoint>>();
125 auto vtxCollection = std::make_unique<std::vector<recob::Vertex>>();
126 auto sliceCollection = std::make_unique<std::vector<recob::Slice>>();
127 auto pfpMetaCollection = std::make_unique<std::vector<larpandoraobj::PFParticleMetadata>>();
130 auto t0PFPAssn = std::make_unique<art::Assns<anab::T0, recob::PFParticle>>();
131 auto sliceHitAssn = std::make_unique<art::Assns<recob::Slice, recob::Hit>>();
132 auto pfpSliceAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Slice>>();
133 auto pfpVtxAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Vertex>>();
134 auto pfpSPAssn = std::make_unique<art::Assns<recob::PFParticle, recob::SpacePoint>>();
135 auto pfpClusterAssn = std::make_unique<art::Assns<recob::PFParticle, recob::Cluster>>();
136 auto pfpMetaAssn = std::make_unique<art::Assns<recob::PFParticle, larpandoraobj::PFParticleMetadata>>();
137 auto spHitAssn = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
138 auto clusterHitAssn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
150 std::vector<art::Ptr<recob::Slice>> allSlices;
156 std::vector<art::Ptr<recob::Cluster>> allClusters;
162 std::vector<art::Ptr<recob::SpacePoint>> allSpacePoints;
168 std::vector<art::Ptr<recob::PFParticle>> allPFParticles;
174 std::vector<art::Ptr<recob::Track>> allTracks;
178 art::FindManyP<recob::PFParticle> fmSlicePFP(sliceHandle, evt,
fPFPLabel);
179 art::FindManyP<recob::Track> fmPFPTrack(pfpHandle, evt,
fTrackLabel);
180 art::FindManyP<recob::SpacePoint> fmPFPSP(pfpHandle, evt,
fPFPLabel);
181 art::FindManyP<recob::Cluster> fmPFPCluster(pfpHandle, evt,
fPFPLabel);
182 art::FindManyP<recob::Vertex> fmPFPVertex(pfpHandle, evt,
fPFPLabel);
183 art::FindManyP<recob::Hit> fmClusterHit(clusterHandle, evt,
fPFPLabel);
184 art::FindManyP<recob::Hit> fmSPHit(spHandle, evt,
fPFPLabel);
185 art::FindManyP<recob::Hit> fmSliceHit(sliceHandle, evt,
fPFPLabel);
186 art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta(pfpHandle, evt,
fPFPLabel);
190 if (!fmSlicePFP.isValid()) {
193 if (!fmPFPSP.isValid()) {
196 if (!fmSPHit.isValid()) {
205 for (
auto const& slice : allSlices) {
209 sliceCollection->push_back(newSlice);
213 const std::vector<art::Ptr<recob::PFParticle>> slicePFPs = fmSlicePFP.at(slice.key());
215 const std::map<art::Ptr<anab::T0>,
bool> sliceT0CorrectMap =
getSliceT0s(
216 evt, slicePFPs, pfpHandle, trackHandle, fmPFPTrack);
218 const std::pair<art::Ptr<anab::T0>,
bool> sliceT0CorrectPair =
getSliceBestT0(sliceT0CorrectMap);
226 if (!sliceT0CorrectPair.first.isNull()) {
228 t0Offset = detProp.DriftVelocity() * sliceT0CorrectPair.first->Time() / 1e3;
230 t0Collection->push_back(*sliceT0CorrectPair.first);
231 newT0Ptr = t0PtrMaker(t0Collection->size() - 1);
236 if (fmSliceHit.isValid()) {
237 const std::vector<art::Ptr<recob::Hit>> sliceHits = fmSliceHit.at(slice.key());
239 sliceHitAssn->addSingle(newSlicePtr, hitPtr);
244 for (
auto const& pfp : slicePFPs) {
248 pfpCollection->push_back(newPFP);
250 pfpSliceAssn->addSingle(newPFPPtr, newSlicePtr);
253 t0PFPAssn->addSingle(newT0Ptr, newPFPPtr);
256 std::vector<art::Ptr<recob::SpacePoint>> pfpSPs = fmPFPSP.at(pfp.key());
258 if (fmPFPVertex.isValid()) {
259 std::vector<art::Ptr<recob::Vertex>> pfpVertices = fmPFPVertex.at(pfp.key());
260 for (
auto const& pfpVertex : pfpVertices) {
265 std::vector<art::Ptr<recob::SpacePoint>> vtxSPs = pfpSPs.size() ? pfpSPs : allSpacePoints;
269 for (
auto const& sp : vtxSPs) {
270 geo::Point_t spPos(sp->XYZ()[0], sp->XYZ()[1], sp->XYZ()[2]);
272 if (vtxSPDiff.Mag2() < minVtxSPDist) {
274 minVtxSPDist = vtxSPDiff.Mag2();
285 if (!sliceT0CorrectPair.first.isNull() && sliceT0CorrectPair.second) {
293 posOffset.SetX(-posOffset.X());
299 recob::Vertex newVtx(vtxPos, pfpVertex->covariance(), pfpVertex->chi2(),
300 pfpVertex->ndof(), pfpVertex->ID());
301 vtxCollection->push_back(newVtx);
303 pfpVtxAssn->addSingle(newPFPPtr, newVtxPtr);
307 for (
auto const& sp : pfpSPs) {
310 geo::Point_t spPos(sp->XYZ()[0], sp->XYZ()[1], sp->XYZ()[2]);
318 if (!sliceT0CorrectPair.first.isNull() && sliceT0CorrectPair.second) {
326 posOffset.SetX(-posOffset.X());
332 Double32_t spXYZ[3] = { spPos.X(), spPos.Y(), spPos.Z() };
335 spCollection->push_back(correctedSP);
337 pfpSPAssn->addSingle(newPFPPtr, spPtr);
338 spHitAssn->addSingle(spPtr, spHitPtr);
342 if (fmPFPCluster.isValid() && fmClusterHit.isValid()) {
343 std::vector<art::Ptr<recob::Cluster>> pfpClusters = fmPFPCluster.at(pfp.key());
344 for (
auto const& pfpCluster : pfpClusters) {
346 clusterCollection->push_back(newCluster);
349 std::vector<art::Ptr<recob::Hit>> clusterHits = fmClusterHit.at(pfpCluster.key());
350 pfpClusterAssn->addSingle(newPFPPtr, newClusterPtr);
351 for (
auto const& clusterHit : clusterHits) {
352 clusterHitAssn->addSingle(newClusterPtr, clusterHit);
358 if (fmPFPMeta.isValid()) {
359 const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>> pfpMetas = fmPFPMeta.at(pfp.key());
362 pfpMetaCollection->push_back(newPFPMeta);
364 pfpMetaAssn->addSingle(newPFPPtr, newPFPMetaPtr);
407 throw cet::exception(
"SCECorrection") <<
"Drift direction unknown: " << driftDirection
415 const art::Handle<std::vector<recob::PFParticle>>& pfpHandle,
416 const art::Handle<std::vector<recob::Track>>& trackHandle,
417 const art::FindManyP<recob::Track>& fmPFPTrack)
const 420 std::map<art::Ptr<anab::T0>,
bool> pfpT0CorrectMap;
422 for (
auto const& pfp : slicePFPs) {
426 for (
unsigned int i = 0; i <
fT0Labels.size(); i++) {
430 art::FindManyP<anab::T0> fmPFPT0(pfpHandle, evt, t0Label);
431 if (fmPFPT0.isValid()) {
432 std::vector<art::Ptr<anab::T0>> pfpT0s = fmPFPT0.at(pfp.key());
433 if (pfpT0s.size() == 1) {
439 if (!fmPFPTrack.isValid())
441 std::vector<art::Ptr<recob::Track>> pfpTracks = fmPFPTrack.at(pfp.key());
442 if (pfpTracks.size() != 1) {
448 art::FindManyP<anab::T0> fmTrackT0(trackHandle, evt, t0Label);
449 if (fmTrackT0.isValid()) {
450 std::vector<art::Ptr<anab::T0>> trackT0s = fmTrackT0.at(pfpTrack.
key());
451 if (trackT0s.size() == 1) {
458 return pfpT0CorrectMap;
465 if (!sliceT0CorrectMap.size()) {
466 return std::pair<art::Ptr<anab::T0>,
bool>();
470 std::pair<art::Ptr<anab::T0>,
bool> sliceT0CorrectPair;
471 for (
auto const& sliceT0CorrectIter : sliceT0CorrectMap) {
472 double t0Time =
abs(sliceT0CorrectIter.first->Time());
473 if (t0Time < minT0) {
475 sliceT0CorrectPair = sliceT0CorrectIter;
478 return sliceT0CorrectPair;
code to link reconstructed objects back to the MC truth information
SCECorrection(fhicl::ParameterSet const &p)
geo::GeometryCore const * fGeom
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
geo::WireID WireID() const
geo::Vector_t applyT0Shift(const double &t0, const geo::TPCID &tpcId) const
EDProducer(fhicl::ParameterSet const &pset)
Geometry information for a single TPC.
Set of hits with a 2D structure.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition of vertex object for LArSoft.
void produce(art::Event &evt) override
art framework interface to geometry description
spacecharge::SpaceCharge const * fSCE
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
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
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::pair< art::Ptr< anab::T0 >, bool > getSliceBestT0(const std::map< art::Ptr< anab::T0 >, bool > &sliceT0CorrectMap) const
static int max(int a, int b)
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
constexpr TPCID const & asTPCID() const
Conversion to TPCID (for convenience of notation).
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
const std::string fTrackLabel
virtual bool EnableCalSpatialSCE() const =0
Declaration of signal hit object.
Hierarchical representation of particle flow.
short int DetectDriftDirection() const
Returns the expected drift direction based on geometry.
Provides recob::Track data product.
Access the description of detector 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
const std::vector< std::string > fT0Labels
cet::coded_exception< error, detail::translate > exception
SCECorrection & operator=(SCECorrection const &)=delete
QTextStream & endl(QTextStream &s)