本文整理汇总了C++中TH1::IsA方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::IsA方法的具体用法?C++ TH1::IsA怎么用?C++ TH1::IsA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::IsA方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nll
void Fit::nll(int& ndim, double* gout, double& result, double* par, int flags) {
size_t n = Fit::signals.size();
result = 0;
// make summed fit histogram
TH1* hfit = (TH1*) signals[0].histogram->Clone("hfit");
hfit->Reset();
for (size_t i=0; i<n; i++) {
TH1* h = Fit::signals.at(i).histogram;
h->Scale(1.0/h->Integral());
hfit->Add(h, Fit::norms[i] * par[i]);
}
// loop over bins
if (hfit->IsA() == TH2F::Class()) {
TH2F* h2 = dynamic_cast<TH2F*>(hfit);
for (int i=1; i<h2->GetNbinsX(); i++) {
if (i < h2->GetXaxis()->FindBin(Fit::r_range.min) || i > h2->GetXaxis()->FindBin(Fit::r_range.max)) {
continue;
}
for (int j=1; j<h2->GetNbinsY(); j++) {
if (j < h2->GetYaxis()->FindBin(Fit::e_range.min) || j > h2->GetYaxis()->FindBin(Fit::e_range.max)) {
continue;
}
double nexp = h2->GetBinContent(i, j);
double nobs = dynamic_cast<TH2F*>(Fit::data)->GetBinContent(i, j);
result += (nexp - nobs * TMath::Log(TMath::Max(1e-12, nexp)));
//std::cout << "- " << nexp << " " << nobs << " " << TMath::Log(nexp) << " // " << result << std::endl;
}
}
}
else {
for (int i=1; i<hfit->GetNbinsX(); i++) {
if (i < hfit->FindBin(Fit::e_range.min) || i > hfit->FindBin(Fit::e_range.max)) {
continue;
}
double nexp = hfit->GetBinContent(i);
double nobs = Fit::data->GetBinContent(i);
result += (nexp - nobs * TMath::Log(TMath::Max(1e-12, nexp)));
//std::cout << "- " << nexp << " " << nobs << " " << TMath::Log(nexp) << " // " << result << std::endl;
}
}
// constraints
for (size_t i=0; i<n; i++) {
if (Fit::signals.at(i).constraint > 0) {
result += 0.5 * TMath::Power((par[i]-1.0)
/ Fit::signals.at(i).constraint, 2);
}
}
delete hfit;
#ifdef DEBUG
// print parameters at each iteration
std::cout << "+ ";
for (size_t i=0; i<n; i++) {
std::cout << par[i] * Fit::signals.at(i).rate << " (" << par[i] << ") \t";
}
std::cout << result << std::endl;
#endif
}
示例2: setHistStyle
//------------------------------------------------------------------------------
void PlotAlignmentValidation::setHistStyle( TH1& hist,const char* titleX, const char* titleY, int color)
{
std::stringstream titel_Xaxis;
std::stringstream titel_Yaxis;
TString titelXAxis=titleX;
TString titelYAxis=titleY;
if ( titelXAxis.Contains("Phi") )titel_Xaxis<<titleX<<"[rad]";
else if( titelXAxis.Contains("meanX") )titel_Xaxis<<"#LTx'_{pred}-x'_{hit}#GT[cm]";
else if( titelXAxis.Contains("meanY") )titel_Xaxis<<"#LTy'_{pred}-y'_{hit}#GT[cm]";
else if( titelXAxis.Contains("rmsX") )titel_Xaxis<<"RMS(x'_{pred}-x'_{hit})[cm]";
else if( titelXAxis.Contains("rmsY") )titel_Xaxis<<"RMS(y'_{pred}-y'_{hit})[cm]";
else if( titelXAxis.Contains("meanNormX") )titel_Xaxis<<"#LTx'_{pred}-x'_{hit}/#sigma#GT";
else if( titelXAxis.Contains("meanNormY") )titel_Xaxis<<"#LTy'_{pred}-y'_{hit}/#sigma#GT";
else if( titelXAxis.Contains("rmsNormX") )titel_Xaxis<<"RMS(x'_{pred}-x'_{hit}/#sigma)";
else if( titelXAxis.Contains("rmsNormY") )titel_Xaxis<<"RMS(y'_{pred}-y'_{hit}/#sigma)";
else if( titelXAxis.Contains("meanLocalX") )titel_Xaxis<<"#LTx_{pred}-x_{hit}#GT[cm]";
else if( titelXAxis.Contains("rmsLocalX") )titel_Xaxis<<"RMS(x_{pred}-x_{hit})[cm]";
else if( titelXAxis.Contains("meanNormLocalX") )titel_Xaxis<<"#LTx_{pred}-x_{hit}/#sigma#GT[cm]";
else if( titelXAxis.Contains("rmsNormLocalX") )titel_Xaxis<<"RMS(x_{pred}-x_{hit}/#sigma)[cm]";
else if( titelXAxis.Contains("medianX") )titel_Xaxis<<"median(x'_{pred}-x'_{hit})[cm]";
else if( titelXAxis.Contains("medianY") )titel_Xaxis<<"median(y'_{pred}-y'_{hit})[cm]";
else titel_Xaxis<<titleX<<"[cm]";
if (hist.IsA()->InheritsFrom( TH1F::Class() ) )hist.SetLineColor(color);
if (hist.IsA()->InheritsFrom( TProfile::Class() ) ) {
hist.SetMarkerStyle(20);
hist.SetMarkerSize(0.8);
hist.SetMarkerColor(color);
}
hist.GetXaxis()->SetTitle( (titel_Xaxis.str()).c_str() );
hist.GetXaxis()->SetTitleSize ( 0.05 );
hist.GetXaxis()->SetTitleColor ( 1 );
hist.GetXaxis()->SetTitleOffset( 1.2 );
hist.GetXaxis()->SetTitleFont ( 62 );
hist.GetXaxis()->SetLabelSize ( 0.05 );
hist.GetXaxis()->SetLabelFont ( 62 );
//hist.GetXaxis()->CenterTitle ( );
hist.GetXaxis()->SetNdivisions ( 505 );
if /*( titelYAxis.Contains("meanX") )titel_Yaxis<<"#LTx'_{pred}-x'_{hit}#GT[cm]";
else if ( titelYAxis.Contains("rmsX") )titel_Yaxis<<"RMS(x'_{pred}-x'_{hit})[cm]";
else if( titelYAxis.Contains("meanNormX") )titel_Yaxis<<"#LTx'_{pred}-x'_{hit}/#sigma#GT";
else if( titelYAxis.Contains("rmsNormX") )titel_Yaxis<<"RMS(x_'{pred}-x'_{hit}/#sigma)";
else if( titelYAxis.Contains("meanLocalX") )titel_Yaxis<<"#LTx_{pred}-x_{hit}#GT[cm]";
else if( titelYAxis.Contains("rmsLocalX") )titel_Yaxis<<"RMS(x_{pred}-x_{hit})[cm]";
else if*/ ( (titelYAxis.Contains("layer") && titelYAxis.Contains("subDetId"))
|| titelYAxis.Contains("#modules") )titel_Yaxis<<"#modules";
else if ( (titelYAxis.Contains("ring") && titelYAxis.Contains("subDetId"))
|| titelYAxis.Contains("#modules") )titel_Yaxis<<"#modules";
else titel_Yaxis<<titleY<<"[cm]";
hist.GetYaxis()->SetTitle( (titel_Yaxis.str()).c_str() );
//hist.SetMinimum(1);
hist.GetYaxis()->SetTitleSize ( 0.05 );
hist.GetYaxis()->SetTitleColor ( 1 );
if ( hist.IsA()->InheritsFrom( TH2::Class() ) ) hist.GetYaxis()->SetTitleOffset( 0.95 );
else hist.GetYaxis()->SetTitleOffset( 1.2 );
hist.GetYaxis()->SetTitleFont ( 62 );
hist.GetYaxis()->SetLabelSize ( 0.03 );
hist.GetYaxis()->SetLabelFont ( 62 );
}
示例3: DrawTwoInPad
void DrawTwoInPad(TVirtualPad* p,
Int_t sub,
TH1* h1,
TH1* h2,
Bool_t ratio,
Bool_t logy=false,
Bool_t legend=false)
{
TVirtualPad* pp = p->cd(sub);
pp->SetRightMargin(0.02);
pp->SetLeftMargin(0.10);
TVirtualPad* ppp = pp;
if (ratio) {
pp->Divide(1,2,0,0);
ppp = pp->cd(1);
ppp->SetRightMargin(0.02);
}
if (logy) ppp->SetLogy();
TH1* hs[] = { h1, h2, 0 };
if (h1->GetMaximum() < h2->GetMaximum()) {
hs[0] = h2;
hs[1] = h1;
}
TH1** ph = hs;
Double_t size = (ratio ? 0.1 : 0.05);
Double_t off = (ratio ? 0.6 : 0.5);
h1->SetFillStyle(3004);
h2->SetFillStyle(3005);
while (*ph) {
TString opt("hist");
if (ph != hs) opt.Append(" same");
TH1* copy = (*ph)->DrawCopy(opt);
copy->GetXaxis()->SetLabelSize(2*size);
copy->GetYaxis()->SetLabelSize(size);
copy->GetYaxis()->SetTitleSize(size);
copy->GetYaxis()->SetTitleOffset(off);
copy->SetYTitle(copy->GetTitle());
copy->SetTitle("");
copy->SetDirectory(0);
ph++;
}
TString s1 = h1->GetYaxis()->GetTitle();
TString s2 = h2->GetYaxis()->GetTitle();
if (legend) {
TLegend* l = new TLegend(0.6, 0.1, 0.9, 0.9);
l->SetBorderSize(0);
TLegendEntry* e = l->AddEntry("dummy", s1, "lf");
l->SetFillColor(kWhite);
e->SetFillColor(kBlack);
e->SetFillStyle(h1->GetFillStyle());
e = l->AddEntry("dummy", s2, "lf");
e->SetFillColor(kBlack);
e->SetFillStyle(h2->GetFillStyle());
l->Draw();
}
if (!ratio) return;
ppp = pp->cd(2);
ppp->SetRightMargin(0.02);
TH1* r = static_cast<TH1*>(h1->Clone(Form("ratio%s", h1->GetName())));
r->SetDirectory(0);
r->SetTitle("");
r->GetXaxis()->SetLabelSize(size);
r->GetYaxis()->SetLabelSize(size);
r->GetYaxis()->SetTitleSize(0.9*size);
r->GetYaxis()->SetTitleOffset(0.9*off);
r->SetMarkerStyle(20);
r->SetMarkerColor(h1->GetFillColor()+1);
r->SetFillStyle(3007);
r->SetYTitle(Form("#frac{%s}{%s}", s1.Data(), s2.Data()));
// r->Add(h2, -1);
// r->Divide(h1);
if (!r->IsA()->InheritsFrom(TProfile::Class())) {
r->GetSumw2()->Set(0); // r->Sumw2(false);
h2->GetSumw2()->Set(0); // h2->Sumw2(false);
}
r->Divide(h2);
Printf("%s", r->GetName());
for (UShort_t bin = 1; bin <= r->GetNbinsX(); bin++) {
Printf(" bin # %2d: Diff=%g+/-%g", bin, r->GetBinContent(bin),
r->GetBinError(bin));
r->SetBinError(bin, 0);
}
r->GetSumw2()->Set(0); //r->Sumw2(false);
r->SetMarkerSize(4);
r->SetMaximum(r->GetMaximum()*1.2);
r->SetMinimum(r->GetMinimum()*0.8);
r->Draw("hist text30");
p->Modified();
p->Update();
p->cd();
}