hps-java/src/main/java/org/lcsim/hps/users/phansson
diff -u -r1.1 -r1.2
--- ecalGainAna.java 24 Jul 2012 23:27:19 -0000 1.1
+++ ecalGainAna.java 23 Aug 2012 20:40:58 -0000 1.2
@@ -1,19 +1,10 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.lcsim.hps.users.phansson;
import hep.aida.*;
-import hep.aida.ref.plotter.Plotter;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.*;
-import org.lcsim.util.aida.AIDA;
/**
*
@@ -21,47 +12,36 @@
*/
public class ecalGainAna {
-
// private AIDA aida = AIDA.defaultInstance();
// private IAnalysisFactory af = aida.analysisFactory();
// IHistogramFactory hf = aida.histogramFactory();
// ITree tree = aida.tree();//(ITreeFactory) af.createTreeFactory().create();
-
-
private static void printObjectsInTree(ITree tree) {
System.out.println("-----\nObject names in tree " + tree.name() + ":");
- for( String str : tree.listObjectNames()) {
+ for (String str : tree.listObjectNames()) {
System.out.println(str);
}
System.out.println("-----");
}
-
-
+
private static Options createCommandLineOptions() {
Options option = new Options();
option.addOption("f", true, "Input file");
option.addOption("s", false, "Save to file");
- option.addOption("t", true, "Select the type of analysis to run");
option.addOption("n", true, "Name added to plots");
return option;
}
-
-
-
-
+
/**
* @param args the command line arguments
*/
-
public static void main(String[] args) {
// TODO code application logic here
-
+
IAnalysisFactory af = IAnalysisFactory.create();
- ECalHitMapPlots ecalhtplots = new ECalHitMapPlots();
-
-
-
+
+
Options opts = createCommandLineOptions();
if (args.length == 0) {
System.out.println("ecalGainAna [options]");
@@ -70,41 +50,33 @@
System.exit(1);
}
CommandLineParser parser = new PosixParser();
- CommandLine cmd=null;
+ CommandLine cmd = null;
try {
cmd = parser.parse(opts, args);
} catch (ParseException ex) {
Logger.getLogger(ecalGainAna.class.getName()).log(Level.SEVERE, null, ex);
}
-
-
- int type=0;
- String strType = cmd.getOptionValue("t");
- if(strType==null) {
- System.out.println("using default analysis " + type);
- } else {
- type = Integer.parseInt(strType);
- }
+
boolean savePlots = false;
- if(cmd.hasOption("s")) {
+ if (cmd.hasOption("s")) {
savePlots = true;
}
String outName = "ecalgainplots";
- if(cmd.hasOption("n")) {
+ if (cmd.hasOption("n")) {
outName = cmd.getOptionValue("n");
}
- String fileName = "";
- if(cmd.hasOption("f")) {
+
+ if (cmd.hasOption("f")) {
+ String fileName = "";
fileName = cmd.getOptionValue("f");
System.out.println("File: " + fileName);
+ doPelleAnalysis(af, savePlots, fileName, outName);
}
-
-
-
-
-
- ITree tree=null;
+ }
+
+ private static void doPelleAnalysis(IAnalysisFactory af, boolean savePlots, String fileName, String outName) {
+ ITree tree = null;
try {
tree = af.createTreeFactory().create(fileName);
} catch (IllegalArgumentException ex) {
@@ -113,39 +85,39 @@
Logger.getLogger(ecalGainAna.class.getName()).log(Level.SEVERE, null, ex);
}
//printObjectsInTree(tree);
-
+
IDataPointSetFactory dpsf = af.createDataPointSetFactory(null);
IDataPointSet[] dpsEp = new IDataPointSet[2];
- dpsEp[0] = dpsf.create("dpsEp_t","E/p vs p top",2);
- dpsEp[1] = dpsf.create("dpsEp_b","E/p vs p bot",2);
- double[] ebins = {100,600,800,1000,1300};
- for(int iE=0;iE<=4;++iE) {
- String str = iE==0?"":(" iE="+iE);
+ dpsEp[0] = dpsf.create("dpsEp_t", "E/p vs p top", 2);
+ dpsEp[1] = dpsf.create("dpsEp_b", "E/p vs p bot", 2);
+ double[] ebins = {100, 600, 800, 1000, 1300};
+ for (int iE = 0; iE <= 4; ++iE) {
+ String str = iE == 0 ? "" : (" iE=" + iE);
IPlotter pl = af.createPlotterFactory().create();
- pl.createRegions(1,2,0);
- pl.setTitle("E over p"+str);
+ pl.createRegions(1, 2, 0);
+ pl.setTitle("E over p" + str);
pl.style().statisticsBoxStyle().setVisible(true);
pl.show();
- for(int iside=0;iside<=1;++iside) {
- String side = iside==0?"top":"bottom";
-
+ for (int iside = 0; iside <= 1; ++iside) {
+ String side = iside == 0 ? "top" : "bottom";
+
//String name = "E over p x="+icol+" y="+irow+str;
- String name = "E over p "+side+str;
+ String name = "E over p " + side + str;
IHistogram1D h = (IHistogram1D) tree.find(name);
-
+
pl.region(iside).plot(h);
- pl.region(iside).style().xAxisStyle().setLabel("E over p "+ side);
+ pl.region(iside).style().xAxisStyle().setLabel("E over p " + side);
pl.region(iside).style().yAxisStyle().setLabel("Events");
-
+
dpsEp[iside].addPoint();
dpsEp[iside].point(iE).coordinate(0).setValue(ebins[iE]);
dpsEp[iside].point(iE).coordinate(1).setValue(h.mean());
double err = 0.;//(h.entries()>5||h.rms()>0.0)?h.rms()/Math.sqrt(h.entries()):0;
- System.out.println("N " + h.entries() + " rms " + h.rms() + " err " + h.rms()/Math.sqrt(h.entries()));
- dpsEp[iside].point(iE).coordinate(1).setErrorMinus(err/2);
- dpsEp[iside].point(iE).coordinate(1).setErrorPlus(err/2);
-
-
+ System.out.println("N " + h.entries() + " rms " + h.rms() + " err " + h.rms() / Math.sqrt(h.entries()));
+ dpsEp[iside].point(iE).coordinate(1).setErrorMinus(err / 2);
+ dpsEp[iside].point(iE).coordinate(1).setErrorPlus(err / 2);
+
+
// for(int irow=-5;irow<=5;++irow) {
// for(int icol=-23;icol<=23;++icol) {
// String name;
@@ -159,37 +131,35 @@
// }
// }
}
-
- if(savePlots) {
+
+ if (savePlots) {
try {
- pl.writeToFile(outName+"iE"+iE+".png", "png");
+ pl.writeToFile(outName + "iE" + iE + ".png", "png");
} catch (IOException ex) {
Logger.getLogger(ecalGainAna.class.getName()).log(Level.SEVERE, null, ex);
}
}
-
+
}
-
+
IPlotter plM = af.createPlotterFactory().create();
- plM.createRegions(1,1,0);
+ plM.createRegions(1, 1, 0);
plM.setTitle("<E over p>");
plM.style().statisticsBoxStyle().setVisible(false);
plM.region(0).style().xAxisStyle().setLabel("Track momentum bins");
plM.region(0).style().yAxisStyle().setLabel("Mean E/p");
plM.show();
plM.region(0).plot(dpsEp[0]);
- plM.region(0).plot(dpsEp[1],"mode=overlay");
-
- if(savePlots) {
- try {
- plM.writeToFile(outName+"_mean_vs_p.png", "png");
- } catch (IOException ex) {
- Logger.getLogger(ecalGainAna.class.getName()).log(Level.SEVERE, null, ex);
- }
+ plM.region(0).plot(dpsEp[1], "mode=overlay");
+
+ if (savePlots) {
+ try {
+ plM.writeToFile(outName + "_mean_vs_p.png", "png");
+ } catch (IOException ex) {
+ Logger.getLogger(ecalGainAna.class.getName()).log(Level.SEVERE, null, ex);
}
-
-
-
-
+ }
+
+
}
}
\ No newline at end of file