当前位置: 首页>>代码示例>>C++>>正文


C++ TH1::SetName方法代码示例

本文整理汇总了C++中TH1::SetName方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1::SetName方法的具体用法?C++ TH1::SetName怎么用?C++ TH1::SetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TH1的用法示例。


在下文中一共展示了TH1::SetName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Plot2hists1D

// If two histograms from two files are to be ploted onto
// the same plot.  Open the first, and make a copy of the
// histogram and place it in the 2nd file. Then
void Plot2hists1D(TString hist1Name, 
		TString hist2Name, 
		TString file1Name, 
		TString file2Name, 
                TString hist1Label = "",
                TString hist2Label = "",
		Double_t scaleFactor1 = 1.0, 
		Double_t scaleFactor2 = 1.0) {

  // Open the 1st file
  TFile *file1 = new TFile(file1Name);

  // Grab a copy of its histogram
  TH1* histTemp = (TH1*)file1->Get(hist1Name);

  // Open the 2nd file
  TFile *file2 = new TFile(file2Name,"UPDATE");
  file2->cd();

  // Change the name 
  histTemp->SetName(hist1Name+"1");

  // Write the histogram to the 2nd file
  histTemp->Write();

  // Now file2 is the currently active file
  Plot2hists1D(hist1Name+"1",hist2Name, scaleFactor1, scaleFactor2, hist1Label, hist2Label);

  // Close the files, but if they close, the histograms disappear
  //file1->Close();
  //file2->Close();
}
开发者ID:TENorbert,项目名称:SOME-TOOLS,代码行数:35,代码来源:Plot2hists1D.C

示例2: makeIntHist

TH1* makeIntHist(const TH1* hist,bool intIsGreatThan)
{
  TH1* cHist = (TH1*) hist->Clone("cHist");
  cHist->SetDirectory(0);
  cHist->SetName(hist->GetName());
  int maxBin = hist->GetNbinsX()+1;

  for(int binNr=0;binNr<=hist->GetNbinsX();binNr++){
    //if(hist->GetBinContent(binNr) == 0) continue;
    float nrEntries = intIsGreatThan ? hist->Integral(binNr,maxBin) : hist->Integral(0,binNr);
    cHist->SetBinContent(binNr,nrEntries);
  }
  return cHist;
    
}
开发者ID:cms-analysis,项目名称:ZprimeDiLeptons,代码行数:15,代码来源:SamMacroModBinWidth.C

示例3: addhistos

///////////////////////////////////////////////////////////////////
//////// Go4 GUI example script addhistos.C
//          J.Adamczewski, gsi, May 2006
//          JAM May 2015: added support for 2d histograms
// NOTE: to be run in Go4 GUI local command line only!
//       NEVER call this script in remote analysis process!!!
/////// Functionality:
// adds histogram of name2 to histogram of name1
/////// Usage:
// histogram name2 will be scaled by factor.
// (e.g. if factor==-1, his2 is substracted from his1)
// The draw flag switches if the results are displayed each time this makro is called
// if display is switched off, the result histogram is just updated in browser and existing displays
///////
Bool_t addhistos(const char* name1, const char* name2, Double_t factor, Bool_t draw)
{
   if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
      std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
      return kFALSE;
   }
   TString fullname1 = go4->FindItem(name1);
   TObject* ob1=go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms
   TH1 *his1(0), *his2(0);
   if(ob1 && ob1->InheritsFrom("TH1"))
      his1 = (TH1*) ob1;
   if(his1==0) {
      std::cout <<"addhistos could not get histogram "<<fullname1 << std::endl;
      return kFALSE;
   }

   TString fullname2 = go4->FindItem(name2);
   TObject* ob2=go4->GetObject(fullname2,1000); // 1000=timeout to get object from analysis in ms
   if(ob2 && ob2->InheritsFrom("TH1"))
      his2 = (TH1*)ob2;
   if(his2==0) {
      std::cout <<"addhistos could not get histogram "<<fullname2 << std::endl;
      return kFALSE;
   }
   if((his1->GetDimension()) != (his2->GetDimension()))
   {
       std::cout <<"addhistos could not add histograms of different dimensions "<< std::endl;
       return kFALSE;
   }
   TH1* result = (TH1*) his1->Clone();
   TString n1 = his1->GetName();
   TString n2 = his2->GetName();
   TString t1 = his1->GetTitle();
   TString t2 = his2->GetTitle();
   TString soper;
   if(factor>0)
      soper.Form(") + %4.1E * (",factor);
   else
      soper.Form(") - %4.1E * (",-1*factor);
   TString finalname = TString("(")+n1+soper+n2+")";
   TString finaltitle = TString("(")+t1+soper+t2+")";
   result->SetName(finalname);
   result->SetTitle(finaltitle);
   result->Sumw2();
   result->Add(his2,factor);
   result->SetDirectory(0);
   TString rname = go4->SaveToMemory("Sums", result, kTRUE);
   std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
   if(draw) {
      ViewPanelHandle vpanel = go4->StartViewPanel();
      if(result->GetDimension()>1)
      {
          // superimpose mode is not supported for 2d histograms
          go4->DrawItem(rname, vpanel);
      }
      else
      {
        go4->SetSuperimpose(vpanel,kTRUE);
        go4->DrawItem(fullname1, vpanel);
        go4->DrawItem(fullname2, vpanel);
        go4->DrawItem(rname, vpanel);
      }
   }
   return kTRUE;
}
开发者ID:svn2github,项目名称:Go4,代码行数:79,代码来源:addhistos.C

