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


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

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


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

示例1: turn2Dinto1Ds

void turn2Dinto1Ds(char* myf, char *myh, char* myfo)
{
   
  TFile* mytfile = new TFile(myf);
  TH2* my2dh = (TH2*) mytfile->Get(myh);
  my2dh->SetDirectory(0);
  TFile* myoftile = new TFile(myfo,"RECREATE");
  myoftile->cd();
  //std::vector<TH1*> vechist;
  Int_t ybins = my2dh->GetNbinsX();
  std::cout << " Full bins " << ybins << std::endl;
  std::cout << " Entries " << my2dh->GetEntries();
   
  for (Int_t Ybin = 1; Ybin <= ybins; ++Ybin)
    {
      TH1* onehist = (TH1*) my2dh->ProjectionY(Form("rap%d",Ybin), Ybin,Ybin,"");
      std::cout << " Entries: " << onehist->GetEntries() << std::endl;
     
      onehist->Write();
     
    }
   
  myoftile->Write();
  myoftile->Close();
  mytfile->Close();
   
   
}
开发者ID:UMN-CMS,项目名称:ZShape_Analysis,代码行数:28,代码来源:turn2Dinto1Ds.C

示例2: getPlotData

  void getPlotData() {
    TH1 * h = (TH1*) m_file->Get(m_direc.c_str());

    for (int i=0; i<h->GetXaxis()->GetNbins(); i++) {
      m_xs.push_back(h->GetXaxis()->GetBinCenter(i));
      m_ys.push_back(h->GetBinContent(i));
    }

    m_plot->m_xAxisTitle = std::string(h->GetXaxis()->GetTitle());
    m_plot->m_yAxisTitle = std::string(h->GetYaxis()->GetTitle());
    m_plot->m_title = std::string(h->GetTitle());

    std::stringstream ssN, ssMu, ssSig, ssUF, ssOF;
    ssN << std::setprecision(4) << h->GetEntries();
    ssMu << std::setprecision(4) << h->GetMean();
    ssSig << std::setprecision(4) << h->GetRMS();
    ssUF << std::setprecision(4) << h->GetBinContent(0);
    ssOF << std::setprecision(4) << h->GetBinContent(h->GetNbinsX() + 1);

    m_statsTitles.push_back("N:");
    m_statsTitles.push_back("mu:");
    m_statsTitles.push_back("sig:");
    m_statsTitles.push_back("UF:");
    m_statsTitles.push_back("OF:");

    m_statsValues.push_back(ssN.str());
    m_statsValues.push_back(ssMu.str());
    m_statsValues.push_back(ssSig.str());
    m_statsValues.push_back(ssUF.str());
    m_statsValues.push_back(ssOF.str());
  }
开发者ID:suvayu,项目名称:LHCbVeloView,代码行数:31,代码来源:VKeplerContent.cpp

示例3: hsimple

TSeqCollection *GetCollection()
{
   TObject *obj;
#ifndef ClingWorkAroundMissingDynamicScope
# define ClingWorkAroundMissingDynamicScope
#endif
#ifdef ClingWorkAroundMissingDynamicScope
   f = (TFile*)gROOT->ProcessLine("hsimple(1);");
#else
   f = hsimple(1);
#endif

   gROOT->cd();
   TList *l0 = new TList();
   TList *l01 = new TList();
   TH1 *hpx = (TH1*)f->Get("hpx");
   printf("Adding hpx: %d entries\n", (int)hpx->GetEntries());
   l01->Add(hpx);
   TH1 *hpxpy = (TH1*)f->Get("hpxpy");
   l01->Add(hpxpy);
   TH1 *hprof = (TH1*)f->Get("hprof");
   l0->Add(hprof);
   l0->Add(l01);
   return l0;
}
开发者ID:iahmad-khan,项目名称:root,代码行数:25,代码来源:testMergeCont.C

示例4: DrawStatBox

