• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TLeaf类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1:

// This piece of code is borrowed from Argo written by Nathaniel Tagg
std::vector<std::string> DataFetcher::FindLeavesOfType(std::string pattern) {
  /// Look in the tree and try to find a leaf element that matches 'pattern'.
  /// Return the full name of that leaf.
  std::vector<std::string> leaf_names;

  // Strip whitespace from pattern.
  pattern.erase(std::remove_if(pattern.begin(), pattern.end(), ::isspace),
      pattern.end());

  TObjArray * list = tree_->GetListOfLeaves();
  for (int i = 0; i < list->GetEntriesFast(); ++i) {
    TObject * o = list->At(i);
    TLeaf * leaf = (TLeaf *) o;
    std::string name = leaf->GetTypeName();
    // Strip whitespace from pattern.
    name.erase(std::remove_if(name.begin(), name.end(), ::isspace),
        name.end());
    size_t found = name.find(pattern);
    if (found != std::string::npos) {
      // Return this match.
      leaf_names.push_back(leaf->GetName());
    }
  }
  return leaf_names;
}
开发者ID:lar1nd,项目名称:lar1evd,代码行数:26,代码来源:DataFetcher.cpp


示例2: dump_required_lvl2

void dump_required_lvl2(TTree *tree, TLeaf &leaf, CodedOutputStream &o, CodedOutputStream &o2) {
    const int DL = 1; // definition level multiplier
    const int RL = 4; // repetition level multiplier

    std::cout << "Dump vector vector: " << leaf.GetName() << " " << leaf.GetTypeName() << std::endl;
    auto * branch = leaf.GetBranch();

    std::vector<std::vector<T> > * data = NULL;
    tree->SetBranchAddress(leaf.GetBranch()->GetName(), &data);
    int entries = tree->GetEntries();
    for (int i = 0; i < entries; i++) { 
        branch->GetEntry(i);
        if (data->size() == 0) {
            write_out_32(o2, DL*0 + RL*0);
        }
        for (int j = 0; j < data->size(); j++) {
            if (data->at(j).size() == 0) {
                int dl = 1;
                int rl = (j > 0 ? 1 : 0);
                write_out_32(o2, dl*DL + rl*RL);
            }
            for (int k = 0; k < data->at(j).size(); k++) {
                int dl = 2;
                int rl = (k > 0 ? 2 : (j > 0 ? 1 : 0));
                write_out_32(o2, dl*DL + rl*RL);
                write_out_type(o, data->at(j).at(k));
            }
        }
    }
}
开发者ID:pwaller,项目名称:drillbit,代码行数:30,代码来源:root2stripes.cpp


示例3: fixLeafOffsets

void Output::fixLeafOffsets( TBranch * b)
{
  // recalculates the addresses for all the leaves.
  // 
  // when constructing a branch with containing a variable length array with the index
  // variable in the same branch it is not possible to specify the span of the index variable
  // This span defaults to zero. When the addresses are asigned to the various leaves in the branch
  // it calculates the size of the particular leaf (variable length array) in the buffer by looking 
  // at the span of the index variable - 0 in this case! using the method TLeaf::GetLen(). 
  // The following code shoudl be applied to the branch after the spans of the index variables have been
  // specified manually using the TLeaf::SetMaximum method. This time the GetLen method calculates the correct offset.

  TObjArray * leaves = b->GetListOfLeaves();
  char * addr = b->GetAddress();
  int offset = 0;
  int nleaves = leaves->GetEntriesFast();
  
  // loop over the leaves:
  for( int i =0; i < nleaves; ++i) {
    TLeaf * leaf = (TLeaf *)leaves->UncheckedAt(i);
    leaf->SetAddress( addr + offset );
    int oldOffset = leaf->GetOffset();
    leaf->SetOffset( offset );
    //std::cout << " offset changed from : " << oldOffset << " to " << offset << std::endl;
    TLeaf * index = leaf->GetLeafCount();
    int nelements = 1;
    if( index ) {
      nelements = index->GetMaximum(); // deal with variable length arrays
    } else {
      nelements = leaf->GetLenStatic(); // deal with single variables and fixed length arrays
    }
    offset += leaf->GetLenType() * nelements;
  }
}
开发者ID:rafaellopesdesa,项目名称:wmass_pythia_interface,代码行数:34,代码来源:Output.cpp