示例4: reingold_ROOThomework

void reingold_ROOThomework(){

// Initalizing the Canvas

	TCanvas *c1 = new TCanvas("c1" , "Homework Plots" , 800 , 600 );
	c1 -> Divide(3,3);

// Defining the function with three Gaussians on a quadratic background.

	TF1 *func = new TF1("func", "pol2(0) + gaus(3) + gaus(6) + gaus(9)" , 0 , 100 );
	Double_t param[12] = {9 , 1 , -0.01 , 100 , 20 , 1 , 100 , 50 , 1 , 100 , 80 , 1};
	func->SetParameters(param);
			//  quad, lin, const, A, mu, std , ... 
// Generting and filling the histograms

	TH1F *h0 = new TH1F("h0" , "Original Spectrum" , 100 , 0 , 100 );
	for ( Int_t i = 0 ; i < 2000 ; i++ ){
		Float_t rand = func->GetRandom();
		h0->Fill(rand);
	}
	
	for ( Int_t j = 1 ; j < 4 ; j++ ){
		c1->cd(j);
		h0->Draw();
	}
// Fitting the background using ShowBackground()
	c1->cd(4);
	TH1 *hPeaks = (TH1*) h0->Clone();
	TH1 *hBkgrd = (TH1*) h0->Clone();

	hPeaks->SetName("hPeaks");
	hBkgrd->SetName("hBkgrd");

	hBkgrd = h0->ShowBackground(15);

	h0->Draw();
	hBkgrd->Draw("same");
	
	hPeaks->Add(hBkgrd,-1);
	c1->cd(7);
	hPeaks->Draw();

// Fitting the background without excluding the peaks

	c1->cd(5);
	TH1F *hPeaks2 = (TH1F*) h0->Clone();
	TH1F *hBkg2 = (TH1F*) h0->Clone();

	hPeaks2->SetName("hPeaks2");
	hBkg2->SetName("hBkg2");

	TF1 *quadBack = new TF1("quadBack" , "pol2(0)" , 0 , 100 );
	hBkg2->Fit(quadBack,"R+");
	
	hBkg2->Draw();

	c1->cd(8);

	hPeaks2->Add(quadBack , -1 );
	hPeaks2->Draw();

// Fitting the background excluding the peaks

	c1->cd(6);
	TH1F *hPeaks3 = (TH1F*) h0->Clone();
	TH1F *hBkg3 = (TH1F*) h0->Clone();

	hPeaks3->SetName("hPeaks3");
	hBkg3->SetName("hBkg3");

	TF1 *quadBack2 = new TF1("quadBack2" , fQuad , 0 , 100 ,3);
	hBkg3->Fit(quadBack2,"R+");
	
	hBkg3->Draw();

	c1->cd(9);

	hPeaks3->Add(quadBack2 , -1 );
	hPeaks3->Draw();

}
开发者ID:creingold,项目名称:CompDataAnal,代码行数:81,代码来源:reingold_ROOThomework.C

示例5: comparisonJetMCData


