// Funkcja oblicza wektor normalny w punkcie void NormalandReflected(int status, vector v, float *normal_vector, float *reflected_vector, float inter[], int objectype) { int r1 = (Elipsoids[status].radius[0] * Elipsoids[status].radius[0]), r2 = (Elipsoids[status].radius[1] * Elipsoids[status].radius[1]), r3 = (Elipsoids[status].radius[2] * Elipsoids[status].radius[2]); if (objectype == 0) { normal_vector[0] = inter[0] - Spheres[status].position[0]; normal_vector[1] = inter[1] - Spheres[status].position[1]; normal_vector[2] = inter[2] - Spheres[status].position[2]; } if (objectype == 1) { normal_vector[0] = 2 * (inter[0] - Elipsoids[status].position[0]) / (r1 * r1); normal_vector[1] = 2 * (inter[1] - Elipsoids[status].position[1]) / (r2 * r2); normal_vector[2] = 2 * (inter[2] - Elipsoids[status].position[2]) / (r3 * r3); } Normalization(normal_vector); float inverted[3] = { -v[0], -v[1], -v[2]}; Normalization(inverted); float scalar = DOT(inverted, normal_vector); reflected_vector[0] = 2 * (scalar) * normal_vector[0] - inverted[0]; reflected_vector[1] = 2 * (scalar) * normal_vector[1] - inverted[1]; reflected_vector[2] = 2 * (scalar) * normal_vector[2] - inverted[2]; Normalization(reflected_vector); }
// TODO needs some love void run() { while(ros::ok()) { current_time = ros::Time::now(); double dt = (current_time - last_time).toSec(); // TODO these predicst and measure variables are not something that I understand if (predict) { prediction(dt); last_time = current_time; predict = false; if (measure) { update_estimated_measurement(); weighting(); measure = false; } Normalization(); resample(); } if (visualization_enabled) { if (publish_particles) { particles_pub.publish(loc_viz.get_particle_marker(particle_state)); } if (publish_robot) { robot_pub.publish( loc_viz.get_robot_marker(std::vector<ras::sensor_info>(), x, y, theta, visualization_use_distance)); } if (publish_thickened_walls) { wall_cell_pub.publish(loc_viz.get_thick_wall_grid_cells()); } if (publish_walls) { grid_cell_pub.publish(loc_viz.get_wall_grid_cells()); } if (publish_path) { point_path_pub.publish(loc_viz.add_to_path(x, y)); } } //Publish Geometry msg of Predicted postion geometry_msgs::Pose2D msg; msg.x = x; msg.y = y; msg.theta = theta; position_pub.publish(msg); //Use if add a subscription(Add as good measure) ros::spinOnce(); //Delays untill it is time to send another message rate->sleep(); last_time = current_time; } }
void drawMassFrom2DPlot(RooWorkspace& myws, // Local workspace string outputDir, // Output directory struct InputOpt opt, // Variable with run information (kept for legacy purpose) struct KinCuts cut, // Variable with current kinematic cuts map<string, string> parIni, // Variable containing all initial parameters string plotLabel, // The label used to define the output file name // Select the type of datasets to fit string DSTAG, // Specifies the type of datasets: i.e, DATA, MCJPSINP, ... bool isPbPb, // Define if it is PbPb (True) or PP (False) // Select the type of object to fit bool incJpsi, // Includes Jpsi model bool incPsi2S, // Includes Psi(2S) model bool incBkg, // Includes Background model // Select the fitting options // Select the drawing options bool setLogScale, // Draw plot with log scale bool incSS, // Include Same Sign data double binWidth, // Bin width bool paperStyle=false // if true, print less info ) { RooMsgService::instance().getStream(0).removeTopic(Caching); RooMsgService::instance().getStream(1).removeTopic(Caching); RooMsgService::instance().getStream(0).removeTopic(Plotting); RooMsgService::instance().getStream(1).removeTopic(Plotting); RooMsgService::instance().getStream(0).removeTopic(Integration); RooMsgService::instance().getStream(1).removeTopic(Integration); RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ; if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_")); int nBins = min(int( round((cut.dMuon.M.Max - cut.dMuon.M.Min)/binWidth) ), 1000); string pdfTotName = Form("pdfCTAUMASS_Tot_%s", (isPbPb?"PbPb":"PP")); string pdfJpsiPRName = Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP")); string pdfJpsiNoPRName = Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP")); string pdfPsi2SPRName = Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP")); string pdfPsi2SNoPRName = Form("pdfCTAUMASS_Psi2SNoPR_%s", (isPbPb?"PbPb":"PP")); string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); string dsOSNameCut = dsOSName+"_CTAUCUT"; string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); bool isWeighted = myws.data(dsOSName.c_str())->isWeighted(); bool isMC = (DSTAG.find("MC")!=std::string::npos); double normDSTot = 1.0; if (myws.data(dsOSNameCut.c_str())) { normDSTot = myws.data(dsOSName.c_str())->sumEntries()/myws.data(dsOSNameCut.c_str())->sumEntries(); } // Create the main plot of the fit RooPlot* frame = myws.var("invMass")->frame(Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max)); myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); if (paperStyle) TGaxis::SetMaxDigits(3); // to display powers of 10 myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("BKG"),Components(RooArgSet(*myws.pdf(Form("pdfMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))))), FillStyle(paperStyle ? 0 : 1001), FillColor(kAzure-9), VLines(), DrawOption("LCF"), LineColor(kBlue), LineStyle(kDashed) ); if (!paperStyle) { if (incJpsi) { if ( myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSIPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))), *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kRed+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } if ( myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSINOPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))), *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kGreen+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } } if (incPsi2S) { if ( myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kRed+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } if ( myws.pdf(Form("pdfCTAUMASS_Psi2SNoPR_%s", (isPbPb?"PbPb":"PP"))) ) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SNOPR"),Components(RooArgSet(*myws.pdf(Form("pdfCTAUMASS_Psi2SNoPR_%s", (isPbPb?"PbPb":"PP"))))), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kGreen+3), LineStyle(1), Precision(1e-4), NumCPU(32) ); } } } if (incSS) { myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); } myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDF"), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kBlack), NumCPU(32) ); // Create the pull distribution of the fit RooPlot* frameTMP = (RooPlot*)frame->Clone("TMP"); int nBinsTMP = nBins; RooHist *hpull = frameTMP->pullHist(0, 0, true); hpull->SetName("hpull"); RooPlot* frame2 = myws.var("invMass")->frame(Title("Pull Distribution"), Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max)); frame2->addPlotable(hpull, "PX"); // set the CMS style setTDRStyle(); // Create the main canvas TCanvas *cFig = new TCanvas(Form("cMassFig_%s", (isPbPb?"PbPb":"PP")), "cMassFig",800,800); TPad *pad1 = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,paperStyle ? 0 : 0.23,1,1); TPad *pad2 = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228); TLine *pline = new TLine(cut.dMuon.M.Min, 0.0, cut.dMuon.M.Max, 0.0); // TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87); TPad *pad4 = new TPad("pad4","This is pad4",0.55,paperStyle ? 0.29 : 0.36,0.97,paperStyle ? 0.70 : 0.77); pad4->SetFillStyle(0); pad4->SetLeftMargin(0.28); pad4->SetRightMargin(0.10); pad4->SetBottomMargin(0.21); pad4->SetTopMargin(0.072); frame->SetTitle(""); frame->GetXaxis()->CenterTitle(kTRUE); if (!paperStyle) { frame->GetXaxis()->SetTitle(""); frame->GetXaxis()->SetTitleSize(0.045); frame->GetXaxis()->SetTitleFont(42); frame->GetXaxis()->SetTitleOffset(3); frame->GetXaxis()->SetLabelOffset(3); frame->GetYaxis()->SetLabelSize(0.04); frame->GetYaxis()->SetTitleSize(0.04); frame->GetYaxis()->SetTitleOffset(1.7); frame->GetYaxis()->SetTitleFont(42); } else { frame->GetXaxis()->SetTitle("m_{#mu^{+}#mu^{-}} (GeV/c^{2})"); frame->GetXaxis()->SetTitleOffset(1.1); frame->GetYaxis()->SetTitleOffset(1.45); frame->GetXaxis()->SetTitleSize(0.05); frame->GetYaxis()->SetTitleSize(0.05); } setMassFrom2DRange(myws, frame, dsOSName, setLogScale); if (paperStyle) { double Ydown = 0.;//frame->GetMinimum(); double Yup = 0.9*frame->GetMaximum(); frame->GetYaxis()->SetRangeUser(Ydown,Yup); } cFig->cd(); pad2->SetTopMargin(0.02); pad2->SetBottomMargin(0.4); pad2->SetFillStyle(4000); pad2->SetFrameFillStyle(4000); if (!paperStyle) pad1->SetBottomMargin(0.015); //plot fit pad1->Draw(); pad1->cd(); frame->Draw(); printMassFrom2DParameters(myws, pad1, isPbPb, pdfTotName, isWeighted); pad1->SetLogy(setLogScale); // Drawing the text in the plot TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032); float dy = 0; t->SetTextSize(0.03); if (!paperStyle) { // do not print selection details for paper style t->DrawLatex(0.20, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045; if (isPbPb) { t->DrawLatex(0.20, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=2.0*0.045; } else { t->DrawLatex(0.20, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=2.0*0.045; } } if (cut.dMuon.AbsRap.Min>0.1) {t->DrawLatex(0.5175, 0.86-dy, Form("%.1f < |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=0.045;} else {t->DrawLatex(0.5175, 0.86-dy, Form("|y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Max)); dy+=0.045;} t->DrawLatex(0.5175, 0.86-dy, Form("%g < p_{T}^{#mu#mu} < %g GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045; if (isPbPb) {t->DrawLatex(0.5175, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;} // Drawing the Legend double ymin = 0.7602; if (incPsi2S && incJpsi && incSS) { ymin = 0.7202; } if (incPsi2S && incJpsi && !incSS) { ymin = 0.7452; } if (paperStyle) { ymin = 0.72; } TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03); if (frame->findObject("dOS")) { leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe"); } if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); } if (frame->findObject("PDF")) { leg->AddEntry(frame->findObject("PDF"),"Total fit","l"); } if (frame->findObject("JPSIPR")) { leg->AddEntry(frame->findObject("JPSIPR"),"Prompt J/#psi","l"); } if (frame->findObject("JPSINOPR")) { leg->AddEntry(frame->findObject("JPSINOPR"),"Non-Prompt J/#psi","l"); } if (incBkg && frame->findObject("BKG")) { leg->AddEntry(frame->findObject("BKG"),"Background",paperStyle ? "l" : "fl"); } leg->Draw("same"); //Drawing the title TString label; if (isPbPb) { if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){ label = Form("PbPb Run %d", opt.PbPb.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End); } } else { if (opt.pp.RunNb.Start==opt.pp.RunNb.End){ label = Form("PP Run %d", opt.pp.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End); } } // CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label); CMS_lumi(pad1, isPbPb ? 108 : 107, 33, ""); if (!paperStyle) gStyle->SetTitleFontSize(0.05); pad1->Update(); cFig->cd(); if (!paperStyle) { //---plot pull pad2->Draw(); pad2->cd(); frame2->SetTitle(""); frame2->GetYaxis()->CenterTitle(kTRUE); frame2->GetYaxis()->SetTitleOffset(0.4); frame2->GetYaxis()->SetTitleSize(0.1); frame2->GetYaxis()->SetLabelSize(0.1); frame2->GetYaxis()->SetTitle("Pull"); frame2->GetXaxis()->CenterTitle(kTRUE); frame2->GetXaxis()->SetTitleOffset(1); frame2->GetXaxis()->SetTitleSize(0.12); frame2->GetXaxis()->SetLabelSize(0.1); frame2->GetXaxis()->SetTitle("m_{#mu^{+}#mu^{-}} (GeV/c^{2})"); frame2->GetYaxis()->SetRangeUser(-7.0, 7.0); frame2->Draw(); // *** Print chi2/ndof printChi2(myws, pad2, frameTMP, "invMass", dsOSName.c_str(), pdfTotName.c_str(), nBinsTMP, false); pline->Draw("same"); pad2->Update(); } // Save the plot in different formats gSystem->mkdir(Form("%sctauMass/%s/plot/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/root/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), "MASS", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%sctauMass/%s/plot/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/png/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), "MASS", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%sctauMass/%s/plot/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/pdf/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), "MASS", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); cFig->Clear(); cFig->Close(); };
int main() { //Get Learning Dictionary GetLearningDictionary(RGBDic,LabDic); //LabDic[0].print("OK?"); //Do Saliency Detection for(int FileNode=1; FileNode<=MAXPIC; FileNode++) { //GetPic Mat SourceImage; Mat RGBImage; Mat LABImage; sprintf(FileName,"%s%d.jpg",IMGSAIM,FileNode); //get filename SourceImage=imread(FileName); //load picture from file resize(SourceImage,RGBImage,Size(PICSIZE,PICSIZE),0,0,INTER_LINEAR); cvtColor(RGBImage,LABImage,COLOR_BGR2Lab); //translate RGB into Lab imshow("Source",RGBImage); Matrix<double> RGBCannels[3]; Matrix<double> LabCanenls[3]; SpMatrix<double> SPRGB[3]; SpMatrix<double> SPLab[3]; Matrix<double> RGBSaliency; Matrix<double> LabSaliency; Matrix<double> FinalSaliency; Sparam sparam; for(int ColorSpace=1; ColorSpace<=2; ColorSpace++) { Matrix<double> *Cannels; Matrix<double> *Dic; SpMatrix<double> *Sparsecode; Matrix<double> * Saliency; //Choose Image Color Space if(ColorSpace==1) { Cannels=RGBCannels; Dic=RGBDic; Sparsecode=SPRGB; Saliency=&RGBSaliency; } else { Cannels=LabCanenls; Dic=LabDic; Sparsecode=SPLab; Saliency=&LabSaliency; } //Split picture into different cannels and transform Mat into Matrix<T> SplitCannel(RGBImage,Cannels[0],Cannels[1],Cannels[2]); //Split Picture into R,G,B cannel for(int Can=0; Can<3; Can++) { //Image into Row ImageToCol(Cannels[Can],PATCHSIZE,PATCHSIZE); //Represent picture by sparse coding Matrix<double> Result; lasso(Cannels[Can],Dic[Can],Sparsecode[Can],sparam); Dic->mult(Sparsecode[Can],Result); //Result into Image ColToImage(Result,PATCHSIZE,PATCHSIZE,PICSIZE,PICSIZE); } //Get cannnel's local saliency for(int Can=0; Can<3; Can++) { LocalSailency(Sparsecode[Can],Cannels[Can]); Normalization(Cannels[Can]); } //Composite cannels' saliency into space's saliency Saliency->resize(PATCHLEN,PATCHLEN); Saliency->setZeros(); for(int Can=0; Can<3; Can++) Saliency->add(Cannels[Can]); Normalization(*Saliency); } //Composite Lab's and RGB's saliency into finnal sailency FinalSaliency.resize(PATCHLEN,PATCHLEN); FinalSaliency.setZeros(); FinalSaliency.add(LabSaliency); FinalSaliency.add(RGBSaliency); Normalization(FinalSaliency); //transform saliency into image Mat SaliencyImage(PATCHLEN,PATCHLEN,CV_8UC1); MatrixtoMat(FinalSaliency,SaliencyImage); imshow("Final Saliency",SaliencyImage); waitKey(0); } return 0; }
void MuScale() { //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== // event category enumeration enum { eMuMu2HLT=1, eMuMu1HLT1L1, eMuMu1HLT, eMuMuNoSel, eMuSta, eMuTrk }; // event category enum TString outputDir = "MuScaleResults"; vector<TString> infilenamev; infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zmumu/ntuples/data_select.trkCuts.root"); // data infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zmumu/ntuples/zmm_select.raw.trkCuts.root"); // MC const Double_t MASS_LOW = 60; const Double_t MASS_HIGH = 120; const Double_t PT_CUT = 25; const Double_t ETA_CUT = 2.4; const Double_t MU_MASS = 0.105658369; vector<pair<Double_t,Double_t> > scEta_limits; scEta_limits.push_back(make_pair(0.0,1.2)); scEta_limits.push_back(make_pair(1.2,2.1)); scEta_limits.push_back(make_pair(2.1,2.4)); CPlot::sOutDir = outputDir; const TString format("png"); //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== enum { eData=0, eMC }; char hname[100]; vector<TH1D*> hMCv, hDatav; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { sprintf(hname,"mc_%i_%i",ibin,jbin); hMCv.push_back(new TH1D(hname,"",80,MASS_LOW,MASS_HIGH)); hMCv.back()->Sumw2(); sprintf(hname,"data_%i_%i",ibin,jbin); hDatav.push_back(new TH1D(hname,"",80,MASS_LOW,MASS_HIGH)); hDatav.back()->Sumw2(); } } // // Declare output ntuple variables // UInt_t runNum, lumiSec, evtNum; Float_t scale1fb, puWeight; UInt_t matchGen; UInt_t category; UInt_t npv, npu; Int_t q1, q2; TLorentzVector *dilep=0, *lep1=0, *lep2=0; for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) { cout << "Processing " << infilenamev[ifile] << "..." << endl; TFile *infile = TFile::Open(infilenamev[ifile]); assert(infile); TTree *intree = (TTree*)infile->Get("Events"); assert(intree); intree->SetBranchAddress("runNum", &runNum); // event run number intree->SetBranchAddress("lumiSec", &lumiSec); // event lumi section intree->SetBranchAddress("evtNum", &evtNum); // event number intree->SetBranchAddress("scale1fb", &scale1fb); // event weight intree->SetBranchAddress("puWeight", &puWeight); // pileup reweighting intree->SetBranchAddress("matchGen", &matchGen); // event has both leptons matched to MC Z->ll intree->SetBranchAddress("category", &category); // dilepton category intree->SetBranchAddress("npv", &npv); // number of primary vertices intree->SetBranchAddress("npu", &npu); // number of in-time PU events (MC) intree->SetBranchAddress("q1", &q1); // charge of lead lepton intree->SetBranchAddress("q2", &q2); // charge of trail lepton intree->SetBranchAddress("dilep", &dilep); // dilepton 4-vector intree->SetBranchAddress("lep1", &lep1); // lead lepton 4-vector intree->SetBranchAddress("lep2", &lep2); // trail lepton 4-vector for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) { intree->GetEntry(ientry); Double_t weight = 1; if(ifile==eMC) { //if(!matchGen) continue; weight=scale1fb*puWeight*1.1*TMath::Power(10,7)/5610.0; } if((category!=eMuMu2HLT) && (category!=eMuMu1HLT) && (category!=eMuMu1HLT1L1)) continue; if(q1 == q2) continue; if(dilep->M() < MASS_LOW) continue; if(dilep->M() > MASS_HIGH) continue; if(lep1->Pt() < PT_CUT) continue; if(lep2->Pt() < PT_CUT) continue; if(fabs(lep1->Eta()) > ETA_CUT) continue; if(fabs(lep2->Eta()) > ETA_CUT) continue; TLorentzVector vLep1(0,0,0,0); TLorentzVector vLep2(0,0,0,0); vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), MU_MASS); vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), MU_MASS); TLorentzVector vDilep = vLep1 + vLep2; Int_t bin1=-1, bin2=-1; for(UInt_t i=0; i<scEta_limits.size(); i++) { Double_t etalow = scEta_limits.at(i).first; Double_t etahigh = scEta_limits.at(i).second; if(fabs(lep1->Eta())>=etalow && fabs(lep1->Eta())<=etahigh) bin1=i; if(fabs(lep2->Eta())>=etalow && fabs(lep2->Eta())<=etahigh) bin2=i; } assert(bin1>=0); assert(bin2>=0); Int_t ibin= (bin1<=bin2) ? bin1 : bin2; Int_t jbin= (bin1<=bin2) ? bin2 : bin1; UInt_t n=jbin-ibin; for(Int_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); if(ifile==eData) hDatav[n]->Fill(vDilep.M(),weight); if(ifile==eMC) hMCv[n]->Fill(vDilep.M(),weight); } delete infile; infile=0, intree=0; } // // Fit for energy scale and resolution corrections // char vname[100]; // buffer for RooFit object names char pname[100]; char str1[100]; char str2[100]; TCanvas *c = MakeCanvas("c","c",800,600); // Dummy histograms for TLegend (I can't figure out how to properly pass RooFit objects...) TH1D *hDummyData = new TH1D("hDummyData","",0,0,10); hDummyData->SetMarkerStyle(kFullCircle); hDummyData->SetMarkerSize(0.9); TH1D *hDummyMC = new TH1D("hDummyMC","",0,0,10); hDummyMC->SetLineColor(kBlue); hDummyMC->SetFillColor(kBlue); hDummyMC->SetFillStyle(3002); TH1D *hDummyFit = new TH1D("hDummyFit","",0,0,10); hDummyFit->SetLineColor(kGreen+2); RooRealVar mass("mass","M_{#mu#mu}",60.0,120.0,"GeV") ; mass.setBins(1600,"cache"); RooRealVar massmc("massmc","massmc",0.0,150.0,"GeV"); // mass variable for building MC template RooCategory zscEta_cat("zscEta_cat","zscEta_cat"); RooSimultaneous combscalefit("combscalefit","combscalefit",zscEta_cat); map<string,TH1*> hmap; // Mapping of category labels and data histograms RooArgList scalebins; // List of RooRealVars storing per bin energy scale corrections RooArgList sigmabins; // List of RooRealVars storing per bin energy resolution corrections Int_t intOrder = 1; // Interpolation order for for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { sprintf(vname,"scale_%i",ibin); RooRealVar *scalebinned = new RooRealVar(vname,vname,1.0,0.5,1.5); scalebins.add(*scalebinned); sprintf(vname,"sigma_%i",ibin); RooRealVar *sigmabinned = new RooRealVar(vname,vname,1.0,0.0,2.0); sigmabins.add(*sigmabinned); } for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { UInt_t n=jbin-ibin; for(UInt_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); sprintf(vname,"masslinearshifted_%i_%i",ibin,jbin); RooFormulaVar *masslinearshifted = new RooFormulaVar(vname,vname,"sqrt(@0*@1)",RooArgList(*scalebins.at(ibin),*scalebins.at(jbin))); sprintf(vname,"massshiftedscEta_%i_%i",ibin,jbin); RooLinearVar *massshiftedscEta = new RooLinearVar(vname,vname,mass,*masslinearshifted,RooConst(0.0)); // MC-based template sprintf(vname,"zmassmcscEta_%i_%i",ibin,jbin); RooDataHist *zmassmcscEta = new RooDataHist(vname,vname,RooArgList(massmc),hMCv[n]); sprintf(vname,"masstemplatescEta_%i_%i",ibin,jbin); RooHistPdf *masstemplatescEta = new RooHistPdf(vname,vname,RooArgList(*massshiftedscEta),RooArgList(massmc),*zmassmcscEta,intOrder); // Gaussian smearing function sprintf(vname,"sigmascEta_%i_%i",ibin,jbin); RooFormulaVar *sigmascEta = new RooFormulaVar(vname,vname,"sqrt(@0*@0+@1*@1)",RooArgList(*sigmabins.at(ibin),*sigmabins.at(jbin))); sprintf(vname,"resscEta_%i_%i",ibin,jbin); RooGaussian *resscEta = new RooGaussian(vname,vname,mass,RooConst(0.),*sigmascEta); // Fit model: MC-template convoluted with Gaussian sprintf(vname,"fftscEta_%i_%i",ibin,jbin); RooFFTConvPdf *fftscEta = new RooFFTConvPdf(vname,vname,mass,*masstemplatescEta,*resscEta); fftscEta->setBufferStrategy(RooFFTConvPdf::Flat); // Add bin as a category char zscEta_catname[100]; sprintf(zscEta_catname,"zscEta_cat_%i_%i",ibin,jbin); zscEta_cat.defineType(zscEta_catname); zscEta_cat.setLabel(zscEta_catname); hmap.insert(pair<string,TH1*>(zscEta_catname,hDatav[n])); combscalefit.addPdf(*fftscEta,zscEta_catname); } } // perform fit RooDataHist zdatascEta_comb("zdatascEta_comb","zdatascEta_comb",RooArgList(mass),zscEta_cat,hmap,1.0); combscalefit.fitTo(zdatascEta_comb,PrintEvalErrors(kFALSE),Minos(kFALSE),Strategy(0),Minimizer("Minuit2","")); Double_t xval[scEta_limits.size()]; Double_t xerr[scEta_limits.size()]; Double_t scaleDatatoMC[scEta_limits.size()]; Double_t scaleDatatoMCerr[scEta_limits.size()]; Double_t scaleMCtoData[scEta_limits.size()]; Double_t scaleMCtoDataerr[scEta_limits.size()]; Double_t sigmaMCtoData[scEta_limits.size()]; Double_t sigmaMCtoDataerr[scEta_limits.size()]; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; xval[ibin] = 0.5*(etahigh+etalow); xerr[ibin] = 0.5*(etahigh-etalow); scaleDatatoMC[ibin] = ((RooRealVar*)scalebins.at(ibin))->getVal(); scaleDatatoMCerr[ibin] = ((RooRealVar*)scalebins.at(ibin))->getError(); scaleMCtoData[ibin] = 1.0/scaleDatatoMC[ibin]; scaleMCtoDataerr[ibin] = scaleDatatoMCerr[ibin]/scaleDatatoMC[ibin]/scaleDatatoMC[ibin]; sigmaMCtoData[ibin] = ((RooRealVar*)sigmabins.at(ibin))->getVal(); sigmaMCtoDataerr[ibin] = ((RooRealVar*)sigmabins.at(ibin))->getError(); } TGraphErrors *grScaleDatatoMC = new TGraphErrors(scEta_limits.size(),xval,scaleDatatoMC,xerr,scaleDatatoMCerr); TGraphErrors *grScaleMCtoData = new TGraphErrors(scEta_limits.size(),xval,scaleMCtoData,xerr,scaleMCtoDataerr); TGraphErrors *grSigmaMCtoData = new TGraphErrors(scEta_limits.size(),xval,sigmaMCtoData,xerr,sigmaMCtoDataerr); CPlot plotScale1("mu_scale_datatomc","","Muon |#eta|","Data scale correction"); plotScale1.AddGraph(grScaleDatatoMC,"",kBlue); plotScale1.SetYRange(0.98,1.02); plotScale1.AddLine(0,1,2.5,1,kBlack,7); plotScale1.Draw(c,kTRUE,format); CPlot plotScale2("mu_scale_mctodata","","Muon |#eta|","MC#rightarrowData scale correction"); plotScale2.AddGraph(grScaleMCtoData,"",kBlue); plotScale2.SetYRange(0.98,1.02); plotScale2.AddLine(0,1,2.5,1,kBlack,7); plotScale2.Draw(c,kTRUE,format); CPlot plotRes("mu_res_mctodata","","Muon |#eta|","MC#rightarrowData additional smear [GeV]"); plotRes.AddGraph(grSigmaMCtoData,"",kBlue); plotRes.SetYRange(0,1.6); plotRes.Draw(c,kTRUE,format); double nData=0; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { UInt_t n=jbin-ibin; for(UInt_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); // Post-fit plot RooPlot *frame = mass.frame(); char catname[100]; sprintf(catname,"zscEta_cat_%i_%i",ibin,jbin); char cutstr[100]; sprintf(cutstr,"zscEta_cat==zscEta_cat::%s",catname); RooDataHist zmc(catname,catname,RooArgList(mass),hMCv[n]); RooHistPdf mctemplate(catname,catname,RooArgList(mass),zmc,intOrder); //mctemplate.plotOn(frame,LineColor(kBlue),LineWidth(1),Normalization(hDatav[n]->GetEntries())); mctemplate.plotOn(frame,LineColor(kBlue),LineWidth(1),Normalization(hDatav[n]->Integral())); //mctemplate.plotOn(frame,LineColor(kBlue),FillColor(kBlue),FillStyle(3002),DrawOption("F"),Normalization(hDatav[n]->GetEntries())); mctemplate.plotOn(frame,LineColor(kBlue),FillColor(kBlue),FillStyle(3002),DrawOption("F"),Normalization(hDatav[n]->Integral())); zdatascEta_comb.plotOn(frame,Cut(cutstr),MarkerStyle(kFullCircle),MarkerSize(1.0),DrawOption("ZP")); combscalefit.plotOn(frame,Slice(zscEta_cat,catname),ProjWData(RooArgSet(mass,catname),zdatascEta_comb), LineColor(kGreen+2)); sprintf(pname,"postfit_%i_%i",ibin,jbin); sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(ibin).first,scEta_limits.at(ibin).second); sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(jbin).first,scEta_limits.at(jbin).second); CPlot plot(pname,frame,"","m(#mu^{+}#mu^{-}) [GeV/c^{2}]","Events / 0.6 GeV/c^{2}"); plot.AddTextBox(str1,0.21,0.80,0.45,0.87,0,kBlack,-1); plot.AddTextBox(str2,0.21,0.73,0.45,0.80,0,kBlack,-1); plot.SetLegend(0.75,0.64,0.93,0.88); plot.GetLegend()->AddEntry(hDummyData,"Data","PL"); plot.GetLegend()->AddEntry(hDummyMC,"Sim","FL"); plot.GetLegend()->AddEntry(hDummyFit,"Fit","L"); plot.Draw(c,kTRUE,format); nData += hDatav[n]->Integral(); } } cout<<"nData = "<<nData<<endl; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << endl; ofstream txtfile; char txtfname[100]; sprintf(txtfname,"%s/summary.txt",outputDir.Data()); txtfile.open(txtfname); assert(txtfile.is_open()); txtfile << " Data->MC scale correction" << endl; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; txtfile << "$" << etalow << " < |\\eta| < " << etahigh << "$ & "; txtfile << "$" << ((RooRealVar*)scalebins.at(ibin))->getVal() << "$ \\pm $" << ((RooRealVar*)scalebins.at(ibin))->getError() << "$ \\\\" << endl; } txtfile << endl; txtfile << " MC->Data resolution correction [GeV]" << endl; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; txtfile << etalow << " < |\\eta| < " << etahigh << " & "; txtfile << "$" << ((RooRealVar*)sigmabins.at(ibin))->getVal() << "$ \\pm $" << ((RooRealVar*)sigmabins.at(ibin))->getError() << "$ \\\\" << endl; } txtfile.close(); cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; }
bool CSamplingInfEngine:: ConvertingFamilyToPot( int node, const CEvidence* pEv ) { bool ret = false; CPotential* potToSample = m_potsToSampling[node]; Normalization(potToSample); int i; if( !IsAllNdsTab() ) { if( GetModel()->GetModelType() == mtBNet ) { for( i = 0; i < m_environment[node].size(); i++ ) { int num = m_environment[node][i]; CPotential *pot1 = static_cast< CCPD* >( m_currentFactors[ num ] ) ->ConvertWithEvidenceToPotential(pEv); CPotential *pot2 = pot1->Marginalize(&node, 1); delete pot1; *potToSample *= *pot2; delete pot2; } } else { for( i = 0; i < m_environment[node].size(); i++ ) { int num = m_environment[node][i]; CPotential *pot1 = static_cast< CPotential* >( m_currentFactors[ num ] ) ->ShrinkObservedNodes(pEv); CPotential *pot2 = pot1->Marginalize(&node, 1); delete pot1; *potToSample *= *pot2; delete pot2; } } } else { CMatrix< float > *pMatToSample; pMatToSample = static_cast<CTabularDistribFun*>(potToSample->GetDistribFun()) ->GetMatrix(matTable); intVector dims; intVector vls; intVector domain; for( i = 0; i < m_environment[node].size(); i++ ) { int num = m_environment[node][i]; m_currentFactors[ num ]->GetDomain(&domain); GetObsDimsWithVls( domain, node, pEv, &dims, &vls); CMatrix< float > *pMat; pMat = static_cast<CTabularDistribFun*>(m_currentFactors[ num ]-> GetDistribFun())->GetMatrix(matTable); pMat->ReduceOp( &dims.front(), dims.size(), 2, &vls.front(), pMatToSample, PNL_ACCUM_TYPE_MUL ); dims.clear(); vls.clear(); domain.clear(); } } //check for non zero elements CMatrix<float> *pMat; if( potToSample->GetDistributionType()==dtTabular ) { pMat = potToSample->GetDistribFun()->GetMatrix(matTable); } else { CGaussianDistribFun* pDistr = static_cast<CGaussianDistribFun*>(potToSample->GetDistribFun()); if(pDistr->GetMomentFormFlag()) { pMat = pDistr->GetMatrix(matCovariance); } else { pMat = pDistr->GetMatrix(matK); } } CMatrixIterator<float>* iter = pMat->InitIterator(); for( iter; pMat->IsValueHere( iter ); pMat->Next(iter) ) { if(*(pMat->Value( iter )) > FLT_EPSILON) { ret = true; break; } } delete iter; return ret; }
void Phong(int nr, vector viewer_v, float normal_vector[], float inter[], float *pixelcolor, int objectype) { vector vec; vector reflection_vector; float n_dot_l, v_dot_r; for (int i = 0; i < aLights ; i++) { vec[0] = Lights[i].position[0] - inter[0]; // wektor wskazujący kierunek źródła vec[1] = Lights[i].position[1] - inter[1]; vec[2] = Lights[i].position[2] - inter[2]; Normalization(vec); // normalizacja wektora kierunku świecenia źródła n_dot_l = DOT(vec, normal_vector); reflection_vector[0] = 2 * (n_dot_l) * normal_vector[0] - vec[0]; reflection_vector[1] = 2 * (n_dot_l) * normal_vector[1] - vec[1]; reflection_vector[2] = 2 * (n_dot_l) * normal_vector[2] - vec[2]; // obliczenie wektora opisującego kierunek światła odbitego od punktu na powierzchni sfery Normalization(reflection_vector); // normalizacja wektora kierunku światła odbitego v_dot_r = DOT(reflection_vector, viewer_v); if (v_dot_r < 0) { // obserwator nie widzi oświetlanego punktu v_dot_r = 0; } if (n_dot_l > 0) { // oświetlenie wyliczane jest ze wzorów dla modelu Phonga float eq = sqrt //część równania pod pierwiastkiem ( (Lights[i].position[0] - inter[0]) * (Lights[i].position[0] - inter[0]) + (Lights[i].position[1] - inter[1]) * (Lights[i].position[1] - inter[1]) + (Lights[i].position[2] - inter[2]) * (Lights[i].position[2] - inter[2]) ); if (objectype == 0) { pixelcolor[0] += (A / (A + B * eq + C * eq * eq)) * ( Spheres[nr].diffuse[0] * Lights[i].diffuse [0] * n_dot_l + Spheres[nr].specular[0] * Lights[i].specular[0] * pow((double) v_dot_r, (double) Spheres[nr].specularshininess) ) + Spheres[nr].ambient[0] * Lights[i].ambient[0]; pixelcolor[1] += (A / (A + B * eq + C * eq * eq)) * (Spheres[nr].diffuse[1] * Lights[i].diffuse [1] * n_dot_l + Spheres[nr].specular[1] * Lights[i].specular[1] * pow((double) v_dot_r, (double) Spheres[nr].specularshininess) ) + Spheres[nr].ambient[1] * Lights[i].ambient[1]; pixelcolor[2] += (A / (A + B * eq + C * eq * eq)) * (Spheres[nr].diffuse[2] * Lights[i].diffuse[2] * n_dot_l + Spheres[nr].specular[2] * Lights[i].specular[2] * pow((double) v_dot_r, (double) Spheres[nr].specularshininess) ) + Spheres[nr].ambient[2] * Lights[i].ambient[2]; } if (objectype == 1) { pixelcolor[0] += (A / (A + B * eq + C * eq * eq)) * ( Elipsoids[nr].diffuse[0] * Lights[i].diffuse [0] * n_dot_l + Elipsoids[nr].specular[0] * Lights[i].specular[0] * pow((double) v_dot_r, (double) Elipsoids[nr].specularshininess) ) + Elipsoids[nr].ambient[0] * Lights[i].ambient[0]; pixelcolor[1] += (A / (A + B * eq + C * eq * eq)) * (Elipsoids[nr].diffuse[1] * Lights[i].diffuse [1] * n_dot_l + Elipsoids[nr].specular[1] * Lights[i].specular[1] * pow((double) v_dot_r, (double) Elipsoids[nr].specularshininess) ) + Elipsoids[nr].ambient[1] * Lights[i].ambient[1]; pixelcolor[2] += (A / (A + B * eq + C * eq * eq)) * (Elipsoids[nr].diffuse[2] * Lights[i].diffuse[2] * n_dot_l + Elipsoids[nr].specular[2] * Lights[i].specular[2] * pow((double) v_dot_r, (double) Elipsoids[nr].specularshininess) ) + Elipsoids[nr].ambient[2] * Lights[i].ambient[2]; } } // punkt nie jest oświetlany // uwzględniane jest tylko światło rozproszone if (objectype == 0) { pixelcolor[0] += Spheres[nr].ambient[0] * global_a[0]; pixelcolor[1] += Spheres[nr].ambient[1] * global_a[1]; pixelcolor[2] += Spheres[nr].ambient[2] * global_a[2]; } if (objectype == 1) { pixelcolor[0] += Elipsoids[nr].ambient[0] * global_a[0]; pixelcolor[1] += Elipsoids[nr].ambient[1] * global_a[1]; pixelcolor[2] += Elipsoids[nr].ambient[2] * global_a[2]; } } }
int main() { const double PDGLbMass=5619.51; const double RareUpperBlind=PDGLbMass+125.0; const double RareLowerBlind=PDGLbMass-125.0; const double Rare2UpperBlind=PDGLbMass+175.0; const double Rare2LowerBlind=PDGLbMass-175.0; bool blind=true; bool remakecc=false; bool remakerare=false; bool remakerare2=false; bool sweight=false; TRandom3* MultiCandRand=new TRandom3(224); //dont change seed TH1I* ControlChannelMultiCands= new TH1I("ControlChannelMultiCands","ControlChannelMultiCands",10,0,10); TH1I* RareChannelMultiCands= new TH1I("RareChannelMultiCands","RareChannelMultiCands",10,0,10); TH1I* Rare2ChannelMultiCands= new TH1I("RareChannel2MultiCands","RareChannel2MultiCands",10,0,10); //_______________________________________ MAKE CONTROL CHANNEL ROODATASET______________________________________ if(remakecc) { std::string ControlDataPath=std::getenv("BUKETAPDATABDTRESPROOT"); DataFile CC12A(ControlDataPath,Data,Twel,MagAll,buketap,"BDTApplied_SampleA"); DataFile CC12B(ControlDataPath,Data,Twel,MagAll,buketap,"BDTApplied_SampleB"); DataFile CC11A(ControlDataPath,Data,Elev,MagAll,buketap,"BDTApplied_SampleA"); DataFile CC11B(ControlDataPath,Data,Elev,MagAll,buketap,"BDTApplied_SampleB"); TreeReader* CC12Reader= new TreeReader("DecayTree"); CC12Reader->AddFile(CC12A); CC12Reader->AddFile(CC12B); CC12Reader->Initialize(ControlCuts::BranchesToKeep,"contains"); TFile* Minimal12File= new TFile("MinimalCC12.root","RECREATE"); TTree* Minimal12Tree=CC12Reader->CopyTree(ControlCuts::AllCuts12,-1,"DecayTree"); TTree* MinimalFlagged12Tree=HandyFunctions::GetSingleTree(MultiCandRand,Minimal12Tree,ControlChannelMultiCands,NULL); MinimalFlagged12Tree->Write(); Minimal12File->Close(); TreeReader* CC11Reader= new TreeReader("DecayTree"); CC11Reader->AddFile(CC11A); CC11Reader->AddFile(CC11B); CC11Reader->Initialize(ControlCuts::BranchesToKeep,"contains"); TFile* Minimal11File= new TFile("MinimalCC11.root","RECREATE"); TTree* Minimal11Tree=CC11Reader->CopyTree(ControlCuts::AllCuts11,-1,"DecayTree"); TTree* MinimalFlagged11Tree=HandyFunctions::GetSingleTree(MultiCandRand,Minimal11Tree,ControlChannelMultiCands,NULL); MinimalFlagged11Tree->Write(); Minimal11File->Close(); TreeReader* FlaggedReader= new TreeReader("DecayTree"); FlaggedReader->AddFile("MinimalCC12.root"); FlaggedReader->AddFile("MinimalCC11.root"); FlaggedReader->Initialize(); TFile* CCSingleFile= new TFile("CCSingleFile.root","RECREATE"); TTree* SingleTree=FlaggedReader->CopyTree("isSingle==1",-1,"DecayTree"); SingleTree->Write(); CCSingleFile->Close(); } //_____________________________________Make Rare Mode One Data__________________________________________________ if(remakerare) { std::string RareDataPath=std::getenv("LBPKETAPPIPIGDATABDTRESPROOT"); DataFile Rare12A(RareDataPath,Data,Twel,MagAll,lbpketappipig,"BDTApplied_SampleA_NB"); DataFile Rare12B(RareDataPath,Data,Twel,MagAll,lbpketappipig,"BDTApplied_SampleB_NB"); DataFile Rare11A(RareDataPath,Data,Elev,MagAll,lbpketappipig,"BDTApplied_SampleA_NB"); DataFile Rare11B(RareDataPath,Data,Elev,MagAll,lbpketappipig,"BDTApplied_SampleB_NB"); TreeReader* Rare12Reader= new TreeReader("DecayTree"); Rare12Reader->AddFile(Rare12A); Rare12Reader->AddFile(Rare12B); Rare12Reader->Initialize(pipigCuts::BranchesToKeep,"contains"); TFile* Minimal12File= new TFile("MinimalRare12.root","RECREATE"); TTree* Minimal12Tree=Rare12Reader->CopyTree(pipigCuts::AllCuts12,-1,"DecayTree"); TTree* MinimalFlagged12Tree=HandyFunctions::GetSingleTree(MultiCandRand,Minimal12Tree,RareChannelMultiCands,NULL); MinimalFlagged12Tree->Write(); Minimal12File->Close(); TreeReader* Rare11Reader= new TreeReader("DecayTree"); Rare11Reader->AddFile(Rare11A); Rare11Reader->AddFile(Rare11B); Rare11Reader->Initialize(pipigCuts::BranchesToKeep,"contains"); TFile* Minimal11File= new TFile("MinimalRare11.root","RECREATE"); TTree* Minimal11Tree=Rare11Reader->CopyTree(pipigCuts::AllCuts11,-1,"DecayTree"); TTree* MinimalFlagged11Tree=HandyFunctions::GetSingleTree(MultiCandRand,Minimal11Tree,RareChannelMultiCands,NULL); MinimalFlagged11Tree->Write(); Minimal11File->Close(); TreeReader* FlaggedReader= new TreeReader("DecayTree"); FlaggedReader->AddFile("MinimalRare12.root"); FlaggedReader->AddFile("MinimalRare11.root"); FlaggedReader->Initialize(); TFile* RareSingleFile= new TFile("RareSingleFile.root","RECREATE"); TTree* SingleTree=FlaggedReader->CopyTree("isSingle==1",-1,"DecayTree"); SingleTree->Write(); RareSingleFile->Close(); } //___________________________________ Make Rare mode Two Data________________________________________________ if(remakerare2) { std::string Rare2DataPath=std::getenv("LBPKETAPETADATABDTRESPROOT"); DataFile Rare212A(Rare2DataPath,Data,Twel,MagAll,lbpketapeta,"BDTApplied_SampleA_NB"); DataFile Rare212B(Rare2DataPath,Data,Twel,MagAll,lbpketapeta,"BDTApplied_SampleB_NB"); DataFile Rare211A(Rare2DataPath,Data,Elev,MagAll,lbpketapeta,"BDTApplied_SampleA_NB"); DataFile Rare211B(Rare2DataPath,Data,Elev,MagAll,lbpketapeta,"BDTApplied_SampleB_NB"); TreeReader* Rare212Reader= new TreeReader("DecayTree"); Rare212Reader->AddFile(Rare212A); Rare212Reader->AddFile(Rare212B); Rare212Reader->Initialize(etapetaCuts::BranchesToKeep,"contains"); TFile* Minimal12File= new TFile("MinimalRare212.root","RECREATE"); TTree* Minimal12Tree=Rare212Reader->CopyTree(etapetaCuts::AllCuts12,-1,"DecayTree"); TTree* MinimalFlagged12Tree=HandyFunctions::GetSingleTree(MultiCandRand,Minimal12Tree,Rare2ChannelMultiCands,NULL); MinimalFlagged12Tree->Write(); Minimal12File->Close(); TreeReader* Rare211Reader= new TreeReader("DecayTree"); Rare211Reader->AddFile(Rare211A); Rare211Reader->AddFile(Rare211B); Rare211Reader->Initialize(etapetaCuts::BranchesToKeep,"contains"); TFile* Minimal11File= new TFile("MinimalRare211.root","RECREATE"); TTree* Minimal11Tree=Rare211Reader->CopyTree(etapetaCuts::AllCuts11,-1,"DecayTree"); TTree* MinimalFlagged11Tree=HandyFunctions::GetSingleTree(MultiCandRand,Minimal11Tree,Rare2ChannelMultiCands,NULL); MinimalFlagged11Tree->Write(); Minimal11File->Close(); TreeReader* FlaggedReader= new TreeReader("DecayTree"); FlaggedReader->AddFile("MinimalRare212.root"); FlaggedReader->AddFile("MinimalRare211.root"); FlaggedReader->Initialize(); TFile* Rare2SingleFile= new TFile("Rare2SingleFile.root","RECREATE"); TTree* SingleTree=FlaggedReader->CopyTree("isSingle==1",-1,"DecayTree"); SingleTree->Write(); Rare2SingleFile->Close(); } //____________________________________ Shared Parameters_______________________________________________________ RooRealVar DataMCRatio("DataMCRatio","DataMCRatio",1.0,0.5,1.5); RooRealVar CCMean("CCMean","CCMean",5279.0,5250.0,5310.0); RooFormulaVar LambdabMean("LambdabMean","LambdabMean","@0+339.72",RooArgList(CCMean)); //RooRealVar LambdabMean("LambdabMean","LambdabMean",5619.0,5615.0,5630.0); // RooFormulaVar CCMean("CCMean","CCMean","@0 - 339.72",RooArgList(LambdabMean)); std::vector<RooRealVar*> FreeParameters; FreeParameters.push_back(&DataMCRatio); // FreeParameters.push_back(&LambdabMean); //____________________________________ Control Channel PDF______________________________________________________ TFile* CCInputFile = new TFile("CCSingleFile.root"); TTree* CCInputTree=(TTree*)CCInputFile->Get("DecayTree"); RooRealVar CCBMass("Bu_DTF_MF","Bu_DTF_MF",5000.0,5550.0); RooRealVar CCEtaMass("eta_prime_MM","eta_prime_MM",880.0,1040.0); RooArgSet CCArgs(CCBMass,CCEtaMass); RooDataSet* CCData=new RooDataSet("CCData","CCData",CCArgs,Import(*CCInputTree)); //++++++++++++++++++++++++++++++Signal PDF+++++++++++++++++++++++++++++++++ TFile *CCMCFitResultFile = new TFile("CCFitResult.root"); RooFitResult* CCMCFitResult=NULL; try { CCMCFitResult=SafeGetFitResult(CCMCFitResultFile,"CCFitResult"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } CCMCFitResult->Print("v"); RooRealVar* CCMCSigma=NULL; RooRealVar* CCMCLAlphaFix=NULL; RooRealVar* CCMCRAlphaFix=NULL; RooRealVar* CCMCLNFix=NULL; RooRealVar* CCMCRNFix=NULL; try { CCMCSigma=SafeGetVar(CCMCFitResult,"CCSigma"); CCMCLAlphaFix=SafeGetVar(CCMCFitResult,"CCLAlpha"); CCMCRAlphaFix=SafeGetVar(CCMCFitResult,"CCRAlpha"); CCMCLNFix=SafeGetVar(CCMCFitResult,"CCLN"); CCMCRNFix=SafeGetVar(CCMCFitResult,"CCRN"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RooRealVar CCMCSigmaFix("CCMCSigmaFix","CCMCSigmaFix",CCMCSigma->getVal()); CCMCSigmaFix.setConstant(kTRUE); RooFormulaVar CCSigma("CCSigma","CCSigma","@0*@1",RooArgList(DataMCRatio,CCMCSigmaFix)); RooRealVar CCLAlpha("CCLAlpha","CCLAlpha",CCMCLAlphaFix->getVal()); RooRealVar CCRAlpha("CCRAlpha","CCRAlpha",CCMCRAlphaFix->getVal()); RooRealVar CCLN("CCLN","CCLN",CCMCLNFix->getVal()); RooRealVar CCRN("CCRN","CCRN",CCMCRNFix->getVal()); RooCBShape CCDCBLeft("CCDCBLeft","CCDCBLeft",CCBMass,CCMean,CCSigma,CCLAlpha,CCLN); RooCBShape CCDCBRight("CCDCBRight","CCDCBRight",CCBMass,CCMean,CCSigma,CCRAlpha,CCRN); RooRealVar CCFitFraction("CCFitFraction","CCFitFraction",0.5,0.0,1.0); FreeParameters.push_back(&CCFitFraction); RooAddPdf CCDCB("CCDCB","CCDCB",RooArgList(CCDCBRight,CCDCBLeft),CCFitFraction); RooRealVar CCEtamean("CCEtamean","CCEtamean",958.0,955.0,960.0); RooRealVar CCEtasigma("CCEtasigma","CCEtasigma",9.16,9.0,15.0); RooRealVar* CCMCEtaLAlpha=NULL; RooRealVar* CCMCEtaRAlpha=NULL; RooRealVar* CCMCEtaLN=NULL; RooRealVar* CCMCEtaRN=NULL; try { CCMCEtaLAlpha=SafeGetVar(CCMCFitResult,"CCEtaLAlpha"); CCMCEtaRAlpha=SafeGetVar(CCMCFitResult,"CCEtaRAlpha"); CCMCEtaLN=SafeGetVar(CCMCFitResult,"CCEtaLN"); CCMCEtaRN=SafeGetVar(CCMCFitResult,"CCEtaRN"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RooRealVar CCEtaLAlpha("CCEtaLAlpha","CCEtaLAlpha",CCMCEtaLAlpha->getVal()); RooRealVar CCEtaRAlpha("CCEtaRAlpha","CCEtaRAlpha",CCMCEtaRAlpha->getVal()); RooRealVar CCEtaLN("CCEtaLN","CCEtaLN",CCMCEtaLN->getVal()); RooRealVar CCEtaRN("CCEtaRN","CCEtaRN",CCMCEtaRN->getVal()); RooCBShape CCEtaDCBLeft("CCEtaCBLeft","CCEtaCBLeft",CCEtaMass,CCEtamean,CCEtasigma,CCEtaLAlpha,CCEtaLN); RooCBShape CCEtaDCBRight("CCEtaCBRight","CCEtaCBRight",CCEtaMass,CCEtamean,CCEtasigma,CCEtaRAlpha,CCEtaRN); RooRealVar CCEtaFitFraction("CCEtaFitFraction","CCEtaFitFraction",0.22,0.1,1.0); FreeParameters.push_back(&CCEtaFitFraction); RooAddPdf CCEtaDCB("CCEteaDCB","CCEtaDCB",RooArgList(CCEtaDCBRight,CCEtaDCBLeft),CCEtaFitFraction); RooProdPdf CCSignalPdf("CCSignalPdf","CCSignalPdf",RooArgSet(CCEtaDCB,CCDCB)); RooRealVar CCSignalYield("CCSignalYield","CCSignalYield",10000.0,1000.0,20000.0); RooExtendPdf CCExtendedSignalPdf("CCExtendedSignalPdf","CCExtendedSignalPdf",CCSignalPdf,CCSignalYield); //+++++++++++++++++++++++++++++++++ COMB NO ETAP PDF++++++++++++++++++++++++++++++++++++++++ RooRealVar CCNoEtaBSlope("CCNoEtaBSlope","CCNoEtaBSlope",-0.6,-0.8,-0.4); FreeParameters.push_back(&CCNoEtaBSlope); RooRealVar CCNoEtaBCurve("CCNoEtaBCurve","CCNoEtaBCurve",-0.1,-0.30,-0.05); FreeParameters.push_back(&CCNoEtaBCurve); RooChebychev CCNoEtaBLine("CCNoEtaBLine","CCNoEtaBLine",CCBMass,RooArgList(CCNoEtaBSlope,CCNoEtaBCurve)); RooRealVar CCNoEtaEtaP1("CCNoEtaEtaP1","CCNoEtaEtaP1",-0.1,-1.0,0.0); FreeParameters.push_back(&CCNoEtaEtaP1); RooRealVar CCNoEtaEtaP2("CCNoEtaEtaP2","CCNoEtaEtaP2",-0.1,-0.8,0.0); FreeParameters.push_back(&CCNoEtaEtaP2); RooChebychev CCNoEtaQuad("CCNoEtaQuad","CCNoEtaQuad",CCEtaMass,RooArgList(CCNoEtaEtaP1,CCNoEtaEtaP2)); RooProdPdf CCNoEtaBkgPdf("CCNoEtaBkgPdf","CCNoEtaBkgPdf",RooArgSet(CCNoEtaQuad,CCNoEtaBLine)); RooRealVar CCNoEtaBkgYield("CCNoEtaBkgYield","CCNoEtaBkgYield",2400.0,500.0,15000.0); RooExtendPdf ExtCCNoEtaBkgPdf("ExtCCNoEtaBkgPdf","ExtCCNoEtaBkgPdf",CCNoEtaBkgPdf,CCNoEtaBkgYield); //++++++++++++++++++++++++++++++++++ COMB TRUE ETAP PDF++++++++++++++++++++++++++++++++++ RooRealVar CCTrueEtaBSlope("CCTrueEtaBSlope","CCTrueEtaBSlope",-0.1,-1.0,0.0); FreeParameters.push_back(&CCTrueEtaBSlope); RooChebychev CCTrueEtaBLine("CCTrueEtaBLine","CCTrueEtaBLine",CCBMass,RooArgList(CCTrueEtaBSlope)); RooRealVar CCTrueEtaEtaLAlpha("CCTrueEtaEtaLAlpha","CCTrueEtaEtaLAlpha",CCMCEtaLAlpha->getVal()); RooRealVar CCTrueEtaEtaRAlpha("CCTrueEtaEtaRAlpha","CCTrueEtaEtaRAlpha",CCMCEtaRAlpha->getVal()); RooRealVar CCTrueEtaEtaLN("CCTrueEtaEtaLN","CCTrueEtaEtaLN",CCMCEtaLN->getVal()); RooRealVar CCTrueEtaEtaRN("CCTrueEtaEtaRN","CCTrueEtaEtaRN",CCMCEtaRN->getVal()); //RooCBShape CCTrueEtaEtaCBLeft("CCTrueEtaEtaCBLeft","CCTrueEtaEtaCBLeft",CCEtaMass,CCEtamean,CCEtasigma,CCTrueEtaEtaLAlpha,CCTrueEtaEtaLN); RooCBShape CCTrueEtaEtaCBRight("CCTrueEtaEtaCBRight","CCTrueEtaEtaCBRight",CCEtaMass,CCEtamean,CCEtasigma,CCTrueEtaEtaRAlpha,CCTrueEtaEtaRN); // RooRealVar CCTrueEtaEtaFitFraction("CCTrueEtaEtaFitFraction","CCTrueEtaEtaFitFraction",0.4,0.0,1.0); //RooAddPdf CCTrueEtaEtaDCB("CCTrueEtaEtaDCB","CCTrueEtaEtaDCB",RooArgList(CCTrueEtaEtaCBRight,CCTrueEtaEtaCBLeft),CCTrueEtaEtaFitFraction); RooProdPdf CCTrueEtaEtaBkgPdf("CCTrueEtaEtaBkgPdf","CCTrueEtaEtaBkgPdf",RooArgSet(CCTrueEtaEtaCBRight,CCTrueEtaBLine)); RooRealVar CCTrueEtaBkgYield("CCTrueEtaBkgYield","CCTrueEtaBkgYield",800.0,20.0,10000.0); RooExtendPdf ExtCCTrueEtaBkgPdf("ExtCCTrueEtaBkgPdf","ExtCCTrueEtaBkgPdf",CCTrueEtaEtaBkgPdf,CCTrueEtaBkgYield); RooAddPdf CCTotalPdf("CCTotalPdf","CCTotalPdf",RooArgList(ExtCCTrueEtaBkgPdf,ExtCCNoEtaBkgPdf,CCExtendedSignalPdf)); //_________________________________Rare1 Fit_____________________________ TFile * RareInputFile = new TFile("RareSingleFile.root"); TTree* RareInputTree=NULL; try { RareInputTree=SafeGetTree(RareInputFile,"DecayTree"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RooRealVar LbMass("Lambda_b0_DTF_MF","Lambda_b0_DTF_MF",5200.0,6000.0); RooRealVar RareLambda_b0_PE("Lambda_b0_PE","Lambda_b0_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareLambda_b0_PX("Lambda_b0_PX","Lambda_b0_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareLambda_b0_PY("Lambda_b0_PY","Lambda_b0_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareLambda_b0_PZ("Lambda_b0_PZ","Lambda_b0_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareProton_PE("Proton_PE","Proton_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareProton_PX("Proton_PX","Proton_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareProton_PY("Proton_PY","Proton_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareProton_PZ("Proton_PZ","Proton_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareKaon_PE("Kaon_PE","Kaon_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareKaon_PX("Kaon_PX","Kaon_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareKaon_PY("Kaon_PY","Kaon_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar RareKaon_PZ("Kaon_PZ","Kaon_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rareeta_prime_PE("eta_prime_PE","eta_prime_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rareeta_prime_PX("eta_prime_PX","eta_prime_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rareeta_prime_PY("eta_prime_PY","eta_prime_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rareeta_prime_PZ("eta_prime_PZ","eta_prime_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooArgSet RareArgs(LbMass,RareLambda_b0_PE,RareLambda_b0_PX,RareLambda_b0_PY,RareLambda_b0_PZ,RareProton_PE,RareProton_PX,RareProton_PY,RareProton_PZ); RareArgs.add(RareKaon_PE); RareArgs.add(RareKaon_PX); RareArgs.add(RareKaon_PY); RareArgs.add(RareKaon_PZ); RareArgs.add(Rareeta_prime_PE); RareArgs.add(Rareeta_prime_PX); RareArgs.add(Rareeta_prime_PY); RareArgs.add(Rareeta_prime_PZ); RooDataSet* RareData= new RooDataSet("RareData","RareData",RareArgs,Import(*RareInputTree)); TFile * RareFitResultFile = new TFile("RareFitResult.root"); RooFitResult* RareMCFitResult=NULL; try { RareMCFitResult=SafeGetFitResult(RareFitResultFile,"RareFitResult"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RareMCFitResult->Print("v"); RooRealVar* RareMCRAlpha=NULL; RooRealVar* RareMCFitFraction=NULL; RooRealVar* RareMCLAlpha=NULL; RooRealVar* RareMCLN=NULL; RooRealVar* RareMCRN=NULL; RooRealVar* RareMCSigma=NULL; try { RareMCRAlpha=SafeGetVar(RareMCFitResult,"RareAlpha"); RareMCFitFraction=SafeGetVar(RareMCFitResult,"RareFitFraction"); RareMCLAlpha=SafeGetVar(RareMCFitResult,"RareLAlpha"); RareMCLN=SafeGetVar(RareMCFitResult,"RareLN"); RareMCRN=SafeGetVar(RareMCFitResult,"RareRN"); RareMCSigma=SafeGetVar(RareMCFitResult,"RareSigma"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } //++++++++++++++++++++++++++++++Rare Signal PDF++++++++++++++++++++++++++++ RooRealVar RareMCSigmaFix("RareMCSigmaFix","RareMCSigmaFix",RareMCSigma->getVal()); RareMCSigmaFix.setConstant(); RooFormulaVar RareSigma("RareSigma","RareSigma","@0*@1",RooArgSet(RareMCSigmaFix,DataMCRatio)); RooRealVar RareLAlpha("RareLAlpha","RareLAlpha",RareMCLAlpha->getVal()); RooRealVar RareRAlpha("RareRAlpha","RareRAlpha",RareMCRAlpha->getVal()); RooRealVar RareRN("RareRN","RareRN",RareMCRN->getVal()); RooRealVar RareLN("RareLN","RareLN",RareMCLN->getVal()); RooRealVar RareFitFraction("RareFitFraction","RareFitFraction",RareMCFitFraction->getVal()); RooCBShape RareDCBLeft("DCBLeft","DCBLeft",LbMass,LambdabMean,RareSigma,RareLAlpha,RareLN); RooCBShape RareDCBRight("DCBRight","DCBRight",LbMass,LambdabMean,RareSigma,RareRAlpha,RareRN); RooAddPdf RareDCB("RareDCB","RareDCB",RooArgList(RareDCBLeft,RareDCBRight),RareFitFraction); RooRealVar RareYield("RareYield","RareYield",40.0,-100.0,1000.0); RooExtendPdf RareSignalPdf("RareSignalPdf","RareSignalPdf",RareDCB,RareYield); //++++++++++++++++++++++++++++++Rare Combinatorial Bkg+++++++++++++++++++++++++++++++++++ RooRealVar Rarep1("Rarep1","Rarep1",-1.1,-5.0,-0.1); FreeParameters.push_back(&Rarep1); RooRealVar Rarep2("Rarep2","Rarep2",0.5,0.001,10.0); FreeParameters.push_back(&Rarep2); RooChebychev RarePoly("RarePoly","RarePoly",LbMass,RooArgList(Rarep1,Rarep2)); RooRealVar RareBkgYield("RareBkgYield","RareBkgYield",2000.0,0.0,10000.0); RooExtendPdf RareBkgPdf("RareBkgPdf","RareBkgPdf",RarePoly,RareBkgYield); //++++++++++++++++++++++++++++Rare PKPhi Bkg+++++++++++++++++++++++++++++++++ TFile* PKPhiMCFitresultFile= new TFile("PkPhiFitResultFile.root"); RooFitResult* PKPhiMCFitResult=NULL; try { PKPhiMCFitResult=SafeGetFitResult(PKPhiMCFitresultFile,"PkPhiFitResult"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } PKPhiMCFitResult->Print("v"); RooRealVar* PkPhiMean=NULL; RooRealVar* PkPhiSigma=NULL; RooRealVar* PkPhiLAlpha=NULL; RooRealVar* PkPhiRAlpha=NULL; RooRealVar* PkPhiLN=NULL; RooRealVar* PkPhiRN=NULL; try { PkPhiMean=SafeGetVar(PKPhiMCFitResult,"PkPhiMean"); PkPhiSigma=SafeGetVar(PKPhiMCFitResult,"PkPhiSigma"); PkPhiLAlpha=SafeGetVar(PKPhiMCFitResult,"PkPhiLAlpha"); PkPhiLN=SafeGetVar(PKPhiMCFitResult,"PkPhiLN"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RooRealVar RarePkPhiMean("RarePkPhiMean","RarePkPhiMean",PkPhiMean->getVal()); RooRealVar RarePkPhiSigma("RarePkPhiSigma","RarePkPhiSigma",PkPhiSigma->getVal()); RooRealVar RarePkPhiLN("RarePkPhiLN","RarePkPhiLN",PkPhiLN->getVal()); RooRealVar RarePkPhiLAlpha("RarePkPhiLAlpha","RarePkPhiLAlpha",PkPhiLAlpha->getVal()); RooCBShape RarePkPhiModel("RarePkPhiModel","RarePkPhiModel",LbMass,RarePkPhiMean,RarePkPhiSigma,RarePkPhiLAlpha,RarePkPhiLN); RooRealVar RarePkPhiYield("RarePkPhiYield","RarePkPhiYield",50.0,1.0,150.0); RooExtendPdf RarePkPhiPdf("RarePkPhiPdf","RarePkPhiPdf",RarePkPhiModel,RarePkPhiYield); RooAddPdf RarePdf("RarePdf","RarePdf",RooArgList(RarePkPhiPdf,RareBkgPdf,RareSignalPdf)); /*RarePdf.fitTo(*RareData,Extended(kTRUE)); RooPlot* RareFrame=LbMass.frame(Bins(35),Range(5200.0,6100.0)); TCanvas RareCanvas; RareData->plotOn(RareFrame); RarePdf.plotOn(RareFrame); RareFrame->Draw(); RareCanvas.SaveAs("RareCanvas.pdf");*/ //________________________________ Fit Rare 2_______________________________ TFile* Rare2InputFile = new TFile("Rare2SingleFile.root"); TTree* Rare2InputTree=NULL; try { Rare2InputTree=SafeGetTree(Rare2InputFile,"DecayTree"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RooRealVar Rare2Lambda_b0_PE("Lambda_b0_PE","Lambda_b0_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Lambda_b0_PX("Lambda_b0_PX","Lambda_b0_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Lambda_b0_PY("Lambda_b0_PY","Lambda_b0_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Lambda_b0_PZ("Lambda_b0_PZ","Lambda_b0_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Proton_PE("Proton_PE","Proton_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Proton_PX("Proton_PX","Proton_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Proton_PY("Proton_PY","Proton_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Proton_PZ("Proton_PZ","Proton_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Kaon_PE("Kaon_PE","Kaon_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Kaon_PX("Kaon_PX","Kaon_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Kaon_PY("Kaon_PY","Kaon_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2Kaon_PZ("Kaon_PZ","Kaon_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2eta_prime_PE("eta_prime_PE","eta_prime_PE",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2eta_prime_PX("eta_prime_PX","eta_prime_PX",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2eta_prime_PY("eta_prime_PY","eta_prime_PY",-RooNumber::infinity(),RooNumber::infinity()); RooRealVar Rare2eta_prime_PZ("eta_prime_PZ","eta_prime_PZ",-RooNumber::infinity(),RooNumber::infinity()); RooArgSet Rare2Args(LbMass,Rare2Lambda_b0_PE,Rare2Lambda_b0_PX,Rare2Lambda_b0_PY,Rare2Lambda_b0_PZ,Rare2Proton_PE,Rare2Proton_PX,Rare2Proton_PY,Rare2Proton_PZ); Rare2Args.add(Rare2Kaon_PE); Rare2Args.add(Rare2Kaon_PX); Rare2Args.add(Rare2Kaon_PY); Rare2Args.add(Rare2Kaon_PZ); Rare2Args.add(Rare2eta_prime_PE); Rare2Args.add(Rare2eta_prime_PX); Rare2Args.add(Rare2eta_prime_PY); Rare2Args.add(Rare2eta_prime_PZ); RooDataSet* Rare2Data=new RooDataSet("Rare2Data","Rare2Data",Rare2Args,Import(*Rare2InputTree)); TFile* Rare2MCFitResultFile= new TFile("RareTwoFitResult.root"); RooFitResult* Rare2MCFitResult=NULL; try { Rare2MCFitResult=SafeGetFitResult(Rare2MCFitResultFile,"RareTwoFitResult"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } //++++++++++++++++++++++++++++++Signal PDF++++++++++++++++++++++++++++++++ RooRealVar* Rare2MCFitFraction=NULL; RooRealVar* Rare2MCLAlpha=NULL; RooRealVar* Rare2MCLN=NULL; RooRealVar* Rare2MCRN=NULL; RooRealVar* Rare2MCRAlpha=NULL; RooRealVar* Rare2MCSigma=NULL; try { Rare2MCFitFraction=SafeGetVar(Rare2MCFitResult,"Rare2FitFraction"); Rare2MCLAlpha=SafeGetVar(Rare2MCFitResult,"Rare2LAlpha"); Rare2MCLN=SafeGetVar(Rare2MCFitResult,"Rare2LN"); Rare2MCRN=SafeGetVar(Rare2MCFitResult,"Rare2RN"); Rare2MCRAlpha=SafeGetVar(Rare2MCFitResult,"Rare2RAlpha"); Rare2MCSigma=SafeGetVar(Rare2MCFitResult,"Rare2Sigma"); } catch(std::exception &e) { std::cout<<e.what()<<std::endl; return 1; } RooRealVar Rare2SigmaFix("Rare2SigmaFix","Rare2SigmaFix",Rare2MCSigma->getVal()); RooFormulaVar Rare2Sigma("Rare2Sigma","Rare2Sigma","@0*@1",RooArgList(Rare2SigmaFix,DataMCRatio)); RooRealVar Rare2LN("Rare2LN","Rare2LN",Rare2MCLN->getVal()); RooRealVar Rare2RN("Rare2RN","Rare2RN",Rare2MCRN->getVal()); RooRealVar Rare2RAlpha("Rare2RAlpha","Rare2RAlpha",Rare2MCRAlpha->getVal()); RooRealVar Rare2LAlpha("Rare2LAlpha","Rare2LAlpha",Rare2MCLAlpha->getVal()); RooRealVar Rare2FitFraction("Rare2FitFraction","Rare2FitFraction",Rare2MCFitFraction->getVal()); RooCBShape Rare2CBLeft("Rare2CBLeft","Rare2CBLeft",LbMass,LambdabMean,Rare2Sigma,Rare2LAlpha,Rare2LN); RooCBShape Rare2CBRight("Rare2CBRight","Rare2CBRight",LbMass,LambdabMean,Rare2Sigma,Rare2RAlpha,Rare2RN); RooAddPdf Rare2DCB("Rare2DCB","Rare2DCB",RooArgList(Rare2CBLeft,Rare2CBRight),Rare2FitFraction); RooRealVar Rare2SignalYield("Rare2SignalYield","Rare2SignalYield",100.0,-100.0,1000.0); RooExtendPdf Rare2SignalPdf("Rare2SignalPdf","Rare2SignalPdf",Rare2DCB,Rare2SignalYield); //++++++++++++++++++++++++++++++Rare 2 Bkg pdf++++++++++++++++++++++++++++++ RooRealVar Rare2K("K","K",-0.003,-0.1,0.0); RooExponential Rare2BkgExp("Rare2BkgExp","Rare2BkgExp",LbMass,Rare2K); RooRealVar Rare2BkgYield("Rare2BkgYield","Rare2BkgYield",2000.0,0.0,100000.0); RooExtendPdf Rare2BkgPdf("Rare2BkgPdf","Rare2BkgPdf",Rare2BkgExp,Rare2BkgYield); RooAddPdf Rare2Pdf("Rare2Pdf","Rare2Pdf",RooArgList(Rare2SignalPdf,Rare2BkgPdf)); //___________________________________ SImultaneous Part ________________________________________________________ RooCategory Channel("Channel","Channel"); Channel.defineType("Rare"); Channel.defineType("Rare2"); Channel.defineType("Control"); RooDataSet* AllData = new RooDataSet("AllData","AllData",RooArgSet(LbMass,CCBMass,CCEtaMass),Index(Channel),Import("Rare",*RareData),Import("Rare2",*Rare2Data),Import("Control",*CCData)); RooSimultaneous SimPdf("SimPdf","SimPdf",Channel); SimPdf.addPdf(Rare2Pdf,"Rare2"); SimPdf.addPdf(RarePdf,"Rare"); SimPdf.addPdf(CCTotalPdf,"Control"); RooDataSet* BlindedData=NULL; RooFitResult* SimResult=NULL; if(blind) { LbMass.setRange("RLSB",5200.0,RareLowerBlind); LbMass.setRange("RUSB",RareUpperBlind,6000.0); LbMass.setRange("R2LSB",5200.0,Rare2LowerBlind); LbMass.setRange("R2USB",Rare2UpperBlind,6000.0); LbMass.setRange("RDLSB",5200.0,5493.33333); LbMass.setRange("RDUSB",RareUpperBlind,6000.0); std::string CutString="Lambda_b0_DTF_MF<"+std::to_string(RareLowerBlind)+"||Lambda_b0_DTF_MF>"+std::to_string(Rare2UpperBlind); BlindedData=(RooDataSet*)AllData->reduce(CutString.data()); RooMsgService::instance().setSilentMode(kTRUE); RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL) ; } RooArgSet MinosPars(Rare2SignalYield,RareYield,CCSignalYield); SimResult = SimPdf.fitTo(*AllData,Save(kTRUE),Extended(kTRUE),Minos(MinosPars)); SimPdf.Print("v"); RooPlot* NominalLikelihoodRareYield=RareYield.frame(Title("Likelihood scan of RareYield"),Range(50,150)); RooAbsReal* nll = SimPdf.createNLL(*AllData,NumCPU(2),Extended(kTRUE)); TCanvas C; nll->plotOn(NominalLikelihoodRareYield,ShiftToZero()); NominalLikelihoodRareYield->Draw(); C.SaveAs("NominalLikelihood.pdf"); // HandyFunctions::SetlhcbStyle(); //_______________________________ Plot B+ Canvas_____________________________________________________________ RooPlot* CCBFrame= CCBMass.frame(Bins(50),Range(5000.0,5500.0),Title("Control Channel B+ Mass Projection")); AllData->plotOn(CCBFrame,Cut("Channel==Channel::Control")); SimPdf.plotOn(CCBFrame,Slice(Channel,"Control"),Components("ExtCCTrueEtaBkgPdf"),LineColor(kMagenta),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(CCBFrame,Slice(Channel,"Control"),Components("ExtCCNoEtaBkgPdf"),LineColor(kGreen),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(CCBFrame,Slice(Channel,"Control"),Components("CCExtendedSignalPdf"),LineColor(kRed),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(CCBFrame,Slice(Channel,"Control"),ProjWData(Channel,*AllData)); TCanvas* CCBCanvas=HandyFunctions::DecoratePlot(CCBFrame); /*(TCanvas* CCBCanvas= new TCanvas("CCBCanvas","CCBCanvas",1600,900); CCBFrame->Draw(); CCBCanvas->SaveAs("CCBCanvas.eps");*/ //________________________________Plot Eta Canvas_____________________________________________________________ RooPlot* CCEtaFrame=CCEtaMass.frame(Bins(50),Range(880.0,1040.0),Title("Control Channel Eta' Projection")); AllData->plotOn(CCEtaFrame,Cut("Channel==Channel::Control")); SimPdf.plotOn(CCEtaFrame,Slice(Channel,"Control"),Components("ExtCCTrueEtaBkgPdf"),LineColor(kMagenta),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(CCEtaFrame,Slice(Channel,"Control"),Components("ExtCCNoEtaBkgPdf"),LineColor(kGreen),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(CCEtaFrame,Slice(Channel,"Control"),Components("CCExtendedSignalPdf"),LineColor(kRed),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(CCEtaFrame,Slice(Channel,"Control"),ProjWData(Channel,*AllData)); TCanvas* CCEtaCanvas=HandyFunctions::DecoratePlot(CCEtaFrame); /*TCanvas* CCEtaCanvas=new TCanvas("CCEtaCanvas","CCEtaCanvas",1600,900); CCEtaFrame->Draw(); CCEtaCanvas->Print("CCEtaCanvas.eps");*/ //________________________________Plot Rare Canvas_____________________________________________________________ RooPlot* RareFrame=LbMass.frame(Bins(30),Range(5200.0,6000.0),Title("#Lambda_{b} -> p K (#eta' -> #pi #pi #gamma) ;M(#Lambda_{b})")); if(blind) { double sidebandsN = RareData ->sumEntries("1","RLSB,RUSB"); double LowsidebandsN = RareData ->sumEntries("1","RLSB"); RareData->plotOn(RareFrame,CutRange("RDLSB,RDUSB"),Name("RareDataPlotted")); RarePdf.plotOn(RareFrame,Range("RLSB,RUSB"),Components("RarePkPhiPdf"),Name("RarePkPhiBkg"),LineColor(kMagenta),LineStyle(kDashed),Normalization(sidebandsN,RooAbsReal::NumEvent)); RarePdf.plotOn(RareFrame,Range("RLSB,RUSB"),Components("RareBkgPdf"),Name("RareCombBkg"),LineColor(kGreen),LineStyle(kDashed),Normalization(sidebandsN,RooAbsReal::NumEvent)); RarePdf.plotOn(RareFrame,Range("RLSB,RUSB"),Normalization(sidebandsN,RooAbsReal::NumEvent)); } else { AllData->plotOn(RareFrame,Cut("Channel==Channel::Rare")); SimPdf.plotOn(RareFrame,Slice(Channel,"Rare"),Components("RarePkPhiPdf"),LineColor(kMagenta),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(RareFrame,Slice(Channel,"Rare"),Components("RareBkgPdf"),LineColor(kGreen),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(RareFrame,Slice(Channel,"Rare"),Components("RareSignalPdf"),LineColor(kRed),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(RareFrame,Slice(Channel,"Rare"),ProjWData(Channel,*AllData)); } int i=RareFrame->numItems(); std::cout<<"_________________________________________"<<std::endl; for(int j=0; j<i; j++) { std::cout<<RareFrame->nameOf(j)<<std::endl; } TLegend * RareLegend = new TLegend(0.66,0.7,0.9,0.9); RareLegend->AddEntry(RareFrame->findObject("RarePkPhiBkg"),"#Lambda_{b} -> p K #phi bkg","l"); RareLegend->AddEntry(RareFrame->findObject("RareCombBkg"),"Combinatorial Background","l"); std::cout<<"++++++++++++++++++++++++++++++++++++++++++++"<<std::endl; RooHist* Pulls=RareFrame->pullHist(0,"RarePdf_Norm[Lambda_b0_DTF_MF]"); TCanvas* RareCanvas=HandyFunctions::DecoratePlot(RareFrame,"DecoratedRareCanvas"); RareCanvas->Print("RareCanvas.pdf"); TCanvas * PullCanvas=new TCanvas("RarePullCanvas","RarePullCanvas",1200,1000); Pulls->Draw("AP"); PullCanvas->SaveAs("RarePulls.pdf"); TCanvas *RareNoPullCanvas = new TCanvas("RareFitCanvas","RareFitCanvas",1600,900); RareFrame->Draw(); RareLegend->Draw(); RareNoPullCanvas->Print("RareNoPullCanvasPrinted.eps"); //_______________________________Plot Rare2 Canvas_____________________________________________________________ RooPlot* Rare2Frame=LbMass.frame(Bins(25),Range(5200.0,6000.),Title("#Lambda_{b} -> p K (#eta' -> #pi #pi #eta);M(#Lambda_{b})")); if(blind) { double Rare2sidebandsN= Rare2Data->sumEntries("1","R2LSB,R2USB"); Rare2Data->plotOn(Rare2Frame,CutRange("R2LSB,R2USB")); Rare2Pdf.plotOn(Rare2Frame,Range("R2LSB,R2USB"),Normalization(Rare2sidebandsN,RooAbsReal::NumEvent)); } else { AllData->plotOn(Rare2Frame,Cut("Channel==Channel::Rare2")); SimPdf.plotOn(Rare2Frame,Slice(Channel,"Rare2"),Components("Rare2BkgPdf"),LineColor(kGreen),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(Rare2Frame,Slice(Channel,"Rare2"),Components("Rare2SignalPdf"),LineColor(kRed),LineStyle(kDashed),ProjWData(Channel,*AllData)); SimPdf.plotOn(Rare2Frame,Slice(Channel,"Rare2"),ProjWData(Channel,*AllData)); } TCanvas* NoPullRare2= new TCanvas("NoPullRare2","NoPullRare2",1800,1000); Rare2Frame->Draw(); NoPullRare2->SaveAs("PiPiEtaFit.eps"); TCanvas* Rare2Canvas=HandyFunctions::DecoratePlot(Rare2Frame,"DecoratedRare2Canvas"); Rare2Canvas->SaveAs("Rare2Canvas.pdf"); if(blind) { RooArgSet NotBlind(CCEtamean,CCSignalYield,DataMCRatio,CCNoEtaBkgYield,CCTrueEtaBkgYield,CCMean,RareBkgYield,Rare2BkgYield,RarePkPhiYield); cout << "Fit complete" << endl; cout << "covQual:" << SimResult->covQual() << endl; cout << "EDM:" << SimResult->edm() << endl; cout << "FCN at min:" << SimResult->minNll() << endl; NotBlind.Print("s"); } TFile* DataFitResults= new TFile("DataFitResults.root","RECREATE"); RareNoPullCanvas->Write(); CCBCanvas->Write(); CCEtaCanvas->Write(); RareCanvas->Write(); Rare2Canvas->Write(); SimResult->Write("DataFitResult"); DataFitResults->Close(); RooWorkspace* Wkspc= new RooWorkspace("w","workspace"); Wkspc->import(SimPdf); // Wkspc->writeToFile("BigFitWorkspace.root"); Wkspc->writeToFile("TestBigFitWorkspace.root"); for(auto Var : FreeParameters) { Var->setConstant(); } RooStats::SPlot* sDataMass; if(sweight) { sDataMass = new RooStats::SPlot("sData","An SPlot",*RareData,&RarePdf,RooArgList(RarePkPhiYield,RareYield,RareBkgYield)); std::cout<<" Check SWeights: "<<std::endl; std::cout<<" BkgYield= "<<RareBkgYield.getVal()<<std::endl; std::cout<<" Bkg yield from sweights = "<<sDataMass->GetYieldFromSWeight("RareBkgYield")<<std::endl; } }
int read_file_and_draw() { Vertex *N0 , *N1 , *N2; double x,y,z; double max_x,max_y,max_z; double min_x,min_y,min_z; FILE *input; char title[50]; int vertex_number; int draw_times; int i; int point_count; int node0,node1,node2; int start_node; max_x = 0; max_y = 0; max_z = 0; min_x = 0; min_y = 0; min_z = 0; input = fopen ("data.txt","r"); fscanf(input,"%s",title); // read Vertices if( stricmp(title,"Vertices") != 0 ) //the first line is not Vertices { fprintf(stderr,"Input file syntax error!\n"); return -1; } fscanf(input,"%d",&vertex_number); for( i = 0 ; i < vertex_number ; i++ ) { fscanf(input,"%lf%lf%lf",&x,&y,&z); insert_vertex_point(x,y,-z); if ( x > max_x ) max_x = x; else if ( x < min_x ) min_x = x; if ( y > max_y ) max_y = y; else if ( y < min_y ) min_y = y; if ( z > max_z ) max_z = z; else if ( z < min_z ) min_z = z; } //Normalization Normalization( max_x , max_y , min_x , min_y , max_z , min_z); while( fscanf(input,"%s",title) == 1 ) { if( strcmp(title,"Line_segment") == 0) { fscanf( input , "%d" ,&draw_times ); for( i = 0 ; i < draw_times ; i++ ) { fscanf(input,"%d",&node0); fscanf(input,"%d",&node1); N0 = search_vertex(node0); N1 = search_vertex(node1); draw_line( N0->x , N0->y , N0->z , N1->x , N1->y , N1->z ); } } else if( stricmp(title,"Line_strip") == 0 ) { fscanf( input , "%d" ,&draw_times ); fscanf(input,"%d",&node0); for( i = 0 ; i < draw_times ; i++ ) { fscanf(input,"%d",&node1); N0 = search_vertex(node0); N1 = search_vertex(node1); draw_line( N0->x , N0->y , N0->z , N1->x , N1->y , N1->z ); node0 = node1; } } else if( stricmp(title,"Line_loop") == 0 ) { fscanf( input , "%d" ,&draw_times ); fscanf(input,"%d",&node0); start_node = node0; for( i = 0 ; i < draw_times -1; i++ ) { fscanf(input,"%d",&node1); N0 = search_vertex(node0); N1 = search_vertex(node1); draw_line( N0->x , N0->y , N0->z , N1->x , N1->y , N1->z ); node0 = node1; } N1 = search_vertex(start_node); N0 = search_vertex(node0); draw_line( N0->x , N0->y , N0->z , N1->x , N1->y , N1->z ); } else if( stricmp(title,"Triangle_fan") == 0) { fscanf( input , "%d" ,&draw_times ); fscanf( input , "%d" , &node0 ); fscanf( input , "%d" , &node1 ); N0 = search_vertex(node0); // point A N1 = search_vertex(node1); // point B start_node = node1; for( i = 0 ; i < draw_times ; i++ ) { fscanf( input , "%d" , &node2 ); N2 = search_vertex(node2); // point C draw_triangle(N0->x,N0->y,N0->z,N1->x,N1->y,N1->z,N2->x,N2->y,N2->z); N1 = N2; } } else if (stricmp(title,"Triangle_list") == 0 ) { fscanf( input , "%d" ,&draw_times ); for( i = 0 ; i < draw_times ; i++ ) { fscanf( input , "%d" , &node0 ); fscanf( input , "%d" , &node1 ); fscanf( input , "%d" , &node2 ); N0 = search_vertex(node0); // point A N1 = search_vertex(node1); // point B N2 = search_vertex(node2); // point C insert_trangle(N0,N1,N2); draw_triangle(N0->x,N0->y,N0->z,N1->x,N1->y,N1->z,N2->x,N2->y,N2->z); } //sort_trangle_node(draw_times) SORT = 1; trangle_number = draw_times; } else if( stricmp(title,"Triangle_strip") == 0 ) { fscanf( input , "%d" ,&draw_times ); fscanf( input , "%d" , &node0 ); fscanf( input , "%d" , &node1 ); N0 = search_vertex(node0); // point A N1 = search_vertex(node1); // point B for( i = 0 ; i < draw_times ; i++ ) { fscanf( input , "%d" , &node2 ); N2 = search_vertex(node2); // point C draw_triangle(N0->x,N0->y,N0->z,N1->x,N1->y,N1->z,N2->x,N2->y,N2->z); N0 = N1; N1 = N2; } } } //printf("%lf ,%lf , %lf\n",end_vertex_point->x,end_vertex_point->y,end_vertex_point->z); //system("pause"); }
void drawCtauFrom2DPlot(RooWorkspace& myws, // Local workspace string outputDir, // Output directory struct InputOpt opt, // Variable with run information (kept for legacy purpose) struct KinCuts cut, // Variable with current kinematic cuts map<string, string> parIni, // Variable containing all initial parameters string plotLabel, // The label used to define the output file name // Select the type of datasets to fit string DSTAG, // Specifies the type of datasets: i.e, DATA, MCJPSINP, ... bool isPbPb, // Define if it is PbPb (True) or PP (False) // Select the type of object to fit bool incJpsi, // Includes Jpsi model bool incPsi2S, // Includes Psi(2S) model bool incBkg, // Includes Background model // Select the fitting options // Select the drawing options bool setLogScale, // Draw plot with log scale bool incSS, // Include Same Sign data double binWidth // Bin width ) { RooMsgService::instance().getStream(0).removeTopic(Caching); RooMsgService::instance().getStream(1).removeTopic(Caching); RooMsgService::instance().getStream(0).removeTopic(Plotting); RooMsgService::instance().getStream(1).removeTopic(Plotting); RooMsgService::instance().getStream(0).removeTopic(Integration); RooMsgService::instance().getStream(1).removeTopic(Integration); RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ; if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_")); string pdfTotName = Form("pdfCTAUMASS_Tot_%s", (isPbPb?"PbPb":"PP")); string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); string dsOSNameCut = dsOSName+"_CTAUCUT"; string hOSName = Form("dhCTAUERRTot_Tot_%s", (isPbPb?"PbPb":"PP")); string hOSNameBkg = Form("dhCTAUERR_Bkg_%s", (isPbPb?"PbPb":"PP")); string hOSNameJpsi = Form("dhCTAUERR_Jpsi_%s", (isPbPb?"PbPb":"PP")); string hOSNamePsi2S = Form("dhCTAUERR_Psi2S_%s", (isPbPb?"PbPb":"PP")); string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); bool isWeighted = myws.data(dsOSName.c_str())->isWeighted(); vector<double> range; range.push_back(cut.dMuon.ctau.Min); range.push_back(cut.dMuon.ctau.Max); double minRange = -4.0; double maxRange = 7.0; Double_t outTot = myws.data(dsOSName.c_str())->numEntries(); Double_t outErr = myws.data(dsOSName.c_str())->reduce(Form("(ctau>%.6f || ctau<%.6f)", range[1], range[0]))->numEntries(); int nBins = min(int( round((maxRange - minRange)/binWidth) ), 1000); double normDSTot = 1.0; if (myws.data(dsOSNameCut.c_str())) { normDSTot = myws.data(dsOSName.c_str())->sumEntries()/myws.data(dsOSNameCut.c_str())->sumEntries(); } double normJpsi = 1.0; if (myws.data(hOSNameJpsi.c_str())) { normJpsi = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNameJpsi.c_str())->sumEntries(); } double normPsi2S = 1.0; if (myws.data(hOSNamePsi2S.c_str())) { normPsi2S = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNamePsi2S.c_str())->sumEntries(); } double normBkg = 1.0; if (myws.data(hOSNameBkg.c_str())) { normBkg = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSNameBkg.c_str())->sumEntries(); } double normTot = 1.0; if (myws.data(hOSName.c_str())) { normTot = myws.data(dsOSName.c_str())->sumEntries()*normDSTot/myws.data(hOSName.c_str())->sumEntries(); } // Create the main plot of the fit RooPlot* frame = myws.var("ctau")->frame(Bins(nBins), Range(minRange, maxRange)); frame->updateNormVars(RooArgSet(*myws.var("invMass"), *myws.var("ctau"), *myws.var("ctauErr"))) ; myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDF"), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSNameCut.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), FillStyle(1001), FillColor(kViolet+6), VLines(), DrawOption("LF"), NumCPU(32), LineColor(kBlack) ); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("BKG"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Bkg_%s", (isPbPb?"PbPb":"PP"))) )), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), FillStyle(1001), FillColor(kAzure-9), VLines(), DrawOption("LF"), NumCPU(32) ); if (incJpsi) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSIPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_JpsiPR_%s", (isPbPb?"PbPb":"PP"))) )), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kRed+3), Precision(1e-5), NumCPU(32) ); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("JPSINOPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_JpsiNoPR_%s", (isPbPb?"PbPb":"PP"))) )), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kGreen+3), Precision(1e-5), NumCPU(32) ); } if (incPsi2S) { myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Psi2SPR_%s", (isPbPb?"PbPb":"PP"))) )), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kRed+3), Precision(1e-5), NumCPU(32) ); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PSI2SNOPR"),Components(RooArgSet( *myws.pdf(Form("pdfCTAUMASS_Psi2SNo_%s", (isPbPb?"PbPb":"PP"))) )), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSName.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kGreen+3), Precision(1e-5), NumCPU(32) ); } if (incSS) { myws.data(dsSSName.c_str())->plotOn(frame, Name("dSS"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); } myws.data(dsOSName.c_str())->plotOn(frame, Name("dOS"), DataError(RooAbsData::SumW2), XErrorSize(0), MarkerColor(kBlack), LineColor(kBlack), MarkerSize(1.2)); myws.pdf(pdfTotName.c_str())->plotOn(frame,Name("PDFLINE"), ProjWData(RooArgSet(*myws.var("ctauErr")), *myws.data(dsOSNameCut.c_str()), kTRUE), Normalization(normDSTot, RooAbsReal::NumEvent), LineColor(kBlack), NumCPU(32) ); // set the CMS style setTDRStyle(); // Create the pull distribution of the fit RooHist *hpull = frame->pullHist(0, "PDF", true); hpull->SetName("hpull"); RooPlot* frame2 = myws.var("ctau")->frame(Title("Pull Distribution"), Bins(nBins), Range(minRange, maxRange)); frame2->addPlotable(hpull, "PX"); // Create the main canvas TCanvas *cFig = new TCanvas(Form("cCtauFig_%s", (isPbPb?"PbPb":"PP")), "cCtauFig",800,800); TPad *pad1 = new TPad(Form("pad1_%s", (isPbPb?"PbPb":"PP")),"",0,0.23,1,1); TPad *pad2 = new TPad(Form("pad2_%s", (isPbPb?"PbPb":"PP")),"",0,0,1,.228); TLine *pline = new TLine(minRange, 0.0, maxRange, 0.0); TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.46,0.97,0.87); pad4->SetFillStyle(0); pad4->SetLeftMargin(0.28); pad4->SetRightMargin(0.10); pad4->SetBottomMargin(0.21); pad4->SetTopMargin(0.072); frame->SetTitle(""); frame->GetXaxis()->SetTitle(""); frame->GetXaxis()->CenterTitle(kTRUE); frame->GetXaxis()->SetTitleSize(0.045); frame->GetXaxis()->SetTitleFont(42); frame->GetXaxis()->SetTitleOffset(3); frame->GetXaxis()->SetLabelOffset(3); frame->GetYaxis()->SetLabelSize(0.04); frame->GetYaxis()->SetTitleSize(0.04); frame->GetYaxis()->SetTitleOffset(1.7); frame->GetYaxis()->SetTitleFont(42); setCtauFrom2DRange(myws, frame, dsOSNameCut, setLogScale, range, outErr); cFig->cd(); pad2->SetTopMargin(0.02); pad2->SetBottomMargin(0.4); pad2->SetFillStyle(4000); pad2->SetFrameFillStyle(4000); pad1->SetBottomMargin(0.015); //plot fit pad1->Draw(); pad1->cd(); frame->Draw(); printCtauFrom2DParameters(myws, pad1, isPbPb, pdfTotName, isWeighted); pad1->SetLogy(setLogScale); // Drawing the text in the plot TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.032); float dy = 0; t->SetTextSize(0.03); t->DrawLatex(0.21, 0.86-dy, "2015 HI Soft Muon ID"); dy+=0.045; if (isPbPb) { t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045; } else { t->DrawLatex(0.21, 0.86-dy, "HLT_HIL1DoubleMu0_v1"); dy+=0.045; } t->DrawLatex(0.21, 0.86-dy, Form("%.1f #leq p_{T}^{#mu#mu} < %.1f GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045; t->DrawLatex(0.21, 0.86-dy, Form("%.1f #leq |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=0.045; if (isPbPb) {t->DrawLatex(0.21, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;} if (outErr>0.0) { t->DrawLatex(0.21, 0.86-dy, Form("Excl: (%.4f%%) %.0f evts", (outErr*100.0/outTot), outErr)); dy+=1.5*0.045; } // Drawing the Legend double ymin = 0.7602; if (incPsi2S && incJpsi && incSS) { ymin = 0.7202; } if (incPsi2S && incJpsi && !incSS) { ymin = 0.7452; } TLegend* leg = new TLegend(0.5175, ymin, 0.7180, 0.8809); leg->SetTextSize(0.03); leg->AddEntry(frame->findObject("dOS"), (incSS?"Opposite Charge":"Data"),"pe"); if (incSS) { leg->AddEntry(frame->findObject("dSS"),"Same Charge","pe"); } if(frame->findObject("PDF")) { leg->AddEntry(frame->findObject("PDF"),"Total fit","fl"); } if((incBkg && (incJpsi || incPsi2S)) && frame->findObject("BKG")) { leg->AddEntry(frame->findObject("BKG"),"Background","fl"); } if(incBkg && incJpsi && frame->findObject("JPSIPR")) { leg->AddEntry(frame->findObject("JPSIPR"),"J/#psi Prompt","l"); } if(incBkg && incJpsi && frame->findObject("JPSINOPR")) { leg->AddEntry(frame->findObject("JPSINOPR"),"J/#psi Non-Prompt","l"); } if(incBkg && incPsi2S && frame->findObject("PSI2SPR")) { leg->AddEntry(frame->findObject("PSI2SPR"),"#psi(2S) Prompt","l"); } if(incBkg && incPsi2S && frame->findObject("PSI2SNOPR")) { leg->AddEntry(frame->findObject("PSI2SNOPR"),"#psi(2S) Non-Prompt","l"); } leg->Draw("same"); //Drawing the title TString label; if (isPbPb) { if (opt.PbPb.RunNb.Start==opt.PbPb.RunNb.End){ label = Form("PbPb Run %d", opt.PbPb.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PbPb", "HIOniaL1DoubleMu0", opt.PbPb.RunNb.Start, opt.PbPb.RunNb.End); } } else { if (opt.pp.RunNb.Start==opt.pp.RunNb.End){ label = Form("PP Run %d", opt.pp.RunNb.Start); } else { label = Form("%s [%s %d-%d]", "PP", "DoubleMu0", opt.pp.RunNb.Start, opt.pp.RunNb.End); } } //CMS_lumi(pad1, isPbPb ? 105 : 104, 33, label); CMS_lumi(pad1, isPbPb ? 108 : 107, 33, ""); gStyle->SetTitleFontSize(0.05); pad1->Update(); cFig->cd(); //---plot pull pad2->Draw(); pad2->cd(); frame2->SetTitle(""); frame2->GetYaxis()->CenterTitle(kTRUE); frame2->GetYaxis()->SetTitleOffset(0.4); frame2->GetYaxis()->SetTitleSize(0.1); frame2->GetYaxis()->SetLabelSize(0.1); frame2->GetYaxis()->SetTitle("Pull"); frame2->GetXaxis()->CenterTitle(kTRUE); frame2->GetXaxis()->SetTitleOffset(1); frame2->GetXaxis()->SetTitleSize(0.12); frame2->GetXaxis()->SetLabelSize(0.1); frame2->GetXaxis()->SetTitle("#font[12]{l}_{J/#psi} (mm)"); frame2->GetYaxis()->SetRangeUser(-7.0, 7.0); frame2->Draw(); // *** Print chi2/ndof printChi2(myws, pad2, frame, "ctau", dsOSName.c_str(), pdfTotName.c_str(), nBins, false); pline->Draw("same"); pad2->Update(); // Save the plot in different formats gSystem->mkdir(Form("%sctauMass/%s/plot/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/root/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%sctauMass/%s/plot/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/png/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); gSystem->mkdir(Form("%sctauMass/%s/plot/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%sctauMass/%s/plot/pdf/PLOT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), "CTAU", DSTAG.c_str(), (isPbPb?"PbPb":"PP"), plotLabel.c_str(), (cut.dMuon.Pt.Min*10.0), (cut.dMuon.Pt.Max*10.0), (cut.dMuon.AbsRap.Min*10.0), (cut.dMuon.AbsRap.Max*10.0), cut.Centrality.Start, cut.Centrality.End)); cFig->Clear(); cFig->Close(); }
void FFT_MC_OneDay() { //read RD_R_data Double_t RD_RatioInOneDay[8][24]; Double_t RD_Ratio_t[3]; memset(RD_RatioInOneDay,0.0,sizeof(RD_RatioInOneDay)); TFile *F_RD_Ratio = new TFile("data/RD_RatioInOneDay.root"); TTree *Tree_RD_Ratio = (TTree*)F_RD_Ratio->Get("RD_RatioInOneDay"); Tree_RD_Ratio->SetBranchAddress("RD_RatioInOneDay",RD_Ratio_t); for(int N24=0;N24<24;N24++) { Tree_RD_Ratio->GetEntry(N24); for(int Det=0;Det<3;Det++) { RD_R_data[Det][N24] = RD_Ratio_t[Det]; } } //cout<<"hello......"<<endl; const double pi = 3.141592653; Double_t CrossSection = 0.94;//Averaged cross-section, in unit of 1e-43 cm^2; Double_t Np = 1.43;//Total number of target protons in AD1,AD2, in unit of 1e30 for(int Det=0;Det<8;Det++) { for(int Bin=0;Bin<NumOfBin;Bin++) { IsGoodBin[Det][Bin] = false; } } //Prediction candidate double Prediction_t_Bin[8]; double TotalPrediction[8]={0.0}; TFile *F_Bin_Prediction = new TFile("../daily_data/Fraction_AD_Bin.root"); TTree *Tree_Bin_Prediction = (TTree*)F_Bin_Prediction->Get("Fraction"); Tree_Bin_Prediction->SetBranchAddress("Fraction",Prediction_t_Bin); //IBD candidate Int_t IBD_t_Bin[8]; double TotalIBD[8]={0.0}; TFile *F_Bin_IBD = new TFile("../IBD_NoEBin.root"); TTree *Tree_Bin_IBD = (TTree*)F_Bin_IBD->Get("IBD"); Tree_Bin_IBD->SetBranchAddress("IBD",IBD_t_Bin); //FullTime Double_t FullTime_t_Bin[8]; TFile *F_Bin_FullTime = new TFile("../FullTime.root"); TTree *Tree_Bin_FullTime = (TTree*)F_Bin_FullTime->Get("FullTime"); Tree_Bin_FullTime->SetBranchAddress("FullTime",FullTime_t_Bin); //LiveTime Double_t LiveTime_t_Bin[8]; double TotalLiveTime[8]={0.0}; TFile *F_Bin_LiveTime = new TFile("../LiveTime.root"); TTree *Tree_Bin_LiveTime = (TTree*)F_Bin_LiveTime->Get("LiveTime"); Tree_Bin_LiveTime->SetBranchAddress("LiveTime",LiveTime_t_Bin); double BkgInEachBin[8][NumOfBin]={{0.0}}; //AmC Double_t AmC_t_Bin[8]; TFile *F_Bin_AmC = new TFile("../AmC/AmCInEachBin.root"); TTree *Tree_Bin_AmC = (TTree*)F_Bin_AmC->Get("AmCInEachBin"); Tree_Bin_AmC->SetBranchAddress("AmCInEachBin",AmC_t_Bin); //Acc Double_t Acc_t_Bin[8]; TFile *F_Bin_Acc = new TFile("../AccBkg/AccInEachBin.root"); TTree *Tree_Bin_Acc = (TTree*)F_Bin_Acc->Get("AccInEachBin"); Tree_Bin_Acc->SetBranchAddress("AccInEachBin",Acc_t_Bin); Double_t Li9_t_Bin[8]; TFile *F_Bin_Li9 = new TFile("../Li9/Li9InEachBin.root"); TTree *Tree_Bin_Li9 = (TTree*)F_Bin_Li9->Get("Li9InEachBin"); Tree_Bin_Li9->SetBranchAddress("Li9InEachBin",Li9_t_Bin); //FastN Double_t FastN_t_Bin[8]; TFile *F_Bin_FastN = new TFile("../FastN/FastNInEachBin.root"); TTree *Tree_Bin_FastN = (TTree*)F_Bin_FastN->Get("FastNInEachBin"); Tree_Bin_FastN->SetBranchAddress("FastNInEachBin",FastN_t_Bin); double EffInEachBin[8][NumOfBin]={{0.0}}; //MultiEff Double_t MultiEff_t_Bin[8]; TFile *F_Bin_MultiEff = new TFile("../MultiEff/MultiEffInEachBin.root"); TTree *Tree_Bin_MultiEff = (TTree*)F_Bin_MultiEff->Get("MultiEffInEachBin"); Tree_Bin_MultiEff->SetBranchAddress("MultiEffInEachBin",MultiEff_t_Bin); //MuEff Double_t MuEff_t_Bin[8]; TFile *F_Bin_MuEff = new TFile("../MuEff/MuEffInEachBin.root"); TTree *Tree_Bin_MuEff = (TTree*)F_Bin_MuEff->Get("MuEffInEachBin"); Tree_Bin_MuEff->SetBranchAddress("MuEffInEachBin",MuEff_t_Bin); //alpha beta double AlphaBeta_t[2]; TFile *F_Bin_AlphaBeta = new TFile("../daily_data/AlphaBeta_Bin.root"); TTree *Tree_Bin_AlphaBeta = (TTree*)F_Bin_AlphaBeta->Get("AlphaBeta"); Tree_Bin_AlphaBeta->SetBranchAddress("AlphaBeta",AlphaBeta_t); FILE* m_outfile = fopen("log_MC_OneDay.txt", "w+"); for(int Bin=0;Bin<NumOfBin;Bin++) { Tree_Bin_IBD->GetEntry(Bin); Tree_Bin_AlphaBeta->GetEntry(Bin); Tree_Bin_Prediction->GetEntry(Bin); Tree_Bin_FullTime->GetEntry(Bin); Tree_Bin_LiveTime->GetEntry(Bin); Tree_Bin_AmC->GetEntry(Bin); Tree_Bin_Acc->GetEntry(Bin); Tree_Bin_Li9->GetEntry(Bin); Tree_Bin_FastN->GetEntry(Bin); Tree_Bin_MultiEff->GetEntry(Bin); Tree_Bin_MuEff->GetEntry(Bin); for(int Det=0;Det<8;Det++) { TotalLiveTime[Det] += LiveTime_t_Bin[Det]; TotalIBD[Det] += 1.0*IBD_t_Bin[Det]; TotalPrediction[Det] += 1.0*Prediction_t_Bin[Det]*1.0e-17*Np*CrossSection/(4.0*pi); ////////SYS TotalAcc[Det] += Acc_t_Bin[Det]; TotalFN[Det] += FastN_t_Bin[Det]; TotalLi9[Det] += Li9_t_Bin[Det]; ///////SYS if(IBD_t_Bin[Det]>0) { IsGoodBin[Det][Bin] = true; NumOfGoodBin[Det] ++; } } double M[3]={0.0}; double P[3]={0.0}; for(int Det=0;Det<2;Det++) { if(MultiEff_t_Bin[Det]*MuEff_t_Bin[Det]>0.01) { M[0] += IBD_t_Bin[Det]/(MultiEff_t_Bin[Det]*MuEff_t_Bin[Det]) - (AmC_t_Bin[Det]+Acc_t_Bin[Det]+Li9_t_Bin[Det]+FastN_t_Bin[Det]); P[0] += 1.0*Prediction_t_Bin[Det]*1.0e-17*Np*CrossSection/(4.0*pi); } } for(int Det=2;Det<4;Det++) { if(MultiEff_t_Bin[Det]*MuEff_t_Bin[Det]>0.01) { M[1] += IBD_t_Bin[Det]/(MultiEff_t_Bin[Det]*MuEff_t_Bin[Det]) - (AmC_t_Bin[Det]+Acc_t_Bin[Det]+Li9_t_Bin[Det]+FastN_t_Bin[Det]); P[1] += 1.0*Prediction_t_Bin[Det]*1.0e-17*Np*CrossSection/(4.0*pi); } } for(int Det=4;Det<8;Det++) { if(MultiEff_t_Bin[Det]*MuEff_t_Bin[Det]>0.01) { M[2] += IBD_t_Bin[Det]/(MultiEff_t_Bin[Det]*MuEff_t_Bin[Det]) - (AmC_t_Bin[Det]+Acc_t_Bin[Det]+Li9_t_Bin[Det]+FastN_t_Bin[Det]); } } P[2] = AlphaBeta_t[0]*M[0]+AlphaBeta_t[1]*M[1]; for(int Hidx=0;Hidx<3;Hidx++) { if(P[Hidx]>0.0001) { R_data[Hidx][Bin] = M[Hidx]/P[Hidx]; } } } ////cout empty bins.......... FILE* m_outfile_bin = fopen("empty_bin.txt", "w+"); for(int Det=0;Det<8;Det++) { fprintf(m_outfile_bin,"AD..... %2d \n \n",Det+1); for(int Bin=0;Bin<NumOfBin;Bin++) { if(!IsGoodBin[Det][Bin]) { fprintf(m_outfile_bin,"%6d ",Bin); } } fprintf(m_outfile_bin,"\n"); } //FFT double mean_an[3][NumOfBin_Day]={{0.0}}; double mean_bn[3][NumOfBin_Day]={{0.0}}; double sigma_an[3][NumOfBin_Day]={{0.0}}; double sigma_bn[3][NumOfBin_Day]={{0.0}}; TH1F *hist_a0 = new TH1F("hist_a0","hist_a0",1000,-2.0,2.0); TH1F *hist_a1 = new TH1F("hist_a1","hist_a1",1000,-0.1,0.1); TH1F *hist_a2 = new TH1F("hist_a2","hist_a2",1000,-0.1,0.1); TH1F *hist_b1 = new TH1F("hist_b1","hist_b1",1000,-0.1,0.1); TH1F *hist_b2 = new TH1F("hist_b2","hist_b2",1000,-0.1,0.1); Double_t re, im, Frk; for(int idx=0;idx<nSample;idx++) { //cout<<idx<<endl; for(int Bin=0;Bin<NumOfBin_Day;Bin++) { double M[3]={0.0}; double P[3]={0.0}; for(int Det=0;Det<2;Det++) { // if(!IsGoodBin[Det][Bin]) { M[0] += my_Random->PoissonD(TotalIBD[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Eff) - (TotalAcc[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Acc[Det]) - (TotalFN[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_FN[Det]) - (TotalLi9[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Li9[Det]); P[0] += TotalIBD[Det]/NumOfBin_Day*my_Random->Gaus(1.0,RD_Power*0.572); } } for(int Det=2;Det<4;Det++) { // if(!IsGoodBin[Det][Bin]) { M[1] += my_Random->PoissonD(TotalIBD[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Eff) - (TotalAcc[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Acc[Det]) - (TotalFN[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_FN[Det]) - (TotalLi9[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Li9[Det]); P[1] += TotalIBD[Det]/NumOfBin_Day*my_Random->Gaus(1.0,RD_Power*0.472); } } for(int Det=4;Det<8;Det++) { // if(!IsGoodBin[Det][Bin]) { M[2] += my_Random->PoissonD(TotalIBD[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Eff) - (TotalAcc[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Acc[Det]) - (TotalFN[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_FN[Det]) - (TotalLi9[Det]/NumOfBin_Day)*my_Random->Gaus(1.0,RD_Li9[Det]); } } P[2] = (Alpha_8AD*M[0]+Beta_8AD*M[1])*my_Random->Gaus(1.0,RD_Power*0.047); for(int Hidx=0;Hidx<3;Hidx++) { if((P[Hidx]>0.00001)&&(M[Hidx]>0.00001)) { R[Hidx][Bin] = M[Hidx]/P[Hidx]; } } } // Exclusion_3s(); Normalization(); ////just from data for(int Hidx=0;Hidx<3;Hidx++) { for(int N24=0;N24<24;N24++) { R[Hidx][N24] = my_Random->Gaus(AVEP[Hidx],RD_R_data[Hidx][N24]) - AVEP[Hidx]; } } //////////////// for(int Hidx=0;Hidx<3;Hidx++) { int n = NumOfBin_Day; TVirtualFFT *fftr2c = TVirtualFFT::FFT(1, &n, "R2C"); double in[NumOfBin_Day]; for(int Bin=0;Bin<NumOfBin_Day;Bin++) { in[Bin] = R[Hidx][Bin]; } fftr2c->SetPoints(in); fftr2c->Transform(); fftr2c->GetPointComplex(0, re, im); mean_an[Hidx][0] += re/NumOfBin_Day; mean_bn[Hidx][0] += -1.0*im/NumOfBin_Day; sigma_an[Hidx][0] += pow(re/NumOfBin_Day,2.0); sigma_bn[Hidx][0] += pow(-1.0*im/NumOfBin_Day,2.0); if(Hidx==2) { hist_a0->Fill(re/NumOfBin_Day); } //cout<<idx<<" "<<Hidx<<" "<<" "<<re/NumOfBin_Day<<" "<<-1.0*im/NumOfBin_Day<<endl; for(int Bin=1;Bin<NumOfBin_Day;Bin++) { fftr2c->GetPointComplex(Bin, re, im); double a = re*2.0/NumOfBin_Day; double b = -1.0*im*2.0/NumOfBin_Day; mean_an[Hidx][Bin] += a; mean_bn[Hidx][Bin] += b; sigma_an[Hidx][Bin] += a*a; sigma_bn[Hidx][Bin] += b*b; if(Hidx==2) { if(Bin==706) { hist_a1->Fill(a); hist_b1->Fill(b); } if(Bin==1414) { hist_a2->Fill(a); hist_b2->Fill(b); } } } } } for(int Hidx=0;Hidx<3;Hidx++) { for(int Bin=0;Bin<NumOfBin_Day;Bin++) { mean_an[Hidx][Bin] = mean_an[Hidx][Bin]/nSample; mean_bn[Hidx][Bin] = mean_bn[Hidx][Bin]/nSample; sigma_an[Hidx][Bin] = sigma_an[Hidx][Bin]/nSample -pow(mean_an[Hidx][Bin],2.0); sigma_an[Hidx][Bin] = pow(sigma_an[Hidx][Bin],0.5); sigma_bn[Hidx][Bin] = sigma_bn[Hidx][Bin]/nSample -pow(mean_bn[Hidx][Bin],2.0); sigma_bn[Hidx][Bin] = pow(sigma_bn[Hidx][Bin],0.5); //normalization /* mean_an[Hidx][Bin] = mean_an[Hidx][Bin]/mean_an[Hidx][0]; mean_bn[Hidx][Bin] = mean_bn[Hidx][Bin]/mean_an[Hidx][0]; sigma_an[Hidx][Bin] = sigma_an[Hidx][Bin]/mean_an[Hidx][0]; sigma_bn[Hidx][Bin] = sigma_bn[Hidx][Bin]/mean_an[Hidx][0];*/ } } TCanvas *myC_a0 = new TCanvas("c_a0","c_a0",0,0,800,420); hist_a0->Draw(); TCanvas *myC_a1 = new TCanvas("c_a1","c_a1",0,0,800,420); hist_a1->Draw(); TCanvas *myC_a2 = new TCanvas("c_a2","c_a2",0,0,800,420); hist_a2->Draw(); TCanvas *myC_b1 = new TCanvas("c_b1","c_b1",0,0,800,420); hist_b1->Draw(); TCanvas *myC_b2 = new TCanvas("c_b2","c_b2",0,0,800,420); hist_b2->Draw(); //print for(int Bin=0;Bin<NumOfBin_Day;Bin++) { fprintf(m_outfile,"%6d %7.4f \\pm %7.4f %7.4f \\pm %7.4f %7.4f \\pm %7.4f %7.4f \\pm %7.4f %7.4f \\pm %7.4f %7.4f \\pm %7.4f ",Bin, mean_an[0][Bin],sigma_an[0][Bin], mean_bn[0][Bin],sigma_bn[0][Bin], mean_an[1][Bin],sigma_an[1][Bin], mean_bn[1][Bin],sigma_bn[1][Bin], mean_an[2][Bin],sigma_an[2][Bin], mean_bn[2][Bin],sigma_bn[2][Bin]); for(int Det=0;Det<8;Det++) { //fprintf(m_outfile,"%4.1f %4.1f %4.1f ",IBDInEachBin[Det][Bin],LiveTimeInEachBin[Det][Bin]*TotalIBD[Det]/TotalLiveTime[Det],PredictionInEachBin[Det][Bin]); // fprintf(m_outfile,"%4.1f ",IBDInEachBin[Det][Bin]); } fprintf(m_outfile,"\n"); } const int nX = 24; double nBins = 1.0; //Draw, Rt const char* hist_Name_Rt[3] = {"EH1_Rt","EH2_Rt","EH3_Rt"}; const char* file_Name_Rt[3] = {"EH1_Rt_OneDay.eps","EH2_Rt_OneDay.eps","EH3_Rt_OneDay.eps"}; TCanvas *myC_Rt[3]; TGraphErrors *gr_Rt[3]; TLegend *leg_Rt[3]; const char* leg_Name_Rt[3] = {"EH1_R(t)-R0_MC(One Day)","EH2_R(t)-R0_MC(One Day)","EH3 - R(t) -MC(One Day)"}; for(int Hidx=0;Hidx<3;Hidx++) { myC_Rt[Hidx] = new TCanvas(hist_Name_Rt[Hidx],hist_Name_Rt[Hidx],0,0,800,420); int n = NumOfBin_Day; double x[n],y[n],ex[n],ey[n]; for(int Bin=0;Bin<n;Bin++) { x[Bin] = Bin; y[Bin] = R[Hidx][Bin]; ex[Bin]=0.0; ey[Bin] = 0.0; } gr_Rt[Hidx] = new TGraphErrors(n,x,y,ex,ey); gr_Rt[Hidx]->GetYaxis()->SetRangeUser(-0.06,0.06); gr_Rt[Hidx]->GetXaxis()->SetRangeUser(0,n); gr_Rt[Hidx]->SetMarkerColor(kBlue); gr_Rt[Hidx]->SetMarkerStyle(21); gr_Rt[Hidx]->GetXaxis()->SetTitle("sidereal time(1 bin =86164.09/24 seconds)"); gr_Rt[Hidx]->GetYaxis()->SetTitle("R(t) - R0"); gr_Rt[Hidx]->SetTitle(""); gr_Rt[Hidx]->GetYaxis()->SetTitleOffset(0.5); gr_Rt[Hidx]->GetYaxis()->SetTitleSize(0.08); gr_Rt[Hidx]->GetYaxis()->SetLabelSize(0.06); gr_Rt[Hidx]->GetYaxis()->SetLabelOffset(0.0); gr_Rt[Hidx]->GetXaxis()->SetTitleOffset(0.7); gr_Rt[Hidx]->GetXaxis()->SetTitleSize(0.07); gr_Rt[Hidx]->GetXaxis()->SetLabelSize(0.05); gr_Rt[Hidx]->GetXaxis()->SetLabelOffset(0.0); gr_Rt[Hidx]->Draw("APZ"); leg_Rt[Hidx] = new TLegend(0.10,0.70,0.90,0.99); leg_Rt[Hidx]->AddEntry(gr_Rt[Hidx],leg_Name_Rt[Hidx],""); leg_Rt[Hidx]->SetFillStyle(0); leg_Rt[Hidx]->SetBorderSize(0); leg_Rt[Hidx]->SetTextColor(kRed); leg_Rt[Hidx]->Draw(); myC_Rt[Hidx]->SaveAs(file_Name_Rt[Hidx]); } //Draw, _abn const char* hist_Name_abn[3] = {"EH1_abn","EH2_abn","EH3_abn"}; const char* file_Name_abn[3] = {"EH1_abn_MC_OneDay.eps","EH2_abn_MC_OneDay.eps","EH3_abn_MC_OneDay.eps"}; TCanvas *myC_abn[3]; TGraphErrors *gr_an[3]; TLegend *leg_an[3]; const char* leg_Name_an[3] = {"EH1 - a_{n} - MC(One Day)","EH2 - a_{n} - MC(One Day)","EH3 - a_{n} - MC(One Day)"}; TGraphErrors *gr_bn[3]; TLegend *leg_bn[3]; const char* leg_Name_bn[3] = {"EH1 - b_{n} - MC(One Day)","EH2 - b_{n} - MC(One Day)","EH3 - b_{n} - MC(One Day)"}; for(int Hidx=0;Hidx<3;Hidx++) { myC_abn[Hidx] = new TCanvas(hist_Name_abn[Hidx],hist_Name_abn[Hidx],0,0,800,600); myC_abn[Hidx]->Divide(1,2,0); { myC_abn[Hidx]->cd(1); double x[nX],y[nX],ex[nX],ey[nX]; for(int Bin=0;Bin<nX;Bin++) { x[Bin] = Bin;//Bin/nBins; int kM = Bin;//int(24.0*x[Bin]); y[Bin] = mean_an[Hidx][kM]; ex[Bin]=0.0; ey[Bin]=sigma_an[Hidx][kM]; } gr_an[Hidx] = new TGraphErrors(nX,x,y,ex,ey); gr_an[Hidx]->GetYaxis()->SetRangeUser(-0.02,0.02); gr_an[Hidx]->GetXaxis()->SetRangeUser(0,nX); gr_an[Hidx]->SetMarkerColor(kBlue); gr_an[Hidx]->SetLineColor(kBlue); gr_an[Hidx]->SetLineWidth(2); gr_an[Hidx]->SetMarkerStyle(21); // gr_an[Hidx]->SetMarkerSize(0.5); gr_an[Hidx]->GetXaxis()->SetTitle("#omega/#omega_{0}, #omega_{0}=2#pi/1 sidereal day"); gr_an[Hidx]->GetYaxis()->SetTitle("a"); gr_an[Hidx]->SetTitle(""); gr_an[Hidx]->GetYaxis()->SetTitleOffset(0.6); gr_an[Hidx]->GetYaxis()->SetTitleSize(0.08); gr_an[Hidx]->GetYaxis()->SetLabelSize(0.06); gr_an[Hidx]->GetYaxis()->SetLabelOffset(0.0); gr_an[Hidx]->GetXaxis()->SetTitleOffset(0.7); gr_an[Hidx]->GetXaxis()->SetTitleSize(0.07); gr_an[Hidx]->GetXaxis()->SetLabelSize(0.05); gr_an[Hidx]->GetXaxis()->SetLabelOffset(0.0); gr_an[Hidx]->Draw("APZ"); leg_an[Hidx] = new TLegend(0.10,0.70,0.90,0.99); leg_an[Hidx]->AddEntry(gr_an[Hidx],leg_Name_an[Hidx],""); leg_an[Hidx]->SetFillStyle(0); leg_an[Hidx]->SetBorderSize(0); leg_an[Hidx]->SetTextColor(kRed); leg_an[Hidx]->Draw(); } { myC_abn[Hidx]->cd(2); double x[nX],y[nX],ex[nX],ey[nX]; for(int Bin=0;Bin<nX;Bin++) { x[Bin] = Bin;//Bin/nBins; int kM = Bin;// int(706.0*x[Bin]); y[Bin] = mean_bn[Hidx][kM]; ex[Bin]=0.0; ey[Bin]=sigma_bn[Hidx][kM]; } gr_bn[Hidx] = new TGraphErrors(nX,x,y,ex,ey); gr_bn[Hidx]->GetYaxis()->SetRangeUser(-0.02,0.02); gr_bn[Hidx]->GetXaxis()->SetRangeUser(0,nX); gr_bn[Hidx]->SetMarkerColor(kBlue); gr_bn[Hidx]->SetLineColor(kBlue); gr_bn[Hidx]->SetLineWidth(2); gr_bn[Hidx]->SetMarkerStyle(21); //gr_bn[Hidx]->SetMarkerSize(0.5); gr_bn[Hidx]->GetXaxis()->SetTitle("#omega/#omega_{0}, #omega_{0}=2#pi/1 sidereal day"); gr_bn[Hidx]->GetYaxis()->SetTitle("b"); gr_bn[Hidx]->SetTitle(""); gr_bn[Hidx]->GetYaxis()->SetTitleOffset(0.6); gr_bn[Hidx]->GetYaxis()->SetTitleSize(0.08); gr_bn[Hidx]->GetYaxis()->SetLabelSize(0.06); gr_bn[Hidx]->GetYaxis()->SetLabelOffset(0.0); gr_bn[Hidx]->GetXaxis()->SetTitleOffset(0.7); gr_bn[Hidx]->GetXaxis()->SetTitleSize(0.07); gr_bn[Hidx]->GetXaxis()->SetLabelSize(0.05); gr_bn[Hidx]->GetXaxis()->SetLabelOffset(0.0); gr_bn[Hidx]->Draw("APZ"); leg_bn[Hidx] = new TLegend(0.10,0.70,0.90,0.99); leg_bn[Hidx]->AddEntry(gr_bn[Hidx],leg_Name_bn[Hidx],""); leg_bn[Hidx]->SetFillStyle(0); leg_bn[Hidx]->SetBorderSize(0); leg_bn[Hidx]->SetTextColor(kRed); leg_bn[Hidx]->Draw(); } myC_abn[Hidx]->SaveAs(file_Name_abn[Hidx]); } //save to .root file double an_t[3][2]; TFile *F_an = new TFile("an_MC_OneDay.root","recreate"); TTree *Tree_an = new TTree("an","an"); Tree_an->Branch("an",an_t,"an_t[3][2]/D"); for(int Bin=0; Bin<NumOfBin;Bin++) { for(int Hidx=0;Hidx<3;Hidx++) { an_t[Hidx][0] = mean_an[Hidx][Bin]; an_t[Hidx][1] = sigma_an[Hidx][Bin]; } Tree_an->Fill(); } Tree_an->Write(); double bn_t[3][2]; TFile *F_bn = new TFile("bn_MC_OneDay.root","recreate"); TTree *Tree_bn = new TTree("bn","bn"); Tree_bn->Branch("bn",bn_t,"bn_t[3][2]/D"); for(int Bin=0; Bin<NumOfBin;Bin++) { for(int Hidx=0;Hidx<3;Hidx++) { bn_t[Hidx][0] = mean_bn[Hidx][Bin]; bn_t[Hidx][1] = sigma_bn[Hidx][Bin]; } Tree_bn->Fill(); } Tree_bn->Write(); }
void fit2015( TString FileName ="/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/ppData/OniaTree_262163_262328.root", int oniamode = 2, // oniamode-> 3: Z, 2: Upsilon and 1: J/Psi bool isData = true, // isData = false for MC, true for Data bool isPbPb = false, // isPbPb = false for pp, true for PbPb bool doFit = false , bool inExcStat = true // if inExcStat is true, then the excited states are fitted ) { InputOpt opt; SetOptions(&opt, isData, isPbPb, oniamode,inExcStat); if (isPbPb) { FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/PbPbData/OniaTree_262548_262893.root"; } else { FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/ppData/OniaTree_262163_262328.root"; } int nbins = 1; //ceil((opt.dMuon->M->Max - opt.dMuon->M->Min)/binw); if (oniamode==1){ nbins = 140; } else if (oniamode==2) { nbins = 70; } else if (oniamode==3) { nbins = 40; } RooWorkspace myws; TH1F* hDataOS = new TH1F("hDataOS","hDataOS", nbins, opt.dMuon.M.Min, opt.dMuon.M.Max); makeWorkspace2015(myws, FileName, opt, hDataOS); RooRealVar* mass = (RooRealVar*) myws.var("invariantMass"); RooDataSet* dataOS_fit = (RooDataSet*) myws.data("dataOS"); RooDataSet* dataSS_fit = (RooDataSet*) myws.data("dataSS"); RooAbsPdf* pdf = NULL; if (oniamode==3) { doFit=false; } if (doFit) { int sigModel=0, bkgModel=0; if (isData) { if (oniamode==1){ sigModel = inExcStat ? 2 : 3; bkgModel = 1; } else { sigModel = inExcStat ? 1 : 3; // gaussian bkgModel = 2; } } else { if (oniamode==1){ sigModel = inExcStat ? 2 : 3; // gaussian bkgModel = 2; } else { sigModel = inExcStat ? 2 : 3; // gaussian bkgModel = 3; } } if (opt.oniaMode==1) buildModelJpsi2015(myws, sigModel, bkgModel,inExcStat); else if (opt.oniaMode==2) buildModelUpsi2015(myws, sigModel, bkgModel,inExcStat); pdf =(RooAbsPdf*) myws.pdf("pdf"); RooFitResult* fitObject = pdf->fitTo(*dataOS_fit,Save(),Hesse(kTRUE),Extended(kTRUE)); // Fit } RooPlot* frame = mass->frame(Bins(nbins),Range(opt.dMuon.M.Min, opt.dMuon.M.Max)); RooPlot* frame2 = NULL; dataSS_fit->plotOn(frame, Name("dataSS_FIT"), MarkerColor(kRed), LineColor(kRed), MarkerSize(1.2)); dataOS_fit->plotOn(frame, Name("dataOS_FIT"), MarkerColor(kBlue), LineColor(kBlue), MarkerSize(1.2)); if (doFit) { pdf->plotOn(frame,Name("thePdf"),Normalization(dataOS_fit->sumEntries(),RooAbsReal::NumEvent)); RooHist *hpull = frame -> pullHist(0,0,true); hpull -> SetName("hpull"); frame2 = mass->frame(Title("Pull Distribution"),Bins(nbins),Range(opt.dMuon.M.Min,opt.dMuon.M.Max)); frame2 -> addPlotable(hpull,"PX"); } drawPlot(frame,frame2, pdf, opt, doFit,inExcStat); TString OutputFileName = ""; if (isPbPb) { FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/PbPbData/OniaTree_262548_262893.root"; opt.RunNb.Start=262548; opt.RunNb.End=262893; if (oniamode==1) {OutputFileName = (TString)("JPSIPbPbDataset.root");} if (oniamode==2) {OutputFileName = (TString)("YPbPbDataset.root");} if (oniamode==3) {OutputFileName = (TString)("ZPbPbDataset.root");} } else { FileName = "/afs/cern.ch/user/a/anstahll/work/public/ExpressStream2015/ppData/OniaTree_262163_262328.root"; opt.RunNb.Start=262163; opt.RunNb.End=262328; if (oniamode==1) {OutputFileName = (TString)("JPSIppDataset.root");} if (oniamode==2) {OutputFileName = (TString)("YppDataset.root");} if (oniamode==3) {OutputFileName = (TString)("ZppDataset.root");} } TFile* oFile = new TFile(OutputFileName,"RECREATE"); oFile->cd(); hDataOS->Write("hDataOS"); dataOS_fit->Write("dataOS_FIT"); oFile->Write(); oFile->Close(); }
//求雅克比矩阵。 void SolveJacob(const float* MechPara, const float* R1, const float* R2, float* jacob_s, float* jacob_e) { float A1[3],A2[3],A3[3],A4[3],B1[3],B2[3],B3[3],B4[3],B5[3],B6[3],C1[3],C2[3]; const float l1 = MechPara[0]; //const float l2 = MechPara[1]; const float d1 = MechPara[2]; const float r1 = MechPara[3]; const float d2 = MechPara[4]; const float r2 = MechPara[5]; const float d3 = MechPara[6]; const float r3 = MechPara[7]; const float alphaa1 = MechPara[8]; const float psta2 = MechPara[9]; const float psta3 = MechPara[10]; const float alphaa4 = MechPara[11]; const float alphab1 = MechPara[12]; const float alphab2 = MechPara[13]; const float alphab3 = MechPara[14]; const float alphab4 = MechPara[15]; const float alphab5 = MechPara[16]; const float alphab6 = MechPara[17]; const float alphac1 = MechPara[18]; const float alphac2 = MechPara[19]; SolveTmpVec(r1,alphaa1,d1,A1); SolveTmpVec(r1,alphaa4,d1,A4); SolveTmpVec(r2,alphab1,d2,B1); SolveTmpVec(r2,alphab2,d2,B2); SolveTmpVec(r2,alphab3,d2,B3); SolveTmpVec(r2,alphab4,d2,B4); SolveTmpVec(r2,alphab5,d2,B5); SolveTmpVec(r2,alphab6,d2,B6); SolveTmpVec(r3,alphac1,d3,C1); SolveTmpVec(r3,alphac2,d3-84,C2); A2[0] = psta2; A2[1] = r1; A2[2] = d1; A3[0] = psta3; A3[1] = -r1; A3[2] = d1; float A[3] = {0,0,0}; float B[3]; float tmpl[3]; tmpl[0] = tmpl[1] = 0; tmpl[2] = l1; MatMultVec(R1,tmpl,B); float B1_r[3], B2_r[3], B3_r[3], B4_r[3], B5_r[3], B6_r[3], C1_r[3], C2_r[3], ld1[3], ld2[3], ld3[3], ld4[3], ld5[3], ld6[3]; MatMultVec(R1,B1,B1_r); MatMultVec(R1,B2,B2_r); MatMultVec(R1,B3,B3_r); MatMultVec(R1,B4,B4_r); MatMultVec(R1,B5,B5_r); MatMultVec(R1,B6,B6_r); MatMultVec(R2,C1,C1_r); MatMultVec(R2,C2,C2_r); VecAdd(B,C1_r,C1_r); VecAdd(B,C2_r,C2_r); VecSub(B1_r,A1,ld1); VecSub(B2_r,A2,ld2); VecSub(B3_r,A3,ld3); VecSub(B4_r,A4,ld4); VecSub(C1_r,B5,ld5); VecSub(C2_r,B6,ld6); Normalization(ld1); Normalization(ld2); Normalization(ld3); Normalization(ld4); Normalization(ld5); Normalization(ld6); float B1_r_A[3], B2_r_A[3], B3_r_A[3], B4_r_A[3], C1_r_B[3], C2_r_B[3]; VecSub(B1_r,A,B1_r_A); VecSub(B2_r,A,B2_r_A); VecSub(B3_r,A,B3_r_A); VecSub(B4_r,A,B4_r_A); VecSub(C1_r,B,C1_r_B); VecSub(C2_r,B,C2_r_B); float tmp[3]; VecCross(B1_r_A,ld1,tmp); jacob_s[0] = tmp[0]; jacob_s[4] = tmp[1]; jacob_s[8] = tmp[2]; VecCross(B2_r_A,ld2,tmp); jacob_s[1] = tmp[0]; jacob_s[5] = tmp[1]; jacob_s[9] = tmp[2]; VecCross(B3_r_A,ld3,tmp); jacob_s[2] = tmp[0]; jacob_s[6] = tmp[1]; jacob_s[10] = tmp[2]; VecCross(B4_r_A,ld4,tmp); jacob_s[3] = tmp[0]; jacob_s[7] = tmp[1]; jacob_s[11] = tmp[2]; VecCross(C1_r_B,ld5,tmp); jacob_e[0] = tmp[0]; jacob_e[2] = tmp[1]; jacob_e[4] = tmp[2]; VecCross(C2_r_B,ld6,tmp); jacob_e[1] = tmp[0]; jacob_e[3] = tmp[1]; jacob_e[5] = tmp[2]; }
void SCANLINE::Compute_pixel_intensity() { vector <float> Intensity_diffuse(3); vector <float> Intensity_specular(3); float cylinder_u,cylinder_v; int shininess = 8; for (int i = 0; i< Ymax ; i++ ) for (int j = 0; j< Xmax; j++ ) { vector<float> pixel_normal(real_pixel[i][j].begin()+2,real_pixel[i][j].begin()+5); vector<float> device_xyz(real_pixel[i][j].begin()+5,real_pixel[i][j].end()); if(vector_length(pixel_normal) == 0) continue; // if(vector_length(device_xyz) == 0) // continue; // datatest<<i<<'\t'<<j; // for(int p = 0; p<(int)pixel_normal.size(); p++) // datatest<<setw(15)<<pixel_normal[p]; // datatest<<endl; vector<float> line_inter(4); compute_invert(device_xyz);//out put xyz in world space vector_subtraction(line_inter, ObjectCenter, device_xyz); // for(int p = 0; p<(int)line_inter.size(); p++) // datatest<<setw(15)<<line_inter[p]; // datatest<<endl; Normalization(line_inter); //normalize the pixel normal Normalization(pixel_normal); ///texture mapping // textureMapping(pixel_normal,cylinder_u,cylinder_v); textureMapping(pixel_normal,cylinder_u,cylinder_v); ///------------------------------- float cos_diffuse = dot_product3D(pixel_normal,vec_light); float cos_specular = pow(dot_product3D(pixel_normal,H_specular), shininess); for (int p = 0; p< 3 ; p++ ) { ///----------Intensity diffuse----Kd*I*(NL) Intensity_diffuse[p] = K_diffuse*I_light[p]*cos_diffuse; ///----------Intensity specular----Ks*I*(NH)^n Intensity_specular[p] = K_specular*I_light[p]*cos_specular; //---------------sum of all intensity-- //replace normal value to RGB value in real_pixel real_pixel[i][j][p+2]= Intensity_diffuse[p] + Intensity_specular[p] + Intensity_ambient[p] +imagePixel[(int)cylinder_v][(int)cylinder_u][p]; if(real_pixel[i][j][p+2] > 1) real_pixel[i][j][p+2] = 1; } } // datatest.close(); }