bool canUseFor(const RenderBlockFlow& flow) { #if !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(EFL) // FIXME: Non-mac platforms are hitting ASSERT(run.charactersLength() >= run.length()) // https://bugs.webkit.org/show_bug.cgi?id=123338 return false; #else if (!flow.frame().settings().simpleLineLayoutEnabled()) return false; if (!flow.firstChild()) return false; // This currently covers <blockflow>#text</blockflow> case. // The <blockflow><inline>#text</inline></blockflow> case is also popular and should be relatively easy to cover. if (flow.firstChild() != flow.lastChild()) return false; if (!flow.firstChild()->isText()) return false; if (!flow.isHorizontalWritingMode()) return false; if (flow.flowThreadState() != RenderObject::NotInsideFlowThread) return false; if (flow.hasOutline()) return false; if (flow.isRubyText() || flow.isRubyBase()) return false; if (flow.parent()->isDeprecatedFlexibleBox()) return false; // FIXME: Implementation of wrap=hard looks into lineboxes. if (flow.parent()->isTextArea() && flow.parent()->element()->fastHasAttribute(HTMLNames::wrapAttr)) return false; // FIXME: Placeholders do something strange. if (flow.parent()->isTextControl() && toRenderTextControl(*flow.parent()).textFormControlElement().placeholderElement()) return false; // These tests only works during layout. Outside layout this function may give false positives. if (flow.view().layoutState()) { #if ENABLE(CSS_SHAPES) if (flow.view().layoutState()->shapeInsideInfo()) return false; #endif if (flow.view().layoutState()->m_columnInfo) return false; } const RenderStyle& style = flow.style(); if (style.textDecorationsInEffect() != TextDecorationNone) return false; if (style.textAlign() == JUSTIFY) return false; // Non-visible overflow should be pretty easy to support. if (style.overflowX() != OVISIBLE || style.overflowY() != OVISIBLE) return false; if (!style.textIndent().isZero()) return false; if (style.wordSpacing() || style.letterSpacing()) return false; if (style.textTransform() != TTNONE) return false; if (!style.isLeftToRightDirection()) return false; if (style.lineBoxContain() != RenderStyle::initialLineBoxContain()) return false; if (style.writingMode() != TopToBottomWritingMode) return false; if (style.lineBreak() != LineBreakAuto) return false; if (style.wordBreak() != NormalWordBreak) return false; if (style.unicodeBidi() != UBNormal || style.rtlOrdering() != LogicalOrder) return false; if (style.lineAlign() != LineAlignNone || style.lineSnap() != LineSnapNone) return false; if (style.hyphens() == HyphensAuto) return false; if (style.textEmphasisFill() != TextEmphasisFillFilled || style.textEmphasisMark() != TextEmphasisMarkNone) return false; if (style.textShadow()) return false; #if ENABLE(CSS_SHAPES) if (style.resolvedShapeInside()) return true; #endif if (style.textOverflow() || (flow.isAnonymousBlock() && flow.parent()->style().textOverflow())) return false; if (style.hasPseudoStyle(FIRST_LINE) || style.hasPseudoStyle(FIRST_LETTER)) return false; if (style.hasTextCombine()) return false; if (style.backgroundClip() == TextFillBox) return false; if (style.borderFit() == BorderFitLines) return false; const RenderText& textRenderer = toRenderText(*flow.firstChild()); if (flow.containsFloats()) { // We can't use the code path if any lines would need to be shifted below floats. This is because we don't keep per-line y coordinates. // It is enough to test the first line width only as currently all floats must be overhanging. if (textRenderer.minLogicalWidth() > LineWidth(const_cast<RenderBlockFlow&>(flow), false, DoNotIndentText).availableWidth()) return false; } if (textRenderer.isCombineText() || textRenderer.isCounter() || textRenderer.isQuote() || textRenderer.isTextFragment() #if ENABLE(SVG) || textRenderer.isSVGInlineText() #endif ) return false; if (style.font().codePath(TextRun(textRenderer.text())) != Font::Simple) return false; if (style.font().isSVGFont()) return false; // We assume that all lines have metrics based purely on the primary font. auto& primaryFontData = *style.font().primaryFont(); if (primaryFontData.isLoading()) return false; if (!canUseForText(textRenderer, primaryFontData)) return false; return true; #endif }
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; }
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 Font::DrawText3D( std::string text, const Pos3D *pos, uint8_t align, float r, float g, float b, float a, double scale ) { if( ! Initialized ) return; if( LoadedTime.ElapsedSeconds() > Raptor::Game->Res.ResetTime.ElapsedSeconds() ) InitFont(); GLdouble x = 0., y = 0.; Pos3D tl, tr, br, bl; // Adjust for text vertical alignment. int text_height = TextHeight( text ); switch( align ) { case ALIGN_MIDDLE_LEFT: case ALIGN_MIDDLE_CENTER: case ALIGN_MIDDLE_RIGHT: y -= text_height / 2; break; case ALIGN_BASELINE_LEFT: case ALIGN_BASELINE_CENTER: case ALIGN_BASELINE_RIGHT: y -= Ascent; break; case ALIGN_BOTTOM_LEFT: case ALIGN_BOTTOM_CENTER: case ALIGN_BOTTOM_RIGHT: y -= text_height; break; } GLdouble left = 0., right = 0.; GLdouble top = 0., bottom = 0.; GLfloat tex_min_x = 0.f, tex_min_y = 0.f; GLfloat tex_max_x = 0.f, tex_max_y = 0.f; GLdouble min_x = 0.; GLdouble base_left = x; glPushAttrib( GL_ALL_ATTRIB_BITS ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_TEXTURE_2D ); glColor4f( r, g, b, a ); // Adjust for text horizontal alignment. int line_width = LineWidth( text ); switch( align ) { case ALIGN_TOP_CENTER: case ALIGN_MIDDLE_CENTER: case ALIGN_BASELINE_CENTER: case ALIGN_BOTTOM_CENTER: x -= line_width / 2; break; case ALIGN_TOP_RIGHT: case ALIGN_MIDDLE_RIGHT: case ALIGN_BASELINE_RIGHT: case ALIGN_BOTTOM_RIGHT: x -= line_width; break; } const char *text_ptr = text.c_str(); while( *text_ptr != '\0' ) { if( *text_ptr == '\n' ) { x = base_left; y += LineSkip; // Adjust for text horizontal alignment. line_width = LineWidth( text_ptr + 1 ); switch( align ) { case ALIGN_TOP_CENTER: case ALIGN_MIDDLE_CENTER: case ALIGN_BASELINE_CENTER: case ALIGN_BOTTOM_CENTER: x -= line_width / 2; break; case ALIGN_TOP_RIGHT: case ALIGN_MIDDLE_RIGHT: case ALIGN_BASELINE_RIGHT: case ALIGN_BOTTOM_RIGHT: x -= line_width; break; } } else { LoadChar( *text_ptr ); tex_min_x = Glyphs[ (unsigned char) *text_ptr ].TexMinX; tex_min_y = Glyphs[ (unsigned char) *text_ptr ].TexMinY; tex_max_x = Glyphs[ (unsigned char) *text_ptr ].TexMaxX; tex_max_y = Glyphs[ (unsigned char) *text_ptr ].TexMaxY; min_x = Glyphs[ (unsigned char) *text_ptr ].MinX; left = x + min_x; right = x + Glyphs[ (unsigned char) *text_ptr ].Pic->w + min_x; top = y; bottom = y + Glyphs[ (unsigned char) *text_ptr ].Pic->h; tl.Copy( pos ); tl.MoveAlong( &(pos->Right), left * scale ); tl.MoveAlong( &(pos->Up), -top * scale ); tr.Copy( pos ); tr.MoveAlong( &(pos->Right), right * scale ); tr.MoveAlong( &(pos->Up), -top * scale ); br.Copy( pos ); br.MoveAlong( &(pos->Right), right * scale ); br.MoveAlong( &(pos->Up), -bottom * scale ); bl.Copy( pos ); bl.MoveAlong( &(pos->Right), left * scale ); bl.MoveAlong( &(pos->Up), -bottom * scale ); glBindTexture( GL_TEXTURE_2D, Glyphs[ (unsigned char) *text_ptr ].Tex ); glBegin( GL_QUADS ); glTexCoord2f( tex_min_x, tex_min_y ); glVertex3d( tl.X, tl.Y, tl.Z ); glTexCoord2f( tex_max_x, tex_min_y ); glVertex3d( tr.X, tr.Y, tr.Z ); glTexCoord2f( tex_max_x, tex_max_y ); glVertex3d( br.X, br.Y, br.Z ); glTexCoord2f( tex_min_x, tex_max_y ); glVertex3d( bl.X, bl.Y, bl.Z ); glEnd(); x += Glyphs[ (unsigned char) *text_ptr ].Advance; } text_ptr ++; } glPopAttrib(); }
void Font::DrawText( std::string text, int x, int y, uint8_t align, float r, float g, float b, float a ) { if( ! Initialized ) return; if( LoadedTime.ElapsedSeconds() > Raptor::Game->Res.ResetTime.ElapsedSeconds() ) InitFont(); // Adjust for text vertical alignment. int text_height = TextHeight( text ); switch( align ) { case ALIGN_MIDDLE_LEFT: case ALIGN_MIDDLE_CENTER: case ALIGN_MIDDLE_RIGHT: y -= text_height / 2; break; case ALIGN_BASELINE_LEFT: case ALIGN_BASELINE_CENTER: case ALIGN_BASELINE_RIGHT: y -= Ascent; break; case ALIGN_BOTTOM_LEFT: case ALIGN_BOTTOM_CENTER: case ALIGN_BOTTOM_RIGHT: y -= text_height; break; } GLfloat left = 0.0f, right = 0.0f; GLfloat top = 0.0f, bottom = 0.0f; GLfloat tex_min_x = 0.0f, tex_min_y = 0.0f; GLfloat tex_max_x = 0.0f, tex_max_y = 0.0f; GLfloat min_x = 0.0f; GLfloat base_left = x; glPushAttrib( GL_ALL_ATTRIB_BITS ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_TEXTURE_2D ); glColor4f( r, g, b, a ); // Adjust for text horizontal alignment. int line_width = LineWidth( text ); switch( align ) { case ALIGN_TOP_CENTER: case ALIGN_MIDDLE_CENTER: case ALIGN_BASELINE_CENTER: case ALIGN_BOTTOM_CENTER: x -= line_width / 2; break; case ALIGN_TOP_RIGHT: case ALIGN_MIDDLE_RIGHT: case ALIGN_BASELINE_RIGHT: case ALIGN_BOTTOM_RIGHT: x -= line_width; break; } const char *text_ptr = text.c_str(); while( *text_ptr != '\0' ) { if( *text_ptr == '\n' ) { x = base_left; y += LineSkip; // Adjust for text horizontal alignment. line_width = LineWidth( text_ptr + 1 ); switch( align ) { case ALIGN_TOP_CENTER: case ALIGN_MIDDLE_CENTER: case ALIGN_BASELINE_CENTER: case ALIGN_BOTTOM_CENTER: x -= line_width / 2; break; case ALIGN_TOP_RIGHT: case ALIGN_MIDDLE_RIGHT: case ALIGN_BASELINE_RIGHT: case ALIGN_BOTTOM_RIGHT: x -= line_width; break; } } else { LoadChar( *text_ptr ); tex_min_x = Glyphs[ (unsigned char) *text_ptr ].TexMinX; tex_min_y = Glyphs[ (unsigned char) *text_ptr ].TexMinY; tex_max_x = Glyphs[ (unsigned char) *text_ptr ].TexMaxX; tex_max_y = Glyphs[ (unsigned char) *text_ptr ].TexMaxY; min_x = Glyphs[ (unsigned char) *text_ptr ].MinX; left = x + min_x; right = x + Glyphs[ (unsigned char) *text_ptr ].Pic->w + min_x; top = y; bottom = y + Glyphs[ (unsigned char) *text_ptr ].Pic->h; glBindTexture( GL_TEXTURE_2D, Glyphs[ (unsigned char) *text_ptr ].Tex ); glBegin( GL_QUADS ); glTexCoord2f( tex_min_x, tex_min_y ); glVertex2f( left, top ); glTexCoord2f( tex_max_x, tex_min_y ); glVertex2f( right, top ); glTexCoord2f( tex_max_x, tex_max_y ); glVertex2f( right, bottom ); glTexCoord2f( tex_min_x, tex_max_y ); glVertex2f( left, bottom ); glEnd(); x += Glyphs[ (unsigned char) *text_ptr ].Advance; } text_ptr ++; } glPopAttrib(); }
void fitEfficiency(float thres, float mLow=45, float mHigh=70, TString cutdef="pt_HLT>=20", TString cut_choice="HLT", TString dirIn="/data_CMS/cms/ndaci/ndaci_2012/HTauTau/TriggerStudy/SingleMu/MuMu/Run2012A_PRV1/Pairs/", TString dirResults="/home//llr/cms/ndaci/SKWork/macro/HTauTau/results/TriggerStudies/MuMu/Run2012A_PRV1/", TString lumi="200 pb", int nCPU=4, int color1=kBlack, int style1=kFullCircle, int color2=kRed, int style2=kOpenSquare, TString fileIn="*.root", TString image="eff_HLT_MuTau") { // STYLE // gROOT->Reset(); loadPresentationStyle(); gROOT->ForceStyle(); // OUTPUT // TString name_image = dirResults+"/"+image; ofstream fichier(name_image+".txt", ios::out); // BINNING // const int nbinsEB = 14; Double_t binsEB[nbinsEB] = {10., 14., 18., 20., 22., 26., 30., 40., 50., 60., 70., 80, 90, 100}; RooBinning binningEB = RooBinning(nbinsEB-1, binsEB, "binningEB"); const int nbinsEE = 14; Double_t binsEE[nbinsEE] = {10., 14., 18., 20., 22., 26., 30., 40., 50., 60., 70., 80, 90, 100}; RooBinning binningEE = RooBinning(nbinsEE-1, binsEE, "binningEE"); // EB/EE eta cuts // TString etacutEB="eta>-1.479 && eta<1.479", etacutEE="eta<=-1.479 || eta>=1.479"; TString cutdefEB, cutdefEE; if(cutdef=="") { cutdefEB=etacutEB; cutdefEE=etacutEE; } else { cutdefEB=cutdef+" && "+etacutEB ; cutdefEB=cutdef+" && "+etacutEE ; } // INPUT DATA // TChain* treeTnP = new TChain("treeTnP"); treeTnP->Add(dirIn+"/"+fileIn); RooRealVar xaxis("pt","P_{T} [GeV]",0,150) ; RooRealVar mass("mass","mass",mLow,mHigh) ;// consider only this mass range when importing data RooRealVar eta("eta","eta",-3., 3) ; RooRealVar weight("weight","weight",-1,1000) ; RooRealVar pt_HLT_tag("pt_HLT_tag","P_{T} [GeV]",0,150) ; RooRealVar pt_HLT_tag_sanity("pt_HLT_tag_sanity","P_{T} [GeV]",0,150) ; RooRealVar pt_L3("pt_L3","P_{T} [GeV]",0,150) ; RooRealVar pt_L25("pt_L25","P_{T} [GeV]",0,150) ; RooRealVar pt_L2("pt_L2","P_{T} [GeV]",0,150) ; RooRealVar et_L1jet("et_L1_jet","P_{T} [GeV]",0,150) ; RooRealVar et_L1tau("et_L1_tau","P_{T} [GeV]",0,150) ; // DEFINE EFFICIENCY CUT // RooCategory cutHLT("match","") ; cutHLT.defineType("accept",1) ; cutHLT.defineType("reject",0) ; RooCategory cutL1("L1match","") ; cutL1.defineType("accept",1) ; cutL1.defineType("reject",0) ; RooCategory cutL1L2("L1L2match","") ; cutL1L2.defineType("accept",1) ; cutL1L2.defineType("reject",0) ; RooCategory cutL1L2L25("L1L2L25match","") ; cutL1L2L25.defineType("accept",1) ; cutL1L2L25.defineType("reject",0) ; RooCategory cutL1L2L25L3("L1L2L25L3match","") ; cutL1L2L25L3.defineType("accept",1) ; cutL1L2L25L3.defineType("reject",0) ; RooCategory *cut; if(cut_choice=="HLT") cut = &cutHLT; if(cut_choice=="L1") cut = &cutL1; if(cut_choice=="L1L2") cut = &cutL1L2; if(cut_choice=="L1L2L25") cut = &cutL1L2L25; if(cut_choice=="L1L2L25L3") cut = &cutL1L2L25L3; RooDataSet dataSetEB("data","data from tree", RooArgSet(xaxis, *cut, pt_HLT_tag, pt_L3, pt_L25, pt_L2, mass, weight, eta), WeightVar(weight), Import(*treeTnP), Cut(cutdefEB) ); RooDataSet dataSetEE("data","data from tree", RooArgSet(xaxis, *cut, pt_HLT_tag, pt_L3, pt_L25, pt_L2, mass, weight, eta), WeightVar(weight), Import(*treeTnP), Cut(cutdefEE) ); dataSetEB.Print(); dataSetEE.Print(); // PLOT // RooPlot* frame = xaxis.frame(Bins(18000),Title("Fitted efficiency")) ; dataSetEB.plotOn(frame, Binning(binningEB), Efficiency(*cut), MarkerColor(color1), LineColor(color1), MarkerStyle(style1) ); dataSetEE.plotOn(frame, Binning(binningEE), Efficiency(*cut), MarkerColor(color2), LineColor(color2), MarkerStyle(style2) ); // PARAMETRES ROOFIT CRYSTAL BALL // RooRealVar norm("norm","N",0.95,0.6,1); RooRealVar alpha("alpha","#alpha",0.2,0.01,8); RooRealVar n("n","n",2,1.1,35); RooRealVar mean("mean","mean",10,5,30); mean.setVal(thres); RooRealVar sigma("sigma","#sigma",0.23,0.01,5); RooRealVar pedestal("pedestal","pedestal",0.01,0,0.4); FuncCB cb_EB("cb_EB","Fit function EB (cb)",xaxis,mean,sigma,alpha,n,norm) ; FuncCB cb_EE("cb_EE","Fit function EE (cb)",xaxis,mean,sigma,alpha,n,norm) ; RooEfficiency eff_EB("eff_EB","efficiency EB", cb_EB, *cut, "accept"); RooEfficiency eff_EE("eff_EE","efficiency EE", cb_EE, *cut, "accept"); // FIT // double fit_cuts_min = thres-1.5 ; double fit_cuts_max = 150; xaxis.setRange("interesting",fit_cuts_min,fit_cuts_max); fichier << "Fit characteristics :" << endl << "Threshold : " << thres << endl << "Fit Range : [" << fit_cuts_min << "," << fit_cuts_max << "]" << endl << endl << endl; RooFitResult* roofitres_EB = new RooFitResult("roofitres_EB","roofitres_EB"); RooFitResult* roofitres_EE = new RooFitResult("roofitres_EE","roofitres_EE"); // Fit #1 // roofitres_EB = eff_EB.fitTo(dataSetEB,ConditionalObservables(xaxis),Range("interesting"),Minos(kTRUE),Warnings(kFALSE),NumCPU(nCPU),Save(kTRUE),SumW2Error(kTRUE)); cb_EB.plotOn(frame,LineColor(color1),LineWidth(2)); fichier << "<----------------- EB ----------------->" << endl << "double res_mean=" << mean.getVal() << "; " << "double res_sigma=" << sigma.getVal() << "; " << "double res_alpha=" << alpha.getVal() << "; " << "double res_n=" << n.getVal() << "; " << "double res_norm=" << norm.getVal() << "; " << endl << "double err_mean=" << mean.getError() << "; " << "double err_sigma=" << sigma.getError() << "; " << "double err_alpha=" << alpha.getError() << "; " << "double err_n=" << n.getError() << "; " << "double err_norm=" << norm.getErrorLo()<< "; " << endl; // Fit #2 // roofitres_EE = eff_EE.fitTo(dataSetEE,ConditionalObservables(xaxis),Range("interesting"),Minos(kTRUE),Warnings(kFALSE),NumCPU(nCPU),Save(kTRUE),SumW2Error(kTRUE)); cb_EE.plotOn(frame,LineColor(color2),LineWidth(2)); fichier << "<----------------- EE ----------------->" << endl << "double res_mean=" << mean.getVal() << "; " << "double res_sigma=" << sigma.getVal() << "; " << "double res_alpha=" << alpha.getVal() << "; " << "double res_n=" << n.getVal() << "; " << "double res_norm=" << norm.getVal() << "; " << endl << "double err_mean=" << mean.getError() << "; " << "double err_sigma=" << sigma.getError() << "; " << "double err_alpha=" << alpha.getError() << "; " << "double err_n=" << n.getError() << "; " << "double err_norm=" << norm.getErrorLo()<< "; " << endl; //////////////////////////// DRAWING PLOTS AND LEGENDS ///////////////////////////////// TCanvas* ca = new TCanvas("ca","Trigger Efficiency") ; ca->SetGridx(); ca->SetGridy(); ca->cd(); //gPad->SetLogx(); gPad->SetObjectStat(1); frame->GetYaxis()->SetRangeUser(0,1.05); frame->GetXaxis()->SetRangeUser(1,150.); frame->GetYaxis()->SetTitle("Efficiency"); frame->GetXaxis()->SetTitle("E_{T} [GeV]"); frame->Draw() ; TH1F *SCeta_EB = new TH1F("SCeta_EB","SCeta_EB",50,-2.5,2.5); TH1F *SCeta_EE = new TH1F("SCeta_EE","SCeta_EE",50,-2.5,2.5); SCeta_EB->SetLineColor(color1) ; SCeta_EB->SetMarkerColor(color1); SCeta_EB->SetMarkerStyle(style1); SCeta_EE->SetLineColor(color2) ; SCeta_EE->SetMarkerColor(color2); SCeta_EE->SetMarkerStyle(style2); TLegend *leg = new TLegend(0.40, 0.14, 0.63, 0.34, NULL, "brNDC"); leg->SetLineColor(1); leg->SetTextColor(1); leg->SetTextFont(42); leg->SetTextSize(0.0244755); leg->SetShadowColor(kWhite); leg->SetFillColor(kWhite); leg->AddEntry("NULL","e #tau electrons efficiency","h"); // entry->SetLineColor(1); // entry->SetLineStyle(1); // entry->SetLineWidth(1); // entry->SetMarkerColor(1); // entry->SetMarkerStyle(21); // entry->SetMarkerSize(1); // entry->SetTextFont(62); leg->AddEntry(SCeta_EB,"Barrel","p"); leg->AddEntry(SCeta_EE,"Endcaps","p"); leg->Draw(); ostringstream ossi(""); ossi << thres; TString tossi = ossi.str(); leg = new TLegend(0.40, 0.30, 0.50, 0.50, NULL, "brNDC"); leg->SetBorderSize(0); leg->SetTextFont(62); leg->SetTextSize(0.0297203); leg->SetLineColor(0); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(0); leg->AddEntry("NULL","CMS Preliminary 2012 pp #sqrt{s}=8 TeV","h"); leg->AddEntry("NULL","#int L dt = "+lumi+"^{-1}","h"); leg->AddEntry("NULL","Threshold : "+tossi+" GeV","h"); leg->Draw(); ca->Print(name_image+".C","C"); ca->Print(name_image+".cxx","cxx"); ca->Print(name_image+".png","png"); ca->Print(name_image+".gif","gif"); ca->Print(name_image+".pdf","pdf"); ca->Print(name_image+".ps","ps"); ///////////////////////////// // SAVE THE ROO FIT RESULT // ///////////////////////////// RooWorkspace *w = new RooWorkspace("workspace","workspace") ; w->import(dataSetEB); w->import(dataSetEE); w->import(*roofitres_EB,"roofitres_EB"); w->import(*roofitres_EE,"roofitres_EE"); cout << "CREATES WORKSPACE : " << endl; w->Print(); w->writeToFile(name_image+"_fitres.root") ; //gDirectory->Add(w) ; // DELETE POINTERS // int a=0; // cin >> a; // delete treeTnP; delete cut; delete frame; delete roofitres_EB; delete roofitres_EE; delete ca; delete SCeta_EB; delete SCeta_EE; delete leg; delete w; }