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


C++ TTree::GetTitle方法代码示例

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


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

示例1: rewritetrees

void rewritetrees(){
  TString trees[] = {"iso2j1t" , "noniso2j1t" , "iso2j0t" , "noniso2j0t" , "iso3j2t" , "noniso3j2t" , "iso3j1t" , "noniso3j1t" };

  struct{
    float weight;
    float mtw;
    float met;
    bool data;
    bool qcd;
  } info;

  TFile* fout = TFile::Open("out.root" , "RECREATE");

  for( int i=0 ; i < 8 ; i++){
    cout << trees[i] << endl;
    TTree* tree = (TTree*)( _file0->Get("Trees/" + trees[i] ) );
    tree->SetBranchAddress( "info" , &info );

    tree->Print();

    TTree* tout = new TTree( tree->GetName() , tree->GetTitle() );
    tout->SetAutoSave( 10000 );
    tout->Branch( "weight" , &info.weight );
    tout->Branch( "mtw" , &info.mtw);
    tout->Branch( "met" , &info.met );
    tout->Branch( "data" , &info.data );
    tout->Branch( "qcd" , &info.qcd );

    for(int j = 0 ; j < tree->GetEntries() ; j++){
      tree->GetEntry(j);
      tout->Fill();
      //cout << i ;
    }
    
    
  }

  fout->Write();
  fout->Close();
}
开发者ID:hbakhshi,项目名称:Analysis13TeV,代码行数:40,代码来源:rewritetrees.C

示例2: ProcessFilePar

//std::mutex mtx;
void ProcessFilePar(TString fileIn, TString fileOut, TString treename,  vector<TString> friends, vector<TString> branches, vector<TString> newbranches, unsigned jobid = 0, unsigned NPAR = 1)
{
  //mtx.lock(); //for threads
  TFile *fin = new TFile(fileIn);
  TTree *tjet = (TTree*)fin->Get(treename);
  //mtx.unlock();

  vector<TTree *> friendTrees;
  vector<bool> sameFileFriend;
  for (auto f:friends) {
    auto fr = tokenize(f,":");
    if (fr.size()==1) {tjet->AddFriend(fr[0]); sameFileFriend.push_back(true);}
    else if (fr.size()==2) {tjet->AddFriend(fr[1],fr[0]); sameFileFriend.push_back(false);}

    TTree *tfriend = (TTree*)fin->Get(f);
    friendTrees.push_back(tfriend);
  }

  AddBranchesByCounter(tjet, branches);
  for (unsigned i=0;i<friendTrees.size();i++) AddBranchesByCounter(friendTrees[i],branches);

  //sort branches into categories
  for (auto bName:branches) {
    TBranch *b=tjet->GetBranch(bName);
    if (b==0) cout <<"Branch "<<bName<<" doesn't exist!"<<endl;

    //parse in case there is a tree name in the branch
    auto branchtoken = tokenize(bName,".");
    auto leafname = branchtoken[branchtoken.size()-1];

    TObjArray *bl = b->GetListOfLeaves();
    if (bl->GetEntries()>1)
      cout <<" Branch "<<b->GetTitle()<<" has more than 1 leave. Taking first..."<<endl;
    if (bl->GetEntries()==0) {
      cout <<" Branch "<<b->GetTitle()<<" has no leaves! Skipping..."<<endl;
      continue;
    }

    TLeaf * l = (TLeaf *)(*bl)[0];
    //what's the type?
    TString type = l->GetTypeName();
    if (VERBOSE) cout<<l->GetTitle()<<endl;

    //array?
    bool array = l->GetLeafCount()!=0;
    TString counter;
    if (array) counter = l->GetLeafCount()->GetBranch()->GetName();

    if (type=="Float_t")
      {  if (array) {brVFloat.push_back(bName); brVFloatCounter.push_back(counter); }else brFloat.push_back(bName);}
    else if (type=="Int_t")
      {  if (array) {brVInt.push_back(bName); brVIntCounter.push_back(counter); }else brInt.push_back(bName);}
    else cout << "Unsupported branch type "<<type<<" for branch "<<bName<<". Skipping..."<<endl;
  }


  //treat counters as ints only
  AppendToListUniquely(brVIntCounter, brInt);
  AppendToListUniquely(brVFloatCounter, brInt);

  //too keep track of old branches, which cannot be read (todo: just check it...)
  int noldbrInt = brInt.size(), noldbrFloat = brFloat.size(), noldbrVInt = brVInt.size(), noldbrVIntCounter = brVIntCounter.size(), noldbrVFloat = brVFloat.size(), noldbrVFloatCounter = brVFloatCounter.size();
  //add new branches
  ParseNewBranches(newbranches, brInt, brFloat, brVInt, brVIntCounter, brVFloat, brVFloatCounter);

  //print for debugging
  if (VERBOSE) {
    cout<<"int       : "; for (auto s:brInt) cout <<s<<", "; cout<<endl;
    cout<<"float     : "; for (auto s:brFloat) cout <<s<<", "; cout<<endl;
    cout<<"Vint      : "; for (auto s:brVInt) cout <<s<<", "; cout<<endl;
    cout<<"Vfloat    : "; for (auto s:brVFloat) cout <<s<<", "; cout<<endl;
    cout<<"Vintcnt   : "; for (auto s:brVIntCounter) cout <<s<<", "; cout<<endl;
    cout<<"Vfloatcnt : "; for (auto s:brVFloatCounter) cout <<s<<", "; cout<<endl;
  }

  tjet->SetBranchStatus("*",1);
  for (auto b:brVFloat) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0);
  for (auto b:brFloat)  if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0);
  for (auto b:brVInt)   if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0);
  for (auto b:brInt)    if (tjet->GetBranch(b)!=0) {unsigned f=0; tjet->SetBranchStatus(b,0,&f); if (VERBOSE) cout<<"turning off "<<b<<", found = "<<f<<endl;}


  TFile *fout = new TFile(fileOut,"recreate");
  TTree *tjetout;


  //in case of one-to-many event - do not copy branches automatically!
  if (useOneToOne) tjetout = tjet->CloneTree(0);
  else tjetout = new TTree(tjet->GetName(),tjet->GetTitle());


  //think about memory tree
  // tjetout->SetDirectory(0);
  tjetout->SetName(tjet->GetName());
  //TTree *tjetout = new TTree("t","t");

  //to see what is copied...
  //tjetout->Print();

