当前位置: 首页>>代码示例>>C++>>正文


C++ TBranch::GetEntries方法代码示例

本文整理汇总了C++中TBranch::GetEntries方法的典型用法代码示例。如果您正苦于以下问题:C++ TBranch::GetEntries方法的具体用法?C++ TBranch::GetEntries怎么用?C++ TBranch::GetEntries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TBranch的用法示例。


在下文中一共展示了TBranch::GetEntries方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TFile

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;



}
开发者ID:mjbales,项目名称:rdk2analysis,代码行数:60,代码来源:RDK2Events.cpp

示例2: 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;
}
开发者ID:Fisica2014-FF,项目名称:Sper3-RelazioneBragg,代码行数:33,代码来源:PlotSignals.C

示例3:

bool	is_same_size_tree(TTree *tree, Long_t *prev_entries, bool *first)
{
	Long_t entries;

	TObjArray *ar = tree->GetListOfBranches();
	for(Long_t i = 0; i < ar->GetEntries(); i++)
	{
		TBranch *br = (TBranch*)(*ar)[i];
		entries = br->GetEntries();

		if ((!*first) && (entries != *prev_entries))
		{
			return false;
		}
		*prev_entries = entries;
		*first = false;
	}
	return true;
}
开发者ID:veprbl,项目名称:libepecur,代码行数:19,代码来源:ProcessApp.cpp

示例4: plot_HF

