View Javadoc

1   /**
2    * @version $Id: FastMCTrackDriver.java,v 1.1 2007/11/29 21:29:35 jstrube Exp $
3    */
4   package org.lcsim.mc.fast.tracking.fix;
5   
6   import hep.physics.particle.Particle;
7   
8   import java.io.IOException;
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  import org.lcsim.conditions.ConditionsEvent;
13  import org.lcsim.conditions.ConditionsListener;
14  import org.lcsim.conditions.ConditionsSet;
15  import org.lcsim.event.EventHeader;
16  import org.lcsim.event.MCParticle;
17  import org.lcsim.event.Track;
18  import org.lcsim.mc.fast.tracking.SimpleTables;
19  import org.lcsim.mc.fast.tracking.TrackResolutionTables;
20  import org.lcsim.util.Driver;
21  
22  /**
23   * A replacement for the current FastMC Tracks. The simple tables are currently not implemented
24   * @author jstrube
25   * 
26   */
27  public class FastMCTrackDriver extends Driver implements ConditionsListener {
28      private TrackResolutionTables parm;
29      private SimpleTables SmTbl;
30      private boolean beamSpotConstraint;
31      private boolean simple;
32      private final static double[] IP = { 0, 0, 0 };
33  
34      public FastMCTrackDriver(boolean beamSpotConstraint) {
35          this.beamSpotConstraint = beamSpotConstraint;
36      }
37  
38      public FastMCTrackDriver() {
39          this(false);
40      }
41  
42      protected void process(EventHeader event) {
43          if (parm == null) {
44              ConditionsSet conditions = getConditionsManager().getConditions("TrackParameters");
45              conditions.addConditionsListener(this);
46              parm = setTrackResolutionTables(conditions, beamSpotConstraint);
47          }
48  
49          if (SmTbl == null) {
50              ConditionsSet conditions = getConditionsManager().getConditions("SimpleTrack");
51              conditions.addConditionsListener(this);
52              SmTbl = new SimpleTables(conditions);
53          }
54  
55          FastMCTrackFactory factory = new FastMCTrackFactory(event, beamSpotConstraint);
56  
57          double bField = event.getDetector().getFieldMap().getField(IP)[2];
58          boolean hist = getHistogramLevel() > 0;
59  
60          List<Track> trackList = new ArrayList<Track>();
61          for (MCParticle p : event.getMCParticles()) {
62              // filter for FINAL_STATE
63              if (p.getGeneratorStatus() != Particle.FINAL_STATE) {
64                  continue;
65              }
66              double pCharge = p.getCharge();
67              if (pCharge == 0 || Double.isNaN(pCharge) || pCharge == Double.NEGATIVE_INFINITY || pCharge == Double.POSITIVE_INFINITY) {
68                  continue;
69              }
70  
71              double[] momentum = p.getMomentum().v();
72              double pt2 = (momentum[0] * momentum[0]) + (momentum[1] * momentum[1]);
73              double pt = Math.sqrt(pt2);
74              double ptot = Math.sqrt(pt2 + (momentum[2] * momentum[2]));
75              double cosTheta = momentum[2] / ptot;
76  
77              // within acceptance
78              if (pt < parm.getPtMin()) {
79                  continue;
80              }
81              if (Math.abs(cosTheta) > parm.getPolarOuter()) {
82                  continue;
83              }
84  
85              Track t = factory.getTrack(p);
86              trackList.add(t);
87          }
88          event.put("Tracks", trackList, Track.class, 0);
89      }
90  
91      public void conditionsChanged(ConditionsEvent event) {
92          ConditionsSet conditions = getConditionsManager().getConditions("TrackParameters");
93          ConditionsSet simpleconditions = getConditionsManager().getConditions("SimpleTrack");
94          parm = setTrackResolutionTables(conditions, beamSpotConstraint);
95          SmTbl = new SimpleTables(simpleconditions);
96      }
97  
98      private TrackResolutionTables setTrackResolutionTables(ConditionsSet conditions, boolean beamSpotConstraint) {
99          try {
100             return new TrackResolutionTables(conditions, beamSpotConstraint);
101         } catch (IOException x) {
102             throw new RuntimeException("Error reading track resolution tables", x);
103         }
104     }
105 
106 }