void explore_zmass_boost()
{
  // Tell root not to draw everything to the screen.
  gROOT->SetBatch();

  //    TString dyfilename         = TString("/home/acarnes/h2mumu/samples/stage1/monte_carlo/bg/stage_1_dy_jetsToLL_asympt50_ALL.root");
  TString dyfilename         = TString("/home/acarnes/h2mumu/samples/stage1/monte_carlo/bg/stage_1_dy_ZToMuMu_asympt50_ALL.root");
  TString datafilename         = TString("/home/acarnes/h2mumu/samples/stage1/data_from_json/Cert_246908-251883_13TeV_PromptReco_Collisions15_JSON_v2/stage_1_doubleMuon_RunBPrompt_MINIAOD.root");

  TString savedir = TString("../png/dy_vs_data/run1cuts_v2_golden_json/dyzmumu/");

  // Initialize the DiMuPlottingSystems for MC and data
  DiMuPlottingSystem* dpsdata = new DiMuPlottingSystem(datafilename);
  DiMuPlottingSystem* dpsdy = new DiMuPlottingSystem(dyfilename);
  addDiMuMassPrimeBranch(dpsdata);
  dpsdata->applyRun1Cuts();
  dpsdy->applyRun1Cuts();

  // Get the 2D histos
  TH2F* hdataZPt = ZMassVsZPtHist2D("data_zpt", "recoCandMassPrime", "(14,0,60,30,87,95)", dpsdata);
  TH2F* hdyZPt = ZMassVsZPtHist2D("dy_zpt", "recoCandMass", "(14,0,60,30,87,95)", dpsdy);

  //overlayTProfiles(TH2F* hdata, TH2F* hdy, TString bininfo, TString savename)
  TProfile* p = overlayTProfiles(hdataZPt, hdyZPt, 90, 92, savedir+"z_mass_vs_z_pt.png");
  gStyle->SetOptFit(0011);
  fitTProfileCustom(p);
  TCanvas* c = new TCanvas();
  c->cd();
  p->Draw("hist c");
  p->Draw("E0 X0 same");
  dpsdata->arrangeStatBox(c);
  c->Draw();
  c->Print("blah2.png");

  // Look at RMS
  c->Clear();
  c->cd();
  c->SetGridx(kTRUE);
  c->SetGridy(kTRUE);
  c->cd();
  TH1F* h = dpsdata->hist1D("recoCandMass", "(100,87,95)", "");
  TH1F* h2 = dpsdata->hist1D("recoCandMassPrime", "(100,87,95)", "");
  h2->SetLineColor(2);
  h->Draw("");
  h2->Draw("same");

  std::cout << "mass  rms: " << h->GetRMS() << std::endl;
  std::cout << "mass' rms: " << h2->GetRMS() << std::endl;
  std::cout << "mass  mean: " << h->GetMean() << std::endl;
  std::cout << "mass' mean: " << h2->GetMean() << std::endl;
  std::cout << "mass  num: " << h->Integral() << std::endl;
  std::cout << "mass' num: " << h2->Integral() << std::endl;

  DiMuPlottingSystem* dps = new DiMuPlottingSystem();
  dps->arrangeStatBox(c);
  c->Draw();
  c->Print("newfit.png");
}
void __fastcall TfrmMainFormServer::lstModulesDrawItem(
      TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
{
    TRect cRect(0, 0, lstModules->Width, lstModules->Height);


    TCanvas*        pCanvas     = ((TListBox*)Control)->Canvas;

    pCanvas->FillRect(Rect);  //This clears the rect

    Graphics::TBitmap* bitmap = new Graphics::TBitmap();
    AnsiString moduleName = lstModules->Items->Strings[Index];

    if(Index == 0){
        imgList->GetBitmap(1, bitmap);    //table image
    }else{
        imgList->GetBitmap(0, bitmap);    //table image
    }

    
    pCanvas->Draw(Rect.Left + 1, Rect.Top, bitmap);
    delete bitmap;

    pCanvas->TextOut(Rect.Left + 22, Rect.Top + 2, moduleName);


}
Example #3
0
TF1 * iterateFitter(TH1F * histo, int i, TF1 * previousResiduals = 0, TCanvas * inputCanvas = 0)
{
  TCanvas * canvas = inputCanvas;
  std::stringstream ss;
  int iCanvas = i;
  ss << i;

  int nBins = histo->GetNbinsX();

  TF1 * functionToFit;
  if( previousResiduals == 0 ) {
    // functionToFit = relativisticBWFit(ss.str());
    // functionToFit = relativisticBWintFit(ss.str());
    // functionToFit = relativisticBWintPhotFit(ss.str());
    functionToFit = expRelativisticBWintPhotFit(ss.str());
    // functionToFit = crystalBallFit();
    // functionToFit = reversedCrystalBallFit();
    // functionToFit = lorentzianFit();
    // functionToFit = relativisticBWFit();
  }
  else {
    functionToFit = combinedFit(previousResiduals->GetParameters(), ss.str());
  }
  histo->Fit(functionToFit, "MN", "", 60, 120);


  double xMin = histo->GetXaxis()->GetXmin();
  double xMax = histo->GetXaxis()->GetXmax();
  double step = (xMax-xMin)/(double(nBins));
  TH1F * functionHisto = new TH1F(("functionHisto"+ss.str()).c_str(), "functionHisto", nBins, xMin, xMax);
  for( int i=0; i<nBins; ++i ) {
    functionHisto->SetBinContent( i+1, functionToFit->Eval(xMin + (i+0.5)*step) );
  }

  if( canvas == 0 ) {
    canvas = new TCanvas(("canvasResiduals"+ss.str()).c_str(), ("canvasResiduals"+ss.str()).c_str(), 1000, 800);
    canvas->Divide(2,1);
    canvas->Draw();
    iCanvas = 0;
  }
  canvas->cd(1+2*iCanvas);
  histo->Draw();
  functionToFit->SetLineColor(kRed);
  functionToFit->Draw("same");
  // functionHisto->Draw("same");
  // functionHisto->SetLineColor(kGreen);
  canvas->cd(2+2*iCanvas);
  TH1F * residuals = (TH1F*)histo->Clone();
  residuals->Add(functionHisto, -1);
  residuals->SetName("Residuals");

  // TF1 * residualFit = new TF1("residualFit", "-[0] + [1]*x+sqrt( ([1]-1)*([1]-1)*x*x + [0]*[0] )", 0., 1000. );
  // TF1 * residualFit = new TF1("residualFit", "[0]*(x - [1])/([2]*x*x + [3]*x + [4])", 0., 1000. );
  TF1 * residualFitFunction = residualFit(ss.str());
  residuals->Fit(residualFitFunction, "ME", "", 90.56, 120);

  residuals->Draw();

  return residualFitFunction;
}
Example #4
0
void improveHisto(TFile * inputFile, const TString & histoName, TFile * inputFile2, const TString & histoName2)
{
  TH1F * histo = (TH1F*)inputFile->FindObjectAny(histoName);
  TCanvas * canvas = new TCanvas();
  canvas->Draw();
  histo->Draw();
  histo->GetXaxis()->SetTitle("#eta");
  histo->GetXaxis()->SetTitleOffset(1.1);
  histo->GetXaxis()->SetRangeUser(-1.5, 1.5);
  double binWidth = histo->GetXaxis()->GetBinWidth(1);
  stringstream ss;
  ss << binWidth;
  histo->GetYaxis()->SetTitle(TString("Efficiency/("+ss.str()+")"));
  histo->GetYaxis()->SetTitleOffset(1.1);
  histo->GetYaxis()->SetRangeUser(0., 1.1);
  TH1F * histo2 = (TH1F*)inputFile2->FindObjectAny(histoName2);
  histo2->Draw("same");
  histo2->SetMarkerColor(kRed);
  TLegend * legend = new TLegend(0.5, 0.67, 0.88, 0.88);
  legend->AddEntry(histo, "top");
  legend->AddEntry(histo2, "bottom");
  legend->Draw("same");
  legend->SetFillColor(kWhite);
  legend->SetBorderSize(0);
  canvas->Write();
}
Example #5
0
void improveHisto(TFile * inputFile, const TString & histoName, const TString & histoName2 = "")
{
    TH1F * histo = (TH1F*)inputFile->FindObjectAny(histoName);
    TCanvas * canvas = new TCanvas();
    canvas->Draw();
    histo->Draw();
    histo->GetXaxis()->SetTitle("|d_{0}| [cm]");
    histo->GetXaxis()->SetTitleOffset(1.1);
    histo->GetXaxis()->SetRangeUser(0., 50.);
    double binWidth = histo->GetXaxis()->GetBinWidth(1);
    stringstream ss;
    ss << binWidth;
    histo->GetYaxis()->SetTitle(TString("Efficiency/("+ss.str()+" cm)"));
    histo->GetYaxis()->SetTitleOffset(1.1);
    histo->GetYaxis()->SetRangeUser(0., 1.1);
    if( histoName2 != "" ) {
        TH1F * histo2 = (TH1F*)inputFile->FindObjectAny(histoName2);
        histo2->Draw("same");
        histo2->SetMarkerColor(kRed);
        TLegend * legend = new TLegend(0.5, 0.67, 0.88, 0.88);
        legend->AddEntry(histo, "cosmicMuons1Leg");
        legend->AddEntry(histo2, "MC truth");
        // TLegend * legend = canvas->BuildLegend();
        legend->Draw("same");
        legend->SetFillColor(kWhite);
        legend->SetBorderSize(0);
    }
    canvas->Write();
}
Example #6
0
//===========================================================================
void TWave::DrawElementFace()
{
    TCanvas    *dbCanvas = VisualElementParam->Bitmap->Canvas;
    int         aw       = VisualElementParam->Width;
    int         ah       = VisualElementParam->Height;

    dbCanvas->Brush->Color = clWhite;
    dbCanvas->Pen  ->Color = clBlack;

    dbCanvas->Rectangle(0, 0, aw, ah);

    // --------- Отрисовка прямоугольника --- (прямокгольник процесса разработки) -----
    if (DesignPhase != dpAllreadyTesting) {
        if (DesignPhase == dpNotTesting  ) {
            dbCanvas->Pen  ->Color = clRed;
        }
        if (DesignPhase == dpNeedModified) {
            dbCanvas->Pen  ->Color = clRed;
            dbCanvas->Pen  ->Style = psDot;
        }

        dbCanvas->Rectangle(2, 2, VisualElementParam->Width - 2, VisualElementParam->Height - 2);

        dbCanvas->Pen->Color = clBlack;
        dbCanvas->Pen->Style = psSolid;
    }
    // -------------- Отрисовка ресурса если он есть ----------
    dbCanvas->Draw((aw - ResourseBitmapFaceElement->Width) / 2, (ah - ResourseBitmapFaceElement->Height) / 2,ResourseBitmapFaceElement);
}
Example #7
0
void makePassFail_QCDMC(const string njetlabel= "XX")
{

	//dphioption == 0 for dphimin<0.2

	

	vector<string> folders, htbinlabels, dphibins;
	folders.push_back("Hist/HT0to500MHT0to7000");
	folders.push_back("Hist/HT500to7000MHT0to7000");
	//folders.push_back("Hist/HT500to900MHT0to7000");
	//folders.push_back("Hist/HT900to1300MHT0to7000");
	//folders.push_back("Hist/HT1300to7000MHT0to7000");

	htbinlabels.push_back("HT0to500");
	htbinlabels.push_back("HT500to900");
	htbinlabels.push_back("HT900to1300");
	htbinlabels.push_back("HT1300to7000");

	dphibins.push_back("0.15");
	dphibins.push_back("0.20");
	dphibins.push_back("0.25");
	dphibins.push_back("0.30");
	dphibins.push_back("0.35");
	dphibins.push_back("0.40");

	OpenFiles();
	TCanvas *c = new TCanvas("print");	
	c->Draw();
	c->Print("ratios.eps[");
	
	for (unsigned d = 0; d < dphibins.size(); ++d)
	{	
		for (unsigned i = 0; i < folders.size(); ++i)
		{	
//			for (unsigned j = 0; j < htbinlabels.size(); ++j)
			{
				string htrange("");
				if (i==0) htrange += "0<HT<500 GeV";
				else if (i==1) htrange += "500<HT<7000 GeV";
				//else if (i==1) htrange += "500<HT<900 GeV";
				//else if (i==2) htrange += "900<HT<1300 GeV";
				//else if (i==3) htrange += "1300<HT<7000 GeV";

				cout << " >>>>>>>>>>> " << htrange << endl; 
				stringstream title, numeHistName, denoHistName, signalHistName, controlHistName;
				//title << htrange << ";#slash{H}_{T};Ratio (r) = Pass(RA2 dPhi cuts) / Fail(#Delta #phi_{min}< 0.2);";
				title << "Njet " << njetlabel << ", " << htrange << ", #Delta #Phi _{min}<" << dphibins.at(d);
				numeHistName << folders.at(i) << "/signal";
				//denoHistName << folders.at(i) << "/fail1";
				denoHistName << folders.at(i) << "/fail" << d;
				signalHistName << folders.at(i) << "/signalFineBin";
				controlHistName << folders.at(i) << "/failFineBin" << d;
				makePassFail_QCDMC(numeHistName.str(), denoHistName.str(), title.str(), htbinlabels.at(i), signalHistName.str(), controlHistName.str()); 
			}
		}
	}
	c->Print("ratios.eps]");
}
void comparecfback(TString file1, TString file2, TString histname1, TString histname2, TString histname3,TString sys) {

  TFile* ifile1_ = new TFile(Form("%s",file1.Data()), "read");
  TFile* ifile2_ = new TFile(Form("%s",file2.Data()), "read");

  TH1D* hist1;
  TH1D* hist2;
  TH1D* hist3;

  // if ( (strcmp(sys,"V0LL") == 0) || (strcmp(sys,"V0ALAL") == 0) || (strcmp(sys,"V0LAL") == 0)  ) {
  //   hist1 = (TH1D*)ifile1_->Get(Form("Numcqinv%stpcM%d%s",sys,mult,kT));
  //   hist2 = (TH1D*)ifile2_->Get(Form("Numcqinv%stpcM%d%s",sys,mult,kT));
  // }
  // else {
  hist1 = (TH1D*)ifile1_->Get(Form("%s",histname1.Data()));
  hist2 = (TH1D*)ifile2_->Get(Form("%s",histname2.Data()));
  hist3 = (TH1D*)ifile2_->Get(Form("%s",histname3.Data()));
  // }

  TCanvas *myCan = new TCanvas("asd","asd");
  myCan->Draw();
  myCan->cd();
  hist1->SetMarkerColor(kBlack);
  hist2->SetMarkerColor(kRed);
  hist3->SetMarkerColor(kBlue);
  hist1->SetMarkerStyle(20);
  hist2->SetMarkerStyle(20);
  hist3->SetMarkerStyle(20);
  hist1->SetMarkerSize(1.6);
  hist2->SetMarkerSize(1.6);
  hist3->SetMarkerSize(1.6);
  hist1->SetTitle("");
  hist1->GetXaxis()->SetRangeUser(0.,1.0);
  hist2->GetXaxis()->SetRangeUser(0.,1.0);
  hist3->GetXaxis()->SetRangeUser(0.,1.0);
  gStyle->SetOptStat(0);

  //hist1->Scale(1./1.026);//1.026, 1.05

    hist1->SetMaximum(1.015);
  hist1->SetMinimum(0.9425);
  hist1->GetXaxis()->SetTitleSize(0.05);
  hist1->GetYaxis()->SetTitleSize(0.05);
  hist1->Draw("p");
  hist2->Draw("psame");
  hist3->Draw("psame");
  TLatex Tl;
  Tl.SetTextAlign(23);
  Tl.SetTextSize(0.08);
  Tl.SetTextColor(kBlack);
  Tl.DrawLatex(0.5,0.995,"p#bar{p}");
  Tl.SetTextColor(kRed);
  Tl.DrawLatex(0.5,0.980,"p#bar{#Lambda}");
  Tl.SetTextColor(kBlue);
  Tl.DrawLatex(0.5,0.965,"#bar{p}#Lambda");

  myCan->SaveAs(Form("comp%s.eps",sys.Data()));
}
void compare_weights() {
  TFile pwhg("POWHEG/ee/ee_ttbarsignalplustau_pwhgbox_m172p5.root");
  TFile pwhg_pos("POWHEG/ee/ee_ttbarsignalplustau_pwhgbox_m172p5_posweights.root");
  TFile output("comparison_pwhg_weights.root","recreate");

  gDirectory->pwd();

  std::vector<std::string> histograms;

  histograms.push_back("VisGenTTBarpT"); // TTBar system pT
  histograms.push_back("VisGenTTBarMass"); // TTBar system Mass
  histograms.push_back("VisGenTTBarRapidity"); // TTBar Rapidity
  histograms.push_back("VisGenLeptonpT"); // Lepton pT
  histograms.push_back("VisGenLeptonEta"); // Lepton Eta
  histograms.push_back("VisGenBJetpT"); // BJet pT
  histograms.push_back("VisGenBJetRapidity"); // BJet Rapidity
  //histograms.push_back("VisGenJetMulti"); // Jet Multiplicity
  histograms.push_back("VisGenExtraJetpT"); // Additional Jet pT
  histograms.push_back("VisGenTTBar1stJetMass"); // Invariant Mass TTBar+1Jet  

  for(std::vector<std::string>::iterator hist = histograms.begin(); hist != histograms.end(); hist++) {
    
    std::cout << "Plotting " << (*hist) << "..." << std::endl;
    
    TCanvas *c = new TCanvas(hist->c_str(), hist->c_str());
    TH1D *sample_powhegbox = (TH1D*)pwhg.Get(hist->c_str());
    TH1D *sample_pwhg_pos = (TH1D*)pwhg_pos.Get(hist->c_str());
    sample_pwhg_pos->Scale(1/sample_pwhg_pos->Integral(),"width");
    sample_powhegbox->Scale(1/sample_powhegbox->Integral(),"width");

    bool rebin = true;
    
    if(rebin) {
      Int_t rebinning = 4;
      if((*hist) == "VisGenTTBar1stJetMass") { rebinning *= 4; }
      if((*hist) == "VisGenTTBarRapidity") { rebinning /= 2; }
      if((*hist) == "VisGenTTBarpT") { rebinning *= 10; }
      if((*hist) == "VisGenTTBarMass") { rebinning = 20; }

      sample_powhegbox->Rebin(rebinning);
      sample_pwhg_pos->Rebin(rebinning);
    }

    sample_powhegbox->Draw();
    sample_pwhg_pos->SetLineColor(kRed);
    sample_pwhg_pos->Draw("same");

    TLegend *leg = new TLegend(0.6,0.6,0.9,.9);
    leg->AddEntry(sample_powhegbox,"withnegweights 1","l");
    leg->AddEntry(sample_pwhg_pos,"withnegweights 0","l");
    leg->Draw();

    c->Draw();
    c->Write();
  }
}
Example #10
0
//______________________________________________________________________________
void flipPCB(const char* srcName)
{
  // flip PCB in X-direction

//  AliMpSlatMotifMap* srcMotifs = new AliMpSlatMotifMap;
//  AliMpSlatMotifMap* destMotifs = new AliMpSlatMotifMap;

  AliMpDataProcessor mp;
  AliMpDataMap* dataMap = mp.CreateDataMap("data");
  AliMpDataStreams dataStream(dataMap);
  
  AliMpSt345Reader reader(dataStream);

  AliMpPCB* src = reader.ReadPCB(srcName);
  
  if (!src) return;

  AliMpSlatMotifMap* destMotifs = reader.MotifMap();
  
  AliMpPCB* dest = flipX(*src,*destMotifs);
    
  if (!dest)
  {
    cout << "Flipping failed" << endl;
  }
  
  TCanvas* csrc = new TCanvas("src","src");
  csrc->Draw();
  AliMpVPainter* psrc = AliMpVPainter::CreatePainter(src);
  psrc->Draw("MZT");

  if ( dest ) 
  {
    TCanvas* cdest = new TCanvas("dest","dest");
    cdest->Draw();
    AliMpVPainter* pdest = AliMpVPainter::CreatePainter(dest);
    pdest->Draw("MZT");
    dest->Save();

  }
  
}
Example #11
0
TCanvas * plot (TH1F* histoDataIn, TString legendData, TH1F* histoSimulationIn, TString legendSimulation,
                TString & canvasName, Float_t maximum = 0.15, TString xAxisTitle = "#eta",
                TString yAxisTitle = "Number of Clusters", TString error = "", bool useLegend = true,
                TString text = "", Float_t textX = 0.7, Float_t textY = 0.4, Float_t rebin = 0 ) {

  TH1F * histoData = (TH1F*)histoDataIn->Clone();
  TH1F * histoSimulation = (TH1F*)histoSimulationIn->Clone();

  // histoData->Sumw2();
  histoData->Scale(1/(histoData->Integral()));
  histoSimulation->Scale(1/(histoSimulation->Integral()));

  // Create also the legend and add the histograms
  TLegend * legend = new TLegend( 0.55, 0.65, 0.76, 0.82 );
  legend->AddEntry( histoData, xAxisTitle );
  legend->AddEntry( histoSimulation, yAxisTitle, "F" );

  cout << "histoData = " << histoData << endl;
  cout << "histoSimulation = " << histoSimulation << endl;

  TCanvas * c = new TCanvas( canvasName, canvasName, 1000, 800 );
  c->Draw();

  histoSimulation->SetMaximum(maximum);

  histoSimulation->SetFillColor(kRed);
  // histoSimulation->SetLineWidth(0);
  histoSimulation->SetLineColor(kRed);
  histoSimulation->SetXTitle(xAxisTitle);
  histoSimulation->SetYTitle(yAxisTitle);
  histoSimulation->SetTitleOffset(1.6,"Y");
  histoSimulation->SetTitle();

  histoData->SetLineStyle(1);
  histoData->SetLineWidth(2.5);

  histoSimulation->Draw();
  histoData->Draw("same");

  legend->SetFillColor(kWhite);
  if (useLegend) legend->Draw("same");

  if ( text != "" ) {
    TPaveText * pt = new TPaveText(textX, textY, textX+0.2, textY+0.17, "NDC" ); // "NDC" option sets coords relative to pad dimensions
    pt->SetFillColor(0); // text is black on white
    pt->SetTextSize(0.08); 
    pt->SetBorderSize(0);
    pt->SetTextAlign(12);
    pt->AddText(text);
    pt->Draw("same");       //to draw your text object
  }

  return c;
};
Example #12
0
int main( int argc, char **argv ) {

  cout << endl;
  cout << " ** QuickHist 0.0.1 beta" << endl;
  cout << " ** If you want colors, comment out the gStyle option and recompile." << endl;
  cout << " ** Exit with ctrl-c" << endl;
  cout << endl;
    

  TApplication theApp("App", &argc, argv);
  gROOT->Reset();
  gROOT->SetStyle( "Plain" );
//  gStyle->SetFillColor( 0 );

   
  double buffer;
  vector<double> numbersVector;



  while( ! cin.eof() ) {
    cin >> buffer;
    if( cin.eof() ) break; // break if eof
    numbersVector.push_back( buffer );
  }


  double lowerLimit = 0.;
  double upperLimit = 0.;
  double lowerLimitBuf = numbersVector[0]; 
  double upperLimitBuf = numbersVector[0];

  for( unsigned int i = 0; i < numbersVector.size(); i++ ) {
    if( numbersVector[i] < lowerLimitBuf ) lowerLimitBuf = numbersVector[i];
    if( numbersVector[i] > upperLimitBuf ) upperLimitBuf = numbersVector[i];
  }
  
  // broadening the limits a little bit
  upperLimit = upperLimitBuf + .1 * ( upperLimitBuf - lowerLimitBuf );
  lowerLimit = lowerLimitBuf - .1 * ( upperLimitBuf - lowerLimitBuf );

  TCanvas* canvas = new TCanvas( "QuickHist", "QuickHist" );
  canvas->Draw();

  TH1D* histogram = new TH1D( "QuickHist", "QuickHist", 1000, lowerLimit, upperLimit );
  for( unsigned int i = 0; i < numbersVector.size(); i++ ) histogram->Fill( numbersVector[i] );
  histogram->Draw();


  theApp.Run( kTRUE );

}
Example #13
0
void canvas_read()
{
   TFile* f2 = new TSQLFile(dbname, "open", username, userpass);
   if (f2->IsZombie()) { delete f2; return; }

   f2->ls();
   gBenchmark->Start("readSQL");
   TCanvas* cc = (TCanvas*) f2->Get("Canvas");
   gBenchmark->Show("readSQL");
   if (cc!=0) cc->Draw();

   delete f2;
}
Example #14
0
// Print all canvases in a single PS file
void printCanvasesPS(TString name){
  TPostScript * ps = new TPostScript(name,112);
  TIter iter(gROOT->GetListOfCanvases());
  TCanvas *c;
  while( (c = (TCanvas *)iter()) )
    {
      cout << "Printing " << c->GetName() << endl;
      ps->NewPage();
      c->Draw();
    }
  cout << " File " << name << " was created" << endl;
  ps->Close();
}
Example #15
0
void fireball(){

  //set-up
  gROOT->Macro("init.C");
  setStyle();

  //ake the plot
  TCanvas *cFire = new TCanvas("cFire", "cFire", 500, 500);
  cFire->Draw();
 
  ellipises();
  arrows1();
}
Example #16
0
void tempTime(){

  gROOT->Macro("init.C");
  setStyle();

  //make the plot
  TCanvas *cNew = new TCanvas("cNew", "cNew", 500, 500);
  drawFrame(-3., 130., 65., 279., "#tau [fm]", "T [MeV]");
  cNew->Draw();
  
  drawQGP();
  drawMix();
  drawHHG();
}
Example #17
0
//===========================================================================
void TExtrapoljator::DrawElementFace()
{
      TCanvas    *dbCanvas = VisualElementParam->Bitmap->Canvas;
      int         aw       = VisualElementParam->Width;
      int         ah       = VisualElementParam->Height;

      dbCanvas->Brush->Color = clWhite;
      dbCanvas->Pen  ->Color = clBlack;

      dbCanvas->Rectangle(0, 0, aw, ah);

   // -------------- Отрисовка ресурса если он есть ----------
      dbCanvas->Draw((aw - ResourseBitmapFaceElement->Width) / 2, (ah - ResourseBitmapFaceElement->Height) / 2,ResourseBitmapFaceElement);
}
void CalcQCDNormFactor() {
  //TFile *f = TFile::Open("results/Plotter_out_2016_05_29_22h19m32.root"); // 76X Silver JSON
  TFile *f = TFile::Open("results/Plotter_out_2016_06_21_15h27m59.root"); // 76X Golden JSON
  TCanvas *c = (TCanvas*)f->Get("NJet/PlotSamples_Pass5Cuts_PassHLT");
  THStack *s = (THStack*)c->GetListOfPrimitives()->At(1);
  TH1D *data = (TH1D*)c->GetListOfPrimitives()->At(3);
  double MC_integral = 0;
  double QCD_count = 0;
  for (int i=s->GetHists()->GetEntries()-1; i>=0; --i) {
    TH1D* h = (TH1D*)s->GetHists()->At(i);
    if (i==s->GetHists()->GetEntries()-1) QCD_count = h->Integral();
    std::cout<<h->GetName()<<" "<<h->Integral()<<std::endl;
    MC_integral += h->Integral();
  }
  double data_QCD_estimate = data->Integral()- (MC_integral-QCD_count);
  double QCD_scale = data_QCD_estimate/QCD_count;
  std::cout<<"MC:                  "<<MC_integral<<std::endl;
  std::cout<<"Data:                "<<data->Integral()<<std::endl;
  std::cout<<"MC   (QCD only):     "<<QCD_count<<std::endl;
  std::cout<<"Data (QCD only est): "<<data_QCD_estimate<<std::endl;
  std::cout<<"QCD Scale: "<<QCD_scale<<std::endl;

  TH1D* qcd = (TH1D*)s->GetHists()->At(s->GetHists()->GetEntries()-1);
  qcd->Scale(QCD_scale);
  c->Draw();
  
  //TCanvas *c = (TCanvas*)f->Get("NJet/PlotSamples_Pass5Cuts_PassHLT_Ratio");
  //
  //TH1D* ratio = (TH1D*)((TVirtualPad*)c->cd(2))->GetListOfPrimitives()->At(0);
  //TF1* fit = new TF1("fit","pol1", 400, 2000);
  //ratio->Fit("fit","RBQ0");
  //fit->SetLineColor(2);
  //fit->SetLineWidth(1);
  //TF1* fit_up   = (TF1*)fit->Clone("fit_up");
  //TF1* fit_down = (TF1*)fit->Clone("fit_down");
  //fit_up  ->SetParameter(0,fit->GetParameter(0)+fit->GetParError(0)*1);
  //fit_down->SetParameter(0,fit->GetParameter(0)-fit->GetParError(0)*1);
  //fit_up  ->SetParameter(1,fit->GetParameter(1)+fit->GetParError(1)*1);
  //fit_down->SetParameter(1,fit->GetParameter(1)-fit->GetParError(1)*1);
  //fit_up  ->SetLineColor(4); fit_up  ->Draw("SAME");
  //fit_down->SetLineColor(4); fit_down->Draw("SAME");
  //fit->Draw("SAME");
  //
  //std::cout<<"Fit result:"<<std::endl;
  //std::cout<<"p0: "<<fit->GetParameter(0)<<" +- "<<fit->GetParError(0)*1<<std::endl;
  //std::cout<<"p1: "<<fit->GetParameter(1)<<" +- "<<fit->GetParError(1)*1<<std::endl;
  //f->Close();  
}
Example #19
0
void NoiseMatrixLayerGraphs(TString myFileName, int nDDU, int nCham, int nLayer){
  //gSystem->cd("images/NoiseMatrix");
  //gSystem->cd(myFileName);

int nElements = 12;
TH2F *noiseGraph;
TCanvas *noiseCanv;
 for (int i=0; i< nDDU; ++i){
   int idArray[9];
   GetChamberIDs(idArray);
   //   Float_t BoundsMinArray[108];
   //   Float_t BoundsMaxArray[108];
   Float_t BoundsChamMin[9];
   Float_t BoundsChamMax[9];
   //GetNoiseBounds(BoundsMinArray, BoundsMaxArray, BoundsChamMin, BoundsChamMax);
   GetNoiseBounds(BoundsChamMin, BoundsChamMax, nCham);
   for (int j=0; j<nCham; ++j){
     TString ChamDirecName = Form("Chamber_%d_Layer_Graphs", idArray[j]);
     makeDirectory(ChamDirecName); 
     gSystem->cd(ChamDirecName); 
     for (int l=0; l<nLayer; ++l){ 
       TString NoiseCanvName = Form ("Noise_Matrix_Elements_Chamber_%d_Layer_%d",idArray[j],l); 
       noiseCanv = new TCanvas(NoiseCanvName, NoiseCanvName,200,10,1200,800); 
       noiseCanv->Divide(4,3); 
       noiseCanv->Draw(); 
       for (int k=0; k<nElements; ++k){  
	 TString ElementGraphName = Form("Element_%d",k); 
	 noiseGraph = new TH2F(ElementGraphName,ElementGraphName,80,0,80,20,BoundsChamMin[j],BoundsChamMax[j]);  
	 noiseCanv->cd(k+1); 
	 noiseGraph->Draw(); 
	 TString GraphForm = Form("elem[%d]:strip", k); 
	 TString GraphCut = Form("cham==%d&&layer==%d", j, l); 
	 Calibration->Project(ElementGraphName, GraphForm, GraphCut); 
       }//nElements 
       noiseCanv->Update();    
       PrintAsGif(noiseCanv, NoiseCanvName); 
     }//nLayer
     gSystem->cd("../");
   }//nCham 
 }//nDDU 
gSystem->cd("../../../"); 
directoryCheck(); 
}//NoiseMatrixGraphs 
Example #20
0
void collision(){

  //set-up
  gROOT->Macro("init.C");
  setStyle();

  //make the plot
  TCanvas *cColl = new TCanvas("cColl", "cColl", 1000, 500);
  cColl->Divide(2,1);
  cColl->Draw();
  //drawFrame(0., 0., 1., 1., "", "");
  cColl->cd(1);
  ellipises();
  arrows1();

  cColl->cd(2);
  circles();
  arrows2();
}
Example #21
0
void det_canvas_selected(int col,char *title,int cols_max=3)
{
    char *detectors[]={"4X","4U","6V"};
    
    TCanvas *cone = gROOT->FindObject("cone");
    if( cone==NULL )
    {
        cone = new TCanvas("cone","cone");
        cone->Divide(cols_max,sizeof(detectors)/sizeof(*detectors));
    }

    for( int i=0; i<sizeof(detectors)/sizeof(*detectors); i++ )
    {
        cone->cd(col+i*cols_max);
        TH1F *h = draw_detector(detectors[i],card_channel);
        h->SetTitle(title);
    }
    
    cone->cd(0);
    cone->Draw();
}
Example #22
0
void binShiftSchem(){

  //set-up
  gROOT->Macro("init.C");
  setStyle();
  
  //make the plot
  TCanvas *cBinShift = new TCanvas("cBinShift", "cBinShift", 1000, 500);
  cBinShift->Divide(2,1);
  cBinShift->Draw();

  cBinShift->cd(1);
  histo1();
  box1();
  ellipse1();

  cBinShift->cd(2);
  histo2();
  box2();
  ellipse2();
}
Example #23
0
void
ImageStimulus::OnPaint( const DrawContext& inDC )
{
#ifdef __BORLANDC__
  Graphics::TBitmap* pBuffer = BeingPresented() ?
                               mpImageBufferHighlighted :
                               mpImageBufferNormal;
  if( pBuffer != NULL )
  {
    TCanvas* pCanvas = new TCanvas;
    try
    {
      pBuffer->Transparent = ( mRenderingMode == GUI::RenderingMode::Transparent );
      pBuffer->TransparentMode = tmAuto;
      pCanvas->Handle = inDC.handle;
      pCanvas->Draw( inDC.rect.left, inDC.rect.top, pBuffer );
    }
    __finally
    {
      delete pCanvas;
    }
  }
Example #24
0
top::container1DStack StackTest(){

  using namespace top;
  using namespace std;

  container1DStack stack;
  vector<float> bins;
  for(int i=0;i<100;i++) bins << i;

  stack.setDataLegend("data");

  histo1D cont(bins,"contr","x","y");
  histo1D cont2=cont;

  for(float i=0;i<1000;i++) cont.fill(pow(i/100,2));
  stack.push_back(cont, "contr1", kRed, 1);
  cont2=cont2+cont;
  cont.clear();

  for(float i=0;i<1000;i++) cont.fill(pow(i/200,3));
  stack.push_back(cont, "contr2", kBlue, 1);
  cont2=cont2+cont;
  cont.clear();

  for(float i=0;i<1000;i++) cont.fill(pow(i/300,4));
  stack.push_back(cont, "contr3", kGreen, 1);
  cont2=cont2+cont;
  cont.clear();


  stack.push_back(cont2, "data", kBlack, 1);

  return stack;

  TCanvas * c = stack.makeTCanvas();
  c->Draw();


}
Example #25
0
void draw(const std::string& title, const std::vector<TH1D*>& histograms,
          const std::string& filename)
{
   if (histograms.empty() ||
       histograms.size() > (sizeof(hist_style)/sizeof(hist_style[0])))
      return;

   TCanvas* canvas = new TCanvas("canvas", title.c_str(), 800, 600);
   canvas->cd(1)->SetTitle(title.c_str());

   histograms[0]->GetYaxis()->SetRangeUser(0., 1.);
   for (int i = 0; i < histograms.size(); i++) {
      histograms[i]->SetLineWidth(3);
      histograms[i]->SetLineColor(hist_style[i].linecolor);
      histograms[i]->SetFillColor(hist_style[i].fillcolor);
      histograms[i]->SetFillStyle(hist_style[i].fillstyle);
      histograms[i]->Draw(i == 0 ? "" : "same");
   }

   TLegend *legend = new TLegend(0.4,0.7,0.9,0.9);
   legend->SetFillColor(0);
   for (int i = 0; i < histograms.size(); i++) {
      legend->AddEntry(histograms[i],
                       TString::Format("%s (%3.3fs)", histograms[i]->GetTitle(), histograms[i]->GetMean()),
                       "f");
   }
   legend->Draw();

   histograms[0]->SetTitle(title.c_str());
   histograms[0]->GetXaxis()->SetTitle("run-time / s");

   canvas->Draw();
   canvas->SaveAs(TString(filename) + ".pdf");
   canvas->SaveAs(TString(filename) + ".png");

   delete legend;
   delete canvas;
}
Example #26
0
//void plot_Asymptotic(string outputname)
//void plot_Asymptotic()
TGraphAsymmErrors *  plot_Asymptotic(TString dir_path ,TGraphAsymmErrors *grmedian_cls ) 
//void plot_Asymptotic( TGraphAsymmErrors *grmedian_cls )
{

string outputname = "counting";

  bool useNewStyle = true;
  if (useNewStyle)  setFPStyle();
//  gROOT->LoadMacro("CMS_lumi.C");

  TFile *fFREQ[nXm];
  TTree *t[nXm];
//  int Xmass[nXm]={800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000};  
  int Xmass[nXm]={800,1000,1200,1400,1600,1800,2000,2500,3000,3500,4000};
  //int Xmass[nXm]={800,900,1100,1400,1700,1900};  
  vector<double> v_mh, v_median, v_68l, v_68h, v_95l, v_95h, v_obs;
 

  for(int n=0;n<nXm;n++)
  {
    char limitfile[200];



//    if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]);


    if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]);


//    const string dirLimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/";

    TString LimitFile = limitfile;
    LimitFile = dir_path  + LimitFile;
//    LimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"  + LimitFile;
//    limitfile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"  + limitfile;

//    limitfile = dirLimitFile + limitfile;


//    fFREQ[n] = new TFile(limitfile, "READ");
    fFREQ[n] = new TFile( LimitFile , "READ");
    cout<<" Read limit file: "<<limitfile<<endl;
    t[n] = (TTree*)fFREQ[n]->Get("limit");
  
    double mh, limit;
    float quant;
    t[n]->SetBranchAddress("mh", &mh);
    t[n]->SetBranchAddress("limit", &limit);
    t[n]->SetBranchAddress("quantileExpected", &quant);
  
    
    
    //int iMH = 0;
    //while (iMH < n) {
 
      for (int i = 0; i < t[n]->GetEntries(); i++) {

        t[n]->GetEntry(i);

        cout<<" quant : "<<quant<<" limit : " <<limit<<endl;
        /// Map: mh --> observed, 95low, 68low, expected, 68hi, 95hi, xsec
        if (quant > -1.01 && quant < -0.99) {
        v_obs.push_back(limit);
        } 
        else if (quant > 0.02 && quant < 0.03) {
	v_95l.push_back(limit);
        }
        else if (quant > 0.15 && quant < 0.17) {
	v_68l.push_back(limit);
        }
        else if (quant > 0.49 && quant < 0.51) {
	v_median.push_back(limit);
        v_mh.push_back(mh);
        }
        else if (quant > 0.83 && quant < 0.85) {
	v_68h.push_back(limit);
        }
        else if (quant > 0.965 && quant < 0.98) {
	v_95h.push_back(limit);
        }
        else {
        cout << "Error! Quantile =  " << quant << endl;
        }
     }
      //   iMH++;
      // }//end while loop

  }//file loop

//  string xsect_file_th = dirXSect + "13TeV_xsec_Zhllbb.txt";
  string xsect_file_th = dirXSect + "13TeV_xsec_Zh.txt";

  ifstream xsect_file(xsect_file_th.c_str(), ios::in);
  if (! xsect_file.is_open()) {
    cout << "Failed to open file with xsections: " << xsect_file_th << endl;
  }

  float mH, CS;
  vector<float> v_mhxs, v_xs, v_toterrh, v_toterrl;
  while (xsect_file.good()) {
    xsect_file >> mH >> CS;
  
    v_mhxs.push_back(mH);
    v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !)

    //unavailable theory errors for graviton

    float tot_err_p = 0.0;
    float tot_err_m = 0.0;

    v_toterrh.push_back(1.0 + (tot_err_p));
    v_toterrl.push_back(1.0 - (tot_err_m));
  }
  cout << "Size of theory xsects vector" << v_mhxs.size() << endl;
  xsect_file.close();
  ///////////////////////////
  // END THEORY INPUT PART //
  ///////////////////////////


  /// Here we multiply the limits in terms of signal strength by the cross-section.
  /// There are also some hooks to exclude sick mass points.
  
  double mass[nXm], obs_lim_cls[nXm];
  double medianD[nXm];
  double up68err[nXm], down68err[nXm], up95err[nXm], down95err[nXm];
  double xs[nXm], xs_uperr[nXm], xs_downerr[nXm];
  double xs10[nXm], xs10_uperr[nXm], xs10_downerr[nXm];
  int nMassEff = 0;
  
  for (int im = 0; im < nXm; im++) {


    double fl_xs = double(v_xs.at(im)); //*1000.0
    double fl_xs10 = 0;//double(v_xs10.at(ind)); //*1000.0
    fl_xs = (fl_xs);
    fl_xs10 = (fl_xs10);

      mass[nMassEff] = Xmass[im];

    /// This is the part where we multiply the limits in terms of signal strength
    /// by the cross-section, in order to have limits in picobarns.
    //std::cerr << mass[nMassEff] << ":" << v_obs.at(im) << std::endl;
      obs_lim_cls[nMassEff] = v_obs.at(im) * fl_xs;
 
      
      medianD[nMassEff] = v_median.at(im) * fl_xs;
      up68err[nMassEff] = (v_68h.at(im) - v_median.at(im)) * fl_xs;
      down68err[nMassEff] = (v_median.at(im) - v_68l.at(im)) * fl_xs;

      //scale factor 100 for making the xsect visible
      xs[nMassEff] = fl_xs; //*100.0;
      xs_uperr[nMassEff] = double(v_toterrh.at(im)) * xs[nMassEff] - xs[nMassEff];
      xs_downerr[nMassEff] =  xs[nMassEff] - double(v_toterrl.at(im)) * xs[nMassEff];

      xs10[nMassEff] = fl_xs10; //*100.0;
      xs10_uperr[nMassEff] = double(v_toterrh.at(im)) * xs10[nMassEff] - xs10[nMassEff];
      xs10_downerr[nMassEff] =  xs10[nMassEff] - double(v_toterrl.at(im)) * xs10[nMassEff];
     
      up95err[nMassEff] = (v_95h.at(im) - v_median.at(im)) * fl_xs;
      down95err[nMassEff] = (v_median.at(im) - v_95l.at(im)) * fl_xs;
    
      cout<<"fl_xs:"<<fl_xs<<" v_obs"<<v_obs.at(im)<<" obs_lim_cls: "<<obs_lim_cls[nMassEff]  <<medianD[nMassEff] <<" mass: "<<mass[nMassEff]<<endl;
 
      nMassEff++;
    
    
  }//end loop over im (mass points)



  /// The TGraphs themselves.

  //cout<<"Working on TGraph"<<endl;
  TGraphAsymmErrors *grobslim_cls = new TGraphAsymmErrors(nMassEff, mass, obs_lim_cls);
  grobslim_cls->SetName("LimitObservedCLs");

