/*!
Print information about private variables {plots,resolution,minmax}
*/
int Nodes_method::showinfo(ostream & os)
{
   sysprop->showinfo(os);
    os << endl << endl;
    os << "                               Wavefunction  "
       << endl << endl;
    wfdata->showinfo(os);
  os<<"#############Nodes_method#################\n";
  if (doublemove)
    os <<"Doing doublemoves with"<<endl;
  os<<"Plots= "<<plots(0);
  for(int i=1;i<plots.GetSize();i++)
    os<<", "<<plots(i);
  os<<endl;

  if (doublemove){
    os << "Translation vector(s): "<<endl;
    for(int i=0;i<dxyz.GetDim(0);i++)    
      os<<"( "<<dxyz(i,0)<<" , "<<dxyz(i,1)<<" , "<<dxyz(i,2)<<" )"<<endl;
    }
  

  os<<"resolution "<<resolution<<endl;
  os<<"xmin="<<minmax(0)<<" xmax="<<minmax(1)<<endl;
  os<<"ymin="<<minmax(2)<<" ymax="<<minmax(3)<<endl;
  os<<"zmin="<<minmax(4)<<" zmax="<<minmax(5)<<endl;
  os<<"done"<<endl;
  return 1;
}
Example #2
0
void RendererImplementationPlot::onAddContent(AbstractVisualizedData * content, unsigned int /*subViewIndex*/)
{
    assert(dynamic_cast<Context2DData *>(content));
    auto contextData = static_cast<Context2DData *>(content);

    auto items = vtkSmartPointer<vtkPlotCollection>::New();

    vtkCollectionSimpleIterator it;
    contextData->plots()->InitTraversal(it);
    while (auto item = contextData->plots()->GetNextPlot(it))
    {
        items->AddItem(item);
        m_chart->AddPlot(item);
    }

    assert(!m_plots.contains(contextData));
    m_plots.insert(contextData, items);


    addConnectionForContent(content,
        connect(contextData, &Context2DData::plotCollectionChanged,
        [this, contextData] () { fetchContextItems(contextData); }));

    addConnectionForContent(content,
        connect(contextData, &Context2DData::visibilityChanged,
        [this, contextData] (bool) { dataVisibilityChanged(contextData); }));

    dataVisibilityChanged(contextData);
}
Example #3
0
void testRunKsolve()
{
	double simDt = 0.1;
	// double plotDt = 0.1;
	Shell* s = reinterpret_cast< Shell* >( Id().eref().data() );
	Id kin = makeReacTest();
	Id ksolve = s->doCreate( "Ksolve", kin, "ksolve", 1 );
	Id stoich = s->doCreate( "Stoich", ksolve, "stoich", 1 );
	Field< Id >::set( stoich, "compartment", kin );
	Field< Id >::set( stoich, "ksolve", ksolve );
	Field< string >::set( stoich, "path", "/kinetics/##" );
	s->doUseClock( "/kinetics/ksolve", "process", 4 ); 
	s->doSetClock( 4, simDt );

	s->doReinit();
	s->doStart( 20.0 );
	Id plots( "/kinetics/plots" );
	for ( unsigned int i = 0; i < 7; ++i ) {
		stringstream ss;
		ss << "plot." << i;
		SetGet2< string, string >::set( ObjId( plots, i ), "xplot", 
						"tsr2.plot", ss.str() );
	}
	s->doDelete( kin );
	cout << "." << flush;
}
/**
 * Get a vector of all available plots.
 *
 * @return Vector of plot names as strings.
 */
const std::vector<std::string> Topics::getPlots() {
  std::vector<std::string> plots(4);
  plots[0] = "Acceleration";
  plots[1] = "Position + Velocity";
  plots[2] = "Position + Velocity + Movement";
  plots[3] = "Position Error";
  return plots;
}
int GraphView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = CommonView::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 6)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 6;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< GraphWidget::Orientation*>(_v) = orientation(); break;
        case 1: *reinterpret_cast< GraphWidget::Mode*>(_v) = mode(); break;
        case 2: *reinterpret_cast< int*>(_v) = timeLinesCount(); break;
        case 3: *reinterpret_cast< int*>(_v) = valueLinesCount(); break;
        case 4: *reinterpret_cast< QColor*>(_v) = cursorColor(); break;
        case 5: *reinterpret_cast< QColor*>(_v) = linesColor(); break;
        case 6: *reinterpret_cast< QColor*>(_v) = textColor(); break;
        case 7: *reinterpret_cast< QColor*>(_v) = backColor(); break;
        case 8: *reinterpret_cast< QColor*>(_v) = selectionColor(); break;
        case 9: *reinterpret_cast< Plots*>(_v) = plots(); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setOrientation(*reinterpret_cast< GraphWidget::Orientation*>(_v)); break;
        case 1: setMode(*reinterpret_cast< GraphWidget::Mode*>(_v)); break;
        case 2: setTimeLinesCount(*reinterpret_cast< int*>(_v)); break;
        case 3: setValueLinesCount(*reinterpret_cast< int*>(_v)); break;
        case 4: setCursorColor(*reinterpret_cast< QColor*>(_v)); break;
        case 5: setLinesColor(*reinterpret_cast< QColor*>(_v)); break;
        case 6: setTextColor(*reinterpret_cast< QColor*>(_v)); break;
        case 7: setBackColor(*reinterpret_cast< QColor*>(_v)); break;
        case 8: setSelectionColor(*reinterpret_cast< QColor*>(_v)); break;
        case 9: setPlots(*reinterpret_cast< Plots*>(_v)); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 10;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #6
