void shTest(){ Double_t par[] = {0.3164, 3., 1.5}; // guesses Double_t points(24); TF1 * sT = new TF1("sT","0.3164*pow(x,4)*exp(-x*1.5)",0., points); sT->Draw(); Double_t shapeInt = sT->Integral(0., points); Double_t shapeMax = sT->GetMaximum(0.,points); Double_t shapePeak= sT->GetMaximumX(0.,points); Double_t shapeRMS = sqrt(sT->Moment(2,0.,points)-sT->Moment(1,0.,points)*sT->Moment(1,0.,points)); cout<<"SHAPE Peak = "<<shapePeak<<" Max = "<<shapeMax<<" RMS = "<<shapeRMS<<" Integral = "<<shapeInt<<endl; // return par[0]*pow(x1,4.)*(exp(-x1*16./fN)); // fN is set to (float)NSAMPLES }
void GetFWHM(TF1* floo, double& mean, double& fwhm) { TF1* fgt = (TF1*) gROOT->FindObject("fgt"); if (fgt != 0) delete fgt; fgt = new TF1("fgt", gaustail, 0, 6000, 5); for (int i=0;i<5;i++) fgt->SetParameter(i,floo->GetParameter(i)); double mean = fgt->GetMaximumX(); double max = fgt->GetMaximum(); double left = fgt->GetX(max/2.,0,mean); double right = fgt->GetX(max/2.,mean,6000); fwhm = right - left; cout << "Found " << mean << " " << fwhm << endl; }
void produceTF() { gROOT->SetBatch(); setTDRStyle(); TChain ch("trGEN"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hut-MadGraph5-pythia8/data.root"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hct-MadGraph5-pythia8/data.root"); float dMetPx, dMetPy; float dTopLepBJetPx, dTopLepBJetPy, dTopLepBJetPz, dTopLepBJetE; float dHiggsBJet1Px, dHiggsBJet1Py, dHiggsBJet1Pz, dHiggsBJet1E; float dHiggsBJet2Px, dHiggsBJet2Py, dHiggsBJet2Pz, dHiggsBJet2E; float dElecPx, dElecPy, dElecPz, dElecE; float dMuonPx, dMuonPy, dMuonPz, dMuonE; float TopLepWM, TopLepRecM, TopHadRecM, HiggsRecM; ch.SetBranchAddress("dMetPx",&dMetPx); ch.SetBranchAddress("dMetPy",&dMetPy); ch.SetBranchAddress("dTopLepBJetPx",&dTopLepBJetPx); ch.SetBranchAddress("dTopLepBJetPy",&dTopLepBJetPy); ch.SetBranchAddress("dTopLepBJetPz",&dTopLepBJetPz); ch.SetBranchAddress("dTopLepBJetE",&dTopLepBJetE); ch.SetBranchAddress("dHiggsBJet1Px",&dHiggsBJet1Px); ch.SetBranchAddress("dHiggsBJet1Py",&dHiggsBJet1Py); ch.SetBranchAddress("dHiggsBJet1Pz",&dHiggsBJet1Pz); ch.SetBranchAddress("dHiggsBJet1E",&dHiggsBJet1E); ch.SetBranchAddress("dHiggsBJet2Px",&dHiggsBJet2Px); ch.SetBranchAddress("dHiggsBJet2Py",&dHiggsBJet2Py); ch.SetBranchAddress("dHiggsBJet2Pz",&dHiggsBJet2Pz); ch.SetBranchAddress("dHiggsBJet2E",&dHiggsBJet2E); ch.SetBranchAddress("dElecPx",&dElecPx); ch.SetBranchAddress("dElecPy",&dElecPy); ch.SetBranchAddress("dElecPz",&dElecPz); ch.SetBranchAddress("dElecE",&dElecE); ch.SetBranchAddress("dMuonPx",&dMuonPx); ch.SetBranchAddress("dMuonPy",&dMuonPy); ch.SetBranchAddress("dMuonPz",&dMuonPz); ch.SetBranchAddress("dMuonE",&dMuonE); ch.SetBranchAddress("TopLepWM",&TopLepWM); ch.SetBranchAddress("TopLepRecM",&TopLepRecM); ch.SetBranchAddress("HiggsRecM",&HiggsRecM); int nHist = 0; TH1D *h[1000]; std::string hName[1000]; std::string hLab[1000]; TFile *fOut = new TFile("pdf.root","RECREATE"); h[nHist] = new TH1D("h_TopLepRecM","h_TopLepRecM",100,80.,260.); h[nHist]->Sumw2(); hName[nHist] = "TopLepRecM"; hLab[nHist] = "m(t) [GeV]"; nHist++; h[nHist] = new TH1D("h_TopLepWM","h_TopLepWM",100,60.,100.); h[nHist]->Sumw2(); hName[nHist] = "TopLepWM"; hLab[nHist] = "m(W) [GeV]"; nHist++; h[nHist] = new TH1D("h_HiggsRecM","h_HiggsRecM",100,20.,220.); h[nHist]->Sumw2(); hName[nHist] = "HiggsRecM"; hLab[nHist] = "m(H) [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPx","h_dMetPx",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPx"; hLab[nHist] = "MetPx_{gen} - MetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPy","h_dMetPy",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPy"; hLab[nHist] = "MetPy_{gen} - MetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPx","h_dBJetPx",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPx"; hLab[nHist] = "BJetPx_{gen} - BJetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPy","h_dBJetPy",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPy"; hLab[nHist] = "BJetPy_{gen} - BJetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPz","h_dBJetPz",100,-80.,80.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPz"; hLab[nHist] = "BJetPz_{gen} - BJetPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetE","h_dBJetE",100,-300.,120.); h[nHist]->Sumw2(); hName[nHist] = "dBJetE"; hLab[nHist] = "BJetE_{gen} - BJetE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPx","h_dElecPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPx"; hLab[nHist] = "ElecPx_{gen} - ElecPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPy","h_dElecPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPy"; hLab[nHist] = "ElecPy_{gen} - ElecPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPz","h_dElecPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecPz"; hLab[nHist] = "ElecPz_{gen} - ElecPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecE","h_dElecE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecE"; hLab[nHist] = "ElecE_{gen} - ElecE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPx","h_dMuonPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPx"; hLab[nHist] = "MuonPx_{gen} - MuonPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPy","h_dMuonPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPy"; hLab[nHist] = "MuonPy_{gen} - MuonPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPz","h_dMuonPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPz"; hLab[nHist] = "MuonPz_{gen} - MuonPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonE","h_dMuonE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonE"; hLab[nHist] = "MuonE_{gen} - MuonE_{reco} [GeV]"; nHist++; int nev = ch.GetEntries(); TRandom3 *rnd = new TRandom3(); for(int i=0;i<nev;i++) { ch.GetEntry(i); for(int ih=0;ih<nHist;ih++) { if( hName[ih] == "TopLepRecM" ) h[ih]->Fill(TopLepRecM); else if( hName[ih] == "TopLepWM" ) h[ih]->Fill(TopLepWM); else if( hName[ih] == "HiggsRecM" ) h[ih]->Fill(HiggsRecM); else if( hName[ih] == "dMetPx" ) h[ih]->Fill(dMetPx); else if( hName[ih] == "dMetPy" ) h[ih]->Fill(dMetPy); else if( hName[ih] == "dBJetPx" ) {h[ih]->Fill(dHiggsBJet1Px);h[ih]->Fill(dHiggsBJet2Px);h[ih]->Fill(dTopLepBJetPx);} else if( hName[ih] == "dBJetPy" ) {h[ih]->Fill(dHiggsBJet1Py);h[ih]->Fill(dHiggsBJet2Py);h[ih]->Fill(dTopLepBJetPy);} else if( hName[ih] == "dBJetPz" ) {h[ih]->Fill(dHiggsBJet1Pz);h[ih]->Fill(dHiggsBJet2Pz);h[ih]->Fill(dTopLepBJetPz);} else if( hName[ih] == "dBJetE" ) {h[ih]->Fill(dHiggsBJet1E);h[ih]->Fill(dHiggsBJet2E);h[ih]->Fill(dTopLepBJetE);} else if( hName[ih] == "dElecPx" ) {h[ih]->Fill(dElecPx);} else if( hName[ih] == "dElecPy" ) {h[ih]->Fill(dElecPy);} else if( hName[ih] == "dElecPz" ) {h[ih]->Fill(dElecPz);} else if( hName[ih] == "dElecE" ) {h[ih]->Fill(dElecE);} else if( hName[ih] == "dMuonPx" ) {h[ih]->Fill(dMuonPx);} else if( hName[ih] == "dMuonPy" ) {h[ih]->Fill(dMuonPy);} else if( hName[ih] == "dMuonPz" ) {h[ih]->Fill(dMuonPz);} else if( hName[ih] == "dMuonE" ) {h[ih]->Fill(dMuonE);} } } delete rnd; // Plots TCanvas *c1 = new TCanvas(); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); for(int i=0;i<nHist;i++) { // addbin(h[i]); h[i]->Scale(1./h[i]->Integral()); h[i]->Scale(1./h[i]->GetMaximum()); h[i]->SetLineWidth(2); h[i]->SetLineColor(kRed); h[i]->SetMarkerColor(kRed); h[i]->SetMarkerStyle(20); h[i]->Draw("hist e1"); h[i]->GetXaxis()->SetTitle(hLab[i].c_str()); // h[i]->GetYaxis()->SetTitle("Normalized to unity"); float max = h[i]->GetMaximum(); h[i]->SetMaximum(1.2*max); if( hName[i] == "TopLepWM" || hName[i] == "TopLepM" ) { std::string funcName = hName[i]+"_Fit"; TF1 *func = new TF1(funcName.c_str(),BW,h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins()),3); double mean = 80.4; if( hName[i] == "TopLepM" ) mean = 173.0; double sigma = 2.0; if( hName[i] == "TopLepM" ) sigma = 2.0; func->SetParameter(0,mean); func->SetParName(0,"mean"); func->SetParameter(1,sigma); func->SetParName(1,"sigma"); func->SetParameter(2,1.0); func->SetParName(2,"constant"); func->FixParameter(2,1.); h[i]->Fit(funcName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->Write(); std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"gaus(0)",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->Write(); } if( hName[i] == "dMetPx" || hName[i] == "dMetPy" ) { double mean = 0.; double sigma = 50.; std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->SetParameter(3,0.5); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dBJetPx" || hName[i] == "dBJetPy" || hName[i] == "dBJetPz" || hName[i] == "dBJetE" ) { double mean = 0.; double sigma = 20.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[12]*(gaus(0)+gaus(3)+gaus(6)+gaus(9))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(12,1.0); funcGaus->SetParameter(0,1.0); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(0,0.6); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(0,0.6); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(3,0.3); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(5,sigma*4); if( hName[i] == "dBJetPy" ) funcGaus->SetParameter(3,0.2); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(8,sigma/3.); funcGaus->SetParameter(9,0.5); funcGaus->SetParameter(10,mean); funcGaus->SetParameter(11,sigma); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); if( hName[i] == "dBJetE" ) { c1->Update(); TPaveStats *st = (TPaveStats*)h[i]->FindObject("stats"); st->SetX1NDC(0.20); st->SetX2NDC(0.47); } fit->Draw("same"); fit->SetParameter(12,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dElecPx" || hName[i] == "dElecPy" || hName[i] == "dElecPz" || hName[i] == "dElecE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dElecE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dMuonPx" || hName[i] == "dMuonPy" || hName[i] == "dMuonPz" || hName[i] == "dMuonE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(3,0.2); if( hName[i] == "dMuonE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "HiggsRecM" || hName[i] == "TopLepRecM" ) { double mean = 125.; double sigma = 10.; if( hName[i] == "TopLepRecM" ) { mean = 170; sigma = 20; } std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] != "TopLepRecM" ) funcGaus->FixParameter(0,0.7); funcGaus->SetParameter(3,0.3); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(3,0.7); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(4,150); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } std::string figName = "pics/"+hName[i]+".eps"; c1->Print(figName.c_str()); c1->Clear(); } fOut->Write(); fOut->Close(); gApplication->Terminate(); }
void SiCalibrator::MatchPeaks() { Load(); char tmpname[255]; sprintf(tmpname,"/SumCalData_th%dd%ds%dt%d.root",thresh,decay,shaping,top); std::string fname = tmpname; std::string filename = mypath; filename.append(fname); TFile *myfile = new TFile(filename.c_str(),"RECREATE"); int nbins; for (int src=0; src < CalData.size(); src++) { if (CalData[src].hSource != 0) { CalData[src].hSource->SetDirectory(myfile); CalData[src].hSource->Write(); for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) { TH1D* hbi = CalData[src].hSource->ProjectionY("hb",ch+1,ch+1); nbins = hbi->GetNbinsX(); CalData[src].sourcedata[ch].fpol1 = 0; if (hbi->Integral(1,nbins) > 0) { sprintf(tmpname,"fs%dch%d",src,ch); TF1* f = new TF1(tmpname,fitf,0,16000,4); CalData[src].sourcedata[ch].fpol1 = f; // Build spectrum fit function f->FixParameter(0,src); f->FixParameter(1,0); //f->SetParLimits(1,-30,30); f->SetParameter(2,0.2); f->SetParameter(3,1); f->SetNpx(1000); double scale = hbi->GetMaximum()/f->GetMaximum(); f->FixParameter(3,scale); f->SetParameter(2,minimize(f,hbi,2,0.1,0.3)); //f->ReleaseParameter(2); //f->ReleaseParameter(1); //hbi->Draw(); //hbi->Fit(f,"LL","",thresh+50,16000); //cout << f->GetChisquare()/f->GetNDF() << endl; //f->FixParameter(1,f->GetParameter(1)); //f->FixParameter(2,f->GetParameter(2)); //f->SetParameter(3,minimize(f,hbi,3,scale*0.1,scale*5)); //f->ReleaseParameter(3); //f->SetParLimits(3,scale*0.1,scale*5); /* double slope = f->GetParameter(2); if (slope < 0.2 || slope > 0.25) { cout << "src " << src; cout << " ch " << ch; cout << " cnts " << hbi->Integral(1,nbins); cout << " pol1" << slope << endl; //hbi->Draw(); //return; } */ //hbi->Fit(f,"LL","",thresh+50,16000); //cout << f->GetChisquare()/f->GetNDF() << endl; //hbi->Fit(f,"","",150,16000); //f->Draw("same"); /* if (src == 1 && ch==13) { hbi->Draw(); f->Draw("same"); return; } */ f->Write(); } } } } for (int src=0; src < CalData.size(); src++) { if (CalData[src].hSource != 0) { sprintf(tmpname,"hp1_%d",src); CalData[src].hp1 = new TH1D(tmpname,tmpname,CalData[src].sourcedata.size(),0,CalData[src].sourcedata.size()); for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) { if (CalData[src].sourcedata[ch].fpol1 != 0) { TF1* f = CalData[src].sourcedata[ch].fpol1; CalData[src].hp1->SetBinContent(ch+1,f->GetParameter(2)); } } CalData[src].hp1->Write(); /* TCanvas* c = new TCanvas(); c->Divide(1,2); c->cd(1); CalData[src].hSource->Draw("COLZ"); c->cd(2); CalData[src].hp1->Draw(); */ } } myfile->Close(); delete myfile; }
void fitTF1(TCanvas *canvas, TH1F h, double XMIN_, double XMAX_, double dX_, double params[], Color_t LC_=kBlack) { //double& FWHM_, double& x0_, double& x1_, double& x2_, double& y0_, double& y1_, double& INT_, double& YIELD_) { //TCanvas* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) { //TF1* fitTF1(TH1F h, double HSCALE_, double XMIN_, double XMAX_) { gROOT->ForceStyle(); RooMsgService::instance().setSilentMode(kTRUE); for(int i=0;i<2;i++) RooMsgService::instance().setStreamStatus(i,kFALSE); //TCanvas *canvas = new TCanvas(TString::Format("canvas_%s",h.GetName()),TString::Format("canvas_%s",h.GetName()),1800,1200); RooDataHist *RooHistFit = 0; RooAddPdf *model = 0; RooWorkspace w = RooWorkspace("w","workspace"); RooRealVar x("mbbReg","mbbReg",XMIN_,XMAX_); RooRealVar kJES("CMS_scale_j","CMS_scale_j",1,0.9,1.1); RooRealVar kJER("CMS_res_j","CMS_res_j",1,0.8,1.2); kJES.setConstant(kTRUE); kJER.setConstant(kTRUE); TString hname = h.GetName(); RooHistFit = new RooDataHist("fit_"+hname,"fit_"+hname,x,&h); RooRealVar YieldVBF = RooRealVar("yield_"+hname,"yield_"+hname,h.Integral()); RooRealVar m("mean_"+hname,"mean_"+hname,125,100,150); RooRealVar s("sigma_"+hname,"sigma_"+hname,12,3,30); RooFormulaVar mShift("mShift_"+hname,"@0*@1",RooArgList(m,kJES)); RooFormulaVar sShift("sShift_"+hname,"@0*@1",RooArgList(m,kJER)); RooRealVar a("alpha_"+hname,"alpha_"+hname,1,-10,10); RooRealVar n("exp_"+hname,"exp_"+hname,1,0,100); RooRealVar b0("b0_"+hname,"b0_"+hname,0.5,0.,1.); RooRealVar b1("b1_"+hname,"b1_"+hname,0.5,0.,1.); RooRealVar b2("b2_"+hname,"b2_"+hname,0.5,0.,1.); RooRealVar b3("b3_"+hname,"b3_"+hname,0.5,0.,1.); RooBernstein bkg("signal_bkg_"+hname,"signal_bkg_"+hname,x,RooArgSet(b0,b1,b2)); RooRealVar fsig("fsig_"+hname,"fsig_"+hname,0.7,0.0,1.0); RooCBShape sig("signal_gauss_"+hname,"signal_gauss_"+hname,x,mShift,sShift,a,n); model = new RooAddPdf("signal_model_"+hname,"signal_model_"+hname,RooArgList(sig,bkg),fsig); //RooFitResult *res = model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); model->fitTo(*RooHistFit,RooFit::Save(),RooFit::SumW2Error(kFALSE),"q"); //res->Print(); //model->Print(); canvas->cd(); canvas->SetTopMargin(0.1); RooPlot *frame = x.frame(); // no scale RooHistFit->plotOn(frame); model->plotOn(frame,RooFit::LineColor(LC_),RooFit::LineWidth(2));//,RooFit::LineStyle(kDotted)); model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(LC_),RooFit::LineWidth(2),RooFit::LineStyle(kDashed)); // with scale // RooHistFit->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent)); // model->plotOn(frame,RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent),RooFit::LineWidth(1)); // model->plotOn(frame,RooFit::Components(bkg),RooFit::LineColor(kBlue),RooFit::LineWidth(1),RooFit::LineStyle(kDashed),RooFit::Normalization(HSCALE_,RooAbsReal::NumEvent)); frame->GetXaxis()->SetLimits(50,200); frame->GetXaxis()->SetNdivisions(505); frame->GetXaxis()->SetTitle("M_{b#bar{b}} (GeV)"); frame->GetYaxis()->SetTitle("Events"); frame->Draw(); h.SetFillColor(kGray); h.Draw("hist,same"); frame->Draw("same"); gPad->RedrawAxis(); TF1 *tmp = model->asTF(x,fsig,x); //tmp->Print(); double y0_ = tmp->GetMaximum(); double x0_ = tmp->GetMaximumX(); double x1_ = tmp->GetX(y0_/2.,XMIN_,x0_); double x2_ = tmp->GetX(y0_/2.,x0_,XMAX_); double FWHM_ = x2_-x1_; double INT_ = tmp->Integral(XMIN_,XMAX_); double YIELD_= YieldVBF.getVal(); double y1_ = dX_*0.5*y0_*(YieldVBF.getVal()/tmp->Integral(XMIN_,XMAX_)); params[0] = x0_; params[1] = x1_; params[2] = x2_; params[3] = y0_; params[4] = y1_; params[5] = FWHM_; params[6] = INT_; params[7] = YIELD_; //cout<<"Int = "<<tmp->Integral(XMIN_,XMAX_)<<", Yield = "<<YieldVBF.getVal()<<", y0 = "<<y0_<<", y1 = "<<y1_ <<", x0 = "<< x0_ << ", x1 = "<<x1_<<", x2 = "<<x2_<<", FWHM = "<<FWHM_<<endl; TLine ln = TLine(x1_,y1_,x2_,y1_); ln.SetLineColor(kMagenta+3); ln.SetLineStyle(7); ln.SetLineWidth(2); ln.Draw(); canvas->Update(); canvas->SaveAs("testC.png"); // tmp->Delete(); // frame->Delete(); // res->Delete(); // TF1 *f1 = model->asTF(x,fsig,x); // return f1; ////tmp->Delete(); ////ln->Delete(); ////model->Delete(); ////RooHistFit->Delete(); ////w->Delete(); ////YieldVBF->Delete(); ////frame->Delete(); ////res->Delete(); //delete tmp; //delete ln; //delete model; //delete RooHistFit; //delete w; //delete YieldVBF; //delete frame; //delete res; // return canvas; }