本文整理汇总了C++中TDirectory::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ TDirectory::Get方法的具体用法?C++ TDirectory::Get怎么用?C++ TDirectory::Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDirectory
的用法示例。
在下文中一共展示了TDirectory::Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompareDxy
void CompareDxy(const TString & file1, const TString & file2)
{
setTDRStyle();
TFile inputFileData(file1, "READ");
TFile inputFileSim(file2, "READ");
TDirectory * dirData = (TDirectory*)inputFileData.Get("demo");
TH1F * histoData = (TH1F*)dirData->Get("standAloneMuons_dxy");
TDirectory * dirSim = (TDirectory*)inputFileSim.Get("demo");
TH1F * histoSim = (TH1F*)dirSim->Get("standAloneMuons_dxy");
double norm = histoData->Integral(1, histoData->FindBin(40.));
if( norm ) histoData->Scale(1/norm);
norm = histoSim->Integral(1, histoSim->FindBin(40.));
if( norm ) histoSim->Scale(1/norm);
histoSim->SetLineColor(kRed);
TCanvas * canvas = new TCanvas();
histoData->Draw();
histoSim->Draw("Same");
canvas->SaveAs("compareDxy.png");
canvas->SaveAs("compareDxy.pdf");
}
示例2: getKS
/*************************************************************************************
* getKS: Searches through the histograms in the plotter output, adds the MC together
* for each field, and compares the MC with the Data histogram using a KS test
* input: the main() arguments array
* output: writes to stdout the (human-readable) KS statistics of pairs of histograms
*
* Structure-wise: this is fine, can be implemented into class easily.
***********************************/
void getKS(const char* argv[]) {
//open the input TFile
TFile *f = new TFile(argv[2]);
f->cd();
//get the filesystem information from the file
TList *alokDirs = (TList*) f->GetListOfKeys();
//loop through the directories in the input file
for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) {
TDirectory *cDir = (TDirectory*) f->Get(alokDirs->At(idir)->GetName());
TList *alokHistos = (TList*) cDir->GetListOfKeys();
// create the MC histogram and start collecting relevant MC histograms
// from the current directory
TList *aloh = new TList;
// loop through keys (histograms) in current directory
for(int ihisto=0; alokHistos->At(ihisto) != alokHistos->Last(); ihisto++) {
if(TString(alokHistos->At(ihisto)->GetName()).Contains("MC8TeV")) {
TH1F *cHisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName());
aloh->Add(cHisto);
}
}
//merge the data histograms into one histogram
TH1F *MCHisto = (TH1F*) (aloh->Last())->Clone(TString(cDir->GetName()) + TString("MCHisto"));
aloh->RemoveLast();
MCHisto->Merge(aloh);
cout<<"-------------------- "<<cDir->GetName()<<" -----------------------"<<endl;
//now create the data histogram and run the KS test
TH1F *DataHisto = (TH1F*) cDir->Get(alokHistos->Last()->GetName());
cout<<" ---> KS Test: "<<cDir->GetName()<<" has probability "<<MCHisto->KolmogorovTest(DataHisto, "D")<<"\n"<<endl;
}
}
示例3: getHisto
// -----------------------------------------------------------------------------
//
TH1* getHisto( std::string nameFile,
std::string nameHist,
std::string Dirname,
int rebin ) {
std::string name = nameFile;
TFile* file = new TFile(name.c_str());
if (file) { std::cout << "Opened file: " << file->GetName() << std::endl; }
else {
std::cout << "Could not find file: " << name << std::endl;
return 0;
}
TDirectory* dir = (TDirectory*)file->Get(Dirname.c_str());
if (dir) { std::cout << "Opened dir: " << dir->GetName() << std::endl; }
else {
std::cout << "Could not find dir: " << Dirname << std::endl;
return 0;
}
int low = 375;
TH1* hist = 0;
if ( false || nameHist.find("HtMultiplicity_HT375") == std::string::npos ) {
hist = (TH1*)dir->Get(nameHist.c_str());
} else {
for ( uint ii = low; ii <= 975; ii+=100 ) {
std::stringstream tmp; tmp << "HtMultiplicity_HT" << ii << nameHist.substr(20);
if ( !hist ) {
dir->cd();
TH1D* temp = (TH1D*)dir->Get( "HtMultiplicity_HT375_aT0" );
//TH1D* temp = (TH1D*)file->Get( tmp.str().c_str() );
if (temp) { hist = (TH1D*)temp->Clone(); }
else { std::cout << "1 Unable to retrieve histo with name " << tmp.str() << std::endl; }
} else {
dir->cd();
TH1D* temp = (TH1D*)dir->Get( tmp.str().c_str() );
if (temp) { hist->Add( (TH1D*)temp ); }
else { std::cout << "2 Unable to retrieve histo with name " << tmp.str() << std::endl; }
}
}
}
if (hist) { std::cout << "Opened histo: " << hist->GetName() << std::endl; }
else {
std::cout << "Could not find histo: " << nameHist << std::endl;
return 0;
}
hist->SetLineWidth(3);
if ( rebin > 0 ) { hist->Rebin(rebin); }
hist->GetXaxis()->SetTitleSize(0.055);
hist->GetYaxis()->SetTitleSize(0.055);
hist->GetXaxis()->SetLabelSize(0.05);
hist->GetYaxis()->SetLabelSize(0.05);
hist->SetStats(kFALSE);
return hist;
}
示例4: CompareCFLADiffCuts
void CompareCFLADiffCuts()
{
TFile newFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/15-NoOppChargeCut/All/CFs.root");
TDirectory *newDir = newFile.GetDirectory("Merged");
vector<TH1D*> newCFs;
newCFs.push_back((TH1D*)newDir->Get("CFLamALam010"));
newCFs.push_back((TH1D*)newDir->Get("CFLamALam1030"));
newCFs.push_back((TH1D*)newDir->Get("CFLamALam3050"));
TFile oldFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/08-NewAvgSepCuts/All/CFs.root");
TDirectory *oldDir = oldFile.GetDirectory("Merged");
vector<TH1D*> oldCFs;
oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam010"));
oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam1030"));
oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam3050"));
TFile *compareFile = new TFile("Compare.root","update");
TDirectory *dir = compareFile->GetDirectory("Delta");
if(!dir) dir = compareFile->mkdir("Delta");
for(UInt_t i = 0; i < newCFs.size(); i++) {
// TH1D *ratio = (TH1D*)newCFs[i]->Clone();
// TString name = ratio->GetName();
// ratio->SetName(name + "Ratio");
// ratio->SetTitle(name + "Ratio");
// ratio->Divide(oldCFs[i]);
// TH1D *barlowRatio = ComputeRogerBarlowRatio(newCFs[i], oldCFs[i]);
// barlowRatio->SetName(name + "BarlowRatio");
// barlowRatio->SetTitle(name + "BarlowRatio");
TString name = newCFs[i]->GetName();
TH1D *barlowDifference = ComputeRogerBarlowDifference(newCFs[i], oldCFs[i]);
barlowDifference->SetName(name + "BarlowDifference");
barlowDifference->SetTitle(name + "BarlowDifference");
dir->cd();
// ratio->Write();
// barlowRatio->Write();
barlowDifference->Write(barlowDifference->GetName(), TObject::kOverwrite);
Chi2TestWithZero(barlowDifference);
FitWithConstant(barlowDifference, compareFile);
// LookAtMean(barlowDifference);
RebinHist(barlowDifference, compareFile);
ManuallyRebin(barlowDifference, compareFile);
}
compareFile->Close();
}
示例5: create_module_info
void create_module_info(TString dir = "/castor/cern.ch/user/r/rougny/vcalH2L_7/GainRun_173484"){
ofstream t;
t.open("module_info.txt");
if(! t.is_open()){
cout << "[create_module_info] Could not open output txt file. Exiting ..." << endl;
exit(1);
}
for(int i=0 ; i<40 ; ++i){
ostringstream f_str("");
f_str << "rfio://" << dir << "/" << i << ".root";
cout << "Opening file : " << f_str.str() << endl;
TFile* f = TFile::Open(f_str.str().c_str() , "READ");
vector<TString> dir_list = makedirlist(f , "Module");
for(int m = 0 ; m < dir_list.size() ; ++m){
TDirectory* dir = f->GetDirectory(dir_list[m]);
int detid = getDetId(((TH1*) dir->Get(((TKey*) dir->GetListOfKeys()->At(0))->GetName()))->GetName());
t << detid << " " << i << " " << dir_list[m].Remove(0,dir_list[m].First('y')+2) << endl;
}
f->Close();
}
t.close();
}
示例6: loadRootFile
void loadRootFile()
{
TFile* pRootFile = new TFile("myfile.root", "READ");
if (pRootFile != NULL) {
TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
if (pTestDir != NULL) {
pTestDir->cd();
MyROOTObject* pMyObj = NULL;
std::string name = "testobj";
pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
if (pMyObj != NULL) {
std::cout << *pMyObj << std::endl;
delete pMyObj;
}
}
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
delete pTestDir;
pRootFile->Close();
delete pRootFile;
}
}
}
示例7: appendRootFile
void appendRootFile()
{
TFile* pRootFile = new TFile("myfile.root", "UPDATE");
if (pRootFile != NULL) {
TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
if (pTestDir != NULL) {
pTestDir->cd();
MyROOTObject* pMyObj = NULL;
std::string name = "testobj";
pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
if (pMyObj != NULL) {
std::cout << *pMyObj << std::endl;
delete pMyObj;
}
name = "newobj";
MyROOTObject* pNewObj = NULL;
pNewObj = new MyROOTObject(42, 5.9e2, name);
if (pNewObj != NULL) {
std::cout << *pMyObj << std::endl;
pNewObj->Write(pNewObj->GetName());
delete pNewObj;
}
}
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
pRootFile->Close();
delete pRootFile;
}
}
}
示例8: merged
void merged() {
std::vector<std::string> files;
files.push_back("QCDJets_Pythia_15.root");
files.push_back("QCDJets_Pythia_30.root");
files.push_back("QCDJets_Pythia_80.root");
files.push_back("QCDJets_Pythia_170.root");
files.push_back("QCDJets_Pythia_300.root");
files.push_back("QCDJets_Pythia_470.root");
files.push_back("QCDJets_Pythia_800.root");
files.push_back("QCDJets_Pythia_1400.root");
for ( int i = 0; i < files.size(); ++i ) {
TFile* f = new TFile(std::string(files[i]).c_str(),"READ");
if ( f ) {
TDirectory* d = (TDirectory*)f->Get("susyTree");
if ( d ) {
TTree* t = (TTree*)d->Get("tree");
if ( t ) {
std::cout << " TFile: " << files[i]
<< " Entries: " << t->GetEntries()
<< std::endl;
} else {
std::cout << " NULL TTree ptr!" << std::endl;
}
} else {
std::cout << " NULL TDirectory ptr!" << std::endl;
}
f->Close();
delete f;
} else {
std::cout << " NULL TFile ptr!" << std::endl;
}
}
}
示例9: macro
void macro()
{
cout << "Example macro for testing the ROOTobject library from CINT"
<< endl;
TFile* pRootFile = new TFile("myfile.root", "READ");
if (pRootFile != NULL) {
TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
if (pTestDir != NULL) {
pTestDir->cd();
MyROOTObject* pMyObj = NULL;
std::string name = "testobj";
pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
if (pMyObj != NULL) {
std::cout << *pMyObj << std::endl;
}
}
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
pRootFile->Close();
delete pRootFile;
}
}
}
示例10: getHisto
TH1F* getHisto(string filename, string directoryname, string histoname) {
TFile *file = new TFile(filename.c_str(),"READ");
if (!file) {
cout << "Could not open file " << filename << endl;
return 0;
}
TDirectory *dir = (TDirectory*)file->FindObjectAny(directoryname.c_str());
if (!dir) {
cout << "Could not find directory " << directoryname << endl;
delete file;
return 0;
}
TH1F *hist = (TH1F*)dir->Get(histoname.c_str());
if (!hist) {
cout << "Could not find histogram " << histoname << " in directory " << directoryname << endl;
delete dir;
delete file;
return 0;
}
hist->SetDirectory(0);
delete dir;
delete file;
return hist;
}
示例11: getTreeFromFile
//------------------------------------------------------------------------------
// getTreeFromFile
//------------------------------------------------------------------------------
TTree* getTreeFromFile(const char* infname, Bool_t loadFromDir = kTRUE)
{
bool verbose = false;
if (verbose) {
cout << "--- Open file " << infname << endl;
}
TFile* inf = new TFile(infname,"read");
assert(inf);
TTree* t = 0;
if (loadFromDir) {
TDirectory *dir = (TDirectory*)inf->FindObjectAny("ElectronValidationMod");
assert(dir);
t = (TTree*)dir->Get("ElectronIDOptimizationTree");
assert(t);
} else {
t = (TTree*)inf->Get("ElectronIDOptimizationTree");
}
if (verbose) {
cout << "---\tRecovered tree " << t->GetName()
<< " with "<< t->GetEntries() << " entries" << endl;
}
return t;
}
示例12: getTreeFromFile
//------------------------------------------------------------------------------
// getTreeFromFile
//------------------------------------------------------------------------------
TTree* getTreeFromFile(const char* infname, const char* tname)
{
bool verbose = false;
if (verbose) {
cout << "--- Open file " << infname << endl;
}
TFile* inf = new TFile(infname,"read");
assert(inf);
TTree* t = (TTree*)inf->Get(tname);
if (!t) {
TDirectory *dir = (TDirectory*)inf->FindObjectAny("eleIDdir");
if (!dir) {
cout << "Cannot get Directory HwwNtuplerMod from file " << infname << endl;
assert(dir);
}
t = (TTree*)dir->Get(tname);
}
if (!t) {
cout << "Cannot get Tree with name " << tname << " from file " << infname << endl;
}
assert(t);
if (verbose) {
cout << "---\tRecovered tree " << t->GetName()
<< " with "<< t->GetEntries() << " entries" << endl;
}
return t;
}
示例13: getHisto
TH1* getHisto(char * filename, char* histoName, char * dirName, int nBin, double lumi)
{
TH1 * hpt_=0;
TFile *file0 = TFile::Open(filename);
if(!file0) return hpt_;
TDirectory *dir;
TH2D * hMuPt;
if(dirName == "0") {
hMuPt = (TH2D*) file0->Get(histoName);
} else {
dir = (TDirectory*) file0->Get(dirName);
if(!dir) return hpt_;
hMuPt = (TH2D*) dir->Get(histoName);
}
if(hMuPt) {
hpt_ = (TH1*) hMuPt->Clone();
hpt_->Sumw2();
hpt_->Scale(1./lumi); // this take into into account the luminosity
hpt_->SetLineWidth(2);
hpt_->Rebin(nBin);
double nBinX=hpt_->GetNbinsX();
// overFlow
hpt_->SetBinContent((int)nBinX,hpt_->GetBinContent((int)nBinX)+hpt_->GetBinContent((int)nBinX+1));
hpt_->SetDirectory(0);
file0->Close();
hpt_->SetLineWidth(3);
}
return hpt_;
}
示例14:
TObject * getHistogram2(TFile * f, string algo,string histoName, string range = "GLOBAL")
{
string prefix = "JetTag";
string d = prefix+"_"+algo+"_"+range;
TDirectory * dir =(TDirectory *) f->Get(d.c_str());
return dir->Get((histoName+"_"+algo+"_"+range).c_str());
}
示例15: getNEvents
Double_t getNEvents(string filename) {
//Get Number of Events in the Sample
TFile *file = new TFile(filename.c_str(),"READ");
if (!file) {
cout << "Could not open file " << filename << endl;
return 0;
}
TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod");
if (!dir) {
cout << "Could not find directory AnaFwkMod"
<< " in file " << filename << endl;
delete file;
return 0;
}
TH1F *hist = (TH1F*)dir->Get("hDAllEvents");
if (!hist) {
cout << "Could not find histogram hDEvents in directory AnaFwkMod"
<< " in file " << filename << endl;
delete dir;
delete file;
return 0;
}
return hist->Integral();
}