vector<double> getValsFromLikelihood(TGraph *graph){
 
  TGraph *grRot = new TGraph();
  TGraph *grRotUpp = new TGraph();
  TGraph *grRotLow = new TGraph();
  int pLow=0,pHigh=0;
  pair<double,double> graphMin = getGraphMin(graph);
  for (int p=0; p<graph->GetN(); p++){
    double x,y;
    graph->GetPoint(p,x,y);
    grRot->SetPoint(p,y,x);
    if (x<=graphMin.first) {
      grRotLow->SetPoint(pLow,y,x);
      pLow++;
    }
    if (x>=graphMin.first) {
      grRotUpp->SetPoint(pHigh,y,x);
      pHigh++;
    }
  }
  // return best fit and +/- 1/2 sigma errors
  vector<double> result;
  result.push_back(grRot->Eval(0.));
  result.push_back(grRotLow->Eval(1.0));
  result.push_back(grRotUpp->Eval(1.0));
  result.push_back(grRotLow->Eval(4.0));
  result.push_back(grRotUpp->Eval(4.0));
  return result; 
}
예제 #2
0
void points(TString filename) {

	
	TString cmssw;
	// 167
	
	cmssw = "$1.6.7$";
	
	TFile *f = TFile::Open(filename);

	std::vector< TString > taggers;
	taggers.push_back( "gTC2_udsg" );
	taggers.push_back( "gTC3_udsg" );
	taggers.push_back( "gTP_udsg" );
	taggers.push_back( "gJBP_udsg" );
 	taggers.push_back( "gSSV_udsg" );
 	taggers.push_back( "gCSV_udsg" );

	std::vector< TString > discriminators;
	discriminators.push_back( "discTC2_udsg" );
	discriminators.push_back( "discTC3_udsg" );
	discriminators.push_back( "discTP_udsg" );
	discriminators.push_back( "discJBP_udsg" );
 	discriminators.push_back( "discSSV_udsg" );
 	discriminators.push_back( "discCSV_udsg" );

	//TCanvas *cv_TC = new TCanvas("cv_TC","cv_TC",700,700);
	//TCanvas *cv_TP = new TCanvas("cv_TP","cv_TP",700,700);

	std::cout << "Tagger & Point & Discriminator & light mistag & b-efficiency \\\\ \\hline" << std::endl;
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {

		TString tag = taggers[itagger];
		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("Histograms/MCtruth/"+tag);

		//if (taggers == "gTC2_udsg" || taggers =
		
		TGraph *dgraph = (TGraph*) gDirectory->Get("Histograms/MCtruth/"+discriminators[itagger]);
		dgraph->Sort();

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		
		//cv[itagger] = new TCanvas("cv","cv",600,600);
		//g->Draw("ACP");
		TString se = " & ";
		
		
		std::cout << tag << se << "Loose" << se << std::setprecision(3) << dgraph->Eval(0.1) << se << "0.1" << se << std::setprecision(2) << g->Eval(0.1) << "\\\\" << std::endl;
		std::cout << tag << se << "Medium" << se << std::setprecision(3) << dgraph->Eval(0.01) << se << "0.01" << se << std::setprecision(2) << g->Eval(0.01) << "\\\\" << std::endl;
		std::cout << tag << se << "Tight" << se << std::setprecision(3) << dgraph->Eval(0.001) << se << "0.001" << se << std::setprecision(2) << g->Eval(0.001) << "\\\\ \\hline" << std::endl;
		
	}

	
}
예제 #3
0
  /** 
   * Create ratios to other data 
   * 
   * @param ib      Bin number  
   * @param res     Result
   * @param alice   ALICE result if any
   * @param cms     CMS result if any
   * @param all     Stack to add ratio to 
   */
  void Ratio2Stack(Int_t ib, TH1* res, TGraph* alice, TGraph* cms, THStack* all)
  {
    if (!all || !res || !(alice || cms)) return;

    Int_t        off  = 5*ib;
    TGraph*      gs[] = { (alice ? alice : cms), (alice ? cms : 0), 0 };
    TGraph**     pg   = gs;
    while (*pg) { 
      TGraph*     g = *pg;
      const char* n = (g == alice ? "ALICE" : "CMS");

      TH1*    r = static_cast<TH1*>(res->Clone(Form("ratio%s", n)));
      TString tit(r->GetTitle());
      tit.ReplaceAll("Corrected", Form("Ratio to %s", n));
      r->SetTitle(tit);
      r->SetMarkerColor(g->GetMarkerColor());
      r->SetLineColor(g->GetLineColor());

      TObject* tst = r->FindObject("legend");
      if (tst) r->GetListOfFunctions()->Remove(tst);

      for (Int_t i = 1; i <= r->GetNbinsX(); i++) {
	Double_t c = r->GetBinContent(i);
	Double_t e = r->GetBinError(i);
	Double_t o = g->Eval(r->GetBinCenter(i));
	if (o < 1e-12) { 
	  r->SetBinContent(i, 0);
	  r->SetBinError(i, 0);
	  continue;
	}
	r->SetBinContent(i, (c - o) / o + off);
	r->SetBinError(i, e / o);
      }
      all->Add(r);
      pg++;
    }
    TLegend* leg = StackLegend(all);
    if (!leg) return;
      
    TString   txt      = res->GetTitle();
    txt.ReplaceAll("Corrected P(#it{N}_{ch}) in ", "");
    if      (ib == 0) txt.Append(" "); // (#times1)");
    // else if (ib == 1) txt.Append(" (#times10)");
    else              txt.Append(Form(" (+%d)", off));

    TObject* dummy = 0;
    TLegendEntry* e = leg->AddEntry(dummy, txt, "p");
    e->SetMarkerStyle(res->GetMarkerStyle());
    e->SetMarkerSize(res->GetMarkerSize());
    e->SetMarkerColor(kBlack);
    e->SetFillColor(0);
    e->SetFillStyle(0);
    e->SetLineColor(kBlack);
  }
예제 #4
0
void disceff(TString filename) {
	gROOT->SetStyle("Plain");
	
	TString cmssw;
	// 167
	
	cmssw = "$3.1.0_pre9$";
		
	TFile *f = TFile::Open(filename);

	std::vector< TString > taggers;
	taggers.push_back( "TC2" );
	taggers.push_back( "TC3" );
	taggers.push_back( "TP" );
	taggers.push_back( "BTP" );
	taggers.push_back( "SSV" );
	taggers.push_back( "CSV" );
	taggers.push_back( "MSV" );
	taggers.push_back( "SMT" );
	taggers.push_back( "SETbyIP3d" );
	taggers.push_back( "SETbyPt" );
	taggers.push_back( "SMTbyIP3d" );
	taggers.push_back( "SMTbyPt" );

	std::vector< TString > discriminators;
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
		discriminators.push_back( "disc"+taggers[itagger]+"_udsg" );
	}
//	discriminators.push_back( "discTC3_udsg" );
//	discriminators.push_back( "discTP_udsg" );

	const int dim=taggers.size();
        TCanvas *cv[dim];
	TMultiGraph* mg[dim];
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
		TString tag = "g"+taggers[itagger]+"_udsg";
		TString tagb = "g"+taggers[itagger]+"_b";
		TString tagc = "g"+taggers[itagger]+"_c";
		cv[itagger] = new TCanvas("cv_"+taggers[itagger],"cv_"+taggers[itagger],700,700);
		TLegend *legend0 = new TLegend(0.68,0.70,0.88,0.90);

		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag);
		TGraphErrors *bgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagb);
		TGraphErrors *cgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagc);

		TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]);
		TGraph *bvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),bgraph->GetY());
		TGraph *cvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),cgraph->GetY());
		TGraph *lvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),agraph->GetY());
		TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX());
		dgraph->Sort();
//		udsgvsdgraph->Sort();
//		udsgvsdgraph->SetLineColor(1);
//              legend0 -> AddEntry(udsgvsdgraph,"control","l");
		lvsdgraph->Sort();
		lvsdgraph->SetLineColor(2);
                legend0 -> AddEntry(lvsdgraph,tag,"l");
		cvsdgraph->Sort();
		cvsdgraph->SetLineColor(3);
                legend0 -> AddEntry(cvsdgraph,tagc,"l");
		bvsdgraph->Sort();
		bvsdgraph->SetLineColor(4);
                legend0 -> AddEntry(bvsdgraph,tagb,"l");
		mg[itagger]= new TMultiGraph();
//		mg[itagger]->Add(udsgvsdgraph);
		mg[itagger]->Add(lvsdgraph);
		mg[itagger]->Add(cvsdgraph);
		mg[itagger]->Add(bvsdgraph);
