예제 #1
0
TF1* checkTotalResolution( const std::string& outputdir, TTree* tree ) {

  std::string histoName("h1_tot");
  TH1D* h1 = new TH1D(histoName.c_str(), "", 2000, 20000.,900000.);
  //TH1D* h1 = new TH1D(histoName.c_str(), "", 200, 0.,4000.);
  //tree->Project( histoName.c_str(), "cef3_maxAmpl[0]+cef3_maxAmpl[1]+cef3_maxAmpl[2]+cef3_maxAmpl[3]", "");
 tree->Project( histoName.c_str(), "cef3_chaInt[0]+cef3_chaInt[1]+cef3_chaInt[2]+cef3_chaInt[3]", "");
  //  tree->Project( histoName.c_str(), "cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]", "nClusters_hodoX==1 && nClusters_hodoY==1 && pos_corr_hodoX1<5 && pos_corr_hodoX1>-5 && pos_corr_hodoY1<5 && pos_corr_hodoY1>-5");


  //TF1* f1 = new TF1("gaus_tot", "gaus", 100., 4000.);
  TF1* f1 = new TF1("gaus_tot", "gaus", 20000.,900000. );
  // f1->SetParameter(0, 3000000.);
  //f1->SetParameter(1, 3000000.);
  //f1->SetParameter(2, 60000.);

  f1->SetLineColor(kRed);

  doSingleFit( h1, f1, outputdir, "tot" );

  std::cout << std::endl;
  std::cout << std::endl;
  float mean  = f1->GetParameter(1);
  float sigma = f1->GetParameter(2);
  float reso = sigma/mean;
  std::cout << "Total " << std::endl;
  std::cout << "  Mean       : " << mean << std::endl;
  std::cout << "  Sigma      : " << sigma << std::endl;
  std::cout << "  Resolution : " << sigma/mean << std::endl;
  std::cout << "Corresponds to a stochastic term of: " << 100.*reso*sqrt(0.5) << " %" << std::endl;

  return f1;

}
예제 #2
0
TF1* checkTotalResolution( const std::string& outputdir, TTree* tree ) {

  std::string histoName("h1_tot");
  TH1D* h1 = new TH1D(histoName.c_str(), "", 500, 0., 12000.);
  tree->Project( histoName.c_str(), "cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]", "(nHodoFibersCorrX==1 && nHodoFibersCorrY==1)");

  TF1* f1 = new TF1("gaus_tot", "gaus", 1600., 4800.);
  f1->SetParameter(0, 3000.);
  f1->SetParameter(1, 3000.);
  f1->SetParameter(2, 600.);

  doSingleFit( h1, f1, outputdir, "tot" );

  std::cout << std::endl;
  std::cout << std::endl;
  float mean  = f1->GetParameter(1);
  float sigma = f1->GetParameter(2);
  float reso = sigma/mean;
  std::cout << "Total " << std::endl;
  std::cout << "  Mean       : " << mean << std::endl;
  std::cout << "  Sigma      : " << sigma << std::endl;
  std::cout << "  Resolution : " << sigma/mean << std::endl;
  std::cout << "Corresponds to a stochastic term of: " << 100.*reso*sqrt(0.5) << " %" << std::endl;

  return f1;

}
예제 #3
0
TF1* fitSingleElectronPeak( const std::string& outputdir, int i, TTree* tree ) {

    gStyle->SetOptFit(1);
  std::string histoName(Form("h1_%d", i));
  //TH1D* h1 = new TH1D(histoName.c_str(), "", 120, 40., 1000.);
   TH1D* h1 = new TH1D(histoName.c_str(), "", 1000, 0., 250000.);
  //tree->Project( histoName.c_str(), Form("cef3_corr[%d]", i), "");

  // tree->Project( histoName.c_str(), Form("cef3[%d]", i),  "nClusters_hodoSmallX==1 && nClusters_hodoSmallY==1 && pos_corr_hodoSmallX<5 && pos_corr_hodoSmallX>-5 && pos_corr_hodoSmallY<5 && pos_corr_hodoSmallY>-5");
  //tree->Project( histoName.c_str(), Form("cef3_maxAmpl[%d]", i),  "abs(cluster_pos_hodoX2)<5 ");
  tree->Project( histoName.c_str(), Form("cef3_chaInt_corr[%d]", i),  "abs(cluster_pos_hodoX2)<2&& abs(cluster_pos_hodoY2)<2 ");
  //tree->Project( histoName.c_str(), Form("cef3_maxAmpl_corr[%d]", i),  "abs(cluster_pos_hodoX2)<5&& abs(cluster_pos_hodoY2)<5 ");


  //  TF1* f1 = new TF1( Form("gaus_%d", i), "gaus", 5., 1000.);
    TF1* f1 = new TF1( Form("gaus_%d", i), "gaus", 400., 250000.);
    f1->SetParameter(0, 300000.);
    f1->SetParameter(1, 250000.);
    f1->SetParameter(2, 15000.);


  f1->SetLineColor(kRed);

  doSingleFit( h1, f1, outputdir, Form("%d", i) );

  return f1;

}
예제 #4
0
TH1F* GetPosteriorPdf( double pars[6] )
{
  double TF = pars[0];/*transfer factor*/
  double TF_Err = pars[1];/*trabsfer factor Unc.*/
  double Nside = pars[2];/*sideband statistics*/
  double Higgs = pars[3];/*higgs expected*/
  double HiggsErr = pars[4];/*higgs uncertainty*/
  double ShapeErr = pars[5];/*shape uncertainty*/

  /*ramdomize histo name*/
  TRandom3 histoName( 0 );
  //--------------------------------------
  //define a random var for each nuissance 
  //--------------------------------------
  TRandom3 gausTF( 0 );
  TRandom3 poissonNside( 0 );
  TRandom3 gausHiggs( 0 );
  TRandom3 gausShape( 0 );
  //---------------------------------
  //pdf for expected observation
  //---------------------------------
  TRandom3 poissonNobs( 0 );
  //histogram to store sampled Nobs
  int i_tmp = histoName.Integer( 100000 );
  TH1F* h_Nobs = new TH1F( Form("h_Nobs_%d", i_tmp), "h_Nobs", NBINS, -1, 4999. );
  for ( int i = 0; i < nsamples; i++ )
    {
      //--------------------------------
      //sample values for each parameter
      //--------------------------------
      double sTF    = gausTF.Gaus( TF, TF_Err );/*sampled value for TF*/
      double sNside = poissonNside.Poisson( Nside );
      double sHiggs = gausHiggs.Gaus( Higgs, HiggsErr );
      double sShape = gausShape.Gaus( 0.0, ShapeErr );
      
      //-----------------------
      //expected observation
      //using sampled values!!
      //-----------------------
      double poissonMean = sTF*sNside*( 1.0 + sShape ) + sHiggs;
      if (  poissonMean < .0 ) poissonMean = .0;
      double sNobs = poissonNobs.PoissonD( poissonMean );
      //double sNobs = poissonNobs.Gaus( poissonMean, TMath::Sqrt(poissonMean) );
      h_Nobs->Fill( sNobs );
    }
  
  return h_Nobs;
};
예제 #5
0
TF1* fitSingleElectronPeak( const std::string& outputdir, int i, TTree* tree ) {

  std::string histoName(Form("h1_%d", i));
  TH1D* h1 = new TH1D(histoName.c_str(), "", 100, 0., 3000.);
  tree->Project( histoName.c_str(), Form("cef3_corr[%d]", i), "(nHodoFibersCorrX==1 && nHodoFibersCorrY==1)");

  TF1* f1 = new TF1( Form("gaus_%d", i), "gaus", 400., 1200.);
  f1->SetParameter(0, 3000.);
  f1->SetParameter(1, 800.);
  f1->SetParameter(2, 150.);

  doSingleFit( h1, f1, outputdir, Form("%d", i) );

  return f1;

}
예제 #6
0
TF1* fitSingleElectronPeak( const std::string& outputdir, int i, TTree* tree ) {

  std::string histoName(Form("h1_%d", i));
  TH1D* h1 = new TH1D(histoName.c_str(), "", 100, 0., 3000.);
  tree->Project( histoName.c_str(), Form("cef3[%d]", i), "(nHodoFibersCorrX==1 && nHodoFibersCorrY==1)");

  TF1* f1 = new TF1( Form("gaus_%d", i), "gaus", 400., 1200.);
  f1->SetParameter(0, 3000.);
  f1->SetParameter(1, 800.);
  f1->SetParameter(2, 150.);

  h1->Fit( f1, "RQN" );

  int niter = 4.;
  float nSigma = 2.;
  for( unsigned iter=0; iter<niter; iter++ ) {
    float mean  = f1->GetParameter(1);
    float sigma = f1->GetParameter(2);
    float fitMin = mean - nSigma*sigma;
    float fitMax = mean + nSigma*sigma;
    f1->SetRange( fitMin, fitMax );
    if( iter==(niter-1) )
      h1->Fit( f1, "RQN" );
    else
      h1->Fit( f1, "RQ+" );
  }


  TCanvas* c1 = new TCanvas("c1", "", 600, 600);
  c1->cd();

  h1->Draw();

  c1->SaveAs( Form("%s/fit_%d.eps", outputdir.c_str(), i) );
  c1->SaveAs( Form("%s/fit_%d.png", outputdir.c_str(), i) );

  delete c1;

  return f1;

}
FitResults fitSingleHisto_sum( TH1D* histo, double pedMin, double pedMax, double xMin, double xMax, bool isConstrained ) {

  float integral = histo->Integral();
  TF1* f1_ped = new TF1( "ped", "gaus", pedMin, pedMax );
  f1_ped->SetParameter(0, integral);
  f1_ped->SetParameter(1, 110.);
  f1_ped->SetParameter(2, 10.);

  f1_ped->SetLineColor(kRed+2);
  if(pedMin>10){
  histo->Fit( f1_ped, "RQN" );

  int nSteps = 2;
  for( unsigned iStep=0; iStep<nSteps; iStep++ ) {

    float ped_mean = f1_ped->GetParameter(1);
    float ped_sigma = f1_ped->GetParameter(2);

    float nSigma = 2.;
    float newMin = ped_mean-nSigma*ped_sigma;
    float newMax = ped_mean+nSigma*ped_sigma;

    f1_ped->SetRange( newMin, newMax );
 
    std::string option = (iStep<(nSteps-1)) ? "RQN" : "RQ+";
    histo->Fit( f1_ped, option.c_str() );

  }
  }

  TF1* f1;
  if(isConstrained){
    f1 = new TF1( "func", PMTFunction, xMin, xMax, 8 );
  }else{
    f1 = new TF1( "func_unconstrained", PMTFunction_unconstrained, xMin, xMax, 8 );
  }
  f1->SetParameter( 0, integral ); //normalization
  f1->SetParameter( 1, 1 ); //poiss mu
  f1->SetParameter( 2, 25. ); //gauss step
  f1->SetParameter( 3, 10. ); //gauss sigma
  f1->SetParameter( 4, 100 ); //offset
  f1->SetParameter( 5, 3. ); //sigmaoffset
  f1->SetParameter( 6, 0.03 ); //alpha
  f1->SetParameter( 7, 0.4 ); //w
    
  f1->FixParameter( 5, 0. ); //sigmaoffset
  f1->FixParameter( 6, 0. ); //alpha
  f1->FixParameter( 7, 0. ); //w
    
  f1->SetParLimits( 1, 0.5, 2.5 ); //poiss mu
  f1->SetParLimits( 2, 10., 40. ); //gauss step
  f1->SetParLimits( 3, 3., 12. ); //gauss sigma
  //f1->SetParLimits( 4, 90., 110.); //offset
  //f1->SetParLimits( 5, 0., 8. ); //gauss sigma
  f1->SetLineColor(kRed+2);
    
  if(pedMin<10){
    f1->FixParameter( 4, 0 );
  }

  if(!isConstrained){
    std::cout<<"------unconstrained fit"<<std::endl;
    f1->FixParameter(1,1);
    f1->SetLineColor(kBlue);
  }

  histo->Fit( f1, "R+" );

  TCanvas* c1 = new TCanvas("c1", "c1", 600, 600);
  c1->cd();

  c1->SetLogy();

  TH2D* h2_axes;
  if(!(pedMin<10)){
    h2_axes= new TH2D("axes", "", 10, 100., 350., 10, 9., 7.*histo->GetMaximum() );
  }else{
    h2_axes= new TH2D("axes", "", 10, 0., 200., 10, 9., 7.*histo->GetMaximum() );
  }
  h2_axes->SetXTitle( "ADC Counts" );
  h2_axes->Draw();

  histo->Draw("same");


  TString histoName(histo->GetName());


  c1->SaveAs( histoName + ".eps" );
  c1->SaveAs( histoName + ".png" );

  FitResults fr;
  fr.ped_mu = f1_ped->GetParameter(1);
  fr.ped_mu_err = f1_ped->GetParError(1);
  fr.ped_sigma = f1_ped->GetParameter(2);
  fr.ped_sigma_err = f1_ped->GetParError(2);

  fr.mu = f1->GetParameter(1);
  fr.mu_err = f1->GetParError(1);
  fr.offset = f1->GetParameter(4);
  fr.offset_err = f1->GetParError(4);
  fr.Q1 = f1->GetParameter(2);
  fr.Q1_err = f1->GetParError(2);
  fr.sigma = f1->GetParameter(3);
  fr.sigma_err = f1->GetParError(3);
  f1->Clear();

  delete c1;
  delete f1;
  delete f1_ped;
  delete h2_axes;

  return fr;



}
FitResults fitSingleHisto( TH1D* histo, double pedMin, double pedMax, double xMin, double xMax ) {

  float integral = histo->Integral();
  TF1* f1_ped = new TF1( "ped", "gaus", pedMin, pedMax );
  f1_ped->SetParameter(0, integral);
  f1_ped->SetParameter(1, 110.);
  f1_ped->SetParameter(2, 10.);

  f1_ped->SetLineColor(kRed+2);
  if(pedMin>10){
  histo->Fit( f1_ped, "RQN" );

  int nSteps = 2;
  for( unsigned iStep=0; iStep<nSteps; iStep++ ) {

    float ped_mean = f1_ped->GetParameter(1);
    float ped_sigma = f1_ped->GetParameter(2);

    float nSigma = 2.;
    float newMin = ped_mean-nSigma*ped_sigma;
    float newMax = ped_mean+nSigma*ped_sigma;

    f1_ped->SetRange( newMin, newMax );
 
    std::string option = (iStep<(nSteps-1)) ? "RQN" : "RQ+";
    histo->Fit( f1_ped, option.c_str() );

  }
  }

  TF1* f1 = new TF1( "func", PMTFunction, xMin, xMax, 8 );
  f1->SetParameter( 0, integral ); //normalization
  f1->SetParameter( 1, 1. ); //poiss mu
  f1->SetParameter( 2, 25. ); //gauss step
  f1->SetParameter( 3, 10. ); //gauss sigma
  f1->SetParameter( 4, 100 ); //offset
  f1->SetParameter( 5, 3. ); //sigmaoffset
  f1->SetParameter( 6, 0.03 ); //alpha
  f1->SetParameter( 7, 0.4 ); //w

  f1->FixParameter( 5, 0. ); //sigmaoffset
  f1->FixParameter( 6, 0. ); //alpha
  f1->FixParameter( 7, 0. ); //w

  f1->SetParLimits( 1, 0.5, 2.5 ); //poiss mu
  f1->SetParLimits( 2, 10., 40. ); //gauss step
  f1->SetParLimits( 3, 3., 12. ); //gauss sigma
  //f1->SetParLimits( 4, 90., 110.); //offset
  //f1->SetParLimits( 5, 0., 8. ); //gauss sigma
  f1->SetLineColor(kRed+2);

  if(pedMin<10){
    f1->FixParameter( 4, 0 );
  }


  histo->Fit( f1, "RN+" );
  TString histoName(histo->GetName());
  if(histoName=="cef3_pedSubtracted_corr_rebin_2")  f1->SetRange(xMin, xMax+3); //plot for the paper
  f1->SetLineColor(kRed);


  TCanvas* c1 = new TCanvas("c1", "c1", 600, 600);
  c1->cd();

  //  c1->SetLogy();

  TH2D* h2_axes;
  if(!(pedMin<10)){
    h2_axes= new TH2D("axes", "", 10, 100., 350., 10, 9.,1.2*histo->GetMaximum() );
  }else{
    h2_axes= new TH2D("axes", "", 10, 0., 150., 10, 9., 1.2*histo->GetMaximum() );
  }
  h2_axes->SetXTitle( "ADC Channel" );
  h2_axes->SetYTitle( "Entries / (2 ADC Channels)" );
  h2_axes->Draw();

  histo->SetLineWidth(2);

  histo->SetXTitle( "ADC Counts" );

  TPaveText* labelTop = DrawTools::getLabelTop("Cosmic Data");
  labelTop->Draw("same");
  gPad->RedrawAxis(); 



  float N, mu, Q1, sigma;
  float N_err, mu_err, Q1_err, sigma_err;
  N=f1->GetParameter(0);
  mu=f1->GetParameter(1);
  Q1=f1->GetParameter(2);
  sigma=f1->GetParameter(3);

  N_err=f1->GetParError(0);
  mu_err=f1->GetParError(1);
  Q1_err=f1->GetParError(2);
  sigma_err=f1->GetParError(3);


  //longer version
  TPaveText* label_fit = new TPaveText(0.52,0.67,0.8,0.85, "brNDC");
  label_fit->SetFillColor(kWhite);
  label_fit->SetTextSize(0.035);
  label_fit->SetTextAlign(10); // align right
  label_fit->SetTextFont(62);
  label_fit->AddText("W-CeF_{3} Single Tower");
  label_fit->AddText("Single photoelectron fit");
  std::string N_str=Form("N=%4.0f #pm %2.0f", N,N_err);
  //  label_fit->AddText(N_str.c_str());
  std::string mu_str=Form("#mu=%.2f #pm %.2f", mu,mu_err);
  //  label_fit->AddText(mu_str.c_str());
  std::string Q_1_str=Form("Q_{1} = %.1f #pm %.1f", Q1,Q1_err);
  label_fit->AddText(Q_1_str.c_str());
  std::string sigma_str=Form("#sigma_{1} = %.1f #pm %.1f", sigma, sigma_err);
  label_fit->AddText(sigma_str.c_str());


  label_fit->Draw("same");

  histo->Draw("same");
  f1->Draw("same");

  c1->SaveAs( histoName + ".eps" );
  c1->SaveAs( histoName + ".png" );
  c1->SaveAs( histoName + ".C" );
  c1->SaveAs( histoName + ".pdf" );

  c1->SetLogy();

  c1->SaveAs( histoName + "_log.eps" );
  c1->SaveAs( histoName + "_log.png" );
  c1->SaveAs( histoName + "_log.C" );
  c1->SaveAs( histoName + "_log.pdf" );

  FitResults fr;
  fr.ped_mu = f1_ped->GetParameter(1);
  fr.ped_mu_err = f1_ped->GetParError(1);
  fr.ped_sigma = f1_ped->GetParameter(2);
  fr.ped_sigma_err = f1_ped->GetParError(2);

  fr.mu = f1->GetParameter(1);
  fr.mu_err = f1->GetParError(1);
  fr.offset = f1->GetParameter(4);
  fr.offset_err = f1->GetParError(4);
  fr.Q1 = f1->GetParameter(2);
  fr.Q1_err = f1->GetParError(2);
  fr.sigma = f1->GetParameter(3);
  fr.sigma_err = f1->GetParError(3);

  delete c1;
  delete f1;
  delete f1_ped;
  delete h2_axes;

  return fr;



}
FitResults fitSingleHisto( TH1D* histo, double pedMin, double pedMax, double xMin, double xMax ) {

  float integral = histo->Integral();
  TF1* f1_ped = new TF1( "ped", "gaus", pedMin, pedMax );
  f1_ped->SetParameter(0, integral);
  f1_ped->SetParameter(1, 110.);
  f1_ped->SetParameter(2, 10.);

  f1_ped->SetLineColor(kRed+2);
  if(pedMin>10){
  histo->Fit( f1_ped, "RQN" );

  int nSteps = 2;
  for( unsigned iStep=0; iStep<nSteps; iStep++ ) {

    float ped_mean = f1_ped->GetParameter(1);
    float ped_sigma = f1_ped->GetParameter(2);

    float nSigma = 2.;
    float newMin = ped_mean-nSigma*ped_sigma;
    float newMax = ped_mean+nSigma*ped_sigma;

    f1_ped->SetRange( newMin, newMax );
 
    std::string option = (iStep<(nSteps-1)) ? "RQN" : "RQ+";
    histo->Fit( f1_ped, option.c_str() );

  }
  }

  TF1* f1 = new TF1( "func", cef3Function, xMin, xMax, 8 );
  f1->SetParameter( 0, integral ); //normalization
  f1->SetParameter( 1, 1. ); //poiss mu
  f1->SetParameter( 2, 3000. ); //gauss step
  f1->SetParameter( 3, 500. ); //gauss sigma
  f1->SetParameter( 4, 1000 ); //offset
  f1->SetParameter( 5, 30. ); //sigmaoffset
  f1->SetParameter( 6, 0.3 ); //alpha
  f1->SetParameter( 7, 4 ); //w

  f1->FixParameter( 5, 0. ); //sigmaoffset
  f1->FixParameter( 6, 0. ); //alpha
  f1->FixParameter( 7, 0. ); //w

//  f1->SetParLimits( 1, 0.5, 2.5 ); //poiss mu
//  f1->SetParLimits( 2, 10., 40. ); //gauss step
//  f1->SetParLimits( 3, 3., 12. ); //gauss sigma
  //f1->SetParLimits( 4, 90., 110.); //offset
  //f1->SetParLimits( 5, 0., 8. ); //gauss sigma
  f1->SetLineColor(kRed);
  f1->SetLineWidth(3);

  if(pedMin<10){
    f1->FixParameter( 4, 0 );
  }

  histo->Fit( f1, "R+" );

  TCanvas* c1 = new TCanvas("c1", "c1", 600, 600);
  c1->cd();

  c1->SetLogy();
  TLine *lineLow1 = new TLine(f1->GetParameter(2)-2*f1->GetParameter(3),0,f1->GetParameter(2)-2*f1->GetParameter(3),1.2*histo->GetMaximum());
  TLine *lineLow2 = new TLine(2*f1->GetParameter(2)-2*sqrt(2)*f1->GetParameter(3),0,2*f1->GetParameter(2)-2*sqrt(2)*f1->GetParameter(3),1.2*histo->GetMaximum());
  TLine *lineUp2 = new TLine(2*f1->GetParameter(2)+2*sqrt(2)*f1->GetParameter(3),0,2*f1->GetParameter(2)+2*sqrt(2)*f1->GetParameter(3),1.2*histo->GetMaximum());
  lineLow1->SetLineWidth(2);
  lineLow2->SetLineWidth(2);
  lineUp2->SetLineWidth(2);
  lineLow1->SetLineColor(kRed);
  lineLow2->SetLineColor(kBlue);
  lineUp2->SetLineColor(kBlue);

  std::cout<<f1->GetParameter(2)-2*f1->GetParameter(3)<<" "<<2*f1->GetParameter(2)-2*sqrt(2)*f1->GetParameter(3)<<std::endl;
  histo->SetXTitle( "ADC Counts" );
  histo->Draw();
  TString histoName(histo->GetName());
  c1->SaveAs( histoName + ".eps" );
  c1->SaveAs( histoName + ".png" );
  lineLow1->Draw("same");
  lineLow2->Draw("same");
  lineUp2->Draw("same");





  c1->SaveAs( histoName + "_sigma.eps" );
  c1->SaveAs( histoName + "_sigma.png" );

  FitResults fr;
  fr.ped_mu = f1_ped->GetParameter(1);
  fr.ped_mu_err = f1_ped->GetParError(1);
  fr.ped_sigma = f1_ped->GetParameter(2);
  fr.ped_sigma_err = f1_ped->GetParError(2);

  fr.mu = f1->GetParameter(1);
  fr.mu_err = f1->GetParError(1);
  fr.offset = f1->GetParameter(4);
  fr.offset_err = f1->GetParError(4);
  fr.Q1 = f1->GetParameter(2);
  fr.Q1_err = f1->GetParError(2);
  fr.sigma = f1->GetParameter(3);
  fr.sigma_err = f1->GetParError(3);

  delete c1;
  delete f1;
  delete f1_ped;

  return fr;



}