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

Fit Class Reference

Inheritance diagram for Fit:

Inheritance graph
[legend]
Collaboration diagram for Fit:

Collaboration graph
[legend]
List of all members.

Detailed Description

Class containing all info about a comparison between a physics Model and a subset of measured data. Corresponds to a row in the fit table.

Author:
J.Butterworth.
Version:
Date
2007-01-12 18:57:03 +0000 (Fri, 12 Jan 2007)
Revision
1339

Definition at line 48 of file Fit.java.


Public Member Functions

 Fit (int newFitId) throws JetWebException
 Fit (Model newmodel, PlotSelection newselection) throws JetWebException
Date getDate () throws JetWebException
void setDate (Date d)
void setId (int id)
int getId ()
double getScale () throws JetWebException
void setScale (double d)
PlotSelection getSelection ()
Model getModel () throws JetWebException
PlotSelection getPlotSelection () throws JetWebException
void setPlotSelection (PlotSelection sel)
void setModelId (int newId)
boolean isValid () throws JetWebException
Map< Integer, PapergetMCPapers () throws JetWebException
HashMap< Integer, CombinedPapergetPapers () throws JetWebException
void setChi2 (double[] chi2)
double[] getChi2 () throws JetWebException
double[] getChi2 (PlotSelection newSelection, MCProcessType proc) throws JetWebException
double[] getChi2 (PlotSelection newSelection) throws JetWebException
double[] getChi2 (MCProcessType proc) throws JetWebException
void zero ()
void update (boolean force) throws JetWebException
boolean retrieve () throws JetWebException
synchronized boolean store () throws JetWebException

Static Public Member Functions

void delete (int fitId)
List< FitgetFits (final ResultSearchPattern pattern, final PlotSelection selection, final String sort) throws JetWebException
Vector< FitgetFits (Model model) throws JetWebException

Private Member Functions

void doFit (PlotSelection defaultSumPlots) throws JetWebException
void populatePapers () throws JetWebException
void populateMCPapers () throws JetWebException
void insertPlots () throws JetWebException
void init () throws JetWebException
void forceUpdate ()
void fill () throws JetWebException

Private Attributes

Model model
int modelId
PlotSelection selection
Map< Integer, PapermcPapers = new HashMap<IntegerPaper>()
HashMap< Integer, CombinedPaperpapers_
int fitId = -1
boolean valid_ = false
Date date
double bestScale
boolean forceUpdate_ = false
double[] chi2 = {0.0, 0.0}

Constructor & Destructor Documentation

Fit int  newFitId  )  throws JetWebException
 

Create a new Fit using the input fitId

Parameters:
fitId specifies fitId.
Exceptions:
JetWebException 

Definition at line 72 of file Fit.java.

References Fit.fitId, and Fit.init().

Referenced by Fit.getFits().

00072                                                     { 
00073 
00074     fitId = newFitId;
00075     init();
00076     
00077     }

Fit Model  newmodel,
PlotSelection  newselection
throws JetWebException
 

Create a new Fit using a specified data set.

Parameters:
newmodel Specifies the model to be fit.
selection Specifies which data should be used in the fit.
Exceptions:
JetWebException 

Definition at line 86 of file Fit.java.

References PlotSelection.clone(), PlotSelection.getFitPlots(), Fit.getId(), PlotSelection.getId(), Model.getId(), PlotSelection.getSumPlots(), Fit.init(), PlotSelection.isAvailable(), Fit.model, Fit.modelId, Fit.selection, PlotSelection.setFitPlots(), and PlotSelection.setSumPlots().

00087                            {  
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     }


Member Function Documentation

void delete int  fitId  )  [static]
 

Completely delete this fit from the database, and delete the associated files.

Definition at line 535 of file Fit.java.

References Fit.fitId.

00535                                         {
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     }

void doFit PlotSelection  defaultSumPlots  )  throws JetWebException [private]
 

Send a Vector of Papers. Do the fit for all Papers in the Vector for which the Paper is active.

Definition at line 247 of file Fit.java.

References Fit.bestScale, Fit.chi2, Paper.fit(), Fit.fitId, Paper.fixFit(), Paper.getFitChi2(), Paper.getId(), Fit.mcPapers, and Fit.papers_.

Referenced by Fit.fill().

