Exemplo n.º 1
0
void k_Vs_relIso()
{
  TFile* file1 = TFile::Open("outputFile_Mu_Run2010A_Sep17thReReco.root");
  TH2F* obs = static_cast<TH2F*>(file1->Get("relIso_Vs_d0_tagRateObs"));
  TH2F* pred = static_cast<TH2F*>(file1->Get("relIso_Vs_d0_tagRatePred"));
  
  TFile* file2 = TFile::Open("outputFile_Mu_Run2010B_PromptReco_Part1.root");
  obs->Add(static_cast<TH2F*>(file2->Get("relIso_Vs_d0_tagRateObs")));
  pred->Add(static_cast<TH2F*>(file2->Get("relIso_Vs_d0_tagRatePred")));

  TFile* file3 = TFile::Open("outputFile_Mu_Run2010B_PromptReco_Part2.root");
  obs->Add(static_cast<TH2F*>(file3->Get("relIso_Vs_d0_tagRateObs")));
  pred->Add(static_cast<TH2F*>(file3->Get("relIso_Vs_d0_tagRatePred")));

  TFile* file4 = TFile::Open("outputFile_Mu_Run2010B_PromptReco_Part3.root");
  obs->Add(static_cast<TH2F*>(file4->Get("relIso_Vs_d0_tagRateObs")));
  pred->Add(static_cast<TH2F*>(file4->Get("relIso_Vs_d0_tagRatePred")));

  TH2F* k = new TH2F("k", "k Factor vs relIso", 100, 0.0, 0.25, 100, 0.0, 5.0); 
  k->Divide(obs, pred);
  k->ProfileY()->Draw();

  /*file1->Close();*/
  /*delete file1;*/

  /*file2->Close();*/
  /*delete file2;*/

  /*file3->Close();*/
  /*delete file3;*/

  /*file4->Close();*/
  /*delete file4;*/
}
Exemplo n.º 2
0
computePRfast(){
    chain->Add("/afs/cern.ch/work/h/hbrun/public/TnP_CLtree_DYJets.root");
    
    
    TString trigeringElectrons = "((absSCeta<1.479&&CL_sigmaIetaIeta<0.01&&CL_deltaPhiIn<0.15&&CL_deltaEtaIn<0.007&&CL_HoE<0.12&&(CL_isoECAL-1)/pt<0.2)||(absSCeta>=1.479&&CL_sigmaIetaIeta<0.03&&CL_deltaPhiIn<0.1&&CL_deltaEtaIn<0.009&&CL_HoE<0.1&&(CL_isoECAL)/pt<0.2)&&CL_isoHCAL<0.2&&CL_isoTracker<0.2)";
    TString looseID = trigeringElectrons+"&&CL_relatPFiso03<1&&CL_dZ<0.1&&CL_MVA>-0.1";
    TString tightID = looseID+"&&CL_relatPFiso03<0.15&&CL_dZ<0.04&&CL_MVA>0.5&&CL_passConversionVeto==0&&CL_hnHits<1";
    
    
    
    float ptBins[6]={10,15,20,25,50,200};
    float etaBins[4] = {0,  1.4442, 1.556, 2.5};
    
    TH2F *passingLooseID = new TH2F("passingLooseID","",3, etaBins, 5, ptBins);
    chain->Draw("pt:absSCeta>>passingLooseID",looseID+"&&mass>80&&mass<100&&eventMatched==1");//matched with MC truth and in the Z peak (similar with TnP)
    
    TH2F *passingTightID = new TH2F("passingTightID","",3, etaBins, 5, ptBins);
    chain->Draw("pt:absSCeta>>passingTightID",tightID+"&&mass>80&&mass<100&&eventMatched==1");//matched with MC truth and in the Z peak (similar with TnP)
    

    TH2F *promptRate = (TH2F*) passingTightID->Clone("promptRate");
    promptRate->Sumw2();
    promptRate->Divide(passingTightID, passingLooseID,1,1);
    
    
    //save in the file
    myFile->cd();
    promptRate->Write("effMC_Prompt_Rate");
    myFile->Close();
    
    
}
Exemplo n.º 3
0
TH2F *prof2d(TTree *tree, TString var1Name, TString var2Name, TString nllName, TString binning="(40,0,0.05,40,0,0.2)", bool delta=false){

  var1Name.ReplaceAll("-","_");
  var2Name.ReplaceAll("-","_");
  //  tree->Print();
  TString histName="h";
  std::cout << var1Name << "\t" << var2Name << "\t" << histName << std::endl;
  tree->Draw(var1Name+":"+var2Name+">>"+histName+binning);
  TH2F *hEntries = (TH2F*)gROOT->FindObject(histName);
  if(hEntries==NULL) return NULL;
  //std::cerr << "e qui ci sono?" << std::endl;
  tree->Draw(var1Name+":"+var2Name+">>shervin"+binning,nllName);

  TH2F *h = (TH2F*)gROOT->FindObject("shervin");
  if(h==NULL) return NULL;
  h->Divide(hEntries);


  //std::cerr << "io sono qui" << std::endl;    
  delete hEntries;
  Double_t min=1e20, max=0;

  if(delta){
    for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){
      for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){
	Double_t binContent=h->GetBinContent(iBinX, iBinY);
	if(min>binContent && binContent!=0) min=binContent;
	if(max<binContent) max=binContent;
      }
    }
    std::cout << "min=" << min << "\tmax=" << max<<std::endl;    
    for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){
      for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){
	Double_t binContent=h->GetBinContent(iBinX, iBinY);
	//std::cout << binContent << std::endl;
	if(binContent!=0) binContent-=min;
	else binContent=-1;
	h->SetBinContent(iBinX,iBinY,binContent);
      }
    }
  }
  h->GetZaxis()->SetRangeUser(0,500);
  //std::cerr << "io sono qui 3" << std::endl;    
  return h;
//   Double_t variables[2];
//   Double_t nll;
//   tree->SetBranchAddress(var1Name, &(variables[0]));
//   tree->SetBranchAddress(var2Name, &(variables[1]));
//   tree->SetBranchAddress(nllName, &(nll));

  
//   Long64_t nEntries=tree->GetEntries();
//   for(Long64_t jentry=0; jentry<nEntries; jentry++){
    
}
Exemplo n.º 4
0
//2d reweighting of rho and its sigma
void reweight_rhosigma(TH1F* weight_rho, TH1F* weight_rhoo,TH2F*weight_rhon,TH2F*weight_rho2o,TH2F* weight_rhonr, TH2F* weight_rho2,TH2F*weight_sigman,TH2F*weight_sigma2o,TH2F* weight_sigmanr, TH2F* weight_sigma2,RooDataSet **dset, RooDataSet *dsetdestination, bool deleteold){
  if (!(*dset)) return;
//  TH2F *hnum = new TH2F("hnum","hnum",n_rhobins_forreweighting,rhobins_forreweighting,n_sigmabins_forreweighting,sigmabins_forreweighting);
//  TH2F *hden = new TH2F("hden","hden",n_rhobins_forreweighting,rhobins_forreweighting,n_sigmabins_forreweighting,sigmabins_forreweighting);
  TH2F *hnum = new TH2F("hnum","hnum",100,0,100,20,0,20);
  TH2F *hden = new TH2F("hden","hden",100,0,100,20,0,20);
  hnum->Sumw2();
  hden->Sumw2();
  for (int i=0; i<(*dset)->numEntries(); i++){
    hden->Fill(fabs((*dset)->get(i)->getRealValue("roorho")),fabs((*dset)->get(i)->getRealValue("roosigma")),(*dset)->store()->weight(i));
  }
  for (int i=0; i<dsetdestination->numEntries(); i++){
    hnum->Fill(fabs(dsetdestination->get(i)->getRealValue("roorho")),fabs(dsetdestination->get(i)->getRealValue("roosigma")),dsetdestination->store()->weight(i));
  }

  hnum->Scale(1.0/hnum->Integral());
  hden->Scale(1.0/hden->Integral());
//data/MC
  hnum->Divide(hden);
  TH2F *h = hnum;

  RooDataSet *newdset = new RooDataSet(**dset,Form("%s_rhosigmarew",(*dset)->GetName()));
  newdset->reset();
  for (int i=0; i<(*dset)->numEntries(); i++){
    RooArgSet args = *((*dset)->get(i));
    float oldw = (*dset)->store()->weight(i);
    float rho = args.getRealValue("roorho");
    float sigma = args.getRealValue("roosigma");
    float neww = oldw*h->GetBinContent(h->FindBin(rho,sigma));
	if(debug){
		weight_rho->Fill(neww);
		weight_rhoo->Fill(oldw);
		weight_rho2o->Fill(h->GetXaxis()->FindBin(rho),oldw);	
		weight_rhon->Fill(h->GetXaxis()->FindBin(rho),neww);	
		if(oldw!=0)weight_rhonr->Fill(h->GetXaxis()->FindBin(rho),oldw/neww);
		else {weight_rhonr->Fill(-10,1);}//cout << "dipho weight old 0" << endl;}
		if(oldw!=0)weight_rho2->Fill(rho,oldw/neww);
		weight_sigma2o->Fill(h->GetYaxis()->FindBin(sigma),oldw);	
		weight_sigman->Fill(h->GetYaxis()->FindBin(sigma),neww);	
		if(oldw!=0)weight_sigmanr->Fill(h->GetYaxis()->FindBin(sigma),oldw/neww);
		else {weight_sigmanr->Fill(-10,1);}//cout << "dipho weight old 0" << endl;}
		if(oldw!=0)weight_sigma2->Fill(sigma,oldw/neww);
	}
		newdset->add(args,neww);
	  }
	  newdset->SetName((*dset)->GetName());
	  newdset->SetTitle((*dset)->GetTitle());
	  delete hnum; delete hden;
	  RooDataSet *old_dset = *dset;
	  *dset=newdset;
	  std::cout << "RhoSigma2D rew: norm from " << old_dset->sumEntries() << " to " << newdset->sumEntries() << std::endl;
	  if (deleteold) delete old_dset;
	};
