本文整理汇总了C++中TBranch类的典型用法代码示例。如果您正苦于以下问题:C++ TBranch类的具体用法?C++ TBranch怎么用?C++ TBranch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TBranch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: branchName
void ResultFormatter::AddBranch( TTree* inputTree, const string& BranchName, const vector<double>& DoubleData )
{
if( inputTree->GetEntries() != 0 )
{
if( inputTree->GetEntries() != (int) DoubleData.size() )
{
cerr << "CANNOT ADD DOUBLE BRANCH: " << BranchName << " TO: " << inputTree->GetName() << endl;
return;
}
}
TString branchName( BranchName );
TString branchLabel=branchName; branchLabel.Append("/D");
double thisValue=0.;
TBranch* newBranch = inputTree->Branch( branchName, &thisValue, branchLabel );
inputTree->SetEntries( (int) DoubleData.size() );
for( unsigned int i=0; i< DoubleData.size(); ++i )
{
thisValue=DoubleData[i];
newBranch->Fill();
}
return;
}
示例2: pulseHeights
void pulseHeights(Int_t board=112, TString file="latest.root",
Int_t xmin=300, Int_t xmax=50){
TFile *f = new TFile(file);
// create a pointer to an event object for reading the branch values.
TBEvent *event = new TBEvent();
TTree *t1041 = (TTree*) f->Get("t1041");
TBranch *bevent = t1041->GetBranch("tbevent");
bevent->SetAddress(&event);
TH1F *hpulse[32];
for (int i=0; i<32; i++){
TString name;
name.Form("h%d_%2d",board,i);
hpulse[i]=new TH1F(name,name,xmax-xmin,xmin,xmax);
}
// loop over events
for (Int_t i=0; i< t1041->GetEntries(); i++) {
t1041->GetEntry(i);
// loop over PADE channels
for (Int_t j=0; j<event->NPadeChan(); j++){
if (event->GetPadeChan(j).GetBoardID() != board) continue;
int chan=event->GetPadeChan(j).GetChannelID();
hpulse[chan]->Fill(event->GetPadeChan(j).GetMax());
}
}
}
示例3: next
void OnlineGUI::GetTreeVars()
{
// Utility to find all of the variables (leaf's/branches) within a
// Specified TTree and put them within the treeVars vector.
treeVars.clear();
TObjArray *branchList;
vector <TString> currentTree;
for(UInt_t i=0; i<fRootTree.size(); i++) {
currentTree.clear();
branchList = fRootTree[i]->GetListOfBranches();
TIter next(branchList);
TBranch *brc;
while((brc=(TBranch*)next())!=0) {
TString found = brc->GetName();
// Not sure if the line below is so smart...
currentTree.push_back(found);
}
treeVars.push_back(currentTree);
}
#ifdef DEBUG2
for(UInt_t iTree=0; iTree<treeVars.size(); iTree++) {
cout << "In Tree " << iTree << ": " << endl;
for(UInt_t i=0; i<treeVars[iTree].size(); i++) {
cout << treeVars[iTree][i] << endl;
}
}
#endif
}
示例4: make_pair
/// Open new data file
bool DDG4EventHandler::Open(const std::string&, const std::string& name) {
if ( m_file.first ) m_file.first->Close();
m_hasFile = false;
m_hasEvent = false;
TFile* f = TFile::Open(name.c_str());
if ( f && !f->IsZombie() ) {
m_file.first = f;
TTree* t = (TTree*)f->Get("EVENT");
if ( t ) {
TObjArray* br = t->GetListOfBranches();
m_file.second = t;
m_entry = -1;
m_branches.clear();
for(Int_t i=0; i<br->GetSize(); ++i) {
TBranch* b = (TBranch*)br->At(i);
if ( !b ) continue;
m_branches[b->GetName()] = make_pair(b,(void*)0);
printout(INFO,"DDG4EventHandler::open","+++ Branch %s has %ld entries.",b->GetName(),b->GetEntries());
}
for(Int_t i=0; i<br->GetSize(); ++i) {
TBranch* b = (TBranch*)br->At(i);
if ( !b ) continue;
b->SetAddress(&m_branches[b->GetName()].second);
}
m_hasFile = true;
return true;
}
throw runtime_error("+++ Failed to access tree EVENT in ROOT file:"+name);
}
throw runtime_error("+++ Failed to open ROOT file:"+name);
}
示例5: file
void AnalysisModuleRunner::begin_in_file(const string & infile){
std::unique_ptr<TFile> file(TFile::Open(infile.c_str(), "read"));
if(read_trigger){
std::map<int, std::vector<std::string>> runid_to_triggernames;
// find triggernames for all runs in this file:
TTree * intree = dynamic_cast<TTree*>(file->Get("AnalysisTree"));
if(!intree) throw runtime_error("Did not find AnalysisTree in input file");
std::vector<std::string> trigger_names;
std::vector<std::string> *ptrigger_names = &trigger_names;
int runid = 0;
TBranch* runb = 0;
TBranch* tnb = 0;
intree->SetBranchAddress("run", &runid, &runb);
intree->SetBranchAddress("triggerNames", &ptrigger_names, &tnb);
if(runb==0 || tnb==0){
throw runtime_error("did not find branches for setting up trigger names");
}
int nentries = intree->GetEntries();
int last_runid = -1;
for(int i=0; i<nentries; ++i){
runb->GetEntry(i);
if(last_runid == runid) continue;
last_runid = runid;
assert(runid >= 1);
tnb->GetEntry(i);
if(!trigger_names.empty()){
runid_to_triggernames[runid] = trigger_names;
}
}
LOG_INFO("Found " << runid_to_triggernames.size() << " trigger infos in file '" << infile << "'");
helper->set_infile_triggernames(move(runid_to_triggernames));
}
}
示例6: 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;
}
示例7: printout
/// Load the specified event
Int_t DDG4EventHandler::ReadEvent(Long64_t event_number) {
m_data.clear();
m_hasEvent = false;
if ( hasFile() ) {
if ( event_number >= m_file.second->GetEntries() ) {
event_number = m_file.second->GetEntries()-1;
printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read across End-of-file! Reading last event:%d.",event_number);
}
else if ( event_number < 0 ) {
event_number = 0;
printout(ERROR,"DDG4EventHandler","+++ nextEvent: Cannot read across Start-of-file! Reading first event:%d.",event_number);
}
Int_t nbytes = m_file.second->GetEntry(event_number);
if ( nbytes >= 0 ) {
printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Read %d bytes of event data for entry:%d",nbytes,event_number);
for(Branches::const_iterator i=m_branches.begin(); i != m_branches.end(); ++i) {
TBranch* b = (*i).second.first;
std::vector<void*>* ptr_data = *(std::vector<void*>**)b->GetAddress();
m_data[b->GetClassName()].push_back(make_pair(b->GetName(),ptr_data->size()));
}
m_hasEvent = true;
return nbytes;
}
printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read event data for entry:%d",event_number);
throw runtime_error("+++ EventHandler::readEvent: Failed to read event");
}
throw runtime_error("+++ EventHandler::readEvent: No file open!");
}
示例8: hw
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();
}
示例9: loop
unsigned int loop(T& tree, TH3F* hist3D, TH2F* hist2D)
{
unsigned int nEvtsRead = 0;
unsigned int nEB = 0;
Long64_t N = tree.fChain->GetEntriesFast();
for (Long64_t iEvt = 0; iEvt < N; ++iEvt) {
Long64_t localEntry = tree.LoadTree(iEvt);
if (localEntry < 0) break;
++nEvtsRead;
tree.fChain->GetEntry(iEvt);
TObject* object = tree.fChain->GetListOfBranches()->FindObject("totalWeight");
TBranch* branch = NULL;
Float_t totalWeight = 1.0;
if (object != 0) {
branch = (TBranch*)object;
totalWeight = *(Float_t*)branch->GetAddress();
}
if (fabs(tree.probe_SC_eta) < 1.4442) {
++nEB;
hist3D->Fill(tree.dRTagProbe, tree.probe_nJets05, tree.event_nPV, totalWeight);
hist2D->Fill(tree.dRTagProbe, tree.probe_passing, totalWeight);
}
}
cout << "No. of probes in EB: " << nEB << endl;
return nEvtsRead;
}
示例10: getAliasNames
vector<TString> getAliasNames(TTree *t) {
vector<TString> v_aliasnames;
TList *t_list = t->GetListOfAliases();
for(int i = 0; i < t_list->GetSize(); i++) {
TString aliasname(t_list->At(i)->GetName());
TBranch *branch = t->GetBranch(t->GetAlias(aliasname.Data()));
TString branchname(branch->GetName());
TString branchtitle(branch->GetTitle());
if(branchname.BeginsWith("intss") ||
branchname.BeginsWith("floatss") ||
branchname.BeginsWith("doubless") ||
branchname.Contains("LorentzVectorss") ||
branchname.Contains("timestamp") ) {
cout << "Sorry, I dont know about vector of vectors of objects. "
<< "Will be skipping " << aliasname << endl;
continue;
}
if(branchname.Contains("TString") ) {
cout << "Sorry, I don't know how to graphically represent TStrings in only 3 dimensions"
<< " Put in a feature request. Will be skipping " << aliasname << endl;
continue;
}
v_aliasnames.push_back(aliasname);
}
sort(v_aliasnames.begin(), v_aliasnames.end());
return v_aliasnames;
}
示例11: updateweight
void updateweight(TString filename)
{
auto f = new TFile(filename,"update");
auto nt = (TTree *)f->Get("nt");
float prew, weight;
TBranch *bw;
bw = nt->Branch("weight",&weight);
nt->SetBranchAddress("prew",&prew);
int n = nt->GetEntries();
int onep = n/100;
for (int i=0;i<n;i++) {
if (i%onep==0) cout<<i/onep<<endl;
nt->GetEntry(i);
weight = prew;
bw->Fill();
}
nt->Write();
f->Close();
}
示例12: TRandom3
int RDK2Events::loadEvents(TString fileName,TString treeName)
{
if(eventFile!=nullptr){
eventFile->Close();
delete eventFile;
}
if(ranGen==nullptr)
{
ranGen=new TRandom3();
}
eventFilePath = fileName;
eventFile = new TFile(fileName,"READ");
//Check to see if file was succesfully opened
if(eventFile->IsZombie()){
reset();
return -1;
}
//Get Tree from file
eventTree=(TTree*) eventFile->Get(treeName);
TBranch* n = eventTree->GetBranch("n");
numEvents=n->GetEntries();
eventStart=0;
eventEnd=eventStart+numEvents-1;
//Set our branch addresses for filling
eventTree->SetBranchAddress("x0",&x0);
eventTree->SetBranchAddress("y0",&y0);
eventTree->SetBranchAddress("z0",&z0);
eventTree->SetBranchAddress("ee0",&ee0);
eventTree->SetBranchAddress("mxe0",&mxe0);
eventTree->SetBranchAddress("mye0",&mye0);
eventTree->SetBranchAddress("mze0",&mze0);
eventTree->SetBranchAddress("ep0",&ep0);
eventTree->SetBranchAddress("mxp0",&mxp0);
eventTree->SetBranchAddress("myp0",&myp0);
eventTree->SetBranchAddress("mzp0",&mzp0);
eventTree->SetBranchAddress("eg0",&eg0);
eventTree->SetBranchAddress("mxg0",&mxg0);
eventTree->SetBranchAddress("myg0",&myg0);
eventTree->SetBranchAddress("mzg0",&mzg0);
//If eg0 is greater than 0 than it must be a four body decay
if(eventTree->GetBranch("eg0")->GetEntry(0)>0)
fourBody=true;
else
fourBody=false;
return 0;
}
示例13: scanDiffRecoTracks
void scanDiffRecoTracks(std::string eName, std::string eoName,
std::string branchReg = "recoTracks_*"){
gSystem->Load("libFWCoreFWLite");
gROOT->ProcessLine("AutoLibraryLoader::enable();");
TChain* e = new TChain("Events");
e->SetScanField(0);
e->Add(eName.c_str());
TChain* eo = new TChain("Events");
eo->SetScanField(0);
eo->Add(eoName.c_str());
e->AddFriend(eo, "eo");
TRegexp regg(branchReg.c_str(), kTRUE);
TChain* tc = e ;
TObjArray* tl = tc->GetListOfBranches();
Int_t nBr = tl->GetSize();
for (int iB=0;iB<nBr;++iB){
TBranch* br = (TBranch*)(tl->At(iB));
TString ts(br->GetName());
if(ts.Index(regg)>=0){
std::cout<<ts.Data()<<std::endl;
tc->Scan(Form("Sum$(%s.obj.pt()>0):Sum$(eo.%s.obj.pt()>0):Sum$(%s.obj.pt()):Sum$(%s.obj.pt())-Sum$(eo.%s.obj.pt())",
ts.Data(), ts.Data(), ts.Data(), ts.Data(), ts.Data()),"", "");
}
} //> e.tecoTracks.recoT0.txt
}
示例14: make_scan_results
void make_scan_results()
{
TFile *f = TFile::Open("scan_results.root", "UPDATE");
f->Delete("SR;*");
T = new TTree("SR", "Scanning results");
TClonesArray* ts = new TClonesArray("IlcESDtrack", 32);
TBranch * tb = T->Branch("T", &ts);
delete ts;
IlcMultiplicity *ms = 0;
TBranch *mb = T->Branch("M", &ms);
for (Int_t v = 0; v < 3; ++v)
{
vvv[v].vert = 0;
vvv[v].branch = T->Branch(vvv[v].bname, &vvv[v].vert);
}
for (Int_t i=0; i<=9999; ++i)
{
TString name;
name.Form("Tracks_%04d", i);
ts = (TClonesArray*) f->Get(name);
if (ts == 0)
continue;
name.Form("Tracklets_%04d", i);
ms = (IlcMultiplicity*) f->Get(name);
if (ms == 0)
Error("make_scan_results", "'%s' not found.", name.Data());
tb->SetAddress(&ts);
mb->SetAddress(&ms);
for (Int_t v = 0; v < 3; ++v)
{
name.Form("%s_%04d", vvv[v].oname, i);
vvv[v].vert = (IlcESDVertex*) f->Get(name);
if (vvv[v].vert == 0)
Error("make_scan_results", "'%s' not found.", name.Data());
vvv[v].branch->SetAddress(&vvv[v].vert);
}
T->Fill();
delete ts;
delete ms;
for (Int_t v = 0; v < 3; ++v) delete vvv[v].vert;
}
T->Write();
f->Close();
delete f;
}
示例15: UpdateTag
//_____________________________________//
Bool_t UpdateTag(TString faliroot, TString froot, TString fgeant,
TString turl, TString guid,
TString fperiod, TString fpass, TString fname) {
cout<<"> Updating tags...."<<endl;
const char * tagPattern = "tag.root";
// Open the working directory
void * dirp = gSystem->OpenDirectory(gSystem->pwd());
const char * name = 0x0;
// Add all files matching *pattern* to the chain
while((name = gSystem->GetDirEntry(dirp))) {
cout<<">>> Adding to chain file " << name << "...." << endl;
if (strstr(name,tagPattern)) {
TFile *f = TFile::Open(name,"read") ;
AliRunTag *tag = 0x0;
AliFileTag *flTag = 0x0;
TTree *fTree = (TTree *)f->Get("T");
if (!fTree) { f->Close(); continue; }
fTree->SetBranchAddress("AliTAG",&tag);
//Defining new tag objects
AliRunTag *newTag = 0x0;
TTree ttag("T","A Tree with event tags");
TBranch * btag = ttag.Branch("AliTAG", &newTag);
btag->SetCompressionLevel(9);
cout<<">>>>> Found " << fTree->GetEntries() << " entries...." << endl;
for(Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) {
fTree->GetEntry(0);
newTag = new AliRunTag(*tag);
newTag->SetAlirootVersion(faliroot);
newTag->SetRootVersion(froot);
newTag->SetGeant3Version(fgeant);
newTag->SetLHCPeriod(fperiod);
newTag->SetReconstructionPass(fpass);
newTag->SetProductionName(fname);
cout << "Found " << newTag->GetNFiles() << " file tags" << endl;
for(Int_t j = 0; j < newTag->GetNFiles(); j++) {
flTag = (AliFileTag *) newTag->GetFileTag(j);
flTag->SetTURL(turl);
flTag->SetGUID(guid);
}
ttag.Fill();
delete tag;
delete newTag;
}//tag file loop
TFile* ftag = TFile::Open(name, "recreate");
ftag->cd();
ttag.Write();
ftag->Close();
}//pattern check
}//directory loop
return kTRUE;
}