00247                                                                              {
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     }

void fill  )  throws JetWebException [private]
 

Definition at line 843 of file Fit.java.

References Fit.doFit(), Fit.fitId, Fit.forceUpdate_, Fit.mcPapers, Fit.populateMCPapers(), Fit.populatePapers(), Fit.retrieve(), Fit.selection, Fit.store(), and Fit.valid_.

Referenced by Fit.getChi2(), Fit.getDate(), Fit.getMCPapers(), Fit.getModel(), Fit.getPapers(), Fit.getPlotSelection(), Fit.getScale(), Fit.isValid(), and Fit.update().

00843                                                {
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     } 

void forceUpdate  )  [private]
 

If set, the fit will be updated whether the DB thinks it is up to date or not.

Definition at line 554 of file Fit.java.

References Fit.forceUpdate_, and Fit.valid_.

00554                               {
00555     forceUpdate_ = true;
00556     valid_ = false;
00557     }

double [] getChi2 MCProcessType  proc  )  throws JetWebException
 

Returns the total chi2 and DoF for the plots consistent with the input MCProcessType

Definition at line 518 of file Fit.java.

References Fit.fill(), and Fit.getChi2().

00518                                                                        {
00519 
00520     fill();
00521     return getChi2(null, proc);
00522     }

double [] getChi2 PlotSelection  newSelection  )  throws JetWebException
 

Returns the total chi2 and DoF for the list of plots contained in the input PlotSelection.

Definition at line 507 of file Fit.java.

References Fit.fill(), and Fit.getChi2().

00507                                                                                {
00508 
00509     fill();
00510 
00511     return getChi2(newSelection, null);
00512     }

double [] getChi2 PlotSelection  newSelection,
MCProcessType  proc
throws JetWebException
 

Returns the total chi2 and DoF for the list of plots contained in the input PlotSelection and matching the input MCProcessType

Definition at line 446 of file Fit.java.

References Fit.fill(), Fit.getChi2(), Fit.getId(), DataPlot.getId(), Model.getRunSeries(), PlotSelection.getSumPlots(), DataPlot.isPredictedBy(), Fit.model, and Fit.selection.

00447                            {
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     }

double [] getChi2  )  throws JetWebException
 

Returns the total chi2 and DoF for the list of plots specified by the internal plotSelection.

Definition at line 421 of file Fit.java.

References Fit.chi2, DataPlot.chi2, Fit.fill(), Fit.getId(), DataPlot.getId(), PlotSelection.getSumPlots(), and Fit.selection.

Referenced by Fit.getChi2().

00421                                                      {
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     }

Date getDate  )  throws JetWebException
 

Date of the fit

Definition at line 142 of file Fit.java.

References Fit.fill().

Referenced by Fit.getFits().

00142                                                  { 
00143     fill();
00144     return date; 
00145     }

Vector<Fit> getFits Model  model  )  throws JetWebException [static]
 

Return all the fits associated with the input Model.

Definition at line 833 of file Fit.java.

References Fit.model.

00833                                                                           {
00834 
00835     return DBFitManager.select(model);
00836 
00837     }

List<Fit> getFits final ResultSearchPattern  pattern,
final PlotSelection  selection,
final String  sort
throws JetWebException [static]
 

Returns a list of results matching a given ResultSearchPattern and given PlotSelection.

Parameters:
pattern 
selection 
sort specifies parameter on which result list is to be sorted
Returns:
List of Fits sorted as requested
Exceptions:
JetWebFitException thrown if models exist but with insufficient data.
JetWebException thrown for any error.

Definition at line 653 of file Fit.java.

References Fit.Fit(), ResultSearchPattern.getConsistentModels(), Fit.getDate(), Fit.getId(), Fit.getModel(), ResultSearchPattern.getPthat(), Fit.isValid(), Fit.model, and Fit.selection.

00655                                                                 {
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     }

int getId  ) 
 

Unique ID of the fit

Returns:
-1 if undefined.

Implements Storeable.

Definition at line 157 of file Fit.java.

Referenced by HTMLFitWriter.comparePlots(), Searcher.doGet(), Fit.Fit(), FittedPlot.getChi2(), Fit.getChi2(), Fit.getFits(), CombinedPaper.getFittedPlots(), Fit.getModel(), Fit.getPlotSelection(), HTMLFitWriter.startPaperComparison(), Fit.store(), HTMLFitWriter.writeFitPage(), and HTMLPaperWriter.writeGraphics().

