예제 #1
0
파일: root.cpp 프로젝트: dnowatsc/rootana
std::unique_ptr<TH1D> spectrum_to_roothist(const Spectrum & s, const std::string & hname, bool set_errors){
    const int n = s.dim();
    unique_ptr<TH1D> values(new TH1D(hname.c_str(), hname.c_str(), n, 0, n));
    for(int i=0; i<n; ++i){
        values->SetBinContent(i+1, s[i]);
        if(set_errors){
            double err = sqrt(s.cov()(i,i));
            values->SetBinError(i+1, err);
        }
    }
    return move(values);
}
예제 #2
0
Spectrum operator*(const Matrix & R, const Spectrum & t){
    const size_t ngen = R.get_n_cols();
    const size_t nrec = R.get_n_rows();
    Spectrum result(nrec);
    if(t.dim() != ngen){
        throw runtime_error("response * gen: wrong dimensions");
    }
    for(size_t i=0; i<nrec; ++i){
        for(size_t j=0; j<ngen; ++j){
            result[i] += R(i,j) * t[j];
        }
    }
    return result;
}
예제 #3
0
파일: stat.cpp 프로젝트: dnowatsc/rootana
void MeanCov::update(const Spectrum & d, size_t weight){
    assert(d.dim() == npar);
    double factor = count * 1.0 / (count + 1);
    for(size_t i=1; i<weight; ++i){
        factor += (count*count*1.0) / ((count+i) * (count+i+1));
    }
    for(size_t i=0; i<npar; ++i){
        if(!isfinite(d[i])){
            throw runtime_error("MeanCov::update: Spectrum has non-finite entries");
        }
        double diff_i = d[i] - means_[i];
        for(size_t j=i; j<npar; ++j){
            double diff_j = d[j] - means_[j];
            count_covariance(i,j) += factor * diff_i * diff_j;
        }
        //the old means[i] is now no longer needed, as j>=i ...
        means_[i] += weight * 1.0 / (count + weight) * diff_i;
    }
    count += weight;
}