//  TGraphAsymmErrors *grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD);
  grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD);
  grmedian_cls->SetName("LimitExpectedCLs");
  TGraphAsymmErrors *gr68_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down68err, up68err);
  gr68_cls->SetName("Limit68CLs");
  TGraphAsymmErrors *gr95_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down95err, up95err);
  gr95_cls->SetName("Limit95CLs");

  // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr);
  TGraph *grthSM=new TGraph(nMassEff,mass,xs);//xs_downerr,xs_uperr);

  /// For the time being we have to do it like this, given that
  /// the cards and the limits were made with the old, wrong xsects.
  // TGraph *grthSM10 = new TGraph(35);
//   grthSM10->SetPoint(0, 600, 7.1185E-03);
//   grthSM10->SetPoint(1, 650, 4.1893E-03);
//   grthSM10->SetPoint(2, 700, 2.5592E-03);
//   grthSM10->SetPoint(3, 750, 1.6182E-03);
//   grthSM10->SetPoint(4, 800, 1.0564E-03);
//   grthSM10->SetPoint(5, 850, 7.0295E-04);
//   grthSM10->SetPoint(6, 900, 4.7877E-04);
//   grthSM10->SetPoint(7, 950, 3.3017E-04);
//   grthSM10->SetPoint(8, 1000, 2.3212E-04);
//   grthSM10->SetPoint(9, 1050, 1.6574E-04);
//   grthSM10->SetPoint(10, 1100, 1.1917E-04);
//   grthSM10->SetPoint(11, 1150, 8.6629E-05);
//   grthSM10->SetPoint(12, 1200, 6.3987E-05);
//   grthSM10->SetPoint(13, 1250, 4.7353E-05);
//   grthSM10->SetPoint(14, 1300, 3.5511E-05);
//   grthSM10->SetPoint(15, 1350, 2.6631E-05);
//   grthSM10->SetPoint(16, 1400, 2.0199E-05);
//   grthSM10->SetPoint(17, 1450, 1.5333E-05);
//   grthSM10->SetPoint(18, 1500, 1.1758E-05);
//   grthSM10->SetPoint(19, 1550, 9.0363E-06);
//   grthSM10->SetPoint(20, 1600, 6.9870E-06);
//   grthSM10->SetPoint(21, 1650, 5.4316E-06);
//   grthSM10->SetPoint(22, 1700, 4.2252E-06);
//   grthSM10->SetPoint(23, 1750, 3.3172E-06);
//   grthSM10->SetPoint(24, 1800, 2.6083E-06);
//   grthSM10->SetPoint(25, 1850, 2.0499E-06);
//   grthSM10->SetPoint(26, 1900, 1.6186E-06);
//   grthSM10->SetPoint(27, 1950, 1.2799E-06);
//   grthSM10->SetPoint(28, 2000, 1.0205E-06);
//   grthSM10->SetPoint(29, 2050, 8.0867E-07);
//   grthSM10->SetPoint(30, 2100, 6.4555E-07);
//   grthSM10->SetPoint(31, 2150, 5.1755E-07);
//   grthSM10->SetPoint(32, 2200, 4.1408E-07);
//   grthSM10->SetPoint(33, 2250, 3.3170E-07);
//   grthSM10->SetPoint(34, 2300, 2.6637E-07);
//   grthSM10->SetPoint(35, 2350, 2.1366E-07);
//   grthSM10->SetPoint(36, 2400, 1.7285E-07);
//   grthSM10->SetPoint(37, 2450, 1.3896E-07);
//   grthSM10->SetPoint(38, 2500, 1.1238E-07);

