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


C++ TString::ReplaceAll方法代码示例

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


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

示例1: geometry

void geometry() {
   TString dir = gSystem->UnixPathName(__FILE__);
   dir.ReplaceAll("geometry.C","");
   dir.ReplaceAll("/./","/");
   gROOT->Macro(Form("%s/na49.C",dir.Data()));
   gROOT->Macro(Form("%s/na49geomfile.C",dir.Data()));
}
开发者ID:iahmad-khan,项目名称:root,代码行数:7,代码来源:geometry.C

示例2: g

TGraphErrors g(TTree *tree, TString alphaName, TString constTermName){
  Double_t alpha, constTerm;
  alphaName.ReplaceAll("-","_");
  constTermName.ReplaceAll("-","_");

  tree->SetBranchAddress(alphaName,&alpha);
  tree->SetBranchAddress(constTermName,&constTerm);

  //Long64_t nEntries=genTree->GetEntries();

  TGraphErrors graph;
  Int_t iPoint=0;

  tree->GetEntry(0);
  std::cout << alpha << "\t" << constTerm << std::endl;
  Double_t alpha2=alpha*alpha;
  Double_t const2=constTerm*constTerm;
  for(Double_t energy=20; energy<150; energy+=10){
    Double_t addSmearing = (sqrt(alpha2/energy+const2));
    
    graph.SetPoint(iPoint, energy, addSmearing);
    graph.SetPointError(iPoint,0, 0);
    iPoint++;
  }

  graph.Set(iPoint);
  tree->ResetBranchAddresses();
  graph.Draw("A L");
  graph.SetFillColor(kBlue);
  graph.SetLineColor(kYellow);
  graph.GetXaxis()->SetTitle("Energy [GeV]");
  graph.GetYaxis()->SetTitle("Additional smearing [%]");
  return graph;
}
开发者ID:alexeyfinkel,项目名称:ECALELF,代码行数:34,代码来源:mcmcDraw.C

示例3: make_histos_syst_rawyield

void make_histos_syst_rawyield(TString file_syst, TString file_default, TString out_tag){

  TFile *f1 = new TFile(file_syst.Data(),"read");
  TFile *f2 = new TFile(file_default.Data(),"read");
  TDirectoryFile *dir1 = (TDirectoryFile*)(f1->Get("effunf"));
  TDirectoryFile *dir2 = (TDirectoryFile*)(f2->Get("effunf"));
  TList *list = dir1->GetListOfKeys();

  TFile *f = new TFile(Form("plots/ratiosyst_%s.root",out_tag.Data()),"recreate");

  for (int i=0; i<list->GetSize(); i++){
    TString name = dir1->GetListOfKeys()->At(i)->GetName();
    if (!(name.Contains("hreco_"))) continue;
    TObject *obj1 = dir1->Get(name.Data());
    assert(obj1);
    TObject *obj2 = dir2->Get(name.Data());
    assert(obj2);
    TString newname = name;
    newname.Append("_ratiosyst");
    if (name.EndsWith("_0")) newname.ReplaceAll("_0_","_EBEB_");
    if (name.EndsWith("_1")) newname.ReplaceAll("_1_","_EBEE_");
    if (name.EndsWith("_2")) newname.ReplaceAll("_2_","_EEEE_");
    TH1F *h = (TH1F*)(((TH1F*)obj1)->Clone(newname.Data()));
    h->SetTitle(h->GetName());
    h->Divide((TH1F*)obj2);
    for (int j=0; j<h->GetNbinsX(); j++) h->SetBinError(j+1,0);
    for (int j=0; j<h->GetNbinsX(); j++) h->SetBinContent(j+1,1+fabs(1-h->GetBinContent(j+1)));
    f->cd();
    h->Write();
  }

}
开发者ID:peruzzim,项目名称:diphoton,代码行数:32,代码来源:make_histos_syst_rawyield.C

示例4: RecoQA

