View Javadoc

1   /*
2    * BaseMCParticle.java
3    *
4    * Created on March 30, 2006, 8:58 AM
5    *
6    * $Id: BaseMCParticle.java,v 1.7 2012/07/10 07:20:27 grefe Exp $
7    */
8   
9   package org.lcsim.event.base;
10  
11  import hep.physics.particle.BasicParticle;
12  import hep.physics.particle.properties.ParticleType;
13  import hep.physics.vec.BasicHep3Vector;
14  import hep.physics.vec.Hep3Vector;
15  import hep.physics.vec.HepLorentzVector;
16  import org.lcsim.event.MCParticle;
17  
18  /**
19   * A base class implementatin of the MCParticle interface. 
20   * Extends BasicParticle to fulfill the Particle interface. 
21   * @author Norman Graf
22   */
23  public class BaseMCParticle extends BasicParticle implements MCParticle
24  {
25     
26      protected Hep3Vector _endPoint = new BasicHep3Vector(0., 0., 0.);
27      protected SimulatorStatus _status;
28      protected double charge; 
29      protected float[] spin = new float[3];
30      protected int[] colorFlow = new int[2];
31      protected double time;
32      
33      /**
34       * Creates a new instance of BaseMCParticle
35       * @param origin The (x,y,z) point of origin for this particle in mm.
36       * @param p The four momentum of this particle in GeV.
37       * @param ptype The particle type.
38       * @param status the integer status of this particle.
39       * @param time the time of creation of this particle in ns.
40       */
41      public BaseMCParticle(Hep3Vector origin,HepLorentzVector p,ParticleType ptype,int status, double time)
42      {
43          super(origin, p, ptype, status, time);
44          this.time = time;
45      }
46      
47      /**
48       * Overrides the charge from the particle type.
49       */
50      // FIXME Should be offered by BasicParticle instead.
51      public void setCharge(double charge) {
52  		this.charge = charge;
53  	}
54      
55      @Override
56      public double getCharge() {
57      	return Double.isNaN(charge) ? super.getCharge() : charge;
58      }
59      
60      /**
61       * If this point has interacted, set its end point.
62       * @param p The (x,y,z) end point in mm.
63       */
64      public void setEndPoint(Hep3Vector p)
65      {
66          _endPoint = p;
67      }
68      
69      /**
70       * @param status The Geant4 status of the particle
71       */
72      public void setSimulatorStatus(SimulatorStatus status) {
73      	_status = status;
74      }
75      
76      public void setSimulatorStatus(int value) {
77      	_status = new Status(value);
78      }
79      
80      public void setProductionTime(double time)
81      {
82      	this.time = time;
83      }
84      
85      @Override
86      public double getProductionTime() {
87      	return time;
88      }
89      
90      public String toString()
91      {
92          // TODO fix this to call super.toString() when BasicParticle implements toString()
93          String className = getClass().getName();
94          int lastDot = className.lastIndexOf('.');
95          if(lastDot!=-1)className = className.substring(lastDot+1);
96          StringBuffer sb = new StringBuffer(className+": "+getType().getName()+"\n");
97          sb.append("pdgId: "+getPDGID()+"\n");
98          sb.append("(x,y,z): ("+getOriginX()+", "+getOriginY()+", "+getOriginZ()+")\n");
99          sb.append("(px,py,pz): ("+getPX()+", "+getPY()+", "+getPZ()+")\n");
100         return sb.toString();
101     }
102     
103 // MCParticle interface
104     
105     /**
106      * If this event has been simulated by Geant4 this method will return
107      * the simulation status
108      * @return 
109      */
110     public SimulatorStatus getSimulatorStatus()
111     {
112         return _status;
113     }
114     /**
115      * The endpoint of the simulated track. Note this may not always be available,
116      * in which case this method may throw an exception.
117      * @return 
118      */
119     public Hep3Vector getEndPoint()
120     {
121         return _endPoint;
122     }
123     
124     public float[] getSpin()
125     {
126         return spin;
127     }
128 
129     public int[] getColorFlow()
130     {
131         return colorFlow;
132     }           
133         
134     protected class Status implements SimulatorStatus {
135     	int simulatorStatus;
136     	public Status(int v) {
137     		simulatorStatus = v;
138     	}
139         public boolean vertexIsNotEndpointOfParent()
140         {
141            return (simulatorStatus & (1<<BITVertexIsNotEndpointOfParent)) != 0;
142         }
143         
144         public boolean isStopped()
145         {
146            return (simulatorStatus & (1<<BITStopped)) != 0;
147         }
148         
149         public boolean isDecayedInTracker()
150         {
151            return (simulatorStatus & (1<<BITDecayedInTracker)) != 0;
152         }
153         
154         public boolean isDecayedInCalorimeter()
155         {
156            return (simulatorStatus & (1<<BITDecayedInCalorimeter)) != 0;
157         }
158         
159         public boolean isCreatedInSimulation()
160         {
161            return (simulatorStatus & (1<<BITCreatedInSimulation)) != 0;
162         }
163         
164         public boolean isBackscatter()
165         {
166            return (simulatorStatus & (1<<BITBackscatter)) != 0;
167         }
168         
169         public boolean hasLeftDetector()
170         {
171            return (simulatorStatus & (1<<BITLeftDetector)) != 0;
172         }
173         
174         public int getValue()
175         {
176            return simulatorStatus;
177         }
178         // define the bit positions for the simulation flag
179         private final static int BITEndpoint = 31;
180         private final static int BITCreatedInSimulation = 30;
181         private final static int BITBackscatter = 29;
182         private final static int BITVertexIsNotEndpointOfParent = 28;
183         private final static int BITDecayedInTracker = 27;
184         private final static int BITDecayedInCalorimeter = 26;
185         private final static int BITLeftDetector = 25;
186         private final static int BITStopped = 24;
187     }
188 }