예제 #1
0
// Modes: linear or log
plotHistogram(const char* canvas, const char* mode, const char* title,
	      double xlo, double xhi, int nbin,
	      double* sig, double* sigerr, double* bgr, double* bgrerr)
{
  TCanvas *c 
    = new TCanvas(canvas,"SPR Classifier Output",200,10,600,400);
  gStyle->SetPalette(1);
  TLegend *leg = new TLegend(0.1,0.85,0.5,1.,"Classifier Output","NDC");
  double dx = (xhi-xlo) / nbin;
  TH1D* hs = new TH1D("signal",    title,nbin,xlo,xhi);
  TH1D* hb = new TH1D("background",title,nbin,xlo,xhi);
  leg->AddEntry(hs,"Signal","L");
  leg->AddEntry(hb,"Background","L");
  for( int i=0;i<nbin;i++ ) {
    hs->SetBinContent(i+1,sig[i]);
    hs->SetBinError(i+1,sigerr[i]);
    hb->SetBinContent(i+1,bgr[i]);
    hb->SetBinError(i+1,bgrerr[i]);
  }
  TPad* pad = new TPad("pad","pad",0,0,1,1);
  if( strcmp(mode,"log") == 0 ) pad->SetLogy(1);
  pad->Draw();
  pad->cd();
  hs->SetLineColor(2);
  hs->SetLineWidth(3);
  hb->SetLineColor(4);
  hb->SetLineWidth(3);
  hb->Draw();
  hs->Draw("same");
  leg->Draw();
}
예제 #2
0
void fitSlices(TH2* hCorr, TF1* func){

   int nBins = hCorr->GetNbinsX();

   TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());
   TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());

   for(int i = 1; i < nBins+1; ++i){
      int bin = nBins - i;
      TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i);

      func->SetParameter(0,h->GetMaximum());
      func->SetParameter(1,h->GetMean());
      func->SetParameter(2,h->GetRMS());

      if(useFits) h->Fit(func);

      hMean->SetBinContent(i,func->GetParameter(1));
      hMean->SetBinError(i,func->GetParError(1));
      hSigma->SetBinContent(i,func->GetParameter(2));
      hSigma->SetBinError(i,func->GetParError(2));
      
      if(onlySaveTable){
	 h->Delete();
      }
   }
}
예제 #3
0
//------------------------------------------------------------------------
void fitSlices(TH2* hCorr, TF1* func){

   int nBins = hCorr->GetNbinsX();

   TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());
   TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());

   for(int i = 1; i < nBins+1; i++){
      int bin = nBins - i;
      TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i);

      func->SetParameter(0,h->GetMaximum());
      func->SetParameter(1,h->GetMean());
      func->SetParameter(2,h->GetRMS());

      h->Fit(func,"Q");

      /*hMean->SetBinContent(i,func->GetParameter(1));
      hMean->SetBinError(i,func->GetParError(1));
      hSigma->SetBinContent(i,func->GetParameter(2));
      hSigma->SetBinError(i,func->GetParError(2));*/

      hMean->SetBinContent(i,h->GetMean());
      hMean->SetBinError(i,func->GetParError(1)); //errors are not use later for the actual table
      hSigma->SetBinContent(i,h->GetRMS());
      hSigma->SetBinError(i,func->GetParError(2));

   }
}
예제 #4
0
void drawPaPt(){
  
  TCanvas* c1 = new TCanvas("c1","",500,500);
 
  TFile* f1 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr40_to_50_jetPtThr30_20130906.root");
  TH1D* hd1 = (TH1D*)f1->Get("jetPt_icent1_final");
  TFile* f2 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr50_to_60_jetPtThr30_20130906.root");
  TH1D* hd2 = (TH1D*)f2->Get("jetPt_icent1_final");
  TFile* f3 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr60_to_80_jetPtThr30_20130906.root");
  TH1D* hd3 = (TH1D*)f3->Get("jetPt_icent1_final");
  TFile* f4 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr80_to_9999_jetPtThr30_20130906.root");
  TH1D* hd4 = (TH1D*)f4->Get("jetPt_icent1_final");

  TFile* f1m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr40_to_50_jetPtThr30_20130906.root");
  TH1D* hm1 = (TH1D*)f1m->Get("jetPt_icent1_final");
  TFile* f2m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr50_to_60_jetPtThr30_20130906.root");
  TH1D* hm2 = (TH1D*)f2m->Get("jetPt_icent1_final");
  TFile* f3m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr60_to_80_jetPtThr30_20130906.root");
  TH1D* hm3 = (TH1D*)f3m->Get("jetPt_icent1_final");
  TFile* f4m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr80_to_9999_jetPtThr30_20130906.root");
  TH1D* hm4 = (TH1D*)f4m->Get("jetPt_icent1_final");

  double ptBinPaDraw[5] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  TH1D* hd = new TH1D("ptmeanDAta",";p_{T}^{#gamma}; <p_{T}^{Jet}>",4,ptBinPaDraw);
  hd->SetBinContent(1, hd1->GetMean());
  hd->SetBinContent(2, hd2->GetMean());
  hd->SetBinContent(3, hd3->GetMean());
  hd->SetBinContent(4, hd4->GetMean());
  hd->SetBinError(1, hd1->GetMeanError());
  hd->SetBinError(2, hd2->GetMeanError());
  hd->SetBinError(3, hd3->GetMeanError());
  hd->SetBinError(4, hd4->GetMeanError());

  TH1D* hm = new TH1D("ptmeanDAta",";p_{T}^{#gamma}; <p_{T}^{Jet}>",4,ptBinPaDraw);
  hm->SetBinContent(1, hm1->GetMean());
  hm->SetBinContent(2, hm2->GetMean());
  hm->SetBinContent(3, hm3->GetMean());
  hm->SetBinContent(4, hm4->GetMean());
  hm->SetBinError(1, hm1->GetMeanError());
  hm->SetBinError(2, hm2->GetMeanError());
  hm->SetBinError(3, hm3->GetMeanError());
  hm->SetBinError(4, hm4->GetMeanError());



  handsomeTH1(hd,2);
  handsomeTH1(hm,1);
  hm->SetMarkerStyle(24);
  hd->SetAxisRange(30,95,"Y");
  hm->SetAxisRange(30,95,"Y");
  hm->Draw();
  hd->Draw("same");
  TLegend *l1 = new TLegend(0.2399194,0.7288136,0.7862903,0.9322034,NULL,"brNDC");
  easyLeg(l1,"5.02TeV pPb MinBias");
  l1->AddEntry(hd, "DATA","p");
  l1->AddEntry(hm, "MC","p");
  l1->Draw();

  c1->SaveAs("pT_dependence_jetPt_ppb.pdf");
}
예제 #5
0
void takeDirectlyFromMC(TFile* fin, TFile* fout, TString gentype) {

  TList* listOfDirs = fin->GetListOfKeys();
  for (auto k : *listOfDirs) {
    TString srname = k->GetName();
    if (!srname.Contains("sr")) continue;
    if (srname.Contains("base") || srname.Contains("incl") || srname.Contains("sb")) continue;
    if (gentype == "_1lepW" && !srname.EndsWith("2") && !srname.EndsWith("3")) continue;

    auto indir = (TDirectoryFile*) fin->Get(srname);
    auto outdir = (TDirectory*) fout->mkdir(srname);
    auto hlist = indir->GetListOfKeys();

    for (auto h : *hlist) {
      TString hname = h->GetName();
      if (!hname.BeginsWith("h_metbins" + gentype)) continue;
      TH1D* hin = (TH1D*) indir->Get(hname);
      outdir->cd();
      TH1D* hout = (TH1D*) hin->Clone(TString(hname).ReplaceAll(gentype, ""));
      for (int i = 1; i <= hout->GetNbinsX(); ++i) {
        // zero out negative yields
        if (hout->GetBinContent(i) < 0) {
          hout->SetBinContent(i, 0);
          hout->SetBinError(i, 0);
        }
      }
      hout->Write();

      if (yearSeparateSyst && (hname.EndsWith("Up") || hname.EndsWith("Dn"))) {
        for (int i = 1; i < 4; ++i) {
          TH1D* hcen_yi = (TH1D*) fbkgs[i]->Get(srname+"/h_metbins"+gentype);
          TH1D* hsys_yi = (TH1D*) fbkgs[i]->Get(srname+"/"+hname);
          if (hsys_yi && !hcen_yi) {
            cout << "Find " << srname+"/"+hname << " from " << fbkgs[i]->GetName() << " but not hcen " << srname+"/h_metbins"+gentype << " Should not happen?" << endl;
          }
          TH1D* hout_yi = (TH1D*) fin->Get(srname+"/h_metbins"+gentype)->Clone(TString(hname).Insert(hname.Length()-2, Form("%d", 15+i)).ReplaceAll(gentype, ""));
          if (hcen_yi) hout_yi->Add(hcen_yi, -1);
          if (hsys_yi) hout_yi->Add(hsys_yi);
          hout_yi->Write();
        }
      }
    }
    if (!outdir->Get("h_metbins")) {
      cout << "Didn't find yield hist for " << gentype << " in " << fin->GetName() << ":" << srname << "/. Faking a 0 one!" << endl;
      outdir->cd();
      // Get the MET binning from h_metbins, which shall always exist, and then set all bins to 0
      TH1D* hout = (TH1D*) fin->Get(srname + "/h_metbins")->Clone("h_metbins");
      for (int i = 1; i <= hout->GetNbinsX(); ++i) {
        hout->SetBinContent(i, 0);
        hout->SetBinError(i, 0);
      }
      hout->Write();
    }
  }
}
예제 #6
0
void ptDependence()
{
   TFile *inf = new TFile("histos/ppMC.root");
   TTree *t = (TTree*) inf->Get("nt");

   const int nBins = 4;
   double ptBin[nBins+1] = {100,120,140,160,200};
//   const int nBins = 1;
//   double ptBin[nBins+1] = {100,400};
   
   TH1D *hProb = new TH1D("hProb","",nBins,ptBin);
   TH1D *hCSV = new TH1D("hCSV","",nBins,ptBin);
   TH1D *hSVTXM = new TH1D("hSVTXM","",nBins,ptBin);
   TProfile *pGen = new TProfile("pGen","",nBins,ptBin);
   
   for (int n=0; n<nBins;n++)
   {
      RooRealVar f1 = bfractionFit("discr_prob",0,3.5,ptBin[n],ptBin[n+1]);
      RooRealVar f2 = bfractionFit("discr_csvSimple",0,1,ptBin[n],ptBin[n+1]);
      RooRealVar f3 = bfractionFit("svtxm",0,6,ptBin[n],ptBin[n+1]);
      hProb->SetBinContent(n+1,f1.getVal());    
      hProb->SetBinError(n+1,f1.getError());    
      hCSV->SetBinContent(n+1,f2.getVal());    
      hCSV->SetBinError(n+1,f2.getError());    
      hSVTXM->SetBinContent(n+1,f3.getVal());    
      hSVTXM->SetBinError(n+1,f3.getError());    
   }
   
   TCanvas *c2 = new TCanvas("c2","",600,600);
   hProb->SetAxisRange(0,0.05,"Y");
   hProb->SetXTitle("Jet p_{T} (GeV/c)");
   hProb->SetYTitle("b-jet fraction");
   hProb->SetTitleOffset(1.5,"Y");
   hProb->Draw();
   hCSV->SetLineColor(2);
   hCSV->SetMarkerColor(2);
   hCSV->SetMarkerStyle(24);
   hCSV->Draw("same");
   hSVTXM->SetLineColor(4);
   hSVTXM->SetMarkerColor(4);
   hSVTXM->SetMarkerStyle(24);
//   hSVTXM->Draw("same");
   t->Draw("abs(refparton_flavorForB)==5:jtpt","","prof same");
   
   TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   leg->SetFillColor(0);
   leg->AddEntry(hProb,"Jet Probability","pl");
   leg->AddEntry(hCSV,"CSV","pl");
//   leg->AddEntry(hSVTXM,"SV mass","pl");
   leg->Draw();
}
예제 #7
0
파일: residu.C 프로젝트: star-bnl/star-sti
// Loop through detector layers to report 
// various parameters
residu(TString baseName, double min=-1.5, double max=1.5)
{
  double xMin, xMax;
  TString name;
  name = baseName;
  name += "_a";     TH1D * amp  = new TH1D(name,name,55,0,54.);
  name = baseName;
  name += "_mean";  TH1D * mean = new TH1D(name,name,55,0,54.);
  name = baseName;
  name += "_rms";   TH1D * rms = new TH1D(name,name,55,0,54.);
  TString thisL;
  TH1D *h=0;
  TF1 * f;
  int ii;
  for(int i=0; i<51;i++)
    {
      thisL=baseName+i;
      if (i<6)
	{
	  xMin = -0.2;
	  xMax = 0.2;
	}
      else
	{
	  xMin = min;
	  xMax = max;
	}
      h=(TH1D*)gDirectory->Get(thisL);
      h->Fit("gaus","","",xMin,xMax);
      double entries = h->GetEntries();
      if (entries>0)
	{
	  ii = i+1;
	  f = h->GetFunction("gaus");
	  double a = f->GetParameter("Constant"); double ea = f->GetParError(0);
	  double m = f->GetParameter("Mean");double em = f->GetParError(1);
	  double r = f->GetParameter("Sigma");double er = f->GetParError(2);
	  amp->SetBinContent(ii,a);amp->SetBinError(ii,ea);
	  mean->SetBinContent(ii,m);mean->SetBinError(ii,em);
	  rms->SetBinContent(ii,r);rms->SetBinError(ii,er);
	}
    }
  cout << "Fitting completed" << endl;

  c1->Clear();
  c1->Divide(1,3);
  c1->cd(1); amp->Draw();
  c1->cd(2); mean->Draw();
  c1->cd(3); rms->Draw();
  
}
예제 #8
0
TH1D *
GetITSTPCSpectrum(TFile *file, Int_t part, Int_t charge, Int_t cent)
{
  TList *list = (TList *)file->Get("output");
  TH1D *hin = (TH1D *)list->FindObject(Form("h_%s_%s_cen_%d", ITSTPCPartName[part], ITSTPCChargeName[charge], cent + 1));
  if (!hin) return NULL;

  TH1D *h = new TH1D(Form("hITSTPC_cent%d_%s_%s", cent, AliPID::ParticleName(part), chargeName[charge]), "ITSTPC", NptBins, ptBin);
  Double_t pt, width, value, error;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }
  