// Commands executed in a GLOBAL scope, e.g. created hitograms aren't erased...
void plot_HF(TString  inputfile="simevent_HF.root",
	     TString outputfile="HF_histo.root",
	     Int_t drawmode = 2,
             TString    reffile="../data/HF_ref.root")
{
  // Option to no-action(0)/draw(1)/save(2) (default = 0) histograms in gif.
  //int doDraw = 0;
   int doDraw = drawmode;

  char * treename = "Events";        //The Title of Tree.
  
  delete gROOT->GetListOfFiles()->FindObject(inputfile);

  TFile * myf  = new TFile(inputfile);
  
  TTree * tree = dynamic_cast<TTree*>(myf->Get("Events"));
  assert(tree != 0);

  TBranch * branchLayer = tree->GetBranch("PHcalValidInfoLayer_g4SimHits_HcalInfoLayer_CaloTest.obj");
  assert(branchLayer != 0);

  TBranch * branchNxN = tree->GetBranch("PHcalValidInfoNxN_g4SimHits_HcalInfoNxN_CaloTest.obj");
  assert(branchNxN != 0);

  TBranch * branchJets = tree->GetBranch( "PHcalValidInfoJets_g4SimHits_HcalInfoJets_CaloTest.obj");  assert(branchJets != 0);

  // Just number of entries (same for all branches)
  int  nent = branchLayer->GetEntries();
  cout << "Entries branchLayer : " << nent << endl;
  nent = branchJets->GetEntries();
  cout << "Entries branchJets  : " << nent << endl;
  nent = branchNxN->GetEntries();
  cout << "Entries branchNxN   : " << nent << endl;

  // Variables from branches
  PHcalValidInfoJets infoJets;
  branchJets->SetAddress( &infoJets); 
  PHcalValidInfoLayer infoLayer;
  branchLayer->SetAddress( &infoLayer); 
  PHcalValidInfoNxN infoNxN;
  branchNxN->SetAddress( &infoNxN); 
  
  //***************************************************************************
  // Histo titles-labels

  const int Nhist1     = 20, Nhist2 = 1;  // N simple and N combined histos
  const int Nhist1spec =  5;              // N special out of Nsimple total 

  TH1F *h;                              // just a pointer
  TH1F *h1[Nhist1];
  TH2F *h2g;                    // +  eta-phi grid -related for all depthes
  
  char *label1[Nhist1];
  char *label2g;
  

  // simple histos  
  label1[0]  = &"rJetHits.gif";
  label1[1]  = &"tJetHits.gif";
  label1[2]  = &"eJetHits.gif";
  label1[3]  = &"ecalJet.gif";
  label1[4]  = &"hcalJet.gif";
  label1[5]  = &"etotJet.gif";
  label1[6]  = &"jetE.gif";
  label1[7]  = &"jetEta.gif";
  label1[8]  = &"jetPhi.gif";
  label1[9]  = &"etaHits.gif";          
  label1[10] = &"phiHits.gif";
  label1[11] = &"eHits.gif";
  label1[12] = &"tHits.gif";
  label1[13] = &"eEcalHF.gif";
  label1[14] = &"eHcalHF.gif";

  // special
  label1[15] = &"tHits_60ns.gif";   
  label1[16] = &"tHits_eweighted.gif"; 
  label1[17] = &"nHits_HF.gif";
  label1[18] = &"elongHF.gif";
  label1[19] = &"eshortHF.gif";

  label2g    = &"Eta-phi_grid_all_depths.gif";


  //***************************************************************************
  //...Book histograms 

  for (Int_t i = 0; i < Nhist1-Nhist1spec; i++) {
    char hname[3]; 
    sprintf(hname,"h%d",i);

    if(i == 4 || i == 7 || i == 8 ) {
      if(i == 7) h1[i] = new TH1F(hname,label1[i],100,-5.,5.);   
      if(i == 8) h1[i] = new TH1F(hname,label1[i],72,-3.1415926,3.1415926);   
      if(i == 4) h1[i] = new TH1F(hname,label1[i],30,0.,150.);  
    }
    else { 
      h1[i] = new TH1F(hname,label1[i],100,1.,0.);  
    }

//.........这里部分代码省略.........
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:101,代码来源:plot_HF.C

示例5: plot_HE

// Commands executed in a GLOBAL scope, e.g. created hitograms aren't erased...
void plot_HE(TString  inputfile="simevent_HE.root",
	     TString outputfile="HE_histo.root",
	     Int_t drawmode = 2,
             TString    reffile="../data/HE_ref.root"){
 
  // Option to no-action(0)/draw(1)/save(2) (default = 0) histograms in gif.
  //int doDraw = 0; 
  int doDraw = drawmode;

  char * treename = "Events";        //The Title of Tree.
  
  delete gROOT->GetListOfFiles()->FindObject(inputfile);

  TFile * myf  = new TFile(inputfile);
  
  TTree * tree = dynamic_cast<TTree*>(myf->Get("Events"));
  assert(tree != 0);

  TBranch * branchLayer = tree->GetBranch("PHcalValidInfoLayer_g4SimHits_HcalInfoLayer_CaloTest.obj");
  assert(branchLayer != 0);

  TBranch * branchNxN = tree->GetBranch("PHcalValidInfoNxN_g4SimHits_HcalInfoNxN_CaloTest.obj");
  assert(branchNxN != 0);

  TBranch * branchJets = tree->GetBranch( "PHcalValidInfoJets_g4SimHits_HcalInfoJets_CaloTest.obj");  assert(branchJets != 0);

  // Just number of entries (same for all branches)
  int  nent = branchLayer->GetEntries();
  cout << "Entries branchLayer : " << nent << endl;
  nent = branchJets->GetEntries();
  cout << "Entries branchJets  : " << nent << endl;
  nent = branchNxN->GetEntries();
  cout << "Entries branchNxN   : " << nent << endl;

  // Variables from branches
  PHcalValidInfoJets infoJets;
  branchJets->SetAddress( &infoJets); 
  PHcalValidInfoLayer infoLayer;
  branchLayer->SetAddress( &infoLayer); 
  PHcalValidInfoNxN infoNxN;
  branchNxN->SetAddress( &infoNxN); 
  
  //***************************************************************************
  // Histo titles-labels

  const int Nhist1     = 47, Nhist2 = 1;  // N simple and N combined histos
  const int Nhist1spec =  7;              // N special out of Nsimple total 
  const int nLayersMAX = 20;
  const int nDepthsMAX =  5;

  TH1F *h;                              // just a pointer
  TH1F *h1[Nhist1];
  TH1F *h1l[nLayersMAX];                // + all scint. layers separately
  TH1F *h1d[nDepthsMAX];                // + all depths  

  TH2F *h2[Nhist2];
  TH2F *h2g[5];         // +  eta-phi grid -related for all depthes
  
  char *label1[Nhist1], *label2[Nhist2], *label1l[nLayersMAX ];
  char *label1d[nDepthsMAX], *label2g[5];
  

  // simple histos  
  label1[0]  = &"rJetHits.gif";
  label1[1]  = &"tJetHits.gif";
  label1[2]  = &"eJetHits.gif";
  label1[3]  = &"ecalJet.gif";
  label1[4]  = &"hcalJet.gif";
  label1[5]  = &"hoJet.gif";
  label1[6]  = &"etotJet.gif";
  label1[7]  = &"detaJet.gif";
  label1[8]  = &"dphiJet.gif";
  label1[9]  = &"drJet.gif";
  label1[10] = &"jetE.gif";
  label1[11] = &"jetEta.gif";
  label1[12] = &"jetPhi.gif";
  label1[13] = &"dijetM.gif";
  label1[14] = &"ecalNxNr.gif";
  label1[15] = &"hcalNxNr.gif";
  label1[16] = &"hoNxNr.gif";
  label1[17] = &"etotNxNr.gif";
  label1[18] = &"ecalNxN.gif";
  label1[19] = &"hcalNxN.gif";
  label1[20] = &"hoNxN.gif";
  label1[21] = &"etotNxN.gif";
  label1[22] = &"layerHits.gif";
  label1[23] = &"etaHits.gif";          
  label1[24] = &"phiHits.gif";
  label1[25] = &"eHits.gif";
  label1[26] = &"tHits.gif";
  label1[27] = &"idHits.gif";
  label1[28] = &"jitterHits.gif";
  label1[29] = &"eIxI.gif";
  label1[30] = &"tIxI.gif";
  label1[31] = &"eLayer.gif";
  label1[32] = &"eDepth.gif";
  label1[33] = &"eHO.gif";
  label1[34] = &"eHBHE.gif";
  label1[35] = &"elongHF.gif";
//.........这里部分代码省略.........
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:101,代码来源:plot_HE.C

示例6: calibraPlastico

void calibraPlastico(char* filename, int channel=4) {

	FILE *outfile[2];
	outfile[0] = fopen("Chi2_511","w");
	outfile[1] = fopen("Chi2_1275","w");
	Int_t			number_of_loop=0;


	Int_t i, j, k, i_sm, rsen[2];
	Float_t r, alpha, energia;
	Int_t b_altezza;
			
	// energies
	Float_t	E_peak[NUMENERGIES];
	Float_t	E_compton[NUMENERGIES];
	E_peak[0] = 511.;
	E_peak[1] = 1275.;
	for (i=0; i<NUMENERGIES; i++) {
		E_compton[i] = 2*E_peak[i]*E_peak[i]/(511+2*E_peak[i]);
		printf("E_compton[%d] = %f;\n",i,E_compton[i]);
	}

  TTimer  *timer = new TTimer("gSystem->ProcessEvents();", 50, kFALSE);
	TCanvas *c0 = new TCanvas("c0");
	c0->cd();

	h_ideal = new TH1F("h_ideal","Compton ideale",NBINS,0,MAXHISTONRG);
	// check file existance
	f_smearings = new TFile("smearings.root","UPDATE");
	// check smearing samples existance
	for(i=0; i<NUMENERGIES; i++) {
		sprintf(smoothName,"smooth_%.1f_%d;1",E_peak[i],NSMEARINGS-2); 
		if (!f_smearings->Get(smoothName)) {
			cout << smoothName << " " << f_smearings->FindObject(smoothName) << endl;
			// smearing for that energy do not exist
			printf("Non esistono.\n");
			// ideal compton histogram
			for (j=0; j<NBINS; j++) {
				if (j>h_ideal->FindBin(50) && j<h_ideal->FindBin(E_compton[i])) {
					r = h_ideal->GetBinCenter(j)/E_peak[i];
					alpha = E_peak[i]/511.0;
					energia = KN_NORM * (2+r*r/(alpha*alpha*(1-r)*(1-r))+r/(1-r) * (r-2/alpha));
					h_ideal->SetBinContent(j,energia);
				} else { h_ideal->SetBinContent(j,0); }
			}
			h_ideal->Draw();
      c0->Update();
      timer->TurnOn();
      timer->Reset();
      timer->TurnOff();
			// creazione spettri smussati
			for (i_sm=1; i_sm<NSMEARINGS; i_sm++) {
				sprintf(smoothName,"smooth_%.1f_%d",E_peak[i],i_sm); 
				printf("Creo '%s': ",smoothName);
				h_smooth = new TH1F(smoothName,"Smooth",NBINS,0,MAXHISTONRG); // istogramma in energia
				for (j=1; j<h_ideal->FindBin(E_compton[i]); j++) {
					b_altezza = h_ideal->GetBinContent(j);
					for (k=1; k<b_altezza; k++){ h_smooth->Fill(gRandom->Gaus(h_ideal->GetBinCenter(j),i_sm)); } printf(".");
				} printf("\n");
				h_smooth->Write();
			}
		}
	}
	// ok, we've got the smearings!	

	f_smearings->Close();
	f_smearings = new TFile("smearings.root","READ");


	// ----------------------------------
	// retrieving "raw" histogram
	// ----------------------------------
	TFile *infile = new TFile(filename);
	TTree *tree= (TTree*)infile->Get("acq_tree_0");
	TBranch *branch = tree->GetBranch(Form("acq_ch%d",channel));
	branch->SetAddress(&inc_data.timetag);	

	TH1F *h_raw = new TH1F("h_raw","Acquisizione",NBINS,0,MAXHISTOCHN);
	UInt_t toentry=branch->GetEntries();
	printf("getHistoFromFile: There are %d entries in the branch\n",toentry);
	for(i=0; i<toentry; i++) {
		branch->GetEntry(i);
		h_raw->Fill(inc_data.qlong);
	}

  h_raw->Draw();
    
	TSpectrum	*s = new TSpectrum(10);
	Int_t		e, nPeaks, bTemp, bFirstPeak = 9999;
	Float_t	*xPeaks;
    
	// trovo il primo picco
	nPeaks = s->Search(h_raw->Rebin(2, "h_raw_rebinned"));
	if (nPeaks>0) {
		xPeaks = s->GetPositionX();
		// loop sui picchi per trovare il primo
		for (i=0;i<nPeaks;i++) {
			bTemp = h_raw->GetXaxis()->FindBin(xPeaks[i]);
			if (bTemp<bFirstPeak) { bFirstPeak = bTemp; }
		}
//.........这里部分代码省略.........
开发者ID:Clostry,项目名称:analisi,代码行数:101,代码来源:calibraPlastico.C

示例7: 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);
}
开发者ID:vvolkl,项目名称:DD4hep,代码行数:32,代码来源:DDG4EventHandler.cpp


注:本文中的TBranch::GetEntries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。