#include #include #include "TROOT.h" #include "TFile.h" #include "TTree.h" #include "TEventList.h" #include "TCutG.h" #include "TStyle.h" #include "TH1I.h" //include (user modified) gate definitions here: //#include "CubeGate.h" using namespace std; // ** combine results of gates into one tree file **// TCutG *poscut1; void x1y1cut(){ poscut1 = new TCutG("poscut1",5); //name of gate,number of vertices poscut1->SetVarX("raw_x1"); poscut1->SetVarY("raw_y1"); poscut1->SetTitle("Graph"); poscut1->SetFillColor(1); poscut1->SetPoint(0,327,297); poscut1->SetPoint(1,1100,297); poscut1->SetPoint(2,1100,1284); poscut1->SetPoint(3,327,1284); poscut1->SetPoint(4,327,297); } void fillGates(){ x1y1cut(); } // ************************* Apply appropriate gates *********************// int CubeGate(char* datfile){ TFile *f1; TTree *tree; ifstream input; TString gates; char sortfile[300],finfile[300]; string junk; input.open(datfile); if (!input.is_open()){ cout << "Gate input file "<< datfile << " not found."<< endl; return -1; } input >> sortfile; input >> finfile; gates="poscut1"; //input >> gates; input.close(); fillGates();//defined in CubeCuts.h //get sorted tree f1 = new TFile(sortfile,"read"); if (!f1->IsOpen()){ cout << "Error: CubeGate: Sort file " << sortfile << " not found."<< endl; return -1; } tree = (TTree*)f1->Get("CubeTreeNew"); cout << "Number of entries in original tree: " << tree->GetEntries() << endl; cout << "Gates to be applied: " << gates << endl; TFile *ef=new TFile(finfile,"recreate"); TTree *smalltree=tree->CloneTree(0); smalltree->SetName("GatedTree"); TEventList *evlist=new TEventList("gatelist"); tree->Draw(">>gatelist",gates); cout << "Number of entries in gate list: " << evlist->GetN() << endl; for (int i=0;iGetN();i++){ tree->GetEntry(evlist->GetEntry(i)); smalltree->Fill(); } smalltree->Write(); cout << "Number of entries in returned tree: " << smalltree->GetEntries() << endl; delete tree; delete smalltree; delete evlist; delete f1; delete ef; return 0; }