StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MakePicoEvent.C
1 void MakePicoEvent(const char* inFilePath="links/P02gc.central.FullField.2001.mdst/", const char* inFileName="st_physics_2323002_raw_0127.himicro.root")
2 {
3 // Example of Root macro to copy a subset of a Tree to a new Tree
4 
5  gROOT->Reset();
6  gSystem->Load("StHiMicroEvent");
7 
8  //Get old file, old tree and set top branch address
9  char pathAndFile[150];
10  strcat(pathAndFile,inFilePath);
11  strcat(pathAndFile,inFileName);
12  cout << "PathAndFile = " << pathAndFile << endl;
13 
14  TFile *oldfile = new TFile(pathAndFile);
15 
16  TString outFileName(inFileName);
17  TString replace = ".himicro.root";
18  outFileName.ReplaceAll(replace.Data(),".hipico.root");
19  cout << "OutfileName = " << outFileName.Data() << endl;
20 
21 //Get the Tree from the File
22  TTree *oldtree = (TTree*)oldfile->Get("StHiMicroTree");
23  mHiMicroEvent = new StHiMicroEvent;
24  oldtree->SetBranchAddress("StHiMicroEvent",&mHiMicroEvent);
25  //oldtree->Print();
26 
27 //Remove the hits branch from the Tree
28  oldtree->SetBranchStatus("mHits",0);
29  oldtree->SetBranchStatus("mNHit",0);
30 
31 //Create a new file + a clone of old tree in new file
32  TFile *newfile = new TFile(outFileName.Data(),"recreate");
33  TTree *newtree = oldtree->CloneTree();
34 
35  //newtree->Print();
36  newfile->Write();
37  delete oldfile;
38  delete newfile;
39 }