当前位置: 首页>>代码示例>>C++>>正文


C++ RooDataSet::reduce方法代码示例

本文整理汇总了C++中RooDataSet::reduce方法的典型用法代码示例。如果您正苦于以下问题:C++ RooDataSet::reduce方法的具体用法?C++ RooDataSet::reduce怎么用?C++ RooDataSet::reduce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RooDataSet的用法示例。


在下文中一共展示了RooDataSet::reduce方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: rf405_realtocatfuncs

void rf405_realtocatfuncs()
{

   // D e f i n e   p d f   i n   x ,   s a m p l e   d a t a s e t   i n   x 
   // ------------------------------------------------------------------------


   // Define a dummy PDF in x 
   RooRealVar x("x","x",0,10) ;
   RooArgusBG a("a","argus(x)",x,RooConst(10),RooConst(-1)) ;

   // Generate a dummy dataset 
   RooDataSet *data = a.generate(x,10000) ;



   // C r e a t e   a   t h r e s h o l d   r e a l - > c a t   f u n c t i o n
   // --------------------------------------------------------------------------

   // A RooThresholdCategory is a category function that maps regions in a real-valued 
   // input observable observables to state names. At construction time a 'default'
   // state name must be specified to which all values of x are mapped that are not
   // otherwise assigned
   RooThresholdCategory xRegion("xRegion","region of x",x,"Background") ;

   // Specify thresholds and state assignments one-by-one. 
   // Each statement specifies that all values _below_ the given value 
   // (and above any lower specified threshold) are mapped to the
   // category state with the given name
   //
   // Background | SideBand | Signal | SideBand | Background
   //           4.23       5.23     8.23       9.23 
   xRegion.addThreshold(4.23,"Background") ;
   xRegion.addThreshold(5.23,"SideBand") ;
   xRegion.addThreshold(8.23,"Signal") ;
   xRegion.addThreshold(9.23,"SideBand") ; 



   // U s e   t h r e s h o l d   f u n c t i o n   t o   p l o t   d a t a   r e g i o n s
   // -------------------------------------------------------------------------------------

   // Add values of threshold function to dataset so that it can be used as observable
   data->addColumn(xRegion) ;

   // Make plot of data in x
   RooPlot* xframe = x.frame(Title("Demo of threshold and binning mapping functions")) ;
   data->plotOn(xframe) ;

   // Use calculated category to select sideband data
   data->plotOn(xframe,Cut("xRegion==xRegion::SideBand"),MarkerColor(kRed),LineColor(kRed)) ;



   // C r e a t e   a   b i n n i n g    r e a l - > c a t   f u n c t i o n
   // ----------------------------------------------------------------------

   // A RooBinningCategory is a category function that maps bins of a (named) binning definition 
   // in a real-valued input observable observables to state names. The state names are automatically
   // constructed from the variable name, the binning name and the bin number. If no binning name
   // is specified the default binning is mapped

   x.setBins(10,"coarse") ;
   RooBinningCategory xBins("xBins","coarse bins in x",x,"coarse") ;



   // U s e   b i n n i n g   f u n c t i o n   f o r   t a b u l a t i o n   a n d   p l o t t i n g
   // -----------------------------------------------------------------------------------------------

   // Print table of xBins state multiplicity. Note that xBins does not need to be an observable in data
   // it can be a function of observables in data as well
   Roo1DTable* xbtable = data->table(xBins) ;
   xbtable->Print("v") ;

   // Add values of xBins function to dataset so that it can be used as observable
   RooCategory* xb = (RooCategory*) data->addColumn(xBins) ;

   // Define range "alt" as including bins 1,3,5,7,9 
   xb->setRange("alt","x_coarse_bin1,x_coarse_bin3,x_coarse_bin5,x_coarse_bin7,x_coarse_bin9") ;

   // Construct subset of data matching range "alt" but only for the first 5000 events and plot it on the frame
   RooDataSet* dataSel = (RooDataSet*) data->reduce(CutRange("alt"),EventRange(0,5000)) ;
   dataSel->plotOn(xframe,MarkerColor(kGreen),LineColor(kGreen)) ;



   new TCanvas("rf405_realtocatfuncs","rf405_realtocatfuncs",600,600) ;
   xframe->SetMinimum(0.01) ;
   gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;


}
开发者ID:Y--,项目名称:root,代码行数:93,代码来源:rf405_realtocatfuncs.C

