7 std::vector<art::Ptr<recob::Hit> >
hits;
19 double lz = l.
hits.size();
20 double rz = r.
hits.size();
25 if (lz > hitthres && rz <= hitthres)
return false;
26 else if (lz <= hitthres && rz > hitthres)
return true;
46 fCalorimetryAlg(pset.get<
fhicl::ParameterSet>(
"CalorimetryAlg") ),
47 fProjectionMatchingAlg(pset.get<
fhicl::ParameterSet>(
"ProjectionMatchingAlg")){
50 int TCShowerAlg::makeShowers(
std::vector<
art::Ptr<recob::PFParticle> > pfplist,
std::vector<
art::Ptr<recob::Vertex> > vertexlist,
std::vector<
art::Ptr<recob::Cluster> > clusterlist,
std::vector<
art::Ptr<recob::Hit> > hitlist,
art::FindManyP<recob::Hit> cls_fm,
art::FindManyP<recob::Cluster> clspfp_fm,
art::FindManyP<recob::Vertex> vtxpfp_fm,
art::FindManyP<recob::PFParticle> hit_fm,
art::FindManyP<recob::Cluster> hitcls_fm,
art::FindManyP<recob::Track> trkpfp_fm,
art::FindManyP<anab::Calorimetry> fmcal) {
57 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
60 std::vector<pfpStuff> allpfps;
63 for (
size_t i = 0; i < pfplist.size(); ++i) {
67 thispfp.
pfp = pfplist[i];
69 std::vector<art::Ptr<recob::Vertex> > thisvtxlist = vtxpfp_fm.at(pfplist[i].key());
70 if (thisvtxlist.size()) thispfp.
vtx = thisvtxlist[0];
73 if (thistrklist.size()) thispfp.
trk = thistrklist[0];
76 std::vector<int> clustersize;
78 for (
size_t j = 0; j < thisclusterlist.size(); ++j) {
80 thispfp.
clsIDs.push_back(thisclusterlist[j]->ID());
82 std::vector<art::Ptr<recob::Hit> > thishitlist = cls_fm.at(thisclusterlist[j].key());
83 clustersize.push_back((
int)thishitlist.size());
85 for (
size_t k = 0; k < thishitlist.size(); ++k) {
86 thispfp.
hits.push_back(thishitlist[k]);
91 if (clustersize.size() == 3) {
92 if (!thispfp.
vtx)
continue;
93 if (!thispfp.
trk)
continue;
95 allpfps.push_back(thispfp);
100 std::cout <<
"pfp " << thispfp.
pfp->
Self() + 1 <<
" cluster sizes " << clustersize[0] <<
":" << clustersize[1] <<
":" << clustersize[2] <<
" vertex " << thispfp.
vtx->
ID() <<
" " << tick <<
":" << wire <<
" z " << thispfp.
vtx->
position().Z() << std::endl;
106 std::sort(allpfps.begin(), allpfps.end(),
comparePFP);
107 std::reverse(allpfps.begin(), allpfps.end());
109 std::cout <<
"sorted pfps: ";
110 for (
size_t i = 0; i < allpfps.size(); ++i)
111 std::cout << allpfps[i].pfp->Self() + 1 <<
" ";
112 std::cout << std::endl;
114 bool showerCandidate =
false;
116 for (
size_t i = 0; i < allpfps.size(); ++i) {
122 std::vector<art::Ptr<recob::Hit> > pfphits = allpfps[i].hits;
123 std::vector<art::Ptr<recob::Cluster> > pfpcls = clspfp_fm.at(allpfps[i].pfp.key());
127 std::cout <<
"pfp " << allpfps[i].pfp->Self() + 1 <<
" hits " << pfphits.size() << std::endl;
134 if (pfptrk->
Vertex().Z() < pfptrk->
End().Z()) {
145 double pullTolerance = 0.7;
147 double minDistVert = 15;
153 if (pfphits.size() < 30)
continue;
155 if (pfphits.size() > 500)
continue;
157 if (pfphits.size() < 90) {
161 if (pfphits.size() > 400) tolerance = 200;
162 else if (pfphits.size() > 100) tolerance = 100;
165 for (
size_t ii = 0; ii < pfphits.size(); ++ii) {
170 double showerHitPull = 0;
172 TVector3 pfpStart =
shwvtx;
176 std::map<geo::PlaneID, double> trk_tick1;
177 std::map<geo::PlaneID, double> trk_wire1;
180 std::map<geo::PlaneID, double> trk_tick2;
181 std::map<geo::PlaneID, double> trk_wire2;
183 for (
auto iPlane = geom->begin_plane_id(); iPlane != geom->end_plane_id(); ++iPlane){
184 trk_tick1[*iPlane] = detprop->ConvertXToTicks(pfpStart[0], *iPlane);
185 trk_wire1[*iPlane] = geom->WireCoordinate(pfpStart[1], pfpStart[2], *iPlane);
186 trk_tick2[*iPlane] = detprop->ConvertXToTicks(pfpPt2[0], *iPlane);
187 trk_wire2[*iPlane] = geom->WireCoordinate(pfpPt2[1], pfpPt2[2], *iPlane);
190 for (
size_t j = 0; j < clusterlist.size(); ++j) {
191 std::vector< art::Ptr<recob::Hit> > cls_hitlist = cls_fm.at(clusterlist[j].key());
193 if (clusterlist[j]->ID() > 0 && cls_hitlist.size() > 10)
continue;
194 if (cls_hitlist.size() > 50)
continue;
196 bool isGoodCluster =
false;
199 for (
size_t k = 0; k < allpfps[i].clsIDs.size(); ++k) {
200 if (allpfps[i].clsIDs[k] == clusterlist[j]->ID()) skipit =
true;
202 if (skipit)
continue;
204 for (
size_t jj = 0; jj < cls_hitlist.size(); ++jj) {
205 int isGoodHit =
goodHit(cls_hitlist[jj], maxDist, minDistVert, trk_wire1, trk_tick1, trk_wire2, trk_tick2);
207 if (isGoodHit == -1) {
208 isGoodCluster =
false;
211 else if (isGoodHit == 1) {
212 isGoodCluster =
true;
219 for (
size_t jj = 0; jj < cls_hitlist.size(); ++jj) {
222 int showerHitPullAdd = 0;
223 goodHit(cls_hitlist[jj], maxDist, minDistVert, trk_wire1, trk_tick1, trk_wire2, trk_tick2, showerHitPullAdd);
224 showerHitPull += showerHitPullAdd;
233 showerHitPull /= nShowerHits;
235 std::cout <<
"shower hits " <<
showerHits.size() <<
" " << nShowerHits <<
" shower pull " << showerHitPull << std::endl;
237 if (nShowerHits > tolerance && std::abs(showerHitPull) < pullTolerance) {
238 showerCandidate =
true;
239 std::cout <<
"SHOWER CANDIDATE" << std::endl;
241 if (nShowerHits > 400) maxDist *= 2;
242 for (
size_t k = 0; k < hitlist.size(); ++k) {
243 std::vector< art::Ptr<recob::Cluster> > hit_clslist = hitcls_fm.at(hitlist[k].key());
244 if (hit_clslist.size())
continue;
246 int isGoodHit =
goodHit(hitlist[k], maxDist*2, minDistVert*2, trk_wire1, trk_tick1, trk_wire2, trk_tick2);
251 for (
size_t k = 0; k < clusterlist.size(); ++k) {
252 std::vector< art::Ptr<recob::Hit> > cls_hitlist = cls_fm.at(clusterlist[k].key());
254 if (clusterlist[k]->ID() > 0 && cls_hitlist.size() > 50)
continue;
256 double thisDist = maxDist;
257 double thisMin = minDistVert;
259 if (cls_hitlist.size() < 10) {
263 else if (cls_hitlist.size() < 30) thisDist *= 2;
269 for (
size_t kk = 0; kk < cls_hitlist.size(); ++kk) {
271 int isGoodHit =
goodHit(cls_hitlist[kk], thisDist, thisMin, trk_wire1, trk_tick1, trk_wire2, trk_tick2);
272 if (isGoodHit == -1){
276 else if (isGoodHit == 1) {
281 double fracGood = (double)ngoodhits/nhits;
283 bool isGoodTrack = fracGood > 0.4;
286 for (
size_t kk = 0; kk < cls_hitlist.size(); ++kk) {
361 if (showerCandidate) {
362 std::cout <<
"THIS IS THE SHOWER PFP: " << allpfps[i].pfp->Self() + 1 << std::endl;
368 if (showerCandidate)
return 1;
378 int TCShowerAlg::goodHit(
art::Ptr<recob::Hit> hit,
double maxDist,
double minDistVert, std::map<geo::PlaneID, double> trk_wire1, std::map<geo::PlaneID, double> trk_tick1, std::map<geo::PlaneID, double> trk_wire2, std::map<geo::PlaneID, double> trk_tick2){
381 return goodHit(hit, maxDist, minDistVert, trk_wire1, trk_tick1, trk_wire2, trk_tick2, pull);
390 int TCShowerAlg::goodHit(
art::Ptr<recob::Hit> hit,
double maxDist,
double minDistVert, std::map<geo::PlaneID, double> trk_wire1, std::map<geo::PlaneID, double> trk_tick1, std::map<geo::PlaneID, double> trk_wire2, std::map<geo::PlaneID, double> trk_tick2,
int& pull){
392 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
396 double tickToDist = detprop->DriftVelocity(detprop->Efield(),detprop->Temperature());
397 tickToDist *= 1.e-3 * detprop->SamplingRate();
398 double UnitsPerTick = tickToDist / wirePitch;
401 double y0 = hit->
PeakTime() * UnitsPerTick;
403 double x1 = trk_wire1[hit->
WireID()];
404 double y1 = trk_tick1[hit->
WireID()] * UnitsPerTick;
406 double x2 = trk_wire2[hit->
WireID()];
407 double y2 = trk_tick2[hit->
WireID()] * UnitsPerTick;
409 double distToVert = std::sqrt( pow(x0 - x1, 2) + pow(y0 - y1, 2) );
410 if (distToVert < minDistVert)
return -1;
413 if (distToVert < 50) maxDist /= 4;
414 else if (distToVert < 100) maxDist /= 2;
418 double a = std::sqrt( pow(x2 - x1, 2) + pow(y2 - y1, 2) );
419 double b = std::sqrt( pow(x0 - x1, 2) + pow(y0 - y1, 2) );
420 double c = std::sqrt( pow(x0 - x2, 2) + pow(y0 - y2, 2) );
421 double costheta = -( pow(c,2) - pow(a,2) - pow(b,2) ) / (2 * a * b);
422 if (costheta < 0)
return -1;
424 double dist = std::abs((y2-y1)*x0 - (x2-x1)*y0 + x2*y1 - y2*x1)/std::sqrt( pow((y2-y1), 2) + pow((x2-x1), 2) );
426 if (dist < maxDist) {
427 if ( ( (y2-y1)*x0 - (x2-x1)*y0 + x2*y1 - y2*x1) > 0) pull = 1;
440 for (
size_t i = 0; i < showerhits.size(); ++i) {
441 if ( hit.
key() == showerhits[i].key() )
return false;
WireID const & asWireID() const
Conversion to WireID (for convenience of notation).
std::vector< double > totalEnergyErr
std::vector< art::Ptr< recob::Hit > > hits
size_t Self() const
Returns the index of this particle.
Float_t y1[n_points_granero]
int goodHit(art::Ptr< recob::Hit >, double maxDist, double minDistVert, std::map< geo::PlaneID, double > trk_wire1, std::map< geo::PlaneID, double > trk_tick1, std::map< geo::PlaneID, double > trk_wire2, std::map< geo::PlaneID, double > trk_tick2)
geo::WireID WireID() const
Initial tdc tick for hit.
Float_t x1[n_points_granero]
std::vector< double > dEdx
bool addShowerHit(art::Ptr< recob::Hit > hit, std::vector< art::Ptr< recob::Hit > > showerhits)
art::Ptr< recob::PFParticle > pfp
std::vector< art::Ptr< recob::Hit > > showerHits
The data type to uniquely identify a Plane.
Vector_t VertexDirection() const
Access to track direction at different points.
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.
Float_t y2[n_points_geant4]
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
art::Ptr< recob::Vertex > vtx
bool comparePFP(const pfpStuff &l, const pfpStuff &r)
Point_t const & Vertex() const
Access to track position at different points.
Detector simulation of raw signals on wires.
std::vector< int > clsIDs
float PeakTime() const
Time of the signal peak, in tick units.
bool compareHit(const art::Ptr< recob::Hit > &l, const art::Ptr< recob::Hit > &r)
Vector_t EndDirection() const
Access to track direction at different points.
int ID() const
Return vertex id.
art::Ptr< recob::Track > trk
std::vector< double > totalEnergy
Point_t const & End() const
Access to track position at different points.
int makeShowers(std::vector< art::Ptr< recob::PFParticle > > pfplist, std::vector< art::Ptr< recob::Vertex > > vertexlist, std::vector< art::Ptr< recob::Cluster > > clusterlist, std::vector< art::Ptr< recob::Hit > > hitlist, art::FindManyP< recob::Hit > cls_fm, art::FindManyP< recob::Cluster > clspfp_fm, art::FindManyP< recob::Vertex > vtxpfp_fm, art::FindManyP< recob::PFParticle > hit_fm, art::FindManyP< recob::Cluster > hitcls_fm, art::FindManyP< recob::Track > trkpfp_fm, art::FindManyP< anab::Calorimetry > fmcal)
Float_t x2[n_points_geant4]
std::vector< double > dEdxErr
const Point_t & position() const
Return vertex 3D position.