Author: [log in to unmask] Date: Tue Nov 25 16:36:28 2014 New Revision: 1594 Log: Source code formatting. Modified: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedCommissioning.java Modified: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedCommissioning.java ============================================================================= --- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedCommissioning.java (original) +++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedCommissioning.java Tue Nov 25 16:36:28 2014 @@ -39,139 +39,128 @@ * as well as a 2D histogram (hit time vs hit energy). Finally, if available, the raw waveshape (in mV) is displayed. * * @author Andrea Celentano - * * + * */ public class EcalLedCommissioning extends Driver implements CrystalListener, ActionListener { - String inputCollection = "EcalCalHits"; String inputCollectionRaw = "EcalReadoutHits"; String clusterCollection = "EcalClusters"; private IPlotter plotter; - private AIDA aida=AIDA.defaultInstance(); + private AIDA aida = AIDA.defaultInstance(); private Detector detector; private IPlotterFactory plotterFactory; int eventRefreshRate = 1; int eventn = 0; - int ix,iy,id; - - int[] windowRaw=new int[47*11];//in case we have the raw waveform, this is the window lenght (in samples) - boolean[] isFirstRaw=new boolean[47*11]; - - private PEventViewer viewer; //this is the Kyle event viewer. - - + int ix, iy, id; + + int[] windowRaw = new int[47 * 11];// in case we have the raw waveform, this is the window lenght (in samples) + boolean[] isFirstRaw = new boolean[47 * 11]; + + private PEventViewer viewer; // this is the Kyle event viewer. + ArrayList<IHistogram1D> channelEnergyPlot; ArrayList<IHistogram1D> channelTimePlot; ArrayList<IHistogram1D> channelRawWaveform; - // ArrayList<ICloud1D> channelRawWaveform; + // ArrayList<ICloud1D> channelRawWaveform; ArrayList<IHistogram2D> channelTimeVsEnergyPlot; - + IPlotterStyle pstyle; - - + double maxEch = 2500 * ECalUtils.MeV; - + public EcalLedCommissioning() { - + } public void setMaxEch(double maxEch) { this.maxEch = maxEch; } - + public void setInputCollection(String inputCollection) { this.inputCollection = inputCollection; } - + public void setInputCollectionRaw(String inputCollectionRaw) { this.inputCollectionRaw = inputCollectionRaw; } - + public void setInputClusterCollection(String inputClusterCollection) { this.clusterCollection = inputClusterCollection; } - + public void setEventRefreshRate(int eventRefreshRate) { this.eventRefreshRate = eventRefreshRate; } - + @Override public void detectorChanged(Detector detector) { - System.out.println("Ecal event display detector changed"); + System.out.println("Ecal event display detector changed"); this.detector = detector; - - aida.tree().cd("/"); - - - - channelEnergyPlot=new ArrayList<IHistogram1D>(); - channelTimePlot=new ArrayList<IHistogram1D>(); - channelRawWaveform=new ArrayList<IHistogram1D>(); - //channelRawWaveform=new ArrayList<ICloud1D>(); - channelTimeVsEnergyPlot=new ArrayList<IHistogram2D>(); - //create the histograms for single channel energy and time distribution. - //these are NOT shown in this plotter, but are used in the event display. - for(int ii = 0; ii < (47*11); ii = ii +1){ - int row=ECalUtils.getRowFromHistoID(ii); - int column=ECalUtils.getColumnFromHistoID(ii); - channelEnergyPlot.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Energy : " + (column) + " "+ (row)+ ": "+ii, 100, 0, maxEch)); - channelTimePlot.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Time : " + (column) + " "+ (row)+ ": "+ii, 100, 0, 400)); - channelTimeVsEnergyPlot.add(aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Hit Time Vs Energy : " + (column) + " "+ (row)+ ": "+ii, 100, 0, 400,100, 0, maxEch)); - channelRawWaveform.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Energy : " + (column) + " "+ (row)+ ": "+ii)); - //the above instruction is a terrible hack, just to fill the arrayList with all the elements. They'll be initialized properly during the event readout, - //since we want to account for possibly different raw waveform dimensions! - //channelRawWaveform.add(aida.cloud1D(detector.getDetectorName() + " : " + inputCollection + " : Raw Waveform : " + (column) + " "+ (row)+ ": "+ii,1000000000)); - - isFirstRaw[ii]=true; - windowRaw[ii]=1; - } - id=0; - iy=ECalUtils.getRowFromHistoID(id); - ix=ECalUtils.getColumnFromHistoID(id); - - - plotterFactory = aida.analysisFactory().createPlotterFactory("Ecal LED commissioning"); + + aida.tree().cd("/"); + + channelEnergyPlot = new ArrayList<IHistogram1D>(); + channelTimePlot = new ArrayList<IHistogram1D>(); + channelRawWaveform = new ArrayList<IHistogram1D>(); + // channelRawWaveform=new ArrayList<ICloud1D>(); + channelTimeVsEnergyPlot = new ArrayList<IHistogram2D>(); + // create the histograms for single channel energy and time distribution. + // these are NOT shown in this plotter, but are used in the event display. + for (int ii = 0; ii < (47 * 11); ii = ii + 1) { + int row = ECalUtils.getRowFromHistoID(ii); + int column = ECalUtils.getColumnFromHistoID(ii); + channelEnergyPlot.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Energy : " + (column) + " " + (row) + ": " + ii, 100, 0, maxEch)); + channelTimePlot.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Time : " + (column) + " " + (row) + ": " + ii, 100, 0, 400)); + channelTimeVsEnergyPlot.add(aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Hit Time Vs Energy : " + (column) + " " + (row) + ": " + ii, 100, 0, 400, 100, 0, maxEch)); + channelRawWaveform.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Energy : " + (column) + " " + (row) + ": " + ii)); + // the above instruction is a terrible hack, just to fill the arrayList with all the elements. They'll be initialized properly during the event readout, + // since we want to account for possibly different raw waveform dimensions! + // channelRawWaveform.add(aida.cloud1D(detector.getDetectorName() + " : " + inputCollection + " : Raw Waveform : " + (column) + " "+ (row)+ ": "+ii,1000000000)); + + isFirstRaw[ii] = true; + windowRaw[ii] = 1; + } + id = 0; + iy = ECalUtils.getRowFromHistoID(id); + ix = ECalUtils.getColumnFromHistoID(id); + + plotterFactory = aida.analysisFactory().createPlotterFactory("Ecal LED commissioning"); plotter = plotterFactory.create("Single channel"); - pstyle = this.createDefaultStyle(); + pstyle = this.createDefaultStyle(); plotter.setTitle(""); - - - plotter.createRegions(2,2); - + + plotter.createRegions(2, 2); pstyle.xAxisStyle().setLabel("Hit energy (GeV)"); pstyle.yAxisStyle().setLabel(""); - plotter.region(0).plot(channelEnergyPlot.get(id),pstyle); - + plotter.region(0).plot(channelEnergyPlot.get(id), pstyle); + pstyle.xAxisStyle().setLabel("Hit Time (ns)"); - pstyle.yAxisStyle().setLabel(""); - plotter.region(1).plot(channelTimePlot.get(id),pstyle); - + pstyle.yAxisStyle().setLabel(""); + plotter.region(1).plot(channelTimePlot.get(id), pstyle); + pstyle.xAxisStyle().setLabel("Hit Time (ns)"); - pstyle.yAxisStyle().setLabel("Hit Energy (GeV)"); - plotter.region(2).plot(channelTimeVsEnergyPlot.get(id),pstyle); - - pstyle.xAxisStyle().setLabel("Hit Energy (GeV)"); + pstyle.yAxisStyle().setLabel("Hit Energy (GeV)"); + plotter.region(2).plot(channelTimeVsEnergyPlot.get(id), pstyle); + + pstyle.xAxisStyle().setLabel("Hit Energy (GeV)"); pstyle.yAxisStyle().setLabel(""); pstyle.dataStyle().fillStyle().setColor("orange"); pstyle.dataStyle().markerStyle().setColor("orange"); pstyle.dataStyle().errorBarStyle().setVisible(false); - plotter.region(3).plot(channelRawWaveform.get(id),pstyle); - - - + plotter.region(3).plot(channelRawWaveform.get(id), pstyle); + System.out.println("Create the event viewer"); - viewer=new PEventViewer(); + viewer = new PEventViewer(); viewer.addCrystalListener(this); System.out.println("Done"); - - + plotter.show(); - + viewer.setVisible(true); - + } @Override @@ -182,211 +171,199 @@ @Override public void process(EventHeader event) { - - int ii; - int row = 0; - int column = 0; - - boolean do_update=false; - if (++eventn % eventRefreshRate == 0) { - do_update=true; - } - - if (do_update){ - viewer.resetDisplay(); - viewer.updateDisplay(); - } - - Cluster the_cluster; - + + int ii; + int row = 0; + int column = 0; + + boolean do_update = false; + if (++eventn % eventRefreshRate == 0) { + do_update = true; + } + + if (do_update) { + viewer.resetDisplay(); + viewer.updateDisplay(); + } + + Cluster the_cluster; + if (event.hasCollection(CalorimeterHit.class, inputCollection)) { - List<CalorimeterHit> hits = event.get(CalorimeterHit.class, inputCollection); + List<CalorimeterHit> hits = event.get(CalorimeterHit.class, inputCollection); for (CalorimeterHit hit : hits) { - row=hit.getIdentifierFieldValue("iy"); - column=hit.getIdentifierFieldValue("ix"); - if ((row!=0)&&(column!=0)){ - ii = ECalUtils.getHistoIDFromRowColumn(row,column); - if (hit.getCorrectedEnergy() > 0) { //A.C. > 0 for the 2D plot drawing - channelEnergyPlot.get(ii).fill(hit.getCorrectedEnergy()); + row = hit.getIdentifierFieldValue("iy"); + column = hit.getIdentifierFieldValue("ix"); + if ((row != 0) && (column != 0)) { + ii = ECalUtils.getHistoIDFromRowColumn(row, column); + if (hit.getCorrectedEnergy() > 0) { // A.C. > 0 for the 2D plot drawing + channelEnergyPlot.get(ii).fill(hit.getCorrectedEnergy()); channelTimePlot.get(ii).fill(hit.getTime()); - channelTimeVsEnergyPlot.get(ii).fill(hit.getTime(),hit.getCorrectedEnergy()); - if (do_update) viewer.addHit(new EcalHit(column,row, hit.getCorrectedEnergy())); - } - } + channelTimeVsEnergyPlot.get(ii).fill(hit.getTime(), hit.getCorrectedEnergy()); + if (do_update) + viewer.addHit(new EcalHit(column, row, hit.getCorrectedEnergy())); + } + } } } if (event.hasCollection(HPSEcalCluster.class, clusterCollection)) { List<HPSEcalCluster> clusters = event.get(HPSEcalCluster.class, clusterCollection); for (HPSEcalCluster cluster : clusters) { CalorimeterHit seedHit = cluster.getSeedHit(); - if (do_update){ - the_cluster=new Cluster(seedHit.getIdentifierFieldValue("ix"), seedHit.getIdentifierFieldValue("iy"), cluster.getEnergy()); - for (CalorimeterHit hit : cluster.getCalorimeterHits()) { - if (hit.getRawEnergy() > 0) - column=hit.getIdentifierFieldValue("ix"); - row=hit.getIdentifierFieldValue("iy"); - the_cluster.addComponentHit(hit.getIdentifierFieldValue("ix"),hit.getIdentifierFieldValue("iy")); - } - viewer.addCluster(the_cluster); - } + if (do_update) { + the_cluster = new Cluster(seedHit.getIdentifierFieldValue("ix"), seedHit.getIdentifierFieldValue("iy"), cluster.getEnergy()); + for (CalorimeterHit hit : cluster.getCalorimeterHits()) { + if (hit.getRawEnergy() > 0) + column = hit.getIdentifierFieldValue("ix"); + row = hit.getIdentifierFieldValue("iy"); + the_cluster.addComponentHit(hit.getIdentifierFieldValue("ix"), hit.getIdentifierFieldValue("iy")); + } + viewer.addCluster(the_cluster); + } } } - - //here follows the code for the raw waveform - if (event.hasCollection(RawTrackerHit.class, inputCollectionRaw)){ - List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollectionRaw); - for (RawTrackerHit hit : hits) { - row=hit.getIdentifierFieldValue("iy"); - column=hit.getIdentifierFieldValue("ix"); - if ((row!=0)&&(column!=0)&&(!ECalUtils.isInHole(row,column))){ - ii = ECalUtils.getHistoIDFromRowColumn(row,column); - if (isFirstRaw[ii]){ //at the very first hit we read for this channel, we need to read the window length and save it - isFirstRaw[ii]=false; - windowRaw[ii]=hit.getADCValues().length; - channelRawWaveform.set(ii,aida.histogram1D(detector.getDetectorName() + " : " + inputCollectionRaw + " : Raw Waveform : " + (column) + " "+ (row)+ ": "+ii,windowRaw[ii],-0.5*ECalUtils.ecalReadoutPeriod,(-0.5+windowRaw[ii])*ECalUtils.ecalReadoutPeriod)); - } - if (do_update){ - channelRawWaveform.get(ii).reset(); - for (int jj = 0; jj < windowRaw[ii]; jj++) { - channelRawWaveform.get(ii).fill(jj*ECalUtils.ecalReadoutPeriod, hit.getADCValues()[jj]*ECalUtils.adcResolution*1000); - } - } - } + + // here follows the code for the raw waveform + if (event.hasCollection(RawTrackerHit.class, inputCollectionRaw)) { + List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollectionRaw); + for (RawTrackerHit hit : hits) { + row = hit.getIdentifierFieldValue("iy"); + column = hit.getIdentifierFieldValue("ix"); + if ((row != 0) && (column != 0) && (!ECalUtils.isInHole(row, column))) { + ii = ECalUtils.getHistoIDFromRowColumn(row, column); + if (isFirstRaw[ii]) { // at the very first hit we read for this channel, we need to read the window length and save it + isFirstRaw[ii] = false; + windowRaw[ii] = hit.getADCValues().length; + channelRawWaveform.set(ii, aida.histogram1D(detector.getDetectorName() + " : " + inputCollectionRaw + " : Raw Waveform : " + (column) + " " + (row) + ": " + ii, windowRaw[ii], -0.5 * ECalUtils.ecalReadoutPeriod, (-0.5 + windowRaw[ii]) * ECalUtils.ecalReadoutPeriod)); + } + if (do_update) { + channelRawWaveform.get(ii).reset(); + for (int jj = 0; jj < windowRaw[ii]; jj++) { + channelRawWaveform.get(ii).fill(jj * ECalUtils.ecalReadoutPeriod, hit.getADCValues()[jj] * ECalUtils.adcResolution * 1000); + } + } + } } } - - - if (do_update){ - viewer.updateDisplay(); - } - } - + + if (do_update) { + viewer.updateDisplay(); + } + } + /* - @Override - public void reset(){ - for(int ii = 0; ii < (47*11); ii = ii +1){ - channelEnergyPlot.get(ii).reset(); - channelTimePlot.get(ii).reset(); - channelTimeVsEnergyPlot.get(ii).reset(); - } - } - */ - + * @Override public void reset(){ for(int ii = 0; ii < (47*11); ii = ii +1){ channelEnergyPlot.get(ii).reset(); channelTimePlot.get(ii).reset(); channelTimeVsEnergyPlot.get(ii).reset(); } } + */ + @Override public void actionPerformed(ActionEvent ae) { - - } - - @Override - public void crystalActivated(CrystalEvent e){ - - } - - /** - * <b>crystalDeactivated</b><br/><br/> - * <code>public void <b>crystalDeactivated</b>(CrystalEvent e)</code><br/><br/> - * Invoked when a crystal ceases to be highlighted. - * @param e - An object describing the event. - */ - @Override - public void crystalDeactivated(CrystalEvent e){ - - } - - /** - * <b>crystalClicked</b><br/><br/> - * <code>public void <b>crystalClicked</b>(CrystalEvent e)</code><br/><br/> - * Invoked when a crystal is clicked - * @param e - An object describing the event. - */ - @Override - public void crystalClicked(CrystalEvent e){ - - int itmpx,itmpy; - Point displayPoint,ecalPoint; - displayPoint=e.getCrystalID(); - ecalPoint=viewer.toEcalPoint(displayPoint); - itmpx=(int) ecalPoint.getX(); //column - itmpy=(int) ecalPoint.getY(); //row - - if ((itmpx!=0)&&(itmpy!=0)&&(!ECalUtils.isInHole(itmpy,itmpx))){ - ix=itmpx; - iy=itmpy; - id=ECalUtils.getHistoIDFromRowColumn(iy,ix); - System.out.println("Crystal event: "+ix+" "+iy+" "+id); - - - - - - plotter.region(0).clear(); + + } + + @Override + public void crystalActivated(CrystalEvent e) { + + } + + /** + * <b>crystalDeactivated</b><br/> + * <br/> + * <code>public void <b>crystalDeactivated</b>(CrystalEvent e)</code><br/> + * <br/> + * Invoked when a crystal ceases to be highlighted. + * + * @param e + * - An object describing the event. + */ + @Override + public void crystalDeactivated(CrystalEvent e) { + + } + + /** + * <b>crystalClicked</b><br/> + * <br/> + * <code>public void <b>crystalClicked</b>(CrystalEvent e)</code><br/> + * <br/> + * Invoked when a crystal is clicked + * + * @param e + * - An object describing the event. + */ + @Override + public void crystalClicked(CrystalEvent e) { + + int itmpx, itmpy; + Point displayPoint, ecalPoint; + displayPoint = e.getCrystalID(); + ecalPoint = viewer.toEcalPoint(displayPoint); + itmpx = (int) ecalPoint.getX(); // column + itmpy = (int) ecalPoint.getY(); // row + + if ((itmpx != 0) && (itmpy != 0) && (!ECalUtils.isInHole(itmpy, itmpx))) { + ix = itmpx; + iy = itmpy; + id = ECalUtils.getHistoIDFromRowColumn(iy, ix); + System.out.println("Crystal event: " + ix + " " + iy + " " + id); + + plotter.region(0).clear(); pstyle.xAxisStyle().setLabel("Hit energy (GeV)"); pstyle.yAxisStyle().setLabel(""); - plotter.region(0).plot(channelEnergyPlot.get(id),pstyle); - - plotter.region(1).clear(); + plotter.region(0).plot(channelEnergyPlot.get(id), pstyle); + + plotter.region(1).clear(); pstyle.xAxisStyle().setLabel("Hit Time (ns)"); - pstyle.yAxisStyle().setLabel(""); - plotter.region(1).plot(channelTimePlot.get(id),pstyle); - + pstyle.yAxisStyle().setLabel(""); + plotter.region(1).plot(channelTimePlot.get(id), pstyle); + plotter.region(2).clear(); pstyle.xAxisStyle().setLabel("Hit Time (ns)"); - pstyle.yAxisStyle().setLabel("Hit Energy (GeV)"); - plotter.region(2).plot(channelTimeVsEnergyPlot.get(id),pstyle); - - plotter.region(3).clear(); - - - if (!isFirstRaw[id]){ - pstyle.yAxisStyle().setLabel("Signal amplitude (mV)"); - pstyle.xAxisStyle().setLabel("Time (ns)"); - pstyle.dataStyle().fillStyle().setColor("orange"); - pstyle.dataStyle().markerStyle().setColor("orange"); - pstyle.dataStyle().errorBarStyle().setVisible(false); - } - else{ - pstyle.xAxisStyle().setLabel("Hit Energy (GeV)"); - pstyle.yAxisStyle().setLabel(""); - } - plotter.region(3).plot(channelRawWaveform.get(id),pstyle); - - - - - - - } - } - - + pstyle.yAxisStyle().setLabel("Hit Energy (GeV)"); + plotter.region(2).plot(channelTimeVsEnergyPlot.get(id), pstyle); + + plotter.region(3).clear(); + + if (!isFirstRaw[id]) { + pstyle.yAxisStyle().setLabel("Signal amplitude (mV)"); + pstyle.xAxisStyle().setLabel("Time (ns)"); + pstyle.dataStyle().fillStyle().setColor("orange"); + pstyle.dataStyle().markerStyle().setColor("orange"); + pstyle.dataStyle().errorBarStyle().setVisible(false); + } else { + pstyle.xAxisStyle().setLabel("Hit Energy (GeV)"); + pstyle.yAxisStyle().setLabel(""); + } + plotter.region(3).plot(channelRawWaveform.get(id), pstyle); + } + } + /* * This method set the default style. */ public IPlotterStyle createDefaultStyle() { - IPlotterStyle pstyle = plotterFactory.createPlotterStyle(); - // Axis appearence. - pstyle.xAxisStyle().labelStyle().setBold(true); - pstyle.yAxisStyle().labelStyle().setBold(true); - pstyle.xAxisStyle().tickLabelStyle().setBold(true); - pstyle.yAxisStyle().tickLabelStyle().setBold(true); - pstyle.xAxisStyle().lineStyle().setColor("black"); - pstyle.yAxisStyle().lineStyle().setColor("black"); - pstyle.xAxisStyle().lineStyle().setThickness(2); - pstyle.yAxisStyle().lineStyle().setThickness(2); - - pstyle.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow"); - pstyle.dataStyle().fillStyle().setParameter("showZeroHeightBins",Boolean.FALSE.toString()); - pstyle.dataStyle().errorBarStyle().setVisible(false); + IPlotterStyle pstyle = plotterFactory.createPlotterStyle(); + // Axis appearence. + pstyle.xAxisStyle().labelStyle().setBold(true); + pstyle.yAxisStyle().labelStyle().setBold(true); + pstyle.xAxisStyle().tickLabelStyle().setBold(true); + pstyle.yAxisStyle().tickLabelStyle().setBold(true); + pstyle.xAxisStyle().lineStyle().setColor("black"); + pstyle.yAxisStyle().lineStyle().setColor("black"); + pstyle.xAxisStyle().lineStyle().setThickness(2); + pstyle.yAxisStyle().lineStyle().setThickness(2); + + pstyle.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow"); + pstyle.dataStyle().fillStyle().setParameter("showZeroHeightBins", Boolean.FALSE.toString()); + pstyle.dataStyle().errorBarStyle().setVisible(false); pstyle.setParameter("hist2DStyle", "colorMap"); - // Force auto range to zero. - pstyle.yAxisStyle().setParameter("allowZeroSuppression", "false"); - pstyle.xAxisStyle().setParameter("allowZeroSuppression", "false"); - // Title style. - pstyle.titleStyle().textStyle().setFontSize(20); - // Draw caps on error bars. - pstyle.dataStyle().errorBarStyle().setParameter("errorBarDecoration", (new Float(1.0f)).toString()); - // Turn off grid lines until explicitly enabled. - pstyle.gridStyle().setVisible(false); - return pstyle; - } + // Force auto range to zero. + pstyle.yAxisStyle().setParameter("allowZeroSuppression", "false"); + pstyle.xAxisStyle().setParameter("allowZeroSuppression", "false"); + // Title style. + pstyle.titleStyle().textStyle().setFontSize(20); + // Draw caps on error bars. + pstyle.dataStyle().errorBarStyle().setParameter("errorBarDecoration", (new Float(1.0f)).toString()); + // Turn off grid lines until explicitly enabled. + pstyle.gridStyle().setVisible(false); + return pstyle; + } }