DriveHough.c

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2005 Badri Krishnan, Alicia Sintes  
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with with program; see the file COPYING. If not, write to the 
00016  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00017  *  MA  02111-1307  USA
00018  */
00019 
00020 
00021 /**
00022  * \author Alicia Sintes, Badri Krishnan 
00023  * \defgroup houghPulsar
00024  * \ingroup pulsarHough
00025  * \file DriveHough.c 
00026  * \brief Routines for building and updating the space of partial Hough map
00027  *  derivatives and related functions needed for the
00028  *  construction of total Hough maps
00029  */
00030 
00031 /************************************ <lalVerbatim file="DriveHoughCV">
00032 Author: Sintes, A. M. 
00033 $Id: DriveHough.c,v 1.19 2007/11/14 15:49:54 bema Exp $
00034 ************************************* </lalVerbatim> */
00035 
00036 
00037 /* <lalLaTeX>
00038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00039 \subsection{Module \texttt{DriveHough.c}}
00040 \label{ss:DriveHough.c}
00041 
00042 Routines for building and updating the space of partial Hough map derivatives
00043 ({\sc phmd}), 
00044 and related functions needed for the construction of  total Hough maps at
00045 different frequencies and possible residual spin down parameters.
00046 
00047 
00048 
00049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00050 \subsubsection*{Prototypes}
00051 \vspace{0.1in}
00052 \input{DriveHoughD}
00053 \index{\verb&LALHOUGHConstructSpacePHMD()&}
00054 \index{\verb&LALHOUGHupdateSpacePHMDup()&}
00055 \index{\verb&LALHOUGHupdateSpacePHMDdn()&}
00056 \index{\verb&LALHOUGHConstructHMT()&}
00057 \index{\verb&LALHOUGHComputeFBinMap()&}
00058 
00059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00060 \subsubsection*{Description}
00061 
00062 ${}$
00063 
00064 The function \verb&LALHOUGHConstructSpacePHMD()& constructs the space of {\sc
00065 phmd} \verb&PHMDVectorSequence *phmdVS&, given a 
00066 \verb&HOUGHPeakGramVector *pgV& and \verb&HOUGHptfLUTVector *lutV&.
00067 The minimum frequency bin present corresponds to \verb&phmdVS->fBinMin& and the
00068 total number of different frequencies is 
00069 \verb&phmdVS->nfSize&. At this moment the \verb@fBinMin@ line corresponds to the
00070 first row of the cylinder and \verb&phmdVS->breakLine& is set to zero. 
00071 \verb&phmdVS->breakLine&
00072  $\in\, [0,$\verb&nfSize&) is {\it the pointer} which
00073  identifies the position of the  \verb@fBinMin@ row in the circular-cylinder
00074  buffer. \\
00075  
00076  
00077  The function \verb&LALHOUGHupdateSpacePHMDup()& updates the space of {\sc
00078 phmd} increasing the frequency \verb&phmdVS->fBinMin& by one.\\
00079 
00080   The function \verb&LALHOUGHupdateSpacePHMDdn()& updates the space of {\sc
00081 phmd} decreasing the frequency \verb&phmdVS->fBinMin& by one.\\
00082 
00083 Given \verb@PHMDVectorSequence *phmdVS@, the space of {\sc phmd}, and 
00084 \verb&UINT8FrequencyIndexVector *freqInd&, a structure containing the frequency
00085 indices  of the   {\sc phmd} at different time stamps that have to be combined
00086 to form a Hough map, the function \verb&LALHOUGHConstructHMT()& produces the
00087 total Hough map.\\
00088   
00089   The function \verb&LALHOUGHComputeFBinMap()& computes the corresponding frequency bin of
00090   a  {\sc phmd} \verb&UINT8 *fBinMap& for a given  intrinsic
00091   frequency bin of a source \verb&UINT8 *f0Bin&, and information regarding the
00092   time and the 
00093   residual spin down parameters \verb&HOUGHResidualSpinPar *rs&.
00094   
00095   
00096 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00097 \subsubsection*{Uses}
00098 \begin{verbatim}
00099 LALHOUGHPeak2PHMD()
00100 LALHOUGHAddPHMD2HD()
00101 LALHOUGHIntegrHD2HT()
00102 \end{verbatim}
00103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00104 \subsubsection*{Notes}
00105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00106 \vfill{\footnotesize\input{DriveHoughCV}}
00107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00108 </lalLaTeX> */
00109 
00110 
00111 
00112 #include <lal/LALHough.h>
00113 
00114 NRCSID (DRIVEHOUGHC, "$Id: DriveHough.c,v 1.19 2007/11/14 15:49:54 bema Exp $");
00115 
00116 #define rint(x) floor((x)+0.5)
00117 
00118 /*
00119  * The functions that make up the guts of this module
00120  */
00121 
00122 
00123 /** Constructs cylindrical buffer of partial hough map derivatives.  
00124     For each timestamp, there are nfsize number of look up tables. 
00125     The input is a vector of peakgrams and a set of look up tables 
00126     for each timestamp.  A partial hough map derivative basically 
00127     contains pointers to a left and right border in a look up table.
00128     For every selected peak, we get an annulus bounded by a left and 
00129     right border, and this function figures out what the borders are 
00130     and constructs pointers to them */
00131 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00132 void LALHOUGHConstructSpacePHMD  (LALStatus            *status, 
00133                                   PHMDVectorSequence   *phmdVS, /**< Cylindrical buffer of PHMDs */
00134                                   HOUGHPeakGramVector  *pgV, /**< Vetor of peakgrams */
00135                                   HOUGHptfLUTVector    *lutV /**< vector of look up tables */) 
00136 { /*   *********************************************  </lalVerbatim> */
00137 
00138   UINT4    k,j;
00139   UINT4    nfSize;    /* number of different frequencies */
00140   UINT4    length;    /* number of elements for each frequency */
00141   UINT8    fBinMin;   /* present minimum frequency bin */ 
00142   UINT8    fBin;      /* present frequency bin */
00143   REAL8    deltaF;    /* frequency resolution */
00144 
00145 
00146   /* --------------------------------------------- */
00147   INITSTATUS (status, "LALHOUGHConstructSpacePHMD", DRIVEHOUGHC);
00148   ATTATCHSTATUSPTR (status); 
00149 
00150 
00151   /*   Make sure the arguments are not NULL: */ 
00152   ASSERT (phmdVS, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00153   ASSERT (pgV,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00154   ASSERT (lutV,   status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00155   /* -------------------------------------------   */
00156 
00157   ASSERT (phmdVS->phmd, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00158   ASSERT (pgV->pg,      status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00159   ASSERT (lutV->lut,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00160   /* -------------------------------------------   */
00161 
00162   /* Make sure there is no size mismatch */
00163   ASSERT (pgV->length == lutV->length, status, 
00164           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00165   ASSERT (pgV->length == phmdVS->length, status, 
00166           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00167   /* -------------------------------------------   */
00168 
00169   /* Make sure there are elements to be computed*/
00170   ASSERT (phmdVS->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00171   ASSERT (phmdVS->nfSize, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00172 
00173   /* at the  beggining, the  fBinMin line corresponds to the first row */
00174   phmdVS->breakLine = 0; /* mark [0,nfSize) (of the circular buffer)
00175                             pointing to the starting of the fBinMin line */
00176 
00177   length = phmdVS->length;
00178   nfSize = phmdVS->nfSize; 
00179   fBinMin = phmdVS->fBinMin;
00180   deltaF =  phmdVS->deltaF = lutV->lut[0].deltaF;
00181 
00182 
00183   for ( k=0; k<length; ++k ){ 
00184 
00185     /* make sure all deltaF are consistent */
00186     ASSERT (deltaF == lutV->lut[k].deltaF, 
00187             status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00188 
00189     fBin = fBinMin;
00190 
00191     for ( j=0; j<  nfSize; ++j ){ 
00192       phmdVS->phmd[ j*length+k ].fBin = fBin;
00193 
00194       TRY( LALHOUGHPeak2PHMD(status->statusPtr,
00195                              &(phmdVS->phmd[ j*length+k ]),
00196                              &(lutV->lut[k]), &(pgV->pg[k]) ), status);
00197       ++fBin;
00198     }
00199   }
00200  
00201 
00202   DETATCHSTATUSPTR (status);
00203    /* normal exit */
00204   RETURN (status);
00205 }
00206 
00207 
00208 /** Function for shifting the cylindrical buffer of PHMDs up by one
00209     frequency bin -- the lowest frequency bin is dropped and an 
00210     extra frequency bin is added at the highest frequency */
00211 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00212 void LALHOUGHupdateSpacePHMDup  (LALStatus            *status, 
00213                                   PHMDVectorSequence   *phmdVS,
00214                                   HOUGHPeakGramVector  *pgV, 
00215                                   HOUGHptfLUTVector    *lutV) 
00216 { /*   *********************************************  </lalVerbatim> */
00217   UINT4    k,breakLine;
00218   UINT4    nfSize;    /* number of different frequencies */
00219   UINT4    length;    /* number of elements for each frequency */
00220   UINT8    fBinMin;   /* minimum frequency bin */ 
00221   UINT8    fBin;      /* present frequency bin */
00222   REAL8    deltaF;    /* frequency resolution */
00223 
00224 
00225   /* --------------------------------------------- */
00226   INITSTATUS (status, "LALHOUGHupdateSpacePHMDup", DRIVEHOUGHC);
00227   ATTATCHSTATUSPTR (status); 
00228 
00229 
00230   /*   Make sure the arguments are not NULL: */ 
00231   ASSERT (phmdVS, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00232   ASSERT (pgV,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00233   ASSERT (lutV,   status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00234   /* -------------------------------------------   */
00235 
00236   ASSERT (phmdVS->phmd, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00237   ASSERT (pgV->pg,      status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00238   ASSERT (lutV->lut,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00239   /* -------------------------------------------   */
00240 
00241   /* Make sure there is no size mismatch */
00242   ASSERT (pgV->length == lutV->length, status, 
00243           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00244   ASSERT (pgV->length == phmdVS->length, status, 
00245           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00246   /* -------------------------------------------   */
00247 
00248   /* Make sure there are elements to be computed*/
00249   ASSERT (phmdVS->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00250   ASSERT (phmdVS->nfSize, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00251  /* -------------------------------------------   */
00252 
00253 
00254   length = phmdVS->length;
00255   nfSize = phmdVS->nfSize; 
00256   deltaF =  phmdVS->deltaF;
00257   
00258   breakLine = phmdVS->breakLine; /* old Break Line */
00259   fBinMin = phmdVS->fBinMin; /* initial frequency value  */
00260 
00261   /* Make sure initial breakLine is in [0,nfSize)  */
00262   ASSERT ( breakLine < nfSize, status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00263 
00264   /* -------------------------------------------   */
00265 
00266   /* Updating the space of PHMD increasing frequency */ 
00267   
00268   fBin = fBinMin + nfSize;
00269 
00270   for ( k=0; k<length; ++k ){ 
00271     /* make sure all deltaF are consistent */
00272     ASSERT (deltaF == lutV->lut[k].deltaF, 
00273             status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00274    
00275     phmdVS->phmd[ breakLine*length+k ].fBin = fBin;
00276     TRY( LALHOUGHPeak2PHMD(status->statusPtr,
00277                            &(phmdVS->phmd[ breakLine*length+k ]),
00278                            &(lutV->lut[k]), &(pgV->pg[k]) ), status);
00279   }
00280 
00281   /* Shift fBinMin and its mark */
00282   ++phmdVS->fBinMin;
00283   
00284   phmdVS->breakLine = (breakLine +1) % nfSize; 
00285   /* mark [0,nfSize) (of the circular buffer, modulus nfSize)
00286      pointing to the starting of the new fBinMin line */
00287   
00288   DETATCHSTATUSPTR (status);
00289   /* normal exit */
00290   RETURN (status);
00291 }
00292 
00293 
00294 /** Function for shifting the cylindrical buffer of PHMDs down by one
00295     frequency bin -- the highest frequency bin is dropped and an 
00296     extra frequency bin is added at the lowest frequency */
00297 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00298 void LALHOUGHupdateSpacePHMDdn  (LALStatus            *status, 
00299                                  PHMDVectorSequence   *phmdVS,
00300                                  HOUGHPeakGramVector  *pgV, 
00301                                  HOUGHptfLUTVector    *lutV) 
00302 { /*   *********************************************  </lalVerbatim> */
00303   UINT4    k,breakLine;
00304   UINT4    nfSize;    /* number of different frequencies */
00305   UINT4    length;    /* number of elements for each frequency */
00306   
00307   UINT8    fBin;      /* present frequency bin */
00308   REAL8    deltaF;    /* frequency resolution */
00309 
00310 
00311   /* --------------------------------------------- */
00312   INITSTATUS (status, "LALHOUGHupdateSpacePHMDdn", DRIVEHOUGHC);
00313   ATTATCHSTATUSPTR (status); 
00314 
00315 
00316   /*   Make sure the arguments are not NULL: */ 
00317   ASSERT (phmdVS, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00318   ASSERT (pgV,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00319   ASSERT (lutV,   status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00320   /* -------------------------------------------   */
00321 
00322   ASSERT (phmdVS->phmd, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00323   ASSERT (pgV->pg,      status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00324   ASSERT (lutV->lut,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00325   /* -------------------------------------------   */
00326 
00327   /* Make sure there is no size mismatch */
00328   ASSERT (pgV->length == lutV->length, status, 
00329           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00330   ASSERT (pgV->length == phmdVS->length, status, 
00331           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00332   /* -------------------------------------------   */
00333 
00334   /* Make sure there are elements to be computed*/
00335   ASSERT (phmdVS->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00336   ASSERT (phmdVS->nfSize, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00337   /* -------------------------------------------   */
00338 
00339   length = phmdVS->length;
00340   nfSize = phmdVS->nfSize; 
00341   deltaF =  phmdVS->deltaF;
00342   
00343   breakLine = phmdVS->breakLine; /* old Break Line */
00344 
00345   /* Make sure initial breakLine is in [0,nfSize)  */
00346   ASSERT ( breakLine < nfSize, status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00347   
00348   /* -------------------------------------------   */
00349 
00350   /* Updating the space of PHMD decreasing frequency */ 
00351   
00352   /* Shift fBinMin and its mark */
00353   fBin =  --phmdVS->fBinMin; /* initial frequency value  */
00354   
00355   phmdVS->breakLine = (breakLine + nfSize- 1) % nfSize; 
00356   /* mark [0,nfSize) (of the circular buffer, modulus nfSize)
00357      pointing to the starting of the new fBinMin line */
00358   
00359   breakLine = phmdVS->breakLine; /* the new Break Line */
00360 
00361   for ( k=0; k<length; ++k ){ 
00362     /* make sure all deltaF are consistent */
00363     ASSERT (deltaF == lutV->lut[k].deltaF, 
00364             status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00365    
00366     phmdVS->phmd[ breakLine*length+k ].fBin = fBin;
00367     TRY( LALHOUGHPeak2PHMD(status->statusPtr,
00368                            &(phmdVS->phmd[ breakLine*length+k ]),
00369                            &(lutV->lut[k]), &(pgV->pg[k]) ), status);
00370   }
00371 
00372  
00373   
00374   DETATCHSTATUSPTR (status);
00375   /* normal exit */
00376   RETURN (status);
00377 }
00378 
00379 
00380 /** Calculates the total hough map for a given trajectory in the 
00381     time-frequency plane and a set of partial hough map derivatives 
00382     -- this is the top level function to be called for constructing
00383     a total hough map.*/ 
00384 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00385 void LALHOUGHConstructHMT  (LALStatus                  *status, 
00386                             HOUGHMapTotal              *ht, /**< The output hough map */
00387                             UINT8FrequencyIndexVector  *freqInd, /**< time-frequency trajectory */ 
00388                             PHMDVectorSequence         *phmdVS /**< set of partial hough map derivatives */)
00389 { /*   *********************************************  </lalVerbatim> */
00390 
00391 
00392   UINT4    k,j;
00393   UINT4    breakLine;
00394   UINT4    nfSize;    /* number of different frequencies */
00395   UINT4    length;    /* number of elements for each frequency */
00396   UINT8    fBinMin;   /* present minimum frequency bin */ 
00397   INT8     fBin;      /* present frequency bin */
00398   UINT2    xSide,ySide;
00399  
00400   HOUGHMapDeriv hd; /* the Hough map derivative */
00401 
00402   /* --------------------------------------------- */
00403   INITSTATUS (status, "LALHOUGHConstructHMT", DRIVEHOUGHC);
00404   ATTATCHSTATUSPTR (status); 
00405 
00406   /*   Make sure the arguments are not NULL: */ 
00407   ASSERT (phmdVS,  status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00408   ASSERT (ht,      status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00409   ASSERT (freqInd, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00410   /* -------------------------------------------   */
00411 
00412   ASSERT (phmdVS->phmd,  status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00413   ASSERT (freqInd->data, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00414   /* -------------------------------------------   */
00415 
00416   /* Make sure there is no size mismatch */
00417   ASSERT (freqInd->length == phmdVS->length, status, 
00418           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00419   ASSERT (freqInd->deltaF == phmdVS->deltaF, status, 
00420           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00421   /* -------------------------------------------   */
00422 
00423   /* Make sure there are elements  */
00424   ASSERT (phmdVS->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00425   ASSERT (phmdVS->nfSize, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00426   /* -------------------------------------------   */
00427   
00428    /* Make sure the ht map contains some pixels */
00429   ASSERT (ht->xSide, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00430   ASSERT (ht->ySide, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00431 
00432   length = phmdVS->length;
00433   nfSize = phmdVS->nfSize; 
00434   
00435   fBinMin = phmdVS->fBinMin; /* initial frequency value  od the cilinder*/
00436   
00437   breakLine = phmdVS->breakLine;
00438 
00439   /* number of physical pixels */
00440   xSide = ht->xSide;
00441   ySide = ht->ySide;
00442   
00443   /* Make sure initial breakLine is in [0,nfSize)  */
00444   ASSERT ( breakLine < nfSize, status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00445   
00446   /* -------------------------------------------   */
00447   
00448   /* Initializing  hd map and memory allocation */
00449   hd.xSide = xSide;
00450   hd.ySide = ySide;
00451   hd.map = (HoughDT *)LALMalloc(ySide*(xSide+1)*sizeof(HoughDT));
00452   if (hd. map == NULL) {
00453     ABORT( status, LALHOUGHH_EMEM, LALHOUGHH_MSGEMEM);
00454   }
00455   /* -------------------------------------------   */
00456 
00457  
00458   TRY( LALHOUGHInitializeHD(status->statusPtr, &hd), status);
00459   for ( k=0; k<length; ++k ){ 
00460     /* read the frequency index and make sure is in the proper interval*/
00461     fBin =freqInd->data[k] -fBinMin;
00462 
00463     ASSERT ( fBin < nfSize, status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00464     ASSERT ( fBin >= 0,     status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00465  
00466     /* find index */
00467     j = (fBin + breakLine) % nfSize;
00468 
00469     /* Add the corresponding PHMD to HD */
00470     TRY( LALHOUGHAddPHMD2HD(status->statusPtr,
00471                             &hd, &(phmdVS->phmd[j*length+k]) ), status);
00472   }
00473 
00474   TRY( LALHOUGHIntegrHD2HT(status->statusPtr, ht, &hd), status);
00475   
00476   /* Free memory and exit */
00477   LALFree(hd.map);
00478 
00479   DETATCHSTATUSPTR (status);
00480   /* normal exit */
00481   RETURN (status);
00482 }
00483 
00484 
00485 
00486 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00487 void LALHOUGHComputeFBinMap (LALStatus             *status, 
00488                              UINT8                 *fBinMap, 
00489                              UINT8                 *f0Bin,
00490                              HOUGHResidualSpinPar  *rs)
00491 { /*   *********************************************  </lalVerbatim> */
00492 
00493   UINT4    i;
00494   INT4    shiftFBin;
00495   REAL8   shiftF;
00496 
00497   UINT4   spinOrder;
00498   REAL8   *spinF;
00499   REAL8   timeDiff;    /*  T(t)-T(t0) */
00500   REAL8   timeDiffProd;  
00501   REAL8   deltaF;  /*  df=1/TCOH  */
00502   /* --------------------------------------------- */
00503   INITSTATUS (status, "LALHOUGHComputeFBinMap", DRIVEHOUGHC);
00504   ATTATCHSTATUSPTR (status); 
00505   
00506   /*   Make sure the arguments are not NULL: */ 
00507   ASSERT (fBinMap, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00508   ASSERT (f0Bin,   status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00509   ASSERT (rs,      status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00510   /* -------------------------------------------   */
00511   
00512   /*   Make sure the Input/Output pointers are not the same */
00513   ASSERT (fBinMap != f0Bin, status, LALHOUGHH_ESAME, LALHOUGHH_MSGESAME);
00514   
00515   shiftFBin = 0;
00516   shiftF = 0.0;
00517   
00518   spinOrder = rs->spinRes.length;
00519   
00520   if(spinOrder){
00521     ASSERT (rs->spinRes.data , status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00522     timeDiff = rs->timeDiff;
00523     timeDiffProd =  timeDiff;
00524     
00525     deltaF = rs->deltaF; 
00526     spinF = rs->spinRes.data;
00527 
00528     for (i=0; i<spinOrder; ++i ){
00529       shiftF += spinF[i] * timeDiffProd;
00530       timeDiffProd *= timeDiff;
00531     }
00532     shiftFBin = rint( shiftF/deltaF) ; /* positive or negative */
00533   }
00534   
00535   *fBinMap = *f0Bin + shiftFBin;
00536   
00537   DETATCHSTATUSPTR (status);
00538   /* normal exit */
00539   RETURN (status);
00540 }
00541 
00542 
00543 
00544 
00545 
00546 /** Calculates the total hough map for a given trajectory in the 
00547     time-frequency plane and a set of partial hough map derivatives allowing 
00548     each PHMD to have a different weight factor to account for varying
00549     sensitivity at different sky-locations. */ 
00550 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00551 void LALHOUGHConstructHMT_W (LALStatus                  *status, 
00552                              HOUGHMapTotal              *ht, /**< The output hough map */
00553                              UINT8FrequencyIndexVector  *freqInd, /**< time-frequency trajectory */ 
00554                              PHMDVectorSequence         *phmdVS /**< set of partial hough map derivatives */)
00555 { /*   *********************************************  </lalVerbatim> */
00556 
00557 
00558   UINT4    k,j;
00559   UINT4    breakLine;
00560   UINT4    nfSize;    /* number of different frequencies */
00561   UINT4    length;    /* number of elements for each frequency */
00562   UINT8    fBinMin;   /* present minimum frequency bin */ 
00563   INT8     fBin;      /* present frequency bin */
00564   UINT2    xSide,ySide;
00565  
00566   HOUGHMapDeriv hd; /* the Hough map derivative */
00567 
00568   /* --------------------------------------------- */
00569   INITSTATUS (status, "LALHOUGHConstructHMT_W", DRIVEHOUGHC);
00570   ATTATCHSTATUSPTR (status); 
00571 
00572   /*   Make sure the arguments are not NULL: */ 
00573   ASSERT (phmdVS,  status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00574   ASSERT (ht,      status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00575   ASSERT (freqInd, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00576   /* -------------------------------------------   */
00577 
00578   ASSERT (phmdVS->phmd,  status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00579   ASSERT (freqInd->data, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00580   /* -------------------------------------------   */
00581 
00582   /* Make sure there is no size mismatch */
00583   ASSERT (freqInd->length == phmdVS->length, status, 
00584           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00585   ASSERT (freqInd->deltaF == phmdVS->deltaF, status, 
00586           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00587   /* -------------------------------------------   */
00588 
00589   /* Make sure there are elements  */
00590   ASSERT (phmdVS->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00591   ASSERT (phmdVS->nfSize, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00592   /* -------------------------------------------   */
00593   
00594    /* Make sure the ht map contains some pixels */
00595   ASSERT (ht->xSide, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00596   ASSERT (ht->ySide, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00597 
00598   length = phmdVS->length;
00599   nfSize = phmdVS->nfSize; 
00600   
00601   fBinMin = phmdVS->fBinMin; /* initial frequency value  od the cilinder*/
00602   
00603   breakLine = phmdVS->breakLine;
00604 
00605   /* number of physical pixels */
00606   xSide = ht->xSide;
00607   ySide = ht->ySide;
00608   
00609   /* Make sure initial breakLine is in [0,nfSize)  */
00610   ASSERT ( breakLine < nfSize, status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00611   
00612   /* -------------------------------------------   */
00613   
00614   /* Initializing  hd map and memory allocation */
00615   hd.xSide = xSide;
00616   hd.ySide = ySide;
00617   hd.map = (HoughDT *)LALMalloc(ySide*(xSide+1)*sizeof(HoughDT));
00618   if (hd. map == NULL) {
00619     ABORT( status, LALHOUGHH_EMEM, LALHOUGHH_MSGEMEM); 
00620   }
00621 
00622   /* -------------------------------------------   */
00623  
00624   TRY( LALHOUGHInitializeHD(status->statusPtr, &hd), status);
00625   for ( k=0; k<length; ++k ){ 
00626     /* read the frequency index and make sure is in the proper interval*/
00627     fBin =freqInd->data[k] -fBinMin;
00628 
00629     ASSERT ( fBin < nfSize, status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00630     ASSERT ( fBin >= 0,     status, LALHOUGHH_EVAL, LALHOUGHH_MSGEVAL);
00631  
00632     /* find index */
00633     j = (fBin + breakLine) % nfSize;
00634 
00635     /* Add the corresponding PHMD to HD */
00636     TRY( LALHOUGHAddPHMD2HD_W(status->statusPtr,
00637                             &hd, &(phmdVS->phmd[j*length+k]) ), status);
00638   }
00639 
00640   TRY( LALHOUGHIntegrHD2HT(status->statusPtr, ht, &hd), status);
00641   
00642   /* Free memory and exit */
00643   LALFree(hd.map);
00644 
00645   DETATCHSTATUSPTR (status);
00646   /* normal exit */
00647   RETURN (status);
00648 }
00649 
00650 
00651 
00652 /** Adds weight factors for set of partial hough map derivatives -- the 
00653     weights must be calculated outside this function.  */
00654 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00655 void LALHOUGHWeighSpacePHMD  (LALStatus            *status, 
00656                               PHMDVectorSequence   *phmdVS, /**< partial hough map derivatives */
00657                               REAL8Vector *weightV /**< vector of weights */) 
00658 { /*   *********************************************  </lalVerbatim> */
00659 
00660   UINT4    k,j;
00661   UINT4    nfSize;    /* number of different frequencies */
00662   UINT4    length;    /* number of elements for each frequency */
00663   /* --------------------------------------------- */
00664 
00665   INITSTATUS (status, "LALHOUGHWeighSpacePHMD", DRIVEHOUGHC);
00666   ATTATCHSTATUSPTR (status); 
00667 
00668 
00669   /*   Make sure the arguments are not NULL: */ 
00670   ASSERT (phmdVS, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00671   ASSERT (weightV,    status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00672   /* -------------------------------------------   */
00673 
00674   ASSERT (phmdVS->phmd, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00675   ASSERT (weightV->data,status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00676   /* -------------------------------------------   */
00677 
00678   /* Make sure there is no size mismatch */
00679   ASSERT (weightV->length == phmdVS->length, status, 
00680           LALHOUGHH_ESZMM, LALHOUGHH_MSGESZMM);
00681   /* -------------------------------------------   */
00682 
00683   /* Make sure there are elements to be computed*/
00684   ASSERT (phmdVS->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00685   ASSERT (phmdVS->nfSize, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00686 
00687 
00688   length = phmdVS->length;
00689   nfSize = phmdVS->nfSize; 
00690 
00691   /* weigh the phmds according to weightV */
00692   for ( k=0; k<length; ++k ){ 
00693     for ( j=0; j<  nfSize; ++j ){ 
00694       phmdVS->phmd[ j*length+k ].weight = (HoughDT)weightV->data[k];
00695     }
00696   }
00697  
00698 
00699   DETATCHSTATUSPTR (status);
00700    /* normal exit */
00701   RETURN (status);
00702 }
00703 
00704 
00705 
00706 /** Initializes weight factors to unity */
00707 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00708 void LALHOUGHInitializeWeights  (LALStatus  *status, 
00709                                 REAL8Vector *weightV /**< vector of weights */) 
00710 { /*   *********************************************  </lalVerbatim> */
00711 
00712   UINT4 j, length;
00713 
00714    /* --------------------------------------------- */
00715   INITSTATUS (status, "LALHOUGHInitializeWeights", DRIVEHOUGHC);
00716   ATTATCHSTATUSPTR (status); 
00717 
00718 
00719   /*   Make sure the arguments are not NULL: */ 
00720   ASSERT (weightV, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00721   ASSERT (weightV->data,status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00722   /* -------------------------------------------   */
00723 
00724   /* Make sure there are elements to be computed*/
00725   ASSERT (weightV->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00726 
00727   length = weightV->length;
00728 
00729   for (j=0; j<length; j++) {
00730     weightV->data[j] = 1.0;
00731   }
00732  
00733   DETATCHSTATUSPTR (status);
00734    /* normal exit */
00735   RETURN (status);
00736 }
00737 
00738 
00739 
00740 
00741 /** Normalizes weight factors so that their sum is N */
00742 /* *******************************  <lalVerbatim file="DriveHoughD"> */
00743 void LALHOUGHNormalizeWeights  (LALStatus  *status, 
00744                                 REAL8Vector *weightV /**< vector of weights */) 
00745 { /*   *********************************************  </lalVerbatim> */
00746 
00747   UINT4 j, length;
00748   REAL8 sum; 
00749 
00750    /* --------------------------------------------- */
00751   INITSTATUS (status, "LALHOUGHNormalizeWeights", DRIVEHOUGHC);
00752   ATTATCHSTATUSPTR (status); 
00753 
00754 
00755   /*   Make sure the arguments are not NULL: */ 
00756   ASSERT (weightV, status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00757   ASSERT (weightV->data,status, LALHOUGHH_ENULL, LALHOUGHH_MSGENULL);
00758   /* -------------------------------------------   */
00759 
00760   /* Make sure there are elements to be computed*/
00761   ASSERT (weightV->length, status, LALHOUGHH_ESIZE, LALHOUGHH_MSGESIZE);
00762 
00763   length = weightV->