本文整理汇总了C++中TH1D::SetName方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1D::SetName方法的具体用法?C++ TH1D::SetName怎么用?C++ TH1D::SetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TH1D
的用法示例。
在下文中一共展示了TH1D::SetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: chi2
void chi2(int xmin = 0, int xmax = 200, TString filename="../DsubMC/met2j0bIso2ewkScale_0_200.root", int nparam = 2){
RooAbsData::ErrorType errorType = RooAbsData::SumW2;
file = new TFile(filename);
RooRealVar* h = new RooRealVar("h","h",xmin,xmax);
//Get Data
TH1D* hData = file->Get("dataih");
hData->SetName("hData");
//hData->Draw();
RooDataHist* data = new RooDataHist("data","data",*h,hData);
//Get Summed MC
TH1D* hMC = file->Get("hh");
hMC->SetName("hMC");
hMC->Draw();
RooDataHist rdhMC("MC","MC",*h,hMC);
RooHistPdf pdfMC("MCpdf","MCpdf",*h,rdhMC);
//make (plot) the curves
RooPlot* hFrame = h->frame(Name("hFrame"));
data->plotOn(hFrame,RooFit::DataError(errorType));
pdfMC.plotOn(hFrame,ProjWData(*data),Components(pdfMC),Name("h_total"));
//Determine Chi^2
double chi2fit = hFrame->chiSquare("h_total", "h_data", nparam);
cout<<"Chi 2 / dof: "<<chi2fit<<endl;
//Determine K-S
double ks = hMC->KolmogorovTest(hData);
cout<<"Kolmogorov-Smirnov: "<<ks<<endl;
}
示例2:
TH1D *makeDiffHist(TH1D* hData, TH1D* hFit, const TString name)
{
TH1D *hDiff = (TH1D*)hData->Clone("hDiff");
hDiff->SetName(name);
for(Int_t ibin=1; ibin<=hData->GetNbinsX(); ibin++) {
Double_t diff=0;
Double_t err=0;
if(hData->GetBinContent(ibin)!=0)
{
diff = hFit->GetBinContent(ibin)/hData->GetBinContent(ibin);
err = hFit->GetBinError(ibin)/hData->GetBinContent(ibin);
}
hDiff->SetBinContent(ibin,diff);
hDiff->SetBinError(ibin,err);
}
hDiff->GetYaxis()->SetTitleOffset(0.55);
hDiff->GetYaxis()->SetTitleSize(0.13);
hDiff->GetYaxis()->SetLabelSize(0.10);
hDiff->GetYaxis()->SetNdivisions(104);
hDiff->GetYaxis()->CenterTitle();
hDiff->GetXaxis()->SetTitleOffset(1.2);
hDiff->GetXaxis()->SetTitleSize(0.13);
hDiff->GetXaxis()->SetLabelSize(0.12);
hDiff->GetXaxis()->CenterTitle();
return hDiff;
}
示例3: fft
///////////////////////////////////////////////////////////////////
//////// Go4 GUI example script fft.C
// J.Adamczewski, gsi, 30 May 2012
// NOTE: to be run in Go4 GUI local command line only!
// NEVER call this script in remote analysis process!!!
/////// Functionality:
// perfroms fft on histogram of name1 using the option as explained in root TVirtualFFT:FFT
/////// Usage:
// The draw flag switches if the results are displayed each time this macro is called
// if display is switched off, the result histogram is just updated in browser and existing displays
///////
Bool_t fft(const char* name1, Option_t* opt = "R2C M", Bool_t draw=kTRUE)
{
if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
return kFALSE;
}
TString newname;
TString fullname1 = go4->FindItem(name1);
TObject* ob1 = go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms
if ((ob1==0) || !ob1->InheritsFrom("TH1")) {
std::cout <<"fft could not get histogram "<<fullname1 << std::endl;
return kFALSE;
}
if(ob1->InheritsFrom("TH2") || ob1->InheritsFrom("TH3")){ // 2d
std::cout <<"fft does not support 2d/3d histogram "<<fullname1 << std::endl;
return kFALSE;
}
TH1* his1=(TH1*)ob1;
TString n1=his1->GetName();
TString t1=his1->GetTitle();
newname.Form("_fft_%s",opt);
TString finalname = n1+newname;
TString finaltitle = t1+newname;
// do fft here:
Int_t N = his1->GetNbinsX();
TH1D* result = new TH1D(finalname, finaltitle,N,0,N);
result->SetName(finalname);
result->SetTitle(finaltitle);
result->Reset("");
Double_t *in = new Double_t[N];
// since we do not know type of input histo, we copy contents to Double array:
for(Int_t ix=0; ix<N;++ix)
{
in[ix]=his1->GetBinContent(ix+1);
}
TVirtualFFT *thefft = TVirtualFFT::FFT(1, &N, opt);
thefft->SetPoints(in);
thefft->Transform();
Double_t re, im;
for (Int_t i=0; i<N; i++) {
thefft->GetPointComplex(i, re, im);
result->SetBinContent(i+1,TMath::Sqrt(re*re + im*im));
}
result->SetDirectory(0);
TString rname = go4->SaveToMemory("FFT", result, kTRUE);
std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
if(draw){
ViewPanelHandle vpanel = go4->StartViewPanel();
go4->DrawItem(rname, vpanel);
}
return kTRUE;
}
示例4: Proc_hPhi
void ProcYields::Proc_hPhi(hel_t hel/*=UNPOL*/){
Info(TString::Format("Proc_hPhi(%s)",helTitle[hel].Data()), "");
TDirectory* dir_phi=NULL;
if (hel==UNPOL) {
dir_phi = _dirQ2W->mkdir("hPhi");
}else if(hel==POS||hel==NEG){
dir_phi = _dirQ2W->mkdir(TString::Format("hPhi_%s",helTitle[hel].Data()));
}
TDirectory* dir_varset=NULL;
for (Int_t iVarset=0;iVarset<nVARSET;iVarset++){
dir_varset = dir_phi->mkdir(TString::Format("Varset%d", iVarset+1));
dir_varset->cd();
//!Get relevent h5D
THnSparse* hY5D = NULL;
if (hel==UNPOL) {
//! To make hphi from ACC_CORR evts
hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D/Varset%d/hY5D_ACC_CORR",iVarset+1));
//! To make hphi from FULL evts
//hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D/Varset%d/hY5D_FULL",iVarset+1));
//! To make hphi from TH evts
//hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D/Varset%d/hY5D_TH",iVarset+1));
}else if (hel==POS||hel==NEG){
//! To make hphi from ACC_CORR evts
hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D_%s/Varset%d/hY5D_ACC_CORR",helTitle[hel].Data(),iVarset+1));
//! To make hphi from FULL evts
//hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D_%s/Varset%d/hY5D_FULL",helTitle[hel].Data(),iVarset+1));
//! To make hphi from TH evts
//hY5D = (THnSparseF*)_dirQ2W->Get(TString::Format("hY5D_%s/Varset%d/hY5D_TH",helTitle[hel].Data(),iVarset+1));
}
//! PROJECT phi bins for each VAR
TDirectory* dir_var=NULL;
for(Int_t iVar=0; iVar<nVAR; iVar++){
if (iVar==ALPHA || iVar==M1 || iVar==M2 || iVar==PHI) continue;
dir_var = dir_varset->mkdir(varName[iVar].Data());
dir_var->cd();
int nvarbins = hY5D->GetAxis(iVar)->GetNbins();
//! Loop over number of bins in Var and make phi projections for each
for (int ivarbin=0; ivarbin<nvarbins; ivarbin++){
Float_t varbin_lowedge = hY5D->GetAxis(iVar)->GetBinLowEdge(ivarbin+1);
Float_t varbin_highedge = varbin_lowedge + hY5D->GetAxis(iVar)->GetBinWidth(ivarbin+1);
//! Create Phi projection histogram
hY5D->GetAxis(iVar)->SetRange(ivarbin+1, ivarbin+1);
TH1D* hphi = (TH1D*)hY5D->Projection(PHI,"E");
hphi->Sumw2();
TString name = TString::Format("hphi_proj_%02d",ivarbin+1);
TString title = TString::Format("#phi projection for %s = [%.2f,%.2f) | h=%s | top=%s | q2w = %s",
varTitle[iVarset][iVar].Data(), varbin_lowedge, varbin_highedge,
helTitle[hel].Data(), _topList.Data(), _Q2Wdirname);
hphi->SetName(name);
hphi->SetTitle(title);
}//end nvarbins loop
}//end nVAR loop
}//end nVARSET loop
Info(TString::Format("Proc_hPhi(%s)",helTitle[hel].Data()), "done\n");
}
示例5: DynamicExec
void DynamicExec()
{
// Example of function called when a mouse event occurs in a pad.
// When moving the mouse in the canvas, a second canvas shows the
// projection along X of the bin corresponding to the Y position
// of the mouse. The resulting histogram is fitted with a gaussian.
// A "dynamic" line shows the current bin position in Y.
// This more elaborated example can be used as a starting point
// to develop more powerful interactive applications exploiting CINT
// as a development engine.
//
// Author: Rene Brun
TObject *select = gPad->GetSelected();
if(!select) return;
if (!select->InheritsFrom("TH2")) {gPad->SetUniqueID(0); return;}
TH2 *h = (TH2*)select;
gPad->GetCanvas()->FeedbackMode(kTRUE);
//erase old position and draw a line at current position
int pyold = gPad->GetUniqueID();
int px = gPad->GetEventX();
int py = gPad->GetEventY();
float uxmin = gPad->GetUxmin();
float uxmax = gPad->GetUxmax();
int pxmin = gPad->XtoAbsPixel(uxmin);
int pxmax = gPad->XtoAbsPixel(uxmax);
if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
gVirtualX->DrawLine(pxmin,py,pxmax,py);
gPad->SetUniqueID(py);
Float_t upy = gPad->AbsPixeltoY(py);
Float_t y = gPad->PadtoY(upy);
//create or set the new canvas c2
TVirtualPad *padsav = gPad;
TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
if(c2) delete c2->GetPrimitive("Projection");
else c2 = new TCanvas("c2","Projection Canvas",710,10,700,500);
c2->SetGrid();
c2->cd();
//draw slice corresponding to mouse position
Int_t biny = h->GetYaxis()->FindBin(y);
TH1D *hp = h->ProjectionX("",biny,biny);
hp->SetFillColor(38);
char title[80];
sprintf(title,"Projection of biny=%d",biny);
hp->SetName("Projection");
hp->SetTitle(title);
hp->Fit("gaus","ql");
hp->GetFunction("gaus")->SetLineColor(kRed);
hp->GetFunction("gaus")->SetLineWidth(6);
c2->Update();
padsav->cd();
}
示例6:
TH1D* GetRawBackground1D(int itrg, int jass)
{
TH2D* hbackground = (TH2D*) GetRawBackground2D(itrg,jass);
TH1D* hbackphi = (TH1D*)hbackground->ProjectionY(Form("backphi_trg%d_ass%d",itrg,jass),hbackground->GetXaxis()->FindBin(detaprojmin),hbackground->GetXaxis()->FindBin(detaprojmax),"e");
hbackphi->Scale(hbackground->GetXaxis()->GetBinWidth(1));
hbackphi->GetXaxis()->CenterTitle();
hbackphi->GetYaxis()->CenterTitle();
hbackphi->SetYTitle("B(#Delta#phi)");
hbackphi->SetName(Form("backphi_scale_trg%d_ass%d",itrg,jass));
return hbackphi;
}
示例7: fixLeptonBJet
void fixLeptonBJet(char* filename)
{
TH1D *lb;
TFile f(filename, "UPDATE");
f.GetObject("HypLeptonBAjetMass", lb);
if (lb) {
cout << "HypLeptonBAjetMass found, saving as HypLeptonBjetMass\n";
lb->SetName("HypLeptonBjetMass");
lb->Write();
}
f.Close();
}
示例8:
TH1D *getErrorBand(TH1* h)
{
TH1D *hErr = (TH1D*) h->Clone();
hErr->SetName("hErr");
for (int i=0;i<h->GetNbinsX();i++) {
double var = h->GetBinContent(i);
double varErr = h->GetBinError(i);
hErr->SetBinContent(i,var);
hErr->SetBinError(i,var*0.1);
}
return hErr;
}
示例9: run
void run() {
// gROOT->ProcessLine(".L /Users/jdolen/Dropbox/Code/MyAnalysisRootFunctions_NEW.C");
// gROOT->ProcessLine(".L /Users/jdolen/Dropbox/Code/JMAR/TopTagging/MyFunctions_TopTag.C");
TFile *out = new TFile("ModMass_2015_09_22.root","RECREATE");
// TFile *F_qcdpt170 = new TFile("ntuples/ntuple_QCD_Pt_170to300_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
TFile *F_qcdpt300 = new TFile("ntuples/ntuple_QCD_Pt_300to470_RunIISpring15DR74-Asympt50ns_2015_09_22c.root");
TFile *F_qcdpt470 = new TFile("ntuples/ntuple_QCD_Pt_470to600_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
TFile *F_qcdpt600 = new TFile("ntuples/ntuple_QCD_Pt_600to800_RunIISpring15DR74-Asympt50ns_2015_09_22c.root");
TFile *F_qcdpt800 = new TFile("ntuples/ntuple_QCD_Pt_800to1000_RunIISpring15DR74-Asympt50ns_2015_09_22b.root");
TFile *F_qcdpt1000 = new TFile("ntuples/ntuple_QCD_Pt_1000to1400_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
TFile *F_qcdpt1400 = new TFile("ntuples/ntuple_QCD_Pt_1400to1800_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
TFile *F_qcdpt1800 = new TFile("ntuples/ntuple_QCD_Pt_1800to2400_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
TFile *F_qcdpt2400 = new TFile("ntuples/ntuple_QCD_Pt_2400to3200_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
TFile *F_qcdpt3200 = new TFile("ntuples/ntuple_QCD_Pt_3200toInf_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
std::vector <TFile* > rootFiles;
// rootFiles.push_back( F_qcdpt170 );
// rootFiles.push_back( F_qcdpt300 );
rootFiles.push_back( F_qcdpt470 );
rootFiles.push_back( F_qcdpt600 );
rootFiles.push_back( F_qcdpt800 );
rootFiles.push_back( F_qcdpt1000 );
rootFiles.push_back( F_qcdpt1400 );
rootFiles.push_back( F_qcdpt1800 );
rootFiles.push_back( F_qcdpt2400 );
rootFiles.push_back( F_qcdpt3200 );
// for (unsigned int i=0; i<rootFiles.size(); i++){
// TH1D * h1 = (TH1D*) rootFiles[i] -> Get( "h_mAK8_ModMass" );
// cout<<h1->Integral()<<endl;
// }
vector <string> histnames;
histnames.push_back("h_mAK8_ModMass");
histnames.push_back("h_mSDropAK8_ModMass");
histnames.push_back("h_mAK8_ModMass_jet0");
histnames.push_back("h_mSDropAK8_ModMass_jet0");
histnames.push_back("h_mAK8_ModMass_jet1");
histnames.push_back("h_mSDropAK8_ModMass_jet1");
out->cd();
for (unsigned int i=0; i<histnames.size(); i++) {
TH1D * hist = scaleHistsFromPtHatRootFilesReturnHist( histnames[i].c_str(), rootFiles) ;
hist->SetName(histnames[i].c_str());
hist->Write();
}
out->Write();
out->Close();
}
示例10: SaveClosure
void SaveClosure(TH1D* prediction, TH1D* expectation, TDirectory* Folder) // prediction durch expectation
{
TH1D* Closure = (TH1D*) prediction->Clone();
Closure->Divide(prediction,expectation,1,1,"B");
TString title = prediction->GetTitle();
title +="_closure";
// title = "#mu & e Control-Sample Ratio in Search Bins; Search bins; #mu / e CS";
Closure->SetTitle(title);
title = prediction->GetName();
title+="_closure";
Closure->SetName(title);
Folder->cd();
Closure->Write();
}
示例11: StepRebin
// A function to rebin a histogram with incresingly larger bins.
// It is useful for histograms of momentum, energy etc, where
// particles/events become less and less frequent as the quantity
// increases.
TH1D* StepRebin(TH1D *inhisto, int stepPeriod=1)
{
TH1D *first = new TH1D(*inhisto);
int ninbins = inhisto->GetNbinsX();
first->SetName("first");
int sbin=1+stepPeriod;
for ( int i=1; i<ninbins; i++ ) // Actually no need to go up to ninbins
for ( int j=0; j<stepPeriod; ++j ) {
if ( inhisto->GetBinCenter(sbin) >
inhisto->GetBinLowEdge(ninbins) ) continue;
TH1D *second = CombineBins(*first, inhisto->GetBinCenter(sbin),
inhisto->GetBinCenter(sbin+i));
delete first;
second->SetName("second");
sbin = (sbin+i+1);
TH1D *first = new TH1D(*second);
delete second;
first->SetName("first");
}
return first;
}
示例12: CompareCFLADiffCuts
void CompareCFLADiffCuts()
{
TFile newFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/15-NoOppChargeCut/All/CFs.root");
TDirectory *newDir = newFile.GetDirectory("Merged");
vector<TH1D*> newCFs;
newCFs.push_back((TH1D*)newDir->Get("CFLamALam010"));
newCFs.push_back((TH1D*)newDir->Get("CFLamALam1030"));
newCFs.push_back((TH1D*)newDir->Get("CFLamALam3050"));
TFile oldFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/08-NewAvgSepCuts/All/CFs.root");
TDirectory *oldDir = oldFile.GetDirectory("Merged");
vector<TH1D*> oldCFs;
oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam010"));
oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam1030"));
oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam3050"));
TFile *compareFile = new TFile("Compare.root","update");
TDirectory *dir = compareFile->GetDirectory("Delta");
if(!dir) dir = compareFile->mkdir("Delta");
for(UInt_t i = 0; i < newCFs.size(); i++) {
// TH1D *ratio = (TH1D*)newCFs[i]->Clone();
// TString name = ratio->GetName();
// ratio->SetName(name + "Ratio");
// ratio->SetTitle(name + "Ratio");
// ratio->Divide(oldCFs[i]);
// TH1D *barlowRatio = ComputeRogerBarlowRatio(newCFs[i], oldCFs[i]);
// barlowRatio->SetName(name + "BarlowRatio");
// barlowRatio->SetTitle(name + "BarlowRatio");
TString name = newCFs[i]->GetName();
TH1D *barlowDifference = ComputeRogerBarlowDifference(newCFs[i], oldCFs[i]);
barlowDifference->SetName(name + "BarlowDifference");
barlowDifference->SetTitle(name + "BarlowDifference");
dir->cd();
// ratio->Write();
// barlowRatio->Write();
barlowDifference->Write(barlowDifference->GetName(), TObject::kOverwrite);
Chi2TestWithZero(barlowDifference);
FitWithConstant(barlowDifference, compareFile);
// LookAtMean(barlowDifference);
RebinHist(barlowDifference, compareFile);
ManuallyRebin(barlowDifference, compareFile);
}
compareFile->Close();
}
示例13: exec2
void exec2()
{
if (!gPad) {
Error("exec2", "gPad is null, you are not supposed to run this macro");
return;
}
TObject *select = gPad->GetSelected();
if(!select) return;
if (!select->InheritsFrom(TH2::Class())) {gPad->SetUniqueID(0); return;}
gPad->GetCanvas()->FeedbackMode(kTRUE);
//erase old position and draw a line at current position
int pyold = gPad->GetUniqueID();
int px = gPad->GetEventX();
int py = gPad->GetEventY();
float uxmin = gPad->GetUxmin();
float uxmax = gPad->GetUxmax();
int pxmin = gPad->XtoAbsPixel(uxmin);
int pxmax = gPad->XtoAbsPixel(uxmax);
if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
gVirtualX->DrawLine(pxmin,py,pxmax,py);
gPad->SetUniqueID(py);
Float_t upy = gPad->AbsPixeltoY(py);
Float_t y = gPad->PadtoY(upy);
//create or set the new canvas c2
TVirtualPad *padsav = gPad;
TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2");
if(c2) delete c2->GetPrimitive("Projection");
else c2 = new TCanvas("c2");
c2->cd();
//draw slice corresponding to mouse position
TH2 *h = (TH2*)select;
Int_t biny = h->GetYaxis()->FindBin(y);
TH1D *hp = h->ProjectionX("",biny,biny);
char title[80];
sprintf(title,"Projection of biny=%d",biny);
hp->SetName("Projection");
hp->SetTitle(title);
hp->Fit("gaus","ql");
c2->Update();
padsav->cd();
}
示例14: f
TH1D* readTH1(const TString &fileName, const TString &histName, const TString &newHistName, bool useCurrentStyle) {
TFile f(fileName,"READ");
TH1D *h = 0;
f.GetObject(histName,h);
if( h ) {
h->SetDirectory(0);
if( useCurrentStyle ) h->UseCurrentStyle();
if( newHistName.Length() ) h->SetName(newHistName);
} else {
std::cerr << "ERROR in FileOps::readTH1: Histogram with name '" << histName << "' does not exist in file '" << fileName << "'\n.";
f.Close();
exit(-1);
}
f.Close();
return h;
}
示例15: getaCanvas
TH1D *plotIso(TTree *tSig,TString var,TString weight, TString etcut, TString htcut, TString njetcut, TString ph, TString bin,Double_t xmax, Int_t icol)
{
TCut etcut20=weight+" * ("+etcut+htcut+" && "+njetcut+")";
TCut conv1=weight+" * ("+etcut+htcut+" &&"+njetcut+" && mHits<=1)";
TCut conv2=weight+" * ("+etcut+htcut+" && "+njetcut+"&& mHits<=1)";
TCut conv3=weight+" * ("+etcut+htcut+" && "+njetcut+"&& mHits<=1 && (dcot>0.02 || dcot<-0.02 || dist>0.02 || dist<-0.02))";
TCanvas *c = getaCanvas(ph+var+etcut+htcut+"hsqrti");
tSig->Draw(var+">>hsqrti"+bin,conv3);
TH1D *hsqrt = (TH1D*)gDirectory->Get("hsqrti");
hsqrt->SetName(ph+var+htcut+"hsqrti");
hsqrt->SetLineColor(icol);
hsqrt->SetLineWidth(3);
c->Close();
return hsqrt;
}