GEMC  2.3
Geant4 Monte-Carlo Framework
HitProcess.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "HitProcess.h"
3 
4 // CLHEP units
5 #include "CLHEP/Units/PhysicalConstants.h"
6 using namespace CLHEP;
7 
8 HitProcess *getHitProcess(map<string, HitProcess_Factory> *hitProcessMap, string HCname)
9 {
10  if(HCname == "no")
11  return NULL;
12 
13  if(hitProcessMap->find(HCname) == hitProcessMap->end())
14  {
15  cout << endl << " !!! Error: >" << HCname << "< NOT FOUND IN ProcessHit Map. Exiting" << endl;
16  exit(0);
17  return NULL;
18  }
19  return (*hitProcessMap)[HCname]();
20 }
21 
22 // returns the list of Hit Factories registered
23 set<string> getListOfHitProcessHit(map<string, HitProcess_Factory> hitProcessMap)
24 {
25  set<string> listF;
26 
27  for(map<string, HitProcess_Factory>::iterator it = hitProcessMap.begin(); it != hitProcessMap.end(); it++)
28  listF.insert(it->first);
29 
30  return listF;
31 }
32 
33 
34 // - integrateRaw: returns geant4 raw information integrated over the hit
35 map<string, double> HitProcess::integrateRaw(MHit* aHit, int hitn, bool WRITEBANK)
36 {
37  map<string, double> raws;
38 
39  trueInfos tInfos(aHit);
40 
41  if(WRITEBANK)
42  {
43  raws["hitn"] = hitn;
44  raws["pid"] = (double) aHit->GetPID();
45  raws["mpid"] = (double) aHit->GetmPID();
46  raws["tid"] = (double) aHit->GetTId();
47  raws["mtid"] = (double) aHit->GetmTrackId();
48  raws["otid"] = (double) aHit->GetoTrackId();
49  raws["trackE"] = aHit->GetE();
50  raws["totEdep"] = tInfos.eTot;
51  raws["avg_x"] = tInfos.x;
52  raws["avg_y"] = tInfos.y;
53  raws["avg_z"] = tInfos.z;
54  raws["avg_lx"] = tInfos.lx;
55  raws["avg_ly"] = tInfos.ly;
56  raws["avg_lz"] = tInfos.lz;
57  raws["px"] = aHit->GetMom().getX();
58  raws["py"] = aHit->GetMom().getY();
59  raws["pz"] = aHit->GetMom().getZ();
60  raws["vx"] = aHit->GetVert().getX();
61  raws["vy"] = aHit->GetVert().getY();
62  raws["vz"] = aHit->GetVert().getZ();
63  raws["mvx"] = aHit->GetmVert().getX();
64  raws["mvy"] = aHit->GetmVert().getY();
65  raws["mvz"] = aHit->GetmVert().getZ();
66  raws["avg_t"] = tInfos.time;
67  raws["procID"] = aHit->GetProcID();
68  raws["nsteps"] = aHit->GetPIDs().size();
69  }
70  return raws;
71 }
72 
73 
74 
75 map< string, vector <double> > HitProcess::allRaws(MHit* aHit, int hitn)
76 {
77  map< string, vector <double> > allRaws;
78 
79  vector<int> pids = aHit->GetPIDs();
80  vector<double> pids_d(pids.begin(), pids.end());
81 
82  vector<int> mpids = aHit->GetmPIDs();
83  vector<double> mpids_d(mpids.begin(), mpids.end());
84 
85  vector<int> tids = aHit->GetTIds();
86  vector<double> tids_d(tids.begin(), tids.end());
87 
88  vector<int> mtids = aHit->GetmTrackIds();
89  vector<double> mtids_d(mtids.begin(), mtids.end());
90 
91  vector<int> otids = aHit->GetoTrackIds();
92  vector<double> otids_d(otids.begin(), otids.end());
93 
94 
95  vector<double> hitnd(pids.size(), (double) hitn);
96 
97  vector<G4ThreeVector> gpos = aHit->GetPos();
98  vector<G4ThreeVector> lpos = aHit->GetLPos();
99  vector<G4ThreeVector> mome = aHit->GetMoms();
100  vector<G4ThreeVector> vert = aHit->GetVerts();
101  vector<G4ThreeVector> mver = aHit->GetmVerts();
102 
103 
104  vector<double> x, y, z;
105  vector<double> lx, ly, lz;
106  vector<double> px, py, pz;
107  vector<double> vx, vy, vz;
108  vector<double> mvx, mvy, mvz;
109  vector<double> stepi;
110 
111  for(unsigned s=0; s<gpos.size(); s++)
112  {
113 
114  stepi.push_back(s+1);
115 
116  x.push_back(gpos[s].getX());
117  y.push_back(gpos[s].getY());
118  z.push_back(gpos[s].getZ());
119 
120  lx.push_back(lpos[s].getX());
121  ly.push_back(lpos[s].getY());
122  lz.push_back(lpos[s].getZ());
123 
124  px.push_back(mome[s].getX());
125  py.push_back(mome[s].getY());
126  pz.push_back(mome[s].getZ());
127 
128  vx.push_back(vert[s].getX());
129  vy.push_back(vert[s].getY());
130  vz.push_back(vert[s].getZ());
131 
132  mvx.push_back(mver[s].getX());
133  mvy.push_back(mver[s].getY());
134  mvz.push_back(mver[s].getZ());
135  }
136 
137 
138  allRaws["stepn"] = stepi;
139  allRaws["hitn"] = hitnd;
140  allRaws["pid"] = pids_d;
141  allRaws["mpid"] = mpids_d;
142  allRaws["tid"] = tids_d;
143  allRaws["mtid"] = mtids_d;
144  allRaws["otid"] = otids_d;
145  allRaws["trackE"] = aHit->GetEs();
146  allRaws["edep"] = aHit->GetEdep();
147  allRaws["t"] = aHit->GetTime();
148  allRaws["x"] = x;
149  allRaws["y"] = y;
150  allRaws["z"] = z;
151  allRaws["lx"] = lx;
152  allRaws["ly"] = ly;
153  allRaws["lz"] = lz;
154  allRaws["px"] = px;
155  allRaws["py"] = py;
156  allRaws["pz"] = pz;
157  allRaws["vx"] = vx;
158  allRaws["vy"] = vy;
159  allRaws["vz"] = vz;
160  allRaws["mvx"] = mvx;
161  allRaws["mvy"] = mvy;
162  allRaws["mvz"] = mvz;
163 
164 
165 
166  return allRaws;
167 }
168 
169 
170 
171 map< double, double > HitProcess :: signalVT(MHit* aHit)
172 {
173  // Time resolution is an external parameter
174  double tres = gemcOpt.optMap["VTRESOLUTION"].arg;
175 
176  map< double, double > VT;
177  sensitiveID SID = aHit->GetSDID();
178 
179  // signal parameters
180  double par[4];
181 
182  // setting signal parameters
183  par[0] = SID.delay;
184  par[1] = SID.riseTime;
185  par[2] = SID.fallTime;
186  par[3] = SID.mvToMeV;
187 
188  vector<G4double> Edep = aHit->GetEdep();
189  vector<G4double> times = aHit->GetTime();
190  unsigned nsteps = Edep.size();
191 
192  double tmin = 100000;
193  double tmax = 0;
194 
195 
196  // finding min, max
197  for(unsigned int s=0; s<nsteps; s++)
198  {
199  if(tmin > times[s]) tmin = times[s];
200  if(tmax < times[s]) tmax = times[s];
201  // cout << " step " << s+1 << " time " << times[s] << " tmin " << tmin << " tmax " << tmax << endl;
202  }
203 
204  // adding 1/2 DELAY to tmin
205  tmin = floor(tmin + 0.5*SID.delay);
206 
207  // adding a whole signal to tmax
208  tmax = floor(tmax + SID.delay + SID.riseTime + 2*SID.fallTime);
209 
210  unsigned int nt = (int) (tmax - tmin)/tres;
211 
212 
213  // cout << " tmin " << tmin << " tmax " << tmax << " nt " << nt << endl;
214 
215  for(unsigned ti=0; ti<nt; ti++)
216  {
217  // local time
218  double localT = tmin + ti*tres;
219  double totV = 0;
220 
221  // v signal at this time is sum of all signals at each step
222  for(unsigned int s=0; s<nsteps; s++)
223  {
224  totV += DGauss(localT, par, Edep[s], times[s]);
225 
226 // cout << " local time " << localT << " step " << s + 1 << " time " << times[s]
227 // << " Edep " << Edep[s] << " signal " << DGauss(localT, par, Edep[s], times[s]) << endl;
228  }
229 
230  VT[localT] = totV + SID.pedestal;
231  }
232 
233 
234 // for(map<double, double>::iterator it = VT.begin(); it != VT.end(); it++)
235 // cout << " time " << it->first << " VT " << it->second << endl;
236 
237  aHit->setSignal(VT);
238 
239  return VT;
240 }
241 
242 
243 
244 map< int, int > HitProcess :: quantumS(map< double, double > vts, MHit* aHit)
245 {
246  // hardcoded trigger value, need to determine how
247  double triggerV = 3500;
248 
249  sensitiveID sdid = aHit->GetSDID();
250 
251  // voltage signal time resolution is an external parameter
252  double sres = gemcOpt.optMap["VTRESOLUTION"].arg;
253 
254  // sampling time of electronics (typically FADC)
255  double tsampling = get_number(get_info(gemcOpt.optMap["TSAMPLING"].args).back());
256 
257  // time resolution is an external parameter
258  double tres = get_number(get_info(gemcOpt.optMap["TSAMPLING"].args).front());
259 
260  // quantum signal, all initialized to zero
261  // number of elements in the map is total time / resolution
262  map< int, int > QS;
263  vector<int> TR;
264  for(int i=0; i<tsampling/tres; i++)
265  {
266  QS[i*4] = 0;
267  TR.push_back(0);
268  }
269 
270  map< int, int > :: iterator qsi = QS.begin();
271  map<double, double>::iterator vti = vts.begin();
272  int qsind = 0;
273 
274 
275  // leaving the zeros until the first entry in the voltage signal
276  // attention: looks like this can go on forever in some cases?
277  while (qsi->first < vti->first)
278  {
279  // cout << qsi->first << " " << vti->first << endl;
280  qsi++;
281  qsind++;
282  }
283 
284  for(unsigned i=0; i<vts.size(); i++)
285  {
286  if(fabs(vti->first - qsi->first) < sres/2)
287  {
288  // recording all signals
289  QS[qsind*4] = fabs(vti->second - sdid.pedestal);
290 
291  // recording trigger only if above threshold
292  if(fabs(vti->second - sdid.pedestal) > sdid.signalThreshold*sdid.mvToMeV)
293  {
294  TR[qsind] = triggerV;
295  aHit->passedTrigger();
296  }
297 
298  // index have to be increased upon matching
299  qsi++;
300  qsind++;
301  }
302 
303  vti++;
304  }
305 
306 
307 
308 
309 // for(map< int, int > :: iterator qq = QS.begin(); qq != QS.end(); qq++)
310 // cout << qq->first << " " << qq->second << endl;
311 
312 
313 // for(map< double, double > :: iterator qq = vts.begin(); qq != vts.end(); qq++)
314 // cout << qq->first << " " << qq->second << " " << fabs(qq->second - sdid.pedestal) << " " << sdid.signalThreshold*100 << endl;
315 
316  aHit->setQuantum(QS);
317  aHit->setQuantumTR(TR);
318 
319 
320  return QS;
321 }
322 
323 
325 {
326  eTot = 0;
327  time = 0;
328  x = y = z = lx = ly = lz = 0;
329 
330  // getting vectors of energy deposited, positions and times
331  // nsteps is the size
332 
333  vector<G4double> Edep = aHit->GetEdep();
334  vector<G4ThreeVector> pos = aHit->GetPos();
335  vector<G4ThreeVector> Lpos = aHit->GetLPos();
336  vector<G4double> times = aHit->GetTime();
337 
338  nsteps = Edep.size();
339  for(unsigned int s=0; s<nsteps; s++)
340  eTot += Edep[s];
341 
342  // if energy deposited, averaging quantities over the hit
343  // weighted by energy deposited
344  if(eTot)
345  {
346  for(unsigned int s=0; s<nsteps; s++)
347  {
348  x += pos[s].x()*Edep[s];
349  y += pos[s].y()*Edep[s];
350  z += pos[s].z()*Edep[s];
351  lx += Lpos[s].x()*Edep[s];
352  ly += Lpos[s].y()*Edep[s];
353  lz += Lpos[s].z()*Edep[s];
354  time += times[s]*Edep[s];
355  }
356  x = x/eTot;
357  y = y/eTot;
358  z = z/eTot;
359  lx = lx/eTot;
360  ly = ly/eTot;
361  lz = lz/eTot;
362  time = time/eTot;
363  }
364  else
365  {
366  for(unsigned int s=0; s<nsteps; s++)
367  {
368  x += pos[s].x();
369  y += pos[s].y();
370  z += pos[s].z();
371  lx += Lpos[s].x();
372  ly += Lpos[s].y();
373  lz += Lpos[s].z();
374  time += times[s];
375  }
376  x = x/nsteps;
377  y = y/nsteps;
378  z = z/nsteps;
379  lx = lx/nsteps;
380  ly = ly/nsteps;
381  lz = lz/nsteps;
382  time = time/nsteps;
383  }
384 }
385 
386 
387 
virtual map< double, double > signalVT(MHit *)
Definition: HitProcess.cc:171
void setSignal(map< double, double > VT)
Definition: Hit.h:153
void setQuantum(map< int, int > QS)
Definition: Hit.h:168
double delay
time from PMT face to signal
Definition: sensitiveID.h:38
int GetoTrackId()
Definition: Hit.h:126
int GetProcID()
Definition: Hit.h:146
virtual map< int, int > quantumS(map< double, double >, MHit *)
Definition: HitProcess.cc:244
set< string > getListOfHitProcessHit(map< string, HitProcess_Factory > hitProcessMap)
Definition: HitProcess.cc:23
G4ThreeVector GetVert()
Definition: Hit.h:79
double ly
Definition: HitProcess.h:42
int GetPID()
Definition: Hit.h:111
double lz
Definition: HitProcess.h:42
int GetmPID()
Definition: Hit.h:131
vector< string > get_info(string input, string chars)
get information from strings such as "5*GeV, 2*deg, 10*deg", parses out strings in second argument ...
vector< G4ThreeVector > GetMoms()
Definition: Hit.h:93
sensitiveID GetSDID()
Definition: Hit.h:150
G4ThreeVector GetmVert()
Definition: Hit.h:136
vector< int > GetmTrackIds()
Definition: Hit.h:122
double time
Definition: HitProcess.h:43
void setQuantumTR(vector< int > t)
Definition: Hit.h:183
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
double z
Definition: HitProcess.h:41
double lx
Definition: HitProcess.h:42
vector< G4ThreeVector > GetLPos()
Definition: Hit.h:76
double eTot
Definition: HitProcess.h:40
double x
Definition: HitProcess.h:41
map< string, vector< double > > allRaws(MHit *, int)
Definition: HitProcess.cc:75
vector< int > GetmPIDs()
Definition: Hit.h:132
double GetE()
Definition: Hit.h:96
vector< G4ThreeVector > GetPos()
Definition: Hit.h:72
vector< G4ThreeVector > GetmVerts()
Definition: Hit.h:137
double mvToMeV
from MeV to mV constant
Definition: sensitiveID.h:36
G4ThreeVector GetMom()
Definition: Hit.h:92
Definition: Hit.h:22
vector< double > GetEs()
Definition: Hit.h:97
double pedestal
pedestal
Definition: sensitiveID.h:37
vector< double > GetTime()
Definition: Hit.h:89
double y
Definition: HitProcess.h:41
void passedTrigger()
Definition: Hit.h:186
vector< int > GetTIds()
Definition: Hit.h:101
vector< int > GetPIDs()
Definition: Hit.h:112
double signalThreshold
Minimum energy of the hit to be recorded in the output stream.
Definition: sensitiveID.h:30
vector< double > GetEdep()
Definition: Hit.h:83
int GetTId()
Definition: Hit.h:100
vector< int > GetoTrackIds()
Definition: Hit.h:127
vector< G4ThreeVector > GetVerts()
Definition: Hit.h:80
HitProcess * getHitProcess(map< string, HitProcess_Factory > *hitProcessMap, string HCname)
Definition: HitProcess.cc:8
double fallTime
fall time of the PMT signal
Definition: sensitiveID.h:35
int GetmTrackId()
Definition: Hit.h:121
map< string, double > integrateRaw(MHit *, int, bool)
Definition: HitProcess.cc:35
trueInfos(MHit *)
Definition: HitProcess.cc:324
double riseTime
rise time of the PMT signal
Definition: sensitiveID.h:34