]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/icepack/iceconvert/rdmc_mtrack.c
07-jun-2007 GdV OM readout type also updated from the data contents in IceRoot.cxx.
[u/mrichter/AliRoot.git] / RALICE / icepack / iceconvert / rdmc_mtrack.c
1
2 /******** implements functions for the mtrack structure *********/
3
4 #include <string.h>
5 #include <stdlib.h>
6 #define _USE_MATH_DEFINES
7 #include <math.h>
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 $";
10
11 #include "rdmc.h"
12
13 /****************************************************************************/
14 /* init_mtrack() resets the event values to start values                    */
15 /****************************************************************************/
16
17 void rdmc_init_mtrack(mtrack *t)
18 {
19   t->id = MUON_PLUS;
20   t->e = 0.0;
21   t->x = t->y = t->z = 0.0;
22   t->t = 0.0 ;
23   t->costh = 1.0;
24   t->phi = 0.0;
25   t->px = t->py = 0;
26   t->pz = -1.0;
27   t->length = RDMC_NA;
28   t->nmuon = 1;
29   t->parent = RDMC_NA;
30   t->tag = RDMC_NA;
31   t->weight = 1.;
32   t->nuser=0;
33   t->user=NULL;
34   t->comment=NULL;
35   t->tmp=NULL;
36 } /* function init_mtrack() */
37
38 void rdmc_clear_mtrack(mtrack *t){
39   rdmc_free_mtrack(t);
40   rdmc_init_mtrack(t);
41 }
42
43 void rdmc_free_mtrack(mtrack *t){
44   int i;
45   if (t->user !=NULL){
46     for(i=0 ; i < t->nuser ; i++){
47       rdmc_free_mevt_special(&(t->user[i]));
48     }
49     free(t->user);
50     t->nuser=0;
51     t->user=NULL;
52   }
53   if (t->tmp !=NULL){
54     free(t->tmp);
55     t->tmp=NULL;
56   }
57   if (t->comment !=NULL){
58     free(t->comment);
59     t->comment=NULL;
60   }
61
62   rdmc_init_mtrack(t);
63 }
64
65 /*****************************************************************************/
66 /* tau_tr() calcs the direction cosinuus of a given track and fills it into  */
67 /*         the track                                                         */
68 /*****************************************************************************/
69
70 void rdmc_tau_tr(mtrack *tr)
71 {
72
73   double sinth;                                               /* sinus theta */
74   
75   if (fabs(tr->costh) < 1.0){
76     sinth = sqrt( (1 - (double) tr->costh ) * (1 + (double) tr->costh) );
77   }else{
78     sinth = 0.0;
79   }
80
81   tr->px = - sinth * cos(tr->phi);
82   tr->py = - sinth * sin(tr->phi);
83   tr->pz = - tr->costh;
84
85   return;
86
87 } /* function tau_tr() */
88
89
90 /****************************************************************************/
91 /* tauinv_tr() calcs cos theta and phi from the direction cosinus and fills */
92 /*               them into the track                                        */
93 /****************************************************************************/
94
95 void rdmc_tauinv_tr(mtrack *tr)
96 {
97
98   double r;
99   
100   r = tr->px * tr->px + tr->py *tr->py + tr->pz * tr->pz;
101   if (r > 0.0) r = sqrt(r);
102   if (r != 0) {
103     r = 1/r;
104     tr->px *= r;
105     tr->py *= r;
106     tr->pz *= r;
107   } /* if r != 0 */
108
109   tr->costh = - tr->pz;
110
111 #if 0 /* this is wrong and not needed anyway .. atan2 can handle this */  
112   if (tr->px == 0.0)
113     tr->phi = M_PI / 2.0;
114   else
115 #endif
116     tr->phi = atan2(- tr->py, - tr->px);
117
118   if (tr->phi < 0)                       /* I want positive phis (0,..2*Pi) */
119     tr->phi += 2*M_PI;
120
121 } /* function tauinv_tr() */
122
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)
128 {
129   if ((in == NULL) || (out == NULL) || (in == out))
130     return;
131   
132   memcpy(out, in, sizeof(mtrack));
133
134   if (out->nuser){
135     int i;
136     mevt_special_t *from,*to;
137     out->user = (mevt_special_t *) malloc(in->nuser*sizeof(mevt_special_t));
138     if (!(out->user)){
139       out->nuser = 0;
140     } else {
141       from = in->user;
142       to = out->user;
143       for (i = 0 ; i < in->nuser ; i++){
144         rdmc_cp_mevt_special(to,from);
145         to++ ; from++;
146       }
147     }
148   }
149
150   if (in->comment) {
151     out->comment = (char *) malloc(strlen(in->comment)+1);
152     if (out->comment) 
153       strcpy(out->comment, in->comment);
154   }
155
156   if (out->tmp){ /* if there is a new stack delete it */
157     out->tmp=NULL;
158   }
159
160 } /* rdmc_cp_mtrack() */