示例4: dump_required_lvl0

void dump_required_lvl0(TTree *tree, TLeaf &leaf, CodedOutputStream &o) {
    std::cout << "Dump " << leaf.GetName() << std::endl;
    auto *branch = leaf.GetBranch();

    T data; 
    tree->SetBranchAddress(leaf.GetBranch()->GetName(), &data);
    int entries = tree->GetEntries();
    for (int i = 0; i < entries; i++) { 
        branch->GetEntry(i);
        write_out_type(o, data);
    }
}
开发者ID:pwaller,项目名称:drillbit,代码行数:12,代码来源:root2stripes.cpp


示例5: SetBranchAddressToHolder

void GAInputTreeData::SetBranchAddressToHolder(string branch_name){
    if(!fTTree->GetBranch(branch_name.c_str())){
        cout << "[GAInputTreeData-E]: branch " << branch_name << 
                " is not found";
        throw 1;
    }
    fBranchName.push_back(branch_name);
    TLeaf *leaf = fTTree->GetBranch(branch_name.c_str())
        ->GetLeaf(branch_name.c_str());
    Int_t n_data = leaf->GetNdata();
    string type_name = leaf->GetTypeName();
    fEventDataHolderManager->AddDetector(type_name,branch_name, n_data);
}
开发者ID:YJabberwocKy,项目名称:testganaroot,代码行数:13,代码来源:GAInputTreeData.cpp


示例6: addTree

void NCIdeogram::addTree(TTree *tree, const char *mu, const char *sigma)
{
	TLeaf *leafMu = tree->FindLeaf(mu);
	TLeaf *leafSigma = tree->FindLeaf(sigma);
	TEventList *elist = tree->GetEventList();
	Long64_t j,ix,nbr;
	
	nbr = elist ? elist->GetN() : tree->GetEntries();
	for (j = 0; j < nbr; j++) {
		ix = elist ? elist->GetEntry(j) : j;
		tree->GetEntry(ix);
		addPoint(leafMu->GetValue(), leafSigma->GetValue());
	}
} // addTree()
开发者ID:cms-analysis,项目名称:HeavyFlavorAnalysis-Bs2MuMu,代码行数:14,代码来源:NCIdeogram.cpp


示例7: TState

CThreadSlm::TState
CThreadSlm::history_state_of(TState st)
{
    if (st.getLevel() >= m_N) {
        TLeaf* pl = ((TLeaf *)m_Levels[m_N]) + st.getIdx();
        return TState(pl->bol(), pl->bon());
    } else {
        TNode* pn = ((TNode *)m_Levels[st.getLevel()]) + st.getIdx();
        if (pn->ch() == (pn+1)->ch())
            return TState(pn->bol(), pn->bon());
        else
            return st;
    }
}
开发者ID:XueWei,项目名称:sunpinyin,代码行数:14,代码来源:slm.cpp


示例8: CacheTestMCProductions

