本文整理汇总了C++中TH1F::Delete方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1F::Delete方法的具体用法?C++ TH1F::Delete怎么用?C++ TH1F::Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1F
的用法示例。
在下文中一共展示了TH1F::Delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMAD
//*************************************************************
std::pair<Double_t,Double_t> getMAD(TH1F *histo)
//*************************************************************
{
int nbins = histo->GetNbinsX();
Double_t median = getMedian(histo).first;
Double_t x_lastBin = histo->GetBinLowEdge(nbins+1);
const char *HistoName =histo->GetName();
TString Finalname = Form("resMed%s",HistoName);
TH1F *newHisto = new TH1F(Finalname,Finalname,nbins,0.,x_lastBin);
Double_t *residuals = new Double_t[nbins];
Double_t *weights = new Double_t[nbins];
for (int j = 0; j < nbins; j++) {
residuals[j] = TMath::Abs(median - histo->GetBinCenter(j+1));
weights[j]=histo->GetBinContent(j+1);
newHisto->Fill(residuals[j],weights[j]);
}
Double_t theMAD = (getMedian(newHisto).first)*1.4826;
newHisto->Delete("");
std::pair<Double_t,Double_t> result;
result = std::make_pair(theMAD,theMAD/histo->GetEntries());
return result;
}
示例2: MC_EexComponents
void MC_EexComponents(){
Styles style; style.setPadsStyle(1); style.applyStyle();
TString NameTrees[3] = {"AWG82/ntuples/small/RAll_RunAll.root",
"AWG82/ntuples/small/uds_RunAll.root", "AWG82/ntuples/small/ccbar_RunAll.root"};
TChain gen("ntp1"), cont("ntp1");
gen.Add(NameTrees[0]);
for(int t=1; t<3; t++) cont.Add(NameTrees[t]);
double totMCB = 0, totuds = 0, totccbar = 0, totdata = 0, totOffdata = 0;
getNumberB(NameTrees[0], "All", totMCB, totdata, totuds, totccbar, totOffdata);
double wuds = totMCB/totuds*2.09/1.05;
double nTotal, yield[4], maxi;
// TString cuts[] = {"(candPMiss>0.2&&candQ2>4&&candType==2&&(MCType==2||MCType==4||MCType==6))*weight",
// "(candPMiss>0.2&&candQ2>4&&candType==2&&(MCType==1||MCType==3||MCType==5||MCType>6))*weight",
// "(candPMiss>0.2&&candQ2>4&&candType==2&&(MCType==0))*weight",
// "(candPMiss>0.2&&candQ2>4&&candType==2)*weight"};
TString cuts[] = {"(candMvaDl>0.48&&candPMiss>0.2&&candQ2>4&&candType==2&&(MCType==2||MCType==4||MCType==6))*weight",
//"(candPMiss>0.2&&candQ2>4&&candType==2&&(MCType==1||MCType==3||MCType==5||MCType>6))*weight",
"(candMvaDl>0.48&&candPMiss>0.2&&candQ2>4&&candType==2&&(MCType>12))*weight",
"(candMvaDl>0.48&&candPMiss>0.2&&candQ2>4&&candType==2&&(MCType==0))*weight",
"(candMvaDl>0.48&&candPMiss>0.2&&candQ2>4&&candType==2)*weight"};
TH1F *hCount = new TH1F("hCount","",100,-4,12);
for(int i=0; i<3; i++) {
gen.Draw("candM2>>hCount",cuts[i]);
yield[i] = hCount->Integral();
}
cont.Draw("candM2>>hCount",cuts[3]);
yield[3] = hCount->Integral()*wuds;
gen.Draw("candM2>>hCount",cuts[3]);
nTotal = hCount->Integral();
nTotal += yield[3];
hCount->Delete();
TCanvas can("can","BDT variables");TPad *cPad;
//can.Divide(2,4);
TString Variable[] = {"candEExtra","candDeltaE","candDmass","candDeltam",
"candBTagDmass","candBTagDeltam","candTagChargedMult-0.5","candCosT"};
// int bins[] = {32,24,40,22,24,22,7,40}, colors[] = {4,2,1,8};
// double xrange[8][2] = {{0,1.6}, {-0.072,0.072}, {1.94,2.06}, {0.13,0.152},
// {1.841,1.889}, {0.13,0.152}, {1.5,8.5}, {-1,1}};
int bins[] = {10,24,40,22,20,15,7,40}, colors[] = {4,2,1,8};
double xrange[8][2] = {{0,0.5}, {-0.072,0.072}, {1.94,2.06}, {0.13,0.152},
{1.841,1.889}, {0.13,0.152}, {1.5,8.5}, {-1,1}};
TString yTitleEnd[] = {"50 MeV)", "6 MeV)", "3 MeV)", "1 MeV)", "2 MeV)", "1 MeV)", "",""};
TString xTitle[] = {"E_{Extra} (GeV)", "#DeltaE (GeV)", "", "",
"", "", "B_{tag} charged multiplicity", "cos(#Delta#theta_{T})"};
TString labels[] = {"Signal + norm.", "D**l#nu", "Other BB", "Continuum"};
double legW = 0.3, legH = 0.3;
double legX = 1-style.PadRightMargin-0.02, legY = 1-style.PadTopMargin-0.02;
TLegend leg(legX-legW, legY-legH, legX, legY);
leg.SetTextSize(style.LabelSize); leg.SetFillColor(0);
leg.SetTextFont(style.nFont); leg.SetBorderSize(0);
TH1F* h[8][4];
for(int pad=0; pad<1; pad++){
cPad = (TPad *)can.cd(pad+1);
maxi = -99;
for(int i=0; i<4; i++) {
TString hname = "h"; hname += pad; hname += i;
h[pad][i] = new TH1F(hname,"",bins[pad],xrange[pad][0],xrange[pad][1]);
h[pad][i]->SetLineWidth(2); h[pad][i]->SetLineColor(colors[i]);
TString vari = Variable[pad]; vari += ">>"; vari += hname;
if(i<3) gen.Draw(vari,cuts[i]);
else cont.Draw(vari,cuts[i]);
if(pad==0) {
h[pad][i]->Integral();
//labels[i] += RoundNumber(yield[i]*100,0,nTotal); labels[i] += "%)";
leg.AddEntry(h[pad][i],labels[i]);
}
h[pad][i]->Scale(1000/h[pad][i]->Integral());
if(h[pad][i]->GetMaximum()>maxi) maxi = h[pad][i]->GetMaximum();
}
if(pad==0) maxi *= 1.1;
if(pad==6) h[pad][0]->SetNdivisions(207,"x");
h[pad][0]->SetMaximum(maxi*1.1);
h[pad][0]->SetMinimum(0);
h[pad][0]->Draw();
if(pad==0) {
style.fixYAxis(h[pad][0],cPad); style.applyStyle();
leg.Draw();
} else {
h[pad][0]->SetTitleOffset(style.yTitleOffset,"y");
cPad->SetLeftMargin(style.PadLeftMargin);
}
TString yTitle = "Entries/(";
if(pad<6) yTitle += yTitleEnd[pad];
else if(pad==6) yTitle = "Entries";
else yTitle = "Entries/(0.05)";
style.setTitles(h[pad][0],xTitle[pad],yTitle);
h[pad][3]->Draw("same");h[pad][2]->Draw("same");h[pad][1]->Draw("same");h[pad][0]->Draw("same");
}
TString pName = "public_html/MC_EexComponents.eps";
can.SaveAs(pName);
for(int pad=0; pad<1; pad++){
for(int i=0; i<4; i++){
h[pad][i]->Delete();
}
}
//.........这里部分代码省略.........
示例3: nullSlice
//............................................
// Constructor for accpetance from a ROOT Tfile
SlicedAcceptance::SlicedAcceptance( string type, string fileName,string histName, bool fluctuate, bool quiet ) :
slices(), nullSlice(new AcceptanceSlice(0.,0.,0.)), tlow(), thigh(), beta(), _sortedSlices(false), maxminset(false), t_min(0.), t_max(0.), _hasChecked(false), _storedDecision(false)
{
if(!quiet) cout << "Root file being used for acceptance" << endl;
(void)type;
if( type != "RootFile" ) { }//do nothing for now
string fullFileName = StringProcessing::FindFileName( fileName, quiet );
if( !quiet ) cout << "Opening: " << fullFileName << endl;
TFile* file = TFile::Open(TString(fullFileName));
if(!quiet) cout << "File " << fullFileName << " opened!" << endl;
TH1F* histo = (TH1F*)file->Get(TString(histName));
if(!quiet) cout << "Histo " << histName << " opened!" << endl;
histo->Draw();
if(!quiet) cout << "Histo " << histName << " drawn!" << endl;
// histo->Sumw2();
if(fluctuate){
cout << "WARNING! You have fluctuated the acceptance." << endl;
cout << "WARNING! This is for systematic studies only. " << endl;
cout << "WARNING! Projections and pull fits will have a different fluctuated acceptance to the PDF you fit with." << endl;
cout << "WARNING! ONLY USE FluctuateAcceptance:True FOR SYSTEMATIC STUDIES" << endl;
TRandom3 * rng = new TRandom3(0);
//Randomly fluctuate bin contents within error:
for (int l = 1; l <= histo->GetNbinsX(); ++l){
if(!quiet) cout << "Bin content and error before: " << histo->GetBinContent(l) << "+/-" << histo->GetBinError(l);
histo->SetBinContent(l,rng->Gaus(histo->GetBinContent(l),histo->GetBinError(l)));
if(!quiet) cout << " and after: " << histo->GetBinContent(l) << "+/-" << histo->GetBinError(l) << endl;
}
delete rng;
}
histo->Scale(1./(histo->GetBinContent(histo->GetMaximumBin())));
histo->SetMinimum(0);
double maxend = histo->GetBinLowEdge(histo->GetNbinsX()) + histo->GetBinWidth(histo->GetNbinsX());
double height;
double start;
double end = histo->GetBinLowEdge(histo->GetNbinsX()) + histo->GetBinWidth(histo->GetNbinsX());
double dheight;
for (int l = 1; l <= histo->GetNbinsX(); ++l){
height = histo->GetBinContent(l);
dheight = height;
for (int n = l; n>0; n--){
if(histo->GetBinContent(n)<height){
dheight = height - histo->GetBinContent(n);
cout << l << " " << n << " " << dheight << endl;
break;
}
}
start = histo->GetBinLowEdge(l);
end = maxend;
for (int m = l; m <= histo->GetNbinsX(); ++m){
double thisbinheight = histo->GetBinContent(m);
if(thisbinheight<height){
end = histo->GetBinLowEdge(m);
break;
}
}
slices.push_back( new AcceptanceSlice( start, end, dheight ) );
if(!quiet) cout << start << " " << end << " " << dheight << endl;
}
histo->Delete();
// delete histo;
file->Close();
delete file;
if( !quiet ) cout << "Time Acc Slices: " << slices.size() << endl;
if( slices.size() == 1 )
{
cout << "SlicedAcceptance: SERIOUS ERROR" << endl;
exit(0);
}
//....done.....
_sortedSlices = this->isSorted();
if( _sortedSlices )
{
if( !quiet ) cout << "Sliced Acceptance is using sorted horizontal slices" << endl;
}
else
{
if( !quiet ) cout << "Sliced Acceptance is NOT using sorted horizontal slices" << endl;
}
}
示例4: EvtSel_Q2Pmiss
void EvtSel_Q2Pmiss(){
Styles style2; style2.setPadsStyle(2); style2.applyStyle();
TString NameTrees[3] = {"AWG82/ntuples/small/RAll_RunAll.root",
"AWG82/ntuples/small/uds_RunAll.root", "AWG82/ntuples/small/ccbar_RunAll.root"};
TChain gen("ntp1"), cont("ntp1");
gen.Add(NameTrees[0]);
for(int t=1; t<3; t++) cont.Add(NameTrees[t]);
double totMCB = 0, totuds = 0, totccbar = 0, totdata = 0, totOffdata = 0;
getNumberB(NameTrees[0], "All", totMCB, totdata, totuds, totccbar, totOffdata);
double wuds = totMCB/totuds*2.09/1.05;
TH1F *hCount = new TH1F("hCount","",100,-4,12);
gen.Draw("candM2>>hCount","weight");
double nTotal = hCount->Integral();
cont.Draw("candM2>>hCount","weight");
nTotal += hCount->Integral()*wuds;
TLine line; line.SetLineStyle(2); line.SetLineColor(28); line.SetLineWidth(2);
TArrow arrow; arrow.SetLineColor(28); arrow.SetFillColor(28); arrow.SetLineWidth(2);
TCanvas can("can","Pmiss and q2 cuts");
can.Divide(2,1); TPad *cPad = (TPad *)can.cd(1);
int bins[] = {42,40}, colors[2][4] = {{8,4,1,3},{8,2,4,1}};
double xrange[2][2] = {{0,4.2},{-3,13}}, yield[2][4], maxi[] = {-99,-99};
TString Variable[] = {"candPMiss","candQ2"};
TString labels[2][4] = {{"Signal (", "Normaliz. (","Had. bkg. (",""},
{"Signal (", "D l #nu (", "D* l #nu (", "Bkg. ("}};
// TString labels[2][4] = {{"Signal", "Normaliz.","Had. Bkg.",""},
// {"Signal", "D l #nu", "D* l #nu", "Bkg."}};
TString cuts[2][4] = {{"(candType<3&&MCType>4&&MCType<7||candType>2&&MCType>10&&MCType<13)*weight",
"(candType<3&&MCType>0&&MCType<5||candType>2&&MCType>6&&MCType<11)*weight",
"(MCType==0&&MCCombmode==12)*weight", ""},
{"(candType<3&&MCType>4&&MCType<7||candType>2&&MCType>10&&MCType<13)*weight",
"(candType<3&&(MCType==1||MCType==3)||candType>2&&(MCType==7||MCType==9))*weight",
"(candType<3&&(MCType==2||MCType==4)||candType>2&&(MCType==8||MCType==10))*weight",
"(!(candType<3&&MCType>0&&MCType<7||candType>2&&MCType>6&&MCType<13))*weight"}};
double legW = 0.4, legH = 0.225;
double legX = 1-style2.PadRightMargin-0.02, legY = 1-style2.PadTopMargin-0.02;
TLegend *leg[2];
leg[0] = new TLegend(legX-legW, legY-legH, legX, legY);
legW = 0.24; legH = 0.285; legX = 0.47;
leg[1] = new TLegend(legX-legW, legY-legH, legX, legY);
TH1F* h[2][4];
for(int pad=0; pad<2; pad++){
leg[pad]->SetTextSize(style2.LabelSize); leg[pad]->SetFillColor(0);
leg[pad]->SetTextFont(style2.nFont); leg[pad]->SetBorderSize(0);
for(int i=0; i<4; i++) {
if(pad==0 && i==3) continue;
TString hname = "h"; hname += pad; hname += i;
h[pad][i] = new TH1F(hname,"",bins[pad],xrange[pad][0],xrange[pad][1]);
h[pad][i]->SetLineWidth(2); h[pad][i]->SetLineColor(colors[pad][i]);
TString vari = Variable[pad]; vari += ">>"; vari += hname;
gen.Draw(vari,cuts[pad][i]);
if(i==3){
hname = "hCont"; hname += pad; hname += i;
TH1F *hCont = new TH1F(hname,"",bins[pad],xrange[pad][0],xrange[pad][1]);
TString vari = Variable[pad]; vari += ">>"; vari += hname;
cont.Draw(vari,cuts[pad][i]);
hCont->Scale(wuds);
h[pad][i]->Add(hCont);
hCont->Delete();
}
yield[pad][i] = h[pad][i]->Integral();
h[pad][i]->Scale(1000/h[pad][i]->Integral());
if(h[pad][i]->GetMaximum()>maxi[pad]) maxi[pad] = h[pad][i]->GetMaximum();
labels[pad][i] += RoundNumber(yield[pad][i]*100,0,nTotal); labels[pad][i] += "%)";
leg[pad]->AddEntry(h[pad][i],labels[pad][i]);
}
h[pad][0]->SetMaximum(maxi[pad]*1.22);
}
h[0][0]->Draw();
style2.fixYAxis(h[0][0],cPad);
style2.setTitles(h[0][0],"|p_{miss}| (GeV)","Entries/(100 MeV)","a)");
h[0][1]->Draw("same");h[0][2]->Draw("same");
leg[0]->Draw();
line.DrawLine(0.2,h[0][0]->GetMinimum(), 0.2,maxi[0]/1.45);
arrow.DrawArrow(0.2,maxi[0]/1.65,0.5,maxi[0]/1.65,0.01,"|>");
cPad = (TPad *)can.cd(2);
h[1][0]->Draw();
style2.fixYAxis(h[1][0],cPad);
style2.setTitles(h[1][0],"q^{2} (GeV^{2})","Entries/(0.4 GeV^{2})","b)");
h[1][1]->Draw("same"); h[1][2]->Draw("same"); h[1][3]->Draw("same");
leg[1]->Draw();
line.DrawLine(4,h[1][0]->GetMinimum(), 4,maxi[1]/1.45);
arrow.DrawArrow(4,maxi[1]/1.65,5.4,maxi[1]/1.65,0.01,"|>");
TString pName = "public_html/EvtSel_Q2Pmiss.eps";
can.SaveAs(pName);
for(int pad=0; pad<2; pad++){
leg[pad]->Delete();
for(int i=0; i<4; i++){
if(pad==0 && i==3) continue;
h[pad][i]->Delete();
}
}
hCount->Delete();
}