コード例 #1
0
ファイル: customChis.c プロジェクト: DUNE/lblpwgtools
//same as globes, but customized to copy values to xmin for later use and to use B2B errors
double chiSpectrumTiltCustom_BtoB(int exp, int rule, int n_params, double *x, double *errors,
                          void *user_data)
{
  //int n_bins = glbGetNumberOfBins(exp);
  double *true_rates       = glbGetRuleRatePtr(exp, rule);
  double *signal_fit_rates = glbGetSignalFitRatePtr(exp, rule);
  double *bg_fit_rates     = glbGetBGFitRatePtr(exp, rule);
  double *bin_centers      = glbGetBinCentersListPtr(exp);
  double signal_norm, signal_tilt;
  double bg_norm_center, bg_tilt_center;
  double bg_norm, bg_tilt;
  int ew_low, ew_high;
  double emin, emax, ecenter;
  double fit_rate;//, true_rate
  double chi2 = 0.0;
  int i;

  glbGetEminEmax(exp, &emin, &emax);
  ecenter = 0.5 * (emax + emin);
  glbGetEnergyWindowBins(exp, rule, &ew_low, &ew_high);
  glbGetBGCenters(exp, rule, &bg_norm_center, &bg_tilt_center);
  signal_norm = 1.0 + x[0];
  signal_tilt = x[1] / (emax - emin);
  bg_norm = bg_norm_center * (1.0 + x[2]);
  bg_tilt = x[3] / (emax - emin);
  for (i=ew_low; i <= ew_high; i++)
  {
    fit_rate = signal_norm*signal_fit_rates[i]
                + signal_tilt*(bin_centers[i]-ecenter)*signal_fit_rates[i]
                + bg_norm*bg_fit_rates[i]
                + bg_tilt*(bin_centers[i]-ecenter)*bg_fit_rates[i];
    //chi2 += glikelihood(true_rates[i], fit_rate);
    chi2 += glikelihood(true_rates[i], fit_rate,true_rates[i] * (1.0 + true_rates[i]*(sigma_binbin*sigma_binbin)));

  }
  fchi1=chi2;
  
  chi2 += myprior(x[0], 0.0, errors[0])
            + myprior(x[1], 0.0, errors[1])
            + myprior(bg_norm, bg_norm_center, errors[2])
            + myprior(bg_tilt, bg_tilt_center, errors[3]);

  fchi2=chi2;
  priors[0]=myprior(x[0], 0.0, errors[0]);
  priors[1]=myprior(x[1], 0.0, errors[1]);
  priors[2]=myprior(bg_norm, bg_norm_center, errors[2]);
  priors[3]=myprior(bg_tilt, bg_tilt_center, errors[3]);
  //for(i=0; i<n_params; i++){
	//	xmin[i+15*exp]=x[i+15*exp];
	//}
  xmin[exp][0]=x[0];
  xmin[exp][1]=x[1];
  xmin[exp][2]=x[2];
  xmin[exp][3]=bg_tilt;
	
  
  
  /*for (i=ew_low; i <= ew_high; i++){
    double tfit_rate=signal_norm*signal_fit_rates[i]
                  + signal_tilt*(bin_centers[i]-ecenter)*signal_fit_rates[i]
                  + bg_norm*bg_fit_rates[i]
                  + bg_tilt*(bin_centers[i]-ecenter)*bg_fit_rates[i];
    ts[0][i]=true_rates[i];
    ts[1][i]=signal_fit_rates[i];
    ts[2][i]=tfit_rate;
    ts[3][i]=mylikelihood(true_rates[i],tfit_rate);
    ts[4][i]=2*(tfit_rate - true_rates[i]+ true_rates[i] * log(true_rates[i]/tfit_rate));
   

  }*/
           
  return chi2;
}
コード例 #2
0
ファイル: customChis.c プロジェクト: DUNE/lblpwgtools
//This adds in a bin to bin uncorrelated error to reflect
//imperfect knowledge of the shape in the spectrum.
double chiSpectrumSplitBG_BtoB(int exp, int rule, int n_params, double *x, double *errors,
                          void *user_data)
{
  //printf("chiSpectrumSplitBG_BtoB\n");
  double *true_rates       = glbGetRuleRatePtr(exp, rule);
  double *signal_fit_rates = glbGetSignalFitRatePtr(exp, rule);
  double signal_norm;
  int ew_low, ew_high;
  double emin, emax, ecenter;
  double fit_rate;
  double chi2 = 0.0;
  int i,j,ebin;
  
  glbGetEminEmax(exp, &emin, &emax);
  ecenter = 0.5 * (emax + emin);
  glbGetEnergyWindowBins(exp, rule, &ew_low, &ew_high);
  
  //signal norm systematics still treated in sum
  signal_norm = 1.0 + x[0];
  
  //find out how many background channels there are
  //init bg_norm array
  int bg_channels = glbGetLengthOfRule(exp,rule,GLB_BG);
  double bg_norm[bg_channels];

  //count energy bins and init/populate bg_fit_rates_per_channel
  int ebins=0;
  for (i=ew_low; i <= ew_high; i++) ebins++;
  double bg_fit_rates_per_channel[bg_channels][ebins];
  //printf("%d ebins; %d bg_channels\n",ebins,bg_channels);
  for(i=0;i<bg_channels;i++){
	  //printf("channel %d is %s\n",i,glbValueToName(exp,"channel",i));
	  double * trates=glbGetChannelRatePtr(exp,i,GLB_POST);
		for(ebin=0;ebin<ebins;ebin++){
			bg_fit_rates_per_channel[i][ebin] = trates[ebin];
	  }
  }
  double bg_norm_center=1.0;
  //printf("bg_norm_center:%f\n",bg_norm_center);
  //exit(0);
  //bg energy norm is split by background channel
  //there should be an norm for each BG type
  //otherwise, kaboom (TODO: add a check)
  j=1;
  for(i=0; i<bg_channels; i++){
	  bg_norm[i]=bg_norm_center * (1.0 + x[j]);
	  j=j+1;
  }

  for (i=ew_low; i <= ew_high; i++){
    fit_rate = signal_norm*signal_fit_rates[i];
                
		//addon to fit_rate for each bg channel
		for(j=0; j<bg_channels; j++){
			fit_rate += 	bg_norm[j]*bg_fit_rates_per_channel[j][i];
		 }
    chi2 += glikelihood(true_rates[i], fit_rate,true_rates[i] * (1.0 + true_rates[i]*(sigma_binbin*sigma_binbin)));
  }
  //printf("after likelihood, chi2 is %f\n",chi2);
  //add penalty for signal norm
  chi2 += myprior(x[0], 0.0, errors[0]);
  //printf("after first priors, chi2 is %f\n",chi2);
  //add chi2 penalties for bg norms
  j=1;
  for(i=0; i<bg_channels; i++){
	  chi2 += myprior(bg_norm[i], bg_norm_center, errors[j]);
    //printf("after prior %d for channel %s\t, chi2 is %f\n",i,glbValueToName(exp,"channel",i),chi2);
		j=j+1;
  }
  //printf("after all priors, chi2 is %f\n",chi2);
  //copy parameter array into globally accessible variable
  for(i=0; i<n_params; i++){
		xmin[exp][i]=x[i];
	}
  
  //printf("%f\n",chi2);
  //exit(0);
  return chi2;
}
コード例 #3
0
ファイル: customChis.c プロジェクト: DUNE/lblpwgtools
double chiSpectrumTiltSplitBG(int exp, int rule, int n_params, double *x, double *errors,
                          void *user_data)
{
  double *true_rates       = glbGetRuleRatePtr(exp, rule);
  double *signal_fit_rates = glbGetSignalFitRatePtr(exp, rule);
  double *bin_centers      = glbGetBinCentersListPtr(exp);
  double signal_norm, signal_tilt, bg_tilt;
  int ew_low, ew_high;
  double emin, emax, ecenter;
  double fit_rate;
  double chi2 = 0.0;
  int i,j,ebin;
  
  glbGetEminEmax(exp, &emin, &emax);
  ecenter = 0.5 * (emax + emin);
  glbGetEnergyWindowBins(exp, rule, &ew_low, &ew_high);
  
  //signal energy tilt systematics still treated in sum
  signal_norm = 1.0 + x[0];
  signal_tilt = x[1] / (emax - emin);
  //bg tilt treated in sum as well
  bg_tilt=x[2]/(emax-emin);
  
  //find out how many background channels there are
  //init bg_norm array
  int bg_channels = glbGetLengthOfRule(exp,rule,GLB_BG);
  double bg_norm[bg_channels];

  //count energy bins and init/populate bg_fit_rates_per_channel
  int ebins=0;
  for (i=ew_low; i <= ew_high; i++) ebins++;
  double bg_fit_rates_per_channel[bg_channels][ebins];
  //printf("%d ebins; %d bg_channels\n",ebins,bg_channels);
  for(i=0;i<bg_channels;i++){
	  //printf("channel %d is %s\n",i,glbValueToName(exp,"channel",i));
	  double * trates=glbGetChannelRatePtr(exp,i,GLB_POST);
		for(ebin=0;ebin<ebins;ebin++){
			bg_fit_rates_per_channel[i][ebin] = trates[ebin];
			//printf("%f : %f\n",bin_centers[ebin],bg_fit_rates_per_channel[i][ebin]);
	  }
  }
  double bg_norm_center, bg_tilt_center;
  glbGetBGCenters(exp, rule, &bg_norm_center, &bg_tilt_center);
  //printf("bg_norm_center:%f   bg_tilt_center:%f\n",bg_norm_center,bg_tilt_center);
  //exit(0);
  //bg energy norm is split by background channel
  //there should be an norm for each BG type
  //otherwise, kaboom (TODO: add a check)
  j=3;
  for(i=0; i<bg_channels; i++){
	  bg_norm[i]=bg_norm_center * (1.0 + x[j]);
	  j=j+1;
  }

  for (i=ew_low; i <= ew_high; i++){
    fit_rate = signal_norm*signal_fit_rates[i]
                + signal_tilt*(bin_centers[i]-ecenter)*signal_fit_rates[i];
                
		//addon to fit_rate for each bg channel
		for(j=0; j<bg_channels; j++){
			fit_rate += 	bg_norm[j]*bg_fit_rates_per_channel[j][i]
						 +bg_tilt*(bin_centers[i]-ecenter)*bg_fit_rates_per_channel[j][i];
		 }
    
    chi2 += mylikelihood(true_rates[i], fit_rate);
  }

  chi2 += myprior(x[0], 0.0, errors[0])
            + myprior(x[1], 0.0, errors[1])
            + myprior(bg_tilt, bg_tilt_center, errors[2]);
  //add chi2 penalties for bg priors
  j=3;
  for(i=0; i<bg_channels; i++){
	  chi2 += myprior(bg_norm[i], bg_norm_center, errors[j]);
		j=j+1;
  }
  
  //copy parameter array into globally accessible variable
  for(i=0; i<n_params; i++){
		xmin[exp][i]=x[i];
	}
  
  //printf("%f\n",chi2);
  //exit(0);
  return chi2;
}
コード例 #4
0
ファイル: main.c プロジェクト: Pontigre/GLoBES
int main(int argc, char *argv[])
{ 
  /* Initialize libglobes */
  glbInit(argv[0]);

  /* Initialize experiment */
  //glbInitExperiment(AEDLFILE,&glb_experiment_list[0],&glb_num_of_exps); 
  glbInitExperiment(AEDLFILE2,&glb_experiment_list[0],&glb_num_of_exps); /* nuPRISM */
  //glbInitExperiment(AEDLFILE3,&glb_experiment_list[0],&glb_num_of_exps); /* Reactor */

  /* Intitialize output */
  outfile1 = fopen(MYFILE1, "w");
  outfile2 = fopen(MYFILE2, "w");
  outfile3 = fopen(MYFILE3, "w");
  outfile4 = fopen(MYFILE4, "w");
  outfile5 = fopen(MYFILE5, "w");
  outfile6 = fopen(MYFILE6, "w");
  outfile7 = fopen(MYFILE7, "w");

  /* Define "true" oscillation parameters */
  theta12 = asin(sqrt(0.307));
  theta13 = asin(sqrt(0.0241));
  theta23 = 0.5;
  deltacp = 0.0;
  dm21 = 7.6e-5;
  dm32 = 2.4e-3;
  dm31 = dm32 + dm21;

  /* Needed for scans */
  double e_min = 0.0;
  double e_max = 3.0;
  double dist = 295.0;
  double E = 0.0;
  int bins = glbGetNumberOfBins(0);
  int polar = +1;
  int n_bins = 100;
  int bin;
  double e_step = (e_max-e_min)/(n_bins);
  double this_th13, this_delta;
  double th13_lower  = asin(sqrt(0.01));
  double th13_upper  = asin(sqrt(0.04));
  double th13_steps  = 15;
  double delta_lower = -M_PI;
  double delta_upper = M_PI;
  double delta_steps = 15;
  double res, sig, flux;


  true_values = glbAllocParams();
  test_values = glbAllocParams();
  input_errors = glbAllocParams();
  th13delta_projection = glbAllocProjection();

  glbDefineProjection(th13delta_projection,GLB_FIXED,GLB_FIXED,GLB_FREE,GLB_FIXED,GLB_FIXED,GLB_FREE);
  glbSetDensityProjectionFlag(th13delta_projection, GLB_FIXED, GLB_ALL);
  glbSetProjection(th13delta_projection);

  glbDefineParams(true_values,theta12,theta13,theta23,deltacp,dm21,dm31);
  glbSetDensityParams(true_values,1.0,GLB_ALL);

  glbSetOscillationParameters(true_values);
  glbSetRates();

  /*------------------------------------- Initial Fluxes ---------------------------------------------------*/

  printf("Initial fluxes \n");

  for(E = e_min; E<e_max; E += e_step){
    flux = glbFlux(0, 0, E, dist, 1, polar);
    fprintf(outfile1, "%g %g \n", E, flux);
  }

  for(E = e_min; E<e_max; E += e_step){
    flux = glbFlux(0, 0, E, dist, 2, polar);
    fprintf(outfile2, "%g %g \n", E, flux);
  }

  fclose(outfile1);
  fclose(outfile2);

  /*---------------------------------------- Event Rates ---------------------------------------------------*/

  printf("Event Rates \n");

  // rule 0 = NU_E_Appearance_QE
  // rule 2 = NU_MU_Disappearance_QE
  // rule 4 = NU_MU_Disappearance_CC
  // rule 5 = NU_E_Appearance_CC

  double *rates_e = glbGetRuleRatePtr(0,5);
  double *rates_mu = glbGetRuleRatePtr(0,4);

  for(bin=0;bin<bins;bin++){
    fprintf(outfile3, "%i %g \n", bin, rates_e[bin]);
    fprintf(outfile4, "%i %g \n", bin, rates_mu[bin]);
  }

  fclose(outfile3);
  fclose(outfile4);

  /*------------------------------------- Delta CP Significance ----------------------------------------------*/

  printf("Delta_cp significance \n");
  delta_steps = 40;
  glbDefineParams(test_values,theta12,theta13,theta23,deltacp,dm21,dm31);  
  glbSetDensityParams(test_values,1.0,GLB_ALL);
  glbDefineParams(input_errors, theta12*0.1, 0, 0, 0, dm21*0.1, 0);
  glbSetDensityParams(input_errors,0.05,GLB_ALL);
  glbSetInputErrors(input_errors);
  glbSetCentralValues(true_values);

  for(this_delta=delta_lower; this_delta<=delta_upper; this_delta+= (delta_upper-delta_lower)/delta_steps)
    {
      double x = sin(this_delta);
      double i = this_delta*180.0/M_PI;
      glbSetOscParams(test_values, asin(x), GLB_DELTA_CP);
      double chi2=glbChiDelta(test_values, NULL, GLB_ALL);
      glbSetOscParams(test_values, deltacp, GLB_DELTA_CP);
      double chitrue=glbChiDelta(test_values, NULL, GLB_ALL);
      sig = sqrt(abs(chi2 - chitrue));
      printf("delta = %g \n", i);
      fprintf(outfile5, "%g %g\n", i, sig);
    }

  fclose(outfile5);


  /*------------------------------------- theta13 - delta_cp scan ---------------------------------------------------*/

  delta_steps = 15;
  printf("Initial th13-deltacp scan \n");

  for(deltacp = -M_PI/2.0; deltacp < M_PI+0.1; deltacp += M_PI/2.0){
    double x = deltacp/M_PI;
    printf("Delta_CP = %g\n", x);

    /* Define "true" oscillation parameter vector */
    glbDefineParams(true_values,theta12,theta13,theta23,deltacp,dm21,dm31);
    glbSetDensityParams(true_values,1.0,GLB_ALL);
 
    /* Define initial guess for the fit values */ 
    glbDefineParams(test_values,theta12,theta13,theta23,deltacp,dm21,dm31);  
    glbSetDensityParams(test_values,1.0,GLB_ALL);

    glbDefineParams(input_errors, theta12*0.1, 0, 0, 0, dm21*0.1, 0);
    glbSetDensityParams(input_errors,0.05,GLB_ALL);
    glbSetInputErrors(input_errors);
    glbSetCentralValues(true_values);

    /* Compute simulated data */
    glbSetOscillationParameters(true_values);
    glbSetRates();

    for(this_th13=th13_lower; this_th13<=th13_upper; this_th13+=(th13_upper-th13_lower)/th13_steps)
      {
	for(this_delta=delta_lower; this_delta<=delta_upper; this_delta+=(delta_upper-delta_lower)/delta_steps)
	  {
	    glbSetOscParams(test_values, this_th13, GLB_THETA_13);
	    glbSetOscParams(test_values, this_delta, GLB_DELTA_CP);
	    double i = sin(2*this_th13)*sin(2*this_th13);
	    double j = this_delta*180.0/M_PI;
	    res=glbChiNP(test_values, NULL, GLB_ALL);
	    fprintf(outfile6, "%g %g %g\n", i, j, res);
	  }
	fprintf(outfile6, "\n");
      }
  }

  fclose(outfile6);

  /*------------------------------------- theta13 - delta_cp scan - Half errors -------------------------------------*/

  printf("th13-deltacp scan with half the errors \n");

  HalfErrors();
  delta_steps = 60;
  th13_steps = 60;

  for(deltacp = -M_PI/2.0; deltacp < M_PI+0.1; deltacp += M_PI/2.0){
    double x = deltacp/M_PI;
    printf("Delta_CP = %g\n", x);

    /* Define "true" oscillation parameter vector */
    glbDefineParams(true_values,theta12,theta13,theta23,deltacp,dm21,dm31);
    glbSetDensityParams(true_values,1.0,GLB_ALL);
 
    /* Define initial guess for the fit values */ 
    glbDefineParams(test_values,theta12,theta13,theta23,deltacp,dm21,dm31);  
    glbSetDensityParams(test_values,1.0,GLB_ALL);

    glbDefineParams(input_errors, theta12*0.1, 0, 0, 0, dm21*0.1, 0);
    glbSetDensityParams(input_errors,0.05,GLB_ALL);
    glbSetInputErrors(input_errors);
    glbSetCentralValues(true_values);

    /* Compute simulated data */
    glbSetOscillationParameters(true_values);
    glbSetRates();

    for(this_th13=th13_lower; this_th13<=th13_upper; this_th13+=(th13_upper-th13_lower)/th13_steps)
      {
	for(this_delta=delta_lower; this_delta<=delta_upper; this_delta+=(delta_upper-delta_lower)/delta_steps)
	  {
	    glbSetOscParams(test_values, this_th13, GLB_THETA_13);
	    glbSetOscParams(test_values, this_delta, GLB_DELTA_CP);
	    double i = sin(2*this_th13)*sin(2*this_th13);
	    double j = this_delta*180.0/M_PI;
	    double res=glbChiNP(test_values, NULL, GLB_ALL);
	    fprintf(outfile7, "%g %g %g\n", i, j, res);
	  }
	fprintf(outfile7, "\n");
      }
  }
  fclose(outfile7);

  glbFreeParams(test_values);
  glbFreeParams(input_errors);
  glbFreeProjection(th13delta_projection);
  glbFreeParams(true_values);
  return 0;
}