void RecoQA(const char* inFile) {
  gROOT->LoadMacro("bfcread_hist_prefixes_add_to_ps.C");

  TString baseName = inFile;
  if (baseName.EndsWith(".daq"))
    baseName.ReplaceAll(".daq",".hist.root");
  else if (baseName.EndsWith(".event.root"))
    baseName.ReplaceAll(".event.root",".hist.root");
  else if (baseName.EndsWith(".MuDst.root"))
    baseName.ReplaceAll(".MuDst.root",".hist.root");

  TString histFile = baseName;

  baseName.Remove(0,baseName.Last('/')+1);

  TString outputName = baseName;
  outputName.ReplaceAll(".root",".CC");

  TString histList = "StRoot/St_QA_Maker/QAhlist_Reco.h";
  if (! gSystem->Which(".",histList.Data()))
    histList.Prepend(gSystem->ExpandPathName("$STAR/"));
  
  bfcread_hist_prefixes_add_to_ps(histFile.Data(),"EventQA",
    "bfcTree",outputName.Data(),baseName.Data(),histList.Data());
}
开发者ID:star-bnl,项目名称:star-macros,代码行数:25,代码来源:RecoQA.C

示例5: MakeTTreeFromBinfit

void MakeTTreeFromBinfit() {
//  Read data from an ascii file and create a root file with an histogram and an ntuple.
//   see a variant of this macro in basic2.C
      

// read file $ROOTSYS/tutorials/tree/basic.dat
// this file has 3 columns of float data
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("MakeTTreeFromBinfit.C","");
   dir.ReplaceAll("/./","/");
   ifstream in;
   in.open(Form("%sBinfit_results_reco_ptGT8.txt",dir.Data()));

   Float_t fracd,fracs, fracn, chi;
   Int_t nlines;
   string result;
   TFile *f = new TFile("Binfit_results_spsdpsnlo_ptYdy_reco8gev.root","RECREATE");
   TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","fracd:fracs:fracn:chi");

   while (1) {
      in >> fracd >> fracs >> fracn >> chi;
      if (!in.good()) break;
      if (nlines < 5) printf("fracd=%8f, chi=%8f \n",fracd,chi);
      ntuple->Fill(fracd,fracs,fracn,chi);
      nlines++;
   }
   printf(" found %d points\n",nlines);

   in.close();

   f->Write();
}
开发者ID:griley4,项目名称:usercode,代码行数:32,代码来源:MakeTTreeFromBinfit.C

示例6: myfit

void myfit()
{
   TString dir = gSystem->UnixPathName(__FILE__);
   dir.ReplaceAll("myfit.C","../hsimple.C");
   dir.ReplaceAll("/./","/");
   if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
   TFile *hsimple = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
   if (!hsimple) return;

   TCanvas *c1 = new TCanvas("c1","the fit canvas",500,400);

   TH1F *hpx = (TH1F*)hsimple->Get("hpx");

// Creates a Root function based on function fitf above
   TF1 *func = new TF1("fitf",fitf,-2,2,3);

// Sets initial values and parameter names
   func->SetParameters(100,0,1);
   func->SetParNames("Constant","Mean_value","Sigma");

// Fit histogram in range defined by function
   hpx->Fit(func,"r");

// Gets integral of function between fit limits
   printf("Integral of function = %g\n",func->Integral(-2,2));
}
开发者ID:digideskio,项目名称:root,代码行数:26,代码来源:myfit.C

示例7: GetLogical

TString KVNumberList::GetLogical(const Char_t *observable)
{
    // Get logical expression of 'this' list in the TTree:Draw condition format
    // observable is one of the leaf of the TTree
    // 12-15 20 --> ( 12<=observable&&observable<=15 || observable==20 )
    // return "" if 'this' list  is empty

    if (IsEmpty()) return "";
    GetList();
    TString tmp = fString;
    tmp.ReplaceAll(" ","||");
    TObjArray *toks = tmp.Tokenize("||");
    TString cond="( ";
    Int_t nt = toks->GetEntries();
    for (Int_t ii=0; ii<nt; ii+=1) {
        TString line = ((TObjString*)(*toks)[ii])->GetString();
        if ( line.Contains("-") ) {
            line.ReplaceAll("-",Form("<=%s&&%s<=",observable,observable));
            cond+=line;
        }
        else {
            cond+=Form("%s==",observable)+line;
        }
        if (ii!=nt-1) cond+="||";
    }
    cond += " )";
    delete toks;
    return cond;
}
开发者ID:pwigg,项目名称:kaliveda,代码行数:29,代码来源:KVNumberList.cpp

