void evtime() { vector<int> runs; vector<int> marks; vector<int> mcols; runs.push_back(13893); marks.push_back(2); mcols.push_back(2); runs.push_back(14009); marks.push_back(24); mcols.push_back(4); runs.push_back(14085); marks.push_back(25); mcols.push_back(3); runs.push_back(14234); marks.push_back(5); mcols.push_back(3); runs.push_back(14434); marks.push_back(28); mcols.push_back(3); string pre = "run"; string suf = "evt.root"; double tmax = 160; double emax = 180; new TCanvas; TH1* ph = new TH2F("hevtime", "Event vs. time; Time [sec]; Event", tmax, 0, tmax, emax, 0, emax); ph->SetStats(0); ph->Draw("axis"); TLegend* pleg = new TLegend(0.65,0.15,0.85,0.37); pleg->SetBorderSize(0); for ( unsigned int isam=0; isam<runs.size(); ++isam ) { int run = runs[isam]; int icol = dsindex(run); int col = colormap(icol); ostringstream ssrun; ssrun << run; string srun = ssrun.str(); ostringstream sst0; sst0 << t0map(run); string fname = pre + srun + suf; TFile* pfile = TFile::Open(fname.c_str(), "READ"); TTree* ptree = dynamic_cast<TTree*>(pfile->Get("DXDisplay/EventTree")); ptree->SetMarkerStyle(marks[isam]); ptree->SetMarkerColor(col); cout << run << " " << col << " " << sst0.str() << endl; if ( ptree == 0 ) { cout << "Tree not found" << endl; pfile->ls(); return; } string sarg = "event:tlo-"; sarg += sst0.str(); sarg += ">>hevtime"; ptree->Draw(sarg.c_str(), "", "same"); pleg->AddEntry(ptree, srun.c_str(), "p"); } pleg->Draw(); }
void striptree(TString fileName="", Int_t nAPVs=4) { //=========================================================================== // Change the inputs //=========================================================================== //TString fileName = "Raw_Data_July1_Ped_300V"; //TString fileName = "Raw_Data_July1_Source_300V"; //TString fileName = "Raw_Data_July1_Ped_200V"; //TString fileName = "Raw_Data_Pedestal_300V"; // TString fileName = "Raw_Data_Source_300V"; // TString fileName = "Raw_Data_Sept_3_1"; // TString fileName = "Raw_Data_test_3_7"; // TString fileName = "Raw_Data_Albox_2011_03_31_1"; //-- TString fileName = "Raw_Data_04_01_AL_center_1"; // TString fileName = "Raw_Data_04_01_AL_7820_1"; //-- TString fileName = "Raw_Data_7817_04_01_1"; // TString fileName = "Raw_Data_7817_04_01_bkg_1"; //int nAPVs = 4; //TString fileName = "Raw_Data_July1_Source_200V"; //int nAPVs = 1; int nEvents = -1; // -1 means all TString dat = fileName; TString eps = fileName + "-events.eps"; TString root = fileName + "-events.root"; TFile* file = new TFile(root, "RECREATE"); //=========================================================================== // Read the data and make a 2D scatter plot //=========================================================================== ifstream in(dat); if (!in) { cout<< "File " << dat << " not found" <<endl; return; } TString comments = "vertical --> APV0, APV1, ... of event 1, ..."; TString s; while (1) { s.ReadLine(in); if (s.BeginsWith(comments)) break; } gStyle->SetOptStat(10); TString title = fileName+" ADC Counts vs Channel"; TString title32 = fileName+" ADC Counts vs Channel for 32 ch"; TH2D *h2d = new TH2D("h2d", title.Data(), nAPVs*128, 0, nAPVs*128, 200, 0, 200); TH2D *h2d32 = new TH2D("h2d32", title.Data(), 16, 0, 16, 200, 0, 200); TProfile *profile = new TProfile("profile", title32.Data(), nAPVs*128, 0, nAPVs*128); int event, apv, channel, adc; // TTree* tree = new TTree("tree", "tree"); // tree->Branch("event", &event, "event/I"); // tree->Branch("apv", &apv, "apv/I"); // tree->Branch("channel", &channel, "channel/I"); // tree->Branch("adc", &adc, "adc/I"); Int_t raw[512]; TTree* etree = new TTree("etree", "etree"); etree->Branch("raw", &raw, "raw[512]/I"); // etree->Draw("raw:Iteration$","Entry$==0") etree->SetMarkerStyle(6); etree->SetMarkerColor(2); int n = 0; while (1) { in >> s; if (!in.good()) break; if (s.BeginsWith("]DATA]")) // last line break; n++; if ((nEvents != -1) && (n > nEvents)) break; event = atoi(s.Data()); if (event%100 == 0) cout << "Processing event " << event << endl; for (int i=0; i<2; i++) in >> s; // time Int_t ichannel = 0; for (apv=1; apv<=nAPVs; apv++) { in >> s; // header + analog APV data + one tick mark int sequenceNumber = 0; TString subString = ""; int length = s.Length(); for (int j=0; j<length; j++) { char c = s[j]; if (c != ',') { subString += c; } else { if (sequenceNumber >= 12) { channel = sequenceNumber - 12; adc = atoi(subString.Data()); h2d->Fill((apv - 1) * 128 + channel + 0.5, adc); h2d32->Fill(((apv - 1) * 128 + channel)/32 + 0.5, adc); profile->Fill((apv - 1) * 128 + channel + 0.5, adc); //tree->Fill(); raw[ichannel] = adc; ++ichannel; } subString = ""; sequenceNumber++; } } } etree->Fill(); } in.close(); TCanvas *canvas = new TCanvas; canvas->Divide(1,2); canvas->cd(); canvas->cd(1); h2d->Draw(); canvas->cd(2); profile->Draw(); canvas->SaveAs(eps); // //-- TFile file(root, "RECREATE"); // h2d->Write(); // profile->Write(); // tree->Write(); // //file.Close(); cout<< "\nWrite " << etree->GetEntries() << " of tree " << etree->GetName() << " into file " << file->GetName() <<endl; cout<< "To plot strip content use e.g. etree->Draw(\"raw:Iteration$\",\"Entry$==0\")" <<endl; file->Write(); }
void process() { Int_t raw[512]; // buffer for input signal and bkg trees // buffers for output trees Int_t sig[512]; Int_t cmsig[512]; Int_t cm[16]; // pedestal const char* fbkg_name = "Raw_Data_FZ320P_05_MSSD_2_250V_K237_Pedestal.dat-events.root"; TFile* fbkg = TFile::Open(fbkg_name); if (!fbkg) cout<< "File not found: " << fbkg <<endl<<exitl; TTree* tree = (TTree*) fbkg->Get("etree"); tree->SetBranchAddress("raw", &raw); TH2* h2d = (TH2*) fbkg->Get("h2d"); new TCanvas; h2d->Draw(); TProfile* profile = (TProfile*) fbkg->Get("profile"); //new TCanvas; //profile->Draw(); Int_t pedestal[512]; for (int i=0; i<512; i++) { // pedestal[i] = profile->GetBinContent(i+1) - 0.5; // pedestal[i] = profile->GetBinContent(i+1) + 0.5; pedestal[i] = profile->GetBinContent(i+1); } // cout << "\nPedestals for every channel\n" << endl; // for (int i=0; i<512; i++) { // cout << pedestal[i] << " "; // if (i>0 && (i+1)%128==0) // cout << endl; // } cout<< "processing bkg" <<endl; // output file with tree const char* obfname = "FZ320P_05_MSSD_2-bkg.root"; TFile* obfile = TFile::Open(obfname, "recreate"); TTree* btree = new TTree("btree", "btree"); btree->Branch("sig", &sig, "sig[512]/I"); btree->Branch("cmsig", &cmsig, "cmsig[512]/I"); btree->Branch("cm", &cm, "cm[16]/I"); btree->SetMarkerStyle(6); btree->SetMarkerColor(2); for (int jentry=0; jentry<tree->GetEntries(); ++jentry) { tree->GetEvent(jentry); // sig for (int i=0; i<512; ++i) { sig[i] = raw[i] - pedestal[i]; } // calc common mode Int_t group32[32]; Int_t index32[32]; for (int igroup=0; igroup<16; ++igroup) { for (int istrip=0; istrip<32; ++istrip) // istrip is number inside group of 32 { group32[istrip] = sig[igroup*32 + istrip]; } // sort array group32 in ascending order TMath::Sort(32, group32, index32, kFALSE); Int_t median = group32[index32[14]]; cm[igroup] = median; } // subtract common mode for (int istrip=0; istrip<512; ++istrip) { Int_t igroup = istrip/32; cmsig[istrip] = sig[istrip] - cm[igroup]; } // Fill sig, cmsig, cm btree->Fill(); } obfile->Write(); ///////////////////////////////////////////////// // // signal tree // ///////////////////////////////////////////////// cout<< "processing signal" <<endl; TChain* chain = new TChain("etree"); chain->Add("Raw_Data_FZ320P_05_MSSD_250V_K237_Position_1.dat-events.root"); chain->Add("Raw_Data_FZ320P_05_MSSD_250V_K237_Position_2.dat-events.root"); chain->Add("Raw_Data_FZ320P_05_MSSD_2_250V_K237_Position_3.dat-events.root"); chain->Add("Raw_Data_FZ320P_05_MSSD_2_250V_K237_Position_4.dat-events.root"); chain->SetBranchAddress("raw", &raw); // output file with tree const char* osfname = "FZ320P_05_MSSD_2-signal.root"; TFile* osfile = TFile::Open(osfname, "recreate"); TTree* stree = new TTree("stree", "stree"); stree->Branch("sig", &sig, "sig[512]/I"); stree->Branch("cmsig", &cmsig, "cmsig[512]/I"); stree->Branch("cm", &cm, "cm[16]/I"); stree->SetMarkerStyle(6); stree->SetMarkerColor(2); for (int jentry=0; jentry<chain->GetEntries(); ++jentry) { chain->GetEvent(jentry); // sig for (int i=0; i<512; ++i) { sig[i] = raw[i] - pedestal[i]; } // calc common mode Int_t group32[32]; Int_t index32[32]; for (int igroup=0; igroup<16; ++igroup) { for (int istrip=0; istrip<32; ++istrip) // istrip is number inside group of 32 { group32[istrip] = sig[igroup*32 + istrip]; } // sort array group32 in ascending order TMath::Sort(32, group32, index32, kFALSE); Int_t median = group32[index32[14]]; cm[igroup] = median; } // subtract common mode for (int istrip=0; istrip<512; ++istrip) { Int_t igroup = istrip/32; cmsig[istrip] = sig[istrip] - cm[igroup]; } // Fill sig, cmsig, cm stree->Fill(); } osfile->Write(); //////////////////////////////////////////////////////// // // process trees // /////////////////////////////////////////////////////// cout<< "results" <<endl; Double_t a, mean, sigma; TH1F* h_sigma_bkg = new TH1F("h_sigma_bkg","CM subtr. noise for groups", 16,0,16); TH1F* h_mean_sig = new TH1F("h_mean_sig","CM subtr. signal for groups", 16,0,16); TH1F* h_SN = new TH1F("h_SN","Signal to Noise Ratio for groups", 16,0,16); new TCanvas; btree->Draw("cmsig","Iteration$>=0&&Iteration$<32"); fitgr(0,0, "Q", "goff", btree->GetHistogram()); pargaus(a,mean,sigma,"htemp"); //cout<< "mean = " << mean << " sigma = " << sigma <<endl; //-- png("FZ320P_05_MSSD_2-bkg-ex"); new TCanvas; // for (int igroup=0; igroup<16; ++igroup) { for (int igroup=0; igroup<15; ++igroup) { Int_t ch1 = igroup*32; Int_t ch2 = (igroup+1)*32; btree->Draw("cmsig",Form("Iteration$>=%d&&Iteration$<%d",ch1,ch2),""); fitgr(0,0, "", "", btree->GetHistogram()); pargaus(a,mean,sigma,"htemp"); // h_sigma_bkg->Fill(igroup, sigma); h_sigma_bkg->SetBinContent(igroup+1, sigma); } new TCanvas; h_sigma_bkg->Draw(); //-- png("FZ320P_05_MSSD_2-bkg-allgroups"); // signal new TCanvas; stree->Draw("cmsig","cmsig>8 &&Iteration$>=0&&Iteration$<32"); //-- png("FZ320P_05_MSSD_2-sig-ex"); new TCanvas; // for (int igroup=0; igroup<16; ++igroup) { for (int igroup=0; igroup<15; ++igroup) { Int_t ch1 = igroup*32; Int_t ch2 = (igroup+1)*32; stree->Draw("cmsig",Form("cmsig>8 &&Iteration$>=%d&&Iteration$<%d",ch1,ch2),""); gPad->Update(); gPad->Modified(); mean = stree->GetHistogram()->GetMean(); h_mean_sig->SetBinContent(igroup+1, mean); } new TCanvas; h_mean_sig->Draw(); //-- png("FZ320P_05_MSSD_2-signal-allgroups"); for (int igroup=0; igroup<16; ++igroup) { Double_t signal32 = h_mean_sig->GetBinContent(igroup+1); Double_t noise32 = h_sigma_bkg->GetBinContent(igroup+1); Double_t snr = 0; if (noise32 > 0) snr = signal32 / noise32; h_SN->SetBinContent(igroup+1, snr); } new TCanvas; h_SN->Draw(); //-- png("FZ320P_05_MSSD_2-SN-allgroups"); }
void pulseConvert(const char* ifname) { TFile* ifile = TFile::Open(ifname); if (!ifile) { cout<< "File not found: " << ifname <<endl; return; } TTree* itree = (TTree*) ifile->Get("pulse"); if (!itree) { cout<< "Error: could not find tree \"pulse\"" <<endl; return; } Int_t event, tc1, tc2; Float_t b1_t[1024], b1_c[4096], b2_t[1024], b2_c[4096]; Float_t* b1_c1 = b1_c; Float_t* b1_c2 = b1_c + 1024; Float_t* b1_c3 = b1_c + 2048; Float_t* b1_c4 = b1_c + 3072; Float_t* b2_c1 = b2_c; Float_t* b2_c2 = b2_c + 1024; Float_t* b2_c3 = b2_c + 2048; Float_t* b2_c4 = b2_c + 3072; itree->SetBranchAddress("event", &event); itree->SetBranchAddress("tc1", &tc1); itree->SetBranchAddress("tc2", &tc2); itree->SetBranchAddress("b1_t", &b1_t); itree->SetBranchAddress("b2_t", &b2_t); itree->SetBranchAddress("b1_c", &b1_c); itree->SetBranchAddress("b2_c", &b2_c); TFile* ofile = TFile::Open(Form("%s.pulse.root",ifname), "recreate"); // TTree* otree = new TTree("pulse", "old pulse tree"); TTree* otree = new TTree("p", "new pulse tree"); otree->SetMarkerStyle(6); otree->SetMarkerColor(2); otree->SetLineColor(2); // otree->Branch("event", &event, "event/I"); // otree->Branch("tc1", &tc1, "tc1/I"); // otree->Branch("b1_t", b1_t, "b1_t[1024]/F"); // otree->Branch("b1_c1", b1_c1, "b1_c1[1024]/F"); // otree->Branch("b1_c2", b1_c2, "b1_c2[1024]/F"); // otree->Branch("b1_c3", b1_c3, "b1_c3[1024]/F"); // otree->Branch("b1_c4", b1_c4, "b1_c4[1024]/F"); // otree->Branch("tc2", &tc2, "tc2/I"); // otree->Branch("b2_t", b2_t, "b2_t[1024]/F"); // otree->Branch("b2_c1", b2_c1, "b2_c1[1024]/F"); // otree->Branch("b2_c2", b2_c2, "b2_c2[1024]/F"); // otree->Branch("b2_c3", b2_c3, "b2_c3[1024]/F"); // otree->Branch("b2_c4", b2_c4, "b2_c4[1024]/F"); otree->Branch("event", &event, "event/I"); otree->Branch("tc1", &tc1, "tc1/I"); otree->Branch("t1", b1_t, "t1[1024]/F"); otree->Branch("c1", b1_c1, "c1[1024]/F"); otree->Branch("c2", b1_c2, "c2[1024]/F"); otree->Branch("c3", b1_c3, "c3[1024]/F"); otree->Branch("c4", b1_c4, "c4[1024]/F"); otree->Branch("tc2", &tc2, "tc2/I"); otree->Branch("t2", b2_t, "t2[1024]/F"); otree->Branch("c5", b2_c1, "c5[1024]/F"); otree->Branch("c6", b2_c2, "c6[1024]/F"); otree->Branch("c7", b2_c3, "c7[1024]/F"); otree->Branch("c8", b2_c4, "c8[1024]/F"); for (Long64_t jentry=0; jentry<itree->GetEntries(); jentry++) { if (jentry % 1000 == 0) cout<< "jentry = " << jentry <<endl; itree->LoadTree(jentry); itree->GetEntry(jentry); otree->Fill(); } cout<< "Write " << otree->GetEntries() << " events into file " << ofile->GetName() <<endl; ofile->Write(); }
void csv(TString input="tmva.csvoutput.txt", TString par1="par2", TString par2="par3", TString par3="", TString value="eventEffScaled_5") { std::cout << "Usage:" << std::endl << ".x scripts/csv.C with default arguments" << std::endl << ".x scripts/csv.C(filename, par1, par2, value)" << std::endl << std::endl << " Optional arguments:" << std::endl << " filename path to CSV file" << std::endl << " par1 name of X-parameter branch" << std::endl << " par2 name of Y-parameter branch (if empty, efficiency is drawn as a function of par1)" << std::endl << " value name of result (efficiency) branch" << std::endl << std::endl; TTree *tree = new TTree("data", "data"); tree->ReadFile(input); gStyle->SetPalette(1); gStyle->SetPadRightMargin(0.14); TCanvas *canvas = new TCanvas("csvoutput", "CSV Output", 1200, 900); tree->SetMarkerStyle(kFullDotMedium); tree->SetMarkerColor(kRed); if(par2.Length() > 0) { //tree->Draw(Form("%s:%s", par2.Data(), par1.Data())); if(par3.Length() > 0) tree->Draw(Form("%s:%s:%s:%s", par1.Data(), par2.Data(), par3.Data(), value.Data()), "", "COLZ"); //, "", "Z"); else tree->Draw(Form("%s:%s:%s", par2.Data(), par1.Data(), value.Data()), "", "COLZ"); //, "", "Z"); TH1 *histo = tree->GetHistogram(); if(!histo) return; histo->SetTitle(Form("%s with different classifier parameters", value.Data())); histo->GetXaxis()->SetTitle(Form("Classifier parameter %s", par1.Data())); histo->GetYaxis()->SetTitle(Form("Classifier parameter %s", par2.Data())); if(par3.Length() > 0) histo->GetZaxis()->SetTitle(Form("Classifier parameter %s", par3.Data())); else histo->GetZaxis()->SetTitle(""); if(par3.Length() == 0) { float x = 0; float y = 0; float val = 0; double maxVal = tree->GetMaximum(value); double minVal = tree->GetMinimum(value); tree->SetBranchAddress(par1, &x); tree->SetBranchAddress(par2, &y); tree->SetBranchAddress(value, &val); TLatex l; l.SetTextSize(0.03); Long64_t nentries = tree->GetEntries(); for(Long64_t entry=0; entry < nentries; ++entry) { tree->GetEntry(entry); l.SetTextColor(textColor(val, maxVal, minVal)); l.DrawLatex(x, y, Form("%.3f", val*100)); } } } else { tree->Draw(Form("%s:%s", value.Data(), par1.Data())); TH1 *histo = tree->GetHistogram(); if(!histo) return; histo->SetTitle(Form("%s with different classifier parameters", value.Data())); histo->GetXaxis()->SetTitle(Form("Classifier parameter %s", par1.Data())); histo->GetYaxis()->SetTitle(value); } }
void rs101_limitexample() { // -------------------------------------- // An example of setting a limit in a number counting experiment with uncertainty on background and signal // to time the macro TStopwatch t; t.Start(); // -------------------------------------- // The Model building stage // -------------------------------------- RooWorkspace* wspace = new RooWorkspace(); wspace->factory("Poisson::countingModel(obs[150,0,300], sum(s[50,0,120]*ratioSigEff[1.,0,3.],b[100]*ratioBkgEff[1.,0.,3.]))"); // counting model // wspace->factory("Gaussian::sigConstraint(ratioSigEff,1,0.05)"); // 5% signal efficiency uncertainty // wspace->factory("Gaussian::bkgConstraint(ratioBkgEff,1,0.1)"); // 10% background efficiency uncertainty wspace->factory("Gaussian::sigConstraint(gSigEff[1,0,3],ratioSigEff,0.05)"); // 5% signal efficiency uncertainty wspace->factory("Gaussian::bkgConstraint(gSigBkg[1,0,3],ratioBkgEff,0.2)"); // 10% background efficiency uncertainty wspace->factory("PROD::modelWithConstraints(countingModel,sigConstraint,bkgConstraint)"); // product of terms wspace->Print(); RooAbsPdf* modelWithConstraints = wspace->pdf("modelWithConstraints"); // get the model RooRealVar* obs = wspace->var("obs"); // get the observable RooRealVar* s = wspace->var("s"); // get the signal we care about RooRealVar* b = wspace->var("b"); // get the background and set it to a constant. Uncertainty included in ratioBkgEff b->setConstant(); RooRealVar* ratioSigEff = wspace->var("ratioSigEff"); // get uncertain parameter to constrain RooRealVar* ratioBkgEff = wspace->var("ratioBkgEff"); // get uncertain parameter to constrain RooArgSet constrainedParams(*ratioSigEff, *ratioBkgEff); // need to constrain these in the fit (should change default behavior) RooRealVar * gSigEff = wspace->var("gSigEff"); // global observables for signal efficiency RooRealVar * gSigBkg = wspace->var("gSigBkg"); // global obs for background efficiency gSigEff->setConstant(); gSigBkg->setConstant(); // Create an example dataset with 160 observed events obs->setVal(160.); RooDataSet* data = new RooDataSet("exampleData", "exampleData", RooArgSet(*obs)); data->add(*obs); RooArgSet all(*s, *ratioBkgEff, *ratioSigEff); // not necessary modelWithConstraints->fitTo(*data, RooFit::Constrain(RooArgSet(*ratioSigEff, *ratioBkgEff))); // Now let's make some confidence intervals for s, our parameter of interest RooArgSet paramOfInterest(*s); ModelConfig modelConfig(wspace); modelConfig.SetPdf(*modelWithConstraints); modelConfig.SetParametersOfInterest(paramOfInterest); modelConfig.SetNuisanceParameters(constrainedParams); modelConfig.SetObservables(*obs); modelConfig.SetGlobalObservables( RooArgSet(*gSigEff,*gSigBkg)); modelConfig.SetName("ModelConfig"); wspace->import(modelConfig); wspace->import(*data); wspace->SetName("w"); wspace->writeToFile("rs101_ws.root"); // First, let's use a Calculator based on the Profile Likelihood Ratio //ProfileLikelihoodCalculator plc(*data, *modelWithConstraints, paramOfInterest); ProfileLikelihoodCalculator plc(*data, modelConfig); plc.SetTestSize(.05); ConfInterval* lrinterval = plc.GetInterval(); // that was easy. // Let's make a plot TCanvas* dataCanvas = new TCanvas("dataCanvas"); dataCanvas->Divide(2,1); dataCanvas->cd(1); LikelihoodIntervalPlot plotInt((LikelihoodInterval*)lrinterval); plotInt.SetTitle("Profile Likelihood Ratio and Posterior for S"); plotInt.Draw(); // Second, use a Calculator based on the Feldman Cousins technique FeldmanCousins fc(*data, modelConfig); fc.UseAdaptiveSampling(true); fc.FluctuateNumDataEntries(false); // number counting analysis: dataset always has 1 entry with N events observed fc.SetNBins(100); // number of points to test per parameter fc.SetTestSize(.05); // fc.SaveBeltToFile(true); // optional ConfInterval* fcint = NULL; fcint = fc.GetInterval(); // that was easy. RooFitResult* fit = modelWithConstraints->fitTo(*data, Save(true)); // Third, use a Calculator based on Markov Chain monte carlo // Before configuring the calculator, let's make a ProposalFunction // that will achieve a high acceptance rate ProposalHelper ph; ph.SetVariables((RooArgSet&)fit->floatParsFinal()); ph.SetCovMatrix(fit->covarianceMatrix()); ph.SetUpdateProposalParameters(true); ph.SetCacheSize(100); ProposalFunction* pdfProp = ph.GetProposalFunction(); // that was easy MCMCCalculator mc(*data, modelConfig); mc.SetNumIters(20000); // steps to propose in the chain mc.SetTestSize(.05); // 95% CL mc.SetNumBurnInSteps(40); // ignore first N steps in chain as "burn in" mc.SetProposalFunction(*pdfProp); mc.SetLeftSideTailFraction(0.5); // find a "central" interval MCMCInterval* mcInt = (MCMCInterval*)mc.GetInterval(); // that was easy // Get Lower and Upper limits from Profile Calculator cout << "Profile lower limit on s = " << ((LikelihoodInterval*) lrinterval)->LowerLimit(*s) << endl; cout << "Profile upper limit on s = " << ((LikelihoodInterval*) lrinterval)->UpperLimit(*s) << endl; // Get Lower and Upper limits from FeldmanCousins with profile construction if (fcint != NULL) { double fcul = ((PointSetInterval*) fcint)->UpperLimit(*s); double fcll = ((PointSetInterval*) fcint)->LowerLimit(*s); cout << "FC lower limit on s = " << fcll << endl; cout << "FC upper limit on s = " << fcul << endl; TLine* fcllLine = new TLine(fcll, 0, fcll, 1); TLine* fculLine = new TLine(fcul, 0, fcul, 1); fcllLine->SetLineColor(kRed); fculLine->SetLineColor(kRed); fcllLine->Draw("same"); fculLine->Draw("same"); dataCanvas->Update(); } // Plot MCMC interval and print some statistics MCMCIntervalPlot mcPlot(*mcInt); mcPlot.SetLineColor(kMagenta); mcPlot.SetLineWidth(2); mcPlot.Draw("same"); double mcul = mcInt->UpperLimit(*s); double mcll = mcInt->LowerLimit(*s); cout << "MCMC lower limit on s = " << mcll << endl; cout << "MCMC upper limit on s = " << mcul << endl; cout << "MCMC Actual confidence level: " << mcInt->GetActualConfidenceLevel() << endl; // 3-d plot of the parameter points dataCanvas->cd(2); // also plot the points in the markov chain RooDataSet * chainData = mcInt->GetChainAsDataSet(); assert(chainData); std::cout << "plotting the chain data - nentries = " << chainData->numEntries() << std::endl; TTree* chain = RooStats::GetAsTTree("chainTreeData","chainTreeData",*chainData); assert(chain); chain->SetMarkerStyle(6); chain->SetMarkerColor(kRed); chain->Draw("s:ratioSigEff:ratioBkgEff","nll_MarkovChain_local_","box"); // 3-d box proportional to posterior // the points used in the profile construction RooDataSet * parScanData = (RooDataSet*) fc.GetPointsToScan(); assert(parScanData); std::cout << "plotting the scanned points used in the frequentist construction - npoints = " << parScanData->numEntries() << std::endl; // getting the tree and drawing it -crashes (very strange....); // TTree* parameterScan = RooStats::GetAsTTree("parScanTreeData","parScanTreeData",*parScanData); // assert(parameterScan); // parameterScan->Draw("s:ratioSigEff:ratioBkgEff","","goff"); TGraph2D *gr = new TGraph2D(parScanData->numEntries()); for (int ievt = 0; ievt < parScanData->numEntries(); ++ievt) { const RooArgSet * evt = parScanData->get(ievt); double x = evt->getRealValue("ratioBkgEff"); double y = evt->getRealValue("ratioSigEff"); double z = evt->getRealValue("s"); gr->SetPoint(ievt, x,y,z); // std::cout << ievt << " " << x << " " << y << " " << z << std::endl; } gr->SetMarkerStyle(24); gr->Draw("P SAME"); delete wspace; delete lrinterval; delete mcInt; delete fcint; delete data; // print timing info t.Stop(); t.Print(); }