mEmcGeaTrack.c

Go to the documentation of this file.
00001 #include <math.h>
00002 #include <gsl/gsl_math.h>
00003 #include "dio_trk.hh"
00004 #include "mEmcGeaTrack.h"
00005 #include "emlLib.h"
00006 
00020 long mEmcGeaTrack_(
00021   TABLE_HEAD_ST *dEmcGeaTrackTower_h, DEMCGEATRACKTOWER_ST *dEmcGeaTrackTower ,
00022   TABLE_HEAD_ST   *dEmcGeaTrack_h,   DEMCGEATRACK_ST     *dEmcGeaTrack )
00023 {
00024 /*:>--------------------------------------------------------------------
00025 **: ROUTINE:    mEmcGeaTrack_
00026 **: DESCRIPTION: Physics Analysis Module ANSI C template.
00027 **:             This is an ANSI C Physics Analysis Module template
00028 **:             automatically generated by stic from mEmcGeaTrack.idl.
00029 **:             Please edit comments and code.
00030 **: AUTHOR:     hpl - H.P. Lovecraft, hplovecraft@cthulhu.void
00031 **: ARGUMENTS:
00032 **:       IN:
00033 **:  dEmcGeaTrackTower    - PLEASE FILL IN DESCRIPTION HERE
00034 **:  dEmcGeaTrackTower_h   - header Structure for dEmcGeaTrackTower
00035 **:    INOUT:
00036 **:      OUT:
00037 **:       dEmcGeaTrack    - PLEASE FILL IN DESCRIPTION HERE
00038 **:      dEmcGeaTrack_h   - header Structure for dEmcGeaTrack
00039 **: RETURNS:    STAF Condition Value
00040 **:>------------------------------------------------------------------*/
00041 
00042     long i,j,k,k1,k2;
00043     long i_gtr_id;
00044     long i_ancestry;
00045     int size;
00046     int i_max_ancestry;
00047     int ll;
00048     
00049     static float rmass[25] = 
00050     {0.0,    0.0005, 0.0005, 0.0,    0.1057,
00051      0.1057, 0.1349, 0.1395, 0.1395, 0.4977,
00052      0.4936, 0.4936, 0.9396, 0.9383, 0.9383,
00053      0.4977, 0.5475, 1.1156, 1.1894, 1.1926,
00054      1.1975, 1.3149, 1.3213, 1.6724, 0.9396
00055     };
00056 
00057     float xyz[3];
00058     double todeg,torad;
00059     short l_found,l_found_parent,l_first;
00060     long i_gtrto_id,i_last_trkno,i_search_trkno;
00061     long i_ntrack,i_itparent;
00062     long twrhit;
00063     float edep;
00064     double d_thvtx,d_phvtx,d_work0,d_work1,d_work2,d_work;
00065     float r_work,r_work1;
00066     
00067  int isubevent;
00068  int ntrack;
00069  int error;
00070  int nfile;
00071  int status;
00072  int true_track;
00073  int idpart;
00074  float ptot,ptheta,pphi,r_vertex,z_vertex,theta_vertex,phi_vertex;
00075  int itparent,idparent;
00076     
00077 /*
00078 **      executable    
00079 */
00080 
00081     i_max_ancestry = 10;
00082     torad = M_PI / 180.0;
00083     todeg = 180.0 / M_PI;
00084 
00085     if (dEmcGeaTrackTower_h->nok <= 0) return (STAFCV_BAD);
00086 
00087     for (ll = 0; ll < sizeof(xyz)/sizeof(xyz[0]); ll++)
00088       {
00089         *(xyz + ll) = 0.0;
00090       }
00091     
00092     i_gtr_id =0;
00093     i_last_trkno = 0;
00094     for (j = 0; j < dEmcGeaTrackTower_h->nok; j++)
00095     {
00096        if (dEmcGeaTrackTower[j].trkno <= 0) goto orphan;
00097        for (k = 0; k <= 2; k++)
00098          {
00099            xyz[k] = dEmcGeaTrackTower[j].xyz[k];
00100          }
00101        
00102        if(dEmcGeaTrackTower[j].trkno != i_last_trkno)
00103        {
00104           l_found = 0;
00105           i_ancestry = 1;
00106           i_last_trkno = dEmcGeaTrackTower[j].trkno;
00107           true_track = i_last_trkno;
00108 
00109           /* Iterate until max. ancestry level is reached */
00110 
00111           while (l_found > -1 && i_ancestry <= i_max_ancestry)
00112             {
00113               
00114           /* Get track data */
00115 
00116               //        The negative or positive number was introduced as a redundancy
00117               //check for the user, as explained on the WWW site
00118               //"Documentation for PISA Track Ancestry Accessor Functions"
00119               //http://www.phenix.bnl.gov/phenix/WWW/simulation/pisaAncestry.html
00120               //
00121               //************************************************
00122               //Redundancy checks 
00123               //
00124               //As a redundancy check on the dio_ptrkstack ancestry search, 
00125               //the parent particle ID idparent is returned as a negative value if the parent
00126               //particle itself is a secondary . This is not a mistake by the ancestry 
00127               //software, but a deliberate attempt to help you in your coding of your own
00128               //searches. On the other hand, if the particle is a primary, then the parent 
00129               //ID is returned as 0. There are also redundancy checks on the
00130               //itparent track number values. If the particle is itself a primary, 
00131               //then the itparent is returned as a negative value equal to the
00132               //true_track value. It the particle is not a primary, then the itparent 
00133               //track value is returned as a positive number, and that positive must
00134               //be seen to be different from the input true_track value, of course. "
00135 
00136 
00137               // OK: prevent dio_ptrkstack from looking for a negative track
00138 
00139               if(true_track<0)
00140                 {
00141                   error = 1;
00142                 }
00143               else{
00144                 // also, zero out all variables
00145                 nfile = 0; error = 0; itparent = 0; idparent = 0; idpart = 0;
00146                 ptot = 0.0; ptheta = 0.0; pphi = 0.0;
00147                 r_vertex = 0.0; z_vertex = 0.0; theta_vertex = 0.0; phi_vertex = 0.0;
00148 
00149                 status = dio_ptrkstack(&true_track, &nfile,&error, 
00150                                      &ptot, &ptheta, &pphi,
00151                                      &r_vertex, &z_vertex, 
00152                                      &theta_vertex, &phi_vertex,
00153                                        &itparent, &idparent, &idpart);
00154               }
00155               
00156 
00157               if(error == 0)
00158                 {
00159                   /* Get number of towers where it deposited energy 
00160                      and total energy deposition */
00161                   edep = 0.0;
00162                   twrhit = 0;
00163                   for (k2 = 0; k2 < 3; k2++)  /* There is at least on entry */
00164                     {
00165                       if(dEmcGeaTrackTower[j].edep[k2] > 0.0)
00166                         {
00167                           twrhit++;
00168                           edep = edep + dEmcGeaTrackTower[j].edep[k2];
00169                         }
00170                     }
00171                   k1 = 0;
00172                   while(dEmcGeaTrackTower[j+k1].nextid > 0 && k1 < 19)
00173                     {
00174                       for (k2 = 0; k2 < 3; k2++)  /* There is at least on entry */
00175                         {
00176                           if(dEmcGeaTrackTower[j+k1+1].edep[k2] > 0.0)
00177                             {
00178                               twrhit++;
00179                               edep = edep + dEmcGeaTrackTower[j+k1+1].edep[k2];
00180                             }
00181                         }
00182                       k1++;
00183                     }
00184                   dEmcGeaTrack[i_gtr_id].twrhit = twrhit;
00185                   dEmcGeaTrack[i_gtr_id].edep = edep;
00186 
00187                   /* Write basic data */
00188 
00189                   dEmcGeaTrack[i_gtr_id].id = i_gtr_id;
00190                   dEmcGeaTrack[i_gtr_id].trkno = true_track;
00191                   dEmcGeaTrack[i_gtr_id].input = nfile;
00192                   dEmcGeaTrack[i_gtr_id].anclvl = i_ancestry;
00193                   dEmcGeaTrack[i_gtr_id].pid = idpart;
00194                   for (k1 = 0; k1 <= 2; k1++)
00195                     {
00196 
00197                       dEmcGeaTrack[i_gtr_id].impxyz[k1] = xyz[k1];
00198                     }
00199                   
00200                   dEmcGeaTrack[i_gtr_id].ptot = ptot;
00201                   dEmcGeaTrack[i_gtr_id].ekin = ptot;
00202 /*              
00203 **      Watch out!  total momentum instead of kinetic energy !  
00204 */              
00205 
00206                   k1 = idpart - 1;
00207                   if ( k1 > -1 && k1 < 25)
00208                     {
00209                       r_work = rmass[k1] * rmass[k1] +
00210                         ptot * ptot;
00211                       d_work = r_work;
00212                       d_work = sqrt(d_work);
00213                       r_work = d_work - rmass[k1];
00214                       if (r_work > 0.0)
00215                         {
00216                           dEmcGeaTrack[i_gtr_id].ekin = r_work;
00217                         }
00218                     }
00219 
00220 /*
00221 **      Position where the particle was born
00222 **      do it with double precision
00223 */
00224 
00225                   d_thvtx = theta_vertex;
00226                   d_phvtx = phi_vertex;
00227                   d_thvtx = torad * d_thvtx;
00228                   d_phvtx = torad * d_phvtx;
00229                   d_work1 = sin(d_thvtx);
00230                   d_work2 = cos(d_phvtx);
00231                   d_work0 = r_vertex;
00232                 
00233                   d_work = d_work0 * d_work1 * d_work2;
00234                   if(z_vertex != 0.0)
00235                     {
00236                       d_work = d_work0 * d_work2;
00237                     }
00238                   dEmcGeaTrack[i_gtr_id].xyz[0] = d_work;
00239               
00240 
00241                   d_work2 = sin(d_phvtx);
00242                   d_work = d_work0 * d_work1 * d_work2;
00243                   if(z_vertex != 0.0)
00244                     {
00245                       d_work = d_work0 * d_work2;
00246                     }
00247                   dEmcGeaTrack[i_gtr_id].xyz[1] = d_work;
00248                 
00249                   dEmcGeaTrack[i_gtr_id].xyz[2] =
00250                     z_vertex;
00251 
00252 /*
00253 **      Momentum 
00254 **      do it with double precision
00255 */
00256                   d_thvtx = ptheta;
00257                   d_phvtx = pphi;
00258                   d_thvtx = torad * d_thvtx;
00259                   d_phvtx = torad * d_phvtx;
00260                   d_work1 = sin(d_thvtx);
00261                   d_work2 = cos(d_phvtx);
00262                   d_work0 = ptot;
00263 
00264 
00265                   d_work = d_work0 * d_work1 * d_work2;
00266                   dEmcGeaTrack[i_gtr_id].pxyz[0] = d_work;
00267                 
00268 
00269                   d_work2 = sin(d_phvtx);
00270                   d_work = d_work0 * d_work1 * d_work2;
00271                   dEmcGeaTrack[i_gtr_id].pxyz[1] = d_work;
00272 
00273                   d_work1 = cos(d_thvtx);
00274                   d_work = d_work0 * d_work1;
00275                   dEmcGeaTrack[i_gtr_id].pxyz[2] = d_work;
00276                   dEmcGeaTrack[i_gtr_id].itparent = itparent;
00277 
00278                   dEmcGeaTrack[i_gtr_id].idparent = idparent;
00279 
00280                   if(idparent == 0 || i_ancestry >= i_max_ancestry)
00281                     {
00282                       l_found = -1;
00283                       dEmcGeaTrack[i_gtr_id].itparent = 0;
00284                       dEmcGeaTrack[i_gtr_id].parent_ptr = -1;
00285                     }
00286                   else
00287                     {
00288                       i_ancestry = i_ancestry + 1;
00289                       /*  Continue searching on level back*/
00290                       true_track = itparent;
00291                       dEmcGeaTrack[i_gtr_id].parent_ptr = i_gtr_id + 1;
00292                       
00293                     }
00294                   i_gtr_id = i_gtr_id + 1;
00295                   
00296                 
00297                 }    /* endif error = 0; track found by dio_ptrkstack */
00298 
00299               else   /* error != 0  Track not found by dio_ptrkstack */
00300                 {
00301                   l_found = -1;
00302                   /*
00303                   printf(" Error in mEmcGeaTrack: true_track not found \n");
00304                   */
00305                 }
00306               
00307             }   /* while (l_found >= 0 && i_ancestry <= i_max_ancestry) */
00308           
00309        }        /* End if(dEmcGeaTrackTower[j].trkno != i_last_trkno) */
00310 
00311 
00312     orphan:
00313        continue;       /* Track number was zero, nothing to do */
00314 
00315     }        /* End for (j = 0; j < dEmcGeaTrackTower_h->nok; j++)  */
00316 
00317     dEmcGeaTrack_h->nok = i_gtr_id;
00318     
00319 
00320    return STAFCV_OK;
00321 }