void DrawStatBox(TObject** Histos, std::vector<char*> legend, bool Mean, double X, double Y, double W, double H)
{
   int    N             = legend.size();
   char   buffer[255];

   if(Mean)H*=3;
   for(int i=0;i<N;i++){
           TPaveText* stat = new TPaveText(X,Y-(i*H), X+W, Y-(i+1)*H, "NDC");
	   TH1* Histo = (TH1*)Histos[i];
           sprintf(buffer,"Entries : %i\n",(int)Histo->GetEntries());
           stat->AddText(buffer);

           if(Mean){
           sprintf(buffer,"Mean    : %6.2f\n",Histo->GetMean());
           stat->AddText(buffer);

           sprintf(buffer,"RMS     : %6.2f\n",Histo->GetRMS());
           stat->AddText(buffer);
           }

           stat->SetFillColor(0);
           stat->SetLineColor(Color[i]);
           stat->SetTextColor(Color[i]);
           stat->SetBorderSize(0);
           stat->SetMargin(0.05);
           stat->SetTextAlign(12);
           stat->Draw();
   }
}
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:29,代码来源:GainPlot.C

示例5: get

// Extract and merge histograms in range [from, to) (to is not included)
//
TH1 *merge(const string &path, TFile **input, const int &from, const int &to,
        const bool &do_normalize = false)
{
    TH1 *result = 0;
    for(int i = from; to > i; ++i)
    {
        TH1 *hist = get(path, input[i], i);
        if (!hist)
        {
            cerr << "failed to extract: " << path << endl;

            continue;
        }

        if (!result)
            result = dynamic_cast<TH1 *>(hist->Clone());
        else
            result->Add(hist);
    }

    if (do_normalize
            && result
            && result->GetEntries())
    {
        result->Scale(1. / result->Integral());
    }

    return result;
}
开发者ID:PerilousApricot,项目名称:bsm_analyze,代码行数:31,代码来源:fig.C

示例6: PlotAndCheck

int PlotAndCheck(TTree *tree, TCanvas *c1, int index, const char *selection) 
{
   c1->cd(index);
   tree->Draw("fOffset*fX.fElements",selection);
   TH1 *href = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
   
   c1->cd(index+1);
   tree->Draw("mult", selection);
   TH1 *halias = (TH1*)gPad->GetListOfPrimitives()->FindObject("htemp");
   
   if ( href->GetEntries() != halias->GetEntries() 
       || fabs(href->GetMean()-halias->GetMean()) > 0.000001  ){
      fprintf(stdout, "For %s\n",selection);
      fprintf(stdout, "The direct histogram and the alias histogram are different!\n");
      fprintf(stdout, "Entries: %f vs %f\n",href->GetEntries(),halias->GetEntries());
      fprintf(stdout, "Mean   : %f vs %f\n",href->GetMean(),halias->GetMean());
   }
   return index+2;
}
开发者ID:asmagina1995,项目名称:roottest,代码行数:19,代码来源:runalias.C

示例7: AddHistsAt

//________________________________________________________
Int_t GFOverlay::AddHistsAt(const TObjArray &hists, const TObjArray &legends, Int_t layer,Int_t pos)
{
  // hists and legends must have same length, but might have gaps...
  // return number of hists found and added

  Int_t nHists = 0;
  for (Int_t iHist = 0; iHist < hists.GetEntriesFast(); ++iHist) {
    TH1 *hist = static_cast<TH1*>(hists[iHist]);
    if (!hist) continue;

    if (fNormalise && hist->GetEntries()) {
      hist->Scale(1./hist->GetEntries());
    }

    fHistMan->AddHistSame(hist, layer, pos, (legends[iHist] ? legends[iHist]->GetName() : 0));
    ++nHists;
  }

  return nHists;
}
开发者ID:ANSH0712,项目名称:cmssw,代码行数:21,代码来源:GFOverlay.C

示例8: fitfulllang

