예제 #1
0
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
void makeplots(TString runmode = "d", TString drawopt = "norm") {
    gROOT->SetBatch(kTRUE);
    cout<<endl<<"If you want to use custom parameters, option 'b' for branch, 'c' for cuts,";
    cout<<", 'o' to specify the output, or 'f' to select the files and trees to include."<<endl;
    cout<<"Option 'C' saves canvases as .C files."<<endl;
    cout<<"The second parameter is the draw option. 'norm' by default."<<endl<<endl;
    cout<<"This program handles a specified number of variations and generates plots from the files corresponding to these.";
    cout<<" E.g., year, decay, and filetype would plot stuff from nYears*nDecays*nFileTypes files, labeled accordingly.";
    cout<<" This is in addition to however many branches and cuts you would like to perform."<<endl<<endl;
    TString placeholder;//this is to avoid adding strings in functions; assign right before use
    TString placeholder2;
    TString response;//this is for user input; assign right before use
    //default parameters
    TString outputlocation="./";
    TString filename="plots.pdf";
    int nFiles=8;
    vector<TFile*> f(nFiles);
    TString tuplelocation = "/afs/cern.ch/work/m/mwilkins/b_b-bar_cross-section/";
    placeholder = tuplelocation+"Strp20r1_SL_D0andDp_MD.root";
    f[0] = TFile::Open(placeholder);//2011 data B-D0
    placeholder = tuplelocation+"Strp20r1_SL_D0andDp_MD.root";
    f[1] = TFile::Open(placeholder);//2011 data B0D-
    placeholder = tuplelocation+"Bu_D0Xmunu_cocktail_12873441_MC2011_S20r1_noPID_Tuples.root";
    f[2] = TFile::Open(placeholder);//2011 MC B-D0
    placeholder = tuplelocation+"Bd_DpXmunu_cocktail_11874401_MC2011_S20r1_noPID_Tuples.root";
    f[3] = TFile::Open(placeholder);//2011 MC B0D-
    placeholder = tuplelocation+"B2DMuNuX_tuples_05082015.root";
    f[4] = TFile::Open(placeholder);//2015 data B-D0
    placeholder = tuplelocation+"B2DMuNuX_tuples_05082015.root";
    f[5] = TFile::Open(placeholder);//2015 data B0D-
    placeholder = tuplelocation+"Bu_D0Xmunu_cocktail_12873441_MC2015_S22_noPID_Tuples.root";
    f[6] = TFile::Open(placeholder);//2015 MC B-D0
    placeholder = tuplelocation+"Bd_DpXmunu_cocktail_11874401_MC2015_S22_noPID_Tuples.root";
    f[7] = TFile::Open(placeholder);//2015 MC B0D-
    vector<TString> tree(nFiles);
    tree[0] = "tupleb2D0Mu/tupleb2D0Mu";
    tree[1] = "tupleb2DpMu/tupleb2DpMu";
    tree[2] = "Tuple_b2D0MuX/DecayTree";
    tree[3] = "Tuple_b2DpMuX/DecayTree";
    tree[4] = "Tuple_b2D0MuX/DecayTree";
    tree[5] = "Tuple_b2DpMuX/DecayTree";
    tree[6] = "Tuple_b2D0MuX/DecayTree";
    tree[7] = "Tuple_b2DpMuX/DecayTree";
    int nLayers=5;//year, filetype, decay, branch, cuts
    vector<TString> Lresponse(nLayers);
    Lresponse[0]="year";
    Lresponse[1]="filetype";
    Lresponse[2]="decay";
    Lresponse[3]="branch";
    Lresponse[4]="cut";
    vector<int> nL(nLayers);
    nL[0]=2;
    nL[1]=2;
    nL[2]=2;
    nL[3]=1;
    nL[4]=1;
    vector< vector<TString> > L;//L[layer][layerelement]
    L.resize(nLayers);
    for(int i=0; i<nLayers; i++) {
        L[i].resize(nL[i]);
    }
    L[0][0]="2011";
    L[0][1]="2015";
    L[1][0]="data";
    L[1][1]="MC";
    L[2][0]="B^{-}->(D^{0}->K^{-} #pi^{+})#mu^{-}";
    L[2][1]="B^{0}->(D^{-}->K^{+} #pi^{-} #pi^{-})#mu^{+}";
    L[3][0]="";
    L[4][0]="";
    int bL=3;//index corresponding to branch layer
    int nBranches=1;
    int cL=4;//index corresponding to cut layer
    int nCuts=1;
    vector< vector<TString> > branch;//branch[file][branches]
    branch.resize(nFiles);//finished resizing below in loop with cut vector
    vector<int> nBins(nBranches);
    nBins[0]=131;//these are for nLongTracks
    vector<int> loBin(nBranches);
    loBin[0]=0;
    vector<int> hiBin(nBranches);
    hiBin[0]=262;
    vector< vector< vector<TString> > > cut;//cut[file][branch][cuts]
    cut.resize(nFiles);
    for(int i=0; i<nFiles; i++) { //resize and fill branch and cut vectors
        cut[i].resize(nBranches);
        branch[i].resize(nBranches);
        for(int j=0; j<nBranches; j++) {
            cut[i][j].resize(nCuts);
            branch[i][j]="nLongTracks";//only one branch; same for all these files
            for(int k=0; k<nCuts; k++) {
                if(i%2==0) { //since I've listed the files alternating by decay
                    cut[i][j][k]="(B_M>3500)&&(B_M<5000)&&(D_M>1849.84)&&(D_M<1879.84)";
                } else {
                    cut[i][j][k]="(B_M>3500)&&(B_M<5000)&&(D_M>1854.61)&&(D_M<1884.61)";
                }
            }
        }
    }
    int nComparisons=1;
    vector<TString> comparison(nComparisons);
    comparison[0]="decay";
    int nhpc=1;
    int nCanvases=1;
    for(int i=0; i<nLayers; i++) {
        if(i>=(nLayers-nComparisons)) {
            nhpc*=nL[i];//now we're in the realm of comparisons
        } else {
            nCanvases *= nL[i];
        }
    }
    vector<TString> list(0);//this holds the combinations of things used to describe the files;
    //                        keep empty as the combinations are appended in get custom parameters
    //-----------------------------get custom parameters-----------------------//
    if(runmode.Contains("o")) {
        cout<<"Where should the output be stored? (make sure the directory exists; include / at end)"<<endl;
        cin>>outputlocation;
        cout<<"What should the output file be called? (include extension, e.g., 'plots.pdf')"<<endl;
        cin>>filename;
    }
void signalFit()
{
  TFile *file = TFile::Open("treeEDBR_RSGravToZZ_kMpl01_M-4000.root");
  TTree *t0;
  file->GetObject("treeDumper/EDBRCandidates",t0);

  RooRealVar numCands("numCands", "number of candidates", 0., 100.);
  RooRealVar lep("lep", "leptonic number", 0., 100.);
  RooRealVar tau21("tau21", "n-subjettiness", 0., 1.);
  RooRealVar lumiWeight("lumiWeight", "pure weight", 0., 10.);
  RooRealVar candMass("candMass","M_{ZZ}", 100.,7100., "GeV");
  const char* elLo = "numCands>0 && lep<12 && tau21<0.5";
  const char* muLo = "numCands>0 && lep>12 && tau21<0.5";
  const char* elHi = "numCands>0 && lep<12 && tau21>0.5 && tau21<0.75";
  const char* muHi = "numCands>0 && lep>12 && tau21>0.5 && tau21<0.75";
  // The muon and electron channels are considered separately  
  RooDataSet elLods("elLods","elLods",RooArgSet(candMass,numCands,lep,tau21,lumiWeight),RooFit::Cut(elLo),RooFit::WeightVar(lumiWeight),RooFit::Import(*t0));
  RooDataSet muLods("muLods","muLods",RooArgSet(candMass,numCands,lep,tau21,lumiWeight),RooFit::Cut(muLo),RooFit::WeightVar(lumiWeight),RooFit::Import(*t0));
  RooDataSet elHids("elHids","elHids",RooArgSet(candMass,numCands,lep,tau21,lumiWeight),RooFit::Cut(elHi),RooFit::WeightVar(lumiWeight),RooFit::Import(*t0));
  RooDataSet muHids("muHids","muHids",RooArgSet(candMass,numCands,lep,tau21,lumiWeight),RooFit::Cut(muHi),RooFit::WeightVar(lumiWeight),RooFit::Import(*t0));
  RooRealVar mean("mean","mean of the Crystal Ball",4000.,100.,7100.);
  RooRealVar sigma("sigma","Crystal Ball sigma",100.,10.,1000.);
  RooRealVar alphaL("alphaL","alpha left",  1.,  0.,10.);
  RooRealVar alphaR("alphaR","alpha right",-1.,-10., 0.);
  RooRealVar nL("nL","n left", 3.,0.,10.);
  RooRealVar nR("nR","n right",3.,0.,10.);
  // Build Crystal Ball for the left tail
  RooCBShape cbL("cbL","Left Crystal Ball PDF",candMass,mean,sigma,alphaL,nL);
  // Build Crystal Ball for the right tail
  RooCBShape cbR("cbR","Right Crystal Ball PDF",candMass,mean,sigma,alphaR,nR);
  // Add the previous PDFs to build the Double Crystall Ball
  RooRealVar frac("frac","fraction",0.5);
  RooAddPdf cbLR("cbLR","Double Crystall Ball",RooArgList(cbL,cbR),frac);

  TCanvas *c1 = new TCanvas("c1","c1", 1200, 900);
  c1->Divide(2,2,0.00001,0.01);
  c1->cd(1);
  RooPlot* frame1 = candMass.frame(RooFit::Title("CMS Preliminary     #sqrt{s} = 13 TeV     #int L dt = 3 fb^{-1}") );
  muLods.plotOn(frame1); 
  cbLR.fitTo(muLods,RooFit::Range(2500.,5500.));
  cbLR.plotOn(frame1,RooFit::LineColor(kRed)); 
  gPad->SetGridx();
  gPad->SetGridy();
  frame1->Draw();
  frame1->GetYaxis()->SetTitle();
  frame1->GetXaxis()->SetTitleSize(0.045);
  frame1->GetXaxis()->SetLabelSize(0.045);
  TLegend *leg1 = new TLegend(0.13,0.7,0.4,0.88);
  leg1->AddEntry("h_muLods","MC signal","ep");
  leg1->AddEntry("cbLR_Norm[candMass]_Range[fit_nll_cbLR_muLods]_NormRange[fit_nll_cbLR_muLods]","Fit model","l");
  leg1->Draw(); 
  TPaveText *pt1 = new TPaveText(0.63,0.61,0.88,0.88,"NDC");
  pt1->SetFillColor(0);
  pt1->SetBorderSize(1);
  pt1->SetTextFont(42);
  pt1->AddText("muon channel");
  pt1->AddText("#tau_{21} < 0.5");
  pt1->AddText(Form("#chi^{2} / ndf  :  %.2f",frame1->chiSquare(6)));
  pt1->Draw();

  c1->cd(2);
  RooPlot* frame2 = candMass.frame(RooFit::Title("CMS Preliminary     #sqrt{s} = 13 TeV     #int L dt = 3 fb^{-1}") );
  elLods.plotOn(frame2); 
  cbLR.fitTo(elLods,RooFit::Range(2500.,5500.));
  cbLR.plotOn(frame2,RooFit::LineColor(kRed)); 
  gPad->SetGridx();
  gPad->SetGridy();
  frame2->Draw();
  frame2->GetYaxis()->SetTitle();
  frame2->GetXaxis()->SetTitleSize(0.045);
  frame2->GetXaxis()->SetLabelSize(0.045);
  TLegend *leg2 = new TLegend(0.13,0.7,0.4,0.88);
  leg2->AddEntry("h_elLods","MC signal","ep");
  leg2->AddEntry("cbLR_Norm[candMass]_Range[fit_nll_cbLR_muLods,fit_nll_cbLR_elLods]_NormRange[fit_nll_cbLR_muLods,fit_nll_cbLR_elLods]","Fit model","l");
  leg2->Draw(); 
  TPaveText *pt2 = new TPaveText(0.6,0.61,0.88,0.88,"NDC");
  pt2->SetFillColor(0);
  pt2->SetBorderSize(1);
  pt2->SetTextFont(42);
  pt2->AddText("electron channel");
  pt2->AddText("#tau_{21} < 0.5");
  pt2->AddText(Form("#chi^{2} / ndf  :  %.2f",frame2->chiSquare(6)));
  pt2->Draw();

  c1->cd(3);
  RooPlot* frame3 = candMass.frame(RooFit::Title("CMS Preliminary     #sqrt{s} = 13 TeV     #int L dt = 3 fb^{-1}") );
  muHids.plotOn(frame3); 
  cbLR.fitTo(muHids,RooFit::Range(2500.,5500.));
  cbLR.plotOn(frame3,RooFit::LineColor(kRed)); 
  gPad->SetGridx();
  gPad->SetGridy();
  frame3->Draw();
  frame3->GetYaxis()->SetTitle();
  frame3->GetXaxis()->SetTitleSize(0.045);
  frame3->GetXaxis()->SetLabelSize(0.045);
  TLegend *leg3 = new TLegend(0.13,0.7,0.4,0.88);
  leg3->AddEntry("h_muHids","MC signal","ep");
  leg3->AddEntry("cbLR_Norm[candMass]_Range[fit_nll_cbLR_muLods,fit_nll_cbLR_elLods,fit_nll_cbLR_muHids]_NormRange[fit_nll_cbLR_muLods,fit_nll_cbLR_elLods,fit_nll_cbLR_muHids]","Fit model","l");
  leg3->Draw(); 
  TPaveText *pt3 = new TPaveText(0.63,0.61,0.88,0.88,"NDC");
  pt3->SetFillColor(0);
  pt3->SetBorderSize(1);
  pt3->SetTextFont(42);
  pt3->AddText("muon channel");
  pt3->AddText("0.5 < #tau_{21} < 0.75");
  pt3->AddText(Form("#chi^{2} / ndf  :  %.2f",frame3->chiSquare(6)));
  pt3->Draw();

  c1->cd(4);
  RooPlot* frame4 = candMass.frame(RooFit::Title("CMS Preliminary     #sqrt{s} = 13 TeV     #int L dt = 3 fb^{-1}") );
  elHids.plotOn(frame4); 
  cbLR.fitTo(elHids,RooFit::Range(2500.,5500.));
  cbLR.plotOn(frame4,RooFit::LineColor(kRed)); 
  gPad->SetGridx();
  gPad->SetGridy();
  frame4->Draw();
  frame4->GetYaxis()->SetTitle();
  frame4->GetXaxis()->SetTitleSize(0.045);
  frame4->GetXaxis()->SetLabelSize(0.045);
  TLegend *leg4 = new TLegend(0.13,0.7,0.4,0.88);
  leg4->AddEntry("h_elHids","MC signal","ep");
  leg4->AddEntry("cbLR_Norm[candMass]_Range[fit_nll_cbLR_muLods,fit_nll_cbLR_elLods,fit_nll_cbLR_muHids,fit_nll_cbLR_elHids]_NormRange[fit_nll_cbLR_muLods,fit_nll_cbLR_elLods,fit_nll_cbLR_muHids,fit_nll_cbLR_elHids]","Fit model","l");
  leg4->Draw(); 
  TPaveText *pt4 = new TPaveText(0.6,0.61,0.88,0.88,"NDC");
  pt4->SetFillColor(0);
  pt4->SetBorderSize(1);
  pt4->SetTextFont(42);
  pt4->AddText("electron channel");
  pt4->AddText("0.5 < #tau_{21} < 0.75");
  pt4->AddText(Form("#chi^{2} / ndf  :  %.2f",frame4->chiSquare(6)));
  pt4->Draw();

}