Reducing a 4D function into 1D function

ROOT 5.34
gcc version 4.9.2 (Debian 4.9.2-10)

Hello, everyone! I got a problem. I wrote a function with four variables. And I have their integration ranges in the form of two arrays xmin[4] and xmax [4]. I know we can get the finite integration of this function by ROOT::Math::IntegratorMultiDim just like the below codes. However, I want to know is there any way I can eliminate the first three variable by integration and leave the fourth variable unchanged. Thus changing this four-dimention function into one-dimention function and drawing this as a TF1. My simple codes are as belows:

#include "TMath.h"
#include "Math/WrappedFunction.h"
#include "Math/IntegratorMultiDim.h"
#include <iostream>

Double_t func(const Double_t *x){ 
    return x[0]*x[1]*TMath::Exp(x[2]*x[3]);
}

void test5()
{
    // numeric integration
    //ROOT::Math::WrappedMultiFunction<> f1(func,3);
	ROOT::Math::Functor f1(&func,4);
    ROOT::Math::IntegratorMultiDim ig(f1);
	
    Double_t xmin[4] = {0.0,0.0,0.0,0.0};
    Double_t xmax[4] = {2.0,3.0,4.0,4.0};
	
    Double_t result = ig.Integral(xmin, xmax);
	cout<<result<<endl;
}

This code is for definite integration. And I thought about one way to get it’s dimentions reduced like the following code:

#include "TMath.h"
#include "Math/WrappedFunction.h"
#include "Math/IntegratorMultiDim.h"
#include <iostream>

Double_t func(Double_t *x,Double_t *b){ 
    return x[0]*x[1]*TMath::Exp(x[2]*b[0]);
}

void test5()
{
	int nbins=500;
	TF3* f3=new TF3("f3",func,0.,2.,0.,3.,0.,4.,1);
	TH1F* h=new TH1F("h","",nbins,0.,5.);
	for(int i=0;i<nbins;i++){
		double E_tem=h->GetBinCenter(i+1);
		f3->SetParameter(0,E_tem);
		double integral;
		integral=f3->Integral(0.,2.,0.,3.,0.,4.);
		h->SetBinContent(i+1,integral);
	}
	h->Draw();	
}

However, it will need lots of calculation for my real work and cause new problem. So I am wondering is there a simple way in root to get the dimentions reduced. Thanks very much for your attention!

Your function seems to be simple enough that you can write an analytical expression for the integral.

Thanks for your attention ! And actually the function in my real work is more complecated and it needs to be looped for many times. So I want to find a simple way like TF3::Integral() in root . I think there should be something like infinite integration in root, but I can’t find that.
Also, do you have some examples of the analytical expression for integral?

Lists of integrals
Table of Integrals

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.