コード例 #1
0
ファイル: allInOneLifetime.C プロジェクト: allenji/StoppPtls
ExtraAxis anotherScale (const TH1* refHist, double scale, int color, const char* title, double offset) {
  ExtraAxis result;
  double x0 = refHist->GetXaxis()->GetXmin();
  double x1 = refHist->GetXaxis()->GetXmax();
  double y0 = refHist->GetMinimum();
  double y1 = refHist->GetMaximum();
  // double y0 = refHist->GetYaxis()->GetXmin();
  // double y1 = refHist->GetYaxis()->GetXmax();
  double xoffset = exp (log(x0) - (log(x1) - log(x0))*offset);

  TGaxis* axis = new TGaxis(xoffset, y0, xoffset, y1, y0*scale,y1*scale,510,"-GS");
  axis->ImportAxisAttributes (refHist->GetXaxis());
  axis->SetTitle(title);
  axis->SetTextColor (color);
  axis->SetLineColor (color);
  axis->SetLineWidth (1);
  axis->SetTextColor (color);
  axis->SetLabelColor (color);
  axis->SetLabelOffset (0.);
  axis->SetTitleOffset (0.65);
  axis->SetTickSize(0.015);	
  result.Add (axis);

  TLine* line = new TLine (xoffset, y0, xoffset, y1);
  line->SetLineColor (color);
  line->SetLineWidth (2);
  result.Add (line);

  line = new TLine (x0, y0, xoffset, y0);
  line->SetLineColor (kGray);
  line->SetLineWidth (2);
  result.Add (line);
  
  line = new TLine (x0, y1, xoffset, y1);
  line->SetLineColor (kGray);
  line->SetLineWidth (2);
  result.Add (line);

  return result;
}
コード例 #2
0
ファイル: evalFills.C プロジェクト: star-bnl/star-emc
//==========================================
//==========================================
void plotPair(TH1F *h1,TH1F *h0 ) {
  h1->Draw();

  // edit fonts/sizes
  TAxis *ax =h1->GetYaxis(); 
  float ss=ax->GetTitleSize();
  //printf("ss=%f\n",ss);
  ax->SetTitleSize(2*ss);
  ax->SetTitleOffset(0.5);
  ax =h1->GetXaxis(); 
 ax->SetTitleSize(1.5*ss);
 ax->SetLabelSize(1.5*ss);
 ax->SetTitleOffset(0.7);
 

  // edit fonts/sizes DONE



  gPad->Update();
  //scale hint1 to the pad coordinates
  Float_t rightmax = 1.1*h0->GetMaximum();
  Float_t scale = gPad->GetUymax()/rightmax;
  h0->Scale(scale);
  h0->Draw("same");
   
  //draw an axis on the right side
  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
	      gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"-R");
  int col=h0->GetLineColor();
  axis->SetLineColor(col);
  
  axis->SetTextColor(col);
  axis->SetLabelColor(col);
  axis ->SetTitle("LCP yield");
 axis->SetTitleSize(2*ss);
 axis->SetTitleOffset(.5);

  axis->Draw();
  
  
  TPaveStats *st =( TPaveStats *)gPad->GetPrimitive("stats");
  st->SetX1NDC(0.35);
  st->SetX2NDC(0.5);
  st->SetY1NDC(0.7);
  st->SetY2NDC(1.);
}
コード例 #3
0
ファイル: ntuAnalyzer.C プロジェクト: deguio/Analyzers
int ntuAnalyzer(std::string fileName)
{
  setGlobalStyle();
  
  //###############################
  //## run274200 ##
  unsigned int HT250Calo  = 9; //index of DST_HT250_CaloScouting_v   old:1 ref:9
  float HT250Calo_rate = 1928;

  unsigned int HT410PF = 7; //index of DST_HT410_PFScouting_v   old:3 ref:7
  float HT410PF_rate = 294;

  unsigned int MJJ200Calo = 12; //index of DST_DiCaloWideJetMass200_CaloScouting_v
  
  unsigned int HTT200 = 0; //index if L1_HTT200
  unsigned int HTT240 = 1; //index if L1_HTT240
  unsigned int HTT270 = 2; //index if L1_HTT270
  unsigned int HTT280 = 3; //index if L1_HTT280
  unsigned int DoubleJetC100 = 7; //index if L1_DoubleJetC100
  unsigned int DoubleJetC112 = 8; //index if L1_DoubleJetC112
  unsigned int DoubleIsoTau28er = 11; //index if L1_DoubleJetC112

  float instLumi = 0.4; //E34
  float targetLumi = 1; //E34
  float lumiScaleFactor = targetLumi/instLumi;

  float PDRate = 59300; //unprescaled rate of HLTPhysics accordingly to: https://cmswbm2.web.cern.ch/cmswbm2/cmsdb/servlet/DatasetSummary?RUN=274200 and prescale of 9000
  

  unsigned int L1scenario = HTT240;
  //###############################

  TChain* tt = new TChain("MyAnalysis/HLTree");
  tt->Add(fileName.c_str());

  //set branches
  TBranch* b_lumi;
  
  TBranch* b_caloMjj;
  TBranch* b_PFMjj;

  TBranch* b_hltAccept;
  TBranch* b_l1Accept;
  TBranch* b_l1Names;

  TBranch* b_caloJet1Pt;
  TBranch* b_caloJet2Pt;
  TBranch* b_caloJet1Eta;
  TBranch* b_caloJet2Eta;
  TBranch* b_caloDeltaEta;

  TBranch* b_PFJet1Pt;
  TBranch* b_PFJet2Pt;
  TBranch* b_PFJet1Eta;
  TBranch* b_PFJet2Eta;
  TBranch* b_PFDeltaEta;

  int lumi = 0;
  float caloMjj = 0;
  float PFMjj = 0;

  float caloJet1Pt_ = 0;
  float caloJet2Pt_ = 0;
  float caloJet1Eta_ = -999;
  float caloJet2Eta_ = -999;
  float caloDeltaEta_ = -999;

  float PFJet1Pt_ = 0;
  float PFJet2Pt_ = 0;
  float PFJet1Eta_ = -999;
  float PFJet2Eta_ = -999;
  float PFDeltaEta_ = -999;

  
  std::vector<int>* hltAccept = 0;
  std::vector<int>* l1Accept = 0;
  std::vector<string>* l1Names = 0;

  tt->SetBranchAddress("lumi", &lumi, &b_lumi);

  tt->SetBranchAddress("caloMjj", &caloMjj, &b_caloMjj);
  tt->SetBranchAddress("PFMjj", &PFMjj, &b_PFMjj);

  tt->SetBranchAddress("caloJet1Pt", &caloJet1Pt_, &b_caloJet1Pt);
  tt->SetBranchAddress("caloJet2Pt", &caloJet2Pt_, &b_caloJet2Pt);
  tt->SetBranchAddress("caloJet1Eta", &caloJet1Eta_, &b_caloJet1Eta);
  tt->SetBranchAddress("caloJet2Eta", &caloJet2Eta_, &b_caloJet2Eta);
  tt->SetBranchAddress("caloDeltaEta", &caloDeltaEta_, &b_caloDeltaEta);

  tt->SetBranchAddress("PFJet1Pt", &PFJet1Pt_, &b_PFJet1Pt);
  tt->SetBranchAddress("PFJet2Pt", &PFJet2Pt_, &b_PFJet2Pt);
  tt->SetBranchAddress("PFJet1Eta", &PFJet1Eta_, &b_PFJet1Eta);
  tt->SetBranchAddress("PFJet2Eta", &PFJet2Eta_, &b_PFJet2Eta);
  tt->SetBranchAddress("PFDeltaEta", &PFDeltaEta_, &b_PFDeltaEta);

  tt->SetBranchAddress("hltAccept", &hltAccept, &b_hltAccept);
  tt->SetBranchAddress("l1Accept", &l1Accept, &b_l1Accept);
  tt->SetBranchAddress("l1Names", &l1Names, &b_l1Names);

  int nentries = tt->GetEntries();
  std::cout << "Number of entries: " << nentries << std::endl;

  //book graphs and plots
  float min = 0.;
  float max = 1000.;
  int nBins = 20;

  TF1* f1 = new TF1("f1","[0]*TMath::Erf((x-[1])/[2])-[0]*TMath::Erf((-x-[1])/[2])",min,max);
  f1->SetParameters(0.5,350,40);  
  f1->FixParameter(0,0.5);
  f1->SetLineWidth(2.);
  f1->SetLineColor(kRed);

  TF1* f2 = (TF1*)f1->Clone("f2");
  f2->SetParameters(0.5,150,10);
  f2->SetLineColor(kBlack);

  TH1F* caloMjjSpectrum = new TH1F("caloMjjSpectrum","caloMjjSpectrum",nBins,min,max);
  TH1F* PFMjjSpectrum = new TH1F("PFMjjSpectrum","PFMjjSpectrum",nBins,min,max);
  
  TEfficiency* mjj450_eff = new TEfficiency("mjj450_eff","mjj450_eff",nBins,min,max);
  mjj450_eff->SetMarkerColor(kRed);
  mjj450_eff->SetLineColor(kRed);
  mjj450_eff->SetLineWidth(2);
  mjj450_eff->SetTitle("turnOn;Mjj [GeV]");
  TEfficiency* mjj200_eff = new TEfficiency("mjj200_eff","mjj200_eff",nBins,min,max);
  mjj200_eff->SetLineWidth(2);
  mjj200_eff->SetTitle("turnOn;Mjj [GeV]");
  TEfficiency* pf410_eff = new TEfficiency("pf410_eff","pf410_eff",nBins,min,max);
  pf410_eff->SetMarkerColor(kOrange+1);
  pf410_eff->SetLineColor(kOrange+1);
  TEfficiency* calo250_eff = new TEfficiency("calo250_eff","calo250_eff",nBins,min,max);
  calo250_eff->SetMarkerColor(kBlue);
  calo250_eff->SetLineColor(kBlue);
  TEfficiency* HTT240_eff = new TEfficiency("HTT240_eff","HTT240_eff",nBins,min,max);
  HTT240_eff->SetMarkerColor(kGreen+2);
  HTT240_eff->SetLineColor(kGreen+2);

  TH1F* l1 = new TH1F("l1","l1",14,0.,14.);
  TH1F* l2 = new TH1F("l2","l2",14,0.,14.);
  
  //loop
  for (Long64_t jentry=0; jentry<nentries;++jentry)
    {
      tt->GetEntry(jentry);

      //remove low rate lumis.
      //see: https://cmswbm2.web.cern.ch/cmswbm2/cmsdb/servlet/ChartHLTTriggerRates?RUNID=274200&PATHID=2043408&LSLENGTH=23.31040958&TRIGGER_PATH=DST_HT250_CaloScouting_v2
      //if(lumi > 539 && lumi < 553) continue;

      //l1 and hlt rates
      for(unsigned int ii=0; ii<l1Names->size(); ++ii)
	if (l1Accept->at(ii)==1)
	  l1->Fill(ii);
      
      
      //analysis cuts needed to compare to the analysis
      //calo analysis
      if (caloJet1Pt_ > 60. &&
	  caloJet2Pt_ > 30. &&
	  fabs(caloJet1Eta_) < 2.5 &&
	  fabs(caloJet2Eta_) < 2.5 &&
	  caloDeltaEta_ < 1.3)
	{
	  caloMjjSpectrum->Fill(caloMjj);
	  mjj200_eff->Fill((caloMjj>200 && l1Accept->at(L1scenario)==1) || hltAccept->at(HT250Calo)==1, caloMjj);
	  calo250_eff->Fill((hltAccept->at(HT250Calo)==1 && l1Accept->at(L1scenario)==1), caloMjj);

	  //references
	  HTT240_eff->Fill(l1Accept->at(HTT240)==1, caloMjj);
	  //l1 and hlt rates
	  for(unsigned int ii=0; ii<l1Names->size(); ++ii)
	    if (l1Accept->at(ii)==1)
	      l2->Fill(ii);
	}

      //PF analysis
      if (PFJet1Pt_ > 60. &&
	  PFJet2Pt_ > 30. &&
	  fabs(PFJet1Eta_) < 2.5 &&
	  fabs(PFJet2Eta_) < 2.5 &&
	  PFDeltaEta_ < 1.3)
	{
	  PFMjjSpectrum->Fill(PFMjj);
	  mjj450_eff->Fill((caloMjj>450 && l1Accept->at(L1scenario)==1) || hltAccept->at(HT410PF)==1, PFMjj);
	  pf410_eff->Fill((hltAccept->at(HT410PF)==1 && l1Accept->at(L1scenario)==1), PFMjj);
	}
    }

  mjj450_eff->Fit(f1,"r");
  mjj200_eff->Fit(f2,"r");


  caloMjjSpectrum->Scale(1./caloMjjSpectrum->GetBinContent(caloMjjSpectrum->GetMaximumBin()));
  PFMjjSpectrum->Scale(1./PFMjjSpectrum->GetBinContent(PFMjjSpectrum->GetMaximumBin()));

			      
  
  TLegend* leg0 = new TLegend(0.62, 0.78, 0.83, 0.89);
  leg0->AddEntry(mjj200_eff,"MJJ200Calo || HT250Calo","L");
  leg0->AddEntry(calo250_eff,"HT250_Calo","P");
  leg0->AddEntry(HTT240_eff,"HTT240","P");

  TLegend* leg1 = new TLegend(0.62, 0.78, 0.83, 0.89);
  leg1->AddEntry(mjj450_eff,"MJJ450PF || HT410PF","L");
  leg1->AddEntry(pf410_eff,"HT410_PF","P");

  TCanvas* c1 = new TCanvas();
  mjj200_eff->Draw();
  calo250_eff->Draw("sames");
  HTT240_eff->Draw("sames");
  caloMjjSpectrum->Draw("L,sames");
  leg0->Draw("sames");

  TCanvas* c2 = new TCanvas();
  mjj450_eff->Draw();
  pf410_eff->Draw("sames");
  PFMjjSpectrum->Draw("L,sames");
  leg1->Draw("sames");

  TCanvas* c3 = new TCanvas();
  //l1->Scale(PDRate/nentries);

  for(unsigned int ii=0; ii<l1Names->size(); ++ii)
    l1->GetXaxis()->SetBinLabel(ii+1,l1Names->at(ii).c_str());
  //l1->GetYaxis()->SetTitle("L1 Rate @4E33 [Hz]");
  l1->SetMaximum(l1->GetMaximum()+200);
  l2->SetLineColor(kRed);
  
  l1->Draw();
  l2->Draw("same");
  c3->Update();

  // TGaxis *l1axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
  // 			      l1->GetMinimum()*lumiScaleFactor,
  // 			      l1->GetMaximum()*lumiScaleFactor,510,"+L");

  // c2->SetTicky(0);
  // l1axis->SetLineColor(kRed);
  // l1axis->SetLabelColor(kRed);
  // l1axis->SetTextColor(kRed);
  // l1axis->SetTitleOffset(1.3);
  // l1axis->SetLabelSize(0.03);
  // l1axis->SetTitle("L1 Rate @1E34 [Hz]");
  // l1axis->Draw();
  
  
  //return 0;

  //##############################################
  //##############################################

  //book graphs and plots
  TGraphErrors* totRateVsCut = new TGraphErrors();
  totRateVsCut->SetMinimum(0);
  TGraphErrors* pureRateVsCut450 = new TGraphErrors();
  TGraphErrors* pureRateVsCut280 = new TGraphErrors();

  //loops
  int bin = 0;
  for (int cut = 350; cut < 500; cut=cut+10)
    {
      int mjjPassed = 0;
      int HT250Calo_Passed = 0;
      int excl410_passed = 0;
      int excl250_passed = 0;
      for (Long64_t jentry=0; jentry<nentries;++jentry) 
	{
	  tt->GetEntry(jentry);

	  if (hltAccept->at(HT250Calo) == 1)
	    ++HT250Calo_Passed;

	  //if (caloMjj > cut && !hltAccept->at(HT410PF))
	  if (caloMjj > cut && l1Accept->at(L1scenario) == 1 && hltAccept->at(HT410PF)==0)
	    ++excl410_passed;
	  if (caloMjj > cut && l1Accept->at(L1scenario)==1 && hltAccept->at(HT250Calo)==0)
	    ++excl250_passed;
	  if (caloMjj > cut && l1Accept->at(L1scenario)==1)
	    ++mjjPassed;

	  // if (hltAccept->at(HT250Calo) == 0 && mjj > cut)
	  //   std::cout << "ref trigger doesn't completely cover cut at " << cut << std::endl;
	}
      // float mjjTotalRate = (float)mjjPassed/(float)HT250Calo_Passed*HT250Calo_rate;
      // float mjjPureRate = (float)exclPassed/(float)HT250Calo_Passed*HT250Calo_rate;

      float sigmaMjjPassed = sqrt((float)mjjPassed);
      float sigmaNentries = sqrt((float)nentries);
      float sigmaExcl410_passed = sqrt((float)excl410_passed);
      float sigmaExcl250_passed = sqrt((float)excl250_passed);

      float mjjTotalRate = (float)mjjPassed/(float)nentries*PDRate;
      float mjjTotalRateE = PDRate*sqrt(pow((sigmaMjjPassed/nentries),2)+pow((sigmaNentries*mjjPassed/nentries/nentries),2));

      float mjj450_PureRate = (float)excl410_passed/(float)nentries*PDRate;
      float mjj450_PureRateE = PDRate*sqrt(pow((sigmaExcl410_passed/nentries),2)+pow((sigmaNentries*excl410_passed/nentries/nentries),2));
      
      float mjj280_PureRate = (float)excl250_passed/(float)nentries*PDRate;
      float mjj280_PureRateE = PDRate*sqrt(pow((sigmaExcl250_passed/nentries),2)+pow((sigmaNentries*excl250_passed/nentries/nentries),2));

      totRateVsCut->SetPoint(bin,cut,mjjTotalRate);
      totRateVsCut->SetPointError(bin,0.,mjjTotalRateE);

      pureRateVsCut450->SetPoint(bin,cut,mjj450_PureRate);
      pureRateVsCut450->SetPointError(bin,0.,mjj450_PureRateE);

      pureRateVsCut280->SetPoint(bin,cut,mjj280_PureRate);
      pureRateVsCut280->SetPointError(bin,0.,mjj280_PureRateE);

      ++bin;
    }

  //plotting and styling
  TLegend* leg = new TLegend(0.62, 0.78, 0.83, 0.89);
  leg->AddEntry(totRateVsCut,"total rate","P");
  leg->AddEntry(pureRateVsCut450,"pure rate wrt HT410PF","P");
  leg->AddEntry(pureRateVsCut280,"pure rate wrt HT250Calo","P");

  totRateVsCut->SetTitle("Rate Ref");

  totRateVsCut->GetXaxis()->SetTitle("Mjj cut threshold [GeV]");
  totRateVsCut->GetYaxis()->SetTitle("Rate @4E33 [Hz]");
  pureRateVsCut450->SetMarkerColor(kRed);
  pureRateVsCut450->SetLineColor(kRed);
  pureRateVsCut280->SetMarkerColor(kOrange+1);
  pureRateVsCut280->SetLineColor(kOrange+1);

  TCanvas* c4 = new TCanvas();
  c4->cd();
  totRateVsCut->Draw("AP");
  pureRateVsCut450->Draw("P,sames");
  pureRateVsCut280->Draw("P,sames");
  leg->Draw("sames");
  c4->Update();

  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
    			    (totRateVsCut->GetYaxis()->GetBinLowEdge(1))*lumiScaleFactor,
			    (totRateVsCut->GetYaxis()->GetBinLowEdge(totRateVsCut->GetYaxis()->GetNbins())+totRateVsCut->GetYaxis()->GetBinWidth(1))*lumiScaleFactor,510,"+L");

  c4->SetTicky(0);
  axis->SetLineColor(kRed);
  axis->SetLabelColor(kRed);
  axis->SetTextColor(kRed);
  axis->SetTitleOffset(1.3);
  axis->SetLabelSize(0.03);
  axis->SetTitle("Rate @1E34 [Hz]");
  axis->Draw();


  return 0;
}
コード例 #4
0
ファイル: rate.C プロジェクト: deguio/Analyzers
int rate(std::string fileName)
{
  setGlobalStyle();
  
  //###############################
  //## run274200 ##
  unsigned int HT250Calo  = 9; //index of DST_HT250_CaloScouting_v   old:1 ref:9
  unsigned int HT410PF = 7; //index of DST_HT410_PFScouting_v   old:3 ref:7
  unsigned int MJJ200Calo = 12; //index of DST_DiCaloWideJetMass200_CaloScouting_v
  
  unsigned int HTT200 = 0; //index if L1_HTT200
  unsigned int HTT240 = 1; //index if L1_HTT240
  unsigned int HTT270 = 2; //index if L1_HTT270
  unsigned int HTT280 = 3; //index if L1_HTT280
  unsigned int DoubleJetC100 = 7; //index if L1_DoubleJetC100
  unsigned int DoubleJetC112 = 8; //index if L1_DoubleJetC112
  unsigned int DoubleIsoTau28er = 11; //index if L1_DoubleJetC112

  float instLumi = 0.71; //E34
  float targetLumi = 1; //E34
  float lumiScaleFactor = targetLumi/instLumi;

  float PDRate = 21986976; //unprescaled rate of ParkingZeroBias accordingly to:  nEv/(nLS*23.3)*hltPresc*l1Presc   [*nPDs?] = 2343149/(824*23,3)*12*15013

  unsigned int L1MjjThr = 150;
  //###############################

  TChain* tt = new TChain("MyAnalysis/HLTree");
  tt->Add(fileName.c_str());

  //set branches
  TBranch* b_lumi;
  
  TBranch* b_caloMjj;
  TBranch* b_PFMjj;
  TBranch* b_caloWMjj;
  TBranch* b_PFWMjj;
  TBranch* b_l1Mjj;

  TBranch* b_hltAccept;
  TBranch* b_l1Accept;
  TBranch* b_l1Names;

  TBranch* b_caloJet1Pt;
  TBranch* b_caloJet2Pt;
  TBranch* b_caloJet1Eta;
  TBranch* b_caloJet2Eta;
  TBranch* b_caloJet1Phi;
  TBranch* b_caloJet2Phi;
  TBranch* b_caloDeltaEta;
  TBranch* b_caloWJet1Pt;
  TBranch* b_caloWJet2Pt;
  TBranch* b_caloWJet1Eta;
  TBranch* b_caloWJet2Eta;
  TBranch* b_caloWJet1Phi;
  TBranch* b_caloWJet2Phi;
  TBranch* b_caloWDeltaEta;

  TBranch* b_PFJet1Pt;
  TBranch* b_PFJet2Pt;
  TBranch* b_PFJet1Eta;
  TBranch* b_PFJet2Eta;
  TBranch* b_PFJet1Phi;
  TBranch* b_PFJet2Phi;
  TBranch* b_PFDeltaEta;
  TBranch* b_PFWJet1Pt;
  TBranch* b_PFWJet2Pt;
  TBranch* b_PFWJet1Eta;
  TBranch* b_PFWJet2Eta;
  TBranch* b_PFWJet1Phi;
  TBranch* b_PFWJet2Phi;
  TBranch* b_PFWDeltaEta;

  TBranch* b_l1Jet1Pt;
  TBranch* b_l1Jet2Pt;
  TBranch* b_l1Jet1Eta;
  TBranch* b_l1Jet2Eta;
  TBranch* b_l1Jet1Phi;
  TBranch* b_l1Jet2Phi;
  TBranch* b_l1DeltaEta;

  TBranch* b_l1JetPt;
  TBranch* b_l1JetEta;
  TBranch* b_l1JetPhi;

  int lumi = 0;
  float caloMjj = 0;
  float PFMjj = 0;
  float caloWMjj = 0;
  float PFWMjj = 0;
  float l1Mjj = 0;

  float caloJet1Pt_ = 0;
  float caloJet2Pt_ = 0;
  float caloJet1Eta_ = -999;
  float caloJet2Eta_ = -999;
  float caloJet1Phi_ = -999;
  float caloJet2Phi_ = -999;
  float caloDeltaEta_ = -999;
  float caloWJet1Pt_ = 0;
  float caloWJet2Pt_ = 0;
  float caloWJet1Eta_ = -999;
  float caloWJet2Eta_ = -999;
  float caloWJet1Phi_ = -999;
  float caloWJet2Phi_ = -999;
  float caloWDeltaEta_ = -999;

  float PFJet1Pt_ = 0;
  float PFJet2Pt_ = 0;
  float PFJet1Eta_ = -999;
  float PFJet2Eta_ = -999;
  float PFJet1Phi_ = -999;
  float PFJet2Phi_ = -999;
  float PFDeltaEta_ = -999;
  float PFWJet1Pt_ = 0;
  float PFWJet2Pt_ = 0;
  float PFWJet1Eta_ = -999;
  float PFWJet2Eta_ = -999;
  float PFWJet1Phi_ = -999;
  float PFWJet2Phi_ = -999;
  float PFWDeltaEta_ = -999;

  float l1Jet1Pt_ = 0;
  float l1Jet2Pt_ = 0;
  float l1Jet1Eta_ = -999;
  float l1Jet2Eta_ = -999;
  float l1Jet1Phi_ = -999;
  float l1Jet2Phi_ = -999;
  float l1DeltaEta_ = -999;

  std::vector<float>* l1JetPt_ = 0;
  std::vector<float>* l1JetEta_ = 0;
  std::vector<float>* l1JetPhi_ = 0;
  
  std::vector<int>* hltAccept = 0;
  std::vector<int>* l1Accept = 0;
  std::vector<string>* l1Names = 0;

  tt->SetBranchAddress("lumi", &lumi, &b_lumi);

  tt->SetBranchAddress("caloMjj", &caloMjj, &b_caloMjj);
  tt->SetBranchAddress("PFMjj", &PFMjj, &b_PFMjj);
  tt->SetBranchAddress("caloWMjj", &caloWMjj, &b_caloWMjj);
  tt->SetBranchAddress("PFWMjj", &PFWMjj, &b_PFWMjj);
  tt->SetBranchAddress("l1Mjj", &l1Mjj, &b_l1Mjj);

  tt->SetBranchAddress("caloJet1Pt", &caloJet1Pt_, &b_caloJet1Pt);
  tt->SetBranchAddress("caloJet2Pt", &caloJet2Pt_, &b_caloJet2Pt);
  tt->SetBranchAddress("caloJet1Eta", &caloJet1Eta_, &b_caloJet1Eta);
  tt->SetBranchAddress("caloJet2Eta", &caloJet2Eta_, &b_caloJet2Eta);
  tt->SetBranchAddress("caloJet1Phi", &caloJet1Phi_, &b_caloJet1Phi);
  tt->SetBranchAddress("caloJet2Phi", &caloJet2Phi_, &b_caloJet2Phi);
  tt->SetBranchAddress("caloDeltaEta", &caloDeltaEta_, &b_caloDeltaEta);
  tt->SetBranchAddress("caloWJet1Pt", &caloWJet1Pt_, &b_caloWJet1Pt);
  tt->SetBranchAddress("caloWJet2Pt", &caloWJet2Pt_, &b_caloWJet2Pt);
  tt->SetBranchAddress("caloWJet1Eta", &caloWJet1Eta_, &b_caloWJet1Eta);
  tt->SetBranchAddress("caloWJet2Eta", &caloWJet2Eta_, &b_caloWJet2Eta);
  tt->SetBranchAddress("caloWJet1Phi", &caloWJet1Phi_, &b_caloWJet1Phi);
  tt->SetBranchAddress("caloWJet2Phi", &caloWJet2Phi_, &b_caloWJet2Phi);
  tt->SetBranchAddress("caloWDeltaEta", &caloWDeltaEta_, &b_caloWDeltaEta);

  tt->SetBranchAddress("PFJet1Pt", &PFJet1Pt_, &b_PFJet1Pt);
  tt->SetBranchAddress("PFJet2Pt", &PFJet2Pt_, &b_PFJet2Pt);
  tt->SetBranchAddress("PFJet1Eta", &PFJet1Eta_, &b_PFJet1Eta);
  tt->SetBranchAddress("PFJet2Eta", &PFJet2Eta_, &b_PFJet2Eta);
  tt->SetBranchAddress("PFJet1Phi", &PFJet1Phi_, &b_PFJet1Phi);
  tt->SetBranchAddress("PFJet2Phi", &PFJet2Phi_, &b_PFJet2Phi);
  tt->SetBranchAddress("PFDeltaEta", &PFDeltaEta_, &b_PFDeltaEta);
  tt->SetBranchAddress("PFWJet1Pt", &PFWJet1Pt_, &b_PFWJet1Pt);
  tt->SetBranchAddress("PFWJet2Pt", &PFWJet2Pt_, &b_PFWJet2Pt);
  tt->SetBranchAddress("PFWJet1Eta", &PFWJet1Eta_, &b_PFWJet1Eta);
  tt->SetBranchAddress("PFWJet2Eta", &PFWJet2Eta_, &b_PFWJet2Eta);
  tt->SetBranchAddress("PFWJet1Phi", &PFWJet1Phi_, &b_PFWJet1Phi);
  tt->SetBranchAddress("PFWJet2Phi", &PFWJet2Phi_, &b_PFWJet2Phi);
  tt->SetBranchAddress("PFWDeltaEta", &PFWDeltaEta_, &b_PFWDeltaEta);

  tt->SetBranchAddress("l1Jet1Pt", &l1Jet1Pt_, &b_l1Jet1Pt);
  tt->SetBranchAddress("l1Jet2Pt", &l1Jet2Pt_, &b_l1Jet2Pt);
  tt->SetBranchAddress("l1Jet1Eta", &l1Jet1Eta_, &b_l1Jet1Eta);
  tt->SetBranchAddress("l1Jet2Eta", &l1Jet2Eta_, &b_l1Jet2Eta);
  tt->SetBranchAddress("l1Jet1Phi", &l1Jet1Phi_, &b_l1Jet1Phi);
  tt->SetBranchAddress("l1Jet2Phi", &l1Jet2Phi_, &b_l1Jet2Phi);
  tt->SetBranchAddress("l1DeltaEta", &l1DeltaEta_, &b_l1DeltaEta);

  tt->SetBranchAddress("l1JetPt", &l1JetPt_, &b_l1JetPt);
  tt->SetBranchAddress("l1JetEta", &l1JetEta_, &b_l1JetEta);
  tt->SetBranchAddress("l1JetPhi", &l1JetPhi_, &b_l1JetPhi);

  tt->SetBranchAddress("hltAccept", &hltAccept, &b_hltAccept);
  tt->SetBranchAddress("l1Accept", &l1Accept, &b_l1Accept);
  tt->SetBranchAddress("l1Names", &l1Names, &b_l1Names);

  int nentries = tt->GetEntries();
  std::cout << "Number of entries: " << nentries << std::endl;
  
  //book graphs and plots
  float min = 0.;
  float max = 1000.;
  int nBins = 20;

  TF1* f1 = new TF1("f1","[0]*TMath::Erf((x-[1])/[2])-[0]*TMath::Erf((-x-[1])/[2])",min,max);
  f1->SetParameters(0.5,350,40);  
  f1->FixParameter(0,0.5);
  f1->SetLineWidth(2.);
  f1->SetLineColor(kRed);

  TF1* f2 = (TF1*)f1->Clone("f2");
  f2->SetParameters(0.5,150,10);
  f2->SetLineColor(kBlack);

  //##############################################
  //##############################################

  //book graphs and plots
  TGraphErrors* totL1RateVsCut = new TGraphErrors();
  totL1RateVsCut->SetMinimum(0);
  TGraphErrors* pureL1RateVsCut = new TGraphErrors();

  TGraphErrors* totHltRateVsCut = new TGraphErrors();
  totHltRateVsCut->SetMinimum(0);
  TGraphErrors* pureHltRateVsCut = new TGraphErrors();

  //loops
  int bin = 0;
  for (int cut = 200; cut < 350; cut=cut+10)
    {
      std::cout << "analyzing point at " << cut << " GeV" << std::endl;

      int mjjHltPassed = 0;
      int excl_mjjHltPassed = 0;

      int mjjL1Passed = 0;
      int excl_mjjL1Passed = 0;

      int HTT240Passed = 0;

      for (Long64_t jentry=0; jentry<nentries;++jentry) 
	{
	  tt->GetEntry(jentry);

	  //### Sanity checks ###
	  if (l1Accept->at(HTT240) == 1)
	    ++HTT240Passed;
	  
	  //### L1 ###
	  bool l1Pass = (l1Mjj>cut &&
			 l1Jet1Pt_ > 15. &&
			 l1Jet2Pt_ > 15. &&
			 fabs(l1Jet1Eta_) < 5.0 &&
			 fabs(l1Jet2Eta_) < 5.0 &&
			 l1DeltaEta_ < 2.0
			 );

	  bool L1RefPass = (l1Mjj>L1MjjThr &&
			    l1Jet1Pt_ > 15. &&
			    l1Jet2Pt_ > 15. &&
			    fabs(l1Jet1Eta_) < 5.0 &&
			    fabs(l1Jet2Eta_) < 5.0 &&
			    l1DeltaEta_ < 2.0
			    );


	  // if(l1Pass && l1Accept->at(HTT240) == 0 && caloWMjj < 100 && caloWMjj>0)
	  //   {
	  //     std::cout << std::endl;
	  //     std::cout << std::fixed << std::setprecision(2)
	  // 		<< "l1Mjj-caloWMjj = " << l1Mjj-caloWMjj << " l1Mjj = " << l1Mjj << " caloWMjj = " << caloWMjj << std::endl;
	  //     std::cout << "  caloWJet1Pt_    = " << caloWJet1Pt_     << " caloWJet1Eta_     = " << caloWJet1Eta_     << " caloWJet1Phi_     = " << caloWJet1Phi_ << std::endl;
	  //     std::cout << "  l1Jet1Pt        = " << l1Jet1Pt_        << " l1Jet1Eta         = " << l1Jet1Eta_        << " l1Jet1Phi         = " << l1Jet1Phi_ << std::endl;
	  //     std::cout << std::endl;
	  //     std::cout << "  caloWJet2Pt_     = " << caloWJet2Pt_     << " caloWJet2Eta_     = " << caloWJet2Eta_     << " caloWJet2Phi_     = " << caloWJet2Phi_ << std::endl;
	  //     std::cout << "  l1Jet2Pt         = " << l1Jet2Pt_        << " l1Jet2Eta         = " << l1Jet2Eta_        << " l1Jet2Phi         = " << l1Jet2Phi_ << std::endl;
	  //     std::cout << "==========================================================" << std::endl;
	  //   }
	  

		      
	  if (l1Pass)
	    ++mjjL1Passed;
	  if (l1Pass && l1Accept->at(HTT240) == 0)
	    ++excl_mjjL1Passed;


	  //### HLT ###
	  //Hypothesis of HLT rates with L1Mjj seed at L1MjjThr
	  if (caloWMjj > cut && L1RefPass)
	    ++mjjHltPassed;
	  if (caloWMjj > cut && L1RefPass && hltAccept->at(HT250Calo) == 0)
	    ++excl_mjjHltPassed;


	}
      float HTT240rate = (float)HTT240Passed/(float)nentries*PDRate;
      //std::cout << "HTT240rate = " << HTT240rate << std::endl;
      
      float sigmaNentries = sqrt((float)nentries);

      float sigmaMjjHltPassed = sqrt((float)mjjHltPassed);
      float excl_sigmaMjjHltPassed = sqrt((float)excl_mjjHltPassed);

      float sigmaMjjL1Passed = sqrt((float)mjjL1Passed);
      float excl_sigmaMjjL1Passed = sqrt((float)excl_mjjL1Passed);

      float mjjHltRate = (float)mjjHltPassed/(float)nentries*PDRate;
      float mjjHltRateE = PDRate*sqrt(pow((sigmaMjjHltPassed/nentries),2)+pow((sigmaNentries*mjjHltPassed/nentries/nentries),2));
      float excl_mjjHltRate = (float)excl_mjjHltPassed/(float)nentries*PDRate;
      float excl_mjjHltRateE = PDRate*sqrt(pow((excl_sigmaMjjHltPassed/nentries),2)+pow((sigmaNentries*excl_mjjHltPassed/nentries/nentries),2));

      float mjjL1Rate = (float)mjjL1Passed/(float)nentries*PDRate;
      float mjjL1RateE = PDRate*sqrt(pow((sigmaMjjL1Passed/nentries),2)+pow((sigmaNentries*mjjL1Passed/nentries/nentries),2));
      float excl_mjjL1Rate = (float)excl_mjjL1Passed/(float)nentries*PDRate;
      float excl_mjjL1RateE = PDRate*sqrt(pow((excl_sigmaMjjL1Passed/nentries),2)+pow((sigmaNentries*excl_mjjL1Passed/nentries/nentries),2));

      totHltRateVsCut->SetPoint(bin,cut,mjjHltRate);
      totHltRateVsCut->SetPointError(bin,0.,mjjHltRateE);
      pureHltRateVsCut->SetPoint(bin,cut,excl_mjjHltRate);
      pureHltRateVsCut->SetPointError(bin,0.,excl_mjjHltRateE);

      totL1RateVsCut->SetPoint(bin,cut,mjjL1Rate);
      totL1RateVsCut->SetPointError(bin,0.,mjjL1RateE);
      pureL1RateVsCut->SetPoint(bin,cut,excl_mjjL1Rate);
      pureL1RateVsCut->SetPointError(bin,0.,excl_mjjL1RateE);

      ++bin;
    }

  //plotting and styling
  TLegend* legHlt = new TLegend(0.62, 0.78, 0.83, 0.89);
  legHlt->AddEntry(totHltRateVsCut,"hlt total rate","P");
  legHlt->AddEntry(pureHltRateVsCut,"hlt pure rate wrt HT250","P");

  TLegend* legL1 = new TLegend(0.62, 0.78, 0.83, 0.89);
  legL1->AddEntry(totL1RateVsCut,"l1 total rate","P");
  legL1->AddEntry(pureL1RateVsCut,"l1 pure rate wrt HTT240","P");

  totHltRateVsCut->GetXaxis()->SetTitle("Mjj cut threshold [GeV]");
  totHltRateVsCut->GetYaxis()->SetTitle("Rate @7E33 [Hz]");
  totHltRateVsCut->SetMarkerColor(kRed);
  pureHltRateVsCut->SetMarkerColor(kOrange+1);

  totL1RateVsCut->GetXaxis()->SetTitle("Mjj cut threshold [GeV]");
  totL1RateVsCut->GetYaxis()->SetTitle("Rate @7E33 [Hz]");
  totL1RateVsCut->SetMarkerColor(kBlue);
  totL1RateVsCut->SetMarkerColor(kAzure);

  TCanvas* c4 = new TCanvas();
  c4->cd();
  totHltRateVsCut->Draw("AP");
  pureHltRateVsCut->Draw("P,sames");
  legHlt->Draw("sames");
  c4->Update();
  TGaxis *axisHlt = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
    			    (totHltRateVsCut->GetYaxis()->GetBinLowEdge(1))*lumiScaleFactor,
			    (totHltRateVsCut->GetYaxis()->GetBinLowEdge(totHltRateVsCut->GetYaxis()->GetNbins())+totHltRateVsCut->GetYaxis()->GetBinWidth(1))*lumiScaleFactor,510,"+L");

  c4->SetTicky(0);
  axisHlt->SetLineColor(kRed);
  axisHlt->SetLabelColor(kRed);
  axisHlt->SetTextColor(kRed);
  axisHlt->SetTitleOffset(1.3);
  axisHlt->SetLabelSize(0.03);
  axisHlt->SetTitle("Rate @1E34 [Hz]");
  axisHlt->Draw();
  c4->Print("rates/hltRate.pdf","pdf");


  TCanvas* c5 = new TCanvas();
  c5->cd();
  totL1RateVsCut->Draw("AP");
  pureL1RateVsCut->Draw("P,sames");
  legL1->Draw("sames");
  c5->Update();
  TGaxis *axisL1 = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
			      (totL1RateVsCut->GetYaxis()->GetBinLowEdge(1))*lumiScaleFactor,
			      (totL1RateVsCut->GetYaxis()->GetBinLowEdge(totL1RateVsCut->GetYaxis()->GetNbins())+totL1RateVsCut->GetYaxis()->GetBinWidth(1))*lumiScaleFactor,510,"+L");

  c5->SetTicky(0);
  axisL1->SetLineColor(kRed);
  axisL1->SetLabelColor(kRed);
  axisL1->SetTextColor(kRed);
  axisL1->SetTitleOffset(1.3);
  axisL1->SetLabelSize(0.03);
  axisL1->SetTitle("Rate @1E34 [Hz]");
  axisL1->Draw();
  c5->Print("rates/l1Rate.pdf","pdf");

  return 0;
}