Author: ngraf Date: Wed Nov 5 13:46:05 2014 New Revision: 1442 Log: Enable writing of millepedeII binary files. Modified: java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblData.java (contents, props changed) java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblTrajectory.java (contents, props changed) java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/HpsGblRefitter.java (contents, props changed) java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/MilleBinary.java (contents, props changed) Modified: java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblData.java ============================================================================= --- java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblData.java (original) +++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblData.java Wed Nov 5 13:46:05 2014 @@ -1,5 +1,6 @@ package org.hps.recon.tracking.gbl; +import static java.lang.Math.sqrt; import java.util.ArrayList; import java.util.List; import org.hps.recon.tracking.gbl.matrix.Matrix; @@ -270,27 +271,27 @@ return theParameters.size(); } -// -///// Get all Data for MP-II binary record. -///** -// * \param [out] fValue Value -// * \param [out] fErr Error -// * \param [out] indLocal List of labels of local parameters -// * \param [out] derLocal List of derivatives for local parameters -// * \param [out] labGlobal List of labels of global parameters -// * \param [out] derGlobal List of derivatives for global parameters -// */ -//void getAllData(float &fValue, float &fErr, -// std::vector<unsigned int>* &indLocal, std::vector<double>* &derLocal, -// std::vector<int>* &labGlobal, std::vector<double>* &derGlobal) { -// fValue = theValue; -// fErr = 1.0 / sqrt(thePrecision); -// indLocal = &theParameters; -// derLocal = &theDerivatives; -// labGlobal = &globalLabels; -// derGlobal = &globalDerivatives; -//} -// + +/// Get all Data for MP-II binary record. +/** + * \param [out] fValue Value + * \param [out] fErr Error + * \param [out] indLocal List of labels of local parameters + * \param [out] derLocal List of derivatives for local parameters + * \param [out] labGlobal List of labels of global parameters + * \param [out] derGlobal List of derivatives for global parameters + */ +void getAllData(float[] floats, + List<Integer> indLocal, List<Double> derLocal, + List<Integer> labGlobal, List<Double> derGlobal) { + floats[0] = (float)theValue; + floats[1] = (float) (1.0 / sqrt(thePrecision)); + indLocal.addAll(theParameters); + derLocal.addAll(theDerivatives); + labGlobal.addAll(globalLabels); + derGlobal.addAll(globalDerivatives); +} + ///// Get data for residual (and errors). ///** // * \param [out] aResidual Measurement-Prediction Modified: java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblTrajectory.java ============================================================================= --- java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblTrajectory.java (original) +++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/GblTrajectory.java Wed Nov 5 13:46:05 2014 @@ -34,11 +34,6 @@ public void fit(double m_chi2, int m_ndf, int m_lost_weight) { // TODO Auto-generated method stub - } - - public void milleOut(MilleBinary mille) - { - // TODO implement binary writeout of millepedeII data } /** @@ -756,30 +751,27 @@ return ierr; } - //TODO Implement the millepedeII output -///// Write trajectory to Millepede-II binary file. -//void milleOut(MilleBinary &aMille) { -// float fValue; -// float fErr; -// List< int>* indLocal; -// List<double>* derLocal; -// List<int>* labGlobal; -// List<double>* derGlobal; -// -// if (not constructOK) -// return; -// -//// data: measurements, kinks and external seed -// List<GblData>::iterator itData; -// for (itData = theData.begin(); itData != theData.end(); ++itData) { -// itData->getAllData(fValue, fErr, indLocal, derLocal, labGlobal, -// derGlobal); -// aMille.addData(fValue, fErr, *indLocal, *derLocal, *labGlobal, -// *derGlobal); -// } -// aMille.writeRecord(); -//} + +// Write trajectory to Millepede-II binary file. + public void milleOut(MilleBinary aMille) + { + if (!constructOK) { + throw new RuntimeException("GblTrajectory milleOut not properly constructed"); + } +// data: measurements, kinks and external seed + for (GblData d : theData) { + float[] floats = new float[2]; // fValue , fErr + List<Integer> indLocal = new ArrayList<Integer>(); + List<Double> derLocal = new ArrayList<Double>(); + List<Integer> labGlobal = new ArrayList<Integer>(); + List<Double> derGlobal = new ArrayList<Double>(); + d.getAllData(floats, indLocal, derLocal, labGlobal, derGlobal); + aMille.addData(floats[0], floats[1], indLocal, derLocal, labGlobal, derGlobal); + } + aMille.writeRecord(); + } /// Print GblTrajectory + /** * \param [in] level print level (0: minimum, >0: more) */ Modified: java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/HpsGblRefitter.java ============================================================================= --- java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/HpsGblRefitter.java (original) +++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/HpsGblRefitter.java Wed Nov 5 13:46:05 2014 @@ -23,9 +23,9 @@ import org.hps.recon.tracking.gbl.matrix.Vector; /** - * A Driver which refits tracks using GBL. - * Modeled on the hps-dst code written by Per Hansson and Omar Moreno. - * Requires the GBL Collections and Relations to be present in the event. + * A Driver which refits tracks using GBL. Modeled on the hps-dst code written + * by Per Hansson and Omar Moreno. Requires the GBL Collections and Relations to + * be present in the event. * * @author Norman A Graf * @@ -39,9 +39,43 @@ private final String track2GblTrackRelationName = "TrackToGBLTrack"; private final String gblTrack2StripRelationName = "GBLTrackToStripData"; + private MilleBinary mille; + private String milleBinaryFileName = MilleBinary.DEFAULT_OUTPUT_FILE_NAME; + private boolean writeMilleBinary = false; + public void setDebug(boolean debug) { _debug = debug; + } + + public void setMilleBinaryFileName(String filename) + { + milleBinaryFileName = filename; + } + + public void setWriteMilleBinary(boolean writeMillepedeFile) + { + writeMilleBinary = writeMillepedeFile; + } + + public HpsGblRefitter() + { + } + + @Override + protected void startOfData() + { + if (writeMilleBinary) { + mille = new MilleBinary(milleBinaryFileName); + } + } + + @Override + protected void endOfData() + { + if (writeMilleBinary) { + mille.close(); + } } @Override @@ -376,7 +410,9 @@ } // // write to MP binary file -// traj.milleOut(mille); + if (writeMilleBinary) { + traj.milleOut(mille); + } // return 0; } Modified: java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/MilleBinary.java ============================================================================= --- java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/MilleBinary.java (original) +++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/gbl/MilleBinary.java Wed Nov 5 13:46:05 2014 @@ -123,8 +123,8 @@ */ public void writeRecord() { - int recordLength = _intBuffer.size() * 2; - ByteBuffer b = ByteBuffer.allocate((recordLength + 1) * 2); + int recordLength = _intBuffer.size() * 2 * 4; // writing both ints and floats, each is 4 bytes + ByteBuffer b = ByteBuffer.allocate((recordLength + 1) * 2); // writing one extra word per collection b.order(ByteOrder.LITTLE_ENDIAN); b.putInt(recordLength); for (Float f : _floatBuffer) {