OpParamAction.cxx
Go to the documentation of this file.
1 // OpParamAction class implementation : Ben Jones, MIT 2013
2 // See header file for detailed description.
3 
5 
6 #include "cetlib_except/exception.h"
7 
8 #include <cmath>
9 
10 namespace larg4
11 {
12 
13  //-----------------------------------------------
14  // OpParamAction base class methods
15  //-----------------------------------------------
16 
17 
18 
20  {
21  }
22 
24  {
25  }
26 
27  double OpParamAction::GetAttenuationFraction(G4ThreeVector /*PhotonDirection*/, G4ThreeVector /*PhotonPosition*/)
28  {
29  return 0;
30  }
31 
32 
33 
34  //-----------------------------------------------
35  // SimpleWireplaneAction Methods
36  //-----------------------------------------------
37 
38 
39  SimpleWireplaneAction::SimpleWireplaneAction(TVector3 WireDirection, TVector3 PlaneNormal, double WirePitch, double WireDiameter)
40  {
41  fWireDirection = G4ThreeVector(WireDirection.X(),
42  WireDirection.Y(),
43  WireDirection.Z()).unit();
44  fPlaneNormal = G4ThreeVector(PlaneNormal.X(),
45  PlaneNormal.Y(),
46  PlaneNormal.Z()).unit();
47  fDPRatio = WireDiameter/WirePitch;
48  }
49 
50  //-----------------------------------------------
51 
53  {
54  }
55 
56  //-----------------------------------------------
57  // An ideal simple wireplane attenuates the light by a fraction
58  // Wire_Diameter / (Pitch * cos theta) where theta is the angle
59  // of incident light projected into the plane perpendicular to the
60  // wires. The photon position is not used.
61  //
62  double SimpleWireplaneAction::GetAttenuationFraction(G4ThreeVector PhotonDirection, G4ThreeVector /*PhotonPosition*/)
63  {
64  G4ThreeVector ProjDirection = PhotonDirection - fWireDirection*(fWireDirection.dot(PhotonDirection));
65  double CosTheta = std::abs(fPlaneNormal.dot(ProjDirection));
66  if(CosTheta < fDPRatio)
67  return 0;
68  else
69  return (1.0 - fDPRatio / CosTheta);
70  }
71 
72 
73 
74  //-----------------------------------------------
75  // OverlaidWireplanesAction Methods
76  //-----------------------------------------------
77 
78 
79  OverlaidWireplanesAction::OverlaidWireplanesAction(std::vector<std::vector<double> > InputVectors, int Orientation)
80  {
81 
82  G4ThreeVector WireBasis1, WireBasis2;
83 
84  if(Orientation==0)
85  {
86  fPlaneNormal=G4ThreeVector(1,0,0);
87  WireBasis1 =G4ThreeVector(0,1,0);
88  WireBasis2 =G4ThreeVector(0,0,1);
89  }
90  else if(Orientation==1)
91  {
92  fPlaneNormal=G4ThreeVector(0,1,0);
93  WireBasis1 =G4ThreeVector(1,0,0);
94  WireBasis2 =G4ThreeVector(0,0,1);
95  }
96  else if(Orientation==2)
97  {
98  fPlaneNormal=G4ThreeVector(0,0,1);
99  WireBasis1 =G4ThreeVector(0,1,0);
100  WireBasis2 =G4ThreeVector(0,0,1);
101  }
102  else
103  {
104  throw cet::exception("OpParamAction") << "Unrecognized wireplane orientation. Options are 1=Xdrift, 2=Ydrift, 3=Zdrift\n";
105  }
106  for(size_t i=0; i!=InputVectors.size(); ++i)
107  {
108  if(InputVectors.at(i).size()!=3)
109  {
110  throw cet::exception("OpParamAction") << "Unrecognized wireplane parameter format. Expected vector(3)'s with v[0] = wire angle, v[1] = wire pitch, v[2] = wire diameter\n";
111  }
112  else
113  {
114  double theta = InputVectors[i][0]*3.142/180.;
115  fWireDirections.push_back(cos(theta)*WireBasis1 + sin(theta)*WireBasis2);
116  fDPRatios.push_back(InputVectors[i][2]/InputVectors[i][1]);
117  }
118  }
119  }
120 
121 
122  //-----------------------------------------------
123 
125  {
126  }
127 
128 
129  //-----------------------------------------------
130 
131  double OverlaidWireplanesAction::GetAttenuationFraction(G4ThreeVector PhotonDirection, G4ThreeVector /*PhotonPosition*/)
132  {
133 
134  double AttenFraction=1.;
135 
136  for(size_t i=0; i!=fWireDirections.size(); ++i)
137  {
138  G4ThreeVector ProjDirection = PhotonDirection - fWireDirections.at(i) * (fWireDirections.at(i).dot(PhotonDirection.unit()));
139 
140  // fWireDirections.at(i).cross(PhotonDirection.cross(fWireDirections.at(i)).unit());
141  double CosTheta = (ProjDirection.mag() > 0 ? std::abs(fPlaneNormal.dot(ProjDirection))/ProjDirection.mag() : 1.0);
142  if(CosTheta < fDPRatios.at(i))
143  return 0;
144  else
145  AttenFraction *= (1.0 - fDPRatios.at(i) / CosTheta);
146  }
147  return AttenFraction;
148  }
149 
150 
151 
152 
153 
154 }
SimpleWireplaneAction(TVector3 WireDirection, TVector3 PlaneNormal, double WirePitch, double WireDiameter)
double GetAttenuationFraction(G4ThreeVector PhotonDirection, G4ThreeVector PhotonPosition)
struct vector vector
Geant4 interface.
double GetAttenuationFraction(G4ThreeVector PhotonDirection, G4ThreeVector PhotonPosition)
T abs(T value)
OverlaidWireplanesAction(std::vector< std::vector< double > >, int)
virtual double GetAttenuationFraction(G4ThreeVector PhotonDirection, G4ThreeVector PhotonPosition)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33