EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OpDet.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file OpDet.cxx
1 
2 //_____________________________________________________________________________
3 //
4 // detector for optical photons, uniform quantum efficiency
5 //
6 //_____________________________________________________________________________
7 
8 //local headers
9 #include "OpDet.h"
10 
11 //Geant
12 #include <Geant4/G4LogicalVolume.hh>
13 #include <Geant4/G4NistManager.hh>
14 #include <Geant4/G4Box.hh>
15 #include <Geant4/G4SystemOfUnits.hh>
16 #include <Geant4/G4PVPlacement.hh>
17 #include <Geant4/G4VisAttributes.hh>
18 #include <Geant4/G4MaterialPropertiesTable.hh>
19 #include <Geant4/G4OpticalPhoton.hh>
20 #include <Geant4/G4Scintillation.hh>
21 #include <Geant4/G4Cerenkov.hh>
22 
23 //ROOT
24 #include <TTree.h>
25 
26 
27 //C++
28 #include <string>
29 
30 
31 //_____________________________________________________________________________
32 OpDet::OpDet(const G4String& name, G4double xysiz, G4double zpos, G4double xmid, G4double ymid, G4LogicalVolume *top):
33  fNam(name) {
34 
35  //detector for optical photons
36 
37 // G4cout << " OpDet: " << fNam << G4endl;
38 
39  //OpDet shape
40  G4double dz = 0.3*mm; // 300 micro m thickess
41  G4Box *shape = new G4Box(name, xysiz/2., xysiz/2., dz/2.);
42 
43  //quantum efficiency
44  fQE = 0.8;
45 
46  //logical volume
47  G4Material *mat = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
48  G4LogicalVolume *vol = new G4LogicalVolume(shape, mat, name);
49 
50  //visibility
51  G4VisAttributes *vis = new G4VisAttributes();
52  vis->SetColor(1, 0, 1); // magenta
53  vis->SetForceSolid(true);
54  vol->SetVisAttributes(vis);
55 
56  //add to the top
57  fPhys = new G4PVPlacement(0, G4ThreeVector(xmid, ymid, zpos-dz/2.), vol, name, top, false, 0);
58 
59  //random generator for quantum efficiency
60  fRand = new CLHEP::HepRandom();
61 
62  //indices to identify scintillation and Cerenkov processes
63  G4Scintillation scin;
64  fScinType = scin.GetProcessType();
65  fScinSubType = scin.GetProcessSubType();
66  G4Cerenkov cer;
67  fCerenkovType = cer.GetProcessType();
68  fCerenkovSubType = cer.GetProcessSubType();
69 
70 }//OpDet
71 
72 //_____________________________________________________________________________
74 
75  delete fRand;
76 
77 }//~OpDet
78 
79 //_____________________________________________________________________________
80 G4bool OpDet::ProcessHits(const G4Step *step, G4TouchableHistory*) {
81 
82  //total energy deposition in optical detector
83  fEdep += step->GetTotalEnergyDeposit();
84 
85  //optical photons only since now
86  G4Track *track = step->GetTrack();
87  if(track->GetDynamicParticle()->GetParticleDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) {
88  return true;
89  }
90 
91  //energy from optical photons
92  fEopt += step->GetTotalEnergyDeposit();
93 
94  //apply the quantum efficiency
95  if(fRand->flat() > fQE) return true;
96 
97  //scintillation or Cerenkov photon
98  G4int ptype = track->GetCreatorProcess()->GetProcessType();
99  G4int pstype = track->GetCreatorProcess()->GetProcessSubType();
100  //scintillation photons
101  if(ptype == fScinType && pstype == fScinSubType) fNscin++;
102  //Cerenkov photons
103  if(ptype == fCerenkovType && pstype == fCerenkovSubType) fNcerenkov++;
104 
105  //time of the photon
106  G4double tim = step->GetPostStepPoint()->GetGlobalTime();
107  if(tim < fTmin) fTmin = tim;
108  if(tim > fTmax) fTmax = tim;
109  fTavg += tim;
110 
111  //number of optical photons
112  fNphot++;
113 
114  return true;
115 
116 }//ProcessHits
117 
118 //_____________________________________________________________________________
119 void OpDet::CreateOutput(TTree *tree) {
120 
121  AddBranch("_en", &fEdep, tree);
122  AddBranch("_eopt", &fEopt, tree);
123 
124  AddBranch("_nphot", &fNphot, tree);
125  AddBranch("_nscin", &fNscin, tree);
126  AddBranch("_ncerenkov", &fNcerenkov, tree);
127 
128  AddBranch("_tmin", &fTmin, tree);
129  AddBranch("_tmax", &fTmax, tree);
130  AddBranch("_tavg", &fTavg, tree);
131 
132 }//CreateOutput
133 
134 //_____________________________________________________________________________
136 
137  //G4cout << "OpDet::FinishEvent" << G4endl;
138 
139  //average time
140  if(fNphot > 0) {
141  fTavg = fTavg/fNphot;
142  } else {
143  fTavg = -999.;
144  fTmin = -999.;
145  fTmax = -999.;
146  }
147 
148 }//FinishEvent
149 
150 //_____________________________________________________________________________
152 
153  fEdep = 0.;
154  fEopt = 0.;
155  fNphot = 0;
156 
157  fNscin = 0;
158  fNcerenkov = 0;
159 
160  fTmin = 1.e12;
161  fTmax = -1.;
162  fTavg = 0.;
163 
164 }//ClearEvent
165 
166 //_____________________________________________________________________________
167 void OpDet::AddBranch(const std::string& nam, Double_t *val, TTree *tree) {
168 
169  //add branch for one Double_t variable
170 
171  std::string name = fNam + nam; // branch name from detector name and variable name
172  std::string leaf = name + "/D"; // leaflist for Double_t
173  tree->Branch(name.c_str(), val, leaf.c_str()); // create the branch
174 
175 }//AddBranch
176 
177 //_____________________________________________________________________________
178 void OpDet::AddBranch(const std::string& nam, ULong64_t *val, TTree *tree) {
179 
180  //add branch for one ULong64_t variable
181 
182  std::string name = fNam + nam; // branch name from detector name and variable name
183  std::string leaf = name + "/l"; // leaflist for Double_t
184  tree->Branch(name.c_str(), val, leaf.c_str()); // create the branch
185 
186 }//AddBranch
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 
250 
251 
252