42 #include "TLorentzVector.h" 43 #include "TMathBase.h" 47 class MergeEMShower3D;
50 class ShowersCollection;
58 double Angleto(TVector3
const& pmapoint)
const;
146 double th0 = 180.0F * (std::acos(cosine0)) / TMath::Pi();
148 std::vector< std::pair<TVector3, TVector3> > lines;
149 lines.push_back(std::pair<TVector3, TVector3>(this->
fFront, this->
fFront + this->
fDir));
150 lines.push_back(std::pair<TVector3, TVector3>(s1.
fFront, s1.
fFront + s1.
fDir));
156 double th1 = 180.0F * (std::acos(cosine1)) / TMath::Pi();
159 if (th1 < th0) thmin = th1;
166 double cosine = (pmapoint - this->
fFront) * (1.0 / (pmapoint - this->
fFront).Mag()) * this->
fDir;
167 double th = 180.0F * (std::acos(cosine)) / TMath::Pi();
173 public std::binary_function<const ems::ShowerInfo&, const ems::ShowerInfo&, bool>
191 double Angle(TVector3 p0, TVector3
test);
193 double Angle(TVector3 test);
195 size_t Size() {
return fParts.size();}
197 std::vector< ShowerInfo >
const &
GetParts(
void)
const {
return fParts; }
204 std::vector<double> DeDx(
void);
205 std::vector<double> TotEn(
void);
235 else return TVector3(0, 0, 0);
241 else return TVector3(0, 0, 0);
247 else return std::vector<double>(0.0);
252 std::vector<double> en;
254 double enkU = 0.0;
double enkV = 0.0;
double enkZ = 0.0;
255 for (
size_t i = 0; i <
fParts.size(); ++i)
257 std::vector<double> showeren =
fParts[i].GetEnTot();
273 p0 *= 1.0 / p0.Mag();
275 test *= 1.0 / test.Mag();
276 double c = p0 *
test;
277 if (c > 1.0) c = 1.0;
278 return 180.0 * acos(c) / TMath::Pi();
284 test *= 1.0 / test.Mag();
286 if (c > 1.0) c = 1.0;
287 return 180.0 * acos(c) / TMath::Pi();
293 double a, a_min = 360.0;
294 for (
size_t i = 0; i <
fParts.size(); ++i)
298 if (a < a_min) a_min = a;
305 for (
size_t i = 0; i < col2.
fParts.size(); ++i)
306 for (
size_t j = 0; j <
fParts.size(); ++j)
313 for (
size_t i = 0; i < col2.
fParts.size(); ++i)
322 for (
auto const & p :
fParts)
323 if (p.GetGid() != src.
GetGid())
356 int getGammaId(
art::Event & evt,
const size_t t);
362 std::vector< ems::ShowersCollection > collectshowers(
art::Event & evt, std::vector< ems::ShowerInfo > & showers,
bool refpoint);
364 TVector3 getBestPoint(
365 const std::vector<recob::Track>& tracks,
366 const std::vector< ShowerInfo >& showers,
367 const TVector3& p0,
const TVector3& p1,
403 : fShowerEnergyAlg(p.get<
fhicl::ParameterSet>(
"ShowerEnergyAlg"))
407 produces< std::vector<recob::Shower> >();
408 produces< std::vector<recob::Vertex> >();
410 produces< art::Assns<recob::Shower, recob::Vertex> >();
411 produces< art::Assns<recob::Shower, recob::Cluster> >();
412 produces< art::Assns<recob::Shower, recob::Hit> >();
419 fEvTree = tfs->
make<TTree>(
"ShowerTestEv",
"pi0 tests");
449 std::unique_ptr< std::vector< recob::Shower > > cascades(
new std::vector< recob::Shower >);
450 std::unique_ptr< std::vector< recob::Vertex > > vertices(
new std::vector< recob::Vertex >);
456 std::vector< ShowersCollection > gammawithconv;
478 std::vector< ShowerInfo > showers;
479 for (
size_t t = 0; t < trkListHandle->size(); ++t)
483 auto src_clu_list = cluFromTrk.at(t);
485 std::vector<double> ensum(3, 0.0);
487 for (
size_t c = 0; c < src_clu_list.size(); ++c)
489 std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
492 if (src_clu_list[c]->View() ==
geo::kU) { ensum[0] += adcsum; }
493 else if (src_clu_list[c]->View() ==
geo::kV) { ensum[1] += adcsum; }
494 else if (src_clu_list[c]->View() ==
geo::kZ) { ensum[2] += adcsum; }
497 auto cnv = vtxFromTrk.at(t);
502 showers.push_back(si);
508 showers.push_back(si);
512 fNTot = showers.size();
519 std::vector< ShowerInfo > pmaseg;
520 for (
size_t i = 0; i < showers.size(); ++i)
521 if (!showers[i].HasConPoint())
522 pmaseg.push_back(showers[i]);
524 fNPMA = pmaseg.size();
528 if (gammawithconv.size())
529 for (
size_t i = 0; i < pmaseg.size(); i++)
531 double a_min = bigcone;
size_t best = 0;
532 for (
size_t j = 0; j < gammawithconv.size(); j++)
534 TVector3 halfpoint = (pmaseg[i].GetFront() + pmaseg[i].GetEnd()) * 0.5;
535 double a = gammawithconv[j].first.Angleto(halfpoint);
542 gammawithconv[best].Merge(pmaseg[i]);
548 for (
size_t i = 0; i < gammawithconv.size(); ++i)
552 if (gammawithconv.size() == 2)
554 fNParts[0] = gammawithconv[0].Size();
555 fNParts[1] = gammawithconv[1].Size();
562 for (
size_t i = 0; i < gammawithconv.size(); ++i)
565 TVector3 v0(0., 0., 0.);
566 TVector3
dir = gammawithconv[i].Dir();
567 TVector3 front = gammawithconv[i].Front();
569 std::vector<double> dedx = gammawithconv[i].DeDx();
570 std::vector< double > vd;
573 vd, vd, dedx, vd, gammawithconv[i].PlaneId(),
id);
576 std::vector< art::Ptr<recob::Cluster> > cls;
577 std::vector< art::Ptr<recob::Hit> >
hits;
578 for (
size_t p = 0; p < gammawithconv[i].Size(); p++)
580 int trkKey = gammawithconv[i].GetParts()[p].GetKey();
581 auto src_clu_list = cluFromTrk.at(trkKey);
583 for (
size_t c = 0; c < src_clu_list.size(); c++)
585 cls.push_back(src_clu_list[c]);
587 auto v = hitFromClu.at(src_clu_list[c].key());
588 for (
size_t h = 0; h < v.size(); h++) hits.push_back(v[h]);
591 auto ver_list = vtxFromTrk.at(trkKey);
594 std::vector<double> totE;
595 std::vector<double> totEerr;
596 for (
int i = 0; i<3; ++i){
598 totEerr.push_back(0);
602 cascades->push_back(cas);
604 double vtx_pos[3] = {front.X(), front.Y(), front.Z()};
608 if (vertices->size())
610 size_t vtx_idx = (size_t)(vertices->size() - 1);
611 util::CreateAssn(*
this, evt, *cascades, *vertices, *shs2vtx, vtx_idx, vtx_idx + 1);
621 evt.
put(std::move(cascades));
622 evt.
put(std::move(vertices));
624 evt.
put(std::move(shs2vtx));
625 evt.
put(std::move(shs2cl));
626 evt.
put(std::move(shs2hit));
631 std::vector< ems::ShowersCollection > gammawithconv;
643 TVector3 geoP0(dsize[0], dsize[2], dsize[4]), geoP1(dsize[1], dsize[3], dsize[5]);
644 TVector3 pov =
getBestPoint(*trkListHandle, showers, geoP0, geoP1, 5.0);
647 for (
size_t is = 0; is < showers.size(); is++)
648 showers[is].SetP0Dist(pov);
651 for (
size_t is = 0; is < showers.size(); is++)
654 double a, a_min = 360.0;
655 for (
size_t m = 0; m < gammawithconv.size(); ++m)
657 a = gammawithconv[m].Angle(showers[is].GetFront());
660 m_idx = m; a_min = a;
663 std::vector< std::pair<TVector3, TVector3> > lines;
664 lines.push_back(std::pair<TVector3, TVector3>(
665 showers[is].GetFront(), showers[is].GetFront() + showers[is].GetDir()));
666 lines.push_back(std::pair<TVector3, TVector3>(
667 gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir()));
672 gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir());
676 a = gammawithconv[m].Angle(isect);
679 m_idx = m; a_min = a;
685 gammawithconv[m_idx].Merge(showers[is]);
687 else if (showers[is].HasConPoint())
690 gammawithconv.push_back(sc);
698 for (
size_t i = 0; i < showers.size(); ++i)
699 if (showers[i].HasConPoint())
702 gammawithconv.push_back(sc);
705 fNConv = gammawithconv.size();
710 while (i < gammawithconv.size())
712 size_t best = 0;
double a_min = smallcone;
713 for (
size_t j = 0; j < gammawithconv.size(); j++)
716 double a = gammawithconv[i].MinAngle(gammawithconv[j]);
719 a_min = a; best = j; merge =
true;
724 gammawithconv[i].Merge(gammawithconv[best]);
725 gammawithconv.erase(gammawithconv.begin() + best);
732 return gammawithconv;
740 std::map< int, size_t > ids;
744 if (hid.size()) ids[hid.front().trackID]++;
751 if ((p.second > (
int)(0.8 * v.size())) && (p.second >
max))
753 max = p.second; best_id = p.first;
765 std::vector< art::Ptr<simb::MCTruth> > mclist;
766 if (evt.
getByLabel(
"generator", mctruthListHandle))
771 size_t np = mclist[0]->NParticles();
772 for (
size_t i = 0; i < np; ++i)
773 if (mclist[0]->GetParticle(i).PdgCode() == 111)
774 {pi0_idx = i;
break;}
778 if (pi0_idx < 0)
return;
781 TVector3 pi0_vtx(pi0.
Vx(), pi0.
Vy(), pi0.
Vz());
789 int cid = 0, gid = 0;
803 auto src_clu_list = cluFromTrk.at(t);
804 for (
size_t c = 0; c < src_clu_list.size(); ++c)
806 std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
810 if ((
fWhat == 0) && (gid == 0)) gid = cid;
815 if (
fWhat == 0)
return gid;
820 const std::vector< recob::Track >& tracks,
821 const std::vector< ShowerInfo >& showers,
822 const TVector3& p0,
const TVector3& p1,
double step)
826 double f, fmin = 1.0e10;
843 TVector3 mid(0., 0., 0.);
845 p.SetXYZ(x0, y0, z0);
846 for (
size_t t = 0; t < tracks.size(); t++)
849 auto const &
trk = tracks[t];
851 double cos = -acos(
getCos3D(p,
trk) ) / (0.5*TMath::Pi());
854 if (showers[t].HasConPoint()) cos *= 3.0;
855 cos *= sqrt( showers[t].GetAdcSum() );
857 mid += 0.5 * (
trk.Vertex<TVector3>() +
trk.End<TVector3>());
887 p1 = trk.
Vertex<TVector3>();
889 p1 = trk.
End<TVector3>();
897 if (c > 1.0) c = 1.0;
908 sum += ptr->SummedADC();
double ShowerEnergy(std::vector< art::Ptr< recob::Hit > > const &hits, int plane)
Finds the total energy deposited by the shower in this view.
void reconfigure(fhicl::ParameterSet const &p)
TVector3 GetDir(void) const
yes & test(std::ostream &)
Implementation of the Projection Matching Algorithm.
double Dist2(const TVector2 &v1, const TVector2 &v2)
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
TVector3 GetEnd(void) const
double Pointsto(ems::ShowerInfo const &s1) const
ShowersCollection(ShowerInfo const &part)
Declaration of signal hit object.
void set_total_energy(const std::vector< double > &q)
std::string fTrk3DModuleLabel
Vector_t VertexDirection() const
Access to track direction at different points.
Planes which measure Z direction.
double GetP0Dist(void) const
shower::ShowerEnergyAlg fShowerEnergyAlg
std::vector< double > fVentot
std::vector< double > GetDedx(void) const
ShowerInfo(int key, int gid, bool hasvtx, std::vector< double > vensum, recob::Track const &trk)
Definition of vertex object for LArSoft.
void set_total_energy_err(const std::vector< double > &q)
double getCos3D(const TVector3 &p0, const recob::Track &trk)
void CryostatBoundaries(double *boundaries, geo::CryostatID const &cid) const
Returns the boundaries of the specified cryostat.
int getGammaId(art::Event &evt, const size_t t)
ProductID put(std::unique_ptr< PROD > &&product)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
int getClusterBestId(const std::vector< art::Ptr< recob::Hit > > &v)
double Angleto(TVector3 const &pmapoint) const
std::string fCluModuleLabel
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
double MinAngle(ShowersCollection const &col2)
TVector2 GetProjectionToSegment(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
std::string fHitsModuleLabel
double P(const int i=0) const
T get(std::string const &key) const
Point_t const & Vertex() const
Access to track position at different points.
std::vector< ShowerInfo > const & GetParts(void) const
std::vector< ems::ShowersCollection > collectshowers(art::Event &evt, std::vector< ems::ShowerInfo > &showers, bool refpoint)
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.
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 > > &lines, TVector3 &result)
std::vector< double > DeDx(void)
void mcinfo(art::Event &evt)
std::string fVtxModuleLabel
double Angle(TVector3 p0, TVector3 test)
Declaration of cluster object.
std::vector< double > fVdqdx
double GetAdcSum(void) const
TVector3 getBestPoint(const std::vector< recob::Track > &tracks, const std::vector< ShowerInfo > &showers, const TVector3 &p0, const TVector3 &p1, double step)
MergeEMShower3D(fhicl::ParameterSet const &p)
double Vx(const int i=0) const
Implementation of the Projection Matching Algorithm.
T * make(ARGS...args) const
Utility object to perform functions of association.
int GetPlaneId(void) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
void Merge(ShowersCollection const &col2)
double Vz(const int i=0) const
EventNumber_t event() const
std::vector< ShowerInfo > fParts
Point_t const & End() const
Access to track position at different points.
double getClusterAdcSum(const std::vector< art::Ptr< recob::Hit > > &v)
void SetP0Dist(const TVector3 p)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TVector3 GetFront(void) const
std::vector< double > TotEn(void)
bool HasConPoint(void) const
double Vy(const int i=0) const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
std::vector< double > GetEnTot(void) const
void produce(art::Event &e) override