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


C++ TChain::GetTree方法代码示例

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


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

示例1: filter

int filter(TString inputDir, long n_evt=100,bool is11=false,bool isFR=false)
{
	long TotalEvents=n_evt;
	
	//options
	bool is2011=is11;
    int N_ALL=4;
    int N_ELMU=-3;
    if(isFR){
		N_ALL=-4;
		N_ELMU=3;
	}
           
    double cut_mu_pt=9.0;
    double cut_mu_eta=2.4; 
    double cut_el_pt=9.0;
    double cut_el_eta=2.5;
    double cut_tau_pt=19.0;
    double cut_tau_eta=2.3;
    
    if(isFR) cut_tau_pt=0.0;
    
    double cut_dR=-0.09;
    double lepton_mass_min=50.0;
    double lepton_mass_max=150.0;
    
	std::string doubEle="HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v";
	std::string doubEle2="HLT_Ele17_CaloIdL_CaloIsoVL_Ele8_CaloIdL_CaloIsoVL_v";
	
    std::string doubMu="HLT_Mu17_Mu8_v";
    std::string doubMu2="HLT_Mu17_TkMu8_v"; // "HLT_Mu13_Mu8_v" in 2011
    if(is2011) doubMu2="HLT_Mu13_Mu8_v";
    std::string doubMu3="HLT_DoubleMu7_v";
    
    bool debug = false;
    

	
	TChain *chain = new TChain("t");
	chain->Add(inputDir+"*root*");
	
	
	
	//////////////////////// end of modular part ////////////////////////////////////////
	/////////////////////////COMMON part //////////////////////////////////////////
	myevent* in = new myevent();
	chain->SetBranchAddress("myevent",&in);
	
	long MaxEvents = chain->GetEntries();
	if(TotalEvents > MaxEvents || TotalEvents < 0) TotalEvents=MaxEvents;
	
	std::cout << "There are " << MaxEvents << " entries." << std::endl;
	
	
	//bookkeeping
	ofstream lumi;
	long current_run=-1;
	long current_lumi=-1;
    long m_allEvents=0;
	lumi.open("lumi.csv");
	
	//output definition
	
	 TFile *newFile = new TFile("output.root","recreate");
	TChain *newchain = (TChain*)chain->CloneTree(0);
	 TTree *tree = newchain->GetTree();
	
	
	for(uint i =0; i < TotalEvents; i++)
	{
		chain->GetEntry(i);
		m_allEvents++;
		
		if(debug) std::cout << "Processing entry " << i << " event: " << in->eventNumber << std::endl;
		if(i%1000==0)std::cout << "Analyzing entry no. " << i << std::endl;
		
		// storing lumis
		if(in->runNumber!=current_run || in->lumiNumber!=current_lumi){
			lumi << in->runNumber << " " << in->lumiNumber << std::endl;
			current_run=in->runNumber;
			current_lumi=in->lumiNumber;
		}
		
		if(PassFilter(in, debug, doubEle, doubEle2, doubMu, doubMu2, doubMu3,
			         is2011, N_ALL, N_ELMU, 
			         cut_mu_pt, cut_mu_eta, cut_el_pt, cut_el_eta, cut_tau_pt, cut_tau_eta,		    
			         cut_dR, lepton_mass_min, lepton_mass_max)
		   ) tree->Fill();
	}
	
	newFile->cd();
	newFile->Write();
	newFile->Close();
	
	 ofstream log1;       
     log1.open("total.txt");
     log1 << m_allEvents << std::endl;
     log1.close();
     
	return 0;
//.........这里部分代码省略.........
开发者ID:abdollah110,项目名称:53xNtupleProducer,代码行数:101,代码来源:filter.C

示例2: main

int main ()
{
  TFile * outputfile = TFile::Open ("outputTMVA.root","RECREATE");
  TMVA::Factory * TMVAtest = new TMVA::Factory ("TMVAtest", outputfile, "S") ;

  //PG get the signal and deliver it to the TMVA factory
  
  TChain signalTree ("sample") ;
  signalTree.Add ("data/sig_0.root") ;
  std::cout << "READ " << signalTree.GetEntries () << " signal events\n" ;
  TMVAtest->AddSignalTree (&signalTree, 1) ;  

  //PG get the bkg and deliver it to the TMVA factory
  
  TChain bkgTree ("sample") ;
  bkgTree.Add ("data/bkg_0.root") ;
  std::cout << "READ " << bkgTree.GetEntries () << " bkg events\n" ;
  TMVAtest->AddBackgroundTree (&bkgTree, 1) ;  

  //PG get the training and test samples and deliver them to the TMVA factory

  TChain signalTrainTree ("sample") ;
  signalTrainTree.Add ("data/sig_1.root") ;
  std::cout << "READ " << signalTrainTree.GetEntries () << " signal train events\n" ;
  
  TChain bkgTrainTree ("sample") ;
  bkgTrainTree.Add ("data/bkg_1.root") ;
  std::cout << "READ " << bkgTrainTree.GetEntries () << " bkg train events\n" ;
  
  TMVAtest->SetInputTrees (signalTrainTree.GetTree (), bkgTrainTree.GetTree (), 1., 1.) ;  

  //PG variables to be used for the selection
  //PG must be defined in the TTrees
  
  TMVAtest->AddVariable ("vars.x", 'F') ;
  TMVAtest->AddVariable ("vars.y" , 'F') ;

  int signalNumTrain = signalTrainTree.GetEntries () * 4 / 5 ;
  int bkgNumTrain = bkgTrainTree.GetEntries () * 4 / 5 ;
  int signalNumTest = signalTrainTree.GetEntries () - signalNumTrain ;
  int bkgNumTest = bkgTrainTree.GetEntries () - bkgNumTrain ;
  char trainOptions[120] ;
  sprintf (trainOptions,"NSigTrain=%d:NBkgTrain=%d:NSigTest=%d:NBkgTest=%d",
           signalNumTrain, bkgNumTrain,
           signalNumTest, bkgNumTest) ;
  sprintf (trainOptions,"NSigTrain=%d:NBkgTrain=%d:NSigTest=%d:NBkgTest=%d",
           0,0,0,0) ;
  std::cout << "TRAINING CONFIGURATION : " << trainOptions << "\n" ;
  TMVAtest->PrepareTrainingAndTestTree ("",trainOptions) ;
  
  //PG prepare the classifier
  
  //PG cut-based, default params
  TMVAtest->BookMethod (TMVA::Types::kCuts, "Cuts") ;
  
  TMVAtest->TrainAllMethods () ;
  TMVAtest->TestAllMethods () ;
  TMVAtest->EvaluateAllMethods () ;
 
  delete TMVAtest ;
  delete outputfile ;
}
开发者ID:govoni,项目名称:testMVA,代码行数:62,代码来源:unit06.cpp

示例3: combinefiles


//.........这里部分代码省略.........
    eventChain->SetBranchAddress("mt2",            &mt2);
    eventChain->SetBranchAddress("mt2puppi",       &mt2puppi);
    eventChain->SetBranchAddress("mt2pileup",      &mt2pileup);

    eventChain->SetBranchAddress("m_sv",           &m_sv);
    eventChain->SetBranchAddress("m_svpileup",     &m_svpileup);
    eventChain->SetBranchAddress("m_svpuppi",      &m_svpuppi);

    eventChain->SetBranchAddress("nBtag",          &nBtag);
    eventChain->SetBranchAddress("nCentral",       &nCentral);
    eventChain->SetBranchAddress("centB",          &centB);
    eventChain->SetBranchAddress("nJets",          &nJets);

    eventChain->SetBranchAddress("dEta_tt",        &dEta_tt);
    eventChain->SetBranchAddress("dEta_6j",        &dEta_6j);
    eventChain->SetBranchAddress("rho_0",          &rho_0);
    eventChain->SetBranchAddress("rho_1",          &rho_1);
    eventChain->SetBranchAddress("rho_2",          &rho_2);

    eventChain->SetBranchAddress("dEtaBB1",         &dEtaBB1);
    eventChain->SetBranchAddress("dPhiBB1",         &dPhiBB1);
    eventChain->SetBranchAddress("dRBB1",           &dRBB1);

    eventChain->SetBranchAddress("dEtaTT",          &dEtaTT);
    eventChain->SetBranchAddress("dPhiTT",          &dPhiTT);
    eventChain->SetBranchAddress("dRTT",            &dRTT);

    eventChain->SetBranchAddress("dEtaHH",          &dEtaHH);
    eventChain->SetBranchAddress("dPhiHH",          &dPhiHH);
    eventChain->SetBranchAddress("dRHH",            &dRHH);

    eventChain->GetEntry(0);

    TTree *outTree=(TTree*)eventChain->GetTree()->CloneTree(0);

    outTree->Branch("bdtVal", &bdtVal, "bdtVal/f");
    outTree->Branch("chi2", &chi2, "chi2/f");
    outTree->Branch("corrMet", &corrMet, "corrMet/f");
    outTree->Branch("corrMetPhi", &corrMetPhi, "corrMetPhi/f");
    outTree->Branch("conv", &conv, "conv/i");

    //hhMVA::MVAType why1=hhMVA::kTauTau;
    hhMVA::MVAType why2=hhMVA::kMuTau;
    hhMVA::MVAType why3=hhMVA::kElTau;
    hhMVA::MVAType why4=hhMVA::kElMu;

    //hhMVA *ttMVA = new hhMVA();
    hhMVA *mtMVA = new hhMVA();
    hhMVA *etMVA = new hhMVA();
    hhMVA *emMVA = new hhMVA();

    //ttMVA->Intialize(why1);
    mtMVA->Intialize(why2);
    etMVA->Intialize(why3);
    emMVA->Intialize(why4);

    for (Int_t i=0; i<eventChain->GetEntries(); i++) {
        eventChain->GetEntry(i);

        eventWeight/=float(nevents);
        bdtVal=999;

        // hack to fix modified SM samples
        //if (sampleNo>95 && sampleNo<100) eventWeight=2.92/float(nevents);

        if (isBBTT!=1) continue;
开发者ID:jaylawhorn,项目名称:delphes-dihiggs,代码行数:67,代码来源:combinefiles.C

示例4: skimThisBaby

//
// Fucntions
//
void skimThisBaby(TString inPath, TString inFileName, TString inTreeName, TString outPath){

  // Talk to user
  cout << "  Skimming: "<< endl;
  cout << "     " << inPath+inFileName <<endl;
  
  // Load input TChain
  TChain *ch = new TChain(inTreeName);
  TString inFile = inPath;
  inFile += inFileName;
  ch->Add(inFile);
  Long64_t nentries = ch->GetEntries();
  TTreeCache::SetLearnEntries(10);
  ch->SetCacheSize(128*1024*1024);

  // Initialize Branches
  babyAnalyzer.Init(ch->GetTree());
  babyAnalyzer.LoadAllBranches();
  
  // Setup output file name and path
  TString outFileName = outPath;
  outFileName += inFileName;
  outFileName.ReplaceAll("*", "");
  outFileName.ReplaceAll(".root", "_skimmed.root");

  cout << "  Output will be written to: " << endl;
  cout << "      "  << outFileName << endl << endl;

  // Open outputfile and Clone input TTree
  TFile *newfile = new TFile(outFileName, "recreate");
  TTree *newtree  = (TTree*)ch->GetTree()->CloneTree(0);
  if(!newtree) cout << "BAD TTREE CLONE" << endl;

  TH1D *newCounter=NULL;
  
  // Get nEntries
  unsigned int nEventsTotal = 0;
  unsigned int nEventsChain = ch->GetEntries();
  
  // Grab list of files
  TObjArray *listOfFiles = ch->GetListOfFiles();
  TIter fileIter(listOfFiles);
  TFile *currentFile = 0;

  // File Loop
  int iFile=0;
  while ( (currentFile = (TFile*)fileIter.Next()) ) {

    // Get File Content
    TFile *file = new TFile( currentFile->GetTitle() );
    TTree *tree = (TTree*)file->Get("t");
    TTreeCache::SetLearnEntries(10);
    tree->SetCacheSize(128*1024*1024);
    babyAnalyzer.Init(tree);

    if(iFile==0){
      TH1D *temp = (TH1D*)file->Get("h_counter");
      newCounter = (TH1D*)temp->Clone("h_counter");
      newCounter->SetDirectory(newfile);
    }
    //else{
    //TH1D *temp = (TH1D*)file->Get("h_counter");
    //newCounter->Add(temp);
    //}

    // Loop over Events in current file 
    if( nEventsTotal >= nEventsChain ) continue;
    unsigned int nEventsTree = tree->GetEntriesFast();
    for( unsigned int event = 0; event < nEventsTree; ++event) {
      
      // Progress
      stop_1l_babyAnalyzer::progress( nEventsTotal, nEventsChain );
    
      // Load Tree
      tree->LoadTree(event);
      babyAnalyzer.GetEntry(event);
      ++nEventsTotal;

      // Selection
      if(nvetoleps()<1) continue;
      if(nvetoleps()<2 && PassTrackVeto_v3() && PassTauVeto()) continue;
      if(ngoodjets()<2) continue;
      if(mt_met_lep()<150.0) continue;
      if(pfmet()<200.0) continue;

      // Turn on all branches on input
      babyAnalyzer.LoadAllBranches();      
      
      // Fill output tree
      newtree->Fill();
    
    } // end loop over entries
   
    iFile++;
  } // end loop over files in TChain

  // Clean up
//.........这里部分代码省略.........
开发者ID:jgwood3141,项目名称:StopAnalyzers_2p26fb__SUS16002,代码行数:101,代码来源:skimBaby_CR_2lep.C

示例5: main

int main ()
{
  TFile * outputfile = TFile::Open ("outputTMVA.root","RECREATE");
  TMVA::Factory * TMVAtest = new TMVA::Factory ("TMVAtest", outputfile, "S") ;

  //PG get the signal and deliver it to the TMVA factory
  
  TChain signalTree ("shrinked") ;
  signalTree.Add ("data/H160_VBF.root") ;
  std::cout << "READ " << signalTree.GetEntries () << " signal events\n" ;
  TMVAtest->AddSignalTree (&signalTree, 1) ;  

  //PG get the bkg and deliver it to the TMVA factory
  
  TChain bkgTree ("shrinked") ;
  bkgTree.Add ("data/H160_NOVBF.root") ;
  std::cout << "READ " << bkgTree.GetEntries () << " bkg events\n" ;
  TMVAtest->AddBackgroundTree (&bkgTree, 1) ;  

  //PG get the training and test samples and deliver them to the TMVA factory

  TChain signalTrainTree ("shrinked") ;
  signalTrainTree.Add ("data/H150_VBF.root") ;
  std::cout << "READ " << signalTrainTree.GetEntries () << " signal train events\n" ;
  
  TChain bkgTrainTree ("shrinked") ;
  bkgTrainTree.Add ("data/H150_NOVBF.root") ;
  std::cout << "READ " << bkgTrainTree.GetEntries () << " bkg train events\n" ;

  // PG this is useless!!  
  TMVAtest->SetInputTrees (signalTrainTree.GetTree (), bkgTrainTree.GetTree (), 1., 1.) ;  

  //PG variables to be used for the selection
  //PG must be defined in the TTrees
  
  TMVAtest->AddVariable ("vars.Deta", 'F') ;
  TMVAtest->AddVariable ("vars.Dphi" , 'F') ;
  TMVAtest->AddVariable ("vars.Minv" , 'F') ;

  int signalNumTrain = signalTrainTree.GetEntries () * 4 / 5 ;
  int bkgNumTrain = bkgTrainTree.GetEntries () * 4 / 5 ;
  int signalNumTest = signalTrainTree.GetEntries () - signalNumTrain ;
  int bkgNumTest = bkgTrainTree.GetEntries () - bkgNumTrain ;
  char trainOptions[120] ;
  sprintf (trainOptions,"NSigTrain=%d:NBkgTrain=%d:NSigTest=%d:NBkgTest=%d",
           signalNumTrain, bkgNumTrain,
           signalNumTest, bkgNumTest) ;
  sprintf (trainOptions,"NSigTrain=%d:NBkgTrain=%d:NSigTest=%d:NBkgTest=%d",
           0,0,0,0) ;
  std::cout << "TRAINING CONFIGURATION : " << trainOptions << "\n" ;
  TMVAtest->PrepareTrainingAndTestTree ("",trainOptions) ;
  
  //PG prepare the classifiers
  //PG ------------------------

  //PG cut-based, default params
  TMVAtest->BookMethod (TMVA::Types::kCuts, "Cuts") ;
  
  //PG multi layer perceptron
  TMVAtest->BookMethod (TMVA::Types::kMLP, "MLP", 
                        "H:!V:!Normalise:NeuronType=tanh:NCycles=200:HiddenLayers=N+1,N:TestRate=5");
  
  TMVAtest->TrainAllMethods () ;
  TMVAtest->TestAllMethods () ;
  TMVAtest->EvaluateAllMethods () ;
 
  delete TMVAtest ;
  delete outputfile ;
}
开发者ID:govoni,项目名称:testMVA,代码行数:69,代码来源:unit09.cpp


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