/****************************************************************************** * Cpr Comparisons classes definition file * * * * Author: Bob Wagner, Argonne CDF Group * * Phone 630-252-6321 (Argonne) 630-840-8436 (Fermilab) * * * * Description: Algorithmic function objects that do comparisons of CPR * * quantities. These are meant to be used with STL algorithms. * * Actually contains only CPR2 global sorter at present. * * * * Revision History: * * 19-Oct-2004 Bob Wagner Initial creation from ces_comp.cc * * 20-Oct-2004 Bob Wagner Change type of padlist passed to cp2_find_pad* * from vector to int*. * * * *****************************************************************************/ //-------------------------------------- // The Cpr Comparison Classes' Header -- //-------------------------------------- #include "Calor/cpr_comp.hh" //--------------- // C++ Headers -- //--------------- #include #include #include "Rtypes.h" //------------------------------- // Collaborating Class Headers -- //------------------------------- #include "CalorGeometry/Cpr2Geom.hh" // ************************************************ // Global sort function to order CPR2 pads by *** // distance from track/photon intersection with *** // CPR2 plane *** // ************************************************ void cp2_find_pad( float zGlobal, float phiGlobal, int* padlist ) { int compare_floats(const void *a, const void *b); int ipad, ipad2; float delr[54], delr2[54]; float delz, delx; // Need to convert phiGlobal from radians to degrees phiGlobal = 180.0 * phiGlobal / M_PI; int tmpphi = (int) phiGlobal; float local_phi = (tmpphi % 15) + (phiGlobal-tmpphi); for(ipad=0; ipad<54; ++ipad) { delz = fabs(zGlobal)-z_middle[ipad]; delx = (local_phi-phi_middle[ipad])*(12.5/4.13); delr[ipad] = sqrt(delz*delz + delx*delx); delr2[ipad] = delr[ipad]; } int count = sizeof(delr)/sizeof(float); qsort(delr,count,sizeof(float),compare_floats); for(ipad=0; ipad<54; ++ipad) { for(ipad2=0; ipad2<54; ++ipad2) { if(delr[ipad] == delr2[ipad2]) { *padlist=ipad2; ++padlist; break; } } } } // ************************************************ // Helper predicate for sorting CPR2 pads *** // ************************************************ //extern "C" int compare_floats(const void *a, const void *b) int compare_floats(const void *a, const void *b) { float aa = *(float*)a; float bb = *(float*)b; if (aa < bb) return -1; else if (aa > bb) return 1; else return 0; } /****************************************************************************** * ALL DONE * *****************************************************************************/