Print

Print


Commit in java/trunk/analysis/src/main/java/org/hps/analysis/dataquality on MAIN
DataQualityMonitor.java+45-13695 -> 696
FinalStateMonitoring.java+106-62695 -> 696
SVTHitMCEfficiency.java+1-1695 -> 696
SvtMonitoring.java+154-40695 -> 696
TrackingMonitoring.java+1-5695 -> 696
V0Monitoring.java+87-38695 -> 696
+394-159
6 modified files
More additional plots and numbers, including track residuals

java/trunk/analysis/src/main/java/org/hps/analysis/dataquality
DataQualityMonitor.java 695 -> 696
--- java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/DataQualityMonitor.java	2014-06-10 12:34:34 UTC (rev 695)
+++ java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/DataQualityMonitor.java	2014-06-10 14:56:41 UTC (rev 696)
@@ -2,6 +2,8 @@
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.lcsim.util.Driver;
@@ -23,17 +25,21 @@
     public boolean overwriteDB = false;
     public boolean connectToDB = false;
     public boolean printDQMStrings = false;
-
+    public Map<String, Double> monitoredQuantityMap = new HashMap<>();
     public void setRecoVersion(String recoVersion) {
         this.recoVersion = recoVersion;
     }
 
+    public void setRunNumber(int run) {
+        this.runNumber = run;
+    }
+
     public void setOverwriteDB(boolean overwrite) {
         this.overwriteDB = overwrite;
     }
 
     public void setConnectToDB(boolean connect) {
-        this.overwriteDB = connect;
+        this.connectToDB = connect;
     }
 
     public void setPrintDQMStrings(boolean print) {
@@ -50,24 +56,22 @@
         printDQMData();
         if (printDQMStrings)
             printDQMStrings();
+        System.out.println("Should I write to the database?  " + connectToDB);
         if (connectToDB) {
+            System.out.println("Connecting To Database...getting DQMDBManager");
             manager = DQMDatabaseManager.getInstance();
-        //fill any plots that only get filled at end of data...e.g. SVT occupancy plots
-
             //check to see if I need to make a new db entry
             boolean entryExists = false;
             try {
                 entryExists = checkRowExists();
                 if (entryExists)
-                    System.out.println("Found an existing run/reco entry in the dqm database");
+                    System.out.println("Found an existing run/reco entry in the dqm database; overwrite = " + overwriteDB);
             } catch (SQLException ex) {
                 Logger.getLogger(DataQualityMonitor.class.getName()).log(Level.SEVERE, null, ex);
             }
 
             if (!entryExists)
                 makeNewRow();
-            else if (!overwriteDB)
-                return; //entry exists and I don't want to overwrite
             dumpDQMData();
         }
 
@@ -76,13 +80,13 @@
     private void makeNewRow() {
         System.out.println("is the data base connected?  " + manager.isConnected);
         if (manager.isConnected) {
-            String ins = "insert into dqm SET run=" + runNumber;
+            String ins = "insert into dqm SET runNumber=" + runNumber;
 //            System.out.println(ins);
             manager.updateQuery(ins);
-            ins = "update  dqm SET recoversion='" + recoVersion + "' where run=" + runNumber;
+            ins = "update  dqm SET recoVersion='" + recoVersion + "' where runNumber=" + runNumber;
             manager.updateQuery(ins);
         }
-        System.out.println("Made a new row for run=" + runNumber + "; recon version=" + recoVersion);
+        System.out.println("Made a new row for runNumber=" + runNumber + "; recoVersion=" + recoVersion);
     }
 
     private boolean checkRowExists() throws SQLException {
@@ -93,8 +97,19 @@
         return false;
     }
 
+    public boolean checkSelectionIsNULL(String var) throws SQLException {
+        String ins = "select "+var+" from dqm where " + getRunRecoString();
+        ResultSet res = manager.selectQuery(ins);
+        res.next();
+        double result=res.getDouble(var);
+        if(res.wasNull())
+            return true;
+        System.out.println("checkSelectionIsNULL::"+var+" = "+result);
+        return false;
+    }
+
     public String getRunRecoString() {
-        return "run=" + runNumber + " and recoversion='" + recoVersion + "'";
+        return "runNumber=" + runNumber + " and recoVersion='" + recoVersion + "'";
     }
 
     //override this method to do something interesting   
@@ -107,9 +122,26 @@
     public void calculateEndOfRunQuantities() {
     }
 
-//override this method to do something interesting   
-    //like write the DQM data to the database
+  
     public void dumpDQMData() {
+        for (Map.Entry<String, Double> entry : monitoredQuantityMap.entrySet()) {
+            String name = entry.getKey();
+            double val = entry.getValue();
+             boolean isnull=false;
+               try {
+                 isnull=checkSelectionIsNULL(name);
+            } catch (SQLException ex) {
+                Logger.getLogger(SvtMonitoring.class.getName()).log(Level.SEVERE, null, ex);
+            }
+            if (!overwriteDB&&!isnull){                
+                System.out.println("Not writing because "+name+" is already filled for this entry");
+                continue; //entry exists and I don't want to overwrite                
+            }
+            String put = "update dqm SET "+name+" = " + val + " WHERE " + getRunRecoString();
+            System.out.println(put);
+            manager.updateQuery(put); 
+           
+        }
     }
 
     //override this method to do something interesting   

java/trunk/analysis/src/main/java/org/hps/analysis/dataquality
FinalStateMonitoring.java 695 -> 696
--- java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/FinalStateMonitoring.java	2014-06-10 12:34:34 UTC (rev 695)
+++ java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/FinalStateMonitoring.java	2014-06-10 14:56:41 UTC (rev 696)
@@ -1,12 +1,20 @@
 package org.hps.analysis.dataquality;
 
+import hep.aida.IAnalysisFactory;
+import hep.aida.IFitFactory;
+import hep.aida.IFitResult;
+import hep.aida.IFitter;
 import hep.aida.IHistogram1D;
+import hep.aida.IHistogram2D;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterStyle;
 import hep.physics.vec.BasicHep3Vector;
 import hep.physics.vec.Hep3Vector;
-import java.util.HashMap;
+import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.hps.recon.tracking.TrackUtils;
 import org.lcsim.event.Cluster;
 import org.lcsim.event.EventHeader;
@@ -21,17 +29,17 @@
  *
  * @author mgraham on Mar 28, 2014 big update on May 14, 2014...right now the
  * output is crap; no charge<0 tracks & the track momentum isn't filled; likely
- * a problem with ReconParticle 
- * 
- * May 20, 2014:  this was fixed by a) Omar's changes to ReconParticle and 
+ * a problem with ReconParticle
+ *
+ * May 20, 2014: this was fixed by a) Omar's changes to ReconParticle and
  * b) making sure I run ECal clustering before this
