void long_Ay_nu_01() { gROOT->SetStyle("HALLA"); TCanvas *cn = new TCanvas("cn","cn",540,360); cn->Draw(); cn->UseCurrentStyle(); TH1F *frm = new TH1F("frm","",100,0.,10.); frm->GetXaxis()->SetTitle("#nu (GeV)"); frm->GetYaxis()->SetTitle("Ay for Q2=0.13 (GeV/c)2"); frm->SetMinimum(-0.5); // frm->SetMinimum(0); // frm->SetMaximum(1.0); frm->SetMaximum(1.5); frm->UseCurrentStyle(); frm->Draw(); frm->SetAxisRange(0,0.120,"X"); // frm->SetAxisRange(0.5,1.1,"X"); // TF1* galster = new TF1("galster","x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))",0.,4.); // galster->SetLineColor(6); // galster->SetLineStyle(3); // galster->SetLineWidth(2); TF1 *genf = new TF1("genf",genff,1.,10.,1); genf->SetLineColor(2); genf->SetLineStyle(2); genf->SetParameter(0,1.); // match to Madey point just below 1.5 // genf->SetParameter(0,.0411/genf->Eval(1.45)); genf->SetParameter(0,-0.558645); // TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0); // bbba05->SetLineColor(7); // bbba05->SetLineStyle(3); TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}"); TLegend *legDta = new TLegend(.54,.6,.875,.90,"","brNDC"); TMultiGraph* wgr = mgrDta; TLegend *wlg = legDta; // the data legDta->SetBorderSize(0); // turn off border legDta->SetFillStyle(0); datafile_t *f = datafiles; TGraph* gr=0; while ( f && f->filename ) { gr=OneGraph(f); if (gr) { if (f->lnpt) { mgrDta->Add(gr,f->lnpt); legDta->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { mgrDta->Add(gr,"p"); legDta->AddEntry(gr,f->label,"p"); } else { mgrDta->Add(gr,"l"); legDta->AddEntry(gr,f->label,"l"); } } f++; } mgrDta->Draw("p"); // legDta->Draw(); TF1 *theFit = new TF1("theFit","pol0"); gr->Fit(theFit); theFit->Draw("same"); TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}"); TLegend *legThry = new TLegend(.54,.3,.875,.6,"","brNDC"); wgr = mgrThry; wlg = legThry; // the theory wlg->SetBorderSize(0); // turn off border wlg->SetFillStyle(0); f = theoryfiles1; gr=0; while ( f && f->filename ) { gr=OneGraph(f); if (gr) { TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) { gr = toerror_band(egr); gr->SetFillStyle(3000+f->style); } if (f->lnpt) { wgr->Add(gr,f->lnpt); wlg->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { wgr->Add(gr,"p"); wlg->AddEntry(gr,f->label,"p"); } else { wgr->Add(gr,"l"); wlg->AddEntry(gr,f->label,"l"); } } f++; } // genf->Draw("same"); mgrThry->Draw("c"); // galster->Draw("same"); // bbba05->Draw("same"); // legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l"); // legThry->AddEntry(galster,"Galster fit","l"); // legThry->AddEntry(bbba05,"BBBA05","l"); // legThry->Draw(); // legDta->Draw(); // draw a line at 1 cn->Modified(); cn->Update(); cn->SaveAs(Form("%s.eps",psfile)); cn->SaveAs(Form("%s.root",psfile)); gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile)); return; // LEAVING HERE // now an overlay, hopefully matching dimensions // remove everything but the graph cn->Update(); TList *clist = cn->GetListOfPrimitives(); TFrame* frame = cn->GetFrame(); for (int i=0; i<clist->GetSize(); ) { if (clist->At(i) != frame) { clist->RemoveAt(i); } else i++; } // draw markers in the corners TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX1(),frame->GetY2(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY2(),2); mkr->Draw(); frame->SetLineColor(10); cn->Update(); datafile_t miller = { "figure_input/Miller/lattice.GEn.rtf","Miller", "[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" }; gr = OneGraph(&miller); TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+miller.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("gen_Miller_Overlay.eps"); cn->SaveAs("gen_Miller_Overlay.root"); }
void pulserCal_Si() { int channel[14][32][25]={-1}; int itel,istp,ipeaks =-1; float ichan =0.; float voltage_full[22] ={0.}; float voltage_fine[42] ={0.}; int Peaks[14][32] = {-1}; ifstream file("Si_Back_Pulser_Full.dat"); for(int itele =0; itele<14;itele++) { for(int istrip = 0;istrip<32;istrip++) { file >> itel >> istp >> ipeaks; Peaks[itele]=ipeaks; if(itele != itel || istp != istrip) { cout << "Didn't read the file right" << endl; return; } for(int peak =0;peak<ipeaks;peak++) { file >> ichan; if(peak ==0)ped[itele] = ichan; else channel[itele][peak-1] =ichan-ped[itele]; } Peaks[itele] = ipeaks-1; } } for (int ii=1;ii<42;ii++) { voltage[ii-1]= (4./41.)*ii; // cout << voltage[ii] << endl; } gROOT->cd(); TCanvas *mycan1 = (TCanvas*)gROOT->FindObject("mycan1"); if(!mycan1) { mycan1 = new TCanvas("mycan1","mycan1"); mycan1->Divide(5,4); } TCanvas *mycan2 = (TCanvas*)gROOT->FindObject("mycan2"); if(!mycan2) { mycan2 = new TCanvas("mycan2","mycan2"); mycan2->Divide(5,4); } TCanvas *mycan3 = (TCanvas*)gROOT->FindObject("mycan3"); if(!mycan3) { mycan3 = new TCanvas("mycan3","mycan3"); mycan3->Divide(5,4); } for(int itele =0;itele<56;itele++) { if(itele<20) { mycan1->cd(itele+1); TGraph *mygraph = new TGraph(Peaks[itele],channel[itele],voltage); mygraph->SetName(Form("CsI_%i",itele)); mygraph->Draw("AP"); mygraph->SetMarkerStyle(20); TF1 *myfit = new TF1("myfit","pol1",0,500); myfit->SetLineColor(kRed); mygraph->Fit(myfit); } else if(itele>=20 && itele<40) { mycan2->cd(itele+1-20); TGraph *mygraph = new TGraph(Peaks[itele],channel[itele],voltage); mygraph->SetName(Form("CsI_%i",itele)); mygraph->Draw("AP"); mygraph->SetMarkerStyle(20); TF1 *myfit = new TF1("myfit","pol1",0,500); myfit->SetLineColor(kRed); mygraph->Fit(myfit); } else { mycan3->cd(itele+1-40); TGraph *mygraph = new TGraph(Peaks[itele],channel[itele],voltage); mygraph->SetName(Form("CsI_%i",itele)); mygraph->Draw("AP"); mygraph->SetMarkerStyle(20); TF1 *myfit = new TF1("myfit","pol1",0,500); myfit->SetLineColor(kRed); mygraph->Fit(myfit); } } return; }
int main(int argc, char** argv) { gROOT->SetStyle("Plain"); gStyle->SetPalette(1); // load ntuple TChain *chain = new TChain ("myanalysis/EcalAnalysisTree","EcalAnalysisTree") ; chain->Add("/tmp/malberti/EcalTree_EG_Run2010A-WZEG-Nov4Skim_v1_RAW-RECO.root"); chain->Add("/tmp/malberti/EcalTree_Electron_Run2010B-WZEG-Nov4Skim_v1_RAW-RECO.root"); int nEntries = (int)chain->GetEntries() ; cout << "FOUND " << nEntries << " ENTRIES\n" << endl;; //ecalVariables variables unsigned int runId; unsigned int eventId; unsigned int eventNaiveId; int nEcalRecHits; float ecalRecHitType[3300]; float ecalRecHitEnergy[3300]; float ecalRecHitIEta[3300]; float ecalRecHitIPhi[3300]; float ecalRecHitTime[3300]; float ecalRecHitChi2[3300]; int ecalRecHitRecoFlag[3300]; float ecalRecHitMatrixFlag[3300][5][5]; float ecalRecHitMatrix[3300][5][5]; float ecalRecHitS4oS1[3300]; int ecalDigis[3300][10]; int ecalGainId[3300][10]; // Set branch addresses. chain -> SetBranchAddress("runId", &runId); chain -> SetBranchAddress("eventId", &eventId); chain -> SetBranchAddress("eventNaiveId", &eventNaiveId); chain -> SetBranchAddress("nEcalRecHits", &nEcalRecHits); chain -> SetBranchAddress("ecalRecHitType", ecalRecHitType); chain -> SetBranchAddress("ecalRecHitEnergy", ecalRecHitEnergy); chain -> SetBranchAddress("ecalRecHitIEta", ecalRecHitIEta); chain -> SetBranchAddress("ecalRecHitIPhi", ecalRecHitIPhi); chain -> SetBranchAddress("ecalRecHitTime", ecalRecHitTime); chain -> SetBranchAddress("ecalRecHitChi2", ecalRecHitChi2); chain -> SetBranchAddress("ecalRecHitRecoFlag", ecalRecHitRecoFlag); chain -> SetBranchAddress("ecalRecHitMatrixFlag", ecalRecHitMatrixFlag); chain -> SetBranchAddress("ecalRecHitMatrix", ecalRecHitMatrix); chain -> SetBranchAddress("ecalRecHitS4oS1", ecalRecHitS4oS1); chain -> SetBranchAddress("ecalDigis", ecalDigis); chain -> SetBranchAddress("ecalGainId", ecalGainId); // output file char outfileName[100]; sprintf(outfileName,"HistosSlewRate.root"); cout << "Saving histograms on file " << outfileName <<endl; TFile saving (outfileName,"recreate") ; // histos TH1F *hGainSwitch = new TH1F("hGainSwitch","hGainSwitch",10,-5,5); hGainSwitch->GetXaxis()->SetTitle("Gain(max) - Gain(max-1)"); TH1F *hSlewRate = new TH1F("hSlewRate","hSlewRate", 5000, 0, 5000); hSlewRate ->SetFillStyle(1); hSlewRate ->SetFillColor(kRed); hSlewRate ->GetXaxis()->SetTitle("Slew Rate (ADC/ns)"); TH2F *hAmplitude = new TH2F("hAmplitude","hAmplitude", 1000, 0, 10000, 500, 0, 5000); hAmplitude -> SetMarkerColor(kRed); hAmplitude -> SetMarkerStyle(20); hAmplitude -> SetMarkerSize(0.35); hAmplitude -> GetXaxis() -> SetTitle("Expected Amplitude (ADC)"); hAmplitude -> GetYaxis() -> SetTitle("Observed Amplitude (ADC)"); TH2F *hAmplitude2 = new TH2F("hAmplitude2","hAmplitude2", 1000, 0, 10000, 500, 0, 5000); hAmplitude2 -> SetMarkerColor(kBlue); hAmplitude2 -> SetMarkerStyle(20); hAmplitude2 -> SetMarkerSize(0.35); hAmplitude2 -> GetXaxis() -> SetTitle("Expected Amplitude (ADC)"); hAmplitude2 -> GetYaxis() -> SetTitle("Observed Amplitude (ADC)"); TH2F *hAmpl_vs_Time = new TH2F("hAmpl_vs_Time","hAmpl_vs_Time", 800, -100, 100, 1000, 0, 10000); hAmpl_vs_Time -> SetMarkerColor(kRed); hAmpl_vs_Time -> SetMarkerStyle(20); hAmpl_vs_Time -> SetMarkerSize(0.3); hAmpl_vs_Time -> GetXaxis() -> SetTitle("Time (ns)"); hAmpl_vs_Time -> GetYaxis() -> SetTitle("Expected Amplitude (ADC)"); TH2F *hRatio_vs_Time = new TH2F("hRatio_vs_Time","hRatio_vs_Time", 800, -100, 100, 200, 0, 2); hRatio_vs_Time -> SetMarkerColor(kRed); hRatio_vs_Time -> SetMarkerStyle(20); hRatio_vs_Time -> SetMarkerSize(0.3); hRatio_vs_Time -> GetXaxis() -> SetTitle("Time (ns)"); hRatio_vs_Time -> GetYaxis() -> SetTitle("Ratio"); TH1F *hr1 = new TH1F("hr1","hr1",200,0,2); TH1F *hr2 = new TH1F("hr2","hr2",200,0,2); TH1F *hTfit1 = new TH1F("hTfit1","hTfit1 (expected Amplitude < 3000 ADC)",400,-50,50); hTfit1 -> SetFillStyle(3001); hTfit1 -> SetFillColor(kRed+2); hTfit1 -> GetXaxis() -> SetTitle("T_{fit} (ns)"); TH1F *hTfit2 = new TH1F("hTfit2","hTfit2 (expected Amplitude > 3000 ADC)",400,-50,50); hTfit2 -> SetFillStyle(3001); hTfit2 -> SetFillColor(kBlue+2); hTfit2 -> GetXaxis() -> SetTitle("T_{fit} (ns)"); TH1F *hAmax1 = new TH1F("hAmax1","hTAmax1 (expected Amplitude < 3000 ADC)",1000,0,10000); hAmax1 -> SetFillStyle(3001); hAmax1 -> SetFillColor(kRed+2); hAmax1 -> GetXaxis() -> SetTitle("A_{max} (ADC counts)"); TH1F *hAmax2 = new TH1F("hAmax2","hTAmax2 (expected Amplitude > 3000 ADC)",1000,0,10000); hAmax2 -> SetFillStyle(3001); hAmax2 -> SetFillColor(kBlue+2); hAmax2 -> GetXaxis() -> SetTitle("A_{max} (ADC counts)"); TGraphErrors* gsample; char gname[100]; char gtitle[100]; int ievt=0; float A[3300][10]; float G[3] = {1.,2.,12.}; // gain ratios //loop over the events for (int entry = 0 ; entry < nEntries; ++entry) { chain -> GetEntry(entry) ; if (entry%10000==0) cout << " Analyzing entry " << entry << endl; for (int ihit =0 ; ihit < nEcalRecHits; ihit++) { // barrel only if ( ecalRecHitType[ihit]!=0) continue; float energy = ecalRecHitEnergy[ihit]; float eta = ecalRecHitIEta[ihit]*0.0175; float theta = 2. * atan(exp(-eta)); float et = energy*sin(theta); //if ( energy < 100. ) continue; // E>10 GeV //cerco il sample max float ped = (ecalDigis[ihit][0] + ecalDigis[ihit][1] + ecalDigis[ihit][2])/3; int imax = 0; int maxAmpl = 0; for (int isample = 0; isample < 10 ; isample++) { if (ecalGainId[ihit][isample]!=0) A[ihit][isample] = (ecalDigis[ihit][isample] - ped) * G[ ecalGainId[ihit][isample] - 1]; if ( A[ihit][isample] >= maxAmpl) { imax = isample; maxAmpl = A[ihit][isample] ; } } // end loop over 10 samples // check gain switch bool gainSwitch = false; if (ecalGainId[ihit][imax-1]==1 && ecalGainId[ihit][imax] != ecalGainId[ihit][imax-1]) gainSwitch = true; //Seleziono eventi con gain switch if (!gainSwitch) continue; hGainSwitch -> Fill( ecalGainId[ihit][imax]-ecalGainId[ihit][imax-1]); //cout << "MAX sample = "<< imax << " MAX amplitude = "<< A[ihit][imax] << " MAX gain Id =" << ecalGainId[ihit][imax]<< endl; //cout << "MAX-1 sample = "<< imax-1 << " MAX-1 amplitude = "<< A[ihit][imax-1] << " MAX-1 gain Id =" << ecalGainId[ihit][imax-1] << endl; //cout << endl; float slewRate = A[ihit][imax-1]; hSlewRate -> Fill(slewRate); // graphs gsample = new TGraphErrors(); sprintf(gtitle,"shape_Run%d_Evt%d",runId,eventId); sprintf(gname,"shape_%d",ievt); gsample->SetName(gname); gsample->SetTitle(gtitle); gsample->GetXaxis()->SetTitle("Time (ns)"); gsample->GetYaxis()->SetTitle("ADC counts"); for (int isample = 0; isample < 10 ; isample++) { gsample->SetPoint(isample, double(isample)*25., A[ihit][isample]); gsample->SetPointError(isample,0.,0.9); } // fit function TF1 *fpulseShape = new TF1("fpulseShape", pulseShape,0.,240.,3); fpulseShape->SetLineColor(kBlue); fpulseShape->SetParName(0,"Ped"); fpulseShape->SetParName(1,"A"); fpulseShape->SetParName(2,"T0"); fpulseShape->FixParameter(0,0); // ped fpulseShape->SetParameter(1,A[ihit][imax]); // ampl fpulseShape->SetParameter(2,imax*25.); // T0 gsample->RemovePoint(imax-1); gsample->Fit("fpulseShape","QSR+") ; //re-set dei punti, altrimenti root non li plotta! for (int isample = 0; isample < 10 ; isample++) { gsample->SetPoint(isample, double(isample)*25., A[ihit][isample]); gsample->SetPointError(isample,0.,0.9); } ievt++; float measuredAmpl = A[ihit][imax-1] ; float expectedAmpl = A[ihit][imax] * fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.); hAmplitude -> Fill(expectedAmpl,measuredAmpl); hAmplitude2 -> Fill( A[ihit][imax] * 0.774,measuredAmpl); float t0 = fpulseShape->GetParameter(2); hAmpl_vs_Time -> Fill(t0-125.,expectedAmpl); hRatio_vs_Time -> Fill(t0-125., fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.)); if (expectedAmpl > 3000) { hr2->Fill( fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.)); hTfit2->Fill(t0-125.); hAmax2->Fill(A[ihit][imax]); } else { hr1->Fill( fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.)); hTfit1->Fill(t0-125.); hAmax1->Fill(A[ihit][imax]); } if ( expectedAmpl < 3000 ) //if (ievt<10) gsample->Write(); } // end loop over recHits }//end loop over events chain->Delete(); saving.cd () ; hGainSwitch ->Write(); hSlewRate -> Write(); hAmplitude ->Write(); hAmplitude2 ->Write(); hAmpl_vs_Time ->Write(); hRatio_vs_Time ->Write(); hTfit1->Write(); hTfit2->Write(); hAmax1->Write(); hAmax2->Write(); hr1->Write(); hr2->Write(); saving.Close () ; return 0; }
Resolutions() { float Ebeam[] = {2.0,3.0,4.0,6.0,8.0,12.0}; float Ebeam_err[] = {0.,0.,0.,0.,0.,0.}; float beam_spread[] = {.027,.027,0.023,0.023,0.023,0.023}; //float beam_spread[] = {0.,0.,0.,0.,0.,0.}; float Ebeam_no3[] = {2.0,4.0,6.0,8.0,12.0}; float Ebeam_no3_err[] = {0.,0.,0.,0.,0.}; float beam_no3_spread[] = {.027,.027,0.023,0.023,0.023}; float ECal_mean[] = {270.5, 475.9, 586.8, 921.5, 1323., 3022.}; float ECal_sigma[] = {24.69, 31.54, 35.64, 47.51, 55.71, 133.}; float PbG_mean[] = {775.3, 1320., 1613., 2556., 3546., 1846.}; float PbG_sigma[] = {49.63, 71.96, 81., 125.3, 137., 77.99}; float OldPbG_mean[] = {601.5, 1105, 1622, 2074, 2901}; float OldPbG_sigma[] = {25.07, 38.05, 49.33, 58.2, 77.18}; float OldPbG_mean_err[] = {.8, .6, .8, .7, 1.1}; float OldPbG_sigma_err[] = {.83, .53, .74, .6, .93}; float ECal_res[6], ECal_res_err[6]; float PbG_res[6], PbG_res_err[6]; float OldPbG_res[6], OldPbG_res_err[6]; for (int i=0; i<6; i++) { ECal_res[i] = sqrt(ECal_sigma[i]*ECal_sigma[i]/(ECal_mean[i]*ECal_mean[i]) - beam_spread[i]*beam_spread[i]); PbG_res[i] = sqrt(PbG_sigma[i]*PbG_sigma[i]/(PbG_mean[i]*PbG_mean[i]) - beam_spread[i]*beam_spread[i]); ECal_res_err[i] = 0.; PbG_res_err[i] = 0.; } for (int i=0; i<5; i++) { OldPbG_res[i] = sqrt(OldPbG_sigma[i]*OldPbG_sigma[i]/(OldPbG_mean[i]*OldPbG_mean[i]) - beam_no3_spread[i]*beam_no3_spread[i]); OldPbG_res_err[i] = 0.; } TGraphErrors *gECalRes = new TGraphErrors(6, Ebeam, ECal_res, Ebeam_err, ECal_res_err); TGraphErrors *gPbGRes = new TGraphErrors(6, Ebeam, PbG_res, Ebeam_err, PbG_res_err); TGraphErrors *gOldPbGRes = new TGraphErrors(5, Ebeam_no3, OldPbG_res, Ebeam_no3_err, OldPbG_res_err); TF1 *fResECal = new TF1("fResECal", "[1]/sqrt(x) + [0]", 2, 14); TF1 *fResPbG = new TF1("fResPbG", "[1]/sqrt(x) + [0]", 2, 14); TF1 *fResOldPbG = new TF1("fResOldPbG", "[1]/sqrt(x) + [0]", 2, 14); fResECal->SetLineStyle(2); fResECal->SetLineColor(kGreen+2); fResPbG->SetLineStyle(2); fResPbG->SetLineColor(kRed+1); fResOldPbG->SetLineStyle(2); fResOldPbG->SetLineColor(kMagenta+1); gECalRes->Fit(fResECal, "NR"); gPbGRes->Fit(fResPbG, "NR"); gOldPbGRes->Fit(fResOldPbG, "NR"); gECalRes->SetMarkerStyle(20); gECalRes->SetMarkerSize(2.0); gECalRes->SetMarkerColor(kGreen+2); gECalRes->SetLineColor(kGreen+2); gPbGRes->SetMarkerStyle(21); gPbGRes->SetMarkerSize(2.0); gPbGRes->SetMarkerColor(kRed+1); gPbGRes->SetLineColor(kRed+1); gOldPbGRes->SetMarkerStyle(22); gOldPbGRes->SetMarkerSize(2.0); gOldPbGRes->SetMarkerColor(kMagenta+1); gOldPbGRes->SetLineColor(kMagenta+1); TLegend *lres = new TLegend(.45, .56, .93, .83); lres->AddEntry(fResECal, Form("ECAL: #frac{%.2f %%}{#sqrt{E}} + %.2f", fResECal->GetParameter(1)*100.0, fResECal->GetParameter(0)*100.0), "L"); lres->AddEntry(fResPbG, Form("2015 Lead Glass: #frac{%.2f %%}{#sqrt{E}} + %.2f", fResPbG->GetParameter(1)*100.0, fResPbG->GetParameter(0)*100.0), "L"); lres->AddEntry(fResOldPbG, Form("2014 Lead Glass: #frac{%.2f %%}{#sqrt{E}} + %.2f", fResOldPbG->GetParameter(1)*100.0, fResOldPbG->GetParameter(0)*100.0), "L"); lres->SetFillStyle(0); lres->SetTextSize(.035); lres->SetTextFont(42); TCanvas *cRes = new TCanvas("cRes", "Resolutions", 900, 700); cRes->cd(); gECalRes->Draw("AP"); gECalRes->GetXaxis()->SetTitle("Beam Energy (GeV)"); gECalRes->GetYaxis()->SetTitle("Resolution"); gPbGRes->Draw("Psame"); gOldPbGRes->Draw("Psame"); fResECal->Draw("same"); fResPbG->Draw("same"); fResOldPbG->Draw("same"); gECalRes->GetYaxis()->SetRangeUser(0.0,0.11); lres->Draw("same"); cRes->Update(); }
void CompareCent(){ gStyle->SetOptStat(kFALSE); gStyle->SetErrorX(0); TString coll="PbP"; bool Save=kTRUE; TF1 * fCen = new TF1("fCen","[0]*exp([1]+[2]*x+[3]*x*x+[4]*x*x*x+[5]*x*x*x*x+[6]*x*x*x*x*x)", 0., 100.); if(coll=="PPb"){ //fCen->SetParameters(1.20916e-02, 5.02157e+00, -3.38300e-02, 1.87647e-03, -6.76442e-05, 9.08602e-07, -4.01536e-09);//parameterize on 05.03 after approval //fCen->SetParameters(7.92204e-03, 4.52005e+00, 9.77340e-02, -5.00362e-03, 9.74735e-05, -8.93897e-07, 3.39375e-09);//parameterize on new official MC after QM on 12/03/14 fCen->SetParameters(6.06918e-03, 4.84487e+00, 4.26255e-02, -1.30682e-03, 1.94753e-05, -2.53606e-07, 1.61323e-09); //! parameterize on new official MC using double side HF on 02/02/15 TH1F* histodata=(TH1F*)fDataPPb->Get("Cent"); TH1F* histo1=(TH1F*)fMCPPb->Get("Cent"); //TH1F* histo2=(TH1F*)fNMCPPb->Get("Cent"); TH1F* histo2=(TH1F*)fMCPPb->Get("CentW"); TString data="Pb going positive side"; } //fCen->SetParameters(8.68073e-03, 5.09356e+00, -1.33053e-02, 1.46904e-03, -6.99681e-05, 1.06721e-06, -5.21398e-09); //original else if(coll=="PbP"){ //fCen->SetParameters(1.05408e-02, 5.27477e+00, -8.03382e-02, 3.51669e-03, -8.85332e-05, 1.08917e-06, -4.90091e-09); //fCen->SetParameters(1.14851e-02, 5.31172e+00, -8.52366e-02, 3.00268e-03, -6.04667e-05, 6.24105e-07, -2.43580e-09); //fCen->SetParameters(2.89263e-02, 3.43643e+00, 5.62562e-02, -1.86555e-03, 1.97924e-06, 3.15416e-07, -1.97946e-09);//parameterize on new official MC after QM on 12/03/14 fCen->SetParameters(5.10893e-03,4.88698e+00,8.37930e-02,-3.77127e-03, 7.90191e-05,-9.04877e-07, 4.26221e-09); //! parameterize on new official MC using double side HF on 02/02/15 TH1F* histodata=(TH1F*)fDataPbP->Get("Cent"); TH1F* histo1=(TH1F*)fMCPbP->Get("Cent"); //TH1F* histo2=(TH1F*)fNMCPbP->Get("Cent"); TH1F* histo2=(TH1F*)fMCPbP->Get("CentW"); TString data="Proton going positive side"; } histo1->SetName(Form("%sNewMC_unweighted",coll.Data())); histo2->SetName(Form("%sNewMC_weighted",coll.Data())); histodata->SetName(Form("%sData",coll.Data())); //histo1=(TH1F*)histo1->Rebin(Nbin_vz,"histo1",binbound_vz); //histo2=(TH1F*)histo2->Rebin(Nbin_vz,"histo2",binbound_vz); histo1->Scale(1/histo1->Integral()); histo2->Scale(1/histo2->Integral()); histodata->Scale(1/histodata->Integral()); histo1->SetMarkerStyle(24); histo1->SetMarkerSize(1.2); histo1->SetMarkerColor(4); histo1->SetLineColor(4); histo2->SetMarkerStyle(0); histo2->SetMarkerSize(0); histo2->SetFillStyle(3004); histo2->SetFillColor(2); histo2->SetLineColor(2); //histo2->SetMarkerColor(4); //histo2->SetMarkerColor(2); histodata->SetMarkerStyle(20); histodata->SetMarkerSize(1.2); histodata->SetMarkerColor(1); histodata->SetLineColor(1); TCanvas* c1 = new TCanvas("c1"," ",500,500); TCanvas* c2 = new TCanvas("c2"," ",500,500); makeMultiPanelCanvas(c1,1,1,-0.16,0,0.16,0.14,0.03); makeMultiPanelCanvas(c2,1,1,-0.16,0,0.16,0.14,0.03); TH1F* hFrame=new TH1F("","",100,0,100); fixedFontHist(hFrame,1.2,1.7); hFrame->SetTitle(""); hFrame->GetXaxis()->SetTitleSize(0.05); hFrame->GetYaxis()->SetTitleSize(0.05); hFrame->GetXaxis()->SetTitle("Centrality"); hFrame->GetYaxis()->SetTitle("Event Fraction"); hFrame->GetXaxis()->SetLimits(0,100); //hFrame->GetXaxis()->SetLimits(-3,3); hFrame->GetYaxis()->SetRangeUser(0,9.2e-2); c1->cd(1); hFrame->DrawCopy(); histodata->Draw("same"); histo1->Draw("same"); histo2->Draw("HIST same"); TLegend *leg1=new TLegend(0.20,0.80,0.85,0.92); TLegend *leg2=new TLegend(0.20,0.80,0.85,0.92); leg1->SetBorderSize(0); leg2->SetBorderSize(0); leg1->SetFillColor(0); leg2->SetFillColor(0); leg1->SetTextSize(0.04); leg2->SetTextSize(0.04); leg1->AddEntry(histo1,"Before Centrality weighting","lp"); leg1->AddEntry(histo2,"After Centrality weighting","lfp"); //leg1->AddEntry(histo2,"Before Centrality weighting Last 2 pthat","lfp"); leg1->AddEntry(histodata,data,"lp"); leg1->Draw("same"); TLatex *T1=new TLatex(0.25,0.92,""); T1->SetNDC(); T1->SetTextAlign(12); T1->SetTextSize(0.05); T1->SetTextColor(1); T1->SetTextFont(42); T1->Draw("same"); c2->cd(1); hFrame->GetYaxis()->SetTitle("Data/MC"); hFrame->GetXaxis()->SetLimits(0,100); hFrame->GetYaxis()->SetRangeUser(0,2); hFrame->DrawCopy(); TH1F* ratio = (TH1F*)histodata->Clone(Form("%sratio",coll.Data())); //ratio->SetName("ratio"); ratio->Divide(histo1); /*ratio->Fit(fCen); cout<<fCen->GetNDF()<<endl; cout<<fCen->GetChisquare()<<endl; for(int icent=0;icent<=6;icent++) cout<<fCen->GetParameter(icent)<<","; cout<<endl;*/ ratio->DrawCopy("same"); fCen->SetLineColor(2); fCen->Draw("same"); leg2->AddEntry(ratio,data,"lp"); leg2->AddEntry(fCen,"reweighting function","lp"); leg2->Draw("same"); if(Save){ TFile *fout = new TFile("CentCompare.root","Update"); fout->cd(); ratio->Write("",TObject::kOverwrite); histo1->Write("",TObject::kOverwrite); histo2->Write("",TObject::kOverwrite); histodata->Write("",TObject::kOverwrite); fout->Close(); c2->Print(Form("ratio_Cent_%s.png",coll.Data())); c1->Print(Form("CentCompare_Data%s.png",coll.Data())); c1->Print(Form("CentCompare_Data%s.pdf",coll.Data())); } }
void showFunctions1d(std::vector<TF1*>& functions, const std::vector<std::string>& legendEntries, const TString& xAxisTitle, double yMin, double yMax, const TString& yAxisTitle, const std::string& outputFileName) { assert(functions.size() == legendEntries.size()); TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.12); canvas->SetBottomMargin(0.12); assert(functions.size() > 0); TF1* refFunction = functions[0]; TH1* dummyHistogram = new TH1F("dummyHistogram", "dummyHistogram", 10, refFunction->GetXmin(), refFunction->GetXmax()); dummyHistogram->SetStats(false); dummyHistogram->SetTitle(""); dummyHistogram->SetMinimum(-TMath::Log(yMax)); dummyHistogram->SetMaximum(-TMath::Log(yMax) + 5.); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.Data()); xAxis->SetTitleOffset(1.15); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(Form("-log(%s)", yAxisTitle.Data())); yAxis->SetTitleOffset(1.30); dummyHistogram->Draw("axis"); int colors[] = { 1, 2, 3, 4, 5, 6, 7, 15 }; int numFunctions = functions.size(); if ( numFunctions > 8 ) { std::cerr << "<showFunctions1d>:" << std::endl; std::cerr << "Number of functions must not exceed 8 !!" << std::endl; assert(0); } for ( int iFunction = 0; iFunction < numFunctions; ++iFunction ) { TF1* function = functions[iFunction]; function->SetLineColor(colors[iFunction]); function->SetLineWidth(2); function->Draw("same"); } TLegend* legend = new TLegend(0.68, 0.89 - (0.03 + 0.040*numFunctions), 0.89, 0.89, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextSize(0.035); for ( int iFunction = 0; iFunction < numFunctions; ++iFunction ) { TF1* function = functions[iFunction]; const std::string& legendEntry = legendEntries[iFunction]; legend->AddEntry(function, legendEntry.data(), "l"); } legend->Draw(); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete dummyHistogram; delete legend; delete canvas; }
//--------------------------------------------------------------- double *treat(TString fileData, double lumi, TString decay, vector<double> mtop, vector<double> xlim, int binned, TString date, TString version) //--------------------------------------------------------------- { //TString indir = date+"/v"+version+"/"; TString indir = date+"/"+version+"/"; TString outdir = indir; TString channel = " + Jets channel"; if (fileData.Contains("ElectronHad")) { outdir += "CalibEl/"; indir += "MyAnaEl/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "e"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "ee/e#mu"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "e/ee/e#mu"+channel; } if (fileData.Contains("MuHad")) { outdir += "CalibMu/"; indir += "MyAnaMu/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "#mu"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "#mu#mu/#mue"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "#mu/#mu#mu/#mue"+channel; } if (fileData.Contains("Run2012")) { outdir += "CalibAll/"; indir += "MyAnaAll/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "e/#mu"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "ee/#mu#mu/e#mu"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "e/#mu/ee/#mu#mu/e#mu"+channel; } gROOT->ProcessLine(".! mkdir "+outdir); TLatex* channel_tex = new TLatex(0.22, 0.9, channel); channel_tex->SetNDC(true); channel_tex->SetTextFont(43); channel_tex->SetTextSize(TITLE_FONTSIZE - 6); const unsigned int numberOfPoints = mtop.size(); double x[numberOfPoints], ex[numberOfPoints]; double y[numberOfPoints], ey[numberOfPoints]; for (unsigned int itop = 0; itop < numberOfPoints; itop++) { TString fileMC = TString::Format("All_%d_5.root", (int)mtop[itop]); //TString fileMC = TString::Format("TTJets_MSDecays_JpsiFilter_%d_5.root", (int)mtop[itop]); double *mean_err = new double[2]; if (binned < 2) mean_err = unbinnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi); if (binned == 2) mean_err = binnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi); y[itop] = mean_err[0]; ey[itop] = mean_err[1]; x[itop] = mtop[itop]+0.5; ex[itop] = 0.; } TGraphErrors *gr = new TGraphErrors(numberOfPoints, x, y, ex, ey); TFitResultPtr fitptr = gr->Fit("pol1", "FSQ", ""); TF1 *fit = gr->GetFunction("pol1"); double yinte = fitptr->Parameter(0); double errYinte = fitptr->ParError(0); double slope = fitptr->Parameter(1); double errSlope = fitptr->ParError(1); double chi2 = fitptr->Chi2(); double ndf = fitptr->Ndf(); double err_up[numberOfPoints]; double err_down[numberOfPoints]; double err_val[numberOfPoints]; fitptr->GetConfidenceIntervals(numberOfPoints, 1, 1, x, err_val, 0.68); for(unsigned int itop = 0; itop < numberOfPoints; itop++) { double error = err_val[itop]; err_up[itop] = fit->Eval(x[itop]) + error; err_down[itop] = fit->Eval(x[itop]) - error; } TGraph *gr_up = new TGraph(numberOfPoints,x,err_up); gr_up->Fit("pol2","FQ",""); TF1 *fit_up = gr_up->GetFunction("pol2"); TGraph *gr_down = new TGraph(numberOfPoints,x,err_down); gr_down->Fit("pol2","FQ",""); TF1 *fit_down = gr_down->GetFunction("pol2"); TLegend *leg_calib = new TLegend(0.2,0.75,0.65,0.83,NULL,"brNDC"); leg_calib->SetTextSize(0.04); leg_calib->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp"); leg_calib->SetHeader("Calibration curve"); // Blinded analysis TCanvas *cn_calib = new TCanvas("cn_calib", "cn_calib", 800, 800); cn_calib->cd(); grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)"); gr->Draw("AP"); cn_calib->Update(); fit->SetLineColor(30); fit_up->SetLineColor(29); fit_up->SetLineStyle(2); fit_up->SetLineWidth(2); fit_up->Draw("same"); fit_down->SetLineColor(29); fit_down->SetLineStyle(2); fit_down->SetLineWidth(2); fit_down->Draw("same"); leg_myStyle(leg_calib); leg_calib->SetTextAlign(22); leg_calib->Draw(); channel_tex->Draw("same"); cms_myStyle(lumi, false); TString outBlind = outdir; if (binned < 2) outBlind += "BlindedUnbinnedCalibration"; if (binned == 2) outBlind += "BlindedBinnedCalibration"; cn_calib->SaveAs(outBlind+".pdf"); cn_calib->SaveAs(outBlind+".C"); cn_calib->SaveAs(outBlind+".jpg"); cn_calib->SaveAs(outBlind+".eps"); // Unblinded analysis double *data_fit = new double[2]; if (binned == 0) data_fit = unbinnedFit(indir+fileData, xlim, 0., channel_tex, outdir, lumi); if (binned > 0) data_fit = binnedFit(indir+fileData, xlim, 0., channel_tex, outdir, lumi); double mean_gaus = data_fit[0]; double err_gaus = data_fit[1]; TString mjpsil_res = TString::Format("M_{J/#psi+l} = (%3.1f #pm %3.1f) GeV", mean_gaus, err_gaus); double x_horiz[4]={gr->GetXaxis()->GetXmin(),fit->GetX(mean_gaus+err_gaus,0,250),fit->GetX(mean_gaus-err_gaus,0,250),gr->GetXaxis()->GetXmin()}; double y_horiz[4]={mean_gaus+err_gaus,mean_gaus+err_gaus,mean_gaus-err_gaus,mean_gaus-err_gaus}; TPolyLine *horiz = new TPolyLine(4,x_horiz,y_horiz); TLine *horiz_sup = new TLine(x_horiz[0], y_horiz[0], x_horiz[1], y_horiz[1]); TLine *horiz_med = new TLine(gr->GetXaxis()->GetXmin(), mean_gaus, fit->GetX(mean_gaus,0,250), mean_gaus); TLine *horiz_inf = new TLine(x_horiz[2], y_horiz[2], x_horiz[3], y_horiz[3]); double x_vert_min[4]={fit_up->GetX(mean_gaus-err_gaus,0,250),fit_up->GetX(mean_gaus-err_gaus,0,250),x_horiz[2],x_horiz[2]}; double y_vert_min[4]={gr->GetYaxis()->GetXmin(),mean_gaus-err_gaus,mean_gaus-err_gaus,gr->GetYaxis()->GetXmin()}; TPolyLine *vert_min = new TPolyLine(4,x_vert_min,y_vert_min); double x_vert_mean[4]={x_horiz[2],x_horiz[2],x_horiz[1],x_horiz[1]}; double y_vert_mean[4]={gr->GetYaxis()->GetXmin(),y_horiz[2],y_horiz[1],gr->GetYaxis()->GetXmin()}; TPolyLine *vert_mean = new TPolyLine(4,x_vert_mean,y_vert_mean); double x_vert_max[4]={x_horiz[1],x_horiz[1],fit_down->GetX(mean_gaus+err_gaus,0,250),fit_down->GetX(mean_gaus+err_gaus,0,250)}; double y_vert_max[4]={gr->GetYaxis()->GetXmin(),mean_gaus+err_gaus,mean_gaus+err_gaus,gr->GetYaxis()->GetXmin()}; TPolyLine *vert_max = new TPolyLine(4,x_vert_max,y_vert_max); TLine *vert1 = new TLine(x_vert_min[0],y_vert_min[0],x_vert_min[1],y_vert_min[1]); TLine *vert2 = new TLine(x_vert_mean[0],y_vert_mean[0],x_vert_mean[1],y_vert_mean[1]); TLine *vert3 = new TLine(fit->GetX(mean_gaus,0,250),y_vert_mean[0],fit->GetX(mean_gaus,0,250),mean_gaus); TLine *vert4 = new TLine(x_vert_mean[3],y_vert_mean[3],x_vert_mean[2],y_vert_mean[2]); TLine *vert5 = new TLine(x_vert_max[3],y_vert_max[3],x_vert_max[2],y_vert_max[2]); TString mt_res; double pm_fit = (x_vert_mean[3]-x_vert_mean[0])/2.; double p_fit = x_vert_max[3]-x_vert_mean[3]; double m_fit = x_vert_mean[0]-x_vert_min[0]; if (fabs(p_fit-m_fit)<0.1) mt_res= TString::Format("M_{t} = (%0.1f #pm %0.1f #pm %0.1f) GeV", fit->GetX(mean_gaus,0,250), pm_fit, fabs(m_fit)); else mt_res= TString::Format("M_{t} = (%0.1f #pm %0.1f #splitline{_{+ %0.1f}}{_{- %0.1f}}) GeV", fit->GetX(mean_gaus,0,250),pm_fit, fabs(p_fit), fabs(m_fit)); double *mtop_res = new double[2]; mtop_res[0] = fit->GetX(mean_gaus,0,250); mtop_res[1] = pm_fit + max(fabs(p_fit), fabs(m_fit)); TLegend *leg_res = new TLegend(0.2,0.75,0.65,0.87,NULL,"brNDC"); leg_res->SetTextSize(0.04); leg_res->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp"); leg_res->AddEntry((TObject*)0, mjpsil_res, ""); leg_res->AddEntry((TObject*)0, mt_res, ""); TCanvas *cn_res = new TCanvas("cn_res", "cn_res", 800, 800); cn_res->cd(); grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)"); gr->Draw("AP"); cn_res->Update(); fit->SetLineColor(30); fit_up->SetLineColor(29); fit_up->SetLineStyle(2); fit_up->SetLineWidth(2); fit_up->Draw("same"); fit_down->SetLineColor(29); fit_down->SetLineStyle(2); fit_down->SetLineWidth(2); fit_down->Draw("same"); poly_myStyle(horiz,0,30,1,9,3002); horiz->Draw("f"); horiz->Draw("same"); line_myStyle(horiz_sup,2,9,2); horiz_sup->Draw("same"); line_myStyle(horiz_med,2,4,1); horiz_med->Draw("same"); line_myStyle(horiz_inf,2,9,2); horiz_inf->Draw("same"); poly_myStyle(vert_min,0,9,2,38,3003); vert_min->Draw("f"); vert_min->Draw("same"); poly_myStyle(vert_mean,0,30,1,9,3002); vert_mean->Draw("f"); vert_mean->Draw("same"); poly_myStyle(vert_max,2,38,2,38,3003); vert_max->Draw("f"); vert_max->Draw("same"); line_myStyle(vert1,2,38,2); vert1->Draw("same"); line_myStyle(vert2,2,9,2); vert2->Draw("same"); line_myStyle(vert3,2,4,1); vert3->Draw("same"); line_myStyle(vert4,2,9,2); vert4->Draw("same"); line_myStyle(vert5,2,38,2); vert5->Draw("same"); leg_myStyle(leg_res); leg_res->SetTextAlign(22); leg_res->Draw(); channel_tex->Draw("same"); cms_myStyle(lumi, true); TString outUnblind = outdir; if (binned == 0) outUnblind += "UnblindedUnbinnedCalibration"; if (binned == 1) outUnblind += "UnblindedMixedCalibration"; if (binned == 2) outUnblind += "UnblindedBinnedCalibration"; cn_res->SaveAs(outUnblind+".pdf"); cn_res->SaveAs(outUnblind+".C"); cn_res->SaveAs(outUnblind+".jpg"); cn_res->SaveAs(outUnblind+".eps"); cout << "\n=============== " << channel <<" =================\n" <<endl; for (unsigned int itop = 0; itop < numberOfPoints; itop++) cout << "M_{top} = "<< x[itop] << " GeV, #tilde{M}_{J/#psi+l} = (" << y[itop] << " +/- "<< ey[itop] << ") GeV" << endl; cout << "\nCalibration:" << endl; cout << "#chi^{2}/Ndof = " << chi2/ndf << endl; cout << "slope = " << slope << " +/- " << errSlope << endl; cout << "y-intercept = " << yinte << " +/- " << errYinte << endl; if (binned == 0) cout << "\nUnbinned fit:" << endl; if (binned == 1) cout << "\nMixed fit:" << endl; if (binned == 2) cout << "\nBinned fit:" << endl; cout << mjpsil_res << endl; cout << mt_res << endl; cout << "\nFigures saved in " << outdir << endl; return mtop_res; }
void CreateDrawAndSaveHistogramWithFit(TH1* &histo, TString outputdir, TString outputname, bool saveoutput, bool close, bool autorange = true, double innerRange = 0.1 , double outerRange=1, bool excludeCenter=false, int fittype=2){ /** @brief saves Histogramm as *.root and *.png and if wanted closes the histograms at the end * @details This mehtod create a histogramm and save it as root and png file. If you choose close, the canvas is closed after the histogram was saved */ setPandaStyle(); TString name = TString(histo->GetName()); TString title = TString(histo->GetTitle()); TCanvas * canvas = new TCanvas("c_"+name, title, 0,0,1500,1000); histo->Draw(); TF1 * fit; TF1 * fitinner; TF1 * fitouter; if(excludeCenter){ fit = andi::doubleGaussFitExcludeCenter(histo, false, innerRange, outerRange); } else if (fittype==1){ fit = gaussFit(histo, innerRange); } else if (fittype==2){ fit = doubleGaussFit(histo, autorange, innerRange, outerRange); fitinner = getDoubleFit(histo, autorange, innerRange, outerRange, 1); fitouter = getDoubleFit(histo, autorange, innerRange, outerRange, 2); } else{ std::cout << "Type of fit is not defined"<< std::endl; } fit->SetLineColor(kRed); fit->SetLineStyle(7); fit->SetLineWidth(3); fit->Draw("SAME"); fitinner->SetLineColor(kBlue); fitinner->SetLineStyle(7); fitinner->SetLineWidth(3); fitinner->Draw("SAME"); fitouter->SetLineColor(kBlack); fitouter->SetLineStyle(7); fitouter->SetLineWidth(3); fitouter->Draw("SAME"); PandaSmartLabel("L"); if (saveoutput){ canvas->Print(outputdir + "root-files/" + outputname + ".root"); canvas->Print(outputdir + "png-files/" + outputname + ".png"); canvas->Print(outputdir + "pdf-files/" + outputname + ".pdf"); } if (close) canvas->Close(); }
void makePlot(TH1* histogram_data, bool doKeepBlinded, TH1* histogram_ttH, TH1* histogram_ttZ, TH1* histogram_ttW, TH1* histogram_EWK, TH1* histogram_Rares, TH1* histogram_fakes, TH1* histogramSum_mc, TH1* histogramErr_mc, const std::string& xAxisTitle, const std::string& yAxisTitle, double yMin, double yMax, bool showLegend, const std::string& label, const std::string& outputFileName, bool useLogScale) { TH1* histogram_data_density = 0; if ( histogram_data ) { histogram_data_density = divideHistogramByBinWidth(histogram_data); } histogram_data_density->SetMarkerColor(1); histogram_data_density->SetMarkerStyle(20); histogram_data_density->SetMarkerSize(2); histogram_data_density->SetLineColor(1); histogram_data_density->SetLineWidth(1); histogram_data_density->SetLineStyle(1); TH1* histogram_ttH_density = 0; if ( histogram_ttH ) { if ( histogram_data ) checkCompatibleBinning(histogram_ttH, histogram_data); histogram_ttH_density = divideHistogramByBinWidth(histogram_ttH); } histogram_ttH_density->SetFillColor(628); histogram_ttH_density->SetLineColor(1); histogram_ttH_density->SetLineWidth(1); TH1* histogram_ttZ_density = 0; if ( histogram_ttZ ) { if ( histogram_data ) checkCompatibleBinning(histogram_ttZ, histogram_data); histogram_ttZ_density = divideHistogramByBinWidth(histogram_ttZ); } histogram_ttZ_density->SetFillColor(822); histogram_ttZ_density->SetLineColor(1); histogram_ttZ_density->SetLineWidth(1); TH1* histogram_ttW_density = 0; if ( histogram_ttW ) { if ( histogram_data ) checkCompatibleBinning(histogram_ttW, histogram_data); histogram_ttW_density = divideHistogramByBinWidth(histogram_ttW); } histogram_ttW_density->SetFillColor(823); histogram_ttW_density->SetLineColor(1); histogram_ttW_density->SetLineWidth(1); TH1* histogram_EWK_density = 0; if ( histogram_EWK ) { if ( histogram_data ) checkCompatibleBinning(histogram_EWK, histogram_data); histogram_EWK_density = divideHistogramByBinWidth(histogram_EWK); } histogram_EWK_density->SetFillColor(610); histogram_EWK_density->SetLineColor(1); histogram_EWK_density->SetLineWidth(1); TH1* histogram_Rares_density = 0; if ( histogram_Rares ) { if ( histogram_data ) checkCompatibleBinning(histogram_Rares, histogram_data); histogram_Rares_density = divideHistogramByBinWidth(histogram_Rares); } histogram_Rares_density->SetFillColor(851); histogram_Rares_density->SetLineColor(1); histogram_Rares_density->SetLineWidth(1); TH1* histogram_fakes_density = 0; if ( histogram_fakes ) { if ( histogram_data ) checkCompatibleBinning(histogram_fakes, histogram_data); histogram_fakes_density = divideHistogramByBinWidth(histogram_fakes); } histogram_fakes_density->SetFillColor(1); histogram_fakes_density->SetFillStyle(3005); histogram_fakes_density->SetLineColor(1); histogram_fakes_density->SetLineWidth(1); TH1* histogramSum_mc_density = 0; if ( histogramSum_mc ) { if ( histogram_data ) checkCompatibleBinning(histogramSum_mc, histogram_data); histogramSum_mc_density = divideHistogramByBinWidth(histogramSum_mc); } std::cout << "histogramSum_mc_density = " << histogramSum_mc_density << std::endl; dumpHistogram(histogramSum_mc_density); TH1* histogramErr_mc_density = 0; if ( histogramErr_mc ) { if ( histogram_data ) checkCompatibleBinning(histogramErr_mc, histogram_data); histogramErr_mc_density = divideHistogramByBinWidth(histogramErr_mc); } setStyle_uncertainty(histogramErr_mc_density); TCanvas* canvas = new TCanvas("canvas", "canvas", 950, 1100); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->Draw(); TPad* topPad = new TPad("topPad", "topPad", 0.00, 0.34, 1.00, 0.995); topPad->SetFillColor(10); topPad->SetTopMargin(0.065); topPad->SetLeftMargin(0.20); topPad->SetBottomMargin(0.00); topPad->SetRightMargin(0.04); topPad->SetLogy(useLogScale); TPad* bottomPad = new TPad("bottomPad", "bottomPad", 0.00, 0.01, 1.00, 0.335); bottomPad->SetFillColor(10); bottomPad->SetTopMargin(0.085); bottomPad->SetLeftMargin(0.20); bottomPad->SetBottomMargin(0.35); bottomPad->SetRightMargin(0.04); bottomPad->SetLogy(false); canvas->cd(); topPad->Draw(); topPad->cd(); THStack* histogramStack_mc = new THStack(); histogramStack_mc->Add(histogram_fakes_density); histogramStack_mc->Add(histogram_Rares_density); histogramStack_mc->Add(histogram_EWK_density); histogramStack_mc->Add(histogram_ttW_density); histogramStack_mc->Add(histogram_ttZ_density); histogramStack_mc->Add(histogram_ttH_density); TH1* histogram_ref = histogram_data_density; histogram_ref->SetTitle(""); histogram_ref->SetStats(false); histogram_ref->SetMaximum(yMax); histogram_ref->SetMinimum(yMin); TAxis* xAxis_top = histogram_ref->GetXaxis(); assert(xAxis_top); if ( xAxisTitle != "" ) xAxis_top->SetTitle(xAxisTitle.data()); xAxis_top->SetTitleOffset(1.20); xAxis_top->SetLabelColor(10); xAxis_top->SetTitleColor(10); TAxis* yAxis_top = histogram_ref->GetYaxis(); assert(yAxis_top); if ( yAxisTitle != "" ) yAxis_top->SetTitle(yAxisTitle.data()); yAxis_top->SetTitleOffset(1.20); yAxis_top->SetTitleSize(0.080); yAxis_top->SetLabelSize(0.065); yAxis_top->SetTickLength(0.04); histogram_ref->Draw("axis"); // CV: calling THStack::Draw() causes segmentation violation ?! //histogramStack_mc->Draw("histsame"); // CV: draw histograms without using THStack instead; // note that order in which histograms need to be drawn needs to be reversed // compared to order in which histograms were added to THStack !! histogram_ttH_density->Add(histogram_ttZ_density); histogram_ttH_density->Add(histogram_ttW_density); histogram_ttH_density->Add(histogram_EWK_density); histogram_ttH_density->Add(histogram_Rares_density); histogram_ttH_density->Add(histogram_fakes_density); histogram_ttH_density->Draw("histsame"); std::cout << "histogram_ttH_density = " << histogram_ttH_density << ":" << std::endl; dumpHistogram(histogram_ttH_density); histogram_ttZ_density->Add(histogram_ttW_density); histogram_ttZ_density->Add(histogram_EWK_density); histogram_ttZ_density->Add(histogram_Rares_density); histogram_ttZ_density->Add(histogram_fakes_density); histogram_ttZ_density->Draw("histsame"); histogram_ttW_density->Add(histogram_EWK_density); histogram_ttW_density->Add(histogram_Rares_density); histogram_ttW_density->Add(histogram_fakes_density); histogram_ttW_density->Draw("histsame"); histogram_EWK_density->Add(histogram_Rares_density); histogram_EWK_density->Add(histogram_fakes_density); histogram_EWK_density->Draw("histsame"); histogram_Rares_density->Add(histogram_fakes_density); histogram_Rares_density->Draw("histsame"); TH1* histogram_fakes_density_cloned = (TH1*)histogram_fakes_density->Clone(); histogram_fakes_density_cloned->SetFillColor(10); histogram_fakes_density_cloned->SetFillStyle(1001); histogram_fakes_density_cloned->Draw("histsame"); histogram_fakes_density->Draw("histsame"); if ( histogramErr_mc_density ) { histogramErr_mc_density->Draw("e2same"); } if ( !doKeepBlinded ) { histogram_data_density->Draw("e1psame"); } histogram_ref->Draw("axissame"); double legend_y0 = 0.6950; if ( showLegend ) { TLegend* legend1 = new TLegend(0.2600, legend_y0, 0.5350, 0.9250, NULL, "brNDC"); legend1->SetFillStyle(0); legend1->SetBorderSize(0); legend1->SetFillColor(10); legend1->SetTextSize(0.050); TH1* histogram_data_forLegend = (TH1*)histogram_data_density->Clone(); histogram_data_forLegend->SetMarkerSize(2); legend1->AddEntry(histogram_data_forLegend, "Observed", "p"); legend1->AddEntry(histogram_ttH_density, "t#bar{t}H", "f"); legend1->AddEntry(histogram_ttZ_density, "t#bar{t}Z", "f"); legend1->AddEntry(histogram_ttW_density, "t#bar{t}W", "f"); legend1->Draw(); TLegend* legend2 = new TLegend(0.6600, legend_y0, 0.9350, 0.9250, NULL, "brNDC"); legend2->SetFillStyle(0); legend2->SetBorderSize(0); legend2->SetFillColor(10); legend2->SetTextSize(0.050); legend2->AddEntry(histogram_EWK_density, "Electroweak", "f"); legend2->AddEntry(histogram_Rares_density, "Rares", "f"); legend2->AddEntry(histogram_fakes_density, "Fakes", "f"); if ( histogramErr_mc ) legend2->AddEntry(histogramErr_mc_density, "Uncertainty", "f"); legend2->Draw(); } //addLabel_CMS_luminosity(0.2100, 0.9700, 0.6350); addLabel_CMS_preliminary(0.2100, 0.9700, 0.6350); TPaveText* label_category = 0; if ( showLegend ) label_category = new TPaveText(0.6600, legend_y0 - 0.0550, 0.9350, legend_y0, "NDC"); else label_category = new TPaveText(0.2350, 0.8500, 0.5150, 0.9100, "NDC"); label_category->SetTextAlign(13); label_category->AddText(label.data()); label_category->SetTextSize(0.055); label_category->SetTextColor(1); label_category->SetFillStyle(0); label_category->SetBorderSize(0); label_category->Draw(); canvas->cd(); bottomPad->Draw(); bottomPad->cd(); TH1* histogramRatio = (TH1*)histogram_data_density->Clone("histogramRatio"); if ( !histogramRatio->GetSumw2N() ) histogramRatio->Sumw2(); histogramRatio->SetTitle(""); histogramRatio->SetStats(false); histogramRatio->SetMinimum(-0.99); histogramRatio->SetMaximum(+0.99); histogramRatio->SetMarkerColor(histogram_data_density->GetMarkerColor()); histogramRatio->SetMarkerStyle(histogram_data_density->GetMarkerStyle()); histogramRatio->SetMarkerSize(histogram_data_density->GetMarkerSize()); histogramRatio->SetLineColor(histogram_data_density->GetLineColor()); TH1* histogramRatioUncertainty = (TH1*)histogram_data_density->Clone("histogramRatioUncertainty"); if ( !histogramRatioUncertainty->GetSumw2N() ) histogramRatioUncertainty->Sumw2(); histogramRatioUncertainty->SetMarkerColor(10); histogramRatioUncertainty->SetMarkerSize(0); setStyle_uncertainty(histogramRatioUncertainty); int numBins_bottom = histogramRatio->GetNbinsX(); for ( int iBin = 1; iBin <= numBins_bottom; ++iBin ) { double binContent_data = histogram_data_density->GetBinContent(iBin); double binError_data = histogram_data_density->GetBinError(iBin); double binContent_mc = 0; double binError_mc = 0; if ( histogramSum_mc && histogramErr_mc ) { binContent_mc = histogramSum_mc_density->GetBinContent(iBin); binError_mc = histogramErr_mc_density->GetBinError(iBin); } else { TList* histograms = histogramStack_mc->GetHists(); TIter nextHistogram(histograms); double binError2_mc = 0.; while ( TH1* histogram_density = dynamic_cast<TH1*>(nextHistogram()) ) { binContent_mc += histogram_density->GetBinContent(iBin); binError2_mc += square(histogram_density->GetBinError(iBin)); } binError_mc = TMath::Sqrt(binError2_mc); } if ( binContent_mc > 0. ) { histogramRatio->SetBinContent(iBin, binContent_data/binContent_mc - 1.0); histogramRatio->SetBinError(iBin, binError_data/binContent_mc); histogramRatioUncertainty->SetBinContent(iBin, 0.); histogramRatioUncertainty->SetBinError(iBin, binError_mc/binContent_mc); } } std::cout << "histogramRatio = " << histogramRatio << std::endl; dumpHistogram(histogramRatio); std::cout << "histogramRatioUncertainty = " << histogramRatioUncertainty << std::endl; dumpHistogram(histogramRatioUncertainty); TAxis* xAxis_bottom = histogramRatio->GetXaxis(); assert(xAxis_bottom); xAxis_bottom->SetTitle(xAxis_top->GetTitle()); xAxis_bottom->SetLabelColor(1); xAxis_bottom->SetTitleColor(1); xAxis_bottom->SetTitleOffset(1.05); xAxis_bottom->SetTitleSize(0.16); xAxis_bottom->SetTitleFont(xAxis_top->GetTitleFont()); xAxis_bottom->SetLabelOffset(0.02); xAxis_bottom->SetLabelSize(0.12); xAxis_bottom->SetTickLength(0.065); xAxis_bottom->SetNdivisions(505); TAxis* yAxis_bottom = histogramRatio->GetYaxis(); assert(yAxis_bottom); yAxis_bottom->SetTitle("#frac{Data - Expectation}{Expectation}"); yAxis_bottom->SetLabelColor(1); yAxis_bottom->SetTitleColor(1); yAxis_bottom->SetTitleOffset(0.95); yAxis_bottom->SetTitleFont(yAxis_top->GetTitleFont()); yAxis_bottom->SetNdivisions(505); yAxis_bottom->CenterTitle(); yAxis_bottom->SetTitleSize(0.095); yAxis_bottom->SetLabelSize(0.110); yAxis_bottom->SetTickLength(0.04); histogramRatio->Draw("axis"); TF1* line = new TF1("line","0", xAxis_bottom->GetXmin(), xAxis_bottom->GetXmax()); line->SetLineStyle(3); line->SetLineWidth(1.5); line->SetLineColor(kBlack); line->Draw("same"); histogramRatioUncertainty->Draw("e2same"); if ( !doKeepBlinded ) { histogramRatio->Draw("epsame"); } histogramRatio->Draw("axissame"); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScale ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); canvas->Print(std::string(outputFileName_plot).append(".root").data()); //delete label_cms; delete topPad; delete label_category; delete histogramRatio; delete histogramRatioUncertainty; delete line; delete bottomPad; delete canvas; }
int main (int argc, char**argv){ if(argc!=3){ std::cerr<<" Wrongs input "<<std::endl; return -1; } std::string inputFile1 = argv[1]; std::string inputFile2 = argv[2]; std::cout<<" InputFile1 = "<<inputFile1<<std::endl; std::cout<<" InputFile2 = "<<inputFile2<<std::endl; std::ifstream File1 (inputFile1.c_str()); std::ifstream File2 (inputFile2.c_str()); if(!File1.is_open()){ std::cerr << "** ERROR: Can't open '" << inputFile1 << "' for input" << std::endl; return -1; } if(!File2.is_open()){ std::cerr << "** ERROR: Can't open '" << inputFile2 << "' for input" << std::endl; return -1; } // Set style options gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetOptTitle(1); gStyle->SetOptStat(0); gStyle->SetFitFormat("6.3g"); gStyle->SetPalette(1); gStyle->SetOptTitle(0); gStyle->SetTextFont(42); gStyle->SetTextSize(0.05); gStyle->SetTitleFont(42,"xyz"); gStyle->SetTitleSize(0.05); gStyle->SetLabelFont(42,"xyz"); gStyle->SetLabelSize(0.05); gStyle->SetTitleXOffset(0.8); gStyle->SetTitleYOffset(1.1); gROOT->ForceStyle(); int iPhi, iEta, iz; double ic, eic; /// Histo for first ic set TString Name = Form("mapEB_%s",inputFile1.c_str()); TH2F * map1_EB = new TH2F(Name,Name,360,1, 361, 171, -85, 86); Name = Form("mapEEp_%s",inputFile1.c_str()); TH2F * map1_EEp = new TH2F(Name,Name,100,1, 101, 100, 1, 101); Name = Form("mapEEm_%s",inputFile1.c_str()); TH2F * map1_EEm = new TH2F(Name,Name,100,1, 101, 100, 1, 101); std::cout<<" Opening first file ..... reading "<<std::endl; while (!File1.eof()){ File1 >> iEta >> iPhi >> iz >> ic >> eic ; if(iz==0) map1_EB->Fill(iPhi,iEta,ic); if(iz==1) map1_EEp->Fill(iEta,iPhi,ic); if(iz==-1)map1_EEm->Fill(iEta,iPhi,ic); } std::cout<<" End first file "<<std::endl; std::cout<<" Opening second file ..... reading "<<std::endl; /// Histo for first ic set Name = Form("mapEB_%s",inputFile2.c_str()); TH2F * map2_EB = new TH2F(Name,Name,360,1, 361, 171, -85, 86); Name = Form("mapEEp_%s",inputFile2.c_str()); TH2F * map2_EEp = new TH2F(Name,Name,100,1, 101, 100, 1, 101); Name = Form("mapEEm_%s",inputFile2.c_str()); TH2F * map2_EEm = new TH2F(Name,Name,100,1, 101, 100, 1, 101); while (!File2.eof()){ File2 >> iEta >> iPhi >> iz >> ic >> eic ; if(iz==0) map2_EB->Fill(iPhi,iEta,ic); if(iz==1) map2_EEp->Fill(iEta,iPhi,ic); if(iz==-1) map2_EEm->Fill(iEta,iPhi,ic); } std::cout<<" End second file "<<std::endl; TApplication* theApp = new TApplication("Application",&argc, argv); /// Set of two ic sets Name = Form("diffmapEB"); TH2F * diffmap_EB = (TH2F*) map1_EB->Clone("diffmapEB"); diffmap_EB->Reset(); Name = Form("diffmapEEp"); TH2F * diffmap_EEp = (TH2F*) map1_EEp->Clone("diffmapEEp"); diffmap_EEp->Reset(); Name = Form("diffmapEEm"); TH2F * diffmap_EEm = (TH2F*) map1_EEm->Clone("diffmapEEm"); diffmap_EEm->Reset(); Name = Form("ratiomapEB"); TH2F * ratiomap_EB = (TH2F*) map1_EB->Clone("ratiomapEB"); ratiomap_EB->Reset(); Name = Form("ratiomapEEp"); TH2F * ratiomap_EEp = (TH2F*) map1_EEp->Clone("ratiomapEEp"); ratiomap_EEp->Reset(); Name = Form("ratiomapEEm"); TH2F * ratiomap_EEm = (TH2F*) map1_EEm->Clone("ratiomapEEm"); ratiomap_EEm->Reset(); Name = Form("diffHistEB"); TH1F * diffHistEB = new TH1F(Name,Name,100,-0.6,0.6); diffHistEB->SetLineWidth(2); Name = Form("diffHistEEp"); TH1F * diffHistEEp = new TH1F(Name,Name,100,-0.6,0.6); diffHistEEp->SetLineWidth(2); Name = Form("diffHistEEm"); TH1F * diffHistEEm = new TH1F(Name,Name,100,-0.6,0.6); diffHistEEm->SetLineWidth(2); Name = Form("correlationEB"); TH2F * correlationEB = new TH2F(Name,Name,100,0.2,2.,100,0.2,2.); Name = Form("correlationEEp"); TH2F * correlationEEp= new TH2F(Name,Name,100,0.2,2.,100,0.2,2.); Name = Form("correlationEEm"); TH2F * correlationEEm= new TH2F(Name,Name,100,0.2,2.,100,0.2,2.); for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){ for(int iEta=1; iEta<map1_EB->GetNbinsY()+1; iEta++){ if(map1_EB->GetBinContent(iPhi,iEta)==-1. || map2_EB->GetBinContent(iPhi,iEta)==-1.){ diffmap_EB->SetBinContent(iPhi,iEta,-1.); ratiomap_EB->SetBinContent(iPhi,iEta,-1.); continue;} diffmap_EB->SetBinContent(iPhi,iEta,map1_EB->GetBinContent(iPhi,iEta)-map2_EB->GetBinContent(iPhi,iEta)); diffHistEB->Fill(map1_EB->GetBinContent(iPhi,iEta)-map2_EB->GetBinContent(iPhi,iEta)); ratiomap_EB->SetBinContent(iPhi,iEta,map1_EB->GetBinContent(iPhi,iEta)/map2_EB->GetBinContent(iPhi,iEta)); correlationEB->Fill(map1_EB->GetBinContent(iPhi,iEta),map2_EB->GetBinContent(iPhi,iEta)); } } for(int ix =1; ix<map1_EEp->GetNbinsX()+1; ix++){ for(int iy=1; iy<map1_EEp->GetNbinsY()+1; iy++){ if(map1_EEp->GetBinContent(ix,iy)==-1. || map2_EEp->GetBinContent(ix,iy)==-1.){ diffmap_EEp->SetBinContent(ix,iy,-1.); ratiomap_EEp->SetBinContent(ix,iy,-1.); continue;} diffmap_EEp->SetBinContent(ix,iy,map1_EEp->GetBinContent(ix,iy)-map2_EEp->GetBinContent(ix,iy)); diffHistEEp->Fill(map1_EEp->GetBinContent(ix,iy)-map2_EEp->GetBinContent(ix,iy)); ratiomap_EEp->SetBinContent(ix,iy,map1_EEp->GetBinContent(ix,iy)/map2_EEp->GetBinContent(ix,iy)); correlationEEp->Fill(map1_EEp->GetBinContent(ix,iy),map2_EEp->GetBinContent(ix,iy)); } } for(int ix =1; ix<map1_EEm->GetNbinsX()+1; ix++){ for(int iy=1; iy<map1_EEm->GetNbinsY()+1; iy++){ if(map1_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==-1.){ diffmap_EEm->SetBinContent(ix,iy,-1.); ratiomap_EEm->SetBinContent(ix,iy,-1.); continue;} diffmap_EEm->SetBinContent(ix,iy,map1_EEm->GetBinContent(ix,iy)-map2_EEm->GetBinContent(ix,iy)); diffHistEEm->Fill(map1_EEm->GetBinContent(ix,iy)-map2_EEm->GetBinContent(ix,iy)); ratiomap_EEm->SetBinContent(ix,iy,map1_EEm->GetBinContent(ix,iy)/map2_EEm->GetBinContent(ix,iy)); correlationEEm->Fill(map1_EEm->GetBinContent(ix,iy),map2_EEm->GetBinContent(ix,iy)); } } /// Profile along phi for EB: TGraphErrors *phiProjectionEB1 = new TGraphErrors(); phiProjectionEB1->SetMarkerStyle(20); phiProjectionEB1->SetMarkerSize(1); phiProjectionEB1->SetMarkerColor(kBlue); TGraphErrors *phiProjectionEB2 = new TGraphErrors(); phiProjectionEB2->SetMarkerStyle(20); phiProjectionEB2->SetMarkerSize(1); phiProjectionEB2->SetMarkerColor(kRed); for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){ double sumEta=0, nEta=0; for(int iEta =1; iEta<map1_EB->GetNbinsY()+1; iEta++){ if(map1_EB->GetBinContent(iPhi,iEta)==-1. || map1_EB->GetBinContent(iPhi,iEta)==0.) continue; sumEta=sumEta+map1_EB->GetBinContent(iPhi,iEta); nEta++; } phiProjectionEB1->SetPoint(iPhi-1,iPhi-1,sumEta/nEta); phiProjectionEB1->SetPointError(iPhi-1,0.,0.002); } for(int iPhi =1; iPhi<map2_EB->GetNbinsX()+1; iPhi++){ double sumEta=0, nEta=0; for(int iEta =1; iEta<map2_EB->GetNbinsY()+1; iEta++){ if(map2_EB->GetBinContent(iPhi,iEta)==-1.||map2_EB->GetBinContent(iPhi,iEta)==0. ) continue; sumEta=sumEta+map2_EB->GetBinContent(iPhi,iEta); nEta++; } phiProjectionEB2->SetPoint(iPhi-1,iPhi-1,sumEta/nEta); phiProjectionEB2->SetPointError(iPhi-1,0.,0.002); } /// Profile along phi for EE+: TEndcapRings *eRings = new TEndcapRings(); std::vector<double> vectSum; std::vector<double> vectCounter; vectCounter.assign(360,0.); vectSum.assign(360,0.); TGraphErrors *phiProjectionEEp1 = new TGraphErrors(); phiProjectionEEp1->SetMarkerStyle(20); phiProjectionEEp1->SetMarkerSize(1); phiProjectionEEp1->SetMarkerColor(kBlue); TGraphErrors *phiProjectionEEp2 = new TGraphErrors(); phiProjectionEEp2->SetMarkerStyle(20); phiProjectionEEp2->SetMarkerSize(1); phiProjectionEEp2->SetMarkerColor(kRed); for(int ix=1; ix<map1_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEp->GetNbinsY()+1;iy++){ if(map1_EEp->GetBinContent(ix,iy)==-1. || map1_EEp->GetBinContent(ix,iy)==0. ) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map1_EEp->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } int j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEp1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEp->GetNbinsY()+1;iy++){ if(map2_EEp->GetBinContent(ix,iy)==-1. ||map2_EEp->GetBinContent(ix,iy)==0.) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map2_EEp->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEp2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// Profile along phi for EE-: TGraphErrors *phiProjectionEEm1 = new TGraphErrors(); phiProjectionEEm1->SetMarkerStyle(20); phiProjectionEEm1->SetMarkerSize(1); phiProjectionEEm1->SetMarkerColor(kBlue); TGraphErrors *phiProjectionEEm2 = new TGraphErrors(); phiProjectionEEm2->SetMarkerStyle(20); phiProjectionEEm2->SetMarkerSize(1); phiProjectionEEm2->SetMarkerColor(kRed); for(int ix=1; ix<map1_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEm->GetNbinsY()+1;iy++){ if(map1_EEm->GetBinContent(ix,iy)==-1. || map1_EEm->GetBinContent(ix,iy)==0. ) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map1_EEm->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEm1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEm->GetNbinsY()+1;iy++){ if(map2_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==0.) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map2_EEm->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEm2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// projection along eta for EB TGraphErrors *etaProjectionEB1 = new TGraphErrors(); etaProjectionEB1->SetMarkerStyle(20); etaProjectionEB1->SetMarkerSize(1); etaProjectionEB1->SetMarkerColor(kBlue); TGraphErrors *etaProjectionEB2 = new TGraphErrors(); etaProjectionEB2->SetMarkerStyle(20); etaProjectionEB2->SetMarkerSize(1); etaProjectionEB2->SetMarkerColor(kRed); for(int iEta =1; iEta<map1_EB->GetNbinsY()+1; iEta++){ double sumPhi=0, nPhi=0; for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){ if(map1_EB->GetBinContent(iPhi,iEta)==-1.) continue; sumPhi=sumPhi+map1_EB->GetBinContent(iPhi,iEta); nPhi++; } etaProjectionEB1->SetPoint(iEta-1,iEta-1,sumPhi/nPhi); etaProjectionEB1->SetPointError(iEta-1,0.,0.002); } for(int iEta =1; iEta<map2_EB->GetNbinsY()+1; iEta++){ double sumPhi=0, nPhi=0; for(int iPhi =1; iPhi<map2_EB->GetNbinsX()+1; iPhi++){ if(map2_EB->GetBinContent(iPhi,iEta)==-1.) continue; sumPhi=sumPhi+map2_EB->GetBinContent(iPhi,iEta); nPhi++; } etaProjectionEB2->SetPoint(iEta-1,iEta-1,sumPhi/nPhi); etaProjectionEB2->SetPointError(iEta-1,0.,0.002); } /// projection along eta for EE+: TGraphErrors *etaProjectionEEp1 = new TGraphErrors(); etaProjectionEEp1->SetMarkerStyle(20); etaProjectionEEp1->SetMarkerSize(1); etaProjectionEEp1->SetMarkerColor(kBlue); TGraphErrors *etaProjectionEEp2 = new TGraphErrors(); etaProjectionEEp2->SetMarkerStyle(20); etaProjectionEEp2->SetMarkerSize(1); etaProjectionEEp2->SetMarkerColor(kRed); vectCounter.clear(); vectSum.clear(); vectCounter.assign(360,0.); vectSum.assign(360,0.); for(int ix=1; ix<map1_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEp->GetNbinsY()+1;iy++){ if(map1_EEp->GetBinContent(ix,iy)==-1. || map1_EEp->GetBinContent(ix,iy)==0.) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>360)continue; vectSum.at(iEta)=vectSum.at(iEta)+map1_EEp->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0) continue; etaProjectionEEp1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEp->GetNbinsY()+1;iy++){ if(map2_EEp->GetBinContent(ix,iy)==-1. || map2_EEp->GetBinContent(ix,iy)==0. ) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>360)continue; vectSum.at(iEta)=vectSum.at(iEta)+map2_EEp->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0) continue; etaProjectionEEp2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// projection along eta for EE-: TGraphErrors *etaProjectionEEm1 = new TGraphErrors(); etaProjectionEEm1->SetMarkerStyle(20); etaProjectionEEm1->SetMarkerSize(1); etaProjectionEEm1->SetMarkerColor(kBlue); TGraphErrors *etaProjectionEEm2 = new TGraphErrors(); etaProjectionEEm2->SetMarkerStyle(20); etaProjectionEEm2->SetMarkerSize(1); etaProjectionEEm2->SetMarkerColor(kRed); for(int ix=1; ix<map1_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEm->GetNbinsY()+1;iy++){ if(map1_EEm->GetBinContent(ix,iy)==-1.||map1_EEm->GetBinContent(ix,iy)==0.) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>360)continue; vectSum.at(iEta)=vectSum.at(iEta)+map1_EEm->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; etaProjectionEEm1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEm->GetNbinsY()+1;iy++){ if(map2_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==0.) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>171)continue; vectSum.at(iEta)=vectSum.at(iEta)+map2_EEm->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; etaProjectionEEm2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// phi Profile Histos EB cout<<" Phi Profile Histos "<<endl; TH1F* phiProfileEB1 = new TH1F ("phiProfileEB1","phiProfileEB1",60,0.7,1.3); TH1F* phiProfileEB2 = new TH1F ("phiProfileEB2","phiProfileEB2",60,0.7,1.3); for(int i=0; i<phiProjectionEB1->GetN() ; i++){ double x=0,y=0; phiProjectionEB1->GetPoint(i,x,y); phiProfileEB1->Fill(y); } for(int i=0; i<phiProjectionEB2->GetN() ; i++){ double x=0,y=0; phiProjectionEB2->GetPoint(i,x,y); phiProfileEB2->Fill(y); } TF1 *fgaus = new TF1("fgaus","gaus",-10,10); fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEB1->GetRMS()); fgaus->SetRange(1-5*phiProfileEB1->GetRMS(),1+5*phiProfileEB1->GetRMS()); fgaus->SetLineColor(kBlue); phiProfileEB1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<phiProfileEB1->GetMean()<<" RMS dist "<<phiProfileEB1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEB2->GetRMS()); fgaus->SetRange(1-5*phiProfileEB2->GetRMS(),1+5*phiProfileEB2->GetRMS()); fgaus->SetLineColor(kRed); phiProfileEB2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<phiProfileEB2->GetMean()<<" RMS dist "<<phiProfileEB2->GetRMS()<<endl; /// phi Profile Histos EE+ TH1F* phiProfileEEp1 = new TH1F ("phiProfileEEp1","phiProfileEEp1",60,0.6,1.6); TH1F* phiProfileEEp2 = new TH1F ("phiProfileEEp2","phiProfileEEp2",60,0.6,1.6); for(int i=0; i<phiProjectionEEp1->GetN() ; i++){ double x=0,y=0; phiProjectionEEp1->GetPoint(i,x,y); phiProfileEEp1->Fill(y); } for(int i=0; i<phiProjectionEEp2->GetN() ; i++){ double x=0,y=0; phiProjectionEEp2->GetPoint(i,x,y); phiProfileEEp2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEp1->GetRMS()); fgaus->SetRange(1-5*phiProfileEEp1->GetRMS(),1+5*phiProfileEEp1->GetRMS()); fgaus->SetLineColor(kBlue); phiProfileEEp1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<phiProfileEEp1->GetMean()<<" RMS dist "<<phiProfileEEp1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEp2->GetRMS()); fgaus->SetRange(1-5*phiProfileEEp2->GetRMS(),1+5*phiProfileEEp2->GetRMS()); fgaus->SetLineColor(kRed); phiProfileEEp2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<phiProfileEEp2->GetMean()<<" RMS dist "<<phiProfileEEp2->GetRMS()<<endl; /// phi Profile Histos EE- TH1F* phiProfileEEm1 = new TH1F ("phiProfileEEm1","phiProfileEEm1",60,0.6,1.6); TH1F* phiProfileEEm2 = new TH1F ("phiProfileEEm2","phiProfileEEm2",60,0.6,1.6); for(int i=0; i<phiProjectionEEm1->GetN() ; i++){ double x=0,y=0; phiProjectionEEm1->GetPoint(i,x,y); phiProfileEEm1->Fill(y); } for(int i=0; i<phiProjectionEEm2->GetN() ; i++){ double x=0,y=0; phiProjectionEEm2->GetPoint(i,x,y); phiProfileEEm2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEm1->GetRMS()); fgaus->SetRange(1-5*phiProfileEEm1->GetRMS(),1+5*phiProfileEEm1->GetRMS()); fgaus->SetLineColor(kBlue); phiProfileEEm1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<phiProfileEEm1->GetMean()<<" RMS dist "<<phiProfileEEm1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEm2->GetRMS()); fgaus->SetRange(1-5*phiProfileEEm2->GetRMS(),1+5*phiProfileEEm2->GetRMS()); fgaus->SetLineColor(kRed); phiProfileEEm2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<phiProfileEEm2->GetMean()<<" RMS dist "<<phiProfileEEm2->GetRMS()<<endl; /// eta Profile Histos EB cout<<" Eta Profile Histos "<<endl; TH1F* etaProfileEB1 = new TH1F ("etaProfileEB1","etaProfileEB1",60,0.85,1.15); TH1F* etaProfileEB2 = new TH1F ("etaProfileEB2","etaProfileEB2",60,0.85,1.15); for(int i=0; i<etaProjectionEB1->GetN() ; i++){ double x=0,y=0; etaProjectionEB1->GetPoint(i,x,y); etaProfileEB1->Fill(y); } for(int i=0; i<etaProjectionEB2->GetN() ; i++){ double x=0,y=0; etaProjectionEB2->GetPoint(i,x,y); etaProfileEB2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEB1->GetRMS()); fgaus->SetRange(1-5*etaProfileEB1->GetRMS(),1+5*etaProfileEB1->GetRMS()); fgaus->SetLineColor(kBlue); etaProfileEB1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<etaProfileEB1->GetMean()<<" RMS dist "<<etaProfileEB1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEB2->GetRMS()); fgaus->SetRange(1-5*etaProfileEB2->GetRMS(),1+5*etaProfileEB2->GetRMS()); fgaus->SetLineColor(kRed); etaProfileEB2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<etaProfileEB2->GetMean()<<" RMS dist "<<etaProfileEB2->GetRMS()<<endl; /// eta Profile Histos EE+ TH1F* etaProfileEEp1 = new TH1F ("etaProfileEEp1","etaProfileEEp1",35,0.,2.5); TH1F* etaProfileEEp2 = new TH1F ("etaProfileEEp2","etaProfileEEp2",35,0.,2.5); for(int i=0; i<etaProjectionEEp1->GetN() ; i++){ double x=0,y=0; etaProjectionEEp1->GetPoint(i,x,y); etaProfileEEp1->Fill(y); } for(int i=0; i<etaProjectionEEp2->GetN() ; i++){ double x=0,y=0; etaProjectionEEp2->GetPoint(i,x,y); etaProfileEEp2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEp1->GetRMS()); fgaus->SetRange(1-5*etaProfileEEp1->GetRMS(),1+5*etaProfileEEp1->GetRMS()); fgaus->SetLineColor(kBlue); etaProfileEEp1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<etaProfileEEp1->GetMean()<<" RMS dist "<<etaProfileEEp1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEp2->GetRMS()); fgaus->SetRange(1-5*etaProfileEEp2->GetRMS(),1+5*etaProfileEEp2->GetRMS()); fgaus->SetLineColor(kRed); etaProfileEEp2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<etaProfileEEp2->GetMean()<<" RMS dist "<<etaProfileEEp2->GetRMS()<<endl; /// eta Profile Histos EB TH1F* etaProfileEEm1 = new TH1F ("etaProfileEEm1","etaProfileEEm1",35,0.,2.5); TH1F* etaProfileEEm2 = new TH1F ("etaProfileEEm2","etaProfileEEm2",35,0.,2.5); for(int i=0; i<etaProjectionEEm1->GetN() ; i++){ double x=0,y=0; etaProjectionEEm1->GetPoint(i,x,y); etaProfileEEm1->Fill(y); } for(int i=0; i<etaProjectionEEm2->GetN() ; i++){ double x=0,y=0; etaProjectionEEm2->GetPoint(i,x,y); etaProfileEEm2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEm1->GetRMS()); fgaus->SetRange(1-5*etaProfileEEm1->GetRMS(),1+5*etaProfileEEm1->GetRMS()); fgaus->SetLineColor(kBlue); etaProfileEEm1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<etaProfileEEm1->GetMean()<<" RMS dist "<<etaProfileEEm1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEm2->GetRMS()); fgaus->SetRange(1-5*etaProfileEEm2->GetRMS(),1+5*etaProfileEEm2->GetRMS()); fgaus->SetLineColor(kRed); etaProfileEEm2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<etaProfileEEm2->GetMean()<<" RMS dist "<<etaProfileEEm2->GetRMS()<<endl; ///------------------------------------------------------------------------ ///----------------------------------------------------------------- ///--- Draw plots ///----------------------------------------------------------------- TCanvas *c[30]; c[0] = new TCanvas("hdiffEB","hdiffEB"); c[0]->SetLeftMargin(0.1); c[0]->SetRightMargin(0.13); c[0]->SetGridx(); diffmap_EB->GetXaxis()->SetNdivisions(1020); diffmap_EB->GetXaxis() -> SetLabelSize(0.03); diffmap_EB->GetXaxis() ->SetTitle("i#phi"); diffmap_EB->GetYaxis() ->SetTitle("i#eta"); diffmap_EB->GetZaxis() ->SetRangeUser(-0.1,0.1); diffmap_EB->Draw("COLZ"); c[1] = new TCanvas("histdiffEB","histdiffEB"); c[1]->SetLeftMargin(0.1); c[1]->SetRightMargin(0.13); c[1]->SetLogy(); diffHistEB->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); diffHistEB->Draw(); c[2] = new TCanvas("hratioEB","hratioEB"); c[2]->SetLeftMargin(0.1); c[2]->SetRightMargin(0.13); c[2]->SetGridx(); ratiomap_EB->GetXaxis()->SetNdivisions(1020); ratiomap_EB->GetXaxis() -> SetLabelSize(0.03); ratiomap_EB->GetXaxis() ->SetTitle("i#phi"); ratiomap_EB->GetYaxis() ->SetTitle("i#eta"); ratiomap_EB->GetZaxis() ->SetRangeUser(0.95,1.05); ratiomap_EB->Draw("COLZ"); c[3] = new TCanvas("correlationEB","correlationEB"); c[3]->SetLeftMargin(0.1); c[3]->SetRightMargin(0.13); c[3]->SetGridx(); c[3]->SetGridy(); correlationEB->GetXaxis()->SetNdivisions(1020); correlationEB->GetXaxis() -> SetLabelSize(0.03); correlationEB->GetXaxis() ->SetTitle("c_{#pi}"); correlationEB->GetYaxis() ->SetTitle("c_{ele}"); correlationEB->Draw("COLZ"); c[4] = new TCanvas("hdiffEEp","hdiffEEp"); c[4]->SetLeftMargin(0.1); c[4]->SetRightMargin(0.13); c[4]->SetGridx(); diffmap_EEp->GetXaxis()->SetNdivisions(1020); diffmap_EEp->GetXaxis() -> SetLabelSize(0.03); diffmap_EEp->GetXaxis() ->SetTitle("ix"); diffmap_EEp->GetYaxis() ->SetTitle("iy"); diffmap_EEp->GetZaxis() ->SetRangeUser(-0.15,0.15); diffmap_EEp->Draw("COLZ"); c[5] = new TCanvas("histdiffEEp","histdiffEEp"); c[5]->SetLeftMargin(0.1); c[5]->SetRightMargin(0.13); c[5]->SetLogy(); diffHistEEp->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); diffHistEEp->Draw(); c[6] = new TCanvas("hratioEEp","hratioEEp"); c[6]->SetLeftMargin(0.1); c[6]->SetRightMargin(0.13); c[6]->SetGridx(); ratiomap_EEp->GetXaxis()->SetNdivisions(1020); ratiomap_EEp->GetXaxis() -> SetLabelSize(0.03); ratiomap_EEp->GetXaxis() ->SetTitle("ix"); ratiomap_EEp->GetYaxis() ->SetTitle("iy"); ratiomap_EEp->GetZaxis() ->SetRangeUser(0.9,1.1); ratiomap_EEp->Draw("COLZ"); c[7] = new TCanvas("correlationEEp","correlationEEp"); c[7]->SetLeftMargin(0.1); c[7]->SetRightMargin(0.13); c[7]->SetGridx(); c[7]->SetGridy(); correlationEEp->GetXaxis()->SetNdivisions(1020); correlationEEp->GetXaxis() -> SetLabelSize(0.03); correlationEEp->GetXaxis() ->SetTitle("c_{#pi}"); correlationEEp->GetYaxis() ->SetTitle("c_{ele}"); correlationEEp->Draw("COLZ"); c[8] = new TCanvas("hdiffEEm","hdiffEEm"); c[8]->SetLeftMargin(0.1); c[8]->SetRightMargin(0.13); c[8]->SetGridx(); diffmap_EEm->GetXaxis()->SetNdivisions(1020); diffmap_EEm->GetXaxis() -> SetLabelSize(0.03); diffmap_EEm->GetXaxis() ->SetTitle("ix"); diffmap_EEm->GetYaxis() ->SetTitle("iy"); diffmap_EEm->GetZaxis() ->SetRangeUser(-0.15,0.15); diffmap_EEm->Draw("COLZ"); c[9] = new TCanvas("histdiffEEm","histdiffEEm"); c[9]->SetLeftMargin(0.1); c[9]->SetRightMargin(0.13); c[9]->SetLogy(); diffHistEEm->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); diffHistEEm->Draw(); c[10] = new TCanvas("hratioEEm","hratioEEm"); c[10]->SetLeftMargin(0.1); c[10]->SetRightMargin(0.13); c[10]->SetGridx(); ratiomap_EEm->GetXaxis()->SetNdivisions(1020); ratiomap_EEm->GetXaxis() -> SetLabelSize(0.03); ratiomap_EEm->GetXaxis() ->SetTitle("ix"); ratiomap_EEm->GetYaxis() ->SetTitle("iy"); ratiomap_EEm->GetZaxis() ->SetRangeUser(0.9,1.1); ratiomap_EEm->Draw("COLZ"); c[11] = new TCanvas("correlationEEm","correlationEEm"); c[11]->SetLeftMargin(0.1); c[11]->SetRightMargin(0.13); c[11]->SetGridx(); c[11]->SetGridy(); correlationEEm->GetXaxis()->SetNdivisions(1020); correlationEEm->GetXaxis() -> SetLabelSize(0.03); correlationEEm->GetXaxis() ->SetTitle("c_{#pi}"); correlationEEm->GetYaxis() ->SetTitle("c_{ele}"); correlationEEm->Draw("COLZ"); c[12] = new TCanvas("phiProjectionEB","phiProjectionEB"); c[12]->SetGridx(); c[12]->SetGridy(); phiProjectionEB1->GetHistogram()->GetYaxis()-> SetRangeUser(0.85,1.1); phiProjectionEB1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361); phiProjectionEB1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); phiProjectionEB1->GetHistogram()->GetXaxis()-> SetTitle("i#phi"); phiProjectionEB1->Draw("apl"); phiProjectionEB2->Draw("plsame"); TLegend * leg1 = new TLegend(0.75,0.75,0.89, 0.89); leg1->AddEntry(phiProjectionEB1,"IC set 1","LP"); leg1->AddEntry(phiProjectionEB2,"IC set 2","LP"); leg1->SetFillColor(0); leg1->Draw("same"); c[13] = new TCanvas("phiProjectionEEp","phiProjectionEEp"); c[13]->SetGridx(); c[13]->SetGridy(); phiProjectionEEp1->GetHistogram()->GetYaxis()-> SetRangeUser(0.7,1.4); phiProjectionEEp1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361); phiProjectionEEp1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); phiProjectionEEp1->GetHistogram()->GetXaxis()-> SetTitle("i#phi"); phiProjectionEEp1->Draw("apl"); phiProjectionEEp2->Draw("plsame"); TLegend * leg2 = new TLegend(0.75,0.75,0.89, 0.89); leg2->AddEntry(phiProjectionEEp1,"IC set 1","LP"); leg2->AddEntry(phiProjectionEEp2,"IC set 2","LP"); leg2->SetFillColor(0); leg2->Draw("same"); c[14] = new TCanvas("phiProjectionEEm","phiProjectionEEm"); c[14]->SetGridx(); c[14]->SetGridy(); phiProjectionEEm1->GetHistogram()->GetYaxis()-> SetRangeUser(0.7,1.4); phiProjectionEEm1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361); phiProjectionEEm1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); phiProjectionEEm1->GetHistogram()->GetXaxis()-> SetTitle("i#phi"); phiProjectionEEm1->Draw("apl"); phiProjectionEEm2->Draw("plsame"); TLegend * leg3 = new TLegend(0.75,0.75,0.89, 0.89); leg3->AddEntry(phiProjectionEEm1,"IC set 1","LP"); leg3->AddEntry(phiProjectionEEm2,"IC set 2","LP"); leg3->SetFillColor(0); leg3->Draw("same"); c[15] = new TCanvas("etaProjectionEB","etaProjectionEB"); c[15]->SetGridx(); c[15]->SetGridy(); etaProjectionEB1->GetHistogram()->GetYaxis()-> SetRangeUser(0.9,1.1); etaProjectionEB1->GetHistogram()->GetXaxis()-> SetRangeUser(0,171); etaProjectionEB1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); etaProjectionEB1->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); etaProjectionEB1->Draw("apl"); etaProjectionEB2->Draw("plsame"); TLegend * leg4 = new TLegend(0.75,0.75,0.89, 0.89); leg4->AddEntry(etaProjectionEB1,"IC set 1","LP"); leg4->AddEntry(etaProjectionEB2,"IC set 2","LP"); leg4->SetFillColor(0); leg1->Draw("same"); c[16] = new TCanvas("etaProjectionEEp","etaProjectionEEp"); c[16]->SetGridx(); c[16]->SetGridy(); etaProjectionEEp1->GetHistogram()->GetYaxis()-> SetRangeUser(0.55,1.5); etaProjectionEEp1->GetHistogram()->GetXaxis()-> SetRangeUser(85,125); etaProjectionEEp1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); etaProjectionEEp1->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); etaProjectionEEp1->Draw("apl"); etaProjectionEEp2->Draw("plsame"); TLegend * leg5 = new TLegend(0.75,0.75,0.89, 0.89); leg5->AddEntry(etaProjectionEEp1,"IC set 1","LP"); leg5->AddEntry(etaProjectionEEp2,"IC set 2","LP"); leg5->SetFillColor(0); leg5->Draw("same"); c[17] = new TCanvas("etaProjectionEEm","etaProjectionEEm"); c[17]->SetGridx(); c[17]->SetGridy(); etaProjectionEEm1->GetHistogram()->GetYaxis()-> SetRangeUser(0.55,1.5); etaProjectionEEm1->GetHistogram()->GetXaxis()-> SetRangeUser(85,125); etaProjectionEEm1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); etaProjectionEEm1->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); etaProjectionEEm1->Draw("apl"); etaProjectionEEm2->Draw("plsame"); TLegend * leg6 = new TLegend(0.75,0.75,0.89, 0.89); leg6->AddEntry(etaProjectionEEm1,"IC set 1","LP"); leg6->AddEntry(etaProjectionEEm2,"IC set 2","LP"); leg6->SetFillColor(0); leg6->Draw("same"); c[18] = new TCanvas("phiProfileEB","phiProfileEB"); c[18]->SetGridx(); c[18]->SetGridy(); phiProfileEB1->GetXaxis()->SetTitle("#bar{IC}"); phiProfileEB1->SetLineColor(kBlue); phiProfileEB1->SetMarkerSize(0.8); phiProfileEB1->SetLineWidth(2); phiProfileEB2->SetLineColor(kRed); phiProfileEB2->SetMarkerSize(0.8); phiProfileEB2->SetLineWidth(2); phiProfileEB1->Draw(); phiProfileEB2->Draw("same"); TLegend * leg7 = new TLegend(0.6,0.7,0.89, 0.89); leg7->SetFillColor(0); leg7->AddEntry(phiProfileEB1,"EB Projection I set ", "LP"); leg7->AddEntry(phiProfileEB2,"EB Projection II set ", "LP"); leg7->Draw("same"); c[19] = new TCanvas("phiProfileEEp","phiProfileEEp"); c[19]->SetGridx(); c[19]->SetGridy(); phiProfileEEp1->GetXaxis()->SetTitle("#bar{IC}"); phiProfileEEp1->SetLineColor(kBlue); phiProfileEEp1->SetMarkerSize(0.8); phiProfileEEp1->SetLineWidth(2); phiProfileEEp2->SetLineColor(kRed); phiProfileEEp2->SetMarkerSize(0.8); phiProfileEEp2->SetLineWidth(2); phiProfileEEp1->Draw(); phiProfileEEp2->Draw("same"); TLegend * leg8 = new TLegend(0.6,0.7,0.89, 0.89); leg8->SetFillColor(0); leg8->AddEntry(phiProfileEEp1,"EE+ Projection I set ", "LP"); leg8->AddEntry(phiProfileEEp2,"EE+ Projection II set ", "LP"); leg8->Draw("same"); c[20] = new TCanvas("phiProfileEEm","phiProfileEEm"); c[20]->SetGridx(); c[20]->SetGridy(); phiProfileEEm1->GetXaxis()->SetTitle("#bar{IC}"); phiProfileEEm1->SetLineColor(kBlue); phiProfileEEm1->SetMarkerSize(0.8); phiProfileEEm1->SetLineWidth(2); phiProfileEEm2->SetLineColor(kRed); phiProfileEEm2->SetMarkerSize(0.8); phiProfileEEm2->SetLineWidth(2); phiProfileEEm1->Draw(); phiProfileEEm2->Draw("same"); TLegend * leg9 = new TLegend(0.6,0.7,0.89, 0.89); leg9->SetFillColor(0); leg9->AddEntry(phiProfileEEm1,"EE- Projection I set ", "LP"); leg9->AddEntry(phiProfileEEm2,"EE- Projection II set ", "LP"); leg9->Draw("same"); c[21] = new TCanvas("etaProfileEB","etaProfileEB"); c[21]->SetGridx(); c[21]->SetGridy(); etaProfileEB1->GetXaxis()->SetTitle("#bar{IC}"); etaProfileEB1->SetLineColor(kBlue); etaProfileEB1->SetMarkerSize(0.8); etaProfileEB1->SetLineWidth(2); etaProfileEB2->SetLineColor(kRed); etaProfileEB2->SetMarkerSize(0.8); etaProfileEB2->SetLineWidth(2); etaProfileEB1->Draw(); etaProfileEB2->Draw("same"); TLegend * leg10 = new TLegend(0.6,0.7,0.89, 0.89); leg10->SetFillColor(0); leg10->AddEntry(etaProfileEB1,"EB Projection I set ", "LP"); leg10->AddEntry(etaProfileEB2,"EB Projection II set ", "LP"); leg10->Draw("same"); c[22] = new TCanvas("etaProfileEEp","etaProfileEEp"); c[22]->SetGridx(); c[22]->SetGridy(); etaProfileEEp1->GetXaxis()->SetTitle("#bar{IC}"); etaProfileEEp1->SetLineColor(kBlue); etaProfileEEp1->SetMarkerSize(0.8); etaProfileEEp1->SetLineWidth(2); etaProfileEEp2->SetLineColor(kRed); etaProfileEEp2->SetMarkerSize(0.8); etaProfileEEp2->SetLineWidth(2); etaProfileEEp1->Draw(); etaProfileEEp2->Draw("same"); TLegend * leg11 = new TLegend(0.6,0.7,0.89, 0.89); leg11->SetFillColor(0); leg11->AddEntry(phiProfileEEp1,"EE+ Projection I set ", "LP"); leg11->AddEntry(phiProfileEEp2,"EE+ Projection II set ", "LP"); leg11->Draw("same"); c[23] = new TCanvas("etaProfileEEm","etaProfileEEm"); c[23]->SetGridx(); c[23]->SetGridy(); etaProfileEEm1->GetXaxis()->SetTitle("#bar{IC}"); etaProfileEEm1->SetLineColor(kBlue); etaProfileEEm1->SetMarkerSize(0.8); etaProfileEEm1->SetLineWidth(2); etaProfileEEm2->SetLineColor(kRed); etaProfileEEm2->SetMarkerSize(0.8); etaProfileEEm2->SetLineWidth(2); etaProfileEEm1->Draw(); etaProfileEEm2->Draw("same"); TLegend * leg12 = new TLegend(0.6,0.7,0.89, 0.89); leg12->SetFillColor(0); leg12->AddEntry(phiProfileEEm1,"EE- Projection I set ", "LP"); leg12->AddEntry(phiProfileEEm2,"EE- Projection II set ", "LP"); leg12->Draw("same"); theApp->Run(); return 0; }
double StandardFrequentistDiscovery( const char* infile = "", const char* workspaceName = "channel1", const char* modelConfigNameSB = "ModelConfig", const char* dataName = "obsData", int toys = 1000, double poiValueForBackground = 0.0, double poiValueForSignal = 1.0 ) { // The workspace contains the model for s+b. The b model is "autogenerated" // by copying s+b and setting the one parameter of interest to zero. // To keep the script simple, multiple parameters of interest or different // functional forms of the b model are not supported. // for now, assume there is only one parameter of interest, and these are // its values: // ------------------------------------------------------- // First part is just to access a user-defined file // or create the standard example file if it doesn't exist const char* filename = ""; if (!strcmp(infile,"")) { filename = "results/example_channel1_GammaExample_model.root"; bool fileExist = !gSystem->AccessPathName(filename); // note opposite return code // if file does not exists generate with histfactory if (!fileExist) { #ifdef _WIN32 cout << "HistFactory file cannot be generated on Windows - exit" << endl; return -1; #endif // Normally this would be run on the command line cout <<"will run standard hist2workspace example"<<endl; gROOT->ProcessLine(".! prepareHistFactory ."); gROOT->ProcessLine(".! hist2workspace config/example.xml"); cout <<"\n\n---------------------"<<endl; cout <<"Done creating example input"<<endl; cout <<"---------------------\n\n"<<endl; } } else filename = infile; // Try to open the file TFile *file = TFile::Open(filename); // if input file was specified byt not found, quit if(!file ){ cout <<"StandardRooStatsDemoMacro: Input file " << filename << " is not found" << endl; return -1; } // ------------------------------------------------------- // Tutorial starts here // ------------------------------------------------------- TStopwatch *mn_t = new TStopwatch; mn_t->Start(); // get the workspace out of the file RooWorkspace* w = (RooWorkspace*) file->Get(workspaceName); if (!w) { cout << "workspace not found" << endl; return -1.0; } // get the modelConfig out of the file ModelConfig* mc = (ModelConfig*) w->obj(modelConfigNameSB); // get the data out of the file RooAbsData* data = w->data(dataName); // make sure ingredients are found if (!data || !mc) { w->Print(); cout << "data or ModelConfig was not found" << endl; return -1.0; } RooRealVar* firstPOI = (RooRealVar*) mc->GetParametersOfInterest()->first(); firstPOI->setVal(poiValueForSignal); mc->SetSnapshot(*mc->GetParametersOfInterest()); // create null model ModelConfig *mcNull = mc->Clone("ModelConfigNull"); firstPOI->setVal(poiValueForBackground); mcNull->SetSnapshot(*(RooArgSet*)mcNull->GetParametersOfInterest()->snapshot()); // ---------------------------------------------------- // Configure a ProfileLikelihoodTestStat and a SimpleLikelihoodRatioTestStat // to use simultaneously with ToyMCSampler ProfileLikelihoodTestStat* plts = new ProfileLikelihoodTestStat(*mc->GetPdf()); plts->SetOneSidedDiscovery(true); plts->SetVarName( "q_{0}/2" ); // ---------------------------------------------------- // configure the ToyMCImportanceSampler with two test statistics ToyMCSampler toymcs(*plts, 50); // Since this tool needs to throw toy MC the PDF needs to be // extended or the tool needs to know how many entries in a dataset // per pseudo experiment. // In the 'number counting form' where the entries in the dataset // are counts, and not values of discriminating variables, the // datasets typically only have one entry and the PDF is not // extended. if (!mc->GetPdf()->canBeExtended()) { if (data->numEntries() == 1) { toymcs.SetNEventsPerToy(1); } else cout << "Not sure what to do about this model" << endl; } // We can use PROOF to speed things along in parallel // ProofConfig pc(*w, 2, "user@yourfavoriteproofcluster", false); ProofConfig pc(*w, 2, "", false); //toymcs.SetProofConfig(&pc); // enable proof // instantiate the calculator FrequentistCalculator freqCalc(*data, *mc, *mcNull, &toymcs); freqCalc.SetToys( toys,toys ); // null toys, alt toys // Run the calculator and print result HypoTestResult* freqCalcResult = freqCalc.GetHypoTest(); freqCalcResult->GetNullDistribution()->SetTitle( "b only" ); freqCalcResult->GetAltDistribution()->SetTitle( "s+b" ); freqCalcResult->Print(); double pvalue = freqCalcResult->NullPValue(); // stop timing mn_t->Stop(); cout << "total CPU time: " << mn_t->CpuTime() << endl; cout << "total real time: " << mn_t->RealTime() << endl; // plot TCanvas* c1 = new TCanvas(); HypoTestPlot *plot = new HypoTestPlot(*freqCalcResult, 100, -0.49, 9.51 ); plot->SetLogYaxis(true); // add chi2 to plot int nPOI = 1; TF1* f = new TF1("f", TString::Format("1*ROOT::Math::chisquared_pdf(2*x,%d,0)",nPOI), 0,20); f->SetLineColor( kBlack ); f->SetLineStyle( 7 ); plot->AddTF1( f, TString::Format("#chi^{2}(2x,%d)",nPOI) ); plot->Draw(); c1->SaveAs("standard_discovery_output.pdf"); return pvalue; }
//***############## main fitting Fxn ################ *****// void ZeetimeFitAndPlot( char *Ifile ){ /** Plot Options***/ //gROOT->Reset(); // gROOT->Clear(); gROOT->SetStyle("Plain") ; //gROOT->SetBatch(kFALSE); gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetStatX(.89); gStyle->SetStatY(.89) ; gStyle->SetStatBorderSize(0); //gStyle->SetOptStat(1111111) gStyle->SetCanvasColor(kWhite); // background is no longer mouse-dropping white gStyle->SetPalette(1); // blue to red false color palette. Use 9 for b/w gStyle->SetCanvasBorderMode(0); // turn off canvas borders gStyle->SetPadBorderMode(0); gStyle->SetPaintTextFormat("5.2f"); // What precision to put numbers if plotted with "TEXT" // For publishing: gStyle->SetLineWidth(2); gStyle->SetTextSize(1.1); gStyle->SetLabelSize(0.06,"xy"); gStyle->SetTitleSize(0.08,"xy"); gStyle->SetTitleOffset(1.2,"x"); gStyle->SetTitleOffset(1.0,"y"); gStyle->SetPadTopMargin(0.1); gStyle->SetPadRightMargin(0.1); gStyle->SetPadBottomMargin(0.16); gStyle->SetPadLeftMargin(0.12); TGaxis::SetMaxDigits(2); // Set Axis to be of the form 0.11 10^N TFile *ifile = new TFile(Ifile); TF1 *fitFcn = new TF1("fitFcn", mygaus, FitLowRange, FitHighRange, 3 ); fitFcn->SetNpx(500); fitFcn->SetLineWidth(4); fitFcn->SetLineStyle(5); fitFcn->SetLineColor(kBlue); TH1F*h_Seed_TimeEBEB = (TH1F*)ifile->Get("EBEB/seed time"); TH1F*h_Seed_TimeEEEE = (TH1F*)ifile->Get("EEEE/seed time"); TH1F*h_TofCor_TimeEBEB = (TH1F*)ifile->Get("EBEB/TOF-corr time difference of seeds"); TH1F*h_TofCor_TimeEEEE = (TH1F*)ifile->Get("EEEE/TOF-corr time difference of seeds"); if(h_Seed_TimeEBEB == 0){ std::cout <<"!! Histogram Does not exist!!" << std::endl; throw 1;} if(h_Seed_TimeEEEE == 0){ std::cout <<"!! Histogram Does not exist!!" << std::endl; throw 1;} if(h_TofCor_TimeEBEB == 0){ std::cout <<"!! Histogram Does not exist!!" << std::endl; throw 1;} if(h_TofCor_TimeEEEE == 0){ std::cout <<"!! Histogram Does not exist!!" << std::endl; throw 1;} h_Seed_TimeEBEB->SetTitle("Seed Time[ns]"); h_Seed_TimeEBEB->SetMarkerStyle(20); h_Seed_TimeEBEB->SetMarkerSize(0.8); h_Seed_TimeEBEB->SetStats(1); h_Seed_TimeEBEB->SetTitleSize(0.08, "x"); h_Seed_TimeEBEB->SetTitleOffset(1.0, "x"); h_Seed_TimeEBEB->SetTitleSize(0.06, "y"); h_Seed_TimeEBEB->SetTitleOffset(0.95, "y"); h_Seed_TimeEBEB->SetYTitle("Number of Seeds/0.05ns"); h_Seed_TimeEBEB->SetXTitle("t_{seed}[ns]"); h_Seed_TimeEBEB->GetXaxis()->SetRangeUser(FitLowRange, FitHighRange); h_Seed_TimeEBEB->GetXaxis()->SetNoExponent(kFALSE); /** Set parms as parms of Fit Fxn **/ /* fitFcn->SetParameters(500, h_Seed_TimeEBEB->GetMean(), h_Seed_TimeEBEB->GetRMS() ); fitFcn->SetParNames("CONST", "#mu(ns)", "#sigma(ns)"); h_Seed_TimeEBEB->Fit("fitFcn", "LL"); //Fit with improved LL/ std::cout << "Printing Fit Parameters for EBEB ...... " << std::endl; printf("Integral of function in EBEB = %g\n", fitFcn->Integral( FitLowRange, FitHighRange)); ///// retrive fit results // int npar = fitFcn->GetNpar(); TVirtualFitter *fit = TVirtualFitter::GetFitter(); fit->PrintResults(2,0.); TMatrixD *CovMatrix = new TMatrixD ( npar, npar, fit->GetCovarianceMatrix() ); CovMatrix->Print(); TCanvas *c1 = new TCanvas("c1","EB-EB",200,10,800,900); c1->SetGridx(); c1->SetGridy(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderMode(-1); c1->GetFrame()->SetBorderSize(5); // c1->Divide(2,1); c1->cd(); h_Seed_TimeEBEB->Draw(); fitFcn->Draw("sames"); c1->SetLogy(0); // draw the legend TLegend *leg = new TLegend(0.15,0.72,0.3,0.85); leg->Clear(); leg->SetTextFont(72); leg->SetTextSize(0.04); leg->AddEntry(h_Seed_TimeEBEB,"EB","lpe"); leg->AddEntry(fitFcn,"GAUS","l"); leg->Draw(); c1->SaveAs("Seed_Time_DoubleElectron_Run2012A-EB-EB.png"); */ //EE seed h_Seed_TimeEEEE->SetTitle("Seed Time[ns]"); h_Seed_TimeEEEE->SetMarkerStyle(20); h_Seed_TimeEEEE->SetMarkerSize(0.8); h_Seed_TimeEEEE->SetStats(1); h_Seed_TimeEEEE->SetTitleSize(0.08, "x"); h_Seed_TimeEEEE->SetTitleOffset(1.0, "x"); h_Seed_TimeEEEE->SetTitleSize(0.06, "y"); h_Seed_TimeEEEE->SetTitleOffset(0.95, "y"); h_Seed_TimeEEEE->SetYTitle("Number of Seeds/0.05ns"); h_Seed_TimeEEEE->SetXTitle("t_{seed}[ns]"); h_Seed_TimeEEEE->GetXaxis()->SetRangeUser(FitLowRange, FitHighRange); h_Seed_TimeEEEE->GetXaxis()->SetNoExponent(kFALSE); /** Set parms as parms of Fit Fxn **/ fitFcn->SetParameters(500, h_Seed_TimeEEEE->GetMean(), h_Seed_TimeEEEE->GetRMS() ); fitFcn->SetParNames("CONST", "#mu(ns)", "#sigma(ns)"); h_Seed_TimeEEEE->Fit("fitFcn", "LL"); /**Fit with improved LL**/ std::cout << "Printing Fit Parameters for EEEE ...... " << std::endl; printf("Integral of function in EEEE = %g\n", fitFcn->Integral( FitLowRange, FitHighRange)); //*** retrive fit results***// /* int npar2 = fitFcn->GetNpar(); TVirtualFitter *fit2 = TVirtualFitter::GetFitter(); fit2->PrintResults(2,0.); TMatrixD *CovMatrix2 = new TMatrixD ( npar2, npar2, fit2->GetCovarianceMatrix() ); CovMatrix2->Print(); */ TCanvas *c2 = new TCanvas("c2","EE-EE",200,10,800,900); c2->SetGridx(); c2->SetGridy(); c2->GetFrame()->SetFillColor(21); c2->GetFrame()->SetBorderMode(-1); c2->GetFrame()->SetBorderSize(5); /* c1->Divide(2,1); */ c2->cd(); h_Seed_TimeEEEE->Draw(); fitFcn->Draw("sames"); c2->SetLogy(0); // draw the legend TLegend *leg1 = new TLegend(0.15,0.72,0.3,0.85); leg1->Clear(); leg1->SetTextFont(72); leg1->SetTextSize(0.04); leg1->AddEntry(h_Seed_TimeEEEE,"EE","lpe"); leg1->AddEntry(fitFcn,"GAUS","l"); leg1->Draw(); c2->SaveAs("Seed_Time_DoubleElectron_Run2012A-EE-EE.png"); //EB TOF-corr seed Diff h_TofCor_TimeEBEB->SetTitle("TOF-Corrected(t_{1}-t_{2})[ns]"); h_TofCor_TimeEBEB->SetMarkerStyle(20); h_TofCor_TimeEBEB->SetMarkerSize(0.8); h_TofCor_TimeEBEB->SetStats(1); h_TofCor_TimeEBEB->SetTitleSize(0.08, "x"); h_TofCor_TimeEBEB->SetTitleOffset(1.0, "x"); h_TofCor_TimeEBEB->SetTitleSize(0.06, "y"); h_TofCor_TimeEBEB->SetTitleOffset(0.95, "y"); h_TofCor_TimeEBEB->SetYTitle("Number Of Seed Pair/0.05ns"); h_TofCor_TimeEBEB->SetXTitle("(t_{seed1} - t_{seed2})TOF-Corrected[ns]"); h_TofCor_TimeEBEB->GetXaxis()->SetRangeUser(FitLowRange, FitHighRange); h_TofCor_TimeEBEB->GetXaxis()->SetNoExponent(kFALSE); /** Set parms as parms of Fit Fxn **/ fitFcn->SetParameters(500, h_TofCor_TimeEBEB->GetMean(), h_TofCor_TimeEBEB->GetRMS() ); fitFcn->SetParNames("CONST", "#mu(ns)", "#sigma(ns)"); h_TofCor_TimeEBEB->Fit("fitFcn", "LL"); /**Fit with improved LL**/ std::cout << "Printing Fit Parameters for EBEB-Tof ...... " << std::endl; printf("Integral of function in EBEB Tof = %g\n", fitFcn->Integral( FitLowRange, FitHighRange)); //*** retrive fit results***// /* int npar3 = fitFcn->GetNpar(); TVirtualFitter *fit3 = TVirtualFitter::GetFitter(); fit3->PrintResults(2,0.); TMatrixD *CovMatrix3 = new TMatrixD ( npar3, npar3, fit3->GetCovarianceMatrix() ); CovMatrix3->Print(); */ TCanvas *c3 = new TCanvas("c3","EB-EB TOF-corr",200,10,800,900); c3->SetGridx(); c3->SetGridy(); c3->GetFrame()->SetFillColor(21); c3->GetFrame()->SetBorderMode(-1); c3->GetFrame()->SetBorderSize(5); /* c1->Divide(2,1); */ c3->cd(); h_TofCor_TimeEBEB->Draw(); fitFcn->Draw("sames"); c3->SetLogy(0); // draw the legend TLegend *leg2 = new TLegend(0.15,0.72,0.3,0.85); leg2->SetTextFont(72); leg2->SetTextSize(0.04); leg2->AddEntry(h_TofCor_TimeEBEB,"EB","lpe"); leg2->AddEntry(fitFcn,"GAUS","l"); leg2->Draw(); c3->SaveAs("TOF-Corrected-Seed_Time_DoubleElectron_Run2012A-EB-EB.png"); //EE: TOF-corr seed Diff h_TofCor_TimeEEEE->SetTitle("TOF-Corrected(t_{1}-t_{2})[ns]"); h_TofCor_TimeEEEE->SetMarkerStyle(20); h_TofCor_TimeEEEE->SetMarkerSize(0.8); h_TofCor_TimeEEEE->SetStats(1); h_TofCor_TimeEEEE->SetTitleSize(0.08, "x"); h_TofCor_TimeEEEE->SetTitleOffset(1.0, "x"); h_TofCor_TimeEEEE->SetTitleSize(0.06, "y"); h_TofCor_TimeEEEE->SetTitleOffset(0.95, "y"); h_TofCor_TimeEEEE->SetYTitle("Number Of Seed Pair/0.05ns"); h_TofCor_TimeEEEE->SetXTitle("(t_{seed1} - t_{seed2})TOF-Corrected[ns]"); h_TofCor_TimeEEEE->GetXaxis()->SetRangeUser(FitLowRange, FitHighRange); h_TofCor_TimeEEEE->GetXaxis()->SetNoExponent(kFALSE); /** Set parms as parms of Fit Fxn **/ fitFcn->SetParameters(500, h_TofCor_TimeEEEE->GetMean(), h_TofCor_TimeEEEE->GetRMS() ); fitFcn->SetParNames("CONST", "#mu(ns)", "#sigma(ns)"); h_TofCor_TimeEEEE->Fit("fitFcn", "LL"); /**Fit with improved LL**/ std::cout << "Printing Fit Parameters for EEEE-Tof ...... " << std::endl; printf("Integral of function in EEEE Tof = %g\n", fitFcn->Integral( FitLowRange, FitHighRange)); //*** retrive fit results***// /* int npar4 = fitFcn->GetNpar(); TVirtualFitter *fit4 = TVirtualFitter::GetFitter(); fit4->PrintResults(2,0.); TMatrixD *CovMatrix4 = new TMatrixD ( npar4, npar4, fit4->GetCovarianceMatrix() ); CovMatrix4->Print(); */ TCanvas *c4 = new TCanvas("c4","EE-EE TOF-corr",200,10,800,900); c4->SetGridx(); c4->SetGridy(); c4->GetFrame()->SetFillColor(21); c4->GetFrame()->SetBorderMode(-1); c4->GetFrame()->SetBorderSize(5); /* c1->Divide(2,1); */ c4->cd(); h_TofCor_TimeEEEE->Draw(); fitFcn->Draw("sames"); c4->SetLogy(0); // draw the legend TLegend *leg3 = new TLegend(0.15,0.72,0.3,0.85); leg3->SetTextFont(72); leg3->SetTextSize(0.04); leg3->AddEntry(h_TofCor_TimeEEEE,"EE","lpe"); leg3->AddEntry(fitFcn,"GAUS","l"); leg3->Draw(); c4->SaveAs("TOF-Corrected-Seed_Time_DoubleElectron_Run2012A-EE-EE.png"); }
void plot_ch1() { TFile* hfile=TFile::Open("Histo_ch1.root"); gStyle->SetPadTopMargin(0.10); gStyle->SetOptStat(0); gStyle->SetTitleSize(.5,"XYZ"); TLatex* tt=new TLatex(); tt->SetTextSize(0.05); if (false) { TString hNames[13]={"hMbc","hDeltaE","hMinvEta","hMinvEtaP","hMinvK0S","hPIDpi","hD0pi","hZ0pi","hNPxdHitspi","hVtxPValueK0S","hVtxPValueEta","hVtxPValueEtaP","hVtxPValueB0"}; bool hLog[13]={false,false,false,false,true,true,true,true,false,true,true,true,true}; float hCutLow[13] ={5.25,-0.1,0.45,0.93,0.48,0.2,-0.08,-0.1,1,1E-3,1E-3,1E-3,1E-3}; float hCutHigh[13]={5.29, 0.1,0.57,0.98,0.52,1.0,+0.08,+0.1,4,1E-3,1E-3,1E-3,1E-3}; TLine* tl=new TLine(); tl->SetLineWidth(2); tl->SetLineColor(kRed+2); TCanvas* c1=new TCanvas("c1","Before Cuts"); c1->Divide(4,4); for (int i=0; i<13; ++i) { c1->cd(i+1); hfile->cd("AllCandidates"); TH1* htmp=(TH1F*)gDirectory->Get(hNames[i]); if (htmp) htmp->DrawCopy(); float ymin=0; if (hLog[i]) { gPad->SetLogy(); ymin=1; } hfile->cd("AllCandidatesIsSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]); if (htmp_is) { htmp_is->SetFillColor(kYellow); htmp_is->DrawCopy("same"); } hfile->cd("AllGoodCandidates"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]+"_good"); if (htmp_is) { htmp_is->SetFillColor(kBlue); htmp_is->DrawCopy("same"); } hfile->cd("AllGoodCandidatesIsSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]+"_is_good"); if (htmp_is) { htmp_is->SetFillColor(kGreen); htmp_is->DrawCopy("same"); } hfile->cd("BestCandidates"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]+"_best"); if (htmp_is) { htmp_is->SetLineColor(kRed); htmp_is->DrawCopy("same"); } hfile->cd("BestCandidatesIsSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]+"_is_best"); if (htmp_is) { htmp_is->SetLineColor(kViolet); htmp_is->DrawCopy("same"); } tl->DrawLine(hCutLow[i],ymin,hCutLow[i],htmp->GetMaximum()*1.05); tl->DrawLine(hCutHigh[i],ymin,hCutHigh[i],htmp->GetMaximum()*1.05); } c1->cd(16); TH1* htmp=(TH1F*)hfile->Get("hNCands"); if (htmp) htmp->DrawCopy(); tt->DrawLatexNDC(0.3,0.6,Form("All cands #e: %3.2f",htmp->GetEntries()/10000.)); tt->DrawLatexNDC(0.3,0.5,Form("All cands multiplicity: %3.2f",htmp->GetMean())); //c1->cd(16); htmp=(TH1F*)hfile->Get("hNGoodCands"); if (htmp) { htmp->SetFillColor(kGreen); htmp->DrawCopy("same"); tt->DrawLatexNDC(0.3,0.4,Form("All cands #e: %3.2f",htmp->GetEntries()/10000.)); tt->DrawLatexNDC(0.3,0.3,Form("Good cands multiplicity: %3.2f",htmp->GetMean())); } c1->cd(15); channel(c1,0.3,0.3); hfile->cd(); } if(true) { TString hNames[6]={"hMbc","hDeltaE","hMinvEta","hMinvEtaP","hMinvK0S","hPIDpi"}; bool hLog[6]={false,false,false,false,true,true}; float hCutLow[6] ={5.25,-0.1,0.45,0.93,0.48,0.2}; float hCutHigh[6]={5.29, 0.1,0.57,0.98,0.52,1.0}; TLine* tl=new TLine(); tl->SetLineWidth(2); tl->SetLineColor(kRed+2); TCanvas* c1=new TCanvas("c1","Before Cuts",900,600); c1->Divide(3,2); TLegend* tleg=new TLegend(0.2,0.4,0.6,0.89); tleg->SetFillStyle(0); for (int i=0; i<6; ++i) { c1->cd(i+1); hfile->cd("AllCandidates"); TH1* htmp=(TH1F*)gDirectory->Get(hNames[i]); if (htmp) { htmp->GetXaxis()->SetTitleOffset(.7); htmp->GetXaxis()->SetTitleSize(0.08); htmp->DrawCopy(); if (i==0)tleg->AddEntry(htmp,"All cands","l"); } float ymin=0; if (hLog[i]) { gPad->SetLogy(); ymin=1; } hfile->cd("AllCandidatesIsSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]); if (htmp_is) { htmp_is->SetFillColor(kYellow); htmp_is->DrawCopy("same"); if (i==0)tleg->AddEntry(htmp_is,"MC match","f"); } hfile->cd("AllGoodCandidates"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]); if (htmp_is) { htmp_is->SetFillColor(kBlue); htmp_is->DrawCopy("same"); if (i==0)tleg->AddEntry(htmp_is,"Good cands","f"); } hfile->cd("AllGoodCandidatesIsSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]); if (htmp_is) { htmp_is->SetFillColor(kGreen); htmp_is->DrawCopy("same"); if (i==0)tleg->AddEntry(htmp_is," \" MC match","f"); } tl->DrawLine(hCutLow[i],ymin,hCutLow[i],htmp->GetMaximum()*1.05); tl->DrawLine(hCutHigh[i],ymin,hCutHigh[i],htmp->GetMaximum()*1.05); if (i==0) tleg->Draw(); } channel(c1); c1->Print("Ch1_distr.pdf"); c1->Print("Ch1_distr.png"); TCanvas* c2=new TCanvas("c2","Before Cuts",900,600); c2->Divide(3,2); TLegend* tleg=new TLegend(0.2,0.6,0.6,0.89); for (int i=0; i<6; ++i) { c2->cd(i+1); hfile->cd("BestCandidates"); TH1* htmp=(TH1F*)gDirectory->Get(hNames[i]); float ymin=0; if (hLog[i]) { gPad->SetLogy(); ymin=1; } if (htmp) { htmp->GetXaxis()->SetTitleOffset(.7); htmp->GetXaxis()->SetTitleSize(0.08); htmp->SetMinimum(ymin); htmp->SetFillColor(kBlue); htmp->DrawCopy(); if (i==0)tleg->AddEntry(htmp,"Best cands","f"); } hfile->cd("BestCandidatesIsSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]); if (htmp_is) { htmp_is->SetFillColor(kGreen); htmp_is->DrawCopy("same"); if (i==0)tleg->AddEntry(htmp_is," \" MC match","f"); } hfile->cd("BestCandidatesIsNotSignal"); TH1* htmp_is=(TH1F*)gDirectory->Get(hNames[i]); if (htmp_is) { htmp_is->SetLineColor(kBlack); htmp_is->SetLineStyle(2); htmp_is->DrawCopy("same"); if (i==0)tleg->AddEntry(htmp_is," \" SXF","l"); } tl->DrawLine(hCutLow[i],ymin,hCutLow[i],htmp->GetMaximum()*1.05); tl->DrawLine(hCutHigh[i],ymin,hCutHigh[i],htmp->GetMaximum()*1.05); if (i==0) tleg->Draw(); } channel(c2); c2->Print("Ch1_best_distr.pdf"); c2->Print("Ch1_best_distr.png"); } if (true) { hfile->cd(); TCanvas* cEvents=new TCanvas("cEvents","",600,300); cEvents->Divide(2); cEvents->cd(1); TH1* htmp=(TH1F*)hfile->Get("hNCands"); if (htmp) htmp->DrawCopy(); tt->DrawLatexNDC(0.3,0.6,Form("All cands multiplicity: %3.2f",htmp->GetMean())); tt->DrawLatexNDC(0.3,0.5,Form("All cands #epsilon: %3.3f",htmp->GetEntries()/10000.)); cEvents->cd(2); htmp=(TH1F*)hfile->Get("hNGoodCands"); if (htmp) { htmp->SetFillColor(kBlue); htmp->DrawCopy(); tt->DrawLatexNDC(0.3,0.5,Form("Good cands #epsilon: %3.3f",htmp->GetEntries()/10000.)); tt->DrawLatexNDC(0.3,0.6,Form("Good cands multiplicity: %3.2f",htmp->GetMean())); } hfile->cd(); // Statistics TH1* hEvents=(TH1F*)hfile->Get("hEvents"); cout << "Total number of events: " << hEvents->GetBinContent(1) << " " << hEvents->GetBinContent(10)<< endl; cout << "Total number of events passed: " << hEvents->GetBinContent(2) << " " << hEvents->GetBinContent(11)<< endl; cout << "Total number of signal events passed: " << hEvents->GetBinContent(3) << " " << hEvents->GetBinContent(12)<< endl; channel(cEvents,0.5,0.93); cEvents->Print("Ch1_events.pdf"); cEvents->Print("Ch1_events.png"); } hfile->cd("BestCandidatesDeltaT"); // MC DT TH1* hTrueDT_best=(TH1F*)gDirectory->Get("hTrueDT_best"); TH1* hTrueDT_TrueB0_best=(TH1F*)gDirectory->Get("hTrueDT_TrueB0_best"); hTrueDT_TrueB0_best->SetLineColor(kRed); TH1* hTrueDT_TrueB0bar_best=(TH1F*)gDirectory->Get("hTrueDT_TrueB0bar_best"); hTrueDT_TrueB0bar_best->SetLineColor(kBlue); TH1* hTrueDT_TagB0_best=(TH1F*)gDirectory->Get("hTrueDT_TagB0_best"); hTrueDT_TagB0_best->SetLineColor(kRed); TH1* hTrueDT_TagB0bar_best=(TH1F*)gDirectory->Get("hTrueDT_TagB0bar_best"); hTrueDT_TagB0bar_best->SetLineColor(kBlue); // Reco DT TH1* hDT_best=(TH1F*)gDirectory->Get("hDT_best"); TH1* hDT_TrueB0_best=(TH1F*)gDirectory->Get("hDT_TrueB0_best"); hDT_TrueB0_best->SetLineColor(kRed); TH1* hDT_TrueB0bar_best=(TH1F*)gDirectory->Get("hDT_TrueB0bar_best"); hDT_TrueB0bar_best->SetLineColor(kBlue); TH1* hDT_TagB0_best=(TH1F*)gDirectory->Get("hDT_TagB0_best"); hDT_TagB0_best->SetLineColor(kRed); TH1* hDT_TagB0bar_best=(TH1F*)gDirectory->Get("hDT_TagB0bar_best"); hDT_TagB0bar_best->SetLineColor(kBlue); // define the number of parameters and fit range for the function fitFunc. Int_t npar = 9; Double_t min_range = -20.0; Double_t max_range = 20.0; TF1 * myFitFunc = new TF1("fitFunc", fitFunc, min_range, max_range, npar); myFitFunc->SetParName(0, "norm"); myFitFunc->SetParName(1, "Bias_{C}"); myFitFunc->SetParName(2, "#sigma_{C}"); myFitFunc->SetParName(3, "Bias_{T}"); myFitFunc->SetParName(4, "#sigma_{T}"); myFitFunc->SetParName(5, "Bias_{O}"); myFitFunc->SetParName(6, "#sigma_{O}"); myFitFunc->SetParName(7, "f_{C}"); myFitFunc->SetParName(8, "f_{T}"); myFitFunc->SetParameters(1500.0, 0., 1., 0., 1.5, 0, 3., 0.4, 0.3); myFitFunc->SetParLimits(0, 0.0, 2500.0); // norm myFitFunc->SetParLimits(1, -2.0, 2.0); // mu1 myFitFunc->SetParLimits(2, 0.1, 1.); // sigma1 myFitFunc->SetParLimits(3, -4.0, +4.0); // mu2 myFitFunc->SetParLimits(4, 1., 3.); // sigma2 myFitFunc->SetParLimits(5, -4.0, +4.0); // mu3 myFitFunc->SetParLimits(6, 2., 20.); // sigma3 myFitFunc->SetParLimits(7, 0.0, 1.0); // frac1 myFitFunc->SetParLimits(8, 0.0, 1.0); // frac2 myFitFunc->SetLineWidth(2); if (false) { TCanvas* cDtAll=new TCanvas("cDtAll"); cDtAll->Divide(3,2); cDtAll->cd(1); //hTrueDT_best->Draw(); hTrueDT_best->Fit("fitFunc", "LE"); hTrueDT_best->Draw("e"); TF1 *gC = new TF1("gC","gaus",min_range, max_range); TF1 *gT = new TF1("gT","gaus",min_range, max_range); TF1 *gO = new TF1("gO","gaus",min_range, max_range); double* fitParams=myFitFunc->GetParameters(); gC->SetLineColor(kRed); gC->SetLineStyle(2); gC->SetParameter(0,fitParams[0]*fitParams[7]); gC->SetParameter(1,fitParams[1]); gC->SetParameter(2,fitParams[2]); cout << "Core " << gC->GetParameter(0) << " " << gC->GetParameter(1) << " " << gC->GetParameter(2)<< endl; gT->SetLineColor(kGreen); gT->SetLineStyle(2); gT->SetParameter(0,fitParams[0]*fitParams[8]); gT->SetParameter(1,fitParams[3]); gT->SetParameter(2,fitParams[4]); cout << "Tail " << gT->GetParameter(0) << " " << gT->GetParameter(1) << " " << gT->GetParameter(2)<< endl; gO->SetLineColor(kBlue); gO->SetLineStyle(2); gO->SetParameter(0,fitParams[0]*(1-fitParams[7]-fitParams[8])); gO->SetParameter(1,fitParams[5]); gO->SetParameter(2,fitParams[6]); cout << "Outlier " << gO->GetParameter(0) << " " << gO->GetParameter(1) << " " << gO->GetParameter(2)<< endl; gC->Draw("same"); gT->Draw("same"); gO->Draw("same"); //return; cDtAll->cd(2); hTrueDT_TrueB0_best->Draw(); hTrueDT_TrueB0bar_best->Draw("same"); cDtAll->cd(3); hTrueDT_TagB0_best->Draw(); hTrueDT_TagB0bar_best->Draw("same"); cDtAll->cd(4); //hDT_best->Draw(); hDT_best->Fit("fitFunc", "LE"); hDT_best->Draw("e"); TF1 *gC = new TF1("gC","gaus",min_range, max_range); TF1 *gT = new TF1("gT","gaus",min_range, max_range); TF1 *gO = new TF1("gO","gaus",min_range, max_range); double* fitParams=myFitFunc->GetParameters(); gC->SetLineColor(kRed); gC->SetLineStyle(2); gC->SetParameter(0,fitParams[0]*fitParams[7]); gC->SetParameter(1,fitParams[1]); gC->SetParameter(2,fitParams[2]); cout << "Core " << gC->GetParameter(0) << " " << gC->GetParameter(1) << " " << gC->GetParameter(2)<< endl; gT->SetLineColor(kGreen); gT->SetLineStyle(2); gT->SetParameter(0,fitParams[0]*fitParams[8]); gT->SetParameter(1,fitParams[3]); gT->SetParameter(2,fitParams[4]); cout << "Tail " << gT->GetParameter(0) << " " << gT->GetParameter(1) << " " << gT->GetParameter(2)<< endl; gO->SetLineColor(kBlue); gO->SetLineStyle(2); gO->SetParameter(0,fitParams[0]*(1-fitParams[7]-fitParams[8])); gO->SetParameter(1,fitParams[5]); gO->SetParameter(2,fitParams[6]); cout << "Outlier " << gO->GetParameter(0) << " " << gO->GetParameter(1) << " " << gO->GetParameter(2)<< endl; gC->Draw("same"); gT->Draw("same"); gO->Draw("same"); cDtAll->cd(5); hDT_TrueB0_best->Draw(); hDT_TrueB0bar_best->Draw("same"); cDtAll->cd(6); hDT_TagB0_best->Draw(); hDT_TagB0bar_best->Draw("same"); } gStyle->SetOptStat(0); gStyle->SetFitFormat("4.3g"); gStyle->SetStatFontSize(0.05); gStyle->SetStatFont(62); gStyle->SetStatH(0.15); gStyle->SetStatW(0.18); TCanvas* cDt=new TCanvas("cDt"); //hDT_best->Draw(); hDT_best->Fit("fitFunc", "LE"); hDT_best->Draw("e"); TF1 *gC = new TF1("gC","gaus",min_range, max_range); TF1 *gT = new TF1("gT","gaus",min_range, max_range); TF1 *gO = new TF1("gO","gaus",min_range, max_range); double* fitParams=myFitFunc->GetParameters(); gC->SetLineColor(kRed); gC->SetLineStyle(2); gC->SetParameter(0,fitParams[0]*fitParams[7]); gC->SetParameter(1,fitParams[1]); gC->SetParameter(2,fitParams[2]); cout << "Core " << gC->GetParameter(0) << " " << gC->GetParameter(1) << " " << gC->GetParameter(2)<< endl; gT->SetLineColor(kGreen); gT->SetLineStyle(2); gT->SetParameter(0,fitParams[0]*fitParams[8]); gT->SetParameter(1,fitParams[3]); gT->SetParameter(2,fitParams[4]); cout << "Tail " << gT->GetParameter(0) << " " << gT->GetParameter(1) << " " << gT->GetParameter(2)<< endl; gO->SetLineColor(kBlue); gO->SetLineStyle(2); gO->SetParameter(0,fitParams[0]*(1-fitParams[7]-fitParams[8])); gO->SetParameter(1,fitParams[5]); gO->SetParameter(2,fitParams[6]); cout << "Outlier " << gO->GetParameter(0) << " " << gO->GetParameter(1) << " " << gO->GetParameter(2)<< endl; gC->Draw("same"); gT->Draw("same"); gO->Draw("same"); double resoDt=(gC->GetParameter(2)*gC->GetParameter(0))+(gO->GetParameter(2)*gO->GetParameter(0))+(gT->GetParameter(2)*gT->GetParameter(0)); double sumW=gC->GetParameter(0)+gO->GetParameter(0)+gT->GetParameter(0); cout << "Mean(DT) = " << resoDt/sumW << endl; TLegend* tleg=new TLegend(0.2,.6,0.4,0.89,"Fit","NDC"); tleg->AddEntry(gC,"Core","l"); tleg->AddEntry(gT,"Tail","l"); tleg->AddEntry(gO,"Outlier","l"); tleg->Draw(); tt->DrawLatexNDC(0.65,0.35,Form("<#Deltat>: %3.2f ps",resoDt/sumW)); channel(cDt,0.3,0.96); cDt->Print("Ch1_Dt.pdf"); cDt->Print("Ch1_Dt.png"); TCanvas* cAsym=new TCanvas("cAsym"); TPad *pad1 = new TPad("pad1", "The pad 80% of the height",0.0,0.3,1.0,1.0,0); TPad *pad2 = new TPad("pad2", "The pad 20% of the height",0.0,0.0,1.0,0.3,0); pad1->Draw(); pad2->Draw(); pad1->cd(); hDT_TagB0_best->SetMarkerStyle(24); hDT_TagB0_best->SetMarkerColor(kBlue); hDT_TagB0_best->SetLineColor(kBlue); hDT_TagB0_best->Draw("histoe"); hDT_TagB0bar_best->SetMarkerStyle(20); hDT_TagB0bar_best->SetMarkerColor(kRed); hDT_TagB0bar_best->SetLineColor(kRed); hDT_TagB0bar_best->Draw("histo e same"); TLegend* tleg=new TLegend(0.2,.6,0.4,0.89,"Flavour","NDC"); tleg->AddEntry(hDT_TagB0_best,"B_{0}","l"); tleg->AddEntry(hDT_TagB0bar_best,"#bar{B_{0}}","l"); tleg->Draw(); pad2->cd(); TH1* hDT_Tag_best_num=hDT_TagB0_best->Clone(); hDT_Tag_best_num->Add(hDT_TagB0bar_best,-1.); TH1* hDT_Tag_best_den=hDT_TagB0_best->Clone(); hDT_Tag_best_den->Add(hDT_TagB0bar_best,+1.); TH1* hDT_Tag_best_asym=hDT_Tag_best_num->Clone(); hDT_Tag_best_asym->Divide(hDT_Tag_best_den); hDT_Tag_best_asym->SetMaximum(+1.05); hDT_Tag_best_asym->SetMinimum(-1.05); hDT_Tag_best_asym->SetLineColor(kBlack); hDT_Tag_best_asym->SetMarkerColor(kBlack); hDT_Tag_best_asym->SetMarkerStyle(20); gPad->SetGridy(); hDT_Tag_best_asym->Draw("e"); hDT_Tag_best_asym->GetYaxis()->SetNdivisions(503); hDT_Tag_best_asym->GetYaxis()->SetTitle("Asymmetry"); hDT_Tag_best_asym->GetYaxis()->SetTitleOffset(0.3); hDT_Tag_best_asym->GetYaxis()->SetTitleSize(0.1); hDT_Tag_best_asym->GetYaxis()->SetLabelSize(0.1); hDT_Tag_best_asym->GetXaxis()->SetLabelSize(0.1); hDT_Tag_best_asym->GetXaxis()->SetTitleSize(0.1); hDT_Tag_best_asym->Draw("e"); // TF1* mysin=new TF1("mysin","[0]*sin([1]*x)",-10,10); // mysin->SetParameter(0,0.2); // mysin->SetParameter(1,0.2); // hDT_Tag_best_asym->Fit("mysin","R"); channel(cAsym,0.5,0.96); cAsym->Print("Ch1_Asym.pdf"); cAsym->Print("Ch1_Asym.png"); }
void fitX(TString infname="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151202_bPt0jpsiPt0tkPt0p5/finder_pp_merged.root") { TFile *inf = new TFile(infname.Data()); TTree *ntmix = (TTree*) inf->Get("Bfinder/ntmix"); TH1D *h = new TH1D("h","",40,3.6,4); TCut cutTrk = "1"; //original YJ //TCut cutTrk = "Btrk1PixelHit>=2&&Btrk1StripHit>=7&&Btrk1Chi2ndf<5&&Btrk2PixelHit>=2&&Btrk2StripHit>=7&&Btrk2Chi2ndf<5"; TCut cutTotal="Btype==7&&Bpt>10&&abs(Beta)<10&&sqrt((Bmumueta-Btrk1Eta)*(Bmumueta-Btrk1Eta)+(Bmumuphi-Btrk1Phi)*(Bmumuphi-Btrk1Phi))<9999"&&cutTrk; TCanvas *c = new TCanvas("c","",750,600); ntmix->Draw("Bmass>>h",cutTotal); TFile*output=new TFile("histoX.root","recreate"); output->cd(); h->Write(); output->Close(); h->Sumw2(); TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x+[8]*x*x*x+[9]*x*x*x*x+[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f->SetLineColor(4); f->SetParameters(-2.2597e4,1.326e4,-1.727e3,50,3.686,0.00357,1,3.8725,0.0054); f->FixParameter(4,3.686); f->FixParameter(5,0.00357); f->FixParameter(7,3.8725); h->Fit("f","LL"); h->Fit("f",""); h->Fit("f","LL"); h->Fit("f","LL","",3.65,3.94); h->Fit("f","LL","",3.65,3.94); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(7); h->Fit("f","LL","",3.65,3.94); h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y"); TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+0*Gaus(x,[4],[5])+0*Gaus(x,[7],[5])"); f2->SetParameter(0,f->GetParameter(0)); f2->SetParameter(1,f->GetParameter(1)); f2->SetParameter(2,f->GetParameter(2)); TF1 *f3 = new TF1("f3","[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f3->SetParameter(3,f->GetParameter(3)); f3->SetParameter(4,f->GetParameter(4)); f3->SetParameter(5,f->GetParameter(5)); f3->SetParameter(6,f->GetParameter(6)); f3->SetParameter(7,f->GetParameter(7)); f3->SetParameter(8,f->GetParameter(8)); f->SetLineColor(4); f2->SetLineColor(4); f3->SetRange(3.65,3.94); f2->SetRange(3.65,3.94); f2->SetLineStyle(2); f3->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)"); l->Draw(); TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)"); l2->Draw(); TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary"); l3->Draw(); TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV"); l4->Draw(); cout<<ntmix->GetEntries()<<endl; TH1D *hProj = (TH1D*)h->Clone("hProj"); hProj->Clear(); f->SetRange(3.6,4); for (int i=0;i<h->GetEntries()*11;i++) { hProj->Fill(f->GetRandom()); } TCanvas *c2 = new TCanvas("c2","",750,600); hProj->SetTitle("Estimated Projection"); hProj->Draw("e"); }
void plotSignals_4mu(int channel = 1) { gSystem->AddIncludePath("-I$ROOFITSYS/include"); gROOT->ProcessLine(".L ~/tdrstyle.C"); setTDRStyle(); //gSystem->Load("PDFs/RooRelBW1_cxx.so"); //gSystem->Load("PDFs/RooRelBW2_cxx.so"); gSystem->Load("../PDFs/HZZ4LRooPdfs_cc.so"); string schannel; if (channel == 1) schannel = "4mu"; if (channel == 2) schannel = "4e"; if (channel == 3) schannel = "2mu2e"; std::cout << "schannel = " << schannel << std::endl; const int nPoints = 17.; int masses[nPoints] = {120,130,140,150,160,170,180,190,200,250,300,350,400,450,500,550,600}; double mHVal[nPoints] = {120,130,140,150,160,170,180,190,200,250,300,350,400,450,500,550,600}; double widths[nPoints] = {3.48e-03,4.88e-03,8.14e-03,1.73e-02,8.30e-02,3.80e-01,6.31e-01,1.04e+00,1.43e+00,4.04e+00,8.43e+00,1.52e+01,2.92e+01,46.95,6.80e+01,93.15,1.23e+02}; // R e a d w o r k s p a c e f r o m f i l e // ----------------------------------------------- double a_meanBW[nPoints]; double a_gammaBW[nPoints]; double a_meanCB[nPoints]; double a_sigmaCB[nPoints]; double a_alphaCB[nPoints]; double a_nCB[nPoints]; //for (int i = 0; i < nPoints; i++){ for (int i = 0; i < (nPoints-3); i++){ // Open input file with workspace (generated by rf14_wspacewrite) char infile[192]; sprintf(infile,"/scratch/hep/ntran/dataFiles/HZZ4L/datasets/datasets_baseline/%s/ZZAnalysisTree_H%i%s.root",schannel.c_str(),masses[i],schannel.c_str()); TFile *f = new TFile(infile) ; char outfile[192]; sprintf( outfile, "figs/pdf_%s_bkg_highmass.eps", schannel.c_str() ); //f->ls(); double windowVal = max( widths[i], 1. ); if (mHVal[i] >= 275){ lowside = 180.; } else { lowside = 100.; } double low_M = max( (mHVal[i] - 20.*windowVal), lowside) ; //double high_M = min( (mHVal[i] + 15.*windowVal), 900.) ; double high_M = min( (mHVal[i] + 15.*windowVal), 600.) ; std::cout << "lowM = " << low_M << ", highM = " << high_M << std::endl; RooDataSet* set = (RooDataSet*) f->Get("data"); RooArgSet* obs = set->get() ; obs->Print(); RooRealVar* CMS_zz4l_mass = (RooRealVar*) obs->find("CMS_zz4l_mass") ; CMS_zz4l_mass->setRange(low_M,high_M); for (int a=0 ; a<set->numEntries() ; a++) { set->get(a) ; //cout << CMS_zz4l_mass->getVal() << " = " << set->weight() << endl ; } // constraining parameters... double l_sigmaCB = 0., s_sigmaCB = 3.; if (mHVal[i] >= 500.){ l_sigmaCB = 10.; s_sigmaCB = 12.; } double h_alpha_CB = 1.15; if (mHVal[i] >= 500.){ h_alpha_CB = 0.99; } double s_alpha_CB = 1.2 + (-0.4/590)*(mHVal[i]-110.); RooRealVar mean_CB("mean_CB","mean_CB",0.,-25.,25); RooRealVar sigma_CB("sigma_CB","sigma_CB",s_sigmaCB,l_sigmaCB,30.); //RooRealVar alpha_CB("alpha_CB","alpha_CB",0.9,0.7,h_alpha_CB); RooRealVar alpha_CB("alpha_CB","alpha_CB",s_alpha_CB); RooRealVar n_CB("n_CB","n_CB",1.7,1.5,2.4); RooCBShape signalCB("signalCB","signalCB",*CMS_zz4l_mass,mean_CB,sigma_CB,alpha_CB,n_CB); RooRealVar mean_BW("mean_BW","mean_BW", mHVal[i] ,100.,1000.); RooRealVar gamma_BW("gamma_BW","gamma_BW",widths[i],0.,200.); //RooBreitWigner signalBW("signalBW", "signalBW",*CMS_zz4l_mass,mean_BW,gamma_BW); //RooRelBW1 signalBW("signalBW", "signalBW",*CMS_zz4l_mass,mean_BW,gamma_BW); RooRelBWUF signalBW("signalBW", "signalBW",*CMS_zz4l_mass,mean_BW); //RooRelBW1 signalBW("signalBW", "signalBW",*CMS_zz4l_mass,mean_BW,gamma_BW); RooBreitWigner signalBW1("signalBW1", "signalBW1",*CMS_zz4l_mass,mean_BW,gamma_BW); RooRelBW1 signalBW2("signalBW2", "signalBW2",*CMS_zz4l_mass,mean_BW,gamma_BW); RooRealVar x("x","x",1.); RooRelBWUFParam signalBW3("signalBW3", "signalBW3",*CMS_zz4l_mass,mean_BW,x); RooRealVar y("y","y",0.33333); RooRelBWUFParam signalBW4("signalBW4", "signalBW4",*CMS_zz4l_mass,mean_BW,y); //Set #bins to be used for FFT sampling to 10000 CMS_zz4l_mass->setBins(100000,"fft") ; //Construct BW (x) CB RooFFTConvPdf* sig_ggH = new RooFFTConvPdf("sig_ggH","BW (X) CB",*CMS_zz4l_mass,signalBW,signalCB, 2); // Buffer fraction for cyclical behavior sig_ggH->setBufferFraction(0.2); mean_BW.setConstant(kTRUE); gamma_BW.setConstant(kTRUE); n_CB.setConstant(kTRUE); //alpha_CB.setConstant(kTRUE); RooFitResult *r = sig_ggH.fitTo( *set, SumW2Error(kTRUE) );//, Save(kTRUE), SumW2Error(kTRUE)) ; a_meanBW[i] = mean_BW.getVal(); a_gammaBW[i] = gamma_BW.getVal(); a_meanCB[i] = mean_CB.getVal(); a_sigmaCB[i] = sigma_CB.getVal();; a_alphaCB[i] = alpha_CB.getVal();; a_nCB[i] = n_CB.getVal();; /////////////////////////////////////////////////// // P l o t t i n g int iLineColor = 1; string lab = "blah"; if (channel == 1) { iLineColor = 2; lab = "4#mu"; } if (channel == 3) { iLineColor = 4; lab = "2e2#mu"; } if (channel == 2) { iLineColor = 6; lab = "4e"; } double separation = 0.5; if (mHVal[i] >= 300.) separation = 2; double nbins = (high_M-low_M); nbins /= separation; char yname[192]; sprintf(yname,"Events / %1.1f GeV/c^{2}", separation); char lname[192]; sprintf(lname,"M_{H} = %i [GeV/c^{2}]", (int) mHVal[i] ); char lname2[192]; sprintf(lname2,"Shape Model, %s", lab.c_str() ); RooPlot* frameM4l = CMS_zz4l_mass->frame(Bins( (int) nbins )) ; set->plotOn(frameM4l) ; sig_ggH->plotOn(frameM4l, LineColor(iLineColor)) ; // dummy! TF1* dummyF = new TF1("dummyF","1",0.,1.); TH1F* dummyH = new TH1F("dummyG","dummyG",1, 0.,1.); dummyF->SetLineColor( iLineColor ); //dummyH->SetLineColor( kBlue ); TLegend * box2 = new TLegend(0.17,0.70,0.52,0.90); box2->SetFillColor(0); box2->SetBorderSize(0); box2->AddEntry(dummyH,"Simulation (Powheg + CMS) ","pe"); box2->AddEntry(dummyH,lname,""); box2->AddEntry(dummyF,lname2,"l"); TPaveText *pt = new TPaveText(0.15,0.955,0.4,0.99,"NDC"); pt->SetFillColor(0); pt->SetBorderSize(0); pt->AddText("CMS Preliminary 2011"); TPaveText *pt2 = new TPaveText(0.83,0.955,0.99,0.99,"NDC"); pt2->SetFillColor(0); pt2->SetBorderSize(0); pt2->AddText("#sqrt{s} = 7 TeV"); frameM4l->SetTitle(""); frameM4l->GetXaxis()->SetTitle("M_{4l} [GeV/c^{2}]"); frameM4l->GetYaxis()->SetTitleOffset(1.2); frameM4l->GetYaxis()->SetTitle(yname); TCanvas *c = new TCanvas("c","c",800,600); c->cd(); frameM4l->Draw(); box2->Draw(); pt->Draw(); pt2->Draw(); char plotName[192]; sprintf(plotName,"sigFigs/m%i.eps",masses[i]); c->SaveAs(plotName); /////////////////////////////////////////////////// RooPlot* testFrame = CMS_zz4l_mass->frame(Title("M4L"),Bins(100)) ; signalBW.plotOn(testFrame) ; signalBW1.plotOn(testFrame, LineColor(kBlack)) ; signalBW2.plotOn(testFrame, LineColor(kRed)) ; TCanvas *c3 = new TCanvas("c3","c3",800,600); c3->cd(); testFrame->Draw(); //char plotName[192]; sprintf(plotName,"sigFigs/shape%i.eps",masses[i]); c3->SaveAs(plotName); /////////////////////////////////////////////////// delete f; delete set; delete c; } TGraph* gr_meanBW = new TGraph( nPoints, mHVal, a_meanBW ); TGraph* gr_gammaBW = new TGraph( nPoints, mHVal, a_gammaBW ); TGraph* gr_meanCB = new TGraph( nPoints, mHVal, a_meanCB ); TGraph* gr_sigmaCB = new TGraph( nPoints, mHVal, a_sigmaCB ); TGraph* gr_alphaCB = new TGraph( nPoints, mHVal, a_alphaCB ); TGraph* gr_nCB = new TGraph( nPoints, mHVal, a_nCB ); TF1 *polyFunc1= new TF1("polyFunc1","[0]+[1]*x+[2]*(x-[3])*(x-[3])+[4]*x*x*x*x", 120., 600.); polyFunc1->SetParameters(1., 1., 1., 100.,0.1); TF1 *polyFunc2= new TF1("polyFunc2","[0]+[1]*x+[2]*(x-[3])*(x-[3])+[4]*x*x*x*x", 120., 600.); polyFunc2->SetParameters(1., 1., 1., 100.,0.1); TCanvas *c = new TCanvas("c","c",1200,800); c->Divide(3,2); //c->SetGrid(); //TH1F *hr = c->DrawFrame(0.,0.,610.,1.); c->cd(1); gr_meanBW->Draw("alp"); gr_meanBW->GetXaxis()->SetTitle("mean BW"); c->cd(2); gr_gammaBW->Draw("alp"); gr_gammaBW->GetXaxis()->SetTitle("gamma BW"); c->cd(3); gr_meanCB->Fit(polyFunc1,"Rt"); gr_meanCB->Draw("alp"); gr_meanCB->GetXaxis()->SetTitle("mean CB"); c->cd(4); gr_sigmaCB->Fit(polyFunc2,"Rt"); gr_sigmaCB->Draw("alp"); gr_sigmaCB->GetXaxis()->SetTitle("sigma CB"); c->cd(5); gr_alphaCB->Draw("alp"); gr_alphaCB->GetXaxis()->SetTitle("alpha CB"); c->cd(6); gr_nCB->Draw("alp"); gr_nCB->GetXaxis()->SetTitle("n CB"); c->SaveAs("sigFigs/params.eps"); std::cout << "mean_CB = " << polyFunc1->GetParameter(0) << " + " << polyFunc1->GetParameter(1) << "*m + " << polyFunc1->GetParameter(2) << "*(m - " << polyFunc1->GetParameter(3) << ")*(m - " << polyFunc1->GetParameter(3); std::cout << ") + " << polyFunc1->GetParameter(4) << "*m*m*m*m;" << std::endl; std::cout << "sigma_CB = " << polyFunc2->GetParameter(0) << " + " << polyFunc2->GetParameter(1) << "*m + " << polyFunc2->GetParameter(2) << "*(m - " << polyFunc2->GetParameter(3) << ")*(m - " << polyFunc2->GetParameter(3); std::cout << ") + " << polyFunc2->GetParameter(4) << "*m*m*m*m;" << std::endl; // calculate sysetmatic errors from interpolation... double sum_meanCB = 0; double sum_sigmaCB = 0; for (int i = 0; i < nPoints; i++){ double tmp_meanCB = (polyFunc1->Eval(mHVal[i]) - a_meanCB[i]); sum_meanCB += (tmp_meanCB*tmp_meanCB); double tmp_sigmaCB = (polyFunc2->Eval(mHVal[i]) - a_sigmaCB[i])/a_sigmaCB[i]; sum_sigmaCB += (tmp_sigmaCB*tmp_sigmaCB); std::cout << "mean: " << tmp_meanCB << ", sigma: " << tmp_sigmaCB << std::endl; } double rms_meanCB = sqrt( sum_meanCB/( (double) nPoints) ); double rms_sigmaCB = sqrt( sum_sigmaCB/( (double) nPoints) ); std::cout << "err (meanCB) = " << rms_meanCB << ", err (sigmaCB) = " << rms_sigmaCB << std::endl; }
void* Monitoring::MonitorThread(void* arg){ //std::cout<<"d1"<<std::endl; monitor_thread_args* args= static_cast<monitor_thread_args*>(arg); std::string outpath=args->outputpath; zmq::socket_t Ireceive (*(args->context), ZMQ_PAIR); Ireceive.connect("inproc://MonitorThread"); // std::vector<CardData*> carddata; std::map<int,std::vector<TH1F> > PedTime; std::map<int,std::vector<TH1F> > PedRMSTime; std::vector<TH1F> rates; std::vector<TH1F> averagesize; std::vector<TH1I> tfreqplots; std::map<int,std::vector<std::vector<float > > > pedpars; TCanvas c1("c1","c1",600,400); bool running=true; bool init=true; std::vector<PMT> PMTInfo; /////////////////// Connect to sql /////////////////////// //std::cout<<"d2"<<std::endl; pqxx::connection *C; std::stringstream tmp; tmp<<"dbname=annie"<<" hostaddr=127.0.0.1"<<" port=5432" ; C=new pqxx::connection(tmp.str().c_str()); if (C->is_open()) { // std::cout << "Opened database successfully: " << C->dbname() << std::endl; } else { std::cout << "Can't open database" << std::endl; return false; } tmp.str(""); pqxx::nontransaction N(*C); tmp<<"select gx,gy,gz,vmecard,vmechannel from pmtconnections order by channel; "; /* Execute SQL query */ pqxx::result R( N.exec( tmp.str().c_str() )); //pqxx::result::const_iterator c = R.begin(); ///////// Fill PMT Info//////////////// for ( pqxx::result::const_iterator c = R.begin(); c != R.end(); ++c) { PMT tmp; tmp.gx= c[0].as<int>(); tmp.gy= c[1].as<int>(); tmp.gz= c[2].as<int>(); tmp.card= c[3].as<int>(); tmp.channel= c[4].as<int>()-1; PMTInfo.push_back(tmp); } //std::cout<<"d3"<<std::endl; while (running){ //std::cout<<"d4"<<std::endl; zmq::message_t comm; Ireceive.recv(&comm); std::istringstream iss(static_cast<char*>(comm.data())); std::string arg1=""; iss>>arg1; //std::cout<<"d5"<<std::endl; if(arg1=="Data"){ ////////// Setting up plots///////// std::vector<TGraph2D*> mg; TH2I EventDisplay ("Event Display", "Event Display", 10, -1, 8, 10, -1, 8); TH2I RMSDisplay ("RMS Display", "RMS Display", 10, -1, 8, 10, -1, 8); std::vector<TH1F> temporalplots; std::vector<TH1I> freqplots; CardData* carddata; int size=0; iss>>size; //freqplots.clear(); //std::cout<<"d6"<<std::endl; for(int i=0;i<size;i++){ //std::cout<<"d7"<<std::endl; long long unsigned int pointer; iss>>std::hex>>pointer; carddata=(reinterpret_cast<CardData *>(pointer)); if(init){ ////make initial freq plot and ped vector ped time and ped rms//// for(int j=0;j<carddata->channels;j++){ std::stringstream tmp; tmp<<"Channel "<<(i*4)+j<<" frequency"; TH1I tmpfreq(tmp.str().c_str(),tmp.str().c_str(),10,0,9); tfreqplots.push_back(tmpfreq); tmp.str(""); tmp<<"Channel "<<(i*4)+j<<" Pedistal"; TH1F tmppedtime(tmp.str().c_str(),tmp.str().c_str(),100,0,99); PedTime[carddata->CardID].push_back(tmppedtime); tmp.str(""); tmp<<"Channel "<<(i*4)+j<<" Pedistal RMS"; TH1F tmppedrmstime(tmp.str().c_str(),tmp.str().c_str(),100,0,99); PedRMSTime[carddata->CardID].push_back(tmppedrmstime); std::vector<float> tmppedpars; tmppedpars.push_back(0); tmppedpars.push_back(0); pedpars[carddata->CardID].push_back(tmppedpars); } if(i==size-1)init=false; } //std::cout<<"d8"<<std::endl; // std::cout<<"d1"<<std::endl; ///////Make temporal plot ////////// for(int j=0;j<carddata->channels;j++){ std::stringstream tmp; tmp<<"Channel "<<(i*4)+j<<" temporal"; TH1F temporal(tmp.str().c_str(),tmp.str().c_str(),carddata->buffersize,0,carddata->buffersize-1); long sum=0; //////////Make freq plot/////////////// tmp.str(""); tmp<<"Channel "<<(i*4)+j<<" frequency"; TH1I freq(tmp.str().c_str(),tmp.str().c_str(),200,200,399); // std::cout<<"d2"<<std::endl; //std::cout<<"d9"<<std::endl; ///// Calculate sum for event dispkay and fill freq plots ///////// for(int k=0;k<carddata->buffersize;k++){ //std::cout<<"d10"<<std::endl; // std::cout<<"i="<<i<<" j="<<j<<std::endl; //std::cout<<"d2.5 "<<(i*4)+j<<" feqplot.size = "<<freqplots.size()<<std::endl; if(carddata->Data[(j*carddata->buffersize)+k]>pedpars[carddata->CardID].at(j).at(0)+(pedpars[carddata->CardID].at(j).at(1)*5))sum+=carddata->Data[(j*carddata->buffersize)+k]; freq.Fill(carddata->Data[(j*carddata->buffersize)+k]); //temporal.SetBinContent(k,carddata->Data[(j*carddata->buffersize)+k]); } freqplots.push_back(freq); //////// find pedistall fill ped temporals////////// freq.Fit("gaus"); TF1 *gaus = freq.GetFunction("gaus"); pedpars[carddata->CardID].at(j).at(0)=(gaus->GetParameter(1)); pedpars[carddata->CardID].at(j).at(1)=(gaus->GetParameter(2)); gaus->SetLineColor(j+1); //std::cout<<"d11"<<std::endl; for(int bin=99;bin>0;bin--){ PedTime[carddata->CardID].at(j).SetBinContent(bin,PedTime[carddata->CardID].at(j).GetBinContent(bin-1)); PedRMSTime[carddata->CardID].at(j).SetBinContent(bin,PedRMSTime[carddata->CardID].at(j).GetBinContent(bin-1)); } PedTime[carddata->CardID].at(j).SetBinContent(0, pedpars[carddata->CardID].at(j).at(0)); PedRMSTime[carddata->CardID].at(j).SetBinContent(0, pedpars[carddata->CardID].at(j).at(1)); //////// fill temporal plot///////// for(int k=0;k<carddata->buffersize/4;k++){ //std::cout<<"d12"<<std::endl; //std::cout<<"j*4 = "<<j*4<<std::endl; //std::cout<<"(i*BufferSize)+(j*4) = "<<(i*BufferSize)+(j*4)<<std::endl; //std::cout<<"i*BufferSize)+(j*4)+(BufferSize/2) = "<<(i*BufferSize)+(j*4)+(BufferSize/2)<<std::endl; //std::cout<<"(i*BufferSize)+(j*4)+(BufferSize/2)+1 = "<<(i*BufferSize)+(j*4)+(BufferSize/2)+1<<std::endl; int offset=pedpars[carddata->CardID].at(j).at(0); double conversion=2.415/pow(2.0, 12.0); temporal.SetBinContent(k*4,(carddata->Data[(j*carddata->buffersize)+(k*2)]-offset)*conversion); temporal.SetBinContent((k*4)+1,(carddata->Data[(j*carddata->buffersize)+(k*2)+1]-offset)*conversion); temporal.SetBinContent((k*4)+2,(carddata->Data[(j*carddata->buffersize)+(k*2)+(carddata->buffersize/2)]-offset)*conversion); temporal.SetBinContent((k*4)+3,(carddata->Data[(j*carddata->buffersize)+(k*2)+(carddata->buffersize/2)+1]-offset)*conversion); } //std::cout<<"d13"<<std::endl; //std::cout<<"d3"<<std::endl; temporalplots.push_back(temporal); ////// find x,y,z fill event display ///////// int x=-10; int z=-10; int y=-10; for(int pmt=0;pmt<PMTInfo.size();pmt++){ //std::cout<<"d4"<<std::endl; if(PMTInfo.at(pmt).card==carddata->CardID && PMTInfo.at(pmt).channel==j){ x=PMTInfo.at(pmt).gx; z=PMTInfo.at(pmt).gz; y=PMTInfo.at(pmt).gy; //std::cout<<"d15"<<std::endl; } } /* int x=(((i*4)+j)%8); int y=(floor(((i*4)+j)/8.0)); if(x==0 && y==0){x=-10;y=-10;} if(x==7 && y==0){x=-10;y=-10;} if(x==0 && y==7){x=-10;y=-10;} if(x==7 && y==7){x=-10;y=-10;} if (y>7){x=-10;y=-10;} std::cout<<"i="<<i<<" j="<<j<<" (i*4)+j)="<<((i*4)+j)<<" x="<<x<<" y="<<y<<" sum="<<sum<<std::endl; EventDisplay.SetBinContent(x+1,y+1,sum); //EventDisplay.SetBinContent(((i*4)+j),sum); */ //std::cout<<"d16"<<std::endl; if(x!=-10 && z!=-10){ //std::cout<<"d17"<<std::endl; //std::cout<<"gx = "<<x<<" , gz="<<z<<std::endl; EventDisplay.SetBinContent(x+2,z+2,sum); RMSDisplay.SetBinContent(x+2,z+2,gaus->GetParameter(2)*100); //// Attempted 2ne event display /// TGraph2D *dt=new TGraph2D(1); dt->SetPoint(0,x,z,z); dt->SetMarkerStyle(20); //dt->GetXaxis()->SetRangeUser(-1,8); // dt->GetYaxis()->SetRangeUser(-1,8); //dt->GetZaxis()->SetRangeUser(-1,8); mg.push_back(dt); } } //std::cout<<"d18"<<std::endl; ///////Find max freq for scaling////////// int maxplot=0; long maxvalue=0; //std::cout<<"i="<<i<<" (i*4)="<<(i*4)<<" (i*4)+4="<<(i*4)+4<<" size="<<freqplots.size()<<std::endl; for(int j=(i*4);j<(i*4)+4;j++){ if (freqplots.at(j).GetMaximum()>maxvalue){ //std::cout<<"d19"<<std::endl; maxvalue=freqplots.at(j).GetMaximum(); maxplot=j; } } //std::cout<<"d20"<<std::endl; ////////Find current time and plot frewuency plot time_t t = time(0); // get time now struct tm * now = localtime( & t ); std::stringstream title; title<<"Card "<<carddata->CardID<<" frequency: "<<(now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday<<','<<now->tm_hour<<':'<<now->tm_min<<':'<<now->tm_sec; //std::cout<<"d21"<<std::endl; freqplots.at(maxplot).SetTitle(title.str().c_str()); freqplots.at(maxplot).GetXaxis()->SetTitle("ADC Value"); freqplots.at(maxplot).GetYaxis()->SetTitle("Frequency"); freqplots.at(maxplot).SetLineColor((maxplot%4)+1); freqplots.at(maxplot).Draw(); TLegend leg(0.8,0.4,1.0,0.7); //leg.SetHeader("The Legend Title"); //std::cout<<"d22"<<std::endl; for(int j=(i*4);j<(i*4)+4;j++){ //std::cout<<"d23"<<std::endl; std::stringstream legend; legend<<"Channel "<<j-(i*4); leg.AddEntry(&freqplots.at(j),legend.str().c_str(),"l"); freqplots.at(j).SetLineColor((j%4)+1); if(j==maxplot){;}//freqplots.at(i).Draw(); else freqplots.at(j).Draw("same"); } leg.Draw(); //std::cout<<"d24"<<std::endl; std::stringstream tmp; tmp<<outpath<<carddata->CardID<<"freq.jpg"; c1.SaveAs(tmp.str().c_str()); //std::cout<<"d25"<<std::endl; ///////find max tmporal plot for scaling ///temporal maxplot=0; maxvalue=0; //std::cout<<"i="<<i<<" (i*4)="<<(i*4)<<" (i*4)+4="<<(i*4)+4<<" size="<<freqplots.size()<<std::endl; for(int j=(i*4);j<(i*4)+4;j++){ //std::cout<<"d26"<<std::endl; if (temporalplots.at(j).GetMaximum()>maxvalue){ maxvalue=temporalplots.at(j).GetMaximum(); maxplot=j; } } //std::cout<<"d27"<<std::endl; //////// Find time and plot temporal plot t = time(0); // get time now now = localtime( & t ); std::stringstream title2; title2<<"Card "<<carddata->CardID<<" Temporal: "<<(now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday<<','<<now->tm_hour<<':'<<now->tm_min<<':'<<now->tm_sec; //std::cout<<"d28"<<std::endl; temporalplots.at(maxplot).SetTitle(title2.str().c_str()); temporalplots.at(maxplot).GetXaxis()->SetTitle("Samples"); temporalplots.at(maxplot).GetYaxis()->SetTitle("Volate (V)"); temporalplots.at(maxplot).SetLineColor((maxplot%4)+1); temporalplots.at(maxplot).Draw(); TLegend leg2(0.8,0.4,1.0,0.7); //std::cout<<"d29"<<std::endl; for(int j=(i*4);j<(i*4)+4;j++){ //std::cout<<"d30"<<std::endl; std::stringstream legend; legend<<"Channel "<<j-(i*4); leg2.AddEntry(&temporalplots.at(j),legend.str().c_str(),"l"); temporalplots.at(j).SetLineColor((j%4)+1); if(j==0){;} else temporalplots.at(j).Draw("same"); } //std::cout<<"d31"<<std::endl; leg2.Draw(); //std::cout<<"d6"<<std::endl; std::stringstream tmp2; tmp2<<outpath<<carddata->CardID<<"temporal.jpg"; c1.SaveAs(tmp2.str().c_str()); //std::cout<<"d32"<<std::endl; ///////plotting PED time and ped rms time ////// maxplot=0; maxvalue=0; for(int j=0;j<4;j++){ //std::cout<<"d26"<<std::endl; if ( PedTime[carddata->CardID].at(j).GetMaximum()>maxvalue){ maxvalue=PedTime[carddata->CardID].at(j).GetMaximum(); maxplot=j; } } t = time(0); // get time now now = localtime( & t ); title2.str(""); title2<<"Card "<<carddata->CardID<<" Pedistal Variation: "<<(now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday<<','<<now->tm_hour<<':'<<now->tm_min<<':'<<now->tm_sec; //std::cout<<"d28"<<std::endl; PedTime[carddata->CardID].at(maxplot).SetTitle(title2.str().c_str()); PedTime[carddata->CardID].at(maxplot).GetXaxis()->SetTitle("Samples"); PedTime[carddata->CardID].at(maxplot).GetYaxis()->SetTitle("ADC Value"); PedTime[carddata->CardID].at(maxplot).SetLineColor((maxplot%4)+1); PedTime[carddata->CardID].at(maxplot).Draw(); TLegend leg3(0.8,0.4,1.0,0.7); //std::cout<<"d29"<<std::endl; for(int j=0;j<4;j++){ //std::cout<<"d30"<<std::endl; std::stringstream legend; legend<<"Channel "<<j; leg3.AddEntry(&PedTime[carddata->CardID].at(j),legend.str().c_str(),"l"); PedTime[carddata->CardID].at(j).SetLineColor((j%4)+1); PedTime[carddata->CardID].at(j).Draw("same"); } //std::cout<<"d31"<<std::endl; leg3.Draw(); //std::cout<<"d6"<<std::endl; tmp2.str(""); tmp2<<outpath<<"plots2/"<<carddata->CardID<<"PedTime.jpg"; c1.SaveAs(tmp2.str().c_str()); PedRMSTime[carddata->CardID].at(0).Draw(); for (int channel=1;channel<4;channel++){ PedRMSTime[carddata->CardID].at(channel).Draw("same"); } tmp2.str(""); tmp2<<outpath<<"plots2/"<<carddata->CardID<<"PedRMSTime.jpg"; c1.SaveAs(tmp2.str().c_str()); delete carddata; } /// size i /* //std::cout<<"d4"<<std::endl; int maxplot=0; long maxvalue=0; for(int i=0;i<freqplots.size();i++){ if (freqplots.at(i).GetMaximum()>maxvalue){ maxvalue=freqplots.at(i).GetMaximum(); maxplot=i; } } freqplots.at(maxplot).SetLineColor(maxplot+1); freqplots.at(maxplot).Draw(); for(int i=0;i<freqplots.size();i++){ // Double_t scale = 1/freqplots.at(i).GetMaximum(); // freqplots.at(i).Scale(scale); freqplots.at(i).SetLineColor(i+1); if(i==maxplot);//freqplots.at(i).Draw(); else freqplots.at(i).Draw("same"); //freqplots.at(i).Scale((1.0/scale)); } std::cout<<"d5"<<std::endl; std::stringstream tmp; tmp<<outpath<<"freq.jpg"; c1.SaveAs(tmp.str().c_str()); for(int i=0;i<temporalplots.size();i++){ temporalplots.at(i).SetLineColor(i+1); if(i==0)temporalplots.at(i).Draw(); else temporalplots.at(i).Draw("same"); } std::cout<<"d6"<<std::endl; std::stringstream tmp2; tmp2<<outpath<<"temporal.jpg"; c1.SaveAs(tmp2.str().c_str()); */ //std::cout<<"d33"<<std::endl; /////////plot event display ///////// EventDisplay.Draw("COLZ"); std::stringstream tmp3; tmp3<<outpath<<"0EventDisplay.jpg"; c1.SaveAs(tmp3.str().c_str()); //std::cout<<"d34 ="<<mg.size()<<std::endl; /////////plot RMS display ///////// RMSDisplay.Draw("COLZ"); tmp3.str(""); tmp3<<outpath<<"0RMSDisplay.jpg"; c1.SaveAs(tmp3.str().c_str()); ///plot atempted 3d event display/////// tmp3.str(""); if(mg.size()>0) mg.at(0)->Draw(); for(int plots=1;plots<mg.size();plots++){ mg.at(plots)->Draw("same"); //std::cout<<"d35"<<std::endl; } tmp3<<outpath<<"0EventDisplay3D.jpg"; //c1.SaveAs(tmp3.str().c_str()); } else if(arg1=="Quit"){
void fillTree(TTree*& tree, TGraph*& graph, double& limit, unsigned int itype, std::map<double, std::string>& tanb_values, bool upper_exclusion, unsigned int verbosity) { double value=-99; double tanb_help=-99; unsigned int ibin=0; // fill graph with scanned points for(std::map<double, std::string>::const_iterator tanb = tanb_values.begin(); tanb!=tanb_values.end(); ++tanb){ value = singlePointLimit(tanb->second, tanb->first, itype, verbosity); if( value>0 ){ graph->SetPoint(ibin++, tanb->first, value); } tanb_help=tanb->first; } // determine smooth curve on graph for interpolation TSpline3* spline = new TSpline3("spline", graph, "r", 3., 10.); // linear polarisation func TF1 *fnc = 0; // determine all crossing points with y==1 std::vector<CrossPoint> points = crossPoints(graph); int dist = 1; bool filled = false; unsigned int np = 0; unsigned int steps = 10e6; if(points.size()>0) limit = graph->GetX()[upper_exclusion ? points.begin()->first : points.end()->first]; for(std::vector<CrossPoint>::const_reverse_iterator point = points.rbegin(); point!=points.rend(); ++point, ++np){ //for(std::vector<CrossPoint>::iterator point = points.begin(); point!=points.end(); ++point, ++np){ //double min = (point->first-dist)>0 ? graph->GetX()[point->first-dist] : graph->GetX()[0]; double min = (point->first)>0 ? graph->GetX()[point->first] : graph->GetX()[0]; double max = (point->first+dist)<graph->GetN() ? graph->GetX()[point->first+dist] : graph->GetX()[graph->GetN()-1]; //double y_min = (point->first-dist)>0 ? graph->GetY()[point->first-dist] : graph->GetY()[0]; double y_min = (point->first)>0 ? graph->GetY()[point->first] : graph->GetY()[0]; double y_max = (point->first+dist)<graph->GetN() ? graph->GetY()[point->first+dist] : graph->GetY()[graph->GetN()-1]; vector<double> crossing; crossing.push_back((min-max-y_max*min+y_min*max)/(y_min-y_max)); //double crossing; //crossing = (1.-y_min)/(y_max-y_min)*(max-min); double deltaM = -999.; double offset = min; double step_size = (max-min)/steps; for(unsigned int scan=0; scan<=steps; ++scan){ if(deltaM<0 || fabs(spline->Eval(offset+scan*step_size)-1.)<deltaM){ limit=offset+scan*step_size; deltaM=fabs(spline->Eval(offset+scan*step_size)-1.); } } std::cout << "****************************************************************" << std::endl; std::cout << "* [" << np+1 << "|" << point->second << "] asymptotic limit("; std::cout << limitType(itype) << ") :" << crossing[np] << " -- " << limit << " deltaM : " << deltaM; // if(((upper_exclusion && point->second) || (!upper_exclusion && !(point->second))) && !filled){ // //std::cout << "limit is taken from linear interpolation at the moment" << std::endl; // //limit = crossing; // std::cout << " [-->to file]"; filled=true; tree->Fill(); // } if(np==0){ fnc = new TF1("fnc", "[0]*x+[1]", min, max); fnc->SetParameter(0, (y_min-y_max)/(min-max)); fnc->SetParameter(1, (y_max*min-y_min*max)/(min-max)); std::cout << std::endl; std::cout << "limit is taken from linear interpolation at the moment" << std::endl; limit = crossing[np]; std::cout << limit << std::endl; std::cout << " [-->to file]"; filled=true; tree->Fill(); } std::cout << endl; std::cout << "****************************************************************" << std::endl; } // catch cases where no crossing point was found if(!filled){ if(value<1) { std::cout << "WARNING: no crossing found - all tanb values excluded: " << value << std::endl; if(itype == observed) { limit=3.00; } if(itype == plus_2sigma) { limit=5.00; } if(itype == plus_1sigma) { limit=4.00; } if(itype == expected) { limit=3.00; } if(itype == minus_1sigma) { limit=2.50; } if(itype == minus_2sigma) { limit=2.00; } tree->Fill(); } else { std::cout << "WARNING: no crossing found - no tanb value excluded: " << value << " -- " << tanb_help << std::endl; if(itype == observed) { limit=tanb_help*value; } if(itype == plus_2sigma) { limit=tanb_help*value; } if(itype == plus_1sigma) { limit=tanb_help*value; } if(itype == expected) { limit=tanb_help*value; } if(itype == minus_1sigma) { limit=tanb_help*value; } if(itype == minus_2sigma) { limit=tanb_help*value; } tree->Fill(); } } if( verbosity>0 ){ std::string monitor = std::string("SCAN-")+limitType(itype); TCanvas* canv = new TCanvas(monitor.c_str(), monitor.c_str(), 600, 600); TH1F* frame = canv->DrawFrame(graph->GetX()[0]-0.1, 0., graph->GetX()[graph->GetN()-1]+0.1, 10.); canv->SetGridx(1); canv->SetGridy(1); canv->cd(); graph->SetMarkerStyle(20.); graph->SetMarkerColor(kBlack); graph->SetMarkerSize(1.3); graph->Draw("P"); //spline->SetLineColor(kBlue); //spline->SetLineWidth(3.); //spline->Draw("same"); if(filled) fnc->SetLineColor(kRed); if(filled) fnc->SetLineWidth(3.); if(filled) fnc->Draw("same"); canv->Print(monitor.append(".png").c_str(), "png"); delete frame; delete canv; delete spline; if(filled) delete fnc; } return; }
void draw_variations_muidtrg_pp(int ieta, bool plotAll, double stamode, bool statonly=false) { // ieta = 0 (0-0.9), 1 (0.9-1.6), 2 (1.6-2.1), 3 (2.1-2.4) // plotAll: plot 100 variations for muid+trg if true, plot only +1/-1 sigma if false // stamode: 0 -> no STA correction, 1 -> correct only variations (for plotAll=false), 2 -> correct nominal and variations // statonly: false -> stat+syst variations, true -> stat only variations const char* statonly_str = statonly ? "_statonly" : ""; double eta; double ptmin = 0; if (ieta==0) {ptmin = 3.4; eta=0.3;} else if (ieta==1) {ptmin = 2.1; eta=1.2;} else if (ieta==2) {ptmin = 1.7; eta=1.9;} else {ptmin = 1.5; eta=2.3;} TCanvas *c1 = new TCanvas(); TH1F *haxes = new TH1F("haxes","haxes",10,0,20); haxes->GetYaxis()->SetRangeUser(0.8,1.5); haxes->GetXaxis()->SetTitle("p_{T}"); haxes->GetYaxis()->SetTitle("Correction"); haxes->Draw(); TLegend *tleg = new TLegend(0.55,0.5,0.9,0.83); tleg->SetFillStyle(0); tleg->SetFillColor(0); tleg->SetBorderSize(0); tleg->SetTextSize(0.035); if (ieta==0) tleg->SetHeader("MuId+Trg #eta^{#mu} #in [0.0, 0.9]"); else if (ieta==1) tleg->SetHeader("MuId+Trg #eta^{#mu} #in [0.9, 1.6]"); else if (ieta==2) tleg->SetHeader("MuId+Trg #eta^{#mu} #in [1.6, 2.1]"); else tleg->SetHeader("MuId+Trg #eta^{#mu} #in [2.1, 2.4]"); int istart, istep; if (plotAll) { istart = 100; istep = -1; } else { istart = -2; istep = 1; } for (int i=istart; i*istep<=0; i += istep) { TF1 *func = new TF1(Form("var_%i",i),Form("tnp_weight%s_muidtrg_pp(x,%f,%i)",statonly_str,eta,i),ptmin,20); if (stamode==2) func = new TF1(Form("var_%i",i),Form("tnp_weight%s_muidtrg_pp(x,%f,%i)*tnp_weight%s_sta_pp(x,%f,0)",statonly_str,eta,i,statonly_str,eta),ptmin,20); if (i==0) func->SetLineColor(kRed); else func->SetLineColor(kBlack); func->Draw("same"); if (i==0) { if (stamode==2) tleg->AddEntry(func,"nominal * STA","l"); else tleg->AddEntry(func,"nominal","l"); } else if (abs(i)==1) { if (stamode==2) tleg->AddEntry(func,"variation * STA","l"); else tleg->AddEntry(func,"variation","l"); } } if (stamode==1 && !plotAll) { TF1 *func1 = new TF1("var1_0",Form("tnp_weight%s_muidtrg_pp(x,%f,0)*tnp_weight%s_sta_pp(x,%f,0)",statonly_str,eta,statonly_str,eta),ptmin,20); func1->SetLineColor(kBlue); func1->Draw("same"); tleg->AddEntry(func1,"nominal * STA", "l"); TF1 *func2 = new TF1("var2_0",Form("tnp_weight%s_muidtrg_pp(x,%f,0)/tnp_weight%s_sta_pp(x,%f,0)",statonly_str,eta,statonly_str,eta),ptmin,20); func2->SetLineColor(kBlue); func2->Draw("same"); } tleg->Draw(); TLatex *lt1 = new TLatex(); lt1->SetNDC(); lt1->SetTextSize(0.05); lt1->DrawLatex(0.55,0.86,"pp #sqrt{s} = 2.76 TeV"); }
void testInterpolation (TGraph ** tg_sample_par, TString sample, int Npar) { //PG testing sets for the test TGraph ** tg_test_par = new TGraph * [7] ; // [parameter][mass] for (int k = 0 ; k < Npar ; ++k) tg_test_par[k] = new TGraph (4) ; TCanvas * c_merge = new TCanvas () ; bkg = (TH1F *) c_merge->DrawFrame (200, 0.0000001, 1500, 0.002) ; // c_merge->SetLogy () ; bkg->GetXaxis ()->SetTitle ("m_{WW}") ; bkg->GetYaxis ()->SetTitle ("signal") ; //PG loop on the point to be removed for (int iTest = 0 ; iTest < 5 ; ++iTest) { cout << " ==== iTest " << iTest << endl ; int iActualMass = 0 ; //PG fill the temporary graphs for (int iMass = 0 ; iMass < 5 ; ++iMass) { if (iMass == iTest) continue ; double x = 0 ; double y = 0 ; for (int k = 0 ; k < 7 ; ++k) { tg_sample_par[k]->GetPoint (iMass, x, y) ; tg_test_par[k]->SetPoint (iActualMass, x, y) ; } ++iActualMass ; } //PG fill the temporary graphs // plot the interpolation bkg->Draw () ; drawShapes (tg_test_par, Npar) ; // overlap the missing point double dummy = 0 ; double mass = 0 ; tg_sample_par[0]->GetPoint (iTest, mass, dummy) ; TF1 * func = new TF1 ("func",crystalBallLowHigh, 200, 2000, 7) ; TGraph * log_tg_this_sample_par0 = makeLog (tg_sample_par[0]) ; func->SetParameter (0, TMath::Exp (log_tg_this_sample_par0->Eval (mass))) ; for (int iPar = 1 ; iPar < Npar ; ++iPar) func->SetParameter (iPar, tg_sample_par[iPar]->Eval (mass)) ; func->SetLineColor (kRed) ; func->Draw ("same") ; // output // c_merge->SetLogy (1) ; // TString name = "test_interpol_log_" ; // name += sample ; name += "_" ; name += iTest ; name += ".pdf" ; // c_merge->Print (name, "pdf") ; TString name = "test_interpol_lin_" ; name += sample ; name += "_" ; name += iTest ; name += ".pdf" ; c_merge->SetLogy (0) ; c_merge->Print (name, "pdf") ; } //PG loop on the point to be removed return ; }
void read_scope_spect() { int i,j,k; //for(i=0;i<17;i++) { cin>>i; ifstream indata; sprintf(fileName,"F620130603-%d-%.1f-00000",i+1,hv[i]); // sprintf(fileName,"F6-21-73.9v-00000"); sprintf(buf1,"%s%s.txt",directory,fileName); indata.open(buf1,ios::in); if(!indata) { cout<<endl<<buf1<<" doesn't exist!!"<<endl<<endl; // exit(-1); continue; } else { int nCount; varMax=0; varMin=nMax; indxMin=nMax; indxMax=0; nCount=0; while(!indata.eof()) { indata>>indx1>>var1; //cout<<indx1<<" "<<var1<<endl; if(indxMin>indx1) indxMin=indx1; if(indxMax<indx1) indxMax=indx1; var[nCount]=var1*1e9; indx[nCount]=indx1; if(varMax<var[nCount]) varMax=var[nCount]; if(varMin>var[nCount]) varMin=var[nCount]; nCount++; } //h1->Write(); indata.close(); //file1->Close(); varbuf=varMax-varMin; varMax=varMax+0.025*varbuf; varMin=varMin-0.025*varbuf; //TH1D *spec = new TH1D("SiPM","Spectrum",nBins,varMin,varMax); //TH1D *spec = new TH1D("SiPM","Spectrum",nBins,tLimits[0],tLimits[1]); // TGraph *spec = new TGraph(nCount,indx,var); // for(j=0;j<nCount;j++) { // spec->Fill(var[j]); // } gStyle->SetOptFit(1111); gStyle->SetOptStat(1111); double mean,sigma,para[16],err; //////////////output fit result to txt ofstream outResult; outResult.open(Form("%sfitResult.txt",directory),ios::app); cout<<fileName<<endl; outResult<<"######## file: "<<fileName<<".txt #######"<<"\n"; ///////////////////////////////// int nBins,nFill; TH1D *spec; TCanvas *c1 = new TCanvas(fileName,fileName,10,10,700,600); for(k=0;k<3;k++) { nBins= (tLimits[1]-tLimits[0])*1.0*nNumBins[k]; spec = new TH1D("SiPM","Spectrum",nBins,tLimits[0],tLimits[1]); nFill=0; for(j=0;j<nCount;j++) { if(var[j]>=tLimits[0] && var[j]<=tLimits[1]) { spec->Fill(var[j]); nFill++; } if(nFill==nFillMax) break; } c1->Divide(2,2); for(j=0;j<4;j++) { c1->cd(j+1); spec->Draw(); // spec->Draw("AB"); // spec->SetFillColor(38); // spec->GetXaxis()->SetLimits(tLimits[0],tLimits[1]); spec->GetXaxis()->SetTitle("t [ns]"); // spec->GetXaxis()->SetTitle("Maximum of SiPM signals [mV]"); spec->GetXaxis()->CenterTitle(); spec->GetYaxis()->SetTitle("Counts"); spec->GetYaxis()->CenterTitle(); spec->SetTitle("CTR_2_STiC"); spec->Fit("gaus","NQ"); gaus->GetParameters(¶[0]); gaus->SetRange(para[1]-nSigma[j]*para[2], para[1]+nSigma[j]*para[2]); spec->Fit("gaus","NQR"); gaus->GetParameters(¶[0]); gaus->SetRange(para[1]-nSigma[j]*para[2], para[1]+nSigma[j]*para[2]); spec->Fit("gaus","NQR"); gaus->GetParameters(¶[0]); gaus->SetRange(para[1]-nSigma[j]*para[2], para[1]+nSigma[j]*para[2]); spec->Fit("gaus","QR"); //spec->Fit("gaus"); gaus->GetParameters(¶[0]); err=gaus->GetParError(2); cout<<nNumBins[k]<<" "<<nSigma[j]<<" FWHM: "<<para[2]*2.35<<"\t"<<err*2.35<<"\n"; TF1 *ftemp = new TF1("ftemp","[0]*exp(-0.5*((x-[1])/[2])**2)",tLimits[0],tLimits[1]); //TF1 *ftemp = new TF1("ftemp","[0]*exp(-0.5*((x-[1])/[2])**2)",varMin,varMax); ftemp->SetParameters(para[0],para[1],para[2]); ftemp->SetLineWidth(3); ftemp->SetLineStyle(2); ftemp->SetLineColor(2); ftemp->Draw("same"); c1->cd(j+1)->Update(); outResult<<nSigma[j]<<' '<<tLimits[0]<<' '<<tLimits[1]<<" "<<nBins<<"\n"; outResult<<"Sigma[ps] Err_of_Sigma[ps] CTR_FWHM Err_of_FWHM"<<"\n"; outResult<<para[2]<<"\t"<<err<<"\t"<<para[2]*2.35<<"\t"<<err*2.35<<"\n\n"; } wait(); c1->Clear(); } c1->Close(); // ///////////save histogram to .root file // TFile *fHist = new TFile(Form("%s%s-hist.root",directory,fileName),"recreate"); // c1->Write(); // fHist->ls(); // fHist->Close(); // ////////// ////////close output file outResult<<"\n\n"; outResult.close(); ///////////////////////// // wait(); // c1->Close(); } //} }
// Determine sensitivity to tracker dynamic inefficiency // by studying ratio of jet responses in Runs G and F (and BCD / F, E / F) void drawAvsB() { setTDRStyle(); string epocha = "BCD";//"BCD";//"H";//"F";//"BCD";//"F";//"E";//"BCD";//"F"; string epochb = "GH";//"G";//"BCD";//"G";//"E";//"E";//"F";//"G"; // Add the rest as well string epocha2 = "";//"EF"; string epochb2 = "";//"G"; string type = "data"; vector<string> methods; methods.push_back("mpfchs1"); methods.push_back("ptchs"); bool nozjptb = false; bool nogjmpf = false; bool nogjptb = true; bool mjvsjes = false; vector<string> samples; samples.push_back("zeejet"); samples.push_back("zmmjet"); samples.push_back("gamjet"); //samples.push_back("multijet"); cout << "draw"<<epocha<<"vs"<<epochb<<endl; const char *ct = type.c_str(); const char *pa = epocha.c_str(); const char *pb = epochb.c_str(); const char *pa2 = epocha2.c_str(); const char *pb2 = epochb2.c_str(); TFile *fg = new TFile(Form("rootfiles/jecdata%s.root",pb),"READ"); assert(fg && !fg->IsZombie()); TFile *ff = new TFile(Form("rootfiles/jecdata%s.root",pa),"READ"); assert(ff && !ff->IsZombie()); TFile *fg2(0), *ff2(0); if (epochb2!="") fg2 = new TFile(Form("rootfiles/jecdata%s.root",pb2),"READ"); if (epocha2!="") ff2 = new TFile(Form("rootfiles/jecdata%s.root",pa2),"READ"); TH1D *h = new TH1D("h", Form(";p_{T,ref} (GeV);%s ratio (%s / %s)", (type=="ratio" ? "Data/MC" : type=="data" ? "Data/data" : "MC/MC"), (epocha + (epocha2!="" ? "+"+epocha2 : "")).c_str(), (epochb + (epochb2!="" ? "+"+epochb2 : "")).c_str()), 3470,30,3500); h->SetMinimum(0.90); h->SetMaximum(1.15); h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); if (epocha=="F" && epochb=="G") lumi_13TeV = "Run2016F+G, 3.1+7.1 fb^{-1}"; if (epocha=="BCD" && epochb=="G") lumi_13TeV = "Run2016BCD+H, 12.9+8.8 fb^{-1}"; if (epocha=="BCD" && epochb=="G") lumi_13TeV = "Run2016BCD+FearlyGH, 12.9+16.8 fb^{-1}"; if (epocha=="BCD" && epochb=="F") lumi_13TeV = "Run2016BCD+F, 13+3.1 fb^{-1}"; if (epocha=="BCD" && epochb=="E") lumi_13TeV = "Run2016BCD+E, 13+4.0 fb^{-1}"; if (epocha=="E" && epochb=="F") lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}"; if (epocha=="F" && epochb=="E") lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}"; if ((epocha=="BCDEF" && epochb=="GH") || (epocha=="BCD" && epocha2=="EF" && epochb=="H" && epochb2=="G")) lumi_13TeV = "Run2016BCDEF+GH, 19.7+16.8 fb^{-1}"; if (epocha=="EF" && epochb=="BCD") lumi_13TeV = "Run2016BCD+EF, 12.9+6.8 fb^{-1}"; if (epocha=="H" && epochb=="G") lumi_13TeV = "Run2016G+H, 8.0+8.8 fb^{-1}"; if ((epocha=="BCD" && epocha2=="EF" && epochb=="G" && epochb2=="H")) lumi_13TeV = "Run2016BCDFearly+FlateGH, 19.7+16.8 fb^{-1}"; if ((epocha=="BCD" && epocha2=="" && ((epochb=="GH" && epochb2=="") || (epochb=="G" && epochb2=="H")))) lumi_13TeV = "Run2016BCD+FlateGH, 12.9+16.8 fb^{-1}"; if ((epocha=="EF" && epocha2=="" && ((epochb=="GH" && epochb2=="") || (epochb=="G" && epochb2=="H")))) lumi_13TeV = "Run2016EF+FlateGH, 6.8+16.8 fb^{-1}"; if ((epocha=="EF" && epocha2=="" && epochb=="G" && epochb2=="H")) lumi_13TeV = "Run2016EFearly+FlateGH, 6.8+16.8 fb^{-1}"; TCanvas *c1 = tdrCanvas("c1",h,4,11,true); c1->SetLogx(); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(0.045); TMultiGraph *mg = new TMultiGraph(); string s = "draw"+epocha+(epocha2!="" ? "p" + epocha2 : "") +"vs"+epochb+(epochb2!="" ? "p" + epochb2 : ""); TGraphErrors *gmjb(0), *gmpf(0); for (unsigned int im = 0; im != methods.size(); ++im) { const char *cm = methods[im].c_str(); tex->DrawLatex(0.20,0.75-0.06*im,cm); s += "_" + methods[im]; for (unsigned int is = 0; is != samples.size(); ++is) { const char *cs = samples[is].c_str(); TGraphErrors *gg = (TGraphErrors*)fg->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); cout << cm << " " << cs << endl << flush; assert(gg); if (fg2) { TGraphErrors *gg2 = (TGraphErrors*)fg2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gg2); gg = addGraph(gg,gg2); } TGraphErrors *gf = (TGraphErrors*)ff->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gf); if (ff2) { TGraphErrors *gf2 = (TGraphErrors*)ff2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gf2); gf = addGraph(gf,gf2); } if (!(gf->GetN()==gg->GetN())) { // Remove highest pT point is that is the offender (BCD vs GH) if (gg->GetN()>gf->GetN() && fabs(gg->GetX()[gg->GetN()-1]/gf->GetX()[gf->GetN()-1]-1)>0.1 && fabs(gg->GetX()[gg->GetN()-2]/gf->GetX()[gf->GetN()-1]-1)<0.1) { cout << "Remove point B(N-1)" << endl; gg->RemovePoint(gg->GetN()-1); } else { cout << "sample " << samples[is] << " method " << methods[im] << " gf->N: " << gf->GetN() << " gg->N: " << gg->GetN() << endl; cout << " x_gf(N-1)=" << gf->GetX()[gf->GetN()-1] << " x_gg(N-1)=" << gg->GetX()[gg->GetN()-1] << " x_gg(N-2)=" << gg->GetX()[gg->GetN()-2] << endl; } assert(gf->GetN()==gg->GetN()); } TGraphErrors *g = (TGraphErrors*)gg->Clone(Form("ge_%s_%s",cm,cs)); for (int i = 0; i != g->GetN(); ++i) { double yg = gg->GetY()[i]; double yf = gf->GetY()[i]; g->SetPoint(i, gg->GetX()[i], yf / yg); double ex = gg->GetEX()[i]; double eg = gg->GetEY()[i]; double ef = gf->GetEY()[i]; g->SetPointError(i, ex, yf/yg*sqrt(pow(eg/yg,2)+pow(ef/yf,2))); } //g->Draw(is==0 ? "AP" : "SAMEP"); g->SetLineWidth(1+is); g->Draw("SAMEPZ"); if (samples[is]=="gamjet" && methods[im]=="mpfchs1" && nogjmpf) { tex->SetTextColor(kBlue); tex->DrawLatex(0.20,0.63,"#gamma+jet MPF excl. from fit"); tex->SetTextColor(kBlack); } else if (samples[is]=="gamjet" && methods[im]=="ptchs" && nogjptb) { tex->SetTextColor(kBlue); tex->DrawLatex(0.20,0.63,"#gamma+jet p_{T}^{bal} excl. from fit"); tex->SetTextColor(kBlack); } else if ((samples[is]=="zmmjet" || samples[is]=="zeejet") && methods[im]=="ptchs" && nozjptb) { tex->SetTextColor(kRed); tex->DrawLatex(0.20,0.63,"Z+jet p_{T}^{bal} excl. from fit"); tex->SetTextColor(kBlack); } else if (samples[is]=="multijet") { g->SetMarkerColor(kGray+1); g->SetLineColor(kGray+1); if (methods[im]=="ptchs") gmjb = g; if (methods[im]=="mpfchs1") gmpf = g; } else mg->Add(g); } // for is } // for im if (nogjmpf) s += "_nogjmpf"; if (nogjptb) s += "_nogptb"; if (nozjptb) s += "_nozptb"; if (mjvsjes) { s += "_mjvsjes"; tex->SetTextColor(kBlack); tex->DrawLatex(0.20,0.58,"Multijet vs JES fit"); } TF1 *fjes = new TF1("fjes",jesFit,30,2200,2); fjes->SetParameters(0.99,0.05); mg->Fit(fjes,"RN"); fjes->SetLineColor(kBlack); fjes->SetLineStyle(kDashed); fjes->SetLineWidth(2); fjes->SetRange(10.,3500.); fjes->Draw("SAME"); //TF1 *ft = new TF1("ft","1-[0]-[1]*pow(x,[2]) + ([3]+[4]*log(x))/x",30,2200); //ft->SetParameters(0,0.05,-0.5,1,0.1); //ft->FixParameter(3,0); // Logarithmic sigmoid //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-log(abs([1])))" // "/(log(abs([2])+abs([1]))-log(abs([1])))))", 30,2200); //ft->SetParameters(0.98, 150, 50); TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))",30,2200); //ft->SetParameters(0.98,log(145),log(190)-log(145)); //ft->SetParameters(0.982,4.967,0.271); //ft->SetParameters(0.976,5.040,0.370); // ENDCAP //ft->SetParameters(0.985,5.0,0.3); ft->SetParameters(0.985,5.025,0.3); //ft->FixParameter(1,5.03); // semi-weighted average of BCD and EF //ft->FixParameter(2,0.395); // combined fit to BCD+EF / G+H // ( 12.9*5.055+6.8*5.000)/(12.9+6.8) ft->FixParameter(1,5.036); // semi-weighted average of BCD/GH and EF/GH // ( 12.9*0.344 + 6.8*0.455)/(12.9+6.8) ft->FixParameter(2,0.391); // combined fit to BCD+EF / GH // Log-sigmoid + powerlaw //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))" // "*(1-[3]*pow(x,[4]))",30,2200); //ft->SetParameters(0.982,4.967,0.271,0.1,-0.2); // Double powerlaw //TF1 *ft = new TF1("ft","[4]-[0]*pow(x,[1])-[2]*pow(x,[3])",30,2200); //ft->SetParameters(0.05,-0.15,0.01,-0.3,1); mg->Fit(ft,"RN"); ft->SetLineColor(kBlue); ft->SetLineWidth(2); ft->SetRange(10.,3500.); ft->Draw("SAME"); // Map multijet with response ratio if (gmpf) { // we have multijet available TGraphErrors *gmpf2 = (TGraphErrors*)gmpf->Clone("gmpf2"); gmpf2->SetMarkerColor(kBlack);//kGray+1); gmpf2->SetLineColor(kBlack);//kGray+1); for (int i = 0; i != gmpf->GetN(); ++i) { if (mjvsjes) { gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i], fjes->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]); gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i], gmpf->GetEY()[i]); } else { gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i], ft->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]); gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i], gmpf->GetEY()[i]); } } gmpf2->Draw("SAMEPz"); } // multijet tex->SetTextColor(kBlue); tex->DrawLatex(0.50,0.85,Form("#chi^{2} / NDF = %1.1f / %d", ft->GetChisquare(), ft->GetNDF())); tex->SetTextColor(kBlack); tex->SetTextSize(0.040); tex->DrawLatex(0.50,0.80,Form("(#chi^{2} / NDF = %1.1f / %d)", fjes->GetChisquare(), fjes->GetNDF())); tex->SetTextColor(kBlue-9); tex->SetTextSize(0.030); tex->DrawLatex(0.20,0.25,ft->GetExpFormula()); tex->DrawLatex(0.20,0.20, Form("p_{0}=%1.3f#pm%1.3f" ", p_{1}=%1.3f#pm%1.3f" ", p_{2}=%1.3f#pm%1.3f", ft->GetParameter(0),ft->GetParError(0), ft->GetParameter(1),ft->GetParError(1), ft->GetParameter(2),ft->GetParError(2))); if (ft->GetNpar()>3) tex->DrawLatex(0.20,0.17, Form("p_{3}=%1.3f#pm%1.3f" ", p_{4}=%1.3f#pm%1.3f", ft->GetParameter(3),ft->GetParError(3), ft->GetParameter(4),ft->GetParError(4))); c1->SaveAs(Form("pdf/%s.pdf",s.c_str())); for (int i = 0; i != ft->GetNpar(); ++i) { cout << Form("%s%1.4g",i==0 ? "{" : ", ",ft->GetParameter(i)); } cout << "}" << endl; }
void doCarlosPlots() { TCanvas *c1 = new TCanvas("c1","Luminosity",200,10,700,500); // c1->SetFillColor(42); c1->SetGrid(); // c1->GetFrame()->SetFillColor(21); // c1->GetFrame()->SetBorderSize(12); const Int_t n = 6; Float_t x[n] = {0., 28., 54., 74., 91., 100.}; // Float_t y[n] = {8.0E29, 3.4E30, 2.5E31, 4.9E31, 5.1E31, 1.4E32}; Float_t y[n] = {8.0E29, 3.4E30, 2.5E31, 4.9E31, 5.1E31, 6.278E31}; Float_t ex[n] = {.0001,.0001,.0001,.0001,.0001,.0001}; Float_t ey[n] = {0.,0.,0.,0.,0.,0.}; Float_t y2[n] = {0., 2., 15., 40.,70.,99.7}; Float_t xd[2] = {0., 100.}; Float_t yd[2] = {-10000.,1500000.}; Float_t yd2[2] = {0.001,0.3}; Float_t exd[n] = {.0001,.0001}; Float_t eyd[n] = {0.,0.}; TGraphErrors *gr3 = new TGraphErrors(n,x,y,ex,ey); gr3->SetMarkerColor(2); gr3->SetLineColor(2); gr3->SetLineWidth(3); gr3->SetMarkerStyle(20); gr3->SetMinimum(-2.E30); gr3->GetXaxis()->SetTitle("Time (days)"); gr3->GetYaxis()->SetTitle("L_{inst} (cm^{-2} s^{-1})"); gr3->Draw("ALP"); TLine *hline = new TLine(-10.,1E31,36.,1E31); hline->SetLineColor(4); hline->SetLineWidth(3); hline->Draw("SAME"); TLine *vline = new TLine(36.,-2E30,36.,1E31); vline->SetLineColor(4); vline->SetLineWidth(3); vline->Draw("SAME"); c1->Update(); c1->SaveAs("LumiInst.gif"); TGraphErrors *gr2 = new TGraphErrors(n,x,y2,ex,ey); gr2->SetMarkerColor(2); gr2->SetMinimum(-5.0); gr2->SetMaximum(110.0); gr2->SetMarkerStyle(20); gr2->GetXaxis()->SetTitle("Time (days)"); gr2->GetYaxis()->SetTitle("L_{integ} (pb^{-1})"); gr2->Draw("AP"); TF1 *ftotal = new TF1("ftotal","myFunc(x)",0.,101.); ftotal->SetLineWidth(3); ftotal->SetLineColor(2); ftotal->Draw("SAME"); TLine *hline2 = new TLine(-10.,3.85,36.,3.85); hline2->SetLineColor(4); hline2->SetLineWidth(3); hline2->Draw("SAME"); TLine *vline2 = new TLine(36.,-5.0,36.,3.85); vline2->SetLineColor(4); vline2->SetLineWidth(3); vline2->Draw("SAME"); c1->Update(); c1->SaveAs("LumiInteg.gif"); c1->SetLogy(); c1->Update(); c1->SaveAs("LumiIntegLog.gif"); TCanvas *c2 = new TCanvas("c2","Events",300,100,700,500); c2->cd(); c2->SetGrid(); TGraphErrors *gr4 = new TGraphErrors(2,xd,yd,exd,eyd); // DUMMY gr4->SetMarkerColor(kWhite); gr4->GetXaxis()->SetTitle("Time (days)"); gr4->GetYaxis()->SetTitle("N (prompt J/#psi reco)"); TLine *vline3 = new TLine(36.,-20000.0,36.,900000.); // MENU CHANGE vline3->SetLineColor(kMagenta); vline3->SetLineStyle(kDashed); vline3->SetLineWidth(2); /// FUNCTIONS: HLTMu3 TF1 *fhighHLTMu3 = new TF1("fhighHLTMu3","23887*myFunc(x)",0.,36.); fhighHLTMu3->SetLineWidth(4); fhighHLTMu3->SetLineColor(2); TF1 *fmediumHLTMu3 = new TF1("fmediumHLTMu3","30993*myFunc(x)",0.,36.); fmediumHLTMu3->SetLineWidth(2); fmediumHLTMu3->SetLineColor(4); TF1 *flowHLTMu3 = new TF1("flowHLTMu3","66119*myFunc(x)",0.,36.); flowHLTMu3->SetLineWidth(2); flowHLTMu3->SetLineColor(3); TF1 *ftotalHLTMu3 = new TF1("ftotalHLTMu3","121000*myFunc(x)",0.,36.); ftotalHLTMu3->SetLineWidth(4); ftotalHLTMu3->SetLineColor(1); /// /// FUNCTIONS: HLTMu5 TF1 *fhighHLTMu5 = new TF1("fhighHLTMu5","491*myFunc(x)+90309",36.,100.); fhighHLTMu5->SetLineWidth(4); fhighHLTMu5->SetLineColor(2); TF1 *fmediumHLTMu5 = new TF1("fmediumHLTMu5","475*myFunc(x)+117799",36.,100.); fmediumHLTMu5->SetLineWidth(2); fmediumHLTMu5->SetLineColor(4); TF1 *flowHLTMu5 = new TF1("flowHLTMu5","1112*myFunc(x)+250927",36.,100.); flowHLTMu5->SetLineWidth(2); flowHLTMu5->SetLineColor(3); TF1 *ftotalHLTMu5 = new TF1("ftotalHLTMu5","2078*myFunc(x)+459038",36.,100.); ftotalHLTMu5->SetLineWidth(4); ftotalHLTMu5->SetLineColor(1); /// /// FUNCTIONS: HLTMu9 TF1 *fhighHLTMu9 = new TF1("fhighHLTMu9","2430*myFunc(x)+82824",36.,100.); fhighHLTMu9->SetLineWidth(4); fhighHLTMu9->SetLineColor(2); TF1 *fmediumHLTMu9 = new TF1("fmediumHLTMu9","1401*myFunc(x)+114225",36.,100.); fmediumHLTMu9->SetLineWidth(2); fmediumHLTMu9->SetLineColor(4); TF1 *flowHLTMu9 = new TF1("flowHLTMu9","2833*myFunc(x)+244283",36.,100.); flowHLTMu9->SetLineWidth(2); flowHLTMu9->SetLineColor(3); TF1 *ftotalHLTMu9 = new TF1("ftotalHLTMu9","6664*myFunc(x)+441337",36.,100.); ftotalHLTMu9->SetLineWidth(4); ftotalHLTMu9->SetLineColor(1); /// /// FUNCTIONS: HLT2Mu3 TF1 *fhighHLT2Mu3 = new TF1("fhighHLT2Mu3","10271*myFunc(x)+52258",36.,100.); fhighHLT2Mu3->SetLineWidth(4); fhighHLT2Mu3->SetLineColor(2); TF1 *fmediumHLT2Mu3 = new TF1("fmediumHLT2Mu3","1157*myFunc(x)+115167",36.,100.); fmediumHLT2Mu3->SetLineWidth(2); fmediumHLT2Mu3->SetLineColor(4); TF1 *flowHLT2Mu3 = new TF1("flowHLT2Mu3","52*myFunc(x)+255122",36.,100.); flowHLT2Mu3->SetLineWidth(2); flowHLT2Mu3->SetLineColor(3); TF1 *ftotalHLT2Mu3 = new TF1("ftotalHLT2Mu3","11480*myFunc(x)+422747",36.,100.); ftotalHLT2Mu3->SetLineWidth(4); ftotalHLT2Mu3->SetLineColor(1); /// /// FIRST PLOT: HLTMu3 + HLTMu5 gr4->Draw("AP"); fhighHLTMu3->Draw("SAME"); fmediumHLTMu3->Draw("SAME"); flowHLTMu3->Draw("SAME"); ftotalHLTMu3->Draw("SAME"); fhighHLTMu5->Draw("SAME"); fmediumHLTMu5->Draw("SAME"); flowHLTMu5->Draw("SAME"); ftotalHLTMu5->Draw("SAME"); vline3->Draw("SAME"); // LEGENDS leg = new TLegend(0.20,0.65,0.60,0.9); leg->AddEntry(fhighHLTMu3,"2 global muons","l"); leg->AddEntry(fmediumHLTMu3,"1 global + 1 tracker muon","l"); leg->AddEntry(flowHLTMu3,"1 global + 1 calo muon","l"); leg->AddEntry(ftotalHLTMu3,"all muons","l"); leg->AddEntry(vline3,"Trigger menu switch","l"); leg->Draw("SAME"); hltmu3 = new TPaveLabel(-5.,400000.,20.,550000.,"HLT_Mu3 (1x1)"); hltmu3->SetTextColor(kMagenta); hltmu3->Draw("SAME"); hltmu5 = new TPaveLabel(65.,1100000.,95.,1250000.,"HLT_Mu5 (25x1)"); hltmu5->SetTextColor(kMagenta); hltmu5->Draw("SAME"); c2->Update(); c2->SaveAs("Njpsi_Mu3Mu5.gif"); /// SECOND PLOT: HLTMu3 + HLTMu9 gr4->Draw("AP"); fhighHLTMu3->Draw("SAME"); fmediumHLTMu3->Draw("SAME"); flowHLTMu3->Draw("SAME"); ftotalHLTMu3->Draw("SAME"); fhighHLTMu9->Draw("SAME"); fmediumHLTMu9->Draw("SAME"); flowHLTMu9->Draw("SAME"); ftotalHLTMu9->Draw("SAME"); vline3->Draw("SAME"); // LEGENDS leg->Draw("SAME"); hltmu3->Draw("SAME"); hltmu9 = new TPaveLabel(65.,1100000.,90.,1250000.,"HLT_Mu9 (1x1)"); hltmu9->SetTextColor(kMagenta); hltmu9->Draw("SAME"); c2->Update(); c2->SaveAs("Njpsi_Mu3Mu9.gif"); /// THIRD PLOT: HLTMu3 + HLT2Mu3 gr4->Draw("AP"); fhighHLTMu3->Draw("SAME"); fmediumHLTMu3->Draw("SAME"); flowHLTMu3->Draw("SAME"); ftotalHLTMu3->Draw("SAME"); fhighHLT2Mu3->Draw("SAME"); fmediumHLT2Mu3->Draw("SAME"); flowHLT2Mu3->Draw("SAME"); ftotalHLT2Mu3->Draw("SAME"); vline3->Draw("SAME"); // LEGENDS leg->Draw("SAME"); hltmu3->Draw("SAME"); hltmu9 = new TPaveLabel(60.,1200000.,87.,1350000.,"HLT_2Mu3 (1x1)"); hltmu9->SetTextColor(kMagenta); hltmu9->Draw("SAME"); c2->Update(); c2->SaveAs("Njpsi_Mu32Mu3.gif"); // S/B TCanvas *c3 = new TCanvas("c3","Events",500,300,700,500); c3->cd(); c3->SetGrid(); c3->SetLogy(); TGraphErrors *grsb4 = new TGraphErrors(2,xd,yd2,exd,eyd); // DUMMY grsb4->SetMarkerColor(kWhite); grsb4->GetXaxis()->SetTitle("Time (days)"); grsb4->GetYaxis()->SetTitle("sqrt(S+B)/S (prompt J/#psi reco)"); TLine *vline6 = new TLine(36.,0.0,36.,0.3); // MENU CHANGE vline6->SetLineColor(kMagenta); vline6->SetLineStyle(kDashed); vline6->SetLineWidth(2); /// FUNCTIONS: HLTMu3 TF1 *sbhighHLTMu3 = new TF1("sbhighHLTMu3","sqrt(31649*myFunc(x))/(23887*myFunc(x))",0.,36.); sbhighHLTMu3->SetLineWidth(4); sbhighHLTMu3->SetLineColor(2); TF1 *sbmediumHLTMu3 = new TF1("sbmediumHLTMu3","sqrt(215502*myFunc(x))/(30993*myFunc(x))",0.,36.); sbmediumHLTMu3->SetLineWidth(2); sbmediumHLTMu3->SetLineColor(4); TF1 *sblowHLTMu3 = new TF1("sblowHLTMu3","sqrt(493892*myFunc(x))/(66119*myFunc(x))",0.,36.); sblowHLTMu3->SetLineWidth(2); sblowHLTMu3->SetLineColor(3); TF1 *sbtotalHLTMu3 = new TF1("sbtotalHLTMu3","sqrt(741043*myFunc(x))/(121000*myFunc(x))",0.,36.); sbtotalHLTMu3->SetLineWidth(4); sbtotalHLTMu3->SetLineColor(1); /// /// FUNCTIONS: HLTMu5 TF1 *sbhighHLTMu5 = new TF1("sbhighHLTMu5","sqrt(636*myFunc(x)+119747)/(491*myFunc(x)+90309)",36.,100.); sbhighHLTMu5->SetLineWidth(4); sbhighHLTMu5->SetLineColor(2); TF1 *sbmediumHLTMu5 = new TF1("sbmediumHLTMu5","sqrt(3640*myFunc(x)+821259)/(475*myFunc(x)+117799)",36.,100.); sbmediumHLTMu5->SetLineWidth(2); sbmediumHLTMu5->SetLineColor(4); TF1 *sblowHLTMu5 = new TF1("sblowHLTMu5","sqrt(7050*myFunc(x)+1674140)/(1112*myFunc(x)+250927)",36.,100.); sblowHLTMu5->SetLineWidth(2); sblowHLTMu5->SetLineColor(3); TF1 *sbtotalHLTMu5 = new TF1("sbtotalHLTMu5","sqrt(11326*myFunc(x)+2615146)/(2078*myFunc(x)+459038)",36.,100.); sbtotalHLTMu5->SetLineWidth(4); sbtotalHLTMu5->SetLineColor(1); /// /// FUNCTIONS: HLTMu9 TF1 *sbhighHLTMu9 = new TF1("sbhighHLTMu9","sqrt(3339*myFunc(x)+109315)/(2430*myFunc(x)+82824)",36.,100.); sbhighHLTMu9->SetLineWidth(4); sbhighHLTMu9->SetLineColor(2); TF1 *sbmediumHLTMu9 = new TF1("sbmediumHLTMu9","sqrt(17310*myFunc(x)+768495)/(1401*myFunc(x)+114225)",36.,100.); sbmediumHLTMu9->SetLineWidth(2); sbmediumHLTMu9->SetLineColor(4); TF1 *sblowHLTMu9 = new TF1("sblowHLTMu9","sqrt(12969*myFunc(x)+1856362)/(2833*myFunc(x)+244283)",36.,100.); sblowHLTMu9->SetLineWidth(2); sblowHLTMu9->SetLineColor(3); TF1 *sbtotalHLTMu9 = new TF1("sbtotalHLTMu9","sqrt(33438*myFunc(x)+2734172)/(6664*myFunc(x)+441337)",36.,100.); sbtotalHLTMu9->SetLineWidth(4); sbtotalHLTMu9->SetLineColor(1); /// /// FUNCTIONS: HLT2Mu3 TF1 *sbhighHLT2Mu3 = new TF1("sbhighHLT2Mu3","sqrt(12498*myFunc(x)+73661)/(10271*myFunc(x)+52258)",36.,100.); sbhighHLT2Mu3->SetLineWidth(4); sbhighHLT2Mu3->SetLineColor(2); TF1 *sbmediumHLT2Mu3 = new TF1("sbmediumHLT2Mu3","sqrt(6702*myFunc(x)+809442)/(1157*myFunc(x)+115167)",36.,100.); sbmediumHLT2Mu3->SetLineWidth(2); sbmediumHLT2Mu3->SetLineColor(4); TF1 *sblowHLT2Mu3 = new TF1("sblowHLT2Mu3","sqrt(5233*myFunc(x)+1886327)/(52*myFunc(x)+255122)",36.,100.); sblowHLT2Mu3->SetLineWidth(2); sblowHLT2Mu3->SetLineColor(3); TF1 *sbtotalHLT2Mu3 = new TF1("sbtotalHLT2Mu3","sqrt(24433*myFunc(x)+2769430)/(11480*myFunc(x)+422747)",36.,100.); sbtotalHLT2Mu3->SetLineWidth(4); sbtotalHLT2Mu3->SetLineColor(1); /// /// FIRST PLOT: HLTMu3 + HLTMu5 grsb4->Draw("AP"); sbhighHLTMu3->Draw("SAME"); sbmediumHLTMu3->Draw("SAME"); sblowHLTMu3->Draw("SAME"); sbtotalHLTMu3->Draw("SAME"); sbhighHLTMu5->Draw("SAME"); sbmediumHLTMu5->Draw("SAME"); sblowHLTMu5->Draw("SAME"); sbtotalHLTMu5->Draw("SAME"); vline6->Draw("SAME"); // LEGENDS leg = new TLegend(0.50,0.65,0.90,0.9); leg->AddEntry(sbhighHLTMu3,"2 global muons","l"); leg->AddEntry(sbmediumHLTMu3,"1 global + 1 tracker muon","l"); leg->AddEntry(sblowHLTMu3,"1 global + 1 calo muon","l"); leg->AddEntry(sbtotalHLTMu3,"all muons","l"); leg->AddEntry(vline6,"Trigger menu switch","l"); leg->Draw("SAME"); hltmu3 = new TPaveLabel(-5.,0.002,20.,0.004,"HLT_Mu3 (1x1)"); hltmu3->SetTextColor(kMagenta); hltmu3->Draw("SAME"); hltmu5 = new TPaveLabel(65.,0.02,95.,0.03,"HLT_Mu5 (25x1)"); hltmu5->SetTextColor(kMagenta); hltmu5->Draw("SAME"); c3->Update(); c3->SaveAs("SBjpsi_Mu3Mu5.gif"); /// SECOND PLOT: HLTMu3 + HLTMu9 grsb4->Draw("AP"); sbhighHLTMu3->Draw("SAME"); sbmediumHLTMu3->Draw("SAME"); sblowHLTMu3->Draw("SAME"); sbtotalHLTMu3->Draw("SAME"); sbhighHLTMu9->Draw("SAME"); sbmediumHLTMu9->Draw("SAME"); sblowHLTMu9->Draw("SAME"); sbtotalHLTMu9->Draw("SAME"); vline6->Draw("SAME"); // LEGENDS leg->Draw("SAME"); hltmu3->Draw("SAME"); hltmu9 = new TPaveLabel(65.,0.02,90.,0.03,"HLT_Mu9 (1x1)"); hltmu9->SetTextColor(kMagenta); hltmu9->Draw("SAME"); c3->Update(); c3->SaveAs("SBjpsi_Mu3Mu9.gif"); /// THIRD PLOT: HLTMu3 + HLT2Mu3 grsb4->Draw("AP"); sbhighHLTMu3->Draw("SAME"); sbmediumHLTMu3->Draw("SAME"); sblowHLTMu3->Draw("SAME"); sbtotalHLTMu3->Draw("SAME"); sbhighHLT2Mu3->Draw("SAME"); sbmediumHLT2Mu3->Draw("SAME"); sblowHLT2Mu3->Draw("SAME"); sbtotalHLT2Mu3->Draw("SAME"); vline6->Draw("SAME"); // LEGENDS leg->Draw("SAME"); hltmu3->Draw("SAME"); hltmu9 = new TPaveLabel(60.,0.02,87.,0.03,"HLT_2Mu3 (1x1)"); hltmu9->SetTextColor(kMagenta); hltmu9->Draw("SAME"); c3->Update(); c3->SaveAs("SBjpsi_Mu32Mu3.gif"); // S/B (pt < 6) TCanvas *c4 = new TCanvas("c4","Events",600,400,700,500); c4->cd(); c4->SetGrid(); c4->SetLogy(); /// FUNCTIONS: HLTMu3 TF1 *sbpt6highHLTMu3 = new TF1("sbpt6highHLTMu3","sqrt(4301*myFunc(x))/(3301*myFunc(x))",0.,36.); sbpt6highHLTMu3->SetLineWidth(4); sbpt6highHLTMu3->SetLineColor(2); TF1 *sbpt6mediumHLTMu3 = new TF1("sbpt6mediumHLTMu3","sqrt(85523*myFunc(x))/(14660*myFunc(x))",0.,36.); sbpt6mediumHLTMu3->SetLineWidth(2); sbpt6mediumHLTMu3->SetLineColor(4); TF1 *sbpt6lowHLTMu3 = new TF1("sbpt6lowHLTMu3","sqrt(174973*myFunc(x))/(35700*myFunc(x))",0.,36.); sbpt6lowHLTMu3->SetLineWidth(2); sbpt6lowHLTMu3->SetLineColor(3); TF1 *sbpt6totalHLTMu3 = new TF1("sbpt6totalHLTMu3","sqrt(264797*myFunc(x))/(53661*myFunc(x))",0.,36.); sbpt6totalHLTMu3->SetLineWidth(4); sbpt6totalHLTMu3->SetLineColor(1); /// FUNCTIONS: HLTMu5 (NON PRESCALED) TF1 *sbpt6highHLTMu5 = new TF1("sbpt6highHLTMu5","sqrt(402*myFunc(x)+15050)/(311*myFunc(x)+11541)",36.,100.); sbpt6highHLTMu5->SetLineWidth(4); sbpt6highHLTMu5->SetLineColor(2); TF1 *sbpt6mediumHLTMu5 = new TF1("sbpt6mediumHLTMu5","sqrt(10083*myFunc(x)+291198)/(2902*myFunc(x)+45385)",36.,100.); sbpt6mediumHLTMu5->SetLineWidth(2); sbpt6mediumHLTMu5->SetLineColor(4); TF1 *sbpt6lowHLTMu5 = new TF1("sbpt6lowHLTMu5","sqrt(38740*myFunc(x)+525859)/(11650*myFunc(x)+92833)",36.,100.); sbpt6lowHLTMu5->SetLineWidth(2); sbpt6lowHLTMu5->SetLineColor(3); TF1 *sbpt6totalHLTMu5 = new TF1("sbpt6totalHLTMu5","sqrt(49225*myFunc(x)+832107)/(14863*myFunc(x)+149759)",36.,100.); sbpt6totalHLTMu5->SetLineWidth(4); sbpt6totalHLTMu5->SetLineColor(1); /// FIRST PLOT: HLTMu3 + HLTMu5 grsb4->GetYaxis()->SetTitle("sqrt(S+B)/S (p_{T} < 6 GeV)"); grsb4->Draw("AP"); sbpt6highHLTMu3->Draw("SAME"); sbpt6mediumHLTMu3->Draw("SAME"); sbpt6lowHLTMu3->Draw("SAME"); sbpt6totalHLTMu3->Draw("SAME"); sbpt6highHLTMu5->Draw("SAME"); sbpt6mediumHLTMu5->Draw("SAME"); sbpt6lowHLTMu5->Draw("SAME"); sbpt6totalHLTMu5->Draw("SAME"); vline6->Draw("SAME"); // LEGENDS leg->Draw("SAME"); hltmu3->Draw("SAME"); hltmu5 = new TPaveLabel(65.,0.02,90.,0.03,"HLT_Mu5 (1x1)"); hltmu5->SetTextColor(kMagenta); hltmu5->Draw("SAME"); c4->Update(); c4->SaveAs("SBjpsi_Mu3Mu5_ptlt6.gif"); }
int fitfunc(int *energy, int *gopt, int append, char* addname){ if(setlogy==0){ //double labelx[6]={380,800,1200,1700,2400,5000}, labely[6]={80,45,25,21,25,15}; //Position }else{ //double labelx[6]={300,750,1400,1800,2700,5000}, labely[6]={130,75,50,30,25,5}; //Position } //void fitfunc(int energy[5], int gopt[5]){ for(int i=0; i<6; i++){ cout<<energy[i]<<" "<<gopt[i]<<endl; } if(histname=="p2p"){ char* dirsim = "../output/rec"; }else if(histname=="p3p"){ //char* dirsim = "../output/rec_p3p"; char* dirsim = "../output/rec"; //char* direxp = "../expout/Feb12/h_SpectrumMINOS_wAdBk.root"; //char* outname = Form("../output/fit/%i%i%i%i%i_%s%i",gopt[0],gopt[1],gopt[2],gopt[3],gopt[4],histname,energy[4]); // .pdf .png .C .root will be created }else{// if(histname=="h23"){ char* dirsim = "../output/rec"; //char* direxp = "../expout/Feb12/h_SpectrumMINOS_wAdBk.root"; //char* outname = Form("../output/fit/%i%i%i%i%i_%s%i",gopt[0],gopt[1],gopt[2],gopt[3],gopt[4],histname,energy[4]); // .pdf .png .C .root will be created } char* outname = Form("../output/fit/%s_%i_%i_%i_%i_%i_%i%s",histname, energy[0],energy[1],energy[2],energy[3],energy[4],energy[5],addname); // .pdf .png .C .root will be created ofstream fpara(Form("%s_fitresult.txt",outname)); if(append == 1){ ofstream fitlist(Form("../output/fit/fitlist_%s%s.csv",histname,addname),ios_base::app); }else{ ofstream fitlist(Form("../output/fit/fitlist_%s%s.csv",histname,addname)); fitlist<<"E0, E1, E2, E3, E4, E5, CS0, CS1, CS2, CS3, CS4, CS5, ER0, ER1, ER2, ER3, ER4, ER5, Chi-sq"<<endl; } gStyle->SetOptStat(kFALSE); gROOT->ProcessLine( ".L fit78Ni.h" ); gStyle->SetOptStat(kFALSE); gStyle->SetPadGridX(false); gStyle->SetPadGridY(false); //gStyle->SetOptLogy(1); char temp[300]; int minBin = 0; //int maxBin = 5500; int maxBin = 6000; int binning = 100; int numBin = (maxBin-minBin)/binning; //Id starts with one!!! int daliIDMin = 1; int daliIDMax = 186; //**************************************************************************** // The simulated peaks TFile *sim[6]; for(int i=0; i<6; i++){ if(energy[i]>0){ sim[i] = new TFile(Form("%s/%ikeV.root",dirsim,energy[i])); }else{ sim[i] = new TFile(Form("%s/%ikeV.root",dirsim,2620));//dummy gopt[i] = 0; } } //The experimental data: TFile *exp[1]; //exp[0] = new TFile(Form("%s/MINOStest.root",direxp)); exp[0] = new TFile(direxp); TCanvas *fCanvas=new TCanvas("Canvas","Response function",700,700); fCanvas->SetBorderSize(0); fCanvas->SetBorderMode(0); fCanvas->SetFrameBorderMode(0); fCanvas->SetFrameFillColor(0); fCanvas->SetBottomMargin(0.15); fCanvas->SetLeftMargin(0.15); fCanvas->cd(); TFile *fout = new TFile(Form("%s.root",outname),"RECREATE"); fout->cd(); // Main TPad *c_m = new TPad("c_m", "c_m",0.0,0.0,1.0,1.0); c_m->Draw(); c_m->cd(); c_m->SetFillColor(0); //c_m->SetFillStyle(0); c_m->SetBorderSize(0); c_m->SetRightMargin(0.05); c_m->SetTopMargin(0.03); c_m->SetBottomMargin(0.15); c_m->SetLeftMargin(0.15); if(setlogy>0) c_m->SetLogy(); fCanvas->cd(); //**************************************************************************** //The simulated spectra: TH1F *hsim[6]; for(int i=0;i<6;i++) { sprintf(temp,"hsim[%i]",i); hsim[i] = new TH1F(temp,temp,numBin,minBin,maxBin); hsim[i] = (TH1F*)sim[i]->Get("h_doppler_addback[0]"); } /* hsim[0] = (TH1F*)sim[0]->Get("h_doppler_addback[0]"); hsim[1] = (TH1F*)sim[1]->Get("h_doppler_addback[0]"); hsim[2] = (TH1F*)sim[2]->Get("h_doppler_addback[0]"); hsim[3] = (TH1F*)sim[3]->Get("h_doppler_addback[0]"); hsim[4] = (TH1F*)sim[4]->Get("h_doppler_addback[0]"); */ //The experimental spectra: TH1F *hexp[1]; for(int i=0;i<1;i++) { sprintf(temp,"hexp[%i]",i); hexp[i] = new TH1F(temp,temp,numBin,minBin,maxBin); } //Getting the experimental spectrum //78Ni hexp[0] = (TH1F*)exp[0]->Get(histname); //hexp[0] = (TH1F*)exp[0]->Get("h23;1"); //hexp[0]->Rebin(2); for(int i=0;i<1;i++) { hexp[i]->SetStats(0); hexp[i]->SetFillColor(0); hexp[i]->SetLineColor(kBlue); hexp[i]->SetLineStyle(0); //hexp[i]->GetXaxis()->SetRangeUser(0,maxBin); hexp[i]->GetXaxis()->SetRangeUser(minBin,maxBin); //hexp[i]->GetXaxis()->SetRangeUser(0,6000); if(setlogy==0){ hexp[i]->GetYaxis()->SetRangeUser(0,yrangemax); }else { hexp[i]->GetYaxis()->SetRangeUser(0.5,yrangemax); } hexp[i]->GetXaxis()->SetNdivisions(305); hexp[i]->GetYaxis()->SetNdivisions(305); hexp[i]->GetYaxis()->SetTitle(Form("Counts / %i keV",binning)); hexp[i]->GetXaxis()->SetTitle("Energy (keV)"); hexp[i]->GetXaxis()->SetTitleOffset(0.9); hexp[i]->GetYaxis()->SetTitleOffset(0.9); hexp[i]->GetXaxis()->SetTitleFont(132); hexp[i]->GetYaxis()->SetTitleFont(132); /* hexp[i]->GetXaxis()->SetTitleSize(0.08); hexp[i]->GetYaxis()->SetTitleSize(0.08); hexp[i]->GetXaxis()->SetLabelSize(0.08); hexp[i]->GetYaxis()->SetLabelSize(0.08); */ hexp[i]->GetXaxis()->SetTitleSize(0.05); hexp[i]->GetYaxis()->SetTitleSize(0.05); hexp[i]->GetXaxis()->SetLabelSize(0.05); hexp[i]->GetYaxis()->SetLabelSize(0.05); //How to get error bar for each bin hexp[i]->SetDefaultSumw2(kTRUE); hexp[i]->SetTitle(""); } //***************************************************************************** peak1g = new TGraph(hsim[0]); peak2g = new TGraph(hsim[1]); peak3g = new TGraph(hsim[2]); peak4g = new TGraph(hsim[3]); peak5g = new TGraph(hsim[4]); peak6g = new TGraph(hsim[5]); /*TGraph *peak1g = new TGraph(hsim[0]); TGraph *peak2g = new TGraph(hsim[1]); TGraph *peak3g = new TGraph(hsim[2]); TGraph *peak4g = new TGraph(hsim[3]); TGraph *peak5g = new TGraph(hsim[4]); */ //******************Function Definition**************************************** //***************************************************************************** const Double_t fitmin=300.; const Double_t fitmax=(Double_t)maxBin;//4000.; c_m->cd(); TF1 *whole = new TF1( "whole", ex_respf,fitmin,fitmax,10); whole->SetParameters(0.0001,0.01,0.00,0.0001,0.001,0.001,3.,-1e-03,3,-1.e-3); //whole->SetParameters(0.0001,0.0001,0.0001, 5.9,-0.00080 ); for(int i=0; i<6; i++){ if(gopt[i]==1){ whole->SetParLimits(i,0.0,parlimit[i]); }else{ whole->FixParameter(i,0.0); } } whole->SetParLimits(6,0,10); whole->SetParLimits(7,-1e-02,0.); whole->SetParLimits(8,0,5); whole->SetParLimits(9,-1e-02,-1e-5); //whole->FixParameter(8,1.426); //whole->FixParameter(9,-8.1e-5); whole->SetLineColor(1); whole->SetLineWidth(2); whole->SetNpx(200); hexp[0]->Fit(whole,"R LL"); //hexp[0]->Fit(whole,""); //cout<<"test"<<endl; //hexp[0]->Draw(""); //hexp[0]->GetXaxis()->SetRangeUser(0,5000); //fCanvas->Print(Form("%s.png",outname)); fpara<<"Chisquare\t"<< whole->GetChisquare()<<endl; fpara<<"para\tvalue\terror\tfilename"<<endl; for(int para=0;para<10;para++){ fpara<<para<<"\t"<<whole->GetParameter(para)<<"\t"<<whole->GetParError(para); if(para<6) { string strenergy =sim[para]->GetName(); int itr = strenergy.find_last_of("/"); strenergy.erase(0,itr+1); fpara<<"\t"<<strenergy; } fpara<<endl; } // fitlist<<"E0, E1, E2, E3, E4, CS0, CS1, CS2, CS3, CS4, ER0, ER1, ER2, ER3, ER4, Chi-sq"<<endl; for(int i=0; i<6; i++) gopt[i]==1? fitlist<<energy[i]<<", ": fitlist<<"0, "; for(int i=0; i<6; i++) gopt[i]==1? fitlist<<genevts*whole->GetParameter(i)*CSincl/tot78Ni<<", ": fitlist<<"0, "; for(int i=0; i<6; i++){gopt[i]==1? fitlist<<sqrt(pow(whole->GetParError(i)*CSincl,2.) //Error from fitting //+whole->GetParameter(i)*pow(CSincl,2) //Statistical error for the events (included? //+pow(whole->GetParameter(i)*CSinclerr,2) // Inclusive cross section error )*genevts/tot78Ni<<", " :fitlist<<"0, "; } fitlist<<whole->GetChisquare()<<endl; //RT end TF1 *peak1f= new TF1( "peak1f", resp1,fitmin,fitmax,1); peak1f->SetParameter(0,whole->GetParameter(0) ); peak1f->SetLineColor(2); peak1f->SetLineWidth(2); peak1f->SetLineStyle(9); peak1f->Draw("same"); TF1 *peak2f= new TF1( "peak2f", resp2,fitmin,fitmax,1); peak2f->SetParameter(0,whole->GetParameter(1) ); peak2f->SetLineColor(2); peak2f->SetLineWidth(2); peak2f->SetLineStyle(9); peak2f->Draw("same"); // TF1 *peak3f= new TF1( "peak3f", resp3,fitmin,fitmax,1); peak3f->SetParameter(0,whole->GetParameter(2) ); peak3f->SetLineColor(2); peak3f->SetLineWidth(2); peak3f->SetLineStyle(9); peak3f->Draw("same"); TF1 *peak4f= new TF1( "peak4f", resp4,fitmin,fitmax,1); peak4f->SetParameter(0,whole->GetParameter(3) ); peak4f->SetLineColor(2); peak4f->SetLineWidth(2); peak4f->SetLineStyle(9); peak4f->Draw("same"); TF1 *peak5f= new TF1( "peak5f", resp5,fitmin,fitmax,1); peak5f->SetParameter(0,whole->GetParameter(4) ); peak5f->SetLineColor(2); peak5f->SetLineWidth(2); peak5f->SetLineStyle(9); peak5f->Draw("same"); TF1 *peak6f= new TF1( "peak6f", resp6,fitmin,fitmax,1); peak6f->SetParameter(0,whole->GetParameter(5) ); peak6f->SetLineColor(2); peak6f->SetLineWidth(2); peak6f->SetLineStyle(9); peak6f->Draw("same"); TF1 *expon= new TF1( "expon",expf ,fitmin,fitmax,4); //expon->SetParameters(whole->GetParameter(5),whole->GetParameter(6),whole->GetParameter(7),whole->GetParameter(8)); expon->SetParameters(whole->GetParameter(6),whole->GetParameter(7),whole->GetParameter(8),whole->GetParameter(9)); expon->SetLineColor(4); expon->SetLineWidth(2); expon->SetLineStyle(7); expon->Draw("same"); //hexp[0]->Draw("same"); hexp[0]->Draw("EL same"); /*TLatex *tex = new TLatex(2000,setlogy?130:60,Form("^{78}Ni (%s)",histname)); tex->SetTextFont(132); tex->SetTextSize(0.07); tex->SetLineWidth(2); tex->Draw(); */ /*TLatex *tex = new TLatex(2700,setlogy?80:55,Form("Incl: %2.1f mbarn for %d cnts", CSincl, (int)tot78Ni)); tex->SetTextFont(132); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); */ for(int i =0; i<6; i++){ if(gopt[i]==1){ TLatex *tex = new TLatex(labelx[i],labely[i], //Form("#splitline{%d keV }{%2.2f mbarn (%3.1f cnts)}",energy[i], genevts*whole->GetParameter(i)*CSincl/tot78Ni, genevts*whole->GetParameter(i))); Form("%d keV",energy[i])); tex->SetTextFont(132); tex->SetTextSize(0.05); tex->SetLineWidth(2); tex->Draw(); } } fCanvas->Print(Form("%s.C",outname)); fCanvas->Print(Form("%s.png",outname)); fCanvas->Print(Form("%s.pdf",outname)); fCanvas->Write(); hexp[0]->Write(); fout->Write(); fout->Close(); }
void ratioPlots_Zxx() { // llbb_Mass_reco mfJetEta_450_600 mfJetEta_250_300 lljjMass_reco mjj_HighMass_reco drll_HighMass_reco TString Variable = "Zxx_Mass_reco"; // TString Variable2 = "Zbb_Mass_reco"; TString x_title = "M_{llxx}"; Int_t N_Rebin = 10; Double_t yTopLimit = 3; TFile *f1 = TFile::Open("/home/fynu/amertens/storage/test/MG_PY6_/output/MG_PY6_/MG_PY6v9.root"); TH1D *h1 = (TH1D*)f1->Get(Variable); h1->Sumw2(); // h1->Add((TH1D*)f1->Get(Variable2)); h1->SetDirectory(0); f1->Close(); TFile *f2 = TFile::Open("/home/fynu/amertens/storage/test/aMCNLO_PY8_/output/aMCNLO_PY8_/aMCNLO_PY8v9.root"); TH1D *h2 = (TH1D*)f2->Get(Variable); h2->Sumw2(); // h2->Add((TH1D*)f2->Get(Variable2)); h2->SetDirectory(0); f2->Close(); /* TFile *f3 = TFile::Open("/home/fynu/amertens/storage/test/MG_PY8_/output/MG_PY8_/MG_PY8.root"); TH1D *h3 = (TH1D*)f3->Get(Variable); h3->SetDirectory(0); f3->Close(); */ // h1->Sumw2(); // h2->Sumw2(); // h3->Sumw2(); cout << "MG_PY6 : " << h1->Integral() << endl; cout << "aMC@NLO_PY8 : " << h2->Integral() << endl; //h1->Scale(1.0/151456.0); //h2->Scale(1.0/1.45192e+09); //h2->Scale(1./12132.9); h1->Scale(1.0/h1->Integral()); h2->Scale(1.0/h2->Integral()); h1->Sumw2(); h2->Sumw2(); // h3->Scale(1.0/h3->Integral()); h1->Rebin(N_Rebin); h2->Rebin(N_Rebin); // h3->Rebin(N_Rebin); TH1D *h1c = h1->Clone(); h1c->Sumw2(); TH1D *h2c = h2->Clone(); h2c->Sumw2(); TH1D *h1c2 = h1->Clone(); h1c2->Sumw2(); h2c->Add(h1c,-1); h2c->Divide(h1c); h1->SetTitle(""); h2->SetTitle(""); // h3->SetTitle(""); h1->SetLineColor(kRed); // h3->SetLineColor(kGreen); TCanvas *c1 = new TCanvas("c1","example",600,700); TPad *pad1 = new TPad("pad1","pad1",0,0.5,1,1); pad1->SetBottomMargin(0); gStyle->SetOptStat(0); pad1->Draw(); pad1->cd(); h2->DrawCopy(); // h3->DrawCopy("same"); h1->GetYaxis()->SetLabelSize(0.1); h1->GetYaxis()->SetRangeUser(0, 0.2);// ,yTopLimit); h1->GetYaxis()->SetTitleSize(0.06); h1->GetYaxis()->SetTitleOffset(0.7); h1->Draw("same"); TLegend *leg = new TLegend(0.6,0.7,0.89,0.89); leg->SetLineColor(0); leg->SetFillColor(0); //leg->AddEntry(h1,"t#bar{t} uncertainty","f"); leg->AddEntry(h1,"MG5 + PY6","l"); leg->AddEntry(h2,"aMC@NLO + PY8","l"); // leg->AddEntry(h3,"MG5 + PY8","l"); leg->Draw(); c1->cd(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.5); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.4); pad2->Draw(); pad2->cd(); pad2->SetGrid(); h2->SetStats(0); h2->Divide(h1); //h2->SetMarkerStyle(21); h2->Draw("ep"); h2->GetYaxis()->SetLabelSize(0.1); h2->GetYaxis()->SetRangeUser(-0.5, 2.5);// ,yTopLimit); h2->GetYaxis()->SetTitle("aMC@NLO+PY8 / MG5+PY6"); h2->GetYaxis()->SetTitleSize(0.06); h2->GetYaxis()->SetTitleOffset(0.7); h2->GetXaxis()->SetLabelSize(0.1); h2->GetXaxis()->SetTitle(x_title); h2->GetXaxis()->SetTitleSize(0.16); h2->GetXaxis()->SetTitleOffset(0.9); // Double_t matrix[4][4]; h2->Fit("pol3","","",50.0,1200.0); TF1 *ratio = h2->GetFunction("pol3"); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); TMatrixD matrix(4,4,fitter->GetCovarianceMatrix()); Double_t errorPar00 = fitter->GetCovarianceMatrixElement(0,0); Double_t errorPar11 = fitter->GetCovarianceMatrixElement(1,1); Double_t errorPar22 = fitter->GetCovarianceMatrixElement(2,2); Double_t errorPar33 = fitter->GetCovarianceMatrixElement(3,3); // c1->cd(); matrix.Print(); //const TMatrixDSym m = matrix; const TMatrixDEigen eigen(matrix); const TMatrixD eigenVal = eigen.GetEigenValues(); const TMatrixD V = eigen.GetEigenVectors(); cout << "V" << endl; V.Print(); cout << "eigenVal" << endl; eigenVal.Print(); cout << "Recomputed diag" << endl; //const TMatrixD Vt(TMatrixD::kTransposed,V); //const TMatrixD Vinv = V.Invert(); const TMatrixD Vt(TMatrixD::kTransposed,V); //cout << "V-1" << endl; //Vinv.Print(); cout << "Vt" << endl; Vt.Print(); const TMatrixD VAVt = Vt*matrix*V; VAVt.Print(); const TVectorD FittedParam(4); FittedParam(0) = fitter->GetParameter(0); FittedParam(1) = fitter->GetParameter(1); FittedParam(2) = fitter->GetParameter(2); FittedParam(3) = fitter->GetParameter(3); FittedParam.Print(); //const TVectorD FittedParamNB(4); const TVectorD PNb = V*FittedParam; cout << "Pnb" << endl; PNb.Print(); cout << " Generating other parameters values " << endl; cout <<" V " << V(0,0) << endl; TRandom3 r; const TVectorD NewP(4); TH1D *hist100 = new TH1D("h100","h100",200,-5,5); TH1D *hist200 = new TH1D("h200","h200",200,-5,5); TH1D *hist400 = new TH1D("h400","h400",200,-5,5); TH1D *hist600 = new TH1D("h600","h600",100,-5,5); TH1D *hist800 = new TH1D("h800","h800",100,-5,5); TH1D *hist1000 = new TH1D("h1000","h1000",100,-5,5); TH1D *histp0 = new TH1D("p0","p0",100,-0.2,0.3); TH1D *histp1 = new TH1D("p1","p1",100,0.0,0.01); TH1D *histp2 = new TH1D("p2","p2",100,-0.00001,0); TH1D *histp3 = new TH1D("p3","p3",100,0,0.000000002); for (Int_t i = 0; i< 500; i++){ NewP(0) = r.Gaus(PNb(0),sqrt(eigenVal(0,0))); NewP(1) = r.Gaus(PNb(1),sqrt(eigenVal(1,1))); NewP(2) = r.Gaus(PNb(2),sqrt(eigenVal(2,2))); NewP(3) = r.Gaus(PNb(3),sqrt(eigenVal(3,3))); //NewP.Print(); //FittedParam.Print(); const TVectorD NewP2 = Vt*NewP; //NewP2.Print(); histp0->Fill(NewP2(0)); histp1->Fill(NewP2(1)); histp2->Fill(NewP2(2)); histp3->Fill(NewP2(3)); TF1 *newFit=new TF1("test","[0]+x*[1]+[2]*pow(x,2)+[3]*pow(x,3)",0,1400); newFit->SetParameters(NewP2(0),NewP2(1),NewP2(2),NewP2(3)); newFit->SetLineColor(kBlue); Double_t area=0; for(Int_t it=1; it < 16; it++){ //cout << "bin : " << it << " " << h1c2->GetBinContent(it) << endl; area += h1c2->GetBinContent(it)*newFit->Eval(100*it+50); } //newFit->Draw("same"); //cout <<"val: " << newFit->Eval(200) << endl; hist100->Fill(newFit->Eval(100)/area); hist200->Fill(newFit->Eval(200)/area); hist400->Fill(newFit->Eval(400)/area); hist600->Fill(newFit->Eval(600)/area); hist800->Fill(newFit->Eval(800)/area); hist1000->Fill(newFit->Eval(1000)/area); } c1->cd(); TCanvas *c2 = new TCanvas("c2","c2",1000,1000); c2->cd(); c2->Divide(3,2); c2->cd(1); hist100->Draw(); c2->cd(2); hist200->Draw(); c2->cd(3); hist400->Draw(); c2->cd(4); hist600->Draw(); c2->cd(5); hist800->Draw(); c2->cd(6); hist1000->Draw(); Double_t m_100,m_200,m_400,m_600,m_800,m_1000; Double_t s_100,s_200,s_400,s_600,s_800,s_1000; hist100->Fit("gaus","","",0.3,1.2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_100 = fitter->GetParameter(1); s_100 = fitter->GetParameter(2); hist200->Fit("gaus","","",0.5,1.2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_200 = fitter->GetParameter(1); s_200 = fitter->GetParameter(2); hist400->Fit("gaus","","",0.8,1.2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_400 = fitter->GetParameter(1); s_400 = fitter->GetParameter(2); hist600->Fit("gaus","","",0.8,1.3); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_600 = fitter->GetParameter(1); s_600 = fitter->GetParameter(2); hist800->Fit("gaus","","",0.5,2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_800 = fitter->GetParameter(1); s_800 = fitter->GetParameter(2); hist1000->Fit("gaus","","",0.5,2.5); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_1000 = fitter->GetParameter(1); s_1000 = fitter->GetParameter(2); Double_t x[6],y[6],ym[6],yup[6],ydown[6]; x[0]=100; x[1]=200; x[2]=400;x[3]=600; x[4]=800; x[5]=1000; yup[0]=ratio->Eval(100)+s_100; yup[1]=ratio->Eval(200)+s_200; yup[2]=ratio->Eval(400)+s_400; yup[3]=ratio->Eval(600)+s_600; yup[4]=ratio->Eval(800)+s_800; yup[5]=ratio->Eval(1000)+s_1000; ydown[0]=ratio->Eval(100)-s_100; ydown[1]=ratio->Eval(200)-s_200; ydown[2]=ratio->Eval(400)-s_400; ydown[3]=ratio->Eval(600)-s_600; ydown[4]=ratio->Eval(800)-s_800; ydown[5]=ratio->Eval(1000)-s_1000; y[0]=1+s_100/ratio->Eval(100); y[1]=1+s_200/ratio->Eval(200); y[2]=1+s_400/ratio->Eval(400); y[3]=1+s_600/ratio->Eval(600); y[4]=1+s_800/ratio->Eval(800); y[5]=1+s_1000/ratio->Eval(1000); ym[0]=-s_100/m_100; ym[1]=-s_200/m_200; ym[2]=-s_400/m_400; ym[3]=-s_600/m_600; ym[4]=-s_800/m_800; ym[5]=-s_1000/m_1000; TGraph* g = new TGraph(6,x,y); TGraph* gm = new TGraph(6,x,ym); TGraph* gup = new TGraph(6,x,yup); TGraph* gdown = new TGraph(6,x,ydown); TCanvas *c3 = new TCanvas("c3","c3",1000,1000); c3->cd(); //gup->Draw("AC*"); //gdown->Draw("C*"); g->Draw("AC*"); gPad->SetBottomMargin(0.2); gPad->SetLeftMargin(0.2); gStyle->SetOptStat(0); g->GetXaxis()->SetTitle("M_{Zbb}"); g->GetXaxis()->SetRangeUser(50,1100); g->GetYaxis()->SetLabelSize(0.06); g->GetYaxis()->SetTitle("Uncertainty"); g->GetYaxis()->SetTitleSize(0.06); g->GetYaxis()->SetTitleOffset(1.4); g->GetXaxis()->SetLabelSize(0.06); g->GetXaxis()->SetTitleSize(0.06); g->GetXaxis()->SetTitleOffset(1); g->GetYaxis()->SetNdivisions(5); TFile f("syst_zxx.root","recreate"); g->Write(); f.Close(); //gm->Draw("C*"); //g->SetMaximum(1); //g->SetMinimum(-1); //h2c->Draw("same"); TH1D *h22=h2->Clone(); TCanvas *c5 = new TCanvas("c5","c5",1000,1000); gPad->SetBottomMargin(0.2); gPad->SetLeftMargin(0.2); gStyle->SetOptStat(0); h22->Draw(); h22->GetXaxis()->SetRangeUser(50,1100); h22->GetYaxis()->SetLabelSize(0.06); h22->GetYaxis()->SetTitleSize(0.06); h22->GetYaxis()->SetTitleOffset(1.4); h22->GetXaxis()->SetLabelSize(0.06); h22->GetXaxis()->SetTitleSize(0.06); h22->GetXaxis()->SetTitleOffset(1); ratio->SetLineColor(kRed); ratio->Draw("same"); gup->Draw("C"); gdown->Draw("C"); TLegend *leg = new TLegend(0.6,0.7,0.89,0.89); leg->SetLineColor(0); leg->SetFillColor(0); leg->AddEntry(h22,"aMC@NLO / MG5","lep"); leg->AddEntry(ratio,"best fit","l"); leg->AddEntry(gup,"Syst Error (#pm 1 #sigma)","l"); leg->Draw(); TCanvas *c4 = new TCanvas("c4","c4",1000,1000); c4->Divide(2,2); c4->cd(1); histp0->Draw(); c4->cd(2); histp1->Draw(); c4->cd(3); histp2->Draw(); c4->cd(4); histp3->Draw(); }
void geugd_riordan() { gROOT->SetStyle("HALLA"); TCanvas *cn = new TCanvas("cn"); cn->Draw(); cn->UseCurrentStyle(); TH1F *frm = new TH1F("frm","",100,0.,12.); frm->GetXaxis()->SetTitle("Q^{2} [GeV^{2}]"); frm->GetXaxis()->CenterTitle(); frm->GetYaxis()->SetTitle("G_{E}^{u}/G_{D}"); frm->GetYaxis()->CenterTitle(); frm->SetMinimum(.40); frm->SetMaximum(2.4); //frm->SetMaximum(0.3); frm->UseCurrentStyle(); frm->Draw(); frm->SetAxisRange(0.10,12.,"X"); TF1* galster = new TF1("galster", "x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))", 0.,4.); galster->SetLineColor(kBlack); galster->SetLineStyle(kBlack); galster->SetLineWidth(2); TF1* gen0 = new TF1("gen0", f1dugen0, 0.,12.); gen0->SetLineColor(kBlack); gen0->SetLineStyle(kBlack); gen0->SetLineWidth(1); TF1 *genf = new TF1("genf",genff,1.,10.,1); genf->SetLineColor(kBlue); genf->SetLineStyle(1); genf->SetParameter(0,1.); // match to Madey point just below 1.5 // genf->SetParameter(0,.0411/genf->Eval(1.45)); // genf->SetParameter(0,-0.558645); genf->SetParameter(0,-0.182645); TF1 *roberts_curve = new TF1("roberts",roberts_gen,0.035,12.344,1); roberts_curve->SetLineColor(kRed); roberts_curve->SetLineStyle(9); TF1 *ourfit = new TF1("ourfit",gen_ourfit,0.,10.,0); ourfit->SetLineColor(kBlue); ourfit->SetLineStyle(0); /* TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0); bbba05->SetLineColor(kGreen); bbba05->SetLineStyle(3); */ // TF1 *lomon = new TF1("Lomon",Lomon_GEn,0.,10.,0); // lomon->SetLineColor(7); // lomon->SetLineStyle(4); TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}"); //TLegend *legDta = new TLegend(.3448,.6123,.6810,.9110,"","brNDC"); TLegend *legDta = new TLegend(.6020,.4004,.9382,.9089,"","brNDC"); TMultiGraph* wgr = mgrDta; TLegend *wlg = legDta; // the data legDta->SetBorderSize(0); // turn off border legDta->SetFillStyle(0); datafile_t *f = datafiles; TGraph* gr=0; TGraph* ogr=0; while ( f && f->filename ) { ogr=OneGraph(f); if (ogr) { gr = fromGEntransform(ogr); gr->SetLineStyle(0); if (f->lnpt) { mgrDta->Add(gr,f->lnpt); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,f->lnpt); } mgrDta->Add(gr,"p"); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,"p"); /* else if (gr->GetMarkerStyle()>=20) { mgrDta->Add(gr,"p"); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,"p"); } else { mgrDta->Add(gr,"l"); if( f->label[0] != 'x' ) legDta->AddEntry(gr,f->label,"l"); } */ } f++; } mgrDta->Draw("p"); legDta->Draw(); TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}"); // TLegend *legThry = new TLegend(.546,.6208,.8822,.9195,"","brNDC"); // TLegend *legThry = new TLegend(.2055,.7013,.6020,.8893,"","brNDC"); TLegend *legThry = new TLegend(.4267,.8453,.6236,.8962,"","brNDC"); wgr = mgrThry; wlg = legThry; // the theory wlg->SetBorderSize(0); // turn off border wlg->SetFillStyle(0); f = theoryfiles1; gr=0; Bool_t isfill; while ( f && f->filename ) { gr=OneGraph(f); gr->SetLineWidth(2); isfill = kFALSE; if (gr) { TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) { gr = toerror_band(egr); gr->SetFillStyle(3000+f->style); gr->SetFillStyle(1); gr->SetFillColor(gr->GetLineColor()); isfill = kTRUE; } if (f->lnpt) { wgr->Add(gr,f->lnpt); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,f->lnpt); } else if (gr->GetMarkerStyle()>=20) { wgr->Add(gr,"p"); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,"p"); } else { if( isfill ){ gr->SetLineStyle(0); wgr->Add(gr,"f"); // wgr->Add( new TGraph(*egr),"l"); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,"lf"); } else { wgr->Add(gr,"l"); if( f->label[0] != 'x' ) wlg->AddEntry(gr,f->label,"l"); } } } f++; } TPaveLabel *prelim = new TPaveLabel( 0.3204, 0.1886, 0.9310, 0.4643, "PRELIMINARY", "NDC" ); prelim->SetTextAngle(0); TColor *pink = new TColor(300, 1.0, 0.7, 0.7, "pink"); prelim->SetTextColor(300); prelim->SetFillStyle(0); prelim->SetBorderSize(0); #ifdef FAKE_SCHIAVILLA TGraph *schiagraph = draw_schiavilla(); schiagraph->Draw("F"); schiagraph = draw_schiavilla(1); schiagraph->Draw("C"); legThry->AddEntry(schiagraph, "d(e,e'd) T_{20} - Schiavilla & Sick", "LF"); #endif #ifdef PRELIMINARY prelim->Draw("same"); #endif TPaveLabel *nofsilab = new TPaveLabel( 0.4569, 0.1674, 0.7514, 0.2415, "No FSI Corrections", "NDC" ); nofsilab->SetFillStyle(0); nofsilab->SetBorderSize(0); nofsilab->SetTextColor(kRed); #ifdef NOFSI // nofsilab->Draw("same"); #endif #ifdef PQCD genf->Draw("same"); #endif mgrThry->Draw("c"); #ifdef GALSTER galster->Draw("same"); #endif // gen0->Draw("same"); #ifdef NEW_ROBERTS roberts_curve->Draw("same"); #endif // ourfit->Draw("same"); // bbba05->Draw("same"); //lomon->Draw("same"); // bandi->Draw("same"); #ifdef PQCD legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l"); #endif #ifdef GALSTER legThry->AddEntry(galster,"Galster fit (1971)","l"); #endif // legThry->AddEntry(gen0,"G_{E}^{n} = 0","l"); #ifdef NEW_ROBERTS legThry->AddEntry(roberts_curve,"q(qq) Faddeev - I. Cloet, ANL","l"); #endif // legThry->AddEntry(bbba05,"BBBA05","l"); // legThry->AddEntry(lomon, "Lomon", "l"); // legThry->AddEntry(ourfit, "Our Fit", "l"); legThry->Draw(); legDta->Draw(); mgrDta->Draw("p"); legDta->Draw(); TEllipse *cir1 = new TEllipse(1.31, 0.0, 0.17, 0.0065); TEllipse *cir2 = new TEllipse(2.4, 0.0, 0.17, 0.0065); cir1->SetFillStyle(0); cir2->SetFillStyle(0); #ifdef PLOTKIN1 cir1->Draw("same"); // cir2->Draw("same"); // TPaveLabel *exacc = new TPaveLabel( 0.3779, 0.2691, 0.5963, 0.3114, "Expected Accuracy", "NDC"); TPaveLabel *exacc = new TPaveLabel( 0.2716, 0.2733, 0.4899, 0.3136, "Expected Accuracy", "NDC"); exacc->SetFillStyle(0); exacc->SetBorderSize(0); exacc->Draw("same"); #endif // draw a line at 1 cn->Modified(); cn->Update(); cn->SaveAs(Form("%s.pdf",psfile)); cn->SaveAs(Form("%s.eps",psfile)); // cn->SaveAs(Form("%s.root",psfile)); // gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile)); // cn->SaveAs("bogdan_gen.eps"); return; // LEAVING HERE // now an overlay, hopefully matching dimensions // remove everything but the graph cn->Update(); TList *clist = cn->GetListOfPrimitives(); TFrame* frame = cn->GetFrame(); for (int i=0; i<clist->GetSize(); ) { if (clist->At(i) != frame) { clist->RemoveAt(i); } else i++; } // draw markers in the corners TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY1(),2); mkr->Draw(); mkr = new TMarker(frame->GetX1(),frame->GetY2(),2); mkr->Draw(); mkr = new TMarker(frame->GetX2(),frame->GetY2(),2); mkr->Draw(); frame->SetLineColor(10); cn->Update(); datafile_t miller = { "figure_input/Miller/lattice.GEn.rtf","Miller", "[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" }; gr = OneGraph(&miller); TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr); if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) { gr = toerror_band(egr); gr->SetLineStyle(1); gr->SetFillColor(gr->GetLineColor()); gr->SetFillStyle(3000+miller.style); } gr->Draw("F"); cn->Update(); cn->SaveAs("gen_Miller_Overlay.pdf"); cn->SaveAs("gen_Miller_Overlay.root"); }
TF1 *fit(TTree *nt, TTree *ntMC, double ptmin,double ptmax) { //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",30,5.03,5.93); // TH1D *hBck = new TH1D(Form("hBck%d",count),"",40,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",30,5.03,5.93); // Fit function //QM2014 //TString iNP="6.71675e+00*Gaus(x,5.30142e+00,8.42680e-02)/(sqrt(2*3.14159)*8.42680e-02)+4.06744e+01*Gaus(x,5.00954e+00,8.11305e-02)/(sqrt(2*3.14159)*8.11305e-02)+5.99974e-01*(2.376716*Gaus(x,5.640619,0.095530)/(sqrt(2*3.14159)*0.095530)+3.702342*Gaus(x,5.501706,0.046222)/(sqrt(2*3.14159)*0.046222))+1.31767e-01*(61.195688*Gaus(x,5.127566,0.087439)/(sqrt(2*3.14159)*0.087439)+58.943919*Gaus(x,5.246471,0.041983)/(sqrt(2*3.14159)*0.041983))"; TString iNP="2.28629e1*Gaus(x,5.02606,6.84e-2)/(sqrt(2*3.14159)*(6.84e-2))+3.85695*Gaus(x,5.27701,0.04305)/(sqrt(2*3.14159)*(0.04305))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[6]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax)); // nt->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax)); // nt2->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax)); // cout <<"nsig = "<<hBck->GetEntries(); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.08); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParLimits(6,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(6,0); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(6); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; cout<<"======= chi2 ======="<<endl; cout<<f->GetChisquare()<<endl; cout<<"===== chi2 end ====="<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (30 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); // hBck->Draw("hist same"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl; double yield = mass->Integral(5,6)/0.03; double yieldErr = mass->Integral(5,6)/0.03*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); //c->SaveAs(Form("../ResultsBzero/BMass-%d.pdf",count)); c->SaveAs("../../../BzeroDefault.pdf"); return mass; }
TF1* fit(Double_t ptmin, Double_t ptmax) { TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",600,600); TFile* infile = new TFile(Form("%s_%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSwapped = (TH1D*)infile->Get("hMCSwapped"); hMCSwapped->SetName(Form("hMCSwapped_%.0f_%.0f",ptmin,ptmax)); TF1* f = new TF1(Form("f_%.0f_%.0f",ptmin,ptmax),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]*exp([4]*x)", 1.7, 2.0); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); h->GetEntries(); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); f->SetParLimits(0,0,1.e+6); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->SetParLimits(3,0,1.e+10); f->SetParameter(3,1.e+3); f->SetLineColor(kRed); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.85,1.90); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background_%.0f_%.0f",ptmin,ptmax),"[0]*exp([1]*x)"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_%.0f_%.0f",ptmin,ptmax),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_%.0f_%.0f",ptmin,ptmax),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol = new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* texPt = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); texPt->SetNDC(); texPt->SetTextFont(42); texPt->SetTextSize(0.04); texPt->SetLineWidth(2); texPt->Draw(); TLatex* texY = new TLatex(0.22,0.83,"|y| < 1.0"); texY->SetNDC(); texY->SetTextFont(42); texY->SetTextSize(0.04); texY->SetLineWidth(2); texY->Draw(); TLatex* texYield = new TLatex(0.22,0.73,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); texYield->SetNDC(); texYield->SetTextFont(42); texYield->SetTextSize(0.04); texYield->SetLineWidth(2); texYield->Draw(); c->SaveAs(Form("plotFits/DMass_expo_%s_%.0f_%.0f.pdf",collisionsystem.Data(),ptmin,ptmax)); TCanvas* cPull = new TCanvas(Form("cPull_%.0f_%.0f",ptmin,ptmax),"",600,700); TH1D* hPull = (TH1D*)h->Clone("hPull"); for(int i=0;i<h->GetNbinsX();i++) { Double_t nfit = f->Integral(h->GetBinLowEdge(i+1),h->GetBinLowEdge(i+1)+h->GetBinWidth(i+1))/h->GetBinWidth(i+1); if(h->GetBinError(i+1)==0) { hPull->SetBinContent(i+1,0.); } else hPull->SetBinContent(i+1,(h->GetBinContent(i+1)-nfit)/h->GetBinError(i+1)); hPull->SetBinError(i+1,0); } hPull->SetMinimum(-4.); hPull->SetMaximum(4.); hPull->SetYTitle("Pull"); hPull->GetXaxis()->SetTitleOffset(1.); hPull->GetYaxis()->SetTitleOffset(0.65); hPull->GetXaxis()->SetLabelOffset(0.007); hPull->GetYaxis()->SetLabelOffset(0.007); hPull->GetXaxis()->SetTitleSize(0.12); hPull->GetYaxis()->SetTitleSize(0.12); hPull->GetXaxis()->SetLabelSize(0.1); hPull->GetYaxis()->SetLabelSize(0.1); hPull->GetYaxis()->SetNdivisions(504); TLine* lPull = new TLine(1.7, 0, 2., 0); lPull->SetLineWidth(1); lPull->SetLineStyle(7); lPull->SetLineColor(1); TPad* pFit = new TPad("pFit","",0,0.3,1,1); pFit->SetBottomMargin(0); pFit->Draw(); pFit->cd(); h->Draw("e"); background->Draw("same"); mass->Draw("same"); massSwap->Draw("same"); f->Draw("same"); leg->Draw("same"); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); texYield->Draw(); cPull->cd(); TPad* pPull = new TPad("pPull","",0,0,1,0.3); pPull->SetTopMargin(0); pPull->SetBottomMargin(0.3); pPull->Draw(); pPull->cd(); hPull->Draw("p"); lPull->Draw(); cPull->cd(); cPull->SaveAs(Form("plotFits/DMass_expo_%s_%.0f_%.0f_Pull.pdf",collisionsystem.Data(),ptmin,ptmax)); return mass; }
void CompareVz(){ gStyle->SetOptStat(kFALSE); gStyle->SetErrorX(0); TString coll="PbP"; bool Save=kTRUE; TF1 * fVz = new TF1("fVx","[0]+[1]*x+[2]*TMath::Power(x,2)+[3]*TMath::Power(x,3)+[4]*TMath::Power(x,4)", -15., 15.); if(coll=="PPb"){ fVz->SetParameters(1.47442e+00, -2.83100e-03, -1.19295e-02, 1.10312e-05, 2.64814e-05); //! new official MC >QM14 //fVz->SetParameters(1.60182e+00,1.08425e-03,-1.29156e-02,-7.24899e-06,2.80750e-05); //fVz->SetParameters(1.66731e+00,-2.43367e-03,-1.42488e-02,7.40147e-06,3.22477e-05); TH1F* histodata=(TH1F*)fDataPPb->Get("Vz"); TH1F* histo1=(TH1F*)fMCPPb->Get("Vz"); TH1F* histo2=(TH1F*)fMCPPb->Get("VzW"); TString data="Pb going positive side"; } else if(coll=="PbP"){ //fVz->SetParameters(1.54398e+00, -8.56155e-03, -1.40026e-02, 4.01020e-05, 3.47683e-05); //latest parameterization fVz->SetParameters(1.49736e+00, -6.93060e-03, -1.26864e-02, 2.98693e-05, 2.89538e-05); //! new official MC after QM14 TH1F* histodata=(TH1F*)fDataPbP->Get("Vz"); TH1F* histo1=(TH1F*)fMCPbP->Get("Vz"); TH1F* histo2=(TH1F*)fMCPbP->Get("VzW"); //TH1F* histo2=(TH1F*)fNMCPbP->Get("Vz"); TString data="Proton going positive side"; } else fVz->SetParameters(1.,0,0,0,0); histo1->SetName(Form("%sNewMC_unweighted",coll.Data())); histo2->SetName(Form("%sNewMC_weighted",coll.Data())); histodata->SetName(Form("%sData",coll.Data())); histo1->Rebin(5); histo2->Rebin(5); histodata->Rebin(5); //histo1=(TH1F*)histo1->Rebin(Nbin_vz,"histo1",binbound_vz); //histo2=(TH1F*)histo2->Rebin(Nbin_vz,"histo2",binbound_vz); histo1->Scale(1/histo1->Integral()); histo2->Scale(1/histo2->Integral()); histodata->Scale(1/histodata->Integral()); histo1->SetMarkerStyle(24); histo1->SetMarkerSize(1.2); histo1->SetMarkerColor(4); histo1->SetLineColor(4); histo2->SetMarkerStyle(0); histo2->SetMarkerColor(0); histo2->SetMarkerSize(0); histo2->SetFillStyle(3004); histo2->SetFillColor(2); histo2->SetLineColor(2); //histo2->SetMarkerColor(0); //histo2->SetMarkerColor(4); histodata->SetMarkerStyle(20); histodata->SetMarkerSize(1.2); histodata->SetMarkerColor(1); histodata->SetLineColor(1); TCanvas* c1 = new TCanvas("c1"," ",500,500); TCanvas* c2 = new TCanvas("c2"," ",500,500); makeMultiPanelCanvas(c1,1,1,-0.16,0,0.16,0.14,0.03); makeMultiPanelCanvas(c2,1,1,-0.16,0,0.16,0.14,0.03); TH1F* hFrame=new TH1F("","",400,-20,20); fixedFontHist(hFrame,1.1,1.7); hFrame->SetTitle(""); hFrame->GetXaxis()->SetTitleSize(0.05); hFrame->GetYaxis()->SetTitleSize(0.05); hFrame->GetXaxis()->SetTitle("Vz (cm)"); hFrame->GetYaxis()->SetTitle("Event Fraction"); hFrame->GetXaxis()->SetLimits(-15,15); //hFrame->GetXaxis()->SetLimits(-3,3); hFrame->GetYaxis()->SetRangeUser(0,5e-2); c1->cd(1); hFrame->DrawCopy(); histodata->Draw("same"); histo1->Draw("same"); histo2->Draw("HIST same"); TLegend *leg1=new TLegend(0.30,0.80,0.85,0.92); TLegend *leg2=new TLegend(0.30,0.85,0.85,0.95); leg1->SetBorderSize(0); leg2->SetBorderSize(0); leg1->SetFillColor(0); leg2->SetFillColor(0); leg1->SetTextSize(0.04); leg2->SetTextSize(0.04); leg1->AddEntry(histo1,"Before Vz weighting","lp"); leg1->AddEntry(histo2,"After Vz weighting","lpf"); //leg1->AddEntry(histo2,"New MC Before Vz weighting","lp"); leg1->AddEntry(histodata,data,"lp"); leg1->Draw("same"); TLatex *T1=new TLatex(0.25,0.92,""); T1->SetNDC(); T1->SetTextAlign(12); T1->SetTextSize(0.05); T1->SetTextColor(1); T1->SetTextFont(42); T1->Draw("same"); c2->cd(1); hFrame->GetYaxis()->SetTitle("Data/MC"); hFrame->GetXaxis()->SetLimits(-15,15); hFrame->GetYaxis()->SetRangeUser(0,2); hFrame->DrawCopy(); TH1F* ratio = (TH1F*)histodata->Clone(Form("%sratio",coll.Data())); //ratio->SetName("ratio"); ratio->Divide(histo1); /*ratio->Fit(fCen); cout<<fCen->GetNDF()<<endl; cout<<fCen->GetChisquare()<<endl; for(int icent=0;icent<=6;icent++) cout<<fCen->GetParameter(icent)<<","; cout<<endl;*/ ratio->DrawCopy("same"); fVz->SetLineColor(2); fVz->Draw("same"); leg2->AddEntry(ratio,data,"lp"); leg2->AddEntry(fVz,"reweighting function","lp"); leg2->Draw("same"); if(Save){ TFile *fout = new TFile("VzandcentCompare.root","Update"); fout->cd(); ratio->Write("",TObject::kOverwrite); histo1->Write("",TObject::kOverwrite); histo2->Write("",TObject::kOverwrite); histodata->Write("",TObject::kOverwrite); fout->Close(); c2->Print(Form("ratio_Vz_%s.png",coll.Data())); c1->Print(Form("VzCompare_Data%s.gif",coll.Data())); c1->Print(Form("VzCompare_Data%s.pdf",coll.Data())); } }
void PostProcessQAMultistrange(Int_t icasType = 0, // 0) Xi- 1) Xi+ 2) Omega- 3) Omega+ Int_t collidingsystem = 2, // 0) PbPb 1) pp 2) pPb Bool_t isMC = kTRUE, // kTRUE-->MC and kFALSE-->Exp. Char_t *fileDir = ".", // Input file directory Char_t *filein = "AnalysisResults.root" // Input file name ) { //___________________ //DEFINE DRAW OPTIONS gStyle->SetOptStat(1110); gStyle->SetOptStat(kFALSE); gStyle->SetOptTitle(kFALSE); gStyle->SetFrameLineWidth(2.5); gStyle->SetCanvasColor(0); gStyle->SetPadColor(0); gStyle->SetHistLineWidth(2.5); gStyle->SetLabelSize(0.05, "x"); gStyle->SetLabelSize(0.05, "y"); gStyle->SetTitleSize(0.05, "x"); gStyle->SetTitleSize(0.05, "y"); gStyle->SetTitleOffset(1.1, "x"); gStyle->SetPadBottomMargin(0.14); //_______________________ //SOURCE USEFUL LIBRARIES gSystem->Load("libANALYSIS.so"); gSystem->Load("libANALYSISalice.so"); gSystem->Load("libCORRFW.so"); //_________________________________ //SOURCE THE FILE AND THE CONTAINER TFile *f1 = new TFile(Form("%s/%s",fileDir,filein)); AliCFContainer *cf = (AliCFContainer*) (f1->Get("PWGLFStrangeness.outputCheckCascade/fCFContCascadeCuts")); //____________ //DEEFINE TEXT TLatex* t1 = new TLatex(0.6,0.55,"#color[3]{OK!!}"); t1->SetTextSize(0.1); t1->SetNDC(); TLatex* t2 = new TLatex(0.6,0.55,"#color[2]{NOT OK!!}"); t2->SetTextSize(0.1); t2->SetNDC(); t2->SetTextColor(2); TLatex* tcasc; if (icasType == 0) tcasc = new TLatex(0.8,0.7,"#color[1]{#Xi^{-}}"); else if (icasType == 1) tcasc = new TLatex(0.8,0.7,"#color[1]{#Xi^{+}}"); else if (icasType == 2) tcasc = new TLatex(0.8,0.7,"#color[1]{#Omega^{-}}"); else if (icasType == 3) tcasc = new TLatex(0.8,0.7,"#color[1]{#Omega^{+}}"); tcasc->SetTextSize(0.2); tcasc->SetNDC(); tcasc->SetTextColor(2); TLatex* tpdgmass; if (icasType == 0) tpdgmass = new TLatex(0.55,0.7,"#color[1]{PDG mass: 1.321 GeV/c^{2}}"); else if (icasType == 1) tpdgmass = new TLatex(0.55,0.7,"#color[1]{PDG mass: 1.321 GeV/c^{2}}"); else if (icasType == 2) tpdgmass = new TLatex(0.55,0.7,"#color[1]{PDG mass: 1.672 GeV/c^{2}}"); else if (icasType == 3) tpdgmass = new TLatex(0.55,0.7,"#color[1]{PDG mass: 1.672 GeV/c^{2}}"); tpdgmass->SetTextSize(0.07); tpdgmass->SetNDC(); tpdgmass->SetTextColor(2); //________________________________ //DEFINE 1st CANVAS AND DRAW PLOTS TCanvas *c1 = new TCanvas("c1","",1200,800); c1->Divide(2,3); //Pad 1: DCA cascade daughters c1->cd(1); gPad->SetLogy(); TH1D *hvar0 = cf->ShowProjection(0,icasType); hvar0->Draw("histo"); Double_t x0; if (collidingsystem == 0) x0 = 0.3; else if (collidingsystem == 1) x0 = 2.0; else if (collidingsystem == 2) x0 = 2.0; TLine *line0 = new TLine(x0,0.,x0,hvar0->GetBinContent(hvar0->GetMaximumBin())); line0->SetLineColor(kRed); line0->SetLineStyle(9); line0->SetLineWidth(2.0); line0->Draw("same"); Bool_t check_0 = checkOverTheLimit(hvar0, x0); if (check_0) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } tcasc->Draw(); //Pad 2: Bachelor IP to PV c1->cd(2); gPad->SetLogy(); TH1D *hvar1 = cf->ShowProjection(1,icasType); hvar1->GetXaxis()->SetRangeUser(0.,0.24); hvar1->Draw("histo"); Double_t x1; if (collidingsystem == 0) x1 = 0.03; else if (collidingsystem == 1) x1 = 0.01; else if (collidingsystem == 2) x1 = 0.03; TLine *line1 = new TLine(x1,0.,x1,hvar1->GetBinContent(hvar1->GetMaximumBin())); line1->SetLineColor(kRed); line1->SetLineStyle(9); line1->SetLineWidth(2.0); line1->Draw("same"); Bool_t check_1 = checkUnderTheLimit(hvar1, x1); if (check_1) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 3: Cascade cosine of Pointing Angle c1->cd(3); gPad->SetLogy(); TH1D *hvar2 = cf->ShowProjection(2,icasType); Double_t max2 = hvar2->GetBinContent(hvar2->GetMaximumBin()); hvar2->GetYaxis()->SetRangeUser(0.01,max2*1.5); hvar2->Draw("histo"); Double_t x2; if (collidingsystem == 0) x2 = 0.999; else if (collidingsystem == 1) x2 = 0.98; else if (collidingsystem == 2) x2 = 0.95; TLine *line2 = new TLine(x2,0.,x2,hvar2->GetBinContent(hvar2->GetMaximumBin())); line2->SetLineColor(kRed); line2->SetLineStyle(9); line2->SetLineWidth(2.0); line2->Draw("same"); line1->Draw("same"); Bool_t check_2 = checkUnderTheLimit(hvar2, x2); if (check_2) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 4: Cascade radius of fiducial volume c1->cd(4); gPad->SetLogy(); TH1D *hvar3 = cf->ShowProjection(3,icasType); hvar3->GetXaxis()->SetRangeUser(0.,3.8); hvar3->Draw("histo"); Double_t x3; if (collidingsystem == 0) x3 = 0.9; else if (collidingsystem == 1) x3 = 0.2; else if (collidingsystem == 2) x3 = 0.4; TLine *line3 = new TLine(x3,0.,x3,hvar3->GetBinContent(hvar3->GetMaximumBin())); line3->SetLineColor(kRed); line3->SetLineStyle(9); line3->SetLineWidth(2.0); line3->Draw("same"); Bool_t check_3 = checkUnderTheLimit(hvar3, x3); if (check_3) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 5: Invariant mass Lambda c1->cd(5); TH1D *hvar4 = cf->ShowProjection(4,icasType); hvar4->Draw("histo"); Double_t x41; if (collidingsystem < 2) x41 = 1.116 + 0.008; else if (collidingsystem == 2) x41 = 1.116 + 0.010; TLine *line41 = new TLine(x41,0.,x41,hvar4->GetBinContent(hvar4->GetMaximumBin())); line41->SetLineColor(kRed); line41->SetLineStyle(9); line41->SetLineWidth(2.0); line41->Draw("same"); Double_t x42; if (collidingsystem < 2) x42 = 1.115 - 0.008; else if (collidingsystem == 2) x42 = 1.115 - 0.010; TLine *line42 = new TLine(x42,0.,x42,hvar4->GetBinContent(hvar4->GetMaximumBin())); line42->SetLineColor(kRed); line42->SetLineStyle(9); line42->SetLineWidth(2.0); line42->Draw("same"); // for (Int_t i = 0; i < hvar4->GetNbinsX()+1; i++) { // cout<<"Content bin: "<<i<<": "<<hvar4->GetBinContent(i)<<endl; // cout<<"Bin low edge: "<<hvar4->GetBinLowEdge(i)<<endl; // cout<<"Bin high edge: "<<hvar4->GetBinLowEdge(i+1)<<endl; // } // cout<<"Low check limit: "<<x42<<endl; // cout<<"High check limit: "<<x41<<endl; Bool_t check_4_1 = checkUnderTheLimit(hvar4, x42); Bool_t check_4_2 = checkOverTheLimit(hvar4, x41); if (check_4_1 && check_4_2) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 6: DCA V0 daughters c1->cd(6); gPad->SetLogy(); TH1D *hvar5 = cf->ShowProjection(5,icasType); hvar5->Draw("histo"); Double_t x5; if (collidingsystem == 0) x5 = 1.0; else if (collidingsystem == 1) x5 = 1.5; else if (collidingsystem == 2) x5 = 2.0; TLine *line5 = new TLine(x5,0.,x5,hvar5->GetBinContent(hvar5->GetMaximumBin())); line5->SetLineColor(kRed); line5->SetLineStyle(9); line5->SetLineWidth(2.0); line5->Draw("same"); Bool_t check_5 = checkOverTheLimit(hvar5, x5); if (check_5) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } c1->SaveAs("fig_lf_Multistrange.pdf("); //________________________________ //DEFINE 2nd CANVAS AND DRAW PLOTS TCanvas *c2 = new TCanvas("c2","",1200,800); c2->Divide(2,3); //Pad 1: V0 cosine of Pointing Angle to PV c2->cd(1); gPad->SetLogy(); TH1D *hvar6 = cf->ShowProjection(6,icasType); Double_t max6 = hvar6->GetBinContent(hvar6->GetMaximumBin()); hvar6->GetYaxis()->SetRangeUser(0.01,max6*1.5); hvar6->Draw("histo"); //Pad 2: Min V0 Radius Fid. Vol. c2->cd(2); gPad->SetLogy(); TH1D *hvar7 = cf->ShowProjection(7,icasType); hvar7->GetXaxis()->SetRangeUser(0.,3.0); hvar7->Draw("histo"); Double_t x7; if (collidingsystem == 0) x7 = 0.9; else if (collidingsystem == 1) x7 = 0.2; else if (collidingsystem == 2) x7 = 0.4; TLine *line7 = new TLine(x7,0.,x7,hvar7->GetBinContent(hvar7->GetMaximumBin())); line7->SetLineColor(kRed); line7->SetLineStyle(9); line7->SetLineWidth(2.0); line7->Draw("same"); Bool_t check_7 = checkUnderTheLimit(hvar7, x7); if (check_7) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad3: Min DCA V0 To PV c2->cd(3); gPad->SetLogy(); TH1D *hvar8 = cf->ShowProjection(8,icasType); hvar8->GetXaxis()->SetRangeUser(0.,0.3); hvar8->Draw("histo"); Double_t x8; if (collidingsystem == 0) x8 = 0.05; else if (collidingsystem == 1) x8 = 0.01; else if (collidingsystem == 2) x8 = 0.05; TLine *line8 = new TLine(x8,0.,x8,hvar8->GetBinContent(hvar8->GetMaximumBin())); line8->SetLineColor(kRed); line8->SetLineStyle(9); line8->SetLineWidth(2.0); line8->Draw("same"); Bool_t check_8 = checkUnderTheLimit(hvar8, x8); if (check_8) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 4: Min DCA Pos To PV c2->cd(4); gPad->SetLogy(); TH1D *hvar9 = cf->ShowProjection(9,icasType); hvar9->GetXaxis()->SetRangeUser(0.,0.2); hvar9->Draw("histo"); Double_t x9; if (collidingsystem == 0) x9 = 0.1; else if (collidingsystem == 1) x9 = 0.05; else if (collidingsystem == 2) x9 = 0.02; TLine *line9 = new TLine(x9,0.,x9,hvar9->GetBinContent(hvar9->GetMaximumBin())); line9->SetLineColor(kRed); line9->SetLineStyle(9); line9->SetLineWidth(2.0); line9->Draw("same"); Bool_t check_9 = checkUnderTheLimit(hvar9, x9); if (check_9) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 5: Min DCA Neg To PV c2->cd(5); gPad->SetLogy(); TH1D *hvar10 = cf->ShowProjection(10,icasType); hvar10->GetXaxis()->SetRangeUser(0.,0.2); hvar10->Draw("histo"); Double_t x10; if (collidingsystem == 0) x10 = 0.1; else if (collidingsystem == 1) x10 = 0.05; else if (collidingsystem == 2) x10 = 0.02; TLine *line10 = new TLine(x10,0.,x10,hvar10->GetBinContent(hvar10->GetMaximumBin())); line10->SetLineColor(kRed); line10->SetLineStyle(9); line10->SetLineWidth(2.0); line10->Draw("same"); Bool_t check_10 = checkUnderTheLimit(hvar10, x10); if (check_10) { cout<<"The cut is OK!!"<<endl; t1->Draw(); } else { cout<<"The cut is NOT OK!!"<<endl; t2->Draw(); } //Pad 6: V0 cosine of Pointing Angle to Xi vtx c2->cd(6); gPad->SetLogy(); TH1D *hvar20 = cf->ShowProjection(18,icasType); Double_t max20 = hvar20->GetBinContent(hvar20->GetMaximumBin()); hvar20->GetYaxis()->SetRangeUser(0.01,max20*1.5); hvar20->Draw("histo"); c2->SaveAs("fig_lf_Multistrange.pdf"); //________________________________ //DEFINE 3rd CANVAS AND DRAW PLOTS TCanvas *c3 = new TCanvas("c3","",1200,800); c3->Divide(2,3); //Pad 1: InvMass c3->cd(1); TH1D *hvar12 = cf->ShowProjection(11+icasType/2,icasType); hvar12->Draw("histo"); tpdgmass->Draw(); TLine *linemass; if (icasType == 0) linemass = new TLine(1.32171,0.,1.32171,0.5*hvar12->GetBinContent(hvar12->GetMaximumBin())); else if (icasType == 1) linemass = new TLine(1.32171,0.,1.32171,0.5*hvar12->GetBinContent(hvar12->GetMaximumBin())); else if (icasType == 2) linemass = new TLine(1.67245,0.,1.67245,0.5*hvar12->GetBinContent(hvar12->GetMaximumBin())); else if (icasType == 3) linemass = new TLine(1.67245,0.,1.67245,0.5*hvar12->GetBinContent(hvar12->GetMaximumBin())); linemass->SetLineColor(kRed); linemass->SetLineStyle(1); linemass->SetLineWidth(2.0); linemass->Draw("same"); //Pad 2: Transverse momentum c3->cd(2); TH1D *hvar13 = cf->ShowProjection(13,icasType); hvar13->Draw("histo"); //Pad 3: Y c3->cd(3); TH1D *hvar14 = cf->ShowProjection(14+icasType/2,icasType); hvar14->Draw("histo"); //Pad 4: Cascade proper length c3->cd(4); TH1D *hvar18; hvar18 = cf->ShowProjection(16,icasType); hvar18->GetXaxis()->SetRangeUser(0.,90.); hvar18->Draw("histo"); //Pad 5: V0 proper length c3->cd(5); TH1D *hvar19; hvar19 = cf->ShowProjection(17,icasType); hvar19->GetXaxis()->SetRangeUser(0.,90.); hvar19->Draw("histo"); //Pad 6 // empty c3->SaveAs("fig_lf_Multistrange.pdf"); //________________________________ //DEFINE 4th CANVAS AND DRAW PLOTS TCanvas *c4 = new TCanvas("c4","",600,400); c4->Divide(2,1); //Pad1: invariant mass fit c4->cd(1); TH1D *hvar18 = cf->ShowProjection(11+icasType/2,icasType); hvar18->Draw("histo"); // - SOME PARAMETER VALUE Bool_t kfitgauss = kFALSE; Bool_t kfitleft = kFALSE; Bool_t kfitright = kFALSE; Int_t ptbinNarrowY = 0; if (icasType < 2) ptbinNarrowY = 10; // 6; else ptbinNarrowY = 3; // 2; // - SOME DEFINITIONS Float_t lowlimmass; Float_t uplimmass; Float_t lowgausslim; Float_t upgausslim; if (icasType==0||icasType==1) { lowlimmass=1.30; uplimmass=1.34; lowgausslim=1.312; upgausslim=1.332; } else { lowlimmass=1.645; uplimmass=1.70; lowgausslim=1.668; upgausslim=1.678; } TF1* fitinvmass = new TF1("fitinvmass","gaus(0)+pol2(3)",lowlimmass,uplimmass); fitinvmass->SetParName(0, "cnstntG"); fitinvmass->SetParName(1, "meanG"); fitinvmass->SetParName(2, "sigmaG"); fitinvmass->SetParLimits(0,0.,500000.); if (icasType==0||icasType==1) { fitinvmass->SetParameter(1, 1.32171); fitinvmass->SetParLimits(1, 1.31,1.33); fitinvmass->SetParLimits(2,0.001,0.005); } else { fitinvmass->SetParameter(1, 1.67245); fitinvmass->SetParLimits(1, 1.664,1.68); fitinvmass->SetParLimits(2,0.0008,0.006); } hvar18->Fit("fitinvmass","rimeN"); fitinvmass->SetLineColor(kRed); fitinvmass->Draw("same"); Float_t meanGauss = fitinvmass->GetParameter(1); Float_t sigmaGauss = fitinvmass->GetParameter(2); cout<<"Mean: "<<meanGauss<<endl; cout<<"Sigma: "<<sigmaGauss<<endl; //Pad2: Text c4->cd(2); Float_t refwidth = 0.002; if (icasType > 1) refwidth = 0.0025; TPaveText *pave1 = new TPaveText(0.05,0.3,0.95,0.5); pave1->SetFillColor(0); pave1->SetTextSize(0.04); pave1->SetTextAlign(12); if (icasType < 2) pave1->AddText("PDG mass: 1.32171 GeV/c^{2}"); else pave1->AddText("PDG mass: 1.67245 GeV/c^{2}"); pave1->AddText(Form("#color[1]{Mass form Fit: %.5f #pm %.5f GeV/c^{2}}",meanGauss,sigmaGauss)); if (sigmaGauss > refwidth - 0.0003 && sigmaGauss < refwidth + 0.0003) pave1->AddText("#color[3]{OK!! The width is compatible with standard.}"); else pave1->AddText("#color[2]{NOT OK!! Problem.}"); pave1->Draw(); cout<<" "<<refwidth - 0.0003<<"<"<<sigmaGauss<<"<"<<refwidth + 0.0003<<endl; c4->SaveAs("fig_lf_Multistrange.pdf"); //________________________________ //DEFINE 5th CANVAS AND DRAW PLOTS if (collidingsystem == 0 || collidingsystem == 2) { TCanvas *c5 = new TCanvas("c5","",600,720);//1200,270); //c5->Divide(2,1); //Pad 1: centrality c5->cd(1); TH1D *hvar16 = cf->ShowProjection(19,icasType); hvar16->Draw("histo"); //Pad 2: track multiplicity //c5->cd(2); //TH1D *hvar17 = cf->ShowProjection(20,icasType); //hvar17->Draw("histo"); if (!isMC) c5->SaveAs("fig_lf_Multistrange.pdf)"); else if (isMC) c5->SaveAs("fig_lf_Multistrange.pdf"); } //_______________________________ //CHECK ON MONTE CARLO PRODUCTION if (isMC) { AliCFContainer *cfMC = (AliCFContainer*) (f1->Get("PWGLFStrangeness.outputCheckCascade/fCFContCascadeMCgen")); //DEFINE 6th CANVAS AND DRAW PLOTS TCanvas *c6 = new TCanvas("c6","",1200,800); c6->Divide(2,3); //Pad 1: Total Momentum c6->cd(1); TH1D *hvar17 = cfMC->ShowProjection(0,icasType); hvar17->Draw("histo"); tcasc->Draw(); //Pad 2: Transverse Momentum c6->cd(2); TH1D *hvar18 = cfMC->ShowProjection(1,icasType); hvar18->Draw("histo"); //Pad 3: Rapidity (y) c6->cd(3); TH1D *hvar19 = cfMC->ShowProjection(2,icasType); hvar19->Draw("histo"); //Pad 4: Pseudo-rapidity (eta) c6->cd(4); TH1D *hvar20 = cfMC->ShowProjection(3,icasType); hvar20->Draw("histo"); //Pad 5: Theta c6->cd(5); TH1D *hvar21 = cfMC->ShowProjection(4,icasType); hvar21->Draw("histo"); //Pad 6: Phi c6->cd(6); TH1D *hvar22 = cfMC->ShowProjection(5,icasType); hvar22->Draw("histo"); c6->SaveAs("fig_lf_Multistrange.pdf)"); } }
void TriggerEfficienciesSF(TString datafile, TString mcfile, TString ref, TString id, TString variable, TString xtitle, Bool_t linear = true) { gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); TFile * file = new TFile(datafile); TH1D * All = (TH1D*) file->Get(TString("AllEvents")+variable)->Clone(); TH1D * Ref = (TH1D*) file->Get("Trigger"+ref+variable)->Clone(); TH1D * Trigger = (TH1D*) file->Get("Trigger"+id+variable)->Clone(); Int_t ngroup = 2; All->Rebin(ngroup); Ref->Rebin(ngroup); Trigger->Rebin(ngroup); TCanvas * canvas = new TCanvas(); // canvas->SetLogy(); All->GetXaxis()->SetTitle(xtitle); All->GetYaxis()->SetTitle("Trigger efficiency"); All->GetYaxis()->SetRangeUser(0.0,1.1); All->Draw("axis"); TEfficiency * EffData = new TEfficiency(); EffData->SetTotalHistogram(*Ref, "f"); EffData->SetPassedHistogram(*Trigger, "f"); EffData->SetMarkerStyle(kFullCircle); EffData->SetMarkerColor(kBlack); EffData->SetLineColor(kBlack); EffData->Draw("samep"); TF1 * datafit = new TF1("datafit","[0] + [1]*(x-100)^2", 100, 800); datafit->SetParameter(0,1.0); datafit->SetParameter(1,0.0); if (linear) datafit->FixParameter(1,0.0); TBinomialEfficiencyFitter * fitter = new TBinomialEfficiencyFitter(Trigger,Ref); fitter->Fit(datafit); datafit->Draw("same"); Double_t * datamatrix = fitter->GetFitter()->GetCovarianceMatrix(); Double_t dataparam[7]; dataparam[1] = datafit->GetParameter(0); dataparam[2] = datafit->GetParameter(1); for (Int_t i = 0; i < 4; ++i) { if (linear && i) dataparam[i+3] = 0; else dataparam[i+3] = datamatrix[i]; } dataparam[0] = 1.0; TF1 * dataplus = new TF1("dataplus", fitSigma, 100.0, 1000, 7); dataplus->SetParameters(dataparam); dataplus->SetLineStyle(kDashed); dataplus->SetLineWidth(1); dataplus->Draw("same"); dataparam[0] = -1.0; TF1 * dataminus = new TF1("dataminus", fitSigma, 100.0, 1000, 7); dataminus->SetParameters(dataparam); dataminus->SetLineStyle(kDashed); dataminus->SetLineWidth(1); dataminus->Draw("same"); canvas->SaveAs(id+variable+"r"+ref+"-data.png"); file = new TFile(mcfile); Ref = (TH1D*) file->Get("Trigger"+ref+variable)->Clone(); Trigger = (TH1D*) file->Get("Trigger"+id+variable)->Clone(); Ref->Rebin(ngroup); Trigger->Rebin(ngroup); TEfficiency * EffMC = new TEfficiency(); EffMC->SetTotalHistogram(*Ref, "f"); EffMC->SetPassedHistogram(*Trigger, "f"); EffMC->SetMarkerStyle(kFullSquare); EffMC->SetMarkerColor(kRed); EffMC->SetLineColor(kRed); All->Draw("axis"); EffMC->Draw("samep"); TF1 * mcfit = new TF1("mcfit","[0] + [1]*(x-100)^2", 100, 800); mcfit->SetLineColor(kRed); mcfit->SetParameter(0,1.0); mcfit->SetParameter(1,0.0); if (linear) mcfit->FixParameter(1,0.0); TBinomialEfficiencyFitter * mcfitter = new TBinomialEfficiencyFitter(Trigger,Ref); mcfitter->Fit(mcfit); mcfit->Draw("same"); Double_t * mcmatrix = mcfitter->GetFitter()->GetCovarianceMatrix(); Double_t mcparam[7]; mcparam[1] = mcfit->GetParameter(0); mcparam[2] = mcfit->GetParameter(1); for (Int_t i = 0; i < 4; ++i) { if (linear && i) mcparam[i+3] = 0; else mcparam[i+3] = mcmatrix[i]; } mcparam[0] = 1.0; TF1 * mcplus = new TF1("dataplus", fitSigma, 100.0, 1000, 7); mcplus->SetParameters(mcparam); mcplus->SetLineStyle(kDashed); mcplus->SetLineColor(kRed); mcplus->SetLineWidth(1); mcplus->Draw("same"); mcparam[0] = -1.0; TF1 * mcminus = new TF1("dataminus", fitSigma, 100.0, 1000, 7); mcminus->SetParameters(mcparam); mcminus->SetLineStyle(kDashed); mcminus->SetLineColor(kRed); mcminus->SetLineWidth(1); mcminus->Draw("same"); canvas->SaveAs(id+variable+"r"+ref+"-mc.png"); Double_t sfparam[13]; sfparam[1] = dataparam[1]; sfparam[2] = dataparam[2]; sfparam[3] = mcparam[1]; sfparam[4] = mcparam[2]; for (Int_t i = 0; i < 4; ++i) sfparam[i+5] = dataparam[i+3]; for (Int_t i = 0; i < 4; ++i) sfparam[i+9] = mcparam[i+3]; for (Int_t i = 0; i < 13; ++i) cout << sfparam[i] << " "; cout << endl; sfparam[0] = 0.0; TF1 * sf = new TF1("sf", sffit, 100.0, 1000, 13); sf->SetParameters(sfparam); All->GetYaxis()->SetTitle("Trigger scale factor"); All->GetYaxis()->SetRangeUser(0.0,1.1); All->Draw("axis"); sf->Draw("same"); sfparam[0] = 1.0; TF1 * sfplus = new TF1("sfplus", sffit, 100.0, 1000, 13); sfplus->SetParameters(sfparam); sfplus->SetLineStyle(kDashed); sfplus->SetLineWidth(1); sfplus->Draw("same"); sfparam[0] = -1.0; TF1 * sfminus = new TF1("sfminus", sffit, 100.0, 1000, 13); sfminus->SetParameters(sfparam); sfminus->SetLineStyle(kDashed); sfminus->SetLineWidth(1); sfminus->Draw("same"); if (linear) cout << "Linear fit for sf: " << sf->Eval(100) << " +- " << (sfplus->Eval(100)-sf->Eval(100)) << endl; canvas->SaveAs(id+variable+"r"+ref+"-sf.png"); }