#if 0
  /* add systematic error */
  Double_t sys;
  if (part == 2) sys = 0.5;
  else sys = 0.1;
  Double_t cont, conte;
  for (Int_t ipt = 0; ipt < h->GetNbinsX(); ipt++) {
    cont = h->GetBinContent(ipt + 1);
    conte = h->GetBinError(ipt + 1);
    conte = TMath::Sqrt(conte * conte + sys * sys * cont * cont);
    h->SetBinError(ipt + 1, conte);
  }
#endif
  
  h->SetTitle("ITSTPC");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(21);
  h->SetMarkerColor(2);
  h->SetFillStyle(0);
  h->SetFillColor(0);
  return h;
}
void GaussianProfile::getTruncatedMeanRMS(TH1* hist, float& mean, float& mean_error, float& rms, float& rms_error) {
  int nBins = hist->GetNbinsX();
  double xMin = hist->GetXaxis()->GetXmin();
  double xMax = hist->GetXaxis()->GetXmax();
  //double binWidth = (xMax - xMin) / (double) nBins; //WARNING: this works only if bins are of the same size
  double integral = hist->Integral();

  int maxBin = 0;
  TF1* gaussian = new TF1("gaussian", "gaus");
  fitProjection(hist, gaussian, 1.5, "RQN");
  //maxBin = (int) ceil((gaussian->GetParameter(1) - xMin) / binWidth);
  maxBin = hist->FindBin(gaussian->GetParameter(1));
  delete gaussian;

  TH1D* newHisto = new TH1D("newHisto", "", nBins, xMin, xMax);
  newHisto->SetBinContent(maxBin, hist->GetBinContent(maxBin));
  newHisto->SetBinError(maxBin, hist->GetBinError(maxBin));
  int iBin = maxBin;
  int delta_iBin = 1;
  int sign  = 1;

  while (newHisto->Integral() < 0.99 * integral) {
    iBin += sign * delta_iBin;

    newHisto->SetBinContent(iBin, hist->GetBinContent(iBin));
    newHisto->SetBinError(iBin, hist->GetBinError(iBin));

    delta_iBin += 1;
    sign *= -1;
  }

  rms = newHisto->GetRMS();
  rms_error = newHisto->GetRMSError();

  while (newHisto->Integral() < 0.99 * integral) {
    iBin += sign * delta_iBin;

    newHisto->SetBinContent(iBin, hist->GetBinContent(iBin));
    newHisto->SetBinError(iBin, hist->GetBinError(iBin));

    delta_iBin += 1;
    sign *= -1;
  }

  mean = newHisto->GetMean();
  mean_error = newHisto->GetMeanError();

  delete newHisto;
}
예제 #10
0
void MergeOverflow(TH1D &h, bool merge_underflow, bool merge_overflow) {
    if(merge_underflow) {
        h.SetBinContent(1, h.GetBinContent(0)+h.GetBinContent(1));
        h.SetBinContent(0, 0.);
        h.SetBinError(1, hypot(h.GetBinError(0), h.GetBinError(1)));
        h.SetBinError(0, 0.);
    }
    int nbins = h.GetNbinsX();
    if(merge_overflow) {
        h.SetBinContent(nbins, h.GetBinContent(nbins)+h.GetBinContent(nbins+1));
        h.SetBinContent(nbins+1, 0.);
        h.SetBinError(nbins, hypot(h.GetBinError(nbins), h.GetBinError(nbins+1)));
        h.SetBinError(nbins+1, 0.);
    }
}
예제 #11
0
void doJob(std::string name,std::string nominame){
	std::vector<TH1D*> histUp = hists("up","Up");
	std::vector<TH1D*> histDown = hists("down","Down");
	TH1D * nominal = GetNominal(nominame);
	TH1D * h = new TH1D(name.c_str(), name.c_str(), histUp[0]->GetXaxis()->GetNbins(), -1.,1.);
	cout<<"before loop "<<h->GetXaxis()->GetNbins()<<endl;
	for(int iBin = 0; iBin < h->GetXaxis()->GetNbins(); iBin++){
		double sum = 0;
		cout<<"Bin "<<iBin+1<<"\t"<<histDown.size()<<"\t"<<histUp.size()<<endl;
		for(unsigned int i = 0; i < histDown.size(); i++){
			cout<<"---------- file "<< i+1<<"\t"<<histDown[i]<<"\t"<<histUp[i]<<endl;
			cout<<nominal->GetBinContent(iBin + 1)<<"\t"<<histDown[i]->GetXaxis()->GetNbins()<<endl;
			cout<<"\t"<<histUp[i]->GetBinContent(iBin + 1)<<endl;
			cout<<histDown[i]->GetBinContent(iBin + 1); 
			double iDown = fabs(histDown[i]->GetBinContent(iBin + 1) - nominal->GetBinContent(iBin + 1));
			double iUp = fabs(histUp[i]->GetBinContent(iBin + 1) - nominal->GetBinContent(iBin + 1));
			double iAvg = (iUp + iDown)/2.;
			sum+= pow(iAvg,2);
			cout<<iDown<<"\t"<<iUp<<"\t"<<iAvg<<"\t"<<sum<<endl;
		}
		h->SetBinContent(iBin + 1, nominal->GetBinContent(iBin + 1));
		h->SetBinError(iBin + 1, sqrt(sum));
	}
	cout<<"After loop"<<endl;
	TFile * final = new TFile(name.c_str(),"recreate");
	TDirectory * d = final->mkdir("Default_allW");
	h->SetName("Default_allWcosTheta");
	d->cd();
	h->Write();
	final->Close();
예제 #12
0
TH1D* returnRelDiff(TH1D* h, TH1D* b, TString name) {
  TH1D* hRelDiff = new TH1D(name, "", h->GetNbinsX(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
  hRelDiff->SetLineColor(h->GetLineColor());
  hRelDiff->SetLineStyle(h->GetLineStyle());
  hRelDiff->SetLineWidth(h->GetLineWidth());

  hRelDiff->GetYaxis()->SetTitleOffset(0.42);
  hRelDiff->GetYaxis()->SetTitleSize(0.13);
  hRelDiff->GetYaxis()->SetLabelSize(0.10);
  hRelDiff->GetXaxis()->SetTitleOffset(1.2);
  hRelDiff->GetXaxis()->SetTitleSize(0.13);
  hRelDiff->GetXaxis()->SetLabelSize(0.12);
  //hRelDiff->GetXaxis()->CenterTitle();                                                                                   
  hRelDiff->GetYaxis()->CenterTitle();
  hRelDiff->GetYaxis()->SetNdivisions(303,kTRUE);

  // (mc-data)/mc, uncertainty is √data
  for (Int_t i=1; i<h->GetNbinsX()+1; i++) {
    Double_t y = b->GetBinContent(i);
    Double_t val = h->GetBinContent(i) - y;
    if (y!=0) { hRelDiff->SetBinContent(i, val/h->GetBinContent(i)); hRelDiff->SetBinError(i,TMath::Sqrt(b->GetBinContent(i))/h->GetBinContent(i)); }
    else hRelDiff->SetBinContent(i, 0);
  }
  return hRelDiff;
}
예제 #13
0
TH1D* ratio_hist_to_func(TH1D* num, double par0, double par1, double par2) {
    cout<<"[Ratio to fit used]"<<endl;

    TH1D *hRatio = (TH1D*) num->Clone("hRatio");

    TF1 *f3 = new TF1("f3","[0]*(1+(sqrt(0.1396**2+x**2)-0.1396)/([1]*[2]))**(-[2])",0,6.5);
    f3->SetParameters(par0,par1,par2);
    //f3->SetLineColor(2);

    int nbin = num->GetEntries();
    for(int i=0; i<nbin; i++) {

        double cms_value = (double) f3->Eval(hRatio->GetBinCenter(i+1));

        if(hRatio->GetBinCenter(i+1)>0.4 && hRatio->GetBinCenter(i+1)<6.0) {
            //double ratio = cms_value/hRatio->GetBinContent(i+1);
            //double ratio_err = cms_value/hRatio->GetBinError(i+1);
            double ratio = hRatio->GetBinContent(i+1)/cms_value;
            double ratio_err = hRatio->GetBinError(i+1)/cms_value;
        } else {
            double ratio = -999;
            double ratio_err = 0.0;
        }
        //double ratio = hRatio->GetBinContent(i+1)/cms_value;
        //double ratio_err = hRatio->GetBinError(i+1)/cms_value;
        hRatio->SetBinContent(i+1,ratio);
        hRatio->SetBinError(i+1,ratio_err);
    }

    return hRatio;

}
예제 #14
0
파일: fitBarea.C 프로젝트: KiSooLee/Bntuple
void fitBarea(TString infname="",bool doweight = 1)
{
  if (doweight==0) weight="1";
  if (infname=="") infname=inputdata.Data();
  TFile *inf = new TFile(infname.Data());
  TTree *nt = (TTree*) inf->Get("ntKp");

  TFile *infMC = new TFile(inputmc.Data());
  TTree *ntGen = (TTree*)infMC->Get("ntGen");
  TTree *ntGen2 = (TTree*)inf->Get("ntGen");
  TTree *ntMC = (TTree*)infMC->Get("ntKp");
    
  ntGen->AddFriend(ntMC);
  ntGen2->AddFriend(ntMC);
    
  const int nBins = 1;
  double ptBins[nBins+1] = {10,60};
//  const int nBins = 1;
//  double ptBins[nBins+1] = {10,60};
  TH1D *hPt = new TH1D("hPt","",nBins,ptBins);

  for (int i=0;i<nBins;i++)
    {
      TF1 *f = fit(nt,ntMC,ptBins[i],ptBins[i+1]);
      double yield = f->Integral(5,6)/0.02;
      double yieldErr = f->Integral(5,6)/0.02*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
    }
  
}
예제 #15
0
파일: fitWm.C 프로젝트: ksung25/UserCode
//--------------------------------------------------------------------------------------------------
TH1D *makeDiffHist(TH1D* hData, TH1D* hFit, const TString name)
{
  TH1D *hDiff = new TH1D(name,"",hData->GetNbinsX(),hData->GetXaxis()->GetXmin(),hData->GetXaxis()->GetXmax());
  for(Int_t ibin=1; ibin<=hData->GetNbinsX(); ibin++) {
    
    Double_t diff = (hData->GetBinContent(ibin)-hFit->GetBinContent(ibin));
    
    Double_t err = sqrt(hData->GetBinContent(ibin));
    if(err==0) err= sqrt(hFit->GetBinContent(ibin));
    
    if(err>0) hDiff->SetBinContent(ibin,diff/err);
    else      hDiff->SetBinContent(ibin,0);
    hDiff->SetBinError(ibin,1);   
  }
  
  hDiff->GetYaxis()->SetTitleOffset(0.42);
  hDiff->GetYaxis()->SetTitleSize(0.13);
  hDiff->GetYaxis()->SetLabelSize(0.10);
  hDiff->GetYaxis()->SetNdivisions(104);
  hDiff->GetYaxis()->CenterTitle();
  hDiff->GetXaxis()->SetTitleOffset(1.2);
  hDiff->GetXaxis()->SetTitleSize(0.13);
  hDiff->GetXaxis()->SetLabelSize(0.12);
  hDiff->GetXaxis()->CenterTitle();
  
  return hDiff;
}
예제 #16
0
TH1D *makeDiffHist(TH1D* hData, TH1D* hFit, const TString name)
{
  TH1D *hDiff = (TH1D*)hData->Clone("hDiff");
  hDiff->SetName(name);
  for(Int_t ibin=1; ibin<=hData->GetNbinsX(); ibin++) {
    
    Double_t diff=0;
    Double_t err=0;
    if(hData->GetBinContent(ibin)!=0)
      {
	diff = hFit->GetBinContent(ibin)/hData->GetBinContent(ibin);
	err = hFit->GetBinError(ibin)/hData->GetBinContent(ibin);
      }
    hDiff->SetBinContent(ibin,diff);
    hDiff->SetBinError(ibin,err);   
  }
  
  hDiff->GetYaxis()->SetTitleOffset(0.55);
  hDiff->GetYaxis()->SetTitleSize(0.13);
  hDiff->GetYaxis()->SetLabelSize(0.10);
  hDiff->GetYaxis()->SetNdivisions(104);
  hDiff->GetYaxis()->CenterTitle();
  hDiff->GetXaxis()->SetTitleOffset(1.2);
  hDiff->GetXaxis()->SetTitleSize(0.13);
  hDiff->GetXaxis()->SetLabelSize(0.12);
  hDiff->GetXaxis()->CenterTitle();
  
  return hDiff;
}
예제 #17
0
void QinvKstar (const char* filename, const char* histname) {

	TFile*  fileIn = new TFile(filename,"update");
	TH1D* hist = (TH1D*)fileIn->Get(histname);
	TH1D* histnew = new TH1D(Form("kstar_%s",histname),"",hist->GetNbinsX(),0,0.25);//(TH1D*)fileIn->Get(histname);

//   for (int ibins = 1; ibins <= hist->GetNbinsX()*2; ibins++ ) {
//     hist->SetBinContent(ibins, hist->GetBinContent(ibins));
//     //    hist->SetBinContent(ibins, hist->GetBinContent(ibins));
//   }

	int bin=2;//1

	for (double kstar = 0.00375; kstar <= 0.25; kstar += 0.0025 ) {

//	for (double kstar = 0.00375; kstar <= 0.25; kstar += 0.0025 ) {
		//  for (double kstar = 0.005; kstar <= 0.25; kstar += 0.01 ) {
		//        hist->Fill(kstar,hist->GetBinContent(hist->FindBin(kstar*2)));

		histnew->SetBinContent(bin,hist->GetBinContent(hist->FindFixBin(kstar*2)));
		histnew->SetBinError(bin++,hist->GetBinError(hist->FindFixBin(kstar*2)));

		//    hist->SetBinContent(ibins, hist->GetBinContent(ibins));
		//    hist->SetBinContent(ibins, hist->GetBinContent(ibins));
	}

	TFile* fileOut = new TFile(Form("kstar_%s",filename), "update");
	hist->Write();
	histnew->Write();
}
예제 #18
0
void drawPaEta( bool saveFigures=false) {
  TFile * fData = new TFile("../histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr40_to_9999_jetPtThr30_20130829.root");
  TH1D* hD1 = (TH1D*)fData->Get("etaJg_icent1_final");
  TH1D* hD2 = (TH1D*)fData->Get("etaJg_icent2_final");
  TH1D* hD3 = (TH1D*)fData->Get("etaJg_icent3_final");

  TFile * fMC = new TFile("../histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr40_to_9999_jetPtThr30_20130829.root");
  TH1D* hM1 = (TH1D*)fMC->Get("etaJg_icent1_final");
  TH1D* hM2 = (TH1D*)fMC->Get("etaJg_icent2_final");
  TH1D* hM3 = (TH1D*)fMC->Get("etaJg_icent3_final");

  TCanvas* c1 = new TCanvas("c1","",500,500);
  handsomeTH1(hD1,1);
  handsomeTH1(hD2,4);
  handsomeTH1(hD3,2);
  hD1->Rebin(10);
  hD2->Rebin(10);
  hD3->Rebin(10);

  hD1->Draw();
  hD2->Draw("same");
  hD3->Draw("same");

  TCanvas* c2 = new TCanvas("c2","",400,400);
  TH1D* hmData = new TH1D("hmData",";HF energy;",nCentBinPa,centBinPa);
  hmData->SetBinContent(1, hD1->GetMean());
  hmData->SetBinContent(2, hD2->GetMean());
  hmData->SetBinContent(3, hD3->GetMean());
  hmData->SetBinError(1, hD1->GetMeanError());
  hmData->SetBinError(2, hD2->GetMeanError());
  hmData->SetBinError(3, hD3->GetMeanError());
  TH1D* hmMc = new TH1D("hmMc",";HF energy;",nCentBinPa,centBinPa);
  hmMc->SetBinContent(1, hM1->GetMean());
  hmMc->SetBinContent(2, hM2->GetMean());
  hmMc->SetBinContent(3, hM3->GetMean());
  hmMc->SetBinError(1, hM1->GetMeanError());
  hmMc->SetBinError(2, hM2->GetMeanError());
  hmMc->SetBinError(3, hM3->GetMeanError());
  handsomeTH1(hmData,2);
  handsomeTH1(hmMc,1);
  hmMc->SetMarkerStyle(24);
  hmMc->Draw();
  hmData->Draw("same");
  

}
void transferxSecFromTextToROOT(std::string inputStr="xSec_T3G.txt"){

   ifstream fin(inputStr.c_str());
   char line[200];
   TFile *xSecProspinoFile =0;
   TH1D *xSecProspino =0; 
   int minMom = 1000000, maxMom = 0;
   int nBins = 0;

   std::vector<int> momVec; std::vector<double> xSecVec, xSecErrVec;
   while( fin.getline(line, 200) ){
      TString lineT(line);
      if( lineT.Contains("Interactions") ) continue;
      TObjArray *vlist = lineT.Tokenize(" ");
      int nEntries = vlist->GetEntries();
      int mMom;
      double xSec =0, xSecRelErr =0;
      for(int ie=0; ie<nEntries; ie++){
         TObjString* perObj = dynamic_cast<TObjString*>(vlist->At(ie));
         TString perStr = perObj->GetString();
         if( ie==0 ){
            mMom = perStr.Atoi();
            if( minMom > mMom ) minMom = mMom;
            if( maxMom < mMom ) maxMom = mMom;
         }
         if( ie==1 ) xSec = perStr.Atof();
         if( ie==2 ) xSecRelErr = perStr.Atof();
      }
      nBins ++;
      momVec.push_back(mMom); xSecVec.push_back(xSec); xSecErrVec.push_back(xSec*xSecRelErr/100.);
//      std::cout<<"mMom : "<<mMom<<"  xSec : "<<xSec<<"  xSecRelErr : "<<xSecRelErr<<std::endl;
   }
   double divBin = 1.0*(maxMom - minMom)/(nBins-1);
   double lowMom = minMom-divBin/2.0, highMom = maxMom+divBin/2.0;
   std::cout<<"nBins : "<<nBins<<"  minMom : "<<minMom<<"  maxMom : "<<maxMom<<"  divBin : "<<divBin<<"  lowMom : "<<lowMom<<"  highMom : "<<highMom<<std::endl;

   TString rootStrT(inputStr);
   rootStrT.ReplaceAll("txt", "root");

   std::cout<<"root file : "<<rootStrT<<std::endl;
   xSecProspinoFile = new TFile(rootStrT, "RECREATE");

   if( rootStrT.Contains("T1") ) xSecProspino = new TH1D("gluino_xsection", "gluino_xsection", nBins, lowMom, highMom);
   if( rootStrT.Contains("T2") ) xSecProspino = new TH1D("squark_xsection", "squark_xsection", nBins, lowMom, highMom);
   if( rootStrT.Contains("T3G") ) xSecProspino = new TH1D("stop_xsection", "stop_xsection", nBins, lowMom, highMom);

   for(int iv=0; iv<(int)momVec.size(); iv++){
      double mMom = (double)momVec[iv];
      int ib = xSecProspino->FindFixBin(mMom);
      xSecProspino->SetBinContent(ib, xSecVec[iv]);
      xSecProspino->SetBinError(ib, xSecErrVec[iv]);
   }

//   xSecProspino->Write();
   xSecProspinoFile->Write(); xSecProspinoFile->Close();

}
예제 #20
0
// Draw 1D histos
TH1D *plot1Dhisto(double intLumi,TFile *fileName,TString folderName,TString histoName,int color,int rebin,float xMin,float xMax,TString xName, TString yName,TString sampleName,bool mc) {  
  
  TH1D *hTemp = (TH1D*)fileName->Get(folderName+"/"+histoName);
  hTemp->SetName(histoName+"_"+sampleName);
  if (mc){ 
    hTemp->Scale(intLumi/100.);
  }
  hTemp->Rebin(rebin);
  hTemp->SetLineColor(color);
  hTemp->SetLineWidth(5);
  hTemp->GetXaxis()->SetRangeUser(xMin,xMax);
  hTemp->GetXaxis()->SetTitle(xName);
  hTemp->GetXaxis()->SetTitleSize(0.06);
  hTemp->GetXaxis()->SetLabelSize(0.06);
  hTemp->GetYaxis()->SetTitle(yName);
  hTemp->GetYaxis()->SetTitleSize(0.06);
  hTemp->GetYaxis()->SetLabelSize(0.06);
  hTemp->SetTitleOffset(1.5, "Y");
  // last/first bin: put over/underflow
  hTemp->SetBinContent(hTemp->FindBin(xMax),hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1));
  hTemp->SetBinContent(hTemp->FindBin(xMin),hTemp->Integral(-1,hTemp->FindBin(xMin)));  

  hTemp->SetBinError(hTemp->FindBin(xMax),sqrt(hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1)));
  hTemp->SetBinError(hTemp->FindBin(xMin),sqrt(hTemp->Integral(-1,hTemp->FindBin(xMin))));
  //fileName->Close();

  /*
  if (histoName != "LP_tot") {
    if (histoName != "SumLepPt_tot") {
      if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,300.); } 
      if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,400.); }
      if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,500.); }
      if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,1000.); }
    }
    else {
      if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(100.,300.); } 
      if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(200.,400.); }
      if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(300.,500.); }
      if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(400.,1000.); }
    }
  } 
  */ 
  return hTemp;
} // ~ end of plot1Dhisto function
TH1D* Prediction::GetScaledHisto(TH1D* histo, float scale_fact, float scale_fact_err){
	// takes histo, scale factor and uncertainty on scale factor
	// and returns scaled and rebinned histo with 1 bin with uncertainty on scale factor propagated.
	TH1D *h        = (TH1D*) histo->Clone(histo->GetName());
	h->Rebin(h->GetNbinsX());
	h->SetBinError(1, sqrt(h->GetBinError(1)*  h->GetBinError(1)   *scale_fact    *scale_fact + 
			  h->GetBinContent(1)*h->GetBinContent(1) *scale_fact_err*scale_fact_err));
	h->SetBinContent(1, h->GetBinContent(1)*scale_fact);
	return h;
}
예제 #22
0
// A function to make a new histogram by combining the contents of selected
// consecutive bins in an input histogram.  Useful to produce variable-bin-size
// histograms from fixed-bin-size ones, particularly for regions of phase space
// which lack statistics.
TH1D* CombineBins(TH1D inhisto, float xmin, float xmax)
{
  int startbin = inhisto.FindBin(xmin);
  int endbin = inhisto.FindBin(xmax);

  if (startbin >= endbin) return 0;

  const int newNbins = inhisto.GetNbinsX() - endbin + startbin;

  Double_t edgeArr[newNbins+1];

  for (int i=0; i<=newNbins; ++i) {
    int skipbin = 0;
    if (i>=startbin) skipbin = endbin - startbin;
    edgeArr[i] = inhisto.GetBinLowEdge(i+1+skipbin);
  }

  TH1D *newhist = new TH1D("newhist",inhisto.GetTitle(),newNbins,edgeArr);
  newhist->GetYaxis()->SetTitle(inhisto.GetYaxis()->GetTitle());
  newhist->GetXaxis()->SetTitle(inhisto.GetXaxis()->GetTitle());
  bool sw2 = ( inhisto.GetSumw2N() != 0 );

  // Starting from the new underflow bin, up to the new overflow bin,
  // copy contents for the "untouched" bins. For the new "combination"
  // bin, copy only the startbin
  for (int i=0; i<=newNbins+1; ++i) {
    int skipbin = 0;
    if (i>startbin) skipbin = endbin - startbin;
    newhist->SetBinContent(i, inhisto.GetBinContent(i+skipbin));
    if ( sw2 ) newhist->SetBinError(i, inhisto.GetBinError(i+skipbin));
  }

  // Now we have to handle the "combination" bin. We need to add
  // everything from startbin+1 to endbin. 
  for (int i=startbin+1; i<=endbin; ++i) {
    newhist->SetBinContent(startbin, newhist->GetBinContent(startbin)
			   +inhisto.GetBinContent(i));
    if ( sw2 ) newhist->SetBinError(startbin, sqrt(pow(newhist->GetBinError(startbin),2)+
						   pow(inhisto.GetBinError(i),2)));
  }

  return newhist;
}
예제 #23
0
TH1D * getNiceHistogram(int nbins, std::vector<Double_t> binning, TFile * file, TString hist) {
  TH1D *sample = (TH1D*)(file->Get(hist)->Clone());
  TH1D *binned = dynamic_cast<TH1D*>(sample->Rebin(nbins,"madgraph",&binning.front()));
  for (Int_t bin=0; bin < nbins; bin++) {
    // Divide rebinned histogram's bin content by bin width factor (new/old):
    binned->SetBinError(bin+1,sqrt(binned->GetBinContent(bin+1))/((binning.at(bin+1)-binning.at(bin))/sample->GetBinWidth(1)));
    binned->SetBinContent(bin+1,binned->GetBinContent(bin+1)/((binning.at(bin+1)-binning.at(bin))/sample->GetBinWidth(1)));
  }
  binned->Scale(1/binned->Integral("width"));
  return binned;
}
TH1D *getErrorBand(TH1* h)
{
   TH1D *hErr = (TH1D*) h->Clone();
   hErr->SetName("hErr");
   for (int i=0;i<h->GetNbinsX();i++) {
      double var = h->GetBinContent(i);
      double varErr = h->GetBinError(i);
      hErr->SetBinContent(i,var);
      hErr->SetBinError(i,var*0.1);
   }
   return hErr;
}
예제 #25
0
파일: cdcHits.C 프로젝트: noemi8a/sim-recon
void cdcHits(void)
{
	gROOT->Reset();
	gStyle->SetErrorX(0.0);

	TCanvas *c1 = new TCanvas("c1");
	c1->SetTicky();
	c1->SetTickx();
	c1->SetGridy();
	c1->Draw();
	
	TFile *f = new TFile("cdc_hits.root");
	TTree *t = (TTree*)gROOT->FindObject("cdcHits");
	double Nevents_thrown = (double)t->GetEntries();
	double timewindow = 1.0E-6;
	double total_integrated_time = timewindow*Nevents_thrown;
	double tagged_rate = 1.0E7;
	cout<<"Number of events thrown: "<<(int)Nevents_thrown<<endl;
	cout<<"Assuming "<<timewindow/1.0E-6<<" microsecond time window"<<endl;
	cout<<"Total beam time represented by simulation:"<<total_integrated_time<<" seconds"<<endl;
	cout<<"Assuming rates correspond to "<<tagged_rate<<" tagged photons/sec beam"<<endl;
	
	// Number of straws in each "ring"
	int n_straws[]={43,50,57,64,71,78,85,99,106,113,120,127,134,141,148,155,166,173,182,187,194,201,208,215,222};
	
	TH1D *nstraws = new TH1D("nstraws","Straws per ring", 25, 0.5, 25.5);
	for(int i=0;i<25; i++){
		nstraws->SetBinContent(i+1, n_straws[i]);
		nstraws->SetBinError(i+1, 0.0);
	}

	TH1D *hits_per_straw = new TH1D("hits_per_straw","CDC Hits per layer", 25, 0.5, 25.5);
	t->Project("hits_per_straw","ring");
	hits_per_straw->Divide(nstraws);
	
	TH1D *rate_per_straw = hits_per_straw->Clone("rate_per_straw");
	char str[256];
	sprintf(str, "Rate per straw at %g tags/sec (kHz)", tagged_rate);
	rate_per_straw->Scale(1.0E-3/total_integrated_time);
	rate_per_straw->SetXTitle("CDC layer");
	rate_per_straw->SetYTitle(str);
	rate_per_straw->SetStats(0);
	rate_per_straw->SetLineColor(kRed);
	rate_per_straw->SetLineWidth(2.0);
	rate_per_straw->SetMarkerColor(kRed);
	rate_per_straw->SetMarkerStyle(20);
	rate_per_straw->SetMarkerSize(1.5);
	rate_per_straw->Draw("P");
	
	c1->SaveAs("cdc_hit_rate.gif");
	c1->SaveAs("cdc_hit_rate.pdf");
}
TH1D* Prediction::GetScaledHisto(TH1D* histo, float scale_fact, float scale_fact_err, int ngroup){
	// takes histo, scale factor and uncertainty on scale factor
	// and returns scaled and rebinned histo with ngroup bins merged into 1 with uncertainty on scale factor propagated.
	if(ngroup>=histo->GetNbinsX()) ngroup=histo->GetNbinsX();
	TH1D *h        = (TH1D*) histo->Clone(histo->GetName());
	h->Rebin(ngroup);
	for(int i=1; i<=h->GetNbinsX(); ++i){
		h->SetBinError(i, sqrt(h->GetBinError(i)*  h->GetBinError(i)   *scale_fact    *scale_fact + 
				  h->GetBinContent(i)*h->GetBinContent(i) *scale_fact_err*scale_fact_err));
		h->SetBinContent(i, h->GetBinContent(i)*scale_fact);
	}
	return h;
}
예제 #27
0
  TH1D* GetRatio(TH1D* hEM,TH1D* hME,double xmin, double xmax)
  {
  	TH1D* ratio = (TH1D*)hEM->Clone("ratio");
  	ratio->Divide(hME);
//  	ratio->GetYaxis()->SetTitle("Ratio"); //ratio->SetTitleFont(64);
  	ratio->GetYaxis()->SetTitle("Ratio"); ratio->GetYaxis()->SetTitleSize(0.1);
  	ratio->GetYaxis()->SetTitleOffset(0.3);
  	ratio->GetYaxis()->CenterTitle();
//  	ratio->SetTitleSize(0.1);
  	ratio->GetXaxis()->SetRangeUser(xmin,xmax); ratio->SetLineColor(kBlack);
  	ratio->GetYaxis()->SetRangeUser(0,2);
  	ratio->SetLineWidth(2); ratio->SetMarkerStyle(8); ratio->SetMarkerSize(0.7);
  	ratio->SetMarkerColor(kBlack);
  	ratio->GetXaxis()->SetTitle("M_{coll} (GeV)"); ratio->GetXaxis()->SetTitleSize(0.15);
  	ratio->GetXaxis()->SetTitleOffset(0.8);
	ratio->GetXaxis()->SetLabelOffset();
  	ratio->GetYaxis()->SetLabelSize(0.1);
  	ratio->GetYaxis()->SetNdivisions(5);
  	ratio->GetXaxis()->SetLabelSize(0.1);

  	ratio->GetXaxis()->SetRangeUser(xmin,xmax);
  	for (int i=1; i<=hEM->GetXaxis()->FindBin(99); i++){
  		double n = hEM->GetBinContent(i);
  		double m = hME->GetBinContent(i);
  		double deltaN = hEM->GetBinError(i);
  		double deltaM = hME->GetBinError(i);
  		double err = (1./m)*TMath::Sqrt(TMath::Power(deltaN,2)+TMath::Power(n*deltaM/m,2));
  		ratio->SetBinError(i,err);
  	}
	for (int i=hEM->GetXaxis()->FindBin(151); i<=hEM->GetXaxis()->GetNbins(); i++){
  		double n = hEM->GetBinContent(i);
  		double m = hME->GetBinContent(i);
  		double deltaN = hEM->GetBinError(i);
  		double deltaM = hME->GetBinError(i);
  		double err = (1./m)*TMath::Sqrt(TMath::Power(deltaN,2)+TMath::Power(n*deltaM/m,2));
  		ratio->SetBinError(i,err);
  	}
  	return ratio;
  }
예제 #28
0
TH1D *
GetITSsaSpectrum(TFile *file, Int_t part, Int_t charge, Int_t cent, Bool_t cutSpectrum = kTRUE, Bool_t addSystematicError = kTRUE)
{
  /* pt limits for combined spectra */
  Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0.1, 0.2, 0.3};
  Double_t ptMax[AliPID::kSPECIES] = {0., 0., 0.6, 0.5, 0.6};

  TList *list = (TList *)file->Get("output");
  TH1D *hin = (TH1D *)list->FindObject(Form("h_%s_%s_cen_%d", ITSsaPartName[part], ITSsaChargeName[charge], cent));
  if (!hin) return NULL;  

  /* get systematics */
  TFile *fsys = TFile::Open("SPECTRASYS_ITSsa.root");
  TH1 *hsys = fsys->Get(Form("hSystTot%s%s", ITSsaChargeName[charge], ITSsaPartName[part]));
			
  TH1D *h = new TH1D(Form("hITSsa_cent%d_%s_%s", cent, AliPID::ParticleName(part), chargeName[charge]), "ITSsa", NptBins, ptBin);
  Double_t pt, width, value, error, sys;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* check pt limits */
    if (cutSpectrum && (pt < ptMin[part] || pt > ptMax[part])) continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    /*** TEMP ADD SYS ***/
    if (addSystematicError) {
      sys = hsys->GetBinContent(bin) * value;
      error = TMath::Sqrt(error * error + sys * sys);
    }
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }

  h->SetTitle("ITSsa");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(20);
  h->SetMarkerColor(1);
  h->SetFillStyle(0);
  h->SetFillColor(0);

  return h;
}
예제 #29
0
TH1D* mergeSys( TH1D* h1, TH1D* h2) {

  TH1D* hres = (TH1D*)h1->Clone(Form("%s_merged",h1->GetName()) );
  hres->Reset();
  Int_t nBins = h1->GetNbinsX();
  for ( Int_t j=1; j<=nBins ;j++)
    {
      float y1 =  h1->GetBinContent(j);
      float y2 =  h2->GetBinContent(j);
      hres->SetBinContent(j,  sqrt(  y1*y1 + y2*y2) );
      hres->SetBinError(j,  0.00001);
    }
  return hres;
}
예제 #30
-1
void MCtoSTATerrors() {
  TLatex *tplus = labelLatex(0.1364943,0.8114407,"MC sample");

  TFile *file0 = TFile::Open("results/StandardCutflow/allmc.root");

  TCanvas *c1 = new TCanvas();
  //TCanvas *c2 = new TCanvas();
  TH1D * LPplus = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_ICVarPFPlus");
  TH1D * LPminus = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_ICVarPFMinus");

  LPplus->Rebin(20);
  LPminus->Rebin(20);

  LPplus->Scale(0.3);
  LPminus->Scale(0.3);

  TH1D * newLPplus = (TH1D*)LPplus->Clone();
  TH1D * newLPminus = (TH1D*)LPminus->Clone();

  for(unsigned int i=1; i < LPplus->GetXaxis()->GetNbins(); i++) {
    newLPplus->SetBinError(i, TMath::Sqrt(LPplus->GetBinContent(i)));
    newLPminus->SetBinError(i, TMath::Sqrt(LPminus->GetBinContent(i)));
  }

  c1->cd();
  newLPplus->GetYaxis()->SetTitle("Events / 300 nb^{-1}");
  //newLPplus->GetXaxis()->SetTitle("LP(#mu^{+})");
  newLPplus->GetXaxis()->SetTitle("LP(#mu)");
  newLPplus->GetXaxis()->SetRangeUser(-1.0,2.0);
  newLPplus->SetLineWidth(3);
  newLPplus->SetLineStyle(2);
  newLPplus->SetLineColor(kRed);
  newLPplus->DrawCopy();
  tplus->DrawClone("same");

//   c2->cd();
//   newLPminus->GetYaxis()->SetTitle("Events / 100 nb^{-1}");
//   newLPminus->GetXaxis()->SetTitle("LP(#mu^{-})");
  newLPminus->SetLineWidth(3);
  newLPminus->SetLineStyle(2);
  newLPminus->SetLineColor(kBlack);
  newLPminus->DrawCopy("same");
//   tplus->DrawClone("same");

  leg = new TLegend(0.762931,0.720339,0.8649425,0.8622881,NULL,"brNDC");
  leg->AddEntry(newLPplus,"#mu^{+}","l");
  leg->AddEntry(newLPminus,"#mu^{-}","l");

  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->DrawClone();

  file0->Close();

  return;
}