- * 
- * 
+ *
+ *
  */
 public class FinalStateMonitoring extends DataQualityMonitor {
 
     String finalStateParticlesColName = "FinalStateParticles";
-    private Map<String, Double> monitoredQuantityMap = new HashMap<>();
+
     String[] fpQuantNames = {"nEle_per_Event", "nPos_per_Event", "nPhoton_per_Event", "nUnAssociatedTracks_per_Event", "avg_delX_at_ECal", "avg_delY_at_ECal", "avg_E_Over_P"};
     //some counters
     int nRecoEvents = 0;
@@ -46,6 +54,7 @@
     double sumEoverP = 0.0;
     boolean debug = false;
     private String plotDir = "FinalStateParticles/";
+
     @Override
     protected void detectorChanged(Detector detector) {
         System.out.println("FinalStateMonitoring::detectorChanged  Setting up the plotter");
@@ -53,44 +62,45 @@
 
         /*  Final State Particle Quantities   */
         /*  plot electron & positron momentum separately  */
-        IHistogram1D elePx = aida.histogram1D(plotDir+"Electron Px (GeV)", 25, -0.1, 0.200);
-        IHistogram1D elePy = aida.histogram1D(plotDir+"Electron Py (GeV)", 25, -0.1, 0.1);
-        IHistogram1D elePz = aida.histogram1D(plotDir+"Electron Pz (GeV)", 25, 0, 2.4);
+        IHistogram1D elePx = aida.histogram1D(plotDir + "Electron Px (GeV)", 50, -0.1, 0.200);
+        IHistogram1D elePy = aida.histogram1D(plotDir + "Electron Py (GeV)", 50, -0.1, 0.1);
+        IHistogram1D elePz = aida.histogram1D(plotDir + "Electron Pz (GeV)", 50, 0, 2.5);
+        IHistogram1D elePzBeam = aida.histogram1D(plotDir + "Beam Electrons Pz (GeV)", 50, 1.8, 2.5);
 
-        IHistogram1D posPx = aida.histogram1D(plotDir+"Positron Px (GeV)", 25, -0.1, 0.200);
-        IHistogram1D posPy = aida.histogram1D(plotDir+"Positron Py (GeV)", 25, -0.1, 0.1);
-        IHistogram1D posPz = aida.histogram1D(plotDir+"Positron Pz (GeV)", 25, 0, 2.4);
+        IHistogram1D posPx = aida.histogram1D(plotDir + "Positron Px (GeV)", 50, -0.1, 0.200);
+        IHistogram1D posPy = aida.histogram1D(plotDir + "Positron Py (GeV)", 50, -0.1, 0.1);
+        IHistogram1D posPz = aida.histogram1D(plotDir + "Positron Pz (GeV)", 50, 0, 2.5);
         /*  photon quanties (...right now, just unassociated clusters) */
-        IHistogram1D nPhotonsHisto = aida.histogram1D(plotDir+"Number of photons per event", 10, 0, 10);
-        IHistogram1D enePhoton = aida.histogram1D(plotDir+"Photon Energy (GeV)", 25, 0, 2.4);
-        IHistogram1D xPhoton = aida.histogram1D(plotDir+"Photon X position (mm)", 25, -100, 100);
-        IHistogram1D yPhoton = aida.histogram1D(plotDir+"Photon Y position (mm)", 25, -100, 100);
+        IHistogram1D nPhotonsHisto = aida.histogram1D(plotDir + "Number of photons per event", 15, 0, 15);
+        IHistogram1D enePhoton = aida.histogram1D(plotDir + "Photon Energy (GeV)", 50, 0, 2.4);
+        IHistogram1D xPhoton = aida.histogram1D(plotDir + "Photon X position (mm)", 50, -100, 100);
+        IHistogram1D yPhoton = aida.histogram1D(plotDir + "Photon Y position (mm)", 50, -100, 100);
 
         /*  tracks with associated clusters */
-        IHistogram1D eneOverp = aida.histogram1D(plotDir+"Cluster Energy Over TrackMomentum", 25, 0, 2.0);
-        IHistogram1D deltaXAtCal = aida.histogram1D(plotDir+"delta X @ ECal (mm)", 25, -100, 100.0);
-        IHistogram1D deltaYAtCal = aida.histogram1D(plotDir+"delta Y @ ECal (mm)", 25, -100, 100.0);
-        /* number of unassocaited tracks */
-        IHistogram1D nUnAssTracksHisto = aida.histogram1D(plotDir+"Number of unassociated tracks per event", 10, 0, 10);
+        IHistogram1D eneOverp = aida.histogram1D(plotDir + "Cluster Energy Over TrackMomentum", 50, 0, 2.0);
+        IHistogram1D deltaXAtCal = aida.histogram1D(plotDir + "delta X @ ECal (mm)", 50, -100, 100.0);
+        IHistogram1D deltaYAtCal = aida.histogram1D(plotDir + "delta Y @ ECal (mm)", 50, -100, 100.0);
+        //IHistogram2D trackXvsECalX = aida.histogram2D(plotDir + "track X vs ECal X", 50, -300, 300.0, 50, -300, 300.0);
+        //IHistogram2D trackYvsECalY = aida.histogram2D(plotDir + "track Y vs ECal Y", 50, -100, 100.0, 50, -100, 100.0);
+        IHistogram2D trackPvsECalE = aida.histogram2D(plotDir + "track mom vs ECal E", 50, 0, 2.5, 50, 0, 2.5);
+        /* number of unassocaited tracks/event */
+        IHistogram1D nUnAssTracksHisto = aida.histogram1D(plotDir + "Number of unassociated tracks per event", 5, 0, 5);
     }
 
     @Override
     public void process(EventHeader event) {
         /*  make sure everything is there */
-        if (!event.hasCollection(ReconstructedParticle.class, finalStateParticlesColName)) {
+        if (!event.hasCollection(ReconstructedParticle.class, finalStateParticlesColName))
             return;
-        }
         nRecoEvents++;
         int nPhotons = 0;  //number of photons 
         int nUnAssTracks = 0; //number of tracks w/o clusters
         List<ReconstructedParticle> finalStateParticles = event.get(ReconstructedParticle.class, finalStateParticlesColName);
-        if (debug) {
+        if (debug)
             System.out.println("This events has " + finalStateParticles.size() + " final state particles");
-        }
         for (ReconstructedParticle fsPart : finalStateParticles) {
-            if (debug) {
+            if (debug)
                 System.out.println("PDGID = " + fsPart.getParticleIDUsed() + "; charge = " + fsPart.getCharge() + "; pz = " + fsPart.getMomentum().x());
-            }
 
             // Extrapolate the track to the Ecal cluster position
             boolean isPhoton = false;
@@ -99,17 +109,15 @@
             Cluster fsCluster = null;
             //TODO:  mg-May 14, 2014 use PID to do this instead...not sure if that's implemented yet
             if (fsPart.getTracks().size() == 1)//should always be 1 or zero for final state particles
-            {
+
                 fsTrack = fsPart.getTracks().get(0);
-            } else {
+            else
                 isPhoton = true;
-            }
             //get the cluster
-            if (fsPart.getClusters().size() == 1) {
+            if (fsPart.getClusters().size() == 1)
                 fsCluster = fsPart.getClusters().get(0);
-            } else {
+            else
                 hasCluster = false;
-            }
 
             //deal with electrons & positrons first
             if (!isPhoton) {
@@ -117,20 +125,20 @@
                 Hep3Vector mom = fsPart.getMomentum();
                 if (charge < 0) {
                     nTotEle++;
-                    aida.histogram1D(plotDir+"Electron Px (GeV)").fill(mom.x());
-                    aida.histogram1D(plotDir+"Electron Py (GeV)").fill(mom.y());
-                    aida.histogram1D(plotDir+"Electron Pz (GeV)").fill(mom.z());
+                    aida.histogram1D(plotDir + "Electron Px (GeV)").fill(mom.x());
+                    aida.histogram1D(plotDir + "Electron Py (GeV)").fill(mom.y());
+                    aida.histogram1D(plotDir + "Electron Pz (GeV)").fill(mom.z());
+                    aida.histogram1D(plotDir + "Beam Electrons Pz (GeV)").fill(mom.z());
                 } else {
                     nTotPos++;
-                    aida.histogram1D(plotDir+"Positron Px (GeV)").fill(mom.x());
-                    aida.histogram1D(plotDir+"Positron Py (GeV)").fill(mom.y());
-                    aida.histogram1D(plotDir+"Positron Pz (GeV)").fill(mom.z());
+                    aida.histogram1D(plotDir + "Positron Px (GeV)").fill(mom.x());
+                    aida.histogram1D(plotDir + "Positron Py (GeV)").fill(mom.y());
+                    aida.histogram1D(plotDir + "Positron Pz (GeV)").fill(mom.z());
                 }
 
             }
             //now, the photons
             if (isPhoton) {
-                System.out.println("what is the charge of this photon? "+fsPart.getCharge());
                 double ene = fsPart.getEnergy();
                 //TODO:  mg-May 14, 2014....I would like to do this!!!!
                 //double xpos = fsCluster.getPositionAtShowerMax(false)[0];// false-->assume a photon instead of electron from calculating shower depth
@@ -141,12 +149,12 @@
                 double ypos = clusterPosition.y();
                 nPhotons++;
                 nTotPhotons++;
-                aida.histogram1D(plotDir+"Photon Energy (GeV)").fill(ene);
-                aida.histogram1D(plotDir+"Photon X position (mm)").fill(xpos);
-                aida.histogram1D(plotDir+"Photon Y position (mm)").fill(ypos);
+                aida.histogram1D(plotDir + "Photon Energy (GeV)").fill(ene);
+                aida.histogram1D(plotDir + "Photon X position (mm)").fill(xpos);
+                aida.histogram1D(plotDir + "Photon Y position (mm)").fill(ypos);
             }
 
-            if (hasCluster && !isPhoton&&fsPart.getCharge()>0) {
+            if (hasCluster && !isPhoton) {
                 nTotAss++;
                 Hep3Vector mom = fsPart.getMomentum();
                 double ene = fsPart.getEnergy();
@@ -155,35 +163,38 @@
                 Hep3Vector trackPosAtEcal = TrackUtils.extrapolateTrack(fsTrack, clusterPosition.z());
                 double dx = trackPosAtEcal.x() - clusterPosition.x();//remember track vs detector coords
                 double dy = trackPosAtEcal.y() - clusterPosition.y();//remember track vs detector coords
-//                System.out.println(trackPosAtEcal.x()+";"+trackPosAtEcal.y()+";"+trackPosAtEcal.z());
+                System.out.println(trackPosAtEcal.x() + ";" + trackPosAtEcal.y() + ";" + trackPosAtEcal.z());
+                System.out.println(clusterPosition.x() + ";" + clusterPosition.y() + ";" + clusterPosition.z());
+
                 sumdelX += dx;
                 sumdelY += dy;
                 sumEoverP += eOverP;
 
-                aida.histogram1D(plotDir+"Cluster Energy Over TrackMomentum").fill(eOverP);
-                aida.histogram1D(plotDir+"delta X @ ECal (mm)").fill(dx);
-                aida.histogram1D(plotDir+"delta Y @ ECal (mm)").fill(dy);
+                aida.histogram1D(plotDir + "Cluster Energy Over TrackMomentum").fill(eOverP);
+                aida.histogram1D(plotDir + "delta X @ ECal (mm)").fill(dx);
+                aida.histogram1D(plotDir + "delta Y @ ECal (mm)").fill(dy);
+                /* here are some plots for debugging track-cluster matching */
+                // aida.histogram2D(plotDir + "track X vs ECal X").fill(trackPosAtEcal.x(), clusterPosition.x());
+                // aida.histogram2D(plotDir + "track Y vs ECal Y").fill(trackPosAtEcal.y(), clusterPosition.y());
+                aida.histogram2D(plotDir + "track mom vs ECal E").fill(fsPart.getMomentum().magnitude(), fsPart.getEnergy());
+                //          if(dy<-20)
+                //              System.out.println("Big deltaY...")
+
             }
             if (!hasCluster) {//if there is no cluster, can't be a track or else it wouldn't be in list
                 nUnAssTracks++; //count per event
                 nTotUnAss++; //and keep a running total for averaging
             }
         }
-        aida.histogram1D(plotDir+"Number of unassociated tracks per event").fill(nUnAssTracks);
-        aida.histogram1D(plotDir+"Number of photons per event").fill(nPhotons);
+        aida.histogram1D(plotDir + "Number of unassociated tracks per event").fill(nUnAssTracks);
+        aida.histogram1D(plotDir + "Number of photons per event").fill(nPhotons);
     }
 
     @Override
-    public void dumpDQMData() {
-        System.out.println("ReconMonitoring::endOfData filling DQM database");
-    }
-
-    @Override
     public void printDQMData() {
         System.out.println("FinalStateMonitoring::printDQMData");
-        for (Entry<String, Double> entry : monitoredQuantityMap.entrySet()) {
+        for (Entry<String, Double> entry : monitoredQuantityMap.entrySet())
             System.out.println(entry.getKey() + " = " + entry.getValue());
-        }
         System.out.println("*******************************");
     }
 
@@ -192,6 +203,17 @@
      */
     @Override
     public void calculateEndOfRunQuantities() {
+        IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+        IFitFactory fitFactory = analysisFactory.createFitFactory();
+        IFitter fitter = fitFactory.createFitter("chi2");
+        IHistogram1D beamE = aida.histogram1D(plotDir + "Beam Electrons Pz (GeV)");
+        IFitResult result = fitBeamEnergyPeak(beamE, fitter, "range=\"(-10.0,10.0)\"");
+
+        for (int i = 0; i < 5; i++) {
+            double par = result.fittedParameters()[i];
+            System.out.println("Beam Energy Peak:  " + result.fittedParameterNames()[i] + " = " + par);
+        }
+
         monitoredQuantityMap.put(fpQuantNames[0], (double) nTotEle / nRecoEvents);
         monitoredQuantityMap.put(fpQuantNames[1], (double) nTotPos / nRecoEvents);
         monitoredQuantityMap.put(fpQuantNames[2], (double) nTotPhotons / nRecoEvents);
@@ -199,13 +221,35 @@
         monitoredQuantityMap.put(fpQuantNames[4], (double) sumdelX / nTotAss);
         monitoredQuantityMap.put(fpQuantNames[5], (double) sumdelY / nTotAss);
         monitoredQuantityMap.put(fpQuantNames[6], (double) sumEoverP / nTotAss);
+
+        IPlotter plotter = analysisFactory.createPlotterFactory().create("Beam Energy Electrons");
+
+        IPlotterStyle pstyle = plotter.style();
+        pstyle.legendBoxStyle().setVisible(false);
+        pstyle.dataStyle().fillStyle().setColor("green");
+        pstyle.dataStyle().lineStyle().setColor("black");        
+        plotter.region(0).plot(beamE);              
+        plotter.region(0).plot(result.fittedFunction());
+        try {
+            plotter.writeToFile("beamEnergyElectrons.png");
+        } catch (IOException ex) {
+            Logger.getLogger(FinalStateMonitoring.class.getName()).log(Level.SEVERE, null, ex);
+        }
     }
 
     @Override
     public void printDQMStrings() {
-        for (int i = 0; i < 7; i++) {//TODO:  do this in a smarter way...loop over the map
-            System.out.println(fpQuantNames[i]);
-        }
+        for (int i = 0; i < 7; i++)//TODO:  do this in a smarter way...loop over the map
+            System.out.println("ALTER TABLE dqm ADD " + fpQuantNames[i] + " double;");
     }
 
+    IFitResult fitBeamEnergyPeak(IHistogram1D h1d, IFitter fitter, String range) {
+//        return fitter.fit(h1d, "g", range);
+   
+//        return fitter.fit(h1d, "g+p1", init, range);
+  double[] init = {20.0, 2.2, 0.12, 10, 0.0};
+//        double[] init = {20.0, 2.2, 0.1};
+        return fitter.fit(h1d, "g+p1", init);
+    }
+
 }

java/trunk/analysis/src/main/java/org/hps/analysis/dataquality
SVTHitMCEfficiency.java 695 -> 696
--- java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/SVTHitMCEfficiency.java	2014-06-10 12:34:34 UTC (rev 695)
+++ java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/SVTHitMCEfficiency.java	2014-06-10 14:56:41 UTC (rev 696)
@@ -184,7 +184,7 @@
     @Override
     public void printDQMStrings() {
         for (SiSensor sensor : sensors)
-            System.out.println(avgClusterEffNames.get(sensor.getName()));
+            System.out.println("ALTER TABLE dqm ADD "+avgClusterEffNames.get(sensor.getName())+" double;");
     }
 
 }

