GEMC  2.3
Geant4 Monte-Carlo Framework
crs_hitprocess.cc
Go to the documentation of this file.
1 // G4 headers
2 #include "G4Poisson.hh"
3 #include "Randomize.hh"
4 
5 // gemc headers
6 #include "crs_hitprocess.h"
7 
8 // CLHEP units
9 #include "CLHEP/Units/PhysicalConstants.h"
10 using namespace CLHEP;
11 
12 map<string, double> crs_HitProcess :: integrateDgt(MHit* aHit, int hitn)
13 {
14  map<string, double> dgtz;
15  vector<identifier> identity = aHit->GetId();
16 
17  int sector = identity[0].id;
18  int xch = identity[1].id;
19  int ych = identity[2].id;
20 
21  // Digitization Parameters
22 // double light_yield=1600/MeV; // number of optical photons pruced in the scintillator per MeV of deposited energy
23 // double att_length=108*cm; // light at tenuation length
24 // double sensor_surface=pow(3.5*cm,2)*pi; // area of photo sensor
25 // double paddle_surface=pow(10*cm,2); // paddle surface
26 // double light_coll=sensor_surface/paddle_surface; // ratio of photo_sensor area over paddle section ~ light collection efficiency
27 
28 // double sensor_qe=0.15; // photo sensor quantum efficiency
29 // double sensor_gain=0.472*1.6*1.275; // pmt gain x electron charge in pC (4x10^6)x(1.6x10^-7) ->val * 1.6 * 0.6 = 0,963 modifica 21/01/10
30 // double adc_conv=10; // conversion factor from pC to ADC (typical sensitivy of CAEN VME QDC is of 0.1 pC/ch)
31 // double adc_ped=0; // ADC Pedestal
32 // double veff=13*cm/ns; // light velocity in scintillator
33 // double tdc_conv=1/0.001/ns; // TDC conversion factor
34 
35 
36  // initialize ADC and TDC
37 // double etotL = 0;
38 // double etotR = 0;
39 // double timeL = 0;
40 // double timeR = 0;
41 // int ADCL = 0;
42 // int ADCR = 0;
43 // int TDCL = 4096;
44 // int TDCR = 4096;
45 
46 // double etotB = 0; // signal propagating to backward end of paddle hit happened in
47 // double etotF = 0; // signal propagating to forward end of the paddle the hit happened in, round u-turn and along neighbouring paddle
48 // double timeB = 0;
49 // double timeF = 0;
50 // int ADCB = 0;
51 // int ADCF = 0;
52 
53 
54  // Parameter for BaBar Crystal
55  double integration_frac=1.; // integration time SEE DIGI ROUTINE = 1us 67% of the all signal (0.8us->58% 1us->67% 2us->92% 3us->100%)
56  double optical_coupling=0.8;
57  double light_yield_crs=50000*integration_frac/MeV;
58  double att_length_crs=600*cm;
59  double sensor_surface_crs=pow(0.3*cm,2);
60  // ! requires to be matched with the Babar crystal individual geometry (short side ave = (4.1+4.7)/2=4.4)
61  double redout_surface_crs=pow(4.7*cm,2);
62  double light_coll_crs=sensor_surface_crs/redout_surface_crs;
63  double sensor_qe_crs=0.22; // 24% sipm 100um 22% sipm 25um 35% sipm 50um
64 // double sensor_pe_crs=20; //20mV*100ns/50Ohm/2 -> 1 pe = 20 pC
65 // double sensor_gain_crs=1;
66  // ! requires to be matched with the Babar crystal individual geometry (32,5 cm)
67  double length_crs;
68  double etotL_crs = 0; //L= Large side redout
69  double etotR_crs = 0; //R= short side redout
70  double timeL_crs = 0;
71  double timeR_crs = 0;
72  double veff_crs=30/1.8*cm/ns; // light velocity in crystal
73 // double adc_conv_crs=1; // conversion factor from pC to ADC (typical sensitivy of CAEN VME QDC is of 0.1 pC/ch)
74 // double adc_ped_crs=0; // ADC Pedestal
75  double tdc_conv_crs=1./ns; // TDC conversion factor
76  double T_offset_crs=0*ns;
77  double ADCL_crs = 0;
78  double ADCR_crs = 0;
79  double TDCL_crs = 4096;
80  double TDCR_crs = 4096;
81  double TDCB = 4096;
82 
83 
84 
85  // Get the paddle length: in crs paddles are along y
86 // double length = aHit->GetDetector().dimensions[2];
87  //double length = 20*cm;
88 
89  // Get info about detector material to eveluate Birks effect
90  double birks_constant=aHit->GetDetector().GetLogical()->GetMaterial()->GetIonisation()->GetBirksConstant();
91  // cout << " Birks constant is: " << birks_constant << endl;
92  // cout << aHit->GetDetector().GetLogical()->GetMaterial()->GetName() << endl;
93  // forcing Birks for CsI(Tl) from arxiv.org/pdf/0911.3041 and checked with alpha
94  birks_constant=3.2e-3;
95 
96 // double time_min[4] = {0,0,0,0};
97  double time_min_crs[4] = {0,0,0,0};
98 
99  vector<G4ThreeVector> Lpos = aHit->GetLPos();
100  vector<G4double> Edep = aHit->GetEdep();
101  vector<G4double> Dx = aHit->GetDx();
102  length_crs = aHit->GetDetector().dimensions[4];
103  //cout<<length_crs<< endl;
104 
105  // Charge for each step
106  vector<int> charge = aHit->GetCharges();
107  vector<G4double> times = aHit->GetTime();
108  //vector<string> theseMats = aHit->GetMaterials();
109 
110  unsigned int nsteps = Edep.size();
111 // double Etot = 0;
112  double Etot_crs = 0;
113  {
114  for(unsigned int s=0; s<nsteps; s++)
115  {
116 // Etot = Etot + Edep[s];
117  Etot_crs = Etot_crs + Edep[s];
118  }
119  }
120 
121  double Etot_B_crs=0;
122  if(Etot_crs>0)
123  {
124  for(unsigned int s=0; s<nsteps; s++)
125  {
126  // Distances from Downstrem (R), Upstream (L)
127  // Sipm's on D side (R)
128  double dLeft_crs = length_crs + Lpos[s].z();//Upstream
129  double dRight_crs = length_crs - Lpos[s].z();//Downstream
130  //cout<<length_crs<<" "<< Lpos[s].z()<< endl;
131  //cout<<dLeft_crs<<" "<< dRight_crs<< endl;
132 
133 // cout << " material " << theseMats[s] << endl;
134 
135  // cout << "\n Distances: " << endl;
136  // cout << "\t dLeft, dRight, dBack, dFwd: " << dLeft << ", " << dRight << ", " << dBack << ", " << dFwd << endl;
137 
138  // apply Birks effect
139 // double stepl = 0.;
140 
141 // if (s == 0){
142 // stepl = sqrt(pow((Lpos[s+1].x() - Lpos[s].x()),2) + pow((Lpos[s+1].y() - Lpos[s].y()),2) + pow((Lpos[s+1].z() - Lpos[s].z()),2));
143 // }
144 // else {
145 // stepl = sqrt(pow((Lpos[s].x() - Lpos[s-1].x()),2) + pow((Lpos[s].y() - Lpos[s-1].y()),2) + pow((Lpos[s].z() - Lpos[s-1].z()),2));
146 // }
147 
148 // double Edep_B = BirksAttenuation(Edep[s],Dx[s],charge[s],birks_constant);
149 
150  double Edep_B_crs = BirksAttenuation(Edep[s],Dx[s],charge[s],birks_constant);
151  Etot_B_crs = Etot_B_crs + Edep_B_crs;
152 
153  // cout << "\t Birks Effect: " << " Edep=" << Edep[s] << " StepL=" << stepl
154  // << " PID =" << pids[s] << " charge =" << charge[s] << " Edep_B=" << Edep_B << endl;
155 
156 // if (light_coll > 1) light_coll = 1.; // To make sure you don't miraculously get more energy than you started with
157  if (light_coll_crs > 1) light_coll_crs = 1.;
158 
159 // etotL = etotL + Edep_B/2 * exp(-dLeft/att_length) * light_coll;
160 // etotR = etotR + Edep_B/2 * exp(-dRight/att_length) * light_coll;
161 
162  etotL_crs = etotL_crs + Edep_B_crs/2 * exp(-dLeft_crs/att_length_crs) * light_coll_crs;
163  etotR_crs = etotR_crs + Edep_B_crs/2 * exp(-dRight_crs/att_length_crs) * light_coll_crs;
164 
165 
166 // etotB = etotB + Edep[s]/2 * exp(-dLeft/att_length) * light_coll;
167 // etotF = etotF + Edep[s]/2 * exp(-dRight/att_length) * light_coll;
168 
169  // cout << "step: " << s << " etotL, etotR, etotB, etotF: " << etotL << ", " << etotR << ", " << etotB << ", " << etotF << endl;
170 
171  // timeL= timeL + (times[s] + dLeft/veff) / nsteps;
172  // timeR= timeR + (times[s] + dRight/veff) / nsteps;
173 
174 // timeL= timeL + (times[s] + dLeft/veff) / nsteps;
175 // timeR= timeR + (times[s] + dRight/veff) / nsteps;
176 
177 
178  timeL_crs= timeL_crs + (times[s] + dLeft_crs/veff_crs) / nsteps;
179  timeR_crs= timeR_crs + (times[s] + dRight_crs/veff_crs) / nsteps;
180 
181 // timeB= timeB + (times[s] + dLeft/veff) / nsteps;
182 // timeF= timeF + (times[s] + dRight/veff) / nsteps;
183 
184 // if(etotL > 0.) {
185 // if(s==0 || (time_min[0]>(times[s]+dLeft/veff))) time_min[0]=times[s]+dLeft/veff;
186 // }
187  //.q cout << "min " << time_min[0] << "min " << times[s]+dLeft/veff << endl;
188 // if(etotR > 0.) {
189 // if(s==0 || (time_min[1]>(times[s]+dRight/veff))) time_min[1]=times[s]+ dRight/veff;
190 // }
191 
192 
193  if(etotL_crs > 0.) {
194  if(s==0 || (time_min_crs[0]>(times[s]+dLeft_crs/veff_crs))) time_min_crs[0]=times[s]+dLeft_crs/veff_crs;
195  }
196  //.q cout << "min " << time_min[0] << "min " << times[s]+dLeft/veff << endl;
197  if(etotR_crs > 0.) {
198  if(s==0 || (time_min_crs[1]>(times[s]+dRight_crs/veff_crs))) time_min_crs[1]=times[s]+ dRight_crs/veff_crs;
199  }
200 
201  //cout<<time_min_crs[1]<<" "<< dRight_crs<< endl;
202 
203 // if(etotB > 0.) {
204 // if(s==0 || (time_min[2]>(times[s]+dLeft/veff))) time_min[2]=times[s]+ dLeft/veff;
205 // }
206 // if(etotF > 0.) {
207 // if(s==0 || (time_min[3]>(times[s]+dRight/veff))) time_min[3]=times[s]+ dRight/veff;
208 // }
209 //
210  }
211 
212  // cout << "Etot " << Etot_crs << " EtotB " << Etot_B_crs << " steps " << nsteps<< endl;
213 // double peL=G4Poisson(etotL*light_yield*sensor_qe);
214 // double peR=G4Poisson(etotR*light_yield*sensor_qe);
215 // double sigmaTL=sqrt(pow(0.2*nanosecond,2.)+pow(1.*nanosecond,2.)/(peL+1.));
216 // double sigmaTR=sqrt(pow(0.2*nanosecond,2.)+pow(1.*nanosecond,2.)/(peR+1.));
217 
218  // Keeping the L side for future pindiode parametrization
219  //double peL_crs=G4Poisson(etotL_crs*light_yield_crs*sensor_qe_crs*optical_coupling);
220  //double sigmaTL_crs=sqrt(pow(5.*nanosecond,2.)+pow(10.*nanosecond,2.)/(peL_crs/10.+1.));
221  // All time spread added in the function WaveForm
222 
223  // sampling the short side readout and getting timing out of the digitized WF
224 
225 
226  // cout << "Etot " << peL_crs << " EtotB " << rr << endl;
227 
228  // double sigmaTL=0;
229  // double sigmaTR=0;
230 // TDCL=(int) ((time_min[0]+G4RandGauss::shoot(0.,sigmaTL)) * tdc_conv);
231 // TDCR=(int) ((time_min[1]+G4RandGauss::shoot(0.,sigmaTR)) * tdc_conv);
232 // if(TDCL<0) TDCL=0;
233 // if(TDCR<0) TDCR=0;
234 // ADCL=(int) (peL*sensor_gain*adc_conv + adc_ped);
235 // ADCR=(int) (peR*sensor_gain*adc_conv + adc_ped);
236  // cout << "ADCL: " << ADCL << " " << peL << " " << sensor_gain << " " << adc_conv << endl;
237 
238 
239 
240 // TDCL_crs=(int) ((time_min_crs[0]+T_offset_crs+G4RandGauss::shoot(0.,sigmaTL_crs)) * tdc_conv_crs);
241 // TDCR_crs=(int) ((time_min_crs[1]+T_offset_crs+G4RandGauss::shoot(0.,sigmaTR_crs)) * tdc_conv_crs);
242 // if(TDCL_crs<0) TDCL_crs=0;
243 // if(TDCR_crs<0) TDCR_crs=0;
244 // ADCL_crs=(int) (peL_crs*sensor_gain_crs*adc_conv_crs + adc_ped_crs);
245 // ADCR_crs=(int) (peR_crs*sensor_gain_crs*adc_conv_crs + adc_ped_crs);
246 
247  // Crystal readout
248  //double test=WaveForm(peR_crs,TDCR_crs);
249  double* test;
250  double tim;
251  double peR_int_crs;
252  double peR_crs;
253  int Nsamp_int=250; // 1us
254 
255  // SIPM 1
256  peR_crs=G4Poisson(etotR_crs*light_yield_crs*sensor_qe_crs*optical_coupling);
257  test=WaveForm(peR_crs,&tim);
258  // integrating over the integration time (each sample 4.ns, see digi routine)
259  //for(unsigned int s=0; s<1000; s++)cout << s << " " << test[s] << endl ;
260  peR_int_crs=0.;
261  for(int s=0; s<Nsamp_int; s++) peR_int_crs=peR_int_crs+test[s];
262  //cout << "TDCR: " << tim << " Npe before digi " << peR_crs<< " Npe avter digi " <<peR_int_crs <<endl;
263  TDCR_crs=int(tim);
264  ADCR_crs=int(peR_int_crs);
265  //ADCL_crs=etotR_crs*1000;
266  //cout << "TDCR: " << tim << " Npe before digi " << peR_crs<< " Npe avter digi " <<peR_int_crs <<endl;
267 
268  //Assigning to TDCB the usual timing seen by sipm1 (TDCR)
269  double sigmaTR_crs=sqrt(pow(5.*nanosecond,2.)+pow(10.*nanosecond,2.)/(peR_crs/10.+1.));
270  sigmaTR_crs=0.;
271  TDCB=((time_min_crs[1]+T_offset_crs+G4RandGauss::shoot(0.,sigmaTR_crs)) * tdc_conv_crs);
272  //cout <<time_min_crs[1]<<" "<<TDCB<<endl;
273 
274 
275  // SIPM 2
276  double sensor_qe_crs_sipm2=0.35;//PDE sipm2
277  double optical_coupling_sipm2=optical_coupling;// assuming the two optical coupling are the same
278  peR_crs=G4Poisson(etotR_crs*light_yield_crs*sensor_qe_crs_sipm2*optical_coupling_sipm2);
279  test=WaveForm(peR_crs,&tim);
280  // integrating over the integration time (each sample 4.ns, see digi routine)
281  //for(unsigned int s=0; s<1000; s++)cout << s << " " << test[s] << endl ;
282  peR_int_crs=0.;
283  for(int s=0; s<Nsamp_int; s++) peR_int_crs=peR_int_crs+test[s];
284  //cout << "TDCR: " << tim << " Npe before digi " << peR_crs<< " Npe avter digi " <<peR_int_crs <<endl;
285  TDCL_crs=int(tim); // assigning to L the sipm2
286  ADCL_crs=int(peR_int_crs);// assigning to L the sipm2
287  //ADCL_crs=etotR_crs*1000;
288  //cout << "TDCR: " << tim << " Npe before digi " << peR_crs<< " Npe avter digi " <<peR_int_crs <<endl;
289 
290 
291 
292 
293 // double peB=G4Poisson(etotB*light_yield*sensor_qe);
294 // double peF=G4Poisson(etotF*light_yield*sensor_qe);
295 // double sigmaTB=sqrt(pow(0.2*nanosecond,2.)+pow(1.*nanosecond,2.)/(peB+1.));
296 // double sigmaTF=sqrt(pow(0.2*nanosecond,2.)+pow(1.*nanosecond,2.)/(peF+1.));
297  // double sigmaTB=0;
298  // double sigmaTF=0;
299 // TDCB=(int) ((time_min[2] + G4RandGauss::shoot(0.,sigmaTB)) * tdc_conv);
300 // TDCF=(int) ((time_min[3] + G4RandGauss::shoot(0.,sigmaTF)) * tdc_conv);
301 // if(TDCB<0) TDCB=0;
302 // if(TDCF<0) TDCF=0;
303 // ADCB=(int) (G4Poisson(etotB*light_yield*sensor_qe)*sensor_gain*adc_conv + adc_ped);
304 // ADCF=(int) (G4Poisson(etotF*light_yield*sensor_qe)*sensor_gain*adc_conv + adc_ped);
305 
306  //cout << "energy right: " << ADCR / (adc_conv*sensor_gain*sensor_qe*light_yield) << " E left: " << ADCL / (adc_conv*sensor_gain*sensor_qe*light_yield) << endl;
307  //cout << "energy forw: " << ADCF / (adc_conv*sensor_gain*sensor_qe*light_yield) << " E back: " << ADCB / (adc_conv*sensor_gain*sensor_qe*light_yield) << endl;
308 
309  //cout << " Light collection: " << light_coll << endl;
310 
311  }
312  // closes (Etot > 0) loop
313 
314  if(verbosity>4)
315  {
316  cout << log_msg << " xch: " << xch << ", ych: " << ych ;
317  cout << log_msg << " Etot=" << Etot_crs/MeV << endl;
318  cout << log_msg << " TDCL=" << TDCL_crs << " TDCR=" << TDCR_crs << " ADCL=" << ADCL_crs << " ADCR=" << ADCR_crs << endl;
319  //cout << log_msg << " TDCB=" << TDCB << " TDCF=" << TDCF << " ADCB=" << ADCB << " ADCF=" << ADCF << endl;
320  }
321 
322  dgtz["hitn"] = hitn;
323  dgtz["sector"] = sector;
324  dgtz["xch"] = xch;
325  dgtz["ych"] = ych;
326  dgtz["adcl"] = ADCL_crs;//Downstream side large cell sipm
327  dgtz["adcr"] = ADCR_crs;//Downstream side small cell sipm
328  dgtz["tdcl"] = TDCL_crs;//Downstream side large cell sipm
329  dgtz["tdcr"] = TDCR_crs;//Downstream side small cell sipm
330  dgtz["adcb"] = 0;
331  dgtz["adcf"] = 0;
332  dgtz["tdcb"] = TDCB*1000.;//original time in ps
333  dgtz["tdcf"] = 0;
334 
335  return dgtz;
336 }
337 
338 
339 vector<identifier> crs_HitProcess :: processID(vector<identifier> id, G4Step *step, detector Detector)
340 {
341  id[id.size()-1].id_sharing = 1;
342  return id;
343 }
344 
345 
346 
347 double crs_HitProcess::BirksAttenuation(double destep, double stepl, int charge, double birks)
348 {
349  //Example of Birk attenuation law in organic scintillators.
350  //adapted from Geant3 PHYS337. See MIN 80 (1970) 239-244
351  //
352  // Taken from GEANT4 examples advanced/amsEcal and extended/electromagnetic/TestEm3
353  //
354  double response = destep;
355  if (birks*destep*stepl*charge != 0.)
356  {
357  response = destep/(1. + birks*destep/stepl);
358  }
359  return response;
360 }
361 
362 
363 double crs_HitProcess::BirksAttenuation2(double destep,double stepl,int charge,double birks)
364 {
365  //Extension of Birk attenuation law proposed by Chou
366  // see G.V. O'Rielly et al. Nucl. Instr and Meth A368(1996)745
367  //
368  //
369  double C=9.59*1E-4*mm*mm/MeV/MeV;
370  double response = destep;
371  if (birks*destep*stepl*charge != 0.)
372  {
373  response = destep/(1. + birks*destep/stepl + C*pow(destep/stepl,2.));
374  }
375  return response;
376 }
377 
378 
379 map< string, vector <int> > crs_HitProcess :: multiDgt(MHit* aHit, int hitn)
380 {
381  map< string, vector <int> > MH;
382 
383  return MH;
384 }
385 
386 
387 
388 
389 //double crs_HitProcess::WaveForm(double npe, double time)
390 double* crs_HitProcess::WaveForm(double npe, double* time)
391 {
392  double c=exp(-2.);
393 // double Time;
394  double t; // time in usec
395  double WF;
396  double y;
397  double rr;
398  int it;
399  int Nch_digi=800; //Number of cjannel for the digitizer
400  static double WFsample[1000]; //Needs to be > Nch_digi+size of the response to the single pe
401  double smp_t=4./1000. ;// Assuming fADC sampling at 250 MHz 1sample every 4ns
402 
403  // double p[6] = {0.14,-3.5,2.5,-2.,0.5,-1.2};
404  double p[6] = {0.,0.680,0.64,3.34,0.36,0.};// Babar CsI paprameters: fast component(in us), % fast, slow comp(in us), % slow
405  // double p1[6] = {0.33,-0.04,3.45,-0.05,2.5,-0.045};
406 
407  double tau=15.; // ampli response time constant (in ns)
408  double t0=0.01; // t0 starting time (in ns)
409  double area=(tau/c/2.);
410  double A=1./area; // amplitude at mnax (55.41 to have it normalized to integral=1, otherwise the max is at 1)
411 // double threshold=10.*1./area/smp_t/1000.; //time threshold in pe - 1/55.41/smp_t*1000. is the funct max -
412 
413 
414  double t_spread= 1.*0.000;// pream time spread in us
415  double A_spread= 1.*0.05*A;// pream amp spread (in fraction of 1pe amplitude = A)
416  double func=0.;
417  // Building the waveform
418  for(unsigned int s=0; s<1000; s++)
419  {
420  WFsample[s]=0;
421  }
422  // Building the response to a single pe (preamps response)
423  double AmpWF[80];
424  for(unsigned int s=0; s<80; s++)
425  {t=1000.*s*smp_t;
426  // parametrization of preamp out time is in ns (rise ~10ns decay~80ns) sampled in 160ns or 40 samples
427  //func=1./411.5*((1-exp(p1[0]+p1[1]*t))*exp(p1[2]+p1[3]*t)+exp(p1[4]+p1[5]*t)));
428  func=(t-t0)*(t-t0)*exp(-(t-t0)/tau)*A/(4*tau*tau*c)*0.5*(abs(t-t0)/(t-t0)+1);
429  // spreading amplitude by apli noise
430  AmpWF[s]=smp_t*1000.*func;
431  }
432 
433  // fraction of pe in Nch_digi
434  double frac=1-((p[2]*exp(-smp_t*Nch_digi/p[1])+p[4]*exp(-smp_t*Nch_digi/p[3])));
435  int Npe = frac*npe;
436 // cout << "Npe " << Npe<<" "<<npe << endl;
437 
438  //Npe=1.;
439  //Npe=Npe/100.;
440  for(int s=1; s<=Npe; s++){
441  y=1.;
442  WF=0.;
443  while (y > WF) {
444  rr=(rand() % 1000000+1)/1000000.; // rnd number between 0-1
445  t= Nch_digi*smp_t*rr; // extracting over 5000 samples range (5000x4ns=20us)
446  //WF= 1./5.15*((1-exp(p[0]+p[1]*t))*exp(p[2]+p[3]*t)+exp(p[4]+p[5]*t));
447  WF= (p[2]/p[1]*exp(-t/p[1])+p[4]/p[3]*exp(-t/p[3]))/(p[2]/p[1]+p[4]/p[3]);
448  rr=(rand() % 10000000+1)/10000000.; // rnd number between 0-1
449  y=rr;
450  // cout << "WF " << WF << " rnd " << y << endl;
451  }
452  // spreading time and amplitude of the ampli signal
453 // it=t/smp_t;
454 // cout << "t " << t << "it " << it << endl;
455 
456  t=G4RandGauss::shoot(t,t_spread);
457  if (t<0.) t=0.;
458  it=t/smp_t;
459 // cout << "t " << t << "it " << it << endl;
460  for(int s=0; s<80; s++)
461  { t=1000.*s*smp_t;
462  func=AmpWF[s];
463  func=G4RandGauss::shoot(func,A_spread);
464  if((s+it)<Nch_digi) WFsample[s+it]=WFsample[s+it]+ func;
465  }
466  }
467 
468  //for(unsigned int s=0; s<200; s++) cout << s << " " << WFsample[s] << endl ;
469 
470  // mimicking a CF discriminatorm at 1/3 of the max signal
471  *time=0.;
472  double time_max=-100;
473  int s=0;
474  int s_time_max=0;
475  while (time_max<WFsample[s]){
476  time_max=1/2.*(WFsample[s+1]+WFsample[s]);
477  s_time_max=s;
478  *time=1000.*smp_t*s_time_max/3.;
479  s++;
480  }
481  // cout<<s_time_max<<" "<< time_max<< " "<<*time <<endl;
482 
483 /* // mimicking a FixedT discriminatorm
484  for(unsigned int s=0; s<1000; s++)
485  {
486  //cout << s << " " << WFsample[s] << endl ;
487  //look for the max
488 
489  if(WFsample[s]>threshold)
490  {*time=1000.*s*smp_t; //time in ns
491  break;
492  }
493  }
494  */
495 
496  // get timing from digitized WF
497 
498  // cout << "routine " << WFsample[50] << endl ;
499  //cout << "Time " << threshold<< "sample "<<s<< "time "<< *time << endl;
500 
501  return WFsample;
502 
503 }
504 
map< string, vector< int > > multiDgt(MHit *, int)
vector< identifier > processID(vector< identifier >, G4Step *, detector)
G4LogicalVolume * GetLogical()
Returns Logical Volume pointer.
Definition: detector.h:113
double verbosity
vector< identifier > GetId()
Definition: Hit.h:103
vector< G4ThreeVector > GetLPos()
Definition: Hit.h:76
Definition: Hit.h:22
vector< double > GetTime()
Definition: Hit.h:89
double BirksAttenuation(double, double, int, double)
double BirksAttenuation2(double, double, int, double)
vector< double > dimensions
vector of dimensions. Size, units depends on solid type
Definition: detector.h:77
vector< double > GetEdep()
Definition: Hit.h:83
detector GetDetector()
Definition: Hit.h:108
vector< int > GetCharges()
Definition: Hit.h:116
vector< double > GetDx()
Definition: Hit.h:86
map< string, double > integrateDgt(MHit *, int)
double * WaveForm(double, double *)