19 printf(
"made a new ChargeMapReader with default values -- cascading to next constructor\n");
25 printf(
"made a new ChargeMapReader with defined values:\n %d %.2f %.2f\n %d %.2f %.2f\n %d %.2f %.2f\n",
26 _nr, _rmin, _rmax, _nphi, _phimin, _phimax, _nz, _zmin, _zmax);
50 float pos[3] = {
x,
y, z};
52 TAxis*
ax[3] = {
nullptr,
nullptr,
nullptr};
53 ax[0] = h->GetXaxis();
54 ax[1] = h->GetYaxis();
55 ax[2] = h->GetZaxis();
58 for (
int i = 0;
i < 3;
i++)
60 nbins[
i] = ax[
i]->GetNbins();
69 for (
int i = 0;
i < 3;
i++)
71 int axbin = ax[
i]->FindBin(pos[
i]);
73 if (axbin < 1 || axbin > nbins[i])
77 if (axbin > 1 && axbin < nbins[i])
83 float low = ax[
i]->GetBinLowEdge(axbin);
84 float high = ax[
i]->GetBinUpEdge(axbin);
85 float binmid = 0.5 * (high + low);
87 if (axbin == 1 && pos[i] <= binmid)
91 if (axbin == nbins[i] && pos[i] >= binmid)
110 printf(
"filling chargehistogram\n");
119 for (i[0] = 0; i[0] <
nBins[0]; i[0]++)
121 float rmid =
lowerBound[0] + (i[0] + 0.5) * dr;
122 for (i[1] = 0; i[1] < nBins[1]; i[1]++)
125 for (i[2] = 0; i[2] < nBins[2]; i[2]++)
128 h->Fill(phimid, rmid, zmid,
charge->
Get(i[0], i[1], i[2]));
147 printf(
"no charge data found. Setting all charges to 0.0\n");
158 float dzhist, drhist;
165 for (i[0] = 0; i[0] <
nBins[0]; i[0]++)
169 float histBinVolume = dzhist * dphi * rmid * drhist;
173 for (i[1] = 0; i[1] < nBins[1]; i[1]++)
176 for (i[2] = 0; i[2] < nBins[2]; i[2]++)
184 printf(
"function said we could interpolate at (r,phi,z)=(%.2f, %.2f,%.2f), bounds are:\n", rmid, phimid, zmid);
189 q = scaleFactor *
hChargeDensity->Interpolate(phimid, rmid, zmid);
200 printf(
"density debug report (interp) (r,phi,z)=(%.2f, %.2f,%.2f), glob=%d, q_dens=%E", rmid, phimid, zmid, global, q);
202 printf(
", q_bin=%E, q_bin_coul=%E",
205 printf(
", q_interp=%E, q_bin_coul/vol=%E\n",
211 printf(
"density debug report (getbin) (r,phi,z)=(%.2f, %.2f,%.2f), glob=%d, q_dens=%E", rmid, phimid, zmid, global, q);
213 printf(
", q_bin=%E, q_bin_ions=%E",
216 printf(
", q_bin_ions/vol=%E\n",
228 printf(
"done regenerating charge array contents\n");
240 printf(
"regenerating density histogram\n");
248 printf(
"deleting old density histogram\n");
255 printf(
"no source charge data file is open, or the histogram was not found.\n");
266 TAxis*
ax[3] = {
nullptr,
nullptr,
nullptr};
272 for (
int i = 0;
i < 3;
i++)
274 nbins[
i] = ax[
i]->GetNbins();
280 float low[3], high[3];
284 for (i[0] = 1; i[0] <= nbins[0]; i[0]++)
287 low[
a] = ax[
a]->GetBinLowEdge(i[a]);
288 high[
a] = ax[
a]->GetBinUpEdge(i[a]);
289 float dphi = high[
a] - low[
a];
290 for (i[1] = 1; i[1] <= nbins[1]; i[1]++)
293 low[
a] = ax[
a]->GetBinLowEdge(i[a]);
294 high[
a] = ax[
a]->GetBinUpEdge(i[a]);
295 dr = high[
a] - low[
a];
296 float rphiterm = dphi * (low[1] + 0.5 * dr) * dr;
297 for (i[2] = 1; i[2] <= nbins[2]; i[2]++)
300 low[
a] = ax[
a]->GetBinLowEdge(i[a]);
301 high[
a] = ax[
a]->GetBinUpEdge(i[a]);
302 dz = high[
a] - low[
a];
304 float volume = dz * rphiterm;
310 printf(
"iprz=(%d,%d,%d),glob=%d", i[0], i[1], i[2], globalBin);
311 printf(
"edges=[%.2f,%.2f],[%.1f,%.1f],[%.1f,%f.1],", low[0], high[0], low[1], high[1], low[2], high[2]);
319 printf(
"done regenerating density histogram\n");
330 TFile* inputFile = TFile::Open(filename,
"READ");
347 printf(
"reading charge from %s\n", sourceHist->GetName());
361 printf(
"done reading charge from %s\n", sourceHist->GetName());
367 bool ChargeMapReader::ReadSourceAdc(
const char* adcfilename,
const char* adchistname,
const char* ibfgainfilename,
const char* ibfgainhistname,
float axisScale,
float contentScale)
370 TFile* adcInputFile = TFile::Open(adcfilename,
"READ");
372 adcInputFile->GetObject(adchistname, hAdc);
375 printf(
"Source Charge hist or file %s not found!\n", adcfilename);
379 TFile* ibfGainInputFile = TFile::Open(ibfgainfilename,
"READ");
380 TH2* hIbfGain =
nullptr;
381 ibfGainInputFile->GetObject(ibfgainhistname, hIbfGain);
382 if (hIbfGain ==
nullptr)
384 printf(
"IBF Gain hist or file %s not found!\n", ibfgainfilename);
389 bool ret =
ReadSourceAdc(hAdc, hIbfGain, axisScale, contentScale);
390 adcInputFile->Close();
399 printf(
"reading ADCs from %s, ibfGain from %s\n", adcHist->GetName(), gainHist->GetName());
411 TAxis*
ax[3] = {
nullptr,
nullptr,
nullptr};
417 for (
int i = 0;
i < 3;
i++)
419 nbins[
i] = ax[
i]->GetNbins();
426 for (i[0] = 1; i[0] <= nbins[0]; i[0]++)
428 for (i[1] = 1; i[1] <= nbins[1]; i[1]++)
430 int globalBin2D = gainHist->GetBin(i[0], i[1]);
431 float scalefactor = gainHist->GetBinContent(globalBin2D);
432 for (i[2] = 1; i[2] <= nbins[2]; i[2]++)
439 printf(
"applying gain to adc input: iprz=(%d,%d,%d), glob3d=%d, glob2d=%d, adc=%f, scale=%f\n", i[0], i[1], i[2], globalBin, globalBin2D, q, scalefactor);
446 printf(
"done converting adc hist to ions\n");
454 printf(
"done converting ADCs from %s\n", adcHist->GetName());
463 if (!(_rmax > _rmin) || !(_phimax > _phimin) || !(_zmax > _zmin))
467 if (_nr < 1 || _nphi < 1 || _nz < 1)
482 for (
int i = 0;
i < 3;
i++)
492 printf(
"charge array existed. deleting\n");
499 printf(
"building new charge array\n");
512 printf(
"charge density data exists, regenerating charge\n");
522 printf(
"finished building array\n");
532 if (!(_rmax > _rmin) || !(_phimax > _phimin) || !(_zmax > _zmin))
544 for (
int i = 0;
i < 3;
i++)
573 if (_nr < 1 || _nphi < 1 || _nz < 1)
581 for (
int i = 0;
i < 3;
i++)
612 printf(
"adding charge in array element %d %d %d to %.2E\n", r, phi, z, q);
628 if (!(r >= 0 && r <
nBins[0]))
630 printf(
"requested rbin %d, but bounds are %d to %d. Failing.\n", r, 0,
nBins[0]);
633 if (!(phi >= 0 && phi <
nBins[1]))
635 printf(
"requested phibin %d, but bounds are %d to %d. Failing.\n", phi, 0,
nBins[1]);
638 if (!(z >= 0 && z <
nBins[2]))
640 printf(
"requested rbin %d, but bounds are %d to %d. Failing.\n", z, 0,
nBins[2]);
646 printf(
"getting charge in array element %d %d %d\n", r, phi, z);
660 if (!(r >= 0 && r <
nBins[0]))
662 printf(
"requested rbin %d, but bounds are %d to %d. Failing.\n", r, 0,
nBins[0]);
665 if (!(phi >= 0 && phi <
nBins[1]))
667 printf(
"requested phibin %d, but bounds are %d to %d. Failing.\n", phi, 0,
nBins[1]);
670 if (!(z >= 0 && z <
nBins[2]))
672 printf(
"requested rbin %d, but bounds are %d to %d. Failing.\n", z, 0,
nBins[2]);
677 printf(
"setting charge in array element %d %d %d to %.2E\n", r, phi, z, q);