//.........这里部分代码省略.........
开发者ID:istaslis,项目名称:pPbmacro,代码行数:101,代码来源:HelperProcess.C

示例3: AnalyseFile

void KVSimDir::AnalyseFile(const Char_t* filename)
{
   // Analyse ROOT file given as argument.
   // If there is a TTree in the file, then we look at all of its branches until we find one
   // containing objects which derive from KVEvent:
   //
   //   -- if they inherit from KVSimEvent, we add the file to the list of simulated data:
   //            * a KVSimFile is created. The title of the TTree where data were found will
   //               be used as 'Information' on the nature of the simulation.
   //   -- if they inherit from KVReconstructedEvent, we add the file to the list of filtered data.
   //            * a KVSimFile is created. Informations on the filtered data are extracted from
   //              TNamed objects in the file with names 'Dataset', 'System', 'Run', 'Geometry'
   //              (type of geometry used, 'ROOT' or 'KV'), 'Origin' (i.e. the name of the simulation
   //              file which was filtered), 'Filter' (type of filter: Geo, GeoThresh or Full).
   //              These objects are automatically created when data is filtered using KVEventFiltering.
   //
   // Analysis of the file stops after the first TTree with a branch satisfying one of the
   // two criteria is found (it is assumed that in each file there is only one TTree containing
   // either simulated or filtered data).

   Info("AnalyseFile", "Analysing file %s...", filename);
   TString fullpath;
   AssignAndDelete(fullpath, gSystem->ConcatFileName(GetDirectory(), filename));
   TFile* file = TFile::Open(fullpath);
   if (!file || file->IsZombie()) return;
   // look for TTrees in file
   TIter next(file->GetListOfKeys());
   TKey* key;
   while ((key = (TKey*)next())) {
      TString cn = key->GetClassName();
      if (cn == "TTree") {
         // look for branch with KVEvent objects
         TTree* tree = (TTree*)file->Get(key->GetName());
         TSeqCollection* branches = tree->GetListOfBranches();
         TIter nextB(branches);
         TBranchElement* branch;
         while ((branch = (TBranchElement*)nextB())) {
            TString branch_classname = branch->GetClassName();
            TClass* branch_class = TClass::GetClass(branch_classname, kFALSE, kTRUE);
            if (branch_class && branch_class->InheritsFrom("KVEvent")) {
               if (branch_class->InheritsFrom("KVSimEvent")) {
                  fSimData.Add(new KVSimFile(this, filename, tree->GetTitle(), tree->GetEntries(), tree->GetName(), branch->GetName()));
                  delete file;
                  return;
               } else if (branch_class->InheritsFrom("KVReconstructedEvent")) {
                  // filtered data. there must be TNamed called 'Dataset', 'System', & 'Run' in the file.
                  TNamed* ds = (TNamed*)file->Get("Dataset");
                  TNamed* orig = (TNamed*)file->Get("Origin");
                  TNamed* sys = (TNamed*)file->Get("System");
                  TNamed* r = (TNamed*)file->Get("Run");
                  TNamed* g = (TNamed*)file->Get("Geometry");
                  TNamed* f = (TNamed*)file->Get("Filter");
                  TString dataset;
                  if (ds) dataset = ds->GetTitle();
                  TString system;
                  if (sys) system = sys->GetTitle();
                  TString run;
                  if (r) run = r->GetTitle();
                  TString origin;
                  if (orig) origin = orig->GetTitle();
                  TString geometry;
                  if (g) geometry = g->GetTitle();
                  TString filter;
                  if (f) filter = f->GetTitle();
                  Int_t run_number = run.Atoi();
                  fFiltData.Add(new KVSimFile(this, filename, tree->GetTitle(), tree->GetEntries(), tree->GetName(), branch->GetName(),
                                              dataset, system, run_number, geometry, origin, filter));
                  delete file;
                  delete ds;
                  delete sys;
                  delete r;
                  delete f;
                  return;
               }
            }
         }
      }
   }
}
开发者ID:GiuseppePast,项目名称:kaliveda,代码行数:79,代码来源:KVSimDir.cpp