java/trunk/analysis/src/main/java/org/hps/analysis/dataquality
SvtMonitoring.java 695 -> 696
--- java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/SvtMonitoring.java	2014-06-10 12:34:34 UTC (rev 695)
+++ java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/SvtMonitoring.java	2014-06-10 14:56:41 UTC (rev 696)
@@ -1,20 +1,32 @@
 package org.hps.analysis.dataquality;
 
+import hep.aida.IAnalysisFactory;
+import hep.aida.IFitFactory;
+import hep.aida.IFitResult;
+import hep.aida.IFitter;
 import hep.aida.IHistogram1D;
 import hep.aida.IPlotter;
-import org.lcsim.geometry.Detector;
+import hep.aida.IPlotterStyle;
+import java.io.IOException;
+import java.sql.SQLException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.hps.conditions.deprecated.SvtUtils;
 import org.hps.recon.tracking.FittedRawTrackerHit;
 import org.lcsim.detector.tracker.silicon.SiSensor;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
 
 /**
- *  DQM driver for the monte carlo for reconstructed track quantities
- *  plots things like occupancy, t0, amplitude, chi^2 (from APV25 sampling fit); each on a per/sensor basis
- * saves to DQM database:  <occupancy> 
+ * DQM driver for the monte carlo for reconstructed track quantities
+ * plots things like occupancy, t0, amplitude, chi^2 (from APV25 sampling fit);
+ * each on a per/sensor basis
+ * saves to DQM database: <occupancy>
+ *
  * @author mgraham on Mar 28, 2014
  */
 //TODO:  add some more quantities to DQM database:  <t0> or <sigma>_t0 for intime events;  <chi^2>, <amplitude> etc