Double_t fitfulllang( char* hs ) {

  TH1 *h = (TH1*)gDirectory->Get(hs);

  if( h == NULL ){
    cout << hs << " does not exist\n";
    return 0;
  }

  double aa = h->GetEntries();//normalization

  // find peak:
  int ipk = h->GetMaximumBin();
  double xpk = h->GetBinCenter(ipk);
  double sm = xpk / 9; // sigma
  double ns = sm; // noise

  // fit range:
  int ib0 = ipk/2;
  int ib9 = h->GetNbinsX() - 1;

  double x0 = h->GetBinLowEdge(ib0);
  double x9 = h->GetBinLowEdge(ib9) + h->GetBinWidth(ib9);

  // create a TF1 with the range from x0 to x9 and 4 parameters
  TF1 *fitFcn = new TF1( "fitFcn", fitLandauGauss, x0, x9, 4 );

  fitFcn->SetParName( 0, "peak" );
  fitFcn->SetParName( 1, "sigma" );
  fitFcn->SetParName( 2, "area" );
  fitFcn->SetParName( 3, "smear" );

  fitFcn->SetNpx(500);
  fitFcn->SetLineWidth(4);
  fitFcn->SetLineColor(kMagenta);

  // set start values:
  fitFcn->SetParameter( 0, xpk ); // peak position, defined above
  fitFcn->SetParameter( 1, sm ); // width
  fitFcn->SetParameter( 2, aa ); // area
  fitFcn->SetParameter( 3, ns ); // noise

  h->Fit("fitFcn", "NQR", "ep" );// R = range from fitFcn
  return fitFcn->GetParameter(0);
}
开发者ID:schuetzepaul,项目名称:testbeam-analysis,代码行数:45,代码来源:tools.C

示例9: Save

void HistoProofMan::Save(){

  if(!fname[0])return;
  printf("HistoMan::Save ----> Saving %s\n",fname);
  TDirectory *dsave = gDirectory;
  TFile* pp=TFile::Open(fname,"RECREATE");
  pp->cd();
  hashtable<TH1*>::iterator it;
  for(it=hlist.begin();it!=hlist.end();it++) {
    TH1 *obj = it->second;
    if (obj && obj->GetEntries() > 0) obj->Write();
  }
  pp->Write();
  pp->Close();
  printf(" ..... done\n");
  if (dsave) dsave->cd();
  //  fdir->Purge();
  return;
}
开发者ID:krafczyk,项目名称:AMS,代码行数:19,代码来源:HistoProofMan.C

示例10: logStatisticsPar

void logStatisticsPar(std::ostream& out, RooDataSet *dataSet, RooRealVar *realVar, int nBins, double chi2, const RooArgList &variables)
{
    TH1 *histogram = dataSet->createHistogram(Form("h%s", dataSet->GetName()), *realVar, RooFit::Binning(nBins));
    
    // Create the TeX file
    out << "\\documentclass[10pt]{article}" << std::endl;
    out << "\\usepackage[usenames]{color} %used for font color" << std::endl;
    out << "\\usepackage{fontspec}" << std::endl;
    out << "\\usepackage{xunicode}" << std::endl;
    out << "\\usepackage{xltxtra}" << std::endl;
    out << "\\defaultfontfeatures{Scale=MatchLowercase}" << std::endl;
    out << "\\setromanfont[Mapping=tex-text]{Myriad Pro}" << std::endl;
    out << "\\setsansfont[Mapping=tex-text]{Myriad Pro}" << std::endl;
    out << "\\setmonofont{Monaco}" << std::endl;
    out << "\\begin{document}" << std::endl;
    out << "\\thispagestyle{empty}" << std::endl;
    out << "\\setlength{\\tabcolsep}{1ex}" << std::endl;
    out << "\\setlength{\\fboxsep}{0ex}" << std::endl;
    out << "{\\fontsize{7pt}{0.9em}\\selectfont" << std::endl;
    out << "\\framebox{\\begin{tabular*}{60pt}{[email protected]{\\extracolsep{\\fill}}r}" << std::endl;
    
    // This is the particular info for the histogram
    out << "Entries & " ;
    formatNumber(histogram->GetEntries(), out) << " \\\\" << std::endl;
    out << "Mean & " ;
    formatNumber(histogram->GetMean(), out) << " \\\\" << std::endl;
    out << "RMS & " ;
    formatNumber(histogram->GetRMS(), out) << " \\\\" << std::endl;
    if (chi2 > 0.0) {
        out << "Fit $\\chi^{2}$ & " ;
        formatNumber(chi2, out) << " \\\\" << std::endl;
    }
    RooRealVar *theVariable;
    for (int index = 0; index < variables.getSize(); index++) {
        theVariable = dynamic_cast<RooRealVar*>(variables.find(variables[index].GetName()));
        out << theVariable->GetTitle() << " & $\\textrm{" ;
        formatNumber(theVariable->getValV(), out) << "} \\pm \\textrm{" ;
        formatNumber(theVariable->getError(), out) << "}$ \\\\" << std::endl;
    }
    out << "\\end{tabular*}}}" << std::endl;
    out << "\\end{document}" << std::endl;
    histogram->Delete();
}
开发者ID:orduna,项目名称:f0Extras,代码行数:43,代码来源:logResults.cpp

