Author: [log in to unmask] Date: Thu Nov 6 01:19:32 2014 New Revision: 1446 Log: Commit some files that were on the ecal-commissioning branch. Also, fixed a typo in the ecal event display PassiveViewer.java class Added: java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/DummyRecon.lcsim java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/PedestalComputationRaw.lcsim java/trunk/users/src/main/java/org/hps/users/celentan/EcalChannelsAmplitude.java java/trunk/users/src/main/java/org/hps/users/celentan/RawPedestalComputator.java Removed: java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/EcalMonitoringTestCelentan.lcsim Modified: java/trunk/ecal-event-display/src/main/java/org/hps/monitoring/ecal/eventdisplay/ui/PassiveViewer.java java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/ECalUtils.java java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalEventDisplay.java java/trunk/users/src/main/java/org/hps/users/celentan/StripChartTest.java Modified: java/trunk/ecal-event-display/src/main/java/org/hps/monitoring/ecal/eventdisplay/ui/PassiveViewer.java ============================================================================= --- java/trunk/ecal-event-display/src/main/java/org/hps/monitoring/ecal/eventdisplay/ui/PassiveViewer.java (original) +++ java/trunk/ecal-event-display/src/main/java/org/hps/monitoring/ecal/eventdisplay/ui/PassiveViewer.java Thu Nov 6 01:19:32 2014 @@ -38,7 +38,7 @@ * @param min - The lower bound. * @param max - The upper bound. */ - public void setScale(int min, int max) { + public void setScale(double min, double max) { //A.C. I modified these to double since ecalPanel methods use double ecalPanel.setScaleMinimum(min); ecalPanel.setScaleMaximum(max); } @@ -48,14 +48,14 @@ * scale. * @param max - The upper bound. */ - public void setScaleMaximum(int max) { ecalPanel.setScaleMaximum(max); } + public void setScaleMaximum(double max) { ecalPanel.setScaleMaximum(max); } //A.C. I modified these to double since ecalPanel methods use double /** * Sets the lower bound for the calorimeter display's color mapping * scale. * @param min - The lower bound. */ - public void setScaleMinimum(int min) { ecalPanel.setScaleMinimum(min); } + public void setScaleMinimum(double min) { ecalPanel.setScaleMinimum(min); } //A.C. I modified these to double since ecalPanel methods use double /** * Displays the hits and clusters added by the <code>addHit</code> Modified: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/ECalUtils.java ============================================================================= --- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/ECalUtils.java (original) +++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/ECalUtils.java Thu Nov 6 01:19:32 2014 @@ -98,4 +98,42 @@ } return ret; } + + + /** + * This is a very basic method that, given an array with the raw-waveform (in FADC units), returns the amplitude (in mV) + * @param data Array with data from FADC, in fadc units + * @param lenght The array lenght + * @param pedestalSamples How many samples at the beginning of the array to use for the pedestal. Must be < lenght + * @return double[], 0 is the amplitude in mV, 1 is the offest in ADC counts, 2 is the RMS in adc counts + */ + public static double[] computeAmplitude(short [] data, int lenght, int pedestalSamples){ + double amplitude,pedestal,noise; + pedestal=0; + noise=0; + amplitude=data[0]; + double[] ret={0.,0.,0.}; + if (pedestalSamples>lenght){ + return ret; + } + for (int jj = 0; jj < lenght; jj++){ + if (jj<pedestalSamples){ + pedestal+=data[jj]; + noise+=data[jj]*data[jj]; + } + if (data[jj]>amplitude) amplitude=data[jj]; + } + pedestal/=pedestalSamples; + noise/=pedestalSamples; + noise=Math.sqrt(noise-pedestal*pedestal); + amplitude-=pedestal; + + amplitude*=adcResolution*1000; + ret[0]=amplitude; + ret[1]=pedestal; + ret[2]=noise; + return ret; + + } + } Modified: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalEventDisplay.java ============================================================================= --- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalEventDisplay.java (original) +++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalEventDisplay.java Thu Nov 6 01:19:32 2014 @@ -6,12 +6,20 @@ import hep.aida.ICloud2D; import hep.aida.IPlotter; import hep.aida.IPlotterFactory; +import hep.aida.IPlotterStyle; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; +import java.lang.System; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.IOException; + import org.hps.monitoring.ecal.eventdisplay.event.Cluster; import org.hps.monitoring.ecal.eventdisplay.event.EcalHit; @@ -28,7 +36,7 @@ import org.lcsim.util.aida.AIDA; /** - * The driver <code>EcalEvendDisplay</code> implements the histogram shown to the user + * The driver <code>EcalEventDisplay</code> implements the histogram shown to the user * in the fifth tab of the Monitoring Application, when using the Ecal monitoring lcsim file. * IT ALSO OPENS KYLE's EVENT DISPLAY <code>PEventViewer</code>. * The implementation is as follows: @@ -54,11 +62,17 @@ int eventRefreshRate = 1; int eventn = 0; int ix,iy,id; - + int pedSamples=10; + + double amp,ped,sigma; + double hitE; 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. + + boolean enableAllFadc=false; + + private PEventViewer viewer; //this is the Kyle event viewer. ArrayList<IHistogram1D> channelEnergyPlot; @@ -67,16 +81,32 @@ // ArrayList<ICloud1D> channelRawWaveform; ArrayList<IHistogram2D> channelTimeVsEnergyPlot; + IPlotterStyle pstyle; double maxEch = 2500 * ECalUtils.MeV; + double minEch = -0.1; + + int itmpx,itmpy; public EcalEventDisplay() { } + public void setEnableAllFadc(boolean enableAllFadc){ + this.enableAllFadc = enableAllFadc; + } + public void setMaxEch(double maxEch) { this.maxEch = maxEch; + } + + public void setMinEch(double minEch) { + this.minEch = minEch; + } + + public void setPedSamples(int pedSamples) { + this.pedSamples = pedSamples; } public void setInputCollection(String inputCollection) { @@ -110,13 +140,12 @@ //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)); + channelEnergyPlot.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Energy : " + (column) + " "+ (row)+ ": "+ii, 100, -.2, 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)); + channelTimeVsEnergyPlot.add(aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Hit Time Vs Energy : " + (column) + " "+ (row)+ ": "+ii, 100, 0, 400,100, -.2, 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! @@ -130,49 +159,41 @@ ix=ECalUtils.getColumnFromHistoID(id); - - - - - plotterFactory = aida.analysisFactory().createPlotterFactory("Ecal single channel plots"); + plotterFactory = aida.analysisFactory().createPlotterFactory("Single channel"); + plotter = plotterFactory.create("Single channel"); + pstyle = this.createDefaultStyle(); + plotter.setTitle(""); - - plotter = plotterFactory.create("Single channel"); - plotter.setTitle(""); - plotter.style().setParameter("hist2DStyle", "colorMap"); - plotter.style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow"); - plotter.style().dataStyle().fillStyle().setParameter("showZeroHeightBins",Boolean.FALSE.toString()); - plotter.style().dataStyle().errorBarStyle().setVisible(false); + plotter.createRegions(2,2); - - plotter.region(0).plot(channelEnergyPlot.get(id)); - plotter.region(0).style().xAxisStyle().setLabel("Hit energy (GeV)"); - plotter.region(0).style().yAxisStyle().setLabel(""); - - plotter.region(1).plot(channelTimePlot.get(id)); - plotter.region(1).style().xAxisStyle().setLabel("Hit Time (ns)"); - plotter.region(1).style().yAxisStyle().setLabel(""); - - plotter.region(2).plot(channelTimeVsEnergyPlot.get(id)); - plotter.region(2).style().xAxisStyle().setLabel("Hit Time (ns)"); - plotter.region(2).style().yAxisStyle().setLabel("Hit Energy (GeV)"); - - - plotter.region(3).plot(channelRawWaveform.get(id)); - plotter.region(3).style().xAxisStyle().setLabel("Hit energy (GeV)"); - plotter.region(3).style().yAxisStyle().setLabel(""); - plotter.region(3).style().dataStyle().fillStyle().setColor("orange"); - plotter.region(3).style().dataStyle().markerStyle().setColor("orange"); - plotter.region(3).style().dataStyle().errorBarStyle().setVisible(false); - - + pstyle.xAxisStyle().setLabel("Hit energy (GeV)"); + pstyle.yAxisStyle().setLabel(""); + 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.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(""); + pstyle.dataStyle().fillStyle().setColor("orange"); + pstyle.dataStyle().markerStyle().setColor("orange"); + pstyle.dataStyle().errorBarStyle().setVisible(false); + plotter.region(3).plot(channelRawWaveform.get(id),pstyle); + System.out.println("Create the event viewer"); viewer=new PEventViewer(); viewer.addCrystalListener(this); + viewer.setScaleMinimum(minEch); + viewer.setScaleMaximum(maxEch); System.out.println("Done"); @@ -189,11 +210,12 @@ } @Override - public void process(EventHeader event) { + public void process(EventHeader event){ int ii; int row = 0; int column = 0; + double[] result; boolean do_update=false; if (++eventn % eventRefreshRate == 0) { @@ -214,12 +236,25 @@ 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 + hitE=hit.getCorrectedEnergy(); + if (hitE > 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)){ + if ((hitE>minEch)&&(hitE<maxEch)){ + viewer.addHit(new EcalHit(column,row, hitE)); //before was in >0 check + } + else if (hitE>maxEch){ + viewer.addHit(new EcalHit(column,row, maxEch)); + } + + + + + + } } } } @@ -230,10 +265,12 @@ 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"); + hitE=hit.getCorrectedEnergy(); + if ((hitE>minEch)&&(hitE<maxEch)){ + column=hit.getIdentifierFieldValue("ix"); row=hit.getIdentifierFieldValue("iy"); the_cluster.addComponentHit(hit.getIdentifierFieldValue("ix"),hit.getIdentifierFieldValue("iy")); + } } viewer.addCluster(the_cluster); } @@ -246,19 +283,25 @@ 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 ((row!=0)&&(column!=0)){ + if (!ECalUtils.isInHole(row,column)||(enableAllFadc)){ + + 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); + } + result=ECalUtils.computeAmplitude(hit.getADCValues(),windowRaw[ii],pedSamples); + channelRawWaveform.get(ii).setTitle("Ampl: "+String.format("%.2f",result[0])+" mV , ped : "+String.format("%.2f",result[1])+" "+String.format("%.2f",result[2])+" ADC counts"); + plotter.region(3).refresh(); + } + } } } } @@ -310,50 +353,86 @@ @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(); - plotter.region(0).plot(channelEnergyPlot.get(id)); - plotter.region(0).style().xAxisStyle().setLabel("Hit energy (GeV)"); - plotter.region(0).style().yAxisStyle().setLabel(""); - - plotter.region(1).clear(); - plotter.region(1).plot(channelTimePlot.get(id)); - plotter.region(1).style().xAxisStyle().setLabel("Hit Time (ns)"); - plotter.region(1).style().yAxisStyle().setLabel(""); - - plotter.region(2).clear(); - plotter.region(2).plot(channelTimeVsEnergyPlot.get(id)); - plotter.region(2).style().yAxisStyle().setLabel("Hit Energy (GeV)"); - plotter.region(2).style().xAxisStyle().setLabel("Hit Time (ns)"); + if ((itmpx!=0)&&(itmpy!=0)) + if (!ECalUtils.isInHole(itmpy,itmpx)||(enableAllFadc)){ + 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(); + pstyle.xAxisStyle().setLabel("Hit Time (ns)"); + 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(); - plotter.region(3).clear(); - plotter.region(3).plot(channelRawWaveform.get(id)); - if (!isFirstRaw[id]){ - plotter.region(3).style().yAxisStyle().setLabel("Signal amplitude (mV)"); - plotter.region(3).style().xAxisStyle().setLabel("Time (ns)"); - plotter.region(3).style().dataStyle().fillStyle().setColor("orange"); - plotter.region(3).style().dataStyle().markerStyle().setColor("orange"); - plotter.region(3).style().dataStyle().errorBarStyle().setVisible(false); - } - else{ - plotter.region(3).style().xAxisStyle().setLabel("Hit energy (GeV)"); - plotter.region(3).style().yAxisStyle().setLabel(""); - } + + 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); + 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; + } } - Added: java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/DummyRecon.lcsim ============================================================================= --- java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/DummyRecon.lcsim (added) +++ java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/DummyRecon.lcsim Thu Nov 6 01:19:32 2014 @@ -0,0 +1,55 @@ +<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd"> + <control> + <numberOfEvents>-1</numberOfEvents> + <printInputFiles>true</printInputFiles> + <printDriversDetailed>true</printDriversDetailed> + </control> + <execute> + <driver name="EventMarkerDriver"/> + <!-- <driver name="ConditionsDriver"/> --> + <driver name="CalibrationDriver"/> + <driver name="EcalRawConverter"/> + <driver name="EcalChannelsAmplitude"/> + + + +<!-- <driver name="RunControlDriver" />--> + <driver name="AidaSaveDriver"/> + <driver name="CleanupDriver"/> + </execute> + +<!-- Here starts the drivers description --> + <drivers> + <driver name="EventMarkerDriver" type="org.lcsim.job.EventMarkerDriver"> + <eventInterval>1</eventInterval> + </driver> + + <driver name="CalibrationDriver" type="org.hps.conditions.deprecated.CalibrationDriver"/> + + <driver name="EcalRawConverter" type="org.hps.recon.ecal.EcalRawConverterDriver"> +<!-- <threshold>150</threshold>--> + <applyBadCrystalMap>false</applyBadCrystalMap> +<!-- <dropBadFADC>true</dropBadFADC>--> + </driver> + + + <driver name="EcalChannelsAmplitude" type="org.hps.users.celentan.EcalChannelsAmplitude"> + <inputCollection>EcalCalHits</inputCollection> + <inputCollectionRaw>EcalReadoutHits</inputCollectionRaw> + <inputClusterCollection>EcalClusters</inputClusterCollection> + <enableAllFadc>true</enableAllFadc> + <pedSamples>20</pedSamples> + <maxEch>10.0</maxEch> + <minEch>-0.01</minEch> + <eventRefreshRate>100</eventRefreshRate> + </driver> + + <driver name="AidaSaveDriver" type="org.lcsim.job.AidaSaveDriver"> + <outputFileName>${outputFile}</outputFileName> + </driver> + + <driver name="CleanupDriver" type="org.lcsim.recon.tracking.digitization.sisim.config.ReadoutCleanupDriver"/> + </drivers> +</lcsim> + Added: java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/PedestalComputationRaw.lcsim ============================================================================= --- java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/PedestalComputationRaw.lcsim (added) +++ java/trunk/steering-files/src/main/resources/org/hps/steering/users/celentan/PedestalComputationRaw.lcsim Thu Nov 6 01:19:32 2014 @@ -0,0 +1,36 @@ +<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd"> + <control> + <numberOfEvents>-1</numberOfEvents> + <printInputFiles>true</printInputFiles> + <printDriversDetailed>true</printDriversDetailed> + </control> + <execute> + <driver name="EventMarkerDriver"/> + <!-- <driver name="ConditionsDriver"/> --> + <driver name="CalibrationDriver"/> + <driver name="EcalRawConverter"/> + <driver name="Pedestal"/> + + +<!-- <driver name="RunControlDriver" />--> + <!--<driver name="AidaSaveDriver"/>--> + </execute> + +<!-- Here starts the drivers description --> + <drivers> + <driver name="EventMarkerDriver" type="org.lcsim.job.EventMarkerDriver"> + <eventInterval>1</eventInterval> + </driver> + + <driver name="CalibrationDriver" type="org.hps.conditions.deprecated.CalibrationDriver"/> + + <driver name="EcalRawConverter" type="org.hps.recon.ecal.EcalRawConverterDriver"> +<!-- <threshold>150</threshold>--> + <applyBadCrystalMap>false</applyBadCrystalMap> +<!-- <dropBadFADC>true</dropBadFADC>--> + </driver> + <driver name="Pedestal" type="org.hps.users.celentan.RawPedestalComputator"/> + </drivers> +</lcsim> + Added: java/trunk/users/src/main/java/org/hps/users/celentan/EcalChannelsAmplitude.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/celentan/EcalChannelsAmplitude.java (added) +++ java/trunk/users/src/main/java/org/hps/users/celentan/EcalChannelsAmplitude.java Thu Nov 6 01:19:32 2014 @@ -0,0 +1,201 @@ +package org.hps.users.celentan; + +import hep.aida.IHistogram1D; +import hep.aida.IHistogram2D; +import hep.aida.ICloud1D; +import hep.aida.ICloud2D; +import hep.aida.IPlotter; +import hep.aida.IPlotterFactory; +import hep.aida.IPlotterStyle; + +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import java.lang.System; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.IOException; + +import org.hps.recon.ecal.ECalUtils; +import org.hps.recon.ecal.HPSEcalCluster; +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.EventHeader; +import org.lcsim.event.RawTrackerHit; +import org.lcsim.geometry.Detector; +import org.lcsim.util.Driver; +import org.lcsim.util.aida.AIDA; + +/** + * The driver <code>EcalChannelAmplitude</code> implements the histogram shown to the user + * in the fifth tab of the Monitoring Application, when using the Ecal monitoring lcsim file. + * The implementation is as follows: + * - The event display is opened in a separate window + * - It is updated regularly, according to the event refresh rate + * - If the user clicks on a crystal, the corresponding energy and time distributions (both Histogram1D) are shown in the last panel of the MonitoringApplication, + * 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 EcalChannelsAmplitude extends Driver{ + + + String inputCollection = "EcalCalHits"; + String inputCollectionRaw = "EcalReadoutHits"; + String clusterCollection = "EcalClusters"; + + private AIDA aida=AIDA.defaultInstance(); + private Detector detector; + + int eventRefreshRate = 1; + int eventn = 0; + int ix,iy,id; + int pedSamples=10; + + double amp,ped,sigma; + double hitE; + 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]; + + + boolean enableAllFadc=false; + + + + ArrayList<IHistogram1D> channelAmplitudePlot; + ArrayList<IHistogram1D> channelRawWaveform; + + + + double maxEch = 2500 * ECalUtils.MeV; + double minEch = -0.1; + + int itmpx,itmpy; + + public EcalChannelsAmplitude() { + + } + + public void setEnableAllFadc(boolean enableAllFadc){ + this.enableAllFadc = enableAllFadc; + } + + public void setMaxEch(double maxEch) { + this.maxEch = maxEch; + } + + public void setMinEch(double minEch) { + this.minEch = minEch; + } + + public void setPedSamples(int pedSamples) { + this.pedSamples = pedSamples; + } + + 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"); + this.detector = detector; + + aida.tree().cd("/"); + + + + channelAmplitudePlot=new ArrayList<IHistogram1D>(); + channelRawWaveform=new ArrayList<IHistogram1D>(); + //create the histograms for single channel energy and time distribution. + for(int ii = 0; ii < (47*11); ii = ii +1){ + int row=ECalUtils.getRowFromHistoID(ii); + int column=ECalUtils.getColumnFromHistoID(ii); + channelAmplitudePlot.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Amplitude : " + (column) + " "+ (row)+ ": "+ii, 100, -.2, 2100.)); + channelRawWaveform.add(aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : Hit Amplitude : " + (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! + + + isFirstRaw[ii]=true; + windowRaw[ii]=1; + } + id=0; + iy=ECalUtils.getRowFromHistoID(id); + ix=ECalUtils.getColumnFromHistoID(id); + } + + @Override + public void endOfData() { + System.out.println("END OF DATA"); + } + + @Override + public void process(EventHeader event){ + + int ii; + int row = 0; + int column = 0; + double[] result; + + + 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"); + ii = ECalUtils.getHistoIDFromRowColumn(row,column); + if ((row!=0)&&(column!=0)&&(!(ECalUtils.isInHole(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)); + } + result=ECalUtils.computeAmplitude(hit.getADCValues(),windowRaw[ii],pedSamples); + channelAmplitudePlot.get(ii).fill(result[0]); + } + } + } + + } + + /* + @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(); + } + } + */ + + + + + + +} + + + + + + Added: java/trunk/users/src/main/java/org/hps/users/celentan/RawPedestalComputator.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/celentan/RawPedestalComputator.java (added) +++ java/trunk/users/src/main/java/org/hps/users/celentan/RawPedestalComputator.java Thu Nov 6 01:19:32 2014 @@ -0,0 +1,131 @@ +package org.hps.users.celentan; + +import java.util.List; + +import org.hps.conditions.deprecated.EcalConditions; +import org.hps.recon.ecal.ECalUtils; +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.EventHeader; +import org.lcsim.event.GenericObject; +import org.lcsim.event.RawCalorimeterHit; +import org.lcsim.event.RawTrackerHit; +import org.lcsim.geometry.Detector; +import org.lcsim.lcio.LCIOConstants; +import org.lcsim.util.Driver; +import java.io.PrintWriter; +import java.io.FileNotFoundException; +import java.io.IOException; + + +public class RawPedestalComputator extends Driver{ + + String inputCollectionRaw = "EcalReadoutHits"; + int row,column; + + 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]; + + double[] pedestal=new double[47*11]; + double[] noise=new double[47*11]; + double[] result; + + int pedSamples=50; + int nEvents=0; + @Override + public void detectorChanged(Detector detector) { + System.out.println("Pedestal computator: detector changed"); + for (int ii=0;ii<11*47;ii++){ + isFirstRaw[ii]=true; + pedestal[ii]=0; + noise[ii]=0; + } + } + + + @Override + public void process(EventHeader event) { + int ii=0; + 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"); + ii = ECalUtils.getHistoIDFromRowColumn(row,column); + if ((row!=0)&&(column!=0)){ + if (!ECalUtils.isInHole(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; + } + result=ECalUtils.computeAmplitude(hit.getADCValues(),windowRaw[ii],pedSamples); + pedestal[ii]+=result[1]; + noise[ii]+=result[2]; + } + } + } + } + nEvents++; + } + + @Override + public void endOfData() { + try{ + PrintWriter writerTop = new PrintWriter("default01.ped","UTF-8"); + PrintWriter writerBottom = new PrintWriter("default02.ped","UTF-8"); + + for (int ii=0;ii<11*47;ii++){ + int row,column; + row=ECalUtils.getRowFromHistoID(ii); + column=ECalUtils.getColumnFromHistoID(ii); + if (ECalUtils.isInHole(row,column)) continue; + if ((row==0)||(column==0)) continue; + pedestal[ii]/=nEvents; + noise[ii]/=nEvents; + + long daqID=EcalConditions.physicalToDaqID(EcalConditions.makePhysicalID(column,row)); + + int crate=EcalConditions.getCrate(daqID); + int slot=EcalConditions.getSlot(daqID); + int channel=EcalConditions.getChannel(daqID); + + System.out.println(column+" "+row+" "+crate+" "+slot+" "+channel+" "+pedestal[ii]+" "+noise[ii]); + + + + if (crate==37){ + writerTop.print(slot+" "+channel+" "+(int)(Math.round(pedestal[ii]))+" "+(int)(Math.round(noise[ii]))+"\r\n"); + } + else if (crate==39){ + writerBottom.print(slot+" "+channel+" "+(int)(Math.round(pedestal[ii]))+" "+(int)(Math.round(noise[ii]))+"\r\n"); + } + + } + + writerTop.close(); + writerBottom.close(); + } + catch(FileNotFoundException fnfe) + { + + System.out.println(fnfe.getMessage()); + + } + + catch(IOException ioe) + { + + System.out.println(ioe.getMessage()); + + } + } +} + + + + + + + + + + Modified: java/trunk/users/src/main/java/org/hps/users/celentan/StripChartTest.java ============================================================================= --- java/trunk/users/src/main/java/org/hps/users/celentan/StripChartTest.java (original) +++ java/trunk/users/src/main/java/org/hps/users/celentan/StripChartTest.java Thu Nov 6 01:19:32 2014 @@ -6,5 +6,5 @@ */ public class StripChartTest { - + int dummy; }