Commits

Anonymous committed 763a772

make all indices C-based and consistently so

Comments (0)

Files changed (2)

 	defer C.free(unsafe.Pointer(c_mode))
 	c_f := C.fdopen(c_fd, c_mode)
 	C.fflush(c_f)
-	C.hepevt_print_particle(C.int(idx), c_f)
+	C.hepevt_print_particle(C.int(idx+1), c_f)
 	C.fflush(c_f)
 	_ = f.Sync()
 }
 
 // status code
 func StatusCode(idx int) int {
-	return int(C.hepevt_status_code(C.int(idx)))
+	return int(C.hepevt_status_code(C.int(idx+1)))
 }
 
 // PDG particle id
 func PdgId(idx int) int {
-	return int(C.hepevt_pdg_id(C.int(idx)))
+	return int(C.hepevt_pdg_id(C.int(idx+1)))
 }
 
 // index of 1st mother
 func FirstParent(idx int) int {
-	return int(C.hepevt_first_parent(C.int(idx)))
+	return int(C.hepevt_first_parent(C.int(idx+1)))
 }
 
 // index of last mother
 func LastParent(idx int) int {
-	return int(C.hepevt_last_parent(C.int(idx)))
+	return int(C.hepevt_last_parent(C.int(idx+1)))
 }
 
 // number of parents
 func NumberParents(idx int) int {
-	return int(C.hepevt_number_parents(C.int(idx)))
+	return int(C.hepevt_number_parents(C.int(idx+1)))
 }
 
 // index of 1st daughter
 func FirstChild(idx int) int {
-	return int(C.hepevt_first_child(C.int(idx)))
+	return int(C.hepevt_first_child(C.int(idx+1)))
 }
 
 // index of last daughter
 func LastChild(idx int) int {
-	return int(C.hepevt_last_child(C.int(idx)))
+	return int(C.hepevt_last_child(C.int(idx+1)))
 }
 
 // number of children
 func NumberChildren(idx int) int {
-	return int(C.hepevt_number_children(C.int(idx)))
+	return int(C.hepevt_number_children(C.int(idx+1)))
 }
 
 // X momentum
 func Px(idx int) float64 {
-	return float64(C.hepevt_px(C.int(idx)))
+	return float64(C.hepevt_px(C.int(idx+1)))
 }
 
 // Y momentum
 func Py(idx int) float64 {
-	return float64(C.hepevt_py(C.int(idx)))
+	return float64(C.hepevt_py(C.int(idx+1)))
 }
 
 // Z momentum
 func Pz(idx int) float64 {
-	return float64(C.hepevt_pz(C.int(idx)))
+	return float64(C.hepevt_pz(C.int(idx+1)))
 }
 
 // Energy
 func E(idx int) float64 {
-	return float64(C.hepevt_e(C.int(idx)))
+	return float64(C.hepevt_e(C.int(idx+1)))
 }
 
 // Generated mass
 func M(idx int) float64 {
-	return float64(C.hepevt_m(C.int(idx)))
+	return float64(C.hepevt_m(C.int(idx+1)))
 }
 
 // X production vertex
 func X(idx int) float64 {
-	return float64(C.hepevt_x(C.int(idx)))
+	return float64(C.hepevt_x(C.int(idx+1)))
 }
 
 // Y production vertex
 func Y(idx int) float64 {
-	return float64(C.hepevt_y(C.int(idx)))
+	return float64(C.hepevt_y(C.int(idx+1)))
 }
 
 // Z production vertex
 func Z(idx int) float64 {
-	return float64(C.hepevt_z(C.int(idx)))
+	return float64(C.hepevt_z(C.int(idx+1)))
 }
 
 // production time
 func T(idx int) float64 {
-	return float64(C.hepevt_t(C.int(idx)))
+	return float64(C.hepevt_t(C.int(idx+1)))
 }
 
 // set methods ---------------------------------------------------------------
 
-// set event number
-func SetEventNumber(evtno int) {
-	C.hepevt_set_event_number(C.int(evtno))
-}
+// FIXME: make sure the massaging of indices is consistent...
+//         - do we expect a C-based index or a FORTRAN one ?
+//         - for index ?
+//         - for firstchild/lastchild ?
 
-// set number of entries in HEPEVT
-func SetNumberEntries(nentries int) {
-	C.hepevt_set_number_entries(C.int(nentries))
-}
+// // set event number
+// func SetEventNumber(evtno int) {
+// 	C.hepevt_set_event_number(C.int(evtno))
+// }
 
-// set particle status code
-func SetStatusCode(index, status int) {
-	C.hepevt_set_status_code(C.int(index), C.int(status))
-}
+// // set number of entries in HEPEVT
+// func SetNumberEntries(nentries int) {
+// 	C.hepevt_set_number_entries(C.int(nentries))
+// }
 
-// set particle PDG-id
-func SetPdgId(index, id int) {
-	C.hepevt_set_pdg_id(C.int(index), C.int(id))
-}
+// // set particle status code
+// func SetStatusCode(index, status int) {
+// 	C.hepevt_set_status_code(C.int(index), C.int(status))
+// }
 