@@ -30,12 +42,16 @@
     private Map<String, int[]> occupancyMap;
     private Map<String, Double> avgOccupancyMap;
     private Map<String, String> avgOccupancyNames;
+    private Map<String, Double> avgt0Map;
+    private Map<String, Double> sigt0Map;
+    private Map<String, String> avgt0Names;
+    private Map<String, String> sigt0Names;
     private int eventCountRaw = 0;
     private int eventCountFit = 0;
     private int eventCountCluster = 0;
     private static final String nameStrip = "Tracker_TestRunModule_";
     private static final int maxChannels = 640;
-    private String plotDir="SvtMonitoring/";
+    private String plotDir = "SvtMonitoring/";
 
     public void setRawTrackerHitCollectionName(String inputCollection) {
         this.rawTrackerHitCollectionName = inputCollection;
@@ -53,21 +69,21 @@
         System.out.println("SvtMonitoring::detectorChanged  Setting up the plotter");
         this.detector = detector;
         aida.tree().cd("/");
-      
+
         // Make a list of SiSensors in the SVT.
         sensors = this.detector.getSubdetector(trackerName).getDetectorElement().findDescendants(SiSensor.class);
 
         // Reset the data structure that keeps track of strip occupancies.
         resetOccupancyMap();
-     
+
         // Setup the occupancy plots.
         aida.tree().cd("/");
         for (SiSensor sensor : sensors) {
             //IHistogram1D occupancyPlot = aida.histogram1D(sensor.getName().replaceAll("Tracker_TestRunModule_", ""), 640, 0, 639);
-            IHistogram1D occupancyPlot = createSensorPlot(plotDir+"occupancy_",sensor, maxChannels, 0, maxChannels - 1);
-            IHistogram1D t0Plot = createSensorPlot(plotDir+"t0_",sensor,50,-50.,50.);
-            IHistogram1D amplitudePlot = createSensorPlot(plotDir+"amplitude_",sensor,50,0,2000);
-            IHistogram1D chi2Plot = createSensorPlot(plotDir+"chi2_",sensor,50,0,25);
+            IHistogram1D occupancyPlot = createSensorPlot(plotDir + "occupancy_", sensor, maxChannels, 0, maxChannels - 1);
+            IHistogram1D t0Plot = createSensorPlot(plotDir + "t0_", sensor, 50, -50., 50.);
+            IHistogram1D amplitudePlot = createSensorPlot(plotDir + "amplitude_", sensor, 50, 0, 2000);
+            IHistogram1D chi2Plot = createSensorPlot(plotDir + "chi2_", sensor, 50, 0, 25);
             occupancyPlot.reset();
         }
 
@@ -88,32 +104,33 @@
         } else
             return; /* kick out of this if the even has none of these...*/
         /*  fill the FittedTrackerHit related histograms */
