1 6 import java.awt.*; 7 import java.awt.event.*; 8 import JSci.physics.relativity.*; 9 import JSci.physics.quantum.*; 10 import JSci.physics.particles.*; 11 12 18 public final class HEPsimulator extends Frame implements Runnable { 19 private final Runnable thr=this; 20 private MenuBar mBar=new MenuBar(); 21 private Menu mExp=new Menu("Experiment"); 22 private Menu mRes=new Menu("Results"); 23 private MenuItem mDev=new MenuItem("Device"); 24 private MenuItem mSet=new MenuItem("Setup"); 25 private MenuItem mCalc=new MenuItem("Calculate"); 26 private DeviceDialog dlgDevice; 27 private SetupDialog dlgSetup; 28 31 private QuantumParticle particles[]=new QuantumParticle[38]; 32 33 private QuantumParticle ingoing[]=new QuantumParticle[2]; 34 private QuantumParticle outgoing[]=new QuantumParticle[2]; 35 private CMframe uni; 36 39 public HEPsimulator() { 40 super("HEP simulator"); 41 addWindowListener(new WindowAdapter() { 42 public void windowClosing(WindowEvent evt) { 43 dlgDevice.dispose(); 44 dlgSetup.dispose(); 45 dispose(); 46 System.exit(0); 47 } 48 }); 49 mDev.addActionListener(new ActionListener() { 50 public void actionPerformed(ActionEvent evt) { 51 dlgDevice.show(); 52 } 53 }); 54 mSet.addActionListener(new ActionListener() { 55 public void actionPerformed(ActionEvent evt) { 56 dlgSetup.show(); 57 } 58 }); 59 mCalc.addActionListener(new ActionListener() { 60 public void actionPerformed(ActionEvent evt) { 61 new Thread (thr).start(); 62 } 63 }); 64 setSize(400,300); 65 mBar.add(mExp); 66 mExp.add(mDev); 67 mExp.add(mSet); 68 mBar.add(mRes); 69 mRes.add(mCalc); 70 setMenuBar(mBar); 71 loadDatabase(); 72 dlgDevice=new DeviceDialog(this,dlgSetup=new SetupDialog(this,particles)); 73 } 74 public static void main(String args[]) { 75 HEPsimulator sim=new HEPsimulator(); 76 sim.start(); 77 } 78 public void start() { 79 show(); 80 } 81 84 public void run() { 85 uni=new CMframe(); 86 ingoing[0]=dlgSetup.getParticleA(); 87 ingoing[1]=dlgSetup.getParticleB(); 88 uni.setRelCMvel(ingoing[0],ingoing[1]); 89 uni.addParticle(ingoing[0]); 90 if(ingoing[1]!=null) 91 uni.addParticle(ingoing[1]); 92 93 try { 94 for(int i=0;i<particles.length;i++) { 95 outgoing[0]=(QuantumParticle) particles[i].getClass().newInstance(); 96 for(int j=i;j<particles.length;j++) { 97 outgoing[1]=(QuantumParticle) particles[j].getClass().newInstance(); 98 if(uni.conserve(outgoing[0],outgoing[1])) 99 new ResultsDialog(this,ingoing,outgoing,uni.interact()).show(); 100 } 101 } 102 } catch(Exception e) {} 103 } 104 107 private void loadDatabase() { 108 particles[0]=new Electron(); 110 particles[1]=new Positron(); 111 particles[2]=new ElectronNeutrino(); 112 particles[3]=new AntiElectronNeutrino(); 113 particles[4]=new Muon(); 114 particles[5]=new AntiMuon(); 115 particles[6]=new MuonNeutrino(); 116 particles[7]=new AntiMuonNeutrino(); 117 particles[8]=new Tau(); 118 particles[9]=new AntiTau(); 119 particles[10]=new TauNeutrino(); 120 particles[11]=new AntiTauNeutrino(); 121 particles[12]=new PiZero(); 123 particles[13]=new PiPlus(); 124 particles[14]=new PiMinus(); 125 particles[15]=new KPlus(); 126 particles[16]=new KMinus(); 127 particles[17]=new KZero(); 128 particles[18]=new AntiKZero(); 129 particles[19]=new Eta(); 130 particles[20]=new Proton(); 132 particles[21]=new AntiProton(); 133 particles[22]=new Neutron(); 134 particles[23]=new AntiNeutron(); 135 particles[24]=new Lambda(); 136 particles[25]=new AntiLambda(); 137 particles[26]=new SigmaPlus(); 138 particles[27]=new AntiSigmaPlus(); 139 particles[28]=new SigmaZero(); 140 particles[29]=new AntiSigmaZero(); 141 particles[30]=new SigmaMinus(); 142 particles[31]=new AntiSigmaMinus(); 143 particles[32]=new XiZero(); 144 particles[33]=new AntiXiZero(); 145 particles[34]=new XiMinus(); 146 particles[35]=new XiPlus(); 147 particles[36]=new OmegaMinus(); 148 particles[37]=new AntiOmegaMinus(); 149 } 150 } 151 152 153 159 class DeviceDialog extends Dialog { 160 private Button ok=new Button("OK"); 161 private SetupDialog dlgRel; 162 private CheckboxGroup cbg=new CheckboxGroup(); 163 private Checkbox cbChamber=new Checkbox("Bubble chamber",cbg,true); 164 private Checkbox cbAccelerator=new Checkbox("Particle accelerator",cbg,false); 165 public DeviceDialog(Frame f,SetupDialog sd) { 166 super(f,"Device Selection",true); 167 addWindowListener(new WindowAdapter() { 168 public void windowClosing(WindowEvent evt) { 169 setVisible(false); 170 } 171 }); 172 cbChamber.addItemListener(new ItemListener() { 173 public void itemStateChanged(ItemEvent evt) { 174 dlgRel.particleB.setEnabled(false); 175 dlgRel.energyB.setEnabled(false); 176 } 177 }); 178 cbAccelerator.addItemListener(new ItemListener() { 179 public void itemStateChanged(ItemEvent evt) { 180 dlgRel.particleB.setEnabled(true); 181 dlgRel.energyB.setEnabled(true); 182 } 183 }); 184 ok.addActionListener(new ActionListener() { 185 public void actionPerformed(ActionEvent evt) { 186 dispose(); 187 } 188 }); 189 setSize(200,120); 190 dlgRel=sd; 191 setLayout(new GridLayout(3,1)); 192 add(cbChamber); 193 add(cbAccelerator); 194 add(ok); 195 dlgRel.particleB.setEnabled(false); 196 dlgRel.energyB.setEnabled(false); 197 } 198 } 199 200 201 207 class SetupDialog extends Dialog { 208 private Button ok=new Button("OK"); 209 public Choice particleA=new Choice(); 210 public Choice particleB=new Choice(); 211 public TextField energyA,energyB; 212 private QuantumParticle array[]; 213 public SetupDialog(Frame f,QuantumParticle qpArray[]) { 214 super(f,"Device Settings",true); 215 array=qpArray; 216 energyA=new TextField(Double.toString(array[0].restMass())); 217 energyB=new TextField(Double.toString(array[0].restMass())); 218 addWindowListener(new WindowAdapter() { 219 public void windowClosing(WindowEvent evt) { 220 setVisible(false); 221 } 222 }); 223 particleA.addItemListener(new ItemListener() { 224 public void itemStateChanged(ItemEvent evt) { 225 energyA.setText(Double.toString(array[particleA.getSelectedIndex()].restMass())); 226 } 227 }); 228 particleB.addItemListener(new ItemListener() { 229 public void itemStateChanged(ItemEvent evt) { 230 energyB.setText(Double.toString(array[particleB.getSelectedIndex()].restMass())); 231 } 232 }); 233 energyA.addActionListener(new ActionListener() { 234 public void actionPerformed(ActionEvent evt) { 235 if(Double.valueOf(energyA.getText()).doubleValue() < array[particleA.getSelectedIndex()].restMass()) 236 energyA.setText(Double.toString(array[particleA.getSelectedIndex()].restMass())); 237 } 238 }); 239 energyB.addActionListener(new ActionListener() { 240 public void actionPerformed(ActionEvent evt) { 241 if(Double.valueOf(energyB.getText()).doubleValue() < array[particleB.getSelectedIndex()].restMass()) 242 energyB.setText(Double.toString(array[particleB.getSelectedIndex()].restMass())); 243 } 244 }); 245 ok.addActionListener(new ActionListener() { 246 public void actionPerformed(ActionEvent evt) { 247 dispose(); 248 } 249 }); 250 setSize(350,130); 251 GridBagLayout gb=new GridBagLayout(); 252 GridBagConstraints c=new GridBagConstraints(); 253 for(int n=0;n<array.length;n++) { 254 particleA.addItem(array[n].toString()); 255 particleB.addItem(array[n].toString()); 256 } 257 setLayout(gb); 258 c.anchor=GridBagConstraints.CENTER; 259 c.gridwidth=GridBagConstraints.RELATIVE; 260 gb.setConstraints(particleA,c); 261 add(particleA); 262 c.gridwidth=GridBagConstraints.REMAINDER; 263 gb.setConstraints(particleB,c); 264 add(particleB); 265 c.gridwidth=GridBagConstraints.RELATIVE; 266 gb.setConstraints(energyA,c); 267 add(energyA); 268 c.gridwidth=GridBagConstraints.REMAINDER; 269 gb.setConstraints(energyB,c); 270 add(energyB); 271 c.gridwidth=GridBagConstraints.REMAINDER; 272 gb.setConstraints(ok,c); 273 add(ok); 274 } 275 public QuantumParticle getParticleA() { 276 QuantumParticle temp; 277 try { 278 temp=(QuantumParticle) array[particleA.getSelectedIndex()].getClass().newInstance(); 279 } catch(Exception e) { 280 temp=null; 281 } 282 double energy=Double.valueOf(energyA.getText()).doubleValue(); 283 double mass=temp.restMass(); 284 temp.momentum=new Rank1Tensor(energy,Math.sqrt(energy*energy-mass*mass),0.0,0.0); 285 return temp; 286 } 287 public QuantumParticle getParticleB() { 288 QuantumParticle temp; 289 if(particleB.isEnabled()) { 290 try { 291 temp=(QuantumParticle) array[particleB.getSelectedIndex()].getClass().newInstance(); 292 } catch(Exception e) { 293 temp=null; 294 } 295 double energy=Double.valueOf(energyB.getText()).doubleValue(); 296 double mass=temp.restMass(); 297 temp.momentum=new Rank1Tensor(energy,-Math.sqrt(energy*energy-mass*mass),0.0,0.0); 298 } else 299 temp=null; 300 return temp; 301 } 302 } 303 304 305 311 class ResultsDialog extends Dialog { 312 private Button ok=new Button("OK"); 313 public ResultsDialog(Frame f,QuantumParticle in[],QuantumParticle out[],String interact) { 314 super(f,"Results",false); 315 addWindowListener(new WindowAdapter() { 316 public void windowClosing(WindowEvent evt) { 317 dispose(); 318 } 319 }); 320 ok.addActionListener(new ActionListener() { 321 public void actionPerformed(ActionEvent evt) { 322 dispose(); 323 } 324 }); 325 setSize(300,300); 326 setLayout(new GridLayout(9,1)); 327 if(in[1]==null) 328 add(new Label(in[0].toString()+"------>")); 329 else 330 add(new Label(in[0].toString()+" ---> <--- "+in[1].toString())); 331 add(new Label(out[0].toString())); 332 add(new Label("Energy = "+Double.toString(out[0].momentum.getComponent(0)))); 333 add(new Label("Momentum = "+Double.toString(out[0].momentum.getComponent(1)))); 334 add(new Label(out[1].toString())); 335 add(new Label("Energy = "+Double.toString(out[1].momentum.getComponent(0)))); 336 add(new Label("Momentum = "+Double.toString(out[1].momentum.getComponent(1)))); 337 add(new Label("Interaction was the "+interact)); 338 add(ok); 339 } 340 } 341 342 348 final class CMframe { 349 352 private double energy; 353 356 private int B,I,Iz,Le,Lm,Lt,Q,S; 357 361 private double relCMvel; 362 365 private int interaction; 366 369 private final static int STRONG=1,WEAK=2,EM=3; 370 373 public CMframe() { 374 energy=B=I=Iz=Le=Lm=Lt=Q=S=0; 375 } 376 380 public boolean conserve(QuantumParticle a,QuantumParticle b) { 381 double Ei,Ej,pi,pj; 382 if(a.charge()+b.charge()==Q && a.eLeptonQN()+b.eLeptonQN()==Le && 384 a.muLeptonQN()+b.muLeptonQN()==Lm && a.tauLeptonQN()+b.tauLeptonQN()==Lt && 385 a.baryonQN()+b.baryonQN()==B && Math.abs(S-a.strangeQN()-b.strangeQN())<=1) { 386 if(a.strangeQN()+b.strangeQN()==S && a.isospinZ()+b.isospinZ()==Iz) { 387 if(a.isospin()==0 && b.isospin()==0) { 388 interaction=EM; 390 } else { 391 interaction=STRONG; 393 } 394 } else { 395 interaction=WEAK; 397 } 398 } else { 399 interaction=0; 400 } 401 if(interaction>0) { 403 double massA=1000.0*a.restMass(); 405 double massB=1000.0*b.restMass(); 406 Ei=(energy*energy-massB*massB+massA*massA)/(2.0*energy); 408 Ej=(energy*energy-massA*massA+massB*massB)/(2.0*energy); 409 pi=(energy*energy*energy*energy + 410 massA*massA*massA*massA + 411 massB*massB*massB*massB - 412 2.0*massA*massA*energy*energy - 413 2.0*massB*massB*energy*energy - 414 2.0*massA*massA*massB*massB); 415 if(pi>=0.0 && Ei>=0.0 && Ej>=0.0) { 417 pi=Math.sqrt(pi)/(2.0*energy); 418 pi/=1000.0; 420 a.momentum=new Rank1Tensor(Ei/1000.0,pi,0.0,0.0); 421 b.momentum=new Rank1Tensor(Ej/1000.0,-pi,0.0,0.0); 422 if(relCMvel!=0.0) { 424 LorentzBoost lb=new LorentzBoost(-relCMvel,0.0,0.0); 425 a.momentum=lb.multiply(a.momentum); 426 b.momentum=lb.multiply(b.momentum); 427 } 428 return true; 429 } 430 } 431 return false; 432 } 433 public void addParticle(QuantumParticle qp) { 434 B+=qp.baryonQN(); 435 I+=qp.isospin(); 436 Iz+=qp.isospinZ(); 437 Le+=qp.eLeptonQN(); 438 Lm+=qp.muLeptonQN(); 439 Lt+=qp.tauLeptonQN(); 440 Q+=qp.charge(); 441 S+=qp.strangeQN(); 442 443 LorentzBoost lb=new LorentzBoost(relCMvel,0.0,0.0); 444 qp.momentum=lb.multiply(qp.momentum); 445 446 energy+=qp.momentum.getComponent(0)*1000.0; } 448 451 public void setRelCMvel(QuantumParticle a,QuantumParticle b) { 452 if(b==null) 453 relCMvel=a.momentum.getComponent(1)/a.momentum.getComponent(0); 454 else 455 relCMvel=(a.momentum.getComponent(1)+b.momentum.getComponent(1))/(a.momentum.getComponent(0)+b.momentum.getComponent(0)); 456 } 457 460 public String interact() { 461 switch(interaction) { 462 case STRONG : return new String ("Strong Force"); 463 case WEAK : return new String ("Weak Force"); 464 case EM : return new String ("Electromagnetic Force"); 465 default : return new String ("Unknown - error"); 466 } 467 } 468 } 469 | Popular Tags |