示例8: basic

void basic() {
//  Read data from an ascii file and create a root file with an histogram and an ntuple.
//   see a variant of this macro in basic2.C
//Author: Rene Brun


// read file $ROOTSYS/tutorials/tree/basic.dat
// this file has 3 columns of float data
   TString dir = gSystem->UnixPathName(__FILE__);
   dir.ReplaceAll("basic.C","");
   dir.ReplaceAll("/./","/");
   ifstream in;
   in.open(Form("%sbasic.dat",dir.Data()));

   Float_t x,y,z;
   Int_t nlines = 0;
   TFile *f = new TFile("basic.root","RECREATE");
   TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
   TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y:z");

   while (1) {
      in >> x >> y >> z;
      if (!in.good()) break;
      if (nlines < 5) printf("x=%8f, y=%8f, z=%8f\n",x,y,z);
      h1->Fill(x);
      ntuple->Fill(x,y,z);
      nlines++;
   }
   printf(" found %d points\n",nlines);

   in.close();

   f->Write();
}
开发者ID:digideskio,项目名称:root,代码行数:34,代码来源:basic.C

示例9: bestFit

TGraphErrors bestFit(TTree *tree, TString alphaName, TString constTermName){
  Double_t alpha, constTerm;
  alphaName.ReplaceAll("-","_");
  constTermName.ReplaceAll("-","_");

  tree->SetBranchAddress(alphaName,&alpha);
  tree->SetBranchAddress(constTermName,&constTerm);

  //Long64_t nEntries=genTree->GetEntries();

  TGraphErrors graph;
  Int_t iPoint=0;

  tree->GetEntry(0);
  graph.SetPoint(0, constTerm, alpha);
  graph.SetPointError(0,0, 0);
  iPoint++;

  graph.Set(iPoint);
  tree->ResetBranchAddresses();
  graph.Draw("A P");
//   graph.SetFillColor(kBlue);
//   graph.SetLineColor(kYellow);
//   graph.GetXaxis()->SetTitle("Energy [GeV]");
//   graph.GetYaxis()->SetTitle("Additional smearing [%]");
  return graph;
}
开发者ID:alexeyfinkel,项目名称:ECALELF,代码行数:27,代码来源:mcmcDraw.C

示例10: GetEtaBin

  TCollection* GetEtaBin(TObject* o, Double_t& etaMin, Double_t& etaMax)
  {
    const char* re = "[pm][0-9]*d[0-9]*_[pm][0-9]*d[0-9]*";
    TRegexp     check(re);

    if (!o->IsA()->InheritsFrom(TCollection::Class())) {
      // Warning("GetEtaBin", "Don't know how to deal with %s - a %s",
      //         o->GetName(), o->ClassName());
      return 0;
    }
    TString oN(o->GetName());
    if (oN.Index(check) == kNPOS) { 
      // Warning("GetEtaBin", "Collection %s does not match %s",
      //         oN.Data(), re);
      return 0;
    }
    Int_t    ul     = oN.Index("_");
    TString  sMin   = oN(0, ul);
    TString  sMax   = oN(ul+1, oN.Length()-ul-1);
    sMin.ReplaceAll("p", "+");
    sMin.ReplaceAll("m", "-");
    sMin.ReplaceAll("d", ".");
    sMax.ReplaceAll("p", "+");
    sMax.ReplaceAll("m", "-");
    sMax.ReplaceAll("d", ".");
    etaMin = sMin.Atof();
    etaMax = sMax.Atof();

    return static_cast<TCollection*>(o);
  }
开发者ID:ktf,项目名称:AliPhysics,代码行数:30,代码来源:SummaryMultDistsDrawer.C

