本文整理汇总了C++中TH1::SetDirectory方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::SetDirectory方法的具体用法?C++ TH1::SetDirectory怎么用?C++ TH1::SetDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::SetDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TGraphAsymmErrors
//____________________________________________________________________________________
TGraphAsymmErrors *calcEfficiency(TH1* h1, TH1* h2)
{
TH1 *phUp = (TH1 *)h2->Clone("phUp");
TH1 *phDown = (TH1 *)h1->Clone("phDown");
phUp->SetDirectory(0);
phDown->SetDirectory(0);
TGraphAsymmErrors *pgEfficiency = new TGraphAsymmErrors();
pgEfficiency->BayesDivide(phUp,phDown,"");
return pgEfficiency;
}
示例2: GetHist
TH1* GetHist(const string histname)
{
const float scaleTo = fDATA_LUMI; // pb
TH1 *hists[nBins] = {0,0,0,0,0,0,0};
TH1 *Hist = 0;
for (int i=0; i<nBins; ++i)
{
hists[i] = dynamic_cast<TH1*> (files[i]->Get(histname.c_str()));
if (hists[i] != 0)
{
hists[i]->Sumw2();
const float scale = scaleTo/ ( nEvents[i] / xSec[i] );
hists[i]->Scale(scale);
hists[i]->SetLineWidth(2);
hists[i]->SetLineColor(i);
if (i == 0)
{
Hist = dynamic_cast<TH1*> (hists[i]->Clone("hist0_copy"));
Hist->SetDirectory(0);
} else
{
Hist->Add(hists[i]);
}
} else {
cout << "hist " << histname << " not found in " << files[i]->GetName() << "!" << endl;
assert (false);
}
}
return Hist;
}
示例3: CreateIndex
bool TrLikeDB::LoadPdfVer0(char* dirname) {
TFile* file = TFile::Open(Form("%s/v5.00/TrLikeDBver0/PDFDBv2.root",dirname),"read");
if (!file) return false;
int index = 0;
int irig = 1;
TH1* pdf = 0;
fZmax = 28;
for (int Z=1; Z<=fZmax; Z++) {
for (int icat=0; icat<2; icat++) {
// 2D Xi_{X} vs Xi_{Y}
index = CreateIndex(0,Z,icat,0,irig);
pdf = (TH1*) file->Get(Form("hLogXi2D_Z%d_Rig%d_Cat%d",Z,irig,icat+1));
if (!pdf) {
printf("TrLikeDB::LoadPdfVer0-E error in loading PDFs (hLogXi2D_Z%d_Rig%d_Cat%d). Tracker integer charge could have some problem!\n",Z,irig,icat+1);
file->Close();
break;
}
pdf->SetDirectory(0);
AddPdf(pdf,index);
for (int iside=0; iside<2; iside++) {
// 1D Xi
index = CreateIndex(1,Z,icat,iside,irig);
pdf = (TH1*) file->Get(Form("hLogXi1D_Z%d_Rig%d_Cat%d_Side%d",Z,irig,icat+1,iside));
if (!pdf) {
printf("TrLikeDB::LoadPdfVer0-E error in loading PDFs (hLogXi1D_Z%d_Rig%d_Cat%d_Side%d). Tracker integer charge could have some problem!\n",Z,irig,icat+1,iside);
file->Close();
break;
}
pdf->SetDirectory(0);
AddPdf(pdf,index);
// 1D Eta
index = CreateIndex(2,Z,icat,iside,irig);
pdf = (TH1*) file->Get(Form("hLogEtaS1D_Z%d_Rig%d_Cat%d_Side%d",Z,irig,icat+1,iside));
if (!pdf) {
printf("TrLikeDB::LoadPdfVer0-E error in loading PDFs (hLogEtaS1D_Z%d_Rig%d_Cat%d_Side%d). Tracker integer charge could have some problem!\n",Z,irig,icat+1,irig);
file->Close();
break;
}
pdf->SetDirectory(0);
AddPdf(pdf,index);
}
}
}
// create missing pdf here if needed ... not for now
file->Close();
return true;
}
示例4: 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));
}
示例5: GetSumNom
void GetSumNom(){
TH1* htemp;
for(int i = 1; i < 12; i++){
TFile* inputfile = TFile::Open(pathsum + Form("Tree_TTbar_Powheg_%i.root", i))->GetObject("CountLHE",htemp);
h->Add(htemp);
htemp->SetDirectory(0);
//cout << "i = " << i << ", h->GetEntries() = " << h->GetEntries() << endl;
delete htemp; delete inputfile;
}
fac = h->GetBinContent(1002);
}
示例6: DrawInPad
//#endif
void DrawInPad(TVirtualPad* p,
Int_t sub,
TH1* h,
Bool_t logy=false)
{
TVirtualPad* pp = p->cd(sub);
pp->SetRightMargin(0.02);
if (logy) pp->SetLogy();
TH1* copy = h->DrawCopy("hist");
copy->GetXaxis()->SetLabelSize(0.13);
copy->GetYaxis()->SetLabelSize(0.08);
copy->SetDirectory(0);
}
示例7: makeIntHist
TH1* makeIntHist(const TH1* hist,bool intIsGreatThan)
{
TH1* cHist = (TH1*) hist->Clone("cHist");
cHist->SetDirectory(0);
cHist->SetName(hist->GetName());
int maxBin = hist->GetNbinsX()+1;
for(int binNr=0;binNr<=hist->GetNbinsX();binNr++){
//if(hist->GetBinContent(binNr) == 0) continue;
float nrEntries = intIsGreatThan ? hist->Integral(binNr,maxBin) : hist->Integral(0,binNr);
cHist->SetBinContent(binNr,nrEntries);
}
return cHist;
}
示例8: One
//____________________________________________________________________
TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2)
{
TString name;
name.Form("cent%03dd%02d_%03dd%02d",
Int_t(c1), Int_t(c1*100)%100,
Int_t(c2), Int_t(c2*100)%100);
TDirectory* newSubDir = GetD(newDir, name);
TDirectory* oldSubDir = GetD(oldDir, name);
if (!newSubDir || !oldSubDir) return 0;
Int_t newDim = 0;
if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3;
else if (TString(newDir->GetName()).Contains("eta")) newDim = 2;
else if (TString(newDir->GetName()).Contains("const")) newDim = 1;
Int_t oldDim = 0;
if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3;
else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2;
else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1;
TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim));
TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim));
if (!newSubSubDir || !oldSubSubDir) return 0;
TH1* newRes = GetH1(newSubSubDir, "result");
TH1* oldRes = GetH1(oldSubSubDir, "result");
if (!newRes || !oldRes) return 0;
TH1* ratio = static_cast<TH1*>(newRes->Clone(name));
ratio->SetDirectory(0);
ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2));
ratio->SetYTitle("New / Old");
ratio->Divide(oldRes);
fMin = TMath::Min(fMin, ratio->GetMinimum());
fMax = TMath::Max(fMax, ratio->GetMaximum());
Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName());
if (!fLegend) return ratio;
TLegendEntry* e =
fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f");
e->SetFillStyle(1001);
e->SetFillColor(ratio->GetMarkerColor());
return ratio;
}
示例9: savehistos
void savehistos(const string& filewithlist,
const string& outputfilename,
const string& openmode="RECREATE")
{
FILE *fp = fopen(filewithlist.c_str(),"r");
if (!fp) {
cerr << "File not found, " << filewithlist << endl;
return;
}
TFile *rootfile = new TFile(outputfilename.c_str(),openmode.c_str());
if (rootfile->IsZombie()) {
cerr << "File failed to open, " << outputfilename << endl;
return;
}
string theline,newname;
vector<string> tokens;
while (getLine(fp,theline)) {
if (theline[0] == '#') continue; // "comments are welcome"
Tokenize(theline,tokens,"\t");
TH1 *h1 = getHisto(tokens[0]);
if (!h1) {
cerr << "Couldn't get histo " << tokens[0] << endl;
return;
}
TH1 *target = h1;
if( tokens.size() > 1 && tokens[1].length() ) {
newname = tokens[1];
cout<<"Writing histo "<<newname<<" to file "<<outputfilename<<endl;
target = (TH1 *)h1->Clone(newname.c_str());
} else
cout<<"Writing histo "<<h1->GetName()<<" to file "<<outputfilename<<endl;
target->SetDirectory(rootfile);
rootfile->cd();
target->Write();
}
rootfile->Close();
}
示例10: getHistogram
std::shared_ptr<TH1> getHistogram(const std::string& name, const std::vector<Input>& inputs, int type) {
TH1* h = nullptr;
for (const auto& input: inputs) {
if (input.type != type)
continue;
TH1* f = static_cast<TH1*>(input.file->Get(name.c_str()));
f->Scale(input.cross_section / (input.generated_events * input.top_pt_weight));
if (! h) {
h = static_cast<TH1*>(f->Clone());
h->SetDirectory(NULL);
} else
h->Add(f);
}
return std::shared_ptr<TH1>(h);
}
示例11: next
/**
* Add the bin histograms to our summary stacks
*
* @param bin Bin stack
* @param i Current off-set in the stacks
* @param measured All measured @f$ P(N_{ch})@f$
* @param truth All MC truth @f$ P(N_{ch})@f$
* @param accepted All MC accepted @f$ P(N_{ch})@f$
* @param unfolded All unfolded @f$ P(N_{ch})@f$
* @param corrected All corrected @f$ P(N_{ch})@f$
* @param result The result in this bin
*/
void Bin2Stack(const THStack* bin, Int_t i,
THStack* measured,
THStack* truth,
THStack* accepted,
THStack* unfolded,
THStack* corrected,
TH1*& result)
{
Int_t open, closed;
Double_t factor;
Float_t size;
BinAttributes(i, open, closed, size, factor);
TIter next(bin->GetHists());
TH1* h = 0;
while ((h = static_cast<TH1*>(next()))) {
THStack* tmp = 0;
Int_t col = h->GetMarkerColor();
Int_t sty = 0;
switch (col) {
case kColorMeasured: tmp = measured; sty = closed; break;
case kColorTruth: tmp = truth; sty = open; break;
case kColorAccepted: tmp = accepted; sty = open; break;
case kColorUnfolded: tmp = unfolded; sty = closed; break;
case kColorCorrected: tmp = corrected; sty = closed; break;
default: continue;
}
// Now clone, and add to the appropriate stack
TH1* cln = static_cast<TH1*>(h->Clone(h->GetName()));
cln->SetDirectory(0);
cln->SetMarkerStyle(sty);
cln->SetMarkerSize(size);
cln->Scale(factor); // Scale by 10^i
if (col == kColorCorrected) result = cln;
// Make sure we do not get the old legend
TObject* tst = cln->FindObject("legend");
if (tst) cln->GetListOfFunctions()->Remove(tst);
tmp->Add(cln, next.GetOption());
}
// Add entries to our stacks
TString txt = bin->GetTitle();
if (i == 0) txt.Append(" (#times1)");
else if (i == 1) txt.Append(" (#times10)");
else txt.Append(Form(" (#times10^{%d})", i));
THStack* stacks[] = { measured, truth, accepted, unfolded, corrected, 0 };
THStack** pstack = stacks;
while (*pstack) {
TLegend* leg = StackLegend(*pstack);
pstack++;
if (!leg) continue;
TObject* dummy = 0;
TLegendEntry* e = leg->AddEntry(dummy, txt, "p");
e->SetMarkerStyle(closed);
e->SetMarkerSize(1.2*size);
e->SetMarkerColor(kBlack);
e->SetFillColor(0);
e->SetFillStyle(0);
e->SetLineColor(kBlack);
}
}
示例12: ProcessBin
/**
* Process a single eta bin
*
* @param measured Input collection of measured data
* @param corrections Input collection of correction data
* @param method Unfolding method to use
* @param regParam Regularisation parameter
* @param out Output directory.
*
* @return Stack of histograms or null
*/
THStack* ProcessBin(TCollection* measured,
TCollection* corrections,
UInt_t method,
Double_t regParam,
TDirectory* out)
{
Printf(" Processing %s ...", measured->GetName());
// Try to get the data
TH1* inRaw = GetH1(measured, "rawDist");
TH1* inTruth = GetH1(corrections, "truth");
TH1* inTruthA = GetH1(corrections, "truthAccepted");
TH1* inTrgVtx = GetH1(corrections, "triggerVertex");
TH2* inResp = GetH2(corrections, "response");
if (!inRaw || !inTruth || !inTruthA || !inTrgVtx || !inResp)
return 0;
// Make output directory
TDirectory* dir = out->mkdir(measured->GetName());
dir->cd();
// Copy the input to the output
TH1* outRaw = static_cast<TH1*>(inRaw ->Clone("measured"));
TH1* outTruth = static_cast<TH1*>(inTruth ->Clone("truth"));
TH1* outTruthA = static_cast<TH1*>(inTruthA ->Clone("truthAccepted"));
TH1* outTrgVtx = static_cast<TH1*>(inTrgVtx ->Clone("triggerVertex"));
TH2* outResp = static_cast<TH2*>(inResp ->Clone("response"));
// Make our response matrix
RooUnfoldResponse matrix(0, 0, inResp);
// Store regularization parameter
Double_t r = regParam;
RooUnfold::Algorithm algo = (RooUnfold::Algorithm)method;
RooUnfold* unfolder = RooUnfold::New(algo, &matrix, inRaw, r);
unfolder->SetVerbose(0);
// Do the unfolding and get the result
TH1* res = unfolder->Hreco();
res->SetDirectory(0);
// Make a copy to store on the output
TH1* outUnfold = static_cast<TH1*>(res->Clone("unfolded"));
TString tit(outUnfold->GetTitle());
tit.ReplaceAll("Unfold Reponse matrix", "Unfolded P(#it{N}_{ch})");
outUnfold->SetTitle(tit);
// Clone the unfolded results and divide by the trigger/vertex
// bias correction
TH1* outCorr = static_cast<TH1*>(outUnfold->Clone("corrected"));
outCorr->Divide(inTrgVtx);
tit.ReplaceAll("Unfolded", "Corrected");
outCorr->SetTitle(tit);
// Now normalize the output to integral=1
TH1* hists[] = { outRaw, outUnfold, outCorr, 0 };
TH1** phist = hists;
while (*phist) {
TH1* h = *phist;
if (h) {
Double_t intg = h->Integral(1, h->GetXaxis()->GetXmax());
h->Scale(1. / intg, "width");
}
phist++;
}
// And make ratios
TH1* ratioTrue = static_cast<TH1*>(outCorr->Clone("ratioCorrTruth"));
tit = ratioTrue->GetTitle();
tit.ReplaceAll("Corrected", "Corrected/MC 'truth'");
ratioTrue->SetTitle(tit);
ratioTrue->Divide(outTruth);
ratioTrue->SetYTitle("P_{corrected}(#it{N}_{ch})/P_{truth}(#it{N}_{ch})");
TH1* ratioAcc = static_cast<TH1*>(outUnfold->Clone("ratioUnfAcc"));
tit = ratioAcc->GetTitle();
tit.ReplaceAll("Unfolded", "Unfolded/MC selected");
ratioAcc->SetTitle(tit);
ratioAcc->Divide(outTruthA);
ratioAcc->SetYTitle("P_{unfolded}(#it{N}_{ch})/P_{MC}(#it{N}_{ch})");
// Make a stack
tit = measured->GetName();
tit.ReplaceAll("m", "-");
tit.ReplaceAll("p", "+");
tit.ReplaceAll("d", ".");
tit.ReplaceAll("_", "<#it{#eta}<");
THStack* stack = new THStack("all", tit);
stack->Add(outTruth, "E2");
//.........这里部分代码省略.........
示例13: plotHadTau3
// Plot the closure test
void plotHadTau3(double scale = 1.,
const TString &fileName = "HadTau_WJetMC_PredGen.root") {
gROOT->ProcessLine(".L ../utils/StyleMatters.h+");
StyleMatters::init();
bool isMCPred = false;
if( fileName.Contains("MC") ) isMCPred = true;
bool isGenPred = false;
if( isMCPred && fileName.Contains("Gen") ) isGenPred = true;
// Get histograms from file
const unsigned int kNDists = 3;
TH1* hTrue[kNDists];
TH1* hPred[kNDists];
TH1* hMuonPt = 0;
TFile file(fileName,"READ");
for(unsigned int i = 0; i < kNDists; ++i) {
TString name = "";
if( i == 0 ) name = "TauJetPt";
else if( i == 1 ) name = "Ht";
else if( i == 2 ) name = "Mht";
file.GetObject("hPred"+name,hPred[i]);
if( !hPred[i] ) {
std::cerr << "ERROR: Histograms not found" << std::endl;
exit(-1);
}
hPred[i]->SetDirectory(0);
hPred[i]->UseCurrentStyle();
if( isMCPred ) {
file.GetObject("hTrue"+name,hTrue[i]);
if( !hTrue[i] ) {
std::cerr << "ERROR: Histograms not found" << std::endl;
exit(-1);
}
hTrue[i]->SetDirectory(0);
hTrue[i]->UseCurrentStyle();
}
}
file.GetObject("hMuonPt",hMuonPt);
if( !hMuonPt ) {
std::cerr << "ERROR: Histogram not found" << std::endl;
exit(-1);
}
hMuonPt->SetDirectory(0);
hMuonPt->UseCurrentStyle();
file.Close();
// Apply correction factors
for(unsigned int i = 0; i < kNDists; ++i) {
hPred[i]->Scale(scale);
}
// Set style
for(unsigned int i = 0; i < kNDists; ++i) {
TString xTitle = "";
if( i == 0 ) xTitle = "p_{T}(#tau) [GeV]";
else if( i == 1 ) xTitle = "H_{T} [GeV]";
else if( i == 2 ) xTitle = "#slash{H}_{T} [GeV]";
TString yTitle = "N(events) / ";
yTitle += static_cast<int>(hPred[i]->GetXaxis()->GetBinWidth(1));
yTitle += " GeV";
hPred[i]->GetXaxis()->SetTitle(xTitle);
hPred[i]->GetYaxis()->SetTitle(yTitle);
hPred[i]->SetMarkerStyle(20);
hPred[i]->SetMarkerColor(kRed);
hPred[i]->SetLineColor(hPred[i]->GetMarkerColor());
if( isMCPred ) {
hTrue[i]->GetXaxis()->SetTitle(xTitle);
hTrue[i]->GetYaxis()->SetTitle(yTitle);
hTrue[i]->SetLineColor(kBlue);
}
}
if( isGenPred ) hMuonPt->GetXaxis()->SetTitle("p_{T}(#mu^{gen}) [GeV]");
else hMuonPt->GetXaxis()->SetTitle("p_{T}(#mu) [GeV]");
hMuonPt->SetMarkerStyle(20);
hMuonPt->SetMarkerColor(kBlack);
hMuonPt->SetLineColor(hMuonPt->GetMarkerColor());
// Create legend
TLegend* leg = new TLegend(0.4,0.75,0.9,0.89);
leg->SetBorderSize(0);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetTextFont(42);
leg->SetTextSize(0.05);
if( isMCPred ) {
leg->AddEntry(hTrue[0],"MC Expectation");
if( isGenPred ) leg->AddEntry(hPred[0],"Gen-Based Pred.");
else leg->AddEntry(hPred[0],"Data-Based Pred.");
}
//.........这里部分代码省略.........
示例14: 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();
}
示例15: addhistos
///////////////////////////////////////////////////////////////////
//////// Go4 GUI example script addhistos.C
// J.Adamczewski, gsi, May 2006
// JAM May 2015: added support for 2d histograms
// NOTE: to be run in Go4 GUI local command line only!
// NEVER call this script in remote analysis process!!!
/////// Functionality:
// adds histogram of name2 to histogram of name1
/////// Usage:
// histogram name2 will be scaled by factor.
// (e.g. if factor==-1, his2 is substracted from his1)
// The draw flag switches if the results are displayed each time this makro is called
// if display is switched off, the result histogram is just updated in browser and existing displays
///////
Bool_t addhistos(const char* name1, const char* name2, Double_t factor, Bool_t draw)
{
if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
return kFALSE;
}
TString fullname1 = go4->FindItem(name1);
TObject* ob1=go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms
TH1 *his1(0), *his2(0);
if(ob1 && ob1->InheritsFrom("TH1"))
his1 = (TH1*) ob1;
if(his1==0) {
std::cout <<"addhistos could not get histogram "<<fullname1 << std::endl;
return kFALSE;
}
TString fullname2 = go4->FindItem(name2);
TObject* ob2=go4->GetObject(fullname2,1000); // 1000=timeout to get object from analysis in ms
if(ob2 && ob2->InheritsFrom("TH1"))
his2 = (TH1*)ob2;
if(his2==0) {
std::cout <<"addhistos could not get histogram "<<fullname2 << std::endl;
return kFALSE;
}
if((his1->GetDimension()) != (his2->GetDimension()))
{
std::cout <<"addhistos could not add histograms of different dimensions "<< std::endl;
return kFALSE;
}
TH1* result = (TH1*) his1->Clone();
TString n1 = his1->GetName();
TString n2 = his2->GetName();
TString t1 = his1->GetTitle();
TString t2 = his2->GetTitle();
TString soper;
if(factor>0)
soper.Form(") + %4.1E * (",factor);
else
soper.Form(") - %4.1E * (",-1*factor);
TString finalname = TString("(")+n1+soper+n2+")";
TString finaltitle = TString("(")+t1+soper+t2+")";
result->SetName(finalname);
result->SetTitle(finaltitle);
result->Sumw2();
result->Add(his2,factor);
result->SetDirectory(0);
TString rname = go4->SaveToMemory("Sums", result, kTRUE);
std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
if(draw) {
ViewPanelHandle vpanel = go4->StartViewPanel();
if(result->GetDimension()>1)
{
// superimpose mode is not supported for 2d histograms
go4->DrawItem(rname, vpanel);
}
else
{
go4->SetSuperimpose(vpanel,kTRUE);
go4->DrawItem(fullname1, vpanel);
go4->DrawItem(fullname2, vpanel);
go4->DrawItem(rname, vpanel);
}
}
return kTRUE;
}