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

Fit.java

Go to the documentation of this file.
00001 package cedar.jetweb.model.fit;
00002 
00003 import java.io.File;
00004 import java.io.IOException;
00005 import java.io.BufferedReader;
00006 import java.io.BufferedWriter;
00007 import java.io.FileReader;
00008 import java.io.FileWriter;
00009 
00010 import java.util.List;
00011 import java.util.ArrayList;
00012 import java.util.Comparator;
00013 import java.util.Collections;
00014 import java.util.Date;
00015 import java.util.Vector;
00016 import java.util.Enumeration;
00017 import java.util.HashMap;
00018 import java.util.Map;
00019 import java.util.Iterator;
00020 import java.util.Collection;
00021 
00022 import java.text.DateFormat;
00023 import java.text.ParseException;
00024 import java.text.DecimalFormat;
00025 
00026 import org.apache.commons.io.FileUtils;
00027 
00028 import cedar.jetweb.*;
00029 import cedar.jetweb.model.plots.*;
00030 import cedar.jetweb.model.paper.*;
00031 import cedar.jetweb.model.*;
00032 
00033 import cedar.jetweb.html.*;
00034 
00035 import cedar.jetweb.db.DBFitManager;
00036 import cedar.jetweb.db.DBPlotManager;
00037 
00038 
00048 public class Fit implements Storeable {
00049     
00050     private Model model;
00051     private int modelId;
00052     private PlotSelection selection;
00053     private Map<Integer,Paper> mcPapers=new HashMap<Integer,Paper>();
00054     private HashMap<Integer, CombinedPaper> papers_ = 
00055     new HashMap<Integer, CombinedPaper>();
00056     private int fitId=-1;
00057     private boolean valid_=false;
00058     private Date date;
00059     private double bestScale;
00060 
00061     // If true, the fit will be updated next time it is queried.
00062     private boolean forceUpdate_=false;
00063 
00064     private double[] chi2 = {0.0, 0.0};
00065 
00072     public Fit(int newFitId) throws JetWebException { 
00073 
00074     fitId = newFitId;
00075     init();
00076     
00077     }
00078 
00086     public Fit(Model newmodel, PlotSelection newselection) 
00087     throws JetWebException {  
00088 
00089     model=newmodel;
00090     modelId=model.getId();
00091 
00092     selection=(PlotSelection)newselection.clone();
00093     
00094     init();
00095     
00096     // Check the required plots are available and get the chi2/dof for them.
00097     if (!selection.isAvailable(model)){
00098 
00099         System.out.println
00100         ("JM:  plot selection is not available in this model");
00101 
00102         throw new JetWebFitException
00103         ("Requested plots not available for model, Id:"
00104          +model.getId(),"");
00105     }
00106     
00107     // Find the cross section set matching this PlotSelection.
00108     try {
00109         int cssId = selection.getId();
00110         if (cssId<0) {
00111         System.out.println
00112             ("Error: could not allocate cross section set for this fit."+cssId);
00113         throw new JetWebException
00114             ("Error: could not allocate cross section set for this fit.","fit = "+getId());
00115         }
00116     } catch (JetWebException e) {
00117         System.out.println("Error: could not allocate cross section set for this fit."+e);
00118         throw e;
00119     }
00120     
00121     // There are two types of plots in the PlotSelection. Those to
00122     // be included int the reported Chi2 Sum, and those to be used
00123     // to determine the normalisation of the MC in the fit. Only
00124     // the latter really distinguishes two completely different
00125     // Fits, since the former can be easily recalculated on the
00126     // fly. Thus to determine whether or not this Fit has already
00127     // been done, we search using a PlotSelection which has the
00128     // "Sum" plots set to the default value, but the "Fit" plots
00129     // as given in the input PlotSelection.
00130     // 
00131     PlotSelection defaultSelection = new PlotSelection();
00132     //defaultSelection.setSumDefault();
00133     defaultSelection.setSumPlots(selection.getSumPlots());
00134     defaultSelection.setFitPlots(selection.getFitPlots());
00135     
00136     System.out.println("Successfully made fit for model "+newmodel);
00137 
00138     return;
00139     }
00140 
00142     public Date getDate() throws JetWebException { 
00143     fill();
00144     return date; 
00145     }
00147     public void setDate(Date d) { date = d;}
00148     
00150     public void setId(int id) { fitId = id;}
00151     
00157     public int getId(){ return fitId; }
00158     
00160     public double getScale()  throws JetWebException  { 
00161     fill();
00162     return bestScale;
00163     }
00165     public void setScale(double d){ bestScale = d;}
00166     
00168     public PlotSelection getSelection(){ return selection;}
00172     public Model getModel() throws JetWebException {
00173     
00174     if(getId() >= 0 ) fill();
00175     if (modelId<0) return null;
00176     try {
00177         if (model==null){
00178         model=new Model(modelId);
00179         }
00180     } catch (JetWebException e){
00181         throw e;
00182     }
00183     return model;
00184     }
00185 
00189     public PlotSelection getPlotSelection()  throws JetWebException {
00190     if(getId()>=0) fill();
00191     return selection;
00192     }
00193 
00197     public void setPlotSelection(PlotSelection sel){
00198     selection = sel;
00199     }
00200 
00204     public void setModelId(int newId){ modelId=newId;}
00209     public boolean isValid()  throws JetWebException { 
00210     fill();
00211     return valid_; }
00217     public Map<Integer,Paper> getMCPapers() throws JetWebException {
00218 
00219     fill();
00220     if (mcPapers.isEmpty()){
00221         populateMCPapers();
00222         populatePapers();
00223     }
00224     Map<Integer,Paper> retn = new HashMap<Integer,Paper>();
00225     retn.putAll(mcPapers);
00226     return retn;
00227     }
00228     
00229     public HashMap<Integer, CombinedPaper> getPapers() throws JetWebException{
00230 
00231     fill();
00232     if(papers_.isEmpty()){
00233         populatePapers();
00234     }
00235     
00236     HashMap<Integer, CombinedPaper> retn = 
00237         new HashMap<Integer, CombinedPaper>();
00238     
00239     retn.putAll(papers_);
00240     return retn;
00241     }
00242 
00247     private void doFit(PlotSelection defaultSumPlots) throws JetWebException {
00248 
00249     System.out.println("Fit: Starting fit "+fitId);
00250 
00251     double start     = JetWebConfig.lowScale;
00252     double stop      = JetWebConfig.highScale;
00253     double increment = JetWebConfig.scaleIncrement;
00254     Double chi2min = Double.POSITIVE_INFINITY;
00255     bestScale = 0;
00256     //doing the fit is much nicer with CombinedPapers.  Not used yet.
00257     
00258 
00259     while(start<=stop){
00260         double chi2 = 0.0;
00261         for(CombinedPaper paper: papers_.values()){
00262         paper.setScale(start);
00263         chi2 = chi2 + paper.getFitChi2(defaultSumPlots);
00264         }
00265         if(chi2<chi2min){
00266         chi2min = chi2;
00267         bestScale = start;
00268 
00269         }
00270         start = start + increment;
00271     }
00272 
00273     //Set the best scale for the papers and re-calculate the chi2
00274     //Could do this by keeping a copy of the papers when the best scale
00275     //is found.  Would need a deep copy of the paper and to copy the 
00276     //paper each time a better scale is found so may not even be
00277     //faster
00278 
00279     for(CombinedPaper paper: papers_.values()){
00280         paper.setScale(bestScale);
00281         paper.getFitChi2(defaultSumPlots);
00282         //papers_.put(paper.getRealPaper().getId(), paper);
00283     }
00284 
00285     Map<Integer,Paper> dataPapers = new HashMap<Integer,Paper>();
00286     Map<Integer,Paper> scaledPapers = new HashMap<Integer,Paper>();
00287 
00288     // Get the Vector of Data Papers which match these.
00289     for (Paper mcPaper : mcPapers.values()) {
00290         Paper dataPaper = PaperBank.getPaper(mcPaper.getId());
00291         dataPapers.put(new Integer(dataPaper.getId()),dataPaper);
00292     }
00293 
00294     while (start<=stop){
00295 
00296         double chi2=0;
00297         for (Paper mcPaper : mcPapers.values()){
00298         Paper dataPaper = dataPapers.get(new Integer(mcPaper.getId()));
00299         Paper tmpPaper  = mcPaper.fit
00300             (dataPaper,start,defaultSumPlots,false);
00301         chi2=chi2+tmpPaper.getFitChi2()[0];
00302         //System.out.println("chi2,scale"+chi2+","+start);
00303         }
00304 
00305         if (chi2<chi2min){
00306         chi2min=chi2;
00307         bestScale=start;
00308             }
00309 
00310         start = start+increment;
00311 
00312     }
00313 
00314     System.out.println("Have fit. Now adjust mcPapers to use the correct scale.");
00315     for (Paper mcPaper : mcPapers.values()){
00316         Paper dataPaper = dataPapers.get(new Integer(mcPaper.getId()));
00317         mcPaper = mcPaper.fit(dataPaper,bestScale,defaultSumPlots,true);
00318         mcPaper.fixFit(this);
00319             scaledPapers.put(new Integer(mcPaper.getId()),mcPaper);
00320     }
00321 
00322     // Replace the old mcPapers by the new ones.
00323     mcPapers = scaledPapers;
00324     System.out.println("Best scale = "+bestScale);
00325 
00326     }
00327 
00328     private void populatePapers() throws JetWebException{
00329     
00330     for(RealPaper realPaper: PaperBank.getRealPapers()){
00331         CombinedPaper newPaper = new CombinedPaper(realPaper, getModel());
00332         if(newPaper.getNPredictedPlots()!=0){ 
00333         papers_.put(newPaper.getRealPaper().getId(), newPaper);
00334         }
00335     }
00336 
00337     return;
00338     }
00339 
00340     private void populateMCPapers() throws JetWebException {
00341 
00342     System.out.println("Fit: Getting MC papers");
00343 
00344     /*
00345     for (Paper dataPaper : PaperBank.getPapers()){
00346         Paper mcPaper = null;
00347         mcPaper = new Paper(dataPaper,getModel());
00348         if (mcPaper.getPlots()!=null && mcPaper.getPlots().iterator().hasNext()){
00349         mcPapers.put(new Integer(mcPaper.getId()),mcPaper);
00350         }
00351     }
00352     */
00353     System.out.println("+++ populating mcpapers +++");
00354     mcPapers = DBPlotManager.getPredictedPapers(getModel());
00355     System.out.println("+++ done +++");
00356     return;
00357     }
00358 
00359 
00360     // Insert the fitted plots into the fitted_points and
00361     // fitted_prediction tables.
00362     private void insertPlots() throws JetWebException {
00363 
00364     Vector<Integer> allPlots = selection.getPlotIds();
00365 
00366     //Insert plots using new CombinedPaper:
00367 
00368     for(Map.Entry<Integer, CombinedPaper> entry: papers_.entrySet()){
00369         CombinedPaper paper = entry.getValue();
00370         paper.setFit(this);
00371         for(FittedPlot plot: paper.getFittedPlots()){
00372         //Uncomment this line to enable storage of 
00373         // FittedPlots from new Combined Papers
00374         //plot.toDB();
00375         }
00376     }
00377 
00378     //using old method
00379 
00380     // Loop over papers.
00381     for (Paper mcPaper : mcPapers.values()){
00382 
00383         //Iterator<DataPlot> mcPlotList = mcPaper.getPlots().iterator(); 
00384         
00385         //while (mcPlotList.hasNext()){
00386         for (DataPlot plot : mcPaper.getPlots()){
00387         //FittedPlot mcPlot = (FittedPlot)mcPlotList.next();
00388         if(allPlots.contains(plot.getId())){
00389             System.out.println
00390             ("Saving plot "+ plot.getNumber() +
00391              " from paper " + mcPaper.getId());
00392             
00393             FittedPlot mcPlot = (FittedPlot)plot;
00394             mcPlot.setFit(this);
00395             mcPlot.toDB();
00396         }
00397         }
00398     }
00399     }
00400 
00401     private void init() throws JetWebException {
00402 
00403     mcPapers=new HashMap<Integer,Paper>();
00404 
00405     }
00406 
00407 
00408 
00409 
00413     public void setChi2(double[] chi2){
00414     this.chi2[0] = chi2[0];
00415     this.chi2[1] = chi2[1];
00416     }
00421     public double[] getChi2() throws JetWebException {
00422 
00423     fill();
00424 
00425     if (this.chi2[0]>0) { 
00426         return this.chi2; 
00427     } else {
00428 
00429         double[] chi2 = {0.0, 0.0};
00430         Iterator<DataPlot> plots = selection.getSumPlots().iterator();
00431         while (plots.hasNext()){
00432         DataPlot plot = plots.next();       
00433         chi2 = DataPlot.getChi2(plot.getId(),getId());
00434         this.chi2[0]+=chi2[0];
00435         this.chi2[1]+=chi2[1];
00436         }
00437 
00438         return this.chi2; 
00439     }   
00440     }
00441 
00446     public double[] getChi2(PlotSelection newSelection, MCProcessType proc) 
00447     throws JetWebException {
00448 
00449     fill();
00450 
00451     if (newSelection == null && proc == null){
00452         return getChi2();
00453     } else if (proc == null){
00454 
00455         double[] newChi2 = {0.0, 0.0};
00456         double[] tmpChi2 = {0.0, 0.0};
00457         Iterator<DataPlot> plots = newSelection.getSumPlots().iterator();
00458         while (plots.hasNext()){
00459         DataPlot plot = plots.next();       
00460         tmpChi2 = DataPlot.getChi2(plot.getId(),getId());
00461         newChi2[0]+=tmpChi2[0];
00462         newChi2[1]+=tmpChi2[1];
00463         }
00464         return newChi2;
00465     }
00466     
00467 
00468     Iterator<DataPlot> plots;
00469     if (newSelection == null) { 
00470         plots = selection.getSumPlots().iterator();
00471     } else {
00472         plots = newSelection.getSumPlots().iterator();
00473     }
00474 
00475     double[] newChi2 = {0.0, 0.0};
00476     double[] tmpChi2 = {0.0, 0.0};
00477 
00478     try {
00479         Vector<RunSeries> rsVector = model.getRunSeries(proc);
00480 
00481         while (plots.hasNext()){
00482         DataPlot plot = plots.next();
00483         Enumeration<RunSeries> rsList = rsVector.elements();
00484         boolean notFound = true;
00485         while (rsList.hasMoreElements() && notFound){
00486             RunSeries runSeries = rsList.nextElement();
00487             if (plot.isPredictedBy(runSeries)){
00488             tmpChi2 = DataPlot.getChi2(plot.getId(),getId());
00489             newChi2[0]+=tmpChi2[0];
00490             newChi2[1]+=tmpChi2[1];
00491             notFound = false;
00492             }       
00493         }       
00494         }
00495     } catch (JetWebException j) {
00496         System.out.println(j);
00497     }
00498 
00499     return newChi2;
00500 
00501     }
00502 
00507     public double[] getChi2(PlotSelection newSelection) throws JetWebException {
00508 
00509     fill();
00510 
00511     return getChi2(newSelection, null);
00512     }
00513 
00518     public double[] getChi2(MCProcessType proc) throws JetWebException {
00519 
00520     fill();
00521     return getChi2(null, proc);
00522     }
00523 
00527     public void zero(){
00528     DBFitManager.zeroFit(fitId);
00529     }
00530 
00535     public static void delete(int fitId){
00536 
00537     System.out.println("Fit: Removing Fit "+fitId);
00538     File dir = new File(JetWebConfig.rootDirectory
00539                 +"/"+JetWebConfig.plotCacheDirName
00540                 +"/"+fitId);
00541     try {
00542         FileUtils.deleteDirectory(dir);
00543         DBFitManager.deleteAll(fitId);
00544     } catch (Exception e) {
00545         System.out.println("Failed in attempt to delete fit"+e);
00546         e.printStackTrace();
00547     }
00548     
00549     }
00550 
00554     private void forceUpdate(){
00555     forceUpdate_ = true;
00556     valid_ = false;
00557     }
00558 
00559 
00560 
00565     public void update(boolean force) throws JetWebException {
00566     
00567     try {
00568         
00569         System.out.println("Fit: Deleting graphics Files ");
00570         File dir = new File(JetWebConfig.rootDirectory+"/"
00571                 +"/"+JetWebConfig.plotCacheDirName
00572                 +"/"+fitId);
00573         FileUtils.deleteDirectory(dir);
00574 
00575         //fit = new Fit(fitId);
00576         this.forceUpdate();
00577         fill();
00578     } catch (JetWebException e) {
00579         System.out.println("Failed in attempt to force update: "+e);
00580         e.printStackTrace();
00581         throw e; 
00582     } catch (IOException e) {
00583         System.out.println("Failed in attempt to force update: "+e);
00584         e.printStackTrace();
00585         throw new JetWebException(e); 
00586     }
00587     }
00588 
00589     public boolean retrieve() throws JetWebException {
00590 
00591     String result = DBFitManager.selectFromDB(this);    
00592 
00593     boolean uptodate = result.equals(DBFitManager.SUCCESS);
00594     System.out.println(result);
00595     return uptodate;
00596     }
00597 
00598     public synchronized boolean store() throws JetWebException {
00599 
00600     if (!valid_) {
00601         throw new JetWebException("Attempt to store invalid fit!","ID:"+getId());
00602     }
00603 
00604     System.out.println("Storing fit");
00605 
00606     boolean existed = (getId()>0);
00607 
00608     System.out.println("Fit ID = "+getId());
00609     System.out.println("fit already existed = "+existed);
00610 
00611     // If a row existed before. Delete it, and everything
00612     // associated with it.
00613 
00614     if (existed) DBFitManager.deleteAll(getId());
00615     // If this fails, the fitId will be set to 0
00616 
00617     DBFitManager.addFit(this);
00618 
00619     if (fitId!=0){
00620 
00621         System.out.println("inserting plots");
00622 
00623         // Insert the plots.
00624         insertPlots();
00625 
00626     } else {
00627         throw new JetWebException("Fit.store:Error determining fitId! "
00628                       ,"ModelId="+model.getId()
00629                       +", PlotSelection="+selection.getId());
00630     }
00631 
00632     System.out.println("returning from store method");
00633 
00634 
00635     return existed;
00636     }
00637 
00638 
00639 
00640 
00641 
00653     public static List<Fit> getFits( final ResultSearchPattern pattern, 
00654                      final PlotSelection selection, 
00655                      final String sort ) throws JetWebException {
00656 
00657     List<Fit> fitList = new ArrayList<Fit>();
00658 
00659     System.out.println("Fit: Looking for models for "+pattern.getGenerator());
00660 
00661     // Build a list of Models which are consistent with this ResultSearchPattern
00662     Collection<Model> modelList = pattern.getConsistentModels();
00663     
00664     // Build Fits from the models and the cross section set.
00665     for (Model model : modelList){
00666         try {
00667         Fit fit = new Fit(model, selection);
00668         if (fit.isValid()) { fitList.add(fit); }
00669         } catch (JetWebFitException e) { 
00670         // Come here if the required plots aren't available.
00671         System.out.println("Fit: found a model, but with insufficient data.");
00672         }
00673     }
00674 
00675     //sort the fitList according to the "sort" input
00676     Comparator listSort = new Comparator() {
00677         public int compare(Object o1, Object o2) {
00678             Fit j1 = (Fit)o1; 
00679             Fit j2 = (Fit)o2; 
00680             Model m1 =null;
00681             Model m2 =null;
00682             try {
00683             m1 = j1.getModel();
00684             } catch (JetWebException e){
00685             return -1;
00686             }
00687             try {
00688             m2 = j2.getModel();
00689             } catch (JetWebException e){
00690             return 1;
00691             }
00692             int sortResult=0;
00693             try {
00694             if (sort.equals(HTMLUtils.PTHAT)){
00695                 sortResult = m2.getPthat().compareTo(m1.getPthat());
00696             } else if (sort.equals(HTMLUtils.DATE)){
00697                 sortResult = j1.getDate().compareTo(j2.getDate());
00698 
00699             /*
00700             } else if (sort.equals(HTMLUtils.CHI2ALL)){
00701             CutBand band1 = (CutBand)j1.bands.get(CutBand.ALL);
00702             CutBand band2 = (CutBand)j2.bands.get(CutBand.ALL);
00703             sortResult = (new Double(band2.getChi2Total()/band2.getDOFTotal()))
00704                 .compareTo((new Double(band1.getChi2Total()/band1.getDOFTotal())));
00705             } else if (sort.equals(HTMLUtils.CHI2HIGH)){
00706             CutBand band1 = (CutBand)j1.bands.get(CutBand.HI);
00707             CutBand band2 = (CutBand)j2.bands.get(CutBand.HI);
00708             sortResult = (new Double(band2.getChi2Total()/band2.getDOFTotal()) )
00709                 .compareTo((new Double(band1.getChi2Total()/band1.getDOFTotal())));
00710             } else if (sort.equals(HTMLUtils.CHI2LOW)){
00711             CutBand band1 = (CutBand)j1.bands.get(CutBand.LO);
00712             CutBand band2 = (CutBand)j2.bands.get(CutBand.LO);
00713             sortResult = (new Double(band2.getChi2Total()/band2.getDOFTotal()) )
00714                 .compareTo((new Double(band1.getChi2Total()/band1.getDOFTotal())));
00715             } else if (sort.equals(HTMLUtils.CHI2SHAPE)){
00716             CutBand band1 = (CutBand)j1.bands.get(CutBand.SHAPE);
00717             CutBand band2 = (CutBand)j2.bands.get(CutBand.SHAPE);
00718             sortResult = (new Double(band2.getChi2Total()/band2.getDOFTotal()) )
00719                 .compareTo((new Double(band1.getChi2Total()/band1.getDOFTotal())));
00720             } else if (sort.equals(HTMLUtils.CHI2CHARM)){
00721             CutBand band1 = (CutBand)j1.bands.get(CutBand.CHARM);
00722             CutBand band2 = (CutBand)j2.bands.get(CutBand.CHARM);
00723             sortResult = (new Double(band2.getChi2Total()/band2.getDOFTotal()) )
00724                 .compareTo((new Double(band1.getChi2Total()/band1.getDOFTotal())));
00725 
00726             } else if (sort.equals(HTMLUtils.CHI2ALLEP)){
00727             CutBand band1 = (CutBand)j1.bands.get(CutBand.ALL);
00728             CutBand band2 = (CutBand)j2.bands.get(CutBand.ALL);
00729             sortResult = (new Double(band2.getChi2Ep()/band2.getDOFEp()))
00730                 .compareTo((new Double(band1.getChi2Ep()/band1.getDOFEp())));
00731             } else if (sort.equals(HTMLUtils.CHI2HIGHEP)){
00732             CutBand band1 = (CutBand)j1.bands.get(CutBand.HI);
00733             CutBand band2 = (CutBand)j2.bands.get(CutBand.HI);
00734             sortResult = (new Double(band2.getChi2Ep()/band2.getDOFEp()) )
00735                 .compareTo((new Double(band1.getChi2Ep()/band1.getDOFEp())));
00736             } else if (sort.equals(HTMLUtils.CHI2LOWEP)){
00737             CutBand band1 = (CutBand)j1.bands.get(CutBand.LO);
00738             CutBand band2 = (CutBand)j2.bands.get(CutBand.LO);
00739             sortResult = (new Double(band2.getChi2Ep()/band2.getDOFEp()) )
00740                 .compareTo((new Double(band1.getChi2Ep()/band1.getDOFEp())));
00741             } else if (sort.equals(HTMLUtils.CHI2SHAPEEP)){
00742             CutBand band1 = (CutBand)j1.bands.get(CutBand.SHAPE);
00743             CutBand band2 = (CutBand)j2.bands.get(CutBand.SHAPE);
00744             sortResult = (new Double(band2.getChi2Ep()/band2.getDOFEp()) )
00745                 .compareTo((new Double(band1.getChi2Ep()/band1.getDOFEp())));
00746             } else if (sort.equals(HTMLUtils.CHI2CHARMEP)){
00747             CutBand band1 = (CutBand)j1.bands.get(CutBand.CHARM);
00748             CutBand band2 = (CutBand)j2.bands.get(CutBand.CHARM);
00749             sortResult = (new Double(band2.getChi2Ep()/band2.getDOFEp()) )
00750                 .compareTo((new Double(band1.getChi2Ep()/band1.getDOFEp())));
00751 
00752             } else if (sort.equals(HTMLUtils.CHI2ALLEE)){
00753             CutBand band1 = (CutBand)j1.bands.get(CutBand.ALL);
00754             CutBand band2 = (CutBand)j2.bands.get(CutBand.ALL);
00755             sortResult = (new Double(band2.getChi2Ee()/band2.getDOFEe()))
00756                 .compareTo((new Double(band1.getChi2Ee()/band1.getDOFEe())));
00757             } else if (sort.equals(HTMLUtils.CHI2HIGHEE)){
00758             CutBand band1 = (CutBand)j1.bands.get(CutBand.HI);
00759             CutBand band2 = (CutBand)j2.bands.get(CutBand.HI);
00760             sortResult = (new Double(band2.getChi2Ee()/band2.getDOFEe()) )
00761                 .compareTo((new Double(band1.getChi2Ee()/band1.getDOFEe())));
00762             } else if (sort.equals(HTMLUtils.CHI2LOWEE)){
00763             CutBand band1 = (CutBand)j1.bands.get(CutBand.LO);
00764             CutBand band2 = (CutBand)j2.bands.get(CutBand.LO);
00765             sortResult = (new Double(band2.getChi2Ee()/band2.getDOFEe()) )
00766                 .compareTo((new Double(band1.getChi2Ee()/band1.getDOFEe())));
00767             } else if (sort.equals(HTMLUtils.CHI2SHAPEEE)){
00768             CutBand band1 = (CutBand)j1.bands.get(CutBand.SHAPE);
00769             CutBand band2 = (CutBand)j2.bands.get(CutBand.SHAPE);
00770             sortResult = (new Double(band2.getChi2Ee()/band2.getDOFEe()) )
00771                 .compareTo((new Double(band1.getChi2Ee()/band1.getDOFEe())));
00772             } else if (sort.equals(HTMLUtils.CHI2CHARMEE)){
00773             CutBand band1 = (CutBand)j1.bands.get(CutBand.CHARM);
00774             CutBand band2 = (CutBand)j2.bands.get(CutBand.CHARM);
00775             sortResult = (new Double(band2.getChi2Ee()/band2.getDOFEe()) )
00776                 .compareTo((new Double(band1.getChi2Ee()/band1.getDOFEe())));
00777 
00778             } else if (sort.equals(HTMLUtils.CHI2ALLPP)){
00779             CutBand band1 = (CutBand)j1.bands.get(CutBand.ALL);
00780             CutBand band2 = (CutBand)j2.bands.get(CutBand.ALL);
00781             sortResult = (new Double(band2.getChi2Pp()/band2.getDOFPp()))
00782                 .compareTo((new Double(band1.getChi2Pp()/band1.getDOFPp())));
00783             } else if (sort.equals(HTMLUtils.CHI2HIGHPP)){
00784             CutBand band1 = (CutBand)j1.bands.get(CutBand.HI);
00785             CutBand band2 = (CutBand)j2.bands.get(CutBand.HI);
00786             sortResult = (new Double(band2.getChi2Pp()/band2.getDOFPp()) )
00787                 .compareTo((new Double(band1.getChi2Pp()/band1.getDOFPp())));
00788             } else if (sort.equals(HTMLUtils.CHI2LOWPP)){
00789             CutBand band1 = (CutBand)j1.bands.get(CutBand.LO);
00790             CutBand band2 = (CutBand)j2.bands.get(CutBand.LO);
00791             sortResult = (new Double(band2.getChi2Pp()/band2.getDOFPp()) )
00792                 .compareTo((new Double(band1.getChi2Pp()/band1.getDOFPp())));
00793             } else if (sort.equals(HTMLUtils.CHI2SHAPEPP)){
00794             CutBand band1 = (CutBand)j1.bands.get(CutBand.SHAPE);
00795             CutBand band2 = (CutBand)j2.bands.get(CutBand.SHAPE);
00796             sortResult = (new Double(band2.getChi2Pp()/band2.getDOFPp()) )
00797                 .compareTo((new Double(band1.getChi2Pp()/band1.getDOFPp())));
00798             } else if (sort.equals(HTMLUtils.CHI2CHARMPP)){
00799             CutBand band1 = (CutBand)j1.bands.get(CutBand.CHARM);
00800             CutBand band2 = (CutBand)j2.bands.get(CutBand.CHARM);
00801             sortResult = (new Double(band2.getChi2Pp()/band2.getDOFPp()) )
00802                 .compareTo((new Double(band1.getChi2Pp()/band1.getDOFPp())));
00803             */
00804 
00805             }
00806             } catch (NumberFormatException e){
00807             System.out.println("Fit: number format exception in sorting of results by " 
00808                        + sort);
00809             } catch (JetWebException e1){
00810             System.out.println("Fit: JetWebException thrown " 
00811                        + sort);
00812             e1.printStackTrace(System.out);
00813             } catch (NullPointerException e2){
00814             System.out.println("Fit:NullPointerException in sorting of results by " 
00815                        + sort);
00816             e2.printStackTrace(System.out);
00817             System.out.println("Fit ID 1:"+j1.getId());
00818             System.out.println("Fit ID 2:"+j2.getId());
00819             }
00820             return -1*sortResult;
00821         }
00822     };
00823     
00824     Collections.sort(fitList,listSort);
00825     return fitList;
00826 
00827     }
00828 
00829 
00833     public static Vector<Fit> getFits(Model model) throws JetWebException {
00834 
00835     return DBFitManager.select(model);
00836 
00837     }
00838 
00839     //
00840     // This method is invoked automatically when any get method for the
00841     // the fit is invoked. It  
00842     // 
00843     private void fill() throws JetWebException {
00844 
00845     if (valid_) {return;}
00846 
00847     // Search DB for a fit either with this id, or associated with
00848     // this model and cross section set.  Regenerate the fit if
00849     // data has been added to the model since the fit was last
00850     // remade.  
00851     boolean uptodate = retrieve();
00852 
00853     valid_=true;
00854 
00855     System.out.println("Fit "+fitId+" up to date? "+uptodate);
00856 
00857     if ( !uptodate || forceUpdate_ ){
00858 
00859         forceUpdate_=false;
00860 
00861         // (Re)do the fit.
00862         populateMCPapers();
00863         populatePapers();
00864 
00865         doFit(selection);
00866 
00867         // store it
00868         store();
00869 
00870         // (Re)write the graphics files
00871         HTMLPaperWriter.writeGraphics(mcPapers,this);
00872     }
00873     } 
00874 }
00875 
00876 
00877 
00878 
00879 
00880 
00881 
00882 
00883 
00884 
00885 
00886 
00887 
00888 

Generated Wed Jan 17 09:14:27 GMT 2007