0
void testSetupReac()
{
	Shell* s = reinterpret_cast< Shell* >( Id().eref().data() );
	Id kin = makeReacTest();
	s->doReinit();
	s->doStart( 20.0 );
	Id plots( "/kinetics/plots" );
	/*
	for ( unsigned int i = 0; i < 7; ++i ) {
		stringstream ss;
		ss << "plot." << i;
		SetGet2< string, string >::set( ObjId( plots, i ), "xplot", 
						"tsr.plot", ss.str() );
	}
	*/
	s->doDelete( kin );
	cout << "." << flush;
}
Example #7
0
void testRunGsolve()
{
	double simDt = 0.1;
	// double plotDt = 0.1;
	Shell* s = reinterpret_cast< Shell* >( Id().eref().data() );
	Id kin = makeReacTest();
	double volume = 1e-21;
	Field< double >::set( kin, "volume", volume );
	Field< double >::set( ObjId( "/kinetics/A" ), "concInit", 2 );
	Field< double >::set( ObjId( "/kinetics/e1Pool" ), "concInit", 1 );
	Field< double >::set( ObjId( "/kinetics/e2Pool" ), "concInit", 1 );
	Id e1( "/kinetics/e1Pool/e1" );
	Field< double >::set( e1, "Km", 5 );
	Field< double >::set( e1, "kcat", 1 );
	vector< double > stim( 100, 0.0 );
	for ( unsigned int i = 0; i< 100; ++i ) {
		stim[i] = volume * NA * (1.0 + sin( i * 2.0 * PI / 100.0 ) );
	}
	Field< vector< double > >::set( ObjId( "/kinetics/tab" ), "vector", stim );


	Id gsolve = s->doCreate( "Gsolve", kin, "gsolve", 1 );
	Id stoich = s->doCreate( "Stoich", gsolve, "stoich", 1 );
	Field< Id >::set( stoich, "compartment", kin );
	Field< Id >::set( stoich, "ksolve", gsolve );
	
	Field< string >::set( stoich, "path", "/kinetics/##" );
	s->doUseClock( "/kinetics/gsolve", "process", 4 ); 
	s->doSetClock( 4, simDt );

	s->doReinit();
	s->doStart( 20.0 );
	Id plots( "/kinetics/plots" );
	for ( unsigned int i = 0; i < 7; ++i ) {
		stringstream ss;
		ss << "plot." << i;
		SetGet2< string, string >::set( ObjId( plots, i ), "xplot", 
						"tsr3.plot", ss.str() );
	}
	s->doDelete( kin );
	cout << "." << flush;
}
Example #8
0
void GA::evolve()
{
  // create initial population (generation 0)
  std::cout << "-- Generation 0 of " <<  m_generation_max << " ..." << std::endl;
  m_generation = 0;
  m_population.resize(m_population_size);
  m_last_population.resize(m_population_size);

  for (unsigned int i=0; i<m_population_size; i++){
    m_population[i] = new Individual();

    for (auto &var : m_variables) {
      m_population[i]->add_cut(get_random_cut(var));
    }
  }
  evaluate_fitness();
  show_best();

  // loop step until condition is satisfied
  while (check_end_condition()) {
    m_generation++;
    std::cout << "-- Generation " << m_generation << " of " <<  m_generation_max << " ..." << std::endl;
    step();
    show_best();
  }

  std::cout << std::endl;

  long total_calc = 1;
  for (auto &var : m_variables) {
    total_calc *= var.bins;
  }
  std::cout << "-- Number of calculations = " << hist_z->GetNbins() << " of " << total_calc << std::endl;

  output.close();

  // make plots
  std::cout << "-- Doing some plots..." << std::endl;
  plots();


}
Example #9
0
int main(int argc, char** argv) {
  ArgParser a(argc,argv);

  a.addArgument("InputFile",ArgParser::required,"Name of the Input File");
  a.addArgument("OutputFolder",ArgParser::required,"Name of the folder to which to save the output");
  a.addArgument("OutputTag",ArgParser::required,"Tag to append to output plots");

  a.addLongOption("isSMS",ArgParser::noArg,"file is an SMS file (no data)");
  
  std::string ret;
  if(a.process(ret) !=0){
    std::cout << "Invalid Options:  " << ret << std::endl;
    a.printOptions(argv[0]);
    return 0;
  }

  Plotter plots(a.getArgument("InputFile"),a.getArgument("OutputFolder"),a.getArgument("OutputTag"));
  if(a.longFlagPres("isSMS")) plots.setIsSMS(true);

  plots.Run();

};
Example #10
0
int main(int argc, char* argv[]) {

  TH1::SetDefaultSumw2();

  ProgramOptions options(argc, argv);

  double lumi = options.lumi;

  // input datasets
  Datasets datasets(options.iDir);
  datasets.readFile(options.datasetFile);
 
  std::string oDir_Plot = options.oDir+std::string("/ZBackground");

  boost::filesystem::path opath(oDir_Plot);
  if (!exists(opath)) {
    std::cout << "Creating output directory : " << oDir_Plot << std::endl;
    boost::filesystem::create_directory(opath);
  }
 
  if (options.doMCFMWeights) std::cout << "Going to apply MCFM weights" << std::endl;

  // output file
  TFile* ofile = TFile::Open( (options.oDir+std::string("/ZBackground.root")).c_str(), "RECREATE");

  // cuts
  Cuts cuts;
  unsigned nCutsZMuMu = cuts.nCutsZMuMu();

  TCut puWeight("puWeight");
  TCut trigCorr( "(trigCorrWeight>0) ? trigCorrWeight : 1." );
  TCut METNoMuon130("metNoMuon>130.");	// add here later for VBF efficiency when MET>35, MET>70 (QCD estimation)
  TCut METNo2Muon130("metNo2Muon>130.");
  TCut cutLoDPhi = cuts.cut("dPhiJJ");

  // For lepton weights
  TCut lVetoWeight   = cuts.elVetoWeight(options.leptCorr) * cuts.muVetoWeight(options.leptCorr);
  TCut muTightWeight = cuts.muTightWeight(options.leptCorr);

  // histograms
  double dphiEdges[4] = { 0., 1.0, 2.6, TMath::Pi() };
  //double metEdges[13] = { 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120. };

  // signal MET>130
  TH1D* hZ_DY_C_DPhi   = new TH1D("hZ_DY_C_DPhi",   "", 3, dphiEdges);  // Z+jets MC ctrl region
  TH1D* hZ_BG_C_DPhi   = new TH1D("hZ_BG_C_DPhi",   "", 3, dphiEdges);  // background MC ctrl region
  TH1D* hZ_Data_C_DPhi = new TH1D("hZ_Data_C_DPhi", "", 3, dphiEdges);  // Data ctrl region

  TH1D* hZ_QCD_EffVBFS_D = new TH1D("hZ_QCD_EffVBFS_D", "", 1, 0., 1.);
  TH1D* hZ_QCD_EffVBFS_N = new TH1D("hZ_QCD_EffVBFS_N", "", 1, 0., 1.);
  TH1D* hZ_EWK_EffVBFS_D = new TH1D("hZ_EWK_EffVBFS_D", "", 1, 0., 1.);
  TH1D* hZ_EWK_EffVBFS_N = new TH1D("hZ_EWK_EffVBFS_N", "", 1, 0., 1.);
 
  // combine eps_VBF_C * eps_mumu which remove canceling term (denominator is Z->uu gen level cut)
  TH1D* hZ_QCD_EffVBFC_D = new TH1D("hZ_QCD_EffVBFC_D", "", 1, 0., 1.);
  TH1D* hZ_QCD_EffVBFC_N = new TH1D("hZ_QCD_EffVBFC_N", "", 1, 0., 1.);
  TH1D* hZ_EWK_EffVBFC_D = new TH1D("hZ_EWK_EffVBFC_D", "", 1, 0., 1.);
  TH1D* hZ_EWK_EffVBFC_N = new TH1D("hZ_EWK_EffVBFC_N", "", 1, 0., 1.);

  // cutflow histograms
  TH1D* hZ_CutFlow_Data       = new TH1D("hZ_CutFlow_Data",       "", nCutsZMuMu, 0., nCutsZMuMu);
  TH1D* hZ_CutFlow_DY         = new TH1D("hZ_CutFlow_DY",         "", nCutsZMuMu, 0., nCutsZMuMu);
  TH1D* hZ_CutFlow_SingleTSum = new TH1D("hZ_CutFlow_SingleTSum", "", nCutsZMuMu, 0., nCutsZMuMu);
  TH1D* hZ_CutFlow_Diboson    = new TH1D("hZ_CutFlow_Diboson",    "", nCutsZMuMu, 0., nCutsZMuMu);

  // Hists to calculate DY normalisation factor
  TH1D* hZ_DY_NoVBFNoWeight = new TH1D("hZ_DY_NoVBFNoWeight","", 1, 0., 1.); // DY MC yield after dimuon and dijet selection without y* and mjj weighting
  TH1D* hZ_DY_NoVBFWeight   = new TH1D("hZ_DY_NoVBFWeight",  "", 1, 0., 1.); // DY MC yield after dimuon and dijet selection with y* and mjj weighting

  // loop over MC datasets
  for (unsigned i=0; i<datasets.size(); ++i) {

    Dataset dataset = datasets.getDataset(i);
    
    TCut cutD = cuts.cutDataset(dataset.name);
    TCut yStarWeight("");
    TCut mjjWeight("");

    // check if it's DYJets
    bool isDY = false;
    if (dataset.name.compare(0,2,"DY")==0) {
      isDY = true;
      std::cout << "Analysing DY->ll MC : " << dataset.name << std::endl; 
      // check if it's QCD
      if ( !(dataset.name.length()>11 && dataset.name.compare(11,14,"EWK")==0) ) {
    	if (options.doMCFMWeights) {
    	  yStarWeight = TCut("(0.849667 + (0.149687*abs(log((sqrt(zgenmass*zgenmass + zgenpt*zgenpt*cosh(zgeneta)*cosh(zgeneta)) + zgenpt*sinh(zgeneta))/sqrt(zgenmass*zgenmass + zgenpt*zgenpt)) - 0.5*(genJet1Eta + genJet2Eta))))");
    	  mjjWeight   = TCut("0.392568 + (0.120734*log(genVBFM)) - (0.000255622*genVBFM)");
    	}
    	std::cout << "Analysing QCD DY MC " << std::endl;
      }
    }
    else if (dataset.isData) {
      std::cout << "Analysing Data      : " << dataset.name << std::endl;
    }
    else {
      std::cout << "Analysing BG MC     : " << dataset.name << std::endl;
    }

    TCut otherWeight = puWeight * yStarWeight * mjjWeight;

    // get file & tree
    TFile* file = datasets.getTFile(dataset.name);
    TTree* tree = (TTree*) file->Get("invHiggsInfo/InvHiggsInfo");

    // set up cuts
    TCut cutZMuMu_C           = otherWeight * trigCorr * (cutD + cuts.zMuMuVBF() + METNo2Muon130);
    
    TCut cutEfficiencyMuMu_D  = otherWeight * (cutD + cuts.zMuMuGen());
    //TCut cutEfficiencyMuMu_N  = otherWeight * (cutD + cuts.zMuMuGen() + cuts.zMuMuReco());
 
    TCut cutEfficiencyVBFS_D  = otherWeight * (cutD + cuts.zMuMuGenMass());
    TCut cutEfficiencyVBFS_N  = otherWeight * trigCorr * (cutD + cuts.HLTandMETFilters() + cuts.zMuMuGenMass() + cuts.vbf() + METNoMuon130 + cutLoDPhi);
    
    //TCut cutEfficiencyVBFC_D  = otherWeight * (cutD + cuts.zMuMuGen() + cuts.zMuMuReco());
    TCut cutEfficiencyVBFC_N  = otherWeight * trigCorr * (cutD + cuts.HLTandMETFilters() + cuts.zMuMuGen() + cuts.zMuMuReco() + cuts.vbf() + METNo2Muon130 + cutLoDPhi);

    // re-weighting
    TCut cutDYNoVBFNoWeight = puWeight * trigCorr * (cutD  + cuts.zMuMuGen() + cuts.zMuMuReco() + cuts.cutZMuMu("dijet"));
    TCut cutDYNoVBFWeight   = otherWeight * trigCorr * (cutD  + cuts.zMuMuGen() + cuts.zMuMuReco() + cuts.cutZMuMu("dijet"));

    if(!(dataset.isData)) {
	cutZMuMu_C *= muTightWeight;
	cutEfficiencyVBFC_N *= muTightWeight;
	cutDYNoVBFNoWeight  *= muTightWeight;
	cutDYNoVBFWeight    *= muTightWeight;
    }

    // fill tmp histograms for BG estimation
    TH1D* hZ_C_DPhi  = new TH1D("hZ_C_DPhi", "", 3, dphiEdges);  // this is for the actual BG estimation
    // fill tmp histograms for efficiency calculation
    TH1D* hZ_EffVBFS_D  = new TH1D("hZ_EffVBFS_D", "", 1, 0., 1.);
    TH1D* hZ_EffVBFS_N  = new TH1D("hZ_EffVBFS_N", "", 1, 0., 1.);
    TH1D* hZ_EffVBFC_D  = new TH1D("hZ_EffVBFC_D", "", 1, 0., 1.);
    TH1D* hZ_EffVBFC_N  = new TH1D("hZ_EffVBFC_N", "", 1, 0., 1.);

    TH1D* hZ_DY_NoWeight = new TH1D("hZ_DY_NoWeight", "", 1, 0, 1);
    TH1D* hZ_DY_Weight   = new TH1D("hZ_DY_Weight",   "", 1, 0, 1);
    

    if (isDY) {
      tree->Draw("vbfDPhi>>hZ_C_DPhi", cutZMuMu_C);
      tree->Draw("0.5>>hZ_EffVBFS_D",  cutEfficiencyVBFS_D);
      tree->Draw("0.5>>hZ_EffVBFS_N",  cutEfficiencyVBFS_N);
      tree->Draw("0.5>>hZ_EffVBFC_D",  cutEfficiencyMuMu_D);
      tree->Draw("0.5>>hZ_EffVBFC_N",  cutEfficiencyVBFC_N);

      tree->Draw("0.5>>hZ_DY_NoWeight", cutDYNoVBFNoWeight);
      tree->Draw("0.5>>hZ_DY_Weight",   cutDYNoVBFWeight);

//       tree->Draw("abs((log((sqrt(zgenmass*zgenmass + zgenpt*zgenpt*cosh(zgeneta)*cosh(zgeneta)) + zgenpt*sinh(zgeneta))/(sqrt(zgenmass*zgenmass + zgenpt*zgenpt)))) - 0.5*(genJet1Eta + genJet2Eta))>>hYStar", cutDYNoVBFNoWeight);
//       tree->Draw("abs((log((sqrt(zgenmass*zgenmass + zgenpt*zgenpt*cosh(zgeneta)*cosh(zgeneta)) + zgenpt*sinh(zgeneta))/(sqrt(zgenmass*zgenmass + zgenpt*zgenpt)))) - 0.5*(genJet1Eta + genJet2Eta))>>hYStarC", cutZMuMu_C);
    }
    else {
      tree->Draw("vbfDPhi>>hZ_C_DPhi", cutZMuMu_C);
      //tree->Draw("met:vbfDPhi>>hZ_C_METDPhi",  cutZMuMu_MET0_C);
    }

    // weight  to lumi
    double weight = (dataset.isData) ? 1. : lumi * dataset.sigma / dataset.nEvents;
    hZ_C_DPhi->Scale(weight);
    hZ_EffVBFS_D->Scale(weight);
    hZ_EffVBFS_N->Scale(weight);
    hZ_EffVBFC_D->Scale(weight);
    hZ_EffVBFC_N->Scale(weight);

    hZ_DY_NoWeight->Scale(weight);
    hZ_DY_Weight->Scale(weight);
    
    // add to output histograms
    if (dataset.isData) {
      hZ_Data_C_DPhi->Add(hZ_C_DPhi);
    }
    else if (isDY) {
      hZ_DY_C_DPhi->Add(hZ_C_DPhi);

      hZ_DY_NoVBFNoWeight->Add(hZ_DY_NoWeight);
      hZ_DY_NoVBFWeight->Add(hZ_DY_Weight);

      if(dataset.name == "DYJetsToLL_NoTrig" || dataset.name == "DYJetsToLL_PtZ-100_NoTrig") {
        hZ_QCD_EffVBFS_D->Add(hZ_EffVBFS_D);
        hZ_QCD_EffVBFS_N->Add(hZ_EffVBFS_N);
        hZ_QCD_EffVBFC_D->Add(hZ_EffVBFC_D);
        hZ_QCD_EffVBFC_N->Add(hZ_EffVBFC_N);
      }
      if(dataset.name == "DYJetsToLL_EWK_NoTrig") {
        hZ_EWK_EffVBFS_D->Add(hZ_EffVBFS_D);
        hZ_EWK_EffVBFS_N->Add(hZ_EffVBFS_N);
        hZ_EWK_EffVBFC_D->Add(hZ_EffVBFC_D);
        hZ_EWK_EffVBFC_N->Add(hZ_EffVBFC_N);
      }
    }
    else {
      hZ_BG_C_DPhi->Add(hZ_C_DPhi);
    }

    std::cout << "  N ctrl (dphi<1.0) : " << hZ_C_DPhi->GetBinContent(1) << " +/- " << hZ_C_DPhi->GetBinError(1) << std::endl;  
    

    delete hZ_C_DPhi;
    delete hZ_EffVBFS_D;
    delete hZ_EffVBFS_N;
    delete hZ_EffVBFC_D;
    delete hZ_EffVBFC_N;

    delete hZ_DY_NoWeight;
    delete hZ_DY_Weight;

    ofile->cd();

    // cut flow histograms
    std::string hname = std::string("hZ_CutFlow_")+dataset.name;
    TH1D* hZ_CutFlow = new TH1D(hname.c_str(), "", nCutsZMuMu, 0., nCutsZMuMu);

    for (unsigned c=0; c<nCutsZMuMu; ++c) {

      TCut cut;

      if(c == nCutsZMuMu-1) cut = otherWeight * trigCorr * (cutD + cuts.cutflowZMuMu(c));
      else cut = otherWeight * (cutD + cuts.cutflowZMuMu(c));

      if(!(dataset.isData)) cut *= muTightWeight;

      TH1D* h = new TH1D("h","", 1, 0., 1.);
      tree->Draw("0.5>>h", cut);

      hZ_CutFlow->SetBinContent(c+1, h->GetBinContent(1));
      hZ_CutFlow->SetBinError(c+1, h->GetBinError(1));

      delete h;
    }

    hZ_CutFlow->Scale(weight);

    if (dataset.isData) {
      hZ_CutFlow_Data->Add(hZ_CutFlow);
    }
    if (dataset.name.compare(0,2,"DY")==0) {
      hZ_CutFlow_DY->Add(hZ_CutFlow);
    }
    if (dataset.name.compare(0,7,"SingleT")==0) {
      hZ_CutFlow_SingleTSum->Add(hZ_CutFlow);
    }
    if (dataset.name.compare(0,2,"WW")==0 ||
  	dataset.name.compare(0,2,"WZ")==0 ||
  	dataset.name.compare(0,2,"ZZ")==0 || 
	dataset.name.compare(0,2,"WG")==0) {
      hZ_CutFlow_Diboson->Add(hZ_CutFlow);
    }

    hZ_CutFlow->Write("",TObject::kOverwrite);

    delete hZ_CutFlow;


    // Z control plots
    TCut cutPlots = otherWeight * trigCorr * (cutD + cuts.zMuMuVBFLoose());

    if(!(dataset.isData)) cutPlots *= muTightWeight;
 
    TFile* ofile_Plot = TFile::Open( (oDir_Plot+std::string("/")+dataset.name+std::string(".root")).c_str(), "RECREATE");

    TH1D* ZCtrlZMass    = new TH1D("ZCtrlZMass",    "", 30, 60., 120.);
    TH1D* ZCtrlZpT      = new TH1D("ZCtrlZpT",      "", 50, 0.,  1000.);
    TH1D* ZCtrlJet1pT   = new TH1D("ZCtrlJet1pT",   "", 50, 0.,  1000.);
    TH1D* ZCtrlJet1Eta  = new TH1D("ZCtrlJet1Eta",  "", 50, -5., 5.);
    TH1D* ZCtrlJet2pT   = new TH1D("ZCtrlJet2pT",   "", 50, 0.,  1000.);
    TH1D* ZCtrlJet2Eta  = new TH1D("ZCtrlJet2Eta",  "", 50, -5., 5.);
    TH1D* ZCtrlCenJetpT = new TH1D("ZCtrlCenJetpT", "", 50, 0.,  400.);
    TH1D* ZCtrlDEtajj   = new TH1D("ZCtrlDEtajj",   "", 50, 0.,  8.);
    TH1D* ZCtrlMjj      = new TH1D("ZCtrlMjj",      "", 30, 0.,  3000.);
    TH1D* ZCtrlMET      = new TH1D("ZCtrlMET",      "", 25, 10.,  510.);
    TH1D* ZCtrlDPhijj   = new TH1D("ZCtrlDPhijj",   "", 50, 0.,  TMath::Pi());

    TH1D* ZCtrlYStar    = new TH1D("ZCtrlYStar",    "", 50, 0., 5.);
    TH1D* ZCtrlYStarWt  = new TH1D("ZCtrlYStarWt",  "", 50, 0., 2.);
    TH1D* ZCtrlMjjWt    = new TH1D("ZCtrlMjjWt",    "", 50, 0., 2.);
    TH1D* ZCtrlYStarMjjWt    = new TH1D("ZCtrlYStarMjjWt",    "", 50, -1., 5.);    

    tree->Draw("zMass>>ZCtrlZMass"	    , cutPlots);
    tree->Draw("zPt>>ZCtrlZpT"		    , cutPlots);
    tree->Draw("jet1Pt>>ZCtrlJet1pT"	    , cutPlots);
    tree->Draw("jet1Eta>>ZCtrlJet1Eta"	    , cutPlots);
    tree->Draw("jet2Pt>>ZCtrlJet2pT"	    , cutPlots);
    tree->Draw("jet2Eta>>ZCtrlJet2Eta"	    , cutPlots);
    tree->Draw("cenJetEt>>ZCtrlCenJetpT"    , cutPlots);
    tree->Draw("vbfDEta>>ZCtrlDEtajj"	    , cutPlots);
    tree->Draw("vbfM>>ZCtrlMjj"		    , cutPlots);
    tree->Draw("metNo2Muon>>ZCtrlMET"	    , cutPlots);
    tree->Draw("vbfDPhi>>ZCtrlDPhijj"	    , cutPlots);

    if (options.doMCFMWeights) {

    tree->Draw("abs(log((sqrt(zgenmass*zgenmass + zgenpt*zgenpt*cosh(zgeneta)*cosh(zgeneta)) + zgenpt*sinh(zgeneta))/sqrt(zgenmass*zgenmass + zgenpt*zgenpt)) - 0.5*(genJet1Eta + genJet2Eta))>>ZCtrlYStar"	  , cutPlots);
    tree->Draw("(0.849667 + (0.149687*abs(log((sqrt(zgenmass*zgenmass + zgenpt*zgenpt*cosh(zgeneta)*cosh(zgeneta)) + zgenpt*sinh(zgeneta))/sqrt(zgenmass*zgenmass + zgenpt*zgenpt)) - 0.5*(genJet1Eta + genJet2Eta))))>>ZCtrlYStarWt", cutPlots);
    tree->Draw("(0.392568 + (0.120734*log(genVBFM)) - (0.000255622*genVBFM))>>ZCtrlMjjWt", cutPlots);
    tree->Draw("(0.849667 + (0.149687*abs(log((sqrt(zgenmass*zgenmass + zgenpt*zgenpt*cosh(zgeneta)*cosh(zgeneta)) + zgenpt*sinh(zgeneta))/sqrt(zgenmass*zgenmass + zgenpt*zgenpt)) - 0.5*(genJet1Eta + genJet2Eta))))*(0.392568 + (0.120734*log(genVBFM)) - (0.000255622*genVBFM))>>ZCtrlYStarMjjWt", cutPlots);

    }

    if (!dataset.isData) {
      ZCtrlZMass->Scale(weight);
      ZCtrlZpT->Scale(weight);
      ZCtrlJet1pT->Scale(weight);
      ZCtrlJet1Eta->Scale(weight);
      ZCtrlJet2pT->Scale(weight);
      ZCtrlJet2Eta->Scale(weight);
      ZCtrlCenJetpT->Scale(weight);
      ZCtrlDEtajj->Scale(weight);
      ZCtrlMjj->Scale(weight);
      ZCtrlMET->Scale(weight);
      ZCtrlDPhijj->Scale(weight);
      ZCtrlYStar->Scale(weight);
      ZCtrlYStarWt->Scale(weight);
      ZCtrlMjjWt->Scale(weight);
      ZCtrlYStarMjjWt->Scale(weight);
    }

    ofile_Plot->cd();
    ZCtrlZMass->Write("",TObject::kOverwrite);
    ZCtrlZpT->Write("",TObject::kOverwrite);
    ZCtrlJet1pT->Write("",TObject::kOverwrite);
    ZCtrlJet1Eta->Write("",TObject::kOverwrite);
    ZCtrlJet2pT->Write("",TObject::kOverwrite);
    ZCtrlJet2Eta->Write("",TObject::kOverwrite);
    ZCtrlCenJetpT->Write("",TObject::kOverwrite);
    ZCtrlDEtajj->Write("",TObject::kOverwrite);
    ZCtrlMjj->Write("",TObject::kOverwrite);
    ZCtrlMET->Write("",TObject::kOverwrite);
    ZCtrlDPhijj->Write("",TObject::kOverwrite);
    ZCtrlYStar->Write("",TObject::kOverwrite);
    ZCtrlYStarWt->Write("",TObject::kOverwrite);
    ZCtrlMjjWt->Write("",TObject::kOverwrite);
    ZCtrlYStarMjjWt->Write("",TObject::kOverwrite);

    ofile_Plot->Close();

    // clean up
    delete tree;
    file->Close();
   
  }

  // re-weighting : will be 1 if re-weighting is off
  TH1D* hZ_DYNorm = new TH1D("hZ_DYNorm", "", 1, 0, 1); 
  hZ_DYNorm->Add(hZ_DY_NoVBFNoWeight);
  hZ_DYNorm->Divide(hZ_DY_NoVBFWeight);
  
  double dyNorm = hZ_DYNorm->GetBinContent(1);

  // numbers - calculate these from MC in this program later!
  double ratioBF = constants::ratioZToNuNuZToLL;

  // efficiencies (these will all have syst uncertainty only)
  TH1D* hZ_QCD_EffVBFS      = new TH1D("hZ_QCD_EffVBFS",  "", 1, 0., 1.);
  TH1D* hZ_QCD_EffVBFC      = new TH1D("hZ_QCD_EffVBFC",  "", 1, 0., 1.);
  TH1D* hZ_EWK_EffVBFS      = new TH1D("hZ_EWK_EffVBFS",  "", 1, 0., 1.);
  TH1D* hZ_EWK_EffVBFC      = new TH1D("hZ_EWK_EffVBFC",  "", 1, 0., 1.);
 
  TH1D* hZ_DY_EffVBFS       = new TH1D("hZ_DY_EffVBFS",  "", 1, 0., 1.);  	// epsilon_s_vbf
  TH1D* hZ_DY_EffVBFC       = new TH1D("hZ_DY_EffVBFC",  "", 1, 0., 1.);        // epsilon_c_vbf
  TH1D* hZ_DY_TotalEff      = new TH1D("hZ_DY_TotalEff", "", 1, 0., 1.); 

  // for stat only calculation
  TH1D* hZ_Eff_S_DPhi       = new TH1D("hZ_Eff_S_DPhi",       "", 3, dphiEdges);
  TH1D* hZ_Est_C_DPhi       = new TH1D("hZ_Est_C_DPhi",       "", 3, dphiEdges);
  TH1D* hZ_Est_S_DPhi       = new TH1D("hZ_Est_S_DPhi",       "", 3, dphiEdges);

  // for syst only calculation
  TH1D* hZ_BG_C_DPhi_Syst   = new TH1D("hZ_BG_C_DPhi_Syst",   "", 3, dphiEdges);
  TH1D* hZ_Data_C_DPhi_Syst = new TH1D("hZ_Data_C_DPhi_Syst", "", 3, dphiEdges);
  TH1D* hZ_Eff_S_DPhi_Syst  = new TH1D("hZ_Eff_S_DPhi_Syst",  "", 3, dphiEdges);
  TH1D* hZ_Est_C_DPhi_Syst  = new TH1D("hZ_Est_C_DPhi_Syst",  "", 3, dphiEdges);
  TH1D* hZ_Est_S_DPhi_Syst  = new TH1D("hZ_Est_S_DPhi_Syst",  "", 3, dphiEdges);

  // calculate efficiencies for QCD and EWK processes
  hZ_QCD_EffVBFS->Add(hZ_QCD_EffVBFS_N);
  hZ_QCD_EffVBFS->Divide(hZ_QCD_EffVBFS_D);
  hZ_EWK_EffVBFS->Add(hZ_EWK_EffVBFS_N);
  hZ_EWK_EffVBFS->Divide(hZ_EWK_EffVBFS_D);

  hZ_QCD_EffVBFC->Add(hZ_QCD_EffVBFC_N);
  hZ_QCD_EffVBFC->Divide(hZ_QCD_EffVBFC_D);
  hZ_EWK_EffVBFC->Add(hZ_EWK_EffVBFC_N);
  hZ_EWK_EffVBFC->Divide(hZ_EWK_EffVBFC_D); 

  // combine QCD Zll and EWK Zll with correct weights
  hZ_DY_EffVBFS->Add(hZ_QCD_EffVBFS,constants::sigma_Zvv_QCD);
  hZ_DY_EffVBFS->Add(hZ_EWK_EffVBFS,constants::sigma_Zvv_EWK);
  hZ_DY_EffVBFC->Add(hZ_QCD_EffVBFC,constants::sigma_Zuu_QCD);
  hZ_DY_EffVBFC->Add(hZ_EWK_EffVBFC,constants::sigma_Zuu_EWK);

  hZ_DY_TotalEff->Add(hZ_DY_EffVBFS);
  hZ_DY_TotalEff->Divide(hZ_DY_EffVBFC);

  for(int ibin = 1; ibin <= hZ_Eff_S_DPhi->GetNbinsX(); ++ibin) {
    hZ_Eff_S_DPhi->SetBinContent(ibin,hZ_DY_TotalEff->GetBinContent(1));
    hZ_Eff_S_DPhi->SetBinError(ibin,0.);
    hZ_Eff_S_DPhi_Syst->SetBinContent(ibin,hZ_DY_TotalEff->GetBinContent(1));
    hZ_Eff_S_DPhi_Syst->SetBinError(ibin,hZ_DY_TotalEff->GetBinError(1));
  }

  // do stat only version
  hZ_BG_C_DPhi_Syst->Add(hZ_BG_C_DPhi, 1.);  // copy MC BG histogram for syst calculation
  for (int i=1; i<=hZ_BG_C_DPhi->GetNbinsX(); ++i) hZ_BG_C_DPhi->SetBinError(i,0.);  // set MC BG errors to zero for stat only
  hZ_Est_C_DPhi->Add(hZ_Data_C_DPhi, hZ_BG_C_DPhi, 1., -1.);
  hZ_Est_S_DPhi->Add(hZ_Est_C_DPhi);
  hZ_Est_S_DPhi->Multiply(hZ_Eff_S_DPhi);

  // do syst only version
  hZ_Data_C_DPhi_Syst->Add(hZ_Data_C_DPhi, 1.);
  for (int i=1; i<=hZ_Data_C_DPhi_Syst->GetNbinsX(); ++i) hZ_Data_C_DPhi_Syst->SetBinError(i,0.);

  hZ_Est_C_DPhi_Syst->Add(hZ_Data_C_DPhi_Syst, hZ_BG_C_DPhi, 1., -1.);
  hZ_Est_S_DPhi_Syst->Add(hZ_Est_C_DPhi_Syst);
  hZ_Est_S_DPhi_Syst->Multiply(hZ_Eff_S_DPhi_Syst);


  std::cout << std::endl;
  std::cout << "##################################### MET > 130 #####################################" << std::endl;
  std::cout << "dphi<1.0" << std::endl;
  std::cout << std::endl;
  std::cout << "  Numerator_s_vbf : " << hZ_QCD_EffVBFS_N->GetBinContent(1) << " +/- " << hZ_QCD_EffVBFS_N->GetBinError(1) << std::endl;
  std::cout << "  Deno_s_vbf      : " << hZ_QCD_EffVBFS_D->GetBinContent(1) << " +/- " << hZ_QCD_EffVBFS_D->GetBinError(1) << std::endl;
  std::cout << "  eps_s_vbf (QCD) : " << hZ_QCD_EffVBFS->GetBinContent(1) << " +/- " << hZ_QCD_EffVBFS->GetBinError(1) << std::endl;
  std::cout << std::endl;
  std::cout << "  Numerator_s_vbf : " << hZ_EWK_EffVBFS_N->GetBinContent(1) << " +/- " << hZ_EWK_EffVBFS_N->GetBinError(1) << std::endl;
  std::cout << "  Deno_s_vbf      : " << hZ_EWK_EffVBFS_D->GetBinContent(1) << " +/- " << hZ_EWK_EffVBFS_D->GetBinError(1) << std::endl;
  std::cout << "  eps_s_vbf (EWK) : " << hZ_EWK_EffVBFS->GetBinContent(1) << " +/- " << hZ_EWK_EffVBFS->GetBinError(1) << std::endl;
  std::cout << std::endl;
  std::cout << "  Numerator_c_vbf : " << hZ_QCD_EffVBFC_N->GetBinContent(1) << " +/- " << hZ_QCD_EffVBFC_N->GetBinError(1) << std::endl;
  std::cout << "  Deno_c_vbf      : " << hZ_QCD_EffVBFC_D->GetBinContent(1) << " +/- " << hZ_QCD_EffVBFC_D->GetBinError(1) << std::endl;
  std::cout << "  eps_c_vbf (QCD) : " << hZ_QCD_EffVBFC->GetBinContent(1) << " +/- " << hZ_QCD_EffVBFC->GetBinError(1) << std::endl;
  std::cout << std::endl;
  std::cout << "  Numerator_c_vbf : " << hZ_EWK_EffVBFC_N->GetBinContent(1) << " +/- " << hZ_EWK_EffVBFC_N->GetBinError(1) << std::endl;
  std::cout << "  Deno_c_vbf      : " << hZ_EWK_EffVBFC_D->GetBinContent(1) << " +/- " << hZ_EWK_EffVBFC_D->GetBinError(1) << std::endl;
  std::cout << "  eps_c_vbf (EWK) : " << hZ_EWK_EffVBFC->GetBinContent(1) << " +/- " << hZ_EWK_EffVBFC->GetBinError(1) << std::endl;
  std::cout << std::endl;
  std::cout << "  eps_s_vbf : " << hZ_DY_EffVBFS->GetBinContent(1) << " +/- " << hZ_DY_EffVBFS->GetBinError(1) << std::endl;
  std::cout << "  eps_c_vbf : " << hZ_DY_EffVBFC->GetBinContent(1) << " +/- " << hZ_DY_EffVBFC->GetBinError(1) << std::endl;
  std::cout << "  total eff : " << hZ_DY_TotalEff->GetBinContent(1) << " +/- " << hZ_DY_TotalEff->GetBinError(1) << std::endl;
  std::cout << std::endl;
  std::cout << "  DY+jets MC ctrl region : " << hZ_DY_C_DPhi->GetBinContent(1) << " +/- " << hZ_DY_C_DPhi->GetBinError(1) << std::endl;
  std::cout << "  Background ctrl region : " << hZ_BG_C_DPhi->GetBinContent(1) << " +/- " << hZ_BG_C_DPhi->GetBinError(1) << std::endl;
  std::cout << "  Data ctrl region       : " << hZ_Data_C_DPhi->GetBinContent(1) << " +/- " << hZ_Data_C_DPhi->GetBinError(1) << std::endl;
  std::cout << std::endl;
  std::cout << "  Z in ctrl region       : " << hZ_Est_C_DPhi->GetBinContent(1) << " +/- " << hZ_Est_C_DPhi->GetBinError(1) << " (stat.) + " << hZ_Est_C_DPhi_Syst->GetBinError(1) << " (syst)" << std::endl;
  std::cout << "  Z in sgnl region       : " << hZ_Est_S_DPhi->GetBinContent(1) << " +/- " << hZ_Est_S_DPhi->GetBinError(1) << " (stat.) + " << hZ_Est_S_DPhi_Syst->GetBinError(1) << " (syst)" << std::endl;
  std::cout << std::endl;
  //std::cout << "  N_DY^No VBF (no y* or mjj weight)  : " << hZ_DY_NoVBFNoWeight->GetBinContent(1) << " +/- " << hZ_DY_NoVBFNoWeight->GetBinError(1) << std::endl; 
  //std::cout << "  N_DY^No VBF(with y* and mjj weight): " << hZ_DY_NoVBFWeight->GetBinContent(1) << " +/- " << hZ_DY_NoVBFWeight->GetBinError(1) << std::endl;
  //std::cout << "  norm eff (unweighted DY, no VBF / weighted DY, no VBF): " << dyNorm << std::endl;
  std::cout << std::endl;
  std::cout << "#####################################################################################" << std::endl;
  std::cout << std::endl << std::endl;

  // write the cutflow table
  std::cout << "Writing cut flow TeX file" << std::endl;

  ofstream effFile;
  effFile.open(options.oDir+std::string("/cutflowZMuMu.tex"));

  effFile << "Cut & N(data) & N(DY\\rightarrow\\ell\\ell) & N($t\\bar{t}$) & N(single $t$) & N(diboson) \\\\" << std::endl;

  TH1D* hZ_CutFlow_TTBar = (TH1D*) ofile->Get("hZ_CutFlow_TTBar");

  // cutflow table
  for (unsigned i=0; i<nCutsZMuMu; ++i) {

    effFile << cuts.cutNameZMuMu(i) << " & ";
    effFile << "$" << hZ_CutFlow_Data->GetBinContent(i+1) << " \\pm " << hZ_CutFlow_Data->GetBinError(i+1) << "$ & ";
    effFile << "$" << hZ_CutFlow_DY->GetBinContent(i+1) << " \\pm " << hZ_CutFlow_DY->GetBinError(i+1) << "$ & ";
    effFile << "$" << hZ_CutFlow_TTBar->GetBinContent(i+1) << " \\pm " << hZ_CutFlow_TTBar->GetBinError(i+1) << "$ & ";
    effFile << "$" << hZ_CutFlow_SingleTSum->GetBinContent(i+1) << " \\pm " << hZ_CutFlow_SingleTSum->GetBinError(i+1) << "$ & ";
    effFile << "$" << hZ_CutFlow_Diboson->GetBinContent(i+1) << " \\pm " << hZ_CutFlow_Diboson->GetBinError(i+1) << "$ & ";
    effFile << std::endl;

  }

  effFile << std::endl << std::endl;
  effFile.close();

  // list histograms for dataset summing
  std::vector<std::string> hists;
  hists.push_back("ZCtrlZMass");
  hists.push_back("ZCtrlZpT");
  hists.push_back("ZCtrlJet1pT");
  hists.push_back("ZCtrlJet1Eta");
  hists.push_back("ZCtrlJet2pT");
  hists.push_back("ZCtrlJet2Eta");
  hists.push_back("ZCtrlCenJetpT");
  hists.push_back("ZCtrlDEtajj");
  hists.push_back("ZCtrlMjj");
  hists.push_back("ZCtrlMET");
  hists.push_back("ZCtrlDPhijj");

  // check whether we have NoTrig histograms or normal
  bool noTrig = false;
  std::string dyJetsName = oDir_Plot+std::string("/DYJetsToLL.root");
  std::string dyJetsPtZName = oDir_Plot+std::string("/DYJetsToLL_PtZ-100.root");
  struct stat buffer; 
  if (stat (dyJetsName.c_str(), &buffer) != 0) {
    noTrig = true;
    dyJetsName = oDir_Plot+std::string("/DYJetsToLL_NoTrig.root");
    dyJetsPtZName = oDir_Plot+std::string("/DYJetsToLL_PtZ-100_NoTrig.root");
  }

  std::cout << "Getting histograms for plots from " << dyJetsName << " and " << dyJetsPtZName << std::endl;

  // re-scale QCD DY histograms
  TFile* qcdDYFile = TFile::Open(dyJetsName.c_str(), "UPDATE");
  for (std::vector<std::string>::const_iterator hname=hists.begin(); hname!=hists.end(); ++hname) {
    TH1D* h = (TH1D*) qcdDYFile->Get(hname->c_str());
    //std::cout << "Integral before : " << h->Integral() << std::endl;
    h->Scale(dyNorm);
    //std::cout << "Integral after : " << h->Integral() << std::endl;
    h->Write("",TObject::kOverwrite);
  }
  qcdDYFile->Close();

  qcdDYFile = TFile::Open(dyJetsPtZName.c_str(), "UPDATE");
  for (std::vector<std::string>::const_iterator hname=hists.begin(); hname!=hists.end(); ++hname) {
    TH1D* h = (TH1D*) qcdDYFile->Get(hname->c_str());
    h->Scale(dyNorm);
    h->Write("",TObject::kOverwrite);
  }
  qcdDYFile->Close();


  // sum DY datasets
  std::vector<std::string> DYDatasets;
  if (noTrig) {
    DYDatasets.push_back(std::string("DYJetsToLL_NoTrig"));
    DYDatasets.push_back(std::string("DYJetsToLL_PtZ-100_NoTrig"));
    DYDatasets.push_back(std::string("DYJetsToLL_EWK_NoTrig"));
  }
  else {
    DYDatasets.push_back(std::string("DYJetsToLL"));
    DYDatasets.push_back(std::string("DYJetsToLL_PtZ-100"));
    DYDatasets.push_back(std::string("DYJetsToLL_EWK"));
  }
  SumDatasets(oDir_Plot, DYDatasets, hists, "DY+jets");

  // sum single top datasets
  std::vector<std::string> topDatasets;
  topDatasets.push_back(std::string("SingleT_t"));
  topDatasets.push_back(std::string("SingleTbar_t"));
  topDatasets.push_back(std::string("SingleT_s"));
  topDatasets.push_back(std::string("SingleTbar_s"));
  topDatasets.push_back(std::string("SingleT_tW"));
  topDatasets.push_back(std::string("SingleTbar_tW"));
  topDatasets.push_back(std::string("TTBar"));
  SumDatasets(oDir_Plot, topDatasets, hists, "SingleT+TTbar"); 

  // sum diboson datasets
  std::vector<std::string> dibDatasets;
  dibDatasets.push_back(std::string("WW"));
  dibDatasets.push_back(std::string("WZ"));
  dibDatasets.push_back(std::string("ZZ"));
  dibDatasets.push_back(std::string("WG"));
  SumDatasets(oDir_Plot, dibDatasets, hists, "DiBoson");

  // sum SM backgrounds
  std::vector<std::string> bgDatasets;
  bgDatasets.push_back(std::string("WW"));
  bgDatasets.push_back(std::string("WZ"));
  bgDatasets.push_back(std::string("ZZ"));
  bgDatasets.push_back(std::string("WG"));
  bgDatasets.push_back(std::string("SingleT_t"));
  bgDatasets.push_back(std::string("SingleTbar_t"));
  bgDatasets.push_back(std::string("SingleT_s"));
  bgDatasets.push_back(std::string("SingleTbar_s"));
  bgDatasets.push_back(std::string("SingleT_tW"));
  bgDatasets.push_back(std::string("SingleTbar_tW"));
  bgDatasets.push_back(std::string("TTBar"));
  SumDatasets(oDir_Plot, bgDatasets, hists, "tt+VV"); 

  // make plots
  std::cout << "Making plots" << std::endl;
  StackPlot plots(oDir_Plot);
  plots.setLegPos(0.70,0.60,0.93,0.89);
  //plots.setLegPos(0.62,0.62,0.89,0.89);

  // Note that here I've used the overloaded method addDataset, which allows you to specify a filename for the input ROOT file
  // *and* also allows you to specify what to put in the TLegend. (By default, it uses the filename as the TLegend entry)
  // This is because the Tlegend entry involves some odd characters, which are best not used in filenames for safety

  //  plots.addDataset("DiBoson", kViolet-6, 0);
  plots.addDataset("tt+VV", "t#bar{t}, tW, VV", kAzure-2, 0);
  plots.addDataset("DY+jets", "DY(ll)+jets", kPink-4, 0);
  plots.addDataset("METABCD", kBlack, 1);
  plots.setScaleMCtoData(true); //rescale MC to data

  plots.draw("ZCtrlZpT",	"Z_p_{T} [GeV]",		"N_{events}"	,1,"RATIO_Z");
  plots.draw("ZCtrlJet1pT", 	"Leading jet p_{T} [GeV]", 	"N_{events}"	,1,"RATIO_Z");
  plots.draw("ZCtrlJet1Eta", 	"Leading jet #eta", 		"N_{events}"	,1,"RATIO_Z");
  plots.draw("ZCtrlJet2pT",     "Sub-leading jet p_{T} [GeV]",  "N_{events}"	,1,"RATIO_Z");
  plots.draw("ZCtrlJet2Eta",    "Sub-leading jet #eta",         "N_{events}"	,1,"RATIO_Z");
  plots.draw("ZCtrlCenJetpT",	"Central jet p_{T} [GeV]",	"N_{events}"    ,1,"RATIO_Z");
  plots.draw("ZCtrlDEtajj",	"#Delta #eta_{jj}",		"N_{events}"	,1,"RATIO_Z");
  plots.setYMax(5.e2);
  plots.setXMin(1100.);
  plots.setXMax(2600.);
  plots.draw("ZCtrlMjj", 	"M_{jj} [GeV]",			"Events / 100 GeV"	,1,"RATIO_Z");
  plots.setYMax(5.e2);
  plots.setXMin(130.);
  plots.draw("ZCtrlMET", 	"E_{T}^{miss} [GeV]",		"Events / 20 GeV"	,1,"RATIO_Z");
  plots.draw("ZCtrlDPhijj", 	"#Delta #phi_{jj}",		"Events"	,1,"RATIO_Z");
  plots.setYMax(80.);
  plots.setYMin(0.);
  plots.draw("ZCtrlZMass",      "M_{#mu#mu}  [GeV]",      "Events / 5 GeV"    ,0,"RATIO_Z");

  //store histograms
  ofile->cd();
  hZ_DY_C_DPhi->Write("",TObject::kOverwrite);
  hZ_BG_C_DPhi->Write("",TObject::kOverwrite);
  hZ_Data_C_DPhi->Write("",TObject::kOverwrite);
  hZ_Est_C_DPhi->Write("",TObject::kOverwrite);
  hZ_Est_C_DPhi_Syst->Write("",TObject::kOverwrite);
  hZ_Est_S_DPhi->Write("",TObject::kOverwrite);
  hZ_Est_S_DPhi_Syst->Write("",TObject::kOverwrite);

  hZ_Eff_S_DPhi->Write("",TObject::kOverwrite);
  hZ_Eff_S_DPhi_Syst->Write("",TObject::kOverwrite);
  hZ_QCD_EffVBFS_D->Write("",TObject::kOverwrite);
  hZ_QCD_EffVBFS_N->Write("",TObject::kOverwrite);
  hZ_QCD_EffVBFC_D->Write("",TObject::kOverwrite);
  hZ_QCD_EffVBFC_N->Write("",TObject::kOverwrite);
  hZ_EWK_EffVBFS_D->Write("",TObject::kOverwrite);
  hZ_EWK_EffVBFS_N->Write("",TObject::kOverwrite);
  hZ_EWK_EffVBFC_D->Write("",TObject::kOverwrite);
  hZ_EWK_EffVBFC_N->Write("",TObject::kOverwrite);
  hZ_DY_EffVBFS->Write("",TObject::kOverwrite);
  hZ_DY_EffVBFC->Write("",TObject::kOverwrite);
  hZ_DY_TotalEff->Write("",TObject::kOverwrite);

  hZ_CutFlow_Data->Write("",TObject::kOverwrite);
  hZ_CutFlow_DY->Write("",TObject::kOverwrite);
  hZ_CutFlow_SingleTSum->Write("",TObject::kOverwrite);
  hZ_CutFlow_Diboson->Write("",TObject::kOverwrite);

  ofile->Close();    

}
Example #11
0
void gluinoMass(double lumi=-1., double maxInstLumi=-1.) {
	
  if (lumi<0)
    lumi=877.;
  if (maxInstLumi<0)
    maxInstLumi=1300.;
  LimitPlots plots(lumi);
  
  plots.calculateCrossSections(7,4,39,9);
	
  // expected limit (1 and 2 sigma bands)
  TGraph* g_exp = plots.getExpMassLimitGluino();
  TGraphAsymmErrors* g_exp1 = plots.getExpMassLimitGluino1Sig();
  TGraphAsymmErrors* g_exp2 = plots.getExpMassLimitGluino2Sig();
  
  // three points on counting expt curve
  TGraph* g_gluino = plots.getMassLimitGluino();
  TGraph* g_stop = plots.getMassLimitStop();
  
  // one point from lifetime fit
  TGraph* g_tp = plots.getMassLimitGluinoTP();
  
  // theory prediction
  TGraph* g_thGluino = plots.getGluinoTheory();
  TGraph* g_thStop = plots.getStopTheory();
  
  TCanvas* canvas = new TCanvas("canvas");
  
  //canvas->SetGrid();
  canvas->SetLogy();
  
  TH1 * h;
  h = canvas->DrawFrame(300., .02, 1000., 1e2);
  //h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; Stopped HSCP Cross Section #times BR [pb]");
  h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) [pb]");
  
  // not covered region
  TBox* nc = new TBox(100., .1, 150., 5e2);
  nc->SetFillStyle(3354);
  nc->SetFillColor(kRed-4);
  //nc->Draw();
  
  // details
  TPaveText* blurb = new TPaveText(300., 2, 550., 1e2);
  blurb->AddText("CMS Preliminary 2012");

  std::stringstream label;
  label<<"#int L dt = "<<lumi<<" fb^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10.;
    ++exponent;
  }
  label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  blurb->AddText("m_{#tilde{g}} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{t}} - m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");	
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.032);

  
  // legend
  TBox *legbg = new TBox(600., 2., 900., 1e2);
  legbg->Draw();
  TLegend *leg = new TLegend(600., 2., 900., 1e2,"95% C.L. Limits","");
  leg->SetTextSize(0.028);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  leg->AddEntry(g_exp, "Expected: 10 #mus - 1000 s Counting Exp. ", "l");
  leg->AddEntry(g_exp1, "Expected #pm1#sigma: 10 #mus - 1000 s Counting Exp. ", "f");
  leg->AddEntry(g_exp2, "Expected #pm2#sigma: 10 #mus - 1000 s Counting Exp. ", "f");
  //	  leg->AddEntry(graph3, "Obs.: 10^{6} s Counting Exp.", "l");
  leg->AddEntry(g_gluino, "Obs.: 10 #mus - 1000 s Counting Exp. ", "l");
  leg->AddEntry(g_tp, "Obs.: 10 #mus Timing Profile ", "l");
  //leg->AddEntry(g_stop, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(graph_em, "Obs.: 10 #mus - 1000 s Counting Exp. (EM only)", "l");
  //  leg->AddEntry(graph1, "Obs.: 570 ns Counting Exp.", "l");
  leg->Draw();
  
  
  
  // 2 sigma expected band
  g_exp2->SetLineColor(0);
  g_exp2->SetLineStyle(0);
  g_exp2->SetLineWidth(0);
  g_exp2->SetFillColor(5);
  g_exp2->SetFillStyle(1001);
  g_exp2->Draw("3");
  
  // 1 sigma expected band
  g_exp1->SetLineColor(0);
  g_exp1->SetLineStyle(0);
  g_exp1->SetLineWidth(0);
  g_exp1->SetFillColor(3);
  g_exp1->SetFillStyle(1001);
  g_exp1->Draw("3");  
  
  // expected line
  g_exp->SetLineStyle(2);
  g_exp->SetLineWidth(1);
  g_exp->Draw("l");
  
 
  // plateau limit - 1 ms
  g_gluino->SetLineColor(1);
  g_gluino->SetLineStyle(1);
  g_gluino->SetLineWidth(2);
  g_gluino->Draw("l");
  
  // stop curve
  g_stop->SetLineColor(1);
  g_stop->SetLineStyle(5);
  g_stop->SetLineWidth(2);
  //g_stop->Draw("l");
 

  // 1 mus lifetime fit limit
  g_tp->SetLineColor(kRed);
  g_tp->SetLineStyle(1);
  g_tp->SetLineWidth(2);
  g_tp->Draw("l");
  
  // theory line
  g_thGluino->SetLineColor(kBlue);
  g_thGluino->SetLineStyle(1);
  g_thGluino->SetLineWidth(2);
  g_thGluino->SetFillStyle(3001);
  g_thGluino->SetFillColor(kBlue-4);
  g_thGluino->Draw("l3");
  
  g_thStop->SetLineColor(kRed);
  g_thStop->SetLineStyle(1);
  g_thStop->SetLineWidth(2);
  g_thStop->SetFillStyle(3001);
  g_thStop->SetFillColor(kRed-4);
  //g_thStop->Draw("l3");


  // theory line label
  TLatex* th = new TLatex(600., .3, "NLO+NLL #tilde{g}");
  th->SetTextColor(kBlue);
  th->SetTextFont(42);
  th->SetTextSize(0.035);
  th->Draw();

  TLatex* ths = new TLatex(330., 2., "NLO+NLL #tilde{t}");
  ths->SetTextColor(kRed);
  ths->SetTextFont(42);
  ths->SetTextSize(0.035);
  //ths->Draw();

  // not explored label
  TText* ne = new TText(125., .2, "Not Sensitive");
  ne->SetTextColor(kRed+1);
  ne->SetTextFont(42);
  ne->SetTextAngle(90);
  ne->SetTextSize(0.035);
  //ne->Draw();

  blurb->Draw();

  canvas->RedrawAxis();

  canvas->Print("gluinoMassLimit.pdf");
  canvas->Print("gluinoMassLimit.C");

  plots.calculateIntercepts();
  
}
Example #12
0
void modelIndLimit(double lumi=-1.,double maxInstLumi=-1.) 
{
  if (lumi<0)
    lumi=LUMI;
  if (maxInstLumi<0)
    maxInstLumi=MAXINSTLUMI;
  LimitPlots plots(lumi);
	
  plots.calculateCrossSections(7,4,39,9);

  // graphs - observed
  TGraph* g_gluino  = plots.getLimitGluinoBasic();
  TGraph* g_stop    = plots.getLimitStopBasic();
  
  TCanvas *canvas;
  canvas = new TCanvas("basicPlot");

  //canvas->SetGrid();
  canvas->SetLogx();
  canvas->SetLogy();

  TH1* h = canvas->DrawFrame(7.5e-8, 3e-3, 1e6, 10);
  //	h->SetTitle("Beamgap Expt;#tau_{#tilde{g}} [s]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) #times #varepsilon^{#tilde{g}#tilde{g}}_{stop} [pb]");
  h->SetTitle("Beamgap Expt;#tau_{HSCP} [s]; Model Independent Cross-section [pb]");

  TPaveText* blurb = new TPaveText(5e-7, .5, 1e-2, 7);
  blurb->AddText("CMS Preliminary 2012");

  std::stringstream label;
  label<<"#int L dt = "<<lumi<<" fb^{-1}";
  blurb->AddText(label.str().c_str());

  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10;
    ++exponent;
  }
  label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  blurb->AddText(label.str().c_str());

  //	blurb->AddText("LUMI pb^{-1}");
  //	blurb->AddText("L^{max}_{inst} = MAXLUMI 10^{33} cm^{-2}s^{-1}");
	
  label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  //blurb->AddText("m_{HSCP} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{g}} = 300 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();


  //	TPaveText* cms = new TPaveText(1e-6, 1.5e1, 1e-2, 2e1);
  //	cms->AddText("CMS 2011");
  //	cms->SetTextFont(62);
  //	cms->SetBorderSize(0);
  //	cms->SetFillColor(0);
  //	cms->SetShadowColor(0);
  //	cms->SetTextAlign(12);
  //	cms->SetTextSize(0.040);
  //	cms->Draw();


  TLegend* leg = new TLegend(2e-2, .5, 1e2, 7,"95% C.L. Limits:","");
  leg->SetTextSize(0.030);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  leg->AddEntry(g_gluino, "Gluino : m_{#tilde{g}}=500 GeV/c^{2}, m_{#tilde{#chi^{0}}}=387 GeV/c^{2}", "l");
  leg->AddEntry(g_stop, "Stop  : m_{#tilde{t}}=300 GeV/c^{2}, m_{#tilde{#chi^{0}}}=109 GeV/c^{2}", "l");
  leg->Draw();

  g_gluino->SetLineColor(2);
  g_gluino->SetLineStyle(1);
  g_gluino->SetLineWidth(2);
  g_gluino->Draw("l");

  g_stop->SetLineColor(4);
  g_stop->SetLineStyle(1);
  g_stop->SetLineWidth(2);
  g_stop->Draw("l");

  canvas->Print("basicLimit.png");
  canvas->Print("basicLimit.pdf");
  canvas->Print("basicLimit.C");

  return;

}
void gluinostopMassLifetime(double lumi=4560., double maxInstLumi=5000.) {

  ExtraLimitPlots plots(lumi);
  plots.calculateCrossSections(4,6,3,39,9);

  // xsecs as extracted from nllfast http://web.physik.rwth-aachen.de/service/wiki/bin/view/Main/SquarksandGluinos
  // gluino (m_squark=m_gluino):  "nllfast gg mstw <mass> <mass>"
  // gluino (m_squark>>m_gluino): "nllfast gdcpl mstw <mass>"
  // stop: "nllfast st mstw <mass>"
  // the xsec of gluino and stop are updated for 13TeV analysis, the xsecs are extracted from:
  // https://twiki.cern.ch/twiki/bin/view/LHCPhysics/SUSYCrossSections#Cross_sections_for_various_S_AN2
  double g_mass [21] = {  
    200 ,     250 ,     300 ,     350 ,     400 ,   
    450 ,     500 ,     550 ,     600 ,     650 ,   
    700 ,     750 ,     800 ,     850 ,     900 ,   
    950 ,    1000 ,    1050 ,    1100 ,    1150 ,   
    1200 };
  double g_xsec [21] = {  
    3574,      1190,     462,     202,     98.0,
    50.4,      27.4,    15.6,     9.20,    5.60,
    3.53,      2.27,     1.49,   0.996,   0.677,
    0.466,     0.325,  0.229,   0.163,  0.118,
    0.0856
  };
  double g_xsecdcpl [21] = {  
    3574,      1190,     462,     202,     98.0,
    50.4,      27.4,    15.6,     9.20,    5.60,
    3.53,      2.27,     1.49,   0.996,   0.677,
    0.466,     0.325,  0.229,   0.163,  0.118,
    0.0856
  };
  double s_mass [21] = {  
    100 ,     150 ,     200 ,     250 ,     300 ,   
    350 ,     400 ,     450 ,     500 ,     550 ,   
    600 ,     650 ,     700 ,     750 ,     800 ,   
    850 ,     900 ,     950 ,    1000 ,    1050 ,   
    1100 };
  double s_xsec [21] = {  
    1521,       249.4,     64.5,     21.6,     8.51,
    3.79,        1.84,    0.948,   0.518,   0.296,
    0.175,      0.107,  0.067,  0.0431,  0.0283,
    0.0190,    0.0129, 0.00883, 0.00615, 0.00432,
    0.00307
  };

  //gluino xsec
  vector<double> masses;
  for (int i = 0; i < 21; ++i)  {
    masses.push_back(g_mass[i]);
    g_xsec [i] = log10 (g_xsec [i]*1e3) * 20.;
    g_xsecdcpl [i] = log10 (g_xsecdcpl [i]*1e3) * 20.;
  }
  //  Xsection gluino_xs (masses, g_xsec);
  Xsection gluino_xs (masses, g_xsecdcpl);
  
  //stop xsec
  masses.clear();
  for (int i = 0; i < 19; ++i)  {
    masses.push_back(s_mass[i]);
    s_xsec [i] = log10 (s_xsec [i]*1e3) * 20.;
  }
  Xsection stop_xs (masses, s_xsec);
  
  // graphs
  TGraph* g_obs     = new TGraph (*plots.getLimitGluino());
  gluino_xs.xsec2mass (g_obs);

  TGraph* g_exp      = new TGraph (*plots.getExpLimitGluino());
  gluino_xs.xsec2mass (g_exp);
  TGraphAsymmErrors* g_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitGluino1Sig());
  gluino_xs.xsec2mass (g_exp_1sig);
  TGraphAsymmErrors* g_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitGluino2Sig());
  gluino_xs.xsec2mass (g_exp_2sig);

  TGraph* stop_obs     = new TGraph (*plots.getLimitStop());
  stop_xs.xsec2mass (stop_obs);

  TGraph* stop_exp      = new TGraph (*plots.getExpLimitStop());
  stop_xs.xsec2mass (stop_exp);
  TGraphAsymmErrors* stop_exp_1sig = new TGraphAsymmErrors (*plots.getExpLimitStop1Sig());
  stop_xs.xsec2mass (stop_exp_1sig);
  TGraphAsymmErrors* stop_exp_2sig = new TGraphAsymmErrors (*plots.getExpLimitStop2Sig());
  stop_xs.xsec2mass (stop_exp_2sig);

  
  TCanvas *canvas = new TCanvas("allMassLifetime", "allMassLifetime", 800, 600);
  
  canvas->SetLogx();