//		mg[itagger]->Add(dgraph);

		cv[itagger]->cd(1);
		mg[itagger]->Draw("ALP");
		mg[itagger]->GetYaxis()->SetTitle("eff");
		mg[itagger]->GetXaxis()->SetTitle("discriminant");
		legend0 -> Draw();
		cv[itagger]->Update();
	        cv[itagger]->cd(0);
		cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".eps");
		cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".ps");

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		g->SetLineColor(itagger+1);

		std::cout << " Tagger: " << tag << std::endl;
		std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl;
		std::cout << " Medium(1%):  " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl;
		std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl;

	}//end for
 
	
}
예제 #5
0
void DMplot()
{

    TCanvas *canv = new TCanvas("canv", "limits canvas", 800., 680.);
	gStyle->SetCanvasDefH(600); //Height of canvas
	gStyle->SetCanvasDefW(640); //Width of canvas
	gStyle->SetCanvasDefX(0);   //POsition on screen
	gStyle->SetCanvasDefY(0);

	gStyle->SetPadLeftMargin(0.14);//0.16);
	gStyle->SetPadRightMargin(0.165);//0.02);
	gStyle->SetPadTopMargin(0.085);//0.02);
	gStyle->SetPadBottomMargin(0.12);//0.02);

	  // For g axis titles:
	gStyle->SetTitleColor(1, "XYZ");
	gStyle->SetTitleFont(42, "XYZ");
	gStyle->SetTitleSize(0.045, "Z");
	gStyle->SetTitleSize(0.055, "XY");
	gStyle->SetTitleXOffset(1.0);//0.9);
	gStyle->SetTitleYOffset(1.15); // => 1.15 if exponents

	// For g axis labels:
	gStyle->SetLabelColor(1, "XYZ");
	gStyle->SetLabelFont(42, "XYZ");
	gStyle->SetLabelOffset(0.007, "XYZ");
	gStyle->SetLabelSize(0.04, "XYZ");

	// Legends
	gStyle->SetLegendBorderSize(0);
	gStyle->SetLegendFillColor(kWhite);
	gStyle->SetLegendFont(42);
    TPad* t1d = new TPad();
    t1d = new TPad("t1d","t1d", 0.0, 0.0, 1.0, 1.0);
    t1d->Draw();
    t1d->SetTicky();
    t1d->SetTickx();
    t1d->SetRightMargin(0.03);
    t1d->cd();

    //t1d->SetGridx(1);
    //t1d->SetGridy(1);
    t1d->SetLogy();
    t1d->SetLogx();

    //double const fn = 0.629;//0.326;
    TGraph *h_scalar_min = MakeGraph(0,0.260);
    TGraph *h_scalar_lat = MakeGraph(0,0.326);
    TGraph *h_scalar_max = MakeGraph(0,0.629);
    TGraph *h_fermion_min = MakeGraph(1,0.260);
    TGraph *h_fermion_lat = MakeGraph(1,0.326);
    TGraph *h_fermion_max = MakeGraph(1,0.629);

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

    // Get LUX bound 
    //TGraph *z1 = new TGraph("LUX_90CL.dat","%lg %lg");
    //
    TFile *fi_LUX2015 = TFile::Open("LUX_latest_2015.root");
    TGraph *z12015 =(TGraph*) fi_LUX2015->Get("LUX_2015");
    //TFile *fi_LUX2016 = TFile::Open("LUX_latest_2016.root");
    //TGraph *z12016 =(TGraph*) fi_LUX2016->Get("LUX_2016");
    TFile *fi_LUX2016 = TFile::Open("LUX_2013_2014_2015_combined.root");
    TGraph *z12016 =(TGraph*) fi_LUX2016->Get("LUX_2013_2014_2015_combined");

    z12015->SetLineWidth(3);
    z12015->SetLineColor(kGreen+2);
//    z12015->SetLineStyle(2);
    z12016->SetLineWidth(3);
    //z12016->SetLineStyle(2);
    z12016->SetLineColor(kGreen+2);

//    TLegend *leg2 = new TLegend(0.65, 0.15, 0.93, 0.42);
    TLegend *leg2 = new TLegend(0.70, 0.15, 0.97, 0.42);
    leg2->SetFillColor(0);
    leg2->SetBorderSize(0);
    //leg2->AddEntry(z1,"LUX(90\%CL)","L");
//////////////////////////////////////////////////
//  CDMS/ CRESST TOO
    TFile *CDMS_2016f = TFile::Open("CDMS_2016.root");
    TGraph *SCDMS = (TGraph*)CDMS_2016f->Get("CDMS_2016");

    TFile *CRESST2_2016f = TFile::Open("CRESST_2.root");
    TGraph *CRESST2 = (TGraph*)CRESST2_2016f->Get("CRESST_2_2016");

    TFile *PANDAX_2016f = TFile::Open("PANDAX.root");
    TGraph *PANDAX = (TGraph*)PANDAX_2016f->Get("PANDAX");

    SCDMS->SetLineColor(kAzure+7); SCDMS->SetLineStyle(9); SCDMS->SetLineWidth(3);
    CRESST2->SetLineColor(kMagenta+2); CRESST2->SetLineStyle(7); CRESST2->SetLineWidth(3);
    PANDAX->SetLineColor(kMagenta+2); PANDAX->SetLineStyle(4); PANDAX->SetLineWidth(3);
	
//
//

    h_scalar_min->SetTitle("");
    h_scalar_min->SetMinimum(2.0e-47);
    h_scalar_min->SetMaximum(1.0e-39);
    //h_scalar_min->SetMinimum(0.6e-46);
    //h_scalar_min->SetMaximum(1.0e-42);
    h_scalar_min->SetLineColor(4);
    h_scalar_min->SetLineStyle(2);
    h_scalar_min->SetLineWidth(3);
    h_scalar_min->GetXaxis()->SetTitleOffset(1.03);
    h_scalar_min->GetXaxis()->SetTitle("DM mass [GeV]");
    h_scalar_min->GetYaxis()->SetTitle("DM-nucleon cross section [cm^{2}]");
    h_scalar_lat->SetLineColor(4);
    h_scalar_lat->SetLineStyle(1);
    h_scalar_lat->SetLineWidth(3);
    h_scalar_max->SetLineColor(4);
    h_scalar_max->SetLineStyle(2);
    h_scalar_max->SetLineWidth(3);


    h_fermion_min->SetLineColor(kRed);
    h_fermion_min->SetLineStyle(2);
    h_fermion_min->SetLineWidth(3);
    h_fermion_lat->SetLineColor(kRed);
    h_fermion_lat->SetLineStyle(1);
    h_fermion_lat->SetLineWidth(3);
    h_fermion_max->SetLineColor(kRed);
    h_fermion_max->SetLineStyle(2);
    h_fermion_max->SetLineWidth(3);


    //h_scalar_lat->SetFillStyle(3005);
    //h_scalar_lat->SetLineWidth(-402);

    h_scalar_min->Draw("AL");
    h_scalar_lat->Draw("L");
    h_scalar_max->Draw("L");

    h_fermion_min->Draw("L");
    h_fermion_lat->Draw("L");
    h_fermion_max->Draw("L");
    z12016->Draw("L");
    //z12015->Draw("L");
    //CRESST2->Draw("C");
    SCDMS->Draw("C");
    PANDAX->Draw("C");

    //leg2->Draw();
    TLatex *lat = new TLatex(); lat->SetTextSize(0.025);
    lat->SetTextFont(42);
    lat->SetTextColor(kGreen+2);
    lat->SetTextAngle(15);
    //lat->DrawLatex(130,z1->Eval(130)*1.5,"LUX #it{Phys. Rev. Lett.} #bf{116} (2016)");


    //lat->DrawLatex(130,z12015->Eval(130)*1.5,"LUX (2015)");
    lat->DrawLatex(130,z12016->Eval(130)*0.5,"LUX (2013+2014-16)");
    
    lat->SetTextColor(SCDMS->GetLineColor());
    lat->SetTextAngle(344);
    //lat->SetFillColor(kWhite);
    lat->DrawLatex(5,SCDMS->Eval(5)*1.5,"CDMSlite (2015)");
    
    lat->SetTextColor(kBlue);
    lat->SetTextAngle(330);
    lat->DrawLatex(13,h_scalar_lat->Eval(13)*1.5,"Scalar DM");

    lat->SetTextColor(kRed);
    lat->SetTextAngle(4);
    lat->DrawLatex(5,h_fermion_lat->Eval(5)*1.5,"Fermion DM");


    lat->SetTextColor(kMagenta+2);
    lat->SetTextAngle(15);
    lat->DrawLatex(130,PANDAX->Eval(130)*1.25,"PandaX-II (2016)");

	TLatex * tex = new TLatex();
	tex->SetNDC();
	tex->SetTextFont(42);
	tex->SetLineWidth(2);
	tex->SetTextSize(0.04);
	tex->SetTextAlign(31);
	tex->DrawLatex(0.93,0.78,"4.9 fb^{-1} (7 TeV) + 19.7 fb^{-1} (8 TeV)");
	tex->DrawLatex(0.93,0.74,"+ 2.3 fb^{-1} (13 TeV)");
	//tex->SetTextAlign(11);
  	tex->SetTextFont(42);
	tex->SetTextSize(0.06);
        TLegend *legBOX; 
	if (isPrelim)	{
   		legBOX = new TLegend(0.16,0.83,0.38,0.89);
		legBOX->SetFillColor(kWhite);
		legBOX->SetLineWidth(0);
		legBOX->Draw();
		tex->DrawLatex(0.17, 0.84, "#bf{CMS} #it{Preliminary}");
	} else {
   		legBOX = new TLegend(0.16,0.83,0.28,0.89);
		legBOX->SetFillColor(kWhite);
		legBOX->SetLineWidth(0);
		//legBOX->Draw();
		tex->DrawLatex(0.93, 0.84, "#bf{CMS}");
	}
  tex->SetTextSize(0.045);
  tex->DrawLatex(0.93,0.68,Form("B(H #rightarrow inv.) < %.2f",BRinv));
  tex->DrawLatex(0.93,0.5,"90% CL limits");
  canv->SetTicky(1);
  canv->SetTickx(1);
  canv->SaveAs("limitsDM.pdf"); 

}
예제 #6
0
void mass4Chan(){
//=========Macro generated from canvas: ccc/
//=========  (Thu Mar  7 22:11:11 2013) by ROOT version5.34/03
   TCanvas *ccc = new TCanvas("ccc", "",0,0,600,600);
   gStyle->SetOptFit(1);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   ccc->Range(86.5625,-1.875,92.8125,10.625);
   ccc->SetFillColor(0);
   ccc->SetBorderMode(0);
   ccc->SetBorderSize(2);
   ccc->SetLeftMargin(0.15);
   ccc->SetRightMargin(0.05);
   ccc->SetTopMargin(0.05);
   ccc->SetBottomMargin(0.15);
   ccc->SetFrameFillStyle(0);
   ccc->SetFrameBorderMode(0);
   ccc->SetFrameFillStyle(0);
   ccc->SetFrameBorderMode(0);
   
  

   
   TH2F *hframe = new TH2F("hframe","",100,85,96,100,0,10);
   hframe->SetLineStyle(0);
   hframe->SetMarkerStyle(20);
   hframe->GetXaxis()->SetTitle(" m_{Z} (GeV)");
   hframe->GetXaxis()->SetNdivisions(510);
   hframe->GetXaxis()->SetLabelFont(42);
   hframe->GetXaxis()->SetLabelOffset(0.01);
   hframe->GetXaxis()->SetLabelSize(0.05);
   hframe->GetXaxis()->SetTitleSize(0.05);
   hframe->GetXaxis()->SetTitleOffset(1.15);
   hframe->GetXaxis()->SetTitleFont(42);
   hframe->GetYaxis()->SetTitle(" -2#Delta ln L");
   hframe->GetYaxis()->SetLabelFont(42);
   hframe->GetYaxis()->SetLabelOffset(0.01);
   hframe->GetYaxis()->SetLabelSize(0.05);
   hframe->GetYaxis()->SetTitleSize(0.05);
   hframe->GetYaxis()->SetTitleOffset(1.4);
   hframe->GetYaxis()->SetTitleFont(42);
   hframe->GetZaxis()->SetLabelFont(42);
   hframe->GetZaxis()->SetLabelOffset(0.007);
   hframe->GetZaxis()->SetLabelSize(0.045);
   hframe->GetZaxis()->SetTitleSize(0.05);
   hframe->GetZaxis()->SetTitleFont(42);
   hframe->Draw("");
   
   //4e
   TGraph *graph = new TGraph(211);
   graph->SetName("Graph");
   graph->SetTitle("Graph");
   graph->SetLineColor(kGreen+1);
   graph->SetLineWidth(3);
   graph->SetMarkerStyle(20);
   graph->SetPoint(0,88.01999664,7.234320164);
   graph->SetPoint(1,88.05999756,7.121326923);
   graph->SetPoint(2,88.09999847,7.008939743);
   graph->SetPoint(3,88.13999939,6.897168636);
   graph->SetPoint(4,88.18000031,6.786022186);
   graph->SetPoint(5,88.22000122,6.67550993);
   graph->SetPoint(6,88.26000214,6.565642357);
   graph->SetPoint(7,88.30000305,6.456428051);
   graph->SetPoint(8,88.33999634,6.347877979);
   graph->SetPoint(9,88.37999725,6.240002632);
   graph->SetPoint(10,88.41999817,6.1328125);
   graph->SetPoint(11,88.45999908,6.026317596);
   graph->SetPoint(12,88.5,5.920529366);
   graph->SetPoint(13,88.54000092,5.815458775);
   graph->SetPoint(14,88.58000183,5.711116314);
   graph->SetPoint(15,88.62000275,5.607512951);
   graph->SetPoint(16,88.66000366,5.504659653);
   graph->SetPoint(17,88.69999695,5.402567387);
   graph->SetPoint(18,88.73999786,5.301246643);
   graph->SetPoint(19,88.77999878,5.200707436);
   graph->SetPoint(20,88.81999969,5.100960732);
   graph->SetPoint(21,88.81999969,5.100960732);
   graph->SetPoint(22,88.86000061,5.002016068);
   graph->SetPoint(23,88.90000153,4.903883457);
   graph->SetPoint(24,88.94000244,4.806572437);
   graph->SetPoint(25,88.98000336,4.710093021);
   graph->SetPoint(26,89.01999664,4.614454269);
   graph->SetPoint(27,89.05999756,4.519664764);
   graph->SetPoint(28,89.09999847,4.425733089);
   graph->SetPoint(29,89.13999939,4.332668304);
   graph->SetPoint(30,89.18000031,4.240478516);
   graph->SetPoint(31,89.22000122,4.149171829);
   graph->SetPoint(32,89.26000214,4.058755875);
   graph->SetPoint(33,89.30000305,3.969237804);
   graph->SetPoint(34,89.33999634,3.880625486);
   graph->SetPoint(35,89.37999725,3.792925596);
   graph->SetPoint(36,89.41999817,3.706145048);
   graph->SetPoint(37,89.45999908,3.620290518);
   graph->SetPoint(38,89.5,3.535368204);
   graph->SetPoint(39,89.54000092,3.451384068);
   graph->SetPoint(40,89.58000183,3.368344069);
   graph->SetPoint(41,89.62000275,3.286253691);
   graph->SetPoint(42,89.62000275,3.286253691);
   graph->SetPoint(43,89.66000366,3.205118656);
   graph->SetPoint(44,89.69999695,3.124943733);
   graph->SetPoint(45,89.73999786,3.045734167);
   graph->SetPoint(46,89.77999878,2.967494488);
   graph->SetPoint(47,89.81999969,2.890229225);
   graph->SetPoint(48,89.86000061,2.813942432);
   graph->SetPoint(49,89.90000153,2.738638639);
   graph->SetPoint(50,89.94000244,2.664321423);
   graph->SetPoint(51,89.98000336,2.590994596);
   graph->SetPoint(52,90.01999664,2.518661499);
   graph->SetPoint(53,90.05999756,2.447325468);
   graph->SetPoint(54,90.09999847,2.376989603);
   graph->SetPoint(55,90.13999939,2.307657003);
   graph->SetPoint(56,90.18000031,2.23933053);
   graph->SetPoint(57,90.22000122,2.172012329);
   graph->SetPoint(58,90.26000214,2.105705023);
   graph->SetPoint(59,90.30000305,2.040410995);
   graph->SetPoint(60,90.33999634,1.976132512);
   graph->SetPoint(61,90.37999725,1.912871242);
   graph->SetPoint(62,90.41999817,1.85062921);
   graph->SetPoint(63,90.41999817,1.85062921);
   graph->SetPoint(64,90.45999908,1.789408088);
   graph->SetPoint(65,90.5,1.729209423);
   graph->SetPoint(66,90.54000092,1.670034766);
   graph->SetPoint(67,90.58000183,1.611885428);
   graph->SetPoint(68,90.62000275,1.554762602);
   graph->SetPoint(69,90.66000366,1.498667479);
   graph->SetPoint(70,90.69999695,1.443601012);
   graph->SetPoint(71,90.73999786,1.389564157);
   graph->SetPoint(72,90.77999878,1.336557865);
   graph->SetPoint(73,90.81999969,1.284582734);
   graph->SetPoint(74,90.86000061,1.233639359);
   graph->SetPoint(75,90.90000153,1.183728576);
   graph->SetPoint(76,90.94000244,1.134850621);
   graph->SetPoint(77,90.98000336,1.087006092);
   graph->SetPoint(78,91.01999664,1.040195346);
   graph->SetPoint(79,91.05999756,0.9944185615);
   graph->SetPoint(80,91.09999847,0.9496760368);
   graph->SetPoint(81,91.13999939,0.9059679508);
   graph->SetPoint(82,91.18000031,0.8632944226);
   graph->SetPoint(83,91.22000122,0.8216554523);
   graph->SetPoint(84,91.22000122,0.8216554523);
   graph->SetPoint(85,91.26000214,0.7810510397);
   graph->SetPoint(86,91.30000305,0.7414811254);
   graph->SetPoint(87,91.33999634,0.70294559);
   graph->SetPoint(88,91.37999725,0.6654443145);
   graph->SetPoint(89,91.41999817,0.6289771199);
   graph->SetPoint(90,91.45999908,0.5935436487);
   graph->SetPoint(91,91.5,0.5591436625);
   graph->SetPoint(92,91.54000092,0.5257768631);
   graph->SetPoint(93,91.58000183,0.4934427738);
   graph->SetPoint(94,91.62000275,0.462141037);
   graph->SetPoint(95,91.66000366,0.431871146);
   graph->SetPoint(96,91.69999695,0.4026326835);
   graph->SetPoint(97,91.73999786,0.3744250238);
   graph->SetPoint(98,91.77999878,0.3472476304);
   graph->SetPoint(99,91.81999969,0.3210999072);
   graph->SetPoint(100,91.86000061,0.2959812582);
   graph->SetPoint(101,91.90000153,0.2718909979);
   graph->SetPoint(102,91.94000244,0.2488284409);
   graph->SetPoint(103,91.98000336,0.2267929316);
   graph->SetPoint(104,92.01999664,0.2057837248);
   graph->SetPoint(105,92.01999664,0.2057837248);
   graph->SetPoint(106,92.05999756,0.1858001053);
   graph->SetPoint(107,92.09999847,0.1668412983);
   graph->SetPoint(108,92.13999939,0.1489065737);
   graph->SetPoint(109,92.18000031,0.1319951713);
   graph->SetPoint(110,92.22000122,0.1161063388);
   graph->SetPoint(111,92.26000214,0.1012392938);
   graph->SetPoint(112,92.30000305,0.08739329875);
   graph->SetPoint(113,92.33999634,0.07456759363);
   graph->SetPoint(114,92.37999725,0.06276145577);
   graph->SetPoint(115,92.41999817,0.05197418481);
   graph->SetPoint(116,92.45999908,0.04220509902);
   graph->SetPoint(117,92.5,0.03345353901);
   graph->SetPoint(118,92.54000092,0.02571888082);
   graph->SetPoint(119,92.58000183,0.01900054142);
   graph->SetPoint(120,92.62000275,0.01329800207);
   graph->SetPoint(121,92.66000366,0.008610763587);
   graph->SetPoint(122,92.69999695,0.004938419908);
   graph->SetPoint(123,92.73999786,0.002280603396);
   graph->SetPoint(124,92.77999878,0.0006370125338);
   graph->SetPoint(125,92.81999969,7.419047051e-06);
   //graph->SetPoint(126,92.81999969,7.419047961e-06);
   graph->SetPoint(127,92.82485199,0);
   graph->SetPoint(128,92.82485199,0);
   graph->SetPoint(129,92.82485199,0);
   graph->SetPoint(130,92.82485199,0);
   graph->SetPoint(131,92.82485199,0);
   graph->SetPoint(132,92.82485199,0);
   graph->SetPoint(133,92.82485199,0);
   graph->SetPoint(134,93.05999756,0.01752127893);
   graph->SetPoint(135,93.09999847,0.02399016172);
   graph->SetPoint(136,93.13999939,0.0314742066);
   graph->SetPoint(137,93.18000031,0.03997394815);
   graph->SetPoint(138,93.22000122,0.04949002713);
   graph->SetPoint(139,93.26000214,0.06002314016);
   graph->SetPoint(140,93.30000305,0.07157406956);
   graph->SetPoint(141,93.33999634,0.08414366841);
   graph->SetPoint(142,93.37999725,0.09773286432);
   graph->SetPoint(143,93.41999817,0.1123426482);
   graph->SetPoint(144,93.45999908,0.1279740632);
   graph->SetPoint(145,93.5,0.144628197);
   graph->SetPoint(146,93.54000092,0.1623062044);
   graph->SetPoint(147,93.58000183,0.1810092628);
   graph->SetPoint(148,93.62000275,0.200738579);
   graph->SetPoint(149,93.62000275,0.200738579);
   graph->SetPoint(150,93.66000366,0.2214953899);
   graph->SetPoint(151,93.69999695,0.2432809174);
   graph->SetPoint(152,93.73999786,0.2660964429);
   graph->SetPoint(153,93.77999878,0.2899431586);
   graph->SetPoint(154,93.81999969,0.3148224056);
   graph->SetPoint(155,93.86000061,0.3407353461);
   graph->SetPoint(156,93.90000153,0.367683202);
   graph->SetPoint(157,93.94000244,0.3956672251);
   graph->SetPoint(158,93.98000336,0.4246885478);
   graph->SetPoint(159,94.01999664,0.4547482729);
   graph->SetPoint(160,94.05999756,0.4858476222);
   graph->SetPoint(161,94.09999847,0.5179876089);
   graph->SetPoint(162,94.13999939,0.5511692166);
   graph->SetPoint(163,94.18000031,0.585393548);
   graph->SetPoint(164,94.22000122,0.6206615567);
   graph->SetPoint(165,94.26000214,0.6569740772);
   graph->SetPoint(166,94.30000305,0.6943320632);
   graph->SetPoint(167,94.33999634,0.7327364087);
   graph->SetPoint(168,94.37999725,0.772187829);
   graph->SetPoint(169,94.41999817,0.8126871586);
   graph->SetPoint(170,94.41999817,0.8126871586);
   graph->SetPoint(171,94.45999908,0.8542351723);
   graph->SetPoint(172,94.5,0.8968324661);
   graph->SetPoint(173,94.54000092,0.940479815);
   graph->SetPoint(174,94.58000183,0.985177815);
   graph->SetPoint(175,94.62000275,1.030927062);
   graph->SetPoint(176,94.66000366,1.077728152);
   graph->SetPoint(177,94.69999695,1.125581622);
   graph->SetPoint(178,94.73999786,1.174487948);
   graph->SetPoint(179,94.77999878,1.224447489);
   graph->SetPoint(180,94.81999969,1.27546072);
   graph->SetPoint(181,94.86000061,1.327528);
   graph->SetPoint(182,94.90000153,1.380649686);
   graph->SetPoint(183,94.94000244,1.434825897);
   graph->SetPoint(184,94.98000336,1.490056992);
   graph->SetPoint(185,95.01999664,1.546342969);
   graph->SetPoint(186,95.05999756,1.603683949);
   graph->SetPoint(187,95.09999847,1.66207993);
   graph->SetPoint(188,95.13999939,1.721530676);
   graph->SetPoint(189,95.18000031,1.782036185);
   graph->SetPoint(190,95.22000122,1.843595982);
   graph->SetPoint(191,95.22000122,1.843595982);
   graph->SetPoint(192,95.26000214,1.906209826);
   graph->SetPoint(193,95.30000305,1.969877124);
   graph->SetPoint(194,95.33999634,2.034597158);
   graph->SetPoint(195,95.37999725,2.100369453);
   graph->SetPoint(196,95.41999817,2.167192936);
   graph->SetPoint(197,95.45999908,2.235066652);
   graph->SetPoint(198,95.5,2.30398941);
   graph->SetPoint(199,95.54000092,2.37395978);
   graph->SetPoint(200,95.58000183,2.44497633);
   graph->SetPoint(201,95.62000275,2.517037392);
   graph->SetPoint(202,95.66000366,2.590141296);
   graph->SetPoint(203,95.69999695,2.66428566);
   graph->SetPoint(204,95.73999786,2.739468575);
   graph->SetPoint(205,95.77999878,2.815687418);
   graph->SetPoint(206,95.81999969,2.892939568);
   graph->SetPoint(207,95.86000061,2.971222401);
   graph->SetPoint(208,95.90000153,3.050532341);
   graph->SetPoint(209,95.94000244,3.130866289);
   graph->SetPoint(210,95.98000336,3.212220907);


   graph->Sort();

   cout << "4e: " << graph->Eval(91.1876) << endl;


   //2e2mu
   TGraph *graph1 = new TGraph(211);
   graph1->SetName("Graph1");
   graph1->SetTitle("Graph1");
   graph1->SetFillColor(1);
   graph1->SetLineWidth(3);
   graph1->SetLineColor(kBlue);
   graph1->SetMarkerStyle(20);
   graph1->SetPoint(0,88.01999664,8.795412064);
   graph1->SetPoint(1,88.05999756,8.61370182);
   graph1->SetPoint(2,88.09999847,8.43285656);
   graph1->SetPoint(3,88.13999939,8.252916336);
   graph1->SetPoint(4,88.18000031,8.073918343);
   graph1->SetPoint(5,88.22000122,7.895903111);
   graph1->SetPoint(6,88.26000214,7.718908787);
   graph1->SetPoint(7,88.30000305,7.542974472);
   graph1->SetPoint(8,88.33999634,7.36813879);
   graph1->SetPoint(9,88.37999725,7.194441795);
   graph1->SetPoint(10,88.41999817,7.021921158);
   graph1->SetPoint(11,88.45999908,6.850616932);
   graph1->SetPoint(12,88.5,6.680567265);
   graph1->SetPoint(13,88.54000092,6.51181221);
   graph1->SetPoint(14,88.58000183,6.344389915);
   graph1->SetPoint(15,88.62000275,6.178339481);
   graph1->SetPoint(16,88.66000366,6.013700008);
   graph1->SetPoint(17,88.69999695,5.850510597);
   graph1->SetPoint(18,88.73999786,5.688809872);
   graph1->SetPoint(19,88.77999878,5.528635979);
   graph1->SetPoint(20,88.81999969,5.370028496);
   graph1->SetPoint(21,88.81999969,5.370028496);
   graph1->SetPoint(22,88.86000061,5.21302557);
   graph1->SetPoint(23,88.90000153,5.057665825);
   graph1->SetPoint(24,88.94000244,4.903987885);
   graph1->SetPoint(25,88.98000336,4.752028942);
   graph1->SetPoint(26,89.01999664,4.601828575);
   graph1->SetPoint(27,89.05999756,4.4534235);
   graph1->SetPoint(28,89.09999847,4.306852341);
   graph1->SetPoint(29,89.13999939,4.162151814);
   graph1->SetPoint(30,89.18000031,4.019360065);
   graph1->SetPoint(31,89.22000122,3.87851429);
   graph1->SetPoint(32,89.26000214,3.739651203);
   graph1->SetPoint(33,89.30000305,3.602807283);
   graph1->SetPoint(34,89.33999634,3.468019247);
   graph1->SetPoint(35,89.37999725,3.335323095);
   graph1->SetPoint(36,89.41999817,3.204754591);
   graph1->SetPoint(37,89.45999908,3.076349258);
   graph1->SetPoint(38,89.5,2.950142145);
   graph1->SetPoint(39,89.54000092,2.82616806);
   graph1->SetPoint(40,89.58000183,2.704461336);
   graph1->SetPoint(41,89.62000275,2.58505559);
   graph1->SetPoint(42,89.62000275,2.58505559);
   graph1->SetPoint(43,89.66000366,2.467984438);
   graph1->SetPoint(44,89.69999695,2.353280783);
   graph1->SetPoint(45,89.73999786,2.240977049);
   graph1->SetPoint(46,89.77999878,2.131105185);
   graph1->SetPoint(47,89.81999969,2.023696423);
   graph1->SetPoint(48,89.86000061,1.918781519);
   graph1->SetPoint(49,89.90000153,1.816390634);
   graph1->SetPoint(50,89.94000244,1.716553092);
   graph1->SetPoint(51,89.98000336,1.619297981);
   graph1->SetPoint(52,90.01999664,1.524653077);
   graph1->SetPoint(53,90.05999756,1.432646155);
   graph1->SetPoint(54,90.09999847,1.343303561);
   graph1->SetPoint(55,90.13999939,1.256651402);
   graph1->SetPoint(56,90.18000031,1.17271471);
   graph1->SetPoint(57,90.22000122,1.091517925);
   graph1->SetPoint(58,90.26000214,1.013084531);
   graph1->SetPoint(59,90.30000305,0.9374370575);
   graph1->SetPoint(60,90.33999634,0.864597559);
   graph1->SetPoint(61,90.37999725,0.7945868969);
   graph1->SetPoint(62,90.41999817,0.727425158);
   graph1->SetPoint(63,90.41999817,0.727425158);
   graph1->SetPoint(64,90.45999908,0.6631317139);
   graph1->SetPoint(65,90.5,0.6017247438);
   graph1->SetPoint(66,90.54000092,0.5432218313);
   graph1->SetPoint(67,90.58000183,0.4876395166);
   graph1->SetPoint(68,90.62000275,0.4349934459);
   graph1->SetPoint(69,90.66000366,0.3852983713);
   graph1->SetPoint(70,90.69999695,0.3385681808);
   graph1->SetPoint(71,90.73999786,0.2948157787);
   graph1->SetPoint(72,90.77999878,0.2540532351);
   graph1->SetPoint(73,90.81999969,0.2162916809);
   graph1->SetPoint(74,90.86000061,0.1815413088);
   graph1->SetPoint(75,90.90000153,0.1498114169);
   graph1->SetPoint(76,90.94000244,0.1211103573);
   graph1->SetPoint(77,90.98000336,0.09544557333);
   graph1->SetPoint(78,91.01999664,0.07282357663);
   graph1->SetPoint(79,91.05999756,0.05324992537);
   graph1->SetPoint(80,91.09999847,0.0367292501);
   graph1->SetPoint(81,91.13999939,0.02326522022);
   graph1->SetPoint(82,91.18000031,0.01286056917);
   graph1->SetPoint(83,91.22000122,0.005517064128);
   graph1->SetPoint(84,91.22000122,0.005517064128);
   graph1->SetPoint(85,91.26000214,0.001235519536);
   graph1->SetPoint(86,91.29593658,0);
   graph1->SetPoint(87,91.29593658,0);
   graph1->SetPoint(88,91.29593658,0);
   graph1->SetPoint(89,91.29593658,0);
   graph1->SetPoint(90,91.29593658,0);
   graph1->SetPoint(91,91.29593658,0);
   graph1->SetPoint(92,91.29593658,0);
   graph1->SetPoint(93,91.5,0.03977194428);
   graph1->SetPoint(94,91.54000092,0.05686627701);
   graph1->SetPoint(95,91.58000183,0.07699460536);
   graph1->SetPoint(96,91.62000275,0.1001491994);
   graph1->SetPoint(97,91.66000366,0.1263214052);
   graph1->SetPoint(98,91.69999695,0.1555016339);
   graph1->SetPoint(99,91.73999786,0.1876795292);
   graph1->SetPoint(100,91.77999878,0.2228437364);
   graph1->SetPoint(101,91.81999969,0.260982126);
   graph1->SetPoint(102,91.86000061,0.3020817041);
   graph1->SetPoint(103,91.90000153,0.3461286724);
   graph1->SetPoint(104,91.94000244,0.3931084573);
   graph1->SetPoint(105,91.98000336,0.443005681);
   graph1->SetPoint(106,92.01999664,0.4958042502);
   //graph1->SetPoint(107,92.01999664,0.4958042204);
   graph1->SetPoint(108,92.05999756,0.551487267);
   graph1->SetPoint(109,92.09999847,0.6100373268);
   graph1->SetPoint(110,92.13999939,0.671436131);
   graph1->SetPoint(111,92.18000031,0.7356648445);
   graph1->SetPoint(112,92.22000122,0.802703917);
   graph1->SetPoint(113,92.26000214,0.872533381);
   graph1->SetPoint(114,92.30000305,0.945132494);
   graph1->SetPoint(115,92.33999634,1.020480037);
   graph1->SetPoint(116,92.37999725,1.098554254);
   graph1->SetPoint(117,92.41999817,1.179333091);
   graph1->SetPoint(118,92.45999908,1.262793779);
   graph1->SetPoint(119,92.5,1.348913193);
   graph1->SetPoint(120,92.54000092,1.437667727);
   graph1->SetPoint(121,92.58000183,1.52903378);
   graph1->SetPoint(122,92.62000275,1.622986913);
   graph1->SetPoint(123,92.66000366,1.719502687);
   graph1->SetPoint(124,92.69999695,1.818556309);
   graph1->SetPoint(125,92.73999786,1.920122623);
   graph1->SetPoint(126,92.77999878,2.024176359);
   graph1->SetPoint(127,92.81999969,2.130692005);
   graph1->SetPoint(128,92.81999969,2.130692005);
   graph1->SetPoint(129,92.86000061,2.239643812);
   graph1->SetPoint(130,92.90000153,2.351006031);
   graph1->SetPoint(131,92.94000244,2.464752674);
   graph1->SetPoint(132,92.98000336,2.580857754);
   graph1->SetPoint(133,93.01999664,2.699294806);
   graph1->SetPoint(134,93.05999756,2.820037603);
   graph1->SetPoint(135,93.09999847,2.94306016);
   graph1->SetPoint(136,93.13999939,3.068335533);
   graph1->SetPoint(137,93.18000031,3.195837736);
   graph1->SetPoint(138,93.22000122,3.325540066);
   graph1->SetPoint(139,93.26000214,3.457416296);
   graph1->SetPoint(140,93.30000305,3.591439486);
   graph1->SetPoint(141,93.33999634,3.727583647);
   graph1->SetPoint(142,93.37999725,3.865821838);
   graph1->SetPoint(143,93.41999817,4.006127834);
   graph1->SetPoint(144,93.45999908,4.148474216);
   graph1->SetPoint(145,93.5,4.292835712);
   graph1->SetPoint(146,93.54000092,4.439184189);
   graph1->SetPoint(147,93.58000183,4.587494373);
   graph1->SetPoint(148,93.62000275,4.737738609);
   graph1->SetPoint(149,93.62000275,4.737738609);
   graph1->SetPoint(150,93.66000366,4.889890194);
   graph1->SetPoint(151,93.69999695,5.043922424);
   graph1->SetPoint(152,93.73999786,5.199808598);
   graph1->SetPoint(153,93.77999878,5.357521057);
   graph1->SetPoint(154,93.81999969,5.517033577);
   graph1->SetPoint(155,93.86000061,5.678318024);
   graph1->SetPoint(156,93.90000153,5.841347694);
   graph1->SetPoint(157,93.94000244,6.006094933);
   graph1->SetPoint(158,93.98000336,6.172532082);
   graph1->SetPoint(159,94.01999664,6.340631485);
   graph1->SetPoint(160,94.05999756,6.510365486);
   graph1->SetPoint(161,94.09999847,6.681705952);
   graph1->SetPoint(162,94.13999939,6.854624748);
   graph1->SetPoint(163,94.18000031,7.029093266);
   graph1->SetPoint(164,94.22000122,7.205083847);
   graph1->SetPoint(165,94.26000214,7.382567883);
   graph1->SetPoint(166,94.30000305,7.561516285);
   graph1->SetPoint(167,94.33999634,7.741900921);
   graph1->SetPoint(168,94.37999725,7.923692226);
   graph1->SetPoint(169,94.41999817,8.106862068);
   graph1->SetPoint(170,94.41999817,8.106862068);
   graph1->SetPoint(171,94.45999908,8.291379929);
   graph1->SetPoint(172,94.5,8.477218628);
   graph1->SetPoint(173,94.54000092,8.664347649);
   graph1->SetPoint(174,94.58000183,8.85273838);
   graph1->SetPoint(175,94.62000275,9.042361259);
   graph1->SetPoint(176,94.66000366,9.233187675);
   graph1->SetPoint(177,94.69999695,9.425187111);
   graph1->SetPoint(178,94.73999786,9.618330002);
   graph1->SetPoint(179,94.77999878,9.812587738);
   graph1->SetPoint(180,94.81999969,10.00793171);
   graph1->SetPoint(181,94.86000061,10.20433044);
   graph1->SetPoint(182,94.90000153,10.40175724);
   graph1->SetPoint(183,94.94000244,10.60017967);
   graph1->SetPoint(184,94.98000336,10.79957104);
   graph1->SetPoint(185,95.01999664,10.99990082);
   graph1->SetPoint(186,95.05999756,11.20113945);
   graph1->SetPoint(187,95.09999847,11.40325832);
   graph1->SetPoint(188,95.13999939,11.60622883);
   graph1->SetPoint(189,95.18000031,11.81002045);
   graph1->SetPoint(190,95.22000122,12.01460457);
   graph1->SetPoint(191,95.22000122,12.01460457);
   graph1->SetPoint(192,95.26000214,12.21995258);
   graph1->SetPoint(193,95.30000305,12.42603588);
   graph1->SetPoint(194,95.33999634,12.63282394);
   graph1->SetPoint(195,95.37999725,12.84028816);
   graph1->SetPoint(196,95.41999817,13.04840088);
   graph1->SetPoint(197,95.45999908,13.25713253);
   graph1->SetPoint(198,95.5,13.46645451);
   graph1->SetPoint(199,95.54000092,13.6763382);
   graph1->SetPoint(200,95.58000183,13.88675499);
   graph1->SetPoint(201,95.62000275,14.09767723);
   graph1->SetPoint(202,95.66000366,14.3090744);
   graph1->SetPoint(203,95.69999695,14.5209198);
   graph1->SetPoint(204,95.73999786,14.73318481);
   graph1->SetPoint(205,95.77999878,14.94584179);
   graph1->SetPoint(206,95.81999969,15.15886116);
   graph1->SetPoint(207,95.86000061,15.37221718);
   graph1->SetPoint(208,95.90000153,15.58588123);
   graph1->SetPoint(209,95.94000244,15.79982567);
   graph1->SetPoint(210,95.98000336,16.01402283);

   
   graph1->Sort();
   
   cout<< "2e2mu: " << graph1->Eval(91.1876) << endl;


   //4mu
   TGraph *graph2 = new TGraph(216);
   graph2->SetName("Graph2");
   graph2->SetTitle("Graph2");
   graph2->SetFillColor(1);
   graph2->SetLineWidth(3);
   graph2->SetLineColor(kRed);
   graph2->SetMarkerStyle(20);
   graph2->SetPoint(0,88.01999664,42.99673462);
   graph2->SetPoint(1,88.05999756,42.01807404);
   graph2->SetPoint(2,88.09999847,41.04578781);
   graph2->SetPoint(3,88.13999939,40.08004379);
   graph2->SetPoint(4,88.18000031,39.12101746);
   graph2->SetPoint(5,88.22000122,38.16888046);
   graph2->SetPoint(6,88.26000214,37.22380447);
   graph2->SetPoint(7,88.30000305,36.2859726);
   graph2->SetPoint(8,88.33999634,35.35555267);
   graph2->SetPoint(9,88.37999725,34.43272781);
   graph2->SetPoint(10,88.41999817,33.51767731);
   graph2->SetPoint(11,88.45999908,32.61057281);
   graph2->SetPoint(12,88.5,31.71160507);
   graph2->SetPoint(13,88.54000092,30.82094765);
   graph2->SetPoint(14,88.58000183,29.93878746);
   graph2->SetPoint(15,88.62000275,29.06530762);
   graph2->SetPoint(16,88.66000366,28.20069313);
   graph2->SetPoint(17,88.69999695,27.34512901);
   graph2->SetPoint(18,88.73999786,26.49880409);
   graph2->SetPoint(19,88.77999878,25.66190529);
   graph2->SetPoint(20,88.81999969,24.83462334);
   graph2->SetPoint(21,88.81999969,24.83462334);
   graph2->SetPoint(22,88.86000061,24.01715088);
   graph2->SetPoint(23,88.90000153,23.20967865);
   graph2->SetPoint(24,88.94000244,22.41239929);
   graph2->SetPoint(25,88.98000336,21.62551308);
   graph2->SetPoint(26,89.01999664,20.84921074);
   graph2->SetPoint(27,89.05999756,20.08369446);
   graph2->SetPoint(28,89.09999847,19.32916451);
   graph2->SetPoint(29,89.13999939,18.58581734);
   graph2->SetPoint(30,89.18000031,17.85385895);
   graph2->SetPoint(31,89.22000122,17.13349152);
   graph2->SetPoint(32,89.26000214,16.42491913);
   graph2->SetPoint(33,89.30000305,15.72835064);
   graph2->SetPoint(34,89.33999634,15.04399014);
   graph2->SetPoint(35,89.37999725,14.37204742);
   graph2->SetPoint(36,89.41999817,13.71273041);
   graph2->SetPoint(37,89.45999908,13.0662508);
   graph2->SetPoint(38,89.5,12.43281651);
   graph2->SetPoint(39,89.54000092,11.81264019);
   graph2->SetPoint(40,89.58000183,11.20593262);
   graph2->SetPoint(41,89.62000275,10.6129055);
   graph2->SetPoint(42,89.62000275,10.6129055);
   graph2->SetPoint(43,89.66000366,10.03376961);
   graph2->SetPoint(44,89.69999695,9.468736649);
   graph2->SetPoint(45,89.73999786,8.918016434);
   graph2->SetPoint(46,89.77999878,8.381820679);
   graph2->SetPoint(47,89.81999969,7.860357285);
   graph2->SetPoint(48,89.86000061,7.353835583);
   graph2->SetPoint(49,89.90000153,6.862462997);
   graph2->SetPoint(50,89.94000244,6.386445045);
   graph2->SetPoint(51,89.98000336,5.92598629);
   graph2->SetPoint(52,90.01999664,5.481288433);
   graph2->SetPoint(53,90.05999756,5.0525527);
   graph2->SetPoint(54,90.09999847,4.639976501);
   graph2->SetPoint(55,90.13999939,4.243755817);
   graph2->SetPoint(56,90.18000031,3.864083052);
   graph2->SetPoint(57,90.22000122,3.501147509);
   graph2->SetPoint(58,90.26000214,3.155135393);
   graph2->SetPoint(59,90.30000305,2.826228619);
   graph2->SetPoint(60,90.33999634,2.514605522);
   graph2->SetPoint(61,90.37999725,2.220438957);
   graph2->SetPoint(62,90.41999817,1.943897605);
   graph2->SetPoint(63,90.41999817,1.943897605);
   graph2->SetPoint(64,90.45999908,1.685144305);
   graph2->SetPoint(65,90.5,1.444335938);
   graph2->SetPoint(66,90.54000092,1.221622825);
   graph2->SetPoint(67,90.58000183,1.017148852);
   graph2->SetPoint(68,90.62000275,0.8310500383);
   graph2->SetPoint(69,90.66000366,0.663454473);
   graph2->SetPoint(70,90.69999695,0.5144816637);
   graph2->SetPoint(71,90.73999786,0.3842421472);
   graph2->SetPoint(72,90.77999878,0.2728365958);
   graph2->SetPoint(73,90.81999969,0.1803556085);
   graph2->SetPoint(74,90.86000061,0.1068789586);
   graph2->SetPoint(75,90.90000153,0.05247514695);
   graph2->SetPoint(76,90.94000244,0.01720083691);
   graph2->SetPoint(77,90.98000336,0.00110038009);
   graph2->SetPoint(78,90.9935379,0);
   graph2->SetPoint(79,90.9935379,0);
   graph2->SetPoint(80,90.9935379,0);
   graph2->SetPoint(81,90.9935379,0);
   graph2->SetPoint(82,90.9935379,0);
   graph2->SetPoint(83,90.9935379,0);
   graph2->SetPoint(84,90.9935379,0);
   graph2->SetPoint(85,91.01999664,0.004205350298);
   graph2->SetPoint(86,91.05999756,0.02653408609);
   graph2->SetPoint(87,91.09999847,0.06809128821);
   graph2->SetPoint(88,91.13999939,0.1288676411);
   graph2->SetPoint(89,91.18000031,0.208839491);
   graph2->SetPoint(90,91.22000122,0.3079685569);
   graph2->SetPoint(91,91.22000122,0.3079685569);
   graph2->SetPoint(92,91.26000214,0.4262017608);
   graph2->SetPoint(93,91.30000305,0.5634709001);
   graph2->SetPoint(94,91.33999634,0.7196927667);
   graph2->SetPoint(95,91.37999725,0.8947688341);
   graph2->SetPoint(96,91.41999817,1.088585615);
   graph2->SetPoint(97,91.45999908,1.301014304);
   graph2->SetPoint(98,91.5,1.531911612);
   graph2->SetPoint(99,91.54000092,1.781119347);
   graph2->SetPoint(100,91.58000183,2.048465252);
   graph2->SetPoint(101,91.62000275,2.333762884);
   graph2->SetPoint(102,91.66000366,2.636813402);
   graph2->SetPoint(103,91.69999695,2.957404137);
   graph2->SetPoint(104,91.73999786,3.295311213);
   graph2->SetPoint(105,91.77999878,3.650299788);
   graph2->SetPoint(106,91.81999969,4.022123814);
   graph2->SetPoint(107,91.86000061,4.410528183);
   graph2->SetPoint(108,91.90000153,4.815249443);
   graph2->SetPoint(109,91.94000244,5.23601675);
   graph2->SetPoint(110,91.98000336,5.672553062);
   graph2->SetPoint(111,92.01999664,6.124575138);
   graph2->SetPoint(112,92.01999664,6.124575138);
   graph2->SetPoint(113,92.05999756,6.591795921);
   graph2->SetPoint(114,92.09999847,7.073926449);
   graph2->SetPoint(115,92.13999939,7.570672989);
   graph2->SetPoint(116,92.18000031,8.08174324);
   graph2->SetPoint(117,92.22000122,8.606842995);
   graph2->SetPoint(118,92.26000214,9.145680428);
   graph2->SetPoint(119,92.30000305,9.697964668);
   graph2->SetPoint(120,92.33999634,10.26340675);
   graph2->SetPoint(121,92.37999725,10.84172058);
   graph2->SetPoint(122,92.41999817,11.43262482);
   graph2->SetPoint(123,92.45999908,12.03584099);
   graph2->SetPoint(124,92.5,12.65109539);
   graph2->SetPoint(125,92.54000092,13.27812099);
   graph2->SetPoint(126,92.58000183,13.91665268);
   graph2->SetPoint(127,92.62000275,14.56643105);
   graph2->SetPoint(128,92.66000366,15.22720337);
   graph2->SetPoint(129,92.69999695,15.89872169);
   graph2->SetPoint(130,92.73999786,16.58073997);
   graph2->SetPoint(131,92.77999878,17.2730217);
   graph2->SetPoint(132,92.81999969,17.97533035);
   graph2->SetPoint(133,92.81999969,17.97533035);
   graph2->SetPoint(134,92.86000061,18.68743896);
   graph2->SetPoint(135,92.90000153,19.40911865);
   graph2->SetPoint(136,92.94000244,20.14015007);
   graph2->SetPoint(137,92.98000336,20.88031387);
   graph2->SetPoint(138,93.01999664,21.62939453);
   graph2->SetPoint(139,93.05999756,22.38718414);
   graph2->SetPoint(140,93.09999847,23.15346909);
   graph2->SetPoint(141,93.13999939,23.92804527);
   graph2->SetPoint(142,93.18000031,24.71071243);
   graph2->SetPoint(143,93.22000122,25.50126266);
   graph2->SetPoint(144,93.26000214,26.29950333);
   graph2->SetPoint(145,93.30000305,27.10523224);
   graph2->SetPoint(146,93.33999634,27.91825485);
   graph2->SetPoint(147,93.37999725,28.73837852);
   graph2->SetPoint(148,93.41999817,29.56540871);
   graph2->SetPoint(149,93.45999908,30.39915657);
   graph2->SetPoint(150,93.5,31.23942947);
   graph2->SetPoint(151,93.54000092,32.0860405);
   graph2->SetPoint(152,93.58000183,32.93880081);
   graph2->SetPoint(153,93.62000275,33.79752731);
   graph2->SetPoint(154,93.62000275,33.79752731);
   graph2->SetPoint(155,93.66000366,34.66203308);
   graph2->SetPoint(156,93.69999695,35.53213501);
   graph2->SetPoint(157,93.73999786,36.40764999);
   graph2->SetPoint(158,93.77999878,37.28839874);
   graph2->SetPoint(159,93.81999969,38.17420197);
   graph2->SetPoint(160,93.86000061,39.06488037);
   graph2->SetPoint(161,93.90000153,39.96025848);
   graph2->SetPoint(162,93.94000244,40.86016464);
   graph2->SetPoint(163,93.98000336,41.76441956);
   graph2->SetPoint(164,94.01999664,42.67286301);
   graph2->SetPoint(165,94.05999756,43.5853157);
   graph2->SetPoint(166,94.09999847,44.50161362);
   graph2->SetPoint(167,94.13999939,45.42160034);
   graph2->SetPoint(168,94.18000031,46.34510422);
   graph2->SetPoint(169,94.22000122,47.27197266);
   graph2->SetPoint(170,94.26000214,48.20204544);
   graph2->SetPoint(171,94.30000305,49.13516998);
   graph2->SetPoint(172,94.33999634,50.07119751);
   graph2->SetPoint(173,94.37999725,51.00997925);
   graph2->SetPoint(174,94.41999817,51.95137024);
   graph2->SetPoint(175,94.41999817,51.95137024);
   graph2->SetPoint(176,94.45999908,52.89523315);
   graph2->SetPoint(177,94.5,53.84142303);
   graph2->SetPoint(178,94.54000092,54.789814);
   graph2->SetPoint(179,94.58000183,55.74026871);
   graph2->SetPoint(180,94.62000275,56.69266129);
   graph2->SetPoint(181,94.66000366,57.64687347);
   graph2->SetPoint(182,94.69999695,58.60277939);
   graph2->SetPoint(183,94.73999786,59.5602684);
   graph2->SetPoint(184,94.77999878,60.51922989);
   graph2->SetPoint(185,94.81999969,61.47954941);
   graph2->SetPoint(186,94.86000061,62.44112778);
   graph2->SetPoint(187,94.90000153,63.40386581);
   graph2->SetPoint(188,94.94000244,64.36766815);
   graph2->SetPoint(189,94.98000336,65.33243561);
   graph2->SetPoint(190,95.01999664,66.29808044);
   graph2->SetPoint(191,95.05999756,67.264534);
   graph2->SetPoint(192,95.09999847,68.23168945);
   graph2->SetPoint(193,95.13999939,69.19949341);
   graph2->SetPoint(194,95.18000031,70.16786194);
   graph2->SetPoint(195,95.22000122,71.13671875);
   graph2->SetPoint(196,95.22000122,71.13671875);
   graph2->SetPoint(197,95.26000214,72.10600281);
   graph2->SetPoint(198,95.30000305,73.07565308);
   graph2->SetPoint(199,95.33999634,74.04560852);
   graph2->SetPoint(200,95.37999725,75.01580811);
   graph2->SetPoint(201,95.41999817,75.98619843);
   graph2->SetPoint(202,95.45999908,76.95672607);
   graph2->SetPoint(203,95.5,77.92734528);
   graph2->SetPoint(204,95.54000092,78.89801788);
   graph2->SetPoint(205,95.58000183,79.86868286);
   graph2->SetPoint(206,95.62000275,80.83930969);
   graph2->SetPoint(207,95.66000366,81.80986023);
   graph2->SetPoint(208,95.69999695,82.7802887);
   graph2->SetPoint(209,95.73999786,83.7505722);
   graph2->SetPoint(210,95.77999878,84.72067261);
   graph2->SetPoint(211,95.81999969,85.69055176);
   graph2->SetPoint(212,95.86000061,86.6601944);
   graph2->SetPoint(213,95.90000153,87.62956238);
   graph2->SetPoint(214,95.94000244,88.59862518);
   graph2->SetPoint(215,95.98000336,89.56736755);



   cout<< "4mu: " << graph2->Eval(91.1876) << endl;


   //4l
   TGraph *graph3 = new TGraph(212);
   graph3->SetName("Graph3");
   graph3->SetTitle("Graph3");
   graph3->SetFillColor(1);
   graph3->SetLineWidth(3);
   graph3->SetMarkerStyle(20);
   graph3->SetPoint(0,88.01999664,57.33911514);
   graph3->SetPoint(1,88.05999756,56.08871841);
   graph3->SetPoint(2,88.09999847,54.84604263);
   graph3->SetPoint(3,88.13999939,53.61128998);
   graph3->SetPoint(4,88.18000031,52.38465881);
   graph3->SetPoint(5,88.22000122,51.1663475);
   graph3->SetPoint(6,88.26000214,49.95656586);
   graph3->SetPoint(7,88.30000305,48.75551605);
   graph3->SetPoint(8,88.33999634,47.56340408);
   graph3->SetPoint(9,88.37999725,46.38043976);
   graph3->SetPoint(10,88.41999817,45.20683289);
   graph3->SetPoint(11,88.45999908,44.04279709);
   graph3->SetPoint(12,88.5,42.88854218);
   graph3->SetPoint(13,88.54000092,41.74428558);
   graph3->SetPoint(14,88.58000183,40.61024094);
   graph3->SetPoint(15,88.62000275,39.48662186);
   graph3->SetPoint(16,88.66000366,38.37365723);
   graph3->SetPoint(17,88.69999695,37.27156067);
   graph3->SetPoint(18,88.73999786,36.18055725);
   graph3->SetPoint(19,88.77999878,35.10086823);
   graph3->SetPoint(20,88.81999969,34.03272247);
   graph3->SetPoint(21,88.81999969,34.03272247);
   graph3->SetPoint(22,88.86000061,32.97634506);
   graph3->SetPoint(23,88.90000153,31.93196487);
   graph3->SetPoint(24,88.94000244,30.89981461);
   graph3->SetPoint(25,88.98000336,29.88012505);
   graph3->SetPoint(26,89.01999664,28.87313271);
   graph3->SetPoint(27,89.05999756,27.87907028);
   graph3->SetPoint(28,89.09999847,26.8981781);
   graph3->SetPoint(29,89.13999939,25.93069649);
   graph3->SetPoint(30,89.18000031,24.97686577);
   graph3->SetPoint(31,89.22000122,24.03692818);
   graph3->SetPoint(32,89.26000214,23.11112785);
   graph3->SetPoint(33,89.30000305,22.19971466);
   graph3->SetPoint(34,89.33999634,21.30293083);
   graph3->SetPoint(35,89.37999725,20.42103004);
   graph3->SetPoint(36,89.41999817,19.55426025);
   graph3->SetPoint(37,89.45999908,18.70287132);
   graph3->SetPoint(38,89.5,17.86711502);
   graph3->SetPoint(39,89.54000092,17.04724693);
   graph3->SetPoint(40,89.58000183,16.24351692);
   graph3->SetPoint(41,89.62000275,15.45617962);
   graph3->SetPoint(42,89.62000275,15.45617962);
   graph3->SetPoint(43,89.66000366,14.6854887);
   graph3->SetPoint(44,89.69999695,13.93169785);
   graph3->SetPoint(45,89.73999786,13.19505882);
   graph3->SetPoint(46,89.77999878,12.47582531);
   graph3->SetPoint(47,89.81999969,11.77424908);
   graph3->SetPoint(48,89.86000061,11.09057903);
   graph3->SetPoint(49,89.90000153,10.4250679);
   graph3->SetPoint(50,89.94000244,9.777960777);
   graph3->SetPoint(51,89.98000336,9.149505615);
   graph3->SetPoint(52,90.01999664,8.539945602);
   graph3->SetPoint(53,90.05999756,7.949523926);
   graph3->SetPoint(54,90.09999847,7.378479958);
   graph3->SetPoint(55,90.13999939,6.827050209);
   graph3->SetPoint(56,90.18000031,6.295467854);
   graph3->SetPoint(57,90.22000122,5.783964634);
   graph3->SetPoint(58,90.26000214,5.292765617);
   graph3->SetPoint(59,90.30000305,4.82209301);
   graph3->SetPoint(60,90.33999634,4.37216568);
   graph3->SetPoint(61,90.37999725,3.943194866);
   graph3->SetPoint(62,90.41999817,3.535388231);
   graph3->SetPoint(63,90.41999817,3.535388231);
   graph3->SetPoint(64,90.45999908,3.148947239);
   graph3->SetPoint(65,90.5,2.784065962);
   graph3->SetPoint(66,90.54000092,2.440932035);
   graph3->SetPoint(67,90.58000183,2.119725466);
   graph3->SetPoint(68,90.62000275,1.820617914);
   graph3->SetPoint(69,90.66000366,1.543772101);
   graph3->SetPoint(70,90.69999695,1.28934145);
   graph3->SetPoint(71,90.73999786,1.057468891);
   graph3->SetPoint(72,90.77999878,0.8482871056);
   graph3->SetPoint(73,90.81999969,0.6619167924);
   graph3->SetPoint(74,90.86000061,0.4984668195);
   graph3->SetPoint(75,90.90000153,0.3580331504);
   graph3->SetPoint(76,90.94000244,0.240698427);
   graph3->SetPoint(77,90.98000336,0.1465311348);
   graph3->SetPoint(78,91.01999664,0.07558509707);
   graph3->SetPoint(79,91.05999756,0.02789884619);
   graph3->SetPoint(80,91.09999847,0.003495044075);
   graph3->SetPoint(81,91.12191772,0);
   graph3->SetPoint(82,91.12191772,0);
   graph3->SetPoint(83,91.12191772,0);
   graph3->SetPoint(84,91.12191772,0);
   graph3->SetPoint(85,91.12191772,0);
   graph3->SetPoint(86,91.12191772,0);
   graph3->SetPoint(87,91.12191772,0);
   graph3->SetPoint(88,91.26000214,0.1385737211);
   graph3->SetPoint(89,91.30000305,0.230332002);
   graph3->SetPoint(90,91.33999634,0.345148921);
   graph3->SetPoint(91,91.37999725,0.4829240143);
   graph3->SetPoint(92,91.41999817,0.643538177);
   graph3->SetPoint(93,91.45999908,0.8268537521);
   graph3->SetPoint(94,91.5,1.032714605);
   graph3->SetPoint(95,91.54000092,1.260946751);
   graph3->SetPoint(96,91.58000183,1.511358023);
   graph3->SetPoint(97,91.62000275,1.783738732);
   graph3->SetPoint(98,91.66000366,2.07786274);
   graph3->SetPoint(99,91.69999695,2.39348793);
   graph3->SetPoint(100,91.73999786,2.730356455);
   graph3->SetPoint(101,91.77999878,3.088196516);
   graph3->SetPoint(102,91.81999969,3.466723442);
   graph3->SetPoint(103,91.86000061,3.865639925);
   graph3->SetPoint(104,91.90000153,4.284637928);
   graph3->SetPoint(105,91.94000244,4.723400593);
   graph3->SetPoint(106,91.98000336,5.181601524);
   graph3->SetPoint(107,92.01999664,5.658910275);
   graph3->SetPoint(108,92.01999664,5.658910275);
   graph3->SetPoint(109,92.05999756,6.154988289);
   graph3->SetPoint(110,92.09999847,6.669495583);
   graph3->SetPoint(111,92.13999939,7.202087879);
   graph3->SetPoint(112,92.18000031,7.752422333);
   graph3->SetPoint(113,92.22000122,8.32015419);
   graph3->SetPoint(114,92.26000214,8.904941559);
   graph3->SetPoint(115,92.30000305,9.506444931);
   graph3->SetPoint(116,92.33999634,10.12432957);
   graph3->SetPoint(117,92.37999725,10.75826359);
   graph3->SetPoint(118,92.41999817,11.40792084);
   graph3->SetPoint(119,92.45999908,12.07298279);
   graph3->SetPoint(120,92.5,12.75313663);
   graph3->SetPoint(121,92.54000092,13.44807529);
   graph3->SetPoint(122,92.58000183,14.15750027);
   graph3->SetPoint(123,92.62000275,14.88112068);
   graph3->SetPoint(124,92.66000366,15.61865044);
   graph3->SetPoint(125,92.69999695,16.36981392);
   graph3->SetPoint(126,92.73999786,17.13433838);
   graph3->SetPoint(127,92.77999878,17.91196251);
   graph3->SetPoint(128,92.81999969,18.70242691);
   graph3->SetPoint(129,92.81999969,18.70242691);
   graph3->SetPoint(130,92.86000061,19.50548172);
   graph3->SetPoint(131,92.90000153,20.32088089);
   graph3->SetPoint(132,92.94000244,21.14838409);
   graph3->SetPoint(133,92.98000336,21.98775864);
   graph3->SetPoint(134,93.01999664,22.83877182);
   graph3->SetPoint(135,93.05999756,23.70119667);
   graph3->SetPoint(136,93.09999847,24.57481003);
   graph3->SetPoint(137,93.13999939,25.45939636);
   graph3->SetPoint(138,93.18000031,26.35473442);
   graph3->SetPoint(139,93.22000122,27.2606163);
   graph3->SetPoint(140,93.26000214,28.17682648);
   graph3->SetPoint(141,93.30000305,29.10315895);
   graph3->SetPoint(142,93.33999634,30.03940773);
   graph3->SetPoint(143,93.37999725,30.98536491);
   graph3->SetPoint(144,93.41999817,31.94083023);
   graph3->SetPoint(145,93.45999908,32.9056015);
   graph3->SetPoint(146,93.5,33.87947845);
   graph3->SetPoint(147,93.54000092,34.86225891);
   graph3->SetPoint(148,93.58000183,35.85375214);
   graph3->SetPoint(149,93.62000275,36.85375214);
   graph3->SetPoint(150,93.62000275,36.85375214);
   graph3->SetPoint(151,93.66000366,37.86207199);
   graph3->SetPoint(152,93.69999695,38.87851334);
   graph3->SetPoint(153,93.73999786,39.90288162);
   graph3->SetPoint(154,93.77999878,40.93498611);
   graph3->SetPoint(155,93.81999969,41.97463608);
   graph3->SetPoint(156,93.86000061,43.02164078);
   graph3->SetPoint(157,93.90000153,44.07581329);
   graph3->SetPoint(158,93.94000244,45.13696671);
   graph3->SetPoint(159,93.98000336,46.20491409);
   graph3->SetPoint(160,94.01999664,47.27947617);
   graph3->SetPoint(161,94.05999756,48.360466);
   graph3->SetPoint(162,94.09999847,49.44770813);
   graph3->SetPoint(163,94.13999939,50.54101944);
   graph3->SetPoint(164,94.18000031,51.64023209);
   graph3->SetPoint(165,94.22000122,52.74516296);
   graph3->SetPoint(166,94.26000214,53.85564804);
   graph3->SetPoint(167,94.30000305,54.97151947);
   graph3->SetPoint(168,94.33999634,56.09260941);
   graph3->SetPoint(169,94.37999725,57.21875763);
   graph3->SetPoint(170,94.41999817,58.34980011);
   graph3->SetPoint(171,94.41999817,58.34980011);
   graph3->SetPoint(172,94.45999908,59.48558426);
   graph3->SetPoint(173,94.5,60.62595749);
   graph3->SetPoint(174,94.54000092,61.77076721);
   graph3->SetPoint(175,94.58000183,62.91986847);
   graph3->SetPoint(176,94.62000275,64.07312012);
   graph3->SetPoint(177,94.66000366,65.2303772);
   graph3->SetPoint(178,94.69999695,66.39151001);
   graph3->SetPoint(179,94.73999786,67.55638123);
   graph3->SetPoint(180,94.77999878,68.72486877);
   graph3->SetPoint(181,94.81999969,69.89684296);
   graph3->SetPoint(182,94.86000061,71.07218933);
   graph3->SetPoint(183,94.90000153,72.25079346);
   graph3->SetPoint(184,94.94000244,73.43252563);
   graph3->SetPoint(185,94.98000336,74.61729431);
   graph3->SetPoint(186,95.01999664,75.80497742);
   graph3->SetPoint(187,95.05999756,76.99549103);
   graph3->SetPoint(188,95.09999847,78.18872833);
   graph3->SetPoint(189,95.13999939,79.38459015);
   graph3->SetPoint(190,95.18000031,80.58299255);
   graph3->SetPoint(191,95.22000122,81.78383636);
   graph3->SetPoint(192,95.22000122,81.78383636);
   graph3->SetPoint(193,95.26000214,82.98705292);
   graph3->SetPoint(194,95.30000305,84.19254303);
   graph3->SetPoint(195,95.33999634,85.40024567);
   graph3->SetPoint(196,95.37999725,86.61006927);
   graph3->SetPoint(197,95.41999817,87.82195282);
   graph3->SetPoint(198,95.45999908,89.03581238);
   graph3->SetPoint(199,95.5,90.25159454);
   graph3->SetPoint(200,95.54000092,91.46923065);
   graph3->SetPoint(201,95.58000183,92.68865204);
   graph3->SetPoint(202,95.62000275,93.90979767);
   graph3->SetPoint(203,95.66000366,95.13261414);
   graph3->SetPoint(204,95.69999695,96.35704803);
   graph3->SetPoint(205,95.73999786,97.58303833);
   graph3->SetPoint(206,95.77999878,98.81052399);
   graph3->SetPoint(207,95.81999969,100.0394745);
   graph3->SetPoint(208,95.86000061,101.2698212);
   graph3->SetPoint(209,95.90000153,102.5015259);
   graph3->SetPoint(210,95.94000244,103.7345352);
   graph3->SetPoint(211,95.98000336,104.9688034);



   TH1F *Graph_Graph1 = new TH1F("Graph_Graph1","Graph",212,84.03,95.97);
   Graph_Graph1->SetMinimum(0);
   Graph_Graph1->SetMaximum(57.47094);
   Graph_Graph1->SetDirectory(0);
   Graph_Graph1->SetStats(0);
   Graph_Graph1->SetLineStyle(0);
   Graph_Graph1->SetMarkerStyle(20);
   Graph_Graph1->GetXaxis()->SetLabelFont(42);
   Graph_Graph1->GetXaxis()->SetLabelOffset(0.01);
   Graph_Graph1->GetXaxis()->SetLabelSize(0.045);
   Graph_Graph1->GetXaxis()->SetTitleSize(0.055);
   Graph_Graph1->GetXaxis()->SetTitleOffset(0.9);
   Graph_Graph1->GetXaxis()->SetTitleFont(42);
   Graph_Graph1->GetYaxis()->SetLabelFont(42);
   Graph_Graph1->GetYaxis()->SetLabelOffset(0.01);
   Graph_Graph1->GetYaxis()->SetLabelSize(0.045);
   Graph_Graph1->GetYaxis()->SetTitleSize(0.055);
   Graph_Graph1->GetYaxis()->SetTitleOffset(1.25);
   Graph_Graph1->GetYaxis()->SetTitleFont(42);
   Graph_Graph1->GetZaxis()->SetLabelFont(42);
   Graph_Graph1->GetZaxis()->SetLabelOffset(0.01);
   Graph_Graph1->GetZaxis()->SetLabelSize(0.045);
   Graph_Graph1->GetZaxis()->SetTitleSize(0.055);
   Graph_Graph1->GetZaxis()->SetTitleFont(42);
   Graph_Graph1->GetXaxis()->SetNdivisions(510);
   
   graph->SetHistogram(Graph_Graph1);
   graph->Draw("cx");
   graph1->Draw("cx");
   graph2->Draw("cx");
   graph3->Draw("cx");

   TPaveText *pt = new TPaveText(0.1577181,0.95,0.9580537,0.99,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   TText *text = pt->AddText(0.01,0.5,"CMS");
   text = pt->AddText(0.3,0.6,"#sqrt{s} = 7 TeV, L = 5.1 fb^{-1}  #sqrt{s} = 8 TeV, L = 19.7 fb^{-1}");
   pt->Draw();
   

   TLegend *leg = new TLegend(0.73,0.77,0.94,0.94);
   leg->SetTextSize(0.035);
   leg->SetTextFont(42);
   leg->SetFillColor(kWhite);
   //leg->SetBorderSize(0);
   //leg->SetFillStyle(0);

   leg->AddEntry(graph3,"Combined","L");
   leg->AddEntry(graph,"Z#rightarrow 4e","L");
   leg->AddEntry(graph2,"Z#rightarrow 4#mu","L");
   leg->AddEntry(graph1,"Z#rightarrow 2e2#mu","L");






   double yLow = 0.5;

   

   pt = new TPaveText(0.11,yLow,0.4,yLow+0.04,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   pt->SetTextColor(kBlue);
   text = pt->AddText(0.2,0.2,"m_{2e2#mu} = 91.24 #pm 0.46 GeV");
   //text = pt->AddText(0.2,0.2,"m_{2e2#mu} = 91.24 #pm 0.40 #pm 0.16 GeV");
   //stat 91.4315 +0.405948-0.397679
   cout << "Syst 2e2mu: " << findSystErr(0.43,0.40) << endl;
   //pt->Draw();

   pt = new TPaveText(0.11,yLow+0.06,0.4,yLow+0.1,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   pt->SetTextColor(kRed);
   text = pt->AddText(0.2,0.2,"m_{4#mu} = 91.00 #pm 0.26 GeV");
   //text = pt->AddText(0.2,0.2,"m_{4#mu} = 91.00 #pm 0.25 #pm 0.09 GeV");
   //stat 91.0078 +0.255715-0.25533
   cout << "Syst 4mu: " << findSystErr(0.27,0.255) << endl;
   //pt->Draw();

   pt = new TPaveText(0.11,yLow+0.12,0.4,yLow+0.16,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   pt->SetTextColor(kGreen+1);
   text = pt->AddText(0.2,0.2,"m_{4e} = 93.67 #pm 1.08 GeV");
   //text = pt->AddText(0.2,0.2,"m_{4e} = 9 #pm 0.74 #pm 0.30 GeV");
   //stat 91.8026 +0.745333-0.740755
   cout << "Syst 4e: " << findSystErr(0.8,0.74) << endl;
   //pt->Draw();

   pt = new TPaveText(0.11,yLow+0.18,0.4,yLow+0.22,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   text = pt->AddText(0.2,0.2,"m_{4l} = 91.15 #pm 0.23 GeV");
   //text = pt->AddText(0.2,0.2,"m_{4l} = 91.17 #pm 0.18 #pm 0.13 GeV");
   //stat  91.1724 +0.168014-0.204439
   cout << "Syst 4l: " << findSystErr(0.22,0.18) << endl;
   //pt->Draw();

   pt = new TPaveText(0.18,yLow+0.24,0.4,yLow+0.28,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.035);
   text = pt->AddText(0.2,0.2,"#chi^{2}/ndof = 1.38/3");
   //pt->Draw();
   
   gPad->SetTicks(1,1);

   TLine *line95 = new TLine(88,3.84,96,3.84);
   line95->SetLineColor(kRed);
   line95->SetLineWidth(2);
   line95->Draw();

   TLine *line68 = new TLine(88,1,96,1);
   line68->SetLineColor(kRed);
   line68->SetLineWidth(3);
   line68->Draw();
   
   TLine *lineZ = new TLine(91.1876,0,91.1876,10);
   lineZ->SetLineColor(kGray+2);
   lineZ->SetLineStyle(7);
   lineZ->Draw();

   leg->Draw();
   hframe->GetXaxis()->SetRangeUser(88,96);
   ccc->Modified();
   ccc->cd();
   ccc->SetSelected(ccc);

   ccc->SaveAs("massZ4lScan_MZ2gt12_Legacy_split.eps");
   ccc->SaveAs("massZ4lScan_MZ2gt12_Legacy_split.png");
}
예제 #7
0
void plotLimit(string outputDir="./", TString inputs="", TString inputs_blinded="", TString inputXSec="", bool strengthLimit=true, bool blind=false, double energy=7, double luminosity=5.035, TString legendName="ee and #mu#mu channels")
{
   setTDRStyle();  
   gStyle->SetPadTopMargin   (0.05);
   gStyle->SetPadBottomMargin(0.12);
   gStyle->SetPadRightMargin (0.16);
   gStyle->SetPadLeftMargin  (0.14);
   gStyle->SetTitleSize(0.04, "XYZ");
   gStyle->SetTitleXOffset(1.1);
   gStyle->SetTitleYOffset(1.45);
   gStyle->SetPalette(1);
   gStyle->SetNdivisions(505);
  
  //get the limits from the tree
  TFile* file = TFile::Open(inputs);
  printf("Looping on %s\n",inputs.Data());
  if(!file) return;
  if(file->IsZombie()) return;
  TFile* file_blinded = TFile::Open(inputs_blinded);
  printf("Looping on %s\n",inputs_blinded.Data());
  if(!file_blinded) return;
  if(file_blinded->IsZombie()) return;
  TTree* tree_blinded = (TTree*)file_blinded->Get("limit");
  tree_blinded->GetBranch("mh"              )->SetAddress(&Tmh      );
  tree_blinded->GetBranch("limit"           )->SetAddress(&Tlimit   );
  tree_blinded->GetBranch("limitErr"        )->SetAddress(&TlimitErr);
  tree_blinded->GetBranch("quantileExpected")->SetAddress(&TquantExp);
  TGraph* ExpLimitm2 = getLimitGraph(tree_blinded,0.025);
  TGraph* ExpLimitm1 = getLimitGraph(tree_blinded,0.160);
  TGraph* ExpLimit   = getLimitGraph(tree_blinded,0.500);
  TGraph* ExpLimitp1 = getLimitGraph(tree_blinded,0.840);
  TGraph* ExpLimitp2 = getLimitGraph(tree_blinded,0.975);
  file_blinded->Close(); 
  TTree* tree = (TTree*)file->Get("limit");
  tree->GetBranch("mh"              )->SetAddress(&Tmh      );
  tree->GetBranch("limit"           )->SetAddress(&Tlimit   );
  tree->GetBranch("limitErr"        )->SetAddress(&TlimitErr);
  tree->GetBranch("quantileExpected")->SetAddress(&TquantExp);
  TGraph* ObsLimit   = getLimitGraph(tree,-1   ); 
  file->Close(); 

  FILE* pFileSStrenght = fopen((outputDir+"SignalStrenght").c_str(),"w");
  std::cout << "Printing Signal Strenght" << std::endl;
  for(int i=0;i<ExpLimit->GetN();i++){
     double M = ExpLimit->GetX()[i];
     std::cout << "Mass: " << M << "; ExpLimit: " << ExpLimit->Eval(M) << std::endl; 
     printf("$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ \\\\\\hline\n",M, ExpLimit->Eval(M), ExpLimitm1->Eval(M), ExpLimitp1->Eval(M), ExpLimitm2->Eval(M),  ExpLimitp2->Eval(M));
     fprintf(pFileSStrenght, "$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ & $%8.6E$ \\\\\\hline\n",M, ExpLimit->Eval(M), ExpLimitm1->Eval(M), ExpLimitp1->Eval(M), ExpLimitm2->Eval(M),  ExpLimitp2->Eval(M), ObsLimit->Eval(M));
    if(int(ExpLimit->GetX()[i])%50!=0)continue; //printf("%f ",ObsLimit->Eval(M));
  }printf("\n");
  fclose(pFileSStrenght); 
 

  //get the pValue
  inputs = inputs.ReplaceAll("/LimitTree", "/PValueTree");
  file = TFile::Open(inputs);
  
  printf("Looping on %s\n",inputs.Data());
  if(!file) return;
  if(file->IsZombie()) return;
  
  tree = (TTree*)file->Get("limit");
  
  tree->GetBranch("limit"           )->SetAddress(&Tlimit   );
  
  TGraph* pValue     = getLimitGraph(tree,-1);
  
  file->Close();

  
  //make TH Cross-sections
   string suffix = outputDir;
   TGraph* THXSec   = Hxswg::utils::getXSec(outputDir); 
   scaleGraph(THXSec, 1000);  //convert cross-section to fb
   double cprime=1.0; double  brnew=0.0;
   double XSecScaleFactor = 1.0;
   if(suffix.find("_cp")!=string::npos){
     sscanf(suffix.c_str()+suffix.find("_cp"), "_cp%lf_brn%lf", &cprime, &brnew);
     XSecScaleFactor = pow(cprime,2) * (1-brnew);
   }
  //XSecScaleFactor = 0.001; //pb to fb
  scaleGraph(THXSec, XSecScaleFactor);


  string prod = "pp_SM";
  if(outputDir.find("ggH")!=std::string::npos)prod="gg";
  if(outputDir.find("qqH")!=std::string::npos)prod="qq";
  if(outputDir.find("ppH")!=std::string::npos)prod="pp";

  
  strengthLimit = false;
  if(prod=="pp_SM")strengthLimit=true;
 
  //TGraph *XSecMELA = Hxswg::utils::getXSecMELA(cprime);

  //Hxswg::utils::multiplyGraph(   ObsLimit, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitm2, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitm1, XSecMELA);
  //Hxswg::utils::multiplyGraph(   ExpLimit, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitp1, XSecMELA);
  //Hxswg::utils::multiplyGraph( ExpLimitp2, XSecMELA);
 
  //Scale exclusion XSec in fb
  scaleGraph(ObsLimit  , 0.001); //pb to fb
  scaleGraph(ExpLimitm2, 0.001); //pb to fb
  scaleGraph(ExpLimitm1, 0.001); //pb to fb
  scaleGraph(ExpLimit  , 0.001); //pb to fb
  scaleGraph(ExpLimitp1, 0.001); //pb to fb
  scaleGraph(ExpLimitp2, 0.001); //pb to fb

  //scal eTH cross-section and limits according to scale factor 
  //this only apply to NarrowResonnance case
  if(strengthLimit){
     Hxswg::utils::divideGraph(ObsLimit   , THXSec);
     Hxswg::utils::divideGraph(ExpLimitm2 , THXSec);
     Hxswg::utils::divideGraph(ExpLimitm1 , THXSec);
     Hxswg::utils::divideGraph(ExpLimit   , THXSec);
     Hxswg::utils::divideGraph(ExpLimitp1 , THXSec);
     Hxswg::utils::divideGraph(ExpLimitp2 , THXSec);
     Hxswg::utils::divideGraph(THXSec     , THXSec);
  }


  //limits in terms of signal strength
  TCanvas* c = new TCanvas("c", "c",800,800);
  c->SetGridx();
  c->SetGridy();
  TH1F* framework = new TH1F("Graph","Graph",1,strengthLimit?199:199,2500); //3000);
  framework->SetStats(false);
  framework->SetTitle("");
  framework->GetXaxis()->SetTitle("M_{H} [GeV]");
  framework->GetYaxis()->SetTitleOffset(1.70);
  if(strengthLimit){
  framework->GetYaxis()->SetTitle("#mu = #sigma_{95%} / #sigma_{th}");
  framework->GetYaxis()->SetRangeUser(1E-4,1E3);
  c->SetLogy(true);
  }else{
  framework->GetYaxis()->SetTitle((string("#sigma_{95%} (") + prod +" #rightarrow H #rightarrow ZZ) (pb)").c_str());
  framework->GetYaxis()->SetRangeUser(1E-3,1E3);
  c->SetLogy(true);
  }
  framework->GetXaxis()->SetLabelOffset(0.007);
  framework->GetXaxis()->SetLabelSize(0.03);
  framework->GetXaxis()->SetTitleOffset(1.0);
  framework->GetXaxis()->SetTitleFont(42);
  framework->GetXaxis()->SetTitleSize(0.035);
  framework->GetYaxis()->SetLabelFont(42);
  framework->GetYaxis()->SetLabelOffset(0.007);
  framework->GetYaxis()->SetLabelSize(0.03);
  framework->GetYaxis()->SetTitleOffset(1.3);
  framework->GetYaxis()->SetTitleFont(42);
  framework->GetYaxis()->SetTitleSize(0.035);
  framework->Draw();

  
  TGraph* TGObsLimit   = ObsLimit;  TGObsLimit->SetLineWidth(2);
  TGraph* TGExpLimit   = ExpLimit;  TGExpLimit->SetLineWidth(2); TGExpLimit->SetLineStyle(2);
  TCutG* TGExpLimit1S  = GetErrorBand("1S", ExpLimitm1, ExpLimitp1);  
  TCutG* TGExpLimit2S  = GetErrorBand("2S", ExpLimitm2, ExpLimitp2);  TGExpLimit2S->SetFillColor(5);
  THXSec->SetLineWidth(2); THXSec->SetLineStyle(1); THXSec->SetLineColor(4);

  TGExpLimit->SetLineColor(1);  TGExpLimit->SetLineStyle(2);
  TGObsLimit->SetLineWidth(2);  TGObsLimit->SetMarkerStyle(20);
  TGExpLimit2S->Draw("fc same");
  TGExpLimit1S->Draw("fc same");
  if(!blind) TGObsLimit->Draw("same P");
  TGExpLimit->Draw("same c");

  
  /*if(strengthLimit){
     TLine* SMLine = new TLine(framework->GetXaxis()->GetXmin(),1.0,framework->GetXaxis()->GetXmax(),1.0);
     SMLine->SetLineWidth(2); SMLine->SetLineStyle(1); SMLine->SetLineColor(4);      
     SMLine->Draw("same C");
  }else{
     THXSec->Draw("same C");
  }*/

  utils::root::DrawPreliminary(luminosity, energy, c);

  
  TLegend* LEG = new TLegend(0.55,0.75,0.85,0.95);
  LEG->SetHeader("");
  LEG->SetFillColor(0);
  LEG->SetFillStyle(0);
  LEG->SetTextFont(42);
  LEG->SetBorderSize(0);
  //LEG->AddEntry(THXSec  , "Th prediction"  ,"L");
  LEG->AddEntry(TGExpLimit  , "median expected"  ,"L");
  LEG->AddEntry(TGExpLimit1S  , "expected #pm 1#sigma"  ,"F");
  LEG->AddEntry(TGExpLimit2S  , "expected #pm 2#sigma"  ,"F");
  if(!blind) LEG->AddEntry(TGObsLimit  , "observed"  ,"LP");
  LEG->Draw();
  c->RedrawAxis();
  c->SaveAs((outputDir+"Limit.png").c_str());
  c->SaveAs((outputDir+"Limit.C").c_str());
  c->SaveAs((outputDir+"Limit.pdf").c_str()); 

  
  //save a summary of the limits
  FILE* pFileSum = fopen((outputDir+"LimitSummary").c_str(),"w");
  for(int i=0;i<TGExpLimit->GetN();i++){
     double M = ExpLimit->GetX()[i];
     fprintf(pFileSum, "$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ & $%8.6E$ & Th=$%8.6E$ & pValue=$%8.6E$\\\\\\hline\n",M, ExpLimit->Eval(M), ExpLimitm1->Eval(M), ExpLimitp1->Eval(M), ExpLimitm2->Eval(M),  ExpLimitp2->Eval(M), ObsLimit->Eval(M), (THXSec!=NULL)?THXSec->Eval(M):-1, pValue->Eval(M));
    if(int(ExpLimit->GetX()[i])%50!=0)continue; printf("%f ",ObsLimit->Eval(M));
  }printf("\n");
  fclose(pFileSum);

  pFileSum = fopen((outputDir+"LimitRange").c_str(),"w");
  fprintf(pFileSum, "EXPECTED LIMIT --> ");                   printLimits(pFileSum,TGExpLimit, TGExpLimit->GetX()[0], TGExpLimit->GetX()[TGExpLimit->GetN()-1]);
  if(!blind) fprintf(pFileSum, "OBSERVED LIMIT --> ");        printLimits(pFileSum,TGObsLimit, TGObsLimit->GetX()[0], TGObsLimit->GetX()[TGObsLimit->GetN()-1]);
  fprintf(pFileSum, "Exp Limits for Model are: ");              for(int i=0;i<TGExpLimit->GetN();i++){if(int(TGExpLimit->GetX()[i])%50==0) fprintf(pFileSum, "%f+-%f ",TGExpLimit->GetY()[i], (ExpLimitp1->GetY()[i]-ExpLimitm1->GetY()[i])/2.0);}fprintf(pFileSum,"\n");
  if(!blind) { fprintf(pFileSum, "Obs Limits for Model are: "); for(int i=0;i<TGObsLimit->GetN();i++){if(int(TGObsLimit->GetX()[i])%50==0) fprintf(pFileSum, "%f ",TGObsLimit->GetY()[i]);}fprintf(pFileSum,"\n"); }
  fclose(pFileSum); 
}
예제 #8
0
파일: Sparse_MC.C 프로젝트: musinsky/bordel
void AnalysisSparse(Bool_t save_output = kFALSE)
{
  gStyle->SetGridColor(kGray);
  //  TString tmpstr(fname);
  //  if (tmpstr.Contains("data")) {
  //    Printf("!!! Real Data !!!");
  //    mc = kFALSE;
  //  }
  TString gtitle = Form("Monte Carlo, %s", graph_name.Data());
  grapht = graph_name.Data();
  Double_t grx[999], gry[999], gry2[999], gry3[999], gry4[999],
    gry_eff[999], gry_fix[999], grxE[999];
  Double_t gry22[999], gry22E[999], grx22E[999];
  Double_t gry_true[999], gry_true_eff[999], gry_true_effE[999];
  TH1::AddDirectory(kFALSE);
  TFile::SetCacheFileDir(gSystem->HomeDirectory());
  TFile *f = TFile::Open(fname.Data(), "CACHEREAD");
  if (!f) return;
  TList *l; f->GetObject(lname.Data(), l);
  if (!l) return;
  Int_t bf[999], bl[999];
  Int_t nn = FindExactRange(((THnSparse *)(l->FindObject(s1name.Data())))->
                            Projection(1), del_step, bf, bl);
  //  Int_t nn = FindRange5(bf, bl);
  Bool_t binhaluska = kFALSE;
  if (binAnders) {
    nn = 8;
    bf[0] = 6;bf[1] =  9;bf[2] = 11;bf[3] = 16;bf[4] = 21;bf[5] = 26;
    bl[0] = 8;bl[1] = 10;bl[2] = 15;bl[3] = 20;bl[4] = 25;bl[5] = 30;

    bf[6] = 31;bf[7] = 41;
    bl[6] = 40;bl[7] = 50;
  }
  Printf("number of intervals = %d =>", nn);

  Int_t count = 0;
  Double_t ptmean = 0, value = 0;
  Int_t fitStatus = -1;
  gStyle->SetOptStat(0);
  TCanvas *c = new TCanvas("c", "Signal & Background");
  c->Divide(5, 5); c->Modified(); c->Draw();
  TCanvas *c2 = (TCanvas *)c->DrawClone("c2");
  c2->SetTitle("Phi mesons (raw)"); c2->Modified(); c2->Draw();
  TCanvas *c3, *c4;
  if (mc) {
    c3 = (TCanvas *)c->DrawClone("c3");
    c3->SetTitle("Phi mesons (gen)"); c3->Modified(); c3->Draw();
    c4 = (TCanvas *)c->DrawClone("c4");
    c4->SetTitle("Phi mesons (true)"); c4->Modified(); c4->Draw();
  }

  for (Int_t i = 0; i < nn; i++) {
    c->cd(count + 1)->SetGrid();
    h1 = (TH1D *)PullHisto(l, s1name.Data(), bf[i], bl[i], ptmean);
    h1->SetLineColor(kRed);
    h1->GetXaxis()->SetTitle("inv. mass, GeV/c^2");
    h1->Draw("hist");

    h3_p = (TH1D *)PullHisto(l, s3name_p.Data(), bf[i], bl[i], ptmean);
    h3_m = (TH1D *)PullHisto(l, s3name_m.Data(), bf[i], bl[i], ptmean);
    // !!!!!!!!!!!!!!!!!!!!!!!!
    if (count==0) h3_p = h1;
    // !!!!!!!!!!!!!!!!!!!!!!!!
    else {
      h3_p->Add(h3_m);
      //      h3_p->Add((TH1D *)PullHisto(l, smix.Data(), bf[i], bl[i], ptmean));
      //      h3_p->Add((TH1D *)PullHisto(l, smixpp.Data(), bf[i], bl[i], ptmean));
      //      h3_p->Add((TH1D *)PullHisto(l, smixmm.Data(), bf[i], bl[i], ptmean));
      Norm(h1, h3_p, norm[0], norm[1]);
    }
    h3_p->SetLineColor(kBlue);
    h3_p->Draw("hist, same");

    if (mc) {
      c3->cd(count + 1)->SetGrid();
      Printf("%s", s1namegen.Data());
      hg = (TH1D *)PullHisto(l, s1namegen.Data(), bf[i], bl[i], ptmean);
      hg->SetLineColor(kMagenta);
      hg->GetXaxis()->SetTitle("inv. mass, GeV/c^2");
      hg->Draw("hist");
      c4->cd(count + 1)->SetGrid();
      ht = (TH1D *)PullHisto(l, s1nametrue.Data(), bf[i], bl[i], ptmean);
      ht->SetLineColor(kMagenta-5);
      ht->GetXaxis()->SetTitle("inv. mass, GeV/c^2");
      ht->Draw("hist");
    }
    c2->cd(count + 1)->SetGrid();
    TH1 *hh = (TH1 *)h1->Clone("hh");
    hh->SetLineColor(kRed+1);
    hh->Add(h3_p, -1);
    /// !!!!!!!!!!!!!!!!!!!!!!
    //////////    if ((ilist == 3) && (count < 2)) hh->Reset();
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    hh->Draw("hist");

    // !!!!!!!!!!!!!!!!!!
    ff->SetParameters(0.1, 1.02, 0.004, -25000., 0., 0., 0.);
    ff->SetLineColor(hh->GetLineColor());
    ff->SetLineWidth(1);
    //    ff->SetLineStyle(kDashed);
    // where fit
    Double_t fmin = 1.02-2*0.004;
    Double_t fmax = 1.02+2*0.004;
    //    Double_t fmin = 0.995;
    //    Double_t fmax = 1.185;
    // !!!!!!!!!!!!!!!!!!
    Bool_t hisfun = kFALSE; // kFALSE = integral from function
    Double_t   hisfun_k = 1.0/hh->GetBinWidth(10);
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if (binhaluska)
      if (i > 9) hisfun_k = 0.5/hh->GetBinWidth(10);
    Printf("======= %f", hisfun_k);
    // !!!!!!!!!!!!!!!!!!
    // wehere integral (his or fun)
    Double_t fmini = 1.02-2*0.004;
    Double_t fmaxi = 1.02+2*0.004;
    hh->Fit(ff, "Q", "", fmin, fmax);
    hh->Fit(ff, "Q", "", fmin, fmax);
    fitStatus = hh->Fit(ff, "Q", "", fmin, fmax);
    TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax);
    pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4),
                       ff->GetParameter(5), ff->GetParameter(6));
    pp3->SetLineWidth(1);
    pp3->SetLineColor(h3_p->GetLineColor());
    pp3->Draw("same");
    // ff->SetRange(fmin, fmax);
    // ff->DrawCopy("same");

    value              = hh->Integral(hh->FindBin(fmini), hh->FindBin(fmaxi));
    if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k -
                   pp3->Integral(fmini, fmaxi)*hisfun_k;
    if (value < 0) value = 0;

    if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) {
      printf(" SKIP Data");
      value = 0;
    }
    grx[count] = ptmean;
    if (binhaluska) {
      if (count < 10) grxE[count] = 0.25; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      else            grxE[count] = 0.50; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
    else
      //      grxE[count] = (1.30-1.10)/2.0; // !!!!!!!!!!!!!!!!!!!!!!!!!!
      grxE[count] = 0.05;
    gry[count] = value;

    Double_t tmp1 = h1->Integral(h1->FindBin(fmini), h1->FindBin(fmaxi));
    Double_t tmp2 = h3_p->Integral(h3_p->FindBin(fmini), h3_p->FindBin(fmaxi));
    Double_t tmp_sg = tmp1 - tmp2;
    Double_t tmp_bg = tmp2;

    // if ((tmp_sg <= -tmp_bg) || (tmp_bg < 33.0)) {
    //   gry3[count] = 0.0;
    //   gry4[count] = 0.0;
    // }
    // else {
    gry3[count] = tmp_sg/tmp_bg;
    gry4[count] = tmp_sg/TMath::Sqrt(tmp_sg + tmp_bg);
    // }

    //    Printf("%4.2f, %10f, %10f, %10f", ptmean, tmp1, tmp2, gry3[count]);


    if (mc) {
      c3->cd(count + 1);
      // !!!!!!!!!!!!!!!!
      ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.);
      hg->Fit(ff, "Q", "", fmin, fmax);
      hg->Fit(ff, "Q", "", fmin, fmax);
      fitStatus = hg->Fit(ff, "Q", "", fmin, fmax);
      /*      TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax);
              pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4),
              ff->GetParameter(5), ff->GetParameter(6));
              pp3->SetLineWidth(1);
              pp3->SetLineColor(h3_p->GetLineColor());
              pp3->Draw("same");
      */

      value              = hg->Integral(hg->FindBin(fmini), hg->FindBin(fmaxi));
      if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k;
      //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k;
      if (value <= 0) value = -1;

      if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) {
        printf(" SKIP MC");
        value = -1;
      }
      gry2[count]    = value;
      Double_t superfactor = CalculateFactor(l, 0.1);
      if (useCF) {
        gry22E[i] = TMath::Sqrt(gry2[i])*superfactor;
        //        gry22E[i] = 0.0001;
        gry22[i]  = gry2[i]*superfactor;
        grx22E[i] = 0.05;
      }
      gry_eff[count] = gry[count]/gry2[count];

      c4->cd(count + 1);
      // !!!!!!!!!!!!!!!!
      ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.);
      ht->Fit(ff, "Q", "", fmin, fmax);
      ht->Fit(ff, "Q", "", fmin, fmax);
      fitStatus = ht->Fit(ff, "Q", "", fmin, fmax);
      /*      TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax);
              pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4),
              ff->GetParameter(5), ff->GetParameter(6));
              pp3->SetLineWidth(1);
              pp3->SetLineColor(h3_p->GetLineColor());
              pp3->Draw("same");
      */

      value              = ht->Integral(ht->FindBin(fmini), ht->FindBin(fmaxi));
      if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k;
      //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k;
      if (value <= 0) value = -1;

      if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) {
        printf(" SKIP true");
        value = -1;
      }
      gry_true[count]     = value;
      gry_true_eff[count] = gry_true[count]/gry2[count];
      // Propagation of uncertainty (A/B)
      Double_t AAA  = gry_true[count];
      Double_t AAAE = TMath::Sqrt(AAA);
      Double_t BBB  = gry2[count];
      Double_t BBBE = TMath::Sqrt(BBB);
      Double_t EEE  = TMath::Sqrt((AAAE/AAA)*(AAAE/AAA)+(BBBE/BBB)*(BBBE/BBB));
      EEE = EEE*gry_true_eff[count];
      gry_true_effE[count] = EEE;
    }

    Printf("=> %6.4f", ptmean);
    count++;
  }

  new TCanvas();
  TGraph *gr = new TGraph(count, grx, gry);
  gr->SetMarkerStyle(8);
  gr->SetMarkerColor(hh->GetLineColor());
  gr->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr->SetTitle(Form("raw phi, %s", gtitle.Data()));
  gr->Draw("AP");

  cc3 = new TCanvas();
  TGraph *gr3 = new TGraph(count, grx, gry3);
  gr3->SetMarkerStyle(22);
  gr3->SetMarkerColor(kBlue+1);
  gr3->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr3->SetTitle(Form("SIG / BKG, %s", gtitle.Data()));
  gr3->SetMinimum(0);
  gr3->Draw("AP");

  cc4 = new TCanvas();
  TGraph *gr4 = new TGraph(count, grx, gry4);
  gr4->SetMarkerStyle(23);
  gr4->SetMarkerColor(kBlue-1);
  gr4->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr4->SetTitle(Form("Significance, %s", gtitle.Data()));
  gr4->SetMinimum(0);
  gr4->Draw("AP");

  ccc = new TCanvas("ccc","ccc",0,0,900,300);
  ccc->Divide(2, 1, 0.001, 0.001);
  ccc->cd(1); gr3->Draw("AP");
  ccc->cd(2); gr4->Draw("AP");

  TString blabla = "mc";
  if (!mc) blabla = "data";
  // gr3->SaveAs(Form("SB_%s_%s.C", blabla.Data(), grapht.Data()));
  // gr4->SaveAs(Form("Sig_%s_%s.C", blabla.Data(), grapht.Data()));
  // ccc->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data()));
  // c->SaveAs(Form("%s_%s_0.eps", blabla.Data(), grapht.Data()));
  // c2->SaveAs(Form("%s_%s_1.eps", blabla.Data(), grapht.Data()));

  //  cc3->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data()));
  //  gr3->SaveAs(Form("sig_bck_%s_%s.C", blabla.Data(), grapht.Data()));

  if (mc) {
    new TCanvas();
    TGraph *gr2 = new TGraph(count, grx, gry2);
    gr2->SetMarkerStyle(8);
    gr2->SetMarkerColor(hg->GetLineColor());
    gr2->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr2->SetTitle(Form("gen phi, %s", gtitle.Data()));
    gr2->Draw("AP");

    new TCanvas();
    TGraphErrors *gr22 = new TGraphErrors(count, grx, gry22, grx22E, gry22E);
    gr22->SetMarkerStyle(8);
    gr22->SetMarkerColor(kCyan);
    gr22->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr22->SetTitle(Form("gen phi, %s", gtitle.Data()));
    gr22->Draw("AP");


    c = new TCanvas();
    c->SetGrid();
    TGraph *gr_e = new TGraph(count, grx, gry_eff);
    gr_e->SetMarkerStyle(22);
    gr_e->SetMarkerColor(kBlack);
    gr_e->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr_e->SetTitle(Form("efficiency (raw), %s", grapht.Data()));
    gr_e->Draw("AP");
    Printf("Save as '\033[1meffi_raw_%s\033[0m' file", grapht.Data());
    for (Int_t i = 0; i < gr_e->GetN(); i++)
      Printf("%f %f", gr_e->GetX()[i], gr_e->GetY()[i]);

    cvb = new TCanvas();
    cvb->cd();
    TGraph *gr_true = new TGraph(count, grx, gry_true);
    gr_true->SetMarkerStyle(8);
    gr_true->SetMarkerColor(ht->GetLineColor());
    gr_true->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr_true->SetTitle(Form("true phi, %s", gtitle.Data()));
    gr_true->Draw("AP");
    c = new TCanvas();
    c->cd();
    c->SetGrid();
    TGraphErrors *gr_true_eff = new TGraphErrors(count, grx, gry_true_eff,
                                                 grxE, gry_true_effE);
    gr_true_eff->SetMarkerStyle(20);
    //    gr_true_eff->SetMarkerSize(0.75);
    gr_true_eff->SetMarkerColor(kBlack);
    gr_true_eff->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr_true_eff->SetTitle(Form("efficiency (true), %s", grapht.Data()));
    gr_true_eff->Draw("AEP");
    m_gr->Add(gr_true_eff);
    Printf("Save as '\033[1meffi_true_%s\033[0m' file", grapht.Data());
    TString tout;
    Double_t oux, ouy, ouxe, ouye;
    for (Int_t i = 0; i < gr_true_eff->GetN(); i++) {
      oux = gr_true_eff->GetX()[i];
      ouy = gr_true_eff->GetY()[i];
      ouy = MinusCheck(ouy);
      ouxe = gr_true_eff->GetErrorX(i);
      ouye = gr_true_eff->GetErrorY(i);
      ouye = NanCheck(ouye);
      Printf("%f %f %f %f", gr_true_eff->GetX()[i], gr_true_eff->GetY()[i],
             gr_true_eff->GetErrorX(i), gr_true_eff->GetErrorY(i));
      if (!save_output) continue;
      gSystem->mkdir(dir_prefix.Data());
      tout = Form("%f %f %f %f", oux, ouy, ouxe, ouye);
      if (i == 0)
        tout = Form("Printf(\"%s\"); > %s/effi_%s", tout.Data(),
                    dir_prefix.Data(), grapht.Data());
      else
        tout = Form("Printf(\"%s\"); >> %s/effi_%s", tout.Data(),
                    dir_prefix.Data(), grapht.Data());
      //      Printf(":::::: %s", tout.Data());
      gROOT->ProcessLine(tout.Data());
    }
    // ------------------
    c = new TCanvas("cfinal", "mc_effi", 1200, 450);
    c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw();
    c->cd(1);
    gr_true->SetMinimum(0);
    gr_true->SetTitle(Form("phi (true & raw), %s", gtitle.Data()));
    gr_true->SetMarkerColor(kGreen+1);
    gr_true->Draw("AP");
    gr->SetMarkerColor(kRed+1);
    gr->Draw("P");
    c->cd(2)->SetGrid();
    gr_true_eff->SetMinimum(0);
    gr_true_eff->SetTitle(Form("efficiency, %s", grapht.Data()));
    gr_true_eff->SetMarkerColor(kGreen+1);
    gr_true_eff->Draw("AP");
    gr_e->SetMarkerColor(kRed+1);
    gr_e->Draw("P");
    //    c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data()));
    return;
  }

  //  TGraph *geff = new TGraph(Form("effi_raw_%s", grapht.Data()));
  //  TGraph *geff = new TGraph(Form("effi_true_%s", grapht.Data()));
  //  TGraph *geff = new TGraph("effi_true_Phi2010_qualityonly");
  TGraph *geff = new TGraph("effi_true_PhiNsigma_qualityonly");
  if (geff->IsZombie()) return;
  geff->SetMarkerStyle(22);
  geff->SetMarkerColor(kBlack);
  geff->GetXaxis()->SetTitle("p_{t}, GeV/c");
  geff->SetTitle(Form("efficiency, %s", grapht.Data()));
  c = new TCanvas();
  c->SetGrid();
  geff->Draw("AP");
  Double_t tpcsigma = 9999.9;
  if (ilist == 1) tpcsigma = 1.0;
  if (ilist == 2) tpcsigma = 1.5;
  if (ilist == 3) tpcsigma = 2.0;
  if (ilist == 4) tpcsigma = 2.5;
  if (ilist == 5) tpcsigma = 3.0;
  Double_t sss = TMath::Erf(tpcsigma/TMath::Sqrt(2.0));
  if (noSigma) sss = 1.0;
  Printf("sigma = %10f", sss);

  // for (Int_t i = 0; i < count; i++)
  //   geff->GetY()[i] = (sss*sss)/(geff->GetY()[i]);
  // geff->SetMaximum(1.0);
  // geff->Draw("AP");

  for (Int_t i = 0; i < count; i++) {
    Double_t deno = geff->Eval(grx[i])*sss*sss;
    if (deno < 0.00001) deno = 1;
    gry_fix[i] = gry[i]/deno;
  }
  new TCanvas;
  TGraph *gr_fix = new TGraph(count, grx, gry_fix);
  gr_fix->SetMarkerStyle(21);
  gr_fix->SetMarkerColor(hh->GetLineColor());
  gr_fix->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr_fix->SetTitle(Form("corrected phi * #sigma^{2}, %s", gtitle.Data()));
  if (noSigma)
    gr_fix->SetTitle(Form("corrected phi (no #sigma), %s", gtitle.Data()));
  gr_fix->Draw("AP");

  //---------------------
  c = new TCanvas("cfinald", "data_correct", 1200, 450);
  c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw();
  c->cd(1);
  gr->SetMinimum(0);
  gr->SetMarkerColor(kBlack);
  gr->Draw("AP");
  c->cd(2);
  gr_fix->SetMinimum(0);
  gr_fix->SetMarkerColor(kGreen+3);
  gr_fix->Draw("AP");
  TString bla9 = Form("qualityonly_PID2_%s", grapht.Data());
  if (noSigma) bla9 = Form("%s_noSig.C", bla9.Data());
  else         bla9 = Form("%s.C", bla9.Data());
  //  gr_fix->SaveAs(bla9.Data());
  //  TPad *cp = new TPad("cpf", "", 0.45,0.45,0.99,0.92);
  TPad *cp = new TPad("cpf", "", 0.60,0.55,0.99,0.93);
  cp->SetLogy(); cp->Draw(); cp->cd();
  TGraph *cloneg = ((TGraph *)gr_fix->Clone());
  cloneg->SetTitle(); cloneg->SetMarkerSize(0.8);
  cloneg->Draw("AP");
  //  c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data()));
  f->Close();
}
예제 #9
0
void pointsed(TString filename = "btagpatanalyzerpy.root", TString check="") {
	TString cmssw;
	// 167
	
	cmssw = "$3.1.0_pre9$";
	
	TFile *f = TFile::Open(filename);
/////////////////////////////////////////////////////////////////////////////////////////
	std::vector< TString > checks;
	checks.push_back("");
	checks.push_back("Corr30_");
	checks.push_back("Corr30t0_");
	checks.push_back("Corr30t1_");
	checks.push_back("Corr30t2_");
	checks.push_back("Corr30t0_nConstituent_");
	checks.push_back("Corr30t1_nConstituent_");
	checks.push_back("Corr30t2_nConstituent_");
	checks.push_back("Uncor10_");
	checks.push_back("Uncor10t0_");
	checks.push_back("Uncor10t1_");
	checks.push_back("Uncor10t2_");
	checks.push_back("Uncor10t0_nConstituent_");
	checks.push_back("Uncor10t1_nConstituent_");
	checks.push_back("Uncor10t2_nConstituent_");
/////////////////////////////////////////////////////////////////////////////////////////
	std::vector< TString > taggers;
	std::vector< TString > labeltag;
        std::vector< int> colorlines;
	taggers.push_back( "TC2" );colorlines.push_back( 1 );labeltag.push_back( "TCHE");
	taggers.push_back( "TC3" );colorlines.push_back( 2 );labeltag.push_back( "TCHP");
	taggers.push_back( "TP"  );colorlines.push_back( 3 );labeltag.push_back( "JP");
	taggers.push_back( "SSV" );colorlines.push_back( 4 );labeltag.push_back( "SSV");
	taggers.push_back( "CSV" );colorlines.push_back( 5 );labeltag.push_back( "CSV");
	taggers.push_back( "MSV" );colorlines.push_back( 6 );labeltag.push_back( "CSVMVAB");
	taggers.push_back( "SMT" );colorlines.push_back( 8 );labeltag.push_back( "SMT");
	taggers.push_back( "BTP" );colorlines.push_back( 9 );labeltag.push_back( "JBP");
	taggers.push_back( "SMTbyIP3d" );colorlines.push_back( 11 );labeltag.push_back( "SMTByIP3d");
	taggers.push_back( "SMTbyPt" );colorlines.push_back( 12 );labeltag.push_back( "SMTByPt");
	taggers.push_back( "SETbyIP3d" );colorlines.push_back( 13 );labeltag.push_back( "SETByIP3d");
	taggers.push_back( "SETbyPt" );colorlines.push_back( 14 );labeltag.push_back( "SETByPt");
//	taggers.push_back( "IPM" );colorlines.push_back( 11 );labeltag.push_back( "IPMVAB");
//	taggers.push_back( "SMNIPT" );colorlines.push_back( 12 );labeltag.push_back( "SMTNoIP");

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
//ed	for ( size_t ichks = 0; ichks < checks.size(); ++ichks ) {
//ed		TString check = checks[ichks];
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
        TString PerfTitle= check;
        if (check == "") PerfTitle="uncorr pt>30";
	if (check == "Corr30_") PerfTitle="pt>30";
	if (check == "Corr30t0_") PerfTitle="pt>30, #tracks > 0";
	if (check == "Corr30t1_") PerfTitle="pt>30, #tracks > 1";
	if (check == "Corr30t2_") PerfTitle="pt>30, #tracks > 2";
	if (check == "Corr30t0_nConstituent_") PerfTitle="pt>30, #tracks > 0 & nConstituents >1";
	if (check == "Corr30t1_nConstituent_") PerfTitle="pt>30, #tracks > 1 & nConstituents >1";
	if (check == "Corr30t2_nConstituent_") PerfTitle="pt>30, #tracks > 2 & nConstituents >1";
	if (check == "Uncor10_") PerfTitle="uncorr pt>10";
	if (check == "Uncor10t0_") PerfTitle="uncorr pt>10 #tracks > 0";
	if (check == "Uncor10t1_") PerfTitle="uncorr pt>10 #tracks > 1";
	if (check == "Uncor10t2_") PerfTitle="uncorr pt>10 #tracks > 2";
	if (check == "Uncor10t0_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 0 & nConstituents >1";
	if (check == "Uncor10t1_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 1 & nConstituents >1";
	if (check == "Uncor10t2_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 2 & nConstituents >1";

	std::vector< TString > discriminators;
        for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
  		discriminators.push_back( check+"disc"+taggers[itagger]+"_udsg" );
	}
//	discriminators.push_back( "discTC3_udsg" );
//	discriminators.push_back( "discTP_udsg" );

	TCanvas *cv = new TCanvas("cv","cv",900,900);
	TMultiGraph *mg =new TMultiGraph();
	TLegend *legend0 = new TLegend(0.68,0.12,0.88,0.32);
        // inverted axis
	TMultiGraph *mginv =new TMultiGraph();
	TLegend *legend1 = new TLegend(0.65,0.18,0.85,0.48);
	std::ofstream salida("BTagPATop3"+check+".txt");
	
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {

		TString tag    = check+"g"+taggers[itagger]+"_udsg";
		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag);

		
		TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]);
//		TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX());
		dgraph->Sort();
//		udsgvsdgraph->Sort();

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		g->SetLineColor(itagger+1);
                legend0 -> AddEntry(g,taggers[itagger],"l");
		mg->Add(g);

                //inverted axis
		TGraphErrors *ginv = new TGraphErrors(agraph->GetN(),agraph->GetX(),agraph->GetY(),agraph->GetEX(),agraph->GetEY());
		ginv->Sort();
		ginv->SetLineColor(colorlines[itagger]);
		ginv->SetMarkerStyle(8);
		ginv->SetMarkerColor(colorlines[itagger]);
                legend1 -> AddEntry(ginv,labeltag[itagger],"l");
		mginv->Add(ginv);

		std::cout << " Tagger: " << tag << std::endl;
		std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl;
		std::cout << " Medium(1%):  " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl;
		std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl;
                salida << " " << taggers[itagger] << endl;
	        salida << " #bin \t b-eff  \t err-beff \t  non-beff \t err-non-b"<< endl;
        	for ( size_t i=0;i< agraph->GetN();i++){ 
			salida	<< "  " << (i+1) << " \t "
				<< agraph->GetX()[i] <<" \t " 
				<< agraph->GetEX()[i]<<" \t "
				<< agraph->GetY()[i] <<" \t "
				<< agraph->GetEY()[i]
                       		<< " "<< endl;
		}

	}
