本文整理汇总了C++中TH1F::GetNbinsX方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::GetNbinsX方法的具体用法?C++ TH1F::GetNbinsX怎么用?C++ TH1F::GetNbinsX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::GetNbinsX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkTriggers
void checkTriggers()
{
triggers.clear();
triggers.push_back("HLT_Mu23_TrkIsoVVL_Ele8_CaloIdL_TrackIdL_IsoVL_v*");
triggers.push_back("HLT_Mu8_TrkIsoVVL_Ele23_CaloIdL_TrackIdL_IsoVL_v*");
triggers.push_back("HLT_Ele27_eta2p1_WPLoose_Gsf_v*");
triggers.push_back("HLT_IsoMu22_v*");
triggers.push_back("HLT_IsoTkMu22_v*");
triggers.push_back("HLT_Ele23_Ele12_CaloIdL_TrackIdL_IsoVL_DZ_v*");
triggers.push_back("HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_v*");
triggers.push_back("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_v*");
TFile* file = new TFile(_lxplus + "21Jun2016_Run2016B_PromptReco/l2loose__hadd__EpTCorr__l2tight/latino_Run2016B_PromptReco_MuonEG.root");
TH1F* selectedTriggers = (TH1F*)file->Get("selectedTriggers");
TAxis* xaxis = (TAxis*)selectedTriggers->GetXaxis();
printf("\n Checking %d triggers\n\n", (int)triggers.size());
for (int i=0; i<triggers.size(); i++)
{
for (int j=0; j<=selectedTriggers->GetNbinsX(); j++)
{
TString label = (TString)xaxis->GetBinLabel(j);
if (label.Length() < 1) continue;
if (triggers[i].EqualTo(label)) printf(" found [%d] %s\n", i, label.Data());
}
}
printf("\n");
}
示例2: shape_histos
TH1F* shape_histos(TH1F* hin, const TString datacard, const TString name)
/*
use the proper histograms and errors including shpae uncertainties as provided by combine
*/
{
TH1F* hout = (TH1F*)hin->Clone(); hout->Clear();
TFile* mlfit = new TFile("fitresults/mlfit.root", "READ");
TH1F* shape = (TH1F*)mlfit->Get(TString("shapes_fit_s/").Append(datacard).Append("/").Append(name)); // currently problems with data and hioggsprocesses -> different name
if(shape==0) std::cout << " No histogram found for " << name << std::endl;
// for(int i=0; i<hout->GetNbinsX(); ++i)
for(int i=1; i<hout->GetNbinsX()+1; i++)
{
Float_t Norig = hin->GetBinContent(i)*hin->GetBinWidth(i);
Float_t Nshape = shape->GetBinContent(i);
Float_t scale_err = (Nshape==0) ? 1 : Norig/Nshape;
// hout->SetBinContent(i,shape->GetBinContent(i));
hout->SetBinContent(i,hin->GetBinContent(i)*hin->GetBinWidth(i));
hout->SetBinError(i,shape->GetBinError(i)*scale_err);
}
mlfit->Close();
return hout;
}
示例3: refill
TH1F* refill(TH1F* hin, const char* sample)
/*
refill histograms, for MC histograms set bin errors to zero.
*/
{
if(hin==0){
std::cout << "hist not found: " << sample << " -- this may happen for samples of type signal." << std::endl;
bool skip = false;
if(std::string(sample).find("ggH")==std::string::npos){ skip == true ; }
if(skip || std::string(sample).find("Zmm")==std::string::npos){ skip == true; }
if(skip || std::string(sample).find("Fakes/QCD")==std::string::npos){ skip == true; }
if(skip){
std::cout << "hist is not of type signal, Fakes/QCD, Zmm in mumu, close here" << std::endl;
exit(1);
}
else{
return hin;
}
}
TH1F* hout = (TH1F*)hin->Clone(); hout->Clear();
for(int i=0; i<hout->GetNbinsX(); ++i){
// simple refill, histograms are already devided by bin width
// but for a useful lotting the bin errors for MC need to be
// set to zero.
hout->SetBinContent(i+1, hin->GetBinContent(i+1));
hout->SetBinError(i+1, 0.);
}
return hout;
}
示例4: refill
TH1F* refill(TH1F* hin, const char* sample, bool data=false)
/*
refill histograms, divide by bin width and correct bin errors. For MC histograms set
bin errors to zero.
*/
{
if(hin==0){
std::cout << "hist not found: " << sample << " -- close here" << std::endl;
exit(1);
}
TH1F* hout = (TH1F*)hin->Clone(); hout->Clear();
for(int i=0; i<hout->GetNbinsX(); ++i){
if(data){
#if defined MSSM
hout->SetBinContent(i+1, BLIND_DATA && blinding_MSSM(hin->GetBinCenter(i+1)) ? 0. : hin->GetBinContent(i+1)/hin->GetBinWidth(i+1));
hout->SetBinError (i+1, BLIND_DATA && blinding_MSSM(hin->GetBinCenter(i+1)) ? 0. : hin->GetBinError(i+1)/hin->GetBinWidth(i+1));
#endif
}
else{
hout->SetBinContent(i+1, hin->GetBinContent(i+1)/hin->GetBinWidth(i+1));
hout->SetBinError(i+1, 0.);
}
}
return hout;
}
示例5: Difference
void Difference(TH1* iH0,TH1 *iH1) {
std::string lName = std::string(iH0->GetName());
//TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),50,0,300); lHDiff->Sumw2();
TH1F *lHDiff = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax()); lHDiff->Sumw2();
lHDiff->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1);
TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax());
int i1 = 0;
lXHDiff1->SetLineStyle(2); lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed);
lHDiff->GetYaxis()->SetRangeUser(0,2);
lHDiff->GetYaxis()->SetTitleOffset(0.6);
lHDiff->GetYaxis()->SetTitleSize(0.08);
lHDiff->GetYaxis()->SetLabelSize(0.08);
lHDiff->GetYaxis()->CenterTitle();
lHDiff->GetXaxis()->SetTitleOffset(1.2);
lHDiff->GetXaxis()->SetTitleSize(0.10);
lHDiff->GetXaxis()->SetLabelSize(0.08);
lHDiff->GetXaxis()->SetTitle("#slash{E}_{T} [GeV]");
//lHDiff->GetXaxis()->CenterTitle();
//lHDiff->GetYaxis()->SetTitle(YLabel);
for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) {
double lXCenter = lHDiff->GetBinCenter(i0);
double lXVal = iH0 ->GetBinContent(i0);
lXHDiff1->SetBinContent(i0, 1.0);
while(iH1->GetBinCenter(i1) < lXCenter) {i1++;}
if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,(lXVal-iH1->GetBinContent(i0))/(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,iH0->GetBinError(i0)/(iH1->GetBinContent(i0)));
}
lHDiff->SetMarkerStyle(kFullCircle); lHDiff->SetLineColor(kBlack); lHDiff->SetMarkerColor(kBlack);
lHDiff->Draw("E1");
lXHDiff1->Draw("hist sames");
}
示例6: divideHistosForRatio
TH1F * divideHistosForRatio(TH1F * sig, TH1F * bkg) {
TH1F * cloneS = (TH1F *) sig->Clone( sig->GetTitle() );
TH1F * cloneB = (TH1F *) bkg->Clone( bkg->GetTitle() );
/*
for( Int_t bin = 1; bin <= cloneB->GetNbinsX(); bin++ )
cloneB->SetBinError( bin, 0. );
cloneS->Divide( cloneS, cloneB, 1, 1, "" );
*/
for( Int_t bin = 1; bin <= cloneS->GetNbinsX(); bin++ ){
Double_t sv = cloneS->GetBinContent(bin);
Double_t se = cloneS->GetBinError(bin);
Double_t bv = cloneB->GetBinContent(bin);
Double_t rat = -1.;
Double_t err = 0.;
if( sv != 0. && bv != 0. ) {
rat = sv / bv;
// err = sqrt( sv / (bv*bv) );
err = sqrt( se / (bv*bv) );
}
cloneS->SetBinContent( bin, rat );
cloneS->SetBinError( bin, err );
}
return cloneS;
}
示例7: drawDifference
//Difference plotting
void drawDifference(TH1* iH0,TH1 *iH1,TH1 *iHH=0,TH1 *iHL=0,TH1 *iHH1=0,TH1 *iHL1=0) {
std::string lName = std::string(iH0->GetName());
TH1F *lHDiff = (TH1F*) iH0->Clone("Diff");
TH1F *lHDiffH = (TH1F*) iH0->Clone("DiffH");
TH1F *lHDiffL = (TH1F*) iH0->Clone("DiffL");
TH1F *lHDiffH1 = (TH1F*) iH0->Clone("DiffH1");
TH1F *lHDiffL1 = (TH1F*) iH0->Clone("DiffL1");
lHDiff ->SetFillColor(kViolet); lHDiff->SetFillStyle(1001); lHDiff->SetLineWidth(1);
lHDiffL ->SetLineWidth(1); lHDiffL ->SetLineColor(iHL ->GetLineColor());
lHDiffH ->SetLineWidth(1); lHDiffH ->SetLineColor(iHH ->GetLineColor());
lHDiffL1->SetLineWidth(1); lHDiffL1->SetLineColor(iHL1->GetLineColor());
lHDiffH1->SetLineWidth(1); lHDiffH1->SetLineColor(iHH1->GetLineColor());
TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax());
TH1F *lXHDiff2 = new TH1F((lName+"XDiff2").c_str(),(lName+"XDiff2").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax());
int i1 = 0;
lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kRed);
lXHDiff2->SetLineWidth(2); lXHDiff2->SetLineColor(kRed);
lXHDiff1->GetYaxis()->SetTitle("Ratio");
lXHDiff1->GetYaxis()->SetRangeUser(0.2,1.8);
lXHDiff1->GetYaxis()->SetTitleOffset(0.4);
lXHDiff1->GetYaxis()->SetTitleSize(0.2);
lXHDiff1->GetYaxis()->SetLabelSize(0.11);
for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) {
double lXCenter = lHDiff->GetBinCenter(i0);
double lXVal = iH0 ->GetBinContent(i0);
double lXValH = iHH ->GetBinContent(i0);
double lXValL = iHL ->GetBinContent(i0);
double lXValH1 = iHH1 ->GetBinContent(i0);
double lXValL1 = iHL1 ->GetBinContent(i0);
lXHDiff1->SetBinContent(i0, 1.0);
lXHDiff2->SetBinContent(i0, 1.0);
while(iH1->GetBinCenter(i1) < lXCenter) {i1++;}
if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,lXVal /(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError (i0,sqrt(lXVal)/(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiffL->SetBinContent(i0,lXValL/(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiffH->SetBinContent(i0,lXValH/(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiffL1->SetBinContent(i0,lXValL1/(iH1->GetBinContent(i0)));
if(iH1->GetBinContent(i0) > 0) lHDiffH1->SetBinContent(i0,lXValH1/(iH1->GetBinContent(i0)));
//if(iH1->GetBinContent(i0) > 0) cout << "unc" << lXVal << " -- " << sqrt(lXVal)/(iH1->GetBinContent(i0)) << endl;
}
lHDiff->SetMarkerStyle(kFullCircle);
//lHDiff->Draw("EP");
lXHDiff1->SetStats(0);
lXHDiff2->SetStats(0);
lHDiff->SetStats(0);
lHDiffH->SetStats(0);
lHDiffL->SetStats(0);
lHDiffH1->SetStats(0);
lHDiffL1->SetStats(0);
lXHDiff1->Draw("hist");
lXHDiff2->Draw("hist sames");
lHDiff->Draw("EP sames");
lHDiffH ->Draw("hist sames");
lHDiffL ->Draw("hist sames");
lHDiffH1->Draw("hist sames");
lHDiffL1->Draw("hist sames");
}
示例8: RestoreBinning
TH1F RestoreBinning(TH1F const& src, TH1F const& ref) {
TH1F res = ref;
res.Reset();
for (int x = 1; x <= res.GetNbinsX(); ++x) {
res.SetBinContent(x, src.GetBinContent(x));
}
return res;
}
示例9: getRecoTimesDQM
void getRecoTimesDQM(const char* fName){
// std::cout<<"File "<<fName<<std::endl;
TFile* f = new TFile(fName);
f->cd("/DQMData/Run 1/DQM/Run summary/TimerService/Paths");
TH1F* h = gDirectory->Get("reconstruction_step_module_total");
int n = h->GetNbinsX();
for(int i=1;i<=n;++i)std::cout<<h->GetXaxis()->GetBinLabel(i)<<" "<<h->GetBinContent(i)<<std::endl;
}
示例10: sumUpEntries
double sumUpEntries(TH1F& histo){
// sum up all bin entries of histo
// +1 : include overflow bin
double entries=0;
for(int idx=1; idx<=histo.GetNbinsX()+1; idx++){
entries+=histo.GetBinContent(idx);
}
return entries;
}
示例11: plotweight
void plotweight(int isub){
TFile *f = TFile::Open("/phenix/u/xuq/xuq/taxi/Run15pAu200FVTXClusAna503/8845/data/435527_0.root");
int ivz = 0;
TH1F* h = (TH1F*)f->Get(Form("phiweight_0_0_0_%d_0_%d",ivz,isub));
TH1F* hc = (TH1F*)h->Clone("hc");
h->Rebin(4);
hc->Rebin(4);
for(int ibin=0;ibin<=h->GetNbinsX();ibin++){
if(h->GetBinContent(ibin)!=0)
hc->SetBinContent(ibin,h->Integral()/h->GetNbinsX()/h->GetBinContent(ibin));
else
hc->SetBinContent(ibin,1.);
}
TCanvas *c1 = new TCanvas("c1");
hc->Draw();
TCanvas *c2 = new TCanvas("c2");
h->Draw();
}
示例12: refill
// re-fill histograms (this is only a little helper for the example histogram)
TH1F* refill(TH1F* hin)
{
TH1F* hout = (TH1F*)hin->Clone(); hout->Clear();
for(int i=0; i<hout->GetNbinsX(); ++i){
hout->SetBinContent(i+1, hin->GetBinContent(i+1));
hout->SetBinError (i+1, 0.);
}
return hout;
}
示例13: GetPseudoData
TH1F* GetPseudoData(TH1F* h_tt1l, TH1F* h_Wjets, TH1F* h_tt2l){
TH1F* h = (TH1F*) h_tt1l->Clone("data");
h->Add(h_Wjets);
h->Add(h_tt2l);
//randomisation of the histo ...
for(int i=1;i<=h->GetNbinsX();i++){
h->SetBinContent(i,randomnessGenerator->Poisson(h->GetBinContent(i)));
}
return h;
}
示例14: getErrHist
TH1F * getErrHist(TH1F * h, bool rel = true)
{
TH1F * res = (TH1F *) h->Clone("errhist");
res->Reset();
for(int j = 1; j <= res->GetNbinsX(); j++)
if(rel) res->SetBinContent(j,h->GetBinError(j)/h->GetBinContent(j));
else res->SetBinContent(j,h->GetBinError(j));
return res;
}
示例15: PoissonianMagic
void PoissonianMagic()
{
TFile file_PUnum("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/DataPUFile_22Jan2013ReReco_Run2012.root", "read");
TFile file_PUden("/nfs/dust/cms/user/rathjd/VBF-LS-tau/PU/S10MC_PUFile.root", "read");
TH1F *data = (TH1F*)file_PUnum.Get("analyzeHiMassTau/NVertices_0");
data->Scale(1/data->Integral(0,-1));
TH1F *MC = (TH1F*)file_PUden.Get("analyzeHiMassTau/NVertices_0");
MC->Scale(1/MC->Integral(0,-1));
//define empty histograms for the smeared versions
TH1F *num = (TH1F*)data->Clone("ratio");
for(int i=0; i<num->GetNbinsX(); i++) num->SetBinContent(i+1,0);
TH1F *den = (TH1F*)data->Clone("MC");
for(int i=0; i<den->GetNbinsX(); i++) den->SetBinContent(i+1,0);
//generate the poissonian distributions
for(unsigned int i=0; i<data->GetNbinsX(); i++){
TF1 *Pd = new TF1("Pd", "TMath::PoissonI(x,[0])",0,100);
Pd->SetParameter(0,data->GetBinLowEdge(i+1));
std::cout<<data->GetBinLowEdge(i+1)<<std::endl;
TF1 *Pm = new TF1("Pm", "TMath::PoissonI(x,[0])",0,100);
Pm->SetParameter(0,MC->GetBinLowEdge(i+1));
//add up the poissonians
for(unsigned int j=0; j<data->GetNbinsX(); j++){
num->SetBinContent(j+1,num->GetBinContent(j+1)+Pd->Eval(j)/Pd->Integral(0,100)*data->GetBinContent(i+1));
den->SetBinContent(j+1,den->GetBinContent(j+1)+Pm->Eval(j)/Pm->Integral(0,100)*MC->GetBinContent(i+1));
}
}
//make the ratio and save the result
num->Divide(den);
TFile *f=new TFile("PUreweightHistogram.root","RECREATE");
num->Write();
den->Write();
f->Close();
file_PUnum.Close();
file_PUden.Close();
}