-        if (event.hasCollection(FittedRawTrackerHit.class, fittedTrackerHitCollectionName)){
-             List<FittedRawTrackerHit> fittedTrackerHits = event.get(FittedRawTrackerHit.class, fittedTrackerHitCollectionName);
-             for(FittedRawTrackerHit hit: fittedTrackerHits){
-                 String sensorName= hit.getRawTrackerHit().getDetectorElement().getName();
-                 double t0=hit.getT0();
-                 double amp=hit.getAmp();
-                 double chi2=hit.getShapeFitParameters().getChiSq();
-                 getSensorPlot(plotDir+"t0_",sensorName).fill(t0);
-                 getSensorPlot(plotDir+"amplitude_",sensorName).fill(amp);  
-                  getSensorPlot(plotDir+"chi2_",sensorName).fill(chi2); 
-             }
-             ++eventCountFit;
+
+        if (event.hasCollection(FittedRawTrackerHit.class, fittedTrackerHitCollectionName)) {
+            List<FittedRawTrackerHit> fittedTrackerHits = event.get(FittedRawTrackerHit.class, fittedTrackerHitCollectionName);
+            for (FittedRawTrackerHit hit : fittedTrackerHits) {
+                String sensorName = hit.getRawTrackerHit().getDetectorElement().getName();
+                double t0 = hit.getT0();
+                double amp = hit.getAmp();
+                double chi2 = hit.getShapeFitParameters().getChiSq();
+                getSensorPlot(plotDir + "t0_", sensorName).fill(t0);
+                getSensorPlot(plotDir + "amplitude_", sensorName).fill(amp);
+                getSensorPlot(plotDir + "chi2_", sensorName).fill(chi2);
+            }
+            ++eventCountFit;
         } else
             return;
     }
 