Exemplo n.º 5
0
void
SimpleTrackCorrector::load(std::string dirName)
{
  std::string cn[6] = {"heff","hrec","hsim","hfak","hmul","hsec"};

  TH2F * corr2Deff = (TH2F*) table->Get(Form("%s/heff",dirName.c_str()));
  TH2F * corr2Dsim = (TH2F*) table->Get(Form("%s/hsim",dirName.c_str()));
  TH2F * corr2Drec = (TH2F*) table->Get(Form("%s/hrec",dirName.c_str()));
  TH2F * corr2Dfak = (TH2F*) table->Get(Form("%s/hfak",dirName.c_str()));
  TH2F * corr2Dsec = (TH2F*) table->Get(Form("%s/hsec",dirName.c_str()));
  TH2F * corr2Dmul = (TH2F*) table->Get(Form("%s/hmul",dirName.c_str()));


  reff2D = (TH2F*) corr2Deff->Clone("reff");
  rfak2D = (TH2F*) corr2Dfak->Clone("rfak");
  rmul2D = (TH2F*) corr2Dmul->Clone("rmul");
  rsec2D = (TH2F*) corr2Dsec->Clone("rsec");

  reff2D->Divide(corr2Deff,corr2Dsim,1,1,"B");
  rmul2D->Divide(corr2Dmul,corr2Dsim,1,1,"B");
  rfak2D->Divide(corr2Dfak,corr2Drec,1,1,"B");
  rsec2D->Divide(corr2Dsec,corr2Drec,1,1,"B");

}
Exemplo n.º 6
0
TCanvas *PlotDataMC2D(TChain *data, TChain *mc, TString branchname, TString binning, 
		      TCut selection, 
		      TString dataLabel, TString mcLabel, 
		      TString xLabel, TString yLabel, 
		      int type=2, TString opt="colz", bool usePU=true, bool smear=false, bool scale=false){
  //type == 0: data only
  //type == 1: MC only
  //type == 2: data/MC
   
  TCanvas *c = new TCanvas("c","");
  TString weightVar;
  if(branchname.Contains("map")){
    weightVar=branchname.ReplaceAll("_map","").ReplaceAll("map","");
    branchname="seedXSCEle:seedYSCEle";
    binning="(361,-0.5,360.5,171,-85.5,85.5)";
    yLabel="iEta";
    xLabel="iPhi";
    c->SetGridx();
  }
  if(weightVar!="") selection+="*"+weightVar;
  data->Draw(branchname+">>data_hist"+binning, selection,opt);
  if(usePU)  mc->Draw(branchname+">>mc_hist"+binning, selection *"puWeight",opt);
  else  mc->Draw(branchname+">>mc_hist"+binning, selection,opt);

  c->Clear();
  
  TH2F *d = (TH2F *) gROOT->FindObject("data_hist");
  TH2F *s = (TH2F *) gROOT->FindObject("mc_hist");

  if(type==0) d->Draw(opt);
  else if(type==1) s->Draw(opt);
  else if(type==3){
    s->Scale(d->Integral()/s->Integral());
    d->Divide(s);
    d->Draw(opt);
  }

  d->GetXaxis()->SetTitle(xLabel);
  s->GetXaxis()->SetTitle(xLabel);
  d->GetYaxis()->SetTitle(yLabel);
  s->GetYaxis()->SetTitle(yLabel);
  c->SetRightMargin(0.2);
  return c;
  
}
Exemplo n.º 7
0
// Method by pointer
TH2F* eff2(TH2F* h1, TH2F* h2, const char* name="eff"){

  // first, verify that all histograms have same binning
  // nx is the number of visible bins
  // nxtot = nx+2 includes underflow and overflow
  Int_t nx = h1->GetNbinsX();
  if (h2->GetNbinsX() != nx) {
    cout << "Histograms must have same number of bins" << endl;
    return 0;
  }

  // get the new histogram
  TH2F* temp = (TH2F*) h1->Clone(name);
  temp->SetTitle(name);
  temp->Reset();
  temp->Sumw2();

  // Do the calculation
  temp->Divide(h2,h1,1.,1.,"B");

  // Done
  return temp;
}
Exemplo n.º 8
0
//Usage:
//.x Draw_EtaRing_EE.C+
void Draw_EtaRing_EE( bool EB=false, bool EE=true, bool noplot = true ){

  cout<<"Let's start with Parsing!"<<endl;
  //PARSING
  ifstream file;
  file.open("../common/Endc_x_y_ring.txt", ifstream::in);
  vector<iXiYtoRing> VectRing;

  while ( !file.eof() ) {
    string Line;
    getline( file, Line);
    string value;
    stringstream MyLine(Line);

    char * cstr, *p;
    cstr = new char [Line.size()+1];
    strcpy (cstr, Line.c_str());
    p=strtok (cstr," ");
    int i(0);
    while (p!=NULL){
	if(i==0)  GiveRing.iX = atoi(p);
	if(i==1)  GiveRing.iY = atoi(p);
	if(i==2)  GiveRing.sign = atoi(p);
	if(i==3){ 
	  GiveRing.Ring = atoi(p);
	  VectRing.push_back(GiveRing);
	}
	p=strtok(NULL," ");
	i++;
    }
    delete[] cstr;  
  }
  if(!noplot){
    //EE
    cout<<"Loop on the EE histo."<<endl;
    TH2F* h_EE = new TH2F("h_EE","EE etaring", 100, 0., 100., 100, 0., 100. );

    for(int x=0; x<100;x++){
	for(int y=0; y<100;y++){
	  int ring = GetRing( x, y, VectRing);
	  if( ring==-1 )     h_EE->SetBinContent(x,y,0);
	  else if(ring%2==0) h_EE->SetBinContent(x,y,100);
	  else               h_EE->SetBinContent(x,y,50);
	}
    }
    TCanvas* myc1 = new TCanvas("myc1", "CMS", 600, 600);
    h_EE->Draw("colz");
    myc1->SaveAs("EE_EtaRing.png");
    cout<<"Drawing..."<<endl;
    cout<<"Finally: THE END!"<<endl;
  }
  //Check on the Histo
  TFile* f_Ec  = TFile::Open( "../AfterCalibTools/WorkOnIC/prova_7Iter/ECAL/IC_SetAverageTo1_EtaRing.root" );
  if(!f_Ec) cout<<"Problem with File: EcalPro"<<endl;
  TFile* f_Ca  = TFile::Open( "../AfterCalibTools/WorkOnIC/prova_7Iter/CAL/IC_SetAverageTo1_EtaRing.root" );
  if(!f_Ca) cout<<"Problem with File: EtaRing"<<endl;
  TFile* f_Div = TFile::Open( "../AfterCalibTools/WorkOnIC/prova_7Iter/2012C_ECALCC_Vs_CalCC_7Iter_EtaRing1.root" );
  if(!f_Div) cout<<"Problem with File: division"<<endl;

  if(EB){
  cout<<"Now EB: "<<endl;
    TCanvas* myc1 = new TCanvas("myc1", "CMS", 600, 600);
    gStyle->SetOptStat(0);
    for(int nh=0; nh<=3; nh++){
	TProfile *pr_h = new TProfile("pr_h","profile", 171, 0., 171., 0.9, 1.1); pr_h->GetXaxis()->SetTitle("iEtaBin");
	TH2F* h;
	if(nh==0) h = (TH2F*) f_Ec->Get( "calibMap_EB" );
	if(nh==1) h = (TH2F*) f_Ca->Get( "calibMap_EB" );
	if(nh==2) h = (TH2F*) f_Div->Get( "Ratio_EBMap" );
	if(nh==3){h = (TH2F*) f_Ec->Get( "calibMap_EB" ); TH2F* h_2 = (TH2F*) f_Ca->Get( "calibMap_EB" ); h->Divide(h_2); }
	float Corr[171]={0.};
	float Norm[360]={0.};
	for(int iEta=0+1; iEta<171+1; iEta++){
	  for(int iPhi=0+1; iPhi<360+1; iPhi++){
	    if( iEta!=86 && h->GetBinContent(nh!=2?iEta:iPhi,nh!=2?iPhi:iEta)!=0 && h->GetBinContent(nh!=2?iEta:iPhi,nh!=2?iPhi:iEta)!=1 ){
		Corr[iEta-1] += h->GetBinContent(nh!=2?iEta:iPhi,nh!=2?iPhi:iEta);
		Norm[iEta-1] += 1.;
		if(nh==2) pr_h->Fill( float(iEta) , h->GetBinContent(nh!=2?iEta:iPhi,nh!=2?iPhi:iEta) );
		//cout<<iPhi<<" "<<iEta<<" : "<<h->GetBinContent(nh!=2?iEta:iPhi,nh!=2?iPhi:iEta)<<"  "<<Corr[iEta-1]<<"  "<<Norm[iEta-1]<<endl;
	    }
	  }
	}
	if(nh==2){ pr_h->Draw("colz"); myc1->SaveAs("Profile.png");}
	if(nh==0) cout<<"Now ECALpro"<<endl;
	if(nh==1) cout<<"Now Caltech"<<endl;
	if(nh==2) cout<<"Now Comparison"<<endl;
	if(nh==3) cout<<"Now the division"<<endl;
	for(int i=0; i<171;i++){
	  if(Norm[i]>0) cout<<Corr[i]/Norm[i]<<endl;
	}

    }
  }
  if(EE){
    cout<<"Now EE: "<<endl;
    for(int nh=0; nh<=3; nh++){
	TH2F* h;
	if(nh==0) h = (TH2F*) f_Ec->Get( "calibMap_EEp" ); 
	if(nh==1) h = (TH2F*) f_Ca->Get( "calibMap_EEp" ); 
	if(nh==2) h = (TH2F*) f_Div->Get( "Ratio_EEpMap" ); 
	if(nh==3){h = (TH2F*) f_Ec->Get( "calibMap_EEp" ); TH2F* h_2 = (TH2F*) f_Ca->Get( "calibMap_EEp" ); h->Divide(h_2); }
	float Corr[40]={0.};
	float Norm[40]={0.};
	for(int x=0; x<100;x++){
	  for(int y=0; y<100;y++){
	    int ring = GetRing( x, y, VectRing);
	    if( h->GetBinContent(x+1,y+1)!=0 && h->GetBinContent(x+1,y+1)!=1 ){
		//cout<<x<<" "<<y<<" "<<ring<<" "<<h->GetBinContent(x+1,y+1)<<endl;
		Corr[ring] += h->GetBinContent(x+1,y+1);
		Norm[ring] += 1.;
	    }
	  }
	}
	if(nh==0) cout<<"Now ECALpro"<<endl;
	if(nh==1) cout<<"Now Caltech"<<endl;
	if(nh==2) cout<<"Now Comparison"<<endl;
	if(nh==3) cout<<"Now the division"<<endl;
	for(int i=0; i<40;i++){
	  if(Norm[i]>0) cout<<Corr[i]/Norm[i]<<endl;
	}
    }
  }
}
Exemplo n.º 9
0
void plotHistHi() {



  gStyle->SetOptStat(0);

  set_plot_style();

  TFile *f = new TFile("./../root_files/hists.root");


  // sim-to-reco hists
  TH2F *hSim = (TH2F*) f->Get("hitrkEffAnalyzer/hsim"); hSim->GetYaxis()->SetRangeUser(0,10);
  TH2F *hAcc = (TH2F*) f->Get("hitrkEffAnalyzer/hacc"); hAcc->GetYaxis()->SetRangeUser(0,10);
  TH2F *hEff = (TH2F*) f->Get("hitrkEffAnalyzer/heff"); hEff->GetYaxis()->SetRangeUser(0,10);
  TH2F *hMul = (TH2F*) f->Get("hitrkEffAnalyzer/hmul"); hMul->GetYaxis()->SetRangeUser(0,10);

  // reco-to-sim hists
  TH2F *hRec = (TH2F*) f->Get("hitrkEffAnalyzer/hrec"); hRec->GetYaxis()->SetRangeUser(0,10);
  TH2F *hFak = (TH2F*) f->Get("hitrkEffAnalyzer/hfak"); hFak->GetYaxis()->SetRangeUser(0,10);
  TH2F *hSec = (TH2F*) f->Get("hitrkEffAnalyzer/hsec"); hSec->GetYaxis()->SetRangeUser(0,10);

  // ratio histograms
  TH2F *rAcc = (TH2F*) hAcc->Clone("rAcc");
  TH2F *rEff = (TH2F*) hEff->Clone("rEff");
  TH2F *rMul = (TH2F*) hMul->Clone("rMul");
  TH2F *rFak = (TH2F*) hFak->Clone("rFak");
  TH2F *rSec = (TH2F*) hSec->Clone("rSec");
  //TH2F *rDec = (TH2F*) hDec->Clone("rDec");

  //---------------------------------------------

  // acceptance fraction
  TCanvas *c1 = new TCanvas("c1","Acceptance Fraction",600,500);
  gPad->SetRightMargin(0.15);
  rAcc->Divide(hAcc,hSim,1,1,"B");
  rAcc->SetStats(0);
  rAcc->SetMaximum(1.0); rAcc->SetMinimum(0.0);
  rAcc->SetTitle("Geometrical Acceptance");
  rAcc->Draw("colz");

  // reco efficiency fraction
  TCanvas *c2 = new TCanvas("c2","Reco Efficiency Fraction",600,500);
  gPad->SetRightMargin(0.15);
  rEff->Divide(hEff,hAcc,1,1,"B");
  rEff->SetStats(0);
  rEff->SetMaximum(1.0); rEff->SetMinimum(0.0);
  rEff->SetTitle("Algorithmic Efficiency");
  rEff->Draw("colz");

  // multiple reco fraction
  TCanvas *c3 = new TCanvas("c3","Multiple Reco Fraction",600,500);
  gPad->SetRightMargin(0.15);
  rMul->Divide(hMul,hAcc,1,1,"B");
  rMul->SetStats(0);
  rMul->SetMaximum(0.00049); rMul->SetMinimum(0.0);
  rMul->SetTitle("Multiple Reconstruction Fraction");
  rMul->Draw("colz");

  // fake reco fraction
  TCanvas *c4 = new TCanvas("c4","Fake Reco Fraction",600,500);
  gPad->SetRightMargin(0.15);
  rFak->Divide(hFak,hRec,1,1,"B");
  rFak->SetStats(0);
  rFak->SetMaximum(0.1); rFak->SetMinimum(0.0);
  rFak->SetTitle("Fake Reconstruction Fraction");
  rFak->Draw("colz");

  // secondary reco fraction
  TCanvas *c5 = new TCanvas("c5","Secondary Fraction",600,500);  
  gPad->SetRightMargin(0.15);
  rSec->Divide(hSec,hRec,1,1,"B");
  rSec->SetStats(0);
  rSec->SetMaximum(0.05); rSec->SetMinimum(0.0);
  rSec->SetTitle("Non-Primary Reconstruction Fraction");
  rSec->Draw("colz");

  //---------------------------------------------

  // find bins corresponding to projections for below
  Int_t ptbin04=hSim->GetYaxis()->FindBin(0.91);
  Int_t ptbin20=hSim->GetYaxis()->FindBin(2.01);
  Int_t ptbins=hSim->GetYaxis()->GetNbins();
  Int_t etabin24m=hSim->GetXaxis()->FindBin(-2.39);
  Int_t etabin24p=hSim->GetXaxis()->FindBin(2.39);
  Int_t etabin10m=hSim->GetXaxis()->FindBin(-0.99);
  Int_t etabin10p=hSim->GetXaxis()->FindBin(0.99);

  cout << "etabin10m: " << etabin10m << " etabin10p: " << etabin10p << endl;
  cout << "etabin10m: " << etabin24m << " etabin10p: " << etabin24p << endl;

  // projected hists: pt > 0.9 GeV/c
  TH1D* hSimEta = (TH1D*) hSim->ProjectionX("hSimEta",ptbin04,ptbins,"e");
  TH1D* hAccEta = (TH1D*) hAcc->ProjectionX("hAccEta",ptbin04,ptbins,"e");
  TH1D* hEffEta = (TH1D*) hEff->ProjectionX("hEffEta",ptbin04,ptbins,"e");
  TH1D* hMulEta = (TH1D*) hMul->ProjectionX("hMulEta",ptbin04,ptbins,"e");
  TH1D* hRecEta = (TH1D*) hRec->ProjectionX("hRecEta",ptbin04,ptbins,"e");
  TH1D* hFakEta = (TH1D*) hFak->ProjectionX("hFakEta",ptbin04,ptbins,"e");
  TH1D* hSecEta = (TH1D*) hSec->ProjectionX("hSecEta",ptbin04,ptbins,"e");

  // projected hists: pt > 2.0 GeV/c
  TH1D* hSimEta2 = (TH1D*) hSim->ProjectionX("hSimEta2",ptbin20,ptbins,"e");
  TH1D* hAccEta2 = (TH1D*) hAcc->ProjectionX("hAccEta2",ptbin20,ptbins,"e");
  TH1D* hEffEta2 = (TH1D*) hEff->ProjectionX("hEffEta2",ptbin20,ptbins,"e");
  TH1D* hMulEta2 = (TH1D*) hMul->ProjectionX("hMulEta2",ptbin20,ptbins,"e");
  TH1D* hRecEta2 = (TH1D*) hRec->ProjectionX("hRecEta2",ptbin20,ptbins,"e");
  TH1D* hFakEta2 = (TH1D*) hFak->ProjectionX("hFakEta2",ptbin20,ptbins,"e");
  TH1D* hSecEta2 = (TH1D*) hSec->ProjectionX("hSecEta2",ptbin20,ptbins,"e");

  TH1D* hDumEta = new TH1D("hDumEta",";#eta",60,-2.4,2.4); hDumEta->SetMaximum(1.0);
  hDumEta->GetXaxis()->CenterTitle(); hDumEta->GetYaxis()->SetTitleOffset(1.8);
  TH1D* hDumEta2 = (TH1D*) hDumEta->Clone("hDumEta2"); hDumEta2->SetMaximum(0.1); 
  TH1D* hDumEta3 = (TH1D*) hDumEta->Clone("hDumEta3"); hDumEta3->SetMaximum(0.00049); 


  // projected hists: abs(eta) < 1.0
  TH1D* hSimPt  = (TH1D*) hSim->ProjectionY("hSimPt",etabin10m,etabin10p,"e");
  TH1D* hAccPt  = (TH1D*) hAcc->ProjectionY("hAccPt",etabin10m,etabin10p,"e");
  TH1D* hEffPt  = (TH1D*) hEff->ProjectionY("hEffPt",etabin10m,etabin10p,"e");
  TH1D* hMulPt  = (TH1D*) hMul->ProjectionY("hMulPt",etabin10m,etabin10p,"e");
  TH1D* hRecPt  = (TH1D*) hRec->ProjectionY("hRecPt",etabin10m,etabin10p,"e");
  TH1D* hFakPt  = (TH1D*) hFak->ProjectionY("hFakPt",etabin10m,etabin10p,"e");
  TH1D* hSecPt  = (TH1D*) hSec->ProjectionY("hSecPt",etabin10m,etabin10p,"e");

  // projected hists: abs(eta) < 2.4
  TH1D* hSimPt2  = (TH1D*) hSim->ProjectionY("hSimPt2",etabin24m,etabin24p,"e");
  TH1D* hAccPt2  = (TH1D*) hAcc->ProjectionY("hAccPt2",etabin24m,etabin24p,"e");
  TH1D* hEffPt2  = (TH1D*) hEff->ProjectionY("hEffPt2",etabin24m,etabin24p,"e");
  TH1D* hMulPt2  = (TH1D*) hMul->ProjectionY("hMulPt2",etabin24m,etabin24p,"e");
  TH1D* hRecPt2  = (TH1D*) hRec->ProjectionY("hRecPt2",etabin24m,etabin24p,"e");
  TH1D* hFakPt2  = (TH1D*) hFak->ProjectionY("hFakPt2",etabin24m,etabin24p,"e");
  TH1D* hSecPt2  = (TH1D*) hSec->ProjectionY("hSecPt2",etabin24m,etabin24p,"e");
  
  TH1D* hDumPt = new TH1D("hDumPt",";p_{T} [GeV/c]",80,0.0,10.0); hDumPt->SetMaximum(1.0);
  hDumPt->GetXaxis()->CenterTitle(); hDumPt->GetYaxis()->SetTitleOffset(1.8);
  TH1D* hDumPt2 = (TH1D*) hDumPt->Clone("hDumPt2"); hDumPt2->SetMaximum(0.1); 
  TH1D* hDumPt3 = (TH1D*) hDumPt->Clone("hDumPt3"); hDumPt3->SetMaximum(0.00049); 

  // Acceptance
  TGraphAsymmErrors *gAccEta = new TGraphAsymmErrors(); gAccEta->SetName("gAccEta");
  gAccEta->BayesDivide(hAccEta,hSimEta);
  gAccEta->SetMarkerStyle(25);
  gAccEta->SetLineStyle(2);
  gAccEta->SetLineColor(2);
  gAccEta->SetMarkerColor(2);

  TGraphAsymmErrors *gAccPt = new TGraphAsymmErrors(); gAccPt->SetName("gAccPt");
  gAccPt->BayesDivide(hAccPt,hSimPt);
  gAccPt->SetMarkerStyle(24);
  gAccPt->SetLineColor(4);
  gAccPt->SetMarkerColor(4);

  TGraphAsymmErrors *gAccEta2 = new TGraphAsymmErrors(); gAccEta2->SetName("gAccEta2");
  gAccEta2->BayesDivide(hAccEta2,hSimEta2);
  gAccEta2->SetMarkerStyle(24);
  gAccEta2->SetLineColor(4);
  gAccEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gAccPt2 = new TGraphAsymmErrors(); gAccPt2->SetName("gAccPt2");
  gAccPt2->BayesDivide(hAccPt2,hSimPt2);
  gAccPt2->SetMarkerStyle(25);
  gAccPt2->SetLineStyle(2);
  gAccPt2->SetLineColor(2);
  gAccPt2->SetMarkerColor(2);

  TLegend *legEta = new TLegend(0.35,0.3,0.65,0.5);
  legEta->SetFillColor(0); legEta->SetBorderSize(0);
  legEta->AddEntry(gAccEta,"p_{T} > 0.9 GeV/c","lp");
  legEta->AddEntry(gAccEta2,"p_{T} > 2.0 GeV/c","lp");

  TLegend *legPt = new TLegend(0.4,0.3,0.6,0.5);
  legPt->SetFillColor(0); legPt->SetBorderSize(0);
  legPt->AddEntry(gAccPt2,"|#eta| < 2.4","lp");
  legPt->AddEntry(gAccPt,"|#eta| < 1.0","lp");

  TCanvas *c6 = new TCanvas("c6","Acceptance Fraction",900,500);
  c6->Divide(2,1);
  hDumEtaAcc=(TH1F*) hDumEta->Clone("hDumEtaAcc");
  hDumEtaAcc->GetYaxis()->SetTitle("Geometrical acceptance");
  hDumPtAcc=(TH1F*) hDumPt->Clone("hDumPtAcc");
  hDumPtAcc->GetYaxis()->SetTitle("Geometrical acceptance");
  c6->cd(1); hDumEtaAcc->Draw(); gAccEta->Draw("pc"); gAccEta2->Draw("pc"); legEta->Draw();
  c6->cd(2); hDumPtAcc->Draw(); gAccPt->Draw("pc"); gAccPt2->Draw("pc"); legPt->Draw();


  // Efficiency
  TGraphAsymmErrors *gEffEta = new TGraphAsymmErrors(); gEffEta->SetName("gEffEta");
  gEffEta->BayesDivide(hEffEta,hAccEta);
  gEffEta->SetMarkerStyle(25);
  gEffEta->SetLineStyle(2);
  gEffEta->SetLineColor(2);
  gEffEta->SetMarkerColor(2);

  TGraphAsymmErrors *gEffPt = new TGraphAsymmErrors(); gEffPt->SetName("gEffPt");
  gEffPt->BayesDivide(hEffPt,hAccPt);
  gEffPt->SetMarkerStyle(24);
  gEffPt->SetLineColor(4);
  gEffPt->SetMarkerColor(4);

  TGraphAsymmErrors *gEffEta2 = new TGraphAsymmErrors(); gEffEta2->SetName("gEffEta2");
  gEffEta2->BayesDivide(hEffEta2,hAccEta2);
  gEffEta2->SetMarkerStyle(24);
  gEffEta2->SetLineColor(4);
  gEffEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gEffPt2 = new TGraphAsymmErrors(); gEffPt2->SetName("gEffPt2");
  gEffPt2->BayesDivide(hEffPt2,hAccPt2);
  gEffPt2->SetMarkerStyle(25);
  gEffPt2->SetLineStyle(2);
  gEffPt2->SetLineColor(2);
  gEffPt2->SetMarkerColor(2);

  TCanvas *c7 = new TCanvas("c7","Efficiency Fraction",900,500);
  c7->Divide(2,1);
  hDumEtaEff=(TH1F*) hDumEta->Clone("hDumEtaEff");
  hDumEtaEff->GetYaxis()->SetTitle("Algorithmic efficiency");
  hDumPtEff=(TH1F*) hDumPt->Clone("hDumPtEff");
  hDumPtEff->GetYaxis()->SetTitle("Algorithmic efficiency");
  c7->cd(1); hDumEtaEff->Draw(); gEffEta->Draw("pc"); gEffEta2->Draw("pc"); legEta->Draw();
  c7->cd(2); hDumPtEff->Draw(); gEffPt->Draw("pc"); gEffPt2->Draw("pc"); legPt->Draw();

  // Multiple Reco
  TGraphAsymmErrors *gMulEta = new TGraphAsymmErrors(); gMulEta->SetName("gMulEta");
  gMulEta->BayesDivide(hMulEta,hAccEta);
  gMulEta->SetMarkerStyle(25);
  gMulEta->SetLineStyle(2);
  gMulEta->SetLineColor(2);
  gMulEta->SetMarkerColor(2);

  TGraphAsymmErrors *gMulPt = new TGraphAsymmErrors(); gMulPt->SetName("gMulPt");
  gMulPt->BayesDivide(hMulPt,hAccPt);
  gMulPt->SetMarkerStyle(24);
  gMulPt->SetLineColor(4);
  gMulPt->SetMarkerColor(4);

  TGraphAsymmErrors *gMulEta2 = new TGraphAsymmErrors(); gMulEta2->SetName("gMulEta2");
  gMulEta2->BayesDivide(hMulEta2,hAccEta2);
  gMulEta2->SetMarkerStyle(24);
  gMulEta2->SetLineColor(4);
  gMulEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gMulPt2 = new TGraphAsymmErrors(); gMulPt2->SetName("gMulPt2");
  gMulPt2->BayesDivide(hMulPt2,hAccPt2);
  gMulPt2->SetMarkerStyle(25);
  gMulPt2->SetLineStyle(2);
  gMulPt2->SetLineColor(2);
  gMulPt2->SetMarkerColor(2);

  TCanvas *c8 = new TCanvas("c8","Multiple Fraction",900,500);
  c8->Divide(2,1);
  hDumEtaMul=(TH1F*) hDumEta3->Clone("hDumEtaMul");
  hDumEtaMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction");
  hDumPtMul=(TH1F*) hDumPt3->Clone("hDumPtMul");
  hDumPtMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction");
  legEta2 = (TLegend*) legEta->Clone(); legEta2->SetY1(0.65); legEta2->SetY2(0.85);
  legPt2 = (TLegend*) legPt->Clone(); legPt2->SetY1(0.65); legPt2->SetY2(0.85);
  c8->cd(1); hDumEtaMul->Draw(); gMulEta->Draw("pc"); gMulEta2->Draw("pc"); legEta2->Draw();
  c8->cd(2); hDumPtMul->Draw(); gMulPt->Draw("pc"); gMulPt2->Draw("pc"); legPt2->Draw();

  // Fakes
  TGraphAsymmErrors *gFakEta = new TGraphAsymmErrors();  gFakEta->SetName("gFakEta");
  gFakEta->BayesDivide(hFakEta,hRecEta);
  gFakEta->SetMarkerStyle(25);
  gFakEta->SetLineStyle(2);
  gFakEta->SetLineColor(2);
  gFakEta->SetMarkerColor(2);

  TGraphAsymmErrors *gFakPt = new TGraphAsymmErrors(); gFakPt->SetName("gFakPt");
  gFakPt->BayesDivide(hFakPt,hRecPt);
  gFakPt->SetMarkerStyle(24);
  gFakPt->SetLineColor(4);
  gFakPt->SetMarkerColor(4);

  TGraphAsymmErrors *gFakEta2 = new TGraphAsymmErrors(); gFakEta2->SetName("gFakEta2");
  gFakEta2->BayesDivide(hFakEta2,hRecEta2);
  gFakEta2->SetMarkerStyle(24);
  gFakEta2->SetLineColor(4);
  gFakEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gFakPt2 = new TGraphAsymmErrors();  gFakPt2->SetName("gFakPt2");
  gFakPt2->BayesDivide(hFakPt2,hRecPt2);
  gFakPt2->SetMarkerStyle(25);
  gFakPt2->SetLineStyle(2);
  gFakPt2->SetLineColor(2);
  gFakPt2->SetMarkerColor(2);

  TCanvas *c9 = new TCanvas("c9","Fake Fraction",900,500);
  c9->Divide(2,1);
  hDumEtaFak=(TH1F*) hDumEta2->Clone("hDumEtaMul");
  hDumEtaFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction");
  hDumPtFak=(TH1F*) hDumPt2->Clone("hDumPtMul");
  hDumPtFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction");
  c9->cd(1); hDumEtaFak->Draw(); gFakEta->Draw("pc"); gFakEta2->Draw("pc"); legEta2->Draw();
  c9->cd(2); hDumPtFak->Draw(); gFakPt->Draw("pc"); gFakPt2->Draw("pc"); legPt2->Draw();

  // Secondaries
  TGraphAsymmErrors *gSecEta = new TGraphAsymmErrors(); gSecEta->SetName("gSecEta");
  gSecEta->BayesDivide(hSecEta,hRecEta);
  gSecEta->SetMarkerStyle(25);
  gSecEta->SetLineStyle(2);
  gSecEta->SetLineColor(2);
  gSecEta->SetMarkerColor(2);

  TGraphAsymmErrors *gSecPt = new TGraphAsymmErrors(); gSecPt->SetName("gSecPt");
  gSecPt->BayesDivide(hSecPt,hRecPt);
  gSecPt->SetMarkerStyle(24);
  gSecPt->SetLineColor(4);
  gSecPt->SetMarkerColor(4);

  TGraphAsymmErrors *gSecEta2 = new TGraphAsymmErrors(); gSecEta2->SetName("gSecEta2");
  gSecEta2->BayesDivide(hSecEta2,hRecEta2);
  gSecEta2->SetMarkerStyle(24);
  gSecEta2->SetLineColor(4);
  gSecEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gSecPt2 = new TGraphAsymmErrors();  gSecPt2->SetName("gSecPt2");
  gSecPt2->BayesDivide(hSecPt2,hRecPt2);
  gSecPt2->SetMarkerStyle(25);
  gSecPt2->SetLineStyle(2);
  gSecPt2->SetLineColor(2);
  gSecPt2->SetMarkerColor(2);

  TCanvas *c10 = new TCanvas("c10","Secondary Fraction",900,500);
  c10->Divide(2,1);
  hDumEtaSec=(TH1F*) hDumEta2->Clone("hDumEtaMul");
  hDumEtaSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction");
  hDumPtSec=(TH1F*) hDumPt2->Clone("hDumPtMul");
  hDumPtSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction");
  c10->cd(1); hDumEtaSec->Draw(); gSecEta->Draw("pc"); gSecEta2->Draw("pc"); legEta2->Draw();
  c10->cd(2); hDumPtSec->Draw(); gSecPt->Draw("pc"); gSecPt2->Draw("pc"); legPt2->Draw();

  /*
  printCanvases(c1,"hitrk_can1",0,1);
  printCanvases(c2,"hitrk_can2",0,1);
  printCanvases(c3,"hitrk_can3",0,1);
  printCanvases(c4,"hitrk_can4",0,1);
  printCanvases(c5,"hitrk_can5",0,1);
  printCanvases(c6,"hitrk_can6",0,1);
  printCanvases(c7,"hitrk_can7",0,1);
  printCanvases(c8,"hitrk_can8",0,1);
  printCanvases(c9,"hitrk_can9",0,1);
  printCanvases(c10,"hitrk_can10",0,1);
  */


  /*
  TFile *f = new TFile("trkEffPY8.root","RECREATE");
  gAccPt->Write(); gAccPt2->Write(); gAccEta->Write(); gAccEta2->Write();
  gEffPt->Write(); gEffPt2->Write(); gEffEta->Write(); gEffEta2->Write();
  gMulPt->Write(); gMulPt2->Write(); gMulEta->Write(); gMulEta2->Write();
  gFakPt->Write(); gFakPt2->Write(); gFakEta->Write(); gFakEta2->Write();
  gSecPt->Write(); gSecPt2->Write(); gSecEta->Write(); gSecEta2->Write();
  f->Close();
  */
}
Exemplo n.º 10
0
void makeValidationPlots(TTree* tree, sel_t type,bool isMC) {

  SelectionStrings strings;

  TString tag="";

  TString lowString="",midString="",highString="";

  switch(type) {
  case kReal:
    tag = "_realselection";
    break;
  case kShift:
    tag = "_side";
    break;
  case kSingleIso:
    tag = "_singleIso";
    break;
  }
  if(isMC) {
    tag+="__DiPhotonJets";
  }
  Double_t Red[] = {0.00, 0.70, 0.90, 1.00, 1.00, 1.00, 1.00};
  Double_t Green[] ={0.00, 0.70, 0.90, 1.00, 0.90, 0.70, 0.00};
  Double_t Blue[] = {1.00, 1.00, 1.00, 1.00, 0.90, 0.70, 0.00};
  Double_t Length[] =  {0.00, 0.20, 0.35, 0.50, 0.65, 0.8, 1.00};

  TCanvas cv;

  std::vector<TH2F*> nSigs;
  std::vector<TH2F*> nSigs_gauss;

  cv.SetLogx();
  for(int iBox=0; iBox<SigRegionBinning::nBoxes; iBox++) {
    TString boxName = SigRegionBinning::getRegionName(static_cast<SigRegionBinning::BinningRegion>(iBox));
    switch(type) {
    case kReal:
      lowString = strings.baseSelection+" && mgg>103 && mgg<120";
      midString = strings.baseSelection+" && "+strings.mggSigRegion[iBox];
      highString = strings.baseSelection+" && mgg>131 && mgg<160";
      break;
    case kShift:
      lowString = strings.baseSelection+" && mgg>130 && mgg<140";
      midString = strings.baseSelection+" && mgg>140 && mgg<150";
      highString = strings.baseSelection+" && mgg>150 && mgg<160";
      break;
    case kSingleIso:
      lowString = TString("(pho1_pt>40 && pho2_pt>25 && abs(pho1_eta)<1.48 && abs(pho2_eta)<1.48 && (pho1_pass_iso || pho2_pass_iso) && !(pho1_pass_iso && pho2_pass_iso))")+" && mgg>103 && mgg<120";
      midString = TString("(pho1_pt>40 && pho2_pt>25 && abs(pho1_eta)<1.48 && abs(pho2_eta)<1.48 && (pho1_pass_iso || pho2_pass_iso) && !(pho1_pass_iso && pho2_pass_iso))")+" && "+strings.mggSigRegion[iBox];
      highString = TString("(pho1_pt>40 && pho2_pt>25 && abs(pho1_eta)<1.48 && abs(pho2_eta)<1.48 && (pho1_pass_iso || pho2_pass_iso) && !(pho1_pass_iso && pho2_pass_iso))")+" && mgg>131 && mgg<160";      
      break;
    }


    TH2F* low = SigRegionBinning::makeHistogram(static_cast<SigRegionBinning::BinningRegion>(iBox),"low");
    TH2F* mid = SigRegionBinning::makeHistogram(static_cast<SigRegionBinning::BinningRegion>(iBox),"mid");
    TH2F* high = SigRegionBinning::makeHistogram(static_cast<SigRegionBinning::BinningRegion>(iBox),"high");
  
    TH2F* nsig = SigRegionBinning::makeHistogram(static_cast<SigRegionBinning::BinningRegion>(iBox),"nsig_"+boxName);
    TH2F* nsig_gauss = SigRegionBinning::makeHistogram(static_cast<SigRegionBinning::BinningRegion>(iBox),"nsig_gauss_"+boxName);

    low->SetMinimum(0.1);
    mid->SetMinimum(0.1);
    high->SetMinimum(0.1);

    tree->Project("low","Rsq:MR",lowString+" && "+strings.boxDefs[iBox]);
    tree->Project("mid","Rsq:MR",midString+" && "+strings.boxDefs[iBox]);
    tree->Project("high","Rsq:MR",highString+" && "+strings.boxDefs[iBox]);

    //SigRegionBinning::formatSigRegionPlot(low);
    //SigRegionBinning::formatSigRegionPlot(mid);
    //SigRegionBinning::formatSigRegionPlot(high);

    //get the difference in the prediction
    TH2F* low_norm = (TH2F*)low->Clone("low_norm");
    TH2F* high_norm = (TH2F*)high->Clone("high_norm");

    low_norm->Scale(1./low_norm->Integral());
    high_norm->Scale(1./high_norm->Integral());

    TH2F* pred_diff = (TH2F*)high_norm->Clone("pred_diff");
    pred_diff->Add(low_norm,-1);

    TH2F* norm_av = (TH2F*)low_norm->Clone("norm_av");
    norm_av->Add(high_norm);
    norm_av->Scale(0.5);

    TH2F* pred_per_diff = (TH2F*)pred_diff->Clone("pred_per_diff");
    pred_per_diff->Divide(norm_av);
    cv.SetLogx(1);
    cv.SetLogy(0);
    pred_per_diff->Draw("COLZ TEXT");
    cv.SaveAs("RsqMR_high_minus_low_div_av_"+boxName+tag+".png");
    cv.SetLogx(1);
    cv.SetLogy(0);

    TH1D* low_1D = SigRegionBinning::make1DProj(low);
    TH1D* high_1D = SigRegionBinning::make1DProj(high);
    
    pred_per_diff->SetYTitle("high - low / (high+low/2)");
    TH1D* pred_per_diff_1D = SigRegionBinning::make1DProj(pred_per_diff);
    cv.SetLogx(0);
    cv.SetLogy(0);
    pred_per_diff_1D->Draw();
    cv.SaveAs("RsqMR_1D_high_minus_low_div_av_"+boxName+tag+".png");
    cv.SetLogx(1);
    cv.SetLogy(0);
    
    TFile out("RsqMR_1D_high_minus_low_div_av_"+boxName+tag+".root","RECREATE");
    low->Write();
    high->Write();
    low_1D->Write();
    high_1D->Write();
    pred_per_diff_1D->Write();
    pred_per_diff->Write();
    out.Close();



    TH2F* sideband_tot = (TH2F*)low->Clone("sideband_tot");
    sideband_tot->Add(high);


    sideband_tot->Draw("COLZ TEXT");
    cv.SetLogz();
    cv.SaveAs("RsqMR_low_plus_high_"+boxName+tag+".png");
    cv.SetLogz(0);

    float sf = mid->Integral()/sideband_tot->Integral();
    std::cout << "sf: " << sf << std::endl;
    TH2F* sideband_pred = (TH2F*)sideband_tot->Clone("sideband_pred");

    sideband_pred->Scale(sf);

    sideband_pred->Draw("COLZ TEXT");
    cv.SetLogz();
    cv.SaveAs("RsqMR_sideband_pred_"+boxName+tag+".png");
    cv.SetLogz(0);

    mid->Draw("COLZ TEXT");
    cv.SetLogz();
    cv.SaveAs("RsqMR_mid_"+boxName+tag+".png");
    cv.SetLogz(0);

    TH1D* pred_1D = SigRegionBinning::make1DProj(sideband_pred,true,sf);
    TH1D* mid_1D  = SigRegionBinning::make1DProj(mid);
    cv.SetLogx(0);
    cv.SetLogy();
    mid_1D->SetMarkerStyle(20);
    mid_1D->SetMarkerColor(kBlack);
    mid_1D->SetMarkerSize(1.4);

    pred_1D->SetFillColor(kRed);
    pred_1D->SetFillStyle(3001);
    pred_1D->SetLineColor(kRed);
    pred_1D->SetLineWidth(2);
    pred_1D->SetMarkerSize(0);
    pred_1D->Draw("L E2");
    pred_1D->Draw("LSAME");
    mid_1D->Draw("PSAME");
    cv.SaveAs("RsqMR_1D_obs_sideband_pred_"+boxName+tag+".png");    
    cv.SetLogx(1);
    cv.SetLogy(0);


    TH2F* perdiff = (TH2F*)mid->Clone("perdiff");
    perdiff->Add(sideband_pred,-1);
    perdiff->Divide(perdiff);
    perdiff->Draw("COLZ TEXT");

    cv.SaveAs("RsqMR_percentDiff_"+boxName+tag+".png");
    

    for(int iXbin=1; iXbin<=sideband_pred->GetNbinsX(); iXbin++) {
      for(int iYbin=1; iYbin<=sideband_pred->GetNbinsY(); iYbin++) {
	float obs = mid->GetBinContent(iXbin,iYbin);
	float exp = sideband_pred->GetBinContent(iXbin,iYbin);
	float err = TMath::Sqrt(sideband_tot->GetBinContent(iXbin,iYbin))*sf;
	float ns = fabs(TMath::NormQuantile(SigRegionBinning::pValue(obs,exp,err/exp)/2));
	if(obs<exp) ns*=-1;

	nsig->SetBinContent(iXbin,iYbin,ns);
	std::cout << "\t" << iXbin << "  " << iYbin << "  " << nsig->GetBinContent(iXbin,iYbin) << std::endl;

	float gauss_err = TMath::Sqrt(TMath::Power(err,2)+exp);
	if(gauss_err==0) gauss_err=1;
	nsig_gauss->SetBinContent(iXbin,iYbin,(obs-exp)/gauss_err);

      }
    }
    
    SigRegionBinning::formatSigRegionPlot(nsig); 
    SigRegionBinning::formatSigRegionPlot(nsig_gauss); 
    //cv.SetLogx();

    nSigs.push_back(nsig);
    nSigs_gauss.push_back(nsig_gauss);
    

    delete low;
    delete mid;
    delete high;
    delete sideband_tot;
    delete sideband_pred;

  }

  for(int iBox=0; iBox<SigRegionBinning::nBoxes; iBox++) {
    TString boxName = SigRegionBinning::getRegionName(static_cast<SigRegionBinning::BinningRegion>(iBox));
    TColor::CreateGradientColorTable(7,Length,Red,Green,Blue,999);
    TH2F* nsig = nSigs.at(iBox);

    nsig->SetMaximum(5.1);
    nsig->SetMinimum(-5.1);
    nsig->SetContour(999);


    nsig->Draw("COLZ TEXT0");
    cv.SaveAs("RsqMR_low_plus_high_RAWSUM_NSIGMA_"+boxName+tag+".png");
    
    TH2F* nsig_gauss = nSigs_gauss.at(iBox);
    nsig_gauss->SetMaximum(5.1);
    nsig_gauss->SetMinimum(-5.1);
    nsig_gauss->SetContour(999);

    nsig_gauss->Draw("COLZ");
    cv.SaveAs("RsqMR_low_plus_high_RAWSUM_NSIGMAGAUSS_"+boxName+tag+".png");
    

    TH1D* nsig_gauss_1D = SigRegionBinning::make1DProj(nsig_gauss);

    nsig_gauss_1D->SetLineColor(kBlack);
    nsig_gauss_1D->SetLineWidth(1.5);
    nsig_gauss_1D->SetMinimum(-5.1);
    nsig_gauss_1D->SetMaximum(5.1);
    nsig_gauss_1D->SetYTitle("Number of Sigma");
    cv.SetLogx(0);
    cv.SetLogy(0);
    nsig_gauss_1D->Draw();
    cv.SaveAs("RsqMR_low_plus_high_1D_RAWSUM_NSIGMAGAUSS_"+boxName+tag+".png");
    cv.SetLogx(1);
  }
}
Exemplo n.º 11
0
void make_SMS_exclusion(TH2F *rawlimits,TH2F *xsec,int scantype,std::string& scanx, bool isobserved) {
  TH2F *limits = prep_histo(rawlimits,scantype); // this is to be independent of the style used at creation time
  //here we get some limits and the cross section; we want to make an exclusion plot!
  TH2F *rellimits = (TH2F*)limits->Clone("rellimits");
  TH2F *rellimitsd3 = (TH2F*)limits->Clone("rellimitsd3"); // one third the cross section ("divided by 3" -> d3)
  TH2F *rellimitst3 = (TH2F*)limits->Clone("rellimitst3"); // three times the cross section ("times 3" -> t3)
  
  if(!xsec ) {
    cout << "Watch out, cross section map is invalid!" << endl;
    delete limits;
    return;
  }
  
  rellimits->Divide(xsec);
  
  
  for(int i=1;i<=rellimits->GetNbinsX();i++) {
    for(int j=1;j<=rellimits->GetNbinsY();j++) {
      rellimitst3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))/3.0);
      rellimitsd3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))*3.0);
    }
  }
  

