// Some of the ROOT stuff we will need... #include #include #include #include #include // Stuff for RooFit. #include #include #include #include #include #include #include #include #include #include #include using namespace RooFit; int main(int argc, char* argv[]){ // This is our observable. RooRealVar t0("t0", "t0", -1e3, 1e3); // Let the first input be the name of the ROOT file. std::cout << "Opening the TFiles!" << std::endl; std::string ROOTFilename = argv[1]; std::string ROOTTTree = argv[2]; std::cout << ROOTTTree << std::endl; // Open said ROOT file and get the TTree (second argument). TFile* f = new TFile(ROOTFilename.c_str(), "OPEN"); TTree* t = (TTree*)f->Get(ROOTTTree.c_str()); std::cout << "Creating the observed dataset!" << std::endl; // Store the dataset into a RooDataSet with RooRealVar. // vFlag is for the cuts (i.e. Did it stop in lead?) RooRealVar tim("time", "time", -1e9, 10e9); RooRealVar cts("counts", "counts", 0, 100); RooDataSet data("data", "data", RooArgSet(tim,cts), Import(*t)); // Open the second file and get the mean as a function of time. TFile* f2 = new TFile("t0-analyzed.root", "OPEN"); TTree* t2 = (TTree*)f2->Get("mean"); // Store these in a RooRealVar. RooRealVar meanTime("meanTime", "meanTime", -1e9, 10e9); RooRealVar meanCounts("meanCounts", "meanCounts", 0, 30); std::cout << "Creating the mean dataset!" << std::endl; // Form the dataset for the mean. RooDataSet mean("mean", "mean", RooArgSet(meanTime, meanCounts), Import(*t2)); // We subtract out t0 to the time. RooFormulaVar tPrime("tPrime", "meanTime-t0", RooArgList(t0,meanTime)); RooPoisson poisson("poisson", "poisson", tPrime, meanCounts, kFALSE); RooAbsReal* nll = poisson.createNLL(data, NumCPU(2)); RooMinuit(*nll).migrad(); TCanvas* c = new TCanvas("c", "c", 400, 400); RooPlot* frame1 = t0.frame(Range(-1e3,1e3), Title("Test Likelihood")); nll->plotOn(frame1); frame1->Draw(); f->Close(); f2->Close(); c->Print("test.png"); return 0; }