7 modified files
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.1 -r1.2
--- GainCalib.java 24 Jul 2012 23:28:36 -0000 1.1
+++ GainCalib.java 9 Aug 2012 00:51:15 -0000 1.2
@@ -1,7 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.lcsim.hps.recon.ecal;
import hep.aida.*;
@@ -16,9 +12,6 @@
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JLabel;
-import org.lcsim.detector.identifier.ExpandedIdentifier;
-import org.lcsim.detector.identifier.IExpandedIdentifier;
-import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
import org.lcsim.event.Track;
@@ -26,7 +19,6 @@
import org.lcsim.event.base.BaseRawCalorimeterHit;
import org.lcsim.geometry.Detector;
import org.lcsim.hps.monitoring.AIDAFrame;
-import org.lcsim.hps.recon.tracking.EcalTrackMatch;
import org.lcsim.util.aida.AIDA;
/**
@@ -36,27 +28,18 @@
public class GainCalib implements ActionListener {
boolean _debug = false;
-
EventHeader _event = null;
HPSEcalClusterer _clusterer = null;
- HPSEcalRawConverter _converter = null;
private int _integralWindow = 30;
private double _threshold = Double.NEGATIVE_INFINITY;
private boolean _applyBadCrystalMap = true;
-
- private Map<Long,Double> _gains = new HashMap<Long,Double>();
+ private Map<Long, Double> _gains = new HashMap<Long, Double>();
//original list
- private Map<Integer,List<BaseRawCalorimeterHit>> _hits = new HashMap<Integer,List<BaseRawCalorimeterHit>>();
- private Map<Integer,List<MatchedTrack>> _tracks = new HashMap<Integer,List<MatchedTrack>>();
-
+ private Map<Integer, List<BaseRawCalorimeterHit>> _hits = new HashMap<Integer, List<BaseRawCalorimeterHit>>();
+ private Map<Integer, List<MatchedTrack>> _tracks = new HashMap<Integer, List<MatchedTrack>>();
private Detector _detector;
private String _ecalReadoutName;
- private String _ecalName;
private String _ecalTmpCollectionName = "temporaryEcalCalHits";
- private static IIdentifierHelper helper = null;
- private static IExpandedIdentifier expId =null;
-
-
private AIDA aida = AIDA.defaultInstance();
private IAnalysisFactory af = aida.analysisFactory();
IHistogramFactory hf = aida.histogramFactory();
@@ -64,12 +47,11 @@
List<PEHistograms> iterPE = new ArrayList<PEHistograms>();
private AIDAFrame plotFrame = new AIDAFrame();
private List<IPlotter> plotterList = new ArrayList<IPlotter>();
-
- JComboBox xCombo=null;
- JLabel xLabel=null;
+ JComboBox xCombo = null;
+ JLabel xLabel = null;
Integer xList[];
- JComboBox yCombo=null;
- JLabel yLabel=null;
+ JComboBox yCombo = null;
+ JLabel yLabel = null;
Integer yList[];
@Override
@@ -77,311 +59,261 @@
//if(ae == blankButton) {
// //
//}
- Integer x = (Integer)xCombo.getSelectedItem();
- Integer y = (Integer)yCombo.getSelectedItem();
- for(IPlotter p : plotterList) {
+ Integer x = (Integer) xCombo.getSelectedItem();
+ Integer y = (Integer) yCombo.getSelectedItem();
+ for (IPlotter p : plotterList) {
String title = p.title(); //("Gain iteration " + iter);
String v[] = title.split(" ");
- if(v.length<3) {
+ if (v.length < 3) {
System.out.println("ERROR this title " + title + " doesn't have the correct syntax");
System.exit(1);
}
Integer iter = Integer.parseInt(v[2]);
- for(PEHistograms peh : iterPE) {
- if(peh._i==iter) {
+ for (PEHistograms peh : iterPE) {
+ if (peh._i == iter) {
p.region(4).clear();
- p.region(4).plot(peh.pe[x+23][y+5]);
+ p.region(4).plot(peh.pe[x + 23][y + 5]);
}
}
-
+
}
-
-
-
- //throw new UnsupportedOperationException("Not supported yet.");
}
-
-
-
-
-
- class MatchedTrack {
+
+ public class MatchedTrack {
+
long _cellid;
Track _track;
- MatchedTrack(long id,Track trk) {
+
+ MatchedTrack(long id, Track trk) {
_cellid = id;
_track = trk;
}
}
+
class PEHistograms {
+
int _i;
IHistogram1D pe[][] = new IHistogram1D[47][11];
+
PEHistograms(int i) {
_i = i;
}
}
-
+
GainCalib() {
-
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- pe[icol+23][irow+5] = aida.histogram1D("(GainCalib) E over p x=" + icol + " y=" + irow, 50, 0,3);
-
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ pe[icol + 23][irow + 5] = aida.histogram1D("(GainCalib) E over p x=" + icol + " y=" + irow, 50, 0, 3);
}
}
-
-
-
-
+
xList = new Integer[46];
yList = new Integer[10];
- int in=0;
- for(int i=-5;i<=5;++i) {
- if(i!=0) {
+ int in = 0;
+ for (int i = -5; i <= 5; ++i) {
+ if (i != 0) {
yList[in] = i;
++in;
}
}
- in=0;
- for(int i=-23;i<=23;++i) {
- if(i!=0) {
+ in = 0;
+ for (int i = -23; i <= 23; ++i) {
+ if (i != 0) {
xList[in] = i;
++in;
}
}
-
-
-
-
-
-
-
-
}
-
+
public void setApplyBadCrystalMap(boolean d) {
this._applyBadCrystalMap = d;
}
-
+
public void setDebug(boolean d) {
this._debug = d;
}
-
+
public void setClusterer(HPSEcalClusterer clust) {
_clusterer = clust;
}
-
- public void setConverter(HPSEcalRawConverter conv) {
- _converter = conv;
- }
-
- public void setOriginalHits(int evt, List<BaseRawCalorimeterHit> hits, double gain) {
+
+ public void setOriginalHits(int evt, List<BaseRawCalorimeterHit> hits) {
this._hits.put(evt, hits);
- for(BaseRawCalorimeterHit hit: hits) {
- this._gains.put(hit.getCellID(), gain);
+ for (BaseRawCalorimeterHit hit : hits) {
+ this._gains.put(hit.getCellID(), HPSEcalConditions.physicalToGain(hit.getCellID()));
}
}
-
+
public void setTrack(int evt, long ecalCellID, Track track) {
- MatchedTrack mt = new MatchedTrack(ecalCellID,track);
-
-
- if(!this._tracks.containsKey(evt)) {
+ MatchedTrack mt = new MatchedTrack(ecalCellID, track);
+
+ if (!this._tracks.containsKey(evt)) {
this._tracks.put(evt, new ArrayList<MatchedTrack>());
- }
-
- List<MatchedTrack> list = this._tracks.get(evt);
- list.add(mt);
-
-
-
+ }
+
+ List<MatchedTrack> list = this._tracks.get(evt);
+ list.add(mt);
}
-
+
public void setIntegralWindow(int val) {
_integralWindow = val;
}
-
+
public void setThreshold(double val) {
_threshold = val;
}
-
+
public void setEcalReadoutName(String str) {
this._ecalReadoutName = str;
}
-
- public void setEcalName(String str) {
- this._ecalName = str;
- }
public void setDetector(Detector det) {
this._detector = det;
}
-
public void runOptimization(int nIterations) {
-
+
System.out.println("Start gain calibration");
-
-
-
-
+
System.out.println("nIterations " + nIterations);
-
-
- if(_hits==null) {
+
+ if (_hits == null) {
System.out.println("No original hits available");
System.exit(1);
}
-
+
int event;
int iter = 0;
- while(iter<nIterations) {
+ while (iter < nIterations) {
System.out.println("Iteration " + iter);
-
+
Iterator it = _hits.entrySet().iterator();
- while(it.hasNext()) {
- event = ((Map.Entry<Integer,ArrayList<BaseRawCalorimeterHit>>)it.next()).getKey();
- if(_debug) System.out.println("Event " + event);
-
- List<HPSEcalCluster> clusters = getCalibratedClusters(event);
-
- if(_debug) System.out.println("Found " + clusters.size() + " clusters");
-
- for(HPSEcalCluster cluster : clusters) {
-
+ while (it.hasNext()) {
+ event = ((Map.Entry<Integer, ArrayList<BaseRawCalorimeterHit>>) it.next()).getKey();
+ if (_debug) {
+ System.out.println("Event " + event);
+ }
+
+ List<HPSEcalCluster> clusters = getCalibratedClusters(event);
+
+ if (_debug) {
+ System.out.println("Found " + clusters.size() + " clusters");
+ }
+
+ for (HPSEcalCluster cluster : clusters) {
+
int[] pos = new int[2];
pos[0] = cluster.getSeedHit().getIdentifierFieldValue("ix");
pos[1] = cluster.getSeedHit().getIdentifierFieldValue("iy");
//find the tracks matched to those clusters
-
- MatchedTrack track = getTrack(event,cluster.getSeedHit().getCellID());
-
- if(_debug) System.out.println("Found track with with cell id " + cluster.getSeedHit().getCellID());
-
-
- double P = track._track.getPX()*1000;
+
+ MatchedTrack track = getTrack(event, cluster.getSeedHit().getCellID());
+
+ if (_debug) {
+ System.out.println("Found track with with cell id " + cluster.getSeedHit().getCellID());
+ }
+
+ double P = track._track.getPX() * 1000;
double E = cluster.getEnergy();
double samplingFraction = 0.9;
- double Ep = E*samplingFraction;
- double Eoverp = Ep/P;
+ double Ep = E * samplingFraction;
+ double Eoverp = Ep / P;
+
-
- if(_debug)
+ if (_debug) {
System.out.println("P " + P + " E " + E + " Ep " + Ep + " --> E/p=" + Eoverp);
-
-
- pe[pos[0]+23][pos[1]+5].fill(Eoverp);
-
- if(_debug)
- System.out.println("Cluster icol " + pos[0] + " irow " + pos[1] + " entries " + pe[pos[0]+23][pos[1]+5].entries());
-
-
+ }
+
+ pe[pos[0] + 23][pos[1] + 5].fill(Eoverp);
+
+ if (_debug) {
+ System.out.println("Cluster icol " + pos[0] + " irow " + pos[1] + " entries " + pe[pos[0] + 23][pos[1] + 5].entries());
+ }
}
-
-
}
-
copyPE(iter);
-
-
++iter;
}
-
-
-
-
-
-
}
-
-
+
void copyPE(int iter) {
-
+
//copy the histograms, extract gains and reset for new iteration
- IHistogram2D mpePlot = aida.histogram2D("Iter " + iter + " <E over p>",47,-23.5,23.5,11,-5.5,5.5);
- IHistogram2D spePlot = aida.histogram2D("Iter " + iter + " RMS(E over p)",47,-23.5,23.5,11,-5.5,5.5);
+ IHistogram2D mpePlot = aida.histogram2D("Iter " + iter + " <E over p>", 47, -23.5, 23.5, 11, -5.5, 5.5);
+ IHistogram2D spePlot = aida.histogram2D("Iter " + iter + " RMS(E over p)", 47, -23.5, 23.5, 11, -5.5, 5.5);
IHistogram1D pePlot = hf.createCopy("Iter " + iter + " E over p", pe[0][0]);
- IHistogram2D gainPlot = aida.histogram2D("Iter " + iter + " gain",47,-23.5,23.5,11,-5.5,5.5);
+ IHistogram2D gainPlot = aida.histogram2D("Iter " + iter + " gain", 47, -23.5, 23.5, 11, -5.5, 5.5);
+
-
PEHistograms hists = new PEHistograms(iter);
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- hists.pe[icol+23][irow+5] = hf.createCopy("Iter " + iter + " E over p x=" + icol + " y=" + irow, pe[icol+23][irow+5]);
- pePlot = hf.add("Iter " + iter + " E over p", pePlot, pe[icol+23][irow+5]);
- if(pe[icol+23][irow+5].entries()>10) {
- mpePlot.fill(icol,irow,pe[icol+23][irow+5].mean());
- spePlot.fill(icol,irow,pe[icol+23][irow+5].rms());
- double corr = 1.0/pe[icol+23][irow+5].mean(); //Correction to get p/E==1
- double gain = this.getGain(icol, irow)*corr;
- setGain(icol,irow,gain);
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ hists.pe[icol + 23][irow + 5] = hf.createCopy("Iter " + iter + " E over p x=" + icol + " y=" + irow, pe[icol + 23][irow + 5]);
+ pePlot = hf.add("Iter " + iter + " E over p", pePlot, pe[icol + 23][irow + 5]);
+ if (pe[icol + 23][irow + 5].entries() > 10) {
+ mpePlot.fill(icol, irow, pe[icol + 23][irow + 5].mean());
+ spePlot.fill(icol, irow, pe[icol + 23][irow + 5].rms());
+ double corr = 1.0 / pe[icol + 23][irow + 5].mean(); //Correction to get p/E==1
+ double gain = this.getGain(icol, irow) * corr;
+ setGain(icol, irow, gain);
gain = this.getGain(icol, irow);
- gainPlot.fill(icol,irow,gain);
+ gainPlot.fill(icol, irow, gain);
}
-
+
}
}
hists._i = iter;
iterPE.add(hists);
-
-
-
-
-
-/*
+
+ /*
for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- for(PEHistograms peh : iterPE) {
- if(peh._i==iter) {
- if(peh.pe[icol+23][irow+5].entries()>10) {
- mpePlot.fill(icol,irow,peh.pe[icol+23][irow+5].mean());
- spePlot.fill(icol,irow,peh.pe[icol+23][irow+5].rms());
- }
- }
- }
- }
+ for(int icol=-23;icol<=23;++icol) {
+ for(PEHistograms peh : iterPE) {
+ if(peh._i==iter) {
+ if(peh.pe[icol+23][irow+5].entries()>10) {
+ mpePlot.fill(icol,irow,peh.pe[icol+23][irow+5].mean());
+ spePlot.fill(icol,irow,peh.pe[icol+23][irow+5].rms());
+ }
+ }
+ }
+ }
}
- */
-
-
+ */
+
//Plot
- if(xCombo==null) {
- xCombo = new JComboBox(xList);
- xCombo.addActionListener(this);
- xLabel = new JLabel("x");
- xLabel.setLabelFor(xCombo);
- plotFrame.getControlsPanel().add(xLabel);
- plotFrame.getControlsPanel().add(xCombo);
- yCombo = new JComboBox(yList);
- yCombo.addActionListener(this);
- yLabel = new JLabel("y");
- yLabel.setLabelFor(xCombo);
- plotFrame.getControlsPanel().add(yLabel);
- plotFrame.getControlsPanel().add(yCombo);
- xCombo.setSelectedIndex(-15+23);
- yCombo.setSelectedIndex(1+5-1);
+ if (xCombo == null) {
+ xCombo = new JComboBox(xList);
+ xCombo.addActionListener(this);
+ xLabel = new JLabel("x");
+ xLabel.setLabelFor(xCombo);
+ plotFrame.getControlsPanel().add(xLabel);
+ plotFrame.getControlsPanel().add(xCombo);
+ yCombo = new JComboBox(yList);
+ yCombo.addActionListener(this);
+ yLabel = new JLabel("y");
+ yLabel.setLabelFor(xCombo);
+ plotFrame.getControlsPanel().add(yLabel);
+ plotFrame.getControlsPanel().add(yCombo);
+ xCombo.setSelectedIndex(-15 + 23);
+ yCombo.setSelectedIndex(1 + 5 - 1);
}
-
-
-
-
+
IPlotter plotter = af.createPlotterFactory().create();
- plotter.createRegions(1,5,0);
+ plotter.createRegions(1, 5, 0);
plotter.setTitle("Gain iteration " + iter);
//plotter.style().statisticsBoxStyle().setVisible(false);
plotFrame.addPlotter(plotter);
plotterList.add(plotter);
-
-
+
plotter.region(0).plot(mpePlot);
plotter.region(1).plot(spePlot);
plotter.region(2).plot(gainPlot);
plotter.region(3).plot(pePlot);
- plotter.region(4).plot(hists.pe[-15+23][1+5-1+1]);
-
+ plotter.region(4).plot(hists.pe[-15 + 23][1 + 5 - 1 + 1]);
+
plotter.region(0).style().statisticsBoxStyle().setVisible(false);
plotter.region(0).style().setParameter("hist2DStyle", "colorMap");
plotter.region(0).style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
@@ -391,35 +323,46 @@
plotter.region(2).style().statisticsBoxStyle().setVisible(false);
plotter.region(2).style().setParameter("hist2DStyle", "colorMap");
plotter.region(2).style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
-
+
//Extract gain corrections
-
+
plotFrame.pack();
plotFrame.setVisible(false);
-
+
//Reset basic histograms
-
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- pe[icol+23][irow+5].reset();
+
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ pe[icol + 23][irow + 5].reset();
}
}
-
-
}
-
-
+
public void setAllGain(double g) {
-
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- this.setGain(icol,irow,g);
+
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ this.setGain(icol, irow, g);
+ }
+ }
+ }
+
+ public void setAllGain() {
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ long cellid = HPSEcalConditions.makePhysicalID(icol, irow);
+ Double gain = HPSEcalConditions.physicalToGain(cellid);
+ if (gain != null) {
+ this.setGain(icol, irow, gain);
+ } else {
+ this.setGain(icol, irow, 0);
+ }
}
- }
+ }
}
-
+
public void setAllGain(String fileName) {
-
+
FileReader fReader = null;
BufferedReader bReader = null;
try {
@@ -430,10 +373,12 @@
bReader = new BufferedReader(fReader);
String line;
try {
- while((line = bReader.readLine()) != null) {
- if(line.contains("#")) continue;
+ while ((line = bReader.readLine()) != null) {
+ if (line.contains("#")) {
+ continue;
+ }
String[] vec = line.split("\\s+");
- if(vec.length!=4) {
+ if (vec.length != 4) {
System.out.println("Wrong format for line: " + line);
throw new RuntimeException("");
}
@@ -441,130 +386,111 @@
int x = Integer.valueOf(vec[1]);
int y = Integer.valueOf(vec[2]);
double g = Double.valueOf(vec[3]);
- if(E==0) this.setGain(x,y,g);
+ if (E == 0) {
+ this.setGain(x, y, g);
+ }
}
} catch (IOException ex) {
Logger.getLogger(GainCalib.class.getName()).log(Level.SEVERE, null, ex);
}
-
-
}
-
- public void setGain(int icol,int irow,double corr) {
-
- if(helper==null) {
- helper = _detector.getSubdetector(_ecalName).getDetectorElement().getIdentifierHelper();
- expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields());
- expId.setValue(helper.getFieldIndex("system"), _detector.getSubdetector(_ecalName).getSystemID());
- }
-
-
- //int x = Integer.valueOf(lineTok.nextToken());
- //int y = Integer.valueOf(lineTok.nextToken());
- expId.setValue(helper.getFieldIndex("ix"), icol);
- expId.setValue(helper.getFieldIndex("iy"), irow);
- long cellid = helper.pack(expId).getValue();
-
+
+ public void setGain(int icol, int irow, double corr) {
+ long cellid = HPSEcalConditions.makePhysicalID(icol, irow);
+
//if(!this._gains.containsKey(cellid)) {
// System.out.println("ERROR updating gain from icol " + icol + " irow " + irow + " this cellid " + cellid + " doesn't have a previous gain?");
// System.exit(1);
//}
- double gain = corr;//this._gains.get(cellid);
+// double gain = corr;//this._gains.get(cellid);
this._gains.put(cellid, corr);
-
-
}
-
- public double getGain(int icol,int irow) {
- if(helper==null) {
- helper = _detector.getSubdetector(_ecalName).getDetectorElement().getIdentifierHelper();
- expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields());
- expId.setValue(helper.getFieldIndex("system"), _detector.getSubdetector(_ecalName).getSystemID());
- }
- expId.setValue(helper.getFieldIndex("ix"), icol);
- expId.setValue(helper.getFieldIndex("iy"), irow);
- long cellid = helper.pack(expId).getValue();
- if(!this._gains.containsKey(cellid)) {
+
+ public double getGain(int icol, int irow) {
+ long cellid = HPSEcalConditions.makePhysicalID(icol, irow);
+ if (!this._gains.containsKey(cellid)) {
System.out.println("ERROR getting gain from icol " + icol + " irow " + irow + " this cellid " + cellid + " doesn't have a previous gain?");
System.exit(1);
}
return this._gains.get(cellid);
-
+
}
-
-
- public MatchedTrack getTrack(int evt,long id) {
+
+ public MatchedTrack getTrack(int evt, long id) {
MatchedTrack mt = null;
-
- if(this._tracks.containsKey(evt)) {
- for(MatchedTrack trk : this._tracks.get(evt)) {
- if(trk._cellid == id) {
+
+ if (this._tracks.containsKey(evt)) {
+ for (MatchedTrack trk : this._tracks.get(evt)) {
+ if (trk._cellid == id) {
mt = trk;
}
}
}
return mt;
-
+
}
-
+
public double getGain(BaseRawCalorimeterHit hit) {
long id = hit.getCellID();
- if(!this._gains.containsKey(id)) {
+ if (!this._gains.containsKey(id)) {
System.out.println("ERROR hit with id " + id + " doesn't exist in gain map!!!");
}
return this._gains.get(id);
}
-
+
public List<HPSEcalCluster> getCalibratedClusters(int eventNumber) {
-
- if(!_hits.containsKey(eventNumber)) {
+
+ if (!_hits.containsKey(eventNumber)) {
System.out.println("ERROR no raw hits for event " + eventNumber);
System.exit(1);
}
-
-
- if(_hits.get(eventNumber).isEmpty()) {
+
+
+ if (_hits.get(eventNumber).isEmpty()) {
System.out.println("empy hits for " + eventNumber);
System.exit(1);
}
-
- if(_debug) System.out.println("Converting " + _hits.get(eventNumber).size() + " raw ecal hits");
-
+ if (_debug) {
+ System.out.println("Converting " + _hits.get(eventNumber).size() + " raw ecal hits");
+ }
-
ArrayList<CalorimeterHit> newHits = new ArrayList<CalorimeterHit>();
-
+
for (BaseRawCalorimeterHit hit : _hits.get(eventNumber)) {
- if(_debug) System.out.println("Converting hit id " + hit.getCellID());
+ if (_debug) {
+ System.out.println("Converting hit id " + hit.getCellID());
+ }
double gain = getGain(hit);
- CalorimeterHit newHit = _converter.HitDtoA(hit,_integralWindow,gain);
- if(_applyBadCrystalMap && HPSEcalRawConverterDriver.isBadCrystal(newHit)) continue;
+ CalorimeterHit newHit = HPSEcalRawConverter.HitDtoA(hit, _integralWindow, gain);
+ if (_applyBadCrystalMap && HPSEcalRawConverterDriver.isBadCrystal(newHit)) {
+ continue;
+ }
//if(applyBadCrystalMap && HPSEcalRawConverterDriver.isBadCrystal(newHit)) continue;
//if (dropBadFADC && HPSEcalRawConverterDriver.isBadFADC(newHit)) continue;
if (newHit.getRawEnergy() > _threshold) {
newHits.add(newHit);
}
-
- if(_debug)
+
+ if (_debug) {
System.out.println("Converted hit id " + hit.getCellID() + " with gain " + gain);
-
-
+ }
+ }
+
+ if (_debug) {
+ System.out.println(newHits.size() + " calibrated calorimeter hits for event " + eventNumber);
}
-
- if(_debug) System.out.println(newHits.size() + " calibrated calorimeter hits for event " + eventNumber);
//To be able to use decoders I need to associate with readout. Use event put to do that?! -> FIX THIS
- int run =999999;
- BaseLCSimEvent event = new BaseLCSimEvent(999999,eventNumber,_detector.getDetectorName());
+ BaseLCSimEvent event = new BaseLCSimEvent(999999, eventNumber, _detector.getDetectorName());
event.put(_ecalTmpCollectionName, newHits, CalorimeterHit.class, 0, _ecalReadoutName);
-
+
//Now we have a set of calibrated ecal hits
// Clusterize them
-
+
// Make a hit map for quick lookup by ID.
Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
for (CalorimeterHit hit : newHits) {
@@ -572,20 +498,11 @@
}
List<HPSEcalCluster> clusters = _clusterer.createClusters(hitMap);
-
- if(_debug) System.out.println(clusters.size() + " clusters found from event " + eventNumber);
-
- //clean up for this event!
- //LCSimEvent should clear by itself!?
- newHits.clear();
-
+ if (_debug) {
+ System.out.println(clusters.size() + " clusters found from event " + eventNumber);
+ }
+
return clusters;
-
-
}
-
-
-
-
}
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.1 -r1.2
--- GainCalibrationDriver.java 24 Jul 2012 23:28:36 -0000 1.1
+++ GainCalibrationDriver.java 9 Aug 2012 00:51:15 -0000 1.2
@@ -1,11 +1,6 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.lcsim.hps.recon.ecal;
import hep.aida.*;
-import hep.aida.ref.histogram.Histogram1D;
import hep.aida.ref.plotter.PlotterRegion;
import java.awt.Button;
import java.awt.FlowLayout;
@@ -24,13 +19,8 @@
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
-import org.lcsim.detector.identifier.ExpandedIdentifier;
-import org.lcsim.detector.identifier.IExpandedIdentifier;
-import org.lcsim.detector.identifier.IIdentifier;
-import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
-import org.lcsim.event.RawTrackerHit;
import org.lcsim.event.Track;
import org.lcsim.event.base.BaseRawCalorimeterHit;
import org.lcsim.geometry.Detector;
@@ -39,20 +29,16 @@
import org.lcsim.hps.monitoring.AIDAFrame;
import org.lcsim.hps.monitoring.Redrawable;
import org.lcsim.hps.monitoring.Resettable;
-import org.lcsim.hps.recon.ecal.HPSEcalRawConverterDriver;
-import org.lcsim.hps.recon.ecal.HPSEcalCluster;
-import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import org.lcsim.hps.recon.tracking.EcalTrackMatch;
import org.lcsim.util.Driver;
import org.lcsim.util.aida.AIDA;
-import org.lcsim.util.lcio.LCIOConstants;
/**
*
* @author phansson+
*/
public class GainCalibrationDriver extends Driver implements Resettable, ActionListener, Redrawable {
-
+
int nevents = 0;
boolean debug = true;
protected IDDecoder dec = null;
@@ -62,31 +48,24 @@
String ecalReadoutName = "EcalHits";
String ecalTmpCollectionName = "EcalCalHitsTmp";
private String trackCollectionName = "MatchedTracks";
- private String ecalClusterCollectionName = "EcalClusters";
private String outputPlotFileName = "test.aida";
private String ecalGainFileName = "";
private String ecalGainCalibCorrFileName = "";
-
//I would like to steel these from the converter -> FIX THIS!
private boolean applyBadCrystalMap = true;
private boolean dropBadFADC = false;
double threshold = Double.NEGATIVE_INFINITY;
private int integralWindow = 30;
private int _numIterations = 0;
-
-
HPSEcalClusterer clusterer = null;
EcalTrackMatch trkMatchTool = null;
- HPSEcalRawConverter converter = null;
-
+ HPSEcalRawConverter converter = null;
GainCalib gainCalib = new GainCalib();
-
private boolean hideFrame = false;
private int refreshRate = 100;
private AIDA aida = AIDA.defaultInstance();
private IAnalysisFactory af = aida.analysisFactory();
IHistogramFactory hf = aida.histogramFactory();
- private AIDAFrame plotterFrame;
private AIDAFrame pePlotterFrame;
IPlotter plotter;
JComboBox xCombo;
@@ -96,35 +75,32 @@
Integer xList[];
Integer yList[];
JButton blankButton;
-
boolean alive = true;
-
-
-
IHistogram1D pePlots[][][] = new IHistogram1D[47][11][5];
IHistogram2D mpePlot;
IHistogram2D spePlot;
IHistogram2D hitmap;
IHistogram1D[] h_PE_t = new IHistogram1D[5];
IHistogram1D[] h_PE_b = new IHistogram1D[5];
-
- class AL extends Frame implements ActionListener,WindowListener {
+ class AL extends Frame implements ActionListener, WindowListener {
+
Button b;
-
+
public AL(String title) {
super(title);
setLayout(new FlowLayout());
- b= new Button("Click to stop program");
+ b = new Button("Click to stop program");
add(b);
b.addActionListener(this);
}
+
@Override
public void actionPerformed(ActionEvent ae) {
- if(ae.getSource() == b) {
+ if (ae.getSource() == b) {
System.out.println("Clicked to exit!");
dispose();
- alive=false;//System.exit(0);
+ alive = false;//System.exit(0);
}
//throw new UnsupportedOperationException("Not supported yet.");
}
@@ -138,7 +114,7 @@
public void windowClosing(WindowEvent we) {
System.out.println("windowClosing to exit!");
dispose();
- alive=false;//System.exit(0);
+ alive = false;//System.exit(0);
//throw new UnsupportedOperationException("Not supported yet.");
}
@@ -146,7 +122,7 @@
public void windowClosed(WindowEvent we) {
System.out.println("windowClosing to exit!");
dispose();
- alive=false;//System.exit(0);
+ alive = false;//System.exit(0);
//throw new UnsupportedOperationException("Not supported yet.");
}
@@ -169,63 +145,51 @@
public void windowDeactivated(WindowEvent we) {
//throw new UnsupportedOperationException("Not supported yet.");
}
-
- }
-
-
-
- public void startOfData() {
}
-
+
+ @Override
public void detectorChanged(Detector detector) {
- // Get the Subdetector.
- ecal = detector.getSubdetector(ecalName);
-
+ // Get the Subdetector.
+ ecal = detector.getSubdetector(ecalName);
+
clusterer.setEcalName("Ecal");
clusterer.detectorChanged(detector);
-
+
// Cache ref to decoder.
- dec = ecal.getIDDecoder();
-
-
-
-
+ dec = ecal.getIDDecoder();
+
gainCalib.setClusterer(clusterer);
- gainCalib.setConverter(converter);
gainCalib.setDetector(detector);
gainCalib.setEcalReadoutName(ecalReadoutName);
- gainCalib.setEcalName(ecalName);
gainCalib.setThreshold(threshold);
gainCalib.setIntegralWindow(integralWindow);
gainCalib.setApplyBadCrystalMap(this.applyBadCrystalMap);
-
- //Use gain calibration file
- System.out.println("Using gain calibration file \""+ecalGainFileName+"\"");
- if(!"".equals(ecalGainFileName)) {
+
+ //Use gain calibration file
+ System.out.println("Using gain calibration file \"" + ecalGainFileName + "\"");
+ if (!"".equals(ecalGainFileName)) {
gainCalib.setAllGain(ecalGainFileName);
} else {
- gainCalib.setAllGain(converter.gain);
+ gainCalib.setAllGain();
}
-
-
+
pePlotterFrame = new AIDAFrame();
pePlotterFrame.setTitle("Gain Frame");
//plotterFrame = new AIDAFrame();
//plotterFrame.setTitle("Gain General");
-
+
IPlotterStyle style;
-
-
+
IPlotter plotter_hitmap_gr = af.createPlotterFactory().create();
- plotter_hitmap_gr.createRegions(1,3,0);
+ plotter_hitmap_gr.createRegions(1, 3, 0);
plotter_hitmap_gr.setTitle("Cluster hit map");
plotter_hitmap_gr.style().statisticsBoxStyle().setVisible(false);
pePlotterFrame.addPlotter(plotter_hitmap_gr);
-
+
hitmap = aida.histogram2D("Cluster hit map", 47, -23.5, 23.5, 11, -5.5, 5.5);
plotter_hitmap_gr.region(0).plot(hitmap);
-
+
style = plotter_hitmap_gr.region(0).style();
style.setParameter("hist2DStyle", "colorMap");
style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
@@ -233,34 +197,33 @@
((PlotterRegion) plotter_hitmap_gr.region(0)).getPlot().setAllowPopupMenus(true);
IPlotter[] plotter_PoverE = new IPlotter[5];
-
-
- for(int iE=0;iE<=4;++iE) {
-
- String str = iE==0?"":(" iE="+iE);
-
- h_PE_t[iE] = aida.histogram1D("E over p top"+str,50,0,2);
- h_PE_b[iE] = aida.histogram1D("E over p bottom"+str,50,0,2);
-
+
+ for (int iE = 0; iE <= 4; ++iE) {
+
+ String str = iE == 0 ? "" : (" iE=" + iE);
+
+ h_PE_t[iE] = aida.histogram1D("E over p top" + str, 50, 0, 2);
+ h_PE_b[iE] = aida.histogram1D("E over p bottom" + str, 50, 0, 2);
+
plotter_PoverE[iE] = af.createPlotterFactory().create();
- plotter_PoverE[iE].createRegions(1,2,0);
- plotter_PoverE[iE].setTitle("E over P"+str);
+ plotter_PoverE[iE].createRegions(1, 2, 0);
+ plotter_PoverE[iE].setTitle("E over P" + str);
plotter_PoverE[iE].style().statisticsBoxStyle().setVisible(true);
pePlotterFrame.addPlotter(plotter_PoverE[iE]);
-
+
plotter_PoverE[iE].region(0).plot(h_PE_t[iE]);
plotter_PoverE[iE].region(1).plot(h_PE_b[iE]);
}
-
+
plotter = af.createPlotterFactory().create();
- plotter.createRegions(1,3,0);
+ plotter.createRegions(1, 3, 0);
plotter.setTitle("Gain Plots");
-
+
pePlotterFrame.addPlotter(plotter);
-
- mpePlot = aida.histogram2D("<E over p>",47,-23.5,23.5,11,-5.5,5.5);
+
+ mpePlot = aida.histogram2D("<E over p>", 47, -23.5, 23.5, 11, -5.5, 5.5);
plotter.region(0).plot(mpePlot);
- spePlot = aida.histogram2D("RMS(E over p)",47,-23.5,23.5,11,-5.5,5.5);
+ spePlot = aida.histogram2D("RMS(E over p)", 47, -23.5, 23.5, 11, -5.5, 5.5);
plotter.region(1).plot(spePlot);
plotter.region(0).style().statisticsBoxStyle().setVisible(false);
plotter.region(0).style().setParameter("hist2DStyle", "colorMap");
@@ -268,40 +231,36 @@
plotter.region(1).style().statisticsBoxStyle().setVisible(false);
plotter.region(1).style().setParameter("hist2DStyle", "colorMap");
plotter.region(1).style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
-
-
-
- for(int iE=0;iE<=4;++iE) {
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- if(iE==0) {
- pePlots[icol+23][irow+5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow, 50, 0,2);
+
+ for (int iE = 0; iE <= 4; ++iE) {
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ if (iE == 0) {
+ pePlots[icol + 23][irow + 5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow, 50, 0, 2);
} else {
- pePlots[icol+23][irow+5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow + " iE="+iE, 50, 0,2);
+ pePlots[icol + 23][irow + 5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow + " iE=" + iE, 50, 0, 2);
}
}
}
}
-
-
+
xList = new Integer[46];
yList = new Integer[10];
- int in=0;
- for(int i=-5;i<=5;++i) {
- if(i!=0) {
+ int in = 0;
+ for (int i = -5; i <= 5; ++i) {
+ if (i != 0) {
yList[in] = i;
++in;
}
}
- in=0;
- for(int i=-23;i<=23;++i) {
- if(i!=0) {
+ in = 0;
+ for (int i = -23; i <= 23; ++i) {
+ if (i != 0) {
xList[in] = i;
++in;
}
}
-
-
+
xCombo = new JComboBox(xList);
xCombo.addActionListener(this);
xLabel = new JLabel("x");
@@ -314,159 +273,148 @@
yLabel.setLabelFor(xCombo);
pePlotterFrame.getControlsPanel().add(yLabel);
pePlotterFrame.getControlsPanel().add(yCombo);
-
-
- plotter.region(2).plot(pePlots[-5 + 23][2 + 5 - 1][0]);
+
+ plotter.region(2).plot(pePlots[-5 + 23][2 + 5 - 1][0]);
xCombo.setSelectedIndex(-5 + 23);
yCombo.setSelectedIndex(2 + 5 - 1);
-
+
blankButton = new JButton("Hide histogram");
pePlotterFrame.getControlsPanel().add(blankButton);
blankButton.addActionListener(this);
-
-
-
-
-
- if(!hideFrame) {
+
+ if (!hideFrame) {
//plotterFrame.pack();
//plotterFrame.setVisible(true);
pePlotterFrame.pack();
pePlotterFrame.setVisible(true);
-
}
-
-
-
-
-
-
-
}
-
+
public GainCalibrationDriver() {
converter = new HPSEcalRawConverter();
trkMatchTool = new EcalTrackMatch(false);
clusterer = new HPSEcalClusterer();
gainCalib = new GainCalib();
-
-
-
}
-
-
public void setNumIterations(int i) {
this._numIterations = i;
}
-
+
public void setDebug(boolean flag) {
this.debug = flag;
}
-
- public void setOutputPlotFileName( String name ) {
+
+ public void setOutputPlotFileName(String name) {
this.outputPlotFileName = name;
}
-
- public void setEcalGainFileName( String name ) {
+
+ public void setEcalGainFileName(String name) {
this.ecalGainFileName = name;
}
- public void setEcalGainCalibCorrFileName( String name ) {
+
+ public void setEcalGainCalibCorrFileName(String name) {
this.ecalGainCalibCorrFileName = name;
}
- public void setHideFrame( boolean val ) {
+
+ public void setHideFrame(boolean val) {
this.hideFrame = val;
}
-
-
-
+
public void process(EventHeader event) {
++nevents;
- if( debug ) {
- System.out.println("Processing event " + nevents);
+ if (debug) {
+ System.out.println("Processing event " + nevents);
}
-
- if( refreshRate > 0 && nevents % refreshRate == 0 ) {
+
+ if (refreshRate > 0 && nevents % refreshRate == 0) {
redraw();
}
// Find the raw hits used to build calorimeter hits
-
/*
List<RawTrackerHit> hits = null;
if (event.hasCollection(RawTrackerHit.class, rawCollectionName)) {
- hits = event.get(RawTrackerHit.class, rawCollectionName);
+ hits = event.get(RawTrackerHit.class, rawCollectionName);
}
-
+
if(hits==null) {
- if(debug) System.out.println("No raw ecal hits");
- return;
+ if(debug) System.out.println("No raw ecal hits");
+ return;
}
-*/
+ */
List<BaseRawCalorimeterHit> hits = null;
if (event.hasCollection(BaseRawCalorimeterHit.class, rawCollectionName)) {
hits = event.get(BaseRawCalorimeterHit.class, rawCollectionName);
}
- if(hits==null) {
- if(debug) System.out.println("No raw ecal hits ");
+ if (hits == null) {
+ if (debug) {
+ System.out.println("No raw ecal hits ");
+ }
return;
}
-
- if(debug) System.out.println(hits.size() + " raw ecal hits");
-
- if(hits.isEmpty()) return;
-
-
+ if (debug) {
+ System.out.println(hits.size() + " raw ecal hits");
+ }
+
+ if (hits.isEmpty()) {
+ return;
+ }
-
ArrayList<CalorimeterHit> newHits = new ArrayList<CalorimeterHit>();
-
-
-
-
-
+
for (BaseRawCalorimeterHit hit : hits) {
double g = gainCalib.getGain(hit);
- CalorimeterHit newHit = converter.HitDtoA(hit,integralWindow);
- if(applyBadCrystalMap && HPSEcalRawConverterDriver.isBadCrystal(newHit)) continue;
- if (dropBadFADC && HPSEcalRawConverterDriver.isBadFADC(newHit)) continue;
+ CalorimeterHit newHit = converter.HitDtoA(hit, integralWindow);
+ if (applyBadCrystalMap && HPSEcalRawConverterDriver.isBadCrystal(newHit)) {
+ continue;
+ }
+ if (dropBadFADC && HPSEcalRawConverterDriver.isBadFADC(newHit)) {
+ continue;
+ }
if (newHit.getRawEnergy() > threshold) {
newHits.add(newHit);
}
}
-
- if(debug) System.out.println(newHits.size() + " calibrated calorimeter hits");
+
+ if (debug) {
+ System.out.println(newHits.size() + " calibrated calorimeter hits");
+ }
//To be able to use decoders I need to associate with readout. Use event put to do that?! -> FIX THIS
event.put(ecalTmpCollectionName, newHits, CalorimeterHit.class, 0, ecalReadoutName);
-
+
//Get the newly created hits
-
+
List<CalorimeterHit> newCalHits = null;
if (event.hasCollection(CalorimeterHit.class, ecalTmpCollectionName)) {
newCalHits = event.get(CalorimeterHit.class, ecalTmpCollectionName);
}
- if(newCalHits==null) {
- if(debug) System.out.println("No newCalHits ");
+ if (newCalHits == null) {
+ if (debug) {
+ System.out.println("No newCalHits ");
+ }
System.exit(1);
-
+
+ }
+
+ if (debug) {
+ System.out.println(newCalHits.size() + " newCalHits");
+ }
+
+ if (newCalHits.isEmpty()) {
+ return;
}
-
- if(debug) System.out.println(newCalHits.size() + " newCalHits");
-
- if(newCalHits.isEmpty()) return;
-
-
//Now we have a set of calibrated ecal hits
// Clusterize them to get a starting point -> copy the clusterer
-
+
// Make a hit map for quick lookup by ID.
Map<Long, CalorimeterHit> hitMap = new HashMap<Long, CalorimeterHit>();
for (CalorimeterHit hit : newCalHits) {
@@ -474,170 +422,163 @@
}
List<HPSEcalCluster> clusters = clusterer.createClusters(hitMap);
-
- if(debug) System.out.println(clusters.size() + " clusters found");
-
+ if (debug) {
+ System.out.println(clusters.size() + " clusters found");
+ }
+
// Now we want to produce the corrections for each module: c = p/E
-
-
-
+
List<Track> tracks = null;
- if(event.hasCollection(Track.class, trackCollectionName)) {
- tracks = event.get(Track.class, trackCollectionName);
+ if (event.hasCollection(Track.class, trackCollectionName)) {
+ tracks = event.get(Track.class, trackCollectionName);
}
-
- if(debug) System.out.println( tracks.size() + " tracks in this event");
-
- if(tracks==null) return;
-
-
-
- for(HPSEcalCluster cl : clusters) {
-
-
-
-
+
+ if (debug) {
+ System.out.println(tracks.size() + " tracks in this event");
+ }
+
+ if (tracks == null) {
+ return;
+ }
+
+ for (HPSEcalCluster cl : clusters) {
+
int[] pos = getCrystalPair(cl);
- int side = pos[1]>0 ? 0 : 1; //top or bottom
+ int side = pos[1] > 0 ? 0 : 1; //top or bottom
+
+ if (debug) {
+ System.out.println("Looking at cluster at ix=" + pos[0] + " iy=" + pos[1]);
+ }
- if(debug) System.out.println("Looking at cluster at ix=" + pos[0] + " iy=" + pos[1]);
-
trkMatchTool.setCluster(cl);
trkMatchTool.match(tracks);
-
- if(!trkMatchTool.isMatchedY(50)) {
- if(debug) System.out.println("Cluster not matched to a track");
+
+ if (!trkMatchTool.isMatchedY(50)) {
+ if (debug) {
+ System.out.println("Cluster not matched to a track");
+ }
continue;
}
-
-
- if(debug) System.out.println("Cluster matched to track at distance Y " + trkMatchTool.getDistanceToTrackInY() + " and X " + trkMatchTool.getDistanceToTrackInX());
-
-
- double P = trkMatchTool.getMatchedTrack().getPX()*1000;
+
+ if (debug) {
+ System.out.println("Cluster matched to track at distance Y " + trkMatchTool.getDistanceToTrackInY() + " and X " + trkMatchTool.getDistanceToTrackInX());
+ }
+
+ double P = trkMatchTool.getMatchedTrack().getPX() * 1000;
double E = cl.getEnergy();
double samplingFraction = 0.9;
- double Ep = E*samplingFraction;
- double Eoverp = Ep/P;
-
- if(debug) System.out.println("P " + P + " E " + E + " Ep " + Ep);
-
-
+ double Ep = E * samplingFraction;
+ double Eoverp = Ep / P;
+
+ if (debug) {
+ System.out.println("P " + P + " E " + E + " Ep " + Ep);
+ }
+
+
double Eseed = cl.getSeedHit().getRawEnergy();
double ErawSum = 0;
- for(CalorimeterHit hit : cl.getCalorimeterHits()) {
+ for (CalorimeterHit hit : cl.getCalorimeterHits()) {
ErawSum += hit.getRawEnergy();
}
-
- if(Eseed/ErawSum<0.6) continue;
-
+
+ if (Eseed / ErawSum < 0.6) {
+ continue;
+ }
+
int ebin = -1;
- if(P>500&&P<=700) ebin=1;
- else if(P>700&&P<=900) ebin=2;
- else if(P>900&&P<=1100) ebin=3;
- else ebin=4;
-
- if(side==0) {
+ if (P > 500 && P <= 700) {
+ ebin = 1;
+ } else if (P > 700 && P <= 900) {
+ ebin = 2;
+ } else if (P > 900 && P <= 1100) {
+ ebin = 3;
+ } else {
+ ebin = 4;
+ }
+
+ if (side == 0) {
h_PE_t[0].fill(Eoverp);
h_PE_t[ebin].fill(Eoverp);
-
- }
- else {
+
+ } else {
h_PE_b[0].fill(Eoverp);
h_PE_b[ebin].fill(Eoverp);
}
-
+
hitmap.fill(pos[0], pos[1]);
-
- pePlots[pos[0]+23][pos[1]+5][0].fill(Eoverp);
-
- pePlots[pos[0]+23][pos[1]+5][ebin].fill(Eoverp);
-
-
- gainCalib.setOriginalHits(event.getEventNumber(), hits, converter.gain);
- for(BaseRawCalorimeterHit hit : hits) {
+
+ pePlots[pos[0] + 23][pos[1] + 5][0].fill(Eoverp);
+
+ pePlots[pos[0] + 23][pos[1] + 5][ebin].fill(Eoverp);
+
+
+ gainCalib.setOriginalHits(event.getEventNumber(), hits);
+ for (BaseRawCalorimeterHit hit : hits) {
gainCalib.setTrack(event.getEventNumber(), hit.getCellID(), trkMatchTool.getMatchedTrack());
}
-
-
-
- }
-
-
-
-
- }
-
-
-
-
-
+ }
+ }
+
public int[] getCrystalPair(HPSEcalCluster cluster) {
int[] pos = new int[2];
pos[0] = cluster.getSeedHit().getIdentifierFieldValue("ix");
pos[1] = cluster.getSeedHit().getIdentifierFieldValue("iy");
-
+
//System.out.println("cluster ix,iy " + pos[0] + "," + pos[1] + " from pos " + cluster.getSeedHit().getPositionVec().toString());
return pos;
//getCrystalPair(cluster.getPosition());
}
-
-
-
-
-
-
-
-
+ @Override
public void endOfData() {
-
+
redraw();
-
- if (outputPlotFileName != "")
- try {
- aida.saveAs(outputPlotFileName);
- } catch (IOException ex) {
- Logger.getLogger(GainCalibrationDriver.class.getName()).log(Level.SEVERE, "Couldn't save aida plots to file " + outputPlotFileName, ex);
+
+ if (!"".equals(outputPlotFileName)) {
+ try {
+ aida.saveAs(outputPlotFileName);
+ } catch (IOException ex) {
+ Logger.getLogger(GainCalibrationDriver.class.getName()).log(Level.SEVERE, "Couldn't save aida plots to file " + outputPlotFileName, ex);
+ }
}
//displayFastTrackingPlots();
-
- PrintWriter out=null;
+
+ PrintWriter out = null;
try {
out = new PrintWriter(ecalGainCalibCorrFileName);
} catch (FileNotFoundException ex) {
Logger.getLogger(GainCalibrationDriver.class.getName()).log(Level.SEVERE, null, ex);
}
//Save a new file with corrected gains
- for(int iE=0;iE<=4;++iE) {
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- IHistogram1D h = pePlots[icol+23][irow+5][iE];
- double g = gainCalib.getGain(icol,irow);
+ for (int iE = 0; iE <= 4; ++iE) {
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ IHistogram1D h = pePlots[icol + 23][irow + 5][iE];
+ double g = gainCalib.getGain(icol, irow);
int N = h.entries();
- if(N>6) {
+ if (N > 6) {
double m = h.mean();
- double c = 1.0/m;
- g = g*c;
+ double c = 1.0 / m;
+ g = g * c;
out.println(iE + " " + icol + " " + irow + " " + g);
}
-
+
}
}
}
out.close();
-
+
//gainCalib.runOptimization(this._numIterations);
-
+
//AL alWindow = new AL("Click to quit");
//alWindow.setSize(350,100);
//alWindow.setVisible(true);
//while(alive) {
// sleep
//}
-
-
+
+
}
@Override
@@ -647,59 +588,49 @@
plotter.destroyRegions();
for (int x = -23; x <= 23; x++) { // slot
for (int y = -5; y <= 5; y++) { // crate
- for(int iE=0;iE<=4;++iE) {
+ for (int iE = 0; iE <= 4; ++iE) {
pePlots[x + 23][y + 5][iE].reset();
}
}
}
}
- //throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void actionPerformed(ActionEvent ae) {
-
- if(ae.getSource()==blankButton) {
+
+ if (ae.getSource() == blankButton) {
plotter.region(2).clear();
} else {
//get the col and row to display
Integer x = (Integer) xCombo.getSelectedItem();
Integer y = (Integer) yCombo.getSelectedItem();
plotter.region(2).clear();
- plotter.region(2).plot(pePlots[x+23][y+5][0]);
+ plotter.region(2).plot(pePlots[x + 23][y + 5][0]);
}
-
-
- //throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void redraw() {
-
+
//do something if needed
mpePlot.reset();
spePlot.reset();
-
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
+
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
//System.out.println(" redraw irow " + irow + " icol " + icol + " entries " + pePlots[icol+23][irow+5].entries());
- if(pePlots[icol+23][irow+5][0].entries()>10) {
- mpePlot.fill(icol,irow,pePlots[icol+23][irow+5][0].mean());
- spePlot.fill(icol,irow,pePlots[icol+23][irow+5][0].rms());
-
+ if (pePlots[icol + 23][irow + 5][0].entries() > 10) {
+ mpePlot.fill(icol, irow, pePlots[icol + 23][irow + 5][0].mean());
+ spePlot.fill(icol, irow, pePlots[icol + 23][irow + 5][0].rms());
+
}
}
}
-
-
- //throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setEventRefreshRate(int eventRefreshRate) {
refreshRate = eventRefreshRate;
- //throw new UnsupportedOperationException("Not supported yet.");
}
-
-
}
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.10 -r1.11
--- HPSEcalRawConverter.java 25 Jul 2012 22:22:39 -0000 1.10
+++ HPSEcalRawConverter.java 9 Aug 2012 00:51:15 -0000 1.11
@@ -9,34 +9,27 @@
* @version $Id: HPSEcalRawConverterDriver.java,v 1.2 2012/05/03 00:17:54
* phansson Exp $
*/
- public class HPSEcalRawConverter {
+public class HPSEcalRawConverter {
- boolean debug = false;
- public double gain = 2.0*60.0/800.0; //factor of two from the 2:1 splitting issue discovered
+ private boolean debug = false;
+ private boolean constantGain = false;
+ private double gain;
public HPSEcalRawConverter() {
}
public void setGain(double gain) {
+ constantGain = true;
this.gain = gain;
}
- public double getPedestal(RawTrackerHit hit) {
- return HPSEcalConditions.physicalToPedestal(hit.getCellID());
- }
-
- public double getPedestal(BaseRawCalorimeterHit hit) {
- return HPSEcalConditions.physicalToPedestal(hit.getCellID());
- }
-
- //public short sumADC(RawTrackerHit hit, double scale, double pedestal) {
public short sumADC(RawTrackerHit hit) {
//Sum all pedestal subtracted ADC values
//return scale * (amplitude + 0.5) + pedestal;
if (debug) {
System.out.println("Summing ADC for hit: " + hit.toString());
}
- double pedestal = getPedestal(hit);
+ double pedestal = HPSEcalConditions.physicalToPedestal(hit.getCellID());
short sum = 0;
short samples[] = hit.getADCValues();
for (int isample = 0; isample < samples.length; ++isample) {
@@ -46,55 +39,49 @@
}
}
return sum;
-
}
public CalorimeterHit HitDtoA(RawTrackerHit hit) {
double time = hit.getTime();
long id = hit.getCellID();
- double rawEnergy = gain*sumADC(hit);
+ double rawEnergy;
+ if (constantGain) {
+ rawEnergy = gain * sumADC(hit);
+ } else {
+ rawEnergy = HPSEcalConditions.physicalToGain(id) * sumADC(hit);
+ }
double[] pos = hit.getDetectorElement().getGeometry().getPosition().v();
-// double [] pos = new double[3];
-// pos[0] = pvec.x();
-// pos[1] = pvec.y();
-// pos[2] = pvec.z();
CalorimeterHit h = new HPSRawCalorimeterHit(rawEnergy + 0.0000001, pos, time, id, 0);
//+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
return h;
}
public CalorimeterHit HitDtoA(BaseRawCalorimeterHit hit, int window) {
- if (hit.getTimeStamp()%64 !=0) {
- System.out.println("unexpected timestamp "+hit.getTimeStamp());
+ if (hit.getTimeStamp() % 64 != 0) {
+ System.out.println("unexpected timestamp " + hit.getTimeStamp());
}
- double time = hit.getTimeStamp()/16.0;
+ double time = hit.getTimeStamp() / 16.0;
long id = hit.getCellID();
- double rawEnergy = gain*(hit.getAmplitude() - window * getPedestal(hit));
-// Hep3Vector pvec = hit.getDetectorElement().getGeometry().getPosition();
-// double [] pos = new double[3];
-// pos[0] = pvec.x();
-// pos[1] = pvec.y();
-// pos[2] = pvec.z();
+ double rawEnergy;
+ if (constantGain) {
+ rawEnergy = gain * (hit.getAmplitude() - window * HPSEcalConditions.physicalToPedestal(id));
+ } else {
+ rawEnergy = HPSEcalConditions.physicalToGain(id) * (hit.getAmplitude() - window * HPSEcalConditions.physicalToPedestal(id));
+ }
CalorimeterHit h = new HPSRawCalorimeterHit(rawEnergy + 0.0000001, hit.getPosition(), time, id, 0);
//+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
return h;
}
- public CalorimeterHit HitDtoA(BaseRawCalorimeterHit hit, int window,double g) {
- if (hit.getTimeStamp()%64 !=0) {
- System.out.println("unexpected timestamp "+hit.getTimeStamp());
+ public static CalorimeterHit HitDtoA(BaseRawCalorimeterHit hit, int window, double g) {
+ if (hit.getTimeStamp() % 64 != 0) {
+ System.out.println("unexpected timestamp " + hit.getTimeStamp());
}
- double time = hit.getTimeStamp()/16.0;
+ double time = hit.getTimeStamp() / 16.0;
long id = hit.getCellID();
- double rawEnergy = g*(hit.getAmplitude() - window * getPedestal(hit));
-// Hep3Vector pvec = hit.getDetectorElement().getGeometry().getPosition();
-// double [] pos = new double[3];
-// pos[0] = pvec.x();
-// pos[1] = pvec.y();
-// pos[2] = pvec.z();
+ double rawEnergy = g * (hit.getAmplitude() - window * HPSEcalConditions.physicalToPedestal(id));
CalorimeterHit h = new HPSRawCalorimeterHit(rawEnergy + 0.0000001, hit.getPosition(), time, id, 0);
//+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
return h;
}
-
- }
+}
hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -u -r1.14 -r1.15
--- HPSEcalConditions.java 6 Aug 2012 23:14:18 -0000 1.14
+++ HPSEcalConditions.java 9 Aug 2012 00:51:15 -0000 1.15
@@ -17,7 +17,7 @@
/**
*
* @author meeg
- * @version $Id: HPSEcalConditions.java,v 1.14 2012/08/06 23:14:18 meeg Exp $
+ * @version $Id: HPSEcalConditions.java,v 1.15 2012/08/09 00:51:15 meeg Exp $
*/
public class HPSEcalConditions extends Driver {
@@ -33,6 +33,9 @@
private static HashSet<Long> badChannelsSet = new HashSet<Long>();
private static boolean badChannelsLoaded = false;
private static IIdentifierHelper helper = null;
+ //gain
+ private static HashMap<Long, Double> physicalToGainMap = new HashMap<Long, Double>();
+ private static boolean gainsLoaded = false;
//subdetector name (for when this is used as a driver)
private String subdetectorName = "Ecal";
private static Subdetector subdetector;
@@ -53,6 +56,7 @@
helper = subdetector.getDetectorElement().getIdentifierHelper();
fillDaqCellMap(subdetector);
loadBadChannels(subdetector);
+ loadGains();
}
public void setSubdetectorName(String subdetectorName) {
@@ -78,6 +82,10 @@
public static boolean badChannelsLoaded() {
return badChannelsLoaded;
}
+
+ public static boolean gainsLoaded() {
+ return gainsLoaded;
+ }
public static void loadPedestals() {
ConditionsManager conditions = ConditionsManager.defaultInstance();
@@ -172,6 +180,46 @@
badChannelsLoaded = true;
}
+ public static void loadGains() {
+ BufferedReader bufferedReader;
+ ConditionsManager conditions = ConditionsManager.defaultInstance();
+ try {
+ bufferedReader = new BufferedReader(conditions.getRawConditions("calibECal/default.gain").getReader());
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't get gain file", e);
+ }
+
+ String line;
+ while (true) {
+ try {
+ line = bufferedReader.readLine();
+ } catch (IOException e) {
+ throw new RuntimeException("couldn't parse gain file", e);
+ }
+ if (line == null) {
+ break;
+ }
+
+ if (line.indexOf("#") != -1) {
+ line = line.substring(0, line.indexOf("#"));
+ }
+
+ StringTokenizer lineTok = new StringTokenizer(line);
+
+ if (lineTok.countTokens() != 0) {
+ if (lineTok.countTokens() != 3) {
+ throw new RuntimeException("Invalid line in gain file: " + line);
+ } else {
+ int x = Integer.valueOf(lineTok.nextToken());
+ int y = Integer.valueOf(lineTok.nextToken());
+ double gain = Double.valueOf(lineTok.nextToken());
+ physicalToGainMap.put(makePhysicalID(x, y), gain);
+ }
+ }
+ }
+ gainsLoaded = true;
+ }
+
public static boolean isBadChannel(long id) {
return badChannelsSet.contains(id);
}
@@ -274,4 +322,8 @@
public static Double physicalToPedestal(long physicalID) {
return daqToPedestalMap.get(physicalToDaqMap.get(physicalID));
}
+
+ public static Double physicalToGain(long physicalID) {
+ return physicalToGainMap.get(physicalID);
+ }
}
hps-java/src/main/java/org/lcsim/hps/users/phansson
diff -u -r1.1 -r1.2
--- ECalGainDriver.java 25 Jul 2012 22:27:49 -0000 1.1
+++ ECalGainDriver.java 9 Aug 2012 00:51:15 -0000 1.2
@@ -6,54 +6,36 @@
import org.lcsim.hps.recon.ecal.*;
import hep.aida.*;
-import hep.aida.ref.histogram.Histogram1D;
import hep.aida.ref.plotter.PlotterRegion;
-import java.awt.Button;
-import java.awt.FlowLayout;
-import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
import java.io.*;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
-import org.lcsim.detector.identifier.ExpandedIdentifier;
-import org.lcsim.detector.identifier.IExpandedIdentifier;
-import org.lcsim.detector.identifier.IIdentifier;
-import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
-import org.lcsim.event.RawTrackerHit;
import org.lcsim.event.Track;
-import org.lcsim.event.base.BaseRawCalorimeterHit;
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.IDDecoder;
import org.lcsim.geometry.Subdetector;
import org.lcsim.hps.monitoring.AIDAFrame;
import org.lcsim.hps.monitoring.Redrawable;
import org.lcsim.hps.monitoring.Resettable;
-import org.lcsim.hps.recon.ecal.HPSEcalRawConverterDriver;
import org.lcsim.hps.recon.ecal.HPSEcalCluster;
-import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import org.lcsim.hps.recon.tracking.EcalTrackMatch;
import org.lcsim.util.Driver;
import org.lcsim.util.aida.AIDA;
-import org.lcsim.util.lcio.LCIOConstants;
/**
*
* @author phansson+
*/
public class ECalGainDriver extends Driver implements Resettable, ActionListener, Redrawable {
-
+
int nevents = 0;
boolean debug = true;
protected IDDecoder dec = null;
@@ -66,18 +48,9 @@
private String ecalClusterCollectionName = "EcalClusters";
private String outputPlotFileName = "test.aida";
private String ecalGainFileName = "clusterList.txt";
-
//Print out cluster and track to file
- PrintWriter gainWriter=null;
-
-
-
-
+ PrintWriter gainWriter = null;
EcalTrackMatch trkMatchTool = null;
- HPSEcalRawConverter converter = null;
-
-
-
private boolean hideFrame = false;
private int refreshRate = 100;
private AIDA aida = AIDA.defaultInstance();
@@ -93,58 +66,44 @@
Integer xList[];
Integer yList[];
JButton blankButton;
-
boolean alive = true;
-
-
-
IHistogram1D pePlots[][][] = new IHistogram1D[47][11][5];
IHistogram2D mpePlot;
IHistogram2D spePlot;
IHistogram2D hitmap;
IHistogram1D[] h_PE_t = new IHistogram1D[5];
IHistogram1D[] h_PE_b = new IHistogram1D[5];
-
-
-
-
-
+ @Override
public void startOfData() {
}
-
+
+ @Override
public void detectorChanged(Detector detector) {
- // Get the Subdetector.
- ecal = detector.getSubdetector(ecalName);
-
-
-
+ // Get the Subdetector.
+ ecal = detector.getSubdetector(ecalName);
+
// Cache ref to decoder.
- dec = ecal.getIDDecoder();
-
-
-
-
-
-
+ dec = ecal.getIDDecoder();
+
pePlotterFrame = new AIDAFrame();
pePlotterFrame.setTitle("Gain Frame");
//plotterFrame = new AIDAFrame();
//plotterFrame.setTitle("Gain General");
-
+
IPlotterStyle style;
-
-
+
+
IPlotter plotter_hitmap_gr = af.createPlotterFactory().create();
- plotter_hitmap_gr.createRegions(1,3,0);
+ plotter_hitmap_gr.createRegions(1, 3, 0);
plotter_hitmap_gr.setTitle("Cluster hit map");
plotter_hitmap_gr.style().statisticsBoxStyle().setVisible(false);
pePlotterFrame.addPlotter(plotter_hitmap_gr);
-
+
hitmap = aida.histogram2D("Cluster hit map", 47, -23.5, 23.5, 11, -5.5, 5.5);
plotter_hitmap_gr.region(0).plot(hitmap);
-
+
style = plotter_hitmap_gr.region(0).style();
style.setParameter("hist2DStyle", "colorMap");
style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
@@ -152,34 +111,34 @@
((PlotterRegion) plotter_hitmap_gr.region(0)).getPlot().setAllowPopupMenus(true);
IPlotter[] plotter_PoverE = new IPlotter[5];
-
-
- for(int iE=0;iE<=4;++iE) {
-
- String str = iE==0?"":(" iE="+iE);
-
- h_PE_t[iE] = aida.histogram1D("E over p top"+str,50,0,2);
- h_PE_b[iE] = aida.histogram1D("E over p bottom"+str,50,0,2);
-
+
+
+ for (int iE = 0; iE <= 4; ++iE) {
+
+ String str = iE == 0 ? "" : (" iE=" + iE);
+
+ h_PE_t[iE] = aida.histogram1D("E over p top" + str, 50, 0, 2);
+ h_PE_b[iE] = aida.histogram1D("E over p bottom" + str, 50, 0, 2);
+
plotter_PoverE[iE] = af.createPlotterFactory().create();
- plotter_PoverE[iE].createRegions(1,2,0);
- plotter_PoverE[iE].setTitle("E over P"+str);
+ plotter_PoverE[iE].createRegions(1, 2, 0);
+ plotter_PoverE[iE].setTitle("E over P" + str);
plotter_PoverE[iE].style().statisticsBoxStyle().setVisible(true);
pePlotterFrame.addPlotter(plotter_PoverE[iE]);
-
+
plotter_PoverE[iE].region(0).plot(h_PE_t[iE]);
plotter_PoverE[iE].region(1).plot(h_PE_b[iE]);
}
-
+
plotter = af.createPlotterFactory().create();
- plotter.createRegions(1,3,0);
+ plotter.createRegions(1, 3, 0);
plotter.setTitle("Gain Plots");
-
+
pePlotterFrame.addPlotter(plotter);
-
- mpePlot = aida.histogram2D("<E over p>",47,-23.5,23.5,11,-5.5,5.5);
+
+ mpePlot = aida.histogram2D("<E over p>", 47, -23.5, 23.5, 11, -5.5, 5.5);
plotter.region(0).plot(mpePlot);
- spePlot = aida.histogram2D("RMS(E over p)",47,-23.5,23.5,11,-5.5,5.5);
+ spePlot = aida.histogram2D("RMS(E over p)", 47, -23.5, 23.5, 11, -5.5, 5.5);
plotter.region(1).plot(spePlot);
plotter.region(0).style().statisticsBoxStyle().setVisible(false);
plotter.region(0).style().setParameter("hist2DStyle", "colorMap");
@@ -187,40 +146,40 @@
plotter.region(1).style().statisticsBoxStyle().setVisible(false);
plotter.region(1).style().setParameter("hist2DStyle", "colorMap");
plotter.region(1).style().dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
-
-
-
- for(int iE=0;iE<=4;++iE) {
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
- if(iE==0) {
- pePlots[icol+23][irow+5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow, 50, 0,2);
+
+
+
+ for (int iE = 0; iE <= 4; ++iE) {
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
+ if (iE == 0) {
+ pePlots[icol + 23][irow + 5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow, 50, 0, 2);
} else {
- pePlots[icol+23][irow+5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow + " iE="+iE, 50, 0,2);
+ pePlots[icol + 23][irow + 5][iE] = aida.histogram1D("E over p x=" + icol + " y=" + irow + " iE=" + iE, 50, 0, 2);
}
}
}
}
-
-
+
+
xList = new Integer[46];
yList = new Integer[10];
- int in=0;
- for(int i=-5;i<=5;++i) {
- if(i!=0) {
+ int in = 0;
+ for (int i = -5; i <= 5; ++i) {
+ if (i != 0) {
yList[in] = i;
++in;
}
}
- in=0;
- for(int i=-23;i<=23;++i) {
- if(i!=0) {
+ in = 0;
+ for (int i = -23; i <= 23; ++i) {
+ if (i != 0) {
xList[in] = i;
++in;
}
}
-
-
+
+
xCombo = new JComboBox(xList);
xCombo.addActionListener(this);
xLabel = new JLabel("x");
@@ -233,21 +192,17 @@
yLabel.setLabelFor(xCombo);
pePlotterFrame.getControlsPanel().add(yLabel);
pePlotterFrame.getControlsPanel().add(yCombo);
-
-
- plotter.region(2).plot(pePlots[-5 + 23][2 + 5 - 1][0]);
+
+
+ plotter.region(2).plot(pePlots[-5 + 23][2 + 5 - 1][0]);
xCombo.setSelectedIndex(-5 + 23);
yCombo.setSelectedIndex(2 + 5 - 1);
-
+
blankButton = new JButton("Hide histogram");
pePlotterFrame.getControlsPanel().add(blankButton);
blankButton.addActionListener(this);
-
-
-
-
-
- if(!hideFrame) {
+
+ if (!hideFrame) {
//plotterFrame.pack();
//plotterFrame.setVisible(true);
@@ -256,111 +211,96 @@
pePlotterFrame.setVisible(true);
}
-
-
-
-
-
-
-
}
-
+
public ECalGainDriver() {
- converter = new HPSEcalRawConverter();
trkMatchTool = new EcalTrackMatch(false);
-
-
-
+
try {
gainWriter = new PrintWriter(ecalGainFileName);
} catch (FileNotFoundException ex) {
Logger.getLogger(ECalGainDriver.class.getName()).log(Level.SEVERE, null, ex);
}
-
-
-
}
-
-
-
-
public void setDebug(boolean flag) {
this.debug = flag;
}
-
- public void setOutputPlotFileName( String name ) {
+
+ public void setOutputPlotFileName(String name) {
this.outputPlotFileName = name;
}
-
- public void setEcalGainFileName( String name ) {
+
+ public void setEcalGainFileName(String name) {
this.ecalGainFileName = name;
}
-
- public void setHideFrame( boolean val ) {
+
+ public void setHideFrame(boolean val) {
this.hideFrame = val;
}
-
-
-
+
+ @Override
public void process(EventHeader event) {
++nevents;
- if( debug ) {
- System.out.println("Processing event " + nevents);
+ if (debug) {
+ System.out.println("Processing event " + nevents);
}
-
- if( refreshRate > 0 && nevents % refreshRate == 0 ) {
+
+ if (refreshRate > 0 && nevents % refreshRate == 0) {
redraw();
}
-
-
List<HPSEcalCluster> clusters = event.get(HPSEcalCluster.class, ecalClusterCollectionName);
-
- if(debug) System.out.println(clusters.size() + " clusters found");
-
+ if (debug) {
+ System.out.println(clusters.size() + " clusters found");
+ }
+
List<Track> tracks = null;
- if(event.hasCollection(Track.class, trackCollectionName)) {
- tracks = event.get(Track.class, trackCollectionName);
+ if (event.hasCollection(Track.class, trackCollectionName)) {
+ tracks = event.get(Track.class, trackCollectionName);
+ } else {
+ return;
}
-
- if(debug) System.out.println( tracks.size() + " tracks in this event");
-
- if(tracks==null) return;
-
-
-
- for(HPSEcalCluster cl : clusters) {
-
-
-
-
+
+ if (debug) {
+ System.out.println(tracks.size() + " tracks in this event");
+ }
+
+ for (HPSEcalCluster cl : clusters) {
int[] pos = getCrystalPair(cl);
- int side = pos[1]>0 ? 0 : 1; //top or bottom
+ int side = pos[1] > 0 ? 0 : 1; //top or bottom
+
+ if (debug) {
+ System.out.println("Looking at cluster at ix=" + pos[0] + " iy=" + pos[1]);
+ }
- if(debug) System.out.println("Looking at cluster at ix=" + pos[0] + " iy=" + pos[1]);
-
trkMatchTool.setCluster(cl);
trkMatchTool.match(tracks);
-
- if(!trkMatchTool.isMatchedY(50)) {
- if(debug) System.out.println("Cluster not matched to a track");
+
+ if (!trkMatchTool.isMatchedY(50)) {
+ if (debug) {
+ System.out.println("Cluster not matched to a track");
+ }
continue;
}
-
-
- if(debug) System.out.println("Cluster matched to track at distance Y " + trkMatchTool.getDistanceToTrackInY() + " and X " + trkMatchTool.getDistanceToTrackInX());
-
-
- double P = trkMatchTool.getMatchedTrack().getPX()*1000;
+
+
+ if (debug) {
+ System.out.println("Cluster matched to track at distance Y " + trkMatchTool.getDistanceToTrackInY() + " and X " + trkMatchTool.getDistanceToTrackInX());
+ }
+
+
+ double P = trkMatchTool.getMatchedTrack().getPX() * 1000;
double E = cl.getEnergy();
double Ep = E;
- double Eoverp = Ep/P;
-
- if(debug) System.out.println("P " + P + " E " + E);
-
-
+ double Eoverp = Ep / P;
+
+ if (debug) {
+ System.out.println("P " + P + " E " + E);
+ }
+
+
// double Eseed = cl.getSeedHit().getRawEnergy();
// double ErawSum = 0;
// for(CalorimeterHit hit : cl.getCalorimeterHits()) {
@@ -370,81 +310,64 @@
// if(Eseed/ErawSum<0.6) continue;
//
int ebin = -1;
- if(P>500&&P<=700) ebin=1;
- else if(P>700&&P<=900) ebin=2;
- else if(P>900&&P<=1100) ebin=3;
- else ebin=4;
-
- if(side==0) {
+ if (P > 500 && P <= 700) {
+ ebin = 1;
+ } else if (P > 700 && P <= 900) {
+ ebin = 2;
+ } else if (P > 900 && P <= 1100) {
+ ebin = 3;
+ } else {
+ ebin = 4;
+ }
+
+ if (side == 0) {
h_PE_t[0].fill(Eoverp);
h_PE_t[ebin].fill(Eoverp);
-
- }
- else {
+
+ } else {
h_PE_b[0].fill(Eoverp);
h_PE_b[ebin].fill(Eoverp);
}
-
+
hitmap.fill(pos[0], pos[1]);
-
- pePlots[pos[0]+23][pos[1]+5][0].fill(Eoverp);
-
- pePlots[pos[0]+23][pos[1]+5][ebin].fill(Eoverp);
-
-
- gainWriter.print(event.getEventNumber()+" "+P+" "+E+" "+pos[0]+" "+pos[1]);
- for(CalorimeterHit hit: cl.getCalorimeterHits()) {
- gainWriter.print(" "+hit.getIdentifierFieldValue("ix")+" "+hit.getIdentifierFieldValue("iy")+" "+hit.getRawEnergy()+" "+converter.gain );
+
+ pePlots[pos[0] + 23][pos[1] + 5][0].fill(Eoverp);
+
+ pePlots[pos[0] + 23][pos[1] + 5][ebin].fill(Eoverp);
+
+
+ gainWriter.print(event.getEventNumber() + " " + P + " " + E + " " + pos[0] + " " + pos[1]);
+ for (CalorimeterHit hit : cl.getCalorimeterHits()) {
+ gainWriter.print(" " + hit.getIdentifierFieldValue("ix") + " " + hit.getIdentifierFieldValue("iy") + " " + hit.getRawEnergy() + " " + HPSEcalConditions.physicalToGain(hit.getCellID()));
}
gainWriter.println("");
-
-
-
-
-
- }
-
-
-
-
- }
-
-
-
-
-
+ }
+ }
+
public int[] getCrystalPair(HPSEcalCluster cluster) {
int[] pos = new int[2];
pos[0] = cluster.getSeedHit().getIdentifierFieldValue("ix");
pos[1] = cluster.getSeedHit().getIdentifierFieldValue("iy");
-
+
//System.out.println("cluster ix,iy " + pos[0] + "," + pos[1] + " from pos " + cluster.getSeedHit().getPositionVec().toString());
return pos;
//getCrystalPair(cluster.getPosition());
}
-
-
-
-
-
-
-
-
-
+
+ @Override
public void endOfData() {
-
redraw();
-
- if (outputPlotFileName != "")
- try {
- aida.saveAs(outputPlotFileName);
- } catch (IOException ex) {
- Logger.getLogger(ECalGainDriver.class.getName()).log(Level.SEVERE, "Couldn't save aida plots to file " + outputPlotFileName, ex);
+
+ if (!"".equals(outputPlotFileName)) {
+ try {
+ aida.saveAs(outputPlotFileName);
+ } catch (IOException ex) {
+ Logger.getLogger(ECalGainDriver.class.getName()).log(Level.SEVERE, "Couldn't save aida plots to file " + outputPlotFileName, ex);
+ }
}
//displayFastTrackingPlots();
-
+
gainWriter.close();
-
}
@Override
@@ -454,59 +377,52 @@
plotter.destroyRegions();
for (int x = -23; x <= 23; x++) { // slot
for (int y = -5; y <= 5; y++) { // crate
- for(int iE=0;iE<=4;++iE) {
+ for (int iE = 0; iE <= 4; ++iE) {
pePlots[x + 23][y + 5][iE].reset();
}
}
}
}
- //throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void actionPerformed(ActionEvent ae) {
-
- if(ae.getSource()==blankButton) {
+
+ if (ae.getSource() == blankButton) {
plotter.region(2).clear();
} else {
//get the col and row to display
Integer x = (Integer) xCombo.getSelectedItem();
Integer y = (Integer) yCombo.getSelectedItem();
plotter.region(2).clear();
- plotter.region(2).plot(pePlots[x+23][y+5][0]);
+ plotter.region(2).plot(pePlots[x + 23][y + 5][0]);
}
-
-
+
+
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void redraw() {
-
+
//do something if needed
mpePlot.reset();
spePlot.reset();
-
- for(int irow=-5;irow<=5;++irow) {
- for(int icol=-23;icol<=23;++icol) {
+
+ for (int irow = -5; irow <= 5; ++irow) {
+ for (int icol = -23; icol <= 23; ++icol) {
//System.out.println(" redraw irow " + irow + " icol " + icol + " entries " + pePlots[icol+23][irow+5].entries());
- if(pePlots[icol+23][irow+5][0].entries()>10) {
- mpePlot.fill(icol,irow,pePlots[icol+23][irow+5][0].mean());
- spePlot.fill(icol,irow,pePlots[icol+23][irow+5][0].rms());
-
+ if (pePlots[icol + 23][irow + 5][0].entries() > 10) {
+ mpePlot.fill(icol, irow, pePlots[icol + 23][irow + 5][0].mean());
+ spePlot.fill(icol, irow, pePlots[icol + 23][irow + 5][0].rms());
+
}
}
}
-
-
- //throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setEventRefreshRate(int eventRefreshRate) {
refreshRate = eventRefreshRate;
- //throw new UnsupportedOperationException("Not supported yet.");
}
-
-
}
hps-java/src/main/resources/org/lcsim/hps/steering
diff -u -r1.11 -r1.12
--- ECalMonitoring.lcsim 21 Jun 2012 18:59:45 -0000 1.11
+++ ECalMonitoring.lcsim 9 Aug 2012 00:51:15 -0000 1.12
@@ -10,11 +10,11 @@
<!-- <driver name="EventMarkerDriver"/>-->
<driver name="HPSCalibrationDriver"/>
<driver name="EcalRawConverter"/>
-<!-- <driver name="EcalClusterer"/>-->
+ <driver name="EcalClusterer"/>
<!-- <driver name="EcalPedestalPlots"/>-->
-<!-- <driver name="EcalMonitoringPlots"/>-->
+ <driver name="EcalMonitoringPlots"/>
<driver name="EcalHitPlots"/>
-<!-- <driver name="EcalClusterPlots"/>-->
+ <driver name="EcalClusterPlots"/>
<!-- <driver name="EcalEvsX"/>-->
<!-- <driver name="TriggerPlots"/>-->
<!--
hps-java/src/main/resources/org/lcsim/hps/steering
diff -u -r1.9 -r1.10
--- HPSTestRunReconToEvio.lcsim 3 Aug 2012 23:14:39 -0000 1.9
+++ HPSTestRunReconToEvio.lcsim 9 Aug 2012 00:51:15 -0000 1.10
@@ -10,21 +10,33 @@
<execute>
<driver name="LoadCalibrations"/>
- <driver name="HPSCalibrationDriver"/>
+ <driver name="HPSCalibrationDriver"/>
+ <driver name="Timer1"/>
<driver name="EcalReadout"/>
<driver name="EcalConverter"/>
<driver name="EcalClusterer"/>
<driver name="EcalTrigger"/>
+ <driver name="Timer2"/>
<driver name="SVTSensorSetup"/>
<driver name="SVTReadout"/>
- <driver name="ClockDriver"/>
+ <driver name="Timer3"/>
<driver name="TestRunReconToEvio"/>
+ <driver name="ClockDriver"/>
<driver name="CleanupDriver"/>
</execute>
<drivers>
<driver name="LoadCalibrations" type="org.lcsim.hps.recon.tracking.LoadCalibrationsDriver" />
<driver name="HPSCalibrationDriver" type="org.lcsim.hps.monitoring.HPSCalibrationDriver"/>
+ <driver name="Timer1" type="org.lcsim.hps.util.TimerDriver">
+ <name>1</name>
+ </driver>
+ <driver name="Timer2" type="org.lcsim.hps.util.TimerDriver">
+ <name>2</name>
+ </driver>
+ <driver name="Timer3" type="org.lcsim.hps.util.TimerDriver">
+ <name>3</name>
+ </driver>
<driver name="TestRunReconToEvio" type="org.lcsim.hps.evio.TestRunTriggeredReconToEvio">
<evioOutputFile>${evioFile}</evioOutputFile>
</driver>
@@ -67,7 +79,7 @@
<driver name="SVTReadout"
type="org.lcsim.hps.recon.tracking.apv25.HPSSiSensorReadout">
- <addNoise>true</addNoise>
+ <addNoise>true</addNoise>
</driver>
<driver name="ClockDriver"
CVSspam 0.2.12