2 /******** implements functions for the mtrack structure *********/
6 #define _USE_MATH_DEFINES
8 char *rdmc_mtrack_cvsid =
9 "$Header: /net/local/cvsroot/siegmund/rdmc/rdmc_mtrack.c,v 1.13 2001/06/08 17:23:59 wiebusch Exp $";
13 /****************************************************************************/
14 /* init_mtrack() resets the event values to start values */
15 /****************************************************************************/
17 void rdmc_init_mtrack(mtrack *t)
21 t->x = t->y = t->z = 0.0;
36 } /* function init_mtrack() */
38 void rdmc_clear_mtrack(mtrack *t){
43 void rdmc_free_mtrack(mtrack *t){
46 for(i=0 ; i < t->nuser ; i++){
47 rdmc_free_mevt_special(&(t->user[i]));
57 if (t->comment !=NULL){
65 /*****************************************************************************/
66 /* tau_tr() calcs the direction cosinuus of a given track and fills it into */
68 /*****************************************************************************/
70 void rdmc_tau_tr(mtrack *tr)
73 double sinth; /* sinus theta */
75 if (fabs(tr->costh) < 1.0){
76 sinth = sqrt( (1 - (double) tr->costh ) * (1 + (double) tr->costh) );
81 tr->px = - sinth * cos(tr->phi);
82 tr->py = - sinth * sin(tr->phi);
87 } /* function tau_tr() */
90 /****************************************************************************/
91 /* tauinv_tr() calcs cos theta and phi from the direction cosinus and fills */
92 /* them into the track */
93 /****************************************************************************/
95 void rdmc_tauinv_tr(mtrack *tr)
100 r = tr->px * tr->px + tr->py *tr->py + tr->pz * tr->pz;
101 if (r > 0.0) r = sqrt(r);
109 tr->costh = - tr->pz;
111 #if 0 /* this is wrong and not needed anyway .. atan2 can handle this */
113 tr->phi = M_PI / 2.0;
116 tr->phi = atan2(- tr->py, - tr->px);
118 if (tr->phi < 0) /* I want positive phis (0,..2*Pi) */
121 } /* function tauinv_tr() */
123 /****************************************************************************
124 * copies the track *in to *out by overwriting.
125 * If in == out, nothing is done.
126 ****************************************************************************/
127 void rdmc_cp_mtrack(mtrack *out, const mtrack *in)
129 if ((in == NULL) || (out == NULL) || (in == out))
132 memcpy(out, in, sizeof(mtrack));
136 mevt_special_t *from,*to;
137 out->user = (mevt_special_t *) malloc(in->nuser*sizeof(mevt_special_t));
143 for (i = 0 ; i < in->nuser ; i++){
144 rdmc_cp_mevt_special(to,from);
151 out->comment = (char *) malloc(strlen(in->comment)+1);
153 strcpy(out->comment, in->comment);
156 if (out->tmp){ /* if there is a new stack delete it */
160 } /* rdmc_cp_mtrack() */