void mc2a(int iShow){
  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);

  gRandom = new TRandom3();
  gRandom->SetSeed(0);
  TH1D * hBW   = new TH1D("hBW","",100,0.0,2.0);
  TH1D * hGaus   = new TH1D("hGaus","",100,0.0,2.0);
  TH1D * hExp1   = new TH1D("hExp1","",100,0.0,10.0);
  TH1D * hExp2   = new TH1D("hExp2","",100,0.0,10.0);

  TF1 *f1 = new TF1("f1","exp(x*[0])",0,10);
  f1->SetParameter(0,-0.5);

  int nToGen = 1000000;
  for (int i = 0; i<nToGen; i++) {  
    double bwCenter = 0.77;
    double bwWidth = 0.1464;
    double bwRand = gRandom->BreitWigner(bwCenter,bwWidth);  
    hBW->Fill(bwRand);

    double gausCenter = 0.77;
    double gausWidth = 0.1464;
    double gausRand = gRandom->Gaus(gausCenter,gausWidth);  
    hGaus->Fill(gausRand);

    double expSlope = 0.5;
    double tau = 1.0/expSlope;
    double expRand1 = gRandom->Exp(tau);  
    hExp1->Fill(expRand1);

    double expRand2 = f1->GetRandom();  
    hExp2->Fill(expRand2);
    
  }

  if (iShow == 1) hBW->Draw(); 
  if (iShow == 2) hGaus->Draw(); 
  if (iShow == 3) hExp1->Draw(); 
  if (iShow == 4) hExp2->Draw(); 

}

