本文整理汇总了C++中TBranch::SetAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ TBranch::SetAddress方法的具体用法?C++ TBranch::SetAddress怎么用?C++ TBranch::SetAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBranch
的用法示例。
在下文中一共展示了TBranch::SetAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectBranches
/*********************
* BRANCHES
* *******************
*/
void Tree::selectBranches()
{
//Deactivate all branches (used branches activated below)
tree->SetBranchStatus("*", 0);
TBranch *branch;
//Timestamp
branch = tree->GetBranch("Time");
branch->SetStatus(1);
branch->SetAddress(&branchTime);
//ECal energy
branch = tree->GetBranch("EcalEnergy");
branch->SetStatus(1);
branch->SetAddress(&branchEcalEnergy);
//Rigidity
branch = tree->GetBranch("TrackerRigidity");
branch->SetStatus(1);
branch->SetAddress(&branchTrackerRigidity);
//Ecal BDT
branch = tree->GetBranch("EcalBDT");
branch->SetStatus(1);
branch->SetAddress(&branchEcalBDT);
}
示例2: 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);
}
}
示例3: 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;
}
示例4: 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());
}
}
}
示例5: 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();
}
示例6: runtime_error
/// 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);
}
示例7: 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;
}
示例8: displaySingleChannelWaveforms
void displaySingleChannelWaveforms(TString fdat, int board, int channel) {
gStyle->SetOptStat(0);
TFile *f = new TFile(fdat);
if (f->IsZombie()){
cout << "Cannot open file: " << fdat << endl;
return;
}
TBEvent *event = new TBEvent();
TTree *t1041 = (TTree*)f->Get("t1041");
TBranch *bevent = t1041->GetBranch("tbevent");
bevent->SetAddress(&event);
TCanvas * canv = new TCanvas("canv", "canv", 2000, 2000);
canv->cd();
TH1F * dummy = new TH1F("dummy", "dummy", 120, 0, 120);
dummy->GetYaxis()->SetRangeUser(0, 2500);
dummy->Draw();
vector<TH1F*> waves;
TH1F * wave = new TH1F("wave", "wave", 120, 0, 120);
int nplots = 0;
for (Int_t i = 0; i < t1041->GetEntries(); i++) {
t1041->GetEntry(i);
for (int j = 0; j < event->NPadeChan(); j++){
PadeChannel pch = event->GetPadeChan(j);
if((int)pch.GetBoardID() != board || (int)pch.GetChannelID() != channel) continue;
pch.GetHist(wave);
nplots++;
TH1F * wavecopy = (TH1F*)wave->Clone("wave_"+TString(Form("%d", nplots)));
waves.push_back(wavecopy);
}
}
int nBigPeaks = 0;
for(unsigned int ui = 0; ui < waves.size(); ui++) {
if(waves[ui]->GetMaximum() > 400) {
waves[ui]->SetLineColor(nBigPeaks+2);
nBigPeaks++;
}
waves[ui]->Draw("same");
}
}
示例9: 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;
}
示例10: 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
}
示例11: 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();
}
示例12: 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;
}
示例13: mTree
mTree(TTree *t){
name=t->GetName();
entries=(long)t->GetEntries();
totSize=t->GetZipBytes();
leaves=t->GetListOfBranches()->GetEntriesFast();
for (int i=0; i<leaves; i++) {
TBranch* branch = (TBranch*)t->GetListOfBranches()->UncheckedAt(i);
branch->SetAddress(0);
// cout <<i<<"\t"<<branch->GetName()<<"\t BS: "<< branch->GetBasketSize()<<"\t size: "<< branch->GetTotalSize()<< "\ttotbytes: "<<branch->GetTotBytes() << endl;
branchSizes.insert(std::pair<string,long>(branch->GetName(),branch->GetZipBytes()));
}
}
示例14: dumpDDG4
int dumpDDG4(const char* fname, int event_num) {
TFile* data = TFile::Open(fname);
if ( !data || data->IsZombie() ) {
printf("+ File seems to not exist. Exiting\n");
usage();
return -1;
}
TTree* tree = (TTree*)data->Get("EVENT");
for(int event=0, num=tree->GetEntries(); event<num; ++event) {
TObjArray* arr = tree->GetListOfBranches();
if ( event_num>= 0 ) event = event_num;
for(int j=0, nj=arr->GetEntries(); j<nj; ++j) {
TBranch* b = (TBranch*)arr->At(j);
typedef vector<void*> _E;
_E* e = 0;
b->SetAddress(&e);
int nbytes = b->GetEvent(event);
if ( nbytes > 0 ) {
if ( e->empty() ) {
continue;
}
string br_name = b->GetName();
string cl_name = b->GetClassName();
if ( cl_name.find("dd4hep::sim::Geant4Tracker::Hit") != string::npos ) {
typedef vector<Geant4Tracker::Hit*> _H;
printHits(br_name,(_H*)e);
}
else if ( cl_name.find("dd4hep::sim::Geant4Calorimeter::Hit") != string::npos ) {
typedef vector<Geant4Calorimeter::Hit*> _H;
printHits(br_name,(_H*)e);
}
else if ( cl_name.find("dd4hep::sim::Geant4Particle") != string::npos ) {
typedef vector<Geant4Particle*> _H;
::printf("%s\n+ Particle Dump of event %8d [%8d bytes] +\n%s\n",
line,event,nbytes,line);
printParticles(br_name,(_H*)e);
}
}
}
if ( event_num >= 0 ) break;
}
delete data;
return 0;
}
示例15: GetMean
Float_t KVINDRAPulserDataTree::GetMean(const Char_t* param, Int_t run)
{
// Return mean value of pulser/laser for given parameter and run.
// For detectors, param should be name of an acquisition parameter
// e.g. CI_0201_PG, CSI_1301_L, etc.
// For pin laser diodes, param should be name of associated acquisition parameter
// with either '_laser' or '_gene' appended
// e.g. PILA_05_PG_laser, SI_PIN1_PG_gene
//
// Returns -1.0 if no data available for this parameter/run.
if( !fArb ) return -1.0;
//find corresponding branch
TBranch *br = fArb->GetBranch(param);
if( !br ){
//no branch found - wrong name given ?
Error("GetMean", "No branch found with name %s", param);
return -1.0;
}
//enable branch
fArb->SetBranchStatus(param, 1);
//connect variable to branch
Float_t value = -1.0;
br->SetAddress(&value);
//read entry corresponding to run
Int_t bytes = fArb->GetEntryWithIndex(run);
if( bytes < 0 ){
//unknown run number
Error("GetMean", "Unknown run %d", run);
return -1.0;
}
//disable branch
fArb->SetBranchStatus(param, 0);
return value;
}