void treegetval() { // create a simple TTree with 5 branches Int_t run, evt; Float_t x,y,z; TTree *T = new TTree("T","test friend trees"); T->Branch("Run",&run,"Run/I"); T->Branch("Event",&evt,"Event/I"); T->Branch("x",&x,"x/F"); T->Branch("y",&y,"y/F"); T->Branch("z",&z,"z/F"); TRandom r; for (Int_t i=0;i<10000;i++) { if (i < 5000) run = 1; else run = 2; evt = i; x = r.Gaus(10,1); y = r.Gaus(20,2); z = r.Landau(2,1); T->Fill(); } // Draw with option goff and generate seven variables Int_t n = T->Draw("x:y:z:Run:Event:sin(x):cos(x)","Run==1","goff"); printf("The arrays' dimension is %d\n",n); // Retrieve variables 5 et 6 Double_t *vxs = T->GetVal(5); Double_t *vxc = T->GetVal(6); // Draw with option goff and generate only one variable T->Draw("x","Run==1","goff"); // Retrieve variable 0 Double_t *vx = T->GetVal(0); // Create and draw graphs TGraph *gs = new TGraph(n,vx,vxs); TGraph *gc = new TGraph(n,vx,vxc); gs->Draw("ap"); gc->Draw("p"); }
void CalcLimit(bool useCLs=true, string inName="nEvents.txt", string outName="nLimit.txt"){ gErrorIgnoreLevel = kWarning; gSystem->SetIncludePath( "-I$ROOFITSYS/include" ); gSystem->Load("libRooFit"); // gSystem->SetIncludePath( "-I/afs/hep.wisc.edu/cern/.root/root_v5.30.00.Linux-slc5_amd64-gcc4.3/include/RooStats" ); gROOT->ProcessLine(".L ../../../StatisticalTools/RooStatsRoutines/root/roostats_cl95.C+"); string outfile(outName.c_str()); ofstream out(outfile.c_str()); if(!out) { cout << "Cannot open file " << outfile << endl; abort(); } out << setiosflags(ios::fixed) << setprecision(4) << setiosflags(ios::left); out<<"SignalCode/F:" <<"Mass/F:" <<"Lumi/F:" <<"sLumi/F:" <<"Eff/F:" <<"sEff/F:" <<"DataEvts/F:" <<"BkgEvts/F:" <<"sBkgEvts/F:" <<"ObsLimit/F:" <<"ExpLimit/F:" <<"ExpLimitP1/F:" <<"ExpLimitM1/F:" <<"ExpLimitP2/F:" <<"ExpLimitM2/F" <<endl; TTree* tree = new TTree("tree", "Number of Events"); tree->ReadFile(inName.c_str()); tree->Draw("SignalCode:Mass:Lumi:DataEvts:BkgEvts:sBkgEvts:Eff:sEff", "", "para goff"); float n = tree->GetSelectedRows(); for(int isample=0; isample<n; ++isample){ const Double_t SignalCode = tree->GetVal(0)[isample]; const Double_t mass = tree->GetVal(1)[isample]; const Double_t lumi = tree->GetVal(2)[isample]; const Double_t DataEvts = tree->GetVal(3)[isample]; const Double_t BkgEvts = tree->GetVal(4)[isample]; const Double_t sBkgEvts = tree->GetVal(5)[isample]; const Double_t Eff = tree->GetVal(6)[isample]; const Double_t sEff = tree->GetVal(7)[isample]; cout<<"Calculating limit for mass: "<<mass<<" and lumi: "<<lumi<<endl; float sLumi = sLumiFrac*lumi; Double_t obs_limit, exp_limit; Double_t exp_up, exp_down, exp_2up, exp_2down; if(useCLs){////CLs Limits //Does not work for bayesian, only works with cls LimitResult limit = roostats_limit(lumi, sLumi, Eff, sEff, BkgEvts, sBkgEvts, DataEvts, false, 0, "cls", "", 12345); cout<<"\nCompleted Limit Calc\n"; obs_limit = limit.GetObservedLimit(); exp_limit = limit.GetExpectedLimit(); exp_up = limit.GetOneSigmaHighRange(); exp_down = limit.GetOneSigmaLowRange(); exp_2up = limit.GetTwoSigmaHighRange(); exp_2down = limit.GetTwoSigmaLowRange(); }else{ ////Bayesian Limits LimitResult limit = roostats_clm (lumi, sLumi, Eff, sEff, BkgEvts, sBkgEvts); //obs_limit = limit.GetObservedLimit(); obs_limit = roostats_cl95(lumi, sLumi, Eff, sEff, BkgEvts, sBkgEvts, DataEvts, false, 0, "bayesian", ""); exp_limit = limit.GetExpectedLimit(); exp_up = limit.GetOneSigmaHighRange(); exp_down = limit.GetOneSigmaLowRange(); exp_2up = limit.GetTwoSigmaHighRange(); exp_2down = limit.GetTwoSigmaLowRange(); } out<<setprecision(1) <<SignalCode<<"\t" <<setprecision(0) <<mass<<"\t" <<lumi<<"\t" <<sLumi<<"\t" <<setprecision(4) <<Eff<<"\t" <<sEff<<"\t" <<setprecision(0) <<DataEvts<<"\t" <<setprecision(4) <<BkgEvts<<"\t" <<sBkgEvts<<"\t"; // out<<Value(obs_limit,-4)<<"\t" // <<Value(exp_limit,-4)<<"\t" // <<Value(exp_up,-4)<<"\t" // <<Value(exp_down,-4)<<"\t" // <<Value(exp_2up,-4)<<"\t" // <<Value(exp_2down,-4) // <<endl; out<<setprecision(8) <<obs_limit<<"\t" <<exp_limit<<"\t" <<exp_up<<"\t" <<exp_down<<"\t" <<exp_2up<<"\t" <<exp_2down <<endl; } out.close(); cout<<"Done\n"; return; }
void ModXSec(string inFile, string outFile, bool removeTaus=true, bool applyKFactors=true){ bool doTC = inFile.find("TC") != string::npos; cout<<"doTC is "<<doTC<<endl; TTree* tLimit = new TTree("tLimit", "Limits"); tLimit->ReadFile(inFile.c_str()); ofstream out(outFile.c_str()); if(doTC) out<<"Rho/F:"; else out<<"Mass/F:"; if(doTC){ out<<"Pi/F:"; out<<"SinX/F:"; } out<<"Xsec/F:" <<"percentError/F" <<endl; //kfactors TGraph* gK = new TGraph(20); gK->SetPoint( 0, 200,1.347); gK->SetPoint( 1, 300,1.347); gK->SetPoint( 2, 500,1.363); gK->SetPoint( 3, 700,1.351); gK->SetPoint( 4, 900,1.347); gK->SetPoint( 5,1100,1.331); gK->SetPoint( 6,1300,1.317); gK->SetPoint( 7,1500,1.293); gK->SetPoint( 8,1700,1.257); gK->SetPoint( 9,1900,1.230); gK->SetPoint( 10,2000,1.214); //Signal pdf uncertainties TGraph* gPerErr = new TGraph(20); gPerErr->SetPoint( 0, 200,2.192); gPerErr->SetPoint( 1, 300,2.192); gPerErr->SetPoint( 2, 500,2.632); gPerErr->SetPoint( 3, 700,3.070); gPerErr->SetPoint( 4, 900,3.448); gPerErr->SetPoint( 5,1100,3.771); gPerErr->SetPoint( 6,1300,4.101); gPerErr->SetPoint( 7,1500,4.339); gPerErr->SetPoint( 8,1700,4.581); gPerErr->SetPoint( 9,1900,4.846); gPerErr->SetPoint( 10,2000,4.981); if(doTC) tLimit->Draw("Rho:Xsec:Pi:SinX", "SinX > 0.32 && SinX<0.34", "para goff"); //if(doTC) tLimit->Draw("Rho:Xsec:Pi:SinX", "(280<=Rho && Rho<=300) && (150<=Pi && Pi<=160)", "para goff"); else tLimit->Draw("Mass:Xsec", "", "para goff"); float n = tLimit->GetSelectedRows(); for(int isample=0; isample<n; ++isample){ int idx=0; Double_t mass = tLimit->GetVal(idx++)[isample]; Double_t xsec = tLimit->GetVal(idx++)[isample]; Double_t pi(-1), sinx(-1); if(doTC){ pi = tLimit->GetVal(idx++)[isample]; sinx = tLimit->GetVal(idx++)[isample]; } //cout<<"For rho: "<<rho<<" the kfactor is "<<gK->Eval(rho)<<endl; //xsec *= 1e9; //convert from mb to pb if(removeTaus) xsec *= 4./9.; //convert from emt to em if(applyKFactors) xsec *= gK->Eval(mass);//apply k factor Double_t perErr = gPerErr->Eval(mass); out.precision(0) ; out.setf ( ios::fixed, ios::floatfield); out <<mass<<"\t"; if(doTC){ out.precision(0) ; out.setf ( ios::fixed, ios::floatfield); out <<pi<<"\t"; out.precision(4) ; out.setf ( ios::fixed, ios::floatfield); out <<sinx<<"\t"; } out.precision(4) ; out.setf ( ios::scientific, ios::floatfield); out <<xsec<<"\t"; out.precision(3); out.setf ( ios::fixed, ios::floatfield); out<<perErr<<"\t"; out<<endl; } }