示例4: AnalyseEvents


//.........这里部分代码省略.........
	Muon1_p4 = muon1->P4();
	Muon1_px = muon1->P4().Px(); Muon1_py = muon1->P4().Py(); Muon1_pz = muon1->P4().Pz(); Muon1_energy = muon1->P4().E();
	Muon1_eta = muon1->P4().Eta(); Muon1_phi = muon1->P4().Phi(); Muon1_pt = muon1->PT;
	}
    if (hasMuon2){
	Muon2_p4 = muon2->P4();
	Muon2_px = muon2->P4().Px(); Muon2_py = muon2->P4().Py(); Muon2_pz = muon2->P4().Pz(); Muon2_energy = muon2->P4().E();
	Muon2_eta = muon2->P4().Eta(); Muon2_phi = muon2->P4().Phi(); Muon2_pt = muon2->PT;
	}
   
    if (hasMuon1 && hasMuon2){
    if (((muon1->PT > muonPt1_ && muon2->PT > muonPt2_) || (muon1->PT > muonPt2_ && muon2->PT > muonPt1_)) 
	&& fabs(muon1->Eta)<muonsEta_ && fabs(muon2->Eta)< muonsEta_) hastwomuons =true;
    }
    // Loop over all electrons in event
    for(i = 0; i < branchElectron->GetEntriesFast(); ++i)
    {
      electron = (Electron*) branchElectron->At(i);
      particle = (GenParticle*) electron->Particle.GetObject();
      //cout <<" electron "; printGenParticle(particle);
    }

    // Loop over all photons in event
    for(i = 0; i < branchPhoton->GetEntriesFast(); ++i)
    {
      photon = (Photon*) branchPhoton->At(i);

      // skip photons with references to multiple particles
      if(photon->Particles.GetEntriesFast() != 1) continue;

      particle = (GenParticle*) photon->Particles.At(0);
      //cout <<" photon "; printGenParticle(particle);
    }

   if (hasb1jet and hasb2jet and hasMuon1 and hasMuon2){
	dR_b1l1 = b1jet_p4.DeltaR(Muon1_p4);
	dR_b1l2 = b1jet_p4.DeltaR(Muon2_p4);
	dR_b2l1 = b2jet_p4.DeltaR(Muon1_p4);
	dR_b2l2 = b2jet_p4.DeltaR(Muon2_p4);
	dR_b1b2 = b1jet_p4.DeltaR(b2jet_p4);
	dR_l1l2 = Muon1_p4.DeltaR(Muon2_p4);
	TLorentzVector ll_p4 = Muon1_p4+Muon2_p4;
	TLorentzVector bjets_p4 = b1jet_p4+b2jet_p4;
	mass_l1l2 = ll_p4.M();
        mass_b1b2 = bjets_p4.M();
        if (dR_b1l1>jetleptonDeltaR_ and dR_b1l2>jetleptonDeltaR_ and dR_b2l1>jetleptonDeltaR_ and dR_b2l2>jetleptonDeltaR_) hasdRljet =true;
       
    }
     
    // Loop over all tracks in event
    /*
    for(i = 0; i < branchTrack->GetEntriesFast(); ++i)
    {
      track = (Track*) branchTrack->At(i);
      particle = (GenParticle*) track->Particle.GetObject();
      cout <<" Track "; printGenParticle(particle);

    }*/
   // calculate the DeltaR between bjet and lepton 

    h2tohh = (htobb and Wtomu1nu1 and Wtomu2nu2);
    if (runMMC_ && h2tohh && hasgenb1jet && hasgenb2jet){
	 TLorentzVector bjets_lorentz=genb1jet->P4()+genb2jet->P4();
          
         cout <<" m_{bjets} " << bjets_lorentz.M(); bjets_lorentz.Print();
	 TLorentzVector met_lorentz = Met->P4();
	 bool simulation_ = true;
	 bool weightfromonshellnupt_func = false;
         bool weightfromonshellnupt_hist = true;
	 bool weightfromonoffshellWmass_hist=true; 
	 int iterations = 100000;
	 std::string RefPDFfile("MMCRefPDF.ROOT");
	 bool useMET = true;
	 int onshellMarker_;
 	 if (genW1->Mass > genW2->Mass) onshellMarker_=1;
	 else onshellMarker_=2;
	 // rescale bjets in MMC?????
        //MMC *thismmc = new MMC();

         MMC *thismmc = new MMC(genmu1->P4(), genmu2->P4(), bjets_lorentz, totjets_lorentz, 
          met_lorentz, gennu1->P4(), gennu2->P4(), genb1->P4()+genb2->P4(),
	  genh2->P4(), onshellMarker_,// only for simulation 
          simulation_, entry, weightfromonshellnupt_func, weightfromonshellnupt_hist, weightfromonoffshellWmass_hist,
          iterations, RefPDFfile, useMET);
	  thismmc->runMMC();
	  TTree *mmctree = (thismmc->getMMCTree())->CloneTree();
          std::cout <<"MMCTree entries " << (thismmc->getMMCTree())->GetEntries() << std::endl;
          std::cout <<"testtree entries " << mmctree->GetEntries()<<" title "<< mmctree->GetTitle() << std::endl;
	  //esttree->SetDirectory((TDirectory*)MMCfile);
	  //MMCfile->WriteObject(mmctree,mmctree->GetTitle());
	delete thismmc;
	}