//   if (!isZZChannel) {
//     grthSM10->SetPoint(0, 800, 2.0523E-03);
//     grthSM10->SetPoint(1, 850, 1.3726E-03);
//     grthSM10->SetPoint(2, 900, 9.3786E-04);
//     grthSM10->SetPoint(3, 950, 6.4928E-04);
//     grthSM10->SetPoint(4, 1000, 4.5618E-04);
//     grthSM10->SetPoint(5, 1050, 3.2571E-04);
//     grthSM10->SetPoint(6, 1100, 2.3543E-04);
//     grthSM10->SetPoint(7, 1150, 1.7157E-04);
//     grthSM10->SetPoint(8, 1200, 1.2611E-04);
//     grthSM10->SetPoint(9, 1250, 9.3461E-05);
//     grthSM10->SetPoint(10, 1300, 6.9899E-05);
//     grthSM10->SetPoint(11, 1350, 5.2749E-05);
//     grthSM10->SetPoint(12, 1400, 4.0048E-05);
//     grthSM10->SetPoint(13, 1450, 3.0363E-05);
//     grthSM10->SetPoint(14, 1500, 2.3324E-05);
//     grthSM10->SetPoint(15, 1550, 1.8008E-05);
//     grthSM10->SetPoint(16, 1600, 1.3876E-05);
//     grthSM10->SetPoint(17, 1650, 1.0812E-05);
//     grthSM10->SetPoint(18, 1700, 8.4385E-06);
//     grthSM10->SetPoint(19, 1750, 6.5972E-06);
//     grthSM10->SetPoint(20, 1800, 5.1608E-06);
//     grthSM10->SetPoint(21, 1850, 4.0824E-06);
//     grthSM10->SetPoint(22, 1900, 3.2292E-06);
//     grthSM10->SetPoint(23, 1950, 2.5502E-06);
//     grthSM10->SetPoint(24, 2000, 2.0281E-06);
//     grthSM10->SetPoint(25, 2050, 1.6179E-06);
//     grthSM10->SetPoint(26, 2100, 1.2893E-06);
//     grthSM10->SetPoint(27, 2150, 1.0313E-06);
//     grthSM10->SetPoint(28, 2200, 8.2293E-07);
//     grthSM10->SetPoint(29, 2250, 6.6187E-07);
//     grthSM10->SetPoint(30, 2300, 5.3108E-07);
//     grthSM10->SetPoint(31, 2350, 4.2755E-07);
//     grthSM10->SetPoint(32, 2400, 3.4315E-07);
//     grthSM10->SetPoint(33, 2450, 2.7803E-07);
//     grthSM10->SetPoint(34, 2500, 2.2432E-07);
//   }
  grthSM->SetName("SMXSection");


  // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0);
  TGraph *grthSM10=new TGraph(nMassEff,mass,xs10);
  // TGraph *grthSM = new TGraph(35);