/// \brief Cache  MC production trees, store summary information in formated text files -> root trees
/// \param dataType  -
/// \param fileList
void CacheTestMCProductions(TString dataType, const char *fileList=NULL){
  AliExternalInfo info;
  info.fLoadMetadata=kFALSE;
  TObjArray* periodList = NULL;
  TArrayI nRuns;
  if (fileList!=NULL) {
    periodList=(gSystem->GetFromPipe(TString::Format("cat %s", fileList).Data())).Tokenize("\n");
    nRuns.Set(periodList->GetEntries());

  }else{
    TTree * tree = info.GetTree("MonALISA.ProductionMC","","");
    Int_t nProd=tree->GetEntries();
    periodList = new TObjArray(nProd);
    nRuns.Set(nProd);
    TLeaf *leaf = tree->GetLeaf("Tag");
    TLeaf *leafRuns = tree->GetLeaf("Number_of_runs");
    for (Int_t iProd=0; iProd<nProd; iProd++){
      tree->GetEntry(iProd);
      TString prodName=((char*)leaf->GetValuePointer());
      if (prodName.Contains("LHC")==0) continue;
      periodList->AddAt(new TObjString(((char*)leaf->GetValuePointer())),iProd);
      nRuns[iProd]=leafRuns->GetValue();
    }
    delete tree;
  }
  for (Int_t iPeriod=0; iPeriod<periodList->GetEntriesFast(); iPeriod++){
    TObjString * pName= (TObjString*)periodList->At(iPeriod);
    if (pName==NULL) continue;
    TTree* tree = info.GetTree(dataType.Data(),periodList->At(iPeriod)->GetName(),"passMC");
    if (tree){
      Int_t entries=tree->Draw("run","1","goff");
      TString sInfo=periodList->At(iPeriod)->GetName();
      sInfo+="\t";
      sInfo+=dataType;
      sInfo+="\t";
      sInfo+=TString::Format("%d\t",entries);
      sInfo+=TString::Format("%d\t",nRuns[iPeriod]);
      for (Int_t j=0; j<entries; j++) {
        sInfo+=TString::Format("%2.0f,",tree->GetV1()[j]);
        ::Info("CacheTestMCProductionsRun:","%s\t%s\t%d\t%d\t%d\t%2.0f",periodList->At(iPeriod)->GetName(),dataType.Data(),entries,nRuns[iPeriod],j, tree->GetV1()[j]);
      }
      sInfo+="0";
      ::Info("CacheTestMCProductionsPeriod:","%s\n",sInfo.Data());
      delete tree;
    }else{
      ::Error("CacheTestMCProductionsPeriod:","%s\t%s\t-1\t%d\t0",periodList->At(iPeriod)->GetName(), dataType.Data(),nRuns[iPeriod]);
    }
  }
}
开发者ID:alisw,项目名称:AliRoot,代码行数:52,代码来源:aliExternalInfo.C


示例9:

CThreadSlm::TState&
CThreadSlm::historify(TState& st)
{
    if (st.getLevel() >= m_N) {
        TLeaf* pl = ((TLeaf *)m_Levels[m_N]) + st.getIdx();
        st.setLevel(pl->bol());
        st.setIdx(pl->bon());
    } else {
        TNode* pn = ((TNode *)m_Levels[st.getLevel()]) + st.getIdx();
        if (pn->ch() == (pn+1)->ch()) {
            st.setLevel(pn->bol());
            st.setIdx(pn->bon());
        }
    }
    return st;
}
开发者ID:XueWei,项目名称:sunpinyin,代码行数:16,代码来源:slm.cpp


示例10: SetAllBranches

void GAInputTreeData::SetAllBranches(){
    TObjArray* ArrayOfBranches = fTTree->GetListOfBranches();
    Int_t n_branch = ArrayOfBranches->GetEntries();
    cout << "[GAInputTreeData-M]:Loading " << n_branch << " branches from "
        << fTTree->GetName() << endl;
    for(int i_branch=0; i_branch<n_branch; i_branch++){
        TBranch* Branch = (TBranch*)ArrayOfBranches->At(i_branch);
        string branch_name = Branch->GetName();
        TLeaf *leaf = (TLeaf*)Branch->GetListOfLeaves()->At(0);//(branch_name.c_str());
        Int_t n_data = leaf->GetNdata();
        string type_name = leaf->GetTypeName();
        fBranchName.push_back(branch_name);
        fEventDataHolderManager->AddDetector(type_name, branch_name, n_data);
        cout << "[GAInputTreeData-M]:Loading branch " << branch_name
            << " (" << type_name << "[" << n_data << "])" << endl;
    }
}
开发者ID:YJabberwocKy,项目名称:testganaroot,代码行数:17,代码来源:GAInputTreeData.cpp


示例11: Form