示例11: rescaleBoundaryHists

void rescaleBoundaryHists(std::string infile, int numSamples=-1){

  TFile* f = new TFile(infile.c_str(), "UPDATE");
  TDirectory* dir = 0;

  TIter dir_it(f->GetListOfKeys());
  TKey* dir_k;
  while ((dir_k = (TKey *)dir_it())) {
    if (TString(dir_k->GetClassName()) != "TDirectoryFile") continue;
    std::string dir_name = std::string(dir_k->GetTitle());
    if(dir_name == "") continue;
    dir = (TDirectory*)dir_k->ReadObj();
    if(dir == 0) continue;
    TIter hist_it(dir->GetListOfKeys(), kIterBackward);
    TKey* hist_k;
    while ((hist_k = (TKey *)hist_it())) {
      std::string hist_name = (hist_k->GetTitle());
      if (hist_name.find("_HI") != std::string::npos || hist_name.find("_LOW") != std::string::npos || hist_name.find("h_n_mt2bins") != std::string::npos) {
        TH1* h = (TH1*)hist_k->ReadObj();
        if(numSamples==-1)
            h->Scale(1.0/h->GetEntries());
        else
            h->Scale(1.0/numSamples);
        dir->cd();
        h->Write("",TObject::kOverwrite);
      }
    }
  }

  delete dir;

  gDirectory->GetList()->Delete();
  
  f->Write("",TObject::kOverwrite);
  f->Close();
  delete f;

}
开发者ID:cmstas,项目名称:MT2Analysis,代码行数:38,代码来源:rescaleBoundaryHists.C

示例12: while

// Returns the RMS including 96% of the histogram entries, cutting the tails:
Double_t getRMS96(char* hs, double truncation=96.) {

  bool debug = false;

  TH1 *h = (TH1*)gDirectory->Get(hs);
  if( h == NULL ){ cout << hs << " does not exist\n"; return 0; }

  // Total entries:
  double integral = h->GetEntries();
  int maxbin = h->GetMaximumBin();
  if(debug) cout << "entries=" << integral << " maxbin=" << maxbin << endl;

  double subrange_integral = h->GetBinContent(maxbin);
  int bin = 0;
  while(subrange_integral < truncation/100*integral) {
    bin++;
    // Add one bin to the left:
    subrange_integral += h->GetBinContent(maxbin-bin);
    // Add one bin to the right:
    subrange_integral += h->GetBinContent(maxbin+bin);
    if(debug) cout << "subrange " << (maxbin-bin) << "-" << (maxbin+bin) << ": entries=" << subrange_integral << endl;
  }
  if(debug) cout << "subrange " << (maxbin-bin) << "-" << (maxbin+bin) << " now has " << subrange_integral << " entries, this is " << (100.0*subrange_integral)/integral << "%" << endl;

  // Correct by overshoot bin:
  subrange_integral -= h->GetBinContent(maxbin+bin);
  subrange_integral -= h->GetBinContent(maxbin-bin);
  bin--;

  int binlow = maxbin-bin;
  int binhigh = maxbin+bin;
  if(debug) cout << "subrange " << (maxbin-bin) << "-" << (maxbin+bin) << " now has " << subrange_integral << " entries, this is " << (100.0*subrange_integral)/integral << "%" << endl;

  h->GetXaxis()->SetRange(binlow,binhigh); //to restrict range to bins binlow to binhigh
  double rms96 = h->GetRMS(); //will return the RMS within the axis range

  return rms96;
}
开发者ID:schuetzepaul,项目名称:testbeam-analysis,代码行数:39,代码来源:tools.C

示例13: DoFit

void DoFit(TH2 *hist) {
   TChannel::DeleteAllChannels();
   TChannel::ReadCalFile("GrifCal.cal");
   printf("made %i channels.\n",TChannel::GetNumberOfChannels());
   TNucleus nuc("152eu");
   for(int x = 1; x <= 64; ++x) {
      printf(" x = %i\n",x);
      TH1 *p = GetProjectionY(hist,x);
      if(p->GetEntries() < 100)
         continue;
      TGraph* graph = autogain(p,&nuc);
      TChannel *chan = TChannel::GetChannelByNumber(x);
      if(!chan)
         continue;
      chan->DestroyCalibrations();
      chan->AddENGCoefficient(graph->GetFunction("pol1")->GetParameter(0));
      chan->AddENGCoefficient(graph->GetFunction("pol1")->GetParameter(1));
      chan->SetIntegration(125);
   }

   TChannel::WriteCalFile("NewGrifCal.cal");

}
开发者ID:atlaffoley,项目名称:GRSISort,代码行数:23,代码来源:autoeffic.C

