Ejemplo n.º 1
0
void XiaEventReader::make_events() {
	// set all indices to zero
	for(int i=0; i<XER_MODMAX; i++) {
		dgf_buffers[i].index = 0;
	}
	events_index = 0;
	events_cnt = 0;

	int st_index;
	while((st_index = get_smallesttime_index())!=-1) {
		uint64_t st_val = get_eventtime(st_index);


		// reset global event
		t_event *glev = &events[events_cnt];
		t_event_unixtime *glev_ut = &events_unixtime[events_cnt];
		glev_ut->value = 0;
		glev_ut->active = 0;
		glev->cnt = 0;
		for(int mod=0; mod<XER_MODMAX; mod++) {
			t_dgf_buffer *buf = &dgf_buffers[mod];

			// reached end of buffer
			if(buf->index>=buf->evcnt) {
				continue;
			}

			uint64_t val = get_eventtime(mod);
			int64_t diff = val-st_val;
			if(diff>=0&&diff<EVENT_TLHISTMAX) {
				evtl_hist[diff]++;
			}
			t_dgf_event *dgfev = &buf->events[buf->index];

			// timestamps do not match
			if(val-st_val>EVENT_TIMELIMIT) continue;

			// add to global event	
			for(int j=0; j<dgfev->cnt; j++) {
				int ch = dgfev->dets[j];
				uint64_t time = dgfev->chtime[j];
				uint16_t en = dgfev->chen[j];				
				int veto = dgfev->veto[j];


				// add hit
				int det = getdet(buf->module, ch);
				if(det==-1) {
					fprintf(stderr, "warning: not detector specified for module %d, channel %d\n", buf->module, ch);
					continue;
				}
				int cnt = glev->cnt;
				glev->dets[cnt] = det;
				glev->times[cnt] = (int64_t)time; // this should work since time is only 48 bit unsigned
				glev->energies[cnt] = en;
				glev->veto[cnt] = veto;
				glev->cnt = glev->cnt + 1;
			}
			if(dgfev->utimefound) {
				if(glev_ut->active) {
					fprintf(stderr, "warning unixtime already defined\n");
				}	
				glev_ut->active = 1;
				glev_ut->value = dgfev->utime;
			}
			buf->index = buf->index + 1;			
		}

		events_cnt++;
	}
}
Ejemplo n.º 2
0
// set embedded data values
void minimesh::setvals(const minivals &vals)
   {
   unsigned int i,j;

   miniv3d v1,v2,v3,v4;
   double b0,b1,b2,b3,b4;

   minival val;

   // apply the embedded data values to each tetrahedron
   for (i=0; i<getsize(); i++)
      {
      // set the embedded data values
      ref(i).vals=vals;

      // get the vertices of the actual tetrahedron
      v1=get(i).vtx1;
      v2=get(i).vtx2;
      v3=get(i).vtx3;
      v4=get(i).vtx4;

      // for each embedded data value
      for (j=0; j<vals.getsize(); j++)
         {
         // get the embedded data value
         val=get(i).vals[j];

         // calculate the determinant of reference tetrahedron
         b0=getdet(val.ref1,val.ref2,val.ref3,val.ref4);

         // calculate barycentric coordinates #1
         b4=getdet(val.ref1,val.ref2,val.ref3,v1);
         b3=getdet(val.ref1,val.ref4,val.ref2,v1);
         b1=getdet(val.ref2,val.ref4,val.ref3,v1);
         b2=getdet(val.ref3,val.ref4,val.ref1,v1);

         // reconstruct data coordinate #1
         ref(i).vals.ref(j).crd1=(b1*val.crd1+b2*val.crd2+b3*val.crd3+b4*val.crd4)/b0;

         // calculate barycentric coordinates #2
         b4=getdet(val.ref1,val.ref2,val.ref3,v2);
         b3=getdet(val.ref1,val.ref4,val.ref2,v2);
         b1=getdet(val.ref2,val.ref4,val.ref3,v2);
         b2=getdet(val.ref3,val.ref4,val.ref1,v2);

         // reconstruct data coordinate #2
         ref(i).vals.ref(j).crd2=(b1*val.crd1+b2*val.crd2+b3*val.crd3+b4*val.crd4)/b0;

         // calculate barycentric coordinates #3
         b4=getdet(val.ref1,val.ref2,val.ref3,v3);
         b3=getdet(val.ref1,val.ref4,val.ref2,v3);
         b1=getdet(val.ref2,val.ref4,val.ref3,v3);
         b2=getdet(val.ref3,val.ref4,val.ref1,v3);

         // reconstruct data coordinate #3
         ref(i).vals.ref(j).crd3=(b1*val.crd1+b2*val.crd2+b3*val.crd3+b4*val.crd4)/b0;

         // calculate barycentric coordinates #4
         b4=getdet(val.ref1,val.ref2,val.ref3,v4);
         b3=getdet(val.ref1,val.ref4,val.ref2,v4);
         b1=getdet(val.ref2,val.ref4,val.ref3,v4);
         b2=getdet(val.ref3,val.ref4,val.ref1,v4);

         // reconstruct data coordinate #4
         ref(i).vals.ref(j).crd4=(b1*val.crd1+b2*val.crd2+b3*val.crd3+b4*val.crd4)/b0;
         }
      }
   }