Author: [log in to unmask] Date: Tue Nov 17 11:36:53 2015 New Revision: 3965 Log: added some of Sebouh's private files and made them public. Added: java/trunk/users/src/main/java/org/hps/users/spaul/StyleUtil.java java/trunk/users/src/main/java/org/hps/users/spaul/SumEverything.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/BinGenerator.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/CustomBinning.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/DisplayHistograms.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/EcalUtil.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/MakeHistograms.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/ShowCustomBinning.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/CountsPerBinVsCharge.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/ExtractCrossSections.java java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/PlotPhiDependence.java Added: java/trunk/users/src/main/java/org/hps/users/spaul/StyleUtil.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/StyleUtil.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/StyleUtil.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,56 @@ +package org.hps.users.spaul; + +import java.util.Arrays; + +import hep.aida.IAnalysisFactory; +import hep.aida.IFunction; +import hep.aida.IPlotterRegion; + +public class StyleUtil { + + public static void stylize(IPlotterRegion r, String title, String lx, String ly, double xmin, double xmax, double ymin, double ymax){ + r.setTitle(title); + stylize(r, lx, ly); + r.setXLimits(xmin, xmax); + r.setYLimits(ymin, ymax); + } + public static void stylize(IPlotterRegion r, String title, String lx, String ly){ + r.setTitle(title); + stylize(r, lx, ly); + } + public static void stylize(IPlotterRegion r, String lx, String ly){ + + r.style().titleStyle().textStyle().setFontSize(22); + r.style().xAxisStyle().setLabel(lx); + r.style().xAxisStyle().labelStyle().setFontSize(16); + r.style().xAxisStyle().tickLabelStyle().setFontSize(14); + r.style().yAxisStyle().setLabel(ly); + r.style().yAxisStyle().labelStyle().setFontSize(16); + r.style().yAxisStyle().tickLabelStyle().setFontSize(14); + r.style().statisticsBoxStyle().setParameter("backgroundColor", "white"); + r.style().statisticsBoxStyle().boxStyle().backgroundStyle().setColor("White"); + r.style().statisticsBoxStyle().boxStyle().backgroundStyle().setParameter("color", "white"); + r.style().statisticsBoxStyle().boxStyle().backgroundStyle().setOpacity(100); + System.out.println(Arrays.toString(r.style().dataStyle().availableParameters())); + r.style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow"); + r.style().dataStyle().fillStyle().setParameter("showZeroHeightBins", "false"); + //r.style().dataStyle().setParameter("showDataInStatisticsBox", "false"); + r.style().setParameter("hist2DStyle", "colorMap"); + //r.style().dataBoxStyle() + } + static void addHorizontalLine(IPlotterRegion r, double y, String name){ + IAnalysisFactory af = IAnalysisFactory.create(); + IFunction f = af.createFunctionFactory(af.createTreeFactory().create()).createFunctionByName(name, "p0"); + f.setParameter("p0", y); + r.plot(f); + } + public static void addParabola(IPlotterRegion region, double p0, + double p1, double p2, String string) { + IAnalysisFactory af = IAnalysisFactory.create(); + IFunction f = af.createFunctionFactory(af.createTreeFactory().create()).createFunctionByName(string, "p2"); + f.setParameter("p0", p0); + f.setParameter("p1", p1); + f.setParameter("p2", p2); + region.plot(f); + } +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/SumEverything.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/SumEverything.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/SumEverything.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,89 @@ +package org.hps.users.spaul; + +import java.io.File; +import java.io.IOException; + +import hep.aida.IAnalysisFactory; +import hep.aida.IHistogram1D; +import hep.aida.IHistogram2D; +import hep.aida.IHistogramFactory; +import hep.aida.ITree; +import hep.aida.ITreeFactory; + +//sums up everything in a folder full of files containing histograms. Pretty convenient. +// or if one arg is given, assume that that one arg is a folder full of folders +// full of aida output files. Then add up all of the histograms in each sub folder, +// and put the sums in separate files in a folder called "sums" +public class SumEverything { + public static void main(String arg[]) throws IllegalArgumentException, IOException{ + if(arg.length > 1){ + twoArg(arg[0], arg[1]); + } + else{ + oneArg(arg[0]); + } + } + static void oneArg(String indir) throws IllegalArgumentException, IOException{ + File outdir = new File(indir + "/sums"); + outdir.mkdir(); + for(File subdirf : new File(indir).listFiles()){ + String subdir = subdirf.getAbsolutePath(); + if(subdir.matches(".*/sums/?")) + continue; + String split[] = subdir.split("/"); + String outfile = indir + "/sums/" + split[split.length-1] + ".aida"; + twoArg(subdir, outfile); + } + new File(indir + "/sums/total.aida").delete(); + twoArg(outdir.getAbsolutePath(), indir + "/sums/total.aida"); + + } + + static void twoArg(String indir, String out) throws IllegalArgumentException, IOException{ + IAnalysisFactory af = IAnalysisFactory.create(); + ITreeFactory tf = af.createTreeFactory(); + new File(out).delete(); + ITree tree0 = tf.create(out, "xml", false, true); + IHistogramFactory hf = af.createHistogramFactory(tree0); + + + int j = 0; + for(File s : new File(indir).listFiles()){ + ITree tree = af.createTreeFactory().create(s.getAbsolutePath(),"xml"); + + + if(j == 0){ + String [] names = tree.listObjectNames(); + tree0.mount("/tmp", tree, "/"); + for(String name : names){ + Object o = tree.find(name); + if(o instanceof IHistogram1D || o instanceof IHistogram2D) + tree0.cp("/tmp/" + name, name); + } + tree0.unmount("/tmp"); + tree.close(); + + } + else{ + //tree. + String [] names = tree.listObjectNames(); + tree0.mount("/tmp", tree, "/"); + for(String name : names){ + Object o = tree.find(name); + if(o instanceof IHistogram1D) + ((IHistogram1D)tree0.find(name)).add((IHistogram1D)o); + if(o instanceof IHistogram2D) + ((IHistogram2D)tree0.find(name)).add((IHistogram2D)o); + } + tree0.unmount("/tmp"); + tree.close(); + } + + tree.close(); + j++; + System.out.println(j + " files have been read"); + } + tree0.commit(); + } +} + Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/BinGenerator.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/BinGenerator.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/BinGenerator.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,80 @@ +package org.hps.users.spaul.feecc; + +import java.io.FileNotFoundException; +import java.io.PrintStream; +import java.io.PrintWriter; + +public class BinGenerator { + public static void main(String arg[]) throws FileNotFoundException{ + int nBins = 20; + + PrintStream pw = new PrintStream("generatedbins.txt"); + pw.println(nBins); + double[] thetaBins = getThetaBins(nBins); + for(int i = 0; i< nBins; i++){ + double thetaMin = thetaBins[i]; + double thetaMax = thetaBins[i+1]; + double phiBounds[] = getPhiBounds(thetaMin, thetaMax); + pw.printf("%d %.4f %.4f ", phiBounds.length/2, thetaMin, thetaMax); + for(int j = 0; j< phiBounds.length; j++){ + pw.printf("%.4f ", phiBounds[j]); + } + pw.println(); + } + ShowCustomBinning.main(new String[]{"generatedbins.txt"}); + + } + + private static double[] getThetaBins(int nBins){ + /*double thetaMin = 0.035; + double dTheta = .2/nBins; + double[] bins = new double[nBins +1]; + for(int i = 0; i< nBins+1; i++){ + bins[i] = thetaMin+dTheta*i; + } + return bins; */ + double thetaMax = .145; + double thetaMin = .035; + + double[] bins = new double[nBins +1]; + double xMin = 1/(thetaMax*thetaMax); + double xMax = 1/(thetaMin*thetaMin); + for(int i = 0; i< nBins+1; i++){ + double x = xMax - i*(xMax-xMin)/nBins; + bins[i] = Math.pow(x, -.5); + } + return bins; + } + private static double[] getPhiBounds(double thetaMin, double thetaMax){ + double phiBins[] = new double[6]; + double dphi = .01; + int edgeNumber = 0; + + boolean prevInRange = false; + for(double phi = 0; phi< 3.14; phi+= dphi){ + boolean inRange = EcalUtil.fid_ECal_spherical(thetaMin, phi) && EcalUtil.fid_ECal_spherical(thetaMax, phi) + && EcalUtil.fid_ECal_spherical(thetaMin, -phi) && EcalUtil.fid_ECal_spherical(thetaMax, -phi); + if(inRange && !prevInRange) + phiBins[edgeNumber++] = phi; + if(prevInRange && !inRange) + phiBins[edgeNumber++] = phi-dphi; + prevInRange = inRange; + } + if(phiBins[2] == 0) + return new double[]{phiBins[0], phiBins[1]}; + if(phiBins[4] == 0) + return new double[]{phiBins[0], phiBins[1],phiBins[2], phiBins[3]}; + + //3 segments: choose the largest two + if(phiBins[4] != 0 && phiBins[1] - phiBins[0] > phiBins[3]-phiBins[2] && phiBins[5] - phiBins[4] > phiBins[3]-phiBins[2]){ + return new double[]{phiBins[0], phiBins[1],phiBins[4], phiBins[5]}; + } + if(phiBins[4] != 0 && phiBins[3] - phiBins[2] > phiBins[1]-phiBins[0] && phiBins[5] - phiBins[4] > phiBins[1]-phiBins[0]){ + return new double[]{phiBins[2], phiBins[3],phiBins[4], phiBins[5]}; + } + return new double[]{phiBins[0], phiBins[1],phiBins[2], phiBins[3]}; + + + } + +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/CustomBinning.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/CustomBinning.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/CustomBinning.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,96 @@ +package org.hps.users.spaul.feecc; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class CustomBinning { + public CustomBinning(File f) throws FileNotFoundException{ + Scanner s = new Scanner(f); + + nTheta = s.nextInt(); //number of bins in theta; + thetaMax = new double[nTheta]; + thetaMin = new double[nTheta]; + + phiMax = new double[nTheta][]; + phiMin = new double[nTheta][]; + int i = 0; + while(s.hasNext()){ //new row + int nPhi = s.nextInt(); + thetaMin[i] = s.nextDouble(); + thetaMax[i] = s.nextDouble(); + + phiMax[i] = new double[nPhi]; + phiMin[i] = new double[nPhi]; + for(int j = 0; j<nPhi; j++){ + phiMin[i][j] = s.nextDouble(); + phiMax[i][j] = s.nextDouble(); + } + i++; + } + } + double[][] phiMax; + double[][] phiMin; + public double thetaMax[], thetaMin[]; + public int nTheta; + + double getSteradians(int binNumber){ + double t1 = thetaMin[binNumber]; + double t2 = thetaMax[binNumber]; + double dCos = Math.cos(t1)-Math.cos(t2); + double dPhiTot = 0; + for(int i = 0; i< phiMax[binNumber].length; i++){ + dPhiTot += phiMax[binNumber][i]-phiMin[binNumber][i]; + } + return 2*dPhiTot*dCos; //factor of two because top and bottom + } + boolean inRange(double theta, double phi){ + phi = Math.abs(phi); + /*int i =(int) Math.floor((theta-theta0)/deltaTheta); + if(i>= nTheta || i<0) + return false;*/ + if(theta > thetaMax[nTheta-1] || theta < thetaMin[0]) + return false; + int i; + boolean found = false; + for(i = 0; i< nTheta; i++){ + if(theta > thetaMin[i] && theta < thetaMax[i]){ + found = true; + break; + } + } + if(!found) + return false; + + for(int j = 0; j<phiMax[i].length; j++){ + if(phi>phiMin[i][j] && phi< phiMax[i][j]) + return true; + } + return false; + + } + public double getTotSteradians() { + double tot = 0; + for(int i = 0; i<nTheta; i++){ + tot += getSteradians(i); + } + return tot; + } + /** + * @param bin + * @param a = 2E/M + * @return the integral of 1/sin^4(th/2)*cos^2(th/2)/(1+a*sin^2(th/2)) times dPhi, + * which appears in the integral of mott scattering. + */ + public double mottIntegralFactor(double a, int bin){ + double dPhi = 0; + for(int i = 0; i< phiMax[bin].length; i++) + dPhi += 2*(phiMax[bin][0] - phiMin[bin][0]); //factor of 2 from top and bottom + + double csc2 = Math.pow(Math.sin(thetaMax[bin]/2), -2); + double Imax = (-csc2+(1+a)*Math.log(a+2*csc2)); + csc2 = Math.pow(Math.sin(thetaMin[bin]/2), -2); + double Imin = (-csc2+(1+a)*Math.log(a+2*csc2)); + return 2*dPhi*(Imax-Imin); + } +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/DisplayHistograms.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/DisplayHistograms.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/DisplayHistograms.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,9 @@ +package org.hps.users.spaul.feecc; + +import java.io.IOException; + +public class DisplayHistograms { + public static void main(String arg[]) throws IllegalArgumentException, IOException{ + MakeHistograms.main(new String[]{arg[0]}); + } +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/EcalUtil.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/EcalUtil.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/EcalUtil.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,164 @@ +package org.hps.users.spaul.feecc; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + + +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.Cluster; + +public class EcalUtil { + /** + * Holly's algorithm. + * @param x x position of cluster + * @param y y position of cluster + * @param e energy of cluster + * @param pid type of particle (11 = electron; -1 = positron) + * @return array of doubles + * <br> [0] theta = atan(py/pz) + * <br> [1] phi = atan(px/pz) + */ + static double [] toHollysCoordinates(double x, double y, double e, int pid){ + if(pid == 11){ + return new double[]{0.00071 * y +0.000357, 0.00071*x + 0.00003055*e + 0.04572/e +0.0006196}; + } else if(pid == -11){ + return new double[]{0.00071 * y +0.000357, 0.00071*x - 0.0006465*e + 0.045757/e +0.003465}; + } + return null; + } + + static double getSteradians(double x, double y, double e,int pid, double dA){ + double thetaPhi[] = toHollysCoordinates(x, y, e, pid); + return .00071*.00071*dA/Math.sqrt(thetaPhi[0]*thetaPhi[0]+ thetaPhi[1]*thetaPhi[1]+1); + } + + static boolean isSeedEdge(Cluster c){ + CalorimeterHit seedhit = (CalorimeterHit)c.getCalorimeterHits().get(0); + // seedhit + int ix = seedhit.getIdentifierFieldValue("ix"); + int iy = seedhit.getIdentifierFieldValue("iy"); + + //seedhit.get + return isEdge(ix, iy); + } + static boolean isEdge(int ix, int iy){ + if(iy == 5 || iy == 1 || iy == -1 || iy == -5) + return true; + if(ix == -23 || ix == 23) + return true; + if((iy == 2 || iy == -2) && (ix >=-11 && ix <= -1)) + return true; + return false; + } + public static boolean fid_ECal(Cluster c){ + return fid_ECal(c.getPosition()[0], c.getPosition()[1]); + } + public static boolean fid_ECal(double x, double y) + { + y = Math.abs(y); + + boolean in_fid = false; + double x_edge_low = -262.74; + double x_edge_high = 347.7; + double y_edge_low = 33.54; + double y_edge_high = 75.18; + + double x_gap_low = -106.66; + double x_gap_high = 42.17; + double y_gap_high = 47.18; + + y = Math.abs(y); + + if( x > x_edge_low && x < x_edge_high && y > y_edge_low && y < y_edge_high ) + { + if( !(x > x_gap_low && x < x_gap_high && y > y_edge_low && y < y_gap_high) ) + { + in_fid = true; + } + } + + return in_fid; + } + static double[] toSphericalFromBeam(double pxpz, double pypz){ + double x = pxpz, y = pypz, z = 1; + double beamTilt = .03057; + double xtemp = Math.cos(beamTilt)*x - Math.sin(beamTilt)*z; + double ztemp = Math.cos(beamTilt)*z + Math.sin(beamTilt)*x; + double ytemp = y; + + double theta = Math.atan(Math.hypot(xtemp, ytemp)/ ztemp); + double phi = Math.atan2(ytemp, xtemp); + + + return new double[]{theta, phi}; + } + static Map<Integer, double[]> map = new HashMap(); + static void readMap() throws FileNotFoundException{ + Scanner s = new Scanner(new File("ecal_positions.txt")); + + + while(s.hasNext()){ + int ix =s.nextInt(); + int iy = s.nextInt(); + double x = s.nextDouble(); + double y =s.nextDouble(); + map.put(ix+100*iy, new double[]{x, y}); + + } + s.close(); + } + static double getArea(int ix, int iy){ + int ixp = ix+1; + if(ixp == 0) + ixp = 1; + int ixm = ix-1; + if(ixm == 0) + ixm = -1; + double[] plus = map.get(ixp+100*(iy+1)); + double[] minus = map.get(ixm+100*(iy-1)); + return (plus[0]-minus[0])*(plus[1]-minus[1])/4; + } + + public static double[] getThetaPhiSpherical(double x,double y){ + double hcoord[] = toHollysCoordinates(x,y, 1.056, 11); + return toSphericalFromBeam(Math.tan(hcoord[1]),Math.tan(hcoord[0])); + } + /*beam tilt*/ + static double tilt = .03057; + //assuming FEE electron. + + public static double[] getXY(double theta, double phi){ + + double ux = Math.cos(phi)*Math.sin(theta)*Math.cos(tilt)+Math.cos(theta)*Math.sin(tilt); + double uy = Math.sin(phi)*Math.sin(theta); + double uz = Math.cos(theta)*Math.cos(tilt)-Math.cos(phi)*Math.sin(theta)*Math.sin(tilt); + double pxpz = ux/uz; + double pypz = uy/uz; + //holly's coordinates: + double h1 = Math.atan(pypz); + double h2 = Math.atan(pxpz); + //0.00071 * y +0.000357, + //0.00071*x + 0.00003055*e + 0.04572/e +0.0006196 + double y = (h1-0.000357)/0.00071; + double e = 1.056; + double x = (h2 - 0.00003055*e - 0.04572/e -0.0006196)/0.00071; + return new double[]{x,y}; + } + public static boolean fid_ECal_spherical(double theta, double phi){ + double[] xy = getXY(theta, phi); + double x = xy[0]; + double y = xy[1]; + return fid_ECal(x, y); + } + public static void main(String arg[]){ + double x = 0, y = 0; + double sp[] = getThetaPhiSpherical(x,y); + System.out.println(Arrays.toString(getXY(sp[0], sp[1]))); + } +} + + Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/MakeHistograms.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/MakeHistograms.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/MakeHistograms.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,260 @@ +package org.hps.users.spaul.feecc; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import org.hps.conditions.ConditionsDriver; +import org.hps.record.triggerbank.AbstractIntData; +import org.hps.record.triggerbank.TIData; +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.Cluster; +import org.lcsim.event.EventHeader; +import org.lcsim.event.GenericObject; +import org.lcsim.event.ReconstructedParticle; +import org.lcsim.lcio.LCIOReader; + +import hep.aida.IAnalysisFactory; +import hep.aida.IHistogram1D; +import hep.aida.IHistogram2D; +import hep.aida.IHistogramFactory; +import hep.aida.IPlotter; +import hep.aida.IPlotterFactory; +import hep.aida.ITree; +import hep.aida.ITreeFactory; +import hep.physics.vec.Hep3Vector; +import org.hps.users.spaul.StyleUtil; + +public class MakeHistograms { + static boolean display = false; + static CustomBinning cb; + public static void main(String arg[]) throws IllegalArgumentException, IOException{ + if(arg.length == 1){ + File file = new File(arg[0]); + String path = arg[0]; + if(file.isDirectory()){ + org.hps.users.spaul.SumEverything.main(new String[]{path, "temp.aida"}); + path = "temp.aida"; + } + IAnalysisFactory af = IAnalysisFactory.create(); + ITreeFactory tf = af.createTreeFactory(); + ITree tree0 = tf.create(path, "xml"); + extractHistograms(tree0); + setupPlotter(af); + + } else{ + + String input = arg[0]; + String output = arg[1]; + cb = new CustomBinning(new File(arg[2])); + if(arg.length == 5) + display = true; + IAnalysisFactory af = IAnalysisFactory.create(); + ITree tree = af.createTreeFactory().create(output,"xml",false,true); + IHistogramFactory hf = af.createHistogramFactory(tree); + setupHistograms(hf); + if(display){ + setupPlotter(af); + } + ConditionsDriver hack = new ConditionsDriver(); + //hack.setXmlConfigResource("/u/group/hps/hps_soft/detector-data/detectors/HPS-EngRun2015-Nominal-v3"); + hack.setDetectorName("HPS-EngRun2015-Nominal-v3"); + hack.setFreeze(true); + hack.setRunNumber(Integer.parseInt(arg[3])); + hack.initialize(); + LCIOReader reader = new LCIOReader(new File(input)); + //reader.open(input); + //reader. + EventHeader event = reader.read(); + int nEvents = 0; + try{ + outer : while(event != null){ + processEvent(event); + + //System.out.println(Q2); + + event = reader.read(); + } + } catch (Exception e){ + e.printStackTrace(); + } + tree.commit(); + tree.close(); + } + + } + + static IHistogram2D h1, h2, h2a, h2b, h2c; + static IHistogram2D h4,h4a; + static IHistogram1D h3, h3a; + static IHistogram1D h5, h6; + + private static void extractHistograms(ITree tree0) { + h2 = (IHistogram2D) tree0.find("theta vs phi"); + h2a = (IHistogram2D) tree0.find("theta vs phi cut"); + h2b = (IHistogram2D) tree0.find("theta vs phi cut alt"); + h2c = (IHistogram2D) tree0.find("theta vs phi alt"); + + h3 = (IHistogram1D) tree0.find("theta"); + h4 = (IHistogram2D) tree0.find("px\\/pz vs py\\/pz"); + h4a = (IHistogram2D) tree0.find("px\\/pz vs py\\/pz cut"); + h5 = (IHistogram1D) tree0.find("energy"); + + } + static void setupHistograms(IHistogramFactory hf){ + //h1 = hf.createHistogram2D("px\\/pz vs py\\/pz", 160, -.16, .24, 160, -.2, .2); + + + + + h2 = hf.createHistogram2D("theta vs phi", 300, 0, .3, 314, -3.14, 3.14); + + h2a = hf.createHistogram2D("theta vs phi cut", 300, 0, .3, 314, -3.14, 3.14); + + double thetaBins[] = new double[cb.nTheta+1]; + for(int i = 0; i<cb.nTheta; i++){ + thetaBins[i] = cb.thetaMin[i]; + } + + thetaBins[thetaBins.length-1] = cb.thetaMax[cb.nTheta-1]; + + double phiBins[] = new double[315]; + for(int i = 0; i<315; i++){ + phiBins[i] = i/50.-3.14; //every 10 mrad; + } + + //identical to h2a, except different binning + h2b = hf.createHistogram2D("theta vs phi cut alt", "theta vs phi cut alt", thetaBins, phiBins); + h2c = hf.createHistogram2D("theta vs phi alt", "theta vs phi alt", thetaBins, phiBins); + + h3 = hf.createHistogram1D("theta", "theta", thetaBins); + + h4 = hf.createHistogram2D("px\\/pz vs py\\/pz", 160, -.16, .24, 160, -.2, .2); + h4a = hf.createHistogram2D("px\\/pz vs py\\/pz cut", 160, -.16, .24, 160, -.2, .2); + + h5 = hf.createHistogram1D("energy", 75, 0, 1.5); + } + static void setupPlotter(IAnalysisFactory af){ + IPlotterFactory pf = af.createPlotterFactory(); + IPlotter p = pf.create(); + p.createRegions(2,2); + p.region(0).plot(h2); + + StyleUtil.stylize(p.region(0), "theta", "phi"); + p.region(1).plot(h2a); + StyleUtil.stylize(p.region(1), "theta", "phi"); + p.region(2).plot(h3); + StyleUtil.stylize(p.region(2), "theta", "# of particles"); + p.region(3).plot(h5); + StyleUtil.stylize(p.region(3), "energy", "# of particles"); + + p.show(); + //new window for the next plot + IPlotter p2 = pf.create(); + p2.region(0).plot(h2b); + StyleUtil.stylize(p2.region(0), "theta", "phi"); + + p2.show(); + + //new window for the next plot + IPlotter p3 = pf.create(); + p3.region(0).plot(h2c); + StyleUtil.stylize(p3.region(0), "theta", "phi"); + + p3.show(); + + //new window for the next plot + IPlotter p4 = pf.create(); + p4.region(0).plot(h4); + StyleUtil.stylize(p4.region(0), "px/pz", "py/pz"); + + p4.show(); + + //new window for the next plot + IPlotter p5 = pf.create(); + p5.region(0).plot(h4a); + StyleUtil.stylize(p5.region(0), "px/pz", "py/pz"); + + p5.show(); + } + private static void processEvent(EventHeader event) { + if(event.getEventNumber() %1000 == 0) + System.out.println("event number " + event.getEventNumber()); + + for (GenericObject gob : event.get(GenericObject.class,"TriggerBank")) + { + if (!(AbstractIntData.getTag(gob) == TIData.BANK_TAG)) continue; + TIData tid = new TIData(gob); + if (!tid.isSingle1Trigger()) + { + return; + } + } + List<ReconstructedParticle> particles = event.get(ReconstructedParticle.class, "FinalStateParticles"); + + for(ReconstructedParticle p : particles){ + + boolean isGood = addParticle(p); + + + } + } + + static double eMin = .8; + static double eMax = 1.2; + static double beamEnergy = 1.057; + + static double beamTilt = .03057; + static double maxChi2 = 50; + static boolean addParticle(ReconstructedParticle part){ + + if(part.getTracks().size() == 0) + return false; + if(part.getTracks().get(0).getChi2()>maxChi2){ + return false; + } + if(part.getClusters().size() == 0) + return false; + Cluster c = part.getClusters().get(0); + double time = c.getCalorimeterHits().get(0).getTime(); + if(EcalUtil.fid_ECal(c)){ + if(c.getCalorimeterHits().size() < 3) + return false; + if(time>40 && time <48) + h5.fill(c.getEnergy()); + if(c.getEnergy() > eMin && c.getEnergy() < eMax && (time >40 && time < 48)) { + + Hep3Vector p = part.getMomentum(); + + double px = p.x(), pz = p.z(); + double pxtilt = px*Math.cos(beamTilt)-pz*Math.sin(beamTilt); + double py = p.y(); + double pztilt = pz*Math.cos(beamTilt)+px*Math.sin(beamTilt); + + double theta = Math.atan(Math.hypot(pxtilt, py)/pztilt); + double phi =Math.atan2(py, pxtilt); + + h2.fill(theta, phi); + h2c.fill(theta, phi); + + h4.fill(px/pz, py/pz); + + if(cb.inRange(theta, phi)){ + h2a.fill(theta, phi); + h2b.fill(theta, phi); + h3.fill(theta); + h4a.fill(px/pz, py/pz); + } + + + return true; + } + + } + return false; + } + +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/ShowCustomBinning.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/ShowCustomBinning.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/ShowCustomBinning.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,218 @@ +package org.hps.users.spaul.feecc; + +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Graphics; +import java.io.File; +import java.io.FileNotFoundException; + +import javax.swing.JFrame; + +import hep.aida.IAnalysisFactory; +import hep.aida.ICloud2D; +import hep.aida.IHistogramFactory; +import hep.aida.IPlotter; +import hep.aida.IPlotterFactory; +import hep.aida.IPlotterRegion; +import hep.aida.IPlotterStyle; +import hep.aida.ITreeFactory; + +public class ShowCustomBinning extends Canvas{ + /** + * show Rafo's fiducial cuts translated into rotated theta and phi, + * and overlay this with my bins in x and y. + * @param arg + * @throws FileNotFoundException + */ + public static void main(String arg[]) throws FileNotFoundException{ + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new ShowCustomBinning(new File(arg[0]))); + frame.setSize(800, 800); + frame.setVisible(true); + + } + public void paint(Graphics g){ + drawEcalOutline(g); + drawFidEcalOutline(g); + drawCustomBinRectangles(g); + } + + void drawFidEcalOutline(Graphics g){ + g.setColor(Color.GRAY); + double x_edge_low = -262.74; + double x_edge_high = 347.7; + double y_edge_low = 33.54; + double y_edge_high = 75.18; + + double x_gap_low = -106.66; + double x_gap_high = 42.17; + double y_gap_high = 47.18; + double x1,y1, x2, y2; + double nPoints = 500; + for(int i = 0; i< nPoints-1; i++){ + x1 = x_gap_high+i/nPoints*(x_edge_high-x_gap_high); + x2 = x_gap_high+(i+1)/nPoints*(x_edge_high-x_gap_high); + y1 = y_edge_low; + y2 = y1; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + + + x1 = x_edge_low+i/nPoints*(x_gap_low-x_edge_low); + x2 = x_edge_low+(i+1)/nPoints*(x_gap_low-x_edge_low); + y1 = y2 = y_edge_low; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + + + + x1 = x_gap_low+i/nPoints*(x_gap_high-x_gap_low); + x2 = x_gap_low+(i+1)/nPoints*(x_gap_high-x_gap_low); + y1 = y2 = y_gap_high; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + + x1 = x_edge_low+i/nPoints*(x_edge_high-x_edge_low); + x2 = x_edge_low+(i+1)/nPoints*(x_edge_high-x_edge_low); + y1 = y2 = y_edge_high; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + } + drawEcalFaceLine(g, x_gap_low, y_edge_low, x_gap_low, y_gap_high); + drawEcalFaceLine(g, x_gap_high, y_edge_low, x_gap_high, y_gap_high); + + drawEcalFaceLine(g, x_edge_low, y_edge_low, x_edge_low, y_edge_high); + drawEcalFaceLine(g, x_edge_high, y_edge_low, x_edge_high, y_edge_high); + + + drawEcalFaceLine(g, x_gap_low, -y_edge_low, x_gap_low, -y_gap_high); + drawEcalFaceLine(g, x_gap_high, -y_edge_low, x_gap_high, -y_gap_high); + + drawEcalFaceLine(g, x_edge_low, -y_edge_low, x_edge_low, -y_edge_high); + drawEcalFaceLine(g, x_edge_high, -y_edge_low, x_edge_high, -y_edge_high); + + } + + void drawEcalOutline(Graphics g){ + g.setColor(Color.BLACK); + double x_edge_low = -276.50; + double x_edge_high = 361.55; + double y_edge_low = 20.17; + double y_edge_high = 89; + + double x_gap_low = -93.30; + double x_gap_high = 28.93; + double y_gap_high = 33.12; + double x1,y1, x2, y2; + double nPoints = 500; + for(int i = 0; i< nPoints-1; i++){ + x1 = x_gap_high+i/nPoints*(x_edge_high-x_gap_high); + x2 = x_gap_high+(i+1)/nPoints*(x_edge_high-x_gap_high); + y1 = y_edge_low; + y2 = y1; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + + + x1 = x_edge_low+i/nPoints*(x_gap_low-x_edge_low); + x2 = x_edge_low+(i+1)/nPoints*(x_gap_low-x_edge_low); + y1 = y2 = y_edge_low; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + + + + x1 = x_gap_low+i/nPoints*(x_gap_high-x_gap_low); + x2 = x_gap_low+(i+1)/nPoints*(x_gap_high-x_gap_low); + y1 = y2 = y_gap_high; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + + x1 = x_edge_low+i/nPoints*(x_edge_high-x_edge_low); + x2 = x_edge_low+(i+1)/nPoints*(x_edge_high-x_edge_low); + y1 = y2 = y_edge_high; + drawEcalFaceLine(g, x1, y1, x2, y2); + drawEcalFaceLine(g, x1, -y1, x2, -y2); + } + drawEcalFaceLine(g, x_gap_low, y_edge_low, x_gap_low, y_gap_high); + drawEcalFaceLine(g, x_gap_high, y_edge_low, x_gap_high, y_gap_high); + + drawEcalFaceLine(g, x_edge_low, y_edge_low, x_edge_low, y_edge_high); + drawEcalFaceLine(g, x_edge_high, y_edge_low, x_edge_high, y_edge_high); + + + drawEcalFaceLine(g, x_gap_low, -y_edge_low, x_gap_low, -y_gap_high); + drawEcalFaceLine(g, x_gap_high, -y_edge_low, x_gap_high, -y_gap_high); + + drawEcalFaceLine(g, x_edge_low, -y_edge_low, x_edge_low, -y_edge_high); + drawEcalFaceLine(g, x_edge_high, -y_edge_low, x_edge_high, -y_edge_high); + } + + CustomBinning binning; + + ShowCustomBinning(File file) throws FileNotFoundException{ + this.binning = new CustomBinning(file); + print(this.binning); + } + Color altBin1 = new Color(0, 0, 128); + Color altBin2 = new Color(0,128,0); + void drawCustomBinRectangles(Graphics g){ + for(int i = 0; i<binning.nTheta; i++){ + g.setColor(i%2 == 0 ? altBin1 : altBin2); + for(int j = 0; j<binning.phiMax[i].length; j++){ + double phi1 = binning.phiMax[i][j]; + double phi2 = binning.phiMin[i][j]; + double theta1 = binning.thetaMin[i]; + double theta2 = binning.thetaMax[i]; + + int x =getX(theta1)+1, y = getY(phi1), w = getX(theta2)-getX(theta1), h = getY(phi2)-getY(phi1); + g.drawRect(x, y, w, h); + x =getX(theta1)+1; y = getY(-phi2); w = getX(theta2)-getX(theta1); h = getY(-phi1)-getY(-phi2); + + g.drawRect(x, y, w, h); + + + } + } + } + + + void drawEcalFaceLine(Graphics g, double x1, double y1, double x2, double y2){ + + double[] polar1 = EcalUtil.getThetaPhiSpherical(x1, y1); + double[] polar2 = EcalUtil.getThetaPhiSpherical(x2, y2); + g.drawLine(getX(polar1[0]), getY(polar1[1]), getX(polar2[0]), getY(polar2[1])); + + } + int getX(double theta){ + return (int)(this.getWidth()*theta/.3); + } + int getY(double phi){ + return (int)(this.getHeight()*(3.2-phi)/6.4); + } + static void print(CustomBinning binning){ + System.out.println(" Bin \\# & $\\theta_{\\textrm{min}}$ & $\\theta_{\\textrm{max}}$ & $\\phi_{\\textrm{min 1}}$ & $\\phi_{\\textrm{max 1}}$ & $\\phi_{\\textrm{min 2}}$ & $\\phi_{\\textrm{max 2}}$ & Solid angle \\\\"); + for(int i = 0; i<binning.nTheta; i++){ + if(binning.phiMax[i].length == 1) + System.out.printf("%d & %.0f & %.0f & %.0f & %.0f & -- & -- & %.0f \\\\\n", + i+1, + binning.thetaMin[i]*1000, + binning.thetaMax[i]*1000, + binning.phiMin[i][0]*1000, + binning.phiMax[i][0]*1000., + binning.getSteradians(i)*1e6); + if(binning.phiMax[i].length == 2) + System.out.printf("%d & %.0f & %.0f & %.0f & %.0f & %.0f & %.0f & %.0f \\\\\n", + i+1, + binning.thetaMin[i]*1000, + binning.thetaMax[i]*1000, + binning.phiMin[i][0]*1000, + binning.phiMax[i][0]*1000, + binning.phiMin[i][1]*1000, + binning.phiMax[i][1]*1000, + binning.getSteradians(i)*1e6); + } + System.out.println("total " + binning.getTotSteradians()*1e6 + " microsteradians"); + } +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/CountsPerBinVsCharge.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/CountsPerBinVsCharge.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/CountsPerBinVsCharge.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,42 @@ +package org.hps.users.spaul.feecc.analysis; + +import hep.aida.*; +import org.hps.users.spaul.feecc.CustomBinning; + +import java.io.File; +import java.io.IOException; + +//arg[0] should point to the sums directory, +// with files that are named runnum.aida and one file total.aida +//arg[1] is the binning scheme file. +//arg[2] is an overall normalization scale (2E/Zalpha)*sqrt(cc/counts) +//arg[3] is recoil parameter (2E/M) +public class CountsPerBinVsCharge { + public static void main(String arg[]) throws IllegalArgumentException, IOException{ + IAnalysisFactory af = IAnalysisFactory.create(); + ITreeFactory tf = af.createTreeFactory(); + CustomBinning cb = new CustomBinning(new File(arg[1])); + double scale = Double.parseDouble(arg[2]); + double recoil = Double.parseDouble(arg[3]); + + ITree tree0 = tf.create(arg[0], "xml"); + IHistogram1D hist = (IHistogram1D) tree0.find("theta"); + + int nBins = hist.axis().bins(); + for(int i = 0; i< nBins; i++){ + double thmax = cb.thetaMax[i]; + double thmin = cb.thetaMin[i]; + double n = hist.binHeight(i); + double mottInt = cb.mottIntegralFactor(recoil, i); + double F = scale*Math.sqrt(n/mottInt); + double dF = scale/(2*Math.sqrt(mottInt)); + System.out.println(i + "\t" + thmin+ "\t" + thmax + "\t" + F + "\t" + dF); + } + + } + + private static double getBeamCharge(int runNumber) { + //placeholder until we have the beam charges reliably in the database. + return 1; + } +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/ExtractCrossSections.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/ExtractCrossSections.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/ExtractCrossSections.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,43 @@ +package org.hps.users.spaul.feecc.analysis; + +import hep.aida.*; + +import java.io.File; +import java.io.IOException; + +//arg[0] should point to the sums directory, +// with files that are named runnum.aida and one file total.aida +public class ExtractCrossSections { + public static void main(String arg[]) throws IllegalArgumentException, IOException{ + IAnalysisFactory af = IAnalysisFactory.create(); + ITreeFactory tf = af.createTreeFactory(); + + boolean isFirst = true; + int nBins =0; + for(File f : new File(arg[0]).listFiles()){ + String[] split = f.getAbsolutePath().split("[\\./]"); + String a = split[split.length-2]; + if(a.equals("total")) + continue; + int runNumber = Integer.parseInt(a); + + ITree tree0 = tf.create(f.getAbsolutePath(), "xml"); + IHistogram1D theta = (IHistogram1D) tree0.find("theta"); + + if(isFirst){ + nBins = theta.axis().bins(); + isFirst = false; + } + double beamCharge = getBeamCharge(runNumber); + System.out.println(runNumber + "\t"); + for(int i = 0; i< nBins; i++) + System.out.print(theta.binHeight(i)/beamCharge + "\t"); + System.out.println(); + } + } + + private static double getBeamCharge(int runNumber) { + //placeholder until we have the beam charges reliably in the database. + return 1; + } +} Added: java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/PlotPhiDependence.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/PlotPhiDependence.java (added) +++ java/trunk/users/src/main/java/org/hps/users/spaul/feecc/analysis/PlotPhiDependence.java Tue Nov 17 11:36:53 2015 @@ -0,0 +1,40 @@ +package org.hps.users.spaul.feecc.analysis; + +import hep.aida.*; + +import org.hps.users.spaul.feecc.CustomBinning; +import org.hps.users.spaul.StyleUtil; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +//arg[0] should point to the sums directory, +// with files that are named runnum.aida and one file total.aida +public class PlotPhiDependence { + public static void main(String arg[]) throws IllegalArgumentException, IOException{ + IAnalysisFactory af = IAnalysisFactory.create(); + ITreeFactory tf = af.createTreeFactory(); + IHistogramFactory hf = af.createHistogramFactory(tf.create()); + + ITree tree0 = tf.create(arg[0], "xml"); + IHistogram2D hist = (IHistogram2D) tree0.find("theta vs phi alt"); + + int nBinsTheta = hist.xAxis().bins(); + + for(int i = 0; i< nBinsTheta; i++){ + IPlotter p = af.createPlotterFactory().create(); + IHistogram1D proj = hf.sliceY("bin " + i, hist, i); + p.region(0).plot(proj); + StyleUtil.stylize(p.region(0),"Phi Dependence", "phi", "# of hits"); + System.out.println(Arrays.toString(p.region(0).style().dataStyle().markerStyle().availableParameters())); + p.region(0).style().dataStyle().setParameter("showHistogramBars", "false"); + + p.show(); + } + + } + + + + +}