Example #1
0
/**
 * returns the modified spherical Bessel function of the second kind needed
 * for bound states.
 \param l = order of the function (orbital angular momentum)
 \param rho = independent variable (rho = k * r)
 */
double sphericalB::k(int l, double rho)
{
  switch (l)
    {
    case 0:
      return k0(rho);
    case 1:
      return k1(rho);
    case 2: 
      return k2(rho);
    case 3: 
      return k3(rho);
    case 4:
      return k4(rho);
    case 5:
      return k5(rho);
    case 6:
      return k6(rho);
    case 7:
      return k7(rho);
    default:
      cout << "no l>6 programed in sphericalB" << endl;
      return 0.;
    }
}
void locDynOneEqEddy::correct(const tmp<volTensorField>& gradU)
{
    LESModel::correct(gradU);

    volSymmTensorField D = symm(gradU);

    volScalarField KK = 0.5*(filter_(magSqr(U())) - magSqr(filter_(U())));
    KK.max(dimensionedScalar("small", KK.dimensions(), SMALL));

    volScalarField P = 2.0*nuSgs_*magSqr(D);

    fvScalarMatrix kEqn
    (
       fvm::ddt(k_)
     + fvm::div(phi(), k_)
     - fvm::laplacian(DkEff(), k_)
    ==
       P
     - fvm::Sp(ce(D, KK)*sqrt(k_)/delta(), k_)
    );

    kEqn.relax();
    kEqn.solve();

    bound(k_, k0());

    updateSubGridScaleFields(D, KK);
}
double TransformErrFunction::evaluateReprojErrInt()
{
    double reprojErr = 0;
    for(TransformSet::const_iterator ppTrans = transformSet_->begin(); ppTrans != transformSet_->end(); ppTrans++)
    {
        int j = ppTrans->first.im1Id();
        int k = ppTrans->first.im2Id();

        if(j != alignTo_ && k != alignTo_ && (j > minIdToRefine_ || k > minIdToRefine_))
        {
            IdPair j0(j, alignTo_);
            IdPair k0(k, alignTo_);
            const Transform * Tj0 = (*transformSet_)[j0]->transform();
            const Transform * Tk0 = (*transformSet_)[k0]->transform();

            const Transform * Tjk = ppTrans->second->transform();
            int inlierCount = ppTrans->second->correspondences().size();

            Transform * Tj0_from_jk = Tk0->accumulate(Tjk);
            reprojErr += getErr(Tj0, Tj0_from_jk, inlierCount);
            delete Tj0_from_jk;
        }
        /*else if(j != alignTo_ ) //Here ppTrans->first.second == alignTo_. Don't calc reproj err for identity!
        {
            const Transform * Tj0 = ppTrans->second->transform();
            reprojErr += getErr(Tj0);

        }*/
    }
    return reprojErr * scaleCost_; //scaleCost_ makes errors initially about 1
}
Example #4
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    mexPrintf("start calculating kappa0");
//declare variables
    mxArray *S_in_m, *U_in_m, *Res_out_m;
    const mwSize *dims;
    double *S, *U, *Res;
    int dimx, dimy, numdims;
    int i,j;

//associate inputs
    S_in_m = mxDuplicateArray(prhs[0]);
    U_in_m = mxDuplicateArray(prhs[1]);

//figure out dimensions
    dims = mxGetDimensions(prhs[0]);
    numdims = mxGetNumberOfDimensions(prhs[0]);
    dimy = (int)dims[0]; dimx = (int)dims[1];

//associate outputs
    Res_out_m = plhs[0] = mxCreateDoubleMatrix(dimy,dimx,mxREAL);
    
