示例#1
0
void example_N_Wlnu(const std::string& output_name =
		    "output_example_N_Wlnu.root"){

  double mW   = 80.385;  // GeV, PDG 2016
  double wW   = 2.085;
  double mL   = 0.106;   // muons
  double mN   = 0.;

  // number of events to generate (for each W multiplicity)
  int Ngen = 10000;

  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing generator frames and tree..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  
  ppLabGenFrame     LAB_G2W("LAB_G2W","LAB");      ppLabGenFrame     LAB_G3W("LAB_G3W","LAB");
  DecayGenFrame     CM_G2W("CM_G2W","CM");         DecayGenFrame     CM_G3W("CM_G3W","CM");
  ResonanceGenFrame Wa_G2W("Wa_G2W","W_{a}");      ResonanceGenFrame Wa_G3W("Wa_G3W","W_{a}");
  ResonanceGenFrame Wb_G2W("Wb_G2W","W_{b}");      ResonanceGenFrame Wb_G3W("Wb_G3W","W_{b}");
                                                   ResonanceGenFrame Wc_G3W("Wc_G3W","W_{c}");
  VisibleGenFrame   La_G2W("La_G2W","#it{l}_{a}"); VisibleGenFrame   La_G3W("La_G3W","#it{l}_{a}");
  InvisibleGenFrame Na_G2W("Na_G2W","#nu_{a}");    InvisibleGenFrame Na_G3W("Na_G3W","#nu_{a}");
  VisibleGenFrame   Lb_G2W("Lb_G2W","#it{l}_{b}"); VisibleGenFrame   Lb_G3W("Lb_G3W","#it{l}_{b}");
  InvisibleGenFrame Nb_G2W("Nb_G2W","#nu_{b}");    InvisibleGenFrame Nb_G3W("Nb_G3W","#nu_{b}");
                                                   VisibleGenFrame   Lc_G3W("Lc_G3W","#it{l}_{c}");
                                                   InvisibleGenFrame Nc_G3W("Nc_G3W","#nu_{c}");

  ppLabGenFrame     LAB_G4W("LAB_G4W","LAB");     
  DecayGenFrame     CM_G4W("CM_G4W","CM");        
  ResonanceGenFrame Wa_G4W("Wa_G4W","W_{a}");     
  ResonanceGenFrame Wb_G4W("Wb_G4W","W_{b}");    
  ResonanceGenFrame Wc_G4W("Wc_G4W","W_{c}");
  ResonanceGenFrame Wd_G4W("Wd_G4W","W_{d}");
  VisibleGenFrame   La_G4W("La_G4W","#it{l}_{a}"); 
  InvisibleGenFrame Na_G4W("Na_G4W","#nu_{a}");   
  VisibleGenFrame   Lb_G4W("Lb_G4W","#it{l}_{b}");
  InvisibleGenFrame Nb_G4W("Nb_G4W","#nu_{b}");
  VisibleGenFrame   Lc_G4W("Lc_G4W","#it{l}_{c}");
  InvisibleGenFrame Nc_G4W("Nc_G4W","#nu_{c}");
  VisibleGenFrame   Ld_G4W("Ld_G4W","#it{l}_{d}");
  InvisibleGenFrame Nd_G4W("Nd_G4W","#nu_{d}");

  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
  
  LAB_G2W.SetChildFrame(CM_G2W);                   LAB_G3W.SetChildFrame(CM_G3W);
  CM_G2W.AddChildFrame(Wa_G2W);                    CM_G3W.AddChildFrame(Wa_G3W);
  CM_G2W.AddChildFrame(Wb_G2W);                    CM_G3W.AddChildFrame(Wb_G3W);
  Wa_G2W.AddChildFrame(La_G2W);                    CM_G3W.AddChildFrame(Wc_G3W);
  Wa_G2W.AddChildFrame(Na_G2W);                    Wa_G3W.AddChildFrame(La_G3W);
  Wb_G2W.AddChildFrame(Lb_G2W);                    Wa_G3W.AddChildFrame(Na_G3W);
  Wb_G2W.AddChildFrame(Nb_G2W);                    Wb_G3W.AddChildFrame(Lb_G3W);
                                                   Wb_G3W.AddChildFrame(Nb_G3W);
  LAB_G4W.SetChildFrame(CM_G4W);                   Wc_G3W.AddChildFrame(Lc_G3W);
  CM_G4W.AddChildFrame(Wa_G4W);                    Wc_G3W.AddChildFrame(Nc_G3W);                               
  CM_G4W.AddChildFrame(Wb_G4W);
  CM_G4W.AddChildFrame(Wc_G4W);
  CM_G4W.AddChildFrame(Wd_G4W);
  Wa_G4W.AddChildFrame(La_G4W);
  Wa_G4W.AddChildFrame(Na_G4W);
  Wb_G4W.AddChildFrame(Lb_G4W);
  Wb_G4W.AddChildFrame(Nb_G4W);
  Wc_G4W.AddChildFrame(Lc_G4W);
  Wc_G4W.AddChildFrame(Nc_G4W);
  Wd_G4W.AddChildFrame(Ld_G4W);
  Wd_G4W.AddChildFrame(Nd_G4W);

  if(LAB_G2W.InitializeTree() && LAB_G3W.InitializeTree() &&
     LAB_G4W.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized generator trees" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator trees" << LogEnd;

  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
  
  // non-resonant production
  CM_G2W.SetVariableMass(true); CM_G3W.SetVariableMass(true); CM_G4W.SetVariableMass(true);
  // set W masses and widths
  Wa_G2W.SetMass(mW);  Wb_G2W.SetMass(mW);
  Wa_G3W.SetMass(mW);  Wb_G3W.SetMass(mW);  Wc_G3W.SetMass(mW);
  Wa_G4W.SetMass(mW);  Wb_G4W.SetMass(mW);  Wc_G4W.SetMass(mW);   Wd_G4W.SetMass(mW);
  Wa_G2W.SetWidth(wW); Wb_G2W.SetWidth(wW);
  Wa_G3W.SetWidth(wW); Wb_G3W.SetWidth(wW); Wc_G3W.SetWidth(wW);
  Wa_G4W.SetWidth(wW); Wb_G4W.SetWidth(wW); Wc_G4W.SetWidth(wW); Wd_G4W.SetWidth(wW);
  // set lepton masses
  La_G2W.SetMass(mL);  Lb_G2W.SetMass(mL);
  La_G3W.SetMass(mL);  Lb_G3W.SetMass(mL);  Lc_G3W.SetMass(mL);
  La_G4W.SetMass(mL);  Lb_G4W.SetMass(mL);  Lc_G4W.SetMass(mL);  Ld_G4W.SetMass(mL);
  // set neutrino masses
  Na_G2W.SetMass(mN);  Nb_G2W.SetMass(mN);
  Na_G3W.SetMass(mN);  Nb_G3W.SetMass(mN);  Nc_G3W.SetMass(mN);
  Na_G4W.SetMass(mN);  Nb_G4W.SetMass(mN);  Nc_G4W.SetMass(mN);  Nd_G4W.SetMass(mN);

  // lepton pT/eta cuts
  La_G2W.SetPtCut(15.);  Lb_G2W.SetPtCut(15.);
  La_G2W.SetEtaCut(2.5); Lb_G2W.SetEtaCut(2.5);
  La_G3W.SetPtCut(15.);  Lb_G3W.SetPtCut(15.);  Lc_G3W.SetPtCut(15.);
  La_G3W.SetEtaCut(2.5); Lb_G3W.SetEtaCut(2.5); Lc_G3W.SetEtaCut(2.5);
  La_G4W.SetPtCut(15.);  Lb_G4W.SetPtCut(15.);  Lc_G4W.SetPtCut(15.);  Ld_G4W.SetPtCut(15.);
  La_G4W.SetEtaCut(2.5); Lb_G4W.SetEtaCut(2.5); Lc_G4W.SetEtaCut(2.5); Ld_G4W.SetEtaCut(2.5);
  
  if(LAB_G2W.InitializeAnalysis() && LAB_G3W.InitializeAnalysis() &&
     LAB_G4W.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized generator analyses" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator analyses" << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing reconstruction frames and trees..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////

  LabRecoFrame       LAB_2W("LAB_2W","LAB");       LabRecoFrame       LAB_3W("LAB_3W","LAB");
  DecayRecoFrame     CM_2W("CM_2W","CM");          DecayRecoFrame     CM_3W("CM_3W","CM");
  DecayRecoFrame     Wa_2W("Wa_2W","W_{a}");       DecayRecoFrame     Wa_3W("Wa_3W","W_{a}");
  DecayRecoFrame     Wb_2W("Wb_2W","W_{b}");       DecayRecoFrame     Wb_3W("Wb_3W","W_{b}");
                                                   DecayRecoFrame     Wc_3W("Wc_3W","W_{c}");
  VisibleRecoFrame   La_2W("La_2W","#it{l}_{a}");  VisibleRecoFrame   La_3W("La_3W","#it{l}_{a}");
  InvisibleRecoFrame Na_2W("Na_2W","#nu_{a}");     InvisibleRecoFrame Na_3W("Na_3W","#nu_{a}");
  VisibleRecoFrame   Lb_2W("Lb_2W","#it{l}_{b}");  VisibleRecoFrame   Lb_3W("Lb_3W","#it{l}_{b}");
  InvisibleRecoFrame Nb_2W("Nb_2W","#nu_{b}");     InvisibleRecoFrame Nb_3W("Nb_3W","#nu_{b}");
                                                   VisibleRecoFrame   Lc_3W("Lc_3W","#it{l}_{c}");
                                                   InvisibleRecoFrame Nc_3W("Nc_3W","#nu_{c}");

  LabRecoFrame       LAB_4W("LAB_4W","LAB");     
  DecayRecoFrame     CM_4W("CM_4W","CM");        
  DecayRecoFrame     Wa_4W("Wa_4W","W_{a}");     
  DecayRecoFrame     Wb_4W("Wb_4W","W_{b}");    
  DecayRecoFrame     Wc_4W("Wc_4W","W_{c}");
  DecayRecoFrame     Wd_4W("Wd_4W","W_{d}");
  VisibleRecoFrame   La_4W("La_4W","#it{l}_{a}"); 
  InvisibleRecoFrame Na_4W("Na_4W","#nu_{a}");   
  VisibleRecoFrame   Lb_4W("Lb_4W","#it{l}_{b}");
  InvisibleRecoFrame Nb_4W("Nb_4W","#nu_{b}");
  VisibleRecoFrame   Lc_4W("Lc_4W","#it{l}_{c}");
  InvisibleRecoFrame Nc_4W("Nc_4W","#nu_{c}");
  VisibleRecoFrame   Ld_4W("Ld_4W","#it{l}_{d}");
  InvisibleRecoFrame Nd_4W("Nd_4W","#nu_{d}");
  
  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
  
  LAB_2W.SetChildFrame(CM_2W);                   LAB_3W.SetChildFrame(CM_3W);
  CM_2W.AddChildFrame(Wa_2W);                    CM_3W.AddChildFrame(Wa_3W);
  CM_2W.AddChildFrame(Wb_2W);                    CM_3W.AddChildFrame(Wb_3W);
  Wa_2W.AddChildFrame(La_2W);                    CM_3W.AddChildFrame(Wc_3W);
  Wa_2W.AddChildFrame(Na_2W);                    Wa_3W.AddChildFrame(La_3W);
  Wb_2W.AddChildFrame(Lb_2W);                    Wa_3W.AddChildFrame(Na_3W);
  Wb_2W.AddChildFrame(Nb_2W);                    Wb_3W.AddChildFrame(Lb_3W);
                                                 Wb_3W.AddChildFrame(Nb_3W);
  LAB_4W.SetChildFrame(CM_4W);                   Wc_3W.AddChildFrame(Lc_3W);
  CM_4W.AddChildFrame(Wa_4W);                    Wc_3W.AddChildFrame(Nc_3W);                               
  CM_4W.AddChildFrame(Wb_4W);
  CM_4W.AddChildFrame(Wc_4W);
  CM_4W.AddChildFrame(Wd_4W);
  Wa_4W.AddChildFrame(La_4W);
  Wa_4W.AddChildFrame(Na_4W);
  Wb_4W.AddChildFrame(Lb_4W);
  Wb_4W.AddChildFrame(Nb_4W);
  Wc_4W.AddChildFrame(Lc_4W);
  Wc_4W.AddChildFrame(Nc_4W);
  Wd_4W.AddChildFrame(Ld_4W);
  Wd_4W.AddChildFrame(Nd_4W);

  if(LAB_2W.InitializeTree() && LAB_3W.InitializeTree() &&
     LAB_4W.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized reconstruction trees" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing reconstruction trees" << LogEnd;
 
  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

  // Invisible Groups
  InvisibleGroup INV_2W("INV_2W","#nu #nu Jigsaws");
  INV_2W.AddFrame(Na_2W);
  INV_2W.AddFrame(Nb_2W);
  InvisibleGroup INV_3W("INV_3W","#nu #nu #nu Jigsaws");
  INV_3W.AddFrame(Na_3W);
  INV_3W.AddFrame(Nb_3W);
  INV_3W.AddFrame(Nc_3W);
  InvisibleGroup INV_4W("INV_4W","#nu #nu #nu #nu Jigsaws");
  INV_4W.AddFrame(Na_4W);
  INV_4W.AddFrame(Nb_4W);
  INV_4W.AddFrame(Nc_4W);
  INV_4W.AddFrame(Nd_4W);

  // Set N nu mass equal to ~ N lep mass
  SetMassInvJigsaw NuNuM_2W("NuNuM_2W", "M_{#nu#nu} ~ m_{#it{l}#it{l}}");
  INV_2W.AddJigsaw(NuNuM_2W);
  SetMassInvJigsaw NuNuM_3W("NuNuM_3W", "M_{#nu#nu#nu} ~ m_{#it{l}#it{l}#it{l}}");
  INV_3W.AddJigsaw(NuNuM_3W);
  SetMassInvJigsaw NuNuM_4W("NuNuM_4W", "M_{#nu#nu#nu#nu} ~ m_{#it{l}#it{l}#it{l}#it{l}}");
  INV_4W.AddJigsaw(NuNuM_4W);

  // Set N nu rapidity equal to N lep rapidity
  SetRapidityInvJigsaw NuNuR_2W("NuNuR_2W", "#eta_{#nu#nu} = #eta_{#it{l}#it{l}}");
  INV_2W.AddJigsaw(NuNuR_2W);
  NuNuR_2W.AddVisibleFrames(La_2W+Lb_2W);
  SetRapidityInvJigsaw NuNuR_3W("NuNuR_3W", "#eta_{#nu#nu#nu} = #eta_{#it{l}#it{l}#it{l}}");
  INV_3W.AddJigsaw(NuNuR_3W);
  NuNuR_3W.AddVisibleFrames(La_3W+Lb_3W+Lc_3W);
  SetRapidityInvJigsaw NuNuR_4W("NuNuR_4W", "#eta_{#nu#nu#nu#nu} = #eta_{#it{l}#it{l}#it{l}#it{l}}");
  INV_4W.AddJigsaw(NuNuR_4W);
  NuNuR_4W.AddVisibleFrames(La_4W+Lb_4W+Lc_4W+Ld_4W);

  // Set neutrino 4-vectors by minimizing N W masses ^2
  MinMassesSqInvJigsaw MinMW_2W("MinMW_2W","min #Sigma M_{W}^{ 2}", 2);
  INV_2W.AddJigsaw(MinMW_2W);
  MinMW_2W.AddVisibleFrame(La_2W, 0);   MinMW_2W.AddInvisibleFrame(Na_2W, 0);
  MinMW_2W.AddVisibleFrame(Lb_2W, 1);   MinMW_2W.AddInvisibleFrame(Nb_2W, 1);
  MinMassesSqInvJigsaw MinMW_3W("MinMW_3W","min #Sigma M_{W}^{ 2}", 3);
  INV_3W.AddJigsaw(MinMW_3W);
  MinMW_3W.AddVisibleFrame(La_3W, 0);   MinMW_3W.AddInvisibleFrame(Na_3W, 0);
  MinMW_3W.AddVisibleFrame(Lb_3W, 1);   MinMW_3W.AddInvisibleFrame(Nb_3W, 1);
  MinMW_3W.AddVisibleFrame(Lc_3W, 2);   MinMW_3W.AddInvisibleFrame(Nc_3W, 2);
  MinMassesSqInvJigsaw MinMW_4W("MinMW_4W","min #Sigma M_{W}^{ 2}", 4);
  INV_4W.AddJigsaw(MinMW_4W);
  MinMW_4W.AddVisibleFrame(La_4W, 0);   MinMW_4W.AddInvisibleFrame(Na_4W, 0);
  MinMW_4W.AddVisibleFrame(Lb_4W, 1);   MinMW_4W.AddInvisibleFrame(Nb_4W, 1);
  MinMW_4W.AddVisibleFrame(Lc_4W, 2);   MinMW_4W.AddInvisibleFrame(Nc_4W, 2);
  MinMW_4W.AddVisibleFrame(Ld_4W, 3);   MinMW_4W.AddInvisibleFrame(Nd_4W, 3);

  if(LAB_2W.InitializeAnalysis() && LAB_3W.InitializeAnalysis() &&
     LAB_4W.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized analyses" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing analyses" << LogEnd;

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  TreePlot* treePlot = new TreePlot("TreePlot","TreePlot");
  
  treePlot->SetTree(CM_2W);
  treePlot->Draw("Reco_2W_Tree", "2W Reconstruction Tree");

  treePlot->SetTree(CM_3W);
  treePlot->Draw("Reco_3W_Tree", "3W Reconstruction Tree");

  treePlot->SetTree(CM_4W);
  treePlot->Draw("Reco_4W_Tree", "4W Reconstruction Tree");

  treePlot->SetTree(INV_2W);
  treePlot->Draw("Inv_2W_Tree", "2W Inivisible Jigsaws", true);

  treePlot->SetTree(INV_3W);
  treePlot->Draw("Inv_3W_Tree", "3W Inivisible Jigsaws", true);

  treePlot->SetTree(INV_4W);
  treePlot->Draw("Inv_4W_Tree", "4W Inivisible Jigsaws", true);

  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
  
  HistPlot* histPlot   = new HistPlot("HistPlot","pp #rightarrow N W(#it{l} #nu)");

  const HistPlotCategory& cat_2W = histPlot->GetNewCategory("Reco_2W", "2 W(#it{l} #nu)");
  const HistPlotCategory& cat_3W = histPlot->GetNewCategory("Reco_3W", "3 W(#it{l} #nu)");
  const HistPlotCategory& cat_4W = histPlot->GetNewCategory("Reco_4W", "4 W(#it{l} #nu)");

  const HistPlotVar& MCM    = histPlot->GetNewVar("MCM", "M_{CM} / m_{CM}^{ true}", 0., 2.);
  const HistPlotVar& sumMW2 = histPlot->GetNewVar("MWTOT",
		   "#sqrt{#Sigma M_{W}^{ 2} / #Sigma m_{W, true}^{ 2}}", 0., 1.5);
  double sumMW2gen;
  
  histPlot->AddPlot(MCM,    cat_2W+cat_3W+cat_4W);
  histPlot->AddPlot(sumMW2, cat_2W+cat_3W+cat_4W);
  histPlot->AddPlot(MCM, sumMW2, cat_2W+cat_3W+cat_4W);

  
  for(int igen = 0; igen < Ngen; igen++){
    if(igen%(Ngen/10) == 0) 
      g_Log << LogInfo << "Generating event " << igen << " of " << Ngen << LogEnd;

    // generate event
    LAB_G2W.ClearEvent();                            // clear the gen tree;
    LAB_G2W.AnalyzeEvent();                          // generate a new event
    LAB_G3W.ClearEvent();                                   
    LAB_G3W.AnalyzeEvent();                         
    LAB_G4W.ClearEvent();                                
    LAB_G4W.AnalyzeEvent();                        

    TVector3 MET_2W = LAB_G2W.GetInvisibleMomentum();  // Get the MET from gen tree
    MET_2W.SetZ(0.);
    TVector3 MET_3W = LAB_G3W.GetInvisibleMomentum();  
    MET_3W.SetZ(0.);
    TVector3 MET_4W = LAB_G4W.GetInvisibleMomentum(); 
    MET_4W.SetZ(0.);

    // analyze event(s)
    LAB_2W.ClearEvent();                                  // clear the reco tree
    INV_2W.SetLabFrameThreeVector(MET_2W);                // Set the MET in reco tree
    LAB_3W.ClearEvent();                              
    INV_3W.SetLabFrameThreeVector(MET_3W);            
    LAB_4W.ClearEvent();                           
    INV_4W.SetLabFrameThreeVector(MET_4W);              

    La_2W.SetLabFrameFourVector(La_G2W.GetFourVector());  // Set "measured" lep 4-vectors
    Lb_2W.SetLabFrameFourVector(Lb_G2W.GetFourVector());
    La_3W.SetLabFrameFourVector(La_G3W.GetFourVector()); 
    Lb_3W.SetLabFrameFourVector(Lb_G3W.GetFourVector());
    Lc_3W.SetLabFrameFourVector(Lc_G3W.GetFourVector());
    La_4W.SetLabFrameFourVector(La_G4W.GetFourVector()); 
    Lb_4W.SetLabFrameFourVector(Lb_G4W.GetFourVector());
    Lc_4W.SetLabFrameFourVector(Lc_G4W.GetFourVector());
    Ld_4W.SetLabFrameFourVector(Ld_G4W.GetFourVector());

    LAB_2W.AnalyzeEvent();                                // analyze the event
    LAB_3W.AnalyzeEvent();
    LAB_4W.AnalyzeEvent();
    
    //////////////////////////////////////
    // Observable Calculations
    //////////////////////////////////////
    
    MCM = CM_2W.GetMass()/CM_G2W.GetMass();
    sumMW2  = Wa_2W.GetMass()*Wa_2W.GetMass();
    sumMW2 += Wb_2W.GetMass()*Wb_2W.GetMass();
    sumMW2gen  = Wa_G2W.GetMass()*Wa_G2W.GetMass();
    sumMW2gen += Wb_G2W.GetMass()*Wb_G2W.GetMass();
    sumMW2 /= sumMW2gen;
    sumMW2 = sqrt(sumMW2);

    histPlot->Fill(cat_2W);

    MCM = CM_3W.GetMass()/CM_G3W.GetMass();
    sumMW2  = Wa_3W.GetMass()*Wa_3W.GetMass();
    sumMW2 += Wb_3W.GetMass()*Wb_3W.GetMass();
    sumMW2 += Wc_3W.GetMass()*Wc_3W.GetMass();
    sumMW2gen  = Wa_G3W.GetMass()*Wa_G3W.GetMass();
    sumMW2gen += Wb_G3W.GetMass()*Wb_G3W.GetMass();
    sumMW2gen += Wc_G3W.GetMass()*Wc_G3W.GetMass();
    sumMW2 /= sumMW2gen;
    sumMW2 = sqrt(sumMW2);

    histPlot->Fill(cat_3W);

    MCM = CM_4W.GetMass()/CM_G4W.GetMass();
    sumMW2  = Wa_4W.GetMass()*Wa_4W.GetMass();
    sumMW2 += Wb_4W.GetMass()*Wb_4W.GetMass();
    sumMW2 += Wc_4W.GetMass()*Wc_4W.GetMass();
    sumMW2 += Wd_4W.GetMass()*Wd_4W.GetMass();
    sumMW2gen  = Wa_G4W.GetMass()*Wa_G4W.GetMass();
    sumMW2gen += Wb_G4W.GetMass()*Wb_G4W.GetMass();
    sumMW2gen += Wc_G4W.GetMass()*Wc_G4W.GetMass();
    sumMW2gen += Wd_G4W.GetMass()*Wd_G4W.GetMass();
    sumMW2 /= sumMW2gen;
    sumMW2 = sqrt(sumMW2);

    histPlot->Fill(cat_4W);
  }

  histPlot->Draw();

  TFile fout(output_name.c_str(),"RECREATE");
  fout.Close();
  histPlot->WriteOutput(output_name);
  histPlot->WriteHist(output_name);
  treePlot->WriteOutput(output_name);

  g_Log << LogInfo << "Finished" << LogEnd;
}
void example_ttbar_to_bWlnubWlnu(const std::string output_name =
				 "output_ttbar_to_bWlnubWlnu.root"){

  double mT = 173.21; // GeV, PDG 2016
  double mW = 80.385;
  double mB = 4.18;
  double mL = 0.106;
  double mN = 0.;

  // number of events to generate
  int Ngen = 100000;

  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing generator frames and tree..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  ppLabGenFrame     LAB_Gen("LAB_Gen","LAB");
  DecayGenFrame     TT_Gen("TT_Gen","t #bar{t}");
  DecayGenFrame     Ta_Gen("Ta_Gen","t_{a}");
  DecayGenFrame     Tb_Gen("Tb_Gen","t_{b}");
  DecayGenFrame     Wa_Gen("Wa_Gen","W_{a}");
  DecayGenFrame     Wb_Gen("Wb_Gen","W_{b}");
  VisibleGenFrame   Ba_Gen("Ba_Gen","b_{a}");
  VisibleGenFrame   La_Gen("La_Gen","#it{l}_{a}");
  InvisibleGenFrame Na_Gen("Na_Gen","#nu_{a}");
  VisibleGenFrame   Bb_Gen("Bb_Gen","b_{b}");
  VisibleGenFrame   Lb_Gen("Lb_Gen","#it{l}_{b}");
  InvisibleGenFrame Nb_Gen("Nb_Gen","#nu_{b}");

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

  LAB_Gen.SetChildFrame(TT_Gen);
  TT_Gen.AddChildFrame(Ta_Gen);
  TT_Gen.AddChildFrame(Tb_Gen);
  Ta_Gen.AddChildFrame(Ba_Gen);
  Ta_Gen.AddChildFrame(Wa_Gen);
  Tb_Gen.AddChildFrame(Bb_Gen);
  Tb_Gen.AddChildFrame(Wb_Gen);
  Wa_Gen.AddChildFrame(La_Gen);
  Wa_Gen.AddChildFrame(Na_Gen);
  Wb_Gen.AddChildFrame(Lb_Gen);
  Wb_Gen.AddChildFrame(Nb_Gen);

  if(LAB_Gen.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized generator tree" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator tree" << LogEnd;							        
  
  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

  // non-resonant ttbar production
  TT_Gen.SetVariableMass();
  // set top masses
  Ta_Gen.SetMass(mT);            Tb_Gen.SetMass(mT);
  // set W masses
  Wa_Gen.SetMass(mW);            Wb_Gen.SetMass(mW);
  // set B masses
  Ba_Gen.SetMass(mB);            Bb_Gen.SetMass(mB);
  // set : masses
  La_Gen.SetMass(mL);            Lb_Gen.SetMass(mL);
  // set neutrino masses
  Na_Gen.SetMass(mN);            Nb_Gen.SetMass(mN);

  // set b-jet/lepton pT/eta cuts
  Ba_Gen.SetPtCut(20.);          Bb_Gen.SetPtCut(20.);
  Ba_Gen.SetEtaCut(2.5);         Bb_Gen.SetEtaCut(2.5);
  La_Gen.SetPtCut(15.);          Lb_Gen.SetPtCut(15.);
  La_Gen.SetEtaCut(2.5);         Lb_Gen.SetEtaCut(2.5);

  if(LAB_Gen.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized generator analysis" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator analysis" << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////								    
  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing reconstruction frames and trees..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  LabRecoFrame       LAB_R1("LAB_R1","LAB");      LabRecoFrame       LAB_R2("LAB_R2","LAB");
  DecayRecoFrame     TT_R1("TT_R1","t #bar{t}");  DecayRecoFrame     TT_R2("TT_R2","t #bar{t}");
  DecayRecoFrame     Ta_R1("Ta_R1","t_{a}");      DecayRecoFrame     Ta_R2("Ta_R2","t_{a}");
  DecayRecoFrame     Tb_R1("Tb_R1","t_{b}");      DecayRecoFrame     Tb_R2("Tb_R2","t_{b}");
  DecayRecoFrame     Wa_R1("Wa_R1","W_{a}");      DecayRecoFrame     Wa_R2("Wa_R2","W_{a}");
  DecayRecoFrame     Wb_R1("Wb_R1","W_{b}");      DecayRecoFrame     Wb_R2("Wb_R2","W_{b}");
  VisibleRecoFrame   Ba_R1("Ba_R1","b_{a}");      VisibleRecoFrame   Ba_R2("Ba_R2","b_{a}");
  VisibleRecoFrame   La_R1("La_R1","#it{l}_{a}"); VisibleRecoFrame   La_R2("La_R2","#it{l}_{a}");
  InvisibleRecoFrame Na_R1("Na_R1","#nu_{a}");    InvisibleRecoFrame Na_R2("Na_R2","#nu_{a}");
  VisibleRecoFrame   Bb_R1("Bb_R1","b_{b}");      VisibleRecoFrame   Bb_R2("Bb_R2","b_{b}");
  VisibleRecoFrame   Lb_R1("Lb_R1","#it{l}_{b}"); VisibleRecoFrame   Lb_R2("Lb_R2","#it{l}_{b}");
  InvisibleRecoFrame Nb_R1("Nb_R1","#nu_{b}");    InvisibleRecoFrame Nb_R2("Nb_R2","#nu_{b}");

  LabRecoFrame       LAB_R3("LAB_R3","LAB");      LabRecoFrame       LAB_R4("LAB_R4","LAB");
  DecayRecoFrame     TT_R3("TT_R3","t #bar{t}");  DecayRecoFrame     TT_R4("TT_R4","t #bar{t}");
  DecayRecoFrame     Ta_R3("Ta_R3","t_{a}");      DecayRecoFrame     Ta_R4("Ta_R4","t_{a}");
  DecayRecoFrame     Tb_R3("Tb_R3","t_{b}");      DecayRecoFrame     Tb_R4("Tb_R4","t_{b}");
  DecayRecoFrame     Wa_R3("Wa_R3","W_{a}");      DecayRecoFrame     Wa_R4("Wa_R4","W_{a}");
  DecayRecoFrame     Wb_R3("Wb_R3","W_{b}");      DecayRecoFrame     Wb_R4("Wb_R4","W_{b}");
  VisibleRecoFrame   Ba_R3("Ba_R3","b_{a}");      VisibleRecoFrame   Ba_R4("Ba_R4","b_{a}");
  VisibleRecoFrame   La_R3("La_R3","#it{l}_{a}"); VisibleRecoFrame   La_R4("La_R4","#it{l}_{a}");
  InvisibleRecoFrame Na_R3("Na_R3","#nu_{a}");    InvisibleRecoFrame Na_R4("Na_R4","#nu_{a}");
  VisibleRecoFrame   Bb_R3("Bb_R3","b_{b}");      VisibleRecoFrame   Bb_R4("Bb_R4","b_{b}");
  VisibleRecoFrame   Lb_R3("Lb_R3","#it{l}_{b}"); VisibleRecoFrame   Lb_R4("Lb_R4","#it{l}_{b}");
  InvisibleRecoFrame Nb_R3("Nb_R3","#nu_{b}");    InvisibleRecoFrame Nb_R4("Nb_R4","#nu_{b}");

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

  LAB_R1.SetChildFrame(TT_R1);                    LAB_R2.SetChildFrame(TT_R2);
  TT_R1.AddChildFrame(Ta_R1);                     TT_R2.AddChildFrame(Ta_R2);
  TT_R1.AddChildFrame(Tb_R1);                     TT_R2.AddChildFrame(Tb_R2);
  Ta_R1.AddChildFrame(Ba_R1);                     Ta_R2.AddChildFrame(Ba_R2);
  Ta_R1.AddChildFrame(Wa_R1);                     Ta_R2.AddChildFrame(Wa_R2);
  Tb_R1.AddChildFrame(Bb_R1);                     Tb_R2.AddChildFrame(Bb_R2);
  Tb_R1.AddChildFrame(Wb_R1);                     Tb_R2.AddChildFrame(Wb_R2);
  Wa_R1.AddChildFrame(La_R1);                     Wa_R2.AddChildFrame(La_R2);
  Wa_R1.AddChildFrame(Na_R1);                     Wa_R2.AddChildFrame(Na_R2);
  Wb_R1.AddChildFrame(Lb_R1);                     Wb_R2.AddChildFrame(Lb_R2);
  Wb_R1.AddChildFrame(Nb_R1);                     Wb_R2.AddChildFrame(Nb_R2);

  LAB_R3.SetChildFrame(TT_R3);                    LAB_R4.SetChildFrame(TT_R4);
  TT_R3.AddChildFrame(Ta_R3);                     TT_R4.AddChildFrame(Ta_R4);
  TT_R3.AddChildFrame(Tb_R3);                     TT_R4.AddChildFrame(Tb_R4);
  Ta_R3.AddChildFrame(Ba_R3);                     Ta_R4.AddChildFrame(Ba_R4);
  Ta_R3.AddChildFrame(Wa_R3);                     Ta_R4.AddChildFrame(Wa_R4);
  Tb_R3.AddChildFrame(Bb_R3);                     Tb_R4.AddChildFrame(Bb_R4);
  Tb_R3.AddChildFrame(Wb_R3);                     Tb_R4.AddChildFrame(Wb_R4);
  Wa_R3.AddChildFrame(La_R3);                     Wa_R4.AddChildFrame(La_R4);
  Wa_R3.AddChildFrame(Na_R3);                     Wa_R4.AddChildFrame(Na_R4);
  Wb_R3.AddChildFrame(Lb_R3);                     Wb_R4.AddChildFrame(Lb_R4);
  Wb_R3.AddChildFrame(Nb_R3);                     Wb_R4.AddChildFrame(Nb_R4);

  if(LAB_R1.InitializeTree() && LAB_R2.InitializeTree() && 
     LAB_R3.InitializeTree() && LAB_R4.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized reconstruction trees" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing reconstruction trees" << LogEnd;
 
  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//

  //////////////////////// define Groups for reconstruction trees ////////////////////////
  std::string group_name;

  // Invisible Group
  group_name = "#splitline{#nu #nu Jigsaws for}{min M_{top} , M_{top}^{ a} = M_{top}^{ b}}";
  InvisibleGroup INV_R1("INV_R1", group_name);
  INV_R1.AddFrame(Na_R1);
  INV_R1.AddFrame(Nb_R1);
  // Combinatoric Group for b's
  CombinatoricGroup B_R1("VIS_R1","b-jet Jigsaws");
  B_R1.AddFrame(Ba_R1);
  B_R1.AddFrame(Bb_R1);
  // b-jet frames must have at least one element
  B_R1.SetNElementsForFrame(Ba_R1, 1);
  B_R1.SetNElementsForFrame(Bb_R1, 1);

  group_name = "#splitline{#nu #nu Jigsaws for}{min M_{W}, M_{W}^{ a} = M_{W}^{ b}}";
  InvisibleGroup INV_R2("INV_R2", group_name);
  INV_R2.AddFrame(Na_R2);
  INV_R2.AddFrame(Nb_R2);
  CombinatoricGroup B_R2("VIS_R2","b-jet Jigsaws");
  B_R2.AddFrame(Ba_R2);
  B_R2.AddFrame(Bb_R2);
  B_R2.SetNElementsForFrame(Ba_R2, 1);
  B_R2.SetNElementsForFrame(Bb_R2, 1);

  group_name = "#splitline{#nu #nu Jigsaws for}{min M_{top a}^{2}+ M_{top b}^{2}}";
  InvisibleGroup INV_R3("INV_R3", group_name);
  INV_R3.AddFrame(Na_R3);
  INV_R3.AddFrame(Nb_R3);
  CombinatoricGroup B_R3("VIS_R3","b-jet Jigsaws");
  B_R3.AddFrame(Ba_R3);
  B_R3.AddFrame(Bb_R3);
  B_R3.SetNElementsForFrame(Ba_R3, 1);
  B_R3.SetNElementsForFrame(Bb_R3, 1);

  group_name = "#splitline{#nu #nu Jigsaws for}{min (M_{top a}- M_{top b})^{2}}";
  InvisibleGroup INV_R4("INV_R4", group_name);
  INV_R4.AddFrame(Na_R4);
  INV_R4.AddFrame(Nb_R4);
  CombinatoricGroup B_R4("VIS_R4","b-jet Jigsaws");
  B_R4.AddFrame(Ba_R4);
  B_R4.AddFrame(Bb_R4);
  B_R4.SetNElementsForFrame(Ba_R4, 1);
  B_R4.SetNElementsForFrame(Bb_R4, 1);

  //////////////////////// define Jigsaws for reconstruction trees ////////////////////////
  std::string jigsaw_name;

  // Minimize equal top masses neutrino jigsaws
  jigsaw_name = "M_{#nu#nu} = f(m_{b#it{l}b#it{l}} , m_{b#it{l}}^{ a} , m_{b#it{l}}^{ b})";
  SetMassInvJigsaw NuNuM_R1("NuNuM_R1", jigsaw_name);
  INV_R1.AddJigsaw(NuNuM_R1);

  jigsaw_name = "#eta_{#nu#nu} = #eta_{b #it{l} b #it{l}}";
  SetRapidityInvJigsaw NuNuR_R1("NuNuR_R1", jigsaw_name);
  INV_R1.AddJigsaw(NuNuR_R1);
  NuNuR_R1.AddVisibleFrames(La_R1+Ba_R1+Lb_R1+Bb_R1);

  jigsaw_name = "min M_{top}, M_{top}^{ a} = M_{top}^{ b}";
  ContraBoostInvJigsaw MinMt_R1("MinMt_R1", jigsaw_name);
  INV_R1.AddJigsaw(MinMt_R1);
  MinMt_R1.AddVisibleFrames(La_R1+Ba_R1, 0);
  MinMt_R1.AddVisibleFrames(Lb_R1+Bb_R1, 1);
  MinMt_R1.AddInvisibleFrame(Na_R1, 0);
  MinMt_R1.AddInvisibleFrame(Nb_R1, 1);

  // Minimize equal W masses neutrino jigsaws
  jigsaw_name = "M_{#nu#nu} = f(m_{#it{l}#it{l}} , m_{#it{l}}^{ a} , m_{#it{l}}^{ b})";
  SetMassInvJigsaw NuNuM_R2("NuNuM_R2", jigsaw_name);
  INV_R2.AddJigsaw(NuNuM_R2);

  jigsaw_name = "#eta_{#nu#nu} = #eta_{b #it{l} b #it{l}}";
  SetRapidityInvJigsaw NuNuR_R2("NuNuR_R2", jigsaw_name);
  INV_R2.AddJigsaw(NuNuR_R2);
  NuNuR_R2.AddVisibleFrames(La_R2+Ba_R2+Lb_R2+Bb_R2);

  jigsaw_name = "min M_{W}, M_{W}^{ a} = M_{W}^{ b}";
  ContraBoostInvJigsaw MinMW_R2("MinMW_R2", jigsaw_name);
  INV_R2.AddJigsaw(MinMW_R2);
  MinMW_R2.AddVisibleFrame(La_R2, 0);
  MinMW_R2.AddVisibleFrame(Lb_R2, 1);
  MinMW_R2.AddInvisibleFrame(Na_R2, 0);
  MinMW_R2.AddInvisibleFrame(Nb_R2, 1);

  // Minimize sum Mt^2 jigsaws
  jigsaw_name = "M_{#nu#nu} = f(m_{#it{l}#it{l}} , m_{#it{l}}^{ a} , m_{#it{l}}^{ b})";
  SetMassInvJigsaw NuNuM_R3("NuNuM_R3", jigsaw_name);
  INV_R3.AddJigsaw(NuNuM_R3);

  jigsaw_name = "#eta_{#nu#nu} = #eta_{b #it{l} b #it{l}}";
  SetRapidityInvJigsaw NuNuR_R3("NuNuR_R3", jigsaw_name);
  INV_R3.AddJigsaw(NuNuR_R3);
  NuNuR_R3.AddVisibleFrames(LAB_R3.GetListVisibleFrames());

  jigsaw_name = "min #Sigma M_{top}^{2}";
  MinMassesSqInvJigsaw MinMt_R3("MinMt_R3", jigsaw_name, 2);
  INV_R3.AddJigsaw(MinMt_R3);
  MinMt_R3.AddInvisibleFrame(Na_R3, 0);
  MinMt_R3.AddInvisibleFrame(Nb_R3, 1);
  MinMt_R3.AddVisibleFrames(La_R3+Ba_R3, 0);
  MinMt_R3.AddVisibleFrames(Lb_R3+Bb_R3, 1);
  MinMt_R3.AddMassFrame(La_R3, 0);
  MinMt_R3.AddMassFrame(Lb_R3, 1);

  // Minimize difference Mt jigsaws
  jigsaw_name = "M_{#nu#nu} = f(m_{#it{l}#it{l}} , m_{#it{l}}^{ a} , m_{#it{l}}^{ b})";
  SetMassInvJigsaw NuNuM_R4("NuNuM_R4", jigsaw_name);
  INV_R4.AddJigsaw(NuNuM_R4);

  jigsaw_name = "#eta_{#nu#nu} = #eta_{b #it{l} b #it{l}}";
  SetRapidityInvJigsaw NuNuR_R4("NuNuR_R4", jigsaw_name);
  INV_R4.AddJigsaw(NuNuR_R4);
  NuNuR_R4.AddVisibleFrames(LAB_R4.GetListVisibleFrames());

  jigsaw_name = "min ( M_{top a}- M_{top b} )^{2}";
  MinMassDiffInvJigsaw MinDeltaMt_R4("MinDeltaMt_R4", jigsaw_name, 2);
  INV_R4.AddJigsaw(MinDeltaMt_R4);
  MinDeltaMt_R4.AddInvisibleFrame(Na_R4, 0);
  MinDeltaMt_R4.AddInvisibleFrame(Nb_R4, 1);
  MinDeltaMt_R4.AddVisibleFrames(La_R4+Ba_R4, 0);
  MinDeltaMt_R4.AddVisibleFrames(Lb_R4+Bb_R4, 1);
  MinDeltaMt_R4.AddMassFrame(La_R4, 0);
  MinDeltaMt_R4.AddMassFrame(Lb_R4, 1);

  // b-jet combinatoric jigsaws for all trees
  jigsaw_name = "Minimize M(b #it{l} )_{a} , M(b #it{l} )_{b}";

  MinMassesCombJigsaw MinBL_R1("MinBL_R1", jigsaw_name);
  B_R1.AddJigsaw(MinBL_R1);
  MinBL_R1.AddFrames(La_R1+Ba_R1,0);
  MinBL_R1.AddFrames(Lb_R1+Bb_R1,1);

  MinMassesCombJigsaw MinBL_R2("MinBL_R2", jigsaw_name);
  B_R2.AddJigsaw(MinBL_R2);
  MinBL_R2.AddFrames(La_R2+Ba_R2,0);
  MinBL_R2.AddFrames(Lb_R2+Bb_R2,1);

  MinMassesCombJigsaw MinBL_R3("MinBL_R3", jigsaw_name);
  B_R3.AddJigsaw(MinBL_R3);
  MinBL_R3.AddFrames(La_R3+Ba_R3,0);
  MinBL_R3.AddFrames(Lb_R3+Bb_R3,1);

  MinMassesCombJigsaw MinBL_R4("MinBL_R4", jigsaw_name);
  B_R4.AddJigsaw(MinBL_R4);
  MinBL_R4.AddFrames(La_R4+Ba_R4,0);
  MinBL_R4.AddFrames(Lb_R4+Bb_R4,1);

  if(LAB_R1.InitializeAnalysis() && LAB_R2.InitializeAnalysis() && 
     LAB_R3.InitializeAnalysis() && LAB_R4.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized analysis" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing analysis" << LogEnd;	

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  TreePlot* treePlot = new TreePlot("TreePlot","TreePlot");
 
  treePlot->SetTree(LAB_Gen);
  treePlot->Draw("GenTree", "Generator Tree", true);
  
  treePlot->SetTree(LAB_R1);
  treePlot->Draw("RecoTree", "Reconstruction Tree");

  treePlot->SetTree(B_R1);
  treePlot->Draw("VisTree", "b-jet Jigsaws", true);

  treePlot->SetTree(INV_R1);
  treePlot->Draw("InvTree_R1", "Inivisibl Jigsaws", true);

  treePlot->SetTree(INV_R2);
  treePlot->Draw("InvTree_R2", "Inivisibl Jigsaws", true);

  treePlot->SetTree(INV_R3);
  treePlot->Draw("InvTree_R3", "Inivisibl Jigsaws", true);

  treePlot->SetTree(INV_R4);
  treePlot->Draw("InvTree_R4", "Inivisibl Jigsaws", true);

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

  HistPlot* histPlot = new HistPlot("HistPlot", "t #bar{t} #rightarrow b W(#it{l} #nu) b W(#it{l} #nu)");

  const HistPlotCategory& cat_Gen = histPlot->GetNewCategory("Gen",  "Generator");
  const HistPlotCategory& cat_R1  = histPlot->GetNewCategory("Reco1", "M_{top}^{ a} = M_{top}^{ b} Reco");
  const HistPlotCategory& cat_R2  = histPlot->GetNewCategory("Reco2", "M_{W}^{ a} = M_{W}^{ b} Reco");
  const HistPlotCategory& cat_R3  = histPlot->GetNewCategory("Reco3", "min #Sigma M_{top}^{ 2} Reco");
  const HistPlotCategory& cat_R4  = histPlot->GetNewCategory("Reco4", "min #Delta M_{top} Reco");

  const HistPlotVar& Mtt    = histPlot->GetNewVar("Mtt", "M_{t #bar{t}} / m_{t #bar{t}}", 0., 2.);
  const HistPlotVar& Eb_ta  = histPlot->GetNewVar("Eb_ta", "E_{b a}^{top a} / E_{b a}^{top a gen}", 0., 2.);
  const HistPlotVar& Eb_tb  = histPlot->GetNewVar("Eb_tb", "E_{b b}^{top b} / E_{b b}^{top b gen}", 0., 2.);
  const HistPlotVar& El_Wa  = histPlot->GetNewVar("El_Wa", "E_{#it{l} a}^{W a} / E_{#it{l} a}^{W a gen}", 0., 2.);
  const HistPlotVar& El_Wb  = histPlot->GetNewVar("El_Wb", "E_{#it{l} b}^{W b} / E_{#it{l} b}^{W b gen}", 0., 2.);
  const HistPlotVar& costt  = histPlot->GetNewVar("costt","cos #theta_{t #bar{t}}", -1., 1.);
  const HistPlotVar& costa  = histPlot->GetNewVar("costa","cos #theta_{top a}", -1., 1.);
  const HistPlotVar& costb  = histPlot->GetNewVar("costb","cos #theta_{top b}", -1., 1.);
  const HistPlotVar& cosWa  = histPlot->GetNewVar("cosWa","cos #theta_{W a}", -1., 1.);
  const HistPlotVar& cosWb  = histPlot->GetNewVar("cosWb","cos #theta_{W b}", -1., 1.);
  const HistPlotVar& Dcostt = histPlot->GetNewVar("Dcostt","#theta_{t #bar{t}} - #theta_{t #bar{t}}^{gen}", 
						  -acos(-1.)/2., acos(-1.)/2.);
  const HistPlotVar& Dcosta = histPlot->GetNewVar("Dcosta","#theta_{top a} - #theta_{top a}^{gen}", 
						  -acos(-1.)/2., acos(-1.)/2.);
  const HistPlotVar& Dcostb = histPlot->GetNewVar("Dcostb","#theta_{top b} - #theta_{top b}^{gen}", 
						  -acos(-1.)/2., acos(-1.)/2.);
  const HistPlotVar& DcosWa = histPlot->GetNewVar("DcosWa","#theta_{W a} - #theta_{W a}^{gen}", 
						  -acos(-1.)/2., acos(-1.)/2.);
  const HistPlotVar& DcosWb = histPlot->GetNewVar("DcosWb","#theta_{W b} - #theta_{W b}^{gen}", 
						  -acos(-1.)/2., acos(-1.)/2.);

  histPlot->AddPlot(Mtt,   cat_R1+cat_R2+cat_R3+cat_R4);
  histPlot->AddPlot(Eb_ta, cat_R1+cat_R2+cat_R3+cat_R4);
  histPlot->AddPlot(El_Wa, cat_R1+cat_R2+cat_R3+cat_R4);
  histPlot->AddPlot(Dcostt, cat_R1+cat_R2+cat_R3+cat_R4);
  histPlot->AddPlot(Dcosta, cat_R1+cat_R2+cat_R3+cat_R4);
  histPlot->AddPlot(DcosWa, cat_R1+cat_R2+cat_R3+cat_R4);

  histPlot->AddPlot(Mtt, Eb_ta, cat_R4);
  histPlot->AddPlot(Mtt, El_Wa, cat_R4);
  histPlot->AddPlot(Eb_ta, Eb_tb, cat_R4);
  histPlot->AddPlot(El_Wa, El_Wb, cat_R4);
  histPlot->AddPlot(Eb_ta, El_Wa, cat_R4);
  histPlot->AddPlot(Eb_ta, El_Wb, cat_R4);
  histPlot->AddPlot(Dcostt, Mtt,  cat_R4);
  histPlot->AddPlot(Dcosta, Eb_ta, cat_R4);
  histPlot->AddPlot(DcosWa, El_Wa, cat_R4);
  histPlot->AddPlot(Dcostt, Dcosta, cat_R4);
  histPlot->AddPlot(Dcosta, Dcostb, cat_R4);
  histPlot->AddPlot(DcosWa, DcosWb, cat_R4);
  histPlot->AddPlot(Dcosta, DcosWa, cat_R4);

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  for(int igen = 0; igen < Ngen; igen++){
    if(igen%((std::max(Ngen,10))/10) == 0)
      g_Log << LogInfo << "Generating event " << igen << " of " << Ngen << LogEnd;

    // generate event
    LAB_Gen.ClearEvent();                             // clear the gen tree
  
    LAB_Gen.AnalyzeEvent();                           // generate a new event

    // analyze event three different ways
    TVector3 MET = LAB_Gen.GetInvisibleMomentum();    // Get the MET from gen tree
    MET.SetZ(0.);

    LAB_R1.ClearEvent();   
    LAB_R2.ClearEvent(); 
    LAB_R3.ClearEvent(); 
    LAB_R4.ClearEvent(); 
             
    INV_R1.SetLabFrameThreeVector(MET); 
    INV_R2.SetLabFrameThreeVector(MET); 
    INV_R3.SetLabFrameThreeVector(MET);
    INV_R4.SetLabFrameThreeVector(MET);

    La_R1.SetLabFrameFourVector(La_Gen.GetFourVector());
    Lb_R1.SetLabFrameFourVector(Lb_Gen.GetFourVector());
    La_R2.SetLabFrameFourVector(La_Gen.GetFourVector());
    Lb_R2.SetLabFrameFourVector(Lb_Gen.GetFourVector());
    La_R3.SetLabFrameFourVector(La_Gen.GetFourVector());
    Lb_R3.SetLabFrameFourVector(Lb_Gen.GetFourVector());
    La_R4.SetLabFrameFourVector(La_Gen.GetFourVector());
    Lb_R4.SetLabFrameFourVector(Lb_Gen.GetFourVector());

    std::vector<RFKey> B_R1_ID; // ID for tracking jets in tree
    B_R1_ID.push_back(B_R1.AddLabFrameFourVector(Ba_Gen.GetFourVector()));
    B_R1_ID.push_back(B_R1.AddLabFrameFourVector(Bb_Gen.GetFourVector()));
    B_R2.AddLabFrameFourVector(Ba_Gen.GetFourVector());
    B_R2.AddLabFrameFourVector(Bb_Gen.GetFourVector());
    B_R3.AddLabFrameFourVector(Ba_Gen.GetFourVector());
    B_R3.AddLabFrameFourVector(Bb_Gen.GetFourVector());
    B_R4.AddLabFrameFourVector(Ba_Gen.GetFourVector());
    B_R4.AddLabFrameFourVector(Bb_Gen.GetFourVector());
   
    LAB_R1.AnalyzeEvent(); // analyze the event
    LAB_R2.AnalyzeEvent();     
    LAB_R3.AnalyzeEvent(); 
    LAB_R4.AnalyzeEvent(); 

    //////////////////////////////////////
    // Observable Calculations
    //////////////////////////////////////

    double Mttgen   = TT_Gen.GetMass();
    double Eb_tagen = Ba_Gen.GetFourVector(Ta_Gen).E();
    double Eb_tbgen = Bb_Gen.GetFourVector(Tb_Gen).E();
    double El_Wagen = La_Gen.GetFourVector(Wa_Gen).E();
    double El_Wbgen = Lb_Gen.GetFourVector(Wb_Gen).E();
    double costtgen = TT_Gen.GetCosDecayAngle();
    double costagen = Ta_Gen.GetCosDecayAngle();
    double costbgen = Tb_Gen.GetCosDecayAngle();
    double cosWagen = Wa_Gen.GetCosDecayAngle();
    double cosWbgen = Wb_Gen.GetCosDecayAngle();

    Mtt = TT_R1.GetMass()/Mttgen;
    // Mta = Ta_R1.GetMass();
    // Mtb = Tb_R1.GetMass();
    // MWa = Wa_R1.GetMass();
    // MWb = Wb_R1.GetMass();
    Eb_ta = Ba_R1.GetFourVector(Ta_R1).E()/Eb_tagen;
    Eb_tb = Bb_R1.GetFourVector(Tb_R1).E()/Eb_tbgen;
    El_Wa = La_R1.GetFourVector(Wa_R1).E()/El_Wagen;
    El_Wb = Lb_R1.GetFourVector(Wb_R1).E()/El_Wbgen;
    costt = TT_R1.GetCosDecayAngle();
    costa = Ta_R1.GetCosDecayAngle();
    costb = Tb_R1.GetCosDecayAngle();
    cosWa = Wa_R1.GetCosDecayAngle();
    cosWb = Wb_R1.GetCosDecayAngle();
    Dcostt = asin(sqrt(1.-costt*costt)*costtgen-sqrt(1.-costtgen*costtgen)*costt);
    Dcosta = asin(sqrt(1.-costa*costa)*costagen-sqrt(1.-costagen*costagen)*costa);
    Dcostb = asin(sqrt(1.-costb*costb)*costbgen-sqrt(1.-costbgen*costbgen)*costb);
    DcosWa = asin(sqrt(1.-cosWa*cosWa)*cosWagen-sqrt(1.-cosWagen*cosWagen)*cosWa);
    DcosWb = asin(sqrt(1.-cosWb*cosWb)*cosWbgen-sqrt(1.-cosWbgen*cosWbgen)*cosWb);

    histPlot->Fill(cat_R1);

    Mtt = TT_R2.GetMass()/Mttgen;
    // Mta = Ta_R2.GetMass();
    // Mtb = Tb_R2.GetMass();
    // MWa = Wa_R2.GetMass();
    // MWb = Wb_R2.GetMass();
    Eb_ta = Ba_R2.GetFourVector(Ta_R2).E()/Eb_tagen;
    Eb_tb = Bb_R2.GetFourVector(Tb_R2).E()/Eb_tbgen;
    El_Wa = La_R2.GetFourVector(Wa_R2).E()/El_Wagen;
    El_Wb = Lb_R2.GetFourVector(Wb_R2).E()/El_Wbgen;
    costt = TT_R2.GetCosDecayAngle();
    costa = Ta_R2.GetCosDecayAngle();
    costb = Tb_R2.GetCosDecayAngle();
    cosWa = Wa_R2.GetCosDecayAngle();
    cosWb = Wb_R2.GetCosDecayAngle();
    Dcostt = asin(sqrt(1.-costt*costt)*costtgen-sqrt(1.-costtgen*costtgen)*costt);
    Dcosta = asin(sqrt(1.-costa*costa)*costagen-sqrt(1.-costagen*costagen)*costa);
    Dcostb = asin(sqrt(1.-costb*costb)*costbgen-sqrt(1.-costbgen*costbgen)*costb);
    DcosWa = asin(sqrt(1.-cosWa*cosWa)*cosWagen-sqrt(1.-cosWagen*cosWagen)*cosWa);
    DcosWb = asin(sqrt(1.-cosWb*cosWb)*cosWbgen-sqrt(1.-cosWbgen*cosWbgen)*cosWb);

    histPlot->Fill(cat_R2);

    Mtt = TT_R3.GetMass()/Mttgen;
    // Mta = Ta_R3.GetMass();
    // Mtb = Tb_R3.GetMass();
    // MWa = Wa_R3.GetMass();
    // MWb = Wb_R3.GetMass();
    Eb_ta = Ba_R3.GetFourVector(Ta_R3).E()/Eb_tagen;
    Eb_tb = Bb_R3.GetFourVector(Tb_R3).E()/Eb_tbgen;
    El_Wa = La_R3.GetFourVector(Wa_R3).E()/El_Wagen;
    El_Wb = Lb_R3.GetFourVector(Wb_R3).E()/El_Wbgen;
    costt = TT_R3.GetCosDecayAngle();
    costa = Ta_R3.GetCosDecayAngle();
    costb = Tb_R3.GetCosDecayAngle();
    cosWa = Wa_R3.GetCosDecayAngle();
    cosWb = Wb_R3.GetCosDecayAngle();
    Dcostt = asin(sqrt(1.-costt*costt)*costtgen-sqrt(1.-costtgen*costtgen)*costt);
    Dcosta = asin(sqrt(1.-costa*costa)*costagen-sqrt(1.-costagen*costagen)*costa);
    Dcostb = asin(sqrt(1.-costb*costb)*costbgen-sqrt(1.-costbgen*costbgen)*costb);
    DcosWa = asin(sqrt(1.-cosWa*cosWa)*cosWagen-sqrt(1.-cosWagen*cosWagen)*cosWa);
    DcosWb = asin(sqrt(1.-cosWb*cosWb)*cosWbgen-sqrt(1.-cosWbgen*cosWbgen)*cosWb);

    histPlot->Fill(cat_R3);

    Mtt = TT_R4.GetMass()/Mttgen;
    // Mta = Ta_R4.GetMass();
    // Mtb = Tb_R4.GetMass();
    // MWa = Wa_R4.GetMass();
    // MWb = Wb_R4.GetMass();
    Eb_ta = Ba_R4.GetFourVector(Ta_R4).E()/Eb_tagen;
    Eb_tb = Bb_R4.GetFourVector(Tb_R4).E()/Eb_tbgen;
    El_Wa = La_R4.GetFourVector(Wa_R4).E()/El_Wagen;
    El_Wb = Lb_R4.GetFourVector(Wb_R4).E()/El_Wbgen;
    costt = TT_R4.GetCosDecayAngle();
    costa = Ta_R4.GetCosDecayAngle();
    costb = Tb_R4.GetCosDecayAngle();
    cosWa = Wa_R4.GetCosDecayAngle();
    cosWb = Wb_R4.GetCosDecayAngle();
    Dcostt = asin(sqrt(1.-costt*costt)*costtgen-sqrt(1.-costtgen*costtgen)*costt);
    Dcosta = asin(sqrt(1.-costa*costa)*costagen-sqrt(1.-costagen*costagen)*costa);
    Dcostb = asin(sqrt(1.-costb*costb)*costbgen-sqrt(1.-costbgen*costbgen)*costb);
    DcosWa = asin(sqrt(1.-cosWa*cosWa)*cosWagen-sqrt(1.-cosWagen*cosWagen)*cosWa);
    DcosWb = asin(sqrt(1.-cosWb*cosWb)*cosWbgen-sqrt(1.-cosWbgen*cosWbgen)*cosWb);

    histPlot->Fill(cat_R4);

  }

  histPlot->Draw();

  LAB_Gen.PrintGeneratorEfficiency();

  TFile fout(output_name.c_str(),"RECREATE");
  fout.Close();
  histPlot->WriteOutput(output_name);
  histPlot->WriteHist(output_name);
  treePlot->WriteOutput(output_name);

  g_Log << LogInfo << "Finished" << LogEnd;
}
示例#3
0
void example_top_to_bWlnu(const std::string& output_name =
			 "output_top_to_bWlnu.root"){
 
  // set particle masses and widths
  double mtop = 173.21; // GeV, PDG 2016
  double wtop = 1.41;
  double mW   = 80.385;
  double wW   = 2.085;
  
  // Number of events to generate
  int Ngen = 100000;
  
  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing generator frames and tree..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  ppLabGenFrame         LAB_Gen("LAB_Gen","LAB");
  ResonanceGenFrame     T_Gen("T_Gen","t");
  ResonanceGenFrame     W_Gen("W_Gen","W");
  VisibleGenFrame       B_Gen("B_Gen","b");
  VisibleGenFrame       L_Gen("L_Gen","#it{l}");
  InvisibleGenFrame     NU_Gen("NU_Gen","#nu");

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

  LAB_Gen.SetChildFrame(T_Gen);
  T_Gen.AddChildFrame(B_Gen);
  T_Gen.AddChildFrame(W_Gen);
  W_Gen.AddChildFrame(L_Gen);
  W_Gen.AddChildFrame(NU_Gen);

  if(LAB_Gen.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized generator tree" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator tree" << LogEnd;

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

  // set top mass and width
  T_Gen.SetMass(mtop);                 T_Gen.SetWidth(wtop);
  // set W mass and width
  W_Gen.SetMass(mW);                   W_Gen.SetWidth(wW);

  // set b-jet/lepton pT and eta cuts
  L_Gen.SetPtCut(20.);                 L_Gen.SetEtaCut(2.5);
  B_Gen.SetPtCut(20.);                 B_Gen.SetEtaCut(2.5);  

  if(LAB_Gen.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized generator analysis" << std::endl << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator analysis" << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing reconstruction frames and trees..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  LabRecoFrame       LAB_Mt("LAB_Mt","LAB"); LabRecoFrame       LAB_MW("LAB_MW","LAB");
  DecayRecoFrame     T_Mt("T_Mt","t");       DecayRecoFrame     T_MW("T_MW","t");
  DecayRecoFrame     W_Mt("W_Mt","W");       DecayRecoFrame     W_MW("W_MW","W");
  VisibleRecoFrame   B_Mt("B_Mt","b");       VisibleRecoFrame   B_MW("B_MW","b");
  VisibleRecoFrame   L_Mt("L_Mt","#it{l}");  VisibleRecoFrame   L_MW("L_MW","#it{l}");
  InvisibleRecoFrame NU_Mt("NU_Mt","#nu");   InvisibleRecoFrame NU_MW("NU_MW","#nu");

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

  LAB_Mt.SetChildFrame(T_Mt);                LAB_MW.SetChildFrame(T_MW);
  T_Mt.AddChildFrame(B_Mt);                  T_MW.AddChildFrame(B_MW);
  T_Mt.AddChildFrame(W_Mt);                  T_MW.AddChildFrame(W_MW);
  W_Mt.AddChildFrame(L_Mt);                  W_MW.AddChildFrame(L_MW);
  W_Mt.AddChildFrame(NU_Mt);                 W_MW.AddChildFrame(NU_MW);

  if(LAB_Mt.InitializeTree() && LAB_MW.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized reconstruction trees" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing reconstruction trees" << LogEnd;

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

  // Invisible Groups
  InvisibleGroup INV_Mt("INV_Mt","#nu Jigsaws");
  INV_Mt.AddFrame(NU_Mt);     
  InvisibleGroup INV_MW("INV_MW","#nu Jigsaws");
  INV_MW.AddFrame(NU_MW);

  // Set neutrino masses to zero
  SetMassInvJigsaw NuM_Mt("NuM_Mt","M_{#nu} = 0"); 
  INV_Mt.AddJigsaw(NuM_Mt);                        
  SetMassInvJigsaw NuM_MW("NuM_MW","M_{#nu} = 0");
  INV_MW.AddJigsaw(NuM_MW);

  // Set neutrino rapidity to that of visible particles
  SetRapidityInvJigsaw NuR_Mt("NuR_Mt","#eta_{#nu} = #eta_{b+#it{l}}");
  INV_Mt.AddJigsaw(NuR_Mt);
  NuR_Mt.AddVisibleFrame(L_Mt);
  NuR_Mt.AddVisibleFrame(B_Mt);
  SetRapidityInvJigsaw NuR_MW("NuR_MW","#eta_{#nu} = #eta_{#it{l}}");
  INV_MW.AddJigsaw(NuR_MW);
  NuR_MW.AddVisibleFrame(L_MW);

  if(LAB_Mt.InitializeAnalysis() && LAB_MW.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized analyses" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing analyses" << LogEnd;

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  TreePlot* treePlot = new TreePlot("TreePlot","TreePlot");
 
  treePlot->SetTree(LAB_Gen);
  treePlot->Draw("GenTree", "Generator Tree", true);

  treePlot->SetTree(LAB_Mt);
  treePlot->Draw("RecoTree", "Reconstruction Tree");

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

  // Declare observables for histogram booking
  HistPlot* histPlot   = new HistPlot("HistPlot","pp #rightarrow t #rightarrow W(#it{l} #nu) b");

  const HistPlotCategory& cat_Gen   = histPlot->GetNewCategory("Gen", "Generator");
  const HistPlotCategory& cat_minMt = histPlot->GetNewCategory("minMt", "min M_{t} Reco");
  const HistPlotCategory& cat_minMW = histPlot->GetNewCategory("minMW", "min M_{W} Reco");

  const HistPlotVar& Mt     = histPlot->GetNewVar("Mt", "M_{t}", 0., 280., "[GeV]");
  const HistPlotVar& MW     = histPlot->GetNewVar("MW", "M_{W}", 0., 150., "[GeV]");
  const HistPlotVar& pTtoMt = histPlot->GetNewVar("pTtoMt","p_{T}^{top} / m_{top}", 0., 1.);
  const HistPlotVar& cosT   = histPlot->GetNewVar("cosT","cos #theta_{t}", -1., 1.);
  const HistPlotVar& cosW   = histPlot->GetNewVar("cosW","cos #theta_{W}", -1., 1.);
  const HistPlotVar& dphiT  = histPlot->GetNewVar("dphiT", "#Delta #phi_{t}", 0., 2.*acos(-1.));
  const HistPlotVar& dphiW  = histPlot->GetNewVar("dphiW", "#Delta #phi_{W}", 0., 2.*acos(-1.));
  const HistPlotVar& DcosT  = histPlot->GetNewVar("DcosT","#theta_{t} - #theta_{t}^{gen}", -1., 1.);
  const HistPlotVar& DcosW  = histPlot->GetNewVar("DcosW","#theta_{W} - #theta_{W}^{gen}", -1., 1.);
  const HistPlotVar& DdphiT = histPlot->GetNewVar("DdphiT","#Delta #phi_{t} - #Delta #phi_{t}^{gen}", -1., 1.);
  const HistPlotVar& DdphiW = histPlot->GetNewVar("DdphiW","#Delta #phi_{W} - #Delta #phi_{W}^{gen}", -1., 1.);

  histPlot->AddPlot(DcosT,  cat_minMt+cat_minMW);
  histPlot->AddPlot(DcosW,  cat_minMt+cat_minMW);
  histPlot->AddPlot(DdphiT, cat_minMt+cat_minMW);
  histPlot->AddPlot(DdphiW, cat_minMt+cat_minMW);
  histPlot->AddPlot(MW,     cat_minMt+cat_minMW+cat_Gen);
  histPlot->AddPlot(Mt,     cat_minMt+cat_minMW+cat_Gen);
  histPlot->AddPlot(Mt, MW, cat_minMt+cat_minMW+cat_Gen);
  histPlot->AddPlot(Mt, pTtoMt, cat_minMt+cat_minMW);
  histPlot->AddPlot(MW, pTtoMt, cat_minMt+cat_minMW);
  histPlot->AddPlot(DcosW,  MW, cat_minMt+cat_minMW);
  histPlot->AddPlot(DcosT,  Mt, cat_minMt+cat_minMW);
  histPlot->AddPlot(Mt, pTtoMt, cat_minMt+cat_minMW);
  histPlot->AddPlot(MW, pTtoMt, cat_minMt+cat_minMW);
  histPlot->AddPlot(DcosT, DcosW, cat_minMt+cat_minMW);
 

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  for(int igen = 0; igen < Ngen; igen++){
    if(igen%((std::max(Ngen,10))/10) == 0)
      g_Log << LogInfo << "Generating event " << igen << " of " << Ngen << LogEnd;

    // generate event
    LAB_Gen.ClearEvent();                            // clear the gen tree

    pTtoMt = gRandom->Rndm();                        // give the Top some Pt
    LAB_Gen.SetPToverM(pTtoMt); 
  
    LAB_Gen.AnalyzeEvent();                          // generate a new event

    TVector3 MET = LAB_Gen.GetInvisibleMomentum();   // Get the MET from gen tree
    MET.SetZ(0.);
    
    // analyze event one way
    LAB_Mt.ClearEvent();                               // clear the reco tree
    
    L_Mt.SetLabFrameFourVector(L_Gen.GetFourVector()); // Set lepton 4-vec
    B_Mt.SetLabFrameFourVector(B_Gen.GetFourVector()); // Set b-jet 4-vec
    INV_Mt.SetLabFrameThreeVector(MET);                // Set the MET in reco tree
    
    LAB_Mt.AnalyzeEvent();                             //analyze the event

    // analyze event another way
    LAB_MW.ClearEvent();                               // clear the reco tree
    
    L_MW.SetLabFrameFourVector(L_Gen.GetFourVector()); // Set lepton 4-vec
    B_MW.SetLabFrameFourVector(B_Gen.GetFourVector()); // Set b-jet 4-vec
    INV_MW.SetLabFrameThreeVector(MET);                // Set the MET in reco tree
    
    LAB_MW.AnalyzeEvent();                             //analyze the event

    // Generator-level observables
    double MTgen = T_Gen.GetMass();
    double cosTgen  = T_Gen.GetCosDecayAngle();
    double dphiTgen = LAB_Gen.GetDeltaPhiDecayPlanes(T_Gen);
    double MWgen = W_Gen.GetMass();
    double cosWgen  = W_Gen.GetCosDecayAngle();
    double dphiWgen = T_Gen.GetDeltaPhiDecayPlanes(W_Gen);

    Mt = MTgen;
    MW = MWgen;
    histPlot->Fill(cat_Gen);

    // minMt observables
    Mt     = T_Mt.GetMass();
    cosT   = T_Mt.GetCosDecayAngle();
    dphiT  = LAB_Mt.GetDeltaPhiDecayPlanes(T_Mt);
    MW     = W_Mt.GetMass();
    cosW   = W_Mt.GetCosDecayAngle();
    dphiW  = T_Mt.GetDeltaPhiDecayPlanes(W_Mt);
    DcosT  = asin(sqrt(1.-cosT*cosT)*cosTgen-sqrt(1.-cosTgen*cosTgen)*cosT);
    DdphiT = asin(sin(dphiT-dphiTgen));
    DcosW  = asin(sqrt(1.-cosW*cosW)*cosWgen-sqrt(1.-cosWgen*cosWgen)*cosW);
    DdphiW = asin(sin(dphiW-dphiWgen));

    histPlot->Fill(cat_minMt);

    // minMW observables
    Mt     = T_MW.GetMass();
    cosT   = T_MW.GetCosDecayAngle();
    dphiT  = LAB_MW.GetDeltaPhiDecayPlanes(T_MW);
    MW     = W_MW.GetMass();
    cosW   = W_MW.GetCosDecayAngle();
    dphiW  = T_MW.GetDeltaPhiDecayPlanes(W_MW);
    DcosT  = asin(sqrt(1.-cosT*cosT)*cosTgen-sqrt(1.-cosTgen*cosTgen)*cosT);
    DdphiT = asin(sin(dphiT-dphiTgen));
    DcosW  = asin(sqrt(1.-cosW*cosW)*cosWgen-sqrt(1.-cosWgen*cosWgen)*cosW);
    DdphiW = asin(sin(dphiW-dphiWgen));

    histPlot->Fill(cat_minMW);
  }

  histPlot->Draw();

  LAB_Gen.PrintGeneratorEfficiency();
  
  TFile fout(output_name.c_str(),"RECREATE");
  fout.Close();
  histPlot->WriteOutput(output_name);
  histPlot->WriteHist(output_name);
  treePlot->WriteOutput(output_name);

  g_Log << LogInfo << "Finished" << LogEnd;

}
示例#4
0
void example_Hp_to_HggWlnu(const std::string& output_name =
			   "output_Hp_to_HggWlnu.root"){
 
  // set particle masses and widths
  double mH   = 125.; 
  double mW   = 80.385; // GeV, PDG 2016
  double wW   = 2.085;
  
  std::vector<double> mHp; // vary charged Higgs mass
  mHp.push_back(300.);
  mHp.push_back(500.);
  mHp.push_back(750.);
  mHp.push_back(1000.);
  mHp.push_back(1500.);
  
  // Number of events to generate (per H+ mass)
  int Ngen = 10000;
  
  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing generator frames and tree..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  ppLabGenFrame         LAB_Gen("LAB_Gen","LAB");
  DecayGenFrame         Hp_Gen("Hp_Gen","H^{ +}");
  DecayGenFrame         H_Gen("H_Gen","h^{ 0}");
  ResonanceGenFrame     W_Gen("W_Gen","W^{ +}");
  VisibleGenFrame       G1_Gen("G1_Gen","#gamma_{1}");
  VisibleGenFrame       G2_Gen("G2_Gen","#gamma_{2}");
  VisibleGenFrame       L_Gen("L_Gen","#it{l}^{ +}");
  InvisibleGenFrame     NU_Gen("NU_Gen","#nu");

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

  LAB_Gen.SetChildFrame(Hp_Gen);
  Hp_Gen.AddChildFrame(H_Gen);
  Hp_Gen.AddChildFrame(W_Gen);
  H_Gen.AddChildFrame(G1_Gen);
  H_Gen.AddChildFrame(G2_Gen);
  W_Gen.AddChildFrame(L_Gen);
  W_Gen.AddChildFrame(NU_Gen);

  if(LAB_Gen.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized generator tree" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator tree" << LogEnd;

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

  if(mHp.size() < 1) return;
  
  // set neutral and charged Higgs mass 
  Hp_Gen.SetMass(mHp[0]);              H_Gen.SetMass(mH);         
  // set W mass and width
  W_Gen.SetMass(mW);                   W_Gen.SetWidth(wW);

  // set photon/lepton pT and eta cuts
  L_Gen.SetPtCut(15.);                 L_Gen.SetEtaCut(2.5);
  G1_Gen.SetPtCut(20.);                G1_Gen.SetEtaCut(3.);
  G2_Gen.SetPtCut(20.);                G2_Gen.SetEtaCut(3.);  

  if(LAB_Gen.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized generator analysis" << std::endl << LogEnd;
  else
    g_Log << LogError << "...Failed initializing generator analysis" << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  /////////////////////////////////////////////////////////////////////////////////////////
  g_Log << LogInfo << "Initializing reconstruction frames and trees..." << LogEnd;
  /////////////////////////////////////////////////////////////////////////////////////////
  LabRecoFrame       LAB("LAB","LAB");
  DecayRecoFrame     Hp("Hp","H^{ +}");
  DecayRecoFrame     H("H","h^{ 0}");
  DecayRecoFrame     W("W","W^{ +}");
  VisibleRecoFrame   G1("G1","#gamma_{1}");
  VisibleRecoFrame   G2("G2","#gamma_{2}");
  VisibleRecoFrame   L("L","#it{l}^{ +}");
  InvisibleRecoFrame NU("NU","#nu");

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

  LAB.SetChildFrame(Hp);
  Hp.AddChildFrame(H);
  Hp.AddChildFrame(W);
  H.AddChildFrame(G1);
  H.AddChildFrame(G2);
  W.AddChildFrame(L);
  W.AddChildFrame(NU);

  if(LAB.InitializeTree())
    g_Log << LogInfo << "...Successfully initialized reconstruction trees" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing reconstruction trees" << LogEnd;

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

  // Invisible Group
  InvisibleGroup INV("INV","#nu Jigsaws");
  INV.AddFrame(NU);     

  // Set neutrino masses to zero
  SetMassInvJigsaw NuM("NuM","M_{#nu} = 0"); 
  INV.AddJigsaw(NuM);                        

  // Set neutrino rapidity to that of visible particles
  SetRapidityInvJigsaw NuR("NuR","#eta_{#nu} = #eta_{#gamma#gamma#it{l}}");
  INV.AddJigsaw(NuR);
  NuR.AddVisibleFrames(Hp.GetListVisibleFrames());

  if(LAB.InitializeAnalysis())
    g_Log << LogInfo << "...Successfully initialized analyses" << LogEnd;
  else
    g_Log << LogError << "...Failed initializing analyses" << LogEnd;

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  TreePlot* treePlot = new TreePlot("TreePlot","TreePlot");
 
  treePlot->SetTree(LAB_Gen);
  treePlot->Draw("GenTree", "Generator Tree", true);

  treePlot->SetTree(LAB);
  treePlot->Draw("RecoTree", "Reconstruction Tree");

  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
  
  // Declare observables for histogram booking
  std::string plot_title = "pp #rightarrow H^{ +} #rightarrow h^{ 0}(#gamma #gamma ) W(#it{l} #nu)";
  HistPlot* histPlot   = new HistPlot("HistPlot", plot_title);

  RFList<const HistPlotCategory> cat_list;
  int Nmass = mHp.size();
  for(int m = 0; m < Nmass; m++){
    char smass[50], scat[50];
    sprintf(scat, "MHp%.0f", mHp[m]);
    sprintf(smass, "m_{H^{ +}} = %.0f", mHp[m]);
    cat_list += histPlot->GetNewCategory(scat, smass);
  }

  const HistPlotCategory& cat_Hp  = histPlot->GetNewCategory("HprodHp", "h^{ 0} prod. frame = H^{ +}");
  const HistPlotCategory& cat_LAB = histPlot->GetNewCategory("HprodLAB", "h^{ 0} prod. frame = LAB");
  
  const HistPlotVar& MHp    = histPlot->GetNewVar("MHp", "M_{H^{ +}}", 0., 2400., "[GeV]");
  const HistPlotVar& MHpN   = histPlot->GetNewVar("MHpN", "M_{H^{ +}} / m_{H^{ +}}^{true}", 0.7, 1.05);
  const HistPlotVar& MWN    = histPlot->GetNewVar("MWN", "M_{W} / m_{W}^{true}", 0., 2.);
  const HistPlotVar& cosHp  = histPlot->GetNewVar("cosHp","cos #theta_{H^{ +}}", -1., 1.);
  const HistPlotVar& cosW   = histPlot->GetNewVar("cosW","cos #theta_{W}", -1., 1.);
  const HistPlotVar& cosH   = histPlot->GetNewVar("cosH","cos #theta_{h^{ 0}}", -1., 1.);
  const HistPlotVar& DcosHp = histPlot->GetNewVar("DcosHp","#theta_{H^{ +}} - #theta_{H^{ +}}^{true}", -1., 1.);
  const HistPlotVar& DcosW  = histPlot->GetNewVar("DcosW","#theta_{W} - #theta_{W}^{true}", -1., 1.);
  const HistPlotVar& DcosH  = histPlot->GetNewVar("DcosW","#theta_{h^{ 0}} - #theta_{h^{ 0}}^{true}", -1., 1.);

  histPlot->AddPlot(DcosH,  cat_list);
  histPlot->AddPlot(DcosW,  cat_list);
  histPlot->AddPlot(DcosHp, cat_list);
  histPlot->AddPlot(MWN,  cat_list);
  histPlot->AddPlot(MHpN, cat_list);
  histPlot->AddPlot(MHp,  cat_list);
  histPlot->AddPlot(MWN,    MHpN,   cat_list[2]);
  histPlot->AddPlot(DcosW, MWN,  cat_list[2]);
  histPlot->AddPlot(DcosHp, MHpN, cat_list[2]);
  histPlot->AddPlot(DcosHp, DcosW,  cat_list[2]);
  histPlot->AddPlot(DcosH,  MHpN,   cat_list[2]);
  
  histPlot->AddPlot(DcosH,  cat_Hp+cat_LAB);

  /////////////////////////////////////////////////////////////////////////////////////////
  /////////////////////////////////////////////////////////////////////////////////////////

  for(int m = 0; m < Nmass; m++){
    g_Log << LogInfo << "Generating events for H^{+} mass = " << mHp[m] << LogEnd;

    Hp_Gen.SetMass(mHp[m]);
    LAB_Gen.InitializeAnalysis();
  
    for(int igen = 0; igen < Ngen; igen++){
      if(igen%((std::max(Ngen,10))/10) == 0)
	g_Log << LogInfo << "Generating event " << igen << " of " << Ngen << LogEnd;
      
      // generate event
      LAB_Gen.ClearEvent();                            // clear the gen tree

      LAB_Gen.SetPToverM(gRandom->Rndm());             // give charged Higgs some Pt
      
      LAB_Gen.AnalyzeEvent();                          // generate a new event

      TVector3 MET = LAB_Gen.GetInvisibleMomentum();   // Get the MET from gen tree
      MET.SetZ(0.);
    
      // analyze event 
      LAB.ClearEvent();                                   // clear the reco tree
    
      L.SetLabFrameFourVector(L_Gen.GetFourVector());     // Set lepton 4-vec
      G1.SetLabFrameFourVector(G1_Gen.GetFourVector());   // Set photons' 4-vec
      G2.SetLabFrameFourVector(G2_Gen.GetFourVector());   
      INV.SetLabFrameThreeVector(MET);                    // Set the MET in reco tree
    
      LAB.AnalyzeEvent();                                 //analyze the event

      // Generator-level observables
      double MHpgen = Hp_Gen.GetMass();
      double MWgen  = W_Gen.GetMass();
      double cosHpgen = Hp_Gen.GetCosDecayAngle();
      double cosHgen  = H_Gen.GetCosDecayAngle();
      double cosWgen  = W_Gen.GetCosDecayAngle();

      // Reconstructed observables
      MHp    = Hp.GetMass();
      MHpN   = Hp.GetMass()/MHpgen;
      MWN    = W.GetMass()/MWgen;
      cosHp  = Hp.GetCosDecayAngle();
      cosH   = H.GetCosDecayAngle();
      cosW   = W.GetCosDecayAngle();
      DcosHp = asin(sqrt(1.-cosHp*cosHp)*cosHpgen-sqrt(1.-cosHpgen*cosHpgen)*cosHp);
      DcosH  = asin(sqrt(1.-cosH*cosH)*cosHgen-sqrt(1.-cosHgen*cosHgen)*cosH);
      DcosW  = asin(sqrt(1.-cosW*cosW)*cosWgen-sqrt(1.-cosWgen*cosWgen)*cosW);

      histPlot->Fill(cat_list[m]);

      if(m == 0){
	histPlot->Fill(cat_Hp);
	
	TVector3 Hboost = H.GetFourVector().BoostVector();
	TLorentzVector vP_G1 = G1.GetFourVector();
	vP_G1.Boost(-Hboost);
	cosH   = -vP_G1.Vect().Unit().Dot(Hboost.Unit());
	DcosH  = asin(sqrt(1.-cosH*cosH)*cosHgen-sqrt(1.-cosHgen*cosHgen)*cosH);

	histPlot->Fill(cat_LAB);
      }
    }

    LAB_Gen.PrintGeneratorEfficiency();
  }

  histPlot->Draw();
  
  TFile fout(output_name.c_str(),"RECREATE");
  fout.Close();
  histPlot->WriteOutput(output_name);
  histPlot->WriteHist(output_name);
  treePlot->WriteOutput(output_name);

  g_Log << LogInfo << "Finished" << LogEnd;

}