本文整理汇总了C++中TNtuple::Project方法的典型用法代码示例。如果您正苦于以下问题:C++ TNtuple::Project方法的具体用法?C++ TNtuple::Project怎么用?C++ TNtuple::Project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TNtuple
的用法示例。
在下文中一共展示了TNtuple::Project方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Getmean
double Getmean(TString sys1, TString sys2, float cent1, float cent2){
gROOT->SetStyle("Plain");
TFile *infile = TFile::Open(Form("glau_%s%s_ntuple_1M.root",sys1.Data(),sys2.Data()));
infile->cd();
TH2F *pEcc2B = new TH2F("pEcc2B","#epsilon_{2} vs impact paramter in 200 GeV Collisions from Glauber MC;B;#epsilon_{n}",25200,-0.5,251.5,100,0,1);
if(sys2.Contains("smeared")){
TNtuple *nt = (TNtuple*)infile->Get("nt");
nt->Project("pEcc2B","Ecc3G:B");
}
else{
TNtuple *nt = (TNtuple*)infile->Get(Form("nt_%s_%s",sys1.Data(),sys2.Data()));
nt->Project("pEcc2B","Ecc2:B");
}
TH1D* hB = (TH1D*)pEcc2B->ProjectionX("hB",0,-1);
for(int ibin=0;ibin<hB->GetNbinsX();ibin++){
if(hB->Integral(0,ibin) >= cent1 /100. * hB->Integral()){ int bin1 = ibin; break;}
}
for(int ibin=0;ibin<hB->GetNbinsX();ibin++){
if(hB->Integral(0,ibin) >= cent2 /100. * hB->Integral()){ int bin2 = ibin; break;}
}
cout<< bin1 << "\t" << bin2 << endl;
TH1D* hEcc2 = (TH1D*)pEcc2B->ProjectionY("hEcc2",bin1,bin2);
// hEcc2->Draw();
cout << hEcc2 -> GetEntries() << endl;
double mean = hEcc2->GetMean();
return mean;
}
示例2: Hijing
void Hijing()
{
TFile *fin = TFile::Open("/sphenix/user/pinkenbu/jade/hijingdat2.root");
gROOT->cd();
TH1 *hjbkg = new TH1F("hjbkg","Hijing Background",100,0.,0.5);
TNtuple *de = (TNtuple *) fin->Get("de");
de->Project("hjbkg","dtotal","(ID<=2)*edep/250.");
char fname [100];
sprintf(fname, "Gamma_Neutron_Hijing_Energy_Graphs.root");
TFile *fout = TFile::Open(fname,"UPDATE");
hjbkg->Write();
fout->Write();
fout->Close();
fin->Close();
}
示例3: testMM
void testMM()
{
//TFile *fout = new TFile("fout.root","recreate");
TH1F *hx1 = new TH1F("hx1","hx1",100,0,1);
TH1F *hx2 = new TH1F("hx2","hx2",100,0,1);
TH1F *hx3 = new TH1F("hx3","hx3",100,0,1);
TH1F *hchi2 = new TH1F("hchi2","hchi2",1000,0,2000);
TH1F *mc1, *mc2, *mc3, *data, *tmp;
mc1 = new TH1F("mc1","mc1",bins,x1,x2);
mc2 = new TH1F("mc2","mc2",bins,x1,x2);
mc3 = new TH1F("mc3","mc3",bins,x1,x2);
TNtuple *d = new TNtuple("d","d","x:weight");
TH1F *pred = new TH1F("pred","pred",bins,x1,x2);
TH1F *truth = new TH1F("truth","truth",bins,x1,x2);
data = new TH1F("data","data",bins,x1,x2);
tmp = new TH1F("tmp","tmp",bins,x1,x2);
mc1->Sumw2(); mc2->Sumw2(); mc3->Sumw2(); data->Sumw2();
//GenerateData(mc1,mc2,mc3,data);
GenerateDataUnbinned(mc1,mc2,mc3,d);
d->Project("data","x","weight");
TCanvas *cc = new TCanvas ("temp","temp",600,600);
data->Draw();
cc->SaveAs("data.pdf");
cout<<"???"<<data->Integral()<<endl;
double chi2 = Fit(mc1,mc2,mc3,d,hx1,hx2,hx3,hchi2);
cout<<"Fit chi2 = "<<chi2<<endl;
TH1F *mctmp1, *mctmp2, *mctmp3;
mctmp1 = (TH1F *)mc1->Clone("mctmp1x");
mctmp2 = (TH1F *)mc2->Clone("mctmp2x");
mctmp3 = (TH1F *)mc3->Clone("mctmp3x");
ShakeMC(mc1,mc2,mc3,mctmp1,mctmp2,mctmp3);
TCanvas *c2 = new TCanvas("c2","c2",600,600);
mc1->Draw();
mctmp1->Draw("same");
TCanvas *c3 = new TCanvas("c3","c3",600,600);
hx1->Draw();
hx2->Draw("same");
hx3->Draw("same");
double ymax = hx1->GetMaximum();
TLine *l1 = new TLine(x1true,0,x1true,ymax); l1->SetLineWidth(2.0);l1->SetLineColor(kRed); l1->Draw();
TLine *l2 = new TLine(x2true,0,x2true,ymax); l2->SetLineWidth(2.0);l2->SetLineColor(kRed); l2->Draw();
TLine *l3 = new TLine(x3true,0,x3true,ymax); l3->SetLineWidth(2.0);l3->SetLineColor(kRed); l3->Draw();
TCanvas *cchi2 = new TCanvas("cchi2","cchi2",600,600);
hchi2->Draw();
cout<<"x1 = "<<hx1->GetMean()<<"±"<<hx1->GetStdDev()<<endl;
cout<<"x2 = "<<hx2->GetMean()<<"±"<<hx2->GetStdDev()<<endl;
cout<<"x3 = "<<hx3->GetMean()<<"±"<<hx3->GetStdDev()<<endl;
cout<<"Median 1 "<<median1(hx1)<<endl;
cout<<"Median 2 "<<median1(hx2)<<endl;
cout<<"Median 3 "<<median1(hx3)<<endl;
double xx[]={x1true,x2true,x3true};
//cout<<"Chi2 of truth = "<<Chi2(xx)<<endl;
mc1->Scale(hx1->GetMean());
mc2->Scale(hx2->GetMean());
mc3->Scale(hx3->GetMean());
pred->Add(mc1); pred->Add(mc2); pred->Add(mc3);
pred->SetMarkerColor(kBlue);
truth->Add(mc1,x1true/mc1->Integral());
truth->Add(mc2,x2true/mc2->Integral());
truth->Add(mc3,x3true/mc3->Integral());
truth->SetMarkerColor(kBlack);
data->Scale(1/data->Integral());
data->SetMarkerColor(kRed);
TCanvas *c1 = new TCanvas("c1","c1",600,600);
data->Draw();
mc1->Draw("same,hist");
mc2->Draw("same,hist");
mc3->Draw("same,hist");
pred->Draw("same");
data->Draw("same");
//.........这里部分代码省略.........
示例4: fragmentEnergyDistributionDifferentAngles
//.........这里部分代码省略.........
for(int k = 1; k <= 6; k++){
TString Znum = Form("%i", k);
hist1->SetTitle("Z=" + Znum);
//ALL UNITS ARE cm!
Double_t detectorSideLength = 4; //40mm, as e.haettner H1 detector
Double_t scatteringDistance = detectorDistance - phantomCenterDistance; //temporarily hard-coded, should be distance from target-center to detector
Double_t degrees; //< actually radians
Double_t r, rMin, rMax, deltaOmega, normFloat;
TString rMinString, rMaxString, normString;
TString same = "";
TString histName;
TCanvas *c3 = new TCanvas("histograms", "Distribution (at different angles)");
int i = 0; //so that the degree steps can be varied to unevenly spaced values separate counter is used
std::cout << "The following numbers also make it possible to make number of fragments comparison to the graph in A1 of E.Haettner\n";
for(Double_t j = 0.0; j <= 8.0; j=j+1.0){
i++;
degrees = j * TMath::DegToRad();
//std::cout << "plotting for Z = " << Znum << " at " << j << " degrees\n";
//Distance from straight beam at the requested angle
r = scatteringDistance * TMath::Tan(degrees);
//now the "detector is rotated around all possible perpendicularlynangle values to beamline".
//This forms an annulus with rMin and RMax as otuer and inner radiuses
//Notice this will give a bit of approximation at small angles where at 0 degrees this gives a round sensor.
Double_t deltaPhi = TMath::ATan((TMath::Cos(degrees)*detectorSideLength)/(2*scatteringDistance));
rMin = TMath::Max(0.0,r - (detectorSideLength/(2*TMath::Cos(degrees))));
rMax = rMin + ((detectorSideLength*TMath::Sin(degrees))/TMath::Tan((TMath::Pi()/2) - degrees - deltaPhi)) + (detectorSideLength*TMath::Cos(degrees));
rMinString = Form("%f", rMin);
rMaxString = Form("%f", rMax);
//normalization of the bins.
deltaPhi = degrees - TMath::ATan(TMath::Tan(degrees) - detectorSideLength/(2*scatteringDistance)); // this should be around arctan(detectorsidelength/sd)
if(j != 0.0){
deltaOmega = 2*TMath::Pi()*(TMath::Cos(TMath::Max(0.0,degrees-deltaPhi)) - TMath::Cos(degrees+deltaPhi));
}else{
deltaOmega = 4 * TMath::ASin(pow(detectorSideLength,2.0) / (4*pow(scatteringDistance,2) + pow(detectorSideLength,2)) );
}
normFloat = deltaOmega * events * binWidth;
normString = Form("/%f", normFloat);
// The following is veryvery ugly relies on a bunch of hardcoded histograms because other solutions did not work
histName = Form("hist%i", i);
if(j != 0.0){
fragments->Project(histName,"energy", "(Z == " + Znum + " && energy > 0 && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")" + normString);
}else{
fragments->Project(histName,"energy", "(Z == " + Znum + " && energy > 0 && posZ < " + rMaxString + "&& posY < " + rMaxString + " && posY > 0 && posZ > 0)" + normString);
}
int numEntries = fragments->GetEntries("(Z == " + Znum + " && energy > 0 && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")");
std::cout << "\nj: "<< numEntries/(deltaOmega * events) << " entries for " << j;
}
//the ugly hardcoded histograms being plotted
//0 degrees
hist1->SetLineColor(kBlue);
hist1->Draw();
//1 degree
hist2->SetLineColor(kGreen);
hist2->Draw("same"); //add "same" when also plotting 0 degrees
//2 degrees
hist3->SetLineColor(kRed);
hist3->Draw("same");
//3 degrees
//hist4->SetLineColor(kGreen + 5);
//hist4->Draw("same");
//4 degrees
hist5->SetLineColor(kGreen + 3); //gives a darker shade of green
hist5->Draw("same");
//5 degrees
//hist6->SetLineColor(kRed);
//hist6->Draw("same");
//6 degrees
hist7->SetLineColor(kRed);
hist7->Draw("same");
//7 degrees
//hist8->SetLineColor(kRed);
//hist8->Draw("same");
//8 degrees
//hist9->SetLineColor(kRed);
//hist9->Draw("same");
// Legends for the data
leg = new TLegend(0.9,0.7,1,1); //coordinates are fractions
leg->SetHeader("Angles");
leg->AddEntry(hist1,"0","l");
leg->AddEntry(hist2,"1","l");
leg->AddEntry(hist3,"2","l");
leg->AddEntry(hist5,"4","l");
leg->AddEntry(hist7,"6","l");
leg->Draw();
c3->SaveAs("AEDistrib" + Znum + ".png");
}
in.close();
f->Write();
}
示例5: plotGlauberCenVars
void plotGlauberCenVars(Float_t eff=1., const Char_t* file="ZNA_ntuple_195483.root")
{
TFile *f = TFile::Open(file);
TNtuple* ntuple = dynamic_cast<TNtuple*> (f->Get("gnt"));
TGraphErrors *gNpart=new TGraphErrors(0);
gNpart->SetName("gNpart");
TGraphErrors *gNcoll=new TGraphErrors(0);
gNcoll->SetName("gNcoll");
TGraphErrors *gtAA=new TGraphErrors(0);
gtAA->SetName("gtAA");
/*TFile *ffd = TFile::Open("hZNAcalibRUN195483.root");
TH1F * hd = dynamic_cast<TH1F*> (ffd->Get(("hZNA")));
hd->Sumw2();*/
//
TFile *ff = TFile::Open("ZNA_fit_195483.root");
TH1F * hd = dynamic_cast<TH1F*> (ff->Get(("hZNA")));
hd->Sumw2();
TH1F * hg = dynamic_cast<TH1F*> (ff->Get(("hZNA_GLAU")));
hd->SetMarkerColor(kBlue+3);
hd->SetMarkerSize(1.);
hd->SetLineColor(kBlue+3);
hd->SetLineWidth(2);
hd->SetMarkerStyle(20);
hd->SetLineWidth(2);
// hg->Scale(1./hd->GetEntries());
// hd->Scale(1./hd->GetEntries());
hd->SetMinimum(1.e-01);
hd->SetXTitle("E_{ZNA} (TeV)");
hg->SetLineColor(kPink-2);
hg->SetLineWidth(2);
TH1F* hist = (TH1F*) hg->Clone("hist");
//---------------------------------------------------
getCentrality(hist, eff);
//---------------------------------------------------
TCanvas* canvas = new TCanvas("canvas","Multiplicity",200,200,600,600);
canvas->cd();
canvas->SetLogy();
hd->Draw("pe");
//hd->GetXaxis()->SetRangeUser(0.,130.);
hd->SetMinimum(0.01);
hg->Draw("SAME");
float low = 0;
float high = hist->GetNbinsX();
for(int i=0; i<binUp->GetSize(); i++){
low = binUp->At(i);
hist->GetXaxis()->SetRange(low+1, high);
hist->SetFillColor((i%2==0)?0:kAzure+6);
hist->SetLineColor((i%2==0)?0:kAzure+6);
printf(" bin %d low %f high %f\n",i,low,high);
hist->DrawCopy("h same");
high=low;
}
hd->Draw("esame");
hg->Draw("SAME");
canvas->Print("plotGlauber.gif");
TCanvas* canvas2 = new TCanvas("canvas2","NPart");
canvas2->cd();
canvas2->SetLogy();
TH1F *hist2 = new TH1F("hist2","N_{part}",35,0.,35);
ntuple->Project("hist2","fNpart");
//hist2->SetStats(0);
hist2->SetTitle("");
hist2->GetXaxis()->SetTitle("NPart");
hist2->GetXaxis()->SetTitleSize(0.05);
hist2->GetXaxis()->SetLabelSize(0.04);
hist2->GetXaxis()->SetTitleOffset(1.2);
hist2->GetYaxis()->SetTitle("");
hist2->GetYaxis()->SetTitleOffset(1.3);
hist2->GetYaxis()->SetTitleSize(0.05);
hist2->GetYaxis()->SetLabelSize(0.04);
hist2->DrawCopy();
float lownp=0;
float highnp=5000;
TH1F *htemp10[nbins];
printf("\n ***** N_part \n");
for(int i=0; i<Multbin->GetSize(); i++){
lownp = Multbin->At(i);
char cuts[120];
char histname[20];
sprintf(cuts,"Etot>%f && Etot<=%f",lownp,highnp);
sprintf(histname,"htemp10[%i]",i);
htemp10[i] = new TH1F(histname,"N_{part}",35,0.,35);
//printf(" cut: %s\n", cuts);
ntuple->Project(histname,"fNpart",cuts);
htemp10[i]->SetLineColor(i+1);
htemp10[i]->Draw("same");
cout << i << " | " << lownp << " | " << highnp << " | " << setprecision(3) <<
htemp10[i]->GetMean() << " | " << htemp10[i]->GetRMS() << " | " << endl;
gNpart->SetPoint(i,Float_t(i),htemp10[i]->GetMean());
gNpart->SetPointError(i,0,htemp10[i]->GetRMS());
highnp = lownp;
}
//.........这里部分代码省略.........
示例6: gammaJetDifferentialxjg
void gammaJetDifferentialxjg()
{
TH1::SetDefaultSumw2();
TFile *inFile = TFile::Open("gammaJets_inclusive_dphi7pi8_pPbData_v2.root");
TNtuple *inTuple = (TNtuple*)inFile->Get("gammaJets");
//book histos
TH1D *gammaJetEta[nhfBins];
TH1D *x_jg[nhfBins];
TH1D *hfEnergy[nhfBins];
Int_t numEvts[nhfBins];
Int_t numEvtsEtaPlus[nhfBins];
TCanvas *c[4];
c[0] = new TCanvas();
c[1] = new TCanvas();
TLegend *leg = new TLegend(0.65,0.65,0.9,0.9);
leg->SetFillColor(0);
for(Int_t i = 0; i < nhfBins; ++i)
{
TString s_gammaJetEta = "gammaJetEta";
s_gammaJetEta += i;
gammaJetEta[i] = new TH1D(s_gammaJetEta,";Avg #eta_{#gamma jet};Event Fraction",14,-3,3);
TString s_hfEnergy = "hfEnergy";
s_hfEnergy += i;
hfEnergy[i] = new TH1D(s_hfEnergy,"",1000,0,1000);
TString s_x_jg = "x_jg";
s_x_jg += i;
x_jg[i] = new TH1D(s_x_jg,";p_{T}^{jet}/p_{T}^{#gamma};Event Fraction",20,0,1.5);
TCut isolationCut = "(cc4 + cr4 + ct4PtCut20 < 1.0)";
//TCut etaCut = "(abs(gEta) > 1.479)";
//TCut showerShapeCut = "(sigmaIetaIeta < 0.035)";
TCut etaShowerCut = "((abs(gEta) < 1.479) && (sigmaIetaIeta < 0.01) || (abs(gEta) > 1.479) && (sigmaIetaIeta < 0.035))";
TCut ptCut = "(jPt > 30) && (gPt > 50)";
TString hfCut = Form("((HFplusEta4+HFminusEta4) > %f) && ((HFplusEta4+HFminusEta4) > %f)", hfBins[i], hfBins[i+1]);
//TCut cut = isolationCut && etaCut && showerShapeCut && ptCut && hfCut;
TCut cut = isolationCut && etaShowerCut && ptCut && hfCut;
//printf("cut: %s\n",(const char*)cut);
TString runFlip = "((run > 211257)*(-1) + (run < 211257))";
numEvts[i] = inTuple->Project(s_gammaJetEta,"avgEta*"+runFlip,cut);
numEvtsEtaPlus[i] = inTuple->GetEntries(
cut &&
"( avgEta*(run < 211257) >0 ) || ( avgEta*(run > 211257) <0 )"
);
inTuple->Project(s_hfEnergy,"(HFplusEta4+HFminusEta4)",cut);
inTuple->Project(s_x_jg,"jPt/gPt",cut);
gammaJetEta[i]->Scale(1./numEvts[i]);
gammaJetEta[i]->SetMarkerColor(i+1);
gammaJetEta[i]->SetLineColor(i+1);
x_jg[i]->Scale(1./numEvts[i]);
x_jg[i]->SetMarkerColor(i+1);
x_jg[i]->SetLineColor(i+1);
TString label;
label += hfBins[i];
label += " < E_{T}^{HF[|#eta|>4]} < ";
label += hfBins[i+1];
leg->AddEntry(gammaJetEta[i], label, "lp");
if(i==0)
{
//TLatex *lnorm = new TLatex(0.2,0.85, "Monte Carlo");
//lnorm->SetNDC(1);
//lnorm->SetTextSize(0.05);
gammaJetEta[i]->GetXaxis()->CenterTitle();
gammaJetEta[i]->GetYaxis()->CenterTitle();
gammaJetEta[i]->SetMaximum(gammaJetEta[i]->GetMaximum()*1.7);
x_jg[i]->GetXaxis()->CenterTitle();
x_jg[i]->GetYaxis()->CenterTitle();
x_jg[i]->SetMaximum(x_jg[i]->GetMaximum()*1.7);
c[0]->cd();
gammaJetEta[i]->Draw("");
//lnorm->Draw("same");
c[1]->cd();
x_jg[i]->Draw("");
//lnorm->Draw("same");
}
else
{
c[0]->cd();
gammaJetEta[i]->Draw("same");
c[1]->cd();
x_jg[i]->Draw("same");
}
c[0]->cd();
gammaJetEta[i]->Draw("same Lhist");
leg->Draw();
c[1]->cd();
//.........这里部分代码省略.........
示例7: EdepPercentSmall
void EdepPercentSmall (const char *part="e")//,int nevent = 1000)
{
char infile[100];
int pz[9] = {1,2,4,8,12,16,32,40,50};
double x[9];
double means[9] = {0};
double y[9];
double mval = 0;
int lastbincont = 0;
bool lastbin = false;
for (int i=0; i<9; i++)
{
x[i] = pz[i];
y[i] = means[i];
sprintf(infile, "/sphenix/user/jpinkenburg/ShowerSize/ntuple/%s_eta0_%dGeV.root",part, pz[i]);
char hname [100];
sprintf(hname, "%s%dd",part,pz[i]);
TH1F *h1 = new TH1F(hname, hname, 8000, 0, 4);
TFile *f = TFile::Open(infile);
gROOT->cd();
TNtuple *nt = (TNtuple *)f->Get("de");
nt->Project(hname,"dtotal","(ID<=2)*edep");
//h1->Draw();
/* for (int j = 1000; j>0; j--)
{
if (lastbin == false)
{
if (h1->GetBinContent(j) == 0)
{
cout << j << endl;
}
else
{
lastbin = true;
lastbincont = (j/1000)*3.5;
}
}
else
{
j=0;
}
}
char revhname[100];
sprintf(revhname,"%s%dGeV",part,pz[i]);
TH1F *h4 = new TH1F(revhname,revhname,10000,0,lastbincont);
nt->Project(revhname,"dtotal","(ID<=2)*edep","");
*/f->Close();
h1->Draw();
/* mval = h1->Integral();
// cout << "mval " << mval << endl;
cout << "mval_supposed_to_be " << h4->Integral() << endl;
means[i] += mval;
mval = 0;
cout << "6" << endl;
*/
char fname [100];
sprintf(fname, "%s_ThinBins.root",part);
TFile *fout = TFile::Open(fname,"UPDATE");
h1->Write();
fout->Write();
cout << h1->Integral() << " " << hname << " " << pz[i] << endl;
fout->Write();
fout->Close();
}
/* TFile *f1 = TFile::Open("anti_neutronShowerEdepPercent.root");
gROOT->cd();
TH2 *h2 = new TH2F("meanvals","anti_neutron",1,0,1,1,0,.01);
gStyle->SetOptStat(0);
TMarker *mean = new TMarker();
mean->SetMarkerStyle(20);
mean->SetMarkerColor(3);
TMarker *test = new TMarker();
test->SetMarkerStyle(20);
test->SetMarkerColor(5);
TCanvas *c2 = new TCanvas("c2","stupid graph",1);
double dtot[9] = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
TGraph *gr = new TGraph(9,dtot,means);
gr->Draw("AC*");
h2->Draw();
test->DrawMarker(0.5,0.005);
mean->DrawMarker(0,0);
double dtot[9] = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
double z[9];
// cout << "bflmv" << meanval[0] << endl;
for (int i=0;i<9;i++)
{
// sprintf(
cout << "coming" << endl;
z[i] = dtot[i];
// mean->DrawMarker(0,0);
// test->DrawMarker(dtot[i],.005);
cout << "meanval" << " " << dtot[i] << endl;
cout << "means" << " " << means[i] << endl;
// cout << means[i] << endl;
}
char fname [100];
//.........这里部分代码省略.........