本文整理汇总了C++中TH1::GetNbinsX方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::GetNbinsX方法的具体用法?C++ TH1::GetNbinsX怎么用?C++ TH1::GetNbinsX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::GetNbinsX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetEffHist
// === FUNCTION ============================================================
// Name: TPlot::GetEffHist
// Description:
// ===========================================================================
TH1* TPlot::GetEffHist(std::string Eff, std::string det, std::string algo)
{
TH1* hNum = GetHist1D(listEff[Eff].first, det, algo);
TH1* hDem = GetHist1D(listEff[Eff].second, det, algo);
TH1* temp = (TH1*)hNum->Clone(Eff.c_str());
assert(hNum->GetNbinsX() == hDem->GetNbinsX());
for (int i = 0; i < hNum->GetNbinsX(); ++i)
{
double val = hNum->GetBinContent(i) / hDem->GetBinContent(i);
double valerr = val * sqrt( pow(hNum->GetBinError(i)/hNum->GetBinContent(i), 2) +
pow(hDem->GetBinError(i)/hDem->GetBinContent(i), 2) );
if (isnan(val)) { val = 0; valerr = 0; }
temp->SetBinContent(i, val);
temp->SetBinError(i, valerr);
std::cout << " bin " <<i <<" val " << val << std::endl;
}
//temp->Divide(hDem);
temp->GetYaxis()->SetTitle("Efficiency");
return temp;
} // ----- end of function TPlot::GetEffHist -----
示例2: Run
//____________________________________________________________________
void Run(const char* newName, const char* oldName,
const char* newTitle="New", const char* oldTitle="Old")
{
TFile* newFile = TFile::Open(newName,"READ");
TFile* oldFile = TFile::Open(oldName,"READ");
if (!newFile || !oldFile) return;
TH1* newCent = GetH1(newFile, "realCent");
TH1* oldCent = GetH1(oldFile, "realCent");
if (!newCent || !oldCent) return;
TString t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
TCanvas* c = new TCanvas("c", t, 1200, 800);
c->SetTopMargin(0.01);
c->SetRightMargin(0.20);
fLegend = new TLegend(1-c->GetRightMargin(),
c->GetBottomMargin(),
1, 1-c->GetTopMargin(),
t);
fLegend->SetFillStyle(0);
fLegend->SetBorderSize(0);
THStack* stack = new THStack("ratios","");
fMin = +1e6;
fMax = -1e6;
TH1* one = 0;
for (Int_t i = newCent->GetNbinsX(); i--;) {
Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
Info("", "c1=%f c2=%f", c1, c2);
TH1* r = One(newFile, oldFile, c1, c2);
if (!r) continue;
if (!one) {
one = static_cast<TH1*>(r->Clone("one"));
one->SetDirectory(0);
one->Reset();
for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
one->SetBinContent(j,1);
one->SetBinError (j,0);
}
}
// r->Add(one, i-1);
// r->Scale(TMath::Power(10,i));
stack->Add(r);
}
stack->Draw("nostack");
stack->SetMinimum(0.95*fMin);
stack->SetMaximum(1.05*fMax);
stack->GetHistogram()->SetXTitle("#eta");
stack->GetHistogram()->SetYTitle("#it{R}");
fLegend->Draw();
c->Modified();
c->Update();
c->cd();
c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
}
示例3: cutFlow
void cutFlow(bool eff = false)
{
using namespace std;
double integral, preInt = 1.0;
vector<pair<string,TFile*> > fnames;
vector<pair<string,string> > hnames;
hnames.push_back(pair<string,string>("none","hNu/cut0_none/mWR"));
hnames.push_back(pair<string,string>("LLJJ Pt","hNu/cut1_LLJJpt/mWR"));
hnames.push_back(pair<string,string>("trig","hNu/cut2_TrigMatches/mWR"));
hnames.push_back(pair<string,string>("vertex","hNu/cut3_Vertex/mWR"));
hnames.push_back(pair<string,string>("mu1 pt","hNu/cut4_Mu1HighPt/mWR"));
hnames.push_back(pair<string,string>("Mll","hNu/cut5_diLmass/mWR"));
hnames.push_back(pair<string,string>("MWR","hNu/cut6_mWRmass/mWR"));
fnames.push_back(pair<string,TFile*>("ttbar powheg", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_TTTo2L2Nu2B_7TeV-powheg-pythia6.root")));
fnames.push_back(pair<string,TFile*>("ttbar madgraph", new TFile("/local/cms/user/dahmes/wr2011/bgMC/Summer11/aug30/ttbar-PFJets.root")));
fnames.push_back(pair<string,TFile*>("Z+Jets sherpa", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_DYToLL_M-50_7TeV-sherpa.root")));
fnames.push_back(pair<string,TFile*>("W+Jets sherpa", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_WToLNu_7TeV-sherpa.root")));
fnames.push_back(pair<string,TFile*>("ZZ", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_ZZ_TuneZ2_7TeV_pythia6_tauola.root")));
fnames.push_back(pair<string,TFile*>("WZ", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_WZ_TuneZ2_7TeV_pythia6_tauola.root")));
fnames.push_back(pair<string,TFile*>("WW", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_WW_TuneZ2_7TeV_pythia6_tauola.root")));
fnames.push_back(pair<string,TFile*>("tW", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_T_TuneZ2_tW-channel-DR_7TeV-powheg-tauola.root")));
fnames.push_back(pair<string,TFile*>("tbarW", new TFile("/local/cms/user/pastika/heavynu/heavynu_2011Bg_summer11_Tbar_TuneZ2_tW-channel-DR_7TeV-powheg-tauola.root")));
printf("%8s", "cut");
for(vector<pair<string,TFile*> >::const_iterator i = fnames.begin(); i != fnames.end(); i++)
{
printf(eff?" & %15s ":" & %15s", i->first.c_str());
}
printf(" \\\\ \\hline\n");
for(vector<pair<string,string> >::const_iterator j = hnames.begin(); j != hnames.end(); j++)
{
printf("%8s", j->first.c_str());
for(vector<pair<string,TFile*> >::const_iterator i = fnames.begin(); i != fnames.end(); i++)
{
TH1* h = (TH1*)i->second->Get(j->second.c_str());
integral = h->Integral(0, h->GetNbinsX()+1);
printf((j == hnames.begin() && eff)?" & %15.0f ":" & %15.0f", integral);
if(j != hnames.begin() && eff)
{
TH1* hpre = (TH1*)i->second->Get((j-1)->second.c_str());
preInt = hpre->Integral(0, h->GetNbinsX()+1);
printf(" (%4.2f)", integral/preInt);
}
}
printf(" \\\\ \\hline\n");
}
}
示例4: min
void TH2CB::FillElements(const TH1 &h)
{
if( h.GetNbinsX() != GetNumberOfElements() ) {
cerr << "WARNING: Number of bis don't match" << endl;
}
const Int_t n = min((Int_t)GetNumberOfElements(), h.GetNbinsX());
for(Int_t i=1;i<=n; ++i) {
SetElement(i-1, GetElement(i-1) + h.GetBinContent(i));
}
SetBinContentChanged(kTRUE);
}
示例5: next
void TH2Crystals::SetElements(const TH1 &h)
{
if( h.GetNbinsX() != GetNumberOfElements() ) {
cerr << "WARNING: Number of bis don't match" << endl;
}
TIter next(fBins);
TObject *obj;
TH2PolyBin *bin;
Int_t hbin=1;
while ( (obj = next()) && (hbin <= h.GetNbinsX()) ) {
bin = (TH2PolyBin*) obj;
bin->SetContent(h.GetBinContent(hbin++));
}
}
示例6: value
TH1 *
YieldMean_HighExtrapolationHisto(TH1 *h, TF1 *f, Double_t max, Double_t binwidth)
{
/* find highest edge in histo */
Int_t binhi;
Double_t hi;
for (Int_t ibin = h->GetNbinsX(); ibin > 0; ibin--) {
if (h->GetBinContent(ibin) != 0.) {
binhi = ibin + 1;
hi = h->GetBinLowEdge(ibin + 1);
break;
}
}
if(max<hi) {
Printf("Warning! You should probably set a higher max value (Max = %f, hi = %f)", max, hi);
return 0x0;
}
Int_t nbins = (max - hi) / binwidth;
if(nbins<1)
return 0x0;
TH1 *hhi = new TH1F("hhi", "", nbins, hi, max);
/* integrate function in histogram bins */
Double_t cont, err, width;
for (Int_t ibin = 0; ibin < hhi->GetNbinsX(); ibin++) {
width = hhi->GetBinWidth(ibin + 1);
cont = f->Integral(hhi->GetBinLowEdge(ibin + 1), hhi->GetBinLowEdge(ibin + 2), (Double_t *)0, 1.e-6);
err = f->IntegralError(hhi->GetBinLowEdge(ibin + 1), hhi->GetBinLowEdge(ibin + 2), (Double_t *)0, (Double_t *)0, 1.e-6);
hhi->SetBinContent(ibin + 1, cont / width);
hhi->SetBinError(ibin + 1, err / width);
}
return hhi;
}
示例7:
TH1 *
YieldMean_LowExtrapolationHisto(TH1 *h, TF1 *f, Double_t min, Double_t binwidth)
{
/* find lowest edge in histo */
Int_t binlo;
Double_t lo;
for (Int_t ibin = 1; ibin < h->GetNbinsX() + 1; ibin++) {
if (h->GetBinContent(ibin) != 0.) {
binlo = ibin;
lo = h->GetBinLowEdge(ibin);
break;
}
}
Int_t nbins = (lo - min) / binwidth;
if(nbins<1)
return 0x0;
TH1 *hlo = new TH1F("hlo", "", nbins, min, lo);
/* integrate function in histogram bins */
Double_t cont, err, width;
for (Int_t ibin = 0; ibin < hlo->GetNbinsX(); ibin++) {
width = hlo->GetBinWidth(ibin + 1);
cont = f->Integral(hlo->GetBinLowEdge(ibin + 1), hlo->GetBinLowEdge(ibin + 2), (Double_t *)0, 1.e-6);
err = f->IntegralError(hlo->GetBinLowEdge(ibin + 1), hlo->GetBinLowEdge(ibin + 2), (Double_t *)0, (Double_t *)0, 1.e-6);
hlo->SetBinContent(ibin + 1, cont / width);
hlo->SetBinError(ibin + 1, err / width);
}
return hlo;
}
示例8: 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());
}
示例9: make_pair
//------------------------------------------------------------------------------
std::pair<double,double> fitskwlin( char* hs, double xl=-0.1, double xr=0.1 ) {
TH1 *h = (TH1*)gDirectory->Get(hs);
if( h == NULL ) {
cout << hs << " does not exist\n";
return std::make_pair(0.,0.);
}
int nb = h->GetNbinsX();
double x1 = h->GetBinCenter(1); // first
double x9 = h->GetBinCenter(nb); // last
if( xl > x1 && xl < x9 ) x1 = xl; // left
if( xr > x1 && xr < x9 ) x9 = xr; // right
// create a TF1 with the range from x1 to x9 and 3 parameters
TF1 *tanhFcn = new TF1( "tanhFcn", fitSkw, x1, x9, 2 );
tanhFcn->SetParName( 0, "dyoff" );
tanhFcn->SetParName( 1, "dyslp" );
// set start values:
tanhFcn->SetParameter( 0, 0 ); // dy off [um]
tanhFcn->SetParameter( 1, 99 ); // dy slope [um/skw]
h->Fit( "tanhFcn", "R Q", "p" );// R = range from tanhFcn
return std::make_pair(tanhFcn->GetParameter(0),tanhFcn->GetParameter(1));
}
示例10: ProjectionX
void KVCanvas::ProjectionX(TH2* hh)
{
TString pname = Form("%s_px", hh->GetName());
Int_t ip = 1;
while (gROOT->FindObject(pname.Data())) {
pname = Form("%s_px%d", hh->GetName(), ip);
ip++;
}
TH1* px = hh->ProjectionX(pname.Data());
if (!px) return;
Double_t minY = (hh->GetYaxis()->GetXmin());
Double_t maxY = (hh->GetYaxis()->GetXmax());
Double_t dY = (maxY - minY) * 0.8;
Double_t maxH = px->GetBinContent(px->GetMaximumBin());
TGraph* gg = 0;
if ((gg = (TGraph*)gROOT->FindObject(Form("%s_gjx", hh->GetName())))) gg->Delete();
gg = new TGraph;
for (int i = 0; i < px->GetNbinsX(); i++) {
gg->SetPoint(i, px->GetBinCenter(i), minY + px->GetBinContent(i)*dY / maxH);
}
gg->SetName(Form("%s_gjx", hh->GetName()));
gg->SetTitle(Form("%s_gjx", hh->GetName()));
gg->SetLineColor(kBlack);
gg->SetMarkerColor(kBlack);
gg->SetMarkerStyle(8);
gg->Draw("PL");
Modified();
Update();
}
示例11: subtractHistograms
TH1* subtractHistograms(const std::string& newHistogramName, const TH1* histogram_central, const TH1* histogram_shift, int mode)
{
const TH1* histogramMinuend = 0;
const TH1* histogramSubtrahend = 0;
if ( compIntegral(histogram_central) >= compIntegral(histogram_shift) ) {
histogramMinuend = histogram_central;
histogramSubtrahend = histogram_shift;
} else {
histogramMinuend = histogram_shift;
histogramSubtrahend = histogram_central;
}
if ( !(histogramMinuend && histogramSubtrahend) ) return 0;
TH1* newHistogram = (TH1*)histogramMinuend->Clone(newHistogramName.data());
newHistogram->Reset();
if ( !newHistogram->GetSumw2N() ) newHistogram->Sumw2();
int numBins = newHistogram->GetNbinsX();
for ( int iBin = 0; iBin <= (numBins + 1); ++iBin ) {
double newBinContent = histogramMinuend->GetBinContent(iBin) - histogramSubtrahend->GetBinContent(iBin);
double newBinError2 = square(histogramMinuend->GetBinError(iBin)) + square(histogramSubtrahend->GetBinError(iBin));
if ( mode == kRelative ) {
if ( histogram_central->GetBinContent(iBin) > 0. ) {
newBinContent /= histogram_central->GetBinContent(iBin);
newBinError2 /= square(histogram_central->GetBinContent(iBin));
} else {
newBinContent = 0.;
newBinError2 = 0.;
}
}
newHistogram->SetBinContent(iBin, newBinContent);
assert(newBinError2 >= 0.);
newHistogram->SetBinError(iBin, TMath::Sqrt(newBinError2));
}
return newHistogram;
}
示例12: GenerateConsistentHist
TH1* GenerateConsistentHist(TH1* hbg, TH1* hprod)
{
TH1* hpprod = 0;
if (hbg!=NULL && hprod!=NULL)
{
hpprod = dynamic_cast<TH1*>(hbg->Clone(hprod->GetName()));
if (hpprod!=NULL)
{
Reset(hpprod);
Double_t binctr=0, x=0, ex=0;
// cout << hpprod->GetName() << endl;
for(Int_t i=1; i<=hpprod->GetNbinsX(); i++)
{
binctr = hbg->GetBinCenter(i);
x = hprod->GetBinContent(hprod->GetXaxis()->FindBin(binctr));
ex = hprod->GetBinError(hprod->GetXaxis()->FindBin(binctr));
if (x!=0 && ex/x > 1.0001)
cout << "bin:" << i << "\tcontent:" << x << "\terr:" << ex
<< " \terr/content:" << ex/x << endl;
hpprod->SetBinContent(i,x);
hpprod->SetBinError(i,ex);
}
}
}
return hpprod;
}
示例13: setRange
void setRange(RooWorkspace& myws, RooPlot* frame, string dsName, bool setLogScale, double dMuonYmin)
{
// Find maximum and minimum points of Plot to rescale Y axis
TH1* h = myws.data(dsName.c_str())->createHistogram("hist", *myws.var("ctau"), Binning(frame->GetNbinsX(),frame->GetXaxis()->GetXmin(),frame->GetXaxis()->GetXmax()));
Double_t YMax = h->GetBinContent(h->GetMaximumBin());
cout << YMax << endl;
// Double_t YMin = min( h->GetBinContent(h->FindFirstBinAbove(0.0)), h->GetBinContent(h->FindLastBinAbove(0.0)) );
Double_t YMin = 1e99;
for (int i=1; i<=h->GetNbinsX(); i++) if (h->GetBinContent(i)>0) YMin = min(YMin, h->GetBinContent(i));
bool isMC = false;
if (dsName.find("MC")!=std::string::npos) isMC = true;
Double_t Yup(0.),Ydown(0.);
if(setLogScale)
{
if (isMC) Ydown = YMin*0.3;
else Ydown = YMin/(TMath::Power((YMax/YMin), (0.1/(1.0-0.1-0.4))));
Yup = YMax*TMath::Power((YMax/YMin), (0.4/(1.0-0.1-0.4)));
}
else
{
Ydown = max(YMin-(YMax-YMin)*(0.1/(1.0-0.1-0.4)),0.0);
Yup = YMax+(YMax-YMin)*(0.4/(1.0-0.1-0.4));
}
cout << Ydown << " " << Yup << endl;
frame->GetYaxis()->SetRangeUser(Ydown,Yup);
delete h;
// Create line to indicate upper fitting range for MC
if (isMC)
{
if (dsName.find("JPSIP")!=std::string::npos)
{
TLine* line(0x0);
if (dMuonYmin >= 1.6) line = new TLine(3.32,Ydown,3.32,Yup);
else line = new TLine(3.26,Ydown,3.26,Yup);
line->SetLineStyle(2);
line->SetLineColor(1);
line->SetLineWidth(3);
frame->addObject(line);
}
else if (dsName.find("PSI2S")!=std::string::npos)
{
TLine* line(0x0);
if (dMuonYmin >= 1.6) line = new TLine(3.95,Ydown,3.95,Yup);
else line = new TLine(3.85,Ydown,3.85,Yup);
line->SetLineStyle(2);
line->SetLineColor(1);
line->SetLineWidth(3);
frame->addObject(line);
}
}
}
示例14:
Double_t fitgp0( char* hs ) {
TH1 *h = (TH1*)gDirectory->Get(hs);
if( h == NULL ){
cout << hs << " does not exist\n";
return 0;
}
h->SetMarkerStyle(21);
h->SetMarkerSize(0.8);
h->SetStats(1);
gStyle->SetOptFit(101);
gROOT->ForceStyle();
double dx = h->GetBinWidth(1);
double nmax = h->GetBinContent(h->GetMaximumBin());
double xmax = h->GetBinCenter(h->GetMaximumBin());
double nn = 7*nmax;
int nb = h->GetNbinsX();
double n1 = h->GetBinContent(1);
double n9 = h->GetBinContent(nb);
double bg = 0.5*(n1+n9);
double x1 = h->GetBinCenter(1);
double x9 = h->GetBinCenter(nb);
// create a TF1 with the range from x1 to x9 and 4 parameters
TF1 *gp0Fcn = new TF1( "gp0Fcn", gp0Fit, x1, x9, 4 );
gp0Fcn->SetParName( 0, "mean" );
gp0Fcn->SetParName( 1, "sigma" );
gp0Fcn->SetParName( 2, "area" );
gp0Fcn->SetParName( 3, "BG" );
gp0Fcn->SetNpx(500);
gp0Fcn->SetLineWidth(4);
gp0Fcn->SetLineColor(kMagenta);
gp0Fcn->SetLineColor(kGreen);
// set start values for some parameters:
gp0Fcn->SetParameter( 0, xmax ); // peak position
gp0Fcn->SetParameter( 1, 4*dx ); // width
gp0Fcn->SetParameter( 2, nn ); // N
gp0Fcn->SetParameter( 3, bg );
// N: not drawing
// Q: quiet
// R: use specified range
h->Fit( "gp0Fcn", "NQR", "ep" );
return gp0Fcn->GetParameter(1);
}
示例15: TGraphAsymmErrors
RooHistN::RooHistN(const TH1 &data1, const TH1 &data2, Double_t nominalBinWidth, Double_t nSigma, Double_t xErrorFrac) :
TGraphAsymmErrors(), _nominalBinWidth(nominalBinWidth), _nSigma(nSigma), _rawEntries(-1)
{
// Create a histogram from the asymmetry between the specified TH1 objects
// which may have fixed or variable bin widths, but which must both have
// the same binning. The asymmetry is calculated as (1-2)/(1+2). Error bars are
// calculated using Binomial statistics. Prints a warning and rounds
// any bins with non-integer contents. Use the optional parameter to
// specify the confidence level in units of sigma to use for
// calculating error bars. The nominal bin width specifies the
// default used by addAsymmetryBin(), and is used to set the relative
// normalization of bins with different widths. If not set, the
// nominal bin width is calculated as range/nbins.
initialize();
// copy the first input histogram's name and title
SetName(data1.GetName());
SetTitle(data1.GetTitle());
// calculate our nominal bin width if necessary
if(_nominalBinWidth == 0) {
const TAxis *axis= ((TH1&)data1).GetXaxis();
if(axis->GetNbins() > 0) _nominalBinWidth= (axis->GetXmax() - axis->GetXmin())/axis->GetNbins();
}
setYAxisLabel(Form("Asymmetry (%s - %s)/(%s + %s)",
data1.GetName(),data2.GetName(),data1.GetName(),data2.GetName()));
// initialize our contents from the input histogram contents
Int_t nbin= data1.GetNbinsX();
if(data2.GetNbinsX() != nbin) {
coutE(InputArguments) << "RooHistN::RooHistN: histograms have different number of bins" << endl;
return;
}
for(Int_t bin= 1; bin <= nbin; bin++) {
Axis_t x= data1.GetBinCenter(bin);
if(fabs(data2.GetBinCenter(bin)-x)>1e-10) {
coutW(InputArguments) << "RooHistN::RooHistN: histograms have different centers for bin " << bin << endl;
}
Stat_t y1= data1.GetBinContent(bin);
Stat_t y2= data2.GetBinContent(bin);
addAsymmetryBin(x,roundBin(y1),roundBin(y2),data1.GetBinWidth(bin),xErrorFrac);
}
// we do not have a meaningful number of entries
_entries= -1;
}