10 #include "fhiclcpp/ParameterSet.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
33 greaterThan1(PlnLen
p1, PlnLen p2)
35 return p1.length > p2.length;
43 fSPTAlg = pset.get<
int>(
"SPTAlg", 0);
44 fTrajOnly = pset.get<
bool>(
"TrajOnly",
false);
45 ftmatch = pset.get<
double>(
"TMatch");
46 fsmatch = pset.get<
double>(
"SMatch");
64 Track3D(clockData, detProp, fHits);
67 throw cet::exception(
"CosmicTrackerAlg")
68 <<
"Unknown SPTAlg " <<
fSPTAlg <<
", needs to be 0 or 1";
72 MakeSPT(clockData, detProp, fHits);
85 std::array<std::vector<geo::WireID>, 3> trkWID;
86 std::array<std::vector<double>, 3> trkX;
87 std::array<std::vector<double>, 3> trkXErr;
89 std::array<std::vector<art::Ptr<recob::Hit>>, 3> trajHits;
91 for (
size_t i = 0; i < fHits.size(); ++i) {
92 trajHits[fHits[i]->WireID().Plane].push_back(fHits[i]);
95 std::vector<PlnLen> spl;
97 for (
unsigned int ipl = 0; ipl < 3; ++ipl) {
99 plnlen.length = trajHits[ipl].size();
100 spl.push_back(plnlen);
102 std::sort(spl.begin(), spl.end(), greaterThan1);
105 for (
size_t ipl = 0; ipl < 3; ++ipl) {
106 if (!trajHits[ipl].
size())
continue;
107 double xbeg0 = detProp.
ConvertTicksToX(trajHits[spl[0].index][0]->PeakTime(),
110 trajHits[spl[0].index][0]->
WireID().Cryostat);
111 double xend0 = detProp.
ConvertTicksToX(trajHits[spl[0].index].back()->PeakTime(),
113 trajHits[spl[0].index].back()->
WireID().
TPC,
114 trajHits[spl[0].index].back()->
WireID().Cryostat);
118 trajHits[ipl][0]->
WireID().Cryostat);
119 double xend1 = detProp.
ConvertTicksToX(trajHits[ipl].back()->PeakTime(),
122 trajHits[ipl].back()->
WireID().Cryostat);
129 std::reverse(trajHits[ipl].
begin(), trajHits[ipl].
end());
133 for (
size_t ipl = 0; ipl < 3; ++ipl) {
135 trkWID[ipl].resize(trajHits[ipl].
size());
136 trkX[ipl].resize(trajHits[ipl].
size());
137 trkXErr[ipl].resize(trajHits[ipl].
size());
138 for (
size_t iht = 0; iht < trajHits[ipl].size(); ++iht) {
139 trkWID[ipl][iht] = trajHits[ipl][iht]->WireID();
140 trkX[ipl][iht] = detProp.
ConvertTicksToX(trajHits[ipl][iht]->PeakTime(),
143 trajHits[ipl][iht]->
WireID().Cryostat);
144 trkXErr[ipl][iht] = 0.2 * trajHits[ipl][iht]->RMS() * trajHits[ipl][iht]->Multiplicity();
149 mf::LogWarning(
"CosmicTrackerAlg") <<
"Failed to reconstruct trajectory points.";
154 auto ipos1 = ipos + 1;
155 if (*ipos1 == *ipos) {
167 vw.resize(
geom->Ncryostats());
168 vt.resize(
geom->Ncryostats());
170 for (
size_t cstat = 0; cstat <
geom->Ncryostats(); ++cstat) {
171 vw[cstat].resize(
geom->Cryostat(cstat).NTPC());
172 vt[cstat].resize(
geom->Cryostat(cstat).NTPC());
173 vtraj[cstat].resize(
geom->Cryostat(cstat).NTPC());
174 for (
size_t tpc = 0; tpc <
geom->Cryostat(cstat).NTPC(); ++tpc) {
176 vw[cstat][tpc].resize(tpcgeom.
Nplanes());
177 vt[cstat][tpc].resize(tpcgeom.
Nplanes());
179 for (
size_t plane = 0; plane < tpcgeom.
Nplanes(); ++plane) {
180 for (
size_t i = 0; i <
trajPos.size(); ++i) {
184 vw[cstat][tpc][plane].push_back(wirecord);
185 vt[cstat][tpc][plane].push_back(tick);
186 vtraj[cstat][tpc][plane].push_back(i);
199 larprop = lar::providerFrom<detinfo::LArPropertiesService>();
202 std::vector<std::map<int, double>> vtimemap(3);
203 std::vector<std::map<int, art::Ptr<recob::Hit>>> vhitmap(3);
206 for (
size_t ihit = 0; ihit < fHits.size(); ++ihit) {
208 unsigned int w = hitWireID.
Wire;
209 unsigned int pl = hitWireID.
Plane;
210 double time = fHits[ihit]->PeakTime();
213 vtimemap[pl][
w] = time;
214 vhitmap[pl][
w] = fHits[ihit];
221 unsigned maxnumhits0 = 0;
222 unsigned maxnumhits1 = 0;
224 std::vector<double> tmin(vtimemap.size());
225 std::vector<double> tmax(vtimemap.size());
226 for (
size_t iclu = 0; iclu < vtimemap.size(); ++iclu) {
231 for (
size_t iclu = 0; iclu < vtimemap.size(); ++iclu) {
232 for (
auto itime = vtimemap[iclu].
begin(); itime != vtimemap[iclu].end(); ++itime) {
233 if (itime->second > tmax[iclu]) { tmax[iclu] = itime->second; }
234 if (itime->second < tmin[iclu]) { tmin[iclu] = itime->second; }
236 if (vtimemap[iclu].
size() > maxnumhits0) {
239 maxnumhits1 = maxnumhits0;
242 maxnumhits0 = vtimemap[iclu].size();
244 else if (vtimemap[iclu].
size() > maxnumhits1) {
246 maxnumhits1 = vtimemap[iclu].size();
250 std::swap(iclu1, iclu2);
253 for (
int iclu = 0; iclu < (int)vtimemap.size(); ++iclu) {
254 if (iclu != iclu1 && iclu != iclu2) iclu3 = iclu;
257 if (iclu1 != -1 && iclu2 != -1) {
259 auto ihit = vhitmap[iclu1].begin();
260 auto itime = vtimemap[iclu1].begin();
261 while (itime != vtimemap[iclu1].
end()) {
262 if (itime->second < std::max(tmin[iclu1], tmin[iclu2]) -
ftmatch ||
263 itime->second > std::min(tmax[iclu1], tmax[iclu2]) +
ftmatch) {
264 vtimemap[iclu1].erase(itime++);
265 vhitmap[iclu1].erase(ihit++);
273 ihit = vhitmap[iclu2].begin();
274 itime = vtimemap[iclu2].begin();
275 while (itime != vtimemap[iclu2].
end()) {
276 if (itime->second < std::max(tmin[iclu1], tmin[iclu2]) -
ftmatch ||
277 itime->second > std::min(tmax[iclu1], tmax[iclu2]) +
ftmatch) {
278 vtimemap[iclu2].erase(itime++);
279 vhitmap[iclu2].erase(ihit++);
288 if (!vtimemap[iclu1].
size()) {
289 if (iclu3 != -1) { std::swap(iclu3, iclu1); }
291 if (!vtimemap[iclu2].
size()) {
293 std::swap(iclu3, iclu2);
294 std::swap(iclu1, iclu2);
297 if ((!vtimemap[iclu1].
size()) || (!vtimemap[iclu2].
size()))
return;
300 auto times1 = vtimemap[iclu1].begin();
301 auto timee1 = vtimemap[iclu1].end();
303 auto times2 = vtimemap[iclu2].begin();
304 auto timee2 = vtimemap[iclu2].end();
307 double ts1 = times1->second;
308 double te1 = timee1->second;
309 double ts2 = times2->second;
310 double te2 = timee2->second;
318 double Efield_drift = detProp.
Efield(0);
322 Efield_drift, Temperature);
323 double timepitch = driftvelocity * timetick;
327 vhitmap[0].begin()->second->WireID().TPC,
328 vhitmap[0].begin()->second->WireID().Cryostat);
331 std::vector<double> vtracklength;
332 for (
size_t iclu = 0; iclu < vtimemap.size(); ++iclu) {
334 double tracklength = 0;
335 if (vtimemap[iclu].
size() == 1) { tracklength = wire_pitch; }
336 else if (!vtimemap[iclu].
empty()) {
337 std::map<int, double>::const_iterator iw = vtimemap[iclu].cbegin(),
338 wend = vtimemap[iclu].cend();
339 double t0 = iw->first, w0 = iw->second;
340 while (++iw != wend) {
341 tracklength += std::hypot((iw->first - w0) * wire_pitch, (iw->second - t0) * timepitch);
346 vtracklength.push_back(tracklength);
349 std::map<int, int> maxhitsMatch;
351 auto ihit1 = vhitmap[iclu1].begin();
352 for (
auto itime1 = vtimemap[iclu1].
begin(); itime1 != vtimemap[iclu1].end();
354 std::vector<art::Ptr<recob::Hit>> sp_hits;
355 sp_hits.push_back(ihit1->second);
356 double hitcoord[3] = {0., 0., 0.};
358 if (vtimemap[iclu1].
size() == 1) { length1 = wire_pitch; }
360 for (
auto iw1 = vtimemap[iclu1].
begin(); iw1 != itime1; ++iw1) {
363 length1 += std::hypot((iw1->first - iw2->first) * wire_pitch,
364 (iw1->second - iw2->second) * timepitch);
367 double difference = 1
e10;
368 auto matchedtime = vtimemap[iclu2].end();
369 auto matchedhit = vhitmap[iclu2].end();
371 auto ihit2 = vhitmap[iclu2].begin();
372 for (
auto itime2 = vtimemap[iclu2].
begin(); itime2 != vtimemap[iclu2].end();
374 if (maxhitsMatch[itime2->first])
continue;
376 if (vtimemap[iclu2].
size() == 1) { length2 = wire_pitch; }
378 for (
auto iw1 = vtimemap[iclu2].
begin(); iw1 != itime2; ++iw1) {
381 length2 += std::hypot((iw1->first - iw2->first) * wire_pitch,
382 (iw1->second - iw2->second) * timepitch);
385 if (rev) length2 = vtracklength[iclu2] - length2;
386 length2 = vtracklength[iclu1] / vtracklength[iclu2] * length2;
388 if (timematch &&
std::abs(length2 - length1) < difference) {
389 difference =
std::abs(length2 - length1);
390 matchedtime = itime2;
396 matchedtime->second + detProp.
GetXTicksOffset((matchedhit->second)->WireID().Plane,
397 (matchedhit->second)->
WireID().TPC,
398 (matchedhit->second)->
WireID().Cryostat),
399 (matchedhit->second)->WireID().Plane,
400 (matchedhit->second)->
WireID().TPC,
401 (matchedhit->second)->
WireID().Cryostat);
412 bool sameTpcOrNot =
geom->WireIDsIntersect(c1, c2, tmpWIDI);
415 hitcoord[1] = tmpWIDI.
y;
416 hitcoord[2] = tmpWIDI.
z;
419 if (hitcoord[1] > -1e9 && hitcoord[2] > -1e9) {
420 maxhitsMatch[matchedtime->first] = 1;
421 sp_hits.push_back(matchedhit->second);
424 if (sp_hits.size() > 1) {
425 trajPos.push_back(TVector3(hitcoord));
438 larprop = lar::providerFrom<detinfo::LArPropertiesService>();
441 double Efield_drift = detProp.
Efield(0);
443 double driftvelocity =
445 double time_pitch = driftvelocity * timetick;
447 for (
size_t i = 0; i < fHits.size(); ++i) {
454 double mindis1 = 1e9;
455 double mindis2 = 1e9;
456 double mindis2p = 1e9;
458 unsigned int wire = wireid.
Wire;
459 unsigned int plane = wireid.
Plane;
460 unsigned int tpc = wireid.
TPC;
461 unsigned int cstat = wireid.
Cryostat;
462 double wire_pitch =
geom->WirePitch(plane, tpc, cstat);
465 for (
size_t j = 0; j <
vw[cstat][tpc][plane].size(); ++j) {
466 double dis = std::hypot(wire_pitch * (wire -
vw[cstat][tpc][plane][j]),
467 time_pitch * (fHits[i]->PeakTime() -
vt[cstat][tpc][plane][j]));
470 ip1 =
vtraj[cstat][tpc][plane][j];
475 for (
size_t j = 0; j <
vw[cstat][tpc][plane].size(); ++j) {
476 if (
int(j) == ih1)
continue;
477 double dis = std::hypot(wire_pitch * (wire -
vw[cstat][tpc][plane][j]),
478 time_pitch * (fHits[i]->PeakTime() -
vt[cstat][tpc][plane][j]));
481 ip2 =
vtraj[cstat][tpc][plane][j];
484 TVector3 v1(wire_pitch * (wire -
vw[cstat][tpc][plane][ih1]),
485 time_pitch * (fHits[i]->PeakTime() -
vt[cstat][tpc][plane][j]),
487 TVector3 v2(wire_pitch * (wire -
vw[cstat][tpc][plane][j]),
488 time_pitch * (fHits[i]->PeakTime() -
vt[cstat][tpc][plane][j]),
490 if (v1.Dot(v2) < 0) {
491 if (dis < mindis2p) {
493 ip2p =
vtraj[cstat][tpc][plane][j];
502 if (ip1 == -1 || ip2 == -1) {
504 throw cet::exception(
"CosmicTrackerAlg") <<
"Cannot find two nearest trajectory points.";
506 TVector3 v1(wire_pitch * (wire -
vw[cstat][tpc][plane][ih1]),
507 time_pitch * (fHits[i]->PeakTime() -
vt[cstat][tpc][plane][ih1]),
509 TVector3 v2(wire_pitch * (
vw[cstat][tpc][plane][ih2] -
vw[cstat][tpc][plane][ih1]),
510 time_pitch * (
vt[cstat][tpc][plane][ih2] -
vt[cstat][tpc][plane][ih1]),
513 throw cet::exception(
"CosmicTrackerAlg") <<
"Two identical trajectory points.";
515 double ratio = v1.Dot(v2) / v2.Mag2();
std::vector< std::vector< std::vector< std::vector< double > > > > vw
double z
z position of intersection
Utilities related to art service access.
Encapsulate the construction of a single cyostat.
std::vector< std::vector< std::vector< std::vector< double > > > > vt
double GetXTicksOffset(int p, int t, int c) const
unsigned int Nplanes() const
Number of planes in this tpc.
double ftmatch
tolerance for time matching (in ticks)
Declaration of signal hit object.
Geometry information for a single TPC.
double Temperature() const
In kelvin.
std::vector< TVector3 > trajPos
CryostatID_t Cryostat
Index of cryostat.
std::size_t size(FixedBins< T, C > const &) noexcept
std::vector< TVector3 > trkDir
WireID_t Wire
Index of the wire within its plane.
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other echo the stabs desc and the stab type Stabs symbols are echo used to hold debugging information For more echo see *Note or object file format specific echo echo For Mac OS X
double Efield(unsigned int planegap=0) const
kV/cm
void TrackTrajectory(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &fHits)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< std::vector< std::vector< std::vector< unsigned int > > > > vtraj
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
TrackTrajectoryAlg fTrackTrajectoryAlg
auto end(FixedBins< T, C > const &) noexcept
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
double ConvertXToTicks(double X, int p, int t, int c) const
CosmicTrackerAlg(fhicl::ParameterSet const &pset)
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
PlaneID_t Plane
Index of the plane within its TPC.
double fsmatch
tolerance for distance matching (in cm)
void TrackTrajectory(std::array< std::vector< geo::WireID >, 3 > trkWID, std::array< std::vector< double >, 3 > trkX, std::array< std::vector< double >, 3 > trkXErr, std::vector< TVector3 > &TrajPos, std::vector< TVector3 > &TrajDir)
Definition of data types for geometry description.
Class defining a plane for tracking. It provides various functionalities to convert track parameters ...
double ConvertTicksToX(double ticks, int p, int t, int c) const
auto begin(FixedBins< T, C > const &) noexcept
art::ServiceHandle< geo::Geometry const > geom
const detinfo::LArProperties * larprop
std::vector< TVector3 > trkPos
void MakeSPT(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &fHits)
Contains all timing reference information for the detector.
double y
y position of intersection
void SPTReco(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &fHits)
constexpr WireID()=default
Default constructor: an invalid TPC ID.
then echo ***************************************echo Variable FHICL_FILE_PATH not found echo You porbably haven t set up larsoft echo Try setup uboonecode vXX_XX_XX q e10
TPCID_t TPC
Index of the TPC within its cryostat.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< TVector3 > trajDir
bool empty(FixedBins< T, C > const &) noexcept
void Track3D(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &fHits)
physics associatedGroupsWithLeft p1
art framework interface to geometry description
Encapsulate the construction of a single detector plane.
std::vector< std::vector< art::Ptr< recob::Hit > > > trajHit