示例2: rf303_conditional

void rf303_conditional()
{
   // S e t u p   c o m p o s e d   m o d e l   g a u s s ( x , m ( y ) , s )
   // -----------------------------------------------------------------------

   // Create observables
   RooRealVar x("x","x",-10,10) ;
   RooRealVar y("y","y",-10,10) ;

   // Create function f(y) = a0 + a1*y
   RooRealVar a0("a0","a0",-0.5,-5,5) ;
   RooRealVar a1("a1","a1",-0.5,-1,1) ;
   RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;

   // Create gauss(x,f(y),s)
   RooRealVar sigma("sigma","width of gaussian",0.5,0.1,2.0) ;
   RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ;


   // Obtain fake external experimental dataset with values for x and y
   RooDataSet* expDataXY = makeFakeDataXY() ;



   // G e n e r a t e   d a t a   f r o m   c o n d i t i o n a l   p . d . f   m o d e l ( x | y )
   // ---------------------------------------------------------------------------------------------

   // Make subset of experimental data with only y values
   RooDataSet* expDataY= (RooDataSet*) expDataXY->reduce(y) ;

   // Generate 10000 events in x obtained from _conditional_ model(x|y) with y values taken from experimental data
   RooDataSet *data = model.generate(x,ProtoData(*expDataY)) ;
   data->Print() ;



   // F i t   c o n d i t i o n a l   p . d . f   m o d e l ( x | y )   t o   d a t a
   // ---------------------------------------------------------------------------------------------

   model.fitTo(*expDataXY,ConditionalObservables(y)) ;



   // P r o j e c t   c o n d i t i o n a l   p . d . f   o n   x   a n d   y   d i m e n s i o n s
   // ---------------------------------------------------------------------------------------------

   // Plot x distribution of data and projection of model on x = 1/Ndata sum(data(y_i)) model(x;y_i)
   RooPlot* xframe = x.frame() ;
   expDataXY->plotOn(xframe) ;
   model.plotOn(xframe,ProjWData(*expDataY)) ;


   // Speed up (and approximate) projection by using binned clone of data for projection
   RooAbsData* binnedDataY = expDataY->binnedClone() ;
   model.plotOn(xframe,ProjWData(*binnedDataY),LineColor(kCyan),LineStyle(kDotted)) ;


   // Show effect of projection with too coarse binning
   ((RooRealVar*)expDataY->get()->find("y"))->setBins(5) ;
   RooAbsData* binnedDataY2 = expDataY->binnedClone() ;
   model.plotOn(xframe,ProjWData(*binnedDataY2),LineColor(kRed)) ;


   // Make canvas and draw RooPlots
   new TCanvas("rf303_conditional","rf303_conditional",600, 460);
   gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.2) ; xframe->Draw() ;

}
开发者ID:Y--,项目名称:root,代码行数:68,代码来源:rf303_conditional.C

示例3: fitKmm_loQ

