28 bool SortByLength(CluLen
const&
c1, CluLen
const&
c2)
30 return c1.length > c2.length;
43 fKSCut = pset.
get<
double>(
"KSCut");
44 fEnableU = pset.
get<
bool>(
"EnableU");
45 fEnableV = pset.
get<
bool>(
"EnableV");
46 fEnableZ = pset.
get<
bool>(
"EnableZ");
50 std::vector<std::vector<unsigned int>> ClusterMatchTQ::MatchedClusters(
55 std::vector<std::vector<unsigned int>> matchedclusters;
59 int nplanes = wireReadoutGeom.Nplanes();
62 std::vector<std::vector<TH1D>> signals(nplanes);
64 std::vector<std::vector<unsigned int>> Cls(nplanes);
65 std::vector<std::vector<CluLen>> clulens(nplanes);
67 for (
size_t iclu = 0; iclu < clusterlist.size(); ++iclu) {
69 float wire_pitch = wireReadoutGeom.Plane(clusterlist[iclu]->
Plane()).WirePitch();
71 float w0 = clusterlist[iclu]->StartWire();
72 float w1 = clusterlist[iclu]->EndWire();
73 float t0 = clusterlist[iclu]->StartTick();
74 float t1 = clusterlist[iclu]->EndTick();
81 clulen.length = std::hypot((w0 - w1) * wire_pitch, x0 -
x1);
83 switch (clusterlist[iclu]->View()) {
85 if (fEnableU) clulens[0].push_back(clulen);
88 if (fEnableV) clulens[1].push_back(clulen);
91 if (fEnableZ) clulens[2].push_back(clulen);
98 for (
size_t i = 0; i < clulens.size(); ++i) {
99 std::sort(clulens[i].
begin(), clulens[i].
end(), SortByLength);
100 for (
size_t j = 0; j < clulens[i].size(); ++j) {
101 Cls[i].push_back(clulens[i][j].index);
105 for (
int i = 0; i < nplanes; ++i) {
106 for (
size_t ic = 0; ic < Cls[i].size(); ++ic) {
108 Form(
"sig_%d_%d", i,
int(ic)), Form(
"sig_%d_%d", i,
int(ic)), nts + 100, -100, nts);
110 Form(
"sigint_%d_%d", i,
int(ic)), Form(
"sigint_%d_%d", i,
int(ic)), nts + 100, -100, nts);
111 std::vector<art::Ptr<recob::Hit>> hitlist = fm.at(Cls[i][ic]);
112 std::sort(hitlist.begin(), hitlist.end(),
SortByWire);
114 for (
auto theHit = hitlist.begin(); theHit != hitlist.end(); theHit++) {
116 double time = (*theHit)->PeakTime();
118 (*theHit)->WireID().Plane, (*theHit)->WireID().TPC, (*theHit)->WireID().Cryostat);
120 double charge = (*theHit)->Integral();
121 int bin = sig.FindBin(time);
122 sig.SetBinContent(bin, sig.GetBinContent(bin) + charge);
123 for (
int j = bin; j <= sig.GetNbinsX(); ++j) {
124 sigint.SetBinContent(j, sigint.GetBinContent(j) + charge);
127 if (sigint.Integral()) sigint.Scale(1. / sigint.GetBinContent(sigint.GetNbinsX()));
128 signals[i].push_back(sigint);
133 std::vector<int> matched(clusterlist.size());
134 for (
size_t i = 0; i < clusterlist.size(); ++i)
137 for (
int i = 0; i < nplanes - 1; ++i) {
138 for (
int j = i + 1; j < nplanes; ++j) {
139 for (
size_t c1 = 0;
c1 < Cls[i].size(); ++
c1) {
140 for (
size_t c2 = 0;
c2 < Cls[j].size(); ++
c2) {
143 if (clusterlist[Cls[i][
c1]]->View() == clusterlist[Cls[j][
c2]]->View())
continue;
145 if (clusterlist[Cls[i][
c1]]->
Plane().Cryostat !=
146 clusterlist[Cls[j][
c2]]->
Plane().Cryostat)
148 if (clusterlist[Cls[i][
c1]]->
Plane().TPC != clusterlist[Cls[j][
c2]]->
Plane().TPC)
151 if (matched[Cls[i][
c1]] == 1 && matched[Cls[j][
c2]] == 1)
continue;
154 if (signals[i][
c1].Integral() && signals[j][
c2].Integral())
155 ks = signals[i][
c1].KolmogorovTest(&signals[j][
c2]);
158 <<
"One of the two clusters appears to be empty: " << clusterlist[Cls[i][
c1]]->ID()
159 <<
" " << clusterlist[Cls[j][
c2]]->ID() <<
" " << i <<
" " << j <<
" " <<
c1 <<
" " 160 << c2 <<
" " << signals[i][
c1].Integral() <<
" " << signals[j][
c2].Integral();
169 for (
size_t l = 0; l < matchedclusters.size(); ++l) {
170 for (
size_t m = 0; m < matchedclusters[l].size(); ++m) {
171 if (matchedclusters[l][m] == Cls[i][
c1]) {
175 else if (matchedclusters[l][m] == Cls[j][c2]) {
183 bool matchview =
false;
185 for (
size_t ii = 0; ii < matchedclusters[imatch].size(); ++ii) {
186 if (clusterlist[matchedclusters[imatch][ii]]->View() ==
187 clusterlist[Cls[i][
c1]]->View()) {
190 if (fm.at(Cls[i][
c1]).size() > fm.at(matchedclusters[imatch][ii]).size()) {
191 matched[matchedclusters[imatch][ii]] = 0;
192 matchedclusters[imatch][ii] = Cls[i][
c1];
193 matched[Cls[i][
c1]] = 1;
198 matchedclusters[imatch].push_back(Cls[i][
c1]);
199 matched[Cls[i][
c1]] = 1;
203 bool matchview =
false;
204 for (
size_t jj = 0; jj < matchedclusters[imatch].size(); ++jj) {
205 if (clusterlist[matchedclusters[imatch][jj]]->View() ==
206 clusterlist[Cls[j][
c2]]->View()) {
209 if (fm.at(Cls[j][c2]).size() > fm.at(matchedclusters[imatch][jj]).size()) {
210 matched[matchedclusters[imatch][jj]] = 0;
211 matchedclusters[imatch][jj] = Cls[j][
c2];
212 matched[Cls[j][
c2]] = 1;
217 matchedclusters[imatch].push_back(Cls[j][c2]);
218 matched[Cls[j][
c2]] = 1;
223 std::vector<unsigned int>
tmp;
224 tmp.push_back(Cls[i][
c1]);
225 tmp.push_back(Cls[j][c2]);
226 matchedclusters.push_back(tmp);
227 matched[Cls[i][
c1]] = 1;
228 matched[Cls[j][
c2]] = 1;
236 for (
size_t i = 0; i < matchedclusters.size(); ++i) {
237 if (matchedclusters[i].
size())
239 for (
size_t j = 0; j < matchedclusters[i].size(); ++j) {
244 return matchedclusters;
code to link reconstructed objects back to the MC truth information
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
double GetXTicksOffset(int p, int t, int c) const
Float_t x1[n_points_granero]
Plane(const Point_t &planePos, const Vector_t &planeDir)
Constructor from reference position on the plane and direction orthogonal to the plane.
Planes which measure Z direction.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
WireID_t Wire
Index of the wire within its plane.
geo::WireID const & WireID() const
Initial tdc tick for hit.
Cluster finding and building.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
bool SortByWire(art::Ptr< recob::Hit > const &h1, art::Ptr< recob::Hit > const &h2)
T get(std::string const &key) const
unsigned int NumberTimeSamples() const
double ConvertTicksToX(double ticks, int p, int t, int c) const
Encapsulate the construction of a single detector plane .
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
recob::tracking::Plane Plane