本文整理汇总了C++中RooDataSet::weight方法的典型用法代码示例。如果您正苦于以下问题:C++ RooDataSet::weight方法的具体用法?C++ RooDataSet::weight怎么用?C++ RooDataSet::weight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RooDataSet
的用法示例。
在下文中一共展示了RooDataSet::weight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: backgroundFits_ggzz_1Dw
// The actual job
void backgroundFits_ggzz_1Dw(int channel, int sqrts, int VBFtag)
{
TString schannel;
if (channel == 1) schannel = "4mu";
else if (channel == 2) schannel = "4e";
else if (channel == 3) schannel = "2e2mu";
else cout << "Not a valid channel: " << schannel << endl;
TString ssqrts = (long) sqrts + TString("TeV");
cout << "schannel = " << schannel << " sqrts = " << sqrts << " VBFtag = "<< VBFtag << endl;
TString outfile;
outfile = "CardFragments/ggzzBackgroundFit_" + ssqrts + "_" + schannel + "_" + Form("%d",int(VBFtag)) + ".txt";
ofstream of(outfile,ios_base::out);
gSystem->AddIncludePath("-I$ROOFITSYS/include");
gROOT->ProcessLine(".L ../CreateDatacards/include/tdrstyle.cc");
setTDRStyle(false);
gStyle->SetPadLeftMargin(0.16);
TString filepath;filepath.Form("AAAOK/ZZ%s/ZZ4lAnalysis.root",schannel.Data());
TFile *f = TFile::Open(filepath);
TTree *tree = f->Get("ZZTree/candTree");
RooRealVar* MC_weight = new RooRealVar("MC_weight","MC_weight",0.,2.) ;
RooRealVar* ZZMass = new RooRealVar("ZZMass","ZZMass",100,100.,1000.);
RooRealVar* NJets30 = new RooRealVar("NJets30","NJets30",0.,5.);
RooArgSet ntupleVarSet(*ZZMass,*NJets30,*MC_weight);
RooDataSet *set = new RooDataSet("set","set",ntupleVarSet,WeightVar("MC_weight"));
//RooArgSet ntupleVarSet(*ZZMass,*NJets30);
//RooDataSet *set = new RooDataSet("set","set",ntupleVarSet);
Float_t myMC,myMass;
Int_t myNJets;
int nentries = tree->GetEntries();
Float_t myPt,myJetPt,myJetEta,myJetPhi,myJetMass,myFisher;
Int_t myExtralep,myBJets;
tree->SetBranchAddress("ZZMass",&myMass);
tree->SetBranchAddress("genHEPMCweight",&myMC);
tree->SetBranchAddress("nCleanedJetsPt30",&myNJets);
tree->SetBranchAddress("ZZPt",&myPt);
tree->SetBranchAddress("nExtraLep",&myExtralep);
tree->SetBranchAddress("nCleanedJetsPt30BTagged",&myBJets);
tree->SetBranchAddress("DiJetDEta",&myFisher);
for(int i =0;i<nentries;i++) {
tree->GetEntry(i);
if(myMass<100.)continue;
int cat = category(myExtralep,myPt, myMass,myNJets, myBJets,/* jetpt, jeteta, jetphi, jetmass,*/myFisher);
if(VBFtag != cat )continue;
ntupleVarSet.setRealValue("ZZMass",myMass);
ntupleVarSet.setRealValue("MC_weight",myMC);
ntupleVarSet.setRealValue("NJets30",(double)cat);
set->add(ntupleVarSet, myMC);
}
//RooRealVar* ZZLD = new RooRealVar("ZZLD","ZZLD",0.,1.);
//char cut[10];
//sprintf(cut,"ZZLD>0.5");
//RooDataSet* set = new RooDataSet("set","set",tree,RooArgSet(*ZZMass,*MC_weight,*ZZLD),cut,"MC_weight");
double totalweight = 0.;
for (int i=0 ; i<set->numEntries() ; i++) {
set->get(i) ;
totalweight += set->weight();
//cout << CMS_zz4l_mass->getVal() << " = " << set->weight() << endl ;
}
cout << "nEntries: " << set->numEntries() << ", totalweight: " << totalweight << endl;
gSystem->Load("libHiggsAnalysisCombinedLimit.so");
//// ---------------------------------------
//Background
RooRealVar CMS_qqzzbkg_a0("CMS_qqzzbkg_a0","CMS_qqzzbkg_a0",115.3,0.,200.);
RooRealVar CMS_qqzzbkg_a1("CMS_qqzzbkg_a1","CMS_qqzzbkg_a1",21.96,0.,200.);
RooRealVar CMS_qqzzbkg_a2("CMS_qqzzbkg_a2","CMS_qqzzbkg_a2",122.8,0.,200.);
RooRealVar CMS_qqzzbkg_a3("CMS_qqzzbkg_a3","CMS_qqzzbkg_a3",0.03479,0.,1.);
RooRealVar CMS_qqzzbkg_a4("CMS_qqzzbkg_a4","CMS_qqzzbkg_a4",185.5,0.,200.);
RooRealVar CMS_qqzzbkg_a5("CMS_qqzzbkg_a5","CMS_qqzzbkg_a5",12.67,0.,200.);
RooRealVar CMS_qqzzbkg_a6("CMS_qqzzbkg_a6","CMS_qqzzbkg_a6",34.81,0.,100.);
RooRealVar CMS_qqzzbkg_a7("CMS_qqzzbkg_a7","CMS_qqzzbkg_a7",0.1393,0.,1.);
RooRealVar CMS_qqzzbkg_a8("CMS_qqzzbkg_a8","CMS_qqzzbkg_a8",66.,0.,200.);
RooRealVar CMS_qqzzbkg_a9("CMS_qqzzbkg_a9","CMS_qqzzbkg_a9",0.07191,0.,1.);
RooggZZPdf_v2* bkg_ggzz = new RooggZZPdf_v2("bkg_ggzz","bkg_ggzz",*ZZMass,
CMS_qqzzbkg_a0,CMS_qqzzbkg_a1,CMS_qqzzbkg_a2,CMS_qqzzbkg_a3,CMS_qqzzbkg_a4,
CMS_qqzzbkg_a5,CMS_qqzzbkg_a6,CMS_qqzzbkg_a7,CMS_qqzzbkg_a8,CMS_qqzzbkg_a9);
//// ---------------------------------------
RooFitResult *r1 = bkg_ggzz->fitTo( *set, Save(kTRUE), SumW2Error(kTRUE) );//, Save(kTRUE), SumW2Error(kTRUE)) ;
cout << endl;
cout << "------- Parameters for " << schannel << " sqrts=" << sqrts << endl;
cout << " a0_bkgd = " << CMS_qqzzbkg_a0.getVal() << endl;
//.........这里部分代码省略.........
示例2: backgroundFits_qqzz_1Dw
// The actual job
void backgroundFits_qqzz_1Dw(int channel, int sqrts, int VBFtag)
{
if(sqrts==7)return;
TString schannel;
if (channel == 1) schannel = "4mu";
else if (channel == 2) schannel = "4e";
else if (channel == 3) schannel = "2e2mu";
else cout << "Not a valid channel: " << schannel << endl;
TString ssqrts = (long) sqrts + TString("TeV");
cout << "schannel = " << schannel << " sqrts = " << sqrts << " VBFtag = " << VBFtag << endl;
TString outfile;
if(VBFtag<2) outfile = "CardFragments/qqzzBackgroundFit_" + ssqrts + "_" + schannel + "_" + Form("%d",int(VBFtag)) + ".txt";
if(VBFtag==2) outfile = "CardFragments/qqzzBackgroundFit_" + ssqrts + "_" + schannel + ".txt";
ofstream of(outfile,ios_base::out);
of << "### background functions ###" << endl;
gSystem->AddIncludePath("-I$ROOFITSYS/include");
gROOT->ProcessLine(".L ../CreateDatacards/include/tdrstyle.cc");
setTDRStyle(false);
gStyle->SetPadLeftMargin(0.16);
TString filepath;
if (sqrts==7) {
filepath = filePath7TeV;
} else if (sqrts==8) {
filepath = filePath8TeV;
}
TChain* tree = new TChain("SelectedTree");
tree->Add( filepath+ "/" + (schannel=="2e2mu"?"2mu2e":schannel) + "/HZZ4lTree_ZZTo*.root");
RooRealVar* MC_weight = new RooRealVar("MC_weight","MC_weight",0.,2.) ;
RooRealVar* ZZMass = new RooRealVar("ZZMass","ZZMass",100.,1000.);
RooRealVar* NJets30 = new RooRealVar("NJets30","NJets30",0.,100.);
RooArgSet ntupleVarSet(*ZZMass,*NJets30,*MC_weight);
RooDataSet *set = new RooDataSet("set","set",ntupleVarSet,WeightVar("MC_weight"));
Float_t myMC,myMass;
Short_t myNJets;
int nentries = tree->GetEntries();
tree->SetBranchAddress("ZZMass",&myMass);
tree->SetBranchAddress("MC_weight",&myMC);
tree->SetBranchAddress("NJets30",&myNJets);
for(int i =0;i<nentries;i++) {
tree->GetEntry(i);
if(VBFtag==1 && myNJets<2)continue;
if(VBFtag==0 && myNJets>1)continue;
ntupleVarSet.setRealValue("ZZMass",myMass);
ntupleVarSet.setRealValue("MC_weight",myMC);
ntupleVarSet.setRealValue("NJets30",(double)myNJets);
set->add(ntupleVarSet, myMC);
}
double totalweight = 0.;
double totalweight_z = 0.;
for (int i=0 ; i<set->numEntries() ; i++) {
//set->get(i) ;
RooArgSet* row = set->get(i) ;
//row->Print("v");
totalweight += set->weight();
if (row->getRealValue("ZZMass") < 200) totalweight_z += set->weight();
}
cout << "nEntries: " << set->numEntries() << ", totalweight: " << totalweight << ", totalweight_z: " << totalweight_z << endl;
gSystem->Load("libHiggsAnalysisCombinedLimit.so");
//// ---------------------------------------
//Background
RooRealVar CMS_qqzzbkg_a0("CMS_qqzzbkg_a0","CMS_qqzzbkg_a0",115.3,0.,200.);
RooRealVar CMS_qqzzbkg_a1("CMS_qqzzbkg_a1","CMS_qqzzbkg_a1",21.96,0.,200.);
RooRealVar CMS_qqzzbkg_a2("CMS_qqzzbkg_a2","CMS_qqzzbkg_a2",122.8,0.,200.);
RooRealVar CMS_qqzzbkg_a3("CMS_qqzzbkg_a3","CMS_qqzzbkg_a3",0.03479,0.,1.);
RooRealVar CMS_qqzzbkg_a4("CMS_qqzzbkg_a4","CMS_qqzzbkg_a4",185.5,0.,200.);
RooRealVar CMS_qqzzbkg_a5("CMS_qqzzbkg_a5","CMS_qqzzbkg_a5",12.67,0.,200.);
RooRealVar CMS_qqzzbkg_a6("CMS_qqzzbkg_a6","CMS_qqzzbkg_a6",34.81,0.,100.);
RooRealVar CMS_qqzzbkg_a7("CMS_qqzzbkg_a7","CMS_qqzzbkg_a7",0.1393,0.,1.);
RooRealVar CMS_qqzzbkg_a8("CMS_qqzzbkg_a8","CMS_qqzzbkg_a8",66.,0.,200.);
RooRealVar CMS_qqzzbkg_a9("CMS_qqzzbkg_a9","CMS_qqzzbkg_a9",0.07191,0.,1.);
RooRealVar CMS_qqzzbkg_a10("CMS_qqzzbkg_a10","CMS_qqzzbkg_a10",94.11,0.,200.);
RooRealVar CMS_qqzzbkg_a11("CMS_qqzzbkg_a11","CMS_qqzzbkg_a11",-5.111,-100.,100.);
RooRealVar CMS_qqzzbkg_a12("CMS_qqzzbkg_a12","CMS_qqzzbkg_a12",4834,0.,10000.);
RooRealVar CMS_qqzzbkg_a13("CMS_qqzzbkg_a13","CMS_qqzzbkg_a13",0.2543,0.,1.);
if (channel == 1){
///* 4mu
CMS_qqzzbkg_a0.setVal(103.854);
CMS_qqzzbkg_a1.setVal(10.0718);
CMS_qqzzbkg_a2.setVal(117.551);
CMS_qqzzbkg_a3.setVal(0.0450287);
CMS_qqzzbkg_a4.setVal(185.262);
//.........这里部分代码省略.........
示例3: main
int main(int argc, char *argv[]){
OptionParser(argc,argv);
RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR);
RooMsgService::instance().setSilentMode(true);
system(Form("mkdir -p %s",outdir_.c_str()));
vector<string> procs;
split(infilenames_,infilenamesStr_,boost::is_any_of(","));
TPython::Exec("import os,imp,re");
const char * env = gSystem->Getenv("CMSSW_BASE") ;
std::string globeRt = env;
TPython::Exec(Form("buildSMHiggsSignalXSBR = imp.load_source('*', '%s/src/flashggFinalFit/Signal/python/buildSMHiggsSignalXSBR.py')",globeRt.c_str()));
TPython::Eval(Form("buildSMHiggsSignalXSBR.Init%dTeV()", 13));
for (unsigned int i =0 ; i<infilenames_.size() ; i++){
int mH =(int) TPython::Eval(Form("int(re.search('_M(.+?)_','%s').group(1))",infilenames_[i].c_str()));
double WH_XS = (double)TPython::Eval(Form("buildSMHiggsSignalXSBR.getXS(%d,'%s')",mH,"WH"));
double ZH_XS = (double)TPython::Eval(Form("buildSMHiggsSignalXSBR.getXS(%d,'%s')",mH,"ZH"));
float tot_XS = WH_XS + ZH_XS;
float wFrac= WH_XS /tot_XS ;
float zFrac= ZH_XS /tot_XS ;
std::cout << "mass "<< mH << " wh fraction "<< WH_XS /tot_XS << ", zh fraction "<< ZH_XS /tot_XS <<std::endl;
TFile *infile = TFile::Open(infilenames_[i].c_str());
string outname =(string) TPython::Eval(Form("'%s'.split(\"/\")[-1].replace(\"VH\",\"WH_VH\")",infilenames_[i].c_str()));
TFile *outfile = TFile::Open(outname.c_str(),"RECREATE") ;
TDirectory* saveDir = outfile->mkdir("tagsDumper");
saveDir->cd();
RooWorkspace *inWS = (RooWorkspace*) infile->Get("tagsDumper/cms_hgg_13TeV");
RooRealVar *intLumi = (RooRealVar*)inWS->var("IntLumi");
RooWorkspace *outWS = new RooWorkspace("cms_hgg_13TeV");
outWS->import(*intLumi);
std::list<RooAbsData*> data = (inWS->allData()) ;
std::cout <<" [INFO] Reading WS dataset contents: "<< std::endl;
for (std::list<RooAbsData*>::const_iterator iterator = data.begin(), end = data.end(); iterator != end; ++iterator ) {
RooDataSet *dataset = dynamic_cast<RooDataSet *>( *iterator );
if (dataset) {
string zhname =(string) TPython::Eval(Form("'%s'.replace(\"wzh\",\"zh\")",dataset->GetName()));
string whname =(string) TPython::Eval(Form("'%s'.replace(\"wzh\",\"wh\")",dataset->GetName()));
RooDataSet *datasetZH = (RooDataSet*) dataset->emptyClone(zhname.c_str(),zhname.c_str());
RooDataSet *datasetWH = (RooDataSet*) dataset->emptyClone(whname.c_str(),whname.c_str());
TRandom3 r;
r.Rndm();
double x[dataset->numEntries()];
r.RndmArray(dataset->numEntries(),x);
for (int j =0; j < dataset->numEntries() ; j++){
if( x[j] < wFrac){
dataset->get(j);
datasetWH->add(*(dataset->get(j)),dataset->weight());
} else{
dataset->get(j);
datasetZH->add(*(dataset->get(j)),dataset->weight());
}
}
float w =datasetWH->sumEntries();
float z =datasetZH->sumEntries();
if(verbose_){
std::cout << "Original dataset " << *dataset <<std::endl;
std::cout << "WH dataset " << *datasetWH <<std::endl;
std::cout << "ZH dataset " << *datasetZH <<std::endl;
std::cout << "********************************************" <<std::endl;
std::cout << "WH fraction (obs) : WH " << w/(w+z) <<", ZH "<< z/(w+z) << std::endl;
std::cout << "WH fraction (exp) : WH " << wFrac <<", ZH "<< zFrac << std::endl;
std::cout << "********************************************" <<std::endl;
std::cout << "" <<std::endl;
std::cout << "" <<std::endl;
std::cout << "" <<std::endl;
std::cout << "********************************************" <<std::endl;
}
outWS->import(*datasetWH);
outWS->import(*datasetZH);
}
RooDataHist *datahist = dynamic_cast<RooDataHist *>( *iterator );
if (datahist) {
string zhname =(string) TPython::Eval(Form("'%s'.replace(\"wzh\",\"zh\")",datahist->GetName()));
string whname =(string) TPython::Eval(Form("'%s'.replace(\"wzh\",\"wh\")",datahist->GetName()));
RooDataHist *datahistZH = (RooDataHist*) datahist->emptyClone(zhname.c_str(),zhname.c_str());
RooDataHist *datahistWH = (RooDataHist*) datahist->emptyClone(whname.c_str(),whname.c_str());
TRandom3 r;
r.Rndm();
double x[datahist->numEntries()];
r.RndmArray(datahist->numEntries(),x);
for (int j =0; j < datahist->numEntries() ; j++){
datahistWH->add(*(datahist->get(j)),datahist->weight()*wFrac);
datahistZH->add(*(datahist->get(j)),datahist->weight()*zFrac);
}
float w =datahistWH->sumEntries();
float z =datahistZH->sumEntries();
if(verbose_){
std::cout << "Original datahist " << *datahist <<std::endl;
std::cout << "WH datahist " << *datahistWH <<std::endl;
//.........这里部分代码省略.........