42 #include "TLorentzVector.h" 43 #include "TMathBase.h" 47 class MergeEMShower3D;
50 class ShowersCollection;
58 double Angleto(TVector3
const& pmapoint)
const;
113 bool isplane =
false;
114 unsigned int nplanes = geom->
Nplanes();
115 for (
unsigned int p = 0; p < nplanes; ++p)
120 {
fPlaneId = int(p); isplane =
true;}
133 double th0 = 180.0F * (std::acos(cosine0)) / TMath::Pi();
135 std::vector< std::pair<TVector3, TVector3> > lines;
136 lines.push_back(std::pair<TVector3, TVector3>(this->
fFront, this->
fFront + this->
fDir));
137 lines.push_back(std::pair<TVector3, TVector3>(s1.
fFront, s1.
fFront + s1.
fDir));
143 double th1 = 180.0F * (std::acos(cosine1)) / TMath::Pi();
146 if (th1 < th0) thmin = th1;
153 double cosine = (pmapoint - this->
fFront) * (1.0 / (pmapoint - this->
fFront).Mag()) * this->
fDir;
154 double th = 180.0F * (std::acos(cosine)) / TMath::Pi();
160 public std::binary_function<const ems::ShowerInfo&, const ems::ShowerInfo&, bool>
178 double Angle(TVector3 p0, TVector3
test);
180 double Angle(TVector3 test);
182 size_t Size() {
return fParts.size();}
184 std::vector< ShowerInfo >
const &
GetParts(
void)
const {
return fParts; }
191 std::vector<double> DeDx(
void);
192 std::vector<double> TotEn(
void);
222 else return TVector3(0, 0, 0);
228 else return TVector3(0, 0, 0);
234 else return std::vector<double>(0.0);
239 std::vector<double> en;
241 double enkU = 0.0;
double enkV = 0.0;
double enkZ = 0.0;
242 for (
size_t i = 0; i <
fParts.size(); ++i)
244 std::vector<double> showeren =
fParts[i].GetEnTot();
260 p0 *= 1.0 / p0.Mag();
262 test *= 1.0 / test.Mag();
263 double c = p0 *
test;
264 if (c > 1.0) c = 1.0;
265 return 180.0 * acos(c) / TMath::Pi();
271 test *= 1.0 / test.Mag();
273 if (c > 1.0) c = 1.0;
274 return 180.0 * acos(c) / TMath::Pi();
280 double a, a_min = 360.0;
281 for (
size_t i = 0; i <
fParts.size(); ++i)
285 if (a < a_min) a_min = a;
292 for (
size_t i = 0; i < col2.
fParts.size(); ++i)
293 for (
size_t j = 0; j <
fParts.size(); ++j)
300 for (
size_t i = 0; i < col2.
fParts.size(); ++i)
309 for (
auto const & p :
fParts)
310 if (p.GetGid() != src.
GetGid())
343 int getGammaId(
art::Event & evt,
const size_t t);
349 std::vector< ems::ShowersCollection > collectshowers(
art::Event & evt, std::vector< ems::ShowerInfo > & showers,
bool refpoint);
351 TVector3 getBestPoint(
352 const std::vector<recob::Track>& tracks,
353 const std::vector< ShowerInfo >& showers,
354 const TVector3& p0,
const TVector3& p1,
390 : fShowerEnergyAlg(p.get<
fhicl::ParameterSet>(
"ShowerEnergyAlg"))
394 produces< std::vector<recob::Shower> >();
395 produces< std::vector<recob::Vertex> >();
397 produces< art::Assns<recob::Shower, recob::Vertex> >();
398 produces< art::Assns<recob::Shower, recob::Cluster> >();
399 produces< art::Assns<recob::Shower, recob::Hit> >();
406 fEvTree = tfs->
make<TTree>(
"ShowerTestEv",
"pi0 tests");
436 std::unique_ptr< std::vector< recob::Shower > > cascades(
new std::vector< recob::Shower >);
437 std::unique_ptr< std::vector< recob::Vertex > > vertices(
new std::vector< recob::Vertex >);
443 std::vector< ShowersCollection > gammawithconv;
465 std::vector< ShowerInfo > showers;
466 for (
size_t t = 0; t < trkListHandle->size(); ++t)
470 auto src_clu_list = cluFromTrk.at(t);
472 std::vector<double> ensum(3, 0.0);
474 for (
size_t c = 0; c < src_clu_list.size(); ++c)
476 std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
479 if (src_clu_list[c]->View() ==
geo::kU) { ensum[0] += adcsum; }
480 else if (src_clu_list[c]->View() ==
geo::kV) { ensum[1] += adcsum; }
481 else if (src_clu_list[c]->View() ==
geo::kZ) { ensum[2] += adcsum; }
484 auto cnv = vtxFromTrk.at(t);
489 showers.push_back(si);
495 showers.push_back(si);
499 fNTot = showers.size();
506 std::vector< ShowerInfo > pmaseg;
507 for (
size_t i = 0; i < showers.size(); ++i)
508 if (!showers[i].HasConPoint())
509 pmaseg.push_back(showers[i]);
511 fNPMA = pmaseg.size();
515 if (gammawithconv.size())
516 for (
size_t i = 0; i < pmaseg.size(); i++)
518 double a_min = bigcone;
size_t best = 0;
519 for (
size_t j = 0; j < gammawithconv.size(); j++)
521 TVector3 halfpoint = (pmaseg[i].GetFront() + pmaseg[i].GetEnd()) * 0.5;
522 double a = gammawithconv[j].first.Angleto(halfpoint);
529 gammawithconv[best].Merge(pmaseg[i]);
535 for (
size_t i = 0; i < gammawithconv.size(); ++i)
539 if (gammawithconv.size() == 2)
541 fNParts[0] = gammawithconv[0].Size();
542 fNParts[1] = gammawithconv[1].Size();
549 for (
size_t i = 0; i < gammawithconv.size(); ++i)
552 TVector3 v0(0., 0., 0.);
553 TVector3
dir = gammawithconv[i].Dir();
554 TVector3 front = gammawithconv[i].Front();
556 std::vector<double> dedx = gammawithconv[i].DeDx();
557 std::vector< double > vd;
560 vd, vd, dedx, vd, gammawithconv[i].PlaneId(),
id);
563 std::vector< art::Ptr<recob::Cluster> > cls;
564 std::vector< art::Ptr<recob::Hit> >
hits;
565 for (
size_t p = 0; p < gammawithconv[i].Size(); p++)
567 int trkKey = gammawithconv[i].GetParts()[p].GetKey();
568 auto src_clu_list = cluFromTrk.at(trkKey);
570 for (
size_t c = 0; c < src_clu_list.size(); c++)
572 cls.push_back(src_clu_list[c]);
574 auto v = hitFromClu.at(src_clu_list[c].key());
575 for (
size_t h = 0; h < v.size(); h++) hits.push_back(v[h]);
578 auto ver_list = vtxFromTrk.at(trkKey);
581 std::vector<double> totE;
582 std::vector<double> totEerr;
583 for (
int i = 0; i<3; ++i){
585 totEerr.push_back(0);
589 cascades->push_back(cas);
591 double vtx_pos[3] = {front.X(), front.Y(), front.Z()};
595 if (vertices->size())
597 size_t vtx_idx = (size_t)(vertices->size() - 1);
598 util::CreateAssn(*
this, evt, *cascades, *vertices, *shs2vtx, vtx_idx, vtx_idx + 1);
608 evt.
put(std::move(cascades));
609 evt.
put(std::move(vertices));
611 evt.
put(std::move(shs2vtx));
612 evt.
put(std::move(shs2cl));
613 evt.
put(std::move(shs2hit));
618 std::vector< ems::ShowersCollection > gammawithconv;
630 TVector3 geoP0(dsize[0], dsize[2], dsize[4]), geoP1(dsize[1], dsize[3], dsize[5]);
631 TVector3 pov =
getBestPoint(*trkListHandle, showers, geoP0, geoP1, 5.0);
634 for (
size_t is = 0; is < showers.size(); is++)
635 showers[is].SetP0Dist(pov);
638 for (
size_t is = 0; is < showers.size(); is++)
641 double a, a_min = 360.0;
642 for (
size_t m = 0; m < gammawithconv.size(); ++m)
644 a = gammawithconv[m].Angle(showers[is].GetFront());
647 m_idx = m; a_min = a;
650 std::vector< std::pair<TVector3, TVector3> > lines;
651 lines.push_back(std::pair<TVector3, TVector3>(
652 showers[is].GetFront(), showers[is].GetFront() + showers[is].GetDir()));
653 lines.push_back(std::pair<TVector3, TVector3>(
654 gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir()));
659 gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir());
663 a = gammawithconv[m].Angle(isect);
666 m_idx = m; a_min = a;
672 gammawithconv[m_idx].Merge(showers[is]);
674 else if (showers[is].HasConPoint())
677 gammawithconv.push_back(sc);
685 for (
size_t i = 0; i < showers.size(); ++i)
686 if (showers[i].HasConPoint())
689 gammawithconv.push_back(sc);
692 fNConv = gammawithconv.size();
697 while (i < gammawithconv.size())
699 size_t best = 0;
double a_min = smallcone;
700 for (
size_t j = 0; j < gammawithconv.size(); j++)
703 double a = gammawithconv[i].MinAngle(gammawithconv[j]);
706 a_min = a; best = j; merge =
true;
711 gammawithconv[i].Merge(gammawithconv[best]);
712 gammawithconv.erase(gammawithconv.begin() + best);
719 return gammawithconv;
727 std::map< int, size_t > ids;
731 if (hid.size()) ids[hid.front().trackID]++;
738 if ((p.second > (
int)(0.8 * v.size())) && (p.second >
max))
740 max = p.second; best_id = p.first;
752 std::vector< art::Ptr<simb::MCTruth> > mclist;
753 if (evt.
getByLabel(
"generator", mctruthListHandle))
758 size_t np = mclist[0]->NParticles();
759 for (
size_t i = 0; i < np; ++i)
760 if (mclist[0]->GetParticle(i).PdgCode() == 111)
761 {pi0_idx = i;
break;}
765 if (pi0_idx < 0)
return;
768 TVector3 pi0_vtx(pi0.
Vx(), pi0.
Vy(), pi0.
Vz());
776 int cid = 0, gid = 0;
790 auto src_clu_list = cluFromTrk.at(t);
791 for (
size_t c = 0; c < src_clu_list.size(); ++c)
793 std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
797 if ((
fWhat == 0) && (gid == 0)) gid = cid;
802 if (
fWhat == 0)
return gid;
807 const std::vector< recob::Track >& tracks,
808 const std::vector< ShowerInfo >& showers,
809 const TVector3& p0,
const TVector3& p1,
double step)
813 double f, fmin = 1.0e10;
830 TVector3 mid(0., 0., 0.);
832 p.SetXYZ(x0, y0, z0);
833 for (
size_t t = 0; t < tracks.size(); t++)
836 auto const &
trk = tracks[t];
838 double cos = -acos(
getCos3D(p,
trk) ) / (0.5*TMath::Pi());
841 if (showers[t].HasConPoint()) cos *= 3.0;
842 cos *= sqrt( showers[t].GetAdcSum() );
844 mid += 0.5 * (
trk.Vertex() +
trk.End());
884 if (c > 1.0) c = 1.0;
895 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.
const double & DQdxAtPoint(unsigned int p, geo::View_t view=geo::kUnknown) const
Covariance matrices are either set or not.
double Dist2(const TVector2 &v1, const TVector2 &v2)
TVector3 VertexDirection() const
Covariance matrices are either set or not.
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
TVector3 GetEnd(void) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
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
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
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
#define DEFINE_ART_MODULE(klass)
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
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.
Provides recob::Track data product.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
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)
TVector3 Vertex() const
Covariance matrices are either set or not.
double Vz(const int i=0) const
EventNumber_t event() const
std::vector< ShowerInfo > fParts
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)
TVector3 End() const
Covariance matrices are either set or not.
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