16 modified files
java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions
--- java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -11,55 +11,25 @@
import org.lcsim.util.Driver;
/**
- * This {@link org.lcsim.util.Driver} sets up the {@link DatabaseConditionsManager} and
- * loads the conditions onto a detector.
+ * This abstract {@link org.lcsim.util.Driver} contains the
+ * general methods used to set up {@link DatabaseConditionsManager}
+ * and load the conditions onto a detector. The connection
+ * parameters are set by subclasses.
*
* @author Jeremy McCormick <[log in to unmask]>
*/
-public final class ConditionsDriver extends Driver {
+public abstract class ConditionsDriver extends Driver {
// Static instance of the manager.
static DatabaseConditionsManager manager;
- // Default conditions system XML config, which is for the Test Run 2012 database.
- static final String DEFAULT_CONFIG = "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
-
- // Default database connection parameters, which points to the SLAC development database.
- static final String DEFAULT_CONNECTION = "/org/hps/conditions/config/conditions_database_testrun_2012_connection.properties";
-
- String ecalSubdetectorName = "Ecal";
- String svtSubdetectorName = "Tracker";
+ private String ecalSubdetectorName = "Ecal";
+ private String svtSubdetectorName = "Tracker";
boolean loadSvtConditions = true;
boolean loadEcalConditions = true;
- /**
- * Constructor which initializes the conditions manager with default connection
- * parameters and configuration.
- */
- public ConditionsDriver() {
- manager = new DatabaseConditionsManager();
- manager.setConnectionResource(DEFAULT_CONNECTION);
- manager.configure(DEFAULT_CONFIG);
- manager.register();
- }
- /**
- * Set the configuration XML resource to be used by the manager.
- * @param resource the configuration resource
- */
- public void setConfigResource(String resource) {
- manager.configure(resource);
- }
-
- /**
- * Set the connection properties file resource to be used by the manager.
- * @param resource the connection resource
- */
- public void setConnectionResource(String resource) {
- manager.setConnectionResource(resource);
- }
-
public void setLoadSvtConditions(boolean loadSvtConditions) {
this.loadSvtConditions = loadSvtConditions;
}
@@ -95,7 +65,7 @@
private void loadSvtConditions(Detector detector) {
SvtConditions conditions = manager.getCachedConditions(SvtConditions.class, SVT_CONDITIONS).getCachedData();
SvtDetectorSetup loader = new SvtDetectorSetup();
- loader.load(detector, conditions);
+ loader.load(detector.getSubdetector(svtSubdetectorName), conditions);
}
/**
java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/ecal
--- java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsConverter.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsConverter.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -6,64 +6,123 @@
import static org.hps.conditions.TableConstants.ECAL_GAINS;
import static org.hps.conditions.TableConstants.ECAL_TIME_SHIFTS;
+
+import org.lcsim.conditions.ConditionsConverter;
+import org.lcsim.conditions.ConditionsManager;
+
import org.hps.conditions.ecal.EcalBadChannel.EcalBadChannelCollection;
import org.hps.conditions.ecal.EcalCalibration.EcalCalibrationCollection;
import org.hps.conditions.ecal.EcalChannel.ChannelId;
import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
import org.hps.conditions.ecal.EcalGain.EcalGainCollection;
import org.hps.conditions.ecal.EcalTimeShift.EcalTimeShiftCollection;
-import org.lcsim.conditions.ConditionsConverter;
-import org.lcsim.conditions.ConditionsManager;
+import org.hps.conditions.DatabaseConditionsManager;
+import org.hps.conditions.TableMetaData;
/**
* This class loads all ecal conditions into an {@link EcalConditions} object from the
* database, based on the current run number known by the conditions manager.
+ *
* @author Jeremy McCormick <[log in to unmask]>
*/
public final class EcalConditionsConverter implements ConditionsConverter<EcalConditions> {
+ private TableMetaData metaData = null;
+ private String tableName = null;
+
/**
* Create ECAL conditions object containing all data for the current run.
*/
public EcalConditions getData(ConditionsManager manager, String name) {
- // Create new, empty conditions object to fill with data.
- EcalConditions conditions = new EcalConditions();
+ DatabaseConditionsManager dbConditionsManager = (DatabaseConditionsManager) manager;
- // Get the channel information from the database.
- EcalChannelCollection channels = manager.getCachedConditions(EcalChannelCollection.class, ECAL_CHANNELS).getCachedData();
+ // Get the table name containing the Ecal channel map from the database
+ // configuration. If it doesn't exist, use the default value.
+ metaData = dbConditionsManager.findTableMetaData(EcalChannelCollection.class);
+ if(metaData != null){
+ tableName = metaData.getTableName();
+ } else {
+ tableName = ECAL_CHANNELS;
+ }
+ // Get the Ecal channel map from the conditions database
+ EcalChannelCollection channels = manager.getCachedConditions(EcalChannelCollection.class, tableName).getCachedData();
+ // Create the Ecal conditions object that will be used to encapsulate
+ // Ecal conditions collections
+ EcalConditions conditions = new EcalConditions();
+
// Set the channel map.
conditions.setChannelCollection(channels);
System.out.println("channel collection size = " + channels.getObjects().size());
- // Add gains.
- EcalGainCollection gains = manager.getCachedConditions(EcalGainCollection.class, ECAL_GAINS).getCachedData();
+ // Get the table name containing the Ecal gains from the database
+ // configuration. If it doesn't exist, use the default value.
+ metaData = dbConditionsManager.findTableMetaData(EcalGainCollection.class);
+ if(metaData != null){
+ tableName = metaData.getTableName();
+ } else {
+ tableName = ECAL_GAINS;
+ }
+ // Add the gains
+ EcalGainCollection gains = manager.getCachedConditions(EcalGainCollection.class, tableName).getCachedData();
for (EcalGain gain : gains.getObjects()) {
ChannelId channelId = new ChannelId(new int[] {gain.getChannelId()});
EcalChannel channel = channels.findChannel(channelId);
conditions.getChannelConstants(channel).setGain(gain);
}
+ // Get the table name containing the Ecal bad channel map from the
+ // database configuration. If it doesn't exist, use the default value.
+ metaData = dbConditionsManager.findTableMetaData(EcalBadChannelCollection.class);
+ if(metaData != null){
+ tableName = metaData.getTableName();
+ } else {
+ tableName = ECAL_BAD_CHANNELS;
+ }
+
// Add bad channels.
- EcalBadChannelCollection badChannels = manager.getCachedConditions(EcalBadChannelCollection.class, ECAL_BAD_CHANNELS).getCachedData();
- for (EcalBadChannel badChannel : badChannels.getObjects()) {
- ChannelId channelId = new ChannelId(new int[] {badChannel.getChannelId()});
- EcalChannel channel = channels.findChannel(channelId);
- conditions.getChannelConstants(channel).setBadChannel(true);
+ // FIXME: This should be changed to catch a conditions record not found
+ // exception instead of a runtime exception
+ try {
+ EcalBadChannelCollection badChannels = manager.getCachedConditions(EcalBadChannelCollection.class, tableName).getCachedData();
+ for (EcalBadChannel badChannel : badChannels.getObjects()) {
+ ChannelId channelId = new ChannelId(new int[] {badChannel.getChannelId()});
+ EcalChannel channel = channels.findChannel(channelId);
+ conditions.getChannelConstants(channel).setBadChannel(true);
+ }
+ } catch(RuntimeException e){
+ e.printStackTrace();
}
+
+ // Get the table name containing the Ecal calibrations (pedestal, noise)
+ // from the database configuration. If it doesn't exist, use the default value.
+ metaData = dbConditionsManager.findTableMetaData(EcalCalibrationCollection.class);
+ if(metaData != null){
+ tableName = metaData.getTableName();
+ } else {
+ tableName = ECAL_CALIBRATIONS;
+ }
// Add calibrations including pedestal and noise values.
- EcalCalibrationCollection calibrations = manager.getCachedConditions(EcalCalibrationCollection.class, ECAL_CALIBRATIONS).getCachedData();
+ EcalCalibrationCollection calibrations = manager.getCachedConditions(EcalCalibrationCollection.class, tableName).getCachedData();
for (EcalCalibration calibration : calibrations.getObjects()) {
ChannelId channelId = new ChannelId(new int[] {calibration.getChannelId()});
EcalChannel channel = channels.findChannel(channelId);
conditions.getChannelConstants(channel).setCalibration(calibration);
}
+ // Get the table name containing the Ecal calibrations (pedestal, noise)
+ // from the database configuration. If it doesn't exist, use the default value.
+ metaData = dbConditionsManager.findTableMetaData(EcalTimeShiftCollection.class);
+ if(metaData != null){
+ tableName = metaData.getTableName();
+ } else {
+ tableName = ECAL_TIME_SHIFTS;
+ }
// Add time shifts.
- EcalTimeShiftCollection timeShifts = manager.getCachedConditions(EcalTimeShiftCollection.class, ECAL_TIME_SHIFTS).getCachedData();
+ EcalTimeShiftCollection timeShifts = manager.getCachedConditions(EcalTimeShiftCollection.class, tableName).getCachedData();
for (EcalTimeShift timeShift : timeShifts.getObjects()) {
ChannelId channelId = new ChannelId(new int[] {timeShift.getChannelId()});
EcalChannel channel = channels.findChannel(channelId);
java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/svt
--- java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/svt/SvtDetectorSetup.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/main/java/org/hps/conditions/svt/SvtDetectorSetup.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -8,6 +8,7 @@
import org.hps.conditions.svt.SvtT0Shift.SvtT0ShiftCollection;
import org.lcsim.detector.tracker.silicon.HpsSiSensor;
import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.compact.Subdetector;
import org.hps.util.Pair;
/**
@@ -21,14 +22,13 @@
/**
* Load conditions data onto a detector object.
*
- * @param detector The detector object.
+ * @param The detector object.
* @param conditions The conditions object.
*/
- public void load(Detector detector, SvtConditions conditions) {
+ public void load(Subdetector subdetector, SvtConditions conditions) {
// Find sensor objects.
- List<HpsSiSensor> sensors = detector.getSubdetector("Tracker").getDetectorElement().findDescendants(HpsSiSensor.class);
- //List<HpsSiSensor> sensors = detector.getDetectorElement().findDescendants(HpsSiSensor.class);
+ List<HpsSiSensor> sensors = subdetector.getDetectorElement().findDescendants(HpsSiSensor.class);
SvtChannelCollection channelMap = conditions.getChannelMap();
SvtDaqMappingCollection daqMap = conditions.getDaqMap();
SvtT0ShiftCollection t0Shifts = conditions.getT0Shifts();
java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions
--- java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/ConditionsDriverTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/ConditionsDriverTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -42,7 +42,7 @@
// Configure the loop.
loop.setLCIORecordSource(testFile);
- ConditionsDriver conditionsDriver = new ConditionsDriver();
+ ConditionsDriver conditionsDriver = new TestRunConditionsDriver();
conditionsDriver.setLoadSvtConditions(false);
loop.add(conditionsDriver);
RunNumberDriver runNumberDriver = new RunNumberDriver();
java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/beam
--- java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/beam/BeamCurrentTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/beam/BeamCurrentTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -10,6 +10,7 @@
import junit.framework.TestCase;
import org.hps.conditions.ConditionsDriver;
+import org.hps.conditions.TestRunConditionsDriver;
import org.hps.conditions.beam.BeamCurrent.BeamCurrentCollection;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.event.EventHeader;
@@ -57,7 +58,7 @@
// Configure and run the loop.
loop.setLCIORecordSource(testFile);
- ConditionsDriver conditionsDriver = new ConditionsDriver();
+ ConditionsDriver conditionsDriver = new TestRunConditionsDriver();
conditionsDriver.setLoadSvtConditions(false);
loop.add(conditionsDriver);
loop.add(new BeamCurrentChecker());
java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/ecal
--- java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/ecal/PhysicalToGainTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/ecal/PhysicalToGainTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -8,6 +8,7 @@
import org.hps.conditions.ConditionsDriver;
import org.hps.conditions.TableConstants;
+import org.hps.conditions.TestRunConditionsDriver;
import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
import org.hps.conditions.ecal.EcalChannel.GeometryId;
import org.lcsim.conditions.ConditionsManager;
@@ -43,7 +44,7 @@
// Configure the loop.
loop.setLCIORecordSource(testFile);
- ConditionsDriver conditionsDriver = new ConditionsDriver();
+ ConditionsDriver conditionsDriver = new TestRunConditionsDriver();
conditionsDriver.setLoadSvtConditions(false);
loop.add(conditionsDriver);
loop.add(new PhysicalToGainDriver());
java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/svt
--- java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/svt/SvtBadChannelTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/svt/SvtBadChannelTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -9,8 +9,8 @@
import junit.framework.TestCase;
-import org.hps.conditions.ConditionsDriver;
import org.hps.conditions.DatabaseConditionsManager;
+import org.hps.conditions.TestRunConditionsDriver;
import org.lcsim.detector.tracker.silicon.HpsSiSensor;
import org.lcsim.event.EventHeader;
import org.lcsim.geometry.Detector;
@@ -58,7 +58,7 @@
// Configure the loop.
loop.setLCIORecordSource(testFile);
- loop.add(new ConditionsDriver());
+ loop.add(new TestRunConditionsDriver());
loop.add(new SvtBadChannelChecker());
DatabaseConditionsManager.getInstance().setLogLevel(Level.OFF);
java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/svt
--- java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/svt/SvtDetectorSetupTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/conditions/src/test/java/org/hps/conditions/svt/SvtDetectorSetupTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -54,11 +54,10 @@
// Load the SVT conditions onto detector.
SvtDetectorSetup loader = new SvtDetectorSetup();
- loader.load(detector, conditions);
+ loader.load(detector.getSubdetector(SVT_SUBDETECTOR_NAME), conditions);
// Check sensor data.
List<HpsSiSensor> sensors = detector.getSubdetector(SVT_SUBDETECTOR_NAME).getDetectorElement().findDescendants(HpsSiSensor.class);
- //List<HpsSiSensor> sensors = detector.getDetectorElement().findDescendants(HpsSiSensor.class);
// Check for correct number of sensors processed.
this.printDebug("Total number of sensors found: " + sensors.size());
java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps
--- java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps/EcalReadoutSimTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps/EcalReadoutSimTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -86,9 +86,8 @@
static final String className = EcalReadoutSimTest.class.getSimpleName();
// Resource locations.
- static final String resourceDir = "/org/hps/ecalreadoutsim/";
- static final String steeringResource = resourceDir + className + ".lcsim";
- static final String triggeredEventsResource = resourceDir + "triggered_events.txt";
+ static final String steeringResource = "/org/hps/steering/test/EcalReadoutSimTest.lcsim";
+ static final String triggeredEventsResource = "/org/hps/test/EcalReadoutSimTest/triggered_events.txt";
// File information.
static final File inputFile = new File("/nfs/slac/g/hps3/data/testcase/ecal_readout_sim_input.slcio");
java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps
--- java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps/GenerateEcalReadoutSimData.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps/GenerateEcalReadoutSimData.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -15,7 +15,7 @@
public class GenerateEcalReadoutSimData extends TestCase {
// This file is tridents, AP and backgrounds merged together into one event file.
- static String dataPath = "/nfs/slac/g/hps3/data/testcase/ap025mev_egs_tri_2.2gev_0.00125x0_200na_5e5b_30mr_001_SLIC-v04-00-00_Geant4-v10-00-02_QGSP_BERT_HPS-Proposal2014-v8-6pt6.slcio";
+ static String dataPath = "/nfs/slac/g/hps3/data/testcase/ap050mev_egs_tri_6.6gev_0.0025x0_450na_5e5b_30mr_001_SLIC-v04-00-00_Geant4-v10-00-02_QGSP_BERT_HPS-Proposal2014-v8-6pt6.slcio";
public void testGenerateReadoutSimData() throws Exception {
java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps
--- java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps/MockDataReconTest.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/integration-tests/src/test/java/org/hps/MockDataReconTest.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -35,7 +35,7 @@
static final File reconFile = new File(outputFile.getAbsolutePath() + ".slcio");
static final File aidaFile = new File(outputFile.getAbsolutePath() + ".aida");
- static final String steeringResource = "/org/hps/mockdatarecon/MockDataReconTest.lcsim";
+ static final String steeringResource = "/org/hps/steering/test/MockDataReconTest.lcsim";
//static final String steeringResource = "/org/hps/steering/recon/HPS2014OfflineTruthRecon.lcsim";
// TODO: Get some values for these and add test assertions!
java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix
--- java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/BorderedBandMatrix.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/BorderedBandMatrix.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -3,6 +3,7 @@
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.Math.max;
+import java.util.List;
/**
*
@@ -37,8 +38,8 @@
private int numBand; ///< Band width
private int numCol; ///< Band matrix size
private VSymMatrix theBorder = new VSymMatrix(0); ///< Border part
- private VMatrix theMixed = new VMatrix(0,0); ///< Mixed part
- private VMatrix theBand = new VMatrix(0,0); ///< Band part
+ private VMatrix theMixed = new VMatrix(0, 0); ///< Mixed part
+ private VMatrix theBand = new VMatrix(0, 0); ///< Band part
/// Resize bordered band matrix.
/**
@@ -65,26 +66,21 @@
* of rows/colums to be used \param aVector [in] Vector
*/
public void addBlockMatrix(double aWeight,
- int[] anIndex,
- double[] aVector)
+ int[] anIndex,
+ double[] aVector)
{
int nBorder = numBorder;
- for (int i = 0; i < anIndex.length; ++i)
- {
+ for (int i = 0; i < anIndex.length; ++i) {
int iIndex = (anIndex)[i] - 1; // anIndex has to be sorted
- for (int j = 0; j <= i; ++j)
- {
+ for (int j = 0; j <= i; ++j) {
int jIndex = (anIndex)[j] - 1;
- if (iIndex < nBorder)
- {
+ if (iIndex < nBorder) {
theBorder.addTo(iIndex, jIndex, aVector[i] * aWeight
* aVector[j]);
- } else if (jIndex < nBorder)
- {
+ } else if (jIndex < nBorder) {
theMixed.addTo(jIndex, iIndex - nBorder, aVector[i] * aWeight
* aVector[j]);
- } else
- {
+ } else {
int nBand = iIndex - jIndex;
theBand.addTo(nBand, jIndex - nBorder, aVector[i] * aWeight
* aVector[j]);
@@ -94,34 +90,36 @@
}
}
-///// Retrieve symmetric block matrix.
-///**
-// * Get (compressed) block from bordered band matrix: aMatrix(i,j) = BBmatrix(anIndex(i),anIndex(j)).
-// * \param anIndex [in] List of rows/colums to be used
-// */
-//TMatrixDSym BorderedBandMatrix::getBlockMatrix(
-// const std::vector<unsigned int> anIndex) const {
-//
-// TMatrixDSym aMatrix(anIndex.size());
-// int nBorder = numBorder;
-// for (unsigned int i = 0; i < anIndex.size(); ++i) {
-// int iIndex = anIndex[i] - 1; // anIndex has to be sorted
-// for (unsigned int j = 0; j <= i; ++j) {
-// int jIndex = anIndex[j] - 1;
-// if (iIndex < nBorder) {
-// aMatrix(i, j) = theBorder(iIndex, jIndex); // border part of inverse
-// } else if (jIndex < nBorder) {
-// aMatrix(i, j) = -theMixed(jIndex, iIndex - nBorder); // mixed part of inverse
-// } else {
-// unsigned int nBand = iIndex - jIndex;
-// aMatrix(i, j) = theBand(nBand, jIndex - nBorder); // band part of inverse
-// }
-// aMatrix(j, i) = aMatrix(i, j);
-// }
-// }
-// return aMatrix;
-//}
+/// Retrieve symmetric block matrix.
+ /**
+ * Get (compressed) block from bordered band matrix: aMatrix(i,j) =
+ * BBmatrix(anIndex(i),anIndex(j)). \param anIndex [in] List of rows/colums
+ * to be used
+ */
+ public SymMatrix getBlockMatrix(List<Integer> anIndex)
+ {
+
+ SymMatrix aMatrix = new SymMatrix(anIndex.size());
+ int nBorder = numBorder;
+ for (int i = 0; i < anIndex.size(); ++i) {
+ int iIndex = anIndex.get(i) - 1; // anIndex has to be sorted
+ for (int j = 0; j <= i; ++j) {
+ int jIndex = anIndex.get(j) - 1;
+ if (iIndex < nBorder) {
+ aMatrix.set(i, j, theBorder.get(iIndex, jIndex)); // border part of inverse
+ } else if (jIndex < nBorder) {
+ aMatrix.set(i, j, -theMixed.get(jIndex, iIndex - nBorder)); // mixed part of inverse
+ } else {
+ int nBand = iIndex - jIndex;
+ aMatrix.set(i, j, theBand.get(nBand, jIndex - nBorder)); // band part of inverse
+ }
+ aMatrix.set(j, i, aMatrix.get(i, j));
+ }
+ }
+ return aMatrix;
+ }
/// Solve linear equation system, partially calculate inverse.
+
/**
* Solve linear equation A*x=b system with bordered band matrix A, calculate
* bordered band part of inverse of A. Use decomposition in border and band
@@ -146,38 +144,40 @@
* \param [in] aRightHandSide Right hand side (vector) 'b' of A*x=b \param
* [out] aSolution Solution (vector) x of A*x=b
*/
-public void solveAndInvertBorderedBand(
- VVector aRightHandSide, VVector aSolution) {
+ public void solveAndInvertBorderedBand(
+ VVector aRightHandSide, VVector aSolution)
+ {
- // decompose band
- decomposeBand();
- // invert band
- VMatrix inverseBand = invertBand();
- if (numBorder > 0) { // need to use block matrix decomposition to solve
- // solve for mixed part
- VMatrix auxMat = solveBand(theMixed); // = Xt
- VMatrix auxMatT = auxMat.transpose(); // = X
- // solve for border part
- VVector auxVec = aRightHandSide.getVec(numBorder,0).minus(
- auxMat.times( aRightHandSide.getVec(numCol, numBorder) ) ); // = b1 - Xt*b2
- VSymMatrix inverseBorder = theBorder.minus(theMixed.times(auxMatT) );
- inverseBorder.invert(); // = E
- VVector borderSolution = inverseBorder.times(auxVec); // = x1
- // solve for band part
- VVector bandSolution = solveBand(
- aRightHandSide.getVec(numCol, numBorder)); // = x
- aSolution.putVec(borderSolution,0);
- aSolution.putVec(bandSolution.minus(auxMatT.times(borderSolution)), numBorder); // = x2
- // parts of inverse
- theBorder = inverseBorder; // E
- theMixed = inverseBorder.times(auxMat); // E*Xt (-mixed part of inverse) !!!
- theBand = inverseBand.plus(bandOfAVAT(auxMatT, inverseBorder)); // band(D^-1 + X*E*Xt)
- } else {
- aSolution.putVec(solveBand(aRightHandSide),0);
- theBand = inverseBand;
- }
-}
+ // decompose band
+ decomposeBand();
+ // invert band
+ VMatrix inverseBand = invertBand();
+ if (numBorder > 0) { // need to use block matrix decomposition to solve
+ // solve for mixed part
+ VMatrix auxMat = solveBand(theMixed); // = Xt
+ VMatrix auxMatT = auxMat.transpose(); // = X
+ // solve for border part
+ VVector auxVec = aRightHandSide.getVec(numBorder, 0).minus(
+ auxMat.times(aRightHandSide.getVec(numCol, numBorder))); // = b1 - Xt*b2
+ VSymMatrix inverseBorder = theBorder.minus(theMixed.times(auxMatT));
+ inverseBorder.invert(); // = E
+ VVector borderSolution = inverseBorder.times(auxVec); // = x1
+ // solve for band part
+ VVector bandSolution = solveBand(
+ aRightHandSide.getVec(numCol, numBorder)); // = x
+ aSolution.putVec(borderSolution, 0);
+ aSolution.putVec(bandSolution.minus(auxMatT.times(borderSolution)), numBorder); // = x2
+ // parts of inverse
+ theBorder = inverseBorder; // E
+ theMixed = inverseBorder.times(auxMat); // E*Xt (-mixed part of inverse) !!!
+ theBand = inverseBand.plus(bandOfAVAT(auxMatT, inverseBorder)); // band(D^-1 + X*E*Xt)
+ } else {
+ aSolution.putVec(solveBand(aRightHandSide), 0);
+ theBand = inverseBand;
+ }
+ }
/// Print bordered band matrix.
+
public void printMatrix()
{
System.out.println("Border part ");
@@ -204,29 +204,22 @@
int nRow = numBand + 1;
int nCol = numCol;
VVector auxVec = new VVector(nCol);
- for (int i = 0; i < nCol; ++i)
- {
+ for (int i = 0; i < nCol; ++i) {
auxVec.set(i, theBand.get(0, i) * 16.0); // save diagonal elements
}
- for (int i = 0; i < nCol; ++i)
- {
- if ((theBand.get(0, i) + auxVec.get(i)) != theBand.get(0, i))
- {
+ for (int i = 0; i < nCol; ++i) {
+ if ((theBand.get(0, i) + auxVec.get(i)) != theBand.get(0, i)) {
theBand.set(0, i, 1.0 / theBand.get(0, i));
- if (theBand.get(0, i) < 0.)
- {
+ if (theBand.get(0, i) < 0.) {
throw new RuntimeException("BorderedBandMatrix decomposeBand not positive definite");
}
- } else
- {
+ } else {
theBand.set(0, i, 0.0);
throw new RuntimeException("BorderedBandMatrix decomposeBand singular");
}
- for (int j = 1; j < min(nRow, nCol - i); ++j)
- {
+ for (int j = 1; j < min(nRow, nCol - i); ++j) {
double rxw = theBand.get(j, i) * theBand.get(0, i);
- for (int k = 0; k < min(nRow, nCol - i) - j; ++k)
- {
+ for (int k = 0; k < min(nRow, nCol - i) - j; ++k) {
theBand.subFrom(k, i + j, theBand.get(k + j, i) * rxw);
}
theBand.set(j, i, rxw);
@@ -245,13 +238,10 @@
int nCol = numCol;
VMatrix inverseBand = new VMatrix(nRow, nCol);
- for (int i = nCol - 1; i >= 0; i--)
- {
+ for (int i = nCol - 1; i >= 0; i--) {
double rxw = theBand.get(0, i);
- for (int j = i; j >= max(0, i - nRow + 1); j--)
- {
- for (int k = j + 1; k < min(nCol, j + nRow); ++k)
- {
+ for (int j = i; j >= max(0, i - nRow + 1); j--) {
+ for (int k = j + 1; k < min(nCol, j + nRow); ++k) {
rxw -= inverseBand.get(abs(i - k), min(i, k))
* theBand.get(k - j, j);
}
@@ -277,16 +267,14 @@
VVector aSolution = new VVector(aRightHandSide);
for (int i = 0; i < nCol; ++i) // forward substitution
{
- for (int j = 1; j < min(nRow, nCol - i); ++j)
- {
+ for (int j = 1; j < min(nRow, nCol - i); ++j) {
aSolution.subFrom(j + i, theBand.get(j, i) * aSolution.get(i));
}
}
for (int i = nCol - 1; i >= 0; i--) // backward substitution
{
double rxw = theBand.get(0, i) * aSolution.get(i);
- for (int j = 1; j < min(nRow, nCol - i); ++j)
- {
+ for (int j = 1; j < min(nRow, nCol - i); ++j) {
rxw -= theBand.get(j, i) * aSolution.get(j + i);
}
aSolution.set(i, rxw);
@@ -306,12 +294,10 @@
int nRow = theBand.getNumRows();
int nCol = theBand.getNumCols();
VMatrix aSolution = new VMatrix(aRightHandSide);
- for (int iBorder = 0; iBorder < numBorder; iBorder++)
- {
+ for (int iBorder = 0; iBorder < numBorder; iBorder++) {
for (int i = 0; i < nCol; ++i) // forward substitution
{
- for (int j = 1; j < min(nRow, nCol - i); ++j)
- {
+ for (int j = 1; j < min(nRow, nCol - i); ++j) {
aSolution.subFrom(iBorder, j + i, theBand.get(j, i)
* aSolution.get(iBorder, i));
}
@@ -319,8 +305,7 @@
for (int i = nCol - 1; i >= 0; i--) // backward substitution
{
double rxw = theBand.get(0, i) * aSolution.get(iBorder, i);
- for (int j = 1; j < min(nRow, nCol - i); ++j)
- {
+ for (int j = 1; j < min(nRow, nCol - i); ++j) {
rxw -= theBand.get(j, i) * aSolution.get(iBorder, j + i);
}
aSolution.set(iBorder, i, rxw);
@@ -329,32 +314,31 @@
return aSolution;
}
-
/// Calculate band part of: 'anArray * aSymArray * anArray.T'.
-/**
- * \return Band part of product
- */
-private VMatrix bandOfAVAT( VMatrix anArray,
- VSymMatrix aSymArray) {
- int nBand = numBand;
- int nCol = numCol;
- int nBorder = numBorder;
- double sum;
- VMatrix aBand = new VMatrix((nBand + 1), nCol);
- for (int i = 0; i < nCol; ++i) {
- for (int j = max(0, i - nBand); j <= i; ++j) {
- sum = 0.;
- for (int l = 0; l < nBorder; ++l) { // diagonal
- sum += anArray.get(i, l) * aSymArray.get(l, l) * anArray.get(j, l);
- for (int k = 0; k < l; ++k) { // off diagonal
- sum += anArray.get(i, l) * aSymArray.get(l, k) * anArray.get(j, k)
- + anArray.get(i, k) * aSymArray.get(l, k) * anArray.get(j, l);
- }
- }
- aBand.set(i - j, j, sum);
- }
- }
- return aBand;
-}
-
-}
+ /**
+ * \return Band part of product
+ */
+ private VMatrix bandOfAVAT(VMatrix anArray,
+ VSymMatrix aSymArray)
+ {
+ int nBand = numBand;
+ int nCol = numCol;
+ int nBorder = numBorder;
+ double sum;
+ VMatrix aBand = new VMatrix((nBand + 1), nCol);
+ for (int i = 0; i < nCol; ++i) {
+ for (int j = max(0, i - nBand); j <= i; ++j) {
+ sum = 0.;
+ for (int l = 0; l < nBorder; ++l) { // diagonal
+ sum += anArray.get(i, l) * aSymArray.get(l, l) * anArray.get(j, l);
+ for (int k = 0; k < l; ++k) { // off diagonal
+ sum += anArray.get(i, l) * aSymArray.get(l, k) * anArray.get(j, k)
+ + anArray.get(i, k) * aSymArray.get(l, k) * anArray.get(j, l);
+ }
+ }
+ aBand.set(i - j, j, sum);
+ }
+ }
+ return aBand;
+ }
+}
\ No newline at end of file
java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix
--- java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/Matrix.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/Matrix.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -205,22 +205,22 @@
// return X;
// }
//
-// /**
-// * Make a deep copy of a matrix
-// */
-// public Matrix copy()
-// {
-// Matrix X = new Matrix(m, n);
-// double[][] C = X.getArray();
-// for (int i = 0; i < m; i++)
-// {
-// for (int j = 0; j < n; j++)
-// {
-// C[i][j] = A[i][j];
-// }
-// }
-// return X;
-// }
+ /**
+ * Make a deep copy of a matrix
+ */
+ public Matrix copy()
+ {
+ Matrix X = new Matrix(m, n);
+ double[][] C = X.getArray();
+ for (int i = 0; i < m; i++)
+ {
+ for (int j = 0; j < n; j++)
+ {
+ C[i][j] = A[i][j];
+ }
+ }
+ return X;
+ }
//
// /**
// * Clone the Matrix object.
@@ -1354,27 +1354,27 @@
output.println(); // end with blank line.
}
+ /**
+ * String representation for this Object.
+ *
+ * @return string representation of this object.
+ */
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer();
+ for (int i = 0; i < m; ++i)
+ {
+ for (int j = 0; j < n; ++j)
+ {
+ tmp.append(" " + A[i][j]);
+ }
+ tmp.append("\n");
+ }
+ tmp.append("\n");
+ return tmp.toString();
+ }
+
// /**
-// * String representation for this Object.
-// *
-// * @return string representation of this object.
-// */
-// public String toString()
-// {
-// StringBuffer tmp = new StringBuffer();
-// for (int i = 0; i < m; ++i)
-// {
-// for (int j = 0; j < n; ++j)
-// {
-// tmp.append(" " + A[i][j]);
-// }
-// tmp.append("\n");
-// }
-// tmp.append("\n");
-// return tmp.toString();
-// }
-//
-// /**
// * Read a matrix from a stream. The format is the same the print method, so
// * printed matrices can be read back in (provided they were printed using US
// * Locale). Elements are separated by whitespace, all the elements for each
java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix
--- java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/VMatrix.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/VMatrix.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -23,33 +23,31 @@
numRows = nRows;
numCols = nCols;
theVec = new ArrayList(nRows * nCols);
- for (int i = 0; i < numRows * nCols; ++i)
- {
+ for (int i = 0; i < numRows * nCols; ++i) {
theVec.add(0.);
}
}
-
-public VMatrix(VMatrix m)
+
+ public VMatrix(VMatrix m)
{
numRows = m.numRows;
numCols = m.numCols;
theVec = new ArrayList(numRows * numCols);
- for (int i = 0; i < numRows; ++i)
- {
- for(int j=0; j<numCols; ++j)
- {
- theVec.set(numCols * i + j, m.get(i, j));
+ for (int i = 0; i < numRows * numCols; ++i) {
+ theVec.add(0.);
+ }
+ for (int i = 0; i < numRows; ++i) {
+ for (int j = 0; j < numCols; ++j) {
+ theVec.set(numCols * i + j, m.get(i, j));
}
}
- }
+ }
public VMatrix copy()
{
VMatrix aResult = new VMatrix(numRows, numCols);
- for (int i = 0; i < numRows; ++i)
- {
- for (int j = 0; j < numCols; ++j)
- {
+ for (int i = 0; i < numRows; ++i) {
+ for (int j = 0; j < numCols; ++j) {
{
aResult.set(i, j, get(i, j));
}
@@ -69,8 +67,7 @@
numRows = nRows;
numCols = nCols;
theVec = new ArrayList(numRows * nCols);
- for (int i = 0; i < numRows * nCols; ++i)
- {
+ for (int i = 0; i < numRows * nCols; ++i) {
theVec.add(0.);
}
}
@@ -82,10 +79,8 @@
public VMatrix transpose()
{
VMatrix aResult = new VMatrix(numCols, numRows);
- for (int i = 0; i < numRows; ++i)
- {
- for (int j = 0; j < numCols; ++j)
- {
+ for (int i = 0; i < numRows; ++i) {
+ for (int j = 0; j < numCols; ++j) {
//System.out.println("row: "+i+" col: "+j+" val: "+theVec.get(numCols * i + j));
aResult.set(j, i, (double) theVec.get(numCols * i + j));
}
@@ -97,14 +92,15 @@
{
theVec.set(numCols * row + col, val);
}
-
- public void addTo(int row, int col, double val)
+
+ public void addTo(int row, int col, double val)
{
- theVec.set(numCols * row + col, (double) theVec.get(numCols * row + col)+val);
+ theVec.set(numCols * row + col, (double) theVec.get(numCols * row + col) + val);
}
- public void subFrom(int row, int col, double val)
+
+ public void subFrom(int row, int col, double val)
{
- theVec.set(numCols * row + col, (double) theVec.get(numCols * row + col)-val);
+ theVec.set(numCols * row + col, (double) theVec.get(numCols * row + col) - val);
}
public double get(int row, int col)
@@ -134,11 +130,9 @@
VVector times(VVector aVector)
{
VVector aResult = new VVector(numRows);
- for (int i = 0; i < numRows; ++i)
- {
+ for (int i = 0; i < numRows; ++i) {
double sum = 0.0;
- for (int j = 0; j < numCols; ++j)
- {
+ for (int j = 0; j < numCols; ++j) {
sum += (double) theVec.get(numCols * i + j) * aVector.get(j);
}
aResult.set(i, sum);
@@ -151,13 +145,10 @@
{
VMatrix aResult = new VMatrix(numRows, aMatrix.numCols);
- for (int i = 0; i < numRows; ++i)
- {
- for (int j = 0; j < aMatrix.numCols; ++j)
- {
+ for (int i = 0; i < numRows; ++i) {
+ for (int j = 0; j < aMatrix.numCols; ++j) {
double sum = 0.0;
- for (int k = 0; k < numCols; ++k)
- {
+ for (int k = 0; k < numCols; ++k) {
sum += (double) theVec.get(numCols * i + k) * aMatrix.get(k, j);
}
aResult.set(i, j, sum);
@@ -170,10 +161,8 @@
VMatrix plus(VMatrix aMatrix)
{
VMatrix aResult = new VMatrix(numRows, numCols);
- for (int i = 0; i < numRows; ++i)
- {
- for (int j = 0; j < numCols; ++j)
- {
+ for (int i = 0; i < numRows; ++i) {
+ for (int j = 0; j < numCols; ++j) {
aResult.set(i, j, (double) theVec.get(numCols * i + j) + (double) aMatrix.get(i, j));
}
}
@@ -184,12 +173,9 @@
public void print()
{
System.out.println(" VMatrix: " + numRows + "*" + numCols);
- for (int i = 0; i < numRows; ++i)
- {
- for (int j = 0; j < numCols; ++j)
- {
- if (j % 5 == 0)
- {
+ for (int i = 0; i < numRows; ++i) {
+ for (int j = 0; j < numCols; ++j) {
+ if (j % 5 == 0) {
System.out.format("%n%4d " + "," + "%4d" + " - " + "%4d" + " : ", i, j, min(j + 4, numCols));
}
System.out.format("%13f", theVec.get(numCols * i + j));
@@ -197,5 +183,4 @@
}
System.out.print("\n\n\n");
}
-
}
java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix
--- java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/VVector.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/VVector.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -21,8 +21,7 @@
{
numRows = nRows;
theVec = new ArrayList(nRows);
- for (int i = 0; i < numRows; ++i)
- {
+ for (int i = 0; i < numRows; ++i) {
theVec.add(0.);
}
}
@@ -44,12 +43,12 @@
{
theVec.set(row, val);
}
-
+
public void addTo(int row, double val)
{
theVec.set(row, (double) theVec.get(row) + val);
}
-
+
public void subFrom(int row, double val)
{
theVec.set(row, (double) theVec.get(row) - val);
@@ -67,7 +66,7 @@
*/
public VVector getVec(int len, int start)
{
- return new VVector(theVec.subList(start, start + len - 1));
+ return new VVector(theVec.subList(start, start + len));
}
@@ -93,10 +92,8 @@
public void print()
{
System.out.println(theVec.size());
- for (int i = 0; i < numRows; ++i)
- {
- if (i % 5 == 0)
- {
+ for (int i = 0; i < numRows; ++i) {
+ if (i % 5 == 0) {
System.out.format("%n%4d " + " - " + "%4d" + " : ", i, min(i + 4, numRows));
}
System.out.format("%13f", theVec.get(i));
@@ -108,8 +105,7 @@
VVector minus(VVector aVector)
{
VVector aResult = new VVector(numRows);
- for (int i = 0; i < numRows; ++i)
- {
+ for (int i = 0; i < numRows; ++i) {
aResult.set(i, (double) theVec.get(i) - aVector.get(i));
}
return aResult;
@@ -119,8 +115,7 @@
public VVector copy()
{
VVector aResult = new VVector(numRows);
- for (int i = 0; i < numRows; ++i)
- {
+ for (int i = 0; i < numRows; ++i) {
aResult.set(i, get(i));
}
return aResult;
java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix
--- java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/Vector.java 2014-09-17 06:22:25 UTC (rev 1034)
+++ java/branches/hps-java_HPSJAVA-88/tracking/src/main/java/org/hps/recon/tracking/gbl/matrix/Vector.java 2014-09-17 17:45:13 UTC (rev 1035)
@@ -73,7 +73,7 @@
{
Vector x = copyVector();
for (int i = 0; i < size(); ++i) {
- A[i][0] = -A[i][0];
+ x.set(i, -get(i));
}
return x;
}
@@ -184,7 +184,12 @@
public Vector plus(Vector vec) throws IllegalArgumentException
{
- return (Vector) super.plus(vec);
+ Vector tmp = new Vector(getSize());
+ for(int i=0; i<getSize(); ++i)
+ {
+ tmp.set(i, get(i)+vec.get(i));
+ }
+ return tmp;
}
/**
@@ -196,7 +201,12 @@
*/
public Vector timesScalar(double s)
{
- return (Vector) super.times(s);
+ Vector tmp = new Vector(getSize());
+ for(int i=0; i<getSize(); ++i)
+ {
+ tmp.set(i, get(i)*s);
+ }
+ return tmp;
}
// /**
SVNspam 0.1