#include #include #include #include using namespace std; #include #include #include #include #include #include #include #include #define MAX_TREE_EVENTS 10000 bool DONE =false; void sigHandler(int sig) { DONE = true; } int main(int narg, char *argv[]) { DRootSpy *drootspy = new DRootSpy(); signal(SIGINT, sigHandler); // Lock access to ROOT global while we access it pthread_rwlock_wrlock(gROOTSPY_RW_LOCK); // Define some histograms to file TDirectory *main = gDirectory; gDirectory->mkdir("components")->cd(); TH1D *h_px = new TH1D("px", "Momentum X-component", 500, 0.0, 10.0); TH1D *h_py = new TH1D("py", "Momentum Y-component", 500, 0.0, 10.0); TH1D *h_pz = new TH1D("pz", "Momentum Z-component", 500, 0.0, 10.0); TProfile *h_pvE = new TProfile("pvE", "Total Momentum vs. Energy", 500, 0.0, 10.0); main->cd(); //gDirectory->cd(".."); TH1D *h_E = new TH1D("E", "Energy", 500, 0.0, 10.0); TH1D *h_Mass = new TH1D("Mass", "Mass", 1000, 0.0, 2.0); TH2D *h_Mass_E = new TH2D("MassVEnergy", "Energy v. Mass", 1000, 0.0, 2.0, 500, 0.0, 10.0); // Define some local variables double px,py,pz,E,Mass; float data[100]; for(int i=0; i< 100; i++) data[i] = (float)i; // Define some trees to save TTree *T = new TTree("T", "Event Info"); T->Branch("px", &px, "px/D"); T->Branch("py", &py, "py/D"); T->Branch("pz", &pz, "pz/D"); T->Branch("E", &E, "E/D"); T->Branch("Mass", &Mass, "Mass/D"); T->Branch("data", &data, "data[100]/F"); // Set nice labels for X-axes h_px->SetXTitle("p_{x} (GeV/c)"); h_py->SetXTitle("p_{y} (GeV/c)"); h_pz->SetXTitle("p_{z} (GeV/c)"); h_E->SetXTitle("Energy (GeV)"); h_Mass->SetXTitle("mass (GeV/c^2)"); // Random number generator TRandom ran; // Release lock on ROOT global pthread_rwlock_unlock(gROOTSPY_RW_LOCK); // Loop forever while filling the hists cout<Fill(px); h_py->Fill(py); h_pz->Fill(pz); h_pvE->Fill(E,p); h_E->Fill(E); h_Mass->Fill(Mass); h_Mass_E->Fill(Mass, E); // Limit how large the TTree can get if(NeventsFill(); }else if(Nevents == MAX_TREE_EVENTS){ cout << MAX_TREE_EVENTS/1000 << "k events in tree. Only histograms will be filled from here on." << endl; } // Release lock on ROOT global pthread_rwlock_unlock(gROOTSPY_RW_LOCK); if(((++Nevents) % 100)==0){ //gDirectory->ls(); cout <<" "<