//   grthSM->SetPoint(0, 600, 4.4387E-02);
//   grthSM->SetPoint(1, 650, 2.6088E-02);
//   grthSM->SetPoint(2, 700, 1.5907E-02);
//   grthSM->SetPoint(3, 750, 1.0045E-02);
//   grthSM->SetPoint(4, 800, 6.5582E-03);
//   grthSM->SetPoint(5, 850, 4.3560E-03);
//   grthSM->SetPoint(6, 900, 2.9701E-03);
//   grthSM->SetPoint(7, 950, 2.0553E-03);
//   grthSM->SetPoint(8, 1000, 1.4410E-03);
//   grthSM->SetPoint(9, 1050, 1.0283E-03);
//   grthSM->SetPoint(10, 1100, 7.3979E-04);
//   grthSM->SetPoint(11, 1150, 5.4086E-04);
//   grthSM->SetPoint(12, 1200, 3.9717E-04);
//   grthSM->SetPoint(13, 1250, 2.9347E-04);
//   grthSM->SetPoint(14, 1300, 2.1957E-04);
//   grthSM->SetPoint(15, 1350, 1.6507E-04);
//   grthSM->SetPoint(16, 1400, 1.2514E-04);
//   grthSM->SetPoint(17, 1450, 9.5937E-05);
//   grthSM->SetPoint(18, 1500, 7.3300E-05);
//   grthSM->SetPoint(19, 1550, 5.6376E-05);
//   grthSM->SetPoint(20, 1600, 4.3715E-05);
//   grthSM->SetPoint(21, 1650, 3.3834E-05);
//   grthSM->SetPoint(22, 1700, 2.6389E-05);
//   grthSM->SetPoint(23, 1750, 2.0691E-05);
//   grthSM->SetPoint(24, 1800, 1.6259E-05);
//   grthSM->SetPoint(25, 1850, 1.2809E-05);
//   grthSM->SetPoint(26, 1900, 1.0131E-05);
//   grthSM->SetPoint(27, 1950, 8.0235E-06);
//   grthSM->SetPoint(28, 2000, 6.3711E-06);
//   grthSM->SetPoint(29, 2050, 5.0725E-06);
//   grthSM->SetPoint(30, 2100, 4.0513E-06);
//   grthSM->SetPoint(31, 2150, 3.2469E-06);
//   grthSM->SetPoint(32, 2200, 2.6006E-06);
//   grthSM->SetPoint(33, 2250, 2.0899E-06);
//   grthSM->SetPoint(34, 2300, 1.6810E-06);
//   grthSM->SetPoint(35, 2350, 1.3586E-06);
//   grthSM->SetPoint(36, 2400, 1.0964E-06);
//   grthSM->SetPoint(37, 2450, 8.8416E-07);
//   grthSM->SetPoint(38, 2500, 7.1662E-07);
//   if (!isZZChannel) {
//     grthSM->SetPoint(0, 800, 1.2713E-02);
//     grthSM->SetPoint(1, 850, 8.5015E-03);
//     grthSM->SetPoint(2, 900, 5.8030E-03);
//     grthSM->SetPoint(3, 950, 4.0261E-03);
//     grthSM->SetPoint(4, 1000, 2.8289E-03);
//     grthSM->SetPoint(5, 1050, 2.0214E-03);
//     grthSM->SetPoint(6, 1100, 1.4580E-03);
//     grthSM->SetPoint(7, 1150, 1.0625E-03);
//     grthSM->SetPoint(8, 1200, 7.8079E-04);
//     grthSM->SetPoint(9, 1250, 5.7987E-04);
//     grthSM->SetPoint(10, 1300, 4.3448E-04);
//     grthSM->SetPoint(11, 1350, 3.2719E-04);
//     grthSM->SetPoint(12, 1400, 2.4778E-04);
//     grthSM->SetPoint(13, 1450, 1.8896E-04);
//     grthSM->SetPoint(14, 1500, 1.4543E-04);
//     grthSM->SetPoint(15, 1550, 1.1200E-04);
//     grthSM->SetPoint(16, 1600, 8.6492E-05);
//     grthSM->SetPoint(17, 1650, 6.7405E-05);
//     grthSM->SetPoint(18, 1700, 5.2283E-05);
//     grthSM->SetPoint(19, 1750, 4.1121E-05);
//     grthSM->SetPoint(20, 1800, 3.2378E-05);
//     grthSM->SetPoint(21, 1850, 2.5507E-05);
//     grthSM->SetPoint(22, 1900, 2.0215E-05);
//     grthSM->SetPoint(23, 1950, 1.6020E-05);
//     grthSM->SetPoint(24, 2000, 1.2714E-05);
//     grthSM->SetPoint(25, 2050, 1.0133E-05);
//     grthSM->SetPoint(26, 2100, 8.0785E-06);
//     grthSM->SetPoint(27, 2150, 6.4583E-06);
//     grthSM->SetPoint(28, 2200, 5.1774E-06);
//     grthSM->SetPoint(29, 2250, 4.1620E-06);
//     grthSM->SetPoint(30, 2300, 3.3440E-06);
//     grthSM->SetPoint(31, 2350, 2.7018E-06);
//     grthSM->SetPoint(32, 2400, 2.1753E-06);
//     grthSM->SetPoint(33, 2450, 1.7626E-06);
//     grthSM->SetPoint(34, 2500, 1.4225E-06);
//   }
  grthSM10->SetName("SMXSection_2nd");

  // double fr_left = 590.0, fr_down = 1E-5, fr_right = 2000.0, fr_up = 0.5; 
//   double fr_left = 590.0, fr_down = 5E-5, fr_right = 2000.0, fr_up = 5;
   double fr_left = 500.0, fr_down = 5E-7, fr_right = 4500.0, fr_up = 5E-1;

  TCanvas *cMCMC = new TCanvas("c_lim_Asymptotic", "canvas with limits for Asymptotic CLs", 630, 600);
  cMCMC->cd();
  cMCMC->SetGridx(1);
  cMCMC->SetGridy(1);
  // draw a frame to define the range

  TH1F *hr = cMCMC->DrawFrame(fr_left, fr_down, fr_right, fr_up, "");
  TString VV = "ZH";
  
  hr->SetXTitle("M_{X} [GeV]");
  hr->SetYTitle("#sigma_{95%} [pb]"); // #rightarrow 2l2q
  

  gr95_cls->SetFillColor(kYellow);
  gr95_cls->SetFillStyle(1001);//solid
  gr95_cls->SetLineStyle(kDashed);
  gr95_cls->SetLineWidth(3);
  gr95_cls->GetXaxis()->SetTitle("M_{V'} [GeV]");
  gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q
  gr95_cls->GetXaxis()->SetRangeUser(fr_left, fr_right);

//  gr95_cls->Draw("3");

  gr68_cls->SetFillColor(kGreen);
  gr68_cls->SetFillStyle(1001);//solid
  gr68_cls->SetLineStyle(kDashed);
  gr68_cls->SetLineWidth(3);
//  gr68_cls->Draw("3same");
  grmedian_cls->GetXaxis()->SetTitle("M_{V'} [GeV]");
  grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q
  grmedian_cls->SetMarkerStyle(24);//25=hollow squre
  grmedian_cls->SetMarkerColor(kBlack);
  grmedian_cls->SetLineStyle(2);
  grmedian_cls->SetLineWidth(3);
  grmedian_cls->SetMinimum(0.0);
  grmedian_cls->SetMaximum(8.0);

  grobslim_cls->SetMarkerColor(kBlack);
  grobslim_cls->SetMarkerStyle(21);//24=hollow circle
  grobslim_cls->SetMarkerSize(1.0);
  grobslim_cls->SetLineStyle(1);
  grobslim_cls->SetLineWidth(3);

  grthSM->SetLineColor(kRed);
  grthSM->SetLineWidth(2);
  grthSM->SetLineStyle(kSolid);
  grthSM->SetFillColor(kRed);
  grthSM->SetFillStyle(3344);

  grthSM10->SetLineColor(kRed);
  grthSM10->SetLineWidth(2);
  grthSM10->SetLineStyle(1);
  grthSM10->SetLineStyle(kDashed);
  grthSM10->SetFillColor(kRed);
  grthSM10->SetFillStyle(3344);

//  grthSM->Draw("L3");
  grmedian_cls->Draw("L");
//  grobslim_cls->Draw("LP");

  /*
  TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ");
  TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs");
  TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs");
  grobs_ump->SetName("LimitObs_UnmatchedPlus");
  grmedian_ump->SetName("LimitExp_UnmatchedPlus");
  grobs_ump->SetMarkerColor(kBlue);
  grobs_ump->SetLineColor(kBlue);
  grobs_ump->SetMarkerStyle(25);
  grmedian_ump->SetMarkerColor(kBlue);
  grmedian_ump->SetLineColor(kBlue);
  grmedian_ump->SetMarkerStyle(25);
  grobs_ump->Draw("P");
  grmedian_ump->Draw("L");
  */

  //draw grid on top of limits
  gStyle->SetOptStat(0);
  TH1D* postGrid = new TH1D("postGrid", "", 1, fr_left, fr_right);
  postGrid->GetYaxis()->SetRangeUser(fr_down, fr_up);
  postGrid->Draw("AXIGSAME");

  //more graphics

  TLegend *leg = new TLegend(.20, .2, .75, .35);
  //   TLegend *leg = new TLegend(.35,.71,.90,.90);
  leg->SetFillColor(0);
  leg->SetShadowColor(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.03);
  //   leg->SetBorderMode(0);
  leg->AddEntry(grmedian_cls, "CL_{S} Expected limit central value", "L");
//  leg->AddEntry(grobslim_cls, "Frequentist CL_{S} Observed", "LP");
//  leg->AddEntry(gr68_cls, "Frequentist CL_{S}  Expected #pm 1#sigma", "LF");
//  leg->AddEntry(gr95_cls, "Frequentist CL_{S}  Expected #pm 2#sigma", "LF");
//  leg->AddEntry(grthSM, "#sigma_{TH}", "L");
//    leg->AddEntry(grthSM, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.50", "L"); // #rightarrow 2l2q
//    leg->AddEntry(grthSM10, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.20", "L"); // #rightarrow 2l2q
  leg->Draw();

    TLatex * latex = new TLatex();
    latex->SetNDC();
    latex->SetTextSize(0.04);
    latex->SetTextAlign(31);
    latex->SetTextAlign(11); // align left
//    latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012");
//    latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV", intLumi));
    latex->DrawLatex(0.18, 0.96, "CMS preliminary 2015");
    latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 13 TeV", intLumi));
  

  // cMCMC->RedrawAxis("");
  gPad->RedrawAxis("");
  // hr->GetYaxis()->DrawClone();
  cMCMC->Update();
  char fnam[50];
  //string outputname="shape2d";
  //string outputname="shape1d";
  //string outputname="counting";

  sprintf(fnam, "XZHllbb_%s_Asymptotic.root",outputname.data() );
//  cMCMC->SaveAs(fnam);
  //sprintf(fnam, "XZHllbb_%s_Asymptotic.eps", outputname.data());
  //cMCMC->SaveAs(fnam);
    sprintf(fnam, "XZHllbb_%s_Asymptotic.png", outputname.data());
//    cMCMC->SaveAs(fnam);
    //sprintf(fnam, "XZHllbb_%s_Asymptotic.pdf", outputname.data());
    //cMCMC->SaveAs(fnam);
    gPad->SetLogy();
    //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.eps", outputname.data());
    //cMCMC->SaveAs(fnam);
    sprintf(fnam, "XZHllbb_%s_Asymptotic_log.png", outputname.data());
//    cMCMC->SaveAs(fnam);
    //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.pdf", outputname.data());
    //cMCMC->SaveAs(fnam);
 

  cMCMC->Draw();



