Commit in hps-java/src/main/java/org/lcsim/hps/users/phansson on MAIN | |||
ecalGainAna.java | +121 | -5 | 1.2 -> 1.3 |
gain cal with AIDA trees as input
diff -u -r1.2 -r1.3 --- ecalGainAna.java 23 Aug 2012 20:40:58 -0000 1.2 +++ ecalGainAna.java 23 Aug 2012 22:54:08 -0000 1.3 @@ -2,9 +2,12 @@
import hep.aida.*; import java.io.IOException;
+import java.io.PrintStream;
import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.cli.*;
+import org.lcsim.geometry.util.DetectorLocator; +import org.lcsim.hps.recon.ecal.HPSEcalConditions;
/** *
@@ -57,22 +60,135 @@
Logger.getLogger(ecalGainAna.class.getName()).log(Level.SEVERE, null, ex); }
- - boolean savePlots = false; - if (cmd.hasOption("s")) { - savePlots = true; - }
String outName = "ecalgainplots"; if (cmd.hasOption("n")) { outName = cmd.getOptionValue("n"); } if (cmd.hasOption("f")) {
+ boolean savePlots = false; + if (cmd.hasOption("s")) { + savePlots = true; + } +
String fileName = ""; fileName = cmd.getOptionValue("f"); System.out.println("File: " + fileName); doPelleAnalysis(af, savePlots, fileName, outName); }
+ + if (cmd.getArgs().length != 2) { + System.err.println("Expected two arguments: ecalGainAna gaindriver_sim.aida gaindriver.aida"); + System.exit(1); + } + + ITree sim = null; + ITree real = null; + try { + sim = af.createTreeFactory().create(cmd.getArgs()[0]); + real = af.createTreeFactory().create(cmd.getArgs()[1]); + } catch (IOException e) { + throw new RuntimeException(e); + } + + IHistogram1D pePlotsSim[][][] = new IHistogram1D[47][11][5]; + IHistogram1D pePlotsReal[][][] = new IHistogram1D[47][11][5]; + + for (int iE = 0; iE <= 4; ++iE) { + for (int irow = -5; irow <= 5; ++irow) { + for (int icol = -23; icol <= 23; ++icol) { + if (iE == 0) { + pePlotsSim[icol + 23][irow + 5][iE] = (IHistogram1D) sim.find("E over p x=" + icol + " y=" + irow); + pePlotsReal[icol + 23][irow + 5][iE] = (IHistogram1D) real.find("E over p x=" + icol + " y=" + irow); + } else { + pePlotsSim[icol + 23][irow + 5][iE] = (IHistogram1D) sim.find("E over p x=" + icol + " y=" + irow + " iE=" + iE); + pePlotsReal[icol + 23][irow + 5][iE] = (IHistogram1D) real.find("E over p x=" + icol + " y=" + irow + " iE=" + iE); + } + } + } + } + +// IHistogram2D mpePlotSim = (IHistogram2D) sim.find("<E over p>"); +// IHistogram2D spePlotSim = (IHistogram2D) sim.find("RMS(E over p)"); +// IHistogram2D mpePlotReal = (IHistogram2D) real.find("<E over p>"); +// IHistogram2D spePlotReal = (IHistogram2D) real.find("RMS(E over p)"); + + String detectorName = "HPS-TestRun-v2"; + HPSEcalConditions.detectorChanged(DetectorLocator.findDetector(detectorName), "Ecal"); + + IHistogramFactory hf = af.createHistogramFactory(null); + + IPlotter gainPlotter = af.createPlotterFactory().create(); + gainPlotter.createRegion(); +// gainPlotter.setTitle("ECal map"); + IHistogram2D gainsPlot = hf.createHistogram2D("ECal map", 47, -23.5, 23.5, 11, -5.5, 5.5); + gainPlotter.region(0).plot(gainsPlot); + gainPlotter.region(0).style().statisticsBoxStyle().setVisible(false); + gainPlotter.region(0).style().setParameter("hist2DStyle", "colorMap"); + gainPlotter.region(0).style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow"); + +// IHistogram1D pePlotsHV[][] = new IHistogram1D[4][12]; +// for (int quad = 1; quad <= 4; ++quad) { +// for (int module = 1; module <= 12; ++module) { +// pePlotsHV[quad - 1][module - 1] = hf.createHistogram1D("E over p quadrant=" + quad + " HV group=" + module, 50, 0, 2); +// } +// } +// + + gainsPlot.setTitle("Crystal gains before iterating"); + gainPlotter.region(0).refresh(); +// gainPlotter.region(0).clear(); +// gainPlotter.region(0).plot(gainsPlot); + for (int x = -23; x <= 23; x++) { // slot + for (int y = -5; y <= 5; y++) { // crate + Double gain = HPSEcalConditions.physicalToGain(HPSEcalConditions.makePhysicalID(x, y)); + if (gain != null) { + gainsPlot.fill(x, y, gain); +// gainsPlot.fill(x, y, HPSECalUtils.getHVGroup(x, y)); + } + } + } + + try { + gainPlotter.writeToFile(outName + "_initial_gains.png", "png"); + } catch (IOException e) { + throw new RuntimeException(e); + } + + gainsPlot.reset(); + gainsPlot.setTitle("Crystal gains after iterating"); + gainPlotter.region(0).refresh(); +// gainPlotter.region(0).clear(); +// gainPlotter.region(0).plot(gainsPlot); + + PrintStream gainStream; + try { + gainStream = new PrintStream(outName + ".gain"); + } catch (IOException e) { + throw new RuntimeException(e); + } + + gainStream.format("#x\ty\tgain\n"); + for (int x = -23; x <= 23; x++) { // slot + for (int y = -5; y <= 5; y++) { // crate + Double gain = HPSEcalConditions.physicalToGain(HPSEcalConditions.makePhysicalID(x, y)); + if (gain != null) { + if (pePlotsSim[x + 23][y + 5][0].allEntries() >= 10 && pePlotsReal[x + 23][y + 5][0].allEntries() >= 10) { + gain *= (pePlotsSim[x + 23][y + 5][0].mean() / pePlotsReal[x + 23][y + 5][0].mean()); + } + gainStream.format("%d\t%d\t%f\n", x, y, gain); + gainsPlot.fill(x, y, gain); +// System.out.printf("%d\t%d\t%d\t%f\t%f\n", x, y, pePlotsSim[x + 23][y + 5][0].allEntries(), pePlotsSim[x + 23][y + 5][0].mean(), pePlotsSim[x + 23][y + 5][0].rms()); + } + } + } + gainStream.close(); + + try { + gainPlotter.writeToFile(outName + "_final_gains.png", "png"); + } catch (IOException e) { + throw new RuntimeException(e); + }
} private static void doPelleAnalysis(IAnalysisFactory af, boolean savePlots, String fileName, String outName) {
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1