本文整理汇总了C++中TTree::GetBranch方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::GetBranch方法的具体用法?C++ TTree::GetBranch怎么用?C++ TTree::GetBranch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::GetBranch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillhist
void fillhist(const char* filename, const char* treename, int process, double scale, TH1* hist) {
TFile* file = new TFile(filename);
TTree* tree = (TTree*)file->Get(treename);
TBranch *bmet = tree->GetBranch("mumet");
TBranch *bweight = tree->GetBranch("weight");
TBranch *bnjets = tree->GetBranch("njets");
TBranch *bjjdphi = tree->GetBranch("jetjetdphi");
double vmet = 0.0;
double vweight = 0.0;
unsigned vnjets = 0;
double vjjdphi = 0.0;
bmet ->SetAddress(&vmet);
bweight->SetAddress(&vweight);
bnjets ->SetAddress(&vnjets);
bjjdphi->SetAddress(&vjjdphi);
for (int i = 0; i < tree->GetEntries(); i++) {
bmet ->GetEvent(i);
bweight->GetEvent(i);
bnjets ->GetEvent(i);
bjjdphi->GetEvent(i);
if (process == 0) vweight *= scale;
if (process == 1) vweight *= scale * (5.942 * 1.023) / (0.79*(1.0-exp(-0.00910276*(vmet-36.1669))));
if (process == 2) vweight *= scale * 38.7823/pow(-85.7023 + vmet, 0.667232);
hist->Fill(vmet, vweight);
}
}
示例2: closeAdj
//---------------------------------------------------------------------------
TArrayF &StockReturn(TFile *f,const TString &name,Int_t sDay,Int_t eDay)
{
TTree *tDaily = (TTree*)f->Get(name);
TStockDaily *data = 0;
tDaily->SetBranchAddress("daily",&data);
TBranch *b_closeAdj = tDaily->GetBranch("fCloseAdj");
TBranch *b_date = tDaily->GetBranch("fDate");
//read only the "adjusted close" branch for all entries
const Int_t nrEntries = (Int_t)tDaily->GetEntries();
TArrayF closeAdj(nrEntries);
for (Int_t i = 0; i < nrEntries; i++) {
b_date->GetEntry(i);
b_closeAdj->GetEntry(i);
if (data->fDate >= sDay && data->fDate <= eDay)
closeAdj[i] = data->fCloseAdj/100.;
}
TArrayF *r = new TArrayF(nrEntries-1);
for (Int_t i = 1; i < nrEntries; i++)
// (*r)[i-1] = closeAdj[i]-closeAdj[i-1];
(*r)[i-1] = closeAdj[i]/closeAdj[i-1];
return *r;
}
示例3: GetTreeSize
void GetTreeSize(TString FileName, TString TreeName)
{
TFile *inf = TFile::Open(FileName);
TTree *tr = (TTree*)inf->Get(TreeName);
TObjArray *branches = (TObjArray*)tr->GetListOfBranches();
int size(0);
cout.setf(ios::right);
int N(branches->GetEntries());
TH1F *hSize = new TH1F("size","size",N,0,N);
for(int ib=0;ib<N;ib++) {
TString name(branches->At(ib)->GetName());
TBranch *br = (TBranch*)tr->GetBranch(name);
hSize->Fill(name,br->GetZipBytes()/1e+3);
size += br->GetZipBytes();
}
cout<<"Total size: "<<size<<endl;
for(int ib=0;ib<N;ib++) {
TString name(branches->At(ib)->GetName());
TBranch *br = (TBranch*)tr->GetBranch(name);
float percent = TMath::Ceil(1000*float(br->GetZipBytes())/float(size))/10;
cout<<ib<<setw(20)<<name<<setw(15)<<br->GetZipBytes()<<" "<<percent<<"%"<<endl;
}
TCanvas *can = new TCanvas("TreeSize","TreeSize",1000,400);
hSize->GetXaxis()->SetTitle("Branch Name");
hSize->GetXaxis()->SetLabelSize(0.04);
hSize->GetYaxis()->SetTitle("Size (KB)");
hSize->SetFillColor(kGray);
hSize->Draw();
}
示例4: ProtonCounting
// This ROOT macro counts the number of protons that stop in the thick silicon detectors
void ProtonCounting(std::string filename) {
TFile* file = new TFile(filename.c_str(), "READ");
TTree* tree = (TTree*) file->Get("tree");
std::vector<std::string>* particleName = 0;
std::vector<std::string>* volName = 0;
std::vector<std::string>* ovolName = 0;
std::vector<int>* stopped = 0;
TBranch* br_particleName = tree->GetBranch("M_particleName");
TBranch* br_volName = tree->GetBranch("M_volName");
TBranch* br_ovolName = tree->GetBranch("M_ovolName");
TBranch* br_stopped = tree->GetBranch("M_stopped");
br_particleName->SetAddress(&particleName);
br_volName->SetAddress(&volName);
br_ovolName->SetAddress(&ovolName);
br_stopped->SetAddress(&stopped);
int n_protons = 0;
int n_protons_right = 0;
int n_protons_left = 0;
int n_stopped_muons = 0;
for (int iEntry = 0; iEntry < tree->GetEntries(); ++iEntry) {
tree->GetEvent(iEntry);
for (int iElement = 0; iElement < particleName->size(); ++iElement) {
if (particleName->at(iElement) == "proton" && volName->at(iElement) == "ESi1" && stopped->at(iElement) == 1 && ovolName->at(iElement) == "Target") {
++n_protons_right;
++n_protons;
}
else if (particleName->at(iElement) == "proton" && volName->at(iElement) == "ESi2" && stopped->at(iElement) == 1 && ovolName->at(iElement) == "Target") {
++n_protons_left;
++n_protons;
}
else if (particleName->at(iElement) == "mu-" && volName->at(iElement) == "Target" && stopped->at(iElement) == 1) {
++n_stopped_muons;
}
}
}
std::cout << "There were " << n_protons << " protons that reached the thick silicon detectors out of " << n_stopped_muons << " stopped muons (" << tree->GetEntries() << " input muons." << std::endl;
std::cout << "N_right = " << n_protons_right << ", N_left = " << n_protons_left << std::endl;
std::cout << "Acceptance = " << (double) n_protons / n_stopped_muons << std::endl;
}
示例5: loadTracks
Tracks * loadTracks(Int_t Runs, Int_t dataType, Float_t energy) {
TString sDataType = (dataType == 0) ? "_MC_" : "_data_";
TString sAbsThick = Form("_%.0fmm", kAbsorbatorThickness);
TString sEnergy = Form("_%.2fMeV", energy);
TString fileName = "Data/Tracks/tracks";
TString sMaterial = getMaterialChar();
fileName.Append(sDataType);
fileName.Append(sMaterial);
fileName.Append(sAbsThick);
fileName.Append(sEnergy);
fileName.Append(".root");
TFile *f = new TFile(fileName);
if (!f) return 0;
TTree *T = (TTree*) f->Get("T");
Tracks * tracks = new Tracks();
T->GetBranch("tracks")->SetAutoDelete(kFALSE);
T->SetBranchAddress("tracks",&tracks);
T->GetEntry(0);
cout << "There are " << tracks->GetEntriesFast() << " tracks in " << fileName << ".\n";
return tracks;
}
示例6: covmat
hw()
{
Float_t data;
TFile *f=new TFile("data.root");
TTree* tree = f->Get("mytree");
TBranch* branch = tree->GetBranch("data");
branch->SetAddress(&data);
TH1F* h1 = new TH1F("h1","h1",200,0.0,5.0);
for(Int_t i= 0 ; i< tree->GetEntries() ; i++) {
tree->GetEntry(i);
h1->Fill( data) ;
}
TF1 *f2 = new TF1("f2", "[0]*x+[1]+gaus(2)", 0.0, 5.0);
f2->SetParameter(3,3.7);
TVirtualFitter *min = TVirtualFitter::Fitter(0,2);
TVirtualFitter::SetDefaultFitter("Minuit");
TFitResultPtr fitresult = h1->Fit("f2", "MES");
cout<< "Parameter 0" << fitresult->Parameter(0) << "+-" << fitresult->ParError(0) << endl;
cout<< "Parameter 1" <<fitresult->Parameter(1) << "+-" << fitresult->ParError(1) << endl;
cout << "Chi2 " << fitresult->Chi2() << endl;
cout << "NDF " << fitresult->Ndf() << endl;
cout << "Chi2 probability " << fitresult->Prob() << endl;
TMatrixD covmat(fitresult->GetCovarianceMatrix());
cout << "Covariance matrix" << endl;
covmat.Print();
TCanvas *c1 = new TCanvas("c1", "binned line fit", 600, 600);
c1->Draw();
h1->Draw();
}
示例7: histogram
void histogram() {
// Read data from ASCII file and create histogram/ntuple combo
ifstream in;
in.open("/users/ronnie/git/Journal-Analysis/data.txt");
Text_t month;
Float_t date, day, words;
TFile *file = new TFile("histogramTest.root", "CREATE");
TH1F *histo = new TH1F("histo", "writing distribution", 100, 0, 2);
TTree *Tree = new TTree("ntuple", "data from file");
Tree->ReadFile(Form("/users/ronnie/git/Journal-Analysis/Daily Journals/data.txt"), "month:date:day:words");
graph = new TGraph(200, &words, &day);
// Get the total number of words written and print out to CLI
Tree->Print();
Int_t numEntries = (Int_t)(Tree->GetEntries());
TBranch *wordsBranch = Tree->GetBranch("words");
for(Int_t i = 0; i < numEntries; i++) {
Tree->GetEntry(i, 0);
}
// Draw the Tree (words vs. day) on canvas
Tree->SetEstimate(Tree->GetEntries());
Tree->Draw("words:day");
// Have to loop back through drawn tree to get values and count number of words total
Float_t numWords = 0.0;
Double_t *array = Tree->GetV1();
for (Int_t i = 0; i < numEntries; i++) {
numWords += array[i];
}
cout << numWords << endl;
}
示例8: CheckOutput
void CheckOutput(){
//
//
//
TFile * f = TFile::Open("Filtered.root");
TTree * highPt = (TTree*)f->Get("highPt");
TTree * treeV0s = (TTree*)f->Get("V0s");
//
// Export variable:
//
Double_t ratioHighPtV0Entries=treeV0s->GetEntries()/Double_t(treeV0s->GetEntries()+highPt->GetEntries()+0.000001);
Double_t ratioHighPtV0Size=treeV0s->GetZipBytes()/Double_t(treeV0s->GetZipBytes()+highPt->GetZipBytes()+0.000001);
printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPtToV0Entries\t%f\n",ratioHighPtV0Entries);
printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPtToV0Size\t%f\n",ratioHighPtV0Size);
//
//
Double_t ratioPointsV0 = 2*treeV0s->GetBranch("friendTrack0.fCalibContainer")->GetZipBytes()/Double_t(0.00001+treeV0s->GetZipBytes());
Double_t ratioPointsHighPt = highPt->GetBranch("friendTrack.fCalibContainer")->GetZipBytes()/Double_t(0.00001+highPt->GetZipBytes());
printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPointsV0\t%f\n",ratioPointsV0);
printf("#UnitTest:\tAliAnalysisTaskFiltered\tRatioPointsHighPt\t%f\n",ratioPointsHighPt);
//
// a.) Check track correspondence
//
Int_t entries= highPt->Draw("(friendTrack.fTPCOut.fP[3]-esdTrack.fIp.fP[3])/sqrt(friendTrack.fTPCOut.fC[9]+esdTrack.fIp.fC[9])","friendTrack.fTPCOut.fP[3]!=0","");
// here we should check if the tracks
Double_t pulls=TMath::RMS(entries, highPt->GetV1());
printf("#UnitTest:\tAliAnalysisTaskFiltered\tFriendPull\t%2.4f\n",pulls);
printf("#UnitTest:\tAliAnalysisTaskFiltered\tFriendOK\t%d\n",pulls<10);
}
示例9: PlotSignals
int PlotSignals(char *filename, int plfrom=0, int plto=100, int same=1) {
bragg_signal signal;
TFile *fin=new TFile(filename);
if (!fin->IsOpen()) {
std::cout << "file not found! " << std::endl;
return -1;
}
TTree *tree = (TTree*)fin->Get("bragg");
if (!tree) {
std::cout << "Bragg tree not found! " << std::endl;
return -2;
}
TBranch *br = tree->GetBranch("signals");
if (!br) {
std::cout << "Signal branch not found! " << std::endl;
return -3;
}
br->SetAddress(&signal);
int nev = br->GetEntries();
std::cout << "Number of events in file : " << nev << std::endl;
for (int i=plfrom; i<plto; i++) {
br->GetEntry(i);
plotSignal(signal,same);
}
return 0;
}
示例10: drawmerged
void drawmerged(Int_t sec, Int_t row, Int_t x1=-1, Int_t x2=-1, Int_t y1=-1, Int_t y2=-1)
{
/// if you think that there is memory leak -
/// you are tru but othervise graphic doesn't work
/// sec=0; row =0;
TFile * f = new TFile("galice.root");
TFile * f1= new TFile("ev1/galice.root.digits");
TFile * f2= new TFile("ev2/galice.root.digits");
TTree * tree = (TTree*)f->Get("TreeD_75x40_100x60_150x60_0");
TTree * tree1 = (TTree*)f1->Get("TreeD_75x40_100x60_150x60_0");
TTree * tree2 = (TTree*)f2->Get("TreeD_75x40_100x60_150x60_0");
//
AliSimDigits *dig=0;
AliSimDigits *dig1=0;
AliSimDigits *dig2=0;
//
tree->GetBranch("Segment")->SetAddress(&dig);
tree1->GetBranch("Segment")->SetAddress(&dig1);
tree2->GetBranch("Segment")->SetAddress(&dig2);
AliTPCParam * param =(AliTPCParam*) f->Get("75x40_100x60");
if(param){
delete param;
param=new AliTPCParamSR();
}
else param=(AliTPCParam*) f->Get("75x40_100x60_150x60");
Int_t index = param->GetIndex(sec,row);
tree->GetEvent(index);
tree1->GetEvent(index);
tree2->GetEvent(index);
TCanvas * c = new TCanvas(" Test merged digits", "test",600,900);
c->Divide(1,3);
//
c->cd(1);
AliH2F * his = dig->DrawDigits("cont1",x1,x2,y1,y2);
his->SetTitle("MergedDigits");
his->SetName("Merged Digits");
his->GetXaxis()->SetTitle("time");
his->GetYaxis()->SetTitle("pad");
his->DrawClone("cont1");
//
c->cd(2);
AliH2F * his1 =dig1->DrawDigits("cont1",x1,x2,y1,y2);
his1->SetTitle("background");
his1->SetName("background");
his1->GetXaxis()->SetTitle("time");
his1->GetYaxis()->SetTitle("pad");
his1->DrawClone("cont1");
//
c->cd(3);
AliH2F * his2 =dig2->DrawDigits("cont1",x1,x2,y1,y2);
his2->SetTitle("signal");
his2->SetName("signal");
his2->GetXaxis()->SetTitle("time");
his2->GetYaxis()->SetTitle("pad");
his2->DrawClone("cont1");
}
示例11: test_event
int test_event()
{
TTree *T = (TTree*)gFile->Get("T");
SillyStlEvent *event = new SillyStlEvent();
event->foo = 0xfa3;
TBranch *branch = T->GetBranch("test");
branch->SetAddress(&event);
T->GetEvent(0);
return event->foo.to_ulong() != 0xfa2;
}
示例12: h2fast
void h2fast(const char *url , Bool_t draw=kFALSE, Long64_t cachesize=10000000, Int_t learn=1) {
// gEnv->SetValue("TFile.DavixLog", 10);
// gDebug= 0x02;
TStopwatch sw;
TTree* T = NULL;
sw.Start();
Long64_t oldb = TFile::GetFileBytesRead();
TFile *f = TFile::Open(url);
if (!f || f->IsZombie()) {
printf("File h1big.root does not exist\n");
exit (-1);
}
// TTreeCacheUnzip::SetParallelUnzip(TTreeCacheUnzip::kEnable);
T= (TTree*)f->Get("h42");
Long64_t nentries = T->GetEntries();
T->SetCacheSize(cachesize);
TTreeCache::SetLearnEntries(learn);
TFileCacheRead *tpf = f->GetCacheRead();
//tpf->SetEntryRange(0,nentries);
if (draw) T->Draw("rawtr","E33>20");
else {
TBranch *brawtr = T->GetBranch("rawtr");
TBranch *bE33 = T->GetBranch("E33");
Float_t E33;
bE33->SetAddress(&E33);
for (Long64_t i=0;i<nentries;i++) {
T->LoadTree(i);
bE33->GetEntry(i);
if (E33 > 0) brawtr->GetEntry(i);
}
}
if (tpf) tpf->Print();
printf("Bytes read = %lld\n",TFile::GetFileBytesRead()-oldb);
printf("Real Time = %7.3f s, CPUtime = %7.3f s\n",sw.RealTime(),sw.CpuTime());
delete T;
delete f;
}
示例13: kt_test_pico
void kt_test_pico(TString fin="test.root")
{
gROOT->Reset();
gROOT->Clear();
// ktJet lib
if (gClassTable->GetID("ktJet") < 0) {
cout<<"Load ktJet lib ..."<<endl;
gSystem->Load("libKtJet.so");
}
cout<<endl;
cout<<" Test STAR pico Dst interface"<<endl;
cout<<" ----------------------------"<<endl;
cout<<endl;
cout<<"Open STAR pico Dst file : "<<fin<<endl;
cout<<endl;
TFile *inFile = TFile::Open(fin);
inFile->cd();
TTree *outT = inFile->Get("JetTree");
TStarJetPicoEvent *event = new TStarJetPicoEvent();
TBranch *branch = outT->GetBranch("PicoJetTree");
branch->SetAddress(&event);
Int_t ievents = outT->GetEntries();
cout<<"Number of events = "<<ievents<<endl;
ktStarPico *mQA=new ktStarPico(true);
mQA->PrintQACuts();
for (Int_t i = 0; i<ievents; i++)
{
if (i>250) continue;
outT->GetEvent(i);
mQA->DoQAOnly(event);
}
mQA->WriteQAOutputFile("QA_test_out.root");
//inFile->Close();
delete mQA;
cout<<endl;
cout<<"Done ;-)"<<endl;
cout<<endl;
}
示例14: testgeo
void testgeo(const char* rootfile)
{
// Clear global scope
gROOT->Reset();
// Load the library with class dictionary info
gSystem->Load("libWCSimRoot.so");
// Open the file, replace if you've named it something else
TFile file(rootfile);
// Get the a pointer to the tree from the file
TTree *gtree = (TTree*)file.Get("wcsimGeoT");
// Get the number of events
int nevent = gtree->GetEntries();
printf("geo nevent %d\n",nevent);
// Create a WCSimRootGeom to put stuff from the tree in
WCSimRootGeom* wcsimrootgeom = new WCSimRootGeom();
// Set the branch address for reading from the tree
TBranch *branch = gtree->GetBranch("wcsimrootgeom");
branch->SetAddress(&wcsimrootgeom);
// Now loop over "events" (should be only one for geo tree)
int ev;
for (ev=0;ev<nevent; ev++) {
// Read the event from the tree into the WCSimRootGeom instance
gtree->GetEntry(ev);
printf("Cyl radius %f\n", wcsimrootgeom->GetWCCylRadius());
printf("Cyl length %f\n", wcsimrootgeom->GetWCCylLength());
printf("PMT radius %f\n", wcsimrootgeom->GetWCPMTRadius());
printf("Offset x y z %f %f %f\n", wcsimrootgeom->GetWCOffset(0),
wcsimrootgeom->GetWCOffset(1),wcsimrootgeom->GetWCOffset(2));
int numpmt = wcsimrootgeom->GetWCNumPMT();
printf("Num PMTs %d\n", numpmt);
int i;
for (i=0;i<((numpmt<20)?numpmt:20);i++){
WCSimRootPMT pmt;
pmt = wcsimrootgeom->GetPMT(i);
printf ("pmt %d %d %d\n",i,pmt.GetTubeNo(), pmt.GetCylLoc());
printf ("position: %f %f %f\n", pmt.GetPosition(0),
pmt.GetPosition(1),pmt.GetPosition(2));
printf ("orientation: %f %f %f\n", pmt.GetOrientation(0),
pmt.GetOrientation(1),pmt.GetOrientation(2));
}
} // End of loop over events
}
示例15: beginRun
AppResult GeneratorReader::beginRun(AppEvent& event) {
TTree *Events = 0;
if( event.get("Events",Events) || !Events )
return AppResult(AppResult::STOP|AppResult::ERROR,"No 'Events' tree found");
TBranch *inputGen = Events->GetBranch("BNmcparticles_BNproducer_MCstatus3_BEANs.");
if( !inputGen ) return AppResult(AppResult::STOP|AppResult::ERROR,"No 'BNmcparticles_BNproducer_MCstatus3_BEANs.' branch found");
inputGen->SetAddress(&__genParticles);
return AppResult();
}