return grmedian_cls;

}//end main
Example #27
0
void test()
{	
	style();
	setLogBins(nlogfullimassbins,logfullimassmin,logfullimassmax,logfullimassbins);

	float Mhat;
	
	TCanvas* c = new TCanvas("c","c",600,400);
	c->SetLogx();
	c->SetLogy();
	c->Draw();
	c->cd();
	
	TLegend* leg = new TLegend(0.6627517,0.6846449,0.7919463,0.8261126,NULL,"brNDC");
	leg->SetFillStyle(4000); //will be transparent
	leg->SetFillColor(0);
	leg->SetTextFont(42);

	TFile fLoose("/data/hod/2011/NTUPLE/analysisLocalControl_TightLoose.root", "READ");
	TTree* tLoose = (TTree*)fLoose.Get("allCuts/allCuts_tree");
	tLoose->SetBranchAddress("Mhat",  &Mhat);
	Int_t nLoose = tLoose->GetEntries();
	TH1D* hLoose = new TH1D("hLoose","tight-loose vs. tight-tight selection;m_{#mu#mu} TeV;Events",nlogfullimassbins,logfullimassbins);
	hLoose->SetLineColor(kRed);
	hLoose->SetMarkerColor(kRed);
	hLoose->SetMarkerStyle(24);
	hLoose->SetMarkerSize(0.8);
	hLoose->SetMinimum(1.e-3);
	hLoose->SetMaximum(7.e+5);
	hLoose->GetXaxis()->SetMoreLogLabels();
	hLoose->GetXaxis()->SetNoExponent();
	leg->AddEntry(hLoose,"tight-loose","lep");
	for(Int_t i=0 ; i<nLoose ; i++)
	{
		tLoose->GetEntry(i);
		hLoose->Fill(Mhat*TeV2GeV);
	}
	
	TFile fTight("/data/hod/2011/NTUPLE/analysisLocalControl.root", "READ");
	TTree* tTight = (TTree*)fTight.Get("allCuts/allCuts_tree");
	tTight->SetBranchAddress("Mhat",  &Mhat);
	Int_t nTight = tTight->GetEntries();
	TH1D* hTight = new TH1D("hTight","tight-loose vs. tight-tight selection;m_{#mu#mu} TeV;Events",nlogfullimassbins,logfullimassbins);
	hTight->SetLineColor(kBlack);
	hTight->SetMarkerColor(kBlack);
	hTight->SetMarkerStyle(24);
	hTight->SetMarkerSize(0.8);
	hTight->SetMinimum(1.e-3);
	hTight->SetMaximum(7.e+5);
	hTight->GetXaxis()->SetMoreLogLabels();
	hTight->GetXaxis()->SetNoExponent();
	leg->AddEntry(hTight,"tight-tight","lep");
	for(Int_t i=0 ; i<nTight ; i++)
	{
		tTight->GetEntry(i);
		hTight->Fill(Mhat*TeV2GeV);
	}

	
	hTight->Draw("e1x1");
	hLoose->Draw("e1x1SAMES");
	leg->Draw("SAMES");
	c->RedrawAxis();
	c->SaveAs("plots/Wjets.png");
}
void long_Ay_nu_05() {
  gROOT->SetStyle("HALLA");
  TCanvas *cn = new TCanvas("cn","cn",540,360);
  cn->Draw();
  cn->UseCurrentStyle();
  TH1F *frm = new TH1F("frm","",100,0.,10.);
  frm->GetXaxis()->SetTitle("#nu (GeV)");
  frm->GetYaxis()->SetTitle("Ay for Q2=0.456 (GeV/c)2");
  frm->SetMinimum(0);
//  frm->SetMinimum(0);
//  frm->SetMaximum(1.0);
  frm->SetMaximum(0.35);
  frm->UseCurrentStyle();
  frm->Draw();
  frm->SetAxisRange(0.120,0.350,"X");
//  frm->SetAxisRange(0.5,1.1,"X");

//  TF1* galster = new TF1("galster","x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))",0.,4.);
//  galster->SetLineColor(6);
//  galster->SetLineStyle(3);
//  galster->SetLineWidth(2);


  TF1 *genf = new TF1("genf",genff,1.,10.,1);
  genf->SetLineColor(2);
  genf->SetLineStyle(2);
  genf->SetParameter(0,1.);
  // match to Madey point just below 1.5
  // genf->SetParameter(0,.0411/genf->Eval(1.45));
  genf->SetParameter(0,-0.558645);

//  TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0);
//  bbba05->SetLineColor(7);
//  bbba05->SetLineStyle(3);

  
  TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}");
  TLegend *legDta = new TLegend(.54,.6,.875,.90,"","brNDC");

  TMultiGraph* wgr = mgrDta;
  TLegend *wlg = legDta;

   // the data
  legDta->SetBorderSize(0); // turn off border
  legDta->SetFillStyle(0);
  
  datafile_t *f = datafiles;
  TGraph* gr=0;
  while ( f && f->filename ) {
    gr=OneGraph(f);
    if (gr) {
      if (f->lnpt) {
	mgrDta->Add(gr,f->lnpt);
	legDta->AddEntry(gr,f->label,f->lnpt);
      }
      else if (gr->GetMarkerStyle()>=20) {
	mgrDta->Add(gr,"p");
	legDta->AddEntry(gr,f->label,"p");
      }	
      else {
	mgrDta->Add(gr,"l");
	legDta->AddEntry(gr,f->label,"l");
      }
    }
    f++;
  }
    

  mgrDta->Draw("p");
//  legDta->Draw();
  TF1 *theFit = new TF1("theFit","pol0");
  gr->Fit(theFit);
  theFit->Draw("same");  
  TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}");
  TLegend *legThry = new TLegend(.54,.3,.875,.6,"","brNDC");

  wgr = mgrThry;
  wlg = legThry;

  // the theory
  wlg->SetBorderSize(0); // turn off border
  wlg->SetFillStyle(0);
  
  f = theoryfiles1;
  gr=0;
  while ( f && f->filename ) {
    gr=OneGraph(f);
    if (gr) {
      TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr);
      if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) {
	gr = toerror_band(egr);
	gr->SetFillStyle(3000+f->style);
      }
      if (f->lnpt) {
	wgr->Add(gr,f->lnpt);
	wlg->AddEntry(gr,f->label,f->lnpt);
      }
      else if (gr->GetMarkerStyle()>=20) {
	wgr->Add(gr,"p");
	wlg->AddEntry(gr,f->label,"p");
      }	
      else {
	wgr->Add(gr,"l");
	wlg->AddEntry(gr,f->label,"l");
      }
    }
    f++;
  }

//  genf->Draw("same");
  mgrThry->Draw("c");
