15 #include "art_root_io/TFileService.h" 38 #include "TTimeStamp.h" 74 TLorentzVector
const & pvtx);
77 const size_t cryo,
const size_t tpc,
const size_t plane)
const;
78 TVector2
getMCdir2d(TVector3
const & mcvtx3d, TVector3
const & mcdir3d,
79 const size_t cryo,
const size_t tpc,
const size_t plane)
const;
81 std::vector< TVector3 >
findPhDir()
const;
87 std::vector< dunefd::Hit2D >
reselectCls(std::map<
size_t, std::vector< dunefd::Hit2D > >
const & cls,
89 const size_t cryo,
const size_t tpc,
const size_t plane)
const;
92 std::vector< std::vector<Hit2D> >
const & src, TVector3
const & primary);
155 produces< std::vector<recob::Track> >();
156 produces< std::vector<recob::SpacePoint> >();
157 produces< art::Assns<recob::Track, recob::Hit> >();
158 produces< art::Assns<recob::Track, recob::SpacePoint> >();
159 produces< art::Assns<recob::SpacePoint, recob::Hit> >();
167 fTree = tfs->make<TTree>(
"nueana",
"analysis tree");
172 fTree->Branch(
"dx",&
dx,
"dx/F");
181 fTree->Branch(
"cos", &
cos,
"cos/F");
188 fTree->Branch(
"t0", &
t0,
"t0/F");
201 file.open(
"data.dat");
202 file1.open(
"data1.dat");
257 std::unique_ptr< std::vector< recob::Track > >
tracks(
new std::vector< recob::Track >);
258 std::unique_ptr< std::vector< recob::SpacePoint > > allsp(
new std::vector< recob::SpacePoint >);
264 TVector3 primary(0, 0, 0);
265 bool isinside =
false;
269 std::vector<art::Ptr<simb::MCTruth> > mclist;
271 if (mctruthListHandle)
278 primary = TVector3(pvtx.X(), pvtx.Y(), pvtx.Z());
286 const sim::ParticleList& plist = pi_serv->
ParticleList();
292 TLorentzVector mom = particle->
Momentum();
293 TVector3 momvec(mom.Px(), mom.Py(), mom.Pz());
295 if ((particle->
PdgCode() == 22) && (momvec.Mag() > 0.030))
298 TLorentzVector conversion = particle->
EndPosition();
299 TVector3 convec(conversion.X(), conversion.Y(), conversion.Z());
303 if (!photon)
ngamma = -10;
330 std::vector<art::Ptr<simb::MCTruth> > mclist;
332 if (mctruthListHandle)
351 std::vector<art::Ptr<recob::Hit> > hitlist;
357 std::vector<art::Ptr<recob::Track> > tracklist;
363 std::vector<art::Ptr<recob::Vertex> > vtxlist;
369 std::vector<art::Ptr<simb::MCTruth> > mclist;
371 if (mctruthListHandle)
379 const TLorentzVector& pvtx = particle.
Position();
380 TVector3 primary(pvtx.X(), pvtx.Y(), pvtx.Z());
383 TVector3 closestvtx; TVector3 minzvtx;
386 double xyz[3] = {0.0, 0.0, 0.0};
387 vtxlist[0]->XYZ(xyz);
388 float vxreco = xyz[0];
389 if (vxreco > 0) vxreco -=
t0Corr(evt, detProp, pvtx);
390 else vxreco +=
t0Corr(evt, detProp, pvtx);
393 TVector3 vtxreco(xyz);
394 vtxreco.SetXYZ(xyz[0], xyz[1], xyz[2]);
395 closestvtx.SetXYZ(xyz[0], xyz[1], xyz[2]);
397 double mindist2 =
pma::Dist2(primary, vtxreco);
399 for (
size_t v = 1; v < vtxlist.size(); ++v)
401 vtxlist[v]->XYZ(xyz);
403 if (temp > 0) temp -=
t0Corr(evt, detProp, pvtx);
404 else temp +=
t0Corr(evt, detProp, pvtx);
407 vtxreco.SetXYZ(xyz[0], xyz[1], xyz[2]);
409 if (dist2 < mindist2)
411 closestvtx.SetXYZ(xyz[0], xyz[1], xyz[2]);
417 double minz_xyz[3] = {0.0, 0.0, 0.0};
419 for (
size_t v = 0; v < vtxlist.size(); ++v)
421 vtxlist[v]->XYZ(minz_xyz);
422 float temp = minz_xyz[0];
423 if (temp > 0) temp -=
t0Corr(evt, detProp, pvtx);
424 else temp +=
t0Corr(evt, detProp, pvtx);
427 if (minz_xyz[2] < minz)
430 minzvtx.SetXYZ(minz_xyz[0], minz_xyz[1], minz_xyz[2]);
435 for (
size_t t = 0;
t < tracklist.size(); ++
t)
437 if (!tracklist[
t]->NumberTrajectoryPoints())
continue;
438 TVector3 pos_p = tracklist[
t]->LocationAtPoint<TVector3>(0);
440 float temp = pos_p.X();
441 if (temp > 0) temp -=
t0Corr(evt, detProp, pvtx);
442 else temp +=
t0Corr(evt, detProp, pvtx);
446 if (dist2 < mindist2)
448 closestvtx.SetXYZ(pos_p.X(), pos_p.Y(), pos_p.Z());
452 if (pos_p.Z() < minzvtx.Z())
454 minzvtx.SetXYZ(pos_p.X(), pos_p.Y(), pos_p.Z());
457 TVector3 pos_end = tracklist[
t]->LocationAtPoint<TVector3>(tracklist[
t]->NumberTrajectoryPoints()-1);
459 if (temp > 0) temp -=
t0Corr(evt, detProp, pvtx);
460 else temp +=
t0Corr(evt, detProp, pvtx);
464 if (dist2 < mindist2)
466 closestvtx.SetXYZ(pos_end.X(), pos_end.Y(), pos_end.Z());
470 if (pos_end.Z() < minzvtx.Z())
472 minzvtx.SetXYZ(pos_end.X(), pos_end.Y(), pos_end.Z());
491 TVector3 mcvtx3d(pvtx.X(), pvtx.Y(), pvtx.Z());
492 std::vector< TVector3 > mcdir3d =
findPhDir();
494 float minlep_dist = 9999;
495 for (
size_t v = 0; v < mcdir3d.size(); ++v)
507 std::vector< art::Ptr<recob::Hit> > recoinihit = fb.at(recotrack.
key());
513 float px = pos_p.X();
514 if (px > 0) px -=
t0Corr(evt, detProp, pvtx);
515 else px +=
t0Corr(evt, detProp, pvtx);
518 float ldist = std::sqrt(
pma::Dist2(primary, pos_p));
519 if (ldist < minlep_dist)
577 TVector3 mcvtx3d(pvtx.X(), pvtx.Y(), pvtx.Z());
591 std::vector< art::Ptr<recob::Hit> > recoinihit = fb.at(recotrack.
key());
597 float px = pos_p.X();
598 if (px > 0) px -=
t0Corr(evt,detProp, pvtx);
599 else px +=
t0Corr(evt, detProp, pvtx);
664 std::vector<art::Ptr<recob::Cluster> > clusterlist;
666 if (clusterListHandle)
674 for (
size_t t = 0;
t < cryo.
NTPC(); ++
t)
677 std::vector< std::vector< dunefd::Hit2D > > clinput;
680 std::map<size_t, std::vector< dunefd::Hit2D > > cls;
681 for (
size_t i = 0; i < clusterlist.size(); ++i)
683 std::vector< art::Ptr<recob::Hit> > hitscl;
684 std::vector< Hit2D > hits2dcl;
688 for (
size_t h = 0;
h < hitscl.size(); ++
h)
690 size_t wire = hitscl[
h]->WireID().Wire;
691 size_t plane = hitscl[
h]->WireID().Plane;
692 size_t tpc = hitscl[
h]->WireID().TPC;
693 size_t cryo = hitscl[
h]->WireID().Cryostat;
695 if ((plane ==
p) && (tpc ==
t) && (cryo ==
c))
698 TVector2 point =
pma::WireDriftToCm(detProp, wire, hitscl[
h]->PeakTime(), plane, tpc, cryo);
700 hits2dcl.push_back(hit2d);
704 if (found) cls[i] = hits2dcl;
711 if (clinput.size() > 1)
714 TVector3 primary(pvtx.X(), pvtx.Y(), pvtx.Z());
715 make3dseg(evt, detProp, clinput, primary);
727 std::vector< dunefd::Hit2D >
cluster;
728 if (!cls.size())
return cluster;
731 const TLorentzVector& pvtx = particle.
Position();
736 TVector3 mcvtx3d(pvtx.X(), pvtx.Y(), pvtx.Z());
738 TVector2 mcvtx2d =
getMCvtx2d(mcvtx3d, cryo, tpc, plane);
739 TVector2 mcdir2d =
getMCdir2d(mcvtx3d, mcdir3d, cryo, tpc, plane);
743 recoini.
FeedwithMc(mcvtx2d, mcdir2d, mcdir3d);
744 cluster = recoini.
GetCl();
755 std::vector< std::vector< dunefd::Hit2D > >
const & src,
756 TVector3
const & primary)
758 if (src.size() < 2)
return;
759 if ((src[0].
size() < 2) || (src[1].size() < 2))
return;
761 std::vector<art::Ptr<recob::Hit> > hitlist;
766 std::vector< art::Ptr<recob::Hit> > hitsel;
768 for (
size_t i = 0; i < src.size(); ++i)
769 for (
size_t h = 0;
h < src[i].size(); ++
h)
770 hitsel.push_back(hitlist[src[i][
h].GetKey()]);
772 if (hitsel.size() > 5)
782 const size_t cryo,
const size_t tpc,
const size_t plane)
const 784 TVector3 shift3d = mcvtx3d + mcdir3d;
786 TVector2 mcdir2d = shift2d * (1.0 / shift2d.Mod());
804 TVector3
dir(0, 0, 0);
809 TLorentzVector mom = lepton.
Momentum();
810 TVector3 momvec3(mom.Px(), mom.Py(), mom.Pz());
811 dir = momvec3 * (1 / momvec3.Mag());
821 std::cout <<
" chargeParticleatVtx " <<
std::endl;
823 const sim::ParticleList& plist = pi_serv->
ParticleList();
825 TVector3 pospri;
bool primary =
false;
830 if (particle->
Process() !=
"primary")
continue;
833 primary =
true;
break;
836 if (!primary)
return;
838 size_t ninteractions = 0;
841 std::vector< double >
temp;
844 std::cout <<
" pdg " << particle->
PdgCode() <<
" " << particle->
P(0) <<
std::endl;
847 const TLorentzVector& startpos = particle->
Position(0);
848 TVector3 start(startpos.X(), startpos.Y(), startpos.Z());
849 const TLorentzVector& endpos = particle->
EndPosition();
850 TVector3 stop(endpos.X(), endpos.Y(), endpos.Z());
852 double diststartpri = std::sqrt(
pma::Dist2(start, pospri));
853 double diststoppri = std::sqrt(
pma::Dist2(stop, pospri));
854 if ((diststartpri > 0.1) && (diststartpri < 1.0))
858 double ek = particle->
E(0) - particle->
Mass();
859 file << evt.
run() <<
" " << evt.
id().
event() <<
" " << particle->
PdgCode() <<
" " << diststartpri <<
" " << diststoppri <<
" " << particle->
P(0) <<
" " << particle->
Mass() <<
" " << ek <<
std::endl;
861 if (ek > 0.05) ninteractions++;
873 std::vector< TVector3 > phdirs;
875 const sim::ParticleList& plist = pi_serv->
ParticleList();
880 if (particle->
Process() !=
"primary")
continue;
882 TVector3
dir(0, 0, 0);
883 if (particle->
PdgCode() == 111)
888 if (daughter1->
PdgCode() != 22)
continue;
891 if (daughter2->
PdgCode() != 22)
continue;
896 TVector3 momvec3(mom.Px(), mom.Py(), mom.Pz());
897 dir = momvec3 * (1 / momvec3.Mag());
898 phdirs.push_back(dir);
904 TVector3 momvec3(mom.Px(), mom.Py(), mom.Pz());
905 dir = momvec3 * (1 / momvec3.Mag());
906 phdirs.push_back(dir);
909 else if (particle->
PdgCode() == 22)
911 TLorentzVector mom = particle->
Momentum();
912 TVector3 momvec3(mom.Px(), mom.Py(), mom.Pz());
913 dir = momvec3 * (1 / momvec3.Mag());
914 phdirs.push_back(dir);
925 std::vector< TVector3 > dirs;
928 const sim::ParticleList& plist = pi_serv->
ParticleList();
933 TLorentzVector mom = particle->
Momentum();
934 TVector3 momvec(mom.Px(), mom.Py(), mom.Pz());
936 if ((particle->
PdgCode() ==
pdg) && (momvec.Mag() > 0.030))
939 TVector3 momconvec3(momconv.Px(), momconv.Py(), momconv.Pz());
940 TVector3
dir = momconvec3 * (1 / momconvec3.Mag());
952 TLorentzVector
const & pvtx)
954 float corrt0x = 0.0F;
959 std::vector<art::Ptr<simb::MCTruth> > mclist;
961 if (mctruthListHandle)
964 double vtx[3] = {pvtx.X(), pvtx.Y(), pvtx.Z()};
989 double vtx[3] = {pvtx.X(), pvtx.Y(), pvtx.Z()};
997 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
998 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
999 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
1017 double dista = fabs(minx - pvtx.X());
1018 double distb = fabs(pvtx.X() - maxx);
1020 if ((pvtx.X() > minx) && (pvtx.X() < maxx) &&
1025 else { inside =
false; }
1027 dista = fabs(maxy - pvtx.Y());
1028 distb = fabs(pvtx.Y() - miny);
1029 if (inside && (pvtx.Y() > miny) && (pvtx.Y() < maxy) &&
1031 else inside =
false;
1034 dista = fabs(maxz - pvtx.Z());
1035 distb = fabs(pvtx.Z() - minz);
1036 if (inside && (pvtx.Z() > minz) && (pvtx.Z() < maxz) &&
1038 else inside =
false;
1048 std::vector< TVector3 > xyz, dircos;
1050 for (
size_t i = 0; i < src.
size(); ++i)
1052 xyz.push_back(src[i]->
Point3D());
1054 if (i < src.
size() - 1)
1056 TVector3 dc(src[i + 1]->
Point3D());
1057 dc -= src[i]->Point3D();
1058 dc *= 1.0 / dc.Mag();
1059 dircos.push_back(dc);
1061 else dircos.push_back(dircos.back());
1064 if (xyz.size() != dircos.size())
1066 mf::LogError(
"IniSegReco") <<
"pma::Track3D to recob::Track conversion problem.";
double E(const int i=0) const
code to link reconstructed objects back to the MC truth information
const TLorentzVector & Position(const int i=0) const
const simb::MCNeutrino & GetNeutrino() const
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
void cluster(In first, In last, Out result, Pred *pred)
const TLorentzVector & EndPosition() const
Implementation of the Projection Matching Algorithm.
IniSegReco & operator=(IniSegReco const &)=delete
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
const simb::MCParticle * TrackIdToParticle_P(int id) const
void make3dseg(art::Event const &evt, detinfo::DetectorPropertiesData const &detProp, std::vector< std::vector< Hit2D > > const &src, TVector3 const &primary)
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
unsigned int Nplanes() const
Number of planes in this tpc.
const simb::MCParticle & Nu() const
Point_t const & LocationAtPoint(size_t i) const
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.
Geometry information for a single TPC.
recob::Track convertFrom(pma::Track3D const &src)
TrackTrajectory::Flags_t Flags_t
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
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.
TVector2 getMCvtx2d(TVector3 const &mcvtx3d, const size_t cryo, const size_t tpc, const size_t plane) const
void chargeParticlesatVtx(art::Event const &evt)
IniSegReco(fhicl::ParameterSet const &p)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Geometry information for a single cryostat.
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
std::string Process() const
void UseClusters(art::Event const &evt, detinfo::DetectorPropertiesData const &detProp)
int NumberDaughters() const
art framework interface to geometry description
int Daughter(const int i) const
std::vector< pma::Track3D * > pmatracks
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.
std::vector< TVector3 > findDirs(art::Ptr< simb::MCTruth > const mctruth, int pdg) const
const simb::MCParticle & Lepton() const
void produce(art::Event &e) override
#define DEFINE_ART_MODULE(klass)
std::string EndProcess() const
A trajectory in space reconstructed from hits.
void FeedwithMc(TVector2 const &vtx, TVector2 const &dir, TVector3 const &dir3d)
std::string fGenieGenModuleLabel
bool insideFidVol(TLorentzVector const &pvtx) const
double P(const int i=0) const
key_type key() const noexcept
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.
unsigned int NTPC() const
Number of TPCs in this cryostat.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
void collectCls(art::Event const &evt, detinfo::DetectorPropertiesData const &detProp, art::Ptr< simb::MCTruth > const mctruth)
SubRunNumber_t subRun() const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
pma::Track3D * buildSegment(const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits_1, const std::vector< art::Ptr< recob::Hit >> &hits_2={}) const
The data type to uniquely identify a TPC.
TVector3 findElDir(art::Ptr< simb::MCTruth > const mctruth) const
float t0Corr(art::Event const &evt, detinfo::DetectorPropertiesData const &detProp, TLorentzVector const &pvtx)
void reconfigure(fhicl::ParameterSet const &p)
double MaxY() const
Returns the world y coordinate of the end of the box.
const sim::ParticleList & ParticleList() const
std::string fHitsModuleLabel
std::string fVertexModuleLabel
const simb::MCParticle & GetParticle(int i) const
std::string fClusterModuleLabel
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether we have the specified TPC.
Implementation of the Projection Matching Algorithm.
Declaration of signal hit object.
TVector2 getMCdir2d(TVector3 const &mcvtx3d, TVector3 const &mcdir3d, const size_t cryo, const size_t tpc, const size_t plane) const
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< dunefd::Hit2D > const & GetCl() const
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
const TLorentzVector & Momentum(const int i=0) const
void UseTracks(art::Event const &evt, detinfo::DetectorPropertiesData const &detProp)
Provides recob::Track data product.
EventNumber_t event() const
std::string fTrackModuleLabel
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
std::vector< dunefd::Hit2D > reselectCls(std::map< size_t, std::vector< dunefd::Hit2D > > const &cls, art::Ptr< simb::MCTruth > const mctruth, const size_t cryo, const size_t tpc, const size_t plane) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
pma::ProjectionMatchingAlg fProjectionMatchingAlg
float const & GetCos() const
double MinY() const
Returns the world y coordinate of the start of the box.
const TLorentzVector & EndMomentum() const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
art::Ptr< recob::Track > const & GetTrk() const
QTextStream & endl(QTextStream &s)
Event finding and building.
std::vector< TVector3 > findPhDir() const