EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExitWindowV2.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExitWindowV2.cxx
1 
2 //_____________________________________________________________________________
3 //
4 // Exit window version 2, radial geometry
5 //
6 //_____________________________________________________________________________
7 
8 //local classes
9 #include "ExitWindowV2.h"
10 #include "DetUtils.h"
11 
12 //ROOT
13 #include <TMath.h>
14 #include <TTree.h>
15 
16 //Geant
17 #include <Geant4/G4LogicalVolume.hh>
18 #include <Geant4/G4NistManager.hh>
19 #include <Geant4/G4Tubs.hh>
20 #include <Geant4/G4SystemOfUnits.hh>
21 #include <Geant4/G4VisAttributes.hh>
22 #include <Geant4/G4PVPlacement.hh>
23 #include <Geant4/G4Transform3D.hh>
24 #include <Geant4/G4RotationMatrix.hh>
25 #include <Geant4/G4ThreeVector.hh>
26 
27 #include <Geant4/G4Track.hh>
28 #include <Geant4/G4Step.hh>
29 
30 
31 
32 using namespace std;
33 
34 //_____________________________________________________________________________
35 ExitWindowV2::ExitWindowV2(const G4String& nam, G4double zpos, G4LogicalVolume *top): fNam(nam) {
36 
37  G4cout << "ExitWindowV2: " << fNam << G4endl;
38 
39  G4double dz = 2.5*meter; // length along z
40  G4double radius = 10*cm; // inner radius
41  G4double thickness = 1*mm; // exit window thickness
42 
43  //cylindrical U-shape
44  G4Tubs *shape = new G4Tubs(fNam, radius, radius+thickness, dz/2., 90*deg, 180*deg);
45 
46  //exit window material
47  G4Material *mat = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
48 
49  //logical volume
50  G4LogicalVolume *vol = new G4LogicalVolume(shape, mat, fNam);
51 
52  //visualization
53  G4VisAttributes *vis = new G4VisAttributes();
54  vis->SetColor(0, 1, 0, 0.5);
55  vis->SetForceSolid(true);
56  vol->SetVisAttributes(vis);
57 
58  //100 mrad in x-z plane by rotation along y
59  G4RotationMatrix rot(G4ThreeVector(0, 1, 0), -0.1*rad); //typedef to CLHEP::HepRotation
60 
61  //placement with rotation at a given position along z
62  G4ThreeVector pos(0, 0, zpos);
63  G4Transform3D transform(rot, pos); // is HepGeom::Transform3D
64 
65  new G4PVPlacement(transform, vol, fNam, top, false, 0);
66 
67 }//ExitWindowV2
68 
69 //_____________________________________________________________________________
70 G4bool ExitWindowV2::ProcessHits(const G4Step *step, G4TouchableHistory*) {
71 
72  //track in current step
73  G4Track *track = step->GetTrack();
74 
75  //primary only
76  if( track->GetParentID() != 0 ) return true;
77 
78  //first point on the exit window
79  if( fPhotZ > 9998.) {
80 
81  const G4ThreeVector point = step->GetPostStepPoint()->GetPosition();
82 
83  fPhotX = point.x();
84  fPhotY = point.y();
85  fPhotZ = point.z();
86  }
87 
88  //conversion to a pair
89  G4int nsec = 0, nel = 0, npos = 0; // number of secondaries, electrons and positrons
90 
91  //secondary loop
92  const vector<const G4Track*> *sec = step->GetSecondaryInCurrentStep();
93  vector<const G4Track*>::const_iterator i;
94  for(i = sec->begin(); i != sec->end(); i++) {
95 
96  //all secondaries
97  nsec++;
98 
99  //get the pdg
100  const G4ParticleDefinition *def = (*i)->GetParticleDefinition();
101  G4int pdg = def->GetPDGEncoding();
102 
103  //electrons and positrons
104  if(pdg == 11) nel++;
105  if(pdg == -11) npos++;
106 
107  }//secondary loop
108 
109  //select e+e- conversion
110  if(nsec != 2 || nel != 1 || npos != 1) return true;
111 
112  fConv = kTRUE;
113 
114  //location of the conversion
115  const G4ThreeVector cp = step->GetPostStepPoint()->GetPosition();
116  fConvX = cp.x();
117  fConvY = cp.y();
118  fConvZ = cp.z();
119 
120  //step lenght with the conversion
121  fConvStepLen = step->GetStepLength();
122 
123  return true;
124 
125 }//ProcessHits
126 
127 //_____________________________________________________________________________
128 void ExitWindowV2::CreateOutput(TTree *tree) {
129 
130  //set output branches of exit window
131 
132  DetUtils u(fNam, tree); // prefix for variable names and tree for AddBranch
133 
134  u.AddBranch("_IsHit", &fIsHit, "O");
135 
136  u.AddBranch("_photX", &fPhotX, "D");
137  u.AddBranch("_photY", &fPhotY, "D");
138  u.AddBranch("_photZ", &fPhotZ, "D");
139 
140  u.AddBranch("_conv", &fConv, "O");
141 
142  u.AddBranch("_convX", &fConvX, "D");
143  u.AddBranch("_convY", &fConvY, "D");
144  u.AddBranch("_convZ", &fConvZ, "D");
145 
146  u.AddBranch("_steplen", &fConvStepLen, "D");
147  u.AddBranch("_convlen", &fPhotConvLen, "D");
148 
149 }//CreateOutput
150 
151 //_____________________________________________________________________________
153 
154  //default values
155 
156  fIsHit = kFALSE;
157 
158  fPhotX = 9999.;
159  fPhotY = 9999.;
160  fPhotZ = 9999.;
161 
162  fConv = kFALSE;
163 
164  fConvStepLen = -9999.;
165  fPhotConvLen = -9999.;
166 
167  fConvX = 9999.;
168  fConvY = 9999.;
169  fConvZ = 9999.;
170 
171 }//ClearEvent
172 
173 //_____________________________________________________________________________
175 
176  // length between photon first point and conversion point
178  fPhotConvLen = TMath::Sqrt(fPhotConvLen);
179 
180 }//FinishEvent
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194