00001 package cedar.jetweb.model.plots; 00002 00003 00004 import java.io.Serializable; 00005 import java.io.File; 00006 00007 import java.util.Vector; 00008 import java.util.Collection; 00009 import java.util.Collections; 00010 import java.util.HashSet; 00011 import java.util.Iterator; 00012 00013 import java.text.DecimalFormat; 00014 00015 import cedar.jetweb.*; 00016 import cedar.jetweb.model.paper.PaperBank; 00017 import cedar.jetweb.model.MCProcessType; 00018 import cedar.jetweb.model.RunSeries; 00019 import cedar.jetweb.model.Collision; 00020 import cedar.jetweb.generator.Generator; 00021 import cedar.jetweb.db.DBPlotManager; 00022 00023 import cedar.jetweb.job.CutCollection; 00024 00036 public abstract class DataPlot implements Serializable { 00038 public static final String REAL = DBPlotManager.REAL; 00040 public static final String PREDICTED = DBPlotManager.PREDICTED; 00042 public static final String FITTED = DBPlotManager.FITTED; 00043 00044 // Declarations. 00046 protected double sysScale=1.0; 00048 protected int number; 00050 protected String title = "No title"; 00051 00052 protected int collisionId; 00053 protected int procIdWanted; 00054 00055 protected CutCollection cuts_; 00056 00062 protected Vector<DataPoint> dataPoints; 00066 //private HashSet unSynch = new HashSet(); 00067 //protected HashSet switches = (HashSet)Collections.synchronizedSet(unSynch); 00068 HashSet<PlotSwitch> switches = 00069 new HashSet<PlotSwitch>(Collections.synchronizedSet(new HashSet<PlotSwitch>())); 00070 00071 protected int paperId; 00072 00073 protected double[] chi2 = new double[]{0,0}; 00074 00075 00079 protected double ecms; 00080 00082 protected int csnId=-1; 00084 protected boolean hasdata = false; 00087 protected boolean shape; 00088 protected MCProcessType proc; 00089 00090 private DecimalFormat form = new DecimalFormat("0.00"); 00091 private boolean defFit; 00092 private boolean defSum; 00093 private int nDataSources=1; 00094 private boolean logarithmic; 00095 private String ylabel = " "; 00096 private String xlabel = " "; 00097 00098 //accessors 00100 public int getId(){ return csnId; } 00101 00103 public void setId(int newId){ csnId = newId; } 00104 00110 public int getNumber(){ return number; } 00111 00117 public void setNumber(int newnum){ number = newnum; } 00118 00119 public CutCollection getCutCollection(){ 00120 return cuts_; 00121 } 00122 00123 public DataPlot setCutCollection(CutCollection cuts){ 00124 cuts_ = cuts; 00125 return this; 00126 } 00127 00129 public double getSysScale(){ return sysScale; } 00131 public void setSysScale(double scale){ sysScale=scale; } 00132 00134 public boolean isDefaultFit(){ return defFit; } 00136 public void setDefaultFit(boolean isit){ defFit = isit; } 00137 00139 public boolean isDefaultSum(){ return defSum; } 00141 public void setDefaultSum(boolean isit){ defSum = isit; } 00142 00144 public boolean isLogarithmic(){ return logarithmic; } 00146 public void setLogarithmic(boolean b){ logarithmic = b; } 00147 00150 public boolean isShape(){ return shape; } 00153 public void setShape(boolean isit){ shape = isit; } 00154 00155 00157 public String getTitle(){ return title; } 00159 public void setTitle(String newtitle){ title=newtitle; } 00161 public int getNDataSources(){return nDataSources;} 00162 00163 00165 public String getYLabel(){ 00166 return ylabel; 00167 } 00169 public void setYLabel(String newlabel){ 00170 ylabel = newlabel; 00171 } 00173 public String getXLabel(){ 00174 return xlabel; 00175 } 00177 public void setXLabel(String newlabel){ 00178 xlabel = newlabel; 00179 } 00180 00184 public boolean hasData() throws JetWebException { return hasdata; } 00185 public void setHasData(boolean b){ hasdata = b; } 00186 00192 public Vector<DataPoint> getDataPoints() throws JetWebException { 00193 if (dataPoints==null){ 00194 dataPoints = DBPlotManager.getDataPoints(this); 00195 } 00196 return dataPoints; 00197 } 00204 public void setDataPoints(Collection<DataPoint> newDataPoints){ 00205 00206 dataPoints = new Vector<DataPoint>(); 00207 00208 for (DataPoint point : newDataPoints) { 00209 00210 try{ 00211 dataPoints.add((DataPoint)point.clone() ); 00212 } catch (ClassCastException e){ 00213 System.out.println("Invalid Point Data sent to DataPlot.setDataPoints"); 00214 } 00215 } 00216 00217 if (dataPoints.isEmpty()){ 00218 System.out.println("No data for plot " + number + ":" + title); 00219 hasdata=false; 00220 } else { 00221 hasdata=true; 00222 } 00223 00224 } 00225 //public methods 00229 public double getYMin(){ 00230 00231 double min = 1000000; 00232 for (DataPoint point : dataPoints) { 00233 if (point.getY()<min){min=point.getY();} 00234 } 00235 return min*getSysScale(); 00236 } 00237 00242 public double getYMinNonZero(){ 00243 00244 double min = 1000000; 00245 for (DataPoint point : dataPoints) { 00246 if (point.getY()<min && point.getY()>0){min=point.getY();} 00247 } 00248 return min*getSysScale(); 00249 } 00250 00254 public double getYMax(){ 00255 00256 double max = -1000000; 00257 for (DataPoint point : dataPoints){ 00258 if (point.getY()>max) {max=point.getY();} 00259 } 00260 return max*getSysScale(); 00261 } 00262 00263 00264 00267 public void setFrom(DataPlot plot){ 00268 00269 setDefaultFit(plot.isDefaultFit()); 00270 setDefaultSum(plot.isDefaultSum()); 00271 setLogarithmic(plot.isLogarithmic()); 00272 setTitle(plot.getTitle()); 00273 setYLabel(plot.getYLabel()); 00274 setXLabel(plot.getXLabel()); 00275 setId(plot.getId()); 00276 setNumber(plot.getNumber()); 00277 setSysScale(plot.getSysScale()); 00278 setChi2(plot.getChi2()); 00279 setShape(plot.isShape()); 00280 setCollisionId(plot.getCollisionId()); 00281 setPaperId(plot.getPaperId()); 00282 /* 00283 try { 00284 proc=plot.getMCProcessType(); 00285 } catch (JetWebException jwe) { 00286 System.out.println("ALARM!"); 00287 jwe.printStackTrace(System.out); 00288 } 00289 */ 00290 } 00291 00292 00300 public boolean populateDBData() throws JetWebException { 00301 dataPoints = DBPlotManager.getDataPoints(this); 00302 if (dataPoints.isEmpty()){ 00303 hasdata = false; 00304 System.out.println("No data for plot " + number + ":" + title); 00305 } else { 00306 hasdata = true; 00307 } 00308 return hasdata; 00309 } 00310 00312 public void zero(){ 00313 00314 System.out.println("Called zero on plot "+getId()); 00315 00316 // loop over the dataPoints. 00317 for (DataPoint point : dataPoints){ 00318 point.setYUp(0); 00319 point.setYDown(0); 00320 point.setY(0); 00321 } 00322 } 00323 00324 00328 public boolean isPredictedBy(RunSeries rs){ 00329 try { 00330 return (DBPlotManager.plotExists(this,rs)); 00331 } catch (JetWebException j) { 00332 System.out.println(j); 00333 return false; 00334 } 00335 } 00336 00340 public Iterator<PlotSwitch> getSwitches() throws JetWebException { 00341 00342 HashSet<PlotSwitch> tmp = DBPlotManager.getSwitches(csnId); 00343 00344 if (switches==null) { 00345 switches = tmp; 00346 } else { 00347 Iterator<PlotSwitch> en = tmp.iterator(); 00348 while (en.hasNext()){ 00349 addSwitch(en.next()); 00350 } 00351 } 00352 return switches.iterator(); 00353 00354 } 00358 public void addSwitch(PlotSwitch ps) { 00359 00360 /* 00361 Iterator psl = switches.iterator(); 00362 while (psl.hasNext()){ 00363 if (ps.equals((PlotSwitch)psl.next())){ 00364 return; 00365 } 00366 } 00367 */ 00368 switches.add(ps); 00369 } 00370 00374 public void deleteSwitch(PlotSwitch ps) throws JetWebException { 00375 00376 if (switches.contains(ps)) { 00377 switches.remove(ps); 00378 } 00379 DBPlotManager.delete(ps); 00380 00381 } 00382 00383 public double getCMEnergy() { return ecms; } 00384 public void setCMEnergy(double e) { ecms = e; } 00385 00389 public void setPaperId(int newPaperId){ 00390 paperId = newPaperId; 00391 } 00392 00393 public int getPaperId(){ return paperId; } 00394 00398 public void storeSwitches() throws JetWebException { 00399 00400 // Get all the switches for the plot in memory. 00401 Iterator<PlotSwitch> psws = getSwitches(); 00402 while (psws.hasNext()){ 00403 PlotSwitch ps = (PlotSwitch)psws.next(); 00404 ps.store(); 00405 } 00406 } 00407 00414 public double[] getChi2(){ 00415 return chi2; 00416 } 00417 00418 00423 public void setChi2(double[] newchi2){ 00424 if (newchi2.length==2){ 00425 chi2[0]=newchi2[0]; 00426 chi2[1]=newchi2[1]; 00427 } else { 00428 System.out.println("invalid Chi2 array - DataPlot.setChi2()"); 00429 } 00430 } 00431 00432 00433 public int getCollisionId(){ return collisionId; } 00434 00435 public void setCollisionId(int id){ collisionId = id; } 00436 00437 00443 public abstract int getProcIdWanted() throws JetWebException; 00444 00450 public abstract MCProcessType getMCProcessType() throws JetWebException ; 00451 00456 public static double[] getChi2(int plotId, int fitId){ 00457 return DBPlotManager.getChi2(plotId,fitId); 00458 } 00459 00464 public double[] getChi2(int fitId){ 00465 return DBPlotManager.getChi2(getId(),fitId); 00466 } 00467 00468 00473 public int getProcIdWanted(Generator gen) throws JetWebException { 00474 00475 if (procIdWanted==0){ 00476 00477 Vector<PlotSwitch> bestMatches = 00478 DBPlotManager.getMatchedSwitches(this.getId(),gen); 00479 00480 int procIdDefault = (PlotSwitch.defaultProc(new Collision(collisionId))).getId(); 00481 00482 if (bestMatches.size()!=0) { 00483 00484 // Apply the switches. 00485 for (PlotSwitch pSwitch : bestMatches) { 00486 00487 if ( (pSwitch.getParameterName()==null)){ 00488 // This is the default for this plot. 00489 procIdDefault = pSwitch.getMCProcessTypeId(); 00490 } else { 00491 if (pSwitch.getParameterName().equals("pthat")){ 00492 try { 00493 00494 Double genPthat = gen.getPthat(); 00495 00496 if ((pSwitch.getParameterValueLow()==null|| 00497 genPthat>pSwitch.getParameterValueLow()) && 00498 (pSwitch.getParameterValueHigh()==null || 00499 genPthat<pSwitch.getParameterValueHigh()) 00500 ){ 00501 procIdWanted = pSwitch.getMCProcessTypeId(); 00502 } 00503 //System.out.println("DataPlot: pthat="+genPthat+" "+pSwitch.getParameterValueLow()+" "+pSwitch.getParameterValueHigh()); 00504 00505 } catch (NumberFormatException nfe) { 00506 nfe.printStackTrace(); 00507 } 00508 } 00509 } 00510 } 00511 } 00512 00513 if (procIdWanted==0) {procIdWanted=procIdDefault;} 00514 00515 } 00516 return procIdWanted; 00517 } 00518 00519 } 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536
Generated Wed Jan 17 09:14:27 GMT 2007