#include #include "TMath.h" #include "TString.h" using namespace std; void recon_tree() { gROOT->SetBatch(kTRUE); // ROOT data file referencing variables int nph, ev, k; float y, z, x; float y_adj, z_adj; // Recon ROOT file variables int element, tot_hit_count; int hc[19]; float y_seed, z_seed; // Setting up canvas object array and histogram variables char cname[10], ctitle[10], hname[10], htitle[10]; TObjArray Clist(0); Clist.SetOwner(kTRUE); TCanvas* c; TH1F* h; cout << "Here" << endl; // Initializing canvases and histograms for TObjArray for(int a = 0; a <= 1600; a++) { sprintf(cname, "c%d", a); c = new TCanvas(cname, "multipads", 900, 700); c->Divide(4,5); for(int f = 0; f <= 19; f++) { c->cd(f); sprintf(hname, "h%d at c%d", f, a); sprintf(htitle, "hist num: %d, c%d", f, a); h = new TH1F(hname, htitle, 100, 0, 400); } Clist.Add(c); } // Opening raw data file and referencing variables within it TFile* datafile = new TFile("back_ref_20mm.root"); TTree* datatree = (TTree*)(datafile->Get("dstree")); int nentries = datatree->GetEntries(); datatree->SetBranchAddress("nph", &nph); datatree->SetBranchAddress("ev", &nph); datatree->SetBranchAddress("y", &y); datatree->SetBranchAddress("z", &z); float ph_y[1000], ph_z[1000], ph_wl[1000]; int ph_pid[1000]; datatree->SetBranchAddress("ph_y", ph_y); datatree->SetBranchAddress("ph_z", ph_z); datatree->SetBranchAddress("ph_pid", ph_pid); // Opening ROOT file for writing and setting variables for it TFile* recon_file = recon_file = TFile::Open("recon_tree.root","RECREATE"); TTree* rtree = new TTree("rtree","Data for PDF reconstruction"); rtree->Branch("element", &element, "element/I"); rtree->Branch("y_seed", &y_seed, "y_seed/F"); rtree->Branch("z_seed", &z_seed, "z_seed/F"); rtree->Branch("tot_hit_count", &tot_hit_count, "tot_hit_count/I"); rtree->Branch("hc", hc, "hc[19]/I"); // Histogram for element selection TH2F *h_p = new TH2F("h_p", "Element array", 40, -100, 100, 40, -100, 100); // Iterating over all entries in the data file for(int i = 0; i < nentries; i++) { fill_n(hc, 19, 0); // setting all elements of "hit count" array to zero tot_hit_count = 0; // setting total hit counts to zero datatree->GetEntry(i); // accessing current entry of the ROOT data file y_adj = y*10; // changing/adjusting y and z values to mm z_adj = z*10; y_seed = y_adj; z_seed = z_adj; element = h_p->FindBin(y_adj,z_adj,0); // determing the element for reconstruction based on position // Iterating over all photons absorbed in photocathode and adding them to the appropriate "hit count" for PMT for(int j = 0; j <= nph; j++) { if(ph_pid[j] <= 28 && ph_pid[j] >= 10) { k = ph_pid[j] - 10; hc[k]++; } } // Determining the total hits from the hit count array for the current event for(int l = 0; l <= 18; l++) { tot_hit_count += hc[l]; } Clist.At(element); // Selecting canvas associated with current element for event c->cd(0); // Selecting first pad of canvas, which is correlated with total hits for element h->Fill(tot_hit_count); // Filling the total hits histogram for the current element // Iterating over the subsequent canvases and filling their histograms with the current hit count for that PMT for(int b = 1; b <= 19; b++) { c->cd(b); h->Fill(hc[b]); } rtree->Fill(); } // Iterating over all canvases and drawing all histograms for(int m = 0; m <= 1600; m++) { Clist.At(m); for(int n = 0; n <= 19; n++) { c->cd(n); h->Draw(); } } /*Clist.At(10); c->cd(11); int out = h->Integral(); cout << out << endl;*/ rtree->Write(); Clist.Write(); recon_file->Close(); datafile->Close(); Clist.Delete(); cout << "Done generating recon data ROOT file" << endl; }