void makeReducedTrees_P(Int_t bin) { TString binStr; binStr+=bin; Double_t minQ(0.), maxQ(0.); switch(bin) { case 0: minQ = TMath::Sqrt(0.1e6); maxQ = TMath::Sqrt(0.98e6); break; case 1: minQ = TMath::Sqrt(1.1e6); maxQ = TMath::Sqrt(2.e6); break; case 2: minQ = TMath::Sqrt(2.e6); maxQ = TMath::Sqrt(3.e6); break; case 3: minQ = TMath::Sqrt(3.e6); maxQ = TMath::Sqrt(4.e6); break; case 4: minQ = TMath::Sqrt(4.e6); maxQ = TMath::Sqrt(5.e6); break; case 5: minQ = TMath::Sqrt(5.e6); maxQ = TMath::Sqrt(6.e6); break; case 6: minQ = TMath::Sqrt(6.e6); maxQ = TMath::Sqrt(7.e6); break; case 7: minQ = TMath::Sqrt(7.e6); maxQ = TMath::Sqrt(8.e6); break; case 8: minQ = TMath::Sqrt(11.e6); maxQ = TMath::Sqrt(11.75e6); break; case 9: minQ = TMath::Sqrt(11.75e6); maxQ = TMath::Sqrt(12.5e6); break; case 10: minQ = TMath::Sqrt(15.e6); maxQ = TMath::Sqrt(16.e6); break; case 11: minQ = TMath::Sqrt(16.e6); maxQ = TMath::Sqrt(17.e6); break; case 12: minQ = TMath::Sqrt(17.e6); maxQ = TMath::Sqrt(18.e6); break; case 13: minQ = TMath::Sqrt(18.e6); maxQ = TMath::Sqrt(19.e6); break; case 14: minQ = TMath::Sqrt(19.e6); maxQ = TMath::Sqrt(20.e6); break; case 15: minQ = TMath::Sqrt(20.e6); maxQ = TMath::Sqrt(21.e6); break; case 16: minQ = TMath::Sqrt(21.e6); maxQ = TMath::Sqrt(22.e6); break; case 17: minQ = TMath::Sqrt(1.1e6); maxQ = TMath::Sqrt(6.e6); break; case 18: minQ = TMath::Sqrt(15.e6); maxQ = TMath::Sqrt(22.e6); break; case 19: minQ = TMath::Sqrt( 8.e6); maxQ = TMath::Sqrt(11.e6); break; case 20: minQ = TMath::Sqrt(12.5e6); maxQ = TMath::Sqrt(15.e6); break; default: return; } TFile * f = TFile::Open("/Home/dcraik/lhcb/rd/Kll/tuples/fromPatrick/Kmm.root"); TTree * tree = dynamic_cast<TTree*>(f->Get("finalTree_KMuMu")); TFile* fs = TFile::Open("fromPatrick/Kmm_Q"+binStr+"_sWeights.root"); TTree* stree = dynamic_cast<TTree*>(fs->Get("sWeights")); TFile* fn = new TFile("fromPatrick/Kmm_Q"+binStr+"_reduced.root","RECREATE"); TTree* newtree = tree->CloneTree(0); TLorentzVector mup_4mom; TLorentzVector mum_4mom; TLorentzVector Psi_4mom; TLorentzVector K_4mom; TLorentzVector B_4mom; TVector3 B_boost; TVector3 Psi_boost; TVector3 mup_boost; TVector3 mum_boost; Double_t K_PE(0.), K_PX(0.), K_PY(0.), K_PZ(0.); Double_t mup_PE(0.), mup_PX(0.), mup_PY(0.), mup_PZ(0.); Double_t mum_PE(0.), mum_PX(0.), mum_PY(0.), mum_PZ(0.); Double_t B_M(0.), Psi_M(0.); Double_t cosThetaL(0.); Double_t sWeight(0.); newtree->Branch("cosThetaL" ,&cosThetaL); newtree->Branch("sWeight" ,&sWeight); tree->SetBranchAddress("Bplus_M", &B_M); tree->SetBranchAddress("Jpsi_M", &Psi_M); tree->SetBranchAddress("Kplus_PE", &K_PE); tree->SetBranchAddress("Kplus_PX", &K_PX); tree->SetBranchAddress("Kplus_PY", &K_PY); tree->SetBranchAddress("Kplus_PZ", &K_PZ); tree->SetBranchAddress("muplus_PE", &mup_PE); tree->SetBranchAddress("muplus_PX", &mup_PX); tree->SetBranchAddress("muplus_PY", &mup_PY); tree->SetBranchAddress("muplus_PZ", &mup_PZ); tree->SetBranchAddress("muminus_PE", &mum_PE); tree->SetBranchAddress("muminus_PX", &mum_PX); tree->SetBranchAddress("muminus_PY", &mum_PY); tree->SetBranchAddress("muminus_PZ", &mum_PZ); stree->SetBranchAddress("Nsig_sw", &sWeight); Int_t i(0), is(0); Int_t n = tree->GetEntries(); Int_t ns = stree->GetEntries(); while( i<n && is<ns ) { if(is % 100 == 0) std::cout << "Entry " << is << " of " << ns << "..." << std::endl; do { ++i; if(i==n) {//i cannot iterate past n because is would have already hit ns. std::cout << "This was supposed to be impossible. The two trees don't match!" << std::endl; std::cout << is << "\t" << ns << std::endl; return; } tree->GetEntry(i); } while(B_M<5170 || B_M>5970 || Psi_M<minQ || Psi_M>maxQ); ++is; stree->GetEntry(is); //Get 4 momentum of each track K_4mom.SetPxPyPzE( K_PX/1000, K_PY/1000, K_PZ/1000, K_PE/1000); mup_4mom.SetPxPyPzE( mup_PX/1000, mup_PY/1000, mup_PZ/1000, mup_PE/1000); mum_4mom.SetPxPyPzE( mum_PX/1000, mum_PY/1000, mum_PZ/1000, mum_PE/1000); //Make 4 momenta of composites Psi_4mom = mup_4mom + mum_4mom; B_4mom = Psi_4mom + K_4mom; //boost into B frame B_boost = B_4mom.BoostVector(); Psi_4mom.Boost(-B_boost); mup_4mom.Boost(-B_boost); //Boost into Psi frame Psi_boost = Psi_4mom.BoostVector(); mup_4mom.Boost(-Psi_boost); //cosThetaL is the angle between the Psi and the mu+ in the Psi rest frame mup_boost = mup_4mom.BoostVector(); cosThetaL = Psi_boost.Dot(mup_boost)/(Psi_boost.Mag()*mup_boost.Mag()); newtree->Fill(); } std::cout << is << "\t" << ns << std::endl; newtree->AutoSave(); fn->Close(); }
RooFitResult * safeFit(RooAbsPdf * pdf, RooDataSet * data, Str2VarMap p, ISVALIDF_PTR isValid, string opt = "", int nfree = -1, RooArgSet * cons = NULL, RooAbsReal * nll = NULL) { RooFitResult * res = NULL; RooRealVar cosThetaL("cosThetaL","cosThetaL",0.,-1.,1.); RooRealVar cosThetaB("cosThetaB","cosThetaB",0.,-1.,1.); RooArgSet obs(cosThetaL,cosThetaB); //if(opt.find("-scan")==string::npos) res = pdf->fitTo(*data,PrintLevel(-1),Save(),Extended(true)); if(p.size()==1 && p.find("afb") != p.end()) p["fL"] = GetParam(pdf,"fL"); else if(p.size()==1 && p.find("fL") != p.end()) p["afb"] = GetParam(pdf,"afb"); RooArgSet * nuisances = NULL; /* bool afb_iscost = false, fL_iscost = false, afbB_iscost = false; if (p.find("afb") != p.end()) { afb_iscost = ((RooRealVar*)p["afb"])->getAttribute("Constant"); ((RooRealVar*)p["afb"])->setConstant(); } if (p.find("fL") != p.end()) { fL_iscost = ((RooRealVar*)p["fL"])->getAttribute("Constant"); ((RooRealVar*)p["fL"])->setConstant(); } if (p.find("afbB") != p.end()) { afbB_iscost = ((RooRealVar*)p["afbB"])->getAttribute("Constant"); ((RooRealVar*)p["afbB"])->setConstant(); } RooArgSet * nuisances = copyFreePars(pdf,obs); if (p.find("afb") != p.end()) ((RooRealVar*)p["afb"])->setConstant(afb_iscost); if (p.find("afbB") != p.end()) ((RooRealVar*)p["afbB"])->setConstant(afbB_iscost); if (p.find("fL") != p.end()) ((RooRealVar*)p["fL"])->setConstant(fL_iscost); */ int np = 20; if((!res || res->covQual()!=3 || res->edm() > 0.1) && opt.find("-noscan")==string::npos) { if(!nll) nll = pdf->createNLL(*data); vector < double > mins, maxs, r; Str2VarMap::iterator iter; int pp = 0; for (iter = p.begin(); iter != p.end(); iter++) { RooRealVar * curp = (RooRealVar *)iter->second; maxs.push_back(curp->getMax()); mins.push_back(curp->getMin()); r.push_back((maxs.back() - mins.back())/(double)np); pp++; } findMin(pdf,data,nll,p,mins,maxs,np,isValid,nfree,opt+"-nofit",cons,nuisances); double prec = 1e6; while (prec > 0.001) { double maxr = 0; maxs.clear(); mins.clear(); pp=0; for (iter = p.begin(); iter != p.end(); iter++) { RooRealVar * curp = (RooRealVar *)iter->second; if((curp->getVal() + r[pp]) < curp->getMax()) maxs.push_back(curp->getVal() + r[pp]); else maxs.push_back(curp->getMax()); if((curp->getVal() - r[pp]) > curp->getMin()) mins.push_back(curp->getVal() - r[pp]); else mins.push_back(curp->getMin()); r[pp] = (maxs.back() - mins.back())/(double)np; if(r[pp] > maxr) maxr = r[pp]; pp++; } prec = maxr; res = findMin(pdf,data,nll,p,mins,maxs,np,isValid,nfree,opt,cons,nuisances); } //if(!mynll) delete nll; } return res; }