void DataInterface::getDataProfile(TH2F *hProfile, TH2F *hProjection, Int_t energy) {
   if (!existsEnergyFile(energy)) {
      cout << "There are no data files with energy " << energy << endl;
      return;
   }

   TString fn = Form("Data/ExperimentalData/DataFrame_%i_MeV.root", energy);
   TFile *f = new TFile(fn);
   TTree *tree = (TTree*) f->Get("tree");

   Int_t nentries = tree->GetEntries();
   printf("Found %d frames in the DataFrame.\n", nentries);

   TLeaf *lX = tree->GetLeaf("fDataFrame.fX");
   TLeaf *lY = tree->GetLeaf("fDataFrame.fY");
   TLeaf *lLayer = tree->GetLeaf("fDataFrame.fLayer");

   Float_t x, y, layer;

   for (Int_t i=0; i<nentries; i++) {
      tree->GetEntry(i);

      for (Int_t j=0; j<lY->GetLen(); j++) {
         x = lX->GetValue(j)  + nx/2;
         y = lY->GetValue(j)  + ny/2;
         layer = lLayer->GetValue(j);

         hProfile->Fill(y, layer);
         hProjection->Fill(x, y);
      }
   }
}
开发者ID:HelgeEgil,项目名称:focal,代码行数:32,代码来源:DataInterface.C


示例12: printf

void
CArpaSlm::load(const char* filename, const TLexicon& lexicon)
{
    printf("Loading ARPA slm..."); fflush(stdout);
    ifstream file(filename);
    char buf[1024];
    for (int i = 0; i <= N_GRAM; ++i) {
        unsigned lvl;
        int size;
        file.getline(buf, sizeof(buf));
        if (!file) {
            cerr << "Failed to read from" << filename << endl;
            exit(1);
        }
        sscanf(buf, "\\%d-gram\\%d%*[\n]", &lvl, &size);
        assert(lvl <= N_GRAM);
        if (lvl == 0) {
            TNode node0;
            node0.load_level0(file);
            m_levels[0].push_back(node0);
        } else if (lvl < m_N) {
            m_levels[lvl].reserve(size);
            for (int i = 0; i < size; ++i) {
                TNode node;
                node.load(file, lexicon);
                m_levels[lvl].push_back(node);
            }
        } else {
            // leaf nodes
            m_lastLevel.reserve(size);
            for (int i = 0; i < size; ++i) {
                TLeaf leaf;
                leaf.load(file, lexicon);
                m_lastLevel.push_back(leaf);
            }
        }
    }
}
开发者ID:WilliamRen,项目名称:sunpinyin,代码行数:38,代码来源:arpa_slm.cpp


示例13: main

int main() {
    // Get a map of the histograms of the Z Masses
    const std::string Tree_HighCut = "ZFinder/Combined Single Reco/Combined Single Reco";
    const std::string Tree_LowCut = "ZFinder/Combined Single Lowered Threshold Reco/Combined Single Lowered Threshold Reco";
    const std::string file_name = "/data/whybee0a/user/gude_2/Data/20150324_SingleElectron_2012ALL/hadded.root";
    // Open the file and load the tree
    TTree* treeH = GetTTree(file_name, Tree_HighCut);
    TBranch* event_infoH = treeH->GetBranch("event_info");
    TLeaf* EVNumbH = event_infoH->GetLeaf("event_number");
    // Pack into a hitogram
    std::set<int> eventnumber;
    std::set<int> eventnumberLow;
    for (int i = 0; i < treeH->GetEntries(); i++) {
        treeH->GetEntry(i);
        if (eventnumber.find(EVNumbH->GetValue()) == eventnumber.end()) {
            eventnumber.insert(EVNumbH->GetValue());
        } else {
            cout << "multiple events numbered :" << EVNumbH->GetValue()<<" in higher cuts" << endl;
        }

    }

    TTree* TreeLow = GetTTree(file_name, Tree_LowCut);
    TBranch* event_infoL = TreeLow->GetBranch("event_info");
    TLeaf* EVNumbLow = event_infoL->GetLeaf("event_number");
    for (int i = 0; i < TreeLow->GetEntries(); i++) {
        TreeLow->GetEntry(i);
        eventnumberLow.insert(EVNumbLow->GetValue());
        if (eventnumberLow.find(EVNumbLow->GetValue()) == eventnumber.end()) {
            eventnumberLow.insert(EVNumbLow->GetValue());
        } else {
cout << "multiple events numbered :" << EVNumbLow->GetValue()<<" in lowered cuts" << endl;
        }

    }

    return EXIT_SUCCESS;
}
开发者ID:Spudmeister,项目名称:tuningAna,代码行数:38,代码来源:EventDupFind.cpp