示例11: mergeKFolds

void HistoTransform::mergeKFolds(TDirectory* source, SubDirectory* subDir) {
  TDirectory* savdir = gDirectory;
  TDirectory* adir = source;
  //    if (source != m_inFile) {
  //      adir = savdir -> mkdir(source -> GetName());
  //    }
  adir -> cd();
  //loop on all entries of this directory
  TKey* key;
  TIter nextkey(source -> GetListOfKeys());
  while ((key = (TKey*) nextkey())) {
    TClass* cl = gROOT -> GetClass(key -> GetClassName());
    if (!cl) continue;
    if (cl -> InheritsFrom(TDirectory::Class())) {
      cout << "INFO: going into directory '" << key -> GetName() << "'" << endl;
      source -> cd(key -> GetName());
      TDirectory* subdir = gDirectory;
      adir -> cd();
      mergeKFolds(subdir, subDir);
      adir -> cd();
    } else if (cl -> InheritsFrom(TH1::Class())) {
      string name = key -> GetName();
      TH1* histo = (TH1*) source -> Get(name.c_str());
      adir -> cd();
      KFold* kFold = getKFold(subDir, name);
      if (isFirstOfKFold(kFold, name)) {
        TString string0ofK = TString::Format("_0of%i", (int) kFold -> regions.size());
        TString nameMerged = name.c_str();
        nameMerged.ReplaceAll(string0ofK, "");
        TH1* histoMerged = (TH1*) histo -> Clone(nameMerged);
        bool foundAllFolds = true;
        for (unsigned int iRegion = 1; iRegion < kFold -> regions.size(); iRegion++) {
          //region = kFold -> regions[iRegion];
          TString foldName = name.c_str();
          //foldName.ReplaceAll(nameFirstRegion, region -> name.c_str());
          TString stringIofK = TString::Format("_%iof%i", iRegion, (int) kFold -> regions.size());
          foldName.ReplaceAll(string0ofK, stringIofK);
          TObject* objHisto = source -> Get(foldName);
          if (objHisto) {
            histo = (TH1*) objHisto;
            histoMerged -> Add(histo);
            delete histo;
            //cout << "added " << iRegion << endl;
          } else {
            cout << "WARNING: histogram '" << foldName << "' not found! Not writing merged output." << endl;
            foundAllFolds = false;
          }
        }
        if (foundAllFolds)
          histoMerged -> Write();
        delete histoMerged;
      }
    }
  }
  adir -> SaveSelf(kTRUE);
  savdir -> cd();
}
开发者ID:tibristo,项目名称:mva,代码行数:57,代码来源:HistoTransform.cpp

示例12: drawMyPlot

doADraw3bins(TString name, TString title){
    cout << "on va plotter le plot " << name << endl;
    drawMyPlot(name, "|#eta| <0.9",title,0.6,1.05);
    name.ReplaceAll("bin0","bin1");
	drawMyPlot(name, "0.9 <|#eta| < 1.2",title,0.6,1.05);
    name.ReplaceAll("bin1","bin2");
	drawMyPlot(name, "1.2 <|#eta| < 2.4",title,0.6,1.05);
    
}
开发者ID:HuguesBrun,项目名称:electronEffPloter,代码行数:9,代码来源:doThePlotsMC_runMC.C

示例13: fit1

