本文整理汇总了C++中TFile::GetListOfKeys方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::GetListOfKeys方法的具体用法?C++ TFile::GetListOfKeys怎么用?C++ TFile::GetListOfKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::GetListOfKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void
dumpToPDF(string inName, string fitName){
TFile *fin = TFile::Open(inName.c_str(), "read"); assert(fin);
string outName = inName;
outName.replace(outName.find(".root"), 5, ".pdf");
//fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root";
TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit);
TCanvas c1;
c1.Print(Form("%s[", outName.c_str()), "pdf"); //Open .pdf
//get list of keys
int nplots = fin->GetNkeys();
int nfits = fFit->GetNkeys();
printf("nplots: %i, nfits: %i\n", nplots, nfits);
if(nplots != nfits){
cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl;
abort();
}
TList* plots = fin->GetListOfKeys();
TList* fits = fFit->GetListOfKeys();
for(int i=0; i<nplots; ++i){
TKey* plot = (TKey*) plots->At(i);
TKey* fit = (TKey*) fits->At(i);//assume they're in the same order for now
if(!fin->GetKey(plot->GetName())){
cout<<"Didn't find "<<plot<<". Removing."<<endl;
abort();
}
if(!fFit->GetKey(fit->GetName())){
cout<<"Didn't find "<<fit<<". Removing."<<endl;
abort();
}
TCanvas* c = new TCanvas();
c->Divide(1,2);
TCanvas* cPlot = (TCanvas*) fin->Get(plot->GetName());
c->cd(1);
cPlot->DrawClonePad();
TCanvas* cFit = (TCanvas*) fFit->Get(fit->GetName());
c->cd(2);
cFit->DrawClonePad();
string bookmarkName = "Title: ";
bookmarkName += plot->GetName();
c->Print(outName.c_str(), bookmarkName.c_str());
}
c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .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: initialize
void initialize( const char* countdbfn = "counts.root" )
{
XSWeightTool::update( "Xsection8TeV_bkg_v4.txt" );
XSWeightTool::update( "Xsection8TeV_sig_v4.txt" );
// XSWeightTool::print();
using namespace std;
TFile* f = TFile::Open( countdbfn, "read" );
if( f == NULL || f->IsZombie() )
{
return;
}
TIter next( f->GetListOfKeys() );
TKey *key;
int nhist = 0;
while( (key = (TKey*)next()) ) {
nhist++;
// cout << "Key " << nhist << endl;
// cout << " Classname " << key->GetClassName() << endl;
// cout << " Title " <<key->GetTitle() << endl;
if( key->ReadObj()->InheritsFrom( TH1::Class() ) )
{
TH1* h = (TH1*)( key->ReadObj() );
long run_num = TString( h->GetName() ).Atoi();
num_events[run_num] = h->GetBinContent( 1 );
// cout << " Run, # of events : " << run_num << ", " << h->GetBinContent( 21 ) << endl;
}
}
// cout << "Done" << endl;
}
示例4: Drawgrid
void Drawgrid(){
if (!TClass::GetDict("NBD")) {
gROOT->ProcessLine(".L /afs/cern.ch/user/q/qixu/CMSSW_6_2_5/src/Centrality/NBD_Glauber_fit/NBD/NBDclass.C+");
}
int sth=0;
int Gth=0;
TFile *fs = TFile::Open(Form("G%d%d.root",sth,Gth),"Read");
tl = fs->GetListOfKeys();
key = ((TKey*) tl->At(0));
NBD *n0 = (NBD*)key->ReadObj();
cout<<n0->mubest<<"\t"<<n0->kbest<<endl;
cout<<n0->chis<<"\t"<<n0->Ndf<<endl;
TGraph2D *gr2;
TCanvas *c1 = new TCanvas();
// c1->SetLogz();
gr2 = n0->gr2;
int N = gr2->GetN();
double *z = gr2->GetZ();
double *x = gr2->GetX();
double *y = gr2->GetY();
for(int i=0;i<N;i++){
z[i]=-z[i];
y[i]=-y[i];
}
gr2 = new TGraph2D(N,x,y,z);
gr2->Draw("surf1");
}
示例5: main
int main(int argc, char **argv){
if (argc<2) {
cout<<"usage: inpector <filename> "<<endl;
return 0;
}
vector<mTree> m_trees;
string fn = argv[1];
TFile *f = TFile::Open(fn.c_str());
TIter nextkey( f->GetListOfKeys() );
TKey *key;
while ( (key = (TKey*)nextkey())) {
TObject *obj = key->ReadObj();
if ( obj->IsA()->InheritsFrom( "TTree" ) ) {
TTree *tree = (TTree*)f->Get(obj->GetName());
int exist=0;
for(vector<mTree>::iterator i=m_trees.begin();i!=m_trees.end();i++)
if (obj->GetName()==(*i).name) exist=1;
if (!exist) m_trees.push_back(mTree(tree));
}
}
cout<<m_trees.size()<<endl;
for (vector<mTree>::iterator it = m_trees.begin();it != m_trees.end(); it++)
it->print();
f->Close();
return 0;
}
示例6: histoName
pair<Double_t, Double_t> getnLLIn(TString fname, int nJets, TString hyptype) {
TFile *f = TFile::Open(fname.Data(), "READ");
vector<TH1F*> vhistos;
TList *l_keys = f->GetListOfKeys();
for(int i = 0; i< l_keys->GetSize(); i++) {
TString histoName(l_keys->At(i)->GetName());
if(histoName.Contains(Form("hnJetinZwindow_%s", hyptype.Data()) ) )
vhistos.push_back((TH1F*)f->Get(histoName.Data()));
}
Double_t nllIn = 0.;
Double_t nllInErr2 = 0.;
for(unsigned int j = 0; j < vhistos.size(); j++) {
if(nJets <= 1) {
nllIn += vhistos.at(j)->GetBinContent(nJets+1);
nllInErr2 += getError2(vhistos.at(j), nJets+1, nJets+1);
} else {
Int_t binHigh = vhistos.at(j)->GetNbinsX() + 1;
for(Int_t i = 3; i <= binHigh; i++)
nllIn += vhistos.at(j)->GetBinContent(i);
nllInErr2 += getError2(vhistos.at(j), 3, binHigh);
}
}
return make_pair(nllIn, nllInErr2 );
f->Close();
vhistos.clear();
}
示例7: validateInput
void validateInput(const char* filename, int level=0)
{
TFile* file = new TFile(filename, "update");
TIter nextDirectory(file->GetListOfKeys());
TKey* idir;
while((idir = (TKey*)nextDirectory())){
file->cd();
if( idir->IsFolder() ){
if( level>-1 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
file->cd(idir->GetName());
validateFolder(file, idir->GetName(), level);
}
else{
if( level> 0 ){ std::cout << "Found histogram: " << idir->GetName() << std::endl; }
if( level>-1 ){
TH1F* h = (TH1F*)file->Get(idir->GetName());
if(h->Integral() == 0){
std::cout << "----- E R R O R ----- : histogram has 0 integral please fix this: --> " << idir->GetName() << std::endl;
}
}
}
}
file->Close();
return;
}
示例8: efficiencies
void efficiencies( TString fin = "TMVA.root", Int_t type = 2, Bool_t useTMVAStyle = kTRUE )
{
// argument: type = 1 --> plot efficiency(B) versus eff(S)
// type = 2 --> plot rejection (B) versus efficiency (S)
// set style and remove existing canvas'
TMVAGlob::Initialize( useTMVAStyle );
// checks if file with name "fin" is already open, and if not opens one
TFile* file = TMVAGlob::OpenFile( fin );
// check if multi-cut MVA or only one set of MVAs
Bool_t multiMVA=kFALSE;
TIter nextDir(file->GetListOfKeys());
TKey *key;
// loop over all directories and check if
// one contains the key word 'multicutMVA'
while ((key = (TKey*)nextDir())) {
TClass *cl = gROOT->GetClass(key->GetClassName());
if (!cl->InheritsFrom("TDirectory")) continue;
TDirectory *d = (TDirectory*)key->ReadObj();
TString path(d->GetPath());
if (path.Contains("multicutMVA")){
multiMVA=kTRUE;
plot_efficiencies( file, type, d );
}
}
plot_efficiencies( file, type, gDirectory );
return;
}
示例9: FillHistograms
void FillHistograms(TString SAMPLE)
{
cout<<"Processing sample "<<SAMPLE<<endl;
//TString PATH("root://eoscms//eos/cms/store/cmst3/user/kkousour/ttH/flat/");
TString PATH("/afs/cern.ch/work/k/kkousour/private/CMSSW_7_4_12/src/KKousour/TopAnalysis/prod/ttH/");
TFile *inf = TFile::Open(PATH+"flatTree_"+SAMPLE+".root");
TFile *outf = TFile::Open(TString::Format("Histo_%s.root",SAMPLE.Data()),"RECREATE");
TIter nextKey(inf->GetListOfKeys());
TKey *key;
while ((key = (TKey*)nextKey())) {
TString dirName(key->GetName());
cout<<"Found directory "<<dirName<<endl;
TH1F *hPass = (TH1F*)inf->Get(dirName+"/TriggerPass");
outf->mkdir(dirName);
TDirectory *dir = (TDirectory*)outf->Get(dirName);
TTree *tr = (TTree*)inf->Get(dirName+"/events");
TreeClass myTree(tr);
dir->cd();
hPass->Write("TriggerPass");
myTree.Loop(dir);
cout<<"Loop finished"<<endl;
dir->Close();
delete tr;
}
outf->Close();
inf->Close();
}
示例10: stripTrees
int stripTrees(char* filename = "all.root") {
char outfilename[100];
std::string filenameString(filename);
std::cout << filenameString.size() << std::endl;
std::string filenameStripped = filenameString.substr(filenameString.size()-5, filenameString.size());
// filenameStripped.erase(filenameStripped
sprintf(outfilename, "%s_histograms.root", filenameString.c_str());
std::vector<TTree*> trees;
std::vector<TH1F*> th1fs;
std::vector<TH2F*> th2fs;
std::vector<TProfile*> tprofiles;
TFile* f = new TFile(filename);
// Create an iterator on the list of keys
TIter nextTopLevelKey = NULL;
nextTopLevelKey=(f->GetListOfKeys());
TKey *keyTopLevel;
while (keyTopLevel = (TKey*)nextTopLevelKey()) {
TString name(keyTopLevel->GetName());
TString className(keyTopLevel->GetClassName());
if ((className.CompareTo("TTree") != 0) ||
((name.CompareTo("plotvariables") == 0) || (name.CompareTo("inputfiles") == 0))) {
std::cout << "Adding " << keyTopLevel->GetName() << std::endl;
if (className.CompareTo("TTree") == 0)
trees.push_back((TTree*) f->Get(name));
else if (className.CompareTo("TH1F") == 0)
th1fs.push_back((TH1F*) f->Get(name));
else if (className.CompareTo("TH2F") == 0)
th2fs.push_back((TH2F*) f->Get(name));
else if (className.CompareTo("TProfile") == 0)
tprofiles.push_back((TProfile*) f->Get(name));
}
}
TFile* out = new TFile(outfilename, "recreate");
out->cd();
for (unsigned int i=0; i<trees.size(); i++)
trees[i]->Write();
for (unsigned int i=0; i<th1fs.size(); i++)
th1fs[i]->Write();
for (unsigned int i=0; i<th2fs.size(); i++)
th2fs[i]->Write();
for (unsigned int i=0; i<tprofiles.size(); i++)
tprofiles[i]->Write();
out->Close();
return 0;
}
示例11: next
TTree *getTree(const std::string &arg)
{
std::string::size_type pos = arg.find('@');
std::string fileName;
if (pos == std::string::npos)
fileName = arg;
else
fileName = arg.substr(pos + 1);
TFile *file = TFile::Open(fileName.c_str());
if (!file) {
std::cerr << "ROOT file \"" << fileName << "\" could not be "
"opened for reading." << std::endl;
return 0;
}
TTree *tree = 0;
if (pos == std::string::npos) {
TIter next(file->GetListOfKeys());
TObject *obj;
TString treeName;
while((obj = next())) {
TString name = static_cast<TKey*>(obj)->GetName();
TTree *cur = dynamic_cast<TTree*>(file->Get(name));
if (!cur || name == treeName)
continue;
if (tree) {
std::cerr << "ROOT file \"" << fileName
<< "\" contains more than one tree. "
"Please use <tree>@<file> syntax."
<< std::endl;
return 0;
}
tree = cur;
treeName = name;
}
} else {
TString name(arg.substr(0, pos).c_str());
tree = dynamic_cast<TTree*>(file->Get(name));
if (!tree) {
std::cerr << "ROOT file \"" << fileName << "\" does "
"not contain a tree named \"" << name
<< "\"." << std::endl;
return 0;
}
}
return tree;
}
示例12: parseOptions
int
main (int argc, char *argv[])
{
map<string, string> opt;
vector<string> argVector;
parseOptions (argc, argv, opt, argVector);
if (argVector.size () != 1 || opt.count ("help"))
{
printHelp (argv[0]);
return 0;
}
TFile *fin;
if (!(fin = TFile::Open (argVector.at (0).c_str (), "update")))
{
cout << "Failed to open " << argVector.at (0) << "!" << endl;
return 0;
}
TIter next0 (fin->GetListOfKeys ());
TObject *obj0;
TH1D *cutFlow = 0;
TDirectoryFile *dir = 0;
while ((obj0 = next0 ()))
{
string obj0Class = ((TKey *) obj0)->GetClassName (),
obj0Name = obj0->GetName ();
if (obj0Class == "TDirectoryFile")
{
dir = (TDirectoryFile *) fin->Get (obj0Name.c_str ());
TIter next1 (dir->GetListOfKeys ());
TObject *obj1;
while ((obj1 = next1 ()))
{
string obj1Class = ((TKey *) obj1)->GetClassName (),
obj1Name = obj1->GetName ();
if (obj1Class == "TH1D" && obj1Name.length () >= 7 && ((obj1Name.substr (obj1Name.length () - 7, 7) == "CutFlow" || obj1Name.substr (obj1Name.length () - 7, 7) == "cutFlow")
|| (obj1Name.length () >= 9 && (obj1Name.substr (obj1Name.length () - 9, 9) == "Selection" || obj1Name.substr (obj1Name.length () - 9, 9) == "selection"))
|| (obj1Name.length () >= 8 && (obj1Name.substr (obj1Name.length () - 8, 8) == "MinusOne" || obj1Name.substr (obj1Name.length () - 8, 8) == "minusOne")))
&& !dir->Get ((obj1Name + "LowerLimit").c_str ()) && !dir->Get ((obj1Name + "UpperLimit").c_str ()))
{
cutFlow = (TH1D *) dir->Get (obj1Name.c_str ());
cutFlow->SetDirectory (0);
getLimits (cutFlow, dir);
}
}
}
}
fin->Close ();
return 0;
}
示例13: iter
map<string, TH1F *> histoToMap (string file, string type)
{
map<string, TH1F *> histoMap;
TKey *key = 0;
TFile * myFile = new TFile(file.c_str());
TIter iter (myFile->GetListOfKeys());
while((key = (TKey*) iter()))
{
histoMap[key->GetName()] = (TH1F*)key->ReadObj();
}
// myFile->Close();
return histoMap;
}
示例14: Compare
Int_t Compare(TDirectory* from) {
TFile * reffile = new TFile("dt_reference.root");
TIter next(reffile->GetListOfKeys());
TH1 *ref, *draw;
const char* name;
Int_t comp;
Int_t fail = 0;
TKey* key;
while ((key=(TKey*)next())) {
if (strcmp(key->GetClassName(),"TH1F")
&& strcmp(key->GetClassName(),"TH2F") )
continue; //may be a TList of TStreamerInfo
ref = (TH1*)reffile->Get(key->GetName());
name = ref->GetName();
if (strncmp(name,"ref",3)) continue;
name += 3;
draw = (TH1*)from->Get(name);
if (!draw) {
if (!gSkipped.FindObject(name)) {
cerr << "Miss: " << name << endl;
fail++;
}
continue;
}
comp = HistCompare(ref,draw);
if (comp!=0) {
cerr << "Fail: " << name << ":" << comp << endl;
fail++;
if (gInteractiveTest) {
TCanvas * canv = new TCanvas();
canv->Divide(2,1);
canv->cd(1);
TString reftitle = "Ref: ";
reftitle.Append(ref->GetTitle());
ref->SetTitle(reftitle);
ref->Draw();
canv->cd(2); draw->Draw();
return 1;
}
} else {
if (gQuietLevel<1) cerr << "Succ: " << name << ":" << comp << endl;
}
}
delete reffile;
return fail;
}
示例15: mode1
//================================================
void mode1()
{
TString filename = "Rootfiles/Run14_AuAu200.StudyLumiDep.root";
TFile *fin = TFile::Open(filename.Data());
TFile *fout = TFile::Open(Form("%s_filter.root",filename.Data()),"recreate");
TKey *key;
TIter nextkey(fin->GetListOfKeys());
while ((key = (TKey*)nextkey()))
{
TObject *obj = key->ReadObj();
if ( obj->IsA()->InheritsFrom( "TH2" ) ) continue;
obj->Write();
}
fout->Close();
fin->Close();
}