All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StubMergeAlgorithms.cxx
Go to the documentation of this file.
1 #include "StubMergeAlgorithms.h"
2 
4  if (sce && sce->EnableCalSpatialSCE()) {
5  geo::Vector_t offset = sce->GetCalPosOffsets(loc_w, TPC.TPC);
6  loc_w.SetX(loc_w.X() + xsign * offset.X());
7  loc_w.SetY(loc_w.Y() + offset.Y());
8  loc_w.SetZ(loc_w.Z() + offset.Z());
9  }
10 
11  return loc_w;
12 }
13 
14 double sbn::GetEfield(const detinfo::DetectorPropertiesData &dprop, const spacecharge::SpaceCharge *sce, geo::Point_t loc, geo::TPCID TPC, bool correct_loc_sce, float xsign) {
15 
16  double EField = dprop.Efield();
17  if (sce && sce->EnableSimEfieldSCE()) {
18  if (correct_loc_sce) loc = sbn::GetLocation(sce, loc, TPC, xsign);
19 
20  // Gets relative E field Distortions
21  geo::Vector_t EFieldOffsets = sce->GetEfieldOffsets(loc);
22  // Add 1 in X direction as this is the direction of the drift field
23  EFieldOffsets = EFieldOffsets + geo::Xaxis();
24  // Convert to Absolute E Field from relative
25  EFieldOffsets = EField * EFieldOffsets;
26  // We only care about the magnitude for recombination
27  EField = EFieldOffsets.r();
28  }
29 
30  return EField;
31 }
32 
34  if (sce && sce->EnableCalSpatialSCE()) {
35  // Returned X is the drift -- multiply by the drift direction to undo this
36  int corr = geo->TPC(TPC).DriftDir()[0];
37 
39  loc.SetX(loc.X() + corr * xsign * offset.X());
40  loc.SetY(loc.Y() + offset.Y());
41  loc.SetZ(loc.Z() + offset.Z());
42  }
43 
44  return loc;
45 }
46 
48  const geo::GeometryCore *geo, const spacecharge::SpaceCharge *sce,
50  geo::View_t view, geo::TPCID tpc,
51  bool correct_sce, bool track_is_sce_corrected, float xsign) {
52 
53  double angleToVert = geo->WireAngleToVertical(view, tpc) - 0.5*::util::pi<>();
54 
55  geo::Vector_t dir_w;
56 
57  // "dir_w" should be the direction that the wires see. If the track already has the field
58  // distortion corrections applied, then we need to de-apply them to get the direction as
59  // seen by the wire planes
60  if (correct_sce && track_is_sce_corrected) {
61  // compute the dir of the track trajectory
62  geo::Point_t loc_mdx = loc - dir * (geo->WirePitch(view) / 2.);
63  geo::Point_t loc_pdx = loc + dir * (geo->WirePitch(view) / 2.);
64 
65  // map to the wires
66  loc_mdx = GetLocationAtWires(sce, geo, loc_mdx, tpc, xsign);
67  loc_pdx = GetLocationAtWires(sce, geo, loc_pdx, tpc, xsign);
68 
69  dir_w = (loc_pdx - loc_mdx).Unit();
70  }
71  // If there is no space charge or the track is not yet corrected, then the dir
72  // is what we want
73  else {
74  dir_w = dir;
75  }
76 
77  double cosgamma = std::abs(std::sin(angleToVert)*dir_w.Y() + std::cos(angleToVert)*dir_w.Z());
78  double pitch;
79  if (cosgamma) {
80  pitch = geo->WirePitch(view)/cosgamma;
81  }
82  else {
83  pitch = 0.;
84  }
85 
86  // now take the pitch computed on the wires and correct it back to the particle trajectory
87  geo::Point_t loc_w = loc;
88  if (correct_sce && track_is_sce_corrected) {
89  loc_w = sbn::GetLocationAtWires(sce, geo, loc, tpc, xsign);
90  }
91 
92  geo::Point_t locw_traj = (correct_sce) ? sbn::GetLocation(sce, loc_w, tpc, xsign) : loc_w;
93  geo::Point_t locw_pdx_traj = (correct_sce) ? sbn::GetLocation(sce, loc_w + pitch * dir_w, tpc, xsign) : (loc_w + pitch * dir_w);
94 
95  pitch = (locw_traj - locw_pdx_traj).R();
96 
97  return pitch;
98 }
99 
100 
101 // Check if A contains B
103  if (A.vhit_hit->WireID().Plane != B.vhit_hit->WireID().Plane) return false;
104 
105  for (const art::Ptr<recob::Hit> &h: A.hits) {
106  if (A.stub.OnCore(h->WireID())) {
107  if (h.key() == B.vhit_hit.key()) {
108  return true;
109  }
110  }
111  }
112  return false;
113 }
114 
116  const geo::GeometryCore *geo,
117  const detinfo::DetectorPropertiesData &dprop) {
118 
119  // A and B should chare vertex locations
120  //
121  // We want this to be the vertex as seen by the wires
122  float vert_w = A.vhit->vtxw;
123  float vert_x = A.vhit->vtxx;;
124 
125  float Ahit_w = A.vhit_hit->WireID().Wire * geo->WirePitch() - vert_w;
126  float Ahit_x = dprop.ConvertTicksToX(A.vhit_hit->PeakTime(), A.vhit_hit->WireID()) - vert_x;
127 
128  float Bhit_w = B.vhit_hit->WireID().Wire * geo->WirePitch() - vert_w;
129  float Bhit_x = dprop.ConvertTicksToX(B.vhit_hit->PeakTime(), B.vhit_hit->WireID()) - vert_x;
130 
131  float Amag = sqrt(Ahit_w*Ahit_w + Ahit_x*Ahit_x);
132  float Bmag = sqrt(Bhit_w*Bhit_w + Bhit_x*Bhit_x);
133 
134  return(Ahit_w*Bhit_w + Ahit_x*Bhit_x) / (Amag*Bmag);
135 }
136 
138  const detinfo::DetectorClocksData &dclock,
139  const detinfo::DetectorPropertiesData &dprop) {
140 
141  // Convert the ticks to an X-point to undo tick-offsets between planes. And then convert to ticks.
142  return abs(dprop.ConvertTicksToX(A.vhit_hit->PeakTime(), A.vhit_hit->WireID()) - dprop.ConvertTicksToX(B.vhit_hit->PeakTime(), B.vhit_hit->WireID())) / dprop.DriftVelocity() / dclock.TPCClock().TickPeriod();
143 }
144 
146  const geo::GeometryCore *geo,
147  const spacecharge::SpaceCharge *sce,
148  const detinfo::DetectorPropertiesData &dprop) {
149 
150  static constexpr bool VERBOSE = false;
151 
152  // intersect the wires with the geometry service
153  geo::Point_t yz;
154  bool intersects = geo->WireIDsIntersect(A.vhit_hit->WireID(), B.vhit_hit->WireID(), yz);
155  (void) intersects; // TODO: Do we care if the wires intersect? Means the end point will be outside the AV
156  double y = yz.Y();
157  double z = yz.Z();
158 
159  // just average the x-pos
160  double x = (dprop.ConvertTicksToX(A.vhit_hit->PeakTime(), A.vhit_hit->WireID()) + dprop.ConvertTicksToX(B.vhit_hit->PeakTime(), B.vhit_hit->WireID())) / 2.;
161 
162  geo::Point_t pos(x, y, z);
163 
164  // Correct for space charge
165  pos = GetLocation(sce, pos, A.vhit_hit->WireID());
166 
167  if (VERBOSE) {
168  std::cout << "A View: " << geo->View(A.vhit_hit->WireID()) << " Angle to Vertical: " << geo->WireAngleToVertical(geo->View(A.vhit_hit->WireID()), A.vhit_hit->WireID()) << std::endl;
169  std::cout << "B View: " << geo->View(B.vhit_hit->WireID()) << " Angle to Vertical: " << geo->WireAngleToVertical(geo->View(B.vhit_hit->WireID()), B.vhit_hit->WireID()) << std::endl;
170  std::cout << "A End: " << A.stub.end.X() << " " << A.stub.end.Y() << " " << A.stub.end.Z() << std::endl;
171  std::cout << "B End: " << B.stub.end.X() << " " << B.stub.end.Y() << " " << B.stub.end.Z() << std::endl;
172  std::cout << "A Wire Pos Y: " << geo->Wire(A.vhit_hit->WireID()).GetCenter().Y() << " Z: " << geo->Wire(A.vhit_hit->WireID()).GetCenter().Z() << std::endl;
173  std::cout << "B Wire Pos Y: " << geo->Wire(B.vhit_hit->WireID()).GetCenter().Y() << " Z: " << geo->Wire(B.vhit_hit->WireID()).GetCenter().Z() << std::endl;
174 
175  std::cout << "A Wire: " << A.vhit_hit->WireID().Wire << " Plane: " << A.vhit_hit->WireID().Plane << " TPC: " << A.vhit_hit->WireID().TPC << std::endl;
176  std::cout << "B Wire: " << B.vhit_hit->WireID().Wire << " Plane: " << B.vhit_hit->WireID().Plane << " TPC: " << B.vhit_hit->WireID().TPC << std::endl;
177 
178  std::cout << "Output Y: " << y << " Z: " << z << std::endl;
179 
180  std::cout << "A Wire coord: " << geo->WireCoordinate(pos, A.vhit_hit->WireID()) << std::endl;
181  std::cout << "B Wire coord: " << geo->WireCoordinate(pos, B.vhit_hit->WireID()) << std::endl;
182 
183  std::cout << "A X: " << dprop.ConvertTicksToX(A.vhit_hit->PeakTime(), A.vhit_hit->WireID()) << std::endl;
184  std::cout << "B X: " << dprop.ConvertTicksToX(B.vhit_hit->PeakTime(), B.vhit_hit->WireID()) << std::endl;
185 
186  std::cout << "Output X: " << x << std::endl;
187 
188 
189  std::cout << "Final x: " << pos.x() << " y: " << pos.y() << " z: " << pos.z() << std::endl;
190  }
191 
192  return pos;
193 }
194 
196  assert(A.stub.hits.size() == 1 && B.stub.hits.size() == 1);
197 
198  // Only count charge on the main stub
199  float ACharge = A.stub.CoreCharge();
200  float BCharge = B.stub.CoreCharge();
201 
202  return abs(ACharge - BCharge);
203 }
204 
206  return abs(A.vhit->charge - B.vhit->charge);
207 }
208 
210  const geo::GeometryCore *geo,
211  const spacecharge::SpaceCharge *sce,
212  const detinfo::DetectorPropertiesData &dprop) {
213 
214  // stubs should share the vertex
215  geo::Point_t vtx = A.stub.vtx;
216  geo::Point_t end = sbn::TwoStubEndPosition(A, B, geo, sce, dprop);
217 
218  geo::Vector_t dir((end-vtx).Unit());
219 
220  // Input point, dir are always space charge corrected here
221  float Apitch = GetPitch(geo, sce, end, dir, A.vhit_hit->View(), A.vhit_hit->WireID(), true, true);
222  float Bpitch = GetPitch(geo, sce, end, dir, B.vhit_hit->View(), B.vhit_hit->WireID(), true, true);
223 
224  return abs(A.vhit->charge / Apitch - B.vhit->charge / Bpitch);
225 }
226 
float StubChargeOffset(const sbn::StubInfo &A, const sbn::StubInfo &B)
Difference of the total charge between two stubs.
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
float StubTimeOffset(const sbn::StubInfo &A, const sbn::StubInfo &B, const detinfo::DetectorClocksData &dclock, const detinfo::DetectorPropertiesData &dprop)
process_name opflash particleana ie ie ie z
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
Vector DriftDir() const
Returns the direction of the drift (vector pointing toward the planes).
Definition: TPCGeo.h:773
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
Definition: CORSIKAGen.fcl:7
float StubPeakdQdxOffset(const sbn::StubInfo &A, const sbn::StubInfo &B, const geo::GeometryCore *geo, const spacecharge::SpaceCharge *sce, const detinfo::DetectorPropertiesData &dprop)
Difference of the endpoint dQ/dx between two stubs.
process_name opflash particleana ie x
ElecClock const & TPCClock() const noexcept
Borrow a const TPC clock with time set to Trigger time [us].
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
float StubDirectionDot(const sbn::StubInfo &A, const sbn::StubInfo &B, const geo::GeometryCore *geo, const detinfo::DetectorPropertiesData &dprop)
Computes the dot product of two stubs.
std::vector< std::vector< StubHit > > hits
Hits on each plane. Ordered vtx-&gt;end.
Definition: Stub.h:32
geo::Point_t end
End of Stub. Space charge corrected. [cm].
Definition: Stub.h:19
bool OnCore(const geo::WireID &w) const
Returns whether the input wire-ID is on the core of the stub.
Definition: Stub.cxx:57
geo::Point_t GetLocation(const spacecharge::SpaceCharge *sce, geo::Point_t loc_w, geo::TPCID TPC, float xsign=1.)
Get the location in the presence of space charge.
Internal struct: contains information on stub and other associated data products. ...
float CoreCharge(unsigned plane_index=0) const
Helper functions.
Definition: Stub.cxx:25
geo::Point_t vtx
Interaction Vertex / Start of Stub. Space charge corrected. [cm].
Definition: Stub.h:18
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
BEGIN_PROLOG TPC
geo::Point_t GetLocationAtWires(const spacecharge::SpaceCharge *sce, const geo::GeometryCore *geo, geo::Point_t loc, geo::TPCID TPC, float xsign=1.)
Get the SCE-distorted location (i.e. the location &quot;seen&quot; by the wireplanes)
double Efield(unsigned int planegap=0) const
kV/cm
constexpr double TickPeriod() const noexcept
A single tick period in microseconds.
Definition: ElecClock.h:352
std::vector< art::Ptr< recob::Hit > > hits
while getopts h
T abs(T value)
process_name opflash particleana ie ie y
virtual geo::Vector_t GetEfieldOffsets(geo::Point_t const &point) const =0
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
bool StubContains(const sbn::StubInfo &A, const sbn::StubInfo &B)
Returns whether stub A contains stub B.
constexpr Vector Xaxis()
Returns a x axis vector of the specified type.
Definition: geo_vectors.h:215
art::Ptr< recob::Hit > vhit_hit
double GetPitch(const geo::GeometryCore *geo, const spacecharge::SpaceCharge *sce, geo::Point_t loc, geo::Vector_t dir, geo::View_t view, geo::TPCID tpc, bool correct_sce, bool track_is_sce_corrected, float xsign=1.)
Computes the track-pitch on a plane given an input direction and location.
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
j template void())
Definition: json.hpp:3108
Description of geometry of one entire detector.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
tuple dir
Definition: dropbox.py:28
double ConvertTicksToX(double ticks, int p, int t, int c) const
art::Ptr< sbn::VertexHit > vhit
bool WireIDsIntersect(WireID const &wid1, WireID const &wid2, geo::Point_t &intersection) const
Computes the intersection between two wires.
WireGeo const & Wire(geo::WireID const &wireid) const
Returns the specified wire.
virtual geo::Vector_t GetPosOffsets(geo::Point_t const &point) const =0
Contains all timing reference information for the detector.
geo::Point_t TwoStubEndPosition(const sbn::StubInfo &A, const sbn::StubInfo &B, const geo::GeometryCore *geo, const spacecharge::SpaceCharge *sce, const detinfo::DetectorPropertiesData &dprop)
Returns an updated end position of a stub after merging across two planes.
double GetEfield(const detinfo::DetectorPropertiesData &dprop, const spacecharge::SpaceCharge *sce, geo::Point_t loc, geo::TPCID TPC, bool correct_loc_sce, float xsign=1.)
Get the E-Field in the presence of space charge.
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
float StubPeakChargeOffset(const sbn::StubInfo &A, const sbn::StubInfo &B)
Difference of the endpoint charge between two stubs.
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
virtual bool EnableCalSpatialSCE() const =0
float A
Definition: dedx.py:137
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
double WireAngleToVertical(geo::View_t view, geo::TPCID const &tpcid) const
Returns the angle of the wires in the specified view from vertical.
virtual bool EnableSimEfieldSCE() const =0
BEGIN_PROLOG could also be cout