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


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

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


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

示例1: merge_all

/**
 * Merge all files in folder path with names matching the regular expression filematch into trees in a ROOT file.
 *
 * @param filematch Merge files whose names match this regular expression (default: read all)
 * @param path Merge files in this folder (default: current folder)
 */
void merge_all(const char *filematch = "[0-9]+[a-z]+.out", const char *path = ".")
{
	TFile *outfile = new TFile("out.root","RECREATE"); // create ROOT file
	ifstream infile;
	TSystemDirectory dir(path,path); // open given folder
	TList *files = dir.GetListOfFiles(); // get all files in that folder
	TRegexp re(filematch); // create regular expression from given parameter

	outfile->cd(); // switch current directory to ROOT file
	
	Int_t n = 0;
	for (Int_t i = 0; ; i++){ // for loop incrementing index i
		TObject *f = files->At(i); // get file from folder with index i
		if (f){ // if next file was found
			TString filename = f->GetName(); // get filename
			TString fn = filename;
			fn.Resize(filename.Length() - 4); // shorten filename by extension ".out"
			
			ULong64_t jobnumber;
			char logtype[64];
			double data[1024];
			
			if ((re.Index(filename, &n) == 0) && (sscanf(fn.Data(), "%Ld%s", &jobnumber, logtype) == 2)){ // if filename matches regular expression and contains jobnumber
				infile.open(filename.Data()); // open file
				TNtupleD *tree = (TNtupleD*)outfile->Get(logtype); // get corresponding tree from file
				
				if (!tree) { // if tree does not yet exist
					TString bdescriptor;
					bdescriptor.ReadLine(infile); // read branch descriptor from file header
					bdescriptor.ReplaceAll(" ",":"); // format branch descriptor for root ("x y z" -> "x:y:z")

					tree = new TNtupleD(logtype, logtype, bdescriptor.Data()); // create new tree with name logtype from filename 
					printf("%ss have %i columns\n", logtype, tree->GetNvar());
				}
				else
					infile.ignore(9999, '\n'); // if tree already exists skip file header

				n = tree->GetNvar(); // get number of file columns
				cout << "Adding " << filename << '\n';
				while (1){
					for (int j = 0; j < n; j++) infile >> data[j]; // read values into data array
					if (!infile) break; // if something happened during reading: stop
					tree->Fill(data); // fill data into tree
				}
				infile.close(); // close file
				cout << "Entries: " << tree->GetEntries() << '\n';
			}
		}
		else break;
开发者ID:beja1100,项目名称:PENTrack,代码行数:55,代码来源:merge_all.c

示例2: paracoor

void paracoor( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE )
{
   // set style and remove existing canvas'
   TMVAGlob::Initialize( useTMVAStyle );

   // checks if file with name "fin" is already open, and if not opens one
   TFile* file = TMVAGlob::OpenFile( fin );  
   TTree* tree = (TTree*)file->Get("TestTree");
   if(!tree) {
      cout << "--- No TestTree saved in ROOT file. Parallel coordinates will not be plotted" << endl;
      return;
   }

   // first get list of leaves in tree
   TObjArray* leafList = tree->GetListOfLeaves();
   vector<TString> vars;
   vector<TString> mvas;   
   for (Int_t iar=0; iar<leafList->GetSize(); iar++) {
      TLeaf* leaf = (TLeaf*)leafList->At(iar);
      if (leaf != 0) {
         TString leafName = leaf->GetName();
         if (leafName != "type" && leafName != "weight"  && leafName != "boostweight" &&
             leafName != "class" && leafName != "className" && leafName != "classID" && 
             !leafName.Contains("prob_")) {
            // is MVA ?
            if (TMVAGlob::ExistMethodName( leafName )) {
               mvas.push_back( leafName );
            }
            else {
               vars.push_back( leafName );
            }
         }
      }
   }

   cout << "--- Found: " << vars.size() << " variables" << endl;
   cout << "--- Found: " << mvas.size() << " MVA(s)" << endl;
   

   TString type[2] = { "Signal", "Background" };
   const Int_t nmva = mvas.size();
   TCanvas* csig[nmva];
   TCanvas* cbkg[nmva];
   for (Int_t imva=0; imva<mvas.size(); imva++) {
      cout << "--- Plotting parallel coordinates for : " << mvas[imva] << " & input variables" << endl;

      for (Int_t itype=0; itype<2; itype++) {

         // create draw option
         TString varstr = mvas[imva] + ":";
         for (Int_t ivar=0; ivar<vars.size(); ivar++) varstr += vars[ivar] + ":";
         varstr.Resize( varstr.Last( ':' ) );

         // create canvas
         TString mvashort = mvas[imva]; mvashort.ReplaceAll("MVA_","");
         TCanvas* c1 = (itype == 0) ? csig[imva] : cbkg[imva];
         c1 = new TCanvas( Form( "c1_%i",itype ), 
                           Form( "Parallel coordinate representation for %s and input variables (%s events)", 
                                 mvashort.Data(), type[itype].Data() ), 
                           50*(itype), 50*(itype), 750, 500 );      
         tree->Draw( varstr.Data(), Form("classID==%i",1-itype) , "para" );
         c1->ToggleEditor();
         gStyle->SetOptTitle(0);

         TParallelCoord*    para   = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject( "ParaCoord" );
         TParallelCoordVar* mvavar = (TParallelCoordVar*)para->GetVarList()->FindObject( mvas[imva] );
         Double_t minrange = tree->GetMinimum( mvavar->GetName() );
         Double_t maxrange = tree->GetMaximum( mvavar->GetName() );
         Double_t width    = 0.2*(maxrange - minrange);
         Double_t x1 = minrange, x2 = x1 + width;
         TParallelCoordRange* parrange = new TParallelCoordRange( mvavar, x1, x2 );
         parrange->SetLineColor(4);
         mvavar->AddRange( parrange );

         para->AddSelection("-1");

         for (Int_t ivar=1; ivar<TMath::Min(Int_t(vars.size()) + 1,3); ivar++) {
            TParallelCoordVar* var = (TParallelCoordVar*)para->GetVarList()->FindObject( vars[ivar] );
            minrange = tree->GetMinimum( var->GetName() );
            maxrange = tree->GetMaximum( var->GetName() );
            width    = 0.2*(maxrange - minrange);

            switch (ivar) {
            case 0: { x1 = minrange; x2 = x1 + width; break; }
            case 1: { x1 = 0.5*(maxrange + minrange - width)*0.02; x2 = x1 + width*0.02; break; }
            case 2: { x1 = maxrange - width; x2 = x1 + width; break; }
            }

            parrange = new TParallelCoordRange( var, x1, x2 );
            parrange->SetLineColor( ivar == 0 ? 2 : ivar == 1 ? 5 : 6 );
            var->AddRange( parrange );

            para->AddSelection( Form("%i",ivar) );
         }

         c1->Update();

         TString fname = Form( "plots/paracoor_c%i_%s", imva, itype == 0 ? "S" : "B" );
         TMVAGlob::imgconv( c1, fname );
      }
//.........这里部分代码省略.........
开发者ID:CMSAachen3B,项目名称:RWTH3b,代码行数:101,代码来源:paracoor.C

示例3: Example_tags

void Example_tags(TString topDir = "/star/rcf/GC/daq/tags")
{
//////////////////////////////////////////////////////////////////////////
//                                                                      //
// Example_tags.C                                                       //
//                                                                      //
// shows how to use the STAR tags files                                 //
// Input: top level directory                                           //
//                                                                      //
// what it does:                                                        //
// 1. creates TChain from all tags files down from the topDir           //
// 2. loops over all events in the chain                                //
//                                                                      //
// owner: Alexandre V. Vaniachine <[email protected]>                //
//////////////////////////////////////////////////////////////////////////

  gSystem->Load("libTable");
  gSystem->Load("St_base");
  // start benchmarks
  gBenchmark = new TBenchmark();
  gBenchmark->Start("total");
   
  // set loop optimization level
  gROOT->ProcessLine(".O4");
  // gather all files from the same top directory into one chain
  // topDir must end with "/"
  topDir +='/';
  St_FileSet dirs(topDir);
  St_DataSetIter next(&dirs,0);
  St_DataSet *set = 0; 
  TChain chain("Tag");
  while ( (set = next()) ) {           
    if (strcmp(set->GetTitle(),"file") || 
	!(strstr(set->GetName(),".tags.root"))) continue;
    chain.Add(gSystem->ConcatFileName(topDir,set->Path()));
  }
  UInt_t nEvents = chain->GetEntries();
  cout<<"chained "<<nEvents<<" events "<<endl;

  TObjArray *files = chain.GetListOfFiles();
  UInt_t nFiles = files->GetEntriesFast();
  cout << "chained " << nFiles << " files from " << topDir << endl;

  TObjArray *leaves = chain.GetListOfLeaves();
  Int_t nleaves = leaves->GetEntriesFast();

  TString tableName = " ";
  TObjArray *tagTable = new TObjArray;

  Int_t tableCount = 0;
  Int_t *tableIndex = new Int_t[nleaves];
  Int_t tagCount = 0;

  // decode tag table names
  for (Int_t l=0;l<nleaves;l++) {
    TLeaf *leaf = (TLeaf*)leaves->UncheckedAt(l);
    tagCount+=leaf->GetNdata();
    TBranch *branch = leaf->GetBranch();
    // new tag table name
    if ( strstr(branch->GetName(), tableName.Data()) == 0 ) {
      tableName = branch->GetName();
      // the tableName is encoded in the branch Name before the "."
      tableName.Resize(tableName->Last('.'));
      tagTable->AddLast(new TObjString(tableName.Data()));
      tableCount++;
    }
    tableIndex[l]=tableCount-1;
  }
  cout << " tot num tables, tags = " << tableCount << "   " 
       << tagCount << endl << endl;

  //EXAMPLE 1: how to print out names of all tags and values for first event
  for (l=0;l<nleaves;l++) {
    leaf = (TLeaf*)leaves->UncheckedAt(l);
    branch = leaf->GetBranch();
    branch->GetEntry();
    // tag comment is in the title
    TString Title = leaf->GetTitle();
    Int_t dim = leaf->GetNdata();
    if (dim==1) {
      Title.ReplaceAll('['," '"); 
      Title.ReplaceAll(']',"'"); 
    }
    cout << "\n Table: ";
    cout.width(10);
    cout << ((TObjString*)tagTable->UncheckedAt(tableIndex[l]))->GetString()
	 <<" -- has tag: " << Title << endl;
    for (Int_t i=0;i<dim;i++) {
      cout <<"                               "<< leaf->GetName();
      if (dim>1) cout << '['<<i<<']';
      cout << " = " << leaf->GetValue(i) << endl; 
    }
  }

  // EXAMPLE 2: how to make a plot
  c1 = new TCanvas("c1","Beam-Gas Rejection",600,1000);
  gStyle->SetMarkerStyle(8);
  chain->Draw("n_trk_tpc[0]:n_trk_tpc[1]");

  // EXAMPLE 3: how to make a selection (write selected event numbers on the plot)
//.........这里部分代码省略.........
开发者ID:star-bnl,项目名称:star-macros,代码行数:101,代码来源:Example_tags.C

示例4: MPDummyForLowStat

void MPDummyForLowStat(const char* stfile, int thr=30, int nGen=40,Bool_t bin=kTRUE)
{
  // show degrees of freedom with low stat
  TFile* fl = TFile::Open(stfile);
  if (!fl) {printf("Failed to open %s\n",stfile); return;}
  TList* lst = (TList*)fl->Get("clist");
  if (!lst) {printf("No clist in %s\n",stfile); return;}
  TH1* hstdof = (TH1*)lst->FindObject("DOFstat");
  if (!hstdof) {printf("No DOFstat histo in %s\n",stfile); return;}
  //
  int ndof = hstdof->GetNbinsX();
  TAxis* xax = hstdof->GetXaxis();
  printf("%4s\t%-50s\t%s","cnt"," DOF ID_name","entries");
  Mille* ml = 0;
  AliAlgSteer* algSteer=0;
  AliAlgMPRecord* mpRec=0;
  //
  if (bin) ml = new Mille(Form("%s.%s",mpDummy.Data(),"mille"));
  else {
    algSteer = new AliAlgSteer();
    algSteer->SetMPDatFileName(mpDummy.Data());
    algSteer->SetMPOutType(AliAlgSteer::kMPRec);
    algSteer->InitMPRecOutput();
    mpRec = algSteer->GetMPRecord();
  }
  //
  int   labDum[1] = {0}, cnt=0;
  float locDum[1] = {0}, gloDum[1] = {kDummyDer};
  //
  for (int i=1;i<=ndof;i++) {
    if (hstdof->GetBinContent(i)>thr) continue;
    TString labS = xax->GetBinLabel(i);
    printf("%4d\t%-50s\t%7d\n",cnt++,labS.Data(),(int)hstdof->GetBinContent(i));
    int indL = labS.Index("_");
    if (indL>0) labS.Resize(indL);
    else {
      printf("Failed to extract label from %s\n",labS.Data());
      exit(1);
    }
    labDum[0] = labS.Atoi();
    if (bin) {
      for (int j=nGen;j--;) {
	ml->mille(0, locDum, 1, gloDum, labDum, kDummyRes, kDummyErr);
	ml->end();
      }
    }
    else {
      mpRec->DummyRecord(kDummyRes,kDummyErr,kDummyDer,labDum[0]);
      for (int j=nGen;j--;) algSteer->GetMPRecTree()->Fill();
    }
  }
  //
  if (bin) delete ml;
  else {
    algSteer->CloseMPRecOutput();
    delete algSteer;
  }
  //
  lst->SetOwner();
  delete lst;
  fl->Close();
  delete fl;
}
开发者ID:ktf,项目名称:AliPhysics,代码行数:63,代码来源:MPDummyForLowStat.C

示例5: macroComparison

void macroComparison(string sfileA,string sfileB,string sfileC, string fname){

  TFile * fileA = new TFile(TString(sfileA), "READ");
  TFile * fileB = new TFile(TString(sfileB), "READ");
  TFile * fileC = new TFile(TString(sfileC), "READ");

  // get canvas name
  TList *listA = fileA->GetListOfKeys();  
  TString canvasnameA = listA->At(0)->GetName();
 
  TList *listB = fileB->GetListOfKeys();  
  TString canvasnameB = listB->At(0)->GetName();

  TList *listC = fileC->GetListOfKeys();  
  TString canvasnameC = listC->At(0)->GetName();

  // make histogram name out of canvas name
  TString histonameA = canvasnameA;
  Ssiz_t objIndexA = histonameA.Index("canvas");
  histonameA.Resize(objIndexA);
  histonameA+= "_data_hist";

  TString histonameB = canvasnameB;
  Ssiz_t objIndexB = histonameB.Index("canvas");
  histonameB.Resize(objIndexB);
  histonameB+= "_data_hist";

  TString histonameC = canvasnameC;
  Ssiz_t objIndexC = histonameC.Index("canvas");
  histonameC.Resize(objIndexC);
  histonameC+= "_data_hist";

  // get canvas from files
  // get histograms from canvases
  
  TCanvas *cvA = (TCanvas*) fileA->Get(canvasnameA);
  TH1D * histoA = (TH1D*) cvA->FindObject(histonameA)->Clone();
  // set name to different value
  cvA->SetName("dummy");
  
  TCanvas *cvB = (TCanvas*) fileB->Get(canvasnameB);
  TH1D * histoB = (TH1D*) cvB->FindObject(histonameB)->Clone();
  cvB->SetName("dummy2");

  TCanvas *cvC = (TCanvas*) fileC->Get(canvasnameC);
  TH1D * histoC = (TH1D*) cvC->FindObject(histonameC)->Clone();


  // ratio plots
  TH1D * histoAoverBRatio =  (TH1D*) histoA->Clone();
  TH1D * histoAoverCRatio =  (TH1D*) histoA->Clone();
  TH1D * histoBoverCRatio =  (TH1D*) histoB->Clone();

  histoAoverBRatio->Divide(histoB);
  histoAoverCRatio->Divide(histoC);
  histoBoverCRatio->Divide(histoC);

  // make new Canvas for plotting
  TCanvas *cv1 = new TCanvas(histonameA, histonameA, 1024,1024);
  cv1->cd();
  cv1->Clear();
  cv1->Divide(1,2,0.01,0.0);
  

  cv1->cd(1);
  cv1->SetFillColor(0); 
  gStyle->SetOptTitle(0);
  gPad->SetFillColor(0);
  gPad->SetPad( 0.0, 0.25, 1.0, 1.0 );
  gPad->SetTopMargin(0.1);
  gPad->SetLeftMargin(0.16);
  gPad->SetRightMargin(0.04);

  cv1->cd(2);
  cv1->SetFillColor(0);
  gStyle->SetOptTitle(0);
  gPad->SetFillColor(0);
  gPad->SetPad( 0.0, 0.0,  1.0, 0.25 );
  gPad->SetBottomMargin(0.375);
  gPad->SetLeftMargin(0.16);
  gPad->SetRightMargin(0.04);
  gPad->SetGridy();

  cv1->cd(1);

  histoA->SetMarkerStyle(20);
  histoA->SetMarkerSize(2);
  histoA->SetMarkerColor(1);
  histoA->Draw("E1X0");
  //  histoA->DrawNormalized("E1X0");

  histoB->SetMarkerStyle(21);
  histoB->SetMarkerSize(2);
  histoB->SetMarkerColor(2);
  histoB->Draw("E1X0SAME");
  //  histoB->DrawNormalized("E1X0SAME");

  histoC->SetMarkerStyle(22);
  histoC->SetMarkerSize(2);
  histoC->SetMarkerColor(3);
//.........这里部分代码省略.........
开发者ID:JyothsnaKomaragiri,项目名称:bTag,代码行数:101,代码来源:macroComparison.C

示例6: plotTGraphs

TCanvas* plotTGraphs(std::vector<TGraph*> theGraphs, bool autoFormat, TString titleString, bool logX, bool logY)
{
	gROOT->cd();

	TCanvas* theCanvas = new TCanvas(titleString, titleString, 1600, 1200);
	theCanvas->cd();
	theCanvas->SetLeftMargin(.13);
	theCanvas->SetRightMargin(.06);
	theCanvas->SetGrid(1, 1);
	gPad->SetTickx(1);
	gPad->SetTicky(1);
	gPad->SetLogx(logX);
	gPad->SetLogy(logY);

	//Create frame based on the min and max from all the histograms;
	double minX = minFromTGraphs(theGraphs, true, true);
	double minY = minFromTGraphs(theGraphs, true, false);
	double maxX = maxFromTGraphs(theGraphs, true, true);
	double maxY = maxFromTGraphs(theGraphs, true, false);
	double lengthX = maxX - minX;
	double lengthY = maxY - minY;
	double widen = 0.05;
	if(!logX)
	{
		minX -= widen * lengthX;
		maxX += widen * lengthX;
	}
	else
	{
		minX *= widen;
		maxX /= widen;
	}

	if(!logY)
	{
		minY -= widen * lengthY;
		maxY += widen * lengthY;
	}
	else
	{
		minY *= widen;
		maxY /= widen;
	}
	TH1F* theFrameHist = theCanvas->DrawFrame(minX, minY, maxX, maxY);
	theFrameHist->SetTitleOffset(1.5, "y");
	theFrameHist->SetTitleOffset(1.3, "X");
	theFrameHist->SetTitle(titleString);

	//If it doesn't have a title string use the first histogram
	if(TString(theFrameHist->GetXaxis()->GetTitle()) == "")
	{
		theFrameHist->SetXTitle(theGraphs[0]->GetXaxis()->GetTitle());
		theFrameHist->SetYTitle(theGraphs[0]->GetYaxis()->GetTitle());
	}

	theCanvas->Update();
	theCanvas->Modified();

	TLegend* theLegend = nullptr;

	if(theGraphs.size() > 1)
	{
		double legendSize = .05 * theGraphs.size();
		if(legendSize < .15) legendSize = .15;

//		theLegend = new TLegend(0.55, .8 - legendSize, 0.87, 0.8);  //Top Right
//		theLegend = new TLegend(0.2, .8 - legendSize, 0.47, 0.8);  //Top Left
		theLegend = new TLegend(0.55, .4 - legendSize, 0.87, 0.4); //Bottom Right
	}

	for (unsigned int i = 0; i < theGraphs.size(); i++)
	{
		if(autoFormat)
		{
			theGraphs[i]->SetLineColor(MR_GRAPH_COLOR_LIST[i % MR_GRAPH_NUMCOLORS]);
			theGraphs[i]->SetMarkerColor(MR_GRAPH_COLOR_LIST[i % MR_GRAPH_NUMCOLORS]);
			theGraphs[i]->SetMarkerStyle(MR_MARKER_STYLE_LIST[i % MR_MARKER_NUMSTYLES]);
		}
		theGraphs[i]->Draw("P E1 same");
		if(theLegend != nullptr)
		{
			TString legendString = theGraphs[i]->GetTitle();
			legendString.Resize(legendString.First(';'));
			theLegend->AddEntry(theGraphs[i], legendString, "P E1");
		}
	}

	if(theLegend != nullptr) theLegend->Draw("same");

	return theCanvas;
}
开发者ID:mjbales,项目名称:mattroot,代码行数:91,代码来源:MRGraphics.cpp

示例7: AddTask_GammaCaloDalitzV1_pPb


//.........这里部分代码省略.........
  if (doWeightingPart==1) {
    TObjString *Header1 = new TObjString("pi0_1");
    HeaderList->Add(Header1);
  }
  if (doWeightingPart==2){
    TObjString *Header3 = new TObjString("eta_2");
    HeaderList->Add(Header3);
  }
  if (doWeightingPart==3) {
    TObjString *Header1 = new TObjString("pi0_1");
    HeaderList->Add(Header1);
    TObjString *Header3 = new TObjString("eta_2");
    HeaderList->Add(Header3);
  }

  EventCutList->SetOwner(kTRUE);
  AliConvEventCuts **analysisEventCuts = new AliConvEventCuts*[numberOfCuts];

  ConvCutList->SetOwner(kTRUE);
  AliConversionPhotonCuts **analysisCuts = new AliConversionPhotonCuts*[numberOfCuts];

  ClusterCutList->SetOwner(kTRUE);
  AliCaloPhotonCuts **analysisClusterCuts = new AliCaloPhotonCuts*[numberOfCuts];

  ElectronCutList->SetOwner(kTRUE);
  AliDalitzElectronCuts   **analysisElectronCuts = new AliDalitzElectronCuts*[numberOfCuts];

  MesonCutList->SetOwner(kTRUE);
  AliConversionMesonCuts **analysisMesonCuts = new AliConversionMesonCuts*[numberOfCuts];

  for(Int_t i = 0; i<numberOfCuts; i++){
    //create AliCaloTrackMatcher instance, if there is none present
    TString caloCutPos = clusterCutArray[i];
    caloCutPos.Resize(1);
    TString TrackMatcherName = Form("CaloTrackMatcher_%s",caloCutPos.Data());
    if( !(AliCaloTrackMatcher*)mgr->GetTask(TrackMatcherName.Data()) ){
      AliCaloTrackMatcher* fTrackMatcher = new AliCaloTrackMatcher(TrackMatcherName.Data(),caloCutPos.Atoi());
      fTrackMatcher->SetV0ReaderName(V0ReaderName);
      mgr->AddTask(fTrackMatcher);
      mgr->ConnectInput(fTrackMatcher,0,cinput);
    }

    analysisEventCuts[i] = new AliConvEventCuts();
    analysisEventCuts[i]->SetV0ReaderName(V0ReaderName);
    analysisEventCuts[i]->InitializeCutsFromCutString(eventCutArray[i].Data());
    EventCutList->Add(analysisEventCuts[i]);
    analysisEventCuts[i]->SetFillCutHistograms("",kFALSE);

    analysisCuts[i] = new AliConversionPhotonCuts();
    analysisCuts[i]->SetV0ReaderName(V0ReaderName);
    analysisCuts[i]->InitializeCutsFromCutString(photonCutArray[i].Data());
    analysisCuts[i]->SetIsHeavyIon(isHeavyIon);
    ConvCutList->Add(analysisCuts[i]);
    analysisCuts[i]->SetFillCutHistograms("",kFALSE);

    analysisClusterCuts[i] = new AliCaloPhotonCuts();
    analysisClusterCuts[i]->SetV0ReaderName(V0ReaderName);
    analysisClusterCuts[i]->SetCaloTrackMatcherName(TrackMatcherName);
    analysisClusterCuts[i]->InitializeCutsFromCutString(clusterCutArray[i].Data());
    ClusterCutList->Add(analysisClusterCuts[i]);
    analysisClusterCuts[i]->SetExtendedMatching(enableExtendedMatching);
    analysisClusterCuts[i]->SetFillCutHistograms("");

    analysisElectronCuts[i] = new AliDalitzElectronCuts();
    if( !analysisElectronCuts[i]->InitializeCutsFromCutString(electronCutArray[i].Data())) {
      cout<< "ERROR:  analysisElectronCuts [ " <<i<<" ] "<<endl;
开发者ID:ktf,项目名称:AliPhysics,代码行数:67,代码来源:AddTask_GammaCaloDalitzV1_pPb.C

示例8: DrawMLPoutputMovie


//.........这里部分代码省略.........
      countCanvas++;
      TString ctitle = Form("TMVA response %s",methodTitle.Data());
      c = new TCanvas( Form("canvas%d", countCanvas), ctitle, 0, 0, width, (Int_t)width*0.78 ); 
      
      TH1F* sig = (TH1F*)titkeyTit->ReadObj();
      sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) );
      
      TString dataType = (name.Contains("_train_") ? "(training sample)" : "(test sample)");
      
      // find background
      TString nbn = sig->GetName(); nbn[nbn.Length()-1] = 'B';            
      TH1F* bgd = dynamic_cast<TH1F*>(epochDir->Get( nbn ));
      if (bgd == 0) {
         cout << "Big troubles with histogram: " << bgd << " -> cannot find!" << endl;
         exit(1);
      }
      
      cout << "sig = " << sig->GetName() << endl;
      cout << "bgd = " << bgd->GetName() << endl;
      
      // set the histogram style
      TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
      
      // normalise both signal and background
      TMVAGlob::NormalizeHists( sig, bgd );
      
      // set only first time, then same for all plots
      if (first) {
         if (xmin == 0 && xmax == 0) {
            xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), 
                                          bgd->GetMean() - nrms*bgd->GetRMS() ),
                               sig->GetXaxis()->GetXmin() );
            xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), 
                                          bgd->GetMean() + nrms*bgd->GetRMS() ),
                               sig->GetXaxis()->GetXmax() );
         }
         ymin = 0;
         ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult;
         first = kFALSE;
      }
      
      // build a frame
      Int_t nb = 100;
      TString hFrameName(TString("frame") + methodTitle);
      TObject *o = gROOT->FindObject(hFrameName);
      if(o) delete o;
      TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), 
                              nb, xmin, xmax, nb, ymin, ymax );
      frame->GetXaxis()->SetTitle( methodTitle + " response" );
      frame->GetYaxis()->SetTitle("(1/N) dN^{ }/^{ }dx");
      TMVAGlob::SetFrameStyle( frame );
      
      // find epoch number (4th token)
      TObjArray* tokens = name.Tokenize("_");
      TString es = ((TObjString*)tokens->At(4))->GetString();
      if (!es.IsFloat()) {
         cout << "Big troubles in epoch parsing: \"" << es << "\" is not float" << endl;
         exit(1);
      }
      Int_t epoch = es.Atoi();
      
      // eventually: draw the frame
      frame->Draw();  
      
      c->GetPad(0)->SetLeftMargin( 0.105 );
      frame->GetYaxis()->SetTitleOffset( 1.2 );
      
      // Draw legend               
      TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, 
                                    c->GetLeftMargin() + 0.5, 1 - c->GetTopMargin() );
      legend->SetFillStyle( 1 );
      legend->AddEntry(sig,TString("Signal ")     + dataType, "F");
      legend->AddEntry(bgd,TString("Background ") + dataType, "F");
      legend->SetBorderSize(1);
      legend->SetMargin( 0.15 );
      legend->Draw("same");
      
      TText* t = new TText();            
      t->SetTextSize( 0.04 );
      t->SetTextColor( 1 );
      t->SetTextAlign( 31 );
      t->DrawTextNDC( 1 - c->GetRightMargin(), 1 - c->GetTopMargin() + 0.015, Form( "Epoch: %i", epoch) );
      
      // overlay signal and background histograms
      sig->Draw("samehist");
      bgd->Draw("samehist");
      
      // save to file
      TString dirname  = "movieplots";
      TString foutname = dirname + "/" + name;
      foutname.Resize( foutname.Length()-2 );
      foutname.ReplaceAll("convergencetest___","");
      foutname += ".gif";
      
      cout << "storing file: " << foutname << endl;
      
      c->Update();
      c->Print(foutname);            
   }
}
开发者ID:CMSAachen3B,项目名称:RWTH3b,代码行数:101,代码来源:MovieMaker.C