void mc2b(int iShow){
  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);

  TH1D * hEGamma = new TH1D("hEGamma","",200,7.5,9.5);  
  TH2D * hMoVsThetaPro = new TH2D("hMoVsThetaPro","",90,0.0,90.0,100,0.0,10.0);  
  TH1D * hMassRho = new TH1D("hMassRho","",200,0.0,2.0);  
  TH1D * hMassPipPim = new TH1D("hMassPipPim","",200,0.0,2.0);  
  TH2D * hMoVsThetaPim = new TH2D("hMoVsThetaPim","",90,0.0,90.0,100,0.0,10.0);  
  TH2D * hMoVsThetaPip = new TH2D("hMoVsThetaPip","",90,0.0,90.0,100,0.0,10.0);  

  gRandom =  new TRandom3();
  gRandom->SetSeed(0);

  double pi = 3.14159;

  double mPro       = 0.938;
  double mPip       = 0.13957;
  double mRhoCenter = 0.7755;
  double rhoWidth   = 0.1464;
  double mRho       = mRhoCenter;
    
  TLorentzVector target(0,0,0,mPro);

  double eGammaLow  = 8.0;
  double eGammaHigh = 9.0;
  
  

  int nToGen = 1000000;
  for (int i = 0; i<nToGen; i++) {
    bool keep = false;
    double eGamma = 0;
    double testVal = 0;
    while (keep == false){
      eGamma = gRandom->Uniform(eGammaLow,eGammaHigh);
      testVal = gRandom->Uniform(0.0,1.0/eGammaLow);
      if (testVal < 1.0/eGamma) keep = true; 
    }
    hEGamma->Fill(eGamma);

    TLorentzVector beam(0,0,eGamma,eGamma);
    TLorentzVector pTot4Vec = beam + target;
    double sVal = pTot4Vec.Mag2();
    double wVal = pTot4Vec.Mag();  //Invariant mass of initial state

    
    keep = false;
    while (keep == false){
      mRho = gRandom->BreitWigner(mRhoCenter,rhoWidth);  
      if (mRho >= 2*mPip && wVal >= (mRho+mPro)) keep = true;
    }
    hMassRho->Fill(mRho);

    //Since wVal is invariant, it is the same in every frame
    //The center of mass frame is especially nice. Let us "decay"
    //the initial state into the final state = proton and rho meson
    //
    double eRhoCM = (sVal + pow(mRho,2) - pow(mPro,2))/(2*wVal); 
    double pRhoCM = sqrt(pow(eRhoCM,2) - pow(mRho,2));
    double eProCM = wVal - eRhoCM;
    double pProCM = pRhoCM;
  
    //
    //Now phase-space generate the angles
    double phiRho      = gRandom->Uniform(-pi,pi);    
    double cosThetaRho = gRandom->Uniform(-1.0,1.0);
    //Obtain the components of the rho 4-vector
    double pRhoZCM          = pRhoCM*cosThetaRho;
    double pRhoTransverseCM = sqrt(pow(pRhoCM,2) - pow(pRhoZCM,2));
    double pRhoXCM          = pRhoTransverseCM*cos(phiRho);
    double pRhoYCM          = pRhoTransverseCM*sin(phiRho);
    //Obtain the components of the proton 4-vector
    double pProXCM          = -pRhoXCM;
    double pProYCM          = -pRhoYCM;
    double pProZCM          = -pRhoZCM;
    //Create the rho CM 4-vector and the proton CM 4-vector
    TLorentzVector pRhoCM4Vec = TLorentzVector(pRhoXCM,pRhoYCM,pRhoZCM,eRhoCM);
    TLorentzVector pProCM4Vec = TLorentzVector(pProXCM,pProYCM,pProZCM,eProCM);
    //
    //Boost back to lab frame. First find beta and gamma of CM frame
    //Treat the entire system as a single particle of mass W = sqrt(s).
    //This means that the (total momentum) = gamma betaCM W
    //and that the (total energy) = gamma W
    // => gammaCM = (total energy)/ W
    //and betaCM = (total momentum)/(total energy)
    double betaCM  = pTot4Vec.P()/pTot4Vec.E();
    double gammaCM = pTot4Vec.E()/pTot4Vec.Mag();
    //
    //Boost back to lab
    //
    TLorentzVector pPro4Vec = pProCM4Vec;
    pPro4Vec.Boost(pTot4Vec.BoostVector());

    TLorentzVector pRho4Vec = pRhoCM4Vec;
    pRho4Vec.Boost(pTot4Vec.BoostVector());

    hMoVsThetaPro->Fill(pPro4Vec.Theta()*180.0/3.14159,pPro4Vec.P());      

    //////Rho decay////////////
    //Let RFR = Rest frame of Rho
    double ePipRFR = mRho/2.0; 
    double pPipRFR = sqrt(pow(ePipRFR,2) - pow(mPip,2));    
    double ePimRFR = ePipRFR;
    double pPimRFR = pPipRFR;
    double phiPipRFR      = gRandom->Uniform(-pi,pi);    
    double cosThetaPipRFR = gRandom->Uniform(-1.0,1.0);
    //Obtain the components of the pip 4-vector
    double pPipZRFR          = pPipRFR*cosThetaPipRFR;
    double pPipTransverseRFR = sqrt(pow(pPipRFR,2) - pow(pPipZRFR,2));    
    double pPipXRFR          = pPipTransverseRFR*cos(phiPipRFR);
    double pPipYRFR          = pPipTransverseRFR*sin(phiPipRFR);
    //Load the RFR 4-vectors for pip and pim
    TLorentzVector pPipRFR4Vec = TLorentzVector(pPipXRFR,pPipYRFR,pPipZRFR,ePipRFR);
    TLorentzVector pPimRFR4Vec = TLorentzVector(-pPipXRFR,-pPipYRFR,-pPipZRFR,ePipRFR);
    ///////////////////////////
    //Boost the pions to the lab frame from the Rest-Frame of the Rho (RFR)
    //
    TLorentzVector pPip4Vec = pPipRFR4Vec;
    pPip4Vec.Boost(pRho4Vec.BoostVector());    

    TLorentzVector pPim4Vec = pPimRFR4Vec;
    pPim4Vec.Boost(pRho4Vec.BoostVector());    

    TLorentzVector pPipPim4Vec = pPip4Vec + pPim4Vec;
    hMassPipPim->Fill(pPipPim4Vec.Mag());      

    hMoVsThetaPip->Fill(pPip4Vec.Theta()*180.0/3.14159,pPip4Vec.P());      
    hMoVsThetaPim->Fill(pPim4Vec.Theta()*180.0/3.14159,pPim4Vec.P());      

  }
  if (iShow == 1){
    hEGamma->Draw();
  }
  if (iShow == 2){
    hMoVsThetaPro->Draw("colz");      
  } 
  if (iShow == 3){
    hMassRho->Draw();      
  } 
  if (iShow == 4){
    hMassPipPim->Draw();      
  } 
  if (iShow == 5){
    hMoVsThetaPip->Draw("colz");      
  } 
  if (iShow == 6){
    hMoVsThetaPim->Draw("colz");      
  } 

}
