Commit in GeomConverter/test/org/lcsim/material on MAIN
BetheBlockTest.java+164-671.5 -> 1.6
JM: Add additional tests using muon, pion in Si, C.

GeomConverter/test/org/lcsim/material
BetheBlockTest.java 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- BetheBlockTest.java	21 Jan 2006 18:28:02 -0000	1.5
+++ BetheBlockTest.java	25 Jan 2006 01:08:58 -0000	1.6
@@ -6,7 +6,6 @@
 
 package org.lcsim.material;
 
-import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
@@ -14,73 +13,171 @@
 import org.lcsim.material.MaterialElement;
 
 /**
- *
+ * 
  * @author jeremym
  */
 public class BetheBlockTest extends TestCase
 {
-    /** Creates a new instance of MaterialManagerTest */
-    public BetheBlockTest()
-    {}
-    
-    public BetheBlockTest(String testName)
-    {
-        super(testName);
-    }
-    
-    public static TestSuite suite()
-    {
-        return new TestSuite(BetheBlockTest.class);
-    }
-    
-    public void testDummy()
-    {
-        MaterialElement element = new MaterialElement("DummyElement", 1.0, 1.0);
-        Material material = new Material("DummyMaterial", 1, 1.0, org.lcsim.material.MaterialState.SOLID, 1.0, 1.0);
-        material.addElement(element, 1.0);
-        /*CarolineMilstene- I replaced pT by p. The reason is that generally we reserve
-	pT for P-Transverse which is (px,py)and has 2 component whereas you define a 3 
-	component momentum []p=(1.,0.,0.)= (px,py,pz) */
-        double p[] = {1.0, 0, 0};
-        double mass = 1.0;
-        
-        double dEdx = MaterialCalculator.computeBetheBloch(
-        		material, // material 
-        		p,       // particle momentum
-        		mass,     // particle mass
-        		1.0,      // particle charge
-        		1.0);     // path length   
-    }
-    
-	// FIXME: Results look very wrong.
-    public void testMuonInCarbon()
-    {
-    	MaterialManager mgr = MaterialManager.instance();
-    	Material material = mgr.getMaterials().get("Carbon");
-    	
-    	System.out.println(material.toString());
-    	
-    	assert(material != null);
-    	
-    	double p[] = {1.0, 0, 0};
-    	
-    	// muon mass in MeV 
-    	double mass = 105.658369;
-    	/* CarolineMilstene- To Jeremy: The Momentum in the package is in
-	(GeV), we deal mostly with particles with masses of ~100 MeV/c
-	which are relativistic, therefore their momentum is of the order
-	of ~(GeV)=1000 MeV, which is also the unit in the pacjage we use,
-	 therefore I make the transformation inside the formula- 
-	 We enter with []p in GeV and inside it becomes []pmev
-	using a factor 1e+03 for each component and the calculation is 
-	made- then beta and gamma is calculated using those factors 
-	Jeremy-you can reduce this comment once you read and hopefully 
-	approve */
-    	double dEdx = MaterialCalculator.computeBetheBloch(
-    			material, // material 			
-    			p,        // particle momentum-in GeV 
-    			mass,     // particle mass -MeV/c
-    			1.0,      // particle charge
-    			1.0);     // path length ! (cm)
-    }
-}
+	/** Creates a new instance of MaterialManagerTest */
+	public BetheBlockTest()
+	{}
+
+	public BetheBlockTest(String testName)
+	{
+		super(testName);
+		MaterialManager.instance();
+	}
+
+	public static TestSuite suite()
+	{
+		return new TestSuite(BetheBlockTest.class);
+	}
+
+	public void test_Dummy()
+	{
+		MaterialElement element = new MaterialElement("DummyElement", 1.0, 1.0);
+		Material material = new Material("DummyMaterial", 1, 1.0,
+				org.lcsim.material.MaterialState.SOLID, 1.0, 1.0);
+		material.addElement(element, 1.0);
+
+		double p[] =
+		{ 1.0, 0, 0 };
+		double mass = 1.0;
+				
+		double dEdx = MaterialCalculator.computeBetheBloch(material, // material
+				p, // particle momentum
+				mass, // particle mass
+				1.0, // particle charge
+				1.0); // path length
+
+		printResult(material, "dummy", p, dEdx);
+	}
+
+	/** Test dEdx with muons of various P in Carbon. */
+	public void test_MuonInCarbon()
+	{		
+		Material material = MaterialManager.getMaterials().get("Carbon");
+
+		//System.out.println(material.toString());
+
+		assert (material != null);
+
+		// muon mass in MeV
+		double mass = 105.658369;
+		
+		// 1 GeV
+		double p[] =
+		{ 1.0, 0, 0 };
+
+		runTest("Carbon", "muon", mass, 1.0, p );
+
+		// 10 GeV
+		p[0] = 10.0;
+
+		runTest("Carbon", "muon", mass, 1.0, p );
+
+		// 200 MeV
+		p[0] = 0.2;
+		
+		runTest("Carbon", "muon", mass, 1.0, p );
+		
+		// 100 MeV
+		p[0] = 0.1;
+		
+		runTest("Carbon", "muon", mass, 1.0, p );
+	}
+
+	/** Test dEdx with muons of various P in Carbon. */
+	public void test_MuonInSilicon()
+	{		
+		Material material = MaterialManager.getMaterials().get("Silicon");
+
+		//System.out.println(material.toString());
+
+		assert (material != null);
+
+		// muon mass in MeV
+		double mass = 105.658369;
+
+		// 1 GeV
+		double p[] =
+		{ 1.0, 0, 0 };
+
+		double dEdx = MaterialCalculator.computeBetheBloch(material, // material
+				p, // particle momentum-in GeV
+				mass, // particle mass -MeV/c
+				1.0, // particle charge
+				1.0); // path length ! (cm)
+
+		printResult(material, "muon", p, dEdx);
+
+		// 10 GeV
+		p[0] = 10.0;
+
+		dEdx = MaterialCalculator
+				.computeBetheBloch(material, p, mass, 1.0, 1.0);
+
+		printResult(material, "muon", p, dEdx);
+
+		// 200 MeV
+		p[0] = 0.2;
+
+		dEdx = MaterialCalculator
+				.computeBetheBloch(material, p, mass, 1.0, 1.0);
+
+		printResult(material, "muon", p, dEdx);
+	}
+
+	public void test_PionInCarbon()
+	{
+		// pion mass in MeV
+		double mass = 139.57018;
+
+		// 1 GeV
+		double p[] =
+		{ 1.0, 0, 0 };
+
+		runTest("Carbon", "pion", mass, 1.0, p);
+		
+		// 10 GeV
+		p[0] = 10.0;
+		
+		runTest("Carbon", "pion", mass, 1.0, p);
+		
+		// 200 MeV
+		p[0] = 0.2;
+		
+		runTest("Carbon", "pion", mass, 1.0, p);
+		
+		// 100 MeV
+		p[0] = 0.1;
+		
+		runTest("Carbon", "pion", mass, 1.0, p);
+	}	
+	
+	private double runTest(String materialName, String particle, double mass,
+			double charge, double[] momentum)
+	{
+		Material material = MaterialManager.getMaterials().get(materialName);
+
+		assert (material != null);
+
+		double dEdx = MaterialCalculator.computeBetheBloch(material,
+				momentum, mass, charge, 1.0);
+		
+		printResult(material, particle, momentum, dEdx);
+		
+		return dEdx;
+	}
+
+	/** Print test result, assuming momentum has X component, only. */
+	private static void printResult(Material material, String particle,
+			double p[], double dEdx)
+	{
+		assert (p.length == 3);
+		System.out.println("dEdx="+dEdx);
+		System.out.println('\t' + particle + "; momentum=(" + p[0]
+				+ ", " + p[1] + ", " + p[2] + "); " + material.getName() 
+				);
+	}
+}
\ No newline at end of file
CVSspam 0.2.8