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>>();
105 std::unique_ptr<std::vector<anab::CosmicTag>> cosmicTagPFParticleVector(
106 new std::vector<anab::CosmicTag>);
107 std::unique_ptr<art::Assns<recob::PCAxis, anab::CosmicTag>> assnOutCosmicTagPCAxis(
109 std::unique_ptr<art::Assns<recob::PFParticle, anab::CosmicTag>> assnOutCosmicTagPFParticle(
116 if (!pfParticleHandle.
isValid()) {
140 art::FindManyP<recob::PCAxis> pfPartToPCAxisAssns(pfParticleHandle, evt,
fPCAxisModuleLabel);
143 art::FindManyP<recob::SpacePoint> spacePointAssnVec(
154 for (
size_t pfPartIdx = 0; pfPartIdx != pfParticleHandle->size(); pfPartIdx++) {
158 std::vector<art::Ptr<recob::PCAxis>> pcAxisVec = pfPartToPCAxisAssns.at(pfPartIdx);
161 if (pcAxisVec.empty())
continue;
168 if (pcAxisVec.size() > 1 && pcAxisVec.front()->getID() > pcAxisVec.back()->getID())
186 double maxArcLen = 3. * eigenVal0;
189 TVector3 vertexPosition(
195 TVector3 pcAxisStart = vertexPosition - maxArcLen * vertexDirection;
196 TVector3 pcAxisEnd = vertexPosition + maxArcLen * vertexDirection;
199 float trackEndPt1_X = pcAxisStart[0];
200 float trackEndPt1_Y = pcAxisStart[1];
201 float trackEndPt1_Z = pcAxisStart[2];
202 float trackEndPt2_X = pcAxisEnd[0];
203 float trackEndPt2_Y = pcAxisEnd[1];
204 float trackEndPt2_Z = pcAxisEnd[2];
207 std::vector<art::Ptr<recob::Cluster>> clusterVec = clusterAssns.at(pfParticle.
key());
212 for (
const auto&
cluster : clusterVec) {
214 std::vector<art::Ptr<recob::Hit>> hitVec = clusterHitAssns.at(
cluster->ID());
222 for (
const auto&
hit : hitVec) {
224 std::cout <<
"***>> Hit key: " <<
hit.key() <<
", peak - RMS: " <<
hit->PeakTimeMinusRMS()
225 <<
", peak + RMS: " <<
hit->PeakTimePlusRMS()
238 std::vector<art::Ptr<recob::SpacePoint>> spacePointVec = spacePointAssnVec.at(pfParticle.
key());
243 if (isCosmic == 0 && !spacePointVec.empty()) {
249 if (eigenVal0 > 0. && transRMS > 0.) {
256 double arcLengthToFirstHit(9999.);
257 double arcLengthToLastHit(-9999.);
259 for (
const auto spacePoint : spacePointVec) {
260 TVector3 spacePointPos(spacePoint->XYZ()[0], spacePoint->XYZ()[1], spacePoint->XYZ()[2]);
261 TVector3 deltaPos = spacePointPos - vertexPosition;
262 double arcLenToHit = deltaPos.Dot(vertexDirection);
264 if (arcLenToHit < arcLengthToFirstHit) {
265 arcLengthToFirstHit = arcLenToHit;
266 pcAxisStart = spacePointPos;
269 if (arcLenToHit > arcLengthToLastHit) {
270 arcLengthToLastHit = arcLenToHit;
271 pcAxisEnd = spacePointPos;
276 trackEndPt1_X = pcAxisStart[0];
277 trackEndPt1_Y = pcAxisStart[1];
278 trackEndPt1_Z = pcAxisStart[2];
279 trackEndPt2_X = pcAxisEnd[0];
280 trackEndPt2_Y = pcAxisEnd[1];
281 trackEndPt2_Z = pcAxisEnd[2];
288 bool nBdX[] = {
false,
false};
289 bool nBdY[] = {
false,
false};
290 bool nBdZ[] = {
false,
false};
319 bool exitEnd1 = nBdX[0] || nBdY[0];
320 bool exitEnd2 = nBdX[1] || nBdY[1];
328 if ((exitEnd1 && exitEnd2) || exitEndZ1 || exitEndZ2) {
330 if (nBdX[0] && nBdX[1])
332 else if (nBdY[0] && nBdY[1])
334 else if ((nBdX[0] || nBdX[1]) && (nBdY[0] || nBdY[1]))
336 else if ((nBdX[0] || nBdX[1]) && (nBdZ[0] || nBdZ[1]))
342 else if (nBdZ[0] && nBdZ[1]) {
347 else if ((nBdX[0] || nBdY[0] || nBdZ[0]) != (nBdX[1] || nBdY[1] || nBdZ[1])) {
349 if (nBdX[0] || nBdX[1])
351 else if (nBdY[0] || nBdY[1])
353 else if (nBdZ[0] || nBdZ[1])
359 std::vector<float> endPt1;
360 std::vector<float> endPt2;
361 endPt1.push_back(trackEndPt1_X);
362 endPt1.push_back(trackEndPt1_Y);
363 endPt1.push_back(trackEndPt1_Z);
364 endPt2.push_back(trackEndPt2_X);
365 endPt2.push_back(trackEndPt2_Y);
366 endPt2.push_back(trackEndPt2_Z);
368 float cosmicScore = isCosmic > 0 ? 1. : 0.;
373 else if (isCosmic == 4)
377 cosmicTagPFParticleVector->emplace_back(endPt1, endPt2, cosmicScore, tag_id);
380 *
this, evt, *cosmicTagPFParticleVector, pfParticle, *assnOutCosmicTagPFParticle);
383 for (
const auto& axis : pcAxisVec) {
384 util::CreateAssn(*
this, evt, *cosmicTagPFParticleVector, axis, *assnOutCosmicTagPCAxis);
const EigenVectors & getEigenVectors() const
const double * getEigenValues() const
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
enum anab::cosmic_tag_id CosmicTagID_t
EDProducer(fhicl::ParameterSet const &pset)
std::string fPFParticleModuleLabel
std::vector< reco::ClusterHit2D > Hit2DVector
Cluster finding and building.
art framework interface to geometry description
bool isValid() const noexcept
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
#define DEFINE_ART_MODULE(klass)
CosmicPCAxisTagger(fhicl::ParameterSet const &p)
key_type key() const noexcept
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
void produce(art::Event &e) override
Detector simulation of raw signals on wires.
const double * getAvePosition() const
Declaration of signal hit object.
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
lar_cluster3d::PrincipalComponentsAlg fPcaAlg
Principal Components algorithm.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
LArSoft geometry interface.
QTextStream & endl(QTextStream &s)
std::string fPCAxisModuleLabel