Beispiel #1
0
  ///output operator
  ostream& StatSample::print_tex (ostream& os, const string title) const {
    
    bool weightMode = _weight->nevents() > 0 ?  true : false ;

    os << "" << endl;
    os << "% Efficiency table %" << endl;
    os << "" << endl;
    os << "\\begin{table}[p]" << endl;
    os << "\\begin{center}" << endl;
    os << "\\begin{tabular}{lrrr" ; 
    if (weightMode) os << "r" ;
    os << "}" << endl;
    os << "  \\hline  \\hline" << endl;
    os << "  Selection & Events & Relative  & Total  " ;
    if (weightMode) os << "& Total Corrected by Event Weights " ;
    os << "\\\\ \\hline" << endl;
    
    os << tex(eventSelection(0)->name()) << " & " ;
    os <<  nevents(0) << " & & " ;
    if (weightMode) os << " & " ;
    os << "\\\\ " << endl ; 

    for (unsigned int n = 1; n < size() ; n++) {
      
      os << tex(eventSelection(n)->name()) << " & " ;
      os <<  nevents(n) << " & ";

      if (eventSelection(n)->isWeight()) {	
	os << " $\\mathit{ " << eff(n) << " \\pm " 
	   << effErr(n) << " }$ & & " ;
	if (weightMode) os << " & " ;
      } else {	
	os << " $ " << 100.0*eff(n) << " \\pm " 
	   << 100.0*effErr(n) << " ~\\% $ & " ;
	os << " $ " << 100.0*effGlob(n) << " \\pm " 
	   << 100.0*effErrGlob(n) << "~\\% $ " ;
	if (weightMode) 
	  os << " $ " << 100.0*correctedEfficiency(n) << " \\pm " 
	     << 100.0*correctedEffErr(n) << "~\\% $ " ;
      }

      os << " \\\\ " << endl ; 
    }

    os << "  \\hline " << endl;
    os << " \\hline" << endl;
    os << " \\end{tabular}" << endl;
    os << " \\caption{" << title << " Sample " << name() << " }" << endl;
    os << " \\label{Table:" <<  title.c_str() << ":" << name() << "}" << endl;
    os << "\\end{center}" << endl;
    os << "\\end{table}" << endl; 
    os << endl;

    return os ;    
  }
Beispiel #2
0
  ostream& StatSample::HtmlTable(ostream& os) const {
    
    bool weightMode = _weight->nevents() > 0 ?  true : false ;

    os << "<TABLE BORDERCOLORDARK=\"996633\"  BORDERCOLOR=\"CC9966\"    BORDERCOLORLIGHT=\"FFCC99\"   border=3 cellPadding=5 width=\"99%\">" << endl ;
    os << "<TBODY align=right>" << endl ;
    
    os << "<TR>" << endl ;
    os << "<TH align=left>" << endl ;
    os << "SELECTION"   ;
    os << " </TH>" << endl ;
    if (weightMode) 
      os << "<TH align=center colspan=4>" << endl ; 
    else 
      os << "<TH align=center colspan=3>" << endl ; 
    os <<  name() << endl ;
    os << "</TH>" << endl ; 
    os << "</TR>" << endl ;
      
    bool color = false ;
    
    for (unsigned int n = 0; n < size() ; n++) {
      
      if (color) {
	os << "<TR BGCOLOR=#bfefff>" << endl ; 
	color = !color ;
      } else { 
	os << "<TR>" << endl ; 
	color = !color ;
      }      
     
      os << "<TD align=left>" << endl ; 
      os <<  eventSelection(n)->name() << endl ;
      os << "</TD>" << endl ; 

      os << "<TD TITLE=\"Number of events\">" << endl ; 
      os <<  nevents(n) << endl ;
      if (n==0) {
	os << "<TD>&#160;</TD> <TD>&#160;</TD>" ;
	if (weightMode) os << "<TD>&#160;</TD> " ;
	os << endl ; 
	continue ;
      }
	
      if (eventSelection(n)->isWeight()) {
	  if (eventSelection(n)->name() == eventWeight()->name()) 
	    os << "</TD> <TD TITLE=\"Global event weight\">" << endl ; 
	  else 
	    os << "</TD> <TD TITLE=\"Average weight\">" << endl ; 
	  os << eff(n) << "&#177;" << effErr(n)<< endl ;
	  os << "</TD> <TD> &#160;</TD>";
	  if (weightMode) os << "<TD> &#160;</TD>";	  
	  os << endl ;
	  continue ;
      } 
      
      os << "</TD><TD TITLE=\"Selection efficiency\">"<< endl ;
      os << 100.0*eff(n) << "&#177;" << 100.0*effErr(n) << "%" << endl ;
      os << "</TD><TD TITLE=\"Global efficiency\">"<< endl ;
      os << 100.0*effGlob(n) << "&#177;" << 100.0*effErrGlob(n) << "%" 
	 << endl ;
      os << "</TD>" << endl ;       
      if (weightMode) {
	os << "</TD><TD TITLE=\"Global efficiency corrected by the event weight\">"<< endl ;
	os << 100.0*correctedEfficiency(n) << "&#177;" << 100.0*correctedEffErr(n) << "%" 
	   << endl ;
	os << "</TD>" << endl ;       	
      }
      os << "</TR>" << endl ; 
    }
    
    os << "</TBODY></TABLE>" << endl ;

    return os ;
  }
