本文整理汇总了C++中TFile::GetObject方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::GetObject方法的具体用法?C++ TFile::GetObject怎么用?C++ TFile::GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::GetObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: count_entries
void count_entries(const char* listname="list.txt", const char* treename="analyze/Analysis") {
TFile *f;
TTree *tree;
Int_t count=0;
Int_t filecount=0;
ifstream list;
list.open(listname);
char filename[300];
while (true) {
list >> filename;
if (!list.good()) break;
cout << filename << endl;
TString base("dcap://t3se01.psi.ch:22125/");
base.Append(filename);
f=TFile::Open(base.Data(),"read");
filecount++;
f->GetObject(treename,tree);
count+=tree->GetEntries();
f->Close();
}
list.close();
cout << "Total entries: " << count << " from " << filecount << " files" << endl;
}
示例2: GetGraph
TGraph2DErrors* GetGraph(std::string fname)
{
TGraph2DErrors* gr = 0;
std::string fGrName = "mygraph";
TFile *f = new TFile(fname.data());
if (!f->IsOpen())
{
std::cerr << "Failed to open " << fname << std::endl;
return gr;
}
f->ls();
std::cout << "Enter name of graph : ";
if (std::cin.peek()=='\n') std::cin.get();
std::getline(std::cin, fGrName);
f->GetObject(fGrName.data(), gr);
if (gr!=NULL)
{
TGraph2DErrors* tgr = (TGraph2DErrors*) gr->Clone("mygraph_0");
gr=tgr;
gr->SetDirectory(0);
}
return gr;
}
示例3: testSimpleFile
int testSimpleFile(const char *filename, Long64_t entries, Int_t compSetting, Long64_t fileSize, UInt_t tolerance = 0)
{
fprintf(stdout,"Checking %s\n",filename);
TFile *file = TFile::Open(filename);
if (file == nullptr || file->IsZombie()) {
Error("testSimpleFile", "Could not open %s.",filename);
return 1;
}
//file->ls();
if (file->GetCompressionSettings() != compSetting) {
Error("testSimpleFile","Compression level of %s should have been %d but is %d\n",file->GetName(), 206, file->GetCompressionSettings() );
return 3;
}
if (abs(file->GetSize()-fileSize) > tolerance) {
Error("testSimpleFile","Disk size of %s should have been %lld but is %lld (tolerance %u bytes)\n",file->GetName(), fileSize, file->GetSize(), tolerance);
return 4;
}
TTree *ntuple;
file->GetObject("ntuple",ntuple);
if (ntuple == 0) {
Error("testSimpleFile", "Could not retrieve ntuple from %s.",file->GetName());
return 2;
}
if (ntuple->GetEntries() != entries) {
Error("testSimpleFile","Number of entries in ntuple in %s should have been %lld but is %lld\n",file->GetName(), entries, ntuple->GetEntries());
return 4;
}
delete file;
return 0;
}
示例4: ViewData
void ViewData() {
TFile *file = new TFile("result.root", "READ");
TTree *tree;
file->GetObject("run", tree);
Double_t qtotal;
tree->SetBranchAddress("Q_total", &qtotal);
for (Int_t i = 0; i < tree->GetEntries(); i++) {
tree->GetEntry(i);
cout << "Q_total = " << qtotal << endl;
}
/*
vector<double> arrivalTimes;
tree->SetBranchAddress("ArrivalTime", &arrivalTimes);
cout << "Arrival Times from Measurement.root" << endl;
for (unsigned int i = 0; i < 10; i++) {
cout << "arrival time number " << i << ": " << arrivalTimes.at(i) << endl;
}
*/
//TCanvas *c1 = new TCanvas("c1", "Test", 800, 600);
//c1->cd();
}
示例5: Yield
float Yield(Int_t ip_chan, Int_t ip_level){
TH1F* hist;
TFile* inputfile = TFile::Open(path + sampleName);
inputfile->GetObject("H_Yields_" + chan[ip_chan],hist);
float yield = hist->GetBinContent(ip_level+1);
delete inputfile;
return yield*lumi;
}
示例6: addDQMFiles_MC
int addDQMFiles_MC(){
TH2F* Charge_Vs_Index=0;
TH2F* together=0;
int i=0;
int run;
TFile *f;
TString strFile;
ifstream inputFile("runlistMC.txt");
while(inputFile>>run){
cout<<"run = "<<run<<endl;
strFile.Form("MC2012/%i/DQM_V0001_R000000001__Express__PCLTest__ALCAPROMPT.root",run);
cout<<"Open "<<strFile<<endl;
f = TFile::Open(strFile);
if(!f){
cout<<"continue"<<endl;
continue;
}
TString strHisto;
strHisto = "DQMData/Run 1/AlCaReco/Run summary/SiStripGains/Charge_Vs_Index;1";
cout<<"Get "<<strHisto<<endl;
if(i==0){
f->GetObject(strHisto,together);
together->SetDirectory(0);
if(!together){
cout<<"No histogram available"<<endl;
continue;
}
}
else{
f->GetObject(strHisto,Charge_Vs_Index);
together->Add(Charge_Vs_Index,1);
}
delete f;
i++;
}
TFile fSave("DQM_MC.root","recreate");
together->Write();
fSave.Close();
return 0;
}
示例7: printSizes
int printSizes()
{
TFile *f = TFile::Open("hsimple.root");
if (!f) return 1;
TTree *t; f->GetObject("ntuple",t);
if (!t) return 1;
printTreeSummary(t);
return 0;
}
示例8: GetWeight
float GetWeight(TString chan, TString lev, Int_t index){
// index from 1 to 249
TH1F* hist;
TFile* inputfile = TFile::Open(path + sampleName);
inputfile->GetObject("H_LHEweights"+ chan + "_" + lev,hist);
float weight = hist->GetBinContent(index)*lumi;
inputfile -> Close();
delete inputfile;
return weight/GetWeightSum(index)*fac;
}
示例9: MECompare
void MECompare( TString currentfile = "new.root",
TString referencefile = "ref.root",
TString theDir = "DQMData/Run 1/Generator/Run summary/MBUEandQCD" )
{
std::vector<TString> theList = histoList(currentfile, theDir);
gROOT ->Reset();
const char* rfilename = referencefile.Data();
const char* sfilename = currentfile.Data();
delete gROOT->GetListOfFiles()->FindObject(rfilename);
delete gROOT->GetListOfFiles()->FindObject(sfilename);
TFile * rfile = new TFile(rfilename);
TFile * sfile = new TFile(sfilename);
const char* baseDir=theDir.Data();
rfile->cd(baseDir);
gDirectory->ls();
sfile->cd(baseDir);
gDirectory->ls();
for ( unsigned int index = 0; index < theList.size() ; index++ ) {
std::cout << index << std::endl;
TString theName = theDir+"/"+theList[index];
std::cout << theName << std::endl;
TH1* href_;
rfile->GetObject(theName,href_);
TH1* hnew_;
sfile->GetObject(theName,hnew_);
MEComparePlot(href_, hnew_, currentfile, referencefile, theDir, theList[index]);
}
}
示例10: nu_spect
void nu_spect(const std::string& filename) {
TFile* file = new TFile(filename.c_str(), "read");
TTree* tree = NULL;
file->GetObject("MARLEY_event_tree", tree);
if (!tree) {
std::cout << "MARLEY event tree not found" << '\n';
return;
}
marley::Event* ev = new marley::Event;
tree->SetBranchAddress("event", &ev);
size_t num_events = tree->GetEntries();
std::vector<double> E_vec;
for (size_t i = 0; i < num_events; ++i) {
tree->GetEntry(i);
E_vec.push_back(ev->projectile().total_energy());
if (i % 1000 == 0) std::cout << "Event " << i << '\n';
}
double E_max = -1e30;
double E_min = 1e30;
for (size_t k = 0; k < E_vec.size(); ++k) {
double e = E_vec.at(k);
if (e > E_max) E_max = e;
else if (e < E_min) E_min = e;
}
TString title_str;
TH1D* Es = new TH1D("nu_Es", "reacting neutrino spectrum", 100,
E_max, E_min);
for (size_t j = 0; j < E_vec.size(); ++j) {
Es->Fill(E_vec.at(j));
}
TCanvas* c = new TCanvas;
c->cd();
gStyle->SetOptStat();
Es->SetStats(true);
Es->SetLineColor(kBlue);
Es->SetLineWidth(2);
Es->Draw();
//c->SaveAs("nu_Es.pdf");
}
示例11: rootFileName
DrawPlot::DrawPlot(const unsigned int iterationNumber, const bool summaryFile):
outpath_(nullptr), file_(nullptr), fileZeroApe_(nullptr), designFile_(nullptr), baselineTreeX_(nullptr), baselineTreeY_(nullptr), delta0_(nullptr),
legendEntry_("data (final APE)"), legendEntryZeroApe_("data (APE=0)"), designLegendEntry_("MCideal"),
legendXmin_(0.41), legendYmin_(0.27), legendXmax_(0.71), legendYmax_(0.42),
thesisMode_(false)
{
std::stringstream ss_inpath, ss_inpathZeroApe;
ss_inpath<<"$CMSSW_BASE/src/Alignment/APEEstimation/hists/workingArea/iter";
ss_inpathZeroApe<<ss_inpath.str()<<"0/";
ss_inpath<<iterationNumber<<"/";
const TString* inpath = new TString(ss_inpath.str().c_str());
const TString* inpathZeroApe = new TString(ss_inpathZeroApe.str().c_str());
outpath_ = new TString(inpath->Copy().Append("plots/"));
const TString rootFileName(summaryFile ? "allData_resultsFile.root" : "allData.root");
const TString* fileName = new TString(inpath->Copy().Append(rootFileName));
const TString* fileNameZeroApe = new TString(inpathZeroApe->Copy().Append(rootFileName));
const TString* designFileName = new TString("$CMSSW_BASE/src/Alignment/APEEstimation/hists/Design/baseline/" + rootFileName);
const TString* baselineFileName = new TString("$CMSSW_BASE/src/Alignment/APEEstimation/hists/Design/baseline/allData_baselineApe.root");
std::cout<<"\n";
std::cout<<"Outpath: "<<*outpath_<<"\n";
std::cout<<"File name (final APE): "<<*fileName<<"\n";
std::cout<<"File name (zero APE): "<<*fileNameZeroApe<<"\n";
std::cout<<"Design file name: "<<*designFileName<<"\n";
std::cout<<"Baseline file name: "<<*baselineFileName<<"\n";
std::cout<<"\n";
if(iterationNumber!=0)file_ = new TFile(*fileName, "READ");
fileZeroApe_ = new TFile(*fileNameZeroApe, "READ");
designFile_ = new TFile(*designFileName, "READ");
TFile* baselineFile = new TFile(*baselineFileName, "READ");
//if(!file_ || !fileZeroApe_ || !designFile_ || !baselineFile){
// Not needed: root gives error by default when file is not found
//std::cout<<"\n\tInput file not found, please check file name: "<<*fileName<<"\n";
//}
if(baselineFile){
baselineFile->GetObject("iterTreeX", baselineTreeX_);
baselineFile->GetObject("iterTreeY", baselineTreeY_);
}
if(!baselineTreeX_)std::cout<<"Baseline tree for x coordinate not found, cannot draw baselines!\n";
if(!baselineTreeY_)std::cout<<"Baseline tree for y coordinate not found, cannot draw baselines!\n";
baseLineTreeX_->SetDirectory(nullptr);
baselineTreeY_->SetDirectory(nullptr);
delete inpath;
delete fileName;
delete fileNameZeroApe;
delete designFileName;
delete baselineFileName;
}
示例12: stat
float stat(TString mass){
TString samplename = "TTbar_Powheg";
if (mass == "1725") samplename += ".root";
else samplename += "_mtop" + mass + ".root";
TFile *f = TFile::Open(path + samplename);
TH1F* h;
f->GetObject("H_Yields_ElMu", h);
float y = h->GetBinError(5);
delete f;
return y*Lumi;
}
示例13: runreadvararypolyp
void runreadvararypolyp()
{
C* c = 0;
TFile* f = new TFile(testfilename);
f->GetObject("C", c);
c->print();
c->clear();
TTree* t = 0;
f->GetObject("t", t);
t->SetBranchAddress("br1.", &c);
t->GetEntry(1);
cout << endl;
c->print();
delete t;
t = 0;
f->Close();
delete f;
f = 0;
delete c;
c = 0;
}
示例14: makeGraphData
int makeGraphData(){
TGraphErrors* histoJet, *histoPhoton;
TCanvas* canvas[13];
TFile *file;
TString fileName;
for(int i=4; i<13; i++){
fileName.Form("c%i",i);
canvas[i] = new TCanvas(fileName,fileName,0,0,500,500);
canvas[i] ->cd();
fileName.Form("root_files_JetHemisphere/jet_energy_resolution_for_1_eta_bin_%i_pTGamma_bin_PFCHS_mc.root",i);
file = TFile::Open(fileName);
file->GetObject("Graph",histoJet);
histoJet -> SetMarkerColor(2);
histoJet -> SetLineColor(2);
histoJet -> GetFunction("fResolutionAlpha")->SetLineColor(2);
histoJet ->Draw("AP");
delete file;
fileName.Form("root_files/jet_energy_resolution_for_1_eta_bin_%i_pTGamma_bin_PFCHS_mc.root",i);
file = TFile::Open(fileName);
file->GetObject("Graph",histoPhoton);
histoPhoton -> SetMarkerColor(3);
histoPhoton -> SetLineColor(3);
histoPhoton -> GetFunction("fResolutionAlpha")->SetLineColor(3);
histoPhoton ->Draw("Psame");
delete file;
}
return 0;
}
示例15: GetTree
void eurica_treeinfo::GetTree(TString infile, TTree *tree)
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
if (tree == 0) {
TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(infile);
if (!f || !f->IsOpen()) {
f = new TFile(infile);
}
f->GetObject("tree",tree);
}
Init(tree);
}