#define residual_cxx #include "residual.h" #include #include #include void residual::Loop() { // In a ROOT session, you can do: // Root > .L residual.C // Root > residual t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); // Must be at least number of events nentries = 10000; // book a histogram TH1F *residual = new TH1F("residual","residual",500,0,450000); //loop and delta t Long64_t nbytes = 0, nb = 0, iprevevt = -10; for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb; if ((residual::EvtElapsedTime-iprevevt)>0) { residual->Fill((residual::EvtElapsedTime-iprevevt)); } iprevevt = residual::EvtElapsedTime; // if (Cut(ientry) < 0) continue; } //poisson fit TF1 *f1 = new TF1("f1","[0]*TMath::Power(([1]/[2]),(x/[2]))*(TMath::Exp(-([1]/[2])))/TMath::Gamma((x/[2])+1)", 0, 450000); // func, "xmin", "xmax" f1->SetParameters(112, 1.58339e-20, 1.33478e+06); // you MUST set non-zero initial values for parameters residual->Fit("f1","R"); // "R" = fit between "xmin" and "xmax" of the "f1" // Build the difference histogram TH1F DiffHist(*(residual)); DiffHist.SetNameTitle("DiffHist", "Difference in error functions (all-fit)"); DiffHist->GetXaxis()->SetTitle("'Data'"); for ( int i = 1; i <= DiffHist->GetNbinsX(); i++ ) { DiffHist.SetBinContent(i,residual->GetBinContent(i) - f1->GetBinContent(i)); } // Plot simultaneously c = new TCanvas("Comp", "Error function comparison", 500, 600); c->Divide(1,2); c->cd(1); residual->SetLineColor(kBlue); residual->DrawCopy(); f1->SetLineColor(kRed); f1->DrawCopy("same"); c->cd(2); c->SetGridx(1); DiffHist.DrawCopy(); }