11 #include <Math/DistFunc.h>
33 double xx[3] = {0.0, 0.0, 0.0}, b[3] = { 0.0, 0.0, 0.0};
43 for(
unsigned iq=0; iq<300; iq++) {
47 printf(
"%3d -> %7.2f %7.2f %7.2f\n", iq, b[0], b[1], b[2]);
68 double invp = 0.0, invpt = 0.0;
79 if (!invp && !invpt) {
84 for(
int gr=0; gr<
mGroups.size(); gr++) {
96 id[gr] = ngroup->
Pack(vcrs);
100 double pt = invpt ? 1.0/invpt : sin(theta)/invp;
102 double b =
GetBzAtIP(),
R = 100.0 * (pt/0.03) * (1.0/b);
105 for(
int gr=0; gr<
mGroups.size(); gr++) {
111 double dr = (location->
GetZ() - vz)*tan(theta), alfa = dr/
R;
112 double yy =
R*(1.0 -
cos(alfa)), xx =
R*sin(alfa);
118 id[gr] = ngroup->
Pack(crs);
126 unsigned id,
unsigned cdim,
const double min[],
127 const double max[],
const double gra[])
142 bool cylindricalPreference,
143 const std::set<double> &xMin,
const std::set<double> &xMax,
144 const std::set<double> &yMin,
const std::set<double> &yMax,
145 const std::set<double> &rMin,
const std::set<double> &rMax)
153 std::set<double> spatialSigma, angularSigma;
154 bool cartesianOk =
true, cylindricalOk =
true, useCartesian =
true;
155 for(
unsigned kfnd=0; kfnd<location->
GetNodeCount(); kfnd++) {
165 printf(
"%s -> %8.5f %8.5f\n", node->
GetName(), aSigma, spSigma);
166 if (spSigma) spatialSigma.insert(spSigma);
167 if ( aSigma) angularSigma.insert( aSigma);
177 assert(cartesianOk || cylindricalOk);
178 if ((cylindricalPreference && cylindricalOk) || !cartesianOk) useCartesian =
false;
182 double spSigma = 0.0, aSigma = 0.0;
187 assert(spatialSigma.size());
188 spSigma = *spatialSigma.begin();
191 if (spatialSigma.size()) spSigma = *spatialSigma.begin();
192 if (angularSigma.size()) aSigma = *angularSigma.begin();
196 assert(spSigma && (*rMax.rbegin()));
198 aSigma = spSigma/(*rMax.rbegin()/5);
209 double min[3],
max[3], gra[3];
211 _template->
FillMinMaxArrays(useCartesian, xMin, xMax, yMin, yMax, rMin, rMax, min, max);
213 printf(
"%7.2f -> %2d --> %d\n", location->
GetZ(), tmpl, location->
GetMdim(tmpl));
214 printf(
" -> xmin=%7.2f, xmax =%7.2f, ymin=%7.2f, ymax=%7.2f\n",
215 min[0], max[0], min[1], max[1]);
250 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
257 if (!member)
continue;
276 assert(trknode && !trknode->
IsFired());
289 Int_t mchitid = hit->GetRefIndex();
290 assert(mchitid >= 0);
342 const unsigned *
id = match->
GetIdPtr();
343 for(
unsigned iq=0; iq<
GetDdim(); iq++) {
359 void FwdHoughTree::SeparateSiamTracks(
MatchCandidate *match,
unsigned minHitCount,
360 std::vector<MatchCandidate*> *newMatches)
367 unsigned overallHitCount = 0;
368 for(
int gr=0; gr<
GetGdim(); gr++)
371 unsigned maxTrackCount = overallHitCount / minHitCount;
372 printf(
"%d %d\n", overallHitCount, maxTrackCount);
374 assert(maxTrackCount);
376 unsigned hCounters[maxTrackCount], toggle = 0;
377 memset(hCounters, 0x00,
sizeof(hCounters));
379 for(
int gr=0; gr<
GetGdim(); gr++) {
382 if (multi > maxTrackCount) multi = maxTrackCount;
383 for(
unsigned iq=0; iq<multi; iq++) {
385 toggle = (toggle+1)%maxTrackCount;
390 unsigned splitValue = 0;
391 for(
unsigned tr=0; tr<maxTrackCount; tr++)
392 if (hCounters[tr] >= minHitCount)
395 printf(
"Double counts: %2d %2d\n", hCounters[0], hCounters[1]);
396 printf(
"Will try to split into %2d tracks\n", splitValue);
402 printf(
" Building KF fit of original siam group track ...\n");
421 std::multimap<double, unsigned> suggestions;
422 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
425 double smootherDimSum = 0;
426 double smootherChiSquareSum = 0.0;
429 if (!member)
continue;
446 smootherDimSum += trknode->
GetMdim();
451 suggestions.insert(std::pair<
double,
452 unsigned>(ROOT::Math::chisquared_cdf_c(smootherChiSquareSum, smootherDimSum), gr));
455 if (!suggestions.size()) {
456 printf(
"Give up on this siam group, sorry ...\n");
461 printf(
" -> %d suggestions\n", suggestions.size());
468 for(std::multimap<double, unsigned>::iterator
it=suggestions.begin();
it!=suggestions.end();
it++) {
469 printf(
"%10.7f -> gr#%02d\n",
it->first,
it->second);
472 unsigned worstGroup = suggestions.begin()->second;
473 printf(
" -> so worst group is gr#%02d\n", worstGroup);
477 for(
unsigned tr=0; tr<splitValue; tr++) {
486 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
487 unsigned mmCounter = 0;
494 if (!member)
continue;
498 if (gr == worstGroup && mmCounter++ != tr)
continue;
509 newMatches->push_back(track);
514 unsigned maxAliveMemberCount = 0;
515 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
521 if (!member)
continue;
529 unsigned unresolvedGroupCount =
mGroups.size() - 1;
530 bool resolved[
mGroups.size()]; memset(resolved, 0x00,
sizeof(resolved));
531 resolved[worstGroup] =
true;
539 double ccdf[
mGroups.size()][splitValue][maxAliveMemberCount];
542 for(
unsigned tr=0; tr<splitValue; tr++) {
557 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
558 if (resolved[gr])
continue;
566 if (!member)
continue;
594 bool conflicts[
mGroups.size()], cleanGroupsExist =
false;
595 memset(conflicts, 0x00,
sizeof(conflicts));
597 int hitIds[
mGroups.size()][splitValue];
598 for(
unsigned gr=0; gr<
mGroups.size(); gr++)
599 for(
unsigned tr=0; tr<splitValue; tr++)
602 std::multimap<double, unsigned> significances;
604 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
605 if (resolved[gr])
continue;
607 bool usedHit[mnum[gr]]; memset(usedHit, 0x00,
sizeof(usedHit));
608 bool happyTrack[splitValue]; memset(happyTrack, 0x00,
sizeof(happyTrack));
611 std::multimap<double, unsigned> tracksToHits[splitValue];
614 for(
unsigned tr=0; tr<splitValue; tr++) {
615 for(
unsigned mm=0;
mm<mnum[gr];
mm++) {
616 tracksToHits[tr].insert(std::pair<double, unsigned>(ccdf[gr][tr][
mm], mm));
623 double significance = 1.0;
626 for(
unsigned tr=0; tr<splitValue; tr++) {
627 for(std::multimap<double, unsigned>::reverse_iterator
it = tracksToHits[tr].rbegin();
628 it != tracksToHits[tr].rend();
it++) {
630 if (!
it->first)
break;
632 if (!usedHit[
it->second]) {
634 printf(
"#gr%02d: setting tr%02d as owner of mm#%02d\n", gr, tr,
it->second);
635 hitIds[gr][tr] =
it->second;
637 happyTrack[tr] =
true;
638 usedHit[
it->second] =
true;
641 std::multimap<double, unsigned>::reverse_iterator is =
it; is++;
642 printf(
"#gr%02d, tr%02d: %10.6f, %10.6f\n", gr, tr,
it->first, is->first);
643 if (is != tracksToHits[tr].rend()) significance *= is->first/
it->first;
651 if (!happyTrack[tr] || hitIds[gr][tr] != tracksToHits[tr].rbegin()->second) {
652 printf(
"Track tr#%02d is not happy about gr#%02d\n", tr, gr);
653 conflicts[gr] =
true;
659 if (!conflicts[gr]) cleanGroupsExist =
true;
661 printf(
"gr#%02d (%d) %10.6f\n", gr, conflicts[gr], significance);
662 significances.insert(std::pair<double, unsigned>(significance, gr));
665 printf(
"Clean group flag: %d\n", cleanGroupsExist);
667 int weakGroup = -1; assert(significances.size());
668 for(std::multimap<double, unsigned>::iterator
it = significances.begin();
669 it != significances.end();
it++) {
671 unsigned gr =
it->second;
673 if (cleanGroupsExist && conflicts[gr])
continue;
678 assert(weakGroup != -1);
679 printf(
"Weak group: %02d\n", weakGroup);
682 for(
unsigned tr=0; tr<splitValue; tr++) {
687 if (!member)
continue;
691 if (hitIds[weakGroup][tr] == -1 ||
mm != hitIds[weakGroup][tr])
696 resolved[weakGroup] =
true;
697 unresolvedGroupCount--;
700 if (!unresolvedGroupCount)
break;
713 printf(
" Resolving ambiguities ...\n");
736 std::multimap<double, std::pair<unsigned,unsigned> > ccdfs;
738 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
747 ccdfs.insert(std::pair<
double, std::pair<unsigned,unsigned> >
753 assert(ccdfs.size());
754 std::pair<unsigned,unsigned> worstMember = ccdfs.begin()->second;
758 std::multimap<double, unsigned> separations;
764 std::multimap<double, unsigned> inspections[
mGroups.size()];
766 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
778 double best = inspections[gr].rbegin()->first, worst = inspections[gr].rend()->first;
783 printf(
"%f %f\n", best, worst); fflush(stdout);
784 double separation = (best > 0.0 && worst > 1E-10) ? best / worst : 1E10;
785 separations.insert(std::pair<double, unsigned>(separation, gr));
788 unsigned highestSeparationGroup = separations.rbegin()->second;
789 match->
ResetMemberPtr(highestSeparationGroup, inspections[highestSeparationGroup].begin()->second);
799 if (!member)
return 0;
823 #define _CCDF_MIN_ ( 0.010)
824 #define _SEPARATION_MIN_ (10.000)
830 printf(
" Resolving ambiguities ...\n");
858 std::multimap<double, unsigned> inspections[
mGroups.size()];
860 bool resolved =
false;
861 std::multimap<double, unsigned> separations;
865 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
873 if (!member)
continue;
888 inspections[gr].insert(std::pair<
double,
892 Int_t mchitid = hit->GetRefIndex();
893 assert(mchitid >= 0);
896 printf(
"gr#%02d, mm#%02d %p (%d,%d) %p -> chi^2 %7.3f, CCDF %10.7f ... %3d\n",
908 assert(inspections[gr].size());
909 if (inspections[gr].rbegin()->first >= _CCDF_MIN_) {
913 std::multimap<double, unsigned>::reverse_iterator
it = inspections[gr].rbegin(); it++;
917 double separation = it->first > 0.0 ? fabs(log(it->first / inspections[gr].rbegin()->first)) : 0.0;
918 separations.insert(std::pair<double, unsigned>(separation, gr));
919 printf(
" best-to-next separation %10.8f; best is mm#%02d ...\n", separation,
920 inspections[gr].rbegin()->second);
924 if (inspections[gr].rbegin()->first >= _CCDF_MIN_ &&
925 separation > _SEPARATION_MIN_) {
930 if (!member)
continue;
933 if (
mm == inspections[gr].rbegin()->second) {
949 separations.insert(std::pair<double, unsigned>(0.0, gr));
956 assert(separations.size());
957 unsigned highestSeparationGroup = separations.rbegin()->second;
959 unsigned mm = inspections[highestSeparationGroup].begin()->second;
960 printf(
"Highest best-to-worst separation group: gr#%02d -> removing mm#%02d ...\n",
961 highestSeparationGroup, mm);
999 printf(
" Final fit started ...\n");
1020 std::map<unsigned, unsigned> ptracks;
1022 std::multimap<unsigned, unsigned> ordered;
1024 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
1030 if (!member)
continue;
1045 Int_t mchitid = hit->GetRefIndex();
1046 assert(mchitid >= 0);
1050 printf(
" @@@ gr#%02d, mm#%02d %p (%d,%d) %p -> chi^2 %c%7.3f (%d), CCDF %8.5f ... %3d\n",
1063 for(std::map<unsigned, unsigned>::iterator it=ptracks.begin(); it != ptracks.end(); it++) {
1064 ordered.insert(std::pair<unsigned, unsigned>(it->second, it->first));
1093 for(
unsigned gr=0; gr<
mGroups.size(); gr++) {
1098 if (!member)
continue;