#include #include #include #include #include #include #include #include #ifdef SOLARIS #include #include #endif #ifdef LINUX #include #endif #include "ctk.h" /*---------*/ /* globals */ /*---------*/ #define DEBUG 0 volatile extern TRACKINGPAR Pars; /* tracking parameters */ /*--------------------------------------------------------*/ int matchMaker (int ii, int jj, int evno, STAT * ctkStat, CLUSTER_INTPTS Clstr[MAXCLUSTERHITS], int *nClusters, float target_pos[3]) { /* declarations */ float d1, dist; int try, j; if (Pars.nprint > 0 || DEBUG) { printf ("** matchMaker called at event no %i, ", evno); printf ("combine cluster %i and %i?\n", ii, jj); }; /* find distance beween them */ /* return if they are too far from one another */ /* Pars.matchmakerMaxDist is already squared */ /* dist = sqrtf (dist); */ /* kickout as soon as we can */ dist = 0; d1 = Clstr[ii].intpts[0].xx - Clstr[jj].intpts[0].xx; dist += d1 * d1; if (dist > Pars.matchmakerMaxDist) return (1); d1 = Clstr[ii].intpts[0].yy - Clstr[jj].intpts[0].yy; dist += d1 * d1; if (dist > Pars.matchmakerMaxDist) return (1); d1 = Clstr[ii].intpts[0].zz - Clstr[jj].intpts[0].zz; dist += d1 * d1; if (dist > Pars.matchmakerMaxDist) return (1); /* if we get here, the two single hits */ /* are close enought to warrent making */ /* a trial cluster and track it */ try = (*nClusters); Clstr[try].ndet = 2; Clstr[try].esum = Clstr[ii].esum + Clstr[jj].esum; #if SIMULATED Clstr[try].intpts[0].esumOrig = Clstr[ii].intpts[0].esumOrig; Clstr[try].intpts[0].origPos = Clstr[ii].intpts[0].origPos; #endif Clstr[try].intpts[0].shellHitPos = Clstr[ii].intpts[0].shellHitPos; Clstr[try].intpts[0].xx = Clstr[ii].intpts[0].xx; Clstr[try].intpts[0].yy = Clstr[ii].intpts[0].yy; Clstr[try].intpts[0].zz = Clstr[ii].intpts[0].zz; Clstr[try].intpts[0].timestamp = Clstr[ii].intpts[0].timestamp; Clstr[try].intpts[0].detno = Clstr[ii].intpts[0].detno; #if SIMULATED Clstr[try].intpts[1].esumOrig = Clstr[jj].intpts[0].esumOrig; Clstr[try].intpts[1].origPos = Clstr[jj].intpts[0].origPos; #endif Clstr[try].intpts[1].shellHitPos = Clstr[ii].intpts[0].shellHitPos; Clstr[try].intpts[1].xx = Clstr[jj].intpts[0].xx; Clstr[try].intpts[1].yy = Clstr[jj].intpts[0].yy; Clstr[try].intpts[1].zz = Clstr[jj].intpts[0].zz; Clstr[try].intpts[1].timestamp = Clstr[jj].intpts[0].timestamp; Clstr[try].intpts[1].detno = Clstr[jj].intpts[0].detno; /* initialize trial cluster for tracking */ for (j = 0; j < Clstr[try].ndet; j++) Clstr[try].intpts[j].order = -1; Clstr[try].valid = 1; Clstr[try].fom = MAXFOM; Clstr[try].tracked = 0; #if (DEBUG) printf ("combined trial cluster: Clstr[try].ndet=%i\n", Clstr[try].ndet); printCluster (try, Clstr); #endif /* track the cluster */ #if (DEBUG) printf ("tracking...\n"); fflush (stdout); #endif ctksort (try, Clstr, nClusters); switch (Pars.trackOps[Clstr[try].ndet]) { case 0: ctktk0 (try, target_pos, ctkStat, Clstr, nClusters); break; case 1: ctktk1 (try, target_pos, ctkStat, Clstr, nClusters); break; case 3: ctktk3 (try, target_pos, ctkStat, Clstr, nClusters); break; case 4: ctktk4 (try, target_pos, ctkStat, Clstr, nClusters); break; case 5: ctktk5 (try, target_pos, ctkStat, Clstr, nClusters); break; default: printf ("ctk: tracking option not known!?\n, Quit"); exit (1); }; /* if OK, promote to valid cluster */ if (Clstr[try].fom < Pars.matchmaker_kickoutfom) { /* validate the new combined cluster */ Clstr[try].valid = 1; (*nClusters)++; /* invalidate the two clusters we combined from */ Clstr[ii].valid = 0; Clstr[jj].valid = 0; if (Pars.nprint > 0 || DEBUG) { printf ("...matchMaker: success! made the combination> \n"); fflush (stdout); printCluster (try, stdout, Clstr); }; return (0); } else { Clstr[try].valid = 0; if (Pars.nprint > 0 || DEBUG) { printf ("...matchMaker: combination not OK, FOM=%f \n", Clstr[try].fom); fflush (stdout); }; return (2); }; if (1) exit (0); /* done */ return (0); };