void fitKmm_loQ(Int_t bin) {
	gSystem->Load("libRooFit");
	gROOT->SetStyle("Plain");
	gStyle->SetOptStat(1111);

	TFile * file = TFile::Open("/Disk/ecdf-nfs-ppe/lhcb/gcowan/B2Kll/data/fromAlex/BuKmm.root");
	TTree * DecayTree = dynamic_cast<TTree*>(file->Get("DecayTree"));

	TString binStr; binStr+=bin;
	Double_t minQ(0.), maxQ(0.);

	switch(bin) {
	case 0:
		minQ = TMath::Sqrt(1.1e6);
		maxQ = TMath::Sqrt(2.e6);
		break;
	case 1:
		minQ = TMath::Sqrt(2.e6);
		maxQ = TMath::Sqrt(3.e6);
		break;
	case 2:
		minQ = TMath::Sqrt(3.e6);
		maxQ = TMath::Sqrt(4.e6);
		break;
	case 3:
		minQ = TMath::Sqrt(4.e6);
		maxQ = TMath::Sqrt(5.e6);
		break;
	case 4:
		minQ = TMath::Sqrt(5.e6);
		maxQ = TMath::Sqrt(6.e6);
		break;
	default:
		return;
	}
	TString cutStr("Psi_M> "); cutStr += minQ; cutStr += " && Psi_M< "; cutStr += maxQ;

	//B_M 
	RooRealVar B_M("B_M","; m(Kmumu) (MeV/c^{2}); Candidates / 12 MeV/c^{2}",5150,6000);
	RooRealVar Psi_M("Psi_M","; m(mumu) (MeV/c^{2}); Candidates / 45 MeV/c^{2}",500,5000);

	RooDataSet * data  = new RooDataSet("data", "dataset with B_REFITTED_M", DecayTree, RooArgSet(B_M,Psi_M));
	RooDataSet * data1 = dynamic_cast<RooDataSet*>(data->reduce(cutStr));

// from J/Psi region
//   1  #sigma_{Lo}  1.59171e+01   9.61516e-02   1.80663e-03   6.11760e-02
//   2  M_{B}        5.28397e+03   3.00802e-02   1.66677e-03   3.66768e-01
//   3  a1           1.57752e+00   1.64484e-02   2.65338e-03  -7.53912e-01
//   4  a2          -2.64268e+00   2.11254e-02   2.51938e-03   4.90950e-01
//   5  frac         6.78672e-01   1.29969e-02   7.03329e-03   3.65422e-01
//   6  n1           4.79832e+00   2.84430e-01   2.61785e-02  -4.03463e-02
//   7  n2           1.08224e+00   2.68180e-02   5.47500e-03  -9.00362e-01
//   8  nbkg         5.56890e+03   1.31433e+02   7.62084e-03  -8.36640e-01
//   9  nsig         6.56230e+05   8.17224e+02   4.15943e-03   6.95832e-01
//  10  p0          -6.44379e-02   2.13769e-03   2.57927e-02   4.41139e-01
//  11  ratio        1.60407e+00   9.46569e-03   3.93086e-03  -7.72555e-01


	// B DCB 
	// start, range to from. plus names and titles.
	RooRealVar sigmean("M_{B}","B mass",5281.0,5250.0,5300.0,"MeV/c^{2}");
	RooRealVar sigsigma("#sigma_{Lo}","B sigma",15.9,0.0,30.0,"MeV/c^{2}");
	RooRealVar a1("a1","a1", 1.57752e+00);
	RooRealVar n1("n1","n1", 4.79832e+00);
	RooRealVar a2("a2","a2",-2.64268e+00);
	RooRealVar n2("n2","n2", 1.08224e+00);
	RooRealVar ratio("ratio","Ratio of widths",1.60407e+00);
	RooProduct sigsigma2("#sigma_{B}2","B sigma2",RooArgSet(sigsigma,ratio));
	RooRealVar frac("frac","fraction of events in each gaussian",6.78672e-01);
	RooCBShape BSig_RF( "Bsig_RF", "Signal CB B RF Mass", B_M, sigmean, sigsigma, a1, n1 );
	RooCBShape BSig_RF2( "Bsig_RF2", "Signal CB B RF Mass", B_M, sigmean, sigsigma2, a2, n2 );
	RooAddPdf B0Sig("B0signal","signal pdf",RooArgList(BSig_RF,BSig_RF2),RooArgList(frac));

	RooRealVar p0("p0","",-6.44379e-02,-0.1,0.1);
	RooExponential comb_bkg("comb_bkg","",B_M,p0);

	// Number of signal & background events
	RooRealVar nsig("nsig","#signal events",150,-1000,50000,"Events");
	RooRealVar nbkg("nbkg","#signal events",150,-1000,50000,"Events");

	RooAddPdf full_RF_PDF("full_RF_PDF","RF PDF of everything",RooArgList(B0Sig,comb_bkg), RooArgList(nsig,nbkg));

	//# Do the fit on REFITTED Mass
	full_RF_PDF.fitTo(*data1,RooFit::Extended());

	TCanvas * can = new TCanvas("can","Mass fits Data",800,600);
	B_M_RF_Plot = B_M.frame(100);
	B_M_RF_Plot->SetTitle("");
	B_M_RF_Plot->GetYaxis()->SetTitle("Candidates / 8.5 MeV/c^{2}");
	B_M_RF_Plot->GetXaxis()->SetTitle("m(K#mu#mu) (MeV/c^{2})");

	data1->plotOn(B_M_RF_Plot);
	full_RF_PDF.plotOn(B_M_RF_Plot);
	full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("comb_bkg"), RooFit::LineStyle(kDashed),RooFit::LineColor(kMagenta));
        full_RF_PDF.plotOn(B_M_RF_Plot, RooFit::Components("B0signal"), RooFit::LineStyle(kDashed));
	B_M_RF_Plot->Draw();

	can->SaveAs("plots/Kmm_loQ_"+binStr+".pdf");

	can->SetLogy();
