コード例 #1
0
// a.k.a Tonelli_Shanks algorithm
int ressol(int n, int p) {
	n %= p;
	if (n == 0) return 0;
	if (legendre(n, p) != 1) return -1;
	int q = p - 1, s = 0, z, c;
	while (q % 2 == 0) q /= 2, ++s;
	while (true) {
		z = rand() % (p - 1) + 1;
		if (legendre(z, p) == p - 1) break; 
	}
	c = fpow(z, q, p);
	int r = fpow(n, (q + 1) / 2, p), t = fpow(n, q, p), m = s;
	while (true) {
		if (t == 1) return r;
		for (int i = 0, tmp = t; i < m; ++i, tmp = 1ll * tmp * tmp % p) {
			if (tmp == 1) {
				int b = fpow(c, 1 << (m - i - 1), p);
				c = 1ll * b * b % p;
				r = 1ll * r * b % p;
				t = 1ll * t * c % p;
				m = i;
				break;
			}
		}
	}
	return r;
}
コード例 #2
0
void legendre(int n, double *x, int xsize, double *output)
{
	double temp1[xsize], temp2[xsize];
	int ii;
	if (n == 0)
	{
		for (ii = 0; ii < xsize; ++ii)
		{
			output[ii] = 1.;
		}
	}
	else if (n == 1)
	{
		for (ii = 0; ii < xsize; ++ii)
		{
			output[ii] = x[ii];
		}
	}
	else
	{
		legendre(n - 1, x, xsize, temp1);
		legendre(n - 2, x, xsize, temp2);
		for (ii = 0; ii < xsize; ++ii)
		{
			output[ii] = ((2 * n - 1) * x[ii] * temp1[ii] - (n - 1) * temp2[ii]) / n;
		}
	}
}
コード例 #3
0
double legendre (int n, double x) //n must be greater than or equal to 0
{
  if (n<=0)
    return (long)1;
  else
    return ((2*n+1)/(n+1))*x*legendre((n-1), x) - (n/(n+1))*legendre((n-2), x);
}
コード例 #4
0
float legendre(int n, int x)
{
	if(n == 0)
		return 1;
	if(n == 1)
		return x;

	int m = (2*n-1)*x*legendre(n-1, x) - (n-1)*legendre(n-2, x);

	return m/n;
}
コード例 #5
0
ファイル: poly.c プロジェクト: chrismullins/moab
/* n nodes */
void gauss_nodes(real *z, int n)
{
  int i,j;
  for(i=0; i<=n/2-1; ++i) {
    real ox, x = cosr( (2*n-2*i-1)*(PI/2)/n );
    do {
      ox = x;
      x -= legendre(n,x)/legendre_d1(n,x);
    } while(fabsr(x-ox)>-x*EPS);
    z[i] = x - legendre(n,x)/legendre_d1(n,x);
  }
  if(n&1) z[n/2]=0;
  for(j=(n+1)/2,i=n/2-1; j<n; ++j,--i) z[j]=-z[i];
}
コード例 #6
0
ファイル: Cartesian.C プロジェクト: FHilty/moose
TEST(FunctionalExpansionsTest, legendreSeriesStandardEvaluation)
{
  const unsigned int order = 15;
  Real location = -0.90922108754014;
  const std::array<Real, order> truth = {{0.50000000000000,
                                          -1.36383163131021,
                                          1.85006119760378,
                                          -1.80341832197563,
                                          1.19175581122701,
                                          -0.11669847057321,
                                          -1.20462734483853,
                                          2.48341349094950,
                                          -3.41981864606651,
                                          3.76808851494207,
                                          -3.39261995754146,
                                          2.30300489952095,
                                          -0.66011244776270,
                                          -1.24901920248131,
                                          3.06342136027001}};

  Legendre legendre({FunctionalBasisInterface::_domain_options = "x"},
                    {order},
                    expansion_type = "standard",
                    generation_type = "standard");

  legendre.setLocation(Point(location));
  auto & answer = legendre.getAllGeneration();
  for (std::size_t i = 0; i < order; ++i)
    EXPECT_NEAR(answer[i], truth[i] / (i + 0.5), tol);
}
コード例 #7
0
ファイル: gauss.hpp プロジェクト: gregvw/legendre-gauss
// Update grid points as well as the nth Legendre polynomial and its derivative  
void newton_step(const dvec& a, const dvec& b, dvec& x, dvec& L, dvec& Lp) {
    int n = x.size();
    legendre(a,b,x,L,Lp);
    for(int i=0;i<n;++i) {
        x[i] -= L[i]/Lp[i];
    } 
}
コード例 #8
0
main()
{
      double p=653,q=751,N=p*q; //N=368292653
     // double p=2,q=3,N=p*q;
      double temp,x=313599//,temp;
      short msg=101,i,y;
      tobinary(msg);printf("Original Message: \n");
      for(i=0;i<16;i++)
                 printf("%d   ",arr[i]);    
      
      printf("\n\nEncrypted Message: \n");
      for(i=15;i>=0;i--)
       {
               // srand(NULL);
            
                y=yrange[rand()%7]; 
                //y=3;
                printf("\ny= %d     ",y);
                c[i]=fmod((pow(y,2)*pow(x,arr[i])),N); 
                printf("%ld ",c[i]);
       }        
      printf("\n\nDecrypted Message:  \n");
       //decryption  
     
     for(i=0;i<16;i++)
       {
                temp=c[i];        
                printf("%d   ",legendre(temp,p)); 
                
       }
      printf("\n\n\n");
      system("pause"); 
}     
コード例 #9
0
ファイル: poly.c プロジェクト: chrismullins/moab
void gauss_weights(const real *z, real *w, int n)
{
  int i,j;
  for(i=0; i<=(n-1)/2; ++i) {
    real d = (n+1)*legendre(n+1,z[i]);
    w[i] = 2*(1-z[i]*z[i])/(d*d);
  }
  for(j=(n+1)/2,i=n/2-1; j<n; ++j,--i) w[j]=w[i];
}
コード例 #10
0
ファイル: poly.c プロジェクト: chrismullins/moab
void lobatto_weights(const real *z, real *w, int n)
{
  int i,j;
  for(i=0; i<=(n-1)/2; ++i) {
    real d = legendre(n-1,z[i]);
    w[i] = 2/((n-1)*n*d*d);
  }
  for(j=(n+1)/2,i=n/2-1; j<n; ++j,--i) w[j]=w[i];
}
コード例 #11
0
ファイル: Cartesian.C プロジェクト: FHilty/moose
TEST(FunctionalExpansionsTest, legendreConstructor)
{
  const unsigned int order = 5;

  Legendre legendre({FunctionalBasisInterface::_domain_options = "x"},
                    {order},
                    expansion_type = "orthonormal",
                    generation_type = "standard");
  EXPECT_EQ(legendre.getOrder(0), order);
}
コード例 #12
0
int main(void)
{
	printf("input n, x:\n");
	int n, x;

	scanf("%d%d", &n, &x);

	printf("%f\n", legendre(n, x));

	return 0;
}
コード例 #13
0
ファイル: gridrec.c プロジェクト: MrQ007/tomopy
void 
set_pswf_tables(
    float C, int nt, float lambda, const float *coefs, 
    int ltbl, int linv, float* wtbl, float* winv)                                            
{
    // Set up lookup tables for convolvent (used in Phase 1 of   
    // do_recon()), and for the final correction factor (used in 
    // Phase 3).

    int i;
    float norm;
    const float fac = (float)ltbl / (linv+0.5);
    const float polyz = legendre(nt, coefs, 0.);

    wtbl[0] = 1.0;
    for(i=1; i<=ltbl; i++) 
    {   
        wtbl[i] = legendre(nt, coefs, (float)i/ltbl) / polyz;
    }

    // Note the final result at end of Phase 3 contains the factor, 
    // norm^2.  This incorporates the normalization of the 2D
    // inverse FFT in Phase 2 as well as scale factors involved
    // in the inverse Fourier transform of the convolvent.
    norm = sqrt(M_PI/2/C/lambda) / 1.2;

    winv[linv] = norm / wtbl[0];
    for(i=1; i<=linv; i++)
    {
        // Minus sign for alternate entries
        // corrects for "natural" data layout
        // in array H at end of Phase 1.
        norm = -norm; 
        winv[linv+i] = winv[linv-i] = norm / wtbl[lroundf(i*fac)];
    }
}
コード例 #14
0
int main() {
  int i=0;
  double x=0;
  FILE *outp = fopen("legendre.dat", "w");
  srand((unsigned)time(NULL));  //initialize random number generator
  fprintf(outp, "# x    leg(n=0)   leg(n=1)  leg(n=2)  leg(n=3)  leg(n=4)  leg(n=5)\n");
  fprintf(outp, "#--------------------------------------\n");
  for(i=0; i<10000; i++){
    x = 2.0*rand()/RAND_MAX - 1.0;
    fprintf(outp, "%lf    %lf    %lf    %lf    %lf     %lf    %lf\n", x, legendre(0, x), legendre(1, x),           legendre(2, x), legendre(3, x), legendre(4, x), legendre(5, x));
    x=0;
  }
  fclose(outp);
  return 0;
}
コード例 #15
0
ファイル: legendre.c プロジェクト: UnProgrammatore/CCQ
int main(){

    printf("ciao pippo1 \n");

	mpz_t n;
	mpz_init(n);
	mpz_set_ui(n,4);

    printf("ciao pippo2 \n");

    unsigned int p = 17;

    printf("ciao pippo3 \n");
    
    mpz_t s;
    mpz_init(s);
    mpz_sqrt(s,n);

    printf("ciao pippo4 \n");

    pair solution;

    printf("ciao pippo5 \n"); 

    inizializza_pair(&solution);

    printf("ciao pippo6 \n");

    unsigned int pippo=-3;

    printf("ciao pippo7 \n");

    pippo = legendre(n,p);

    printf("ciao pippo8 \n");

    printf("%d\n",pippo);

    pippo = legendre_sol(n,p,&solution);

    printf("ciao pippo9 \n");

    printf("%d\n",pippo);

    printf("%d\n",solution.sol1);
    printf("%d\n",solution.sol2);    

}
コード例 #16
0
void gausslobatto_quadrature(int polyorder, double *roots, double *weights){
	int n, ii;
	double temp[polyorder];

	if (polyorder == 1){
		roots[0] = 0.;
		weights[0] = 2.;
	}
	else{
		n = polyorder;
		dlegendre_roots(n, roots);
		legendre(n-1, roots, n, temp);
		for(ii=0;ii<n; ++ii){
			weights[ii] = 2./(n*(n-1)*(temp[ii]*temp[ii]));
		}
	}
}
コード例 #17
0
TH1* project2DHistoLegendre(TH2* h2,int l){
  if(!h2 || l<0)return NULL;

  //the projection will be on to the X axis
  //Also: The the signal is defined as  I(x,m)= A(m)*I(x)  where I(x)=sum(a_l * P_l(x))
  //where I(x) is normalized: integral(I(x)*dx,-1,1)=1   

  //get range binning
  int nbinsx=h2->GetXaxis()->GetNbins();
  int nbinsy=h2->GetYaxis()->GetNbins();
  float xmin=h2->GetXaxis()->GetXmin();
  float xmax=h2->GetXaxis()->GetXmax();

  //create a new histogram
  TH1F* h=new TH1F(TString(h2->GetName())+"_LegendreProj"+(long)l,TString(h2->GetName())+"_LegendreProj"+(long)l,nbinsx,xmin,xmax);
  float bincont=0;
  float polval=0;
  float add=0;
  float erradd=0;

  for(int bx=1;bx<=nbinsx;bx++){

    add=0;
    erradd=0;
    //perform the integral over angle: integral( ((2.*l+1.)/2.) * P_l(x)*I(x)*dx)
    for(int by=1;by<=nbinsy;by++){
      bincont=h2->GetBinContent(bx,by);//this equals I(m,x)*dm*dx= A(m)*dm*I(x)*dx
      polval=legendre(l,h2->GetYaxis()->GetBinCenter(by))*(2.*l+1.)/2.;//this equals P_l(x)
      add+=bincont*polval;
      erradd+= pow(h2->GetBinError(bx,by)*polval,2);
    }

    h->SetBinContent(bx,add);//fill with  A(m)*dm*a_l
    h->SetBinError(bx,sqrt(erradd));//error is error of each integral piece added in quadrature 
  }

  return (TH1*)h;
}
コード例 #18
0
void Basis_HGRAD_LINE_Hermite_FEM<Scalar, ArrayScalar>::getValues(ArrayScalar &        outputValues,
                                                                  const ArrayScalar &  inputPoints,
                                                                  const EOperator      operatorType) const {
  
  // Verify arguments
#ifdef HAVE_INTREPID_DEBUG
  Intrepid::getValues_HGRAD_Args<Scalar, ArrayScalar>(outputValues,
                                                      inputPoints,
                                                      operatorType,
                                                      this -> getBaseCellTopology(),
                                                      this -> getCardinality() );
#endif
  // Number of evaluation points = dim 0 of inputPoints
  int nPts = inputPoints.dimension(0);  
  int nBf  = this->getCardinality();  

  int n = nBf/2;

  // Legendre polynomials and their derivatives evaluated on inputPoints
  SerialDenseMatrix legendre(nBf,nPts); 

  // Hermite interpolants evaluated on inputPoints
  SerialDenseMatrix hermite(nBf,nPts);
    
  ArrayScalar P (nBf);
  ArrayScalar Px(nBf);
         
  int derivative_order;
  int derivative_case = static_cast<int>(operatorType);

  if( derivative_case == 0 ) {
    derivative_order = 0;
  }
  else if( derivative_case > 0 && derivative_case < 5 ) {
    derivative_order = 1;
  }
  else {
    derivative_order = derivative_case - 3;
  }
  
  try {
    // GRAD,CURL,DIV, and D1 are all the first derivative
    switch (operatorType) {
      case OPERATOR_VALUE: 
      { 
        for( int i=0; i<nPts; ++i ) { 
          recurrence( P, Px, inputPoints(i,0) );
          for( int j=0; j<nBf; ++j ) {
             legendre(j,i) = P(j);
          }
        }
        break; 
      }
      case OPERATOR_GRAD:
      case OPERATOR_DIV:
      case OPERATOR_CURL:
      case OPERATOR_D1:
      {
        for( int i=0; i<nPts; ++i ) { 
          recurrence( P, Px, inputPoints(i,0) );
          for( int j=0; j<nBf; ++j ) {
             legendre(j,i) = Px(j);
          }
        }
        break;
      }  
      case OPERATOR_D2:
      case OPERATOR_D3:
      case OPERATOR_D4:
      case OPERATOR_D5:
      case OPERATOR_D6:
      case OPERATOR_D7:
      case OPERATOR_D8:
      case OPERATOR_D9:
      case OPERATOR_D10:
      {
        for( int i=0; i<nPts; ++i ) {
          legendre_d( P, Px, derivative_order, inputPoints(i,0));
          for( int j=0; j<nBf; ++j ) {
            legendre(j,i) = Px(j); 
          }
        }
        break;
      }
      default:
        TEUCHOS_TEST_FOR_EXCEPTION( !( Intrepid::isValidOperator(operatorType) ), std::invalid_argument,
                            ">>> ERROR (Basis_HGRAD_LINE_Hermite_FEM): Invalid operator type");

    } // switch(operatorType)
  }
  catch (std::invalid_argument &exception){
    TEUCHOS_TEST_FOR_EXCEPTION( true , std::invalid_argument,
                        ">>> ERROR (Basis_HGRAD_LINE_Hermite_FEM): Operator failed");    
  }

  if( !isFactored_ ) {
    solver_.factorWithEquilibration(true);
    solver_.factor();
  }

  solver_.setVectors(Teuchos::rcpFromRef(hermite),Teuchos::rcpFromRef(legendre));
  solver_.solve();

  if(derivative_order > 0)
  {
    for( int i=0; i<n; ++i ) {
      for( int j=0; j<nPts; ++j ) {
        outputValues(2*i,  j,0)  = hermite(i,  j);
        outputValues(2*i+1,j,0)  = hermite(i+n,j);
      } 
    }
  }
  else {
    for( int i=0; i<n; ++i ) {
      for( int j=0; j<nPts; ++j ) {
        outputValues(2*i  ,j)   = hermite(i,  j);
        outputValues(2*i+1,j)   = hermite(i+n,j);
      } 
    }
  }
     
} // getValues()
コード例 #19
0
ファイル: Legendre.cpp プロジェクト: IDI-Systems/acre2
void PolynomialFinderBase::solve (int n)
{
  assert (n <= m_maxN);

  double c0,c1;
  int i,j,k;

  k = (n-1)/2;
  //
  //  form vector of 'a' constants
  //
  if (n & 1) {                // odd
    for (i=0;i<=k;i++) {
      m_a[i] = (2.0*i+1.0)/(m_sqrt2()*(k+1.0));
    }
  }                           // even
  else {
    for (i=0;i<k+1;i++) {
      m_a[i] = 0.0;
    }
    if (k & 1) {
      for (i=1;i<=k;i+=2) {
        m_a[i] = (2*i+1)/sqrt(double((k+1)*(k+2)));
      }
    }
    else {
      for (i=0;i<=k;i+=2) {
        m_a[i] = (2*i+1)/sqrt(double((k+1)*(k+2)));
      }
    }
  }
  for (i=0;i<=n;i++){
    m_s[i] = 0.0;
    m_w[i] = 0.0;
  }
  //
  // form s[] = sum of a[i]*P[i]
  //
  m_s[0] = m_a[0];
  m_s[1] = m_a[1];
  for (i=2;i<=k;i++) {
    legendre(m_p,i);
    for (j=0;j<=i;j++) {
      m_s[j] += m_a[i]*m_p[j];
    }
  }
  //
  //  form v[] = square of s[]
  //
  for (i=0;i<=2*k+2;i++) {
    m_v[i] = 0.0;
  }
  for (i=0;i<=k;i++) {
    for (j=0;j<=k;j++) {
      m_v[i+j] += m_s[i]*m_s[j];    
    }
  }
  //
  //  modify integrand for even 'n'
  //
  m_v[2*k+1] = 0.0;
  if ((n & 1) == 0) {
    for (i=n;i>=0;i--) {
      m_v[i+1] += m_v[i];
    }
  }
  //
  //  form integral of v[]
  //
  for (i=n+1;i>=0;i--) {
    m_v[i+1] = m_v[i]/(double)(i+1.0);
  }
  m_v[0] = 0.0;
  //
  // clear s[] for use in computing definite integral
  //
  for (i=0;i<(n+2);i++){ 
    m_s[i] = 0.0;
  }
  m_s[0] = -1.0;
  m_s[1] = 2.0;
  //
  //  calculate definite integral
  //
  for (i=1;i<=n;i++) {
    if (i > 1) {
      c0 = -m_s[0];
      for (j=1;j<i+1;j++) {
        c1 = -m_s[j] + 2.0*m_s[j-1];
        m_s[j-1] = c0;
        c0 = c1;
      }
      c1 = 2.0*m_s[i];
      m_s[i] = c0;
      m_s[i+1] = c1;
    }
    for (j=i;j>0;j--) {
      m_w[j] += (m_v[i]*m_s[j]);
    }
  }
  if ((n & 1) == 0) m_w[1] = 0.0;
}
コード例 #20
0
ファイル: Average_ekt.cpp プロジェクト: bbusemeyer/mainline
void Average_ekt::calcPseudoMo(System * sys,
    Sample_point * sample,
    Pseudopotential *psp, 
    const Array1 <doublevar> & accept_var,
    Array1 <dcomplex> & totalv)//, 
{
  int natoms=sample->ionSize();
  assert(accept_var.GetDim(0) >= nTest());
  //assert(totalv.GetDim(0) >= nwf);
  assert(nelectrons == sample->electronSize());

  Array1 <doublevar> ionpos(3), oldpos(3), newpos(3);
  Array1 <doublevar> newdist(5), olddist(5);

  int accept_counter=0;
  //deriv.Resize(natoms, 3);
  //deriv=0;
  dcomplex nonlocal; 
  Array1 <doublevar> rDotR(psp->getMaxAIP());
  Array2 <dcomplex> movals_t(nmo, 1);
  Array2 <dcomplex> movals(nmo, 1);
  sample->getElectronPos(0, oldpos);
  calc_mos(sample, 0, movals);
  dcomplex local; 
  for (int jmo = 0; jmo < nmo; jmo ++) {
    nonlocal=0.0; 
    local = 0.0; 
    for(int at = 0; at< natoms; at++){
      if(psp->getNumL(at) != 0) {
        Array1 <doublevar> v_l(psp->getNumL(at));
        sample->getIonPos(at, ionpos);
        sample->updateEIDist();
        sample->getEIDist(0, at, olddist);
        int spin=1;
        //	if(e < sys->nelectrons(0)) spin=0;
        spin = 0;
        psp->getRadialOut(at, spin, sample, olddist, v_l);

        //----------------------------------------
        //Start integral

        int accept;
        if(psp->getDeterministic()) {
          accept= olddist(0) < psp->getCutoff(at);
        }
        else {
          doublevar strength=0;
          const doublevar calculate_threshold=10;

          for(int l=0; l<psp->getNumL(at)-1; l++) {
            strength+=calculate_threshold*(2*l+1)*fabs(v_l(l));
          }
          strength=min((doublevar) 1.0, strength);
          doublevar rand=accept_var(accept_counter++);
          //cout << at <<"  random number  " << rand
          //   << "  p_eval  " << strength  << endl;
          if ( strength > 0.0 ) {
            for(int l=0; l<psp->getNumL(at)-1; l++)
              v_l(l)/=strength;
          }
          accept=strength>rand;
        }

        //bool localonly = true;
        if(accept)  {
          for(int i=0; i< psp->getAIP(at); i++) {
            for(int d=0; d < 3; d++) 
              newpos(d)=psp->getIntegralPt(at,i,d)*olddist(0)-olddist(d+2);
            sample->translateElectron(0, newpos);
            sample->updateEIDist();
            sample->getEIDist(0,at,newdist);
            rDotR(i)=0;
            for(int d=0; d < 3; d++)
              rDotR(i)+=newdist(d+2)*olddist(d+2);

            rDotR(i)/=(newdist(0)*olddist(0));  //divide by the magnitudes
            calc_mos(sample, 0, movals_t);//update value
            //----
            //cout << "signs " << base_sign << "  " << new_sign << endl;;
            for(int l=0; l< psp->getNumL(at)-1; l++) {
              nonlocal+=(2*l+1)*v_l(l)*legendre(rDotR(i), l)*psp->getIntegralWeight(at, i)*movals_t(jmo, 0);
            }
            sample->setElectronPos(0, oldpos);
          } 
        }
        int localL=psp->getNumL(at)-1; //The l-value of the local part is
        local += v_l(localL); 
      } // if atom has psp
    }  //atom loop
    //    cout << "Local:" << local << endl; 
    //cout << "Nonlocal: " << nonlocal/movals(jmo, 0) << endl; 
    totalv(jmo) = local*movals(jmo, 0)+nonlocal;
    //totalv(jmo) =0.0; 
  }  //nmo loop
  //cout << "psp: local part " << accum_local
  // << "  nonlocal part " << accum_nonlocal << endl;
}
コード例 #21
0
Int_t DstPiAnalysis::WeightEvents(){
 
  
  if(!OpenReducedNtuple())return 0;
  SetReducedNtupleBranches();
  if(!OpenEfficiency()){cout<<"Could not open efficiecy file"<<endl;return 0;}


  //
  TH1F HDstPi("HDstPi","HDstPi",2000,2.1,4.1);
 
  //
  TH1F HDstPiEff("HDstPiEff","HDstPiEff",2000,2.1,4.1);
  HDstPiEff.Sumw2();
    
  //mass cut abs(heli)>.75
  TH1F HDstPiMD2420Helicity("HDstPiMD2420Helicity","HDstPiMD2420Helicity",2000,2.1,4.1);
  HDstPiMD2420Helicity.Sumw2();

  //mass cut abs(heli)<.5
  TH1F HDstPiMD2460Helicity("HDstPiMD2460Helicity","HDstPiMD2460Helicity",2000,2.1,4.1);
  HDstPiMD2460Helicity.Sumw2();


  //mass vs helicity .2 slices
  TH1F* HDstPiMVsHelicity[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsHelicity[i]=new TH1F(TString("HDstPiMVsHelicity")+(long)i,"HDstPiMVsHelicity",2000,2.1,4.1);
    HDstPiMVsHelicity[i]->Sumw2();
  }  

  //mass vs helicity .1 slices
  TH1F* HDstPiMVsHelicityFine[20];
  for(Int_t i=0;i<20;i++){
    HDstPiMVsHelicityFine[i]=new TH1F(TString("HDstPiMVsHelicityFine")+(long)i,"HDstPiMVsHelicityFine",2000,2.1,4.1);
    HDstPiMVsHelicityFine[i]->Sumw2();
  }  


  //mass vs helicity .2 slices cut -.5 cosD*
  TH1F* HDstPiMVsHelicityN5Cos[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsHelicityN5Cos[i]=new TH1F(TString("HDstPiMVsHelicityN5Cos")+(long)i,"HDstPiMVsHelicityN5Cos",2000,2.1,4.1);
    HDstPiMVsHelicityN5Cos[i]->Sumw2();
  }  


  //mass vs helicity .2 slices cut -.9 cosD*
  TH1F* HDstPiMVsHelicityN9Cos[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsHelicityN9Cos[i]=new TH1F(TString("HDstPiMVsHelicityN9Cos")+(long)i,"HDstPiMVsHelicityN9Cos",2000,2.1,4.1);
    HDstPiMVsHelicityN9Cos[i]->Sumw2();
  }  


  //mass vs helicity in slices of .25, for dependent mass widths 
  TH1F* HDstPiMVsHelicityMW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsHelicityMW[i]=new TH1F(TString("HDstPiMVsHelicityMW")+(long)i,"HDstPiMVsHelicityMW",2000,2.1,4.1);
    HDstPiMVsHelicityMW[i]->Sumw2();
  }


  //mass vs helicity in slices of .25, for dependent mass widths 
  TH1F* HDstPiMVsCoarseAbsHelicity[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCoarseAbsHelicity[i]=new TH1F(TString("HDstPiMVsCoarseAbsHelicity")+(long)i,"HDstPiMVsCoarseAbsHelicity",2000,2.1,4.1);
    HDstPiMVsCoarseAbsHelicity[i]->Sumw2();
  }




  //efficiency corrected mass vs p* coarse
  TH1F* HDstPiMVsPstar[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPstar[i]=new TH1F(TString("HDstPiMVsPstar")+(long)i,"HDstPiMVsPstar",2000,2.1,4.1);
    HDstPiMVsPstar[i]->Sumw2();
  } 
  TH1* HDstPiMVsPstarNoEff[4];//for p* dependent mass-width systematics with no helicity cut
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarNoEff[i]=new TH1F(TString("HDstPiMVsPstarNoEff")+(long)i,"HDstPiMVsPstarNoEff",2000,2.1,4.1); 

  TH1* HDstPiMVsPstarD2420[4];//for p* systematics for MC this should not be weighted due to low stats
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPstarD2420[i]=new TH1F(TString("HDstPiMVsPstarD2420")+(long)i,"HDstPiMVsPstarD2420",2000,2.1,4.1); 
    HDstPiMVsPstarD2420[i]->Sumw2();
  }
  TH1* HDstPiMVsPstarD2460[4];//for p* systematics
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPstarD2460[i]=new TH1F(TString("HDstPiMVsPstarD2460")+(long)i,"HDstPiMVsPstarD2460",2000,2.1,4.1); 
    HDstPiMVsPstarD2460[i]->Sumw2();
  }


  //efficiency corrected mass vs p* for crossections  
  TH1F* HDstPiMVsPstarFine[10];
  for(Int_t i=0;i<10;i++){
    HDstPiMVsPstarFine[i]=new TH1F(TString("HDstPiMVsPstarFine")+(long)i,"HDstPiMVsPstarFine",2000,2.1,4.1);
    HDstPiMVsPstarFine[i]->Sumw2();
  }   
  TH1F* HDstPiMVsEnergyFine[30];
  for(Int_t i=0;i<30;i++){
    HDstPiMVsEnergyFine[i]=new TH1F(TString("HDstPiMVsEnergyFine")+(long)i,"HDstPiMVsEnergyFine",2000,2.1,4.1);
    HDstPiMVsEnergyFine[i]->Sumw2();
  }   
  

  //efficiency corrected mass vs cos Dstar  
  TH1F* HDstPiMVsCosDstar[20];
  for(Int_t i=0;i<20;i++){
    HDstPiMVsCosDstar[i]=new TH1F(TString("HDstPiMVsCosDstar")+(long)i,"HDstPiMVsCosDstar",2000,2.1,4.1);
    HDstPiMVsCosDstar[i]->Sumw2();
  }


  //efficiency corrected mass vs cosD* in slices of .25, for dependent mass widths 
  TH1F* HDstPiMVsCosDstarMW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsCosDstarMW[i]=new TH1F(TString("HDstPiMVsCosDstarMW")+(long)i,"HDstPiMVsCosDstarMW",2000,2.1,4.1);
    HDstPiMVsCosDstarMW[i]->Sumw2();
  }

  //efficiency corrected mass vs cosD* in slices of .25, for dependent mass widths , for D2420 cut helicity>.75
  TH1F* HDstPiMVsCosDstarD2420MW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsCosDstarD2420MW[i]=new TH1F(TString("HDstPiMVsCosDstarD2420MW")+(long)i,"HDstPiMVsCosDstarD2420MW",2000,2.1,4.1);
    HDstPiMVsCosDstarD2420MW[i]->Sumw2();
  }
  //efficiency corrected mass vs cosD* in slices of .25, for dependent mass widths , for D2420 cut helicity<.5
  TH1F* HDstPiMVsCosDstarD2460MW[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMVsCosDstarD2460MW[i]=new TH1F(TString("HDstPiMVsCosDstarD2460MW")+(long)i,"HDstPiMVsCosDstarD2460MW",2000,2.1,4.1);
    HDstPiMVsCosDstarD2460MW[i]->Sumw2();
  }




  //efficiency corrected mass vs phi*
  TH1F* HDstPiMVsPhi[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhi[i]=new TH1F(TString("HDstPiMVsPhi")+(long)i,"HDstPiMVsPhi",2000,2.1,4.1);
    HDstPiMVsPhi[i]->Sumw2();
  } 
  TH1F* HDstPiMVsPhiNoEff[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhiNoEff[i]=new TH1F(TString("HDstPiMVsPhiNoEff")+(long)i,"HDstPiMVsPhiNoEff",2000,2.1,4.1);
    HDstPiMVsPhiNoEff[i]->Sumw2();
  } 
  TH1* HDstPiMVsPhiD2420[4];//for  systematics
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhiD2420[i]=new TH1F(TString("HDstPiMVsPhiD2420")+(long)i,"HDstPiMVsPhiD2420",2000,2.1,4.1);
    HDstPiMVsPhiD2420[i]->Sumw2();
  }
  TH1* HDstPiMVsPhiD2460[4];//for   systematics 
  for(Int_t i=0;i<4;i++){
    HDstPiMVsPhiD2460[i]=new TH1F(TString("HDstPiMVsPhiD2460")+(long)i,"HDstPiMVsPhiD2460",2000,2.1,4.1); 
    HDstPiMVsPhiD2460[i]->Sumw2();
  }




  //efficiency corrected mass vs cos*
  TH1F* HDstPiMVsCos[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCos[i]=new TH1F(TString("HDstPiMVsCos")+(long)i,"HDstPiMVsCos",2000,2.1,4.1);
    HDstPiMVsCos[i]->Sumw2();
  }
  TH1F* HDstPiMVsCosNoEff[4];
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCosNoEff[i]=new TH1F(TString("HDstPiMVsCosNoEff")+(long)i,"HDstPiMVsCosNoEff",2000,2.1,4.1);
    HDstPiMVsCosNoEff[i]->Sumw2();
  } 
  TH1* HDstPiMVsCosD2420[4];//for  systematics  
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCosD2420[i]=new TH1F(TString("HDstPiMVsCosD2420")+(long)i,"HDstPiMVsCosD2420",2000,2.1,4.1); 
    HDstPiMVsCosD2420[i]->Sumw2();
  }
  TH1* HDstPiMVsCosD2460[4];//for  systematics 
  for(Int_t i=0;i<4;i++){
    HDstPiMVsCosD2460[i]=new TH1F(TString("HDstPiMVsCosD2460")+(long)i,"HDstPiMVsCosD2460",2000,2.1,4.1); 
    HDstPiMVsCosD2460[i]->Sumw2();
  }





  //Legendre projections
  TH1F* HDstPiMLegendre[NPROJS];
  for(Int_t i=0;i<NPROJS;i++){
    HDstPiMLegendre[i]=new TH1F(TString("HDstPiMLegendre")+(long)i,"HDstPiMLegendre",2000,2.1,4.1);
    HDstPiMLegendre[i]->Sumw2();
  }  
  //slice P2 in cosD* 
  TH1F* HDstPiMP2VsCosDstar[8];
  for(Int_t i=0;i<8;i++){
    HDstPiMP2VsCosDstar[i]=new TH1F(TString("HDstPiMP2VsCosDstar")+(long)i,"HDstPiMP2VsCosDstar",2000,2.1,4.1);
    HDstPiMP2VsCosDstar[i]->Sumw2();
  }  



  //2D Helicity vs mass
  TH2F H2DstPiMVsDstarHel("H2DstPiMVsDstarHel","H2DstPiMVsDstarHel",2000,2.1,4.1,20,-1.0,1.0);
  H2DstPiMVsDstarHel.Sumw2();
  TH2F H2DstPiMVsDstarHelNoEff("H2DstPiMVsDstarHelNoEff","H2DstPiMVsDstarHelNoEff",2000,2.1,4.1,20,-1.0,1.0);
  H2DstPiMVsDstarHelNoEff.Sumw2();

  TH2F* H2DstPiMVsHelCosDstar[4];
  for(Int_t i=0;i<4;i++){
    H2DstPiMVsHelCosDstar[i]=new TH2F(TString("H2DstPiMVsHelCosDstar")+(long)i,TString("H2DstPiMVsHelCosDstar")+(long)i,2000,2.1,4.1,20,-1.0,1.0);
    H2DstPiMVsHelCosDstar[i]->Sumw2();
  }  



  ///------------------------------------------
  ////efficiencies after eff corrections
  //----------------------------
  TH3F H3PvsMVsDstA; 

  TH2F H2PvsM;   

  TH1F HDstarHelicityNoShape;

  TH1F HDstarHelicity;
 
  TH1F HDstPiMNoShape;

  TH1F HDstPiDM;

  TH1F HPstarNoShape;

  TH1F HDstarAngleNoShape;

  TH1F HDstarAngle;
  
  TH1F HDstPiCosstarNoShape;
    
  //fully efficiency corrected mass
  TH1F HDstPiMFineNoRes;

  //Generated mass vs p*   
  TH1* HMCMVsPstar[4];

  if(_TruthMatch){
   
    if(!OpenReducedFile())return 0;

    HMCDstarHelicity=(TH1F*)ReducedFile->Get("HMCDstarHelicity");
    if(!HMCDstarHelicity)return 0;
  
    HMCXMass=(TH1F*)ReducedFile->Get("HMCXMass");
    if(!HMCXMass)return 0;  
  
    HMCXp3CM=(TH1F*)ReducedFile->Get("HMCXp3CM");
    if(!HMCXp3CM)return 0;

    HMCXcosthCM=(TH1F*)ReducedFile->Get("HMCXcosthCM");
    if(!HMCXcosthCM)return 0;

    HMCDstarAngle=(TH1F*)ReducedFile->Get("HMCDstarAngle");
    if(!HMCDstarAngle)return 0;

    H3MCPvsMassVsDstAngle=(TH3F*)ReducedFile->Get("H3MCPvsMassVsDstAngle");                                                    
    if(!H3MCPvsMassVsDstAngle){
      cout<<"No histogram found"<<endl;
      return 0;
    }
    
    H2MCPvsMass=(TH2F*)ReducedFile->Get("H2MCPvsMass");                                                    
    if(!H2MCPvsMass){
      cout<<"No histogram found"<<endl;
      return 0;
    }

    H2MCPvsMassFine=(TH2F*)ReducedFile->Get("H2MCPvsMassFine");                                                    
    if(!H2MCPvsMass){
      cout<<"No histogram found"<<endl;
      return 0;
    }


    //----------------------------
    H3PvsMVsDstA.SetNameTitle("H3PvsMVsDstA","H3PvsMVsDstA");
    H3PvsMVsDstA.SetBins(H3MCPvsMassVsDstAngle->GetXaxis()->GetNbins(),
		      H3MCPvsMassVsDstAngle->GetXaxis()->GetXmin(),
		      H3MCPvsMassVsDstAngle->GetXaxis()->GetXmax(),
		      H3MCPvsMassVsDstAngle->GetYaxis()->GetNbins(),
		      H3MCPvsMassVsDstAngle->GetYaxis()->GetXmin(),
		      H3MCPvsMassVsDstAngle->GetYaxis()->GetXmax(),
		      H3MCPvsMassVsDstAngle->GetZaxis()->GetNbins(),
		      H3MCPvsMassVsDstAngle->GetZaxis()->GetXmin(),
		      H3MCPvsMassVsDstAngle->GetZaxis()->GetXmax()); 
    H3PvsMVsDstA.Sumw2();


    //----------------------------
    H2PvsM.SetNameTitle("H2PvsM","H2PvsM");
    H2PvsM.SetBins(H2MCPvsMass->GetXaxis()->GetNbins(),
		H2MCPvsMass->GetXaxis()->GetXmin(),
		H2MCPvsMass->GetXaxis()->GetXmax(),
		H2MCPvsMass->GetYaxis()->GetNbins(),
		H2MCPvsMass->GetYaxis()->GetXmin(),
		H2MCPvsMass->GetYaxis()->GetXmax());   

    H2PvsM.Sumw2();


    //
    HDstarHelicityNoShape.SetNameTitle("HDstarHelicityNoShape","HDstarHelicityNoShape");
    HDstarHelicityNoShape.SetBins(HMCDstarHelicity->GetXaxis()->GetNbins(),HMCDstarHelicity->GetXaxis()->GetXmin(),HMCDstarHelicity->GetXaxis()->GetXmax());
    HDstarHelicityNoShape.Sumw2();
    
    
    HDstarHelicity.SetNameTitle("HDstarHelicity","HDstarHelicity");
    HDstarHelicity.SetBins(HMCDstarHelicity->GetXaxis()->GetNbins(),HMCDstarHelicity->GetXaxis()->GetXmin(),HMCDstarHelicity->GetXaxis()->GetXmax());
    HDstarHelicity.Sumw2();
    
    //efficiency corrected mass
    HDstPiMNoShape.SetNameTitle("HDstPiMNoShape","HDstPiMNoShape");
    HDstPiMNoShape.SetBins(HMCXMass->GetXaxis()->GetNbins(),HMCXMass->GetXaxis()->GetXmin(),HMCXMass->GetXaxis()->GetXmax());
    HDstPiMNoShape.Sumw2();
    
    //fully efficiency corrected delta mass
    HDstPiDM.SetNameTitle("HDstPiDM","HDstPiDM");
    HDstPiDM.SetBins(HMCXMass->GetXaxis()->GetNbins(),HMCXMass->GetXaxis()->GetXmin(),HMCXMass->GetXaxis()->GetXmax());
    HDstPiDM.Sumw2();
    
    HPstarNoShape.SetNameTitle("HPstarNoShape","HPstarNoShape");
    HPstarNoShape.SetBins(HMCXp3CM->GetXaxis()->GetNbins(),HMCXp3CM->GetXaxis()->GetXmin(),HMCXp3CM->GetXaxis()->GetXmax());
    HPstarNoShape.Sumw2();
    
    HDstarAngleNoShape.SetNameTitle("HDstarAngleNoShape","HDstarAngleNoShape");
    HDstarAngleNoShape.SetBins(HMCDstarAngle->GetXaxis()->GetNbins(),HMCDstarAngle->GetXaxis()->GetXmin(),HMCDstarAngle->GetXaxis()->GetXmax());
    HDstarAngleNoShape.Sumw2();

    HDstarAngle.SetNameTitle("HDstarAngle","HDstarAngle");
    HDstarAngle.SetBins(HMCDstarAngle->GetXaxis()->GetNbins(),HMCDstarAngle->GetXaxis()->GetXmin(),HMCDstarAngle->GetXaxis()->GetXmax());
    HDstarAngle.Sumw2();
    
    HDstPiCosstarNoShape.SetNameTitle("HDstPiCosstarNoShape","HDstPiCosstarNoShape");
    HDstPiCosstarNoShape.SetBins(HMCXcosthCM->GetXaxis()->GetNbins(),HMCXcosthCM->GetXaxis()->GetXmin(),HMCXcosthCM->GetXaxis()->GetXmax());
    HDstPiCosstarNoShape.Sumw2();
    
    //efficiency corrected mass
    HDstPiMFineNoRes.SetNameTitle("HDstPiMFineNoRes","HDstPiMFineNoRes");
    HDstPiMFineNoRes.SetBins(2000,2.1,4.1);
    HDstPiMFineNoRes.Sumw2();
   
   
    //Generated mass vs p*   
    for(Int_t i=0;i<4;i++){
      HMCMVsPstar[i]=H2MCPvsMassFine->ProjectionY(TString("HMCMVsPstar")+(long)i,i+1,i+1,"");
      if(!HMCMVsPstar[i]){cout<<"bad projection of HMCMVsPstar"<<endl; return 0;}
    } 


    if(!CloseReducedFile())return 0;
  
  }


  ///
  Float_t eff;
  Float_t effnoshape;
  Int_t e=0;
  while(ReducedNtuple->GetEntry(e)){
    e++;
    if(e%50000==0)cout<<e<<" cands done"<<endl;


    //for checking eff shapes after 3-D eff correction
    if(_TruthMatch){
      effnoshape=GetEfficiencyNoShape();
      if(effnoshape>0){//note resolution is removed so should not attemp to fit these 
	HDstarHelicityNoShape.Fill(dstarhelicity,1./effnoshape);
	HDstPiMNoShape.Fill(dstpimdm-dstpidmres,1./effnoshape);
	HPstarNoShape.Fill(dstpipstar,1./effnoshape);
	HDstarAngleNoShape.Fill(dstarcostheta,1./effnoshape);
	HDstPiCosstarNoShape.Fill(dstpicosstar,1./effnoshape);
	H3PvsMVsDstA.Fill(dstpipstar,dstpimdm-dstpidmres,dstarcostheta,1./effnoshape);
	H2PvsM.Fill(dstpipstar,dstpimdm-dstpidmres,1./effnoshape);
      }

    }
    

    HDstPi.Fill(dstpimdm);   
    H2DstPiMVsDstarHelNoEff.Fill(dstpimdm,dstarhelicity);
    ///
    HDstPiDM.Fill(dstpideltam);
    if(fabs(dstarhelicity)>.75)
      HDstPiMD2420Helicity.Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      HDstPiMD2460Helicity.Fill(dstpimdm);

    //for bumps
    for(Int_t i=0;i<10;i++){
      if((-1+.2*i)<dstarhelicity&&dstarhelicity<(-1+.2*(i+1))){
	if(dstarcostheta<-.5)
	  HDstPiMVsHelicityN5Cos[i]->Fill(dstpimdm);
	
	if(dstarcostheta<-.9)
	  HDstPiMVsHelicityN9Cos[i]->Fill(dstpimdm);
	
      }
    }

    for(Int_t i=0;i<4;i++){
      if(.25*i<fabs(dstarhelicity)&&fabs(dstarhelicity)<.25*(i+1))
	HDstPiMVsCoarseAbsHelicity[i]->Fill(dstpimdm);
    }


    //
    for(Int_t i=0;i<10;i++){
      if((-1+.2*i)<dstarhelicity&&dstarhelicity<(-1+.2*(i+1))){
	HDstPiMVsHelicity[i]->Fill(dstpimdm);
      }
    }
    for(Int_t i=0;i<20;i++){
      if((-1+.1*i)<dstarhelicity&&dstarhelicity<(-1+.1*(i+1)))
	HDstPiMVsHelicityFine[i]->Fill(dstpimdm);
    }
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarhelicity&&dstarhelicity<(-1.+.25*(i+1)))
	HDstPiMVsHelicityMW[i]->Fill(dstpimdm);



    //p* dependence
    for(Int_t i=0;i<4;i++)
      if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	HDstPiMVsPstar[i]->Fill(dstpimdm); 
    for(Int_t i=0;i<10;i++)
      if((3+.2*i)<dstpipstar&&dstpipstar<(3+.2*(i+1)))
	HDstPiMVsPstarFine[i]->Fill(dstpimdm);
    Float_t energyfraction=sqrt(dstpimass*dstpimass+dstpipstar*dstpipstar)/(OnPeakEnergy/2.);
    for(Int_t i=0;i<30;i++)
      if((.5+.02*i)<energyfraction&&energyfraction<(.5+.02*(i+1)))
	HDstPiMVsEnergyFine[i]->Fill(dstpimdm);

    //cos D*
    for(Int_t i=0;i<20;i++)
      if((-1+.1*i)<dstarcostheta&&dstarcostheta<(-1.+.1*(i+1)))
	HDstPiMVsCosDstar[i]->Fill(dstpimdm);
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1)))
	HDstPiMVsCosDstarMW[i]->Fill(dstpimdm);
    for(Int_t i=0;i<4;i++){
      if((-1+.5*i)<dstarcostheta&&dstarcostheta<(-1.+.5*(i+1)))
	H2DstPiMVsHelCosDstar[i]->Fill(dstpimdm,dstarhelicity);
    }
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1))&&fabs(dstarhelicity)>.75)
	HDstPiMVsCosDstarD2420MW[i]->Fill(dstpimdm);
    for(Int_t i=0;i<8;i++)
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1))&&fabs(dstarhelicity)<.5)
	HDstPiMVsCosDstarD2460MW[i]->Fill(dstpimdm);

        
    //phi dependence
    for(Int_t i=0;i<4;i++)
      if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	HDstPiMVsPhi[i]->Fill(dstpimdm);



    //cos* dependence
    for(Int_t i=0;i<4;i++)
      if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	HDstPiMVsCos[i]->Fill(dstpimdm);



    // p* systematics
    for(Int_t i=0;i<4;i++)
      if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	HDstPiMVsPstarNoEff[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)>.75)
      for(Int_t i=0;i<4;i++)
	if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	  HDstPiMVsPstarD2420[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      for(Int_t i=0;i<4;i++)
	if((3+.5*i)<dstpipstar&&dstpipstar<(3+.5*(i+1)))
	  HDstPiMVsPstarD2460[i]->Fill(dstpimdm);
    
    //phi
    for(Int_t i=0;i<4;i++)
      if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	HDstPiMVsPhiNoEff[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)>.75)
      for(Int_t i=0;i<4;i++)
	if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	  HDstPiMVsPhiD2420[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      for(Int_t i=0;i<4;i++)
	if((-mypi+i*mypi/2)<dstpiphistar&&dstpiphistar<(-mypi+(i+1)*mypi/2))
	  HDstPiMVsPhiD2460[i]->Fill(dstpimdm);

    //cos(theta*)
    for(Int_t i=0;i<4;i++)
      if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	HDstPiMVsCosNoEff[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)>.75)
      for(Int_t i=0;i<4;i++)
	if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	  HDstPiMVsCosD2420[i]->Fill(dstpimdm);
    if(fabs(dstarhelicity)<.5)
      for(Int_t i=0;i<4;i++)
	if((-1+.5*i)<dstpicosstar&&dstpicosstar<(-1.+(i+1)*.5))
	  HDstPiMVsCosD2460[i]->Fill(dstpimdm);
   


    //
    eff=GetEfficiency();
    if(eff<=0)continue;

    HDstPiEff.Fill(dstpimdm,1./eff);  

    //angles
    HDstarAngle.Fill(dstarcostheta,1./eff);
    HDstarHelicity.Fill(dstarhelicity,1./eff);

    HDstPiMFineNoRes.Fill(dstpimdm-dstpidmres,1./eff);


    ///
    H2DstPiMVsDstarHel.Fill(dstpimdm,dstarhelicity,1./eff);
 
    for(Int_t i=0;i<NPROJS;i++){
      HDstPiMLegendre[i]->Fill(dstpimdm,((2.*i+1.)/2.)*legendre(i,dstarhelicity)/eff);
    }
    for(Int_t i=0;i<8;i++)//weight by P2
      if((-1+.25*i)<dstarcostheta&&dstarcostheta<(-1.+.25*(i+1)))
	HDstPiMP2VsCosDstar[i]->Fill(dstpimdm,((2.*2+1.)/2.)*legendre(2,dstarhelicity)/eff);



  }
  if(CloseReducedNtuple()!=1)return 0;
  CloseEfficiency();


  //   //add error from the efficiency;
  //   TArrayD* sw2=HDstPiMFine.GetSumw2();
  //   for(Int_t i=1;i<=HDstPiMFine.GetNbinsX();i++){
  //     (*sw2)[i]=(*sw2)[i]+pow(.0*HDstPiMFine.GetBinContent(i),2);    
  //     if(i>300&&i<350)cout<<" "<<HDstPiMFine.GetBinError(i)/HDstPiMFine.GetBinContent(i)<<endl;        
  //   }


  TFile HistosForFit(_OutputDir+"/HistosForFit.root","recreate");  

  if(_TruthMatch){
    HDstarHelicityNoShape.Write();
    HDstPiMNoShape.Write();
    HPstarNoShape.Write();
    HDstarAngleNoShape.Write();
    HDstPiCosstarNoShape.Write();
    H3PvsMVsDstA.Write();
    H2PvsM.Write();
    HDstPiMFineNoRes.Write();

    for(Int_t i=0;i<4;i++)      
      HMCMVsPstar[i]->Write();
    
  }

  //
  HDstPi.Write();
  HDstPiEff.Write();
  HDstPiMD2420Helicity.Write();
  HDstPiMD2460Helicity.Write();
  

  //
  HDstarHelicity.Write();
  HDstarAngle.Write();
  HDstPiDM.Write();

  for(Int_t i=0;i<10;i++)
    HDstPiMVsHelicityN5Cos[i]->Write();
  for(Int_t i=0;i<10;i++)
    HDstPiMVsHelicityN9Cos[i]->Write();
  for(Int_t i=0;i<10;i++)
    HDstPiMVsHelicity[i]->Write();
  for(Int_t i=0;i<20;i++)
    HDstPiMVsHelicityFine[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsHelicityMW[i]->Write();

  for(Int_t i=0;i<4;i++)
    HDstPiMVsCoarseAbsHelicity[i]->Write();

  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstar[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarNoEff[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarD2420[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPstarD2460[i]->Write();
  for(Int_t i=0;i<10;i++)
    HDstPiMVsPstarFine[i]->Write();
  for(Int_t i=0;i<30;i++)
    HDstPiMVsEnergyFine[i]->Write();


  for(Int_t i=0;i<20;i++)
    HDstPiMVsCosDstar[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsCosDstarMW[i]->Write();
  for(Int_t i=0;i<4;i++)
    H2DstPiMVsHelCosDstar[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsCosDstarD2420MW[i]->Write();
  for(Int_t i=0;i<8;i++)
    HDstPiMVsCosDstarD2460MW[i]->Write();



  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhi[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhiNoEff[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhiD2420[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsPhiD2460[i]->Write();

  for(Int_t i=0;i<4;i++)
    HDstPiMVsCos[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsCosNoEff[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsCosD2420[i]->Write();
  for(Int_t i=0;i<4;i++)
    HDstPiMVsCosD2460[i]->Write();

  H2DstPiMVsDstarHel.Write();
  H2DstPiMVsDstarHelNoEff.Write();


  for(Int_t i=0;i<NPROJS;i++){
    HDstPiMLegendre[i]->Write();
  }
  for(Int_t i=0;i<8;i++)
    HDstPiMP2VsCosDstar[i]->Write();


  HistosForFit.ls();
  HistosForFit.Close();


  //-------------
  //clean up
  
  for(Int_t i=0;i<NPROJS;i++)
    delete HDstPiMLegendre[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMP2VsCosDstar[i];
  
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsHelicityN5Cos[i];
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsHelicityN9Cos[i];
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsHelicity[i];  
  for(Int_t i=0;i<20;i++)
    delete HDstPiMVsHelicityFine[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsHelicityMW[i];
 
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCoarseAbsHelicity[i];

  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstar[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstarNoEff[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstarD2420[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPstarD2460[i];
  for(Int_t i=0;i<10;i++)
    delete HDstPiMVsPstarFine[i];
  for(Int_t i=0;i<30;i++)
    delete HDstPiMVsEnergyFine[i];

  for(Int_t i=0;i<20;i++)
    delete HDstPiMVsCosDstar[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsCosDstarMW[i];
  for(Int_t i=0;i<4;i++)
    delete H2DstPiMVsHelCosDstar[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsCosDstarD2420MW[i];
  for(Int_t i=0;i<8;i++)
    delete HDstPiMVsCosDstarD2460MW[i];

  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhi[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhiNoEff[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhiD2420[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsPhiD2460[i];

  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCos[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCosNoEff[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCosD2420[i];
  for(Int_t i=0;i<4;i++)
    delete HDstPiMVsCosD2460[i];
  
 
  return 1;
}
コード例 #22
0
void  make_cof(points_t *pts, coefficients_t *cof)
{

    gsl_matrix *A, *A_inverse, *BF, *wsp;
    gsl_permutation * perm, *permtest;
    gsl_vector *wspt, *bf;

    double		*x = pts->x;
    double		*y = pts->y;
    double		a = x[0];
    double		b = x[pts->n - 1];
    int			m = pts->n - 2 > 10 ? 10 : pts->n - 2;
    int			i, j, k;
    double      tmp;
    char		*mEnv = getenv("APPROX_BASE_SIZE");

    if (mEnv != NULL && atoi(mEnv) > 0)
        m = atoi(mEnv);
    m++;

    wspt = gsl_vector_alloc(m);
    bf = gsl_vector_alloc(m);
    permtest = gsl_permutation_alloc(m);

    gsl_vector_set_zero (bf);
    for (i = 0; i < m; i++)
    {
        tmp = 0.0;
        for (k = 0; k < pts->n; k++)
            tmp += legendre(i, x[k]) * y[k];
        gsl_vector_set(bf, i, tmp);
        //printf("%g\n", gsl_vector_get(bf, i));
    }


    A = gsl_matrix_alloc(m, m);
    A_inverse = gsl_matrix_alloc(m, m);
    perm = gsl_permutation_alloc(m);
    BF = gsl_matrix_alloc(m, 1);
    wsp = gsl_matrix_alloc(m, 1);

    gsl_matrix_set_zero (A);
    for (i = 0; i < m; i++)
    {
        for (j = 0; j < m; j++)
        {
            for (k = 0; k < pts->n; k++)
            {
                A->data[i * A->tda + j] += legendre(i, x[k]) * legendre(j, x[k]);
            }
        }
    }

    gsl_linalg_LU_decomp(A, permtest, &i);
    gsl_linalg_LU_solve(A, permtest, bf, wspt);
    gsl_vector_fprintf(stdout, wspt, "%g");


//macierz odwrotna
    gsl_linalg_LU_decomp(A, perm, &i);
    gsl_linalg_LU_invert(A, perm, A_inverse);
    gsl_matrix_free(A);
    gsl_permutation_free(perm);



    gsl_matrix_set_zero (BF);
    for (i = 0; i < m; i++)
    {
        for (k = 0; k < pts->n; k++)
            BF->data[i * BF->tda + 0] += legendre(i, x[k]) * y[k];
    }

//mnozenie macierzy
    gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, A_inverse, BF, 0.0, wsp);
    gsl_matrix_free(A_inverse);
    gsl_matrix_free(BF);

    if (alloc_cof(cof, m) == 0)
    {
        for (i = 0; i < cof->base; i++)
            cof->coefficients[i] = gsl_matrix_get(wsp, i, 0);
    }

    return;
}
コード例 #23
0
ファイル: scl.cpp プロジェクト: LuaAV/LuaAV
double legendre(int l, int m, double t){
	return legendre(l,m,cos(t),sin(t));
}