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

JetWebHist.java

Go to the documentation of this file.
00001 package cedar.jetweb.hist;
00002 
00003 import hep.aida.*;
00004 import hep.aida.ref.plotter.PlotterUtilities;
00005 
00006 import java.io.PrintWriter;
00007 import java.io.FileWriter;
00008 import java.io.File;
00009 import java.io.FileOutputStream;
00010 import java.io.BufferedOutputStream;
00011 import java.io.OutputStream;
00012 import java.io.BufferedWriter;
00013 import java.io.FileNotFoundException;
00014 import java.io.IOException;
00015 
00016 import java.util.Enumeration;
00017 import java.util.Iterator;
00018 import java.util.Vector;
00019 import java.util.Properties;
00020 
00021 import java.awt.Dimension;
00022 import java.awt.Image;
00023 import java.awt.Graphics;
00024 import java.awt.image.ImageProducer;
00025 import java.awt.Color;
00026 
00027 //import javax.swing.JComponent;
00028 //import javax.swing.JFrame;
00029 //import javax.swing.SwingUtilities;
00030 
00031 import cedar.jetweb.JetWebConfig;
00032 import cedar.jetweb.model.paper.Paper;
00033 import cedar.jetweb.model.plots.DataPlot;
00034 import cedar.jetweb.model.plots.DataPoint;
00035 import cedar.jetweb.model.plots.FittedPlot;
00036 import cedar.jetweb.model.plots.PredictedPlot;
00037 
00038 //import org.apache.commons.io.FileUtils;
00039 
00044 public abstract class JetWebHist {
00045     
00050     public static void writeGraphics(Paper paper, String path){
00051 
00052     String plotPath = path+"/"+paper.getDirName();
00053 
00054         for (DataPlot plot : paper.getPlots()){
00055             writeGraphics(plot,plotPath);
00056         }
00057     }
00058     
00063     protected static IDataPointSet buildHist(DataPlot thisPlot, String path, String title){
00064         
00065         IDataPointSet data = null;
00066         try{
00067             System.setProperty("java.awt.headless", "true");
00068             IAnalysisFactory af = IAnalysisFactory.create();
00069             ITree tree = null;
00070             if(path!=null) {
00071                 tree = af.createTreeFactory().create(path+"/plot"+thisPlot.getNumber()+".xml",
00072                              "xml",false,true);
00073                 System.out.println("allow me to write you some XML :)");
00074                 
00075             }else{
00076                 tree = af.createTreeFactory().create();
00077             }
00078             
00079             IDataPointSetFactory dpsf = af.createDataPointSetFactory(tree);
00080             
00081           
00082             
00083             if(thisPlot.getNDataSources()==1) {
00084                 //System.out.println("HERE!");
00085                 Vector<DataPoint> points = thisPlot.getDataPoints();
00086                 
00087                 //data = dpsf.create(thisPlot.getTitle(),thisPlot.getTitle(),2);     //sort this out
00088                 //data = dpsf.create("/data",thisPlot.getTitle(),2);
00089                 data = dpsf.create("/data",title,2);
00090                 
00091                 for(int i=0;i<points.size();i++) {
00092                     
00093                     DataPoint p = points.elementAt(i);
00094                     data.addPoint();
00095                     data.point(i).coordinate(0).setValue(p.getX());
00096                     data.point(i).coordinate(1).setValue(p.getY()*thisPlot.getSysScale());
00097                     data.point(i).coordinate(1).setErrorPlus(p.getYUp()*thisPlot.getSysScale());
00098                     data.point(i).coordinate(1).setErrorMinus(p.getYDown()*thisPlot.getSysScale());
00099                     
00100                     
00101                 }
00102                 
00103                 
00104             }else{
00105                 System.out.println("SHOULDNT BE HERE");
00106             }
00107             
00108             if(path!=null) {
00109                 tree.commit();
00110             }
00111             
00112         }catch(Exception e) {
00113             e.printStackTrace();
00114         }
00115         
00116         return data;
00117     }
00118     
00124     public static void writeGraphics(DataPlot plot, String path) {
00125         try{
00126 
00127         File plotDir = new File(path);
00128         //System.out.println("I am checking "+path);
00129         if (!plotDir.exists()){
00130         try {
00131             //FileUtils.forceMkdir(plotDir);
00132             plotDir.mkdirs();
00133         } catch (Exception io) {
00134             System.out.println("JetWebHist: failed to make "+plotDir);
00135             return;
00136         }       
00137         }
00138 
00139 
00140             IAnalysisFactory af = IAnalysisFactory.create();
00141             IPlotterFactory pf = af.createPlotterFactory();
00142             IPlotter page1 = pf.create("page1");
00143         page1.setParameter("plotterWidth","200");
00144         page1.setParameter("plotterHeight","200");
00145 
00146             
00147         IDataPointSet histMC=null;
00148         IDataPointSet histReal=null;
00149             page1.createRegions(1,1);
00150             
00151         DataPlot comparisonPlot = null;
00152 
00153         //page1.region(0).style().dataStyle().markerStyle().setColor("black");
00154         //page1.region(0).style().dataStyle().markerStyle().setShape("circle");
00155 
00156         page1.region(0).style().setParameter("showStatisticsBox","false");
00157         page1.region(0).setTitle(plot.getTitle());
00158         //      page1.region(0).style().setParameter("showTitle","false");
00159 
00160 
00161         //This styles overwrite some of the region styles
00162         IPlotterStyle styleReal = pf.createPlotterStyle();
00163         styleReal.dataStyle().markerStyle().setParameter("shape","1");
00164         styleReal.dataStyle().markerStyle().setParameter("color","black");
00165         IPlotterStyle styleMC = pf.createPlotterStyle();
00166         styleMC.dataStyle().markerStyle().setParameter("shape","2");
00167         styleMC.dataStyle().markerStyle().setParameter("color","red");
00168 
00169             //list available parameters
00170 
00171         /*      
00172             String[] styles = styleReal.availableParameters();
00173             for(int t = 0;t<styles.length;t++) {
00174         System.out.println(styles[t]);
00175             }
00176         */
00177             
00178             if (plot instanceof FittedPlot){
00179                 comparisonPlot = ((FittedPlot)plot).getCompPlot();
00180         histMC = buildHist(plot,null,"Simulation"); //set at path if you want xml
00181 
00182             } else if (plot instanceof PredictedPlot){
00183                 comparisonPlot = ((PredictedPlot)plot).getCompPlot();
00184         histMC = buildHist(plot,null,"Simulation"); //set at path if you want xml
00185 
00186         } else {
00187         histReal = buildHist(plot,null,"Measurement"); //set at path if you want xml
00188         }
00189 
00190         if ((comparisonPlot!=null)){
00191         histReal = buildHist(comparisonPlot,null,"Measurement"); //set at path if you want xml
00192             }
00193             
00194             if(plot.isLogarithmic()) {
00195                 System.out.println("Using logarithmic scale");
00196                 double ymx = plot.getYMax();
00197                 double ymn = plot.getYMinNonZero();
00198                 
00199                 if(comparisonPlot !=null) {
00200                     ymx = Math.max(ymx,comparisonPlot.getYMax());
00201                     ymn = Math.max(ymn,comparisonPlot.getYMinNonZero());
00202                     
00203                 }
00204                 
00205                 page1.region(0).style().yAxisStyle().setParameter("scale","logarithmic");
00206                 page1.region(0).setYLimits(ymn/2.0,ymx*2.0);
00207             }else {
00208                 double ymx = plot.getYMax();
00209                 double ymn = plot.getYMinNonZero();
00210                 
00211                 if(comparisonPlot !=null) {
00212                     ymx = Math.max(ymx,comparisonPlot.getYMax());
00213                     ymn = Math.max(ymn,comparisonPlot.getYMinNonZero());
00214                     
00215                 }
00216                 page1.region(0).setYLimits(0,ymx*1.1);
00217                 page1.region(0).style().xAxisStyle().setLabel(plot.getXLabel());
00218                 page1.region(0).style().yAxisStyle().setLabel(plot.getYLabel());
00219                 
00220             }
00221 
00222         if (histMC!=null) page1.region(0).plot(histMC,styleMC);     
00223         page1.region(0).plot(histReal,styleReal);
00224             
00225             page1.region(0).style().xAxisStyle().setLabel(plot.getXLabel());
00226             page1.region(0).style().yAxisStyle().setLabel(plot.getYLabel());
00227             
00228         Properties props = new Properties();
00229         props.setProperty("plotWidth",String.valueOf(300));
00230         props.setProperty("plotHeight",String.valueOf(300));
00231 
00232             //System.out.println("JetWebHist writing: "+path);
00233             PlotterUtilities.writeToFile(page1,path+"/plot"+plot.getNumber()
00234                      +"."+JetWebConfig.graphicsType,
00235                      JetWebConfig.graphicsType,props);
00236         }catch (Exception e) {
00237             e.printStackTrace();
00238         }
00239     return;
00240     }
00241     
00242     
00243 }
00244 

Generated Wed Jan 17 09:14:27 GMT 2007