Skip to content

Commit

Permalink
Merge pull request #68 from NESTCollaboration/gr_sync
Browse files Browse the repository at this point in the history
Synced with NESTv2.2.2; updated HISTORY.md
  • Loading branch information
grischbieter authored Jul 8, 2021
2 parents e10b5a4 + 6861374 commit 3cfe989
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 133 deletions.
23 changes: 23 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ History

Patch releases mean (the Z number in X.Y.Z version) that the underlying physics has not changed. Changes to the NEST version will always trigger a minor or major release. If this library changes such that end users have to change their code, this may also trigger a minor or major release.


1.4.10 (2021-07-08)
-----------------
Sync with [NEST v2.2.2](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.2)

Code Quality and/or Misc Bug Fixes:
* Added default density argument for LXe case, forcing an argument re-ordering (Sophia)
* Moved position of "delete detector" in execNEST to solve python problem (Albert Baker, Greg R.)
* Approx eff func for single phe made simpler, for FlameDisx (Robert James, Sophia, Matthew)
* More robust rule used for when to approximate binomial as Gaussian (Sophia, Greg R.)
* Warn that you are in a region of too-low time between S1a and S1b for Kr83m only 1x (Sophia)
* Bad-order if-statements simplified with a min within a max for <0, >1 checks (Luke K., Matthew)
New Physics:
* Liquid Ar model for ER fits all the data better now, in both energy and dE/dx bases (Kate K.)

Code Quality and/or Miscellaneous Bug Fixes:
* Deleted unused redundant line in GetS1 that re-calculated the drift time (Quentin Riffard, LBNL/LZ)
* Only print most error and warning messages if verbosity on (Quentin Riffard, LBNL/LZ)
* Updated TravisCI link in README and added note about OSX builds (Chris Tunnell, Rice/XENON)
* Use of abs value func standardized, lines broken up, multi-line string for cerr (Matthew at behest of Luke Kreczko, Bristol/LZ)
New Physics:
* Liquid Xe model for NR is now better behaved at few hundred keV and few hundred in S1: no odd increase in band width caused by Nex/Ni zeroing out and kinking the recombination probability. Mean yields model unchanged, nor recombination fluctuations / skewness. (Matthew and Greg R., UAlbany/LZ)