//.........这里部分代码省略.........
开发者ID:dcraik,项目名称:lhcb,代码行数:101,代码来源:fitKmm_loQ.C

示例4: main

int main(int argc, char* argv[])
{
  string name;

  for(Int_t i=1;i<argc;i++){
    char *pchar = argv[i];

    switch(pchar[0]){

    case '-':{

      switch(pchar[1]){
      case 'n':
        name = argv[i+1];
        cout << "Name of the configuration key " << name << endl;
        break;
      }
    }
    }
  }

  Bool_t doFit = kFALSE;
  Bool_t extract = kFALSE;
  Bool_t doFrac = kFALSE;
  Bool_t doPlots = kTRUE;
  Bool_t doChi2 = kFALSE;

  BaBarStyle p;
  p.SetBaBarStyle();
  gROOT->GetStyle("BABAR")->SetPalette(1);
  gROOT->GetStyle("BABAR")->SetPadTopMargin(0.04);
  gROOT->GetStyle("BABAR")->SetPadLeftMargin(0.17);
  gROOT->GetStyle("BABAR")->SetPadBottomMargin(0.19);
  gROOT->GetStyle("BABAR")->SetTitleSize(0.08,"xyz"); // set the 3 axes title size 

  //define DalitzSpace for generation
  EvtPDL pdl;
  pdl.readPDT("evt.pdl");
  EvtDecayMode mode("D0 -> K- pi+ pi0");
  EvtDalitzPlot dalitzSpace(mode);

  RooRealVar tau("tau","tau",0.4099);
  RooRealVar m2Kpi_d0mass("m2Kpi_d0mass","m2Kpi_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::AB),dalitzSpace.qAbsMax(EvtCyclic3::AB));
  RooRealVar m2Kpi0_d0mass("m2Kpi0_d0mass","m2Kpi0_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::AC),dalitzSpace.qAbsMax(EvtCyclic3::AC));
  RooRealVar m2pipi0_d0mass("m2pipi0_d0mass","m2pipi0_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::BC),dalitzSpace.qAbsMax(EvtCyclic3::BC));
  RooRealVar d0Lifetime("d0Lifetime","d0Lifetime",-2.,4.);
  RooRealVar d0LifetimeErr("d0LifetimeErr","d0LifetimeErr",0.0000001,0.5);
  RooCategory D0flav("D0flav","D0flav");
  D0flav.defineType("D0",-1);
  D0flav.defineType("antiD0",1);

  RooRealVar scalefact1("scalefact1","scalefact1",3.20);
  RooRealVar scalefact2("scalefact2","scalefact2",1.42);
  RooRealVar scalefact3("scalefact3","scalefact3",0.94);

  RooRealVar c1("c1","c1",-2.,2.);
  RooRealVar c2("c2","c2",-2.,2.);
  RooUnblindOffset c1_unblind("c1_unblind","c1 (unblind)","VaffanculoS",1.,c1) ;
  RooUnblindOffset c2_unblind("c2_unblind","c2 (unblind)","VaffanculoS",1.,c2) ;

  TFile fWS("DataSet_out_tmp.root");
  gROOT->cd();
  RooDataSet *data = (RooDataSet*)fWS.Get("fulldata");
  RooDataSet *data_clean = (RooDataSet*)data->reduce("d0LifetimeErr < 0.5 && d0Lifetime > -2. && d0Lifetime < 4. && deltaMass > 0.1449 && deltaMass < 0.1459");
  RooDataSet *dataWS_2 = (RooDataSet*)data_clean->reduce("isWS == 1");
  RooDataSet *dataWS = (RooDataSet*)dataWS_2->reduce("d0Mass > 1.8495 && d0Mass < 1.8795");
  RooDataSet *RSdata = (RooDataSet*)data_clean->reduce("isWS == 0 && d0Mass > 1.8495 && d0Mass < 1.8795");

  Double_t low12,hig12,low13,hig13,low23,hig23;
  Bool_t m12bool = dataWS->getRange(m2Kpi_d0mass,low12,hig12);
  Bool_t m13bool = dataWS->getRange(m2Kpi0_d0mass,low13,hig13);
  Bool_t m23bool = dataWS->getRange(m2pipi0_d0mass,low23,hig23);
  m2Kpi_d0mass.setRange(low12,hig12);
  m2Kpi0_d0mass.setRange(low13,hig13);
  m2pipi0_d0mass.setRange(low23,hig23);

  m2Kpi_d0mass.setBins(10);
  m2Kpi0_d0mass.setBins(10);
  d0Lifetime.setBins(8);
  d0LifetimeErr.setBins(10);
  m2pipi0_d0mass.setBins(10);

  Float_t total = pow(dalitzSpace.bigM(),2) + pow(dalitzSpace.mA(),2) + pow(dalitzSpace.mB(),2) + pow(dalitzSpace.mC(),2);
  RooRealVar totalm("totalm","totalm",total);
  RooFormulaVar mass13a("mass13a","@[email protected]@2",RooArgSet(totalm,m2Kpi_d0mass,m2pipi0_d0mass));

  //Construct signal pdf
  RooRealVar bias("bias","bias",0.0047) ;
  RooRealVar one("one","one",1.);

  //consider the resolution or the truth model
  RooGaussModel gm1("gm1","gauss model 1",d0Lifetime,bias,d0LifetimeErr,one,scalefact1) ;
  RooGaussModel gm2("gm2","gauss model 2",d0Lifetime,bias,d0LifetimeErr,one,scalefact2) ;
  RooGaussModel gm3("gm3","gauss model 3",d0Lifetime,bias,d0LifetimeErr,one,scalefact3) ;

  RooRealVar N1("N1","N1",0.0052);
  RooRealVar N2("N2","N2",0.179);

  RooFormulaVar f2("f2","f2","([email protected])*@1",RooArgList(N1,N2));
  RooFormulaVar f3("f3","f3","([email protected])*([email protected])",RooArgList(N1,N2));
//.........这里部分代码省略.........
开发者ID:pellicci,项目名称:UserCode,代码行数:101,代码来源:WSTimeFit.C


注:本文中的RooDataSet::reduce方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。