{ // >> example2_1.C // takes a dipole sample reweighted with grwght1p (systematic named AxFFCCQEshape) // and a nominal z-expansion sample and plots histograms of Q2 to compare // gStyle->SetOptStat(0); //< remove statistics box // import the gst files and the weight file // TFile* f1 = TFile::Open("gntp.1.gst.root"); //< zexp file TFile* f2 = TFile::Open("gntp.ma135.gst.root"); //< dipole file TFile* f2w = TFile::Open("wght.ma135.dpl.root"); //< dipole weight file // extract the trees from the files // TTree* t1 = (TTree*) f1->Get("gst"); //< GENIE summary tree TTree* t2 = (TTree*) f2->Get("gst"); // weight file has a different tree within it // tree name is same as systematic which was reweighted // to find this, try f2w->ls() TTree* w2 = (TTree*) f2w->Get("AxFFCCQEshape"); // create histograms to fill // int nbins=8; //< number of bins in histograms TH1F* hz = new TH1F("hz","",nbins,0,1); //< bins in range (0,1), zexp sample TH1F* hdr = new TH1F("hdr","",nbins,0,1); //< to hold reweighted dipole TH1F* hdu = new TH1F("hdu","",nbins,0,1); //< to hold unweighted dipole hz->Sumw2(); hdr->Sumw2(); hdu->Sumw2(); double wsum = 0; //< hold the sum of the weights // create objects to hold data when loading // double q2z; double q2d; TArrayF* wght; TArrayF* twk; // set trees to point to data objects // > now when GetEntry is called, it puts the data in the variables below // t1->SetBranchAddress("Q2",&q2z); t2->SetBranchAddress("Q2",&q2d); w2->SetBranchAddress("weights",&wght); //< array of weights; i=0->garbage; i=1->dipole; i=2->zexp; w2->SetBranchAddress("twkdials",&twk); //< array of tweak dials; i=0->dipole; i=1->zexp; // loop over and read the trees // for(int i=0;iGetEntries();i++){ t1->GetEntry(i); t2->GetEntry(i); w2->GetEntry(i); // fill the histograms with the data hz->Fill(q2z); hdu->Fill(q2d); //< unweighted dipole histogram hdr->Fill(q2d,wght.At(2)); //< fill the dipole histogram with the weighted value wsum += wght.At(2); } // scale reweighted dipole by the average weight // hdr->Scale(t2->GetEntries()/wsum); // create canvas to plot on // TCanvas* c1 = new TCanvas("c1",""); // plot the histograms // hz->GetXaxis()->SetTitle("Q^{2}"); hz->SetLineColor(kRed); //< zexp nominal is red hz->Draw(""); hdr->SetLineColor(kBlue); //< reweighted dipole is blue hdr->Draw("psame"); hdu->SetLineColor(kBlack); //< unweighted dipole is black hdu->Draw("psame"); }