예제 #1
0
파일: UnitTest.C 프로젝트: alisw/AliRoot
void UnitTestPlaneFitter(){
  //
  // Unit test plane fitter
  //
  TLinearFitter fitter(6,"x[0]++x[1]++x[2]++x[3]++x[4]++x[5]");
  Double_t x[6]={0};
  TVectorD vec(6);
  for (Int_t i=0; i<10000; i++) { 
    x[0]=i; 
    x[1]=i*i; 
    x[2]=i*i*i; 
    x[3]=TMath::Power(i,1/2.); 
    x[4]=TMath::Power(i,1/3.); 
    x[5]=TMath::Power(i,1/4.); 
    fitter.AddPoint(x,i*i*i);
  }
  fitter.Eval();
  fitter.GetParameters(vec);
  vec.Print();
  if (TMath::Abs(vec[2]-1)>kAlmost0){
    ::Fatal("UnitTestPlaneFitter","Wrong value\n");    
  }else{
    ::Info("UnitTestPlaneFitter","OK");
  }
}
예제 #2
0
void QxrdCenterFinder::fitPowderEllipse(int n)
{
  QxrdFitterRingEllipse fitter(this, n, get_CenterX(), get_CenterY());

  int niter = fitter.fit();

  int update = false;
  QString message;

  if (fitter.reason() == QxrdFitter::Successful) {
    message.append(tr("Ellipse Fitting Succeeded after %1 iterations\n").arg(niter));
    message.append(tr("Old Center = [%1,%2]\n").arg(get_CenterX()).arg(get_CenterY()));
    message.append(tr("New Center = [%1,%2], New Radii = %3,%4\n")
                   .arg(fitter.fittedX()).arg(fitter.fittedY()).arg(fitter.fittedA()).arg(fitter.fittedB()));
    message.append(tr("Major Axis rotation = %1 deg\n").arg(fitter.fittedRot()*180.0/M_PI));

    double dx = fitter.fittedX() - get_CenterX();
    double dy = fitter.fittedY() - get_CenterY();
    message.append(tr("Moved by [%1,%2] = %3\n").arg(dx).arg(dy).arg(sqrt(dx*dx + dy*dy)));
  } else {
    message.append(tr("Ellipse Fitting Failed: Reason = %1\n").arg(fitter.reasonString()));
  }

  printMessage(message);

  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);

  if (app && app->get_GuiWanted()) {
    if (fitter.reason() == QxrdFitter::Successful) {
      message.append(tr("Do you want to update the beam centering parameters?"));
      if (QMessageBox::question(NULL, "Update Fitted Center?", message, QMessageBox::Ok | QMessageBox::No, QMessageBox::Ok) == QMessageBox::Ok) {
        update = true;
      }
    } else {
      QMessageBox::information(NULL, "Fitting Failed", message);
    }
  } else if (niter >= 0){
    update = true;
  }

  if (update) {
    set_CenterX(fitter.fittedX());
    set_CenterY(fitter.fittedY());
    set_RingRadiusA(fitter.fittedA());
    set_RingRadiusB(fitter.fittedB());
    set_RingRotation(fitter.fittedRot());
  }
}
예제 #3
0
int decompose_n(const Event_Signal *asig,  /* observed signals*/
		Event_Signal *bsig, /* fitted signals*/
		int nseg, int *seg, int coalesce, 
		Interaction *ints, double *t0, double *chisq_out)  /* parameters */
{
  /*
    performs the adaptive grid search algorithm for three-segment events,
    optionally followed by constrained least-squares

    returns number of best-fit interactions found
    ints[] array is set to contain the resulting best-fit multi-interaction
  */

  double chisq2;
  int    i, j, m, n, jseg, jfit, jint, segsave, best, shift_t0;
  float  e1, e2;
  Event_Signal  asig_temp;
  Interaction   f_ints[4*MAX_SEGS][3*MAX_SEGS];     /* test/fitted interactions */
  Event_Signal  f_bsig[4*MAX_SEGS];        /* calculated/fitted event data */
  double        f_t0[4*MAX_SEGS], chisq[4*MAX_SEGS];
  int           nints[4*MAX_SEGS];


  /* put segments in order of decreasing energy */
  for (i=1; i<nseg; i++) {
    for (j=i; j>0 && asig->seg_energy[seg[j-1]] < asig->seg_energy[seg[j]]; j--) {
      segsave  = seg[j-1];
      seg[j-1] = seg[j];
      seg[j]   = segsave;
    }
  }

  /* start off with a simple nseg-interaction fit, one in each hit segment */
  for (i=0; i<nseg; i++) {
    f_ints[0][i].seg = seg[i];
    f_ints[0][i].pos = -1;
    f_ints[0][i].r   = maxir[seg[i]]/2;
    f_ints[0][i].p   = maxip[seg[i]]/2;
    f_ints[0][i].z   = maxiz[seg[i]]/2;
    f_ints[0][i].e   = asig->seg_energy[seg[i]] / asig->total_energy;
  }
  nints[0] = nseg;
  f_t0[0] = 0;
  chisq[0] = fitter(asig, &f_bsig[0], f_ints[0], &f_t0[0], nseg, 0);
  best = 0;
  asig_temp = *asig;
  jfit = 1;

  /* loop throught the hit segments, trying to add interactions one at a time
     if the net energy gets too small, then quit  */
  for (jseg=0; jseg<nseg && asig->seg_energy[seg[jseg]] > 120.0; jseg++) {

    /* ----------------------------------------------
       now add a second interaction to the jseg-th segment;
       first subtract the calculated signal for the other segments
       from the observed signal */

    jint = nints[best] - nseg + jseg;
    for (i=0; i<jint; i++) {
      f_ints[jfit][i] = f_ints[best][i];
    }
    for (i=jint + 1; i<nints[best]; i++) {
      f_ints[jfit][i-1] = f_ints[best][i];
    }
    eval_int_pos(asig, bsig, f_ints[jfit], f_t0[best], nints[best]-1);
    for (i=0; i<MEAS_SEGS; i++) {
      for (j=0; j<TIME_STEPS; j++) {
	asig_temp.signal[i][j] -= bsig->signal[i][j];
      }
    }

    /* shift the remaining signal to bring t0 close to zero */
    shift_t0 = f_t0[best] - 1.0;
    if (shift_t0 > 0) {
      if (!quiet) printf("*----* shifting t0 by %d\n", shift_t0);
      for (i=0; i<MEAS_SEGS; i++) {
	for (j=0; j<TIME_STEPS-shift_t0; j++) {
	  asig_temp.signal[i][j] = asig_temp.signal[i][j+shift_t0];
	}
	for (j=TIME_STEPS-shift_t0; j<TIME_STEPS-1; j++) {
	  asig_temp.signal[i][j] = asig_temp.signal[i][TIME_STEPS-1];
	}
      }
    } else {
      shift_t0 = 0;
    }

    /* do 2-interation grid search in segment seg[jseg] */
    /* CHECKME min. energy fract */
    if (2 != decompose_1(&asig_temp, &f_bsig[jfit],
			 seg[jseg], &f_ints[jfit][jint], &f_t0[jfit], &chisq[jfit],
			 0, 0, 1, 0, 0, 0, 0, 0, 0.01)) {
      printf("*** ACK! decompose_1 gave number of interactions != 2...\n"
	     "         ... expect a crash very soon ...\n");
    } 
    if (!quiet) {
      printf("** grid1[%d]: chisq, pars: %7.4f", jseg, chisq[jfit]);
      for (i=jint; i<jint+2; i++) printf(", %6.3f %6.3f %6.3f %6.3f",
					 f_ints[jfit][i].r, f_ints[jfit][i].p,
					 f_ints[jfit][i].z, f_ints[jfit][i].e);
      printf("\n");
    }
    for (i=jint + 1; i<nints[best]; i++) {
      f_ints[jfit][i+1] = f_ints[best][i];
    }
    f_t0[jfit] = (f_t0[jfit] + f_t0[best] + (double) shift_t0)/2.0;
    nints[jfit] = nints[best] + 1;
    chisq2 = eval_int_pos(asig, &f_bsig[jfit], f_ints[jfit], f_t0[jfit], nints[jfit]);
    if (!quiet) {
      if (fabs(chisq[jfit]-chisq2) < 0.00001) {
	printf("***** chisq[%d] == chisq2: %f %f\n", jfit, chisq[jfit], chisq2);
      } else {
	printf("***** chisq[%d] != chisq2: %f %f\n", jfit, chisq[jfit], chisq2);
      }
    }
    chisq[jfit] = chisq2;
    if (chisq[jfit] < PENALTY3 * chisq[best]) best = jfit;

    /* do nonlinear least-squares fit with the extra interaction(s)*/
    for (i=0; i<nints[jfit]; i++) {
      f_ints[jfit+1][i] = f_ints[jfit][i];
    }
    /* f_t0[jfit+1] = f_t0[jfit]; */
    f_t0[jfit+1] = f_t0[best];
    nints[jfit+1] = nints[jfit];
    jfit++;
    chisq[jfit] = fitter(asig, &f_bsig[jfit], f_ints[jfit], &f_t0[jfit], nints[jfit], 0);
    if (chisq[jfit] < PENALTY4 * chisq[best]) best = jfit;

    if (!quiet) {
      printf("**>>> jint, jfit, best, chisq[best], nints[best] : %d %d %d %f %d\n",
	     jint, jfit, best, chisq[best], nints[best]);
    }
    jfit++;
  }

  if (coalesce) {
    /* Try coalescing interactions, accepting/rejecting by chisq value */
    /* loop throught the hit segments, looking for double interactions */
    for (jseg=0; jseg<nseg; jseg++) {
      m = n = -1;
      for (i = 0; i < nints[best]; i++) {
	f_ints[jfit][i] = f_ints[best][i];
	if (f_ints[best][i].seg == seg[jseg]) {
	  if (m < 0) {
	    m = i;
	  } else {
	    n = i;
	    break;
	  }
	}
      }
      if (n >= 0) {
	/* have found 2 interactions in this seg */
	if (!quiet)
	  printf("*** Try a coalescence fit for seg %d, ints %d, %d\n",
		 seg[jseg], m, n);
	e1 = f_ints[best][m].e;
	e2 = f_ints[best][n].e;
	f_ints[jfit][m].r = (e1*f_ints[best][m].r + e2*f_ints[best][n].r) / (e1+e2);
	f_ints[jfit][m].p = (e1*f_ints[best][m].p + e2*f_ints[best][n].p) / (e1+e2);
	f_ints[jfit][m].z = (e1*f_ints[best][m].z + e2*f_ints[best][n].z) / (e1+e2);
	f_ints[jfit][m].e = e1+e2;
	for (i = n; i < nints[best]-1; i++) {
	  f_ints[jfit][i] = f_ints[best][i+1];
	}
	f_t0[jfit] = f_t0[best];
	nints[jfit] = nints[best] - 1;

	chisq[jfit] = fitter(asig, &f_bsig[jfit], f_ints[jfit], &f_t0[jfit], nints[jfit], 0);
	if (PENALTY3 * chisq[jfit] <= chisq[best]) best = jfit;

	if (!quiet) {
	  printf("**>>> jfit, best, chisq[best], nints[best] : %d %d %f %d\n",
		 jfit, best, chisq[best], nints[best]);
	}
	jfit++;
      }
    }
  }

  /* do a final fit with tighter convergence criteria */
  for (i=0; i<nints[best]; i++) {
    f_ints[jfit][i] = f_ints[best][i];
  }
  f_t0[jfit] = f_t0[best];
  nints[jfit] = nints[best];
  chisq[jfit] = fitter(asig, &f_bsig[jfit], f_ints[jfit], &f_t0[jfit], nints[jfit], 1);
  if (chisq[jfit] < chisq[best]) best = jfit;
  
  *bsig = f_bsig[best];
  *t0 = f_t0[best];
  *chisq_out = chisq[best];
  for (i=0; i<nints[best]; i++) {
    ints[i] = f_ints[best][i];
  }

  return nints[best];
} /* decompose_n */
예제 #4
0
int decompose_1(const Event_Signal *asig,  /* observed signals */
		Event_Signal *bsig, /* fitted signals */
		int seg, Interaction *ints, double *t0, double *chisq_out, /* parameters */
		int grid2, int fit0, int fit1, int fit2, int fit3,         /* control */
		int fit4, int final_fit, int coalesce, double min_e_fraction)  /* control */
{
	
  /*
    performs the adaptive grid search algorithm for single-segment events,
    optionally followed by constrained least-squares
    
    returns number of best-fit interactions found
    ints[] array is set to contain the resulting best-fit double-interaction
    grid2, fit0, fit1, fit2, fit3, fit4, final_fit and coalesce control what parts
    of the decomposition algorithm get run
  */
  
  double chisq0, chisq2, chisq_cg;
  int    i, j, k, m, n, best = 0, best2, shift_t0 = 0, nints = 0;
  float  e1, e2;
  Event_Signal  asig_temp;
  Interaction   f_ints[11][4];     /* test/fitted interactions */
  Event_Signal  f_bsig[11];        /* calculated/fitted event data */
  double        f_t0[11], chisq[11];

  *t0 = 0.0;
  ints[2].seg = seg;
  ints[2].e   = 0.0;
  chisq2 = 100.0;
  for (i=0; i<7; i++) {
    chisq[i] = 100.0;
    f_t0[i] = 0.0;
  }
  if (fit0) grid2 = 0;
  
  memset(f_ints, 0, 7 * 4 * sizeof(Interaction));
  
  /* start off with a simple 1-interaction fit */
  if (fit0) {
    f_ints[6][0].seg = seg;
    f_ints[6][0].pos = -1;
    f_ints[6][0].r   = maxir[seg]/2;
    f_ints[6][0].p   = maxip[seg]/2;
    f_ints[6][0].z   = maxiz[seg]/2;
    f_ints[6][0].e   = 1.0;
    f_ints[6][1].seg = seg;
    f_ints[6][1].e   = 0.0;
    f_t0[6] = 3;   /* NOTE Changed, was f_t0[6] = 0 */
    chisq[6] = fitter(asig, &f_bsig[6], f_ints[6], &f_t0[6], 1, 0);
    best = 6;

    /* shift the remaining signal to bring t0 close to zero */
    asig_temp = *asig;
    shift_t0 = f_t0[best] - 0.0;
    if (shift_t0 > 0) {
      if (!quiet) printf("*----* shifting t0 by %d\n", shift_t0);
      for (i=0; i<MEAS_SEGS; i++) {
	for (j=0; j<TIME_STEPS-shift_t0; j++) {
	  asig_temp.signal[i][j] = asig_temp.signal[i][j+shift_t0];
	}
	for (j=TIME_STEPS-shift_t0; j<TIME_STEPS-1; j++) {
	  asig_temp.signal[i][j] = asig_temp.signal[i][TIME_STEPS-1];
	}
      }
    } else {
      shift_t0 = 0;
    }
    
    /* do the grid search over the course grid for the hit segment */
    chisq_cg = coarse_grid_1(&asig_temp, seg, f_ints[0], &chisq0, min_e_fraction);
    f_t0[0] = shift_t0;
    chisq[0] = eval_int_pos(asig, bsig, f_ints[0], f_t0[0], 2);
    if (chisq[0] < PENALTY1 * chisq[best]) best = 0;
    
  } else {

    /* do the grid search over the course grid for the hit segment */
    /* NOTE could guess that t0 is 2 or 3, rather than zero, at this point */
    chisq_cg = coarse_grid_1(asig, seg, f_ints[0], &chisq0, min_e_fraction);
    chisq[0] = eval_int_pos(asig, bsig, f_ints[0], f_t0[0], 2);
  }
  if (!quiet) {
    printf("** grid1: seg, chisq, pars: %2d, %7.4f, %7.4f", seg, chisq_cg, chisq[0]);
    for (i=0; i<2; i++) printf(", %6.3f %6.3f %6.3f %6.3f",
			       f_ints[0][i].r, f_ints[0][i].p,
			       f_ints[0][i].z, f_ints[0][i].e);
    printf("\n");
  }
  
  if (fit1) {
    /* do nonlinear least-squares fit
       starting from coarse grid point pair with lowest chisq */
    f_ints[1][0] = f_ints[0][0];
    f_ints[1][1] = f_ints[0][1];
    f_t0[1] = f_t0[0] - 1.0;
    if (f_t0[1] < 0.0) f_t0[1] = 0.0;
    chisq[1] = fitter(asig, &f_bsig[1], f_ints[1], &f_t0[1], 2, 0);
    if (chisq[1] < PENALTY1 * chisq[best]) best = 1;
  }

  if (fit2 && f_ints[0][2].pos >= 0 && f_ints[0][3].pos >= 0) {
    /* try nonlinear least-squares fit
       starting from coarse grid point pair with second best chisq */
    f_ints[2][0] = f_ints[0][2];
    f_ints[2][1] = f_ints[0][3];
    f_t0[2] = f_t0[0] - 1.0;
    if (f_t0[2] < 0.0) f_t0[2] = 0.0;
    chisq[2] = fitter(asig, &f_bsig[2], f_ints[2], &f_t0[2], 2, 0);
    if (chisq[2] < PENALTY1 * chisq[best]) best = 2;
  }

  if (grid2) {
    /* now do adaptive part of AGS,
       i.e. check neighboring sites on fine grid */
    chisq2 = refine_grid_1(asig, chisq_cg, chisq0, min_e_fraction, f_ints[0]);
    if (chisq2 < chisq_cg - 0.00000001) {
      chisq[0] = eval_int_pos(asig, bsig, f_ints[0], *t0, 2);
      if (!quiet) printf("** fine_grid1: seg, chisq: %2d, %7.4f, %7.4f\n", seg, chisq2, chisq[0]);
      if (chisq[0] < PENALTY1 * chisq[best]) best = 0;
      if (fit3) {
	/* try nonlinear least-squares fit
	   starting from new fine grid point pair */
	f_ints[3][0] = f_ints[0][0];
	f_ints[3][1] = f_ints[0][1];
	chisq[3] = fitter(asig, &f_bsig[3], f_ints[3], &f_t0[3], 2, 0);
	if (chisq[3] < PENALTY1 * chisq[best]) best = 3;
      }
    }
  }

  /*  if (fit4 && asig->seg_energy[seg] > 400.0 && chisq[best] > 0.028) {  NOTE hardwire limit */
    if (fit4 && asig->seg_energy[seg] > 150.0) {  /* NOTE hardwire limit */
    if (!quiet) printf("*** trying a fit with 3 interactions...\n");
    if (best == 6) {
      j = 0;
      if (chisq[1] < chisq[j]) j = 1;
      if (chisq[2] < chisq[j]) j = 2;
      if (chisq[3] < chisq[j]) j = 3;
    } else {
      j = best;
    }
    f_ints[4][0] = f_ints[j][0];
    f_ints[4][1] = f_ints[j][1];
    f_ints[4][2].seg = seg;
    f_ints[4][2].pos = -1;
    f_ints[4][2].r   = maxir[seg]/2;
    f_ints[4][2].p   = maxip[seg]/2;
    f_ints[4][2].z   = maxiz[seg]/2;
    f_ints[4][2].e   = asig->seg_energy[seg] / (3.0*asig->total_energy);
    f_t0[4] = f_t0[j];
    chisq[4] = fitter(asig, &f_bsig[4], f_ints[4], &f_t0[4], 3, 0);
    if (chisq[4] < PENALTY2 * chisq[best]) best = 4;
  }

  if (coalesce) {
    /* Try coalescing interactions, accepting/rejecting by chisq value */
    nints = 2;
    if (best == 4) {
      nints = 3;
    } else if (best == 6) {
      nints = 1;
    }
    best2 = best;
    if (nints == 3) {
      if (!quiet) printf("*** trying coalescence fits with 2 interactions...\n");
      for (j=7; j<10; j++) {
	if (j == 7) {
	  k=0; m=1; n=2;
	} else if (j == 8) {
	  k=1; m=0; n=2;
	} else {
	  k=2; m=1; n=0;
	}
	e1 = f_ints[best][m].e;
	e2 = f_ints[best][n].e;

	f_ints[j][0] = f_ints[best][k];
	f_ints[j][1] = f_ints[best][m];
	f_ints[j][1].r = (e1*f_ints[best][m].r + e2*f_ints[best][n].r) / (e1+e2);
	f_ints[j][1].p = (e1*f_ints[best][m].p + e2*f_ints[best][n].p) / (e1+e2);
	f_ints[j][1].z = (e1*f_ints[best][m].z + e2*f_ints[best][n].z) / (e1+e2);
	f_ints[j][1].e = e1+e2;
	f_t0[j] = f_t0[best];

	chisq[j] = fitter(asig, &f_bsig[j], f_ints[j], &f_t0[j], 2, 0);
	if (chisq[j] < chisq[best2]) best2 = j;
      }
      if (best2 != best && PENALTY2 * chisq[best2] <= chisq[best]) {
	best = best2;
	nints = 2;
      }
    }
	
    if (nints == 2) {
      if (!quiet) printf("*** trying coalescence fit with 1 interaction...\n");
      e1 = f_ints[best][0].e;
      e2 = f_ints[best][1].e;

      f_ints[10][0] = f_ints[best][0];
      f_ints[10][0].r = (e1*f_ints[best][0].r + e2*f_ints[best][1].r) / (e1+e2);
      f_ints[10][0].p = (e1*f_ints[best][0].p + e2*f_ints[best][1].p) / (e1+e2);
      f_ints[10][0].z = (e1*f_ints[best][0].z + e2*f_ints[best][1].z) / (e1+e2);
      f_ints[10][0].e = e1+e2;
      f_t0[10] = f_t0[best];

      chisq[10] = fitter(asig, &f_bsig[10], f_ints[10], &f_t0[10], 1, 0);

      if (PENALTY1 * chisq[10] <= chisq[best]) {
	best = 10;
	nints = 1;
      }
    }
  }

  /* decide which part of the algorithm gave the best chi-squared
     and, if necessary, finish up the nonlinear least-squares fit
     with more stringent convergence requirements */
  if (!quiet) printf(">>> g f1 f2 f3, best: %.4f %.4f %.4f %.4f %.4f %.4f, %.4f\n",
		     chisq[0], chisq[1], chisq[2], chisq[3],
		     chisq[4], chisq[6], chisq[best]);

  ints[0] = f_ints[best][0];
  ints[1] = f_ints[best][1];
  *t0 = f_t0[best];
  *chisq_out = chisq[best];
  nints = 2;
  if (best == 0) {
    if (!quiet) {  /* calculate bsig for matrix */
      chisq2 = eval_int_pos(asig, bsig, ints, *t0, 2);
      if (fabsf(chisq2 - chisq[best]) > 0.000001)
	printf("**** ACK!! best_chisq != eval_int_pos(); %f %f\n",
	       chisq[best], chisq2);
    }
  } else {
    if (best == 4) {
      nints = 3;
      ints[2] = f_ints[best][2];
    } else if (best == 6 || best == 10) {
      nints = 1;
    }
    if (final_fit) {
      *chisq_out = fitter(asig, bsig, ints, t0, nints, 1);
    } else {
      *bsig = f_bsig[best];
    }
  }

  return nints;
} /* decompose_1 */
void ChebyshevFitterTest::testConstructor() {
	ims::ChebyshevFitter fitter(2);
	CPPUNIT_ASSERT_EQUAL((size_t)2, fitter.getDegree());
}
void BSplineSurfaceFitterWindow::CreateScene()
{
    // Begin with a flat 64x64 height field.
    int const numSamples = 64;
    float const extent = 8.0f;
    VertexFormat hfformat;
    hfformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0);
    hfformat.Bind(VA_TEXCOORD, DF_R32G32_FLOAT, 0);
    MeshFactory mf;
    mf.SetVertexFormat(hfformat);
    mHeightField = mf.CreateRectangle(numSamples, numSamples, extent, extent);
    int numVertices = numSamples * numSamples;
    VertexPT* hfvertices = mHeightField->GetVertexBuffer()->Get<VertexPT>();

    // Set the heights based on a precomputed height field.  Also create a
    // texture image to go with the height field.
    std::string path = mEnvironment.GetPath("BTHeightField.png");
    std::shared_ptr<Texture2> texture(WICFileIO::Load(path, false));
    std::shared_ptr<Texture2Effect> txeffect =
        std::make_shared<Texture2Effect>(mProgramFactory, texture,
        SamplerState::MIN_L_MAG_L_MIP_P, SamplerState::CLAMP,
        SamplerState::CLAMP);
    mHeightField->SetEffect(txeffect);

    std::mt19937 mte;
    std::uniform_real_distribution<float> symmr(-0.05f, 0.05f);
    std::uniform_real_distribution<float> intvr(32.0f, 64.0f);
    unsigned char* data = (unsigned char*)texture->Get<unsigned char>();
    std::vector<Vector3<float>> samplePoints(numVertices);
    for (int i = 0; i < numVertices; ++i)
    {
        unsigned char value = *data;
        float height = 3.0f*((float)value) / 255.0f + symmr(mte);
        *data++ = (unsigned char)intvr(mte);
        *data++ = 3 * (128 - value / 2) / 4;
        *data++ = 0;
        data++;

        hfvertices[i].position[2] = height;
        samplePoints[i] = hfvertices[i].position;
    }

    // Compute a B-Spline surface with NxN control points, where N < 64.
    // This surface will be sampled to 64x64 and displayed together with the
    // original height field for comparison.
    int const numControls = 32;
    int const degree = 3;
    BSplineSurfaceFit<float> fitter(degree, numControls, numSamples, degree,
        numControls, numSamples, &samplePoints[0]);

    VertexFormat ffformat;
    ffformat.Bind(VA_POSITION, DF_R32G32B32_FLOAT, 0);
    ffformat.Bind(VA_COLOR, DF_R32G32B32A32_FLOAT, 0);
    mf.SetVertexFormat(ffformat);
    mFittedField = mf.CreateRectangle(numSamples, numSamples, extent, extent);
    VertexPC* ffvertices = mFittedField->GetVertexBuffer()->Get<VertexPC>();

    Vector4<float> translucent{ 1.0f, 1.0f, 1.0f, 0.5f };
    for (int i = 0; i < numVertices; ++i)
    {
        float u = 0.5f*(ffvertices[i].position[0] / extent + 1.0f);
        float v = 0.5f*(ffvertices[i].position[1] / extent + 1.0f);
        ffvertices[i].position = fitter.GetPosition(u, v);
        ffvertices[i].color = translucent;
    }

    std::shared_ptr<VertexColorEffect> vceffect =
        std::make_shared<VertexColorEffect>(mProgramFactory);
    mFittedField->SetEffect(vceffect);

    mCameraRig.Subscribe(mHeightField->worldTransform,
        txeffect->GetPVWMatrixConstant());
    mCameraRig.Subscribe(mFittedField->worldTransform,
        vceffect->GetPVWMatrixConstant());

    mTrackball.Attach(mHeightField);
    mTrackball.Attach(mFittedField);
    mTrackball.Update();
}
예제 #7
0
/*!
  Draw the shape item

  \param painter Painter
  \param xMap X-Scale Map
  \param yMap Y-Scale Map
  \param canvasRect Contents rect of the plot canvas
*/
void QwtPlotShapeItem::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    if ( d_data->shape.isEmpty() )
        return;

    if ( d_data->pen.style() == Qt::NoPen 
        && d_data->brush.style() == Qt::NoBrush )
    {
        return;
    }

    const QRectF cRect = QwtScaleMap::invTransform(
        xMap, yMap, canvasRect.toRect() );

    if ( d_data->boundingRect.intersects( cRect ) )
    {
        const bool doAlign = QwtPainter::roundingAlignment( painter );

        QPainterPath path = qwtTransformPath( xMap, yMap, 
            d_data->shape, doAlign );

        if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) )
        {
            qreal pw = qMax( qreal( 1.0 ), painter->pen().widthF());
            QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );

            QPainterPath clippedPath;
            clippedPath.setFillRule( path.fillRule() );

            const QList<QPolygonF> polygons = path.toSubpathPolygons();
            for ( int i = 0; i < polygons.size(); i++ )
            {
                const QPolygonF p = QwtClipper::clipPolygonF(
                    clipRect, polygons[i], true );

                clippedPath.addPolygon( p );

            }

            path = clippedPath;
        }

        if ( d_data->renderTolerance > 0.0 )
        {
            QwtWeedingCurveFitter fitter( d_data->renderTolerance );

            QPainterPath fittedPath;
            fittedPath.setFillRule( path.fillRule() );

            const QList<QPolygonF> polygons = path.toSubpathPolygons();
            for ( int i = 0; i < polygons.size(); i++ )
                fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) );

            path = fittedPath;
        }

        painter->setPen( d_data->pen );
        painter->setBrush( d_data->brush );

        painter->drawPath( path );
    }
}
예제 #8
0
//----------------------------------------------------------------------------
void BSplineSurfaceFitter::CreateScene ()
{
	mScene = new0 Node();
	mWireState = new0 WireState();
	mRenderer->SetOverrideWireState(mWireState);
	mCullState = new0 CullState();
	mCullState->Enabled = false;
	mRenderer->SetOverrideCullState(mCullState);

	// Begin with a flat 64x64 height field.
	const int numSamples = 64;
	const float extent = 8.0f;
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);
	mHeightField = StandardMesh(vformat).Rectangle(numSamples, numSamples,
	               extent, extent);
	mScene->AttachChild(mHeightField);

	// Set the heights based on a precomputed height field.  Also create a
	// texture image to go with the height field.
	std::string path = Environment::GetPathR("HeightField.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	VisualEffectInstance* instance = Texture2DEffect::CreateUniqueInstance(
	                                     texture, Shader::SF_LINEAR, Shader::SC_CLAMP_EDGE,
	                                     Shader::SC_CLAMP_EDGE);
	mHeightField->SetEffectInstance(instance);
	unsigned char* data = (unsigned char*)texture->GetData(0);

	VertexBufferAccessor vba(mHeightField);
	Vector3f** samplePoints = new2<Vector3f>(numSamples, numSamples);
	int i;
	for (i = 0; i < vba.GetNumVertices(); ++i)
	{
		unsigned char value = *data;
		float height = 3.0f*((float)value)/255.0f +
		               0.05f*Mathf::SymmetricRandom();

		*data++ = (unsigned char)Mathf::IntervalRandom(32.0f, 64.0f);
		*data++ = 3*(128 - value/2)/4;
		*data++ = 0;
		data++;

		vba.Position<Vector3f>(i).Z() = height;
		samplePoints[i % numSamples][i / numSamples] =
		    vba.Position<Vector3f>(i);
	}

	// Compute a B-Spline surface with NxN control points, where N < 64.
	// This surface will be sampled to 64x64 and displayed together with the
	// original height field for comparison.
	const int numCtrlPoints = 32;
	const int degree = 3;
	BSplineSurfaceFitf fitter(degree, numCtrlPoints, numSamples, degree,
	                          numCtrlPoints, numSamples, samplePoints);
	delete2(samplePoints);

	vformat = VertexFormat::Create(2,
	                               VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                               VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT4, 0);
	mFittedField = StandardMesh(vformat).Rectangle(numSamples, numSamples,
	               extent, extent);
	mScene->AttachChild(mFittedField);

	vba.ApplyTo(mFittedField);
	Float4 translucent(1.0f, 1.0f, 1.0f, 0.5f);
	for (i = 0; i < vba.GetNumVertices(); ++i)
	{
		float u = 0.5f*(vba.Position<Vector3f>(i).X()/extent + 1.0f);
		float v = 0.5f*(vba.Position<Vector3f>(i).Y()/extent + 1.0f);
		vba.Position<Vector3f>(i) = fitter.GetPosition(u, v);
		vba.Color<Float4>(0,i) = translucent;
	}

	instance = VertexColor4Effect::CreateUniqueInstance();
	mFittedField->SetEffectInstance(instance);
	instance->GetEffect()->GetAlphaState(0, 0)->BlendEnabled = true;
}
예제 #9
0
/*!
  Draw the shape item

  \param painter Painter
  \param xMap X-Scale Map
  \param yMap Y-Scale Map
  \param canvasRect Contents rect of the plot canvas
*/
void QwtPlotShapeItem::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    if ( d_data->shape.isEmpty() )
        return;

    if ( d_data->pen.style() == Qt::NoPen
        && d_data->brush.style() == Qt::NoBrush )
    {
        return;
    }

    const QRectF cr = QwtScaleMap::invTransform(
        xMap, yMap, canvasRect.toRect() );

    const QRectF &br = d_data->boundingRect;

    if ( ( br.left() > cr.right() ) || ( br.right() < cr.left() )
        || ( br.top() > cr.bottom() ) || ( br.bottom() < cr.top() ) )
    {
        // outside the visisble area
        return;
    }

    const bool doAlign = QwtPainter::roundingAlignment( painter );

    QPainterPath path = qwtTransformPath( xMap, yMap,
        d_data->shape, doAlign );

    if ( testPaintAttribute( QwtPlotShapeItem::ClipPolygons ) )
    {
        const qreal pw = QwtPainter::effectivePenWidth( painter->pen() );
        const QRectF clipRect = canvasRect.adjusted( -pw, -pw, pw, pw );

        QPainterPath clippedPath;
        clippedPath.setFillRule( path.fillRule() );

        QList<QPolygonF> polygons = path.toSubpathPolygons();
        for ( int i = 0; i < polygons.size(); i++ )
        {
            QwtClipper::clipPolygonF( clipRect, polygons[i], true );
            clippedPath.addPolygon( polygons[i] );

        }

        path = clippedPath;
    }

    if ( d_data->renderTolerance > 0.0 )
    {
        QwtWeedingCurveFitter fitter( d_data->renderTolerance );

        QPainterPath fittedPath;
        fittedPath.setFillRule( path.fillRule() );

        const QList<QPolygonF> polygons = path.toSubpathPolygons();
        for ( int i = 0; i < polygons.size(); i++ )
            fittedPath.addPolygon( fitter.fitCurve( polygons[ i ] ) );

        path = fittedPath;
    }

    painter->setPen( d_data->pen );
    painter->setBrush( d_data->brush );

    painter->drawPath( path );
}
예제 #10
0
void ana_complete(int nevts=0)
{
        TDatabasePDG::Instance()->AddParticle("pbarpSystem","pbarpSystem",1.9,kFALSE,0.1,0,"",88888);
        TStopwatch fTimer;
	// *** some variables
	int i=0,j=0, k=0, l=0;
	gStyle->SetOptFit(1011);
	
	// *** the output file for FairRunAna
	TString OutFile="output.root";  
					
	// *** the files coming from the simulation
	TString inPidFile  = "psi2s_jpsi2pi_jpsi_mumu_pid.root";    // this file contains the PndPidCandidates and McTruth
	TString inParFile  = "psi2s_jpsi2pi_jpsi_mumu_par.root";
	
	// *** PID table with selection thresholds; can be modified by the user
	TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all_day1.par";	
	
	// *** initialization
	FairLogger::GetLogger()->SetLogToFile(kFALSE);
	FairRunAna* fRun = new FairRunAna();
	FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
	fRun->SetInputFile(inPidFile);
	
	// *** setup parameter database 	
	FairParRootFileIo* parIO = new FairParRootFileIo();
	parIO->open(inParFile);
	FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
	parIOPid->open(pidParFile.Data(),"in");
	
	rtdb->setFirstInput(parIO);
	rtdb->setSecondInput(parIOPid);
	rtdb->setOutput(parIO);  
	
	fRun->SetOutputFile(OutFile);
	fRun->Init(); 
	
        // *** create an output file for all histograms
	TFile *out = TFile::Open("output_ana.root","RECREATE");
	
	// *** create some histograms
	TH1F *hmomtrk    = new TH1F("hmomtrk","track momentum (all)",200,0,5);
	TH1F *hthttrk    = new TH1F("hthttrk","track theta (all)",200,0,3.1415);
	
	TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5);
	TH1F *hpsim_all  = new TH1F("hpsim_all","#psi(2S) mass (all)",200,0,5);
	
	TH1F *hjpsim_lpid = new TH1F("hjpsim_lpid","J/#psi mass (loose pid)",200,0,4.5);
	TH1F *hpsim_lpid  = new TH1F("hpsim_lpid","#psi(2S) mass (loose pid)",200,0,5);
	
	TH1F *hjpsim_tpid = new TH1F("hjpsim_tpid","J/#psi mass (tight pid)",200,0,4.5);
	TH1F *hpsim_tpid  = new TH1F("hpsim_tpid","#psi(2S) mass (tight pid)",200,0,5);
	
	TH1F *hjpsim_trpid = new TH1F("hjpsim_trpid","J/#psi mass (true pid)",200,0,4.5);
	TH1F *hpsim_trpid  = new TH1F("hpsim_trpid","#psi(2S) mass (true pid)",200,0,5);
	
	
	TH1F *hjpsim_ftm = new TH1F("hjpsim_ftm","J/#psi mass (full truth match)",200,0,4.5);
	TH1F *hpsim_ftm  = new TH1F("hpsim_ftm","#psi(2S) mass (full truth match)",200,0,5);
	
	TH1F *hjpsim_nm = new TH1F("hjpsim_nm","J/#psi mass (no truth match)",200,0,4.5);
	TH1F *hpsim_nm  = new TH1F("hpsim_nm","#psi(2S) mass (no truth match)",200,0,5);
	
	TH1F *hjpsim_diff = new TH1F("hjpsim_diff","J/#psi mass diff to truth",100,-2,2);
	TH1F *hpsim_diff  = new TH1F("hpsim_diff","#psi(2S) mass diff to truth",100,-2,2);
	
	
	TH1F *hjpsim_vf   = new TH1F("hjpsim_vf","J/#psi mass (vertex fit)",200,0,4.5);
	TH1F *hjpsim_4cf  = new TH1F("hjpsim_4cf","J/#psi mass (4C fit)",200,0,4.5);
	TH1F *hjpsim_mcf  = new TH1F("hjpsim_mcf","J/#psi mass (mass constraint fit)",200,0,4.5);
	
	TH1F *hjpsi_chi2_vf  = new TH1F("hjpsi_chi2_vf", "J/#psi: #chi^{2} vertex fit",100,0,10);
	TH1F *hpsi_chi2_4c   = new TH1F("hpsi_chi2_4c",  "#psi(2S): #chi^{2} 4C fit",100,0,250);
	TH1F *hjpsi_chi2_mf  = new TH1F("hjpsi_chi2_mf", "J/#psi: #chi^{2} mass fit",100,0,10);
	
	TH1F *hjpsi_prob_vf  = new TH1F("hjpsi_prob_vf", "J/#psi: Prob vertex fit",100,0,1);
	TH1F *hpsi_prob_4c   = new TH1F("hpsi_prob_4c",  "#psi(2S): Prob 4C fit",100,0,1);
	TH1F *hjpsi_prob_mf  = new TH1F("hjpsi_prob_mf", "J/#psi: Prob mass fit",100,0,1);
	
	TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-2,2,100,-2,2);
	
	//
	// Now the analysis stuff comes...
	//
	
	
	// *** the data reader object
	PndAnalysis* theAnalysis = new PndAnalysis();
	if (nevts==0) nevts= theAnalysis->GetEntries();
	
	// *** RhoCandLists for the analysis
	RhoCandList chrg, muplus, muminus, piplus, piminus, jpsi, psi2s;
	
	// *** Mass selector for the jpsi cands
	double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass();   // Get nominal PDG mass of the J/psi
	RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
	
	// *** the lorentz vector of the initial psi(2S)
	TLorentzVector ini(0, 0, 6.231552, 7.240065);
	
	// ***
	// the event loop
	// ***
	
	int cntdbltrk=0, cntdblmc=0, cntdblboth=0, cnttrk=0, cnt_dbl_jpsi=0, cnt_dbl_psip=0;
	
	while (theAnalysis->GetEvent() && i++<nevts)
	{
		if ((i%100)==0) cout<<"evt " << i << endl;
				
		// *** Select with no PID info ('All'); type and mass are set 		
		theAnalysis->FillList(chrg,    "Charged");
		theAnalysis->FillList(muplus,  "MuonAllPlus");
		theAnalysis->FillList(muminus, "MuonAllMinus");
		theAnalysis->FillList(piplus,  "PionAllPlus");
		theAnalysis->FillList(piminus, "PionAllMinus");

		// *** momentum and theta histograms
		for (j=0;j<muplus.GetLength();++j) 
		{
			hmomtrk->Fill(muplus[j]->P());
			hthttrk->Fill(muplus[j]->P4().Theta());
		}
		for (j=0;j<muminus.GetLength();++j) 
		{
			hmomtrk->Fill(muminus[j]->P());
			hthttrk->Fill(muminus[j]->P4().Theta());
		}
		
		cnttrk += chrg.GetLength();
		
		int n1, n2, n3;
		
		countDoubles(chrg,n1,n2,n3);
		cntdbltrk  += n1;
		cntdblmc   += n2;
		cntdblboth += n3;		
		
		// *** combinatorics for J/psi -> mu+ mu-
		jpsi.Combine(muplus, muminus);
		
		
		// ***
		// *** do the TRUTH MATCH for jpsi
		// ***
		jpsi.SetType(443);
				
		int nm = 0;
		for (j=0;j<jpsi.GetLength();++j) 
		{
			hjpsim_all->Fill( jpsi[j]->M() );
			
			if (theAnalysis->McTruthMatch(jpsi[j]))
			{ 
				nm++;
				hjpsim_ftm->Fill( jpsi[j]->M() );
			 	hjpsim_diff->Fill( jpsi[j]->GetMcTruth()->M() - jpsi[j]->M() );
			}
			else 
				hjpsim_nm->Fill( jpsi[j]->M() );
		}
		
		if (nm>1) cnt_dbl_jpsi++;
		// ***
		// *** do VERTEX FIT (J/psi)
		// ***
		for (j=0;j<jpsi.GetLength();++j) 
		{
			PndKinVtxFitter vtxfitter(jpsi[j]);	// instantiate a vertex fitter
			vtxfitter.Fit();
			
			double chi2_vtx = vtxfitter.GetChi2();	// access chi2 of fit
			double prob_vtx = vtxfitter.GetProb();	// access probability of fit
			hjpsi_chi2_vf->Fill(chi2_vtx);
			hjpsi_prob_vf->Fill(prob_vtx);			
			
			if ( prob_vtx > 0.01 )				// when good enough, fill some histos
			{
				RhoCandidate *jfit = jpsi[j]->GetFit();	// access the fitted cand
				TVector3 jVtx=jfit->Pos();		// and the decay vertex position
				
				hjpsim_vf->Fill(jfit->M());            
				hvpos->Fill(jVtx.X(),jVtx.Y());
			}
		}
		
		// *** some rough mass selection
		jpsi.Select(jpsiMassSel);
		
		// *** combinatorics for psi(2S) -> J/psi pi+ pi-
		psi2s.Combine(jpsi, piplus, piminus);
		
		
		// ***
		// *** do the TRUTH MATCH for psi(2S)
		// ***
		psi2s.SetType(88888);

		nm = 0;
		for (j=0;j<psi2s.GetLength();++j) 
		{
			hpsim_all->Fill( psi2s[j]->M() );
			
			if (theAnalysis->McTruthMatch(psi2s[j])) 
			{
				nm++;
			 	hpsim_ftm->Fill( psi2s[j]->M() );
			 	hpsim_diff->Fill( psi2s[j]->GetMcTruth()->M() - psi2s[j]->M() );
			}
			else 
				hpsim_nm->Fill( psi2s[j]->M() );
		}			
		if (nm>1) cnt_dbl_psip++;

		
		// ***
		// *** do 4C FIT (initial psi(2S) system)
		// ***
		for (j=0;j<psi2s.GetLength();++j) 
		{
			PndKinFitter fitter(psi2s[j]);	// instantiate the kin fitter in psi(2S)
			fitter.Add4MomConstraint(ini);	// set 4 constraint
			fitter.Fit();		            // do fit
			
			double chi2_4c = fitter.GetChi2();	// get chi2 of fit
			double prob_4c = fitter.GetProb();	// access probability of fit
			hpsi_chi2_4c->Fill(chi2_4c);
			hpsi_prob_4c->Fill(prob_4c);			
			
			if ( prob_4c > 0.01 )			// when good enough, fill some histo
			{
				RhoCandidate *jfit = psi2s[j]->Daughter(0)->GetFit();	// get fitted J/psi
				
				hjpsim_4cf->Fill(jfit->M());
			}
		}		
		
		
		// ***
		// *** do MASS CONSTRAINT FIT (J/psi)
		// ***
		for (j=0;j<jpsi.GetLength();++j) 
		{
			PndKinFitter mfitter(jpsi[j]);		// instantiate the PndKinFitter in psi(2S)
			mfitter.AddMassConstraint(m0_jpsi);	// add the mass constraint
			mfitter.Fit();						// do fit
			
			double chi2_m = mfitter.GetChi2();	// get chi2 of fit
			double prob_m = mfitter.GetProb();	// access probability of fit
			hjpsi_chi2_mf->Fill(chi2_m);
			hjpsi_prob_mf->Fill(prob_m);			
			
			if ( prob_m > 0.01 )				// when good enough, fill some histo
			{
				RhoCandidate *jfit = jpsi[j]->GetFit();	// access the fitted cand
				hjpsim_mcf->Fill(jfit->M());
			}
		}		
		
		
		// ***
		// *** TRUE PID combinatorics
		// ***
		
		// *** do MC truth match for PID type
		SelectTruePid(theAnalysis, muplus);
		SelectTruePid(theAnalysis, muminus);
		SelectTruePid(theAnalysis, piplus);
		SelectTruePid(theAnalysis, piminus);
				
		// *** all combinatorics again with true PID
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_trpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_trpid->Fill( psi2s[j]->M() );
		
		
		// ***
		// *** LOOSE PID combinatorics
		// ***
		
		// *** and again with PidAlgoMvd;PidAlgoStt;PidAlgoDrc and loose selection
		theAnalysis->FillList(muplus,  "MuonLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc;PidAlgoMdtHardCuts");
		theAnalysis->FillList(muminus, "MuonLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc;PidAlgoMdtHardCuts");
		theAnalysis->FillList(piplus,  "PionLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_lpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_lpid->Fill( psi2s[j]->M() );
		
		
		// ***
		// *** TIGHT PID combinatorics
		// ***
		
		// *** and again with PidAlgoMvd;PidAlgoStt and tight selection
		theAnalysis->FillList(muplus,  "MuonTightPlus",  "PidAlgoMdtHardCuts");
		theAnalysis->FillList(muminus, "MuonTightMinus", "PidAlgoMdtHardCuts");
		theAnalysis->FillList(piplus,  "PionLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_tpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_tpid->Fill( psi2s[j]->M() );
		
	}
		
	// *** write out all the histos
	out->cd();
	
	hmomtrk->Write();
	hthttrk->Write();
	
	hjpsim_all->Write();
	hpsim_all->Write();
	hjpsim_lpid->Write();
	hpsim_lpid->Write();
	hjpsim_tpid->Write();
	hpsim_tpid->Write();
	hjpsim_trpid->Write();
	hpsim_trpid->Write();
	
	hjpsim_ftm->Write();
	hpsim_ftm->Write();
	hjpsim_nm->Write();
	hpsim_nm->Write();
	
	hpsim_diff->Write();
	hjpsim_diff->Write();
	
	hjpsim_vf->Write();
	hjpsim_4cf->Write();
	hjpsim_mcf->Write();
	
	hjpsi_chi2_vf->Write();
	hpsi_chi2_4c->Write();
	hjpsi_chi2_mf->Write();
			
	hjpsi_prob_vf->Write();
	hpsi_prob_4c->Write();
	hjpsi_prob_mf->Write();
			
	hvpos->Write();
		
	out->Save();
        
	// Extract the maximal used memory an add is as Dart measurement
	// This line is filtered by CTest and the value send to CDash
	FairSystemInfo sysInfo;
	Float_t maxMemory=sysInfo.GetMaxMemory();
	cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
	cout << maxMemory;
	cout << "</DartMeasurement>" << endl;
  
	fTimer.Stop();
	Double_t rtime = fTimer.RealTime();
	Double_t ctime = fTimer.CpuTime();
  
	Float_t cpuUsage=ctime/rtime;
	cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
	cout << cpuUsage;
	cout << "</DartMeasurement>" << endl;
  
	cout << endl;
	cout << "Real time " << rtime << " s, CPU time " << ctime
		  << "s" << endl;
	cout << "CPU usage " << cpuUsage*100. << "%" << endl;
	cout << "Max Memory " << maxMemory << " MB" << endl;
   
	cout << "Macro finished successfully." << endl;

        exit(0);
	
}
예제 #11
0
void ana_complete(int nevts=0)
{
    //-----User Settings:------------------------------------------------------
  TString  parAsciiFile   = "all.par";
  TString  prefix         = "evtcomplete";
  TString  input          = "psi2s_Jpsi2pi_Jpsi_mumu.dec"; 
  TString  output         = "ana";
  TString  friend1        = "pid";
  TString  friend2        = "";
  TString  friend3        = "";
  TString  friend4        = "";
  
  // -----   Initial Settings   --------------------------------------------
  PndMasterRunAna *fRun= new PndMasterRunAna();
  fRun->SetInput(input);
  fRun->SetOutput(output);
  fRun->SetFriend1(friend1);
  fRun->SetFriend2(friend2);
  fRun->SetFriend3(friend3);
  fRun->SetFriend4(friend4);
  fRun->SetParamAsciiFile(parAsciiFile);
  fRun->Setup(prefix);
        
	// *** some variables
	int i=0,j=0, k=0, l=0;
	gStyle->SetOptFit(1011);

	fRun->Init(); 
	
        // *** create an output file for all histograms
	TFile *out = TFile::Open(prefix+"_output_ana.root","RECREATE");
	
	// *** create some histograms
	TH1F *hmomtrk    = new TH1F("hmomtrk","track momentum (all)",200,0,5);
	TH1F *hthttrk    = new TH1F("hthttrk","track theta (all)",200,0,3.1415);
	
	TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5);
	TH1F *hpsim_all  = new TH1F("hpsim_all","#psi(2S) mass (all)",200,0,5);
	
	TH1F *hjpsim_lpid = new TH1F("hjpsim_lpid","J/#psi mass (loose pid)",200,0,4.5);
	TH1F *hpsim_lpid  = new TH1F("hpsim_lpid","#psi(2S) mass (loose pid)",200,0,5);
	
	TH1F *hjpsim_tpid = new TH1F("hjpsim_tpid","J/#psi mass (tight pid)",200,0,4.5);
	TH1F *hpsim_tpid  = new TH1F("hpsim_tpid","#psi(2S) mass (tight pid)",200,0,5);
	
	TH1F *hjpsim_trpid = new TH1F("hjpsim_trpid","J/#psi mass (true pid)",200,0,4.5);
	TH1F *hpsim_trpid  = new TH1F("hpsim_trpid","#psi(2S) mass (true pid)",200,0,5);
	
	
	TH1F *hjpsim_ftm = new TH1F("hjpsim_ftm","J/#psi mass (full truth match)",200,0,4.5);
	TH1F *hpsim_ftm  = new TH1F("hpsim_ftm","#psi(2S) mass (full truth match)",200,0,5);
	
	TH1F *hjpsim_nm = new TH1F("hjpsim_nm","J/#psi mass (no truth match)",200,0,4.5);
	TH1F *hpsim_nm  = new TH1F("hpsim_nm","#psi(2S) mass (no truth match)",200,0,5);
	
	TH1F *hjpsim_diff = new TH1F("hjpsim_diff","J/#psi mass diff to truth",100,-2,2);
	TH1F *hpsim_diff  = new TH1F("hpsim_diff","#psi(2S) mass diff to truth",100,-2,2);
	
	
	TH1F *hjpsim_vf   = new TH1F("hjpsim_vf","J/#psi mass (vertex fit)",200,0,4.5);
	TH1F *hjpsim_4cf  = new TH1F("hjpsim_4cf","J/#psi mass (4C fit)",200,0,4.5);
	TH1F *hjpsim_mcf  = new TH1F("hjpsim_mcf","J/#psi mass (mass constraint fit)",200,0,4.5);
	
	TH1F *hjpsi_chi2_vf  = new TH1F("hjpsi_chi2_vf", "J/#psi: #chi^{2} vertex fit",100,0,10);
	TH1F *hpsi_chi2_4c   = new TH1F("hpsi_chi2_4c",  "#psi(2S): #chi^{2} 4C fit",100,0,250);
	TH1F *hjpsi_chi2_mf  = new TH1F("hjpsi_chi2_mf", "J/#psi: #chi^{2} mass fit",100,0,10);
	
	TH1F *hjpsi_prob_vf  = new TH1F("hjpsi_prob_vf", "J/#psi: Prob vertex fit",100,0,1);
	TH1F *hpsi_prob_4c   = new TH1F("hpsi_prob_4c",  "#psi(2S): Prob 4C fit",100,0,1);
	TH1F *hjpsi_prob_mf  = new TH1F("hjpsi_prob_mf", "J/#psi: Prob mass fit",100,0,1);
	
	TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-2,2,100,-2,2);
	
	//
	// Now the analysis stuff comes...
	//
	
	
	// *** the data reader object
	PndAnalysis* theAnalysis = new PndAnalysis();
	if (nevts==0) nevts= theAnalysis->GetEntries();
	
	// *** RhoCandLists for the analysis
	RhoCandList chrg, muplus, muminus, piplus, piminus, jpsi, psi2s;
	
	// *** Mass selector for the jpsi cands
	double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass();   // Get nominal PDG mass of the J/psi
	RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
	
	// *** the lorentz vector of the initial psi(2S)
	TLorentzVector ini(0, 0, 6.231552, 7.240065);
	
	// ***
	// the event loop
	// ***
	
	int cntdbltrk=0, cntdblmc=0, cntdblboth=0, cnttrk=0, cnt_dbl_jpsi=0, cnt_dbl_psip=0;
	
	while (theAnalysis->GetEvent() && i++<nevts)
	{
		if ((i%100)==0) cout<<"evt " << i << endl;
				
		// *** Select with no PID info ('All'); type and mass are set 		
		theAnalysis->FillList(chrg,    "Charged");
		theAnalysis->FillList(muplus,  "MuonAllPlus");
		theAnalysis->FillList(muminus, "MuonAllMinus");
		theAnalysis->FillList(piplus,  "PionAllPlus");
		theAnalysis->FillList(piminus, "PionAllMinus");

		// *** momentum and theta histograms
		for (j=0;j<muplus.GetLength();++j) 
		{
			hmomtrk->Fill(muplus[j]->P());
			hthttrk->Fill(muplus[j]->P4().Theta());
		}
		for (j=0;j<muminus.GetLength();++j) 
		{
			hmomtrk->Fill(muminus[j]->P());
			hthttrk->Fill(muminus[j]->P4().Theta());
		}
		
		cnttrk += chrg.GetLength();
		
		int n1, n2, n3;
		
		countDoubles(chrg,n1,n2,n3);
		cntdbltrk  += n1;
		cntdblmc   += n2;
		cntdblboth += n3;		
		
		// *** combinatorics for J/psi -> mu+ mu-
		jpsi.Combine(muplus, muminus);
		
		
		// ***
		// *** do the TRUTH MATCH for jpsi
		// ***
		jpsi.SetType(443);
				
		int nm = 0;
		for (j=0;j<jpsi.GetLength();++j) 
		{
			hjpsim_all->Fill( jpsi[j]->M() );
			
			if (theAnalysis->McTruthMatch(jpsi[j]))
			{ 
				nm++;
				hjpsim_ftm->Fill( jpsi[j]->M() );
			 	hjpsim_diff->Fill( jpsi[j]->GetMcTruth()->M() - jpsi[j]->M() );
			}
			else 
				hjpsim_nm->Fill( jpsi[j]->M() );
		}
		
		if (nm>1) cnt_dbl_jpsi++;
		// ***
		// *** do VERTEX FIT (J/psi)
		// ***
		for (j=0;j<jpsi.GetLength();++j) 
		{
			PndKinVtxFitter vtxfitter(jpsi[j]);	// instantiate a vertex fitter
			vtxfitter.Fit();
			
			double chi2_vtx = vtxfitter.GetChi2();	// access chi2 of fit
			double prob_vtx = vtxfitter.GetProb();	// access probability of fit
			hjpsi_chi2_vf->Fill(chi2_vtx);
			hjpsi_prob_vf->Fill(prob_vtx);			
			
			if ( prob_vtx > 0.01 )				// when good enough, fill some histos
			{
				RhoCandidate *jfit = jpsi[j]->GetFit();	// access the fitted cand
				TVector3 jVtx=jfit->Pos();		// and the decay vertex position
				
				hjpsim_vf->Fill(jfit->M());            
				hvpos->Fill(jVtx.X(),jVtx.Y());
			}
		}
		
		// *** some rough mass selection
		jpsi.Select(jpsiMassSel);
		
		// *** combinatorics for psi(2S) -> J/psi pi+ pi-
		psi2s.Combine(jpsi, piplus, piminus);
		
		
		// ***
		// *** do the TRUTH MATCH for psi(2S)
		// ***
		psi2s.SetType(88888);

		nm = 0;
		for (j=0;j<psi2s.GetLength();++j) 
		{
			hpsim_all->Fill( psi2s[j]->M() );
			
			if (theAnalysis->McTruthMatch(psi2s[j])) 
			{
				nm++;
			 	hpsim_ftm->Fill( psi2s[j]->M() );
			 	hpsim_diff->Fill( psi2s[j]->GetMcTruth()->M() - psi2s[j]->M() );
			}
			else 
				hpsim_nm->Fill( psi2s[j]->M() );
		}			
		if (nm>1) cnt_dbl_psip++;

		
		// ***
		// *** do 4C FIT (initial psi(2S) system)
		// ***
		for (j=0;j<psi2s.GetLength();++j) 
		{
			PndKinFitter fitter(psi2s[j]);	// instantiate the kin fitter in psi(2S)
			fitter.Add4MomConstraint(ini);	// set 4 constraint
			fitter.Fit();		            // do fit
			
			double chi2_4c = fitter.GetChi2();	// get chi2 of fit
			double prob_4c = fitter.GetProb();	// access probability of fit
			hpsi_chi2_4c->Fill(chi2_4c);
			hpsi_prob_4c->Fill(prob_4c);			
			
			if ( prob_4c > 0.01 )			// when good enough, fill some histo
			{
				RhoCandidate *jfit = psi2s[j]->Daughter(0)->GetFit();	// get fitted J/psi
				
				hjpsim_4cf->Fill(jfit->M());
			}
		}		
		
		
		// ***
		// *** do MASS CONSTRAINT FIT (J/psi)
		// ***
		for (j=0;j<jpsi.GetLength();++j) 
		{
			PndKinFitter mfitter(jpsi[j]);		// instantiate the PndKinFitter in psi(2S)
			mfitter.AddMassConstraint(m0_jpsi);	// add the mass constraint
			mfitter.Fit();						// do fit
			
			double chi2_m = mfitter.GetChi2();	// get chi2 of fit
			double prob_m = mfitter.GetProb();	// access probability of fit
			hjpsi_chi2_mf->Fill(chi2_m);
			hjpsi_prob_mf->Fill(prob_m);			
			
			if ( prob_m > 0.01 )				// when good enough, fill some histo
			{
				RhoCandidate *jfit = jpsi[j]->GetFit();	// access the fitted cand
				hjpsim_mcf->Fill(jfit->M());
			}
		}		
		
		
		// ***
		// *** TRUE PID combinatorics
		// ***
		
		// *** do MC truth match for PID type
		SelectTruePid(theAnalysis, muplus);
		SelectTruePid(theAnalysis, muminus);
		SelectTruePid(theAnalysis, piplus);
		SelectTruePid(theAnalysis, piminus);
				
		// *** all combinatorics again with true PID
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_trpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_trpid->Fill( psi2s[j]->M() );
		
		
		// ***
		// *** LOOSE PID combinatorics
		// ***
		
		// *** and again with PidAlgoMvd;PidAlgoStt;PidAlgoDrc and loose selection
		theAnalysis->FillList(muplus,  "MuonLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(muminus, "MuonLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piplus,  "PionLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_lpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_lpid->Fill( psi2s[j]->M() );
		
		
		// ***
		// *** TIGHT PID combinatorics
		// ***
		
		// *** and again with PidAlgoMvd;PidAlgoStt and tight selection
		theAnalysis->FillList(muplus,  "MuonTightPlus",  "PidAlgoMdtHardCuts");
		theAnalysis->FillList(muminus, "MuonTightMinus", "PidAlgoMdtHardCuts");
		theAnalysis->FillList(piplus,  "PionLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_tpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_tpid->Fill( psi2s[j]->M() );
		
	}
		
	// *** write out all the histos
	out->cd();
	
	hmomtrk->Write();
	hthttrk->Write();
	
	hjpsim_all->Write();
	hpsim_all->Write();
	hjpsim_lpid->Write();
	hpsim_lpid->Write();
	hjpsim_tpid->Write();
	hpsim_tpid->Write();
	hjpsim_trpid->Write();
	hpsim_trpid->Write();
	
	hjpsim_ftm->Write();
	hpsim_ftm->Write();
	hjpsim_nm->Write();
	hpsim_nm->Write();
	
	hpsim_diff->Write();
	hjpsim_diff->Write();
	
	hjpsim_vf->Write();
	hjpsim_4cf->Write();
	hjpsim_mcf->Write();
	
	hjpsi_chi2_vf->Write();
	hpsi_chi2_4c->Write();
	hjpsi_chi2_mf->Write();
			
	hjpsi_prob_vf->Write();
	hpsi_prob_4c->Write();
	hjpsi_prob_mf->Write();
			
	hvpos->Write();
		
	out->Save();
        
	fRun->Finish();
        exit(0);
	
}