示例14:

map<TString, vector<TString> >GetCounterBranchListMap(TTree *t)
{
  map<TString, vector<TString> > m;
  TObjArray *l = t->GetListOfLeaves(); //sometimes leave can be named wrong - rely on branches
  int n = l->GetEntries();// cout<<t->GetName()<<" has "<<n<<" leaves"<<endl;
  for (int i=0;i<n;i++) {
    TLeaf * leaf = (TLeaf *)(*l)[i];
    TLeaf *lc = leaf->GetLeafCount();
    
    if (lc!=0) {
      m[lc->GetBranch()->GetName()].push_back(leaf->GetBranch()->GetName()); //get leaf's branch name
      if (VERBOSE) cout<<lc->GetBranch()->GetName()<<" _ "<<leaf->GetBranch()->GetName()<<endl;
    }
  }

  return m;
}
开发者ID:istaslis,项目名称:pPbmacro,代码行数:17,代码来源:HelperProcess.C


示例15: getlist

void getlist(ostream& out, TBranch* branch, int depth=0)
{
  TObjArray* array = branch->GetListOfBranches();
  if ( ! array ) return;
  if ( depth > 10 ) return;

  string name;
  int nitems = array->GetEntries();

  for (int i = 0; i < nitems; i++)
	{
	  TBranch* b = (TBranch*)((*array)[i]);
      if ( ! b ) continue;

      string branchname(b->GetName());
      out << SPACE.substr(0,4*depth) << branchname << endl;
 
      TObjArray* a = b->GetListOfLeaves();
      if ( a )
        {
          int n = a->GetEntries();
          {
              for (int j = 0; j < n; j++)
                {
                  TLeaf* leaf = (TLeaf*)((*a)[j]);
                  int count = 0;
                  int ndata = 0;
                  TLeaf* leafc = leaf->GetLeafCounter(count);
                  if ( ! leafc)
                    ndata = leaf->GetLen();
                  else
                    ndata = leafc->GetMaximum();

                  string leafname(leaf->GetName());
                  out << SPACE.substr(0,4*(depth+1)) 
                      << ndata << " " << leafname << endl;
                }
          }
//           else if ( n == 1 )
//             {
//               TBranch* bc = (TBranch*)((*a)[j]);
//               string leafname(bc->GetName());
//               if ( leafname != branchname )
//               out << SPACE.substr(0,4*(depth+1)) << leafname << endl;
//             }
        }
      getlist(out, b, depth+1);
    }
}
开发者ID:hbprosper,项目名称:SusySapien,代码行数:49,代码来源:getlist.cpp


示例16: analysis

