#include #include #include #include #include #include #include #include #include #include using namespace std; #include "time.h" #include #include #include "TApplication.h" #include "TFile.h" #include "TTree.h" #include "dataStruct.h" int maxEvts = 10000; void createBranchFirst(firstClass *first, TTree *businessTree) { businessTree->Branch("first", first, "intOne/I:intTwo/I:floatOne/F:floatTwo/F:theta/F:cosTheta/F:sinTheta/F"); } void createBranchCoach(coachClass *coach, TTree *businessTree) { businessTree->Branch("coach", coach, "intOneI:intTwo/I:abc/F:def/F"); } int main() { const float pi = 3.1415926737; //declare the data structure businessClass business; string rootFileName = "treeTest.root"; TFile *histFile = new TFile(rootFileName.c_str(), "RECREATE"); TTree *businessTree = new TTree("business", "business"); createBranchFirst(&business.first, businessTree); createBranchCoach(&business.coach, businessTree); for (int iEvt = 0; iEvt < maxEvts; iEvt++) { business.coach.intOne = rand(); business.coach.intTwo = rand(); business.first.intOne = business.coach.intOne; business.first.intTwo = rand(); business.coach.abc = static_cast(rand()) / static_cast(RAND_MAX); business.coach.def = static_cast(rand()) / static_cast(RAND_MAX); business.first.floatOne = business.coach.def; business.first.floatTwo = business.coach.def * 2.0 * pi; business.first.theta = business.first.floatTwo; business.first.cosTheta = cos(business.first.theta); business.first.sinTheta = sin(business.first.theta); businessTree->Fill(); } businessTree->Write(); histFile->Close(); histFile->~TFile(); }