Exemple #1
0
void fitKee(Int_t bin) {
	gSystem->Load("libRooFit");
	gROOT->SetStyle("Plain");
	gStyle->SetOptStat(1111);

	TFile * file = TFile::Open("/Disk/ecdf-nfs-ppe/lhcb/dcraik/BuKee_reduced.root");

	TTree * DecayTree = dynamic_cast<TTree*>(file->Get("DecayTree"));

	TString binStr; binStr+=bin;
	Double_t minQ(0.), maxQ(0.);

	switch(bin) {
	//case 0:
	//	minQ = TMath::Sqrt(0.1e6);
	//	maxQ = TMath::Sqrt(0.98e6);
	//	break;
	//case 1:
	//	minQ = TMath::Sqrt(1.1e6);
	//	maxQ = TMath::Sqrt(2.e6);
	//	break;
	//case 2:
	//	minQ = TMath::Sqrt(2.e6);
	//	maxQ = TMath::Sqrt(3.e6);
	//	break;
	//case 3:
	//	minQ = TMath::Sqrt(3.e6);
	//	maxQ = TMath::Sqrt(4.e6);
	//	break;
	//case 4:
	//	minQ = TMath::Sqrt(4.e6);
	//	maxQ = TMath::Sqrt(5.e6);
	//	break;
	//case 5:
	//	minQ = TMath::Sqrt(5.e6);
	//	maxQ = TMath::Sqrt(6.e6);
	//	break;
	//case 6:
	//	minQ = TMath::Sqrt(6.e6);
	//	maxQ = TMath::Sqrt(7.e6);
	//	break;
	//case 7:
	//	minQ = TMath::Sqrt(7.e6);
	//	maxQ = TMath::Sqrt(8.e6);
	//	break;
	//case 8:
	//	minQ = TMath::Sqrt(11.e6);
	//	maxQ = TMath::Sqrt(11.75e6);
	//	break;
	//case 9:
	//	minQ = TMath::Sqrt(11.75e6);
	//	maxQ = TMath::Sqrt(12.5e6);
	//	break;
	//case 10:
	//	minQ = TMath::Sqrt(15.e6);
	//	maxQ = TMath::Sqrt(16.e6);
	//	break;
	//case 11:
	//	minQ = TMath::Sqrt(16.e6);
	//	maxQ = TMath::Sqrt(17.e6);
	//	break;
	//case 12:
	//	minQ = TMath::Sqrt(17.e6);
	//	maxQ = TMath::Sqrt(18.e6);
	//	break;
	//case 13:
	//	minQ = TMath::Sqrt(18.e6);
	//	maxQ = TMath::Sqrt(19.e6);
	//	break;
	//case 14:
	//	minQ = TMath::Sqrt(19.e6);
	//	maxQ = TMath::Sqrt(20.e6);
	//	break;
	//case 15:
	//	minQ = TMath::Sqrt(20.e6);
	//	maxQ = TMath::Sqrt(21.e6);
	//	break;
	//case 16:
	//	minQ = TMath::Sqrt(21.e6);
	//	maxQ = TMath::Sqrt(22.e6);
	//	break;
	case 17:
		minQ = TMath::Sqrt(1.1e6);
		maxQ = TMath::Sqrt(6.e6);
		break;
	case 18:
		minQ = TMath::Sqrt(15.e6);
		maxQ = TMath::Sqrt(22.e6);
		break;
	case 19:
		minQ = TMath::Sqrt(1.1e6);
		maxQ = TMath::Sqrt(22.e6);
		break;
	default:
		return;
	}
	TString cutStr("B_ConstBNoPsiFit_J_psi_1S_M> "); cutStr += minQ; cutStr += " && B_ConstBNoPsiFit_J_psi_1S_M< "; cutStr += maxQ;

	//B_M 
	RooRealVar B_M("B_NoPsiFit_M","; m(Kmumu) (MeV/c^{2}); Candidates / 12 MeV/c^{2}",4900,5600);
	RooRealVar Psi_M("B_ConstBNoPsiFit_J_psi_1S_M","; m(mumu) (MeV/c^{2}); Candidates / 45 MeV/c^{2}",0,5000);
	RooRealVar B_PsiFit_M("B_FullFit_M","; m(Kmumu) (MeV/c^{2}); Candidates / 12 MeV/c^{2}",3000,7000);

	RooDataSet * data  = new RooDataSet("data", "dataset with B_REFITTED_M", DecayTree, RooArgSet(B_M,Psi_M,B_PsiFit_M));
	RooDataSet * data1 = dynamic_cast<RooDataSet*>(data->reduce(cutStr));
	RooDataSet * dataPR  = dynamic_cast<RooDataSet*>(data->reduce("B_FullFit_M>4800&&B_FullFit_M<5200"));
	RooDataSet * dataSig = dynamic_cast<RooDataSet*>(data->reduce("B_FullFit_M>5200&&B_FullFit_M<5350"));

    	RooKeysPdf pr( "pr" ,"pr" ,B_M,*dataPR);
    	RooKeysPdf sig("sig","sig",B_M,*dataSig);

	RooRealVar p0("p0","",0.);//-4.03708e-03,-0.1,0.1);
	RooExponential comb("comb","",B_M,p0);

	// Number of signal & background events
	RooRealVar nsig("nsig","#signal events",300,-1000,50000,"Events");
	RooRealVar nPR( "nPR" ,"#PR events"    ,300,-1000,50000,"Events");
	RooRealVar nbkg("nbkg","#signal events",300,-1000,50000,"Events");

	RooAddPdf full_RF_PDF("full_RF_PDF","RF PDF of everything",RooArgList(sig,pr,comb), RooArgList(nsig,nPR,nbkg));

	//# Do the fit on REFITTED Mass
	full_RF_PDF.fitTo(*data1,RooFit::Extended());

	TCanvas * can = new TCanvas("can","Mass fits Data",800,600);
	B_M_RF_Plot = B_M.frame(20);
	B_M_RF_Plot->SetTitle("");
	B_M_RF_Plot->GetYaxis()->SetTitle("Candidates / 16 MeV/c^{2}");
	B_M_RF_Plot->GetXaxis()->SetTitle("m(K#mu#mu) (MeV/c^{2})");

	data1->plotOn(B_M_RF_Plot);
	full_RF_PDF.plotOn(B_M_RF_Plot);
	full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("pr"),   RooFit::LineStyle(kDashed),RooFit::LineColor(kRed));
	full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("comb"), RooFit::LineStyle(kDashed),RooFit::LineColor(kMagenta));
        full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("sig"),  RooFit::LineStyle(kDashed));
	B_M_RF_Plot->Draw();

	can->SaveAs("plots/Kee_Q"+binStr+".pdf");

	can->SetLogy();
        B_M_RF_Plot->SetMinimum(1.e-1);
        B_M_RF_Plot->SetMaximum(5.e+2);
	B_M_RF_Plot->Draw();
	can->SaveAs("plots/Kee_Q"+binStr+"_log.pdf");

