instrAsy() { gStyle->SetOptStat(0); gStyle->SetOptFit(0); TGraphErrors *gr =new TGraphErrors; gr->SetName("insyAsy"); gr->SetTitle("Instrumental Asymmetries"); //gr->SetMarkerColor(ampCol[iam]); gr->SetMarkerSize(0.8); gr->SetMarkerStyle(21); TGraphErrors *gr1=gr; TString wrkDir="final/"; TString fname=wrkDir+"defaultB-H/asyVer1.hist.root"; TFile *inpH=new TFile(fname); assert(inpH->IsOpen()); //inpH->ls(); const int nSel=5; char *selL[nSel]={ "a0*All","b0*All","a2*All","b2*All","c1*All"}; int isel; for (isel=0;isel<nSel;isel++) { TGraphErrors *gr =(TGraphErrors *) inpH->Get(selL[isel]); assert(gr); //gr->Print(); //gr->Draw("AP"); float x1=0; if(isel<2) x1=2189; gr->Fit("pol0","","",x1,3000); TF1 *ff=gr->GetFunction("pol0"); if(ff==0) continue; // no fit was made float val=ff->GetParameter(0); float err=ff->GetParError(0); printf("pol0= %f +/- %f\n",val,err); int n=gr1->GetN(); float x=isel+1; gr1->SetPoint(n,x,val); gr1->SetPointError(n,0,err); } gr1->Print(); // return; gr1->Draw("AP"); // save Tgraph TString fname=wrkDir+"instAsy.hist.root"; TFile *outH=new TFile(fname,"RECREATE"); assert(outH->IsOpen()); printf("save outH -->%s\n", fname.Data()); gr1->Write(); outH->ls(); outH->Write(); return; }
std::pair<double,double> plotVelocity(std::vector<double> positions, std::vector<double> means, int strip, std::vector<double> errors, char thresholdLabel) { TCanvas* c = new TCanvas(); TGraphErrors* vGraph = new TGraphErrors(positions.size(), &means[0], &positions[0], 0, &errors[0] ); vGraph->SetMarkerStyle(20); vGraph->SetMarkerSize(1); vGraph->Draw("AP"); vGraph->Fit("pol1"); TF1* fit = vGraph->GetFunction("pol1"); std::stringstream buf; buf << strip << "_" << thresholdLabel; c->SaveAs( (buf.str() + ".png").c_str() ); std::pair<double,double> resultOfFit = std::make_pair<double,double> ( (fit->GetParameter(1))*-0.2, (fit->GetParError(1))*-0.2 ); return resultOfFit; }
void howManyPe7_17_evening(){ cout << "Starting" << endl; const int numRuns = 6; const char* files[numRuns] = { "../../crunchedFiles/run_00480_crunched.root", "../../crunchedFiles/run_00481_crunched.root", "../../crunchedFiles/run_00482_crunched.root", "../../crunchedFiles/run_00483_crunched.root", "../../crunchedFiles/run_00484_crunched.root", "../../crunchedFiles/run_00485_crunched.root", }; gStyle->SetOptFit(1); gStyle->SetOptStat(0); double pes[16]; double peErrors[16]; double gains[16]; double gainErrors[16]; TCanvas* c1 = new TCanvas(); cout << "starting loop " << endl; for(int row = 2; row < 6; ++row){ for(int col = 2; col < 6; ++col){ vector<double> means; vector<double> sigs; vector<double> meanErrs; vector<double> sigErrs; for (int i = 0; i < numRuns; ++i){ TFile* f = new TFile(files[i]); TTree* t = (TTree*) f->Get("t"); t->Draw(Form("sipm%i%i.energy>>histo%i%i", row,col,row,col),Form("sipm%i%i.valid",row,col)); TH1F* h = (TH1F*) gROOT->FindObject(Form("histo%i%i",row,col)); h->Fit("gaus","0q"); if(h->GetFunction("gaus")->GetParameter(1)>250){ means.push_back(h->GetFunction("gaus")->GetParameter(1)); sigs.push_back(h->GetFunction("gaus")->GetParameter(2)); meanErrs.push_back(h->GetFunction("gaus")->GetParError(1)); sigErrs.push_back(h->GetFunction("gaus")->GetParError(2)); } } vector<double> variances; vector<double> varianceErrors; for(int i = 0; i < means.size(); ++i){ variances.push_back(sigs[i]*sigs[i]); varianceErrors.push_back(2*sigs[i]*sigErrs[i]); } if(means.size() > 1){ TGraphErrors* linGraph = new TGraphErrors(means.size(), &means[0], &variances[0], &meanErrs[0], &varianceErrors[0]); TGraphErrors* quadGraph = new TGraphErrors(means.size(), &means[0], &variances[0], &meanErrs[0], &varianceErrors[0]); linGraph->SetMarkerStyle(20); linGraph->Fit("pol1","q"); linGraph->SetTitle(Form("SiPM %i%i", row, col)); linGraph->GetFunction("pol1")->SetLineColor(kBlue); linGraph->GetXaxis()->SetTitle("Mean"); linGraph->GetYaxis()->SetTitle("#sigma^{2}"); quadGraph->SetMarkerStyle(20); quadGraph->Fit("pol2","q"); quadGraph->GetFunction("pol2")->SetLineColor(kRed); linGraph->Draw("ap"); quadGraph->Draw("psame"); UInt_t index = (row-2)*4 + (col-2); pes[index] = 1.0/linGraph->GetFunction("pol1")->GetParameter(1)*means[0]; gains[index] = linGraph->GetFunction("pol1")->GetParameter(1); gainErrors[index] = linGraph->GetFunction("pol1")->GetParError(1); peErrors[index] = TMath::Sqrt((1/gains[index]*meanErrs[0])*(1/gains[index]*meanErrs[0])+ (means[0]/(gains[index]*gains[index])*gainErrors[index])*(means[0]/(gains[index]*gains[index])*gainErrors[index])); /* pes[drs] = 1.0/quadGraph->GetFunction("pol2")->GetParameter(1)*means[0]; gains[drs] = quadGraph->GetFunction("pol2")->GetParameter(1); gainErrors[drs] = quadGraph->GetFunction("pol2")->GetParError(1); peErrors[drs] = TMath::Sqrt((1/gains[drs]*meanErrs[0])*(1/gains[drs]*meanErrs[0])+ (means[0]/(gains[drs]*gains[drs])*gainErrors[drs])*(means[0]/(gains[drs]*gains[drs])*gainErrors[drs])); */ delete linGraph; delete quadGraph; } else if (means.size()==1){ UInt_t index = (row-2)*4 + (col-2); UInt_t mean = means[0]; UInt_t sig = sigs[0]; UInt_t meanErr = meanErrs[0]; UInt_t sigErr = sigErrs[0]; pes[index] = mean*mean/sig/sig; gains[index] = mean/pes[index]; gainErrors[index] = TMath::Sqrt((2*sig/mean*sigErr)*(2*sig/mean*sigErr)+(sig*sig/mean/mean*meanErr)*(sig*sig/mean/mean*meanErr)); peErrors[index] = TMath::Sqrt((2*mean/sig/sig*sigErr)*(2*mean/sig/sig*sigErr)+(2*mean*mean/sig/sig/sig*sigErr)*(2*mean*mean/sig/sig/sig*sigErr)); } else{ UInt_t index = (row-2)*4 + (col-2); pes[index] = -1; gains[index] = -1; peErrors[index] = -1; gainErrors[index] = -1; } } } for(int i = 0; i <16; ++i){ cout << "SiPM " << 2+i/4 << 2+i%4 << " --- " << "p1 : " << gains[i] << ", " << pes[i] << " photoelectrons at open filter, " << gains[i]*pes[i] << "calibration constant." << endl; } TGraphErrors* peGainGraph = new TGraphErrors(16, gains, pes, gainErrors, peErrors); peGainGraph->SetMarkerStyle(20); peGainGraph->GetXaxis()->SetTitle("gain"); peGainGraph->GetYaxis()->SetTitle("PE at open filter"); c1->SetGridx(); c1->SetGridy(); peGainGraph->Draw("ap"); cout << "drew graph " << endl; TCanvas* c2 = new TCanvas(); TH2F* peMap = new TH2F("pes","PE Map", 4,0,4,4,0,4); for(int i = 0; i < 16; ++i){ peMap->Fill(.5+i%4, 3.5-i/4, pes[i]); } peMap->GetXaxis()->SetLabelOffset(99); peMap->GetYaxis()->SetLabelOffset(99); c2->SetTickx(0); c2->SetTicky(0); peMap->Draw("TEXT"); TCanvas* c3 = new TCanvas(); TH2F* gainMap = new TH2F("gains","Gain Map", 4,0,4,4,0,4); for(int i = 0; i < 16; ++i){ gainMap->Fill(.5+i%4, 3.5-i/4, gains[i]); } gainMap->GetXaxis()->SetLabelOffset(99); gainMap->GetYaxis()->SetLabelOffset(99); gainMap->Draw("TEXT"); }
void getCalibrationResults(TString url="TopMassCalibration.root",int nCategs=4) { TString mpts[]={"161.5","163.5","166.5","169.5","172.5","175.5","178.5","181.5","184.5"}; const size_t nmpts=sizeof(mpts)/sizeof(TString); std::vector<TString> labels; if(nCategs==2) { labels.push_back("1 b-tags"); labels.push_back("#geq 2 b-tags"); } else if(nCategs==4) { labels.push_back("1 b-tags (ee+#mu#mu)"); labels.push_back("#geq 2 b-tags (ee+#mu#mu)"); labels.push_back("1 b-tags (e#mu)"); labels.push_back("#geq 2 b-tags (e#mu)"); } else { labels.push_back("1 b-tags (ee)"); labels.push_back("#geq 2 b-tags (ee)"); labels.push_back("1 b-tags (#mu#mu)"); labels.push_back("#geq 2 b-tags (#mu#mu)"); labels.push_back("1 b-tags (e#mu)"); labels.push_back("#geq 2 b-tags (e#mu)"); } TString outDir=gSystem->DirName(url); report << "Plots will be stored at @ " << outDir << endl; TGraphErrors *lingr = new TGraphErrors; lingr->SetMarkerStyle(20); TGraphErrors *biasgr = new TGraphErrors; biasgr->SetMarkerStyle(20); std::vector<TGraphErrors *> categbiasgr; for(int icat=0; icat<nCategs; icat++) categbiasgr.push_back( new TGraphErrors ); TObjArray statUncResults; TObjArray pullResults; //get results from file TFile *fin=TFile::Open(url); for(size_t i=0; i<nmpts; i++) { Float_t trueMass=mpts[i].Atof(); TH1D *massFitH=(TH1D *)fin->Get(mpts[i]+"/massfit"); if(massFitH==0) continue; TF1 *ffunc=massFitH->GetFunction("gaus"); float avgMass=ffunc->GetParameter(1); float avgMassErr=ffunc->GetParError(1); int ipt=lingr->GetN(); lingr->SetPoint(ipt,trueMass,avgMass); lingr->SetPointError(ipt,0,avgMassErr); for(int icat=0; icat<=nCategs;icat++) { TString postfix(""); TGraphErrors *gr=biasgr; if(icat<nCategs){ postfix ="_"; postfix +=( icat+1); gr=categbiasgr[icat]; } TH1D *biasH=(TH1D *)fin->Get(mpts[i]+"/bias"+postfix); ffunc=biasH->GetFunction("gaus"); float avgBias=ffunc->GetParameter(1); float avgBiasErr=ffunc->GetParError(1); ipt=gr->GetN(); gr->SetPoint(ipt,trueMass,avgBias); gr->SetPointError(ipt,0,avgBiasErr); if(trueMass==172.5) { TH1D *h=(TH1D *)fin->Get(mpts[i]+"/statunc"+postfix); h->SetDirectory(0); h->SetLineColor(icat==nCategs? 1 : icat+2); h->SetMarkerColor(icat==nCategs? 1 : icat+2); h->SetMarkerStyle(1); h->SetLineWidth(2); statUncResults.Add(h); } } TH1D *pullH=(TH1D *)fin->Get(mpts[i]+"/pull"); pullH->SetDirectory(0); pullResults.Add(pullH); } fin->Close(); //plot results setStyle(); gStyle->SetOptFit(0); TCanvas *c=new TCanvas("linc","linc",600,600); c->SetWindowSize(600,600); c->Divide(1,2); TPad *p=(TPad *)c->cd(1); p->SetPad(0,0.3,1.0,1.0); lingr->Draw("ap"); lingr->GetXaxis()->SetTitle("Generated m_{top} [GeV/c^{2}]"); lingr->GetXaxis()->SetTitle("Fitted m_{top} [GeV/c^{2}]"); TLine *l=new TLine(lingr->GetXaxis()->GetXmin(),lingr->GetYaxis()->GetXmin(), lingr->GetXaxis()->GetXmax(),lingr->GetYaxis()->GetXmax()); l->SetLineColor(kGray); l->SetLineStyle(6); l->Draw("same"); TLegend *leg = p->BuildLegend(); formatForCmsPublic(p,leg,"CMS simulation",3); leg->Delete(); p=(TPad *)c->cd(2); p->SetPad(0,0.0,1.0,0.28); p->SetTopMargin(0); p->SetBottomMargin(0.5); float yscale = (1.0-0.3)/(0.28-0); biasgr->Draw("ap"); biasgr->GetXaxis()->SetTitle("Generated m_{top} [GeV/c^{2}]"); biasgr->GetYaxis()->SetTitle("Bias"); biasgr->GetYaxis()->SetRangeUser(-5.2,5.2); biasgr->GetXaxis()->SetTitleOffset(0.85); biasgr->GetXaxis()->SetLabelSize(0.04 * yscale); biasgr->GetXaxis()->SetTitleSize(0.05 * yscale); biasgr->GetXaxis()->SetTickLength( 0.03 * yscale ); biasgr->GetYaxis()->SetTitleOffset(0.5); biasgr->GetYaxis()->SetLabelSize(0.04 * yscale); biasgr->GetYaxis()->SetTitleSize(0.04 * yscale); biasgr->Fit("pol1"); float a=biasgr->GetFunction("pol1")->GetParameter(1); float b=biasgr->GetFunction("pol1")->GetParameter(0); report << "[Inclusive bias correction] resslope:" << (a+1.) << " resbias:" << b << endl; c->Modified(); c->Update(); c->SaveAs(outDir+"/TopMassCalibrationResults.C"); c->SaveAs(outDir+"/TopMassCalibrationResults.png"); c->SaveAs(outDir+"/TopMassCalibrationResults.pdf"); // delete c; //biases per category c=new TCanvas("biasc","biasc",600,600); c->SetWindowSize(600,600); c->Divide(1,nCategs+1); c->cd(nCategs+1)->Delete(); float ystep=(1.0)/(nCategs+1); for(int icat=nCategs-1; icat>=0; --icat) { TGraphErrors *gr=categbiasgr[icat]; gr->SetMarkerStyle(20); TPad *p=(TPad *)c->cd(icat+1); p->SetFillStyle(1001); p->SetFillColor(0); float ymin=(icat+1)*ystep-0.05; float ymax=(icat+2)*ystep-0.05; if(icat==0) { ymin=icat*ystep; } p->SetPad(0,ymin,1.0,ymax); p->SetTopMargin(0.0); p->SetBottomMargin(icat==0?0.4:0.0); gr->Draw("ap"); float yscale = (0.95-ystep)/(ystep-0.0); if(icat==0) yscale=(0.95-2*ystep)/(1.2*ystep-0); if(icat==0) gr->GetXaxis()->SetTitle("Generated m_{top} [GeV/c^{2}]"); else gr->GetXaxis()->SetNdivisions(0); gr->GetYaxis()->SetTitle("Bias"); gr->GetYaxis()->SetRangeUser(-5.2,5.2); gr->GetXaxis()->SetTitleOffset(0.85); gr->GetXaxis()->SetLabelSize(0.04 * yscale); gr->GetXaxis()->SetTitleSize(0.05 * yscale); gr->GetXaxis()->SetTickLength( 0.03 * yscale ); gr->GetYaxis()->SetTitleOffset(icat==0?0.5:0.3); gr->GetYaxis()->SetLabelSize(0.04 * yscale); gr->GetYaxis()->SetTitleSize(0.04 * yscale); gr->Fit("pol1"); float a=gr->GetFunction("pol1")->GetParameter(1); float b=gr->GetFunction("pol1")->GetParameter(0); report << "[Bias correction #" << icat+1 << "] resslope:" << (a+1.) << " resbias:" << b << endl; //prepare label TPaveText *pave = new TPaveText(0.70,0.65,0.8,0.92,"NDC"); pave->SetTextFont(42); pave->SetFillStyle(0); pave->SetBorderSize(0); pave->AddText( labels[icat] )->SetTextAlign(11); pave->Draw(); if(icat==nCategs-1) { pave = new TPaveText(0.2,0.75,0.45,0.92,"NDC"); pave->SetTextFont(42); pave->SetFillStyle(0); pave->SetBorderSize(0); pave->AddText( "CMS simulation" )->SetTextAlign(11); pave->Draw(); } } c->Modified(); c->Update(); c->SaveAs(outDir+"/TopMassCalibrationBiases.C"); c->SaveAs(outDir+"/TopMassCalibrationBiases.png"); c->SaveAs(outDir+"/TopMassCalibrationBiases.pdf"); //delete c; //stat uncertainty c=new TCanvas("statc","statc",600,600); c->SetWindowSize(600,600); for(int i=0; i<statUncResults.GetEntriesFast(); i++) { int idx=statUncResults.GetEntriesFast()-1-i; statUncResults.At(idx)->Draw(i==0?"hist":"histsame"); ((TH1*)statUncResults.At(idx))->SetTitle( i==0 ? "combined" :labels[idx] ); } leg = c->BuildLegend(); formatForCmsPublic(c,leg,"CMS simulation",3); c->Modified(); c->Update(); c->SaveAs(outDir+"/TopMassCalibrationStat.C"); c->SaveAs(outDir+"/TopMassCalibrationStat.png"); c->SaveAs(outDir+"/TopMassCalibrationStat.pdf"); //delete c; //pulls TGraphErrors *avgPull = new TGraphErrors; avgPull->SetMarkerStyle(20); TGraphErrors *sigmaPull = new TGraphErrors; sigmaPull->SetMarkerStyle(20); c=new TCanvas("pullsc","pullsc",1600,(pullResults.GetEntriesFast()/4+1)*400); c->SetWindowSize(1600,(pullResults.GetEntriesFast()/4+1)*400); c->Divide(4,pullResults.GetEntriesFast()/4+1); for(int i=0; i<pullResults.GetEntriesFast(); i++) { TPad *p=(TPad *)c->cd(i+1); TH1 *pullH=(TH1 *)pullResults.At(i); pullH->Draw("e1"); Float_t trueMass=mpts[i].Atof(); TF1 *gaus=pullH->GetFunction("gaus"); avgPull->SetPoint(i,trueMass,gaus->GetParameter(1)); avgPull->SetPointError(i,0,gaus->GetParError(1)); sigmaPull->SetPoint(i,trueMass,gaus->GetParameter(2)); sigmaPull->SetPointError(i,0,gaus->GetParError(2)); if(i==0) { leg = p->BuildLegend(); formatForCmsPublic(p,leg,"CMS simulation",3); leg->Delete(); } TPaveText *pave = new TPaveText(0.2,0.8,0.35,0.88,"NDC"); pave->SetTextFont(42); pave->SetFillStyle(0); pave->SetBorderSize(0); pave->AddText( mpts[i] )->SetTextAlign(11); pave->Draw(); } c->Modified(); c->Update(); c->SaveAs(outDir+"/TopMassCalibrationPulls.C"); c->SaveAs(outDir+"/TopMassCalibrationPulls.png"); c->SaveAs(outDir+"/TopMassCalibrationPulls.pdf"); //delete c; //pull momenta c=new TCanvas("pullsmomc","pullsmomc",600,600); c->SetWindowSize(600,600); c->Divide(1,2); p=(TPad *)c->cd(1); avgPull->Draw("ap"); avgPull->GetYaxis()->SetRangeUser(-3,3); avgPull->GetXaxis()->SetTitle("Generated m_{top} [GeV/c^{2}]"); avgPull->GetYaxis()->SetTitle("Average pull"); leg = p->BuildLegend(); formatForCmsPublic(p,leg,"CMS simulation",3); leg->Delete(); c->cd(2); sigmaPull->GetYaxis()->SetRangeUser(0.9,1.2); sigmaPull->Draw("ap"); sigmaPull->GetXaxis()->SetTitle("Generated m_{top} [GeV/c^{2}]"); sigmaPull->GetYaxis()->SetTitle("Pull width"); c->Modified(); c->Update(); c->SaveAs(outDir+"/TopMassCalibrationPullsMomenta.C"); c->SaveAs(outDir+"/TopMassCalibrationPullsMomenta.png"); c->SaveAs(outDir+"/TopMassCalibrationPullsMomenta.pdf"); //delete c; cout << report.str() << endl; }
void plotvn(){ gStyle->SetOptStat(kFALSE); int icent = 0; int n = 2; int color[nsub] = {1,2,4,5,7,8,2,4}; int style[12] = {20,21,24,25,26,27,29,30,31,32,33,34}; TGraphErrors *gr[nsub][3][2]; TGraphErrors *grraw[nsub][3][2]; TString CNTEP, dire; for(int isub=0;isub<nsub;isub++){ for(int idire=0;idire<3;idire++){ for(int iCNTEP=0;iCNTEP<1;iCNTEP++){ if(iCNTEP==0) CNTEP = "NoUseCNTEP"; if(iCNTEP==1) CNTEP = "UseCNTEP"; if(idire==0) dire = ""; if(idire==1) dire = "_east"; if(idire==2) dire = "_west"; TString str = choosesub(isub); if(str=="ABORT") continue; gr[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%d_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg"); grraw[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%draw_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg"); SetStyle(*gr[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]); SetStyle(*grraw[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]); } } } TGraphErrors *grv2 = new TGraphErrors("Result/v2_pAu_0_5_asys.dat","%lg %lg %lg"); //p+Au TGraphErrors *gr3 = new TGraphErrors("../../Ridge3sub/v2_cent0.dat"); TGraphErrors *gr3sub = new TGraphErrors("../../Ridge3sub/v2_cent0_scale1.dat"); TGraphErrors *grpc3 = new TGraphErrors("../usephiweightpc3/Result/NoUseCNTEP/v2_00_2_FVTX2p4p1LS.dat","%lg %lg %lg"); TGraphErrors *grAngle36 = new TGraphErrors("../usephiweight/Result/NoUseCNTEP/v2_00_0_FVTX2p4p1LS.dat","%lg %lg %lg"); TGraphErrors *grLow = new TGraphErrors("../usephiweightLowLumi/Result/NoUseCNTEP/v2_00_0_FVTX2p4p1LS.dat","%lg %lg %lg"); TGraphErrors *grHigh = new TGraphErrors("../usephiweightHighLumi/Result/NoUseCNTEP/v2_00_0_FVTX2p4p1LS.dat","%lg %lg %lg"); TH1F* h = new TH1F("h","",50,0,5); h->GetXaxis()->SetRangeUser(0,3.2); /* TCanvas *c1 = new TCanvas("c1","c1",800,450); iCNTEP = 0; idire = 0; c1->Divide(2); c1->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); h->GetXaxis()->SetRangeUser(0,3.2); //SetTitle(h,"","p_{T}","v_{2}^{raw}"); SetTitle(h,"","p_{T}","v_{2}"); h->DrawCopy(); TLegend *leg = new TLegend(0.2,0.7,0.5,0.9); leg->SetFillColor(0); leg->SetBorderSize(0); for(int ilay = 0;ilay<4;ilay++){ leg->AddEntry(gr[ilay+8][idire][iCNTEP],Form("FVTX layer %d",ilay)); gr[ilay+8][idire][iCNTEP]->Draw("Psame"); } gr[6][0][1]->Draw("Psame"); leg->AddEntry(gr[6][idire][iCNTEP],Form("FVTX -3.0<#eta<-1.0")); leg->Draw("Psame"); c1->cd(2); h->SetMinimum(0.8); h->SetMaximum(1.2); SetTitle(h,"","p_{T}","v_{2} ratio"); h->DrawCopy(); for(int ilay = 0;ilay<4;ilay++){ TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[ilay+8][idire][iCNTEP],gr[6][idire][iCNTEP]); SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[ilay+8]); grr->Draw("Psame"); } */ TCanvas *c2 = new TCanvas("c2","c2",800,450); iCNTEP = 0; idire = 0; c2->Divide(2); c2->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T}","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.2,0.7,0.5,0.9); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.05); SetStyle(*gr[4][idire][iCNTEP], 1.2, 2,style[2]); SetStyle(*gr[5][idire][iCNTEP], 1.2, 4,style[4]); SetStyle(*gr3, 1.2, 1,style[1]); SetStyle(*gr3sub, 1.2, 1,style[3]); SetStyle(*grv2, 1.2, 1,style[2]); gr[4][idire][iCNTEP]->Draw("Psame"); gr[5][idire][iCNTEP]->Draw("Psame"); //grv2->Draw("Psame"); //gr3->Draw("Psame"); //gr3sub->Draw("Psame"); leg->AddEntry(gr[4][idire][iCNTEP],Form("BBCs")); leg->AddEntry(gr[5][idire][iCNTEP],Form("FVTXs -3.0<#eta<-1.0")); //leg->AddEntry(gr[5][idire][iCNTEP],Form("p+Al event plane")); //leg->AddEntry(gr3,Form("p+Al 3-sub event method")); //leg->AddEntry(grv2,Form("PPG191 p+Au v2")); //leg->AddEntry(gr3sub,Form("3-sub non-flow PP subtracted")); leg->Draw("Psame"); c2->cd(2); h->SetMinimum(0.); h->SetMaximum(2); SetTitle(*h,"p_{T}","v_{2} ratio BBCs/FVTXs",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[4][idire][iCNTEP],gr[5][idire][iCNTEP]); SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(1); grr->Draw("Psame"); c2->Print(Form("FVTXvsBBCv%d.png",n)); TCanvas *c3 = new TCanvas("c3","c3",800,450); idire = 0; isub=7; c3->Divide(2); c3->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T}","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.2,0.7,0.5,0.88); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.05); SetStyle(*grLow, 1.2, 2,style[2]); SetStyle(*grHigh, 1.2, 4,style[4]); grLow->Draw("Psame"); grHigh->Draw("Psame"); gr[isub][idire][0]->Draw("Psame"); leg->AddEntry(gr[isub][idire][0],Form("Inclusive")); leg->AddEntry(grLow,Form("Low lumi runs < 500kHz"),"P"); leg->AddEntry(grHigh,Form("High lumi runs > 500kHz"),"P"); leg->Draw("Psame"); c3->cd(2); h->SetMinimum(0.); h->SetMaximum(2.); SetTitle(*h,"p_{T}","v_{2} ratio over Total",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(grLow,gr[isub][idire][0]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(2); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(grHigh,gr[isub][idire][0]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(4); grr->Draw("Psame"); c3->Print(Form("v%dFVTXs%dLH.png",n,isub)); TCanvas *c4 = new TCanvas("c4","c4",800,450); isub=3; iCNTEP = 0; c4->Divide(2); c4->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T} (GeV/c)","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.2,0.7,0.5,0.88); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.04); gr[isub][0][iCNTEP]->Draw("Psame"); gr[isub][1][iCNTEP]->Draw("Psame"); gr[isub][2][iCNTEP]->Draw("Psame"); if(isub==5) leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs -3.0<#eta<-1.0")); else if(isub<4) leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer %d -3.0<#eta<-1.0", isub+1)); else if(isub==6) leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer 2+4")); else if(isub==7) leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer 1+2+4")); leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P"); leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P"); leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P"); leg->Draw("Psame"); c4->cd(2); h->SetMinimum(0); h->SetMaximum(2); SetTitle(*h,"p_{T} (GeV/c)","v_{2} ratio",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]); SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(2); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]); SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(4); grr->Draw("Psame"); c4->Print(Form("v%dFVTXs%dEW.png",n,isub)); TCanvas *c5 = new TCanvas("c5","c5",800,450); isub=4; iCNTEP = 0; c5->Divide(2); c5->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T}","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.2,0.7,0.5,0.9); leg->SetTextSize(0.05); leg->SetFillColor(0); leg->SetBorderSize(0); gr[isub][0][iCNTEP]->Draw("Psame"); gr[isub][1][iCNTEP]->Draw("Psame"); gr[isub][2][iCNTEP]->Draw("Psame"); leg->AddEntry(gr[isub][0][iCNTEP],Form("Using BBC event plane")); leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P"); leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P"); leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P"); leg->Draw("Psame"); c5->cd(2); h->SetMinimum(0); h->SetMaximum(2.); SetTitle(*h,"p_{T}","v_{2} ratio",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]); SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(2); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]); SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(4); grr->Draw("Psame"); c5->Print(Form("v%dBBCs%dEW.png",n,isub)); TCanvas *c6 = new TCanvas("c6","c6",800,450); iCNTEP = 0; c6->Divide(2); c6->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T}","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.5,0.65,0.8,0.85); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.04); SetStyle(*gr[0][0][iCNTEP], 1.2, color[0],style[0]); SetStyle(*gr[1][0][iCNTEP], 1.2, color[1],style[1]); SetStyle(*gr[2][0][iCNTEP], 1.2, color[2],style[2]); SetStyle(*gr[3][0][iCNTEP], 1.2, color[4],style[4]); SetStyle(*gr[5][0][iCNTEP], 1.2, color[5],style[5]); gr[0][0][iCNTEP]->Draw("Psame"); gr[1][0][iCNTEP]->Draw("Psame"); gr[2][0][iCNTEP]->Draw("Psame"); gr[3][0][iCNTEP]->Draw("Psame"); gr[5][0][iCNTEP]->Draw("Psame"); leg->AddEntry(gr[0][0][iCNTEP],Form("FVTX 1LS"),"P"); leg->AddEntry(gr[1][0][iCNTEP],Form("FVTX 2LS"),"P"); leg->AddEntry(gr[2][0][iCNTEP],Form("FVTX 3LS"),"P"); leg->AddEntry(gr[3][0][iCNTEP],Form("FVTX 4LS"),"P"); leg->AddEntry(gr[5][0][iCNTEP],Form("FVTX All"),"P"); leg->Draw("same"); c6->cd(2); h->SetMinimum(0.5); h->SetMaximum(1.5); SetTitle(*h,"p_{T}","v_{2} ratio",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[0][0][iCNTEP],gr[5][0][iCNTEP]); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[1][0][iCNTEP],gr[5][0][iCNTEP]); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[2][0][iCNTEP],gr[5][0][iCNTEP]); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[3][0][iCNTEP],gr[5][0][iCNTEP]); grr->Draw("Psame"); c6->Print(Form("FVTXeachlayerv%d.png",n)); TCanvas *c7 = new TCanvas("c7","c7",800,450); iCNTEP = 0; c7->Divide(2); c7->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T}","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.5,0.75,0.8,0.85); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.05); SetStyle(*gr[5][0][iCNTEP], 1.2, color[5],style[0]); SetStyle(*gr[6][0][iCNTEP], 1.2, color[6],style[1]); SetStyle(*gr[7][0][iCNTEP], 1.2, color[7],style[2]); gr[5][0][iCNTEP]->Draw("Psame"); gr[6][0][iCNTEP]->Draw("Psame"); gr[7][0][iCNTEP]->Draw("Psame"); leg->AddEntry(gr[5][0][iCNTEP],Form("FVTX All"),"P"); leg->AddEntry(gr[6][0][iCNTEP],Form("FVTX 2+4 layer"),"P"); leg->AddEntry(gr[7][0][iCNTEP],Form("FVTX 1+2+4 layer"),"P"); leg->Draw("same"); c7->cd(2); h->SetMinimum(0.5); h->SetMaximum(1.5); SetTitle(*h,"p_{T}","v_{2} ratio",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[5][0][iCNTEP],gr[5][0][iCNTEP]); SetStyle(*grr,1.2,color[5],style[isub]); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[6][0][iCNTEP],gr[5][0][iCNTEP]); SetStyle(*grr,1.2,color[6],style[isub]); grr->Draw("Psame"); TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[7][0][iCNTEP],gr[5][0][iCNTEP]); SetStyle(*grr,1.2,color[7],style[isub]); grr->Draw("Psame"); c7->Print(Form("FVTXlayerCombv%d.png",n)); TCanvas *c8 = new TCanvas("c8","c8",800,450); idire = 0; isub=7; c8->Divide(2); c8->cd(1); h->SetMinimum(0); h->SetMaximum(0.3); SetTitle(*h,"p_{T}","v_{2}",""); h->DrawCopy(); TLegend *leg = new TLegend(0.2,0.7,0.5,0.88); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.05); SetStyle(*grAngle36, 1.2, 2,style[2]); gr[isub][idire][0]->Draw("Psame"); grAngle36->Draw("Psame"); leg->AddEntry(gr[isub][idire][0],Form("Angle=2.3mrad")); leg->AddEntry(grAngle36,Form("Angle=3.6mrad")); leg->Draw("Psame"); c8->cd(2); h->SetMinimum(0.); h->SetMaximum(2.); SetTitle(*h,"p_{T}","v_{2} ratio Angle=2.3mrad/Angle=2.6mrad",""); h->DrawCopy(); TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][idire][0],grAngle36); grr->Fit("pol0"); grr->GetFunction("pol0")->SetLineColor(4); grr->Draw("Psame"); c8->Print(Form("v%dFVTXs%dAngle.png",n,isub)); }
void fullCalib7_14(){ const int numRuns = 6; const char* files[numRuns] = { "../crunchedFiles/run_00393_crunched.root", "../crunchedFiles/run_00394_crunched.root", "../crunchedFiles/run_00395_crunched.root", "../crunchedFiles/run_00398_crunched.root", "../crunchedFiles/run_00399_crunched.root", "../crunchedFiles/run_00400_crunched.root" }; gStyle->SetOptFit(1); cout << "Which? " << endl; int which; cin >> which; vector<double> means; vector<double> sigs; vector<double> meanErrs; vector<double> sigErrs; for (int i = 0; i < numRuns; ++i){ TFile* f = new TFile(files[i]); TTree* t = (TTree*) f->Get("t"); cout << "got tree" << endl; t->Draw(Form("sipm%i.energy>>histo%i", which,i),Form("sipm%i.valid",which)); cout << "drew" << endl; cout << "finding obj" << endl; TH1F* h = (TH1F*) gROOT->FindObject(Form("histo%i",i)); h->Fit("gaus","0"); means.push_back(h->GetFunction("gaus")->GetParameter(1)); sigs.push_back(h->GetFunction("gaus")->GetParameter(2)); meanErrs.push_back(h->GetFunction("gaus")->GetParError(1)); sigErrs.push_back(h->GetFunction("gaus")->GetParError(2)); cout << "end itr" << endl; } vector<double> variances; vector<double> varianceErrors; for(int i = 0; i < means.size(); ++i){ variances.push_back(sigs[i]*sigs[i]); varianceErrors.push_back(2*sigs[i]*sigErrs[i]); } TGraphErrors* linGraph = new TGraphErrors(means.size(), &means[0], &variances[0], &meanErrs[0], &varianceErrors[0]); TGraphErrors* quadGraph = new TGraphErrors(means.size(), &means[0], &variances[0], &meanErrs[0], &varianceErrors[0]); linGraph->SetMarkerStyle(20); linGraph->Fit("pol1"); linGraph->SetTitle(Form("SiPM %i", which)); linGraph->GetFunction("pol1")->SetLineColor(kBlue); linGraph->GetXaxis()->SetTitle("Mean"); linGraph->GetYaxis()->SetTitle("#sigma^{2}"); quadGraph->SetMarkerStyle(20); quadGraph->Fit("pol2"); quadGraph->GetFunction("pol2")->SetLineColor(kRed); linGraph->Draw("ap"); quadGraph->Draw("psame"); }
void vertexAssociationFit(TFile* input, TFile* output) { // style gStyle->SetOptStat(0); gStyle->SetOptFit(111); gStyle->SetOptTitle(1); // margins gStyle->SetStatFormat("6.4g"); gStyle->SetFitFormat("5.2g"); gStyle->SetPadTopMargin(0.07); gStyle->SetPadBottomMargin(0.12); gStyle->SetPadLeftMargin(0.1); gStyle->SetPadRightMargin(0.02); // prepare the output // * canvas to put the fit per bin TCanvas* canvas_0 = new TCanvas("FitPerBin","Fit for each vertex bin",1200,900); canvas_0->Divide(4,4); // * canvas to put the plots per bin TCanvas* canvas_1 = new TCanvas("EffPerBin","Efficiency vs purity for each vertex bin",1200,900); canvas_1->Divide(4,4); // * canvas with other plots: slope vs nvertices, efficiency and purity for fixed cut, etc. TCanvas* canvas_2 = new TCanvas("jvAssociation","Efficiency vs purity summary plots",1000,600); canvas_2->Divide(4,2); // summary graphs TGraphErrors* slopeGraph = new TGraphErrors(nbins); slopeGraph->SetNameTitle("slopeGraph","expo slope in each n_PU bin"); TGraphErrors* constGraph = new TGraphErrors(nbins); constGraph->SetNameTitle("constGraph","expo normalization in each n_PU bin"); TGraphErrors* cuteffGraph = new TGraphErrors(nbins); cuteffGraph->SetNameTitle("cuteffGraph","Efficiency in each n_PU bin"); TGraphErrors* cutpurGraph = new TGraphErrors(nbins); cutpurGraph->SetNameTitle("cutpurGraph","Purity in each n_PU bin"); TGraphErrors* effcutGraph = new TGraphErrors(nbins); effcutGraph->SetNameTitle("effcutGraph","Cut for fixed efficiency in each n_PU bin"); TGraphErrors* effpurGraph = new TGraphErrors(nbins); effpurGraph->SetNameTitle("effpurGraph","Purity for fixed efficiency in each n_PU bin"); TGraphErrors* purcutGraph = new TGraphErrors(nbins); purcutGraph->SetNameTitle("purcutGraph","Cut for fixed purity in each n_PU bin"); TGraphErrors* pureffGraph = new TGraphErrors(nbins); pureffGraph->SetNameTitle("pureffGraph","Efficiency for fixed purity in each n_PU bin"); // loop over the directories double slope = 0.; double slopeError = -999.; double constnorm = 0.; double constError = -999.; TGraphErrors* result = NULL; TFitResultPtr fitRes(-1); double x,y, xe,ye; unsigned int index; TString histonames[nbins+1]; TString labelnames[nbins+1]; // get the histogram TH1* evts_per_PUbin = (TH1*)input->Get("finaldistros_ssvhpt/GoodJet/GoodJet_nvertices"); double sumTot(0), effTot(0); TLatex *latexLabel = new TLatex(); latexLabel->SetTextSize(0.05); latexLabel->SetTextFont(42); latexLabel->SetLineWidth(2); latexLabel->SetNDC(); TLatex *latexLabel2 = new TLatex(); latexLabel2->SetTextSize(0.09); latexLabel2->SetTextFont(42); latexLabel2->SetLineWidth(2); latexLabel2->SetNDC(); for(unsigned int i=0; i<=nbins; ++i) { // get the histogram labelnames[i]=Form("n_PU = %d bin",i); std::cout<<"labelnames["<<i<<"]"<<labelnames[i]<<std::endl; histonames[i]=Form("finaldistros_ssvhpt/GoodJet/GoodJet_jetvtx_ratio2b_%d_PUvtx",i); std::cout<<"seizing: histonames["<<i<<"]:"<<histonames[i]<<std::endl; TH1* fraction = (TH1*)input->Get(histonames[i]); //fraction->Rebin(2); // do it canvas_0->cd(i+1); fraction->SetTitle(""); MakeNiceHistoStyle(fraction); if(fraction) vertexAssociationAnalysis(fraction,i,slope,slopeError,constnorm,constError,result,fitRes); latexLabel2->DrawLatex(0.15, 0.85,labelnames[i]); latexLabel2->DrawLatex(0.15, 0.75,"CMS #sqrt{s}= 7 TeV"); gPad->Draw(); gPad->SetLogy(); MakeNiceStatBox(fraction); output->cd(); fraction->Write(); // plot canvas_1->cd(i+1); result->SetTitle(""); MakeNiceGraphStyle(result); result->Draw("alP"); latexLabel->DrawLatex(0.05, 0.95,labelnames[i]); result->GetXaxis()->SetTitle("Purity"); result->GetYaxis()->SetTitle("Efficiency"); result->GetXaxis()->SetRangeUser(0.8,1.2); result->GetYaxis()->SetRangeUser(0.85,1.0); output->cd(); result->Write(); // extract other quantities slopeGraph->SetPoint(i,i,slope); slopeGraph->SetPointError(i,0,slopeError); slopeGraph->GetXaxis()->SetTitle("n_{PU} vertices"); constGraph->SetPoint(i,i,constnorm); constGraph->SetPointError(i,0,constError); constGraph->GetXaxis()->SetTitle("n_{PU} vertices"); index = unsigned(((defaultCut-cutmin)/(cutmax-cutmin)*nSteps)+0.5); findWorkingPoint(result,index,x,y,xe,ye,1); // to compute the weighted efficiency int ivtx_bin=evts_per_PUbin->FindBin(i+1); sumTot+=evts_per_PUbin->GetBinContent(ivtx_bin); effTot+=y*evts_per_PUbin->GetBinContent(ivtx_bin); cuteffGraph->SetPoint(i,i,y); cuteffGraph->SetPointError(i,0,ye); cuteffGraph->GetXaxis()->SetTitle("n_{PU} vertices"); cutpurGraph->SetPoint(i,i,x); cutpurGraph->SetPointError(i,0,xe); cutpurGraph->GetXaxis()->SetTitle("n_{PU} vertices"); x = defaultPur; findWorkingPoint(result,index,x,y,xe,ye,2); purcutGraph->SetPoint(i,i,cutmin+(cutmax-cutmin)/nSteps*index); purcutGraph->GetXaxis()->SetTitle("n_{PU} vertices"); pureffGraph->SetPoint(i,i,y); pureffGraph->SetPointError(i,0,ye); pureffGraph->GetXaxis()->SetTitle("n_{PU} vertices"); y = defaultEff; findWorkingPoint(result,index,x,y,xe,ye,3); effcutGraph->SetPoint(i,i,cutmin+(cutmax-cutmin)/nSteps*index); effcutGraph->GetXaxis()->SetTitle("n_{PU} vertices"); effpurGraph->SetPoint(i,i,x); effpurGraph->SetPointError(i,0,xe); effpurGraph->GetXaxis()->SetTitle("n_{PU} vertices"); std::cout<<"end of other quantities: bin["<<i<<"]"<<std::endl; } std::cout << "Weighted Efficiency" << effTot/sumTot << std::endl; // plot summary graphs TF1* f=NULL; canvas_2->cd(1); MakeNiceGraphStyle(slopeGraph); slopeGraph->Draw("alP"); slopeGraph->Fit("pol1"); f = slopeGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) slopeGraph->Fit("pol0"); canvas_2->cd(2); MakeNiceGraphStyle(constGraph); constGraph->Draw("alP"); constGraph->Fit("pol2"); f = constGraph->GetFunction("pol2"); canvas_2->cd(3); MakeNiceGraphStyle(cuteffGraph); cuteffGraph->Draw("alP"); cuteffGraph->Fit("pol1"); f = cuteffGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) cuteffGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Jet Fraction cut: %.2f",defaultCut)); canvas_2->cd(4); MakeNiceGraphStyle(cutpurGraph); cutpurGraph->Draw("alP"); cutpurGraph->Fit("pol1"); f = cutpurGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) cutpurGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Jet Fraction cut: %.2f",defaultCut)); canvas_2->cd(5); MakeNiceGraphStyle(effcutGraph); effcutGraph->Draw("alP"); effcutGraph->Fit("expo"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed efficiency: %.2f",defaultEff)); canvas_2->cd(6); MakeNiceGraphStyle(effpurGraph); effpurGraph->Draw("alP"); effpurGraph->Fit("pol1"); f = effpurGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) effpurGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed efficiency: %.2f",defaultEff)); canvas_2->cd(7); gPad->SetLeftMargin(0.12); MakeNiceGraphStyle(purcutGraph); purcutGraph->Draw("alP"); purcutGraph->Fit("expo"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed purity: %.3f",defaultPur)); canvas_2->cd(8); MakeNiceGraphStyle(pureffGraph); pureffGraph->Draw("alP"); pureffGraph->Fit("pol1"); f = pureffGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) pureffGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed purity: %.3f",defaultPur)); // save output->cd(); canvas_0->Write(); canvas_1->Write(); canvas_2->Write(); canvas_0->SaveAs((TString)(canvas_0->GetName())+".png"); canvas_1->SaveAs((TString)(canvas_1->GetName())+".png"); canvas_2->SaveAs((TString)(canvas_2->GetName())+".png"); }
void CalcPeriod(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt, Int_t startEv = 1, char *PedFile) { // create progress bar TGHProgressBar *gProgress = ProgressBar("Calcolo periodo"); // Redefine DOMINO Depth in ADC counts const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH); // open file FILE *fdata = OpenDataFile(DataFile); struct channel_struct *p; struct channel_struct *dep; // create list of graphs for pedestals TList *grPedList = new TList(); TGraphErrors *grPed; // create period histogram TString title = "Period histogram"; TH1 *hPeriod = new TH1F(title,title, 2*((Int_t) DOMINO_NCELL), (Double_t) -DOMINO_NCELL, (Double_t) DOMINO_NCELL); // calculate or read pedestals from file grPedList = OpenPedestals(PedFile); grPed = (TGraphErrors *) grPedList->At(anaChannel); // Count number of events in data file int nevtDataMax = 0; while (!feof(fdata)) { fread((void *) &event_data, 1, sizeof(event_data), fdata); nevtDataMax++; } printf("nevtDataMax: %d\n", nevtDataMax - 1); if (nevt > (nevtDataMax - startEv) || nevt == 0) nevt = nevtDataMax - startEv; cout << endl << "==>> Processing " << nevt << " events from file " << DataFile << endl; rewind(fdata); Int_t ievt = 1; // go to first event (startEv) while (ievt < startEv) { fread((void *) &event_data, 1, sizeof(event_data), fdata); if (feof(fdata)) break; ievt++; } ievt = 1; Int_t flagEnd = 0; Int_t fitusati = 0; Double_t chtmp; Double_t PedVal, itmp; Double_t mean, rms; Double_t ratio; //debug canvas TCanvas *cfitTest = new TCanvas("cfitTest", "fit tests", 1200, 780); cfitTest->Divide(1,nevt); // loop on events gProgress->Reset(); gProgress->SetMax(nevt); gSystem->ProcessEvents(); while (ievt <= nevt && !flagEnd) { fread((void *) &event_data, 1, sizeof(event_data), fdata); if (feof(fdata)) flagEnd = 1; p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data // goes to channel to analyze p += anaChannel; // read data, subtract pedestals values and save results in grAnaChDataTemp graph with // fixed error for each point (x = 0.5 and y = 2.1). Also generate an array with Domino // X and Y values TGraphErrors *grAnaChDataTemp = new TGraphErrors(DOMINO_NCELL); for (int ch = 0; ch < DOMINO_NCELL; ch++) { // Read pedestal value for this cell grPed->GetPoint(ch, itmp, PedVal); chtmp = (Double_t)(p->data[ch]); // data value chtmp = chtmp - PedVal; grAnaChDataTemp->SetPoint(ch, (Double_t) ch, chtmp); grAnaChDataTemp->SetPointError(ch, 0.5, 2.1); } // create fit functions TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4); fsin->SetParameters(600., 255., 150., 150.); fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset"); grAnaChDataTemp->Fit("fsin", "Q"); TF1 *fsinFit = grAnaChDataTemp->GetFunction("fsin"); fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset"); // debug cfitTest->cd(ievt); grAnaChDataTemp->SetMarkerStyle(20); grAnaChDataTemp->SetMarkerSize(0.3); grAnaChDataTemp->GetYaxis()->SetLabelSize(0.12); grAnaChDataTemp->GetXaxis()->SetLabelSize(0.12); grAnaChDataTemp->Draw("APE"); Double_t fitPeriod, fitAmplitude, chisquare; fitPeriod = fsinFit->GetParameter("Period"); fitAmplitude = TMath::Abs(fsinFit->GetParameter("amplitude")); chisquare = fsinFit->GetChisquare(); cout << "period: " << fitPeriod << " amplitude: " << fitAmplitude << " chisquare: " << chisquare << endl; if(chisquare > 0.1e+06) { gProgress->Increment(1); gSystem->DispatchOneEvent(kTRUE); ievt++; continue; } gProgress->Increment(1); gSystem->DispatchOneEvent(kTRUE); hPeriod->Fill(fitPeriod); fitusati++; ievt++; } cout << "fit scartati :" << nevt - fitusati << endl; //draw TString Title = "Period distribution for nevt events"; TCanvas *cPeriod = new TCanvas("cPeriod", Title, 700, 700); hPeriod->Draw(); hPeriod->Fit("gaus"); TF1 *fgausFit = hPeriod->GetFunction("gaus"); //mean = fgausFit->GetParameter(1); // rms = fgausFit->GetParameter(2); mean = hPeriod->GetMean(); rms = hPeriod->GetRMS(); TString OutFile = "Period"; OutFile += nevt; OutFile += "events.dat"; FILE *f = fopen(OutFile.Data(), "w"); fwrite(&mean, sizeof(mean), 1, f); fwrite(&rms, sizeof(rms), 1, f); ((TGMainFrame *) gProgress->GetParent())->CloseWindow(); fclose(f); cout << "mean: " << mean << " rms: " << rms << endl; fclose(fdata); }
void residualAlignment(TH2D* residualX, TH2D* residualY, double& offsetX, double& offsetY, double& rotation, double relaxation, bool display) { assert(residualX && residualY && "Processors: can't perform residual alignment without histograms"); rotation = 0; offsetX = 0; offsetY = 0; double angleWeights = 0; double fitChi2 = 0; for (int axis = 0; axis < 2; axis++) { TH2D* hist = 0; if (axis) hist = residualX; else hist = residualY; // Project the histogram and fit with a gaussian to center the sensor TH1D* project = hist->ProjectionX("ResidualProjetion", 1, hist->GetNbinsY()); project->SetDirectory(0); double sigma = project->GetBinWidth(1); double mean = 0; fitGaussian(project, mean, sigma, false); if (axis) offsetX = mean; else offsetY = mean; delete project; std::vector<double> ptsX; std::vector<double> ptsY; std::vector<double> ptsErr; const unsigned int numSlices = hist->GetNbinsY(); for (Int_t row = 1; row <= (int)numSlices; row++) { TH1D* slice = hist->ProjectionX("ResidualSlice", row, row); slice->SetDirectory(0); double mean = 0; double sigma = 0; double factor = 0; double background = 0; if (slice->Integral() < 1) { delete slice; continue; } fitGaussian(slice, mean, sigma, factor, background, false); const double sliceMin = slice->GetBinCenter(1); const double sliceMax = slice->GetBinCenter(slice->GetNbinsX()); delete slice; // Quality assurance // Sigma is contained in the slice's range if (sigma > (sliceMax - sliceMin)) continue; // Mean is contained in the slice's range if (mean > sliceMax || mean < sliceMin) continue; // Peak is contains sufficient events if (factor < 100) continue; // Sufficient signal to noise ratio if (factor / background < 10) continue; // Get the total number of events in the gaussian 1 sigma Int_t sigRangeLow = hist->FindBin(mean - sigma); Int_t sigRangeHigh = hist->FindBin(mean + sigma); double sigRangeTotal = 0; for (Int_t bin = sigRangeLow; bin <= sigRangeHigh; bin++) sigRangeTotal += hist->GetBinContent(bin); // 2 * 1 sigma integral shoudl give ~ area under gaussian sigma /= sqrt(2 * sigRangeTotal); ptsX.push_back(hist->GetYaxis()->GetBinCenter(row)); ptsY.push_back(mean); ptsErr.push_back(sigma); } if (ptsX.size() < 3) continue; std::vector<double> yvals = ptsY; std::sort(yvals.begin(), yvals.end()); const double median = yvals[yvals.size()/2]; double avgDeviation = 0; for (unsigned int i = 0; i < yvals.size(); i++) avgDeviation += fabs(yvals[i] - median); avgDeviation /= (double)yvals.size(); std::vector<double> ptsXGood; std::vector<double> ptsYGood; std::vector<double> ptsErrGood; for (unsigned int i = 0; i < ptsX.size(); i++) { if (fabs(ptsY[i] - median) > 1.5*avgDeviation) continue; ptsXGood.push_back(ptsX[i]); ptsYGood.push_back(ptsY[i]); ptsErrGood.push_back(ptsErr[i]); } if (ptsXGood.size() < 3) continue; TGraphErrors* graph = new TGraphErrors(ptsXGood.size(), &(ptsXGood.at(0)), &(ptsYGood.at(0)), 0, &(ptsErrGood.at(0))); TF1* fitFunc = new TF1("f1", "1 ++ x"); TF1* result = 0; graph->Fit(fitFunc, "Q0E").Get(); result = graph->GetFunction(fitFunc->GetName()); // Weight the angle by the slope uncertainty and the inverse of the chi2 normalized double weight = result->GetParError(1); const double chi2 = result->GetChisquare() / (double)result->GetNDF(); fitChi2 += chi2; weight *= chi2; if (weight > 10 * DBL_MIN) weight = 1.0 / weight; else weight = 1.0; if (axis) { rotation -= weight * atan(result->GetParameter(1)); offsetX = result->GetParameter(0); } else { rotation += weight * atan(result->GetParameter(1)); offsetY = result->GetParameter(0); } angleWeights += weight; if (display) { TCanvas* can = new TCanvas("ResidualAlignment", "Residual Alignment", 900, 600); can->Divide(2); can->cd(1); hist->Draw("COLZ"); can->cd(2); result->SetLineColor(46); result->SetLineWidth(2); graph->Draw("ap"); result->Draw("SAME"); can->Update(); can->WaitPrimitive(); } delete fitFunc; delete graph; } if (angleWeights > 10 * DBL_MIN) rotation /= angleWeights; std::cout << "relaxation: " << relaxation << std::endl; rotation *= relaxation; offsetX *= relaxation; offsetY *= relaxation; }
int plotJetResponseAlpha(int variable){ gDirectory->Delete(); gROOT->GetListOfCanvases()->Delete(); TString sourceResponseAlpha, sourceIntrinsicAlpha, sourceImbalanceAlpha, sourceTotalAlpha, pdfFile, etaRegion, ptRegion, title, EtaPtRegion; double ptBorders[pt_int+1] = {0}; double etaBorders[eta_int+1] = {0}; etaBorders[0] = 0.0; etaBorders[1] = 0.5; etaBorders[2] = 1.1; etaBorders[3] = 1.7; etaBorders[4] = 2.3; ptBorders[0] = 22; ptBorders[1] = 33; ptBorders[2] = 55; ptBorders[3] = 82.5; ptBorders[4] = 99; ptBorders[5] = 148.5; ptBorders[6] = 165; ptBorders[7] = 176; ptBorders[8] = 200; ptBorders[9] = 250; ptBorders[10] = 300; ptBorders[11] = 400; TLatex* info; TLegend *legend; TGraphErrors* Add; TF1 *fScaleAlpha; TF1 *total; for(int j=0; j<eta_int; j++){ for(int i=pt_int-1;i<pt_int;i++){ if(variable ==1){ //sourceResponseAlpha.Form("plots_2012/mc/PF_L1FastJet/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_PF_mc.root",j+1,i+1); //sourceIntrinsicAlpha.Form("plots_2012/mc/PF_L1FastJet/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_intrinsic_PF_mc.root",j+1,i+1); //sourceImbalanceAlpha.Form("plots_2012/mc/PF_L1FastJet/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_imbalance_PF_mc.root",j+1,i+1); //sourceTotalAlpha.Form("plots_2012/mc/PF_L1FastJet/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_total_PF_mc.root",j+1,i+1); //pdfFile.Form("plots_2012/PF_L1FastJet/mc/pdfs/JES_for_%i_eta_bin_%i_pTGamma_bin_ALL_PF_mc.pdf",j+1,i+1); sourceResponseAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_PF_mc.root",j+1,i+1); sourceIntrinsicAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_intrinsic_PF_mc.root",j+1,i+1); sourceImbalanceAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_imbalance_PF_mc.root",j+1,i+1); sourceTotalAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_scale_for_%i_eta_bin_%i_pTGamma_bin_total_PF_mc.root",j+1,i+1); pdfFile.Form("plots_2012/PF_L1FastJet/mc/pdfs/JES_for_%i_eta_bin_%i_pTGamma_bin_ALL_PF_mc.pdf",j+1,i+1); title = "Jet Energy Scale"; } else if(variable == 2){ //sourceResponseAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_PF_mc.root",j+1,i+1); //sourceIntrinsicAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_intrinsic_PF_mc.root",j+1,i+1); //sourceImbalanceAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_imbalance_PF_mc.root",j+1,i+1); //sourceTotalAlpha.Form("plots_2012/PF_L1FastJet/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_total_PF_mc.root",j+1,i+1); sourceResponseAlpha.Form("plots_2012/PF_L1CHS/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_PFCHS_mc.root",j+1,i+1); sourceIntrinsicAlpha.Form("plots_2012/PF_L1CHS/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_intrinsic_PFCHS_mc.root",j+1,i+1); sourceImbalanceAlpha.Form("plots_2012/PF_L1CHS/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_imbalance_PFCHS_mc.root",j+1,i+1); sourceTotalAlpha.Form("plots_2012/PF_L1CHS/mc/root_files/jet_energy_resolution_for_%i_eta_bin_%i_pTGamma_bin_total_PFCHS_mc.root",j+1,i+1); //pdfFile.Form("plots_2012/PF_L1FastJet/mc/JER_for_%i_eta_bin_%i_pTGamma_bin_ALL_PF_mc.pdf",j+1,i+1); pdfFile.Form("plots_2012/PF_L1CHS/mc/pdfs/JER_for_%i_eta_bin_%i_pTGamma_bin_ALL_PF_mc.pdf",j+1,i+1); title = "Jet Energy Resolution"; } if (i==pt_int-1) ptRegion.Form(" %4.1f GeV < p_{T}^{#gamma} \n",ptBorders[i]); else ptRegion.Form("%4.1f GeV < p_{T}^{#gamma} < %4.1f GeV \n" ,ptBorders[i], ptBorders[i+1]); if(j == 0) etaRegion.Form("|#eta| < %4.1f", etaBorders[j+1]); else etaRegion.Form("%4.1f < #eta < %4.1f",etaBorders[j], etaBorders[j+1]); EtaPtRegion.Form("#splitline{%s}{%s}",ptRegion.Data(),etaRegion.Data()); TCanvas *c = new TCanvas(EtaPtRegion,title,200,10,450,450); c -> SetLeftMargin(0.12); c -> cd(); c->SetBottomMargin(0.12); c->SetLeftMargin(0.12); legend = new TLegend(0.5,0.7,0.9,0.9); legend -> SetFillColor(0); legend -> SetTextSize(0.030); Add = readTGraphErrors(sourceResponseAlpha,"Graph;1","Graph;1"); if(variable == 1) fScaleAlpha = Add->GetFunction("fScaleAlpha"); else fScaleAlpha = Add->GetFunction("fResolutionAlpha"); Add -> SetMarkerColor(2); Add -> SetLineColor(2); fScaleAlpha -> SetLineColor(2); Add -> GetXaxis()->SetTitleSize(0.04); Add -> GetYaxis()->SetTitleSize(0.04); Add -> GetXaxis() -> SetTitle("p_{T}^{Jet_{2}}/p_{T}^{#gamma} #upoint 100"); Add -> GetYaxis() -> SetTitle("Resolution"); Add -> Draw("AP"); Add -> SetTitle(""); Add -> GetYaxis() -> SetTitleOffset(1.5); Add -> GetXaxis() -> SetTitleOffset(1.2); if(variable ==1){ Add -> GetYaxis() -> SetTitle("JES"); Add -> SetMinimum(0.8); Add -> SetMaximum(1.1); } else if(variable ==2){ //Add -> GetYaxis() -> SetTitle("JER"); Add -> SetMinimum(0.0); Add -> SetMaximum(0.4); } Add -> GetXaxis()->SetLimits(0,20); legend -> AddEntry(Add,"#gamma + Jet (pseudo data)","l"); // Intrinsic Add = readTGraphErrors(sourceIntrinsicAlpha,"Graph;1","Graph;1"); if(variable == 1) fScaleAlpha = Add->GetFunction("fScaleAlpha"); else fScaleAlpha = Add->GetFunction("fResolutionAlpha"); Add -> SetMarkerColor(4); Add -> SetLineColor(4); fScaleAlpha -> SetLineColor(4); legend -> AddEntry(Add,"Intrinsic","l"); Add->SetTitle(""); Add -> GetXaxis()->SetTitleSize(0.04); Add -> GetYaxis()->SetTitleSize(0.04); Add -> GetYaxis() -> SetTitleOffset(1.5); Add -> GetXaxis() -> SetTitleOffset(1.2); Add -> GetXaxis() -> SetTitle("p_{T}^{Jet_{2}}/p_{T}^{#gamma} #upoint 100"); Add -> GetYaxis() -> SetTitle("Resolution"); Add -> Draw("Psame"); Add = readTGraphErrors(sourceImbalanceAlpha,"Graph;1","Graph;1"); if(variable == 1) fScaleAlpha = Add->GetFunction("fScaleAlpha"); else fScaleAlpha = Add->GetFunction("fResolutionAlpha"); Add -> SetMarkerColor(1); Add -> SetLineColor(1); fScaleAlpha -> SetLineColor(1); legend -> AddEntry(Add,"Imbalance","l"); Add -> Draw("Psame"); if(variable == 1) total = readTF1(sourceTotalAlpha,"totalScale;1", "totalScale;1"); else total = readTF1(sourceTotalAlpha,"totalResolution;1", "totalResolution;1"); total -> SetLineColor(14); total -> SetLineWidth(3); legend -> AddEntry(total,"Total","l"); total -> Draw("same"); // Draw info boxes info = new TLatex(); info->SetTextFont(132); info-> SetNDC(); info->SetTextSize(0.035); if(variable == 1){ info->DrawLatex(0.22,0.2, EtaPtRegion); info->DrawLatex(0.60,0.2, "Anti-k_{T} 0.5 PFJets"); } else{ info->DrawLatex(0.22,0.6, EtaPtRegion); info->DrawLatex(0.60,0.6, "Anti-k_{T} 0.5 PFJets"); } legend -> Draw("same"); c -> SaveAs(pdfFile); //delete info; //delete total; //delete legend; //delete fScaleAlpha; //delete Add; } } // FINAL PLOTS return 0; }
void Fitting(){ TString RootFile_Name; TString Target, Arm; gSystem->Exec("ls -l *.root"); cerr<<" --- Target (H2,He3,He4) = "; cin >> Target; cerr<<" --- Arm (L, R) = "; cin >> Arm; RootFile_Name = Form("%s_Yield_%s_All.root",Target.Data(),Arm.Data()); TFile *f1 = new TFile(RootFile_Name.Data(),"r"); TTree *T = (TTree*) gDirectory->Get("T"); TString OutFile_Name = RootFile_Name; OutFile_Name.ReplaceAll(".root",".out"); ofstream outfile(OutFile_Name); TString File_Name1 = RootFile_Name; TString File_Name2 = RootFile_Name; TString File_Name3 = RootFile_Name; TString File_Name4 = RootFile_Name; File_Name1.ReplaceAll(".root",".png"); File_Name2.ReplaceAll(".root",".pdf"); File_Name3.ReplaceAll(".root","_0.png"); File_Name4.ReplaceAll(".root","_0.pdf"); double VZ, I, Y, Y_Err; int size, runno, Bin; T->SetBranchAddress("runsize",&size); T->SetBranchAddress("Bin",&Bin); T->SetBranchAddress("RunNo",&runno); T->SetBranchAddress("I",&I); T->SetBranchAddress("Y",&Y); T->SetBranchAddress("Y_Err",&Y_Err); T->SetBranchAddress("VZ",&VZ); int N = T->GetEntries(); T->GetEntry(0); const int Size = size; int temp=20; if(Target=="C12"||Target=="Ca40"||Target=="Ca48") temp=1; const int Bin_Size = temp; /*Read Root File{{{*/ cerr<<" @@@ Reading Root File ..."<<endl; double vI[Bin_Size][Size]; double vI_Err[Bin_Size][Size]; double vY[Bin_Size][Size]; double vY_Err[Bin_Size][Size]; double vVZ[Bin_Size]; double Y_Max=-1e32,Y_Min=1e32, X_Max=-1000,X_Min=1000; int k=0; for(int j=0;j<Bin_Size; j++){ k=0; for(int i=0;i<N;i++){ T->GetEntry(i); if(Y>-0.5 && Bin==j){ vI[j][k]=I; vI_Err[j][k]=0.; vY[j][k]=Y; vY_Err[j][k]=Y_Err; vVZ[j] = VZ; if(X_Max<vI[j][k]) X_Max = vI[j][k]; if(X_Min>vI[j][k]) X_Min = vI[j][k]; if(Y_Max<vY[j][k]) Y_Max = vY[j][k]; if(Y_Min>vY[j][k]) Y_Min = vY[j][k]; // Y_Max = Y_Max?vY[j][k]:Y_Max<vY[j][k]; // Y_Min = Y_Min?vY[j][k]:Y_Min>vY[j][k]; // X_Max = X_Max?vI[j][k]:X_Max<vI[j][k]; // X_Min = X_Min?vI[j][k]:X_Min>vI[j][k]; cerr<<Form("--- Bin = %d, VZ=%6.4f, I=%6.4f, Y=%e", Bin, VZ, I, Y)<<endl; k++; if(k>Size) cerr<<"*** Something wrong?!"<<endl; } } } /*}}}*/ /*Plot and Fit{{{*/ cerr<<" @@@ Making Plots and Fitting ..."<<endl; cerr<<Form(" ---- X_Min=%f, X_Max=%f, Y_Min=%e, Y_Max=%e",X_Min,X_Max, Y_Min, Y_Max)<<endl; TCanvas *c3 = new TCanvas("c3","c3",1200,700); c3->cd(); TH2F *h3 = new TH2F("h3","",300,X_Min-2.0,X_Max+2.0,300,0.0,Y_Max/Y_Min*1.12); h3->SetStats(kFALSE); h3->SetXTitle("I (uA)"); h3->GetXaxis()->CenterTitle(1); h3->GetXaxis()->SetTitleFont(32); h3->GetXaxis()->SetTitleSize(0.06); h3->GetYaxis()->SetTitleOffset(0.8); h3->SetYTitle("Yield_{normalized}"); h3->GetYaxis()->CenterTitle(1); h3->GetYaxis()->SetTitleFont(32); h3->GetYaxis()->SetTitleSize(0.06); h3->GetYaxis()->SetTitleOffset(0.8); gStyle->SetOptStat(1); gStyle->SetOptFit(1); double S[Bin_Size],S_Err[Bin_Size]; double Y0[Bin_Size],Y0_Err[Bin_Size]; double BF[Bin_Size],BF_Err[Bin_Size]; double Zero[Bin_Size]; for(int l=0; l<Bin_Size; l++){ for(int m=0; m<Size; m++){ vY[l][m]/=Y_Min; vY_Err[l][m]/=Y_Min; } } TLatex *tex; outfile<<Form("%12s %12s %12s %12s %12s", "VZ","Y0","Y0_Err","BF","BF_Err")<<endl; Y_Max=-1e32,Y_Min=1e32; for(int l=0; l<Bin_Size; l++){ h3->Draw(); for(int m=0;m<Size;m++) cerr<<Form(" VZ=%6.4f, I = %6.3f, Y = %e", vVZ[l], vI[l][m],vY[l][m])<<endl; TGraphErrors *ex = new TGraphErrors(Size, vI[l], vY[l], vI_Err[l], vY_Err[l]); ex->SetMarkerStyle(25); ex->SetMarkerColor(4); ex->SetLineColor(4); ex->Draw("P"); ex->Fit("pol1","IM","",X_Min,X_Max); if(l==0){//For C12 only // if(l==30){ tex=new TLatex(0.25, 0.6, Form("%s Boiling Effect Fit at z_{react} = %4.2f cm on HRS-%s",Target.Data(), vVZ[l]*100, Arm.Data())); tex->SetNDC(); tex->SetTextFont(32); tex->SetTextSize(0.05); tex->Draw(); c3->Print(File_Name3.Data()); c3->Print(File_Name4.Data()); } Y0[l] = ex->GetFunction("pol1")->GetParameter(0) ; Y0_Err[l] = ex->GetFunction("pol1")->GetParError(0) ; S[l] = ex->GetFunction("pol1")->GetParameter(1); S_Err[l] = ex->GetFunction("pol1")->GetParError(1); BF[l] = S[l]/Y0[l]; BF_Err[l] = BF[l] * sqrt( pow(Y0_Err[l]/Y0[l],2) + pow(S_Err[l]/S[l],2) ); Zero[l] = 0.0; if(Y_Max<S[l]) Y_Max = S[l]; if(Y_Min>S[l]) Y_Min = S[l]; cerr<<Form(" VZ=%f, Slop=%f",vVZ[l],S[l])<<endl; outfile<<Form(" %12.8f %12.8f %12.8f %12.8f %12.8f",vVZ[l],Y0[l], Y0_Err[l], BF[l],BF_Err[l])<<endl; c3->Clear(); } c3->Close(); TCanvas *c4 = new TCanvas("c4","c4",1200,700); c4->cd(); TH2F *h4 = new TH2F("h4","",300, -0.14, 0.14, 300, -0.011, 0.001); h4->SetStats(kFALSE); h4->SetXTitle("z_{react} (m)"); h4->GetXaxis()->CenterTitle(1); h4->GetXaxis()->SetTitleFont(32); h4->GetXaxis()->SetTitleSize(0.06); h4->GetXaxis()->SetTitleOffset(0.7); h4->SetYTitle("BF"); h4->GetYaxis()->CenterTitle(1); h4->GetYaxis()->SetTitleFont(32); h4->GetYaxis()->SetTitleSize(0.04); h4->GetYaxis()->SetTitleOffset(1.2); h4->Draw(); TGraphErrors *ex1 = new TGraphErrors(Bin_Size, vVZ, BF, Zero, BF_Err); ex1->SetMarkerStyle(20); ex1->SetMarkerColor(4); ex1->SetLineColor(4); ex1->Draw("P"); tex=new TLatex(0.3, 0.2, Form("%s Boiling Effect on HRS-%s",Target.Data(), Arm.Data())); tex->SetNDC(); tex->SetTextFont(32); tex->SetTextSize(0.05); tex->Draw(); c4->Print(File_Name1.Data()); c4->Print(File_Name2.Data()); /*}}}*/ }
void fit_fy_vs_y_from_all_angles(TString tgt_pos){ // histo parameters gStyle->SetTitleYOffset(1.2); gStyle->SetTitleXOffset(1.0); gStyle->SetLabelSize(0.06,"x"); gStyle->SetLabelSize(0.06,"y"); gStyle->SetTitleSize(0.06,"x"); gStyle->SetTitleSize(0.06,"y"); gStyle->SetTitleX(0.4); gStyle->SetTitleW(0.6); gStyle->SetTitleBorderSize(0); gStyle->SetTitleFillColor(0); gStyle->SetTitleFontSize(0.09); gStyle->SetStripDecimals(0); // Fit and stat parameters gStyle->SetOptFit(1111); gStyle->SetOptStat(0); gStyle->SetStatFont(132); gStyle->SetStatY(0.99); gStyle->SetStatX(0.99); gStyle->SetStatW(0.20); gStyle->SetStatH(0.20); //Pad parameters gStyle->SetPadColor(0); gStyle->SetPadBorderMode(0); gStyle->SetFrameBorderMode(0); gStyle->SetPadBorderSize(0); gStyle->SetPadTopMargin(0.18); gStyle->SetPadBottomMargin(0.16); gStyle->SetPadRightMargin(0.05); gStyle->SetPadLeftMargin(0.15); //set target flag if(tgt_pos.Contains("us")) upstream = true; else upstream = false; // Open a file to output the fy values fp = fopen(Form("%s_al_fy_for_all_angles.txt",tgt_pos.Data()), "w+"); // fprintf(fp, This is testing for fprintf...\n"); // fputs("This is testing for fputs...\n", fp); //Delete all the objects stored in the current directory memmory gDirectory->Delete("*"); std::vector<std::string> files; Double_t angles[6] = {18,22,26,32,40,50}; // vectors to store the fy and y from individual angles and their errors TVectorD *fyv = new TVectorD(); TVectorD *yv= new TVectorD(); TVectorD *yev= new TVectorD(); TVectorD *fyev= new TVectorD(); // vectors to store the fy_data/fy_model ratio and its error TVectorD *ratio = new TVectorD(); TVectorD *eratio = new TVectorD(); // vectors to store all the data together TVectorD *tfyv = new TVectorD(); TVectorD *tyv= new TVectorD(); TVectorD *tyev= new TVectorD(); TVectorD *tfyev= new TVectorD(); // Open canvas to draw the comparision between Fy vs Y using sig_exp and sig_exp corrected for sig_di// s TCanvas * c = new TCanvas("c", "",0,0,1000,1000); c->Draw(); c->Divide(1,2); Int_t pp = 0; // select files for a target with the given angle and get fy and y for(int i=0;i<6;i++){ std::cout<<"reading angle = "<<angles[i]<<std::endl; files = get_files(angles[i], tgt_pos); if(nodata){ //skip. Do nothing nodata = false; } else{ // get the fy and y from data with their errors get_fy_y(files, fyv, yv, yev, fyev); for(int k =0;k<fyv->GetNoElements();k++){ // Fill the full arrays (*tfyv).ResizeTo(pp+1); (*tfyev).ResizeTo(pp+1); (*tyv).ResizeTo(pp+1); (*tyev).ResizeTo(pp+1); (*tfyv).operator()(pp) = (*fyv)[k]; (*tfyev).operator()(pp) = (*fyev)[k]; (*tyv).operator()(pp) = (*yv)[k]; (*tyev).operator()(pp) = (*yev)[k]; // Fill the full ratio arrays (*ratio).ResizeTo(pp+1); (*eratio).ResizeTo(pp+1); (*ratio).operator()(pp)=((*fyv)[k]/al_fy_from_pass0((*yv)[k])); //std::cout<<ratio(k)<<std::endl; (*eratio).operator()(pp)=((*fyev)[k]/al_fy_from_pass0((*yv)[k])); std::cout<<" @ y = "<<(*yv)[k]<<" (ratio, eratio) = "<<"("<<(*ratio)[pp]<<","<<(*eratio)[pp]<<")"<<std::endl; pp++; } } } TLegend * leg= new TLegend(0.2,0.6,0.4,0.8); myfunc(); TGraphErrors *gp = new TGraphErrors(*tyv,*tfyv,*tyev,*tfyev); c->cd(1); gPad->SetGridy(); gPad->SetGridx(); gp->Draw("AEP"); gp->SetMarkerStyle(4); gp->SetMarkerColor(kBlue); gp->SetLineStyle(1); gp->SetLineColor(kBlue); gp->Fit("myfunc","EBMR"); TF1 *tfit = gp->GetFunction("myfunc"); tfit->SetLineColor(kRed); gp->GetYaxis()->SetRangeUser(0,4); gp->GetXaxis()->SetRangeUser(-1.0,0.2); gp->GetXaxis()->SetTitle("y(GeV/c)"); gp->GetYaxis()->SetTitle("F(y)(GeV/c)^{-1}"); gp->SetTitle(""); leg->AddEntry(gp,"data","p"); leg->AddEntry(tfit,"F(y) from pass1","l"); // From model: myfunc(); TF1 *ft = new TF1("ft"," al_fy_from_pass0(x)",-1.0,0.1); ft->SetLineColor(kBlack); ft->SetLineStyle(1); // draw the model ft->Draw("same"); leg->AddEntry(ft,"F(y) model","l"); leg->Draw(); // Draw in log scale c->cd(2); gPad->SetGridy(); gPad->SetGridx(); gp->Draw("AEP"); ft->Draw("same"); gPad->Modified(); gPad->Update(); gPad->SetLogy(); gp->GetYaxis()->SetRangeUser(1e-6,10); gp->GetXaxis()->SetRangeUser(-1.0,0.2); gp->SetTitle(Form("%s Al, Y scaling with DIS subtraction;y(GeV/c);F(y,q)(GeV/c)^{-1}",tgt_pos.Data())); leg->Draw(); TCanvas * c1 = new TCanvas("c1", "",0,0,700,500); c1->Draw(); gPad->SetGridy(); gPad->SetGridx(); // Fill the ratio graphs TGraphErrors * grr = new TGraphErrors(*tyv,*ratio,*tyev,*eratio); grr->SetMarkerStyle(2); grr->SetMarkerColor(2); grr->SetLineStyle(1); grr->SetLineColor(2); grr->Draw("AEP"); //grr->GetYaxis()->SetRangeUser(-100); grr->GetXaxis()->SetRangeUser(-1.0,0.2); grr->GetXaxis()->SetTitle("y(GeV/c)"); grr->GetYaxis()->SetTitle("data_{F(y)}/model_{F(y)}"); //close the text file fclose(fp); // // // c->Print(Form("xsec_rad_exp_mod_ratio_x_geq_%2.1f_and_x_leq_%2.1f_%s_dummy_%s_%s.png",xlow,xup,tgt_pos.Data(),angle.Data(),fit.Data())); }
double fResX(int trkA, int trkB, int trkC, int trkD, int test, double *GemCluster1d_x, double *GemCluster1d_dx, double *GemCluster1d_z, double *GemCluster1d_dz, double *Chi2, float *dispX_trkA, float *dispX_trkB, float *dispX_trkC, float *dispX_trkD) { double x[4],z[4],dx[4],dz[4]; double xfit, dispX; double A_ZX,B_ZX; int n=4; TGraphErrors *plotZX; TF1 *fitZX; dispX=0.; x[0] = GemCluster1d_x[trkA] + tiltX_TRKA; dx[0] = GemCluster1d_dx[trkA]; z[0] = GemCluster1d_z[trkA]; dz[0] = GemCluster1d_dz[trkA]; x[1] = GemCluster1d_x[trkB] + tiltX_TRKB; dx[1] = GemCluster1d_dx[trkB]; z[1] = GemCluster1d_z[trkB]; dz[1] = GemCluster1d_dz[trkB]; x[2] = GemCluster1d_x[trkC] + tiltX_TRKC; dx[2] = GemCluster1d_dx[trkC]; z[2] = GemCluster1d_z[trkC]; dz[2] = GemCluster1d_dz[trkC]; x[3] = GemCluster1d_x[trkD] + tiltX_TRKD; dx[3] = GemCluster1d_dx[trkD]; z[3] = GemCluster1d_z[trkD]; dz[3] = GemCluster1d_dz[trkD]; //cout << x[0] << " " << z[0] << " " << x[1] << " " << z[1] << " " << x[2] << " " << z[2] << " " << x[3] << " " << z[3] << " " << endl; plotZX = new TGraphErrors(n,z,x,dz,dx); plotZX->Fit("pol1","Q"); fitZX = plotZX->GetFunction("pol1"); A_ZX = fitZX -> GetParameter(0); B_ZX = fitZX -> GetParameter(1); *Chi2 = (double) (fitZX->GetChisquare()); //cout << GemCluster1d_z[test] << " " << A_ZX << " " << B_ZX << endl; xfit = A_ZX + (GemCluster1d_z[test]*B_ZX); //cout<<"xfit "<<xfit<<" xtest "<<GemCluster1d_x[test]<<endl; dispX = (xfit - (GemCluster1d_x[test] + tiltX_TEST)); //cout << dispX << " " << xfit << " " << GemCluster1d_x[test] << " " << test << " " << tiltX_TEST << endl; xfit = A_ZX + (GemCluster1d_z[trkA]*B_ZX); *dispX_trkA = (xfit - (GemCluster1d_x[trkA] + tiltX_TRKA)); xfit = A_ZX + (GemCluster1d_z[trkB]*B_ZX); *dispX_trkB = (xfit - (GemCluster1d_x[trkB] + tiltX_TRKB)); xfit = A_ZX + (GemCluster1d_z[trkC]*B_ZX); *dispX_trkC = (xfit - (GemCluster1d_x[trkC] + tiltX_TRKC)); xfit = A_ZX + (GemCluster1d_z[trkD]*B_ZX); *dispX_trkD = (xfit - (GemCluster1d_x[trkD] + tiltX_TRKD)); //plotZX->~TGraphErrors() ; //fitZX->~TF1(); return dispX; }
void drawBeamSpotGraph (TDirectory* directory, TH1* refHisto, const char* name, const char* fname, float* runSummary = 0) { TGraphErrors* graph = directory->Get(name); if ( graph==0 ) return; gStyle->SetOptFit(1); gStyle->SetOptStat(0); char newName[64]; newName[0] = 'c'; strcpy(&newName[1],name); std::string fullName(name); if ( fname ) fullName += fname; else fullName += directory->GetName(); TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str()); newName[0] = 'h'; TH1* h = refHisto->Clone(newName); h->Reset(); h->SetTitle(name); std::string xTitle("Luminosity block / "); xTitle += directory->GetName(); h->GetXaxis()->SetTitle(xTitle->c_str()); // int nb = h->GetNbinsX(); // if ( nb>50 ) { // int iscale = nb/50+1; // TAxis* xaxis = h->GetXaxis(); // for ( int i=1; i<=h->GetNbinsX(); ++i ) { // if ( (i-1)%iscale ) xaxis->SetBinLabel(i,""); // } // } TAxis* yaxis = h->GetYaxis(); float scale(1); if ( strcmp(name,"x")==0 ) { yaxis->SetTitle("PV x position [mm]"); scale = 10.; } else if ( strcmp(name,"y")==0 ) { yaxis->SetTitle("PV y position [mm]"); scale = 10.; } else if ( strcmp(name,"z")==0 ) { yaxis->SetTitle("PV z position [cm]"); } else if ( strcmp(name,"ex")==0 ) { yaxis->SetTitle("PV x width [#mum]"); scale = 10000.; } else if ( strcmp(name,"ey")==0 ) { yaxis->SetTitle("PV y width [#mum]"); scale = 10000.; } else if ( strcmp(name,"ez")==0 ) { yaxis->SetTitle("PV z width [cm]"); } else if ( strcmp(name,"corrxy")==0 ) { yaxis->SetTitle("PV x-y correlation"); } else if ( strcmp(name,"dxdz")==0 ) { yaxis->SetTitle("PV slope dx/dz [10^{-3}]"); scale = 1000.; } else if ( strcmp(name,"dydz")==0 ) { yaxis->SetTitle("PV slope dy/dz [10^{-3}]"); scale = 1000.; } scaleGraph(graph,scale); double xmin,xmax,ymin,ymax; graph->ComputeRange(xmin,ymin,xmax,ymax); h->SetMinimum((ymax+ymin)/2.-2.*(ymax-ymin)/2.); h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.); h->Draw(); graph->SetMarkerStyle(20); // graph->SetMarkerColor(2); // graph->SetLineColor(2); graph->Draw("P"); graph->Fit("pol1","same"); graph->GetFunction("pol1")->SetLineStyle(2); graph->GetFunction("pol1")->SetLineWidth(2); TF1* fit = graph->GetFunction("pol1"); cout << "Pol1 fit chi2 = " << fit->GetChisquare() << " " << fit->GetNDF() << endl; // string epsName = fullName + ".eps"; // c->SaveAs(epsName.c_str()); // string pngName = fullName + ".png"; // c->SaveAs(pngName.c_str()); if ( runSummary ) { TF1* fit = graph->GetFunction("pol1"); runSummary[0] = fit->GetChisquare(); runSummary[1] = fit->GetNDF(); runSummary[2] = fit->GetParameter(0); runSummary[3] = fit->GetParError(0); runSummary[4] = fit->GetParameter(1); runSummary[5] = fit->GetParError(1); } }
void rateStudy() { const int NRUNS = 25; const int NCH = 32; const int NBINS = 32; TCanvas* c1 = new TCanvas("c1", "c1", 800, 600); TMultiGraph *mg = new TMultiGraph(); TLegend *legend=new TLegend(0.65,0.15,0.88,0.55); legend->SetNColumns(4); legend->SetFillColor(0); TH1F* hRate = new TH1F("hRate", "hist", 32.0, 0, 8.0); //Color buffer const int NCOLORS = 32; int color[NCOLORS] = {73, 2, 3, 4, 99, 6, 7, 8, 9, 12, 28, 32, 34, 28, 50, 51, 56, 58, 88, 99, 1, 208, 209, 218, 212, 210, 221, 224, 225, 226, 227, 228 }; ifstream fin; //fin.open("runlist.txt"); fin.open("filter_runlist.txt"); string line = ""; TFile* out = new TFile("outtemp.root", "REACREATE"); TH1F* h = new TH1F("h","hist", NBINS, 0, NBINS); TF1* pois = new TF1("pois","[0]*TMath::Poisson(x,[1])",0,50); TF1* ppp = new TF1("ppp","[0]*TMath::Power(0.5,x*[1])",0.01,1.0); for (int ch = 0; ch < NCH; ++ch) { //if ( ch==26 || ch==27 ) //continue; //Graph points and errors Double_t x[NRUNS]; Double_t y[NRUNS]; Double_t errX[NRUNS] = {0}; Double_t errY[NRUNS] = {0}; int fileCounter = 0; while(getline(fin, line)) { vector<double> data = parse(line); stringstream filePath; filePath << "pmtratestudy/run" << data[0] << "*.root"; cout << "opening file at " << filePath.str() << endl; cout << "file counter: " << fileCounter << " channel=" << ch << endl; //TFile* f = new TFile(filePath.str().c_str()); //TTree* t = (TTree *)f->Get("eventtree"); TChain* t = new TChain("eventtree"); t->Add( filePath.str().c_str() ); out->cd(); x[fileCounter] = data[1]; int nfires[NCH] = {0}; int samples = 0; float chmax = 0.0; t->SetBranchAddress("nfires", &nfires); t->SetBranchAddress("samples", &samples); t->SetBranchAddress("chmax", &chmax); h->Reset(); int nentries = t->GetEntries(); for (int entry = 0; entry < nentries; ++entry) { t->GetEntry(entry); if (chmax < 100.0) { h->Fill(nfires[ch]); } } pois->SetParameter(0,1); pois->SetParameter(1, h->GetMean()); h->Fit(pois,"RQ","",0,50); //TF1 *myfit = (TF1 *)h->GetFunction("pois"); TF1 *myfit = (TF1 *)pois; Double_t lambda = myfit->GetParameter(1); h->Draw(); stringstream histFileName; histFileName << "hist/h" << data[0] << "_ch" << ch << ".png"; c1->SaveAs(histFileName.str().c_str()); //Graph with poisson method #if 1 y[fileCounter] = lambda / ((samples - 1) * 15.625E-6); errY[fileCounter] = myfit->GetParError(1) / ((samples - 1) * 15.625E-6); #endif //Graph with mean method #if 0 y[fileCounter] = h->GetMean() / ((samples - 1) * 15.625E-6); errY[fileCounter] = h->GetMeanError() / ((samples - 1) * 15.625E-6); #endif cout << x[fileCounter] << ", " << y[fileCounter] << " | " << (samples - 1) << endl; delete t; //f->Close(); fileCounter++; } ppp->SetParameter(0,1); ppp->SetParameter(1,0.4); TGraphErrors* gr = new TGraphErrors(NRUNS, x, y, errX, errY); gr->SetLineColor(color[ch % NCOLORS]); cout << "color: " << color[ch % NCOLORS] << endl; gr->SetLineWidth(2); gr->SetMarkerStyle(7); gr->Fit("ppp","R0","Q0",0.045,2.0); TF1 *afit = (TF1 *)gr->GetFunction("ppp"); Double_t aRate = 1/afit->GetParameter(1); if (aRate > 0) { hRate->Fill(aRate); } gr->GetXaxis()->SetTitle("Run Date"); gr->GetYaxis()->SetTitle("Rate [kHz]"); stringstream entryName, fileName; entryName << "Channel" << ch; gr->SetTitle(entryName.str().c_str()); fileName << "plots/" << ch << ".png"; legend->AddEntry(gr, entryName.str().c_str()); gr->Draw("alp"); c1->SaveAs(fileName.str().c_str()); mg->Add(gr); cout << "added plot to mg\n"; fin.clear(); fin.seekg(0, ios::beg); } // loop over channel hRate->Draw(); hRate->Fit("gaus"); c1->SaveAs("hrate.pdf"); mg->Draw("alp"); mg->GetXaxis()->SetTitle("Days since first run"); mg->GetYaxis()->SetTitle("Rate [kHz]"); mg->SetTitle("All channels: Rate vs. Days since first Run"); legend->Draw(); c1->SaveAs("mg.pdf"); }
uwLowLightCalib(){ const int numRuns = 18; const char* files[numRuns] = { "../crunchedFiles/run_00262_crunched.root", "../crunchedFiles/run_00263_crunched.root", "../crunchedFiles/run_00264_crunched.root", "../crunchedFiles/run_00265_crunched.root", "../crunchedFiles/run_00266_crunched.root", "../crunchedFiles/run_00267_crunched.root", "../crunchedFiles/run_00268_crunched.root", "../crunchedFiles/run_00269_crunched.root", "../crunchedFiles/run_00270_crunched.root", "../crunchedFiles/run_00274_crunched.root", "../crunchedFiles/run_00275_crunched.root", "../crunchedFiles/run_00278_crunched.root", "../crunchedFiles/run_00279_crunched.root", "../crunchedFiles/run_00280_crunched.root", "../crunchedFiles/run_00281_crunched.root", "../crunchedFiles/run_00282_crunched.root", "../crunchedFiles/run_00284_crunched.root", "../crunchedFiles/run_00285_crunched.root"}; gStyle->SetOptFit(1); vector<double> means[4]; vector<double> sigs[4]; vector<double> meanErrs[4]; vector<double> sigErrs[4]; for (int i = 0; i < numRuns; ++i){ TFile* f = new TFile(files[i]); TTree* t = (TTree*) f->Get("t"); for (int j = 0; j < 4; ++j){ t->Draw(Form("sipm%i.energy>>h%i",j+1,j),Form("sipm%i.valid",j+1)); TH1F* h = (TH1F*) gROOT->FindObject(Form("h%i",j)); h->Fit("gaus","0"); means[j].push_back(h->GetFunction("gaus")->GetParameter(1)); sigs[j].push_back(h->GetFunction("gaus")->GetParameter(2)); meanErrs[j].push_back(h->GetFunction("gaus")->GetParError(1)); sigErrs[j].push_back(h->GetFunction("gaus")->GetParError(2)); } } vector<double> variances[4]; vector<double> varianceErrors[4]; for(int i = 0; i < means.size(); ++i){ for(int j = 0; j < 4; ++j){ variances[j].push_back(sigs[j][i]*sigs[j][i]); varianceErrors[j].push_back(2*sigs[j][i]*sigErrs[j][i]); } } TCanvas* c1 = new TCanvas(); c1->Divide(2,2); for(int j = 0; j < 4; ++j){ c1->cd(j+1); TGraphErrors* linGraph = new TGraphErrors(means[j].size(), &means[j][0], &variances[j][0], &meanErrs[j][0], &varianceErrors[j][0]); TGraphErrors* quadGraph = new TGraphErrors(means.size(), &means[j][0], &variances[j][0], &meanErrs[j][0], &varianceErrors[j][0]); linGraph->SetMarkerStyle(20); linGraph->Fit("pol1"); linGraph->SetTitle(Form("SiPM %i", j+1)); linGraph->GetFunction("pol1")->SetLineColor(kBlue); linGraph->GetXaxis()->SetTitle("Mean"); linGraph->GetYaxis()->SetTitle("#sigma^{2}"); quadGraph->SetMarkerStyle(20); quadGraph->Fit("pol2"); quadGraph->GetFunction("pol2")->SetLineColor(kRed); linGraph->Draw("ap"); quadGraph->Draw("psame"); } for( int i = 0; i < 4; ++ i){ for (int j = 0; j<i; ++j){ new TCanvas(); TGraphErrors* corrGraph = new TGraphErrors(means[i].size(), &means[i][0], &means[j][0], &meanErrs[i][0], &meanErrs[j][0]); corrGraph->GetXaxis()->SetTitle(Form("SiPM %i Mean", i+1)); corrGraph->GetYaxis()->SetTitle(Form("SiPM %i Mean", j+1)); corrGraph->SetTitle(Form("SiPM %i vs SiPM %i",j+1, i+1)); corrGraph->Fit("pol1"); corrGraph->SetMarkerStyle(20); corrGraph->Draw("ap"); } } }
//--------------------------------------------------------------- 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; }