c++ - Logic Help: comparing values and taking the smallest distance, while removing it from the list of "available to compare" -
okay, have been set task of comparing list of photons using 1 method (iu) , comparing (tsp). need take first iu photon , compare distances all of tsp photons, find smallest distance, , "pair" them (i.e. set them both in arrays same index). then, need take next photon in iu list, , compare of tsp photons, minus 1 chosen already. know need use boolean array of sorts, keeping counter. can't seem logic out entirely.
the code below not standard c++ syntax, written interact root (cern data analysis software). if have questions syntax better understand code, please ask. i'll happily answer.
i have arrays , variables declared already. types see called eemcparticlecandidate , that's type reads tree of information, , have whole set of classes , headers tell how behave.
thanks.
bool_t used[2]; if (num[0]==2 && num[1]==2) { titer photoniteriu(mphotonarray[0]); while(iu_photon=(eemcparticlecandidate_t*)photoniteriu.next()){ if (iu_photon->e > thresh2) { distmin=1000.0; index = 0; iu_photonarray[index] = iu_photon; titer photonitertsp(mphotonarray[1]); while(tsp_photon=(eemcparticlecandidate_t*)photonitertsp.next()) { if (tsp_photon->e > thresh2) { float_t xpos_iu = iu_photon->position.fx; float_t ypos_iu = iu_photon->position.fy; float_t xpos_tsp = tsp_photon->position.fx; float_t ypos_tsp = tsp_photon->position.fy; distance_1 = find distance //formula didnt fit here // if (distance_1 < distmin){ distmin = distance_1;; (int_t i=0;i<2;i++){ used[i] = false; } //for used[index] = true; tsp_photonarray[index] = tsp_photon; index++; } //if } //if thresh } // while tsp } //if thresh } // while iu
thats have @ moment... work in progress, realize of braces aren't closed. simple logic question.
this may take few iterations.
as particle physicist, should understand importance of breaking things down component parts. let's start iterating on tsp photons. looks if relevant code here:
titer photonitertsp(mphotonarray[1]); while(tsp_photon=(eemcparticlecandidate_t*)photonitertsp.next()) { ... if(a condition met) tsp_photonarray[index] = tsp_photon; }
so tsp_photon
pointer, copying array tsp_photonarray
(if energy of photon exceeds fixed threshold), , go lot of trouble keeping track of pointers have been copied. there better way, let's consider problem of finding best match:
distmin=1000.0; while(tsp_photon= ... ) { distance_1 = compute_distance_somehow(); if (distance_1 < distmin) { distmin = distance_1; tsp_photonarray[index] = tsp_photon; // <-- bad index++; // <-- bad } }
this wrong. suppose find tsp_photon smallest distance yet seen. haven't yet checked tsp photons, might not best, store pointer anyway, and increment index. if find match that's better, you'll store 1 too. conceptually, should this:
distmin=1000.0; best_photon_yet = null; while(tsp_photon= ... ) { distance_1 = compute_distance_somehow(); if (distance_1 < distmin) { distmin = distance_1; best_pointer_yet = tsp_photon; } } // we've finished searching whole list of tsp photons. tsp_photonarray[index] = best_photon_yet; index++;
post comment answer, telling me if makes sense; if so, can proceed, if not, i'll try clarify.
Comments
Post a Comment