本文整理汇总了C++中TTree::CloneTree方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::CloneTree方法的具体用法?C++ TTree::CloneTree怎么用?C++ TTree::CloneTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::CloneTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyDir
void CopyDir(TDirectory *source) {
//copy all objects and subdirs of directory source as a subdir of the current directory
source->ls();
TDirectory *savdir = gDirectory;
TDirectory *adir = savdir->mkdir(source->GetName());
adir->cd();
//loop on all entries of this directory
TKey *key;
TIter nextkey(source->GetListOfKeys());
while ((key = (TKey*)nextkey())) {
const char *classname = key->GetClassName();
TClass *cl = gROOT->GetClass(classname);
if (!cl) continue;
if (cl->InheritsFrom(TDirectory::Class())) {
source->cd(key->GetName());
TDirectory *subdir = gDirectory;
adir->cd();
CopyDir(subdir);
adir->cd();
} else if (cl->InheritsFrom(TTree::Class())) {
TTree *T = (TTree*)source->Get(key->GetName());
adir->cd();
TTree *newT = T->CloneTree(-1,"fast");
newT->Write();
} else {
source->cd();
TObject *obj = key->ReadObj();
adir->cd();
obj->Write();
delete obj;
}
}
adir->SaveSelf(kTRUE);
savdir->cd();
}
示例2: MakeFlatTree
void TreeFlattener::MakeFlatTree(){
TFile* InFile = new TFile(InputFile);
TTree* InTree =(TTree*)InFile->Get(TreeName.data());
for(auto& B : BranchesToFlatten){
int status=InTree->SetBranchAddress(B.BranchName.data(),&(B.StackedBranch));
std::cout<<"Branch Set Status = "<<status<<"for branch "<<B.BranchName<<std::endl;
if(status!=0){
BranchAddressError BError(B.BranchName);
throw BError;
}
}
TFile* TOutFile = new TFile(OutputFile,"RECREATE");
TTree* NewTree = InTree->CloneTree(0);
for(auto& B : BranchesToFlatten){
std::string TypeName=B.BranchName+"/D";
NewTree->Branch(B.FlatBranchName.data(),&(B.FlatBranch),TypeName.data());
}
LoopTimer LT(0.10);
Long64_t N=InTree->GetEntries();
for(int i=0;i<N;++i){
LT.DeclareLoopStart(N);
InTree->GetEntry(i);
for(auto& B: BranchesToFlatten){
B.FlatBranch=B.StackedBranch[0];
}
NewTree->Fill();
}
NewTree->Write();
TOutFile->Close();
}
示例3: skim
void skim(){
int numSkip = 1013;
TFile* file = TFile::Open("bigFile.root");
TTree* tree = (TTree*) file->Get("T");
Long64_t nEntries = tree->GetEntries();
ULong64_t event;
tree->SetBranchAddress("event", &event);
tree->SetBranchStatus("*",1);
TFile *newfile = new TFile("skimmedTree.root","recreate");
TTree *newtree = tree->CloneTree(0);
for (Long64_t n=0; n<nEntries; n++) {
tree->GetEntry(n);
if (event % numSkip == 0) newtree->Fill();
}
newtree->Print();
newfile->Write();
delete file;
delete newfile;
}
示例4: addBranches
void addBranches(string filename = "f1420")
{
cout << "Adding branches to " << filename << endl;
/*Input************************************************************************/
// Open the input file and create the output file
TFile* infile = TFile::Open((filename+".root" ).c_str()),
* outfile = TFile::Open((filename+"_Bs0_branches.root").c_str(),"RECREATE");
// Get the input tree and create an empty output tree
TTree* intree = (TTree*)infile->Get("tree"),
* outtree = intree->CloneTree(0);
// Read the number of events in the input file
Int_t n = intree->GetEntries();
double mass;
intree->SetBranchAddress("m_b",&mass);
outtree->Branch("B_s0_M",&mass);
outtree->Branch("B_s0_LOKI_Mass",&mass);
/*Event loop*******************************************************************/
for(Int_t i = 0; i < n; i++)
{
intree->GetEntry(i);
/*Fill tree and show progress**************************************************/
outtree->Fill();
}
/*Write the output*************************************************************/
outtree->Write();
infile->Close();
outfile->Close();
return;
}
示例5: create_smalltuple
void create_smalltuple()
{
TFile *oldfile = new TFile("/afs/cern.ch/work/t/tbird/eta/pipipi/DPiPiPi_NTuple.root");
TTree *oldtree = (TTree*)oldfile->Get("subTree");
Double_t nEntries = oldtree->GetEntries();
TFile *newfile = new TFile("dataForPhiFit.root", "recreate");
TTree *newtree = oldtree->CloneTree(0);
Float_t M_12_MuMu;
oldtree->SetBranchAddress("M_12_MuMu", &M_12_MuMu);
for (Int_t i = 0; i < 100000000; i++)
{
oldtree->GetEntry(i);
if (abs(M_12_MuMu - 1020) < 100)
{
newtree->Fill();
}
}
newtree->AutoSave();
delete oldfile;
delete newfile;
}
示例6: NormalizeHwwNtuple
//*************************************************************************************************
//Main part of the macro
//*************************************************************************************************
void NormalizeHwwNtuple(const string InputFilename, const string datasetName,
const string OutputFilename, const int nsel) {
TTree* HwwTree = getTreeFromFile(InputFilename.c_str(),nsel);
assert(HwwTree);
MitNtupleEvent event(HwwTree);
Double_t normalizationWeight = getNormalizationWeight(InputFilename, datasetName);
//*************************************************************************************************
//Create new normalized tree
//*************************************************************************************************
TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE");
outputFile->cd();
TTree *normalizedTree = HwwTree->CloneTree(0);
cout << "Events in the ntuple: " << HwwTree->GetEntries() << endl;
for (int n=0; n<HwwTree->GetEntries(); n++) {
event.GetEntry(n);
event.H_weight = event.H_weight * normalizationWeight;
normalizedTree->Fill();
}
normalizedTree->Write();
outputFile->Close();
}
示例7: make_example_cfa
void make_example_cfa(TString file){
TFile fin(file);
fin.cd("cfA");
TTree *eventA = (TTree*)gDirectory->Get("eventA");
TTree *eventB = (TTree*)gDirectory->Get("eventB");
TTree *eA(eventA->CloneTree(0));
TTree *eB(eventB->CloneTree(0));
TString outname="cfa_one.root";
TFile fout(outname, "RECREATE");
fout.mkdir("cfA");
fout.cd("cfA");
eA->Write();
eB->Write();
fout.Close();
cout<<endl<<"Written "<<outname<<" with the tree structure of the cfA file."<<endl<<endl;
}
示例8: donewfile
void donewfile(){
if (newtree){
newtree->Print();
newtree->AutoSave();
newfile->Close();
}
counter_files++;
thisentries = 0;
newfile = new TFile(Form("splitted_%d.root",counter_files),"recreate");
newfile->cd();
newtree = oldtree->CloneTree(0);
}
示例9: clonefile
void clonefile(const char *filename = defaultname)
{
TString copyname("copy-");
copyname.Append(filename);
TFile f(filename);
TTree *in; f.GetObject("tree",in);
TFile copy(copyname,"RECREATE");
in->CloneTree(-1,"fast");
copy.Write();
}
示例10: CommonFiducialSkim
void CommonFiducialSkim() {
// Example of Root macro to copy a subset of a Tree to a new Tree
//gSystem->Load("$ROOTSYS/test/libEvent");
//Get old file, old tree and set top branch address
TFile *origFile = new TFile(origFileLoc.c_str());
TTree *origTree = (TTree*)origFile->Get(origTreeLoc.c_str());
//Event *event = new Event();
//origTree->SetBranchAddress("event",&event);
vector<float>* L1Muon_Etas;
origTree->SetBranchAddress("L1Muon_Etas", &L1Muon_Etas);
origTree->SetBranchStatus("*",0); //Disables All Branches
//Then enables only select branches
origTree->SetBranchStatus("Generator_Weights",1);
origTree->SetBranchStatus("L1Muon_Etas",1);
origTree->SetBranchStatus("L1Muon_Phis",1);
origTree->SetBranchStatus("L1Muon_Pts",1);
origTree->SetBranchStatus("HOReco_Etas",1);
origTree->SetBranchStatus("HOReco_Phis",1);
origTree->SetBranchStatus("HOReco_Energies",1);
origTree->SetBranchStatus("hltMu5PropToRPC1_Etas",1);
origTree->SetBranchStatus("hltMu5PropToRPC1_Phis",1);
origTree->SetBranchStatus("hltMu5PropToRPC1_Pts",1);
//origTree->SetBranchStatus("fH",1);
//Create a new file + a clone of old tree in new file
TFile *skimFile = new TFile("/data/users/cranelli/HOL1Muon/Trees/"
"Version_5_1/Skim_HOMuonTreee_Test.root",
"RECREATE");
TTree *skimTree = origTree->CloneTree(0);
Long64_t nentries = origTree->GetEntries();
for (Long64_t i=0;i<nentries; i++) {
if(i%1000==0) std::cout << i << std::endl;
origTree->GetEntry(i);
// Select Only Events with a L1Muon inside the barrel.
bool keepEvent = false;
for(unsigned int l1MuonB_index = 0; l1MuonB_index < L1Muon_Etas->size(); l1MuonB_index++){
if(fabs(L1Muon_Etas->at(l1MuonB_index)) < loose_barrel_eta) keepEvent = true;
}
if (keepEvent) skimTree->Fill();
L1Muon_Etas->clear();
}
skimTree->Print();
skimFile->Write();
//delete oldfile;
//delete newfile;
}
示例11: weightBkgMC
void weightBkgMC(TString inputFileName,TString outputFileName,float weight,TString treeName="SusyHggTree") {
float inw,outw;
bool isSherpa = (inputFileName.Index("DiPhotonJetsBox_M60_8TeV-sherpa") != -1);
int Nj;
TFile inputFile(inputFileName);
TTree* inputTree = (TTree*)inputFile.Get(treeName);
TFile outputFile(outputFileName,"RECREATE");
TTree* outputTree = inputTree->CloneTree(0);
inputTree->SetBranchAddress("pileupWeight",&inw);
inputTree->SetBranchAddress("Njets",&Nj);
outputTree->SetBranchAddress("pileupWeight",&outw);
Long64_t iEntry=-1;
if(isSherpa) {
double wSum=0;
double entries=0;
while(inputTree->GetEntry(++iEntry)) {
wSum+=getSherpaWeight(Nj);
entries++;
}
weight = weight*entries/wSum;
std::cout << "sherpa: sum of weights: " << wSum << " total entries: " << entries << std::endl;
}
iEntry=-1;
while(inputTree->GetEntry(++iEntry)) {
outw = inw*weight;
if(isSherpa) outw*=getSherpaWeight(Nj);
outputTree->Fill();
}
outputFile.cd();
outputTree->Write();
outputFile.Close();
inputFile.Close();
}
示例12: addMCWeight
void addMCWeight(TString filename, TString treename)
{
using namespace std;
cout << "adding MCWeight to:"<< filename << endl;
double scale_w;
float mcWeight;
int npv;
TFile *file = new TFile(filename,"UPDATE");
TTree *oldtree = (TTree*)file->Get(treename);
if(oldtree==NULL)
{
cout << "Could not find tree " << treeDir << "/" << treename << endl
<< "in file " << file->GetName() << endl;
return;
}
oldtree->SetBranchAddress("scale_w",&scale_w);
oldtree->SetBranchAddress("mcWeight",&mcWeight);
oldtree->SetBranchAddress("npv",&npv);
double scaleMC_w = 1.0;
TBranch *branch = oldtree->Branch("scaleMC_w",&scaleMC_w,"scaleMC_w/D");
for(int i = 0; i < oldtree->GetEntries(); i++)
{
oldtree->GetEntry(i);
double w_npv = (3.57041 + -1.49846*npv + 0.515829*npv*npv + -0.0839209*npv*npv*npv + 0.00719964*npv*npv*npv*npv + -0.000354548*npv*npv*npv*npv*npv + 1.01544e-05*npv*npv*npv*npv*npv*npv + -1.58019e-07*npv*npv*npv*npv*npv*npv*npv + 1.03663e-09*npv*npv*npv*npv*npv*npv*npv*npv);
scaleMC_w = scale_w*mcWeight*w_npv;
branch->Fill();
}
file->cd();
oldtree->CloneTree()->Write(treename, TObject::kOverwrite);
file->Close();
}
示例13: addMCWeight_data
void addMCWeight_data(TString filename, TString treename)
{
using namespace std;
cout << "Data adding MCWeight to:"<< filename << endl;
double scale_w;
float mcWeight;
TFile *file = new TFile(filename,"UPDATE");
TTree *oldtree = (TTree*)file->Get(treename);
if(oldtree==NULL)
{
cout << "Could not find tree " << treeDir << "/" << treename << endl
<< "in file " << file->GetName() << endl;
return;
}
oldtree->SetBranchAddress("scale_w",&scale_w);
oldtree->SetBranchAddress("mcWeight",&mcWeight);
double scaleMC_w = 1.0;
TBranch *branch = oldtree->Branch("scaleMC_w",&scaleMC_w,"scaleMC_w/D");
for(int i = 0; i < oldtree->GetEntries(); i++)
{
oldtree->GetEntry(i);
scaleMC_w = scale_w*mcWeight;
branch->Fill();
}
file->cd();
oldtree->CloneTree()->Write(treename, TObject::kOverwrite);
file->Close();
}
示例14: applypvalue
void applypvalue(std::string iName="BDTOutput.root") {
TFile *lFile = new TFile(iName.c_str());
TTree *lTree = (TTree*) lFile->FindObjectAny("Result");
fMVA = 0;
lTree->SetBranchAddress("bdt" ,&fMVA);
fPFType = 0;
lTree->SetBranchAddress("pftype",&fPFType);
fGenPt = 0;
lTree->SetBranchAddress("genpt" ,&fGenPt);
fPt = 0;
lTree->SetBranchAddress("pt" ,&fPt);
float *lMean = new float[6];
float *lRMS = new float[6];
computeMeanRMS(lMean,lRMS,lTree);
TFile *lOFile = new TFile("Output.root","RECREATE");
TTree *lOTree = (TTree*) lTree->CloneTree(0);
float lChi2PV = 0;
lOTree->Branch("chi2pv",&lChi2PV,"lChi2PV/F");
float lChi2PU = 0;
lOTree->Branch("chi2pu",&lChi2PU,"lChi2PU/F");
float lProb = 0;
lOTree->Branch("prob" ,&lProb ,"lProb/F" );
for(int i0 = 0; i0 < lTree->GetEntries(); i0++) {
lTree->GetEntry(i0);
lChi2PV = chi2(0,lMean,lRMS);
lChi2PU = chi2(1,lMean,lRMS);
float pP1 = TMath::Prob(lChi2PV,1.);
float pP2 = TMath::Prob(lChi2PU,1.);
lProb = pP1*(1-pP2);
lProb *= 2.;
if(lProb > 1) lProb = 1;
//if(fPFType == 1) std::cout << " --> " << lChi2PV << " -- " << pP1 << " -- " << lChi2PU << " -- " << pP2 << " -- " << -2*log(pP1/pP2) << " -- " << lProb << std::endl;
if(fPFType > 5) {
lProb = 1;
}
lOTree->Fill();
}
lOTree->Write();
}
示例15: ExtractEventNums
void ExtractEventNums(std::string inFileName, std::string outFileName)
{
std::cout << "Copying from tree: " << inFileName << std::endl;
std::cout << "Writing to: " << outFileName << std::endl;
TFile inFile(inFileName.c_str(), "READ");
TTree* inTree = static_cast<TTree*>(inFile.Get("bdttree"));
inTree->SetBranchStatus("*", 0);
inTree->SetBranchStatus("Run", 1);
inTree->SetBranchStatus("Event", 1);
inTree->SetBranchStatus("LumiSec", 1);
TFile outFile(outFileName.c_str(), "RECREATE");
TTree* outTree = static_cast<TTree*>(inTree->CloneTree());
outTree->Print();
outTree->Write();
//outFile.Write();
return;
}