21 int MAX_SAMPLING = geo->max_sample;
25 if ( sampling < 0 )
return -1;
26 if ( sampling >= MAX_SAMPLING )
return -1;
28 int sample_size = SampleIdx[sampling].
size;
29 unsigned int sample_index = SampleIdx[sampling].
index;
32 if ( sample_size == 0 )
return -1;
34 long long bestDDE = -1;
35 if ( !distance ) distance = &dist;
36 *distance = +10000000;
40 beststeps = ( *steps );
44 if ( sampling < 21 ) {
45 for (
int skip_range_check = 0; skip_range_check <= 1; ++skip_range_check ) {
46 for (
unsigned int j = sample_index; j < sample_index + sample_size; ++j ) {
47 if ( !skip_range_check ) {
48 if (
eta <
gr[j].mineta() )
continue;
49 if (
eta >
gr[j].maxeta() )
continue;
52 intsteps = ( *steps );
56 long long newDDE =
gr[j].getDDE(
eta,
phi, &newdist, &intsteps );
57 if ( newdist < *distance ) {
60 if ( steps ) beststeps = intsteps;
61 if ( newdist < -0.1 )
break;
64 if ( bestDDE >= 0 )
break;
69 if ( steps ) *steps = beststeps;
114 int nbinsx = ( *hf2d ).nbinsx;
115 int nbinsy = ( *hf2d ).nbinsy;
116 float* HistoContents = ( *hf2d ).h_contents;
117 float* HistoBorders = ( *hf2d ).h_bordersx;
118 float* HistoBordersy = ( *hf2d ).h_bordersy;
120 int ibin =
find_index_f( HistoContents, nbinsx * nbinsy, rnd0 );
122 int biny = ibin / nbinsx;
123 int binx = ibin - nbinsx * biny;
126 if ( ibin > 0 ) basecont = HistoContents[ibin - 1];
128 float dcont = HistoContents[ibin] - basecont;
130 valuex = HistoBorders[binx] + ( HistoBorders[binx + 1] - HistoBorders[binx] ) * ( rnd0 - basecont ) / dcont;
132 valuex = HistoBorders[binx] + ( HistoBorders[binx + 1] - HistoBorders[binx] ) / 2;
134 valuey = HistoBordersy[biny] + ( HistoBordersy[biny + 1] - HistoBordersy[biny] ) * rnd1;
173 float charge = args.charge;
181 float alpha,
r, rnd1, rnd2;
183 rnd2 = args.rand[t + args.nhits];
185 if ( args.is_phi_symmetric ) {
199 float delta_eta_mm =
r * cos( alpha );
200 float delta_phi_mm =
r * sin( alpha );
204 if ( center_eta < 0. ) delta_eta_mm = -delta_eta_mm;
207 if (
charge < 0. ) delta_phi_mm = -delta_phi_mm;
209 float dist000 = sqrt( center_r * center_r + center_z * center_z );
210 float eta_jakobi = abs( 2.0 * exp( -center_eta ) / ( 1.0 + exp( -2 * center_eta ) ) );
212 float delta_eta = delta_eta_mm / eta_jakobi / dist000;
213 float delta_phi = delta_phi_mm / center_r;
216 float* histocontents = ( args.fh1d)->h_contents;
217 float* histoborders = ( args.fh1d)->h_borders;
218 float* histoerrors= ( args.fh1d)->h_errors;
219 int nbins = args.fh1d->nbins ;
220 float delta_r_mm = sqrt( delta_eta_mm * delta_eta_mm + delta_phi_mm * delta_phi_mm );
221 int ibin =
find_index_f( histoborders, nbins + 1, delta_r_mm);
222 if( ibin < 1 ) ibin = 1 ;
223 if( ibin > nbins ) ibin = nbins ;
224 float weight = histocontents[ibin];
225 float rms = histoerrors[ibin];
227 float rnd1 = args.rand[t + 2 * args.nhits -100 ];
228 float rnd2 = args.rand[t + 2 * args.nhits -10 ];
229 float logweight= sqrt(
r-2. * log(rnd1) )*cos(
M_2PI * rnd2) * rms - 0.5 * rms * rms;
230 weight *= exp( logweight );
235 hit.
setEtaPhiZE( center_eta + delta_eta, center_phi + delta_phi, center_z, hit.
E() );
253 int nhist = ( *( args.fhs ) ).nhist;
254 float* bin_low_edge = ( *( args.fhs ) ).low_edge;
256 float eta = fabs( hit.
eta() );
260 for (
int i = 0; i < nhist + 1; ++i ) {
261 if ( bin_low_edge[i] >
eta ) {
269 unsigned int mxsz = args.fhs->mxsz;
270 uint32_t*
contents = &( args.fhs->d_contents1D[
bin * mxsz] );
271 float* borders = &( args.fhs->d_borders1D[
bin * mxsz] );
272 int h_size = ( *( args.fhs ) ).h_szs[
bin];
273 uint32_t s_MaxValue = ( *( args.fhs ) ).s_MaxValue;
275 float rnd = args.rand[t + 2 * args.nhits];
279 float hit_phi_shifted = hit.
phi() + wiggle;