2 /******** implements functions for the mhit structure *********/
10 void rdmc_init_mhit(mhit *h){
11 h->ch = h->str = h->mt = h->ma = h->id = RDMC_NA ;
13 h->amp = h->tot = RDMC_NA ;
15 rdmc_init_mhit_stat(&(h->hstat));
22 void rdmc_init_mhit_stat(mhit_stat_t *s){
27 void rdmc_clear_mhit(mhit *h){
32 void rdmc_free_mhit(mhit *h){
35 for(i=0 ; i < h->nuser ; i++){
36 rdmc_free_mevt_special(&(h->user[i]));
46 if (h->comment !=NULL){
53 /****************************************************************************
54 * merge two hits. the amplitude of the merged hit is added only if ch=-1
55 * else the amplitude of the channel ch is used.
56 * If there is no such channel, a zero amplitude is assumed
57 ****************************************************************************/
59 void rdmc_merge_hits(mhit *in_1, mhit *in_2, int ch)
62 float ampa,tfirst,tota;
65 if (in_1 == in_2) return; /* the hits are the SAME! */
67 if ((ch == -1) || ((ch == in_1->ch) && (ch == in_2->ch) )){ /* use both */
68 if ((in_1->amp >= 0.) && (in_2->amp >= 0.))
69 ampa= in_1->amp + in_2->amp; /* sum of amplitudes*/
70 else if (in_1->amp >= 0.)
72 else if (in_2->amp >= 0.)
77 ida = (in_1->amp >= in_2->amp) ? (in_1->ma) : (in_2->ma) ;
79 ida = -1; /* amp muon id*/
80 } else if ((ch == in_1->ch) && (in_1->amp >= 0.)) { /* only first */
82 ida = (ampa > 0)? in_1->ma : -1;
83 } else if ((ch == in_2->ch) && (in_2->amp >= 0.)) { /* only second */
85 ida = (ampa > 0)? in_2->ma : -1;
86 in_1->ch = ch; /* set correct (for amp) channel number */
92 tfirst = (in_1->t <= in_2->t ) ? (in_1->t) : (in_2->t) ; /* keep first time*/
93 idt = (in_1->t <= in_2->t ) ? (in_1->mt) : (in_2->mt) ; /* time muon id*/
95 in_1->amp = ampa; /* new amplitude */
98 if ((in_1->tot >= 0.)&&(in_2->tot >= 0.))
99 tota= in_1->tot + in_2->tot; /* sum of totlitudes*/
110 ida = (in_1->tot >= in_2->tot ) ? (in_1->ma) : (in_2->ma) ;
113 in_1->tot = tota; /* new amplitude */
123 in_1->hstat.n_tdc_edges =
124 (in_1->hstat.n_tdc_edges >= in_2->hstat.n_tdc_edges )
125 ? in_1->hstat.n_tdc_edges
126 : in_2->hstat.n_tdc_edges;
128 in_1->hstat.tdc_flag =
129 (in_1->hstat.tdc_flag >= in_2->hstat.tdc_flag )
130 ? in_1->hstat.tdc_flag
131 : in_2->hstat.tdc_flag;
133 in_1->weight = in_1->weight * in_2->weight ;
137 } /* rdmc_merge_hits() */
139 /****************************************************************************
140 * copies the hit *in to *out by overwriting.
141 * If in == out, nothing is done.
142 ****************************************************************************/
143 void rdmc_cp_mhit(mhit *out, mhit *in)
145 if ((in == NULL) || (out == NULL) || (in == out))
148 memcpy(out, in, sizeof(mhit));
151 mevt_special_t *from,*to;
152 out->user = (mevt_special_t *) malloc(in->nuser*sizeof(mevt_special_t));
158 for (i = 0 ; i < in->nuser ; i++){
159 rdmc_cp_mevt_special(to,from);
166 out->comment = (char *) malloc(strlen(in->comment)+1);
168 strcpy(out->comment, in->comment);
171 if (out->tmp){ /* if there is a new stack delete it */
176 } /* rdmc_cp_mhit() */