void fit1() {
   //Simple fitting example (1-d histogram with an interpreted function)
   //To see the output of this macro, click begin_html <a href="gif/fit1.gif">here</a>. end_html
   //Author: Rene Brun
   
   TCanvas *c1 = new TCanvas("c1_fit1","The Fit Canvas",200,10,700,500);
   c1->SetGridx();
   c1->SetGridy();
   c1->GetFrame()->SetFillColor(21);
   c1->GetFrame()->SetBorderMode(-1);
   c1->GetFrame()->SetBorderSize(5);

   gBenchmark->Start("fit1");
   //
   // We connect the ROOT file generated in a previous tutorial
   // (see begin_html <a href="fillrandom.C.html">Filling histograms with random numbers from a function</a>) end_html
   //
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("fit1.C","");
   dir.ReplaceAll("/./","/");
   TFile *fill = TFile::Open("fillrandom.root");
   if (!fill) {
      gROOT->ProcessLine(Form(".x %s../hist/fillrandom.C",dir.Data()));
      fill = TFile::Open("fillrandom.root");
      if (!fill) return;
   }
      
   //
   // The function "ls()" lists the directory contents of this file
   //
   fill->ls();

   //
   // Get object "sqroot" from the file. Undefined objects are searched
   // for using gROOT->FindObject("xxx"), e.g.:
   // TF1 *sqroot = (TF1*) gROOT.FindObject("sqroot")
   //
   sqroot->Print();

   //
   // Now fit histogram h1f with the function sqroot
   //
   h1f->SetFillColor(45);
   h1f->Fit("sqroot");

   // We now annotate the picture by creating a PaveText object
   // and displaying the list of commands in this macro
   //
   fitlabel = new TPaveText(0.6,0.3,0.9,0.80,"NDC");
   fitlabel->SetTextAlign(12);
   fitlabel->SetFillColor(42);
   fitlabel->ReadFile(Form("%sfit1_C.C",dir.Data()));
   fitlabel->Draw();
   c1->Update();
   gBenchmark->Show("fit1");
}
开发者ID:dawehner,项目名称:root,代码行数:56,代码来源:fit1.C

示例14: SaveCanvasAs

void KVCanvas::SaveCanvasAs()
{

   if (strcmp("", fSavedAs)) {
      Int_t ret_val;
      TString file = fSavedAs.Data();
      file.ReplaceAll(gSystem->DirName(fSavedAs.Data()), "");
      file.ReplaceAll("/", "");
      new TGMsgBox(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), "File name exist",
                   Form("File name '%s' already exists, OK to owerwrite it?", file.Data()),
                   kMBIconExclamation, kMBOk | kMBCancel, &ret_val);

      if (ret_val & kMBOk) {
         fCanvas->SaveAs(fSavedAs);
         return;
      }
   }

   const char* SaveAsTypes[] = {
      "PDF",          "*.pdf",
      "PostScript",   "*.ps",
      "Encapsulated PostScript", "*.eps",
      "SVG",          "*.svg",
      "TeX",          "*.tex",
      "GIF",          "*.gif",
      "ROOT macros",  "*.C",
      "ROOT files",   "*.root",
      "XML",          "*.xml",
      "PNG",          "*.png",
      "XPM",          "*.xpm",
      "JPEG",         "*.jpg",
      "TIFF",         "*.tiff",
      "XCF",          "*.xcf",
      "All files",    "*",
      0,              0
   };

   TString workdir = gSystem->WorkingDirectory();
   static TString dir(".");
   static Int_t typeidx = 0;
   static Bool_t overwr = kFALSE;
   TGFileInfo fi;
   fi.fFileTypes   = SaveAsTypes;
   fi.fIniDir      = StrDup(dir);
   fi.fFileTypeIdx = typeidx;
   fi.fOverwrite   = overwr;
   new TGFileDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), kFDSave, &fi);
   gSystem->ChangeDirectory(workdir.Data());
   if (!fi.fFilename) return;
   TString fn = fi.fFilename;
   dir     = fi.fIniDir;
   typeidx = fi.fFileTypeIdx;
   overwr  = fi.fOverwrite;
   fCanvas->SaveAs(fn);
   fSavedAs = fn;
}
开发者ID:GiuseppePast,项目名称:kaliveda,代码行数:56,代码来源:KVCanvas.cpp

示例15: demo

void demo(string infile = "data.dat"){
	TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
	dir.ReplaceAll("demo.C","");
	dir.ReplaceAll("/./","/");
	TString pathName;
	pathName = dir + "data.dat";
	infile = pathName;
	cout << infile<< endl;
	plotGood(infile);
	plotBad(infile);
}
开发者ID:gsize,项目名称:ROOTScript,代码行数:11,代码来源:demo.C


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