00157 { return fitId; }

Map<Integer,Paper> getMCPapers  )  throws JetWebException
 

Provides a copy of all the papers concerned with this result.

Returns:
mcPapers : a collection of Papers.

Definition at line 217 of file Fit.java.

References Fit.fill(), Fit.mcPapers, Fit.populateMCPapers(), and Fit.populatePapers().

Referenced by HTMLFitWriter.makeComparison().

00217                                                                    {
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     }

Model getModel  )  throws JetWebException
 

Return the model used in this fit.

Definition at line 172 of file Fit.java.

References Fit.fill(), Fit.getId(), Fit.model, and Fit.modelId.

Referenced by Fit.getFits(), FittedPlot.getMCProcessType(), Fit.populateMCPapers(), Fit.populatePapers(), and HTMLFitWriter.writeCompareFitsPage().

00172                                                    {
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     }

HashMap<Integer, CombinedPaper> getPapers  )  throws JetWebException
 

Definition at line 229 of file Fit.java.

References Fit.fill(), Fit.papers_, and Fit.populatePapers().

00229                                                                              {
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     }

PlotSelection getPlotSelection  )  throws JetWebException
 

Return the PlotSelection for this fit.

Definition at line 189 of file Fit.java.

References Fit.fill(), and Fit.getId().

00189                                                                     {
00190     if(getId()>=0) fill();
00191     return selection;
00192     }

double getScale  )  throws JetWebException
 

Scale factor for the Job Result data

Definition at line 160 of file Fit.java.

References Fit.fill().

Referenced by CombinedPaper.CombinedPaper(), and FittedPlot.FittedPlot().

00160                                                       { 
00161     fill();
00162     return bestScale;
00163     }

PlotSelection getSelection  ) 
 

Scale factor for the Job Result data

Definition at line 168 of file Fit.java.

00168 { return selection;}

void init  )  throws JetWebException [private]
 

Definition at line 401 of file Fit.java.

References Fit.mcPapers.

Referenced by Fit.Fit().

00401                                                {
00402 
00403     mcPapers=new HashMap<Integer,Paper>();
00404 
00405     }

void insertPlots  )  throws JetWebException [private]
 

Definition at line 362 of file Fit.java.

References CombinedPaper.getFittedPlots(), PlotSelection.getPlotIds(), Fit.mcPapers, Fit.papers_, Fit.selection, FittedPlot.setFit(), CombinedPaper.setFit(), and FittedPlot.toDB().

Referenced by Fit.store().

00362                                                       {
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     }

boolean isValid  )  throws JetWebException
 

Flag allowing this job result to be rendered invalid if processing errors occur.

Definition at line 209 of file Fit.java.

References Fit.fill().

Referenced by Fit.getFits().

00209                                                      { 
00210     fill();
00211     return valid_; }

void populateMCPapers  )  throws JetWebException [private]
 

Definition at line 340 of file Fit.java.

References Fit.getModel(), and Fit.mcPapers.

Referenced by Fit.fill(), and Fit.getMCPapers().

00340                                                            {
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     }

void populatePapers  )  throws JetWebException [private]
 

Definition at line 328 of file Fit.java.

References RealPaper.getId(), Fit.getModel(), CombinedPaper.getNPredictedPlots(), CombinedPaper.getRealPaper(), and Fit.papers_.

Referenced by Fit.fill(), Fit.getMCPapers(), and Fit.getPapers().

00328                                                         {
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     }

boolean retrieve  )  throws JetWebException
 

Populate the object in memory from the database. Return true if the information retrieved is up to date.

Implements Storeable.

Definition at line 589 of file Fit.java.

Referenced by Fit.fill().

00589                                                      {
00590 
00591     String result = DBFitManager.selectFromDB(this);    
00592 
00593     boolean uptodate = result.equals(DBFitManager.SUCCESS);
00594     System.out.println(result);
00595     return uptodate;
00596     }

void setChi2 double[]  chi2  ) 
 

Sets the total chi2 and DoF

Definition at line 413 of file Fit.java.

References DataPlot.chi2.