//associate pointers
    S = mxGetPr(S_in_m);
    U = mxGetPr(U_in_m);
    Res = mxGetPr(Res_out_m);
    kappa0 k0;
    double diagValue = k0(0.01,0.01);
    for(i=0;i<dimx;i++)
    {
        for(j=i;j<dimy;j++)
        {
            if( i == j ) 
                Res[i*dimy+j] = diagValue;
            else
                Res[i*dimy+j] = k0(S[i*dimy+j],U[i*dimy+j]); 
        }
        
        for(j=0;j<i;j++)
        {
            Res[i*dimy+j] = Res[j*dimy+i]; 
        }
    }
    mexPrintf("\nend calculating kappa0 \n");
    return;
}
Example #5
0
void KisNodeDelegate::drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    QPen oldPen = p->pen();
    p->setPen(scm.gridColor(option, d->view));

    const QPoint base = option.rect.topLeft();

    QPoint p2 = base + QPoint(-scm.indentation() - 1, 0);
    QPoint p3 = base + QPoint(-2 * scm.border() - 2 * scm.decorationMargin() - scm.decorationSize(), 0);
    QPoint p4 = base + QPoint(-1, 0);
    QPoint p5(iconsRect(option,
                           index).left() - 1, base.y());
    QPoint p6(option.rect.right(), base.y());

    QPoint v(0, option.rect.height());

    const bool paintForParent =
        index.parent().isValid() &&
        !index.row();

    if (paintForParent) {
        QPoint p1(-2 * scm.indentation() - 1, 0);
        p1 += base;
        p->drawLine(p1, p2);
    }


    QPoint k0(0, base.y());
    QPoint k1(1 * scm.border() + 2 * scm.visibilityMargin() + scm.visibilitySize(), base.y());
    p->drawLine(k0, k1);
    p->drawLine(k0 + v, k1 + v);
    p->drawLine(k0, k0 + v);
    p->drawLine(k1, k1 + v);

    p->drawLine(p2, p6);
    p->drawLine(p2 + v, p6 + v);
    p->drawLine(p2, p2 + v);
    p->drawLine(p3, p3 + v);
    p->drawLine(p4, p4 + v);
    p->drawLine(p5, p5 + v);
    p->drawLine(p6, p6 + v);

    //// For debugging purposes only
    //p->setPen(Qt::blue);
    //KritaUtils::renderExactRect(p, iconsRect(option, index));
    //KritaUtils::renderExactRect(p, textRect(option, index));
    //KritaUtils::renderExactRect(p, scm.relThumbnailRect().translated(option.rect.topLeft()));

    p->setPen(oldPen);
}
Example #6
0
void lengthcalc(Mat_DP origins, Segment *segchain[]) {

	Vec_DP k0(3), k1(3), k2(3), k3(3);

	for (int i=0; i<3; i++) {
		k0[i]=origins[0][i];
		k1[i]=origins[1][i];
		k2[i]=origins[2][i];
		k3[i]=origins[3][i];
	}

	segchain[0]->length=KINEMATICS::distpnts(k0,k1);
	segchain[1]->length=KINEMATICS::distpnts(k1,k2);
	segchain[2]->length=KINEMATICS::distpnts(k2,k3);

	return;
}
void oneEqEddy::correct(const tmp<volTensorField>& gradU)
{
    GenEddyVisc::correct(gradU);

    volScalarField G = 2.0*nuSgs_*magSqr(symm(gradU));

    solve
    (
       fvm::ddt(k_)
     + fvm::div(phi(), k_)
     - fvm::laplacian(DkEff(), k_)
    ==
       G
     - fvm::Sp(ce_*sqrt(k_)/delta(), k_)
    );

    bound(k_, k0());

    nuSgs_ = ck_*sqrt(k_)*delta();
    nuSgs_.correctBoundaryConditions();
}
void lowReOneEqEddy::correct(const tmp<volTensorField>& tgradU)
{
    const volTensorField& gradU = tgradU();

    GenEddyVisc::correct(gradU);

    volScalarField divU = fvc::div(phi()/fvc::interpolate(rho()));
    volScalarField G = 2*muSgs_*(gradU && dev(symm(gradU)));

    solve
    (
        fvm::ddt(rho(), k_)
      + fvm::div(phi(), k_)
      - fvm::laplacian(DkEff(), k_)
     ==
        G
      - fvm::SuSp(2.0/3.0*rho()*divU, k_)
      - fvm::Sp(ce_*rho()*sqrt(k_)/delta(), k_)
    );

    bound(k_, k0());

    updateSubGridScaleFields();
}
int main(int argc, char *argv[])
{
    argList::addNote
    (
        "apply a simplified boundary-layer model to the velocity and\n"
        "turbulence fields based on the 1/7th power-law."
    );

    argList::addOption
    (
        "ybl",
        "scalar",
        "specify the boundary-layer thickness"
    );
    argList::addOption
    (
        "Cbl",
        "scalar",
        "boundary-layer thickness as Cbl * mean distance to wall"
    );
    argList::addBoolOption
    (
        "writenut",
        "write nut field"
    );

    #include "setRootCase.H"

    if (!args.optionFound("ybl") && !args.optionFound("Cbl"))
    {
        FatalErrorIn(args.executable())
            << "Neither option 'ybl' or 'Cbl' have been provided to calculate "
            << "the boundary-layer thickness.\n"
            << "Please choose either 'ybl' OR 'Cbl'."
            << exit(FatalError);
    }
    else if (args.optionFound("ybl") && args.optionFound("Cbl"))
    {
        FatalErrorIn(args.executable())
            << "Both 'ybl' and 'Cbl' have been provided to calculate "
            << "the boundary-layer thickness.\n"
            << "Please choose either 'ybl' OR 'Cbl'."
            << exit(FatalError);
    }

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    // Modify velocity by applying a 1/7th power law boundary-layer
    // u/U0 = (y/ybl)^(1/7)
    // assumes U0 is the same as the current cell velocity

    Info<< "Setting boundary layer velocity" << nl << endl;
    scalar yblv = ybl.value();
    forAll(U, cellI)
    {
        if (y[cellI] <= yblv)
        {
            mask[cellI] = 1;
            U[cellI] *= ::pow(y[cellI]/yblv, (1.0/7.0));
        }
    }
    mask.correctBoundaryConditions();

    Info<< "Writing U\n" << endl;
    U.write();

    // Update/re-write phi
    #include "createPhi.H"
    phi.write();

    singlePhaseTransportModel laminarTransport(U, phi);

    autoPtr<incompressible::turbulenceModel> turbulence
    (
        incompressible::turbulenceModel::New(U, phi, laminarTransport)
    );

    if (isA<incompressible::RASModel>(turbulence()))
    {
        // Calculate nut - reference nut is calculated by the turbulence model
        // on its construction
        tmp<volScalarField> tnut = turbulence->nut();
        volScalarField& nut = tnut();
        volScalarField S(mag(dev(symm(fvc::grad(U)))));
        nut = (1 - mask)*nut + mask*sqr(kappa*min(y, ybl))*::sqrt(2)*S;

        // do not correct BC - wall functions will 'undo' manipulation above
        // by using nut from turbulence model

        if (args.optionFound("writenut"))
        {
            Info<< "Writing nut" << endl;
            nut.write();
        }


        //--- Read and modify turbulence fields

        // Turbulence k
        tmp<volScalarField> tk = turbulence->k();
        volScalarField& k = tk();
        scalar ck0 = pow025(Cmu)*kappa;
        k = (1 - mask)*k + mask*sqr(nut/(ck0*min(y, ybl)));

        // do not correct BC - operation may use inconsistent fields wrt these
        // local manipulations
        // k.correctBoundaryConditions();

        Info<< "Writing k\n" << endl;
        k.write();


        // Turbulence epsilon
        tmp<volScalarField> tepsilon = turbulence->epsilon();
        volScalarField& epsilon = tepsilon();
        scalar ce0 = ::pow(Cmu, 0.75)/kappa;
        epsilon = (1 - mask)*epsilon + mask*ce0*k*sqrt(k)/min(y, ybl);

        // do not correct BC - wall functions will use non-updated k from
        // turbulence model
        // epsilon.correctBoundaryConditions();

        Info<< "Writing epsilon\n" << endl;
        epsilon.write();

        // Turbulence omega
        IOobject omegaHeader
        (
            "omega",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE,
            false
        );

        if (omegaHeader.headerOk())
        {
            volScalarField omega(omegaHeader, mesh);
            dimensionedScalar k0("VSMALL", k.dimensions(), VSMALL);
            omega = (1 - mask)*omega + mask*epsilon/(Cmu*k + k0);

            // do not correct BC - wall functions will use non-updated k from
            // turbulence model
            // omega.correctBoundaryConditions();

            Info<< "Writing omega\n" << endl;
            omega.write();
        }

        // Turbulence nuTilda
        IOobject nuTildaHeader
        (
            "nuTilda",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE,
            false
        );

        if (nuTildaHeader.headerOk())
        {
            volScalarField nuTilda(nuTildaHeader, mesh);
            nuTilda = nut;

            // do not correct BC
            // nuTilda.correctBoundaryConditions();

            Info<< "Writing nuTilda\n" << endl;
            nuTilda.write();
        }
    }

    Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
        << "  ClockTime = " << runTime.elapsedClockTime() << " s"
        << nl << endl;

    Info<< "End\n" << endl;

    return 0;
}
Example #10
0
qreal KMath::pr(qreal A)
{
    //srs-19 page 177
    qreal prx = ((qExp(A) * k0(A))/(0.142*M_PI));
    return qMax(prx, 1.0);
}
Example #11
0
qreal KMath::pe(qreal A, qreal N)
{
    qreal pex = (qExp(A) * k0(A)) / (0.32 * M_PI * qSqrt(N));
    return qMax(pex, 1.0);
}
Example #12
0
    void DrrnPsiClient::recv(Channel s0, Channel s1, span<block> inputs)
    {
        if (inputs.size() != mClientSetSize)
            throw std::runtime_error(LOCATION);

        Matrix<u64> bins(mNumSimpleBins, mBinSize);
        std::vector<u64> binSizes(mNumSimpleBins);
        u64 cuckooSlotsPerBin = (mCuckooParams.numBins() + mNumSimpleBins) / mNumSimpleBins;

        // Simple hashing with a PRP
        std::vector<block> hashs(inputs.size());
        AES hasher(mHashingSeed);
        u64 numCuckooBins = mCuckooParams.numBins();
        for (u64 i = 0; i < u64(inputs.size());)
        {
            auto min = std::min<u64>(inputs.size() - i, 8);
            auto end = i + min;
            hasher.ecbEncBlocks(inputs.data() + i, min, hashs.data() + i);
            for (; i < end; ++i)
            {
                hashs[i] = hashs[i] ^ inputs[i];
                for (u64 j = 0; j < mCuckooParams.mNumHashes; ++j)
                {
                    u64 idx = CuckooIndex<>::getHash(hashs[i], j, numCuckooBins) * mNumSimpleBins / mCuckooParams.numBins();

                    // insert this item in this bin. pack together the hash index and input index
                    bins(idx, binSizes[idx]++) = (j << 56) | i;
                }

                //if (!i)
                //{
                //    ostreamLock(std::cout) << "cinput[" << i << "] = " << inputs[i] << " -> " << hashs[i] << " ("
                //        << CuckooIndex<>::getHash(hashs[i], 0, numCuckooBins) << ", "
                //        << CuckooIndex<>::getHash(hashs[i], 1, numCuckooBins) << ", "
                //        << CuckooIndex<>::getHash(hashs[i], 2, numCuckooBins) << ")"
                //        << std::endl;
                //}
            }
        }



        // power of 2
        u64 numLeafBlocks = (cuckooSlotsPerBin + mBigBlockSize * 128 - 1) / (mBigBlockSize * 128);
        u64 gDepth = 2;
        u64 kDepth = std::max<u64>(gDepth, log2floor(numLeafBlocks)) - gDepth;
        u64 groupSize = (numLeafBlocks + (u64(1) << kDepth) - 1) / (u64(1) << kDepth);
        if (groupSize > 8) throw std::runtime_error(LOCATION);

        //std::cout << "kDepth:   " << kDepth << std::endl;
        //std::cout << "mBinSize: " << mBinSize << std::endl;

        u64 numQueries = mNumSimpleBins * mBinSize;
        auto permSize = numQueries * mBigBlockSize;

        // mask generation
        block rSeed = CCBlock;// mPrng.get<block>();
        AES rGen(rSeed);


        std::vector<block> shares(mClientSetSize * mCuckooParams.mNumHashes), r(permSize), piS1(permSize), s(permSize);
        //std::vector<u32> rIdxs(numQueries);
        //std::vector<u64> sharesIdx(shares.size());

        //TODO("use real masks");
        //memset(r.data(), 0, r.size() * sizeof(block));
        rGen.ecbEncCounterMode(r.size() * 0, r.size(), r.data());
        rGen.ecbEncCounterMode(r.size() * 1, r.size(), piS1.data());
        rGen.ecbEncCounterMode(r.size() * 2, r.size(), s.data());

        //auto encIter = enc.begin();
        auto shareIter = shares.begin();
        //auto shareIdxIter = sharesIdx.begin();
        u64 queryIdx = 0, dummyPermIdx = mClientSetSize * mCuckooParams.mNumHashes;

        std::unordered_map<u64, u64> inputMap;
        inputMap.reserve(mClientSetSize * mCuckooParams.mNumHashes);

        std::vector<u32> pi(permSize);
        auto piIter = pi.begin();


        u64 keySize = kDepth + 1 + groupSize;
        u64 mask = (u64(1) << 56) - 1;
        auto binIter = bins.begin();
        for (u64 bIdx = 0; bIdx < mNumSimpleBins; ++bIdx)
        {
            u64 i = 0;

            auto binOffset = (bIdx * numCuckooBins + mNumSimpleBins - 1) / mNumSimpleBins;

            std::vector<block> k0(keySize * mBinSize), k1(keySize * mBinSize);
            //std::vector<u64> idx0(mBinSize), idx1(mBinSize);
            auto k0Iter = k0.data(), k1Iter = k1.data();
            //auto idx0Iter = idx0.data(), idx1Iter = idx1.data();

            for (; i < binSizes[bIdx]; ++i)
            {
                span<block>
                    kk0(k0Iter, kDepth + 1),
                    g0(k0Iter + kDepth + 1, groupSize),
                    kk1(k1Iter, kDepth + 1),
                    g1(k1Iter + kDepth + 1, groupSize);

                k0Iter += keySize;
                k1Iter += keySize;

                u8 hashIdx = *binIter >> 56;
                u64 itemIdx = *binIter & mask;
                u64 cuckooIdx = CuckooIndex<>::getHash(hashs[itemIdx], hashIdx, numCuckooBins) - binOffset;
                ++binIter;

                auto bigBlockoffset = cuckooIdx % mBigBlockSize;
                auto bigBlockIdx = cuckooIdx / mBigBlockSize;

                BgiPirClient::keyGen(bigBlockIdx, mPrng.get<block>(), kk0, g0, kk1, g1);



                // the index of the mask that will mask this item
                auto rIdx = *piIter = itemIdx * mCuckooParams.mNumHashes + hashIdx * mBigBlockSize + bigBlockoffset;

                // the masked value that will be inputted into the PSI
                *shareIter = r[rIdx] ^ inputs[itemIdx];
                //*shareIter = inputs[itemIdx];

                //if (itemIdx == 0)
                //    ostreamLock(std::cout)
                //    << "item[" << i << "]    bin " << bIdx
                //    << " block " << bigBlockIdx 
                //    << " offset " << bigBlockoffset 
                //    << " psi " << *shareIter << std::endl;

                // This will be used to map itemed items in the intersection back to their input item
                inputMap.insert({ queryIdx, itemIdx });

                ++shareIter;
                ++piIter;
                ++queryIdx;
            }

            u64 rem = mBinSize - i;


            binIter += rem;
            for (u64 i = 0; i < rem; ++i)
            {
                *piIter++ = dummyPermIdx++;
            }

            //s0.asyncSendCopy(k0);
            //s0.asyncSendCopy(k1);
            //s1.asyncSendCopy(k1);
            //s1.asyncSendCopy(k0);

            s0.asyncSend(std::move(k0));
            s1.asyncSend(std::move(k1));

        }

        std::vector<u32> pi1(permSize), pi0(permSize), pi1Inv(permSize);
        for (u32 i = 0; i < pi1.size(); ++i) pi1[i] = i;
        PRNG prng(rSeed ^ OneBlock);
        std::random_shuffle(pi1.begin(), pi1.end(), prng);


        //std::vector<block> pi1RS(pi.size());
        for (u64 i = 0; i < permSize; ++i)
        {
            //auto pi1i = pi1[i];
            //pi1RS[i] = r[pi1i] ^ s[pi1i];

            pi1Inv[pi1[i]] = i;
            //std::cout << "pi1(r + s)[" << i << "] " << pi1RS[i] << std::endl;
        }
        std::vector<block> piS0(r.size());
        for (u64 i = 0; i < permSize; ++i)
        {
            //std::cout << "r[" << i << "] " << r[i] << std::endl;
            //std::cout << "pi(r + s)[" << i << "]=" << (r[pi[i]] ^ s[pi[i]]) << std::endl;


            pi0[i] = pi1Inv[pi[i]];
            piS0[i] = piS1[i] ^ s[pi[i]];
            //std::cout << "pi (r + s)[" << i << "] = " << (r[pi[i]] ^ s[pi[i]]) << " = " << r[pi[i]] << " ^ " << s[pi[i]] << " c " << pi[i] << std::endl;
            //std::cout << "pi`(r + s)[" << i << "] = " << pi1RS[pi0[i]]  <<" c " << pi0[pi1[i]] << std::endl;
        }

        s0.asyncSend(std::move(pi0));
        s0.asyncSend(std::move(piS0));
        //rGen.ecbEncBlocks(r.data(), r.size(), r.data());
        //for (u64 i = 0; i < shares.size(); ++i)
        //{
        //    std::cout << IoStream::lock << "cshares[" << i << "] " << shares[i] << " input[" << sharesIdx[i]<<"]" << std::endl << IoStream::unlock;
        //}
        mPsi.sendInput(shares, s0);

        mIntersection.reserve(mPsi.mIntersection.size());
        for (u64 i = 0; i < mPsi.mIntersection.size(); ++i) {
            // divide index by #hashes
            mIntersection.emplace(inputMap[mPsi.mIntersection[i]]);
        }

    }