//  canvas->SetGridy();

  
  TH1F* h = new TH1F ("h", "", 1,  7.5e-8, 1e6);
  h->SetStats (0);
  h->SetMinimum (300);
  h->SetMaximum (2000);
  h->SetTitle("Beamgap Expt");
  //  h->GetXaxis()->SetTitle("#tau_{#tilde{g},#tilde{t},#tilde{#tau}} [s]");
  h->GetXaxis()->SetTitle("#tau [s]");
  h->GetYaxis()->SetTitle("m [GeV]  ");
  h->Draw ("");

  
  
  // limit arrows
  double* x = g_obs->GetX();
  for (int i = 0; i < g_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  g_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kRed);
      arrow->SetLineWidth (2);
      //arrow->Draw();
      cout << "GLUINO mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
  x = g_obs->GetX();
  for (int i = 0; i < stop_obs->GetN(); ++i) {
    if (x[i] > 0.5) {
      double y =  stop_obs->GetY()[i];
      TArrow* arrow = new TArrow (x[i], y, h->GetXaxis()->GetXmin(), y, 0.02);
      arrow->SetLineColor (kBlue);
      arrow->SetLineWidth (2);
      //arrow->Draw();
      cout << "STOP mass limit @ " << x[i] << "sec is found: " << y << endl;
      break;
    }
  }
 
  // gluino  
  // 2 sigma band
  if (g_exp_2sig) {
    g_exp_2sig->SetLineColor(0);
    g_exp_2sig->SetLineStyle(0);
    g_exp_2sig->SetLineWidth(0);
    g_exp_2sig->SetFillColor(kYellow);
    g_exp_2sig->SetFillStyle(1001);
    g_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (g_exp_1sig) {
    // g_exp_1sig->SetLineColor(8);
    g_exp_1sig->SetLineColor(0);
    g_exp_1sig->SetLineStyle(0);
    g_exp_1sig->SetLineWidth(0);
    // g_exp_1sig->SetFillColor(8);
    g_exp_1sig->SetFillColor(kGreen);
    g_exp_1sig->SetFillStyle(1001);
    // g_exp_1sig->SetFillStyle(3005);
    g_exp_1sig->Draw("3");
    // g_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (g_exp) {
    g_exp->SetLineColor(kRed);
    g_exp->SetLineStyle(4);
    g_exp->SetLineWidth(2);
    g_exp->Draw("l3");
  }
  

  // observed limit
  if (g_obs) {
    g_obs->SetLineColor(kRed);
    g_obs->SetLineStyle(1);
    g_obs->SetLineWidth(2);
    g_obs->Draw("l");
  }
  
  // stop  
  // 2 sigma band
  if (stop_exp_2sig) {
    stop_exp_2sig->SetLineColor(0);
    stop_exp_2sig->SetLineStyle(0);
    stop_exp_2sig->SetLineWidth(0);
    stop_exp_2sig->SetFillColor(kYellow);
    stop_exp_2sig->SetFillStyle(1001);
    stop_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (stop_exp_1sig) {
    // stop_exp_1sig->SetLineColor(8);
    stop_exp_1sig->SetLineColor(0);
    stop_exp_1sig->SetLineStyle(0);
    stop_exp_1sig->SetLineWidth(0);
    // stop_exp_1sig->SetFillColor(8);
    stop_exp_1sig->SetFillColor(kGreen);
    stop_exp_1sig->SetFillStyle(1001);
    // stop_exp_1sig->SetFillStyle(3005);
    stop_exp_1sig->Draw("3");
    // stop_exp_1sig->Draw("lX");
  }
  
  
  // epxected limit
  if (stop_exp) {
    stop_exp->SetLineColor(kBlue);
    stop_exp->SetLineStyle(3);
    stop_exp->SetLineWidth(2);
    stop_exp->Draw("l3");
  }
  

  // observed limit
  if (stop_obs) {
    stop_obs->SetLineColor(kBlue);
    stop_obs->SetLineStyle(2);
    stop_obs->SetLineWidth(2);
    stop_obs->Draw("l");
  }
  
  

  TPaveText* blurb = new TPaveText(0.20, 0.63, 0.60, 0.90, "NDC");
  blurb->AddText("CMS Preliminary 2015");
  //blurb->AddText("CMS 2012");
  blurb->AddText("#int L dt = 2.46 fb^{-1}"); //,  #int L_{eff} dt = 935 pb^{-1}");
  //blurb->AddText("L^{max}_{inst} = 3.5 #times 10^{33} cm^{-2}s^{-1}");

  // std::stringstream label;
  // label<<"#int L dt = "<<lumi<<" pb^{-1}";
  // blurb->AddText(label.str().c_str());
  // double peakInstLumi=maxInstLumi;
  // int exponent=30;
  // while (peakInstLumi>10) {
  //   peakInstLumi/=10;
  //   ++exponent;
  // }
  // std::stringstream label2;
  // label2<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
//  blurb->AddText(label2.str().c_str());
  blurb->AddText("#sqrt{s} = 13 TeV");
  blurb->AddText("E_{g} > 120 GeV, E_{t} > 150 GeV");
  blurb->AddText("E_{jet} > 70 GeV");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();

  TLegend* leg = new TLegend(0.6, 0.62, 0.87, 0.90,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);

  leg->AddEntry(g_obs, " #tilde{g} observed", "l");
  leg->AddEntry(stop_obs, " #tilde{t} observed", "l");

  TGraph* expectedStyle1 = new TGraph (*g_exp);
  expectedStyle1->SetFillColor (g_exp_1sig->GetFillColor());
  TGraph* expectedStyle2 = new TGraph (*g_exp);
  expectedStyle2->SetFillColor (g_exp_2sig->GetFillColor());
  leg->AddEntry(expectedStyle1, " #tilde{g} expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, " #tilde{g} expected #pm2#sigma", "lf");

  expectedStyle1 = new TGraph (*stop_exp);
  expectedStyle1->SetFillColor (stop_exp_1sig->GetFillColor());
  expectedStyle2 = new TGraph (*stop_exp);
  expectedStyle2->SetFillColor (stop_exp_2sig->GetFillColor());
  leg->AddEntry(expectedStyle1, " #tilde{t} expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, " #tilde{t} expected #pm2#sigma", "lf");
  leg->Draw();

  h->Draw("sameaxis");

  canvas->Print("gluinostopMassLifetime.png");
  canvas->Print("gluinostopMassLifetime.pdf");
}
/*!
Read the "words" from the method section in the input file
via doinput() parsing, and store section information in private
variables isoses, resolution, and minmax.
Set up MO_matrix and Sample_point objects for wavefunction from input
*/
void Nodes_method::read(vector <string> words,
                       unsigned int & pos,
                       Program_options & options)
{
  pos=0;	//always start from first word
  doublevar Tres;
  vector <string> Torbs;
  vector <string> Tminmax;
  vector <string> orbtext;
  vector <string> Tdxyz;


  allocate(options.systemtext[0], sysprop);
  sysprop->generateSample(mywalker);

  allocate(options.twftext[0], sysprop, wfdata);
  wfdata->generateWavefunction(wf);

  mywalker->attachObserver(wf);
 
  pos=0;
  if(readsection(words,pos=0,Torbs,"CONTOURS")){
    //   error("Need CONTOURS in METHOD section");
  plots.Resize(Torbs.size());
  for(unsigned int i=0; i<Torbs.size(); i++){
        plots(i)=atoi(Torbs[i].c_str());
      }
  }
  else {
    cout <<"WARNING: All electrons are used for scanning!"<<endl;
    plots.Resize(mywalker->electronSize());
    for(int i=0; i<plots.GetSize(); i++){
      plots(i)=i+1;
      } 
  }
 
  pos=0;
  if(! readvalue(words,pos,Tres,"RESOLUTION"))
    error("Need RESOLUTION in METHOD section");
  resolution=Tres;


  pos=0;
  minmax.Resize(6);
  if(readsection(words,pos,Tminmax,"MINMAX")) { 
    if(Tminmax.size() != 6)
      error("MINMAX needs 6 values");
    for(unsigned int i=0; i<Tminmax.size(); i++)
    {
      minmax(i)=atof(Tminmax[i].c_str());
    }
  }
  else  { 
    minmax=0.0;
  
    int nions=sysprop->nIons();
    Array1 <doublevar> ionpos(3);
    for(int i=0; i< nions; i++) {
      sysprop->getIonPos(i,ionpos);
      for(int d=0; d< 3; d++) {
        if(ionpos(d) < minmax(2*d)) minmax(2*d) = ionpos(d);
        if(ionpos(d) > minmax(2*d+1)) minmax(2*d+1)=ionpos(d);
      }
    }

    for(int d=0; d< 3; d++) {
      minmax(2*d)-=4.0;
      minmax(2*d+1)+=4.0;
      cout << "minmax " << minmax(2*d) << " " << minmax(2*d+1) << endl;
    }
  } 
  
  
 

  // Makes the Nodes methods use the current implementation of Nodes
  if(readvalue(words, pos=0, readconfig, "READCONFIG")){
    Array1 <Config_save_point> config_pos;
    config_pos.Resize(0);
    if(readconfig!="") { 
      read_configurations(readconfig, config_pos);
    }
    if(config_pos.GetDim(0)<1)
      error("Could not read a single walker from config file");
    //take a first one
    config_pos(0).restorePos(mywalker);
  }
  else {
    mywalker->randomGuess();
    debug_write(cout, 0, " configs read ", 1,
                " configs randomly generated \n");
  }
  
  pos=0;
  doublemove=false;
  if( readsection(words,pos,Tdxyz,"DOUBLEMOVES")){
    doublemove=true;
    if(plots.GetSize()%2)
      error("Needs pairs of countours for doublemoves");
    unsigned int dummy=3*plots.GetSize()/2;
    if(Tdxyz.size()!=dummy)
      error("DOUBLEMOVES needs 3 x # of vectors values");
    dxyz.Resize(plots.GetSize()/2,3);
    for(int i=0; i<plots.GetSize()/2; i++){
      for (int j=0; j<3;j++)
        dxyz(i,j)=atof(Tdxyz[i*3+j].c_str());
    }
  }
}
void Nodes_method::run(Program_options & options, ostream & output)
{
  ofstream os; //for writing to *.plt files
  string pltfile; //name of plotfile being written
  string confile; //name of configuration of electrons to be  being written
  double max_value,min_value;
  int count;
  Array1 <doublevar> xyz(3), xyz2(3),
    resolution_array(3); //position of electron "in" MO
  Array1 <int> D_array1(3); //dummy array1
  Array2 <doublevar> oldpos(mywalker->electronSize(),3);
  Array1 <doublevar> tmp(3);
  D_array1=0; //sets all 3 components to 0. use as counter for gridpoints
  
  
  D_array1(0)=roundoff((minmax(1)-minmax(0))/resolution);
  D_array1(1)=roundoff((minmax(3)-minmax(2))/resolution);
  D_array1(2)=roundoff((minmax(5)-minmax(4))/resolution);

  resolution_array(0)=(minmax(1)-minmax(0))/(D_array1(0)-1);  
  resolution_array(1)=(minmax(3)-minmax(2))/(D_array1(1)-1);
  resolution_array(2)=(minmax(5)-minmax(4))/(D_array1(2)-1);

  Array2 <doublevar> grid(plots.GetSize(),D_array1(0)*D_array1(1)*D_array1(2));
  Wf_return wfvals(wf->nfunc(), 2); //where wfval fist index labels 
    //wf number ie. ground state
    // excited state and so on, and second label is for two values, sign and log(wf).

 //scan electron positions
  cout << "Using these electron positions:"<<endl;
  for(int i=0; i<mywalker->electronSize(); i++){
    mywalker->getElectronPos(i, tmp);
    cout.precision(5);
    cout.width(8);
    cout <<i+1<<" "<<tmp(0)<<" "<<tmp(1)<<" "<<tmp(2)<<endl;
    for (int d=0;d<3;d++)
      oldpos(i,d)=tmp(d);
    //    cout << "pos " << oldpos(i,0) << "   " << oldpos(i,1) << "   " << oldpos(i,2)
    //     << endl;
  }

  //generate .xyz file for gOpenMol to view coordinates
  pltfile=options.runid + ".xyz";
  os.open(pltfile.c_str());
  cout<<"writing to "<<pltfile<<endl;
  vector <string> atomlabels;
  sysprop->getAtomicLabels(atomlabels);
  os<<atomlabels.size()+mywalker->electronSize()<<endl;
  os<<endl;
  
  int spin_up=sysprop->nelectrons(0);
  //cout << "Up electrons "<<spin_up<<endl;

  
  for(unsigned int i=0; i<atomlabels.size(); i++){
    Array1 <doublevar> pos(3);
    mywalker->getIonPos(i, pos);
    os<<atomlabels[i] <<" "<< pos(0)
    <<" "<<pos(1)
    <<" "<< pos(2)<<endl;
  }
  for(int j=0; j<mywalker->electronSize(); j++){
    if (j<spin_up) os<<"Eu";
    else os<<"Ed";
        // mywalker->getElectronPos(j, pos);
       os<<" "<< oldpos(j,0)<<" "<<oldpos(j,1) <<" "<< oldpos(j,2)<<endl;
  }
  os.close();
  

  if (!doublemove) {
    //calculate value of each molecular orbital at each grid point and store in an Array1
    // grid values with x=fastest running variable, and z=slowest

    cout<<"calculating "<<D_array1(0)*D_array1(1)*D_array1(2)
        <<" grid points"<<endl;
    cout<<"for "<< plots.GetDim(0) <<" 3D projections of wavefunction"<<endl;
    count=0;
    xyz(0)=minmax(0);
    xyz(1)=minmax(2);
    xyz(2)=minmax(4); //init elec probe to xmin ymin zmin
    //Array1 <doublevar> oldpos(3)

  
  
    for(int i=0; i<plots.GetSize(); i++){
      cout.width(3);
      cout <<"============================="<<plots(i)
           <<"=============================="
           <<endl;
      count=0;
      for(int xx=0; xx<D_array1(0);xx++){
	xyz(0)=minmax(0)+xx*resolution_array(0);  //move forward on x axis one resolution unit
	max_value=min_value=0.0;
	cout << "x ";
        cout.precision(5);
        cout.width(8);
        cout<< xyz(0);
	for(int yy=0; yy<D_array1(1);yy++){
          xyz(1)=minmax(2)+yy*resolution_array(1);  //move forward on y axis one resolution unit
	  for(int zz=0;zz<D_array1(2);zz++){
	    xyz(2)=minmax(4)+zz*resolution_array(2); //move forward on z axis one resolution unit
	    // mywalker->getElectronPos(plots(i), oldpos);
            mywalker->setElectronPos(plots(i)-1,xyz); //move elec#plots(i) to point specified by xyz
            wf->updateVal(wfdata, mywalker); //update wfdata
            wf->getVal(wfdata, 0, wfvals); //get wf value
            const doublevar cutoff=15;
            if(wfvals.amp(0,0)<cutoff) { 
              grid(i,count)=wfvals.sign(0)*exp(wfvals.amp(0,0));
            }
            else { //cut off the maximum value output so that there aren't overflow errors
              grid(i,count)=wfvals.sign(0)*exp(cutoff);
            }
            //grid(i,count)=exp(2.0*wfvals(0,1));//!square of wavefunction
            if (grid(i,count)>max_value) max_value=grid(i,count);
            if (grid(i,count)<min_value) min_value=grid(i,count);
            //  cout << "grid " << grid(i,count)<< " " << xyz(0) << endl;
	    count++; //index for cycling through grid points
          }
        }
        cout.setf(ios::scientific| ios:: showpos);
        cout <<", max. value "<<max_value<<", min. value "<<min_value<< endl;
        cout.unsetf(ios::scientific| ios:: showpos);
        
      }
      mywalker->setElectronPos(plots(i)-1, oldpos(plots(i)-1));
    }
  
  
    //Loop through and generate plot files for each orbital requested
    if(plots.GetSize()<=0)
      error("Number of requested plots is not a positive number");
    cout<<"saving data for "<<plots.GetSize()<<" 3D projections of wavefunction"<<endl;
    for(int i=0; i<plots.GetSize(); i++)
      {
        //output to file with orbital number in it
        char strbuff[40];
        sprintf(strbuff, "%d", plots(i));
        confile=pltfile = options.runid;
        confile += ".orb.";
        pltfile += ".orb.";
        pltfile += strbuff;
        confile += strbuff;
        pltfile += ".cube"; /*FIGURE OUT HOW TO CONVERT INT TO STRING*/
        confile += ".xyz";
        
        os.open(pltfile.c_str());
        cout<<"writing to "<<pltfile<<endl;

        os << "QWalk nodes output\n";
        os << "Wavefunction single scan with " <<   plots(i) <<" electron"<<endl;
        int natoms=sysprop->nIons();
        os << "  " << natoms+ mywalker->electronSize()-1 << "   " << minmax(0) << "   "
          << minmax(2) << "   " << minmax(4) << endl;
        os << D_array1(0) << "   " << resolution_array(0) << "  0.0000   0.0000" << endl;
        os << D_array1(1) << "   0.0000   " << resolution_array(1) << "  0.0000" << endl;
        os << D_array1(2) << "   0.0000    0.0000    " << resolution_array(2) << endl;
        Array1 <doublevar> pos(3);
        for(int at=0; at< natoms; at++) {
          mywalker->getIonPos(at,pos);
          os << "   " << mywalker->getIonCharge(at) << "   0.0000    " << pos(0) 
            <<"    " << pos(1) << "   " << pos(2) << endl;
        }
        for(int j=0; j<mywalker->electronSize(); j++){
          if (j!=plots(i)-1){
            if (j<spin_up) os<<"     3   0.0000    ";
            else os<<"     3     0.0000    ";
            os<< oldpos(j,0)<<"   "<<oldpos(j,1)<<"   "<< oldpos(j,2)<<endl;
          }
        }
        os.setf(ios::scientific);
        for(int j=0; j< D_array1(0)*D_array1(1)*D_array1(2); j++) {
          os <<setw(16)<<setprecision(8)<<grid(i,j);
          if(j%6 ==5) os << endl;
        }
        os << endl;
        os.unsetf(ios::scientific);
        os<<setprecision(6);
        os.close();

	
        /*
	  old plt file plots
        // http://www.csc.fi/gopenmol/developers/plt_format.phtml
        os<<"3 "; //rank=3 always
        os<<"2\n"; //dummy variable => "Orbital/density surface"
        //number of grid points for x, y, & z direction
        os <<D_array1(2)<<" "<<D_array1(1)<<" "<<D_array1(0)<<endl;
        os <<minmax(4)<<" "<<minmax(5)<<" "<<minmax(2)<<" "<<minmax(3)
           <<" "<<minmax(0)<<" "<<minmax(1)<<endl;
        
        for(int j=0; j<(D_array1(0)*D_array1(1)*D_array1(2)); j++)
          os<<grid(i,j)<<endl;
        os.close();
        
        os.open(confile.c_str());
        cout<<"writing to "<<confile<<endl;
        Array1 <doublevar> pos(3);
        sysprop->getAtomicLabels(atomlabels);
        os<<atomlabels.size()+ mywalker->electronSize()-1 <<endl;
        os << endl;
        for(unsigned int j=0; j<atomlabels.size();j++){
          mywalker->getIonPos(j, pos);
          os<<atomlabels[j] <<" "<< pos(0)
            <<" "<<pos(1)
            <<" "<< pos(2)<<endl;
        }
        for(int j=0; j<mywalker->electronSize(); j++){
          if (j!=plots(i)-1){
            if (j<spin_up) os<<"Eu";
            else os<<"Ed";
            // mywalker->getElectronPos(j, pos);
            os<<" "<< oldpos(j,0)<<" "<<oldpos(j,1)
              <<" "<< oldpos(j,2)<<endl;
          }
        }
        os.close();   
	*/
	
      }
    
  }
  else {
    cout << "Using translation vector(s): "<<endl;
    for(int i=0;i<dxyz.GetDim(0);i++)    
      cout<<"( "<<dxyz(i,0)<<" , "<<dxyz(i,1)<<" , "<<dxyz(i,2)<<" )"<<endl;

    for(int i=0; i<plots.GetSize(); i=i+2){
      count=0;
      xyz(0)=minmax(0);
      xyz(1)=minmax(2);
      xyz(2)=minmax(4); //init elec probe to xmin ymin zmin
      //Array1 <doublevar> oldpos(3)
      cout.width(3);
      cout <<"============================="<<plots(i)<<" and "<<plots(i+1)
           <<"=============================="
           <<endl;
      for(int xx=0; xx<D_array1(0);xx++){
        max_value=min_value=0.0;
        xyz(0)=minmax(0)+xx*resolution_array(0); 
        xyz2(0)=xyz(0)+dxyz(i/2,0);  
        cout << "x ";
        cout.precision(5);
        cout.width(8);
        cout<< xyz(0);
        for(int yy=0; yy<D_array1(1);yy++){
          xyz(1)=minmax(2)+yy*resolution_array(1); 
          xyz2(1)=xyz(1)+dxyz(i/2,1);
          for(int zz=0;zz<D_array1(2);zz++){
            xyz(2)=minmax(4)+zz*resolution_array(2); 
            xyz2(2)=xyz(2)+dxyz(i/2,2);
            // mywalker->getElectronPos(plots(i), oldpos);
            mywalker->setElectronPos(plots(i)-1,xyz);//move elec#plots(i) 
            //to point specified by xyz
            mywalker->setElectronPos(plots(i+1)-1,xyz2);//move elec#plots(i) 
            //to point specified by xyz
            wf->updateVal(wfdata, mywalker); //update wfdata
            wf->getVal(wfdata, 0, wfvals); //get wf value
            grid(i,count)=wfvals.sign(0)*exp(wfvals.amp(0,0));
            //grid(i,count)=exp(2.0*wfvals(0,1));//!square of wavefunction
            //  cout << "grid " << grid(i,count)<< " " << xyz(0) << endl;
            if (grid(i,count)>max_value) max_value=grid(i,count);
            if (grid(i,count)<min_value) min_value=grid(i,count);
            
            count++; //index for cycling through grid points
          }
        }
        cout.setf(ios::scientific| ios:: showpos);
        cout <<", max. value "<<max_value<<", min. value "<<min_value<< endl;
        cout.unsetf(ios::scientific| ios:: showpos);
      }
      
      mywalker->setElectronPos(plots(i)-1, oldpos(plots(i)-1));
      mywalker->setElectronPos(plots(i+1)-1, oldpos(plots(i+1)-1)); 
    }
    
    //Loop through and generate plot files for each orbital requested
    if(plots.GetSize()<=0)
      error("Number of requested plots is not a positive number");
    cout<<"saving data for "<<plots.GetSize()<<" 3D projections of wavefunction"<<endl;
    for(int i=0; i<plots.GetSize(); i=i+2)
      {
        char strbuff2[40],strbuff[40];
        //output to file with orbital number in it
        sprintf(strbuff, "%d", plots(i));
        sprintf(strbuff2, "%d", plots(i+1));
        confile=pltfile = options.runid;
        confile += ".orb.";
        pltfile += ".orb.";
        pltfile += strbuff;
        confile += strbuff;
        pltfile += "with";
        confile += "with";
        pltfile += strbuff2;
        confile += strbuff2;
        
        pltfile += ".cube"; /*FIGURE OUT HOW TO CONVERT INT TO STRING*/
        confile += ".xyz";
        
        os.open(pltfile.c_str());
        cout<<"writing to "<<pltfile<<endl;
	os << "GOS nodes output\n";
	os << "Wave function double scan with "<<   plots(i) <<" & "<<plots(i+1)<<" electrons"<< endl;
        int natoms=sysprop->nIons();
        os << "  " << natoms + mywalker->electronSize()-2 << "   " << minmax(0) << "   "
           << minmax(2) << "   " << minmax(4) << endl;
        os << D_array1(0) << "   " << resolution_array(0) << "  0.0000   0.0000" << endl;
        os << D_array1(1) << "   0.0000   " << resolution_array(1) << "  0.0000" << endl;
        os << D_array1(2) << "   0.0000    0.0000    " << resolution_array(2) << endl;
        Array1 <doublevar> pos(3);
        for(int at=0; at< natoms; at++) {
          mywalker->getIonPos(at,pos);
          os << "   " << mywalker->getIonCharge(at) << "   0.0000    " << pos(0) 
             <<"    " << pos(1) << "   " << pos(2) << endl;
        }
        for(int j=0; j<mywalker->electronSize(); j++){
          if ((j!=plots(i)-1)&&(j!=plots(i+1)-1)){
            if (j<spin_up) os<<"    3    0.0000    ";
            else os<<"    3    0.0000   ";
            os<< oldpos(j,0)<<"    "<<oldpos(j,1)<<"    "<< oldpos(j,2)<<endl;
          }
        }
	os.setf(ios::scientific);
        for(int j=0; j< D_array1(0)*D_array1(1)*D_array1(2); j++) {
          os << setw(16) << setprecision(8) << grid(i,j);
          if(j%6 ==5) os << endl;
        }
        os << endl;
	os.unsetf(ios::scientific);
	os<<setprecision(6);
        os.close();

        /*
          old plot to plt file version
        // http://www.csc.fi/gopenmol/developers/plt_format.phtml
        os<<"3 "; //rank=3 always
        os<<"2\n"; //dummy variable => "Orbital/density surface"
        //number of grid points for x, y, & z direction
        os <<D_array1(2)<<" "<<D_array1(1)<<" "<<D_array1(0)<<endl;
        os <<minmax(4)<<" "<<minmax(5)<<" "<<minmax(2)<<" "<<minmax(3)
           <<" "<<minmax(0)<<" "<<minmax(1)<<endl;
        
        for(int j=0; j<(D_array1(0)*D_array1(1)*D_array1(2)); j++)
          os<<grid(i,j)<<endl;
        os.close();
        
        os.open(confile.c_str());
        cout<<"writing to "<<confile<<endl;
        Array1 <doublevar> pos(3);
        sysprop->getAtomicLabels(atomlabels);
        os<<atomlabels.size()+ mywalker->electronSize()-2 <<endl;
        os << endl;
        for(unsigned int j=0; j<atomlabels.size();j++){
          mywalker->getIonPos(j, pos);
          os<<atomlabels[j] <<" "<< pos(0)
            <<" "<<pos(1)
            <<" "<< pos(2)<<endl;
        }
        for(int j=0; j<mywalker->electronSize(); j++){
          if ((j!=plots(i)-1)&&(j!=plots(i+1)-1)){
            if (j<spin_up) os<<"Eu";
            else os<<"Ed";
            // mywalker->getElectronPos(j, pos);
            os<<" "<< oldpos(j,0)<<" "<<oldpos(j,1)
              <<" "<< oldpos(j,2)<<endl;
          }
        }
        os.close();    
        */
    
      } 
  }
  cout <<"End of Nodes Method"<<endl;  
}
Example #16
0
int main(int argc, char* argv[]) {

  TH1::SetDefaultSumw2();

  ProgramOptions options(argc, argv);

  double lumi = options.lumi;

  // input datasets
  Datasets datasets(options.iDir);
  datasets.readFile(options.datasetFile);

  std::string oDir_Plot = options.oDir+std::string("/QCDBackground");
  
  boost::filesystem::path opath(oDir_Plot);
  if (!exists(opath)) {
    std::cout << "Creating output directory : " << oDir_Plot << std::endl;
    boost::filesystem::create_directory(opath);
  }

  // output file
  TFile* ofile = TFile::Open( (options.oDir+std::string("/QCDBackground.root")).c_str(), "RECREATE");

  // cuts
  Cuts cuts;
  TCut puWeight("puWeight");
  TCut trigCorr( "(trigCorrWeight>0.) ? trigCorrWeight : 1." );
 
  // histograms
  double dphiEdges[4] = { 0., 1.0, 2.6, TMath::Pi() };
  double metEdges[14] = { 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100., 110., 120., 10000. };

  TH2D* hQCD_BG_METDPhi = new TH2D("hQCD_BG_METDPhi", "", 3, dphiEdges, 13, metEdges);  // BG in NoMET region
  TH1D* hQCD_BG_Tight_DPhi = new TH1D("hQCD_BG_Tight_DPhi", "", 3, dphiEdges);  // BG in tight region

  TH2D* hQCD_WTau_METDPhi = new TH2D("hQCD_WTau_METDPhi", "", 3, dphiEdges, 13, metEdges);  // BG in NoMET region
  TH1D* hQCD_WTau_Tight_DPhi = new TH1D("hQCD_WTau_Tight_DPhi", "", 3, dphiEdges);  // BG in tight region

  TH2D* hQCD_TTBar_METDPhi = new TH2D("hQCD_TTBar_METDPhi", "", 3, dphiEdges, 13, metEdges);  // BG in NoMET region
  TH1D* hQCD_TTBar_Tight_DPhi = new TH1D("hQCD_TTBar_Tight_DPhi", "", 3, dphiEdges);  // BG in tight region

  TH2D* hQCD_SingleTSum_METDPhi = new TH2D("hQCD_SingleTSum_METDPhi", "", 3, dphiEdges, 13, metEdges);  // BG in NoMET region
  TH1D* hQCD_SingleTSum_Tight_DPhi = new TH1D("hQCD_SingleTSum_Tight_DPhi", "", 3, dphiEdges);  // BG in tight region

  TH2D* hQCD_DY_METDPhi = new TH2D("hQCD_DY_METDPhi", "", 3, dphiEdges, 13, metEdges);  // BG in NoMET region
  TH1D* hQCD_DY_Tight_DPhi = new TH1D("hQCD_DY_Tight_DPhi", "", 3, dphiEdges);  // BG in tight region

  TH2D* hQCD_Diboson_METDPhi = new TH2D("hQCD_Diboson_METDPhi", "", 3, dphiEdges, 13, metEdges);  // BG in NoMET region
  TH1D* hQCD_Diboson_Tight_DPhi = new TH1D("hQCD_Diboson_Tight_DPhi", "", 3, dphiEdges);  // BG in tight region

  TH2D* hQCD_Data_METDPhi = new TH2D("hQCD_Data_METDPhi", "", 3, dphiEdges, 13, metEdges);  // Data in NoMET region
  TH1D* hQCD_Data_Tight_DPhi = new TH1D("hQCD_Data_Tight_DPhi", "", 3, dphiEdges);  // Data in tight region

  // loop over MC datasets
  for (unsigned i=0; i<datasets.size(); ++i) {

    Dataset dataset = datasets.getDataset(i);

    TCut cutD = cuts.cutDataset(dataset.name);
    
    // check if it's ZToNuNuJets
    bool isZvv = false;

    if (dataset.isData) {
      std::cout << "Analysing Data         : " << dataset.name << std::endl;
    }
    else if (dataset.name.compare(0,3,"Zvv")==0) {
      isZvv = true;
      std::cout << "Analysing Zvv MC       : " << dataset.name << std::endl;
    }
    else {
      std::cout << "Analysing BG MC        : " << dataset.name << std::endl;
    }

    // get file & tree
    TFile* file = datasets.getTFile(dataset.name);
    TTree* tree = (TTree*) file->Get("invHiggsInfo/InvHiggsInfo");

    // cuts
    TCut cutQCDNoMET = puWeight * trigCorr * cuts.qcdNoMET();
    TCut cutQCDTightHiDPhi = puWeight * trigCorr * cuts.qcdTightHiDPhi();
    
    TCut cutWQCDNoMET = puWeight * trigCorr * cuts.wWeight() * (cuts.wTauGen() + cuts.qcdNoMET());
    TCut cutWQCDTightHiDPhi = puWeight * trigCorr * cuts.wWeight() * (cuts.wTauGen() + cuts.qcdTightHiDPhi());

    // fill tmp histograms for BG estimation
    TH2D* hQCD_METDPhi  = new TH2D("hQCD_METDPhi", "", 3, dphiEdges, 13, metEdges);  // 
    TH1D* hQCD_Tight_DPhi  = new TH1D("hQCD_Tight_DPhi", "", 3, dphiEdges);  // this is for the actual BG estimation

    if (dataset.name=="WJets" ||
	dataset.name=="W1Jets" ||
	dataset.name=="W2Jets" ||
	dataset.name=="W3Jets" ||
	dataset.name=="W4Jets") {
      tree->Draw("met:vbfDPhi>>hQCD_METDPhi", cutWQCDNoMET);
      tree->Draw("vbfDPhi>>hQCD_Tight_DPhi", cutWQCDTightHiDPhi);
    }
    else {
      tree->Draw("met:vbfDPhi>>hQCD_METDPhi", cutQCDNoMET);
      tree->Draw("vbfDPhi>>hQCD_Tight_DPhi", cutQCDTightHiDPhi);
    }

    // weight  to lumi
    double weight = (dataset.isData ? 1. : lumi * dataset.sigma / dataset.nEvents);

    hQCD_METDPhi->Scale(weight);
    hQCD_Tight_DPhi->Scale(weight);

    // add to output histograms
    if (dataset.isData) {
      hQCD_Data_METDPhi->Add(hQCD_METDPhi);
      hQCD_Data_Tight_DPhi->Add(hQCD_Tight_DPhi);
    }
    else {
      if (!isZvv) hQCD_BG_Tight_DPhi->Add(hQCD_Tight_DPhi); // do not include Z->vv samples we use data-driven number
      hQCD_BG_METDPhi->Add(hQCD_METDPhi);
    }

    if (dataset.name=="WJets" ||
	dataset.name=="W1Jets" ||
	dataset.name=="W2Jets" ||
	dataset.name=="W3Jets" ||
	dataset.name=="W4Jets" ) {
      hQCD_WTau_METDPhi->Add(hQCD_METDPhi);
      hQCD_WTau_Tight_DPhi->Add(hQCD_Tight_DPhi);
    }

    if (dataset.name=="TTBar") {
      hQCD_TTBar_METDPhi->Add(hQCD_METDPhi);
      hQCD_TTBar_Tight_DPhi->Add(hQCD_Tight_DPhi);
    }

    if (dataset.name.compare(0,7,"SingleT")==0) {
      hQCD_SingleTSum_METDPhi->Add(hQCD_METDPhi);
      hQCD_SingleTSum_Tight_DPhi->Add(hQCD_Tight_DPhi);
    }

    if (dataset.name.compare(0,2,"DY")==0) {
      hQCD_DY_METDPhi->Add(hQCD_METDPhi);
      hQCD_DY_Tight_DPhi->Add(hQCD_Tight_DPhi);
    }

    if (dataset.name == "WW" ||
	dataset.name == "WZ" ||
	dataset.name == "ZZ") {
      hQCD_Diboson_METDPhi->Add(hQCD_METDPhi);
      hQCD_Diboson_Tight_DPhi->Add(hQCD_Tight_DPhi);
    }     

    std::cout << "  N (met>130, dphi>2.6) : " << hQCD_Tight_DPhi->GetBinContent(3) << std::endl;

    delete hQCD_METDPhi;
    delete hQCD_Tight_DPhi;

    // QCD Figure 13 in AN
    TCut cutPlots("");

    if (dataset.name == "WJets"  ||
        dataset.name == "W1Jets" ||
        dataset.name == "W2Jets" ||
        dataset.name == "W3Jets" ||
        dataset.name == "W4Jets") {
		cutPlots = puWeight * trigCorr * cuts.wWeight() * (cuts.HLTandMETFilters() + cuts.leptonVeto() + cuts.vbf());  //no MET and dPhijj
    }
    else 	cutPlots = puWeight * trigCorr * (cuts.HLTandMETFilters() + cuts.leptonVeto() + cuts.vbf());  //no MET and dPhijj

    TFile* ofile_Plot = TFile::Open( (oDir_Plot+std::string("/")+dataset.name+std::string(".root")).c_str(), "RECREATE");

    TH1D* QCD_DPhijj 	= new TH1D("QCD_DPhijj",    "", 50, 0.,  TMath::Pi());
    TH1D* QCD_MET	= new TH1D("QCD_MET",       "", 50, 0.,  1000.);

    tree->Draw("vbfDPhi>>QCD_DPhijj"	, cutPlots);
    tree->Draw("met>>QCD_MET"		, cutPlots);

    if (!dataset.isData) {
    QCD_DPhijj->Scale(weight);
    QCD_MET->Scale(weight);
    }

    ofile_Plot->cd();

    QCD_DPhijj->Write("",TObject::kOverwrite);
    QCD_MET->Write("",TObject::kOverwrite);

    ofile_Plot->Close();

    // clean up
    delete tree;
    file->Close();
   
  }

  // get data-driven background estimates
  std::cout << "Reading Z backgrounds from : " << options.oDir+std::string("/ZBackground.root") << std::endl;
  TFile* zfile = TFile::Open( (options.oDir+std::string("/ZBackground.root")).c_str(), "READ");
  TH2D* hQCD_Z_METDPhi  = (TH2D*) zfile->Get("hZ_Est_S_METDPhi");
  TH1D* hQCD_Z_Tight_DPhi  = (TH1D*) zfile->Get("hZ_Est_S_DPhi");

  if (hQCD_Z_Tight_DPhi == 0) {
    std::cerr << "Could not read Z background histogram" << std::endl;
    std::exit(1);
  }

  std::cout << "  N (met>130, dphi>2.6) : " << hQCD_Z_Tight_DPhi->GetBinContent(3) << std::endl;
  std::cout << std::endl;
  
  std::cout << "Reading W backgrounds from : " << options.oDir+std::string("/WBackground.root") << std::endl;
  TFile* wfile = TFile::Open( (options.oDir+std::string("/WBackground.root")).c_str(), "READ");
  TH2D* hQCD_W_METDPhi  = (TH2D*) wfile->Get("hW_Est_S_METDPhi");
  TH1D* hQCD_W_Tight_DPhi  = (TH1D*) wfile->Get("hW_Est_S_DPhi");

  if (hQCD_W_Tight_DPhi == 0) {
    std::cerr << "Could not read W background histogram" << std::endl;
    std::exit(1);
  }  

  std::cout << "  N (met>130, dphi>2.6) : " << hQCD_W_Tight_DPhi->GetBinContent(3) << std::endl;
  std::cout << std::endl;
  

  // create output histograms
  TH2D* hQCD_Est_METDPhi  = new TH2D("hQCD_Est_METDPhi", "", 3, dphiEdges, 13, metEdges);
  TH1D* hQCD_Est_S_DPhi      = new TH1D("hQCD_Est_S_DPhi",     "", 3, dphiEdges);

  // do the background estimation
  hQCD_Est_METDPhi->Add(hQCD_Data_METDPhi, hQCD_BG_METDPhi, 1., -1.);
  hQCD_Est_S_DPhi->Add(hQCD_Data_Tight_DPhi, hQCD_BG_Tight_DPhi, 1., -1.);

  //  hQCD_Est_METDPhi->Add(hQCD_Z_METDPhi, -1.);
  hQCD_Est_S_DPhi->Add(hQCD_Z_Tight_DPhi, -1.);

  //  hQCD_Est_METDPhi->Add(hQCD_W_METDPhi, -1.);

  hQCD_Est_S_DPhi->Add(hQCD_W_Tight_DPhi, -1.);

  // calculate ratios
//   double rNoMET      = hQCD_Est_METDPhi->GetBinContent(1) / hQCD_Est_METDPhi->GetBinContent(3);
//   double err_rNoMET  = rNoMET * sqrt(pow(hQCD_Est_METDPhi->GetBinError(1)/hQCD_Est_METDPhi->GetBinContent(1),2) + pow(hQCD_Est_METDPhi->GetBinError(3)/hQCD_Est_METDPhi->GetBinContent(3),2));
//   double rLoose2     = hQCD_Est_Loose2_DPhi->GetBinContent(1) / hQCD_Est_Loose2_DPhi->GetBinContent(3);
//   double err_rLoose2 = rLoose2 * sqrt(pow(hQCD_Est_Loose2_DPhi->GetBinError(1)/hQCD_Est_Loose2_DPhi->GetBinContent(1),2) + pow(hQCD_Est_Loose2_DPhi->GetBinError(3)/hQCD_Est_Loose2_DPhi->GetBinContent(3),2));
//   double rLoose      = hQCD_Est_Loose_DPhi->GetBinContent(1) / hQCD_Est_Loose_DPhi->GetBinContent(3);
//   double err_rLoose  = rLoose * sqrt(pow(hQCD_Est_Loose_DPhi->GetBinError(1)/hQCD_Est_Loose_DPhi->GetBinContent(1),2) + pow(hQCD_Est_Loose_DPhi->GetBinError(3)/hQCD_Est_Loose_DPhi->GetBinContent(3),2));
  
//   // linear extrapolation using MET>80 and MET>100 bins
  double rTight = 0.0046;
  double err_rTight = 0.0046 * 1.5;

  // predict signal
  double nQCD_Est_S_HiDPhi = rTight * hQCD_Est_S_DPhi->GetBinContent(3);
  double err_nQCD_Est_S_HiDPhi = nQCD_Est_S_HiDPhi * sqrt(pow(err_rTight/rTight,2)+pow(hQCD_Est_S_DPhi->GetBinError(3)/hQCD_Est_S_DPhi->GetBinContent(3),2));

  // set bins in output histogram
  hQCD_Est_S_DPhi->SetBinContent(1, nQCD_Est_S_HiDPhi);
  hQCD_Est_S_DPhi->SetBinError(1, err_nQCD_Est_S_HiDPhi);

  // print results
  std::cout << std::endl;
  std::cout << "QCD Background estimate" << std::endl << std::endl;
  std::cout << std::endl;

  std::cout <<" Ratios" << std::endl;
//   std::cout << "   R(MET>80)   : " << rNoMET << " +/- " << err_rNoMET << std::endl;
//   std::cout << "   R(MET>90)   : " << rLoose2 << " +/- " << err_rLoose2 << std::endl;
//   std::cout << "   R(MET>100)   : " << rLoose << " +/- " << err_rLoose << std::endl;
//   std::cout << "   R(MET>130)  : " << rTight << " +/- " << err_rTight << std::endl;
//   std::cout << std::endl;

  std::cout << "Control region (MET>130, dphi>2.6)" << std::endl;
  std::cout << "   N data      : " << hQCD_Data_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_Data_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N Z (data)  : " << hQCD_Z_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_Z_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N W (data)  : " << hQCD_W_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_W_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N BG (MC)   : " << hQCD_BG_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_BG_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N WTau (MC)     : " << hQCD_WTau_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_WTau_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N TTbar (MC)    : " << hQCD_TTBar_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_TTBar_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N SingleT (MC)  : " << hQCD_SingleTSum_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_SingleTSum_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N DY (MC)       : " << hQCD_DY_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_DY_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N Diboson (MC)  : " << hQCD_Diboson_Tight_DPhi->GetBinContent(3) << " +/- " << hQCD_Diboson_Tight_DPhi->GetBinError(3) << std::endl;
  std::cout << "   N QCD (est) : " << hQCD_Est_S_DPhi->GetBinContent(3) << " +/- " << hQCD_Est_S_DPhi->GetBinError(3) << std::endl;
  std::cout << std::endl;
  std::cout << "Signal region (MET>130, dphi<1.0)" << std::endl;
  std::cout << "   N QCD (est): " << hQCD_Est_S_DPhi->GetBinContent(1) << " +/- " << hQCD_Est_S_DPhi->GetBinError(1) << std::endl;

  // list histograms for dataset summing
  std::vector<std::string> hists;
  hists.push_back("QCD_DPhijj");
  hists.push_back("QCD_MET");

  // sum Z+jets datasets
  std::vector<std::string> zjetsDatasets;
  zjetsDatasets.push_back(std::string("Zvv_50to100"));
  zjetsDatasets.push_back(std::string("Zvv_100to200"));
  zjetsDatasets.push_back(std::string("Zvv_200to400"));
  zjetsDatasets.push_back(std::string("Zvv_400toinf"));
  SumDatasets(oDir_Plot, zjetsDatasets, hists, "ZJets");

  // sum W+jets datasets
  std::vector<std::string> wjetsDatasets;
  wjetsDatasets.push_back(std::string("WJets"));
  wjetsDatasets.push_back(std::string("W1Jets"));
  wjetsDatasets.push_back(std::string("W2Jets"));
  wjetsDatasets.push_back(std::string("W3Jets"));
  wjetsDatasets.push_back(std::string("W4Jets"));
  SumDatasets(oDir_Plot, wjetsDatasets, hists, "WNJets");

  // sum single top datasets
  std::vector<std::string> topDatasets;
  topDatasets.push_back(std::string("SingleT_t"));
  topDatasets.push_back(std::string("SingleTbar_t"));
  topDatasets.push_back(std::string("SingleT_s"));
  topDatasets.push_back(std::string("SingleTbar_s"));
  topDatasets.push_back(std::string("SingleT_tW"));
  topDatasets.push_back(std::string("SingleTbar_tW"));
  topDatasets.push_back(std::string("TTBar"));
  SumDatasets(oDir_Plot, topDatasets, hists, "SingleT+TTbar");

  // sum DY contributions
  std::cout << "Summing histograms for DYJetsToLL" << std::endl;
  std::vector<std::string> dyjets;
  dyjets.push_back("DYJetsToLL");
  dyjets.push_back("DYJetsToLL_EWK");
  SumDatasets(oDir_Plot,dyjets,hists,"DYJets");

  // sum diboson datasets
  std::vector<std::string> dibDatasets;
  dibDatasets.push_back(std::string("WW"));
  dibDatasets.push_back(std::string("WZ"));
  dibDatasets.push_back(std::string("ZZ"));
  SumDatasets(oDir_Plot, dibDatasets, hists, "DiBoson");

  // make plots
  std::cout << "Making plots" << std::endl;
  StackPlot plots(oDir_Plot);
  plots.setLegPos(0.66,0.60,0.89,0.89);

  plots.addDataset("DiBoson", kViolet-6, 0);
  plots.addDataset("DYJets", kPink-4,0);
  plots.addDataset("SingleT+TTbar", kAzure-2, 0);
  plots.addDataset("ZJets", kOrange-2, 0);
  plots.addDataset("WNJets", kGreen-3, 0);
  plots.addDataset("METABCD",    kBlack, 1);

  plots.setYMax(1e+8); 
  plots.draw("QCD_DPhijj",	"#Delta #phi_{jj}",	"N_{events}"    ,1,"RATIO");
  plots.draw("QCD_MET",		"E_{T}^{miss} [GeV]",	"N_{events}"    ,1,"RATIO");

  // write out histograms
  ofile->cd();
  hQCD_Data_METDPhi->Write("", TObject::kOverwrite);
  hQCD_Data_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_BG_METDPhi->Write("", TObject::kOverwrite);
  hQCD_BG_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_Z_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_W_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_WTau_METDPhi->Write("", TObject::kOverwrite);
  hQCD_WTau_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_TTBar_METDPhi->Write("", TObject::kOverwrite);
  hQCD_TTBar_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_SingleTSum_METDPhi->Write("", TObject::kOverwrite);
  hQCD_SingleTSum_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_DY_METDPhi->Write("", TObject::kOverwrite);
  hQCD_DY_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_Diboson_METDPhi->Write("", TObject::kOverwrite);
  hQCD_Diboson_Tight_DPhi->Write("", TObject::kOverwrite);
  hQCD_Est_METDPhi->Write("", TObject::kOverwrite);
  hQCD_Est_S_DPhi->Write("", TObject::kOverwrite);

  // clean up
  ofile->Close();

}
Example #17
0
void massPlot(double lumi=-1., double maxInstLumi=-1.) {

  setTDRStyle();
  //tdrGrid(false, tdrStyle);

  writeExtraText = true;
  //extraText  = "Preliminary Simulation"; 
  //lumi_8TeV = ""; 
  int iPeriod = 2; // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV 
  //int iPos=0;
  int iPos=11;
  //int iPos=22;
	
  if (lumi<0)
    lumi=LUMI;
  if (maxInstLumi<0)
    maxInstLumi=MAXINSTLUMI;
  DifferentXSLimitPlots plots(lumi);

  //mchamp index 0 is used, corresponds to 0th mass point = 100 GeV
  plots.calculateCrossSections(0,0,0,39,9);
    
  // three points on counting expt curve
  //TGraph* g_obs_gluino = plots.getMassLimitGluino();
  TGraph* g_gluino = plots.getExpMassLimitGluino();

  //TGraph* g_obs_stop = plots.getMassLimitStop();
  TGraph* g_stop = plots.getExpMassLimitStop();

  TGraph* g_obs_mchamp = plots.getMassLimitMchamp();
  TGraph* g_mchamp = plots.getExpMassLimitMchamp();

  //TGraphAsymmErrors* g_expGluino_1sig = plots.getExpMassLimitGluino1Sig();  
  //TGraphAsymmErrors* g_expGluino_2sig = plots.getExpMassLimitGluino2Sig();  

  //TGraphAsymmErrors* g_expStop_1sig = plots.getExpMassLimitStop1Sig();  
  //TGraphAsymmErrors* g_expStop_2sig = plots.getExpMassLimitStop2Sig();  

  TGraphAsymmErrors* g_exp_1sig = plots.getExpMassLimitMchamp1Sig();  
  TGraphAsymmErrors* g_exp_2sig = plots.getExpMassLimitMchamp2Sig();  

  // one point from lifetime fit
  TGraph* g_tpg = plots.getMassLimitGluinoTP();
  TGraph* g_tps = plots.getMassLimitStopTP();
  
  // theory prediction
  TGraph* g_thGluino = plots.getGluinoTheory();
  TGraph* g_thStop = plots.getStopTheory();
  TGraph* g_thMchamp = plots.getMchampTheory();
  
  TCanvas* canvas = new TCanvas("canvas","",10,10,575,500);

  Double_t x[10], yMinus[10], x2[10], y[10], yPlus[10], z[10];
  cout<<"MCHAMP LIMITS ARE: "<<endl;
  for(Int_t i=0; i<g_mchamp->GetN(); i++){
    g_mchamp->GetPoint(i, x[i], y[i]);
    yPlus[i] = g_exp_1sig->GetErrorYhigh(i);
    yMinus[i] = g_exp_1sig->GetErrorYlow(i);
    g_obs_mchamp->GetPoint(i, x2[i], z[i]);
    cout<<" mass is: "<<x[i]<<", expected limit is: "<<y[i]<<", expected +1 sigma is: "<<yPlus[i]<<", expected -1 sigma is: "<<yMinus[i]<<", observed limit is: "<<z[i]<<endl;
  }

  //canvas->SetGrid();
  canvas->SetLogy();
  
  TH1 * h;
  //h = canvas->DrawFrame(100., 1e-5, 1500., 1e6); //2DSA gluios and stops
  h = canvas->DrawFrame(100., 1e-5, 1000., 1e3); //2DSA
  //h = canvas->DrawFrame(100., 1e-5, 1000., 1e4); //1DSA
  //h->SetTitle(";m [GeV];#sigma [pb]");
  h->SetTitle(";m_{mchamp} [GeV];#sigma(pp #rightarrow mchamp mchamp) [pb]");
  //h->SetTitle(";m_{mchamp} [GeV];#sigma(pp #rightarrow mch mch) #times BF(mch #rightarrow #mu#mu)  [pb]");
  //h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) [pb]");
  
  // not covered region
  TBox* nc = new TBox(100., .1, 150., 5e2);
  nc->SetFillStyle(3354);
  nc->SetFillColor(kRed-4);
  //nc->Draw();
  
  /*
  // details
  //TPaveText* blurb = new TPaveText(305., 1.e1, 550., 4.5e2);
  TPaveText* blurb = new TPaveText(0.25, 0.70, 0.50, 0.92, "NDC");
  blurb->AddText("CMS Preliminary 2012");
  
  std::stringstream label;
  label<<"#int L dt = 19.7 fb^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10.;
    ++exponent;
  }
  //label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  //blurb->AddText(label.str().c_str());
  //label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  //blurb->AddText("m_{#tilde{g}} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{t}} - m_{#tilde{#chi}^{0}} = 180 GeV/c^{2}");	
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  */
  
  // legend
  TBox *legbg = new TBox(600., 1.e1, 900., 4e2);
  //legbg->Draw();
  //TLegend *leg = new TLegend(600., 1.e1, 900., 4e2,"95% C.L. Limits","");
  //TLegend* leg = new TLegend(0.67, 0.70, 0.82, 0.92,"95% CL Limits:","NDC");
  /////////TLegend* leg = new TLegend(0.52, 0.70, 0.77, 0.92,"95% CL Limits:","NDC");
  TLegend* leg = new TLegend(0.45, 0.70, 0.70, 0.92,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);

  leg->AddEntry(g_obs_mchamp, "Observed, 10 #mus - 1000 s", "lp");
  leg->AddEntry(g_mchamp, "Expected, 10 #mus - 1000 s", "l");
  leg->AddEntry(g_exp_1sig, "Expected #pm1#sigma, 10 #mus - 1000 s", "lf");
  leg->AddEntry(g_exp_2sig, "Expected #pm2#sigma, 10 #mus - 1000 s", "lf");
  leg->AddEntry(g_thMchamp, "LO Prediction", "l");
  /*
  leg->AddEntry(g_gluino, "Expected Gluino Limit, 10 #mus - 1000 s", "l");
  leg->AddEntry(g_thGluino, "Gluino LO Prediction", "l");
  leg->AddEntry(g_stop, "Expected Stop Limit, 10 #mus - 1000 s", "l");
  leg->AddEntry(g_thStop, "Stop LO Prediction", "l");
  */
  //leg->AddEntry(g_thGluino, "NLO+NLL #tilde{g}", "l");
  //leg->AddEntry(g_gluino, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{g})", "l");
  //leg->AddEntry(g_tpg, "Obs.: 10 #mus Timing Profile (#tilde{g})", "l");
  //leg->AddEntry(g_thStop, "NLO+NLL #tilde{t}", "l");
  //leg->AddEntry(g_stop, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(g_tps, "Obs.: 10 #mus Timing Profile (#tilde{t})", "l");
  //leg->AddEntry(graph_em, "Obs.: 10 #mus - 1000 s Counting Exp. (EM only)", "l");
  //  leg->AddEntry(graph1, "Obs.: 570 ns Counting Exp.", "l");
  leg->Draw();
  
  
  
  /*
  // gluino curves
  g_gluino->SetLineColor(kBlue);
  g_gluino->SetLineStyle(2);
  g_gluino->SetLineWidth(3);
  g_gluino->Draw("l");

  g_tpg->SetLineColor(kBlue);
  g_tpg->SetLineStyle(3);
  g_tpg->SetLineWidth(3);
  //g_tpg->Draw("l");

  // theory line
  g_thGluino->SetLineColor(kGreen);
  g_thGluino->SetLineStyle(1);
  g_thGluino->SetLineWidth(2);
  g_thGluino->SetFillStyle(3001);
  g_thGluino->SetFillColor(kGreen-4);
  g_thGluino->Draw("l3");


  
   // stop curves
  g_stop->SetLineColor(kRed);
  g_stop->SetLineStyle(2);
  g_stop->SetLineWidth(2);
  g_stop->Draw("l");

  g_tps->SetLineColor(kRed);
  g_tps->SetLineStyle(3);
  g_tps->SetLineWidth(3);
  //g_tps->Draw("l");
   
  g_thStop->SetLineColor(kOrange);
  g_thStop->SetLineStyle(1);
  g_thStop->SetLineWidth(2);
  g_thStop->SetFillStyle(3001);
  g_thStop->SetFillColor(kOrange-4);
  g_thStop->Draw("l3");
  */

  // mchamp curves
  // 2 sigma band
  g_exp_2sig->SetLineColor(0);
  g_exp_2sig->SetLineStyle(0);
  g_exp_2sig->SetLineWidth(0);
  g_exp_2sig->SetFillColor(kYellow);
  g_exp_2sig->SetFillStyle(1001);
  g_exp_2sig->Draw("3");

  // 1 sigma band 
  // g_exp_1sig->SetLineColor(8);                                                                                                                                                           
  g_exp_1sig->SetLineColor(0);
  g_exp_1sig->SetLineStyle(0);
  g_exp_1sig->SetLineWidth(0);
  // g_exp_1sig->SetFillColor(8);                                                                                                                                                           
  g_exp_1sig->SetFillColor(kGreen);
  g_exp_1sig->SetFillStyle(1001);
  // g_exp_1sig->SetFillStyle(3005);                                                                                                                                                        
  g_exp_1sig->Draw("3");
  // g_exp_1sig->Draw("lX");                                                                                                                                                                

  g_obs_mchamp->SetLineStyle(1);
  g_obs_mchamp->SetLineWidth(2);
  g_obs_mchamp->SetMarkerStyle(20);
  g_obs_mchamp->SetMarkerSize(1);
  g_obs_mchamp->Draw("pl");

  //g_mchamp->SetLineColor(kBlue);
  g_mchamp->SetLineStyle(2);
  //g_mchamp->SetLineStyle(1);
  g_mchamp->SetLineWidth(3);
  g_mchamp->SetMarkerStyle(20);
  g_mchamp->SetMarkerSize(1);
  g_mchamp->Draw("l");

  // theory line
  g_thMchamp->SetLineColor(kRed);
  g_thMchamp->SetLineStyle(1);
  g_thMchamp->SetLineWidth(2);
  g_thMchamp->SetFillStyle(3001);
  g_thMchamp->SetFillColor(kRed-4);
  g_thMchamp->Draw("l3");

  // theory line label
  TLatex* th = new TLatex(480., 4., "NLO+NLL #tilde{g}");
  th->SetTextColor(kBlue);
  th->SetTextFont(42);
  th->SetTextSize(0.035);
  //th->Draw();

  TLatex* ths = new TLatex(330., 2., "NLO+NLL #tilde{t}");
  ths->SetTextColor(kRed);
  ths->SetTextFont(42);
  ths->SetTextSize(0.035);
  //ths->Draw();

  TLatex* thm = new TLatex(480., 4., "NLO+NLL mchamp");
  //thm->SetTextColor(kBlue);
  thm->SetTextFont(42);
  thm->SetTextSize(0.035);
  //thm->Draw();

  // not explored label
  TText* ne = new TText(125., .2, "Not Sensitive");
  ne->SetTextColor(kRed+1);
  ne->SetTextFont(42);
  ne->SetTextAngle(90);
  ne->SetTextSize(0.035);
  //ne->Draw();

  //blurb->Draw();

  canvas->RedrawAxis();

  CMS_lumi(canvas, iPeriod, iPos);

  canvas->Print("massLimit.pdf");
  canvas->Print("massLimit.png");
  canvas->Print("massLimit.C");

  plots.calculateIntercepts();

  TFile* fnew = new TFile("histos.root", "recreate");
  fnew->cd();
  g_obs_mchamp->Write();
  g_mchamp->Write();
  g_thMchamp->Write();

}
Example #18
0
void allInOneLifetime(double lumi=4560., double maxInstLumi=5000.) {

  ExtraLimitPlots plots(lumi);
  plots.calculateCrossSections(4,6,3,39,9);
  
  // graphs - observed
  TGraph* g_obs      = plots.getObsLimit();
  TGraph* g_exp      = plots.getExpLimit();
  TGraphAsymmErrors* g_exp_1sig = plots.getExpLimit1Sig();
  TGraphAsymmErrors* g_exp_2sig = plots.getExpLimit2Sig();

  TGraph* g_obs_gluino = plots.getLimitGluino();
  double gluino2ref    = g_obs_gluino->GetY()[0] / g_obs->GetY()[0];
  TGraph* g_obs_stop   = plots.getLimitStop();
  double stop2ref      = g_obs_stop->GetY()[0] / g_obs->GetY()[0];
  TGraph* g_obs_stau   = plots.getLimitStau();
  double stau2ref      = g_obs_stau->GetY()[0] / g_obs->GetY()[0];

  cout << "scales: " << g_obs->GetY()[0] 
       << '/' <<g_obs_gluino->GetY()[0]
       << '/' <<g_obs_stop->GetY()[0]
       << '/' <<g_obs_stau->GetY()[0]
       <<endl;

  
  TCanvas *canvas = new TCanvas("allLifetime", "allLifetime", 1000, 600);
  
  canvas->SetLogx();
  canvas->SetLogy();

  canvas->SetRightMargin(0.8*canvas->GetLeftMargin());
  canvas->SetLeftMargin(1.2*canvas->GetLeftMargin());
  canvas->SetTicks (canvas->GetTickx(), 0);
  
  TH1F* h = new TH1F ("h", "", 1, 7.5e-8, 1e6);
  h->SetStats (0);
  h->SetMinimum (.0001);
  h->SetMaximum (0.99e1);
  // TH1* h = canvas->DrawFrame(7.5e-8, .001, 1e6, 1e2, "Y+");
  h->SetTitle("Beamgap Expt");
  //  h->GetXaxis()->SetTitle("#tau_{#tilde{g},#tilde{t},#tilde{#tau}} [s]");
  h->GetXaxis()->SetTitle("#tau [s]");
  h->GetYaxis()->SetTitle("#sigma #times BF #times #varepsilon_{stopping} #times #varepsilon_{reco}   [pb]  ");
  h->Draw ("Y+");

  ExtraAxis aGluino = anotherScale (h, gluino2ref, kRed+2, "#sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BF(#tilde{g} #rightarrow g#tilde{#chi}^{0})   [pb]  ", 0.0);

  ExtraAxis aStop = anotherScale (h, stop2ref, kBlue+2, "#sigma(pp #rightarrow #tilde{t}#tilde{t}) #times BF(#tilde{t} #rightarrow t#tilde{#chi}^{0})   [pb]  ", 0.2);

  ExtraAxis aStau = anotherScale (h, stau2ref, kGreen+2, "#sigma(pp #rightarrow #tilde{#tau}#tilde{#tau}) #times BF(#tilde{#tau} #rightarrow #tau#tilde{#chi}^{0})   [pb]  ", 0.4);


  
  
  TPaveText* blurb = new TPaveText(0.25, 0.57, 0.50, 0.87, "NDC");

  blurb->AddText("CMS Preliminary 2015");
  // std::stringstream label;
  // label<<"#int L dt = "<<lumi<<" pb^{-1}";
  // blurb->AddText(label.str().c_str());
  // double peakInstLumi=maxInstLumi;
  // int exponent=30;
  // while (peakInstLumi>10) {
  //   peakInstLumi/=10;
  //   ++exponent;
  // }
  // std::stringstream label2;
  // label2<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  // blurb->AddText(label2.str().c_str());

  //blurb->AddText("CMS 2011");
  blurb->AddText("#int L dt = 2.46 fb^{-1}");//,  #int L_{eff} dt = 935 pb^{-1}");
  //blurb->AddText("L^{max}_{inst} = 3.5 #times 10^{33} cm^{-2}s^{-1}");
  blurb->AddText("#sqrt{s} = 13 TeV");
  blurb->AddText("E_{g} > 120 GeV, E_{t} > 150 GeV");
  blurb->AddText("E_{jet} > 70 GeV");
  //blurb->AddText("m_{#tilde{g}} = 300 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  blurb->Draw();
  
  
  // 2 sigma band
  if (g_exp_2sig) {
    g_exp_2sig->SetLineColor(0);
    g_exp_2sig->SetLineStyle(0);
    g_exp_2sig->SetLineWidth(0);
    g_exp_2sig->SetFillColor(kYellow);
    g_exp_2sig->SetFillStyle(1001);
    g_exp_2sig->Draw("3");
  }
  
  // 1 sigma band
  if (g_exp_1sig) {
    // g_exp_1sig->SetLineColor(8);
    g_exp_1sig->SetLineColor(0);
    g_exp_1sig->SetLineStyle(0);
    g_exp_1sig->SetLineWidth(0);
    // g_exp_1sig->SetFillColor(8);
    g_exp_1sig->SetFillColor(kGreen);
    g_exp_1sig->SetFillStyle(1001);
    // g_exp_1sig->SetFillStyle(3005);
    g_exp_1sig->Draw("3");
    // g_exp_1sig->Draw("lX");
  }
  
  
  // GLUINO LIMIT
  if (g_exp) {
    g_exp->SetLineColor(1);
    g_exp->SetLineStyle(4);
    g_exp->SetLineWidth(2);
    g_exp->Draw("l3");
  }
  
  TLine *l;
  l = new TLine(7.5e-8, 1.49/gluino2ref, 1e6, 1.49/gluino2ref); //600 GeV
  l->SetLineColor(kRed);
  l->SetLineWidth(2);
  l->Draw();
  
  TLatex *t1;
  t1 = new TLatex(0.1, 0.7/gluino2ref, "#sigma_{theory} (m_{#tilde{g}} = 800 GeV)");
  t1->SetTextColor(kRed);
  t1->SetTextFont(42);
  t1->SetTextSize(0.035);
  t1->Draw();

  // STOP LIMIT
  TLine *ltop = new TLine(7.5e-8, 0.028/stop2ref, 1e6, 0.028/stop2ref); //600 GeV
  ltop->SetLineColor(kBlue);
  ltop->SetLineWidth(2);
  ltop->Draw();
  
  TLatex *t1top;
  t1top = new TLatex(0.1, 0.015/stop2ref, "#sigma_{theory} (m_{#tilde{t}} = 800 GeV)");
  t1top->SetTextColor(kBlue);
  t1top->SetTextFont(42);
  t1top->SetTextSize(0.035);
  t1top->Draw();
  

  // observed limit
  if (g_obs) {
    g_obs->SetLineColor(1);
    g_obs->SetLineStyle(1);
    g_obs->SetLineWidth(2);
    g_obs->Draw("l");
  }
  
  

  TLegend* leg = new TLegend(0.67, 0.65, 0.82, 0.87,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  TGraph* expectedStyle1 = new TGraph (*g_exp);
  expectedStyle1->SetFillColor (g_exp_1sig->GetFillColor());
  TGraph* expectedStyle2 = new TGraph (*g_exp);
  expectedStyle2->SetFillColor (g_exp_2sig->GetFillColor());
  cout << "colors: " << g_exp_1sig->GetFillColor() << ':' << g_exp_2sig->GetFillColor() << endl;
  leg->AddEntry(g_obs, "Observed", "l");
  leg->AddEntry(expectedStyle1, "Expected #pm1#sigma", "lf");
  leg->AddEntry(expectedStyle2, "Expected #pm2#sigma", "lf");
  //leg->AddEntry(g_obs_stop,"Obs.: Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(g_obs_nb, "Obs.: Counting Exp. (Neutral R-Baryon)", "l");
  //leg->AddEntry(g_obs_em, "Observed: Counting Exp. (EM only)", "l");
  //leg->AddEntry(g_obs_tp, "Observed: Timing Profile", "l");
  leg->Draw();

  h->Draw("sameaxis y+");
  aGluino.Draw();
  aStop.Draw();
  //aStau.Draw();

  canvas->Print("allInOneLifetime.png");
  canvas->Print("allInOneLifetime.pdf");
}