View Javadoc

1   package org.lcsim.event.util;
2   
3   import hep.physics.event.generator.MCEvent;
4   import hep.physics.event.generator.GeneratorFactory;
5   import hep.physics.particle.BasicParticle;
6   import hep.physics.particle.Particle;
7   import hep.physics.particle.properties.ParticleType;
8   import hep.physics.particle.properties.UnknownParticleIDException;
9   import hep.physics.vec.Hep3Vector;
10  import hep.physics.vec.HepLorentzVector;
11  import org.lcsim.event.MCParticle;
12  import org.lcsim.event.MCParticle.SimulatorStatus;
13  import org.lcsim.event.base.BaseLCSimEvent;
14  
15  public class LCSimFactory extends GeneratorFactory
16  {
17      private String detectorName;
18      private static SimulatorStatus emptySimulatorStatus = new Status();
19      public LCSimFactory(String detectorName)
20      {
21          this.detectorName = detectorName;
22      }
23  
24      public MCEvent createEvent(int run, int event)
25      {
26          return new BaseLCSimEvent(run,event,detectorName);
27      }
28  
29      public BasicParticle createParticle(Hep3Vector origin, HepLorentzVector p, ParticleType ptype, int status, double time)
30      {
31          return new GeneratorParticle(origin,p,ptype,status,time);
32      }
33  
34      private static class GeneratorParticle extends BasicParticle implements MCParticle
35      {
36          float[] spin = new float[3];
37          int[] colorFlow = new int[2];
38  
39          GeneratorParticle(Hep3Vector origin,HepLorentzVector p,ParticleType ptype,int status, double time)
40          {
41              super(origin,p,ptype,status,time);
42          }
43  
44          public SimulatorStatus getSimulatorStatus()
45          {
46              return emptySimulatorStatus;
47          }
48  
49          public Hep3Vector getEndPoint()
50          {
51              if (getDaughters().isEmpty()) throw new RuntimeException("MCParticle end point not available");
52              return ((Particle) getDaughters().get(0)).getOrigin();
53          }
54          // FixMe: Ugly workaround for particle 92 (pythia string) problem
55          public double getCharge()
56          {
57              try
58              {
59                  return super.getCharge();
60              }
61              catch (UnknownParticleIDException x)
62              {
63                  if (x.getPDGID() == 92) return 0;
64                  else throw x;
65              }
66          }
67  
68          public float[] getSpin()
69          {
70              return spin;
71          }
72  
73          public int[] getColorFlow()
74          {
75              return colorFlow;
76          }
77      }
78      private static class Status implements SimulatorStatus
79      {
80          public boolean vertexIsNotEndpointOfParent()
81          {
82              return false;
83          }
84  
85          public boolean isStopped()
86          {
87              return false;
88          }
89  
90          public boolean isDecayedInTracker()
91          {
92              return false;
93          }
94  
95          public boolean isDecayedInCalorimeter()
96          {
97              return false;
98          }
99  
100         public boolean isCreatedInSimulation()
101         {
102             return false;
103         }
104 
105         public boolean isBackscatter()
106         {
107             return false;
108         }
109 
110         public boolean hasLeftDetector()
111         {
112             return false;
113         }
114 
115         public int getValue()
116         {
117             return 0;
118         }
119     }
120 }