本文整理汇总了C++中TH1F::GetSum方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::GetSum方法的具体用法?C++ TH1F::GetSum怎么用?C++ TH1F::GetSum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::GetSum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unfoldPt
//.........这里部分代码省略.........
{
test->SetParameter(i,1);
}
hdphi2->SetXTitle("|#Delta#phi|");
hdphi2->SetYTitle("Arbitrary Normalization");
hdphi2->Fit("histFunMC","M");
hdphi->SetXTitle("|#Delta#phi|");
hdphi->SetYTitle("Arbitrary Normalization");
hdphi->Fit("histFun","M");
hdphi->SetStats(0);
hdphi->Draw();
for (int i=0;i<nPtBin+1;i++) {
TF1 *testPlot = new TF1(Form("histFun%d",i),myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1);
testPlot->SetParameter(i,test->GetParameter(i));
testPlot->SetLineColor(i+2);
testPlot->Draw("same");
}
int total=0,totalMC=0;
for (int i=0;i<nPtBin;i++){
if (test->GetParameter(i)==0) continue;
hptUnfold->SetBinContent(i+1,fabs(test->GetParameter(i)));
hptUnfold->SetBinError(i+1,test->GetParError(i));
hptMC->SetBinContent(i+1,fabs(test2->GetParameter(i)));
hptMC->SetBinError(i+1,test2->GetParError(i));
total+=fabs(test->GetParameter(i));
totalMC+=fabs(test2->GetParameter(i));
}
hptUnfold->SetEntries(total);
hptMC->SetEntries(totalMC);
TCanvas *c3 = new TCanvas("c3","",600,600);
hpt->Sumw2();
hptH->Sumw2();
//hptMC->Sumw2();
double normMC=0;
double norm=0;
double normTruth=0;
hptUnfold->SetMarkerColor(2);
hptUnfold->SetMarkerStyle(4);
// hptUnfold->Scale(1./hptUnfold->GetEntries());
TH1F *hptCorrected = (TH1F*)hptUnfold->Clone();
hptCorrected->SetName("hptCorrected");
hptMC->Divide(hpt);
hptCorrected->Divide(hptMC);
for (int i=0;i<nPtBin;i++){
if (hptMC->GetBinContent(i)<=0.001)hptCorrected->SetBinContent(i,0);
}
hptCorrected->Scale(1./(hptCorrected->GetSum()));
hptCorrected->SetMarkerStyle(20);
hpt->Scale(1./hpt->GetEntries());
if (hptH->GetEntries())hptH->Scale(1./hptH->GetEntries());
hptTemp->SetXTitle("ln(P_{T}) GeV/c");
hptTemp->SetYTitle("Arbitrary Normalization");
hptTemp->Draw();
hptH->SetXTitle("ln(P_{T}) GeV/c");
hptH->SetYTitle("Arbitrary Normalization");
hptH->Draw("hist");
hptH->SetLineColor(4);
hpt->Draw("hist same ");
hptCorrected->Draw("same");
TH1F *hptUnfoldRatio = (TH1F*)hptUnfold->Clone();
hptUnfoldRatio->SetName("hptUnfoldRatio");
hptUnfoldRatio->Scale(1./hptUnfoldRatio->GetSum());
//hptUnfoldRatio->Divide(hptH);
TH1F *hptCorrectedRatio = (TH1F*)hptCorrected->Clone();
hptCorrectedRatio->SetName("hptCorrectedRatio");
hptCorrectedRatio->SetMarkerColor(2);
//hptCorrectedRatio->Divide(hptH);
TCanvas *c4 = new TCanvas("c4","",600,600);
TLine *l = new TLine(-2.5,1,2.5,1);
hptUnfoldRatio->Draw();
hptMC->Draw("same");
hptCorrectedRatio->Draw("same");
l->Draw("same");
}
示例2: FitSignal
//.........这里部分代码省略.........
double parp = par + dirSize*spar;
fits[ind]->SetParameter(ipar,parp);
double yp = fits[ind]->Eval(xx);
vv(i,0) = limitBinSize*(yp-y0)/(dirSize*spar);
fits[ind]->SetParameter(ipar,par);
//printf("%f %f %f\n",yp,y0,spar);
}
//vv.Print();
if(debug) printf("start matrix %i\n",ibin);
TMatrixD tempM(matrix, TMatrixDBase::kMult, vv);
//matrix.Print();
TMatrixD tempN(vv, TMatrixDBase::kTransposeMult, tempM);
//tempN.Print();
float bgSig = 0.0;
if(tempN(0,0)>0.0) bgSig = sqrt(tempN(0,0));
// ****** hack temp **********
bgSig = 0.3*y0;
// file hists to be saved
if(debug) printf("start fill %i\n",ibin);
if(ind==0) {
//printf("filling cc %i %f\n",ibin,h->GetBinContent(ibin));
cc->SetBinContent(ibin,h->GetBinContent(ibin));
//printf("getting cc %i %f\n",ibin,cc->GetBinContent(ibin));
ccBg->SetBinContent(ibin,yy);
ccBgErr->SetBinContent(ibin,bgSig);
ccBgP->SetBinContent(ibin,yy+bgSig);
ccBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0)));
//if(ibin==27) {
//printf("bg %f %f \n",yy,bgSig);
//}
} else {
cp->SetBinContent(ibin,h->GetBinContent(ibin));
cpBg->SetBinContent(ibin,yy);
cpBgErr->SetBinContent(ibin,bgSig);
cpBgP->SetBinContent(ibin,yy+bgSig);
cpBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0)));
}
if(debug) printf("end fill %i\n",ibin);
}
*/
}
printf("cc plus BG=%f\n",ccBgP->GetSum());
printf("cc minus BG=%f\n",ccBgM->GetSum());
printf("cp plus BG=%f\n",cpBgP->GetSum());
printf("cp minus BG=%f\n",cpBgM->GetSum());
char fn[100];
if(mode==0) {
sprintf(fn,"FitSignal_%d",fitMode);
savePlot(c,fn);
} else if(mode==1) {
sprintf(fn,"FitSignalLin_%d",fitMode);
savePlot(c,fn);
}
//if(mode!=0) return;
// plot of fit results
gStyle->SetOptLogy(0);
c = NewCanvas();
c->Divide(1,2);
c->cd(1);
cc->Draw();
ccBg->Draw("SAME");
c->cd(2);
ccBgErr->SetMinimum(0.0); ccBgErr->SetMaximum(4.0);
ccBgErr->Draw();
ccBgP->SetLineStyle(2); ccBgP->Draw("SAME");
ccBgM->SetLineStyle(2); ccBgM->Draw("SAME");
savePlot(c,"FitSignalResultsCC");
c = NewCanvas();
c->Divide(1,2);
c->cd(1);
cp->Draw();
cpBg->Draw("SAME");
c->cd(2);
cpBgErr->SetMinimum(0.0); cpBgErr->SetMaximum(4.0);
cpBgErr->Draw();
cpBgP->SetLineStyle(2); cpBgP->Draw("SAME");
cpBgM->SetLineStyle(2); cpBgM->Draw("SAME");
savePlot(c,"FitSignalResultsCP");
char title[100];
if(name) {
sprintf(title,"TPeaksHiggs_FitSignalHist_%s.root",name);
TFile* ff = new TFile(title,"RECREATE");
gROOT->GetList()->Write();
ff->Close();
}
}
示例3: Total_fit
//5_3_6: gROOT->ProcessLine(".include /afs/cern.ch/cms/slc5_amd64_gcc462/lcg/roofit/5.32.03-cms9/include/")
//7_1_0: gROOT->ProcessLine(".include /afs/cern.ch/cms/slc6_amd64_gcc481/lcg/roofit/5.34.22-cms2/include/")
//Usage: .x Total_fit.C+("root://eoscms//eos/cms/store/group/dpg_ecal/alca_ecalcalib/lpernie/
//ALL_Neutrino_Pt2to20_AVE40BX25_FoldEtaRing_eta01/iter_0/epsilonPlots.root", "Comp_2015A", "", true, true, false )
void Total_fit( TString File, TString folder, TString Hname, bool RunOnAll, bool isEB=true, bool Are_pi0_=true ){
//OLD STYLE
gROOT->SetStyle("Plain");
gStyle->SetPalette(1);
gStyle->SetOptStat(1111111); // Show overflow, underflow + SumOfWeights
gStyle->SetOptFit(111110);
gStyle->SetOptFile(1);
gStyle->SetMarkerStyle(20);
gStyle->SetMarkerSize(.3);
gStyle->SetMarkerColor(1);
TCanvas* myc1 = new TCanvas("myc1"," ",500,500);
myc1->SetLeftMargin(0.16);
//Files
TString Comm = "mkdir -p " + folder;
system( Comm.Data() );
cout<<"Opening: "<<File.Data()<<endl;
TFile* fin = TFile::Open(File.Data());
//Histos
int MaxH = 1;
if( RunOnAll ) MaxH = isEB ? 61200 : 14648;
cout<<"Running on "<<MaxH<<" events"<<endl;
for(int i=0; i<MaxH; i++){
std::stringstream ind; ind << (int) i;
TString EBEE = isEB ? "EB" : "EE";
TString BarEnd = isEB ? "Barrel" : "Endcap";
TString isPi0 = Are_pi0_ ? "pi0" : "eta";
TString name = BarEnd + "/epsilon_" + EBEE + "_iR_" + TString(ind.str());
if( ! RunOnAll ) name = Hname;
TH1F *h = (TH1F*) fin->Get( name.Data() );
h->SetTitle("");
TString outName = folder + "/" + EBEE + "_iR_" + TString(ind.str()) + "_" + isPi0 + ".png";
TString outName1 = folder + "/" + EBEE + "_iR_" + TString(ind.str()) + "_" + isPi0 +".pdf";
TString outName2 = folder + "/" + EBEE + "_iR_" + TString(ind.str()) + "_" + isPi0 +".C";
TString outName3 = folder + "/" + EBEE + "_iR_" + TString(ind.str()) + "_" + isPi0 +".root";
//Fit Method
int ngaus=1; //1: simple Gaussian, 2: two Gaussian
float xlo = Are_pi0_? 0.08:0.4, xhi = Are_pi0_? 0.22:0.65;
RooRealVar x("x","#gamma#gamma invariant mass",xlo, xhi, "GeV/c^{2}");
RooDataHist dh("dh","#gamma#gamma invariant mass",RooArgList(x),h);
RooRealVar mean("mean","#pi^{0} peak position", Are_pi0_? 0.116:0.57, Are_pi0_? 0.105:0.5, Are_pi0_? 0.150:0.62,"GeV/c^{2}");
RooRealVar sigma("sigma","#pi^{0} core #sigma",0.013, 0.005,0.020,"GeV/c^{2}");
if(!isEB) {
mean.setRange( Are_pi0_? 0.10:0.45, Are_pi0_? 0.140:0.62); // 0.200
mean.setVal(Are_pi0_? 0.120:0.55);
sigma.setRange(0.005, 0.060);
}
if(isEB){
mean.setRange(Are_pi0_? 0.105:0.47, Are_pi0_? 0.155:0.62);
sigma.setRange(0.003, 0.030);
}
RooRealVar Nsig("Nsig","#pi^{0} yield",1000.,0.,1.e7);
Nsig.setVal( h->GetSum()*0.1);
RooGaussian gaus("gaus","Core Gaussian",x, mean,sigma);
RooRealVar sigmaTail("sigmaTail","#pi^{0} tail #sigma",0.040, 0.020,0.065,"GeV/c^{2}");
RooGaussian gaus2("gaus2","Tail Gaussian",x, mean,sigmaTail);
RooRealVar fcore("fcore","f_{core}",0.9,0.,1.);
RooAddPdf signal("signal","signal model",RooArgList(gaus,gaus2),fcore);
RooRealVar p0("p0","p0", 1000.,-1.e5,1.e5);
RooRealVar p1("p1","p1", -3000.,-1.e5,1.e5);
RooRealVar p2("p2","p2", 10000.,-1.e5,1.e5);
RooRealVar p3("p3","p3", -10000.,-1.e5,1.e5);
RooRealVar p4("p4","p4",-4000.,-1.e5,1.e5);
RooRealVar p5("p5","p5", 5.,-1.e5,1.e5);
RooRealVar p6("p6","p6", 6.,-1.e5,1.e5);
RooRealVar cb0("cb0","cb0", 0.2, -1.,1.);
RooRealVar cb1("cb1","cb1",-0.1, -1.,1.);
RooRealVar cb2("cb2","cb2", 0.1, -1.,1.);
RooRealVar cb3("cb3","cb3",-0.1, -0.5,0.5);
RooRealVar cb4("cb4","cb4", 0.1, -1.,1.);
RooRealVar cb5("cb5","cb5", 0.1, -1.,1.);
RooRealVar cb6("cb6","cb6", 0.3, -1.,1.);
RooArgList cbpars(cb0,cb1,cb2);
if(Are_pi0_) cbpars.add( cb3);
// if(isEB){
// cb3.setRange(-1,1.);
// cb4.setRange(-0.3,0.3);
// cbpars.add( cb4 );
// }
RooChebychev bkg("bkg","bkg model", x, cbpars );
RooRealVar Nbkg("Nbkg","background yield",1.e3,0.,1.e8);
Nbkg.setVal( h->GetSum()*0.8 );
RooAbsPdf* model=0;
//.........这里部分代码省略.........
示例4: PlotEffPt
//.........这里部分代码省略.........
histos[iEta][iType][0] = TH1toTH1(histNum,nPtBins,ptBins,false,"_new");
TH1F * histDen = (TH1F*)file->Get(name+LepQ+Type[iType]+denName[iType]+EtaBinName[iEta]);
if (lepSign==0) {
TH1F * histDenX = (TH1F*)file->Get(name+"Pos"+Type[iType]+denName[iType]+EtaBinName[iEta]);
histDen->Add(histDen,histDenX);
}
histos[iEta][iType][1] = TH1toTH1(histDen,nPtBins,ptBins,false,"_new");
}
}
int color[3] = {1,2,4};
int symbol[3] = {20,21,22};
TGraphAsymmErrors * eff[3][2];
for (int iEta=0; iEta<3; ++iEta) {
for (int iType=0; iType<2; ++iType) {
eff[iEta][iType] = new TGraphAsymmErrors();
eff[iEta][iType]->SetLineColor(color[iEta]);
eff[iEta][iType]->SetMarkerColor(color[iEta]);
eff[iEta][iType]->SetLineWidth(2);
eff[iEta][iType]->SetMarkerSize(2.5);
eff[iEta][iType]->SetMarkerStyle(symbol[iEta]);
if (iType==1)
eff[iEta][iType]->SetMarkerStyle(symbol[iEta]+4);
eff[iEta][iType]->Divide(histos[iEta][iType][0],histos[iEta][iType][1]);
}
}
// **************
// Tag-and-Probe
// **************
TString mass("massEEId_");
if (isMuId)
mass = "massMuMuId_";
TString TagQ("Pos");
int nPtBins = 7;
float ptBins[8] = {10,15,20,30,40,50,70,100};
TString PtBinName[7] = {"pt10to15",
"pt15to20",
"pt20to30",
"pt30to40",
"pt40to50",
"pt50to70",
"pt70to100"};
TString passName[2] = {"Pass","Fail"};
TH1F * histosTP[3][2];
for (int iEta=0; iEta<3; ++iEta) {
for (int iPass=0; iPass<2; ++iPass) {
histosTP[iEta][iPass] = new TH1F(passName[iPass]+EtaBinName[iEta],"",nPtBins,ptBins);
for (int iPt=0; iPt<nPtBins; ++iPt) {
TH1F * hist = (TH1F*)file->Get(mass+TagQ+EtaBinName[iEta]+PtBinName[iPt]+passName[iPass]);
float yield = hist->GetSum();
histosTP[iEta][iPass]->SetBinContent(iPt+1,yield);
}
}
}
TGraphAsymmErrors * effTP[3];
for (int iEta=0; iEta<3; ++iEta) {
effTP[iEta] = new TGraphAsymmErrors();
effTP[iEta]->SetLineColor(color[iEta]);
effTP[iEta]->SetMarkerColor(color[iEta]);
effTP[iEta]->SetLineWidth(2);
effTP[iEta]->SetMarkerSize(3);
effTP[iEta]->SetMarkerStyle(28);
histosTP[iEta][1]->Add(histosTP[iEta][0],histosTP[iEta][1]);
effTP[iEta]->Divide(histosTP[iEta][0],histosTP[iEta][1]);
}
TH2F * frame = new TH2F("frame","",2,10,50,2,yMin,yMax);
frame->GetYaxis()->SetTitle(yTitle);
frame->GetXaxis()->SetTitle("electron p_{T} [GeV/c]");
// frame->GetYaxis()->SetNdivisions(505);
TString LegName("Z#rightarrowee");
if (isMuId) {
frame->GetXaxis()->SetTitle("muon p_{T} [GeV/c]");
LegName = "Z#rightarrow#mu#mu";
}
TCanvas * canv = new TCanvas("canv","",900,700);
frame->Draw();
eff[EtaBin][0]->Draw("EPS");
eff[EtaBin][1]->Draw("EPS");
// effTP[EtaBin]->Draw("EPS");
TLegend * leg = new TLegend(0.6,0.2,0.9,0.5);
leg->SetFillColor(0);
leg->SetHeader(EtaLeg[EtaBin]);
leg->AddEntry(eff[EtaBin][0],"Z#rightarrow#tau#tau#rightarrowe+#mu","lp");
leg->AddEntry(eff[EtaBin][1],LegName,"lp");
// leg->AddEntry(effTP[EtaBin] ,LegName+" (T&P)","lp");
leg->Draw();
canv->Update();
canv->Print(fileName+"_"+name+numName0+"_"+denName0+"_"+EtaBinName[EtaBin]+".gif");
}
示例5: axis_proj
//.........这里部分代码省略.........
assert(hxy);
TH1F * ht = dynamic_cast<TH1F*>(hm->getHisto(
get_histo_prefix() + "_G4Hit_HitTime"));
assert(ht);
TH2F * hlat = dynamic_cast<TH2F*>(hm->getHisto(
get_histo_prefix() + "_G4Hit_LateralTruthProjection"));
assert(hlat);
h_norm->Fill("G4Hit Active", _calo_hit_container->size());
PHG4HitContainer::ConstRange calo_hit_range =
_calo_hit_container->getHits();
for (PHG4HitContainer::ConstIterator hit_iter = calo_hit_range.first;
hit_iter != calo_hit_range.second; hit_iter++)
{
PHG4Hit *this_hit = hit_iter->second;
assert(this_hit);
e_calo += this_hit->get_edep();
ev_calo += this_hit->get_light_yield();
// EM visible energy that is only associated with electron energy deposition
PHG4Particle* particle = _truth_container->GetParticle(
this_hit->get_trkid());
if (!particle)
{
cout <<__PRETTY_FUNCTION__<<" - Error - this PHG4hit missing particle: "; this_hit -> identify();
}
assert(particle);
if (abs(particle->get_pid()) == 11)
ev_calo_em += this_hit->get_light_yield();
const TVector3 hit(this_hit->get_avg_x(), this_hit->get_avg_y(),
this_hit->get_avg_z());
hrz->Fill(hit.Z(), hit.Perp(), this_hit->get_edep());
hxy->Fill(hit.X(), hit.Y(), this_hit->get_edep());
ht->Fill(this_hit->get_avg_t() - t0, this_hit->get_edep());
const double hit_azimuth = axis_azimuth.Dot(hit - vertex);
const double hit_polar = axis_polar.Dot(hit - vertex);
hlat->Fill(hit_polar, hit_azimuth, this_hit->get_edep());
}
}
if (_calo_abs_hit_container)
{
h_norm->Fill("G4Hit Absor.", _calo_abs_hit_container->size());
PHG4HitContainer::ConstRange calo_abs_hit_range =
_calo_abs_hit_container->getHits();
for (PHG4HitContainer::ConstIterator hit_iter = calo_abs_hit_range.first;
hit_iter != calo_abs_hit_range.second; hit_iter++)
{
PHG4Hit *this_hit = hit_iter->second;
assert(this_hit);
ea_calo += this_hit->get_edep();
}
}
if (verbosity > 3)
cout << "QAG4SimulationCalorimeter::process_event_G4Hit::" << _calo_name
<< " - SF = " << e_calo / (e_calo + ea_calo + 1e-9) << ", VSF = "
<< ev_calo / (e_calo + ea_calo + 1e-9) << endl;
if (e_calo + ea_calo > 0)
{
h = dynamic_cast<TH1F*>(hm->getHisto(get_histo_prefix() + "_G4Hit_SF"));
assert(h);
h->Fill(e_calo / (e_calo + ea_calo));
h = dynamic_cast<TH1F*>(hm->getHisto(get_histo_prefix() + "_G4Hit_VSF"));
assert(h);
h->Fill(ev_calo / (e_calo + ea_calo));
}
h = dynamic_cast<TH1F*>(hm->getHisto(
get_histo_prefix() + "_G4Hit_FractionTruthEnergy"));
assert(h);
h->Fill((e_calo + ea_calo) / total_primary_energy);
if (ev_calo > 0)
{
h = dynamic_cast<TH1F*>(hm->getHisto(
get_histo_prefix() + "_G4Hit_FractionEMVisibleEnergy"));
assert(h);
h->Fill(ev_calo_em / (ev_calo));
}
if (verbosity > 3)
cout << "QAG4SimulationCalorimeter::process_event_G4Hit::" << _calo_name
<< " - histogram " << h->GetName() << " Get Sum = " << h->GetSum()
<< endl;
return Fun4AllReturnCodes::EVENT_OK;
}