18 std::vector<art::Ptr<recob::Hit>> hits;
19 std::vector<int> clsIDs;
24 comparePFP(
const pfpStuff&
l,
const pfpStuff&
r)
29 double const lz = l.hits.size();
30 double const rz = r.hits.size();
33 constexpr
int hitthres = 80;
35 if (lz > hitthres && rz <= hitthres)
return false;
37 if (lz <= hitthres && rz > hitthres)
return true;
46 : fCalorimetryAlg(pset.
get<
fhicl::ParameterSet>(
"CalorimetryAlg"))
47 , fProjectionMatchingAlg(pset.
get<
fhicl::ParameterSet>(
"ProjectionMatchingAlg"))
57 art::FindManyP<recob::Hit>
const& cls_fm,
58 art::FindManyP<recob::Cluster>
const& clspfp_fm,
59 art::FindManyP<recob::Vertex>
const& vtxpfp_fm,
60 art::FindManyP<recob::PFParticle>
const& hit_fm,
61 art::FindManyP<recob::Cluster>
const& hitcls_fm,
62 art::FindManyP<recob::Track>
const& trkpfp_fm,
63 art::FindManyP<anab::Calorimetry>
const& fmcal)
72 std::vector<pfpStuff> allpfps;
75 for (
size_t i = 0; i < pfplist.size(); ++i) {
78 thispfp.clsIDs.clear();
79 thispfp.pfp = pfplist[i];
81 std::vector<art::Ptr<recob::Vertex>> thisvtxlist = vtxpfp_fm.at(pfplist[i].
key());
82 if (thisvtxlist.size()) thispfp.vtx = thisvtxlist[0];
85 if (thistrklist.size()) thispfp.trk = thistrklist[0];
88 std::vector<int> clustersize;
90 for (
size_t j = 0; j < thisclusterlist.size(); ++j) {
92 thispfp.clsIDs.push_back(thisclusterlist[j]->
ID());
94 std::vector<art::Ptr<recob::Hit>> thishitlist = cls_fm.at(thisclusterlist[j].
key());
95 clustersize.push_back((
int)thishitlist.size());
97 for (
size_t k = 0;
k < thishitlist.size(); ++
k) {
98 thispfp.hits.push_back(thishitlist[
k]);
103 if (clustersize.size() == 3) {
104 if (!thispfp.vtx)
continue;
105 if (!thispfp.trk)
continue;
107 allpfps.push_back(thispfp);
111 thispfp.vtx->position().Y(), thispfp.vtx->position().Z(),
geo::PlaneID(0, 0, 2));
113 std::cout <<
"pfp " << thispfp.pfp->Self() + 1 <<
" cluster sizes " << clustersize[0] <<
":" 114 << clustersize[1] <<
":" << clustersize[2] <<
" vertex " << thispfp.vtx->ID()
115 <<
" " << tick <<
":" << wire <<
" z " << thispfp.vtx->position().Z()
122 std::sort(allpfps.begin(), allpfps.end(), comparePFP);
125 std::cout <<
"sorted pfps: ";
126 for (
size_t i = 0; i < allpfps.size(); ++i)
127 std::cout << allpfps[i].pfp->Self() + 1 <<
" ";
130 bool showerCandidate =
false;
132 for (
size_t i = 0; i < allpfps.size(); ++i) {
138 std::vector<art::Ptr<recob::Hit>> pfphits = allpfps[i].hits;
139 std::vector<art::Ptr<recob::Cluster>> pfpcls = clspfp_fm.at(allpfps[i].pfp.key());
141 std::cout <<
"pfp " << allpfps[i].pfp->Self() + 1 <<
" hits " << pfphits.size() <<
std::endl;
148 if (pfptrk->
Vertex().Z() < pfptrk->
End().Z()) {
158 double pullTolerance = 0.7;
160 double minDistVert = 15;
166 if (pfphits.size() < 30)
continue;
167 if (pfphits.size() > 500)
continue;
169 if (pfphits.size() < 90) {
173 if (pfphits.size() > 400)
175 else if (pfphits.size() > 100)
179 for (
size_t ii = 0; ii < pfphits.size(); ++ii) {
184 double showerHitPull = 0;
186 TVector3 pfpStart =
shwvtx;
190 std::map<geo::PlaneID, double> trk_tick1;
191 std::map<geo::PlaneID, double> trk_wire1;
194 std::map<geo::PlaneID, double> trk_tick2;
195 std::map<geo::PlaneID, double> trk_wire2;
199 trk_wire1[*iPlane] = geom->
WireCoordinate(pfpStart[1], pfpStart[2], *iPlane);
201 trk_wire2[*iPlane] = geom->
WireCoordinate(pfpPt2[1], pfpPt2[2], *iPlane);
204 for (
size_t j = 0; j < clusterlist.size(); ++j) {
205 std::vector<art::Ptr<recob::Hit>> cls_hitlist = cls_fm.at(clusterlist[j].
key());
207 if (clusterlist[j]->
ID() > 0 && cls_hitlist.size() > 10)
continue;
208 if (cls_hitlist.size() > 50)
continue;
210 bool isGoodCluster =
false;
214 for (
size_t k = 0;
k < allpfps[i].clsIDs.size(); ++
k) {
215 if (allpfps[i].clsIDs[
k] == clusterlist[j]->
ID()) skipit =
true;
217 if (skipit)
continue;
219 for (
size_t jj = 0; jj < cls_hitlist.size(); ++jj) {
220 int isGoodHit =
goodHit(clockData,
230 if (isGoodHit == -1) {
231 isGoodCluster =
false;
234 else if (isGoodHit == 1) {
235 isGoodCluster =
true;
242 for (
size_t jj = 0; jj < cls_hitlist.size(); ++jj) {
245 int showerHitPullAdd = 0;
256 showerHitPull += showerHitPullAdd;
265 showerHitPull /= nShowerHits;
267 std::cout <<
"shower hits " <<
showerHits.size() <<
" " << nShowerHits <<
" shower pull " 270 if (nShowerHits > tolerance &&
std::abs(showerHitPull) < pullTolerance) {
271 showerCandidate =
true;
272 std::cout <<
"SHOWER CANDIDATE" <<
std::endl;
274 if (nShowerHits > 400) maxDist *= 2;
275 for (
size_t k = 0;
k < hitlist.size(); ++
k) {
276 std::vector<art::Ptr<recob::Cluster>> hit_clslist = hitcls_fm.at(hitlist[
k].
key());
277 if (hit_clslist.size())
continue;
279 int isGoodHit =
goodHit(clockData,
293 for (
size_t k = 0;
k < clusterlist.size(); ++
k) {
294 std::vector<art::Ptr<recob::Hit>> cls_hitlist = cls_fm.at(clusterlist[
k].
key());
295 if (clusterlist[
k]->
ID() > 0 && cls_hitlist.size() > 50)
continue;
297 double thisDist = maxDist;
298 double thisMin = minDistVert;
300 if (cls_hitlist.size() < 10) {
304 else if (cls_hitlist.size() < 30)
311 for (
size_t kk = 0; kk < cls_hitlist.size(); ++kk) {
313 int isGoodHit =
goodHit(clockData,
322 if (isGoodHit == -1) {
326 else if (isGoodHit == 1) {
331 double fracGood = (double)ngoodhits / nhits;
333 bool isGoodTrack = fracGood > 0.4;
336 for (
size_t kk = 0; kk < cls_hitlist.size(); ++kk) {
345 if (showerCandidate) {
346 std::cout <<
"THIS IS THE SHOWER PFP: " << allpfps[i].pfp->Self() + 1 <<
std::endl;
352 if (showerCandidate)
return 1;
366 double const maxDist,
367 double const minDistVert,
368 std::map<geo::PlaneID, double>
const& trk_wire1,
369 std::map<geo::PlaneID, double>
const& trk_tick1,
370 std::map<geo::PlaneID, double>
const& trk_wire2,
371 std::map<geo::PlaneID, double>
const& trk_tick2)
const 397 double const minDistVert,
398 std::map<geo::PlaneID, double>
const& trk_wire1,
399 std::map<geo::PlaneID, double>
const& trk_tick1,
400 std::map<geo::PlaneID, double>
const& trk_wire2,
401 std::map<geo::PlaneID, double>
const& trk_tick2,
409 double UnitsPerTick = tickToDist / wirePitch;
412 double y0 = hit->
PeakTime() * UnitsPerTick;
414 double x1 = trk_wire1.at(hit->
WireID());
415 double y1 = trk_tick1.at(hit->
WireID()) * UnitsPerTick;
417 double x2 = trk_wire2.at(hit->
WireID());
418 double y2 = trk_tick2.at(hit->
WireID()) * UnitsPerTick;
420 double distToVert =
std::hypot(x0 - x1, y0 - y1);
421 if (distToVert < minDistVert)
return -1;
426 else if (distToVert < 100)
434 double costheta = -(
pow(c, 2) -
pow(a, 2) -
pow(b, 2)) / (2 * a * b);
435 if (costheta < 0)
return -1;
438 std::abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) /
std::hypot(y2 - y1, x2 - x1);
440 if (dist < maxDist) {
441 if (((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) > 0)
459 for (
size_t i = 0; i < showerhits.size(); ++i) {
460 if (hit.
key() == showerhits[i].key())
return false;
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
std::vector< double > totalEnergyErr
bool addShowerHit(art::Ptr< recob::Hit > hit, std::vector< art::Ptr< recob::Hit >> showerhits) const
geo::WireID WireID() const
std::vector< double > dEdx
double Temperature() const
In kelvin.
Vector_t VertexDirection() const
WireID_t Wire
Index of the wire within its plane.
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
art framework interface to geometry description
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
double Efield(unsigned int planegap=0) const
kV/cm
int makeShowers(detinfo::DetectorClocksData const &dataClock, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::PFParticle >> const &pfplist, std::vector< art::Ptr< recob::Vertex >> const &vertexlist, std::vector< art::Ptr< recob::Cluster >> const &clusterlist, std::vector< art::Ptr< recob::Hit >> const &hitlist, art::FindManyP< recob::Hit > const &cls_fm, art::FindManyP< recob::Cluster > const &clspfp_fm, art::FindManyP< recob::Vertex > const &vtxpfp_fm, art::FindManyP< recob::PFParticle > const &hit_fm, art::FindManyP< recob::Cluster > const &hitcls_fm, art::FindManyP< recob::Track > const &trkpfp_fm, art::FindManyP< anab::Calorimetry > const &fmcal)
key_type key() const noexcept
Point_t const & Vertex() const
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
double ConvertXToTicks(double X, int p, int t, int c) const
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
float PeakTime() const
Time of the signal peak, in tick units.
Contains all timing reference information for the detector.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
plane_id_iterator end_plane_id() const
Returns an iterator pointing after the last plane ID in the detector.
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Vector_t EndDirection() const
std::vector< double > totalEnergy
Point_t const & End() const
Access the description of detector geometry.
detail::Node< FrameID, bool > PlaneID
plane_id_iterator begin_plane_id() const
Returns an iterator pointing to the first plane ID in the detector.
int goodHit(detinfo::DetectorClocksData const &dataClock, detinfo::DetectorPropertiesData const &detProp, art::Ptr< recob::Hit > const &, double maxDist, double minDistVert, std::map< geo::PlaneID, double > const &trk_wire1, std::map< geo::PlaneID, double > const &trk_tick1, std::map< geo::PlaneID, double > const &trk_wire2, std::map< geo::PlaneID, double > const &trk_tick2) const
auto const & get(AssnsNode< L, R, D > const &r)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< art::Ptr< recob::Hit > > showerHits
std::vector< double > dEdxErr
const Point_t & position() const
Return vertex 3D position.
QTextStream & endl(QTextStream &s)