本文整理汇总了C++中TDirectory::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ TDirectory::GetName方法的具体用法?C++ TDirectory::GetName怎么用?C++ TDirectory::GetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDirectory
的用法示例。
在下文中一共展示了TDirectory::GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: GetListOfJobs
UInt_t GetListOfJobs( TFile* file, TList& jobdirs)
{
// get a list of all jobs in all method directories
// based on ideas by Peter and Joerg found in macro deviations.C
TIter next(file->GetListOfKeys());
TKey *key(0);
while ((key = (TKey*)next())) {
if (TString(key->GetName()).BeginsWith("Method_")) {
if (gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) {
TDirectory* mDir = (TDirectory*)key->ReadObj();
TIter keyIt(mDir->GetListOfKeys());
TKey *jobkey;
while ((jobkey = (TKey*)keyIt())) {
if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom("TDirectory")) continue;
TDirectory *jobDir = (TDirectory *)jobkey->ReadObj();
cout << "jobdir name " << jobDir->GetName() << endl;
jobdirs.Add(jobDir);
}
}
}
}
return jobdirs.GetSize();
}
示例3: network
// input: - Input file (result from TMVA),
// - use of TMVA plotting TStyle
void network( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE )
{
// 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 );
Network_GFile = file;
TKey* mkey = TMVAGlob::FindMethod("MLP");
if (mkey==0) {
cout << "Could not locate directory MLP in file " << fin << endl;
return;
}
TDirectory *dir = (TDirectory *)mkey->ReadObj();
dir->cd();
TList titles;
UInt_t ni = TMVAGlob::GetListOfTitles( dir, titles );
if (ni==0) {
cout << "No titles found for Method_MLP" << endl;
return;
}
TIter nextTitle(&titles);
TKey *titkey;
TDirectory *titDir;
while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) {
titDir = (TDirectory *)titkey->ReadObj();
cout << "Drawing title: " << titDir->GetName() << endl;
draw_network(titDir);
}
}
示例4: 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;
}
示例5: make
void make(TDirectory & out, TObject * o) {
TDirectory * dir;
TH1F * th1f;
TH1D * th1d;
TH2F * th2f;
TH2D * th2d;
out.cd();
if((dir = dynamic_cast<TDirectory*>(o)) != 0) {
TDirectory * outDir = out.mkdir(dir->GetName(), dir->GetTitle());
TIter next(dir->GetListOfKeys());
TKey *key;
while( (key = dynamic_cast<TKey*>(next())) ) {
string className(key->GetClassName());
string name(key->GetName());
TObject * obj = dir->Get(name.c_str());
if(obj == 0) {
cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl;
exit(-1);
}
make(*outDir, obj);
}
} else if((th1f = dynamic_cast<TH1F*>(o)) != 0) {
TH1F *h = (TH1F*) th1f->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
} else if((th1d = dynamic_cast<TH1D*>(o)) != 0) {
TH1D *h = (TH1D*) th1d->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
} else if((th2f = dynamic_cast<TH2F*>(o)) != 0) {
TH2F *h = (TH2F*) th2f->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
} else if((th2d = dynamic_cast<TH2D*>(o)) != 0) {
TH2D *h = (TH2D*) th2d->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
}
}
示例6: fill
void fill(TDirectory & out, TObject * o, double w) {
TDirectory * dir;
TH1F * th1f;
TH1D * th1d;
TH2F * th2f;
TH2D * th2d;
if((dir = dynamic_cast<TDirectory*>(o)) != 0) {
const char * name = dir->GetName();
TDirectory * outDir = dynamic_cast<TDirectory*>(out.Get(name));
if(outDir == 0) {
cerr << "can't find directory " << name << " in output file" << endl;
exit(-1);
}
TIter next(dir->GetListOfKeys());
TKey *key;
while( (key = dynamic_cast<TKey*>(next())) ) {
string className(key->GetClassName());
string name(key->GetName());
TObject * obj = dir->Get(name.c_str());
if(obj == 0) {
cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl;
exit(-1);
}
fill(*outDir, obj, w);
}
} else if((th1f = dynamic_cast<TH1F*>(o)) != 0) {
const char * name = th1f->GetName();
TH1F * outTh1f = dynamic_cast<TH1F*>(out.Get(name));
if(outTh1f == 0) {
cerr <<"error: histogram TH1F" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh1f->Add(th1f, w);
} else if((th1d = dynamic_cast<TH1D*>(o)) != 0) {
const char * name = th1d->GetName();
TH1D * outTh1d = dynamic_cast<TH1D*>(out.Get(name));
if(outTh1d == 0) {
cerr <<"error: histogram TH1D" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh1d->Add(th1d, w);
} else if((th2f = dynamic_cast<TH2F*>(o)) != 0) {
const char * name = th2f->GetName();
TH2F * outTh2f = dynamic_cast<TH2F*>(out.Get(name));
if(outTh2f == 0) {
cerr <<"error: histogram TH2F" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh2f->Add(th2f, w);
} else if((th2d = dynamic_cast<TH2D*>(o)) != 0) {
const char * name = th2d->GetName();
TH2D * outTh2d = dynamic_cast<TH2D*>(out.Get(name));
if(outTh2d == 0) {
cerr <<"error: histogram TH2D" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh2d->Add(th2d, w);
}
}
示例7: addDir
// helper function to add and weight all plots in the subsamples
void addDir(const std::string& path, const std::vector< std::pair< TFile*, double > >& files, TFile *target, int verbose)
{
// loop all objects in the file
std::vector< std::pair< TFile*, double > >::const_iterator first=files.begin();
first->first->cd(path.c_str());
TIter nextkey(gDirectory->GetListOfKeys());
TKey *key=0;
while ( (key = (TKey*)nextkey())) {
// read object from first source file
first->first->cd(path.c_str());
TObject *obj = key->ReadObj();
if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
// if descendant of TH1 -> mergeit
TH1 *h1 = (TH1*)obj;
h1->Sumw2();
h1->Scale(first->second);
// loop over all source files and add the content of the
// corresponding histogram to the one pointed to by "h1"
for(std::vector< std::pair< TFile*, double > >::const_iterator file=first+1; file!=files.end(); ++file) {
// make sure we are at the correct directory level by cd'ing to path
file->first->cd(path.c_str());
TH1 *h2 = (TH1*)gDirectory->Get( h1->GetName() );
if ( h2 ) {
h2->Sumw2();
h1->Add(h2,file->second);
delete h2; // don't know if this is necessary, i.e. if
// h2 is created by the call to gDirectory above.
}
}
}
else if (obj->IsA()->InheritsFrom( "TDirectory" ) ) {
// for a subdirectory
if(verbose>1) std::cout << "Found subdirectory " << obj->GetName() << std::endl;
// create a new subdir of same name and title in the target file
target->cd();
TDirectory *newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
// newdir is now the starting point of another round of merging
// newdir still knows its depth within the target file via
// GetPath(), so we can still figure out where we are in the recursion
addDir(newdir->GetName(),files,target, verbose);
}
if ( obj ) {
target->cd(path.c_str());
obj->Write( key->GetName() );
}
delete obj;
}
target->Write();
delete key;
}
示例8: copyDir
//Clone the file excluding the histogram (code stolen from Rene Brun)
void copyDir(TDirectory *source,std::string iSkipHist,bool iFirst=true) {
//copy all objects and subdirs of directory source as a subdir of the current directory
TDirectory *savdir = gDirectory;
TDirectory *adir = savdir;
if(!iFirst) adir = savdir->mkdir(source->GetName());
if(!iFirst) adir->cd();
//loop on all entries of this directory
TKey *key;
TIter nextkey(source->GetListOfKeys());
while ((key = (TKey*)nextkey())) {
const char *classname = key->GetClassName();
TClass *cl = gROOT->GetClass(classname);
if (!cl) continue;
if (cl->InheritsFrom(TDirectory::Class())) {
source->cd(key->GetName());
TDirectory *subdir = gDirectory;
adir->cd();
copyDir(subdir,iSkipHist,false);
adir->cd();
} else {
source->cd();
TObject *obj = key->ReadObj();
std::string pFullName = std::string(adir->GetName())+"/"+std::string(obj->GetName());
std::string iSkipHist2 = iSkipHist;
std::string fine_binning = "_fine_binning";
iSkipHist2.replace(iSkipHist2.find(fine_binning), fine_binning.length(),"");
if(pFullName.find(iSkipHist) != std::string::npos || pFullName.find(iSkipHist2) != std::string::npos) {
continue;
}
adir->cd();
obj->Write();
delete obj;
}
}
adir->SaveSelf(kTRUE);
savdir->cd();
}
示例9: DoComparison
void DoComparison(TString newFileName, TString oldFileName, vector<TString> newHistName, vector<TString> oldHistName)
{
TFile newF(newFileName,"read");
TDirectory *newDir = newF.GetDirectory("Merged");
TFile old(oldFileName);
TFile output("Comparison.root","update");
assert(newHistName.size() == oldHistName.size());
vector<TH1D*> newHists;
vector<TH1D*> oldHists;
for(UInt_t i = 0; i < newHistName.size(); i++) {
TH1D *newH = (TH1D*)newDir->Get(newHistName[i]);
if(!newH) {
cout<<"Could not find "<<newHistName[i]<< " in "<<newDir->GetName()<<endl;
return;
}
TH1D *oldH = (TH1D*)old.Get(oldHistName[i]);
if(!oldH) {
cout<<"Could not find "<<oldHistName[i]<< " in "<<old.GetName()<<endl;
return;
}
newHists.push_back(newH);
oldHists.push_back(oldH);
}
for(UInt_t i = 0; i < newHists.size(); i++) {
// Make ratio
TH1D *ratio = (TH1D*)newHists[i]->Clone();
ratio->Divide(oldHists[i]);
ratio->SetDirectory(0);
TString newName = newHists[i]->GetName();
newName += "Ratio";
ratio->SetName(newName);
ratio->SetTitle(newName);
ratio->SetMarkerStyle(20);
output.cd();
ratio->Write(newName, TObject::kOverwrite);
cout<<"Wrote "<<newName<<" to "<< output.GetName()<<endl;
// Make difference
TH1D *difference = (TH1D*)newHists[i]->Clone();
difference->Add(oldHists[i],-1.);
difference->SetDirectory(0);
newName = newHists[i]->GetName();
newName += "Difference";
difference->SetName(newName);
difference->SetTitle(newName);
difference->SetMarkerStyle(20);
output.cd();
difference->Write(newName, TObject::kOverwrite);
cout<<"Wrote "<<newName<<" to "<< output.GetName()<<endl;
// Make side by side plot
TString canName = "Canvas";
canName += newHists[i]->GetName();
canName += "Comparison";
TCanvas *can = new TCanvas(canName, canName);
newHists[i]->SetLineColor(kBlack);
newHists[i]->SetMarkerStyle(20);
newHists[i]->SetMarkerColor(kBlack);
oldHists[i]->SetLineColor(kRed);
oldHists[i]->SetMarkerStyle(20);
oldHists[i]->SetMarkerColor(kRed);
oldHists[i]->Draw();
newHists[i]->Draw("same");
can->Write(canName, TObject::kOverwrite);
delete can; can = NULL;
}
}
示例10: plotauto
void plotauto(TString infilename) {
TString plname = infilename+".ps";
TCanvas* cc = new TCanvas("validate","validate",500,370);
cc->Print(plname+"[");
TText tt;
tt.SetTextColor(2);
tt.SetTextSize(0.02);
gStyle->SetMarkerSize(0.1);
gStyle->SetTitleSize(0.15,"ff");
gStyle->SetTitleTextColor(4);
std::vector < TString > vnames;
vnames.push_back("Sim_HitEn");
vnames.push_back("Sim_HitTime");
vnames.push_back("Sim_posXY");
vnames.push_back("Sim_posXZ");
vnames.push_back("Sim_posYZ");
vnames.push_back("Sim_posRZ");
std::vector <TString> exts;
exts.push_back("");
exts.push_back("_posZ");
exts.push_back("_negZ");
TH1F* h;
TH2F* hh;
TKey *key;
TIter next;
TKey *key2;
TIter next2;
TFile* infile = new TFile(infilename, "read");
// overall geometry
TDirectory* td = (TDirectory*) infile->Get("ALLCollections");
cc->Clear();
cc->Divide(3,3);
cc->cd(1);
hh = (TH2F*) td->Get("ALLCollections_overallhitZR");
hh->Draw("box");
cc->cd(2);
int icol=1;
bool first=true;
TLegend* tl = new TLegend(0., 0., 1, 1);
next = td->GetListOfKeys();
while ((key = (TKey*)next())) {
TClass *cll = gROOT->GetClass(key->GetClassName());
if (cll->InheritsFrom("TH2F")) {
hh = (TH2F*)key->ReadObj();
TString hn = hh->GetName();
if ( hn.Contains("ALL") ) continue;
if ( hn.Contains("_Log") ) continue;
hh->SetLineColor(icol);
if ( first ) {hh->Draw("box"); first=false;}
else hh->Draw("same;box");
icol++;
if (icol==10) icol=1;
TString ss = hn.ReplaceAll( "_overallhitZR", "");
tl->AddEntry(hh, ss , "l");
}
}
// the legend
cc->cd(3);
tl->Draw();
cc->cd(4);
hh = (TH2F*) td->Get("ALLCollections_Log_overallhitZR");
hh->Draw("box");
cc->cd(5);
icol=1;
first=true;
next = td->GetListOfKeys();
while ((key = (TKey*)next())) {
TClass *cll = gROOT->GetClass(key->GetClassName());
if (cll->InheritsFrom("TH2F")) {
hh = (TH2F*)key->ReadObj();
TString hn = hh->GetName();
if ( hn.Contains("ALL" ) ) continue;
if ( ! hn.Contains("_Log_") ) continue;
hh->SetLineColor(icol);
if ( first ) {hh->Draw("box"); first=false;}
else hh->Draw("same;box");
icol++;
if (icol==10) icol=1;
}
}
cc->cd(7);
hh = (TH2F*) td->Get("ALLCollections_LogLog_overallhitZR");
hh->Draw("box");
cc->cd(8);
icol=1;
first=true;
next = td->GetListOfKeys();
while ((key = (TKey*)next())) {
TClass *cll = gROOT->GetClass(key->GetClassName());
if (cll->InheritsFrom("TH2F")) {
//.........这里部分代码省略.........
示例11: trigger
void trigger() {
gStyle->SetOptStat(1111111);
std::vector<std::string> trig;
trig.push_back("HLT_HT150_v2");
trig.push_back("HLT_HT150_AlphaT0p60_v1");
std::vector<std::string> his;
his.push_back("ge2");
his.push_back("eq2");
his.push_back("eq3");
his.push_back("ge4");
TFile* f = new TFile(std::string("../Trigger_HT_Run2011A_PromptReco_v1.root").c_str(),"READ");
if ( f && !f->IsZombie() ) {
std::cout << "Opened file: " << f->GetName() << std::endl;
} else {
std::cout << "Could not find file " << std::endl;
//return;
}
TDirectory* d = (f==0?0:(TDirectory*)f->Get("Triggers"));
if (d) { std::cout << "Opened dir: " << d->GetName() << std::endl; }
else {
std::cout << "Could not find dir " << std::endl;
//return;
}
TCanvas* c1 = new TCanvas(std::string("trigger").c_str(),
std::string("trigger").c_str(),
600,600);
c1->Divide(1,2);
TLegend* legend = new TLegend( 0.7, 0.6, 0.85, 0.7, NULL, "brNDC" );
std::vector<TH1D*> h(trig.size(),0);
std::vector<TH1D*> i(trig.size(),0);
for ( int ii = 0; ii < trig.size(); ++ii ) {
std::string str;
str = trig[ii]+"_all";
// if ( his[jj] == "eq2" ) { str = trig[ii]+"_2"; }
// else if ( his[jj] == "eq3" ) { str = trig[ii]+"_3"; }
// else if ( his[jj] == "ge4" ) { str = trig[ii]+"_4"; }
// else { str = trig[ii]+"_all"; }
h[ii] = (d==0?0:(TH1D*)d->Get(str.c_str()));
if (h[ii]) { std::cout << "Opened histo: " << h[ii]->GetName() << std::endl; }
else {
std::cout << "Could not find histo " << std::endl;
//continue;
}
i[ii] = (h[ii]==0?0:(TH1D*)h[ii]->Clone());
if (i[ii]) calcIntegral(i[ii],true);
legend->AddEntry( h[ii], trig[ii].c_str(), "pl" );
}
// TGraphAsymmErrors* gr1 = new TGraphAsymmErrors();
// if ( h[0] && h[1] ) gr1->BayesDivide(h[0],h[1]);
// TGraphAsymmErrors* gr2 = new TGraphAsymmErrors();
// if ( i[0] && i[1] ) gr2->BayesDivide(i[0],i[1]);
c1->cd(1);
if ( h[0] && h[1] ) {
h[0]->GetXaxis()->SetTitle("#alpha_{T}");
h[0]->SetLineColor(kRed);
h[0]->SetFillColor(kRed-10);
h[0]->GetXaxis()->SetRangeUser(0.,1.);
h[0]->Draw("");
h[1]->GetXaxis()->SetTitle("#alpha_{T}");
h[1]->GetXaxis()->SetRangeUser(0.,1.);
h[1]->Draw("sameP");
legend->SetTextSize(0.035);
//legend->SetFillColor(0);
//legend->SetLineColor(0);
//legend->SetShadowColor(0);
legend->Draw("same");
}
c1->cd(2);
if ( i[0] && i[1] ) {
i[0]->GetXaxis()->SetTitle("#alpha_{T} > cut value");
i[0]->GetXaxis()->SetRangeUser(0.,1.);
i[0]->SetLineColor(kRed);
i[0]->SetFillColor(kRed-10);
i[0]->Draw("LF2");
i[1]->GetXaxis()->SetTitle("#alpha_{T} > cut value");
i[1]->GetXaxis()->SetRangeUser(0.,1.);
i[1]->Draw("sameP");
legend->SetTextSize(0.035);
legend->SetFillColor(0);
//.........这里部分代码省略.........
示例12: recurseFile
void recurseFile(TDirectory *indir, TDirectory *outdir,
double etawid, double etamid) {
TDirectory *curdir = gDirectory;
// Automatically go through the list of keys (directories)
TList *keys = indir->GetListOfKeys();
TListIter itkey(keys);
TObject *key, *obj;
TDirectory *dir;
while ( (key = itkey.Next()) ) {
if (_debug) cout << key->GetName() << endl << flush;
obj = ((TKey*)key)->ReadObj(); assert(obj);
dir = indir;
// Found a subdirectory: copy it to output and go deeper
if (obj->InheritsFrom("TDirectory")) {
//assert(outdir->mkdir(obj->GetName()));
outdir->mkdir(obj->GetName());
assert(outdir->cd(obj->GetName()));
TDirectory *outdir2 = outdir->GetDirectory(obj->GetName()); assert(outdir2);
outdir2->cd();
assert(indir->cd(obj->GetName()));
TDirectory *indir2 = indir->GetDirectory(obj->GetName());
indir2->cd();
// Check if directory name contains information on eta bin width
float etamin, etamax;
if ( (sscanf(indir->GetName(),"Eta_%f-%f",&etamin,&etamax)==2)
&& (etamax>etamin) ) {
etawid = 2.*(etamax-etamin);
etamid = 0.5*(etamax+etamin);
//cout << "Eta bin width: " << etawid << flush << endl;
}
recurseFile(indir2, outdir2, etawid, etamid);
//outdir2->Write(); // does this speedup or slow down?
} // inherits from TDirectory
// Found a plot: normalize if hpt, then copy to output
if (obj->InheritsFrom("TH1")) {
outdir->cd();
TObject *obj2 = obj->Clone(obj->GetName());
// Normalize hpt and hselpt histograms
// Same for hbpt
if (string(obj2->GetName())=="hpt" ||
string(obj2->GetName())=="hpt_evt" ||
string(obj2->GetName())=="hpt_jet" ||
string(obj2->GetName())=="hpt_pre" ||
string(obj2->GetName())=="hpt0" ||
string(obj2->GetName())=="hpt1" ||
string(obj2->GetName())=="hpt2" ||
string(obj2->GetName())=="hpt3" ||
string(obj2->GetName())=="hpt_jk1" ||
string(obj2->GetName())=="hpt_jk2" ||
string(obj2->GetName())=="hpt_jk3" ||
string(obj2->GetName())=="hpt_jk4" ||
string(obj2->GetName())=="hpt_jk5" ||
string(obj2->GetName())=="hpt_jk6" ||
string(obj2->GetName())=="hpt_jk7" ||
string(obj2->GetName())=="hpt_jk8" ||
string(obj2->GetName())=="hpt_jk9" ||
string(obj2->GetName())=="hpt_jk10" ||
string(obj2->GetName())=="hpt_l1off" ||
string(obj2->GetName())=="hpt_l1fast" ||
string(obj2->GetName())=="hpt_plus" ||
string(obj2->GetName())=="hpt_minus" ||
string(obj2->GetName())=="hpt0_plus" ||
string(obj2->GetName())=="hpt0_minus" ||
string(obj2->GetName())=="hpt_noid" ||
string(obj2->GetName())=="hpt_noevtid" ||
string(obj2->GetName())=="hpt_nojetid" ||
string(obj2->GetName())=="hpt_ak5calo" ||
string(obj2->GetName())=="hpt_ak5pf" ||
string(obj2->GetName())=="hpt_evt_ak5pf" ||
string(obj2->GetName())=="hpt_jet_ak5pf" ||
string(obj2->GetName())=="hselpt" ||
string(obj2->GetName())=="hpt_r" ||
string(obj2->GetName())=="hpt_g" ||
string(obj2->GetName())=="hpt_gg" ||
string(obj2->GetName())=="hpt_g0" ||
string(obj2->GetName())=="hpt_g0tw" ||
string(obj2->GetName())=="hdjmass" ||
string(obj2->GetName())=="hdjmass0" ||
string(obj2->GetName())=="hdjmass0_hgg") {
cout << "." << flush;
TH1D *hpt = (TH1D*)obj2;
bool isgen = TString(obj2->GetName()).Contains("pt_g");
bool isoth = (TString(obj2->GetName()).Contains("pt_no") ||
TString(obj2->GetName()).Contains("djmass") ||
TString(obj2->GetName()).Contains("hpt0") ||
TString(obj2->GetName()).Contains("l1off") ||
//.........这里部分代码省略.........
示例13: deviations
// input: - Input file (result from TMVA)
// - use of TMVA plotting TStyle
void deviations( TString fin = "TMVAReg.root",
HistType htype = MVAType, Bool_t showTarget, Bool_t useTMVAStyle = kTRUE )
{
// set style and remove existing canvas'
TMVAGlob::Initialize( useTMVAStyle );
gStyle->SetNumberContours(999);
// switches
const Bool_t Save_Images = kTRUE;
// checks if file with name "fin" is already open, and if not opens one
TFile* file = TMVAGlob::OpenFile( fin );
// define Canvas layout here!
Int_t xPad = 1; // no of plots in x
Int_t yPad = 1; // no of plots in y
Int_t noPad = xPad * yPad ;
const Int_t width = 650; // size of canvas
// this defines how many canvases we need
TCanvas* c[100];
// counter variables
Int_t countCanvas = 0;
// search for the right histograms in full list of keys
// TList* methods = new TMap();
TIter next(file->GetListOfKeys());
TKey *key(0);
while ((key = (TKey*)next())) {
if (!TString(key->GetName()).BeginsWith("Method_")) continue;
if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue;
TString methodName;
TMVAGlob::GetMethodName(methodName,key);
cout << "--- Plotting deviation for method: " << methodName << endl;
TObjString *mN = new TObjString( methodName );
TDirectory* mDir = (TDirectory*)key->ReadObj();
TList* jobNames = new TList();
TIter keyIt(mDir->GetListOfKeys());
TKey *titkey;
while ((titkey = (TKey*)keyIt())) {
if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;
TDirectory *titDir = (TDirectory *)titkey->ReadObj();
TObjString *jN = new TObjString( titDir->GetName() );
if (!jobNames->Contains( jN )) jobNames->Add( jN );
else delete jN;
TString methodTitle;
TMVAGlob::GetMethodTitle(methodTitle,titDir);
TString hname = "MVA_" + methodTitle;
TIter dirKeyIt( titDir->GetListOfKeys() );
TKey* dirKey;
Int_t countPlots = 0;
while ((dirKey = (TKey*)dirKeyIt())){
if (dirKey->ReadObj()->InheritsFrom("TH2F")) {
TString s(dirKey->ReadObj()->GetName());
if (s.Contains("_reg_") &&
( (showTarget && s.Contains("_tgt")) || (!showTarget && !s.Contains("_tgt")) ) &&
s.Contains( (htype == CompareType ? "train" : "test" ))) {
c[countCanvas] = new TCanvas( Form("canvas%d", countCanvas+1),
Form( "Regression output deviation versus %s for method: %s",
(showTarget ? "target" : "input variables"), methodName.Data() ),
countCanvas*50+100, (countCanvas+1)*20, width, (Int_t)width*0.72 );
c[countCanvas]->SetRightMargin(0.10); // leave space for border
TH1* h = (TH1*)dirKey->ReadObj();
h->SetTitle( Form("Output deviation for method: %s (%s sample)",
hname.Data(), (htype == CompareType ? "training" : "test" )) );
// methodName.Data(), (htype == CompareType ? "training" : "test" )) );
h->Draw("colz");
TLine* l = new TLine( h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0 );
l->SetLineStyle(2);
l->Draw();
// update and print
cout << "plotting logo" << endl;
TMVAGlob::plot_logo(1.058);
c[countCanvas]->Update();
TString fname = Form( "plots/deviation_%s_%s_%s_c%i",
methodName.Data(),
(showTarget ? "target" : "vars"),
(htype == CompareType ? "training" : "test" ), countPlots );
TMVAGlob::imgconv( c[countCanvas], fname );
countPlots++;
countCanvas++;
}
//.........这里部分代码省略.........
示例14: CombineCFsInDataDir
void CombineCFsInDataDir(TDirectory *f, vector<TString> dataSetNames)
{
TString cfDirName = "CF";
TString countDirName = "Count";
vector<TDirectory*> cfDirs = GetDirectories(f, dataSetNames, cfDirName);
vector<TDirectory*> countDirs = GetDirectories(f, dataSetNames, countDirName);
TDirectory *mergeDir = (TDirectory*)f->GetDirectory("Merged");
if(!mergeDir) {
mergeDir = f->mkdir("Merged");
}
UInt_t nDirs = cfDirs.size();
// Merge each centrality one at a time
// Load the cfs and counts into vectors for that centrality
// Find all the cfs and counts that match the name of the CF
// in the first directory
TIter iter(cfDirs[0]->GetListOfKeys());
TObject *obj = NULL;
while ( (obj = iter()) ) {
TKey *key = dynamic_cast<TKey*>(obj);
TH1D *cf = dynamic_cast<TH1D*>(key->ReadObj());
if(!cf) {
cout<<"Could not find a CF hist"<<endl;
return;
}
//Figure out which CF we are trying to grab
TString cfName = cf->GetName();
TString countName = cfName;
countName.ReplaceAll("CF","Count");
//Grab the corresponding CFs and counts
vector<TH1D*> cfs;
vector<Double_t> counts;
Double_t totalCounts = 0;
for(UInt_t iDir = 0; iDir < nDirs; iDir++) {
TH1D *thisCF = (TH1D*) cfDirs[iDir]->Get(cfName);
if(!thisCF) {
cout<<"Could not find CF matching "<<cfName
<<" in "<<cfDirs[iDir]->GetName()<<endl;
}
// TVectorD *count = dynamic_cast<TVectorD*>(countDirs[iDir]->Get(countName));
TVectorD *count = (TVectorD*)countDirs[iDir]->Get(countName);
// cout<<count->ClassName()<<endl;
Double_t myCount = count[0](0);
cfs.push_back(thisCF);
counts.push_back(myCount);
totalCounts += myCount;
}
// Finally, combine the CFs
TH1D *combinedCF = CombineCFs(cfs, counts);
if (!combinedCF) {
cout << "Combine CF returned nothing. Continuing loop."
<<endl;
continue;
}
TVectorD finalCount(1);
finalCount[0] = totalCounts;
cout<<"Writing combined CF "<<combinedCF->GetName()
<<" to "<<mergeDir->GetName()<<endl;
combinedCF->SetDirectory(0);
mergeDir->cd();
combinedCF->Write(combinedCF->GetName(), TObject::kOverwrite);
finalCount.Write(countName, TObject::kOverwrite);
}
}
示例15: CombineLLAAForDirectory
void CombineLLAAForDirectory(TDirectory *dataDir)
{
// Run after merging centralities
vector<TString> centBins = {"010", "1030", "3050"};
vector<TString> pairTypes = {"LamLam", "ALamALam"};
TString finalPairType = "LLAA";
// Get merge dir
TDirectory *mergeDir = dataDir->GetDirectory("Merged");
if(!mergeDir) {
cout<<"Merge directory does not exist. Cannot merge."<<endl;
return;
}
for(UInt_t iCent = 0; iCent < centBins.size(); iCent++) {
vector<TH1D*> cfs;
vector<Double_t> counts;
Double_t totalCounts = 0;
for(UInt_t iType = 0; iType < pairTypes.size(); iType++) {
TString cfName = "CF" + pairTypes[iType] + centBins[iCent];
TH1D *cf = (TH1D*)mergeDir->Get(cfName);
if(!cf) {
cout<<"Could not find CF named "<<cfName<<" in "<<mergeDir->GetName()<<endl;
return;
}
cfs.push_back(cf);
TString countName = "Count" + pairTypes[iType] + centBins[iCent];
TVectorD *count = (TVectorD*) mergeDir->Get(countName);
totalCounts += count[0](0);
counts.push_back(count[0](0));
}
// Finally, combine the CFs
TH1D *combinedCF = CombineCFs(cfs, counts);
if (!combinedCF) {
cout << "Combine CF returned nothing. Continuing loop."
<<endl;
continue;
}
TVectorD finalCount(1);
finalCount[0] = totalCounts;
// Set names
TString combinedCFName = "CF" + finalPairType + centBins[iCent];
TString combinedCountName = "Count" + finalPairType + centBins[iCent];
combinedCF->SetName(combinedCFName);
combinedCF->SetTitle(combinedCFName);
// Set axis ranges
combinedCF->SetAxisRange(0.9, 1.1, "Y");
combinedCF->SetAxisRange(0., 1., "X");
cout<<"Writing combined CF "<<combinedCF->GetName()
<<" to "<<mergeDir->GetName()<<endl;
combinedCF->SetDirectory(0);
mergeDir->cd();
combinedCF->Write(combinedCF->GetName(), TObject::kOverwrite);
finalCount.Write(combinedCountName, TObject::kOverwrite);
}
}