Commit in hps-java/src/main/java/org/lcsim/hps/users/omoreno on MAIN | |||
ReconstructedParticleChecker.java | +123 | added 1.1 |
Driver to check if ReconstructedParticles are being created correctly
diff -N ReconstructedParticleChecker.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ReconstructedParticleChecker.java 11 Apr 2013 02:38:20 -0000 1.1 @@ -0,0 +1,123 @@
+package org.lcsim.hps.users.omoreno; + +//--- java ---// +import java.util.ArrayList; +import java.util.List; + +//--- hep ---// +import hep.aida.IHistogram1D; +import hep.aida.IPlotter; +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; +import hep.physics.vec.VecOp; + +//--- lcsim ---// +import org.lcsim.event.EventHeader; +import org.lcsim.event.ReconstructedParticle; +import org.lcsim.event.Track; +import org.lcsim.event.Cluster; +import org.lcsim.util.Driver; +import org.lcsim.util.aida.AIDA; +import org.lcsim.geometry.Detector; + +//--- hps-java ---// +import org.lcsim.hps.recon.tracking.SvtTrackExtrapolator; + +/** + * + * @author Omar Moreno <[log in to unmask]> + * @version $Id: ReconstructedParticleChecker.java,v 1.1 2013/04/11 02:38:20 omoreno Exp $ + * + */ +public class ReconstructedParticleChecker extends Driver { + + SvtTrackExtrapolator extrapolator = new SvtTrackExtrapolator(); + private AIDA aida; + private List<IPlotter> plotters = new ArrayList<IPlotter>(); + + IHistogram1D xPositionResidual; + IHistogram1D yPositionResidual; + IHistogram1D zPositionResidual; + IHistogram1D r; + + // Collection Names + private String finalStateParticlesCollectionName = "FinalStateParticles"; + + boolean debug = true; + int plotterIndex = 0; + + public ReconstructedParticleChecker(){} + + protected void detectorChanged(Detector detector){ + super.detectorChanged(detector); + + // Setup AIDA + aida = AIDA.defaultInstance(); + aida.tree().cd("/"); + + plotters.add(PlotUtils.setupPlotter("Track-Cluster Position Residual", 2, 2)); + xPositionResidual = aida.histogram1D("x Residual", 100, -100, 100); + yPositionResidual = aida.histogram1D("y Residual", 100, -100, 100); + zPositionResidual = aida.histogram1D("z Residual", 100, -100, 100); + r = aida.histogram1D("r", 100, -100, 100); + PlotUtils.setup1DRegion(plotters.get(plotterIndex), "x Residual", 0, "delta x [mm]", xPositionResidual); + PlotUtils.setup1DRegion(plotters.get(plotterIndex), "y Residual", 1, "delta y [mm]", yPositionResidual); + PlotUtils.setup1DRegion(plotters.get(plotterIndex), "z Residual", 2, "delta z [mm]", zPositionResidual); + PlotUtils.setup1DRegion(plotters.get(plotterIndex), "r", 3, "r [mm]", r); + + + for(IPlotter plotter : plotters){ + plotter.show(); + } + } + + public void process(EventHeader event){ + + // If the event doesn't contain any final state reconstructed + // particles, skip the event + if(!event.hasCollection(ReconstructedParticle.class, finalStateParticlesCollectionName)){ + this.printDebug("Event does not contain ReconstructedParticles"); + return; + } + + // Get the collections of reconstructed final state particles from the + // event + List<ReconstructedParticle> finalStateParticles + = event.get(ReconstructedParticle.class, finalStateParticlesCollectionName); + + + // Loop over all of the reconstructed particles in the event + for(ReconstructedParticle finalStateParticle : finalStateParticles){ + + // Get the list of clusters from the event + List<Cluster> ecalClusters = finalStateParticle.getClusters(); + this.printDebug("Number of Ecal clusters: " + ecalClusters.size()); + if(ecalClusters.isEmpty()){ + this.printDebug("Number of Ecal clusters: " + ecalClusters.size()); + this.printDebug("List of Ecal cluster is empty ... skipping"); + continue; + } + + // Get the list of tracks from the event + List<Track> tracks = finalStateParticle.getTracks(); + if(tracks.isEmpty()){ + this.printDebug("List of tracks is empty ... skipping"); + continue; + } + extrapolator.setTrack(tracks.get(0)); + + Hep3Vector ecalPosition = new BasicHep3Vector(ecalClusters.get(0).getPosition()); + Hep3Vector trackPositionAtEcal = extrapolator.extrapolateTrack(ecalPosition.z()); + xPositionResidual.fill(trackPositionAtEcal.x() - ecalPosition.x()); + yPositionResidual.fill(trackPositionAtEcal.y() - ecalPosition.y()); + zPositionResidual.fill(trackPositionAtEcal.z() - ecalPosition.z()); + r.fill(VecOp.sub(trackPositionAtEcal, ecalPosition).magnitude()); + } + + } + + private void printDebug(String debugMessage){ + if(debug) + System.out.println(this.getClass().getSimpleName() + ": " + debugMessage); + } +}
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1