43 std::cout <<
"fillSpaceChargeMaps::fillSpaceChargeMaps(const std::string &name) Calling ctor" << std::endl;
58 double z_rdo = 108 *
cm;
62 const int r_bins_N = 66;
63 double r_bins[r_bins_N + 1] = {217.83,
64 223.83, 229.83, 235.83, 241.83, 247.83, 253.83, 259.83, 265.83, 271.83, 277.83, 283.83, 289.83, 295.83, 301.83, 306.83,
65 311.05, 317.92, 323.31, 329.27, 334.63, 340.59, 345.95, 351.91, 357.27, 363.23, 368.59, 374.55, 379.91, 385.87, 391.23, 397.19, 402.49,
66 411.53, 421.70, 431.90, 442.11, 452.32, 462.52, 472.73, 482.94, 493.14, 503.35, 513.56, 523.76, 533.97, 544.18, 554.39, 564.59, 574.76,
67 583.67, 594.59, 605.57, 616.54, 627.51, 638.48, 649.45, 660.42, 671.39, 682.36, 693.33, 704.30, 715.27, 726.24, 737.21, 748.18, 759.11};
68 double r_bins_edges[r_bins_N + 3] = {217.83-2,217.83,
69 223.83, 229.83, 235.83, 241.83, 247.83, 253.83, 259.83, 265.83, 271.83, 277.83, 283.83, 289.83, 295.83, 301.83, 306.83,
70 311.05, 317.92, 323.31, 329.27, 334.63, 340.59, 345.95, 351.91, 357.27, 363.23, 368.59, 374.55, 379.91, 385.87, 391.23, 397.19, 402.49,
71 411.53, 421.70, 431.90, 442.11, 452.32, 462.52, 472.73, 482.94, 493.14, 503.35, 513.56, 523.76, 533.97, 544.18, 554.39, 564.59, 574.76,
72 583.67, 594.59, 605.57, 616.54, 627.51, 638.48, 649.45, 660.42, 671.39, 682.36, 693.33, 704.30, 715.27, 726.24, 737.21, 748.18, 759.11, 759.11+2};
76 double phi_bins[nphi + 1] = { 0., 6.3083-2 * M_PI, 6.3401-2 * M_PI, 6.372-2 * M_PI, 6.4039-2 * M_PI, 6.4358-2 * M_PI, 6.4676-2 * M_PI, 6.4995-2 * M_PI, 6.5314-2 * M_PI,
77 0.2618, 0.2937, 0.3256, 0.3574, 0.3893, 0.4212, 0.453, 0.4849, 0.5168, 0.5487, 0.5805, 0.6124, 0.6443, 0.6762, 0.7081,
78 0.7399, 0.7718, 0.7854, 0.8173, 0.8491, 0.881, 0.9129, 0.9448, 0.9767, 1.0085, 1.0404, 1.0723, 1.1041, 1.136, 1.1679,
79 1.1998, 1.2317, 1.2635, 1.2954, 1.309, 1.3409, 1.3727, 1.4046, 1.4365, 1.4684, 1.5002, 1.5321, 1.564, 1.5959, 1.6277,
80 1.6596, 1.6915, 1.7234, 1.7552, 1.7871, 1.819, 1.8326, 1.8645, 1.8963, 1.9282, 1.9601, 1.992, 2.0238, 2.0557, 2.0876,
81 2.1195, 2.1513, 2.1832, 2.2151, 2.247, 2.2788, 2.3107, 2.3426, 2.3562, 2.3881, 2.42, 2.4518, 2.4837, 2.5156, 2.5474,
82 2.5793, 2.6112, 2.6431, 2.6749, 2.7068, 2.7387, 2.7706, 2.8024, 2.8343, 2.8662, 2.8798, 2.9117, 2.9436, 2.9754, 3.0073,
83 3.0392, 3.0711, 3.1029, 3.1348, 3.1667, 3.1986, 3.2304, 3.2623, 3.2942, 3.326, 3.3579, 3.3898, 3.4034, 3.4353, 3.4671,
84 3.499, 3.5309, 3.5628, 3.5946, 3.6265, 3.6584, 3.6903, 3.7221, 3.754, 3.7859, 3.8178, 3.8496, 3.8815, 3.9134, 3.927,
85 3.9589, 3.9907, 4.0226, 4.0545, 4.0864, 4.1182, 4.1501, 4.182, 4.2139, 4.2457, 4.2776, 4.3095, 4.3414, 4.3732, 4.4051,
86 4.437, 4.4506, 4.4825, 4.5143, 4.5462, 4.5781, 4.61, 4.6418, 4.6737, 4.7056, 4.7375, 4.7693, 4.8012, 4.8331, 4.865,
87 4.8968, 4.9287, 4.9606, 4.9742, 5.0061, 5.0379, 5.0698, 5.1017, 5.1336, 5.1654, 5.1973, 5.2292, 5.2611, 5.2929, 5.3248,
88 5.3567, 5.3886, 5.4204, 5.4523, 5.4842, 5.4978, 5.5297, 5.5615, 5.5934, 5.6253, 5.6572, 5.689, 5.7209, 5.7528, 5.7847,
89 5.8165, 5.8484, 5.8803, 5.9122, 5.944, 5.9759, 6.0078, 6.0214, 6.0533, 6.0851, 6.117, 6.1489, 6.1808, 6.2127, 6.2445,
93 double z_bins[2 * nz + 1];
94 for (
int z = 0;
z <= 2 *
nz;
z++)
96 z_bins[
z] = -z_rdo + z_rdo / nz *
z;
99 _h_R =
new TH1F(
"_h_R",
"_h_R;R, [mm]", r_bins_N+2, r_bins_edges);
100 _h_hits =
new TH1F(
"_h_hits",
"_h_hits;N, [hit]", 1000, 0, 1e6);
101 _h_DC_E =
new TH2F(
"_h_DC_E",
"_h_DC_E;SC;E#times10^{6}", 2000, -100, 2e5 - 100, 1000, -50, 1e3 - 50);
102 _h_SC_XY =
new TH2F(
"_h_SC_XY" ,
"_h_SC_XY;X, [mm];Y, [mm];ADC;" ,4*159,-1*78*
cm,78*
cm,4*159,-1*78*
cm,78*
cm);
106 for (
int iz = 0; iz < 30; iz++)
108 sprintf(name,
"_h_SC_ibf_%d", iz);
109 sprintf(name_ax,
"_h_SC_ibf_%d;#phi, [rad];R, [mm];Z, [mm]", iz);
110 _h_SC_ibf[iz] =
new TH3F(name, name_ax, nphi, phi_bins, r_bins_N, r_bins, 2 * nz, z_bins);
111 sprintf(name,
"_h_SC_prim_%d", iz);
112 sprintf(name_ax,
"_h_SC_prim_%d;#phi, [rad];R, [mm];Z, [mm]", iz);
113 _h_SC_prim[iz] =
new TH3F(name, name_ax, nphi, phi_bins, r_bins_N, r_bins, 2 * nz, z_bins);
119 hm->registerHisto(
_h_R);
131 _rawHits =
new TTree(
"hTree",
"tpc hit tree for ionization");
154 std::string txt_file =
"./data/timestamps_50kHz_1M.txt";
159 txt_file =
"/phenix/u/hpereira/sphenix/work/g4simulations/timestamps_3MHz.txt";
162 std::ifstream InputFile(txt_file);
163 if (InputFile.is_open())
166 while (getline(InputFile, line))
169 if (n_line > start_line)
171 std::istringstream is(line);
172 double n[2] = {0, 0};
181 std::cout << n[1] << std::endl;
183 _keys.push_back(
int(n[0]));
190 std::cout <<
"Unable to open file:" << txt_file << std::endl;
194 TFile *MapsFile =
new TFile(
"./data/IBF_Map.root",
"READ");
195 if (MapsFile->IsOpen())
printf(
"File opened successfully\n");
196 _h_modules_anode = (TH2F *) MapsFile->Get(
"h_modules_anode")->Clone(
"_h_modules_anode");
197 _h_modules_measuredibf = (TH2F *) MapsFile->Get(
"h_modules_measuredibf")->Clone(
"_h_modules_measuredibf");
220 double z_bias_avg = 0;
221 int bemxingsInFile =
_keys.size();
225 z_bias_avg = 1.055 *
m * (float) rand() / RAND_MAX;
235 Shifter shifter(
"/sphenix/user/rcorliss/distortion_maps/2021.04/apr07.average.real_B1.4_E-400.0.ross_phi1_sphenix_phislice_lookup_r26xp40xz40.distortion_map.hist.root");
237 PHG4HitContainer *hits = findNode::getClass<PHG4HitContainer>(topNode,
"G4HIT_TPC");
244 int f_fill_prim[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
245 int f_fill_ibf[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
247 float hit_x0 = hit_iter->second->get_x(0);
248 float hit_y0 = hit_iter->second->get_y(0);
249 float hit_z0 = hit_iter->second->get_z(0);
250 float hit_x1 = hit_iter->second->get_x(1);
251 float hit_y1 = hit_iter->second->get_y(1);
252 float hit_z1 = hit_iter->second->get_z(1);
254 float hit_eion = hit_iter->second->get_eion();
256 float x = (hit_x0 +
f * (hit_x1 - hit_x0)) *
cm;
257 float y = (hit_y0 +
f * (hit_y1 - hit_y0)) *
cm;
258 float z = (hit_z0 +
f * (hit_z1 - hit_z0)) *
cm;
260 float r = sqrt(x * x + y * y);
261 float phi = atan2(x, y);
262 if (phi < 0) phi += 2 * M_PI;
265 TVector3 oldPos(x /
cm, y /
cm, z /
cm);
271 oldPos.SetZ(abs(oldPos.z()));
273 newPos.SetZ(newPos.z() * -1);
282 newPos.SetZ(oldPos.Z());
283 newPos.SetX(oldPos.X());
284 newPos.SetY(oldPos.Y());
303 double dphi_bin = -1;
304 double new_phi = newPos.Phi();
305 double new_r = newPos.Perp() *
cm;
306 if (new_phi < 0) new_phi += 2 * M_PI;
313 std::vector<double> r_phi_bin =
putOnPlane(new_r /
mm, new_phi);
314 dr_bin = r_phi_bin[0];
315 dphi_bin = r_phi_bin[1];
321 _ibf_vol = N_electrons * ionsPerEle;
323 if (new_r < 210 || new_r > 770)
continue;
325 double z_prim[30] = {-1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10,
326 -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10,
327 -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10};
328 double z_ibf[30] = {-1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10,
329 -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10,
330 -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10, -1 * 1e10};
336 for (
int iz = 0; iz < 30; iz++)
344 z_prim[iz] =
_hit_z - z_bias_avg;
345 z_ibf[iz] = 1.055 *
m - z_bias_avg;
352 if (z_prim[iz] > 0 && z_prim[iz] < 1.055 *
m)
356 if (z_ibf[iz] > 0 && z_ibf[iz] < 1.055 *
m)
364 if (_hit_z < -5 * mm && _hit_z > -1.055 *
m)
368 for (
int iz = 0; iz < 30; iz++)
376 z_prim[iz] =
_hit_z + z_bias_avg;
377 z_ibf[iz] = -1.055 *
m + z_bias_avg;
384 if (z_prim[iz] < 0 && z_prim[iz] > -1.055 *
m)
388 if (z_ibf[iz] < 0 && z_ibf[iz] > -1.055 *
m)
397 for (
int iz = 0; iz < 30; iz++)
399 if (f_fill_prim[iz] == 1)
403 if (f_fill_ibf[iz] == 1)
411 double w_ibf_tmp = newWeights[0];
412 double w_gain_tmp = newWeights[1];
424 if(iz==0)
_h_SC_XY->Fill(new_r * cos(new_phi),new_r * sin(new_phi));
429 if (f_fill_ibf[0] == 1)
447 std::cout <<
"fillSpaceChargeMaps::End" << std::endl;
454 for (
int iz = 0; iz < 30; iz++)
468 std::cout <<
"Writing File:" <<
_filename << std::endl;
478 std::cout <<
"Frequency is set to: " <<
_freqKhz <<
" kHz" << std::endl;
484 std::cout <<
"Initial BeamXing is set to: " <<
_beamxing[0] << std::endl;
494 std::cout <<
"Starting event is set to: " << newEvtStart << std::endl;
500 std::cout <<
"Using IBF and Gain Maps" << std::endl;
505 std::cout <<
"Gain is set to: " <<
_ampGain << std::endl;
510 std::cout <<
"IBF is set to: " <<
_ampIBFfrac << std::endl;
517 std::cout <<
"Collision system is set to: " << s_syst[
_collSyst] << std::endl;
524 std::cout <<
"Averaging is set to: " << s_avg[
_fAvg] << std::endl;
529 static const std::string s_sliming[2] = {
"OFF",
"ON"};
530 std::cout <<
"Sliming is set to: " << s_sliming[
_fSliming] << std::endl;
536 static const std::string s_shiftElectrons[2] = {
"OFF",
"ON"};
537 std::cout <<
"Use Field-Maps is set to: " << s_shiftElectrons[
_shiftElectrons] << std::endl;
540 std::vector<double>
fillSpaceChargeMaps::getNewWeights(TH3 *h_SC_ibf, TH2 *h_modules_anode, TH2 *h_modules_measuredibf,
double hit_r,
double hit_phi,
double dr_bin,
double dphi_bin,
bool fUseIBFMap)
542 double w_ibf_tmp = 1.0;
543 double w_gain_tmp = 1.0;
544 int r_bin =
_h_R->GetXaxis()->FindBin(dr_bin);
545 double r_bin_c =
_h_R->GetXaxis()->GetBinCenter(r_bin);
546 double r_bin_r =
_h_R->GetXaxis()->GetBinCenter(r_bin+1);
547 double r_bin_l =
_h_R->GetXaxis()->GetBinCenter(r_bin-1);
549 int phi_bin = h_SC_ibf->GetXaxis()->FindBin(dphi_bin);
551 double phi_bin_c = h_SC_ibf->GetXaxis()->GetBinCenter(phi_bin);
552 double phi_bin_r = h_SC_ibf->GetXaxis()->GetBinCenter(phi_bin+1);
553 double phi_bin_l = h_SC_ibf->GetXaxis()->GetBinCenter(phi_bin-1);
557 if (dr_bin > 0 && dphi_bin < 0)
559 if (hit_r - r_bin_c > 0)
569 if (dr_bin < 0 && dphi_bin > 0)
571 if (hit_phi - phi_bin_c > 0)
580 if (dr_bin > 0 && dphi_bin > 0)
582 if (hit_phi - phi_bin_c >= 0 && hit_r - r_bin_c >= 0)
587 if (hit_phi - phi_bin_c <= 0 && hit_r - r_bin_c <= 0)
592 if (hit_phi - phi_bin_c >= 0 && hit_r - r_bin_c <= 0)
597 if (hit_phi - phi_bin_c <= 0 && hit_r - r_bin_c >= 0)
605 double x_tmp = hit_r * cos(hit_phi);
606 double y_tmp = hit_r * sin(hit_phi);
607 int bin_x = h_modules_anode->GetXaxis()->FindBin(x_tmp);
608 int bin_y = h_modules_anode->GetYaxis()->FindBin(y_tmp);
609 w_ibf_tmp = h_modules_measuredibf->GetBinContent(bin_x, bin_y);
610 w_gain_tmp = h_modules_anode->GetBinContent(bin_x, bin_y);
624 std::vector<double> newWeights;
625 newWeights.push_back(w_ibf_tmp);
626 newWeights.push_back(w_gain_tmp);
627 newWeights.push_back(hit_r);
628 newWeights.push_back(hit_phi);
637 double tpc_margin = 2.0 *
mm;
639 double tpc_frame_r3_outer = 759.11 *
mm;
640 double tpc_frame_r3_inner = 583.67 *
mm;
642 double tpc_frame_r2_outer = 574.76 *
mm;
643 double tpc_frame_r2_inner = 411.53 *
mm;
645 double tpc_frame_r1_outer = 402.49 *
mm;
646 double tpc_frame_r1_inner = 217.83 *
mm;
651 if (r <= tpc_frame_r1_inner + tpc_margin)
655 if (r >= tpc_frame_r1_outer - tpc_margin && r <= tpc_frame_r2_inner + tpc_margin)
659 if (r >= tpc_frame_r2_outer - tpc_margin && r <= tpc_frame_r3_inner + tpc_margin)
663 if (r >= tpc_frame_r3_outer - tpc_margin)
668 for(
int p=0;
p<24;
p=
p+2){
681 double tpc_margin = 2.0*
mm;
683 double tpc_frame_r3_outer = 759.11*
mm;
684 double tpc_frame_r3_inner = 583.67*
mm;
686 double tpc_frame_r2_outer = 574.76*
mm;
687 double tpc_frame_r2_inner = 411.53*
mm;
689 double tpc_frame_r1_outer = 402.49*
mm;
690 double tpc_frame_r1_inner = 217.83*
mm;
694 double phi_0_bin = -1;
696 if (r >= tpc_frame_r1_inner - 2*tpc_margin && r <= tpc_frame_r1_inner + tpc_margin)
699 r_0_bin = tpc_frame_r1_inner - tpc_margin/2;
701 if (r >= tpc_frame_r1_outer - tpc_margin && r <= tpc_frame_r2_inner + tpc_margin)
703 r_0_bin = tpc_frame_r2_inner-(tpc_frame_r2_inner - tpc_frame_r1_outer)/2;
705 if (r >= tpc_frame_r2_outer - tpc_margin && r <= tpc_frame_r3_inner + tpc_margin)
707 r_0_bin = tpc_frame_r3_inner-(tpc_frame_r3_inner - tpc_frame_r2_outer)/2;
709 if (r >= tpc_frame_r3_outer - tpc_margin)
712 r_0_bin = tpc_frame_r3_outer + tpc_margin/2;
719 for(
int p=0;
p<24;
p=
p+2){
742 std::vector<double> r_phi_bin;
743 r_phi_bin.push_back(r_0_bin);
744 r_phi_bin.push_back(phi_0_bin);