//  TH2F *exclusionshape = make_exclusion_shape(rellimits,1);
//  TH2F *exclusionshapet3 = make_exclusion_shape(rellimitst3,2);
//  TH2F *exclusionshaped3 = make_exclusion_shape(rellimitsd3,3);
  
  //Now let's produce the plots!
  
  set_range(xsec,scantype,false);
  set_range(limits,scantype,false);
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  
  bool drawdoubleline=false; //draw nice thin line on top of thick outer line
  TGraph *exclline = MarcosExclusionLine(rellimits, scantype);
  TGraph *thinexcline = thin_line(exclline);
  
  TGraph *excllinet3 = MarcosExclusionLine(rellimitst3, scantype);
  excllinet3->SetLineStyle(2);
  TGraph *thinexclinet3 = thin_line(excllinet3);

  TGraph *excllined3 = MarcosExclusionLine(rellimitsd3, scantype);
  excllined3->SetLineStyle(3);
  TGraph *thinexclined3 = thin_line(excllined3);

//  produce_extensive_plots(xsec,limits,rellimits, rellimitst3, rellimitsd3,scantype);
  
  TCanvas *finalcanvas = new TCanvas("finalcanvas","finalcanvas");
  finalcanvas->SetLogz(1);
  finalcanvas->cd();
  limits->SetZTitle("95% CL upper limit on #sigma [pb]");
  limits->Draw("COLZ");

  TLine *desertline;
  if(drawefficiencydesertline) {
	desertline = new TLine(375,50,1200,875);
	desertline->SetLineWidth(3);
	//desertline->SetLineWidth(4); // paper style
	desertline->SetLineColor(kBlack);
	desertline->Draw("same");
  }


//  fill_with_text(exclline,excllined3,excllinet3,finalcanvas,scantype,scanx);
  stringstream real;
  real << "Limits/";
  if(!isobserved) real << "expected/expected_";
  real << "final_exclusion__" << limits->GetName();
  
  if(Contains(limits->GetName(),"bestlimits")) {
    cout << "----------> " << limits->GetName() << endl;
    TFile *f = new TFile("limits.root","RECREATE");
    thinexcline->SetName("ExclusionLine");
    limits->SetName("UpperLimits");
    limits->Write();
    thinexcline->Write();
    f->Close();
  }
  
  
  exclline->Draw("l");
  if(drawdoubleline) thinexcline->Draw("");
  excllinet3->Draw("");
  if(drawdoubleline) thinexclinet3->Draw("");
  excllined3->Draw("");
  if(drawdoubleline) thinexclined3->Draw("");
  
  CompleteSave(finalcanvas,real.str());

  
  
  //-------------------------------------- extensive plots 
  
  TCanvas *ca = new TCanvas("ca","ca",2400,1200);
  ca->Divide(4,2);
  ca->cd(1);
  ca->cd(1)->SetLogz(1);
  xsec->GetZaxis()->SetRangeUser(0.001,1000);
  xsec->Draw("COLZ");
  TText *title0 = write_title("Reference Cross Section");
  title0->Draw("same");
  ca->cd(2);
  ca->cd(2)->SetLogz(1);
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  limits->Draw("COLZ");
  TText *title = write_title("Cross Section Upper Limit");
  title->Draw("same");
  ca->cd(3);
  ca->cd(3)->SetLogz(1);
  TH2F *limit_ref = (TH2F*)limits->Clone("limit_ref");
  limit_ref->Divide(xsec);
  limit_ref->GetZaxis()->SetRangeUser(limits_ratio_lower_bound,limits_ratio_upper_bound);
  limit_ref->Draw("COLZ");
  TText *title2 = write_title("Cross Section UL / XS");
  title2->Draw("same");
  ca->cd(4);
  ca->cd(4)->SetLogz(1);
  limits->SetTitle("");
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  limits->SetZTitle("95% CL upper limit on #sigma [pb]");

  limits->Draw("COLZ");


  ca->cd(4);
  exclline->Draw();
  thinexcline->Draw();
  excllinet3->Draw();
  thinexclinet3->Draw();
  excllined3->Draw();
  thinexclined3->Draw();
  stringstream partial;
  partial << "Limits/";
  if(!isobserved) real << "expected/expected_";
  partial << "exclusion__" << limits->GetName();
  fill_with_text(exclline,excllined3,excllinet3,ca->cd(4),scantype);