-    private IHistogram1D getSensorPlot( String prefix, SiSensor sensor) {
-        return aida.histogram1D(prefix+sensor.getName());
+    private IHistogram1D getSensorPlot(String prefix, SiSensor sensor) {
+        return aida.histogram1D(prefix + sensor.getName());
     }
-    
-      private IHistogram1D getSensorPlot( String prefix, String sensorName) {
-        return aida.histogram1D(prefix+sensorName);
+
+    private IHistogram1D getSensorPlot(String prefix, String sensorName) {
+        return aida.histogram1D(prefix + sensorName);
     }
 
-    private IHistogram1D createSensorPlot( String prefix,SiSensor sensor, int nchan, double min, double max) {
-        IHistogram1D hist = aida.histogram1D(prefix+sensor.getName(),nchan,min,max);
+    private IHistogram1D createSensorPlot(String prefix, SiSensor sensor, int nchan, double min, double max) {
+        IHistogram1D hist = aida.histogram1D(prefix + sensor.getName(), nchan, min, max);
         hist.setTitle(sensor.getName().replaceAll(nameStrip, "")
                 .replace("module", "mod")
                 .replace("layer", "lyr")
@@ -125,11 +142,20 @@
         occupancyMap = new HashMap<>();
         avgOccupancyMap = new HashMap<>();
         avgOccupancyNames = new HashMap<>();
+        avgt0Names = new HashMap<>();
+        sigt0Names = new HashMap<>();
+        avgt0Map = new HashMap<>();
+        sigt0Map = new HashMap<>();
         for (SiSensor sensor : sensors) {
             occupancyMap.put(sensor.getName(), new int[640]);
             avgOccupancyMap.put(sensor.getName(), -999.);
             String occName = "avgOcc_" + getNiceSensorName(sensor);
             avgOccupancyNames.put(sensor.getName(), occName);
+            String avgt0Name = "avgt0_" + getNiceSensorName(sensor);
+            String sigt0Name = "sigmat0_" + getNiceSensorName(sensor);
+
+            avgt0Names.put(sensor.getName(), avgt0Name);
+            sigt0Names.put(sensor.getName(), sigt0Name);
         }
     }
 
@@ -154,7 +180,7 @@
         for (SiSensor sensor : sensors) {
             Double avg = 0.0;
             //IHistogram1D sensorHist = aida.histogram1D(sensor.getName());
-            IHistogram1D sensorHist = getSensorPlot(plotDir+"occupancy_",sensor);
+            IHistogram1D sensorHist = getSensorPlot(plotDir + "occupancy_", sensor);
             sensorHist.reset();
             int[] strips = occupancyMap.get(sensor.getName());
             for (int i = 0; i < strips.length; i++) {
@@ -163,31 +189,119 @@
                     sensorHist.fill(i, stripOccupancy);
                 avg += stripOccupancy;
             }
-        //do the end-of-run quantities here too since we've already done the loop.  
-            avg /= strips.length;        
+            //do the end-of-run quantities here too since we've already done the loop.  
+            avg /= strips.length;
             avgOccupancyMap.put(sensor.getName(), avg);
         }
+
     }
 
     @Override
+    public void calculateEndOfRunQuantities() {
+        IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+        IFitFactory fitFactory = analysisFactory.createFitFactory();
+        IFitter fitter = fitFactory.createFitter("chi2");
+        IPlotter plotterTop = analysisFactory.createPlotterFactory().create("t0 Top");
+        IPlotter plotterBottom = analysisFactory.createPlotterFactory().create("t0 Bottom");
+
+        plotterTop.createRegions(4, 5);
+        IPlotterStyle pstyle = plotterTop.style();
+        pstyle.legendBoxStyle().setVisible(false);
+        plotterBottom.createRegions(4, 5);
+        IPlotterStyle pstyle2 = plotterBottom.style();
+        pstyle2.legendBoxStyle().setVisible(false);
+
+        int irTop = 0;
+        int irBot = 0;
+        for (SiSensor sensor : sensors) {
+            IHistogram1D sensPlot = getSensorPlot(plotDir + "t0_", sensor);
+            IFitResult result = fitGaussian(sensPlot, fitter, "range=\"(-10.0,10.0)\"");
+            for (int i = 0; i < 5; i++) {
+                double par = result.fittedParameters()[i];
+                System.out.println("t0_" + sensor.getName() + ":  " + result.fittedParameterNames()[i] + " = " + par);
+            }
+
+            boolean isTop = SvtUtils.getInstance().isTopLayer(sensor);
+
+            if (isTop) {
+                System.out.println("Plotting into Top region " + irTop);
+                plotterTop.region(irTop).plot(sensPlot);
+                plotterTop.region(irTop).plot(result.fittedFunction());
+                irTop++;
+            } else {
+                System.out.println("Plotting into Bottom region " + irBot);
+                plotterBottom.region(irBot).plot(sensPlot);
+                plotterBottom.region(irBot).plot(result.fittedFunction());
+                irBot++;
+            }
+            avgt0Map.put(sensor.getName(), result.fittedParameters()[1]);
+            sigt0Map.put(sensor.getName(), result.fittedParameters()[2]);
+        }
+        try {
+            plotterTop.writeToFile("t0TopPlots.png");
+        } catch (IOException ex) {
+            Logger.getLogger(SvtMonitoring.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        try {
+            plotterBottom.writeToFile("t0BottomPlots.png");
+        } catch (IOException ex) {
+            Logger.getLogger(SvtMonitoring.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+
+    @Override
     public void dumpDQMData() {
-        System.out.println("SvtMonitoring::endOfData filling DQM database");
-        double s1occ = 0.99;
-        String put = "update dqm SET avgOcc_T1=" + s1occ + " WHERE " + getRunRecoString();
-//        manager.updateQuery(put);        
+        for (SiSensor sensor : sensors) {
+            String name = avgOccupancyNames.get(sensor.getName());
+            double occ = avgOccupancyMap.get(sensor.getName());
+            checkAndUpdate(name, occ);
+            String avgt0Name = avgt0Names.get(sensor.getName());
+            double avgt0 = avgt0Map.get(sensor.getName());
+            checkAndUpdate(avgt0Name, avgt0);
+            String sigt0Name = sigt0Names.get(sensor.getName());
+            double sigt0 = sigt0Map.get(sensor.getName());
+            checkAndUpdate(sigt0Name, sigt0);
+        }
     }
 
     @Override
     public void printDQMData() {
         for (SiSensor sensor : sensors) {
             System.out.println(avgOccupancyNames.get(sensor.getName()) + ":  " + avgOccupancyMap.get(sensor.getName()));
+            System.out.println(avgt0Names.get(sensor.getName()) + ":  " + avgt0Map.get(sensor.getName()));
+            System.out.println(sigt0Names.get(sensor.getName()) + ":  " + sigt0Map.get(sensor.getName()));
         }
     }
-      
-      @Override
+
+    @Override
     public void printDQMStrings() {
         for (SiSensor sensor : sensors) {
-            System.out.println(avgOccupancyNames.get(sensor.getName()));
+            System.out.println("ALTER TABLE dqm ADD " + avgOccupancyNames.get(sensor.getName()) + " double;");
+            System.out.println("ALTER TABLE dqm ADD " + avgt0Names.get(sensor.getName()) + " double;");
+            System.out.println("ALTER TABLE dqm ADD " + sigt0Names.get(sensor.getName()) + " double;");
         }
     }
+
+    IFitResult fitGaussian(IHistogram1D h1d, IFitter fitter, String range) {
+//        return fitter.fit(h1d, "g", range);
+        double[] init = {20.0, 0.0, 4.0, 20, -1};
+        return fitter.fit(h1d, "g+p1", init, range);
+
+    }
+
+    void checkAndUpdate(String name, double val) {
+        boolean isnull = false;
+        try {
+            isnull = checkSelectionIsNULL(name);
+        } catch (SQLException ex) {
+            Logger.getLogger(SvtMonitoring.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        if (!overwriteDB && !isnull) {
+            System.out.println("Not writing because " + name + " is already filled for this entry");
+            return; //entry exists and I don't want to overwrite                
+        }
+        String put = "update dqm SET " + name + " = " + val + " WHERE " + getRunRecoString();
+        System.out.println(put);
+        manager.updateQuery(put);
+    }
 }

java/trunk/analysis/src/main/java/org/hps/analysis/dataquality
TrackingMonitoring.java 695 -> 696
--- java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/TrackingMonitoring.java	2014-06-10 12:34:34 UTC (rev 695)
+++ java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/TrackingMonitoring.java	2014-06-10 14:56:41 UTC (rev 696)
@@ -43,7 +43,6 @@
     double sumslope = 0;
     double sumchisq = 0;
      private String plotDir = "Tracks/";
-    private Map<String, Double> monitoredQuantityMap = new HashMap<>();
     String[] trackingQuantNames = {"avg_N_tracks", "avg_N_hitsPerTrack", "avg_d0", "avg_z0", "avg_absslope", "avg_chi2"};
 
     public void setHelicalTrackHitCollectionName(String helicalTrackHitCollectionName) {
@@ -134,9 +133,6 @@
         monitoredQuantityMap.put(trackingQuantNames[5], sumchisq / nTotTracks);
     }
 
-    @Override
-    public void dumpDQMData() {
-    }
 
     @Override
     public void printDQMData() {
@@ -149,7 +145,7 @@
     @Override
     public void printDQMStrings() {
          for (Map.Entry<String, Double> entry : monitoredQuantityMap.entrySet())
-            System.out.println(entry.getKey());
+            System.out.println("ALTER TABLE dqm ADD "+entry.getKey()+" double;");
 
     }
 

java/trunk/analysis/src/main/java/org/hps/analysis/dataquality
V0Monitoring.java 695 -> 696
--- java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/V0Monitoring.java	2014-06-10 12:34:34 UTC (rev 695)
+++ java/trunk/analysis/src/main/java/org/hps/analysis/dataquality/V0Monitoring.java	2014-06-10 14:56:41 UTC (rev 696)
@@ -1,24 +1,30 @@
 package org.hps.analysis.dataquality;
 
+import hep.aida.IAnalysisFactory;
+import hep.aida.IFitFactory;
+import hep.aida.IFitResult;
+import hep.aida.IFitter;
 import hep.aida.IHistogram1D;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterStyle;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.ReconstructedParticle;
 import org.lcsim.event.Vertex;
 import org.lcsim.geometry.Detector;
 
 /**
- * DQM driver reconstructed particles (i.e. electrons, positrons, photons) plots
- * things like number of electrons (or positrons)/event, photons/event, e+/e-
- * momentum, and track-cluster matching stuff
+ * DQM driver V0 particles (i.e. e+e- pars) plots
+ * things like number of vertex position an mass
  *
- * @author mgraham on Mar 28, 2014 big update on May 14, 2014...right now the
- * output is crap; no charge<0 tracks & the track momentum isn't filled; likely
- * a problem with ReconParticle TODO: may want to break out the V0 DQM (not
- * written) into it's own class
+ * @author mgraham  on May 14, 2014
+
  */
 public class V0Monitoring extends DataQualityMonitor {
 
@@ -26,19 +32,17 @@
     String unconstrainedV0CandidatesColName = "UnconstrainedV0Candidates";
     String beamConV0CandidatesColName = "BeamspotConstrainedV0Candidates";
     String targetV0ConCandidatesColName = "TargetConstrainedV0Candidates";
-    private Map<String, Double> monitoredQuantityMap = new HashMap<>();
-    String[] fpQuantNames = {"nEle_per_Event", "nPos_per_Event", "nPhoton_per_Event", "nUnAssociatedTracks_per_Event", "avg_delX_at_ECal", "avg_delY_at_ECal", "avg_E_Over_P"};
+    String[] fpQuantNames = {"nV0_per_Event", "avg_BSCon_mass", "avg_BSCon_Vx", "avg_BSCon_Vy", "avg_BSCon_Vz", "avg_BSCon_Chi2"};
     //some counters
     int nRecoEvents = 0;
-    int nTotEle = 0;
-    int nTotPos = 0;
-    int nTotPhotons = 0;
-    int nTotUnAss = 0;
-    int nTotAss = 0;
+    int nTotV0 = 0;
     //some summers
-    double sumdelX = 0.0;
-    double sumdelY = 0.0;
-    double sumEoverP = 0.0;
+    double sumMass = 0.0;
+    double sumVx = 0.0;
+    double sumVy = 0.0;
+    double sumVz = 0.0;
+    double sumChi2 = 0.0;
+
     boolean debug = false;
     private String plotDir = "V0Monitoring/";
 
@@ -50,6 +54,7 @@
         /*  V0 Quantities   */
         /*  Mass, vertex, chi^2 of fit */
         /* beamspot constrained */
+        IHistogram1D nV0 = aida.histogram1D(plotDir + "Number of V0 per event", 10, 0, 10);
         IHistogram1D bsconMass = aida.histogram1D(plotDir + "BS Constrained Mass (GeV)", 100, 0, 0.200);
         IHistogram1D bsconVx = aida.histogram1D(plotDir + "BS Constrained Vx (mm)", 50, -1, 1);
         IHistogram1D bsconVy = aida.histogram1D(plotDir + "BS Constrained Vy (mm)", 50, -1, 1);
@@ -78,35 +83,37 @@
         nRecoEvents++;
 
         List<ReconstructedParticle> beamConstrainedV0List = event.get(ReconstructedParticle.class, beamConV0CandidatesColName);
+        aida.histogram1D(plotDir + "Number of V0 per event").fill(beamConstrainedV0List.size());
         for (ReconstructedParticle bsV0 : beamConstrainedV0List) {
+            nTotV0++;
             Vertex bsVert = bsV0.getStartVertex();
             aida.histogram1D(plotDir + "BS Constrained Vx (mm)").fill(bsVert.getPosition().x());
             aida.histogram1D(plotDir + "BS Constrained Vy (mm)").fill(bsVert.getPosition().y());
             aida.histogram1D(plotDir + "BS Constrained Vz (mm)").fill(bsVert.getPosition().z());
             aida.histogram1D(plotDir + "BS Constrained Mass (GeV)").fill(bsV0.getMass());
-            aida.histogram1D(plotDir + "BS Constrained Chi2").fill(bsVert.getChi2());            
+            aida.histogram1D(plotDir + "BS Constrained Chi2").fill(bsVert.getChi2());
+            sumMass += bsV0.getMass();
+            sumVx += bsVert.getPosition().x();
+            sumVy += bsVert.getPosition().y();
+            sumVz += bsVert.getPosition().z();
+            sumChi2 += bsVert.getChi2();
         }
-        
-          List<ReconstructedParticle> targetConstrainedV0List = event.get(ReconstructedParticle.class, targetV0ConCandidatesColName);
-          System.out.println("Number of V0s = " + targetConstrainedV0List.size());
-          for (ReconstructedParticle tarV0 : targetConstrainedV0List) {
+
+        List<ReconstructedParticle> targetConstrainedV0List = event.get(ReconstructedParticle.class, targetV0ConCandidatesColName);
+//        System.out.println("Number of V0s = " + targetConstrainedV0List.size());
+        for (ReconstructedParticle tarV0 : targetConstrainedV0List) {
             Vertex tarVert = tarV0.getStartVertex();
-            System.out.println(tarVert.toString());
+//            System.out.println(tarVert.toString());
             aida.histogram1D(plotDir + "Target Constrained Vx (mm)").fill(tarVert.getPosition().x());
             aida.histogram1D(plotDir + "Target Constrained Vy (mm)").fill(tarVert.getPosition().y());
             aida.histogram1D(plotDir + "Target Constrained Vz (mm)").fill(tarVert.getPosition().z());
             aida.histogram1D(plotDir + "Target Constrained Mass (GeV)").fill(tarV0.getMass());
-            aida.histogram1D(plotDir + "Target Constrained Chi2").fill(tarVert.getChi2());            
-            System.out.println("Target Constrained chi^2 = "+tarVert.getChi2());
+            aida.histogram1D(plotDir + "Target Constrained Chi2").fill(tarVert.getChi2());
+            //           System.out.println("Target Constrained chi^2 = " + tarVert.getChi2());
         }
     }
 
     @Override
-    public void dumpDQMData() {
-        System.out.println("ReconMonitoring::endOfData filling DQM database");
-    }
-
-    @Override
     public void printDQMData() {
         System.out.println("V0Monitoring::printDQMData");
         for (Entry<String, Double> entry : monitoredQuantityMap.entrySet())
@@ -119,19 +126,61 @@
      */
     @Override
     public void calculateEndOfRunQuantities() {
-        monitoredQuantityMap.put(fpQuantNames[0], (double) nTotEle / nRecoEvents);
-        monitoredQuantityMap.put(fpQuantNames[1], (double) nTotPos / nRecoEvents);
-        monitoredQuantityMap.put(fpQuantNames[2], (double) nTotPhotons / nRecoEvents);
-        monitoredQuantityMap.put(fpQuantNames[3], (double) nTotUnAss / nRecoEvents);
-        monitoredQuantityMap.put(fpQuantNames[4], (double) sumdelX / nTotAss);
-        monitoredQuantityMap.put(fpQuantNames[5], (double) sumdelY / nTotAss);
-        monitoredQuantityMap.put(fpQuantNames[6], (double) sumEoverP / nTotAss);
+        monitoredQuantityMap.put(fpQuantNames[0], (double) nTotV0 / nRecoEvents);
+        monitoredQuantityMap.put(fpQuantNames[1], sumMass / nTotV0);
+        monitoredQuantityMap.put(fpQuantNames[2], sumVx / nTotV0);
+        monitoredQuantityMap.put(fpQuantNames[3], sumVy / nTotV0);
+        monitoredQuantityMap.put(fpQuantNames[4], sumVz / nTotV0);
+        monitoredQuantityMap.put(fpQuantNames[5], sumChi2 / nTotV0);
+
+        IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+        IFitFactory fitFactory = analysisFactory.createFitFactory();
+        IFitter fitter = fitFactory.createFitter("chi2");
+        IHistogram1D bsconVx = aida.histogram1D(plotDir + "BS Constrained Vx (mm)");
+        IHistogram1D bsconVy = aida.histogram1D(plotDir + "BS Constrained Vy (mm)");
+        IHistogram1D bsconVz = aida.histogram1D(plotDir + "BS Constrained Vz (mm)");
+        double[] init = {50.0, 0.0, 0.2, 1.0, 0.0};
+        IFitResult resVx = fitVertexPosition(bsconVx, fitter, init, "range=\"(-0.5,0.5)\"");
+        double[] init2 = {50.0, 0.0, 0.04, 1.0, 0.0};
+        IFitResult resVy = fitVertexPosition(bsconVy, fitter, init2, "range=\"(-0.2,0.2)\"");
+        double[] init3 = {50.0, 0.0, 3.0, 1.0, 0.0};
+        IFitResult resVz = fitVertexPosition(bsconVz, fitter, init3, "range=\"(-6,6)\"");
+
+        for (int i = 0; i < 5; i++) {
+            double parVx = resVx.fittedParameters()[i];
+            double parVy = resVy.fittedParameters()[i];
+            double parVz = resVz.fittedParameters()[i];
+            System.out.println("Vertex Fit Parameters:  " + resVx.fittedParameterNames()[i] + " = " + parVx + "; " + parVy + "; " + parVz);
+        }
+
+        IPlotter plotter = analysisFactory.createPlotterFactory().create("Vertex Position");
+        plotter.createRegions(1, 3);
+        IPlotterStyle pstyle = plotter.style();
+        pstyle.legendBoxStyle().setVisible(false);
+        pstyle.dataStyle().fillStyle().setColor("green");
+        pstyle.dataStyle().lineStyle().setColor("black");
+        plotter.region(0).plot(bsconVx);
+        plotter.region(0).plot(resVx.fittedFunction());
+        plotter.region(1).plot(bsconVy);
+        plotter.region(1).plot(resVy.fittedFunction());
+        plotter.region(2).plot(bsconVz);
+        plotter.region(2).plot(resVz.fittedFunction());
+        try {
+            plotter.writeToFile("vertex.png");
+        } catch (IOException ex) {
+            Logger.getLogger(V0Monitoring.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
     }
 
     @Override
     public void printDQMStrings() {
         for (int i = 0; i < 7; i++)//TODO:  do this in a smarter way...loop over the map
-            System.out.println(fpQuantNames[i]);
+            System.out.println("ALTER TABLE dqm ADD " + fpQuantNames[i] + " double;");
     }
 
+    IFitResult fitVertexPosition(IHistogram1D h1d, IFitter fitter, double[] init, String range) {
+        return fitter.fit(h1d, "g+p1", init, range);
+    }
+
 }
SVNspam 0.1