46 class CosmicPCAxisTagger;
90 const double driftVelocity =
91 detector.DriftVelocity(detector.Efield(), detector.Temperature());
94 2 * geo->
DetHalfWidth() / (driftVelocity * fSamplingRate / 1000);
96 produces<std::vector<anab::CosmicTag>>();
97 produces<art::Assns<recob::PFParticle, anab::CosmicTag>>();
98 produces<art::Assns<recob::PCAxis, anab::CosmicTag>>();
104 std::unique_ptr<std::vector<anab::CosmicTag>> cosmicTagPFParticleVector(
105 new std::vector<anab::CosmicTag>);
106 std::unique_ptr<art::Assns<recob::PCAxis, anab::CosmicTag>> assnOutCosmicTagPCAxis(
108 std::unique_ptr<art::Assns<recob::PFParticle, anab::CosmicTag>> assnOutCosmicTagPFParticle(
115 if (!pfParticleHandle.
isValid()) {
116 evt.
put(std::move(cosmicTagPFParticleVector));
117 evt.
put(std::move(assnOutCosmicTagPFParticle));
118 evt.
put(std::move(assnOutCosmicTagPCAxis));
132 evt.
put(std::move(cosmicTagPFParticleVector));
133 evt.
put(std::move(assnOutCosmicTagPFParticle));
134 evt.
put(std::move(assnOutCosmicTagPCAxis));
153 for (
size_t pfPartIdx = 0; pfPartIdx != pfParticleHandle->size(); pfPartIdx++) {
157 std::vector<art::Ptr<recob::PCAxis>> pcAxisVec = pfPartToPCAxisAssns.at(pfPartIdx);
160 if (pcAxisVec.empty())
continue;
167 if (pcAxisVec.size() > 1 && pcAxisVec.front()->getID() > pcAxisVec.back()->getID())
168 std::reverse(pcAxisVec.begin(), pcAxisVec.end());
185 double maxArcLen = 3. * eigenVal0;
188 TVector3 vertexPosition(
194 TVector3 pcAxisStart = vertexPosition - maxArcLen * vertexDirection;
195 TVector3 pcAxisEnd = vertexPosition + maxArcLen * vertexDirection;
198 float trackEndPt1_X = pcAxisStart[0];
199 float trackEndPt1_Y = pcAxisStart[1];
200 float trackEndPt1_Z = pcAxisStart[2];
201 float trackEndPt2_X = pcAxisEnd[0];
202 float trackEndPt2_Y = pcAxisEnd[1];
203 float trackEndPt2_Z = pcAxisEnd[2];
206 std::vector<art::Ptr<recob::Cluster>> clusterVec = clusterAssns.at(pfParticle.
key());
211 for (
const auto&
cluster : clusterVec) {
213 std::vector<art::Ptr<recob::Hit>> hitVec = clusterHitAssns.at(
cluster->ID());
221 for (
const auto&
hit : hitVec) {
223 std::cout <<
"***>> Hit key: " <<
hit.key() <<
", peak - RMS: " <<
hit->PeakTimeMinusRMS()
224 <<
", peak + RMS: " <<
hit->PeakTimePlusRMS()
237 std::vector<art::Ptr<recob::SpacePoint>> spacePointVec = spacePointAssnVec.at(pfParticle.
key());
242 if (isCosmic == 0 && !spacePointVec.empty()) {
248 if (eigenVal0 > 0. && transRMS > 0.) {
255 double arcLengthToFirstHit(9999.);
256 double arcLengthToLastHit(-9999.);
258 for (
const auto spacePoint : spacePointVec) {
259 TVector3 spacePointPos(spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]);
260 TVector3 deltaPos = spacePointPos - vertexPosition;
261 double arcLenToHit = deltaPos.Dot(vertexDirection);
263 if (arcLenToHit < arcLengthToFirstHit) {
264 arcLengthToFirstHit = arcLenToHit;
265 pcAxisStart = spacePointPos;
268 if (arcLenToHit > arcLengthToLastHit) {
269 arcLengthToLastHit = arcLenToHit;
270 pcAxisEnd = spacePointPos;
275 trackEndPt1_X = pcAxisStart[0];
276 trackEndPt1_Y = pcAxisStart[1];
277 trackEndPt1_Z = pcAxisStart[2];
278 trackEndPt2_X = pcAxisEnd[0];
279 trackEndPt2_Y = pcAxisEnd[1];
280 trackEndPt2_Z = pcAxisEnd[2];
287 bool nBdX[] = {
false,
false};
288 bool nBdY[] = {
false,
false};
289 bool nBdZ[] = {
false,
false};
318 bool exitEnd1 = nBdX[0] || nBdY[0];
319 bool exitEnd2 = nBdX[1] || nBdY[1];
327 if ((exitEnd1 && exitEnd2) || exitEndZ1 || exitEndZ2) {
329 if (nBdX[0] && nBdX[1])
331 else if (nBdY[0] && nBdY[1])
333 else if ((nBdX[0] || nBdX[1]) && (nBdY[0] || nBdY[1]))
335 else if ((nBdX[0] || nBdX[1]) && (nBdZ[0] || nBdZ[1]))
341 else if (nBdZ[0] && nBdZ[1]) {
346 else if ((nBdX[0] || nBdY[0] || nBdZ[0]) != (nBdX[1] || nBdY[1] || nBdZ[1])) {
348 if (nBdX[0] || nBdX[1])
350 else if (nBdY[0] || nBdY[1])
352 else if (nBdZ[0] || nBdZ[1])
358 std::vector<float> endPt1;
359 std::vector<float> endPt2;
360 endPt1.push_back(trackEndPt1_X);
361 endPt1.push_back(trackEndPt1_Y);
362 endPt1.push_back(trackEndPt1_Z);
363 endPt2.push_back(trackEndPt2_X);
364 endPt2.push_back(trackEndPt2_Y);
365 endPt2.push_back(trackEndPt2_Z);
367 float cosmicScore = isCosmic > 0 ? 1. : 0.;
372 else if (isCosmic == 4)
376 cosmicTagPFParticleVector->emplace_back(endPt1, endPt2, cosmicScore, tag_id);
378 util::CreateAssn(evt, *cosmicTagPFParticleVector, pfParticle, *assnOutCosmicTagPFParticle);
381 for (
const auto& axis : pcAxisVec) {
382 util::CreateAssn(evt, *cosmicTagPFParticleVector, axis, *assnOutCosmicTagPCAxis);
386 evt.
put(std::move(cosmicTagPFParticleVector));
387 evt.
put(std::move(assnOutCosmicTagPFParticle));
388 evt.
put(std::move(assnOutCosmicTagPCAxis));
const EigenVectors & getEigenVectors() const
const double * getEigenValues() const
enum anab::cosmic_tag_id CosmicTagID_t
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
std::string fPFParticleModuleLabel
std::vector< reco::ClusterHit2D > Hit2DVector
Cluster finding and building.
Length_t DetLength(TPCID const &tpcid=tpc_zero) const
Returns the length of the active volume of the specified TPC.
bool isValid() const noexcept
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
#define DEFINE_ART_MODULE(klass)
CosmicPCAxisTagger(fhicl::ParameterSet const &p)
key_type key() const noexcept
Declaration of cluster object.
void produce(art::Event &e) override
Detector simulation of raw signals on wires.
This header file defines the interface to a principal components analysis designed to be used within ...
const double * getAvePosition() const
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
lar_cluster3d::PrincipalComponentsAlg fPcaAlg
Principal Components algorithm.
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
std::string fPCAxisModuleLabel