int main( int argc, const char *argv[] )
{

	////////////////////////
	// 					  //
	// -- Initializing -- //
	// 				      //
	////////////////////////
	

	int nEvents = 3;

	// Event parameters
	int nParticles = 2;

	// Auxiliary vector(s)
	TLorentzVector k0 (1.0, 0.0, 0.0, 1.0);

	// Fortran COMMON blocks
	masses_.rmtau             = m_tau;
	couplings_.wcl            = 1.0;
	couplings_.gh_tautau      = 1.0;
	amplitudes_.rh_6f_tautau  = 0.0;
	amplitudes_.rh_6f_taum    = 0.0;
	amplitudes_.rh_6f_taup    = 0.0;
	amplitudes_.rh_6f_res     = 0.0;
	amplitudes_.rh_6f_res_nwa = 0.0;

	// Ampltiudes
	//cval cdec_taum[2][2];
	CMatrix_2_2 cdec_taum;
	CMatrix_2_2 cdec_taup;
	CMatrix_2_2 ch_tautau;

	TauMatrix h_tautau;
	TauMatrix taum;
	TauMatrix taup;
	TauMatrix c7_568;
	h_tautau.SetName("H->tau- tau+");
	taum.SetName("taum");
	taup.SetName("taup");
	c7_568.SetName("c7_568");

	////////////////////////////////////////////////////
	// -- Generate HiggsDecays with TGenPhaseSpace -- //
	////////////////////////////////////////////////////
	
	TGenPhaseSpace HiggsDecay;
	TLorentzVector Higgs(0.0, 0.0, 0.0, m_higgs);
	
	double TauMasses[2] = {m_tau, m_tau};
	TGenPhaseSpace p568Decay;
	TGenPhaseSpace p734Decay;

	double LeptonMasses1[3] = {m_nu_tau, m_ele, m_nu_ele};
	double LeptonMasses2[3] = {m_nu_tau, m_muo, m_nu_muo};

	HiggsDecay.SetDecay(Higgs, 2, TauMasses);
	
	TH2F *h2 = new TH2F("h2","h2", 50,1.1,1.8, 50,1.1,1.8);

	double p1_[4];
	double p2_[4];
	double p3_[4];
	double p4_[4];
	double p5_[4];
	double p6_[4];
	double p7_[4];
	double p8_[4];

	std::cout << "\n\n#########################" << std::endl;
	std::cout << "### Consistency check ###" << std::endl;
	std::cout << "#########################\n" << std::endl;

	std::cout << "Process:" << std::endl;
	std::cout << "H -->  (tau+) (tau-) --> (3 leptons) (3 leptons)\n" << std::endl;

	std::cout << Form("m_higgs (used in phase space gen): %8.4f [GeV]", m_higgs) << std::endl;
	std::cout << Form("masses_.rmtau (used in rh_6f):     %8.4f [GeV]", masses_.rmtau) << std::endl;
	std::cout << Form("m_tau (used in phase space gen):   %8.4f [GeV]", m_tau) << std::endl;
	std::cout << Form("m_ele (used in phase space gen):   %8.4f [GeV]", m_ele) << std::endl;
	std::cout << Form("m_muo (used in phase space gen):   %8.4f [GeV]", m_muo) << std::endl;
	std::cout << Form("and all neutrinos are massless") << std::endl;
	
	for (int iEv = 0; iEv < nEvents; iEv++)
	{

		std::cout << Form("\n################\n### iEv: %3d ###\n################", iEv) << std::endl;

		// Higgs Decay
	   Double_t weight = HiggsDecay.Generate();

		std::cout << "weight: " << weight << std::endl;

		// Get tau+ and tau-
	   TLorentzVector *p734 = HiggsDecay.GetDecay(1);
	   TLorentzVector *p568 = HiggsDecay.GetDecay(0);

		TVector3 p734_BoostVector = p734->BoostVector();
		TVector3 p568_BoostVector = p568->BoostVector();

		// Make taus decay
		p734Decay.SetDecay( (*p734), 3, LeptonMasses1 );
		p568Decay.SetDecay( (*p568), 3, LeptonMasses2 );

	   Double_t weight1 = p568Decay.Generate();
	   Double_t weight2 = p734Decay.Generate();

		std::cout << "weight1: " << weight1 << std::endl;
		std::cout << "weight2: " << weight2 << std::endl;

	   TLorentzVector *p7 = p734Decay.GetDecay(0); // v_tau
	   TLorentzVector *p3 = p734Decay.GetDecay(1); // ele-
	   TLorentzVector *p4 = p734Decay.GetDecay(2); // v_ele_bar
	   TLorentzVector *p8 = p568Decay.GetDecay(0); // v_tau_bar
	   TLorentzVector *p6 = p568Decay.GetDecay(1); // mu+
	   TLorentzVector *p5 = p568Decay.GetDecay(2); // v_muo
 
 		double p568k0 = k0 * (*p568);
 		double p734k0 = k0 * (*p734);
 		double p3k0 = k0 * (*p3);
 		double p4k0 = k0 * (*p4); 
 		double p5k0 = k0 * (*p5);
 		double p6k0 = k0 * (*p6);
		double p7k0 = k0 * (*p7);
		double p8k0 = k0 * (*p8);

	   TLorentzVector *sum = new TLorentzVector;
		(*sum) = (*p8) + (*p6) + (*p5) + (*p7) + (*p3) + (*p4);

		std::cout << "\n# --- Generated momenta --- #\n";
		std::cout << "- sum: "; displayTLorentzVector(sum);
		std::cout << "- p734 "; displayTLorentzVector(p734);
		std::cout << "- p568 "; displayTLorentzVector(p568);
		std::cout << "- p7   (v_tau )"; displayTLorentzVector(p7);
		std::cout << "- p3       (e-)"; displayTLorentzVector(p3);
		std::cout << "- p4   (v_ebar)"; displayTLorentzVector(p4);
		std::cout << "- p8 (v_taubar)"; displayTLorentzVector(p8);
		std::cout << "- p6    (muon+)"; displayTLorentzVector(p6);
		std::cout << "- p5     (v_mu)"; displayTLorentzVector(p5);


		// -- Unpolarized term -- //
		double taum_amp = p734->Dot((*p4)) * p3->Dot((*p7));
		double taup_amp = p568->Dot((*p5)) * p6->Dot((*p8));

		// -- Polarized term -- //

		// polarization vectors
		TLorentzVector polvec_taum;
		TLorentzVector polvec_taup;

		//  standard polarization vector with p and k0
		for(int nu = 0; nu<4; nu++)
		{
			polvec_taum[nu] = ( (*p734)[nu]/m_tau) - (m_tau/p734k0)*k0[nu];
			polvec_taup[nu] = ( (*p568)[nu]/m_tau) - (m_tau/p568k0)*k0[nu];
		}

		double taum_pol_amp = m_tau*( polvec_taum * (*p4) ) * ( (*p3) * (*p7) ); // (ek')(qk)
		double taup_pol_amp = m_tau*( polvec_taup * (*p5) ) * ( (*p6) * (*p8) ); // (ek')(qk)


		std::cout << Form("\n# --- Standard calculation --- #") << std::endl;
		std::cout << Form("Unpolarized case:") << std::endl;
		std::cout << Form("- tau- (pk')(qk) (unpolarized): %.4f", taum_amp ) << std::endl;
		std::cout << Form("- tau+ (pk')(qk) (unpolarized): %.4f", taup_amp ) << std::endl;
		std::cout << Form("- tau-/tau+ (unpolarized): %.4f", taum_amp/taup_amp ) << std::endl;
		std::cout << Form("Polarized case:") << std::endl;

		std::cout << Form("- tau- m_tau*(ek')(qk) (polarized term): %.4f", taum_pol_amp ) << std::endl;
		std::cout << Form("- tau+ m_tau*(ek')(qk) (polarized term): %.4f", taup_pol_amp ) << std::endl;

		double taum_standard_pol_1 = taum_amp - taum_pol_amp;
		double taum_standard_pol_2 = taum_amp + taum_pol_amp;
		double taup_standard_pol_1 = taup_amp - taup_pol_amp;
		double taup_standard_pol_2 = taup_amp + taup_pol_amp;

		std::cout << Form("- taum_standard_pol_1 ((pk')(qk)-m_tau*(ek')(qk)): %.4f", taum_standard_pol_1) << std::endl;
		std::cout << Form("- taum_standard_pol_2 ((pk')(qk)+m_tau*(ek')(qk)): %.4f", taum_standard_pol_2) << std::endl;
		std::cout << Form("- taup_standard_pol_1 ((pk')(qk)-m_tau*(ek')(qk)): %.4f", taup_standard_pol_1) << std::endl;
		std::cout << Form("- taup_standard_pol_2 ((pk')(qk)+m_tau*(ek')(qk)): %.4f", taup_standard_pol_2) << std::endl;

		for (int i = 0; i < 4; i++)
		{
			p1_[e2m[i]] = (*p568)[i];
			p2_[e2m[i]] = (*p734)[i];
			p3_[e2m[i]] = (*p3)[i];
			p4_[e2m[i]] = (*p4)[i];
			p5_[e2m[i]] = (*p5)[i];
			p6_[e2m[i]] = (*p6)[i];
			p7_[e2m[i]] = (*p7)[i];
			p8_[e2m[i]] = (*p8)[i];
		}

//		double rh_tautau_val = rh_tautau_(p1_,p2_);
//		std::cout << Form("rh_tautau: %.2f\n", rh_tautau_val) << std::endl;

		std::cout << Form("\n# --- Helicity amplitude calculation --- #") << std::endl;
		double rh_6f_val = rh_6f_(p3_,p4_,p5_,p6_,p7_,p8_);

		h_tautau.ReadInCMatrix_2_2( taumatrices_.ch_tautau );
		taum.ReadInCMatrix_2_2(     taumatrices_.cdec_taum );
		taup.ReadInCMatrix_2_2(     taumatrices_.cdec_taup );
		c7_568.ReadInCMatrix_2_2(   taumatrices_.c7_568    );

		h_tautau.Show();
		taum.Show();
		taup.Show();

		double taum_rh_6f_pol_1 = std::abs(taum.m[1][0])*std::abs(taum.m[1][0]);
		double taum_rh_6f_pol_2 = std::abs(taum.m[1][1])*std::abs(taum.m[1][1]);

		double taup_rh_6f_pol_1 = std::abs(taup.m[0][1])*std::abs(taup.m[0][1]);
		double taup_rh_6f_pol_2 = std::abs(taup.m[1][1])*std::abs(taup.m[1][1]);

		taum_rh_6f_pol_1 = taum_rh_6f_pol_1/p3k0/p4k0/p7k0/p734k0;
		taum_rh_6f_pol_2 = taum_rh_6f_pol_2/p3k0/p4k0/p7k0/p734k0;

		taup_rh_6f_pol_1 = taup_rh_6f_pol_1/p5k0/p6k0/p8k0/p568k0;
		taup_rh_6f_pol_2 = taup_rh_6f_pol_2/p5k0/p6k0/p8k0/p568k0;

		taum.ShowSumOfSquares();
		taup.ShowSumOfSquares();
//		for (int i=0; i<2; i++)
//		for (int j=0; j<2; j++)
//		{
//		  std::cout << Form("rh_6f_tau-[%d][%d].r: %.4f \n",i,j,cdec_taum[i][j].r);
//		  std::cout << Form("rh_6f_tau-[%d][%d].i: %.4f \n",i,j,cdec_taum[i][j].i);
//		}
//
//		for (int i=0; i<2; i++)
//		for (int j=0; j<2; j++)
//		{
//		  std::cout << Form("rh_6f_tau+[%d][%d].r: %.4f \n",i,j,cdec_taup[i][j].r);
//		  std::cout << Form("rh_6f_tau+[%d][%d].i: %.4f \n",i,j,cdec_taup[i][j].i);
//		}
		double taum_unpol = taum.CalcSumOfSquares();
		double taup_unpol = taup.CalcSumOfSquares();

		taum_unpol = taum_unpol/p3k0/p4k0/p7k0/p734k0;
		taup_unpol = taup_unpol/p5k0/p6k0/p8k0/p568k0;

		std::cout << Form("- taum_unpolarized (calc via sum of square of tau elements): %.4f", taum_unpol) << std::endl;
		std::cout << Form("- taup_unpolarized (calc via sum of square of tau elements): %.4f", taup_unpol) << std::endl;

		std::cout << Form("- taum_rh_6f_pol_1 (calc via square): %.4f", taum_rh_6f_pol_1) << std::endl;
		std::cout << Form("- taum_rh_6f_pol_2 (calc via square): %.4f", taum_rh_6f_pol_2) << std::endl;
		std::cout << Form("- taup_rh_6f_pol_1 (calc via square): %.4f", taup_rh_6f_pol_1) << std::endl;
		std::cout << Form("- taup_rh_6f_pol_2 (calc via square): %.4f", taup_rh_6f_pol_2) << std::endl;

		std::cout << Form("- (taum_rh_6f_pol_1-taum_rh_6f_pol_2) (calc via square): %.4f", taum_rh_6f_pol_1-taum_rh_6f_pol_2) << std::endl;
		std::cout << Form("- (taup_rh_6f_pol_1-taup_rh_6f_pol_2) (calc via square): %.4f", taup_rh_6f_pol_1-taup_rh_6f_pol_2) << std::endl;


		std::cout << Form("- rh_6f_taum (passed through FORTRAN common): %.4f", amplitudes_.rh_6f_taum) << std::endl;
		std::cout << Form("- rh_6f_taup (passed through FORTRAN common): %.4f", amplitudes_.rh_6f_taup ) << std::endl;
		std::cout << Form("- rh_6f tau-/tau+ (passed through FORTRAN common): %.4f", amplitudes_.rh_6f_taum/amplitudes_.rh_6f_taup	) << std::endl;
		std::cout << Form("- rh_6f_res (passed through FORTRAN common): %.4f", amplitudes_.rh_6f_res ) << std::endl;
		std::cout << Form("- rh_6f_res_nwa (passed through FORTRAN common): %.4f", amplitudes_.rh_6f_res_nwa ) << std::endl;

		std::cout << Form("\n# --- Comparison --- #") << std::endl;
		std::cout << Form("- rh_6f_taum/taum ratio (unpolarized): %.4f", amplitudes_.rh_6f_taum/taum_amp ) << std::endl;
		std::cout << Form("- rh_6f_taup/taup ratio (unpolarized): %.4f", amplitudes_.rh_6f_taup/taup_amp ) << std::endl;

		std::cout << Form("- taum_pol_1 (rh_6f/standard ratio) (polarized): %.4f", taum_rh_6f_pol_1/taum_standard_pol_1 ) << std::endl;
		std::cout << Form("- taum_pol_2 (rh_6f/standard ratio) (polarized): %.4f", taum_rh_6f_pol_2/taum_standard_pol_2 ) << std::endl;
		std::cout << Form("- taup_pol_1 (rh_6f/standard ratio) (polarized): %.4f", taup_rh_6f_pol_1/taup_standard_pol_1 ) << std::endl;
		std::cout << Form("- taup_pol_2 (rh_6f/standard ratio) (polarized): %.4f", taup_rh_6f_pol_2/taup_standard_pol_2 ) << std::endl;


		//std::cout << Form("rh_6f: %.2f", rh_6f_val) << std::endl;
		//	double LeptonMasses1[3] = {m_nu_tau, m_ele, m_nu_ele};
		//	double LeptonMasses2[3] = {m_nu_tau, m_muo, m_nu_muo};
		// H(p) -> e-(p3) vebar(p4) vmu(p5) mu+(p6) vtau(p7) vtaubar(p8)                 
	}

}