void SiteWaterMainsTemperature_Impl::populateValidityReport(ValidityReport& report,bool checkNames) const { // Inherit lower-level errors ModelObject_Impl::populateValidityReport(report,checkNames); if (report.level() > StrictnessLevel::Draft) { boost::optional<IddKey> key = iddObject().getField(OS_Site_WaterMainsTemperatureFields::CalculationMethod).get().getKey(calculationMethod()); OS_ASSERT(key); if (key->name() == "Schedule") { if (!temperatureSchedule()) { report.insertError(DataError(OS_Site_WaterMainsTemperatureFields::TemperatureScheduleName, getObject<ModelObject>(), DataErrorType::NullAndRequired)); } } else { // Correlation if (!annualAverageOutdoorAirTemperature()) { report.insertError(DataError(OS_Site_WaterMainsTemperatureFields::AnnualAverageOutdoorAirTemperature, getObject<ModelObject>(), DataErrorType::NullAndRequired)); } if (!maximumDifferenceInMonthlyAverageOutdoorAirTemperatures()) { report.insertError(DataError(OS_Site_WaterMainsTemperatureFields::MaximumDifferenceInMonthlyAverageOutdoorAirTemperatures, getObject<ModelObject>(), DataErrorType::NullAndRequired)); } } } }
void GasMixture_Impl::populateValidityReport(ValidityReport& report,bool checkNames) const { // Inherit lower-level errors ModelObject_Impl::populateValidityReport(report,checkNames); if (report.level() == StrictnessLevel::Final) { // all gases must be defined for (unsigned i = 0, n = numGases(); i < n; ++i) { try { std::string type = getGasType(i); } catch (...) { report.insertError(DataError(mf_getGasTypeFieldIndex(i), getObject<GasMixture>(), DataErrorType::NullAndRequired)); } try { /* double fraction =*/ getGasFraction(i); } catch (...) { report.insertError(DataError(mf_getGasFractionFieldIndex(i), getObject<GasMixture>(), DataErrorType::NullAndRequired)); } } } }
} int WinSerial::getBlock(char *buf, unsigned long size) { int ret; unsigned long count; unsigned long bytesRead; int emptyReads = 0; if (!mSetup) setupLink(); for (count = 0;count < size;count += bytesRead) { ret = ReadFile(mPortFh, &buf[count], 64, &bytesRead, 0); /* to avoid hanging here if we loose contact */ if (bytesRead > 0) emptyReads = 0; else emptyReads++; if (emptyReads > 10) { if (gDebugging & thisModule) fprintf(stderr, "short read %ld\n", size - count); printf("throwing DataError\n"); throw DataError(1); } } return 1;
void voigtian(RooDataSet *dataset, RooDataSet *dataset2, RooRealVar &variable, RooPlot *fitFrame, RooBinning b, double rangeMin, double rangeMax, vector <double> &fitParameters) { RooRealVar mean("mean","mean",0.0,-0.1,0.1); RooRealVar sigma("sigma","sigma",0.5,0.0,1.0); RooRealVar width("width","width",0.5,0.0,1.0); RooVoigtian * pdf = new RooVoigtian("pdf","Voigtian",variable,mean,sigma,width); dataset->plotOn(fitFrame,Name("myhist"),Binning(b),DataError(RooAbsData::SumW2)); RooFitResult * res = pdf->fitTo(*dataset, Range(rangeMin, rangeMax),Save(),SumW2Error(kTRUE)); res->Print(); //minNll = res->minNll(); pdf->plotOn(fitFrame,Name("mycurve")); fitParameters.push_back(3); // nb of fit parameters fitParameters.push_back(mean.getVal()); fitParameters.push_back(mean.getError()); fitParameters.push_back(sigma.getVal()); fitParameters.push_back(sigma.getError()); fitParameters.push_back(width.getVal()); fitParameters.push_back(width.getError()); }
void THSRooFit::PlotDataModel(){ //Function to plot the data and fitted model for each variable TCanvas *canvas=0; if(!fCanvases){fCanvases=new TList();fCanvases->SetOwner();fCanvases->SetName(TString("RFPlots")+GetName());} //Loop over variables for(Int_t idr=0;idr<fVariables.getSize();idr++){ cout<<"Plotting versus "<<fVariables[idr].GetName()<<endl; RooRealVar* var=fWS->var(fVariables[idr].GetName());//get variable if(!var) continue; fCanvases->Add(canvas=new TCanvas(TString(GetName())+fVariables[idr].GetName()+Form("%d",fFiti),TString(GetName())+fVariables[idr].GetName()));//create new canvas for drawing on RooPlot* frame = var->frame(); // RooFit frame fData->plotOn(frame, DataError(RooAbsData::SumW2) ) ; //plot the data fModel->plotOn(frame,LineColor(kRed)) ; //model = signal + back fit result //Get the chi2 fChi2=frame->chiSquare(); cout<<fFiti<<" THSRooFit::PlotDataModel() chi2 = "<<fChi2<<endl; fModel->paramOn(frame, Layout(0.1, 0.4, 0.9), Format("NEU",AutoPrecision(2)), ShowConstants()); //show fit parameters frame->SetTitle(TString("Fit components for ")+fVariables[idr].GetName()); //Loop over components for(Int_t ic=0;ic<fPDFs.getSize();ic++) fModel->plotOn(frame,Components(fPDFs[ic]),LineStyle(kDashed),LineColor(ic%8+1)) ; //just the back fit result frame->Draw() ; canvas->Modified(); canvas->Update(); } }
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(); };
//Read in a general basis set from a GAMESS log file BasisSet * BasisSet::ParseGAMESSBasisSet(BufferFile * Buffer, long NumAtoms, const mpAtom * Atoms) { long NumShells=0, NextAtom=0, ShellStart=0, fShellStart=0, BasisEndPos, nTotFuncs=0, LinePos, EndPos, iatom, items; char LineText[kMaxLineLength+1]; Buffer->GetLine(LineText); Buffer->LocateKeyWord("CONTRACTION COEFFICIENT", 21); Buffer->SkipnLines(2); long StartPos = Buffer->GetFilePos(); //go to the end of the basis and get the total # of shells to dimension mem //output was changed in June, 2000 bool ShellsFound = Buffer->LocateKeyWord("TOTAL NUMBER OF BASIS SET SHELLS", 32); if (!ShellsFound) ShellsFound = Buffer->LocateKeyWord("TOTAL NUMBER OF SHELLS", 22); if (ShellsFound) { BasisEndPos = Buffer->GetFilePos(); Buffer->GetLine(LineText); LinePos = FindKeyWord(LineText, "=", 1) + 1; sscanf(&(LineText[LinePos]),"%ld",&NumShells); } else return NULL; if (NumShells<=0) return NULL; //invalid number of shells if (NumAtoms <= 0) return NULL; BasisSet * Basis = new BasisSet(NumAtoms, NumShells); if (Basis == NULL) return NULL;//No memory! Buffer->SetFilePos(StartPos); Buffer->SkipnLines(2); //advance to the first primitive line //Note the atom label is skipped since it is just a general text string and the //Basis set is always given in the same order as the coordinates //The ishell loop could be a do-while structure, but this ensures //that I don't go off the end of the shell array for (long ishell=0; ishell<NumShells; ishell++) { float fExp, fCoef1, fCoef2, fCoef3, scrap; char ShellText[10]; long fShell, scrapl, NumPrims, CoefsperPrim; short ShellType; BasisShell foo; StartPos = Buffer->GetFilePos(); EndPos = Buffer->FindBlankLine(); NumPrims = Buffer->GetNumLines(EndPos-StartPos); Buffer->GetLine(LineText); items = sscanf(LineText, "%ld%5s",&fShell, ShellText); if (items != 2) throw DataError(); CoefsperPrim = 1; switch (ShellText[0]) { case 'S': ShellType=SShell; break; case 'P': ShellType=PShell; break; case 'D': ShellType=DShell; break; case 'F': ShellType=FShell; break; case 'G': ShellType=GShell; break; case 'H': ShellType=HShell; break; case 'I': ShellType=IShell; break; case 'L': ShellType=LShell; CoefsperPrim = 2; break; default: wxString msg; msg.Printf(_("Unknown shell type encountered, shell label = %s"), ShellText); wxLogMessage(msg); throw DataError(); } Basis->Shells.push_back(foo); Basis->Shells[ishell].NumPrims = NumPrims; Basis->Shells[ishell].ShellType = ShellType; std::vector<float> & Exponent = Basis->Shells[ishell].Exponent; std::vector<float> & NormCoef = Basis->Shells[ishell].NormCoef; std::vector<float> & InputCoef = Basis->Shells[ishell].InputCoef; Exponent.reserve(NumPrims); if (ShellType >= 0) { NormCoef.reserve(NumPrims); InputCoef.reserve(NumPrims); } else { NormCoef.reserve(2*NumPrims); InputCoef.reserve(2*NumPrims); } bool OldStyle = false; if (FindKeyWord(LineText, "(", 1) != -1) OldStyle=true; for (long iprim=0; iprim<NumPrims; iprim++) { InputCoef.push_back(0.0); NormCoef.push_back(0.0); if (ShellType<0) { InputCoef.push_back(0.0); NormCoef.push_back(0.0); } Exponent.push_back(0.0); } for (long iprim=0; iprim<NumPrims; iprim++) { if (ShellType>=0) { if (OldStyle) { items = sscanf(LineText, "%ld%5s%ld%f%f (%f)",&fShell, ShellText, &scrapl, &fExp, &fCoef1, &scrap); if (items != 6) throw DataError(); InputCoef[iprim] = scrap; } else { items = sscanf(LineText, "%ld%5s%ld%f%f",&fShell, ShellText, &scrapl, &fExp, &fCoef1); if (items != 5) throw DataError(); InputCoef[iprim] = fCoef1; } } else { if (OldStyle) { items = sscanf(LineText, "%ld%5s%ld%f%f (%f)%f (%f)",&fShell, ShellText, &scrapl, &fExp, &fCoef1,&scrap,&fCoef2,&fCoef3); NormCoef[iprim+NumPrims] = fCoef2; InputCoef[iprim+NumPrims] = fCoef3; InputCoef[iprim] = scrap; if (items != 8) throw DataError(); } else { items = sscanf(LineText, "%ld%5s%ld%f%f %f",&fShell, ShellText, &scrapl, &fExp, &fCoef1,&fCoef2); NormCoef[iprim+NumPrims] = fCoef2; //This is not normalized, but we take care of that later InputCoef[iprim+NumPrims] = fCoef2; InputCoef[iprim] = fCoef1; if (items != 6) throw DataError(); } } Exponent[iprim] = fExp; NormCoef[iprim] = fCoef1; //Coefficients are already normalized when read in from in front of parenthesis //so this code is unneeded but might be useful in the future /* ExpNorm = sqrt(sqrt(fExp)); ExpNorm2 = ExpNorm*ExpNorm; ExpNorm *= ExpNorm2; //Normalization constant is: [fExp^(n+3/2) 2^(2n+3/2)/(pi^3/2 n!!)]^1/2 //This factor is correct for functions of the form xx, xxx, etc but is off //for the xy, xxy, etc functions which must be multiplied by sqrt3, sqrt5 etc later switch (ShellType) { case -1: //L shells NormCoef[iprim+NumPrims] = fCoef2*PNorm*ExpNorm*ExpNorm2; case 0: //S shell NormCoef[iprim] *= SNorm*ExpNorm; break; case 1: //P shell NormCoef[iprim] *= PNorm*ExpNorm*ExpNorm2; break; case 2: //D shell NormCoef[iprim] *= DNorm*fExp*ExpNorm; break; case 3: //F shell NormCoef[iprim] *= FNorm*fExp*ExpNorm*ExpNorm2; break; case 4: //G shell NormCoef[iprim] *= GNorm*fExp*fExp*ExpNorm; break; }*/ Buffer->GetLine(LineText); } StartPos = Buffer->GetFilePos(); Buffer->GetLine(LineText); Buffer->SetFilePos(StartPos); long iscanerr = sscanf(LineText, "%ld %5s %ld %f (%f) ",&scrapl, ShellText, &scrapl, &fExp, &scrap); nTotFuncs += Basis->Shells[ishell].GetNumFuncs(false); Basis->NumShells++; if (iscanerr<3) {//Found next atom label so tidy up the current atom Buffer->SkipnLines(2); //Skip Atom label and blank line long nGotShells = ishell-ShellStart+1; long nMappedAtoms = (fShell-fShellStart-nGotShells)/nGotShells + 1; Basis->NumFuncs += nMappedAtoms*nTotFuncs; //skip over any MM atoms since they aren't included in the basis while (Atoms[NextAtom].IsSIMOMMAtom() && (NextAtom < NumAtoms)) NextAtom++; nTotFuncs = 0; //reset the function counter for the next atom for (iatom=0; iatom<nMappedAtoms; iatom++) { Basis->BasisMap[2*NextAtom] = ShellStart; Basis->BasisMap[2*NextAtom+1] = ishell; NextAtom++; } ShellStart = ishell+1; fShellStart = fShell; } if (fShell >= NumShells) break; } return Basis; } /*ParseGAMESSBasisSet*/
void MEPdfPartialB::DrawDeltaE(RooDataSet* ds){ mbc->setRange("mbcSignal",cuts->get_mbc_min_h0(m_mode,m_h0mode),cuts->get_mbc_max_h0(m_mode,m_h0mode)); RooPlot* deFrame = de->frame(); ds->plotOn(deFrame,DataError(RooAbsData::SumW2),MarkerSize(1),MarkerColor(kGreen)); pdf_part->plotOn(deFrame,LineWidth(2),LineColor(kGreen)); ds->plotOn(deFrame,DataError(RooAbsData::SumW2),MarkerSize(1),CutRange("mbcSignal")); pdf_part->plotOn(deFrame,LineWidth(2),ProjectionRange("mbcSignal")); RooHist* hdepull = deFrame->pullHist(); RooPlot* dePull = de->frame(Title("#Delta E pull distribution")); dePull->addPlotable(hdepull,"P"); dePull->GetYaxis()->SetRangeUser(-5,5); TCanvas* cm = new TCanvas("Delta E","Delta E",600,700); cm->cd(); TPad *pad3 = new TPad("pad3","pad3",0.01,0.20,0.99,0.99); TPad *pad4 = new TPad("pad4","pad4",0.01,0.01,0.99,0.20); pad3->Draw(); pad4->Draw(); pad3->cd(); pad3->SetLeftMargin(0.15); pad3->SetFillColor(0); deFrame->GetXaxis()->SetTitleSize(0.05); deFrame->GetXaxis()->SetTitleOffset(0.85); deFrame->GetXaxis()->SetLabelSize(0.04); deFrame->GetYaxis()->SetTitleOffset(1.6); deFrame->Draw(); stringstream out; out.str(""); out << "#chi^{2}/n.d.f = " << deFrame->chiSquare(); TPaveText *pt = new TPaveText(0.6,0.75,0.98,0.9,"brNDC"); pt->SetFillColor(0); pt->SetTextAlign(12); pt->AddText(out.str().c_str()); pt->AddText(cuts->GetLabel(m_mode,m_h0mode).c_str()); pt->Draw(); TLine *de_line_RIGHT = new TLine(cuts->get_de_min_h0(m_mode,m_h0mode),0,cuts->get_de_min_h0(m_mode,m_h0mode),80); de_line_RIGHT->SetLineColor(kRed); de_line_RIGHT->SetLineStyle(1); de_line_RIGHT->SetLineWidth((Width_t)2.); de_line_RIGHT->Draw(); TLine *de_line_LEFT = new TLine(cuts->get_de_max_h0(m_mode,m_h0mode),0,cuts->get_de_max_h0(m_mode,m_h0mode),80); de_line_LEFT->SetLineColor(kRed); de_line_LEFT->SetLineStyle(1); de_line_LEFT->SetLineWidth((Width_t)2.); de_line_LEFT->Draw(); pad4->cd(); pad4->SetLeftMargin(0.15); pad4->SetFillColor(0); dePull->SetMarkerSize(0.05); dePull->Draw(); TLine *de_lineUP = new TLine(cuts->get_de_fit_min(),3,cuts->get_de_fit_max(),3); de_lineUP->SetLineColor(kBlue); de_lineUP->SetLineStyle(2); de_lineUP->Draw(); TLine *de_line = new TLine(cuts->get_de_fit_min(),0,cuts->get_de_fit_max(),0); de_line->SetLineColor(kBlue); de_line->SetLineStyle(1); de_line->SetLineWidth((Width_t)2.); de_line->Draw(); TLine *de_lineDOWN = new TLine(cuts->get_de_fit_min(),-3,cuts->get_de_fit_max(),-3); de_lineDOWN->SetLineColor(kBlue); de_lineDOWN->SetLineStyle(2); de_lineDOWN->Draw(); cm->Update(); out.str(""); out << "pics/de_part_m" << m_mode << "_h0m" << m_h0mode << ".eps"; cm->Print(out.str().c_str()); string line = string("evince ") + out.str() + string(" &"); system(line.c_str()); out.str(""); out << "pics/de_part_m" << m_mode << "_h0m" << m_h0mode << ".root"; cm->Print(out.str().c_str()); }
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 drawCtauPlot(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 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 drawing options bool setLogScale, // Draw plot with log scale bool incSS, // Include Same Sign data int nBins, // Number of bins used for plotting bool paperStyle=false,// if true, print less info bool saveWS=true // save the workspace into a file ) { if (DSTAG.find("_")!=std::string::npos) DSTAG.erase(DSTAG.find("_")); string dsOSName = Form("dOS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); string dsSSName = Form("dSS_%s_%s", DSTAG.c_str(), (isPbPb?"PbPb":"PP")); // Create the main plot of the fit // RooPlot* frame = myws.var("invMass")->frame(Bins(nBins), Range(cut.dMuon.M.Min, cut.dMuon.M.Max)); RooPlot* frame = myws.var("ctau")->frame(Bins(nBins), Range(-1,3)); 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 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)); // 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("#font[12]{l}_{J/#psi} (mm)"); frame->GetXaxis()->SetTitleOffset(1.1); frame->GetYaxis()->SetTitleOffset(1.45); frame->GetXaxis()->SetTitleSize(0.05); frame->GetYaxis()->SetTitleSize(0.05); } setRange(myws, frame, dsOSName, setLogScale, cut.dMuon.AbsRap.Min); if (paperStyle) { double Ydown = 0.1;//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(); 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.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; } } if (cut.dMuon.AbsRap.Min>0.1) {t->DrawLatex(0.20, 0.86-dy, Form("%.1f < |y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Min,cut.dMuon.AbsRap.Max)); dy+=1.5*0.045;} else {t->DrawLatex(0.20, 0.86-dy, Form("|y^{#mu#mu}| < %.1f",cut.dMuon.AbsRap.Max)); dy+=1.5*0.045;} t->DrawLatex(0.20, 0.86-dy, Form("%g < p_{T}^{#mu#mu} < %g GeV/c",cut.dMuon.Pt.Min,cut.dMuon.Pt.Max)); dy+=0.045; t->DrawLatex(0.20, 0.86-dy, Form("%g < M^{#mu#mu} < %g GeV/c^{2}",cut.dMuon.M.Min,cut.dMuon.M.Max)); dy+=0.045; if (isPbPb) {t->DrawLatex(0.20, 0.86-dy, Form("Cent. %d-%d%%", (int)(cut.Centrality.Start/2), (int)(cut.Centrality.End/2))); dy+=0.045;} dy+=0.5*0.045; t->DrawLatex(0.20, 0.86-dy, "#mu in acceptance"); dy+=0.045; // Drawing the Legend double ymin = 0.7802; if (paperStyle) { ymin = 0.72; } 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"); } 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(); // Save the plot in different formats gSystem->mkdir(Form("%splot/%s/root/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%splot/%s/root/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (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("%splot/%s/png/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%splot/%s/png/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.png", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (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("%splot/%s/pdf/", outputDir.c_str(), DSTAG.c_str()), kTRUE); cFig->SaveAs(Form("%splot/%s/pdf/%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.pdf", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (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(); // Save the workspace if (saveWS) { gSystem->mkdir(Form("%sresult/%s/", outputDir.c_str(), DSTAG.c_str()), kTRUE); TFile *file = NULL; file = new TFile(Form("%sresult/%s/FIT_%s_%s_%s%s_pt%.0f%.0f_rap%.0f%.0f_cent%d%d.root", outputDir.c_str(), DSTAG.c_str(), DSTAG.c_str(), "Psi2SJpsi", (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), "RECREATE"); if (!file) { cout << "[ERROR] Output root file with fit results could not be created!" << endl; } else { file->cd(); myws.Write("workspace"); file->Write(); file->Close(); delete file; } } }
void GameArbiter::process_command(Message *command) { switch (command->type) { case UnitMove: { auto cmd = dynamic_cast<UnitMoveMessage *>(command); int stack_id = cmd->data1; IntSet units = cmd->data2; Path& path = cmd->data3; int target_id = cmd->data4; UnitStack::pointer stack = game->stacks.get(stack_id); if (units.empty() || !stack->has_units(units) || path.empty()) { throw DataError() << "Invalid UnitMove message"; } /* Check that the move is allowed; shorten it if necessary */ Point end_pos = path.back(); UnitStack::pointer end_stack = game->level.tiles[end_pos].stack; int end_stack_id = end_stack ? end_stack->id : 0; if (end_stack_id != target_id) { path.pop_back(); target_id = 0; } MovementModel movement(game); UnitStack::pointer selected_stack = stack->copy_subset(units); unsigned int allowed_steps = movement.check_path(*selected_stack, path); bool truncated = allowed_steps < path.size(); int attack_target_id = target_id; if (truncated) target_id = 0; path.resize(allowed_steps); if (!path.empty()) { end_pos = path.back(); /* Generate updates. */ Faction::pointer faction = stack->owner; bool move = units.size() == stack->units.size() && target_id == 0; bool split = units.size() < stack->units.size() && target_id == 0; bool merge = units.size() == stack->units.size() && target_id != 0; UnitStack::pointer target = game->stacks.find(target_id); if (move) target_id = stack_id; if (split) target_id = game->get_free_stack_id(); // Send the moves for (auto iter = path.begin(); iter != path.end(); iter++) { emit(create_message(MoveUnits, stack_id, units, *iter)); } // If the stack is splitting to a new empty position, create a stack there if (split) { emit(create_message(CreateStack, target_id, end_pos, faction->id)); } emit(create_message(TransferUnits, stack_id, units, path, target_id)); // If the whole stack merged with an existing one, destroy it if (merge) { emit(create_message(DestroyStack, stack_id)); } } else { end_pos = stack->position; } UnitStack::pointer attack_target = game->stacks.find(attack_target_id); bool attack = attack_target && (attack_target->owner != stack->owner); if (attack) { BOOST_LOG_TRIVIAL(debug) << "Attack!"; Point target_point = attack_target->position; Point attacking_point = end_pos; Battle battle(game, target_point, attacking_point); battle.run(); emit(create_message(DoBattle, end_stack_id, target_point, battle.moves)); } } break; case FactionReady: { auto cmd = dynamic_cast<FactionReadyMessage *>(command); int faction_id = cmd->data1; bool ready = cmd->data2; if (game->mark_faction_ready(faction_id, ready)) { emit(create_message(FactionReady, faction_id, ready)); } if (game->all_factions_ready()) { emit(create_message(TurnEnd)); // process turn end spawn_units(); game->turn_number++; emit(create_message(TurnBegin, game->turn_number)); } } break; case Chat: { auto chat_msg = dynamic_cast<ChatMessage *>(command); emit(create_message(Chat, chat_msg->data)); } break; case SetLevelData: case CreateStructure: case DestroyStructure: { emit(command->shared_from_this()); } break; default: break; } }
void Wpt_ZmassCompEtaBins_Gaus(const TString Mode,//Channel - Muon or Electron const TString corrName, const TString outputDir ) { TString plotTitle; TString mu_etaRange[6]; mu_etaRange[0] = "-2.1 #geq eta < -1.4"; mu_etaRange[1] = "-1.4 #geq eta < -0.7"; mu_etaRange[2] = "-0.7 #geq eta < 0"; mu_etaRange[3] = "0 #geq eta < 0.7"; mu_etaRange[4] = "0.7 #geq eta < 1.4"; mu_etaRange[5] = "1.4 #geq eta < 2.1"; TH1D* makeDiffHist(TH1D* h1, TH1D* h2, const TString name); const TString format("png"); Int_t ratioColor = kGray+2; TFile *fname_MC; TFile *fname_RD; gSystem->mkdir(outputDir,kTRUE); CPlot::sOutDir = outputDir; fname_MC = new TFile("Muon2012LoPU/Muon_DYToMuMu_S8.root"); fname_RD = new TFile("Muon2012LoPU/Muon_RD_LowPU.root"); if(Mode=="Electron") { fname_MC = new TFile("Electron2012LoPU/Ele_DYToEE_S8.root"); fname_RD = new TFile("Electron2012LoPU/Ele_RD_LowPU.root"); } CPlot *plotMllEtaBinP; CPlot *plotMllEtaBinM; CPlot *plotMllEtameanP; CPlot *plotMllEtameanM; CPlot *plotMllEtawidthP; CPlot *plotMllEtawidthM; TH1D *hMCetaBinP[ScaleBins]; TH1D *hRDetaBinP[ScaleBins]; TH1D *hMCetaBinM[ScaleBins]; TH1D *hRDetaBinM[ScaleBins]; RooDataHist *h1_MCetaBinP; RooDataHist *h1_RDetaBinP; RooDataHist *h1_MCetaBinM; RooDataHist *h1_RDetaBinM; TH1D *hMCmeanp = new TH1D("hMCmeanp","hMCmeanp",ScaleBins,-2.1,2.1);hMCmeanp->Sumw2(); TH1D *hRDmeanp = new TH1D("hRDmeanp","hRDmeanp",ScaleBins,-2.1,2.1);hRDmeanp->Sumw2(); TH1D *hMCmeanm = new TH1D("hMCmeanm","hMCmeanm",ScaleBins,-2.1,2.1);hMCmeanm->Sumw2(); TH1D *hRDmeanm = new TH1D("hRDmeanm","hRDmeanm",ScaleBins,-2.1,2.1);hRDmeanm->Sumw2(); TH1D *hMCwidthp = new TH1D("hMCwidthp","hMCwidthp",ScaleBins,-2.1,2.1);hMCwidthp->Sumw2(); TH1D *hRDwidthp = new TH1D("hRDwidthp","hRDwidthp",ScaleBins,-2.1,2.1);hRDwidthp->Sumw2(); TH1D *hMCwidthm = new TH1D("hMCwidthm","hMCwidthm",ScaleBins,-2.1,2.1);hMCwidthm->Sumw2(); TH1D *hRDwidthm = new TH1D("hRDwidthm","hRDwidthm",ScaleBins,-2.1,2.1);hRDwidthm->Sumw2(); char histName[50]; char tmpName[50]; TCanvas *myCan; myCan = MakeCanvas("myCan","myCan",800,600); myCan->SetPad(0,0,1.0,1.0); myCan->SetTopMargin(0.11); myCan->SetBottomMargin(0.15); myCan->SetLeftMargin(0.15); myCan->SetRightMargin(0.05); myCan->SetTickx(1); myCan->SetTicky(1); //============================= //Read Zmass histograms for each pt bin //============================= for(int i(0);i<ScaleBins;i++){ sprintf(tmpName,"h1_Zmass_muEtaP_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_muEtaP_%d",i); if(outputDir=="Wpt_ZmassPlotsEtaBins_noOverLap_Gaus") { sprintf(tmpName,"h1_Zmass_noOverLap_muEtaP_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_noOverLap_muEtaP_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_LeadingLept_noOverLap_Gaus") { sprintf(tmpName,"h1_Zmass_LeadingLept_noOverLap_muEtaP_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_LeadingLept_noOverLap_muEtaP_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_LeadingLept_Gaus") { sprintf(tmpName,"h1_Zmass_LeadingLept_muEtaP_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_LeadingLept_muEtaP_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_TrailingLept_noOverLap_Gaus") { sprintf(tmpName,"h1_Zmass_TrailingLept_noOverLap_muEtaP_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_TrailingLept_noOverLap_muEtaP_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_TrailingLept_Gaus") { sprintf(tmpName,"h1_Zmass_TrailingLept_muEtaP_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_TrailingLept_muEtaP_%d",i); } sprintf(histName,"hMCetaBinP_%d",i); hMCetaBinP[i]= (TH1D*)fname_MC->Get(tmpName)->Clone(histName); hMCetaBinP[i]->Sumw2(); sprintf(histName,"hRDetaBinP_%d",i); hRDetaBinP[i]= (TH1D*)fname_RD->Get(tmpName)->Clone(histName); hRDetaBinP[i]->Sumw2(); sprintf(tmpName,"h1_Zmass_muEtaM_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_muEtaM_%d",i); if(outputDir=="Wpt_ZmassPlotsEtaBins_noOverLap_Gaus") { sprintf(tmpName,"h1_Zmass_noOverLap_muEtaM_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_noOverLap_muEtaM_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_LeadingLept_noOverLap_Gaus") { sprintf(tmpName,"h1_Zmass_LeadingLept_noOverLap_muEtaM_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_LeadingLept_noOverLap_muEtaM_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_LeadingLept_Gaus") { sprintf(tmpName,"h1_Zmass_LeadingLept_muEtaM_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_LeadingLept_muEtaM_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_TrailingLept_noOverLap_Gaus") { sprintf(tmpName,"h1_Zmass_TrailingLept_noOverLap_muEtaM_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_TrailingLept_noOverLap_muEtaM_%d",i); } if(outputDir=="Wpt_ZmassPlotsEtaBins_TrailingLept_Gaus") { sprintf(tmpName,"h1_Zmass_TrailingLept_muEtaM_%d",i); if(corrName=="CorrTotalRegion") sprintf(tmpName,"h1_ZmassCorr_TrailingLept_muEtaM_%d",i); } sprintf(histName,"hMCetaBinM_%d",i); hMCetaBinM[i]= (TH1D*)fname_MC->Get(tmpName)->Clone(histName); hMCetaBinM[i]->Sumw2(); sprintf(histName,"hRDetaBinM_%d",i); hRDetaBinM[i]= (TH1D*)fname_RD->Get(tmpName)->Clone(histName); hRDetaBinM[i]->Sumw2(); hMCetaBinP[i] -> SetMarkerSize(0.9); hMCetaBinP[i] -> SetMarkerColor(kRed); hMCetaBinP[i] -> SetLineColor(kRed); hRDetaBinP[i] -> SetMarkerSize(0.9); hRDetaBinP[i] -> SetMarkerColor(kBlack); hRDetaBinP[i] -> SetLineColor(kBlack); hMCetaBinM[i] -> SetMarkerSize(0.9); hMCetaBinM[i] -> SetMarkerColor(kRed); hMCetaBinM[i] -> SetLineColor(kRed); hRDetaBinM[i] -> SetMarkerSize(0.9); hRDetaBinM[i] -> SetMarkerColor(kBlack); hRDetaBinM[i] -> SetLineColor(kBlack); RooRealVar x("x", "x",80,100); x.setBins(40); x.setRange("R0",86,96); h1_MCetaBinP = new RooDataHist("h1_MCetaBinP","h1_MCetaBinP",RooArgSet(x),hMCetaBinP[i]); h1_MCetaBinM = new RooDataHist("h1_MCetaBinM","h1_MCetaBinM",RooArgSet(x),hMCetaBinM[i]); h1_RDetaBinP = new RooDataHist("h1_RDetaBinP","h1_RDetaBinP",RooArgSet(x),hRDetaBinP[i]); h1_RDetaBinM = new RooDataHist("h1_RDetaBinM","h1_RDetaBinM",RooArgSet(x),hRDetaBinM[i]); //============================= //Gauss function //============================= RooRealVar meanMCp("meanMCp","",91.2,80,100); RooRealVar meanRDp("meanRDp","",91.2,80,100); RooRealVar meanMCm("meanMCm","",91.2,80,100); RooRealVar meanRDm("meanRDm","",91.2,80,100); RooRealVar sigmaMCp("sigmaMCp","",5,-50.,50.); RooRealVar sigmaRDp("sigmaRDp","",5,-50.,50.); RooRealVar sigmaMCm("sigmaMCm","",5,-50.,50.); RooRealVar sigmaRDm("sigmaRDm","",5,-50.,50.); RooGaussian mcModelp("mcModelp", "",x,meanMCp,sigmaMCp); RooGaussian mcModelm("mcModelm", "",x,meanMCm,sigmaMCm); RooGaussian dataModelp("dataModelp", "",x,meanRDp,sigmaRDp); RooGaussian dataModelm("dataModelm", "",x,meanRDm,sigmaRDm); //================================== //Fit Zmass distribution with Gaussian function //============================= mcModelp.fitTo(*h1_MCetaBinP,Range("R0")); mcModelm.fitTo(*h1_MCetaBinM,Range("R0")); dataModelp.fitTo(*h1_RDetaBinP,Range("R0")); dataModelm.fitTo(*h1_RDetaBinM,Range("R0")); //================================== //Fill 2D plots: etaBins and mean values //============================= hMCmeanp->SetBinContent(i+1,meanMCp.getVal()); hRDmeanp->SetBinContent(i+1,meanRDp.getVal()); hMCmeanm->SetBinContent(i+1,meanMCm.getVal()); hRDmeanm->SetBinContent(i+1,meanRDm.getVal()); hMCmeanp->SetBinError(i+1,meanMCp.getError()); hRDmeanp->SetBinError(i+1,meanRDp.getError()); hMCmeanm->SetBinError(i+1,meanMCm.getError()); hRDmeanm->SetBinError(i+1,meanRDm.getError()); hMCwidthp->SetBinContent(i+1,sigmaMCp.getVal()); hRDwidthp->SetBinContent(i+1,sigmaRDp.getVal()); hMCwidthm->SetBinContent(i+1,sigmaMCm.getVal()); hRDwidthm->SetBinContent(i+1,sigmaRDm.getVal()); hMCwidthp->SetBinError(i+1,sigmaMCp.getError()); hRDwidthp->SetBinError(i+1,sigmaRDp.getError()); hMCwidthm->SetBinError(i+1,sigmaMCm.getError()); hRDwidthm->SetBinError(i+1,sigmaRDm.getError()); cout<<meanMCp.getVal()<<"\t"<<meanMCm.getVal()<<"\t"<<meanRDp.getVal()<<"\t"<<meanRDm.getVal()<<endl; RooPlot* pframe = x.frame(Bins(40)); RooPlot* mframe = x.frame(Bins(40)); //================================== //Draw muon plus //================================== sprintf(tmpName,"pFit_etaBin%d_noCorr",i); plotTitle = "Wpt: " + mu_etaRange[i] + " of #mu^{+}, before correction"; if(corrName=="CorrTotalRegion") { sprintf(tmpName,"pFit_etaBin%d_Corr",i); plotTitle = "Wpt: " + mu_etaRange[i] + " of #mu^{+}, after correction"; } sprintf(histName,"Events / %.1f",hMCetaBinP[i]->GetBinWidth(1)); plotMllEtaBinP = new CPlot(tmpName,pframe,plotTitle,"M_{#mu#mu} [GeV]",histName); plotMllEtaBinP->setOutDir(CPlot::sOutDir); plotMllEtaBinP->SetLegend(0.7,0.7,0.88,0.82); h1_MCetaBinP->plotOn(pframe,LineColor(kRed),MarkerColor(kRed),MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"),DataError(RooAbsData::SumW2)); mcModelp.plotOn(pframe,LineColor(kRed)); h1_RDetaBinP->plotOn(pframe,LineColor(kBlack),MarkerColor(kBlack),MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"),DataError(RooAbsData::SumW2)); dataModelp.plotOn(pframe,LineColor(kBlack)); plotMllEtaBinP->GetLegend()->AddEntry(hMCetaBinP[i],"Z #rightarrow #mu#mu","pl"); plotMllEtaBinP->GetLegend()->AddEntry(hRDetaBinP[i],"Data","pl"); sprintf(tmpName,"MC: #mu=%.2f #pm %.2f, #sigma=%.2f #pm %.2f",meanMCp.getVal(),meanMCp.getError(),sigmaMCp.getVal(),sigmaMCp.getError()); plotMllEtaBinP->AddTextBox(tmpName,0.20,0.83,0.6,0.88,0); sprintf(tmpName,"Data: #mu=%.2f #pm %.2f, #sigma=%.2f #pm %.2f",meanRDp.getVal(),meanRDp.getError(),sigmaRDp.getVal(),sigmaRDp.getError()); plotMllEtaBinP->AddTextBox(tmpName,0.20,0.78,0.6,0.83,0); plotMllEtaBinP->SetYRange(0.,1.4*TMath::Max(hRDetaBinP[i]->GetMaximum(),hMCetaBinP[i]->GetMaximum())); plotMllEtaBinP->Draw(myCan,kTRUE,"png"); //================================== //Draw muon minus //============================= sprintf(tmpName,"mFit_etaBin%d_noCorr",i); plotTitle = "Wpt: " + mu_etaRange[i] + " of #mu^{-}, before correction"; if(corrName=="CorrTotalRegion") { sprintf(tmpName,"mFit_etaBin%d_Corr",i); plotTitle = "Wpt: " + mu_etaRange[i] + " of #mu^{-}, after correction"; } sprintf(histName,"Events / %.1f",hMCetaBinM[i]->GetBinWidth(1)); plotMllEtaBinM = new CPlot(tmpName,mframe,plotTitle,"M_{#mu#mu} [GeV]",histName); plotMllEtaBinM->setOutDir(CPlot::sOutDir); plotMllEtaBinM->SetLegend(0.7,0.7,0.88,0.82); h1_MCetaBinM->plotOn(mframe,LineColor(kRed),MarkerColor(kRed),MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"),DataError(RooAbsData::SumW2)); mcModelm.plotOn(mframe,LineColor(kRed)); h1_RDetaBinM->plotOn(mframe,LineColor(kBlack),MarkerColor(kBlack),MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP"),DataError(RooAbsData::SumW2)); dataModelm.plotOn(mframe,LineColor(kBlack)); plotMllEtaBinM->GetLegend()->AddEntry(hMCetaBinM[i],"Z #rightarrow #mu#mu","pl"); plotMllEtaBinM->GetLegend()->AddEntry(hRDetaBinM[i],"Data","pl"); sprintf(tmpName,"MC: #mu=%.2f #pm %.2f, #sigma=%.2f #pm %.2f",meanMCm.getVal(),meanMCm.getError(),sigmaMCm.getVal(),sigmaMCm.getError()); plotMllEtaBinM->AddTextBox(tmpName,0.20,0.83,0.6,0.88,0); sprintf(tmpName,"Data: #mu=%.2f #pm %.2f, #sigma=%.2f #pm %.2f",meanRDm.getVal(),meanRDm.getError(),sigmaRDm.getVal(),sigmaRDm.getError()); plotMllEtaBinM->AddTextBox(tmpName,0.20,0.78,0.6,0.83,0); plotMllEtaBinM->SetYRange(0.,1.4*TMath::Max(hRDetaBinM[i]->GetMaximum(),hMCetaBinM[i]->GetMaximum())); plotMllEtaBinM->Draw(myCan,kTRUE,"png"); } //================================== //Save Mean and Width histograms to root file //================================== TString filename = outputDir + "/Wpt_MeanWidth_Gaus_" + corrName + ".root"; TFile *outfile = new TFile(filename,"RECREATE"); hMCmeanp ->Write(); hMCmeanm ->Write(); hMCwidthp->Write(); hMCwidthm->Write(); hRDmeanp ->Write(); hRDmeanm ->Write(); hRDwidthp->Write(); hRDwidthm->Write(); outfile->Close(); //================================== //Draw 2D plots //================================== TString histoName = "plusMean_" + corrName; plotTitle = "Wpt: mean at #eta of #mu^{+}, before correction"; if(corrName=="CorrTotalRegion") plotTitle = "Wpt: mean at #eta of #mu^{+}, after correction"; plotMllEtameanP= new CPlot(histoName,plotTitle,"#eta of #mu^{+}","Mean of M(#mu^{+}#mu^{-})"); plotMllEtameanP->setOutDir(CPlot::sOutDir); plotMllEtameanP->AddHist1D(hMCmeanp,"Z#rightarrow #mu#mu","E1",kRed); plotMllEtameanP->AddHist1D(hRDmeanp,"Data","E1",kBlack); plotMllEtameanP->SetLegend(0.7,0.7,0.88,0.82); plotMllEtameanP->SetYRange(90,92); plotMllEtameanP->Draw(myCan,kTRUE,format); histoName = "minusMean_" + corrName; plotTitle = "Wpt: mean at #eta of #mu^{-}, before correction"; if(corrName=="CorrTotalRegion") plotTitle = "Wpt: mean at #eta of #mu^{-}, after correction"; plotMllEtameanM= new CPlot(histoName,plotTitle,"#eta of #mu^{-}","Mean of M(#mu^{+}#mu^{-})"); plotMllEtameanM->setOutDir(CPlot::sOutDir); plotMllEtameanM->AddHist1D(hMCmeanm,"Z#rightarrow #mu#mu","E1",kRed); plotMllEtameanM->AddHist1D(hRDmeanm,"Data","E1",kBlack); plotMllEtameanM->SetLegend(0.7,0.7,0.88,0.82); plotMllEtameanM->SetYRange(90,92); plotMllEtameanM->Draw(myCan,kTRUE,format); histoName = "plusWidth_" + corrName; plotTitle = "Wpt: width at #eta of #mu^{+}, before correction"; if(corrName=="CorrTotalRegion") plotTitle = "Wpt: width at #eta of #mu^{+}, after correction"; plotMllEtawidthP= new CPlot(histoName,plotTitle,"#eta of #mu^{+}","Width of M(#mu^{+}#mu^{-})"); plotMllEtawidthP->setOutDir(CPlot::sOutDir); plotMllEtawidthP->AddHist1D(hMCwidthp,"Z#rightarrow #mu#mu","E1",kRed); plotMllEtawidthP->AddHist1D(hRDwidthp,"Data","E1",kBlack); plotMllEtawidthP->SetLegend(0.7,0.7,0.88,0.82); plotMllEtawidthP->SetYRange(1.5,3); plotMllEtawidthP->Draw(myCan,kTRUE,format); histoName = "minusWidth_" + corrName; plotTitle = "Wpt: width at #eta of #mu^{-}, before correction"; if(corrName=="CorrTotalRegion") plotTitle = "Wpt: width at #eta of #mu^{-}, after correction"; plotMllEtawidthM= new CPlot(histoName,plotTitle,"#eta of #mu^{-}","Width of M(#mu^{+}#mu^{-})"); plotMllEtawidthM->setOutDir(CPlot::sOutDir); plotMllEtawidthM->AddHist1D(hMCwidthm,"Z#rightarrow #mu#mu","E1",kRed); plotMllEtawidthM->AddHist1D(hRDwidthm,"Data","E1",kBlack); plotMllEtawidthM->SetLegend(0.7,0.7,0.88,0.82); plotMllEtawidthM->SetYRange(1.5,3); plotMllEtawidthM->Draw(myCan,kTRUE,format); }