GEMC  1.8
Geant4 Monte-Carlo Framework
PCAL_hitprocess.cc
Go to the documentation of this file.
1 // %%%%%%%%%%
2 // G4 headers
3 // %%%%%%%%%%
4 #include "G4UnitsTable.hh"
5 #include "G4Poisson.hh"
6 #include "Randomize.hh"
7 #include <math.h>
8 
9 // %%%%%%%%%%%%%
10 // gemc headers
11 // %%%%%%%%%%%%%
12 #include "PCAL_hitprocess.h"
13 
15 {
16  PH_output out;
17  out.identity = aHit->GetId();
18 
19  // get sector, stack (inner or outer), view (U, V, W), and strip.
20  int sector = out.identity[0].id;
21  int module = out.identity[1].id;
22  int view = out.identity[2].id;
23  int strip = out.identity[3].id;
24 
25  HCname = "PCAL Hit Process";
26 
27  // Attenuation Length (mm)
28  double attlen=3760.;
29 
30  // Get scintillator volume x dimension (mm)
31  double pDx2 = aHit->GetDetector().dimensions[5];
32 
33  //cout<<"pDx2="<<pDx2<<" pDy1="<<pDy1<<endl;
34 
35  // %%%%%%%%%%%%%%%%%%%
36  // Raw hit information
37  // %%%%%%%%%%%%%%%%%%%
38  int nsteps = aHit->GetPos().size();
39 
40  // average global, local positions of the hit
41  double x, y, z;
42  double lx, ly, lz;
43  double xlocal,ylocal;
44  x = y = z = lx = ly = lz = 0;
45  vector<G4ThreeVector> pos = aHit->GetPos();
46  vector<G4ThreeVector> Lpos = aHit->GetLPos();
47 
48  // Get Total Energy deposited
49  double Etot = 0;
50  double Etota = 0;
51  double latt = 0;
52  vector<G4double> Edep = aHit->GetEdep();
53 
54  for(int s=0; s<nsteps; s++)
55  {
56  if(attlen>0)
57  {
58  xlocal = Lpos[s].x();
59  ylocal = Lpos[s].y();
60  if(view==1) latt=pDx2+xlocal;
61  if(view==2) latt=pDx2+xlocal;
62  if(view==3) latt=pDx2+xlocal;
63  Etot = Etot + Edep[s];
64  //cout<<"xlocal="<<xlocal<<" ylocal="<<ylocal<<" view="<<view<<" strip="<<strip<<" latt="<<latt<<endl;
65  Etota = Etota + Edep[s]*exp(-latt/attlen);
66  }
67  else
68  {
69  Etot = Etot + Edep[s];
70  Etota = Etota + Edep[s];
71  }
72  }
73 
74  if(Etot>0)
75  for(int s=0; s<nsteps; s++)
76  {
77  x = x + pos[s].x()*Edep[s]/Etot;
78  y = y + pos[s].y()*Edep[s]/Etot;
79  z = z + pos[s].z()*Edep[s]/Etot;
80  lx = lx + Lpos[s].x()*Edep[s]/Etot;
81  ly = ly + Lpos[s].y()*Edep[s]/Etot;
82  lz = lz + Lpos[s].z()*Edep[s]/Etot;
83  }
84  else
85  {
86  x = pos[0].x();
87  y = pos[0].y();
88  z = pos[0].z();
89  lx = Lpos[0].x();
90  ly = Lpos[0].y();
91  lz = Lpos[0].z();
92  }
93 
94  // average time
95  double time = 0;
96  vector<G4double> times = aHit->GetTime();
97  for(int s=0; s<nsteps; s++) time = time + times[s]/nsteps;
98 
99  // Energy of the track
100  double Ene = aHit->GetE();
101 
102  out.raws.push_back(Etot);
103  out.raws.push_back(x);
104  out.raws.push_back(y);
105  out.raws.push_back(z);
106  out.raws.push_back(lx);
107  out.raws.push_back(ly);
108  out.raws.push_back(lz);
109  out.raws.push_back(time);
110  out.raws.push_back((double) aHit->GetPID());
111  out.raws.push_back(aHit->GetVert().getX());
112  out.raws.push_back(aHit->GetVert().getY());
113  out.raws.push_back(aHit->GetVert().getZ());
114  out.raws.push_back(Ene);
115  out.raws.push_back((double) aHit->GetmPID());
116  out.raws.push_back(aHit->GetmVert().getX());
117  out.raws.push_back(aHit->GetmVert().getY());
118  out.raws.push_back(aHit->GetmVert().getZ());
119 
120 
121  // %%%%%%%%%%%%
122  // Digitization
123  // %%%%%%%%%%%%
124  // adapted by Alex Piaseczny, Canisius College Medium Energy Nuclear Physics (CMENP), through
125  // Dr. Michael Wood from Gilfoyle EC code
126  // Jerry Gilfoyle, Feb, 2010
127 
128  // parameters: factor - conversion for adc (MeV/channel).
129  // pcal_tdc_to_channel - conversion factor for tdc (ns/channel).
130 
131  // int pcal_tdc_time_to_channel = (int) gpars["PCAL/pcal_tdc_time_to_channel"]; // conversion from time (ns) to TDC channels. name has to match parameters
132 
133  double pc_tdc_time_to_channel = 20 ;
134  double PCfactor = 11.5; // number of p.e. divided by the energy deposited in MeV; measured from PCAL cosmic tests
135  int PC_TDC_MAX = 4095; // max value for PC tdc.
136  double pc_MeV_to_channel = 10.; // conversion from energy (MeV) to ADC channels
137 
138  // initialize ADC and TDC
139  int PC_ADC = 0;
140  int PC_TDC = PC_TDC_MAX;
141 
142  // simulate the adc value.
143  if (Etot > 0) {
144  double PC_npe = G4Poisson(Etota*PCfactor); //number of photoelectrons
145  // Fluctuations in PMT gain distributed using Gaussian with
146  // sigma SNR = sqrt(ngamma)/sqrt(del/del-1) del = dynode gain = 3 (From RCA PMT Handbook) p. 169)
147  // algorithm, values, and comment above taken from gsim.
148  double sigma = sqrt(PC_npe)/1.22;
149  double PC_MeV = G4RandGauss::shoot(PC_npe,sigma)*pc_MeV_to_channel/PCfactor;
150  if (PC_MeV <= 0) PC_MeV=0.0; // guard against weird, rare events.
151  PC_ADC = (int) PC_MeV;
152  }
153 
154  // simulate the tdc.
155  PC_TDC = (int) (time*pc_tdc_time_to_channel);
156  if (PC_TDC > PC_TDC_MAX) PC_TDC = PC_TDC_MAX;
157 
158  out.dgtz.push_back(sector);
159  out.dgtz.push_back(module);
160  out.dgtz.push_back(view);
161  out.dgtz.push_back(strip);
162  out.dgtz.push_back(PC_ADC);
163  out.dgtz.push_back(PC_TDC);
164 
165  //cout << "sector = " << sector << " layer = " << module << " view = " << view << " strip = " << strip << " PL_ADC = " << PC_ADC << " PC_TDC = " << PC_TDC << " Edep = " << Etot << endl;
166 
167  return out;
168 }
169 
170 
171 vector<identifier> PCAL_HitProcess :: ProcessID(vector<identifier> id, G4Step* aStep, detector Detector, gemc_opts Opt)
172 {
173  //int sector = yid[0].id;
174  //int layer = yid[1].id;
175  //int view = yid[2].id; // get the view: U->1, V->2, W->3
176  //int strip = yid[3].id;
177  //return yid;
178  id[id.size()-1].id_sharing = 1;
179  return id;
180 }
181 // have to change end
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
PH_output ProcessHit(MHit *, gemc_opts)
Method to process the hit.
G4ThreeVector GetVert()
Definition: MHit.h:72
vector< double > raws
Raw information.
Definition: MPHBaseClass.h:26
int GetPID()
Definition: MHit.h:107
int GetmPID()
Definition: MHit.h:122
vector< identifier > GetId()
Definition: MHit.h:96
string HCname
Hit Collection name.
Definition: MPHBaseClass.h:41
G4ThreeVector GetmVert()
Definition: MHit.h:127
vector< identifier > identity
Identifier.
Definition: MPHBaseClass.h:28
vector< G4ThreeVector > GetLPos()
Definition: MHit.h:69
double GetE()
Definition: MHit.h:89
vector< G4ThreeVector > GetPos()
Definition: MHit.h:65
Definition: MHit.h:29
vector< double > GetTime()
Definition: MHit.h:82
vector< identifier > ProcessID(vector< identifier >, G4Step *, detector, gemc_opts)
Method to calculate new identifier.
vector< double > dimensions
vector of dimensions. Size, units depends on solid type
Definition: detector.h:63
vector< double > GetEdep()
Definition: MHit.h:76
detector GetDetector()
Definition: MHit.h:101
vector< int > dgtz
Digitized information.
Definition: MPHBaseClass.h:27