//  galster->Draw("same");
//  bbba05->Draw("same");
//  legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l");
//  legThry->AddEntry(galster,"Galster fit","l");
//  legThry->AddEntry(bbba05,"BBBA05","l");
//  legThry->Draw();
//  legDta->Draw();
  
  // draw a line at 1
  cn->Modified();

  cn->Update();
  cn->SaveAs(Form("%s.eps",psfile));
  cn->SaveAs(Form("%s.root",psfile));
  gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile));

  return;  // LEAVING HERE

  // now an overlay, hopefully matching dimensions

  // remove everything but the graph
  cn->Update();
  TList *clist = cn->GetListOfPrimitives();
  TFrame* frame = cn->GetFrame();
  for (int i=0; i<clist->GetSize(); ) {
    if (clist->At(i) != frame) {
      clist->RemoveAt(i);
    } else i++;
  }
  // draw markers in the corners
  TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2);
  mkr->Draw();
  mkr = new TMarker(frame->GetX2(),frame->GetY1(),2);
  mkr->Draw();
  mkr = new TMarker(frame->GetX1(),frame->GetY2(),2);
  mkr->Draw();
  mkr = new TMarker(frame->GetX2(),frame->GetY2(),2);
  mkr->Draw();
  frame->SetLineColor(10);
  cn->Update();

  datafile_t miller = { "figure_input/Miller/lattice.GEn.rtf","Miller",
			"[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" };

  gr = OneGraph(&miller);
  TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr);
  if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) {
    gr = toerror_band(egr);
    gr->SetLineStyle(1);
    gr->SetFillColor(gr->GetLineColor());
    gr->SetFillStyle(3000+miller.style);
  }
  
  gr->Draw("F");

  cn->Update();
  cn->SaveAs("gen_Miller_Overlay.eps");
  cn->SaveAs("gen_Miller_Overlay.root");
  
}
Example #29
0
   void qcd_study1( bool fillHists=false, bool savePlots=false, bool interactive=true, const char* datfile = "null" ) {

      TLine* line = new TLine() ;

      gStyle->SetPalette(1) ;
      gStyle->SetPadBottomMargin(0.20) ;

      gDirectory->Delete("h*") ;

      int nBinsBjets = 3 ;

        //-- met3-ht3-v5
        const int nBinsMET   = 3 ;
        const int nBinsHT    = 3 ;
         // const int version = 5;
        float Mbins[nBinsMET+1] = {125, 200.,350.,99999.};
        float Hbins[nBinsHT+1] = {400, 600.,1000.,99999.};

  //  ////-- met4-ht3-v3
  //  const int nBinsMET   = 4 ;
  //  const int nBinsHT    = 3 ;
  //      const int version = 3;
  //  float Mbins[nBinsMET+1] = {125, 150.,250.,350.,99999.};
  //  float Hbins[nBinsHT+1] = {400, 600.,1000.,99999.};

      ////-- met4-ht4-v15
      //const int nBinsMET   = 4 ;
      //const int nBinsHT    = 4 ;
      //    const int version = 15;
      //float Mbins[nBinsMET+1] = {125, 150.,250.,350.,99999.};
      //float Hbins[nBinsHT+1] = {400, 500.,800.,1000.,99999.};




      TH2F* hdummy = new TH2F("hdummy","",2, Mbins[0], 1500., 2, Hbins[0], 1500. ) ;

      const int nQcdSamples(9) ;

      char inputfile[9][1000] = {
        "files15fb_8TeV/QCD-120to170.root"
       ,"files15fb_8TeV/QCD-170to300.root"
       ,"files15fb_8TeV/QCD-300to470.root"
       ,"files15fb_8TeV/QCD-470to600.root"
       ,"files15fb_8TeV/QCD-600to800.root"
       ,"files15fb_8TeV/QCD-800to1000.root"
       ,"files15fb_8TeV/QCD-1000to1400.root"
       ,"files15fb_8TeV/QCD-1400to1800.root"
       ,"files15fb_8TeV/QCD-1800.root"
      } ;

      char samplename[9][100] = {
        "qcd_0120_to_0170"
       ,"qcd_0170_to_0300"
       ,"qcd_0300_to_0470"
       ,"qcd_0470_to_0600"
       ,"qcd_0600_to_0800"
       ,"qcd_0800_to_1000"
       ,"qcd_1000_to_1400"
       ,"qcd_1400_to_1800"
       ,"qcd_1800_to_9999"
      } ;

 //   int samplecolor[9] = {
 //      kOrange+8,
 //      kRed,
 //      KMagenta+2,
 //      KBlue+1,
 //      KAzure+2,
 //      KGreen+2,
 //      kPink-2,
 //      kViolet+2,
 //      kOrange+2
 //   } ;

      int samplecolor[9] = {
         800+8,
         632,
         616+2,
         600+1,
         860+2,
         416+2,
         900-2,
         880+2,
         800+2
      } ;

      TH2F*   h0lep[nQcdSamples][nBinsBjets] ;
      TH2F*   hldp [nQcdSamples][nBinsBjets] ;

      TCanvas* cqcd = (TCanvas*) gDirectory->FindObject("cqcd") ;
      if ( cqcd == 0x0 ) {
         cqcd = new TCanvas("cqcd", "qcd study", 700, 900 ) ;
      }

      char hname[1000] ;
      char htitle[1000] ;

      if ( fillHists ) {

         TChain* qcdch[nQcdSamples] ;

         printf("\n\n") ;
         for ( int si=0; si<nQcdSamples; si++ ) {

            qcdch[si] = new TChain("tree") ;
            printf(" %2d : connecting to %s\n", si, inputfile[si] ) ;
            qcdch[si] -> Add( inputfile[si] ) ;

            for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

               sprintf( hname, "h_0lep_%db_%s", bbi+1, samplename[si] ) ;
               sprintf( htitle, "QCD 0lep yield, nb=%d, %s", bbi+1, samplename[si] ) ;
               printf("         booking hist %s : %s\n", hname, htitle ) ;
               h0lep[si][bbi] = new TH2F( hname, htitle, nBinsMET, Mbins, nBinsHT, Hbins ) ;
               h0lep[si][bbi] -> Sumw2() ;
               sprintf( hname, "h_ldp_%db_%s", bbi+1, samplename[si] ) ;
               sprintf( htitle, "QCD  LDP yield, nb=%d, %s", bbi+1, samplename[si] ) ;
               printf("         booking hist %s  : %s\n", hname, htitle ) ;
               hldp [si][bbi] = new TH2F( hname, htitle, nBinsMET, Mbins, nBinsHT, Hbins ) ;
               hldp [si][bbi] -> Sumw2() ;

            } // bbi.

         } // si.
         printf("\n\n") ;





         char basecuts[10000] ;
         sprintf( basecuts, "pt_1st_leadJet>50&&pt_2nd_leadJet>50&&pt_3rd_leadJet>50&&HT>400&&MET>125&&nMu==0&&nEl==0&&nB>=1&&nJets>=3" ) ;

         char bcut[3][100] = { "nB==1", "nB==2", "nB>=3" } ;


         for ( int si=0; si<nQcdSamples; si++ ) {

            printf(" %2d : %s : 0lep\n", si, samplename[si] ) ; cout << flush ;
            for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

               char arg1[1000] ;

               char cuts0lep[10000] ;
               sprintf( cuts0lep, "(%s)&&(minDelPhiN>4&&%s)", basecuts, bcut[bbi] ) ;
               printf("     %db, 0lep cuts : %s\n", bbi+1, cuts0lep ) ;
               sprintf( arg1, "HT:MET>>h_0lep_%db_%s", bbi+1, samplename[si] ) ;
               qcdch[si] -> Draw( arg1, cuts0lep ) ;
               hdummy->Draw() ;
               h0lep[si][bbi]->Draw("samecolz") ;
               cqcd->Update() ; cqcd->Draw() ;


               char cutsldp[10000] ;
               sprintf( cutsldp, "(%s)&&(minDelPhiN<=4&&%s)", basecuts, bcut[bbi] ) ;
               printf("     %db, ldp  cuts : %s\n", bbi+1, cutsldp  ) ;
               sprintf( arg1, "HT:MET>>h_ldp_%db_%s", bbi+1, samplename[si] ) ;
               qcdch[si] -> Draw( arg1, cutsldp, "colz" ) ;
               hdummy->Draw() ;
               hldp[si][bbi]->Draw("samecolz") ;
               cqcd->Update() ; cqcd->Draw() ;

            } // bbi.

         } // si.

         saveHist( "rootfiles/qcd-study1.root", "h*" ) ;

      }

      //--------

      gStyle->SetOptStat(0) ;

      gDirectory->Delete("h*") ;
      loadHist( "rootfiles/qcd-study1.root" ) ;

      for ( int si=0; si<nQcdSamples; si++ ) {
         for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

            sprintf( hname, "h_0lep_%db_%s", bbi+1, samplename[si] ) ;
            printf("  loading %s\n", hname ) ;
            h0lep[si][bbi] = (TH2F*) gDirectory->FindObject( hname ) ;
            if ( h0lep[si][bbi] == 0x0 ) { printf("\n\n *** %s missing.\n\n", hname ) ; return ; }
            sprintf( hname, "h_ldp_%db_%s", bbi+1, samplename[si] ) ;
            printf("  loading %s\n", hname ) ;
            hldp [si][bbi] = (TH2F*) gDirectory->FindObject( hname ) ;
            if ( hldp [si][bbi] == 0x0 ) { printf("\n\n *** %s missing.\n\n", hname ) ; return ; }

         } // bbi.
      } // si.






     //--- Flatten 2D histos and compute 0lep/LDP ratios for each sample.

      int nbins = nBinsMET*(nBinsHT+1) + 1 ;

      TH1F* hflat_0lep[nQcdSamples][nBinsBjets] ;
      TH1F* hflat_ldp [nQcdSamples][nBinsBjets] ;
      TH1F* hflat_0lepldp_ratio[nQcdSamples][nBinsBjets] ;

      sprintf( hname, "hflat_0lep_all" ) ;
      sprintf( htitle, "All QCD 0lep events" ) ;
      TH1F* hflat_0lep_all = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;
      sprintf( hname, "hflat_ldp_all" ) ;
      sprintf( htitle, "All QCD ldp events" ) ;
      TH1F* hflat_ldp_all = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;


      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
         for ( int si=0; si<nQcdSamples; si++ ) {

            sprintf( hname, "hflat_0lep_%db_%s", bbi+1, samplename[si] ) ;
            sprintf( htitle, "QCD 0lep events, nb=%d, %s", bbi+1, samplename[si] ) ;
            hflat_0lep[si][bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, si ) ;
            hflat_0lep[si][bbi]->SetFillColor(11) ;
            hldp[si][bbi]->Print("all") ;

            sprintf( hname, "hflat_ldp_%db_%s", bbi+1, samplename[si] ) ;
            sprintf( htitle, "QCD LDP events, nb=%d, %s", bbi+1, samplename[si] ) ;
            hflat_ldp[si][bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, si ) ;
            hflat_ldp[si][bbi]->SetFillColor(11) ;

            sprintf( hname, "hflat_0lepldp_ratio_%db_%s", bbi+1, samplename[si] ) ;
            sprintf( htitle, "QCD 0lep/LDP ratio, nb=%d, %s", bbi+1, samplename[si] ) ;
            hflat_0lepldp_ratio[si][bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, si ) ;

            for ( int mbi=0; mbi<nBinsMET; mbi++ ) {
               for ( int hbi=0; hbi<nBinsHT; hbi++ ) {

                  int histbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ;

                  float n0lep     = h0lep[si][bbi] -> GetBinContent( mbi+1, hbi+1 ) ;
                  float n0lep_err = h0lep[si][bbi] -> GetBinError( mbi+1, hbi+1 ) ;

                  float nldp      = hldp [si][bbi] -> GetBinContent( mbi+1, hbi+1 ) ;
                  float nldp_err  = hldp [si][bbi] -> GetBinError( mbi+1, hbi+1 ) ;

                  hflat_0lep[si][bbi] -> SetBinContent( histbin, n0lep ) ;
                  hflat_0lep[si][bbi] -> SetBinError( histbin, n0lep_err ) ;

                  hflat_ldp[si][bbi]  -> SetBinContent( histbin, nldp ) ;
                  hflat_ldp[si][bbi]  -> SetBinError( histbin, nldp_err ) ;

                  double ratio(0.) ;
                  if ( nldp > 0 ) { ratio = n0lep / nldp ; }
                  double ratio_err(0.) ;
                  if ( n0lep_err > 0. && nldp_err > 0. ) {
                     ratio_err = ratio * sqrt( pow(n0lep_err/n0lep,2) + pow(nldp_err/nldp,2) ) ;
                  }

                  hflat_0lepldp_ratio[si][bbi] -> SetBinContent( histbin, ratio ) ;
                  hflat_0lepldp_ratio[si][bbi] -> SetBinError( histbin, ratio_err ) ;


               } // hbi.
            } // mbi.

            hflat_0lep_all -> Add( hflat_0lep[si][bbi] ) ;
            hflat_ldp_all  -> Add( hflat_ldp [si][bbi] ) ;

            cqcd->Clear() ;
            cqcd->Divide(1,3) ;

            cqcd->cd(1) ;
            hflat_0lep[si][bbi] -> DrawCopy("histe") ;
            hflat_0lep[si][bbi] -> DrawCopy("samee") ;

            cqcd->cd(2) ;
            hflat_ldp[si][bbi] -> DrawCopy("histe") ;
            hflat_ldp[si][bbi] -> DrawCopy("samee") ;

            cqcd->cd(3) ;
            hflat_0lepldp_ratio[si][bbi]->SetMinimum(-0.1) ;
            hflat_0lepldp_ratio[si][bbi]->SetMaximum(0.6) ;
            hflat_0lepldp_ratio[si][bbi]->SetMarkerStyle(20) ;
            hflat_0lepldp_ratio[si][bbi]->SetLineWidth(2) ;
            hflat_0lepldp_ratio[si][bbi]->DrawCopy() ;
            gPad->SetGridx(1) ;
            gPad->SetGridy(1) ;
            line->DrawLine(0.5,0,nbins+0.5,0) ;


            cqcd->Update() ; cqcd->Draw() ;

         } // si.
      } // bbi.

      TH1F* hflat_0lep_all_sqrtNerrs = (TH1F*) hflat_0lep_all->Clone("hflat_0lep_all_sqrtNerrs") ;
      TH1F* hflat_ldp_all_sqrtNerrs  = (TH1F*) hflat_ldp_all ->Clone("hflat_ldp_all_sqrtNerrs") ;

      for ( int bi=1; bi<=nbins; bi++ ) {
         double val ;
         val = hflat_0lep_all_sqrtNerrs->GetBinContent( bi ) ;
         hflat_0lep_all_sqrtNerrs -> SetBinError( bi, sqrt(val) ) ;
         val = hflat_ldp_all_sqrtNerrs->GetBinContent( bi ) ;
         hflat_ldp_all_sqrtNerrs -> SetBinError( bi, sqrt(val) ) ;
      }












     //--- Compute sample average of 0lep/LDP ratio


      TH1F* hflat_0lepldp_ratio_ave[nBinsBjets] ;

      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         sprintf( hname, "hflat_0lepldp_ratio_ave_%db", bbi+1 ) ;
         sprintf( htitle, "QCD 0lep/LDP average ratio, nb=%d", bbi+1 ) ;
         hflat_0lepldp_ratio_ave[bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;

         hflat_0lepldp_ratio_ave[bbi] -> SetMarkerStyle(24) ;
         hflat_0lepldp_ratio_ave[bbi] -> SetMarkerSize(2.0) ;
         hflat_0lepldp_ratio_ave[bbi] -> SetLineWidth(3) ;

         for ( int binind=1; binind<=nbins; binind++ ) {

            double wvsum(0.) ;
            double wsum(0.) ;

            for ( int si=0; si<nQcdSamples; si++ ) {

               double val = hflat_0lepldp_ratio[si][bbi] -> GetBinContent( binind ) ;
               double err = hflat_0lepldp_ratio[si][bbi] -> GetBinError( binind ) ;
               if ( err > 0 ) {
                  double weight = 1./(err*err) ;
                  wvsum += val*weight ;
                  wsum  += weight ;
               }
            } // si.

            if ( wsum > 0. ) {
               hflat_0lepldp_ratio_ave[bbi] -> SetBinContent( binind, wvsum/wsum ) ;
               hflat_0lepldp_ratio_ave[bbi] -> SetBinError( binind, 1./sqrt(wsum) ) ;
            }

         } // binind

      } // bbi.








     //--- Compute RMS spread of samples and total uncertainty


      TH1F* hflat_0lepldp_ratio_ave_withRMSerror[nBinsBjets] ;

      printf("\n\n") ;
      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         sprintf( hname, "hflat_0lepldp_ratio_ave_%db_withRMSerror", bbi+1 ) ;
         sprintf( htitle, "QCD 0lep/LDP average ratio, RMS included in error, nb=%d", bbi+1 ) ;
         hflat_0lepldp_ratio_ave_withRMSerror[bbi] = bookHist( hname, htitle, nBinsMET, nBinsHT, 5 ) ;

         hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetMarkerStyle(24) ;
         hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetMarkerSize(2.0) ;
         hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetLineWidth(3) ;

         for ( int binind=1; binind<=nbins; binind++ ) {

            double sumsquare(0.) ;
            int    nsum(0) ;

            double ave     = hflat_0lepldp_ratio_ave[bbi] -> GetBinContent( binind ) ;
            double ave_err = hflat_0lepldp_ratio_ave[bbi] -> GetBinError( binind ) ;

            for ( int si=0; si<nQcdSamples; si++ ) {

               double val = hflat_0lepldp_ratio[si][bbi] -> GetBinContent( binind ) ;
               double err = hflat_0lepldp_ratio[si][bbi] -> GetBinError( binind ) ;

               if ( err <= 0 ) { continue ; }
               if ( val <= 0 ) { continue ; }
               if ( err/val > 0.5 ) { continue ; } //-- do not include points with very large errors.


               double diff = val - ave ;

               sumsquare += diff*diff ;

               nsum ++ ;

            } // si.

            if ( nsum > 1 ) {
               double rms = sqrt(sumsquare/nsum) ;
               double totalerr = sqrt( ave_err*ave_err + rms*rms ) ;
               const char* binlabel = hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> GetXaxis() -> GetBinLabel( binind ) ;
               printf(" %s : %s : ratio = %5.3f, stat err = %5.3f, RMS = %5.3f,  total err = %5.3f\n",
                   hname, binlabel, ave, ave_err, rms, totalerr ) ;
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinContent( binind, ave ) ;
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinError( binind, totalerr ) ;
            } else {
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinContent( binind, ave ) ;
               hflat_0lepldp_ratio_ave_withRMSerror[bbi] -> SetBinError( binind, ave_err ) ;
            }

         } // binind
         printf("\n") ;

      } // bbi.
      printf("\n\n") ;






     //--- compute global average 0lep/LDP ratio.

      double all0lep(0.) ;
      double allldp(0.) ;

      printf("\n\n") ;
      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
         for ( int si=0; si<nQcdSamples; si++ ) {

            double sample_all0lep = h0lep[si][bbi] -> Integral() ;
            double sample_allldp  = hldp [si][bbi] -> Integral() ;
            double sample_ratio(0.) ;
            if ( sample_allldp > 0 ) { sample_ratio = sample_all0lep / sample_allldp ; }

            printf( "%s, nb=%d : 0lep = %8.1f,  LDP = %8.1f, ratio = %5.3f\n", samplename[si], bbi+1, sample_all0lep, sample_allldp, sample_ratio ) ;

            all0lep += sample_all0lep ;
            allldp += sample_allldp ;

         } // si.
         printf("\n") ;
      } // bbi.
      printf("\n\n") ;

      double global_0lepldp_ratio(0.) ;
      if ( allldp > 0.) {
         global_0lepldp_ratio = all0lep / allldp ;
      } else {
         printf("\n\n *** You screwed up.\n\n") ; return ;
      }
      printf("  overall : 0lep = %9.1f,  LDP = %9.1f, ratio = %5.3f\n", all0lep, allldp, global_0lepldp_ratio ) ;










     //--- Compute scale factors.  SF_i = (0lep/LDP)_i / global_(0lep/LDP)

      TH1F* hflat_scale_factor[nBinsBjets] ;
      TH1F* hflat_scale_factor_withRMSerror[nBinsBjets] ;

      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         sprintf( hname, "hflat_scale_factor_%db", bbi+1 ) ;
         sprintf( htitle, "QCD scale factor, nb=%d", bbi+1 ) ;
         hflat_scale_factor[bbi] = (TH1F*) hflat_0lepldp_ratio_ave[bbi]->Clone( hname ) ;
         hflat_scale_factor[bbi] -> SetTitle( htitle ) ;
         hflat_scale_factor[bbi] -> Scale( 1./ global_0lepldp_ratio ) ;

         sprintf( hname, "hflat_scale_factor_%db_withRMSerror", bbi+1 ) ;
         sprintf( htitle, "QCD scale factor, nb=%d, RMS error included ", bbi+1 ) ;
         hflat_scale_factor_withRMSerror[bbi] = (TH1F*) hflat_0lepldp_ratio_ave_withRMSerror[bbi]->Clone( hname ) ;
         hflat_scale_factor_withRMSerror[bbi] -> SetTitle( htitle ) ;
         hflat_scale_factor_withRMSerror[bbi] -> Scale( 1./ global_0lepldp_ratio ) ;

      } // bbi.









     //--- set Scale Factor values in dat file if one is provided.

      if ( strcmp( datfile, "null" ) != 0 ) {

         printf("\n\n\n Setting QCD scale factors in %s\n\n", datfile ) ;

         for ( int mbi=0; mbi<nBinsMET; mbi++ ) {
            for ( int hbi=0; hbi<nBinsHT; hbi++ ) {
               for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
                  char parname[1000] ;
                  int histbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ;
                  double val = hflat_scale_factor_withRMSerror[bbi]->GetBinContent( histbin ) ;
                  double err = hflat_scale_factor_withRMSerror[bbi]->GetBinError( histbin ) ;
                  if ( err <= 0 ) {
                     val = 1.0 ;
                     err = 3.0 ;
                  }
                  sprintf( parname, "sf_qcd_M%d_H%d_%db", mbi+1, hbi+1, bbi+1 ) ;
                  updateFileValue( datfile, parname, val ) ;
                  sprintf( parname, "sf_qcd_M%d_H%d_%db_err", mbi+1, hbi+1, bbi+1 ) ;
                  updateFileValue( datfile, parname, err ) ;
               } // bbi.
            } // hbi.
         } // mbi.

      }







     //===========  End calculations.  Plots and other output below here.  ===================================


     //--- Plot all samples together

      TCanvas* cqcd2 = (TCanvas*) gDirectory->FindObject("cqcd2") ;
      if ( cqcd2 == 0x0 ) {
         cqcd2 = new TCanvas("cqcd2", "qcd study", 1700, 600 ) ;
      }

      TLegend* l2 = new TLegend( 0.79, 0.70,  0.99, 0.99 ) ;
      l2->AddEntry( hflat_0lepldp_ratio[0][0], "120 to 170" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[1][0], "170 to 300" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[2][0], "300 to 470" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[3][0], "470 to 600" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[4][0], "600 to 800" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[5][0], "800 to 1000" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[6][0], "1000 to 1400" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[7][0], "1400 to 1800" ) ;
      l2->AddEntry( hflat_0lepldp_ratio[8][0], "> 1800" ) ;
      l2->AddEntry( hflat_0lepldp_ratio_ave[0], "Average ratio" ) ;


      cqcd2 -> Clear() ;
      cqcd2 -> Divide(3,1) ;

      cqcd2 -> cd(1) ;
      hflat_0lepldp_ratio[0][0] -> SetTitle("QCD 0lep/LDP ratio, nb=1") ;
      for ( int si=0; si<nQcdSamples; si++ ) {
         hflat_0lepldp_ratio[si][0] -> SetMarkerStyle(20+si) ;
         hflat_0lepldp_ratio[si][0] -> SetLineColor(samplecolor[si]) ;
         hflat_0lepldp_ratio[si][0] -> SetMarkerColor(samplecolor[si]) ;
         if ( si == 0 ) { hflat_0lepldp_ratio[si][0] -> DrawCopy() ; } else { hflat_0lepldp_ratio[si][0] -> DrawCopy("same") ; }
      }
      hflat_0lepldp_ratio_ave[0]->DrawCopy("same") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      l2->Draw() ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd2 -> cd(2) ;
      hflat_0lepldp_ratio[0][1] -> SetTitle("QCD 0lep/LDP ratio, nb=2") ;
      for ( int si=0; si<nQcdSamples; si++ ) {
         hflat_0lepldp_ratio[si][1] -> SetMarkerStyle(20+si) ;
         hflat_0lepldp_ratio[si][1] -> SetLineColor(samplecolor[si]) ;
         hflat_0lepldp_ratio[si][1] -> SetMarkerColor(samplecolor[si]) ;
         if ( si == 0 ) { hflat_0lepldp_ratio[si][1] -> DrawCopy() ; } else { hflat_0lepldp_ratio[si][1] -> DrawCopy("same") ; }
      }
      hflat_0lepldp_ratio_ave[1]->DrawCopy("same") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      l2->Draw() ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd2 -> cd(3) ;
      hflat_0lepldp_ratio[0][2] -> SetTitle("QCD 0lep/LDP ratio, nb>=3") ;
      for ( int si=0; si<nQcdSamples; si++ ) {
         hflat_0lepldp_ratio[si][2] -> SetMarkerStyle(20+si) ;
         hflat_0lepldp_ratio[si][2] -> SetLineColor(samplecolor[si]) ;
         hflat_0lepldp_ratio[si][2] -> SetMarkerColor(samplecolor[si]) ;
         if ( si == 0 ) { hflat_0lepldp_ratio[si][2] -> DrawCopy() ; } else { hflat_0lepldp_ratio[si][2] -> DrawCopy("same") ; }
      }
      hflat_0lepldp_ratio_ave[2]->DrawCopy("same") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      l2->Draw() ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;


      cqcd2->Update() ; cqcd2->Draw() ;

      if ( savePlots ) {
         cqcd2 -> SaveAs("outputfiles/qcd-study1-allonone.png") ;
         cqcd2 -> SaveAs("outputfiles/qcd-study1-allonone.pdf") ;
      }








     //--- Go through the samples, 1 by 1, and draw numerator, denominator, and ratio

      TCanvas* cqcd3 = (TCanvas*) gDirectory->FindObject("cqcd3") ;
      if ( cqcd3 == 0x0 ) {
         cqcd3 = new TCanvas("cqcd3", "qcd study", 1200, 900 ) ;
      }

      char oldtitle[1000] ;
      sprintf( oldtitle, "QCD 0lep/LDP ratio, nb=1, %s", samplename[0] ) ;
      hflat_0lepldp_ratio[0][0] -> SetTitle(oldtitle) ;
      sprintf( oldtitle, "QCD 0lep/LDP ratio, nb=2, %s", samplename[0] ) ;
      hflat_0lepldp_ratio[0][1] -> SetTitle(oldtitle) ;
      sprintf( oldtitle, "QCD 0lep/LDP ratio, nb>=3, %s", samplename[0] ) ;
      hflat_0lepldp_ratio[0][2] -> SetTitle(oldtitle) ;

      cqcd3->Clear() ;
      cqcd3->Divide(3,3) ;

      for ( int si=0; si<nQcdSamples; si++ ) {
         TLegend* l3 = new TLegend( 0.65, 0.78, 0.99, 0.92) ;
         l3->AddEntry( hflat_0lepldp_ratio[si][0], samplename[si] ) ;
         l3->AddEntry( hflat_0lepldp_ratio_ave[0], "Average") ;
         for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

            cqcd3->cd(1+bbi) ;
            hflat_0lep[si][bbi] -> DrawCopy("histe") ;
            hflat_0lep[si][bbi] -> DrawCopy("samee") ;

            cqcd3->cd(4+bbi) ;
            hflat_ldp[si][bbi] -> DrawCopy("histe") ;
            hflat_ldp[si][bbi] -> DrawCopy("samee") ;


            cqcd3->cd(7+bbi) ;
            gPad->SetGridx(1) ;
            gPad->SetGridy(1) ;
            hflat_0lepldp_ratio[si][bbi]->DrawCopy() ;
            hflat_0lepldp_ratio_ave[bbi]->DrawCopy("same") ;
            line->DrawLine(0.5,0,nbins+0.5,0) ;
            l3->Draw() ;

         } // bbi.

         cqcd3->Update() ; cqcd3->Draw() ;

         if ( savePlots ) {
            char filename[1000] ;
            sprintf( filename, "outputfiles/qcd-study1-%s.pdf", samplename[si] ) ;
            cqcd3 -> SaveAs( filename ) ;
            sprintf( filename, "outputfiles/qcd-study1-%s.png", samplename[si] ) ;
            cqcd3 -> SaveAs( filename ) ;
         }
         if ( interactive ) {
            char a = getchar() ;
            if ( a == 'q') { return ; }
         }

      } // si.







     //--- Draw the average 0lep/LDP ratio with MC stat error and total error.

      TCanvas* cqcd4 = (TCanvas*) gDirectory->FindObject("cqcd4") ;
      if ( cqcd4 == 0x0 ) {
         cqcd4 = new TCanvas("cqcd4", "qcd study", 1700, 600 ) ;
      }

      gStyle->SetEndErrorSize(5) ;

      cqcd4->Clear() ;
      cqcd4->Divide(3,1) ;

      cqcd4 -> cd(1) ;
      hflat_0lepldp_ratio_ave[0] -> SetTitle("Average QCD 0lep/LDP ratio, nb=1") ;
      hflat_0lepldp_ratio_ave[0] -> SetMarkerSize(1.2) ;
      hflat_0lepldp_ratio_ave[0] -> SetMarkerStyle(20) ;
      hflat_0lepldp_ratio_ave[0] -> SetMaximum(0.6) ;
      hflat_0lepldp_ratio_ave[0] -> SetMinimum(-0.1) ;
      hflat_0lepldp_ratio_ave[0]->DrawCopy("e1") ;
      hflat_0lepldp_ratio_ave_withRMSerror[0]->SetMarkerStyle() ;
      hflat_0lepldp_ratio_ave_withRMSerror[0]->SetLineColor(4) ;
      hflat_0lepldp_ratio_ave_withRMSerror[0]->DrawCopy("samee1") ;
      hflat_0lepldp_ratio_ave[0]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd4 -> cd(2) ;
      hflat_0lepldp_ratio_ave[1] -> SetTitle("Average QCD 0lep/LDP ratio, nb=2") ;
      hflat_0lepldp_ratio_ave[1] -> SetMarkerSize(1.2) ;
      hflat_0lepldp_ratio_ave[1] -> SetMarkerStyle(20) ;
      hflat_0lepldp_ratio_ave[1] -> SetMaximum(0.6) ;
      hflat_0lepldp_ratio_ave[1] -> SetMinimum(-0.1) ;
      hflat_0lepldp_ratio_ave[1]->DrawCopy("e1") ;
      hflat_0lepldp_ratio_ave_withRMSerror[1]->SetMarkerStyle() ;
      hflat_0lepldp_ratio_ave_withRMSerror[1]->SetLineColor(4) ;
      hflat_0lepldp_ratio_ave_withRMSerror[1]->DrawCopy("samee1") ;
      hflat_0lepldp_ratio_ave[1]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd4 -> cd(3) ;
      hflat_0lepldp_ratio_ave[2] -> SetTitle("Average QCD 0lep/LDP ratio, nb>=3") ;
      hflat_0lepldp_ratio_ave[2] -> SetMarkerSize(1.2) ;
      hflat_0lepldp_ratio_ave[2] -> SetMarkerStyle(20) ;
      hflat_0lepldp_ratio_ave[2] -> SetMaximum(0.6) ;
      hflat_0lepldp_ratio_ave[2] -> SetMinimum(-0.1) ;
      hflat_0lepldp_ratio_ave[2]->DrawCopy("e1") ;
      hflat_0lepldp_ratio_ave_withRMSerror[2]->SetMarkerStyle() ;
      hflat_0lepldp_ratio_ave_withRMSerror[2]->SetLineColor(4) ;
      hflat_0lepldp_ratio_ave_withRMSerror[2]->DrawCopy("samee1") ;
      hflat_0lepldp_ratio_ave[2]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;


      cqcd4->Update() ; cqcd4->Draw() ;

      if ( savePlots ) {
         cqcd4 -> SaveAs("outputfiles/qcd-study1-averatio.png") ;
         cqcd4 -> SaveAs("outputfiles/qcd-study1-averatio.pdf") ;
      }












     //--- Draw the QCD scale factor with MC stat error and total error.

      TCanvas* cqcd5 = (TCanvas*) gDirectory->FindObject("cqcd5") ;
      if ( cqcd5 == 0x0 ) {
         cqcd5 = new TCanvas("cqcd5", "qcd study", 1700, 600 ) ;
      }

      gStyle->SetEndErrorSize(5) ;

      cqcd5->Clear() ;
      cqcd5->Divide(3,1) ;

      cqcd5 -> cd(1) ;
      hflat_scale_factor[0] -> SetTitle("QCD Scale Factor, nb=1") ;
      hflat_scale_factor[0] -> SetMarkerSize(1.2) ;
      hflat_scale_factor[0] -> SetMarkerStyle(20) ;
      hflat_scale_factor[0] -> SetMaximum(2.6) ;
      hflat_scale_factor[0] -> SetMinimum(-0.1) ;
      hflat_scale_factor[0]->DrawCopy("e1") ;
      hflat_scale_factor_withRMSerror[0]->SetMarkerStyle() ;
      hflat_scale_factor_withRMSerror[0]->SetLineColor(4) ;
      hflat_scale_factor_withRMSerror[0]->DrawCopy("samee1") ;
      hflat_scale_factor[0]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd5 -> cd(2) ;
      hflat_scale_factor[1] -> SetTitle("QCD Scale Factor, nb=2") ;
      hflat_scale_factor[1] -> SetMarkerSize(1.2) ;
      hflat_scale_factor[1] -> SetMarkerStyle(20) ;
      hflat_scale_factor[1] -> SetMaximum(2.6) ;
      hflat_scale_factor[1] -> SetMinimum(-0.1) ;
      hflat_scale_factor[1]->DrawCopy("e1") ;
      hflat_scale_factor_withRMSerror[1]->SetMarkerStyle() ;
      hflat_scale_factor_withRMSerror[1]->SetLineColor(4) ;
      hflat_scale_factor_withRMSerror[1]->DrawCopy("samee1") ;
      hflat_scale_factor[1]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;

      cqcd5 -> cd(3) ;
      hflat_scale_factor[2] -> SetTitle("QCD Scale Factor, nb>=3") ;
      hflat_scale_factor[2] -> SetMarkerSize(1.2) ;
      hflat_scale_factor[2] -> SetMarkerStyle(20) ;
      hflat_scale_factor[2] -> SetMaximum(2.6) ;
      hflat_scale_factor[2] -> SetMinimum(-0.1) ;
      hflat_scale_factor[2]->DrawCopy("e1") ;
      hflat_scale_factor_withRMSerror[2]->SetMarkerStyle() ;
      hflat_scale_factor_withRMSerror[2]->SetLineColor(4) ;
      hflat_scale_factor_withRMSerror[2]->DrawCopy("samee1") ;
      hflat_scale_factor[2]->DrawCopy("samee1") ;
      line->DrawLine(0.5,0,nbins+0.5,0) ;
      gPad->SetGridx(1) ;
      gPad->SetGridy(1) ;


      cqcd5->Update() ; cqcd5->Draw() ;

      if ( savePlots ) {
         cqcd5 -> SaveAs("outputfiles/qcd-study1-scalefactor.png") ;
         cqcd5 -> SaveAs("outputfiles/qcd-study1-scalefactor.pdf") ;
      }







   } // qcd_study.
