本文整理汇总了C++中TTree::SaveAs方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::SaveAs方法的具体用法?C++ TTree::SaveAs怎么用?C++ TTree::SaveAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::SaveAs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Save
void LegendreMomentShape::Save(const std::string filename)
{
TTree* outputTree = new TTree("LegendreMomentsTree","");
char branchtitle[20];
double**** c = newcoefficients();
sprintf(branchtitle,"c[%d][%d][%d][%d]/D",l_max,i_max,k_max,j_max);
outputTree->Branch("c",c,branchtitle);
outputTree->Branch("mKK_min",&mKK_min,"mKK_min/D");
outputTree->Branch("mKK_max",&mKK_max,"mKK_max/D");
// Set up the branches
for ( int l = 0; l < l_max; l++ )
for ( int i = 0; i < i_max; i++ )
for ( int k = 0; k < k_max; k++ )
for ( int j = 0; j < j_max; j++ )
{
char branchname[5];
sprintf(branchname,"c%d%d%d%d",l,i,k,j);
outputTree->Branch(branchname,&c[l][i][k][j],((std::string)branchname+"/D").c_str());
}
// Pass the non-zero coefficients
for(auto coeff: coeffs)
c[coeff.l][coeff.i][coeff.k][coeff.j] = coeff.val;
outputTree->Fill();
// Save the tree to a file
outputTree->SaveAs(filename.c_str());
deletecoefficients(c);
}
示例2: makehlt_tree
void makehlt_tree(TString filename, TString outfolder="root/hlt/sep4/"){
TString cuts[] = {"onelpt>15", "onmupt>15"};
TString tags[] = {"el15", "mu15"}, folder, sCut;
TChain tree("tree"); TChain treeglobal("treeglobal");
tree.Add(filename); treeglobal.Add(filename);
vector<int> genlep_thresh, v_nori_genels, v_nori_genmus;
vector<int> *nori_genels = &v_nori_genels, *nori_genmus = &v_nori_genmus;
int noriginal, nori_genmu0, nori_genel0;
treeglobal.SetBranchAddress("noriginal",&noriginal);
treeglobal.GetEntry(0);
genlep_thresh.push_back(0); genlep_thresh.push_back(10);
genlep_thresh.push_back(15); genlep_thresh.push_back(17);
genlep_thresh.push_back(20); genlep_thresh.push_back(25);
for(unsigned ind(0); ind<genlep_thresh.size(); ind++){
sCut = "Max$(genels_pt)>"; sCut += genlep_thresh[ind];
v_nori_genels.push_back(tree.GetEntries(sCut));
sCut = "Max$(genmus_pt)>"; sCut += genlep_thresh[ind];
v_nori_genmus.push_back(tree.GetEntries(sCut));
}
nori_genel0 = v_nori_genels[0]; nori_genmu0 = v_nori_genmus[0];
filename.Remove(0,filename.Last('/')+1);
filename.ReplaceAll(".root","");
for(int cut(0); cut<2; cut++){
folder = outfolder+"/"+tags[cut]+"/";
gSystem->mkdir(folder, kTRUE);
TTree *ctree = tree.CopyTree(cuts[cut]);
folder += filename+"_"+tags[cut]+".root";
ctree->SaveAs(folder);
TFile file(folder,"UPDATE");
file.cd();
TTree ctreeglobal("treeglobal", "treeglobal");
ctreeglobal.Branch("noriginal",&noriginal);
ctreeglobal.Branch("nori_genels",&nori_genels);
ctreeglobal.Branch("nori_genmus",&nori_genmus);
ctreeglobal.Branch("nori_genel0",&nori_genel0);
ctreeglobal.Branch("nori_genmu0",&nori_genmu0);
ctreeglobal.Branch("genlep_thresh", &genlep_thresh);
ctreeglobal.Fill();
ctreeglobal.Write();
file.Close();
}
}
示例3: MakePlots
void MakePlots(TString filename, TString energy="8TeV", TString lumi=""){
TString outDir=filename; outDir.ReplaceAll("fitres","img");
outDir="tmp/";
//std::map<TString, TH2F *> deltaNLL_map;
/*------------------------------ Plotto */
TCanvas *c = new TCanvas("c","c");
TFile f_in(filename, "read");
if(f_in.IsZombie()){
std::cerr << "File opening error: " << filename << std::endl;
return;
}
TList *KeyList = f_in.GetListOfKeys();
std::cout << KeyList->GetEntries() << std::endl;
for(int i =0; i < KeyList->GetEntries(); i++){
c->Clear();
TKey *key = (TKey *)KeyList->At(i);
if(TString(key->GetClassName())!="RooDataSet") continue;
RooDataSet *dataset = (RooDataSet *) key->ReadObj();
TString constTermName = dataset->GetName();
TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha");
TTree *tree = dataset2tree(dataset);
TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName);
TH2F *hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)",true);
// // deltaNLL_map.insert(std::pair <TString, TH2F *>(keyName,hist));
hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root");
hist->Draw("colz");
bestFit_.Draw("P same");
bestFit_.SetMarkerSize(2);
Int_t iBinX, iBinY;
Double_t x,y;
hist->GetBinWithContent2(0,iBinX,iBinY);
x= hist->GetXaxis()->GetBinCenter(iBinX);
y= hist->GetYaxis()->GetBinCenter(iBinY);
TGraph nllBestFit(1,&x,&y);
nllBestFit.SetMarkerStyle(3);
nllBestFit.SetMarkerColor(kRed);
TList* contour68 = contourFromTH2(hist, 0.68);
hist->Draw("colz");
hist->GetZaxis()->SetRangeUser(0,50);
bestFit_.Draw("P same");
nllBestFit.Draw("P same");
//contour68->Draw("same");
c->SaveAs(outDir+"/deltaNLL-"+constTermName+".png");
hist->SaveAs("tmp/hist-"+constTermName+".root");
nllBestFit.SaveAs("tmp/nllBestFit.root");
contour68->SaveAs("tmp/contour68.root");
delete hist;
hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)");
RooHistPdf *histPdf = nllToL(hist);
delete hist;
RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE);
TTree *genTree = dataset2tree(gen_dataset);
genTree->SaveAs("tmp/genTree-"+constTermName+".root");
delete gen_dataset;
delete histPdf;
TGraphErrors toyGraph = g(genTree, constTermName);
TGraphErrors bestFitGraph = g(tree,alphaName, constTermName);
TGraphErrors bestFitScanGraph = g(y, x);
delete genTree;
delete tree;
toyGraph.SetFillColor(kGreen);
toyGraph.SetLineColor(kBlue);
toyGraph.SetLineStyle(2);
bestFitGraph.SetLineColor(kBlack);
bestFitScanGraph.SetLineColor(kRed);
bestFitScanGraph.SetLineWidth(2);
TMultiGraph g_multi("multigraph","");
g_multi.Add(&toyGraph,"L3");
g_multi.Add(&toyGraph,"L");
g_multi.Add(&bestFitGraph, "L");
g_multi.Add(&bestFitScanGraph, "L");
g_multi.Draw("A");
c->Clear();
g_multi.Draw("A");
c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png");
// TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8);
// TLegend *legend = new TLegend(0.7,0.8,0.95,0.92);
// legend->SetFillStyle(3001);
// legend->SetFillColor(1);
// legend->SetTextFont(22); // 132
// legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize()
// // legend->SetFillColor(0); // colore di riempimento bianco
// legend->SetMargin(0.4); // percentuale della larghezza del simbolo
// SetLegendStyle(legend);
//.........这里部分代码省略.........