本文整理汇总了C++中TH1F::GetEntries方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::GetEntries方法的具体用法?C++ TH1F::GetEntries怎么用?C++ TH1F::GetEntries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::GetEntries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testTThreadedObjectAutoMemManagement
void testTThreadedObjectAutoMemManagement() {
ROOT::EnableThreadSafety();
const auto filename = "testTThreadedObjectAutoMemManagement.root";
const auto nentries = 5000;
{
TFile f(filename,"RECREATE");
ROOT::TThreadedObject<TH1F> h("h","h",64,-2,2);
auto fillh = [&h](){
h->FillRandom("gaus",nentries);
};
auto t1 = std::thread(fillh);
auto t2 = std::thread(fillh);
fillh();
t1.join();
t2.join();
auto mh = h.Merge();
mh->Write();
}
// Check content
TFile f(filename);
TH1F* h;
f.GetObject("h",h);
if (!h) {
std::cerr << "Cannot find merged histo on disk!\n";
return 1;
}
if (nentries*3 != h->GetEntries()) {
std::cerr << "Wrong number of entries: " << h->GetEntries() << "!\n";
return 1;
}
return 0;
}
示例2: CheckEHF
void CheckEHF()
{
TH1F * HDat;
TH1F * HDatnoPUAft;
TH1F * HDatnoPUBef;
// TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root");
TFile *fzee = new TFile("ZDiffOutputfile_Data2011_noPU.root");
// TFile *fzee = new TFile("ZDiffOutputfile.root");
HDat = (TH1F*)fzee->Get("NVTX1_minEHFZoom_DATA10");
HDatnoPUAft = (TH1F*)fzee->Get("NVTX1noPUAft_minEHFZoom_DATA10");
HDatnoPUBef = (TH1F*)fzee->Get("NVTX1noPUBef_minEHFZoom_DATA10");
HDat->Scale(1./HDat->GetEntries());
HDatnoPUAft->Add(HDatnoPUBef);
HDatnoPUAft->Scale(1./HDatnoPUAft->GetEntries());
HDatnoPUBef->Scale(1./HDatnoPUBef->GetEntries());
HDatnoPUAft->SetMinimum(0.);
NHSetMarker(HDatnoPUAft,2,20,0.8);
NHSetLine(HDatnoPUAft,2,1,1.);
HDatnoPUAft->Draw("E1");
HDatnoPUAft->SetTitle("2011 Z->ee Data, minHF Energy");
NSetTitle(HDatnoPUAft,"HF Energy [GeV]", "Fraction");
NHSetMarker(HDatnoPUBef,6,20,0.8);
NHSetLine(HDatnoPUBef,6,1,1.);
// HDatnoPUBef->Draw("SAMEP");
NHSetMarker(HDat,4,20,0.8);
NHSetLine(HDat,1,1,1.);
HDat->Draw("SAMEP");
TLegend *legend = new TLegend(0.6,0.1,0.75,0.4);
legend->SetTextFont(72);
legend->SetTextSize(0.04);
legend->SetBorderSize(0);
legend->AddEntry(HDatnoPUBef,"No PU before or after","p");
// legend->AddEntry(HDatnoPUBef,"No PU before","p");
// legend->AddEntry(HDatnoPUAft,"No PU after","p");
legend->AddEntry(HDat,"PU before && after","p");
legend->Draw();
// NHSetLine(HDatnoPUBef,3,2,1.);
// HDatnoPUBef->Draw("SAME HIST");
}
示例3: scale
//testing how the TH1::Integral() values change when a hist is scaled
void scale()
{
gSystem->Load("../RootTools/CommonTools.C.so");
gStyle->SetOptStat("nemouri");
TH1F *h = new TH1F("H1","Test Integral",100,0,10);
h->Fill (1);
h->Fill (1);
h->Fill (1);
h->Fill (1);
//TH1F *h2 = new TH1F("H2","Test Integral copy",100,0,1);
//h->FillRandom("gaus",10000);
//h2->FillRandom("gaus",10000);
// std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", "
// << h->GetEntries() << ", " << h->Integral("width") << std::endl;
//h = (TH1F*) MakeVariableBinHist(h, 0, 0.2, 0.6, 0.8, 1, 0.1, 0.2, 0.2, 0.2);
//std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", "
// << h->GetEntries() << ", " << h->Integral("width") << std::endl;
new TCanvas();
h->Draw();
//new TCanvas();
//h2->Draw();
//h->Scale(1,"width"); //this replaces the loop below
/*
for (int bin = 1; bin <= h->GetNbinsX(); ++bin)
{
const double val = h->GetBinContent(bin);
const double err = h->GetBinError(bin);
const double width = h->GetBinWidth(bin);
h->SetBinContent(bin,val/width);
h->SetBinError(bin,err/width);
}
*/
//h->DrawClone("E");
h->Print();
std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", "
<< h->GetEntries() << ", " << h->Integral("width") << std::endl;
//h->Scale(10);
h->Scale(10/(double)h->Integral());
//h_copy->Scale(h2_copy->Integral()/(double) h2->Integral());
//h_copy->Draw();
std::cout << "after scaling to " << 10 << std::endl;
h->Print();
std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", "
<< h->GetEntries() << ", " << h->Integral("width") << std::endl;
};
示例4: TGraphErrors
TGraph *draw_tof(TDirectory *d, const char *opt, Double_t *intg, Double_t *tof)
{
static Int_t markercolor = 0;
markercolor ++;
TParameter<Double_t> *p_mpv_t = (TParameter<Double_t>*)d->Get("p_mpv_t");
TParameter<Double_t> *p_intg_t_axyt = (TParameter<Double_t>*)d->Get("p_intg_t_axyt");
Double_t mpv_t = p_mpv_t->GetVal();
Double_t intg_t_axyt = p_intg_t_axyt->GetVal();
*tof = mpv_t;
*intg = intg_t_axyt;
TH1F *htof = (TH1F*)d->Get("htof");
Double_t err_t = TMath::Sqrt(htof->GetEntries());
cout << " T "
<< TString::Format("%10.2f", mpv_t) << " "
<< TString::Format("%10.2f", intg_t_axyt) << endl;
gStyle->SetMarkerColor(markercolor);
gStyle->SetLineColor(markercolor);
gStyle->SetMarkerStyle(20);
const Int_t n_t = 1;
Double_t xt[] = { mpv_t };
Double_t xte[] = { 0 };
Double_t yte[] = { 0 };
Double_t yt_axyt[] = { intg_t_axyt };
TGraphErrors *gintg_t_axyt = new TGraphErrors(n_t, xt, yt_axyt, xte, yte);
gintg_t_axyt->Draw(opt);
return gintg_t_axyt;
}
示例5: norm
void norm (double total = 0)
{
double factor = m_XS / m_h_MWW->GetEntries () ;
if (total != 0) factor = m_XS / total ;
m_h_MWW->Scale (factor) ;
m_h_scale->Scale (factor) ;
}
示例6: getpdgs
TH1F * getpdgs(std::string const & dr, std::string const & we) {
TCanvas * canvas_temp = new TCanvas("temp");
tree->Draw((dr+">>h").c_str(), we.c_str());
TH1F * hist = (TH1F*)gDirectory->Get("h");
int const min = hist->GetBinLowEdge(hist->FindFirstBinAbove(0));
int const max = hist->GetBinLowEdge(hist->FindLastBinAbove(0)) +
hist->GetBinWidth(hist->FindLastBinAbove(0)) + 1;
int const binno = max - min;
delete canvas_temp;
delete hist;
canvas_temp = new TCanvas("temp");
tree->Draw(Form((dr+">>h(%d,%d,%d)").c_str(), binno, min, max), we.c_str());
ofile->cd();
delete canvas_temp;
TH1F * histb = (TH1F*)gDirectory->Get("h");
if(histb->GetEntries() == 0) {
delete histb;
return nullptr;
}
return histb;
}
示例7: mass_cut
TGraphAsymmErrors *MakeGraph(TTree *tree, std::vector<int> mass_vec, TString genFun, TString fitFun, TString varName, TString option="mean"){
// TMultiGraph *graph = new TMultiGraph();
TGraphAsymmErrors *graph = new TGraphAsymmErrors();
// TCanvas c_graph("c_graph","c_graph");
// c_graph.cd();
for(std::vector<int>::const_iterator mass_itr=mass_vec.begin();
mass_itr!=mass_vec.end();
mass_itr++){
// std::cout << *mass_itr << std::endl;
TString mass_string;
mass_string+=(*mass_itr);
// mass_string.Print();
TCut mass_cut("mass == "+mass_string);
// mass_cut.Print();
TCut cut=mass_cut;
cut+="genFun==\""+genFun+"\"";
cut+="fitFun==\""+fitFun+"\"";
#ifdef REMOVEBADFIT
cut+="mu>-15 && mu<15";
#endif
#ifdef REMOBELOWSIGMA
cut+="sigma_mu>1e-2";
#endif
cut.Print();
if(varName.CompareTo("mu")==0) tree->Draw(varName+">>hist(600,-15,15)",cut);
if(varName.CompareTo("bkgSig1fwhm/bkgTrue1fwhm")==0) tree->Draw(varName+">>hist(300,-5,5)",cut);
if(varName.CompareTo("bkgErrSig1fwhm/bkgTrue1fwhm")==0) tree->Draw(varName+">>hist(400,0.,2.)",cut);
if(varName.CompareTo("(bkgSig1fwhm-bkgTrue1fwhm)/bkgErrSig1fwhm")==0) tree->Draw(varName+">>hist(400,-3,3.)",cut);
if(varName.CompareTo("(bkgSig2fwhm-bkgTrue2fwhm)/bkgErrSig2fwhm")==0) tree->Draw(varName+">>hist(400,-3,3.)",cut);
if(varName.CompareTo("sigma_mu")==0) tree->Draw(varName+">>hist(400,0,20)",cut);
if(varName.CompareTo("(mu-muTruth)/sigma_mu")==0) tree->Draw(varName+">>hist(300,-3,3)",cut);
if(varName.CompareTo("(mu-muTruth)/bkgErrNormSig2fwhm")==0) tree->Draw(varName+">>hist(400,-8,8)",cut);
if(varName.CompareTo("bkgErrNormSig2fwhm")==0) tree->Draw(varName+">>hist(200,0.,10.)",cut);
TH1F *hist = (TH1F *) gROOT->FindObject("hist");
if(hist==NULL || hist->GetEntries()==0){
std::cerr << "no entries for cut: " << std::endl;
cut.Print();
} else AddPoint(graph, *mass_itr, hist, genFun, fitFun, option);
// graph->SetMinimum(-100);
// graph->SetMaximum(100);
delete hist;
}
// std::cout << "Np = " << i_point << std::endl;
// }
// c.cd();
return graph;
}
示例8: plotEvtSelEff
void plotEvtSelEff() {
gStyle->SetOptStat(0);
TFile *f = new TFile("../test/ROOTupleMC_HighPurity.root");
TH1F *hNSD = (TH1F*) f->Get("preTrgAna/hGenMultNSD");
TH1F *hNSDtrg = (TH1F*) f->Get("postTrgAna/hGenMultNSD");
TH1F *hNSDevt = (TH1F*) f->Get("postEvtSelAna/hGenMultNSD");
TH1F *hNSDvtx = (TH1F*) f->Get("postVtxAna/hGenMultNSD");
TH1F *hNSDtrkvtx = (TH1F*) f->Get("postTrkVtxAna/hGenMultNSD");
TGraphAsymmErrors *gNSDtrg = new TGraphAsymmErrors();
TGraphAsymmErrors *gNSDevt = new TGraphAsymmErrors();
TGraphAsymmErrors *gNSDvtx = new TGraphAsymmErrors();
TGraphAsymmErrors *gNSDtrkvtx = new TGraphAsymmErrors();
gNSDtrg->BayesDivide(hNSDtrg,hNSD);
gNSDevt->BayesDivide(hNSDevt,hNSD);
gNSDvtx->BayesDivide(hNSDvtx,hNSD);
gNSDtrkvtx->BayesDivide(hNSDtrkvtx,hNSD);
TH1F *dum1 = new TH1F("dum1",";Charged-particle multiplicity;Fraction of events",100,0,100);
dum1->SetMaximum(0.05);
dum1->GetYaxis()->SetTitleOffset(1.8);
TH1F *dum2 = new TH1F("dum2",";Charged-particle multiplicity;Selection efficiency",100,0,60);
TCanvas *c1 = new TCanvas("c1","Event Selection",900,500);
c1->Divide(2,1);
c1->cd(1);
dum1->Draw();
hNSDtrkvtx->Sumw2();
hNSDtrkvtx->Scale(1./hNSDtrkvtx->GetEntries());
hNSDtrkvtx->SetMarkerStyle(24);
hNSDtrkvtx->Draw("pzsame");
hNSDvtx->Sumw2();
hNSDvtx->Scale(1./hNSDvtx->GetEntries());
hNSDvtx->SetMarkerStyle(20);
hNSDvtx->Draw("pzsame");
c1->cd(2);
dum2->Draw();
gNSDtrkvtx->SetMarkerStyle(24);
gNSDtrkvtx->Draw("pzsame");
gNSDvtx->SetMarkerStyle(20);
gNSDvtx->Draw("pzsame");
}
示例9: next
std::vector<GaussFitInfo> saveGaussians(TH2F* hp, TList* l, TString savedir)
{
// Each xbin of the TH2F can be viewed as a 1D histogram of the y info.
// Fit the histograms in each xbin with a gaussian and save them into a tlist.
// Save the histograms as png files as well.
// Get the title info from the mother histogram.
TString title = hp->GetTitle();
// This is only used to align the statboxes.
DiMuPlottingSystem* dps = new DiMuPlottingSystem();
// Do the fitting and gather the histos into the tlist.
std::vector<GaussFitInfo> gfis = std::vector<GaussFitInfo>();
gfis = dps->plotVarVsGaussFit(hp, l, 1);
TCanvas* c = new TCanvas();
c->SetGridx(kTRUE);
c->SetGridy(kTRUE);
// Iterate through the list and save the histos as pictures.
TIter next(l);
TObject* obj = 0;
int i = 0;
int total = 0;
while( (obj = next()) )
{
TH1F* h = (TH1F*) obj;
h->SetName(Form("%s_%d_%s", title.Data(), i, hp->GetName()));
c->cd();
h->Draw("");
total+=h->GetEntries();
std::cout << " " << i << " num: "<< h->GetEntries() << std::endl;
dps->arrangeStatBox(c);
c->Print(savedir+Form("%s_%s_gauss_bins_%d.png", hp->GetName(), title.Data(), i));
// c->Print(savedir+Form("%s_%s_gauss_bins.gif+500", hp->GetName(), title.Data()));
i++;
}
c->cd();
// c->Print(savedir+Form("%s_%s_gauss_bins.gif++", hp->GetName(), title.Data()));
std::cout << "nentries total: " << total << std::endl;
delete c;
// delete dps;
return gfis;
}
示例10: setGraphics
TH1F * getTH1Histo(TChain *Events, const char * name, const string varToPlot, unsigned int nBins, double fMin, double fMax, TCut cut) {
TH1F * h = new TH1F(name, name, nBins, fMin, fMax);
// Events->Draw("zGoldenMass");
Events->Project(name, varToPlot.c_str(), cut );
cout<<"Number of entrie for "<< name << " : "<< h->GetEntries()<<endl;
setGraphics(h);
return h;
}
示例11: GetEntries
int GetEntries(const char *var,TCut cut)
{
TTree *t=(TTree*) gROOT->FindObject("t");
TH1F *htemp = (TH1F*) gROOT->FindObject("htemp");
if(htemp) delete htemp;
t->Draw(Form("%s>>htemp",var),cut);
htemp = (TH1F*) gROOT->FindObject("htemp");
//cout<<"Number of entries = "<<htemp->GetEntries()<<endl;
return htemp->GetEntries();
}
示例12: make_hist
void make_hist(TString type, TString physics_type, TString sample_str){
const int num_samples = 12;
int sample = atoi(sample_str);
TFile *file = new TFile("../application/v13/main_tmva_v13_Data_4_"+physics_type+type+".root");
TTree *tree = (TTree*)file->Get("tree");
Int_t events_generated;
TH1F *countPos;
TH1F *countNeg;
if (sample!=11){
countPos = (TH1F*)file->Get("CountPosWeight");
countNeg = (TH1F*)file->Get("CountNegWeight");
events_generated = countPos->GetEntries()-countNeg->GetEntries();
} else events_generated = 1;
/// TString file_names[nfiles] = {"QCD_HT100to200", "QCD_HT200to300", "QCD_HT300to500","QCD_HT500to700", "QCD_HT700to1000", "QCD_HT1000to1500", "QCD_HT1500to2000", "QCD_HT2000toInf", "VBFHToBB_M-125_13TeV_powheg", "VBFHToBB_M-130_13TeV_powheg", "VBFHToBB_M125_13TeV_amcatnlo","data"};
Float_t xsec[num_samples] = { 2.75E07, 1.74E06, 3.67E05, 2.94E04, 6.52E03,1.064E03, 121.5, 2.54E01,2.16 ,1.96,2.16,1./15.47};
float lumi=10000; //in pb
float BDT;
float genweight=1.;
tree->SetBranchAddress("BDT_VBF",&BDT);
tree->SetBranchAddress("genWeight",&genweight);
TH1F *BDT_output = new TH1F("BDT_output","",400,-1.,1.);
int nentries = tree->GetEntries();
for (int entry=0;entry<nentries;entry++){
tree->GetEntry(entry);
genweight=TMath::Sign(1.,genweight);
genweight/=events_generated/(xsec[sample]*lumi); //10 fb^-1 normalization
BDT_output->Fill(BDT,genweight);
}
TFile *f_output = new TFile("output_hist/v13/BDT_hist_"+physics_type+type+".root","recreate");
f_output->cd();
BDT_output->Write();
f_output->Write();
}
示例13: scaled
TH1F* scaled(const char *dirname, TString file, TString tag_one, TString h_entries, TString hist)
{
TFile* f1 = new TFile(dirname+file+".root","READ");
TH1F* h1 = (TH1F*)f1->Get(tag_one+"/"+tag_one+"_"+hist);
TH1F* entries = (TH1F*)f1->Get(tag_one+"/"+tag_one+"_"+h_entries);
//cout<<entries->GetEntries()<<endl;
h1->Scale(1/entries->GetEntries());
return h1;
}
示例14: getBeamLoc
void AnalysisBase::getBeamLoc(){
TH1F* haStrip = new TH1F("haStrip","Strip # of cluster with track",512,0.0,512);
//TH1F* hb = new TH1F("hb","Strip # of cluster with track",512,0.0,512);
Long64_t nentries = fChain->GetEntriesFast();
//cout << "nentries " << nentries << endl;
float lo = 0, hi = 0;
int istrip;
Long64_t nbytes = 0, nb = 0;
std::cout << "======================================= " << std::endl;
std::cout << "getBeamLoc(): Determining Beam Position " << nentries << std::endl;
std::cout << "======================================= " << std::endl;
for (Long64_t jentry=0; jentry<max(50000,(int)nentries);jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
//cout << clusterNumberPerEvent << endl;
for(int j=0; j<min((int)clusterNumberPerEvent,10); j++){
if(polarity*clustersCharge[j] < kClusterChargeMin) continue;
int iChan = clustersSeedPosition[j];
if(polarity*clustersCharge[j]<4*noise[iChan]) continue;
istrip = clustersSeedPosition[j];
if(badStrips[istrip]==0) continue; // exclude bad strips
if(clustersPosition[j]>0.1&&clustersSize[j]==1) haStrip->Fill(clustersPosition[j]);
if(clustersPosition[j]>0.1&&clustersSize[j]==2) haStrip->Fill(clustersPosition[j]);
}
}
int num = haStrip->GetEntries();
for(int i=0; i<1000; i++){
//cout << "num is " << num << endl;
if(num < 1000) continue;
break;
}
if(num < 1000){
std::cout << "ERROR: Something wrong here, insufficient entries in GetBeamLoc(), nEntries = " << num << std::endl;
//exit(1);
}
//haStrip->Draw();
getBeamLocation(haStrip,lo,hi);
iLo = lo;
iHi = hi;
std::cout << "====> Beam is between strips " << iLo << " -- " << iHi << std::endl;
delete haStrip;
return;
}
示例15: test
void test(int nhit1)
{
TH1F *h = (TH1F*) f->FindObjectAny(Form("dNdEtaHits1_%02d",nhit1));
TH1F *g = new TH1F("toymc","",100,-3,3);
for (int i=0;i<h->GetEntries();i++){
g->Fill(h->GetRandom());
}
g->SetLineColor(2);
h->Draw();
g->Draw("same");
}