Example #30
0
vector<Double_t*> simFit(bool makeSoupFit_ = false,
			 const string tnp_ = "etoTauMargLooseNoCracks70", 
			 const string category_ = "tauAntiEMVA",
			 const string bin_ = "abseta<1.5",
			 const float binCenter_ = 0.75,
			 const float binWidth_ = 0.75,
			 const float xLow_=60, 
			 const float xHigh_=120,
			 bool SumW2_ = false,
			 bool verbose_ = true){

  vector<Double_t*> out;
  //return out;

  //TFile *test = new TFile( outFile->GetName(),"UPDATE");
  // output file
  TFile *test = new TFile( Form("EtoTauPlotsFit_%s_%s_%f.root",tnp_.c_str(),category_.c_str(),binCenter_),"RECREATE");
  test->mkdir(Form("bin%f",binCenter_));

  TCanvas *c = new TCanvas("fitCanvas",Form("fitCanvas_%s_%s",tnp_.c_str(),bin_.c_str()),10,30,650,600);
  c->SetGrid(0,0);
  c->SetFillStyle(4000);
  c->SetFillColor(10);
  c->SetTicky();
  c->SetObjectStat(0);
  
  TCanvas *c2 = new TCanvas("fitCanvasTemplate",Form("fitCanvasTemplate_%s_%s",tnp_.c_str(),bin_.c_str()),10,30,650,600);
  c2->SetGrid(0,0);
  c2->SetFillStyle(4000);
  c2->SetFillColor(10);
  c2->SetTicky();
  c2->SetObjectStat(0);

  // input files
  TFile fsup("/data_CMS/cms/lbianchini/tagAndProbe/trees/38XWcut/testNewWriteFromPAT_soup.root");
  TFile fbkg("/data_CMS/cms/lbianchini/tagAndProbe/trees/38XWcut/testNewWriteFromPAT_soup_bkg.root");
  TFile fsgn("/data_CMS/cms/lbianchini/tagAndProbe/trees/38XWcut/testNewWriteFromPAT_soup_sgn.root");
  TFile fdat("/data_CMS/cms/lbianchini/tagAndProbe/trees/38XWcut/testNewWriteFromPAT_Data.root");
  // data from 2iter:
  //TFile fdat("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_Data.root");
  
  //********************** signal only tree *************************/

  TTree *fullTreeSgn = (TTree*)fsgn.Get((tnp_+"/fitter_tree").c_str());
  TH1F* hSall        = new TH1F("hSall","",1,0,150);
  TH1F* hSPall       = new TH1F("hSPall","",1,0,150);
  TH1F* hS           = new TH1F("hS","",1,0,150);
  TH1F* hSP          = new TH1F("hSP","",1,0,150);
  fullTreeSgn->Draw("mass>>hS",Form("weight*(%s && mass>%f && mass<%f && mcTrue && signalPFChargedHadrCands<1.5)",bin_.c_str(),xLow_,xHigh_));
  fullTreeSgn->Draw("mass>>hSall",Form("weight*(%s && mass>%f && mass<%f)",bin_.c_str(),xLow_,xHigh_));

  float SGNtrue = hS->Integral();
  float SGNall  = hSall->Integral();
 
  fullTreeSgn->Draw("mass>>hSP",Form("weight*(%s && %s>0 && mass>%f && mass<%f && mcTrue && signalPFChargedHadrCands<1.5 )",bin_.c_str(),category_.c_str(),xLow_,xHigh_));
  fullTreeSgn->Draw("mass>>hSPall",Form("weight*(%s && %s>0 && mass>%f && mass<%f && signalPFChargedHadrCands<1.5 )",bin_.c_str(),category_.c_str(),xLow_,xHigh_));

  float SGNtruePass = hSP->Integral();
  float SGNallPass  = hSPall->Integral();

  //********************** background only tree *************************//

  TTree *fullTreeBkg = (TTree*)fbkg.Get((tnp_+"/fitter_tree").c_str());
  TH1F* hB = new TH1F("hB","",1,0,150);
  TH1F* hBP = new TH1F("hBP","",1,0,150);
  fullTreeBkg->Draw("mass>>hB",Form("weight*(%s && mass>%f && mass<%f && signalPFChargedHadrCands<1.5 )",bin_.c_str(),xLow_,xHigh_));
 
  float BKG           = hB->Integral();
  float BKGUnWeighted = hB->GetEntries();
  
  fullTreeBkg->Draw("mass>>hBP",Form("weight*(%s && %s>0 && mass>%f && mass<%f && signalPFChargedHadrCands<1.5 )",bin_.c_str(),category_.c_str(),xLow_,xHigh_));
  
  float BKGPass           = hBP->Integral();
  float BKGUnWeightedPass = hBP->GetEntries();
  float BKGFail           = BKG-BKGPass;
  cout << "*********** BKGFail " << BKGFail << endl;

  //********************** soup tree *************************//

  TTree *fullTreeSoup = (TTree*)fsup.Get((tnp_+"/fitter_tree").c_str());

  //********************** data tree *************************//

  TTree *fullTreeData = (TTree*)fdat.Get((tnp_+"/fitter_tree").c_str());

  //********************** workspace ***********************//

  RooWorkspace *w = new RooWorkspace("w","w");
  // tree variables to be imported
  w->factory("mass[30,120]");
  w->factory("weight[0,10000]");
  w->factory("abseta[0,2.5]");
  w->factory("pt[0,200]");
  w->factory("mcTrue[0,1]");
  w->factory("signalPFChargedHadrCands[0,10]");
  w->factory((category_+"[0,1]").c_str());
  // background pass pdf for MC
  w->factory("RooExponential::McBackgroundPdfP(mass,McCP[0,-10,10])");
  // background fail pdf for MC
  w->factory("RooExponential::McBackgroundPdfF(mass,McCF[0,-10,10])");
  // background pass pdf for Data
  w->factory("RooExponential::DataBackgroundPdfP(mass,DataCP[0,-10,10])");
  // background fail pdf for Data
  w->factory("RooExponential::DataBackgroundPdfF(mass,DataCF[0,-10,10])");
  // fit parameters for background
  w->factory("McEfficiency[0.04,0,1]");
  w->factory("McNumSgn[0,1000000]");
  w->factory("McNumBkgP[0,100000]");
  w->factory("McNumBkgF[0,100000]"); 
  w->factory("expr::McNumSgnP('McEfficiency*McNumSgn',McEfficiency,McNumSgn)");
  w->factory("expr::McNumSgnF('(1-McEfficiency)*McNumSgn',McEfficiency,McNumSgn)");
  w->factory("McPassing[pass=1,fail=0]");
  // fit parameters for data
  w->factory("DataEfficiency[0.1,0,1]");
  w->factory("DataNumSgn[0,1000000]");
  w->factory("DataNumBkgP[0,1000000]");
  w->factory("DataNumBkgF[0,10000]");
  w->factory("expr::DataNumSgnP('DataEfficiency*DataNumSgn',DataEfficiency,DataNumSgn)");
  w->factory("expr::DataNumSgnF('(1-DataEfficiency)*DataNumSgn',DataEfficiency,DataNumSgn)");
  w->factory("DataPassing[pass=1,fail=0]");

  RooRealVar  *weight = w->var("weight");
  RooRealVar  *abseta = w->var("abseta");
  RooRealVar  *pt     = w->var("pt");
  RooRealVar  *mass   = w->var("mass");
  mass->setRange(xLow_,xHigh_);
  RooRealVar  *mcTrue = w->var("mcTrue");
  RooRealVar  *cut    = w->var( category_.c_str() );
  RooRealVar  *signalPFChargedHadrCands = w->var("signalPFChargedHadrCands");
 
  // build the template for the signal pass sample:
  RooDataSet templateP("templateP","dataset for signal-pass template", RooArgSet(*mass,*weight,*abseta,*pt,*cut,*mcTrue,*signalPFChargedHadrCands), Import( *fullTreeSgn ), /*WeightVar( *weight ),*/ Cut( Form("(mcTrue && %s>0.5 && %s && signalPFChargedHadrCands<1.5)",category_.c_str(),bin_.c_str()) ) );
  // build the template for the signal fail sample:
  RooDataSet templateF("templateF","dataset for signal-fail template", RooArgSet(*mass,*weight,*abseta,*pt,*cut,*mcTrue,*signalPFChargedHadrCands), Import( *fullTreeSgn ), /*WeightVar( *weight ),*/ Cut( Form("(mcTrue && %s<0.5 && %s && signalPFChargedHadrCands<1.5)",category_.c_str(),bin_.c_str()) ) );
  

  mass->setBins(24);
  RooDataHist templateHistP("templateHistP","",RooArgSet(*mass), templateP, 1.0);
  RooHistPdf TemplateSignalPdfP("TemplateSignalPdfP","",RooArgSet(*mass),templateHistP);
  w->import(TemplateSignalPdfP);

  mass->setBins(24);
  RooDataHist templateHistF("templateHistF","",RooArgSet(*mass),templateF,1.0);
  RooHistPdf TemplateSignalPdfF("TemplateSignalPdfF","",RooArgSet(*mass),templateHistF);
  w->import(TemplateSignalPdfF);

  mass->setBins(10000,"fft");

  RooPlot* TemplateFrameP = mass->frame(Bins(24),Title("Template passing"));
  templateP.plotOn(TemplateFrameP);
  w->pdf("TemplateSignalPdfP")->plotOn(TemplateFrameP);
  
  RooPlot* TemplateFrameF = mass->frame(Bins(24),Title("Template failing"));
  templateF.plotOn(TemplateFrameF);
  w->pdf("TemplateSignalPdfF")->plotOn(TemplateFrameF);

  //w->factory("RooFFTConvPdf::McSignalPdfP(mass,TemplateSignalPdfP,RooTruthModel::McResolModP(mass))");
  //w->factory("RooFFTConvPdf::McSignalPdfF(mass,TemplateSignalPdfF,RooTruthModel::McResolModF(mass))");

  // FOR GREGORY: PROBLEM WHEN TRY TO USE THE PURE TEMPLATE =>
  RooHistPdf McSignalPdfP("McSignalPdfP","McSignalPdfP",RooArgSet(*mass),templateHistP);
  RooHistPdf McSignalPdfF("McSignalPdfF","McSignalPdfF",RooArgSet(*mass),templateHistF);
  w->import(McSignalPdfP);
  w->import(McSignalPdfF);
  // FOR GREGORY: FOR DATA, CONVOLUTION IS OK =>
  w->factory("RooFFTConvPdf::DataSignalPdfP(mass,TemplateSignalPdfP,RooGaussian::DataResolModP(mass,DataMeanResP[0.0,-5.,5.],DataSigmaResP[0.5,0.,10]))");
  w->factory("RooFFTConvPdf::DataSignalPdfF(mass,TemplateSignalPdfF,RooGaussian::DataResolModF(mass,DataMeanResF[-5.,-10.,10.],DataSigmaResF[0.5,0.,10]))");
  //w->factory("RooCBShape::DataSignalPdfF(mass,DataMeanF[91.2,88,95.],DataSigmaF[3,0.5,8],DataAlfaF[1.8,0.,10],DataNF[1.0,1e-06,10])");
  //w->factory("RooFFTConvPdf::DataSignalPdfF(mass,RooVoigtian::DataVoigF(mass,DataMeanF[85,80,95],DataWidthF[2.49],DataSigmaF[3,0.5,10]),RooCBShape::DataResolModF(mass,DataMeanResF[0.5,0.,10.],DataSigmaResF[0.5,0.,10],DataAlphaResF[0.5,0.,10],DataNResF[1.0,1e-06,10]))");
  //w->factory("SUM::DataSignalPdfF(fVBP[0.5,0,1]*RooBifurGauss::bifF(mass,DataMeanResF[91.2,80,95],sigmaLF[10,0.5,40],sigmaRF[0.]), RooVoigtian::voigF(mass, DataMeanResF, widthF[2.49], sigmaVoigF[5,0.1,10]) )" );
  
  // composite model pass for MC
  w->factory("SUM::McModelP(McNumSgnP*McSignalPdfP,McNumBkgP*McBackgroundPdfP)");  
  w->factory("SUM::McModelF(McNumSgnF*McSignalPdfF,McNumBkgF*McBackgroundPdfF)");
  // composite model pass for data
  w->factory("SUM::DataModelP(DataNumSgnP*DataSignalPdfP,DataNumBkgP*DataBackgroundPdfP)");  
  w->factory("SUM::DataModelF(DataNumSgnF*DataSignalPdfF,DataNumBkgF*DataBackgroundPdfF)");  
  // simultaneous fir for MC
  w->factory("SIMUL::McModel(McPassing,pass=McModelP,fail=McModelF)");
  // simultaneous fir for data
  w->factory("SIMUL::DataModel(DataPassing,pass=DataModelP,fail=DataModelF)");
  w->Print("V");
  w->saveSnapshot("clean", w->allVars());

  w->loadSnapshot("clean");

  /****************** sim fit to soup **************************/

  ///////////////////////////////////////////////////////////////
  TFile *f = new TFile("dummySoup.root","RECREATE");
  TTree* cutTreeSoupP = fullTreeSoup->CopyTree(Form("(%s>0.5 && %s && signalPFChargedHadrCands<1.5)",category_.c_str(),bin_.c_str()));
  TTree* cutTreeSoupF = fullTreeSoup->CopyTree(Form("(%s<0.5 && %s && signalPFChargedHadrCands<1.5)",category_.c_str(),bin_.c_str()));
 
  RooDataSet McDataP("McDataP","dataset pass for the soup", RooArgSet(*mass), Import( *cutTreeSoupP ) );
 
  RooDataSet McDataF("McDataF","dataset fail for the soup", RooArgSet(*mass), Import( *cutTreeSoupF ) );
 
  RooDataHist McCombData("McCombData","combined data for the soup", RooArgSet(*mass), Index(*(w->cat("McPassing"))), Import("pass", *(McDataP.createHistogram("histoP",*mass)) ), Import("fail",*(McDataF.createHistogram("histoF",*mass)) ) ) ;

  RooPlot* McFrameP    = 0;
  RooPlot* McFrameF    = 0;
  RooRealVar* McEffFit = 0;

  if(makeSoupFit_){

    cout << "**************** N bins in mass " << w->var("mass")->getBins() << endl;

    RooFitResult* ResMcCombinedFit = w->pdf("McModel")->fitTo(McCombData, Extended(1), Minos(1), Save(1),  SumW2Error( SumW2_ ), Range(xLow_,xHigh_), NumCPU(4) /*, ExternalConstraints( *(w->pdf("ConstrainMcNumBkgF")) )*/ );
    test->cd(Form("bin%f",binCenter_));
    ResMcCombinedFit->Write("McFitResults_Combined");

    RooArgSet McFitParam(ResMcCombinedFit->floatParsFinal());
    McEffFit     = (RooRealVar*)(&McFitParam["McEfficiency"]);
    RooRealVar* McNumSigFit  = (RooRealVar*)(&McFitParam["McNumSgn"]);
    RooRealVar* McNumBkgPFit = (RooRealVar*)(&McFitParam["McNumBkgP"]);
    RooRealVar* McNumBkgFFit = (RooRealVar*)(&McFitParam["McNumBkgF"]);

    McFrameP = mass->frame(Bins(24),Title("MC: passing sample"));
    McCombData.plotOn(McFrameP,Cut("McPassing==McPassing::pass"));
    w->pdf("McModel")->plotOn(McFrameP,Slice(*(w->cat("McPassing")),"pass"), ProjWData(*(w->cat("McPassing")),McCombData), LineColor(kBlue),Range(xLow_,xHigh_));
    w->pdf("McModel")->plotOn(McFrameP,Slice(*(w->cat("McPassing")),"pass"), ProjWData(*(w->cat("McPassing")),McCombData), Components("McSignalPdfP"), LineColor(kRed),Range(xLow_,xHigh_));
    w->pdf("McModel")->plotOn(McFrameP,Slice(*(w->cat("McPassing")),"pass"), ProjWData(*(w->cat("McPassing")),McCombData), Components("McBackgroundPdfP"), LineColor(kGreen),Range(xLow_,xHigh_));
    
    McFrameF = mass->frame(Bins(24),Title("MC: failing sample"));
    McCombData.plotOn(McFrameF,Cut("McPassing==McPassing::fail"));
    w->pdf("McModel")->plotOn(McFrameF,Slice(*(w->cat("McPassing")),"fail"), ProjWData(*(w->cat("McPassing")),McCombData), LineColor(kBlue),Range(xLow_,xHigh_));
    w->pdf("McModel")->plotOn(McFrameF,Slice(*(w->cat("McPassing")),"fail"), ProjWData(*(w->cat("McPassing")),McCombData), Components("McSignalPdfF"), LineColor(kRed),Range(xLow_,xHigh_)); 
    w->pdf("McModel")->plotOn(McFrameF,Slice(*(w->cat("McPassing")),"fail"), ProjWData(*(w->cat("McPassing")),McCombData), Components("McBackgroundPdfF"), LineColor(kGreen),Range(xLow_,xHigh_)); 
  }
  
  ///////////////////////////////////////////////////////////////

  /****************** sim fit to data **************************/

  ///////////////////////////////////////////////////////////////
  TFile *f2 = new TFile("dummyData.root","RECREATE");
  TTree* cutTreeDataP = fullTreeData->CopyTree(Form("(%s>0.5 && %s && signalPFChargedHadrCands<1.5)",category_.c_str(),bin_.c_str()));
  TTree* cutTreeDataF = fullTreeData->CopyTree(Form("(%s<0.5 && %s && signalPFChargedHadrCands<1.5)",category_.c_str(),bin_.c_str()));
 
  RooDataSet DataDataP("DataDataP","dataset pass for the soup", RooArgSet(*mass), Import( *cutTreeDataP ) );
  RooDataSet DataDataF("DataDataF","dataset fail for the soup", RooArgSet(*mass), Import( *cutTreeDataF ) );
  RooDataHist DataCombData("DataCombData","combined data for the soup", RooArgSet(*mass), Index(*(w->cat("DataPassing"))), Import("pass",*(DataDataP.createHistogram("histoDataP",*mass))),Import("fail",*(DataDataF.createHistogram("histoDataF",*mass)))) ;

  RooFitResult* ResDataCombinedFit = w->pdf("DataModel")->fitTo(DataCombData, Extended(1), Minos(1), Save(1),  SumW2Error( SumW2_ ), Range(xLow_,xHigh_), NumCPU(4));
  test->cd(Form("bin%f",binCenter_));
  ResDataCombinedFit->Write("DataFitResults_Combined");

  RooArgSet DataFitParam(ResDataCombinedFit->floatParsFinal());
  RooRealVar* DataEffFit     = (RooRealVar*)(&DataFitParam["DataEfficiency"]);
  RooRealVar* DataNumSigFit  = (RooRealVar*)(&DataFitParam["DataNumSgn"]);
  RooRealVar* DataNumBkgPFit = (RooRealVar*)(&DataFitParam["DataNumBkgP"]);
  RooRealVar* DataNumBkgFFit = (RooRealVar*)(&DataFitParam["DataNumBkgF"]);

  RooPlot* DataFrameP = mass->frame(Bins(24),Title("Data: passing sample"));
  DataCombData.plotOn(DataFrameP,Cut("DataPassing==DataPassing::pass"));
  w->pdf("DataModel")->plotOn(DataFrameP,Slice(*(w->cat("DataPassing")),"pass"), ProjWData(*(w->cat("DataPassing")),DataCombData), LineColor(kBlue),Range(xLow_,xHigh_));
  w->pdf("DataModel")->plotOn(DataFrameP,Slice(*(w->cat("DataPassing")),"pass"), ProjWData(*(w->cat("DataPassing")),DataCombData), Components("DataSignalPdfP"), LineColor(kRed),Range(xLow_,xHigh_));
  w->pdf("DataModel")->plotOn(DataFrameP,Slice(*(w->cat("DataPassing")),"pass"), ProjWData(*(w->cat("DataPassing")),DataCombData), Components("DataBackgroundPdfP"), LineColor(kGreen),LineStyle(kDashed),Range(xLow_,xHigh_));
  
  RooPlot* DataFrameF = mass->frame(Bins(24),Title("Data: failing sample"));
  DataCombData.plotOn(DataFrameF,Cut("DataPassing==DataPassing::fail"));
  w->pdf("DataModel")->plotOn(DataFrameF,Slice(*(w->cat("DataPassing")),"fail"), ProjWData(*(w->cat("DataPassing")),DataCombData), LineColor(kBlue),Range(xLow_,xHigh_));
  w->pdf("DataModel")->plotOn(DataFrameF,Slice(*(w->cat("DataPassing")),"fail"), ProjWData(*(w->cat("DataPassing")),DataCombData), Components("DataSignalPdfF"), LineColor(kRed),Range(xLow_,xHigh_));
  w->pdf("DataModel")->plotOn(DataFrameF,Slice(*(w->cat("DataPassing")),"fail"), ProjWData(*(w->cat("DataPassing")),DataCombData), Components("DataBackgroundPdfF"), LineColor(kGreen),LineStyle(kDashed),Range(xLow_,xHigh_));
  ///////////////////////////////////////////////////////////////

 
  if(makeSoupFit_) c->Divide(2,2);
  else c->Divide(2,1);
 
  c->cd(1);
  DataFrameP->Draw();
  c->cd(2);
  DataFrameF->Draw();

  if(makeSoupFit_){
    c->cd(3);
    McFrameP->Draw();
    c->cd(4);
    McFrameF->Draw();
  }
 
  c->Draw();
 
  test->cd(Form("bin%f",binCenter_));
 
  c->Write();
 
  c2->Divide(2,1);
  c2->cd(1);
  TemplateFrameP->Draw();
  c2->cd(2);
  TemplateFrameF->Draw();
  c2->Draw();
 
  test->cd(Form("bin%f",binCenter_));
  c2->Write();


  // MINOS errors, otherwise HESSE quadratic errors
  float McErrorLo = 0;
  float McErrorHi = 0;
  if(makeSoupFit_){
    McErrorLo = McEffFit->getErrorLo()<0 ? McEffFit->getErrorLo() : (-1)*McEffFit->getError();
    McErrorHi = McEffFit->getErrorHi()>0 ? McEffFit->getErrorHi() : McEffFit->getError();
  }
  float DataErrorLo = DataEffFit->getErrorLo()<0 ? DataEffFit->getErrorLo() : (-1)*DataEffFit->getError();
  float DataErrorHi = DataEffFit->getErrorHi()>0 ? DataEffFit->getErrorHi() : DataEffFit->getError();
  float BinomialError = TMath::Sqrt(SGNtruePass/SGNtrue*(1-SGNtruePass/SGNtrue)/SGNtrue);
 
  Double_t* truthMC = new Double_t[6];
  Double_t* tnpMC   = new Double_t[6];
  Double_t* tnpData = new Double_t[6];

  truthMC[0] = binCenter_;
  truthMC[1] = binWidth_;
  truthMC[2] = binWidth_;
  truthMC[3] = SGNtruePass/SGNtrue;
  truthMC[4] = BinomialError;
  truthMC[5] = BinomialError;
  if(makeSoupFit_){
    tnpMC[0] = binCenter_;
    tnpMC[1] = binWidth_;
    tnpMC[2] = binWidth_;
    tnpMC[3] = McEffFit->getVal();
    tnpMC[4] = (-1)*McErrorLo;
    tnpMC[5] = McErrorHi;
  }
  tnpData[0] = binCenter_;
  tnpData[1] = binWidth_;
  tnpData[2] = binWidth_;
  tnpData[3] = DataEffFit->getVal();
  tnpData[4] = (-1)*DataErrorLo;
  tnpData[5] = DataErrorHi;

  out.push_back(truthMC);
  out.push_back(tnpData);
  if(makeSoupFit_) out.push_back(tnpMC);

  test->Close();

  //delete c; delete c2;

  if(verbose_) cout << "returning from bin " << bin_ << endl;
  return out;

}