138 std::unique_ptr< std::vector<gar::rec::Track> > trkCol(
new std::vector<gar::rec::Track>);
139 std::unique_ptr< art::Assns<gar::rec::VecHit,gar::rec::Track> > vhTrkAssns(new ::art::Assns<gar::rec::VecHit,gar::rec::Track>);
140 std::unique_ptr< art::Assns<gar::rec::TPCCluster,gar::rec::Track> > TPCClusterTrkAssns(new ::art::Assns<gar::rec::TPCCluster,gar::rec::Track>);
143 auto const& vechits = *vechitHandle;
146 auto const& e_tpcclusters = *TPCClusterHandle;
152 const art::FindManyP<gar::rec::TPCCluster> TPCClustersFromVecHits(vechitHandle,e,
fVecHitLabel);
155 G4ThreeVector zerovec(0,0,0);
156 G4ThreeVector magfield = magFieldService->FieldAtPoint(zerovec);
158 std::set<gar::rec::IDNumber> TPCClusNumerosUsedInFirstPass;
165 std::vector< std::vector< size_t > > vhclusters;
167 for (
size_t ivh = 0; ivh< vechits.size(); ++ ivh)
171 std::cout <<
" vhprint " << vechits[ivh].Position()[0] <<
" " << vechits[ivh].Position()[1] <<
" " << vechits[ivh].Position()[2] <<
" " <<
172 vechits[ivh].Direction()[0] <<
" " << vechits[ivh].Direction()[1] <<
" " << vechits[ivh].Direction()[2] <<
" " <<
std::endl;
175 std::vector<size_t> clusmatchlist;
176 for (
size_t iclus=0; iclus<vhclusters.size(); ++iclus)
180 clusmatchlist.push_back(iclus);
183 if (clusmatchlist.size() == 0)
185 std::vector<size_t> newclus;
186 newclus.push_back(ivh);
187 vhclusters.push_back(newclus);
189 else if (clusmatchlist.size() == 1)
191 vhclusters[clusmatchlist[0]].push_back(ivh);
195 for (
size_t icm=1; icm<clusmatchlist.size(); ++icm)
197 for (
size_t ivh2=0; ivh2<vhclusters[clusmatchlist[icm]].size(); ++ivh2)
199 vhclusters[clusmatchlist[0]].push_back(vhclusters[clusmatchlist[icm]][ivh2]);
203 for (
size_t icm=1; icm<clusmatchlist.size(); ++icm)
205 vhclusters.erase(vhclusters.begin() + (clusmatchlist[icm]-icm+1));
225 std::vector<size_t> identified_conversions;
226 std::vector< std::vector< size_t > > splitclus1;
227 std::vector< std::vector< size_t > > splitclus2;
229 for (
size_t iclus=0; iclus<vhclusters.size(); ++iclus)
231 std::vector<size_t> scc1;
232 std::vector<size_t> scc2;
235 identified_conversions.push_back(iclus);
236 splitclus1.push_back(scc1);
237 splitclus2.push_back(scc2);
243 for (
size_t icc=0; icc<identified_conversions.size(); ++icc)
245 vhclusters.at(identified_conversions.at(icc)) = splitclus1.at(icc);
246 vhclusters.push_back(splitclus2.at(icc));
251 for (
size_t iclus=0; iclus < vhclusters.size(); ++iclus)
253 std::vector<gar::rec::TPCCluster> TPCClusters;
254 std::vector<art::Ptr<gar::rec::TPCCluster> > TPCClusterptrs;
255 for (
size_t ivh=0; ivh<vhclusters[iclus].size(); ++ivh)
257 for (
size_t iTPCCluster=0; iTPCCluster<TPCClustersFromVecHits.at(vhclusters[iclus][ivh]).size(); ++iTPCCluster)
259 TPCClusterptrs.push_back(TPCClustersFromVecHits.at(vhclusters[iclus][ivh]).at(iTPCCluster));
260 TPCClusters.push_back(*TPCClusterptrs.back());
270 auto const trackpointer = trackPtrMaker(trkCol->size()-1);
271 for (
size_t iTPCCluster=0; iTPCCluster<TPCClusters.size(); ++iTPCCluster)
273 TPCClusNumerosUsedInFirstPass.insert(TPCClusters.at(iTPCCluster).getIDNumber());
274 TPCClusterTrkAssns->addSingle(TPCClusterptrs.at(iTPCCluster),trackpointer);
276 for (
size_t ivh=0; ivh<vhclusters[iclus].size(); ++ivh)
278 auto const vhpointer = vhPtrMaker(ivh);
279 vhTrkAssns->addSingle(vhpointer,trackpointer);
297 std::vector<gar::rec::TPCCluster> tcc2pass;
298 std::vector<float> clusx;
299 std::vector<size_t> tcc2passidx;
304 for (
size_t iclus=0; iclus < e_tpcclusters.size(); ++iclus)
306 if (TPCClusNumerosUsedInFirstPass.count(e_tpcclusters.at(iclus).getIDNumber()) == 0)
308 tcc2pass.push_back(e_tpcclusters.at(iclus));
309 tcc2passidx.push_back(iclus);
310 clusx.push_back(tcc2pass.back().Position()[0]);
314 if (tcc2pass.size()>0)
316 std::vector<int> csi(clusx.size());
317 TMath::Sort((
int) clusx.size(),clusx.data(),csi.data());
322 std::vector< std::vector<int> > cluslistf;
323 std::vector<int> trackf(tcc2pass.size());
324 for (
size_t iclus=0; iclus<tcc2pass.size(); ++iclus)
326 const float *cpos = tcc2pass[csi[iclus]].Position();
327 TVector3 hpvec(cpos);
329 float bestsignifs = -1;
331 for (
size_t itcand = 0; itcand < cluslistf.size(); ++itcand)
345 const float *hpos = tcc2pass[csi[cluslistf[itcand].back()]].Position();
346 signifs = (TMath::Sq( (hpos[1]-cpos[1]) ) +
347 TMath::Sq( (hpos[2]-cpos[2]) ))/resolSq;
349 if (bestsignifs < 0 || signifs < bestsignifs)
351 bestsignifs = signifs;
355 if (ibest == -1 || bestsignifs > roadsq)
357 ibest = cluslistf.size();
358 std::vector<int> vtmp;
359 cluslistf.push_back(vtmp);
361 cluslistf[ibest].push_back(iclus);
362 trackf[iclus] = ibest;
365 std::vector< std::vector<int> > cluslistb;
366 std::vector<int> trackb(tcc2pass.size());
367 for (
int iclus=tcc2pass.size()-1; iclus >= 0; --iclus)
369 const float *cpos = tcc2pass[csi[iclus]].Position();
370 TVector3 hpvec(cpos);
372 float bestsignifs = -1;
374 for (
size_t itcand = 0; itcand < cluslistb.size(); ++itcand)
388 const float *hpos = tcc2pass[csi[cluslistb[itcand].back()]].Position();
389 signifs = (TMath::Sq( (hpos[1]-cpos[1]) ) +
390 TMath::Sq( (hpos[2]-cpos[2]) ))/resolSq;
393 if (bestsignifs < 0 || signifs < bestsignifs)
395 bestsignifs = signifs;
399 if (ibest == -1 || bestsignifs > roadsq)
401 ibest = cluslistb.size();
402 std::vector<int> vtmp;
403 cluslistb.push_back(vtmp);
405 cluslistb[ibest].push_back(iclus);
406 trackb[iclus] = ibest;
411 std::vector< std::vector<int> > cluslist;
412 for (
size_t itrack=0; itrack<cluslistf.size(); ++itrack)
415 for (
size_t iclus=0; iclus<cluslistf[itrack].size(); ++iclus)
417 int ihif = cluslistf[itrack][iclus];
418 if (iclus == 0 || (trackb[ihif] != itrackl))
420 std::vector<int> vtmp;
421 cluslist.push_back(vtmp);
422 itrackl = trackb[ihif];
424 cluslist.back().push_back(ihif);
430 for (
size_t itrack=0; itrack<cluslist.size(); ++itrack)
433 std::vector<gar::rec::TPCCluster>
tcl;
434 for (
size_t iclus=0; iclus<cluslist.at(itrack).size(); ++iclus)
436 tcl.push_back(tcc2pass.at(csi[cluslist[itrack].at(iclus)]));
442 auto const trackptr = trackPtrMaker(trkCol->size()-1);
443 for (
size_t iclus=0; iclus<tcl.size(); ++iclus)
445 auto const clusptr = clusPtrMaker(tcc2passidx.at(csi[cluslist[itrack][iclus]]));
446 TPCClusterTrkAssns->addSingle(clusptr,trackptr);
449 std::cout <<
" second-pass track " << itrack <<
" clus: " << iclus <<
" : ";
450 TVector3 cp(tcc2pass[csi[cluslist[itrack][iclus]]].Position());
451 std::cout << cp.X() <<
" " << cp.Y() <<
" " << cp.Z() <<
std::endl;
size_t fMinNumTPCClusters
minimum number of hits for a patrec track
int fPrintLevel
debug printout: 0: none, 1: selected, 2: all
std::string fVecHitLabel
label of module to get the vector hits and associations with hits
bool vhclusmatch(const std::vector< gar::rec::VecHit > &vechits, std::vector< size_t > &cluster, size_t vh)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
std::string fTPCClusterLabel
label of module to get the TPC clusters
float fHitResolYZ
resolution in cm of a hit in YZ (pad size)
gar::rec::Track CreateTrack()
bool conversion_test_split(const std::vector< gar::rec::VecHit > &vechits, std::vector< size_t > &cluster, std::vector< size_t > &splitclus1, std::vector< size_t > &splitclus2)
int makepatrectrack(std::vector< gar::rec::TPCCluster > &tpcclusters, gar::rec::TrackPar &trackpar)
int fXBasedMinTPCClusters
min number of TPC clusters to require on new tracks found with the second pass
bool fXBasedSecondPass
switch to tell us to use the X-based second-pass of patrec
float fSigmaRoad
how many sigma away from a track a hit can be and still add it during patrec
QTextStream & endl(QTextStream &s)