//  CompleteSave(ca,partial.str());

  ca->cd(5);
  (hardlimit(rellimitsd3))->Draw("COL");
  TText *c = write_title("Exclusion shape for #sigma_{ref}/3");
  c->Draw();
  excllined3->Draw("same");
  
  ca->cd(6);
  (hardlimit(rellimits))->Draw("COL");
  exclline->Draw("same");
  TText *b = write_title("Exclusion shape for #sigma_{ref}");
  b->Draw();
  
  ca->cd(7);
  (hardlimit(rellimitst3))->Draw("COL");
  excllinet3->Draw("same");
  TText *a = write_title("Exclusion shape for 3x#sigma_{ref}");
  a->Draw();
  
  CompleteSave(ca,partial.str()+"__PlusInfo");
  delete ca;
  delete limits;
  
  //---------------------------------------</extensive plots>
  delete finalcanvas;
}
//*************************************************************************************************
//Main part of the macro
//*************************************************************************************************
void NormalizeElectronNtuple(const string InputFilename, const string datasetName, 
                             const string OutputFilename, Int_t sampleType, 
                             const string normalizationFile = "") {


  Double_t normalizationWeight = 0;
  Bool_t useReweightFactor = kFALSE;
  TH2F *PtEtaReweightFactor = 0;
  Double_t overallWJetsNormalizationFactor = 0;

  //For Normalizing each sample individually
  if (sampleType == 0 || sampleType >= 10) {
    TTree* electronTree = getTreeFromFile(InputFilename.c_str());
    assert(electronTree);    
    MitNtupleElectron ele(electronTree);
    
    normalizationWeight = getNormalizationWeight(InputFilename, datasetName);
    //*************************************************************************************************
    //Create new normalized tree
    //*************************************************************************************************
    TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE");
    outputFile->cd();    
    TTree *normalizedTree = electronTree->CloneTree(0);
    
    for (int n=0;n<electronTree->GetEntries();n++) { 
      ele.GetEntry(n);

      if (sampleType == 10) {
        if (ele.electron_branch_passedSelectionCut == 1) {
          if (datasetName == "s09-wwll10-mc3" || datasetName == "s09-ttbar-mc3") {
            //for mu-e there should be only 1 electron candidate
            ele.electron_branch_weight = normalizationWeight; 
            normalizedTree->Fill(); 
          } else if (datasetName == "s09-we-mc3" || datasetName == "s09-wm-mc3" || datasetName == "s09-wt-mc3") {
            //For the W->enu sample, fill only the fake electron candidates.
            ele.electron_branch_weight = normalizationWeight; 
            if (ele.electron_branch_electronType < 100) {
              normalizedTree->Fill(); 
            }
          } else {
            cout << "Warning: The specified dataset " << datasetName 
                 << " is not recognized to be one of the selection cut samples.\n";
          }
        }        
      } else {
        //For regular samples just fill all electrons
        ele.electron_branch_weight = normalizationWeight; 
        normalizedTree->Fill(); 
      }      
    }
    normalizedTree->Write();
    cout << "Original Tree Entries: " << electronTree->GetEntries() << "  Normalized Tree Entries: " << normalizedTree->GetEntries() << endl;
    outputFile->Close();     
  }
  //For Normalization of Background sample
  else if (sampleType == 1) {
    TTree* electronTree = getTreeFromFile(InputFilename.c_str(), kFALSE);
    assert(electronTree);     
    MitNtupleElectron ele(electronTree);

    //*************************************************************************************************
    //Create new reweighted tree
    //*************************************************************************************************
    TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE");
    TTree *reweightedTree = electronTree->CloneTree(0);    

    if (normalizationFile == "") {
      //normalize according to total number of electrons expected in W+Jets/W+gamma bkg
      Double_t totalWeight = 0;
      for (int n=0;n<electronTree->GetEntries();n++) { 
        ele.GetEntry(n);
        totalWeight += ele.electron_branch_weight;
      }

      cout << "Input Bkg Ntuple Total Weight = " << totalWeight << endl;
      normalizationWeight = 1126.5 / totalWeight;
    } else {
      //do pt/eta Reweighting

      TFile *reweightInputFile = new TFile(normalizationFile.c_str(), "READ");
      assert(reweightInputFile);

      TH2F *WJetsFakeElectronPtEta = (TH2F*)reweightInputFile->Get("hWJetsFakeElectronPtEta");
      assert(WJetsFakeElectronPtEta);      
      WJetsFakeElectronPtEta = (TH2F*)(WJetsFakeElectronPtEta->Clone());
      WJetsFakeElectronPtEta->SetDirectory(0);
      reweightInputFile->Close();

      //Create histogram for reweighting factor
      PtEtaReweightFactor = (TH2F*)WJetsFakeElectronPtEta->Clone();
      PtEtaReweightFactor->SetName("PtEtaReweightFactor");
      PtEtaReweightFactor->SetDirectory(0);

      TH2F *BkgFakeElectronPtEta = new TH2F("BkgFakeElectronPtEta", ";Pt [GeV/c];#eta;" , WJetsFakeElectronPtEta->GetXaxis()->GetNbins(), WJetsFakeElectronPtEta->GetXaxis()->GetBinLowEdge(1), WJetsFakeElectronPtEta->GetXaxis()->GetBinUpEdge(WJetsFakeElectronPtEta->GetXaxis()->GetNbins()), WJetsFakeElectronPtEta->GetYaxis()->GetNbins(), WJetsFakeElectronPtEta->GetYaxis()->GetBinLowEdge(1), WJetsFakeElectronPtEta->GetYaxis()->GetBinUpEdge(WJetsFakeElectronPtEta->GetYaxis()->GetNbins()));
      BkgFakeElectronPtEta->SetDirectory(0);
      for (int n=0;n<electronTree->GetEntries();n++) { 
        ele.GetEntry(n);
        BkgFakeElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight);        
      }
      PtEtaReweightFactor->Divide(WJetsFakeElectronPtEta, BkgFakeElectronPtEta, 1.0,1.0,"B");

      useReweightFactor = kTRUE;    
    }

    cout << "Reweighting Background Ntuple\n";
    outputFile->cd();    

    //check Reweighting
    TH2F *ReweightedBkgFakeElectronPtEta = new TH2F("BkgFakeElectronPtEta", ";Pt [GeV/c];#eta;" , 200, 0, 200, 200, -3.0, 3.0);    
    ReweightedBkgFakeElectronPtEta->SetDirectory(0);
    for (int n=0;n<electronTree->GetEntries();n++) { 
      if (n%250000 == 0) cout << "Entry " << n << endl;
      ele.GetEntry(n);
      if (useReweightFactor) {
        Double_t reweightFactor = PtEtaReweightFactor->GetBinContent(PtEtaReweightFactor->GetXaxis()->FindFixBin(ele.electron_branch_pt),PtEtaReweightFactor->GetYaxis()->FindFixBin(ele.electron_branch_eta));
        ele.electron_branch_weight = ele.electron_branch_weight*reweightFactor;//*overallWJetsNormalizationFactor;
      } else {
        ele.electron_branch_weight = normalizationWeight;
      }
      reweightedTree->Fill(); 

      ReweightedBkgFakeElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight);
    }
    reweightedTree->Write();
    cout << "Original Tree Entries: " << electronTree->GetEntries() << "  Normalized Tree Entries: " << reweightedTree->GetEntries() << endl;
    outputFile->Close();
  
    TCanvas *cv = new TCanvas("BkgReweightedFakeElectronPtEta", "BkgReweightedFakeElectronPtEta", 0,0,800,600);
    ReweightedBkgFakeElectronPtEta->ProjectionX()->DrawCopy("E1");
    cv->SaveAs("BkgReweightedFakeElectronPt.gif");
    ReweightedBkgFakeElectronPtEta->ProjectionY()->DrawCopy("E1");
    cv->SaveAs("BkgReweightedFakeElectronEta.gif");
  } 
  
  //For Normalization of Signal sample
  else if (sampleType == 2) {
    TTree* electronTree = getTreeFromFile(InputFilename.c_str(), kFALSE);
    assert(electronTree);     
    MitNtupleElectron ele(electronTree);

    //*************************************************************************************************
    //Create new reweighted tree
    //*************************************************************************************************
    TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE");
    TTree *reweightedTree = electronTree->CloneTree(0);    

    if (normalizationFile == "") {
      //normalize according to total number of electrons expected in WW -> ee nunu signal
      Double_t totalWeight = 0;
      for (int n=0;n<electronTree->GetEntries();n++) { 
        ele.GetEntry(n);
        totalWeight += ele.electron_branch_weight;
      }

      cout << "Input Bkg Ntuple Total Weight = " << totalWeight << endl;
      normalizationWeight = 1126.5 / totalWeight;
    } else {
      //do pt/eta Reweighting

      TFile *reweightInputFile = new TFile(normalizationFile.c_str(), "READ");
      assert(reweightInputFile);
      TH2F *WWSigElectronPtEta = (TH2F*)reweightInputFile->Get("hWWRealElectronPtEta");
      assert(WWSigElectronPtEta);      
      WWSigElectronPtEta = (TH2F*)(WWSigElectronPtEta->Clone());
      WWSigElectronPtEta->SetDirectory(0);
      reweightInputFile->Close();

      //Create histogram for reweighting factor
      PtEtaReweightFactor = (TH2F*)WWSigElectronPtEta->Clone();
      PtEtaReweightFactor->SetName("PtEtaReweightFactor");
      PtEtaReweightFactor->SetDirectory(0);

      TH2F *SigSampleElectronPtEta = new TH2F("SigSampleElectronPtEta", ";Pt [GeV/c];#eta;" , WWSigElectronPtEta->GetXaxis()->GetNbins(), WWSigElectronPtEta->GetXaxis()->GetBinLowEdge(1), WWSigElectronPtEta->GetXaxis()->GetBinUpEdge(WWSigElectronPtEta->GetXaxis()->GetNbins()), WWSigElectronPtEta->GetYaxis()->GetNbins(), WWSigElectronPtEta->GetYaxis()->GetBinLowEdge(1), WWSigElectronPtEta->GetYaxis()->GetBinUpEdge(WWSigElectronPtEta->GetYaxis()->GetNbins()));
      SigSampleElectronPtEta->SetDirectory(0);
      for (int n=0;n<electronTree->GetEntries();n++) { 
        ele.GetEntry(n);
        SigSampleElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight);        
      }
      PtEtaReweightFactor->Divide(WWSigElectronPtEta, SigSampleElectronPtEta, 1.0,1.0,"B");

      useReweightFactor = kTRUE;    
    }

    cout << "Reweighting Signal Ntuple\n";
    outputFile->cd();    

    //check Reweighting
    TH2F *ReweightedSigRealElectronPtEta = new TH2F("ReweightedSigRealElectronPtEta", ";Pt [GeV/c];#eta;" , 200, 0, 200, 200, -3.0, 3.0);    
    ReweightedSigRealElectronPtEta->SetDirectory(0);
    for (int n=0;n<electronTree->GetEntries();n++) { 
      if (n%250000 == 0) cout << "Entry " << n << endl;
      ele.GetEntry(n);
      if (useReweightFactor) {
        Double_t reweightFactor = PtEtaReweightFactor->GetBinContent(PtEtaReweightFactor->GetXaxis()->FindFixBin(ele.electron_branch_pt),PtEtaReweightFactor->GetYaxis()->FindFixBin(ele.electron_branch_eta));
        ele.electron_branch_weight = ele.electron_branch_weight*reweightFactor;//*overallWJetsNormalizationFactor;
      } else {
        ele.electron_branch_weight = normalizationWeight;
      }
      reweightedTree->Fill(); 
      ReweightedSigRealElectronPtEta->Fill(ele.electron_branch_pt, ele.electron_branch_eta, ele.electron_branch_weight);
    }
    reweightedTree->Write();
    cout << "Original Tree Entries: " << electronTree->GetEntries() << "  Normalized Tree Entries: " << reweightedTree->GetEntries() << endl;
    outputFile->Close();
  
    TCanvas *cv = new TCanvas("BkgReweightedFakeElectronPtEta", "BkgReweightedFakeElectronPtEta", 0,0,800,600);
    ReweightedSigRealElectronPtEta->ProjectionX()->DrawCopy("E1");
    cv->SaveAs("SigReweightedRealElectronPt.gif");
    ReweightedSigRealElectronPtEta->ProjectionY()->DrawCopy("E1");
    cv->SaveAs("SigReweightedRealElectronEta.gif");
  } 
  else {
    cout << "Warning: Specified sampleType " << sampleType << " is not recognized.\n";
  }



}
Exemplo n.º 13
0
int InputForLimits(){
  TH1::SetDefaultSumw2(true);
  if(pcp)cout<<"going to set inputs"<<endl;

  Int_t NBR = 3;
  Float_t BR[] = { 1., 0.75, 0.5};

  TFile* bkgFile = new TFile( "../../BkgPrediction/BkgPrediction.root", "READ"); 
  TTree* bkgTree;
  bkgFile->GetObject( "ElAndMu", bkgTree);
  
  Float_t bkg = 0.;
  Float_t bkgTotUnc = 0.;

  Float_t obs = 0.;

  bkgTree->SetBranchAddress( "srData", &obs);
  bkgTree->SetBranchAddress( "srAllBkgCorr", &bkg);
  bkgTree->SetBranchAddress( "TotUnc", &bkgTotUnc);

  TFile* sigFile = new TFile( "../../SignalSystematics/SignalSys.root", "READ"); 

  std::vector<std::vector<TString> > sysColl;
  std::vector<TString> sys;
  sys.push_back(TString("JES_Up"));
  sys.push_back(TString("JES_Down"));
  sysColl.push_back(sys);

  sys.clear();
  sys.push_back(TString("BTagReweight_UpBC"));
  sys.push_back(TString("BTagReweight_DownBC"));
  sysColl.push_back(sys);

  sys.clear();
  sys.push_back(TString("BTagReweight_UpLight"));
  sys.push_back(TString("BTagReweight_DownLight"));
  sysColl.push_back(sys);

  std::vector<TString> decayMode;
  decayMode.push_back(TString("tt"));
  decayMode.push_back(TString("tb"));
  decayMode.push_back(TString("bb"));
		      
  Systematics* systematics[3];
  TString dirname;
  TString histoname;

  TDirectory* srDir;
  TDirectory* histoDir;

  TFile* outFile = new TFile( "InputForLimits.root", "RECREATE");
  TDirectory* outBRDir;
  TDirectory* outSRDir;

  TH1F* datah = new TH1F( "data", "data", 1, 0., 1.);
  TH1F* bkgh = new TH1F( "bkg", "bkg", 1, 0., 1.);

  TH2F* sigh;
  TH2F* sig_toth;
  TH2F* effh;
  
  TH2F* sigLh;
  TH2F* effLh;

  TH2F* sigRh;
  TH2F* effRh;
  
  TH2F* jesh;
  TH2F* btagBCh;
  TH2F* btagLighth;
  TH2F* btagh;
  
  TH2F* sysh;

  TH2F* unch;

  TH2F* jesPercenth;
  TH2F* btagBCPercenth;
  TH2F* btagLightPercenth;
  TH2F* btagPercenth;
  
  TH2F* sysPercenth;

  TH2F* uncPercenth;

  Float_t sig = 0.;
  Float_t stat = 0.;

  Float_t jes = 0.;
  Float_t bc = 0.;
  Float_t light = 0.;
  
  Float_t unc = 0.;

  int N = bkgTree->GetEntries();

  for ( int ibr = 0; ibr < NBR; ibr++){
    dirname = ""; dirname += BR[ibr];
    outFile->mkdir(dirname);
    outBRDir = outFile->GetDirectory(dirname);

    for ( int iSR = 0; iSR < 9; iSR++){
      bkgTree->GetEntry(iSR);      
      datah->SetBinContent( 1, obs);
      bkgh->SetBinContent( 1, bkg);
      bkgh->SetBinError( 1, bkgTotUnc);

      dirname = ""; dirname += iSR;
      outBRDir->mkdir(dirname);
      outSRDir = outBRDir->GetDirectory(dirname);
      
      dirname = ""; dirname += iSR; dirname += ".root";      
      srDir = sigFile->GetDirectory( dirname);
      for ( int isys = 0; isys < (int) sysColl.size(); isys++){
	systematics[isys] = new Systematics();
	systematics[isys]->BR = BR[ibr];

	histoDir = srDir->GetDirectory( "NoSystematic");
	for ( int idecay = 0; idecay < (int) decayMode.size(); idecay++){
	  histoDir->GetObject( decayMode.at(idecay), systematics[isys]->h[idecay]);
	  histoDir->GetObject( decayMode.at(idecay) + "l", systematics[isys]->Lh);
	  histoDir->GetObject( decayMode.at(idecay) + "r", systematics[isys]->Rh);
	}
	histoDir->GetObject( decayMode.at(0) + "l", systematics[isys]->Lh);
	histoDir->GetObject( decayMode.at(0) + "r", systematics[isys]->Rh);
	histoDir->GetObject( "sig_tot", systematics[isys]->sig_toth);

	for ( int ishift = 0; ishift < 2; ishift++){
	  histoDir = srDir->GetDirectory(sysColl.at(isys).at(ishift));
	  for ( int idecay = 0; idecay < (int) decayMode.size(); idecay++){
	    histoDir->GetObject( decayMode.at(idecay), systematics[isys]->shifth[ishift][idecay]);
	  }
	}
	systematics[isys]->Calc();
      }
      sig_toth = new TH2F( *systematics[0]->sig_toth);
      sig_toth->SetName("sig_tot");
      sig_toth->SetTitle("sig_tot");    

      sigh = new TH2F( *systematics[0]->sigh);
      sigh->SetName("sig");
      sigh->SetTitle("sig");

      effh = new TH2F( *systematics[0]->effh);
      effh->SetName("eff");
      effh->SetTitle("eff");

      sigLh = new TH2F( *systematics[0]->sigRh);
      sigLh->SetName("sigL");
      sigLh->SetTitle("sigL");

      effLh = new TH2F( *systematics[0]->effLh);
      effLh->SetName("effL");
      effLh->SetTitle("effL");

      sigRh = new TH2F( *systematics[0]->sigRh);
      sigRh->SetName("sigR");
      sigRh->SetTitle("sigR");

      effRh = new TH2F( *systematics[0]->effRh);
      effRh->SetName("effR");
      effRh->SetTitle("effR");

      jesh = new TH2F( *systematics[0]->sysh);
      jesh->SetName("jes");
      jesh->SetTitle("jes");

      btagBCh = new TH2F( *systematics[1]->sysh);
      btagBCh->SetName("btagBC");
      btagBCh->SetTitle("btagBC");
      
      btagLighth = new TH2F( *systematics[2]->sysh);
      btagLighth->SetName("btagLight");
      btagLighth->SetTitle("btagLight");
      
      btagh = new TH2F( *btagBCh);
      btagh->Reset();
      btagh->SetName("btag");
      btagh->SetTitle("btag");
 
      sysh = new TH2F( *jesh);
      sysh->Reset();
      sysh->SetName("sys");
      sysh->SetTitle("sys");

      unch = new TH2F( *jesh);
      unch->Reset();
      unch->SetName("unc");
      unch->SetTitle("unc");


      jesPercenth = new TH2F( *systematics[0]->sysh);
      jesPercenth->SetName("jesPercent");
      jesPercenth->SetTitle("jesPercent");
      jesPercenth->Divide( sigh);
      jesPercenth->Scale( 100.);      

      btagBCPercenth = new TH2F( *systematics[1]->sysh);
      btagBCPercenth->SetName("btagBCPercent");
      btagBCPercenth->SetTitle("btagBCPercent");
      btagBCPercenth->Divide( sigh);
      btagBCPercenth->Scale( 100.);   

      btagLightPercenth = new TH2F( *systematics[2]->sysh);
      btagLightPercenth->SetName("btagLightPercent");
      btagLightPercenth->SetTitle("btagLightPercent");
      btagLightPercenth->Divide( sigh);
      btagLightPercenth->Scale( 100.);   

      btagPercenth = new TH2F( *btagBCh);
      btagPercenth->Reset();
      btagPercenth->SetName("btagPercent");
      btagPercenth->SetTitle("btagPercent");
 
      sysPercenth = new TH2F( *jesh);
      sysPercenth->Reset();
      sysPercenth->SetName("sysPercent");
      sysPercenth->SetTitle("sysPercent");

      uncPercenth = new TH2F( *jesh);
      uncPercenth->Reset();
      uncPercenth->SetName("uncPercent");
      uncPercenth->SetTitle("uncPercent");

      for (int ibin = 0; ibin < sigh->GetSize(); ibin++){	
	sig = sigh->GetBinContent( ibin);
	stat = sigh->GetBinError( ibin);

	jes = jesh->GetBinContent(ibin);
	bc = btagBCh->GetBinContent(ibin);
	light = btagLighth->GetBinContent(ibin);
    
	unc = sqrt( bc * bc + light * light);
	btagh->SetBinContent( ibin, unc);
	btagPercenth->SetBinContent( ibin, unc / sig * 100.);
	
	unc = sqrt( jes * jes + bc * bc + light * light +
		    sig * sig * (0.044 * 0.044 + // Lumi
				 0.03  * 0.03  + // Trigger
				 0.05  * 0.05    // Lep Id
				 )
		    );       
	sysh->SetBinContent( ibin, unc);
	sysPercenth->SetBinContent( ibin, unc / sig * 100.);
	
	unc = sqrt( jes * jes + bc * bc + light * light + stat * stat +  
		    sig * sig * (0.044 * 0.044 + // Lumi
				 0.03  * 0.03  + // Trigger
				 0.05  * 0.05    // Lep Id
				 )
		    );	
	unch->SetBinContent( ibin, unc);
	uncPercenth->SetBinContent( ibin, unc / sig * 100.);
      }
      outSRDir->cd();

      datah->Write();
      bkgh->Write();

      sig_toth->Write();
      sigh->Write();
      effh->Write();
      
      sigLh->Write();
      effLh->Write();

      sigRh->Write();
      effRh->Write();

      jesh->Write();
      btagBCh->Write(); 
      btagLighth->Write();
      btagh->Write();
      
      sysh->Write();
      unch->Write();

      jesPercenth->Write();
      btagBCPercenth->Write(); 
      btagLightPercenth->Write();
      btagPercenth->Write();
      
      sysPercenth->Write();
      uncPercenth->Write();
    }
  }

  delete systematics[0];
  delete systematics[1];
  delete systematics[2];

  outFile->Close();
  sigFile->Close();
  bkgFile->Close();

  return 0;
}
Exemplo n.º 14
0
void checkBtagging(){

  char* histname  = "masses";
  char* filename  = (char*) "/tas/cms2/stop/cms2V05-03-26_stoplooperV00-02-23/T2tt_mad/minibaby_V00-03-04/Skim_4jets_MET100_MT120/merged*root";
  char* denomname = (char*) "/tas/cms2/stop/cms2V05-03-26_stoplooperV00-02-23/T2tt_mad/minibaby_V00-03-04/Skim_4jets_MET100_MT120/myMassDB_T2tt_MG_combined_25GeVbins.root";

  cout << "File         " << filename  << endl;
  cout << "Denominator  " << denomname << endl;
  cout << "Histo        " << histname  << endl;

  TChain *ch = new TChain("t");
  ch->Add(filename);
  TFile* f     = TFile::Open(denomname);
  TH2F*  hxsec = (TH2F*) f->Get(histname);

  TCut rho("rhovor>0 && rhovor<40");
  TCut filters("isdata==0 || (csc==0 && hbhe==1 && hcallaser==1 && ecaltp==1 && trkfail==1 && eebadsc==1 && hbhenew==1)");
  TCut goodlep("ngoodlep > 0 && abs( pflep1.Pt() - lep1.Pt() ) < 10.0 && abs(isopf1 * lep1.Pt() ) < 5.0");
  TCut el("leptype==0 && abs(lep1->Eta())<1.4442 && lep1->Pt()>30.0 && eoverpin < 4.0 && (isdata==0 || ele27wp80==1)");
  TCut mu("leptype==1 && abs(lep1->Eta())<2.1    && lep1->Pt()>25.0 && (isdata==0 || isomu24==1)");
  TCut njets4("mini_njets >= 4");
  TCut passisotrk("mini_passisotrk==1");
  TCut tauveto("mini_passtauveto == 1");
  TCut met100("t1metphicorr > 100");
  TCut met150("t1metphicorr > 100");
  TCut mt120("t1metphicorrmt > 120");
  TCut mt150("t1metphicorrmt > 150");
  TCut dphi("mini_dphimjmin>0.8");
  TCut chi2("mini_chi2<5.0");
  TCut mt2w("mini_mt2w>200.0");
  TCut bpt100("mini_pt_b > 100.0");

  TCut btag1      ("mini_nb >= 1");
  TCut btag1upBC  ("mini_nbupBC >= 1");
  TCut btag1downBC("mini_nbdownBC >= 1");
  TCut btag1upL   ("mini_nbupL >= 1");
  TCut btag1downL ("mini_nbdownL >= 1");

  TCut presel;

  //-------------------------------------------
  // THESE CUTS DEFINE PRESELECTION REGION
  //-------------------------------------------
  presel += rho;
  presel += filters;
  presel += goodlep;
  presel += (el||mu);
  presel += njets4;
  presel += passisotrk;
  presel += tauveto;
  presel += met100;
  presel += mt120;

  //presel += btag1;
  //presel += dphi;
  //presel += chi2;
  //presel += mt2w;
  //presel += mt150;

  TH2F* hnom    = new TH2F("hnom"   ,"hnom"   ,41,-12.5,1012.5,41,-12.5,1012.5);
  TH2F* hupBC   = new TH2F("hupBC"  ,"hupBC"  ,41,-12.5,1012.5,41,-12.5,1012.5);
  TH2F* hupL    = new TH2F("hupL"   ,"hupL"   ,41,-12.5,1012.5,41,-12.5,1012.5);
  TH2F* hdownBC = new TH2F("hdownBC","hdownBC",41,-12.5,1012.5,41,-12.5,1012.5);
  TH2F* hdownL  = new TH2F("hdownL" ,"hdownL" ,41,-12.5,1012.5,41,-12.5,1012.5);

  ch->Draw("ml:mg>>hnom"   ,presel+btag1);
  ch->Draw("ml:mg>>hupBC"  ,presel+btag1upBC);
  ch->Draw("ml:mg>>hupL"   ,presel+btag1upL);
  ch->Draw("ml:mg>>hdownBC",presel+btag1downBC);
  ch->Draw("ml:mg>>hdownL" ,presel+btag1downL);

  TH1F* hratio_upBC   = getRatioPlot(hupBC,hnom);
  TH1F* hratio_upL    = getRatioPlot(hupL ,hnom);
  TH1F* hratio_downBC = getRatioPlot(hdownBC,hnom);
  TH1F* hratio_downL  = getRatioPlot(hdownL ,hnom);

  hupBC->Divide(hnom);
  hupL->Divide(hnom);
  hdownBC->Divide(hnom);
  hdownL->Divide(hnom);

  TLatex *t = new TLatex();
  t->SetNDC();

  TCanvas *c1 = new TCanvas("c1","c1",1200,1200);
  c1->Divide(2,2);

  c1->cd(1);
  gPad->SetRightMargin(0.15);
  hupBC->GetXaxis()->SetRangeUser(0,1000);
  hupBC->GetYaxis()->SetRangeUser(0,800);
  hupBC->SetMinimum(0.95);
  hupBC->SetMaximum(1.05);
  hupBC->GetXaxis()->SetTitle("m_{#tilde{t}}  [GeV]");
  hupBC->GetYaxis()->SetTitle("m_{#tilde{#chi}_{1}^{0}}  [GeV]");
  hupBC->Draw("colz");
  t->DrawLatex(0.2,0.7,"upBC / nominal");

  c1->cd(2);
  gPad->SetRightMargin(0.15);
  hupL->GetXaxis()->SetRangeUser(0,1000);
  hupL->GetYaxis()->SetRangeUser(0,800);
  hupL->SetMinimum(0.95);
  hupL->SetMaximum(1.05);
  hupL->GetXaxis()->SetTitle("m_{#tilde{t}}  [GeV]");
  hupL->GetYaxis()->SetTitle("m_{#tilde{#chi}_{1}^{0}}  [GeV]");
  hupL->Draw("colz");
  t->DrawLatex(0.2,0.7,"upL / nominal");

  c1->cd(3);
  gPad->SetRightMargin(0.15);
  hdownBC->GetXaxis()->SetRangeUser(0,1000);
  hdownBC->GetYaxis()->SetRangeUser(0,800);
  hdownBC->SetMinimum(0.95);
  hdownBC->SetMaximum(1.05);
  hdownBC->GetXaxis()->SetTitle("m_{#tilde{t}}  [GeV]");
  hdownBC->GetYaxis()->SetTitle("m_{#tilde{#chi}_{1}^{0}}  [GeV]");
  hdownBC->Draw("colz");
  t->DrawLatex(0.2,0.7,"downBC / nominal");

  c1->cd(4);
  gPad->SetRightMargin(0.15);
  hdownL->GetXaxis()->SetRangeUser(0,1000);
  hdownL->GetYaxis()->SetRangeUser(0,800);
  hdownL->SetMinimum(0.95);
  hdownL->SetMaximum(1.05);
  hdownL->GetXaxis()->SetTitle("m_{#tilde{t}}  [GeV]");
  hdownL->GetYaxis()->SetTitle("m_{#tilde{#chi}_{1}^{0}}  [GeV]");
  hdownL->Draw("colz");
  t->DrawLatex(0.2,0.7,"downL / nominal");

  //c1->Print("../../plots/T2bw_x25_dphi.pdf");
  //c1->Print("../../plots/T2bw_x25_eff_HM150_nodphi.pdf");

  TCanvas* c2 = new TCanvas("c2","c2",800,800);
  c2->Divide(2,2);

  gStyle->SetOptStat(111111);

  c2->cd(1);
  hratio_upBC->GetXaxis()->SetLabelSize(0.035);
  hratio_upBC->GetXaxis()->SetTitle("upBC / nominal");
  hratio_upBC->Draw();

  c2->cd(2);
  hratio_upL->GetXaxis()->SetLabelSize(0.035);
  hratio_upL->GetXaxis()->SetTitle("upL / nominal");
  hratio_upL->Draw();

  c2->cd(3);
  hratio_downBC->GetXaxis()->SetLabelSize(0.035);
  hratio_downBC->GetXaxis()->SetTitle("downBC / nominal");
  hratio_downBC->Draw();

  c2->cd(4);
  hratio_downL->GetXaxis()->SetLabelSize(0.035);
  hratio_downL->GetXaxis()->SetTitle("downL / nominal");
  hratio_downL->Draw();

  c1->Print("../../plots/T2tt_btagging_2D.pdf");
  c2->Print("../../plots/T2tt_btagging_1D.pdf");
  
}
Exemplo n.º 15
0
void makeSMSCards(){

  //---------------------------------------
  // load TChain
  //---------------------------------------
  
  TChain *ch = new TChain("T1");
  ch->Add("output/V00-02-13/wzsms_baby_oldIso.root");
  char* version = (char*) "V00-00-14";

  //---------------------------------------
  // load denominator histogram
  //---------------------------------------

  TFile* fdenom = TFile::Open("output/V00-02-13/wzsms_ngen.root");
  TH2F*  hdenom = (TH2F*) fdenom->Get("hmass");
  hdenom->Scale(10.0);

  //---------------------------------------
  // selection
  //---------------------------------------

  TCut weight   ("19500.0 * trgeff * vtxweight");
  //TCut weight   ("19500.0 * trgeff * vtxweight * (1./100000.)");
  //TCut weight   ("9.2 * trgeff * vtxweight * weight");

  // MEDIUM WP
  TCut presel   ("lep2.pt()>20.0 && dilmass>81 && dilmass<101 && nbcsvm==0 && mjj>70   && mjj<110   && nlep==2 && njets>=2     && leptype<2");
  TCut preseljup("lep2.pt()>20.0 && dilmass>81 && dilmass<101 && nbcsvm==0 && mjjup>70 && mjjup<110 && nlep==2 && njetsup>=2   && leptype<2");
  TCut preseljdn("lep2.pt()>20.0 && dilmass>81 && dilmass<101 && nbcsvm==0 && mjjdn>70 && mjjdn<110 && nlep==2 && njetsdn>=2   && leptype<2");

  /*
  // LOOSE WP
  TCut presel   ("lep2.pt()>20.0 && dilmass>81 && dilmass<101 && nbcsvl==0 && mjj>70   && mjj<110   && nlep==2 && njets>=2     && leptype<2");
  TCut preseljup("lep2.pt()>20.0 && dilmass>81 && dilmass<101 && nbcsvl==0 && mjjup>70 && mjjup<110 && nlep==2 && njetsup>=2   && leptype<2");
  TCut preseljdn("lep2.pt()>20.0 && dilmass>81 && dilmass<101 && nbcsvl==0 && mjjdn>70 && mjjdn<110 && nlep==2 && njetsdn>=2   && leptype<2");
  */

  const unsigned int nbins = 5;
  float metcuts[nbins+1] = {80,100,120,150,200,9999999};

  TCut sigall(Form("pfmet>%.0f"  ,metcuts[0]));
  TCut sigalldn(Form("pfmetdn>%.0f",metcuts[0]));

  cout << "Full signal region            " << sigall.GetTitle()   << endl;
  cout << "Full signal region (JES down) " << sigalldn.GetTitle() << endl;

  TCut sigcut[nbins];
  TCut sigcutup[nbins];
  TCut sigcutdn[nbins];

  for( unsigned int i = 0 ; i < nbins ; ++i ){
    sigcut[i]   = TCut(Form("pfmet  >%.0f && pfmet<%.0f"   , metcuts[i] , metcuts[i+1]));
    sigcutup[i] = TCut(Form("pfmetup>%.0f && pfmetup<%.0f" , metcuts[i] , metcuts[i+1]));
    sigcutdn[i] = TCut(Form("pfmetdn>%.0f && pfmetdn<%.0f" , metcuts[i] , metcuts[i+1]));

    cout << "Region  : " << i << endl;
    cout << "Nominal : " << sigcut[i].GetTitle()   << endl;
    cout << "JES up  : " << sigcutup[i].GetTitle() << endl;
    cout << "JES dn  : " << sigcutdn[i].GetTitle() << endl << endl;
  }
  
  //---------------------------------------
  // preselection and signal region yields
  //---------------------------------------

  TH2F* h[nbins];
  TH2F* hjup[nbins];
  TH2F* hjdn[nbins];

  int   nx   =    41;
  float xmin =  -5.0;
  float xmax = 405.0;

  for( unsigned int i = 0 ; i < nbins ; ++i ){
    h[i]        = new TH2F( Form("h_%i",i)        , Form("h_%i",i)           , nx,xmin,xmax,nx,xmin,xmax);
    hjup[i]     = new TH2F( Form("hjup_%i",i)     , Form("hjup_%i",i)        , nx,xmin,xmax,nx,xmin,xmax);
    hjdn[i]     = new TH2F( Form("hjdn_%i",i)     , Form("hjdn_%i",i)        , nx,xmin,xmax,nx,xmin,xmax);
    
    h[i]    ->Sumw2();
    hjup[i] ->Sumw2();
    hjdn[i] ->Sumw2();
  }
  
  TH2F* hall    = new TH2F( "hall"    , "hall"    , nx,xmin,xmax,nx,xmin,xmax);
  TH2F* hjdnall = new TH2F( "hjdnall" , "hjdnall" , nx,xmin,xmax,nx,xmin,xmax);
  
  hall->Sumw2();
  
  TCanvas *ctemp = new TCanvas();
  ctemp->cd();

  cout << "Filling histos..." << endl;
  for( unsigned int ibin = 0 ; ibin < nbins ; ibin++ ){
    ch->Draw(Form("ml:mg>>h_%i"    , ibin) , (presel    + sigcut[ibin]   ) * weight);
    ch->Draw(Form("ml:mg>>hjup_%i" , ibin) , (preseljup + sigcutup[ibin] ) * weight);
    ch->Draw(Form("ml:mg>>hjdn_%i" , ibin) , (preseljdn + sigcutdn[ibin] ) * weight);

    h[ibin]->Divide(hdenom);
    hjup[ibin]->Divide(hdenom);
    hjdn[ibin]->Divide(hdenom);
  }

  ch->Draw("ml:mg>>hall"        , (presel    + sigall     ) * weight);
  ch->Draw("ml:mg>>hjdnall"     , (preseljdn + sigalldn   ) * weight);

  hall->Divide(hdenom);
  hjdnall->Divide(hdenom);

  delete ctemp;

  ofstream* doScript = new ofstream();
  doScript->open(Form("cards/%s/doLimits.sh",version));

  ofstream* doScript_CLs = new ofstream();
  doScript_CLs->open(Form("cards/%s/doLimits_CLs.sh",version));

  ofstream* doScript_CLs1 = new ofstream();
  doScript_CLs1->open(Form("cards/%s/doLimits_CLs1.sh",version));

  ofstream* doScript_CLs2 = new ofstream();
  doScript_CLs2->open(Form("cards/%s/doLimits_CLs2.sh",version));

  ofstream* doScript_CLs3 = new ofstream();
  doScript_CLs3->open(Form("cards/%s/doLimits_CLs3.sh",version));

  ofstream* doScript_CLs4 = new ofstream();
  doScript_CLs4->open(Form("cards/%s/doLimits_CLs4.sh",version));

  ofstream* doScript_CLs_mL0 = new ofstream();
  doScript_CLs_mL0->open(Form("cards/%s/doLimits_mL0.sh",version));

  ofstream* doScript_CLs_mL50 = new ofstream();
  doScript_CLs_mL50->open(Form("cards/%s/doLimits_mL50.sh",version));

  ofstream* doScript_CLs_mL100 = new ofstream();
  doScript_CLs_mL100->open(Form("cards/%s/doLimits_mL100.sh",version));

  ofstream* filelist = new ofstream();
  filelist->open(Form("cards/%s/file_list.txt",version));

  ofstream* filelist_CLs = new ofstream();
  filelist_CLs->open(Form("cards/%s/file_list_CLs.txt",version));


  //---------------------------------------
  // make and fill data and bkg histos
  //---------------------------------------

  /*
  // MEDIUM WP
  //signal regions             80-100 100-120 120-150 150-200    >200
  float Zbkg_yield[nbins]    = { 40.9 ,  7.0 ,  3.1 ,  1.6 ,     0.8  };
  float Zbkg_err[nbins]      = { 12.4 ,  2.2 ,  0.9 ,  0.5 ,     0.3  };
  float OFbkg_yield[nbins]   = { 17.9 , 11.3 ,  6.9 ,  2.4 ,     0.4  };
  float OFbkg_err[nbins]     = {  3.3 ,  2.2 ,  1.5 ,  1.1 ,     0.3  };
  float WZbkg_yield[nbins]   = {  3.9 ,  2.1 ,  1.6 ,  1.0 ,     0.5  };
  float WZbkg_err[nbins]     = {  2.7 ,  1.5 ,  1.1 ,  0.7 ,     0.5  };
  float ZZbkg_yield[nbins]   = {  1.8 ,  1.0 ,  1.1 ,  0.8 ,     0.7  };
  float ZZbkg_err[nbins]     = {  0.9 ,  0.5 ,  0.6 ,  0.4 ,     0.7  };
  float rarebkg_yield[nbins] = {  0.3 ,  0.2 ,  0.3 ,  0.2 ,     0.2  };
  float rarebkg_err[nbins]   = {  0.2 ,  0.1 ,  0.1 ,  0.1 ,     0.2  };
  int   data_yield[nbins]    = {   56 ,   24 ,   16 ,    3 ,       1  };
  */

  /*
  // LOOSE WP
  //signal regions             80-100 100-120 120-150 150-200    >200
  float Zbkg_yield[nbins]    = { 29.7 ,  3.8 ,  2.2 ,  1.4 ,     0.5  };
  float Zbkg_err[nbins]      = {  9.1 ,  1.2 ,  0.7 ,  0.4 ,     0.2  };
  float OFbkg_yield[nbins]   = {  6.3 ,  5.0 ,  2.7 ,  1.4 ,     0.1  };
  float OFbkg_err[nbins]     = {  1.4 ,  1.2 ,  0.7 ,  0.7 ,     0.1  };
  float WZbkg_yield[nbins]   = {  2.6 ,  1.5 ,  1.0 ,  0.7 ,     0.3  };
  float WZbkg_err[nbins]     = {  1.8 ,  1.0 ,  0.7 ,  0.5 ,     0.3  };
  float ZZbkg_yield[nbins]   = {  1.4 ,  0.8 ,  0.8 ,  0.6 ,     0.5  };
  float ZZbkg_err[nbins]     = {  0.7 ,  0.4 ,  0.4 ,  0.3 ,     0.5  };
  float rarebkg_yield[nbins] = {  0.2 ,  0.1 ,  0.2 ,  0.2 ,     0.1  };
  float rarebkg_err[nbins]   = {  0.1 ,  0.1 ,  0.1 ,  0.1 ,     0.1  };
  int   data_yield[nbins]    = {   40 ,   10 ,   10 ,    2 ,       1  };
  */

  /*
  // MEDIUM WP, 19.3/fb RESULTS
  float Zbkg_yield[nbins]    = { 68.9 ,  7.8 ,  4.8 ,  2.1 ,     0.5  };
  float Zbkg_err[nbins]      = { 21.2 ,  2.5 ,  1.5 ,  0.7 ,     0.1  };
  float OFbkg_yield[nbins]   = { 35.2 , 21.9 , 13.2 ,  5.7 ,     0.8  };
  float OFbkg_err[nbins]     = {  6.2 ,  4.0 ,  2.5 ,  1.6 ,     0.4  };
  float WZbkg_yield[nbins]   = {  7.4 ,  4.0 ,  3.3 ,  2.0 ,     0.9  };
  float WZbkg_err[nbins]     = {  3.7 ,  2.0 ,  1.6 ,  1.0 ,     0.9  };
  float ZZbkg_yield[nbins]   = {  3.2 ,  1.9 ,  2.1 ,  1.5 ,     1.4  };
  float ZZbkg_err[nbins]     = {  1.6 ,  1.0 ,  1.1 ,  0.8 ,     1.4  };
  float rarebkg_yield[nbins] = {  0.9 ,  0.4 ,  0.9 ,  0.6 ,     0.4  };
  float rarebkg_err[nbins]   = {  0.5 ,  0.2 ,  0.5 ,  0.3 ,     0.4  };
  int   data_yield[nbins]    = {  115 ,   36 ,   25 ,   13 ,       4  };
  */

  // MEDIUM WP, 19.5/fb RESULTS
  // float Zbkg_yield[nbins]    = { 64.5 ,  7.8 ,  3.7 ,  2.0 ,     0.4  };
  // float Zbkg_err[nbins]      = { 22.2 ,  3.1 ,  1.6 ,  1.0 ,     0.3  };
  // float OFbkg_yield[nbins]   = { 35.2 , 21.9 , 13.2 ,  5.7 ,     0.8  };
  // float OFbkg_err[nbins]     = {  6.2 ,  4.0 ,  2.5 ,  1.6 ,     0.4  };
  // float WZbkg_yield[nbins]   = {  7.4 ,  4.0 ,  3.3 ,  2.0 ,     0.9  };
  // float WZbkg_err[nbins]     = {  3.7 ,  2.0 ,  1.6 ,  1.0 ,     0.9  };
  // float ZZbkg_yield[nbins]   = {  3.2 ,  1.9 ,  2.1 ,  1.5 ,     1.4  };
  // float ZZbkg_err[nbins]     = {  1.6 ,  1.0 ,  1.1 ,  0.8 ,     1.4  };
  // float rarebkg_yield[nbins] = {  0.9 ,  0.4 ,  0.9 ,  0.6 ,     0.4  };
  // float rarebkg_err[nbins]   = {  0.5 ,  0.2 ,  0.5 ,  0.3 ,     0.4  };
  // int   data_yield[nbins]    = {  115 ,   36 ,   25 ,   13 ,       4  };

  // MEDIUM WP, 19.5/fb RESULTS (fix b-veto)
  float Zbkg_yield[nbins]    = { 64.5 ,  7.8 ,  3.7 ,  2.0 ,     0.4  };
  float Zbkg_err[nbins]      = { 22.2 ,  3.1 ,  1.6 ,  1.0 ,     0.3  };
  float OFbkg_yield[nbins]   = { 35.2 , 21.9 , 13.2 ,  5.7 ,     0.8  };
  float OFbkg_err[nbins]     = {  6.2 ,  4.0 ,  2.5 ,  1.6 ,     0.4  };
  float WZbkg_yield[nbins]   = {  6.8 ,  3.7 ,  2.9 ,  1.9 ,     0.9  };
  float WZbkg_err[nbins]     = {  3.4 ,  1.9 ,  1.5 ,  0.9 ,     0.4  };
  float ZZbkg_yield[nbins]   = {  2.8 ,  1.8 ,  1.9 ,  1.4 ,     1.3  };
  float ZZbkg_err[nbins]     = {  1.4 ,  0.9 ,  0.9 ,  0.7 ,     0.7  };
  float rarebkg_yield[nbins] = {  0.5 ,  0.2 ,  0.4 ,  0.4 ,     0.3  };
  float rarebkg_err[nbins]   = {  0.2 ,  0.1 ,  0.2 ,  0.2 ,     0.1  };
  int   data_yield[nbins]    = {  115 ,   36 ,   25 ,   13 ,       4  };

  int   data_tot  = 0;
  float Zbkg_tot  = 0;
  float OFbkg_tot = 0;
  float WZbkg_tot = 0;
  float ZZbkg_tot = 0;
  float rarebkg_tot = 0;

  for( unsigned int i = 0 ; i < nbins ; ++i ){
    cout << "Bin      " << i << endl;
    cout << "Data     " << data_yield[i] << endl;
    cout << "Z  bkg   " << Form("%.1f +/- %.1f" ,Zbkg_yield[i]    , Zbkg_err[i])    << endl;
    cout << "OF bkg   " << Form("%.1f +/- %.1f" ,OFbkg_yield[i]   , OFbkg_err[i])   << endl;
    cout << "WZ bkg   " << Form("%.1f +/- %.1f" ,WZbkg_yield[i]   , WZbkg_err[i])   << endl;
    cout << "ZZ bkg   " << Form("%.1f +/- %.1f" ,ZZbkg_yield[i]   , ZZbkg_err[i])   << endl;
    cout << "rare bkg " << Form("%.1f +/- %.1f" ,rarebkg_yield[i] , rarebkg_err[i]) << endl;

    data_tot     += data_yield[i];
    Zbkg_tot     += Zbkg_yield[i];
    OFbkg_tot    += OFbkg_yield[i];
    WZbkg_tot    += WZbkg_yield[i];
    ZZbkg_tot    += ZZbkg_yield[i];
    rarebkg_tot  += rarebkg_yield[i];
  }

  cout << "Total data     " << data_tot    << endl;
  cout << "Total Z  bkg   " << Zbkg_tot    << endl;
  cout << "Total OF bkg   " << OFbkg_tot   << endl;
  cout << "Total WZ bkg   " << WZbkg_tot   << endl;
  cout << "Total ZZ bkg   " << ZZbkg_tot   << endl;
  cout << "Total rare bkg " << rarebkg_tot << endl;

  TH1F* histo_Data = new TH1F("histo_Data","histo_Data",nbins,0,nbins);

  TH1F* histo_Zbkg               = new TH1F("histo_Zbkg"                ,"histo_Zbkg"           ,nbins,0,nbins);
  TH1F* histo_Zbkg_errUp         = new TH1F("histo_Zbkg_errZUp"         ,"histo_Zbkg_errZUp"    ,nbins,0,nbins);
  TH1F* histo_Zbkg_errDown       = new TH1F("histo_Zbkg_errZDown"       ,"histo_Zbkg_errZDown"  ,nbins,0,nbins);

  TH1F* histo_OFbkg              = new TH1F("histo_OFbkg"               ,"histo_OFbkg"          ,nbins,0,nbins);
  TH1F* histo_OFbkg_errUp        = new TH1F("histo_OFbkg_errOFUp"       ,"histo_OFbkg_errOFUp"  ,nbins,0,nbins);
  TH1F* histo_OFbkg_errDown      = new TH1F("histo_OFbkg_errOFDown"     ,"histo_OFbkg_errOFDown",nbins,0,nbins);

  TH1F* histo_WZbkg              = new TH1F("histo_WZbkg"               ,"histo_WZbkg"          ,nbins,0,nbins);
  TH1F* histo_WZbkg_errUp        = new TH1F("histo_WZbkg_errWZUp"       ,"histo_WZbkg_errWZUp"  ,nbins,0,nbins);
  TH1F* histo_WZbkg_errDown      = new TH1F("histo_WZbkg_errWZDown"     ,"histo_WZbkg_errWZDown",nbins,0,nbins);

  TH1F* histo_ZZbkg              = new TH1F("histo_ZZbkg"               ,"histo_ZZbkg"          ,nbins,0,nbins);
  TH1F* histo_ZZbkg_errUp        = new TH1F("histo_ZZbkg_errZZUp"       ,"histo_ZZbkg_errZZUp"  ,nbins,0,nbins);
  TH1F* histo_ZZbkg_errDown      = new TH1F("histo_ZZbkg_errZZDown"     ,"histo_ZZbkg_errZZDown",nbins,0,nbins);
            
  TH1F* histo_rarebkg            = new TH1F("histo_rarebkg"             ,"histo_rarebkg"             ,nbins,0,nbins);
  TH1F* histo_rarebkg_errUp      = new TH1F("histo_rarebkg_errRAREUp"   ,"histo_rarebkg_errRAREUp"   ,nbins,0,nbins);
  TH1F* histo_rarebkg_errDown    = new TH1F("histo_rarebkg_errRAREDown" ,"histo_rarebkg_errRAREDown" ,nbins,0,nbins);
      
  for( unsigned int ibin = 0 ; ibin < nbins ; ibin++){

    histo_Data                -> SetBinContent(ibin+1, data_yield[ibin] );

    histo_Zbkg                -> SetBinContent(ibin+1, Zbkg_yield[ibin]);
    histo_Zbkg_errUp          -> SetBinContent(ibin+1, Zbkg_yield[ibin] + Zbkg_err[ibin] );
    histo_Zbkg_errDown        -> SetBinContent(ibin+1, TMath::Max(Zbkg_yield[ibin] - Zbkg_err[ibin],(float)0.0) );

    histo_OFbkg               -> SetBinContent(ibin+1, OFbkg_yield[ibin]);
    histo_OFbkg_errUp         -> SetBinContent(ibin+1, OFbkg_yield[ibin] + OFbkg_err[ibin] );
    histo_OFbkg_errDown       -> SetBinContent(ibin+1, TMath::Max(OFbkg_yield[ibin] - OFbkg_err[ibin],(float)0.0) );

    histo_WZbkg               -> SetBinContent(ibin+1, WZbkg_yield[ibin]);
    histo_WZbkg_errUp         -> SetBinContent(ibin+1, WZbkg_yield[ibin] + WZbkg_err[ibin] );
    histo_WZbkg_errDown       -> SetBinContent(ibin+1, TMath::Max(WZbkg_yield[ibin] - WZbkg_err[ibin],(float)0.0) );

    histo_ZZbkg               -> SetBinContent(ibin+1, ZZbkg_yield[ibin]);
    histo_ZZbkg_errUp         -> SetBinContent(ibin+1, ZZbkg_yield[ibin] + ZZbkg_err[ibin] );
    histo_ZZbkg_errDown       -> SetBinContent(ibin+1, TMath::Max(ZZbkg_yield[ibin] - ZZbkg_err[ibin],(float)0.0) );

    histo_rarebkg             -> SetBinContent(ibin+1, rarebkg_yield[ibin]);
    histo_rarebkg_errUp       -> SetBinContent(ibin+1, rarebkg_yield[ibin] + rarebkg_err[ibin] );
    histo_rarebkg_errDown     -> SetBinContent(ibin+1, TMath::Max(rarebkg_yield[ibin] - rarebkg_err[ibin],(float)0.0) );
  }


  //------------------------------------------
  // loop over SMS points
  //------------------------------------------

  int counter = 0;

  for( int mgbin = 1 ; mgbin <= hall->GetXaxis()->GetNbins() ; mgbin++ ){
    for( int mlbin = 1 ; mlbin <= hall->GetYaxis()->GetNbins() ; mlbin++ ){

      //if( !( mgbin == 17 && mlbin == 5 ) ) continue;

      int mg  = hall->GetXaxis()->GetBinCenter(mgbin);
      int ml  = hall->GetXaxis()->GetBinCenter(mlbin);

      // bool pass = false;

      // if( mg==150 && ml==0  ) pass = true;
      // if( mg==200 && ml==0  ) pass = true;
      // if( mg==250 && ml==0  ) pass = true;
      // if( mg==150 && ml==25 ) pass = true;
      // if( mg==200 && ml==50 ) pass = true;
      // if( mg==250 && ml==50 ) pass = true;
      // if( mg==200 && ml==80 ) pass = true;
      // if( mg==250 && ml==80 ) pass = true;
      
      // if( !pass ) continue;

      cout << endl;
      cout << "----------------------------------" << endl;
      cout << "mg    " << mg    << " ml    " << ml    << endl;
      cout << "mgbin " << mgbin << " mlbin " << mlbin << endl;
      cout << "----------------------------------" << endl;

      if( hjdnall->GetBinContent(mgbin,mlbin) < 1e-10 ) continue;

      float nom = hall->GetBinContent(mgbin,mlbin);

      //---------------------------------------
      // make signal histos
      //---------------------------------------

      TH1F* histo_SMS               = new TH1F( Form("histo_SMS_%i_%i"              ,mgbin,mlbin) , Form("histo_SMS_%i_%i"              ,mgbin,mlbin) , nbins,0,nbins);
      TH1F* histo_SMS_JES_shapeUp   = new TH1F( Form("histo_SMS_%i_%i_JES_shapeUp"  ,mgbin,mlbin) , Form("histo_SMS_%i_%i_JES_shapeUp"  ,mgbin,mlbin) , nbins,0,nbins);
      TH1F* histo_SMS_JES_shapeDown = new TH1F( Form("histo_SMS_%i_%i_JES_shapeDown",mgbin,mlbin) , Form("histo_SMS_%i_%i_JES_shapeDown",mgbin,mlbin) , nbins,0,nbins);

      float sigtot    = 0;
      float sigtotjdn = 0;

      cout << "Signal yield" << endl;
      for( unsigned int ibin = 0 ; ibin < nbins ; ibin++ ){
	float yieldnom = h[ibin]->GetBinContent(mgbin,mlbin);
	float yieldjup = hjup[ibin]->GetBinContent(mgbin,mlbin);
	float yieldjdn = hjdn[ibin]->GetBinContent(mgbin,mlbin);

	sigtot    += yieldnom;
	sigtotjdn += yieldjdn;

	histo_SMS->SetBinContent              ( ibin + 1 , yieldnom );
	histo_SMS_JES_shapeUp->SetBinContent  ( ibin + 1 , yieldjup );
	histo_SMS_JES_shapeDown->SetBinContent( ibin + 1 , yieldjdn );
      
	cout << "Bin " << ibin << " " << yieldnom << endl;
      }

      cout << "Total signal yield " << sigtot << endl;

      if( sigtotjdn < 1e-10 ) continue;
      //if( sigtot    < 2     ) continue;

      counter++;

      *doScript << Form("../../../../test/lands.exe -M Bayesian -d SMS_%i_%i.txt",mgbin,mlbin)         << endl;

      *doScript_CLs << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      *filelist << Form("cards/%s/SMS_%i_%i.txt_Bayesian_bysObsLimit.root",version,mgbin,mlbin)        << endl;

      *filelist_CLs << Form("cards/%s/SMS_%i_%i_m2lnQ.root",version,mgbin,mlbin)        << endl;

      if( counter%4 == 0 ) *doScript_CLs1 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      if( counter%4 == 1 ) *doScript_CLs2 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      if( counter%4 == 2 ) *doScript_CLs3 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      if( counter%4 == 3 ) *doScript_CLs4 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      if( mlbin==1 ) *doScript_CLs_mL0 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      if( mlbin==3 ) *doScript_CLs_mL50 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      if( mlbin==5 ) *doScript_CLs_mL100 << Form("../../../../test/lands.exe -d SMS_%i_%i.txt  -M Hybrid --freq --ExpectationHints Asymptotic --scanRs 1 --freq --nToysForCLsb 3000 --nToysForCLb 1500 --seed 1234 -n SMS_%i_%i -rMin 0 -rMax 100",mgbin,mlbin,mgbin,mlbin) << endl;

      printCard( Form("SMS_%i_%i",mgbin,mlbin) , sigtot , Zbkg_tot , OFbkg_tot , WZbkg_tot , ZZbkg_tot , rarebkg_tot , data_tot , version );


      TFile *f = TFile::Open( Form("rootfiles/%s/SMS_%i_%i.root",version,mgbin,mlbin) , "RECREATE");
      f->cd();
      histo_Data->Write();
      histo_Zbkg->Write();
      histo_Zbkg_errUp->Write();
      histo_Zbkg_errDown->Write();
      histo_OFbkg->Write();
      histo_OFbkg_errUp->Write();
      histo_OFbkg_errDown->Write();
      histo_WZbkg->Write();
      histo_WZbkg_errUp->Write();
      histo_WZbkg_errDown->Write();
      histo_ZZbkg->Write();
      histo_ZZbkg_errUp->Write();
      histo_ZZbkg_errDown->Write();
      histo_rarebkg->Write();
      histo_rarebkg_errUp->Write();
      histo_rarebkg_errDown->Write();
      histo_SMS->Write();
      histo_SMS_JES_shapeUp->Write();
      histo_SMS_JES_shapeDown->Write();
      f->Close();

      delete histo_SMS;
      delete histo_SMS_JES_shapeUp;
      delete histo_SMS_JES_shapeDown;
    }
  }

  doScript->close();
  doScript_CLs->close();
  doScript_CLs1->close();
  doScript_CLs2->close();
  doScript_CLs3->close();
  doScript_CLs4->close();
  doScript_CLs_mL0->close();
  doScript_CLs_mL50->close();
  filelist->close();
  filelist_CLs->close();

}
Exemplo n.º 16
0
TH2F *prof2d(TTree *tree, TString var1Name, TString var2Name, TString nllName, TString binning="(241,-0.0005,0.2405,60,0.00025,0.03025)", bool delta=false, int nSmooth=0, TString optSmooth="k3a"){

  var1Name.ReplaceAll("-","_");
  var2Name.ReplaceAll("-","_");
  //  tree->Print();
  TString histName="h";
  //std::cout << var1Name << "\t" << var2Name << "\t" << histName << std::endl;
  tree->Draw(var1Name+":"+var2Name+">>"+histName+binning);
  TH2F *hEntries = (TH2F*)gROOT->FindObject(histName);
  if(hEntries==NULL) return NULL;
  //std::cerr << "e qui ci sono?" << std::endl;
  tree->Draw(var1Name+":"+var2Name+">>shervin"+binning,nllName);

  TH2F *h = (TH2F*)gROOT->FindObject("shervin");
  if(h==NULL) return NULL;
  h->Divide(hEntries);


  //std::cerr << "io sono qui" << std::endl;    
  delete hEntries;
  Double_t min=1e20, max=0;

  if(nSmooth>0){
    for(int iSmooth=0; iSmooth<nSmooth; iSmooth++){
      Smooth(h, 1, optSmooth);
    }
  }
  
  Int_t iBinXmin=0, iBinYmin=0;
  if(delta){
    for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){
      for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){
	Double_t binContent=h->GetBinContent(iBinX, iBinY);
	if(min>binContent && binContent!=0){
	  min=binContent;
	  iBinXmin=iBinX;
	  iBinYmin=iBinY;
	}
	if(max<binContent) max=binContent;
      }
    }
    //std::cout << "min=" << min << "\tmax=" << max<<std::endl;    
    for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){
      for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){
	Double_t binContent=h->GetBinContent(iBinX, iBinY);
	//std::cout << binContent << std::endl;
	if(binContent==0 && iBinX > 1 && h->GetBinContent(iBinX-1,iBinY) !=0 ){
	binContent=h->GetBinContent(iBinX-1,iBinY);
      }
	if(binContent!=0) binContent-=min-0.0002;
	else binContent=-1;
	h->SetBinContent(iBinX,iBinY,binContent);
      }
    }
  }