00413                                       {
00414     this.chi2[0] = chi2[0];
00415     this.chi2[1] = chi2[1];
00416     }

void setDate Date  d  ) 
 

Date of the fit

Definition at line 147 of file Fit.java.

References Fit.date.

00147 { date = d;}

void setId int  id  ) 
 

Unique ID of the fit

Definition at line 150 of file Fit.java.

References Fit.fitId.

00150 { fitId = id;}

void setModelId int  newId  ) 
 

Set the model Id. Should only be access by DB method.

Definition at line 204 of file Fit.java.

References Fit.modelId.

00204 { modelId=newId;}

void setPlotSelection PlotSelection  sel  ) 
 

Set the PlotSelection.

Definition at line 197 of file Fit.java.

References Fit.selection.

00197                                                    {
00198     selection = sel;
00199     }

void setScale double  d  ) 
 

Scale factor for the Job Result data

Definition at line 165 of file Fit.java.

References Fit.bestScale.

00165 { bestScale = d;}

synchronized boolean store  )  throws JetWebException
 

Write the object in memory to the database. If the ID does not exist in the DB the object is inserted as a new entry. If the ID exists, that entry is updated.

Returns:
true if the object was inserted, false otherwise.

Implements Storeable.

Definition at line 598 of file Fit.java.

References Fit.fitId, PlotSelection.getId(), Model.getId(), Fit.getId(), Fit.insertPlots(), Fit.model, and Fit.selection.

Referenced by Fit.fill().

00598                                                                {
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     }

void update boolean  force  )  throws JetWebException
 

Update the fit.

Parameters:
force the update. Otherwise it will only update if necessary.

Definition at line 565 of file Fit.java.

References Fit.fill(), and Fit.fitId.

Referenced by ServletUtils.editFit(), and JobUtils.updateJobs().

00565                                                              {
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     }

void zero  ) 
 

Zero all the data in this fit.

Definition at line 527 of file Fit.java.

References Fit.fitId.

00527                       {
00528     DBFitManager.zeroFit(fitId);
00529     }


Member Data Documentation

double bestScale [private]
 

Definition at line 59 of file Fit.java.

Referenced by Fit.doFit(), and Fit.setScale().

double [] chi2 = {0.0, 0.0} [private]
 

Definition at line 64 of file Fit.java.

Referenced by Fit.doFit(), and Fit.getChi2().

Date date [private]
 

Definition at line 58 of file Fit.java.

Referenced by Fit.setDate().

int fitId = -1 [private]
 

Definition at line 56 of file Fit.java.

Referenced by Fit.delete(), Fit.doFit(), Fit.fill(), Fit.Fit(), Fit.setId(), Fit.store(), Fit.update(), and Fit.zero().

boolean forceUpdate_ = false [private]
 

Definition at line 62 of file Fit.java.

Referenced by Fit.fill(), and Fit.forceUpdate().

Map<Integer,Paper> mcPapers = new HashMap<IntegerPaper>() [private]
 

Definition at line 53 of file Fit.java.

Referenced by Fit.doFit(), Fit.fill(), Fit.getMCPapers(), Fit.init(), Fit.insertPlots(), and Fit.populateMCPapers().

Model model [private]
 

Definition at line 50 of file Fit.java.

Referenced by Fit.Fit(), Fit.getChi2(), Fit.getFits(), Fit.getModel(), and Fit.store().

int modelId [private]
 

Definition at line 51 of file Fit.java.

Referenced by Fit.Fit(), Fit.getModel(), and Fit.setModelId().

HashMap<Integer, CombinedPaper> papers_ [private]
 

Initial value:

 
    new HashMap<Integer CombinedPaper>()

Definition at line 54 of file Fit.java.

Referenced by Fit.doFit(), Fit.getPapers(), Fit.insertPlots(), and Fit.populatePapers().

PlotSelection selection [private]
 

Definition at line 52 of file Fit.java.

Referenced by Fit.fill(), Fit.Fit(), Fit.getChi2(), Fit.getFits(), Fit.insertPlots(), Fit.setPlotSelection(), and Fit.store().

boolean valid_ = false [private]
 

Definition at line 57 of file Fit.java.

Referenced by Fit.fill(), and Fit.forceUpdate().


The documentation for this class was generated from the following file:

Generated Wed Jan 17 09:14:27 GMT 2007