//	cv->SetLogx();
	mg->Draw("ALP");
	mg->GetYaxis()->SetTitle("b-eff");
	mg->GetXaxis()->SetTitle("udsg-mistagging");
	legend0 -> Draw();
        cv-> SetGrid();
	cv-> Print ("BTagPATop"+check+".eps");
	cv-> Print ("BTagPATop"+check+".png");
	cv->cd(0);
	cv->SetLogx();
	mg->Draw("ALP");
	legend0 -> Draw();
	cv-> Print ("BTagPATop1"+check+".eps");
	cv-> Print ("BTagPATop1"+check+".png");
        //inverted axis
	TCanvas *cvinv = new TCanvas("cvinv","cvinv",700,700);
        cvinv->SetLogy(0);
	mginv->Draw("ALP");
	mginv->GetXaxis()->SetTitle("b-eff");
	mginv->GetYaxis()->SetTitle("udsg-mistagging");
	legend1 -> Draw();
        cvinv->SetGrid();
	cvinv-> Print ("BTagPATop2"+check+".eps");
	cvinv-> Print ("BTagPATop2"+check+".png");
	cvinv->cd(0);
//	cvinv->Update();
//	cvinv->SetLogx();
//	mginv->SetXmin(10^-4);
//      axis range using a histogram helper
    TH2D*hpx = new TH2D("hpx",PerfTitle,200,0.0,1.005,200,0.00002,1.05);
        hpx->SetStats(kFALSE);
		hpx->Draw();
	hpx->GetXaxis()->SetTitle("b-eff");
	hpx->GetYaxis()->SetTitle("udsg-mistagging");
	cvinv->SetLogy(1);
	mginv->Draw("AP");
	legend1 -> Draw();
	cvinv-> Print ("BTagPATop3"+check+".eps");
	cvinv-> Print ("BTagPATop3"+check+".png");
	//ed}
}
예제 #10
0
void LeptonPreselectionCMG( PreselType type, RooWorkspace * w ) {
	const Options & opt = Options::getInstance(); 
	if (type == ELE)
		cout << "Running Electron Preselection :" << endl;
	else if (type == MU)
		cout << "Running Muon Preselection :" << endl;
	else if (type == EMU)
		cout << "Running Electron-Muon Preselection() ..." << endl;
	else if (type == PHOT)
		cout << "Running Photon Preselection :" << endl;

	string systVar;
	try {
		systVar = opt.checkStringOption("SYSTEMATIC_VAR");
	} catch (const std::string & exc) {
		cout << exc << endl;
	}
	if (systVar == "NONE")
		systVar.clear();

#ifdef CMSSWENV
	JetCorrectionUncertainty jecUnc("Summer13_V4_MC_Uncertainty_AK5PFchs.txt");
#endif

	string inputDir = opt.checkStringOption("INPUT_DIR");
	string outputDir = opt.checkStringOption("OUTPUT_DIR");
	string sampleName = opt.checkStringOption("SAMPLE_NAME");
	string inputFile = inputDir + '/' + sampleName + ".root";
	cout << "\tInput file: " << inputFile << endl;

	bool isSignal = opt.checkBoolOption("SIGNAL");
	TGraph * higgsW = 0;
	TGraph * higgsI = 0;
	if (isSignal) {
		double higgsM = opt.checkDoubleOption("HIGGS_MASS");
		if (higgsM >= 400) {
			string dirName = "H" + double2string(higgsM);
			bool isVBF = opt.checkBoolOption("VBF");
			string lshapeHistName = "cps";
			string intHistName = "nominal";
			
			if (systVar == "LSHAPE_UP") {
				intHistName = "up";
			} else if (systVar == "LSHAPE_DOWN") {
				intHistName = "down";
			}

			if (isVBF) {
				TFile weightFile("VBF_LineShapes.root");
				higgsW = (TGraph *) ( (TDirectory *) weightFile.Get(dirName.c_str()))->Get( lshapeHistName.c_str() )->Clone();

			} else {
				TFile weightFile("GG_LineShapes.root");
				higgsW = (TGraph *) ( (TDirectory *) weightFile.Get(dirName.c_str()))->Get( lshapeHistName.c_str() )->Clone();
				TFile interfFile("newwgts_interf.root");
				higgsI = (TGraph *) ( (TDirectory *) interfFile.Get(dirName.c_str()))->Get( intHistName.c_str() )->Clone();
			}
		}
	}

	TFile * file = new TFile( inputFile.c_str() );
	if (!file->IsOpen())
		throw string("ERROR: Can't open the file: " + inputFile + "!");
	TDirectory * dir = (TDirectory *) file->Get("dataAnalyzer");
	TH1D * nEvHisto = (TH1D *) dir->Get("cutflow");
	TH1D * puHisto = (TH1D *) dir->Get("pileup");
	TTree * tree = ( TTree * ) dir->Get( "data" );
	Event ev( tree );
	const int * runP = ev.getSVA<int>("run"); 
	const int * lumiP = ev.getSVA<int>("lumi"); 
	const int * eventP = ev.getSVA<int>("event"); 
	const bool * trigBits = ev.getAVA<bool>("t_bits");
	const int * trigPres = ev.getAVA<int>("t_prescale");
	const float * metPtA = ev.getAVA<float>("met_pt");
	const float * metPhiA = ev.getAVA<float>("met_phi");
	const float * rhoP = ev.getSVA<float>("rho");
	const float * rho25P = ev.getSVA<float>("rho25");
	const int * nvtxP = ev.getSVA<int>("nvtx"); 
	const int * niP = ev.getSVA<int>("ngenITpu"); 
	
#ifdef PRINTEVENTS
	string eventFileName;
	if (type == ELE)
		eventFileName = "events_ele.txt";
	else if (type == MU)
		eventFileName = "events_mu.txt";
	else if (type == EMU)
		eventFileName = "events_emu.txt";

	EventPrinter evPrint(ev, type, eventFileName);
	evPrint.readInEvents("diff.txt");
	evPrint.printElectrons();
	evPrint.printMuons();
	evPrint.printZboson();
	evPrint.printJets();
	evPrint.printHeader();
#endif

	string outputFile = outputDir + '/' + sampleName;

	if (systVar.size())
		outputFile += ('_' + systVar);

	if (type == ELE)
		outputFile += "_elePresel.root";
	else if (type == MU)
		outputFile += "_muPresel.root";
	else if (type == EMU)
		outputFile += "_emuPresel.root";
	else if (type == PHOT)
		outputFile += "_phPresel.root";
	cout << "\tOutput file: " << outputFile << endl;

	TFile * out = new TFile( outputFile.c_str(), "recreate" );
	TH1D * outNEvHisto = new TH1D("nevt", "nevt", 1, 0, 1);
	outNEvHisto->SetBinContent(1, nEvHisto->GetBinContent(1));
	outNEvHisto->Write("nevt");

	TH1D * outPuHisto = new TH1D( *puHisto );
	outPuHisto->Write("pileup");

	std::vector< std::tuple<std::string, std::string> > eleVars;
	eleVars.push_back( std::make_tuple("ln_px", "F") );
	eleVars.push_back( std::make_tuple("ln_py", "F") );
	eleVars.push_back( std::make_tuple("ln_pz", "F") );
	eleVars.push_back( std::make_tuple("ln_en", "F") );
	eleVars.push_back( std::make_tuple("ln_idbits", "I") );
	eleVars.push_back( std::make_tuple("ln_d0", "F") );
	eleVars.push_back( std::make_tuple("ln_dZ", "F") );
	eleVars.push_back( std::make_tuple("ln_nhIso03", "F") );
	eleVars.push_back( std::make_tuple("ln_gIso03", "F") );
	eleVars.push_back( std::make_tuple("ln_chIso03", "F") );
	eleVars.push_back( std::make_tuple("ln_trkLostInnerHits", "F") );

	std::vector< std::tuple<std::string, std::string> > addEleVars;
	addEleVars.push_back( std::make_tuple("egn_sceta", "F") );
	addEleVars.push_back( std::make_tuple("egn_detain", "F") );
	addEleVars.push_back( std::make_tuple("egn_dphiin", "F") );
	addEleVars.push_back( std::make_tuple("egn_sihih", "F") );
	addEleVars.push_back( std::make_tuple("egn_hoe", "F") );
	addEleVars.push_back( std::make_tuple("egn_ooemoop", "F") );
	addEleVars.push_back( std::make_tuple("egn_isConv", "B") );

	std::vector< std::tuple<std::string, std::string> > muVars;
	muVars.push_back( std::make_tuple("ln_px", "F") );
	muVars.push_back( std::make_tuple("ln_py", "F") );
	muVars.push_back( std::make_tuple("ln_pz", "F") );
	muVars.push_back( std::make_tuple("ln_en", "F") );
	muVars.push_back( std::make_tuple("ln_idbits", "I") );
	muVars.push_back( std::make_tuple("ln_d0", "F") );
	muVars.push_back( std::make_tuple("ln_dZ", "F") );
	muVars.push_back( std::make_tuple("ln_nhIso04", "F") );
	muVars.push_back( std::make_tuple("ln_gIso04", "F") );
	muVars.push_back( std::make_tuple("ln_chIso04", "F") );
	muVars.push_back( std::make_tuple("ln_puchIso04", "F") );
	muVars.push_back( std::make_tuple("ln_trkchi2", "F") );
	muVars.push_back( std::make_tuple("ln_trkValidPixelHits", "F") );

	std::vector< std::tuple<std::string, std::string> > addMuVars;
	addMuVars.push_back( std::make_tuple("mn_trkLayersWithMeasurement", "F") );
	addMuVars.push_back( std::make_tuple("mn_pixelLayersWithMeasurement", "F") );
	addMuVars.push_back( std::make_tuple("mn_innerTrackChi2", "F") );
	addMuVars.push_back( std::make_tuple("mn_validMuonHits", "F") );
	addMuVars.push_back( std::make_tuple("mn_nMatchedStations", "F") );

	unsigned run;
	unsigned lumi;
	unsigned event;
	double pfmet;
	int nele;
	int nmu;
	int nsoftmu;
	double l1pt;
	double l1eta;
	double l1phi;
	double l2pt;
	double l2eta;
	double l2phi;
	double zmass;
	double zpt;
	double zeta;
	double mt;
	int nsoftjet;
	int nhardjet;
	double maxJetBTag;
	double minDeltaPhiJetMet;
	double detajj;
	double mjj;
	int nvtx;
	int ni;
	int category;
	double weight;
	double hmass;
	double hweight;

	TTree * smallTree = new TTree("HZZ2l2nuAnalysis", "HZZ2l2nu Analysis Tree");
	smallTree->Branch( "Run", &run, "Run/i" );
	smallTree->Branch( "Lumi", &lumi, "Lumi/i" );
	smallTree->Branch( "Event", &event, "Event/i" );
	smallTree->Branch( "PFMET", &pfmet, "PFMET/D" );
	smallTree->Branch( "NELE", &nele, "NELE/I" );
	smallTree->Branch( "NMU", &nmu, "NMU/I" );
	smallTree->Branch( "NSOFTMU", &nsoftmu, "NSOFTMU/I" );
	smallTree->Branch( "L1PT", &l1pt, "L1PT/D" );
	smallTree->Branch( "L1ETA", &l1eta, "L1ETA/D" );
	smallTree->Branch( "L1PHI", &l1phi, "L1PHI/D" );
	smallTree->Branch( "L2PT", &l2pt, "L2PT/D" );
	smallTree->Branch( "L2ETA", &l2eta, "L2ETA/D" );
	smallTree->Branch( "L2PHI", &l2phi, "L2PHI/D" );
	smallTree->Branch( "ZMASS", &zmass, "ZMASS/D" );
	smallTree->Branch( "ZPT", &zpt, "ZPT/D" );
	smallTree->Branch( "ZETA", &zeta, "ZETA/D" );
	smallTree->Branch( "MT", &mt, "MT/D" );
	smallTree->Branch( "NSOFTJET", &nsoftjet, "NSOFTJET/I" );
	smallTree->Branch( "NHARDJET", &nhardjet, "NHARDJET/I" );
	smallTree->Branch( "MAXJETBTAG", &maxJetBTag, "MAXJETBTAG/D" );
	smallTree->Branch( "MINDPJETMET", &minDeltaPhiJetMet, "MINDPJETMET/D" );
	smallTree->Branch( "DETAJJ", &detajj, "DETAJJ/D" );
	smallTree->Branch( "MJJ", &mjj, "MJJ/D" );
	smallTree->Branch( "NVTX", &nvtx, "NVTX/I" );
	smallTree->Branch( "nInter" , &ni, "nInter/I" );
	smallTree->Branch( "CATEGORY", &category, "CATEGORY/I" );
	smallTree->Branch( "Weight" , &weight, "Weight/D" );
	smallTree->Branch( "HMASS", &hmass, "HMASS/D" );
	smallTree->Branch( "HWEIGHT", &hweight, "HWEIGHT/D" );

	bool isData = opt.checkBoolOption("DATA");

	unsigned long nentries = tree->GetEntries();

	RooDataSet * events = nullptr;

	PhotonPrescale photonPrescales;

	vector<int> thresholds;
	if (type == PHOT) {
		if (w == nullptr)
			throw string("ERROR: No mass peak pdf!");
		RooRealVar * zmass = w->var("mass");
		zmass->setRange(76.0, 106.0);
		RooAbsPdf * pdf = w->pdf("massPDF");
		events = pdf->generate(*zmass, nentries);

		photonPrescales.addTrigger("HLT_Photon36_R9Id90_HE10_Iso40_EBOnly", 36, 3, 7);
		photonPrescales.addTrigger("HLT_Photon50_R9Id90_HE10_Iso40_EBOnly", 50, 5, 8);
		photonPrescales.addTrigger("HLT_Photon75_R9Id90_HE10_Iso40_EBOnly", 75, 7, 9);
		photonPrescales.addTrigger("HLT_Photon90_R9Id90_HE10_Iso40_EBOnly", 90, 10, 10);
	}

	TH1D ptSpectrum("ptSpectrum", "ptSpectrum", 200, 55, 755);
	ptSpectrum.Sumw2();

	unordered_set<EventAdr> eventsSet;
	for ( unsigned long iEvent = 0; iEvent < nentries; iEvent++ ) {
//		if (iEvent < 6060000)
//			continue;

		if ( iEvent % 10000 == 0) {
			cout << string(40, '\b');
			cout << setw(10) << iEvent << " / " << setw(10) << nentries << " done ..." << std::flush;
		}

		tree->GetEntry( iEvent );

		run = -999;
		lumi = -999;
		event = -999;
		pfmet = -999;
		nele = -999;
		nmu = -999;
		nsoftmu = -999;
		l1pt = -999;
		l1eta = -999;
		l1phi = -999;
		l2pt = -999;
		l2eta = -999;
		l2phi = -999;
		zmass = -999;
		zpt = -999;
		zeta = -999;
		mt = -999;
		nsoftjet = -999;
		nhardjet = -999;
		maxJetBTag = -999;
		minDeltaPhiJetMet = -999;
		detajj = -999;
		mjj = -999;
		nvtx = -999;
		ni = -999;
		weight = -999;
		category = -1;
		hmass = -999;
		hweight = -999;

		run = *runP;
		lumi = *lumiP;
		event = *eventP;

		EventAdr tmp(run, lumi, event);
		if (eventsSet.find( tmp ) != eventsSet.end()) {
			continue;
		}
		eventsSet.insert( tmp );

		if (type == ELE && isData) {
			if (trigBits[0] != 1 || trigPres[0] != 1)
				continue;
		}

		if (type == MU && isData) {
			if ( (trigBits[2] != 1 || trigPres[2] != 1)
				&& (trigBits[3] != 1 || trigPres[3] != 1)
				&& (trigBits[6] != 1 || trigPres[6] != 1)
			   )
				continue;
		}

		if (type == EMU && isData) {
			if ( (trigBits[4] != 1 || trigPres[4] != 1)
				&& (trigBits[5] != 1 || trigPres[5] != 1)
			   )
				continue;
		}

		vector<Electron> electrons = buildLeptonCollection<Electron, 11>(ev, eleVars, addEleVars);
		vector<Muon> muons = buildLeptonCollection<Muon, 13>(ev, muVars, addMuVars);

		float rho = *rhoP;
		float rho25 = *rho25P;

		vector<Electron> looseElectrons;
		vector<Electron> selectedElectrons;
		for (unsigned j = 0; j < electrons.size(); ++j) {
			try {
			TLorentzVector lv = electrons[j].lorentzVector();
			if (
					lv.Pt() > 10 &&
					fabs(lv.Eta()) < 2.5 &&
					!electrons[j].isInCrack() &&
					electrons[j].passesVetoID() &&
					electrons[j].isPFIsolatedLoose(rho25)
				) {
				looseElectrons.push_back(electrons[j]);
			}

			if (
					lv.Pt() > 20 &&
					fabs(lv.Eta()) < 2.5 &&
					!electrons[j].isInCrack() &&
					electrons[j].passesMediumID() &&
					electrons[j].isPFIsolatedMedium(rho25)
				) {
				selectedElectrons.push_back(electrons[j]);
			}
			} catch (const string & exc) {
				cout << exc << endl;
				cout << "run = " << run << endl;
				cout << "lumi = " << lumi << endl;
				cout << "event = " << event << endl;
			}
		}

		vector<Muon> looseMuons;
		vector<Muon> softMuons;
		vector<Muon> selectedMuons;
		for (unsigned j = 0; j < muons.size(); ++j) {
			TLorentzVector lv = muons[j].lorentzVector();
			if (
					lv.Pt() > 10 &&
					fabs(lv.Eta()) < 2.4 &&
					muons[j].isLooseMuon() &&
					muons[j].isPFIsolatedLoose()
				) {
				looseMuons.push_back(muons[j]);
			} else if (
					lv.Pt() > 3 &&
					fabs(lv.Eta()) < 2.4 &&
					muons[j].isSoftMuon()
				) {
				softMuons.push_back(muons[j]);
			}
			if (
					lv.Pt() > 20 &&
					fabs(lv.Eta()) < 2.4 &&
					muons[j].isTightMuon() &&
					muons[j].isPFIsolatedTight()
				) {
				selectedMuons.push_back(muons[j]);
			}
		}

		vector<Lepton> looseLeptons;
		for (unsigned i = 0; i < looseElectrons.size(); ++i)
			looseLeptons.push_back(looseElectrons[i]);
		for (unsigned i = 0; i < looseMuons.size(); ++i)
			looseLeptons.push_back(looseMuons[i]);
		for (unsigned i = 0; i < softMuons.size(); ++i)
			looseLeptons.push_back(softMuons[i]);

#ifdef PRINTEVENTS
		evPrint.setElectronCollection(selectedElectrons);
		evPrint.setMuonCollection(selectedMuons);
#endif

		vector<Photon> photons = selectPhotonsCMG( ev );
		vector<Photon> selectedPhotons;
		for (unsigned i = 0; i < photons.size(); ++i) {
			if (photons[i].isSelected(rho) && photons[i].lorentzVector().Pt() > 55)
				selectedPhotons.push_back( photons[i] );
		}

		if (type == PHOT) {
			vector<Electron> tmpElectrons;
			for (unsigned i = 0; i < selectedPhotons.size(); ++i) {
				TLorentzVector phVec = selectedPhotons[i].lorentzVector();
				for (unsigned j = 0; j < looseElectrons.size(); ++j) {
					TLorentzVector elVec = looseElectrons[j].lorentzVector();
					double dR = deltaR(phVec.Eta(), phVec.Phi(), elVec.Eta(), elVec.Phi());
					if ( dR > 0.05 )
						tmpElectrons.push_back( looseElectrons[j] );
				}
			}
			looseElectrons = tmpElectrons;
		}

		string leptonsType;
		Lepton * selectedLeptons[2] = {0};
		if (type == ELE) {
			if (selectedElectrons.size() < 2) {
				continue;
			} else {
				selectedLeptons[0] = &selectedElectrons[0];
				selectedLeptons[1] = &selectedElectrons[1];
			}
		} else if (type == MU) {
			if (selectedMuons.size() < 2) {
				continue;
			} else {
				selectedLeptons[0] = &selectedMuons[0];
				selectedLeptons[1] = &selectedMuons[1];
			}
		} else if (type == EMU) {
			if (selectedElectrons.size() < 1 || selectedMuons.size() < 1) {
				continue;
			} else {
				selectedLeptons[0] = &selectedElectrons[0];
				selectedLeptons[1] = &selectedMuons[0];
			}
		} else if (type == PHOT) {
			if (selectedPhotons.size() != 1) {
				continue;
			}
		}

		nele = looseElectrons.size();
		nmu = looseMuons.size();
		nsoftmu = softMuons.size();

		TLorentzVector Zcand;

		if (type == ELE || type == MU || type == EMU) {
			TLorentzVector lep1 = selectedLeptons[0]->lorentzVector();
			TLorentzVector lep2 = selectedLeptons[1]->lorentzVector();

			if (lep2.Pt() > lep1.Pt() && type != EMU) {
				TLorentzVector temp = lep1;
				lep1 = lep2;
				lep2 = temp;
			}

			l1pt = lep1.Pt();
			l1eta = lep1.Eta();
			l1phi = lep1.Phi();

			l2pt = lep2.Pt();
			l2eta = lep2.Eta();
			l2phi = lep2.Phi();

			Zcand = lep1 + lep2;
			zmass = Zcand.M();
		} else if (type == PHOT) {
			Zcand = selectedPhotons[0].lorentzVector();
			zmass = events->get(iEvent)->getRealValue("mass");
		}

		zpt = Zcand.Pt();
		zeta = Zcand.Eta();

		if (type == PHOT) {
			unsigned idx = photonPrescales.getIndex(zpt);
			if (trigBits[idx])
				weight = trigPres[idx];
			else
				continue;
			ptSpectrum.Fill(zpt, weight);
		}

		TLorentzVector met;
		met.SetPtEtaPhiM(metPtA[0], 0.0, metPhiA[0], 0.0);
		TLorentzVector clusteredFlux;

		unsigned mode = 0;
		if (systVar == "JES_UP")
			mode = 1;
		else if (systVar == "JES_DOWN")
			mode = 2;
		TLorentzVector jecCorr;

#ifdef CMSSWENV
		vector<Jet> jetsAll = selectJetsCMG( ev, looseLeptons, jecUnc, &jecCorr, mode );
#else
		vector<Jet> jetsAll = selectJetsCMG( ev, looseLeptons, &jecCorr, mode );
#endif

		met -= jecCorr;

		mode = 0;
		if (systVar == "JER_UP")
			mode = 1;
		else if (systVar == "JER_DOWN")
			mode = 2;
		TLorentzVector smearCorr = smearJets( jetsAll, mode );
		if (isData && smearCorr != TLorentzVector())
			throw std::string("Jet smearing corrections different from zero in DATA!");
		met -= smearCorr;

		vector<Jet> selectedJets;
		for (unsigned i = 0; i < jetsAll.size(); ++i) {
			if (
					jetsAll[i].lorentzVector().Pt() > 10
					&& fabs(jetsAll[i].lorentzVector().Eta()) < 4.7
					&& jetsAll[i].passesPUID() &&
					jetsAll[i].passesPFLooseID()
				)
				selectedJets.push_back( jetsAll[i] );
		}
		if (type == PHOT) {
			vector<Jet> tmpJets;
			for (unsigned i = 0; i < selectedPhotons.size(); ++i) {
				TLorentzVector phVec = selectedPhotons[i].lorentzVector();
				for (unsigned j = 0; j < selectedJets.size(); ++j) {
					TLorentzVector jVec = selectedJets[j].lorentzVector();
					double dR = deltaR(phVec.Eta(), phVec.Phi(), jVec.Eta(), jVec.Phi());
					if ( dR > 0.4 )
						tmpJets.push_back( selectedJets[j] );
				}
			}
			selectedJets = tmpJets;
		}

		if (systVar == "UMET_UP" || systVar == "UMET_DOWN") {
			for (unsigned i = 0; i < jetsAll.size(); ++i)
				clusteredFlux += jetsAll[i].lorentzVector();
			for (unsigned i = 0; i < looseElectrons.size(); ++i)
				clusteredFlux += looseElectrons[i].lorentzVector();
			for (unsigned i = 0; i < looseMuons.size(); ++i)
				clusteredFlux += looseMuons[i].lorentzVector();

			TLorentzVector unclusteredFlux = -(met + clusteredFlux);
			if (systVar == "UMET_UP")
				unclusteredFlux *= 1.1;
			else
				unclusteredFlux *= 0.9;
			met = -(clusteredFlux + unclusteredFlux);
		}

		if (systVar == "LES_UP" || systVar == "LES_DOWN") {
			TLorentzVector diff;
			double sign = 1.0;
			if (systVar == "LES_DOWN")
				sign = -1.0;
			for (unsigned i = 0; i < looseElectrons.size(); ++i) {
				TLorentzVector tempEle = looseElectrons[i].lorentzVector();
				if (looseElectrons[i].isEB())
					diff += sign * 0.02 * tempEle;
				else
					diff += sign * 0.05 * tempEle;
			}
			for (unsigned i = 0; i < looseMuons.size(); ++i)
				diff += sign * 0.01 * looseMuons[i].lorentzVector();

			met -= diff;
		}

		pfmet = met.Pt();

		double px = met.Px() + Zcand.Px();
		double py = met.Py() + Zcand.Py();
		double pt2 = px * px + py * py;
		double e = sqrt(zpt * zpt + zmass * zmass) + sqrt(pfmet * pfmet + zmass * zmass);
		double mt2 = e * e - pt2;
		mt = (mt2 > 0) ? sqrt(mt2) : 0;

		vector<Jet> hardjets;
		vector<Jet> softjets;
		maxJetBTag = -999;
		minDeltaPhiJetMet = 999;
		for ( unsigned j = 0; j < selectedJets.size(); ++j ) {
			TLorentzVector jet = selectedJets[j].lorentzVector();

			if ( jet.Pt() > 30 ) {
				hardjets.push_back( selectedJets[j] );
			}
			if ( jet.Pt() > 15 )
				softjets.push_back( selectedJets[j] );
		}
		nhardjet = hardjets.size();
		nsoftjet = softjets.size();
//		if ( type == PHOT && nsoftjet == 0 )
//			continue;

		if (nhardjet > 1) {
			sort(hardjets.begin(), hardjets.end(), [](const Jet & a, const Jet & b) {
					return a.lorentzVector().Pt() > b.lorentzVector().Pt();
				});
			TLorentzVector jet1 = hardjets[0].lorentzVector();
			TLorentzVector jet2 = hardjets[1].lorentzVector();
			const double maxEta = max( jet1.Eta(), jet2.Eta() );
			const double minEta = min( jet1.Eta(), jet2.Eta() );
			bool passCJV = true;
			for (unsigned j = 2; j < hardjets.size(); ++j) {
				double tmpEta = hardjets[j].lorentzVector().Eta();
				if ( tmpEta > minEta && tmpEta < maxEta )
					passCJV = false;
			}
			const double tmpDelEta = std::fabs(jet2.Eta() - jet1.Eta());
			TLorentzVector diJetSystem = jet1 + jet2;
			const double tmpMass = diJetSystem.M();
			if ( type == PHOT) {
				if (passCJV && tmpDelEta > 4.0 && tmpMass > 500 && zeta > minEta && maxEta > zeta) {
					detajj = tmpDelEta;
					mjj = tmpMass;
				}
			} else {
				if (passCJV && tmpDelEta > 4.0 && tmpMass > 500 && l1eta > minEta && l2eta > minEta && maxEta > l1eta && maxEta > l2eta) {
					detajj = tmpDelEta;
					mjj = tmpMass;
				}
			}
		}

		category = evCategory(nhardjet, nsoftjet, detajj, mjj, type == PHOT);

		minDeltaPhiJetMet = 10;
		for ( unsigned j = 0; j < hardjets.size(); ++j ) {
			TLorentzVector jet = hardjets[j].lorentzVector();
			if ( hardjets[j].getVarF("jn_jp") > maxJetBTag && fabs(jet.Eta()) < 2.5 )
				maxJetBTag = hardjets[j].getVarF("jn_jp");
			double tempDelPhiJetMet = deltaPhi(met.Phi(), jet.Phi());
			if ( tempDelPhiJetMet < minDeltaPhiJetMet )
				minDeltaPhiJetMet = tempDelPhiJetMet;
		}

		nvtx = *nvtxP;

		if (isData)
			ni = -1;
		else
			ni = *niP;

		if (isSignal) {
			const int nMC = ev.getSVV<int>("mcn");
			const int * mcID = ev.getAVA<int>("mc_id");
			int hIdx = 0;
			for (; hIdx < nMC; ++hIdx)
				if (fabs(mcID[hIdx]) == 25)
					break;
			if (hIdx == nMC)
				throw string("ERROR: Higgs not found in signal sample!");

			float Hpx = ev.getAVV<float>("mc_px", hIdx);
			float Hpy = ev.getAVV<float>("mc_py", hIdx);
			float Hpz = ev.getAVV<float>("mc_pz", hIdx);
			float Hen = ev.getAVV<float>("mc_en", hIdx);
			TLorentzVector higgs;
			higgs.SetPxPyPzE( Hpx, Hpy, Hpz, Hen );
			hmass = higgs.M();

			if (higgsW) {
				hweight = higgsW->Eval(hmass);
				if (higgsI)
					hweight *= higgsI->Eval(hmass);
			} else
				hweight = 1;
		}

		if ( opt.checkBoolOption("ADDITIONAL_LEPTON_VETO") && (type == ELE || type == MU || type == EMU) && ((nele + nmu + nsoftmu) > 2) )
			continue;
		if ( opt.checkBoolOption("ADDITIONAL_LEPTON_VETO") && (type == PHOT) && ((nele + nmu + nsoftmu) > 0) )
			continue;
		if ( opt.checkBoolOption("ZPT_CUT") && zpt < 55 )
			continue;
		// for different background estimation methods different window should be applied:
		// * sample for photons should have 76.0 < zmass < 106.0
		// * sample for non-resonant background should not have this cut applied
		if ( opt.checkBoolOption("TIGHT_ZMASS_CUT") && (type == ELE || type == MU) && (zmass < 76.0 || zmass > 106.0))
			continue;
		if ( opt.checkBoolOption("WIDE_ZMASS_CUT") && (type == ELE || type == MU) && (zmass < 76.0 || zmass > 106.0))
			continue;
		if ( opt.checkBoolOption("BTAG_CUT") && ( maxJetBTag > 0.264) )
			continue;
		if ( opt.checkBoolOption("DPHI_CUT") && ( minDeltaPhiJetMet < 0.5) )
			continue;


#ifdef PRINTEVENTS
		evPrint.setJetCollection(hardjets);
		evPrint.setMET(met);
		evPrint.setMT(mt);
		string channelType;
		if (type == ELE)
			channelType = "ee";
		else if (type == MU)
			channelType = "mumu";
		else if (type == EMU)
			channelType = "emu";
		if (category == 1)
			channelType += "eq0jets";
		else if (category == 2)
			channelType += "geq1jets";
		else
			channelType += "vbf";
		evPrint.setChannel(channelType);
		unsigned bits = 0;
		bits |= (0x7);
		bits |= ((zmass > 76.0 && zmass < 106.0) << 3);
		bits |= ((zpt > 55) << 4);
		bits |= (((nele + nmu + nsoftmu) == 2) << 5);
		bits |= ((maxJetBTag < 0.275) << 6);
		bits |= ((minDeltaPhiJetMet > 0.5) << 7);
		evPrint.setBits(bits);
		evPrint.print();
#endif
		
		smallTree->Fill();
	}
	cout << endl;
	
	TCanvas canv("canv", "canv", 800, 600);
	//effNum.Sumw2();
	//effDen.Sumw2();
	//effNum.Divide(&effDen);
	//effNum.Draw();
	canv.SetGridy();
	canv.SetGridx();
	//canv.SaveAs("triggEff.ps");
	//canv.Clear();
	ptSpectrum.SetMarkerStyle(20);
	ptSpectrum.SetMarkerSize(0.5);
	ptSpectrum.Draw("P0E");
	//ptSpectrum.Draw("COLZ");
	canv.SetLogy();
	canv.SaveAs("ptSpectrum.ps");

	delete file;
	smallTree->Write("", TObject::kOverwrite);
	delete smallTree;
	delete out;
}
예제 #11
0
int main(int argc, char** argv){
 
 ///=======================================================================================
 ///==== Calculate Scale from Data (minimization Chi2 and more)
 ///==== then perform toy MC to see the error on THAT scale with THAT statistics available
 ///======================================================================================= 

 if(argc != 2)
 {
  std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ;
  return 1;
 }
 
 // Parse the config file                                                                                                                                                          
 
 std::string fileName (argv[1]) ;
 boost::shared_ptr<edm::ProcessDesc> processDesc = edm::readConfigFile(fileName) ;
 boost::shared_ptr<edm::ParameterSet> parameterSet = processDesc->getProcessPSet () ;

 edm::ParameterSet subPSetInput = parameterSet->getParameter<edm::ParameterSet> ("inputTree") ;
 std::string treeNameDATA  = subPSetInput.getParameter<std::string> ("treeNameDATA") ;
 std::string inputFileDATA = subPSetInput.getParameter<std::string> ("inputFileDATA") ;
 treeNameMC = subPSetInput.getParameter<std::string> ("treeNameMC") ;
 std::string inputFileMC = subPSetInput.getParameter<std::string> ("inputFileMC") ;
  
 std::cout << ">>>>> InputDATA::treeName  " << treeNameDATA  << std::endl;  
 std::cout << ">>>>> InputDATA::inputFile  " << inputFileDATA  << std::endl;  
 std::cout << ">>>>> InputMC::treeName  " << treeNameMC  << std::endl;  
 std::cout << ">>>>> InputMC::inputFile  " << inputFileMC  << std::endl;  


 edm::ParameterSet subPSetOutput = parameterSet->getParameter<edm::ParameterSet> ("outputTree") ;
 std::string outputFile = subPSetOutput.getParameter<std::string> ("outputFile") ;

 std::cout << ">>>>> Output::outputFile  " << outputFile  << std::endl;  


 edm::ParameterSet subPSetOptions = parameterSet->getParameter<edm::ParameterSet> ("options") ;
 MinScan  = subPSetOptions.getParameter<double> ("MinScan") ;
 MaxScan  = subPSetOptions.getParameter<double> ("MaxScan") ;
 iNoSteps = subPSetOptions.getParameter<int>    ("iNoSteps") ;
  
 std::cout << ">>>>> Options::MinScan  " << MinScan  << std::endl;  
 std::cout << ">>>>> Options::MaxScan  " << MaxScan  << std::endl;  
 std::cout << ">>>>> Options::iNoSteps " << iNoSteps << std::endl;  

 MinScanRange  = subPSetOptions.getParameter<double> ("MinScanRange") ;
 MaxScanRange  = subPSetOptions.getParameter<double> ("MaxScanRange") ;
 
 std::cout << ">>>>> Options::MinScanRange  " << MinScanRange  << std::endl;  
 std::cout << ">>>>> Options::MaxScanRange  " << MaxScanRange  << std::endl;  

 minBINS = subPSetOptions.getParameter<double> ("minBINS") ;
 maxBINS = subPSetOptions.getParameter<double> ("maxBINS") ;
 numBINS = subPSetOptions.getParameter<int>    ("numBINS") ;

 std::cout << ">>>>> Options::numBINS   " << numBINS  << std::endl;  
 std::cout << ">>>>> Options::minBINS   " << minBINS  << std::endl;
 std::cout << ">>>>> Options::maxBINS   " << maxBINS  << std::endl;


 NBINTemplate = 10 * numBINS;
 MinTemplate = minBINS;
 MaxTemplate = maxBINS;
 Delta = (MaxTemplate - MinTemplate) / NBINTemplate;



 variableName = subPSetOptions.getParameter<std::string> ("variableName") ;
 std::cout << ">>>>> Options::variableName " << variableName.c_str() << std::endl;
 
 double minET = subPSetOptions.getParameter<double> ("minET") ;
 std::cout << ">>>>> Options::minET " << minET << std::endl;
 
 
 std::string temp_cut = subPSetOptions.getParameter<std::string> ("cut") ;
 std::cout << ">>>>> Options::cut " << temp_cut.c_str() << std::endl;
 AdditionalCut = Form("%s",temp_cut.c_str());
 std::cout << ">>>>> Options::AdditionalCut " << AdditionalCut.Data() << std::endl;
 
 
 EEEB = subPSetOptions.getParameter<int> ("EEorEB");
 std::cout << ">>>>> Options::EEEB " << EEEB << std::endl;
///==== 0 = EE+EB
///==== 1 = EE
///==== 2 = EB
///==== 3 = EE+
///==== 4 = EE-

 if (EEEB == 1) { ///==== EE
  AdditionalCut = Form("%s && (eta > 1.5 || eta < -1.5)",AdditionalCut.Data());
 }

 if (EEEB == 2) { ///==== EB
  AdditionalCut = Form("%s && (eta < 1.5 && eta > -1.5)",AdditionalCut.Data());
 }
 if (EEEB == 3) { ///==== EE+
  AdditionalCut = Form("%s && (eta > 1.5)",AdditionalCut.Data());
 }
 if (EEEB == 4) { ///==== EE-
  AdditionalCut = Form("%s && (eta < -1.5)",AdditionalCut.Data());
 }
 if (EEEB == 5) { ///==== EB mod 1
  AdditionalCut = Form("%s && (abs(eta) < 0.435)",AdditionalCut.Data());
 }
 if (EEEB == 6) { ///==== EB mod 2
  AdditionalCut = Form("%s && (abs(eta) < 0.783 && abs(eta) > 0.435)",AdditionalCut.Data());
 }
 if (EEEB == 7) { ///==== EB mod 3
  AdditionalCut = Form("%s && (abs(eta) < 1.131 && abs(eta) > 0.783)",AdditionalCut.Data());
 }
 if (EEEB == 8) { ///==== EB mod 4
  AdditionalCut = Form("%s && (abs(eta) < 1.479 && abs(eta) > 1.131)",AdditionalCut.Data());
 }
 if (EEEB == 9) { ///==== EE No ES
  AdditionalCut = Form("%s && (abs(eta) > 2.5)",AdditionalCut.Data());
 }
 if (EEEB == 10) { ///==== EE + ES
 AdditionalCut = Form("%s && (abs(eta) < 2.5 && abs(eta) > 1.5)",AdditionalCut.Data());
 }
 if (EEEB == 11) { ///==== EE- + ES
  AdditionalCut = Form("%s && (eta > -2.5 && eta < -1.5)",AdditionalCut.Data());
 }
 if (EEEB == 12) { ///==== EE+ + ES
  AdditionalCut = Form("%s && (eta < 2.5 && eta > 1.5)",AdditionalCut.Data());
 }
 
 std::cout << ">>>>>        :: " << AdditionalCut.Data() << std::endl;

 maxIter = subPSetOptions.getParameter<int> ("numToyMC") ;
 std::cout << ">>>>> Options::numToyMC  " << maxIter  << std::endl;  

 ///==== DATA ====
 fileInDATA = new TFile(inputFileDATA.c_str(),"READ");
 
 ///==== W ====
 fileInMC = new TFile(inputFileMC.c_str(),"READ");

 ///==== output ====
 outFile = new TFile(outputFile.c_str(),"RECREATE");
 outFile->cd();
 

 double ScaleTrue_Chi2;
 double ScaleTrue_Chi2_Fit;
 double ScaleTrue_LL;
 double ScaleTrue_LL_Fit;
 double ScaleTrue_NewChi2;
 double ScaleTrue_NewChi2_Fit;


 ///==== Prepare output trees ====

 myTreeChi2 = new TTree("myTreeChi2","myTreeChi2");
 myTreeChi2->Branch("Data_or_MC",&Data_or_MC,"Data_or_MC/I");
 myTreeChi2->Branch("Alpha",&Alpha,"Alpha/D");
 myTreeChi2->Branch("Chi2",&Chi2,"Chi2/D");
 myTreeChi2->Branch("NewChi2",&NewChi2,"NewChi2/D");
 myTreeChi2->Branch("LL",&LL,"LL/D");
 myTreeChi2->Branch("ScaleTrue",&ScaleTrue,"ScaleTrue/D");

 myTreeChi2_Result = new TTree("myTreeChi2_Result","myTreeChi2_Result");

 myTreeChi2_Result->Branch("Data_or_MC",&Data_or_MC,"Data_or_MC/I");
 myTreeChi2_Result->Branch("AlphaMean",&AlphaMean,"AlphaMean/D");
 myTreeChi2_Result->Branch("AlphaMinus",&AlphaMinus,"AlphaMinus/D");
 myTreeChi2_Result->Branch("AlphaPlus",&AlphaPlus,"AlphaPlus/D");
 myTreeChi2_Result->Branch("AlphaMean_Fit",&AlphaMean_Fit,"AlphaMean_Fit/D");
 myTreeChi2_Result->Branch("AlphaMinus_Fit",&AlphaMinus_Fit,"AlphaMinus_Fit/D");
 myTreeChi2_Result->Branch("AlphaPlus_Fit",&AlphaPlus_Fit,"AlphaPlus_Fit/D");
 myTreeChi2_Result->Branch("ScaleTrue",&ScaleTrue,"ScaleTrue/D");

 myTreeLL_Result = new TTree("myTreeLL_Result","myTreeLL_Result");
 myTreeLL_Result->Branch("Data_or_MC",&Data_or_MC,"Data_or_MC/I");
 myTreeLL_Result->Branch("AlphaMean",&AlphaMean,"AlphaMean/D");
 myTreeLL_Result->Branch("AlphaMinus",&AlphaMinus,"AlphaMinus/D");
 myTreeLL_Result->Branch("AlphaPlus",&AlphaPlus,"AlphaPlus/D");
 myTreeLL_Result->Branch("AlphaMean_Fit",&AlphaMean_Fit,"AlphaMean_Fit/D");
 myTreeLL_Result->Branch("AlphaMinus_Fit",&AlphaMinus_Fit,"AlphaMinus_Fit/D");
 myTreeLL_Result->Branch("AlphaPlus_Fit",&AlphaPlus_Fit,"AlphaPlus_Fit/D");
 myTreeLL_Result->Branch("ScaleTrue",&ScaleTrue,"ScaleTrue/D");

 myTreeNewChi2_Result = new TTree("myTreeNewChi2_Result","myTreeNewChi2_Result");
 myTreeNewChi2_Result->Branch("Data_or_MC",&Data_or_MC,"Data_or_MC/I");
 myTreeNewChi2_Result->Branch("AlphaMean",&AlphaMean,"AlphaMean/D");
 myTreeNewChi2_Result->Branch("AlphaMinus",&AlphaMinus,"AlphaMinus/D");
 myTreeNewChi2_Result->Branch("AlphaPlus",&AlphaPlus,"AlphaPlus/D");
 myTreeNewChi2_Result->Branch("AlphaMean_Fit",&AlphaMean_Fit,"AlphaMean_Fit/D");
 myTreeNewChi2_Result->Branch("AlphaMinus_Fit",&AlphaMinus_Fit,"AlphaMinus_Fit/D");
 myTreeNewChi2_Result->Branch("AlphaPlus_Fit",&AlphaPlus_Fit,"AlphaPlus_Fit/D");
 myTreeNewChi2_Result->Branch("ScaleTrue",&ScaleTrue,"ScaleTrue/D");


 ///==== Prepare input trees ====
 TTree* MyTreeDATA = (TTree*) fileInDATA->Get(treeNameDATA.c_str());

 MyTreeDATA->SetBranchAddress("pT",&pT);
 MyTreeDATA->SetBranchAddress("ET",&ET);
 MyTreeDATA->SetBranchAddress("MT",&MT);
 MyTreeDATA->SetBranchAddress("EoP",&EoP);
 MyTreeDATA->SetBranchAddress("eta",&eta);

 MyTreeDATA->SetBranchAddress("E5x5",&E5x5);
 MyTreeDATA->SetBranchAddress("p",&p);
 MyTreeDATA->SetBranchAddress("eleES",&eleES);
 MyTreeDATA->SetBranchAddress("eleFBrem",&eleFBrem);
 
 TTree* MyTreeMC = (TTree*) fileInMC->Get(treeNameMC.c_str());
 MyTreeMC->SetBranchAddress("pT",&pT);
 MyTreeMC->SetBranchAddress("ET",&ET);
 MyTreeMC->SetBranchAddress("MT",&MT);
 MyTreeMC->SetBranchAddress("EoP",&EoP);
 MyTreeMC->SetBranchAddress("eta",&eta);
 
 MyTreeMC->SetBranchAddress("E5x5",&E5x5);
 MyTreeMC->SetBranchAddress("p",&p);
 MyTreeMC->SetBranchAddress("eleES",&eleES);
 MyTreeMC->SetBranchAddress("eleFBrem",&eleFBrem);
 
 numEntriesMC = MyTreeMC->GetEntries();
 
 ///==== prepare minuit ====

 fitMin->SetRange(MinScanRange,MaxScanRange); 
 
 double step[1] = {0.001};
 double variable[1] = {0.0};
 minuit->SetLimitedVariable(0,"Scale" , variable[0]  , step[0] , MinScan  , MaxScan );
 

///===========================
///==== DATA Scale search ====
 ScaleTrue = -1000; ///==== default
 Data_or_MC = 1; ///=== 1 = Data;  0 = MC;
 numEvents = MyTreeDATA->GetEntries(); //==== number of events in Data sample
 outFile->cd();
 vET_data.clear();
 nIter = 1000000000; ///==== less than 1000000000 iterations at the end !!!
 TString nameDATA = Form("hDATA_%d_%d_%.5f",Data_or_MC,nIter,ScaleTrue);
 TH1F hDATA(nameDATA,nameDATA,numBINS,minBINS,maxBINS);
 
 MyTreeDATA->Draw(">> myList",(AdditionalCut + Form(" && ET > %f",minET)).Data(),"entrylist");
 TEntryList *mylist = (TEntryList*)gDirectory->Get("myList");
 MyTreeDATA->SetEntryList(mylist);
 
 MyTreeDATA->Draw(Form("%s >> %s",variableName.c_str(),nameDATA.Data()));
 ConvertStdVectDouble(vET_data,MyTreeDATA->GetV1(),mylist->GetN());
 
 hDATA.Write();
  
 std::cerr << "... I'm minimizing ... DATA analysis" << std::endl;
 std::cerr << ">>>>>>> numEvents = " << numEvents << " => " << vET_data.size() << " selected (=" << mylist->GetN() << ")" << std::endl;
 numSelectedData = vET_data.size();
 
 
 ///===== Chi2 ====
 std::cerr << " === Chi2 === " << std::endl;
 minuit->SetFunction(functorChi2);

 TGraph * grChi2 = new TGraph(iNoSteps);
 minuit->Scan(iPar_NoBG,iNoSteps,grChi2->GetX(),grChi2->GetY(),MinScan,MaxScan);

// TGraph * grChi2 = new TGraph();
// for (int iStep = 0; iStep < iNoSteps; iStep++){
//  double x = MinScan + (MaxScan - MinScan) / iNoSteps * (iStep+0.5);
//  double y = Chi2F(&x);
//  grChi2->SetPoint(iStep+1,x,y);
// }
 grChi2->Draw("AL");
 outFile->cd();
 minuit->PrintResults();
 outFile->cd();
 grChi2->SetTitle("grChi2");
 grChi2->Write();
 const double *outParametersTemp = minuit->X();
 const double *errParametersTemp = minuit->Errors();
  
 double *outParameters = new double;
 double *errParameters = new double;
 outParameters[0] = outParametersTemp[0];
 errParameters[0] = errParametersTemp[0];
   
 double minChi2 = grChi2->Eval(outParameters[0]);
 std::cerr << " numEvents = " << numEvents << " Scale = " << outParameters[0] << " +/- " << errParameters[0] << std::endl;
 ///===== end Chi2 ====
  
 ///==== likelihood ====
 std::cerr << " === LL === " << std::endl;
 minuit->SetFunction(functorLL);

 TGraph * grLL_temp = new TGraph(iNoSteps);
 minuit->Scan(iPar_NoBG,iNoSteps,grLL_temp->GetX(),grLL_temp->GetY(),MinScan,MaxScan);
 TGraph * grLL = new TGraph();
 grLL->SetName("grLL");
 int nPointLL = 0;
 for (unsigned int iStep = 0; iStep < iNoSteps; iStep++){
  double x = MinScan + (MaxScan - MinScan) / iNoSteps * (iStep+0.5);
  double y = LLFunc(&x);
//  std::cerr << " y = " << y << std::endl;
  if (y != numberDATA * numEvents) {
   std::cerr << " Ok y = " << y << std::endl;
   grLL->SetPoint(nPointLL,x,y);
   nPointLL++;
  }
 }
 
 
 std::cerr << " finito " << std::endl;
 
 grLL->Draw("AL");
 outFile->cd();
 minuit->PrintResults();
 outFile->cd();
 grLL->SetTitle("grLL");
 grLL->Write();
 
 std::cerr << " done " << std::endl;

 const double *outParametersTemp2 = minuit->X();
 const double *errParametersTemp2 = minuit->Errors();

 std::cerr << " done 2 " << std::endl;
  
 double *outParametersLL = new double;
 double *errParametersLL = new double;
 outParametersLL[0] = outParametersTemp2[0];
 errParametersLL[0] = errParametersTemp2[0];
 
 double minLL = grLL->Eval(outParametersLL[0]);
 std::cerr << " numEvents = " << numEvents << " Scale = " << outParametersLL[0] << " +/- " << errParametersLL[0] << std::endl;
 ///==== end likelihood ====
 
 
 ///==== newChi2 ====
 std::cerr << " === newChi2 === " << std::endl;
 minuit->SetFunction(functorNewChi2);
 TGraph * grNewChi2 = new TGraph(iNoSteps);
 minuit->Scan(iPar_NoBG,iNoSteps,grNewChi2->GetX(),grNewChi2->GetY(),MinScan,MaxScan);
 grNewChi2->Draw("AL");
 outFile->cd();
 minuit->PrintResults();
 outFile->cd();
 grNewChi2->SetTitle("grNewChi2");
 grNewChi2->Write();
 const double *outParametersNewChi2 = minuit->X();
 const double *errParametersNewChi2 = minuit->Errors();
 double minNewChi2 = grNewChi2->Eval(outParametersNewChi2[0]);
 std::cerr << " numEvents = " << numEvents << " Scale = " << outParametersNewChi2[0] << " +/- " << errParametersNewChi2[0] << std::endl;
 ///==== end newChi2 ====
  
 
 
 std::cerr << "... Minimized with all methods ..." << std::endl;

 ///==== Save the whole shape of LL/Chi2 ====
 for (unsigned int ii=0; ii < iNoSteps; ii++){
  double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan;
  
  Alpha   = X_ii;
  Chi2    = grChi2->Eval(X_ii);
  LL      = grLL->Eval(X_ii);
  NewChi2 = grNewChi2->Eval(X_ii);
  myTreeChi2->Fill();
 }
  
 ///===== Look for minima =====
  
 ///===== Chi2 ====
 std::cerr << " === Chi2 === " << std::endl;
 std::cerr << "==== min Scan = " << minChi2 << std::endl;
 double errX_low = -9999;
 double errX_up = 9999;
 int err_low = 0;
 int err_up = 0;
 for (unsigned int ii=0; ii < iNoSteps; ii++){
  double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan;
  double here = grChi2->Eval(X_ii);
  if (err_low == 0){
   if (here < (minChi2 + DELTA_CHI2)){
    errX_low = X_ii;
    err_low = 1;
   }
  }
  else if (err_up == 0 && here > (minChi2 + DELTA_CHI2) && X_ii > outParameters[0]){
   errX_up = X_ii; 
   err_up = 1;
  }
 }
 
 AlphaMean = outParameters[0];
 AlphaMinus = errX_low;
 AlphaPlus = errX_up;

 grChi2->Fit("fitMin","RMQ");
 c = fitMin->GetParameter(0);
 b = fitMin->GetParameter(1);
 a = fitMin->GetParameter(2);
 AlphaMean_Fit  = -b / (2*a);
 AlphaMinus_Fit = (-b + 2 * sqrt(a)) / (2*a);  ///==== delta Chi2 = 1 
 AlphaPlus_Fit  = (-b - 2 * sqrt(a)) / (2*a);  ///==== delta Chi2 = 1   
 myTreeChi2_Result->Fill();
  
 ScaleTrue_Chi2 = AlphaMean;
 ScaleTrue_Chi2_Fit = AlphaMean_Fit;

 ///===== LogLikelihood ====
 std::cerr << " === LL === " << std::endl;
 std::cerr << "==== min Scan = " << minLL << std::endl;
 errX_low = -9999;
 errX_up = 9999;
 err_low = 0;
 err_up = 0;
 for (unsigned int ii=0; ii < iNoSteps; ii++){
  double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan;
  double here = grLL->Eval(X_ii);
  if (err_low == 0){
   if (here < (minLL + DELTA_LL)){
    errX_low = X_ii;
    err_low = 1;
   }
  }
  else if (err_up == 0 && here > (minLL + DELTA_LL) && X_ii > outParametersLL[0]){
   errX_up = X_ii; 
   err_up = 1;
  }
 }
 
 AlphaMean = outParametersLL[0];
 AlphaMinus = errX_low;
 AlphaPlus = errX_up;

 grLL->Fit("fitMin","RMQ");
 c = fitMin->GetParameter(0);
 b = fitMin->GetParameter(1);
 a = fitMin->GetParameter(2);
 AlphaMean_Fit  = -b / (2*a);
 AlphaMinus_Fit = (-b + sqrt(2*a)) / (2*a);  ///==== delta LL = 0.5
 AlphaPlus_Fit  = (-b - sqrt(2*a)) / (2*a);  ///==== delta LL = 0.5   
 
 myTreeLL_Result->Fill();
 
 ScaleTrue_LL = AlphaMean;
 ScaleTrue_LL_Fit = AlphaMean_Fit;

 
 ///===== NewChi2 ====
 std::cerr << " === NewChi2 === " << std::endl;
 std::cerr << "==== min Scan = " << minNewChi2 << std::endl;
 errX_low = -9999;
 errX_up = 9999;
 err_low = 0;
 err_up = 0;
 for (unsigned int ii=0; ii < iNoSteps; ii++){
  double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan;
  double here = grNewChi2->Eval(X_ii);
  if (err_low == 0){
   if (here < (minNewChi2 + DELTA_CHI2)){
    errX_low = X_ii;
    err_low = 1;
   }
  }
  else if (err_up == 0 && here > (minNewChi2 + DELTA_CHI2) && X_ii > outParametersNewChi2[0]){
   errX_up = X_ii; 
   err_up = 1;
  }
 }
  
 AlphaMean = outParametersNewChi2[0];
 AlphaMinus = errX_low;
 AlphaPlus = errX_up;
 
 
 grNewChi2->Fit("fitMin","RMQ");
 c = fitMin->GetParameter(0);
 b = fitMin->GetParameter(1);
 a = fitMin->GetParameter(2);
 AlphaMean_Fit  = -b / (2*a);
 AlphaMinus_Fit = (-b + 2 * sqrt(a)) / (2*a);  ///==== delta Chi2 = 1 
 AlphaPlus_Fit  = (-b - 2 * sqrt(a)) / (2*a);  ///==== delta Chi2 = 1   
 
 myTreeNewChi2_Result->Fill();
  
 ScaleTrue_NewChi2 = AlphaMean;
 ScaleTrue_NewChi2_Fit = AlphaMean_Fit;

 std::cerr << " ================ End DATA Scale search ================ " << std::endl;


///==== MC analysis ==== Scale search ====
 Data_or_MC = 0; ///=== 1 = Data;  0 = MC; -1 = MC Fit
 std::cerr << " ==== MC Scale search ==== " << std::endl; 
 ///==== cycle on number of Toy MC experiments ====
 ///=== Chi2 ===
 std::cerr << "======================= Chi2 " << ScaleTrue_Chi2 << " =====================" << std::endl;
//  ScaleTrue = ScaleTrue_Chi2;
//  doMC_Chi2();

///=== LogLikelihood ===
 std::cerr << "======================= LL " << ScaleTrue_LL << " =====================" << std::endl;
//  ScaleTrue = ScaleTrue_LL;
//  doMC_LL();

///=== NewChi2 ===
 std::cerr << "======================= NewChi2 " << ScaleTrue_NewChi2 << " =====================" << std::endl;
//  ScaleTrue = ScaleTrue_NewChi2;
//  doMC_NewChi2();


 Data_or_MC = -1; ///=== 1 = Data;  0 = MC; -1 = MC Fit
 std::cerr << " ==== MC Scale search ==== " << std::endl; 
 ///==== cycle on number of Toy MC experiments ====
 ///=== Chi2 ===
 std::cerr << "======================= Chi2 FIT " << ScaleTrue_Chi2_Fit << " =====================" << std::endl;
//  ScaleTrue = ScaleTrue_Chi2_Fit;
//  doMC_Chi2();

///=== LogLikelihood ===
 std::cerr << "======================= LL FIT " << ScaleTrue_LL_Fit << " =====================" << std::endl;
 ScaleTrue = ScaleTrue_LL_Fit;
 doMC_LL();

///=== NewChi2 ===
 std::cerr << "======================= NewChi2 FIT " << ScaleTrue_NewChi2_Fit << " =====================" << std::endl;
//  ScaleTrue = ScaleTrue_NewChi2_Fit;
//  doMC_NewChi2();

 
  ///----------------------
  ///---- Plot results ----
  ///----------------------
  outFile->cd();
  myTreeChi2->Write();
  myTreeLL_Result->Write();
  myTreeChi2_Result->Write();
  myTreeNewChi2_Result->Write();
  delete fitMin;
  
}
예제 #12
0
///**** LL ****
void doMC_LL(){
 TTree* MyTreeMC = (TTree*) fileInMC->Get(treeNameMC.c_str());

 for (nIter = 0; nIter<maxIter; nIter++){
  if (!(nIter%1)) std::cerr << ">>> nIter = " << nIter << " : " << maxIter << std::endl;
  vET_data.clear();
  outFile->cd();
  TString nameDATA = Form("hDATA_%d_%d_%.5f",Data_or_MC,nIter,ScaleTrue);
  TH1F hDATA(nameDATA,nameDATA,numBINS,minBINS,maxBINS);
  
  MyTreeMC->Draw(">> myListMC",(AdditionalCut+Form("&& (ET * (1+(%f)))>%f",ScaleTrue,minET)).Data(),"entrylist");
  TEntryList *myListMC = (TEntryList*)gDirectory->Get("myListMC");
  
  MyTreeMC->SetEntryList(0); 
  TEntryList *listMCHere = new TEntryList("listMCHere","listMCHere");    
  for (int iEvt = 0; iEvt < numSelectedData; iEvt ++){
   listMCHere->Enter(myListMC->GetEntry(gRandom->Uniform(0,myListMC->GetN())));
  }
  
  MyTreeMC->SetEntryList(listMCHere);
  MyTreeMC->Draw(Form("(1+%f) * %s >> %s",ScaleTrue,variableName.c_str(),nameDATA.Data()));
  
  ConvertStdVectDouble(vET_data,MyTreeMC->GetV1(),numSelectedData);
  
  ///==== likelihood ====
 std::cerr << " === LL === " << std::endl;
 std::cerr << " === pseudo vET_data.size() = " << vET_data.size() << std::endl;
 
 
  minuit->SetFunction(functorLL); 
  TGraph * grLL_temp = new TGraph(iNoSteps);
  minuit->Scan(iPar_NoBG,iNoSteps,grLL_temp->GetX(),grLL_temp->GetY(),MinScan,MaxScan);
  TGraph * grLL = new TGraph();
  int nPointLL = 0;
 for (unsigned int iStep = 0; iStep < iNoSteps; iStep++){
   double x = MinScan + (MaxScan - MinScan) / iNoSteps * (iStep+0.5);
   double y = LLFunc(&x);
   if (y != numberDATA * numEvents) {
    grLL->SetPoint(nPointLL,x,y);
    nPointLL++;
   }
  }
  grLL->Draw("AL");
  outFile->cd();
  minuit->PrintResults();
  const double *outParametersTemp2 = minuit->X();
  const double *errParametersTemp2 = minuit->Errors();
  
  double *outParametersLL = new double;
  double *errParametersLL = new double;
  outParametersLL[0] = outParametersTemp2[0];
  errParametersLL[0] = errParametersTemp2[0];
  
  std::cerr << " nPointLL = " << nPointLL << std::endl;
  
  double minLL = grLL->Eval(outParametersLL[0]);
  ///==== end likelihood ====
  
    ///==== Save the whole shape of LL/Chi2 ====
  for (unsigned int ii=0; ii < iNoSteps; ii++){
   double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan;
   
   Alpha   = X_ii;
   Chi2    = 0;
   LL      = grLL->Eval(X_ii);
   NewChi2 = 0;
   
   myTreeChi2->Fill();
  }

  ///===== Look for minima =====
  double a;
  double b;
  double c;
  
  
  double errX_low = -9999;
  double errX_up = 9999;
  int err_low = 0;
  int err_up = 0;
  for (unsigned int ii=0; ii < iNoSteps; ii++){
   double X_ii = (MaxScan - MinScan) / iNoSteps * ii + MinScan;
   double here = grLL->Eval(X_ii);
   if (err_low == 0){
    if (here < (minLL + DELTA_LL)){
     errX_low = X_ii;
     err_low = 1;
    }
   }
   else if (err_up == 0 && here > (minLL + DELTA_LL) && X_ii > outParametersLL[0]){
    errX_up = X_ii; 
    err_up = 1;
   }
  }
  
  AlphaMean = outParametersLL[0];
  AlphaMinus = errX_low;
  AlphaPlus = errX_up;
 
  grLL->Fit("fitMin","RMQ");
  c = fitMin->GetParameter(0);
  b = fitMin->GetParameter(1);
  a = fitMin->GetParameter(2);
  AlphaMean_Fit  = -b / (2*a);
  AlphaMinus_Fit = (-b + sqrt(2*a)) / (2*a);  ///==== delta LL = 0.5
  AlphaPlus_Fit  = (-b - sqrt(2*a)) / (2*a);  ///==== delta LL = 0.5   
  
  myTreeLL_Result->Fill();
 
  grLL->Write();
  
  //delete listMCHere;
  
 }
}
예제 #13
0
void bjetefficiency() { 	  	  	
std::vector<string> samples_;
//samples_.push_back("WPHJET.root");
//samples_.push_back("WW.root");
//samples_.push_back("WZ.root");
//samples_.push_back("ZZ.root");
samples_.push_back("SIGNALtGC.root");
samples_.push_back("SIGNALtGu.root");

//open files
std::vector<TFile*> files;
for(unsigned int idx=0; idx<samples_.size(); ++idx){
files.push_back(new TFile(samples_[idx].c_str()));}
std::vector<string> variables2_;
/*
variables2_.push_back("btageffL");
variables2_.push_back("btageffM");
variables2_.push_back("btageffT");

variables2_.push_back("ctageffL");
variables2_.push_back("ctageffM");
variables2_.push_back("ctageffT");
*/
variables2_.push_back("btageffL");
variables2_.push_back("btageffM");
variables2_.push_back("btageffT");


std::vector<double> finaleff;

Double_t bdiscriminator[35];
for (unsigned int i=0; i<15; ++i){
bdiscriminator[i] =0.244-0.1+i*0.02; }
for (unsigned int i=0; i<10; ++i){
bdiscriminator[15+i] = 0.679-0.1+i*0.02;}
for (unsigned int i=0; i<10; ++i){
bdiscriminator[25+i] = 0.898-0.1+i*0.02;}

Double_t count[3];
count[0]=15;
count[1]=10;
count[2]=10;

for(unsigned int ii=0; ii<variables2_.size(); ++ii){
std::vector<TH1F*> hists;
for(unsigned int idx=0; idx<files.size(); ++idx){hists.push_back((TH1F*)files[idx]->Get((std::string("STEP1/").append(variables2_[ii]).c_str())));}

for(unsigned int idx=1; idx<files.size(); ++idx){
hists[idx]->Add(hists[idx-1]);}

//hists[files.size()-1]->Draw();
std::vector<double> eff;
int bin; 

for ( bin=1; bin<count[ii]*2+1; ++bin){eff.push_back(hists[files.size()-1]->GetBinContent(bin));}
for (unsigned int i=0; i<count[ii]; ++i){finaleff.push_back(eff[2*i+1]/(eff[2*i]+eff[2*i+1])); 
//cout<< eff[2*i+1]<<"                "<<eff[2*i+1]/(eff[2*i]+eff[2*i+1])<<endl;
}
}

//   TGraph *gr = new TGraph(30,bdiscriminator,finaleff);

Double_t effi[35];
for (unsigned int i=0; i<35; ++i){
effi[i] =finaleff[i]; }
   TGraph *gr = new TGraph(35,effi,bdiscriminator);
   TGraph *grREV = new TGraph(35,bdiscriminator,effi);

   cout<<"the new working points for nominal SF"<<endl;
   cout<<"loose        "<<gr->Eval(1.008*grREV->Eval(0.244))<<endl;
   cout<<"medium        "<<gr->Eval(0.963*grREV->Eval(0.679))<<endl;
   cout<<"tight        "<<gr->Eval(0.947*grREV->Eval(0.898))<<endl;


   cout<<"the new working points for SF UP"<<endl;
   cout<<"loose        "<<gr->Eval((1.008+0.023)*grREV->Eval(0.244))<<endl;
   cout<<"medium        "<<gr->Eval((0.963+0.020)*grREV->Eval(0.679))<<endl;
   cout<<"tight        "<<gr->Eval((0.947+0.025)*grREV->Eval(0.898))<<endl;


   cout<<"the new working points for SF DOWN"<<endl;
   cout<<"loose        "<<gr->Eval((1.008-0.023)*grREV->Eval(0.244))<<endl;
   cout<<"medium        "<<gr->Eval((0.963-0.020)*grREV->Eval(0.679))<<endl;
   cout<<"tight        "<<gr->Eval((0.947-0.025)*grREV->Eval(0.898))<<endl;

//   cout<<gr->Eval(1.008*grREV->Eval(0.244))<<endl;
//   cout<<gr->Eval(0.966*grREV->Eval(0.679))<<endl;
//   cout<<gr->Eval(0.931*grREV->Eval(0.898))<<endl;

//   cout<<gr->Eval(0.0990)<<endl;
 //  cout<<gr->Eval(0.0142)<<endl;
//   cout<<gr->Eval(0.00155)<<endl;
//   cout<<gr->Eval(0.0142)<<endl;
 //  cout<<gr->Eval(0.0016)<<endl;
   gr->SetLineColor(4);
   gr->SetLineWidth(4);
   gr->SetMarkerColor(4);
   gr->SetMarkerStyle(21);

   gr->Draw("AP");

}
int main(){
  
  system("mkdir -p plots");
  RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR);
  TFile *bkgFile = TFile::Open("comb_svn/hgg.inputbkgdata_8TeV_MVA.root");
  TFile *sigFile = TFile::Open("comb_svn/hgg.inputsig_8TeV_nosplitVH_MVA.root");
  RooWorkspace *bkgWS = (RooWorkspace*)bkgFile->Get("cms_hgg_workspace");
  RooWorkspace *sigWS = (RooWorkspace*)sigFile->Get("wsig_8TeV");

  RooRealVar *mass = (RooRealVar*)bkgWS->var("CMS_hgg_mass");
  RooRealVar *mu = new RooRealVar("mu","mu",-5.,5.);

  mass->setBins(320);
  cout << mass->getBins() << endl;
  RooDataSet *dataAll;
  
  int firstCat=1;
  int lastCat=1;
  float mu_low=-1.;
  float mu_high=3.;
  float mu_step=0.01;

  vector<pair<double,TGraph*> > minNlltrack;

  for (int cat=firstCat; cat<=lastCat; cat++){
    RooDataSet *data = (RooDataSet*)bkgWS->data(Form("data_mass_cat%d",cat));
    if (cat==firstCat) dataAll = (RooDataSet*)data->Clone("data_mass_all");
    else dataAll->append(*data);
    RooDataHist *dataBinned = new RooDataHist(Form("roohist_data_mass_cat%d",cat),Form("roohist_data_mass_cat%d",cat),RooArgSet(*mass),*data);
    RooDataSet *sigMC = (RooDataSet*)sigWS->data(Form("sig_mass_m125_cat%d",cat));

    if (!dataBinned || !sigMC){
      cerr << "ERROR -- one of data or signal is NULL" << endl;
      exit(1);
    }
    
    // Construct PDFs for this category using PdfModelBuilder
    PdfModelBuilder modelBuilder;
    modelBuilder.setObsVar(mass);
    modelBuilder.setSignalModifier(mu);
    // For Standard Analysis
    //if (cat>=0 && cat<=3) modelBuilder.addBkgPdf("Bernstein",5,Form("pol5_cat%d",cat));
    //if (cat>=4 && cat<=5) modelBuilder.addBkgPdf("Bernstein",4,Form("pol4_cat%d",cat));
    //if (cat>=6 && cat<=8) modelBuilder.addBkgPdf("Bernstein",3,Form("pol3_cat%d",cat));
    // To Profile Multiple PDFs
    if (cat==0 || cat==1 || cat==2 || cat==3){
      modelBuilder.addBkgPdf("Bernstein",4,Form("pol4_cat%d",cat));
      modelBuilder.addBkgPdf("Bernstein",5,Form("pol5_cat%d",cat));
      modelBuilder.addBkgPdf("Bernstein",6,Form("pol6_cat%d",cat));
      /*
      modelBuilder.addBkgPdf("PowerLaw",1,Form("pow1_cat%d",cat));
      modelBuilder.addBkgPdf("PowerLaw",3,Form("pow3_cat%d",cat));
      modelBuilder.addBkgPdf("PowerLaw",5,Form("pow5_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",1,Form("exp1_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",3,Form("exp3_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",5,Form("exp5_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",1,Form("lau1_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",3,Form("lau3_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",5,Form("lau5_cat%d",cat));
      */
    }
    if (cat==4 || cat==5 || cat==6 || cat==7 || cat==8) {
      modelBuilder.addBkgPdf("Bernstein",3,Form("pol3_cat%d",cat));
      modelBuilder.addBkgPdf("Bernstein",4,Form("pol4_cat%d",cat));
      /*
      modelBuilder.addBkgPdf("PowerLaw",1,Form("pow1_cat%d",cat));
      modelBuilder.addBkgPdf("PowerLaw",3,Form("pow3_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",1,Form("exp1_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",3,Form("exp3_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",1,Form("lau1_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",3,Form("lau3_cat%d",cat));
      */
    }
    map<string,RooAbsPdf*> bkgPdfs = modelBuilder.getBkgPdfs();
    modelBuilder.setSignalPdfFromMC(sigMC);
    modelBuilder.makeSBPdfs();
    map<string,RooAbsPdf*> sbPdfs = modelBuilder.getSBPdfs();

    modelBuilder.fitToData(dataBinned,true,true);
    modelBuilder.fitToData(dataBinned,false,true);

    modelBuilder.throwToy(Form("cat%d_toy0",cat),dataBinned->sumEntries(),true,true);

    // Profile this category using ProfileMultiplePdfs
    ProfileMultiplePdfs profiler;
    for (map<string,RooAbsPdf*>::iterator pdf=sbPdfs.begin(); pdf!=sbPdfs.end(); pdf++) {
      string bkgOnlyName = pdf->first.substr(pdf->first.find("sb_")+3,string::npos);
      if (bkgPdfs.find(bkgOnlyName)==bkgPdfs.end()){
        cerr << "ERROR -- couldn't find bkg only pdf " << bkgOnlyName << " for SB pdf " << pdf->first << endl;
        pdf->second->fitTo(*dataBinned);
        exit(1);
      }
      int nParams = bkgPdfs[bkgOnlyName]->getVariables()->getSize()-1;
      profiler.addPdf(pdf->second,2*nParams);
      //profiler.addPdf(pdf->second);
      cout << pdf->second->GetName() << " nParams=" << pdf->second->getVariables()->getSize() << " nBkgParams=" << nParams << endl;
    }
    profiler.printPdfs();
    //cout << "Continue?" << endl;
    //string bus; cin >> bus;
    profiler.plotNominalFits(dataBinned,mass,80,Form("cat%d",cat));
    pair<double,map<string,TGraph*> > minNlls = profiler.profileLikelihood(dataBinned,mass,mu,mu_low,mu_high,mu_step);
    pair<double,map<string,TGraph*> > correctedNlls = profiler.computeEnvelope(minNlls,Form("cat%d",cat),2.);
    minNlltrack.push_back(make_pair(correctedNlls.first,correctedNlls.second["envelope"]));
    //minNlls.second.insert(pair<string,TGraph*>("envelope",envelopeNll.second));
    //map<string,TGraph*> minNLLs = profiler.profileLikelihoodEnvelope(dataBinned,mu,mu_low,mu_high,mu_step);
    profiler.plot(correctedNlls.second,Form("cat%d_nlls",cat));
    //profiler.print(minNLLs,mu_low,mu_high,mu_step);
    /*
    if (minNLLs.find("envelope")==minNLLs.end()){
      cerr << "ERROR -- envelope TGraph not found in minNLLs" << endl;
      exit(1);
    }
    */
    //minNlltrack.push_back(make_pair(profiler.getGlobalMinNLL(),minNLLs["envelope"]));
  }
  //exit(1);
  TGraph *comb = new TGraph();
  for (vector<pair<double,TGraph*> >::iterator it=minNlltrack.begin(); it!=minNlltrack.end(); it++){
    if (it->second->GetN()!=minNlltrack.begin()->second->GetN()){
      cerr << "ERROR -- unequal number of points for TGraphs " << it->second->GetName() << " and " << minNlltrack.begin()->second->GetName() << endl;
      exit(1);
    }
  }
  for (int p=0; p<minNlltrack.begin()->second->GetN(); p++){
    double x,y,sumy=0;
    for (vector<pair<double,TGraph*> >::iterator it=minNlltrack.begin(); it!=minNlltrack.end(); it++){
      it->second->GetPoint(p,x,y);
      sumy += (y+it->first);
    }
    comb->SetPoint(p,x,sumy);
  }
  pair<double,double> globalMin = getGraphMin(comb);
  for (int p=0; p<comb->GetN(); p++){
    double x,y;
    comb->GetPoint(p,x,y);
    comb->SetPoint(p,x,y-globalMin.second);
  }
  vector<double> fitVal = getValsFromLikelihood(comb);

  cout << "Best fit.." << endl;
  cout << "\t mu = " << Form("%4.3f",fitVal[0]) << " +/- (1sig) = " << fitVal[2]-fitVal[0] << " / " << fitVal[0]-fitVal[1] << endl;
  cout << "\t      " << "    " << " +/- (2sig) = " << fitVal[4]-fitVal[0] << " / " << fitVal[0]-fitVal[3] << endl;

  cout << comb->Eval(fitVal[0]) << " " << comb->Eval(fitVal[1]) << " " << comb->Eval(fitVal[2]) << " " << comb->Eval(fitVal[3]) << " " << comb->Eval(fitVal[4]) << endl;

  double quadInterpVal = ProfileMultiplePdfs::quadInterpMinimum(comb);
  cout << "quadInterp: mu = " << quadInterpVal << endl;
  cout << "\t " << comb->Eval(quadInterpVal) << " " << comb->Eval(quadInterpVal-0.005) << " " << comb->Eval(quadInterpVal-0.01) << " " << comb->Eval(quadInterpVal+0.005) << " " << comb->Eval(quadInterpVal+0.01) << endl;
  
  comb->SetLineWidth(2);
  TCanvas *canv = new TCanvas();
  comb->Draw("ALP");
  canv->Print("plots/comb.pdf");
  TFile *tempOut = new TFile("tempOut.root","RECREATE");
  tempOut->cd();
  comb->SetName("comb");
  comb->Write();
  tempOut->Close();
  return 0;
}
void ExtractSignalYield(string ModelName, string decayMode, float natural_width, bool dependsOnKtilde=0)
{
  
  string dir = "/usr/users/dschaefer/root/results/";
  string outputfile = ModelName+"_"+decayMode+"_signalYield.root";
  //float natural_width =0.05;
  std::stringstream s;
      if(int(natural_width*100+0.5) == 10 or int(100*natural_width+0.5)==20 or int(natural_width*100+0.5)==30)
      {
	s << std::fixed << std::setprecision(1) << natural_width;
      }
      else
      {
	s << std::fixed << std::setprecision(2) << natural_width;
      }
  string swidth = s.str();
  float ktilde;
  string sktilde;
  if(dependsOnKtilde)
  {
   ktilde = natural_width;
   sktilde = swidth;
  }
  
  TGraph* limit = getObservedLimit(ModelName,decayMode,natural_width,dependsOnKtilde);
  TGraph* limitUP = getLimitUp(ModelName,decayMode,natural_width,1,dependsOnKtilde);
  TGraph* limitDOWN = getLimitDown(ModelName,decayMode,natural_width,1,dependsOnKtilde);
  TGraph* limitUP2 = getLimitUp(ModelName,decayMode,natural_width,2,dependsOnKtilde);
  TGraph* limitDOWN2 = getLimitDown(ModelName,decayMode,natural_width,2,dependsOnKtilde);
  
  
  int number;
  float* masses;
  if(decayMode.find("lvjj")!=string::npos)
  {
    masses = new float[38];
    number =38;
    float array[38] = {800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500,2600,2700,2800,2900,3000,3100,3200,3300,3400,3500,3600,3700,3800,3900,4000,4100,4200,4300,4400,4500};
    masses = array;
  }
  else
  {
   number = 29;
   masses = new float[29];
   float array[29] = {1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500,2600,2700,2800,2900,3000,3100,3200,3300,3400,3500,3600,3700,3800,3900,4000};
   masses = array;
  }
  TGraph* gryellow = new TGraph(2*number);
  TGraph* grgreen  = new TGraph(2*number);
  
  for(int m=0;m<number;m++)
  {
    gryellow->SetPoint(m,masses[m],limitUP->Eval(masses[m]));
    gryellow->SetPoint(number+m,masses[number-m-1],limitDOWN->Eval(masses[number-m-1]));
    grgreen->SetPoint(m,masses[m],limitUP2->Eval(masses[m]));
    grgreen->SetPoint(number+m,masses[number-m-1],limitDOWN2->Eval(masses[number-m-1]));
    
  }
  gryellow->SetFillColor(kYellow);
  grgreen->SetFillColor(kGreen);
  
  TCanvas* test = new TCanvas("test","test",400,400);
  test->SetLogy();
  limitUP->SetFillColor(kGreen+2);
  limitUP->SetLineColor(kGreen+2);
  limitUP->SetLineWidth(-1504);
  
  //limitUP->Draw("ACP");
  limitDOWN->SetFillColor(kBlue);
  limitDOWN->SetLineColor(kGreen+2);
  limitDOWN->SetLineWidth(-1504);
  //limitDOWN->Draw("CPsame");
  gryellow->Draw("AFsame");
  grgreen->Draw("Fsame");
  limit->SetLineColor(kBlue);
  limit->SetLineWidth(3);
  limit->Draw("Lsame");
  test->Update();
  
  float lumi = 2.10*1000;  //pb^-1
  if(decayMode.find("jjjj")!=string::npos){lumi = 2.6*1000;}//pb^-1
  
  
  
  
  //float *xs = getTheoryCrossSection(ModelName,0.1);
  
  //x values for which a theory prediction for production cross section exists
  float m_xs[10]  =  {800,900,1000,1500,1800,2000,2500,3000,3500,4500};
  float BR_G_to_WW[10];
  float BR_G_to_ZZ[10];
  float *acceptance;
  float *N_expected;
  //float xs = 0.01;
  float *xs = new float[10];
  
  if(dependsOnKtilde)
  {
    xs = getTheoryCrossSection(ModelName,ktilde);
  }
  else
  {
    for(int i=0;i<10;i++)
    {
    if(natural_width!=0)
    {
      ktilde = getKtilde(ModelName,m_xs[i],natural_width);
      //std::cout << m_xs[i] << " k = " << ktilde <<std::endl;
      xs[i] = getTheoryCrossSection(ModelName,m_xs[i],ktilde);
    }
    else
    {
      ktilde = getKtilde(ModelName,m_xs[i],0.02);
      //std::cout <<  m_xs[i] << " k = " << ktilde <<std::endl;
      xs[i] = getTheoryCrossSection(ModelName,m_xs[i],ktilde);
    }
    }
  }
  
 
 
 
  
  TGraph* production_xs = new TGraph(10,m_xs,xs);
  
  // TCanvas* c_xs = new TCanvas("c_xs","c_xs",400,400);
  // c_xs->SetLogy();
  // production_xs->SetMarkerColor(1);
  // production_xs->GetXaxis()->SetTitle("m_G [GeV]");
  // production_xs->GetYaxis()->SetTitle("theory production cross section");
  // production_xs->Draw("AL");
  
  
  
  if(!dependsOnKtilde)
  {
  acceptance = getAcceptance(ModelName,decayMode,m_xs,10);
  }
  else
  {
   acceptance = getAcceptance(decayMode,ktilde); 
  }
  
  N_expected = getNumberOfExpectedEvents(xs,m_xs,acceptance,ModelName,decayMode);
  

 std::cout << "production cross section : "<< std::endl;
  for(int i=0;i<10;i++)
    {
      std::cout << m_xs[i] <<  " " << xs[i]<< std::endl;
    }
  std::cout << " acceptance : "<<std::endl;
  for(int i=0;i<10;i++)
    {
      std::cout << m_xs[i] << " "<<acceptance[i]<<std::endl;
    }
  float br[10];
  std::cout << "Branching Ratios : "<<std::endl;
  for(int i=0;i<10;i++)
    {
      float BR_W_to_lv = 0.327;
      float BR_W_to_jj = 0.674;
      float BR_Z_to_jj = 0.6991;
      br[i] = getBranchingRatioToWW(ModelName,m_xs[i])*std::pow(BR_W_to_jj,2)*2 + getBranchingRatioToZZ(ModelName,m_xs[i])*std::pow(BR_Z_to_jj,2)*2;
      if(decayMode.find("lvjj")!=std::string::npos)
	{
	  br[i] = getBranchingRatioToWW(ModelName,m_xs[i])*2*BR_W_to_lv*BR_W_to_jj;
	}
      std::cout << m_xs[i] << " "<< br[i] << std::endl;
    }
  std::cout << lumi <<std::endl;
  std::cout << " N expected : "<<std::endl;
  for(int i=0;i<10;i++)
    {
      std::cout << m_xs[i] << " "<<N_expected[i] << " " <<xs[i]*lumi*br[i]*acceptance[i] << std::endl;
    }

  
  TGraph* N = new TGraph(10,m_xs,N_expected);
  //N->SetName("expected signal yield");
  grgreen->GetXaxis()->SetTitle("m_{VV} [GeV]");
  grgreen->GetYaxis()->SetTitle("number signal events");
  grgreen->GetYaxis()->SetTitleOffset(1.3);
  grgreen->SetTitle("");
  TCanvas* c_N = new TCanvas("c_N","c_N",600,400);
  gPad->SetRightMargin(0.1);
  gPad->SetLeftMargin(0.1);
  limit->SetLineColor(kBlue);
  limit->SetLineWidth(3);
  c_N->SetLogy();
  N->SetLineColor(kRed);
  N->SetLineWidth(2);
  //N->Draw("A");
  grgreen->SetMaximum(1000);
  grgreen->Draw("AF");
  gryellow->Draw("Fsame");
  limit->Draw("Csame");
  N->Draw("Lsame");
  TLegend* leg = new TLegend(0.59,0.65,0.95,0.89);
  leg->SetFillColor(kWhite);
  leg->SetFillStyle(0);
  leg->SetTextSize(0.04);
  leg->SetBorderSize(0);
  
  string title = "Preliminary";
  string cms = "#font[62]{CMS} #font[52]{"+string(title)+"} ";
  string lumitext = "2.6 fb^{-1}, #sqrt{s} = 13 TeV";
  string cmstext = "CMS ,2.6 fb^{-1}, #sqrt{s} = 13 TeV";
  if(decayMode.find("had")==string::npos){lumitext = "2.1 fb^{-1}, #sqrt{s} = 13 TeV";}
  string theory = "G #rightarrow WW, #Gamma = "+swidth;
  if(dependsOnKtilde)
  {
    theory = "G #rightarrow WW, #tilde{k} = "+sktilde;
  }
  if(ModelName.find("RSGrav")!=string::npos)
  {
   theory = "RS #rightarrow WW, #Gamma = "+swidth;
   if(dependsOnKtilde)
    {
      theory = "RS #rightarrow WW, #tilde{k} = "+sktilde;
    }
  }
  
  leg->AddEntry(grgreen,"Expected (95%)","f");
  leg->AddEntry(gryellow,"Expected (68%)","f");
  leg->AddEntry(limit,"observed","L");
  leg->AddEntry(N,theory.c_str(),"L");
  leg->Draw("same");
  
  TLatex CMS;
  int y = 1050;
  int x = 500;
  int x2 = 3400;
  if(decayMode.find("jjjj")!= string::npos){y=1050;x=1000;x2=3000;}
  CMS.SetTextFont(43);
  CMS.SetTextSize(18);
  CMS.DrawLatex(x,y,cms.c_str());
  CMS.DrawLatex(x2,y,lumitext.c_str());
  
  c_N->Update();
  if(dependsOnKtilde)
  {
    c_N->SaveAs(("/usr/users/dschaefer/root/results/misc/"+ModelName+"_limit_"+decayMode+"_ktilde"+swidth+".pdf").c_str());
  }
  else
  {
  c_N->SaveAs(("/usr/users/dschaefer/root/results/misc/"+ModelName+"_limit_"+decayMode+"_"+swidth+".pdf").c_str());
  }
  
  
  //===========================================================================================
  //======== my own produced samples with ktilde = 0.095 ======================================
  //===========================================================================================
  
  
  
  float* acc2 = getAcceptance(decayMode,0.095);
  float* xs_new = getTheoryCrossSection(ModelName,0.095);
  
  for(int i=0;i<10;i++)
  {
   std::cout << " acceptance int : " << acceptance[i] <<std::endl;
   std::cout << " acceptance 2   : " << acc2[i] << std::endl;
  }
  
   // TGraph* testa
   // TCanvas* test2 = new TCanvas("test2","test2",400,400);
//   obsl->Draw("AL");
//   Neve->Draw("LSAME");
  
  float* N_expected2 = getNumberOfExpectedEvents(xs_new,m_xs,acc2,ModelName,decayMode);
  TGraph* obsl = getObservedLimit(ModelName,decayMode,0.095,1);
  TGraph* Neve = new TGraph(10,m_xs,N_expected2);
  

  
  
  TGraph* pl = getExcludedPoints(ModelName,decayMode,obsl,Neve,0.095);
  pl->SetLineWidth(3);
  pl->SetLineColor(kWhite);
  //pl->SetFillStyle(3013);
  //pl->SetFillColor(kWhite);
  
  string channel = "had";
  if(decayMode.find("lvjj")!=std::string::npos)
  {
   channel = "em"; 
  }
  
  TFile* file = new TFile(("/home/dschaefer/CMSSW_7_1_5/src/HiggsAnalysis/CombinedLimit/graphs_"+channel+".root").c_str(),"READ");
  string histoname = "ExclusionLimitOnEventNumber_BulkG_WW_em_HP";
  if(channel.find("had")!=std::string::npos)
  {
   histoname =  "ExclusionLimitOnEventNumber_BulkWW_had_HP";
  }
  TH2F* obsLim = dynamic_cast<TH2F*>(file->Get(histoname.c_str()));
  TCanvas* MyC = new TCanvas("MyC","MyC",800,600);
  MyC->SetRightMargin(0.19);
//   MyC->SetLeftMargin(0.12);
//   MyC->SetTopMargin(0.08);
//   MyC->SetBottomMargin(0.15);
  MyC->SetLogz();
  obsLim->Draw("COLZ");
  //pl->Draw("f");
  pl->Draw("Same");
  
  std::map<float,float> mass_acc;
  for(int i=0;i<10;i++)
  {
   mass_acc.insert(std::pair<float, float>(m_xs[i],acc2[i]));   
  }
  TGraph* allpoints = findAllExcludedPoints(ModelName,decayMode, mass_acc,0.095);
  MyC->cd();
  allpoints->Draw("Psame");
  
  
  float massmax = 4500;
  float massmin = 800;
  int n = (massmax-massmin)/100;
  float* k = new float[n*2];
  int t=0;
  for(int i=0;i<=n;i++)
  {
    k[i] = getKtilde("RSGrav",massmin+i*100,0.3);
    std::cout << "mass max: "<< massmin+i*100 << " ktilde " << k[i]<<std::endl;
  }
  for(int i=n;i<2*n;i++)
  {
   k[i] = getKtilde("RSGrav",massmin+(i-n)*100,0.02);
   std::cout << " mass min : "<< massmin+(i-n)*100 << " ktilde " << k[i] << std::endl;
  }
  
  printWidthForKtilde("RSGrav",0.12,3600,800);
  printWidthForKtilde("RSGrav",0.2 ,2400,800);
  printWidthForKtilde("RSGrav",0.3 ,1800,800);
  printWidthForKtilde("RSGrav",0.4 ,1500,800);
  printWidthForKtilde("RSGrav",0.5 ,1100 ,800);
  printWidthForKtilde("RSGrav",0.05,4500,2000);
  printWidthForKtilde("RSGrav",0.03,4600,3200);
  
}
int evaluate( std::string filelist, std::string outfile )
{
  gStyle->SetOptStat(0);

  TCanvas *ctemp = new TCanvas();

  TCanvas *cres = new TCanvas("TimeDependence");
  TH1F* hres = new TH1F("hres","",100,0,650);
  hres->GetYaxis()->SetRangeUser(0,50);
  hres->SetTitle("");
  hres->GetXaxis()->SetTitle("time (s)");
  hres->GetYaxis()->SetTitle("B_{int} (mT)");
  hres->Draw();
  leg = new TLegend(0.2,0.6,0.9,0.9);
//  leg->SetHeader("The Legend Title"); // option "C" allows to center the header
  leg->SetNColumns(5);

  vector< double > v_Bint;
  vector< double > v_BintErr;
  vector< double > v_Bext;
  vector< double > v_BextErr;

  /* Loop over all lines in input file */
  std::ifstream infilelist(filelist);
  std::string line;

  unsigned colorcounter=38;

  while (std::getline(infilelist, line))
  {
    // skip lines with '#' and empty lines
    if ( line.find("#") != string::npos )
      {
        cout << "Skip line " << line << endl;
        continue;
      }

    if ( line == "" )
      continue;

    //cout << "Processing file " << line << endl;


    TString infilename("data_calib/");
    infilename.Append(line);

    TFile *fin = new TFile( infilename );
    TTree *tin = (TTree*)fin->Get("t");

    ctemp->cd();
    tin->Draw("Bi:time");
    TGraph *gtime = new TGraph(tin->GetEntries(), &(tin->GetV2()[0]), &(tin->GetV1()[0]));
    gtime->SetLineColor(colorcounter);
    colorcounter++;

    TH1F* hBext = new TH1F("hBext","",100,0,1000);
    tin->Draw("Bo >> hBext");

    cres->cd();
    gtime->Draw("lsame");

    double Bext_i = hBext->GetMean();
    double BextErr_i = hBext->GetRMS();

    double Bint_i = gtime->Eval(590);
    double BintErr_i = 0;

    /* add legend entry */
    TString legname("B_ext ~ ");
    legname += (int)Bext_i;
    leg->AddEntry(gtime,legname,"l");

    cout << "B_ext: " << Bext_i << " \t B_int: " << Bint_i << endl;

    v_Bint.push_back(Bint_i);
    v_BintErr.push_back(BintErr_i);
    v_Bext.push_back(Bext_i);
    v_BextErr.push_back(BextErr_i);

  }

  cres->cd();
  leg->Draw();

  TGraphErrors *gfinal = new TGraphErrors(v_Bext.size(), &(v_Bext[0]), &(v_Bint[0]), &(v_BextErr[0]), &(v_BintErr[0]));
  gfinal->Sort();
  gfinal->SetName("Bint_Vs_Bext");
  gfinal->SetTitle("");
  gfinal->GetXaxis()->SetTitle("B_{ext} (mT)");
  gfinal->GetYaxis()->SetTitle("B_{int} (mT)");

  TCanvas *cfinal = new TCanvas();
  gfinal->Draw("APL");

  /* Save output graph */
  TString outfilename("output/");
  outfilename.Append(outfile);
  TFile *fout = new TFile(outfilename,"RECREATE");

  cres->Write();
  gfinal->Write();

  fout->Close();

  /* Write result to txt output file */
  TString outfilenametxt = outfilename;
  outfilenametxt.ReplaceAll(".root",".txt");

  ofstream foutxt;
  foutxt.open( outfilenametxt );
  foutxt <<  "# Bo sig_Bo Bi sig_Bi shield sig_shield sf sig_sf time_dependent" << endl;

  for ( int i = 0; i < gfinal->GetN(); i++ )
  {
    double Bo = gfinal->GetX()[i];
    double sig_Bo = gfinal->GetEX()[i];
    double Bi = gfinal->GetY()[i];
    double sig_Bi = gfinal->GetEY()[i];
    double shield = 0;
    double sig_shield = 0;
    double sf = 0;
    double sig_sf = 0;
    double time_dependent = 0;

    foutxt <<  Bo << " " << sig_Bo << " " << Bi << " " << sig_Bi << " "
         << shield << " " << sig_shield << " " << sf << " " << sig_sf
         << " " << time_dependent << endl;
  }

  return 0;
}
void decon_ind(Int_t chan = 221){
  TFile *file = new TFile("Run_00009188.root");
  TH2* h1 = (TH2*)file->Get(Form("Ind_%d",chan));
  TH2* h3 = (TH2*)h1->Clone("h3");
  TH2* h4 = (TH2*)h1->Clone("h4");
  
  h3->Reset();
  h4->Reset();

  gStyle->SetOptStat(0);

  TCanvas *c1 = new TCanvas("c1","c1",800,800);
  c1->Divide(2,2);
  c1->cd(1);
  h1->Draw("COLZ");
  h1->GetZaxis()->SetRangeUser(-80,80);
  h1->GetXaxis()->SetRangeUser(0,3000);

  h1->SetTitle("Original Induction");
  h3->SetTitle("Noise Removed Induction");
  
  Int_t max_bin = h1->GetMaximumBin();
  Float_t max = h1->GetBinContent(max_bin);
  Int_t min_bin = h1->GetMinimumBin();
  Float_t min = h1->GetBinContent(min_bin);
  
  TH1F *h2 = new TH1F("h2","h2",Int_t(max - min+2), min-1, max+1);
  
  //cout << h1->GetXaxis()->GetNbins() << " " << h1->GetYaxis()->GetNbins() << endl;
  for (Int_t i=0;i!=h1->GetXaxis()->GetNbins();i++){
    h2->Reset();
    for (Int_t j=0;j!=h1->GetYaxis()->GetNbins();j++){
      h2->Fill(h1->GetBinContent(i,j));
    }
    Double_t xq = 0.5;
    Double_t par[10];
    h2->GetQuantiles(1,&par[0],&xq);
    
    for (Int_t j=0;j!=h1->GetYaxis()->GetNbins();j++){
      h3->SetBinContent(i,j,h1->GetBinContent(i,j)-par[0]);
    }
    //cout << par[0] << endl;
    
  }
  c1->cd(2);
  h3->Draw("COLZ");
  h3->GetXaxis()->SetRangeUser(0,3000);
  

  // do deconvolution for every channel ...
  c1->cd(3);
  TFile *file1 = new TFile("ave_res.root");
  TH1F *hva = (TH1F*)file1->Get("hu");
  TGraph *gva = new TGraph();
  for (Int_t i=0;i!=hva->GetNbinsX();i++){
    Double_t x = hva->GetBinCenter(i+1);
    Double_t y = hva->GetBinContent(i+1) * (-1);
    gva->SetPoint(i,x,y);
  }
  TH1F *h2t = new TH1F("h2t","h2t",h1->GetXaxis()->GetNbins(),0,h1->GetXaxis()->GetNbins());
  TH1F *h2r = (TH1F*)h2t->Clone("h2r");
  h2r->Reset();
  for (Int_t i=0;i!=h2r->GetNbinsX();i++){
     Double_t x = h2r->GetBinCenter(i+1)/2.-50;
     h2r->SetBinContent(i+1,gva->Eval(x));
  }
  TF1 *filter_v = new TF1("filter_v","(x>0.0)*gaus*exp(-0.5*pow(x/[3],[4]))");
  double par1[5]={1.74/0.941034, 1.46, 1.33, 0.23, 4.89};
  filter_v->SetParameters(par1);

  TVirtualFFT::SetTransform(0);
  TH1 *hmr = 0;
  TH1 *hpr = 0;
  Int_t n = 8192;
  TVirtualFFT *ifft = TVirtualFFT::FFT(1,&n,"C2R M K");
  Double_t value_re[8192];
  Double_t value_im[8192];
  TH1 *fb = 0;
  TH1 *hmv = 0;
  TH1 *hpv = 0;

  for (Int_t k=0;k!=h1->GetYaxis()->GetNbins();k++){
  // for (Int_t k=33;k!=33+1;k++){
    h2t->Reset();
    for (Int_t i=0;i!=8192;i++){
      float content = h3->GetBinContent(i+1,k+1);
      h2t->SetBinContent(i+1,content);
    }
    h2t->Draw();

    cout << h2t->Integral(500,1500) << endl;
    //cout << max << " " << min << endl;
    hmr = 0;
    hpr = 0;
    hmr = h2r->FFT(hmr,"MAG");
    hpr = h2r->FFT(hpr,"PH");
    
    hmv = 0;
    hpv = 0;
    hmv = h2t->FFT(hmv,"MAG");
    hpv = h2t->FFT(hpv,"PH");
    
    for (Int_t j=0;j!=8192;j++){
      Double_t freq;
      if ( j < 8192/2.){
	freq = j/8192.*2.;
      }else{
	freq = (8192-j)/8192.*2.;
      }
      Double_t rho;
      if (hmr->GetBinContent(j+1)!=0){
	rho = hmv->GetBinContent(j+1) / hmr->GetBinContent(j+1)*filter_v->Eval(freq);
      }else{
	rho = 0;
      }
      Double_t phi = hpv->GetBinContent(j+1) - hpr->GetBinContent(j+1);
      value_re[j] = rho*cos(phi)/8192.;
      value_im[j] = rho*sin(phi)/8192.;
    }
    
    ifft->SetPointsComplex(value_re,value_im);
    ifft->Transform();
    fb = 0;
    fb = TH1::TransformHisto(ifft,fb,"Re");
    
    Double_t sum = 0;
    Double_t sum1 = 0;
    for (Int_t i=5000;i!=8000;i++){
      sum += fb->GetBinContent(i+1);
      sum1 += 1;
    }
    

    for (Int_t i=0;i!=8192;i++){
      Int_t binnum = i+1+104;
      if (binnum > 8192) binnum -=8192;
      h4->SetBinContent(binnum,k+1,fb->GetBinContent(i+1)-sum/sum1);
    }
  }


  h3->GetZaxis()->SetRangeUser(0,100);

  c1->cd(3);
  h4->RebinX(4);
  for (Int_t i=0;i!=h4->GetXaxis()->GetNbins();i++){
    for (Int_t j=0;j!=h4->GetYaxis()->GetNbins();j++){
      Double_t content1 = h4->GetBinContent(i+1,j+1);
      // if (content1 <1)
  	//	h4->SetBinContent(i+1,j+1,1);
    }
  }
  h4->Draw("COLZ");
  h4->GetZaxis()->SetRangeUser(0,30);
  h4->GetXaxis()->SetRangeUser(0,3000);
  c1->cd(4);
  TH2 *h5 = (TH2*)file->Get(Form("Col_%d",chan));
  h5->Draw("COLZ");
  h5->GetZaxis()->SetRangeUser(0,300);
  h5->GetXaxis()->SetRangeUser(0,3000);
  c1->cd(2);
  for (Int_t i=0;i!=h3->GetXaxis()->GetNbins();i++){
    for (Int_t j=0;j!=h3->GetYaxis()->GetNbins();j++){
      Double_t content1 = h3->GetBinContent(i+1,j+1);
      content1 = fabs(content1);
      h3->SetBinContent(i+1,j+1,content1);
    }
  }
  h3->Draw("COLZ");

  h4->SetTitle("Deconvoluted Induction");
  h5->SetTitle("Collection Raw");
  
  // c1->cd(1);
  // h2r->Draw();

  // c1->cd(4);
  // Double_t sum = 0;
  // Double_t sum1 = 0;
  // for (Int_t i=4000;i!=7000;i++){
  //   sum += fb->GetBinContent(i+1);
  //   sum1 += 1;
  // }
  // TH1F *h2k = (TH1F*)h2t->Clone("h2k");
  // for (Int_t j=0;j!=8192;j++){
  //   h2k->SetBinContent(j+1,fb->GetBinContent(j+1)-sum/sum1);
  // }
  // h2k->Rebin(4);
  // h2k->Draw();
  

}
예제 #18
0
//____________________________________________________________________________________
// Plot blue band (SM Higgs curve)
void blueBand( )
{

  double zerror = 4;
  double xmin = 76;

  int npoints = 31;
  double x[] = { 10.000000, 11.392849, 12.979700, 14.787576, 16.847262, 19.193831, 21.867241, 
                 24.913018, 28.383024, 32.336350, 36.840315, 41.971614, 47.817625, 54.477897,
                 62.065844, 70.710678, 76, 80.559606, 91.780341, 104.563955, 119.128133, 135.720881,
                 154.624747, 176.161637, 200.698289, 228.652526, 260.500365, 296.784127, 
                 338.121669, 385.216905, 438.871795, 500.000000 };

  double y[] = { 20.929260, 18.757168, 16.647426, 14.611732, 12.661571, 10.808107, 9.062193,
                 7.434501, 5.935701, 4.576664, 3.368675, 2.323612, 1.454084, 0.776111,
                 0.300018, 0.042673, 0.0001, 0.020469, 0.251087, 0.750519, 1.538231, 2.633789,
                 4.056692, 5.826546, 7.962673, 10.483595, 13.406320, 16.745357, 20.511276,
                 24.717583, 29.345917, 34.380810 };


  TGraph* smGraph = new TGraph( npoints, x, y );

  if ( npoints > MAXPOINTS ) {
    std::cerr << "FATAL: npoints = " << npoints << " is greater than MAXPOINTS" << std::endl;
    exit(-1);
  }
  double x1[2*MAXPOINTS], y1[2*MAXPOINTS];
  double x2[MAXPOINTS], y2[MAXPOINTS];

  // Find mH at minimum
  int i1=0; // iterator for upper curve
  int i2=0; // iterator for lower curve
  double x0,y0;
  double step = 5;
  smGraph->GetPoint( 0, x0, y0 );
  for ( int i=0; i<100; ++i )
    {
      double ix = x0+i*step;
      double iy = smGraph->Eval( ix, 0, "S" );
      double error = TMath::Log( ix/12. )*3.;
      if ( ix<=xmin-error ) { 
        x1[i1] = ix+error; y1[i1]=iy; ++i1; 
        x2[i2] = ix-error; y2[i2]=iy; ++i2;
      }
      else if ( ix>=xmin+error) { 
        x1[i1] = ix-error; y1[i1]=iy; ++i1; 
        x2[i2] = ix+error; y2[i2]=iy; ++i2;
      } else {//if ( iy>0. ) {
        x2[i2] = (ix<=xmin)?ix-error:ix+error; 
        y2[i2]=iy; 
        ++i2;
      }
      
    }
  // Merge arrays
  for ( int i=0; i<i2; ++i ) {
    x1[i+i1] = x2[i2-i-1];
    y1[i+i1] = y2[i2-i-1];
  }
  if ( doBands ) {
    TGraph* blueBand = new TGraph( i1+i2, x1, y1 );
    blueBand->SetFillColor(7);
    blueBand->SetLineColor(7);
    blueBand->Draw("LF");
    blueBand->Draw("C");
  } else {
    smGraph->SetLineWidth(5);
  }

  smGraph->SetLineColor(4);
  smGraph->Draw("C");
  double chi2limit = smGraph->Eval( LEPLIMIT, 0, "S" );
  std::cout << "Value at limit (" << LEPLIMIT << "): " << chi2limit << std::endl;

  TGraph* lowband = new TGraph( i2, x2, y2 );
  std::cout << "Value of (low) blueband at limit: " << lowband->Eval( LEPLIMIT, 0, "S" )
            << std::endl;

}
예제 #19
0
void
ModXSec(string inFile, string outFile, bool removeTaus=true, bool applyKFactors=true){
  bool doTC = inFile.find("TC") != string::npos;
  cout<<"doTC is "<<doTC<<endl;

  TTree* tLimit = new TTree("tLimit", "Limits");
  tLimit->ReadFile(inFile.c_str());

  ofstream out(outFile.c_str());

  if(doTC)  out<<"Rho/F:";
  else      out<<"Mass/F:";
  if(doTC){
    out<<"Pi/F:";
    out<<"SinX/F:";
  }
  out<<"Xsec/F:"
     <<"percentError/F"
     <<endl;

  //kfactors
  TGraph* gK = new TGraph(20);
  gK->SetPoint( 0, 200,1.347);
  gK->SetPoint( 1, 300,1.347);
  gK->SetPoint( 2, 500,1.363);
  gK->SetPoint( 3, 700,1.351);
  gK->SetPoint( 4, 900,1.347);
  gK->SetPoint( 5,1100,1.331);
  gK->SetPoint( 6,1300,1.317);
  gK->SetPoint( 7,1500,1.293);
  gK->SetPoint( 8,1700,1.257);
  gK->SetPoint( 9,1900,1.230);
  gK->SetPoint( 10,2000,1.214);

  //Signal pdf uncertainties
  TGraph* gPerErr = new TGraph(20);
  gPerErr->SetPoint(  0, 200,2.192);
  gPerErr->SetPoint(  1, 300,2.192);
  gPerErr->SetPoint(  2, 500,2.632);
  gPerErr->SetPoint(  3, 700,3.070);
  gPerErr->SetPoint(  4, 900,3.448);
  gPerErr->SetPoint(  5,1100,3.771);
  gPerErr->SetPoint(  6,1300,4.101);
  gPerErr->SetPoint(  7,1500,4.339);
  gPerErr->SetPoint(  8,1700,4.581);
  gPerErr->SetPoint(  9,1900,4.846);
  gPerErr->SetPoint( 10,2000,4.981);
  
  if(doTC) tLimit->Draw("Rho:Xsec:Pi:SinX", "SinX > 0.32 && SinX<0.34", "para goff");
  //if(doTC) tLimit->Draw("Rho:Xsec:Pi:SinX", "(280<=Rho && Rho<=300) && (150<=Pi && Pi<=160)", "para goff");
  else     tLimit->Draw("Mass:Xsec",        "", "para goff");
  float n = tLimit->GetSelectedRows(); 
  for(int isample=0; isample<n; ++isample){
    int idx=0;
    Double_t mass = tLimit->GetVal(idx++)[isample];
    Double_t xsec  = tLimit->GetVal(idx++)[isample];

    Double_t pi(-1), sinx(-1);
    if(doTC){
      pi   = tLimit->GetVal(idx++)[isample];
      sinx = tLimit->GetVal(idx++)[isample];
    }

    //cout<<"For rho: "<<rho<<" the kfactor is "<<gK->Eval(rho)<<endl; 
    
    //xsec *= 1e9; //convert from mb to pb
    if(removeTaus) xsec *= 4./9.; //convert from emt to em
    if(applyKFactors) xsec *= gK->Eval(mass);//apply k factor

    Double_t perErr  = gPerErr->Eval(mass);

    out.precision(0) ;
    out.setf ( ios::fixed, ios::floatfield);
    out  <<mass<<"\t";

    if(doTC){
      out.precision(0) ;
      out.setf ( ios::fixed, ios::floatfield);
      out  <<pi<<"\t";

      out.precision(4) ;
      out.setf ( ios::fixed, ios::floatfield);
      out  <<sinx<<"\t";
    }

    out.precision(4) ;
    out.setf ( ios::scientific, ios::floatfield);
    out  <<xsec<<"\t";
    
    out.precision(3);
    out.setf ( ios::fixed, ios::floatfield);
    out<<perErr<<"\t";
    out<<endl;

  }

}