本文整理汇总了C++中TFile::FindObjectAny方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::FindObjectAny方法的具体用法?C++ TFile::FindObjectAny怎么用?C++ TFile::FindObjectAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::FindObjectAny方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MPSys
//________________________________________________________________________________
Syst* MPSys(TString Sys, TString BaseMC, TString filepart, TString filedirunf, TString histoName, TH1F* CurveBase ) {
//save output directory
TDirectory* current=gDirectory;
TFile* fileM =NULL; fileM = TFile::Open(filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"M.root","READ");
TFile* fileP =NULL; fileP = TFile::Open(filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"P.root","READ");
cout << "FileM: " << filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"M.root" << " ptr: " << fileM << endl;
cout << "FileP: " << filedirunf+"unf_"+BaseMC+filepart+"_SYS"+Sys+"P.root" << " ptr: " << fileP << endl;
//if (fileM==0 || fileP==0) return 0;
if (fileM==0 || fileP==0) cout << "ERROR: NO fileM or NO fileP" <<endl;
TH1F* CurveM = (TH1F*) fileM->FindObjectAny(histoName);
TH1F* CurveP = (TH1F*) fileP->FindObjectAny(histoName);
cout << "CurveM : " << CurveM << " CurveP: " << CurveP << endl;
Syst* Sys_test = new Syst(Sys, CurveBase, CurveM, CurveP);
//recall output directory
current->cd();
Sys_test->write();
fileM->Close(); delete fileM;
fileP->Close(); delete fileP;
delete CurveM; delete CurveP;
return Sys_test;
}
示例2: call_fit_chi2
void call_fit_chi2(std::string filename)
{
TFile *inf = new TFile(filename.data());
std::string remword="_histo.root";
size_t pos = filename.find(remword);
std::string forOutput = filename;
if(pos!= std::string::npos)
forOutput.swap(forOutput.erase(pos,remword.length()));
std::string histo = forOutput + "MixData";
cout << "Finding " << histo << endl;
TH1F *h_data = (TH1F*)inf->FindObjectAny(histo.data());
histo = forOutput + "MixSig";
cout << "Finding " << histo << endl;
TH1F *h_sig = (TH1F*)inf->FindObjectAny(histo.data());
histo = forOutput + "MixBkg";
cout << "Finding " << histo << endl;
TH1F *h_bkg = (TH1F*)inf->FindObjectAny(histo.data());
// TH1F* h_data = (TH1F*)h_sig->Clone();
// h_data->Reset();
// h_data->Sumw2();
// h_data->Add(h_sig,h_bkg,1.0,1.0);
fit_chi2(h_data,h_sig,h_bkg,forOutput);
}
示例3: catalogFile
//--------------------------------------------------------------------------------------------------
void catalogFile(const char *dir, const char *file)
{
TString fileName = TString(dir) + slash + + TString(file);
//printf("Index: %d\n",fileName.Index("castor/cern.ch"));
if (fileName.Index("castor/cern.ch") != -1)
fileName = TString("castor:") + fileName;
if (fileName.Index("pnfs/cmsaf.mit.edu") != -1) {
fileName = dCacheDoor + fileName;
}
if (fileName.Index("mnt/hadoop/cms/store") != -1) {
fileName.Remove(0,15);
fileName = hadoopDoor + fileName;
}
printf("\n Opening: %s\n\n",fileName.Data());
TFile* f = TFile::Open(fileName.Data());
TTree* tree = (TTree*) f->FindObjectAny("Delphes");
if (tree) {
printf("0000 %s %d %d\n",fileName.Data(),tree->GetEntries(),tree->GetEntries());
return;
}
TTree* tree = (TTree*) f->FindObjectAny("Events");
if (tree)
printf("XX-CATALOG-XX %s %d\n",fileName.Data(),tree->GetEntries());
TTree* allTree = (TTree*) f->FindObjectAny("AllEvents");
if (tree && allTree)
printf("XX-CATALOG-XX %s %d %d\n",fileName.Data(),tree->GetEntries(),allTree->GetEntries());
}
示例4: PixelMergeSmallFiles
void PixelMergeSmallFiles(){
TFile * oFilebDist = new TFile("bDistr2.root", "RECREATE");
TNtuple* SimEventsGlobal = new TNtuple("SimEventGlob", "SimEventGlob", "EvN:b");
TFile * oFileLinks = new TFile("Links2.root", "RECREATE");
TNtuple* LinksGlobal = new TNtuple("LinksGlob", "LinksGlob", "EvN:fedid:linkn:nHits");
char FileInNumber[5];
string FileInPath = "/net/pstore01/d00/scratch/icali/CMSSW_2_1_11/PixelAnalysis/PixelNTuple_hydjet_x2_mb_oldPL_d20081106/";
string FileInNameRoot= "hydjet_x2_mb_oldPL_d20081106_r0";
Float_t j = 0;
for(int FileN = 901; FileN <1801; ++FileN){
sprintf(FileInNumber, "%.5d", FileN);
string FileInName = FileInPath+FileInNameRoot+FileInNumber+".root";
TFile *iFile = new TFile((const char*)FileInName.c_str());
if(!iFile->IsZombie()){
PixelAnalyzer->cd();
TNtuple *FEDLinks = (TNtuple*)iFile->FindObjectAny("Links");
TNtuple *SimEvents = (TNtuple*)iFile->FindObjectAny("SimEvent");
Float_t FEDEvN, fedid, linkn, nHits;
FEDLinks->SetBranchAddress("EventN",&FEDEvN);
FEDLinks->SetBranchAddress("fedid",&fedid);
FEDLinks->SetBranchAddress("linkn",&linkn);
FEDLinks->SetBranchAddress("nHits",&nHits);
Long64_t FEDLinkLenght =FEDLinks->GetEntries();
Float_t SimEvN, b;
SimEvents->SetBranchAddress("EventN",&SimEvN);
SimEvents->SetBranchAddress("mult",&b);
Long64_t SimEventLenght =SimEvents->GetEntries();
Long64_t i;
for(i=0; i < SimEventLenght; ++i){
SimEvents->GetEntry(i);
SimEventsGlobal->Fill(i, b);
}
Float_t OldEvN= -1;
for(i=0; i < FEDLinkLenght; ++i){
FEDLinks->GetEntry(i);
if(OldEvN != FEDEvN){
OldEvN= FEDEvN;
++j;
}
LinksGlobal->Fill(j, fedid, linkn, nHits);
}
}
}
oFilebDist->Write();
oFileLinks->Write();
}
示例5: load
TTree * load(std::string iName) {
TFile *lFile = new TFile(iName.c_str());
lFile->cd();
TTree *lTree = (TTree*) lFile->FindObjectAny("Tree");
if(lTree == 0) lTree = (TTree*) lFile->FindObjectAny("Flat");
if(lTree == 0) lTree = (TTree*) lFile->FindObjectAny("TestTree");
if(lTree == 0) lTree = (TTree*) lFile->FindObjectAny("TauCheck");
return lTree;
}
示例6: OpenDataThisFile
//_______________________________________
int OpenDataThisFile(TString fname ) {
int success = 0 ;
// open the ROOT file to process
TString path ="./data1/moukaddam/SpiceTestSep2014/Calibration/Files/";
TString inFileName = fname+".root";
TFile *inFile = new TFile(path + inFileName);
if ( !inFile->IsOpen() ) { //try present directory
cout << "File doesn't exist in the directory : " << path << endl ;
cout << "Trying the present working directory : ./" << endl ;
path ="./";
inFile = new TFile(path + inFileName);
}
if ( inFile->IsOpen() ) {
success = 1 ;
cout << "Opening the root file and grabing the histograms from " << inFile->GetName() << endl ;
inFile->ls();
}
else {
cout << "File is not found.. EXIT!"<< endl;
exit(-1);
}
gFolderHistos = (TFolder*)(inFile->FindObjectAny("histos"));
return success ;
}
示例7: a
std::map<string, double> getMean(char target[6], char list[20], char part[5],
char ene[6], char ctyp0[10]="Multi",
char dir[12]="histo") {
std::vector<std::string> types = typesOld();
std::map<string, double> means;
char ofile[100];
sprintf (ofile, "%s/histo_%s%s_%s_%sGeV.root", dir, target, list, part, ene);
std::cout << "Input File: " << ofile << "\n";
TFile *fout = TFile::Open(ofile);
fout->cd();
TH1I *hi[20];
char name[160], title[160], ctype[20];
for (unsigned int ii=0; ii<=(types.size()); ii++) {
if (ii == 0) sprintf (ctype, "All Particles");
else sprintf (ctype, "%s", types[ii-1].c_str());
sprintf (name, "%s%s%s%sGeV(%s)", ctyp0, target, list, ene, ctype);
hi[ii] = (TH1I*)fout->FindObjectAny(name);
// std::cout << "Histo " << ii << " Name " << name << " " << hi[ii] << " " << hi[ii]->GetMean() << "\n";
string a(ctype);
means[a] = hi[ii]->GetMean();
}
// printMeans(means);
return means;
}
示例8: 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;
}
示例9: Run
void Run( const char *inFileName, const char *outFileName,
const char *dirname, const char *treeName) {
char name[500];
sprintf(name, "%s.root",inFileName);
TFile *infile = TFile::Open(name);
TDirectory *dir = (TDirectory*)infile->FindObjectAny(dirname);
TTree *tree = (TTree*)dir->FindObjectAny(treeName);
std::cout << tree << " tree with nentries (tracks): " << tree->GetEntries() << std::endl;
CalibTree t(tree);
sprintf(name, "%s_%s_%s.root", outFileName, inFileName, dirname);
std::string outFile(name);
t.BookHisto(outFile);
double cvgs[100], itrs[100];
unsigned int k(0);
for (; k<20; ++k) {
double cvg = t.Loop(k);
itrs[k] = k;
cvgs[k] = cvg;
// if (cvg < 0.00001) break;
}
TGraph *g_cvg;
g_cvg = new TGraph(k, itrs, cvgs);
t.fout->WriteTObject(g_cvg, "g_cvg");
std::cout << "Finish looping after " << k << " iterations" << std::endl;
}
示例10: spectrum
void spectrum(char *filename = "example.root")
{
TFile *infile = new TFile(filename);
TTree *data = (TTree*) infile->FindObjectAny("data");
TH1F *h[10];
TCanvas *c = new TCanvas("c","",960,480);
TPad *p = new TPad("p","",0,0,1,1);
p->Divide(4,2,0.01,0.01);
p->Draw();
double norm;
for (int i=0;i<8;i++)
{
p->cd(i+1);
p->GetPad(i+1)->SetLogy();
h[i] = new TH1F(Form("h%d",i),Form("Ch %d",i),60,-0.1,1.1);
// data->Draw(Form("-min[%d]>>h%d",i,i),"min[0]<min[1]&&min[0]<min[2]&&min[0]<min[3]&&min[0]<min[4]&&min[0]<min[5]&&min[0]<min[6]&&min[0]<min[7]");
data->Draw(Form("-min[%d]/256./0.86>>h%d",i,i));
if (i==0) norm = h[i]->GetEntries();
h[i]->SetTitle(Form("Ch %d",i));
h[i]->SetXTitle("Pulse height (Volt)");
h[i]->SetYTitle("#");
h[i]->SetMarkerSize(0.5);
h[i]->SetMarkerColor(2);
h[i]->Sumw2();
h[i]->Scale(1./norm);
h[i]->SetAxisRange(1e-7,10,"Y");
h[i]->Draw("e");
}
}
示例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: Z_Pt
// get the distribution for the Z pt
TH1F* Z_Pt()
{
TFile *inclusive = new TFile( "/afs/cern.ch/work/b/bbachu/private/Z_nunu/boosted-combo-pfmetraw-fj200.root");
TTree *tree = new TTree();
tree = (TTree*) inclusive->FindObjectAny( "Znunu_signal");
Int_t event;
Float_t genVpt;
Float_t weight;
Float_t jet1pt;
Float_t mvamet;
Int_t nentries = (Int_t) tree->GetEntries();
//read all entries and fill the hist
TH1F *hx = new TH1F( "Znunu_signal_genVpt", "Z Pt" , 75, 250, 1000);
hx->Sumw2();
tree->SetBranchAddress("weight", &weight);
tree->SetBranchAddress("genVpt", &genVpt);
tree->SetBranchAddress("mvamet", &mvamet);
tree->SetBranchAddress("jet1pt", &jet1pt);
for ( Int_t i = 0 ; i < nentries ; i++)
{
tree->GetEntry(i);
if ( mvamet < 250) continue;
if ( jet1pt < 200) continue;
hx->Fill(genVpt , weight);
}
return hx;
}
示例13: 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;
}
示例14: 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();
}
示例15: Photon_Pt
TH1F* Photon_Pt()
{
TFile *inclusive = new TFile( "/afs/cern.ch/work/b/bbachu/private/Z_nunu/boosted-combo-pfmetraw-fj200.root");
TTree *tree = new TTree();
tree = (TTree*) inclusive->FindObjectAny( "Photon_photon_control");
Int_t event;
Float_t ptpho;
Float_t mvamet;
Float_t jet1pt;
Float_t weight;
Int_t nentries = (Int_t) tree->GetEntries();
//read all entries and fill the hist
TH1F *hx = new TH1F( "Photon_photon_control_genVpt", "#gamma Pt " , 75 , 250 , 1000);
hx->Sumw2();
tree->SetBranchAddress("weight", &weight);
tree->SetBranchAddress("ptpho", &ptpho);
tree->SetBranchAddress("mvamet", &mvamet);
tree->SetBranchAddress("jet1pt", &jet1pt);
for ( Int_t i = 0 ; i < nentries ; i++)
{
//for boosted we need mvamet > 250 and jet1pt >200
tree->GetEntry(i);
if ( mvamet < 250) continue;
if ( jet1pt < 200) continue;
hx->Fill(ptpho , weight /* apply efficiency factor */ /* *0.971*/ );
}
return hx;
}