//fill branches
    if (htobb || (Wtomu1nu1 && Wtomu2nu2)) evtree->Fill();
    }
 
   // MMCfile->Close();
    //delete MMCfile;
    //evtree->Fill();
}
开发者ID:tahuang1991,项目名称:oldDelphes,代码行数:101,代码来源:DiHiggs_h2tohh.C

示例5: DiHiggstollbbrun


//.........这里部分代码省略.........
      if (hasMuon1) std::cout <<" has reco Muon1 " << std::endl;
      if (hasMuon2) std::cout <<" has reco Muon2 " << std::endl;
      //cout <<" muon eta " << muon->Eta << " phi " << muon->Phi << " Pt "<< muon->PT << endl; 
    }

    if (hasMuon1){
	Muon1_p4 = muon1->P4();
	Muon1_px = muon1->P4().Px(); Muon1_py = muon1->P4().Py(); Muon1_pz = muon1->P4().Pz(); Muon1_energy = muon1->P4().E();
	Muon1_eta = muon1->P4().Eta(); Muon1_phi = muon1->P4().Phi(); Muon1_pt = muon1->PT;
	}
    if (hasMuon2){
	Muon2_p4 = muon2->P4();
	Muon2_px = muon2->P4().Px(); Muon2_py = muon2->P4().Py(); Muon2_pz = muon2->P4().Pz(); Muon2_energy = muon2->P4().E();
	Muon2_eta = muon2->P4().Eta(); Muon2_phi = muon2->P4().Phi(); Muon2_pt = muon2->PT;
	}
   
    if (hasMuon1 && hasMuon2){
    if (((muon1->PT > muonPt1_ && muon2->PT > muonPt2_) || (muon1->PT > muonPt2_ && muon2->PT > muonPt1_)) 
	&& fabs(muon1->Eta)<muonsEta_ && fabs(muon2->Eta)< muonsEta_) hastwomuons =true;
    }
    // Loop over all electrons in event
    // do similar thing for electron when electrons are also taken as final state
    for(i = 0; i < branchElectron->GetEntriesFast(); ++i)
    {
      electron = (Electron*) branchElectron->At(i);
      //particle = (GenParticle*) electron->Particle.GetObject();
      cout <<" electron "; printSortableObject<Electron>(electron);
    }

    // Loop over all photons in event
    for(i = 0; i < branchPhoton->GetEntriesFast(); ++i)
    {
      photon = (Photon*) branchPhoton->At(i);

      // skip photons with references to multiple particles
      if(photon->Particles.GetEntriesFast() != 1) continue;

      //particle = (GenParticle*) photon->Particles.At(0);
      cout <<" photon "; printSortableObject<Photon>(photon);
    }

   if (hasb1jet and hasb2jet and hasMuon1 and hasMuon2){
	dR_b1l1 = b1jet_p4.DeltaR(Muon1_p4);
	dR_b1l2 = b1jet_p4.DeltaR(Muon2_p4);
	dR_b2l1 = b2jet_p4.DeltaR(Muon1_p4);
	dR_b2l2 = b2jet_p4.DeltaR(Muon2_p4);
	dR_b1b2 = b1jet_p4.DeltaR(b2jet_p4);
	dR_l1l2 = Muon1_p4.DeltaR(Muon2_p4);
	TLorentzVector ll_p4 = Muon1_p4+Muon2_p4;
	TLorentzVector bjets_p4 = b1jet_p4+b2jet_p4;
	mass_l1l2 = ll_p4.M();
        mass_b1b2 = bjets_p4.M();
        if (dR_b1l1>jetleptonDeltaR_ and dR_b1l2>jetleptonDeltaR_ and dR_b2l1>jetleptonDeltaR_ and dR_b2l2>jetleptonDeltaR_) hasdRljet =true;
       
    }
     
    // Loop over all tracks in event
    /*
    for(i = 0; i < branchTrack->GetEntriesFast(); ++i)
    {
      track = (Track*) branchTrack->At(i);
      particle = (GenParticle*) track->Particle.GetObject();
      cout <<" Track "; printGenParticle(particle);

    }*/
   // calculate the DeltaR between bjet and lepton 

    if (runMMC_ and hasdRljet){
	 TLorentzVector bjets_lorentz=b1jet->P4()+b2jet->P4();
          
         cout <<" m_{bjets} " << bjets_lorentz.M(); bjets_lorentz.Print();
	 TLorentzVector met_lorentz = Met->P4();
	 bool weightfromonshellnupt_func = false;
         bool weightfromonshellnupt_hist = true;
	 bool weightfromonoffshellWmass_hist=true; 
	 int iterations = 100000;
	 std::string RefPDFfile("MMCRefPDF.ROOT");
	 bool useMET = true;
         bool onshellMarker_ = -1;
	 // rescale bjets in MMC?????
        //MMC *thismmc = new MMC();
        TLorentzVector null_lorentz = TLorentzVector(); 
         MMC *thismmc = new MMC(Muon1_p4, Muon2_p4, bjets_lorentz, totjets_lorentz, 
          met_lorentz, null_lorentz, null_lorentz, null_lorentz,
	   null_lorentz, onshellMarker_,// only for simulation 
          false, entry, weightfromonshellnupt_func, weightfromonshellnupt_hist, weightfromonoffshellWmass_hist,
          iterations, RefPDFfile, useMET);
	  thismmc->runMMC();
	  TTree *mmctree = (thismmc->getMMCTree())->CloneTree();
          std::cout <<"MMCTree entries " << (thismmc->getMMCTree())->GetEntries() << std::endl;
          std::cout <<"testtree entries " << mmctree->GetEntries()<<" title "<< mmctree->GetTitle() << std::endl;
	  //esttree->SetDirectory((TDirectory*)MMCfile);
	  //MMCfile->WriteObject(mmctree,mmctree->GetTitle());
	delete thismmc;
	}
//fill branches
    if (hasb1jet or hasb2jet or hasMuon1 or hasMuon2) evtree->Fill();
    }
 
}
开发者ID:tahuang1991,项目名称:oldDelphes,代码行数:101,代码来源:DiHiggstollbb.C


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