Пример #1
0
TGraph* autogain152(TH1 *hist) {

   hist->GetXaxis()->SetRangeUser(200.,16000.);
   TSpectrum *s = new TSpectrum();
   Int_t nfound = s->Search(hist,6,"",0.08); //This will be dependent on the source used.
   printf("Found %d candidate peaks to fit\n",nfound);
   if(nfound > 6)
      nfound = 6;

   std::vector<float> vec;
   for(int x=0;x<nfound;x++)
      vec.push_back(s->GetPositionX()[x]);

   std::sort(vec.begin(),vec.end());

   Float_t energies[] = {121.7830, 244.6920, 344.276, 778.903, 964.131, 1408.011};
   TGraph* slopefit = new TGraph(nfound, &(vec[0]), energies);

   printf("Now fitting: Be patient\n");
   slopefit->Fit("pol1");
   if(slopefit->GetFunction("pol1")->GetChisquare() > 10.) {
      slopefit->RemovePoint(slopefit->GetN()-1);
      slopefit->Fit("pol1");
   }
   TChannel *chan = 0;
   slopefit->Draw("AC*");

   return slopefit;
}
Пример #2
0
void test5()
{
   TCanvas *c1 = new TCanvas("c1", "c1", 0,   0, 600, 300);
   TCanvas *c2 = new TCanvas("c2", "c2", 605, 0, 600, 300);

   const Int_t n = 20;
   Double_t x[n], y[n];
   for (Int_t i = 0; i < n; i++) {
      x[i] = i;
      y[i] = i;
   }

   TGraph *gr = new TGraph(n, x, y);
   gr->SetMarkerStyle(20);
   c1->cd();
   c1->SetGrid();
   gr->Draw("APC");
   gr->SetHighlight();
   TGraph::SetHighlightPad(c2);

   TH1F *h[n];
   for (Int_t i = 0; i < n; i++) {
      h[i] = new TH1F(TString::Format("h_%02d", i), "", 100, -5.0, 5.0);
      h[i]->SetTitle(h[i]->GetName());
      h[i]->FillRandom("gaus");
      gr->AddHighlight(i, h[i]);
   }

   gr->GetListOfHighlights()->SetOwner(kTRUE);
   gr->RemovePoint(5);
   gr->RemovePoint(9); // point with x = 10 (after remove previous point)
   delete h[14];
   delete h[17];
}
Пример #3
0
TGraph* getContour(TH2D* h, TString name) {

  TGraph* graph = new TGraph(100);
  graph->SetName(name);
  int ip = 0;
  int nx = h->GetXaxis()->GetNbins();
  int ny = h->GetYaxis()->GetNbins();

  // for y>x
  int ix = -1;
  for(int j=ny;true; j--) {
    int k = -1;
    for(int i=2; i<nx-1; i++) {
      if(h->GetBinContent(i,j) < 0) {
	std::cout << "i,j,z : " << i << ", " << j << ", " << h->GetBinContent(i,j) << std::endl;
        k = i;
        break;
      }
    }// for i
    if(k<0) continue;
    double y = h->GetYaxis()->GetBinCenter(j);
    double x1 = h->GetXaxis()->GetBinCenter(k-1);
    double x2 = h->GetXaxis()->GetBinCenter(k);
    double z1 = h->GetBinContent(k-1,j);
    double z2 = h->GetBinContent(k,j);
    double x = x1 + (x2-x1)*fabs(z1)/fabs(z2-z1);
    std::cout << "y, x1, x2, z1, z2, x : " << y << ", " << x1 << ", " << x2 << ", " << x << ", " << z1 << ", " << z2 << std::endl;
    graph->SetPoint(ip++,x,y);

    if(h->GetYaxis()->GetBinCenter(j) < h->GetXaxis()->GetBinCenter(k)) {
      ix = k;
      break;
    }
  }// for j

  if(ix < 0) std::cout << "Something wrong...." << std::endl;

  // for y<x
  for(int i=ix; i<=nx; i++) {
    int k = -1;
    for(int j=2; j<ny-1; j++) {
      if(h->GetBinContent(i,j) < 0) {
        k = j;
        break;
      }
    }// for j
    if(k<0) continue;
    double x = h->GetXaxis()->GetBinCenter(i);
    double y1 = h->GetYaxis()->GetBinCenter(k-1);
    double y2 = h->GetYaxis()->GetBinCenter(k);
    double z1 = h->GetBinContent(i,k-1);
    double z2 = h->GetBinContent(i,k);
    double y = y1 + (y2-y1)*fabs(z1)/fabs(z2-z1);
    std::cout << "x, y1, y2, z1, z2, y : " << x << ", " << y1 << ", " << y2 << ", " << y << ", " << z1 << ", " << z2 << std::endl;
    graph->SetPoint(ip++,x,y);
  }// for i

  ip = graph->GetN()-1;
  while(1) {
    double x, y;
    graph->GetPoint(ip,x,y);
    if(x>1) break;
    else graph->RemovePoint(ip);
    ip--;
  }

  return graph;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
TGraph* compMVAcut(const TH2* histogramMVAoutput_vs_Pt, const TH1* histogramPt, double Efficiency_or_FakeRate)
{
  const TAxis* xAxis = histogramMVAoutput_vs_Pt->GetXaxis();
  int numBinsX = xAxis->GetNbins();

  const TAxis* yAxis = histogramMVAoutput_vs_Pt->GetYaxis();
  int numBinsY = yAxis->GetNbins();

  TGraph* graph = new TGraphAsymmErrors(numBinsX);
  std::string graphName = Form("%s_graph", histogramMVAoutput_vs_Pt->GetName());
  graph->SetName(graphName.data());

  int numPoints = 0;

  for ( int iBinX = 1; iBinX <= numBinsX; ++iBinX ) {
    double ptMin = xAxis->GetBinLowEdge(iBinX);
    double ptMax = xAxis->GetBinUpEdge(iBinX);

    int binLowIndex = const_cast<TH1*>(histogramPt)->FindBin(ptMin);
    int binUpIndex  = const_cast<TH1*>(histogramPt)->FindBin(ptMax);
    //std::cout << "ptMin = " << ptMin << ", ptMax = " << ptMax << ": binLowIndex = " << binLowIndex << ", binUpIndex = " << binUpIndex << std::endl;
    histogramPt->GetXaxis()->SetRange(binLowIndex, binUpIndex);

    // CV: skip bins of low statistics
    if ( histogramPt->GetEntries() < 100 ) {
      std::cout << "Warning: bin @ x = " << xAxis->GetBinCenter(iBinX) << " has low statistics (#entries = " << histogramPt->GetEntries() << ") --> skipping !!" << std::endl;
      continue;
    }

    double x = histogramPt->GetMean();

    //std::cout << "iBinX = " << iBinX << ": xMean = " << x << std::endl;

    double normalization = 0.;
    for ( int iBinY = numBinsY; iBinY >= 1; --iBinY ) {
      normalization += histogramMVAoutput_vs_Pt->GetBinContent(iBinX, iBinY);
    }
    // CV: skip bins of low statistics
    //if ( normalization < 100 ) {
    //  std::cout << "Warning: bin @ x = " << xAxis->GetBinCenter(iBinX) << " has low statistics (normalization = " << normalization << ") --> skipping !!" << std::endl;
    //  continue;
    //}
    
    double y = -1.;

    double runningSum = 0.;
    for ( int iBinY = numBinsY; iBinY >= 1; --iBinY ) {
      double binContent_normalized = histogramMVAoutput_vs_Pt->GetBinContent(iBinX, iBinY)/normalization;
      if ( (runningSum + binContent_normalized) > Efficiency_or_FakeRate ) {
	y = yAxis->GetBinUpEdge(iBinY) - ((Efficiency_or_FakeRate - runningSum)/binContent_normalized)*yAxis->GetBinWidth(iBinY);
	//std::cout << "iBinY = " << iBinY << " (yCenter = " << yAxis->GetBinCenter(iBinY) << "): binContent = " << binContent_normalized << std::endl;
	//std::cout << "--> setting y = " << y << std::endl;
	assert(y >= yAxis->GetBinLowEdge(iBinY));
	break;
      } else {
	runningSum += binContent_normalized;
	//std::cout << "iBinY = " << iBinY << " (yCenter = " << yAxis->GetBinCenter(iBinY) << "): runningSum = " << runningSum << std::endl;
      }
    }
    
    graph->SetPoint(numPoints, x, y);
    ++numPoints;
  }

  for ( int iPoint = numBinsX; iPoint > numPoints; --iPoint ) {
    //std::cout << "removing point #" << iPoint << std::endl;
    graph->RemovePoint(graph->GetN() - 1);
  }

  // reset x-axis range selection 
  histogramPt->GetXaxis()->SetRange(1., 0.);

  return graph;
}
Пример #5
0
void Polarization(){

    TGraph *gObs;
    TGraph *gExp;
    TGraph *gObsL;
    TGraph *gExpL;
    TGraph *gObsR;
    TGraph *gExpR;
    
    TFile *fc = TFile::Open("Limits2DHistograms_T2tt_postfit.root");
    TFile *fl = TFile::Open("Limits2DHistograms_T2tt_lefthanded_postfit.root");
    TFile *fr = TFile::Open("Limits2DHistograms_T2tt_righthanded_postfit.root");
    
    TGraph *g;
    fc->cd();
    g = (TGraph*)fc->Get("gObs");
    gObs = (TGraph*)g->Clone("Obs");
    g = (TGraph*)fc->Get("gExp");
    gExp = (TGraph*)g->Clone("Exp");
    fl->cd();
    g = (TGraph*)fl->Get("gObs_2");
    gObsL = (TGraph*)g->Clone("ObsL");
    g = (TGraph*)fl->Get("gExp_2");
    gExpL = (TGraph*)g->Clone("ExpL");
    fr->cd();
    g = (TGraph*)fr->Get("gObs");
    gObsR = (TGraph*)g->Clone("ObsR");
    g = (TGraph*)fr->Get("gExp");
    gExpR = (TGraph*)g->Clone("ExpR");
    
    gObs->SetLineWidth(4);
    gExp->SetLineWidth(4);
    gObsL->SetLineWidth(2);
    gExpL->SetLineWidth(2);
    gObsR->SetLineWidth(2);
    gExpR->SetLineWidth(2);
    gObs->SetLineStyle(1);
    gExp->SetLineStyle(7);
    gObsL->SetLineStyle(1);
    gExpL->SetLineStyle(7);
    gObsR->SetLineStyle(1);
    gExpR->SetLineStyle(7);
    gObs->SetLineColor(kBlack);
    gExp->SetLineColor(kBlack);
    gObsL->SetLineColor(kBlue);
    gExpL->SetLineColor(kBlue);
    gObsR->SetLineColor(kRed);
    gExpR->SetLineColor(kRed);
    if(killlowdiag){
    for( int i = gObs->GetN()-1; i>=0;--i){
        double x,y;
        gObs->GetPoint(i,x,y);
        if(x-y<172.5) gObs->RemovePoint(i);
    }
    for( int i = gExp->GetN()-1; i>=0;--i){
        double x,y;
        gExp->GetPoint(i,x,y);
        if(x-y<172.5) gExp->RemovePoint(i);
    }
    }
    for( int i = gObsL->GetN()-1; i>=0;--i){
        double x,y;
        gObsL->GetPoint(i,x,y);
        if(x-y<172.5) gObsL->RemovePoint(i);
    }
    for( int i = gObsR->GetN()-1; i>=0;--i){
        double x,y;
        gObsR->GetPoint(i,x,y);
        if(x-y<172.5) gObsR->RemovePoint(i);
    }
    for( int i = gExpL->GetN()-1; i>=0;--i){
        double x,y;
        gExpL->GetPoint(i,x,y);
        if(x-y<172.5) gExpL->RemovePoint(i);
    }
    for( int i = gExpR->GetN()-1; i>=0;--i){
        double x,y;
        gExpR->GetPoint(i,x,y);
        if(x-y<172.5) gExpR->RemovePoint(i);
    }

    
   TCanvas *c1 = new TCanvas("c1", "c1",50,50,600,600);
   gStyle->SetOptFit(1);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   gStyle->SetErrorX(0.5); 
   //c1->Range(-6.311689,-1.891383,28.75325,4.56342);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   //c1->SetLogy();
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
   c1->SetRightMargin(0.05);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.15);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   gStyle->SetHatchesLineWidth(0);

   TH1F *hSum = new TH1F("hSum","",10,150,950);
   hSum->SetMinimum(0.);
   hSum->SetMaximum(550);
   hSum->SetDirectory(0);
   hSum->SetStats(0);
    hSum->Draw();
    hSum->GetYaxis()->SetRangeUser(0,500);
    hSum->GetXaxis()->SetRangeUser(150,950);

   Int_t ci;   // for color index setting
   ci = TColor::GetColor("#000099");
   hSum->SetLineColor(ci);
   hSum->SetLineStyle(0);
   hSum->SetMarkerStyle(20);
   hSum->GetXaxis()->SetTitle("m_{#tilde{t}} [GeV]");
   //hSum->GetXaxis()->SetBit(TAxis::kLabelsVert);
   hSum->GetXaxis()->SetLabelFont(42);
   //hSum->GetXaxis()->SetLabelOffset(0.005);
   hSum->GetXaxis()->SetLabelSize(0.035);
   hSum->GetXaxis()->SetTitleSize(0.06);
   hSum->GetXaxis()->SetTitleOffset(1.2);
   hSum->GetXaxis()->SetTitleFont(42);
   hSum->GetYaxis()->SetTitle("m_{#tilde{#chi}}_{1}^{0} [GeV]");
   hSum->GetYaxis()->SetLabelFont(42);
   //hSum->GetYaxis()->SetLabelOffset(0.007);
   hSum->GetYaxis()->SetLabelSize(0.035);
   hSum->GetYaxis()->SetTitleSize(0.05);
   hSum->GetYaxis()->SetTitleOffset(1.3);
   hSum->GetYaxis()->SetTitleFont(42);
    
    //TLegend *leg = new TLegend(0.4992416,0.4811189,0.898906,0.7503497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.4992416,0.4811189,0.698906,0.7503497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.6992416,0.2811189,0.898906,0.4503497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.6992416,0.3311189,0.898906,0.7903497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.7582416,0.4211189,0.912,0.8043497,NULL,"brNDC");
    TLegend *legE = new TLegend(0.51,0.675,0.81,0.855,NULL,"brNDC");
    //leg-> SetNColumns(2);
    legE->SetBorderSize(0);
    legE->SetTextSize(0.04);
    legE->SetTextFont(42);
    legE->SetLineColor(1);
    legE->SetLineStyle(1);
    legE->SetLineWidth(2);
    legE->SetFillColor(0);
    legE->SetFillStyle(1001);
    legE->SetHeader("Expected");
    legE->AddEntry(gExp, "unpolarized","l");
    legE->AddEntry(gExpR, "right-handed","l");
    legE->AddEntry(gExpL, "left-handed","l");
    
    TLegend *legO = new TLegend(0.175,0.675,0.50,0.855,NULL,"brNDC");
    //legO-> SetNColumns(2);
    legO->SetBorderSize(0);
    legO->SetTextSize(0.04);
    legO->SetTextFont(42);
    legO->SetLineColor(1);
    legO->SetLineStyle(1);
    legO->SetLineWidth(2);
    legO->SetFillColor(0);
    legO->SetFillStyle(1001);
    legO->SetHeader("Observed");
    legO->AddEntry(gObs, "unpolarized","l");
    legO->AddEntry(gObsR, "right-handed","l");
    legO->AddEntry(gObsL, "left-handed","l");
    
    
    TGraph* graphWhite = new TGraph(5);
    graphWhite->SetName("white");
    graphWhite->SetTitle("white");
    graphWhite->SetFillColor(kWhite);
    graphWhite->SetFillStyle(1001);
    graphWhite->SetLineColor(kBlack);
    graphWhite->SetLineStyle(1);
    graphWhite->SetLineWidth(3);
    graphWhite->SetPoint(0,150, 500);
    graphWhite->SetPoint(1,950, 500);
    graphWhite->SetPoint(2,950, 500*0.6666666667);
    graphWhite->SetPoint(3,150, 500*0.6666666667);
    graphWhite->SetPoint(4,150, 500);
    
    Float_t diagX[4] = {175.+25.,175.+25.+5000,175.-25.+5000,175.-25.};
    Float_t diagY[4] = {0,5000,5000,0};
    TGraph *gdiagonal = new TGraph(4, diagX, diagY);
    gdiagonal->SetName("MtopDiagonal");
    gdiagonal->SetFillColor(kWhite);
    //#gdiagonal->SetFillColor(18);
    TLine* ldiagonal = new TLine(175,0.,650-25.,450);
    //TLine* ldiagonal = new TLine(175.,25,175+500,500);
    ldiagonal->SetLineColor(kGray);
    ldiagonal->SetLineStyle(2);
    TLatex* tdiagonal = new TLatex(400-2.5, 400-172.5,"m_{#tilde{t}} = m_{t} + m_{#tilde{#chi}_{1}^{0}}");
    //tdiagonal->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500)));
    tdiagonal->SetTextAngle(56.31);
    tdiagonal->SetTextColor(kGray+2);
    tdiagonal->SetTextAlign(11);
    tdiagonal->SetTextSize(0.025);

    TLine* l2 = new TLine(150,75,585,500);
    l2->SetLineColor(kGray);
    l2->SetLineStyle(2);
    if(killlowdiag){
        l2->SetX1(200); l2->SetY1(0); l2->SetX2(600); l2->SetY2(400);
    }
    TLatex *t2 = new TLatex(300, 300-72.5,"m_{#tilde{t}} = m_{W} + m_{#tilde{#chi}_{1}^{0}}");
    //t2->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500)));
    t2->SetTextAngle(56.31);
    t2->SetTextColor(kGray+2);
    t2->SetTextAlign(11);
    t2->SetTextSize(0.025);

    hSum->Draw("axis");
    
    gExpR->Draw("c");
    gExpL->Draw("c");
    gExp->Draw("c");
    gObsR->Draw("c");
    gObsL->Draw("c");
    gObs->Draw("c");

    gdiagonal->Draw("FSAME");
    ldiagonal->Draw("LSAME");
    l2->Draw();
    if(!killlowdiag) t2->Draw();
    tdiagonal->Draw("SAME");
    graphWhite->Draw("FSAME");
    graphWhite->Draw("LSAME");

    legE->Draw();
    legO->Draw();
    
    TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}  NLO+NLL exclusion");
    //TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}");
    //TLatex* textModelLabel= new TLatex(0.175,0.92,"#tilde{#chi} ");
    textModelLabel->SetNDC();
    textModelLabel->SetTextAlign(13);
    textModelLabel->SetTextFont(42);
    textModelLabel->SetTextSize(0.042);
    textModelLabel->Draw();
    
    //final CMS style
    TLatex *tLumi = new TLatex(0.95,0.944,"2.3 fb^{-1} (13 TeV)");
    tLumi->SetNDC();
    tLumi->SetTextAlign(31);
    tLumi->SetTextFont(42);
    tLumi->SetTextSize(0.042);
    tLumi->SetLineWidth(2);
    tLumi->Draw();
    TLatex *tCMS = new TLatex(0.152,0.944,"CMS");
    tCMS->SetNDC();
    tCMS->SetTextAlign(11);
    tCMS->SetTextFont(61);
    tCMS->SetTextSize(0.0525);
    tCMS->SetLineWidth(2);
    tCMS->Draw();
    TLatex *tPrel = new TLatex(0.265,0.944,"Preliminary");
    tPrel->SetNDC();
    tPrel->SetTextAlign(11);
    tPrel->SetTextFont(52);
    tPrel->SetTextSize(0.042);
    tPrel->SetLineWidth(2);
    tPrel->Draw();
    
   c1->Modified();
   c1->cd();
    c1->Update();
   c1->SetSelected(c1);

}