RcppExport SEXP fitBkgTrace( SEXP Rsig, SEXP RnFrame, SEXP RnFlow ) { SEXP rl = R_NilValue; char *exceptionMesg = NULL; try { RcppMatrix<double> sig(Rsig); int nWell = sig.rows(); int nCol = sig.cols(); int nFrame = Rcpp::as<int>(RnFrame); int nFlow = Rcpp::as<int>(RnFlow); if(nWell <= 0) { std::string exception = "Empty matrix supplied, nothing to fit\n"; exceptionMesg = copyMessageToR(exception.c_str()); } else if(nFlow*nFrame != nCol) { std::string exception = "Number of columns in signal matrix should equal nFrame * nFlow\n"; exceptionMesg = copyMessageToR(exception.c_str()); } else { RcppMatrix<int> bkg(nFrame,nFlow); for(int iFlow=0; iFlow<nFlow; iFlow++) { for(int iFrame=0, frameIndex=iFlow*nFrame; iFrame<nFrame; iFrame++, frameIndex++) { double sum=0; for(int iWell=0; iWell<nWell; iWell++) sum += sig(iWell,frameIndex); sum /= nWell; bkg(iFrame,iFlow) = sum; } } // Build result set to be returned as a list to R. RcppResultSet rs; rs.add("bkg", bkg); // Set the list to be returned to R. rl = rs.getReturnList(); // Clear allocated memory } } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
Background ra2BkgQCD() { Background bkg("QCD"); bkg.addBin( 307.40 , 18.48 , 219.93 ); bkg.addBin( 34.45 , 5.84 , 22.42 ); bkg.addBin( 1.32 , 1.15 , 0.99 ); bkg.addBin( 0.09 , 0.29 , 0.09 ); bkg.addBin( 91.68 , 10.2 , 64.65 ); bkg.addBin( 9.94 , 3.22 , 6.72 ); bkg.addBin( 0.84 , 0.91 , 0.93 ); bkg.addBin( 0.12 , 0.35 , 0.12 ); bkg.addBin( 59.00 , 7.2 , 24.93 ); bkg.addBin( 5.09 , 2.16 , 1.9 ); bkg.addBin( 0.51 , 0.67 , 0.23 ); bkg.addBin( 0.12 , 0.33 , 0.07 ); bkg.addBin( 31.17 , 5.3 , 11.96 ); bkg.addBin( 2.27 , 1.27 , 1 ); bkg.addBin( 0.24 , 0.5 , 0.13 ); bkg.addBin( 35.14 , 6.12 , 11.89 ); bkg.addBin( 2.43 , 1.37 , 1.42 ); bkg.addBin( 18.19 , 3.85 , 8.5 ); bkg.addBin( 1.85 , 1.37 , 0.97 ); bkg.addBin( 0.01 , 0.1 , 0.06 ); bkg.addBin( 13.13 , 3.4 , 5.98 ); bkg.addBin( 1.95 , 1.14 , 0.8 ); bkg.addBin( 0.15 , 0.39 , 0.11 ); bkg.addBin( 11.92 , 3.84 , 4.36 ); bkg.addBin( 1.54 , 1.31 , 0.72 ); bkg.addBin( 0.11 , 0.32 , 0.16 ); bkg.addBin( 6.82 , 2.95 , 2.54 ); bkg.addBin( 0.92 , 1.03 , 0.72 ); bkg.addBin( 0.09 , 0.29 , 0.06 ); bkg.addBin( 8.00 , 2.84 , 3.13 ); bkg.addBin( 0.83 , 0.92 , 0.56 ); bkg.addBin( 0.14 , 0.38 , 0.19 ); bkg.addBin( 0.54 , 0.69 , 0.56 ); bkg.addBin( 0.73 , 0.78 , 0.59 ); bkg.addBin( 0.54 , 0.75 , 0.52 ); bkg.addBin( 0.89 , 0.94 , 0.95 ); return bkg; }
Background ra2BkgHadT() { Background bkg("HadT"); bkg.addBin( 1683.72 , 36.26 , 164.11 ); bkg.addBin( 591.85 , 22.31 , 57.16 ); bkg.addBin( 67.60 , 6.71 , 6.59 ); bkg.addBin( 5.98 , 1.74 , 0.64 ); bkg.addBin( 191.64 , 12.42 , 19.25 ); bkg.addBin( 83.29 , 7.33 , 8.295 ); bkg.addBin( 23.65 , 3.06 , 2.32 ); bkg.addBin( 11.39 , 2.97 , 1.12 ); bkg.addBin( 66.79 , 6.82 , 7.155 ); bkg.addBin( 35.70 , 4.96 , 3.62 ); bkg.addBin( 6.60 , 2.03 , 0.66 ); bkg.addBin( 2.54 , 0.93 , 0.245 ); bkg.addBin( 22.21 , 3.24 , 2.07 ); bkg.addBin( 11.06 , 3.37 , 1.19 ); bkg.addBin( 2.76 , 1.45 , 0.315 ); bkg.addBin( 15.22 , 2.91 , 1.725 ); bkg.addBin( 6.45 , 1.84 , 0.635 ); bkg.addBin( 127.08 , 7.85 , 19.85 ); bkg.addBin( 18.56 , 3.12 , 2.895 ); bkg.addBin( 0.11 , 0.25 , 0.0215 ); bkg.addBin( 44.65 , 4.25 , 7 ); bkg.addBin( 12.76 , 2.37 , 2 ); bkg.addBin( 1.32 , 0.46 , 0.235 ); bkg.addBin( 24.02 , 3.88 , 3.82 ); bkg.addBin( 9.55 , 2.03 , 1.53 ); bkg.addBin( 0.76 , 0.53 , 0.14 ); bkg.addBin( 6.06 , 2.23 , 1.02 ); bkg.addBin( 2.93 , 1.41 , 0.5 ); bkg.addBin( 0.07 , 0.2 , 0.0225 ); bkg.addBin( 2.30 , 1.23 , 0.455 ); bkg.addBin( 2.87 , 1.13 , 0.48 ); bkg.addBin( 2.76 , 1.15 , 0.61 ); bkg.addBin( 2.68 , 0.9 , 0.59 ); bkg.addBin( 3.08 , 1 , 0.675 ); bkg.addBin( 1.32 , 0.71 , 0.345 ); bkg.addBin( 1.53 , 0.95 , 0.435 ); return bkg; }
Background ra2BkgLLep() { Background bkg("LLep"); bkg.addBin( 2210.65 , 51.93 , 421.59 ); bkg.addBin( 660.14 , 27.19 , 125.56 ); bkg.addBin( 77.34 , 9.21 , 14.83 ); bkg.addBin( 9.52 , 3.39 , 2.04 ); bkg.addBin( 277.49 , 18.93 , 53.01 ); bkg.addBin( 112.80 , 11.99 , 21.74 ); bkg.addBin( 36.11 , 6.51 , 7.27 ); bkg.addBin( 9.01 , 3.20 , 1.84 ); bkg.addBin( 103.54 , 12.15 , 20.33 ); bkg.addBin( 52.45 , 8.42 , 10.42 ); bkg.addBin( 6.95 , 2.84 , 1.41 ); bkg.addBin( 2.35 , 1.68 , 0.50 ); bkg.addBin( 31.02 , 6.49 , 6.00 ); bkg.addBin( 10.13 , 3.84 , 2.03 ); bkg.addBin( 2.28 , 1.62 , 0.49 ); bkg.addBin( 16.71 , 4.65 , 3.30 ); bkg.addBin( 9.74 , 3.69 , 2.03 ); bkg.addBin( 132.48 , 11.86 , 56.83 ); bkg.addBin( 22.01 , 4.59 , 9.40 ); bkg.addBin( 0.00 , 0.00 , 1.60 ); bkg.addBin( 55.76 , 7.82 , 24.01 ); bkg.addBin( 10.40 , 3.01 , 4.50 ); bkg.addBin( 2.87 , 2.04 , 1.42 ); bkg.addBin( 24.05 , 5.26 , 10.37 ); bkg.addBin( 7.97 , 3.02 , 3.56 ); bkg.addBin( 0.00 , 0.00 , 1.80 ); bkg.addBin( 11.53 , 4.08 , 5.05 ); bkg.addBin( 3.52 , 2.04 , 1.63 ); bkg.addBin( 0.00 , 0.00 , 1.20 ); bkg.addBin( 10.04 , 5.02 , 4.66 ); bkg.addBin( 3.21 , 2.28 , 1.54 ); bkg.addBin( 1.86 , 1.31 , 0.78 ); bkg.addBin( 4.79 , 1.96 , 2.17 ); bkg.addBin( 1.41 , 1.41 , 0.62 ); bkg.addBin( 5.08 , 2.54 , 2.36 ); bkg.addBin( 0.00 , 0.00 , 2.10 ); return bkg; }
Background ra2BkgZInv() { Background bkg("ZInv"); bkg.addBin( 1821.28 , 26.31 , 322.71 ); bkg.addBin( 993.58 , 19.78 , 175.21 ); bkg.addBin( 273.21 , 10.31 , 49.51 ); bkg.addBin( 42.01 , 4.04 , 7.59 ); bkg.addBin( 215.84 , 9.04 , 38.65 ); bkg.addBin( 124.08 , 6.96 , 22.48 ); bkg.addBin( 46.86 , 4.26 , 8.71 ); bkg.addBin( 35.29 , 3.70 , 6.46 ); bkg.addBin( 76.28 , 5.37 , 13.71 ); bkg.addBin( 39.34 , 3.92 , 7.15 ); bkg.addBin( 18.08 , 2.64 , 3.47 ); bkg.addBin( 17.81 , 2.63 , 3.31 ); bkg.addBin( 25.34 , 3.10 , 4.54 ); bkg.addBin( 16.71 , 2.55 , 3.06 ); bkg.addBin( 12.35 , 2.18 , 2.36 ); bkg.addBin( 10.51 , 1.99 , 1.91 ); bkg.addBin( 10.93 , 2.07 , 1.96 ); bkg.addBin( 22.72 , 2.78 , 5.40 ); bkg.addBin( 9.92 , 1.88 , 2.42 ); bkg.addBin( 0.70 , 0.50 , 0.23 ); bkg.addBin( 9.09 , 1.75 , 2.22 ); bkg.addBin( 4.23 , 1.22 , 1.07 ); bkg.addBin( 1.77 , 0.79 , 0.55 ); bkg.addBin( 4.37 , 1.21 , 1.06 ); bkg.addBin( 3.52 , 1.11 , 0.88 ); bkg.addBin( 1.41 , 0.70 , 0.45 ); bkg.addBin( 3.33 , 1.05 , 0.84 ); bkg.addBin( 1.42 , 0.71 , 0.35 ); bkg.addBin( 0.36 , 0.36 , 0.11 ); bkg.addBin( 1.33 , 0.67 , 0.33 ); bkg.addBin( 1.06 , 0.61 , 0.32 ); bkg.addBin( 0.00 , 0.58 , 0.48 ); bkg.addBin( 0.64 , 0.45 , 0.25 ); bkg.addBin( 0.60 , 0.43 , 0.22 ); bkg.addBin( 0.00 , 0.61 , 0.55 ); bkg.addBin( 0.00 , 0.55 , 0.45 ); return bkg; }
Background ra2BkgFullyCorrelated() { Background bkg("FullyCorrelated"); bkg.addBin(6024.9,0.,620.4); bkg.addBin(2281.0,0.,232.3); bkg.addBin( 419.7,0., 55.0); bkg.addBin( 57.6,0., 9.7); bkg.addBin( 776.9,0.,101.6); bkg.addBin( 330.2,0., 38.3); bkg.addBin( 107.5,0., 14.5); bkg.addBin( 55.8,0., 9.0); bkg.addBin( 305.7,0., 40.1); bkg.addBin( 132.6,0., 17.3); bkg.addBin( 32.2,0., 5.9); bkg.addBin( 22.8,0., 4.7); bkg.addBin( 109.8,0., 17.5); bkg.addBin( 40.2,0., 7.1); bkg.addBin( 17.6,0., 4.0); bkg.addBin( 77.6,0., 16.1); bkg.addBin( 29.6,0., 5.8); bkg.addBin( 300.5,0., 63.4); bkg.addBin( 52.4,0., 12.1); bkg.addBin( 0.8,0., 1.7); bkg.addBin( 122.6,0., 27.7); bkg.addBin( 29.3,0., 6.6); bkg.addBin( 6.1,0., 2.7); bkg.addBin( 64.4,0., 14.6); bkg.addBin( 22.6,0., 5.7); bkg.addBin( 2.3,0., 2.1); bkg.addBin( 27.7,0., 8.1); bkg.addBin( 8.8,0., 3.4); bkg.addBin( 0.5,0., 1.3); bkg.addBin( 21.5,0., 8.1); bkg.addBin( 8.0,0., 3.3); bkg.addBin( 4.8,0., 2.1); bkg.addBin( 8.7,0., 3.3); bkg.addBin( 5.8,0., 2.2); bkg.addBin( 6.9,0., 3.7); bkg.addBin( 2.4,0., 2.8); return bkg; }
int main(int argc, const char** argv){ bool ReDoCuts=false; TCut TwelveCut = "gamma_CL>0.1&&BDT_response>0.36&&piplus_MC12TuneV3_ProbNNpi>0.2&&piminus_MC12TuneV3_ProbNNpi>0.2&&Kaon_MC12TuneV3_ProbNNk>0.4"; TCut ElevenCut = "gamma_CL>0.1&&BDT_response>0.30&&piplus_MC12TuneV3_ProbNNpi>0.2&&piminus_MC12TuneV3_ProbNNpi>0.2&&Kaon_MC12TuneV3_ProbNNk>0.4"; //______________________________MAKE CUT FILE FOR 2012___________________________________ if(ReDoCuts){ DataFile MCA(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Twel,MagAll,buketap,"BDTApplied_SampleA"); DataFile MCB(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Twel,MagAll,buketap,"BDTApplied_SampleB"); TreeReader* MC12Reader= new TreeReader("DecayTree"); MC12Reader->AddFile(MCA); MC12Reader->AddFile(MCB); MC12Reader->Initialize(); TFile* MC12Cut = new TFile("CutFile12.root","RECREATE"); TTree* MC12CutTree=MC12Reader->CopyTree(TwelveCut,-1,"DecayTree"); TRandom3 *MCRand = new TRandom3(224); TH1I * MCnCands12= new TH1I("MCnCands12","MCnCands12",10,0,10); TTree*MC12SingleTree=HandyFunctions::GetSingleTree(MCRand,MC12CutTree,MCnCands12,NULL); MCnCands12->Write(); MC12SingleTree->Write(); MC12Cut->Close(); //________________________________MAKE CUT FILE FOR 2011__________________________________ DataFile MC11A(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Elev,MagAll,buketap,"BDTApplied_SampleA"); DataFile MC11B(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Elev,MagAll,buketap,"BDTApplied_SampleB"); TreeReader* MC11Reader= new TreeReader("DecayTree"); MC11Reader->AddFile(MC11A); MC11Reader->AddFile(MC11B); MC11Reader->Initialize(); TFile* MC11Cut = new TFile("CutFile11.root","RECREATE"); TTree* MC11CutTree=MC11Reader->CopyTree(ElevenCut,-1,"DecayTree"); TH1I * MCnCands11= new TH1I("MCnCands11","MCnCands11",10,0,10); TTree* MC11SingleTree=HandyFunctions::GetSingleTree(MCRand,MC11CutTree,MCnCands11,NULL); MCnCands11->Write(); MC11SingleTree->Write(); MC11Cut->Close(); //_________________________________ MAKE FLAT TREES ____________________________________ TFile* MC12Input = new TFile("CutFile12.root"); TTree* MC12InputTree=(TTree*)MC12Input->Get("DecayTree"); Float_t MCEta_Mass12[20]; MC12InputTree->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&MCEta_Mass12); Int_t isSingle12; MC12InputTree->SetBranchAddress("isSingle",&isSingle12); TFile* MC12FlatOut = new TFile("MCMinimalFile12.root","RECREATE"); TTree* MC12FlatTree = MC12InputTree->CloneTree(0); Double_t MCBu_DTFNoFix_eta_Prime_MF12; MC12FlatTree->Branch("Bu_DTFNoFix_eta_prime_MF",&MCBu_DTFNoFix_eta_Prime_MF12,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries12=MC12InputTree->GetEntries(); for(int i=0;i<Entries12;++i){ MC12InputTree->GetEntry(i); if(isSingle12==0)continue; MCBu_DTFNoFix_eta_Prime_MF12=MCEta_Mass12[0]; MC12FlatTree->Fill(); } MC12FlatTree->Write(); MC12FlatOut->Close(); TFile* MC11Input = new TFile("CutFile11.root"); TTree* MC11InputTree=(TTree*)MC11Input->Get("DecayTree"); Float_t MCEta_Mass11[20]; MC11InputTree->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&MCEta_Mass11); Int_t isSingle11; MC11InputTree->SetBranchAddress("isSingle",&isSingle11); TFile* MC11FlatOut = new TFile("MCMinimalFile11.root","RECREATE"); TTree* MC11FlatTree = MC11InputTree->CloneTree(0); Double_t MCBu_DTFNoFix_eta_Prime_MF11; MC11FlatTree->Branch("Bu_DTFNoFix_eta_prime_MF",&MCBu_DTFNoFix_eta_Prime_MF11,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries11=MC11InputTree->GetEntries(); for(int i=0;i<Entries11;++i){ MC11InputTree->GetEntry(i); if(isSingle11==0)continue; MCBu_DTFNoFix_eta_Prime_MF11=MCEta_Mass11[0]; MC11FlatTree->Fill(); } MC11FlatTree->Write(); MC11FlatOut->Close(); } //_____________________________________________LOAD ROODATASETS___________________________________ TFile* MCFlatInput12= new TFile("MCMinimalFile12.root"); TTree* MCFlatInputTree12=(TTree*)MCFlatInput12->Get("DecayTree"); TFile* MCFlatInput11= new TFile("MCMinimalFile11.root"); TTree* MCFlatInputTree11=(TTree*)MCFlatInput11->Get("DecayTree"); RooRealVar MCBMass("Bu_DTF_MF","Bu_DTF_MF",5000.0,5600.0); RooRealVar MCEtaMass("eta_prime_MM","eta_prime_MM",700.0,1200.0); RooRealVar BDT_response("BDT_response","BDT_response",-1.0,1.0); RooRealVar gamma_CL("gamma_CL","gamma_CL",0.1,1.0); RooArgSet Args(MCBMass,MCEtaMass,BDT_response,gamma_CL); RooDataSet* MCData12 = new RooDataSet("MCData12","MCData12",Args,Import(*MCFlatInputTree12)); std::cout <<" Data File 12 Loaded"<<std::endl; RooDataSet* MCData11 = new RooDataSet("MCData11","MCData11",Args,Import(*MCFlatInputTree11)); std::cout<<" Data File 11 loaded"<<std::endl; RooDataSet* MCDataAll= new RooDataSet("MCDataAll","MCDataAll",Args); MCDataAll->append(*MCData12); MCDataAll->append(*MCData11); RooPlot* massFrame = MCBMass.frame(Title("Data Import Check"),Bins(50)); MCDataAll->plotOn(massFrame); RooPlot *BDTFrame = BDT_response.frame(Title("BDT Cut Check"),Bins(50)); MCDataAll->plotOn(BDTFrame); TCanvas C; C.Divide(2,1); C.cd(1); massFrame->Draw(); C.cd(2); BDTFrame->Draw(); C.SaveAs("ImportChecks.eps"); //________________________________MAKE MCROODATACATEGORIES__________________________________ RooDataSet* MCBData=(RooDataSet*)MCDataAll->reduce(RooArgSet(MCBMass)); MCBData->Print("v"); RooDataSet* MCEtaData=(RooDataSet*)MCDataAll->reduce(RooArgSet(MCEtaMass)); MCEtaData->Print("v"); RooCategory MCMassType("MCMassType","MCMassType") ; MCMassType.defineType("B") ; MCMassType.defineType("Eta") ; // Construct combined dataset in (x,sample) RooDataSet MCcombData("MCcombData","MC combined data",Args,Index(MCMassType),Import("B",*MCBData),Import("Eta",*MCEtaData)); //=============================================== MC FIT MODEL=================================== RooRealVar Mean("Mean","Mean",5279.29,5276.0,5284.00); RooRealVar Sigma("Sigma","Sigma",20.54,17.0,24.8); RooRealVar LAlpha("LAlpha","LAlpha",-1.064,-2.5,0.0); RooRealVar RAlpha("RAlpha","RAlpha",1.88,0.0,5.0); RooRealVar LN("LN","LN",13.0,0.0,40.0); RooRealVar RN("RN","RN",2.56,0.0,6.0); RooCBShape CBLeft("CBLeft","CBLeft",MCBMass,Mean,Sigma,LAlpha,LN); RooCBShape CBRight("CBRight","CBRight",MCBMass,Mean,Sigma,RAlpha,RN); RooRealVar FitFraction("FitFraction","FitFraction",0.5,0.0,1.0); RooAddPdf DCB("DCB","DCB",RooArgList(CBRight,CBLeft),FitFraction); RooRealVar SignalYield("SignalYield","SignalYield",4338.0,500.0,10000.0); // RooExtendPdf ExtDCB("ExtDCB","ExtDCB",DCB,SignalYield); //==============================ETA DCB ++++++++++++++++++++++++++++++ RooRealVar MCEtamean("MCEtamean","MCEtamean",958.0,955.0,960.0); RooRealVar MCEtasigma("MCEtasigma","MCEtasigma",9.16,8.0,14.0); RooRealVar EtaLAlpha("EtaLAlpha","EtaLAlpha",-1.45,-5.0,1.0); RooRealVar EtaRAlpha("EtaRAlpha","EtaRAlpha",1.76,0.0,4.0); RooRealVar EtaLN("EtaLN","EtaLN",0.1,0.0,20.0); RooRealVar EtaRN("EtaRN","EtaRN",0.1,0.0,20.0); RooCBShape EtaCBLeft("EtaCBLeft","EtaCBLeft",MCEtaMass,MCEtamean,MCEtasigma,EtaLAlpha,EtaLN); RooCBShape EtaCBRight("EtaCBRight","EtaCBRight",MCEtaMass,MCEtamean,MCEtasigma,EtaRAlpha,EtaRN); RooRealVar EtaFitFraction("EtaFitFraction","EtaFitFraction",0.22,0.1,1.0); RooAddPdf EtaDCB("EteaDCB","EtaDCB",RooArgList(EtaCBRight,EtaCBLeft),EtaFitFraction); RooProdPdf MCSignalPdf("MCSignalPdf","MCSignalPdf",RooArgSet(EtaDCB,DCB)); RooExtendPdf ExtendedMCSignalPdf("ExtendedMCSignalPdf","ExtendedMCSignalPdf",MCSignalPdf,SignalYield); RooSimultaneous MCsimPdf("MCsimPdf","MC simultaneous pdf",MCMassType) ; // MCsimPdf.addPdf(ExtDCB,"B"); // MCsimPdf.addPdf(ExtendedMCEtaDCB,"Eta"); //============================== DO the MC FIT ======================================= //MCsimPdf.fitTo(MCcombData,Extended(kTRUE),Minos(kTRUE)); //ExtendedMCEtaDCB.fitTo(*MCEtaData,Extended(kTRUE),Minos(kTRUE)); //ExtDCB.fitTo(*MCBData,Extended( ExtendedMCSignalPdf.fitTo(*MCDataAll,Extended(kTRUE),Minos(kTRUE)); RooPlot* MCframe1 = MCBMass.frame(Range(5100.0,5500.0),Bins(50),Title("B mass projection")); MCDataAll->plotOn(MCframe1); ExtendedMCSignalPdf.plotOn(MCframe1); ExtendedMCSignalPdf.paramOn(MCframe1); RooPlot* MCframe2 = MCEtaMass.frame(Range(880.0,1020.0),Bins(50),Title("Eta mass projection")) ; MCDataAll->plotOn(MCframe2); ExtendedMCSignalPdf.plotOn(MCframe2); ExtendedMCSignalPdf.paramOn(MCframe2); TCanvas* MCc = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf",1200,1000) ; gPad->SetLeftMargin(0.15) ; MCframe1->GetYaxis()->SetTitleOffset(1.4) ; MCframe1->Draw() ; MCc->SaveAs("MCSimulCanvas.pdf"); TCanvas* MCcEta = new TCanvas(" Eta Canvas","Eta Canvas",1200,1000); gPad->SetLeftMargin(0.15) ; MCframe2->GetYaxis()->SetTitleOffset(1.4) ; MCframe2->Draw() ; MCcEta->SaveAs("MCEtaCanvas.pdf"); TFile* MCFits= new TFile("MCFitResult.root","RECREATE"); // TCanvas* DecMCB=HandyFunctions::DecoratePlot(MCframe1); // TCanvas* DecMCEta=HandyFunctions::DecoratePlot(MCframe2); //DecMCEta->Write(); // DecMCB->Write(); MCc->Write(); MCcEta->Write(); std::cout<<"MC Eta Chi2 = "<<MCframe2->chiSquare()<<std::endl; std::cout<<"MC B Chi2 = "<<MCframe1->chiSquare()<<std::endl; //___________________________________ CUT DOWN COLLISION DATA ______________________________ if(ReDoCuts){ DataFile TwelveA(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Twel,MagAll,buketap,"BDTApplied_SampleA"); DataFile TwelveB(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Twel,MagAll,buketap,"BDTApplied_SampleB"); DataFile ElevenA(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Elev,MagAll,buketap,"BDTApplied_SampleA"); DataFile ElevenB(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Elev,MagAll,buketap,"BDTApplied_SampleB"); TRandom3* DataRand= new TRandom3(224); TH1I* DataNCand12= new TH1I("DataNCand12","DataNCand12",10,0,10); TH1I* DataNCand11= new TH1I("DataNCand11","DataNCand11",10,0,10); TreeReader* UncutDataReader12= new TreeReader("DecayTree"); UncutDataReader12->AddFile(TwelveA); UncutDataReader12->AddFile(TwelveB); UncutDataReader12->Initialize(); TFile* CutDataFile12 = new TFile("CutDataFile12.root","RECREATE"); TTree* CutDataTree12 = UncutDataReader12->CopyTree(TwelveCut,-1,"DecayTree"); TTree* SingleCutDataTree12=HandyFunctions::GetSingleTree(DataRand,CutDataTree12,DataNCand12,NULL); SingleCutDataTree12->Write(); CutDataFile12->Close(); TreeReader* UncutDataReader11= new TreeReader("DecayTree"); UncutDataReader11->AddFile(ElevenB); UncutDataReader11->AddFile(ElevenA); UncutDataReader11->Initialize(); TFile* CutDataFile11 = new TFile("CutDataFile11.root","RECREATE"); TTree* CutDataTree11 = UncutDataReader11->CopyTree(ElevenCut,-1,"DecayTree"); TTree* SingleCutDataTree11=HandyFunctions::GetSingleTree(DataRand,CutDataTree11,DataNCand11,NULL); SingleCutDataTree11->Write(); CutDataFile11->Close(); TFile* DataInput12 = new TFile("CutDataFile12.root"); TTree* DataInputTree12=(TTree*)DataInput12->Get("DecayTree"); DataInputTree12->SetBranchStatus("*",0); DataInputTree12->SetBranchStatus("Bu_DTF_MF",1); DataInputTree12->SetBranchStatus("Bu_DTFNoFix_eta_prime_M",1); DataInputTree12->SetBranchStatus("eta_prime_MM",1); DataInputTree12->SetBranchStatus("isSingle",1); Float_t Eta_Mass12[20]; DataInputTree12->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&Eta_Mass12); Int_t isSingle12; DataInputTree12->SetBranchAddress("isSingle",&isSingle12); TFile* MinimalDataFile12 = new TFile("MinimalDataFile12.root","RECREATE"); TTree* MinimalDataTree12= DataInputTree12->CloneTree(0); Double_t Bu_DTFNoFix_eta_prime_MF12; MinimalDataTree12->Branch("Bu_DTFNoFix_eta_prime_MF",&Bu_DTFNoFix_eta_prime_MF12,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries12=DataInputTree12->GetEntries(); for(int i=0;i<Entries12;++i){ DataInputTree12->GetEntry(i); if(isSingle12==0)continue; Bu_DTFNoFix_eta_prime_MF12=Eta_Mass12[0]; MinimalDataTree12->Fill(); } MinimalDataTree12->Write(); MinimalDataFile12->Close(); TFile* DataInput11 = new TFile("CutDataFile11.root"); TTree* DataInputTree11=(TTree*)DataInput11->Get("DecayTree"); DataInputTree11->SetBranchStatus("*",0); DataInputTree11->SetBranchStatus("Bu_DTF_MF",1); DataInputTree11->SetBranchStatus("Bu_DTFNoFix_eta_prime_M",1); DataInputTree11->SetBranchStatus("eta_prime_MM",1); DataInputTree11->SetBranchStatus("isSingle",1); Float_t Eta_Mass11[20]; DataInputTree11->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&Eta_Mass11); Int_t isSingle11; DataInputTree11->SetBranchAddress("isSingle",&isSingle11); TFile* MinimalDataFile11 = new TFile("MinimalDataFile11.root","RECREATE"); TTree* MinimalDataTree11= DataInputTree11->CloneTree(0); Double_t Bu_DTFNoFix_eta_prime_MF11; MinimalDataTree11->Branch("Bu_DTFNoFix_eta_prime_MF",&Bu_DTFNoFix_eta_prime_MF11,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries11=DataInputTree11->GetEntries(); for(int i=0;i<Entries11;++i){ DataInputTree11->GetEntry(i); if(isSingle11==0)continue; Bu_DTFNoFix_eta_prime_MF11=Eta_Mass11[0]; MinimalDataTree11->Fill(); } MinimalDataTree11->Write(); MinimalDataFile11->Close(); } //___________________________________ LOAD DATA TO ROODATASET____________________________________ RooRealVar BMass("Bu_DTF_MF","Bu_DTF_MF",5000.0,5600.0); RooRealVar EtaMass("eta_prime_MM","eta_prime_MM",870.0,1050.0); RooArgSet MassArgs(BMass,EtaMass); TFile* Data12File = new TFile("MinimalDataFile12.root"); TTree* DataTree12=(TTree*)Data12File->Get("DecayTree"); RooDataSet* Data12 = new RooDataSet("Data12","Data12",MassArgs,Import(*DataTree12)); TFile* Data11File = new TFile("MinimalDataFile11.root"); TTree* DataTree11=(TTree*)Data11File->Get("DecayTree"); RooDataSet* Data11 = new RooDataSet("Data11","Data11",MassArgs,Import(*DataTree11)); RooDataSet* AllData = new RooDataSet("AllData","AllData",MassArgs); AllData->append(*Data12); AllData->append(*Data11); TCanvas ImportC; RooPlot* ImportCheck = BMass.frame(Title("ImportCheck"),Bins(50)); AllData->plotOn(ImportCheck); ImportCheck->Draw(); ImportC.SaveAs("Alldataimport.pdf"); std::cout<<" Data Loaded, Total Entries = "<<AllData->numEntries()<<std::endl; AllData->Print("v"); RooDataSet* BData=(RooDataSet*)AllData->reduce(RooArgSet(BMass)); BData->Print("v"); RooDataSet* EtaData=(RooDataSet*)AllData->reduce(RooArgSet(EtaMass)); EtaData->Print("v"); //___________________________________Fit to Eta_Prime in BMass Sidebands______________________ RooDataSet* BSidebands=(RooDataSet*)AllData->reduce(Cut("(Bu_DTF_MF>5000.0&&Bu_DTF_MF<5179.0)||(Bu_DTF_MF>5379.0&&Bu_DTF_MF<5800.0)")); TCanvas BSidebandCanvas; RooPlot* BSidebandPlot = EtaMass.frame(Title("B sidebands"),Bins(30)); BSidebands->plotOn(BSidebandPlot); BSidebandPlot->Draw(); BSidebandCanvas.SaveAs("BSidebandDataCheck.pdf"); RooRealVar BsbMean(" Mean","BsbMean",958.0,900.0,1020.0); RooRealVar BsbSigma(" Sigma","BsbSigma",19.8,10.0,40.8); RooRealVar BsbLAlpha(" Alpha","BsbLAlpha",-1.63,-10.0,0.0); // RooRealVar BsbRAlpha("BsbRAlpha","BsbRAlpha",1.47,0.0,10.0); RooRealVar BsbLN(" N","BsbLN",0.1,0.0,20.0); // RooRealVar BsbRN("BsbRN","BsbRN",0.1,0.0,20.0); RooCBShape BsbCBLeft("BsbCBLeft","BsbCBLeft",EtaMass,BsbMean,BsbSigma,BsbLAlpha,BsbLN); // RooCBShape BsbCBRight("BsbCBRight","BsbCBRight",EtaMass,BsbMean,BsbSigma,BsbRAlpha,BsbRN); // RooRealVar BsbFitFraction("BsbFitFraction","BsbFitFraction",0.5,0.0,1.0); // RooAddPdf BsbDCB("BsbDCB","BsbDCB",RooArgList(BsbCBRight,BsbCBLeft),BsbFitFraction); RooRealVar Bsbslope("Bsbslope","Bsbslope",0.5,0.0,1.0); RooRealVar BsbP2("BsbP2","BsbP2",-0.5,-1.0,0.0); RooChebychev BsbLinear("BsbLinear","BsbLinear",EtaMass,RooArgSet(Bsbslope,BsbP2)); RooRealVar BsbFitFraction("BsbFitFraction","BsbFitFraction",0.2,0.0,1.0); RooAddPdf BsbBackground("BsbBackground","BsbBackground",RooArgList(BsbLinear,BsbCBLeft),BsbFitFraction); RooRealVar BsbYield(" Yield","BsbYield",500.0,0.0,1000.0); RooExtendPdf BsbExtDCB("BsbExtDCB","BsbExtDCB",BsbCBLeft,BsbYield); BsbExtDCB.fitTo(*BSidebands,Extended(kTRUE),Minos(kTRUE)); TCanvas BSBFitCanvas; RooPlot* BSBFitPlot = EtaMass.frame(Title("Eta fit in B Sidebands"),Bins(30)); BSidebands->plotOn(BSBFitPlot); BsbExtDCB.plotOn(BSBFitPlot); BsbExtDCB.paramOn(BSBFitPlot); BSBFitPlot->Draw(); BSBFitCanvas.SaveAs("BSidebandFit.pdf"); TFile * SidebandFitFile= new TFile("SidebandFit.root","RECREATE"); BSBFitCanvas.Write(); SidebandFitFile->Close(); //___________________________________DO THE 2D FIT TO DATA___________________________________ const double PDGBMass= 5279.26; BMass.setRange("SignalWindow",PDGBMass-(3*Sigma.getVal()),PDGBMass+(3*Sigma.getVal())); RooRealVar DSignalYield("DSignalYield","DSignalYield",4000.0,0.0,10000.0); //================================= B MASS SIGNAL PDF============================== RooRealVar DMean("Mean","DMean",5279.29,5270.0,5290.00); RooRealVar DSigma("Sigma","DSigma",19.8,10.0,40.8); RooRealVar DLAlpha("DLAlpha","DLAlpha",LAlpha.getVal()); RooRealVar DRAlpha("DRAlpha","DRAlpha",RAlpha.getVal()); RooRealVar DLN("DLN","DLN",LN.getVal()); RooRealVar DRN("DRN","DRN",RN.getVal()); RooCBShape DCBLeft("DCBLeft","DCBLeft",BMass,DMean,DSigma,DLAlpha,DLN); RooCBShape DCBRight("DCBRight","DCBRight",BMass,DMean,DSigma,DRAlpha,DRN); RooRealVar DFitFraction("FitFraction","DFitFraction",0.5,0.0,1.0); RooAddPdf DDCB("DDCB","DDCB",RooArgList(DCBRight,DCBLeft),DFitFraction); //==============================B MASS BKG PDF============================== RooRealVar slope("slope","slope",-0.5,-1.0,0.0); RooChebychev bkg("bkg","Background",BMass,RooArgSet(slope)); //==============================Eta mass signal pdf================================ RooRealVar DEtamean("Etamean","DEtamean",958.0,945.0,980.0) ; RooRealVar DEtasigma("Etasigma","DEtasigma",15.0,5.0,65.0) ; RooRealVar DEtaLAlpha("DEtaLAlpha","DEtaLAlpha",EtaLAlpha.getVal()); RooRealVar DEtaRAlpha("DEtaRAlpha","DEtaRAlpha",EtaRAlpha.getVal()); RooRealVar DEtaLN("DEtaLN","DEtaLN",EtaLN.getVal()); RooRealVar DEtaRN("DEtaRN","DEtaRN",EtaRN.getVal()); RooCBShape EtaDCBLeft("EtaDCBLeft","EtaDCBLeft",EtaMass,DEtamean,DEtasigma,DEtaLAlpha,DEtaLN); RooCBShape EtaDCBRight("EtaDCBRight","EtaDCBRight",EtaMass,DEtamean,DEtasigma,DEtaRAlpha,DEtaRN); RooRealVar DEtaFitFraction("EtaFitFraction","DEtaFitFraction",0.5,0.0,1.0); RooAddPdf EtaDDCB("EtaDDCB","EtaDDCB",RooArgList(EtaDCBRight,EtaDCBLeft),DEtaFitFraction); RooProdPdf DSignalPdf("DSignalPdf","DSignalPdf",RooArgList(EtaDDCB,DDCB)); RooExtendPdf DExtSignalPdf("DExtSignalPdf","DExtSignalPdf",DSignalPdf,DSignalYield); //=============================== Eta mass bkg pdf================================== RooRealVar EtaBkgMean("EtaBkgMean","EtaBkgMean",958.0,900.0,1020.0); RooRealVar EtaBkgSigma("EtaBkgSigma","EtaBkgSigma",19.8,10.0,40.8); RooRealVar EtaBkgLAlpha("EtaBkgLAlpha","EtaBkgLAlpha",BsbLAlpha.getVal()); // RooRealVar EtaBkgRAlpha("EtaBkgRAlpha","EtaBkgRAlpha",BsbRAlpha.getVal()); RooRealVar EtaBkgLN("EtaBkgLN","EtaBkgLN",BsbLN.getVal()); // RooRealVar EtaBkgRN("EtaBkgRN","EtaBkgRN",BsbRN.getVal()); RooCBShape EtaBkgCBLeft("EtaBkgCBLeft","EtaBkgCBLeft",EtaMass,DEtamean,EtaBkgSigma,EtaBkgLAlpha,EtaBkgLN); // RooCBShape EtaBkgCBRight("EtaBkgCBRight","EtaBkgCBRight",EtaMass,DEtamean,EtaBkgSigma,EtaBkgRAlpha,EtaBkgRN); // RooRealVar EtaBkgFitFraction("EtaBkgFitFraction","EtaBkgFitFraction",0.5,0.0,1.0); // RooAddPdf EtaBkgDCB("EtaBkgDCB","EtaBkgDCB",RooArgList(EtaBkgCBRight,EtaBkgCBLeft),EtaBkgFitFraction); RooProdPdf DataBackgroundPDF("DataBackgroundPDF","DataBackgroundPDF",RooArgList(EtaBkgCBLeft,bkg)); RooRealVar DataBackgroundYield("BackgroundYield","DataBackgroundYield",500.0,0.0,10000.0); RooExtendPdf ExtDataBackgroundPDF("ExtDataBackgroundPDF","ExtDataBackgroundPDF",DataBackgroundPDF,DataBackgroundYield); RooAddPdf TotalPDF("TotalPDF","TotalPDF",RooArgList(ExtDataBackgroundPDF,DExtSignalPdf)); std::cout<<"Dependents = "<<std::endl; RooArgSet* Dependents=TotalPDF.getDependents(AllData); Dependents->Print("v"); std::cout<<"parameters= "<<std::endl; RooArgSet* parameters=TotalPDF.getParameters(AllData); parameters->Print("v"); RooCategory MassType("MassType","MassType") ; MassType.defineType("B") ; MassType.defineType("Eta") ; // Construct combined dataset in (x,sample) RooDataSet combData("combData","combined data",MassArgs,Index(MassType),Import("B",*BData),Import("Eta",*EtaData)); RooSimultaneous simPdf("simPdf","simultaneous pdf",MassType) ; // Associate model with the physics state and model_ctl with the control state // simPdf.addPdf(WholeFit,"B"); // simPdf.addPdf(WholeEtaFit,"Eta"); // simPdf.fitTo(combData,Extended(kTRUE)/*,Minos(kTRUE)*/); TotalPDF.fitTo(*AllData,Extended(kTRUE),Minos(kTRUE)); RooPlot* frame1 = BMass.frame(Bins(50),Title("B mass projection")); AllData->plotOn(frame1); TotalPDF.plotOn(frame1,Components(ExtDataBackgroundPDF),LineStyle(kDashed),LineColor(kRed)); TotalPDF.plotOn(frame1); TotalPDF.paramOn(frame1); // The same plot for the control sample slice RooPlot* frame2 = EtaMass.frame(Bins(50),Title("Eta mass projection")) ; AllData->plotOn(frame2); TotalPDF.plotOn(frame2,Components(ExtDataBackgroundPDF),LineStyle(kDashed),LineColor(kRed)); TotalPDF.plotOn(frame2); TotalPDF.paramOn(frame2); TCanvas* DecoratedCanvas =HandyFunctions::DecoratePlot(frame2); TCanvas* DataBC= new TCanvas("BCanvas","BCanvas",1200,1000) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ; TCanvas* EtaBC= new TCanvas("EtaCanvas","EtaCanvas",1200,1000) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ; DataBC->SaveAs("DataBC.pdf"); EtaBC->SaveAs("EtaBC.pdf"); TFile * DataSimulFit = new TFile("DataSimulFit.root","RECREATE"); DataBC->Write(); EtaBC->Write(); DecoratedCanvas->Write(); }
void Plot(TString var,TCut cut,TString bins,Double_t xmax,TString cutpoint){ setstyle(); TH1::SetDefaultSumw2(true); TCanvas *c2 = new TCanvas("canvas"+var+cutpoint,"canname"+var+cutpoint,800,800); TPad *mainPad = new TPad("","",0.01,0.25,0.99,0.99); mainPad->SetNumber(1); mainPad->Draw(); TPad *ratioPad = new TPad("","",0.01,0.01,0.99,0.25); ratioPad->SetNumber(2); ratioPad->Draw(); c2->cd(1); // if (cutpoint == "noHT"){ TCut cut = numpj; TCut cutData = numpjData;} // else if (cutpoint == "HT200"){ TCut cut = HT200; TCut cutData = HT200Data; }// // else if (cutpoint == "anoHT"){ TCut cut = anumpj; TCut cutData = anumpjData;} // else if (cutpoint == "aHT200"){ TCut cut = aHT200; TCut cutData = aHT200Data; } // else if (cutpoint == "HT300"){ TCut cut = HT300; TCut cutData = HT300Data;} // else if (cutpoint == "HT350"){ TCut cut = HT350; TCut cutData = HT350Data; } // else if (cutpoint == "aT"){ TCut cut = aT; TCut cutData = aTData;} // else if (cutpoint == "early"){TCut cut = earlyaT; TCut cutData = earlyaTData;} //else{cout << "ERRORRRR: BRaaaaaaaaaaaaaaaaaains" << endl; } TCut cutData = trig && hbhe && cut; TH1D* lm0 = GetHist("LM0",kRed,var,cut,bins,tLM0,cutpoint); /// cout << "lm0" << endl; TH1D* lm1 = GetHist("LM1",kRed,var,cut,bins,tLM1,cutpoint); // cout << "lm1" << endl; TH1D* qcd = GetHist("QCD_AllPtBins_7TeV_Pythia",kOrange+4,var,cut && mu_pt_hi,bins,tQCD,cutpoint); // cout << "qcd" << endl; TH1D* data = GetHist("Data",1,var,cutData,bins,tData,cutpoint); // cout << "data" << endl; TH1D* W = GetHist("Wjets_vols",kBlue,var,cut,bins,tW,cutpoint); //cout << "W" << endl; TH1D* tt = GetHist("ttbarTauola",kGreen,var,cut,bins,tTT,cutpoint); // cout << "tt" << endl; TH1D* Z = GetHist("ZJets_madgraph",kYellow,var,cut,bins,tZ,cutpoint); // cout << "Z" << endl; //TH1D* qcd_lo = GetHist("QCD_AllPtBins_7TeV_Pythia",kOrange+4,var,cut && mu_pt_lo,bins,tQCD,cutpoint); // qcd_lo->Scale(1.94); // qcd->Add(qcd_lo); // TH1D* SM = GetHist("SM",kGray+2,var,cut,binstLM0,cutpoint); lm1->SetLineStyle(2); W->Scale(1.29557302); tt->Scale(1.65789474); Z->Scale(3048./2400.); TH1::SetDefaultSumw2(true); TH1D *SM = (TH1D*)qcd->Clone(); SM->Add(Z); SM->Add(tt); SM->Add(W); //SM->SetLineColor(kGray+2); // SM->SetFillStyle(3001); // SM->SetFillColor(kGray+2); // SM->SetMarkerSize(0.); //for(int bnum = 1; bnum <9; bnum++){ // if(data->GetBinContent(bnum)>0){ // cout << "Bin Number " << bnum << " has qcd " << qcd->GetBinContent(bnum) << " and data " << data->GetBinContent(bnum) << " and SM " << SM->GetBinContent(bnum) << " and scale factor to QCD " << data->GetBinContent(bnum)/qcd->GetBinContent(bnum) << " and scale factor to SM " << data->GetBinContent(bnum)/SM->GetBinContent(bnum) << endl; // } // } c2->cd(1)->SetLogy(); // data->Draw("PE0"); SM->Draw("E"); THStack bkg("bkg","test stacked histograms"); bkg.Add(Z); bkg.Add(tt); bkg.Add(W); bkg.Add(qcd); bkg.Draw("HIST0SAME"); // data->Draw("PE0SAME"); //qcd->Draw("HIST0same"); /* W->Draw("HIST0same"); Z->Draw("HIST0same"); tt->Draw("HIST0same"); */ lm0->Draw("HIST0same"); lm0->SetLineColor(1); lm0->SetFillColor(0); lm1->Draw("HIST0same"); lm1->SetLineColor(1); lm1->SetFillColor(0); lm1->SetLineStyle(2); // data->Draw("EPSAME"); if(xmax == 1337){ double ymax=SM->GetMaximum()*12.6;} else{ double ymax=SM->GetMaximum()*10.6;} SM->GetYaxis()->SetRangeUser(0.05,ymax); if (var=="AlphaT_Lep") { data->GetXaxis()->SetRangeUser(0.,xmax);} SM->GetXaxis()->SetTitle(var); SM->SetTitle(); TLegend *leg = new TLegend(0.73803,0.591026,0.88137,0.880819); // leg->SetShadowColor(0); //leg->SetBorderSize(0); //leg->SetFillStyle(4100); leg->SetTextSize(0.04); leg->SetFillColor(0); leg->SetLineColor(0); // leg->AddEntry(data,"DATA","PL"); leg->AddEntry(qcd,"QCD","FL"); leg->AddEntry(W,"W","FL"); leg->AddEntry(Z,"Z","FL"); leg->AddEntry(tt,"TTbar","FL"); leg->AddEntry(lm0,"LM0","FL"); leg->AddEntry(lm1,"LM1","FL"); //leg->AddEntry(SM,"SM BKGD","FL"); leg->Draw("same"); TLatex *prelim = new TLatex(0.1152,0.81981,"CMS preliminary 2010"); TLatex *lumi = new TLatex(0.1015,.9403,"#scale[0.8]{#int L dt = " +luminum+ "pb^{-1}, #sqrt{s} = 7 TeV}"); prelim->SetNDC(); lumi->SetNDC(); // prelim->Draw("same"); lumi->Draw("same"); TH1D *RatioBottom = (TH1D*)SM->Clone("Ratiob"); TH1D *RatioTop = (TH1D*)data->Clone("Ratiot"); RatioTop->GetYaxis()->SetTitle("data / sim"); RatioTop->GetXaxis()->SetTitle(); RatioTop->Divide(RatioBottom); c2->cd(2); gPad->SetGridx(); gPad->SetGridy(); RatioTop->SetTitleSize(0.1, "XYZ"); RatioTop->SetTitleOffset(0.55, "X"); RatioTop->SetTitleOffset(0.3, "Y"); RatioTop->SetLabelSize(0.06,"XY"); RatioTop->GetYaxis()->SetRangeUser(-2.,4.0); RatioTop->Draw(); RatioTop->GetYaxis()->SetLabelSize(0.05); TBox *unity = new TBox(RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetFirst()), 0.89,RatioTop->GetXaxis()->GetBinLowEdge(RatioTop->GetXaxis()->GetLast()), 1.11); unity->SetLineWidth(2); unity->SetLineColor(2); unity->SetFillColor(2); unity->SetFillStyle(3002); unity->Draw(); c2->Update(); if(cutpoint == "early"){ c2->SaveAs(plots+erlee+"Muon_ND"+selec+var+"_"+cutpoint+".png"); } else if (xmax == 90003){ c2->SaveAs(plots+"Muon_ND"+selec+"_zooomed_"+var+"_"+cutpoint+".png");} else{ c2->SaveAs(plots+"Muon_ND"+ptsec++selec+var+"_"+cutpoint+".png");} c2->Close(); }
// Data void drawFits(std::string file, std::string category){ TFile *fi = TFile::Open(file.c_str()); TH1F dat("dat","dat",1,0,1); dat.SetMarkerSize(1.2); dat.SetMarkerStyle(20); dat.SetMarkerColor(1); dat.SetLineColor(1); dat.SetLineWidth(2); TH1F bkg("bkg","bkg",1,0,1); bkg.SetMarkerSize(1.2); bkg.SetMarkerStyle(kCircle); bkg.SetMarkerColor(1); bkg.SetLineColor(1); bkg.SetLineWidth(2); TH1F bkgfit("bkgfit","bkgfit",1,0,1); bkgfit.SetMarkerSize(1.2); bkgfit.SetMarkerStyle(24); bkgfit.SetMarkerColor(1); bkgfit.SetLineColor(1); bkgfit.SetLineStyle(2); bkgfit.SetLineWidth(2); TH1F datafit("datafit","datafit",1,0,1); datafit.SetMarkerSize(1.2); datafit.SetMarkerStyle(24); datafit.SetMarkerColor(1); datafit.SetLineColor(4); datafit.SetLineStyle(1); datafit.SetLineWidth(2); // MC TH1F mc("mc","mc",1,0,1); mc.SetMarkerSize(1.2); mc.SetMarkerStyle(20); mc.SetMarkerColor(1); mc.SetLineColor(1); mc.SetLineStyle(1); mc.SetLineWidth(2); TH1F mcfit("mcfit","mcfit",1,0,1); mcfit.SetMarkerSize(1.2); mcfit.SetMarkerStyle(24); mcfit.SetMarkerColor(2); mcfit.SetLineColor(2); mcfit.SetLineStyle(1); mcfit.SetLineWidth(2); std::string cats[1] = {category}; gROOT->SetBatch(1); int c = 0; //for (int c=0;c<3;c++){ TLatex *lat = new TLatex(); lat->SetNDC(); lat->SetTextSize(0.04); lat->SetTextFont(42); fi->cd(Form("category_%s",cats[c].c_str())); TLegend *ld = new TLegend(0.5,0.65,0.89,0.89);ld->SetFillColor(0); ld->AddEntry(&dat,"Data","PE1"); ld->AddEntry(&bkg,"Backgrounds","PE1"); ld->AddEntry(&datafit,"Data Fit","L"); ld->AddEntry(&bkgfit,"Backgrounds Fit","L"); singlemuon_datafit->Draw(); singlemuon_datafit->SetTitle(Form("%s category",cats[c].c_str())); lat->DrawLatex(0.7,0.92,Form("%s category",cats[c].c_str())); lat->DrawLatex(0.1,0.92,"#bf{CMS} #it{Preliminary}"); ld->Draw(); singlemuon_datafit->SaveAs(Form("data_singlemuon_%s.pdf",cats[c].c_str())); singlemuon_datafit->SaveAs(Form("data_singlemuon_%s.png",cats[c].c_str())); dimuon_datafit->Draw(); dimuon_datafit->SetTitle(Form("%s category",cats[c].c_str())); lat->DrawLatex(0.7,0.92,Form("%s category",cats[c].c_str())); lat->DrawLatex(0.1,0.92,"#bf{CMS} #it{Preliminary}"); ld->Draw(); dimuon_datafit->SaveAs(Form("data_dimuon_%s.pdf",cats[c].c_str())); dimuon_datafit->SaveAs(Form("data_dimuon_%s.png",cats[c].c_str())); TLegend *lmw = new TLegend(0.5,0.75,0.89,0.89);lmw->SetFillColor(0); lmw->AddEntry(&mc,"W(#mu#nu) + jets MC ","PE1"); lmw->AddEntry(&mcfit,"MC Fit","L"); singlemuon_mcfit->Draw(); singlemuon_mcfit->SetTitle(Form("%s category",cats[c].c_str())); lat->DrawLatex(0.7,0.92,Form("%s category",cats[c].c_str())); lat->DrawLatex(0.1,0.92,"#bf{CMS} #it{Preliminary}"); lmw->Draw(); singlemuon_mcfit->SaveAs(Form("mc_singlemuon_%s.pdf",cats[c].c_str())); singlemuon_mcfit->SaveAs(Form("mc_singlemuon_%s.png",cats[c].c_str())); TLegend *lmz = new TLegend(0.5,0.75,0.89,0.89); lmz->SetFillColor(0); lmz->AddEntry(&mc,"Z(#mu#mu) + jets MC","PE"); lmz->AddEntry(&mcfit,"MC Fit","L"); dimuon_mcfit->Draw(); dimuon_mcfit->SetTitle(Form("%s category",cats[c].c_str())); lat->DrawLatex(0.7,0.92,Form("%s category",cats[c].c_str())); lat->DrawLatex(0.1,0.92,"#bf{CMS} #it{Preliminary}"); //lat->DrawLatex(0.1,0.92,Form("%s category",cats[c].c_str())); lmz->Draw(); dimuon_mcfit->SaveAs(Form("mc_dimuon_%s.pdf",cats[c].c_str())); dimuon_mcfit->SaveAs(Form("mc_dimuon_%s.png",cats[c].c_str())); singlemuon_ratio->SetTitle(Form("%s category",cats[c].c_str())); singlemuon_ratio->SaveAs(Form("ratio_singlemuon_%s.pdf",cats[c].c_str())); singlemuon_ratio->SaveAs(Form("ratio_singlemuon_%s.png",cats[c].c_str())); dimuon_ratio->SetTitle(Form("%s category",cats[c].c_str())); dimuon_ratio->SaveAs(Form("ratio_dimuon_%s.pdf",cats[c].c_str())); dimuon_ratio->SaveAs(Form("ratio_dimuon_%s.png",cats[c].c_str())); // dimuon_mcfit->Clear(); // dimuon_datafit->Clear(); // singlemuon_mcfit->Clear(); // singlemuon_datafit->Clear(); //} }
void fitTF1(TCanvas *canvas, TH1F h, double XMIN_, double XMAX_, double dX_, double params[], Color_t LC_=kBlack) { //double& FWHM_, double& x0_, double& x1_, double& x2_, double& y0_, double& y1_, double& INT_, double& YIELD_) { //TCanvas* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) { //TF1* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) { gROOT->ForceStyle(); RooMsgService::instance().setSilentMode(kTRUE); for(int i=0;i<2;i++) RooMsgService::instance().setStreamStatus(i,kFALSE); //TCanvas *canvas = new TCanvas(TString::Format("canvas_%s",h.GetName()),TString::Format("canvas_%s",h.GetName()),1800,1200); RooDataHist *RooHistFit = 0; RooAddPdf *model = 0; RooWorkspace w = RooWorkspace("w","workspace"); RooRealVar x("mbbReg","mbbReg",XMIN_,XMAX_); RooRealVar kJES("CMS_scale_j","CMS_scale_j",1,0.9,1.1); RooRealVar kJER("CMS_res_j","CMS_res_j",1,0.8,1.2); kJES.setConstant(kTRUE); kJER.setConstant(kTRUE); TString hname = h.GetName(); RooHistFit = new RooDataHist("fit_"+hname,"fit_"+hname,x,&h); RooRealVar YieldVBF = RooRealVar("yield_"+hname,"yield_"+hname,h.Integral()); RooRealVar m("mean_"+hname,"mean_"+hname,125,100,150); RooRealVar s("sigma_"+hname,"sigma_"+hname,12,3,30); RooFormulaVar mShift("mShift_"+hname,"@0*@1",RooArgList(m,kJES)); RooFormulaVar sShift("sShift_"+hname,"@0*@1",RooArgList(m,kJER)); RooRealVar a("alpha_"+hname,"alpha_"+hname,1,-10,10); RooRealVar n("exp_"+hname,"exp_"+hname,1,0,100); RooRealVar b0("b0_"+hname,"b0_"+hname,0.5,0.,1.); RooRealVar b1("b1_"+hname,"b1_"+hname,0.5,0.,1.); RooRealVar b2("b2_"+hname,"b2_"+hname,0.5,0.,1.); RooRealVar b3("b3_"+hname,"b3_"+hname,0.5,0.,1.); RooBernstein bkg("signal_bkg_"+hname,"signal_bkg_"+hname,x,RooArgSet(b0,b1,b2)); RooRealVar fsig("fsig_"+hname,"fsig_"+hname,0.7,0.0,1.0); RooCBShape sig("signal_gauss_"+hname,"signal_gauss_"+hname,x,mShift,sShift,a,n); model = new RooAddPdf("signal_model_"+hname,"signal_model_"+hname,RooArgList(sig,bkg),fsig); //RooFitResult *res = model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); //res->Print(); //model->Print(); canvas->cd(); canvas->SetTopMargin(0.1); RooPlot *frame = x.frame(); // no scale RooHistFit->plotOn(frame); model->plotOn(frame,RooFit::LineColor(LC_),RooFit::LineWidth(2));//,RooFit::LineStyle(kDotted)); model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(LC_),RooFit::LineWidth(2),RooFit::LineStyle(kDashed)); // with scale // RooHistFit->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent)); // model->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent),RooFit::LineWidth(1)); // model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(kBlue),RooFit::LineWidth(1),RooFit::LineStyle(kDashed),RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent)); frame->GetXaxis()->SetLimits(50,200); frame->GetXaxis()->SetNdivisions(505); frame->GetXaxis()->SetTitle("M_{b#bar{b}} (GeV)"); frame->GetYaxis()->SetTitle("Events"); frame->Draw(); h.SetFillColor(kGray); h.Draw("hist,same"); frame->Draw("same"); gPad->RedrawAxis(); TF1 *tmp = model->asTF(x,fsig,x); //tmp->Print(); double y0_ = tmp->GetMaximum(); double x0_ = tmp->GetMaximumX(); double x1_ = tmp->GetX(y0_/2.,XMIN_,x0_); double x2_ = tmp->GetX(y0_/2.,x0_,XMAX_); double FWHM_ = x2_-x1_; double INT_ = tmp->Integral(XMIN_,XMAX_); double YIELD_= YieldVBF.getVal(); double y1_ = dX_*0.5*y0_*(YieldVBF.getVal()/tmp->Integral(XMIN_,XMAX_)); params[0] = x0_; params[1] = x1_; params[2] = x2_; params[3] = y0_; params[4] = y1_; params[5] = FWHM_; params[6] = INT_; params[7] = YIELD_; //cout<<"Int = "<<tmp->Integral(XMIN_,XMAX_)<<", Yield = "<<YieldVBF.getVal()<<", y0 = "<<y0_<<", y1 = "<<y1_ <<", x0 = "<< x0_ << ", x1 = "<<x1_<<", x2 = "<<x2_<<", FWHM = "<<FWHM_<<endl; TLine ln = TLine(x1_,y1_,x2_,y1_); ln.SetLineColor(kMagenta+3); ln.SetLineStyle(7); ln.SetLineWidth(2); ln.Draw(); canvas->Update(); canvas->SaveAs("testC.png"); // tmp->Delete(); // frame->Delete(); // res->Delete(); // TF1 *f1 = model->asTF(x,fsig,x); // return f1; ////tmp->Delete(); ////ln->Delete(); ////model->Delete(); ////RooHistFit->Delete(); ////w->Delete(); ////YieldVBF->Delete(); ////frame->Delete(); ////res->Delete(); //delete tmp; //delete ln; //delete model; //delete RooHistFit; //delete w; //delete YieldVBF; //delete frame; //delete res; // return canvas; }
/*--------------------------------------------------------*/ int main(int argc, char *argv[]) { char **newheader, *imffname, *parfname, *psffname, *reffname, *instrname, *fieldname, *outfname, *coofname, **diffiles, **imfiles, **kerfiles; int nx0, ny0, k, *sector, nim, iim, npsf, ipsf, hsize, isec_x, isec_y, *cx, *cy, psfn, kern, irad, // ofs, *vnum, i; float *im, *difim, *refim; double **wxy, *x, *y, *xs, *ys, **psfs, *psfim, *kerim, ratio; STAR **obj, *objp; PSF_STRUCT psf; KER_STRUCT ker; PAR_STRUCT par; /*** IO stuff ***/ if (argc != 7) { printf("\n\tUSAGE: phot parameter_file instrument_file"); printf(" ref_image psf_fit_file image_data_list field_name\n"); exit(1); } parfname= argv[1]; instrname=argv[2]; reffname= argv[3]; psffname= argv[4]; imffname= argv[5]; fieldname=argv[6]; get_params(parfname, instrname, &par); if (par.verbose) printf("\n\n*** Profile photometry with variable PSF and kernel ***\n\n"); if (!(outfname=(char *)calloc(strlen(fieldname)+5, sizeof(char)))) errmess("calloc(outfname)"); strcpy(outfname, fieldname); strcat(outfname, ".db"); if (!(coofname=(char *)calloc(strlen(fieldname)+5, sizeof(char)))) errmess("calloc(coofname)"); strcpy(coofname, fieldname); strcat(coofname, ".coo"); /*** read filenames for difference images, images and kernel fits ***/ nim=readfnames(imffname, &diffiles, &imfiles, &kerfiles); if (par.verbose) printf("%d images to process\n", nim); /*** read coordinates of variables ***/ npsf=readcoo(coofname, &vnum, &x, &y); if (par.verbose) printf("%d variables to measure\n\n", npsf); /*** read in psf fit and get a sample kernel from the first image ***/ read_psf(psffname, &psf); read_kernel(kerfiles[0], &ker, 1, par.verbose); psf.normrad = par.normrad; psf.hw += ker.hw; psfn = 2*psf.hw + 1; kern = 2*ker.hw + 1; /*** get memory ***/ if (!(ker.vecs = (double **)malloc(ker.nvecs*sizeof(double *)))) errmess("malloc(ker.vecs)"); for (k=0; k<ker.nvecs; k++) if (!(ker.vecs[k] = (double *)malloc(kern*kern*sizeof(double)))) errmess("malloc(ker.vecs[k])"); if (!(sector=(int *)malloc(npsf*sizeof(int)))) errmess("malloc(sector)"); if (!(cx= (int *)malloc(npsf*sizeof(int)))) errmess("malloc(cx)"); if (!(cy= (int *)malloc(npsf*sizeof(int)))) errmess("malloc(cy)"); if (!(xs= (double *)malloc(npsf*sizeof(double)))) errmess("malloc(xs)"); if (!(ys= (double *)malloc(npsf*sizeof(double)))) errmess("malloc(ys)"); if (!(wxy=(double **)malloc(npsf*sizeof(double *)))) errmess("malloc(wxy)"); if (!(psfs=(double **)malloc(npsf*sizeof(double *)))) errmess("malloc(psfs)"); if (!(kerim=(double *)malloc(kern*kern*sizeof(double)))) errmess("malloc(kerim)"); if (!(psfim=(double *)malloc(psfn*psfn*sizeof(double)))) errmess("malloc(psfim)"); if (!(obj=(STAR **)malloc(npsf*sizeof(STAR *)))) errmess("malloc(obj)"); /***********************************************************************/ /** get things that can be done once for all: spatial coeffs and psfs **/ /***********************************************************************/ for (ipsf=0; ipsf<npsf; ipsf++) { if (!(obj[ipsf]=(STAR *)malloc(nim*sizeof(STAR)))) errmess("malloc(obj[ipsf])"); if (!(wxy[ipsf]=(double *)malloc(ker.nwxy*sizeof(double)))) errmess("malloc(wxy[ipsf])"); if (!(psfs[ipsf]=(double *)malloc(psfn*psfn*sizeof(double)))) errmess("malloc(psfs[ipsf])"); /* offsets for image sectors from kernel fit */ cx[ipsf]=(int)floor(x[ipsf]+0.5); cy[ipsf]=(int)floor(y[ipsf]+0.5); isec_x=(cx[ipsf] - ker.hw)/(ker.nx - 2*ker.hw); isec_y=(cy[ipsf] - ker.hw)/(ker.ny - 2*ker.hw); xs[ipsf]=x[ipsf] - isec_x*(ker.nx - 2*ker.hw); ys[ipsf]=y[ipsf] - isec_y*(ker.ny - 2*ker.hw); sector[ipsf]=isec_y + ker.nsec_y*isec_x; spatial_coeffs(&ker, xs[ipsf], ys[ipsf], wxy[ipsf]); init_psf(&psf, x[ipsf], y[ipsf]); make_psf(&psf, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], psfs[ipsf]); } refim=read_FITS_2D1file(reffname, 's', &hsize, &newheader, &nx0, &ny0); for (i=0; i<hsize; i++) free(newheader[i]); free(newheader); make_vectors(&ker); par.nx0=nx0; par.ny0=ny0; par.psfhw=psf.hw; par.psfn=psfn; irad=(int)par.anrad2 + 2; /*******************************/ /*** main loop over images ***/ /*******************************/ for (iim=0; iim<nim; iim++) { if (par.verbose > 2) printf("%d: %s\n", iim, diffiles[iim]); difim=read_FITS_2D1file(diffiles[iim], 's', &hsize, &newheader, &nx0, &ny0); for (i=0; i<hsize; i++) free(newheader[i]); free(newheader); if ((nx0 != par.nx0) || (ny0 != par.ny0)) { printf("ERROR! phot: wrong size of the image %s\n", diffiles[iim]); exit(2); } im=read_FITS_2D1file(imfiles[iim], 's', &hsize, &newheader, &nx0, &ny0); for (i=0; i<hsize; i++) free(newheader[i]); free(newheader); if ((nx0 != par.nx0) || (ny0 != par.ny0)) { printf("ERROR! phot: wrong size of the image %s\n", imfiles[iim]); exit(3); } /* read kernel into tables allocated before */ read_kernel(kerfiles[iim], &ker, 0, par.verbose); /*** loop over stars ***/ for (ipsf=0; ipsf<npsf; ipsf++) { objp = &obj[ipsf][iim]; if ((cx[ipsf] < irad) || (cy[ipsf] < irad) || (cx[ipsf] >= nx0-irad) || (cy[ipsf] >= ny0-irad)) { if (par.verbose) printf("%s warning: object %4d too close to edge: ignored!\n", diffiles[iim], ipsf); objp->a_flux = par.bad_value; objp->a_err = par.bad_value; objp->p_flux = par.bad_value; objp->p_err = par.bad_value; objp->chi2_n = par.bad_value; objp->ker_chi2 = par.bad_value; objp->corr = par.bad_value; objp->nbad = -1; continue; } /*** prepare local psf ***/ make_kernel(&ker, wxy[ipsf], kerim, sector[ipsf]); im_convolve(psfs[ipsf], psfim, psfn, psfn, kerim, ker.hw); objp->ker_chi2=(float)ker.chi2_n[sector[ipsf]]; objp->fwhm=(float)get_fwhm(psfim, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], &par, &ratio); if (par.bkg_mode) objp->bg = bkg(difim, cx[ipsf], cy[ipsf], &par); else objp->bg = 0.0; /*** actual profile and aperture photometry ***/ get_phot(difim, im, refim, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], psfim, objp, &par); if (par.verbose > 1) printf("%s star: %5d flux= %9g +- %8g nbad: %d\n", diffiles[iim], ipsf, objp->p_flux, objp->p_err, objp->nbad); } free(difim); free(im); } /*** write photometry to the output file ***/ if (par.verbose) printf("\nWriting photometry to: %s\n", outfname); if (par.dbf == 'A') writedba(outfname, diffiles, nim, npsf, vnum, obj); else writedbb(outfname, diffiles, nim, npsf, vnum, obj); if (par.verbose) printf("\nPhotometry done!\n"); return(0); }
void templatesSig(double XMIN,double XMAX,double dX,TString cutstring) { gROOT->ForceStyle(); RooMsgService::instance().setSilentMode(kTRUE); for(int i=0;i<2;i++) RooMsgService::instance().setStreamStatus(i,kFALSE); const int NMASS(1); char name[1000]; TFile *fVBF[NMASS];//,*fGF[NMASS]; TH1F *hVBF[NMASS][5],*hPassVBF; int H_MASS[1] = {125}; TString SELECTION[1] = {"jetPt[0]>80 && jetPt[1]>70"}; int NCAT[1] = {4}; int LUMI[1] = {19281}; int XSEC_VBF[1] = {0.911}; // TH1F *hGF[NMASS][5],*hVBF[NMASS][5],*hTOT[NMASS][5],*hPassGF,*hPassVBF; RooDataHist *RooHistFit[NMASS][5],*RooHistScaled[NMASS][5]; RooAddPdf *model[NMASS][5]; TCanvas *can[NMASS]; TString PATH("rootfiles/"); RooWorkspace *w = new RooWorkspace("w","workspace"); int NBINS = (XMAX-XMIN)/dX; RooRealVar x("mbbReg","mbbReg",XMIN,XMAX); RooRealVar kJES("CMS_scale_j","CMS_scale_j",1,0.9,1.1); RooRealVar kJER("CMS_res_j","CMS_res_j",1,0.8,1.2); kJES.setConstant(kTRUE); kJER.setConstant(kTRUE); TString TRIG_WT[2] = {"trigWtNOM[1]","trigWtVBF"}; for(int iMass=0;iMass<NMASS;iMass++) { cout<<"Mass = "<<H_MASS[iMass]<<" GeV"<<endl; int counter(0); for(int iSEL=0;iSEL<2;iSEL++) { // sprintf(name,"Fit_VBFPowheg%d_sel%s.root",H_MASS[iMass],SELECTION[iSEL].Data()); sprintf(name,"vbfHbb_uncertainties_JEx.root"); cout << name << endl; fVBF[iMass] = TFile::Open(PATH+TString(name)); // hPassVBF = (TH1F*)fVBF[iMass]->Get("TriggerPass"); // sprintf(name,"Fit_GFPowheg%d_sel%s.root",H_MASS[iMass],SELECTION[iSEL].Data()); // fGF[iMass] = TFile::Open(PATH+TString(name)); // hPassGF = (TH1F*)fGF[iMass]->Get("TriggerPass"); sprintf(name,"HMassTemplate_%d_sel%s",H_MASS[iMass],SELECTION[iSEL].Data()); can[iMass] = new TCanvas(name,name,1200,800); can[iMass]->Divide(2,2); for(int icat=0;icat<NCAT[iSEL];icat++) { sprintf(name,"Hbb%d/events",icat); // trVBF = (TTree*)fVBF[iMass]->Get(name); // trGF = (TTree*)fGF[iMass]->Get(name); can[iMass]->cd(icat+1); sprintf(name,"mass_VBF%d_sel%s_CAT%d",H_MASS[iMass],SELECTION[iSEL].Data(),icat); hVBF[iMass][icat] = (TH1F*)fVBF[iMass]->Get("histos/VBF125/h_NOM_VBF125_Hbb_mbbReg1;1");//new TH1F(name,name,NBINS,XMIN,XMAX); // hVBF[iMass][icat]->Sumw2(); // TCut cut("puWt[0]*"+TRIG_WT[iSEL]+"*(mva"+SELECTION[iSEL]+">-1)"); // TCut cut(cutstring.Data()); // trVBF->Draw(MASS_VAR[iSEL]+">>"+TString(name),cut); // sprintf(name,"mass_GF%d_sel%s_CAT%d",H_MASS[iMass],SELECTION[iSEL].Data(),icat); // hGF[iMass][icat] = new TH1F(name,name,NBINS,XMIN,XMAX); // hGF[iMass][icat]->Sumw2(); // trGF->Draw(MASS_VAR[iSEL]+">>"+TString(name),cut); // // delete trVBF; // delete trGF; sprintf(name,"roohist_fit_mass%d_sel%s_CAT%d",H_MASS[iMass],SELECTION[iSEL].Data(),icat); RooHistFit[iMass][icat] = new RooDataHist(name,name,x,hVBF[iMass][icat]); // hGF[iMass][icat]->Scale(LUMI[iSEL]*XSEC_GF[iMass]/hPassGF->GetBinContent(1)); hVBF[iMass][icat]->Scale(LUMI[iSEL]*XSEC_VBF[iMass]/4794398.);//hPassVBF->GetBinContent(1)); // sprintf(name,"mass_Total%d_sel%s_CAT%d",H_MASS[iMass],SELECTION[iSEL].Data(),icat); hTOT[iMass][icat] = (TH1F*)hVBF[iMass][icat]->Clone(name); // hTOT[iMass][icat]->Add(hGF[iMass][icat]); sprintf(name,"yield_signalVBF_mass%d_CAT%d",H_MASS[iMass],counter); RooRealVar *YieldVBF = new RooRealVar(name,name,hVBF[iMass][icat]->Integral()); sprintf(name,"roohist_demo_mass%d_sel%s_CAT%d",H_MASS[iMass],SELECTION[iSEL].Data(),icat); RooHistScaled[iMass][icat] = new RooDataHist(name,name,x,hTOT[iMass][icat]); sprintf(name,"mean_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar m(name,name,125,100,150); sprintf(name,"sigma_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar s(name,name,12,3,30); sprintf(name,"mean_shifted_m%d_CAT%d",H_MASS[iMass],counter); RooFormulaVar mShift(name,"@0*@1",RooArgList(m,kJES)); sprintf(name,"sigma_shifted_m%d_CAT%d",H_MASS[iMass],counter); RooFormulaVar sShift(name,"@0*@1",RooArgList(s,kJER)); sprintf(name,"alpha_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar a(name,name,1,-10,10); sprintf(name,"exp_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar n(name,name,1,0,100); sprintf(name,"b0_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar b0(name,name,0.5,0.,1.); sprintf(name,"b1_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar b1(name,name,0.5,0.,1.); sprintf(name,"b2_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar b2(name,name,0.5,0.,1.); sprintf(name,"b3_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar b3(name,name,0.5,0.,1.); sprintf(name,"signal_bkg_m%d_CAT%d",H_MASS[iMass],counter); RooBernstein bkg(name,name,x,RooArgSet(b0,b1,b2)); sprintf(name,"fsig_m%d_CAT%d",H_MASS[iMass],counter); RooRealVar fsig(name,name,0.7,0.,1.); sprintf(name,"signal_gauss_m%d_CAT%d",H_MASS[iMass],counter); RooCBShape sig(name,name,x,mShift,sShift,a,n); // model(x) = fsig*sig(x) + (1-fsig)*bkg(x) sprintf(name,"signal_model_m%d_CAT%d",H_MASS[iMass],counter); model[iMass][icat] = new RooAddPdf(name,name,RooArgList(sig,bkg),fsig); RooFitResult *res = model[iMass][icat]->fitTo(*RooHistFit[iMass][icat],RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); //res->Print(); RooPlot* frame = x.frame(); RooHistScaled[iMass][icat]->plotOn(frame); //model[iMass][icat]->plotOn(frame,RooFit::VisualizeError(*res,1,kFALSE),RooFit::FillColor(kGray)); //RooHist[iMass][icat]->plotOn(frame); model[iMass][icat]->plotOn(frame); double chi2 = frame->chiSquare(); //model[iMass][icat]->plotOn(frame,RooFit::LineWidth(2)); model[iMass][icat]->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(kBlue),RooFit::LineWidth(2),RooFit::LineStyle(kDashed)); frame->GetXaxis()->SetNdivisions(505); frame->GetXaxis()->SetTitle("M_{bb} (GeV)"); frame->GetYaxis()->SetTitle("Events"); frame->Draw(); // hGF[iMass][icat]->SetFillColor(kGreen-8); hVBF[iMass][icat]->SetFillColor(kRed-10); THStack *hs = new THStack("hs","hs"); // hs->Add(hGF[iMass][icat]); hs->Add(hVBF[iMass][icat]); hs->Draw("same hist"); frame->Draw("same"); gPad->RedrawAxis(); TF1 *tmp_func = model[iMass][icat]->asTF(x,fsig,x); double y0 = tmp_func->GetMaximum(); double x0 = tmp_func->GetMaximumX(); double x1 = tmp_func->GetX(y0/2,XMIN,x0); double x2 = tmp_func->GetX(y0/2,x0,XMAX); double FWHM = x2-x1; //cout<<"Int = "<<tmp_func->Integral(XMIN,XMAX)<<", Yield = "<<Yield->getVal()<<", y0 = "<<y0<<", x0 = "<<x0<<", x1 = "<<x1<<", x2 = "<<x2<<", FWHM = "<<FWHM<<endl; //delete tmp_func; double y1 = dX*0.5*y0*(YieldVBF->getVal()+YieldGF->getVal())/tmp_func->Integral(XMIN,XMAX); TLine *ln = new TLine(x1,y1,x2,y1); ln->SetLineColor(kMagenta+3); ln->SetLineStyle(7); ln->SetLineWidth(2); ln->Draw(); TLegend *leg = new TLegend(0.65,0.35,0.9,0.45); leg->AddEntry(hVBF[iMass][icat],"VBF","F"); // leg->AddEntry(hGF[iMass][icat],"GF","F"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.05); leg->Draw("same"); TPaveText *pave = new TPaveText(0.65,0.55,0.9,0.92,"NDC"); sprintf(name,"M_{H} = %d GeV",H_MASS[iMass]); TLegend *leg = new TLegend(0.65,0.35,0.9,0.45); leg->AddEntry(hVBF[iMass][icat],"VBF","F"); // leg->AddEntry(hGF[iMass][icat],"GF","F"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.05); leg->Draw("same"); TPaveText *pave = new TPaveText(0.65,0.55,0.9,0.92,"NDC"); sprintf(name,"M_{H} = %d GeV",H_MASS[iMass]); pave->AddText(name); sprintf(name,"%s selection",SELECTION[iSEL].Data()); pave->AddText(name); sprintf(name,"CAT%d",icat); pave->AddText(name); sprintf(name,"m = %1.1f #pm %1.1f",m.getVal(),m.getError()); pave->AddText(name); sprintf(name,"#sigma = %1.1f #pm %1.1f",s.getVal(),s.getError()); pave->AddText(name); sprintf(name,"FWHM = %1.2f",FWHM); pave->AddText(name); /* sprintf(name,"a = %1.2f #pm %1.2f",a.getVal(),a.getError()); pave->AddText(name); sprintf(name,"n = %1.2f #pm %1.2f",n.getVal(),n.getError()); pave->AddText(name); sprintf(name,"f = %1.2f #pm %1.2f",fsig.getVal(),fsig.getError()); pave->AddText(name); */ pave->SetFillColor(0); pave->SetBorderSize(0); pave->SetTextFont(42); pave->SetTextSize(0.05); pave->SetTextColor(kBlue); pave->Draw(); b0.setConstant(kTRUE); b1.setConstant(kTRUE); b2.setConstant(kTRUE); b3.setConstant(kTRUE); //m2.setConstant(kTRUE); //s2.setConstant(kTRUE); m.setConstant(kTRUE); s.setConstant(kTRUE); a.setConstant(kTRUE); n.setConstant(kTRUE); fsig.setConstant(kTRUE); w->import(*model[iMass][icat]); w->import(*RooHistScaled[iMass][icat]); w->import(*res); w->import(*YieldVBF); w->import(*YieldGF); counter++; }// categories loop }// selection loop }// mass loop w->Print(); //x.Print(); TString selName = "_"; selName += XMIN; selName += "-"; selName += XMAX; w->writeToFile("signal_shapes_workspace"+selName+".root"); }
plotRatioSignalBackground(TString signal="/work/LS/histos/may29/NL1NJ1/Ms500_Mn200_Mg10000/llp_hist.root",TString background="/work/LS/histos/may29/NL1NJ1/T1_McAtNlo/llp_hist.root", TString histoname="hHtAllJetsAllLeptons", Float_t ScaleSignal=0.14256 , Float_t ScaleBackground=0.194426 ){ //plotRatioSignalBackground(TString signal="/work/LS/histos/may29/NL1NJ1/Ms500_Mn200_Mg10000/llp_hist.root",TString background="/work/LS/histos/may29/NL1NJ1/T1_McAtNlo/llp_hist.root", Float_t ScaleSignal=0.14256 , Float_t ScaleBackground=0.194426 , TString histoname="hMuLowBetaMuon1EtaAbs"){ TFile sig(signal); TFile bkg(background); TH1F *htemp=(TH1F*)bkg.Get(histoname); TH1F *hb=(TH1F*)htemp->Clone(); hb->SetName(histoname+"bkg"); hb->Scale(ScaleSignal); TH1F *htemp2=(TH1F*)sig.Get(histoname); TH1F *hs=(TH1F*)htemp2->Clone(); hs->SetName(histoname+"sig"); hs->Scale(ScaleBackground); Int_t nbins=hs->GetNbinsX(); Float_t FirstBinEdge= hs->GetBinLowEdge(1); Float_t LastBinEdge=hs->GetBinLowEdge(nbins+1); TH1F * hRatio= new TH1F("hRatio","ratio of sig / sqrt(sig + bkg) ",nbins,FirstBinEdge,LastBinEdge); TH1F * hRatioSB= new TH1F("hRatioSB","ratio of sig / sqrt(bkg) ",nbins,FirstBinEdge,LastBinEdge); Float_t sigIntegral; Float_t bkgIntegral; Float_t edge,ratio; Float_t sigIntegralSB; Float_t bkgIntegralSB; Float_t ratioSB; cout << "Entries sig " << hs->GetEntries() << " Entries bkg "<< hb->GetEntries()<< endl; for (Int_t i=1;i<nbins;i++){ edge=hs->GetBinCenter(i); if ( histoname.Contains("Eta")){ sigIntegral=hs->Integral(1,nbins-i); bkgIntegral=hb->Integral(1,nbins-i); if ( bkgIntegral+sigIntegral > 0 ){ ratio = sigIntegral/(TMath::Sqrt(bkgIntegral+sigIntegral)); hRatio->SetBinContent(nbins-i,ratio); } else hRatio->SetBinContent(nbins-i,0.0); sigIntegralSB=hs->Integral(1,nbins-i); bkgIntegralSB=hb->Integral(1,nbins-i); if ( bkgIntegralSB > 0 ){ ratioSB = sigIntegralSB/(TMath::Sqrt(bkgIntegralSB)); hRatioSB->SetBinContent(nbins-i,ratioSB); } else hRatioSB->SetBinContent(nbins-i,0.0); } else{ sigIntegral=hs->Integral(i,nbins); bkgIntegral=hb->Integral(i,nbins); if ( bkgIntegral+sigIntegral > 0 ){ ratio = sigIntegral/(TMath::Sqrt(bkgIntegral+sigIntegral)); hRatio->SetBinContent(i,ratio); } else hRatio->SetBinContent(i,0.0); sigIntegralSB=hs->Integral(i,nbins); bkgIntegralSB=hb->Integral(i,nbins); if ( bkgIntegralSB > 0 ){ ratioSB = sigIntegralSB/(TMath::Sqrt(bkgIntegralSB)); hRatioSB->SetBinContent(i,ratioSB); } else hRatioSB->SetBinContent(i,0.0); } // cout << i << " ) signal Integral " << sigIntegral << " Background integral "<< bkgIntegral << " ratio "<< ratio << " Bin centre " << edge<< endl; } // for (Int_t i=1;i<nbins;i++) // cout << " done with optimization " << endl; cout << "max " << hRatio->GetMaximum() << " for a cut of " << hRatio->GetBinCenter(hRatio->GetMaximumBin()) << endl; if (histoname.Contains("Eta")) cout << "ETASignal percentage " << hs->Integral(1,hRatio->GetMaximumBin())/hs->Integral() << " Bkg percentage " << hb->Integral(1,hRatio->GetMaximumBin())/hb->Integral() << endl; else cout << "Signal percentage " << hs->Integral(hRatio->GetMaximumBin(),nbins)/hs->Integral() << " Bkg percentage " << hb->Integral(hRatio->GetMaximumBin(),nbins)/hb->Integral() << endl; TCanvas C; hRatio->Draw(); C.SaveAs(histoname+"1D"+"SignalOverSqrtSignalBackground.png"); TCanvas C3; hRatioSB->Draw(); C3.SaveAs(histoname+"1D"+"SignalOverSqrtBackground.png"); TCanvas C1; hb->Draw(); C1.SaveAs(histoname+"1D"+"Background.png"); TCanvas C2; hs->Draw(); C2.SaveAs(histoname+"1D"+"Signal.png"); }
/*--------------------------------------------------------*/ int main(int argc, char *argv[]) { char **header, *imffname, *parfname, *psffname, *reffname, *instrname, *fieldname, *catname, *coofname, record[RECORD_LEN], **diffiles, **imfiles, **kerfiles; int nx0, ny0, k, nim, iim, hsize, cx, cy, psfn, kern, irad, ofs, nobj1, nobj1_max, nobj2, nobj2_max, i, j, flag, *index, nvar; float x0_off, y0_off, x_tmp, y_tmp, fwhm_limit, *fwhm, **im, **difim, *refim, *varim1, *varim2, *corrim, *tmpim; double *wxy, x, y, *psfs, *psfim, *kerim, ratio; FILE *outfcat, *outfcoo; STAR *obj1, *obj2, *objp; PSF_STRUCT psf; KER_STRUCT ker; PAR_STRUCT par; /*** IO stuff ***/ if (argc != 9) usage(); parfname = argv[1]; instrname= argv[2]; reffname = argv[3]; psffname = argv[4]; imffname = argv[5]; fieldname = argv[6]; x0_off = atof(argv[7]); y0_off = atof(argv[8]); puts("sssssss"); get_params(parfname, instrname, &par); puts("sssssss"); if (!(catname=(char *)calloc(strlen(fieldname)+5, sizeof(char)))) errmess("calloc(catname)"); strcpy(catname, fieldname); strcat(catname, ".cat"); if (!(coofname=(char *)calloc(strlen(fieldname)+5, sizeof(char)))) errmess("calloc(coofname)"); strcpy(coofname, fieldname); strcat(coofname, ".coo"); if (par.verbose > 2) { printf("parfname = %s\n", parfname); printf("instrname= %s\n", instrname); printf("reffname = %s\n", reffname); printf("psffname = %s\n", psffname); printf("imffname = %s\n", imffname); printf("fieldname= %s\n", fieldname); printf("x0_off = %g\n", x0_off); printf("y0_off = %g\n", y0_off); printf("--------\n"); printf("catname = %s\n", catname); printf("coofname = %s\n", coofname); printf("--------\n"); } nim=read_inp_list(imffname, &diffiles, &imfiles, &kerfiles); if (par.verbose) printf("%s: %d images\n", imffname, nim); // printf("%s %s %s\n", diffiles[0],imfiles[0],kerfiles[0]); // printf("%s %s %s\n", diffiles[1],imfiles[1],kerfiles[1]); //getchar(); /**********************************************************************/ /*** read in psf fit and get a sample kernel from the first image ***/ /**********************************************************************/ read_psf(psffname, &psf, par.verbose); printf("%f %f %f\n",psf.ax, psf.ay, psf.vec[0]); read_kernel(kerfiles[0], &ker, 1, par.verbose); printf("%f %d %f\n",*ker.sig, *ker.deg, *ker.vec[0]); //getchar(); psf.normrad = par.normrad; psf.hw += ker.hw; psfn = 2*psf.hw + 1; kern = 2*ker.hw + 1; /*** get memory ***/ if (!(ker.vecs = (double **)malloc(ker.nvecs*sizeof(double *)))) errmess("malloc(ker.vecs)"); for (k=0; k<ker.nvecs; k++) if (!(ker.vecs[k] = (double *)malloc(kern*kern*sizeof(double)))) errmess("malloc(ker.vecs[k])"); if (!(kerim=(double *)malloc(kern*kern*sizeof(double)))) errmess("malloc(kerim)"); if (!(psfim=(double *)malloc(psfn*psfn*sizeof(double)))) errmess("malloc(psfim)"); if (!(fwhm = (float *)malloc(nim*sizeof(float)))) errmess("malloc(fwhm)"); if (!(index = (int *)malloc(nim*sizeof(int)))) errmess("malloc(index)"); /***********************************************************************/ /** get things that can be done once for all: spatial coeffs and psfs **/ /***********************************************************************/ refim=read_FITS_2D1file(reffname, 's', &hsize, &header, &nx0, &ny0); for (i=0; i<hsize; i++) free(header[i]); free(header); par.nx0 = nx0; par.ny0 = ny0; par.psfhw = psf.hw; par.psfn = psfn; printf("nx0: %d %d %d %d\n",nx0,ny0,psf.hw,psfn); irad = (int)par.anrad2 + 2; /*** get even more memory ***/ if (!(psfs=(double *)malloc(psfn*psfn*sizeof(double)))) errmess("malloc(psfs)"); if (!(wxy=(double *)malloc(ker.nwxy*sizeof(double)))) errmess("malloc(wxy)"); if (!(im =(float **)malloc(nim*sizeof(float *)))) errmess("malloc(im)"); if (!(difim=(float **)malloc(nim*sizeof(float *)))) errmess("malloc(difim)"); if (!(varim1=(float *)malloc(nx0*ny0*sizeof(float)))) errmess("malloc(varim1)"); if (!(varim2=(float *)malloc(nx0*ny0*sizeof(float)))) errmess("malloc(varim2)"); if (!(corrim=(float *)malloc(nx0*ny0*sizeof(float)))) errmess("malloc(corrim)"); for (i=0; i<nx0*ny0; i++) varim1[i] = varim2[i] = 0.0; /*** make reference psf and spatial coeffs for kernel ***/ init_psf(&psf, (double)(nx0/2), (double)(ny0/2)); make_psf(&psf, (double)(nx0/2), (double)(ny0/2), nx0/2, ny0/2, psfs); make_vectors(&ker); spatial_coeffs(&ker, (double)(ker.nx/2), (double)(ker.ny/2), wxy); /*******************************/ /*** main loop over images ***/ /*******************************/ printf("MAIN:\n"); for (iim=0; iim<nim; iim++) { read_kernel(kerfiles[iim], &ker, 0, par.verbose); make_kernel(&ker, wxy, kerim, 0); im_convolve(psfs, psfim, psfn, psfn, kerim, ker.hw); fwhm[iim] = get_fwhm(psfim, 0.0, 0.0, 0, 0, &par, &ratio); } /*** reject bad seeing frames ***/ quick_sort(fwhm, index, nim); printf("fwhm = %f\n",fwhm[0]); printf("fwhm = %f\n",fwhm[1]); fwhm_limit = fwhm[index[(int)(nim*par.fwhm_frac)]]; printf("fwhmlim = %f\n",fwhm_limit); j = 0; for (iim=0; iim<nim; iim++) { if (fwhm[iim] <= fwhm_limit) { if (j != iim) { strcpy(diffiles[j], diffiles[iim]); strcpy( imfiles[j], imfiles[iim]); strcpy(kerfiles[j], kerfiles[iim]); } j++; } } nim = j; if (nim == 0) { printf("no images left ! (exit)\n"); exit(2); } /*** get all variability data at once ***/ for (iim=0; iim<nim; iim++) { difim[iim]=read_FITS_2D1file(diffiles[iim], 's', &hsize, &header, &nx0, &ny0); //printf("difim = %f\n",difim[iim]); for (i=0; i<hsize; i++) free(header[i]); free(header); if ((nx0 != par.nx0) || (ny0 != par.ny0)) { printf("ERROR! getvar: image %s has wrong size\n", diffiles[iim]); exit(3); } im[iim]=read_FITS_2D1file(imfiles[iim], 's', &hsize, &header, &nx0, &ny0); for (i=0; i<hsize; i++) free(header[i]); free(header); if ((nx0 != par.nx0) || (ny0 != par.ny0)) { printf("ERROR! getvar: image %s has wrong size\n", imfiles[iim]); exit(4); } } /*** prepare variability likelihood image ***/ get_repeaters(difim, im, varim1, varim2, &par, nim); /*** save variability images ***/ if (!(tmpim=(float *)malloc(nx0*ny0*sizeof(float)))) errmess("malloc(tmpim)"); memcpy(tmpim, varim1, nx0*ny0*sizeof(float)); writevar2fits("var1.fits", nx0, ny0, tmpim); memcpy(tmpim, varim2, nx0*ny0*sizeof(float)); writevar2fits("var2.fits", nx0, ny0, tmpim); free(tmpim); /*** find stellar looking things ***/ covar_sig(varim1, corrim, nx0, ny0, 0.0, par.mohw, psfs, par.psfhw); obj1 = find_stars(corrim, nx0, ny0, &nobj1, &nobj1_max, &par); if (par.verbose > 1) printf("find_stars -> %d variables of type 1\n", nobj1); center_stars(obj1, nobj1, difim, im, &par, nim); /***/ covar_sig(varim2, corrim, nx0, ny0, 0.0, par.mohw, psfs, par.psfhw); obj2 = find_stars(corrim, nx0, ny0, &nobj2, &nobj2_max, &par); if (par.verbose > 1) printf("find_stars -> %d variables of type 2\n", nobj2); center_stars(obj2, nobj2, difim, im, &par, nim); /*** some stars may be found in both: take only one type and flag ***/ cross_id(obj1, nobj1, obj2, nobj2, par.id_rad); if (par.verbose) printf("\nFound %d and %d candidates for variables of both types\n\n", nobj1, nobj2); /*********************************************************************/ /*** write results to a binary file and x,y to a temporary file ***/ /*********************************************************************/ if (!(outfcoo = fopen(coofname, "w"))) errmess(coofname); if (!(outfcat = fopen(catname, "w"))) errmess(catname); free(coofname); free(catname); fseek(outfcat, 0, SEEK_END); ofs = sizeof(float); /*** get sinusoidal variables out ***/ if (par.verbose) printf("var1:\n num X Y flux flag\n"); nvar=0; for (i=0; i<nobj1; i++) { if (par.verbose > 1) printf("i= %d\n", i); objp = &(obj1[i]); x = (double)(objp->x); y = (double)(objp->y); if (par.verbose > 1) printf("x= %g y= %g\n", x, y); if ((x < par.bad_margin) || (x >= par.nx0 - par.bad_margin)) continue; if ((y < par.bad_margin) || (y >= par.ny0 - par.bad_margin)) continue; cx = objp->cx; cy = objp->cy; if (par.verbose > 1) printf("cx= %d cy= %d\n", cx, cy); /*** append to a binary file ***/ if (objp->nframes > 0) { fprintf(outfcoo, "%5d %11.5f %11.5f\n", nvar, x, y); nvar++; /*** get template photometry ***/ init_psf(&psf, x, y); make_psf(&psf, x, y, cx, cy, psfs); objp->bg = bkg(refim, cx, cy, &par); get_phot(refim, refim, refim, x, y, cx, cy, psfs, objp, &par); flag = neighbor(refim, (int)x, (int)y, &par, objp->bg); if (par.verbose) printf("%4d %9.3f %9.3f %9.1f %5d\n", i, x, y, objp->p_flux, flag); x_tmp = (float)(x + x0_off); y_tmp = (float)(y + y0_off); if (par.verbose > 2) { printf("x_tmp= %g y_tmp= %g\n", x_tmp, y_tmp); printf("ofs= %d 13*ofs= %d\n", ofs, 13*ofs); } memcpy(&record[ 0*ofs], &x_tmp , ofs); memcpy(&record[ 1*ofs], &y_tmp , ofs); memcpy(&record[ 2*ofs], &objp->p_flux , ofs); memcpy(&record[ 3*ofs], &objp->p_err , ofs); memcpy(&record[ 4*ofs], &objp->a_flux , ofs); memcpy(&record[ 5*ofs], &objp->a_err , ofs); memcpy(&record[ 6*ofs], &objp->bg , ofs); memcpy(&record[ 7*ofs], &objp->chi2_n , ofs); memcpy(&record[ 8*ofs], &objp->corr , ofs); memcpy(&record[ 9*ofs], &objp->nbad , sizeof(int)); memcpy(&record[10*ofs], &objp->vtype , sizeof(int)); memcpy(&record[11*ofs], &objp->nframes, sizeof(int)); memcpy(&record[12*ofs], &flag , sizeof(int)); if (par.verbose > 2) printf("record prepared - writting...\n"); fwrite(record, 1, sizeof(record), outfcat); } } /*** the same for transients ***/ if (par.verbose) printf("var2:\n num X Y flux flag\n"); for (i=0; i<nobj2; i++) { if (par.verbose > 1) printf("i= %d\n", i); objp = &obj2[i]; x = (double)(objp->x); y = (double)(objp->y); if (par.verbose > 1) printf("x= %g y= %g\n", x, y); if ((x < par.bad_margin) || (x >= par.nx0 - par.bad_margin)) continue; if ((y < par.bad_margin) || (y >= par.ny0 - par.bad_margin)) continue; cx = objp->cx; cy = objp->cy; if (par.verbose > 1) printf("cx= %d cy= %d\n", cx, cy); /*** append to a binary file ***/ if (objp->nframes > 0) { fprintf(outfcoo, "%5d %11.5f %11.5f\n", nvar, x, y); nvar++; /*** get template photometry ***/ init_psf(&psf, x, y); make_psf(&psf, x, y, cx, cy, psfs); obj2[i].bg = bkg(refim, cx, cy, &par); get_phot(refim, refim, refim, x, y, cx, cy, psfs, objp, &par); flag = neighbor(refim, (int)x, (int)y, &par, objp->bg); if (par.verbose) printf("%4d %9.3f %9.3f %9.1f %5d\n", i+nobj1, x, y, objp->p_flux, flag); x_tmp = (float)(x + x0_off); y_tmp = (float)(y + y0_off); if (par.verbose > 2) { printf("x_tmp= %g y_tmp= %g\n", x_tmp, y_tmp); printf("ofs= %d 13*ofs= %d\n", ofs, 13*ofs); } memcpy(&record[ 0*ofs], &x_tmp , ofs); memcpy(&record[ 1*ofs], &y_tmp , ofs); memcpy(&record[ 2*ofs], &objp->p_flux , ofs); memcpy(&record[ 3*ofs], &objp->p_err , ofs); memcpy(&record[ 4*ofs], &objp->a_flux , ofs); memcpy(&record[ 5*ofs], &objp->a_err , ofs); memcpy(&record[ 6*ofs], &objp->bg , ofs); memcpy(&record[ 7*ofs], &objp->chi2_n , ofs); memcpy(&record[ 8*ofs], &objp->corr , ofs); memcpy(&record[ 9*ofs], &objp->nbad , sizeof(int)); memcpy(&record[10*ofs], &objp->vtype , sizeof(int)); memcpy(&record[11*ofs], &objp->nframes, sizeof(int)); memcpy(&record[12*ofs], &flag , sizeof(int)); if (par.verbose > 2) printf("record prepared - writting...\n"); fwrite(record, 1, sizeof(record), outfcat); } } fclose(outfcoo); fclose(outfcat); if (par.verbose) printf("\nVariability seach fihished!\n"); return(0); }