void draw() { gStyle->SetOptStat(0000); TGraphErrors* gr = new TGraphErrors("papel_um.txt", "%lg %lg %lg %lg"); gr->Draw("A"); gr->GetXaxis()->SetTitle("Diametro (mm)"); gr->GetYaxis()->SetTitle("Massa (u.m.)"); gr->SetTitle("Dimensao Fractal - Papel"); gr->SetMarkerStyle(20); gr->SetMarkerSize(gr->GetMarkerSize()/2.); TCanvas* c1 = new TCanvas(); gr->Draw("AP"); c1->Print("gr1.png"); TGraphErrors* grlog = new TGraphErrors(); for (int i=0; i<gr->GetN(); i++) { grlog->SetPoint(i, TMath::Log(gr->GetX()[i]), TMath::Log(gr->GetY()[i])); grlog->SetPointError(i, gr->GetEX()[i]/gr->GetX()[i], 0.0); } grlog->Draw("A"); grlog->GetXaxis()->SetTitle("Logaritmo do diametro (diametro em mm)"); grlog->GetYaxis()->SetTitle("Logaritmo da massa (massa em unidade arbitraria)"); grlog->SetTitle("Dimensao Fractal - Papel"); grlog->SetMarkerStyle(20); // grlog->SetMarkerSize(gr->GetMarkerSize()/2.); grlog->Fit("pol1"); TCanvas* c2 = new TCanvas(); grlog->Draw("AP"); c2->Print("gr2.png"); }
Double_t calc_dNdY(const char *data_file = "pt_RFE", Bool_t show = kFALSE) { TGraphErrors *g = new TGraphErrors(data_file); if (g->IsZombie()) return; TF1 *flt = new TF1("flt", LevyTsallis, 0., 5., 4); flt->SetParameters(2.93483e-02, 2.80382e-01, 8.10224e+00, 1.01944e+00); flt->FixParameter(3, 1.019445); Double_t fitmin = 0.25, fitmax = 5.25; // !!! g->Fit(flt, "Q", "", fitmin, fitmax); g->Fit(flt, "Q", "", fitmin, fitmax); g->Fit(flt, "Q", "", fitmin, fitmax); Double_t first, last; // !!! bining sensibility !!! Int_t graph_range[2] = {2, 23}; // [2] = 0.05 - 0.01, [23] = 4.70 + 0.01 // interval 1 first = 0.0; // !!! last = g->GetX()[graph_range[0]] - g->GetErrorX(graph_range[0]); Double_t fi1 = flt->Integral(first, last); // interval 2 first = last; last = g->GetX()[graph_range[1]] + g->GetErrorX(graph_range[1]); Double_t fi2 = flt->Integral(first, last); Double_t gi2 = 0.0; for (Int_t ip = graph_range[0]; ip <= graph_range[1]; ip++) gi2 += g->GetY()[ip]*g->GetErrorX(ip)*2.0; // interval 3 first = last; last = 30.0; // !!! Double_t fi3 = flt->Integral(first, last); Double_t result = fi1 + gi2 + fi3; if (!show) { delete g; delete flt; return result; } Printf("function: %f \t %f \t %f", fi1, fi2, fi3); Printf("graph: \t \t \t %f", gi2); Printf("result => %f", result); g->Draw("AP"); gPad->SetLogy(); return result; }
double ll_matrix::matrix_calibration::get_min_mass( TGraphErrors & graph ) { double m_min_x = graph.GetX()[0] , m_min_y = graph.GetY()[0]; for( int i = 0 ; i < graph.GetN() ; i++ ) { if( graph.GetY()[i] < m_min_y ) { if( graph.GetX()[i] < LOWEST_MASS || graph.GetX()[i] > HIGHEST_MASS ) continue; m_min_x = graph.GetX()[i]; m_min_y = graph.GetY()[i]; } } return m_min_x; }
void covertQuan(){ TFile *fin = TFile::Open("pPb.root"); // TFile *fout = new TFile("pPb_xq.root","Recreate"); int mult[4] = {120,150,185,220}; int n[4] = {2,4,6,8}; for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ TGraphErrors *g = (TGraphErrors*)fin->Get(Form("v2Pt_%d_%d",n[j],mult[i])); if(n[j]==4){ cout<<mult[i]<<endl; for(int ibin=0;ibin<g->GetN();ibin++){ cout<<g->GetX()[ibin]<<","; } cout<<endl; for(int ibin=0;ibin<g->GetN();ibin++){ cout<<g->GetY()[ibin]<<","; } cout<<endl; for(int ibin=0;ibin<g->GetN();ibin++){ cout<<g->GetEY()[ibin]<<","; } cout<<endl; } // fout->cd(); // g->Write("AP"); // g1->Write(); } } }
void points(TString filename) { TString cmssw; // 167 cmssw = "$1.6.7$"; TFile *f = TFile::Open(filename); std::vector< TString > taggers; taggers.push_back( "gTC2_udsg" ); taggers.push_back( "gTC3_udsg" ); taggers.push_back( "gTP_udsg" ); taggers.push_back( "gJBP_udsg" ); taggers.push_back( "gSSV_udsg" ); taggers.push_back( "gCSV_udsg" ); std::vector< TString > discriminators; discriminators.push_back( "discTC2_udsg" ); discriminators.push_back( "discTC3_udsg" ); discriminators.push_back( "discTP_udsg" ); discriminators.push_back( "discJBP_udsg" ); discriminators.push_back( "discSSV_udsg" ); discriminators.push_back( "discCSV_udsg" ); //TCanvas *cv_TC = new TCanvas("cv_TC","cv_TC",700,700); //TCanvas *cv_TP = new TCanvas("cv_TP","cv_TP",700,700); std::cout << "Tagger & Point & Discriminator & light mistag & b-efficiency \\\\ \\hline" << std::endl; for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) { TString tag = taggers[itagger]; TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("Histograms/MCtruth/"+tag); //if (taggers == "gTC2_udsg" || taggers = TGraph *dgraph = (TGraph*) gDirectory->Get("Histograms/MCtruth/"+discriminators[itagger]); dgraph->Sort(); TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX()); g->Sort(); //cv[itagger] = new TCanvas("cv","cv",600,600); //g->Draw("ACP"); TString se = " & "; std::cout << tag << se << "Loose" << se << std::setprecision(3) << dgraph->Eval(0.1) << se << "0.1" << se << std::setprecision(2) << g->Eval(0.1) << "\\\\" << std::endl; std::cout << tag << se << "Medium" << se << std::setprecision(3) << dgraph->Eval(0.01) << se << "0.01" << se << std::setprecision(2) << g->Eval(0.01) << "\\\\" << std::endl; std::cout << tag << se << "Tight" << se << std::setprecision(3) << dgraph->Eval(0.001) << se << "0.001" << se << std::setprecision(2) << g->Eval(0.001) << "\\\\ \\hline" << std::endl; } }
printgraph(const char* file, const char* graphname, const char* graphname_syst, bool reverseta=false, double scale=1./34.62) { TFile * f = new TFile(file); TGraphErrors *gr = (TGraphErrors*) f->Get(graphname); TGraphErrors *grsyst = (TGraphErrors*) f->Get(graphname_syst); int nbins = gr->GetN(); double *x = new double[nbins]; if (reverseta) for (int i=0; i<nbins; i++) x[i] = gr->GetX()[nbins-i-1]; else x = gr->GetX(); double *y = gr->GetY(); double *ey = gr->GetEY(); double *ey_syst = grsyst->GetEY(); for (int i=0; i<nbins; i++) cout << x[i] << ": " << y[i]*scale << "+-" << ey[i]*scale << "(stat.) +-" << ey_syst[i]*scale << "(syst.)" << endl; }
TGraphErrors *ReadMWGraph(const char *name, Int_t flag) { Double_t xreject = 0.49; TGraphErrors *g = new TGraphErrors(name); if (g->IsZombie()) return 0; while (g->GetX()[0] < xreject) g->RemovePoint(0); TGraphErrors *g2 = new TGraphErrors(name); if (g2->IsZombie()) return 0; while (g2->GetX()[0] < xreject) g2->RemovePoint(0); g2->SetMarkerStyle(4); g2->SetMarkerSize(1.00); g2->SetMarkerColor(kBlack); g2->SetLineColor(kBlack); TGraphErrors *gsys = new TGraphErrors(name, "%lg %lg %lg %*lg %lg"); if (gsys->IsZombie()) return 0; while (gsys->GetX()[0] < xreject) gsys->RemovePoint(0); for (Int_t i = 0; i < gsys->GetN(); i++) gsys->SetPointError(i, gsys->GetErrorX(i)*0.75, gsys->GetErrorY(i)); gsys->SetFillColor(kGray+2); gsys->SetLineColor(kGray+2); gsys->SetFillStyle(3000); if (flag == 1 || flag == 3) { TGraphErrors *gt = new TGraphErrors(Form("%s_%s", name, "trues")); if (gt->IsZombie()) return 0; while (gt->GetX()[0] < xreject) gt->RemovePoint(0); gt->SetMarkerStyle(20); gt->SetMarkerSize(0.75); gt->SetMarkerColor(kGreen+1); gt->SetLineColor(kGreen+1); TGraphErrors *gbw = new TGraphErrors(Form("%s_%s", name, "gen")); if (gbw->IsZombie()) return 0; while (gbw->GetX()[0] < xreject) gbw->RemovePoint(0); gbw->SetMarkerStyle(20); gbw->SetMarkerSize(0.75); gbw->SetMarkerColor(kBlue+1); gbw->SetLineColor(kBlue+1); for (Int_t i = 0; i < g->GetN(); i++) { g->SetPointError(i, g->GetEX()[i], 0.); gt->SetPointError(i, gt->GetEX()[i], 0.); gbw->SetPointError(i, gbw->GetEX()[i], 0.); } for (Int_t i = 0; i < g2->GetN(); i++) { g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + gbw->GetY()[i]); g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] + gbw->GetEY()[i]*gbw->GetEY()[i])); // g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + 1.01947); // g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] + // 7.78680e-06*7.78680e-06)); gsys->SetPoint(i, gsys->GetX()[i], g2->GetY()[i]); } } g->SetTitle(); g->SetName(name); g->GetXaxis()->SetTitle("p_{T}, GeV/c"); g->SetMarkerStyle(20); g->SetMarkerSize(0.95); g->SetMarkerColor(kRed+1); g->SetLineColor(kRed+1); const Double_t mass = 1.019455; const Double_t mass_delta = 0.000020; const Double_t width = 0.00426; const Double_t width_delta = 0.00004; if (flag == 1) { // mass g->GetYaxis()->SetTitleOffset(1.50); g->GetYaxis()->SetTitle("mass, GeV/c^{2}"); g->SetMaximum(mass+0.0015); g->SetMinimum(mass-0.0015); TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g->GetXaxis()->GetXmax(), mass + mass_delta); box->SetFillColor(kGray+1); box->SetFillStyle(3001); g->GetListOfFunctions()->Add(box); g->GetListOfFunctions()->Add(g2, "CP"); g->GetListOfFunctions()->Add(gt, "CP"); g->GetListOfFunctions()->Add(gbw, "CP"); } else if (flag == 3) { // mass simple g2->SetTitle(); g2->SetName(Form("%s_only", name)); g2->GetXaxis()->SetTitle("p_{T}, GeV/c"); g2->SetMarkerStyle(20); g2->SetMarkerSize(0.75); g2->SetMarkerColor(kBlack); g2->SetLineColor(kBlack); g2->GetYaxis()->SetTitleOffset(1.50); g2->GetYaxis()->SetTitle("mass, GeV/c^{2}"); g2->SetMaximum(mass+0.0015); g2->SetMinimum(mass-0.0015); TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g2->GetXaxis()->GetXmax(), mass + mass_delta); box->SetFillColor(kGray+1); box->SetFillStyle(3001); g2->GetListOfFunctions()->Add(box); g2->GetListOfFunctions()->Add(gsys, "E5"); return g2; } else if (flag == 2) { // width g->SetTitle(); g->SetName(name); g->GetXaxis()->SetTitle("p_{T}, GeV/c"); g->SetMarkerStyle(20); g->SetMarkerSize(0.75); g->SetMarkerColor(kBlack); g->SetLineColor(kBlack); g->GetYaxis()->SetTitleOffset(1.50); g->GetYaxis()->SetTitle("width, GeV/c^{2}"); g->SetMaximum(0.01); g->SetMinimum(0.0); TBox *box = new TBox(g->GetXaxis()->GetXmin(), width - width_delta, g->GetXaxis()->GetXmax(), width + width_delta); box->SetFillColor(kGray+1); box->SetFillStyle(3001); g->GetListOfFunctions()->Add(box); g->GetListOfFunctions()->Add(gsys, "E5"); } return g; }
Int_t VisualizeSurface() { std::string gfname; std::cout << "\nFor the graph "; ListAllFilesInDirOfType (".",".root"); std::cout << "\nEnter filename : "; std::getline(std::cin, gfname); TGraphErrors* mygr = GetGraph(gfname); mygr->SetMarkerColor(kRed); mygr->SetLineColor(kRed); mygr->SetMarkerStyle(20); std::string parfname = GetParamFile(); std::ifstream pfile(parfname.data()); Parameters params(pfile); if (! params.KeysAreSensible()) return -1; AngDistC W(params, 1, ELECTRIC); std::cout << params << std::endl; TGraph* gr = new TGraph(mygr->GetN()); gr->SetMarkerColor(kBlue); gr->SetLineColor(kBlue); gr->SetMarkerStyle(20); Double_t num, denom; Double_t ratio; Double_t x[2]; for (UInt_t i=0; i<mygr->GetN(); i++) { x[0] = mygr->GetX()[i]; x[1] = 0; num = W(x); x[1] = TMath::Pi()/2.; denom = W(x); ratio = num/denom; gr->SetPoint(i, mygr->GetX()[i], TMath::Abs(ratio)); } std::cout << "\n Phase2ChiSqC setup completed " << std::endl; TPaveText* pt = new TPaveText(0.5, 0.75, 0.8, 0.95); std::ostringstream os("", std::ios::out|std::ios::app); os << "a = " << params[0]->GetValue(); pt->AddText(os.str().data()); os.str("b = "); os << params[1]->GetValue(); pt->AddText(os.str().data()); os.str("c = "); os << params[2]->GetValue(); pt->AddText(os.str().data()); os.str("d = "); os << params[3]->GetValue(); pt->AddText(os.str().data()); TH1* h = new TH2D("Ratio Comparison", "", 10, -1,1, 500, 0,100); h->SetStats(0); TCanvas* c = new TCanvas("c"); h->Draw(); gr->Draw("LP"); mygr->Draw("LP"); gPad->Modified(); c->Update(); TLegend *leg = new TLegend(0.5, 0.75, 0.8, 0.95); leg->AddEntry(gr, "Fit", "PL"); leg->AddEntry(mygr, "Data", "PL"); leg->Draw(); return 0; }
void AnalyzeClipping(TString inputWaveName = "sum trigger input ch5 960mV", TString outputWaveName = "sum trigger output ch5 - 2V clip - 960mV input", Double_t inputDelay = 1.1E-8, Double_t lowerCut = 16E-9, Double_t upperCut = 23E-9, const char *inFile = "Data.root",const char *WaveformsFile = "Waveforms.root") { //try to access data file and in case of failure return if(gSystem->AccessPathName(inFile,kFileExists)) { cout << "Error: file " << inFile << " does not exsist. Run .x DataParse.C to create it" << endl; return; } TFile *f = TFile::Open(inFile); TFolder *dataSet; TString dataFolderS = "SumTriggerBoardData"; dataFolderS.Append(";1"); dataSet = (TFolder*)f->Get(dataFolderS); cout << dataSet << endl; cout << dataSet->GetName() << endl; Int_t nScope = 150; // number of measurements done by the scope evey time //try to access waveforms file and in case of failure return if(gSystem->AccessPathName(WaveformsFile,kFileExists)) { cout << "Error: file " << WaveformsFile << " does not exsist. Run .x WaveformsFileMaker.C to create it" << endl; return; } TFile *f = TFile::Open(WaveformsFile); TList *listOfKeys = f->GetListOfKeys(); Int_t numberOfKeys = listOfKeys->GetEntries(); TList *listOfGraphs = new TList(); // if the waveform file name begins with the string "comparator" it goes in this list TList *listOfCompWaves = new TList(); // if the waveform file name begins with the string "sum output" it goes in this list TList *listOfAdderWaves = new TList(); for(Int_t i = 0; i < numberOfKeys; i++) { TString *keyName = new TString(listOfKeys->At(i)->GetName()); TTree *tree = (TTree*)f->Get(keyName->Data()); Float_t x = 0; Float_t y = 0; tree->SetBranchAddress("x",&x); tree->SetBranchAddress("y",&y); Int_t nentries = tree->GetEntries(); TString *gName = new TString(keyName->Data()); gName->Append(" graph"); TGraphErrors *gWave = new TGraphErrors(nentries); gWave->SetName(gName->Data()); gWave->SetTitle(gName->Data()); gWave->GetXaxis()->SetTitle("Time"); gWave->GetYaxis()->SetTitle("Voltage"); for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); gWave->SetPoint(j,x,y); } listOfGraphs->Add(gWave); } // Global variables Double_t *xInput, *xOutput, *yInput, *yOutput; // V input 960 mV TString path = "Clipping/Output width analysis/Channel 5/V input 960mV/"; TGraphErrors *gClip960mV = TBGraphErrors(dataSet,path,"V clip","Output FWHM",1,nScope); gClip960mV->SetMarkerStyle(20); gClip960mV->SetMarkerSize(0.8); gClip960mV->GetXaxis()->SetTitle("V clipping (mV)"); gClip960mV->GetYaxis()->SetTitle("Output FWHM (ns)"); TCanvas *cClip960mV = new TCanvas("cClip960mV","Output FWHM in function of V clipping",800,600); gClip960mV->Draw("APEL"); // Expected output FWHM TGraphErrors *gInput960mV = listOfGraphs->FindObject("sum trigger input ch5 960mV graph"); Double_t *xClip = gClip960mV->GetX(); Int_t nClip = gClip960mV->GetN(); cout << "nClip = " << nClip << endl; Long64_t graphPoints = gInput960mV->GetN(); yInput = gInput960mV->GetY(); xInput = gInput960mV->GetX(); vector<double> xFirst(nClip); vector<double> xLast(nClip); Double_t half; Int_t flag = 0; vector<double> yConv(graphPoints); for(Int_t i = 0; i < graphPoints; i++) { yConv[i] = -(yInput[i]); yConv[i] *= 1000; if(xInput[i] + inputDelay < lowerCut || xInput[i] + inputDelay > upperCut) yConv[i] = 0; } Double_t yInput960mVMax = TMath::MaxElement(graphPoints,&yConv[0]); for(Int_t i = 0; i < nClip; i++) { if(xClip[i] > yInput960mVMax) half = yInput960mVMax; else half = xClip[i]; half /=2; cout << half << endl; flag = 0; for(Int_t j = 0; j < graphPoints - 3; j++) { if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 0) { xFirst[i] = xInput[j]; flag = 1; cout << "found first point! " << xFirst[i] << endl; continue; } if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 1) { xLast[i] = xInput[j]; cout << "found last point! " << xLast[i] << endl; break; } } } vector<double> expectedFWHM960mV(nClip); for(Int_t i = 0; i < expectedFWHM960mV.size(); i++) { expectedFWHM960mV[i] = xLast[i] - xFirst[i]; // convert from seconds to nanoseconds expectedFWHM960mV[i] *= 10E8; cout << "expectedFWHM960mV[" << i << "] = " << expectedFWHM960mV[i] << endl; } // expected FWHM 960 mV graph TGraphErrors *gExpClip960mV = new TGraphErrors(nClip,xClip,&expectedFWHM960mV[0],0,0); gExpClip960mV->SetLineStyle(7); gExpClip960mV->SetMarkerStyle(20); gExpClip960mV->SetMarkerSize(0.8); // V input 1.9 V path = "Clipping/Output width analysis/Channel 5/V input 1.9V/"; TGraphErrors *gClip1Point9V = TBGraphErrors(dataSet,path,"V clip","Output FWHM",1,nScope); gClip1Point9V->SetMarkerStyle(20); gClip1Point9V->SetMarkerSize(0.8); gClip1Point9V->SetLineColor(kRed); gClip1Point9V->GetXaxis()->SetTitle("V clipping (mV)"); gClip1Point9V->GetYaxis()->SetTitle("Output FWHM (ns)"); TCanvas *cClip1Point9V = new TCanvas("cClip1Point9V","Output FWHM in function of V clipping",800,600); gClip1Point9V->Draw("APEL"); // Expected output FWHM TGraphErrors *gInput1Point9V = listOfGraphs->FindObject("sum trigger input ch5 1900mV graph"); xClip = gClip1Point9V->GetX(); nClip = gClip1Point9V->GetN(); cout << "nClip = " << nClip << endl; graphPoints = gInput1Point9V->GetN(); yInput = gInput1Point9V->GetY(); xInput = gInput1Point9V->GetX(); vector<double> xFirst(nClip); vector<double> xLast(nClip); flag = 0; vector<double> yConv(graphPoints); for(Int_t i = 0; i < graphPoints; i++) { yConv[i] = -(yInput[i]); yConv[i] *= 1000; if(xInput[i] + inputDelay < lowerCut || xInput[i] + inputDelay > upperCut) yConv[i] = 0; } Double_t yInput1Point9VMax = TMath::MaxElement(graphPoints,&yConv[0]); for(Int_t i = 0; i < nClip; i++) { if(xClip[i] > yInput1Point9VMax) half = yInput1Point9VMax; else half = xClip[i]; half /= 2; cout << half << endl; flag = 0; for(Int_t j = 0; j < graphPoints - 3; j++) { if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 0) { xFirst[i] = xInput[j]; flag = 1; cout << "found first point! " << xFirst[i] << endl; continue; } if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 1) { xLast[i] = xInput[j]; cout << "found last point! " << xLast[i] << endl; break; } } } vector<double> expectedFWHM1Point9V(nClip); for(Int_t i = 0; i < expectedFWHM1Point9V.size(); i++) { expectedFWHM1Point9V[i] = xLast[i] - xFirst[i]; // convert from seconds to nanoseconds expectedFWHM1Point9V[i] *= 10E8; cout << "expectedFWHM1Point9V[" << i << "] = " << expectedFWHM1Point9V[i] << endl; } // expected FWHM 960 mV graph TGraphErrors *gExpClip1Point9V = new TGraphErrors(nClip,xClip,&expectedFWHM1Point9V[0],0,0); gExpClip1Point9V->SetLineStyle(7); gExpClip1Point9V->SetLineColor(kRed); gExpClip1Point9V->SetMarkerStyle(20); gExpClip1Point9V->SetMarkerSize(0.8); // Collection of Output FWHM graphs, 2 amplitudes, serveral V clipping TMultiGraph *mgClipOutputFWHM = new TMultiGraph(); mgClipOutputFWHM->SetTitle("Collection of Output FWHM graphs, 2 amplitudes, serveral V clipping"); mgClipOutputFWHM->Add(gClip1Point9V); mgClipOutputFWHM->Add(gClip960mV); mgClipOutputFWHM->Add(gExpClip960mV); mgClipOutputFWHM->Add(gExpClip1Point9V); TCanvas *cmgClipOutputFWHM = new TCanvas("cmgClipOutputFWHM","Collection of Output FWHM graphs, 2 amplitudes, serveral V clipping"); mgClipOutputFWHM->Draw("APEL"); cmgClipOutputFWHM->Modified(); mgClipOutputFWHM->GetXaxis()->SetTitle("V clipping (mV)"); mgClipOutputFWHM->GetYaxis()->SetTitle("Output FWHM (ns)"); cmgClipOutputFWHM->Update(); legend = new TLegend(0.6,0.67,0.89,0.86,"V input"); legend->AddEntry(gClip1Point9V, "1.9 V", "lp"); legend->AddEntry(gClip960mV, "960 mV", "lp"); legend->AddEntry(gExpClip960mV, "Exp 960 mV", "lp"); legend->AddEntry(gExpClip1Point9V, "Exp 1.9 V", "lp"); legend->SetTextSize(0.04); legend->SetMargin(0.5); legend->Draw(); // Hysteresis plot: V output (t) in function of V input (t) for several clipping values // variables used in the analysis Long64_t iInputMax, iOutputMax; Float_t xInputMax, xOutputMax, xInputHalf, xOutputHalf; Double_t InputMax, OutputMax, InputHalf, OutputHalf; Long64_t firstIndex = 0; Long64_t lastIndex = 0; Long64_t inputGraphPoints = 0; Long64_t outputGraphPoints = 0; // hard coded values to cut the x axis of both waves // Input wave inputWaveName += " graph"; TGraphErrors *gInput = listOfGraphs->FindObject(inputWaveName); gInput->SetLineColor(kRed); gInput->SetLineWidth(2); xInput = gInput->GetX(); yInput = gInput->GetY(); inputGraphPoints = gInput->GetN(); cout << inputGraphPoints << endl; // Invert the input wave for(Int_t i = 0; i < inputGraphPoints; i++) { yInput[i] = -(yInput[i]); } // find the x at which the graph reaches the max value iInputMax = TMath::LocMax(inputGraphPoints, yInput); xInputMax = xInput[iInputMax]; cout << "iInputMax = " << iInputMax << endl; cout << "xInputMax = " << xInputMax << endl; InputMax = gInput->Eval(xInput[iInputMax]); cout << "InputMax = " << InputMax << endl; // Output wave outputWaveName += " graph"; TGraphErrors *gOutput = listOfGraphs->FindObject(outputWaveName); gOutput->SetLineWidth(2); xOutput = gOutput->GetX(); yOutput = gOutput->GetY(); outputGraphPoints = gOutput->GetN(); // find the x at which the graph reaches the max value iOutputMax = TMath::LocMax(outputGraphPoints, yOutput); xOutputMax = xOutput[iOutputMax]; cout << "iOutputMax = " << iOutputMax << endl; cout << "xOutputMax = " << xOutputMax << endl; OutputMax = gOutput->Eval(xOutput[iOutputMax]); cout << "OutputMax = " << OutputMax << endl; // compute x delay between max points Double_t delay = xOutputMax - xInputMax; cout << "delay = " << delay << endl; // Shift the x axis of the input graph and create a new graph with only a portion of the first graph for(Int_t i = 0; i < inputGraphPoints; i++) { xInput[i] += inputDelay; if(xInput[i] >= lowerCut) { if(firstIndex == 0) firstIndex = i; } if(xInput[i] <= upperCut) lastIndex = i; } cout << "firstIndex = " << firstIndex << endl; cout << "lastIndex = " << lastIndex << endl; cout << "xInput[firstIndex] = " << xInput[firstIndex] << endl; cout << lastIndex - firstIndex << endl; Long64_t input2GraphPoints = lastIndex - firstIndex; TGraphErrors *gInput2 = new TGraphErrors(input2GraphPoints); gInput2->SetTitle(inputWaveName); for(Int_t i = firstIndex; i <= lastIndex; i++) { gInput2->SetPoint(i - firstIndex,xInput[i],yInput[i]); } TCanvas *cgInput2 = new TCanvas("cgInput2", "cgInput2", 1200,800); gInput2->Draw("AL"); // create a new graph with only a portion of the first graph firstIndex = 0; lastIndex = 0; for(Int_t i = 0; i < outputGraphPoints; i++) { if(xOutput[i] >= lowerCut) { if(firstIndex == 0) firstIndex = i; } if(xOutput[i] <= upperCut) lastIndex = i; } cout << "firstIndex = " << firstIndex << endl; cout << "lastIndex = " << lastIndex << endl; cout << "xOutput[firstIndex] = " << xOutput[firstIndex] << endl; cout << lastIndex - firstIndex << endl; Long64_t output2GraphPoints = lastIndex - firstIndex; TGraphErrors *gOutput2 = new TGraphErrors(output2GraphPoints); gOutput2->SetTitle(outputWaveName); for(Int_t i = firstIndex; i <= lastIndex; i++) { gOutput2->SetPoint(i - firstIndex,xOutput[i],yOutput[i]); } TCanvas *cgOutput2 = new TCanvas("cgOutput2", "cgOutput2", 1200,800); gOutput2->Draw("AL"); // first hysteresis plot Double_t step; Double_t *xInput2; xInput2 = gInput2->GetX(); cout << "xInput2[input2GraphPoints - 1] = " << xInput2[input2GraphPoints - 1] << endl; cout << "xInput2[0] = " << xInput2[0] << endl; step = (xInput2[input2GraphPoints - 1] - xInput2[0])/output2GraphPoints; cout << "step = " << step << endl; // in case gInput2 and gOutput2 contain a different number of points create the hysteresis plot with gOutput2 points // and modify the yInput2 to match the number of points of yOutput2 vector<double> yInput2; for(Int_t i = 0; i < output2GraphPoints; i++) { yInput2.push_back(gInput2->Eval(xInput2[0] + i*step)); } Double_t *yOutput2; yOutput2 = gOutput2->GetY(); TGraphErrors *gHyst = new TGraphErrors(output2GraphPoints, &yInput2.at(0),yOutput2); gHyst->SetTitle("Hysteresis plot"); gHyst->GetXaxis()->SetTitle("Vin(t) [mV]"); gHyst->GetYaxis()->SetTitle("Vout(t) [mV]"); gHyst->GetYaxis()->SetTitleOffset(1.4); TCanvas *cgHyst = new TCanvas("cgHyst", "cgHyst", 1200,800); cgHyst->SetLeftMargin(0.12); gHyst->Draw("AL"); // collection of graphs TMultiGraph *mgInputOutput = new TMultiGraph(); mgInputOutput->Add(gInput); mgInputOutput->Add(gOutput); mgInputOutput->SetTitle("Input and output"); TCanvas *cmgInputOutput = new TCanvas("cmgInputOutput", "Input and output", 1200,800); mgInputOutput->Draw("AL"); cmgInputOutput->Update(); legend = new TLegend(0.65,0.68,0.86,0.86); legend->AddEntry(gInput, "Input", "lp"); legend->AddEntry(gOutput, "Output", "lp"); legend->SetMargin(0.4); legend->SetTextSize(0.04); legend->Draw(); cmgInputOutput->Modified(); }
void disceff(TString filename) { gROOT->SetStyle("Plain"); TString cmssw; // 167 cmssw = "$3.1.0_pre9$"; TFile *f = TFile::Open(filename); std::vector< TString > taggers; taggers.push_back( "TC2" ); taggers.push_back( "TC3" ); taggers.push_back( "TP" ); taggers.push_back( "BTP" ); taggers.push_back( "SSV" ); taggers.push_back( "CSV" ); taggers.push_back( "MSV" ); taggers.push_back( "SMT" ); taggers.push_back( "SETbyIP3d" ); taggers.push_back( "SETbyPt" ); taggers.push_back( "SMTbyIP3d" ); taggers.push_back( "SMTbyPt" ); std::vector< TString > discriminators; for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) { discriminators.push_back( "disc"+taggers[itagger]+"_udsg" ); } // discriminators.push_back( "discTC3_udsg" ); // discriminators.push_back( "discTP_udsg" ); const int dim=taggers.size(); TCanvas *cv[dim]; TMultiGraph* mg[dim]; for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) { TString tag = "g"+taggers[itagger]+"_udsg"; TString tagb = "g"+taggers[itagger]+"_b"; TString tagc = "g"+taggers[itagger]+"_c"; cv[itagger] = new TCanvas("cv_"+taggers[itagger],"cv_"+taggers[itagger],700,700); TLegend *legend0 = new TLegend(0.68,0.70,0.88,0.90); TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag); TGraphErrors *bgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagb); TGraphErrors *cgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagc); TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]); TGraph *bvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),bgraph->GetY()); TGraph *cvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),cgraph->GetY()); TGraph *lvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),agraph->GetY()); TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX()); dgraph->Sort(); // udsgvsdgraph->Sort(); // udsgvsdgraph->SetLineColor(1); // legend0 -> AddEntry(udsgvsdgraph,"control","l"); lvsdgraph->Sort(); lvsdgraph->SetLineColor(2); legend0 -> AddEntry(lvsdgraph,tag,"l"); cvsdgraph->Sort(); cvsdgraph->SetLineColor(3); legend0 -> AddEntry(cvsdgraph,tagc,"l"); bvsdgraph->Sort(); bvsdgraph->SetLineColor(4); legend0 -> AddEntry(bvsdgraph,tagb,"l"); mg[itagger]= new TMultiGraph(); // mg[itagger]->Add(udsgvsdgraph); mg[itagger]->Add(lvsdgraph); mg[itagger]->Add(cvsdgraph); mg[itagger]->Add(bvsdgraph); // mg[itagger]->Add(dgraph); cv[itagger]->cd(1); mg[itagger]->Draw("ALP"); mg[itagger]->GetYaxis()->SetTitle("eff"); mg[itagger]->GetXaxis()->SetTitle("discriminant"); legend0 -> Draw(); cv[itagger]->Update(); cv[itagger]->cd(0); cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".eps"); cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".ps"); TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX()); g->Sort(); g->SetLineColor(itagger+1); std::cout << " Tagger: " << tag << std::endl; std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl; std::cout << " Medium(1%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl; std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl; }//end for }
Int_t VisualizeSurface() { std::string gfname; std::cout << "\nFor the graph "; ListAllFilesInDirOfType (".",".root"); std::cout << "\nEnter filename : "; std::getline(std::cin, gfname); TGraphErrors* mygr = GetGraph(gfname); mygr->SetMarkerColor(kRed); mygr->SetLineColor(kRed); mygr->SetMarkerStyle(20); std::cout << "\nBegin setup of eta function" << std::endl; std::string rfname = GetROOTFile(); TFile *fle = new TFile(rfname.data()); if (!fle->IsOpen()) return -1; Eta2C eta(fle); AngMarginalEta2C marg_eta(eta); std::cout << "\neta function set up complete" << std::endl; std::cout << "\nBegin setup of denominators" << std::endl; std::string parfname = GetParamFile(); std::ifstream pfile(parfname.data()); Parameters params(pfile); if (! params.KeysAreSensible()) return -1; AngDistC W(params, 0, ELECTRIC); std::cout << params << std::endl; std::cout << "\ndenominator set up complete" << std::endl; std::cout << "\nSetting up numerator " << std::endl; PolPartAngDistC polpart(1, ELECTRIC); std::cout << "\nNumerator setup complete" << std::endl; std::cout << "\nBegin setup of h function" << std::endl; rfname = GetROOTFile(); TFile *file = new TFile(rfname.data()); if (!file->IsOpen()) return -1; TDirectory* dir = file->GetDirectory("SolidAnglePDFGeneratorCOutput"); if (dir==0) return -3; std::vector<TH2*> solang_hists = ROOTUtils::GetAllTH2InDirectory(dir); std::cout << "h function set up" << std::endl; std::vector<UInt_t> indices(32); for (UInt_t i=0; i<indices.size(); i++) { indices[i] = i; } Phase2ChiSqC FUNC(mygr, W, polpart, marg_eta, solang_hists , indices); std::cout << "\nang dist set up" << std::endl; Double_t par[] = {params.at(0)->GetValue(), params.at(1)->GetValue(), params.at(2)->GetValue(), params.at(3)->GetValue()}; // FUNC.SetAllIntegrandParameters(par); Double_t chisq_pdf = FUNC(par); std::vector<Double_t> ratios = FUNC.GetComputedRatios(); TGraph* gr = new TGraph(ratios.size()); gr->SetMarkerColor(kBlue); gr->SetLineColor(kBlue); gr->SetMarkerStyle(20); for (UInt_t i=0; i<ratios.size(); i++) { gr->SetPoint(i, mygr->GetX()[i], ratios[i]); } std::cout << "\n Phase2ChiSqC setup completed " << std::endl; // Int_t strip; // std::cout << "\nEnter desired strip : "; // std::cin >> strip; // std::shared_ptr<ROOT::Math::IBaseFunctionMultiDim> pi = FUNC.GetDenominator(strip); // ParamFunctorAdapter *pfa = new ParamFunctorAdapter(*pi); // // std::cout << "\nSetting up the function" << std::endl; // ROOT::Math::ParamFunctor pf; // pf.SetFunction(pfa); // TF2* f = new TF2("f", pf, -1, 1, -1.0*CLHEP::pi,CLHEP::pi,0); // Double_t pars[] = {params[0]->GetValue(), // params[1]->GetValue(), // params[2]->GetValue(), // params[3]->GetValue()}; // //f->SetParameters(pars); // f->SetNpx(50); // f->SetNpy(50); TPaveText* pt = new TPaveText(0.5, 0.75, 0.8, 0.95); std::ostringstream os("", std::ios::out|std::ios::app); os << "a = " << params[0]->GetValue(); pt->AddText(os.str().data()); os.str("b = "); os << params[1]->GetValue(); pt->AddText(os.str().data()); os.str("c = "); os << params[2]->GetValue(); pt->AddText(os.str().data()); os.str("d = "); os << params[3]->GetValue(); pt->AddText(os.str().data()); TCanvas* c = new TCanvas("c"); gr->Draw("ALP"); mygr->Draw("LP"); return 0; }
void Drawmethodcomp(){ const int nDil = 8; const double centDil[nDil+1] = {1.0,0.7,0.6,0.5,0.4,0.3,0.2,0.1,0}; double centDilbin[nDil]; for(int i=0;i<nDil;i++) centDilbin[i]=0.29+i+N-1-nDil; const double NpartDil[nDil] = {8.75,30.51,53.30,86.23,130.06,187.35,261.49,355.45}; const double NpartDilerr[nDil] = {1.13,3.02,3.95,4.35,4.60,4.44,3.96,2.83}; const double NcollDil[nDil] = {8.01,38.86,86.85,175.76,326.06,563.21,926.79,1484.49}; const double NcollDilerr[nDil] = {1.41,6.41,12.48,21.13,34.27,52.66,81.37,120.0}; TGraphErrors *graphNpartDil = new TGraphErrors(nDil,centDilbin,NpartDil,0,NpartDilerr); TGraphErrors *graphNcollDil = new TGraphErrors(nDil,centDilbin,NcollDil,0,NcollDilerr); TCanvas *c1 = new TCanvas("c1","c1",1,1,550,460); c1->SetLogy(); c1->SetFillColor(10); c1->SetFrameFillColor(0); c1->SetFrameBorderSize(0); c1->SetFrameBorderMode(0); c1->SetLeftMargin(0.15); c1->SetBottomMargin(0.15); c1->SetTopMargin(0.02); c1->SetRightMargin(0.02); gStyle->SetOptStat(0); c1->SetTicks(-1); N=N-1; TString str="Ncoll"; TH1D* hist = new TH1D("","",N,0,N); hist->GetXaxis()->SetNdivisions(502); if(method==0) hist->SetXTitle("Centrality"); else hist->SetXTitle("HF #Sigma E_{T} |#eta|>3"); hist->SetYTitle(Form("<%s> and systematic errors",str.Data())); hist->SetMinimum(1); hist->SetMaximum(3999.99); hist->GetXaxis()->CenterTitle(0); hist->GetYaxis()->CenterTitle(1); hist->GetYaxis()->SetTitleOffset(1.1); hist->GetXaxis()->SetTitleOffset(1.1); hist->GetXaxis()->SetTitleSize(0.056); hist->GetYaxis()->SetTitleSize(0.056); hist->GetXaxis()->SetLabelSize(0.05); hist->GetYaxis()->SetLabelSize(0.05); hist->GetXaxis()->SetLabelOffset(99); hist->Draw(); TFile *f=TFile::Open(outG); TGraphErrors* graph = (TGraphErrors*)f->Get(Form("std/%s_graph",str.Data())); // TGraphErrors* Gri055_graph = (TGraphErrors*)f->Get(Form("Gri055/%s_graph",str.Data())); // TGraphErrors* Gri101_graph = (TGraphErrors*)f->Get(Form("Gri101/%s_graph",str.Data())); TVectorD *centbin = (TVectorD*)f->Get(Form("std/G0/centbin")); TVectorD *kpoint = (TVectorD*)f->Get(Form("std/G0/kpoint")); TFile *f1=TFile::Open(Form("../../OneComp/double_side/%s",outG.Data())); TGraphErrors* graph1 = (TGraphErrors*)f1->Get(Form("std/%s_graph",str.Data())); // TGraphErrors* Gri055_graph = (TGraphErrors*)f->Get(Form("Gri055/%s_graph",str.Data())); // TGraphErrors* Gri101_graph = (TGraphErrors*)f->Get(Form("Gri101/%s_graph",str.Data())); TVectorD *centbin1 = (TVectorD*)f1->Get(Form("std/G0/centbin")); TVectorD *kpoint1 = (TVectorD*)f1->Get(Form("std/G0/kpoint")); graph->SetTitle("g1"); graph->SetMarkerStyle(20); graph->SetMarkerColor(1); graph->SetLineColor(1); graph->SetLineWidth(2); graph->SetMarkerSize(1.2); graph->Draw("Psameez"); graph1->SetMarkerStyle(24); graph1->SetMarkerColor(4); graph1->SetLineColor(4); graph1->SetLineWidth(2); graph1->SetMarkerSize(1.2); graph1->Draw("Psameez"); /* Gri055_graph->SetTitle("g2"); Gri055_graph->SetMarkerStyle(33); Gri055_graph->SetMarkerColor(2); Gri055_graph->SetLineColor(2); Gri055_graph->SetLineWidth(2); Gri055_graph->SetMarkerSize(1.2); Gri055_graph->Draw("Psameez"); Gri101_graph->SetTitle("g3"); Gri101_graph->SetMarkerStyle(34); Gri101_graph->SetMarkerColor(4); Gri101_graph->SetLineColor(4); Gri101_graph->SetLineWidth(2); Gri101_graph->SetMarkerSize(1.2); Gri101_graph->Draw("Psameez"); */ graphNpartDil->SetMarkerSize(1.2); graphNpartDil->SetLineColor(2); graphNpartDil->SetLineWidth(2); graphNpartDil->SetMarkerStyle(33); graphNpartDil->SetMarkerColor(2); graphNcollDil->SetMarkerSize(1.2); graphNcollDil->SetLineColor(2); graphNcollDil->SetLineWidth(2); graphNcollDil->SetMarkerStyle(33); graphNcollDil->SetMarkerColor(2); if(str=="Npart") graphNpartDil->Draw("Psame"); if(str=="Ncoll") graphNcollDil->Draw("Psame"); std::vector<TString> label(N); for(int i=0;i<N;i++) if(method==0)label[i] = Form("%.2f-%.2f%%",(*centbin)[i]*100,(*centbin)[i+1]*100); else label[i] = Form("%.2f-%.2f",(*kpoint)[i],(*kpoint)[i+1]); TLatex *tex1= new TLatex(0.2,0.9,"CMS Preliminary PbPb #sqrt{s_{NN}} = 2.76 TeV"); tex1->SetNDC(); tex1->SetTextColor(1); tex1->SetTextFont(42); tex1->SetTextSize(0.05); tex1->Draw(); double y = gPad->GetUymin(); // - 0.2*h->GetYaxis()->GetBinWidth(1); TText t; t.SetTextAngle(45); t.SetTextSize(0.03); t.SetTextAlign(33); for (int i=0;i<N;i++) { double x = hist->GetXaxis()->GetBinCenter(i+1); t.DrawText(x,y,label[i]); } TLegend *leg0 = new TLegend(0.18,0.70,0.50,0.85); leg0->SetFillColor(10); leg0->SetBorderSize(0); leg0->SetTextFont(42); leg0->SetTextSize(0.047); leg0->AddEntry(graph,"From Ancestor fitting","p"); leg0->AddEntry(graph1,"From One Comp fitting","p"); // leg0->AddEntry(Gri055_graph,"Gribov #Omega=0.55","p"); // leg0->AddEntry(Gri101_graph,"Gribov #Omega=1.01","p"); if(str=="Npart") leg0->AddEntry(graphNpartDil,"Npart from run I","p"); if(str=="Ncoll") leg0->AddEntry(graphNcollDil,"Ncoll from run I","p"); leg0->Draw(); c1->SaveAs(Form("%sGri.png",str.Data())); c1->SaveAs(Form("%sGri.pdf",str.Data())); TCanvas *c2 = new TCanvas("c2","c2",1,1,550,460); c2->SetFillColor(10); c2->SetFrameFillColor(0); c2->SetFrameBorderSize(0); c2->SetFrameBorderMode(0); c2->SetLeftMargin(0.15); c2->SetBottomMargin(0.15); c2->SetTopMargin(0.02); c2->SetRightMargin(0.02); c2->SetTicks(-1); c2->cd(); TGraphErrors* fdvf1 = (TGraphErrors*)graph->Clone("fdvf1"); TGraphErrors* f1dvDil = (TGraphErrors*)graph->Clone("f1dvDil"); TGraphErrors* fdvDil = (TGraphErrors*)graph->Clone("fdvDil"); TGraphErrors* Dilsys = (TGraphErrors*)graph->Clone("Dilsys"); TGraphErrors* Dilsys2 = (TGraphErrors*)graph->Clone("Dilsys2"); for(int ip = 0;ip<fdvf1->GetN();ip++){ double x = graph->GetX()[ip]; double ey = graph->GetEY()[ip]; double y = graph->GetY()[ip]; double ey1 = graph1->GetEY()[ip]; double y1 = graph1->GetY()[ip]; double eyNcoll = graphNcollDil->GetEY()[ip]; double yNcoll = graphNcollDil->GetY()[ip]; double eyNpart = graphNpartDil->GetEY()[ip]; double yNpart = graphNpartDil->GetY()[ip]; if(y1!=0 && y!=0){ fdvf1->SetPoint(ip,x,y/y1); fdvf1->SetPointError(ip,0,y/y1*sqrt((ey/y)**2+(ey1/y1)**2)); if(str=="Ncoll"){ fdvDil->SetPoint(ip,x,y/yNcoll); double yerr = y/yNcoll*sqrt((ey/y)**2+(eyNcoll/yNcoll)**2); fdvDil->SetPointError(ip,0,0); f1dvDil->SetPoint(ip,x,y1/yNcoll); double y1err = y1/yNcoll*sqrt((ey1/y1)**2+(eyNcoll/yNcoll)**2); f1dvDil->SetPointError(ip,0,0); Dilsys->SetPoint(ip,x,1.); Dilsys->SetPointError(ip,0,TMath::Max(fabs(y1/yNcoll-1),fabs(y/yNcoll-1))); Dilsys2->SetPoint(ip,x,1.); Dilsys2->SetPointError(ip,0,TMath::Max(yerr,y1err)); } else if(str=="Npart"){ fdvDil->SetPoint(ip,x,y/yNpart); double yerr = y/yNpart*sqrt((ey/y)**2+(eyNcoll/yNpart)**2); fdvDil->SetPointError(ip,0,0); f1dvDil->SetPoint(ip,x,y1/yNpart); double y1err = y1/yNpart*sqrt((ey1/y1)**2+(eyNcoll/yNcoll)**2); f1dvDil->SetPointError(ip,0,0); Dilsys->SetPoint(ip,x,1.); Dilsys->SetPointError(ip,0,TMath::Max(fabs(y1/yNpart-1),fabs(y/yNpart-1))); Dilsys2->SetPoint(ip,x,1.); Dilsys2->SetPointError(ip,0,TMath::Max(yerr,y1err)); } } } hist->SetMinimum(0.5); hist->SetMaximum(1.5); hist->SetYTitle(Form("<%s> ratio",str.Data())); hist->Draw(); fdvf1->SetMarkerStyle(20); fdvf1->SetMarkerColor(1); fdvf1->SetLineColor(1); fdvf1->SetLineWidth(2); fdvf1->SetMarkerSize(1.4); //fdvf1->Draw("Psameez"); f1dvDil->SetMarkerStyle(24); f1dvDil->SetMarkerColor(2); f1dvDil->SetLineColor(2); f1dvDil->SetLineWidth(2); f1dvDil->SetMarkerSize(1.4); fdvDil->SetMarkerStyle(20); fdvDil->SetMarkerColor(4); fdvDil->SetLineColor(4); fdvDil->SetLineWidth(2); fdvDil->SetMarkerSize(1.4); Dilsys->SetFillColor(kYellow+2); Dilsys2->SetFillColor(kYellow+1); //Dilsys2->Draw("e3same"); Dilsys->Draw("e3same"); fdvDil->Draw("Psameez"); f1dvDil->Draw("Psameez"); tex1->Draw(); TLine *l = new TLine(0,1,N,1); l->SetLineStyle(2); l->SetLineWidth(3); l->Draw("same"); TLegend *leg1 = new TLegend(0.38,0.72,0.75,0.86); leg1->SetFillColor(10); leg1->SetBorderSize(0); leg1->SetTextFont(42); leg1->SetTextSize(0.04); //leg1->AddEntry(fdvf1,"Ancestor fitting/One Comp fitting","p"); leg1->AddEntry(f1dvDil,"One Component fitting/Run I fitting","p"); leg1->AddEntry(fdvDil,"Two Component fitting/Run I fitting","p"); leg1->AddEntry(Dilsys,"RunI fitting systematics","f"); // leg1->AddEntry(Dilsys2,"RunI fitting ratio systematics","f"); double y = gPad->GetUymin()+0.5; for (int i=0;i<N;i++) { double x = hist->GetXaxis()->GetBinCenter(i+1); t.DrawText(x,y,label[i]); } leg1->Draw(); c2->SaveAs(Form("%sGriratio.png",str.Data())); c2->SaveAs(Form("%sGriratio.pdf",str.Data())); }
// Soft radiation corrections for L3Res void softrad(double etamin=0.0, double etamax=1.3, bool dodijet=false) { setTDRStyle(); writeExtraText = false; // for JEC paper CWR TDirectory *curdir = gDirectory; // Open jecdata.root produced by reprocess.C TFile *fin = new TFile("rootfiles/jecdata.root","UPDATE"); assert(fin && !fin->IsZombie()); const int ntypes = 3; const char* types[ntypes] = {"data", "mc", "ratio"}; const int nmethods = 2; const char* methods[nmethods] = {"mpfchs1", "ptchs"}; const int nsamples = (dodijet ? 4 : 3); const char* samples[4] = {"gamjet", "zeejet", "zmmjet", "dijet"}; string sbin = Form("eta%02.0f-%02.0f",10*etamin,10*etamax); const char* bin = sbin.c_str(); const int nalphas = 4; const int alphas[nalphas] = {30, 20, 15, 10}; // Z+jet bins const double ptbins1[] = {30, 40, 50, 60, 75, 95, 125, 180, 300, 1000}; const int npt1 = sizeof(ptbins1)/sizeof(ptbins1[0])-1; TH1D *hpt1 = new TH1D("hpt1","",npt1,&ptbins1[0]); TProfile *ppt1 = new TProfile("ppt1","",npt1,&ptbins1[0]); // gamma+jet bins const double ptbins2[] = {30, 40, 50, 60, 75, 100, 125, 155, 180, 210, 250, 300, 350, 400, 500, 600, 800}; const int npt2 = sizeof(ptbins2)/sizeof(ptbins2[0])-1; TH1D *hpt2 = new TH1D("hpt2","",npt2,&ptbins2[0]); TProfile *ppt2 = new TProfile("ppt2","",npt2,&ptbins2[0]); // dijet bins const double ptbins4[] = {20, 62, 107, 175, 242, 310, 379, 467, 628, 839, 1121, 1497, 2000}; const int npt4 = sizeof(ptbins4)/sizeof(ptbins4[0])-1; TH1D *hpt4 = new TH1D("hpt4","",npt4,&ptbins4[0]); TProfile *ppt4 = new TProfile("ppt4","",npt4,&ptbins4[0]); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(0.045); map<string,const char*> texlabel; texlabel["gamjet"] = "#gamma+jet"; texlabel["zeejet"] = "Z#rightarrowee+jet"; texlabel["zmmjet"] = "Z#rightarrow#mu#mu+jet"; texlabel["dijet"] = "Dijet"; texlabel["ptchs"] = "p_{T} balance (CHS)"; texlabel["mpfchs"] = "MPF raw (CHS)"; texlabel["mpfchs1"] = "MPF type-I (CHS)"; // overlay of various alpha values TCanvas *c1 = new TCanvas("c1","c1",ntypes*400,nmethods*400); c1->Divide(ntypes,nmethods); TH1D *h1 = new TH1D("h1",";p_{T} (GeV);Response",1270,30,1300); // extrapolation vs alpha for each pT bin vector<TCanvas*> c2s(ntypes*nmethods); for (unsigned int icanvas = 0; icanvas != c2s.size(); ++icanvas) { TCanvas *c2 = new TCanvas(Form("c2_%d",icanvas),Form("c2_%d",icanvas), 1200,1200); c2->Divide(3,3); c2s[icanvas] = c2; } TH1D *h2 = new TH1D("h2",";#alpha;Response",10,0.,0.4); h2->SetMaximum(1.08); h2->SetMinimum(0.88); // krad corrections TCanvas *c3 = new TCanvas("c3","c3",ntypes*400,nmethods*400); c3->Divide(ntypes,nmethods); TH1D *h3 = new TH1D("h3",";p_{T,ref} (GeV);FSR sensitivity: -dR/d#alpha [%]", 1270,30,1300); cout << "Reading in data" << endl << flush; // Read in plots vs pT (and alpha) map<string, map<string, map<string, map<int, TGraphErrors*> > > > gemap; map<string, map<string, map<string, map<int, TGraphErrors*> > > > gamap; for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { for (int isample = 0; isample != nsamples; ++isample) { for (int ialpha = 0; ialpha != nalphas; ++ialpha) { fin->cd(); assert(gDirectory->cd(types[itype])); assert(gDirectory->cd(bin)); TDirectory *d = gDirectory; const char *ct = types[itype]; const char *cm = methods[imethod]; const char *cs = samples[isample]; const int a = alphas[ialpha]; // Get graph made vs pT string s = Form("%s/%s/%s_%s_a%d",types[itype],bin,cm,cs,a); TGraphErrors *g = (TGraphErrors*)fin->Get(s.c_str()); if (!g) cout << "Missing " << s << endl << flush; assert(g); // Clean out empty points // as well as trigger-biased ones for dijets // as well as weird gamma+jet high pT point for (int i = g->GetN()-1; i != -1; --i) { if (g->GetY()[i]==0 || g->GetEY()[i]==0 || (string(cs)=="dijet" && g->GetX()[i]<70.) || (string(cs)=="gamjet" && g->GetX()[i]>600. && etamin!=0)) g->RemovePoint(i); } gemap[ct][cm][cs][a] = g; // Sort points into new graphs vs alpha TH1D *hpt = (isample==0 ? hpt2 : hpt1); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { hpt = hpt4; ppt = ppt4; } // pas-v6 for (int i = 0; i != g->GetN(); ++i) { double pt = g->GetX()[i]; ppt->Fill(pt, pt); int ipt = int(hpt->GetBinLowEdge(hpt->FindBin(pt))+0.5); //int ipt = int(pt+0.5); TGraphErrors *ga = gamap[ct][cm][cs][ipt]; if (!ga) { ga = new TGraphErrors(0); ga->SetMarkerStyle(g->GetMarkerStyle()); ga->SetMarkerColor(g->GetMarkerColor()); ga->SetLineColor(g->GetLineColor()); gamap[ct][cm][cs][ipt] = ga; } int n = ga->GetN(); ga->SetPoint(n, 0.01*a, g->GetY()[i]); ga->SetPointError(n, 0, g->GetEY()[i]); } // for i } // for ialpha } // for isample } // for imethod } // for itype cout << "Drawing plots vs pT for each alpha" << endl << flush; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { const char *ct = types[itype]; const char *cm = methods[imethod]; int ipad = ntypes*imethod + itype + 1; assert(ipad<=6); c1->cd(ipad); gPad->SetLogx(); h1->SetMaximum(itype<2 ? 1.15 : 1.08); h1->SetMinimum(itype<2 ? 0.85 : 0.93); h1->SetYTitle(Form("Response (%s)",ct)); h1->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3, #alpha=0.1--0.3"); TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90); for (int isample = 0; isample != nsamples; ++isample) { for (int ialpha = 0; ialpha != nalphas; ++ialpha) { const char *cs = samples[isample]; const int a = alphas[ialpha]; TGraphErrors *g = gemap[ct][cm][cs][a]; assert(g); // Clean out points with very large uncertainty for plot readability for (int i = g->GetN()-1; i != -1; --i) { if (g->GetEY()[i]>0.02) g->RemovePoint(i); } g->Draw("SAME Pz"); if (ialpha==0) leg->AddEntry(g,texlabel[cs],"P"); } } // for isample // Individual plots for JEC paper if ( true ) { // paper TH1D *h = new TH1D(Form("h_5%s_%s",ct,cm), Form(";p_{T} (GeV);Response (%s)",ct), 1270,30,1300); h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); h->SetMinimum(0.88); h->SetMaximum(1.13); writeExtraText = true; extraText = (string(ct)=="mc" ? "Simulation" : ""); lumi_8TeV = (string(ct)=="mc" ? "" : "19.7 fb^{-1}"); TCanvas *c0 = tdrCanvas(Form("c0_%s_%s",cm,ct), h, 2, 11, true); c0->SetLogx(); TLegend *leg = tdrLeg(0.55,0.68,0.85,0.83); tex->DrawLatex(0.55,0.85,texlabel[cm]); tex->DrawLatex(0.55,0.18,"|#eta| < 1.3, #alpha=0.3"); //tex->DrawLatex(0.55,0.18,"Anti-k_{T} R=0.5"); // Loop over Z+jet and gamma+jet (only, no dijet/multijet) for (int isample = 0; isample != min(3,nsamples); ++isample) { const char *cs = samples[isample]; TGraphErrors *g = gemap[ct][cm][cs][30]; assert(g); g->Draw("SAME Pz"); leg->AddEntry(g,texlabel[cs],"P"); } // for isample if (etamin==0) { c0->SaveAs(Form("pdf/paper_softrad_%s_%s_vspt.pdf",ct,cm)); c0->SaveAs(Form("pdfC/paper_softrad_%s_%s_vspt.C",ct,cm)); } else { c0->SaveAs(Form("pdf/an_softrad_%s_%s_eta%1.0f-%1.0f_vspt.pdf", ct,cm,10*etamin,10*etamax)); } } // paper } // for imethod } // for itype c1->cd(0); //cmsPrel(_lumi, true); CMS_lumi(c1, 2, 33); c1->SaveAs("pdf/softrad_2x6_vspt.pdf"); cout << "Drawing plots vs alpha for each pT" << endl << flush; cout << "...and fitting slope vs alpha" << endl << flush; map<string, map<string, map<string, TGraphErrors* > > > gkmap; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { int icanvas = nmethods*imethod + itype; assert(icanvas<=6); TCanvas *c2 = c2s[icanvas]; assert(c2); const char *ct = types[itype]; const char *cm = methods[imethod]; const int npads = 9; for (int ipad = 0; ipad != npads; ++ipad) { c2->cd(ipad+1); h2->SetYTitle(Form("Response (%s)",ct)); h2->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3"); tex->DrawLatex(0.20,0.75,Form("%1.0f < p_{T} < %1.0f GeV", hpt1->GetBinLowEdge(ipad+1), hpt1->GetBinLowEdge(ipad+2))); TLegend *leg = tdrLeg(0.65,0.75,0.90,0.90); leg->AddEntry(gemap[ct][cm]["gamjet"][30], texlabel["gamjet"], "P"); leg->AddEntry(gemap[ct][cm]["zeejet"][30], texlabel["zeejet"], "P"); leg->AddEntry(gemap[ct][cm]["zmmjet"][30], texlabel["zmmjet"], "P"); leg->AddEntry(gemap[ct][cm]["dijet"][30], texlabel["dijet"], "P"); } for (int isample = 0; isample != nsamples; ++isample) { const char *cs = samples[isample]; map<int, TGraphErrors*> &gam = gamap[ct][cm][cs]; map<int, TGraphErrors*>::iterator itpt; for (itpt = gam.begin(); itpt != gam.end(); ++itpt) { int ipt = itpt->first; int jpt = hpt1->FindBin(ipt); if (jpt>npads) continue; assert(jpt<=npads); c2->cd(jpt); TGraphErrors *ga = itpt->second; assert(ga); ga->Draw("SAME Pz"); // Fit slope TF1 *f1 = new TF1(Form("f1_%s_%s_%s_%d",ct,cm,cs,ipt), "(x<1)*([0]+[1]*x) + (x>1 && x<2)*[0] +" "(x>2)*[1]",-1,1); f1->SetLineColor(ga->GetLineColor()); f1->SetParameters(1,0); const double minalpha = (isample==0 ? 10./ipt : 5./ipt); // Constrain slope to within reasonable values // in the absence of sufficient data using priors if (true) { // use priors int n = ga->GetN(); // For response, limit to 1+/-0.02 (we've corrected for L3Res ga->SetPoint(n, 1.5, 1); ga->SetPointError(n, 0, 0.02); n = ga->GetN(); if (imethod==1) { // pT balance // For pT balance, estimate slope of <vecpT2>/alpha from data // => 7.5%/0.30 = 25% // Approximate uncertainty on this to be // 0.5%/0.30 ~ 1.5% for data, 0.5%/0.30 ~ 1.5% for Z+jet MC, and // 2%/0.30 ~ 6% for gamma+jet MC (same as slope) if (itype==0) ga->SetPoint(n, 2.5, -0.250); // DT if (itype==1 && isample!=0) ga->SetPoint(n, 2.5, -0.250); // MC if (itype==1 && isample==0) ga->SetPoint(n, 2.5, -0.190); if (itype==2 && isample!=0) ga->SetPoint(n, 2.5, -0.000); // rt if (itype==2 && isample==0) ga->SetPoint(n, 2.5, -0.060); // // BUG: found 2015-01-08 (no effect on ratio) //if (itype==1) ga->SetPointError(n, 0, -0.015); if (itype==0) ga->SetPointError(n, 0, -0.015); // DT if (itype==1 && isample!=0) ga->SetPointError(n, 0, -0.015); // MC if (itype==1 && isample==0) ga->SetPointError(n, 0, -0.060); if (itype==2 && isample!=0) ga->SetPointError(n, 0, -0.015); // rt if (itype==2 && isample==0) ga->SetPointError(n, 0, -0.060); } if (imethod==0) { // MPF // For MPF, expectation is no slope // Maximal slope would be approximately // (<vecpT2>/alpha ~ 25% from pT balance) times // (response difference between pT1 and vecpT2~10%) // => 0.25*0.10 = 2.5% // For data/MC, estimate uncertainty as half of this // => 1.25% ga->SetPoint(n, 2.5, 0.); if (itype!=2) ga->SetPointError(n, 0, 0.025); if (itype==2) ga->SetPointError(n, 0, 0.0125); } // MPF } // use priors if (ga->GetN()>2) { f1->SetRange(minalpha, 3.); ga->Fit(f1,"QRN"); if (f1->GetNDF()>=0) { f1->DrawClone("SAME"); f1->SetRange(0,0.4); f1->SetLineStyle(kDashed); f1->DrawClone("SAME"); // Store results TGraphErrors *gk = gkmap[ct][cm][cs]; if (!gk) { gk = new TGraphErrors(0); gk->SetMarkerStyle(ga->GetMarkerStyle()); gk->SetMarkerColor(ga->GetMarkerColor()); gk->SetLineColor(ga->GetLineColor()); gkmap[ct][cm][cs] = gk; } int n = gk->GetN(); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { ppt = ppt4; } // pas-v6 double pt = ppt->GetBinContent(ppt->FindBin(ipt)); gk->SetPoint(n, pt, f1->GetParameter(1)); gk->SetPointError(n, 0, f1->GetParError(1)); } // f1->GetNDF()>=0 } // ga->GetN()>2 } // for itpt } // for isample c2->SaveAs(Form("pdf/softrad_3x3_%s_%s_vsalpha.pdf",ct,cm)); } } cout << "Drawing plots of kFSR vs pT" << endl; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { const char *ct = types[itype]; const char *cm = methods[imethod]; TMultiGraph *mgk = new TMultiGraph(); int ipad = ntypes*imethod + itype + 1; assert(ipad<=6); c3->cd(ipad); gPad->SetLogx(); h3->SetMaximum(imethod==0 ? 0.05 : (itype!=2 ? 0.1 : 0.25)); h3->SetMinimum(imethod==0 ? -0.05 : (itype!=2 ? -0.4 : -0.25)); h3->SetYTitle(Form("k_{FSR} = dR/d#alpha (%s)",ct)); h3->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3"); TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90); for (int isample = 0; isample != nsamples; ++isample) { const char *cs = samples[isample]; TGraphErrors *gk = gkmap[ct][cm][cs]; assert(gk); leg->AddEntry(gk,texlabel[cs],"P"); // Fit each sample separately for pT balance if (true) { TF1 *fk = new TF1(Form("fk_%s_%s_%s",ct,cm,cs), "[0]+[1]*log(0.01*x)+[2]*pow(log(0.01*x),2)", 30,1300); fk->SetParameters(-0.25,-0.5); fk->SetLineColor(gk->GetLineColor()); gk->Fit(fk, "QRN"); tex->SetTextColor(fk->GetLineColor()); tex->DrawLatex(0.55,0.27-0.045*isample, Form("#chi^{2}/NDF = %1.1f / %d", fk->GetChisquare(), fk->GetNDF())); tex->SetTextColor(kBlack); // Error band const int n = fk->GetNpar(); TMatrixD emat(n,n); gMinuit->mnemat(emat.GetMatrixArray(), n); TF1 *fke = new TF1(Form("fk_%s_%s_%s",ct,cm,cs), sr_fitError, 30, 1300, 1); _sr_fitError_func = fk; _sr_fitError_emat = &emat; fke->SetLineStyle(kSolid); fke->SetLineColor(fk->GetLineColor()-10); fke->SetParameter(0,-1); fke->DrawClone("SAME"); fke->SetParameter(0,+1); fke->DrawClone("SAME"); fk->DrawClone("SAME"); gk->DrawClone("SAME Pz"); // Store soft radiation corrections in fsr subdirectory assert(fin->cd(ct)); assert(gDirectory->cd(bin)); if (!gDirectory->FindObject("fsr")) gDirectory->mkdir("fsr"); assert(gDirectory->cd("fsr")); TH1D *hk = (TH1D*)(isample==0 ? hpt2->Clone() : hpt1->Clone()); hk->SetName(Form("hkfsr_%s_%s",cm,cs)); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { ppt = ppt4; } // pas-v6 for (int i = 1; i != hk->GetNbinsX()+1; ++i) { double pt = ppt->GetBinContent(i); if (pt>30 && pt<1300) { hk->SetBinContent(i, fk->Eval(pt)); hk->SetBinError(i, fabs(fke->Eval(pt)-fk->Eval(pt))); } else { hk->SetBinContent(i, 0); hk->SetBinError(i, 0); } } hk->Write(hk->GetName(), TObject::kOverwrite); // Factorize error matrix into eigenvectors // Remember: A = Q*Lambda*Q^-1, where // A is emat, Q is eigmat, and Lambda is a diagonal matrix with // eigenvalues from eigvec on the diagonal. For eigenmatrix // Q^-1 = Q^T, i.e. inverse matrix is the original transposed TVectorD eigvec(n); TMatrixD eigmat = emat.EigenVectors(eigvec); // Eigenvectors are the columns and sum of eigenvectors squared // equals original uncertainty. Calculate histograms from the // eigenvectors and store them TF1 *fkeig = (TF1*)fk->Clone(Form("%s_eig",fk->GetName())); fkeig->SetLineStyle(kDotted); for (int ieig = 0; ieig != n; ++ieig) { // Eigenvector functions for (int i = 0; i != n; ++i) { fkeig->SetParameter(i, fk->GetParameter(i) + eigmat[i][ieig] * sqrt(eigvec[ieig])); } fkeig->DrawClone("SAMEL"); // Eigenvector histograms evaluated at bin mean pT TH1D *hke = (TH1D*)hk->Clone(Form("%s_eig%d",hk->GetName(),ieig)); hke->Reset(); for (int i = 0; i != gk->GetN(); ++i) { double pt = gk->GetX()[i]; int ipt = hke->FindBin(pt); // Need to store central value as well, because // uncertainty sources are signed hke->SetBinContent(ipt, fkeig->Eval(pt)-fk->Eval(pt)); hke->SetBinError(ipt, fabs(fkeig->Eval(pt)-fk->Eval(pt))); } hke->Write(hke->GetName(), TObject::kOverwrite); } cout << "." << flush; } // if tree } // for isample } // for imethod } // for itype c3->cd(0); //cmsPrel(_lumi, true); CMS_lumi(c3, 2, 33); c3->SaveAs("pdf/softrad_2x6_kfsr.pdf"); fin->Close(); curdir->cd(); } // softrad
void DrawCosmicResult(){ TFile* tf = new TFile("Cosmic3Out.root"); TTree* trin = (TTree*)tf->Get("trOut"); const int nCSI = 2716; Int_t RunNumber; Int_t EventNumber; Double_t ScintiSignal = 0; Double_t ScintiHHTime = -500.; Double_t ScintiTime =-500.; Int_t nCSIDigi = 0; Double_t CSIDigiE[nCSI];//nCSIDigi Double_t CSIDigiTime[nCSI];//nCSIDigi Double_t CSIDigiHHTime[nCSI];//nCSIDigi Int_t CSIDigiID[nCSI];//nCSIDigi Double_t CSIDigiSignal[nCSI];//nCSIDigi Double_t FitP0[2]; Double_t FitP1[2]; Double_t FitChisq[2]; Double_t CSIDigiDeltaT0[nCSI];//nCSIDigi Double_t CSIDigiDeltaT1[nCSI];//nCSIDigi Int_t CosmicTrigUp; Int_t CosmicTrigDn; Double_t Roh; Double_t Theta; trin->SetBranchAddress( "RunNumber" , &RunNumber ); trin->SetBranchAddress( "EventNumber" , &EventNumber ); trin->SetBranchAddress( "ScintiSignal" , &ScintiSignal ); trin->SetBranchAddress( "ScintiHHTimne" , &ScintiHHTime ); trin->SetBranchAddress( "ScintiTime" , &ScintiTime ); trin->SetBranchAddress( "nCSIDigi" , &nCSIDigi ); trin->SetBranchAddress( "CSIDigiE" , CSIDigiE ); trin->SetBranchAddress( "CSIDigiTime" , CSIDigiTime ); trin->SetBranchAddress( "CSIDigiHHTime" , CSIDigiHHTime ); trin->SetBranchAddress( "CSIDigiID" , CSIDigiID ); trin->SetBranchAddress( "CSIDigiSignal" , CSIDigiSignal ); trin->SetBranchAddress( "CSIDigiDeltaT0" , CSIDigiDeltaT0 ); trin->SetBranchAddress( "CSIDigiDeltaT1" , CSIDigiDeltaT1 ); trin->SetBranchAddress( "FitP0" , FitP0 ); trin->SetBranchAddress( "FitP1" , FitP1 ); trin->SetBranchAddress( "FitChisq" , FitChisq ); trin->SetBranchAddress( "CosmicTrigUp" , &CosmicTrigUp ); trin->SetBranchAddress( "CosmicTrigDn" , &CosmicTrigDn ); trin->SetBranchAddress( "Roh" , &Roh ); trin->SetBranchAddress( "Theta" , &Theta ); TFile* tfout = new TFile("CosmicOut_hist3.root", "recreate"); TH2D* hisDeltaChannel = new TH2D("hisDeltaChannel","hisDeltaChannel",2716,0,2716,100,-10,10); TH1D* hisDelta[2716]; TGraphErrors* grDelta = new TGraphErrors(); TGraphErrors* grRES = new TGraphErrors(); TCanvas *can = new TCanvas("can","",800,800); for( int i = 0; i< 2716; i++){ hisDelta[i] = new TH1D(Form("hisDelta%d",i ),Form("hisDelta%d",i),100,-10,10); } for( int ievent = 0; ievent < trin->GetEntries(); ievent++){ trin->GetEntry(ievent); for( int idigi = 0; idigi < nCSIDigi ; idigi++){ hisDelta[ CSIDigiID[ idigi ] ]->Fill( CSIDigiDeltaT1[ idigi ] ); hisDeltaChannel->Fill( CSIDigiID[ idigi ] , CSIDigiDeltaT1[ idigi ] ); //std::cout << CSIDigiID[ idigi ] << std::endl; } } for( int i = 0; i< 2716; i++){ //std::cout << hisDelta[i]->GetEntries() << std::endl; if( hisDelta[i]->GetEntries() > 10){ int rst = hisDelta[i]->Fit("gaus","Q","",hisDelta[i]->GetBinCenter( hisDelta[i]->GetMaximumBin() ) - 3, hisDelta[i]->GetBinCenter( hisDelta[i]->GetMaximumBin() )+3); TF1* func = NULL; func = hisDelta[i]->GetFunction("gaus"); if( func != NULL ){ grDelta->SetPoint( grDelta->GetN(), i, func->GetParameter(1)); grDelta->SetPointError( grDelta->GetN()-1, 0, func->GetParError(2)); grRES->SetPoint( grRES->GetN() , i , func->GetParameter(2)); } } /* hisDelta[i]->Draw(); can->Modified(); can->Update(); getchar(); */ hisDelta[ i ] ->Write(); } std::ofstream ofs("TimeResolutionCosmic3.dat"); int ID[2716]; double Delta[2716]; double Resolution[2716]; for( int i = 0; i< 2716; i++){ Resolution[i] = 0xFFFF; Delta[i] = 0xFFFF; } for( int i = 0; i< grRES->GetN(); i++){ Delta[(int)(grDelta->GetX()[i])] = grDelta->GetY()[i]; Resolution[(int)(grRES->GetX()[i])] = grRES->GetY()[i] ; } for( int i = 0; i< 2716; i++){ ofs << i << "\t" << Delta[i] << "\t" << Resolution[i] << "\n"; } grDelta->SetNameTitle("grDelta","grDelta"); grRES->SetNameTitle("grRES","grRES"); grDelta->Write(); grRES->Write(); hisDeltaChannel->Write(); tfout->Close(); ofs.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; }
//------------------------------------------------------------------------------ // // drawXS // //------------------------------------------------------------------------------ void drawXS(UInt_t theCharge = WInclusive) { gStyle->SetEndErrorSize(5); // 7 TeV inclusive //---------------------------------------------------------------------------- xs_value[WInclusive][EEE] = 23.00; xs_value[WInclusive][EEM] = 19.67; xs_value[WInclusive][MME] = 19.81; xs_value[WInclusive][MMM] = 21.02; xs_value[WInclusive][all] = 20.76; xs_stat[WInclusive][EEE] = 3.10; xs_stat[WInclusive][EEM] = 2.73; xs_stat[WInclusive][MME] = 2.60; xs_stat[WInclusive][MMM] = 2.30; xs_stat[WInclusive][all] = 1.32; xs_syst[WInclusive][EEE] = 1.39; xs_syst[WInclusive][EEM] = 1.50; xs_syst[WInclusive][MME] = 1.55; xs_syst[WInclusive][MMM] = 1.47; xs_syst[WInclusive][all] = 1.13; xs_lumi[WInclusive][EEE] = 0.51; xs_lumi[WInclusive][EEM] = 0.43; xs_lumi[WInclusive][MME] = 0.44; xs_lumi[WInclusive][MMM] = 0.46; xs_lumi[WInclusive][all] = 0.46; // 7 TeV W+ //---------------------------------------------------------------------------- xs_value[WPlus][EEE] = 13.39; xs_value[WPlus][EEM] = 13.18; xs_value[WPlus][MME] = 14.14; xs_value[WPlus][MMM] = 11.43; xs_value[WPlus][all] = 12.73; xs_stat[WPlus][EEE] = 2.39; xs_stat[WPlus][EEM] = 2.24; xs_stat[WPlus][MME] = 2.19; xs_stat[WPlus][MMM] = 1.71; xs_stat[WPlus][all] = 1.04; xs_syst[WPlus][EEE] = 0.75; xs_syst[WPlus][EEM] = 0.64; xs_syst[WPlus][MME] = 0.74; xs_syst[WPlus][MMM] = 0.53; xs_syst[WPlus][all] = 0.59; xs_lumi[WPlus][EEE] = 0.29; xs_lumi[WPlus][EEM] = 0.29; xs_lumi[WPlus][MME] = 0.31; xs_lumi[WPlus][MMM] = 0.25; xs_lumi[WPlus][all] = 0.28; // 7 TeV W- //---------------------------------------------------------------------------- xs_value[WMinus][EEE] = 9.49; xs_value[WMinus][EEM] = 6.51; xs_value[WMinus][MME] = 5.73; xs_value[WMinus][MMM] = 9.48; xs_value[WMinus][all] = 7.46; xs_stat[WMinus][EEE] = 1.95; xs_stat[WMinus][EEM] = 1.58; xs_stat[WMinus][MME] = 1.40; xs_stat[WMinus][MMM] = 1.52; xs_stat[WMinus][all] = 0.79; xs_syst[WMinus][EEE] = 0.60; xs_syst[WMinus][EEM] = 0.37; xs_syst[WMinus][MME] = 0.37; xs_syst[WMinus][MMM] = 0.50; xs_syst[WMinus][all] = 0.40; xs_lumi[WMinus][EEE] = 0.21; xs_lumi[WMinus][EEM] = 0.14; xs_lumi[WMinus][MME] = 0.13; xs_lumi[WMinus][MMM] = 0.21; xs_lumi[WMinus][all] = 0.16; // Do the work //---------------------------------------------------------------------------- TGraphErrors* gStat = new TGraphErrors(nChannel); TGraphErrors* gSyst = new TGraphErrors(nChannel); TGraphErrors* gLumi = new TGraphErrors(nChannel); for (UInt_t i=0; i<nChannel; i++) { Double_t errorSquared = (xs_stat[theCharge][i] * xs_stat[theCharge][i]); gStat->SetPointError(i, sqrt(errorSquared) / xs_nlo[theCharge], 0.0); errorSquared += (xs_syst[theCharge][i] * xs_syst[theCharge][i]); gSyst->SetPointError(i, sqrt(errorSquared) / xs_nlo[theCharge], 0.0); errorSquared += (xs_lumi[theCharge][i] * xs_lumi[theCharge][i]); gLumi->SetPointError(i, sqrt(errorSquared) / xs_nlo[theCharge], 0.0); gStat->SetPoint(i, xs_value[theCharge][i] / xs_nlo[theCharge], nChannel-i-1); gSyst->SetPoint(i, xs_value[theCharge][i] / xs_nlo[theCharge], nChannel-i-1); gLumi->SetPoint(i, xs_value[theCharge][i] / xs_nlo[theCharge], nChannel-i-1); } // Cosmetics //---------------------------------------------------------------------------- gStat->SetLineWidth (2); gStat->SetMarkerSize (1.3); gStat->SetMarkerStyle(kFullCircle); gSyst->SetLineColor (kRed); gSyst->SetLineWidth (2); gSyst->SetMarkerSize (1.3); gSyst->SetMarkerStyle(kFullCircle); gLumi->SetLineColor (kBlue); gLumi->SetLineWidth (2); gLumi->SetMarkerSize (1.3); gLumi->SetMarkerStyle(kFullCircle); // Draw //---------------------------------------------------------------------------- TString suffix = "7TeV_" + sCharge[theCharge]; TCanvas* canvas = new TCanvas("ratioNLO_" + suffix, "ratioNLO_" + suffix); canvas->SetLeftMargin(canvas->GetRightMargin()); Double_t xmin = 0.0; Double_t xmax = 2.0; Double_t ylegend = 1.2; Double_t ymin = -0.6; Double_t ymax = nChannel + ymin + ylegend; TH2F* h2 = new TH2F("h2_" + suffix, "", 100, xmin, xmax, 100, ymin, ymax); h2->Draw(); // NLO WZ cross-section //---------------------------------------------------------------------------- TBox* nlo = new TBox(1. - xs_nlo_left [theCharge] / xs_nlo[theCharge], ymin, 1. + xs_nlo_right[theCharge] / xs_nlo[theCharge], ymax - ylegend); nlo->SetLineColor(0); nlo->SetFillColor(kGray); nlo->SetFillStyle(1001); nlo->Draw("e2,same"); TLine* line = new TLine(1., ymin, 1., ymax - ylegend); line->SetLineColor(kGray+1); line->SetLineWidth(2); line->Draw("same"); // Cross sections //---------------------------------------------------------------------------- gLumi->Draw("p,same"); gSyst->Draw("p,same"); gStat->Draw("p,same"); // Labels //---------------------------------------------------------------------------- for (UInt_t i=0; i<nChannel; i++) { Double_t x = gStat->GetX()[i]; Double_t y = gStat->GetY()[i]; Double_t gStatError = gStat->GetErrorX(i); Double_t gSystError = gSyst->GetErrorX(i); Double_t gLumiError = gLumi->GetErrorX(i); DrawTLatex(42, xmin+0.06, y+0.15, 0.035, 12, Form("%s %.2f #pm %.2f", lChannel[i].Data(), x, gLumiError), 0); gLumiError = sqrt(gLumiError*gLumiError - gSystError*gSystError); gSystError = sqrt(gSystError*gSystError - gStatError*gStatError); DrawTLatex(42, xmin+0.06, y-0.15, 0.025, 12, Form("%.2f #pm %.2f #pm %.2f #pm %.2f", x, gStatError, gSystError, gLumiError), 0); } DrawTLatex(42, 0.050, 0.975, _bigLabelSize, 13, "CMS Preliminary"); DrawTLatex(42, 0.940, 0.983, _bigLabelSize, 33, Form("#sqrt{s} = 7 TeV, L = %.1f fb^{-1}", luminosity/1e3)); TString swz = ""; if (theCharge == WPlus) swz = "W^{+}Z"; else if (theCharge == WMinus) swz = "W^{-}Z"; else swz = "W^{#pm}Z"; h2->GetXaxis()->CenterTitle(); h2->GetXaxis()->SetTitleOffset(1.4); h2->GetXaxis()->SetTitle(Form("#sigma_{%s}^{exp} / #sigma_{%s}^{theory}", swz.Data(), swz.Data())); h2->GetYaxis()->SetTitle(""); // Remove y-axis labels //---------------------------------------------------------------------------- TAxis* yaxis = h2->GetYaxis(); for (Int_t j=1; j<yaxis->GetNbins(); j++) yaxis->SetBinLabel(j, ""); // Additional legend //---------------------------------------------------------------------------- DrawLegend(0.645, 0.840, gStat, " stat.", "lp"); DrawLegend(0.645, 0.795, nlo, " theory", "f"); DrawLegend(0.800, 0.840, gSyst, " syst.", "l"); DrawLegend(0.800, 0.795, gLumi, " lumi.", "l"); // Save //---------------------------------------------------------------------------- canvas->Update(); canvas->GetFrame()->DrawClone(); canvas->RedrawAxis(); canvas->SaveAs(Form("pdf/ratioNLO_%s.pdf", suffix.Data())); canvas->SaveAs(Form("png/ratioNLO_%s.png", suffix.Data())); }
int postprocessingSysError(){ cout<<endl<<endl<<endl<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Postproccess all systematic uncertainties! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl; gErrorIgnoreLevel = 1001; const TString method = "RMS99"; const TString type = "PFCHS"; const int nEta =4; double eta_bins[5] = {0., 0.5, 1.1, 1.7, 2.3}; // For looking at different systematic uncertainties independently const bool QCD = true; const bool JEC = true; const bool flavor = true; const bool PU = true; const bool MC = true; TString etaString, filename; TString rootFiles, AuxString; TString JetType = "PFCHS"; TString Method = "RMS99"; double *ratioEtaBinnedX = new double[nEta]; double *ratioEtaBinnedY = new double[nEta]; double *ratioEtaBinnedEX = new double[nEta]; double *ratioEtaBinnedEY = new double[nEta]; double *ratioEtaBinnedQCDUpY = new double[nEta]; double *ratioEtaBinnedQCDDownY = new double[nEta]; TF1 *QCDuncertainty; if(QCD){ rootFiles = (TString) "scripts/plotsQCD/FinalErrorsQCD_" + type + (TString) "_" + method + (TString) ".root"; TFile *_file = TFile::Open(rootFiles); _file->GetObject("function",QCDuncertainty); } for(int eta = 0; eta < nEta; eta++){ //cout<< endl<<endl<<endl<<eta+1<<". eta Bin!!"<<endl; // Read the MC and data results rootFiles = (TString) "root_files_FINAL_data/Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + JetType + (TString) "_data_" + Method + (TString) ".root"; TGraphErrors* JERData = readTGraphErrors(rootFiles,"Graph;1","Graph"); rootFiles = (TString) "root_files_FINAL_mc/Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + JetType + (TString) "_mc_" + Method + (TString) ".root"; TGraphErrors* JERMC = readTGraphErrors(rootFiles,"Graph","Graph"); if(eta+1 == 1) etaString = Form("JER for |#eta| < %4.1f",etaBins[eta+1]); else etaString = Form("JER for %4.1f <|#eta|< %4.1f",etaBins[eta+1],etaBins[eta+2]); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 1.) Calculate the ratio w/o systematic Uncertainties int nData = JERData->GetN(); double *dataX = JERData->GetX(); double *dataY = JERData->GetY(); double *dataEX = JERData->GetEX(); double *dataEY = JERData->GetEY(); double *mcX = new double[nData]; double *mcY = new double[nData]; double *mcEX = new double[nData]; double *mcEY = new double[nData]; double *ratioX = new double[nData]; double *ratioY = new double[nData]; double *ratioEX = new double[nData]; double *ratioEY = new double[nData]; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Initialize some stuff for QCD uncertainty double *ratioQCDUpY = new double[nData]; double *ratioQCDDownY = new double[nData]; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int idx = 0; for(int i=0; i<nData; i++){ JERMC -> GetPoint(idx,mcX[i],mcY[i]); mcEX[i] = JERMC -> GetErrorX(idx); mcEY[i] = JERMC -> GetErrorY(idx); idx += 1; if(TMath::Abs(dataX[i]/mcX[i] - 1.) > 0.1){ i -= 1; continue; } ratioX[i] = 1./2.*(dataX[i] + mcX[i]); ratioY[i] = dataY[i]/mcY[i]; ratioEX[i] = 1./2.*TMath::Sqrt(TMath::Power(dataEX[i],2)+TMath::Power(mcEX[i],2)); ratioEY[i] = TMath::Sqrt(TMath::Power((1./mcY[i]),2)*TMath::Power(dataEY[i],2)+TMath::Power((dataY[i]/(TMath::Power(mcY[i],2))),2)*TMath::Power(mcEY[i],2)); if(QCD){ // For QCD ratioQCDUpY[i] = ratioY[i]*(1. + QCDuncertainty->Eval(ratioX[i])); ratioQCDDownY[i] = ratioY[i]*(1. - QCDuncertainty->Eval(ratioX[i])); //cout<<"QCDuncertainty->Eval(ratioX[i]) = "<<QCDuncertainty->Eval(ratioX[i])<<endl; } } TGraphErrors *Ratio = new TGraphErrors(nData,ratioX,ratioY,ratioEX,ratioEY); // For QCD TGraphErrors *QCDUp = new TGraphErrors(nData,ratioX,ratioQCDUpY,ratioEX,ratioEY); TGraphErrors *QCDDown = new TGraphErrors(nData,ratioX,ratioQCDDownY,ratioEX,ratioEY); if(eta+1 == 1 ) AuxString = Form("Ratio between Data and MC for |#eta| < %4.1f",etaBins[eta+1]); else AuxString = Form("Ratio between Data and MC for %4.1f <|#eta|<%4.1f",etaBins[eta+1],etaBins[eta+2]); Ratio -> SetTitle(AuxString); Ratio -> GetXaxis() -> SetTitle("Photon pT"); Ratio -> GetXaxis() -> SetTitleOffset(1.1); Ratio -> GetYaxis() -> SetTitle("Ratio of JER (DATA/MC)"); Ratio -> GetYaxis() -> SetTitleOffset(1.2); Ratio -> GetXaxis() -> SetLimits(0,600); TF1* f1 = new TF1("name","pol0",0,600); Ratio -> Fit("name","QR"); TF1* fitQCDUp = new TF1("fitQCDUp","pol0",0,600); TF1* fitQCDDown = new TF1("fitQCDDown","pol0",0,600); if(QCD){ // For QCD QCDUp -> Fit("fitQCDUp","QR"); QCDDown -> Fit("fitQCDDown","QR"); } TLegend *legend = 0; legend = new TLegend(0.55,0.8,0.9,0.9); legend -> SetFillColor(0); legend -> SetHeader(Form(" %4.3f #pm %4.3f", f1 -> GetParameter(0), f1->GetParError(0))); TCanvas *c11 = new TCanvas("c11",AuxString,200,10,500,500); c11 -> cd(); Ratio -> SetMinimum(0.5); Ratio -> SetMaximum(2.0); Ratio -> Draw("AP"); legend -> Draw("same"); TLatex* info = new TLatex(); info-> SetNDC(); info->SetTextSize(0.045); info->DrawLatex(0.22,0.84,Form("#splitline{#chi^{2} = %4.2f}{dof = %i}",f1 -> GetChisquare(),f1 -> GetNDF())); filename = (TString) "plots/Ratio_Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + type + (TString) "_data_comparison_" + method + (TString) ".pdf"; c11 -> SaveAs(filename); delete c11; ratioEtaBinnedX[eta] = (eta_bins[eta+1] + eta_bins[eta])/2.; ratioEtaBinnedY[eta] = f1 -> GetParameter(0); ratioEtaBinnedEX[0]=0.25; ratioEtaBinnedEX[1]=0.3; ratioEtaBinnedEX[2]=0.3; ratioEtaBinnedEX[3]=0.3; ratioEtaBinnedEY[eta] = f1->GetParError(0); if(QCD){ ratioEtaBinnedQCDUpY[eta] = fitQCDUp -> GetParameter(0); ratioEtaBinnedQCDDownY[eta]= fitQCDDown -> GetParameter(0); // Some additional stuff for QCD uncertainty TCanvas *plotsQCD = new TCanvas("plotsQCD","plotsQCD",200,10,500,500); plotsQCD -> cd(); Ratio -> SetMarkerColor(1); Ratio -> SetLineColor(1); Ratio -> SetMarkerStyle(20); Ratio -> GetFunction("name")->SetLineColor(1); QCDUp -> SetMarkerColor(3); QCDDown -> SetMarkerColor(3); QCDUp -> SetLineColor(3); QCDDown -> SetLineColor(3); QCDUp -> SetMarkerStyle(20); QCDDown -> SetMarkerStyle(20); QCDUp -> SetMarkerSize(0.8); QCDDown -> SetMarkerSize(0.8); QCDUp -> GetFunction("fitQCDUp")->SetLineColor(3); QCDDown -> GetFunction("fitQCDDown")->SetLineColor(3); Ratio -> Draw("AP"); QCDUp -> Draw("sameP"); QCDDown -> Draw("sameP"); delete legend; legend = new TLegend(0.4,0.8,0.9,0.9); legend -> SetFillColor(0); legend -> SetTextSize(0.045); legend -> AddEntry(Ratio,"Central Value","l"); legend -> AddEntry(QCDUp,Form("Upward variation: + %4.3f",abs(ratioEtaBinnedQCDUpY[eta]/ratioEtaBinnedY[eta]-1.)),"l"); legend -> AddEntry(QCDDown,Form("Downward variation: - %4.3f",abs(ratioEtaBinnedQCDDownY[eta]/ratioEtaBinnedY[eta]-1.)),"l"); legend -> Draw("same"); filename = (TString) "plots/plotsQCD_for_" + (long) (eta+1) + (TString) "_bin_" + type + (TString) "_" + method + (TString) ".pdf"; plotsQCD -> SaveAs(filename); delete plotsQCD; } } TGraphErrors* ratioEtaBinned = new TGraphErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ratioEtaBinnedEX,ratioEtaBinnedEY); filename = (TString) "plots/RatioEtaBinned_" + type + (TString) "_" + method + (TString) ".root"; TFile *f = new TFile(filename,"RECREATE"); f -> WriteTObject(ratioEtaBinned,"Graph"); f->Close(); delete f; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 1.) Calculate sys Error from QCD contamination //cout<<endl; double deltaRatioUpQCD[nEta] = {0.}; double deltaRatioDownQCD[nEta] = {0.}; if(QCD){ for(int eta = 0; eta<nEta; eta++){ deltaRatioUpQCD[eta] = abs(ratioEtaBinnedQCDUpY[eta]/ratioEtaBinnedY[eta]-1.); deltaRatioDownQCD[eta] = abs(ratioEtaBinnedQCDDownY[eta]/ratioEtaBinnedY[eta]-1.); //cout<<"ratioEtaBinnedQCDDownY[eta]"<<ratioEtaBinnedQCDDownY[eta]<<endl; //cout<<"ratioEtaBinnedY[eta]"<<ratioEtaBinnedY[eta]<<endl; //cout<<"deltaRatioUpQCD["<<eta<<"] = "<<deltaRatioUpQCD[eta]<<endl; //cout<<"deltaRatioDownQCD["<<eta<<"] = "<<deltaRatioDownQCD[eta]<<endl; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 2.) Calculate sys Error from JEC uncertainty (percentage change of MC result) //cout<<endl; double deltaRatioUpJEC[nEta] = {0.}; double deltaRatioDownJEC[nEta] = {0.}; if(JEC){ rootFiles = (TString) "scripts/plotsJEC/FinalEtaBinnedErrorsJECUp_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *JECuncertaintyUp = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelJECUp = JECuncertaintyUp -> GetY(); rootFiles = (TString) "scripts/plotsJEC/FinalEtaBinnedErrorsJECLow_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *JECuncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelJECLow = JECuncertaintyLow -> GetY(); for(int eta = 0; eta<nEta; eta++){ deltaRatioUpJEC[eta] = sysRelJECUp[eta]; deltaRatioDownJEC[eta] = sysRelJECLow[eta]; //cout<<"deltaRatioUpJEC["<<eta<<"] = "<<deltaRatioUpJEC[eta]<<endl; //cout<<"deltaRatioDownJEC["<<eta<<"] = "<<deltaRatioDownJEC[eta]<<endl; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 3.) Calculate sys Error from Flavor uncertainty (percentage change of MC result) //cout<<endl; // Multiply on mc (as symmetric Error) // ratioUp = 1/(1 - delta) * ratio // ratioLow = 1/(1 + delta) * ratio double deltaRatioUpFlavor[nEta] = {0.}; double deltaRatioDownFlavor[nEta] = {0.}; if(flavor){ rootFiles = (TString) "scripts/plotsFlavor/FinalEtaBinnedErrorsFlavorUp_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *FlavoruncertaintyUp = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelFlavorUp = FlavoruncertaintyUp -> GetY(); rootFiles = (TString) "scripts/plotsFlavor/FinalEtaBinnedErrorsFlavorLow_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *FlavoruncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelFlavorLow = FlavoruncertaintyLow -> GetY(); for(int eta = 0; eta<nEta; eta++){ deltaRatioUpFlavor[eta] = sysRelFlavorUp[eta]; deltaRatioDownFlavor[eta] = sysRelFlavorLow[eta]; //cout<<"deltaRatioUpFlavor["<<eta<<"] = "<<deltaRatioUpFlavor[eta]<<endl; //cout<<"deltaRatioDownFlavor["<<eta<<"] = "<<deltaRatioDownFlavor[eta]<<endl; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 4.) Calculate sys Error from PU uncertainty (percentage change of MC result) //cout<<endl; double deltaRatioUpPU[nEta] = {0.}; double deltaRatioDownPU[nEta] = {0.}; if(PU){ rootFiles = (TString) "scripts/plotsPU/FinalEtaBinnedErrorsPUUp_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *PUuncertaintyUp = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelPUUp = PUuncertaintyUp -> GetY(); rootFiles = (TString) "scripts/plotsPU/FinalEtaBinnedErrorsPULow_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *PUuncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelPULow = PUuncertaintyLow -> GetY(); // Multiply on mc (as symmetric Error) // ratioUp = 1/(1 - delta) * ratio // ratioUp = 1/(1 + delta) * ratio for(int eta = 0; eta<nEta; eta++){ deltaRatioUpPU[eta] = sysRelPUUp[eta]; deltaRatioDownPU[eta] = sysRelPULow[eta]; //cout<<"deltaRatioUpPU["<<eta<<"] = "<<deltaRatioUpPU[eta]<<endl; //cout<<"deltaRatioDownPU["<<eta<<"] = "<<deltaRatioDownPU[eta]<<endl; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // 5.) Calculate sys Error from Out-of Cone showering simulation (percentage change of full ratio result) //cout<<endl; double deltaRatioUpMC[nEta] = {0.}; double deltaRatioDownMC[nEta] = {0.}; if(MC){ rootFiles = (TString) "scripts/plotsMC/FinalErrorsMC_" + type + (TString) "_" + method + (TString) ".root"; TGraphErrors *MCuncertainty = readTGraphErrors(rootFiles,"graph","Graph"); double *sysRelMC = MCuncertainty -> GetY(); // Percentage change is only in one direction, to take this into account keep deltaRatioDownMC = 0 for(int eta = 0; eta<nEta; eta++){ deltaRatioUpMC[eta] = sysRelMC[eta]; deltaRatioDownMC[eta] = sysRelMC[eta]; //cout<<"deltaRatioUpMC["<<eta<<"] = "<<deltaRatioUpMC[eta]<<endl; //cout<<"deltaRatioDownMC["<<eta<<"] = "<<deltaRatioDownMC[eta]<<endl; } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Take all systematic Uncertainties together and plot //cout<<endl; double *deltaTotalSysUp = new double[nEta]; double *deltaTotalSysDown = new double[nEta]; double *DeltaTotalSysUp = new double[nEta]; double *DeltaTotalSysDown = new double[nEta]; double *DeltaTotalDown = new double[nEta]; double *DeltaTotalUp = new double[nEta]; for(int eta = 0; eta<nEta; eta++){ // Add all systematic Uncertainties in quadrature (delta is relative Uncertainty) deltaTotalSysUp[eta] = sqrt(TMath::Power(deltaRatioUpJEC[eta],2) + TMath::Power(deltaRatioUpFlavor[eta],2) + TMath::Power(deltaRatioUpPU[eta],2) + TMath::Power(deltaRatioUpMC[eta],2) + TMath::Power(deltaRatioUpQCD[eta],2)); deltaTotalSysDown[eta] = sqrt(TMath::Power(deltaRatioDownJEC[eta],2) + TMath::Power(deltaRatioDownFlavor[eta],2) + TMath::Power(deltaRatioDownPU[eta],2) + TMath::Power(deltaRatioDownMC[eta],2) + TMath::Power(deltaRatioDownQCD[eta],2)); // Calculation of the absolute Uncertainty with Delta = ratio * delta DeltaTotalSysUp[eta] = deltaTotalSysUp[eta] * ratioEtaBinnedY[eta]; DeltaTotalSysDown[eta] = deltaTotalSysDown[eta] * ratioEtaBinnedY[eta]; // Calculate Systematic plus staistical Uncertainty DeltaTotalUp[eta] = sqrt(pow(DeltaTotalSysUp[eta],2) + pow(ratioEtaBinnedEY[eta],2)); DeltaTotalDown[eta] = sqrt(pow(DeltaTotalSysDown[eta],2) + pow(ratioEtaBinnedEY[eta],2)); cout<<endl<<"relative: deltaTotalSysUp["<<eta<<"] = "<<fixed<<setprecision(3)<<deltaTotalSysUp[eta]<<endl; cout<<"relative: deltaTotalSysDown["<<eta<<"] = "<<deltaTotalSysDown[eta]<<endl; cout<<endl<<"absolute: DeltaTotalSysUp["<<eta<<"] = "<<DeltaTotalSysUp[eta]<<endl; cout<<"absolute: DeltaTotalSysDown["<<eta<<"] = "<<DeltaTotalSysDown[eta]<<endl; } double ex[nEta] ={0.25,0.3,0.3,0.3}; TGraphAsymmErrors* ratioEtaBinnedSys = new TGraphAsymmErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ex,ex,DeltaTotalSysDown,DeltaTotalSysUp); double *TotalSysUp = new double[nEta]; double *TotalSysDown = new double[nEta]; for(int i=0; i<nEta; i++){ TotalSysUp[i] = ratioEtaBinnedY[i]+DeltaTotalSysUp[i]; TotalSysDown[i] = ratioEtaBinnedY[i]-DeltaTotalSysDown[i]; } TGraph* ratioSysBorderUp = new TGraph(nEta, ratioEtaBinnedX, TotalSysUp); TGraph* ratioSysBorderDown = new TGraph(nEta, ratioEtaBinnedX, TotalSysDown); TGraph* ratioRelativeErrorsUp = new TGraph(nEta,ratioEtaBinnedX,deltaTotalSysUp); TGraph* ratioRelativeErrorsDown = new TGraph(nEta,ratioEtaBinnedX,deltaTotalSysDown); TGraphErrors* ratioEtaBinnedStat = new TGraphErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ratioEtaBinnedEX,ratioEtaBinnedEY); TGraphAsymmErrors* ratioEtaBinnedStatPlusSys = new TGraphAsymmErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ex,ex,DeltaTotalDown,DeltaTotalUp); TCanvas *cFinal = new TCanvas("cFinal","cFinal",200,10,500,500); cFinal -> cd(); ratioEtaBinnedSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); ratioEtaBinnedSys -> GetXaxis() -> SetTitle("|#eta|"); if(PU && flavor && JEC && MC && QCD) etaString = "All sys. Uncertainties"; else if(PU && !flavor && !JEC && !MC && !QCD) etaString = "Only PU uncert."; else if(!PU && flavor && !JEC && !MC && !QCD) etaString = "Only flavor uncert."; else if(!PU && !flavor && JEC && !MC && !QCD) etaString = "Only JEC uncert."; else if(!PU && !flavor && !JEC && MC && !QCD) etaString = "Only Out-of-Cone sim. uncert."; else if(!PU && !flavor && !JEC && MC && !QCD) etaString = "Only Out-of-Cone sim. uncert."; else if(!PU && !flavor && !JEC && !MC && QCD) etaString = "Only QCD uncert."; else if(PU && flavor && JEC && !MC && QCD) etaString = "All besides MC uncertainty."; else etaString = "Strange set of systematic uncertainties."; cout<<endl<<etaString<<endl<<endl; ratioEtaBinnedSys -> SetMarkerStyle(20); ratioEtaBinnedSys -> SetMarkerSize(1.4); ratioEtaBinnedSys -> SetFillColor(kGray); ratioEtaBinnedSys -> SetFillStyle(3001); ratioEtaBinnedSys -> SetLineColor(kGray); ratioEtaBinnedSys -> SetMinimum(0.8); ratioEtaBinnedSys -> SetMaximum(1.5); ratioEtaBinnedSys -> GetXaxis() -> SetLimits(0., 2.3); ratioEtaBinnedSys -> GetXaxis() -> SetNdivisions(6,6,0, "X"); ratioEtaBinnedSys -> DrawClone("Ae3p"); //ratioEtaBinnedSys -> SetPointError(0, 0., 0., 0., 0.); //ratioEtaBinnedSys -> SetPointError(1, 0., 0., 0., 0.); //ratioEtaBinnedSys -> SetPointError(2, 0., 0., 0., 0.); //ratioEtaBinnedSys -> SetPointError(3, 0., 0., 0., 0.); //ratioEtaBinnedSys -> SetPointError(4, 0., 0., 0., 0.); ratioEtaBinnedStat -> SetMarkerStyle(20); ratioEtaBinnedStat -> SetMarkerSize(1.4); ratioEtaBinnedStat -> SetFillColor(kGray); ratioEtaBinnedStat -> SetFillStyle(3001); ratioEtaBinnedStat -> SetLineColor(1); ratioEtaBinnedStat -> Draw("psame"); TLatex *infoFinal = new TLatex(); infoFinal -> SetTextFont(132); infoFinal -> SetNDC(); infoFinal -> SetTextSize(0.045); infoFinal -> DrawLatex(0.2,0.8,etaString); filename = (TString) "plots/FinalErrorPlot_" + type + (TString) "_" + method + (TString) ".pdf"; cFinal -> Print(filename,"pdf"); filename = (TString) "plots/FinalErrorPlot_" + type + (TString) "_" + method + (TString) ".pdf"; cFinal -> SaveAs(filename,"pdf"); delete cFinal; filename = (TString) "plots/FinalRelativeErrorsUp_" + type + (TString) "_" + method + (TString) ".root"; f = new TFile(filename,"RECREATE"); f -> WriteTObject(ratioRelativeErrorsUp,"graph"); f->Close(); delete f; filename = (TString) "plots/FinalRelativeErrorsLow_" + type + (TString) "_" + method + (TString) ".root"; f = new TFile(filename,"RECREATE"); f -> WriteTObject(ratioRelativeErrorsDown,"graph"); f->Close(); delete f; ofstream RelativeErrors; RelativeErrors.open("plots/Errors.txt"); RelativeErrors<<"Relative Errors: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<fixed<<setprecision(3)<<(deltaTotalSysDown[i]*100)<<"% / +"<<(deltaTotalSysUp[i]*100)<<"%"<<endl; } RelativeErrors<<endl<<"Absolute Errors: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(DeltaTotalSysDown[i])<<" / +"<<(DeltaTotalSysUp[i])<<endl; } RelativeErrors<<endl<<endl<<"Relative Errors JEC: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(deltaRatioDownJEC[i]*100)<<"% / +"<<(deltaRatioUpJEC[i]*100)<<"%"<<endl; } RelativeErrors<<endl<<endl<<"Relative Errors Flavor: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(deltaRatioDownFlavor[i]*100)<<"% / +"<<(deltaRatioUpFlavor[i]*100)<<"%"<<endl; } RelativeErrors<<endl<<endl<<"Relative Errors Out-of-Cone showering simulation: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(deltaRatioDownMC[i]*100)<<"% / +"<<(deltaRatioUpMC[i]*100)<<"%"<<endl; } RelativeErrors<<endl<<endl<<"Relative Errors QCD: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(deltaRatioDownQCD[i]*100)<<"% / +"<<(deltaRatioUpQCD[i]*100)<<"%"<<endl; } RelativeErrors<<endl<<endl<<"Relative Errors PU reweighing: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(deltaRatioDownPU[i]*100)<<"% / +"<<(deltaRatioUpPU[i]*100)<<"%"<<endl; } RelativeErrors<<endl<<endl<<"Central values and statistical Uncertainty: "<<endl; for(int i=0; i<nEta; i++){ RelativeErrors<<i+1<<". Eta bin: "<<"-"<<(ratioEtaBinnedY[i])<<" +/- "<<ratioEtaBinnedEY[i]<<endl; } RelativeErrors.close(); // Write directly full latex table with systematic and statistical unceratinty ofstream latexTable; latexTable.open("plots/latexTable.txt"); latexTable<<"\\renewcommand{\\arraystretch}{2.0}"<<endl; latexTable<<"\\begin{center}"<<endl; latexTable<<"\\begin{tabular}{ | c | c c c| }"<<endl; latexTable<<"$|\\eta^{\\text{Jet}}|$ & Ratio & stat. & sys. \\\\\\hline"<<endl; for(int z=0;z<nEta;z++){ latexTable<<"$"<<fixed<<setprecision(1)<<etaBins[z]<<" - "<<etaBins[z+1]<<"$ &"<<fixed<<setprecision(3)<<ratioEtaBinnedY[z]<<" & $\\pm "<<ratioEtaBinnedEY[z]<<"$ & $^{+"<<DeltaTotalSysUp[z]<<"}_{-"<<DeltaTotalSysDown[z]<<"}$ \\\\"<<endl; } latexTable<<"\\hline"<<endl; latexTable<<"\\end{tabular}"<<endl; latexTable<<"\\end{center}"<<endl<<endl<<endl<<endl<<endl; latexTable<<"\\begin{center}"<<endl; latexTable<<"\\begin{tabular}{ l| c | c | c | c |}"<<endl; latexTable<<"\\multicolumn{1}{c}{} & \\multicolumn{4}{c}{$|\\eta^{\\text{Jet}}|$}\\\\\\hline"<<endl<<fixed<<setprecision(1); for(int z=0;z<nEta;z++) latexTable<<"& \\textbf{"<<etaBins[z]<<" - "<<etaBins[z+1]<<"}"; latexTable<<"\\\\\\hline"<<endl; latexTable<<"\\multirow{2}{*}{\\textbf{Multijet contamination}}"; for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpQCD[z]*100<<" \\% $ "; latexTable<<"\\\\"<<endl; for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaRatioDownQCD[z]*100<<" \\% $ "; latexTable<<"\\\\\\hline"<<endl; latexTable<<"\\multirow{2}{*}{\\textbf{Flavor uncertainty}}"; for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpFlavor[z]*100<<" \\% $ "; latexTable<<"\\\\"<<endl; for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownFlavor[z]*100<<" \\% $ "; latexTable<<"\\\\\\hline"<<endl; latexTable<<"\\multirow{2}{*}{\\textbf{JEC uncertainty}}"; for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpJEC[z]*100<<" \\% $ "; latexTable<<"\\\\"<<endl; for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownJEC[z]*100<<" \\% $ "; latexTable<<"\\\\\\hline"<<endl; latexTable<<"\\multirow{2}{*}{\\textbf{Out-of-Cone showering simulation}}"; for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpMC[z]*100<<" \\% $ "; latexTable<<"\\\\"<<endl; for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaRatioDownMC[z]*100<<" \\% $ "; latexTable<<"\\\\\\hline"<<endl; latexTable<<"\\multirow{2}{*}{\\textbf{PU uncertainty}}"; for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpPU[z]*100<<" \\% $ "; latexTable<<"\\\\"<<endl; for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownPU[z]*100<<" \\% $ "; latexTable<<"\\\\\\hline\\hline"<<endl; latexTable<<"\\multirow{2}{*}{\\textbf{Total}}"; for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaTotalSysUp[z]*100<<" \\% $ "; latexTable<<"\\\\"<<endl; for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaTotalSysDown[z]*100<<" \\% $ "; latexTable<<"\\\\\\hline"<<endl; latexTable<<"\\end{tabular}"<<endl; latexTable<<"\\end{center}"<<endl; latexTable.close(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Comparison to 2011 Data cout<<endl; gROOT->LoadMacro("tdrstyle_mod14.C"); setTDRStyle(); gROOT->LoadMacro("CMS_lumi.C"); writeExtraText = true; // if extra text extraText = "Preliminary"; // default extra text is "Preliminary" lumi_8TeV = "19.7 fb^{-1}"; // default is "19.7 fb^{-1}" lumi_7TeV = "4.9 fb^{-1}"; // default is "5.1 fb^{-1}" int iPeriod = 2; // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV gStyle->SetHatchesLineWidth(1); gStyle->SetHatchesSpacing(2.2); //----------------------------------------------------- TCanvas *cFinal2 = new TCanvas("cFinal2","cFinal2",200,10,1000,1000); cFinal2 -> cd(); double x_2011[4]; x_2011[0]=0.25; x_2011[1]=0.80; x_2011[2]=1.40; x_2011[3]=2.00; double y_2011[4]; y_2011[0]=1.052; y_2011[1]=1.057; y_2011[2]=1.096; y_2011[3]=1.134; double yErrStat_2011[4]; yErrStat_2011[0]=0.012; yErrStat_2011[1]=0.012; yErrStat_2011[2]=0.017; yErrStat_2011[3]=0.035; double yErrSysHigh_2011[4]; yErrSysHigh_2011[0]=0.062; yErrSysHigh_2011[1]=0.056; yErrSysHigh_2011[2]=0.063; yErrSysHigh_2011[3]=0.087; double yErrSysLow_2011[4]; yErrSysLow_2011[0]=0.061; yErrSysLow_2011[1]=0.055; yErrSysLow_2011[2]=0.062; yErrSysLow_2011[3]=0.085; double xErrLow_2011[4]; xErrLow_2011[0]=0.25; xErrLow_2011[1]=0.3; xErrLow_2011[2]=0.3; xErrLow_2011[3]=0.3; double xErrHigh_2011[4]; xErrHigh_2011[0]=0.25; xErrHigh_2011[1]=0.3; xErrHigh_2011[2]=0.3; xErrHigh_2011[3]=0.3; double yErrTotalHigh_2011[4]; double yErrTotalLow_2011[4]; for(int i=0; i<4; i++){ yErrTotalHigh_2011[i]=sqrt(pow(yErrStat_2011[i],2) + pow(yErrSysHigh_2011[i],2)); yErrTotalLow_2011[i]=sqrt(pow(yErrStat_2011[i],2) + pow(yErrSysLow_2011[i],2)); } TGraphAsymmErrors *Res_2011_stat = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrStat_2011,yErrStat_2011); Res_2011_stat->SetName("Res_2011_stat"); TGraphAsymmErrors *Res_2011_sys = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrSysLow_2011,yErrSysHigh_2011); Res_2011_sys->SetName("Res_2011_sys"); TGraphAsymmErrors *Res_2011_total = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrTotalLow_2011,yErrTotalHigh_2011); Res_2011_sys->SetName("Res_2011_total"); //----------------------------------------------------- ratioEtaBinnedStatPlusSys -> GetXaxis() -> SetTitle("|#eta|"); ratioEtaBinnedStatPlusSys -> GetXaxis() -> SetRangeUser(0., 2.3); ratioEtaBinnedStatPlusSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); ratioEtaBinnedSys -> GetXaxis() -> SetTitle("|#eta|"); ratioEtaBinnedSys -> GetXaxis() -> SetRangeUser(0., 2.3); ratioEtaBinnedSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); ratioEtaBinnedStat -> GetXaxis() -> SetTitle("|#eta|"); ratioEtaBinnedStat -> GetXaxis() -> SetRangeUser(0., 2.3); ratioEtaBinnedStat -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); ratioEtaBinnedStat -> GetYaxis() -> SetRangeUser(0.8, 1.6); Res_2011_stat -> GetXaxis() -> SetTitle("|#eta|"); Res_2011_stat -> GetXaxis() -> SetLimits(0., 2.3); Res_2011_stat -> GetXaxis() -> SetNdivisions(505, "X"); Res_2011_stat -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); Res_2011_sys -> GetXaxis() -> SetTitle("|#eta|"); Res_2011_sys -> GetXaxis() -> SetLimits(0., 2.3); Res_2011_sys -> GetXaxis() -> SetNdivisions(505, "X"); Res_2011_sys -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); Res_2011_total -> GetXaxis() -> SetTitle("|#eta|"); Res_2011_total -> GetXaxis() -> SetLimits(0., 2.3); Res_2011_total -> GetXaxis() -> SetNdivisions(505, "X"); Res_2011_total -> GetYaxis() -> SetTitle("Data/MC ratio for JER"); Res_2011_total -> GetYaxis() -> SetRangeUser(0.8, 1.5); ratioEtaBinnedStatPlusSys -> SetMarkerStyle(20); ratioEtaBinnedStatPlusSys -> SetMarkerSize(2.0); ratioEtaBinnedStatPlusSys -> SetLineColor(kPink-8); ratioEtaBinnedStatPlusSys -> SetLineWidth(2); ratioEtaBinnedStatPlusSys -> SetMarkerColor(kPink-8); ratioEtaBinnedStatPlusSys -> SetFillColor(kPink-8); ratioEtaBinnedStatPlusSys -> SetName("statPlusSys_2012"); ratioEtaBinnedStat -> SetMarkerStyle(20); ratioEtaBinnedStat -> SetMarkerSize(2.0); ratioEtaBinnedStat -> SetLineColor(kPink-8); ratioEtaBinnedStat -> SetLineWidth(2); ratioEtaBinnedStat -> SetMarkerColor(kPink-8); ratioEtaBinnedStat -> SetFillColor(kPink-8); ratioEtaBinnedStat -> SetName("Stat_2012"); ratioEtaBinnedStatPlusSys -> SetFillStyle(3244); ratioEtaBinnedStat -> SetFillStyle(3144); Res_2011_stat->SetMarkerStyle(24); Res_2011_stat->SetMarkerSize(2.0); Res_2011_stat->SetLineColor(kGray+2); Res_2011_stat->SetLineWidth(2); Res_2011_stat->SetLineWidth(2); Res_2011_stat->SetFillStyle(1001); Res_2011_total->SetMarkerStyle(24); Res_2011_total->SetMarkerSize(2.0); Res_2011_total->SetLineColor(1); Res_2011_total->SetLineWidth(2); Res_2011_total->SetFillColor(kGray); Res_2011_total->SetFillStyle(1001); Res_2011_total->SetLineColor(kGray+2); Res_2011_total->Draw("a2"); Res_2011_stat->Draw("esame"); ratioEtaBinnedStatPlusSys -> Draw("2same"); Res_2011_stat->Draw("pXsame"); Res_2011_stat->SetMarkerSize(1.9); Res_2011_stat->Draw("pXsame"); Res_2011_stat->SetMarkerSize(1.7); Res_2011_stat->Draw("pXsame"); ratioEtaBinnedStatPlusSys -> Draw("pXsame"); ratioEtaBinnedStat -> Draw("esame"); TLegend *leg = new TLegend(0.18, 0.60, 0.55, 0.75); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextFont(42); leg->SetTextSize(0.045); leg->AddEntry(Res_2011_total,"5/fb (7 TeV)", "pfl"); leg->AddEntry(ratioEtaBinnedStatPlusSys,"20/fb (8 TeV)", "pfl"); leg->Draw("same"); TLatex *info = new TLatex(); info->SetNDC(); info->DrawLatex(0.67,0.83,"Anti-k_{T} R=0.5"); info->DrawLatex(0.67,0.77,"PF+CHS"); CMS_lumi( cFinal2, iPeriod, 11 ); cFinal2->Print("plots/resultsComparisonFINAL.pdf","pdf"); cFinal2->SaveAs("plots/resultsComparisonFINAL.C"); return 0; }
void AnalyzeWaveforms(char *WaveformsFile = "Waveforms.root", const int nAddedChannels = 5) { //try to access waveforms file and in case of failure return if(gSystem->AccessPathName(WaveformsFile,kFileExists)) { cout << "Error: file " << WaveformsFile << " does not exsist. Run .x WaveformsFileMaker.C to create it" << endl; return; } // gStyle->SetOptFit(111); // gStyle->SetStatFormat("1.3E"); // gStyle->SetFitFormat("1.3E"); // fetch the list of trees contained in the waveforms file // for every tree generate a waveform graph TFile *f = TFile::Open(WaveformsFile); TList *listOfKeys = f->GetListOfKeys(); Int_t numberOfKeys = listOfKeys->GetEntries(); TList *listOfGraphs = new TList(); // if the waveform file name begins with the string "comparator" it goes in this list TList *listOfCompWaves = new TList(); // if the waveform file name begins with the string "sum output" it goes in this list TList *listOfAdderWaves = new TList(); for(Int_t i = 0; i < numberOfKeys; i++) { TString *keyName = new TString(listOfKeys->At(i)->GetName()); TTree *tree = (TTree*)f->Get(keyName->Data()); Float_t x = 0; Float_t y = 0; tree->SetBranchAddress("x",&x); tree->SetBranchAddress("y",&y); Int_t nentries = tree->GetEntries(); TString *gName = new TString(keyName->Data()); gName->Append(" graph"); TGraphErrors *gWave = new TGraphErrors(nentries); gWave->SetName(gName->Data()); gWave->SetTitle(gName->Data()); gWave->GetXaxis()->SetTitle("Time"); gWave->GetYaxis()->SetTitle("Voltage"); // gWave->SetBit(TH1::kCanRebin); for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); gWave->SetPoint(j,x,y); } listOfGraphs->Add(gWave); if(keyName->BeginsWith("comparator")) listOfCompWaves->Add(gWave); if(keyName->BeginsWith("sum output")) listOfAdderWaves->Add(gWave); /* TString *cName = new TString(keyName->Data()); cName->Append(" canvas"); TCanvas *cy = new TCanvas(cName->Data(),cName->Data(),800,600); gWave->Draw("AL"); */ } cout << listOfAdderWaves->GetEntries() << endl; // analysis for waves with no delay // global variables Double_t xMin,xMax,yStart,yEnd; Int_t graphPoints; Double_t step; // comparator outputs waves sum TGraphErrors *gFirstCompWave = (TGraphErrors *)listOfCompWaves->First(); graphPoints = gFirstCompWave->GetN(); gFirstCompWave->GetPoint(0,xMin,yStart); gFirstCompWave->GetPoint(graphPoints - 1,xMax,yEnd); step = (xMax - xMin)/graphPoints; cout << gFirstCompWave->GetName() << endl; cout << "xMin = " << xMin << " xMax = " << xMax << " graphPoints = " << graphPoints << endl; TGraphErrors *gCompSum = new TGraphErrors(graphPoints); gCompSum->SetLineColor(kBlue); gCompSum->SetLineWidth(2); gCompSum->SetName("Comparator Outputs Sum"); gCompSum->SetTitle("Comparator Outputs Sum"); Int_t nCompWaves = listOfCompWaves->GetEntries(); Float_t gx,gy = 0; // Alpha coefficiens are now written "hard coded" here Float_t alphaArray[3] = {0.199,0.201,0.197}; // Deleays coming from the multiplexer are written "hard coded" here Float_t muxDelayArray[3] = {0,77.14E-12,192.01E-12}; for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nCompWaves; j++) { TGraphErrors *gCompWave = (TGraphErrors *)listOfCompWaves->At(j); gy += (gCompWave->Eval(xMin + i*step + muxDelayArray[j]))*alphaArray[j]; } gCompSum->SetPoint(i,xMin + i*step,gy); gy = 0; } // note that there is a manual correction on the x axis for the comparator waves sum to compare them better in the multigraph Double_t *xArray = gCompSum->GetX(); for(Int_t i = 0; i < graphPoints; i++) { xArray[i] += 5.6E-9; } // TCanvas *cCompSum = new TCanvas("cCompSum","Comparator Outputs Sum",800,600); // gCompSum->Draw("AL"); // adder outputs waves sum // THE ANALYSIS FOR THE ADDER OUTPUT WITH NOT DELAY AND 3 CHANNELS ADDED IS DEPRECATED. // THERE WAS A MISTAKE IN THE DATA TAKING // I'LL KEEP THE CODE HERE FOR FURTHER REFERENCE /* TGraphErrors *gFirstAdderWave = (TGraphErrors *)listOfAdderWaves->First(); graphPoints = gFirstAdderWave->GetN(); gFirstAdderWave->GetPoint(0,xMin,yStart); gFirstAdderWave->GetPoint(graphPoints - 1,xMax,yEnd); step = (xMax - xMin)/graphPoints; cout << gFirstAdderWave->GetName() << endl; cout << "xMin : " << xMin << " xMax : " << xMax << endl; TGraphErrors *gAdderSum = new TGraphErrors(graphPoints); gAdderSum->SetLineWidth(2); // gAdderSum->SetLineColor(kGreen); gAdderSum->SetLineStyle(9); gAdderSum->SetName("Sum of the adder outputs with no delay"); gAdderSum->SetTitle("Sum of the adder outputs with no delay"); Int_t nAdderWaves = listOfAdderWaves->GetEntries(); gy = 0; for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nAdderWaves; j++) { TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j); gy += gAdderWave->Eval(xMin + i*step); } gAdderSum->SetPoint(i,xMin + i*step,gy); gy = 0; } // TCanvas *cAdderSum = new TCanvas("cAdderSum","Sum of the adder outputs",800,600); // gAdderSum->Draw("AL"); TGraphErrors *g3ChannelsSumNoDelay = listOfGraphs->FindObject("sum_output_3_channels_(3) graph"); g3ChannelsSumNoDelay->SetLineColor(kRed); g3ChannelsSumNoDelay->SetLineWidth(2); // note that there is a manual correction on the x axis for the adder output to compare it better in the multigraph Double_t *xArray = g3ChannelsSumNoDelay->GetX(); graphPoints = g3ChannelsSumNoDelay->GetN(); for(Int_t i = 0; i < graphPoints; i++) { xArray[i] -= 600E-12; } // comparison among the computed adder output ,the real one and the sum of the comparator outputs with alpha coefficients correction TMultiGraph *mgSumNoDelay = new TMultiGraph(); mgSumNoDelay->Add(g3ChannelsSumNoDelay); mgSumNoDelay->Add(gAdderSum); mgSumNoDelay->Add(gCompSum); mgSumNoDelay->SetTitle("Collection of graphs for 3 channels sum with no delay"); TCanvas *cmgSumNoDelay = new TCanvas("cmgSumNoDelay", "Collection of graphs for 3 channels sum with no delay", 1200,800); cmgSumNoDelay->Update(); mgSumNoDelay->Draw("AL"); legend = new TLegend(0.6,0.78,0.99,0.99); legend->AddEntry(g3ChannelsSumNoDelay, "Actual sum done by the adder", "lp"); legend->AddEntry(gAdderSum, "Sum of the adder outputs", "lp"); legend->AddEntry(gCompSum, "Sum of the comparator outputs","lp"); legend->Draw(); mgSumNoDelay->GetXaxis()->SetTitle("Seconds"); mgSumNoDelay->GetYaxis()->SetTitle("Volts"); TPaveText *title = (TPaveText*)cmgSumNoDelay->GetPrimitive("title"); title->SetX1NDC(0.009); title->SetY1NDC(0.94); title->SetX2NDC(0.56); title->SetY2NDC(0.99); cmgSumNoDelay->Modified(); */ // analysis for delayed adder outputs Int_t nAdderWaves = listOfAdderWaves->GetEntries(); TGraphErrors *g3ChannelsSumDelay = listOfGraphs->FindObject("sum_output_3_channels_(1-1-1) graph"); g3ChannelsSumDelay->SetLineColor(kRed); g3ChannelsSumDelay->SetLineWidth(2); // Delay coming from cables are written "hard coded" here Float_t cablesDelayArray[3] = {0,1.45E-9,3.21E-9}; graphPoints = g3ChannelsSumDelay->GetN(); //g3ChannelsSumDelay->GetPoint(0,xMin,yStart); //g3ChannelsSumDelay->GetPoint(graphPoints - 1,xMax,yEnd); xMin = 6E-9; xMax = 16E-9; step = (xMax - xMin)/graphPoints; cout << "Sum of the adder outputs with delay" << endl; cout << "xMin : " << xMin << " xMax : " << xMax << endl; TGraphErrors *gAdderSumDelay = new TGraphErrors(graphPoints); gAdderSumDelay->SetLineColor(kBlue); gAdderSumDelay->SetLineWidth(2); gAdderSumDelay->SetName("Sum of the adder outputs with delay"); gAdderSumDelay->SetTitle("Sum of the adder outputs with delay"); gy = 0; // note that there is a manual correction on the delay of 500E-12 to compare the adder output better in the multigraph for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nAdderWaves; j++) { TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j); gy += gAdderWave->Eval(xMin + i*step + cablesDelayArray[j] - 500E-12); } gAdderSumDelay->SetPoint(i,xMin + i*step,gy); gy = 0; } // TCanvas *cSumSumDelay = new TCanvas("cSumSumDelay","Sum of the sum outputs with delay",800,600); // gAdderSumDelay->Draw("APEL"); TMultiGraph *mg3ChannelsSumDelay = new TMultiGraph(); mg3ChannelsSumDelay->Add(gAdderSumDelay); mg3ChannelsSumDelay->Add(g3ChannelsSumDelay); mg3ChannelsSumDelay->SetTitle("Collection of graphs for 3 channels sum with delay"); TCanvas *cmg3ChannelsSumDelay = new TCanvas("cmg3ChannelsSumDelay", "Collection of graphs for 3 channels sum with delay", 1200, 800); cmg3ChannelsSumDelay->Update(); legend = new TLegend(0.6,0.78,0.99,0.99); legend->AddEntry(g3ChannelsSumDelay, "Actual sum done by the adder", "lp"); legend->AddEntry(gAdderSumDelay, "Sum of the delayed adder outputs", "lp"); mg3ChannelsSumDelay->Draw("AL"); legend->Draw(); mg3ChannelsSumDelay->GetXaxis()->SetTitle("Seconds"); mg3ChannelsSumDelay->GetYaxis()->SetTitle("Volts"); TPaveText *title = (TPaveText*)cmg3ChannelsSumDelay->GetPrimitive("title"); title->SetX1NDC(0.009); title->SetY1NDC(0.94); title->SetX2NDC(0.56); title->SetY2NDC(0.99); cmg3ChannelsSumDelay->Modified(); /* // delay test just to try a different method TMultiGraph *mgDelayTest = new TMultiGraph(); Double_t gxTest,gyTest; TGraphErrors *gDelayTest0 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(0))->GetN()); for(Int_t j = 0; j < gDelayTest0->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(0))->GetPoint(j,gxTest,gyTest); gDelayTest0->SetPoint(j,gxTest - cablesDelayArray[0],gyTest); } mgDelayTest->Add(gDelayTest0); TGraphErrors *gDelayTest1 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(1))->GetN()); for(Int_t j = 0; j < gDelayTest1->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(1))->GetPoint(j,gxTest,gyTest); gDelayTest1->SetPoint(j,gxTest - cablesDelayArray[1],gyTest); } mgDelayTest->Add(gDelayTest1); TGraphErrors *gDelayTest2 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(2))->GetN()); for(Int_t j = 0; j < gDelayTest2->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(2))->GetPoint(j,gxTest,gyTest); gDelayTest2->SetPoint(j,gxTest - cablesDelayArray[2],gyTest); } mgDelayTest->Add(gDelayTest2); // TCanvas *cmgDelayTest = new TCanvas("cmgDelayTest", "cmgDelayTest", 800,600); // mgDelayTest->Draw("APEL"); graphPoints = 12000; xMin = 2E-9; xMax = 22E-9; step = (xMax - xMin)/graphPoints; cout << "xMin : " << xMin << " xMax : " << xMax << endl; Double_t delayTest0xMin,delayTest0xMax,delayTest1xMin,delayTest1xMax,delayTest2xMin,delayTest2xMax; gDelayTest0->GetPoint(0,delayTest0xMin,gyTest); gDelayTest0->GetPoint(gDelayTest0->GetN() - 1,delayTest0xMax,gyTest); gDelayTest1->GetPoint(0,delayTest1xMin,gyTest); gDelayTest1->GetPoint(gDelayTest1->GetN() - 1,delayTest1xMax,gyTest); gDelayTest2->GetPoint(0,delayTest2xMin,gyTest); gDelayTest2->GetPoint(gDelayTest2->GetN() - 1,delayTest2xMax,gyTest); cout << delayTest0xMin << endl; TGraphErrors *gAdderSumDelayV2 = new TGraphErrors(graphPoints); for(Int_t i = 0; i < graphPoints; i++) { gyTest = gDelayTest0->Eval(xMin + i*step); gyTest += gDelayTest1->Eval(xMin + i*step); gyTest += gDelayTest2->Eval(xMin + i*step); gAdderSumDelayV2->SetPoint(i,xMin + i*step+ 500E-12,gyTest); } gAdderSumDelayV2->SetLineColor(kGreen); gAdderSumDelayV2->SetLineWidth(2); mg3ChannelsSumDelay->Add(gAdderSumDelayV2); c3ChannelsSumDelay->Modified(); TCanvas *cAdderSumDelayV2 = new TCanvas("cAdderSumDelayV2","cAdderSumDelayV2",800,600); gAdderSumDelayV2->Draw("APL"); */ // List of waves representing the adder output with 5,4,3,2,1 channels in input TGraphErrors *gAdder5Channels = listOfGraphs->FindObject("adder output 5 channels v2 graph"); TGraphErrors *gAdder4Channels = listOfGraphs->FindObject("adder output 4 channels v2 graph"); TGraphErrors *gAdder3Channels = listOfGraphs->FindObject("adder output 3 channels v2 graph"); TGraphErrors *gAdder2Channels = listOfGraphs->FindObject("adder output 2 channels v2 graph"); TGraphErrors *gAdder1Channel = listOfGraphs->FindObject("adder output 1 channel v2 graph"); TGraphErrors *gAdderSingleCh0 = listOfGraphs->FindObject("single sum output ch 0 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh1 = listOfGraphs->FindObject("single sum output ch 1 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh4 = listOfGraphs->FindObject("single sum output ch 4 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh5 = listOfGraphs->FindObject("single sum output ch 5 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh7 = listOfGraphs->FindObject("single sum output ch 7 input 500 mV DT 100 mV graph"); TMultiGraph *mgAdder54321Channels = new TMultiGraph(); mgAdder54321Channels->SetTitle("Collection of graphs for different numbers of added channels"); mgAdder54321Channels->Add(gAdder5Channels); mgAdder54321Channels->Add(gAdder4Channels); mgAdder54321Channels->Add(gAdder3Channels); mgAdder54321Channels->Add(gAdder2Channels); mgAdder54321Channels->Add(gAdder1Channel); TCanvas *cmgAdder54321Channels = new TCanvas("cmgAdder54321Channels", "Collection of graphs for different numbers of added channels",1200,800); mgAdder54321Channels->Draw("AL"); cmgAdder54321Channels->Update(); mgAdder54321Channels->GetXaxis()->SetTitle("seconds"); mgAdder54321Channels->GetYaxis()->SetTitle("Volts"); cmgAdder54321Channels->Modified(); // analysis of the linearity of the adder Double_t addedVMax[nAddedChannels]; addedVMax[0] = TMath::MaxElement(gAdder1Channel->GetN(), gAdder1Channel->GetY()); addedVMax[1] = TMath::MaxElement(gAdder2Channels->GetN(), gAdder2Channels->GetY()); addedVMax[2] = TMath::MaxElement(gAdder3Channels->GetN(), gAdder3Channels->GetY()); addedVMax[3] = TMath::MaxElement(gAdder4Channels->GetN(), gAdder4Channels->GetY()); addedVMax[4] = TMath::MaxElement(gAdder5Channels->GetN(), gAdder5Channels->GetY()); Double_t singleVMax[nAddedChannels]; singleVMax[0] = TMath::MaxElement(gAdderSingleCh0->GetN(), gAdderSingleCh0->GetY()); singleVMax[1] = TMath::MaxElement(gAdderSingleCh1->GetN(), gAdderSingleCh1->GetY()); singleVMax[2] = TMath::MaxElement(gAdderSingleCh4->GetN(), gAdderSingleCh4->GetY()); singleVMax[3] = TMath::MaxElement(gAdderSingleCh5->GetN(), gAdderSingleCh5->GetY()); singleVMax[4] = TMath::MaxElement(gAdderSingleCh7->GetN(), gAdderSingleCh7->GetY()); vector<double> expectedVMax(nAddedChannels); Double_t previousVmax = 0; for(Int_t i = 0; i < expectedVMax.size(); i++) { expectedVMax[i] = singleVMax[i] + previousVmax; previousVmax = expectedVMax[i]; cout << "singleVMax[" <<i <<"] = " << singleVMax[i] << endl; cout << "addedVMax[" <<i <<"] = " << addedVMax[i] << endl; cout << "expectedVMax[" <<i <<"] = " << expectedVMax[i] << endl; } TGraph *gAdderLinearity = new TGraph(expectedVMax.size(),&expectedVMax[0],addedVMax); gAdderLinearity->SetTitle("Linearity of the adder"); gAdderLinearity->GetXaxis()->SetTitle("Expected amplitude value (V)"); gAdderLinearity->GetYaxis()->SetTitle("Actual amplitude value (V)"); gAdderLinearity->GetYaxis()->SetTitleOffset(1.3); TCanvas *cgAdderLinearity = new TCanvas("cgAdderLinearity","Linearity of the adder",800,600); cgAdderLinearity->SetGrid(); cgAdderLinearity->Update(); gAdderLinearity->SetMarkerStyle(20); gAdderLinearity->SetMarkerSize(0.8); //gAdderLinearity->Fit("pol1","Q+","",expectedVMax[0],expectedVMax[2]); TF1 *line = new TF1("line","x",expectedVMax.back(),expectedVMax.front()); gAdderLinearity->Draw("APEL"); line->Draw("SAME"); //gAdderLinearity->GetFunction("pol1")->SetRange(expectedVMax.back(),expectedVMax.front());; cgAdderLinearity->SetLeftMargin(0.13); cgAdderLinearity->Modified(); f->Close(); }
int evaluate( std::string filelist, std::string outfile ) { gStyle->SetOptStat(0); TCanvas *ctemp = new TCanvas(); TCanvas *cres = new TCanvas("TimeDependence"); TH1F* hres = new TH1F("hres","",100,0,650); hres->GetYaxis()->SetRangeUser(0,50); hres->SetTitle(""); hres->GetXaxis()->SetTitle("time (s)"); hres->GetYaxis()->SetTitle("B_{int} (mT)"); hres->Draw(); leg = new TLegend(0.2,0.6,0.9,0.9); // leg->SetHeader("The Legend Title"); // option "C" allows to center the header leg->SetNColumns(5); vector< double > v_Bint; vector< double > v_BintErr; vector< double > v_Bext; vector< double > v_BextErr; /* Loop over all lines in input file */ std::ifstream infilelist(filelist); std::string line; unsigned colorcounter=38; while (std::getline(infilelist, line)) { // skip lines with '#' and empty lines if ( line.find("#") != string::npos ) { cout << "Skip line " << line << endl; continue; } if ( line == "" ) continue; //cout << "Processing file " << line << endl; TString infilename("data_calib/"); infilename.Append(line); TFile *fin = new TFile( infilename ); TTree *tin = (TTree*)fin->Get("t"); ctemp->cd(); tin->Draw("Bi:time"); TGraph *gtime = new TGraph(tin->GetEntries(), &(tin->GetV2()[0]), &(tin->GetV1()[0])); gtime->SetLineColor(colorcounter); colorcounter++; TH1F* hBext = new TH1F("hBext","",100,0,1000); tin->Draw("Bo >> hBext"); cres->cd(); gtime->Draw("lsame"); double Bext_i = hBext->GetMean(); double BextErr_i = hBext->GetRMS(); double Bint_i = gtime->Eval(590); double BintErr_i = 0; /* add legend entry */ TString legname("B_ext ~ "); legname += (int)Bext_i; leg->AddEntry(gtime,legname,"l"); cout << "B_ext: " << Bext_i << " \t B_int: " << Bint_i << endl; v_Bint.push_back(Bint_i); v_BintErr.push_back(BintErr_i); v_Bext.push_back(Bext_i); v_BextErr.push_back(BextErr_i); } cres->cd(); leg->Draw(); TGraphErrors *gfinal = new TGraphErrors(v_Bext.size(), &(v_Bext[0]), &(v_Bint[0]), &(v_BextErr[0]), &(v_BintErr[0])); gfinal->Sort(); gfinal->SetName("Bint_Vs_Bext"); gfinal->SetTitle(""); gfinal->GetXaxis()->SetTitle("B_{ext} (mT)"); gfinal->GetYaxis()->SetTitle("B_{int} (mT)"); TCanvas *cfinal = new TCanvas(); gfinal->Draw("APL"); /* Save output graph */ TString outfilename("output/"); outfilename.Append(outfile); TFile *fout = new TFile(outfilename,"RECREATE"); cres->Write(); gfinal->Write(); fout->Close(); /* Write result to txt output file */ TString outfilenametxt = outfilename; outfilenametxt.ReplaceAll(".root",".txt"); ofstream foutxt; foutxt.open( outfilenametxt ); foutxt << "# Bo sig_Bo Bi sig_Bi shield sig_shield sf sig_sf time_dependent" << endl; for ( int i = 0; i < gfinal->GetN(); i++ ) { double Bo = gfinal->GetX()[i]; double sig_Bo = gfinal->GetEX()[i]; double Bi = gfinal->GetY()[i]; double sig_Bi = gfinal->GetEY()[i]; double shield = 0; double sig_shield = 0; double sf = 0; double sig_sf = 0; double time_dependent = 0; foutxt << Bo << " " << sig_Bo << " " << Bi << " " << sig_Bi << " " << shield << " " << sig_shield << " " << sf << " " << sig_sf << " " << time_dependent << endl; } return 0; }
void QA_Draw_Jet_Summary(const char *jet_family = "AntiKt_Tower", const char *qa_file_name_new = "data/G4sPHENIXCells_2000jets25GeV.root_qa.root", const char *qa_file_name_ref = "data/G4sPHENIXCells_250jets25GeV.root_qa.root") { //! drawing energy range const double min_Et = 10; const double max_Et = 80; SetsPhenixStyle(); TVirtualFitter::SetDefaultFitter("Minuit2"); // file IO TFile *qa_file_new = new TFile(qa_file_name_new); assert(qa_file_new->IsOpen()); // buffer for results vector<float> vec_radius; vector<TGraphErrors *> vec_phi_res; vector<TGraphErrors *> vec_eta_res; vector<TGraphErrors *> vec_e_res; vector<TGraphErrors *> vec_et_res; vector<TGraphErrors *> vec_reco_eff; vector<TGraphErrors *> vec_purity; // list and process all jets TList *hist_key_list = qa_file_new->GetListOfKeys(); for (int i = 0; i < hist_key_list->GetSize(); ++i) { TString key_name = hist_key_list->At(i)->GetName(); TString s_re_fullname = Form( "h_QAG4SimJet_.*_r[0-9]*_%s_r[0-9]*_Matching_Count_Truth_Et", jet_family); // regular expression for search TRegexp re_fullname(s_re_fullname, false); if (key_name.Index(re_fullname) == kNPOS) continue; // cout << " key_name = " << key_name << endl; TString jet_pair_name = key_name(0, key_name.Length() - TString("_Matching_Count_Truth_Et").Length()); // remove suffix // cout << " jet_pair_name = " << jet_pair_name << endl; //get jet radius TRegexp re_jetradius("_r[0-9]*", false); Ssiz_t index_radius = key_name.Index(re_jetradius); // first radius index_radius = key_name.Index(re_jetradius, index_radius + 1); // second radius assert(index_radius != kNPOS); float radius = 0; sscanf(key_name(index_radius, 100).Data(), "_r%f", &radius); // cout << " index_radius = " << index_radius << endl; assert(radius != 0); radius /= 10; // jet radius convention in DST names cout << "QA_Draw_Jet_Summary - process jet pair " << jet_pair_name << " with radius = " << radius << endl; vector<TGraphErrors *> resolution_efficiency_summary( QA_Draw_Jet_TruthMatching(jet_pair_name, qa_file_name_new, qa_file_name_ref)); //save results vec_radius.push_back(radius); vec_phi_res.push_back(resolution_efficiency_summary[0]); vec_eta_res.push_back(resolution_efficiency_summary[1]); vec_e_res.push_back(resolution_efficiency_summary[2]); vec_et_res.push_back(resolution_efficiency_summary[3]); vec_reco_eff.push_back(resolution_efficiency_summary[4]); vec_purity.push_back(resolution_efficiency_summary[5]); // break; } // plot TCanvas *c1 = new TCanvas( TString("QA_Draw_Jet_Summary_") + TString(jet_family), TString("QA_Draw_Jet_Summary_") + TString(jet_family), 1800, 900); c1->Divide(3, 2); int idx = 1; TPad *p; // ------------------------------------ p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); TH1 *h_frame = p->DrawFrame(min_Et, -.1, max_Et, .1, TString(jet_family) + " #phi Reconstruction;E_{T, Truth} (GeV);#phi_{Reco} - #phi_{Truth} (rad)"); // h_frame->GetYaxis()->SetTitleOffset(1.01); TLine *l = new TLine(min_Et, 0, max_Et, 0); l->Draw(); p->SetGridx(0); p->SetGridy(0); TLegend *legend = new TLegend(0.7, 0.2, .95, 0.5); legend->SetFillColor(kWhite); legend->SetFillStyle(1001); legend->SetLineWidth(2); legend->SetLineColor(kBlack); legend->SetLineStyle(kSolid); for (int i = 0; i < vec_radius.size(); ++i) { const float radius = vec_radius[i]; TGraphErrors *ge = vec_phi_res[i]; assert(ge); ge = new TGraphErrors(*ge); // make a copy ge->SetLineColor(i + 2); // automatic color scheme from ROOT ge->SetMarkerColor(i + 2); // automatic color scheme from ROOT for (int idata = 0; idata < ge->GetN(); ++idata) { (ge->GetX())[idata] += i * 0.5; // shift x a little bit (ge->GetEX())[idata] = 0; // no x error bar } ge->Draw("p E l"); legend->AddEntry(ge, Form("r = %.1f", radius), "elp"); } legend->Draw(); // ------------------------------------ p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); h_frame = p->DrawFrame(min_Et, -.1, max_Et, .1, TString(jet_family) + " #eta Reconstruction;E_{T, Truth} (GeV);#eta_{Reco} - #eta_{Truth}"); // h_frame->GetYaxis()->SetTitleOffset(1.01); l = new TLine(min_Et, 0, max_Et, 0); l->Draw(); p->SetGridx(0); p->SetGridy(0); legend = new TLegend(0.7, 0.2, .95, 0.5); legend->SetFillColor(kWhite); legend->SetFillStyle(1001); legend->SetLineWidth(2); legend->SetLineColor(kBlack); legend->SetLineStyle(kSolid); for (int i = 0; i < vec_radius.size(); ++i) { const float radius = vec_radius[i]; TGraphErrors *ge = vec_eta_res[i]; assert(ge); ge = new TGraphErrors(*ge); // make a copy ge->SetLineColor(i + 2); // automatic color scheme from ROOT ge->SetMarkerColor(i + 2); // automatic color scheme from ROOT for (int idata = 0; idata < ge->GetN(); ++idata) { (ge->GetX())[idata] += i * 0.5; // shift x a little bit (ge->GetEX())[idata] = 0; // no x error bar } ge->Draw("p E l"); legend->AddEntry(ge, Form("r = %.1f", radius), "elp"); } legend->Draw(); // ------------------------------------ p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); h_frame = p->DrawFrame(min_Et, 0, max_Et, 2, TString(jet_family) + " Jet Energy Reconstruction;E_{Truth} (GeV);E_{Reco} / E_{Truth}"); // h_frame->GetYaxis()->SetTitleOffset(1.01); l = new TLine(min_Et, 1, max_Et, 1); l->Draw(); p->SetGridx(0); p->SetGridy(0); legend = new TLegend(0.7, 0.2, .95, 0.5); legend->SetFillColor(kWhite); legend->SetFillStyle(1001); legend->SetLineWidth(2); legend->SetLineColor(kBlack); legend->SetLineStyle(kSolid); for (int i = 0; i < vec_radius.size(); ++i) { const float radius = vec_radius[i]; TGraphErrors *ge = vec_e_res[i]; assert(ge); ge = new TGraphErrors(*ge); // make a copy ge->SetLineColor(i + 2); // automatic color scheme from ROOT ge->SetMarkerColor(i + 2); // automatic color scheme from ROOT for (int idata = 0; idata < ge->GetN(); ++idata) { (ge->GetX())[idata] += i * 0.5; // shift x a little bit (ge->GetEX())[idata] = 0; // no x error bar } ge->Draw("p E l"); legend->AddEntry(ge, Form("r = %.1f", radius), "elp"); } legend->Draw(); // ------------------------------------ p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); h_frame = p->DrawFrame(min_Et, 0, max_Et, 2, TString(jet_family) + " Jet E_{T} Reconstruction;E_{T, Truth} (GeV);E_{T, Reco} / E_{T, Truth}"); // h_frame->GetYaxis()->SetTitleOffset(1.01); l = new TLine(min_Et, 1, max_Et, 1); l->Draw(); p->SetGridx(0); p->SetGridy(0); legend = new TLegend(0.7, 0.2, .95, 0.5); legend->SetFillColor(kWhite); legend->SetFillStyle(1001); legend->SetLineWidth(2); legend->SetLineColor(kBlack); legend->SetLineStyle(kSolid); for (int i = 0; i < vec_radius.size(); ++i) { const float radius = vec_radius[i]; TGraphErrors *ge = vec_et_res[i]; assert(ge); ge = new TGraphErrors(*ge); // make a copy ge->SetLineColor(i + 2); // automatic color scheme from ROOT ge->SetMarkerColor(i + 2); // automatic color scheme from ROOT for (int idata = 0; idata < ge->GetN(); ++idata) { (ge->GetX())[idata] += i * 0.5; // shift x a little bit (ge->GetEX())[idata] = 0; // no x error bar } ge->Draw("p E l"); legend->AddEntry(ge, Form("r = %.1f", radius), "elp"); } legend->Draw(); // ------------------------------------ p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); h_frame = p->DrawFrame(min_Et, 0, max_Et, 1.2, TString(jet_family) + " Reco Efficiency;E_{T, Truth} (GeV);Reco efficiency"); // h_frame->GetYaxis()->SetTitleOffset(1.01); l = new TLine(min_Et, 1, max_Et, 1); l->Draw(); p->SetGridx(0); p->SetGridy(0); legend = new TLegend(0.7, 0.2, .95, 0.5); legend->SetFillColor(kWhite); legend->SetFillStyle(1001); legend->SetLineWidth(2); legend->SetLineColor(kBlack); legend->SetLineStyle(kSolid); for (int i = 0; i < vec_radius.size(); ++i) { const float radius = vec_radius[i]; TGraphErrors *ge = vec_reco_eff[i]; assert(ge); ge = new TGraphErrors(*ge); // make a copy ge->SetLineColor(i + 2); // automatic color scheme from ROOT ge->SetMarkerColor(i + 2); // automatic color scheme from ROOT for (int idata = 0; idata < ge->GetN(); ++idata) { (ge->GetX())[idata] += i * 0.5; // shift x a little bit (ge->GetEX())[idata] = 0; // no x error bar } ge->Draw("p E l"); legend->AddEntry(ge, Form("r = %.1f", radius), "elp"); } legend->Draw(); // ------------------------------------ p = (TPad *) c1->cd(idx++); c1->Update(); // p->SetLogz(); h_frame = p->DrawFrame(min_Et, 0, max_Et, 1.2, TString(jet_family) + " Reconstruction Purity;E_{T, Reco} (GeV);Reconstruction Purity"); // h_frame->GetYaxis()->SetTitleOffset(1.01); l = new TLine(min_Et, 1, max_Et, 1); l->Draw(); p->SetGridx(0); p->SetGridy(0); legend = new TLegend(0.7, 0.2, .95, 0.5); legend->SetFillColor(kWhite); legend->SetFillStyle(1001); legend->SetLineWidth(2); legend->SetLineColor(kBlack); legend->SetLineStyle(kSolid); for (int i = 0; i < vec_radius.size(); ++i) { const float radius = vec_radius[i]; TGraphErrors *ge = vec_purity[i]; assert(ge); ge = new TGraphErrors(*ge); // make a copy ge->SetLineColor(i + 2); // automatic color scheme from ROOT ge->SetMarkerColor(i + 2); // automatic color scheme from ROOT for (int idata = 0; idata < ge->GetN(); ++idata) { (ge->GetX())[idata] += i * 0.5; // shift x a little bit (ge->GetEX())[idata] = 0; // no x error bar } ge->Draw("p E l"); legend->AddEntry(ge, Form("r = %.1f", radius), "elp"); } legend->Draw(); // PutInputFileName(c1, .03, qa_file_name_new, qa_file_name_ref); SaveCanvas(c1, TString(qa_file_name_new) + TString(c1->GetName()), true); }
void pointsed(TString filename = "btagpatanalyzerpy.root", TString check="") { TString cmssw; // 167 cmssw = "$3.1.0_pre9$"; TFile *f = TFile::Open(filename); ///////////////////////////////////////////////////////////////////////////////////////// std::vector< TString > checks; checks.push_back(""); checks.push_back("Corr30_"); checks.push_back("Corr30t0_"); checks.push_back("Corr30t1_"); checks.push_back("Corr30t2_"); checks.push_back("Corr30t0_nConstituent_"); checks.push_back("Corr30t1_nConstituent_"); checks.push_back("Corr30t2_nConstituent_"); checks.push_back("Uncor10_"); checks.push_back("Uncor10t0_"); checks.push_back("Uncor10t1_"); checks.push_back("Uncor10t2_"); checks.push_back("Uncor10t0_nConstituent_"); checks.push_back("Uncor10t1_nConstituent_"); checks.push_back("Uncor10t2_nConstituent_"); ///////////////////////////////////////////////////////////////////////////////////////// std::vector< TString > taggers; std::vector< TString > labeltag; std::vector< int> colorlines; taggers.push_back( "TC2" );colorlines.push_back( 1 );labeltag.push_back( "TCHE"); taggers.push_back( "TC3" );colorlines.push_back( 2 );labeltag.push_back( "TCHP"); taggers.push_back( "TP" );colorlines.push_back( 3 );labeltag.push_back( "JP"); taggers.push_back( "SSV" );colorlines.push_back( 4 );labeltag.push_back( "SSV"); taggers.push_back( "CSV" );colorlines.push_back( 5 );labeltag.push_back( "CSV"); taggers.push_back( "MSV" );colorlines.push_back( 6 );labeltag.push_back( "CSVMVAB"); taggers.push_back( "SMT" );colorlines.push_back( 8 );labeltag.push_back( "SMT"); taggers.push_back( "BTP" );colorlines.push_back( 9 );labeltag.push_back( "JBP"); taggers.push_back( "SMTbyIP3d" );colorlines.push_back( 11 );labeltag.push_back( "SMTByIP3d"); taggers.push_back( "SMTbyPt" );colorlines.push_back( 12 );labeltag.push_back( "SMTByPt"); taggers.push_back( "SETbyIP3d" );colorlines.push_back( 13 );labeltag.push_back( "SETByIP3d"); taggers.push_back( "SETbyPt" );colorlines.push_back( 14 );labeltag.push_back( "SETByPt"); // taggers.push_back( "IPM" );colorlines.push_back( 11 );labeltag.push_back( "IPMVAB"); // taggers.push_back( "SMNIPT" );colorlines.push_back( 12 );labeltag.push_back( "SMTNoIP"); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //ed for ( size_t ichks = 0; ichks < checks.size(); ++ichks ) { //ed TString check = checks[ichks]; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TString PerfTitle= check; if (check == "") PerfTitle="uncorr pt>30"; if (check == "Corr30_") PerfTitle="pt>30"; if (check == "Corr30t0_") PerfTitle="pt>30, #tracks > 0"; if (check == "Corr30t1_") PerfTitle="pt>30, #tracks > 1"; if (check == "Corr30t2_") PerfTitle="pt>30, #tracks > 2"; if (check == "Corr30t0_nConstituent_") PerfTitle="pt>30, #tracks > 0 & nConstituents >1"; if (check == "Corr30t1_nConstituent_") PerfTitle="pt>30, #tracks > 1 & nConstituents >1"; if (check == "Corr30t2_nConstituent_") PerfTitle="pt>30, #tracks > 2 & nConstituents >1"; if (check == "Uncor10_") PerfTitle="uncorr pt>10"; if (check == "Uncor10t0_") PerfTitle="uncorr pt>10 #tracks > 0"; if (check == "Uncor10t1_") PerfTitle="uncorr pt>10 #tracks > 1"; if (check == "Uncor10t2_") PerfTitle="uncorr pt>10 #tracks > 2"; if (check == "Uncor10t0_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 0 & nConstituents >1"; if (check == "Uncor10t1_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 1 & nConstituents >1"; if (check == "Uncor10t2_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 2 & nConstituents >1"; std::vector< TString > discriminators; for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) { discriminators.push_back( check+"disc"+taggers[itagger]+"_udsg" ); } // discriminators.push_back( "discTC3_udsg" ); // discriminators.push_back( "discTP_udsg" ); TCanvas *cv = new TCanvas("cv","cv",900,900); TMultiGraph *mg =new TMultiGraph(); TLegend *legend0 = new TLegend(0.68,0.12,0.88,0.32); // inverted axis TMultiGraph *mginv =new TMultiGraph(); TLegend *legend1 = new TLegend(0.65,0.18,0.85,0.48); std::ofstream salida("BTagPATop3"+check+".txt"); for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) { TString tag = check+"g"+taggers[itagger]+"_udsg"; TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag); TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]); // TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX()); dgraph->Sort(); // udsgvsdgraph->Sort(); TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX()); g->Sort(); g->SetLineColor(itagger+1); legend0 -> AddEntry(g,taggers[itagger],"l"); mg->Add(g); //inverted axis TGraphErrors *ginv = new TGraphErrors(agraph->GetN(),agraph->GetX(),agraph->GetY(),agraph->GetEX(),agraph->GetEY()); ginv->Sort(); ginv->SetLineColor(colorlines[itagger]); ginv->SetMarkerStyle(8); ginv->SetMarkerColor(colorlines[itagger]); legend1 -> AddEntry(ginv,labeltag[itagger],"l"); mginv->Add(ginv); std::cout << " Tagger: " << tag << std::endl; std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl; std::cout << " Medium(1%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl; std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl; salida << " " << taggers[itagger] << endl; salida << " #bin \t b-eff \t err-beff \t non-beff \t err-non-b"<< endl; for ( size_t i=0;i< agraph->GetN();i++){ salida << " " << (i+1) << " \t " << agraph->GetX()[i] <<" \t " << agraph->GetEX()[i]<<" \t " << agraph->GetY()[i] <<" \t " << agraph->GetEY()[i] << " "<< endl; } } // cv->SetLogx(); mg->Draw("ALP"); mg->GetYaxis()->SetTitle("b-eff"); mg->GetXaxis()->SetTitle("udsg-mistagging"); legend0 -> Draw(); cv-> SetGrid(); cv-> Print ("BTagPATop"+check+".eps"); cv-> Print ("BTagPATop"+check+".png"); cv->cd(0); cv->SetLogx(); mg->Draw("ALP"); legend0 -> Draw(); cv-> Print ("BTagPATop1"+check+".eps"); cv-> Print ("BTagPATop1"+check+".png"); //inverted axis TCanvas *cvinv = new TCanvas("cvinv","cvinv",700,700); cvinv->SetLogy(0); mginv->Draw("ALP"); mginv->GetXaxis()->SetTitle("b-eff"); mginv->GetYaxis()->SetTitle("udsg-mistagging"); legend1 -> Draw(); cvinv->SetGrid(); cvinv-> Print ("BTagPATop2"+check+".eps"); cvinv-> Print ("BTagPATop2"+check+".png"); cvinv->cd(0); // cvinv->Update(); // cvinv->SetLogx(); // mginv->SetXmin(10^-4); // axis range using a histogram helper TH2D*hpx = new TH2D("hpx",PerfTitle,200,0.0,1.005,200,0.00002,1.05); hpx->SetStats(kFALSE); hpx->Draw(); hpx->GetXaxis()->SetTitle("b-eff"); hpx->GetYaxis()->SetTitle("udsg-mistagging"); cvinv->SetLogy(1); mginv->Draw("AP"); legend1 -> Draw(); cvinv-> Print ("BTagPATop3"+check+".eps"); cvinv-> Print ("BTagPATop3"+check+".png"); //ed} }
void plot(int mass) { double myQCDRelUncert = 0.038; double myEWKRelUncert = 0.131; double myFakesRelUncert = 0.238; double delta = 1.4; double br = 0.05; bool debug = false; bool log = false; double ymin = 0.001; double ymax = 48; static bool bMessage = false; if (!bMessage) { cout << "Values used as relative uncertainty (please check):" << endl; cout << " QCD: " << myQCDRelUncert << endl; cout << " EWK genuine tau: " << myEWKRelUncert << endl; cout << " EWK fake tau: " << myFakesRelUncert << endl << endl; bMessage = true; } cout << "Processing mass point: " << mass << " GeV/c2" << endl; gStyle->SetOptFit(1); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetTitleFont(43, "xyz"); gStyle->SetTitleSize(33, "xyz"); gStyle->SetLabelFont(43, "xyz"); gStyle->SetLabelSize(27, "xyz"); //std::string infile = "EPS_data_nodeltaphi/hplus_100.root"; //std::string infile = "EPS_data_deltaphi160/hplus_100.root"; std::stringstream s; s << "lands_histograms_hplushadronic_m" << mass << ".root"; std::string infile = s.str(); // Canvas TCanvas *myCanvas = new TCanvas("myCanvas", "",0,0,600,600); myCanvas->SetHighLightColor(2); myCanvas->Range(0,0,1,1); myCanvas->SetFillColor(0); myCanvas->SetBorderMode(0); myCanvas->SetBorderSize(2); if (log) myCanvas->SetLogy(); myCanvas->SetTickx(1); myCanvas->SetTicky(1); myCanvas->SetLeftMargin(0.16); myCanvas->SetRightMargin(0.05); myCanvas->SetTopMargin(0.05); myCanvas->SetBottomMargin(0.08); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->SetFrameFillStyle(0); myCanvas->SetFrameBorderMode(0); myCanvas->cd(); Int_t ci; TFile* f = TFile::Open(infile.c_str()); s.str(""); s << "HW" << mass << "_1"; TH1* hw = (TH1*)f->Get(s.str().c_str()); s.str(""); s << "HH" << mass << "_1"; TH1* hh = (TH1*)f->Get(s.str().c_str()); TH1* data = (TH1*)f->Get("data_obs"); data->SetLineWidth(2); data->SetMarkerStyle(20); data->SetMarkerSize(1.2); TH1* ewktau = (TH1*)f->Get("EWK_Tau"); ci = TColor::GetColor("#993399"); ewktau->SetFillColor(ci); ewktau->SetLineWidth(0); TH1* ewkDY = (TH1*)f->Get("EWK_DYx"); TH1* ewkVV = (TH1*)f->Get("EWK_VVx"); ewktau->Add(ewkDY); ewktau->Add(ewkVV); //TH1* qcd = (TH1*)f->Get("QCDInv"); TH1* qcd = (TH1*)f->Get("QCD"); ci = TColor::GetColor("#ffcc33"); qcd->SetFillColor(ci); qcd->SetLineWidth(0); TH1* fakett = (TH1*)f->Get("fake_tt"); ci = TColor::GetColor("#669900"); fakett->SetFillColor(ci); fakett->SetLineWidth(0); TH1* fakeW = (TH1*)f->Get("fake_W"); ci = TColor::GetColor("#cc3300"); fakeW->SetFillColor(ci); fakeW->SetLineWidth(0); TH1* faket = (TH1*)f->Get("fake_t"); TH1F *hFrame = new TH1F("hFrame","",20,0,400); hFrame->SetMinimum(ymin); if (log) hFrame->SetMaximum(ymax*1.5); else hFrame->SetMaximum(ymax); hFrame->SetDirectory(0); hFrame->SetStats(0); hFrame->SetLineStyle(0); hFrame->SetMarkerStyle(20); hFrame->SetXTitle("Transverse mass (#tau jet, E_{T}^{miss}), (GeV/c^{2})"); if (paperStatus) hFrame->SetXTitle("Transverse mass (#tau_{h}, E_{T}^{miss}), (GeV/c^{2})"); hFrame->SetYTitle("Events / 20 GeV/c^{2}"); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(27); hFrame->GetYaxis()->SetTitleOffset(1.3); // signal hh->Scale(br*br); hw->Scale(2*br*(1.0-br)); TH1* signal = (TH1*)hh->Clone(); signal->Add(hw); ci = TColor::GetColor("#ff3399"); signal->SetLineColor(ci); signal->SetLineStyle(2); signal->SetLineWidth(2); // Fakes TH1* fakes = (TH1*)(fakett->Clone()); fakes->Add(fakeW); fakes->Add(faket); // stacked backgrounds THStack *exp = new THStack(); exp->SetName("exp"); exp->SetTitle("exp"); exp->Add(fakes); exp->Add(ewktau); exp->Add(qcd); exp->Add(signal); TH1* hExpBkg = (TH1*)fakes->Clone(); hExpBkg->Add(ewktau); hExpBkg->Add(qcd); // uncertainty TH1* uncert = (TH1*)fakeW->Clone(); uncert->Add(fakett); uncert->Add(ewktau); uncert->Add(qcd); uncert->SetFillColor(1); uncert->SetFillStyle(3344); uncert->SetLineColor(0); uncert->SetLineStyle(0); uncert->SetLineWidth(0); TH1* hExpBkgTotalUncert = (TH1*)uncert->Clone(); hExpBkgTotalUncert->SetFillStyle(3354); TH1* hAgreement = (TH1*)data->Clone(); hAgreement->Divide(hExpBkg); TGraphErrors* hAgreementRelUncert = new TGraphErrors(hAgreement->GetNbinsX()); hAgreementRelUncert->SetLineWidth(2); hAgreementRelUncert->SetLineColor(kBlack); for (int i = 1; i <= hFrame->GetNbinsX(); ++i) { double myQCDTotalUncert = TMath::Power(qcd->GetBinError(i), 2) + TMath::Power(qcd->GetBinContent(i)*myQCDRelUncert, 2); double myEWKTotalUncert = TMath::Power(ewktau->GetBinError(i), 2) + TMath::Power(ewktau->GetBinContent(i)*myEWKRelUncert, 2); double myFakesTotalUncert = TMath::Power(fakes->GetBinError(i), 2) + TMath::Power(fakes->GetBinContent(i)*myFakesRelUncert, 2); hExpBkgTotalUncert->SetBinError(i, TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert)); if (hExpBkg->GetBinContent(i) > 0) { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), data->GetBinContent(i) / hExpBkg->GetBinContent(i)); double myUncertData = 0; if (data->GetBinContent(i) > 0) myUncertData = TMath::Power(data->GetBinError(i) / data->GetBinContent(i), 2); double myUncertBkg = (myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / TMath::Power(hExpBkg->GetBinContent(i), 2); hAgreementRelUncert->SetPointError(i-1, 0, data->GetBinContent(i) / hExpBkg->GetBinContent(i) * TMath::Sqrt(myUncertData + myUncertBkg)); } else { hAgreementRelUncert->SetPoint(i-1, hExpBkg->GetBinCenter(i), 0); hAgreementRelUncert->SetPointError(i-1, 0, 0); } if (debug) { cout << "Point: " << hAgreementRelUncert->GetX()[i-1]-10 << "-" << hAgreementRelUncert->GetX()[i-1]+10 << " GeV/c2, agreement: " << hAgreementRelUncert->GetY()[i-1] << ", uncert: " << hAgreement->GetBinError(i) << ", " << hAgreementRelUncert->GetErrorY(i-1) << endl; cout << " bkg. stat. uncert. " << hExpBkg->GetBinError(i) << " (i.e. " << hExpBkg->GetBinError(i) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << ", stat+syst uncert. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) << " (i.e. " << TMath::Sqrt(myQCDTotalUncert + myEWKTotalUncert + myFakesTotalUncert) / hExpBkg->GetBinContent(i) * 100.0 << " %)" << endl; } } // Agreement pad TPad* pad = new TPad("ratiopad","ratiopad",0.,0.,1.,.3); pad->Draw(); pad->cd(); pad->Range(0,0,1,1); pad->SetFillColor(0); pad->SetFillStyle(4000); pad->SetBorderMode(0); pad->SetBorderSize(2); pad->SetTickx(1); pad->SetTicky(1); pad->SetLeftMargin(0.16); pad->SetRightMargin(0.05); pad->SetTopMargin(0); pad->SetBottomMargin(0.34); pad->SetFrameFillStyle(0); pad->SetFrameBorderMode(0); // Plot here ratio if (1.0-delta > 0) hAgreement->SetMinimum(1.0-delta); else hAgreement->SetMinimum(0.); hAgreement->SetMaximum(1.0+delta); hAgreement->GetXaxis()->SetLabelOffset(0.007); hAgreement->GetXaxis()->SetLabelFont(43); hAgreement->GetXaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelFont(43); hAgreement->GetYaxis()->SetLabelSize(27); hAgreement->GetYaxis()->SetLabelOffset(0.007); hAgreement->GetYaxis()->SetNdivisions(505); hAgreement->GetXaxis()->SetTitleFont(43); hAgreement->GetYaxis()->SetTitleFont(43); hAgreement->GetXaxis()->SetTitleSize(33); hAgreement->GetYaxis()->SetTitleSize(33); hAgreement->SetTitleSize(27, "xyz"); hAgreement->GetXaxis()->SetTitleOffset(3.2); hAgreement->GetYaxis()->SetTitleOffset(1.3); hAgreement->SetXTitle(hFrame->GetXaxis()->GetTitle()); hAgreement->SetYTitle("Data/#Sigmabkg"); hAgreement->Draw("e2"); // Plot line at zero TH1* hAgreementLine = dynamic_cast<TH1*>(hAgreement->Clone()); for (int i = 1; i <= hAgreementLine->GetNbinsX(); ++i) { hAgreementLine->SetBinContent(i,1.0); hAgreementLine->SetBinError(i,0.0); } hAgreementLine->SetLineColor(kRed); hAgreementLine->SetLineWidth(2); hAgreementLine->SetLineStyle(3); hAgreementLine->Draw("hist same"); hAgreement->Draw("same"); hAgreementRelUncert->Draw("[]"); pad->RedrawAxis(); myCanvas->cd(); TPad* plotpad = new TPad("plotpad", "plotpad",0,0.3,1.,1.); plotpad->Draw(); plotpad->cd(); plotpad->Range(0,0,1,1); plotpad->SetFillColor(0); plotpad->SetFillStyle(4000); plotpad->SetBorderMode(0); plotpad->SetBorderSize(2); //if (logy) // plotpad->SetLogy(); plotpad->SetTickx(1); plotpad->SetTicky(1); plotpad->SetLeftMargin(0.16); plotpad->SetRightMargin(0.05); plotpad->SetTopMargin(0.065); plotpad->SetBottomMargin(0.0); plotpad->SetFrameFillStyle(0); plotpad->SetFrameBorderMode(0); hFrame->GetXaxis()->SetTitleSize(0); hFrame->GetXaxis()->SetLabelSize(0); hFrame->GetYaxis()->SetTitleFont(43); hFrame->GetYaxis()->SetTitleSize(33); hFrame->GetYaxis()->SetTitleOffset(1.3); // Draw objects hFrame->Draw(); exp->Draw("hist same"); uncert->Draw("E2 same"); hExpBkgTotalUncert->Draw("E2 same"); // Data data->Draw("same"); //signal->Draw("same"); TLegend *leg = new TLegend(0.53,0.6,0.87,0.91,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextFont(63); leg->SetTextSize(18); leg->SetLineColor(1); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(kWhite); //leg->SetFillStyle(4000); // enabling this will cause the plot to be erased from the pad TLegendEntry* entry = leg->AddEntry(data, "Data", "P"); s.str(""); s << "with H^{#pm}#rightarrow#tau^{#pm}#nu"; entry = leg->AddEntry(signal, s.str().c_str(), "L"); entry = leg->AddEntry(qcd, "QCD (meas.)", "F"); entry = leg->AddEntry(ewktau, "EWK genuine #tau (meas.)", "F"); entry = leg->AddEntry(fakes, "EWK fake #tau (MC)", "F"); entry = leg->AddEntry(uncert, "stat. uncert.", "F"); entry = leg->AddEntry(hExpBkgTotalUncert, "stat. #oplus syst. uncert.", "F"); leg->Draw(); string myTitle = "CMS Preliminary"; if (paperStatus) myTitle = "CMS"; TLatex *tex = new TLatex(0.62,0.945,myTitle.c_str()); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.2,0.945,"#sqrt{s} = 7 TeV"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.43,0.945,"2.2 fb^{-1}"); tex->SetNDC(); tex->SetTextFont(43); tex->SetTextSize(27); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "m_{H^{#pm}} = " << mass << " GeV/c^{2}"; tex = new TLatex(0.28,0.865,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); s.str(""); s << "BR(t#rightarrowbH^{#pm})=" << setprecision(2) << br; tex = new TLatex(0.28,0.805,s.str().c_str()); tex->SetNDC(); tex->SetTextFont(63); tex->SetTextSize(20); tex->SetLineWidth(2); tex->Draw(); plotpad->RedrawAxis(); plotpad->Modified(); s.str(""); s << "mT_datadriven_m" << mass << ".png"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".C"; myCanvas->Print(s.str().c_str()); s.str(""); s << "mT_datadriven_m" << mass << ".eps"; myCanvas->Print(s.str().c_str()); }