int analysis(char* filename)
{
    // char* filename = "combined.root";
    // Read in the file
    TFile* f = new TFile(filename);
    TDirectory* hists  = f->GetDirectory("hists;1");
    TDirectory* tuples = f->GetDirectory("tuples;1");

    TTree* accum = tuples->GetObjectUnchecked("AccumulatedEnergy;1");
    TLeaf* einit = accum->GetLeaf("Einit");
    TLeaf* edepo = accum->GetLeaf("Edep");

    TTree* edeps = tuples->GetObjectUnchecked("EnergyDepositions;1");

    TTree* secs  = tuples->GetObjectUnchecked("SecondarySpectrum;1");
    TLeaf* secsenergy = secs->GetLeaf("KineticEnergy");

    double ein = 0;
    double eout = 0;



    int nevents = accum->GetEntries();
    cout << "Making Summary\n";
    FILE* summary = fopen("summ.txt", "a+");

    for (int ii = 0; ii<nevents; ii++)
    {
        accum->GetEntry(ii);
        ein+=einit->GetValue();
        eout+=edepo->GetValue();
    }

    FILE* summary = fopen("summ.txt", "a+");

    time_t t = time(NULL);
    char* c_time_string = ctime(&t);
    char* mytime[20];
    strncpy(mytime, c_time_string, 19);
    mytime[ strlen(mytime) - 1 ] = '\0';

    fprintf(summary, "%s,%s,%e,%e\n", mytime, filename, ein, eout);//*c_time_string, *filename, ein, eout);
    //cout << *c_time_string << "," << *filename << "," << ein << "," << eout << "\n";
    fclose(summary);

    // Print out or save these values
    cout << "Making Histogram\n";

    nevents = secs->GetEntries();
    TH1F* secondaries = new TH1F("secondaries", "Secondary Electrons <100 keV", 92, 0.010, 0.102);

    for (int ii = 0; ii<nevents; ii++)
    {
        secs->GetEntry(ii);
        secondaries->Fill(secsenergy->GetValue());
    }

    char* suffix = ".secondaryhisto";

    cout << "Making Filenames\n";


    char* outfilename = malloc(strlen(filename) + strlen(suffix) + 1);
    strcpy(outfilename, filename);
    strcat(outfilename, suffix);

    printf("Saving Histogram: %s \n", outfilename);
    h12ascii(secondaries, outfilename);

    return 0;

}
开发者ID:natl,项目名称:multiscale,代码行数:72,代码来源:analysis.C


示例17: 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


示例18: execute

