Beispiel #1
0
double correlation_coef( string source1, string source2 ){

	TChain * c = new TChain( "rcpPicoDst" );

	c->Add( "/Users/danielbrandenburg/bnl/local/data/RcpAnalysis/data/RcpPicoDst/tuple_93477DF676758D2254762F71F52E3D44_14*.root" );

	TCanvas * c1 = new TCanvas( "c1", source1.c_str() );
	c->Draw( (source1 + " >> hSource1 ").c_str() );

	TCanvas * c2 = new TCanvas( "c2", source2.c_str() );
	c->Draw( (source2 + " >> hSource2 ").c_str() );

	TH1 * hSource1 = (TH1*)gDirectory->Get( "hSource1" );
	TH1 * hSource2 = (TH1*)gDirectory->Get( "hSource2" );

	double m1 = hSource1->GetMean();
	double m2 = hSource2->GetMean();

	double s1 = hSource1->GetRMS();
	double s2 = hSource2->GetRMS();

	TCanvas * c3 = new TCanvas( "c3", "correlation" );
	string expr = "( " + source1 + " - " + dts( m1 ) + " ) * ( " + source2 + " - " + dts( m2 ) + " ) / ( " + dts( s1 * s2 ) + " ) >> hCorr";
	c->Draw( expr.c_str() );

	TH1 * hCorr = (TH1*)gDirectory->Get( "hCorr" );


	return m1;

}
void paint(TString dir, TString a, TString b)
{
	TChain *t = new TChain(a);
	t->Add(dir + a + "_" + b +".root");

	std::cout << "painting the histograms for: " << dir + a + "_" + b +".root" << std::endl;

	TDirectory *direc = new TDirectory("dir", "dir");
	direc->cd();

	TH2D * histo = new TH2D("jets", "jets", 50, -2.5, 2.5, 40, 4.17438727, 6.95654544315);//pt starting from 15 and until 1000
	histo->SetDirectory(direc);

	t->Draw("log(jetPt+50):jetEta >> +jets", "", "Lego goff");

  TH2D * histo_lin = new TH2D("jets_lin", "jets_lin", 50, -2.5, 2.5, 40, 15, 1000);//pt starting from 15 and until 1000
	t->Draw("jetPt:jetEta >> +jets_lin", "", "Lego goff");

	std::cout << "saving the histograms: " << a + "_" + b +"_histo.root" << std::endl;
	TFile g(a + "_" + b +"_histo.root", "RECREATE");
	histo->SetDirectory(&g);
	histo_lin->SetDirectory(&g);
	delete direc;

	g.cd();
	histo->Write();
	histo_lin->Write();
	g.Close();

}
Beispiel #3
0
void resol() {
  TChain* trajTree = new TChain("trajTree");
  trajTree->Add("/data/jkarancs/CMSSW/TimingStudy/CMSSW_7_1_0_pre9/src/DPGAnalysis/PixelTimingStudy/Ntuple.root/trajTree");
  
  TH1D* dx_l1 = new TH1D("dx_l1", "PXB2 residuals #Deltax, p_{t} > 12, lever 1;PXB2 #Deltax [#mum];hits", 100, -150, 150); // h420_1
  TH1D* dx_l2 = new TH1D("dx_l2", "PXB1 residuals #Deltax, p_{t} > 12, lever 3;PXB1 #Deltax [#mum];hits", 100, -150, 150); // h520_3
  TH1D* dx_l3 = new TH1D("dx_l3", "PXB3 residuals #Deltax, p_{t} > 12, lever 3;PXB3 #Deltax [#mum];hits", 100, -150, 150); // i520_3
  
  TCanvas c("c");
  trajTree->Draw("res_dx>>dx_l1","layer==1&&pt>12&&lev>1.43&&lev<1.57");
  trajTree->Draw("res_dx>>dx_l2","layer==2&&pt>12&&lev>0&&lev<0.015","SAME");
  trajTree->Draw("res_dx>>dx_l3","layer==3&&pt>12&&lev>1.43&&lev<1.57","SAME");
  c.Close();
  
  double sigma_dx_l1 = fittp0(dx_l1);
  double sigma_dx_l2 = fittp0(dx_l2);
  double sigma_dx_l3 = fittp0(dx_l3);
  
  double res_dx_l1=sqrt((-sigma_dx_l1*sigma_dx_l1-10*sigma_dx_l2*sigma_dx_l2+5*sigma_dx_l3*sigma_dx_l3))/3;
  double res_dx_l2=sqrt((-sigma_dx_l1*sigma_dx_l1+14*sigma_dx_l2*sigma_dx_l2-sigma_dx_l3*sigma_dx_l3))/3;
  double res_dx_l3=sqrt((5*sigma_dx_l1*sigma_dx_l1-10*sigma_dx_l2*sigma_dx_l2-sigma_dx_l3*sigma_dx_l3))/3;
  
  std::cout<<"Resolution dx: Lay1 = "<<res_dx_l1<<" Lay2 = "<<res_dx_l2<<" Lay3 = "<<res_dx_l3<<std::endl;
  
  // Comparison with PixelTriplets:
  // PixelTimingStudy Resolution dx: Lay1 = 10.4437 Lay2 = 10.7449 Lay3 = 10.2808
  // PixelTriplets    Resolution dx: Lay1 = 10.5472 Lay2 = 10.7889 Lay3 = 10.4725
}
void drawThesis(){

  // TFile* f = TFile::Open("testing/comboStudies/generateAngularResolutionTreePlots_352_2016-03-02_11-57-40.root");
  // TFile* f = TFile::Open("testing/comboStudies/generateAngularResolutionTreePlots_352_2016-03-02_13-05-06.root");
  // TTree* t = (TTree*) f->Get("angResTree");

  TChain* t = new TChain("angResTree");
  t->Add("testing/comboStudies/generateAngularResolutionTreePlots_*");

  

  const int numBins = 64; //128;
  const double maxDeg = 2;
  TH1D* hTheta = new TH1D("hTheta", "#delta#theta Distribution of WAIS pulses; #delta#theta (Degrees); Events per bin", numBins, -maxDeg, maxDeg);

  TH1D* hPhi = new TH1D("hPhi", "#delta#phi Distribution of WAIS pulses; #delta#phi (Degrees); Events per bin", numBins, -maxDeg, maxDeg); 

  // t->Draw("deltaPhiDeg>>h2", "TMath::Abs(deltaPhiDeg) < 5", "colz");
  t->Draw("deltaThetaDeg3>>hTheta", "TMath::Abs(deltaPhiDeg3) < 5", "goff");
  t->Draw("deltaPhiDeg3>>hPhi", "TMath::Abs(deltaPhiDeg3) < 5", "goff");

  


  TH1D* hs[2] = {hTheta, hPhi};
  hPhi->SetLineColor(kRed);
  hTheta->SetLineColor(kBlue);  
  auto c1 = RootTools::drawHistsWithStatsBoxes(2, hs, "", "mre");

  TLegend* l1 = new TLegend(0.8, 0.8, 1, 1);
  l1->AddEntry(hPhi, "#delta#phi (Degrees)", "l");
  l1->AddEntry(hTheta, "#delta#phi (Degrees)", "l");
  hs[0]->SetTitle("Angular resolution of WAIS pulses");
}
Beispiel #5
0
void pixelHistos(const char *filenames = "/export/data1/dambach/hardware/ntpls/gradeC/*.root", const char *cuts =  "defects == 0")
{

  Init();      // do not forget to load the Utilities.C

  TH1D *gainH = new TH1D("gainH", "Gain", 1000, 0., 10.);
  TH1D *pedH = new TH1D("pedH", "Pedestal", 1000, -1000., 1000.);
  TH1D *noiseH = new TH1D("noiseH", "Noise", 1100, -100., 1000.);
  TH1D *tthrH = new TH1D("tthrH", "Trimmed Threshold", 100, 0., 100.);
  
  TChain *c = new TChain("mod");
  c->Add(filenames);
  
  canvas->Clear();
  canvas->Divide(2,2);

  canvas->cd(1);
  InitPad("log");
  gainH->GetXaxis()->SetTitle("ADC units/DAC units");
  gainH->GetYaxis()->SetTitle("# pixels");
  gainH->GetXaxis()->SetTitleSize(0.055);
  gainH->GetYaxis()->SetTitleSize(0.055);
  c->Draw("gain>>gainH", cuts);

  TBox *box = new TBox();

  canvas->cd(2);
  InitPad("log");
  pedH->GetXaxis()->SetTitle("DAC units");
  pedH->GetYaxis()->SetTitle("# pixels");
  pedH->GetXaxis()->SetTitleSize(0.055);
  pedH->GetYaxis()->SetTitleSize(0.055);
  c->Draw("ped>>pedH", cuts);

  canvas->cd(3);
  InitPad("log");
  noiseH->GetXaxis()->SetTitle("e^{-}");
  noiseH->GetYaxis()->SetTitle("# pixels");
  noiseH->GetYaxis()->SetRangeUser(0.1,400000);
  noiseH->GetXaxis()->SetTitleSize(0.055);
  noiseH->GetYaxis()->SetTitleSize(0.055);
  c->Draw("noise>>noiseH", cuts);
  noiseH->Fit("gaus");
//   box->SetFillStyle(3003);
//   box->SetFillColor(kBlue);
//   box->DrawBox(0.1,0.,500.,400000.);
//   box->SetFillColor(kRed);
//   box->DrawBox(500.,0.,1000.,400000.);

  canvas->cd(4);
  tthrH->GetXaxis()->SetTitle("DAC units");
  tthrH->GetYaxis()->SetTitle("# pixels");
  tthrH->GetXaxis()->SetTitleSize(0.055);
  tthrH->GetYaxis()->SetTitleSize(0.055);
  InitPad("log");
  c->Draw("tthr>>tthrH", cuts);

}
Beispiel #6
0
plot_BH2Raw()
{
  gROOT->Reset();
  TCanvas *c1 = new TCanvas("c1","c1",1600,900);
  TCanvas *c2 = new TCanvas("c2","c2",1600,900);

  int n = 7;
  TCanvas* c11[24];
  TCanvas* c22[24];

  c1->Divide(7,2);
  c2->Divide(7,2);

  char title1[255];
  char title2[255];

  TChain *chain = new TChain("tree");
  //chain->Add("test0.root");
  chain->Add("./root/lithium/old/run04520_Hodoscope.root");
  //chain->Add("./root/tdcshift/run04554_Hodoscope.root");

  //ADC
  for( int i=0; i<n; ++i){
    c11[i] = (TCanvas*) c1->GetPad(i+1);
    c1->cd(i+1);
    c11[i]->SetLogy();
    sprintf(title1,"bh2ua[%d]>>h10%d(500,0,2000)",i,i);
    //   sprintf(title2,"bh2ut[%d]>0",i);
    //     chain->Draw( title1, title2 );
    chain->Draw( title1 );
  }
  for( int i=0; i<n; ++i){
    c11[i+n] = (TCanvas*) c1->GetPad(i+1+n);
    c1->cd(i+1+n);
    c11[i+n]->SetLogy();
    sprintf(title1,"bh2da[%d]>>h20%d(500,0,1500)",i,i);
    //     sprintf(title2,"bh2dt[%d]>0",i);
    //     chain->Draw( title1, title2 );
    chain->Draw( title1 );
  }

  //TDC
  for( int i=0; i<n; ++i){
    c22[i] = (TCanvas*) c2->GetPad(i+1);
    c2->cd(i+1);
    c22[i]->SetLogy();
    sprintf(title1,"bh2ut[%d]>>h30%d(1000,500,1500)",i,i);
    chain->Draw( title1 );
  }
  for( int i=0; i<n; ++i){
    c22[i+n] = (TCanvas*) c2->GetPad(i+1+n);
    c2->cd(i+1+n);
    c22[i+n]->SetLogy();
    sprintf(title1,"bh2dt[%d]>>h40%d(1000,500,1500)",i,i);
    chain->Draw( title1 );
  }
}
Beispiel #7
0
void MakePlot(TString yvar = "mht30", int nbinsy = 100, double ylow=0., double yhigh=1000., TString xvar = "true_mu_ptW", int nbinsx = 100, double xlow=0., double xhigh=1000., TString axistitles="p_{T}^{W} [GeV];H_{T}^{miss} [GeV]", const TCut cuts="true_mu_pt>0&&num_true_mus==1&&num_true_els+num_true_had_taus==0", const TString treestring = "reduced_trees/13TeV/TTJets_MSDecaysCKM_central_Tune4C_13TeV-madgraph-tauola_Phys14DR-PU20bx25_PHYS14_25_V1-v1_MINIAODSIM_UCSB2406_v78/*.root", const TString plotNote="ttbar_1mu", bool logz = true, TString xvar_name="", TString yvar_name="") 
{
  set_plot_style();
  TH2D* h2 = new TH2D("h2",";"+axistitles,nbinsx,xlow,xhigh,nbinsy,ylow,yhigh);
  h2->SetStats(0);
  h2->GetZaxis()->SetLabelSize(0.02);
  h2->GetYaxis()->SetLabelSize(0.03);
  h2->GetYaxis()->SetTitleOffset(1.3);
  h2->GetXaxis()->SetLabelSize(0.03);
  TCut weighted_selection((cuts)*"(weightppb*10000.)");

  TChain * pypu = new TChain("reduced_tree");
  pypu->Add(treestring);// treestring is passed as an argument
  TCanvas * thecanvas= new TCanvas("thecanvas","the canvas",850,800);
  pypu->Draw(yvar+":"+xvar+">>h2",weighted_selection,"colz");

  h2->Scale(1/h2->Integral(1,nbinsx+1,1,nbinsy+1));

  thecanvas->SetLogz(logz);
  if (xvar_name.Length()>0) xvar=xvar_name;
  if (yvar_name.Length()>0) yvar=yvar_name;
  thecanvas->Print("macros/junews/lostleptons/conceptual_plots/"+yvar+"_vs_"+xvar+"_"+plotNote+"_scatter.pdf");
  
    
  delete h2;
  delete thecanvas;

}
Beispiel #8
0
void plotTowers_dj(
    TString inFile0Name="~/scratch01/ana/Hydj_BSC_HF_L1Emul/oh0928_v2/openhlt_hiReco_RAW2DIGI_RECO_*_djana.root",
    TString outdir = "out/Hydj/BSC_HF_L1Emul/devHLT381")
{
  TChain * djTree = new TChain("dijetAna_data_calojet_tower/djTree");
  djTree->Add(inFile0Name);
  aliases_dj(djTree);
  cout << " # entries: " << djTree->GetEntries() << endl;

  gSystem->mkdir(outdir.Data(),kTRUE);
  Int_t NTowerMax=70;


  pair<TString,TString> t = make_pair("name","cut");
  vector<pair<TString,TCut> > trigs;
  trigs.push_back(make_pair("All","1==1"));
  trigs.push_back(make_pair("HfAnyHit","hlt[2]"));
  trigs.push_back(make_pair("HfCoic1","hlt[3]"));
  trigs.push_back(make_pair("HfCoic2","hlt[4]"));

  for (unsigned int i=0; i<trigs.size(); ++i) {
    TCanvas * cHfNvsP = new TCanvas("HfNvsP_"+trigs[i].first,"HfNvsP_"+trigs[i].first,500,500);
    //cHfNvsP->SetLogx();
    //cHfNvsP->SetLogy();
    TH2D * hHfNvsP = new TH2D("hHfNvsP"+trigs[i].first,"hHfNvsP_",NTowerMax,0,NTowerMax,NTowerMax,0,NTowerMax);
    hHfNvsP->SetAxisRange(0.1,400,"X");
    hHfNvsP->SetAxisRange(0.1,400,"Y");
    djTree->Draw("NHfN:NHfP>>hHfNvsP"+trigs[i].first,trigs[i].second,"colz");
    hHfNvsP->SetTitle("HF Towers;# HF+ Towers (E>3GeV);# HF- Towers (E>3GeV)");
    cHfNvsP->Print(Form("%s/trHfNvsP_%s.gif",outdir.Data(),trigs[i].first.Data()));
  }
}
void paint(TString a, TString b)
{
	TChain *t = new TChain(a);
	t->Add(a + "_" + b +".root");

	std::cout << "painting the histograms for: " << a + "_" + b +".root" << std::endl;

	TDirectory *dir = new TDirectory("dir", "dir");
	dir->cd();

//	histo = new TH2D("jets", "jets", 50, -2.5, 2.5, 60, 10, 610);
//	histo = new TH2D("jets", "jets", 50, -2.5, 2.5, 40, 4.7004803657924166, 6.404803657924166);
//	TH2D * histo = new TH2D("jets", "jets", 25, -2.5, 2.5, 20, 4.0943445622221004, 6.1943445622221004); 
	TH2D * histo = new TH2D("jets", "jets", 50, -2.5, 2.5, 40, 4.0943445622221004, 6.1943445622221004);//original
//	TH2D * histo = new TH2D("jets", "jets", 50, -2.5, 2.5, 40, 4.0943445622221004, 7.8);
	histo->SetDirectory(dir);

	//the varexp part of the draw synatx means: draw log(jetPt+50) versus jetEta and append the existing ("+" -> avoid recreation) histogram called "jets"
	//selection is an expression with a combination of the Tree variables -> no selection applied in this case ""
	//option is the drawing option -> if option contains the string "goff", no graphics is generated.
	//fourth and fifth arguments are: Int_t nevents, Int_t firstevent
	t->Draw("log(jetPt+50):jetEta >> +jets", "", "Lego goff");
	//std::cout <<"jetPt " << log(jetPt+50) << " and jetEta " << jetEta << std::endl;


	std::cout << "saving the histograms: " << a + "_" + b +"_histo.root" << std::endl;
	TFile g(a + "_" + b +"_histo.root", "RECREATE");
	histo->SetDirectory(&g);
	delete dir;

	g.cd();
	histo->Write();
	g.Close();
}
Beispiel #10
0
void make_psi2s_mupt(float ptmin=0.0, float ptmax=30.0, float ymin=0.0, float ymax=2.4, bool absRapidity=true, bool saveFile=false)
{
  TCanvas *c1 = new TCanvas("c1","c1");
  c1->SetLogy();
  TCut defaultCut = "Reco_QQ_sign==0&&Reco_QQ_4mom.M()>3.35&&Reco_QQ_4mom.M()<4.0&&Reco_QQ_ctauTrue>-10";
  TCut ptCut = Form("Reco_QQ_4mom.Pt()>%4.1f&&Reco_QQ_4mom.Pt()<%4.1f",ptmin,ptmax);
  TCut rapCut;
  if (absRapidity)
    rapCut = Form("abs(Reco_QQ_4mom.Rapidity())>%3.1f&&abs(Reco_QQ_4mom.Rapidity())<%3.1f",ymin,ymax);
  else
    rapCut = Form("Reco_QQ_4mom.Rapidity()>%3.1f&&Reco_QQ_4mom.Rapidity()<%3.1f",ymin,ymax);

  unsigned int trigBit=2; // DoubleMu0_HighQ
  TCut trigCut = Form("(HLTriggers&%u)==%u&&(Reco_QQ_trig&%u)==%u",trigBit,trigBit,trigBit,trigBit);

  TString fname;
  fname = Form("20140324/MC_psi2s_pp_mupt_Rap_%3.1f-%3.1f_Pt_%3.1f-%3.1f.root",ymin,ymax,ptmin,ptmax);

  std::cout << fname << std::endl;


  std::cout << "default: " << defaultCut.GetTitle() << std::endl;
  std::cout << "pt cut: " << ptCut.GetTitle() << std::endl;
  std::cout << "rapidity cut: " << rapCut.GetTitle() << std::endl;
  std::cout << "trigger bit: " << trigCut.GetTitle() << std::endl;

  TH1F *hMuPlPtRec = new TH1F("hMuPlPtRec","hMuPlPtRec;p_{T} (#mu^{+}) (GeV/c);Events",200,0,20);
  TH1F *hMuMiPtRec = new TH1F("hMuMiPtRec","hMuMiPtRec;p_{T} (#mu^{-}) (GeV/c);Events",200,0,20);
  TH1F *hMuPtRec = new TH1F("hMuPtRec","hMuPtRec;p_{T} (#mu^{#pm}) (GeV/c);Events",200,0,20);
  hMuPlPtRec->Sumw2();
  hMuMiPtRec->Sumw2();
  hMuPtRec->Sumw2();

  hMuPlPtRec->SetMarkerColor(kRed);
  hMuMiPtRec->SetMarkerColor(kBlue);

  TChain *myTree = new TChain("myTree");
  myTree->Add("../root_files/PRpsi2SMC_Histos_2013pp_GlbGlb_STARTHI53_V28-v1_muLessPV.root");

  myTree->Draw("Reco_QQ_mupl_4mom.Pt()>>hMuPlPtRec",defaultCut&&ptCut&&rapCut&&trigCut,"e");
  myTree->Draw("Reco_QQ_mumi_4mom.Pt()>>hMuMiPtRec",defaultCut&&ptCut&&rapCut&&trigCut,"e");

  hMuPtRec->Add(hMuPlPtRec,hMuMiPtRec);

  hMuPtRec->Draw();
  hMuPlPtRec->Draw("same");
  hMuMiPtRec->Draw("same");

  TFile *outf = NULL;
  if (saveFile) {
    outf = new TFile(fname,"RECREATE");
    hMuPtRec->Write();
    outf->Close();
  }

  return;
}
Beispiel #11
0
void anaFragShape(TString infile="dj_HCPR-GoodTrkAndPixel_CleanEvt1130.root")
{
  TChain * djcalo = new TChain("djcalo/djTree");
  djcalo->Add(infile);
  aliases_dijet(djcalo);
  TChain * djcalopix = new TChain("djcalo_pxl/djTree");
  djcalopix->Add(infile);
  aliases_dijet(djcalopix);
  TString evtSel("(cent<10 && nljet>120 && abs(nljeta)<2 && aljet>50 && abs(aljeta)<2 && jdphi>2.5 && Aj>0.24)");
  TH1::SetDefaultSumw2();

  TCanvas * c0 = new TCanvas("c0","c0",500,500);
  djcalo->Draw("Aj>>hAj(20,0,1)",evtSel);
  djcalopix->Draw("Aj",evtSel,"Esame");

  TCanvas * c2 = new TCanvas("c2","c2",500,500);
  TH1D * hJDPhi = new TH1D("hJDPhi","hJDPhi",50,0,3.1416);
  TH1D * hJDPhi2 = new TH1D("hJDPhi2","hJDPhi",50,0,3.1416);
  Float_t numDJ = djcalo->Draw("jdphi>>hJDPhi",evtSel);
  Float_t numDJ2 = djcalopix->Draw("jdphi>>hJDPhi2",evtSel);
  cout << "num djs: " << numDJ << "  djs(pix)" << numDJ2 << endl;

  TH1D * hPNDRTrk = new TH1D("hPNDRTrk",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  TH1D * hPNDRPix = new TH1D("hPNDRPix",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  TH1D * hPADRTrk = new TH1D("hPADRTrk",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  TH1D * hPADRPix = new TH1D("hPADRPix",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk",Form("(%s&&ppt>=1.2)*(ppt/(TMath::TwoPi()*pndr))",evtSel.Data()));
  djcalopix->Draw("pndr>>hPNDRPix",Form("(%s&&ppt>=0.3&&ppt<1.2)*(ppt/(TMath::TwoPi()*pndr))",evtSel.Data()));
  djcalo->Draw("padr>>hPADRTrk",Form("(%s&&ppt>=1.2)*(ppt/(TMath::TwoPi()*padr))",evtSel.Data()));
  djcalopix->Draw("padr>>hPADRPix",Form("(%s&&ppt>=0.3&&ppt<1.2)*(ppt/(TMath::TwoPi()*padr))",evtSel.Data()));
  hPNDRTrk->Scale(1./(numDJ*hPNDRTrk->GetBinWidth(1)));
  hPNDRPix->Scale(1./(numDJ*hPNDRPix->GetBinWidth(1)));
  hPADRTrk->Scale(1./(numDJ*hPADRTrk->GetBinWidth(1)));
  hPADRPix->Scale(1./(numDJ*hPADRPix->GetBinWidth(1)));
  hPNDRPix->SetMinimum(50);
  hPNDRPix->SetMaximum(100);
  hPNDRTrk->SetMinimum(10);
  hPNDRTrk->SetMaximum(2000);
  hPNDRPix->SetMarkerStyle(kFullCircle);
  hPNDRTrk->SetMarkerStyle(kFullSquare);
  hPNDRPix->SetMarkerColor(kRed);
  hPNDRTrk->SetMarkerColor(kRed);
  hPADRPix->SetMarkerStyle(kOpenCircle);
  hPADRTrk->SetMarkerStyle(kOpenSquare);
  hPADRPix->SetMarkerColor(kBlue);
  hPADRTrk->SetMarkerColor(kBlue);
  TCanvas * c3 = new TCanvas("c3","c3",500,500);
  hPNDRPix->Draw("E");
  hPADRPix->Draw("Esame");
  TCanvas * c3_2 = new TCanvas("c3_2","c3_2",500,500);
  c3_2->SetLogy();
  hPNDRTrk->Draw("E");
  hPADRTrk->Draw("Esame");
}
void quickMakeHisto() {

  
  new TCanvas();
  TChain *nocontainerTree = new TChain("pcaTree");
  nocontainerTree->Add("/home/rjn/creamtea/data/nocontainer/pca_nocontainer_0_1000files.root");
  nocontainerTree->Add("/home/rjn/creamtea/data/nocontainer/pca_nocontainer_1000_2000files.root");
  nocontainerTree->Add("/home/rjn/creamtea/data/nocontainer/pca_nocontainer_3000_4000files.root");

  TFile *fpNocontainer = new TFile("nocontainer.root","RECREATE");
  TH3F *histNocontainer = new TH3F("histNoContainer","histNoContainer",100,-6000,+6000,100,-6000,+6000,100,-6000,+6000);
  
  nocontainerTree->Draw("xPosTrue:yPosTrue:zPosTrue>>histNoContainer","abs(zPosTrue)<3000 && abs(xPosTrue)<6000 && abs(yPosTrue)<6000 && thetaTrue>0.00","");
  histNocontainer->Write();


  new TCanvas();
  TChain *containerTree = new TChain("pcaTree");
  containerTree->Add("/home/rjn/creamtea/data/container13m/pca_container_1_1000files.root");
  containerTree->Add("/home/rjn/creamtea/data/container13m/pca_container_1001_2000files.root");
  containerTree->Add("/home/rjn/creamtea/data/container13m/pca_container_2001_3000files.root");

  TFile *fpcontainer = new TFile("container.root","RECREATE");
  TH3F *histcontainer = new TH3F("histContainer","histContainer",100,-6000,+6000,100,-6000,+6000,100,-6000,+6000);
  
  containerTree->Draw("xPosTrue:yPosTrue:zPosTrue>>histContainer","abs(zPosTrue)<3000 && abs(xPosTrue)<6000 && abs(yPosTrue)<6000 && thetaTrue>0.00","");
  histcontainer->Write();


  new TCanvas();
  TChain *targetTree = new TChain("pcaTree");
  targetTree->Add("/home/rjn/creamtea/data/target/pca_container_1_1000files.root");
  targetTree->Add("/home/rjn/creamtea/data/target/pca_container_1001_2000files.root");
  targetTree->Add("/home/rjn/creamtea/data/target/pca_container_2001_3000files.root");

  TFile *fptarget = new TFile("target.root","RECREATE");
  TH3F *histtarget = new TH3F("histTarget","histTarget",100,-6000,+6000,100,-6000,+6000,100,-6000,+6000);
  
  targetTree->Draw("xPosTrue:yPosTrue:zPosTrue>>histTarget","abs(zPosTrue)<3000 && abs(xPosTrue)<6000 && abs(yPosTrue)<6000 && thetaTrue>0.00","");
  histtarget->Write();



}
Beispiel #13
0
void Sums(const char* savename,unsigned batchmode=0){
  
  if (batchmode ==1){
    gROOT->SetBatch(kTRUE); //set batch mode to suppress canvas output
     }
  //TChain* V;
  // gROOT->ProcessLine(".x dual-seg-chainload.C");
  TChain *P = new TChain("Tab");
 
   for (int i=1;i<11;i++){
       stringstream ss;
       if (i <10){
  	ss<<"094rb_14-seg-0"<<i<<".root";
       }
       else if (i >= 10){
  	ss<<"094rb_14-seg-"<<i<<".root";
       }
       P->Add(ss.str().c_str());
   }
  

   cout<<"chain loaded"<<endl;
      
  TFile *f = new TFile(savename,"RECREATE");

  
  TH2D* NvG = new TH2D("NvG"," NaI (x) vs Ge (y) Paddbacks",8000.,0.,8000.,8000.,0.,8000.);
  TH2D* LvG = new TH2D("LvG"," LaBr3 (x) vs Ge (y) Paddbacks",8000.,0.,8000.,8000.,0.,8000.);
  TH2D* NvL = new TH2D("NvL"," NaI (x) vs LaBr3 (y) Paddbacks",8000.,0.,8000.,8000.,0.,8000.);

  cout<<"Hist + files made"<<endl;
    
  NvG->SetMinimum(1);
  LvG->SetMinimum(1);
  NvL->SetMinimum(1);
  cout<<"minimum set"<<endl;
  P->Draw("pab.GabE:pab.NabE>>NvG");
  cout<<"NvG done"<<endl; 
  P->Draw("pab.GabE:pab.LabE>>LvG");
  cout<<"LvG done"<<endl; 
  P->Draw("pab.LabE:pab.NabE>>NvL");
  
  f->Write();
}
Beispiel #14
0
void DrawdEdxResolExample(){
  /// Example analysis to make an space point resolution study

  TChain * chain  = AliXRDPROOFtoolkit::MakeChain("trackerSimul.list", "simulTrack",0,100); 
  chain->SetCacheSize(10000000000);

  //
  // 1.) Qmax/Qtot as function of the input ionization density
  //
  chain->Draw("tr.CookdEdxDmax(0,0.6,1,0,1,0)/tr.CookdEdxDtot(0,0.6,1,0,1,0):tr.fMNprim>>hisQtotMax(10,10,50)","","prof",10000);
  //
  // 2.) Non linearity due to the truncation Qtot_{60%}/Qtot 100% 
  //
  chain->Draw("tr.CookdEdxDtot(0,0.6,1,0,1,0)/tr.CookdEdxDtot(0,0.99,1,0,1,0):tr.fMNprim>>hisQtot60100(10,10,50)","","prof",10000);
  //
  // 3.) 
  //
  chain->Draw("tr.CookdEdxDtot(0,0.6,1,0,1,0)/tr.fMNprim:tr.fMNprim>>profQtot60(10,10,50)","","prof",10000);
  chain->Draw("tr.CookdEdxDtot(0,0.99,1,0,1,0)/tr.fMNprim:tr.fMNprim>>profQtot100(10,10,50)","","profsame",10000);

}
Beispiel #15
0
TChain * compJOO(
    TString infile="hltana_Exp_151058.root",
    TString header="HLT_HIJet90U"
    )
{
  TChain * dj = new TChain("hltanalysis/HltTree");

  dj->Add(infile);
  dj->AddFriend("onl = hltanalysisOnl/HltTree",infile);
  cout << "Trig Total: " << dj->GetEntries() << endl;

  TCut evtSel("HLT_HIJet90U && hiBin*2.5<100");

  TH1D * hJEtIc5pu = plotJEt(dj,evtSel,"recoJetCalPt[0]","hJEtIc5pu",0);
  TH1D * hJEtIc5puOnl = plotJEt(dj,evtSel,"onl.recoJetCalPt[0]","hJEtIc5puOnl",0);

  TCut matEvtSel(evtSel);
  bool doMat = true;
  if (doMat) matEvtSel = evtSel && "abs(onl.recoJetCalEta[0]-recoJetCalEta[0])<0.2";
  TH2D * hJEtOnlIc5pu = plotJEtCorr(dj,matEvtSel,"onl.recoJetCalPt[0]/recoJetCalPt[0]:recoJetCalPt[0]","hJEtOnlIc5pu",";leading E_{T}^{Ic5pu} [GeV];E_{T}^{Ic5pu Online}/E_{T}^{Ic5pu}");

  TCanvas * cJEt = new TCanvas("cJEt","cJEt",500,500);
  CPlot cpJEt("JEt","JEt","leading E_{T}^{Jet}","#");
  cpJEt.SetLogy();
  cpJEt.AddHist1D(hJEtIc5puOnl,"Online Reco","hist",kGreen+2,kOpenSquare);
  cpJEt.AddHist1D(hJEtIc5pu,"Offline Reco","E",kBlack,kFullCircle);
  cpJEt.SetLegend(0.62,0.78,0.94,0.9);
  cpJEt.SetLegendHeader(header);
  cpJEt.Draw(cJEt,false);

  TCanvas * cDEta = new TCanvas("cDEta","cDEta",500,500);
  cDEta->SetLogy();
  dj->Draw("onl.recoJetCalEta[0]-recoJetCalEta[0]>>hDEta",evtSel,"E");
  TCanvas * cDPhi = new TCanvas("cDPhi","cDPhi",500,500);
  cDPhi->SetLogy();
  dj->Draw("onl.recoJetCalPhi[0]-recoJetCalPhi[0]>>hDPhi",evtSel,"E");

  return dj;
}
void quickAbsorberPlot() 
{
  TChain *Absorbed = new TChain("Absorbed");
  //  Absorbed->Add("/unix/anita1/creamtea/strips_650/container_10cmtungsten/pca/pca_tungsten10cm_1_1000.root");
  //  Absorbed->Add("/unix/anita1/creamtea/strips_650/container_10cmtungsten/pca/pca_tungsten10cm_1001_2000.root");
  //  Absorbed->Add("/unix/anita1/creamtea/strips_650/container_10cmtungsten/pca/pca_tungsten10cm_2001_3000.root");
  
  char inputName[180];
  //Local file old name system
  //  for(int i=0;i<=1000;i+=1000) {
    //    sprintf(inputName,"/unix/anita1/creamtea/strips_650/fakecontainer/pca/pca_fakecontainer_%d_%d.root",i+1,i+1000);
    //    sprintf(inputName,"/unix/anita1/creamtea/strips_650/container/pca/pca_container_%d_%d.root",i+1,i+1000);
    //    sprintf(inputName,"/unix/anita1/creamtea/strips_650/container_10cmtungsten/pca/pca_tungsten10cm_%d_%d.root",i+1,i+1000);
    //    sprintf(inputName,"/unix/anita1/creamtea/strips_650/fakecontainer_10cmtargetat_1_3_1/pca/pca_fakecontainer_10cmtarget_%d_%d.root",i+1,i+1000);

  //  }
//Download from UCL
for(int tag=1;tag<=2;tag++) {
  //  sprintf(inputName,"http://www.hep.ucl.ac.uk/~rjn/creamtea/pcaFiles/fakecontainer_10cmtargetat_0p5_1_0p5_steelboxat_m0p5_3_m0p5/pca_fakecontainer_10cmtarget_steelbox_million_%d.root",tag);
  sprintf(inputName,"/home/rjn/creamtea/data/strips_650/fakecontainer_10cmtargetat_0p5_1_0p5_steelboxat_m0p5_3_m0p5/pca_fakecontainer_10cmtarget_steelbox_million_%d.root",tag);
    Absorbed->Add(inputName);
  }
 
 std::cout << Absorbed->GetEntries() << "\n";
  
  TCanvas *can = new TCanvas("can","can");
 //  can->Divide(2,2);
 //  can->cd(1);
  Absorbed->Draw("yGrad*0000+yCut:xGrad*0000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
 //  can->cd(2);
//   Absorbed->Draw("yGrad*1000+yCut:xGrad*1000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
//   can->cd(3);
//   Absorbed->Draw("yGrad*2000+yCut:xGrad*2000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
//   can->cd(4);
//   Absorbed->Draw("yGrad*3000+yCut:xGrad*3000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
  

//   TCanvas *can2 = new TCanvas("can2","can2");
//   can2->Divide(2,2);
//   can2->cd(1);
//   Absorbed->Draw("yGrad*0000+yCut:xGrad*0000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
//   can2->cd(2);
//   Absorbed->Draw("yGrad*-1000+yCut:xGrad*-1000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
//   can2->cd(3);
//   Absorbed->Draw("yGrad*-2000+yCut:xGrad*-2000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
//   can2->cd(4);
//   Absorbed->Draw("yGrad*-3000+yCut:xGrad*-3000+xCut","abs(xGrad*-7000+xCut)<5000 && abs(yGrad*-7000+yCut)<5000 && xyzFitQual<1","colz");
  


}
void AnalysisWithChain()
{

  TCanvas* c1 = new TCanvas("c1","");

  TChain* chain = GetChainFromRunList("runs_groups12.txt");
  chain->SetAlias("Valid_HODO_HORIZONTAL","Sum$(abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) > 0");
  chain->SetAlias("Valid_HODO_VERTICAL","Sum$(abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) > 0");

  chain->Draw("TOWER_CALIB_TILE_MAPPER[4].energy>>h1(100,0,400)","Valid_HODO_VERTICAL && Valid_HODO_HORIZONTAL","");

  c1->Print("groups12.png");

}
Beispiel #18
0
void allstrips()
{
   TChain* chain = new TChain("etree");
   chain->Add("Raw_Data_FZ320P_05_MSSD_250V_K237_Position_1.dat-events.root");
   chain->Add("Raw_Data_FZ320P_05_MSSD_250V_K237_Position_2.dat-events.root");
   chain->Add("Raw_Data_FZ320P_05_MSSD_2_250V_K237_Position_3.dat-events.root");
   chain->Add("Raw_Data_FZ320P_05_MSSD_2_250V_K237_Position_4.dat-events.root");

   new TCanvas;
   chain->Draw("raw:Iteration$","");
   // change FZ320P to FZ320N in the title
   htemp()->SetTitle("Raw Data FZ320N_05_MSSD_2 250V K237 all events;strip No.;ADC");
   //-- png("Raw_Data_FZ320P_05_MSSD_2_250V_K237-allstrips");
}
Beispiel #19
0
void cutEntries(std::string filename,
		std::string treename="skimLaurent/photonTree")
{

  // chain in all the ncu ntuples in the same directory
  TChain* pho = new TChain(treename.data());

  pho->Add(filename.data());
  ofstream fout;
  fout.open("event.dat", ios::out | ios::app);
  int ntotal = pho->Draw("run",basicCut);
  cout << "For " << filename.data() << endl; 
  cout << "All photons = " << ntotal << endl;
  fout << ntotal << " "; 
  
  int npass = 0; 
//   if(filename.find("qcd") == std::string::npos){
    npass= pho->Draw("run",basicCut && realCut); 
//   }
  cout << "Real photons = " << npass << endl;
  fout << npass << endl;
  fout.close();

}
Beispiel #20
0
void fastLatino(TString sample = "019_TTTo2L2Nu2B")
{
  gROOT->SetBatch();

  TH1::SetDefaultSumw2();

  TH1F* h_mva_loose = new TH1F("h_mva_loose", "", 50, -1, 1);

  TString path = "/pool/ciencias/LatinosSkims/ReducedTrees/R53X_S1_V09_S2_V10_S3_V17newJEC/MC_LooseLooseTypeI/";

  TChain* tree = new TChain("latino", "latino");

  tree->Add(path + "latino_" + sample + ".root");

  TCut muon1 = "pt1>10 && bdt1>100 && pass2012ICHEP1";
  TCut muon2 = "pt2>10 && bdt2>100 && pass2012ICHEP2";
  TCut muon3 = "pt3>10 && bdt3>100";
  TCut gen1  = "leptonGenpid1==13";
  TCut gen2  = "leptonGenpid2==13";
  TCut dr11  = "sqrt((eta1-leptonGeneta1)*(eta1-leptonGeneta1)+(phi1-leptonGenphi1)*(phi1-leptonGenphi1))<0.3";
  TCut dr12  = "sqrt((eta1-leptonGeneta2)*(eta1-leptonGeneta2)+(phi1-leptonGenphi2)*(phi1-leptonGenphi2))<0.3";
  TCut dr21  = "sqrt((eta2-leptonGeneta1)*(eta2-leptonGeneta1)+(phi2-leptonGenphi1)*(phi2-leptonGenphi1))<0.3";
  TCut dr22  = "sqrt((eta2-leptonGeneta2)*(eta2-leptonGeneta2)+(phi2-leptonGenphi2)*(phi2-leptonGenphi2))<0.3";

  TCut cut1 = muon1 && muon2 && muon3;
  TCut cut2 = gen1 && gen2;
  TCut cut3 = (dr11 && dr22) || (dr12 && dr21);

  TCut selection = cut1 && cut2 && cut3;

  TCanvas* c1 = new TCanvas(sample, sample);

  c1->cd();
  
  tree->Draw("isomva3>>h_mva_loose", selection);


  // Define output
  //----------------------------------------------------------------------------
  gSystem->mkdir("rootfiles", kTRUE);

  TFile* file = new TFile("rootfiles/" + sample + ".root", "recreate");

  h_mva_loose->Write();

  file->Close();
}
Beispiel #21
0
void fit(const string &input_file)
{
    TChain *chain = new TChain("SmearEnergy");
    chain->Add(input_file.c_str());
    TH1F *h = new TH1F("energy", "Energy", 500, 0, 70);
    chain->Draw("smearEnergy>>energy", "smearEnergy>0");
    TF1 *g1 = new TF1("g1", "gaus", 4, 12);
    TF1 *g2 = new TF1("g2", "gaus", 14, 32);
    TF1 *g3 = new TF1("g3", "gaus", 36, 54);
    g1->SetLineColor(2);
    g2->SetLineColor(3);
    g3->SetLineColor(4);
    h->Fit(g1, "R");
    cout << "Integral(4,12): " << g1->Integral(4, 12) << endl;
    h->Fit(g2, "R+");
    cout << "Integral(14,32): " << g2->Integral(14, 32) << endl;
    h->Fit(g3, "R+");
    cout << "Integral(36,54): " << g3->Integral(36, 54) << endl;
}
Beispiel #22
0
void sigHist(TChain & EventsVBF, TChain & EventsGF, string variable, string title, int nBins, float min, float max, float GF, float VBF ){

  TCanvas c("");
  TH1F *hVBF = new TH1F("hVBF","hVBF", nBins, min, max);
  TH1F *hGF = new TH1F("hGF","hGF", nBins, min, max);
  EventsVBF.Project("hVBF",variable.c_str() );
  EventsGF.Project("hGF",variable.c_str() );
  //hVBF->Draw();
  EventsVBF.Draw("h.mass()");
  TH1F * h = new TH1F(title.c_str(),title.c_str(), nBins, min,max);

  
  h->Add(hVBF,hGF,VBF,GF);

    h->SetLineColor(kBlue+1);
    h->SetFillColor(kAzure+7);

  //h->SetLineColor(kMagenta+3);
  //h->SetFillColor(kMagenta-3);

  //    h->SetLineColor(kTeal+3);
  //  h->SetFillColor(kTeal+2);

  //  h->SetLineColor(kOrange+7);
  //  h->SetFillColor(kYellow-9);

  h->SetMarkerStyle(0);
  h->SetTitle( ("H350, "+title).c_str() );
  h->SetXTitle("m_{H} (GeV/c^{2})");
  //h->hGF->GetXaxis()->SeXmin();
  //h->Scale(1/h->GetEntries());
  h->Draw("HIST");

  h->Write();
  //c.SaveAs( (title+".eps").c_str() );
  delete hVBF;
  delete hGF;
  delete h;

}
Beispiel #23
0
void Improve_PID2(Char_t* path, Char_t* filename, short aoq, short var=0,
		  Float_t A_Lin = 0, Float_t A_Squ = 0,
		  Float_t X_Lin = 0, Float_t X_Squ = 0,
		  Float_t Y_Lin = 0, Float_t Y_Squ = 0,
		  Float_t D_Lin = 0, Float_t D_Squ = 0,

		  Float_t A_Lin1 = 0, Float_t A_Squ1 = 0,
		  Float_t X_Lin1 = 0, Float_t X_Squ1 = 0,
		  Float_t Y_Lin1 = 0, Float_t Y_Squ1 = 0,
		  Float_t D_Lin1 = 0, Float_t D_Squ1 = 0,

		  Float_t B_Lin = 0, Float_t B_Squ = 0
){



  TChain* tree = new TChain("tree");
  std::cout<< Form("%s%s",path,filename) <<std::endl;
  tree->AddFile(Form("%s%s",path,filename));


  short beta_;
  vector<Char_t*> names;
  names = vector<Char_t*> (9);
  Float_t corr[2][9] = { {A_Lin, X_Lin, Y_Lin,D_Lin, A_Lin1, X_Lin1, Y_Lin1, D_Lin, B_Lin},
		      {A_Squ, X_Squ, Y_Squ,D_Squ, A_Squ1, X_Squ1, Y_Squ1, D_Squ, B_Squ} };
  Float_t plane_[2], delta_[2];


  if(aoq == 0){
    names[0]="FA[0]",  names[1]="FX[0]",  names[2]="FY[0]",  names[3]="delta[0]";//First detector
    names[4]="FA[1]",  names[5]="FX[1]",  names[6]="FY[1]",  names[7]="delta[1]";//Second detector
    names[8]="BETA[0]";                                                       //Beta before ([0]) or after ([1]) the target
    beta_ = 0;
    plane_[0] = 0;
    plane_[1] = 1;
    delta_[0] = 0;
    delta_[1] = 1;
  }else if(aoq == 2){
    names[0]="FA[4]",  names[1]="FX[4]",  names[2]="FY[4]",  names[3]="delta[2]";//First detector
    names[4]="FA[5]",  names[5]="FX[5]",  names[6]="FY[5]",  names[7]="delta[4]";//Second detector
    names[8]="BETA[1]";                                                       //Beta before ([0]) or afte
    beta_ = 0;
    plane_[0] = 4;
    plane_[1] = 5;
    delta_[0] = 2;
    delta_[1] = 4;
  }else if(aoq == 5){
    names[0]="FA[3]",  names[1]="FX[3]",  names[2]="FY[3]",  names[3]="delta[2]";//First detector
    names[4]="FA[5]",  names[5]="FX[5]",  names[6]="FY[5]",  names[7]="delta[4]";//Second detector
    names[8]="BETA[1]";                                                      //Beta before ([0]) or after
    beta_ = 0;
    plane_[0] = 3;
    plane_[1] = 5;
    delta_[0] = 2;
    delta_[1] = 4;
  }

  Char_t* LinCorr = "",* SquCorr = "",*cut = "";
  if(aoq != 0) cut = "ZET[0]>49.5 && ZET[0] < 50.5 && TMath::Abs(AOQ[0]-2.56)<0.01";
  for(short ii = 0; ii < 9; ii++){
    LinCorr = Form("%s+%f*%s"   ,LinCorr,corr[0][ii],names[ii]);
    SquCorr = Form("%s+%f*%s*%s",SquCorr,corr[1][ii],names[ii],names[ii]);
  }
  TH2F* h2_aoq;
  if(var == 8) h2_aoq = new TH2F("h2_aoq",Form("AOQ[%i] vs %s",aoq,names[var]),200, 0.5,0.6,200,2.54,2.58);
  else if(var == 3 || var == 7)h2_aoq = new TH2F("h2_aoq",Form("AOQ[%i] vs %s",aoq,names[var]),200,-2,2, 200,2.54,2.58);
  else  h2_aoq = new TH2F("h2_aoq",Form("AOQ[%i] vs %s",aoq, names[var]),200,-10,10,200,2.54,2.58);
  tree->Draw(Form("AOQ[%i]+%s+%s:%s>>h2_aoq",aoq,LinCorr,SquCorr,names[var]),cut,"colz");



  tree->Draw(Form("AOQ[2]+%s+%s:ZET[3]>>h50(100,45,55,200,2.5,2.7)",LinCorr,SquCorr),cut,"colz");

}
Beispiel #24
0
void draw_sim_bender(TString field_status, Double_t Ne, TString target, Double_t energy)
{
 
  //Delete all the objects stored in the current directory memory
  gDirectory->Delete("*");
  //  gStyle->SetCanvasPreferGL(1); this cuases the canvas to save as a blank canvas. So saveAs option is not working..
  gStyle->SetPalette(1); 
  gStyle->SetOptStat(0); 
  
  // pads parameters
  gStyle->SetPadColor(kWhite); 
  gStyle->SetPadBorderMode(0);
  gStyle->SetPadBorderSize(0);
  gStyle->SetPadGridX(kTRUE);
  gStyle->SetPadGridY(kTRUE);
  gStyle->SetPadTopMargin(0.12);
  gStyle->SetPadBottomMargin(0.12);
  gStyle->SetPadLeftMargin(0.08);  
  gStyle->SetPadRightMargin(0.18);  
  gStyle->SetTitleSize(0.05);

  gStyle->SetLabelSize(0.05,"y");

	   
  // Create a canvas 
  TCanvas * C = new TCanvas("canvas","",1300,950);
  C->Divide(2,3);
  C->SetFillColor(0);
             

  // Open and chain the root file
  Char_t filename[200]; 
  // sprintf(filename,"~/rootfiles/rootfiles/shms_sim_benchmarking/%s_%s.000_ntuple.root",target.Data(),field_status.Data());
  
  sprintf(filename,"~/rootfiles/rootfiles/%s/%s_%s_4gev.000_ntuple.root",target.Data(),target.Data(),field_status.Data());
  //filename = "~/rootfiles/rootfiles/lh2_20cm/lh2_20cm_negative_4gev.000_ntuple.root";
  TChain * chain = new TChain("HBCoil");
  TFile *f = new TFile(filename);
  if (f->IsZombie()) {
    std::cout << "Error opening root file chain "<< filename << std::endl;
    exit(1);
  }
  else{
    //    sprintf(filename,"~/rootfiles/rootfiles/%s/%s_%s.*_ntuple.root",target.Data(),target.Data(),field_status.Data());

    sprintf(filename,"~/rootfiles/rootfiles/lh2_20cm/%s_%s_4gev.*_ntuple.root",target.Data(),field_status.Data());
    //filename = "~/rootfiles/rootfiles/lh2_20cm/lh2_20cm_negative_4gev.*_ntuple.root";


    std::cout << "Opening root file "<< filename << std::endl;
    chain->Add(filename);
    if(chain == NULL){
      std::cout<< "Unable to find the ntuple HBCoil"<< std::endl; 
      exit(1);
    }
    else{
      std::cout<<"Obtaining data from ntuple : HBCoil"<<"\n";

      std::cout<<"Number of beam electrons used for the simulation - "<<Ne<<std::endl;

      //////////////////////////////////
      // Display simulation conditions
      //////////////////////////////////
      C->cd(1);
      TPaveText *text = new TPaveText(0.1,0.1,0.9,0.9,"NDC");
      text->AddText(Form("Beam Energy = %2.0f GeV",energy));
      text->AddText(Form("Target - %s",target.Data()));
      text->AddText("Raster size 2mm x 2mm");
      text->AddText(Form("Number of electrons in the beam  %2.0f",Ne));
      text->AddText(Form("%s field",field_status.Data()));
      text->Draw();
      gPad->Update();

      //////////////////////////////////
      // Draw kinetic energy of the particles in the bender
      //////////////////////////////////
      C->cd(2);
      gPad->SetLogy();
      // secondaries generated by the scattering in the target (parentID == 1)
      chain->Draw("kineticE_MeV>>h2","parentID==1","");
      TH1F* h22 = (TH1F*)(gDirectory->Get("h2"));
      h22->Draw("");
      h22->SetFillColor(kGreen+2);
      h22->GetXaxis()->SetTitle("kinetic Energy (MeV)");
      h22->GetXaxis()->SetNoExponent(1);
      h22->GetYaxis()->SetTitle("Number of tracking steps");
      h22->SetTitle("Kinetic Energy of the Particles in the Coil");
      // primaries scattered in the target (parentID == 0)
      chain->Draw("kineticE_MeV>>h1","parentID==0","same");
      TH1F* h11 = (TH1F*)(gDirectory->Get("h1")); 
      h11->SetFillColor(kMagenta+2);
      gPad->Update();
      gPad->SetRightMargin(0.08);

      leg = new TLegend(0.6,0.7,0.9,0.9);
      leg->AddEntry(h11,"Primaries","f");
      leg->AddEntry(h22,"Secondaries","f");
      leg->Draw();

      //////////////////////////////////
      // Draw the heat deposition profile along the far side
      ////////////////////////////////// 
      C->cd(3);
      TString convert = Form("eDep_MeV/%f",Ne);
      chain->Draw(Form("%s:local_z_cm>>far",convert.Data()),"local_x_cm>12","prof");
      TProfile* h1 = (TProfile*)(gDirectory->Get("far"));
      h1->Rebin(6);
      h1->SetTitle("Profile of the heat deposited along the far side of HBCoil");
      h1->GetYaxis()->SetTitle("W#muA^{-1}");
      h1->GetXaxis()->SetTitle("Z (cm)");
      h1->SetLineColor(kBlue);
      h1->SetMarkerSize(0.5);
      h1->SetMarkerStyle(21);
      h1->SetMarkerColor(kBlue);
      h1->SetLineWidth(1.5);
      h1->Draw("E1X0");
      gPad->SetRightMargin(0.08);
      gPad->SetTopMargin(0.15);
      gPad->Update();
      gPad->Modified();
      
      //////////////////////////////////
      // Draw total heat deposition profile on the near side
      //////////////////////////////////
      C->cd(4);
      chain->Draw(Form("%s:local_z_cm>>near",convert.Data()),"local_x_cm<-5","prof");
      TProfile* h2 = (TProfile*)(gDirectory->Get("near"));
      h2->Rebin(6);
      h2->SetTitle("Profile of the heat deposited along the beam side of HBCoil");
      h2->GetYaxis()->SetTitle("W#muA^{-1}");
      h2->GetXaxis()->SetTitle("Z (cm)");
      h2->GetYaxis()->SetDecimals(kTRUE);
      h2->SetLineColor(kBlue);
      h2->SetMarkerSize(0.5);
      h2->SetMarkerStyle(21);
      h2->SetMarkerColor(kBlue);
      h2->SetLineWidth(1.5);
      h2->Draw("E1X0");
      gPad->SetRightMargin(0.08);
      gPad->SetTopMargin(0.15);
      gPad->Update();
      gPad->Modified();


      //////////////////////////////////
      // Draw total heat deposition on the far side
      //////////////////////////////////
      std::cout<<"Get heat depoisition on the far side ..\n"; 
      C->cd(5);
      //chain->Draw(Form("%s:local_z_cm>>left",convert.Data()),"local_x_cm>0","colz");
      chain->Draw("local_y_cm:local_z_cm>>left",Form("%s*(local_x_cm>12)",convert.Data()),"colz");

      TH2F* h3 = (TH2F*)(gDirectory->Get("left"));
      h3->SetStats(0);
      h3->SetTitle("Heat deposited along the far side of HBCoil");
      h3->GetYaxis()->SetTitle("Y (cm) ");
      h3->GetXaxis()->SetTitle("Z (cm)");
      gPad->Update();
      TPaletteAxis *palette1 = (TPaletteAxis*)h3->GetListOfFunctions()->FindObject("palette");
      palette1->GetAxis()->SetTitle("W#muA^{-1}");
      palette1->GetAxis()->SetTitleOffset(1.0);
      palette1->GetAxis()->SetTitleSize(0.05);
      palette1->GetAxis()->SetLabelSize(0.05);
      palette1->GetAxis()->SetDecimals(kTRUE);
      palette1->GetAxis()->SetMaxDigits(3);
      gPad->Modified();

      //////////////////////////////////
      // Draw total heat deposition on the near side
      //////////////////////////////////
      std::cout<<"Get heat depoisition on near side ..\n"; 
      C->cd(6);
      //      chain->Draw(Form("%s:local_z_cm>>right",convert.Data()),"local_x_cm<=0","colz");
      chain->Draw("local_y_cm:local_z_cm>>right",Form("%s*(local_x_cm<-5)",convert.Data()),"colz");

      TH2F* h4 = (TH2F*)(gDirectory->Get("right"));
      h4->SetStats(0);
      h4->SetTitle("Heat deposited along the beam side of HBCoil");
      h4->GetYaxis()->SetTitle("Y (cm) ");
      h4->GetXaxis()->SetTitle("Z (cm)");
      gPad->Update();
      TPaletteAxis *palette2 = (TPaletteAxis*)h4->GetListOfFunctions()->FindObject("palette");
      palette2->GetAxis()->SetTitle("W#muA^{-1}");
      palette2->GetAxis()->SetTitleOffset(1.0);
      palette2->GetAxis()->SetTitleSize(0.05);
      palette2->GetAxis()->SetLabelSize(0.05);
      palette2->GetAxis()->SetDecimals(kTRUE);
      palette2->GetAxis()->SetMaxDigits(2);
      gPad->Modified();  
    }

    C->Modified();
    C->Update();
    C->SaveAs(Form("bender_field_%s_%s_%2.0fgev_sim_plots.png",field_status.Data(),target.Data(),energy));
    //    C->SaveAs(Form("bender_field_%s_%s_%2.0fgev_sim_plots.C",field_status.Data(),target.Data(),energy));

    std::cout<<"Done!"<<std::endl;
  }
}
void melaDistributions_2D(int index=0,int altModelColor=4){

  gROOT->ProcessLine(".L  ~/tdrstyle.C");
  setTDRStyle();

  TChain* SMHiggs = new TChain("angles");
  TChain* altModel = new TChain("angles");

  TChain* qqZZ = new TChain("angles");

  SMHiggs->Add("/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/SMHiggs_store/SMHiggs_125GeV_wResolution_withDiscriminants.root");
  
  string fileName[7]={
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/psScalar_store/psScalar_125GeV_wResolution_withDiscriminants.root",
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/minGrav_store/minGrav_125GeV_wResolution_withDiscriminants.root",
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/vector_store/vector_125GeV_wResolution_withDiscriminants.root",
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/psVector_store/psVector_125GeV_wResolution_withDiscriminants.root",
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/2hPlus_store/2hPlus_125GeV_wResolution_withDiscriminants.root",
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/2hMinus_store/2hMinus_125GeV_wResolution_withDiscriminants.root",
    "/scratch0/hep/whitbeck/OLDHOME/4lHelicity/generatorJHU_V02-01-00/0hPlus_store/0hPlus_125GeV_wResolution_withDiscriminants.root"
  };

  string discrimName[7]={"pseudomelaLD","gravimelaLD","vectormelaLD","psVectormelaLD","2hPlusmelaLD","2hMinusmelaLD","0hPlusmelaLD"};

  string axisTitle[7]={"D_{0^{-}}","D_{2_{m}^{+}}","D_{1^{+}}","D_{1^{-}}","D_{2_{h}^{+}}","D_{2_{h}^{-}}","D_{0_{h}^{+}}"};

  altModel->Add( fileName[index].c_str() );

  qqZZ->Add("/scratch0/hep/whitbeck/4lHelicity/datafiles/7TeV/training/pwgevents_*_wResolution_withDiscriminants.root");

  char drawString[100];

  gStyle->SetPadRightMargin(0.12);

  TCanvas* qqZZcan = new TCanvas("qqZZcan","qqZZcan",600,600);
  TCanvas* SMHcan = new TCanvas("SMHcan","SMHcan",600,600);
  TCanvas* altModelcan = new TCanvas("altModelcan","altModelcan",600,600);

  char* binning;
  char* cutString;
  binning ="(30,110,140,20,0,1)";
  cutString="zzmass>110&&zzmass<140";
  
  sprintf(drawString,"%s:zzmass>>qqZZhisto%s",discrimName[index].c_str(),binning);
  qqZZ->Draw(drawString,cutString);

  sprintf(drawString,"%s:zzmass>>SMHhisto%s",discrimName[index].c_str(),binning);
  SMHiggs->Draw(drawString,cutString);

  sprintf(drawString,"%s:zzmass>>altModelhisto%s",discrimName[index].c_str(),binning);
  altModel->Draw(drawString,cutString);

  TH1F* qqZZhisto = (TH1F*) gDirectory->Get("qqZZhisto");
  qqZZhisto->Scale(1./qqZZhisto->GetMaximum());
  qqZZhisto->GetYaxis()->SetTitle( axisTitle[index].c_str() );
  qqZZhisto->GetXaxis()->SetTitle( "m_{4l}" );
  qqZZhisto->GetYaxis()->CenterTitle();
  qqZZhisto->GetXaxis()->SetNdivisions(-505);
  qqZZhisto->GetYaxis()->SetNdivisions(-505);
  qqZZhisto->GetZaxis()->SetNdivisions(-505);
  qqZZhisto->GetXaxis()->CenterTitle();
  
  TGaxis::SetMaxDigits(3);

  TH1F* SMHhisto = (TH1F*) gDirectory->Get("SMHhisto");
  SMHhisto->Scale(1./SMHhisto->GetMaximum());
  SMHhisto->GetYaxis()->SetTitle( axisTitle[index].c_str() );
  SMHhisto->GetXaxis()->SetTitle( "m_{4l}" );
  SMHhisto->GetYaxis()->CenterTitle();
  SMHhisto->GetXaxis()->SetNdivisions(-505);
  SMHhisto->GetYaxis()->SetNdivisions(-505);
  SMHhisto->GetZaxis()->SetNdivisions(-505);
  SMHhisto->GetXaxis()->CenterTitle();


  TH1F* altModelhisto = (TH1F*) gDirectory->Get("altModelhisto");
  altModelhisto->Scale(1./altModelhisto->GetMaximum());
  altModelhisto->GetYaxis()->SetTitle( axisTitle[index].c_str() );
  altModelhisto->GetXaxis()->SetTitle( "m_{4l}" );
  altModelhisto->GetYaxis()->CenterTitle();
  altModelhisto->GetXaxis()->SetNdivisions(-505);
  altModelhisto->GetYaxis()->SetNdivisions(-505);
  altModelhisto->GetZaxis()->SetNdivisions(-505);
  altModelhisto->GetXaxis()->CenterTitle();

  qqZZcan->cd();
  qqZZhisto->Draw("COLZ");

  SMHcan->cd();
  SMHhisto->Draw("COLZ");

  altModelcan->cd();
  altModelhisto->Draw("COLZ");

  char saveName[100];

  sprintf(saveName,"epsfiles/kinematics_2D_%s_qqZZ.eps",discrimName[index].c_str() );
  qqZZcan->SaveAs(saveName);
  sprintf(saveName,"pngfiles/kinematics_2D_%s_qqZZ.png",discrimName[index].c_str() );
  qqZZcan->SaveAs(saveName);

  sprintf(saveName,"epsfiles/kinematics_2D_%s_SMH.eps",discrimName[index].c_str() );
  SMHcan->SaveAs(saveName);
  sprintf(saveName,"pngfiles/kinematics_2D_%s_SMH.png",discrimName[index].c_str() );
  SMHcan->SaveAs(saveName);

  sprintf(saveName,"epsfiles/kinematics_2D_%s_altModel.eps",discrimName[index].c_str() );
  altModelcan->SaveAs(saveName);
  sprintf(saveName,"pngfiles/kinematics_2D_%s_altModel.png",discrimName[index].c_str() );
  altModelcan->SaveAs(saveName);

}
void calculateTriggerRates(
			   TString inFile0Name = "root://eoscms//eos/cms/store/caf/user/velicanu/PA2013_merged_HiForest/pPb_hiForest2_pilotRun_200kHz_v3.root",
//         TString inFile0Name = "/castor/cern.ch/user/m/miheejo/openHLT/cms442/r181530_reco_v1_2/HIExpressPhysics_hiexp-hirun2011-r181530-reco-v1_2.root",
//         "/castor/cern.ch/user/k/kimy/openHLT//openhlt_run181531.root",
//         "/castor/cern.ch/user/v/velicanu/HIHLT_Validation_Test_GRIF_v10.root",
			   Int_t runNum        = 202792,
			   TString outdir      = "output",
			   char *projectTitle  = "HIpARun2013",
			   string source       = "data"
			   )
{
  char szBuf[256];
  int scale = 23;


  // event selectoin
  //Form("&&Run==%d&&LumiBlock>%d",runNum,goodLumiStart)
  // trigger under investigation
 //  const int ntrigs = 8;
//   const char* triggerPath[ntrigs] = {"","HLT_HIMinBiasHfOrBSC",
// 				     "L1_SingleMu3_BptxAND","HLT_HIL1SingleMu3","HLT_HIL2Mu3",
// 				     "L1_DoubleMuOpen_BptxAND","HLT_HIL1DoubleMuOpen","HLT_HIL2DoubleMu3"};

  /* const int ntrigs = 9;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAL1SingleMuOpen_v1",
    "HLT_PAL1SingleMu3_v1",
    "HLT_PAL1SingleMu7_v1",
    "HLT_PAL1SingleMu12_v1",
    "HLT_PAL1DoubleMu0_v1",
    "HLT_PADimuon0_NoVertexing_v1",
    "HLT_PAMu5_v1",
    "HLT_PAMu8_v1"
    }; */
  //trigger list for singleMu rate plot
  const int ntrigs = 4 ;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAMu3_v1",
    "HLT_PAMu7_v1",
    "HLT_PAMu12_v1"
  };
  /*
  //trigger list for DoubleMu rate plot
  const int ntrigs = 4 ;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAL1DoubleMuOpen_v1",
    "HLT_PAL1DoubleMu0_HighQ_v1",
    "HLT_PAL2DoubleMu3_v1"
  };
  
  //trigger list fo bJet+Mu rate plot
  const int ntrigs =5;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAMu3PFJet20_v1",
    "HLT_PAMu3PFJet40_v1",
    "HLT_PAMu7PFJet20_v1",
    "HLT_PABTagMu_Jet20_Mu4_v1"    
    };*/
  
  TString str;
  TH1D *ahTemp[ntrigs];
  double ahTempRate[ntrigs];  //Rates (Integrated over lumisections)
  // Load input
  TChain * HltTree = new TChain("hltanalysis/HltTree","HI OpenHLT Tree");
  HltTree->Add(inFile0Name);
  cout << inFile0Name << endl;
  cout << " # entries: " << HltTree->GetEntries() << endl;
  int nEvents = HltTree->GetEntries();
  for(int it=1; it<ntrigs; it++)
  {
    
    TH1D *ph  = new TH1D("ph",";Lumi Section; Counts ",1100,0,1100);
    HltTree->Draw("LumiBlock>>ph",str.Format("%s",triggerPath[it]));
    TLegend *lTemp= new TLegend(0.2,0.8,0.8,0.9);
    lTemp->SetHeader(str.Format("Run : %d",runNum));
    lTemp->SetMargin(0.05);
    lTemp->SetFillStyle(0);
    lTemp->SetLineColor(0);
    lTemp->SetLineWidth(5.0);
    lTemp->SetTextSize(0.03); 
    lTemp->AddEntry(ph,str.Format("%s",triggerPath[it],"l")); 
    lTemp->Draw("same");
    c1->SaveAs(str.Format("%d_%s.pdf",runNum,triggerPath[it]));
    TH1D *phLumi = (TH1D*)gDirectory->Get("ph");
    phLumi->SetDirectory(0);
    phLumi->Scale(1./(phLumi->GetBinWidth(1)*23));// 1lumi unit=23 sec
    ahTempRate[it] = phLumi->Integral()/phLumi->GetNbinsX();
    ahTemp[it] = phLumi;

    cout<< triggerPath[it]<<"\t"<<phLumi->GetEntries()<< "\t" << ahTempRate[it] << endl;
   
  }
     
  //----------------------------
  // drawing part
  // axis
  //  TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;dEvt/dLumiSec",1100,0,1100);
  TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;Rate [Hz]",1,0,1200);
  phLumiAxis->SetMinimum(0.01);
  phLumiAxis->SetMaximum(1e+3);
  gStyle->SetOptStat(kFALSE);

  // legend
  TLegend *l0= new TLegend(0.2,0.7,0.8,0.9);
  l0->SetHeader(str.Format("Run : %d",runNum));
  l0->SetMargin(0.03);
  l0->SetFillStyle(0);
  l0->SetLineColor(0);
  l0->SetLineWidth(1.0);
  l0->SetTextSize(0.03); 
  
  // canvas
  TCanvas *pcLumi = new TCanvas("pcLumi","pcLumi");
  pcLumi->cd();
  phLumiAxis->Draw();
  pcLumi->SetLogy();
 
  for(int it=1; it<ntrigs; it++)
    {
      TH1 *phLocal = (TH1 *)(ahTemp[it]->Clone("phLocal"));
      phLocal->SetDirectory(0); 
      phLocal->SetLineColor(it);
      if (it >= 10) phLocal->SetLineColor(it+20);
      if(it==5)	phLocal->SetLineColor(kOrange+2);
      phLocal->Draw("same");
      l0->AddEntry(phLocal,str.Format("%s: %.2f Hz",triggerPath[it],ahTempRate[it]),"l");
      pcLumi->Update();
     
    }
  l0->Draw("same");
  pcLumi->SaveAs(str.Format("%d_ratedMu.png",runNum));
}
void anaFragShapePtBinsDR(TString infile1="/net/hisrv0001/home/frankma/scratch01/ana/merge/dj_HCPR-J50U-JSON_hiGoodMergedTrksRuns152562to152643-v1_StdAna1204v2.root",
		  TString infile2="/net/hisrv0001/home/frankma/scratch01/ana/merge/dj_HCPR-GoodTrk1123_All0.root"
)
{
  gStyle->SetMarkerStyle(20);

  TChain * djcalo = new TChain("djcalo/djTree");
  djcalo->Add(infile1);
  djcalo->Add(infile2);
  aliases_dijet(djcalo);
  TString evtSel("(cent<10 && nljet>120 && abs(nljeta)<2 && aljet>50 && abs(aljeta)<2 && jdphi>2.5 && Aj>0.24)");
  TH1::SetDefaultSumw2();

  //cones reflected in eta. avoid jets *right* at mid-rapidity to avoid overlap
  djcalo->SetAlias("pndrrefl","(sqrt(pndphi*pndphi+(peta+nljeta)*(peta+nljeta)))");
  djcalo->SetAlias("padrrefl","(sqrt(padphi*padphi+(peta+aljeta)*(peta+aljeta)))");
  
  TString evtSelNS = evtSel + " && (abs(nljeta)>0.5)";
  TString evtSelAS = evtSel + " && (abs(aljeta)>0.5)";

  //jet energy imbalance
  TCanvas * c0 = new TCanvas("c0","c0",500,500);
  djcalo->Draw("Aj>>hAj(20,0,1)",evtSel);

  //back-to-back correlation
  TCanvas * c2 = new TCanvas("c2","c2",500,500);
  TH1D * hJDPhi = new TH1D("hJDPhi","hJDPhi",50,0,3.1416);
  TH1D * hJDPhi2 = new TH1D("hJDPhi2","hJDPhi",50,0,3.1416);
  Float_t numDJNS = djcalo->Draw("jdphi>>hJDPhi",evtSelNS);
  Float_t numDJAS = djcalo->Draw("jdphi>>hJDPhi",evtSelAS,"same");
  cout << "num djs: " << numDJNS << " (near-side) \t" << numDJAS << " (away-side)" << endl;

  //track energy density by dR in pt bins
  TString histtitle = ";R(trk,jet);1/N_{DJ} dp_{T}^{Trk}/dR";
  TH1D * hPNDRTrk0 = new TH1D("hPNDRTrk0",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRTrk0 = new TH1D("hPADRTrk0",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk0",Form("(%s&&ppt<1.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padr>>hPADRTrk0",Form("(%s&&ppt<1.0)*ppt",evtSelAS.Data()),"goff");
  TH1D * hPNDRReflTrk0 = new TH1D("hPNDRReflTrk0",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRReflTrk0 = new TH1D("hPADRReflTrk0",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndrrefl>>hPNDRReflTrk0",Form("(%s&&ppt<1.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padrrefl>>hPADRReflTrk0",Form("(%s&&ppt<1.0)*ppt",evtSelAS.Data()),"goff");

  TH1D * hPNDRTrk1 = new TH1D("hPNDRTrk1",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRTrk1 = new TH1D("hPADRTrk1",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk1",Form("(%s&&ppt<2.0&&ppt>=1.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padr>>hPADRTrk1",Form("(%s&&ppt<2.0&&ppt>=1.0)*ppt",evtSelAS.Data()),"goff");
  TH1D * hPNDRReflTrk1 = new TH1D("hPNDRReflTrk1",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRReflTrk1 = new TH1D("hPADRReflTrk1",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndrrefl>>hPNDRReflTrk1",Form("(%s&&ppt<2.0&&ppt>=1.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padrrefl>>hPADRReflTrk1",Form("(%s&&ppt<2.0&&ppt>=1.0)*ppt",evtSelAS.Data()),"goff");

  TH1D * hPNDRTrk2 = new TH1D("hPNDRTrk2",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRTrk2 = new TH1D("hPADRTrk2",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk2",Form("(%s&&ppt<4.0&&ppt>=2.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padr>>hPADRTrk2",Form("(%s&&ppt<4.0&&ppt>=2.0)*ppt",evtSelAS.Data()),"goff");
  TH1D * hPNDRReflTrk2 = new TH1D("hPNDRReflTrk2",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRReflTrk2 = new TH1D("hPADRReflTrk2",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndrrefl>>hPNDRReflTrk2",Form("(%s&&ppt<4.0&&ppt>=2.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padrrefl>>hPADRReflTrk2",Form("(%s&&ppt<4.0&&ppt>=2.0)*ppt",evtSelAS.Data()),"goff");

  TH1D * hPNDRTrk4 = new TH1D("hPNDRTrk4",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRTrk4 = new TH1D("hPADRTrk4",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk4",Form("(%s&&ppt<8.0&&ppt>=4.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padr>>hPADRTrk4",Form("(%s&&ppt<8.0&&ppt>=4.0)*ppt",evtSelAS.Data()),"goff");
  TH1D * hPNDRReflTrk4 = new TH1D("hPNDRReflTrk4",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRReflTrk4 = new TH1D("hPADRReflTrk4",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndrrefl>>hPNDRReflTrk4",Form("(%s&&ppt<8.0&&ppt>=4.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padrrefl>>hPADRReflTrk4",Form("(%s&&ppt<8.0&&ppt>=4.0)*ppt",evtSelAS.Data()),"goff");

  TH1D * hPNDRTrk8 = new TH1D("hPNDRTrk8",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRTrk8 = new TH1D("hPADRTrk8",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk8",Form("(%s&&ppt>=8.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padr>>hPADRTrk8",Form("(%s&&ppt>=8.0)*ppt",evtSelAS.Data()),"goff");
  TH1D * hPNDRReflTrk8 = new TH1D("hPNDRReflTrk8",histtitle.Data(),10,0,TMath::PiOver2());
  TH1D * hPADRReflTrk8 = new TH1D("hPADRReflTrk8",histtitle.Data(),10,0,TMath::PiOver2());
  djcalo->Draw("pndrrefl>>hPNDRReflTrk8",Form("(%s&&ppt>=8.0)*ppt",evtSelNS.Data()),"goff");
  djcalo->Draw("padrrefl>>hPADRReflTrk8",Form("(%s&&ppt>=8.0)*ppt",evtSelAS.Data()),"goff");

  hPNDRTrk0->Scale(1./(numDJNS*hPNDRTrk0->GetBinWidth(1)));
  hPADRTrk0->Scale(1./(numDJAS*hPADRTrk0->GetBinWidth(1)));
  hPNDRReflTrk0->Scale(1./(numDJNS*hPNDRReflTrk0->GetBinWidth(1)));
  hPADRReflTrk0->Scale(1./(numDJAS*hPADRReflTrk0->GetBinWidth(1)));

  hPNDRTrk1->Scale(1./(numDJNS*hPNDRTrk1->GetBinWidth(1)));
  hPADRTrk1->Scale(1./(numDJAS*hPADRTrk1->GetBinWidth(1)));
  hPNDRReflTrk1->Scale(1./(numDJNS*hPNDRReflTrk1->GetBinWidth(1)));
  hPADRReflTrk1->Scale(1./(numDJAS*hPADRReflTrk1->GetBinWidth(1)));

  hPNDRTrk2->Scale(1./(numDJNS*hPNDRTrk2->GetBinWidth(1)));
  hPADRTrk2->Scale(1./(numDJAS*hPADRTrk2->GetBinWidth(1)));
  hPNDRReflTrk2->Scale(1./(numDJNS*hPNDRReflTrk2->GetBinWidth(1)));
  hPADRReflTrk2->Scale(1./(numDJAS*hPADRReflTrk2->GetBinWidth(1)));

  hPNDRTrk4->Scale(1./(numDJNS*hPNDRTrk4->GetBinWidth(1)));
  hPADRTrk4->Scale(1./(numDJAS*hPADRTrk4->GetBinWidth(1)));
  hPNDRReflTrk4->Scale(1./(numDJNS*hPNDRReflTrk4->GetBinWidth(1)));
  hPADRReflTrk4->Scale(1./(numDJAS*hPADRReflTrk4->GetBinWidth(1)));

  hPNDRTrk8->Scale(1./(numDJNS*hPNDRTrk8->GetBinWidth(1)));
  hPADRTrk8->Scale(1./(numDJAS*hPADRTrk8->GetBinWidth(1)));
  hPNDRReflTrk8->Scale(1./(numDJNS*hPNDRReflTrk8->GetBinWidth(1)));
  hPADRReflTrk8->Scale(1./(numDJAS*hPADRReflTrk8->GetBinWidth(1)));

  hPNDRTrk0->SetMinimum(0.1);
  hPNDRTrk0->SetMaximum(1.3*hPNDRTrk0->GetBinContent(1));
  hPNDRTrk0->SetMarkerStyle(kFullSquare);
  hPNDRTrk0->SetMarkerColor(kRed);
  hPADRTrk0->SetMarkerStyle(kOpenSquare);
  hPADRTrk0->SetMarkerColor(kBlue);
  hPNDRReflTrk0->SetLineColor(kRed);
  hPADRReflTrk0->SetLineColor(kBlue);

  hPNDRTrk1->SetMinimum(0.1);
  hPNDRTrk1->SetMaximum(1.3*hPNDRTrk1->GetBinContent(1));
  hPNDRTrk1->SetMarkerStyle(kFullSquare);
  hPNDRTrk1->SetMarkerColor(kRed);
  hPADRTrk1->SetMarkerStyle(kOpenSquare);
  hPADRTrk1->SetMarkerColor(kBlue);
  hPNDRReflTrk1->SetLineColor(kRed);
  hPADRReflTrk1->SetLineColor(kBlue);

  hPNDRTrk2->SetMinimum(0.1);
  hPNDRTrk2->SetMaximum(1.3*hPNDRTrk2->GetBinContent(1));
  hPNDRTrk2->SetMarkerStyle(kFullSquare);
  hPNDRTrk2->SetMarkerColor(kRed);
  hPADRTrk2->SetMarkerStyle(kOpenSquare);
  hPADRTrk2->SetMarkerColor(kBlue);
  hPNDRReflTrk2->SetLineColor(kRed);
  hPADRReflTrk2->SetLineColor(kBlue);

  hPNDRTrk4->SetMinimum(0.1);
  hPNDRTrk4->SetMaximum(1.3*hPNDRTrk4->GetBinContent(1));
  hPNDRTrk4->SetMarkerStyle(kFullSquare);
  hPNDRTrk4->SetMarkerColor(kRed);
  hPADRTrk4->SetMarkerStyle(kOpenSquare);
  hPADRTrk4->SetMarkerColor(kBlue);
  hPNDRReflTrk4->SetLineColor(kRed);
  hPADRReflTrk4->SetLineColor(kBlue);

  hPNDRTrk8->SetMinimum(0.1);
  hPNDRTrk8->SetMaximum(1.3*hPNDRTrk8->GetBinContent(1));
  hPNDRTrk8->SetMarkerStyle(kFullSquare);
  hPNDRTrk8->SetMarkerColor(kRed);
  hPADRTrk8->SetMarkerStyle(kOpenSquare);
  hPADRTrk8->SetMarkerColor(kBlue);
  hPNDRReflTrk8->SetLineColor(kRed);
  hPADRReflTrk8->SetLineColor(kBlue);

  TCanvas * c3 = new TCanvas("c3","c3",800,500);
  c3->Divide(3,2);
  c3->cd(1);
  hPNDRTrk0->Draw("E");
  hPADRTrk0->Draw("Esame");
  hPNDRReflTrk0->Draw("histsame");
  hPADRReflTrk0->Draw("histsame");
  c3->cd(2);
  hPNDRTrk1->Draw("E");
  hPADRTrk1->Draw("Esame");
  hPNDRReflTrk1->Draw("histsame");
  hPADRReflTrk1->Draw("histsame");
  c3->cd(3);
  hPNDRTrk2->Draw("E");
  hPADRTrk2->Draw("Esame");
  hPNDRReflTrk2->Draw("histsame");
  hPADRReflTrk2->Draw("histsame");
  c3->cd(4);
  hPNDRTrk4->Draw("E");
  hPADRTrk4->Draw("Esame");
  hPNDRReflTrk4->Draw("histsame");
  hPADRReflTrk4->Draw("histsame");
  c3->cd(5);
  hPNDRTrk8->Draw("E");
  hPADRTrk8->Draw("Esame");
  hPNDRReflTrk8->Draw("histsame");
  hPADRReflTrk8->Draw("histsame");

  TCanvas * c4 = new TCanvas("c4","c4",600,500);
  c4->Divide(3,2);
  c4->cd(1);
  TH1D* hPNDRSigTrk0 = (TH1D*) hPNDRTrk0->Clone("hPNDRSigTrk0");
  hPNDRSigTrk0->Add(hPNDRReflTrk0,-1);
  hPNDRSigTrk0->Draw("E");
  TH1D* hPADRSigTrk0 = (TH1D*) hPADRTrk0->Clone("hPADRSigTrk0");
  hPADRSigTrk0->Add(hPADRReflTrk0,-1);
  hPADRSigTrk0->Draw("Esame");
  c4->cd(2);
  TH1D* hPNDRSigTrk1 = (TH1D*) hPNDRTrk1->Clone("hPNDRSigTrk1");
  hPNDRSigTrk1->Add(hPNDRReflTrk1,-1);
  hPNDRSigTrk1->Draw("E");
  TH1D* hPADRSigTrk1 = (TH1D*) hPADRTrk1->Clone("hPADRSigTrk1");
  hPADRSigTrk1->Add(hPADRReflTrk1,-1);
  hPADRSigTrk1->Draw("Esame");
  c4->cd(3);
  TH1D* hPNDRSigTrk2 = (TH1D*) hPNDRTrk2->Clone("hPNDRSigTrk2");
  hPNDRSigTrk2->Add(hPNDRReflTrk2,-1);
  hPNDRSigTrk2->Draw("E");
  TH1D* hPADRSigTrk2 = (TH1D*) hPADRTrk2->Clone("hPADRSigTrk2");
  hPADRSigTrk2->Add(hPADRReflTrk2,-1);
  hPADRSigTrk2->Draw("Esame");
  c4->cd(4);
  TH1D* hPNDRSigTrk4 = (TH1D*) hPNDRTrk4->Clone("hPNDRSigTrk4");
  hPNDRSigTrk4->Add(hPNDRReflTrk4,-1);
  hPNDRSigTrk4->Draw("E");
  TH1D* hPADRSigTrk4 = (TH1D*) hPADRTrk4->Clone("hPADRSigTrk4");
  hPADRSigTrk4->Add(hPADRReflTrk4,-1);
  hPADRSigTrk4->Draw("Esame");
  c4->cd(5);
  TH1D* hPNDRSigTrk8 = (TH1D*) hPNDRTrk8->Clone("hPNDRSigTrk8");
  hPNDRSigTrk8->Add(hPNDRReflTrk8,-1);
  hPNDRSigTrk8->Draw("E");
  TH1D* hPADRSigTrk8 = (TH1D*) hPADRTrk8->Clone("hPADRSigTrk8");
  hPADRSigTrk8->Add(hPADRReflTrk8,-1);
  hPADRSigTrk8->Draw("Esame");

  TCanvas * c5 = new TCanvas("c5","c5",600,500);
  TH1D* hDiff0 = (TH1D*) hPADRSigTrk0->Clone("hDiff0");
  hDiff0->Add(hPNDRSigTrk0,-1);
  hDiff0->SetMarkerColor(kBlue);
  hDiff0->SetMarkerStyle(kFullSquare);
  hDiff0->SetMaximum(14);
  hDiff0->SetMinimum(-4);
  hDiff0->SetStats(0);
  TH1D* hDiff1 = (TH1D*) hPADRSigTrk1->Clone("hDiff1");
  hDiff1->Add(hPNDRSigTrk1,-1);
  hDiff1->SetMarkerColor(kGreen-2);
  hDiff1->SetMarkerStyle(kFullCircle);
  TH1D* hDiff2 = (TH1D*) hPADRSigTrk2->Clone("hDiff2");
  hDiff2->Add(hPNDRSigTrk2,-1);
  hDiff2->SetMarkerColor(kOrange-2);
  hDiff2->SetMarkerSize(1.3);
  hDiff2->SetMarkerStyle(kFullStar);
  TH1D* hDiff4 = (TH1D*) hPADRSigTrk4->Clone("hDiff4");
  hDiff4->Add(hPNDRSigTrk4,-1);
  hDiff4->SetMarkerColor(kOrange+8);
  hDiff4->SetMarkerStyle(kFullTriangleUp);
  TH1D* hDiff8 = (TH1D*) hPADRSigTrk8->Clone("hDiff8");
  hDiff8->Add(hPNDRSigTrk8,-1);
  hDiff8->SetMarkerColor(kRed);
  hDiff8->SetMarkerStyle(kFullTriangleDown);

  hDiff0->Draw("l");
  hDiff1->Draw("lsame");
  hDiff2->Draw("lsame");
  hDiff4->Draw("lsame");
  hDiff8->Draw("lsame");

  TFile *fout = new TFile("out.root","RECREATE");
  fout->cd();

  hPNDRSigTrk0->Write();
  hPADRSigTrk0->Write();
  hPNDRSigTrk1->Write();
  hPADRSigTrk1->Write();
  hPNDRSigTrk2->Write();
  hPADRSigTrk2->Write();
  hPNDRSigTrk4->Write();
  hPADRSigTrk4->Write();
  hPNDRSigTrk8->Write();
  hPADRSigTrk8->Write();

  /*
  hPNDRTrk0->Write();
  hPADRTrk0->Write();
  hPNDRReflTrk0->Write();
  hPADRReflTrk0->Write();
  hPNDRTrk1->Write();
  hPADRTrk1->Write();
  hPNDRReflTrk1->Write();
  hPADRReflTrk1->Write();
  hPNDRTrk2->Write();
  hPADRTrk2->Write();
  hPNDRReflTrk2->Write();
  hPADRReflTrk2->Write();
  hPNDRTrk4->Write();
  hPADRTrk4->Write();
  hPNDRReflTrk4->Write();
  hPADRReflTrk4->Write();
  hPNDRTrk8->Write();
  hPADRTrk8->Write();
  hPNDRReflTrk8->Write();
  hPADRReflTrk8->Write();
  */

  fout->Close();
}
void closure_jetfakepho(){//main  
  
  int channel = 1; // 1 = eg; 2 = mg
	 
  TChain *sigtree = new TChain("signalTree");
  if(channel == 1)sigtree->Add("../../../data/resTree_egsignal_2016.root");
  else if(channel ==2)sigtree->Add("../../../data/resTree_mgsignal_2016.root");

  TChain *controltree = new TChain("jetTree");
  if(channel == 1)controltree->Add("../../../data/resTree_egsignal_2016.root");
  else if(channel == 2)controltree->Add("../../../data/resTree_mgsignal_2016.root");

  std::ostringstream outputname;
  if(channel == 1)outputname << "jet-fake-pho_egpt.root";
  else if(channel == 2)outputname << "jet-fake-pho_mgpt.root";
  TFile *outputfile = TFile::Open(outputname.str().c_str(),"RECREATE");
  outputfile->cd();

//*********** histo list **********************//
//  TH1F *p_controlPhoEt = new TH1F("p_controlPhoEt","#gamma E_{T}; E_{T} (GeV)",300,35,335);
//  TH1F *p_sigPhoEt  = new TH1F("p_sigPhoEt","#gamma E_{T}; E_{T} (GeV)",300,35,335);
//  TH1F *p_fakesPhoEt = new TH1F("p_fakesPhoEt","#gamma E_{T}; E_{T} (GeV)",300,35,335);
//  TH1F *p_elebkgPhoEt = new TH1F("p_elebkgPhoEt","#gamma E_{T}; E_{T} (GeV)",300,35,335);

  TH1F *p_controlPhoEt = new TH1F("p_controlPhoEt",";pt;",115,35,150);
  TH1F *p_sigPhoEt  = new TH1F("p_sigPhoEt",";pt;",115,35,150);
  TH1F *p_fakesPhoEt = new TH1F("p_fakesPhoEt",";pt;",115,35,150);
  TH1F *p_elebkgPhoEt = new TH1F("p_elebkgPhoEt",";pt;",115,35,150);

  sigtree->Draw("phoEt >> p_sigPhoEt", "sigMET < 70");
  controltree->Draw("phoEt >> p_controlPhoEt", "sigMET < 70");

  //p_sigPhoEt->SetBinContent(115, p_sigPhoEt->GetBinContent(115) + p_sigPhoEt->GetBinContent(116));
  //p_controlPhoEt->SetBinContent(115, p_controlPhoEt->GetBinContent(115) + p_controlPhoEt->GetBinContent(116));
  
  p_sigPhoEt->Sumw2();
  p_controlPhoEt->Sumw2();
//************ Proxy Tree **********************//
if(channel == 1){
  TChain *proxytree = new TChain("proxyTree");
  proxytree->Add("../../../data/resTree_egsignal_2016.root");

  float proxyphoEt(0);
  float proxysigMET(0);
  
  proxytree->SetBranchAddress("phoEt",     &proxyphoEt);
  proxytree->SetBranchAddress("sigMET",    &proxysigMET);
 
  for (unsigned ievt(0); ievt<proxytree->GetEntries(); ++ievt){//loop on entries
	proxytree->GetEntry(ievt);

    if(proxysigMET > 70)continue;
	double w_ele = 1; 
    for(unsigned i(0); i<nelePtBins-1; i++){
      if(proxyphoEt > elePtBins[i] && proxyphoEt < elePtBins[i+1])w_ele=elefakepho[i];
    }
    if(proxyphoEt >= 120)w_ele = 0.0124176; 
	p_elebkgPhoEt->Fill(proxyphoEt,w_ele);
  }
  p_elebkgPhoEt->Sumw2();
  p_sigPhoEt->Add(p_elebkgPhoEt, -1);
}
  for(unsigned ibin(1); ibin < p_sigPhoEt->GetSize()-1; ibin++){
    double xvalue = p_sigPhoEt->GetBinCenter(ibin);
    double frac(0),fracerror(0);
    for(unsigned i(0); i<19; i++) 
      if(xvalue >= PtBin[i] && xvalue < PtBin[i+1]){
        frac = fracHad[i];
        fracerror = fracHadError[i];
      }
    if(xvalue >= 140){ frac = (fracHad[18]+fracHad[17])/2; fracerror = fracHadError[18];}
    
    double binvalue = p_sigPhoEt->GetBinContent(ibin)*frac;
    double binerror = p_sigPhoEt->GetBinError(ibin);  
    if(binvalue == 0)continue;
    double totalerror = sqrt(binvalue*binvalue*fracerror*fracerror + binerror*binerror*frac*frac);
    p_fakesPhoEt->SetBinContent(ibin, binvalue);
    p_fakesPhoEt->SetBinError(ibin, binerror);
  }

outputfile->Write();

Double_t plotPtBins[]={35,40,45,50,55,60,65,70,75,80,85,90,100,110,120,130,140,160,200};
gStyle->SetOptStat(0);
TCanvas *c_pt = new TCanvas("Photon_Pt", "Photon P_{T}",800,800);
c_pt->cd();
TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0);
pad1->SetBottomMargin(0.1);
pad1->Draw();  
pad1->cd();  
gPad->SetLogy();
TH1 *new_controlPhoEt = p_controlPhoEt->Rebin(5);
TH1 *new_fakesPhoEt = p_fakesPhoEt->Rebin(5);
new_controlPhoEt->GetXaxis()->SetRangeUser(35,150);
new_fakesPhoEt->GetXaxis()->SetRangeUser(35,150);
new_controlPhoEt->Draw("EP");
new_controlPhoEt->SetLineColor(kBlack);
new_controlPhoEt->SetMarkerStyle(20);
new_fakesPhoEt->SetLineColor(kRed);
new_fakesPhoEt->SetMarkerStyle(20);
new_fakesPhoEt->SetMarkerColor(kRed);
new_fakesPhoEt->Draw("EP same");
TLegend *leg =  new TLegend(0.6,0.7,0.9,0.9);
leg->SetFillStyle(0);
gStyle->SetLegendBorderSize(1);
gStyle->SetLegendFillColor(0);
leg->AddEntry(new_controlPhoEt,"hadron proxies");
leg->AddEntry(new_fakesPhoEt,"fake photons");
leg->Draw("same");

TF1 *fitfunc_num = new TF1("fitfunc_num","expo(0)+expo(3)",35,150);
TF1 *fitfunc_den = new TF1("fitfunc_den","expo(0)+expo(3)",35,150);

c_pt->cd();
TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.25);
pad2->Draw();
pad2->cd();
TH1F *ratio=(TH1F*)new_fakesPhoEt->Clone("transfer factor");
ratio->Divide(new_controlPhoEt);
ratio->SetTitle("");
ratio->GetYaxis()->SetTitle("proxies/fake");
ratio->GetXaxis()->SetLabelFont(63);
ratio->GetXaxis()->SetLabelSize(14);
ratio->GetYaxis()->SetLabelFont(63);
ratio->GetYaxis()->SetLabelSize(14);
ratio->Draw();

RooRealVar pt("pt","",35,150);
//pt.setBins(33);
new_controlPhoEt->SetMaximum(new_controlPhoEt->GetEntries());
new_fakesPhoEt->SetMaximum(new_fakesPhoEt->GetEntries());
RooDataHist* hist_den = new RooDataHist("hist_den","hist_den",pt,new_controlPhoEt);
RooDataHist* hist_num = new RooDataHist("hist_num","hist_num",pt,new_fakesPhoEt);
RooHistPdf*  pdf_den  = new RooHistPdf("pdf_den","pdf_den", pt, *hist_den);
RooHistPdf*  pdf_num  = new RooHistPdf("pdf_num","pdf_num", pt, *hist_num);
RooRealVar coeff1_den("coeff1_den","coeff1", 1, -15, 10*new_controlPhoEt->GetEntries());
RooRealVar coeff2_den("coeff2_den","coeff2", 1, -15, 10*new_controlPhoEt->GetEntries());
RooRealVar lambda1_den("lambda1_den","lambda1", 0.02, -1, 1);
RooRealVar lambda2_den("lambda2_den","lambda2", 0.02, -1, 1);
RooExponential expo1_den("expo1_den", "exponential PDF", pt, lambda1_den);
RooExponential expo2_den("expo2_den", "exponential PDF", pt, lambda2_den);
RooAddPdf model_den("model_den","",RooArgList(expo1_den, expo2_den),RooArgList(coeff1_den, coeff2_den));

RooRealVar coeff1_num("coeff1_num","coeff1", 1, -15, 10*new_fakesPhoEt->GetEntries());
RooRealVar coeff2_num("coeff2_num","coeff2", 1, -15, 10*new_fakesPhoEt->GetEntries());
RooRealVar lambda1_num("lambda1_num","lambda1", 0.02, -1, 1);
RooRealVar lambda2_num("lambda2_num","lambda2", 0.02, -1, 1);
RooExponential expo1_num("expo1_num", "exponential PDF", pt, lambda1_num);
RooExponential expo2_num("expo2_num", "exponential PDF", pt, lambda2_num);
RooAddPdf model_num("model_num","",RooArgList(expo1_num, expo2_num),RooArgList(coeff1_num, coeff2_num));

//RooMCStudy* mcstudy_den = new RooMCStudy(*pdf_den,pt,RooFit::FitModel(model_den),RooFit::Binned(kTRUE),RooFit::Silence(),RooFit::Extended(),
//				       RooFit::FitOptions(RooFit::Save(kTRUE),RooFit::PrintEvalErrors(0)));
//RooMCStudy* mcstudy_num = new RooMCStudy(*pdf_num,pt,RooFit::FitModel(model_num),RooFit::Binned(kTRUE),RooFit::Silence(),RooFit::Extended(),
//				       RooFit::FitOptions(RooFit::Save(kTRUE),RooFit::PrintEvalErrors(0)));
//RooChi2MCSModule chi2mod_den;
//RooChi2MCSModule chi2mod_num;
//mcstudy_den->addModule(chi2mod_den);
//mcstudy_num->addModule(chi2mod_num);
//mcstudy_den->generateAndFit(1000,new_controlPhoEt->GetEntries());
//mcstudy_num->generateAndFit(1000,new_fakesPhoEt->GetEntries());

//TH1* chi2_den = mcstudy_den->fitParDataSet().createHistogram("chi2"); 
//TH1* prob_den = mcstudy_den->fitParDataSet().createHistogram("prob");   
//TH1* chi2_num = mcstudy_num->fitParDataSet().createHistogram("chi2"); 
//TH1* prob_num = mcstudy_num->fitParDataSet().createHistogram("prob");   
//TH1* result_den = mcstudy_den->fitParDataSet().createHistogram("hh");
//TH1* result_den = mcstudy_den->fitResult(0)->correlationHist("c000") ;
//chi2_num->SetLineColor(kRed) ;
//prob_num->SetLineColor(kRed) ;

TCanvas* mccan = new TCanvas("mccan","mccan",800,400) ;
mccan->Divide(2) ;
//mccan->cd(1) ; gPad->SetLeftMargin(0.15) ; chi2_den->GetYaxis()->SetTitleOffset(1.4) ; chi2_den->Draw() ; chi2_num->Draw("esame") ;
//mccan->cd(2) ; gPad->SetLeftMargin(0.15) ; prob_den->GetYaxis()->SetTitleOffset(1.4) ; prob_den->Draw() ; prob_num->Draw("esame") ;
RooPlot* den_frame = pt.frame(RooFit::Title("jet proxies"));
RooPlot* num_frame = pt.frame(RooFit::Title("candidate photon X hadron factor"));

mccan->cd(1);
gPad->SetLogy();
den_frame->SetMaximum(new_controlPhoEt->GetEntries());
RooFitResult* reden = model_den.fitTo(*hist_den,RooFit::SumW2Error(kTRUE),RooFit::Save());
hist_den->plotOn(den_frame);
model_den.plotOn(den_frame,
		 RooFit::FillColor(kBlue-4));
den_frame->Draw();

mccan->cd(2);
gPad->SetLogy();
num_frame->SetMaximum(10000);
num_frame->SetMinimum(10);
RooFitResult* renum = model_num.fitTo(*hist_num,RooFit::SumW2Error(kTRUE),RooFit::Save());
hist_num->plotOn(num_frame);
model_num.plotOn(num_frame,
		 RooFit::FillColor(kBlue-4));
num_frame->Draw();

pt.setRange("signal",35,150);
RooAbsReal* igx_den1 = expo1_den.createIntegral(pt,RooFit::Range("signal"));
RooAbsReal* igx_den2 = expo2_den.createIntegral(pt,RooFit::Range("signal"));
RooAbsReal* igx_num1 = expo1_num.createIntegral(pt,RooFit::Range("signal"));
RooAbsReal* igx_num2 = expo2_num.createIntegral(pt,RooFit::Range("signal"));
std::cout << "inte den1=" << igx_den1->getVal() << " den2=" << igx_den2->getVal() << " num1=" << igx_num1->getVal() << " num2=" << igx_num2->getVal() << std::endl;
std::cout << "totalden=" << new_controlPhoEt->GetEntries() << std::endl;
fitfunc_den->SetParameter(1,lambda1_den.getVal());
fitfunc_den->SetParameter(3,lambda2_den.getVal());
fitfunc_num->SetParameter(1,lambda1_num.getVal());
fitfunc_num->SetParameter(3,lambda2_num.getVal());
new_fakesPhoEt->Fit("fitfunc_num");
new_controlPhoEt->Fit("fitfunc_den");
c_pt->cd();
pad1->cd();
fitfunc_den->Draw("same");
fitfunc_num->Draw("same");
if(channel == 1)c_pt->SaveAs("JetFake_ratio_eg.pdf");
else if(channel == 2)c_pt->SaveAs("JetFake_ratio_mg.pdf");
//  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
//   1  p0           9.73181e+00   2.26898e-01   2.78046e-05   9.10547e-03
//   2  p1          -3.34186e-02   1.55081e-03   4.43967e-07   7.43686e-01
//  3  p3           9.55643e+00   2.70401e-01   3.31514e-05   7.64064e-03
//  4  p4          -3.34188e-02   1.82847e-03   5.28578e-07   5.89368e-01
//FCN=95.1209 FROM MIGRAD    STATUS=CONVERGED     253 CALLS         254 TOTAL
//                    EDM=2.21358e-08    STRATEGY= 1      ERROR MATRIX ACCURATE 
// EXT PARAMETER                                   STEP         FIRST   
// NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
//  1  p0           2.27259e+00   1.40250e+00   3.06094e-04  -1.34231e-05
//  2  p1           2.05848e-02   9.68368e-03   2.22428e-06  -1.31028e-02
//  3  p3           1.24698e+01   9.85422e-03   9.76944e-06  -3.21533e-02
//   4  p4          -4.47018e-02   2.05076e-04   1.63128e-07  -1.91568e+00

mccan->SaveAs("JetFake_ptfitting.pdf");
for(unsigned i(0); i< 23; i++){
  Double_t bincenter = i*5.0+2.5;
  std::cout << "bin" << i << "  " << ratio->GetBinContent(i) << "  predict = " << fitfunc_num->Eval(bincenter)/fitfunc_den->Eval(bincenter) << std::endl;
}
}
void hand_beam_asymmetry_vs_nu(){

	bool includeVetos;
// 	If includeVetos = false, then only good bars will be displayed. If 
//	includeVetos = true, then veto bars will be shown along with the good bars.
//	includeVetos = true;
	includeVetos = false;

	bool includeAntivetos;
// 	If includeAntivetos = false, then only good bars will be displayed. If 
//	includeAntivetos = true, then antiveto bars will be shown along with the good bars.
//	includeAntivetos = true;
	includeAntivetos = false;

	bool antivetosAsVetos;
//	If antivetosAsVetos = false, then the antivetos will not be included in the veto cut
//	If antivetosAsVetos = true, then the antivetos will be included in the veto cut
//	Discusses elsewhere, antivetos are the bars immediately following a goodBar
	antivetosAsVetos = false;
//	antivetosAsVetos = true;

	bool drawCuts = true;
//	bool drawCuts = false;

// 	The SinglePlane and SingleBar booleans skip the loop that goes over
// 	ever bar into just a single plane and/or a single bar.
	bool SinglePlane;
	bool SingleBar;
	int singleplane;
	int singlebar;
//	SinglePlane = true;
	SinglePlane = false;
	singleplane = 2;
//	SingleBar = true;
	SingleBar = false;
	singlebar = 10;
/*
	int HeRunNumber = 22441;
	int endHeRunNumber = 22441;
	TString Q2 = "1.0";
	double q2min = 0.75;
	double q2max = 1.2;
	double numin = 0.3;
	double numax = 0.7;
	int Positionbins = 30;
	double Positionmin = -30;
	double Positionmax = 30;
	int TDCbins = 100;
	double TDCmin = 700;
	double TDCmax = 800;
	int ADCbins = 700;
	double ADCmin = -100;
	double ADCmax = 11100;
	double goodTDCleftcutmin = 752;
	double goodTDCleftcutmax = 775;
	double goodTDCrightcutmin = 752;
	double goodTDCrightcutmax = 775;
	double vetoTDCcutmin = 750;
	double vetoTDCcutmax = 785;
*/
/*
// ********* Vertical, Q2=1.0 *******************
	int HeRunNumber = 20596;
	int endHeRunNumber = 20683;
	TString Q2 = "1.0";
	double q2min = 0.75;
	double q2max = 1.2;
	double numin = 0.3;
	double numax = 0.7;
	int Positionbins = 30;
	double Positionmin = -30;
	double Positionmax = 30;
	int TDCbins = 200;
	double TDCmin = 1300;
	double TDCmax = 1700;
	int ADCbins = 700;
	double ADCmin = -100;
	double ADCmax = 11100;
	double goodTDCleftcutmin = 1385;
	double goodTDCleftcutmax = 1415;
	double goodTDCrightcutmin = 1385;
	double goodTDCrightcutmax = 1415;
	double vetoTDCcutmin = 1385;
	double vetoTDCcutmax = 1415;
*/
/*
// ********* Vertical, Q2=0.5 *******************
	int HeRunNumber = 20890;
	int endHeRunNumber = 20890;
	TString Q2 = "0.5";
	double q2min = 0.3;
	double q2max = 0.6;
	double numin = 0.1;
	double numax = 0.35;
	int Positionbins = 30;
	double Positionmin = -30;
	double Positionmax = 30;
	int TDCbins = 75;
	double TDCmin = 1300;
	double TDCmax = 1500;
	int ADCbins = 700;
	double ADCmin = -100;
	double ADCmax = 11100;
	double goodTDCleftcutmin = 1385;
	double goodTDCleftcutmax = 1415;
	double goodTDCrightcutmin = 1385;
	double goodTDCrightcutmax = 1415;
	double vetoTDCcutmin = 1385;
	double vetoTDCcutmax = 1415;
*/

/*
// ********* Vertical, Q2=0.42 *******************
	int HeRunNumber = 21383;
	int endHeRunNumber = 21387;
	TString Q2 = "0.42";
	double q2min = 0.33;
	double q2max = 0.51;
	double numin = 0.17;
	double numax = 0.3;
	int Positionbins = 30;
	double Positionmin = -30;
	double Positionmax = 30;
	int TDCbins = 50;
	double TDCmin = 700;
	double TDCmax = 800;
	int ADCbins = 700;
	double ADCmin = -100;
	double ADCmax = 11100;
	double goodTDCleftcutmin = 730;
	double goodTDCleftcutmax = 770;
	double goodTDCrightcutmin = 740;
	double goodTDCrightcutmax = 780;
	double vetoTDCcutmin = 730;
	double vetoTDCcutmax = 770;
*/
/*
	int HeRunNumber = 21714;
	int endHeRunNumber = 22248;
	TString Q2 = "0.52";
	double q2min = 0.33;
	double q2max = 0.62;
	double numin = 0.17;
	double numax = 0.35;
	int Positionbins = 30;
	double Positionmin = -30;
	double Positionmax = 30;
	int TDCbins = 50;
	double TDCmin = 700;
	double TDCmax = 800;
	int ADCbins = 700;
	double ADCmin = -100;
	double ADCmax = 11100;
	double goodTDCleftcutmin = 730;
	double goodTDCleftcutmax = 770;
	double goodTDCrightcutmin = 740;
	double goodTDCrightcutmax = 780;
	double vetoTDCcutmin = 730;
	double vetoTDCcutmax = 770;
*/

// ********* Transverse, Q2=1.0 *******************
	int HeRunNumber = 22450;
	int endHeRunNumber = 22450;
//	int endHeRunNumber = 22489;
	TString Q2 = "1.0";
	double q2min = 0.75;
	double q2max = 1.2;
	double numin = 0.3;
	double numax = 0.7;
	int Positionbins = 30;
	double Positionmin = -30;
	double Positionmax = 30;
	int TDCbins = 100;
	double TDCmin = 650;
	double TDCmax = 850;
/*
	int TDCbins = 600;
	double TDCmin = 0;
	double TDCmax = 1600;
*/
	int ADCbins = 700;
	double ADCmin = -100;
	double ADCmax = 11100;

/*	double goodTDCleftcutmin = 745;
	double goodTDCleftcutmax = 775;
	double goodTDCrightcutmin = 750;
	double goodTDCrightcutmax = 780;
*/
//	double goodTDCleftcutmin = 645;
//	double goodTDCleftcutmax = 875;
//	double goodTDCrightcutmin = 650;
//	double goodTDCrightcutmax = 880;

	double goodTDCleftcutmin = 1;
	double goodTDCleftcutmax = 1600;
	double goodTDCrightcutmin = 1;
	double goodTDCrightcutmax = 1600;



	double vetoTDCcutmin = 745;
	double vetoTDCcutmax = 780;



//	const int nuBins = 50;
	const int nuBins = 10;
	double nuMin = 0.35;
	double nuMax = 0.65;

	double xmin = 0.6;
	double xmax = 3.0;

	int bins = 50;

	TString outputPlotsHere = "/home/ellie/physics/e05-102/images/plots_for_hand/hand_beam_asymmetry_vs_nu/";

	TString outputRootString = outputPlotsHere;
	outputRootString += "hand_beam_asym_vs_nu_for_runs_";
	outputRootString += HeRunNumber;
	outputRootString += "-";
	outputRootString += endHeRunNumber;
	outputRootString += ".root";
//	TFile *outputRoot = new TFile(outputRootString,"RECREATE");
	TFile outputRoot(outputRootString,"RECREATE");

	outputRoot.Close();

	TString asymOutFileName = outputPlotsHere;
	asymOutFileName += "target_asymmetry_for_runs_";
	asymOutFileName += HeRunNumber;
	asymOutFileName += "-";
	asymOutFileName += endHeRunNumber;
	if (includeVetos) asymOutFileName += "-with-vetos";
	asymOutFileName += ".txt";
	ofstream asymOutFile;
	asymOutFile.open(asymOutFileName);

	// Although declared here, the goodTDCcut is actually made down below where  it can be included
	// in the loop so that it is easy to have it change for each good bar when done one at a time.
	// However, the left and right min and max TDC values are defined here
	TCut goodTDCcut = "";

	TChain* chainHe = new TChain("T");
	TString filenameHe;

	for (int thisHeRunNumber=HeRunNumber; thisHeRunNumber<(endHeRunNumber+1); thisHeRunNumber++)
	{
		// Skipping Vertical Non-Production Runs
		if(thisHeRunNumber==20591){thisHeRunNumber=20596;}
		if(thisHeRunNumber==20731){thisHeRunNumber=20738;}
		if(thisHeRunNumber==20732){thisHeRunNumber=20738;}
		if(thisHeRunNumber==20733){thisHeRunNumber=20738;}
		if(thisHeRunNumber==20734){thisHeRunNumber=20738;}
		if(thisHeRunNumber==20736){thisHeRunNumber=20738;}
		if(thisHeRunNumber==20737){thisHeRunNumber=20738;}
		if(thisHeRunNumber==20762){thisHeRunNumber=20789;}
		if(thisHeRunNumber==20763){thisHeRunNumber=20789;}
		if(thisHeRunNumber==20764){thisHeRunNumber=20789;}
		if(thisHeRunNumber==20791){thisHeRunNumber=20814;}
		if(thisHeRunNumber==20792){thisHeRunNumber=20814;}

		// Skipping Longitudinal Non-Production Runs
		if(thisHeRunNumber==22380){thisHeRunNumber=22393;}
		if(thisHeRunNumber==22389){thisHeRunNumber=22393;}
		if(thisHeRunNumber==22425){thisHeRunNumber=22436;}
		if(thisHeRunNumber==22426){thisHeRunNumber=22436;}

		// Skipping Transverse Non-Production Runs
		if(thisHeRunNumber==22461){thisHeRunNumber=22465;}


		for (int t=0; t<1000; t++)
		{
			filenameHe = "/home/ellie/physics/e05-102/ellana/ROOTfiles/e05102_R_";
			filenameHe += thisHeRunNumber;
			if (t != 0)
			{
				filenameHe += "_";
				filenameHe += t;
			}
			filenameHe += ".root";
			ifstream ifileHe(filenameHe);
			if (ifileHe)
			{
				cout << "Adding file to chainHe: " << filenameHe << endl;
				chainHe->Add(filenameHe);
			}
			else
			{
				cout << "File " << filenameHe << " does not exist. Ending here." << endl;
				t=999999999;
			}
			TFile fileHe(filenameHe);
		}
	}

	gStyle->SetPalette(1);

	TCut cut = ""; TCut kinematics = ""; TCut eventtype = ""; TCut dp = ""; TCut target = "";
	TCut tracks = ""; TCut thph = ""; TCut xbj = ""; TCut pssh = ""; TCut cerenkov = "";
	TCut q2nu = ""; TCut basic = ""; TCut cuts = "";

	TString imageCutsTitle = outputPlotsHere;
	imageCutsTitle += "HAND_plots_Run_Num_";
	imageCutsTitle += HeRunNumber;
	imageCutsTitle += "-";
	imageCutsTitle += endHeRunNumber;
	imageCutsTitle += "_basic_cuts";
	if (includeVetos) imageCutsTitle += "_with_vetos";
	if (includeAntivetos) {imageCutsTitle += "_with_antivetos";}
	if (antivetosAsVetos && includeAntivetos) {imageCutsTitle += "_as_vetos";}
	imageCutsTitle += ".png";

	hand_basic_cuts(cut, kinematics, eventtype, dp, target, tracks, thph, xbj, pssh, cerenkov, q2nu, basic, cuts, imageCutsTitle, HeRunNumber, endHeRunNumber, chainHe, numin, numax, q2min, q2max, bins, xmin, xmax, drawCuts, Q2, outputRootString);

	TFile *outputRoot1 = new TFile(outputRootString,"UPDATE");

	TString cutstring = TString(cuts);
	cout << "Cuts: " << cutstring << endl;
// **********************************************************************************************
	gStyle->SetOptFit(1111);
        TString veto1plane = "";
        TString veto1bar = "";
        TString veto2plane = "";
        TString veto2bar = "";
        TString veto3plane = "";
        TString veto3bar = "";
        TString veto4plane = "";
        TString veto4bar = "";
        TString veto5plane = "";
        TString veto5bar = "";
        TString veto6plane = "";
        TString veto6bar = "";
        TString antiveto1plane = "";
        TString antiveto1bar = "";
        TString antiveto2plane = "";
        TString antiveto2bar = "";
        TString antiveto3plane = "";
        TString antiveto3bar = "";
        TString allVetos = "";
        TString allAntivetos = "";
        TString vetoTDCslSt = "";
        TString vetoTDCsrSt = "";
        TCut vetoTDCsl = "";
        TCut vetoTDCsr = "";
        TCut vetoTDCs = "";
        TString antivetosTDCslSt = "";
        TString antivetosTDCsrSt = "";
	int maxbars = 0;
	int vetoplane = 0;
	int padBins = 0;
	double padMin = 0;
	double padMax = 0;

// **********************************************************************************************
// This bit of code should set the charge and livetime scaling factors
        double HeChargeScale; double Helivetime;
        double HeChargeScaleUp; double HelivetimeUp;
        double HeChargeScaleDown; double HelivetimeDown;
        double BeamChargeScaleUp; double BeamlivetimeUp;
        double BeamChargeScaleDown; double BeamlivetimeDown;
        hand_scaling_factors(HeRunNumber, endHeRunNumber, HeChargeScale, Helivetime, HeChargeScaleUp, HelivetimeUp, HeChargeScaleDown, HelivetimeDown, BeamChargeScaleUp, BeamlivetimeUp, BeamChargeScaleDown, BeamlivetimeDown);
	HeChargeScale = 0.00001 * int(HeChargeScale * 100000.0 + 0.5);
	HeChargeScaleUp = 0.00001 * int(HeChargeScaleUp * 100000.0 + 0.5);
	HeChargeScaleDown = 0.00001 * int(HeChargeScaleDown * 100000.0 + 0.5);
	BeamChargeScaleUp = 0.00001 * int(BeamChargeScaleUp * 100000.0 + 0.5);
	BeamChargeScaleDown = 0.00001 * int(BeamChargeScaleDown * 100000.0 + 0.5);
	Helivetime = 0.0001 * int(Helivetime * 10000.0 + 0.5);
	HelivetimeUp = 0.0001 * int(HelivetimeUp * 10000.0 + 0.5);
	HelivetimeDown = 0.0001 * int(HelivetimeDown * 10000.0 + 0.5);
	BeamlivetimeUp = 0.0001 * int(BeamlivetimeUp * 10000.0 + 0.5);
	BeamlivetimeDown = 0.0001 * int(BeamlivetimeDown * 10000.0 + 0.5);
	cout << "HeChargeScale: " << HeChargeScale << "C, Helivetime: " << Helivetime << endl;
	cout << "HeChargeScaleUp: " << HeChargeScaleUp << "C, HelivetimeUp: " << HelivetimeUp << endl;
	cout << "HeChargeScaleDown: " << HeChargeScaleDown << "C, HelivetimeDown: " << HelivetimeDown << endl;
	cout << "BeamChargeScaleUp: " << BeamChargeScaleUp << "C, BeamlivetimeUp: " << BeamlivetimeUp << endl;
	cout << "BeamChargeScaleDown: " << BeamChargeScaleDown << "C, BeamlivetimeDown: " << BeamlivetimeDown << endl;

// **********************************************************************************************

// The section below plots the HAND data
// **********************************************************************************************
//	int whichplane = 0;
	int whichplane = 1;
	int endplane = 5;
	if (SinglePlane) {whichplane = singleplane; endplane = singleplane+1;}
	int whichbar=0;
//	int whichbar=11;
	TString titleTotalSpinUpx = "Total Helicity Up vs. xBj";
	if (includeVetos) {titleTotalSpinUpx += " with vetos";}
	else {titleTotalSpinUpx += " without vetos";}
	titleTotalSpinUpx += " with goodTDC cuts";
	cout << "Drawing " << titleTotalSpinUpx << "..." << endl;
	TString plotTotalSpinUpx = "HANDTotalSpinUpx";
	TH1F *HANDTotalSpinUpx = new TH1F(plotTotalSpinUpx,titleTotalSpinUpx,nuBins,nuMin,nuMax);
	TString titleTotalSpinDownx = "Total Spin Down vs. xBj";
	if (includeVetos) {titleTotalSpinDownx += " with vetos";}
	else {titleTotalSpinDownx += " without vetos";}
	titleTotalSpinDownx += " with goodTDC cuts";
	cout << "Drawing " << titleTotalSpinDownx << "..." << endl;
	TString plotTotalSpinDownx = "HANDTotalSpinDownx";
	TH1F *HANDTotalSpinDownx = new TH1F(plotTotalSpinDownx,titleTotalSpinDownx,nuBins,nuMin,nuMax);

	for (int nplane=whichplane; nplane<endplane; nplane++)
	{
		if (nplane==0) maxbars=32;
		if (nplane==1) maxbars=30;
		if (nplane==2) maxbars=24;
		if (nplane==3) maxbars=22;
		if (nplane==4) maxbars=12;
		if (SingleBar) {whichbar = singlebar; maxbars = singlebar + 1;}
		for (int thisbar=whichbar; thisbar<maxbars; thisbar++)
		{

			TString goodPlane = nplane;
			TString goodPMT = thisbar;
			hand_define_vetos(includeVetos, includeAntivetos, antivetosAsVetos, nplane, thisbar, veto1plane, veto2plane, veto3plane, veto4plane, veto5plane, veto6plane, veto1bar, veto2bar, veto3bar, veto4bar, veto5bar, veto6bar, antiveto1plane, antiveto2plane, antiveto3plane, antiveto1bar, antiveto2bar, antiveto3bar, allVetos, allAntivetos, vetoTDCslSt, vetoTDCsrSt, vetoTDCsl, vetoTDCsr, vetoTDCs, vetoTDCcutmin, vetoTDCcutmax, antivetosTDCslSt, antivetosTDCsrSt);
			
			TString goodBar = "nd.p";
			goodBar += nplane;
			goodBar += ".";
			goodBar += thisbar;
			goodBar += " ";
			cout << "Good Bar: " << goodBar << endl;

			TString goodTDCl = "NA.nd.p";
			goodTDCl += nplane;
			if (nplane == 0) goodTDCl = "NA.veto";
			goodTDCl += ".lt_c[";
			goodTDCl += thisbar;
			goodTDCl += "]";
			TString goodTDCr = "NA.nd.p";
			goodTDCr += nplane;
			if (nplane == 0) goodTDCr = "NA.veto";
			goodTDCr += ".rt_c[";
			goodTDCr += thisbar;
			goodTDCr += "]";
			TString goodTDCs = goodTDCl;
			goodTDCs += ":";
			goodTDCs += goodTDCr;
		
                        TString goodADCl = "NA.nd.p";
                        goodADCl += nplane;
                        if (nplane == 0) goodADCl = "NA.veto";
                        goodADCl += ".la_c[";
                        goodADCl += thisbar;
                        goodADCl += "]";
                        TString goodADCr = "NA.nd.p";
                        goodADCr += nplane;
                        if (nplane == 0) goodADCr = "NA.veto";
                        goodADCr += ".ra_c[";
                        goodADCr += thisbar;
                        goodADCr += "]";
                        TString goodADCs = goodADCl;
                        goodADCs += ":";
                        goodADCs += goodADCr;
	
			TString canvasName = "handp";
			canvasName += nplane;
			canvasName += "b";
			canvasName += thisbar;
			TString canvasTitle = "HAND - Plane ";
			canvasTitle += nplane;
			canvasTitle += ", Bar ";
			canvasTitle += thisbar;
			TCanvas *handCanvas = new TCanvas(canvasName,canvasTitle,1400,770); //x,y
			handpad01 =  new TPad("handpad01","handpad01",0.0000,0.0000,0.1000,1.0000,0,0,0);
			handpad02 =  new TPad("handpad02","handpad02",0.1000,0.6666,0.5500,1.0000,0,0,0);
			handpad03 =  new TPad("handpad03","handpad03",0.5500,0.6666,1.0000,1.0000,0,0,0);
			handpad04 =  new TPad("handpad04","handpad04",0.1000,0.3333,0.5500,0.6666,0,0,0);
			handpad05 =  new TPad("handpad05","handpad05",0.5500,0.3333,1.0000,0.6666,0,0,0);
			handpad06 =  new TPad("handpad06","handpad06",0.1000,0.0000,0.5500,0.3333,0,0,0);
			handpad07 =  new TPad("handpad07","handpad07",0.5500,0.0000,1.0000,0.3333,0,0,0);
			handpad01->Draw(); handpad02->Draw(); handpad03->Draw(); handpad04->Draw(); handpad05->Draw();
			handpad06->Draw(); handpad07->Draw();

			// This section will run hand_draw.h which will draw the HAND in handpad01.
			handpad01->cd();
			hand_draw(HeRunNumber, endHeRunNumber, antivetosAsVetos, allVetos, goodBar, allAntivetos);
			handpad01->Update();

			TString goodTDCleftcutString = "(NA.nd.p";
			goodTDCleftcutString += nplane;
			if (nplane == 0) {goodTDCleftcutString = "(NA.veto";}
			goodTDCleftcutString += ".lt_c[";
			goodTDCleftcutString += thisbar;
			goodTDCleftcutString += "]>";
			goodTDCleftcutString += goodTDCleftcutmin;
			if (nplane > 0)
			{
				goodTDCleftcutString += " && NA.nd.p";
				goodTDCleftcutString += nplane;
			}
			if (nplane == 0) {goodTDCleftcutString += " && NA.veto";}
			goodTDCleftcutString += ".lt_c[";
			goodTDCleftcutString += thisbar;
			goodTDCleftcutString += "]<";
			goodTDCleftcutString += goodTDCleftcutmax;
			goodTDCleftcutString += ")";
			cout << "goodTDCleftcutString = " << goodTDCleftcutString << endl;
			TCut goodTDCleftcut = goodTDCleftcutString;
	
			TString goodTDCrightcutString = "(NA.nd.p";
			goodTDCrightcutString += nplane;
			if (nplane == 0) {goodTDCrightcutString = "(NA.veto";}
			goodTDCrightcutString += ".rt_c[";
			goodTDCrightcutString += thisbar;
			goodTDCrightcutString += "]>";
			goodTDCrightcutString += goodTDCrightcutmin;
			if (nplane > 0)
			{
				goodTDCrightcutString += " && NA.nd.p";
				goodTDCrightcutString += nplane;
			}
			if (nplane == 0) {goodTDCrightcutString += " && NA.veto";}
			goodTDCrightcutString += ".rt_c[";
			goodTDCrightcutString += thisbar;
			goodTDCrightcutString += "]<";
			goodTDCrightcutString += goodTDCrightcutmax;
			goodTDCrightcutString += ")";
			cout << "goodTDCrightcutString = " << goodTDCrightcutString << endl;
			TCut goodTDCrightcut = goodTDCrightcutString;
		
			TString firstTrackString = "NA.n.plane==";
			firstTrackString += (nplane - 1);
			firstTrackString += " && NA.n.pad==";
			firstTrackString += thisbar;
			TCut firstTrack = firstTrackString;

	
			goodTDCcut = (goodTDCleftcut || goodTDCrightcut);

//			cout << "Cuts: " << cutstring << endl;
			TString vetoCutString = TString(vetoTDCs);
//			cout << "Veto Cuts: " << vetoCutString << endl; 

			handpad02->cd();
			TString titleHANDleft = "Left TDC for Plane #";
			titleHANDleft += nplane;
			titleHANDleft += ", PMT # ";
			titleHANDleft += thisbar;
			if (includeVetos) {titleHANDleft += " with vetos";}
			else {titleHANDleft += " without vetos";}
			cout << "Drawing " << titleHANDleft << "..." << endl;
			TString plotHANDleft = "HANDleft_p";
			plotHANDleft += nplane;
			plotHANDleft += "_b";
			plotHANDleft += thisbar;
			TString plotHANDleftcut = plotHANDleft;
			plotHANDleftcut += "_cut";
//			cout << "plotHANDleft: " << plotHANDleft << ", plotHANDleftcut: " << plotHANDleftcut << endl;
			cout << "goodTDCl: " << goodTDCl << endl;
			TH1F *HANDleft = new TH1F(plotHANDleft,titleHANDleft,TDCbins,TDCmin,TDCmax);
			HANDleft->SetMinimum(0);
			TH1F *HANDleftcut = new TH1F(plotHANDleftcut,titleHANDleft,TDCbins,TDCmin,TDCmax);
			HANDleftcut->SetMinimum(0);
			TString HANDleftTDC = goodTDCl;
			HANDleftTDC += ">>";
			HANDleftTDC += plotHANDleft;
			TString HANDleftTDCcut = goodTDCl;
			HANDleftTDCcut += ">>";
			HANDleftTDCcut += plotHANDleftcut;
			chainHe->Draw(HANDleftTDC, cuts && vetoTDCs && firstTrack,"");
//			chainHe->Draw(HANDleftTDC, vetoTDCs,"");
//			HANDleft->Scale(1/(HeChargeScale*Helivetime));
			HANDleft->Write();
			HANDleft->Draw();
			if (!includeVetos) {chainHe->Draw(HANDleftTDCcut, cuts && goodTDCleftcut&& firstTrack,"same");}
			if (includeVetos) {chainHe->Draw(HANDleftTDCcut, cuts && vetoTDCs && goodTDCleftcut && firstTrack,"same");}
			HANDleftcut->SetFillColor(kViolet);
//			HANDleftcut->Scale(1/(HeChargeScale*Helivetime));
			HANDleftcut->Write();
			HANDleftcut->Draw("same");
			// ********************************************************************************
			// This section below gathers and prints some statistics on the plot
			double numHANDleftcutEvents = 0;
			for (int i=0; i<TDCbins; i++){ numHANDleftcutEvents = numHANDleftcutEvents + HANDleftcut->GetBinContent(i);}
			TString HANDleftFactorsString = "Total Charge for Runs: ";
			HANDleftFactorsString += HeChargeScale;
			HANDleftFactorsString += " C";
			TString HANDleftFactorsString1 = "Total Livetime for Runs: ";
			HANDleftFactorsString1 += Helivetime;
			TString HANDleftFactorsString2 = "# of Cut (Purple) Events: ";
			HANDleftFactorsString2 += numHANDleftcutEvents;
			HANDleftFactors = new TPaveText(0.11,0.69,0.4,0.89,"NDC");
			TText *t1 = HANDleftFactors->AddText(HANDleftFactorsString);
			TText *t2 = HANDleftFactors->AddText(HANDleftFactorsString1);
			TText *t2 = HANDleftFactors->AddText(HANDleftFactorsString2);
			HANDleftFactors->Write();
			HANDleftFactors->Draw("same");
			// ********************************************************************************
			handpad02->Update();

			handpad03->cd();
			TString titleHANDright = "Right TDC for Plane #";
			titleHANDright += nplane;
			titleHANDright += ", PMT # ";
			titleHANDright += thisbar;
			if (includeVetos) {titleHANDright += " with vetos";}
			else {titleHANDright += " without vetos";}
			TString plotHANDright = "HANDright_p";
			plotHANDright += nplane;
			plotHANDright += "_b";
			plotHANDright += thisbar;
			TString plotHANDrightcut = plotHANDright;
			plotHANDrightcut += "_cut";
			cout << "Drawing " << titleHANDright << "..." << endl;
			TH1F *HANDright = new TH1F(plotHANDright,titleHANDright,TDCbins,TDCmin,TDCmax);
			HANDright->SetMinimum(0);
			TH1F *HANDrightcut = new TH1F(plotHANDrightcut,titleHANDright,TDCbins,TDCmin,TDCmax);
			HANDrightcut->SetMinimum(0);
			TString HANDrightTDC = goodTDCr;
			HANDrightTDC += ">>";
			HANDrightTDC += plotHANDright;
			TString HANDrightTDCcut = goodTDCr;
			HANDrightTDCcut += ">>";
			HANDrightTDCcut += plotHANDrightcut;
			chainHe->Draw(HANDrightTDC, cuts && vetoTDCs && firstTrack,"");
//			HANDright->Scale(1/(HeChargeScale*Helivetime));
			HANDright->Write();
			HANDright->Draw();
			if (!includeVetos) {chainHe->Draw(HANDrightTDCcut, cuts && firstTrack && goodTDCrightcut,"same");}
			if (includeVetos) {chainHe->Draw(HANDrightTDCcut, cuts && vetoTDCs && goodTDCrightcut && firstTrack,"same");}
			HANDrightcut->SetFillColor(kViolet);
//			HANDrightcut->Scale(1/(HeChargeScale*Helivetime));
			HANDrightcut->Write();
			HANDrightcut->Draw("same");
			// ********************************************************************************
			// This section below gathers and prints some statistics on the plot
			double numHANDrightcutEvents = 0;
			for (int j=0; j<TDCbins; j++){ numHANDrightcutEvents = numHANDrightcutEvents + HANDrightcut->GetBinContent(j);}
			TString HANDrightFactorsString = "Total Charge for Runs: ";
			HANDrightFactorsString += HeChargeScale;
			HANDrightFactorsString += " C";
			TString HANDrightFactorsString1 = "Total Livetime for Runs: ";
			HANDrightFactorsString1 += Helivetime;
			TString HANDrightFactorsString2 = "# of Cut (Purple) Events: ";
			HANDrightFactorsString2 += numHANDrightcutEvents;
			HANDrightFactors = new TPaveText(0.11,0.69,0.4,0.89,"NDC");
			TText *t1 = HANDrightFactors->AddText(HANDrightFactorsString);
			TText *t2 = HANDrightFactors->AddText(HANDrightFactorsString1);
			TText *t2 = HANDrightFactors->AddText(HANDrightFactorsString2);
			HANDrightFactors->Write();
			// ********************************************************************************
			handpad03->Update();

			handpad04->cd();
			cout << "Drawing Helicity Up vs. xBj..." << endl;
			TString titleSpinUpx = "Helicity Up vs. xBj for Plane #";
			titleSpinUpx += nplane;
			titleSpinUpx += ", PMT # ";
			titleSpinUpx += thisbar;
			if (includeVetos) {titleSpinUpx += " with vetos";}
			else {titleSpinUpx += " without vetos";}
			TString titleSpinUpxcut = titleSpinUpx;
			titleSpinUpxcut += " with goodTDC cuts";
			cout << "Drawing " << titleSpinUpx << "..." << endl;
			TString plotSpinUpx = "HANDSpinUpx_p";
			plotSpinUpx += nplane;
			plotSpinUpx += "_b";
			plotSpinUpx += thisbar;
			TH1F *HANDSpinUpx = new TH1F(plotSpinUpx,titleSpinUpxcut,nuBins,nuMin,nuMax);
			TString HANDSpinUpxString = "PriKineR.nu";
			HANDSpinUpxString += ">>";
			HANDSpinUpxString += plotSpinUpx;
			if (includeVetos) {chainHe->Draw(HANDSpinUpxString, cuts && vetoTDCs && goodTDCcut && firstTrack && "((g0hel.R.helicity==1 && g.runnum<22467) || (g0hel.R.helicity==-1 && g.runnum>22468))","");}
			if (!includeVetos) {chainHe->Draw(HANDSpinUpxString, cuts && firstTrack && goodTDCcut && "((g0hel.R.helicity==1 && g.runnum<22467) || (g0hel.R.helicity==-1 && g.runnum>22468))","");}
			HANDSpinUpx->SetMinimum(0);
			HANDSpinUpx->Write();
			HANDSpinUpx->Draw();
			handpad04->Update();

			handpad05->cd();
			cout << "Drawing Helicity Down vs. xBj..." << endl;
			TString titleSpinDownx = "Helicity Down vs. xBj for Plane #";
			titleSpinDownx += nplane;
			titleSpinDownx += ", PMT # ";
			titleSpinDownx += thisbar;
			if (includeVetos) {titleSpinDownx += " with vetos";}
			else {titleSpinDownx += " without vetos";}
			TString titleSpinDownxcut = titleSpinDownx;
			titleSpinDownxcut += " with goodTDC cuts";
			cout << "Drawing " << titleSpinDownx << "..." << endl;
			TString plotSpinDownx = "HANDSpinDownx_p";
			plotSpinDownx += nplane;
			plotSpinDownx += "_b";
			plotSpinDownx += thisbar;
			TH1F *HANDSpinDownx = new TH1F(plotSpinDownx,titleSpinDownxcut,nuBins,nuMin,nuMax);
			TString HANDSpinDownxString = "PriKineR.nu";
			HANDSpinDownxString += ">>";
			HANDSpinDownxString += plotSpinDownx;
			if (includeVetos) {chainHe->Draw(HANDSpinDownxString, cuts && vetoTDCs && goodTDCcut && firstTrack && "((g0hel.R.helicity==-1 && g.runnum<22467) || (g0hel.R.helicity==1 && g.runnum>22468))","");}
			if (!includeVetos) {chainHe->Draw(HANDSpinDownxString, cuts && firstTrack && goodTDCcut && "((g0hel.R.helicity==-1 && g.runnum<22467) || (g0hel.R.helicity==1 && g.runnum>22468))","");}
			HANDSpinDownx->SetMinimum(0);
			HANDSpinDownx->Write();
			HANDSpinDownx->Draw();
			handpad05->Update();

			handpad06->cd();
			cout << "Drawing Total Helicity Up vs. xBj..." << endl;
//			TString titleTotalSpinUpx = "Total Spin Up vs. xBj";
//			if (includeVetos) {titleTotalSpinUpx += " with vetos";}
//			else {titleTotalSpinUpx += " without vetos";}
//			titleTotalSpinUpx += " with goodTDC cuts";
//			cout << "Drawing " << titleTotalSpinUpx << "..." << endl;
//			TString plotTotalSpinUpx = "HANDTotalSpinUpx";
//			TH1F *HANDTotalSpinUpx = new TH1F(plotTotalSpinUpx,titleTotalSpinUpx,nuBins,nuMin,nuMax);
			HANDTotalSpinUpx->Add(HANDSpinUpx);
			HANDTotalSpinUpx->SetMinimum(0);
			HANDTotalSpinUpx->Write();
			HANDTotalSpinUpx->Draw();
			handpad06->Update();

			handpad07->cd();
			cout << "Drawing Total Helicity Down vs. xBj..." << endl;
//			TString titleTotalSpinDownx = "Total Spin Down vs. xBj";
//			if (includeVetos) {titleTotalSpinDownx += " with vetos";}
//			else {titleTotalSpinDownx += " without vetos";}
//			titleTotalSpinDownx += " with goodTDC cuts";
//			cout << "Drawing " << titleTotalSpinDownx << "..." << endl;
//			TString plotTotalSpinDownx = "HANDTotalSpinDownx";
//			TH1F *HANDTotalSpinDownx = new TH1F(plotTotalSpinDownx,titleTotalSpinDownx,nuBins,nuMin,nuMax);
			HANDTotalSpinDownx->Add(HANDSpinDownx);
			HANDTotalSpinDownx->SetMinimum(0);
			HANDTotalSpinDownx->Write();
			HANDTotalSpinDownx->Draw();
			handpad07->Update();




			TString imageTitle = outputPlotsHere;
			imageTitle += "TDC_plots_for_beam_asym_Run_Num_";
			imageTitle += HeRunNumber;
			imageTitle += "-";
			imageTitle += endHeRunNumber;
			imageTitle += "_p";
			imageTitle += nplane;
			imageTitle += "_b";
			if (thisbar < 10) {imageTitle += "0";}
			imageTitle += thisbar;
			if (includeVetos) {imageTitle += "_with_vetos";}
			if (includeAntivetos) {imageTitle += "_with_antivetos";}
			if (antivetosAsVetos && includeAntivetos) {imageTitle += "_as_vetos";}
			imageTitle+= ".png";
			handCanvas->Print(imageTitle);

			TString imageAntivetosTitle = outputPlotsHere;
			imageAntivetosTitle += "antivetos_for_beam_asym_for_Run_Num_";
			imageAntivetosTitle += HeRunNumber;
			imageAntivetosTitle += "-";
			imageAntivetosTitle += endHeRunNumber;
			imageAntivetosTitle += "_p";
			imageAntivetosTitle += nplane;
			imageAntivetosTitle += "_b";
			imageAntivetosTitle += thisbar;
			if (includeVetos) {imageAntivetosTitle += "_with_vetos";}
			if (includeAntivetos) {imageAntivetosTitle += "_with_antivetos";}
			if (antivetosAsVetos && includeAntivetos) {imageAntivetosTitle += "_as_vetos";}
			imageAntivetosTitle += ".png";

			if (includeAntivetos) {hand_draw_antivetos(antiveto1plane, antiveto1bar, antiveto2plane, antiveto2bar, antiveto3plane, antiveto3bar, HeRunNumber, endHeRunNumber, chainHe, TDCbins, TDCmin, TDCmax, cuts, goodTDCcut, vetoTDCs, imageAntivetosTitle, nplane, thisbar, includeVetos, includeAntivetos, antivetosAsVetos, veto1plane, veto1bar, veto2plane, veto2bar, veto3plane, veto3bar, veto4plane, veto4bar, veto5plane, veto5bar, veto6plane, veto6bar, allVetos, allAntivetos);}

// *********************************************************************************************************
// The section below will plot the bars used for vetos for the previous canvas. It will consist of two
// canvases, one without the veto cuts made and one with to show the different.
			TString imageVetosWithoutVetosTitle = outputPlotsHere;
			imageVetosWithoutVetosTitle += "vetos_without_veto_cut_for_beam_asym_for_Run_Num_";
			imageVetosWithoutVetosTitle += HeRunNumber;
			imageVetosWithoutVetosTitle += "-";
			imageVetosWithoutVetosTitle += endHeRunNumber;
			imageVetosWithoutVetosTitle += "_p";
			imageVetosWithoutVetosTitle += nplane;
			imageVetosWithoutVetosTitle += "_b";
			imageVetosWithoutVetosTitle += thisbar;
			if (includeVetos) {imageVetosWithoutVetosTitle += "_with_vetos";}
			if (includeAntivetos) {imageVetosWithoutVetosTitle += "_with_antivetos";}
			if (antivetosAsVetos && includeAntivetos) {imageVetosWithoutVetosTitle += "_as_vetos";}
			imageVetosWithoutVetosTitle+= ".png";

			TString imageVetosWithVetosTitle = outputPlotsHere;
			imageVetosWithVetosTitle += "vetos_with_veto_cut_for_beam_asym_Run_Num_";
			imageVetosWithVetosTitle += HeRunNumber;
			imageVetosWithVetosTitle += "-";
			imageVetosWithVetosTitle += endHeRunNumber;
			imageVetosWithVetosTitle += "_p";
			imageVetosWithVetosTitle += nplane;
			imageVetosWithVetosTitle += "_b";
			imageVetosWithVetosTitle += thisbar;
			if (includeVetos) {imageVetosWithVetosTitle += "_with_vetos";}
			if (includeAntivetos) {imageVetosWithVetosTitle += "_with_antivetos";}
			if (antivetosAsVetos && includeAntivetos) {imageVetosWithVetosTitle += "_as_vetos";}
			imageVetosWithVetosTitle+= ".png";

//			if (includeVetos) {hand_draw_vetos(veto1plane, veto2plane, veto3plane, veto4plane, veto5plane, veto6plane,veto1bar, veto2bar, veto3bar, veto4bar, veto5bar, veto6bar, imageVetosWithoutVetosTitle, imageVetosWithVetosTitle, HeRunNumber, endHeRunNumber, chainHe, nplane, thisbar, TDCbins, TDCmin, TDCmax, cuts, vetoTDCs, antivetosAsVetos, allVetos, allAntivetos);}

//		if ((nplane==1) && (thisbar==15)) { nplane = 2; thisbar = 7;}
//		if ((nplane==2) && (thisbar==12)) { nplane = 3; thisbar = 6;}
//		if ((nplane==3) && (thisbar==11)) { nplane = 4; thisbar = 3;}
//		if ((nplane==4) && (thisbar==7))  { nplane = 4; thisbar = 99;}


		}
	}

	TString canvasTotalSpinTest = "TotalSpinTest";
	TString canvasTitleTotalSpinTest = "HAND - Total Spin (Not Scaled)";
	TCanvas *totalSpinTestCanvas = new TCanvas(canvasTotalSpinTest,canvasTitleTotalSpinTest,1400,770); //x,y
	totalspintestpad01 =  new TPad("totalspintestpad01","totalspintestpad01",0.0000,0.5000,0.5000,1.0000,0,0,0);
	totalspintestpad02 =  new TPad("totalspintestpad02","totalspintestpad02",0.5000,0.5000,1.0000,1.0000,0,0,0);
	totalspintestpad03 =  new TPad("totalspintestpad03","totalspintestpad03",0.0000,0.0000,1.0000,0.5000,0,0,0);
	totalspintestpad01->Draw(); totalspintestpad02->Draw(); totalspintestpad03->Draw();

	totalspintestpad01->cd();
	HANDTotalSpinUpx->SetTitle("Total Spin Up (Not Scaled)");
	HANDTotalSpinUpx->Write();
	HANDTotalSpinUpx->Draw();
	totalspintestpad01->Update();

	totalspintestpad02->cd();
	HANDTotalSpinDownx->SetTitle("Total Spin Down (Not Scaled)");
	HANDTotalSpinDownx->Write();
	HANDTotalSpinDownx->Draw();
	totalspintestpad02->Update();

	totalspintestpad03->cd();
        TF1 *fitasymtest = new TF1("fitasymtest","[0]",nuMin,nuMax);
	HANDAsymTest = HANDTotalSpinUpx->GetAsymmetry(HANDTotalSpinDownx);
	TString AsymTestTitle = "Target Asymmerty with Neutron Cuts vs. xBj for runs ";
	AsymTestTitle += HeRunNumber;
	AsymTestTitle += "-";
	AsymTestTitle += endHeRunNumber;
	HANDAsymTest->SetTitle(AsymTestTitle);
	HANDAsymTest->Write();
	HANDAsymTest->Draw();
        fitasymtest->SetLineColor(kBlue);
        HANDAsymTest->Fit("fitasymtest","R");
	totalspintestpad03->Update();


	TString asymTitle = "Target Asymmetry for Runs ";
	asymTitle += HeRunNumber;
	asymTitle += "-";
	asymTitle += endHeRunNumber;
	TCanvas *asymCanvas = new TCanvas("asymCanvas",asymTitle,1400,770); //x,y
	asymCanvas->cd();
	asymCanvas->SetGrid();
	Double_t x[nuBins], y[nuBins], errorx[nuBins], errory[nuBins];
	double minError;
	double maxError;
	double posStuff;
	double negStuff;
	double UpEvents;
	double DownEvents;
	asymOutFile << "Runs " << HeRunNumber << "-" << endHeRunNumber << endl;
	cout << "Runs " << HeRunNumber << "-" << endHeRunNumber << endl;
	asymOutFile << "xBj	Asymmetry	Stat. Error	# BeamPos Events	BeamPos Charge	PosBeam LT	# Neg Events	BeamNeg Charge	NegBeam LT" << endl;
	cout << "xBj	Asymmetry	Stat. Error	# BeamPos Events	BeamPos Charge	PosBeam LT	# Neg Events	BeamNeg Charge	NegBeam LT" << endl;
	for (int i=0; i<nuBins; i++)
	{	
		UpEvents = HANDTotalSpinUpx->GetBinContent(i);
		DownEvents = HANDTotalSpinDownx->GetBinContent(i);
		x[i] = HANDTotalSpinUpx->GetBinCenter(i);
		if (x[i] != (HANDTotalSpinDownx->GetBinCenter(i))) { cout << endl << endl << "!!!!!!!!!!!!!!!!!!!!!!!!!! STOP! THERE'S A PROBLEM!!!!!!!!!!!!!!!!!!!!!!" << endl << endl << endl;}
		posStuff = UpEvents/(BeamChargeScaleUp * BeamlivetimeUp + 1e-15);
		negStuff = DownEvents/(BeamChargeScaleDown * BeamlivetimeDown + 1e-15);
		y[i] = ((posStuff - negStuff)/(posStuff + negStuff + 1e-15));
		errory[i] = 2*(DownEvents*sqrt(UpEvents) + UpEvents*sqrt(DownEvents))/((BeamChargeScaleUp*BeamlivetimeUp)*(BeamChargeScaleDown*BeamlivetimeDown)*pow((UpEvents/(BeamChargeScaleUp*BeamlivetimeUp)) + (DownEvents/(BeamChargeScaleDown*BeamlivetimeDown)),2) + 1e-15);
		if ((UpEvents == 0) || (DownEvents == 0)) { errory[i] = 1;}
		if ((UpEvents == 0) || (DownEvents == 0)) { y[i] = NULL;}
		if (i==0)
		{
			minError = y[i] - 2*errory[i];
			maxError = y[i] + 2*errory[i];
		}
		if ((y[i] - 2*errory[i]) < minError) { minError = y[i] - 2*errory[i];}
		if ((y[i] + 2*errory[i]) > maxError) { maxError = y[i] + 2*errory[i];}
		errorx[i] = ((nuMax - nuMin)/nuBins)/2;
		asymOutFile << x[i] << "	" << y[i] << "	" << errory[i] << "	" << UpEvents << "	" << BeamChargeScaleUp << "	" << BeamlivetimeUp << "	" << DownEvents << "	" << BeamChargeScaleDown << "	" << BeamlivetimeDown << endl;
		cout << x[i] << "	" << y[i] << "	" << errory[i] << "	" << UpEvents << "	" << BeamChargeScaleUp << "	" << BeamlivetimeUp << "	" << DownEvents << "	" << BeamChargeScaleDown << "	" << BeamlivetimeDown << endl;
	}
	asymGraph = new TGraphErrors(nuBins, x, y, errorx, errory);
	asymGraph->SetMarkerStyle(21);
	asymGraph->SetMarkerColor(4);
	asymGraph->SetTitle(asymTitle);
	asymTestHist = new TH2F("asymTestHist",asymTitle,nuBins,nuMin,nuMax,100,minError,maxError);
	asymTestHist->SetStats(kFALSE);
	asymTestHist->Write();
	asymTestHist->Draw();
	cout << "Fit min = " << nuMin << "; Fit max = " << nuMax << endl;
	TF1 *fitAsymGraph = new TF1("fitAsymGraph", "[0]", nuMin, nuMax);
	asymGraph->Draw("P");
	fitAsymGraph->SetLineColor(kBlue);
	asymGraph->Fit("fitAsymGraph","R");
	asymGraph->Write();
	asymCanvas->Update();

	TString TotalAsymOutTitle = outputPlotsHere;
	TotalAsymOutTitle += "target_asymmetry_good_for_Run_Num_";
	TotalAsymOutTitle += HeRunNumber;
	TotalAsymOutTitle += "-";
	TotalAsymOutTitle += endHeRunNumber;
	if (includeVetos) {TotalAsymOutTitle += "_with_vetos";}
	if (includeAntivetos) {TotalAsymOutTitle += "_with_antivetos";}
	if (antivetosAsVetos && includeAntivetos) {TotalAsymOutTitle += "_as_vetos";}
	TotalAsymOutTitle += ".png";
	asymCanvas->Print(TotalAsymOutTitle);



	TString canvasTotalSpin = "TotalSpin";
	TString canvasTitleTotalSpin = "HAND - Total Spin";
	TCanvas *totalSpinCanvas = new TCanvas(canvasTotalSpin,canvasTitleTotalSpin,1400,770); //x,y
	totalspinpad01 =  new TPad("totalspinpad01","totalspinpad01",0.0000,0.5000,0.5000,1.0000,0,0,0);
	totalspinpad02 =  new TPad("totalspinpad02","totalspinpad02",0.5000,0.5000,1.0000,1.0000,0,0,0);
	totalspinpad03 =  new TPad("totalspinpad03","totalspinpad03",0.0000,0.0000,1.0000,0.5000,0,0,0);
	totalspinpad01->Draw(); totalspinpad02->Draw(); totalspinpad03->Draw();

	totalspinpad01->cd();
	cout << "HeChargeScaleUp: " << HeChargeScaleUp << "   HelivetimeUp: " << HelivetimeUp << endl;
	HANDTotalSpinUpx->Scale(1/(BeamChargeScaleUp * BeamlivetimeUp));
	HANDTotalSpinUpx->SetTitle("Total Spin Up (Scaled by Charge, LT)");
	HANDTotalSpinUpx->Write();
	HANDTotalSpinUpx->Draw();
	// ********************************************************************************
	// This section below gathers and prints some statistics on the plot
	TString HANDUpFactorsString = "Total Positive Charge for Runs: ";
	HANDUpFactorsString += BeamChargeScaleUp;
	HANDUpFactorsString += " C";
	TString HANDUpFactorsString1 = "Total Positive Livetime for Runs: ";
	HANDUpFactorsString1 += BeamlivetimeUp;
	HANDUpFactors = new TPaveText(0.11,0.69,0.4,0.89,"NDC");
	TText *t1 = HANDUpFactors->AddText(HANDUpFactorsString);
	TText *t2 = HANDUpFactors->AddText(HANDUpFactorsString1);
	HANDUpFactors->Write();
	HANDUpFactors->Draw("same");
	// ********************************************************************************
	totalspinpad01->Update();

	totalspinpad02->cd();
	cout << "HeChargeScaleDown: " << HeChargeScaleDown << "   HelivetimeDown: " << HelivetimeDown << endl;
	HANDTotalSpinDownx->Scale(1/(BeamChargeScaleDown * BeamlivetimeDown));
	HANDTotalSpinDownx->SetTitle("Total Spin Down (Scaled by Charge, LT)");
	HANDTotalSpinDownx->Write();
	HANDTotalSpinDownx->Draw();
	// ********************************************************************************
	// This section below gathers and prints some statistics on the plot
	TString HANDDownFactorsString = "Total Negative Charge for Runs: ";
	HANDDownFactorsString += BeamChargeScaleDown;
	HANDDownFactorsString += " C";
	TString HANDDownFactorsString1 = "Total Negative Livetime for Runs: ";
	HANDDownFactorsString1 += BeamlivetimeDown;
	HANDDownFactors = new TPaveText(0.11,0.69,0.4,0.89,"NDC");
	TText *t1 = HANDDownFactors->AddText(HANDDownFactorsString);
	TText *t2 = HANDDownFactors->AddText(HANDDownFactorsString1);
	HANDDownFactors->Write();
	HANDDownFactors->Draw("same");
	// ********************************************************************************
	totalspinpad02->Update();

	totalspinpad03->cd();
        TF1 *fitasym = new TF1("fitasym","[0]",nuMin,nuMax);
	HANDAsym = HANDTotalSpinUpx->GetAsymmetry(HANDTotalSpinDownx);
	TString AsymTitle = "Target Asymmerty (Scaled by Charge, LT) with Neutron Cuts vs. xBj for runs ";
	AsymTitle += HeRunNumber;
	AsymTitle += "-";
	AsymTitle += endHeRunNumber;
	HANDAsym->SetTitle(AsymTitle);
	HANDAsym->Write();
	HANDAsym->Draw();
        fitasym->SetLineColor(kBlue);
        HANDAsym->Fit("fitasym","R");
	totalspinpad03->Update();

	TString TotalSpinOutTitle = outputPlotsHere;
	TotalSpinOutTitle += "target_asymmetry_for_Run_Num_";
	TotalSpinOutTitle += HeRunNumber;
	TotalSpinOutTitle += "-";
	TotalSpinOutTitle += endHeRunNumber;
	if (includeVetos) {TotalSpinOutTitle += "_with_vetos";}
	if (includeAntivetos) {TotalSpinOutTitle += "_with_antivetos";}
	if (antivetosAsVetos && includeAntivetos) {TotalSpinOutTitle += "_as_vetos";}
	TotalSpinOutTitle += ".png";
	totalSpinCanvas->Print(TotalSpinOutTitle);


	asymOutFile.close();

	outputRoot1->Close();

	cout << "All done!" << endl;



}
Beispiel #30
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");

  */
	
}