//   std::cout << "iBinXmin = " << iBinXmin 
// 	    << "\tiBinYmin = " << iBinYmin 
// 	    << "\tminBin content = " << h->GetBinContent(iBinXmin, iBinYmin)
//     //	    << "\tminX = h->GetXaxis()->GetBinCenter(
// 	    << std::endl;
  h->GetZaxis()->SetRangeUser(0.000001,50);
  //std::cerr << "io sono qui 3" << std::endl;    
  return h;
//   Double_t variables[2];
//   Double_t nll;
//   tree->SetBranchAddress(var1Name, &(variables[0]));
//   tree->SetBranchAddress(var2Name, &(variables[1]));
//   tree->SetBranchAddress(nllName, &(nll));

  
//   Long64_t nEntries=tree->GetEntries();
//   for(Long64_t jentry=0; jentry<nEntries; jentry++){
    
}
Exemplo n.º 17
0
void CCDimage14(int firstrun, int lastrun)
{
  gStyle->SetPalette(1,0); 
  gSystem->Load("libMaxCam");
  gSystem->Load("libWaveformTools.so");

  std::stringstream sstm;

  TH2F * sum = 0; 
  TH2I * count = 0;
  TH2F * p=0;
         sum = new TH2F("alpha_sum","alpha_sum",256,0,1024,256,0,1024); 
        count = new TH2I("alpha_count","alpha_count",256,0,1024,256,0,1024);
  const int c = 0;
 
  gROOT->cd(); 

  int runnum;
  int setnum;
  
    if		(firstrun>=889 && lastrun<=954)		{setnum=0;}
    else if	(firstrun>=955 && lastrun<=3868)	{setnum=1;}
    else if	(firstrun>=3876 && lastrun<=5789)	{setnum=2;}
	else if	(firstrun>=5792)					{setnum=3;}
	else
	{
	gApplication->Terminate();
	exit;}
  
  
for (int x = firstrun; x <= lastrun; x++){
	runnum=x;
	
       string origfile = "/net/nudsk0001/d00/scratch/dctpc_tmp/bigdctpc_data/BigDCTPC_run_";
       string skimfile = "/net/nudsk0001/d00/scratch/dctpc_tmp/bigdctpc_skim/BigDCTPC_run_";  
      
//            string origfile = "/net/hisrv0001/home/spitzj/myOutput_";
//      string skimfile = "/net/hisrv0001/home/spitzj//myOutput_";
      
      string skimend = "skim.root";
      string origend = ".root";
      string origfilename;
      string skimfilename;
      sstm.str("");
      if (x<10000){ origfile+="0"; skimfile+="0"; }
      if (x<1000){ origfile+="0"; skimfile+="0"; }
      if (x<100){ origfile+="0"; skimfile+="0"; }
      if (x<10){ origfile+="0"; skimfile+="0"; }
      sstm << origfile << x << origend;
      origfilename = sstm.str();
      sstm.str("");
      sstm << skimfile << x << skimend;
      skimfilename = sstm.str();
      cout << origfilename << endl;
      ifstream ifile(origfilename.c_str());
      ifstream ifile2(skimfilename.c_str());
      if(!ifile)
	  continue;
      if(!ifile2)
	continue;
  	DmtpcSkimDataset d;
  	d.openRootFile(skimfilename.c_str());    
  	d.loadDmtpcEvent(true,origfilename.c_str());
  	for (int i = 0; i < d.nevents(); i ++){
        if(i%100==0){
			cout<<"Event: "<<i<<endl;
		}

	//cout<<"here"<<endl
    d.getEvent(i);    
    //cout<<"here2"<<endl;
    for (int t =0 ; t < d.event()->ntracks(c); t++)
    {
      if(d.event()->maxpixel(0,t)>150){continue;}
      if(d.event()->spark(0)){continue;} 
      p = (TH2F*)d.event()->cluster(c)->getImage(); 
      vector<int> clust = d.event()->cluster(c)->getCluster(t); 
     
    	for (vector<int>::iterator it = clust.begin(); it!=clust.end(); it++)
		{
	  		sum->SetBinContent(*it, sum->GetArray()[*it] + p->GetArray()[*it]);
	  		count->SetBinContent(*it, count->GetArray()[*it] + 1); 
		}    
    }
  }
 }

  TH2F * normalized = (TH2F*) sum->Clone("normalized"); 
  normalized->SetName("normalized");
  normalized->Divide(count); 
  normalized->SetStats(0);
  normalized->Draw("COLZ");
  c1->Print(Form("CCDimage14_set_%d_runs_%d_%d.pdf",setnum,firstrun,lastrun));

  TFile *f=new TFile(Form("CCDimage14_set_%d_runs_%d_%d.root",setnum,firstrun,lastrun),"RECREATE");
  normalized->Write();
  f->Close();

  gApplication->Terminate();
}
Exemplo n.º 18
0
void tnpScale_IDISO_el( bool printplot = false ) {

  //----------------------------------------
  // Files
  //----------------------------------------

  char* version = (char*) "V00-00-00";

  TChain *chmc   = new TChain("leptons");
  TChain *chdata = new TChain("leptons");

  char* suffix = "";
  //char* suffix = "_2jets";

  chmc->  Add(Form("smurf/%s/dymm_test%s.root"              , version , suffix));  
  chdata->Add(Form("smurf/%s/data_SingleEl_2012A%s.root"    , version , suffix));


  //----------------------------------------
  // bins 
  //----------------------------------------

  //float ptbin[] = {10., 15., 20., 30., 40., 50., 7000.};
  float ptbin[] = { 30. , 40. , 50. , 60. , 80.0 , 100.0 , 120.0 , 150.0 , 7000.};
  float etabin[] = {0, 0.8, 1.5, 2.1};
  int nptbin=8;
  int netabin=3;

  //
  // histogram
  //
  //deno
  TH2F *hmcid_deno 	= new TH2F("hmcid_deno", "hmcid_deno", nptbin, ptbin, netabin, etabin);
  TH2F *hmciso_deno 	= new TH2F("hmciso_deno", "hmciso_deno", nptbin, ptbin, netabin, etabin);
  TH2F *hdataid_deno 	= new TH2F("hdataid_deno", "hdataid_deno", nptbin, ptbin, netabin, etabin);
  TH2F *hdataiso_deno	= new TH2F("hdataiso_deno", "hdataiso_deno", nptbin, ptbin, netabin, etabin);
  hmcid_deno->Sumw2();
  hmciso_deno->Sumw2();
  hdataid_deno->Sumw2();
  hdataiso_deno->Sumw2();
  //num
  TH2F *hmcid_num 	= new TH2F("hmcid_num", "hmcid_num", nptbin, ptbin, netabin, etabin);
  TH2F *hmciso_num 	= new TH2F("hmciso_num", "hmciso_num", nptbin, ptbin, netabin, etabin);
  TH2F *hdataid_num 	= new TH2F("hdataid_num", "hdataid_num", nptbin, ptbin, netabin, etabin);
  TH2F *hdataiso_num 	= new TH2F("hdataiso_num", "hdataiso_num", nptbin, ptbin, netabin, etabin);
  hmcid_num->Sumw2();
  hmciso_num->Sumw2();
  hdataid_num->Sumw2();
  hdataiso_num->Sumw2();
  // eff
  TH2F *hmcid 	= new TH2F("hmcid", "hmcid", nptbin, ptbin, netabin, etabin);
  TH2F *hmciso 	= new TH2F("hmciso", "hmciso", nptbin, ptbin, netabin, etabin);
  TH2F *hdataid 	= new TH2F("hdataid", "hdataid", nptbin, ptbin, netabin, etabin);
  TH2F *hdataiso 	= new TH2F("hdataiso", "hdataiso", nptbin, ptbin, netabin, etabin);
  hmcid->Sumw2();
  hmciso->Sumw2();
  hdataid->Sumw2();
  hdataiso->Sumw2();
  // SF
  TH2F *hsfid 	= new TH2F("hsfid", "hsfid", nptbin, ptbin, netabin, etabin);
  TH2F *hsfiso 	= new TH2F("hsfiso", "hsfiso", nptbin, ptbin, netabin, etabin);
  hsfid->Sumw2();
  hsfiso->Sumw2();

  TCut elid  	= "(leptonSelection&8)==8";            // ele id 
  TCut eliso 	= "(leptonSelection&16)==16";          // ele iso

  TCut zmass("abs(tagAndProbeMass-91)<15");
  TCut os("qProbe*qTag<0");
  TCut eltnp("(eventSelection&1)==1");
  //TCut eltnptrig("HLT_TNP_tag > 0 || HLT_TNPel_tag > 0");
  TCut eltnptrig("HLT_Ele27_WP80_tag > 0");
  TCut tag_eta21("abs(tag->eta())<2.1");
  TCut tag_pt30("tag->pt()>30.0");

  TCut met30("met<30");
  TCut nbl0("nbl==0");

  TCut njets0("njets==0");
  TCut njets1("njets==1");
  TCut njets2("njets==2");
  TCut njets3("njets==3");
  TCut njets4("njets>=4");

  //TCut tnpcut   = "abs(tagAndProbeMass-91)<15 && (eventSelection&2)==2 && HLT_IsoMu30_eta2p1_tag>0 && qProbe*qTag<0 && abs(tag->eta())<2.1 && tag->pt()>30.0"; 

  TCut tnpcut;
  tnpcut += zmass;
  tnpcut += os;
  tnpcut += eltnp;
  tnpcut += eltnptrig;
  tnpcut += tag_eta21;
  tnpcut += tag_pt30;

  tnpcut += met30;
  tnpcut += nbl0;

  //tnpcut += njets2;

  cout << "Selection  : " << tnpcut.GetTitle()          << endl;
  cout << "Ndata      : " << chdata->GetEntries(tnpcut) << endl;
  cout << "NMC        : " << chmc->GetEntries(tnpcut)   << endl;

  chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_deno", 	tnpcut+eliso,	      	"goff");
  chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_num", 	tnpcut+eliso+elid,	"goff");
  chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_deno", 	tnpcut+elid,	      	"goff");
  chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_num", 	tnpcut+elid+eliso,	"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_deno", 	tnpcut+eliso,		"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_num", 	tnpcut+eliso+elid,	"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_deno", 	tnpcut+elid,	       	"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_num", 	tnpcut+elid+eliso,	"goff");

  // get efficiencies 
  hmcid->Divide(hmcid_num,hmcid_deno,1,1,"B");
  hmciso->Divide(hmciso_num,hmciso_deno,1,1,"B");
  hdataid->Divide(hdataid_num,hdataid_deno,1,1,"B");
  hdataiso->Divide(hdataiso_num,hdataiso_deno,1,1,"B");

  // hmcid->Divide(hmcid_num,hmcid_deno,1,1);
  // hmciso->Divide(hmciso_num,hmciso_deno,1,1);
  // hdataid->Divide(hdataid_num,hdataid_deno,1,1);
  // hdataiso->Divide(hdataiso_num,hdataiso_deno,1,1);
	
  // get scale factors
  hsfid->Divide(hdataid, hmcid, 1, 1);
  hsfiso->Divide(hdataiso, hmciso, 1, 1);

  // Draw histograms	
  //hmcid->Draw("text");

  // print table
  cout << " ------ MC ID ----- " << endl;
  printline(hmcid);
  cout << " ------ MC ISO ----- " << endl;
  printline(hmciso);
  cout << " ------ DATA ID ----- " << endl;
  printline(hdataid);
  cout << " ------ DATA ISO ----- " << endl;
  printline(hdataiso);
  cout << " ------ Scale Factor ID ----- " << endl;
  printline(hsfid);
  cout << " ------ Scale Factor ISO ----- " << endl;
  printline(hsfiso);

  TCanvas *c_iso[10];
  TCanvas *c_id[10];

  for( int i = 0 ; i < 5 ; i++ ){

    TCut mysel;
    if     ( i==0 ) mysel = TCut(tnpcut+njets0);
    else if( i==1 ) mysel = TCut(tnpcut+njets1);
    else if( i==2 ) mysel = TCut(tnpcut+njets2);
    else if( i==3 ) mysel = TCut(tnpcut+njets3);
    else if( i==4 ) mysel = TCut(tnpcut+njets4);

    c_iso[i] = new TCanvas(Form("c_iso_%i",i),Form("c_iso_%i",i),600,600);
    c_iso[i]->cd();
    printHisto( c_iso[i] , chdata , chmc , TCut(eliso) , TCut(mysel+elid) , "probe.pt()" , 10 , 0.0 , 300.0 , "lepton p_{T} [GeV]" , "iso efficiency" );
    if( printplot ) c_iso[i]->Print(Form("plots/iso_el_njets%i.pdf",i));

    c_id[i] = new TCanvas(Form("c_id_%i",i),Form("c_id_%i",i),600,600);
    c_id[i]->cd();
    printHisto( c_id[i] , chdata , chmc , TCut(elid) , TCut(mysel+eliso) , "probe.pt()" , 10 , 0.0 , 300.0 , "lepton p_{T} [GeV]" , "ID efficiency" );
    if( printplot ) c_id[i]->Print(Form("plots/id_el_njets%i.pdf",i));

  }

  /*

  //---------------------------
  // tag cuts
  //---------------------------

  TCut zmass("abs(tagAndProbeMass-91)<15");
  TCut eltnp("(eventSelection&1)==1");
  TCut mutnp("(eventSelection&2)==2");
  TCut os("qProbe*qTag<0");
  TCut tag_eta21("abs(tag->eta())<2.1");
  TCut tag_eta25("abs(tag->eta())<2.5");
  TCut njets1("njets>=1");
  TCut njets2("njets>=2");
  TCut njets3("njets>=3");
  TCut njets4("njets>=4");
  TCut tag_pt30("tag->pt()>30.0");
  TCut met30("met<30");
  TCut met20("met<20");
  TCut nbm0("nbm==0");
  TCut nbl0("nbl==0");
  TCut mt30("mt<30");
  TCut eltnptrig("HLT_TNP_tag > 0 || HLT_TNPel_tag > 0");
  TCut mutnptrig("HLT_IsoMu30_eta2p1_tag > 0");

  //---------------------------
  // tag cuts
  //---------------------------

  TCut mufo 	= "(leptonSelection&32768)==32768";    // mu fo
  TCut elfo     = "(leptonSelection&4)==4";            // ele fo 
  TCut elid  	= "(leptonSelection&8)==8";            // ele id 
  TCut eliso 	= "(leptonSelection&16)==16";          // ele iso
  TCut probept  = "probe->pt()>30";                    // probe pt
  TCut drprobe  = "drprobe<0.05";                      // dR(probe,pfcandidate)

  TCut eltnpcut;
  eltnpcut += zmass;
  eltnpcut += os;
  eltnpcut += eltnp;
  eltnpcut += tag_eta25;
  //eltnpcut += njets2;
  eltnpcut += tag_pt30;
  eltnpcut += eltnptrig;
  eltnpcut += met30;
  // eltnpcut += mt30;
  eltnpcut += nbl0;
  
  eltnpcut += elid;
  eltnpcut += probept;
  eltnpcut += drprobe;

  TCut mutnpcut;
  mutnpcut += zmass;
  mutnpcut += os;
  mutnpcut += mutnp;
  mutnpcut += tag_eta21;
  //mutnpcut += njets2;
  mutnpcut += tag_pt30;
  mutnpcut += mutnptrig;
  mutnpcut += met30;
  // mutnpcut += mt30;
  mutnpcut += nbl0;

  mutnpcut += muid;
  mutnpcut += probept;
  mutnpcut += drprobe;


  //eltnpcut += njets2;
  //eltnpcut += njets3;
  //eltnpcut += nbm0;
  //eltnpcut += mt30;
  //eltnpcut += met20;

  //TCut eltnpcut 	 = "abs(tagAndProbeMass-91)<15 && (eventSelection&1)==1 && qProbe*qTag<0 && abs(tag->eta())<2.5 && njets>=4 && tag->pt()>30.0 && met<30.0 && nbm==0 && mt<30"; 
  //TCut mutnpcut 	 = "abs(tagAndProbeMass-91)<15 && (eventSelection&2)==2 && HLT_IsoMu30_eta2p1_tag>0 && qProbe*qTag<0 && abs(tag->eta())<2.1 && njets>=4 && tag->pt()>30.0"; 

  TCut vtxweight = "vtxweight";

  cout << "Electrons:" << endl;
  cout << "Total MC yields 	: " << chmc->GetEntries(eltnpcut) << endl;
  cout << "Total DATA yields 	: " << chdata->GetEntries(eltnpcut) << endl;

  cout << "Muons:" << endl;
  cout << "Total MC yields 	: " << chmc->GetEntries(mutnpcut) << endl;
  cout << "Total DATA yields 	: " << chdata->GetEntries(mutnpcut) << endl;


  //TCut njets    = "njets>=2";
  TCut tkisoold = "tkisoold/probe->pt()>0.1";
  TCut tkisonew = "tkisonew/probe->pt()>0.1";

  //-----------------------------------------
  // check nvtx data vs. MC
  //-----------------------------------------

  TH1F *hnvtx_mc   = new TH1F("hnvtx_mc"  ,"",30,0,30);
  TH1F *hnvtx_data = new TH1F("hnvtx_data","",30,0,30);

  hnvtx_mc->Sumw2();
  hnvtx_data->Sumw2();

  chdata->Draw("nvtx>>hnvtx_data",(eltnpcut||mutnpcut));
  chmc->Draw("nvtx>>hnvtx_mc",(eltnpcut||mutnpcut)*vtxweight);

  TCanvas *c1 = new TCanvas();
  c1->cd();
  
  hnvtx_mc->SetLineColor(2);
  hnvtx_mc->SetMarkerColor(2);
  hnvtx_data->SetLineColor(4);
  hnvtx_data->SetMarkerColor(4);
  
  hnvtx_data->GetXaxis()->SetTitle("N_{VTX}");
  hnvtx_data->DrawNormalized();
  hnvtx_mc->DrawNormalized("same");

  TLegend *leg = new TLegend(0.6,0.6,0.8,0.8);
  leg->AddEntry(hnvtx_data,"data","lp");
  leg->AddEntry(hnvtx_mc,"MC","lp");
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->Draw();

  if( printplot ) c1->Print("plots/nvtx.pdf");



  // Fill histograms
  //
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_deno", 	tnpcut+"&&"+eliso,				"goff");
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_num", 		tnpcut+"&&"+eliso+"&&"+elid,	"goff");
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_deno", 	tnpcut+"&&"+elid,				"goff");
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_num", 	tnpcut+"&&"+elid+"&&"+eliso,	"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_deno", 	tnpcut+"&&"+eliso,				"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_num", 		tnpcut+"&&"+eliso+"&&"+elid,	"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_deno", 	tnpcut+"&&"+elid,				"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_num", 	tnpcut+"&&"+elid+"&&"+eliso,	"goff");

  */
	
}
Exemplo n.º 19
0
void acceptance(const char* file = "upsilonGun.root", const char* outputName = "acceptance.root") {
  Int_t genUpsSize;
  Float_t genUpsPt[NMAX];
  Float_t genUpsEta[NMAX];
  Float_t genUpsPhi[NMAX];
  Float_t genUpsRapidity[NMAX];
  Int_t genMuSize;
  Float_t genMuPt[NMAX];
  Float_t genMuEta[NMAX];
  Float_t genMuPhi[NMAX];
  Int_t genMuCharge[NMAX];
  Int_t recoMuSize;
  Float_t recoMuPt[NMAX];
  Float_t recoMuEta[NMAX];
  Float_t recoMuPhi[NMAX];
  Int_t recoMuCharge[NMAX];

  TFile* f1 = new TFile(file);
  TTree* t = (TTree*)f1->Get("UpsTree");
  t->SetBranchAddress("genUpsSize",&genUpsSize);
  t->SetBranchAddress("genUpsPt",genUpsPt);
  t->SetBranchAddress("genUpsEta",genUpsEta);
  t->SetBranchAddress("genUpsPhi",genUpsPhi);
  t->SetBranchAddress("genUpsRapidity",genUpsRapidity);
  t->SetBranchAddress("genMuSize",&genMuSize);
  t->SetBranchAddress("genMuPt",genMuPt);
  t->SetBranchAddress("genMuEta",genMuEta);
  t->SetBranchAddress("genMuPhi",genMuPhi);
  t->SetBranchAddress("genMuCharge",genMuCharge);
  t->SetBranchAddress("recoMuSize",&recoMuSize);
  t->SetBranchAddress("recoMuPt",recoMuPt);
  t->SetBranchAddress("recoMuEta",recoMuEta);
  t->SetBranchAddress("recoMuPhi",recoMuPhi);
  t->SetBranchAddress("recoMuCharge",recoMuCharge);

  TH2F* genPtRap = new TH2F("genUps","",4,0,20,4,-2,2);
  TH1F* genPt = new TH1F("genUps1D","",4,0,20);
  genPtRap->Sumw2();
  genPt->Sumw2();
  genPtRap->SetTitle(";Upsilon pT (GeV/c);Upsilon Rapidity;");
  genPt->SetTitle(";Upsilon pT (GeV/c);Acceptance;");
  TH2F* recoPtRap = (TH2F*)genPtRap->Clone("recoUps");
  TH1F* recoPt = (TH1F*)genPt->Clone("recoUps1D");
  recoPtRap->Sumw2();
  recoPt->Sumw2();

  for(int i=0; i<t->GetEntries(); i++){
    if(i%100000 == 0)
      std::cout<<i<<std::endl;
    t->GetEntry(i);

    // calculate cosTheta
    TLorentzVector genUps; genUps.SetPtEtaPhiM(genUpsPt[0], genUpsEta[0], genUpsPhi[0], 9.46);
    TLorentzRotation boost(-genUps.BoostVector());
    int mp = genMuCharge[0]>0 ? 0 : 1;
    TLorentzVector genMuPlus; genMuPlus.SetPtEtaPhiM(genMuPt[mp], genMuEta[mp], genMuPhi[mp], 0.106);
    genMuPlus *= boost;
    Float_t cosThetaStar = genMuPlus.Vect().Dot(genUps.Vect())/genMuPlus.Vect().Mag()/genUps.Vect().Mag();

    // set the weight
    Float_t weight = 1;

    genPtRap->Fill( genUpsPt[0], genUpsRapidity[0], weight );
    genPt->Fill( genUpsPt[0], weight );

    Float_t recoUpsPt = 0;
    Float_t recoUpsRapidity = 0;
    double minDeltaM = 1000;
    for(int tr1=0; tr1<recoMuSize; tr1++){
      for(int tr2=tr1+1; tr2<recoMuSize; tr2++){
        if ( recoMuCharge[tr1]*recoMuCharge[tr2] == -1 && recoMuPt[tr1] >= 3.5 && recoMuPt[tr2] >= 3.5 && fabs(recoMuEta[tr1]) < 2.1 && fabs(recoMuEta[tr2]) < 2.1 ){
          TLorentzVector mu1; mu1.SetPtEtaPhiM(recoMuPt[tr1], recoMuEta[tr1], recoMuPhi[tr1], 0.106);
          TLorentzVector mu2; mu2.SetPtEtaPhiM(recoMuPt[tr2], recoMuEta[tr2], recoMuPhi[tr2], 0.106);
          TLorentzVector recoUps(mu1 + mu2);
          double deltaM = fabs(recoUps.M()-9.46);
          if( deltaM < minDeltaM ){
            recoUpsPt = recoUps.Pt();
            recoUpsRapidity = recoUps.Rapidity();
            minDeltaM = deltaM;
          }
        }
      }
    }
    if( minDeltaM < 1.0 ){
      recoPtRap->Fill( recoUpsPt, recoUpsRapidity, weight );
      recoPt->Fill( recoUpsPt, weight );
    }
  }

  TFile out(outputName,"recreate");
  TH2F* acc = (TH2F*)genPtRap->Clone("acceptance");
  TH1F* acc1D = (TH1F*)genPt->Clone("acceptance1D");
  acc->Sumw2();
  acc1D->Sumw2();
  acc->Divide(recoPtRap,genPtRap,1,1,"B");
  acc1D->Divide(recoPt,genPt,1,1,"B");
  acc->Write();
  acc1D->Write();
  out.Close();
}
Exemplo n.º 20
0
// inputs data file and event in file to display (default is to integrate all)
void dqmDisplay(TString fdat, int ndisplay = -1){

  gStyle->SetOptStat(0);

  TFile *f = new TFile(fdat);
  if (f->IsZombie()){
    cout << "Cannot open file: " << fdat << endl;
    return;
  }

  TBEvent *event = new TBEvent();
  TTree *t1041 = (TTree*)f->Get("t1041"); 
  TBranch *bevent = t1041->GetBranch("tbevent");
  bevent->SetAddress(&event);

  Bool_t singleEvent = (ndisplay >= 0);

  Mapper * mapper = Mapper::Instance();

  TH2F * hModU = (TH2F*)moduleHistogram(true, "RO", threshold, 2500, singleEvent);
  TH2F * hModD = (TH2F*)moduleHistogram(false, "RO", threshold, 2500, singleEvent);
  TH2F * hChanU = (TH2F*)channelHistogram(true, "RO", threshold, 2500, singleEvent);
  TH2F * hChanD = (TH2F*)channelHistogram(false, "RO", threshold, 2500, singleEvent);

  TH2F * hModU_time = (TH2F*)moduleHistogram(true, "Timing", 0, -1, singleEvent);
  TH2F * hModD_time = (TH2F*)moduleHistogram(false, "Timing", 0, -1, singleEvent);
  TH2F * hChanU_time = (TH2F*)channelHistogram(true, "Timing", 0, -1, singleEvent);
  TH2F * hChanD_time = (TH2F*)channelHistogram(false, "Timing", 0, -1, singleEvent);

  int nPerMod = t1041->GetEntries() / 16;
  int nPerFiber = t1041->GetEntries() / 64;

  TH2F * hModU_nhits = (TH2F*)moduleHistogram(true, "nHits", nPerMod * .85, nPerMod * 1.1, singleEvent);
  TH2F * hModD_nhits = (TH2F*)moduleHistogram(false, "nHits", nPerMod * .85, nPerMod * 1.1, singleEvent);
  TH2F * hChanU_nhits = (TH2F*)channelHistogram(true, "nHits", nPerFiber * .25, nPerFiber * 1.1, singleEvent);
  TH2F * hChanD_nhits = (TH2F*)channelHistogram(false, "nHits", nPerFiber * .25, nPerFiber * 1.1, singleEvent);

  TH2F * hModU_ntriggers = (TH2F*)moduleHistogram(true, "nTriggers", nPerMod * .95, nPerMod * 1.3, singleEvent);
  TH2F * hModD_ntriggers = (TH2F*)moduleHistogram(false, "nTriggers", nPerMod * .95, nPerMod * 1.3, singleEvent);
  TH2F * hChanU_ntriggers = (TH2F*)channelHistogram(true, "nTriggers", nPerFiber * .95, nPerFiber * 1.3, singleEvent);
  TH2F * hChanD_ntriggers = (TH2F*)channelHistogram(false, "nTriggers", nPerFiber * .95, nPerFiber * 1.3, singleEvent);

  Int_t start = 0; 
  Int_t end = t1041->GetEntries();

  if (singleEvent) {
    start = ndisplay;
    end = ndisplay + 1;
  }

  for (Int_t i=start; i < end; i++) {
    t1041->GetEntry(i);
    for (Int_t j = 0; j < event->NPadeChan(); j++){
      PadeChannel pch = event->GetPadeChan(j);

      UShort_t max = pch.GetMax();
      Int_t maxTime = pch.GetPeak();
      if (max>MAXADC) continue;    // skip channels with bad adc readings (should be RARE)

      int channelID=pch.GetChannelID();   // boardID*100+channelNum in PADE
      int moduleID,fiberID;
      mapper->ChannelID2ModuleFiber(channelID,moduleID,fiberID);  // get module and fiber IDs

      float xm,ym,xf,yf;
      mapper->ModuleXY(moduleID,xm,ym);
      mapper->FiberXY(fiberID, xf, yf);
	    
      if(moduleID < 0) {
	hModU_ntriggers->Fill(xm, ym);
	hChanU_ntriggers->Fill(xf, yf);
      }
      else {
	hModD_ntriggers->Fill(xm, ym);
	hChanD_ntriggers->Fill(xf, yf);
      }
      if(max <= threshold) continue;


      if (moduleID < 0) {
	hModU->Fill(xm, ym, max);
	hModU_time->Fill(xm, ym, maxTime);
	hModU_nhits->Fill(xm, ym);

	hChanU->Fill(xf, yf, max);
	hChanU_time->Fill(xf, yf, maxTime);
	hChanU_nhits->Fill(xf, yf);
      }
      else {
	hModD->Fill(xm, ym, max);
	hModD_time->Fill(xm, ym, maxTime);
	hModD_nhits->Fill(xm, ym);

	hChanD->Fill(xf, yf, max);
	hChanD_time->Fill(xf, yf, maxTime);
	hChanD_nhits->Fill(xf, yf);
      }
      
    }

  }

  hModD->Divide(hModD_nhits);
  hModU->Divide(hModU_nhits);
  hChanD->Divide(hChanD_nhits);
  hChanU->Divide(hChanU_nhits);

  hModD_time->Divide(hModD_nhits);
  hModU_time->Divide(hModU_nhits);
  hChanD_time->Divide(hChanD_nhits);
  hChanU_time->Divide(hChanU_nhits);

  drawCalorimeterPlot("AvgPeakHeight", 
		      hModU, hModD, hChanU, hChanD,
		      t1041->GetEntries(), ndisplay);

  drawCalorimeterPlot("AvgPeakTiming",
		      hModU_time, hModD_time, hChanU_time, hChanD_time,
		      t1041->GetEntries(), ndisplay);

  drawCalorimeterPlot("NHits", 
		      hModU_nhits, hModD_nhits, hChanU_nhits, hChanD_nhits,
		      t1041->GetEntries(), ndisplay);

  drawCalorimeterPlot("NTriggers",
		      hModU_ntriggers, hModD_ntriggers, hChanU_ntriggers, hChanD_ntriggers,
		      t1041->GetEntries(), ndisplay);

}
Exemplo n.º 21
0
void tnpScale_IDISO( int leptype = 1, bool printplot = false ) {

  cout << endl;
  cout << "-------------------" << endl;
  if     ( leptype == 0 ) cout << "Doing electrons" << endl;
  else if( leptype == 1 ) cout << "Doing muons"      << endl;
  else{
    cout << "ERROR! unrecognized leptype " << leptype << endl;
    exit(0);
  }
  cout << "-------------------" << endl;

  //----------------------------------------
  // Files
  //----------------------------------------

  TChain *chmc   = new TChain("leptons");
  TChain *chdata = new TChain("leptons");

  char* version = (char*) "V00-00-06";
  char* suffix = "";
  //char* suffix = "_2jets";
  //char* suffix = "_probept100";


  chmc->  Add(Form("smurf/ZJetsFull_%s/merged%s.root",version,suffix));

  if( leptype == 1 ){
    chdata->Add(Form("smurf/SingleMu2012AFull_%s/merged_json%s.root",version,suffix));
    chdata->Add(Form("smurf/SingleMu2012BFull_%s/merged_json%s.root",version,suffix));
    chdata->Add(Form("smurf/SingleMu2012CFull_%s/merged_json%s.root",version,suffix));
    chdata->Add(Form("smurf/SingleMu2012DFull_%s/merged_json%s.root",version,suffix));
  }
  else{
    chdata->Add(Form("smurf/SingleEl2012AFull_%s/merged_json%s.root",version,suffix));
    chdata->Add(Form("smurf/SingleEl2012BFull_%s/merged_json%s.root",version,suffix));
    chdata->Add(Form("smurf/SingleEl2012CFull_%s/merged_json%s.root",version,suffix));
    chdata->Add(Form("smurf/SingleEl2012DFull_%s/merged_json%s.root",version,suffix));
  }

  //----------------------------------------
  // bins 
  //----------------------------------------

  // float ptbin[]  = {10., 15., 20., 30., 40., 50., 7000.};
  // float ptbin[]  = { 30. , 40. , 50. , 60. , 80.0 , 100.0 , 120.0 , 150.0 , 7000.};
  // float etabin[] = {0, 0.8, 1.5, 2.1};
  // int nptbin=8;
  // int netabin=3;

  // float ptbin[]  = { 20., 30. , 40. , 50. , 60. , 80.0 , 100.0 , 150.0 , 200.0 , 300.0 , 500.0 , 1000.0 , 10000000.0};
  // int   nptbin   = 12;

  // float etabin[] = {0,2.1};
  // int   netabin  = 1;

  float ptbin[] = { 20., 30. , 40. , 50. , 60. , 80.0 , 100.0 , 150.0 , 200.0 , 300.0, 10000.0};
  int   nptbin  = 10;

  float etabin[4];
  int   netabin = 0;

  if( leptype == 1 ){
    cout << "DOING MUON ETA BINS" << endl;
    netabin=3;
    etabin[0] = 0.0;
    etabin[1] = 0.8;
    etabin[2] = 1.5;
    etabin[3] = 2.1;
  }

  if( leptype == 0 ){
    cout << "DOING ELECTRON ETA BINS" << endl;
    netabin=2;
    etabin[0] = 0.0;
    etabin[1] = 0.8;
    etabin[2] = 1.4442;

    // netabin=1;
    // etabin[0] = 0.0;
    // etabin[1] = 1.4442;
  }


  //deno
  TH2F *hmcid_deno 	= new TH2F("hmcid_deno"   , "hmcid_deno"   , nptbin, ptbin, netabin, etabin);
  TH2F *hmciso_deno 	= new TH2F("hmciso_deno"  , "hmciso_deno"  , nptbin, ptbin, netabin, etabin);
  TH2F *hdataid_deno 	= new TH2F("hdataid_deno" , "hdataid_deno" , nptbin, ptbin, netabin, etabin);
  TH2F *hdataiso_deno	= new TH2F("hdataiso_deno", "hdataiso_deno", nptbin, ptbin, netabin, etabin);
  hmcid_deno->Sumw2();
  hmciso_deno->Sumw2();
  hdataid_deno->Sumw2();
  hdataiso_deno->Sumw2();

  //num
  TH2F *hmcid_num 	= new TH2F("hmcid_num"    , "hmcid_num"    , nptbin, ptbin, netabin, etabin);
  TH2F *hmciso_num 	= new TH2F("hmciso_num"   , "hmciso_num"   , nptbin, ptbin, netabin, etabin);
  TH2F *hdataid_num 	= new TH2F("hdataid_num"  , "hdataid_num"  , nptbin, ptbin, netabin, etabin);
  TH2F *hdataiso_num 	= new TH2F("hdataiso_num" , "hdataiso_num" , nptbin, ptbin, netabin, etabin);
  hmcid_num->Sumw2();
  hmciso_num->Sumw2();
  hdataid_num->Sumw2();
  hdataiso_num->Sumw2();

  // eff
  TH2F *hmcid 	        = new TH2F("hmcid"        , "hmcid"        , nptbin, ptbin, netabin, etabin);
  TH2F *hmciso 	        = new TH2F("hmciso"       , "hmciso"       , nptbin, ptbin, netabin, etabin);
  TH2F *hdataid 	= new TH2F("hdataid"      , "hdataid"      , nptbin, ptbin, netabin, etabin);
  TH2F *hdataiso 	= new TH2F("hdataiso"     , "hdataiso"     , nptbin, ptbin, netabin, etabin);
  hmcid->Sumw2();
  hmciso->Sumw2();
  hdataid->Sumw2();
  hdataiso->Sumw2();

  // SF
  TH2F *hsfid 	= new TH2F("hsfid"  , "hsfid" , nptbin, ptbin, netabin, etabin);
  TH2F *hsfiso 	= new TH2F("hsfiso" , "hsfiso", nptbin, ptbin, netabin, etabin);
  hsfid->Sumw2();
  hsfiso->Sumw2();

  // TCuts
  TCut muid ("(leptonSelection&65536)==65536");     // mu id 
  TCut muiso("(leptonSelection&131072)==131072");   // mu iso 
  TCut elid ("(leptonSelection&8)==8");             // ele id 
  TCut eliso("(leptonSelection&16)==16");           // ele iso

  TCut zmass("abs(tagAndProbeMass-91)<15");
  TCut tightzmass("abs(tagAndProbeMass-91)<5");
  TCut os("qProbe*qTag<0");

  TCut mutnp("(eventSelection&2)==2");
  TCut mutnptrig("HLT_IsoMu24_tag > 0");

  TCut eltnp("(eventSelection&1)==1");
  TCut eltnptrig("HLT_Ele27_WP80_tag > 0");

  TCut tag_eta21("abs(tag->eta())<2.1");
  TCut tag_eta14("abs(tag->eta())<1.4442");
  TCut tag_pt30("tag->pt()>30.0");
  TCut probe_eta21("abs(probe->eta())<2.1");
  TCut probe_eta14("abs(probe->eta())<1.4442");

  TCut mutrk("mutrk==1");

  TCut met30("met<30");
  TCut nbl0("nbl==0");

  TCut njets0("njets>=0");
  TCut njets1("njets>=1");
  TCut njets2("njets>=2");
  TCut njets3("njets>=3");
  TCut njets4("njets>=4");

  TCut mud0("mud0 < 0.02");
  TCut mudz("mudz < 0.5");

  // TCut mud0("mud0 < 0.2");
  // TCut mudz("mudz < 1.0");

  //TCut tnpcut   = "abs(tagAndProbeMass-91)<15 && (eventSelection&2)==2 && HLT_IsoMu30_eta2p1_tag>0 && qProbe*qTag<0 && abs(tag->eta())<2.1 && tag->pt()>30.0"; 

  TCut tnpcut;
  tnpcut += zmass;
  //tnpcut += tightzmass;
  tnpcut += os;
  tnpcut += tag_pt30;

  tnpcut += met30;
  tnpcut += nbl0;

  TCut  lepid;
  TCut  lepiso;
  char* lepchar = "";

  if( leptype == 0 ){
    tnpcut += tag_eta14;
    tnpcut += probe_eta14;
    tnpcut += eltnp;
    tnpcut += eltnptrig;
    lepid   = TCut(elid);
    lepiso  = TCut(eliso);
    lepchar = "el";
  }
  else if( leptype == 1 ){
    tnpcut += tag_eta21;
    tnpcut += probe_eta21;
    //tnpcut += mutrk;
    //tnpcut += mud0;
    //tnpcut += mudz;
    tnpcut += mutnp;
    tnpcut += mutnptrig;
    lepid   = TCut(muid);
    lepiso  = TCut(muiso);
    lepchar = "mu";
  }
  
  //tnpcut += njets2;
  cout << "Selection  : " << tnpcut.GetTitle()          << endl;
  cout << "Ndata      : " << chdata->GetEntries(tnpcut) << endl;
  cout << "NMC        : " << chmc->GetEntries(tnpcut)   << endl;
  cout << "ID cut     : " << lepid.GetTitle()           << endl;
  cout << "iso cut    : " << lepiso.GetTitle()          << endl;

  chmc->  Draw("abs(probe->eta()):probe->pt()>>hmcid_deno", 	tnpcut+lepiso,	      	"goff");
  chmc->  Draw("abs(probe->eta()):probe->pt()>>hmcid_num", 	tnpcut+lepiso+lepid,	"goff");
  chmc->  Draw("abs(probe->eta()):probe->pt()>>hmciso_deno", 	tnpcut+lepid,	      	"goff");
  chmc->  Draw("abs(probe->eta()):probe->pt()>>hmciso_num", 	tnpcut+lepid+lepiso,	"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_deno", 	tnpcut+lepiso,		"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_num", 	tnpcut+lepiso+lepid,	"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_deno", 	tnpcut+lepid,	       	"goff");
  chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_num", 	tnpcut+lepid+lepiso,	"goff");

  // get efficiencies 
  hmcid->Divide(hmcid_num,hmcid_deno,1,1,"B");
  hmciso->Divide(hmciso_num,hmciso_deno,1,1,"B");
  hdataid->Divide(hdataid_num,hdataid_deno,1,1,"B");
  hdataiso->Divide(hdataiso_num,hdataiso_deno,1,1,"B");

  // hmcid->Divide(hmcid_num,hmcid_deno,1,1);
  // hmciso->Divide(hmciso_num,hmciso_deno,1,1);
  // hdataid->Divide(hdataid_num,hdataid_deno,1,1);
  // hdataiso->Divide(hdataiso_num,hdataiso_deno,1,1);
	
  // get scale factors
  hsfid->Divide(hdataid, hmcid, 1, 1);
  hsfiso->Divide(hdataiso, hmciso, 1, 1);

  // Draw histograms	
  //hmcid->Draw("text");


  printHeader( leptype , "MC ID" );
  printline(hmcid);

  printHeader( leptype , "MC ISO" );
  printline(hmciso);

  printHeader( leptype , "DATA ID" );
  printline(hdataid);

  printHeader( leptype , "DATA ISO" );
  printline(hdataiso);

  printHeader( leptype , "Scale Factor ID" );
  printline(hsfid);

  printHeader( leptype , "Scale Factor ISO" );
  printline(hsfiso);

  cout << "\\hline" << endl << "\\hline" << endl;

  TCanvas *c_iso[10];
  TCanvas *c_id[10];

  for( int i = 0 ; i < 1 ; i++ ){

    TCut mysel;
    if     ( i==0 ) mysel = TCut(tnpcut+njets0);
    else if( i==1 ) mysel = TCut(tnpcut+njets1);
    else if( i==2 ) mysel = TCut(tnpcut+njets2);
    else if( i==3 ) mysel = TCut(tnpcut+njets3);
    else if( i==4 ) mysel = TCut(tnpcut+njets4);

    c_iso[i] = new TCanvas(Form("c_iso_%i",i),Form("c_iso_%i",i),600,600);
    c_iso[i]->cd();
    printHisto( c_iso[i] , chdata , chmc , TCut(lepiso) , TCut(mysel+lepid) , "probe.pt()" , 10 , 0.0 , 340.0 , "lepton p_{T} [GeV]" , "iso efficiency" );
    if( printplot ) c_iso[i]->Print(Form("plots/%s_iso_njets%i.pdf",lepchar,i));

    c_id[i] = new TCanvas(Form("c_id_%i",i),Form("c_id_%i",i),600,600);
    c_id[i]->cd();
    printHisto( c_id[i] , chdata , chmc , TCut(lepid) , TCut(mysel+lepiso) , "probe.pt()" , 10 , 0.0 , 340.0 , "lepton p_{T} [GeV]" , "ID efficiency" );
    if( printplot ) c_id[i]->Print(Form("plots/%s_id_njets%i.pdf",lepchar,i));

  }

  /*

  //---------------------------
  // tag cuts
  //---------------------------

  TCut zmass("abs(tagAndProbeMass-91)<15");
  TCut eltnp("(eventSelection&1)==1");
  TCut mutnp("(eventSelection&2)==2");
  TCut os("qProbe*qTag<0");
  TCut tag_eta21("abs(tag->eta())<2.1");
  TCut tag_eta25("abs(tag->eta())<2.5");
  TCut njets1("njets>=1");
  TCut njets2("njets>=2");
  TCut njets3("njets>=3");
  TCut njets4("njets>=4");
  TCut tag_pt30("tag->pt()>30.0");
  TCut met30("met<30");
  TCut met20("met<20");
  TCut nbm0("nbm==0");
  TCut nbl0("nbl==0");
  TCut mt30("mt<30");
  TCut eltnptrig("HLT_TNP_tag > 0 || HLT_TNPel_tag > 0");
  TCut mutnptrig("HLT_IsoMu30_eta2p1_tag > 0");

  //---------------------------
  // tag cuts
  //---------------------------

  TCut mufo 	= "(leptonSelection&32768)==32768";    // mu fo
  TCut elfo     = "(leptonSelection&4)==4";            // ele fo 
  TCut elid  	= "(leptonSelection&8)==8";            // ele id 
  TCut eliso 	= "(leptonSelection&16)==16";          // ele iso
  TCut probept  = "probe->pt()>30";                    // probe pt
  TCut drprobe  = "drprobe<0.05";                      // dR(probe,pfcandidate)

  TCut eltnpcut;
  eltnpcut += zmass;
  eltnpcut += os;
  eltnpcut += eltnp;
  eltnpcut += tag_eta25;
  //eltnpcut += njets2;
  eltnpcut += tag_pt30;
  eltnpcut += eltnptrig;
  eltnpcut += met30;
  // eltnpcut += mt30;
  eltnpcut += nbl0;
  
  eltnpcut += elid;
  eltnpcut += probept;
  eltnpcut += drprobe;

  TCut mutnpcut;
  mutnpcut += zmass;
  mutnpcut += os;
  mutnpcut += mutnp;
  mutnpcut += tag_eta21;
  //mutnpcut += njets2;
  mutnpcut += tag_pt30;
  mutnpcut += mutnptrig;
  mutnpcut += met30;
  // mutnpcut += mt30;
  mutnpcut += nbl0;

  mutnpcut += muid;
  mutnpcut += probept;
  mutnpcut += drprobe;


  //eltnpcut += njets2;
  //eltnpcut += njets3;
  //eltnpcut += nbm0;
  //eltnpcut += mt30;
  //eltnpcut += met20;

  //TCut eltnpcut 	 = "abs(tagAndProbeMass-91)<15 && (eventSelection&1)==1 && qProbe*qTag<0 && abs(tag->eta())<2.5 && njets>=4 && tag->pt()>30.0 && met<30.0 && nbm==0 && mt<30"; 
  //TCut mutnpcut 	 = "abs(tagAndProbeMass-91)<15 && (eventSelection&2)==2 && HLT_IsoMu30_eta2p1_tag>0 && qProbe*qTag<0 && abs(tag->eta())<2.1 && njets>=4 && tag->pt()>30.0"; 

  TCut vtxweight = "vtxweight";

  cout << "Electrons:" << endl;
  cout << "Total MC yields 	: " << chmc->GetEntries(eltnpcut) << endl;
  cout << "Total DATA yields 	: " << chdata->GetEntries(eltnpcut) << endl;

  cout << "Muons:" << endl;
  cout << "Total MC yields 	: " << chmc->GetEntries(mutnpcut) << endl;
  cout << "Total DATA yields 	: " << chdata->GetEntries(mutnpcut) << endl;


  //TCut njets    = "njets>=2";
  TCut tkisoold = "tkisoold/probe->pt()>0.1";
  TCut tkisonew = "tkisonew/probe->pt()>0.1";

  //-----------------------------------------
  // check nvtx data vs. MC
  //-----------------------------------------

  TH1F *hnvtx_mc   = new TH1F("hnvtx_mc"  ,"",30,0,30);
  TH1F *hnvtx_data = new TH1F("hnvtx_data","",30,0,30);

  hnvtx_mc->Sumw2();
  hnvtx_data->Sumw2();

  chdata->Draw("nvtx>>hnvtx_data",(eltnpcut||mutnpcut));
  chmc->Draw("nvtx>>hnvtx_mc",(eltnpcut||mutnpcut)*vtxweight);

  TCanvas *c1 = new TCanvas();
  c1->cd();
  
  hnvtx_mc->SetLineColor(2);
  hnvtx_mc->SetMarkerColor(2);
  hnvtx_data->SetLineColor(4);
  hnvtx_data->SetMarkerColor(4);
  
  hnvtx_data->GetXaxis()->SetTitle("N_{VTX}");
  hnvtx_data->DrawNormalized();
  hnvtx_mc->DrawNormalized("same");

  TLegend *leg = new TLegend(0.6,0.6,0.8,0.8);
  leg->AddEntry(hnvtx_data,"data","lp");
  leg->AddEntry(hnvtx_mc,"MC","lp");
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->Draw();

  if( printplot ) c1->Print("plots/nvtx.pdf");



  // Fill histograms
  //
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_deno", 	tnpcut+"&&"+eliso,				"goff");
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_num", 		tnpcut+"&&"+eliso+"&&"+elid,	"goff");
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_deno", 	tnpcut+"&&"+elid,				"goff");
  // chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_num", 	tnpcut+"&&"+elid+"&&"+eliso,	"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_deno", 	tnpcut+"&&"+eliso,				"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_num", 		tnpcut+"&&"+eliso+"&&"+elid,	"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_deno", 	tnpcut+"&&"+elid,				"goff");
  // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_num", 	tnpcut+"&&"+elid+"&&"+eliso,	"goff");

  */
	
}