-// define parents of a particle
-func SetParents(index, firstparent, lastparent int) {
-	C.hepevt_set_parents(
-		C.int(index),
-		C.int(firstparent),
-		C.int(lastparent))
-}
+// // set particle PDG-id
+// func SetPdgId(index, id int) {
+// 	C.hepevt_set_pdg_id(C.int(index), C.int(id))
+// }
 
-// define children of a particle
-func SetChildren(index, firstchild, lastchild int) {
-	C.hepevt_set_children(
-		C.int(index),
-		C.int(firstchild),
-		C.int(lastchild))
-}
+// // define parents of a particle
+// func SetParents(index, firstparent, lastparent int) {
+// 	C.hepevt_set_parents(
+// 		C.int(index),
+// 		C.int(firstparent),
+// 		C.int(lastparent))
+// }
 
-// set particle momentum
-func SetMomentum(index int, px, py, pz, e float64) {
-	C.hepevt_set_momentum(
-		C.int(index),
-		C.double(px), C.double(py),
-		C.double(pz), C.double(e))
-}
+// // define children of a particle
+// func SetChildren(index, firstchild, lastchild int) {
+// 	C.hepevt_set_children(
+// 		C.int(index),
+// 		C.int(firstchild),
+// 		C.int(lastchild))
+// }
 
-// set particle mass
-func SetMass(index int, m float64) {
-	C.hepevt_set_mass(C.int(index), C.double(m))
-}
+// // set particle momentum
+// func SetMomentum(index int, px, py, pz, e float64) {
+// 	C.hepevt_set_momentum(
+// 		C.int(index),
+// 		C.double(px), C.double(py),
+// 		C.double(pz), C.double(e))
+// }
 
-// set particle production vertex
-func SetPosition(index int, x, y, z, t float64) {
-	C.hepevt_set_position(
-		C.int(index),
-		C.double(x), C.double(y),
-		C.double(z), C.double(t))
-}
+// // set particle mass
+// func SetMass(index int, m float64) {
+// 	C.hepevt_set_mass(C.int(index), C.double(m))
+// }
+
+// // set particle production vertex
+// func SetPosition(index int, x, y, z, t float64) {
+// 	C.hepevt_set_position(
+// 		C.int(index),
+// 		C.double(x), C.double(y),
+// 		C.double(z), C.double(t))
+// }
 
 // HEPEVT floorplan ---------------------------------------------------------
 
 	Encode(v interface{}) os.Error
 }
 
+func max(i,j int) int {
+	switch i > j {
+	case true:
+		return i
+	default:
+		return j
+	}
+	return j
+}
 func GetEvent() *Event {
 	evt := &Event{Nevhep: EventNumber(),	Nhep: NumberEntries()}
 	evt.Isthep = make([]int, evt.Nhep)
 	evt.Vhep =   make([][4]float64, evt.Nhep)
 
 	for i:=0; i != evt.Nhep; i++ {
-		j := 1 + i // fortran index...
-		evt.Isthep[i] = StatusCode(j)
-		evt.Idhep[i]  = PdgId(j)
-		evt.Jmohep[i][0] = FirstParent(j)
-		evt.Jmohep[i][1] = LastParent(j)
-		evt.Jdahep[i][0] = FirstChild(j)
-		evt.Jdahep[i][1] = LastChild(j)
-		evt.Phep[i][0] = Px(j)
-		evt.Phep[i][1] = Py(j)
-		evt.Phep[i][2] = Pz(j)
-		evt.Phep[i][3] = E(j)
-		evt.Phep[i][4] = M(j)
-		evt.Vhep[i][0] = X(j)
-		evt.Vhep[i][1] = Y(j)
-		evt.Vhep[i][2] = Z(j)
-		evt.Vhep[i][3] = T(j)
+		evt.Isthep[i] = StatusCode(i)
+		evt.Idhep[i]  = PdgId(i)
+		// -1 to correct for fortran index value
+		// if return value <0 => no parent
+		evt.Jmohep[i][0] = max(0, FirstParent(i) - 1)
+		// -1 to correct for fortran index value
+		evt.Jmohep[i][1] = max(0, LastParent(i) - 1)
+		// -1 to correct for fortran index value
+		// if return value <0 => no child
+		evt.Jdahep[i][0] = max(0, FirstChild(i) - 1)
+		// -1 to correct for fortran index value
+		evt.Jdahep[i][1] = max(0, LastChild(i) - 1)
+		evt.Phep[i][0] = Px(i)
+		evt.Phep[i][1] = Py(i)
+		evt.Phep[i][2] = Pz(i)
+		evt.Phep[i][3] = E(i)
+		evt.Phep[i][4] = M(i)
+		evt.Vhep[i][0] = X(i)
+		evt.Vhep[i][1] = Y(i)
+		evt.Vhep[i][2] = Z(i)
+		evt.Vhep[i][3] = T(i)
 	}
 	return evt
 }