27 #include "art_root_io/TFileService.h" 92 std::vector<size_t>& used,
95 bool Has(
const std::vector<size_t>& v,
size_t idx);
139 produces< std::vector<recob::Track> >();
140 produces< std::vector<recob::SpacePoint> >();
141 produces< art::Assns<recob::Track, recob::Hit> >();
142 produces< art::Assns<recob::Track, recob::SpacePoint> >();
143 produces< art::Assns<recob::SpacePoint, recob::Hit> >();
152 fEvTree = tfs->make<TTree>(
"Egtestev",
"egtestev");
156 fShTree = tfs->make<TTree>(
"Egtestsh",
"egtestsh");
176 std::unique_ptr< std::vector< recob::Track > >
tracks(
new std::vector< recob::Track >);
177 std::unique_ptr< std::vector< recob::SpacePoint > > allsp(
new std::vector< recob::SpacePoint >);
189 size_t spStart = 0, spEnd = 0;
190 double sp_pos[3], sp_err[6];
191 for (
size_t i = 0; i < 6; i++) sp_err[i] = 1.0;
199 std::vector< art::Ptr< recob::Hit > > hits2d;
201 spStart = allsp->size();
203 for (
int h =
trk->size() - 1;
h >= 0;
h--)
210 (sp_pos[0] != h3d->
Point3D().X()) ||
211 (sp_pos[1] != h3d->
Point3D().Y()) ||
212 (sp_pos[2] != h3d->
Point3D().Z()))
219 sp_pos[0] = h3d->
Point3D().X();
220 sp_pos[1] = h3d->
Point3D().Y();
221 sp_pos[2] = h3d->
Point3D().Z();
230 spEnd = allsp->size();
240 for (
size_t t = 0;
t < fPmatracks.size();
t++)
delete fPmatracks[
t];
255 std::vector< TVector3 > xyz, dircos;
257 for (
size_t i = 0; i < src.
size(); ++i)
258 if (src[i]->IsEnabled())
260 xyz.push_back(src[i]->
Point3D());
262 if (i < src.
size() - 1)
264 TVector3 dc(src[i + 1]->
Point3D());
265 dc -= src[i]->Point3D();
266 dc *= 1.0 / dc.Mag();
267 dircos.push_back(dc);
269 else dircos.push_back(dircos.back());
272 if (xyz.size() != dircos.size())
274 mf::LogError(
"IniSegReco") <<
"pma::Track3D to recob::Track conversion problem.";
288 std::vector<art::Ptr<recob::Hit> > hitlist;
295 const sim::ParticleList& plist = pi_serv->
ParticleList();
297 std::vector<const simb::MCParticle * > primaries = plist.GetPrimaries();
298 if (primaries.size() != 1)
return false;
301 if ((firstel->
PdgCode() != 11) && (firstel->
PdgCode() != -11) && (firstel->
PdgCode() != 22))
return false;
303 TLorentzVector startingp = primaries[0]->Position();
304 TVector3 primaryvtx(startingp.X(), startingp.Y(), startingp.Z());
311 startingp = primaries[0]->EndPosition();
312 TVector3 startp(startingp.X(), startingp.Y(), startingp.Z());
320 TLorentzVector mom = primaries[0]->Momentum();
321 TVector3 momvec3(mom.Px(), mom.Py(), mom.Pz());
322 TVector3
dir = momvec3 * (1 / momvec3.Mag());
324 TVector3 firstpoint(startingp.X(), startingp.Y(), startingp.Z());
325 TVector3 secondpoint = firstpoint +
dir;
334 double startvtx[3] = {firstpoint.X(), firstpoint.Y(), firstpoint.Z()};
338 if (!tpcid.
isValid)
return false;
341 size_t tpc = tpcid.
TPC;
344 iniseg->
AddNode(detProp, firstpoint, tpc, cryo);
345 iniseg->
AddNode(detProp, secondpoint, tpc, cryo);
347 for (
size_t h = 0;
h < hitlist.size();
h++)
348 if (hitlist[
h]->
WireID().TPC == tpc)
356 while (hi < iniseg->
size())
369 if (iniseg->
size() < 5)
return false;
373 double maxdist = 0.0;
size_t bestview = 0;
375 for (
size_t view = 0; view < tpcgeo.
Nplanes(); ++view)
377 std::map< size_t, std::vector< double > >
ex;
383 if ((dist > maxdist) && (ex.size() > 0))
395 std::map< size_t, std::vector< double > > dedx;
401 if (v.second[7] < rmin) rmin = v.second[7];
403 double rmax = rmin + 3.0;
406 if (((v.second[7] +
fR1) >
fR0) && (v.second[7] < 15))
409 double range = v.second[7] + (
fR0 -
fR1);
414 if ((v.second[5] > 0) && (v.second[6] > 0))
416 fDedx = v.second[5] / v.second[6];
419 if (v.second[7] < rmax)
422 sumdx += v.second[6];
441 if (px > 0) px -= corrt0x;
450 std::random_device rd;
451 std::mt19937
gen(rd());
453 double mean = 0.0;
double sigma = 0.7;
454 std::normal_distribution<double>
dist (mean, sigma);
463 std::random_device rd;
464 std::mt19937
gen(rd());
466 std::uniform_real_distribution<double> distribution(0.0,
fR0);
467 fR1 = distribution(gen);
475 double vtx[3] = {pvtx.X(), pvtx.Y(), pvtx.Z()};
483 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
484 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
485 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
488 double dista = fabs(minx - pvtx.X());
489 double distb = fabs(pvtx.X() - maxx);
491 if ((pvtx.X() > minx) && (pvtx.X() < maxx) &&
496 else { inside =
false; }
499 dista = fabs(maxy - pvtx.Y());
500 distb = fabs(pvtx.Y() - miny);
501 if (inside && (pvtx.Y() > miny) && (pvtx.Y() < maxy) &&
506 dista = fabs(maxz - pvtx.Z());
507 distb = fabs(pvtx.Z() - minz);
508 if (inside && (pvtx.Z() > minz) && (pvtx.Z() < maxz) &&
520 for (
auto c : v)
if (
c == idx)
return true;
532 size_t min_size = hits_in.size() / 5;
533 if (min_size < 3) min_size = 3;
535 std::vector<size_t> used;
536 std::vector< art::Ptr<recob::Hit> > close_hits;
538 while (
GetCloseHits(detProp, r2d, hits_in, used, close_hits))
540 if (close_hits.size() > min_size)
541 for (
auto h : close_hits) hits_out.push_back(
h);
551 std::vector<size_t>& used,
557 const double gapMargin = 5.0;
560 while ((idx < hits_in.size()) &&
Has(used, idx)) idx++;
562 if (idx < hits_in.size())
564 hits_out.push_back(hits_in[idx]);
567 double r2d2 = r2d*r2d;
568 double gapMargin2 = sqrt(2 * gapMargin*gapMargin);
569 gapMargin2 = (gapMargin2 + r2d)*(gapMargin2 + r2d);
575 for (
size_t i = 0; i < hits_in.size(); i++)
583 for (
size_t idx_o = 0; idx_o < hits_out.size(); idx_o++)
592 if (d2 < r2d2) { accept =
true;
break; }
596 if (d2 < gapMargin2) { accept =
true;
break; }
602 hits_out.push_back(hi);
bool Has(const std::vector< size_t > &v, size_t idx)
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
bool BuildSegMC(art::Event &e)
ShSeg(fhicl::ParameterSet const &p)
Implementation of the Projection Matching Algorithm.
double Dist2(const TVector2 &v1, const TVector2 &v2)
Handle< PROD > getHandle(SelectorBase const &) const
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
void produce(art::Event &e) override
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
geo::WireID WireID() const
unsigned int Nplanes() const
Number of planes in this tpc.
bool IsEnabled() const noexcept
EDProducer(fhicl::ParameterSet const &pset)
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
double MinX() const
Returns the world x coordinate of the start of the box.
bool isValid
Whether this ID points to a valid element.
Geometry information for a single TPC.
TrackTrajectory::Flags_t Flags_t
TVector3 const & Point3D() const
CryostatID_t Cryostat
Index of cryostat.
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
double MaxX() const
Returns the world x coordinate of the end of the box.
WireID_t Wire
Index of the wire within its plane.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
art framework interface to geometry description
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void AddNode(pma::Node3D *node)
pma::Hit3D * release_at(size_t index)
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::string EndProcess() const
void push_back(Ptr< U > const &p)
void CorrOffset(detinfo::DetectorPropertiesData const &detProp, TVector3 &vec, const simb::MCParticle &particle)
A trajectory in space reconstructed from hits.
recob::Track ConvertFrom(pma::Track3D const &src)
std::vector< pma::Track3D * > fPmatracks
T get(std::string const &key) const
double T(const int i=0) const
double MinZ() const
Returns the world z coordinate of the start of the box.
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.
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
bool GetCloseHits(detinfo::DetectorPropertiesData const &detProp, double r2d, const std::vector< art::Ptr< recob::Hit > > &hits_in, std::vector< size_t > &used, std::vector< art::Ptr< recob::Hit > > &hits_out)
float GetSegFraction() const noexcept
double MaxY() const
Returns the world y coordinate of the end of the box.
const sim::ParticleList & ParticleList() const
size_t CompleteMissingWires(detinfo::DetectorPropertiesData const &detProp, unsigned int view)
void push_back(pma::Hit3D *hit)
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether we have the specified TPC.
ShSeg & operator=(ShSeg const &)=delete
Implementation of the Projection Matching Algorithm.
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
void FilterOutSmallParts(detinfo::DetectorPropertiesData const &detProp, double r2d, const std::vector< art::Ptr< recob::Hit > > &hits_in, std::vector< art::Ptr< recob::Hit > > &hits_out)
double GetRawdEdxSequence(std::map< size_t, std::vector< double >> &dedx, unsigned int view=geo::kZ, unsigned int skip=0, bool inclDisabled=false) const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double MaxZ() const
Returns the world z coordinate of the end of the box.
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
std::string fHitsModuleLabel
Provides recob::Track data product.
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
art::Ptr< recob::Hit > const & Hit2DPtr() const
EventNumber_t event() const
void reconfigure(fhicl::ParameterSet const &p)
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
double MinY() const
Returns the world y coordinate of the start of the box.
geo::CryostatID::CryostatID_t FindCryostatAtPosition(geo::Point_t const &worldLoc) const
Returns the index of the cryostat at specified location.
pma::ProjectionMatchingAlg fProjectionMatchingAlg
bool InsideFidVol(TLorentzVector const &pvtx) const
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
calo::CalorimetryAlg fCalorimetryAlg