示例9: bfcread_tagsBranch

void bfcread_tagsBranch( 
  const char *MainFile="/afs/rhic.bnl.gov/star/data/samples/gstar.tags.root",
  Int_t printEvent=1,
  const char *fname="qa_tags.out",
  Int_t fullPrint=0) 
{
  // start timer
  TStopwatch timer;
  timer.Start();

  cout << endl << endl;
  cout << " bfcread_tagsBranch.C: input file  = " << MainFile << endl;
  cout << " bfcread_tagsBranch.C: print event # " << printEvent << endl;
  cout << " bfcread_tagsBranch.C: output file = " << fname << endl;
  cout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
  cout << endl;

  ofstream fout(fname);

  fout << endl << endl;
  fout << " bfcread_tagsBranch.C: input file  = " << MainFile << endl;
  fout << " bfcread_tagsBranch.C: print evt#  = " << printEvent << endl;
  fout << " bfcread_tagsBranch.C: output file = " << fname << endl;
  fout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
  fout << endl;

  TFile *file = TFile::Open(MainFile);
  TTree *tree = (TTree*)file->Get("Tag");

  cout <<" read file: " << file->GetName() << endl << endl;

  Int_t nEntries = tree->GetEntries();
  cout << " Total # events  = " << nEntries << endl;

  TObjArray *leaves = tree->GetListOfLeaves();
  Int_t nLeaves = leaves->GetEntriesFast();

  cout << "  Total # leaves  = " << nLeaves << endl;

  TString *tName = new TString(" ");
  TNamed *tableName=0;
  TObjArray *tagTable = new TObjArray;
  Int_t tableCount = 0;
  Int_t *tableIndex = new Int_t[nLeaves];
  Int_t tagCount = 0;

  TBranch *branch=0;
  TLeaf *leaf=0;
  Int_t ndim =0;

//count number of tag tables encoded in the TTree branch names
  for (Int_t l=0;l<nLeaves;l++) {
    leaf = (TLeaf*)leaves->UncheckedAt(l);
    tagCount+=leaf->GetNdata();
    branch = leaf->GetBranch();
      cout << "leaf #  " << l << "  br name = " <<  
                                     branch->GetName() << endl;
    //new tag table name
    if ( strstr(branch->GetName(), tName->Data()) == 0 ) {
      tName = new TString(branch->GetName());
      tName->Resize(tName->Index("."));
      //the tableName is encoded in the branch Name before the "."
      tableName = new TNamed(tName->Data(),"Tag");
      tagTable->AddLast(tableName);
      tableCount++;
    }
    tableIndex[l]=tableCount-1;
  }

  cout << endl << "  Total num tables(branches),tags = " 
              << tableCount << "   " << tagCount << endl << endl;

  Int_t *countTagsTable = new Int_t[tableCount];
  Int_t *countLeavesTable = new Int_t[tableCount];
  Float_t *sumTagsLeaf = new Float_t[nLeaves];
  Int_t *countTagsLeaf = new Int_t[nLeaves];

// Now loop over leaves (to get values of tags)

   Int_t setBranch = -1;
   Int_t nowBranch = -1;

   for (Int_t l=0;l<nLeaves;l++) {

      leaf = (TLeaf*)leaves->UncheckedAt(l);
      branch = leaf->GetBranch();
      ndim = leaf->GetNdata();

      nowBranch = tableIndex[l];

      //cout << " nowbranch, setBranch = " << 
      //  nowBranch << ", "<< setBranch << endl;

      Float_t RtableIndex=tableIndex[l];

      if (nowBranch !=  setBranch){ 
          setBranch=nowBranch;
          cout << " QAInfo: branch ";
            cout.width(2);
            cout << tableIndex[l] << " = ";
//.........这里部分代码省略.........
开发者ID:star-bnl,项目名称:star-macros,代码行数:101,代码来源:bfcread_tagsBranch.C


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