Beispiel #3
0
void PhiModel::DefineModel()
{
  if(par->debug) std::cout<<"Running: PhiModel::DefineModel()"<<std::endl;

  std::map<std::string,std::string> mod;
  std::map<std::string,std::string> Bmod;
  mod[Ds2PhiPi]="#phi#pi"; mod[Ds2KKPi]="KK#pi"; mod[Ds2KPiPi]="K#pi#pi";    mod[Ds2KKPi]="#pi#pi#pi";
  Bmod[DsD0]="D_{s}D^{0}"; Bmod[DsPhi]="D_{s}#phi";

  // --------- Yields for DsD0, in an array (as line 447 of Model.C) ---------------
  if(par->debug) std::cout<<"Running: PhiModel::DefineModel() --> Making RooRealVars"<<std::endl;
  
  for(std::vector<std::string>::iterator h=HelBinList.begin();h!=HelBinList.end();h++){ 
    for(std::vector<std::string>::iterator ds=DsBDTBinList.begin();ds!=DsBDTBinList.end();ds++){ 
      for(std::vector<std::string>::iterator ph=PhiBDTBinList.begin();ph!=PhiBDTBinList.end();ph++){ 
        for(std::vector<std::string>::iterator a=magnetList.begin();a!=magnetList.end();a++){
          for(std::vector<std::string>::iterator c=chargeList.begin();c!=chargeList.end();c++){
            yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2PhiPi][*c][*a]  = new RooRealVar(Form("yield_%s_peak_DsD0_Ds2PhiPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Peak D_{s}D^{0} (#phi#pi)",  1660, 0, 830000);
            yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2KKPi][*c][*a]   = new RooRealVar(Form("yield_%s_peak_DsD0_Ds2KKPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),   "Yield #phi Peak D_{s}D^{0} (KK#pi)",    1660, 0, 830000);
            yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2PiPiPi][*c][*a] = new RooRealVar(Form("yield_%s_peak_DsD0_Ds2PiPiPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()), "Yield #phi Peak D_{s}D^{0} (#pi#pi#pi)", 350, 0, 175000);
            yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2KPiPi][*c][*a]  = new RooRealVar(Form("yield_%s_peak_DsD0_Ds2KPiPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Peak D_{s}D^{0} (K#pi#pi)",   200, 0, 100000);

            yield_Phi_comb[*h][*ds][*ph][DsD0][Ds2PhiPi][*c][*a]  = new RooRealVar(Form("yield_%s_comb_DsD0_Ds2PhiPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Comb. D_{s}D^{0} (#phi#pi)",   710, 0, 600000);
            yield_Phi_comb[*h][*ds][*ph][DsD0][Ds2KKPi][*c][*a]   = new RooRealVar(Form("yield_%s_comb_DsD0_Ds2KKPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),   "Yield #phi Comb. D_{s}D^{0} (KK#pi)",     710, 0, 600000);
            yield_Phi_comb[*h][*ds][*ph][DsD0][Ds2PiPiPi][*c][*a] = new RooRealVar(Form("yield_%s_comb_DsD0_Ds2PiPiPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()), "Yield #phi Comb. D_{s}D^{0} (#pi#pi#pi)", 390, 0, 600000);
            yield_Phi_comb[*h][*ds][*ph][DsD0][Ds2KPiPi][*c][*a]  = new RooRealVar(Form("yield_%s_comb_DsD0_Ds2KPiPi_%s_%s_%s_%s_%s",particle_name[DsD0].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Comb. D_{s}D^{0} (K#pi#pi)",   200, 0, 600000);

            // ---------------
            // DsPhi variables
            // ---------------
            yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2PhiPi][*c][*a]  = new RooRealVar(Form("yield_%s_peak_DsPhi_Ds2PhiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Peak D_{s}#phi (#phi#pi)",  1660, 0, 83000);
            yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2KKPi][*c][*a]   = new RooRealVar(Form("yield_%s_peak_DsPhi_Ds2KKPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),   "Yield #phi Peak D_{s}#phi (KK#pi)",    1660, 0, 83000);
            yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2PiPiPi][*c][*a] = new RooRealVar(Form("yield_%s_peak_DsPhi_Ds2PiPiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()), "Yield #phi Peak D_{s}#phi (#pi#pi#pi)", 350, 0, 17500);
            yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2KPiPi][*c][*a]  = new RooRealVar(Form("yield_%s_peak_DsPhi_Ds2KPiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Peak D_{s}#phi (K#pi#pi)",   200, 0, 10000);

            yield_Phi_comb[*h][*ds][*ph][DsPhi][Ds2PhiPi][*c][*a]  = new RooRealVar(Form("yield_%s_comb_DsPhi_Ds2PhiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Comb. D_{s}#phi (#phi#pi)",   710, 0, 600000);
            yield_Phi_comb[*h][*ds][*ph][DsPhi][Ds2KKPi][*c][*a]   = new RooRealVar(Form("yield_%s_comb_DsPhi_Ds2KKPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),   "Yield #phi Comb. D_{s}#phi (KK#pi)",     710, 0, 600000);
            yield_Phi_comb[*h][*ds][*ph][DsPhi][Ds2PiPiPi][*c][*a] = new RooRealVar(Form("yield_%s_comb_DsPhi_Ds2PiPiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()), "Yield #phi Comb. D_{s}#phi (#pi#pi#pi)", 390, 0, 600000);
            yield_Phi_comb[*h][*ds][*ph][DsPhi][Ds2KPiPi][*c][*a]  = new RooRealVar(Form("yield_%s_comb_DsPhi_Ds2KPiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "Yield #phi Comb. D_{s}#phi (K#pi#pi)",   200, 0, 600000);


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

            if(par->debug) std::cout<<"Running: PhiModel::DefineModel() --> Setting up blinding"<<std::endl;
            // RooCategory used for blind/unblind switching.
            TString blind("blind"), unblind("unblind");
            RooCategory blindCatBu("blindCatBu","Bu blind state Category");
            blindCatBu.defineType(unblind, 0);
            blindCatBu.defineType(blind, 1);

            if (needsBlinding)
                blindCatBu.setLabel(blind);
            else
                blindCatBu.setLabel(unblind);

            
            if(needsBlinding){  
              Phi_yield[*h][*ds][*ph][DsD0][Ds2PhiPi][*c][*a]  = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2PhiPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsD0][Ds2KKPi][*c][*a]   = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2KKPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsD0][Ds2KPiPi][*c][*a]  = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2KPiPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsD0][Ds2PiPiPi][*c][*a] = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2PiPiPi][*c][*a];

              //Phi_yield[DsD0][Ds2PhiPi][*c][*a]  = new RooUnblindUniform(Form("B_nsig_DsD0_Ds2PhiPi_%s_%s",(*c).c_str(),(*a).c_str()),  "nsig Bu blind (#phi#pi)",  "nsigBuDsD0blindedPhiPi",  1000., *yield_Phi_peak[DsD0][Ds2PhiPi][*c][*a] );
              //Phi_yield[DsD0][Ds2KKPi][*c][*a]   = new RooUnblindUniform(Form("B_nsig_DsD0_Ds2KKPi_%s_%s",(*c).c_str(),(*a).c_str()),   "nsig Bu blind (KK#pi)",    "nsigBuDsD0blindedKKPi",   1000., *yield_Phi_peak[DsD0][Ds2KKPi][*c][*a]  );
              //Phi_yield[DsD0][Ds2PiPiPi][*c][*a] = new RooUnblindUniform(Form("B_nsig_DsD0_Ds2PiPiPi_%s_%s",(*c).c_str(),(*a).c_str()), "nsig Bu blind (#pi#pi#pi)","nsigBuDsD0blindedPiPiPi", 100., *yield_Phi_peak[DsD0][Ds2PiPiPi][*c][*a] );
              //Phi_yield[DsD0][Ds2KPiPi][*c][*a]  = new RooUnblindUniform(Form("B_nsig_DsD0_Ds2KPiPi_%s_%s",(*c).c_str(),(*a).c_str()),  "nsig Bu blind (K#pi#pi)",  "nsigBuDsD0blindedKPiPi",  100., *yield_Phi_peak[DsD0][Ds2KPiPi][*c][*a]  );
              
              // Only Blind DsPhi numbers...
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2PhiPi][*c][*a]  = new RooUnblindUniform(Form("%s_nsig_DsPhi_Ds2PhiPi_%s_%s_%s_%s_%s", particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "nsig Bu blind (#phi#pi)",  "nsigBuDsPhiblindePhiPi",   40., *yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2PhiPi][*c][*a] );
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2KKPi][*c][*a]   = new RooUnblindUniform(Form("%s_nsig_DsPhi_Ds2KKPi_%s_%s_%s_%s_%s",  particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "nsig Bu blind (KK#pi)",    "nsigBuDsPhiblindedKKPi",   40., *yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2KKPi][*c][*a]  );
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2PiPiPi][*c][*a] = new RooUnblindUniform(Form("%s_nsig_DsPhi_Ds2PiPiPi_%s_%s_%s_%s_%s",particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "nsig Bu blind (#pi#pi#pi)","nsigBuDsPhiblindedPiPiPi", 20., *yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2PiPiPi][*c][*a]);
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2KPiPi][*c][*a]  = new RooUnblindUniform(Form("%s_nsig_DsPhi_Ds2KPiPi_%s_%s_%s_%s_%s", particle_name[DsPhi].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*c).c_str(),(*a).c_str()),  "nsig Bu blind (K#pi#pi)",  "nsigBuDsPhiblindedKPiPi",  10., *yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2KPiPi][*c][*a] );
            } else {
              Phi_yield[*h][*ds][*ph][DsD0][Ds2PhiPi][*c][*a]  = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2PhiPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsD0][Ds2KKPi][*c][*a]   = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2KKPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsD0][Ds2KPiPi][*c][*a]  = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2KPiPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsD0][Ds2PiPiPi][*c][*a] = yield_Phi_peak[*h][*ds][*ph][DsD0][Ds2PiPiPi][*c][*a];

              Phi_yield[*h][*ds][*ph][DsPhi][Ds2PhiPi][*c][*a]  = yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2PhiPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2KKPi][*c][*a]   = yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2KKPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2KPiPi][*c][*a]  = yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2KPiPi][*c][*a];
              Phi_yield[*h][*ds][*ph][DsPhi][Ds2PiPiPi][*c][*a] = yield_Phi_peak[*h][*ds][*ph][DsPhi][Ds2PiPiPi][*c][*a];
            }
          } //end of loop over chargeList
        }  //end of loop over magnetList
      } 
    } 
  }



  // --------- Mean B mass ---------------

  double default_Phi=1019.461;
  double Phi_low    = 994.461;
  double Phi_high   = 1044.461;
  
  double default_D0 =1864.84;
  double D0_low     = 1839.84;
  double D0_high    = 1889.84;
  
  for(std::vector<std::string>::iterator h=allHelbinList.begin();h!=allHelbinList.end();h++){ 
    for(std::vector<std::string>::iterator ds=allDsBDTbinList.begin();ds!=allDsBDTbinList.end();ds++){ 
      for(std::vector<std::string>::iterator ph=allPhiBDTbinList.begin();ph!=allPhiBDTbinList.end();ph++){
        for(std::vector<std::string>::iterator b=allBmodeList.begin();b!=allBmodeList.end();b++){  
          for(std::vector<std::string>::iterator m=allmodeList.begin();m!=allmodeList.end();m++){
            bool isPhi = false;
            if((*b).c_str()==DsPhi) isPhi = true; 
            mean_Phi[*h][*ds][*ph][*b][*m][both][both] = new RooRealVar(Form("mean_%s_%s_%s_%s_%s_%s"           ,particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][plus][up]   = new RooRealVar(Form("mean_%s_%s_%s_%s_%s_plus_up_%s"   ,particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][minus][dn]  = new RooRealVar(Form("mean_%s_%s_%s_%s_%s_minus_dn_%s"  ,particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][plus][dn]   = new RooRealVar(Form("mean_%s_%s_%s_%s_%s_plus_dn_%s"   ,particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][minus][up]  = new RooRealVar(Form("mean_%s_%s_%s_%s_%s_minus_up_%s"  ,particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][plus][both] = new RooRealVar(Form("mean_%s_%s_%s_%s_%s_plus_both_%s" ,particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][minus][both]= new RooRealVar(Form("mean_%s_%s_%s_%s_%s_minus_both_%s",particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()), "Mean Phi mass", (isPhi?default_Phi:default_D0), (isPhi?Phi_low:D0_low), (isPhi?Phi_high:D0_high));
            mean_Phi[*h][*ds][*ph][*b][*m][both][up]		= mean_Phi[*h][*ds][*ph][*b][*m][both][both];
            mean_Phi[*h][*ds][*ph][*b][*m][both][dn]		= mean_Phi[*h][*ds][*ph][*b][*m][both][both];
            mean_Phi[*h][*ds][*ph][*b][Ds2KPiPi][both][both]	= mean_Phi[*h][*ds][*ph][*b][Ds2KKPi][both][both];
            mean_Phi[*h][*ds][*ph][*b][Ds2PiPiPi][both][both] = mean_Phi[*h][*ds][*ph][*b][Ds2KKPi][both][both];
            mean_Phi[*h][*ds][*ph][*b][Ds2PhiPi][both][both]  = mean_Phi[*h][*ds][*ph][*b][Ds2KKPi][both][both];
          }
        }
      }
    }
  }

  if(par->debug) std::cout<<"Running: PhiModel::DefineModel() --> Making more RooRealVars"<<std::endl;
  // --------- Signal width ---------------
  for(std::vector<std::string>::iterator h=allHelbinList.begin();h!=allHelbinList.end();h++){ 
    for(std::vector<std::string>::iterator ds=allDsBDTbinList.begin();ds!=allDsBDTbinList.end();ds++){ 
      for(std::vector<std::string>::iterator ph=allPhiBDTbinList.begin();ph!=allPhiBDTbinList.end();ph++){
        for(std::vector<std::string>::iterator b=allBmodeList.begin();b!=allBmodeList.end();b++){
          for(std::vector<std::string>::iterator m=allmodeList.begin();m!=allmodeList.end();m++){
            sigma_Phi[*h][*ds][*ph][*b][*m][both][both]  = new RooRealVar(Form("sigma_%s_%s_%s_%s_%s_%s",particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str())          ,Form("%s sigma",mod[*b].c_str()),10,  1,  20); //change D0 to D^0
            sigma_Phi[*h][*ds][*ph][*b][*m][plus][both]  = sigma_Phi[*h][*ds][*ph][*b][*m][both][both];
            sigma_Phi[*h][*ds][*ph][*b][*m][minus][both] = sigma_Phi[*h][*ds][*ph][*b][*m][both][both];
            sigma_Phi[*h][*ds][*ph][*b][*m][plus][up]    = new RooRealVar(Form("sigma_%s_%s_%s_%s_%s_%s_plus_up",particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str())  ,Form("%s sigma",mod[*b].c_str()),10,  1,  20);
            sigma_Phi[*h][*ds][*ph][*b][*m][plus][dn]    = new RooRealVar(Form("sigma_%s_%s_%s_%s_%s_%s_plus_dn",particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str())  ,Form("%s sigma",mod[*b].c_str()),10,  1,  20);
            sigma_Phi[*h][*ds][*ph][*b][*m][minus][up]   = new RooRealVar(Form("sigma_%s_%s_%s_%s_%s_%s_minus_up",particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()) ,Form("%s sigma",mod[*b].c_str()),10,  1,  20);//sigma_Phi[*m][minus][up] = sigma_Phi[*m][plus][dn];
            sigma_Phi[*h][*ds][*ph][*b][*m][minus][dn]   = new RooRealVar(Form("sigma_%s_%s_%s_%s_%s_%s_minus_dn",particle_name[*b].c_str(),(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str()) ,Form("%s sigma",mod[*b].c_str()),10,  1,  20);//sigma_Phi[*m][minus][dn] = sigma_Phi[*m][plus][up];
            sigma_Phi[*h][*ds][*ph][*b][*m][both][up]    = sigma_Phi[*h][*ds][*ph][*b][*m][both][both]; 
            sigma_Phi[*h][*ds][*ph][*b][*m][both][dn]    = sigma_Phi[*h][*ds][*ph][*b][*m][both][both];            
            sigma_Phi[*h][*ds][*ph][DsPhi][*m][both][dn] = sigma_Phi[*h][*ds][*ph][DsD0][*m][both][both];
            sigma_Phi[*h][*ds][*ph][DsPhi][*m][both][up] = sigma_Phi[*h][*ds][*ph][DsD0][*m][both][both];
          }
        }
      }
    }
  }

  // --------- Comb. background slope ---------------
  for(std::vector<std::string>::iterator h=allHelbinList.begin();h!=allHelbinList.end();h++){ 
    for(std::vector<std::string>::iterator ds=allDsBDTbinList.begin();ds!=allDsBDTbinList.end();ds++){ 
      for(std::vector<std::string>::iterator ph=allPhiBDTbinList.begin();ph!=allPhiBDTbinList.end();ph++){
        for(std::vector<std::string>::iterator b=allBmodeList.begin();b!=allBmodeList.end();b++){ 
          for(std::vector<std::string>::iterator m=allmodeList.begin();m!=allmodeList.end();m++){
            comb_a1[*h][*ds][*ph][*b][*m] = new RooRealVar(Form("comb_a1_%s_%s_%s_%s_%s",(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str())   ,Form("%s comb. a1",mod[*b].c_str()),  0.4,   -1.0, 1.0);
            comb_a2[*h][*ds][*ph][*b][*m] = new RooRealVar(Form("comb_a2_%s_%s_%s_%s_%s",(*h).c_str(),(*ds).c_str(),(*ph).c_str(),(*b).c_str(),(*m).c_str())   ,Form("%s comb. a2",mod[*b].c_str()), -0.004, -1.0, 1.0);
          }
        }
      }
    }
  }
  
  // --------- Fix RooRealVars to each other  -------------
  // ------------------------------------------------------
  // ------------------------------------------------------
   
  for(std::vector<std::string>::iterator h=allHelbinList.begin();h!=allHelbinList.end();h++){ 
    for(std::vector<std::string>::iterator ds=allDsBDTbinList.begin();ds!=allDsBDTbinList.end();ds++){ 
      for(std::vector<std::string>::iterator ph=allPhiBDTbinList.begin();ph!=allPhiBDTbinList.end();ph++){
        for(std::vector<std::string>::iterator b=allBmodeList.begin();b!=allBmodeList.end();b++){  
          for(std::vector<std::string>::iterator m=allmodeList.begin();m!=allmodeList.end();m++){           
 
            // Fix comb slope to be the same 
            comb_a1[*h][*ds][*ph][*b][*m] = comb_a1[*HelBinList.begin()][*DsBDTBinList.begin()][*PhiBDTBinList.begin()][*BmodeList.begin()][*modeList.begin()];
            comb_a2[*h][*ds][*ph][*b][*m] = comb_a2[*HelBinList.begin()][*DsBDTBinList.begin()][*PhiBDTBinList.begin()][*BmodeList.begin()][*modeList.begin()];

            for(std::vector<std::string>::iterator a=magnetList.begin();a!=magnetList.end();a++){
              for(std::vector<std::string>::iterator c=chargeList.begin();c!=chargeList.end();c++){
                
                // Use same mean value for all plots 
                mean_Phi[*h][*ds][*ph][*b][*m][*a][*c] = mean_Phi[*HelBinList.begin()][*DsBDTBinList.begin()][*PhiBDTBinList.begin()][*BmodeList.begin()][*modeList.begin()][both][both]; 

                // Allow sigma_Phi to vary between Ds decay modes
                sigma_Phi[*h][*ds][*ph][*b][*m][*a][*c] = sigma_Phi[*HelBinList.begin()][*DsBDTBinList.begin()][*PhiBDTBinList.begin()][*BmodeList.begin()][*m][*magnetList.begin()][*chargeList.begin()]; 

              }
            }
          }
        }
      }
    }
  }



  // --------- Define the simultaneous PDFs ---------------
  // ------------------------------------------------------
  // ------------------------------------------------------
  
  if(par->debug) std::cout<<"Running: PhiModel::DefineModel() --> Setting up simultaneous PDF"<<std::endl;
  sim = new RooSimultaneous("model","Simultaneous model",*cat);

  RooAbsPdf *pdf_peak = 0;
  RooAbsPdf *pdf_comb = 0;
  for(std::vector<std::string>::iterator h=HelBinList.begin();h!=HelBinList.end();h++){ 
    for(std::vector<std::string>::iterator ds=DsBDTBinList.begin();ds!=DsBDTBinList.end();ds++){ 
      for(std::vector<std::string>::iterator ph=PhiBDTBinList.begin();ph!=PhiBDTBinList.end();ph++){
        for(std::vector<std::string>::iterator b=BmodeList.begin();b!=BmodeList.end();b++){
          for(std::vector<std::string>::iterator m=modeList.begin();m!=modeList.end();m++){
            for(std::vector<std::string>::iterator a=magnetList.begin();a!=magnetList.end();a++){
              for(std::vector<std::string>::iterator c=chargeList.begin();c!=chargeList.end();c++){
                std::string tag=(*h)+underscore+(*ds)+underscore+(*ph)+underscore+(*b)+underscore+(*m)+underscore+(*c)+underscore+(*a);
                if(par->debug) std::cout<<"Running: PhiModel::DefineModel() --> Adding to sim pdf: "<< tag <<std::endl;
                
                //DsD0
                RooAbsReal* mub     = mean_Phi[*h][*ds][*ph][*b][*m][*c][*a];
                RooAbsReal* sig     = sigma_Phi[*h][*ds][*ph][*b][*m][*c][*a];
                pdf_peak  = new RooGaussian( Form("pdf_Phi_peak_%s",tag.c_str()), "", (((*b).c_str()==DsPhi)?*mPhi:*mD0), *mub, *sig );

                //comb bkg
                RooRealVar* comba1 = comb_a1[*h][*ds][*ph][*b][*m];
                RooRealVar* comba2 = comb_a2[*h][*ds][*ph][*b][*m];
                pdf_comb = new RooChebychev(Form("pdf_Phi_comb_%s",tag.c_str()),"",(((*b).c_str()==DsPhi)?*mPhi:*mD0),RooArgSet(*comba1,*comba2)) ;
              
                //List of PDFs and yields
                RooArgSet pdflist( *pdf_peak, *pdf_comb);
                RooArgSet nevents( *Phi_yield[*h][*ds][*ph][*b][*m][*c][*a], *yield_Phi_comb[*h][*ds][*ph][*b][*m][*c][*a]); 
                
                //Add to master PDF
                RooAddPdf* masterPdf       = new RooAddPdf(Form("masterPdf_Phi_%s",tag.c_str())       ,"",pdflist, nevents);
        	      
                std::stringstream str;
                str<<(*h)<<underscore<<(*ds)<<underscore<<(*ph)<<underscore<<(*b)<<underscore<<(*m)<<underscore<<(*c)<<underscore<<(*a);
                
                sim->addPdf(*masterPdf,str.str().c_str());

              }
            }
          } 
        }//closing of for loops over b, m, a and c
      }
    }
  } // closing loop over h
} //end of funcn DefineModel()