1.4.9 (2021-06-01)
-----------------
Sync with [NEST v2.2.1patch2](https://github.com/NESTCollaboration/nest/releases/tag/v2.2.1patch2)
Expand Down
2 changes: 1 addition & 1 deletion src/nestpy/LUX_Run03.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public:

double radius = sqrt(pow(xPos_mm,2.)+pow(yPos_mm,2.));
double amplitude = 307.9-0.3071*zPos_mm+0.0002257*pow(zPos_mm,2.);
double shape = 1.1525e-7*sqrt(fabs(zPos_mm-318.84));
double shape = 1.1525e-7*sqrt(std::abs(zPos_mm-318.84));
double finalCorr = -shape * pow ( radius, 3. ) + amplitude;
finalCorr /= 307.9;
if ( (finalCorr < 0.5 || finalCorr > 1.5 || std::isnan(finalCorr)) && radius < radmax ) {
Expand Down
71 changes: 41 additions & 30 deletions src/nestpy/NEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ QuantaResult NESTcalc::GetQuanta(const YieldResult& yields, double density,
if (ValidityTests::nearlyEqual(yields.Lindhard, 1.) ) {
skewness = 1. / (1. + exp((engy - E2) / E3)) * (alpha0 + cc0 * exp(-1. * fld / F0) * (1. - exp(-1. * engy / E0))) +
1. / (1. + exp(-1. * (engy - E2) / E3)) * cc1 * exp(-1. * engy / E1) * exp(-1. * sqrt(fld) / sqrt(F1));
//if ( fabs(skewness) <= DBL_MIN ) skewness = DBL_MIN;
//if ( std::abs(skewness) <= DBL_MIN ) skewness = DBL_MIN;
}
else {
skewness = FreeParam[5]; //2.25 but ~5-20 also good (for NR). All better than zero, but 0 is OK too
Expand All @@ -311,7 +311,7 @@ QuantaResult NESTcalc::GetQuanta(const YieldResult& yields, double density,

double widthCorrection = sqrt( 1. - (2./M_PI) * skewness*skewness/(1. + skewness*skewness));
double muCorrection = (sqrt(Variance)/widthCorrection)*(skewness/sqrt(1.+skewness*skewness))*sqrt(2./M_PI);
if ( fabs(skewness) > DBL_MIN && ValidityTests::nearlyEqual(ATOM_NUM, 54.) ) //skewness model only for Xenon!
if ( std::abs(skewness) > DBL_MIN && ValidityTests::nearlyEqual(ATOM_NUM, 54.) ) //skewness model only for Xenon!
Ne = int(floor(RandomGen::rndm()->rand_skewGauss((1.-recombProb)*Ni-muCorrection,sqrt(Variance)/widthCorrection,skewness)+0.5));
else
Ne = int(floor(RandomGen::rndm()->rand_gauss((1.-recombProb)*Ni,sqrt(Variance))+0.5));
Expand Down Expand Up @@ -413,7 +413,7 @@ YieldResult NESTcalc::GetYieldNR(double energy, double density, double dfield, d
{
throw std::runtime_error("ERROR: You need a minimum of 12 nuisance parameters for the mean yields.");
}
if ( energy > 330. )
if ( energy > HIGH_E_NR )
cerr << "\nWARNING: No data out here, you are beyond the AmBe endpoint of about 300 keV.\n";
int massNumber;
double ScaleFactor[2] ={1., 1.};
Expand All @@ -436,16 +436,28 @@ YieldResult NESTcalc::GetYieldNR(double energy, double density, double dfield, d
(1. - 1. / pow(1. + pow((energy / NuisParam[7]), NuisParam[8]), NuisParam[11]));
Nq = Nph + Ne;
double Ni = (4. / ThomasImel) * (exp(Ne * ThomasImel / 4.) - 1.);
double Nex = (-1. / ThomasImel) * (4. * exp(Ne * ThomasImel / 4.) -
(Ne + Nph) * ThomasImel - 4.);
if ( Nex <= 0. ) cerr << "\nCAUTION: You are approaching the border of NEST's validity for high-energy (OR, for LOW) NR, or are beyond it, at " << energy << " keV." << endl;
if ( fabs(Nex + Ni -Nq) > 2. * PHE_MIN )
double Nex = (-1. / ThomasImel) * (4. * exp(Ne * ThomasImel / 4.) - (Ne + Nph) * ThomasImel - 4.);

double NexONi = Nex / Ni;
Wvalue wvalue = WorkFunction(density,fdetector->get_molarMass(),fdetector->get_rmQuanta());
if ( NexONi < wvalue.alpha && energy > 1e2 ) {
NexONi = wvalue.alpha;
Ni = Nq / ( 1. + NexONi );
Nex = Nq - Ni;
}
if ( NexONi > 1.0 && energy < 1. ) {
NexONi = 1.00;
Ni = Nq / ( 1. + NexONi );
Nex = Nq - Ni;
}

if ( Nex <= 0. )
cerr << "\nCAUTION: You are approaching the border of NEST's validity for high-energy (OR, for LOW) NR, or are beyond it, at " << energy << " keV." << endl;
if ( std::abs ( Nex + Ni - Nq ) > 2. * PHE_MIN )
{
throw std::runtime_error("ERROR: Quanta not conserved. Tell Matthew Immediately!");
}
double NexONi = Nex / Ni;

Wvalue wvalue = WorkFunction(density,fdetector->get_molarMass(),fdetector->get_rmQuanta());
double Wq_eV = wvalue.Wq_eV;
double L = (Nq / energy) * Wq_eV * 1e-3;

Expand Down Expand Up @@ -784,7 +796,6 @@ vector<double> NESTcalc::GetS1(const QuantaResult &quanta, double truthPosX, dou
posDepSm = fdetector->FitS1(smearPos[0], smearPos[1], smearPos[2], VDetector::unfold);
else
posDepSm = fdetector->FitS1(0, 0, smearPos[2], VDetector::unfold);
double dt = (fdetector->get_TopDrift() - truthPos[2]) / driftVelocity;
double dz_center = fdetector->get_TopDrift() -
dV_mid * fdetector->get_dtCntr(); // go from t to z
posDep /=
Expand Down Expand Up @@ -894,7 +905,7 @@ vector<double> NESTcalc::GetS1(const QuantaResult &quanta, double truthPosX, dou
AreaTable[0].resize(numPts, 0.);
AreaTable[1].resize(numPts, 0.);

int total_photons = (int)fabs(spike);
int total_photons = (int)std::abs(spike);
int excitons = int(double(total_photons)*double(quanta.excitons)/double(quanta.photons));
photonstream photon_emission_times =
GetPhotonTimes(type_num, total_photons, excitons, dfield, energy);
Expand All @@ -909,7 +920,7 @@ vector<double> NESTcalc::GetS1(const QuantaResult &quanta, double truthPosX, dou

int ii, index;
double min = 1e100, pTime;
for (ii = 0; ii < (int)fabs(spike); ++ii) {
for (ii = 0; ii < (int)std::abs(spike); ++ii) {
PEperBin.clear();
PEperBin = fdetector->SinglePEWaveForm(
photon_areas[0][ii] + photon_areas[1][ii], photon_times[ii]);
Expand Down Expand Up @@ -1052,21 +1063,21 @@ vector<double> NESTcalc::GetS1(const QuantaResult &quanta, double truthPosX, dou
if ( RandomGen::rndm()->rand_uniform() > prob && prob < 1. ) { // coincidence has to happen in different PMTs
// some of these are set to -1 to flag them as having been below threshold
if (ValidityTests::nearlyEqual(scintillation[0], 0.)) scintillation[0] = PHE_MIN;
scintillation[0] = -1.*fabs(scintillation[0]);
scintillation[0] = -1.*std::abs(scintillation[0]);
if (ValidityTests::nearlyEqual(scintillation[1], 0.)) scintillation[1] = PHE_MIN;
scintillation[1] = -1.*fabs(scintillation[1]);
scintillation[1] = -1.*std::abs(scintillation[1]);
if (ValidityTests::nearlyEqual(scintillation[2], 0.)) scintillation[2] = PHE_MIN;
scintillation[2] = -1.*fabs(scintillation[2]);
scintillation[2] = -1.*std::abs(scintillation[2]);
if (ValidityTests::nearlyEqual(scintillation[3], 0.)) scintillation[3] = PHE_MIN;
scintillation[3] = -1.*fabs(scintillation[3]);
scintillation[3] = -1.*std::abs(scintillation[3]);
if (ValidityTests::nearlyEqual(scintillation[4], 0.)) scintillation[4] = PHE_MIN;
scintillation[4] = -1.*fabs(scintillation[4]);
scintillation[4] = -1.*std::abs(scintillation[4]);
if (ValidityTests::nearlyEqual(scintillation[5], 0.)) scintillation[5] = PHE_MIN;
scintillation[5] = -1.*fabs(scintillation[5]);
scintillation[5] = -1.*std::abs(scintillation[5]);
if (ValidityTests::nearlyEqual(scintillation[6], 0.)) scintillation[6] = PHE_MIN;
scintillation[6] = -1.*fabs(scintillation[6]);
scintillation[6] = -1.*std::abs(scintillation[6]);
if (ValidityTests::nearlyEqual(scintillation[7], 0.)) scintillation[7] = PHE_MIN;
scintillation[7] = -1.*fabs(scintillation[7]);
scintillation[7] = -1.*std::abs(scintillation[7]);
}

// scintillation[8] =
Expand Down Expand Up @@ -1164,7 +1175,7 @@ vector<double> NESTcalc::GetS2(int Ne, double truthPosX, double truthPosY, doubl
for (i = 0; i < stopPoint; ++i) {
elecTravT = 0.; // resetting for the current electron
DL = RandomGen::rndm()->rand_gauss(0., sigmaDL);
DT = fabs(RandomGen::rndm()->rand_gauss(0., sigmaDT));
DT = std::abs(RandomGen::rndm()->rand_gauss(0., sigmaDT));
phi = 2. * M_PI * RandomGen::rndm()->rand_uniform();
sigX = DT * cos(phi);
sigY = DT * sin(phi);
Expand Down Expand Up @@ -1211,7 +1222,7 @@ vector<double> NESTcalc::GetS2(int Ne, double truthPosX, double truthPosY, doubl
DL_time = DL / driftVelocity_gas;
electronstream[i] += DL_time;
if ( i >= Nee && eTrain ) { // exponential based on arXiv:1711.07025, power on 2004.07791
E_liq = fdetector->get_E_gas() / (EPS_LIQ / fabs(EPS_GAS));
E_liq = fdetector->get_E_gas() / (EPS_LIQ / std::abs(EPS_GAS));
tau2 = ( fdetector->get_TopDrift() / driftVelocity );//0.58313 * exp(0.20929 * E_liq) * 1e3;
tau1 = 1.40540 * exp(0.15578 * E_liq) * 1e3 * 1e-2;
amp2 = 0.38157 * exp(0.21177 * E_liq) * 1e-2;
Expand Down Expand Up @@ -1362,10 +1373,10 @@ vector<double> NESTcalc::GetS2(int Ne, double truthPosX, double truthPosY, doubl
// units)
}

if (pulseArea < fabs(fdetector->get_s2_thr())) {
if (pulseArea < std::abs(fdetector->get_s2_thr())) {
for (i = 0; i < 8; ++i) {
if (ValidityTests::nearlyEqual(ionization[i], 0.)) ionization[i] = PHE_MIN;
ionization[i] = -1.*fabs(ionization[i]);
ionization[i] = -1.*std::abs(ionization[i]);
}
}

Expand All @@ -1381,7 +1392,7 @@ vector<double> NESTcalc::CalculateG2(bool verbosity) {
// Set parameters for calculating EL yield and extraction
double alpha = 0.137, beta = 4.70e-18, gamma = 0; // note the value of alpha is similar to ~1/7eV. Not coincidence. Noted in Mock et al.
// actually listed as 'a' and 'b' in ref (below). Units 1/V, cm^2
double epsilonRatio = EPS_LIQ / fabs(EPS_GAS);
double epsilonRatio = EPS_LIQ / std::abs(EPS_GAS);
if (fdetector->get_inGas())
epsilonRatio = 1.; // in an all-gas detector, E_liq variable below simply
// becomes the field value between anode and gate
Expand Down Expand Up @@ -1501,7 +1512,7 @@ vector<double> NESTcalc::GetSpike(int Nph, double dx, double dy, double dz,
newSpike[1] = oldScint[5];
return newSpike;
}
newSpike[0] = fabs(oldScint[6]);
newSpike[0] = std::abs(oldScint[6]);
double TruncGauss = 0.;
while ( TruncGauss <= 0. )
TruncGauss = RandomGen::rndm()->rand_gauss(newSpike[0],(fdetector->get_sPEres()/4.)*sqrt(newSpike[0]));
Expand Down Expand Up @@ -1727,7 +1738,7 @@ double NESTcalc::GetDriftVelocity_MagBoltz(
}
if (gasdep >= 3.8e-17) edrift = 6e21 * gasdep - 32279.;

return fabs ( edrift ) * 1e-5; // from cm/s into mm per microsecond
return std::abs ( edrift ) * 1e-5; // from cm/s into mm per microsecond
}

vector<double> NESTcalc::SetDriftVelocity_NonUniform(double rho, double zStep,
Expand All @@ -1742,7 +1753,7 @@ vector<double> NESTcalc::SetDriftVelocity_NonUniform(double rho, double zStep,
if (!fdetector->get_inGas())
driftTime += zStep / SetDriftVelocity(fdetector->get_T_Kelvin(), rho,
fdetector->get_E_gas() /
(EPS_LIQ / fabs(EPS_GAS)) * 1e3);
(EPS_LIQ / std::abs(EPS_GAS)) * 1e3);
else // if gate == TopDrift properly set, shouldn't happen
driftTime += zStep / GetDriftVelocity_MagBoltz(
rho, fdetector->get_E_gas() * 1e3);
Expand Down Expand Up @@ -1774,12 +1785,12 @@ vector<double> NESTcalc::xyResolution(double xPos_mm, double yPos_mm,
double sigmaR = kappa / sqrt(A_top); // ibid.

double phi = 2. * M_PI * RandomGen::rndm()->rand_uniform();
sigmaR = fabs(RandomGen::rndm()->rand_gauss(0.0, sigmaR));
sigmaR = std::abs(RandomGen::rndm()->rand_gauss(0.0, sigmaR));
double sigmaX = sigmaR * cos(phi);
double sigmaY = sigmaR * sin(phi);

if ( sigmaR > 1e2 || std::isnan(sigmaR) || sigmaR <= 0. ||
fabs(sigmaX) > 1e2 || fabs(sigmaY) > 1e2 ) {
std::abs(sigmaX) > 1e2 || std::abs(sigmaY) > 1e2 ) {
if ( A_top > 20. ) {
cerr << "WARNING: your position resolution is worse than 10 cm. Is that correct?!" << endl;
cerr << "Setting resolution to perfect." << endl; sigmaX=0.; sigmaY=0.;
Expand Down
1 change: 1 addition & 0 deletions src/nestpy/NEST.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include <vector>
#include <string>

#define HIGH_E_NR 330.
#define W_DEFAULT 13.4 // default work func, in eV. arXiv:1611.10322. +/- 0.35. 19.5-19.6 eV for LAr
#define W_SCINT 8.5e-3 // the *max* possible energy of 1 scint phot, keV. Make this at least 10 eV for LAr
#define NEST_AVO 6.0221409e+23
Expand Down
2 changes: 1 addition & 1 deletion src/nestpy/TestSpectra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ double TestSpectra::WIMP_dRate(double ER, double mWimp, double dayNum) {
if ((x_e + x_min) < x_esc) {
thisCase = 1;
}
if ((x_min > fabs(x_esc - x_e)) && ((x_e + x_esc) > x_min)) {
if ((x_min > std::abs(x_esc - x_e)) && ((x_e + x_esc) > x_min)) {
thisCase = 2;
}
if (x_e > (x_min + x_esc)) {
Expand Down
4 changes: 2 additions & 2 deletions src/nestpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__version__ = '1.4.9'
__nest_version__ = '2.2.1patch2'
__version__ = '1.4.10'
__nest_version__ = '2.2.2'

from .nestpy import *

Expand Down
Loading

0 comments on commit 3cfe989

Please sign in to comment.