//.........这里部分代码省略.........
      for(int j=1;j<=data->GetNbinsX();j++){
	num1 += data->GetBinContent(j); 		//conto quante Z ci sono tra 60 e 120 GeV
	if(j>10&&j<=50) num2 += data->GetBinContent(j); // ... tra 70 e 110
	if(j>15&&j<=45) num3 += data->GetBinContent(j); // ... tra 75 e 105
      }
      cout << "\n";
      cout << data->GetNbinsX() <<" Number of bins of the invmass histo\n";
      printf("Number of Z in 60-120 %i --- 70-110 %i --- 75-105 %i \n",num1,num2,num3);
      cout << "\n";
    }
    if(str.Contains("zYieldVsjets") && !str.Contains("Vtx")){
      for(int j=1;j<=data->GetNbinsX();j++){
	num1 += data->GetBinContent(j); 		//conto quante Z
	if(j>1) num2 += data->GetBinContent(j); // ... +1,2,3,4... jets
	if(j>2) num3 += data->GetBinContent(j); // ... +2,3,4... jets
	if(j>3) num4 += data->GetBinContent(j); // ..    if(str=="jet_pT"){
	if(j>4) num5 += data->GetBinContent(j); // ... +4... jets
      }
      cout << "\n";
      cout << data->GetNbinsX() <<" Number of bins of the zYieldVsjets histo\n";
      printf("Number of Z+n jet %i --- >1 %i --- >2 %i --- >3 %i --- >4 %i \n",num1,num2,num3,num4,num5);
      cout << "\n";
    }    

    //======================
    // Z + jets signal
    mcf->cd("validationJEC");
    TH1F* mc;
    gDirectory->GetObject(plot.c_str(),mc);
    TH1F * hsum;
    if(mc){
      hsum =  (TH1F*) mc->Clone();
      hsum->SetTitle("hsum");
      hsum->SetName("hsum");
      hsum->Reset();

      Double_t mcint = mc->Integral();
      mc->SetFillColor(kRed);
      mc->Sumw2();
      if(lumiweights==0) mc->Scale(dataint/mcint);
		
      // Blocco da propagare negli altri MC
      if(zNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) mc->Scale( dataLumi2011pix / (zNumEvents / zjetsXsect));
	    else mc->Scale( dataLumi2011 / (zNumEvents / zjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) mc->Scale( dataLumi2011Apix / (zNumEvents / zjetsXsect));
	      else mc->Scale( dataLumi2011A / (zNumEvents / zjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) mc->Scale( dataLumi2011Bpix / (zNumEvents / zjetsXsect));
	      else mc->Scale( dataLumi2011B / (zNumEvents / zjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) mc->Scale(zjetsScale);
      }
      // fin qui
      if(lumiweights==1) mc->Scale(1./zwemean);  // perche' i Weights non fanno 1...
      mc->Rebin(rebin);
开发者ID:bajarang,项目名称:VJets_TreeMaker5311,代码行数:67,代码来源:DrawComparisonXSecSyst.C

示例6: fileOutName

/**
 * This function fits TH2F slices with a selected fitType function (gaussian, lorentz, ...).
 */
TGraphErrors* fit2DProj(TString name, TString path, int minEntries, int rebinX, int rebinY, int fitType,
                        TFile * outputFile, const TString & resonanceType, const double & xDisplace, const TString & append) {

  //Read the TH2 from file
  TFile *inputFile = new TFile(path);
  TH2 * histo = (TH2*) inputFile->Get(name);
  if( rebinX > 0 ) histo->RebinX(rebinX);
  if( rebinY > 0 ) histo->RebinY(rebinY);

  //Declare some variables
  TH1 * histoY;
  TString nameY;
  std::vector<double> Ftop;
  std::vector<double> Fwidth;
  std::vector<double> Fmass;
  std::vector<double> Etop;
  std::vector<double> Ewidth;
  std::vector<double> Emass;
  std::vector<double> Fchi2;
  std::vector<double> Xcenter;
  std::vector<double> Ex;

  TString fileOutName("fitCompare2"+name);
  fileOutName += append;
  fileOutName += ".root";
  TFile *fileOut=new TFile(fileOutName,"RECREATE");

  for (int i=1; i<=(histo->GetXaxis()->GetNbins());i++) {

    //Project on Y (set name and title)
    std::stringstream number;
    number << i;
    TString numberString(number.str());
    nameY = name + "_" + numberString;
    // std::cout << "nameY  " << nameY << std::endl;

    histoY = histo->ProjectionY(nameY, i, i);

    double xBin = histo->GetXaxis()->GetBinCenter(i);
    std::stringstream xBinString;
    xBinString << xBin;
    TString title("Projection of x = ");
    title += xBinString.str();

    histoY->SetName(title);

    if (histoY->GetEntries() > minEntries) {

      //Make the dirty work!
      TF1 *fit;
      std::cout << "fitType = " << fitType << std::endl;
      if(fitType == 1) fit = gaussianFit(histoY, resonanceType);
      else if(fitType == 2) fit = lorentzianFit(histoY, resonanceType);
      else if(fitType == 3) fit = linLorentzianFit(histoY);
      else {
	std::cout<<"Wrong fit type: 1=gaussian, 2=lorentzian, 3=lorentzian+linear."<<std::endl;
	abort();
      }

      double *par = fit->GetParameters();
      double *err = fit->GetParErrors();

      // Check the histogram alone
      TCanvas *canvas = new TCanvas(nameY+"alone", nameY+" alone");
      histoY->Draw();
      canvas->Write();

      // Only for check
      TCanvas *c = new TCanvas(nameY, nameY);

      histoY->Draw();
      fit->Draw("same");
      fileOut->cd();
      c->Write();

      if( par[0] == par[0] ) {
        //Store the fit results
        Ftop.push_back(par[0]);
        Fwidth.push_back(fabs(par[1]));//sometimes the gaussian has negative width (checked with Rene Brun)
        Fmass.push_back(par[2]);
        Etop.push_back(err[0]);
        Ewidth.push_back(err[1]);
        Emass.push_back(err[2]);

        Fchi2.push_back(fit->GetChisquare()/fit->GetNDF());

        double xx= histo->GetXaxis()->GetBinCenter(i);
        Xcenter.push_back(xx);
        double ex = 0;
        Ex.push_back(ex); 
      }
      else {
        // Skip nan
        std::cout << "Skipping nan" << std::endl;
        Ftop.push_back(0);
        Fwidth.push_back(0);
        Fmass.push_back(0);
//.........这里部分代码省略.........
开发者ID:Andrej-CMS,项目名称:cmssw,代码行数:101,代码来源:fit2DProj.C

示例7: moveDirHistsToStacks

void stackPlotter::moveDirHistsToStacks(TDirectory* tdir, TString histname, int color){
	if(debug)
		std::cout << "stackPlotter::moveDirHistsToStacks" << std::endl;

	// get metainfo from directory, else exit TODO
	metaInfo tMI;
	tMI.extractFrom(tdir);

	if(debug) {
		std::cout << "stackPlotter::moveDirHistsToStacks || metaInfo color=" << tMI.color << std::endl;
		std::cout << "stackPlotter::moveDirHistsToStacks || metaInfo legendname=" << tMI.legendname<< std::endl;
		std::cout << "stackPlotter::moveDirHistsToStacks || metaInfo legendorder=" << tMI.legendorder << std::endl;
	}


	TIter    histIter(tdir->GetListOfKeys());
	TObject* cHistObj;
	TKey*    cHistKey;

	if(debug)
		std::cout << "stackPlotter::moveDirHistsToStacks || Iterating through histograms." << std::endl;

	// loop through keys in the directory
	while((cHistKey = (TKey*) histIter())) {
        if(histname != cHistKey->GetName()) continue;
		cHistObj=tdir->Get(cHistKey->GetName());
		if(!cHistObj->InheritsFrom(TH1::Class())) continue;

		if(debug)
			std::cout << "stackPlotter::moveDirHistsToStacks || Found histogram "
			<< cHistKey->GetName() << std::endl;

		// prepare the histogram to be added to the stack
		TH1* cHist = (TH1*) cHistObj->Clone();
		cHist->SetDirectory(0);
		TString mapName = cHist->GetName();

		std::pair<Int_t,TH1*> newEntry(tMI.legendorder,cHist);

		// initialize the stack info if needed
		if(!stacksLegEntries_.count(mapName)) {
			std::vector<std::pair<Int_t,TH1*> > legInfo(0);
			legInfo.push_back(newEntry);
			stacksLegEntries_[mapName] = legInfo;
		}

		cHist->SetFillColor(color);
		cHist->SetFillStyle(1001);
		cHist->SetMarkerStyle(kNone);
		cHist->SetMarkerColor(kBlack);
		cHist->SetLineColor(kBlack);
		cHist->SetTitle(mapName);
		cHist->SetName(tMI.legendname);

		std::vector<std::pair<Int_t,TH1*> > legEntries = stacksLegEntries_[mapName];
		if(debug)
			std::cout << "stackPlotter::moveDirHistsToStacks || legEntries size is " << legEntries.size() << std::endl;
		for(size_t i=0; i < legEntries.size(); i++) {
			if(legEntries.at(i).second == cHist && legEntries.at(i).first == tMI.legendorder) break;

			if(legEntries.at(i).first >= tMI.legendorder) {
				if(debug)
					std::cout << "stackPlotter::moveDirHistsToStacks || i is " << i << std::endl;
				stacksLegEntries_[mapName].insert(stacksLegEntries_[mapName].begin()+i,newEntry);
				break;
			}

			if(i==legEntries.size()-1) {
				stacksLegEntries_[mapName].push_back(newEntry);
				break;
			}
		}

		if(debug)
			std::cout << "stackPlotter::moveDirHistsToStacks || legEntries size is " << legEntries.size() << std::endl;
	}

}
开发者ID:ssghosh,项目名称:Brown-FCNC2016-thcu,代码行数:78,代码来源:stackPlotter.cpp

示例8: makePlots

void makePlots()
{

  TFile * f2 = TFile::Open( "L1ITMuonBarrelPlots2.root");
  TFile * f02 = TFile::Open( "L1ITMuonBarrelPlots0.2.root");
  TFile * f005 = TFile::Open( "L1ITMuonBarrelPlots0.05.root");
  TFile * f002 = TFile::Open( "L1ITMuonBarrelPlots0.02.root");

  d2 = (TDirectory *) f2->Get( "L1ITMuPlotter");
  d02 = (TDirectory *) f02->Get( "L1ITMuPlotter");
  d005 = (TDirectory *) f005->Get( "L1ITMuPlotter");
  d002 = (TDirectory *) f002->Get( "L1ITMuPlotter");
  TString name;


  //////////////////
  /// Confirmed
  drawConfirmed( "confirmed_st1" );
  drawConfirmed( "confirmed_st2" );
  drawConfirmed( "confirmed_st3" );
  drawConfirmed( "confirmed_st4" );

  TH1* conf = d005->Get( "confirmed_st1" )->Clone();
  TH1* conf_2 = d005->Get( "confirmed_st2" );
  TH1* conf_3 = d005->Get( "confirmed_st3" );
  TH1* conf_4 = d005->Get( "confirmed_st4" );
  conf->Add( conf_2 );
  conf->Add( conf_3 );
  conf->Add( conf_4 );

  name = "confirmed_all";
  TCanvas * confirmed =  new TCanvas(name, name);
  confirmed->cd();
  // confirmed->SetLogy();
  confirmed->SetGridy();
  conf->SetLineWidth(2);
  conf->Draw();
  conf->Draw("sametext");
  conf->SetTitle("confirmed in all stations");
  conf->SetName("confirmed in all stations");
  confirmed->SaveAs( name + "_dphi0.05.png" );

  ////////////////////
  /// deltaPhiBin
  name = "deltaPhiBin";
  TCanvas * deltaPhiBin = new TCanvas(name, name);
  deltaPhiBin->cd();
  TH1* dphibin = d2->Get(name);
  dphibin->SetLineWidth(2);
  dphibin->Draw("text");
  dphibin->Draw("same");
  deltaPhiBin->SaveAs( name + ".png" );

  ////////////////////
  /// deltaPhi
  name = "deltaPhi";
  TCanvas * deltaPhi = new TCanvas(name, name);
  deltaPhi->cd();
  TH1* dphi = d2->Get(name);
  dphi->SetLineWidth(2);
  dphi->Draw();
  deltaPhi->SaveAs( name + ".png" );

  ////////////////////
  /// deltaPhiDt
  name = "deltaPhiDt";
  TCanvas * deltaPhiDt = new TCanvas(name, name);
  deltaPhiDt->cd();
  TH1* dphiDt = d005->Get(name);
  dphiDt->SetLineWidth(2);
  dphiDt->Draw();
  deltaPhiDt->SaveAs( name + ".png" );

  /////////////////////////
  /// rpcInHitsPerDtseg
  name = "rpcInHitsPerDtseg";
  TCanvas * rpcInHitsPerDtseg = new TCanvas(name, name);
  rpcInHitsPerDtseg->SetGridy();
  rpcInHitsPerDtseg->SetLogy();
  rpcInHitsPerDtseg->cd();
  TH1* rpcin = d005->Get(name);
  rpcin->SetLineWidth(2);
  rpcin->Draw();
  rpcInHitsPerDtseg->SaveAs( name + "_dphi0.05.png" );

  /////////////////////////
  /// rpcOutHitsPerDtseg
  name = "rpcOutHitsPerDtseg";
  TCanvas * rpcOutHitsPerDtseg =  new TCanvas(name, name);
  rpcOutHitsPerDtseg->SetGridy();
  rpcOutHitsPerDtseg->SetLogy();
  rpcOutHitsPerDtseg->cd();
  TH1* rpcout = d005->Get(name);
  rpcout->SetLineWidth(2);
  rpcout->Draw();
  rpcOutHitsPerDtseg->SaveAs( name + "_dphi0.05.png" );

  ////////////////////
  /// dtQuality_st1
  name = "dtQuality_st1";
//.........这里部分代码省略.........
开发者ID:bapavlov,项目名称:L1IntegratedMuonTrigger,代码行数:101,代码来源:makePlots.C


注:本文中的TH1::SetName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。