示例14: cumulative

TCanvas* cumulative()
{
   TH1* h = new TH1D("h", "h", 100, -5., 5.);
   gRandom->SetSeed();
   h->FillRandom("gaus", 1u << 16);
   // get the cumulative of h
   TH1* hc = h->GetCumulative();
   // check that c has the "right" contents
   Double_t* integral = h->GetIntegral();
   for (Int_t i = 1; i <= hc->GetNbinsX(); ++i) {
      assert(std::abs(integral[i] * h->GetEntries() - hc->GetBinContent(i)) < 1e-7);
   }
   // draw histogram together with its cumulative distribution
   TCanvas* c = new TCanvas;
   c->Divide(1,2);
   c->cd(1);
   h->Draw();
   c->cd(2);
   hc->Draw();
   c->Update();

   return c;
}
开发者ID:digideskio,项目名称:root,代码行数:23,代码来源:cumulative.C

示例15: MergeMetHists


//.........这里部分代码省略.........
		TFolder *fold = (TFolder*) gDirectory->FindObjectAny("Ana");
		assert(fold != NULL && "folder null");
		TFolder *dir = (TFolder*) fold->FindObjectAny("MyJetFilter");
		assert(dir != NULL && "dir null");
		TFolder *dir2 = (TFolder*) dir->FindObjectAny("Hist");
		assert(dir2 != NULL && "Hist null");

		//TH1 *h = dynamic_cast<TH1*> (dir3->FindObjectAny(name.c_str()));
		//assert (h!=NULL && "hist null");
		//h->Draw();
		//return;


		for (unsigned int iPath = 0; iPath < vPaths.size(); ++iPath)
		{
			//std::cout << "iPath = " << iPath << std::endl;
			TFolder *dir3 = (TFolder*) dir2->FindObjectAny(vPaths.at(iPath).c_str());
			assert(dir3 != NULL && "data null");
			//f->cd();
			//gDirectory->pwd();
			//f->cd(vPaths.at(iPath).c_str());
			//gDirectory->pwd();
			//if (iPath<2) f->ls();
			//TH1 *hTemp = dynamic_cast<TH1*> (gDirectory->FindObjectAny(name.c_str()));
			std::stringstream histpath;
			histpath << vPaths.at(iPath) << name;
			//TFolder *ana = (TFolder*) gDirectory->FindObjectAny("Ana");
			//assert(ana !=NULL && "Ana folder not found");
			
			//std::cout << "histpath = " << histpath.str() << std::endl;
			TH1 *hTemp = dynamic_cast<TH1*> (dir3->FindObjectAny(name.c_str()));
			assert(hTemp != NULL && "object not found!");

			if (hTemp->GetEntries())	// this has to be done to avoid crashes when adding hists which some how have 'sum=nan' instead of 'sum=0' when they do not have any entries.
			{
				if (! vHist.at(iPath))
				{
					std::string name = hTemp->GetName() + std::string ("_Clone");
					vHist.at(iPath) = dynamic_cast<TH1*>(hTemp->Clone (name.c_str()));
					assert(vHist.at(iPath) != NULL && "Data hist cast failed");
					vHist.at(iPath)->SetDirectory(0);
				} else
				{
					vHist.at(iPath)->Add(hTemp);
				}
			}
		}

		delete f;

	}

/*	assert(vHist.size() == vPaths.size());
	for (int k=0; k < vHist.size(); ++k)
	{
		vHist.at(k)->Print();
	}
*/
	DoSystematics(vHist);
	
	hist_data = vHist.at(0);
	hist_bg = vHist.at(1);

/*	std::cout << "NORMALIZING BG TO DATA " << std::endl;
	double data_int = hist_data->Integral();
	double bg_int = hist_bg->Integral();
开发者ID:hkaushalya,项目名称:CDFPhoJets,代码行数:67,代码来源:MergeMetHists_DebugSyst.C


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