bool execute(const std::string& skeleton, const std::string& config_file, std::string output_dir/* = ""*/) {

    std::vector<Plot> plots;
    // If an output directory is specified, use it, otherwise use the current directory
    if (output_dir == "")
      output_dir = ".";

    std::map<std::string, std::string> unique_names;

    get_plots(config_file, plots);

    std::cout << "List of requested plots: ";
    for (size_t i = 0; i < plots.size(); i++) {
        std::cout << "'" << plots[i].name << "'";
        if (i != plots.size() - 1)
            std::cout << ", ";
    }
    std::cout << std::endl;

    // Convert plots name to unique name to avoid collision between different runs
    for (Plot& plot: plots) {
        std::string uuid = get_uuid();
        unique_names[uuid] = plot.name;
        plot.name = uuid;
    }

    std::unique_ptr<TChain> t(new TChain("t"));
    t->Add(skeleton.c_str());

    std::vector<Branch> branches;
    std::function<void(TTreeFormula*)> getBranches = [&branches, &getBranches](TTreeFormula* f) {
        if (!f)
            return;

        for (size_t i = 0; i < f->GetNcodes(); i++) {
            TLeaf* leaf = f->GetLeaf(i);
            if (! leaf)
                continue;

            TBranch* p_branch = getTopBranch(leaf->GetBranch());

            Branch branch;
            branch.name = p_branch->GetName();
            if (std::find_if(branches.begin(), branches.end(), [&branch](const Branch& b) {  return b.name == branch.name;  }) == branches.end()) {
                branch.type = p_branch->GetClassName();
                if (branch.type.empty())
                    branch.type = leaf->GetTypeName();

                branches.push_back(branch);
            }

            for (size_t j = 0; j < f->fNdimensions[i]; j++) {
                if (f->fVarIndexes[i][j])
                    getBranches(f->fVarIndexes[i][j]);
            }
        }

        for (size_t i = 0; i < f->fAliases.GetEntriesFast(); i++) {
            getBranches((TTreeFormula*) f->fAliases.UncheckedAt(i));
        }
    };

    std::string hists_declaration;
    std::string text_plots;
    for (auto& p: plots) {
        // Create formulas
        std::shared_ptr<TTreeFormula> selector(new TTreeFormula("selector", p.plot_cut.c_str(), t.get()));

        getBranches(selector.get());

        std::vector<std::string> splitted_variables = split(p.variable, ":");
        for (const std::string& variable: splitted_variables) {
            std::shared_ptr<TTreeFormula> var(new TTreeFormula("var", variable.c_str(), t.get()));
            getBranches(var.get());
        }

        std::string binning = p.binning;
        binning.erase(std::remove_if(binning.begin(), binning.end(), [](char chr) { return chr == '(' || chr == ')'; }), binning.end());

        // If a variable bin size is specified, declare array that will be passed as array to histogram constructor
        if(binning.find("{") != std::string::npos){
          std::string arrayString = buildArrayForVariableBinning(binning, splitted_variables.size(), p.name);
          hists_declaration += arrayString;
        }

        std::string title = p.title + ";" + p.x_axis + ";" + p.y_axis + ";" + p.z_axis;
        std::string histogram_type = getHistogramTypeForDimension(splitted_variables.size());

        hists_declaration += "    std::unique_ptr<" + histogram_type + "> " + p.name + "(new " + histogram_type + "(\"" + p.name + "\", \"" + title + "\", " + binning + ")); " + p.name + "->SetDirectory(nullptr);\n";
 
        std::string variable_string;
        for (size_t i = 0; i < splitted_variables.size(); i++) {
            variable_string += splitted_variables[i];
            if (i != splitted_variables.size() - 1)
                variable_string += ", ";
        }

        ctemplate::TemplateDictionary plot("plot");
        plot.SetValue("CUT", p.plot_cut);
        plot.SetValue("VAR", variable_string);
//.........这里部分代码省略.........
开发者ID:sdevissc,项目名称:CommonTools,代码行数:101,代码来源:createPlotter.cpp


示例19: 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


示例20: DrawXsection

/** @ingroup FMD_xsec_script
    @param scale 
    @param filename 
    @param var 
    @param medName 
    @param thick 
    @param pdgName 
*/
void
DrawXsection(Bool_t scale=kFALSE, 
	     const char* filename="xsec.root", 
	     const char* var="LOSS", 
	     const char* medName="FMD_Si$", 
	     Double_t thick=.03,
	     const char* pdgName="pi+")
{
  TFile*   file = TFile::Open(filename, "READ");
  TTree*   tree = static_cast<TTree*>(file->Get(Form("%s_%s",medName,
						     pdgName)));
  TLeaf* tb   = tree->GetLeaf("T");
  TLeaf* vb   = tree->GetLeaf(var);
  if (!vb) {
    std::cerr << "Leaf " << var << " not found" << std::endl;
    return;
  }
  Float_t tkine, value;
  tb->SetAddress(&tkine);
  vb->SetAddress(&value);
  Int_t n = tree->GetEntries();

  Float_t xscale = 1;
  Float_t yscale = 1;
  if (scale) {
    TDatabasePDG* pdgDb = TDatabasePDG::Instance();
    TParticlePDG* pdgP  = pdgDb->GetParticle(pdgName);
    if (!pdgP) {
      std::cerr << "Couldn't find particle " << pdgName << std::endl;
      return;
    }
    Double_t m = pdgP->Mass();
    Double_t q = pdgP->Charge() / 3;
    if (m == 0 || q == 0) {
      std::cerr  << "Mass is 0" << std::endl;
      return;
    }
    xscale = 1 / m;
    yscale = 1 / (q * q);
  }
  
  TGraphErrors* graph = new TGraphErrors(n);
  for (Int_t i = 0; i < n; i++) {
    tree->GetEntry(i);
    Double_t x = tkine*xscale;
    Double_t y = value*yscale;
    graph->SetPoint(i, x, y); 
    // 5 sigma
    graph->SetPointError(i, 0, 5 * .1 * y);
  }
  TCanvas* c = new TCanvas("c","c");
  c->SetLogx();
  c->SetLogy();
  graph->SetLineWidth(2);
  graph->SetFillStyle(3001);
  graph->SetFillColor(6);
  graph->Draw("L");
  graph->DrawClone("AL3");
  c->Modified();
  c->Update();
  c->cd();
  c->SaveAs("xsec.C");
  
}
开发者ID:alisw,项目名称:AliRoot,代码行数:72,代码来源:DrawXsection.C



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TLeafList类代码示例发布时间:2022-05-31
下一篇:
C++ TLatex类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap