Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

JetWebAIDAXMLPlotReader.java

Go to the documentation of this file.
00001 package cedar.jetweb.xml;
00002 
00008 import java.util.Vector;
00009 import cedar.jetweb.model.plots.DataPoint;
00010 import cedar.jetweb.model.plots.DataPlot;
00011 import cedar.jetweb.model.plots.PredictedPlot;
00012 import cedar.jetweb.JetWebException;
00013 import hep.aida.*;
00014 import hep.aida.ref.plotter.PlotterUtilities;
00015 
00016 public class JetWebAIDAXMLPlotReader implements JetWebPlotReader {
00017     IDataPointSet m_data_ = null;
00018     ITree tree_ = null;
00019     String directory_ = "";
00020     IDataPointSetFactory dpsf_ = null;
00021     IHistogram1D hist_ = null;
00022 
00024     public JetWebAIDAXMLPlotReader(String filename) throws JetWebXMLException{
00025        
00026         //filename is an absolute path apparently
00027         try{
00028             IAnalysisFactory af = IAnalysisFactory.create();
00029             
00030             tree_ = af.createTreeFactory().create(filename,"xml",false,false);
00031             dpsf_ = af.createDataPointSetFactory(tree_);
00032 
00033         /*
00034      * This needs to reflect the directory structure of the tree created with the 
00035      * datapoints. Dont think the JAIDA xml stores this info so work needs to be done
00036 
00037         m_data = dpsf.create("/data","",2);
00038      */
00039         }catch (Exception e) {
00040             throw new JetWebXMLException(e);
00041         }
00042     }
00043     
00044     private Vector<DataPoint> getDataPoints() {
00045             
00046     Vector<DataPoint> dps = new Vector();
00047 
00048     /*
00049     int size = m_data_.size();
00050 
00051         
00052     for(int i=0;i<size;i++) {
00053         IDataPoint p = m_data_.point(i);
00054         double x = p.coordinate(0).value();
00055         double y = p.coordinate(1).value();
00056         double xerrup = p.coordinate(0).errorPlus();
00057         double xerrdown = p.coordinate(0).errorMinus();
00058         double yerrup = p.coordinate(1).errorPlus();
00059         double yerrdown = p.coordinate(1).errorMinus();
00060 
00061         System.out.println("x "+x+" xerr "+xerrup);
00062         System.out.println("y "+x+" yerr "+yerrup);
00063         
00064         DataPoint dp = new DataPoint();
00065         dp.setX(x);
00066         dp.setY(y);
00067         dp.setYUp(yerrup);
00068         dp.setYDown(yerrdown);
00069         dp.setBinWidth(1.0);
00070         dp.setChi2(0.0);
00071         dps.add(dp);
00072 
00073     }
00074     */
00075 
00076     IAxis axis = hist_.axis();
00077     for (int iBin=0 ; iBin<axis.bins(); iBin++){
00078 
00079         DataPoint dp = new DataPoint();
00080         dp.setX( (axis.binUpperEdge(iBin)+axis.binLowerEdge(iBin))/2.0 );
00081         dp.setY(hist_.binHeight(iBin + 1 ));//iBin));
00082         dp.setYUp(hist_.binError(iBin+1));
00083         dp.setYDown(hist_.binError(iBin+1));
00084         dp.setBinWidth(axis.binWidth(iBin));
00085         dp.setChi2(0.0);
00086 
00087         //System.out.println("adding data point: " + dp);
00088 
00089         dps.add(dp);
00090     }
00091         
00092     return dps;
00093     }
00094     
00095     public void setDirectory(String dir) throws JetWebException {
00096     directory_ = dir;
00097     }
00098 
00099     public void fillPlot(DataPlot plot) throws JetWebException {
00100     //set the title - already set by plotfactory
00101     //set xlabel - same
00102     //set ylabel -same
00103     
00104     try {
00105 
00106         String location = directory_ + "/h" + plot.getNumber();
00107 
00108         System.out.println("using histogram at " + location);
00109 
00110         hist_ = (IHistogram1D) tree_.find(directory_+"/h"+plot.getNumber());
00111                
00112         // Create IDataPointSets from the the above AIDA objects.
00113         m_data_   = dpsf_.create("histogram",hist_);
00114         
00115         plot.setDataPoints(getDataPoints());
00116         
00117         if(plot instanceof PredictedPlot) {
00118         PredictedPlot.adjustErrors((PredictedPlot)plot);
00119         }
00120 
00121         plot.setHasData(true);
00122 
00123     } catch (IllegalArgumentException e) {
00124         System.out.println("JetWebAIDAPlotReader: couldnt find "+directory_+"/h"+plot.getNumber());
00125         throw new JetWebException(e,
00126                       "JetWebAIDAPlotReader: couldnt find "
00127                       +directory_+"/h"+plot.getNumber());
00128     }
00129 
00130 
00131     }
00132 }

Generated Wed Jan 17 09:14:27 GMT 2007