本文整理汇总了C++中TList::Last方法的典型用法代码示例。如果您正苦于以下问题:C++ TList::Last方法的具体用法?C++ TList::Last怎么用?C++ TList::Last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TList
的用法示例。
在下文中一共展示了TList::Last方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createMFOutfile
/*************************************************************************************
* createMFOutfile: moves the MLB distributions into an output file for use in
* R. Nally's MassFit.C code.
* input: the main() arguments array
* output: writes to an output file the histograms, in a MassFit.C-readable format
*
* Structure-wise: can be implemented into class easily.
***********************************/
void createMFOutfile(const char* argv[]) {
TFile *f = new TFile(argv[2]);
//create the output file we'd like to write histograms to
TFile *output = new TFile(outfileName, "RECREATE");
//get the filesystem information from the file
f->cd();
TList *alokDirs = (TList*) f->GetListOfKeys();
//create a list of "All" histograms and initialize (TODO)
TList *allHists = new TList;
//loop through the directories in the input file
for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) {
//if it's not mlb, we don't care
if(!TString(alokDirs->At(idir)->GetName()).Contains("_Mlb")) continue;
//get the file directory information, its histograms
TDirectory *cDir = (TDirectory*) f->Get(alokDirs->At(idir)->GetName());
TList *alokHistos = (TList*) cDir->GetListOfKeys();
//loop through the histograms in the current directory
for(int ihisto=0; alokHistos->At(ihisto-1) != alokHistos->Last(); ihisto++) {
// don't consider the graph objects
if(TString(alokHistos->At(ihisto)->GetName()).Contains("Graph_")) continue;
// clone the histogram, give it a new name
TString cloneName = formatName(alokHistos->At(ihisto)->GetName(),nominalWidth);
TH1F *thisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName());
TH1F *tclone = (TH1F*) thisto->Clone(cloneName);
// open the outfile and write the histo in
output->cd();
TList *outkeys = (TList*) output->GetListOfKeys();
// if the histogram already exists, add thisto to the existing one
// messy, but removes the need for magic
for(int iout=0; outkeys->At(iout-1) != outkeys->Last(); iout++) {
if(outkeys->At(iout)->GetName() == cloneName) {
cout<<" - found another histogram in output with name "<<cloneName<<endl;
TH1F *theHisto = (TH1F*) output->Get(cloneName);
cout<<" - got the same histogram from the output file"<<endl;
TH1F *tHclone = (TH1F*) theHisto->Clone(cloneName);
cout<<" - cloned the histogram"<<endl;
cout<<" - adding in clone"<<endl;
tclone->Add(tHclone);
cout<<" - deleting the original histogram from the output file"<<endl;
output->Delete(cloneName + TString(";1"));
cout<<" - deleted thing from output file"<<endl;
cout<<" - tclone looks like "<<tclone<<endl;
}
}
cout<<" - writing the tclone to file"<<endl;
tclone->Write();
// reopen the input root file and clean up
f->cd();
delete thisto;
delete tclone;
}
}
f->Close();
output->cd();
output->Close();
// if we want to interpolate, start making more histograms
if(interpolate) {
// Have to reopen the outfile because ROOT is odd
TFile *output2 = new TFile(outfileName, "UPDATE");
output2->cd();
std::pair<double,TString> maxPair = *moreFiles.begin();
double maxWidth = maxPair.first;
// check that it makes sense to interpolate with our settings
if(maxWidth <= nominalWidth) {
cout<<"\n\nERROR: Max width is less than or equal to the nominal width! Exiting."<<endl;
exit(EXIT_FAILURE);
}
// open the input file and loop through the relevant directories
TFile *maxFile = new TFile(maxPair.second);
for(int i=0; i<lepsSize; i++) {
// change directory and get the name of the folder we want to access
maxFile->cd();
char a[128];
sprintf(a, "mlbwa_%s_Mlb", leps[i]);
TDirectory *tDir = (TDirectory*) maxFile->Get(a);
//.........这里部分代码省略.........
示例3: getYields
/*************************************************************************************
* getYields: Goes through each Counts histogram for every process and subprocess
* (i.e., EE & Drell-Yan, E & WJets, etc.) and properly adds the yields
* for data and MC. Reports ratios of Data:MC as well.
* input: the main() arguments array
* output: writes to stdout the LaTeX-formatted table of yields (pipe the output to
* save)
***********************************/
void getYields(const char* argv[]) {
//open mlbwidth output file
TFile *f = new TFile(argv[2]);
f->cd();
//very inefficient, but for now it works
//loop over all procs, leps and figure out the event counts
for(int i=0; i<lepsSize; i++) {
char a[128];
sprintf(a, "mlbwa_%s_Count", leps[i]);
TDirectory *tDir = (TDirectory*) f->Get(a);
TList *alok = tDir->GetListOfKeys();
for(int j=0; j<procsSize; j++) {
for(int k=0; alok->At(k)->GetName() != alok->Last()->GetName(); k++) {
if(TString(alok->At(k)->GetName()).Contains(TRegexp(procs[j]))) {
char b[128];
sprintf(b, "mlbwa_%s_Count/%s", leps[i], alok->At(k)->GetName());
TH1F *h = (TH1F*) f->Get(b);
eCounts[i][j] += h->GetSumOfWeights();
eErrors[i][j] = sqrt(pow(eErrors[i][j],2) + pow(h->GetBinError(2),2));
delete h;
}
}
}
char d[128];
sprintf(d, "mlbwa_%s_Count/%s", leps[i], alok->Last()->GetName());
if(d == "") { exit(EXIT_FAILURE); }
TH1F *tth = (TH1F*) f->Get(d);
eCounts[i][procsSize] = tth->GetEntries();
double integral = tth->GetSumOfWeights();
eErrors[i][procsSize] = tth->GetBinError(2)*eCounts[i][procsSize]/integral;
delete tth;
}
//Get a string to tell us how many columns we want (size leps + 1)
char cols[] = "c";
for(int i=0; i<lepsSize; i++) {
strcat(cols, "c");
}
//print out LaTeX:
//formatting
cout<<"\\documentclass[12pt,a4paper,titlepage]{article}"<<endl;
cout<<"\\usepackage[utf8]{inputenc}"<<endl;
cout<<"\\usepackage{amsmath}"<<endl;
cout<<"\\usepackage{amsfonts}"<<endl;
cout<<"\\usepackage{amssymb}"<<endl;
cout<<"\\usepackage{hyperref}\n\n"<<endl;
cout<<"\\usepackage[margin=0.0025in]{geometry}"<<endl;
cout<<"\\begin{document}"<<endl;
cout<<"\\begin{tabular}{l|"<<cols<<"} \\\\"<<endl;
//Print out the table header
cout<<"Sample & ";
for(int i=0; i<lepsLaTeXSize; i++) {
cout<<lepsLaTeX[i]<<" & ";
}
cout<<"Sum \\\\ \\hline\\hline"<<endl;
//Printing out the yields for each process
for(int i=0; i<procsSize; i++) {
cout<<yieldLaTeX[i]<<" & ";
for(int j=0; j<lepsSize; j++) {
cout<<GetLatex(j,i)<<" & ";
}
cout<<GetLatexSum(true,i)<<"\\\\"<<(i==procsSize-1 ? "\\hline" : "")<<endl;
}
//Print out the total MC yield
cout<<"Total MC & ";
for(int i=0; i<lepsSize; i++) {
cout<<GetLatexSum(false,i)<<" & ";
}
cout<<GetLatexSum(false,-1)<<"\\\\"<<endl;
//Print out the data yield
cout<<"Data & ";
for(int i=0; i<lepsSize; i++) {
cout<<GetLatex(i,lepsSize+1)<<" & ";
}
cout<<GetLatexSum(true,lepsSize+1)<<"\\\\\\hline\\hline"<<endl;
//Print out the data:MC ratio
cout<<"Data/MC & ";
for(int i=1; i<=procsSize;i++) {
cout<<GetLatexRatio(i)<<(i==procsSize ? "" : " & ");
}
//.........这里部分代码省略.........