/** * Fills in a column of the matrix with this mass profile, starting at the given * index * @param cmatrix InOut matrix whose column should be set to the mass profile * for each active hermite polynomial * @param start Index of the column to start on * @param errors The data errors * @returns The number of columns filled */ size_t MultivariateGaussianComptonProfile::fillConstraintMatrix( Kernel::DblMatrix &cmatrix, const size_t start, const std::vector<double> &errors) const { std::vector<double> result(ySpace().size()); this->massProfile(result.data(), ySpace().size()); std::transform(result.begin(), result.end(), errors.begin(), result.begin(), std::divides<double>()); cmatrix.setColumn(start, result); return 1; }
void MultivariateGaussianComptonProfile::massProfile( double *result, const size_t nData, const double amplitude) const { std::vector<double> s2Cache; buildS2Cache(s2Cache); const double sigmaX(getParameter(SIGMA_X_PARAM)); const double sigmaY(getParameter(SIGMA_Y_PARAM)); const double sigmaZ(getParameter(SIGMA_Z_PARAM)); const double prefactorJ = (1.0 / (sqrt(2.0 * M_PI) * sigmaX * sigmaY * sigmaZ)) * (2.0 / M_PI); const double prefactorFSE = (pow(sigmaX, 4) + pow(sigmaY, 4) + pow(sigmaZ, 4)) / (9.0 * sqrt(2.0 * M_PI) * sigmaX * sigmaY * sigmaZ); const auto &yspace = ySpace(); const auto &modq = modQ(); for (size_t i = 0; i < nData; i++) { const double y(yspace[i]); const double q(modq[i]); double j = prefactorJ * calculateJ(s2Cache, y); double fse = (prefactorFSE / q) * calculateFSE(s2Cache, y); result[i] = amplitude * (j + fse); } }
void moveSelectedUnits() { float coords[2] = { getMouseX(), getMouseY() }; for (int a = 0; a < unitSpawnIndex; a++) { if (u_Current.getSelected() && u_Current.getTarget() == NOTHING) { PosDim unit = u_Current.getPosDim(); if (coords[0] > xSpace(100) - (unit.w / 2)) { coords[0] = xSpace(100) - (unit.h / 2); } else if (coords[0] < xSpace(0) + (unit.w / 2)) { coords[0] = xSpace(0) + (unit.w / 2); } if (coords[1] > ySpace(100) - (unit.h / 2)) { coords[1] = ySpace(100) - (unit.h / 2); } else if (coords[1] < ySpace(20) + (unit.h / 2)) { coords[1] = ySpace(20) + (unit.h / 2); } u_Current.setTargetCoords(coords[0], coords[1]); u_Current.setUnitCollision(false); } } }
//Build a barracks void aih_PB() { bool ud = std::rand() % 2; if (ud) { for (int a = 0; a < gridY; a++) { for (int b = 0; b < gridX; b++) { int y = a; int x = b; if (aih_bg[a][b] == 3) { spawnBuild(b_HumanBarracks, xSpace(buildGrid[y][x] * 10 + 5), ySpace((buildGrid[y + 1][x] + y + 3 - x) * 10 - 7)); p_Player.addMoney(-b_HumanBarracks.getCost()); return; } } } } else { for (int a = gridY - 1; a > 0; a--) { for (int b = gridX - 1; b > 0; b--) { int y = a; int x = b; if (aih_bg[a][b] == 3) { spawnBuild(b_HumanBarracks, xSpace(buildGrid[y][x] * 10 + 5), ySpace((buildGrid[y + 1][x] + y + 3 - x) * 10 - 7)); p_Player.addMoney(-b_HumanBarracks.getCost()); return; } } } } }
/** * Uses a Gaussian approximation for the mass and convolutes it with the Voigt * instrument resolution function * @param result An pre-sized output vector that should be filled with the results * @param lorentzFWHM The lorentz width for the resolution * @param resolutionFWHM The sum-squared value of the resolution errors */ void GaussianComptonProfile::massProfile(std::vector<double> & result,const double lorentzFWHM, const double resolutionFWHM) const { double lorentzPos(0.0), gaussWidth(getParameter(0)), amplitude(getParameter(1)); double gaussFWHM = std::sqrt(std::pow(resolutionFWHM,2) + std::pow(2.0*STDDEV_TO_HWHM*gaussWidth,2)); const auto & yspace = ySpace(); // Gaussian already folded into Voigt voigtApprox(result, yspace, lorentzPos, amplitude, lorentzFWHM, gaussFWHM); std::vector<double> voigtDiffResult(yspace.size()); voigtApproxDiff(voigtDiffResult, yspace, lorentzPos, amplitude, lorentzFWHM, gaussFWHM); const auto & modq = modQ(); const size_t nData(result.size()); for(size_t j = 0; j < nData; ++j) { const double factor = std::pow(gaussWidth,4.0)/(3.0*modq[j]); result[j] -= factor*voigtDiffResult[j]; } }
void main() { int choiceMM = 0, choicePM = 0, choiceOM = 0, choiceBM = 0, choicePPM = 0, choiceLoss = 0; float tempSpeed; bool first = true; bool mm = true; bool dPress = false, aPress = false, wPress = false, sPress = false, spacePress = false; bool playTennis = false, playSingle = false, playMulti = false; bool ballOffScreen = false; bool ballOp = false, playOp = false; curCX = 250; curCY = 250; /*cout << "Please choose game mode:\n\n" << "Tennis: 1\n" << "Single Player: 2\n" << "Multiplayer: 3\n"; cin >> choice;*/ initContext(SCREEN_X, SCREEN_Y, "Pong"); while (stepContext()) { // The main Menu if(mm) { cout << "Main; "; //This if chunk makes one key = one press on MM if (getKey('D') && !dPress) { choiceMM++; dPress = true; } else if (getKey('A') && !aPress) { choiceMM--; aPress = true; } if (choiceMM <= -1) { choiceMM = 2; } else if (choiceMM >= 3) { choiceMM = 0; } if (getKey(' ') && !spacePress) { mm = false; spacePress = true; } cout << choiceMM << "(1); "; menuMain(choiceMM); } //All other menus else if (!mm && !playTennis && !playSingle && !playMulti) { cout << "Other menu; "; //Play menu if (choiceMM == 0) { cout << "Play Menu; "; cout << choicePM << "(1); "; if (getKey('D') && !dPress) { switch (choicePM) { case 0: choicePM = 1; break; case 1: choicePM = 0; break; case 2: choicePM = 3; break; case 3: choicePM = 2; break; } dPress = true; } else if (getKey('A') && !aPress) { switch (choicePM) { case 0: choicePM = 1; break; case 1: choicePM = 0; break; case 2: choicePM = 3; break; case 3: choicePM = 2; break; } aPress = true; } else if (getKey('W') && !wPress) { switch (choicePM) { case 0: choicePM = 2; break; case 1: choicePM = 3; break; case 2: choicePM = 0; break; case 3: choicePM = 1; break; } wPress = true; } else if (getKey('S') && !sPress) { switch (choicePM) { case 0: choicePM = 2; break; case 1: choicePM = 3; break; case 2: choicePM = 0; break; case 3: choicePM = 1; break; } sPress = true; } if (choicePM == -1) { choicePM = 3; } else if (choicePM == 4) { choicePM = 0; } if (getKey(' ') && !spacePress) { if (choicePM == 0) { playSingle = true; } else if (choicePM == 1) { playMulti = true; } else if (choicePM == 2) { choicePM = 0; choiceMM = 0; mm = true; } else { playTennis = true; } spacePress = true; } menuPlay(choicePM); } //Options menu else if (choiceMM == 1) { cout << "Op Menu; "; if (getKey('W') && !wPress) { choiceOM--; wPress = true; } else if (getKey('S') && !sPress) { choiceOM++; sPress = true; } if (choiceOM == -1) { choiceOM = 2; } else if (choiceOM == 3) { choiceOM = 0; } if (ballOp) { cout << "Ball menu; "; if (getKey('A')) { choiceBM--; } else if (getKey('D')) { choiceBM++; } if (choiceBM < 0) { choiceBM = 0; } else if(choiceBM > 1) {choiceBM = 1; } menuBallOp(choiceBM); if (getKey(' ') && !spacePress) { if (!choiceBM) { ballOp = false; menuBallOp(3); } else { menuBallOp(3); } spacePress = true; } cout << choiceBM << "(4); "; } else if (playOp) { cout << "Play mmenu; "; if (getKey('A')) { choicePPM--; } else if (getKey('D')) { choicePPM++; } if (choicePPM < 0) { choicePPM = 0; } else if (choicePPM > 1) { choicePPM = 1; } menuBallOp(choicePPM); if (getKey(' ') && !spacePress) { if (!choicePPM) { playOp = false; menuPlayOp(3); } else { menuPlayOp(3); } spacePress = true; } cout << choicePPM << "(4); "; } else if(getKey(' ') && !spacePress) { switch (choiceOM) { case 0: ballOp = true; break; case 1: playOp = true; break; case 2: choiceOM = 0; choiceMM = 0; mm = true; break; } spacePress = true; } else { menuOpt(choiceOM); } cout << choiceOM << "(1); "; } else if (choiceMM == 2) { termContext(); } } else if (playTennis) { if (first) { moveBall(true, true); first = false; } if (!ballOffScreen) { movePlayers(); moveBall(false, true); } else { if (getKey('W') && !wPress) { choiceLoss--, wPress = true; } else if (getKey('S') && !sPress) { choiceLoss++, sPress = true; } if (choiceLoss < 0) { choiceLoss = 2; } else if (choiceLoss > 2) { choiceLoss = 0; } menuLoss(choiceLoss); if (getKey(' ') && !spacePress) { switch (choiceLoss) { case 0: curCX = xSpace(1, 2); curCY = ySpace(1, 2); first = true; cSPEED_Y = 0; ballOffScreen = false; break; case 1: choicePM = 0; choiceMM = 0; choiceLoss = 0; mm = true; playTennis = false; curCX = xSpace(1, 2); curCY = ySpace(1, 2); first = true; cSPEED_Y = 0; ballOffScreen = false; break; case 2: termContext(); break; } } spacePress = true; } cout << choiceLoss << "(4); "; drawPlayer(PLAYER1); drawCircle(curCX, curCY, R); drawWalls(true); if (curCX > SCREEN_X || curCX < 0) { ballOffScreen = true; } } else if (playSingle) { if (first) { moveBall(true, false); first = false; } if (!ballOffScreen) { movePlayers(); moveBall(false, true); moveAI(); } else { if (getKey('W') && !wPress) { choiceLoss--, wPress = true; } else if (getKey('S') && !sPress) { choiceLoss++, sPress = true; } if (choiceLoss < 0) { choiceLoss = 2; } else if (choiceLoss > 2) { choiceLoss = 0; } menuLoss(choiceLoss); if (getKey(' ') && !spacePress) { switch (choiceLoss) { case 0: curCX = xSpace(1, 2); curCY = ySpace(1, 2); first = true; cSPEED_Y = 0; ballOffScreen = false; break; case 1: choicePM = 0; choiceMM = 0; choiceLoss = 0; mm = true; playSingle = false; curCX = xSpace(1, 2); curCY = ySpace(1, 2); first = true; cSPEED_Y = 0; ballOffScreen = false; break; case 2: termContext(); break; } } spacePress = true; } cout << choiceLoss << "(4); "; drawPlayer(PLAYER1); drawPlayer(AI); drawCircle(curCX, curCY, R); drawWalls(false); if (curCX > SCREEN_X || curCX < 0) { ballOffScreen = true; } } else if (playMulti) { if (first) { moveBall(true, false); first = false; } if (!ballOffScreen) { movePlayers(); moveBall(false, true); } else { if (getKey('W') && !wPress) { choiceLoss--, wPress = true; } else if (getKey('S') && !sPress) { choiceLoss++, sPress = true; } if (choiceLoss < 0) { choiceLoss = 2; } else if (choiceLoss > 2) { choiceLoss = 0; } menuLoss(choiceLoss); if (getKey(' ') && !spacePress) { switch (choiceLoss) { case 0: curCX = xSpace(1, 2); curCY = ySpace(1, 2); first = true; cSPEED_Y = 0; ballOffScreen = false; break; case 1: choicePM = 0; choiceMM = 0; choiceLoss = 0; mm = true; playMulti = false; curCX = xSpace(1, 2); curCY = ySpace(1, 2); first = true; cSPEED_Y = 0; ballOffScreen = false; break; case 2: termContext(); break; } } cout << choiceLoss << "(4); "; spacePress = true; } drawPlayer(PLAYER1); drawPlayer(PLAYER2); drawCircle(curCX, curCY, R); drawWalls(false); if (curCX > SCREEN_X || curCX < 0) { ballOffScreen = true; } } if (!getKey('W') && wPress) { wPress = false; } if (!getKey('A') && aPress) { aPress = false; } if (!getKey('S') && sPress) { sPress = false; } if (!getKey('D') && dPress) { dPress = false; } if (!getKey(' ') && spacePress) { spacePress = false; } cout << endl; } }
//Build a tower void aih_PT() { bool frst = false; bool built = false; int rand; int variate = std::rand() % 3; bool ud = std::rand() % 2; rand = std::rand(); rand %= towersh; if (ud) { for (int a = 0; a < gridY; a++) { for (int b = 0; b < gridX; b++) { int y = a; int x = b; if (built) { a = gridY, b = gridX; } if (aih_bg[a][b] == 2 || aih_bg[a][b] == 0) { if (rand < towersh / 2.5 && !built) { int variate = std::rand() % 3; spawnBuild(b_HumanTower, xSpace(buildGrid[y][x] * 10 + 5 + variate), ySpace((buildGrid[y + 1][x] + y + 3 - x) * 10 - 5 - variate)); built = true; p_Player.addMoney(-b_HumanTower.getCost()); } else { rand = std::rand(); rand %= towersh; } } } } } else { variate *= -1; for (int a = gridY - 1; a > 0; a--) { for (int b = gridX - 1; b > 0; b--) { int y = a; int x = b; if (built) { a = 0, b = 0; } if (aih_bg[a][b] == 2 || aih_bg[a][b] == 0) { if (rand < towersh / 4 && !built) { spawnBuild(b_HumanTower, xSpace(buildGrid[y][x] * 10 + 5 + variate), ySpace((buildGrid[y + 1][x] + y + 3 - x) * 10 - 5 - variate)); built = true; p_Player.addMoney(-b_HumanTower.getCost()); } else { rand = std::rand(); rand %= towersh; } } } } } }