Ejemplo n.º 1
0
TH1D* plot (std::string num, std::string den,std::vector<TFile*>& tfiles,std::vector<double>& weights) {

    double weightTot = 0.0;

    for ( int i = 0; i<weights.size(); i++) {
        weightTot+=weights[i];
    }

    std::string name = num;
    name+="NEW";
    TH1D* hNum = (TH1D*)tfiles[0]->Get(num.c_str());
    TH1D* HNum = (TH1D*)hNum->Clone(name.c_str());
    HNum->Sumw2();



    name=den;
    name+="NEW";
    TH1D* hDen = (TH1D*)tfiles[0]->Get(den.c_str());
    TH1D* HDen = (TH1D*)hDen->Clone(name.c_str());
    HDen->Sumw2();

    for (int i=1; i<tfiles.size(); i++) {
        TH1D* htempNum = (TH1D*)tfiles[i]->Get(num.c_str());
        TH1D* htempDen = (TH1D*)tfiles[i]->Get(den.c_str());
        HNum->Add(htempNum,weights[i]/weightTot);
        HDen->Add(htempDen,weights[i]/weightTot);
    }
    name = num;
    name+="Div";
    TH1D* hDiv = (TH1D*)HNum->Clone(name.c_str());
    //hDiv->Sumw2();
    hDiv->Divide(HDen);
    return hDiv;
}
Ejemplo n.º 2
0
void Drawbbc(){
	TFile *f = new TFile("merged.root");
	TH1D* hbbcs;
	TH1D* hbbcn;
	TCanvas *c1;
	TCanvas *c2;
	TLegend *leg = new TLegend(0.5,0.7,0.7,0.85);
	leg->SetBorderSize(0);
	leg->SetFillColor(0);
	leg->SetTextSize(0.048);
	TH2F* bbcsbbcn = (TH2F*)f->Get(Form("bbcsbbcn_0"));
	for(int xcent=1; xcent < 6; xcent++){
		TH1F* bbcsbbcndis_t = (TH1F*)f->Get(Form("bbcsbbcn_%d",xcent));
		bbcsbbcn->Add(bbcsbbcndis_t);
	}
	hbbcs = (TH1D*)bbcsbbcn->ProjectionX("bbcs",0,-1);
	hbbcn = (TH1D*)bbcsbbcn->ProjectionY("bbcn",0,-1);
	hbbcs->Rebin(4);
	hbbcn->Rebin(4);
	c1= new TCanvas();
	c1->cd();
	c1->SetLogy();
	SetTitle(*hbbcs,"bbc charge","# of events","");
	SetRange(*hbbcs,0,1e-1,100,hbbcn->GetMaximum()*5);
	SetStyle(*hbbcs,1.2,1,20,0,0);
	SetStyle(*hbbcn,1.2,2,24,0,0);
	hbbcs->Draw("P");
	hbbcn->Draw("Psame");
	leg->AddEntry(hbbcs,"bbc south");
	leg->AddEntry(hbbcn,"bbc north");
	leg->Draw("same");
	c1->Print(Form("bbcdis.png"));
	c2= new TCanvas();
	c2->cd();
	c2->SetLogy();
	hbbcs_norm = (TH1D*)hbbcs->Clone("hbbcs_norm");
	hbbcn_norm = (TH1D*)hbbcn->Clone("hbbcn_norm");
	hbbcs_norm->Scale(1./hbbcs_norm->Integral());
	hbbcn_norm->Scale(1./hbbcn_norm->Integral());
	SetRange(*hbbcs_norm,0,1e-9,100,1);
	hbbcs_norm->Draw("P");
	hbbcn_norm->Draw("Psame");
	leg->Draw("same");
	c2->Print(Form("bbcdis_norm.png"));	
	c3= new TCanvas();
	c3->cd();
	c3->SetLogz();
	SetTitle(*bbcsbbcn,"bbc charge south","bbc charge north","# of events");
	SetRange(*bbcsbbcn,0,0,100,100);
	bbcsbbcn->Draw("colz");
	c3->Print("bbcsbbcn.png");
}
Double_t MakeHistsForSlides(TString goodFile, TString badFile, TString rootFile)
{
  //Extracting the histogram
  TFile* f = TFile::Open(rootFile);
  TDirectoryFile* dirFile = (TDirectoryFile*)(f->Get("AliAnalysisTaskCalibEmcal"));
  TList* list = (TList*)(dirFile->Get("histogram"));
  TH2D* cellVAmplitude = (TH2D*)(list->FindObject("_histogram_cell_id_amplitude"));

    
  //Getting a Good Cell
  TH1D* goodC = new TH1D();
  ifstream myFile(goodFile);
  TString title = "";

  const int num = 500;

  if(myFile.is_open())
    {
      string line = "";
      std::getline(myFile,line);

      int index = 0;
      double chi2 = 0.0;
      
      while(myFile >> index >> chi2 && index < num)
	{
	  //cout << index << "\t" << chi2 << endl;
	  title = Form("Energy distribution of Cell %d",index);
	  TH1D* goodCell = cellVAmplitude->ProjectionY("goodCell", index+1,index+1);
	  goodC = (TH1D*)goodCell->Clone();
	}
    }
Ejemplo n.º 4
0
void NTupleSS() {
    double Lumi = 19700.;
    double signal_weight = 2.39163;//Lumi/(3263180./1177.3);
    double ttbar_weight  = Lumi / (4246440. / 23.64);
    double tautau_weight = Lumi / (3297032. / 1966.7);
    double tbarw_weight  = Lumi / (493460. / 11.1);
    double tw_weight     = Lumi / (497658. / 11.1);
    double ww_weight     = Lumi / (10000430. / 54.94);
    double wz_weight     = Lumi / (10000280. / 33.21);
    double zz_weight     = Lumi / (9799908. / 17.7);

    TH1D* Data = GetDataPhiStar();
    TH1D* h_ee    = GetBGPhiStar(File_Signal_reco,    signal_weight);
    TH1D* h_zz    = GetBGPhiStar(File_zz,    zz_weight);
    TH1D* h_tt    = GetBGPhiStar(File_tt,    ttbar_weight);
    TH1D* h_tautau = GetBGPhiStar(File_tautau, tautau_weight);
    TH1D* h_tbarw = GetBGPhiStar(File_tbarw, tbarw_weight);
    TH1D* h_tw    = GetBGPhiStar(File_tw,    tw_weight);
    TH1D* h_ww    = GetBGPhiStar(File_ww,    ww_weight);
    TH1D* h_wz    = GetBGPhiStar(File_wz,    wz_weight);
    //  TH1D* h_zz    =GetBGPhiStar(File_zz,    zz_weight);

    double data_sel = Data->GetSumOfWeights();
    double ee_sel = h_ee->GetSumOfWeights();
    double tt_sel = h_tt->GetSumOfWeights();
    double tautau_sel = h_tautau->GetSumOfWeights();
    double tbarw_sel = h_tbarw->GetSumOfWeights();
    double tw_sel = h_tw->GetSumOfWeights();
    double ww_sel = h_ww->GetSumOfWeights();
    double wz_sel = h_wz->GetSumOfWeights();
    double zz_sel = h_zz->GetSumOfWeights();

    // double t_bg=ee_sel+tt_sel+tautau_sel+tbarw_sel+tw_sel+ww_sel+wz_sel+zz_sel;
    double t_bg = ee_sel + tt_sel + tautau_sel + tbarw_sel + tw_sel + ww_sel +
                  wz_sel + zz_sel;
    cout << "total left:" << data_sel - t_bg;
    cout << "Data: " << data_sel << "  ee: " << ee_sel << "  tt: " << tt_sel <<
         "  tautau: " << tautau_sel << "  tbarw: " << tbarw_sel << "  tw: " << tw_sel <<
         " singletop: " << tbarw_sel + tw_sel << "  ww: " << ww_sel << "  wz: " << wz_sel
         << "  zz: " << zz_sel << endl;
    cout << "ratio:"          << "  ee: " << ee_sel / data_sel << "  tt: " << tt_sel
         / data_sel << "  tautau: " << tautau_sel / data_sel << "  tbarw: " << tbarw_sel
         / data_sel << "  tw: " << tw_sel / data_sel << " singletop: " <<
         (tbarw_sel + tw_sel) / data_sel << "  ww: " << ww_sel / data_sel << "  wz: " <<
         wz_sel / data_sel << "  zz: " << zz_sel / data_sel << "data: " <<
         (data_sel - t_bg) / data_sel << endl;

    TH1D* h_qcd  = (TH1D*)Data->Clone();
    h_qcd->Add(h_ee, -1.0);
    h_qcd->Add(h_tt, -1.0);
    h_qcd->Add(h_tautau, -1.0);
    h_qcd->Add(h_tbarw, -1.0);
    h_qcd->Add(h_tw, -1.0);
    h_qcd->Add(h_ww, -1.0);
    h_qcd->Add(h_wz, -1.0);
    h_qcd->Add(h_zz, -1.0);

    h_qcd->Draw();
    cout << "norm=" << h_qcd->GetSumOfWeights() << endl;;
}
Ejemplo n.º 5
0
void CheckTaggEffButVsH() {
	Char_t Name[256];
	Char_t *VarName;

	//Connect to all existing histograms
	RootFileBut = new TFile(Str_RootFilesBut);
	TH2D *hBut2D = (TH2D*)gROOT->FindObject("hTaggerTime");
	RootFileH = new TFile(Str_RootFilesH);
	TH2D *hH2D = (TH2D*)gROOT->FindObject("hTaggerTime");

	gROOT->cd();

	TH1D *hButBg = hBut2D->ProjectionY("TempBut1D", 800, 950);
	TH1D *hHBg = hH2D->ProjectionY("TempH1D", 800, 950);


	TCanvas *c1 = new TCanvas();
	gStyle->SetPalette(1);
	c1->Divide(2,2);
	c1->cd(1);
	hButBg->Draw("");
	c1->cd(2);
	hHBg ->Draw("");
	c1->cd(3);
	delete gROOT->FindObject("Diff");
	TH1D *hDiff = (TH1D*) hButBg->Clone("Diff");
	hDiff->Divide(hHBg);
	hDiff->Draw();
	

	RootFileBut->Close();
	RootFileH->Close();

	printf("Finished.\n");
}
Ejemplo n.º 6
0
void MCefficiency(TString inputmc, TString outputfile, TString tfend, TString selmcgen, TString cut, TString weight, Float_t centmin, Float_t centmax)
{
  Float_t hiBinMin,hiBinMax;
  hiBinMin = centmin*2;
  hiBinMax = centmax*2;

  selmcgen = Form("%s&&hiBin>=%f&&hiBin<%f",selmcgen.Data(),hiBinMin,hiBinMax);
  cut = Form("%s&&hiBin>=%f&&hiBin<%f",cut.Data(),hiBinMin,hiBinMax);

  TFile* infMC = new TFile(inputmc.Data());
  TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
  ntMC->AddFriend("ntHi");
  ntMC->AddFriend("ntSkim");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  ntGen->AddFriend("ntHi");
  ntGen->AddFriend("ntSkim");

  TH1D* hPtMC = new TH1D("hPtMC","",nPtBins,ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",nPtBins,ptBins);

  ntMC->Project("hPtMC","Dpt",TCut(weight)*(TCut(cut.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMC);
  ntGen->Project("hPtGen","Gpt",TCut(weight)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);
  TH1D* hEff = (TH1D*)hPtMC->Clone("hEff");
  hEff->Divide(hPtGen);

  TFile* fout=new TFile(Form("%s_cent_%.0f_%.0f_%s.root",outputfile.Data(),centmin,centmax,tfend.Data()),"recreate");
  fout->cd();
  hEff->Write();
  fout->Close();
}
Ejemplo n.º 7
0
TH1D * scaleHistsFromPtHatRootFilesReturnHist( string histname, vector <TFile* > &rootFiles )
{
    const double lumi = 40.03 ; // pb-1
    vector <double> mcscales;
    // mcscales.push_back(  117276.          / 3468514. * lumi);  // xs / nevents * lumi
    // mcscales.push_back(    7823.          / 2936644. * lumi);
    mcscales.push_back(     648.2         / 1971800. * lumi);
    mcscales.push_back(     186.9         / 1981608. * lumi);
    mcscales.push_back(      32.293       / 1990208. * lumi);
    mcscales.push_back(       9.4183      / 1487712. * lumi);
    mcscales.push_back(       0.84265     /  197959. * lumi);
    mcscales.push_back(       0.114943    /  194924. * lumi);
    mcscales.push_back(       0.00682981  /  198383. * lumi);
    mcscales.push_back(       0.000165445 /  194528. * lumi);

    TH1D * htemp = (TH1D*)  rootFiles[0] -> Get( histname.c_str() );
    TH1D * h_sum = (TH1D*)htemp->Clone();
    h_sum->Reset();
    h_sum->Sumw2();

    for (unsigned int i=0; i<rootFiles.size(); i++) {
        TH1D * h1 = (TH1D*)  rootFiles[i] -> Get( histname.c_str() );
        // h1->Sumw2();
        h1->Scale(mcscales[i]);
        h_sum->Add(h1);
        // cout<<mcscales[i]<<"  "<<h1->Integral()<<endl;
    }
    return h_sum;
}
Ejemplo n.º 8
0
// Convert plots to paper format - no title, bigger fonts etc
void combineHists( TFile* fSig, TFile* fBg, TFile* fBg2, std::string histName, std::string plotOpt, std::string outputName, std::vector<double> scalingFactors, std::string label, std::string yTitle="DEFAULT"){
    TH1::SetDefaultSumw2();

    // for 3 hists - sig and 2 bg
    TCanvas c1;
    TH1D* hSig = fSig->Get(histName.c_str());
    hSig->SetLineColor(kRed);
    hSig->SetMarkerSize(0);
    doSignalHist(hSig);
    
    // Make combined BG hist
    // Need to rescale carefully
    std::vector<TFile*> files;
    files.push_back(fBg);
    files.push_back(fBg2);
    // TH1D* hBg = combine(files, histName, scalingFactors);
    TH1D* hBgA = fBg->Get(histName.c_str());
    TH1D* hBgB =  fBg2->Get(histName.c_str());
    TH1D* hBg = (TH1D*) hBgA->Clone();
    double total = scalingFactors[0]+scalingFactors[1];
    hBg->Scale(scalingFactors[0]/total);
    hBg->Add(hBgB, scalingFactors[1]/total);
    hBg->SetMarkerSize(0);
    doAltBGHist(hBg);
    
    THStack st("h","");
    st.Add(hSig);
    st.Add(hBg);
    st.Draw((plotOpt+"NOSTACK").c_str());
    st.GetXaxis()->SetTitle(hSig->GetXaxis()->GetTitle());
    if (yTitle == "DEFAULT") {
        st.GetYaxis()->SetTitle(hSig->GetYaxis()->GetTitle());
    } else {
        st.GetYaxis()->SetTitle(yTitle.c_str());
    }
    setAltTitleLabelSizes(&st.GetHistogram());
    st.SetTitle("");
    st.Draw((plotOpt+"NOSTACK").c_str());

    TLegend* l_all = new TLegend(0.65,0.6,0.89,0.89);
    l_all->AddEntry(hBg,"Gen. level QCD MC","lp");
    l_all->AddEntry((TObject*)0,"(b#bar{b} + q-g scatter,",""); //null pointers for blank entries
    l_all->AddEntry((TObject*)0,"q = b, #bar{b}, c, #bar{c})","");
    l_all->AddEntry(hSig, "Signal MC", "lp");
    l_all->AddEntry((TObject*)0,"m_{#phi} = 8 GeV", "");
    doStandardLegend(l_all);
    l_all->Draw();

    TPaveText t(0.15, 0.75, 0.5, 0.85, "NDC");
    t.AddText(label.c_str());
    doStandardText(&t);
    if (label != "") {
        t.Draw();
    }
    c1.SaveAs(outputName.c_str());

    if (!hSig) delete hSig;
    if (!hBg) delete hBg;
}
void  makeGaussianSignals(SigData_t& m_sigdata)
{
  //std::vector<TH1D *> vgsh(NUMCHAN);
  std::vector<TH1D *> vcdfh(NUMCHAN);

  if( m_sigdata.find("gs") == m_sigdata.end() ) {
    cerr << "Gaussian signal data not found, not making CDF signal!" << endl;
    return;
  }

  for (int ichan=0; ichan<NUMCHAN; ichan++) {
    TH1D *cdfh;

    TString channame(channames[ichan]);
    TString name;

    TH1D * gsh = m_sigdata["gs"].at(ichan);

    assert(gsh) ;

#if 0
    name = "Signalgs_"+channame;
    gsh = (TH1D *)tch->Clone(name.Data());

    assert(gsh);

    gsh->SetTitle("Gaussian signal");
    
    gsh->Reset();

    TF1 *g = (TF1 *)gROOT->GetFunction("gaus");
    g->SetParameters(1,gaussian_mean_mass_gev,gaussian_mass_sigma_gev);
    gsh->FillRandom("gaus",100000);

    // norm to 1pb signal with 1/fb integrated luminosity
    double norm = 1000 * gseffxacc[ichan]/gsh->Integral(0,gsh->GetNbinsX()+1,"width");

    //gsh->Scale(norm/eff_fudgefactor); // kludge: pre-undo the fudge in the next module
    gsh->Scale(norm);

    vgsh[ichan] = gsh;
#endif

    // New CDF bump, same as Gauss but set to CDF (obs/theor)*(LHC theor) = 3.43pb
    cdfh = (TH1D *)gsh->Clone("CDFbump");

    cdfh->Scale(3.43);

    vcdfh[ichan] = cdfh;

    cdfh->Draw();

    gsh->Draw("same");

  } // channel loop

  //m_sigdata["gs"]  = vgsh;
  m_sigdata["cdf"] = vcdfh;
}                                                           // makeGaussianSignals
Ejemplo n.º 10
0
void loglikdistrib(Int_t ntrials = 10000, Bool_t print = kFALSE)
{
  // compute distribution of log likelihood value
  TH1D * hmc   = gStack[gPadNr][gOrder[gPadNr][0]];
  TH1D * hdata = gStack[gPadNr][gMaxProcess-1];
  Int_t nbins = hmc->GetNbinsX();
  Double_t loglik = loglikelihood(hmc, hdata, 1, nbins);
  TH1D * htest = new TH1D(*hdata);
  TH1D * lldistrib = new TH1D("lldistrib", "log(Likelihood) distribution", 
			      1000, loglik-200, loglik+200);
  setopt(lldistrib);
  for (Int_t n = 0; n < ntrials; n++) {
    // generate poisson around theorie
    for (Int_t i = 1; i <= nbins; i++) {
      htest->SetBinContent(i, gRandom->Poisson(hmc->GetBinContent(i)));
    }
    lldistrib->Fill(loglikelihood(hmc, htest, 1, nbins));
  }
  TCanvas * llcanvas = new TCanvas("llcanvas", "Log(Likelihood) distribution", 
				   40, 40, 800, 600);
  setopt(llcanvas);
  lldistrib->SetFillColor(kYellow);
  lldistrib->Draw();
  lldistrib->GetYaxis()->SetTitle("Anzahl Ereignisse");
  lldistrib->GetXaxis()->SetTitle("-ln L");
  // autozoom
  Int_t lowbin = 1;
  while (lldistrib->GetBinContent(lowbin) == 0)
    lowbin++;
  Int_t highbin = lldistrib->GetNbinsX();
  while (lldistrib->GetBinContent(highbin) == 0)
    highbin--;
  lldistrib->SetAxisRange(lldistrib->GetBinLowEdge(lowbin), 
			  lldistrib->GetBinLowEdge(highbin));
  TH1D * hworse = (TH1D *) lldistrib->Clone();
  for (Int_t nbin = 1; nbin < 501; nbin++) {
    hworse->SetBinContent(nbin, 0);
  }
  hworse->SetFillColor(95);
  hworse->Draw("same");
  Double_t pvalue = lldistrib->Integral(501,1000) / lldistrib->Integral();
  TLatex * tex = new TLatex(0.18, 0.96, Form("-ln L_{obs} = %5.2f", loglik));
  tex->SetNDC();
  tex->SetTextAlign(13);
  tex->Draw();
  tex = new TLatex(0.18, 0.86, Form("CL_{obs} = %.3f", pvalue));
  tex->SetNDC();
  tex->SetTextAlign(13);
  tex->Draw();
  TLine * l = new TLine(loglik, 0, loglik, lldistrib->GetMaximum());
  l->SetLineWidth(3);
  l->SetLineColor(kBlue);
  l->Draw();
  llcanvas->Modified();
  llcanvas->Update();
  if (print)
    llcanvas->Print("lldistrib.pdf");
  cd(gPadNr+1);
}
Ejemplo n.º 11
0
void getComparisons_ABCD(TString INPUTDIR_PREFIX, TString varType, TString whichHist, TString SCEN_TRIG, TString shapeComb, TString RR) {

   //Add categories according to the factorization ansats. Fixed
   const int nconfs = 3;
   TString overallConfs[nconfs] = {"Glb_Tight2012_IsolPFRelCombNoEGammaR03_"+SCEN_TRIG,"Glb_Tight2012_IsolPFRelCombNoEGammaR03","Glb_Tight2012"};

   //get TP efficiencies for above categories
   TH1D* htrigAB;
   TH1D* hisoAB;
   TH1D* hrecoidAB;
   TH1D* htrig_mc;
   TH1D* hiso_mc;
   TH1D* hrecoid_mc; 

   if (whichHist == "trig")     htrigAB   = getSimplePlot(INPUTDIR_PREFIX,overallConfs[0],"data_all",varType,SCEN_TRIG,"RunAB");
   if (whichHist == "iso")      hisoAB    = getSimplePlot(INPUTDIR_PREFIX,overallConfs[1],"data_all",varType,SCEN_TRIG,"RunAB");
   if (whichHist == "recoid")   hrecoidAB = getSimplePlot(INPUTDIR_PREFIX,overallConfs[2],"data_all",varType,SCEN_TRIG,"RunAB");

   if (whichHist == "trig")     htrigC   = getSimplePlot(INPUTDIR_PREFIX,overallConfs[0],"data_all",varType,SCEN_TRIG,"RunC");
   if (whichHist == "iso")      hisoC    = getSimplePlot(INPUTDIR_PREFIX,overallConfs[1],"data_all",varType,SCEN_TRIG,"RunC");
   if (whichHist == "recoid")   hrecoidC = getSimplePlot(INPUTDIR_PREFIX,overallConfs[2],"data_all",varType,SCEN_TRIG,"RunC");

   if (whichHist == "trig")     htrigD   = getSimplePlot(INPUTDIR_PREFIX,overallConfs[0],"data_all",varType,SCEN_TRIG,"RunD");
   if (whichHist == "iso")      hisoD    = getSimplePlot(INPUTDIR_PREFIX,overallConfs[1],"data_all",varType,SCEN_TRIG,"RunD");
   if (whichHist == "recoid")   hrecoidD = getSimplePlot(INPUTDIR_PREFIX,overallConfs[2],"data_all",varType,SCEN_TRIG,"RunD");

   if (whichHist == "trig")     htrig_mc   = (TH1D*)htrigAB->Clone();
   if (whichHist == "iso")      hiso_mc    = (TH1D*)hisoAB->Clone(); 
   if (whichHist == "recoid")   hrecoid_mc = (TH1D*)hrecoidAB->Clone();

   if (varType != "rrr" && varType != "rrr2" && varType != "rrr3") {    
     if (whichHist == "trig")   { 
        htrig_mc   = getSimplePlot(INPUTDIR_PREFIX,overallConfs[0],"datalike_mc",varType,SCEN_TRIG,RR);
        getComparisonABCDratio(htrig_mc, htrigAB, htrigC, htrigD, varType, true, INPUTDIR_PREFIX,RR);
     } 
     if (whichHist == "iso")    {
        hiso_mc    = getSimplePlot(INPUTDIR_PREFIX,overallConfs[1],"datalike_mc",varType,SCEN_TRIG,RR);
        getComparisonABCD(hiso_mc, hisoAB, hisoC, hisoD, varType, true, INPUTDIR_PREFIX,RR);
     }
     if (whichHist == "recoid") { 
        hrecoid_mc = getSimplePlot(INPUTDIR_PREFIX,overallConfs[2],"datalike_mc",varType,SCEN_TRIG,RR);
        getComparisonABCD(hrecoid_mc, hrecoidAB, hrecoidC, hrecoidD, varType,true, INPUTDIR_PREFIX,RR);
     }
   }
}
Ejemplo n.º 12
0
	// 1 file argument -> add e+m from same files e.g. mc
	// this is considered to be MC -> added to sum histo
	TH1D* get(const TString& File){ //
		TFile file(path+File);
		TH1D* mH = (TH1D*)file.Get(mName);
		TH1D* eH = (TH1D*)file.Get(eName);
		gROOT->cd();
		TH1D*  H = mH->Clone();// Sumw2() is copied as well
		H->Add(eH);
		return H;
	}
Ejemplo n.º 13
0
// -----------------------------------------------------------------------------
//
TH1* getHisto( std::string nameFile,
	       std::string nameHist,
	       std::string Dirname, 
	       int rebin ) {
  std::string name = nameFile;
  TFile* file =  new TFile(name.c_str());
  if (file) { std::cout << "Opened file: " << file->GetName() << std::endl; }
  else { 
    std::cout << "Could not find file: " << name << std::endl; 
    return 0; 
  }
  
  TDirectory* dir = (TDirectory*)file->Get(Dirname.c_str());
  if (dir) { std::cout << "Opened dir: " << dir->GetName() << std::endl; }
  else { 
    std::cout << "Could not find dir: " << Dirname << std::endl; 
    return 0; 
  }
  
  int low = 375;
  TH1* hist = 0;
  if ( false || nameHist.find("HtMultiplicity_HT375") == std::string::npos ) { 
    hist = (TH1*)dir->Get(nameHist.c_str());
  } else {
    
    for ( uint ii = low; ii <= 975; ii+=100 ) {
      std::stringstream tmp; tmp << "HtMultiplicity_HT" << ii << nameHist.substr(20);
      if ( !hist ) { 
	dir->cd();
	TH1D* temp = (TH1D*)dir->Get( "HtMultiplicity_HT375_aT0" );
	//TH1D* temp = (TH1D*)file->Get( tmp.str().c_str() );
	if (temp) { hist = (TH1D*)temp->Clone(); } 
	else { std::cout << "1 Unable to retrieve histo with name " << tmp.str() << std::endl; }
      } else { 
	dir->cd();
	TH1D* temp = (TH1D*)dir->Get( tmp.str().c_str() );
	if (temp) { hist->Add( (TH1D*)temp ); } 
	else { std::cout << "2 Unable to retrieve histo with name " << tmp.str() << std::endl; }
      }
    }

  }
  if (hist) { std::cout << "Opened histo: " << hist->GetName() << std::endl; }
  else { 
    std::cout << "Could not find histo: " << nameHist << std::endl; 
    return 0; 
  }

  hist->SetLineWidth(3);
  if ( rebin > 0 ) { hist->Rebin(rebin); }
  hist->GetXaxis()->SetTitleSize(0.055);
  hist->GetYaxis()->SetTitleSize(0.055);
  hist->GetXaxis()->SetLabelSize(0.05);
  hist->GetYaxis()->SetLabelSize(0.05);
  hist->SetStats(kFALSE);
  return hist;
}
Ejemplo n.º 14
0
	// 2 file arguments -> add e+m from different files e.g. data
	// this is considered to be data not added to sum histo
	TH1D* get(const TString& eFile, const TString& mFile){
		TFile mfile(path+mFile);
		TFile efile(path+eFile);
		TH1D* mH = (TH1D*)mfile.Get(mName);
		TH1D* eH = (TH1D*)efile.Get(eName);
		gROOT->cd();
		TH1D*  H = mH->Clone();
		H->Add(eH);
		return H;
	}
Ejemplo n.º 15
0
int main(){
	TFile * data = TFile::Open("TreesMu_Data_plots.root");
	TH1D * dataMtop = (TH1D*)data->Get("antiEtaFwDTrue_allW/antiEtaFwDTrue_allWcosTheta");
	
	TFile * tt = TFile::Open("TreesMu_TTBar_RW.root");
	
	TH1D * ttMtop = (TH1D*)tt->Get("MtopOutWindowTrue_allW/MtopOutWindowTrue_allWcosTheta");
	
	TH2D * ttMtop2D = (TH2D*)tt->Get("MtopOutWindowTrue_allW/MtopOutWindowTrue_allWcosTheta2D");
	
  std::pair<TF1, WeightFunctionCreator*> WeightFuncUD(WeightFunctionCreator::getWeightFunction("WeightFuncUDF", F0, FL));
  std::pair<TF1, WeightFunctionCreator*> WeightFuncDU(WeightFunctionCreator::getWeightFunction("WeightFuncDUF", F0, FL));
  cout<<F0 + F0Sys<<"\t"<<FL - FLSys<<endl;
	WeightFuncUD.first.SetParameters(F0 + F0Sys, FL - FLSys);
	WeightFuncDU.first.SetParameters(F0 - F0Sys, FL + FLSys);
	
	TH1D * ttUD = myReweightor(ttMtop2D,WeightFuncUD,"WeightFuncUD_");
	cout<<"ratio: "<<ttMtop2D->Integral()/ttUD->Integral()<<endl;
	ttUD->Scale(ttMtop2D->Integral()/ttUD->Integral());
	ttUD->Add(ttMtop);
	TH1D * wUD = (TH1D*)ttUD->Clone("wUD");
	wUD->Scale(-1.);
	wUD->Add(dataMtop);
	
	TH1D * ttDU = myReweightor(ttMtop2D,WeightFuncDU,"WeightFuncDU_");
	cout<<"ratio: "<<ttMtop2D->Integral()/ttDU->Integral()<<endl;
	ttDU->Scale(ttMtop2D->Integral()/ttDU->Integral());
	ttDU->Add(ttMtop);
	TH1D * wDU = (TH1D*)ttDU->Clone("wDU");
	wDU->Scale(-1.);
	wDU->Add(dataMtop);
	
	TFile * out = new TFile("file.root","recreate");
	out->cd();
	WeightFuncUD.first.Write();
	WeightFuncDU.first.Write();
	ttUD->Write();
	ttDU->Write();	
	wUD->Write();
	wDU->Write();	
	out->Close();
	return 1;
}
Ejemplo n.º 16
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();
    }
  }
}
Ejemplo n.º 17
0
TH1D* GetRawCorrFunc1D_ratio(int itrg, int jass)
{
                    TH1D* hsignalphi = GetRawSignal1D(itrg,jass);
                    TH1D* hcorrphi = (TH1D*)hsignalphi->Clone(Form("corrphi_trg%d_ass%d",itrg,jass));
		    hcorrphi->SetYTitle("C(#Delta#phi)");  
		    TH1D* hbackphi = GetRawBackground1D(itrg,jass);
		    hcorrphi->Divide(hbackphi); 
                    float max = hcorrphi->GetBinContent(hcorrphi->GetMaximumBin());
//		    hcorrphi->SetAxisRange(ymin,max*1.3,"Y");
                    return hcorrphi;
}
Ejemplo n.º 18
0
void macro_exc_inc(){
  TFile *f1   = TFile::Open("../MD_DYJetstoLL_inclonlyisMu_0_doUnf_1_isSS_0_jetPt_20_Tightjet_0_JES_0_ZPTweightcorr_0_18_02.root");
  TFile *f2   = TFile::Open("../MD_DYJetstoLL_isMu_0_doUnf_1_isSS_0_jetPt_20_Tightjet_0_JES_0_ZPTweightcorr_0_18_02.root");

//  TH1D *data     =(TH1D*)(f1->Get("nup"));
//  TH1D *mc       =(TH1D*)(f2->Get("nup"));

  TH1D *data     =(TH1D*)(f1->Get("nup_mu_with_cuts"));
  TH1D *mc     =(TH1D*)(f1->Get("nup_mu_with_cuts"));
  Int_t DY;
  Int_t DY2;
  TTree *tree_DY = (TTree *)f1->Get("tree");
  tree_DY->SetBranchAddress("nevent",&DY);
  tree_DY->GetEntry(0);

  TTree *tree_DY2 = (TTree *)f2->Get("tree");
  tree_DY2->SetBranchAddress("nevent",&DY2);
  tree_DY2->GetEntry(0);

//    Double_t Mc_scale= 3531.5*19701./30396328.;
//    Double_t Mc_scale2= 3531.5*19701./;
//    data->Scale(Mc_scale);
//    mc->Scale(Mc_scale2);

  TH1D *Mont= (TH1D*)data->Clone("Mont");

  Mont->Divide(data,mc,1.0,1.0);

for(int i=1;i<=5;i++){
cout<<Mont->GetBinContent(i)<<",";
}

  TCanvas *c1 = new TCanvas("c1","", 700, 900);

          c1->cd(); 
	  colorIt(data,kBlack);  
          splithist(0.2);
          c1->cd(1);
          gPad->SetLogy(); 
	  mc->Draw("hhist");
	  data->SetMarkerStyle(10);
	  data->Draw("peXOCsames");

	  c1->cd(2);
          gPad->SetGridy();
	  colorIt(Mont,kBlack);
	  Mont->SetMinimum(0.5);
	  Mont->SetMaximum(1.5);
	  Mont->GetXaxis()->SetTitleOffset(0.8);
          Mont->SetYTitle("Data/MC");
	  Mont->Draw("peX0C");// rec/gen
          fixsplithist(data,Mont);

}
Ejemplo n.º 19
0
void photonSpectra()
{
  TH1::SetDefaultSumw2();

  const Double_t PTBINS[] = {40, 50, 60, 80, 120, 300};
  const Int_t nPTBINS = 5;

  const TString DATA_FILE = "gammaJets_pA_Data.root";
  const TString MC_FILE = "gammaJets_pA_MC_allQCDPhoton.root";
  TFile *dataFile = TFile::Open(DATA_FILE);
  TTree *dataTree = (TTree*)dataFile->Get("photonTree");
  TFile *mcFile = TFile::Open(MC_FILE);
  TTree *mcTree = (TTree*)mcFile->Get("photonTree");

  TH1D *photonSpectra = new TH1D("photonSpectra","photonSpectra", nPTBINS, PTBINS);
  TH1D *correctedPhotonSpectra = (TH1D*)photonSpectra->Clone("correctedPhotonSpectra");

  const TCut photonEtaCut = "abs(photonTree.eta) < 1.44";
  const TCut isoCut = "ecalRecHitSumEtConeDR04 < 4.2  &&  hcalTowerSumEtConeDR04 < 2.2  &&  trkSumPtHollowConeDR04 < 2 && hadronicOverEm<0.1";
  const TCut genCut = "genCalIsoDR04<5 && abs(genMomId)<=22";
  const TCut sbCut = "(cc4+cr4+ct4PtCut20>10) && (cc4+cr4+ct4PtCut20<20) && hadronicOverEm<0.1";
  const TCut candidateCut = "sigmaIetaIeta<0.01";
  const TCut decayCut = "(sigmaIetaIeta>0.011) && (sigmaIetaIeta<0.017)";

  TCut photonPtCut = "photonTree.corrPt>40 && photonTree.corrPt<300";

  dataTree->Project(photonSpectra->GetName(),"corrPt",isoCut && photonEtaCut && photonPtCut && candidateCut);

  for(int i = 0; i<nPTBINS; ++i)
  {
    photonPtCut = Form("photonTree.corrPt>%f && photonTree.corrPt<%f", PTBINS[i], PTBINS[i+1]  );

    TCut dataCandidateCut = isoCut && photonEtaCut && photonPtCut;
    TCut sidebandCut =  sbCut && photonEtaCut && photonPtCut;
    TCut mcSignalCut = dataCandidateCut && genCut;

    fitResult fitr = getPurity(dataTree, mcTree,
  			       dataCandidateCut, sidebandCut,
  			       mcSignalCut);
    Double_t purity = fitr.purity;
    correctedPhotonSpectra->SetBinContent(i+1,photonSpectra->GetBinContent(i+1)*purity);
  }

  // TCanvas *c1 = new TCanvas();
  // photonSpectra->Draw();
  // correctedPhotonSpectra->Draw("same");

  TFile *outFile = new TFile("photonSpectra.root", "RECREATE");
  outFile->cd();
  photonSpectra->Write();
  correctedPhotonSpectra->Write();
  outFile->Close();
}
Ejemplo n.º 20
0
void Observable::setLikelihoodFromHisto(std::string filename, std::string histoname)
    {
        this->filename = filename;
        this->histoname = histoname;
        TFile *lik = new TFile((filename + ".root").c_str(), "read");
        TH1D *htmp = (TH1D*) (lik->Get(histoname.c_str()));
        if (htmp == NULL)
            throw std::runtime_error("ERROR: nonexistent histogram called "
                    + histoname + " in "
                    + filename + ".root");
        inhisto = (TH1D *) htmp->Clone((filename + "/" + histoname).c_str());
        inhisto->SetDirectory(gROOT);
        setMin(inhisto->GetXaxis()->GetXmin());
        setMax(inhisto->GetXaxis()->GetXmax());
        lik->Close();
        delete lik;
    }
Ejemplo n.º 21
0
TH1D* GetJetCorrFunc1D_ZYA1(int itrg, int jass)
{
                    TH1D* hcorrphi = (TH1D*)GetRawCorrFunc1D_ratio(itrg,jass);
                    TH1D* hcorrphi_clone = (TH1D*)hcorrphi->Clone(Form("corrphi_clone_itrg%d_jass%d",itrg,jass));
                    hcorrphi->SetAxisRange(0.5,2.0,"X");
                    double histminY = hcorrphi->GetMinimum();
		    TF1* fitfunc = new TF1("fitfunc","[0]+[1]*x",0.8,1.2);		    
                    fitfunc->SetParameters(histminY,0);
                    fitfunc->FixParameter(1,0);
		    for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit("fitfunc","RNO");                     
		    float level = fitfunc->GetParameter(0);
		    for(int ibin=1;ibin<=hcorrphi_clone->GetNbinsX();ibin++) hcorrphi_clone->SetBinContent(ibin,hcorrphi_clone->GetBinContent(ibin)-level);
                    float max = hcorrphi_clone->GetBinContent(hcorrphi_clone->GetMaximumBin());
                    hcorrphi_clone->SetAxisRange(ymin,max*1.3,"Y");
		    hcorrphi_clone->SetAxisRange(-PI/2.,3.*PI/2.,"X");
                    delete fitfunc;
                    return hcorrphi_clone;
}
Ejemplo n.º 22
0
TH1D* GetJetCorrFunc1D_doublegaussian(int itrg, int jass)
{
                    TH1D* hcorrphi = (TH1D*)GetRawCorrFunc1D_ratio(itrg,jass);
		    TF1* fitfunc = new TF1("fitfunc",doubleGaussian,-PI/2.,3.*PI/2.,5);		    
                    fitfunc->SetParameters(hcorrphi->GetMinimum(),hcorrphi->GetMaximum()-hcorrphi->GetMinimum(),0.3,hcorrphi->GetMaximum(hcorrphi->GetMaximum())-hcorrphi->GetMinimum(),0.5);  
                    fitfunc->SetParLimits(0,0,100000);
                    fitfunc->SetParLimits(1,0,100000);
                    fitfunc->SetParLimits(2,0,100000);
                    fitfunc->SetParLimits(3,0,100000);
                    fitfunc->SetParLimits(4,0,100000);		    
		    for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit("fitfunc","RNO");                     
		    TH1D* hcorrphi_clone = (TH1D*)hcorrphi->Clone(Form("corrphi_clone_itrg%d_jass%d",itrg,jass));
		    float level = fitfunc->GetParameter(0);
		    for(int ibin=1;ibin<=hcorrphi_clone->GetNbinsX();ibin++) hcorrphi_clone->SetBinContent(ibin,hcorrphi_clone->GetBinContent(ibin)-level);
                    float max = hcorrphi_clone->GetBinContent(hcorrphi_clone->GetMaximumBin());
                    hcorrphi_clone->SetAxisRange(ymin,max*1.3,"Y");
                    delete fitfunc;
                    return hcorrphi_clone;
}
Ejemplo n.º 23
0
void fillPlot2012_gammaJets::SetPuWeights(bool isData,std::string puWeightFile) {
  
  if (puWeightFile == "") {
    std::cout << "you need a weights file to use this function" << std::endl;
    return;
  }
  
  if (!isData)
    std::cout << "PU REWEIGHTING:: Using file " << puWeightFile << std::endl;
  
  TFile *f_pu  = new TFile(puWeightFile.c_str(),"READ");
  
  TH1D *puweights = 0;
  TH1D *gen_pu = 0;

  gen_pu= (TH1D*) f_pu->Get("generated_pu");
  puweights= (TH1D*) f_pu->Get("weights");
  
  if (!puweights || !gen_pu)  {
    std::cout << "weights histograms  not found in file " << puWeightFile << std::endl;
    return;
  }
  
  TH1D* weightedPU= (TH1D*)gen_pu->Clone("weightedPU");
  weightedPU->Multiply(puweights);

  //Rescaling weights in order to preserve same integral of events
  TH1D* weights= (TH1D*)puweights->Clone("rescaledWeights");
  weights->Scale( gen_pu->Integral(1,MAX_PU_REWEIGHT) / weightedPU->Integral(1,MAX_PU_REWEIGHT) );
		  
  float sumPuWeights=0.;

  for (int i = 0; i<MAX_PU_REWEIGHT; i++) {
    float weight=1.;
    if( !isData ) weight=weights->GetBinContent(i+1);

    sumPuWeights+=weight;
    puweights_.push_back(weight);
  }
}
Ejemplo n.º 24
0
TH1D* Plot1D (std::string var,std::vector<TFile*>& tfiles,std::vector<double>& weights) {

    double weightTot = 0.0;

    for ( int i = 0; i<weights.size(); i++) {
        weightTot+=weights[i];
    }

    std::string name = var;
    name+="NEW";
    TH1D* hVar = (TH1D*)tfiles[0]->Get(var.c_str());
    TH1D* HVar = (TH1D*)hVar->Clone(name.c_str());
    HVar->Sumw2();

    for (int i=1; i<tfiles.size(); i++) {
        TH1D* htempVar = (TH1D*)tfiles[i]->Get(var.c_str());
        HVar->Add(htempVar,weights[i]/weightTot);
    }

    return HVar;

}
Ejemplo n.º 25
0
void getMeanPtBins( Double_t * binArr, TF1* func) {
  Double_t atlas_Bin[nAtlasBin+1] = {8, 9.5, 11.5, 14, 20, 30};
  
  TH1D* firhist = (TH1D*)func->GetHistogram();
  for ( int i=1 ; i<= nAtlasBin ; i++) {
    float lowPtCut = atlas_Bin[i-1];
    float highPtCut = atlas_Bin[i];
    
    TH1D* tempHist = (TH1D*)firhist->Clone("tempHist");
    for ( int xbin = 1 ;xbin<=tempHist->GetNbinsX() ; xbin++) {
      if ( (tempHist->GetBinCenter(xbin) > highPtCut) || (tempHist->GetBinCenter(xbin) < lowPtCut) \
	   )
      tempHist->SetBinContent(xbin,0);
    }
    float meanPt = tempHist->GetMean();
    cout << " meanPt = " << meanPt << endl;
    binArr[i-1] = meanPt;
    delete tempHist;
    
  }
  
}
Ejemplo n.º 26
0
void ChangeDataTreeName(std::string suffix){

  // Define names
  TString filename = "", treename = "", histname = "";
  filename.Form("central_%s.root",suffix.c_str());
  treename.Form("id_%s",suffix.c_str());
  histname.Form("sumOfMcWeights_%s",suffix.c_str());

  TString _pathFile(string(getenv("WORKAREA")) + "/histoAna" + "/SusyAna/histos_110312_13fb_n0111_DD_MMtrial9_SYS_HFT/HFTOutputs_merge/");
  filename = _pathFile+filename;
  cout << "open " << filename << endl;

  // Open file
  TFile* file         = new TFile(filename,"UPDATE");
  if(file->IsOpen()==kFALSE){
    cerr << "Cannot open file " << filename << endl;
    abort();
  }
  file->ls();
  TTree* treeOriginal = (TTree*) file->Get(treename);
  TH1D*  histOriginal = (TH1D*)  file->Get(histname);
  TTree* treeNew      = (TTree*) treeOriginal->Clone();
  TH1D*  histNew      = (TH1D*)  histOriginal->Clone();

  // Set-Write-Delete
  histNew->SetName ("sumOfMcWeights_Data" );
  histNew->SetTitle("sumOfMcWeights_Data" );
  histNew->Write   ("",TObject::kOverwrite);
  treeNew->SetName ("id_Data"             );
  treeNew->SetTitle("id_Data"             );
  treeNew->Write   ("",TObject::kOverwrite);
  file->Delete     (histname+";1"         );
  file->Delete     (treename+";1"         );

  // Close file
  file->Close();
}
Ejemplo n.º 27
0
void trksplit()
{
  TFile* f = new TFile("../cfg/dihadroncorrelation_wsplit_real_cent010_mc.root");
  TFile* f1 = new TFile("../cfg/dihadroncorrelation_wosplit_cent010_mc.root");
 
  TH1D* hpt = (TH1D*)f->Get("corr_ana_HI/ptall_trg");
  TH1D* hpt1 = (TH1D*)f1->Get("corr_ana_HI/ptall_trg");
  hpt->SetMarkerStyle(20);
  hpt1->SetMarkerStyle(20);
  hpt->SetMarkerColor(4);
  hpt->Rebin(4);
  hpt1->Rebin(4);

  TCanvas* c = new TCanvas("c","c",500,450);
  hpt->SetAxisRange(0,5.0,"X");
  hpt->Draw("PE");
  hpt1->Draw("PESAME");

  TH1D* hratio = (TH1D*)hpt->Clone("hratio");
  hratio->Divide(hpt1);

  TCanvas* c1 = new TCanvas("c1","c1",500,450);
  hratio->Draw("PE");
}
void getMeanPtBins( Double_t * binArr, TF1* func) {
  Double_t lhcb_Bin[nLHCbBin+1] = {0,1,2,3,4,5,6,7,14};
  
  TH1D* firhist = (TH1D*)func->GetHistogram();
  for ( int i=1 ; i<= nLHCbBin ; i++) {
    float lowPtCut = lhcb_Bin[i-1];
    float highPtCut = lhcb_Bin[i];

    TH1D* tempHist = (TH1D*)firhist->Clone("tempHist");
    for ( int xbin = 1 ;xbin<=tempHist->GetNbinsX() ; xbin++) {
      if ( (tempHist->GetBinCenter(xbin) > highPtCut) || (tempHist->GetBinCenter(xbin) < lowPtCut) )
	tempHist->SetBinContent(xbin,0);
    }
    float meanPt = tempHist->GetMean();
    if ( meanPt <0.1 )   // fit is not applied
      meanPt = (lowPtCut+highPtCut)/2.;

    cout << " meanPt = " << meanPt << endl;
    binArr[i-1] = meanPt;
    delete tempHist;

  }

}
Ejemplo n.º 29
0
TH1D *getpuweights(TFile *file, TH1D *target) {
  
  TDirectory *dirmcpv = (TDirectory*)file->FindObjectAny("AnaFwkMod");
  TH1D *hnpu = (TH1D*)dirmcpv->Get("hNPU");
  TH1D *hpumc = (TH1D*)hnpu->Clone();
  
  hpumc->Sumw2();
  hpumc->Scale(1.0/hpumc->Integral(0,hpumc->GetNbinsX()+1));
  
  
  TH1D *htargettmp = new TH1D("htargettmp","", hpumc->GetNbinsX(), hpumc->GetXaxis()->GetXmin(), hpumc->GetXaxis()->GetXmax());
  htargettmp->Sumw2();
  for (int ibin = 0; ibin<=(htargettmp->GetNbinsX()+1); ++ibin) {
    htargettmp->Fill(htargettmp->GetBinCenter(ibin),target->GetBinContent(target->FindFixBin(htargettmp->GetBinCenter(ibin))));
  }
  htargettmp->Scale(1.0/htargettmp->Integral(0,htargettmp->GetNbinsX()+1));
  
  TH1D *puweights = new TH1D((*htargettmp)/(*hpumc));
    
  delete htargettmp;
  
  return puweights;
    
}
Ejemplo n.º 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;
}