//	//Get integrals
//	double mBdm = sigmean.getVal() - 2.5*(sigsigma.getVal());
//	double mBdp = sigmean.getVal() + 2.5*(sigsigma.getVal());
//
//	B_M.setRange("signal",mBdm,mBdp);
//	B_M.setRange("sideband",5400,5970);
//	B_M.setRange("full",5170,5970);
//
//	double fsig1 = B0Sig.createIntegral(RooArgSet(B_M),RooFit::NormSet(B_M),RooFit::Range("signal"))->getVal();
//	double fsig2 = B0Sig.createIntegral(RooArgSet(B_M),RooFit::NormSet(B_M),RooFit::Range("sideband"))->getVal();
//	double fsig0 = B0Sig.createIntegral(RooArgSet(B_M),RooFit::NormSet(B_M),RooFit::Range("full"))->getVal();
//
//	double fbkg1 = comb_bkg.createIntegral(RooArgSet(B_M),RooFit::NormSet(B_M),RooFit::Range("signal"))->getVal();
//	double fbkg2 = comb_bkg.createIntegral(RooArgSet(B_M),RooFit::NormSet(B_M),RooFit::Range("sideband"))->getVal();
//	double fbkg0 = comb_bkg.createIntegral(RooArgSet(B_M),RooFit::NormSet(B_M),RooFit::Range("full"))->getVal();
//
//	std::cout << std::endl;
//	std::cout << sigmean.getVal() << "\t" << sigsigma.getVal() << std::endl << std::endl;
//	std::cout << "\t\tsig\tbkg" << std::endl;
//	std::cout << "window  \t" << nsig.getVal()*fsig1/fsig0 << "\t" << nbkg.getVal()*fbkg1/fbkg0 << std::endl;
//	std::cout << "sideband\t" << nsig.getVal()*fsig2/fsig0 << "\t" << nbkg.getVal()*fbkg2/fbkg0 << std::endl;
//	std::cout << std::endl;
//
//	std::ofstream fout;
//	fout.open("bkgParams/"+binStr+".dat");
//	fout << sigmean.getVal() - 2.5*sigsigma.getVal() << "\t" << sigmean.getVal() + 2.5*sigsigma.getVal() << "\t" << fbkg1/fbkg2 << std::endl;
//	fout.close();
//
//	//// Try splot stuff
//	//// First set all parameters to constant except for yields
//	sigmean.setConstant();
//	sigsigma.setConstant();
//	p0.setConstant();
//
//	RooStats::SPlot * sData = new RooStats::SPlot("sData","An SPlot",*data1, &full_RF_PDF, RooArgList(nsig,nbkg));
//	sData->GetSDataSet()->write("/Home/dcraik/Kll/tuples/fromPatrick/Kmm_Q"+binStr+"_sWeights.txt");

}
void SUSY_bRPV_m0_vs_m12_all_withBand_cls( TString fname0="", TString fname1="",
        TString fname2="",
        TString gridname="",
        const char* prefix="test",
        const float& lumi = 20.3,
        bool showsig = true,
        int discexcl = 1,
        int showtevatron = 0,
        int showcms = 0,
        int showOneSigmaExpBand = 0,
        bool showSR = false,
        bool useShape = false,
        int channel = -1,
        TString hname0 = "sigp1clsf",
        TString hname1 = "sigp1expclsf",
        TString hname3 = "sigclsu1s",
        TString hname5 = "sigclsd1s",
        TString hname6 = "sigp1ref",
        TString fnameMass= "contourmacros/mSugraGridtanbeta10_gluinoSquarkMasses.root")
{
    // set style and remove existing canvas'
    CombinationGlob::Initialize();

    cout << "--- Plotting m0 versus m12 " << endl;

    // --- prepare
    // open reference files, and retrieve histogram
    cout << "--- Reading root base file: " << fname0 << endl;
    TFile* f0 = TFile::Open( fname0, "READ" );
    if (!f0) {
        cout << "*** Error: could not retrieve histogram: " << hname0 << " in file: " << f0->GetName() 
            << " ==> abort macro execution" << endl;
        return;
    }
    
    TFile *f1; TFile *f2;

    if(fname1 != "")
        f1 = TFile::Open( fname1, "READ" );
        if(!f1) cout << "Warning: could not open " << fname1 << endl;
    if(fname2 != "")
        f2 = TFile::Open( fname2, "READ" );
        if(!f2) cout << "Warning: could not open " << fname2 << endl;

    TH2F* histecls = (TH2F*)f0->Get( "sigp1expclsf" ); 
    TH2F* histocls = (TH2F*)f0->Get( "sigp1clsf" ); 
    if (histecls!=0) histecls->SetDirectory(0);
    if (histocls!=0) histocls->SetDirectory(0);

    TH2F* histe_esigxsp1s;
    if (fname1 != "" && f1)  {
        histe_esigxsp1s = (TH2F*)f1->Get( hname0 );
        cout << "Read up histogram " << histe_esigxsp1s << endl;
    }

    TH2F* histe_esigxsm1s;
    if (fname2 != "" && f2) { 
        histe_esigxsm1s = (TH2F*)f2->Get( hname0 ); 
        cout << "Read down histogram " << histe_esigxsm1s << endl;
    }

    if (histe_esigxsp1s!=0) histe_esigxsp1s->SetDirectory(0);
    if (histe_esigxsm1s!=0) histe_esigxsm1s->SetDirectory(0);

    TH2F* contour_esigxsp1s
        = ( histe_esigxsp1s!=0 ? FixAndSetBorders( *histe_esigxsp1s, "contour_esigxsp1s", "contour_esigxsp1s", 0 ) : 0);
    TH2F* contour_esigxsm1s
        = ( histe_esigxsm1s!=0 ? FixAndSetBorders( *histe_esigxsm1s, "contour_esigxsm1s", "contour_esigxsm1s", 0 ) : 0);

    //    TFile* f3 = TFile::Open( fname3, "READ" );
    TH2F* histe(0);
    TH2F* histe_u1s(0);
    TH2F* histe_d1s(0);

    //    TFile* f4 = TFile::Open( fname4, "READ" );

    bool extExpectation = 0;

    TH2F* hist0 = (TH2F*)f0->Get( hname0 );
    TH2F* hist1 = (TH2F*)f0->Get( hname1 );
    TH2F* hist3 = (TH2F*)f0->Get( hname3 );
    TH2F* hist5 = (TH2F*)f0->Get( hname5 );
    TH2F* hist6 = (TH2F*)f0->Get( hname6 );



    if (hist0!=0) hist0->SetDirectory(0);
    if (hist1!=0) hist1->SetDirectory(0);
    if (hist3!=0) hist3->SetDirectory(0);
    if (hist5!=0) hist5->SetDirectory(0);
    if (hist6!=0) hist6->SetDirectory(0);
    f0->Close();

    TH2F* histe_esigxsp1s; 
    if (fname1!="" && f1) histe_esigxsp1s  = (TH2F*)f1->Get( hname0 ); 
    TH2F* histe_esigxsm1s; 
    if (fname2!="" && f2) histe_esigxsm1s  = (TH2F*)f2->Get( hname0 ); 

    if (fname1!="" &&histe_esigxsp1s!=0) histe_esigxsp1s->SetDirectory(0);
    if (fname2!="" && histe_esigxsm1s!=0) histe_esigxsm1s->SetDirectory(0);

    TH2F* contour_esigxsp1s
        = ( histe_esigxsp1s!=0 ? FixAndSetBorders( *histe_esigxsp1s, "contour_esigxsp1s", "contour_esigxsp1s", 0 ) : 0);
    TH2F* contour_esigxsm1s
        = ( histe_esigxsm1s!=0 ? FixAndSetBorders( *histe_esigxsm1s, "contour_esigxsm1s", "contour_esigxsm1s", 0 ) : 0);

    TH2F* contour         = ( hist1!=0 ? FixAndSetBorders( *hist1, "contour", "contour", 0 ) : 0);
    TH2F* contour_obs     = ( hist0!=0 ? FixAndSetBorders( *hist0, "contour_obs", "contour_obs") : 0 );

    TH2F* contour_ep1s    = ( hist3!=0 ? FixAndSetBorders( *hist3, "contour", "contour", 0 ) : 0 );
    TH2F* contour_em1s    = ( hist5!=0 ? FixAndSetBorders( *hist5, "contour", "contour", 0 ) : 0 );

    // For Band
    if (showOneSigmaExpBand){
        TGraph* gr_contour_ep1s = ContourGraph( contour_ep1s )->Clone(); 
        TGraph* gr_contour_em1s= ContourGraph( contour_em1s )->Clone(); 
    }
    TH2F* contour_exp(0);
    if (histe!=0)     { contour_exp     = FixAndSetBorders( *histe, "contour_exp", "contour_exp", 0 ); } 
    TH2F* contour_au1s(0);
    if (histe_u1s!=0) {  contour_au1s   = FixAndSetBorders( *histe_u1s, "contour", "contour", 0 ); }
    TH2F* contour_ad1s(0);
    if (histe_d1s!=0) {  contour_ad1s   = FixAndSetBorders( *histe_d1s, "contour", "contour", 0 ); }


    TH2F* contour_expcls(0);
    if (histecls!=0)     { contour_expcls     = FixAndSetBorders( *histecls, "contour_expcls", "contour_expcls", 0 ); }
    TH2F* contour_obscls(0);
    if (histocls!=0)     { contour_obscls     = FixAndSetBorders( *histocls, "contour_obscls", "contour_obscls", 0 ); }


    if (contour_obs==0) { 
        cout << "contour is zero" << endl;
        return;
    }

    // set text style
    gStyle->SetPaintTextFormat(".2g");
    if (hist1!=0) hist1->SetMarkerStyle(21);
    if (hist1!=0) hist1->SetMarkerSize(1.5);
    Float_t nsigmax(0)
        if (hist1!=0) nsigmax = hist1->GetMaximum();

    // --- draw

    // create canvas
    TCanvas* c = new TCanvas( "c", "A scan of "+gridname, 0, 0, 
            CombinationGlob::StandardCanvas[0], CombinationGlob::StandardCanvas[1] );  
    //c->SetGrayscale();

    // create and draw the frame
    double plotrange=2250.;
    TH2F *frame = new TH2F("frame", "m_{gluino} vs. m_{lsp} - ATLAS work in progress", 100, 350.,plotrange, 100, 200., 900. );
    // set common frame style
    CombinationGlob::SetFrameStyle2D( frame, 1.0 ); // the size (scale) is 1.0
    
    frame->SetXTitle( "m_{0} [GeV]" );
    frame->SetYTitle( "m_{1/2} [GeV]" );
    frame->GetYaxis()->SetTitleOffset(1.35);

    //frame->SetTextFont( 42 );
    frame->GetXaxis()->SetTitleFont( 42 );
    frame->GetYaxis()->SetTitleFont( 42 );
    frame->GetXaxis()->SetLabelFont( 42 );
    frame->GetYaxis()->SetLabelFont( 42 );

    frame->GetXaxis()->SetTitleSize( 0.04 );
    frame->GetYaxis()->SetTitleSize( 0.04 );
    frame->GetXaxis()->SetLabelSize( 0.04 );
    frame->GetYaxis()->SetLabelSize( 0.04 );

    frame->Draw();

    const int nsig(3);
    //TH2F *chist[3];
    // draw contours
    //!instead of printing sigma in 68% 95% 98% levels now printing +1 sigma deviations 
    //for (Int_t nsigma=1; nsigma<=nsig; nsigma++)
    //  DrawContourSameColor( contour, nsigma, "blue", kFALSE, (nsigma==1?inverse:0) ) ;

    TString basecolor="yellow";
    Int_t nsigma=2;

    TLegend *leg = new TLegend(0.6,0.7,0.92,0.9);

    leg->SetTextSize( CombinationGlob::DescriptionTextSize );
    leg->SetTextSize( 0.03 );
    leg->SetTextFont( 42 );
    leg->SetFillColor( 0 );
    leg->SetFillStyle(1001);

    if (false && channel==1) { // electron

        cout << "removing islands in electron channel ..." << endl;
        // contour line is drawn for values at 1.64485
        TAxis* ax = contour_obs->GetXaxis();
        TAxis* ay = contour_obs->GetYaxis();
        /*     
               contour_em1s

               for (int xbin = 1; xbin <= contour_obs->GetNbinsX(); xbin++) {
               for (int ybin = 1; ybin <= contour_obs->GetNbinsY(); ybin++) {
        // island 2
        if ( ax->GetBinCenter( xbin) > 420. && ax->GetBinCenter( xbin) < 480. &&
        ay->GetBinCenter( ybin) > 140. && ay->GetBinCenter( ybin) < 160. ) {
        cout << "Found spot here: " << xbin << " (" << ax->GetBinCenter( xbin)  << "), "
        << ybin << " (" << ay->GetBinCenter( ybin) << "), "
        << " value: " << contour->GetBinContent(xbin,ybin) <<   endl;
        cout << "   HACK : Setting above point by hand to 1.50 (!)" << endl;
        contour->SetBinContent(xbin, ybin, 1.50);
        }
        }
        }
        */

    }

    if (false && channel==2) { // combined
        cout << "removing islands in combined channel ..." << endl;
    }


    /////////////////////////////////////////////////////////
    //// add 2011 results 


    Int_t c_myYellow   = TColor::GetColor("#ffe938");
    Int_t c_myRed      = TColor::GetColor("#aa000");

    // turn off yellow band    
    if (showOneSigmaExpBand) TGraph* grshadeExp= DrawExpectedBand( gr_contour_ep1s, gr_contour_em1s, CombinationGlob::c_DarkYellow , 1001 , 0)->Clone();


    if (discexcl==1) {
        DrawContourLine95( leg, contour_obs,     "Observed limit (#pm1 #sigma^{SUSY}_{theory})", c_myRed, 1, 4 );   // 95% CL_{S}
        
        
        if (contour_esigxsp1s)
            DrawContourLine95( leg, contour_esigxsp1s, "", c_myRed, 3, 2 );    // Observed limit #pm 1 #sigma^{SUSY}_{theory}
        if (contour_esigxsm1s)
            DrawContourLine95( leg, contour_esigxsm1s, "", c_myRed, 3, 2 );    // Observed limit #pm 1 #sigma^{SUSY}_{theory}
        
        if (!extExpectation) { 
            // Compare the expected limits!
            if (contour_expcls!=0) { 
                //DrawContourLine95( leg, contour_expcls, fname0, CombinationGlob::c_DarkGray, 6 );
                DrawContourLine95( leg, contour_expcls, fname0, CombinationGlob::c_DarkBlueT3, 6 );
            }
            
            if (showOneSigmaExpBand) {
                if (contour_ep1s!=0) {	   
                    DrawContourLine95( leg, contour_ep1s, "", c_myYellow, 1 ); 
                }

                if (contour_em1s!=0)  {	   
                    DrawContourLine95( leg, contour_em1s, "", c_myYellow, 1 );
                }
                DummyLegendExpected(leg, "Expected limit (#pm1 #sigma_{exp})", c_myYellow, 1001, CombinationGlob::c_DarkBlueT3, 6, 2);

            } else {
                //if (contour!=0) DrawContourLine68( leg, contour, "exp. limit 68% CL", CombinationGlob::c_DarkBlueT3, 2 );
                //if (contour!=0) DrawContourLine99( leg, contour, "exp. limit 99% CL", CombinationGlob::c_DarkBlueT3, 3 );
            }

        } else { // expectation from asimov
            if (contour_exp!=0) DrawContourLine95( leg, contour_exp, "Median expected limit", CombinationGlob::c_DarkBlueT3, 6);
            if (showOneSigmaExpBand) {
                if (contour_au1s!=0) DrawContourLine95( leg, contour_au1s, "Expected limit #pm1#sigma", CombinationGlob::c_DarkBlueT3, 3 );
                if (contour_ad1s!=0) DrawContourLine95( leg, contour_ad1s, "", CombinationGlob::c_DarkBlueT3, 3 );
            }
        }
    }


    // plot tevatron limits
    TGraph* lep2slep(0);
    TGraph* lep2char(0);
    TGraph* d0o(0);
    TGraph* d0graph(0);
    TGraph* cdfgraph(0);
    TGraph* atlas(0);
    TGraph* atlasexp(0);

    if (showtevatron==1 && discexcl==1) {
        lep2char = ol1();
        d0graph = d0tanb3muneg();
        cdfgraph = cdftanb5();
        //atlas = ATLAS10_1lepton();
        //atlasexp = ATLAS10_1leptonexp();
    }

    //:w(void) stautanb3();

    TGraph* cmscurve(0);
    if (showcms==1) { 
        //cmscurve = cmsoff();
        cmscurve = cms();
    }


    // legend
    Float_t textSizeOffset = +0.000;
    Double_t xmax = frame->GetXaxis()->GetXmax();
    Double_t xmin = frame->GetXaxis()->GetXmin();
    Double_t ymax = frame->GetYaxis()->GetXmax();
    Double_t ymin = frame->GetYaxis()->GetXmin();
    Double_t dx   = xmax - xmin;
    Double_t dy   = ymax - ymin;

    //TString t1a = "99%, 95%, 68% CL fit contour (excluded)" ;
    // TString t1a = "-1#sigma, central, +1#sigma  fit contour (excluded)" ;
    TString t1b = "tan#beta = 3, A_{0}= 0, #mu < 0" ;
    Float_t nbkg(0);
    if( hist5!=0) nbkg = hist5->GetMaximum();
    TString t1c = Form("MC: n_{bkg}= %.1f", nbkg) ;

    // TLatex* text1a = new TLatex( 70, 260, t1a );
    TLatex* text1b = new TLatex( 150, ymax + dy*0.025, t1b );
    TLatex* text1c = new TLatex( 70, 280, t1c );

    // text1a->SetTextColor( 1 ); //CombinationGlob::c_VDarkGreen );
    text1b->SetTextColor( 1 ); //CombinationGlob::c_VDarkGreen );
    text1c->SetTextColor( 1 );
    text1b->SetTextFont( 42 ); //CombinationGlob::c_VDarkGreen );

    // text1a->SetTextAlign( 11 );
    text1b->SetTextAlign( 11 );
    text1c->SetTextAlign( 11 );

    //  text1a->SetTextSize( CombinationGlob::DescriptionTextSize + textSizeOffset );
    text1b->SetTextSize( CombinationGlob::DescriptionTextSize  );
    text1c->SetTextSize( CombinationGlob::DescriptionTextSize  );
    
    TString plottitle="bRPV-MSUGRA: tan #beta = 30, A_{0}= -2m_{0}, #mu>0";
    
    if(showSR){
        std::cout << "--- printing best SRs" << std::endl;
        Show_SR(fname0, c, xmin, xmax, ymin, ymax, useShape, leg);
        
    } 
    
    TLatex *Leg0 = new TLatex( xmin, ymax + dy*0.025,plottitle );
    Leg0->SetTextAlign( 11 );
    Leg0->SetTextFont( 42 );
    Leg0->SetTextSize( CombinationGlob::DescriptionTextSize);
    Leg0->SetTextColor( 1 );
    Leg0->AppendPad();


    TLatex *Leg1 = new TLatex();
    Leg1->SetNDC();
    Leg1->SetTextAlign( 11 );
    Leg1->SetTextFont( 42 );
    Leg1->SetTextSize( CombinationGlob::DescriptionTextSize );
    Leg1->SetTextColor( 1 );
    Leg1->DrawLatex(0.15,0.78, Form("#int L dt = %1.1f fb^{-1},  #sqrt{s}=8 TeV",lumi));  // 0.32,0.87
    if(useShape){
        Leg1->DrawLatex(0.15,0.72, "0 leptons, 2-6 jets, 5-bin");  // 0.32,0.87
    } else {
        Leg1->DrawLatex(0.15,0.72, "0 leptons, 2-6 jets");  // 0.32,0.87
    }    

    Leg1->AppendPad();

    TLatex *Leg2 = new TLatex();
    Leg2->SetNDC();
    Leg2->SetTextAlign( 11 );
    Leg2->SetTextSize( CombinationGlob::DescriptionTextSize );
    Leg2->SetTextColor( 1 );
    Leg2->SetTextFont(70);
    if (prefix!=0) { 
        Leg2->DrawLatex(0.7,0.85,prefix); // 0.15,0.81
        Leg2->AppendPad(); 
    }

    TLatex *atlasLabel = new TLatex();
    atlasLabel->SetNDC();
    atlasLabel->SetTextFont( 42 );
    atlasLabel->SetTextColor( 1 );
    atlasLabel->SetTextSize( 0.05 );
    atlasLabel->DrawLatex(0.15,0.87, "#bf{#it{ATLAS}} Internal"); // 0.15,0.87

    atlasLabel->AppendPad();

    //// draw number of signal events
    if (nsigmax>0 && showsig) {  hist1->Draw("textsame"); }
    //else {
    //  // draw grid for clarity
    //  c->SetGrid();
    //}
    //reddraw cahnnel label
    //  c->SetGrid();

    if (prefix!=0) { Leg2->AppendPad(); }

    // redraw axes
    frame->Draw( "sameaxis" );


    //  leg->Draw("same");


    // update the canvas
    double xline=1000.;
    double yline=1000.;
    if (fname0.Contains("SS")) {
        xline=800.; 
        yline=800.;
    }
    TLine *line=new TLine(200.,200.,xline,yline);
    line->SetLineStyle(3);
    //line->Draw();
    c->Update();


    gPad->RedrawAxis("same");
    c->Update();
    gPad->Update();

    ////////////////////////////////////////////////////////////////////////////////////////////

    //gROOT->GetListOfSpecials()->Print();

    TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
    if (contours!=0) {
        //contours->Print("v");

        TList *lcontour1 = (TList*)contours->At(0);
        //lcontour1->Print();
        if (lcontour1!=0) {
            TGraph *gc1 = (TGraph*)lcontour1->First();
            if (gc1!=0) { 
                //gc1->Print();
                //if (gc1->GetN() < 10) return;
                //gc1->SetMarkerStyle(21);
                //gc1->Draw("alp");
            }
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////

    // create plots
    // store histograms to output file
    TObjArray* arr = fname0.Tokenize("/");
    TObjString* objstring = (TObjString*)arr->At( arr->GetEntries()-1 );
    TString outfile = TString(Form("%1.2finvfb_",lumi)) + TString(Form("wband%d_",showOneSigmaExpBand)) + TString(Form("showcms%d_",showcms)) + objstring->GetString().ReplaceAll(".root","");
    delete arr;
    
    if(!showSR) outfile += TString("_noLabel");
    TString prefixsave = TString(prefix).ReplaceAll(" ","_") + Form("%1.2finvfb_",lumi) + Form("wband%d_",showOneSigmaExpBand);
    CombinationGlob::imgconv( c, Form("plots/atlascls_m0m12_%s",outfile.Data()) );   

}
Exemple #3
0
void fitKmm_loQ(Int_t bin) {
	gSystem->Load("libRooFit");
	gROOT->SetStyle("Plain");
	gStyle->SetOptStat(1111);

	TFile * file = TFile::Open("/Disk/ecdf-nfs-ppe/lhcb/gcowan/B2Kll/data/fromAlex/BuKmm.root");
	TTree * DecayTree = dynamic_cast<TTree*>(file->Get("DecayTree"));

	TString binStr; binStr+=bin;
	Double_t minQ(0.), maxQ(0.);

	switch(bin) {
	case 0:
		minQ = TMath::Sqrt(1.1e6);
		maxQ = TMath::Sqrt(2.e6);
		break;
	case 1:
		minQ = TMath::Sqrt(2.e6);
		maxQ = TMath::Sqrt(3.e6);
		break;
	case 2:
		minQ = TMath::Sqrt(3.e6);
		maxQ = TMath::Sqrt(4.e6);
		break;
	case 3:
		minQ = TMath::Sqrt(4.e6);
		maxQ = TMath::Sqrt(5.e6);
		break;
	case 4:
		minQ = TMath::Sqrt(5.e6);
		maxQ = TMath::Sqrt(6.e6);
		break;
	default:
		return;
	}
	TString cutStr("Psi_M> "); cutStr += minQ; cutStr += " && Psi_M< "; cutStr += maxQ;

	//B_M 
	RooRealVar B_M("B_M","; m(Kmumu) (MeV/c^{2}); Candidates / 12 MeV/c^{2}",5150,6000);
	RooRealVar Psi_M("Psi_M","; m(mumu) (MeV/c^{2}); Candidates / 45 MeV/c^{2}",500,5000);

	RooDataSet * data  = new RooDataSet("data", "dataset with B_REFITTED_M", DecayTree, RooArgSet(B_M,Psi_M));
	RooDataSet * data1 = dynamic_cast<RooDataSet*>(data->reduce(cutStr));

// from J/Psi region
//   1  #sigma_{Lo}  1.59171e+01   9.61516e-02   1.80663e-03   6.11760e-02
//   2  M_{B}        5.28397e+03   3.00802e-02   1.66677e-03   3.66768e-01
//   3  a1           1.57752e+00   1.64484e-02   2.65338e-03  -7.53912e-01
//   4  a2          -2.64268e+00   2.11254e-02   2.51938e-03   4.90950e-01
//   5  frac         6.78672e-01   1.29969e-02   7.03329e-03   3.65422e-01
//   6  n1           4.79832e+00   2.84430e-01   2.61785e-02  -4.03463e-02
//   7  n2           1.08224e+00   2.68180e-02   5.47500e-03  -9.00362e-01
//   8  nbkg         5.56890e+03   1.31433e+02   7.62084e-03  -8.36640e-01
//   9  nsig         6.56230e+05   8.17224e+02   4.15943e-03   6.95832e-01
//  10  p0          -6.44379e-02   2.13769e-03   2.57927e-02   4.41139e-01
//  11  ratio        1.60407e+00   9.46569e-03   3.93086e-03  -7.72555e-01


	// B DCB 
	// start, range to from. plus names and titles.
	RooRealVar sigmean("M_{B}","B mass",5281.0,5250.0,5300.0,"MeV/c^{2}");
	RooRealVar sigsigma("#sigma_{Lo}","B sigma",15.9,0.0,30.0,"MeV/c^{2}");
	RooRealVar a1("a1","a1", 1.57752e+00);
	RooRealVar n1("n1","n1", 4.79832e+00);
	RooRealVar a2("a2","a2",-2.64268e+00);
	RooRealVar n2("n2","n2", 1.08224e+00);
	RooRealVar ratio("ratio","Ratio of widths",1.60407e+00);
	RooProduct sigsigma2("#sigma_{B}2","B sigma2",RooArgSet(sigsigma,ratio));
	RooRealVar frac("frac","fraction of events in each gaussian",6.78672e-01);
	RooCBShape BSig_RF( "Bsig_RF", "Signal CB B RF Mass", B_M, sigmean, sigsigma, a1, n1 );
	RooCBShape BSig_RF2( "Bsig_RF2", "Signal CB B RF Mass", B_M, sigmean, sigsigma2, a2, n2 );
	RooAddPdf B0Sig("B0signal","signal pdf",RooArgList(BSig_RF,BSig_RF2),RooArgList(frac));

	RooRealVar p0("p0","",-6.44379e-02,-0.1,0.1);
	RooExponential comb_bkg("comb_bkg","",B_M,p0);

	// Number of signal & background events
	RooRealVar nsig("nsig","#signal events",150,-1000,50000,"Events");
	RooRealVar nbkg("nbkg","#signal events",150,-1000,50000,"Events");

	RooAddPdf full_RF_PDF("full_RF_PDF","RF PDF of everything",RooArgList(B0Sig,comb_bkg), RooArgList(nsig,nbkg));

	//# Do the fit on REFITTED Mass
	full_RF_PDF.fitTo(*data1,RooFit::Extended());

	TCanvas * can = new TCanvas("can","Mass fits Data",800,600);
	B_M_RF_Plot = B_M.frame(100);
	B_M_RF_Plot->SetTitle("");
	B_M_RF_Plot->GetYaxis()->SetTitle("Candidates / 8.5 MeV/c^{2}");
	B_M_RF_Plot->GetXaxis()->SetTitle("m(K#mu#mu) (MeV/c^{2})");

	data1->plotOn(B_M_RF_Plot);
	full_RF_PDF.plotOn(B_M_RF_Plot);
	full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("comb_bkg"), RooFit::LineStyle(kDashed),RooFit::LineColor(kMagenta));
        full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("B0signal"), RooFit::LineStyle(kDashed));
	B_M_RF_Plot->Draw();

	can->SaveAs("plots/Kmm_loQ_"+binStr+".pdf");

	can->SetLogy();
        B_M_RF_Plot->SetMinimum(1.e-1);
        B_M_RF_Plot->SetMaximum(5.e+2);
	B_M_RF_Plot->Draw();
	can->SaveAs("plots/Kmm_loQ_"+binStr+"_log.pdf");

      //// Try splot stuff
      //// First set all parameters to constant except for yields
      sigmean.setConstant();
      sigsigma.setConstant();
      p0.setConstant();
      
      RooStats::SPlot * sData = new RooStats::SPlot("sData","An SPlot",*data1, &full_RF_PDF, RooArgList(nsig,nbkg));
      sData->GetSDataSet()->write("/Home/dcraik/Kll/tuples/Kmm_loQ_"+binStr+"_sWeights.txt");

}