Пример #1
1
 // Note: Mean is not really mean
 float randomUniform(float lowestValue,float range=1.0)
 {
     TRandom1 *randomGenerator = new TRandom1();
     return (randomGenerator->Rndm()*range) + lowestValue;
 }
Пример #2
0
void PEs(RooAbsPdf *iGen,RooAbsPdf *iFit,int iN,int iNEvents,RooRealVar &iVar,RooRealVar &iSig,RooRealVar &iMean,
	 RooRealVar &iScale,RooRealVar &iRes) { 
  double iM0 = iMean.getVal(); double iS0 = iSig.getVal();
  //iScale.setVal(iMeanScale); iRes.setVal(iSigScale);
  TRandom1 *lRand = new TRandom1(0xDEADBEEF);
  TNtuple * lDN= new TNtuple( "xxx","xxx","ntot:m_r:m:merr:sig_r:sig:sigerr");
  for(int i0=0;i0<iN;i0++){
    if(i0 % 10 == 0) cout << "+++++++++++++++++++++++++++ running ======> " << i0 << endl;
    int lN    = lRand->Poisson(iNEvents);
    RooDataSet * lSignal  = iGen->generate(iVar,lN);
    iMean.setVal(iM0); iSig.setVal(iS0);
    iFit->fitTo(*lSignal,Strategy(1));//,Save(kTRUE),PrintLevel(1));
    if(iMean.getError() < 0.05) iFit->fitTo(*lSignal,Strategy(2));
    Float_t values[]={
      (Float_t) lN,
      (Float_t) 90.78/iScale.getVal(),
      (Float_t) iMean.getVal(),
      (Float_t) iMean.getError(),
      (Float_t) iSig.getVal(),
      (Float_t) iSig.getVal(),
      (Float_t) iSig.getError()
    };
    lDN->Fill(values);
  }
  TFile *lF = new TFile("XXX.root","RECREATE");
  lDN->Write();
  lF->Close();
}
Пример #3
0
void CompareGammaPoisson(float N=100)
{ 

    gStyle->SetOptStat(111111110);
    gStyle->SetStatW(0.3);                
    gStyle->SetStatH(0.25);                

    TRandom1 *frand = new TRandom1();
    TRandom3 rand(1234); // gamma

    int Nbins = (int)(N+TMath::Sqrt(N)*10);

    TH1F *hpoisson    = new TH1F("hpoisson",    "Poisson",   Nbins, -0.5,  Nbins-0.5);
    TH1F *hgamma      = new TH1F("hgamma",      "Gamma",     Nbins, -0.5,  Nbins-0.5);
    hpoisson->Sumw2();
    hgamma->Sumw2();

    for(int i=0; i<Npseudo; i++)  
    { 
        int checkpoint = (int)Npseudo/10;
        //if((i%checkpoint)==0) cout << "Generated " << i << "/" << Npseudo << " experiments " << endl;
        
        float Npoisson      = frand->Poisson(N);
        float Ngamma        = gsl_ran_gamma(2*N+1,0.5,rand);;

        hpoisson->Fill(Npoisson);
        hgamma->Fill(Ngamma);

    }
    hpoisson->Scale(1./hpoisson->Integral());
    hgamma->Scale(1./hgamma->Integral());

    h1cosmetic(hpoisson, Form("Poisson(black) and Gamma(red), N=%i",(int)N), kBlack, 3, 0, "");
    h1cosmetic(hgamma,   "Gamma", kRed, 3, 0, "");

    TCanvas *c = new TCanvas("c","c",400,400);
    c->cd(1);
    hpoisson->SetMaximum(hpoisson->GetMaximum()>hgamma->GetMaximum()?hpoisson->GetMaximum()*1.2:hgamma->GetMaximum()*1.2);
    hpoisson->Draw("HIST");
    hgamma->Draw("HIST SAME");
    c->Print(Form("fig/ComparePoissonGamma_N%i.pdf", (int)N));
}
Пример #4
0
void BiasStudy_Spectrum()
{
	/// Number of Events ///
	
	double progress = 0;

	/// Dijet Mass Binning ///
	int number_of_variableWidth_bins = 88 - 1;
	Double_t massBins[88] = {1, 3, 6, 10, 16, 23, 31, 40, 50, 61, 74, 88, 103, 119, 137, 156, 176, 197, 220, 244, 270, 296, 325, 354, 386, 419, 453, 489, 526, 565, 606, 649,  693, 740, 788, 838, 890, 944, 1000, 1058, 1118, 1181, 1246, 1313, 1383, 1455, 1530, 1607, 1687, 1770, 1856, 1945, 2037, 2132, 2231, 2332, 2438, 2546, 2659, 2775, 2895, 3019, 3147, 3279, 3416, 3558, 3704, 3854, 4010, 4171, 4337, 4509, 4686, 4869, 5058, 5253, 5455, 5663, 5877, 6099, 6328, 6564, 6808, 7000, 7250,7500,7750,8000}; 
	Double_t mass_low  = 354.;
	Double_t mass_high = 5455.;
	int N = mass_high-mass_low;
	cout << N << endl;

	/// Get Fit Functions ///
	TF1 *func_type1;
	TFile *file_type1 = TFile::Open("../FisherStudies/dijetFitResults_FuncType1_nParFit5_Run2012BCD.root");
	func_type1 = (TF1*)file_type1->FindObjectAny("M1Bkg")->Clone("M1Bkg_func_type_1");
	func_type1->SetLineColor(kRed);
	func_type1->SetNpx(5000);

	TF1 *func_type2;
	TFile *file_type2 = TFile::Open("../FisherStudies/dijetFitResults_FuncType5_nParFit6_Run2012BCD.root");
	func_type2 = (TF1*)file_type2->FindObjectAny("M1Bkg")->Clone("M1Bkg_func_type_2");
	func_type2->SetLineColor(kBlue);
	func_type2->SetNpx(5000);

	/// Generate PseudoExperiments ///
	TFile* generated_spectra= new TFile("generated_spectra.root", "RECREATE");
	Double_t mjj;
	Double_t mjj_y;


	//TH1F *gen_type1 = new TH1F("Generated_by_Type_1_Function","Generated_by_Type_1_Function", number_of_variableWidth_bins, massBins);
	TH1F *gen_type1 = new TH1F("Generated_by_Type_1_Function","Generated_by_Type_1_Function", N, mass_low, mass_high);
	//gen_type1->Sumw2();

	//TH1F *gen_type2 = new TH1F("Generated_by_Type_2_Function","Generated_by_Type_2_Function", number_of_variableWidth_bins, massBins);
	TH1F *gen_type2 = new TH1F("Generated_by_Type_2_Function","Generated_by_Type_2_Function", N, mass_low, mass_high);	
	//gen_type2->Sumw2();

	/// Generate by type 1 ///
	for (int i = 0; i < N; ++i)
	{
		progress = 100.0*i/(1.0*N);
	    int k = TMath::FloorNint(progress);
	    std::cout << "\r" << "Generating by type 1: " << k << "% completed: " << "[" << std::string(k, '|') << std::string(99-k, ' ') << "]";
		std::cout.flush();
		TRandom1* r = new TRandom1();
		mjj_y = func_type1->Integral(mass_low+i, mass_low+i+1);
		//mjj_y = func_type1->Eval(mass_low+i+0.5);
		//mjj = GetRand(func_type1, mass_low, mass_high, r->Integer(1e+10));
		gen_type1->SetBinContent(i+1, r->Poisson(mjj_y));
		gen_type1->SetBinError(i+1, TMath::Sqrt(gen_type1->GetBinContent(i+1)));
		cout << mjj_y << "\t" <<gen_type1->GetBinLowEdge(i+1) << "\t"<< gen_type1->GetBinContent(i+1) << endl;
		//mjj = func_type1->GetRandom(2000., mass_high);
		//gen_type1->Fill(mjj);

		mjj_y = func_type2->Integral(mass_low+i, mass_low+i+1);
		//mjj = GetRand(func_type1, mass_low, mass_high, r->Integer(1e+10));
		gen_type2->SetBinContent(i+1, r->Poisson(mjj_y));
		gen_type2->SetBinError(i+1, TMath::Sqrt(gen_type2->GetBinContent(i+1)));
	}

	TCanvas *Canvas0 = new TCanvas("Canvas0","Canvas0");
	gen_type1->Draw("E");
	func_type1->Draw("SAME");
	gen_type1->GetXaxis()->SetRangeUser(mass_low-100, mass_high+100);
	gen_type1->GetXaxis()->SetMoreLogLabels();
	gen_type1->GetXaxis()->SetNoExponent();
	gPad->SetLogx();
	gPad->SetLogy();

	TCanvas *Canvas1 = new TCanvas("Canvas1","Canvas1");
	gen_type2->Draw("E");
	func_type2->Draw("SAME");
	gen_type2->GetXaxis()->SetRangeUser(mass_low-100, mass_high+100);
	gen_type2->GetXaxis()->SetMoreLogLabels();
	gen_type2->GetXaxis()->SetNoExponent();
	gPad->SetLogx();
	gPad->SetLogy();

	generated_spectra->cd();
	gen_type1->Write();
	gen_type2->Write();
}
Пример #5
0
double ROOTRndm(int dummy){
  return rr.Rndm();
}
Пример #6
0
int ScanChain( TChain* chain, bool fast = true, int nEvents = -1, string skimFilePrefix = "test") {

  // Benchmark
  TBenchmark *bmark = new TBenchmark();
  bmark->Start("benchmark");
////////////////////////////////////////////////////////////////////////////////////////////
int mt2_l_bin = 0;
int mt2_h_bin = 200;
int mt2_n_bin = 20;

int mt_l_bin = 0;
int mt_h_bin = 300;
int mt_n_bin = 30;

int met_l_bin = 0;
int met_h_bin = 225;
int met_n_bin = 45;

int jet_n_bin = 10;
int jet_h_bin = 10;

	TH1F   *fake_wpt_h = new TH1F("fake_w_pt_","fake_W_pt",50,0,100);
	TH1F   *landau_h = new TH1F("landau_h_","landau_H",60,0,mt_h_bin);
	TH1F   *gammaM_h = new TH1F("gammaM_","gamma",120,1,6);

	TH1F *mt2_h_data = new TH1F("mt2_data_","MT2_data",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_data = new  TH1F("mt_data_", "MT_data",mt_n_bin,0,mt_h_bin);
	TH1F   *met_data = new TH1F("met_data_","met_data",met_n_bin,0,met_h_bin);
	TH1F   *jets_data= new TH1F("jets_data_","Jets_data",jet_n_bin,0,jet_h_bin);
	TH1F   *data_w_pt = new     TH1F("data_w_pt_","data_W_pt",60,0,mt_h_bin);
	TH1F   *data_lep_pt = new     TH1F("data_lep_pt_","data_Lep_pt",60,0,mt_h_bin);

	TH1F *mt2_h_ttbar = new TH1F("mt2_ttbar_","MT2_ttbar",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_ttbar = new  TH1F("mt_ttbar_", "MT_ttbar",mt_n_bin,0,mt_h_bin);
	TH1F   *met_ttbar = new TH1F("met_ttbar_","met_ttbar",met_n_bin,0,met_h_bin);
	TH1F   *jets_ttbar  = new TH1F("jets_ttbar_","Jets_ttbar",jet_n_bin,0,jet_h_bin);
	TH1F   *ttbar_w_pt = new     TH1F("ttbar_w_pt_","ttbar_W_pt",60,0,mt_h_bin);
	TH1F   *ttbar_lep_pt = new     TH1F("ttbar_lep_pt_","ttbar_Lep_pt",60,0,mt_h_bin);

	TH1F *mt2_h_wjets = new TH1F("mt2_wjets_","MT2_wjets",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_wjets = new  TH1F("mt_wjets_", "MT_wjets",mt_n_bin,0,mt_h_bin);
	TH1F   *met_wjets = new TH1F("met_wjets_","met_wjets",met_n_bin,0,met_h_bin);
	TH1F   *jets_wjets  = new TH1F("jets_wjets_","Jets_wjets",jet_n_bin,0,jet_h_bin);
	TH1F   *wjets_w_pt = new     TH1F("wjets_w_pt_","wjets_W_pt",60,0,mt_h_bin);
	TH1F   *wjets_lep_pt = new     TH1F("wjets_lep_pt_","wjets_Lep_pt",60,0,mt_h_bin);

	wjets_lep_pt->SetLineColor(kRed);
	data_lep_pt->SetLineColor(kYellow);
	ttbar_lep_pt->SetLineColor(kCyan);

	wjets_lep_pt->SetLineWidth(4);
	 data_lep_pt->SetLineWidth(4);
	ttbar_lep_pt->SetLineWidth(4);

////MUONS////
	TH1F *mt2_h_data_mu = new TH1F("mt2_data_mu_","MT2_data_mu",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_data_mu = new  TH1F("mt_data_mu_", "MT_data_mu",mt_n_bin,0,mt_h_bin);
	TH1F   *met_data_mu = new TH1F("met_data_mu_","met_data_mu",met_n_bin,0,met_h_bin);
	TH1F   *jets_data_mu= new TH1F("jets_data_mu_","Jets_data_mu",jet_n_bin,0,jet_h_bin);
	TH1F   *data_w_pt_mu = new     TH1F("data_w_pt_mu_","data_W_pt_mu",60,0,mt_h_bin);
	TH1F   *data_lep_pt_mu = new     TH1F("data_lep_pt_mu_","data_Lep_pt_mu",60,0,mt_h_bin);

	TH1F *mt2_h_ttbar_mu = new TH1F("mt2_ttbar_mu_","MT2_ttbar_mu",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_ttbar_mu = new  TH1F("mt_ttbar_mu_", "MT_ttbar_mu",mt_n_bin,0,mt_h_bin);
	TH1F   *met_ttbar_mu = new TH1F("met_ttbar_mu_","met_ttbar_mu",met_n_bin,0,met_h_bin);
	TH1F   *jets_ttbar_mu  = new TH1F("jets_ttbar_mu_","Jets_ttbar_mu",jet_n_bin,0,jet_h_bin);
	TH1F   *ttbar_w_pt_mu = new     TH1F("ttbar_w_pt_mu_","ttbar_W_pt_mu",60,0,mt_h_bin);
	TH1F   *ttbar_lep_pt_mu = new     TH1F("ttbar_lep_pt_mu_","ttbar_Lep_pt_mu",60,0,mt_h_bin);

	TH1F *mt2_h_wjets_mu = new TH1F("mt2_wjets_mu_","MT2_wjets_mu",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_wjets_mu = new  TH1F("mt_wjets_mu_", "MT_wjets_mu",mt_n_bin,0,mt_h_bin);
	TH1F   *met_wjets_mu = new TH1F("met_wjets_mu_","met_wjets_mu",met_n_bin,0,met_h_bin);
	TH1F   *jets_wjets_mu  = new TH1F("jets_wjets_mu_","Jets_wjets_mu",jet_n_bin,0,jet_h_bin);
	TH1F   *wjets_w_pt_mu = new     TH1F("wjets_w_pt_mu_","wjets_W_pt_mu",60,0,mt_h_bin);
	TH1F   *wjets_lep_pt_mu = new     TH1F("wjets_lep_pt_mu_","wjets_Lep_pt_mu",60,0,mt_h_bin);

////ELECTRONS////
	TH1F *mt2_h_data_el = new TH1F("mt2_data_el_","MT2_data_el",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_data_el = new  TH1F("mt_data_el_", "MT_data_el",mt_n_bin,0,mt_h_bin);
	TH1F   *met_data_el = new TH1F("met_data_el_","met_data_el",met_n_bin,0,met_h_bin);
	TH1F   *jets_data_el= new TH1F("jets_data_el_","Jets_data_el",jet_n_bin,0,jet_h_bin);
	TH1F   *data_w_pt_el = new     TH1F("data_w_pt_el_","data_W_pt_el",60,0,mt_h_bin);
	TH1F   *data_lep_pt_el = new     TH1F("data_lep_pt_el_","data_Lep_pt_el",60,0,mt_h_bin);

	TH1F *mt2_h_ttbar_el = new TH1F("mt2_ttbar_el_","MT2_ttbar_el",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_ttbar_el = new  TH1F("mt_ttbar_el_", "MT_ttbar_el",mt_n_bin,0,mt_h_bin);
	TH1F   *met_ttbar_el = new TH1F("met_ttbar_el_","met_ttbar_el",met_n_bin,0,met_h_bin);
	TH1F   *jets_ttbar_el  = new TH1F("jets_ttbar_el_","Jets_ttbar_el",jet_n_bin,0,jet_h_bin);
	TH1F   *ttbar_w_pt_el = new     TH1F("ttbar_w_pt_el_","ttbar_W_pt_el",60,0,mt_h_bin);
	TH1F   *ttbar_lep_pt_el = new     TH1F("ttbar_lep_pt_el_","ttbar_Lep_pt_el",60,0,mt_h_bin);

	TH1F *mt2_h_wjets_el = new TH1F("mt2_wjets_el_","MT2_wjets_el",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_wjets_el = new  TH1F("mt_wjets_el_", "MT_wjets_el",mt_n_bin,0,mt_h_bin);
	TH1F   *met_wjets_el = new TH1F("met_wjets_el_","met_wjets_el",met_n_bin,0,met_h_bin);
	TH1F   *jets_wjets_el  = new TH1F("jets_wjets_el_","Jets_wjets_el",jet_n_bin,0,jet_h_bin);
	TH1F   *wjets_w_pt_el = new     TH1F("wjets_w_pt_el_","wjets_W_pt_el",60,0,mt_h_bin);
	TH1F   *wjets_lep_pt_el = new     TH1F("wjets_lep_pt_el_","wjets_Lep_pt_el",60,0,mt_h_bin);
/*
  TFile* f1 = new TFile("/home/users/sanil/single/may15hists/data_w_pt.root");
  TH1F* wp_dist   = (TH1F*) f1->Get("w_pt_"); // 
  f1->Close();
	TH1F *mt2_h_wwjets = new TH1F("mt2_wwjets_","MT2_wwjets",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_wwjets = new  TH1F("mt_wwjets_", "MT_wwjets",mt_n_bin,0,mt_h_bin);
	TH1F   *met_wwjets = new TH1F("met_wwjets_","met_wwjets",met_n_bin,0,met_h_bin);
	TH1F   *jets_wwjets = new TH1F("jets_wwjets_","Jets_wwjets",jet_n_bin,0,jet_h_bin);

	TH1F *mt2_h_ttwjets = new TH1F("mt2_ttwjets_","MT2_ttwjets",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_ttwjets = new  TH1F("mt_ttwjets_", "MT_ttwjets",mt_n_bin,0,mt_h_bin);
	TH1F   *met_ttwjets = new TH1F("met_ttwjets_","met_ttwjets",met_n_bin,0,met_h_bin);

	TH1F *mt2_h_ttzjets = new TH1F("mt2_ttzjets_","MT2_ttzjets",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_ttzjets = new  TH1F("mt_ttzjets_", "MT_ttzjets",mt_n_bin,0,mt_h_bin);
	TH1F   *met_ttzjets = new TH1F("met_ttzjets_","met_ttzjets",met_n_bin,0,met_h_bin);

	TH1F *mt2_h_dy = new TH1F("mt2_dy_","MT2_dy",mt2_n_bin,0,mt2_h_bin);
	TH1F  *mt_h_dy = new  TH1F("mt_dy_", "MT_dy",mt_n_bin,0,mt_h_bin);
	TH1F   *met_dy = new TH1F("met_dy_","met_dy",met_n_bin,0,met_h_bin);
*/


////////////// RANDOM NUMBERS GET W momentum


TRandom1  d;  
TRandom3 rx;
TRandom3 ry;

//mt2_h_data->Sumw2();
//mt_h_data ->Sumw2();
//met_data  ->Sumw2();

/////////////////////////////////////////////////////////////////////////////////////////////
  // Loop over events to Analyze
  unsigned int nEventsTotal = 0;
  unsigned int nEventsChain = chain->GetEntries();
  if( nEvents >= 0 ) nEventsChain = nEvents;
  TObjArray *listOfFiles = chain->GetListOfFiles();
  TIter fileIter(listOfFiles);
  TFile *currentFile = 0;
typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVec;
//GLOBAL COUNTERS//
int file_count = 1;

  // File Loop
  while ( (currentFile = (TFile*)fileIter.Next()) ) {

float mt2_0_counter = 0, //0 bin counter
     mt2_10_counter = 0, //0-10 geV counter
     mt2_20_counter = 0, //10-20 geV counter etc.
     mt2_30_counter = 0,
     mt2_40_counter = 0,
     mt2_50_counter = 0,
     mt2_60_counter = 0,
     mt2_70_counter = 0,
     mt2_80_counter = 0,
     mt2_90_counter = 0,
    mt2_100_counter = 0,
    mt2_110_counter = 0,
    mt2_120_counter = 0,
    mt2_130_counter = 0,
    mt2_140_counter = 0,
    mt2_150_counter = 0,
    mt2_160_counter = 0,
    mt2_170_counter = 0,
    mt2_180_counter = 0,
    mt2_190_counter = 0,
    mt2_200_counter = 0,
    mt2_G200_counter = 0,
    totalEvents = 0;

    // Get File Content
    TFile *file = new TFile( currentFile->GetTitle() );
    TTree *tree = (TTree*)file->Get("tree");
    if(fast) TTreeCache::SetLearnEntries(10);
    if(fast) tree->SetCacheSize(128*1024*1024);
    single.Init(tree);
    
    // Loop over Events in current file
    if( nEventsTotal >= nEventsChain ) continue;
    unsigned int nEventsTree = tree->GetEntriesFast();
    for( unsigned int event = 0; event < nEventsTree; ++event) {

	float lepton_weight = 0;
	
    
      // Get Event Content
      if( nEventsTotal >= nEventsChain ) continue;
      if(fast) tree->LoadTree(event);
      single.GetEntry(event);
      ++nEventsTotal;
    
      // Progress
      SL::progress( nEventsTotal, nEventsChain );

      // Analysis Code
//event based variables
	//COUNTERS
	int el_count = 0, mu_count = 0, nJets = 0, nBtags = 0, good_index = -1, mu_index = -1, el_index = -1;

      float metx = met() * cos( metPhi() );
      float mety = met() * sin( metPhi() );

///metPhi correction//

      float cmetx = met() * cos( metPhi() );
      float cmety = met() * sin( metPhi() );
      float shiftx = 0.;
      float shifty = 0.;

      shiftx = (! isRealData()) ? (0.1166 + 0.0200*nvtxs()) : (0.2661 + 0.3217*nvtxs());
      shifty = (! isRealData()) ? (0.2764 - 0.1280*nvtxs()) : (-0.2251 - 0.1747*nvtxs());

      cmetx -= shiftx;
      cmety -= shifty;

	//problem with this metPhi modulation correction right now
	//keep using cmet, too lazy to change all the variables
	float cmet = met();
     	float cmetphi = metPhi();
	 //float cmetphi = atan2( mety , metx );
      //float cmet = sqrt( cmetx*cmetx + cmety*cmety ); // cmet == corrected met
LorentzVector met_vec;
met_vec.SetPxPyPzE(metx,mety,0,0);

float lepy = lr_p4().py();
float lepx = lr_p4().px();

float w_x = sqrt ( metx*metx + lepx*lepx );
float w_y = sqrt ( mety*mety + lepy*lepy );

float w_pt_ = sqrt (w_x*w_x + w_y*w_y); 


//jet looper
      for (unsigned int k = 0; k < jets_p4().size(); k++){
        if (jets_p4().at(k).pt()*jets_p4Correction().at(k) < 30) continue;
        if (fabs(jets_p4().at(k).eta()) > 2.5) continue;
        if (ROOT::Math::VectorUtil::DeltaR(jets_p4().at(k), lr_p4()) < 0.4) continue;
        nJets++;
        if (btagDiscriminant().at(k) < 0.244) continue;
        nBtags++;
      }

       //metPhi Correction//
//////////// SELECTION ///////
//Event Requirements
//muon eta > 2.1
//electron eta > 2.4
if(lr_p4().pt() < 30) continue;
if(nJets < 2) continue;
if(nBtags != 0) continue;
if(cmet < 40 ) continue;
//Event Requirements

//TRIGGER WEIGH//
if(abs(lr_id()) == 13){
lepton_weight = electronTriggerWeight(lr_p4().pt(),lr_p4().eta());
}
else if(abs(lr_id()) == 11){ 
lepton_weight = muonTriggerWeight(lr_p4().pt(),lr_p4().eta());
}

//float w_pt_ = (lr_p4() + met_vec).pt();

//met FILL
if(file_count == 1){
met_data->Fill(cmet);
	if (abs(lr_id()) == 13){
met_data_mu->Fill(cmet);
	}
	if (abs(lr_id()) == 11){
met_data_el->Fill(cmet);
	}
}

else if(file_count == 2){
met_ttbar->Fill(cmet,scale_1fb()*lepton_weight*5.2);
	if (abs(lr_id()) == 13){
met_ttbar_mu->Fill(cmet,scale_1fb()*lepton_weight*5.2);
	}
	if (abs(lr_id()) == 11){
met_ttbar_el->Fill(cmet,scale_1fb()*lepton_weight*5.2);
	}
}

else if(file_count == 3){
met_wjets->Fill(cmet,scale_1fb()*lepton_weight*5.2);
	if (abs(lr_id()) == 13){
met_wjets_mu->Fill(cmet,scale_1fb()*lepton_weight*5.2);
	}
	if (abs(lr_id()) == 11){
met_wjets_el->Fill(cmet,scale_1fb()*lepton_weight*5.2);
	}
}
/*
		\\\~*~*~*~\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|||||/////////////////////////////////////~*~*~*~///
		///~*~*~*~///////////////////////////////////////|||||\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\~*~*~*~\\\
*/
/////////////    ADD FAKE    ////////////
//W FAKE
//W vector variables
float xw = 0, yw = 0, phiw = 0 , thetaw = 0;
float w_p = -1, w_px = -1, w_py = -1, w_pz = -1;
float b[2];

//lepton vector variables
float xc = 0 , yc = 0, zc = 0;
float r = 40, x = 0, y = 0, phi =0 , theta = 0;
float a[2];
float gammaM;
	//random w momentum from the histogram
	//w_p = d.Landau(95.0291,10.3062);
float rand_pt = d.Landau(40.5,17);

	w_p = rand_pt;

	ry.RndmArray(2,b);
	xw = b[0];
	yw = b[1];

//angles for W vector intial direction
	thetaw = acos(2*xw-1);	   
 	phiw = 2*3.14156265359*(yw-0.5);       

//Change of coordinate to XYZ and scale by magnitude of p
      w_px = w_p* sin(thetaw)* cos(phiw); 
      w_py = w_p* sin(thetaw)* sin(phiw);
      w_pz = w_p* cos(thetaw);
//LEPTON
//Create Lepton fake
	LorentzVector fake_lep, fake_met;
//use TLorentVector to boost
	TLorentzVector lep_boost, met_boost;

//do while eta > 2.4 for the lepton
	do{
//random numbers x,y
//rx TRandom class
	rx.RndmArray(2,a);
	x = a[0];
	y = a[1];

//calculate phi and theta
	phi = (x-0.5)*2*3.14156265359;
	theta = acos(2*y - 1);

//calculate cartesian coordinates of the momentum
	 xc = r*sin(theta)*cos(phi);
	 yc = r*sin(theta)*sin(phi);
	 zc = r*cos(theta);

//lepton momentum and met momentum should be oppositely signed
	lep_boost.SetPxPyPzE(xc,yc,zc,40); 
	met_boost.SetPxPyPzE(-xc,-yc,-zc,40);

//BOOST
//gammaM is gamma * mass, reduces to sqrt(momentum^2 + mass^2)
	float gammaM_ = sqrt(w_p*w_p + 80.2*80.2);
	gammaM = gammaM_;

//Boost lepton
	lep_boost.Boost(w_px / (gammaM), w_py / (gammaM), w_pz / (gammaM) );

		} while  (lep_boost.Eta() > 2.4 ); //make sure lepton is within the eta requirement

//boost the neutrino
	met_boost.Boost(w_px / (gammaM), w_py / (gammaM), w_pz / (gammaM) );

//switch from boost-able TLorentzVector into LorentzVector, 
//some things work different in TLorentzVector
	fake_lep.SetPxPyPzE(lep_boost.Px(),lep_boost.Py(),lep_boost.Pz(),0);
	fake_met.SetPxPyPzE(met_boost.Px(),met_boost.Py(),met_boost.Pz(),0);

//now vector addition using fake_metPhi, metPhi, met, and 40(momentum of the new neutrino)
	float met_x = cos(cmetphi)*cmet;
	float met_y = sin(cmetphi)*cmet;

//real met vector
	LorentzVector real_met;
	real_met.SetPxPyPzE(met_x,met_y,0,0); 

//new met vector
	LorentzVector new_met;
	new_met = real_met + fake_met;
///////////////  END FAKE   ////////////////////////////////////
float fake_W_pt = (fake_lep+fake_met).pt();
if(file_count == 1) fake_wpt_h->Fill(fake_W_pt);
/*
		\\\~*~*~*~\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|||||/////////////////////////////////////~*~*~*~///
		///~*~*~*~///////////////////////////////////////|||||\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\~*~*~*~\\\
*/

////////  MT //////
float dphi = lr_p4().Phi() - cmetphi;
if(dphi > 3.1415) dphi = 6.28 - dphi;
float MT = sqrt(2 * lr_p4().pt() * cmet *(1 - cos(dphi))); 
////////  MT //////

double mt2_event = MT2(new_met.Pt(),new_met.Phi(), lr_p4(), fake_lep);
////////  MT2 //////
if(file_count == 1){
if(mt2_event == 0)				  mt2_0_counter+=1;
else if(0 < mt2_event && mt2_event <= 10)	 mt2_10_counter+=1; 
else if(10 < mt2_event && mt2_event <= 20)	 mt2_20_counter+=1; 
else if(20 < mt2_event && mt2_event <= 30)	 mt2_30_counter+=1;
else if(30 < mt2_event && mt2_event <= 40)	 mt2_40_counter+=1; 
else if(40 < mt2_event && mt2_event <= 50)	 mt2_50_counter+=1;
else if(50 < mt2_event && mt2_event <= 60)	 mt2_60_counter+=1;
else if(60 < mt2_event && mt2_event <= 70)	 mt2_70_counter+=1;
else if(70 < mt2_event && mt2_event <= 80)	 mt2_80_counter+=1;
else if(80 < mt2_event && mt2_event <= 90)	 mt2_90_counter+=1;
else if(90 < mt2_event && mt2_event <= 100)	mt2_100_counter+=1;
else if(100 < mt2_event && mt2_event <= 110)	mt2_110_counter+=1;
else if(110 < mt2_event && mt2_event <= 120)	mt2_120_counter+=1;
else if(120 < mt2_event && mt2_event <= 130)	mt2_130_counter+=1;
else if(130 < mt2_event && mt2_event <= 140)	mt2_140_counter+=1;
else if(140 < mt2_event && mt2_event <= 150)	mt2_150_counter+=1;
else if(150 < mt2_event && mt2_event <= 160)	mt2_160_counter+=1;
else if(160 < mt2_event && mt2_event <= 170)	mt2_170_counter+=1;
else if(170 < mt2_event && mt2_event <= 180)	mt2_180_counter+=1;
else if(180 < mt2_event && mt2_event <= 190)	mt2_190_counter+=1;
else if(190 < mt2_event && mt2_event <= 200)	mt2_200_counter+=1;
else if( mt2_event > 200)		       mt2_G200_counter+=1;
	} //data

if(file_count == 2 || file_count == 3){
if(mt2_event == 0)			   	  mt2_0_counter += 1*lepton_weight;
else if(0 < mt2_event && mt2_event <= 10)	 mt2_10_counter += 1*lepton_weight; 
else if(10 < mt2_event && mt2_event <= 20)	 mt2_20_counter += 1*lepton_weight; 
else if(20 < mt2_event && mt2_event <= 30)	 mt2_30_counter += 1*lepton_weight;
else if(30 < mt2_event && mt2_event <= 40)	 mt2_40_counter += 1*lepton_weight; 
else if(40 < mt2_event && mt2_event <= 50)	 mt2_50_counter += 1*lepton_weight;
else if(50 < mt2_event && mt2_event <= 60)	 mt2_60_counter += 1*lepton_weight;
else if(60 < mt2_event && mt2_event <= 70)	 mt2_70_counter += 1*lepton_weight;
else if(70 < mt2_event && mt2_event <= 80)	 mt2_80_counter += 1*lepton_weight;
else if(80 < mt2_event && mt2_event <= 90)	 mt2_90_counter += 1*lepton_weight;
else if(90 < mt2_event && mt2_event <= 100)	mt2_100_counter += 1*lepton_weight;
else if(100 < mt2_event && mt2_event <= 110)	mt2_110_counter += 1*lepton_weight;
else if(110 < mt2_event && mt2_event <= 120)	mt2_120_counter += 1*lepton_weight;
else if(120 < mt2_event && mt2_event <= 130)	mt2_130_counter += 1*lepton_weight;
else if(130 < mt2_event && mt2_event <= 140)	mt2_140_counter += 1*lepton_weight;
else if(140 < mt2_event && mt2_event <= 150)	mt2_150_counter += 1*lepton_weight;
else if(150 < mt2_event && mt2_event <= 160)	mt2_160_counter += 1*lepton_weight;
else if(160 < mt2_event && mt2_event <= 170)	mt2_170_counter += 1*lepton_weight;
else if(170 < mt2_event && mt2_event <= 180)	mt2_180_counter += 1*lepton_weight;
else if(180 < mt2_event && mt2_event <= 190)	mt2_190_counter += 1*lepton_weight;
else if(190 < mt2_event && mt2_event <= 200)	mt2_200_counter += 1*lepton_weight;
else if( mt2_event > 200)		       mt2_G200_counter += 1*lepton_weight;
	} //MC 
////////  MT2 //////
float lep_pt = lr_p4().pt();

////////  FILL //////
// JETS, MT, MT2, W_pT
//DATA
if(file_count == 1){
totalEvents+=1;
	data_w_pt->Fill(w_pt_);
	data_lep_pt->Fill(lep_pt);
	jets_data->Fill(nJets);
	mt2_h_data->Fill(mt2_event);
	mt_h_data->Fill(MT);
if (abs(lr_id()) == 13){
	data_lep_pt_mu->Fill(lep_pt);
	mt2_h_data_mu->Fill(mt2_event);
	mt_h_data_mu->Fill(MT);
	jets_data_mu->Fill(nJets);
	}
if (abs(lr_id()) == 11){
	data_lep_pt_el->Fill(lep_pt);
	mt2_h_data_el->Fill(mt2_event);
	mt_h_data_el->Fill(MT);
	jets_data_el->Fill(nJets);
	}
}
//TTBAR
else if(file_count == 2){
totalEvents+=1*lepton_weight*scale_1fb()*5.2;
	ttbar_w_pt->Fill(w_pt_,scale_1fb()*lepton_weight*5.2);
	ttbar_lep_pt->Fill(lep_pt,scale_1fb()*lepton_weight*5.2);
	mt2_h_ttbar->Fill(mt2_event,scale_1fb()*lepton_weight*5.2);
	mt_h_ttbar->Fill(MT,scale_1fb()*lepton_weight*5.2);
	jets_ttbar->Fill(nJets,scale_1fb()*lepton_weight*5.2);
if (abs(lr_id()) == 13){
	ttbar_lep_pt_mu->Fill(lep_pt,scale_1fb()*lepton_weight*5.2);
	mt2_h_ttbar_mu->Fill(mt2_event,scale_1fb()*lepton_weight*5.2);
	mt_h_ttbar_mu->Fill(MT,scale_1fb()*lepton_weight*5.2);
	jets_ttbar_mu->Fill(nJets,scale_1fb()*lepton_weight*5.2);
	}
if (abs(lr_id()) == 11){
	ttbar_lep_pt_el->Fill(lep_pt,scale_1fb()*lepton_weight*5.2);
	mt2_h_ttbar_el->Fill(mt2_event,scale_1fb()*lepton_weight*5.2);
	mt_h_ttbar_el->Fill(MT,scale_1fb()*lepton_weight*5.2);
	jets_ttbar_el->Fill(nJets,scale_1fb()*lepton_weight*5.2);
	}
}
//WJETS
else if(file_count == 3){
totalEvents+=1*lepton_weight*scale_1fb()*5.2;
	wjets_w_pt ->Fill(w_pt_,scale_1fb()*lepton_weight*5.2);	
	wjets_lep_pt ->Fill(lep_pt,scale_1fb()*lepton_weight*5.2);	
	mt2_h_wjets->Fill(mt2_event,scale_1fb()*lepton_weight*5.2);
	mt_h_wjets ->Fill(MT,scale_1fb()*lepton_weight*5.2);
	jets_wjets ->Fill(nJets,scale_1fb()*lepton_weight*5.2);
if (abs(lr_id()) == 13){
	wjets_lep_pt_mu->Fill(lep_pt,scale_1fb()*lepton_weight*5.2);
	mt2_h_wjets_mu->Fill(mt2_event,scale_1fb()*lepton_weight*5.2);
	mt_h_wjets_mu->Fill(MT,scale_1fb()*lepton_weight*5.2);
	jets_wjets_mu->Fill(nJets,scale_1fb()*lepton_weight*5.2);
	}
if (abs(lr_id()) == 11){
	wjets_lep_pt_el->Fill(lep_pt,scale_1fb()*lepton_weight*5.2);
	mt2_h_wjets_el->Fill(mt2_event,scale_1fb()*lepton_weight*5.2);
	mt_h_wjets_el->Fill(MT,scale_1fb()*lepton_weight*5.2);
	jets_wjets_el->Fill(nJets,scale_1fb()*lepton_weight*5.2);
	}
}
	/////FILL END //////
	}//event 
///////////////// write histograms ////////////
char* date = "may30";
if(file_count == 1){
     TFile* fout = new TFile(Form("/home/users/sanil/single/%shists/data_sl5_bv_lep30.root",date),"RECREATE");
	mt2_h_data->Write();
	mt_h_data->Write();
	met_data->Write();
	jets_data->Write();
	data_w_pt->Write();
	data_lep_pt->Write();

	data_lep_pt_mu->Write();
	mt2_h_data_mu->Write();
	mt_h_data_mu->Write();
	met_data_mu->Write();
	data_w_pt_mu->Write();
	jets_data_mu->Write();

	data_lep_pt_el->Write();
	mt2_h_data_el->Write();
	mt_h_data_el->Write();
	met_data_el->Write();
	data_w_pt_el->Write();
	jets_data_el->Write();

	//cout << "DATA mt2 tail:    " << mt2tailCounter << endl;
	cout << endl;
	cout << "DATA totalEvents:    " << totalEvents << endl;
	cout << endl;
  fout->Close();
}
else if(file_count == 2){
    TFile* fout = new TFile(Form("/home/users/sanil/single/%shists/ttbar_sl5_bv_lep30.root",date),"RECREATE");
	mt2_h_ttbar->Write();
	mt_h_ttbar->Write();
	met_ttbar->Write();
	jets_ttbar->Write();
	ttbar_w_pt->Write();
	ttbar_lep_pt->Write();


	ttbar_lep_pt_mu->Write();
	mt2_h_ttbar_mu->Write();
	mt_h_ttbar_mu->Write();
	met_ttbar_mu->Write();
	ttbar_w_pt_mu->Write();
	jets_ttbar_mu->Write();

	ttbar_lep_pt_el->Write();
	mt2_h_ttbar_el->Write();
	mt_h_ttbar_el->Write();
	met_ttbar_el->Write();
	ttbar_w_pt_el->Write();
	jets_ttbar_el->Write();
	//cout << "ttbar mt2 tail: " << mt2tailCounter*scale_1fb()*lepton_weight*5.2 << endl;
	cout << endl;
	cout << "ttbar totalEvents:    " << totalEvents << endl;
	cout << endl;
  fout->Close();
}
else if(file_count == 3){
	//TCanvas *c75 = new TCanvas("c75","c75");
    TFile* fout = new TFile(Form("/home/users/sanil/single/%shists/wjets_sl5_bv_lep30.root",date),"RECREATE");
	mt2_h_wjets->Write();
	mt_h_wjets->Write();
	met_wjets->Write();
	jets_wjets->Write();
	wjets_w_pt->Write();
	wjets_lep_pt->Write();

	wjets_lep_pt_mu->Write();
	mt2_h_wjets_mu->Write();
	mt_h_wjets_mu->Write();
	met_wjets_mu->Write();
	wjets_w_pt_mu->Write();
	jets_wjets_mu->Write();

	wjets_lep_pt_el->Write();
	mt2_h_wjets_el->Write();
	mt_h_wjets_el->Write();
	met_wjets_el->Write();
	wjets_w_pt_el->Write();
	jets_wjets_el->Write();
	//cout << "wjets mt2 tail: " << mt2tailCounter*scale_1fb()*lepton_weight*5.2 << endl;
	cout << endl;
	cout << "wjets totalEvents:    " << totalEvents << endl;
	cout << endl;
  fout->Close();
}
///////////////// write histograms END ////////////
		// +++++++++ //

       	//MT2 count writing//

	///txt output///
if(file_count == 1){
ofstream file_d(Form("/home/users/sanil/single/%shists/lep30data_mt2_bin.txt",date));
	if(!file_d.is_open()){return 0;}
	if( file_d.is_open()){
file_d << "total DATA events: " << totalEvents << endl; 
file_d << "starts with 0 < MT2 <= 10, and goes on increments of 10 geV; " << endl;
file_d << mt2_0_counter   << endl;
file_d << mt2_10_counter  << endl;
file_d << mt2_20_counter  << endl;
file_d << mt2_30_counter  << endl;
file_d << mt2_40_counter  << endl;
file_d << mt2_50_counter  << endl;
file_d << mt2_60_counter  << endl;
file_d << mt2_70_counter  << endl;
file_d << mt2_80_counter  << endl;
file_d << mt2_90_counter  << endl;
file_d << mt2_100_counter << endl;
file_d << mt2_110_counter << endl;
file_d << mt2_120_counter << endl;
file_d << mt2_130_counter << endl;
file_d << mt2_140_counter << endl;
file_d << mt2_150_counter << endl;
file_d << mt2_160_counter << endl;
file_d << mt2_170_counter << endl;
file_d << mt2_180_counter << endl;
file_d << mt2_190_counter << endl;
file_d << mt2_200_counter << endl;
file_d << mt2_G200_counter << endl;
file_d << "^^^ MT2 > 200: " << endl;
	}
}
else if (file_count == 3){
ofstream file_w(Form("/home/users/sanil/single/%shists/lep30wjets_mt2_bin.txt",date));
	if(!file_w.is_open()){return 0;}
	if( file_w.is_open()){
file_w << "total W+Jets events: " << totalEvents << endl; 
file_w << "starts with 0 < MT2 <= 10, and goes on increments of 10 geV; " << endl;
file_w << mt2_0_counter   *scale_1fb()*5.2 << endl;
file_w << mt2_10_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_20_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_30_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_40_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_50_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_60_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_70_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_80_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_90_counter  *scale_1fb()*5.2 << endl;
file_w << mt2_100_counter *scale_1fb()*5.2 << endl;
file_w << mt2_110_counter *scale_1fb()*5.2 << endl;
file_w << mt2_120_counter *scale_1fb()*5.2 << endl;
file_w << mt2_130_counter *scale_1fb()*5.2 << endl;
file_w << mt2_140_counter *scale_1fb()*5.2 << endl;
file_w << mt2_150_counter *scale_1fb()*5.2 << endl;
file_w << mt2_160_counter *scale_1fb()*5.2 << endl;
file_w << mt2_170_counter *scale_1fb()*5.2 << endl;
file_w << mt2_180_counter *scale_1fb()*5.2 << endl;
file_w << mt2_190_counter *scale_1fb()*5.2 << endl;
file_w << mt2_200_counter *scale_1fb()*5.2 << endl;
file_w << mt2_G200_counter*scale_1fb()*5.2 << endl;
file_w << "^^^ MT2 > 200 ^^^" << endl;
	}
}
else if (file_count == 2){
ofstream file_t(Form("/home/users/sanil/single/%shists/lep30ttbar_mt2_bin.txt",date));
	if(!file_t.is_open()){return 0;}
	if( file_t.is_open()){
file_d << "total tt~ events: " << totalEvents << endl; 
file_t << "starts with 0 < MT2 <= 10, and goes on increments of 10 geV; " << endl;
file_t << mt2_0_counter  *scale_1fb()*5.2 << endl;
file_t << mt2_10_counter *scale_1fb()*5.2 << endl;
file_t << mt2_20_counter *scale_1fb()*5.2 << endl;
file_t << mt2_30_counter *scale_1fb()*5.2 << endl;
file_t << mt2_40_counter *scale_1fb()*5.2 << endl;
file_t << mt2_50_counter *scale_1fb()*5.2 << endl;
file_t << mt2_60_counter *scale_1fb()*5.2 << endl;
file_t << mt2_70_counter *scale_1fb()*5.2 << endl;
file_t << mt2_80_counter *scale_1fb()*5.2 << endl;
file_t << mt2_90_counter *scale_1fb()*5.2 << endl;
file_t << mt2_100_counter*scale_1fb()*5.2 << endl;
file_t << mt2_110_counter*scale_1fb()*5.2 << endl;
file_t << mt2_120_counter*scale_1fb()*5.2 << endl;
file_t << mt2_130_counter*scale_1fb()*5.2 << endl;
file_t << mt2_140_counter*scale_1fb()*5.2 << endl;
file_t << mt2_150_counter*scale_1fb()*5.2 << endl;
file_t << mt2_160_counter*scale_1fb()*5.2 << endl;
file_t << mt2_170_counter*scale_1fb()*5.2 << endl;
file_t << mt2_180_counter*scale_1fb()*5.2 << endl;
file_t << mt2_190_counter*scale_1fb()*5.2 << endl;
file_t << mt2_200_counter*scale_1fb()*5.2 << endl;
file_t << mt2_G200_counter*scale_1fb()*5.2 << endl;
file_t << "^^^ MT2 > 200 ^^^" << endl;
	}
	///txt output end///
}
       	//MT2 count writing END//

    // Clean Up
    delete tree;
    file->Close();
    delete file;

	file_count++;
  }	//file_loop
fake_wpt_h->Draw();

  if ( nEventsChain != nEventsTotal ) {
    cout << Form( "ERROR: number of events from files (%d) is not equal to total number of events (%d)", nEventsChain, nEventsTotal ) << endl;
  }

  
  // return
  bmark->Stop("benchmark");
  cout << endl;
  cout << nEventsTotal << " Events Processed" << endl;
  cout << "------------------------------" << endl;
  cout << "CPU  Time:	" << Form( "%.01f", bmark->GetCpuTime("benchmark")  ) << endl;
  cout << "Real Time:	" << Form( "%.01f", bmark->GetRealTime("benchmark") ) << endl;
  cout << endl;
  delete bmark;
  return 0;
	}
Пример #7
0
 float randomGauss(float mean=0.0, float spread=1.0)
 {
     TRandom1 *randomGenerator = new TRandom1();
     return randomGenerator->Gaus(mean, spread);
 }
Пример #8
0
void toyV2Generator(const unsigned int numberEvents=300,
		    const unsigned int particlesPerEvent=500,	
		    const bool useFlow=true,
		    const float v2Factor=0.20,
		    const bool writeHistogramFile=true,
		    const bool readHistogramFile=false,
		    const unsigned int nBinsOneD=100,
		    const unsigned int nBinsX=40,
		    const unsigned int nBinsY=40,
		    const unsigned int iBinXMinPlot=3,
		    const unsigned int iBinYMinPlot=3,
		    const unsigned int iBinXMaxPlot=37,
		    const unsigned int iBinYMaxPlot=37) {

  if(readHistogramFile && writeHistogramFile) {
    cerr << "\n Cannot do a simultaneous read and write of the histogram file";
    cerr << endl;
    return;
  }

  const unsigned int particlesPerEventLessOne = particlesPerEvent - 1;
  float particleEta[particlesPerEvent];
  float particlePhi[particlesPerEvent];
  float particlePhiLab[particlesPerEvent];

  float particleEtaPreviousEvent[particlesPerEvent];
  float particlePhiLabPreviousEvent[particlesPerEvent];

  //
  // Function to provide azimuthal angles according to a v2 distribution
  //
  char flowFunction[200];
  sprintf(flowFunction, "1.0 + %4.2f*2.0*cos(2.0*x)", v2Factor);
  TF1 *v2Flow = new TF1("v2Flow", flowFunction, 0.0, 2.0*TMath::Pi());

  const float highEtaBin = 3.0;
  const float lowEtaBin = -3.0;
  const float highPhiBin = 1.5*TMath::Pi();
  const float lowPhiBin = -0.5*TMath::Pi();

  float mixedEventWeight = float(particlesPerEvent)*float(particlesPerEvent - 1)/(2.0*float(particlesPerEvent*particlesPerEvent));

  //
  // Single particle range in eta will be half the maximum for deltaEta
  //
  const float diffEta = 0.5*(highEtaBin - lowEtaBin);

  TH1D *particlePhiHistogram = 0;
  TH1D *particlePhiLabHistogram = 0;
  TH1D *particleEtaHistogram = 0;

  TH1D *pairDeltaPhiHistogram = 0;
  TH1D *pairDeltaPhiHistogramMixed = 0;
  TH1D *pairDeltaPhiHistogramNormalized = 0;

  TH1D *pairDeltaEtaHistogram = 0;
  TH1D *pairDeltaEtaHistogramMixed = 0;
  TH1D *pairDeltaEtaHistogramNormalized = 0;

  TH2D *pairDeltaEtaDeltaPhiHistogram = 0;
  TH2D *pairDeltaEtaDeltaPhiHistogramMixed = 0;
  TH2D *pairDeltaEtaDeltaPhiHistogramNormalized = 0;

  if(!readHistogramFile) {

    particlePhiHistogram = new TH1D("particlePhiHistogram", "Particle azimuthal distribution in reaction plane", nBinsOneD, 0.0, 2.0*TMath::Pi());
    particlePhiHistogram->SetXTitle("Particle azimuthal angle #phi (radians)");
    particlePhiHistogram->SetYTitle("Counts per 0.063 radians bin");

    particlePhiLabHistogram = new TH1D("particlePhiLabHistogram", "Particle azimuthal distribution in lab frame", nBinsOneD, 0.0, 2.0*TMath::Pi());
    particlePhiLabHistogram->SetXTitle("Particle azimuthal angle #phi (radians)");
    particlePhiLabHistogram->SetYTitle("Counts per 0.063 radians bin");

    particleEtaHistogram = new TH1D("particleEtaHistogram", "Particle azimuthal distribution", nBinsOneD, lowEtaBin, highEtaBin);
    particleEtaHistogram->SetXTitle("Particle #eta");
    particleEtaHistogram->SetYTitle("Counts per 0.015 bin");

    pairDeltaPhiHistogram = new TH1D("pairDeltaPhiHistogram", "#Delta #phi pairs in lab frame", nBinsOneD, lowPhiBin, highPhiBin);
    pairDeltaPhiHistogram->SetXTitle("#Delta #phi (radians)");
    pairDeltaPhiHistogram->SetYTitle("Counts");

    pairDeltaPhiHistogramMixed = new TH1D("pairDeltaPhiHistogramMixed", "#Delta #phi pairs in lab frame, mixed-event", nBinsOneD, lowPhiBin, highPhiBin);
    pairDeltaPhiHistogramMixed->SetXTitle("#Delta #phi (radians)");
    pairDeltaPhiHistogramMixed->SetYTitle("Counts");

    pairDeltaPhiHistogramNormalized = new TH1D("pairDeltaPhiHistogramNormalized", "Normalized #Delta #phi pairs in lab frame", nBinsOneD, lowPhiBin, highPhiBin);
    pairDeltaPhiHistogramNormalized->SetXTitle("#Delta #phi (radians)");
    pairDeltaPhiHistogramNormalized->SetYTitle("Counts");

    pairDeltaEtaHistogram = new TH1D("pairDeltaEtaHistogram", "#Delta #eta Pairs, Same Event", nBinsOneD, lowEtaBin, highEtaBin);
    pairDeltaEtaHistogram->SetXTitle("#Delta #eta (radians)");
    pairDeltaEtaHistogram->SetYTitle("Counts");

    pairDeltaEtaHistogramMixed = new TH1D("pairDeltaEtaHistogramMixed", "#Delta #eta Pairs, Mixed Event", nBinsOneD, lowEtaBin, highEtaBin);
    pairDeltaEtaHistogramMixed->SetXTitle("#Delta #eta (radians)");
    pairDeltaEtaHistogramMixed->SetYTitle("Counts");

    pairDeltaEtaHistogramNormalized = new TH1D("pairDeltaEtaHistogramNormalized", "#Delta #eta Pairs, Normalized Event", nBinsOneD, lowEtaBin, highEtaBin);
    pairDeltaEtaHistogramNormalized->SetXTitle("#Delta #eta (radians)");
    pairDeltaEtaHistogramNormalized->SetYTitle("Counts");
    
    pairDeltaEtaDeltaPhiHistogram = new TH2D("pairDeltaEtaDeltaPhiHistogram", "Angular Correlation Pairs", nBinsX, lowEtaBin, highEtaBin, nBinsY, lowPhiBin, highPhiBin);
    pairDeltaEtaDeltaPhiHistogram->SetXTitle("#Delta #eta");
    pairDeltaEtaDeltaPhiHistogram->SetYTitle("#Delta #phi");

    pairDeltaEtaDeltaPhiHistogramMixed = new TH2D("pairDeltaEtaDeltaPhiHistogramMixed", "Angular Correlation Pairs", nBinsX, lowEtaBin, highEtaBin, nBinsY, lowPhiBin, highPhiBin);
    pairDeltaEtaDeltaPhiHistogramMixed->SetXTitle("#Delta #eta");
    pairDeltaEtaDeltaPhiHistogramMixed->SetYTitle("#Delta #phi");

    pairDeltaEtaDeltaPhiHistogramNormalized = new TH2D("pairDeltaEtaDeltaPhiHistogramNormalized", "Normalized Angular Correlation Pairs", nBinsX, lowEtaBin, highEtaBin, nBinsY, lowPhiBin, highPhiBin);
    pairDeltaEtaDeltaPhiHistogramNormalized->SetXTitle("#Delta #eta");
    pairDeltaEtaDeltaPhiHistogramNormalized->SetYTitle("#Delta #phi");

    //
    // Random number generator object
    //
    TRandom1 *particleKinematics = new TRandom1();
    particleKinematics->SetSeed(1);
		
    unsigned int numberEvents10 = numberEvents/10;

    for(unsigned int kEvent=0; kEvent<numberEvents; kEvent++) {
			
      if(kEvent>0 && kEvent%numberEvents10==0) {
	cout << "\n At kEvent = " << kEvent;
      }
			
      //
      // Randomize the reaction plane angle in the lab frame
      //
      float reactionPlaneAngleThisEvent = 2.0*(particleKinematics->Rndm())*TMath::Pi();
			
      //
      // Loop over particles per event
      //
      for(unsigned int kParticle=0; kParticle<particlesPerEvent; kParticle++) {
	particleEta[kParticle] = lowEtaBin + diffEta*(0.5 - particleKinematics->Rndm());
	if(useFlow) {
	  particlePhi[kParticle] = v2Flow->GetRandom();
	  if(particlePhi[kParticle] > 2.0*TMath::Pi())
	    particlePhi[kParticle] -= 2.0*TMath::Pi();

	  particlePhiLab[kParticle] =  particlePhi[kParticle] + reactionPlaneAngleThisEvent;
	  if(particlePhiLab[kParticle] > 2.0*TMath::Pi())
	    particlePhiLab[kParticle] -= 2.0*TMath::Pi();
	}
	else {
	  particlePhi[kParticle] = 2.0*(particleKinematics->Rndm())*TMath::Pi();
	  particlePhiLab[kParticle] =  particlePhi[kParticle];
	}
	particleEtaHistogram->Fill(particleEta[kParticle]);
	particlePhiHistogram->Fill(particlePhi[kParticle]);
 	particlePhiLabHistogram->Fill(particlePhiLab[kParticle]);

      } // loop over particles

      if(kEvent > 0) {
	//
	// Fill the pair histograms for the same event
	//
	for(unsigned int kParticle=0; kParticle<particlesPerEventLessOne; kParticle++) {
	  float phi1 = particlePhiLab[kParticle];
	  float eta1 = particleEta[kParticle];
	  unsigned int jParticleStart = kParticle + 1;
	  for(unsigned int jParticle=jParticleStart; jParticle<particlesPerEvent; jParticle++) {
	    float phiDelta = deltaPhi(phi1, particlePhiLab[jParticle]);

	    //
	    // Change the phiDelta range for plot purposes
	    //
	    if(phiDelta < -0.5*TMath::Pi())
	      phiDelta = TMath::Pi() + TMath::Pi() + phiDelta;

	    float etaDelta = eta1 - particleEta[jParticle];
	    pairDeltaPhiHistogram->Fill(phiDelta);
	    pairDeltaEtaHistogram->Fill(etaDelta, 0.5);
	    pairDeltaEtaHistogram->Fill(-etaDelta, 0.5);
	    pairDeltaEtaDeltaPhiHistogram->Fill(etaDelta, phiDelta, 0.5);
	    pairDeltaEtaDeltaPhiHistogram->Fill(-etaDelta, phiDelta, 0.5);
	  } // loop over second particle in same event pair

	} // loop over first particle in same event pair

	//
	// Fill the pair histograms for the mixed event
	//
	for(unsigned int kParticle=0; kParticle<particlesPerEvent; kParticle++) {
	  float phi1 = particlePhiLab[kParticle];
	  float eta1 = particleEta[kParticle];
	  for(unsigned int jParticle=0; jParticle<particlesPerEvent; jParticle++) {
	    float phiDelta = deltaPhi(phi1, particlePhiLabPreviousEvent[jParticle]);

	    //
	    // Change the phiDelta range for plot purposes
	    //
	    if(phiDelta < -0.5*TMath::Pi())
	      phiDelta = TMath::Pi() + TMath::Pi() + phiDelta;

	    pairDeltaPhiHistogramMixed->Fill(phiDelta, mixedEventWeight);
	    float etaDelta = eta1 - particleEtaPreviousEvent[jParticle];
	    pairDeltaEtaHistogramMixed->Fill(etaDelta,0.5);
	    pairDeltaEtaHistogramMixed->Fill(-etaDelta,0.5);
	    pairDeltaEtaDeltaPhiHistogramMixed->Fill(etaDelta, phiDelta, 0.5);
	    pairDeltaEtaDeltaPhiHistogramMixed->Fill(-etaDelta, phiDelta, 0.5);

	  } // loop over particle in previous event

	} // loop over particle in current event


      } // check on beyond the first event

      //
      // Move particles from current event to previous event arrays
      //
      for(unsigned int kParticle=0; kParticle<particlesPerEvent; kParticle++) {
	particlePhiLabPreviousEvent[kParticle] = particlePhiLab[kParticle];
	particleEtaPreviousEvent[kParticle] = particleEta[kParticle];
      }

    } // loop over events
    cout << "\n Finished NTUPLE scan" << endl;

    //
    // Normalize the delta-phi histograms with the mixed-event yields
    //
    float sumSameEventPhi1D = 0.0;
    float sumMixedEventPhi1D = 0.0;
    for(unsigned int iBinX=1; iBinX<nBinsOneD; iBinX++) {
      sumSameEventPhi1D += pairDeltaPhiHistogram->GetBinContent(iBinX);
      sumMixedEventPhi1D += pairDeltaPhiHistogramMixed->GetBinContent(iBinX);
    }
    if(sumSameEventPhi1D > 0.0 && sumMixedEventPhi1D > 0.0) {
      float normalizationFactor1D = sumMixedEventPhi1D/sumSameEventPhi1D;
      for(unsigned int iBinX=0; iBinX<nBinsOneD; iBinX++) {
	pairDeltaPhiHistogramNormalized->SetBinContent(iBinX,0.0);
	float sameEventContent = pairDeltaPhiHistogram->GetBinContent(iBinX);
	float mixedEventContent = pairDeltaPhiHistogramMixed->GetBinContent(iBinX);
	if(mixedEventContent > 0.0) {
	  float normalizedYield = normalizationFactor1D*sameEventContent/mixedEventContent;
	  pairDeltaPhiHistogramNormalized->SetBinContent(iBinX, normalizedYield);
	} // check for non-zero denominator
      } // loop over phi bins
    } // check for non-zero totals
		
    //
    // Normalize the delta-eta histograms with the mixed-event yields
    //
    float sumSameEvent1D = pairDeltaEtaHistogram->GetEntries();
    float sumMixedEvent1D = pairDeltaEtaHistogramMixed->GetEntries();
    if(sumSameEvent1D > 0.0 && sumMixedEvent1D > 0.0) {
      float normalizationFactor1D = sumMixedEvent1D/sumSameEvent1D;
      for(unsigned int iBinX=0; iBinX<nBinsOneD; iBinX++) {
	pairDeltaEtaHistogramNormalized->SetBinContent(iBinX,0.0);
	float sameEventContent = pairDeltaEtaHistogram->GetBinContent(iBinX);
	float mixedEventContent = pairDeltaEtaHistogramMixed->GetBinContent(iBinX);
	if(mixedEventContent > 0.0) {
	  float normalizedYield = normalizationFactor1D*sameEventContent/mixedEventContent;
	  pairDeltaEtaHistogramNormalized->SetBinContent(iBinX, normalizedYield);
	} // check for non-zero denominator
      } // loop over eta bins
    } // check for non-zero totals
		
    float sumSameEvent2D = pairDeltaEtaDeltaPhiHistogram->GetEntries();
    float sumMixedEvent2D = pairDeltaEtaDeltaPhiHistogramMixed->GetEntries();

    if(sumSameEvent2D > 0.0 && sumMixedEvent2D > 0.0) {
      float normalizationFactor2D = sumMixedEvent2D/sumSameEvent2D;
      for(unsigned int iBinX=0; iBinX<nBinsX; iBinX++) {
	for(unsigned int iBinY=0; iBinY<nBinsY; iBinY++) {
	  pairDeltaEtaDeltaPhiHistogramNormalized->SetBinContent(iBinX, iBinY, 0.0);
	  if(iBinX<iBinXMinPlot || iBinX>iBinXMaxPlot ||
	     iBinY<iBinYMinPlot || iBinY>iBinYMaxPlot)
	    continue;  // limit the fiducial area of the plot because of possible low statistics

	  float sameEventContent = pairDeltaEtaDeltaPhiHistogram->GetBinContent(iBinX, iBinY);
	  float mixedEventContent = pairDeltaEtaDeltaPhiHistogramMixed->GetBinContent(iBinX, iBinY);
	  if(mixedEventContent > 0.0) {
	    float normalizedYield = normalizationFactor2D*sameEventContent/mixedEventContent;
	    pairDeltaEtaDeltaPhiHistogramNormalized->SetBinContent(iBinX, iBinY, normalizedYield);
	  } // check for non-zero mixed event content
	} // loop over phi bins
      } // loop over eta bins
    } // check for non-zero total counts

  } // check on not reading histogram file

  if(readHistogramFile) {

    char inputFileName[200];
    sprintf(inputFileName, "toyV2Generator%dEvents%dParticlesPerEvent%4.2fV2.root", numberEvents, particlesPerEvent, v2Factor);
    TFile *toyV2GeneratorFile = new TFile(inputFileName);
		
    if(!toyV2GeneratorFile) {
      cerr << "\n Unable to find ROOT file " <<  inputFileName << endl;
      return;
    }

    cout << "\n Using input ROOT file " << inputFileName << endl;
		
    particlePhiHistogram = (TH1D*)toyV2GeneratorFile->Get("particlePhiHistogram");
    if(!particlePhiHistogram) {
      cerr << "\n Cannot find particlePhiHistogram" << endl;
      return;
    }

    particlePhiLabHistogram = (TH1D*)toyV2GeneratorFile->Get("particlePhiLabHistogram");
    if(!particlePhiLabHistogram) {
      cerr << "\n Cannot find particlePhiLabHistogram" << endl;
      return;
    }

    particleEtaHistogram = (TH1D*)toyV2GeneratorFile->Get("particleEtaHistogram");
    if(!particleEtaHistogram) {
      cerr << "\n Cannot find particleEtaHistogram" << endl;
      return;
    }
		
    pairDeltaPhiHistogram = (TH1D*)toyV2GeneratorFile->Get("pairDeltaPhiHistogram");
    if(!pairDeltaPhiHistogram) {
      cerr << "\n Cannot find pairDeltaPhiHistogram" << endl;
      return;
    }		

    pairDeltaPhiHistogramMixed = (TH1D*)toyV2GeneratorFile->Get("pairDeltaPhiHistogramMixed");
    if(!pairDeltaPhiHistogramMixed) {
      cerr << "\n Cannot find pairDeltaPhiHistogramMixed" << endl;
      return;
    }

    pairDeltaPhiHistogramNormalized = (TH1D*)toyV2GeneratorFile->Get("pairDeltaPhiHistogramNormalized");
    if(!pairDeltaPhiHistogramNormalized) {
      cerr << "\n Cannot find pairDeltaPhiHistogramNormalized" << endl;
      return;
    }

    pairDeltaEtaHistogram = (TH1D*)toyV2GeneratorFile->Get("pairDeltaEtaHistogram");
    if(!pairDeltaEtaHistogram) {
      cerr << "\n Cannot find pairDeltaEtaHistogram" << endl;
      return;
    }

    pairDeltaEtaHistogramMixed = (TH1D*)toyV2GeneratorFile->Get("pairDeltaEtaHistogramMixed");
    if(!pairDeltaEtaHistogramMixed) {
      cerr << "\n Cannot find pairDeltaEtaHistogramMixed" << endl;
      return;
    }

    pairDeltaEtaHistogramNormalized = (TH1D*)toyV2GeneratorFile->Get("pairDeltaEtaHistogramNormalized");
    if(!pairDeltaEtaHistogramNormalized) {
      cerr << "\n Cannot find pairDeltaEtaHistogramNormalized" << endl;
      return;
    }

    pairDeltaEtaDeltaPhiHistogram = (TH2D*)toyV2GeneratorFile->Get("pairDeltaEtaDeltaPhiHistogram");
    if(!pairDeltaEtaDeltaPhiHistogram) {
      cerr << "\n Cannot find pairDeltaEtaDeltaPhiHistogram" << endl;
      return;
    }

    pairDeltaEtaDeltaPhiHistogramMixed = (TH2D*)toyV2GeneratorFile->Get("pairDeltaEtaDeltaPhiHistogramMixed");
    if(!pairDeltaEtaDeltaPhiHistogramMixed) {
      cerr << "\n Cannot find pairDeltaEtaDeltaPhiHistogramMixed" << endl;
      return;
    }

    pairDeltaEtaDeltaPhiHistogramNormalized = (TH2D*)toyV2GeneratorFile->Get("pairDeltaEtaDeltaPhiHistogramNormalized");
    if(!pairDeltaEtaDeltaPhiHistogramNormalized) {
      cerr << "\n Cannot find pairDeltaEtaDeltaPhiHistogramNormalized" << endl;
      return;
    }

  } // check on readHistogramFile

  TCanvas *c1 = new TCanvas("c1", "Plotting Pair Events", 200, 10, 700, 500);
  //
  // Use ROOT's gStyle function to set up plot options
  //
  gStyle->SetOptStat(1110);
  gStyle->SetStatTextColor(kBlue);
  gStyle->SetFuncColor(kBlue);
  gStyle->SetFuncWidth(2);
  gStyle->SetOptFit(1111);
  gStyle->SetFitFormat("6.5g");
	
  c1->SetFillColor(kWhite);

  c1->Divide(2,2);

  c1->cd(1);
  
  if(useFlow) {
    particlePhiHistogram->SetStats(0);
    particlePhiHistogram->SetMinimum(0);
    float fMaximum = particlePhiHistogram->GetMaximum();
    int iMaximum = 1.5*fMaximum;
    particlePhiHistogram->SetMaximum(iMaximum);
		
    particlePhiHistogram->SetLineColor(4);
    particlePhiHistogram->Draw();
    particlePhiLabHistogram->SetLineColor(1);
    particlePhiLabHistogram->Draw("same");
		
    char labelBufferTitle[200];
    sprintf(labelBufferTitle, "Events = %d, Particles/Event = %d, V2 factor = %4.2f", numberEvents, particlesPerEvent, v2Factor);
    TLatex *text1 = new TLatex(0.5, 0.90*iMaximum, labelBufferTitle);
    text1->SetTextColor(4);
    text1->SetTextSize(0.045);
    text1->Draw();
		
    char labelBuffer2[200];
    sprintf(labelBuffer2, "Blue: azimuthal distribution relative to reaction plane");
    TLatex *text2 = new TLatex(0.5, 0.20*iMaximum, labelBuffer2);
    text2->SetTextColor(4);
    text2->SetTextSize(0.035);
    text2->Draw();
		
    char labelBuffer3[200];
    sprintf(labelBuffer3, "Black: azimuthal distribution relative to lab frame");
    TLatex *text3 = new TLatex(0.5, 0.10*iMaximum, labelBuffer3);
    text3->SetTextColor(1);
    text3->SetTextSize(0.035);
    text3->Draw();
		
  }
  else {
    particlePhiLabHistogram->SetStats(0);
    float fMaximum = particlePhiLabHistogram->GetMaximum();
    int iMaximum = 1.5*fMaximum;
    particlePhiLabHistogram->SetMaximum(iMaximum);
    particlePhiLabHistogram->SetMinimum(0);
    particlePhiLabHistogram->Draw();
		
    char labelBufferTitle[200];
    sprintf(labelBufferTitle, "Events = %d, Particles/Event = %d, No Flow", numberEvents, particlesPerEvent);
    TLatex *text1 = new TLatex(0.5, 0.90*iMaximum, labelBufferTitle);
    text1->SetTextColor(4);
    text1->SetTextSize(0.045);
    text1->Draw();
		
  }

  c1->cd(2);
  //pairDeltaPhiHistogramNormalized->SetStats(0);
  pairDeltaPhiHistogramNormalized->SetMaximum(1.3);
  pairDeltaPhiHistogramNormalized->SetMinimum(0.7);
  pairDeltaPhiHistogramNormalized->SetLineColor(2);

  TF1* fitFcnV2 = new TF1("fitFcnV2", v2Fit, -0.5*TMath::Pi(), 1.5*TMath::Pi(), 1);
  fitFcnV2->SetParameters(0, 0.20);
  fitFcnV2->SetParName(0, "Coeff");

  pairDeltaPhiHistogramNormalized->Fit("fitFcnV2", "", "",  -0.5*TMath::Pi(), 1.5*TMath::Pi());

  char labelBuffer12[200];
  sprintf(labelBuffer12, "Blue: fit with 1.0 + 2.0*Coeff*cos(2#Delta#phi), Coeff = %4.3f", fitFcnV2->GetParameter(0));
  TLatex *text12 = new TLatex(-0.5, 0.83, labelBuffer12);
  text12->SetTextColor(4);
  text12->SetTextSize(0.035);
  text12->Draw();

  char labelBuffer22[200];
  sprintf(labelBuffer22, "Red: normalized pair #Delta#phi distribution in lab frame");
  TLatex *text22 = new TLatex(-0.5, 0.77, labelBuffer22);
  text22->SetTextColor(2);
  text22->SetTextSize(0.035);
  text22->Draw();

  c1->cd(3);
  pairDeltaEtaHistogramNormalized->SetStats(0);
  pairDeltaEtaHistogramNormalized->SetMaximum(1.5);
  pairDeltaEtaHistogramNormalized->SetMinimum(0);
  pairDeltaEtaHistogramNormalized->Draw();
	
  c1->cd(4);
  pairDeltaEtaDeltaPhiHistogramNormalized->SetStats(0);
  pairDeltaEtaDeltaPhiHistogramNormalized->SetMaximum(1.3);
  pairDeltaEtaDeltaPhiHistogramNormalized->SetMinimum(0.7);
  pairDeltaEtaDeltaPhiHistogramNormalized->Draw("surf1");

  if(writeHistogramFile) {
    TFile *toyV2GeneratorFile;
		
    char outputFileName[200];
    sprintf(outputFileName, "toyV2Generator%dEvents%dParticlesPerEvent%4.2fV2.root", numberEvents, particlesPerEvent, v2Factor);
    char outputFileTitle[200];
    sprintf(outputFileTitle, "Toy V2 Generator with %d Events, %d Particles/Event, and V2 = %4.2f", numberEvents, particlesPerEvent, v2Factor);
    toyV2GeneratorFile = new TFile(outputFileName, "recreate", outputFileTitle);

    particlePhiHistogram->Write();
    particlePhiLabHistogram->Write();
    particleEtaHistogram->Write();

    pairDeltaPhiHistogram->Write();
    pairDeltaPhiHistogramMixed->Write();
    pairDeltaPhiHistogramNormalized->Write();

    pairDeltaEtaHistogram->Write();
    pairDeltaEtaHistogramMixed->Write();
    pairDeltaEtaHistogramNormalized->Write();

    pairDeltaEtaDeltaPhiHistogram->Write();
    pairDeltaEtaDeltaPhiHistogramMixed->Write();
    pairDeltaEtaDeltaPhiHistogramNormalized->Write();
		
    toyV2GeneratorFile->Write();
    toyV2GeneratorFile->Close();

  }

  return;

}