本文整理汇总了C++中TH1::GetMaximum方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::GetMaximum方法的具体用法?C++ TH1::GetMaximum怎么用?C++ TH1::GetMaximum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1
的用法示例。
在下文中一共展示了TH1::GetMaximum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AutoSetYRange
double AutoSetYRange(TCanvas& canv, double maxScale) {
TList* list = canv.GetListOfPrimitives();
double maximum = 0;
int firstHist = -1;
// int isCanvasLogY = canv.GetLogy();
for (int iPrims = 0; iPrims <= list->LastIndex(); ++iPrims) {
TH1* hist = dynamic_cast<TH1*>(list->At(iPrims));
if (hist) {
//Remember histo to set maximum of, which is the first one drawn
if (firstHist == -1) {
firstHist = iPrims;
}
if (hist->GetMaximum() > maximum) {
maximum = hist->GetMaximum();
}
}
}
if (firstHist != -1) {
dynamic_cast<TH1*>(list->At(firstHist))->SetMaximum(maximum * maxScale);
return maximum * maxScale;
} else {
std::cout << __func__ << " No Histograms found" << std::endl;
return -1;
}
}
示例2: draw_output_pseudo
void plotter::draw_output_pseudo(TH1* output_, TH1D* pseudotruth_, TH1D* mctruth_, bool norm, TString file_name){
TH1* output = (TH1*) output_->Clone("output");
TH1D* pseudotruth = (TH1D*) pseudotruth_->Clone("pseudotruth");
TH1D* mctruth = (TH1D*) mctruth_->Clone("mctruth");
double ymax_temp = 0;
if(pseudotruth->GetMaximum() > ymax_temp) ymax_temp = pseudotruth->GetMaximum();
if(mctruth->GetMaximum() > ymax_temp) ymax_temp = mctruth->GetMaximum();
if(output->GetMaximum() > ymax_temp) ymax_temp = output->GetMaximum();
double ymax = 1.5 * ymax_temp;
pseudotruth->SetTitle(" ");
pseudotruth->GetYaxis()->SetRangeUser(0., ymax);
pseudotruth->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
if(norm) pseudotruth->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
else pseudotruth->GetYaxis()->SetTitle("events");
pseudotruth->GetYaxis()->SetTitleOffset(1.1);
pseudotruth->GetXaxis()->SetTitleOffset(0.9);
pseudotruth->GetYaxis()->SetTitleSize(0.05);
pseudotruth->GetXaxis()->SetTitleSize(0.05);
pseudotruth->GetYaxis()->SetNdivisions(505);
pseudotruth->SetLineWidth(4);
pseudotruth->SetLineColor(kRed);
mctruth->SetLineWidth(3);
mctruth->SetLineStyle(2);
mctruth->SetLineColor(kBlue);
output->SetLineColor(kBlack);
output->SetMarkerColor(kBlack);
output->SetMarkerStyle(8);
output->SetMarkerSize(1);
TCanvas *c= new TCanvas("Particle Level","",600,600);
gPad->SetLeftMargin(0.15);
TGaxis::SetMaxDigits(3);
pseudotruth->Draw("HIST SAME");
mctruth->Draw("HIST SAME");
output->Draw("E1 SAME");
TLegend *l;
if(mctruth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85);
else l=new TLegend(0.55,0.6,0.85,0.85);
l->SetBorderSize(0);
l->SetFillStyle(0);
l->AddEntry(output,"pseudo data","pl");
l->AddEntry(pseudotruth,"pseudo data truth","pl");
l->AddEntry(mctruth,"MC truth","pl");
l->SetTextSize(0.04);
l->Draw();
gPad->RedrawAxis();
c->SaveAs(directory + file_name + ".pdf");
delete c;
}
示例3: draw_output_stat
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){
// std::vector<double> sys = get_sys_errors();
// TH1* output_sys = add_error_bar(output, sys);
TH1* output = (TH1*) output_->Clone("output");
TH1* stat = (TH1*) stat_->Clone("stat");
TH1D* truth = (TH1D*) truth_->Clone("truth");
TCanvas *c = new TCanvas("c","",600,600);
double ymax;
gPad->SetLeftMargin(0.15);
if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum();
else ymax = 1.5 * output->GetMaximum();
TGaxis::SetMaxDigits(3);
output->SetTitle(" ");
output->GetYaxis()->SetRangeUser(0., ymax);
output->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
else output->GetYaxis()->SetTitle("events");
output->GetYaxis()->SetTitleOffset(1.1);
output->GetXaxis()->SetTitleOffset(0.9);
output->GetYaxis()->SetTitleSize(0.05);
output->GetXaxis()->SetTitleSize(0.05);
output->GetYaxis()->SetNdivisions(505);
output->SetLineColor(kBlack);
output->SetMarkerColor(kBlack);
output->SetMarkerStyle(8);
output->SetMarkerSize(1);
output->Draw("E1");
stat->SetLineColor(kBlack);
stat->SetMarkerColor(kBlack);
stat->SetMarkerStyle(8);
stat->SetMarkerSize(1);
gStyle->SetEndErrorSize(5);
truth->SetLineWidth(3);
truth->SetLineColor(kRed);
truth->SetLineStyle(2);
truth->Draw("HIST SAME");
stat->Draw("E1 SAME");
output->Draw("E1 SAME");
TLegend *l=new TLegend(0.5,0.65,0.85,0.85);
l->SetBorderSize(0);
l->SetFillStyle(0);
l->AddEntry(output,"data unfolded","pl");
l->AddEntry(truth,"MC particle level","pl");
l->SetTextSize(0.04);
l->Draw();
c->SaveAs(directory + file_name + ".pdf");
delete c;
}
示例4: Test
void Test(TH1* h, TH1* s, const char* test)
{
// Check that hist and sparse are equal, print the test result
cout << test << ": ";
// What exactly is "equal"?
// Define it as the max of 1/1000 of the "amplitude" of the
// original hist, or 1E-4, whatever is larger.
Double_t epsilon = 1E-4;
Double_t diffH = h->GetMaximum() - h->GetMinimum();
if (diffH < 0.) diffH = -diffH;
if (diffH / 1000. > epsilon)
epsilon = diffH / 1000.;
TH1* diff = (TH1*)s->Clone("diff");
diff->Add(h, -1);
Double_t max = diff->GetMaximum();
Double_t min = diff->GetMinimum();
if (max < -min) max = -min;
if (max < epsilon) cout << "SUCCESS";
else {
cout << "FAIL: delta=" << max;
TCanvas* c = new TCanvas(test, test);
c->Divide(1,3);
c->cd(1); h->Draw();
c->cd(2); s->Draw();
c->cd(3); diff->Draw();
TFile f("runsparse.root", "UPDATE");
c->Write();
delete c;
}
cout <<endl;
delete diff;
}
示例5: PlotOnCanvas
// Draw pT balance plots
void PlotOnCanvas(TH1& genHist, TH1& recoHist, TString plotname) {
TLine* line1 = new TLine(1.0, genHist.GetMinimum(),
1.0, genHist.GetMaximum());
line1->SetLineColor(4);
line1->SetLineWidth(2);
TCanvas canvas("canvas", "", 880, 600);
gStyle->SetOptStat(0);
genHist.Draw("hist");
line1->Draw();
recoHist.Draw("same");
recoHist.Draw("HIST same");
leg_hist = new TLegend(0.6,0.65,0.85,0.85);
leg_hist->AddEntry(&genHist,"Generator level","l");
leg_hist->AddEntry(&recoHist,"Calorimeter level","l");
leg_hist->SetFillColor(0);
leg_hist->Draw();
canvas.SaveAs(plotname+TString(".eps"));
canvas.SaveAs(plotname+TString(".gif"));
canvas.SaveAs(plotname+TString(".root"));
delete line1;
delete leg_hist;
}
示例6: ratioPlots
void ratioPlots( TCanvas* c1, TH1* h_r, TH1* h_i,
string xTitle, string yTitle, string savePath,
double fitMin=-100000, double fitMax=100000, bool doubleColFit=0 ){
double xMaximum = h_r->GetXaxis()->GetBinUpEdge(h_r->GetXaxis()->GetLast());
double xMinimum = h_r->GetXaxis()->GetBinLowEdge(h_r->GetXaxis()->GetFirst());
double yMaximum;
double yMinimum;
h_i->Sumw2();
h_r->Sumw2();
TLine* line1 = new TLine(xMinimum,1,xMaximum,1);
line1->SetLineColor(1);
line1->SetLineWidth(2);
line1->SetLineStyle(7);
TF1* fpol1 = new TF1("fpol1", "pol1", fitMin, fitMax);
fpol1->SetLineColor(2);
fpol1->SetLineWidth(3);
fpol1->SetLineStyle(7);
TH1* hRatio = (TH1*)h_r->Clone("clone_record");
hRatio->Divide(h_i);
yMaximum = hRatio->GetMaximum();
yMinimum = hRatio->GetMinimum(0);
hRatio->GetYaxis()->SetRangeUser(yMinimum/2.5,yMaximum+yMaximum/5);
hRatio->SetXTitle(xTitle.c_str());
hRatio->SetYTitle(yTitle.c_str());
hRatio->SetLineColor(9);
hRatio->SetLineWidth(2);
hRatio->SetMarkerStyle(8);
hRatio->Draw("e");
hRatio->Fit("fpol1", "L");
line1->Draw("SAME");
if(doubleColFit){
double p0=fpol1->GetParameter(0);
double p1=fpol1->GetParameter(1);
double endPoint=double(fitMax*p1)+p0;
double p1new=(endPoint-1)/(fitMax-fitMin);
char fun[100], text[100];
sprintf(fun,"x*(%f)+1",p1new);
sprintf(text,"Tangent: %f",p1new);
TF1* fnew = new TF1("fnew", fun, fitMin, fitMax);
fnew->SetLineColor(2);
fnew->SetLineWidth(3);
fnew->Draw("SAME");
TText* Title = new TText( fitMax/12, yMinimum, text);
Title->SetTextColor(2);
Title->SetTextSize(0.035);
Title->Draw("SAME");
}
c1->SaveAs(savePath.c_str());
c1->cd();
}
示例7: DrawNP
TCanvas* DrawNP(int np, TObjArray* harr, TCanvas* cnv)
{
if (!harr) harr = &histoArr;
if (!cnv) cnv = new TCanvas(Form("cnv%d",np),Form("cnv%d",np),900,700);
cnv->Clear();
cnv->Divide(2,1);
cnv->cd(1);
//
TH1* dxodd = (TH1*)harr->At(np*10+kDTXodd);
TH1* dxevn = (TH1*)harr->At(np*10+kDTXeven);
TH1* dxoddS =(TH1*)harr->At(np*10+kDTXoddSPL);
TH1* dxevnS =(TH1*)harr->At(np*10+kDTXevenSPL);
double max = TMath::Max(dxodd->GetMaximum(),dxevn->GetMaximum());
dxodd->SetMaximum(1.1*max);
dxodd->GetXaxis()->SetTitle("#DeltaX, #mum");
dxodd->SetTitle(Form("#DeltaX for clSize=%d",np));
dxodd->Fit("gaus","","");
dxevn->Fit("gaus","","sames");
//
dxoddS->Draw("sames");
dxevnS->Draw("sames");
//
gPad->Modified();
gPad->Update();
SetStPadPos(dxodd,0.75,0.97,0.8,1., -1,dxodd->GetLineColor());
SetStPadPos(dxevn,0.75,0.97,0.6,0.8, -1,dxevn->GetLineColor());
SetStPadPos(dxoddS,0.75,0.97,0.4,0.6, -1,dxoddS->GetLineColor());
SetStPadPos(dxevnS,0.75,0.97,0.2,0.4, -1,dxevnS->GetLineColor());
//
cnv->cd(2);
TH1* dz = (TH1*)harr->At(np*10+kDTZ);
dz->SetTitle(Form("#DeltaZ for clSize=%d",np));
dz->GetXaxis()->SetTitle("#DeltaZ, #mum");
dz->Fit("gaus");
TH1* dzS = (TH1*)harr->At(np*10+kDTZSPL);
dz->Draw("sames");
gPad->Modified();
gPad->Update();
SetStPadPos(dz,0.75,0.97,0.8,1., -1, dz->GetLineColor());
SetStPadPos(dzS,0.75,0.97,0.5,0.7, -1, dzS->GetLineColor());
gPad->Modified();
gPad->Update();
//
cnv->cd();
return cnv;
}
示例8: annconvergencetest
void annconvergencetest( TDirectory *lhdir )
{
TCanvas* c = new TCanvas( "MLPConvergenceTest", "MLP Convergence Test", 150, 0, 600, 580*0.8 );
TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" );
TH1* estimatorHistTest = (TH1*)lhdir->Get( "estimatorHistTest" );
Double_t m1 = estimatorHistTrain->GetMaximum();
Double_t m2 = estimatorHistTest ->GetMaximum();
Double_t max = TMath::Max( m1, m2 );
m1 = estimatorHistTrain->GetMinimum();
m2 = estimatorHistTest ->GetMinimum();
Double_t min = TMath::Min( m1, m2 );
estimatorHistTrain->SetMaximum( max + 0.1*(max - min) );
estimatorHistTrain->SetMinimum( min - 0.1*(max - min) );
estimatorHistTrain->SetLineColor( 2 );
estimatorHistTrain->SetLineWidth( 2 );
estimatorHistTrain->SetTitle( TString("MLP Convergence Test") );
estimatorHistTest->SetLineColor( 4 );
estimatorHistTest->SetLineWidth( 2 );
estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" );
estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" );
estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 );
estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 );
estimatorHistTrain->Draw();
estimatorHistTest ->Draw("same");
// need a legend
TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20,
1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 );
legend->AddEntry(estimatorHistTrain,"Training Sample","l");
legend->AddEntry(estimatorHistTest,"Test sample","l");
legend->Draw("same");
legend->SetMargin( 0.3 );
c->cd();
TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-(
c->Update();
TString fname = "plots/annconvergencetest";
TMVAGlob::imgconv( c, fname );
}
示例9: Fill
TH1F *stabilityHist(TGraphErrors *g_data, double& y_err_mean){
//------------------------------
Double_t *Y=g_data->GetY();
Double_t *EY = g_data->GetEY();
TH1 *obj = (TH1*) g_data->GetYaxis()->GetParent();
TH1F *hist_corr = new TH1F("hist_"+TString(g_data->GetName()),"",
g_data->GetN(), obj->GetMinimum(), obj->GetMaximum());
hist_corr->GetXaxis()->SetLabelSize(0);
hist_corr->GetYaxis()->SetLabelSize(0);
for(int i =0; i < g_data->GetN(); i++){
hist_corr -> Fill(Y[i]);
y_err_mean+=EY[i];
}
y_err_mean/=g_data->GetN();
return hist_corr;
}
示例10: 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;
}
示例11: RenderHisto
void RenderHisto( TObject * obj, TCanvas * canvas )
{
assert(obj->InheritsFrom("TH1")) ;
TH1 * histo = dynamic_cast<TH1*>(obj) ;
assert(histo) ;
TString histo_option = ((TH1 *)obj)->GetOption() ;
if ((histo_option.Contains("ELE_LOGY")==kTRUE)&&(histo->GetMaximum()>0))
{ canvas->SetLogy(1) ; }
int histo_name_flag = 1 ; // use 0 to switch off
if ( obj->InheritsFrom("TH2") )
{
gStyle->SetPalette(1) ;
gStyle->SetOptStat(110+histo_name_flag) ;
}
else if ( obj->InheritsFrom("TProfile") )
{ gStyle->SetOptStat(110+histo_name_flag) ; }
else // TH1
{ gStyle->SetOptStat(111110+histo_name_flag) ; }
}
示例12: boostcontrolplots
void boostcontrolplots( TDirectory *boostdir ) {
const Int_t nPlots = 4;
Int_t width = 900;
Int_t height = 600;
char cn[100];
const TString titName = boostdir->GetName();
sprintf( cn, "cv_%s", titName.Data() );
TCanvas *c = new TCanvas( cn, Form( "%s Control Plots", titName.Data() ),
width, height );
c->Divide(2,2);
const TString titName = boostdir->GetName();
TString hname[nPlots]={"Booster_BoostWeight","Booster_MethodWeight","Booster_ErrFraction","Booster_OrigErrFraction"};
for (Int_t i=0; i<nPlots; i++){
Int_t color = 4;
TPad * cPad = (TPad*)c->cd(i+1);
TH1 *h = (TH1*) boostdir->Get(hname[i]);
TString plotname = h->GetName();
h->SetMaximum(h->GetMaximum()*1.3);
h->SetMinimum( 0 );
h->SetMarkerColor(color);
h->SetMarkerSize( 0.7 );
h->SetMarkerStyle( 24 );
h->SetLineWidth(1);
h->SetLineColor(color);
h->Draw();
c->Update();
}
// write to file
TString fname = Form( "plots/%s_ControlPlots", titName.Data() );
TMVAGlob::imgconv( c, fname );
}
示例13: drawPlots
//.........这里部分代码省略.........
if (wleg->drawoption.size()) myHisto->SetDrawOption(wleg->drawoption);
myHisto->Add2Legend(wleg->leg);
}
if (myHisto->statsAreOn()) {
myHisto->DrawStats();
wp->vp->Update();
}
myHisto->ApplySavedStyle();
wp->vp->Update();
}
} // histos loop
/***************************************************
* LOOP OVER HISTOS DEFINED FOR ALTERNATE Y-AXIS
***************************************************/
Float_t rightmax=0.0,rightmin=0.0;
Float_t scale=0.0;
for (unsigned j = 0; j < wp->altyh_ids.size(); j++) {
string& hid = wp->altyh_ids[j];
map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid);
if (it == glmap_id2histo.end()) {
cerr << "ERROR: histo id " << hid << " never defined in layout" << endl;
exit (-1);
}
wTH1 *myHisto = it->second;
TH1 *h = myHisto->histo();
if (!j) {
//scale second set of histos to the pad coordinates
rightmin = h->GetMinimum();
rightmax = 1.1*h->GetMaximum();
scale = gPad->GetUymax()/rightmax;
}
TH1 *scaled=(TH1 *)h->Clone(Form("%s_%d",h->GetName(),ipad));
scaled->Scale(scale);
scaled->Draw("same");
//draw an axis on the right side
TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
gPad->GetUxmax(), gPad->GetUymax(),
rightmin,rightmax,505,"+L");
axis->Draw();
gPad->Update();
if (drawlegend && myHisto->GetLegendEntry().size()) {
if (wleg->drawoption.size()) myHisto->SetDrawOption(wleg->drawoption);
myHisto->Add2Legend(wleg->leg);
}
}
/***************************************************
* LOOP OVER GRAPHS DEFINED FOR PAD...
***************************************************/
#if 0
TMultiGraph *mg;
if (graph_ids.size())
mg = new TMultiGraph();
#endif
for( unsigned j = 0; j < wp->graph_ids.size(); j++ ) {
string& gid = wp->graph_ids[j];
wGraph_t *wg = findGraph(gid);
示例14: PIDEnergy
//______________________________________________________________________________
void PIDEnergy()
{
// Main method.
Char_t tmp[256];
// load CaLib
gSystem->Load("libCaLib.so");
// general configuration
const Char_t* data = "Data.PID.E0";
const Char_t* hName = "CaLib_PID_Energy_Proton_PID_Energy";
// configuration (December 2007)
//const Char_t calibration[] = "LD2_Dec_07";
//const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Dec_07/AR/out/ARHistograms_CB_RUN.root";
//const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/Dec_07/MC/calibration/all.root";
// configuration (February 2009)
//const Char_t calibration[] = "LD2_Feb_09";
//const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Feb_09/AR/out/ARHistograms_CB_RUN.root";
//const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/Feb_09/MC/calibration/all.root";
// configuration (May 2009)
const Char_t calibration[] = "LD2_May_09";
const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/May_09/AR/out/ARHistograms_CB_RUN.root";
const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/May_09/MC/calibration/all.root";
// get number of sets
Int_t nSets = TCMySQLManager::GetManager()->GetNsets(data, calibration);
// create canvas
Int_t n = TMath::Sqrt(nSets);
TCanvas* cOverview = new TCanvas("c", "c", 1200, 900);
cOverview->Divide(n, nSets / n + 1);
// create arrays
Double_t* pos = new Double_t[nSets+1];
Double_t* fwhm = new Double_t[nSets+1];
// total sum histogram
TH1* hTot = 0;
// load MC histo
TFile* fMC = new TFile(mcFile);
TH2* hMC2 = (TH2*) fMC->Get(hName);
TH1* hMC = hMC2->ProjectionX("mc");
hMC->SetLineColor(kBlue);
// loop over sets
for (Int_t i = 0; i < nSets; i++)
{
// create file manager
TCFileManager m(data, calibration, 1, &i, filePat);
// get histo
TH2* h2 = (TH2*) m.GetHistogram(hName);
// skip empty histo
if (!h2) continue;
// project histo
sprintf(tmp, "Proj_%d", i);
TH1* h = (TH1*) h2->ProjectionX(tmp);
//TH1* h = (TH1*) h2->ProjectionX(tmp, 9, 9);
//h->Rebin(4);
// add to total histogram
if (!hTot) hTot = (TH1*) h->Clone();
else hTot->Add(h);
// fit histo
cOverview->cd(i+1);
h->SetLineColor(kBlack);
h->Draw();
hMC->Scale(h->GetMaximum()/hMC->GetMaximum());
hMC->DrawCopy("same");
}
}
示例15: recurseOverKeys
void recurseOverKeys(TDirectory *target, TString imageType) {
// TString path( (char*)strstr( target->GetPath(), ":" ) );
// path.Remove( 0, 2 );
// cout << path << endl;
// sourceFile->cd( path );
target->cd();
TDirectory *current_sourcedir = gDirectory;
TKey *key;
TIter nextkey(current_sourcedir->GetListOfKeys());
TCanvas *canvasDefault = new TCanvas();
while ( (key = (TKey*)nextkey() ) ) {
TObject* obj = key->ReadObj();
if (obj->IsA()->InheritsFrom("TH1") ) {
// **************************
// Plot & Save this Histogram
TH1* h = (TH1*)obj;
h->SetStats(displayStatsBox);
TString histName = h->GetName();
// Now to label the X-axis!
// if (autoLabelXaxis) {
// if ( histName.Contains("Phi") ) {
// h->GetXaxis()->SetTitle("#phi");
// } else if ( histName.Contains("Eta") ) {
// h->GetXaxis()->SetTitle("#eta");
// } else if ( histName.Contains("Pt") ) {
// h->GetXaxis()->SetTitle("p_{T} (GeV)");
// } else if ( histName.Contains("Et") ) {
// h->GetXaxis()->SetTitle("E_{T} (GeV)");
// }
// }
// h->SetLineColor(lineColor);
// h->SetLineWidth(lineWidth);
// ********************************
// A trick to decide whether to have log or no-log y axis
// get hist max y value
if (autoLogYaxis) {
Double_t testYvalue = h->GetMaximum();
//cout << testYvalue << endl;
if (testYvalue > 1.0) {
Double_t maxy = log10(testYvalue);
// get hist min y value
Double_t miny = log10(h->GetMinimum(1.0));
// log scale if more than 3 powers of 10 between low and high bins
if ( (maxy-miny) > 3.0 ) {
canvasDefault->SetLogy(1);
}
}
}
// End of log or no-log y axis decision
// ********************************
h->Draw(drawOptions1D);
canvasDefault->Modified();
canvasDefault->Update();
// gPad->Print(outputFolder+path+"/"+histName+outputType);
TString outputFolder = "images/";
gPad->Print(outputFolder+histName+"."+imageType);
// To store the root file name in image file name:
//canvasDefault->Print(outputFolder+histFileName+histName+outputType);
// if (printOutput) cout << outputFolder+path+"/"+histName+outputType << endl;
canvasDefault->SetLogy(0); // reset to no-log - prevents errors
// **************************
} else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) {
// it's a subdirectory
cout << "Found subdirectory " << obj->GetName() << endl;
// gSystem->MakeDirectory(outputFolder+path+"/"+obj->GetName());
// obj is now the starting point of another round of merging
// obj still knows its depth within the target file via
// GetPath(), so we can still figure out where we are in the recursion
recurseOverKeys((TDirectory*)obj, imageType);
} // end of IF a TDriectory
} // end of LOOP over keys
}