#include <cmath>

#include "SimCalorimetry/EcalSimAlgos/interface/EBShape.h"

void EBShape::fillShape(float& time_interval,
                        double& m_thresh,
                        EcalShapeBase::DVec& aVec,
                        const edm::EventSetup* es) const {
  if (m_useDBShape) {
    if (es == nullptr) {
      throw cms::Exception("EcalShapeBase:: DB conditions are not available, const edm::EventSetup* es == nullptr ");
    }
    auto const& esps = es->getData(espsToken_);

    aVec = esps.barrel_shape;
    time_interval = esps.time_interval;
    m_thresh = esps.barrel_thresh;

  } else  // use old hardcoded arrays
  {
    m_thresh = 0.00013;
    time_interval = 1.0;
    aVec.reserve(500);
    aVec = {
        6.94068e-05,  -5.03304e-05, -2.13404e-05, 6.017e-05,    2.01697e-05,  0.000114845,  2.13998e-05,  2.74476e-05,
        5.2824e-05,   8.754e-05,    2.95346e-06,  -7.58699e-05, -2.72224e-05, 3.10997e-06,  -3.97771e-05, -1.06916e-05,
        -0.000113865, 6.05044e-05,  -5.81202e-05, -6.58974e-06, 5.37494e-05,  -0.000123729, 7.50938e-06,  -1.35628e-05,
        8.33725e-05,  3.19299e-05,  -3.09232e-05, -7.0086e-05,  1.78937e-06,  -2.20365e-05, 7.68054e-05,  -2.5368e-05,
        5.67291e-06,  5.87096e-05,  -2.62771e-06, 4.31832e-05,  8.33616e-06,  7.27813e-05,  7.6159e-05,   -1.60446e-05,
        -4.12127e-06, -5.93381e-05, 1.61444e-05,  -5.49559e-05, 5.55254e-05,  3.32251e-05,  -3.15897e-05, 7.86588e-05,
        -2.9704e-05,  5.66838e-05,  2.85281e-05,  -3.02436e-05, -4.16265e-05, -1.63191e-05, 6.61193e-05,  9.23766e-05,
        6.68903e-05,  -3.20994e-05, 0.00011082,   -4.07997e-05, -8.29046e-06, -7.42197e-05, -1.64386e-05, 1.02508e-05,
        7.10995e-06,  -5.87486e-05, -0.000101201, 1.62003e-05,  -2.53093e-05, 2.65239e-05,  -2.68722e-05, -4.02001e-05,
        5.0674e-05,   -1.75884e-05, 4.7902e-05,   -1.01079e-05, 1.08427e-05,  -0.000112906, 3.33076e-05,  0.000181201,
        0.000426875,  0.00114222,   0.00237804,   0.00541858,   0.0089021,    0.0149157,    0.0231397,    0.0344671,
        0.0471013,    0.0625517,    0.0857351,    0.108561,     0.133481,     0.163557,     0.200243,     0.225919,
        0.269213,     0.302929,     0.342722,     0.378522,     0.436563,     0.467581,     0.510133,     0.550063,
        0.583509,     0.619187,     0.653245,     0.686101,     0.721178,     0.745129,     0.774163,     0.799011,
        0.822177,     0.838315,     0.858847,     0.875559,     0.891294,     0.90537,      0.919617,     0.930632,
        0.936216,     0.947739,     0.955306,     0.961876,     0.968124,     0.97327,      0.977513,     0.984885,
        0.986497,     0.990039,     0.994798,     0.994884,     0.99795,      0.99834,      0.999607,     1,
        0.999047,     0.998745,     0.999219,     0.99814,      0.995082,     0.992449,     0.990418,     0.985032,
        0.982308,     0.978696,     0.975656,     0.971027,     0.964811,     0.959428,     0.95096,      0.947428,
        0.9419,       0.933223,     0.926482,     0.922172,     0.912777,     0.907388,     0.897289,     0.891889,
        0.882056,     0.873382,     0.865442,     0.860032,     0.85202,      0.841013,     0.833802,     0.825259,
        0.815013,     0.807465,     0.799428,     0.792165,     0.783088,     0.773392,     0.764982,     0.752174,
        0.746487,     0.737678,     0.727396,     0.718692,     0.712737,     0.702738,     0.69559,      0.684389,
        0.677989,     0.667643,     0.659009,     0.650217,     0.644479,     0.636017,     0.625257,     0.618507,
        0.609798,     0.600097,     0.592788,     0.584895,     0.578228,     0.569299,     0.560576,     0.552404,
        0.541405,     0.536271,     0.528734,     0.519813,     0.512264,     0.507001,     0.49828,      0.492416,
        0.483181,     0.477907,     0.469623,     0.462528,     0.455099,     0.45055,      0.443576,     0.435364,
        0.429789,     0.422724,     0.415621,     0.409469,     0.40401,      0.398121,     0.391079,     0.384414,
        0.378214,     0.369851,     0.365966,     0.359865,     0.353505,     0.347899,     0.343829,     0.337585,
        0.333089,     0.326289,     0.322249,     0.316079,     0.31061,      0.305426,     0.301885,     0.296753,
        0.290931,     0.286877,     0.281831,     0.276633,     0.272283,     0.268069,     0.26399,      0.258457,
        0.253549,     0.249493};

    for (unsigned int i(250); i != 500; ++i)
      aVec.push_back(exp(2.39735 - 0.0151053 * ((double)i + 1.0)));
  }
}
