void gerrors2() { TCanvas *c1 = new TCanvas("c1","gerrors2",200,10,700,500); c1->SetFillColor(42); c1->SetGrid(); // draw a frame to define the range TH1F *hr = c1->DrawFrame(-0.4,0,1.2,12); hr->SetXTitle("X title"); hr->SetYTitle("Y title"); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(12); // create first graph const Int_t n1 = 10; Double_t x1[] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; Double_t y1[] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1}; Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05}; Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8}; TGraphErrors *gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1); gr1->SetMarkerColor(kBlue); gr1->SetMarkerStyle(21); gr1->Draw("LP"); // create second graph const Int_t n2 = 10; Float_t x2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01}; Float_t y2[] = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2}; Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04}; Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7}; TGraphErrors *gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2); gr2->SetMarkerColor(kRed); gr2->SetMarkerStyle(20); gr2->Draw("LP"); }
void read25cm() { TFile *f = new TFile("read25c.root"); //root file name TTree *ntuple = (TTree*)f->Get("ntuple"); Float_t dRm,dRmbar,dRb,dRbbar; //Values ntuple->SetBranchAddress("dRm",&dRm); //Values ntuple->SetBranchAddress("dRmbar",&dRmbar); ntuple->SetBranchAddress("dRb",&dRb); ntuple->SetBranchAddress("dRbbar",&dRbbar); //create histogram TH1F *mudR = new TH1F("dRm","dR distribution of mu and jet",100,0.,2 * M_PI); TH1F *mubardR = new TH1F("dRmbar","dR distribution of mubar and jet",100,0.,2 * M_PI); TH1F *bdR = new TH1F("dRb","dR distribution of b and jet",100,0.,2 * M_PI); TH1F *bbardR = new TH1F("dRbbar","dR distribution of bbar and jet",100,0.,2 * M_PI); //read all entries and fill the histograms Long64_t nentries = ntuple->GetEntries(); for (Long64_t q=0;q<nentries;q++) { ntuple->GetEntry(q); mudR->Fill(dRm); //Histogram value mubardR->Fill(dRmbar); bdR->Fill(dRb); bbardR->Fill(dRbbar); } { mudR->SetXTitle("dR"); mudR->SetYTitle("Event"); mubardR->SetXTitle("dR"); mubardR->SetYTitle("Event"); bdR->SetXTitle("dR"); bdR->SetYTitle("Event"); bbardR->SetXTitle("dR"); bbardR->SetYTitle("Event"); } if (gROOT->IsBatch()) return; f->Write(); new TBrowser(); ntuple->StartViewer(); }
TCanvas * plot (TH1F* histoDataIn, TString legendData, TH1F* histoSimulationIn, TString legendSimulation, TString & canvasName, Float_t maximum = 0.15, TString xAxisTitle = "#eta", TString yAxisTitle = "Number of Clusters", TString error = "", bool useLegend = true, TString text = "", Float_t textX = 0.7, Float_t textY = 0.4, Float_t rebin = 0 ) { TH1F * histoData = (TH1F*)histoDataIn->Clone(); TH1F * histoSimulation = (TH1F*)histoSimulationIn->Clone(); // histoData->Sumw2(); histoData->Scale(1/(histoData->Integral())); histoSimulation->Scale(1/(histoSimulation->Integral())); // Create also the legend and add the histograms TLegend * legend = new TLegend( 0.55, 0.65, 0.76, 0.82 ); legend->AddEntry( histoData, xAxisTitle ); legend->AddEntry( histoSimulation, yAxisTitle, "F" ); cout << "histoData = " << histoData << endl; cout << "histoSimulation = " << histoSimulation << endl; TCanvas * c = new TCanvas( canvasName, canvasName, 1000, 800 ); c->Draw(); histoSimulation->SetMaximum(maximum); histoSimulation->SetFillColor(kRed); // histoSimulation->SetLineWidth(0); histoSimulation->SetLineColor(kRed); histoSimulation->SetXTitle(xAxisTitle); histoSimulation->SetYTitle(yAxisTitle); histoSimulation->SetTitleOffset(1.6,"Y"); histoSimulation->SetTitle(); histoData->SetLineStyle(1); histoData->SetLineWidth(2.5); histoSimulation->Draw(); histoData->Draw("same"); legend->SetFillColor(kWhite); if (useLegend) legend->Draw("same"); if ( text != "" ) { TPaveText * pt = new TPaveText(textX, textY, textX+0.2, textY+0.17, "NDC" ); // "NDC" option sets coords relative to pad dimensions pt->SetFillColor(0); // text is black on white pt->SetTextSize(0.08); pt->SetBorderSize(0); pt->SetTextAlign(12); pt->AddText(text); pt->Draw("same"); //to draw your text object } return c; };
void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt) { vC1->cd(pad); TH1F *vFrame = gPad->DrawFrame(0,-130,60,70); vFrame->SetTitle(title); vFrame->SetTitleSize(0.2); vFrame->SetXTitle(xt); vFrame->SetYTitle(yt); grin->Draw("P"); grout->DrawClone("LPX"); }
//================================================ void toyMC_Cent() { gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetStatY(0.9); gStyle->SetStatX(0.9); gStyle->SetStatW(0.2); gStyle->SetStatH(0.2); myRandom = new TRandom3(); TDatime *clock = new TDatime(); myRandom->SetSeed(clock->GetTime()); // Get true refMult vs Ncoll distribution TH2F *hRefMultVsNcoll = 0x0; // Get different efficiency curve vs. refMult const int nEff = 2; const int nMult = 2; TF1 *funcEff[nEff]; funcEff[0] = new TF1("funcEff_0", "pol1",0,1000); funcEff[0]->SetParameters(0.9, -2e-4); funcEff[1] = new TF1("funcEff_1", "pol0",0,1000); funcEff[1]->SetParameter(0,0.6); TCanvas *c = new TCanvas("cEff","cEff",800,600); TH1F *hplot = new TH1F("hplot",";Mult;",100,0,1000); hplot->SetYTitle("Efficiency"); hplot->DrawCopy(); for(int i=0; i<2; i++) { funcEff[i]->SetLineColor(i+1); funcEff[i]->SetLineWidth(1.5); funcEff[i]->Draw("sames"); } TPaveText *title = GetTitleText("TPC tracking efficiency"); title->Draw(); TLegend *leg = new TLegend(0.4,0.2,0.7,0.4); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetTextSize(0.04); leg->AddEntry(funcEff[0], "Efficiency 1", "L"); leg->AddEntry(funcEff[1], "Efficiency 2", "L"); leg->Draw(); // Get ngTrack distribution to mimic efficiency distribution TH1F *hMcMult[nMult]; }
void binomialEfficiency1D(TH1F * numerator,TH1F * denominator){ TH1F * efficiency = numerator->Clone("efficiency"); efficiency->SetXTitle(numerator->GetXaxis()->GetTitle()); efficiency->SetYTitle("#epsilon"); for(int j=0;j<=numerator->GetXaxis()->GetNbins() ;j++){ if(denominator->GetBinContent(j)!=0){ float eff = numerator->GetBinContent(j)/denominator->GetBinContent(j); float err = sqrt(eff*(1-eff)/denominator->GetBinContent(j)); efficiency->SetBinContent(j,eff); efficiency->SetBinError(j,err); cout<<"1Deff "<<j<<" "<<eff<<" +/- "<<err<<endl; } } efficiency->Draw("E"); efficiency->SetMarkerColor(kRed); efficiency->SetMarkerStyle(23); efficiency->SetMarkerSize(2); }
void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt) { vC1->cd(pad); TH1F *vFrame = gPad->DrawFrame(0,0,15,150); vFrame->SetTitle(title); vFrame->SetTitleSize(0.2); vFrame->SetXTitle(xt); vFrame->SetYTitle(yt); grxy->SetMarkerColor(kBlue); grxy->SetMarkerStyle(21); grxy->SetMarkerSize(0.5); grxy->Draw("P"); grin->SetMarkerColor(kRed); grin->SetMarkerStyle(5); grin->SetMarkerSize(0.7); grin->Draw("P"); grout->DrawClone("LP"); }
TH1F * DrawOverflowBin(TH1F * h) { // This function paint the histogram h with an extra bin for overflows UInt_t nx = h->GetNbinsX()+1; Double_t *xbins= new Double_t[nx+1]; for (UInt_t i=0;i<nx;i++){ xbins[i]=h->GetBinLowEdge(i+1); } xbins[nx]=xbins[nx-1]+h->GetBinWidth(nx); //char *tempName= new char[strlen(h->GetName())+10]; //sprintf(tempName,"%swtOverFlow",h->GetName()); stringstream tempName; tempName << h->GetName() << "wtOverFlow"; // Book a temporary histogram having ab extra bin for overflows TH1F *htmp = new TH1F(tempName.str().c_str(), h->GetTitle(), nx, xbins); // Reset the axis labels htmp->SetXTitle(h->GetXaxis()->GetTitle()); htmp->SetYTitle(h->GetYaxis()->GetTitle()); // Fill the new hitogram including the extra bin for overflows for (UInt_t i=1; i<=nx; i++){ htmp->Fill(htmp->GetBinCenter(i), h->GetBinContent(i)); htmp->SetBinError(i, h->GetBinError(i)); } //htmp->Draw(); // Fill the underflows //htmp->Fill(h->GetBinLowEdge(1)-1, h->GetBinContent(0)); // Restore the number of entries htmp->SetEntries(h->GetEntries()); /* // FillStyle and color htmp->SetFillStyle(h->GetFillStyle()); htmp->SetFillColor(h->GetFillColor()); */ return htmp; //return h; }
void bichdX() { if (gClassTable->GetID("StBichsel") < 0) { // gSystem->Load("libStar"); // gSystem->Load("St_base"); // gSystem->Load("StarClassLibrary"); gSystem->Load("StBichsel"); } if (!m_Bichsel) m_Bichsel = Bichsel::Instance(); TCanvas *c1 = new TCanvas("c1"); c1->SetLogx(); c1->SetLogy(); // TH1F *hr = c1->DrawFrame(2.e-2,1,1.e3,1.e2); // TH1F *hr = c1->DrawFrame(1.e-2,1,1.e3,1.e2); TH1F *hr = c1->DrawFrame(1.e-1,1,1.e4,2.e2); // hr->SetXTitle("Momentum (GeV/c)"); hr->SetTitle("dE/dx Bichsel predictions for different dX"); hr->SetXTitle("#beta#gamma "); hr->SetYTitle("dE/dx (keV/cm)"); // Mass Type Length log2(dx) Double_t params[4] = { 1.0, 0., 60., 1.}; TLegend *leg = new TLegend(0.72,0.7,0.9,0.9,"");//TLegend(0.79,0.91,0.89,0.89,""); Int_t h = 0; // for (Int_t f = 0; f< NF; f++) { for (Int_t f = 5; f <= 5; f++) { Int_t icol = 2; for (Int_t dx = 0; dx < Nlog10dx; dx++) { params[3] = log10dx[dx]; Char_t *FunName = Form("%s%s%i",FNames[f],Names[h],dx); TF1 *func = func = new TF1(FunName,Rbichsel70,1.e-1,1.e4,4); if (! func) continue; func->SetLineColor(icol); // func->SetLineStyle(f+1); icol++; if (icol == 5) icol++; func->SetParameters(params); func->Draw("same"); leg->AddEntry(func,Form("%s dX = %4.1f (cm)",FNames[f],TMath::Power(2.,params[3])),"L"); } } leg->Draw(); }
//void plot_Asymptotic(string outputname) //void plot_Asymptotic() TGraphAsymmErrors * plot_Asymptotic(TString dir_path ,TGraphAsymmErrors *grmedian_cls ) //void plot_Asymptotic( TGraphAsymmErrors *grmedian_cls ) { string outputname = "counting"; bool useNewStyle = true; if (useNewStyle) setFPStyle(); // gROOT->LoadMacro("CMS_lumi.C"); TFile *fFREQ[nXm]; TTree *t[nXm]; // int Xmass[nXm]={800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000}; int Xmass[nXm]={800,1000,1200,1400,1600,1800,2000,2500,3000,3500,4000}; //int Xmass[nXm]={800,900,1100,1400,1700,1900}; vector<double> v_mh, v_median, v_68l, v_68h, v_95l, v_95h, v_obs; for(int n=0;n<nXm;n++) { char limitfile[200]; // if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]); if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]); // const string dirLimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"; TString LimitFile = limitfile; LimitFile = dir_path + LimitFile; // LimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/" + LimitFile; // limitfile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/" + limitfile; // limitfile = dirLimitFile + limitfile; // fFREQ[n] = new TFile(limitfile, "READ"); fFREQ[n] = new TFile( LimitFile , "READ"); cout<<" Read limit file: "<<limitfile<<endl; t[n] = (TTree*)fFREQ[n]->Get("limit"); double mh, limit; float quant; t[n]->SetBranchAddress("mh", &mh); t[n]->SetBranchAddress("limit", &limit); t[n]->SetBranchAddress("quantileExpected", &quant); //int iMH = 0; //while (iMH < n) { for (int i = 0; i < t[n]->GetEntries(); i++) { t[n]->GetEntry(i); cout<<" quant : "<<quant<<" limit : " <<limit<<endl; /// Map: mh --> observed, 95low, 68low, expected, 68hi, 95hi, xsec if (quant > -1.01 && quant < -0.99) { v_obs.push_back(limit); } else if (quant > 0.02 && quant < 0.03) { v_95l.push_back(limit); } else if (quant > 0.15 && quant < 0.17) { v_68l.push_back(limit); } else if (quant > 0.49 && quant < 0.51) { v_median.push_back(limit); v_mh.push_back(mh); } else if (quant > 0.83 && quant < 0.85) { v_68h.push_back(limit); } else if (quant > 0.965 && quant < 0.98) { v_95h.push_back(limit); } else { cout << "Error! Quantile = " << quant << endl; } } // iMH++; // }//end while loop }//file loop // string xsect_file_th = dirXSect + "13TeV_xsec_Zhllbb.txt"; string xsect_file_th = dirXSect + "13TeV_xsec_Zh.txt"; ifstream xsect_file(xsect_file_th.c_str(), ios::in); if (! xsect_file.is_open()) { cout << "Failed to open file with xsections: " << xsect_file_th << endl; } float mH, CS; vector<float> v_mhxs, v_xs, v_toterrh, v_toterrl; while (xsect_file.good()) { xsect_file >> mH >> CS; v_mhxs.push_back(mH); v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !) //unavailable theory errors for graviton float tot_err_p = 0.0; float tot_err_m = 0.0; v_toterrh.push_back(1.0 + (tot_err_p)); v_toterrl.push_back(1.0 - (tot_err_m)); } cout << "Size of theory xsects vector" << v_mhxs.size() << endl; xsect_file.close(); /////////////////////////// // END THEORY INPUT PART // /////////////////////////// /// Here we multiply the limits in terms of signal strength by the cross-section. /// There are also some hooks to exclude sick mass points. double mass[nXm], obs_lim_cls[nXm]; double medianD[nXm]; double up68err[nXm], down68err[nXm], up95err[nXm], down95err[nXm]; double xs[nXm], xs_uperr[nXm], xs_downerr[nXm]; double xs10[nXm], xs10_uperr[nXm], xs10_downerr[nXm]; int nMassEff = 0; for (int im = 0; im < nXm; im++) { double fl_xs = double(v_xs.at(im)); //*1000.0 double fl_xs10 = 0;//double(v_xs10.at(ind)); //*1000.0 fl_xs = (fl_xs); fl_xs10 = (fl_xs10); mass[nMassEff] = Xmass[im]; /// This is the part where we multiply the limits in terms of signal strength /// by the cross-section, in order to have limits in picobarns. //std::cerr << mass[nMassEff] << ":" << v_obs.at(im) << std::endl; obs_lim_cls[nMassEff] = v_obs.at(im) * fl_xs; medianD[nMassEff] = v_median.at(im) * fl_xs; up68err[nMassEff] = (v_68h.at(im) - v_median.at(im)) * fl_xs; down68err[nMassEff] = (v_median.at(im) - v_68l.at(im)) * fl_xs; //scale factor 100 for making the xsect visible xs[nMassEff] = fl_xs; //*100.0; xs_uperr[nMassEff] = double(v_toterrh.at(im)) * xs[nMassEff] - xs[nMassEff]; xs_downerr[nMassEff] = xs[nMassEff] - double(v_toterrl.at(im)) * xs[nMassEff]; xs10[nMassEff] = fl_xs10; //*100.0; xs10_uperr[nMassEff] = double(v_toterrh.at(im)) * xs10[nMassEff] - xs10[nMassEff]; xs10_downerr[nMassEff] = xs10[nMassEff] - double(v_toterrl.at(im)) * xs10[nMassEff]; up95err[nMassEff] = (v_95h.at(im) - v_median.at(im)) * fl_xs; down95err[nMassEff] = (v_median.at(im) - v_95l.at(im)) * fl_xs; cout<<"fl_xs:"<<fl_xs<<" v_obs"<<v_obs.at(im)<<" obs_lim_cls: "<<obs_lim_cls[nMassEff] <<medianD[nMassEff] <<" mass: "<<mass[nMassEff]<<endl; nMassEff++; }//end loop over im (mass points) /// The TGraphs themselves. //cout<<"Working on TGraph"<<endl; TGraphAsymmErrors *grobslim_cls = new TGraphAsymmErrors(nMassEff, mass, obs_lim_cls); grobslim_cls->SetName("LimitObservedCLs"); // TGraphAsymmErrors *grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD); grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD); grmedian_cls->SetName("LimitExpectedCLs"); TGraphAsymmErrors *gr68_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down68err, up68err); gr68_cls->SetName("Limit68CLs"); TGraphAsymmErrors *gr95_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down95err, up95err); gr95_cls->SetName("Limit95CLs"); // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr); TGraph *grthSM=new TGraph(nMassEff,mass,xs);//xs_downerr,xs_uperr); /// For the time being we have to do it like this, given that /// the cards and the limits were made with the old, wrong xsects. // TGraph *grthSM10 = new TGraph(35); // grthSM10->SetPoint(0, 600, 7.1185E-03); // grthSM10->SetPoint(1, 650, 4.1893E-03); // grthSM10->SetPoint(2, 700, 2.5592E-03); // grthSM10->SetPoint(3, 750, 1.6182E-03); // grthSM10->SetPoint(4, 800, 1.0564E-03); // grthSM10->SetPoint(5, 850, 7.0295E-04); // grthSM10->SetPoint(6, 900, 4.7877E-04); // grthSM10->SetPoint(7, 950, 3.3017E-04); // grthSM10->SetPoint(8, 1000, 2.3212E-04); // grthSM10->SetPoint(9, 1050, 1.6574E-04); // grthSM10->SetPoint(10, 1100, 1.1917E-04); // grthSM10->SetPoint(11, 1150, 8.6629E-05); // grthSM10->SetPoint(12, 1200, 6.3987E-05); // grthSM10->SetPoint(13, 1250, 4.7353E-05); // grthSM10->SetPoint(14, 1300, 3.5511E-05); // grthSM10->SetPoint(15, 1350, 2.6631E-05); // grthSM10->SetPoint(16, 1400, 2.0199E-05); // grthSM10->SetPoint(17, 1450, 1.5333E-05); // grthSM10->SetPoint(18, 1500, 1.1758E-05); // grthSM10->SetPoint(19, 1550, 9.0363E-06); // grthSM10->SetPoint(20, 1600, 6.9870E-06); // grthSM10->SetPoint(21, 1650, 5.4316E-06); // grthSM10->SetPoint(22, 1700, 4.2252E-06); // grthSM10->SetPoint(23, 1750, 3.3172E-06); // grthSM10->SetPoint(24, 1800, 2.6083E-06); // grthSM10->SetPoint(25, 1850, 2.0499E-06); // grthSM10->SetPoint(26, 1900, 1.6186E-06); // grthSM10->SetPoint(27, 1950, 1.2799E-06); // grthSM10->SetPoint(28, 2000, 1.0205E-06); // grthSM10->SetPoint(29, 2050, 8.0867E-07); // grthSM10->SetPoint(30, 2100, 6.4555E-07); // grthSM10->SetPoint(31, 2150, 5.1755E-07); // grthSM10->SetPoint(32, 2200, 4.1408E-07); // grthSM10->SetPoint(33, 2250, 3.3170E-07); // grthSM10->SetPoint(34, 2300, 2.6637E-07); // grthSM10->SetPoint(35, 2350, 2.1366E-07); // grthSM10->SetPoint(36, 2400, 1.7285E-07); // grthSM10->SetPoint(37, 2450, 1.3896E-07); // grthSM10->SetPoint(38, 2500, 1.1238E-07); // if (!isZZChannel) { // grthSM10->SetPoint(0, 800, 2.0523E-03); // grthSM10->SetPoint(1, 850, 1.3726E-03); // grthSM10->SetPoint(2, 900, 9.3786E-04); // grthSM10->SetPoint(3, 950, 6.4928E-04); // grthSM10->SetPoint(4, 1000, 4.5618E-04); // grthSM10->SetPoint(5, 1050, 3.2571E-04); // grthSM10->SetPoint(6, 1100, 2.3543E-04); // grthSM10->SetPoint(7, 1150, 1.7157E-04); // grthSM10->SetPoint(8, 1200, 1.2611E-04); // grthSM10->SetPoint(9, 1250, 9.3461E-05); // grthSM10->SetPoint(10, 1300, 6.9899E-05); // grthSM10->SetPoint(11, 1350, 5.2749E-05); // grthSM10->SetPoint(12, 1400, 4.0048E-05); // grthSM10->SetPoint(13, 1450, 3.0363E-05); // grthSM10->SetPoint(14, 1500, 2.3324E-05); // grthSM10->SetPoint(15, 1550, 1.8008E-05); // grthSM10->SetPoint(16, 1600, 1.3876E-05); // grthSM10->SetPoint(17, 1650, 1.0812E-05); // grthSM10->SetPoint(18, 1700, 8.4385E-06); // grthSM10->SetPoint(19, 1750, 6.5972E-06); // grthSM10->SetPoint(20, 1800, 5.1608E-06); // grthSM10->SetPoint(21, 1850, 4.0824E-06); // grthSM10->SetPoint(22, 1900, 3.2292E-06); // grthSM10->SetPoint(23, 1950, 2.5502E-06); // grthSM10->SetPoint(24, 2000, 2.0281E-06); // grthSM10->SetPoint(25, 2050, 1.6179E-06); // grthSM10->SetPoint(26, 2100, 1.2893E-06); // grthSM10->SetPoint(27, 2150, 1.0313E-06); // grthSM10->SetPoint(28, 2200, 8.2293E-07); // grthSM10->SetPoint(29, 2250, 6.6187E-07); // grthSM10->SetPoint(30, 2300, 5.3108E-07); // grthSM10->SetPoint(31, 2350, 4.2755E-07); // grthSM10->SetPoint(32, 2400, 3.4315E-07); // grthSM10->SetPoint(33, 2450, 2.7803E-07); // grthSM10->SetPoint(34, 2500, 2.2432E-07); // } grthSM->SetName("SMXSection"); // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0); TGraph *grthSM10=new TGraph(nMassEff,mass,xs10); // TGraph *grthSM = new TGraph(35); // grthSM->SetPoint(0, 600, 4.4387E-02); // grthSM->SetPoint(1, 650, 2.6088E-02); // grthSM->SetPoint(2, 700, 1.5907E-02); // grthSM->SetPoint(3, 750, 1.0045E-02); // grthSM->SetPoint(4, 800, 6.5582E-03); // grthSM->SetPoint(5, 850, 4.3560E-03); // grthSM->SetPoint(6, 900, 2.9701E-03); // grthSM->SetPoint(7, 950, 2.0553E-03); // grthSM->SetPoint(8, 1000, 1.4410E-03); // grthSM->SetPoint(9, 1050, 1.0283E-03); // grthSM->SetPoint(10, 1100, 7.3979E-04); // grthSM->SetPoint(11, 1150, 5.4086E-04); // grthSM->SetPoint(12, 1200, 3.9717E-04); // grthSM->SetPoint(13, 1250, 2.9347E-04); // grthSM->SetPoint(14, 1300, 2.1957E-04); // grthSM->SetPoint(15, 1350, 1.6507E-04); // grthSM->SetPoint(16, 1400, 1.2514E-04); // grthSM->SetPoint(17, 1450, 9.5937E-05); // grthSM->SetPoint(18, 1500, 7.3300E-05); // grthSM->SetPoint(19, 1550, 5.6376E-05); // grthSM->SetPoint(20, 1600, 4.3715E-05); // grthSM->SetPoint(21, 1650, 3.3834E-05); // grthSM->SetPoint(22, 1700, 2.6389E-05); // grthSM->SetPoint(23, 1750, 2.0691E-05); // grthSM->SetPoint(24, 1800, 1.6259E-05); // grthSM->SetPoint(25, 1850, 1.2809E-05); // grthSM->SetPoint(26, 1900, 1.0131E-05); // grthSM->SetPoint(27, 1950, 8.0235E-06); // grthSM->SetPoint(28, 2000, 6.3711E-06); // grthSM->SetPoint(29, 2050, 5.0725E-06); // grthSM->SetPoint(30, 2100, 4.0513E-06); // grthSM->SetPoint(31, 2150, 3.2469E-06); // grthSM->SetPoint(32, 2200, 2.6006E-06); // grthSM->SetPoint(33, 2250, 2.0899E-06); // grthSM->SetPoint(34, 2300, 1.6810E-06); // grthSM->SetPoint(35, 2350, 1.3586E-06); // grthSM->SetPoint(36, 2400, 1.0964E-06); // grthSM->SetPoint(37, 2450, 8.8416E-07); // grthSM->SetPoint(38, 2500, 7.1662E-07); // if (!isZZChannel) { // grthSM->SetPoint(0, 800, 1.2713E-02); // grthSM->SetPoint(1, 850, 8.5015E-03); // grthSM->SetPoint(2, 900, 5.8030E-03); // grthSM->SetPoint(3, 950, 4.0261E-03); // grthSM->SetPoint(4, 1000, 2.8289E-03); // grthSM->SetPoint(5, 1050, 2.0214E-03); // grthSM->SetPoint(6, 1100, 1.4580E-03); // grthSM->SetPoint(7, 1150, 1.0625E-03); // grthSM->SetPoint(8, 1200, 7.8079E-04); // grthSM->SetPoint(9, 1250, 5.7987E-04); // grthSM->SetPoint(10, 1300, 4.3448E-04); // grthSM->SetPoint(11, 1350, 3.2719E-04); // grthSM->SetPoint(12, 1400, 2.4778E-04); // grthSM->SetPoint(13, 1450, 1.8896E-04); // grthSM->SetPoint(14, 1500, 1.4543E-04); // grthSM->SetPoint(15, 1550, 1.1200E-04); // grthSM->SetPoint(16, 1600, 8.6492E-05); // grthSM->SetPoint(17, 1650, 6.7405E-05); // grthSM->SetPoint(18, 1700, 5.2283E-05); // grthSM->SetPoint(19, 1750, 4.1121E-05); // grthSM->SetPoint(20, 1800, 3.2378E-05); // grthSM->SetPoint(21, 1850, 2.5507E-05); // grthSM->SetPoint(22, 1900, 2.0215E-05); // grthSM->SetPoint(23, 1950, 1.6020E-05); // grthSM->SetPoint(24, 2000, 1.2714E-05); // grthSM->SetPoint(25, 2050, 1.0133E-05); // grthSM->SetPoint(26, 2100, 8.0785E-06); // grthSM->SetPoint(27, 2150, 6.4583E-06); // grthSM->SetPoint(28, 2200, 5.1774E-06); // grthSM->SetPoint(29, 2250, 4.1620E-06); // grthSM->SetPoint(30, 2300, 3.3440E-06); // grthSM->SetPoint(31, 2350, 2.7018E-06); // grthSM->SetPoint(32, 2400, 2.1753E-06); // grthSM->SetPoint(33, 2450, 1.7626E-06); // grthSM->SetPoint(34, 2500, 1.4225E-06); // } grthSM10->SetName("SMXSection_2nd"); // double fr_left = 590.0, fr_down = 1E-5, fr_right = 2000.0, fr_up = 0.5; // double fr_left = 590.0, fr_down = 5E-5, fr_right = 2000.0, fr_up = 5; double fr_left = 500.0, fr_down = 5E-7, fr_right = 4500.0, fr_up = 5E-1; TCanvas *cMCMC = new TCanvas("c_lim_Asymptotic", "canvas with limits for Asymptotic CLs", 630, 600); cMCMC->cd(); cMCMC->SetGridx(1); cMCMC->SetGridy(1); // draw a frame to define the range TH1F *hr = cMCMC->DrawFrame(fr_left, fr_down, fr_right, fr_up, ""); TString VV = "ZH"; hr->SetXTitle("M_{X} [GeV]"); hr->SetYTitle("#sigma_{95%} [pb]"); // #rightarrow 2l2q gr95_cls->SetFillColor(kYellow); gr95_cls->SetFillStyle(1001);//solid gr95_cls->SetLineStyle(kDashed); gr95_cls->SetLineWidth(3); gr95_cls->GetXaxis()->SetTitle("M_{V'} [GeV]"); gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q gr95_cls->GetXaxis()->SetRangeUser(fr_left, fr_right); // gr95_cls->Draw("3"); gr68_cls->SetFillColor(kGreen); gr68_cls->SetFillStyle(1001);//solid gr68_cls->SetLineStyle(kDashed); gr68_cls->SetLineWidth(3); // gr68_cls->Draw("3same"); grmedian_cls->GetXaxis()->SetTitle("M_{V'} [GeV]"); grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q grmedian_cls->SetMarkerStyle(24);//25=hollow squre grmedian_cls->SetMarkerColor(kBlack); grmedian_cls->SetLineStyle(2); grmedian_cls->SetLineWidth(3); grmedian_cls->SetMinimum(0.0); grmedian_cls->SetMaximum(8.0); grobslim_cls->SetMarkerColor(kBlack); grobslim_cls->SetMarkerStyle(21);//24=hollow circle grobslim_cls->SetMarkerSize(1.0); grobslim_cls->SetLineStyle(1); grobslim_cls->SetLineWidth(3); grthSM->SetLineColor(kRed); grthSM->SetLineWidth(2); grthSM->SetLineStyle(kSolid); grthSM->SetFillColor(kRed); grthSM->SetFillStyle(3344); grthSM10->SetLineColor(kRed); grthSM10->SetLineWidth(2); grthSM10->SetLineStyle(1); grthSM10->SetLineStyle(kDashed); grthSM10->SetFillColor(kRed); grthSM10->SetFillStyle(3344); // grthSM->Draw("L3"); grmedian_cls->Draw("L"); // grobslim_cls->Draw("LP"); /* TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ"); TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs"); TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs"); grobs_ump->SetName("LimitObs_UnmatchedPlus"); grmedian_ump->SetName("LimitExp_UnmatchedPlus"); grobs_ump->SetMarkerColor(kBlue); grobs_ump->SetLineColor(kBlue); grobs_ump->SetMarkerStyle(25); grmedian_ump->SetMarkerColor(kBlue); grmedian_ump->SetLineColor(kBlue); grmedian_ump->SetMarkerStyle(25); grobs_ump->Draw("P"); grmedian_ump->Draw("L"); */ //draw grid on top of limits gStyle->SetOptStat(0); TH1D* postGrid = new TH1D("postGrid", "", 1, fr_left, fr_right); postGrid->GetYaxis()->SetRangeUser(fr_down, fr_up); postGrid->Draw("AXIGSAME"); //more graphics TLegend *leg = new TLegend(.20, .2, .75, .35); // TLegend *leg = new TLegend(.35,.71,.90,.90); leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.03); // leg->SetBorderMode(0); leg->AddEntry(grmedian_cls, "CL_{S} Expected limit central value", "L"); // leg->AddEntry(grobslim_cls, "Frequentist CL_{S} Observed", "LP"); // leg->AddEntry(gr68_cls, "Frequentist CL_{S} Expected #pm 1#sigma", "LF"); // leg->AddEntry(gr95_cls, "Frequentist CL_{S} Expected #pm 2#sigma", "LF"); // leg->AddEntry(grthSM, "#sigma_{TH}", "L"); // leg->AddEntry(grthSM, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.50", "L"); // #rightarrow 2l2q // leg->AddEntry(grthSM10, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.20", "L"); // #rightarrow 2l2q leg->Draw(); TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.04); latex->SetTextAlign(31); latex->SetTextAlign(11); // align left // latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012"); // latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV", intLumi)); latex->DrawLatex(0.18, 0.96, "CMS preliminary 2015"); latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 13 TeV", intLumi)); // cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); char fnam[50]; //string outputname="shape2d"; //string outputname="shape1d"; //string outputname="counting"; sprintf(fnam, "XZHllbb_%s_Asymptotic.root",outputname.data() ); // cMCMC->SaveAs(fnam); //sprintf(fnam, "XZHllbb_%s_Asymptotic.eps", outputname.data()); //cMCMC->SaveAs(fnam); sprintf(fnam, "XZHllbb_%s_Asymptotic.png", outputname.data()); // cMCMC->SaveAs(fnam); //sprintf(fnam, "XZHllbb_%s_Asymptotic.pdf", outputname.data()); //cMCMC->SaveAs(fnam); gPad->SetLogy(); //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.eps", outputname.data()); //cMCMC->SaveAs(fnam); sprintf(fnam, "XZHllbb_%s_Asymptotic_log.png", outputname.data()); // cMCMC->SaveAs(fnam); //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.pdf", outputname.data()); //cMCMC->SaveAs(fnam); cMCMC->Draw(); return grmedian_cls; }//end main
void unfoldPt(int mode=0) { // Matched Tracklets TFile *inf = new TFile("match-10TeV-12.root"); TNtuple *nt = (TNtuple*)inf->FindObjectAny("nt"); // Test sample TFile *infTest = new TFile("./TrackletTree-Run123596.root"); TNtuple *ntTest = (TNtuple*)infTest->FindObjectAny("TrackletTree12"); TFile *pdfFile; if (mode==0) pdfFile = new TFile("pdf.root","recreate"); else pdfFile = new TFile("pdf.root"); double nPtBin=15; double minPt=log(0.05); double maxPt=log(10); double nDphiBin=600; double maxDphi=0.4; char* mycut = Form("abs(eta)<2&&log(pt)>%f&&log(pt)<%f",minPt,maxPt); char* mycut1=Form("abs(eta)<2&&log(pt)>%f&&log(pt)<%f&&abs(eta-eta1)<0.01&&abs(deta)<0.01",minPt,maxPt); TH2F *h; TH1F *hdphi = new TH1F("hdphi","",nDphiBin,0,maxDphi); TH1F *hdphi2; TH1F *hpt; TH1F *hptH = new TH1F("hptH","",nPtBin,minPt,maxPt); TH1F *hptUnfold = new TH1F("hptUnfold","",nPtBin,minPt,maxPt); TH1F *hptMC = new TH1F("hptMC","",nPtBin,minPt,maxPt); TH1F *hptTemp = new TH1F("hptTemp","",nPtBin,minPt,maxPt); // Delta phi as a function of matched genparticle transverse momentum TCanvas *c = new TCanvas("c","",600,600); if (mode == 0) { h = new TH2F("h","",nPtBin,minPt,maxPt,nDphiBin,0,maxDphi); hdphi2 = new TH1F("hdphiMC","",nDphiBin,0,maxDphi); hpt = new TH1F("hpt","",nPtBin,minPt,maxPt); h->SetXTitle("ln(P_{T}) GeV/c"); h->SetYTitle("|#Delta#phi|"); nt->Draw("abs(dphi):log(pt)>>h",mycut1,"col"); // used to generate pdf nt->Draw("abs(dphi)>>hdphiMC",mycut,""); nt->Draw("log(pt)>>hpt",mycut,""); h->Write(); hpt->Write(); hdphi2->Write(); } else { h = (TH2F*) pdfFile->FindObjectAny("h"); hdphi2 = (TH1F*) pdfFile->FindObjectAny("hdphiMC"); hpt = (TH1F*) pdfFile->FindObjectAny("hpt"); } // Delta phi fit TCanvas *c2 = new TCanvas("c2","",600,600); c2->SetLogy(); c2->SetLogx(); // dphi for unfolding and MC truth: ntTest->Draw("abs(dphi)>>hdphi","abs(eta1)<2&&abs(deta)<0.1","",200000); ntTest->Draw("log(pt)>>hptH",mycut,"",200000); histFunction2D *myfun = new histFunction2D(h); TF1 *test = new TF1("histFun",myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); TF1 *test2 = new TF1("histFunMC",myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); for (int i=0;i<nPtBin+1;i++) { test->SetParameter(i,1); } hdphi2->SetXTitle("|#Delta#phi|"); hdphi2->SetYTitle("Arbitrary Normalization"); hdphi2->Fit("histFunMC","M"); hdphi->SetXTitle("|#Delta#phi|"); hdphi->SetYTitle("Arbitrary Normalization"); hdphi->Fit("histFun","M"); hdphi->SetStats(0); hdphi->Draw(); for (int i=0;i<nPtBin+1;i++) { TF1 *testPlot = new TF1(Form("histFun%d",i),myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); testPlot->SetParameter(i,test->GetParameter(i)); testPlot->SetLineColor(i+2); testPlot->Draw("same"); } int total=0,totalMC=0; for (int i=0;i<nPtBin;i++){ if (test->GetParameter(i)==0) continue; hptUnfold->SetBinContent(i+1,fabs(test->GetParameter(i))); hptUnfold->SetBinError(i+1,test->GetParError(i)); hptMC->SetBinContent(i+1,fabs(test2->GetParameter(i))); hptMC->SetBinError(i+1,test2->GetParError(i)); total+=fabs(test->GetParameter(i)); totalMC+=fabs(test2->GetParameter(i)); } hptUnfold->SetEntries(total); hptMC->SetEntries(totalMC); TCanvas *c3 = new TCanvas("c3","",600,600); hpt->Sumw2(); hptH->Sumw2(); //hptMC->Sumw2(); double normMC=0; double norm=0; double normTruth=0; hptUnfold->SetMarkerColor(2); hptUnfold->SetMarkerStyle(4); // hptUnfold->Scale(1./hptUnfold->GetEntries()); TH1F *hptCorrected = (TH1F*)hptUnfold->Clone(); hptCorrected->SetName("hptCorrected"); hptMC->Divide(hpt); hptCorrected->Divide(hptMC); for (int i=0;i<nPtBin;i++){ if (hptMC->GetBinContent(i)<=0.001)hptCorrected->SetBinContent(i,0); } hptCorrected->Scale(1./(hptCorrected->GetSum())); hptCorrected->SetMarkerStyle(20); hpt->Scale(1./hpt->GetEntries()); if (hptH->GetEntries())hptH->Scale(1./hptH->GetEntries()); hptTemp->SetXTitle("ln(P_{T}) GeV/c"); hptTemp->SetYTitle("Arbitrary Normalization"); hptTemp->Draw(); hptH->SetXTitle("ln(P_{T}) GeV/c"); hptH->SetYTitle("Arbitrary Normalization"); hptH->Draw("hist"); hptH->SetLineColor(4); hpt->Draw("hist same "); hptCorrected->Draw("same"); TH1F *hptUnfoldRatio = (TH1F*)hptUnfold->Clone(); hptUnfoldRatio->SetName("hptUnfoldRatio"); hptUnfoldRatio->Scale(1./hptUnfoldRatio->GetSum()); //hptUnfoldRatio->Divide(hptH); TH1F *hptCorrectedRatio = (TH1F*)hptCorrected->Clone(); hptCorrectedRatio->SetName("hptCorrectedRatio"); hptCorrectedRatio->SetMarkerColor(2); //hptCorrectedRatio->Divide(hptH); TCanvas *c4 = new TCanvas("c4","",600,600); TLine *l = new TLine(-2.5,1,2.5,1); hptUnfoldRatio->Draw(); hptMC->Draw("same"); hptCorrectedRatio->Draw("same"); l->Draw("same"); }
//___________________________________________________________________________ Double_t* Ifit(int shift, Double_t& dataResult, Double_t& dataErr, std::string dataFile, TH1D* hsig, TH1D* hbkg, TH1D* hEGdata, Double_t* FitPar, int ptbin=30, char EBEE[10]="EB", int fit_data=2) { printf(" *** calling Ifit for %s , ptbin %d *** \n\n", EBEE,ptbin); cout << "The number of bins are: " << endl; cout << "hdata nbins = " << hEGdata->GetNbinsX() << endl; cout << "hsig nbins = " << hsig->GetNbinsX() << endl; cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl; TCanvas *c1 = new TCanvas("HF1", "Histos1", 0, 0, 600, 600); gStyle->SetOptFit(0); if(fit_data != 3) dataColl.clear(); sigColl.clear(); bkgColl.clear(); totalColl.clear(); ctauColl.clear(); Para.clear(); Para_err.clear(); info.clear(); info_err.clear(); float ptmax=0.; if(ptbin== 21) ptmax= 23; if(ptbin== 23) ptmax= 26; if(ptbin== 26) ptmax= 30; if(ptbin== 30) ptmax= 35; if(ptbin== 35) ptmax= 40; if(ptbin== 40) ptmax= 45; if(ptbin== 45) ptmax= 50; if(ptbin== 50) ptmax= 60; if(ptbin== 60) ptmax= 85; if(ptbin== 85) ptmax= 120; if(ptbin== 120) ptmax= 300; if(ptbin== 300) ptmax= 500; Double_t* fitted = new Double_t[6]; fitted[0] = 0.; fitted[1] = 0.; fitted[2] = 0.; fitted[3] = 0.; fitted[4] = 0.; fitted[5] = 0.; char hname[30]; hsig->SetLineColor(1); hbkg->SetLineColor(1); hsig->SetNdivisions(505,"XY"); hbkg->SetNdivisions(505,"XY"); hsig->SetTitle(""); hbkg->SetTitle(""); hsig->SetXTitle("combined ISO (GeV)"); hbkg->SetXTitle("combined ISO (GeV)"); TH1F *hsum = (TH1F*)hsig->Clone(); hsum->Add(hbkg,1); float ntemplate = 1.; if (hsum->Integral()>1.) ntemplate = hsum->Integral(); float sigfrac = hsig->Integral()/ntemplate*0.8; TH1F *hsum_norm = (TH1F*)hsum->Clone(); hsum_norm->Scale(1./hsum->Integral()); TH1F *hdata = new TH1F(); int ndata=0; if ( fit_data==1 ) { hdata = (TH1F*)hEGdata->Clone(); ndata = (int)hdata->Integral(); for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){ for(int ipoint=0; ipoint<hdata->GetBinContent(ibin); ipoint++) { dataColl.push_back(hdata->GetBinCenter(ibin)); } } ndata = dataColl.size(); }else if (fit_data==2 ){ hdata = (TH1F*)hEGdata->Clone(); hdata -> Reset(); dataColl.clear(); FILE *infile = fopen(dataFile.data(),"r"); float xdata, xdata1, xdata2; // combined isolation, pt, eta int flag = 1; while (flag!=-1){ flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2); if( xdata1 >= ptbin && xdata1 < ptmax && xdata<20.) { if((strcmp(EBEE,"EB")==0 && TMath::Abs(xdata2)<1.45) || (strcmp(EBEE,"EE")==0 && TMath::Abs(xdata2)<2.5 && TMath::Abs(xdata2)>1.7) ) { dataColl.push_back(xdata); hdata->Fill(xdata); } } }// keep reading files as long as text exists ndata = dataColl.size(); printf("test print data 2 %2.3f \n", dataColl[2]); // cout << "ndata in dataColl = " << ndata << endl; if ( ndata == 0 ) { printf(" no data to fit \n"); return fitted; } } if(ndata==0) { printf(" --- no events in the fit \n"); return fitted; } //test fit the template and get PDFs TCanvas *c10 = new TCanvas("c10","c10",1000,500); c10->Divide(2,1); c10->cd(1); double par[20] = {hsig->GetMaximum(), 1., 0.6, 0.3, hbkg->GetMaximum(), -.45, -0.05, 0.03, 1., 1., 1., 1.}; if(strcmp(EBEE,"EE")==0) { par[2]=-0.1, par[3]=0.2; par[6]=-0.15; par[7]=0.02; }; int fit_status; TF1 *f1 = new TF1("f1", exp_conv, -1., 20., 11); TF1 *fmcsigfit = new TF1("fmcsigfit", exp_conv, -1., 20., 11); fmcsigfit->SetLineColor(4); fmcsigfit->SetLineWidth(2); f1->SetNpx(10000); f1->SetParameters(par); f1->SetLineWidth(2); c10->cd(1); fit_status = hsig->Fit(f1,"","",-1., 5.); hsig->Draw(); f1->Draw("same"); if ( fit_status > 0 ) { printf("fit signal template failed. QUIT \n"); return fitted; } if(para_index>0 && para_index<4){ double tmppar = f1->GetParameter(para_index); f1->SetParameter(para_index, tmppar+para_sigma*f1->GetParError(para_index)); } TF1 *fmcsig = (TF1*)f1->Clone(); TF1 *fmcsigcorr = (TF1*)f1->Clone(); fmcsig->SetNpx(10000); fmcsigcorr->SetNpx(10000); fmcsigfit->SetNpx(10000); TCanvas *c101 = new TCanvas("c101","c101",1000,500); c101->Divide(2,1); c101->cd(1); fmcsig->SetLineColor(1); // fmcsig->Draw(); // f1->Draw("same"); TH1F *htmp1 = (TH1F*)fmcsig->GetHistogram(); // TH1F *htmp2 = (TH1F*)fmcsigcorr->GetHistogram(); TH2F *htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25); htmp2->SetNdivisions(505,"XY"); htmp2->SetXTitle("Iso"); htmp2->SetYTitle("A.U."); htmp2->SetLineColor(1); // htmp2->Draw(); // htmp1->Draw("same"); // htmp2->Add(htmp1,-1); // htmp2->Divide(htmp1); htmp2->GetXaxis()->SetRangeUser(-1., 10.); htmp2->SetMinimum(-1.); //htmp2->SetMaximum(1.5); htmp2->Draw(); fmcsig->Draw("same"); // fmcsigcorr->Draw("same"); TLegend *tleg1 = new TLegend(0.5, 0.7, 0.93, 0.92); tleg1->SetHeader(""); tleg1->SetFillColor(0); tleg1->SetShadowColor(0); tleg1->SetBorderSize(0); tleg1->AddEntry(fmcsig,"Zee data","l"); //tleg1->AddEntry(fmcsigcorr,"corrected shape","l"); tleg1->AddEntry(fmcsigfit,"shape from data","l"); tleg1->Draw(); //return fitted; SigPDFnorm = f1->Integral(-1.,20.); printf("status %d, sig area %3.3f \n", fit_status,f1->Integral(-1., 20.)); f1->SetParameter(2,f1->GetParameter(2)+0.2); f1->SetParameter(3,f1->GetParameter(3)+0.1); Para.push_back(f1->GetParameter(0)); Para.push_back(f1->GetParameter(1)); Para.push_back(f1->GetParameter(2)); Para.push_back(f1->GetParameter(3)); Para_err.push_back(f1->GetParError(0)); Para_err.push_back(f1->GetParError(1)); Para_err.push_back(f1->GetParError(2)); Para_err.push_back(f1->GetParError(3)); c10->cd(2); TF1 *fbkgfit = new TF1("fbkgfit", expinv_power, -1., 20., 11); TF1 *f3 = new TF1("f3", expinv_power, -1., 20., 11); fbkgfit->SetNpx(10000); fbkgfit->SetLineColor(4); fbkgfit->SetLineWidth(2); f3->SetNpx(10000); f3->SetLineWidth(2); f3->SetParameters(f1->GetParameters()); f3->SetParLimits(5,-5.,0.); f3->SetParLimits(6,-0.5,0.); f3->SetParLimits(7,0.001,0.2); f3->SetParLimits(8,0.5,5.); if ( strcmp(EBEE,"EB")==0 ){ // f3->FixParameter(8,1.); // f3->FixParameter(6,-0.1); f3->SetParLimits(8,1.,1.5); } float bkg_bend_power = 1.; if ( ptbin==21 ) bkg_bend_power = 4.5; if ( ptbin==23 ) bkg_bend_power = 4.; if ( ptbin==26 ) bkg_bend_power = 3.5; if ( ptbin==30 ) bkg_bend_power = 2.6; if ( ptbin==35 ) bkg_bend_power = 2.2; if ( ptbin==40 ) bkg_bend_power = 2.; if ( ptbin==45 ) bkg_bend_power = 2.; if ( ptbin==50 ) bkg_bend_power = 1.8; if ( ptbin==60 ) bkg_bend_power = 1.5; if ( ptbin==85 ) bkg_bend_power = 1.; if ( ptbin==120 ) bkg_bend_power = 1.; if ( strcmp(EBEE,"EE")==0 ){ f3->SetParameter(8,bkg_bend_power); f3->SetParLimits(8,bkg_bend_power-1., bkg_bend_power+1.); } f3->FixParameter(0,f3->GetParameter(0)); f3->FixParameter(1,f3->GetParameter(1)); f3->FixParameter(2,f3->GetParameter(2)); f3->FixParameter(3,f3->GetParameter(3)); hbkg->SetMaximum(hbkg->GetMaximum()*3.); fit_status = hbkg->Fit(f3,"b","",-1., 20.); hbkg->Draw(); if ( fit_status > 0 ) { printf("fit background template failed. QUIT \n"); return fitted; }else { f3->Draw("same"); } TF1 *fmcbkg = (TF1*)f3->Clone(); fmcbkg->SetLineColor(1); c101->cd(2); htmp1 = (TH1F*)fmcbkg->GetHistogram(); htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25); htmp2->SetNdivisions(505,"XY"); htmp2->SetXTitle("Iso"); htmp2->SetYTitle("A.U."); htmp2->SetLineColor(1); htmp2->GetXaxis()->SetRangeUser(-1., 20.); htmp2->SetMinimum(-1.); htmp2->SetMaximum(1.5); htmp2->Draw(); fmcbkg->Draw("same"); TLegend *tleg2 = new TLegend(0.25, 0.2, 0.6, 0.42); tleg2->SetHeader(""); tleg2->SetFillColor(0); tleg2->SetShadowColor(0); tleg2->SetBorderSize(0); if ( strcmp(EBEE,"EB")==0 ){ tleg2->AddEntry(fmcbkg,"MC shape","l"); }else { tleg2->AddEntry(fmcbkg,"Data SB shape","l"); } tleg2->AddEntry(fbkgfit,"shape from data","l"); tleg2->Draw(); if(para_index>4){ double tmppar = f3->GetParameter(para_index); f3->SetParameter(para_index, tmppar+para_sigma*f3->GetParError(para_index)); } // f3->SetParameter(5,-0.5); // f3->SetParameter(6,-0.05); // f3->SetParameter(7,0.02); // f3->SetParameter(8,1.); Para.push_back(f3->GetParameter(4)); Para.push_back(f3->GetParameter(5)); Para.push_back(f3->GetParameter(6)); Para.push_back(f3->GetParameter(7)); Para.push_back(f3->GetParameter(8)); Para_err.push_back(f3->GetParError(4)); Para_err.push_back(f3->GetParError(5)); Para_err.push_back(f3->GetParError(6)); Para_err.push_back(f3->GetParError(7)); Para_err.push_back(f3->GetParError(8)); BkgPDFnorm = f3->Integral(-1., 20.); printf("status %d, bkg area %3.3f \n", fit_status,f3->Integral(-1., 20.)/hdata->GetBinWidth(2)); //test PDFs TCanvas *c11 = new TCanvas("c11","c11",1000,500); c11->Divide(2,1); c11->cd(1); TF1 *f11 = new TF1("f11",exp_conv_norm, -1., 20., 11); f11->SetNpx(10000); f11->SetParameters(f3->GetParameters()); f11->Draw(); printf(" SIG PDF area %2.3f \n", f11->Integral(-1., 20.)); c11->cd(2); TF1 *f12 = new TF1("f12",expinv_power_norm, -1., 20., 11); f12->SetNpx(10000); f12->SetParameters(f3->GetParameters()); f12->Draw(); printf(" BKG PDF area %2.3f \n", f12->Integral(-1., 20.)); //c1->cd(); printf(" --------- before the fit ------------- \n"); printf("Nsig %2.3f, Nbg %2.3f, Ntemplate %3.3f \n", hsig->Integral(), hbkg->Integral(), ntemplate); printf("Purity %2.3f, init size %4.3f, fit sample size %4d\n", hsig->Integral()/hsum->Integral(), hsum->Integral(), ndata); printf(" -------------------------------------- \n"); printf( " ----- Got %d, %d, %d events for fit ----- \n ", dataColl.size(), sigColl.size(), bkgColl.size() ); //-------------------------------------------------- //init parameters for fit Double_t vstart[11] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.}; vstart[0] = sigfrac*ndata; vstart[1] = (1-sigfrac)*ndata; for (int ii=0; ii<9; ii++) { vstart[ii+2] = Para[ii]; //8 shape parameters } TMinuit *gMinuit = new TMinuit(NPAR); gMinuit->Command("SET STR 1"); gMinuit->SetFCN(fcn); Double_t arglist[11]; Int_t ierflg = 0; arglist[0] = 1; gMinuit->mnexcm("SET ERR", arglist ,1,ierflg); arglist[0] = 1; gMinuit->mnexcm("SET PRINT", arglist ,1,ierflg); Double_t step[] = { 1.,1.,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,}; for ( int ii=0; ii<9; ii++){ printf(" para %d, %.5f, err %.5f \n", ii, Para[ii], Para_err[ii]); } float sigma = 3.; gMinuit->mnparm(0, "Signal yield" , vstart[0], step[0], 0., ndata*2. , ierflg); gMinuit->mnparm(1, "background yield" , vstart[1], step[1], 0., ndata*2. , ierflg); // gMinuit->mnparm(2, "constant" , Para[0], 0.00, Para[0], Para[0] , ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], 0.01, Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], 0.01, Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], 0.01, Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg); // gMinuit->mnparm(6, "constant" , Para[4], 0.00, Para[4] , Para[4] , ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], 0.01, Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], 0.01, Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], 0.01, 0.001 , 0.1 , ierflg); // // gMinuit->mnparm(10, "bg bend power", Para[8], 0.01, Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], 0.01, 0.5 , 5. , ierflg); // gMinuit->mnparm(2, "constant" , Para[0], TMath::Abs(Para[0]*0.0) , Para[0], Para[0], ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.01) , Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.1) , 0.8 , 1.3 , ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], TMath::Abs(Para[2]*0.1) , 0.5 , 1.0 , ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], TMath::Abs(Para[3]*0.1) , 0.25 , 0.5 , ierflg); // gMinuit->mnparm(6, "constant" , Para[4], TMath::Abs(Para[4]*0.0) , Para[4], Para[4], ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.1) , -0.7 , -0.3 , ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], TMath::Abs(Para[6]*0.0) , -0.15 , -0.05 , ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) , 0.01 , 0.05 , ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) , 0.5 , 1.5 , ierflg); gMinuit->mnparm(2, "constant" , Para[0], 0.00, Para[0], Para[0] , ierflg); gMinuit->mnparm(3, "exp tail" , Para[1], 0.00, Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); gMinuit->mnparm(4, "exg mean" , Para[2], 0.00, Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg); gMinuit->mnparm(5, "exg width" , Para[3], 0.00, Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg); gMinuit->mnparm(6, "constant" , Para[4], 0.00, Para[4] , Para[4] , ierflg); gMinuit->mnparm(7, "bg exp turnon", Para[5], 0.00, Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg); gMinuit->mnparm(8, "bg x offset ", Para[6], 0.00, Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg); gMinuit->mnparm(9, "bg bend slope", Para[7], 0.00, 0.001 , 0.1 , ierflg); gMinuit->mnparm(10, "bg bend power", Para[8], 0.00, Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg); printf(" --------------------------------------------------------- \n"); printf(" Now ready for minimization step \n --------------------------------------------------------- \n"); arglist[0] = 500; // number of iteration gMinuit->mnexcm("MIGRAD", arglist,1,ierflg); //can do scan // arglist[0] = 0; // gMinuit->mnexcm("SCAN", arglist,1,ierflg); printf (" -------------------------------------------- \n"); printf("Finished. ierr = %d \n", ierflg); double para[NPAR+1],errpara[NPAR+1]; double tmp_errpara[NPAR+1]; for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j]=0.1; } for(int j=2; j<=NPAR-1;j++) { if(Para_err[j-2]!=0.) tmp_errpara[j]=TMath::Abs(Para_err[j-2]); } int ni=6; if ( strcmp(EBEE,"EE")==0 ) { ni=6; }//if(ptbin==21) ni=0;} if ( ierflg == 0 ) { for(int i=0; i<ni; i++) { float istep[10] = {0.,0.,0.,0.,0.,0.,0.}; if (i<(ni-1)) { istep[i] = 0.001; }else { for (int j=0; j<ni-1; j++) {istep[j] = 0.001;} } for(int j=0; j<=NPAR-1;j++) { gMinuit->GetParameter(j, para[j], errpara[j]); if (errpara[j] != 0. ) { tmp_errpara[j] = TMath::Abs(errpara[j]); } } if ( strcmp(EBEE,"EB")==0 ) { sigma = 10.; if ( i==(ni-1) ) { sigma=5.;istep[1]=istep[4]=0.; } if ( ptbin==21 && i==1 ){ sigma=3.; } if ( ptbin==21 && i==(ni-1) ){ sigma=20.; } if ( ptbin==23 && i==0 ){ para[7]=-0.5; } if ( ptbin==23 && i==1 ){ istep[1]=0.; istep[3]=0.01; } if ( ptbin==23 && i==3 ){ istep[1]=0.01; istep[3]=0.0; } if ( ptbin==23 && i==(ni-1) ){ sigma=20.; } if ( ptbin==26 && i==1 ){ sigma=5.; } if ( ptbin==26 && i==(ni-1) ){ sigma=20.; } if ( ptbin==30 && i==(ni-1) ){ sigma=3.; } if ( ptbin==35 && i==(ni-1) ) { sigma=10.; } if ( ptbin==40 && i==(ni-1) ) { sigma=5.; istep[4]=0.01; } if ( ptbin==45 && i==(ni-1) ) { sigma=10.; } if ( ptbin==60 && i==0 ) { para[3]=1.; para[4]=0.6; para[5]=0.32; para[7]=-0.45; para[9]=0.025; para[10] = 1.;} if ( ptbin==60 && i==(ni-1) ) { sigma=5.; istep[4]=0.01;} if ( ptbin>=85 && i==(ni-1) ){ sigma=3.; } if ( ptbin==300 ) { istep[2]=istep[3]=istep[4]=0.; }// para[7] = -5.11907e-02; istep[1]=0.; } float tmp8=0.; // if( i!= (ni-1) ) { gMinuit->mnparm(0, "Signal yield" , para[0], 1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg); gMinuit->mnparm(1, "background yield", para[1], 1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg); gMinuit->mnparm(2, "constant" , para[2], 0., para[2]-100.*tmp_errpara[2], para[2]+100.*tmp_errpara[2], ierflg); gMinuit->mnparm(6, "constant" , para[6], 0., para[6]-100.*tmp_errpara[6], para[6]+100.*tmp_errpara[6], ierflg); gMinuit->mnparm(3, "exp tail" , para[3], istep[4], para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg); gMinuit->mnparm(4, "exg mean" , para[4], istep[3], para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg); gMinuit->mnparm(5, "exg width" , para[5], istep[2], para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg); gMinuit->mnparm(7, "bg exp turnon", para[7], istep[1], para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); gMinuit->mnparm(8, "bg x offset ", para[8], tmp8 , para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg); gMinuit->mnparm(9, "bg bend slope", para[9], istep[0], para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg); float sigma10=5.; if ( para[10]-sigma10*tmp_errpara[10] < 1. )// && i!=(ni-1)) gMinuit->mnparm(10, "bg bend power", para[10], istep[0], 1., para[10]+sigma10*tmp_errpara[10], ierflg); else gMinuit->mnparm(10, "bg bend power", para[10], istep[0], para[10]-sigma10*tmp_errpara[10], para[10]+sigma10*tmp_errpara[10], ierflg); // }else { // gMinuit->mnparm(2, "constant" , Para[0], TMath::Abs(Para[0]*0.0) , Para[0], Para[0], ierflg); // //gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.01) , Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.0) , 0.8 , 1.3 , ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], TMath::Abs(Para[2]*0.1) , 0.5 , 1.0 , ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], TMath::Abs(Para[3]*0.1) , 0.25 , 0.5 , ierflg); // gMinuit->mnparm(6, "constant" , Para[4], TMath::Abs(Para[4]*0.0) , Para[4], Para[4], ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.0) , -0.7 , -0.3 , ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], TMath::Abs(Para[6]*0.0) , -0.15 , -0.05 , ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) , 0.01 , 0.05 , ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) , 0.5 , 1.5 , ierflg); // } if( ptbin >=300 ) { gMinuit->mnparm(3, "exp tail" , 1.257281, 0.0, para[1]-3.*tmp_errpara[1], para[1]+3.*tmp_errpara[1], ierflg); gMinuit->mnparm(4, "exg mean" , 0.856906, 0.0, para[2]-3.*tmp_errpara[2], para[2]+3.*tmp_errpara[2], ierflg); gMinuit->mnparm(5, "exg width" , 0.320847, 0.0, para[3]-3.*tmp_errpara[3], para[3]+3.*tmp_errpara[3], ierflg); } }else{ sigma=10.; if ( i==0 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 0.3; } if ( i==(ni-1) ) { sigma=3.;istep[1]=istep[4]=0.; } //test of not changing signal template if ( i==(ni-1) ) { istep[4]=0.;} if ( ptbin==21 && i==(ni-1) ) { sigma=20.;} if ( ptbin==23 && i==0 ) { sigma=5.;} if ( ptbin==23 && i==(ni-1) ) { sigma=10.;} if ( ptbin<30 && ptbin>21 && i==1 ){ istep[1]=0.; istep[3]=0.01; } if ( ptbin<30 && ptbin>21 && i==3 ){ istep[1]=0.01; istep[3]=0.0; } if ( ptbin==26 && i==1 ) { para[7] = -0.8; } if ( ptbin==26 && i==(ni-1) ) { sigma=10.; } if ( ptbin==30 && i==(ni-1) ) { sigma=10.; } if ( ptbin==35) {para[7] = -0.75;} if ( ptbin==40 && i==0) {para[7] = -0.65; para[10] = 2.;} if ( ptbin==45 && i==(ni-1) ) {sigma=5.;} if ( ptbin==85 && i==(ni-1) ) {sigma=10.; istep[4]=0.01;} if (ptbin >= 85 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 1.; } if ( ptbin==120 ) { para[7] = -0.615255; istep[1]=0.;} // if ( ptbin==120 && i==0 ) { // para[3] = 1.446454; para[4]=-0.016373; para[5]=0.163238; // istep[2]=istep[3]=istep[4]=0.; sigma=5.; tmp_errpara[10]=0.2; // } // if ( ptbin==120 && i==(ni-1) ) { istep[2]=istep[3]=istep[4]=0.; sigma=5.;} gMinuit->mnparm(0, "Signal yield" , para[0], 1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg); gMinuit->mnparm(1, "background yield", para[1], 1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg); gMinuit->mnparm(2, "constant" , para[2], 0., para[2], para[2] , ierflg); gMinuit->mnparm(6, "constant" , para[6], 0., para[6], para[6], ierflg); gMinuit->mnparm(3, "exp tail" , para[3], istep[4], para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg); gMinuit->mnparm(4, "exg mean" , para[4], istep[3], para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg); gMinuit->mnparm(5, "exg width" , para[5], istep[2], para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg); gMinuit->mnparm(7, "bg exp turnon", para[7], istep[1], para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); gMinuit->mnparm(8, "bg x offset ", para[8], 0.00, para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg); gMinuit->mnparm(9, "bg bend slope", para[9], istep[0], para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg); float minerr=1.; //if ( tmp_errpara[10] > 0.5) tmp_errpara[10] = 0.5; float sigma10=5.; if ( para[10]-sigma10*tmp_errpara[10] < 1. ) gMinuit->mnparm(10, "bg bend power", para[10], istep[0], minerr, para[10]+sigma10*tmp_errpara[10], ierflg); else gMinuit->mnparm(10, "bg bend power", para[10], istep[0], para[10]-sigma10*tmp_errpara[10], para[10]+sigma10*tmp_errpara[10], ierflg); } printf(" ************ \n"); printf(" do %d th fit \n", i); if(i==5 && dataFile.find("toy") != std::string::npos) { cout << "dataResult = " << dataResult << "\t dataErr = " << dataErr << endl; // fixed turn on at +- 1 sigma gMinuit->mnparm(7, "bg exp turnon", dataResult-(float)shift*dataErr, 0.00, para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); } else if(dataFile.find("toy") == std::string::npos) { dataResult = para[7]; dataErr = tmp_errpara[7]; } arglist[0] = 500; // number of iteration gMinuit->mnexcm("MIGRAD", arglist ,1,ierflg); if ( ierflg != 0 ) { printf("fit failed at %d iteration \n", i); c1->cd(); c1->Draw(); hdata->Draw("phe"); return fitted; } } } Double_t amin,edm,errdef; if ( ierflg == 0 ) { for(int j=0; j<=NPAR-1;j++) { gMinuit->GetParameter(j, para[j],errpara[j]); info.push_back(para[j]); info_err.push_back(errpara[j]); printf("Parameter %d = %f +- %f\n",j,para[j],errpara[j]); } para[NPAR] = dataColl.size(); printf(" fitted yield %2.3f \n", (para[0]+para[1])/ndata ); info.push_back(sigColl.size()); for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j] = errpara[j]; if( tmp_errpara[j] == 0. ) tmp_errpara[j] = par[j]*.1; } //do minos if fit sucessed. } if (ierflg != 0 ) { printf(" *********** Fit failed! ************\n"); gMinuit->GetParameter(0, para[0],errpara[0]); gMinuit->GetParameter(1, para[1],errpara[1]); para[0]=0.; errpara[0]=0.; c1->cd(); c1->Draw(); //gPad->SetLogy(); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("comb. ISO (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.); else hdata->SetMaximum(hdata->GetMaximum()*1.25); if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.25); hdata->Draw("phe"); return fitted; } // Print results // Double_t amin,edm,errdef; Int_t nvpar,nparx,icstat; gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); gMinuit->mnprin(1,amin); gMinuit->mnmatu(1); printf(" ========= happy ending !? =========================== \n"); printf("FCN = %3.3f \n", amin); //use new PDF form double tmppar[12]; for(int ii=0; ii<9; ii++){ tmppar[ii] = para[ii+2]; fmcsigfit->SetParameter(ii,tmppar[ii]); fbkgfit->SetParameter(ii,tmppar[ii]); } c101->cd(1); //fmcsigfit->SetParameters(tmppar); //fmcsigfit->SetParameter(2,0.1); //fmcsigfit->SetLineStyle(2); fmcsigfit->Draw("same"); c101->cd(2); fbkgfit->SetParameter(4,fbkgfit->GetParameter(4)*fmcbkg->Integral(-1., 20.)/fbkgfit->Integral(-1., 20.)); fbkgfit->Draw("same"); char fname[100]; sprintf(fname,"plots/template_Ifit%s_%d.pdf",EBEE,ptbin); c101->SaveAs(fname); f11->SetParameters(tmppar); SigPDFnorm = f11->Integral(-1., 20.); f12->SetParameters(tmppar); BkgPDFnorm = f12->Integral(-1., 20.); // plot c1->cd(); c1->Draw(); //gPad->SetLogy(); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("comb. ISO (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.); else hdata->SetMaximum(hdata->GetMaximum()*1.5); if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.2); hdata->Draw("p e "); f11->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2)); // f11->SetFillColor(5); f11->SetLineColor(4); //f11->SetFillColor(603); f11->SetLineWidth(2); // f11->SetFillStyle(3001); f11->Draw("same"); f12->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2)); // f12->SetFillColor(8); f12->SetLineColor(2); //f12->SetFillColor(603); f12->SetLineWidth(2); // f12->SetFillStyle(3013); f12->Draw("same"); TF1 *f13 = new TF1("f13",sum_norm, -1., 20 ,11); f13->SetNpx(10000); f13->SetParameters(f12->GetParameters()); f13->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2)); f13->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2)); f13->SetLineWidth(2); f13->SetLineColor(1); f13->Draw("same"); f11->Draw("same"); hdata->Draw("pe same"); // cout << "The number of bins are: " << endl; // cout << "hdata nbins = " << hdata->GetNbinsX() << endl; // cout << "hsig nbins = " << hsig->GetNbinsX() << endl; // cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl; // get chi2/NDF double chi2ForThisBin=0; int nbinForThisBin=0; chi2Nbins(f13, hdata, chi2ForThisBin, nbinForThisBin); for(int epar=0; epar < 11; epar++) { // cout << "f11 parameter " << epar << " = " << // f11->GetParameter(epar) << endl; FitPar[epar] = f11->GetParameter(epar); } for(int epar=0; epar < 11; epar++) { // cout << "f12 parameter " << epar << " = " << // f12->GetParameter(epar) << endl; FitPar[epar+11] = f12->GetParameter(epar); } for(int epar=0; epar < 11; epar++) { // cout << "f13 parameter " << epar << " = " << // f13->GetParameter(epar) << endl; FitPar[epar+22] = f13->GetParameter(epar); } // cout << "hdata integral = " << hdata->Integral() << endl; // cout << endl; // printf("fit area %3.2f; sig area %3.2f; bg area %3.2f\n", f13->Integral(-1., 20.)/hdata->GetBinWidth(2), f11->Integral(-1., 20.)/hdata->GetBinWidth(2),f12->Integral(-1., 20.)/hdata->GetBinWidth(2)); // for(int i=0; i<12; i++){ // printf(" fit para %d = %4.3f \n", i, f13->GetParameter(i)); // } TLegend *tleg = new TLegend(0.5, 0.7, 0.93, 0.92); char text[50]; sprintf(text,"%s Pt %d ~ %.0f GeV",EBEE, ptbin, ptmax); tleg->SetHeader(text); tleg->SetFillColor(0); tleg->SetShadowColor(0); tleg->SetBorderSize(0); sprintf(text,"#chi^{2}/NDF = %.1f/%d",chi2ForThisBin,nbinForThisBin); tleg->AddEntry(hdata,text,""); sprintf(text,"Data %.1f events",hdata->Integral()); tleg->AddEntry(hdata,text,"pl"); sprintf(text,"Fitted %.1f events",para[0]+para[1]);//f13->Integral(-1., 20.)/hdata->GetBinWidth(2)); tleg->AddEntry(f13,text,"l"); sprintf(text,"SIG %.1f #pm %.1f events",para[0], errpara[0]); tleg->AddEntry(f11,text,"f"); sprintf(text,"BKG %.1f #pm %.1f events",para[1], errpara[1]); tleg->AddEntry(f12,text,"f"); tleg->Draw(); gPad->RedrawAxis(); printf("%s, ptbin %d, Data %.1f events \n",EBEE, ptbin, hdata->Integral()); printf("Fitted %.1f (in 5GeV) %.1f events \n",para[0]+para[1],f13->Integral(-1.,5.)); printf("SIG %.1f #pm %.1f events \n",para[0], errpara[0]); printf("SIG (in 5GeV) %.1f #pm %.1f events \n",f11->Integral(-1.,5.)/hdata->GetBinWidth(2), f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2)); printf("BKG %.1f #pm %.1f events \n",para[1], errpara[1]); printf("BKG (in 5GeV) %.1f #pm %.1f events \n",f12->Integral(-1.,5.)/hdata->GetBinWidth(2), f12->Integral(-1.,5.)*errpara[1]/para[1]/hdata->GetBinWidth(2)); float purity = f11->Integral(-1.,5.)/hdata->GetBinWidth(2)/(f11->Integral(-1.,5.)/hdata->GetBinWidth(2)+f12->Integral(-1.,5.)/hdata->GetBinWidth(2)); float purity_err = purity*errpara[0]/para[0]; printf("Purity (in 5GeV) %.3f #pm %.3f \n", purity, purity_err); // hsig->Scale(para[0]/hsig->Integral()); // hbkg->Scale(para[1]/hbkg->Integral()); // hbkg->Add(hsig); // hsig->SetLineColor(1); // hsig->SetFillColor(5); // hsig->SetFillStyle(3001); // hbkg->SetLineWidth(2); // hsig->Draw("same"); // hbkg->Draw("same"); sprintf(fname,"plots/unbinned_free_Ifit%s_%d.pdf",EBEE,ptbin); if (para_index>0) sprintf(fname,"plots/unbinned_Ifit%s_%d_para%d_sigma%1.0f.pdf",EBEE,ptbin,para_index,para_sigma); if(Opt_SavePDF == 1) { c1->SaveAs(fname); } else { c1->Close(); c10->Close(); c101->Close(); c11->Close(); } printf("----- fit results with signal projection ----------- \n"); fitted[0] = para[0]; fitted[1] = errpara[0]; fitted[2] = para[1]; fitted[3] = errpara[1]; fitted[4] = f11->Integral(-1.,5.)/hdata->GetBinWidth(2); fitted[5] = f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2); return fitted; }
void plottingmacro_IVF() { double fa = 0.46502; double fb = 0.53498; bool debug_ = true; // std::string path("Nov10thFall11Plots/"); // std::string path("Nov10Fall1160MTopSlimPlots/"); std::string path("Nov10Fall1160MTopIVFPlots_b/"); if(debug_) std::cout << "Init the style form setTDRStyle" << std::endl; setTDRStyle(); gStyle->SetErrorX(0.5); gROOT->ForceStyle(); initOptions(); if(debug_) std::cout << "Init the sample" << std::endl; // std::vector<Sample> s = Nov10thDiJetPtUpdatedSlimHistos(); //std::vector<Sample> s = Nov10Fall1160MTopSlimHistos(); std::vector<Sample> s = Nov10Fall1160MTopIVFHistos(); Sample data(1,"fake data","S1.root",0,true,1000); if(debug_) std::cout << "Init the data sample" << std::endl; for(size_t i=0;i< s.size();i++) if(s[i].data) {data=s[i];break;} if(debug_) std::cout << "Ls data sample" << std::endl; data.file()->ls(); if(debug_) std::cout << "Init the mc sample" << std::endl; for(size_t i=0;i< s.size();i++) s[i].dump(1,fa,fb); std::vector<std::string> names; if(debug_) std::cout << "Get List of Keys" << std::endl; TList * subs = data.file()->GetListOfKeys(); for(size_t i=0;i< subs->GetSize();i++) { TString nn = subs->At(i)->GetName(); if( nn.Contains(TRegexp("Count*")) ) continue; if(debug_) std::cout << "Get List of Keys in subdirs" << std::endl; TList * objs = ((TDirectoryFile *)data.file()->Get(subs->At(i)->GetName()))->GetListOfKeys(); for(size_t j=0;j< objs->GetSize();j++) { if(debug_) std::cout << "Name = " << subs->At(i)->GetName()+std::string("/") + objs->At(j)->GetName() << std::endl; names.push_back(subs->At(i)->GetName()+std::string("/") + objs->At(j)->GetName()); // std::cout << subs->At(i)->GetName() << "/" << objs->At(j)->GetName() << std::endl; //TODO: select plots via regexp } } if(debug_) std::cout << "Starting plotting" << std::endl; std::string process; for(size_t i = 0 ; i < names.size() ; i++) { std::map<std::string,TH1F *> grouped; TString n=names[i]; // if(!n.Contains(TRegexp("VlightRegionHZee/HiggsPtVlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("VlightRegionHZee/ZPtVlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("VlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZmmSV"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZeeSV"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZcombSV"))) continue; // if(!n.Contains(TRegexp("ZSVPureRegionZcombSV"))) continue; // if(!n.Contains(TRegexp("ZSVTTbarPureRegionZcombSV"))) continue; if(!n.Contains(TRegexp("TTbarRegionZeeSVJets"))) continue; if(n.Contains(TRegexp("RegionHZcomb"))) process = "Z(l^{+}l^{-})H(b#bar{b})"; if(n.Contains(TRegexp("RegionHZmm"))) process = "Z(#mu^{+}#mu^{-})H(b#bar{b})"; if(n.Contains(TRegexp("RegionHZee"))) process = "Z(e^{+}e^{-})H(b#bar{b})"; if(debug_) std::cout << "Creating the Canvas" << std::endl; TCanvas *c = new TCanvas(); c->SetLogy(false); c->SetTitle(names[i].c_str()); if(debug_) std::cout << "Creating histograms" << std::endl; TH1F *hd = ((TH1F*)data.file()->Get(names[i].c_str())); hd->Sumw2(); Options o=options[names[i]]; // hd->Rebin(o.rebin); hd->SetMarkerStyle(20); hd->GetXaxis()->SetLabelOffset(99); hd->SetYTitle(o.yaxis.c_str()); double nbin = hd->GetNbinsX(); double min_bin = hd->GetXaxis()->GetXmin(); double max_bin = hd->GetXaxis()->GetXmax(); TH1F *hmc = new TH1F("hmc","hmc", nbin, min_bin, max_bin); hmc->SetFillColor(kWhite); hmc->Sumw2(); // hmc->Rebin(o.rebin); if(debug_) std::cout << "Creating the THStack and Legend" << std::endl; THStack * sta = new THStack("sta",hd->GetTitle()); TLegend * l = new TLegend(o.legendx1,o.legendy1,o.legendx2,o.legendy2); //0.7,0.1,0.9,0.6); l->SetFillColor(kWhite); l->SetBorderSize(0); l->SetTextFont(62); l->SetTextSize(0.03); if(debug_) std::cout << "Adding data to the legend" << std::endl; l->AddEntry(hd, "Data","P"); if(debug_) std::cout << "Adding MC to the THStack" << std::endl; //with the proper trigger eff // double SF[] = {1.01,1.03,1.00}; // double SF[] = {1.03,1.054,1.032}; double SF[] = {1.0,1.0,1.0}; if(debug_){ for(int i = 0; i< 3; ++i) std::cout << "SF [" << i << "] = " << SF[i] << std::endl; } double mcIntegral=0; for(size_t j=0;j< s.size() ;j++) { if(!s[j].data) { if(debug_) std::cout << "Creating TH1F from file " << s[j].name << std::endl; TH1F * h = ((TH1F*)s[j].file()->Get(names[i].c_str())); h->Sumw2(); if(debug_){ std::cout << "TH1F created from file " << s[j].name << std::endl; std::cout << "Scaling : " << s[j].scale(data.lumi(),fa,fb) << std::endl; std::cout << "Scaling with SF : " << s[j].scale(data.lumi(),fa,fb,SF) << std::endl; std::cout << "Histo integral before scaling = " << h->Integral() << std::endl; } h->Scale(s[j].scale(data.lumi(),fa,fb,SF)); if(debug_){ std::cout << "Histo integral after scaling = " << h->Integral() << std::endl; std::cout << "Managing style... " << std::endl; } h->SetLineWidth(1.); h->SetFillColor(s[j].color); h->SetLineColor(s[j].color); // h->Rebin(options[names[i]].rebin); if(debug_) std::cout << "Cloning and update legend " << std::endl; if(grouped.find(s[j].name) == grouped.end()){ l->AddEntry(h,s[j].name.c_str(),"F"); } std::cout << "Sample : " << s[j].name << " - Integral for plot " << names[i] << " = " << h->Integral(-10000,10000) << std::endl; mcIntegral += h->Integral(); sta->Add(h); hmc->Add(h); //TO FIX grouped map // sovrascrive histo con lo stesso nome tipo VV o ST etc... grouped[s[j].name]=(TH1F *)h->Clone(("_"+names[i]).c_str()); } } if(debug_){ std::cout << "Data total = " << hd->Integral() << std::endl; std::cout << "MC = " << mcIntegral << std::endl; std::cout << "Data/MC = " << hd->Integral()/mcIntegral << std::endl; } TPad * TopPad = new TPad("TopPad","Top Pad",0.,0.3,1.,1. ) ; TPad * BtmPad = new TPad("BtmPad","Bottom Pad",0.,0.,1.,0.313 ) ; TopPad->SetBottomMargin(0.02); BtmPad->SetTopMargin(0.0); BtmPad->SetFillStyle(4000); TopPad->SetFillStyle(4000); BtmPad->SetFillColor(0); BtmPad->SetBottomMargin(0.35); TopPad->Draw() ; BtmPad->Draw() ; std::cout << "hd maximum = " << hd->GetMaximum() << " sta maximum = " << sta->GetMaximum() << std::endl; double maxY; if(hd->GetMaximum() > sta->GetMaximum()) maxY = (hd->GetMaximum())*1.5; else maxY = (sta->GetMaximum())*1.5; TopPad->cd(); hd->Draw("E1X0"); sta->Draw("sameHIST"); hmc->Draw("sameE2"); hmc->SetFillColor(2); hmc->SetMarkerSize(0); hmc->SetFillStyle(3013); hd->Draw("E1X0same"); l->Draw("same"); std::cout << "Set Maximum to = " << maxY << std::endl; hd->GetYaxis()->SetRangeUser(0.,maxY); hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max); BtmPad->cd(); std::cout << "Division" << std::endl; TH1D * divisionErrorBand = (TH1D*)(hmc)->Clone("divisionErrorBand"); divisionErrorBand->Sumw2(); divisionErrorBand->Divide(hmc); divisionErrorBand->Draw("E2"); divisionErrorBand->SetMaximum(2.49); divisionErrorBand->SetMinimum(0); divisionErrorBand->SetMarkerStyle(20); divisionErrorBand->SetMarkerSize(0.55); divisionErrorBand->GetXaxis()->SetTitleOffset(1.12); divisionErrorBand->GetXaxis()->SetLabelSize(0.12); divisionErrorBand->GetXaxis()->SetTitleSize(0.5); divisionErrorBand->GetYaxis()->SetTitle("Data/MC"); divisionErrorBand->GetYaxis()->SetLabelSize(0.12); divisionErrorBand->GetYaxis()->SetTitleSize(0.12); divisionErrorBand->GetYaxis()->SetTitleOffset(0.40); divisionErrorBand->GetYaxis()->SetNdivisions(505); //divisionErrorBand->UseCurrentStyle(); divisionErrorBand->SetFillColor(2); divisionErrorBand->SetFillStyle(3001); divisionErrorBand->SetMarkerSize(0.); TH1D * division = (TH1D*)(hd)->Clone("division"); division->Sumw2(); division->Divide(hmc); // division->SetMaximum(2.5); // division->SetMinimum(0); // division->SetMarkerStyle(20); // division->SetMarkerSize(0.55); // division->GetXaxis()->SetLabelSize(0.12); // division->GetXaxis()->SetTitleSize(0.14); // division->GetYaxis()->SetLabelSize(0.10); // division->GetYaxis()->SetTitleSize(0.10); // division->GetYaxis()->SetTitle("Data/MC"); Double_t min = division->GetXaxis()->GetXmin(); Double_t max = division->GetXaxis()->GetXmax(); division->Draw("E1X0same"); TLine *line = new TLine(min, 1.0, max, 1.0); line->SetLineColor(kRed); line->Draw("same"); TLegend * leg3 =new TLegend(0.50,0.86,0.69,0.96); leg3->AddEntry(divisionErrorBand,"MC uncert. (stat.)","f"); leg3->SetFillColor(0); leg3->SetLineColor(0); leg3->SetShadowColor(0); leg3->SetTextFont(62); leg3->SetTextSize(0.06); leg3->Draw(); TPaveText *pave = new TPaveText(0.15,0.85,0.32,0.96,"brNDC"); pave->SetTextAlign(12); pave->SetLineColor(0); pave->SetFillColor(0); pave->SetShadowColor(0); //TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",histDt->Chi2Test(histCopyMC5,"UWCHI2/NDF"),histDt->KolmogorovTest(histCopyMC5))); // stat + sys TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",hd->Chi2Test(hmc,"UWCHI2/NDF"),hd->KolmogorovTest(hmc))); // stat only text->SetTextFont(62); text->SetTextSize(0.08); pave->Draw(); TopPad->cd(); TLatex latex; latex.SetNDC(); latex.SetTextAlign(12); latex.SetTextSize(0.052); latex.DrawLatex(0.17,0.89,"CMS Preliminary"); latex.SetTextSize(0.04); latex.DrawLatex(0.17,0.84,"#sqrt{s} = 7 TeV, L = 4.7 fb^{-1}"); // latex.DrawLatex(0.17,0.79,"Z(e^{+}e^{-})H(b#bar{b})"); latex.DrawLatex(0.17,0.79,process.c_str()); c->Update(); std::string cName= hd->GetName(); cName += "_bare.pdf"; cName = path+cName; c->Print(cName.c_str(),"pdf"); // std::cout << names[i] << " d: " << hd->Integral() << " "; // THStack * sta2 = new THStack("sta2",hd->GetTitle()); // float tot=0; // float toterr2=0; // if(debug_) // std::cout << "Putting the iterator in the for loop" << std::endl; // for(std::map<std::string,TH1F *>::reverse_iterator it=grouped.rbegin(); it!=grouped.rend();++it) // { // if(debug_) // std::cout << "Using the iterator" << std::endl; // std::cout << (*it).first << " " << (*it).second->Integral() << " | " << std::endl ; // if((*it).second->GetEntries() > 0) { // float er=1.*sqrt((*it).second->GetEntries())/(*it).second->GetEntries()*(*it).second->Integral(); // toterr2+=er*er; // } // tot+=(*it).second->Integral(); // sta2->Add(it->second); // } // std::cout << " Tot: " << tot << "+-" << sqrt(toterr2) << " SF: " << hd->Integral()/tot << std::endl; // TCanvas *c2 = new TCanvas(); // c2->SetTitle(names[i].c_str()); // std::cout << "hd maximum = " << hd->GetMaximum() << " sta2 maximum = " << sta2->GetMaximum() << std::endl; // if(hd->GetMaximum() > sta2->GetMaximum()) maxY = hd->GetBinContent(hd->GetMaximumBin()) * 1.5; // else maxY = ( sta2->GetMaximum())*1.5; // // hd->Draw("E1"); // sta2->Draw("PADSHIST"); // // hd->Draw("E1same"); // // l->Draw("same"); // std::cout << "Set Maximum to = " << maxY << std::endl; // hd->GetYaxis()->SetRangeUser(0.,maxY); // hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max); // c2->Update(); // std::string c2Name = hd->GetName(); // c2Name = path+c2Name; // c2Name += "_norm.pdf"; // c2->Print(c2Name.c_str(),"pdf"); } }
void drawHFPosition(char file[100]="hf.out", int save=0) { setTDRStyle(); std::ifstream theFile(file); static const int NPMAX=20000; int etaIndex[NPMAX], phiIndex[NPMAX], depths[NPMAX], np=0; float radiusT[NPMAX], radiusH[NPMAX], phiH[NPMAX]; double deg=3.1415926/180.; while (theFile) { int ieta, iphi, idep; float etaR, rr, phideg; theFile >> ieta >> iphi >> idep >> etaR >> rr >> phideg; if (np < NPMAX) { etaIndex[np] = ieta; phiIndex[np] = iphi; depths[np] = idep; radiusT[np] = etaR; radiusH[np] = rr; if (phideg < 0) phideg += 360; int iphi = (int)(phideg/20); float phi = (phideg - iphi*20.0); if (phi > 10) phi -= 20; phiH[np] = phi*deg; np++; } } std::cout << np << " points found\n"; // for (int i=0; i<np; i++) std::cout << std::setw(4) << i << " " << std::setw(3) << etaIndex[i] << " " << std::setw(3) << phiIndex[i] << " " << depths[i] << " " << std::setw(6) << radiusT[i] << " " << std::setw(6) << radiusH[i] << " " << std::setw(6) << phiH[i] << "\n"; int symbol[14] = {20,21,22,23,24,25,26,27,28,29,30,3,5,2}; int colr[3] = {2,4,1}; TGraph *gr[3][14]; float x1[NPMAX], y1[NPMAX], x2[NPMAX], y2[NPMAX], x3[NPMAX], y3[NPMAX]; int np1, np2, np3; for (int i=0; i<13; i++) { np1 = np2 = np3 = 0; for (int j=0; j<np; j++) { if (etaIndex[j] == (i+29)) { int k = 2; if (depths[j] == 3) k = 0; else if (depths[j] == 4) k = 1; if (k == 0) { x1[np1] = radiusH[j]*cos(phiH[j]); y1[np1] = radiusH[j]*sin(phiH[j]); np1++; // if (np1 == 1) std::cout << i << " 0 " <<x1[0] << " " <<y1[0] << "\n"; } else if (k==1) { x2[np2] = radiusH[j]*cos(phiH[j]); y2[np2] = radiusH[j]*sin(phiH[j]); np2++; // if (np2 == 1) std::cout << i << " 1 " <<x2[0] << " " <<y2[0] << "\n"; } else { x3[np3] = radiusH[j]*cos(phiH[j]); y3[np3] = radiusH[j]*sin(phiH[j]); np3++; } } } // std::cout << "i " << i << " " <<np1 << " " <<np2 << " " <<np3 <<"\n"; if (np1 > 0) { gr[0][i] = new TGraph(np1,x1,y1); gr[0][i]->SetTitle(""); gr[0][i]->SetMarkerStyle(symbol[i]); gr[0][i]->SetMarkerColor(colr[0]); } else gr[0][i] = 0; if (np2 > 0) { gr[1][i] = new TGraph(np2,x2,y2); gr[1][i]->SetTitle(""); gr[1][i]->SetMarkerStyle(symbol[i]); gr[1][i]->SetMarkerColor(colr[1]); } else gr[1][i] = 0; if (np3 > 0) { gr[2][i] = new TGraph(np3,x3,y3); gr[2][i]->SetTitle(""); gr[2][i]->SetMarkerStyle(symbol[i]); gr[2][i]->SetMarkerColor(colr[2]); } else gr[2][i] = 0; } np1 = np2 = np3 = 0; for (int j=0; j<np; j++) { if (etaIndex[j] < 29 || etaIndex[j] > 41) { int k = 2; if (depths[j] == 3) k = 0; else if (depths[j] == 4) k = 1; if (k == 0) { x1[np1] = radiusH[j]*cos(phiH[j]); y1[np1] = radiusH[j]*sin(phiH[j]); np1++; if (np1 == 1) std::cout << i << " 0 " <<x1[0] << " " <<y1[0] << "\n"; } else if (k==1) { x2[np2] = radiusH[j]*cos(phiH[j]); y2[np2] = radiusH[j]*sin(phiH[j]); np2++; if (np2 == 1) std::cout << i << " 1 " <<x2[0] << " " <<y2[0] << "\n"; } else { x3[np3] = radiusH[j]*cos(phiH[j]); y3[np3] = radiusH[j]*sin(phiH[j]); np3++; } } } // std::cout << "i " << i << " " <<np1 << " " <<np2 << " " <<np3 <<"\n"; if (np1 > 0) { gr[0][13] = new TGraph(np1,x1,y1); gr[0][13]->SetTitle(""); gr[0][13]->SetMarkerStyle(symbol[13]); gr[0][13]->SetMarkerColor(colr[0]); } else gr[0][13] = 0; if (np2 > 0) { gr[1][13] = new TGraph(np2,x2,y2); gr[1][13]->SetTitle(""); gr[1][13]->SetMarkerStyle(symbol[13]); gr[1][13]->SetMarkerColor(colr[1]); } else gr[1][13] = 0; if (np3 > 0) { gr[2][13] = new TGraph(np3,x3,y3); gr[2][13]->SetTitle(""); gr[2][13]->SetMarkerStyle(symbol[13]); gr[2][13]->SetMarkerColor(colr[2]); } else gr[2][13] = 0; TCanvas *c0 = new TCanvas("c0","PMT Hits",800,600); TH1F *vFrame = c0->DrawFrame(1000.0,-250.0,1500.0,250.0); vFrame->SetXTitle("x (mm)"); vFrame->SetYTitle("y (mm)"); for (int i=0; i<=13; i++) { for (int j=0; j<3; j++) { if (gr[j][i] != 0) { gr[j][i]->Draw("p"); gr[j][i]->SetLineColor(colr[j]); gr[j][i]->SetLineWidth(2); // std::cout << "Next " << i << " " << j << "\n"; } } } TLegend *leg1 = new TLegend(0.75,0.55,0.90,0.90); char list[40]; for (i=0; i<= 13; i++) { if (i < 13) sprintf (list, "#eta = %d", i+29); else sprintf (list, "Unknown #eta"); if (gr[0][i] != 0) leg1->AddEntry(gr[0][i], list, "P"); else if (gr[1][i] != 0) leg1->AddEntry(gr[1][i], list, "P"); } for (i=0; i<2; i++) { if (i == 0) sprintf (list, "Long Fibre"); else sprintf (list, "Short Fibre"); if (gr[i][0] != 0) leg1->AddEntry(gr[i][0], list, "L"); else if (gr[i][1] != 0) leg1->AddEntry(gr[i][1], list, "L"); else if (gr[i][2] != 0) leg1->AddEntry(gr[i][2], list, "L"); } leg1->SetFillColor(0); leg1->SetTextSize(0.03); leg1->SetBorderSize(1); leg1->Draw(); if (save != 0) { if (save > 0) c0->SaveAs("PMTHits.eps"); else c0->SaveAs("PMTHits.gif"); } }
void bichseldX() { if (gClassTable->GetID("StBichsel") < 0) { gSystem->Load("libTable"); gSystem->Load("St_base"); gSystem->Load("StarClassLibrary"); gSystem->Load("StBichsel"); } if (!m_Bichsel) m_Bichsel = Bichsel::Instance(); TCanvas *c1 = new TCanvas("c1"); c1->SetLogx(); c1->SetLogy(); c1->SetGrid(); // TH1F *hr = c1->DrawFrame(2.e-2,1,1.e3,1.e2); // TH1F *hr = c1->DrawFrame(1.e-2,1,1.e3,1.e2); TH1F *hr = c1->DrawFrame(1.e-1,1,1.e2,2.e2); // hr->SetXTitle("Momentum (GeV/c)"); hr->SetTitle("dE/dx predictions"); hr->SetXTitle("#beta #gamma"); hr->SetYTitle("dE/dx (keV/cm)"); hr->Draw(); // Mass Type Length log2(dx) Double_t params[5] = { 1.0, 0., 60., 1., 1e-3}; TLegend *leg = new TLegend(0.4,0.7,0.9,0.9,"");//TLegend(0.79,0.91,0.89,0.89,""); // for (Int_t h = 0; h < 4; h++) { // Masses for (Int_t h = 2; h < 3; h++) { // Masses params[0] = 1.; // Masses[h]; params[1] = h; // for (Int_t f = 0; f < NF; f++) { // Functions Int_t f = 3; for (Int_t dx = 0; dx < Nlog2dx; dx++) { params[3] = log2dx[dx]; Char_t *FunName = Form("%s%s%i",FNames[f],Names[h],(int)log2dx[dx]); // cout << "Make " << FunName << endl; TF1 *func = 0; if (TString(FNames[f]) == "Sirrf") { func = new TF1(FunName,sifunc,1.e-2,1.e3,5); func->SetLineColor(2); } if (TString(FNames[f]) == "Girrf") { func = new TF1(FunName,gfunc,1.e-2,1.e3,5); params[4] = 1.e-3; if (dx == 1) params[4] = 1.e-2; if (dx == 2) params[4] = 1.e-3; if (dx == 3) params[4] = 1.e-4; func->SetLineColor(3); } else {if (TString(FNames[f]) == "Bz") { func = new TF1(FunName,bichselZ,1.e-2,1.e3,5); func->SetLineColor(4); } else {if (TString(FNames[f]) == "B70") { func = new TF1(FunName,bichsel70,1.e-2,1.e3,5); func->SetLineColor(6); } else {if (TString(FNames[f]) == "B60") { func = new TF1(FunName,bichsel60,1.e-2,1.e3,5); func->SetLineColor(7); }}}} if (! func) continue; func->SetParameters(params); func->SetLineColor(dx+1); func->Draw("same"); if ( h == 2) { TString name(FNames[f]); name += ": Bichsel, 30% truncation"; name += Form(" dx = %3.1f cm",TMath::Power(2.,log2dx[dx])); cout << name << endl; leg->AddEntry(func,name.Data(),"L"); } } } leg->Draw(); }
void Control_all_cut_limit_auto() { const float intLumi = 3.0; const int n_cut_index =11; // 10 TString variable_name = "Ele_1st_pt" ; cout<<"variable_name: " << variable_name << endl; // define cuts int cut_value[n_cut_index]; double lowest_cut=435 ; double scan_width = 20;// 21 for(int i=0;i<n_cut_index ;i++){ cut_value[i] = lowest_cut + scan_width*i; cout<<"cut_value[i]: "<< cut_value[i] << endl; } // //int cut_value[n_cut_index] = //{115,136,157,178,199,220,241,262,283,304}; TGraphAsymmErrors *grmedian_cls; TGraphAsymmErrors *grmedian_cls_new[n_cut_index]; const int nMassEff = 11; // # of mass point double mass[nMassEff] = {0}; double medianD[nMassEff] = {0}; grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD); // TString dir_path = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"; TString dir_path[n_cut_index] ; TString leg_name[n_cut_index] ; int nXm = nMassEff; for(int i=0;i<n_cut_index;i++){ // for(int i=0;i<5;i++){ dir_path[i] = Form("YuHsiang_DY_Ele_1st_pt_cut_%d/",cut_value[i] ) ; // dir_path[i] = Form("YuHsiang_DY_h_ele_1st_pT_cut_%d/",cut_value[i] ) ; dir_path[i] = "Datacards_text_and_ROOT_files/" + dir_path[i]; // dir_path[i] = "Datacards_txt_files/" + dir_path[i]; // if(cut_value[i]==515) {nXm = 10;} // if(cut_value[i]==615) {nXm = 10;}// lost M800 // if(cut_value[i]==715) {nXm = 10;}// lost M800 // if(cut_value[i]==815) {nXm = 8;} // if(cut_value[i]==915) {nXm = 8;} // if(cut_value[i]==1015) {nXm = 8;} if(cut_value[i]==515 || cut_value[i]==535 || cut_value[i]==555) {nXm = 10;}// lost M800 if(cut_value[i]==575 || cut_value[i]==595 || cut_value[i]==615) {nXm = 10;}// lost M800 if(cut_value[i]==635 ) {nXm = 10;}// lost M800 if(cut_value[i]==835) {nXm = 8;}// lost M800, M1000, M1200 cout<<endl; cout<<"dir_path[i]: "<< dir_path[i] <<" cut_value[i]: "<< cut_value[i]<<" nXm: "<< nXm <<endl; cout<<endl; grmedian_cls_new[i] = plot_Asymptotic( dir_path[i] ,grmedian_cls, nXm ); // leg_name[i] = Form("CL_{S} Expected Limit for cut pt>%d",cut_value[i] ) ; leg_name[i] = Form("cut pt>%d",cut_value[i] ) ; } TCanvas *c1 = new TCanvas("c1", "canvas with limits for Asymptotic CLs", 630, 600); TLegend *leg = new TLegend(.75, .35, 1., .85); leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.03); c1->SetGridx(1); c1->SetGridy(1); gPad->SetLogy(); c1->cd(); // double fr_left = 500.0, fr_down = 5E-2, fr_right = 4500.0, fr_up = 3E2; // double fr_left = 500.0, fr_down = 2E-1, fr_right = 1500.0, fr_up = 7E-1; // double fr_left = 1800.0, fr_down = 1.1E-1, fr_right = 2200.0, fr_up = 1.5E-1; double fr_left = 2800.0, fr_down = 1E-1, fr_right = 3200.0, fr_up = 1.1E-1; TH1F *hr = c1->DrawFrame(fr_left, fr_down, fr_right, fr_up, ""); int colorN = 1; // loop for(int i=0;i<n_cut_index;i++){ if (i==0){colorN = kRed;} if (i==2){colorN = kOrange;} if (i==4){colorN = kCyan;} if (i==6){colorN = kBlue;} if (i==8){colorN = kGreen;} grmedian_cls_new[i]->SetLineColor(colorN); grmedian_cls_new[i]->SetLineStyle(1); grmedian_cls_new[i]->Draw(); // leg->AddEntry(grmedian_cls_new[i], "CL_{S} Expected Limit", "L"); leg->AddEntry(grmedian_cls_new[i],leg_name[i] , "L"); leg->Draw(); colorN = colorN+2; } // end loop hr->SetXTitle("M_{Z'} [GeV]"); hr->SetYTitle("95% #sigma_{Z'}xBR(Z'->ZH) [pb]"); TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.04); latex->SetTextAlign(31); latex->SetTextAlign(11); latex->DrawLatex(0.25, 0.91, "CL_{S} Expected Limit, cut electron leading pt"); latex->DrawLatex(0.18, 0.96, "CMS preliminary 2015"); latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 13 TeV", intLumi)); TString save_name = "expected_limit_cut_"; save_name = save_name + variable_name ; TString png_name = save_name + ".png"; TString pdf_name = save_name + ".pdf"; c1->SaveAs(png_name); c1->SaveAs(pdf_name); //TString path_to_save = "/afs/cern.ch/user/y/yuchang/www/set_limit_optimize_leading_pt/" ; TString path_to_save = "/afs/cern.ch/user/y/yuchang/www/optimize_cut_with_limit_use_eleIsPassLoose/leading_pt/" ; pdf_name = path_to_save + pdf_name; c1->SaveAs( pdf_name ); }// end codes
void RAA_plot_JetID_CutEfficiency( Int_t radius = 4, char * etaWidth = (char*)"20_eta_p20"){ TH1::SetDefaultSumw2(); gStyle->SetOptStat(0); char * Coll = "PbPb"; //char * Coll = "Pp"; TDatime date; Int_t trigger[3]; if(Coll == "PbPb") {trigger[0] = 55; trigger[1] = 65; trigger[2] = 80;} if(Coll == "Pp") {trigger[0] = 40; trigger[1] = 60; trigger[2] = 80;} char * jetType; if(Coll == "PbPb") jetType = Form("akPu%dPF",radius); if(Coll == "Pp") jetType = Form("ak%dPF",radius); const int nbins_pt = 38; const double boundaries_pt[nbins_pt+1] = { 3, 4, 5, 7, 9, 12, 15, 18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 1000 }; // Pawan's files: TFile * fIn = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PbPb_data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root",etaWidth,radius)); TFile * fPP_in = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PP_data_MC_spectra_residualFactor_finebins_%s_R0p%d.root",etaWidth, radius)); // get the histograms, the Cut Efficiency is plotted from the MC histograms TH1F * hMC_noCut[3], * hMC_Cut[3], * hMC_unm_noCut[3], * hMC_unm_Cut[3]; TH1F * hMC_Denominator, *hMC_Numerator; for(int i = 0; i<3; i++){ hMC_noCut[i] = (TH1F*)fIn->Get(Form("hMC_Jet%d_noCut", trigger[i])); hMC_Cut[i] = (TH1F*)fIn->Get(Form("hMC_Jet%d_CutA", trigger[i])); hMC_unm_noCut[i] = (TH1F*)fIn->Get(Form("hMC_unmatched_Jet%d_noCut", trigger[i])); hMC_unm_Cut[i] = (TH1F*)fIn->Get(Form("hMC_unmatched_Jet%d_CutA", trigger[i])); } hMC_Denominator = (TH1F*)hMC_noCut[0]->Clone("hMC_Denominator"); hMC_Denominator->Add(hMC_noCut[1]); hMC_Denominator->Add(hMC_noCut[2]); hMC_Denominator->Add(hMC_unm_noCut[0]); hMC_Denominator->Add(hMC_unm_noCut[1]); hMC_Denominator->Add(hMC_unm_noCut[2]); hMC_Numerator = (TH1F*)hMC_Cut[0]->Clone("hMC_Numerator"); hMC_Numerator->Add(hMC_Cut[1]); hMC_Numerator->Add(hMC_Cut[2]); hMC_Numerator->Add(hMC_unm_Cut[0]); hMC_Numerator->Add(hMC_unm_Cut[1]); hMC_Numerator->Add(hMC_unm_Cut[2]); TH1F * hCutEff = (TH1F*)hMC_Numerator->Clone("hCutEff"); hCutEff->Divide(hMC_Denominator); hCutEff = (TH1F*)hCutEff->Rebin(nbins_pt, "hCutEff", boundaries_pt); divideBinWidth(hCutEff); // line at 1 TCanvas * cCutEff = new TCanvas("cCutEff","",800,600); hCutEff->SetXTitle(Form("%s Gen p_{T} (GeV/c)",jetType)); hCutEff->SetYTitle("Jet ID Cut Efficiency"); hCutEff->SetTitle(" "); hCutEff->SetAxisRange(40, 300, "X"); hCutEff->SetAxisRange(0.9, 1.05, "Y"); hCutEff->SetMarkerStyle(20); hCutEff->SetMarkerColor(kBlack); hCutEff->Draw(); putCMSPrel(); drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20); drawText(Form("%s",Coll), 0.6, 0.21, 20); cCutEff->SaveAs(Form("May20/%s_Combined_CutEfficiency_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE"); // plot the curves for the different centrality classes. get the combined spectra and do the ratio const int nbins_cent = 6; TH1F * hMC_Denominator[nbins_cent]; TH1F * hMC_Numerator[nbins_cent]; TH1F * hData_Denominator[nbins_cent]; TH1F * hData_Numerator[nbins_cent]; TH1F * hCutEff[nbins_cent]; TH1F * hCutEff_Data[nbins_cent]; TH1F * hPP_MC_Denominator = (TH1F*)fIn_PP->Get("hpp_MC_Comb_noCut"); TH1F * hPP_MC_Numerator = (TH1F*)fIn_PP->Get(Form("hpp_JetComb_gen_R%d_%s",radius,etaWidth)); TH1F * hPP_Data_Denominator = (TH1F*)fIn_PP->Get("hpp_Data_Comb_noCut"); TH1F * hPP_Data_Numerator = (TH1F*)fIn_PP->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth)); TH1F * hPP_CutEff = (TH1F*)hPP_MC_Numerator->Clone("hPP_CutEff"); hPP_CutEff->Divide(hPP_MC_Denominator); hPP_CutEff->Rebin(10); hPP_CutEff->Scale(1./10); TH1F * hPP_CutEff_Data = (TH1F*)hPP_Data_Numerator->Clone("hPP_CutEff_Data"); hPP_CutEff_Data->Divide(hPP_Data_Denominator); hPP_CutEff_Data->Rebin(10); hPP_CutEff_Data->Scale(1./10); TLine *line = new TLine(60,1,299,1); line->SetLineStyle(2); line->SetLineWidth(2); for(int i = 0; i<nbins_cent; ++i){ hMC_Denominator[i] = (TH1F*)fIn->Get(Form("hpbpb_MC_noCut_cent%d",i)); hMC_Numerator[i] = (TH1F*)fIn->Get(Form("hpbpb_gen_R%d_%s_cent%d",radius,etaWidth, i)); hData_Denominator[i] = (TH1F*)fIn->Get(Form("hpbpb_Data_Comb_noCut_cent%d",i)); hData_Numerator[i] = (TH1F*)fIn->Get(Form("hpbpb_HLTComb_R%d_%s_cent%d",radius,etaWidth,i)); hCutEff[i] = (TH1F*)hMC_Numerator[i]->Clone(Form("CutEff_cent%d",i)); hCutEff[i]->Divide(hMC_Denominator[i]); hCutEff[i]->Rebin(20); hCutEff[i]->Scale(1./20); hCutEff_Data[i] = (TH1F*)hData_Numerator[i]->Clone(Form("CutEff_Data_cent%d",i)); hCutEff_Data[i]->Divide(hData_Denominator[i]); hCutEff_Data[i]->Rebin(20); hCutEff_Data[i]->Scale(1./20); } TCanvas * cCutEff = new TCanvas("cCutEff","",800,600); makeMultiPanelCanvas(cCutEff,3,2,0.0,0.0,0.2,0.15,0.07); for(int i = 0; i<nbins_cent; ++i){ cCutEff->cd(nbins_cent-i); hCutEff[i]->SetXTitle(Form("akPu%dPF Gen p_{T} (GeV/c)", radius)); hCutEff[i]->SetYTitle("Jet ID Cut Efficiency"); hCutEff[i]->SetTitle(" "); hCutEff[i]->SetAxisRange(50, 299, "X"); hCutEff[i]->SetAxisRange(0.95, 1.05, "Y"); hCutEff[i]->SetMarkerStyle(20); hCutEff[i]->SetMarkerColor(kBlack); hCutEff[i]->Draw(); line->Draw(); } putCMSPrel(); drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20); drawText(Form("%s",Coll), 0.6, 0.21, 20); cCutEff->SaveAs(Form("May20/%s_Combined_CutEfficiency_centralityClass_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE"); TCanvas * cCutEff_Data = new TCanvas("cCutEff_Data","",800,600); makeMultiPanelCanvas(cCutEff_Data,3,2,0.0,0.0,0.2,0.15,0.07); for(int i = 0; i<nbins_cent; ++i){ cCutEff_Data->cd(nbins_cent-i); hCutEff_Data[i]->SetXTitle(Form("akPu%dPF Data reco p_{T} (GeV/c)", radius)); hCutEff_Data[i]->SetYTitle("Jet ID Cut Efficiency"); hCutEff_Data[i]->SetTitle(" "); hCutEff_Data[i]->SetAxisRange(60, 299, "X"); hCutEff_Data[i]->SetAxisRange(0.2, 1.1, "Y"); hCutEff_Data[i]->SetMarkerStyle(20); hCutEff_Data[i]->SetMarkerColor(kBlack); hCutEff_Data[i]->Draw(); line->Draw(); } putCMSPrel(); drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20); drawText(Form("%s",Coll), 0.6, 0.21, 20); cCutEff_Data->SaveAs(Form("May20/%s_Combined_CutEfficiency_Data_centralityClass_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE"); TCanvas * cPP_CutEff = new TCanvas("cPP_CutEff","",800,600); hPP_CutEff->SetXTitle(Form("ak%dPF Gen p_{T} (GeV/c)", radius)); hPP_CutEff->SetYTitle("Jet ID Cut Efficiency"); hPP_CutEff->SetTitle(" "); hPP_CutEff->SetAxisRange(60, 299, "X"); hPP_CutEff->SetAxisRange(0.8,1.1,"Y"); hPP_CutEff->SetMarkerStyle(20); hPP_CutEff->Draw(); cPP_CutEff->SaveAs(Form("May20/PP_Combined_CutEfficiency_R0p%d_%d.pdf",radius, date.GetDate())); TCanvas * cPP_CutEff_Data = new TCanvas("cPP_CutEff_Data","",800,600); hPP_CutEff_Data->SetXTitle(Form(" ak%dPF Data reco p_{T} (GeV/c)", radius)); hPP_CutEff_Data->SetYTitle("Jet ID Cut Efficiency"); hPP_CutEff_Data->SetTitle(" "); hPP_CutEff_Data->SetAxisRange(60, 299, "X"); hPP_CutEff_Data->SetAxisRange(0.8,1.1,"Y"); hPP_CutEff_Data->SetMarkerStyle(20); hPP_CutEff_Data->Draw(); cPP_CutEff_Data->SaveAs(Form("May20/PP_Combined_CutEfficiency_Data_R0p%d_%s_%d.pdf",radius,etaWidth, date.GetDate())); }
void meson_pi0_normalization(){ gROOT->Reset(); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); c1 = new TCanvas("c1","A Simple Graph with error bars",200,10,700,500); c1->SetFillColor(10); c1->SetGrid(); c1->SetLogy(); c1->SetTicks(); float pt, mtpion, mtother; float weight = 1.0; int nbins = 5000; float ptmin = 0.0; float ptmax = 5.0; float binwidth = (ptmax-ptmin)/(double)nbins; TH1F * ptpion = new TH1F("ptpion","ptpion",nbins,ptmin,ptmax); TH1F * ptother = new TH1F("ptother","ptother",nbins,ptmin,ptmax); TH1F * ptothermt = new TH1F("ptothermt","ptothermt",nbins,ptmin,ptmax); TH1F * ratio = new TH1F("ratio","ratio",nbins,ptmin,ptmax); TH1F * ratiomt = new TH1F("ratiomt","ratiomt",nbins,ptmin,ptmax); TMath math1; double pi = acos(-1.0); double pimass = 0.1349766; double omass = 0.54730; double expected = 0.45; // double omass = 0.7711; // double expected = 1.0; // double omass = 0.78257; // double expected = 1.0; // double omass = 0.95778; // double expected = 0.25; // double omass = 1.019456; // double expected = 0.4; double t_fo = 0.122; double beta = 0.70; double norm = 1.0; double intpion = 0.0; double intother = 0.0; double intothermt = 0.0; for (int ibin=1; ibin<=nbins; ibin++ ) { pt = ptmin+(double)(ibin-1)*binwidth+binwidth/2.0; mtpion = sqrt(pt*pt+pimass*pimass); mtother = sqrt(pt*pt+omass*omass); // minimum bias: // double trans = 1./(1.+exp(5.*pt-17.5)); // double pihagedorn = 3.53e+07/pow(2.28+pt,13.7); // double pipower = 33.9/pow(pt,8.16); // double otherhagedorn = 3.53e+07 / // pow(2.28+sqrt(mtother*mtother-pimass*pimass),13.7); // double otherpower = 33.9/pow(sqrt(mtother*mtother-pimass*pimass),8.16); // 0 - 10 % central // double trans = 1./(1.+exp(5.*pt-17.5)); // double pihagedorn = 1.41e+13/pow(3.48+pt,18.7); // double pipower = 137.3/pow(pt,8.44); // double otherhagedorn = 1.41e+13 / // pow(3.48+sqrt(mtother*mtother-pimass*pimass),18.7); // double otherpower = 137.3/pow(sqrt(mtother*mtother-pimass*pimass),8.44); // 10 - 20 % central // double trans = 1./(1.+exp(5.*pt-17.5)); // double pihagedorn = 2.176e+09/pow(2.651+pt,15.170); // double pipower = 92.46/pow(pt,8.326); // double otherhagedorn = 2.176e+09 / // pow(2.651+sqrt(mtother*mtother-pimass*pimass),15.170); // double otherpower = 92.46/pow(sqrt(mtother*mtother-pimass*pimass),8.326); // 20 - 40 % central // double trans = 1./(1.+exp(5.*pt-17.5)); // double pihagedorn = 2.99e+06/pow(2.00+pt,12.45); // double pipower = 51.28/pow(pt,8.21); // double otherhagedorn = 2.99e+06 / // pow(2.00+sqrt(mtother*mtother-pimass*pimass),12.45); // double otherpower = 51.28/pow(sqrt(mtother*mtother-pimass*pimass),8.21); // 40 - 60 % central // double trans = 1./(1.+exp(5.*pt-17.5)); // double pihagedorn = 3.00e+04/pow(1.56+pt,10.76); // double pipower = 15.75/pow(pt,7.97); // double otherhagedorn = 3.00e+04 / // pow(1.56+sqrt(mtother*mtother-pimass*pimass),10.76); // double otherpower = 15.75/pow(sqrt(mtother*mtother-pimass*pimass),7.97); // 60 - 92 % central // double trans = 1./(1.+exp(5.*pt-17.5)); // double pihagedorn = 8.73e+02/pow(1.29+pt,9.94); // double pipower = 5.28/pow(pt,8.28); // double otherhagedorn = 8.73e+02 / // pow(1.29+sqrt(mtother*mtother-pimass*pimass),9.94); // double otherpower = 5.28/pow(sqrt(mtother*mtother-pimass*pimass),8.28); // if ( pt<1.5 ) weight = 2.0 * pi * pt * pihagedorn; // if ( pt>=1.5 && pt<=5.5 ) // weight = 2.0 * pi * pt * (trans*pihagedorn + (1.-trans)*pipower); // if ( pt>5.5 ) weight = 2.0*pi*pt*pipower; // pp (Xinhua's Run-2 parameterization) // weight = 2.0*pi*pt * (485.0/42.) / pow(exp(-0.5187*pt) + pt/0.6631,8.163); // pp (Run-2 hard parameterization) weight = 2.0*pi*pt * (450.8/42.) / pow(exp(-0.5553*pt) + pt/0.6467,8.046); // pp (Run-3 parameterization) // weight = 2.0*pi*pt * (413.5/42.2) / pow(exp(-0.2614*pt) + pt/0.8144,8.807); // pp (average Run-2/3 parameterization) // weight = 2.0*pi*pt * (546.2/42.2) / pow(exp(-0.2664*pt) + pt/0.7703,8.718); // weight = weight*(1+0.6362/exp(7.736*pt)); ptpion->AddBinContent(ibin,weight); intpion = intpion + weight*binwidth; // if ( pt<1.5 ) weight = 2.0 * pi * pt * otherhagedorn; // if ( pt>=1.5 && pt<=5.5 ) // weight = 2.0 * pi * pt * (trans*otherhagedorn + (1.-trans)*otherpower); // if ( pt>5.5 ) weight = 2.0*pi*pt*otherpower; weight = 2.0*pi*pt * (450.8/42.2) / pow(exp(-0.5553*sqrt(mtother*mtother-pimass*pimass)) + sqrt(mtother*mtother-pimass*pimass)/0.6467,8.046); ptothermt->AddBinContent(ibin,weight); intothermt = intothermt + weight*binwidth; weight = norm*InitializePtHydro(omass,t_fo,beta,pt); ptother->AddBinContent(ibin,weight); intother = intother + weight*binwidth; } cout << "Integral pion (dN/dy): " << intpion << endl; cout << "Integral other (dN/dy): " << intother << endl; cout << "Integral othermt (dN/dy): " << intothermt << endl; norm = intpion/intothermt; ptothermt->Scale(norm); for (int ibin=1; ibin<=nbins; ibin++ ) { weight = ptothermt->GetBinContent(ibin)/ptpion->GetBinContent(ibin); ratiomt->AddBinContent(ibin,weight); } norm = expected/ratiomt->GetMaximum(); ratiomt->Scale(norm); ptothermt->Scale(norm); cout << "meson/pion ratio should be set to: " << norm << endl; norm = expected*intothermt/intother; ptother->Scale(norm); for (int ibin=1; ibin<=nbins; ibin++ ) { weight = ptother->GetBinContent(ibin)/ptpion->GetBinContent(ibin); ratio->AddBinContent(ibin,weight); } ptpion->SetXTitle("p_{t} [GeV/c]"); ptpion->SetYTitle("(1/2#pi p_{t})dN/dp_{t}dy [(c/GeV)^{2}]"); ptpion->SetLineWidth(5); ptpion->SetLineColor(1); ptother->SetLineWidth(5); ptother->SetLineColor(2); ptothermt->SetLineWidth(5); ptothermt->SetLineColor(4); ptpion->Draw(""); ptothermt->Draw("same"); ptother->Draw("same"); TLatex *text_pion0 = new TLatex(3.2,1.5,"#pi^{0}"); text_pion0->SetTextColor(1); text_pion0->Draw(); TLatex *text_pionm = new TLatex(3.2,1.1,"#eta m_{t} scaled"); text_pionm->SetTextColor(4); text_pionm->Draw(); TLatex *text_pionp = new TLatex(3.2,0.7,"#eta hydro"); text_pionp->SetTextColor(2); text_pionp->Draw(); c2 = new TCanvas("c2","A Simple Graph with error bars",200,10,700,500); c2->SetFillColor(10); c2->SetGrid(); c2->SetLogy(0); c2->SetTicks(); c2->cd(); ratiomt->SetXTitle("p_{t} [GeV/c]"); ratiomt->SetYTitle("#eta / #pi^{0}"); ratio->SetLineWidth(5); ratio->SetLineColor(2); ratiomt->SetLineWidth(5); ratiomt->SetLineColor(4); ratiomt->Draw(); ratio->Draw("same"); TLatex *text_pionm = new TLatex(3.2,0.42,"#eta m_{t} scaled"); text_pionm->SetTextColor(4); text_pionm->Draw(); TLatex *text_pionp = new TLatex(3.2,0.35,"#eta hydro"); text_pionp->SetTextColor(2); text_pionp->Draw(); return; }
void plotHitEnergy(string inputDir, int hittype=1, float radius=0.4) { setNCUStyle(true); string decversion; if(inputDir.find("rfull009")!=std::string::npos)decversion="rfull009"; else if(inputDir.find("rfull012")!=std::string::npos)decversion="rfull012"; TH1F* hecal; TH1F* hhcal; std::string ecalhitname = hittype==1? "EM_BARREL":"EcalBarrelHits"; std::string hcalhitname = hittype==1? "HAD_BARREL":"HcalBarrelHits"; TString energy=gSystem->GetFromPipe(Form("file=%s; test=${file##*/}; test2=${test%%mumu*}; echo \"${test2##*tev}\"",inputDir.data())); cout << "energy = " << energy.Data() << endl; string inputFile = inputDir + "/radius" + Form("%0.1f",radius)+ (hittype==1? "_rawhit.root": "_rawhit_new.root"); cout << "opening " << inputFile.data() << endl; TFile *f = TFile::Open(inputFile.data()); hecal = (TH1F*)f->FindObjectAny("hecalhit_energy"); hecal->SetLineWidth(3); hecal->SetFillStyle(1001); hecal->SetFillColor(4); hecal->SetLineColor(4); hecal->SetXTitle(Form("%s hit energy [GeV]",ecalhitname.data())); hecal->SetYTitle(Form("Number of hits per %.1f GeV",hecal->GetBinWidth(1))); hecal->SetTitleOffset(1.2,"X"); hecal->SetTitleOffset(1.4,"Y"); hhcal = (TH1F*)f->FindObjectAny("hhcalhit_energy"); hhcal->SetLineWidth(3); hhcal->SetFillStyle(1001); hhcal->SetFillColor(2); hhcal->SetLineColor(2); hhcal->SetXTitle(Form("%s hit energy [GeV]",hcalhitname.data())); hhcal->SetYTitle(Form("Number of hits per %.1f GeV",hhcal->GetBinWidth(1))); hhcal->SetTitleOffset(1.2,"X"); hhcal->SetTitleOffset(1.4,"Y"); TLegend* leg = new TLegend(0.444,0.690,0.990,0.903); leg->SetFillColor(0); leg->SetFillStyle(0); TCanvas* c1 = new TCanvas("c1","",500,500); int lastbin=hecal->FindLastBinAbove(0)+20; float xmax=hecal->GetBinLowEdge(lastbin); hecal->GetXaxis()->SetRangeUser(0,xmax); hecal->Draw("hist"); c1->SetLogy(1); leg->SetHeader(decversion.data()); leg->AddEntry(hecal,Form("%s-TeV Z'#rightarrow qq",energy.Data()),"f"); leg->Draw("same"); std::string outputname = decversion + "/" + decversion + "_" + ecalhitname + "hit_energy_" + Form("%s",energy.Data()) + "TeVZp"; c1->Print(Form("%s.pdf",outputname.data())); c1->Print(Form("%s.eps",outputname.data())); leg->Clear(); lastbin=hhcal->FindLastBinAbove(0)+20; xmax=hhcal->GetBinLowEdge(lastbin); hhcal->GetXaxis()->SetRangeUser(0,xmax); hhcal->Draw("hist"); c1->SetLogy(1); leg->SetHeader(decversion.data()); leg->AddEntry(hhcal,Form("%s-TeV Z'#rightarrow qq",energy.Data()),"f"); leg->Draw("same"); outputname = decversion + "/" + decversion + "_" + hcalhitname + "hit_energy_" + Form("%s",energy.Data()) + "TeVZp"; c1->Print(Form("%s.pdf",outputname.data())); c1->Print(Form("%s.eps",outputname.data())); }
//void electron_master(const char* file_list="checkP10ic/electrons.list",const char* output="checkP10ic/electroncalib.root", const char* dbDate="2009-04-10 00:11:00", const char* geantfile="geant_func.root", const char* gfname="checkP10ic/mip.gains", const char* ngname="checkP10ic/electron.gains", const char* rgname="matrel.gains",const char* ffname="checkP10ic/electron.fits"){ void electron_master(const char* file_list="checkP11id/electrons.list",const char* output="checkP11id/electroncalib2.root", const char* dbDate="2009-04-10 00:11:00", const char* gfname="checkP11id/mip.gains", const char* ngname="checkP11id/electron2.gains",const char* ffname="checkP11id/electron2.fits"){ //**********************************************// //Load Libraries // //**********************************************// gROOT->Macro("LoadLogger.C"); gROOT->Macro("loadMuDst.C"); gSystem->Load("StTpcDb"); gSystem->Load("StDaqLib"); gSystem->Load("StDetectorDbMaker"); gSystem->Load("St_db_Maker"); gSystem->Load("StDbUtilities"); gSystem->Load("StEmcRawMaker"); gSystem->Load("StMcEvent"); gSystem->Load("StMcEventMaker");//*** gSystem->Load("StEmcSimulatorMaker");//*** gSystem->Load("StEmcADCtoEMaker"); gSystem->Load("StEpcMaker"); gSystem->Load("StDbBroker"); gSystem->Load("StEEmcUtil"); gSystem->Load("StAssociationMaker"); gSystem->Load("StEmcTriggerMaker"); gSystem->Load("StTriggerUtilities"); gSystem->Load("StEmcOfflineCalibrationMaker"); cout<<"input filelist: "<<file_list<<endl; cout<<"output: "<<output<<endl; cout<<"db Date: "<<dbDate<<endl; //**********************************************// //Initialize Stuff // //**********************************************// CalibrationHelperFunctions *helper = new CalibrationHelperFunctions(); StBemcTablesWriter *bemctables = new StBemcTablesWriter(); bemctables->loadTables(dbDate,"sim"); StEmcDecoder* decoder = bemctables->getDecoder(); //chain all input files together char file[300]; TChain* tree = new TChain("skimTree"); ifstream filelist(file_list); while(1){ filelist >> file; if(!filelist.good()) break; cout<<file<<endl; tree->Add(file); } const int ntowers = 4800; const int nrings = 40; const int ncrates = 30; float gains[ntowers]; int status[ntowers]; float peaks[ntowers]; float peakerr[ntowers]; float gainerr[ntowers]; ifstream gainfile(gfname); while(1){ int id,stat; float peak,err,gain,eta,theta; gainfile >> id >> peak >> err >> stat; if(!gainfile.good())break; eta = helper->getEta(id); theta = helper->getTheta(id); gain = 0.264*(1+0.056*eta*eta)/(sin(theta)*peak); peaks[id-1] = peak; gains[id-1] = gain; if(status[id-1] != 1 || stat != 1) status[id-1] = stat; peakerr[id-1] = err; //cout<<id<<" "<<gain; } TFile* geant_file = new TFile("geant_fits.root","READ"); TF1* geant_fits[20]; for(int i = 0; i < 20; i++){ TString fname = "fit_"; fname += i; geant_fits[i] = (TF1*)geant_file->Get(fname); } TFile outfile(output,"RECREATE"); TH1 *crate_histo[ncrates]; TF1 *crate_fit[ncrates]; TH1 *electron_histo[ntowers]; TF1 *fit[ntowers]; TH1 *prs_histo[ntowers]; TH1 *ring_histo[nrings]; TH1 *ring2_histo[nrings/2]; TF1 *ring2fit[nrings/2]; TH1 *etacrate_histo[ncrates*20]; TH1 *etacrate_histo_p[ncrates*20]; TH1 *etacrate_histo_n[ncrates*20]; TH1 *bghisto[21]; TH2F* drvsep = new TH2F("drvsep","drvsep",60,0,3.0,100,0.0,0.03); TF1 *ringfit[nrings]; TH2F* ring_pve[nrings]; TH2F* jan_pve[6]; float eta; int etaindex; TH1F* ringprec = new TH1F("ringprec","",40,-1.0,1.0); TH1F* ringprec2 = new TH1F("ringprec2","",40,-1.0,1.0); ringprec->SetYTitle("E/p"); ringprec->SetXTitle("#eta"); ringprec2->SetYTitle("E/p"); ringprec2->SetXTitle("#eta"); TH1F* ring2prec = new TH1F("ring2prec","",nrings/2,-1.0,1.0); TH1F* ring2prec2 = new TH1F("ring2prec2","",nrings/2,-1.0,1.0); ring2prec->SetYTitle("E/p"); ring2prec->SetXTitle("#eta"); ring2prec2->SetYTitle("E/p"); ring2prec2->SetXTitle("#eta"); double ew[nrings]; TH2F* trgcheck = new TH2F("trgcheck","trgcheck",2,-0.5,1.5,3,-0.5,2.5); TH1F* crateprec = new TH1F("crateprec","",30,0.5,30.5); crateprec->SetXTitle("Crate"); crateprec->SetYTitle("E/p"); TH2F *energyleak = new TH2F("energyleak","",20,0.0,0.03,20,0.0,1.0); TH2F *findbg = new TH2F("findbg","",20,0.0,0.03,30,0.0,5.0); TH1F *energymean = new TH1F("energymean","",20,0.0,0.03); TH1F *leakmean = new TH1F("leakmean","",20,0.0,0.03); energyleak->SetXTitle("#DeltaR"); energyleak->SetYTitle("leaked energy / total energy"); findbg->SetXTitle("#DeltaR"); findbg->SetYTitle("Total energy / track momentum"); TH2F *tevsp = new TH2F("tevsp","",50,0.0,20.0,50,0.0,30.0); TH1F *pmean = new TH1F("pmean","",20,0.0,15.0); tevsp->SetXTitle("track momentum (GeV)"); tevsp->SetYTitle("Total Energy (GeV)"); TH2F *tevspcent = new TH2F("tevspcent","",20,0.0,15.0,20,0.0,15.0); tevspcent->SetXTitle("track momentum (GeV)"); tevspcent->SetYTitle("Energy in central tower (GeV)"); TH1F *cmean = new TH1F("cmain","",20,0.0,15.0); TH2F *sistertracks = new TH2F("sistertracks","",20,0.0,8.0,20,0.0,8.0); sistertracks->SetXTitle("Track momentum (GeV)"); sistertracks->SetYTitle("Neighbor momentum (GeV)"); TH2F* dEdxvsp = new TH2F("dEdxvsp","",100,0.15,1.3,100,-5.7,-5.); dEdxvsp->SetXTitle("Log(p)"); dEdxvsp->SetYTitle("Log(dE/dx)"); TH2F* dEdxvsp_east = new TH2F("dEdxvsp_east","",100,0.15,1.3,100,-5.7,-5.0); dEdxvsp_east->SetXTitle("Log(p)"); dEdxvsp_east->SetYTitle("Log(dE/dx)"); TH2F* dEdxvsp_west = new TH2F("dEdxvsp_west","",100,0.15,1.3,100,-5.7,-5.0); dEdxvsp_west->SetXTitle("Log(p)"); dEdxvsp_west->SetYTitle("Log(dE/dx)"); TH2F* energyleak2 = new TH2F("energyleak2","",20,0.0,0.03,20,0.0,1.0); TH1F* energymean2 = new TH1F("energymean2","",20,0.0,0.03); TH1F* towermult = new TH1F("towermult","",9,0.0,9.0); energyleak2->SetXTitle("#DeltaR"); energyleak2->SetYTitle("leaked energy/total energy"); towermult->SetXTitle("Neighbors with energy"); TH2F* multvsp = new TH2F("multvsp","",20,0.0,20.0,9,0.0,9.0); multvsp->SetXTitle("Track momentum (GeV)"); multvsp->SetYTitle("Neighbors with energy"); TH1F* multmean = new TH1F("multmean","",20,0.0,20.0); TH2F* tep3 = new TH2F("tep3","2 < p < 3",20,0.0,0.03,20,0.0,4.0); TH2F* tep5 = new TH2F("tep5","3 < p < 5",20,0.0,0.03,20,0.0,4.0); TH2F* tep10 = new TH2F("tep10","5 < p < 10",20,0.0,0.03,20,0.0,4.0); tep3->SetXTitle("DeltaR"); tep3->SetYTitle("Total energy / track momentum"); tep5->SetXTitle("DeltaR"); tep5->SetYTitle("Total energy / track momentum"); tep10->SetXTitle("DeltaR"); tep10->SetYTitle("Total energy / track momentum"); TH1F* tep3mean = new TH1F("tep3mean","",20,0,0.03); TH1F* tep5mean = new TH1F("tep5mean","",20,0,0.03); TH1F* tep10mean = new TH1F("tep10mean","",20,0,0.03); TH1F* multen = new TH1F("multen","",40,0.0,1.0); multen->SetXTitle("Energy in neighbor towers (GeV)"); TH1F* east_histo = new TH1F("east_histo","Electron E/p in East",40,0.0,2.0); TH1F* west_histo = new TH1F("west_histo","Electron E/p in West",40,0.0,2.0); TH1F* all_histo = new TH1F("all_histo","Electron E/p",40,0.0,2.0); TH1F* notrg = new TH1F("notrg","Electron E/p",40,0.0,2.0); TH2F* pvsep = new TH2F("pvsep","Electron p vs E/p",120,0,3.0,20,0,20.0); pvsep->SetYTitle("p (Gev)"); pvsep->SetXTitle("E/p"); TH2F* pvsep0 = new TH2F("pvsep0","Electron p vs E/p",120,0,3.0,20,0,20.0); pvsep0->SetYTitle("p (Gev)"); pvsep0->SetXTitle("E/p"); TH2F* evsep = new TH2F("evsep","Electron E vs E/p",120,0,3.0,20,0,20.0); evsep->SetYTitle("E (GeV)"); evsep->SetXTitle("E/p"); TH1F* bsmde = new TH1F("bsmde","BSMDE ADC TOT",1500,0,1500); TH1F* bsmdp = new TH1F("bsmdp","BSMDP ADC TOT",1500,0,1500); TH1F* bsmde_central = new TH1F("bsmde_central","BSMDE ADC TOT",100,0,1500); TH1F* bsmde_mid = new TH1F("bsmde_mid","BSMDE ADC TOT",100,0,1500); TH1F* bsmde_outer = new TH1F("bsmde_outer","BSMDE ADC TOT",100,0,1500); TH2F* bsmdep = new TH2F("bsmdep","BSMDE v BSMDP",100,0,1500,100,0,1500); TH2F* bsmdevp = new TH2F("bsmdevp","BSMDE v p",100,1.0,15.0,100,0,1500); TH2F* bsmdpvp = new TH2F("bsmdpvp","BSMDP v p",100,1.0,15.0,100,0,1500); TH2F* bsmdevep = new TH2F("bsmdevep","BSMDE v E/p",100,0.0,2.0,100,0,1500); TH2F* bsmdpvep = new TH2F("bsmdpvep","BSMDP v E/p",100,0.0,2.0,100,0,1500); TH2F* bsmdeve = new TH2F("bsmdeve","BSMDE v E",100,1.0,30.0,100,0,1500); TH2F* bsmdpve = new TH2F("bsmdpve","BSMDP v E",100,1.0,30.0,100,0,1500); TH1F* httrig = new TH1F("httrig","HT Trigger",5,-0.5,4.5); TH1F* pplus = new TH1F("pplus","e+ p",100,0,20); TH1F* pminus = new TH1F("pminus","e- p",100,0,20); TH1F* posep = new TH1F("posep","e+ E/p",60,0,3.0); TH1F* negep = new TH1F("negep","e- E/p",60,0,3.0); //create the tower histograms char name1[100]; for(int i = 0; i < ncrates; i++){ for(int j = 0; j < 20; j++){ TString ecname,ecnamep,ecnamen; ecname += "etacrate_"; int cr = i+1; int et = j; ecname += cr; ecname += "_"; ecname += et; ecnamep += ecname; ecnamen += ecname; ecnamep.ReplaceAll("te_","te_p_"); ecnamen.ReplaceAll("te_","te_n_"); etacrate_histo[i*20+j] = new TH1F(ecname.Data(),ecname.Data(),60,0.0,3.0); etacrate_histo_p[i*20+j] = new TH1F(ecnamep.Data(),ecnamep.Data(),60,0.0,3.0); etacrate_histo_n[i*20+j] = new TH1F(ecnamen.Data(),ecnamen.Data(),60,0.0,3.0); } } for(int i=0; i<ntowers; i++){ char nameeh[100]; sprintf(nameeh,"electron_histo_%i",i+1); electron_histo[i] = new TH1D(nameeh,"",60,0.,3.0); electron_histo[i]->SetXTitle("E/p"); //sprintf(name1,"prs_histo_%i",i+1); //prs_histo[i] = new TH1D(name1,"",60,0.,500.); //prs_histo[i]->SetXTitle("ADC"); } for(int i = 0; i < 21; i++){ TString namebg; namebg += "bg_"; namebg += i+25; bghisto[i] = new TH1F(namebg.Data(),namebg.Data(),60,0,3.0); } for(int i = 0; i < ncrates; i++){ char name[100]; char title[100]; sprintf(name,"crate_%i",i+1); sprintf(title,"E/p for Crate %i",i+1); crate_histo[i] = new TH1F(name,title,60,0.,3.0); crate_histo[i]->SetXTitle("E/p"); } for(int i = 0; i < nrings/2; i++){ char name[100]; sprintf(name,"ring2_histo_%i",i); ring2_histo[i] = new TH1F(name,"",60,0.,3.0); ring2_histo[i]->SetXTitle("E/p"); } char name2[100]; for(int i=0; i<nrings;i++) { sprintf(name2,"ring_histo_%i",i); //ring_histo[i] = new TH1D(name2,"",30,0.,140.0); //ring_histo[i]->SetXTitle("ADC / GeV Sin(#theta)"); ring_histo[i] = new TH1D(name2,"",60,0.,3.0); ring_histo[i]->SetXTitle("E/p"); char namerpve[100]; sprintf(namerpve,"ring_pve_%i",i); ring_pve[i] = new TH2F(namerpve,"",20,0,20.0,20,0,20.0); ring_pve[i]->SetXTitle("E (GeV)"); ring_pve[i]->SetYTitle("p (GeV)"); } for(int i = 0; i < 6; i++){ char jname[100]; sprintf(jname,"jan_pve_%i",i); jan_pve[i] = new TH2F(jname,"",120,0,3.0,20,0,20.0); jan_pve[i]->SetXTitle("E/p"); jan_pve[i]->SetYTitle("p (GeV)"); } //global graphics functions gStyle->SetOptStat("oue"); gStyle->SetOptFit(111); gStyle->SetCanvasColor(10); gStyle->SetCanvasBorderMode(0); gStyle->SetOptTitle(0); gStyle->SetPalette(1); gStyle->SetStatColor(0); StEmcOfflineCalibrationTrack* track = new StEmcOfflineCalibrationTrack(); StEmcOfflineCalibrationCluster* cluster = new StEmcOfflineCalibrationCluster(); tree->SetBranchAddress("clusters",&cluster); //**********************************************// //Loop Over Tracks, Fill Histograms // //**********************************************// int nentries = tree->GetEntries(); cout<<nentries<<endl; int ngoodhit = 0; int nplt10 = 0; int nnosis = 0; int nfinal = 0; int nbsmdgood = 0; int nnottrig = 0; int nfidu = 0; int nenterexit = 0; for(int j=0; j<nentries; j++){ tree->GetEntry(j); track = &(cluster->centralTrack); TClonesArray *tracks = cluster->tracks; if(j % 500000 == 0) cout<<"reading "<<j<<" of "<<nentries<<endl; httrig->Fill((float)track->htTrig); if(track->charge > 0)pplus->Fill(track->p); if(track->charge < 0)pminus->Fill(track->p); int bsmdeadctot = 0; int bsmdpadctot = 0; for(int i = 0; i < 11; i++){ if(track->smde_adc[i] > track->smde_pedestal[i])bsmdeadctot += track->smde_adc[i] - track->smde_pedestal[i]; if(track->smdp_adc[i] > track->smdp_pedestal[i])bsmdpadctot += track->smdp_adc[i] - track->smdp_pedestal[i]; } double dR = TMath::Sqrt(track->deta*track->deta + track->dphi*track->dphi); double scaled_adc = (track->tower_adc[0] - track->tower_pedestal[0]) / track->p; int index = track->tower_id[0]; //figure out eta and etaindex eta = helper->getEta(index); if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta; etaindex = ((TMath::Nint(eta * 1000.0) + 25)/50 + 19); int geantetaindex = ((TMath::Nint(fabs(eta) * 1000.0) + 25)/50 - 1); double geant_scale = geant_fits[geantetaindex]->Eval(dR); scaled_adc /= geant_scale; //double geant_scale = geant_fit->Eval(dR); //scaled_adc *= geant_scale; //cout<<scaled_adc<<endl; //now rescale dR for last ring to make cuts work if(geantetaindex == 19)dR *= 0.025/0.017; //double tgain = bemctables->calib(1,track->tower_id[0])*gains[index-1]; double tgain = gains[index-1]; if((track->tower_adc[0] - track->tower_pedestal[0]) < 2.5 * track->tower_pedestal_rms[0])continue; ngoodhit++; dEdxvsp->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); if(track->tower_id[0] <= 2400)dEdxvsp_west->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); if(track->tower_id[0] > 2400)dEdxvsp_east->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); trgcheck->Fill(track->nonhtTrig,track->htTrig); if(track->tower_id[0] != track->tower_id_exit)continue; nenterexit++; if(status[index-1]!=1)continue; pvsep0->Fill(scaled_adc*tgain,track->p); if(track->p > 10)continue; nplt10++; //if(track->p < 1.5)continue; //if(track->p < 3.0)continue; if(track->htTrig == 2 && track->nonhtTrig == 0)continue; nnottrig++; //change the fiducial cut to a square with diagonal = 0.06 in deta, dphi space float squarefid = 0.02;//0.03/TMath::Sqrt(2.0); //if(TMath::Abs(track->deta) > squarefid || TMath::Abs(track->dphi) > squarefid)continue; //calculate geant scaled, pedestal subtracted adc //if(dR > 0.0125)continue; int numsis = tracks->GetEntries(); float totalbtow = 0; float maxEt = 0; int maxId = -1; for(int i = 0; i < 9; i++){ if(track->tower_adc[i] - track->tower_pedestal[i] < 0)continue; float theta = helper->getTheta(track->tower_id[i]); float nextEt = (track->tower_adc[i] - track->tower_pedestal[i]) * bemctables->calib(1,track->tower_id[i])*sin(theta); totalbtow += nextEt; if(nextEt > maxEt){ maxEt = nextEt; maxId = i; } } if(track->dEdx > 3.5e-6 && track->dEdx <5.0e-6 && numsis ==0 &&maxId == 0)drvsep->Fill(scaled_adc*tgain,dR); if(dR > 0.02)continue; nfidu++; //if(track->p > 6.0)continue; //if(track->p > 15)continue; //cout<<track->dEdx<<endl; //if(track->dEdx*1000000 > 4.5 || track->dEdx*1000000 < 3.5)continue; //cout<<track->htTrig<<endl; for(int i = 0; i < 21; i++){ if(numsis > 0)break; if(maxId != 0)break; if(track->dEdx*1e7 > 25 + i && track->dEdx*1e7 < 26+i)bghisto[i]->Fill(scaled_adc*tgain); } //if(track->dEdx < 3.5e-6 || track->dEdx > 5.0e-6)continue; if(track->dEdx < 3.5e-6 || track->dEdx > 4.5e-6)continue; //if((bsmdeadctot > -1 && bsmdeadctot < 50) && (bsmdpadctot < 50 && bsmdpadctot > -1))continue; nbsmdgood++; //if(bsmdeadctot < 500) continue; //if(bsmdeadctot < 84.*track->p)continue; //if(bsmdeadctot > 200.*track->p + 1500)continue; //if(bsmdpadctot < 800)continue; if(numsis > 0)continue; nnosis++; if(maxId != 0) continue; nfinal++; if(track->htTrig!=2)notrg->Fill(scaled_adc*tgain); //if(!track->nonhtTrig)continue; //if(track->nHits < 25)continue; //if(status[index-1]==1)ring_histo[etaindex]->Fill(scaled_adc*gains[index-1]); //scaled_adc = totalbtow/track->p; //tgain = 1.0; float phi = helper->getPhi(index); int crate,sequence; decoder->GetCrateFromTowerId(index,crate,sequence); etacrate_histo[(crate-1)*20+geantetaindex]->Fill(scaled_adc*tgain); if(track->charge > 0)etacrate_histo_p[(crate-1)*20+geantetaindex]->Fill(scaled_adc*tgain); if(track->charge < 0)etacrate_histo_n[(crate-1)*20+geantetaindex]->Fill(scaled_adc*tgain); electron_histo[index-1]->Fill(scaled_adc*tgain); ring_histo[etaindex]->Fill(scaled_adc*tgain); if(etaindex == 0 || etaindex == 39){ //cout<<etaindex<<" "<<tgain<<" "<<track->p<<" "<<scaled_adc*tgain*track->p<<" "<<scaled_adc*tgain<<endl; } //cout<<index<<" "<<gains[index-1]<<" "<<scaled_adc*track->p<<" "<<track->p<<" "<<status[index-1]<<endl; ring_pve[etaindex]->Fill(scaled_adc*tgain*track->p,track->p); dEdxvsp->Fill(TMath::Log10(track->p),TMath::Log10(track->dEdx)); float abseta = TMath::Abs(eta); if(abseta > 0.95){ jan_pve[5]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.9){ jan_pve[4]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.6){ jan_pve[3]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.3){ jan_pve[2]->Fill(scaled_adc*tgain,track->p); }else if(abseta > 0.05){ jan_pve[1]->Fill(scaled_adc*tgain,track->p); }else{ jan_pve[0]->Fill(scaled_adc*tgain,track->p); } all_histo->Fill(scaled_adc*tgain); pvsep->Fill(scaled_adc*tgain,track->p); evsep->Fill(scaled_adc*tgain,track->p*scaled_adc*tgain); tevsp->Fill(track->p,scaled_adc*tgain*track->p); if(track->charge > 0)posep->Fill(scaled_adc*tgain); if(track->charge < 0)negep->Fill(scaled_adc*tgain); //if(scaled_adc*tgain < 0.7 || scaled_adc*tgain > 5.0)continue; bsmde->Fill(bsmdeadctot); bsmdp->Fill(bsmdpadctot); bsmdep->Fill(bsmdeadctot,bsmdpadctot); if(abseta > 0.6){ bsmde_outer->Fill(bsmdeadctot); }else if(abseta > 0.3){ bsmde_mid->Fill(bsmdeadctot); }else{ bsmde_central->Fill(bsmdeadctot); } bsmdevp->Fill(track->p,bsmdeadctot); bsmdpvp->Fill(track->p,bsmdpadctot); bsmdevep->Fill(scaled_adc*tgain,bsmdeadctot); bsmdpvep->Fill(scaled_adc*tgain,bsmdpadctot); bsmdeve->Fill(scaled_adc*tgain*track->p,bsmdeadctot); bsmdpve->Fill(scaled_adc*tgain*track->p,bsmdpadctot); if(dR > 0.015)continue; if(track->tower_id[0] <= 2400){ west_histo->Fill(scaled_adc*tgain); } if(track->tower_id[0] > 2400){ east_histo->Fill(scaled_adc*tgain); } } cout<<"processed electron tree"<<endl; cout<<"ngoodhit: "<<ngoodhit<<endl; cout<<"nenterexit: "<<nenterexit<<endl; cout<<"n not trig: "<<nnottrig<<endl; cout<<"n p < 10: "<<nplt10<<endl; cout<<"n in fidu: "<<nfidu<<endl; cout<<"nbsmdhit: "<<nbsmdgood<<endl; cout<<"n no sis: "<<nnosis<<endl; cout<<"n final: "<<nfinal<<endl; //double ew[21]; for(int h=0;h<21;h++){ TH1D* projection = energyleak->ProjectionY("projection",h,h); float mean = projection->GetMean(); energymean->SetBinContent(h,mean); TH1D* projection1 = findbg->ProjectionY("projection1",h,h); float mean1 = projection1->GetMean(); leakmean->SetBinContent(h,mean1); TH1D* projection2 = tevsp->ProjectionY("projection2",h,h); float mean2 = projection2->GetMean(); pmean->SetBinContent(h,mean2); //ew[h] = projection2->GetRMS(); TH1D* projection3 = tevspcent->ProjectionY("projection3",h,h); float mean3 = projection3->GetMean(); cmean->SetBinContent(h,mean3); TH1D* projection4 = energyleak2->ProjectionY("projection4",h,h); float mean4 = projection4->GetMean(); energymean2->SetBinContent(h,mean4); TH1D* projection5 = multvsp->ProjectionY("projection5",h,h); float mean5 = projection5->GetMean(); multmean->SetBinContent(h,mean5); TH1D* projection6 = tep3->ProjectionY("projection6",h,h); float mean6 = projection6->GetMean(); tep3mean->SetBinContent(h,mean6); TH1D* projection7 = tep3->ProjectionY("projection7",h,h); float mean7 = projection7->GetMean(); tep5mean->SetBinContent(h,mean7); TH1D* projection8 = tep3->ProjectionY("projection8",h,h); float mean8 = projection8->GetMean(); tep10mean->SetBinContent(h,mean8); } TF1* fitleak = new TF1("fitleak","[0]",0,0.03); fitleak->SetLineWidth(0.1); leakmean->Fit(fitleak,"rq"); //**********************************************// //Fit Tower Histograms // //**********************************************// /* for(int i=0; i<ntowers; i++){ if(i%600 == 0) cout<<"fitting tower "<<i+1<<" of "<<ntowers<<endl; sprintf(name,"fit_%i",i+1); //this fit is for the electron tree fit[i] = new TF1(name,fit_function,0.,140.,6); fit[i]->SetParameter(1,65.); fit[i]->SetParameter(2,10.); fit[i]->SetParameter(3,10.); //relative height of peak to bg fit[i]->SetParameter(4,10.); fit[i]->SetParameter(5,3.); fit[i]->SetParNames("Constant","Mean","Sigma","Peak Ratio","Bg Mean","Bg Sigma"); fit[i]->SetLineColor(kGreen); fit[i]->SetLineWidth(0.6); electron_histo[i]->Fit(fit[i],"rq"); } */ //**********************************************// //Fit Ring Histograms // //**********************************************// for(int i=0; i<nrings; i++){ //cout<<"fitting ring "<<i+1<<" of "<<nrings<<endl; sprintf(name,"ring_fit_%i",i); /* ringfit[i] = new TF1(name,fit_function,0.,140.,6); ringfit[i]->SetParameter(1,1.); ringfit[i]->SetParameter(2,0.2); ringfit[i]->SetParameter(3,1.5); //relative height of peak to bg ringfit[i]->SetParameter(4,0.15); ringfit[i]->SetParameter(5,0.8); ringfit[i]->SetParNames("Constant","Mean","Sigma","Peak Ratio","Bg Mean","Bg Sigma"); */ //TF1* ffff = new TF1("ffff","expo(0) + gaus(2)",0.4,1.7); ring_histo[i]->Sumw2(); //ring_histo[i]->Rebin(3); ringfit[i] = new TF1(name,"pol1(0) + gaus(2)"); ringfit[i]->SetParLimits(0,0,10.0*ring_histo[i]->GetBinContent(1)); ringfit[i]->SetParLimits(1,-10000,0); ringfit[i]->SetParLimits(2,0,10.0*ring_histo[i]->GetMaximum()); ringfit[i]->SetParLimits(3,0,10); ringfit[i]->SetParameter(0,ring_histo[i]->GetBinContent(1)); ringfit[i]->SetParameter(1,-ring_histo[i]->GetBinContent(1)/6.0); ringfit[i]->SetParameter(2,ring_histo[i]->GetMaximum()); ringfit[i]->SetParameter(3,0.95); ringfit[i]->SetParameter(4,0.15); ringfit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); /* ringfit[i] = new TF1(name,fit_function2,0.1,2.5,8); ringfit[i]->SetParameter(1,1.); ringfit[i]->SetParameter(2,0.2); ringfit[i]->SetParameter(3,1.5); //relative height of peak to bg ringfit[i]->SetParameter(4,0.25); ringfit[i]->SetParameter(5,0.15); ringfit[i]->SetParameter(7,0.8); ringfit[i]->SetParNames("Constant","Mean","Sigma","Peak Ratio","Bg Mean","Bg Sigma","Bg2 constant","Bg2 decay"); */ ringfit[i]->SetLineColor(kBlue); ringfit[i]->SetLineWidth(0.6); ring_histo[i]->Fit(ringfit[i],"rql","",0.2,1.7); ringprec->SetBinContent(i+1,(ringfit[i]->GetParameter(3))); ringprec->SetBinError(i+1,ringfit[i]->GetParameter(4)); ringprec2->SetBinContent(i+1,(ringfit[i]->GetParameter(3))); ringprec2->SetBinError(i+1,ringfit[i]->GetParError(3)); //ew[i] = 4066/(60*(fit[i]->GetParameter(2))*(fit[i]->GetParameter(2))); float mean = ringfit[i]->GetParameter(3); float merr = ringfit[i]->GetParError(3); cout<<"ring "<<i<<" "<<mean<<" "<<merr/mean<<" "<<ring_histo[i]->GetEntries()<<endl; } for(int i = 0; i < nrings/2; i++){ ring2_histo[i]->Add(ring_histo[2*i]); ring2_histo[i]->Add(ring_histo[2*i+1]); sprintf(name,"ring2_fit_%i",i); ring2fit[i] = new TF1(name,"pol1(0) + gaus(2)",0.3,1.7); ring2_histo[i]->Rebin(3); ring2fit[i]->SetParLimits(0,0,10.0*ring2_histo[i]->GetBinContent(1)); ring2fit[i]->SetParLimits(1,-10000,0); ring2fit[i]->SetParLimits(2,0,10.0*ring2_histo[i]->GetMaximum()); ring2fit[i]->SetParLimits(3,0,10); ring2fit[i]->SetParLimits(4,0.17,0.175); ring2fit[i]->SetParameter(0,ring2_histo[i]->GetBinContent(1)); ring2fit[i]->SetParameter(1,-ring2_histo[i]->GetBinContent(1)/6.0); ring2fit[i]->SetParameter(2,ring2_histo[i]->GetMaximum()); ring2fit[i]->SetParameter(3,0.95); ring2fit[i]->SetParameter(4,0.11245); ring2fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); ring2_histo[i]->Fit(ring2fit[i],"rql","",0.3,1.7); ring2prec->SetBinContent(i+1,(ring2fit[i]->GetParameter(3))); ring2prec->SetBinError(i+1,ring2fit[i]->GetParameter(4)); ring2prec2->SetBinContent(i+1,(ring2fit[i]->GetParameter(3))); ring2prec2->SetBinError(i+1,ring2fit[i]->GetParError(3)); cout<<"ring2 "<<i<<" "<<ring2fit[i]->GetParameter(3)<<" "<<ring2fit[i]->GetParError(3)<<endl; } for(int i = 0; i < ntowers; i++){ char name[100]; sprintf(name,"electron_fit_%i",i+1); /* fit[i] = new TF1(name,"pol1(0)+gaus(2)"); fit[i]->SetParLimits(0,0,10.0*electron_histo[i]->GetBinContent(1)); fit[i]->SetParLimits(1,-10000,0); fit[i]->SetParLimits(2,0,10.0*electron_histo[i]->GetMaximum()); fit[i]->SetParLimits(3,0,10); fit[i]->SetParameter(0,electron_histo[i]->GetBinContent(1)); fit[i]->SetParameter(1,-electron_histo[i]->GetBinContent(1)/6.0); fit[i]->SetParameter(2,electron_histo[i]->GetMaximum()); fit[i]->SetParameter(3,0.95); fit[i]->SetParameter(4,0.15); fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); */ fit[i] = new TF1(name,"pol0(0)+gaus(1)"); fit[i]->SetParLimits(0,0,10.0*electron_histo[i]->GetBinContent(1)); fit[i]->SetParLimits(1,0,10.0*electron_histo[i]->GetMaximum()); fit[i]->SetParLimits(2,0,10); fit[i]->SetParameter(0,electron_histo[i]->GetBinContent(1)); fit[i]->SetParameter(1,electron_histo[i]->GetMaximum()); fit[i]->SetParameter(2,0.95); fit[i]->SetParameter(3,0.15); fit[i]->SetParNames("constant1","constant2","Mean","Sigma"); electron_histo[i]->Fit(fit[i],"rql","",0.3,1.7); } ofstream fitfile(ffname); TF1* etacrate_fit[ncrates*20]; for(int ii = 0; ii < ncrates; ii++){ for(int j = 0; j < 20; j++){ TString ecname; ecname += "fit"; int cr = ii+1; int et = j; int i = ii*20 + j; //ecname += cr; //ecname += "_"; //ecname += et; etacrate_fit[i] = new TF1(ecname.Data(),"pol1(0) + gaus(2)",0.25,1.6); //etacrate_fit[i]->SetParLimits(0,0,10.0*etacrate_histo[i]->GetBinContent(1)); etacrate_histo[i]->Rebin(); etacrate_fit[i]->SetParLimits(1,-10000,0); etacrate_fit[i]->SetParLimits(2,0,10.0*etacrate_histo[i]->GetMaximum()); etacrate_fit[i]->SetParLimits(3,0,10); etacrate_fit[i]->SetParameter(0,etacrate_histo[i]->GetBinContent(2)); etacrate_fit[i]->SetParameter(1,-etacrate_histo[i]->GetBinContent(2)/3.0); etacrate_fit[i]->SetParameter(2,etacrate_histo[i]->GetMaximum()); etacrate_fit[i]->SetParameter(3,0.96134); etacrate_fit[i]->SetParameter(4,0.141123); etacrate_fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); etacrate_histo[i]->Fit(etacrate_fit[i],"rql","",0.25,1.5); etacrate_histo_p[i]->Fit(etacrate_fit[i],"rql","",0.25,1.5); etacrate_histo_n[i]->Fit(etacrate_fit[i],"rql","",0.25,1.5); fitfile << i << " " << etacrate_histo[i]->GetFunction("fit")->GetParameter(3) << " " << etacrate_histo_p[i]->GetFunction("fit")->GetParameter(3) << " " << etacrate_histo_n[i]->GetFunction("fit")->GetParameter(3) << endl; } } ofstream newgain(ngname); float gains2[ntowers]; float gerr2[ntowers]; for(int i = 0; i < ntowers; i++){ float eta = helper->getEta(i+1); int crate,sequence; decoder->GetCrateFromTowerId(i+1,crate,sequence); int geantetaindex = ((TMath::Nint(fabs(eta) * 1000.0) + 25)/50 - 1); TString ecname; ecname += "fit"; //int cr = ii+1; //int et = j; //int i = ii*20 + j; //ecname += crate; //ecname += "_"; //ecname += geantetaindex; if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta; int etaindex = ((TMath::Nint(eta * 1000.0) + 25)/50 + 19); //float adjust = ring2fit[(int)etaindex/2]->GetParameter(3); //cout<<etaindex<<" "<<(int)etaindex/2<<" "<<adjust<<endl; //float adjust = fit[i]->GetParameter(3); float ng = 0; float ne = 0; if(status[i] == 1){ //float og = bemctables->calib(1,i+1)*gains[i]; float og = gains[i]; //float aerr = ring2fit[(int)etaindex/2]->GetParError(3); float adjust = etacrate_histo[(crate-1)*20+geantetaindex]->GetFunction("fit")->GetParameter(3); float aerr = etacrate_histo[(crate-1)*20+geantetaindex]->GetFunction("fit")->GetParError(3); if(geantetaindex == 19){ adjust = ringfit[etaindex]->GetParameter(3); aerr = ringfit[etaindex]->GetParError(3); } ng = og/adjust; float gerr = peakerr[i]*gains[i]/peaks[i]; ne = sqrt(pow(og*aerr/(adjust*adjust),2) + pow(gerr/adjust,2)); } newgain << i+1 << " " << ng << " " << ne << " " << status[i] << endl; gains2[i] = ng; gerr2[i] = ne; } newgain.close(); /////////////////////////////////////// //Using new gains regenerate by crate// /////////////////////////////////////// /* for(int j=0; j<nentries; j++){ tree->GetEntry(j); track = &(cluster->centralTrack); TClonesArray *tracks = cluster->tracks; int bsmdeadctot = 0; int bsmdpadctot = 0; for(int i = 0; i < 11; i++){ if(track->smde_adc[i] > track->smde_pedestal[i])bsmdeadctot += track->smde_adc[i] - track->smde_pedestal[i]; if(track->smdp_adc[i] > track->smdp_pedestal[i])bsmdpadctot += track->smdp_adc[i] - track->smdp_pedestal[i]; } double dR = TMath::Sqrt(track->deta*track->deta + track->dphi*track->dphi); double scaled_adc = (track->tower_adc[0] - track->tower_pedestal[0]) / track->p; double geant_scale = geant_fit->Eval(dR); scaled_adc *= geant_scale; //cout<<scaled_adc<<endl; int index = track->tower_id[0]; //figure out eta and etaindex eta = helper->getEta(index); if(TMath::Abs(eta) > 0.968) eta += 0.005 * TMath::Abs(eta)/eta; etaindex = ((TMath::Nint(eta * 1000.0) + 25)/50 + 19); double tgain = bemctables->calib(1,track->tower_id[0])*gains[index-1]*gains2[index-1]; //double tgain = gains[index-1]; if((track->tower_adc[0] - track->tower_pedestal[0]) < 2.5 * track->tower_pedestal_rms[0])continue; if(track->tower_id[0] != track->tower_id_exit)continue; if(track->htTrig == 2)continue; if(track->p > 6)continue; if(dR > 0.025)continue; if(track->dEdx < 3.4e-6)continue; if((bsmdeadctot > -1 && bsmdeadctot < 50) && (bsmdpadctot < 50 && bsmdpadctot > -1))continue; int numsis = tracks->GetEntries(); if(numsis > 0)continue; float totalbtow = 0; float maxEt = 0; int maxId = -1; for(int i = 0; i < 9; i++){ if(track->tower_adc[i] - track->tower_pedestal[i] < 0)continue; float theta = helper->getTheta(track->tower_id[i]); float nextEt = (track->tower_adc[i] - track->tower_pedestal[i]) * bemctables->calib(1,track->tower_id[i])*sin(theta); totalbtow += nextEt; if(nextEt > maxEt){ maxEt = nextEt; maxId = i; } } if(maxId != 0) continue; eta = helper->getEta(index); float phi = helper->getPhi(index); int crate = lookup_crate(eta,phi); if(status[index-1]==1)crate_histo[crate-1]->Fill(scaled_adc*tgain); } for(int i = 0; i < ncrates; i++){ sprintf(name,"crate_fit_%i",i); crate_histo[i]->Sumw2(); crate_histo[i]->Rebin(4); crate_fit[i] = new TF1(name,"pol1(0) + gaus(2)",0.3,1.7); crate_fit[i]->SetParLimits(0,0,10.0*crate_histo[i]->GetBinContent(1)); crate_fit[i]->SetParLimits(1,-10000,0); crate_fit[i]->SetParLimits(2,0,10.0*crate_histo[i]->GetMaximum()); crate_fit[i]->SetParLimits(3,0,10); crate_fit[i]->SetParameter(0,crate_histo[i]->GetBinContent(1)); crate_fit[i]->SetParameter(1,-crate_histo[i]->GetBinContent(1)/6.0); crate_fit[i]->SetParameter(2,-crate_histo[i]->GetMaximum()); crate_fit[i]->SetParameter(3,0.929); crate_fit[i]->SetParameter(4,0.156); crate_fit[i]->SetParNames("constant1","Slope","constant2","Mean","Sigma"); crate_fit[i]->SetLineColor(kBlue); crate_fit[i]->SetLineWidth(0.6); crate_histo[i]->Fit(crate_fit[i],"rql","",0.3,1.8); float mean = crate_histo[i]->GetFunction(name)->GetParameter(3); float merr = crate_histo[i]->GetFunction(name)->GetParError(3); crateprec->SetBinContent(i+1,mean); crateprec->SetBinError(i+1,merr); cout<<"crate "<<i+1<<" "<<mean<<" "<<merr/mean<<endl; } ofstream newgain(ngname); float gains3[ntowers]; float gerr3[ntowers]; for(int i = 0; i < ntowers; i++){ float eta = helper->getEta(i+1); float phi = helper->getPhi(i+1); int crate = lookup_crate(eta,phi); float adjust = crate_fit[crate-1]->GetParameter(3); float og = bemctables->calib(1,i)*gains[i]*gains2[i]; float ng = og; float aerr = crate_fit[crate-1]->GetParError(3); float ne = sqrt(pow(gains[i]*gerr2[i],2) + pow(gains2[i]*gainerr[i],2)); if(fabs(adjust-1)/aerr > 1.5){ ne = sqrt(pow(ne/(adjust),2)+pow(og*aerr/(adjust*adjust),2)); ng /= adjust; } newgain << i+1 << " " << ng << " " << ne << " " << status[i] << endl; gains3[i] = ng; gerr3[i] = ne; } newgain.close(); */ outfile.Write(); outfile.Close(); }
void plot_figure(TString fn,TPad *thePad,bool saxis=false,float ymin=-2.0,float ymax=1.0,bool with_d=false) { //cout<<"wit"<<with_d<<endl; gStyle->SetOptFit(); gStyle->SetPadTickY(1); gStyle->SetLineStyleString(11,"40 20"); float xmin=0,xmax=2; thePad->cd(); //thePad->SetGrid(); /***************************************************** Colors *****************************************************/ int HRMcol=kRed+2; int RNAcol=kMagenta; int QGScol=kGreen+1; float kb2b=1000; Double_t x,y; /***************************************************** Format the pad *****************************************************/ thePad->SetTopMargin(0.15); TH1F *hr = thePad->DrawFrame(xmin,ymin,xmax,ymax); hr->SetXTitle("Q (GeV)"); hr->SetYTitle("t_{20}"); /*hr->GetYaxis()->SetTitleOffset(1.5); hr->GetYaxis()->SetTitleSize(.06); hr->GetYaxis()->SetTitleFont(42); hr->GetYaxis()->CenterTitle(); hr->GetXaxis()->SetTitleSize(.06); hr->GetXaxis()->SetTitleFont(42); *//***************************************************** Draw legend *****************************************************/ TLegend *dummylegend=new TLegend(); TLegend *legend=new TLegend(0.59,0.17,0.94,0.55); legend->SetMargin(0.2); legend->SetTextFont(72); legend->SetTextSize(0.035); legend->SetFillStyle(0); legend->SetBorderSize(0); legend->Draw(); TLegend *thlegend=new TLegend(0.23,0.64,0.57,0.84); thlegend->SetMargin(0.2); thlegend->SetTextFont(72); thlegend->SetTextSize(0.035); thlegend->SetFillStyle(0); thlegend->SetBorderSize(0); thlegend->Draw(); thePad->SetLeftMargin(0.19); /***************************************************** Draw top axis *****************************************************/ float titlex1=0.47, titley1=0.85,titlex2=0.56,titley2=0.95; if (saxis) { titley1=0.72;titley2=0.82; TGaxis *axispp = new TGaxis(thePad->GetUxmin(),thePad->GetUymax()*1, thePad->GetUxmax(), thePad->GetUymax()*1, xmin*0.1973, xmax*0.1973,510,"-R"); axispp->SetTitle("Q (GeV)"); axispp->SetLabelFont(42); axispp->SetLabelSize(0.04); axispp->SetTitleFont(42); axispp->SetTitleSize(.055); axispp->Draw(); } /***************************************************** Make Title *****************************************************/ //TPaveLabel *label = new TPaveLabel(titlex1,titley1,titlex2,titley2,"^{3}He(#gamma,pp)n","NDC"); //label->SetTextSize(0.7); //label->SetFillStyle(0); //label->SetTextFont(42); //label->SetBorderSize(0); //label->Draw(); //TPaveLabel *label = new TPaveLabel(titlex1,titley1-0.06,titlex2,titley2-0.06,"90#circc.m.","NDC"); //label->SetTextSize(0.5); //label->SetFillStyle(0); //label->SetTextFont(42); //label->SetBorderSize(0); //label->Draw(); /*-------------------------------------------------------------------------------------- Constants? ---------------------------------------------------------------------------------------*/ Double_t xmd = 1.875613; Double_t xmdsq = xmd*xmd; Double_t q0sq = 1.15; Double_t degr = 0.01745329252; Double_t xhbarc = 0.1973; /*-------------------------------------------------------------------------------------- Plot IMII modelfor t20 ---------------------------------------------------------------------------------------*/ const Int_t npt = 94; //Double_t x, y; Double_t qfm[npt]; Double_t qsqpt[npt] = {0.0003893797, 0.003893797, 0.03893797, 0.05840695, 0.07787593, 0.09734491, 0.1168139, 0.1362829, 0.1557519, 0.1752208, 0.1946898, 0.2530968, 0.3115037, 0.3893797, 0.4672556, 0.5451315, 0.6230075, 0.7008834, 0.7787593, 0.8566352, 0.9345112, 1.012387, 1.090263, 1.168139, 1.246015, 1.323891, 1.401767, 1.479643, 1.557519, 1.596457, 1.635395, 1.674333, 1.71327, 1.752208, 1.810615, 1.830084, 1.869022, 1.90796, 1.946898, 1.985836, 2.024774, 2.063712, 2.10265, 2.141588, 2.180526, 2.219464, 2.258402, 2.29734, 2.336278, 2.375216, 2.414154, 2.453092, 2.49203, 2.530968, 2.569906, 2.608844, 2.647782, 2.68672, 2.725658, 2.803534, 2.881409, 2.959285, 3.037161, 3.115037, 3.309727, 3.504417, 3.699107, 3.893797, 4.088486, 4.283176, 4.477866, 4.672556, 4.867246, 5.061936, 5.256625, 5.451315, 5.646005, 5.840695, 6.035385, 6.230075, 6.424764, 6.619454, 6.716799, 6.814144, 6.911489, 7.008834, 7.106179, 7.203524, 7.300869, 7.398214, 7.495558, 7.592903, 7.690248, 7.787593}; Double_t t20theory[npt] = {-0.001309568, -0.0131055, -0.1318868, -0.1984704, -0.2654408, -0.3327329, -0.4002368, -0.4677915, -0.5351828, -0.6021447, -0.668362, -0.8587877, -1.027779, -1.198694, -1.286326, -1.282388, -1.197382, -1.054978, -0.8820486, -0.7009335, -0.5265257, -0.3668914, -0.2252485, -0.1019077, 0.004321276, 0.09524616, 0.1728195, 0.238883, 0.2950801, 0.3199333, 0.3428342, 0.3639258, 0.3833423, 0.4012027, 0.4253075, 0.432676, 0.4464807, 0.4591073, 0.4706305, 0.4811208, 0.4906344, 0.4992296, 0.506956, 0.5138575, 0.5199757, 0.5253475, 0.5300049, 0.5339787, 0.5372949, 0.539977, 0.5420477, 0.5435232, 0.5444235, 0.5447623, 0.5445543, 0.5438103, 0.5425456, 0.540766, 0.5384844, 0.5324458, 0.5245013, 0.514713, 0.5031468, 0.4898722, 0.4497016, 0.4006593, 0.3444063, 0.2827923, 0.2178549, 0.1514989, 0.08547981, 0.02124835, -0.04018853, -0.09806195, -0.1520174, -0.2019219, -0.2477681, -0.2898, -0.3282607, -0.3633281, -0.3951718, -0.4241511, -0.4375907, -0.4502916, -0.4622216, -0.473322, -0.4835232, -0.4927239, -0.500801, -0.5076282, -0.513053, -0.516797, -0.5184837, -0.5176145}; //FILE *fp = fopen("im2.dat","r"); for (Int_t i=0;i<npt;i++) { // Int_t ncols = fscanf(fp,"%f, %f",&x, &y); // qsqpt[i] = x; // t20theory[i] = y; qfm[i] = qsqpt[i]**(0.5)/xhbarc; // printf(" line %d read: %f %f \n",i,qsqpt[i],t20theory[i]); } //fclose(fp); //TGraph* gQGS=new TGraph("log170_89.dat","%lg %lg"); gQGS = new TGraph(npt,qsqpt,t20theory); gQGS->SetLineColor(kMagenta); gQGS->SetMarkerStyle(20); gQGS->SetMarkerSize(1.3); gQGS->SetLineStyle(11); gQGS->SetLineWidth(2); gQGS->Draw("l"); thlegend->AddEntry(gQGS,"IMII","L"); /*-------------------------------------------------------------------------------------- Plot IMII+ME modelfor t20 ---------------------------------------------------------------------------------------*/ Double_t t20theoryme[npt] = {-0.001325945, -0.01328168, -0.1349228, -0.2041014, -0.2743705, -0.3456319, -0.4177289, -0.4904376, -0.5634585, -0.6364107, -0.7088243, -0.9168859, -1.095754, -1.251422, -1.277469, -1.170903, -0.9677308, -0.7200701, -0.4713423, -0.2466468, -0.05555869, 0.101535, 0.2283672, 0.3298602, 0.4107891, 0.4752683, 0.5266488, 0.567598, 0.6002075, 0.6139116, 0.6261154, 0.6369641, 0.6465931, 0.6551208, 0.6660647, 0.6692667, 0.6750632, 0.6801088, 0.6844693, 0.6882072, 0.6913724, 0.694014, 0.6961743, 0.6978924, 0.6992062, 0.7001432, 0.7007343, 0.701005, 0.7009771, 0.7006715, 0.7001097, 0.6993112, 0.6982906, 0.6970643, 0.6956426, 0.6940377, 0.6922587, 0.6903158, 0.6882191, 0.6836015, 0.6784688, 0.6728624, 0.6668122, 0.6603509, 0.6425963, 0.622676, 0.6008623, 0.5773537, 0.5521636, 0.5259722, 0.4991099, 0.4706432, 0.4410795, 0.4127616, 0.3872456, 0.3640124, 0.3422358, 0.3246932, 0.3143134, 0.3116054, 0.3142227, 0.3184956, 0.3200235, 0.3212056, 0.3227668, 0.3250734, 0.3281051, 0.3321319, 0.3372873, 0.3437867, 0.351448, 0.3600231, 0.3689893, 0.3779735}; TGraph* gRNA=new TGraph(npt,qsqpt,t20theoryme); gRNA->SetLineColor(kRed); gRNA->SetMarkerStyle(1); gRNA->SetMarkerSize(1.3); gRNA->SetLineStyle(11); gRNA->SetLineWidth(3); gRNA->Draw("l"); thlegend->AddEntry(gRNA,"IM+E II","L"); /*-------------------------------------------------------------------------------------- Dan Phillips no rpg(f/g=0) ---------------------------------------------------------------------------------------*/ const Int_t nph = 66; Double_t qph[nph] = { 0.01, 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 47.5, 50.0, 52.5, 55.0, 57.5, 60.0, 62.5, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0}; for (Int_t i=0;i<nph;i++) {qph[i] = qph[i]*xhbarc**2;} Double_t tphrpg0[nph] = {-0.00139028, -0.0347797, -0.0705278, -0.106823, -0.143214, -0.215941, -0.28903, -0.36176, -0.437352, -0.594782, -0.753442, -0.905365, -1.04209, -1.14824, -1.2301, -1.27076, -1.26585, -1.21681, -1.13043, -1.01648, -0.885684, -0.7701, -0.630809, -0.495011, -0.366781, -0.248492, -0.141153, -0.0449377, 0.0407569, 0.116675, 0.183835, 0.230211, 0.284553, 0.332797, 0.375647, 0.41358, 0.447136, 0.476061, 0.502346, 0.525668, 0.546396, 0.561598, 0.57851, 0.593626, 0.607141, 0.619222, 0.630017, 0.638943, 0.647659, 0.655433, 0.662379, 0.675447, 0.686163, 0.693653, 0.698255, 0.70103, 0.701985, 0.701414, 0.699577, 0.696913, 0.68897, 0.68092, 0.673572, 0.668027, 0.665207, 0.664439}; TGraph* gph=new TGraph(nph,qph,tphrpg0); gph->SetLineColor(9); gph->SetMarkerStyle(1); gph->SetMarkerSize(1.3); gph->SetLineStyle(1); gph->SetLineWidth(3); gph->Draw("l"); thlegend->AddEntry(gph,"#rho#pi#gamma f/g=0","L"); Double_t tphrpg3[nph] = {-0.00139212, -0.0348353, -0.0706589, -0.10705, -0.143559, -0.216597, -0.290087, -0.363321, -0.439532, -0.598654, -0.759312, -0.913351, -1.0519, -1.15918, -1.24066, -1.27901, -1.2698, -1.21493, -1.12197, -1.00156, -0.865071, -0.744981, -0.60214, -0.464095, -0.334789, -0.216384, -0.109662, -0.0145868, 0.069612, 0.143819, 0.20915, 0.254731, 0.307099, 0.353368, 0.394259, 0.43028, 0.461982, 0.489554, 0.51413, 0.535803, 0.554941, 0.568991, 0.584356, 0.59797, 0.610026, 0.620686, 0.630093, 0.63772, 0.645084, 0.651525, 0.657156, 0.666024, 0.673624, 0.678127, 0.679481, 0.67949, 0.677837, 0.674823, 0.670722, 0.662356, 0.650039, 0.638996, 0.628928, 0.620671, 0.614933, 0.610454}; //TGraph* gph3=new TGraph(nph,qph,tphrpg3); //gph3->SetLineColor(39); //gph3->SetMarkerStyle(1); //gph3->SetMarkerSize(1.3); //gph3->SetLineStyle(2); //gph3->SetLineWidth(2); //TPaveLabel * Label = new TPaveLabel(0.20,0.66,0.48,0.71,"Propagator f/g=3","NDC"); //Label->SetTextSize(0.6); //Label->SetLineColor(kWhite); //Label->SetFillColor(kWhite); //Label->SetTextColor(39); //Label->SetBorderSize(0); //Label->Draw(); //gph3->Draw("l"); Double_t tphrpg6[nph] = {-0.00139403, -0.0348929, -0.0707944, -0.107286, -0.143917, -0.217276, -0.29118, -0.364936, -0.441787, -0.602659, -0.765378, -0.921581, -1.06195, -1.17027, -1.25116, -1.28686, -1.27292, -1.21183, -1.11202, -0.985056, -0.84299, -0.718589, -0.572616, -0.432822, -0.302967, -0.184961, -0.0793357, 0.0141671, 0.0964853, 0.168642, 0.231842, 0.276257, 0.326398, 0.370465, 0.409197, 0.443123, 0.472809, 0.498773, 0.52149, 0.541377, 0.558796, 0.571442, 0.58515, 0.597161, 0.607665, 0.616818, 0.624764, 0.630973, 0.636932, 0.642002, 0.646291, 0.650319, 0.654857, 0.656509, 0.654827, 0.652371, 0.648479, 0.643459, 0.637587, 0.622962, 0.607813, 0.595048, 0.583592, 0.574033, 0.566854, 0.560502}; TGraph* gph6=new TGraph(nph,qph,tphrpg6); gph6->SetLineColor(49); gph6->SetMarkerStyle(1); gph6->SetMarkerSize(1.3); gph6->SetLineStyle(1); gph6->SetLineWidth(2); gph6->Draw("l"); thlegend->AddEntry(gph6,"#rho#pi#gamma f/g=6.1","L"); /*-------------------------------------------------------------------------------------- put line at -root(2) ---------------------------------------------------------------------------------------*/ Int_t n = 2; float xfm[2] = {0., 9.}; float yt20[2] = {0., 0.}; TGraph* g0=new TGraph(n,xfm,yt20); g0->SetLineColor(1); g0->SetMarkerStyle(1); g0->SetMarkerSize(1.3); g0->SetLineStyle(1); g0->SetLineWidth(1); g0->Draw("l"); yt20[0] = -1.*2**(0.5); yt20[1] = yt20[0]; xfm[1] = 1.; TGraph* g1=new TGraph(n,xfm,yt20); g1->SetLineColor(1); g1->SetMarkerStyle(1); g1->SetMarkerSize(1.3); g1->SetLineStyle(3); g1->SetLineWidth(1); g1->Draw("l"); /* sanity checks plots11dsdtSet(100,0.040,0.020,0.05,0.000,0.140,kBlack,legend,"E03-101 140 MeV Bins Pn< 100 Mev/c 80 mr X 40 mr"); */ /* PRL */ //plotSet(kBlue,legend,"T_{20}"); //plotSet(kBlue,legend,""); plotSet(kBlue,legend,""); //plots11dsdtSet(kBlue,legend,""); /***************************************************** Add the rest of the legend enteries *****************************************************/ //if(!with_d){ //legend->AddEntry(gQGS,"QGS","l"); //legend->AddEntry(gRNA,"RNA","l"); //legend->AddEntry(gHRM,"HRM","F"); //}; gStyle->SetPaperSize(20,26); //default //TPaveLabel *label = new TPaveLabel(0.5,0.4,0.85,0.5,"Preliminary","NDC"); //label->SetTextColor(kBlue); //label->Draw(); //cout<<with_d<<endl; c->SaveAs(fn+".pdf"); c->SaveAs(fn+".eps"); c->SaveAs(fn+".png"); }
void tpcanalall(Int_t isec =1, Int_t lstep = 1,Float_t tmin=400) { AliTPCParam * tpcparam = gtpc->GetParam(); //make window for displaying results TCanvas * c_occu = new TCanvas("coccu","Occupancy dependence",700,900); c_occu->Update(); TPad * pad1 = new TPad("occupancy","occupancy",0.05,0.25,0.95,0.95,21); pad1->Draw(); //add comments to the histograms TPaveText * comment = new TPaveText(0.05,0.03,0.95,0.2,"NDC"); comment->SetTextAlign(12); comment->SetFillColor(42); comment->ReadFile("comment.txt"); comment->Draw(); //prepare histogram Int_t irow = tpcparam->GetNRow(isec); Float_t xmin = tpcparam->GetPadRowRadii(isec,1); Float_t xmax = tpcparam->GetPadRowRadii(isec,irow); pad1->cd(); char s[220]; char sh[220]; sprintf(s,"occu_sector%d",isec); sprintf(sh,"Occupancy in sector %d as function of pad raw",isec); TH1F * occudep = new TH1F(s,sh,300,xmin,xmax); Float_t res[20]; Float_t x; for (Int_t i=2;i<irow;i+=lstep) { tpcanal(isec,i,10,&res[0],kFALSE,tmin); x = tpcparam->GetPadRowRadii(isec,i) ; Int_t index = (300*(x-xmin))/(xmax-xmin); cout<<i<<" "<<index<<" "<<x<<" "<<res[0]<<" "<<res[1]<<"\n"; occudep->SetBinContent(index,res[0]); occudep->SetBinError(index,res[1]); } //plot occupancy histogram pad1->SetGridx(); pad1->SetGridy(); gStyle->SetOptFit(0); occudep->Draw("error"); occudep->SetXTitle("pad row center position [cm]"); occudep->SetYTitle("occupancy"); //fit occupancy dependence //linear fit TF1 * g1 = new TF1("pol1_r","pol1"); occudep->Fit("pol1_r","+Q"); Double_t par[3]; Float_t error[3]; Float_t chi; g1->GetParameters(&par[0]); error[0]=g1->GetParError(0); error[1]=g1->GetParError(1); Float_t chi = g1->GetChisquare(); sprintf(s,"Linear fit ocupancy = (%2.3f - %2.3f) +(%2.1f+- %2.1f).r chi2 = %2.2f", par[0],error[0],1000*par[1],1000*error[1],chi); comment->AddText(s); //(1-exp([0]1/(r*2+[1]**2) fit TF1 * g1 = new TF1("polm1",occur,1,00,1); occudep->Fit("polm1","+Q"); Double_t par[3]; Float_t error[3]; g1->GetParameters(&par[0]); error[0]=g1->GetParError(0); // error[1]=g1->GetParError(1); chi = g1->GetChisquare(); sprintf(s,"(1-exp(P1/(x^2) fit P1=(%2.3f+- %2.3f) chi2=%2.2f ", par[0],error[0],chi); comment->AddText(s); c_occu->Update(); }
void merge_pbpb_pp_HLT(){ TH1::SetDefaultSumw2(); //TFile *fpbpb1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet80_v2.root"); //TFile *fpbpb2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet65_v2.root"); //TFile *fpbpb3 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet55_v2.root"); //TFile *fpp1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet80.root"); //TFile *fpp2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet40.root"); TFile *fpp1_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet80_v2.root"); TFile *fpp2_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet40_v2.root"); /* TTree *jetpbpb1_v2 = (TTree*)fpbpb1->Get("jetR3"); TTree *jetpbpb2_v2 = (TTree*)fpbpb2->Get("jetR3"); TTree *jetpbpb3_v2 = (TTree*)fpbpb3->Get("jetR3"); TTree *evtpbpb1_v2 = (TTree*)fpbpb1->Get("evt"); TTree *evtpbpb2_v2 = (TTree*)fpbpb2->Get("evt"); TTree *evtpbpb3_v2 = (TTree*)fpbpb3->Get("evt"); jetpbpb1_v2->AddFriend(evtpbpb1_v2); jetpbpb2_v2->AddFriend(evtpbpb2_v2); jetpbpb3_v2->AddFriend(evtpbpb3_v2); */ //TTree *jetpp1 = (TTree*)fpp1->Get("ntjet"); // TTree *jetpp2 = (TTree*)fpp2->Get("ntjet"); TTree *jetpp1_v2 = (TTree*)fpp1_v2->Get("jetR3"); TTree *jetpp2_v2 = (TTree*)fpp2_v2->Get("jetR3"); TTree *evtpp1_v2 = (TTree*)fpp1_v2->Get("evt"); TTree *evtpp2_v2 = (TTree*)fpp2_v2->Get("evt"); jetpp1_v2->AddFriend(evtpp1_v2); jetpp2_v2->AddFriend(evtpp2_v2); //TCut pbpb3 = "abs(eta)<2&&jet55&&!jet65&&!jet80&&chMax/pt>0.01"; TCut pp3 = "abs(eta)<2&&jet40&&!jet60&&!jet80&&chMax/pt>0.01"; //TH1F *hpbpb1 = new TH1F("hpbpb1","",30,0,300); //TH1F *hpbpb2 = new TH1F("hpbpb2","",30,0,300); //TH1F *hpbpb3 = new TH1F("hpbpb3","",30,0,300); //TH1F *hpbpbComb = new TH1F("hpbpbComb","",30,0,300); TH1F *hpp1 = new TH1F("hpp1","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp2 = new TH1F("hpp2","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp3 = new TH1F("hpp3","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hppComb = new TH1F("hppComb","",nbins_jetPtBin,boundaries_jetPtBin); //get the prescl factor information. //Float_t presclpbpb3 = (Float_t)jetpbpb1_v2->GetEntries("jet80")/jetpbpb1_v2->GetEntries("jet55&&jet80"); //cout<<"pbpb prescl3 = "<<presclpbpb3<<endl;//1.99871 Float_t presclpp3 = (Float_t)jetpp1_v2->GetEntries("jet80")/jetpp1_v2->GetEntries("jet40&&jet80"); cout<<"pp prescl3 = "<<presclpp3<<endl; //9.24968 /* jetpbpb1_v2->Project("hpbpb1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpbpb1->Print("base"); divideBinWidth(hpbpb1); jetpbpb2_v2->Project("hpbpb2","pt","abs(eta)<2&&jet65&&!jet80&&chMax/pt>0.01"); hpbpb2->Print("base"); divideBinWidth(hpbpb2); jetpbpb3_v2->Project("hpbpb3","pt","1.9987"*pbpb3); hpbpb3->Print("base"); divideBinWidth(hpbpb3); */ jetpp1_v2->Project("hpp1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpp1->Print("base"); //divideBinWidth(hpp1); //hpp1->Scale(1./3.083e11); //hpp1->Scale(1./4); jetpp2_v2->Project("hpp2","pt","abs(eta)<2&&jet60&&!jet80&&chMax/pt>0.01"); hpp2->Print("base"); //divideBinWidth(hpp2); //hpp2->Scale(1./3.083e11); //hpp2->Scale(1./4); jetpp2_v2->Project("hpp3","pt","9.25038"*pp3); //9.25038 - ak5 //9.24955 - ak4 //9.24968 - ak3 hpp3->Print("base"); //divideBinWidth(hpp3); //hpp3->Scale(1./3.083e11); //hpp3->Scale(1./4); //scale the PbPb histograms before adding them //we have to scale them according to the lumi of the Jet80 file. // HLT file | Lumi // HLT_80 | 150 mub-1 // HLT_65 | 12.1 mub-1 // HLT_55 | 0.38 mub-1 // // therefore scale for HLT_55 = 150/0.38 = 394.73684 // scale for HLT_65 = 150/12.1 = 12.3967 //hpbpb2->Scale(12.3867); //hpbpb3->Scale(394.7368); //add the histograms /* hpbpbComb->Add(hpbpb1,1); hpbpbComb->Add(hpbpb2,1); hpbpbComb->Add(hpbpb3,1); hpbpbComb->Print("base"); */ hppComb->Add(hpp1,1); hppComb->Add(hpp2,1); hppComb->Add(hpp3,1); hppComb->Print("base"); /* TCanvas *c1 = new TCanvas("c1","",800,600); c1->SetLogy(); hpbpbComb->SetMarkerStyle(29); //hpbpbComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hpbpbComb->SetYTitle("counts"); hpbpbComb->SetXTitle("Jet p_{T} GeV/c"); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]*pow(x+[1],[2])"); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Draw(); hpbpb3->SetMarkerStyle(24); hpbpb3->SetMarkerColor(kRed); hpbpb3->Draw("same"); hpbpb2->SetMarkerStyle(25); hpbpb2->SetMarkerColor(kBlue); hpbpb2->Draw("same"); hpbpb1->SetMarkerStyle(26); hpbpb1->SetMarkerColor(kGreen); hpbpb1->Draw("same"); TLegend *title = myLegend(0.54,0.65,0.85,0.9); title->AddEntry(hpbpbComb,"PbPb Merged","pl"); title->AddEntry(hpbpb3,"w_{3} * (HLT_55 && !HLT_65 && !HLT_80)","pl"); title->AddEntry(hpbpb2,"HLT_65 && !HLT_80","pl"); title->AddEntry(hpbpb1,"HLT_80","pl"); title->SetTextSize(0.03); title->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c1->SaveAs("pbpb_2013_pt_combined.gif","RECREATE"); */ //plot the statistical uncertainty here //statistical error/meanvalue as a function of pt for the combined spectra. /* TCanvas *c2 = new TCanvas("c2","",800,600); //TH1F* hPbPb_Uncert = (TH1F*)hpbpbComb->Clone("hPbPb_Uncert"); TH1F* hPbPb_Uncert = new TH1F("hPbPb_Uncert","",30,0,300); for(int i = 1;i<=hpbpbComb->GetNbinsX();i++){ double val = hpbpbComb->GetBinContent(i); double valErr = hpbpbComb->GetBinError(i); double uncert = (double)valErr/val; cout<<"uncert = "<<uncert<<endl; hPbPb_Uncert->SetBinContent(i,uncert); hPbPb_Uncert->SetBinError(i,0); } hPbPb_Uncert->SetYTitle("uncertainty"); hPbPb_Uncert->SetXTitle("p_{T} GeV/c"); hPbPb_Uncert->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c2->SaveAs("pbpb_2013_hlt_merge_scaled_uncert.gif","RECREATE"); */ TCanvas *c2 = new TCanvas("c2","",800,600); c2->SetLogy(); TH1F* hPPComb = (TH1F*)hppComb->Clone("hPPComb"); //TH1F* hPPComb_bins = rebin_yaxian(hppComb,"hPPComb_bins"); hPPComb->Scale(1./3.083e11); hPPComb->Print("base"); hPPComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hPPComb->SetXTitle("Jet p_{T} GeV/c"); //hPPComb_bins->Scale(1./3.083e11); //hPPComb_bins->Print("base"); //hPPComb_bins->Scale(1./4); //divideBinWidth(hPPComb_bins); hPPComb->Scale(1./4); divideBinWidth(hPPComb); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]/pow(x,[1])"); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->SetMarkerColor(kBlue); hPPComb->SetMarkerStyle(26); hPPComb->SetTitle("PP2013 ak3PF"); hPPComb->Draw(); //hPPComb_bins->SetMarkerColor(kRed); //hPPComb_bins->SetMarkerStyle(23); //hPPComb_bins->Draw("same"); c2->SaveAs("pp_2013_ak3_pt_evt_frac_merged.gif","RECREATE"); TCanvas *c5 = new TCanvas("c5","",800,600); TH1F* hppFunc = (TH1F*)functionHist(fPowerLaw,hppComb,"Fit Function p_{T} spectra PP 2013 merged"); TH1F* hPPRatio = (TH1F*)hppComb->Clone("hPPRatio"); hPPRatio->Divide(hppFunc); hPPRatio->SetTitle("Spectra to Fit Ratio"); hPPRatio->SetXTitle("Jet p_{T} GeV/c"); hPPRatio->SetYTitle("Measured data/Fit"); hPPRatio->SetMarkerStyle(8); hPPRatio->SetMarkerColor(4); hPPRatio->Draw(); c5->SaveAs("pp_2013_merged_spectra_fit_comp.gif","RECREATE"); TFile *fpbpbunfo = TFile::Open("result-2013-akPu3PF-cent-6-isFineBin-0/pbpb_pp_merged_chmx_pt_Unfo_2013_akPu3PF_cent_6_isFineBin_0.root"); TH1F* hppUnfo = (TH1F*)fpbpbunfo->Get("Unfolded_cent6"); TH1F* hPPGen = (TH1F*)fpbpbunfo->Get("hGen_cent6"); hppUnfo->Print("base"); hPPGen->Print("base"); hPPGen->Scale(1./4); divideBinWidth(hPPGen); hppUnfo->Scale(1./3.083e11); hppUnfo->Scale(1./4); divideBinWidth(hppUnfo); hppUnfo->Divide(hPPGen); TCanvas *c6 = new TCanvas("c6","",800,600); hppUnfo->SetMarkerStyle(21); hppUnfo->SetMarkerColor(kRed); hPPGen->SetMarkerStyle(21); hPPGen->SetMarkerColor(kBlue); hppUnfo->Draw(); // hPPGen->Draw("same"); c6->SaveAs("pp_2760GeV_unfold_vs_mc.gif","RECREATE"); /* TCanvas *c7 = new TCanvas("c7","",800,600); c7->SetLogy(); hPPComb->Draw(); hPPComb->SetYTitle(""); hPPComb->SetXTitle("p_{T} GeV/c"); //hppComb->SetTitle("PP 2013 2.76 TeV ak4PF measured vs unfolded"); hPPComb->SetMarkerStyle(23); hPPComb->SetMarkerColor(kBlue); //hppUnfo->SetAxisRange(10,500,"X"); //hppUnfo->SetMarkerStyle(24); //hppUnfo->SetMarkerColor(kRed); //hppUnfo->Draw("same"); TLegend *title5 = myLegend(0.54,0.65,0.85,0.9); title5->AddEntry(hppComb,"Measured","pl"); title5->AddEntry(hppUnfo,"Bayesian iter = 4","pl"); title5->SetTextSize(0.06); title5->Draw(); gStyle->SetOptStat(0); c7->SaveAs("PP2013_measured_vs_unfolded.gif","RECREATE"); //TCanvas */ //Create output file and save them. TFile f("merge_pp_ak3_HLT_V2.root","RECREATE"); //hpbpb1->Write(); //hpbpb2->Write(); //hpbpb3->Write(); //hPPComb_bins->Write(); hpp1->Write(); hpp2->Write(); hpp3->Write(); //hpbpbComb->Write(); hppComb->Write(); //hPPComb->Write(); //hPbPb_Uncert->Write(); hPPComb->Write(); hPPGen->Write(); f.Close(); }
void oDependence() { //set plot options gStyle->SetOptFit(1); gStyle->SetOptStat(1); TCanvas * c1 = new TCanvas("canPRF","Pad response function",700,900); TPad * pad1 = new TPad("pad1THR","",0.05,0.55,0.45,0.95,21); pad1->Draw(); TPad * pad2 = new TPad("pad2PRF","",0.55,0.55,0.95,0.95,21); pad2->Draw(); TPad * pad3 = new TPad("pad3PRF","",0.55,0.05,0.95,0.45,21); pad3->Draw(); pad1->cd(); pad1->SetGridx(); pad1->SetGridy(); pad2->SetGridx(); pad2->SetGridy(); pad3->SetGridx(); pad3->SetGridy(); //make histogram of threshold dependence TH1F * hotd =new TH1F("Occupancy dependence on threshold", "Ocupancy at first pad row as function of threshold", 25,0.,25.); hotd->SetBinContent(5,0.625); hotd->SetBinError(5,0.02); hotd->SetBinContent(10,0.559); hotd->SetBinError(10,0.02); hotd->SetBinContent(20,0.478); hotd->SetBinError(20,0.02); hotd->SetXTitle("Threshold [channels]"); hotd->SetYTitle("occupancy"); hotd->Fit("pol1","+"); hotd->Draw("error"); //make histogram of PRF dependence TH1F * hoprfd =new TH1F("Occupancy dependence on PRF width", "Occupancy at first pad row as function of generic PRF sigma for 2.05x0.35 cm pad size ", 65, 0.,6.5); hoprfd->SetBinContent(10,0.492); hoprfd->SetBinError(10,0.02); hoprfd->SetBinContent(20,0.524); hoprfd->SetBinError(20,0.02); hoprfd->SetBinContent(30,0.559); hoprfd->SetBinError(30,0.02); hoprfd->SetXTitle("Sigma of PRF [mm]"); hoprfd->SetYTitle("occupancy"); pad2->cd(); hoprfd->Fit("pol1","+"); hoprfd->Draw("error"); pad2->Draw(); //pad 3 histogram pad3->cd(); TH1F * hoprfd88 =new TH1F("Occupancy dependence on PRF width 08x08", "Occupancy at first pad row as function of generic PRF sigma for 0.8x0.8 cm pad size ", 65, 0.,6.5); hoprfd88->SetBinContent(20,0.322); hoprfd88->SetBinError(20,0.02); hoprfd88->SetBinContent(30,0.344); hoprfd88->SetBinError(30,0.02); hoprfd88->SetBinContent(40,0.369); hoprfd88->SetBinError(40,0.02); hoprfd88->SetBinContent(60,0.416); hoprfd88->SetBinError(60,0.02); hoprfd88->SetXTitle("Sigma of PRF [mm]"); hoprfd88->SetYTitle("occupancy"); hoprfd88->Fit("pol1","+"); hoprfd88->Draw("error"); c1->cd(); TPaveText * comment = new TPaveText(0.05,0.15,0.45,0.35,"NDC"); comment->SetTextAlign(12); comment->SetFillColor(42); comment->ReadFile("commentdep.txt"); comment->Draw(); }
void plot_golfcourse_Asymptotic(bool unblind){ bool useNewStyle=true; if(useNewStyle) setFPStyle(); TFile *fFREQ=new TFile("higgsCombineEXOZZ.Asymptotic.TOTAL.root","READ"); TTree *t=(TTree*)fFREQ->Get("limit"); double mh,limit; float quant; t->SetBranchAddress("mh",&mh); t->SetBranchAddress("limit",&limit); t->SetBranchAddress("quantileExpected",&quant); //1st loop on tree for preparing mH ordered list vector<double> v_mhTMP; for(int i=0;i<t->GetEntries();i++){ t->GetEntry(i); if(quant>-1.01&&quant<-0.99){ v_mhTMP.push_back(mh); } } std::sort(v_mhTMP.begin(),v_mhTMP.end()); int nMH=v_mhTMP.size(); int iMH=0; vector<double> v_mh, v_median,v_68l,v_68h,v_95l,v_95h, v_obs; while(iMH<nMH){ double mhTMP=v_mhTMP.at(iMH); for(int i=0;i<t->GetEntries();i++){ // int i=j; // if(j==t->GetEntries())i=0; t->GetEntry(i); //cout<<"i "<<i<<flush<<" m = "<<mh<<endl; // if(mh==600)cout<<"$$$$$$$$$ TREE 600 $$$$$$$$$$$$$$"<<endl; if(mh!=mhTMP)continue;//follow exactly the order of v_mhTMP if(quant>-1.01&&quant<-0.99){ v_obs.push_back(limit); v_mh.push_back(mh); } else if(quant>0.02&&quant<0.03)v_95l.push_back(limit); else if(quant>0.15&&quant<0.17)v_68l.push_back(limit); else if(quant>0.49&&quant<0.51)v_median.push_back(limit); else if(quant>0.83&&quant<0.85)v_68h.push_back(limit); else if(quant>0.965&&quant<0.98){ // cout<<"95% -> at M="<<mh<<" I found "<<limit<<endl; v_95h.push_back(limit); } else {cout<<"Error! Quantile = "<<quant<<endl;} } iMH++; }//end while loop cout<<"Out of the loop !"<<endl; //////////////////////////////////////// /// //read in theoretical values from text files // bool applyExtraTherUnc=true; string xsect_file_th="../../../data/xsect_BulkG_ZZ_c0p5_xsect_in_pb.txt"; if(!isZZChannel)xsect_file_th="../../../data/xsect_BulkG_WW_c0p5_xsect_in_pb.txt"; // make_interpolated_xsect(xsect_file_th, xsect_file_interpol); // string xsect_file_interpol="./RSGravXSectTimesBRToZZ_AgasheHapola_c10_EXPOINTERP.txt"; ifstream xsect_file(xsect_file_th.c_str(),ios::in); if (! xsect_file.is_open()){ cout<<"Failed to open file with xsections"<<endl;} float mH, CS; vector<float> v_mhxs, v_xs, v_brzz2l2q,v_toterrh,v_toterrl; while(xsect_file.good()){ xsect_file >> mH>> CS; if(mH==1200)cout<<"~~~~~ 1200 theor ~~~~~~~~~~~~~"<<endl; if(mH<600.0)continue; v_mhxs.push_back(mH); v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !) //unavailable theor errors for graviton float tot_err_p=0.0; float tot_err_m=0.0; v_toterrh.push_back(1.0+(tot_err_p)); v_toterrl.push_back(1.0-(tot_err_m)); } cout<<"Size of theor "<<v_mhxs.size()<<endl; xsect_file.close(); string xsect_file_interpol2="../../../data/xsect_BulkG_ZZ_c0p2_xsect_in_pb.txt"; if(!isZZChannel)xsect_file_interpol2="../../../data/xsect_BulkG_WW_c0p2_xsect_in_pb.txt"; ifstream xsect_file2(xsect_file_interpol2.c_str(),ios::in); if (! xsect_file2.is_open()){ cout<<"Failed to open file with xsections (c=0.10)"<<endl;} float mH2,CS10; vector<float> v_xs10; while(xsect_file2.good()){ xsect_file2 >> mH2>> CS10; if(mH2==975)cout<<"~~~~~ 975 theor ~~~~~~~~~~~~~"<<endl; if(mH2<600.0)continue; v_xs10.push_back(CS10);//*BRZZ2l2q //unavailable theor errors for graviton float tot_err_p=0.0; float tot_err_m=0.0; // v_toterrh.push_back(1.0+(tot_err_p)); // v_toterrl.push_back(1.0-(tot_err_m)); } cout<<"Size of theor "<<v_xs10.size()<<endl; xsect_file2.close(); // //END THEOR INPUT PART /////////////// const int nMass= v_mh.size(); double mass[nMass],mass1[nMass],obs_lim_cls[nMass]; double medianD[nMass]; double up68err[nMass],down68err[nMass],up95err[nMass],down95err[nMass]; double xs[nMass], xs_uperr[nMass], xs_downerr[nMass]; double xs10[nMass], xs10_uperr[nMass], xs10_downerr[nMass]; int nMassEff=0,nMassEff1=0; int nM95=0; double mass95[nMass],median95[nMass]; int nexcluded=0; bool excl; for(int im=0;im<nMass;im++){ if( mass[nMassEff-1]>1600.) cout<<"Array "<<im<<flush<<" m = "<<v_mh.at(im)<<endl;; //protection against messed up jobs excl=false; if(v_68h.at(im)>=v_95h.at(im) || v_68l.at(im)<=v_95l.at(im) ){ cout<<"Point at M = "<<v_mh.at(im) <<" excluded: "<<v_95l.at(im)<<" "<<v_68l.at(im)<<" "<<v_median.at(im)<<" "<<v_68h.at(im)<<" "<<v_95h.at(im)<< endl; nexcluded++; // continue; excl=true; } // if(im%2==1)excl=true;//sample only one half of the points //search for right index in theor vectors bool found=false; int indtmp=0,ind=-1; while(!found){ if(v_mhxs.at(indtmp)==v_mh.at(im)){found=true;ind=indtmp;} indtmp++; if(indtmp==v_mhxs.size()){ cout<<"!!! m="<<flush<<v_mh.at(im)<<" NOT found in theor matrix."<<endl; break; } }//end while if(!found){ cout<<"(2) m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl; continue; } double fl_xs=double(v_xs.at(ind));//*1000.0 double fl_xs10=double(v_xs10.at(ind));//*1000.0 if(fl_xs<fl_xs10)cout<<"WARNING ABOUT XSECT! XS="<<fl_xs<<" XS10="<<fl_xs10<<endl; mass[nMassEff]=v_mh.at(im); //if( mass[nMassEff]==600.0)cout<<"=============> 600 !!!"<<endl; obs_lim_cls[nMassEff]=v_obs.at(im)*fl_xs; nMassEff++; if(!excl){ mass1[nMassEff1]=v_mh.at(im); medianD[nMassEff1]=v_median.at(im)*fl_xs; up68err[nMassEff1]=(v_68h.at(im)-v_median.at(im))*fl_xs; down68err[nMassEff1]=(v_median.at(im)-v_68l.at(im))*fl_xs; cout<<"M="<<mass1[nMassEff1]<<" Median="<<medianD[nMassEff1]<<endl; //scale factor 100 for making the xsect visible xs[nMassEff1]=fl_xs;//*100.0; xs_uperr[nMassEff1]=double( v_toterrh.at(ind))*xs[nMassEff1]- xs[nMassEff1]; xs_downerr[nMassEff1]= xs[nMassEff1]- double( v_toterrl.at(ind))* xs[nMassEff1]; xs10[nMassEff1]=fl_xs10;//*100.0; xs10_uperr[nMassEff1]=double( v_toterrh.at(ind))*xs10[nMassEff1]- xs10[nMassEff1]; xs10_downerr[nMassEff1]= xs10[nMassEff1]- double( v_toterrl.at(ind))* xs10[nMassEff1]; //cout<<"Theor err on 4g for M="<<mass[nMassEff]<<" "<< ggxs4g_downerr[nMassEff] << " "<<ggxs4g_uperr[nMassEff]<<endl; nMassEff1++; bool skip95= false;// // skip95=v_mh.at(im)==204||v_mh.at(im)==208||v_mh.at(im)==212||v_mh.at(im)==214|| v_mh.at(im)==232 || v_mh.at(im)==240 || v_mh.at(im)==240 || v_mh.at(im)==244 || v_mh.at(im)==252 || v_mh.at(im)==264 || v_mh.at(im)==272 || v_mh.at(im)==288 ; // skip95=false; if(skip95 )continue; mass95[nM95]=v_mh.at(im); median95[nM95]=v_median.at(im)*fl_xs; up95err[nM95]=(v_95h.at(im)-v_median.at(im))*fl_xs; down95err[nM95]=(v_median.at(im)-v_95l.at(im))*fl_xs; // cout<<"M95: "<< mass95[nM95]<<" "<<median95[nM95]<<" +"<<up95err[nM95]<<" -"<< down95err[nM95]<< // " ("<<v_95h.at(im) <<" - "<<v_median.at(im) <<")"<<endl; nM95++; }//end if not excluded mass point }//end loop over im (mass points) cout<<"Excluded "<<nexcluded<<" sick mass points."<<endl; // cout<<"Working on TGraph"<<endl; TGraphAsymmErrors *grobslim_cls=new TGraphAsymmErrors(nMassEff,mass,obs_lim_cls); grobslim_cls->SetName("LimitObservedCLs"); TGraphAsymmErrors *grmedian_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD); grmedian_cls->SetName("LimitExpectedCLs"); TGraphAsymmErrors *gr68_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD,0,0,down68err,up68err); gr68_cls->SetName("Limit68CLs"); TGraphAsymmErrors *gr95_cls=new TGraphAsymmErrors(nM95,mass95,median95,0,0,down95err,up95err); gr95_cls->SetName("Limit95CLs"); // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr); TGraph *grthSM=new TGraph(nMassEff1,mass1,xs);//xs_downerr,xs_uperr); grthSM->SetName("SMXSection"); // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0); TGraph *grthSM10=new TGraph(nMassEff1,mass1,xs10); grthSM10->SetName("SMXSection_2nd"); // cout<<"Plotting"<<endl; double fr_left=590.0, fr_down=0.0005,fr_right=2020.0,fr_up=1.0; if(!isZZChannel){fr_left=1000.0, fr_down=0.0000005,fr_right=2500.0,fr_up=10.0;} TCanvas *cMCMC=new TCanvas("c_lim_Asymp","canvas with limits for Asymptotic CLs",630,600); cMCMC->cd(); cMCMC->SetGridx(1); cMCMC->SetGridy(1); // draw a frame to define the range TH1F *hr = cMCMC->DrawFrame(fr_left,fr_down,fr_right,fr_up,""); TString VV = "ZZ"; if(!isZZChannel)VV="WW"; hr->SetXTitle("M_{1} [GeV]"); hr->SetYTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q // cMCMC->GetFrame()->SetFillColor(21); //cMCMC->GetFrame()->SetBorderSize(12); gr95_cls->SetFillColor(kYellow); gr95_cls->SetFillStyle(1001);//solid gr95_cls->SetLineStyle(kDashed); gr95_cls->SetLineWidth(3); gr95_cls->GetXaxis()->SetTitle("M_{1} [GeV]"); gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q gr95_cls->GetXaxis()->SetRangeUser(fr_left,fr_right); gr95_cls->Draw("3"); gr68_cls->SetFillColor(kGreen); gr68_cls->SetFillStyle(1001);//solid gr68_cls->SetLineStyle(kDashed); gr68_cls->SetLineWidth(3); gr68_cls->Draw("3same"); grmedian_cls->GetXaxis()->SetTitle("M_{1} [GeV]"); grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q grmedian_cls->SetMarkerStyle(24);//25=hollow squre grmedian_cls->SetMarkerColor(kBlack); grmedian_cls->SetLineStyle(2); grmedian_cls->SetLineWidth(3); grmedian_cls->SetMinimum(0.0); grmedian_cls->SetMaximum(8.0); grobslim_cls->SetMarkerColor(kBlack); grobslim_cls->SetMarkerStyle(20);//24=hollow circle // 20 = solid circle grobslim_cls->SetMarkerSize(0.7); grobslim_cls->SetLineStyle(1); grobslim_cls->SetLineWidth(1); grthSM->SetLineColor(kRed); grthSM->SetLineWidth(2); grthSM->SetLineStyle(kSolid); grthSM->SetFillColor(kRed); grthSM->SetFillStyle(3344); grthSM10->SetLineColor(kRed); grthSM10->SetLineWidth(2); grthSM10->SetLineStyle(1); grthSM10->SetLineStyle(kDashed); grthSM10->SetFillColor(kRed); grthSM10->SetFillStyle(3344); grthSM->Draw("L3"); grthSM10->Draw("L3"); grmedian_cls->Draw("L"); if(unblind)grobslim_cls->Draw("LP"); /* TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ"); TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs"); TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs"); grobs_ump->SetName("LimitObs_UnmatchedPlus"); grmedian_ump->SetName("LimitExp_UnmatchedPlus"); grobs_ump->SetMarkerColor(kBlue); grobs_ump->SetLineColor(kBlue); grobs_ump->SetMarkerStyle(25); grmedian_ump->SetMarkerColor(kBlue); grmedian_ump->SetLineColor(kBlue); grmedian_ump->SetMarkerStyle(25); grobs_ump->Draw("P"); grmedian_ump->Draw("L"); */ //draw grid on top of limits gStyle->SetOptStat(0); TH1D* postGrid = new TH1D("postGrid","",1,fr_left,fr_right); postGrid->GetYaxis()->SetRangeUser(fr_down,fr_up); postGrid->Draw("AXIGSAME"); TLine *l1=new TLine(); l1->SetLineStyle(1); l1->SetLineWidth(2.0); l1->SetLineColor(kRed); // l1->DrawLine(200.0,1.0,600.0,1.0); // cMCMC->Update(); cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); //more graphics TLegend *leg = new TLegend(.46,.75,.94,.92); // TLegend *leg = new TLegend(.35,.71,.90,.90); leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.025); // leg->SetBorderMode(0); if(unblind)leg->AddEntry(grobslim_cls, "Asympt. CL_{S} Observed", "LP"); leg->AddEntry(gr68_cls, "Asympt. CL_{S} Expected #pm 1#sigma", "LF"); leg->AddEntry(gr95_cls, "Asympt. CL_{S} Expected #pm 2#sigma", "LF"); leg->AddEntry(grthSM, "#sigma_{TH} x BR(G #rightarrow "+VV+"), #tilde{k}=0.50", "L" );// #rightarrow 2l2q leg->AddEntry(grthSM10, "#sigma_{TH} x BR(G #rightarrow "+VV+"), #tilde{k}=0.20", "L");// #rightarrow 2l2q leg->Draw(); if(useNewStyle){ TPaveText* cmslabel = new TPaveText( 0.145, 0.953, 0.6, 0.975, "brNDC"); cmslabel->SetFillColor(kWhite); cmslabel->SetTextSize(0.038); cmslabel->SetTextAlign(11); cmslabel->SetTextFont(62); cmslabel->SetBorderSize(0); // std::string leftText = "CMS Preliminary 2011"; std::string leftText = "CMS"; std::string units = "fb ^{-1}"; char lumiText[300]; sprintf( lumiText, "%.1f %s", intLumi, units.c_str()); cmslabel->AddText(Form("%s, #sqrt{s} = 8 TeV, %s", leftText.c_str(), lumiText)); //cmslabel->Draw(); TPaveText* label_sqrt = new TPaveText(0.4,0.953,0.96,0.975, "brNDC"); label_sqrt->SetFillColor(kWhite); label_sqrt->SetBorderSize(0); label_sqrt->SetTextSize(0.038); label_sqrt->SetTextFont(62); label_sqrt->SetTextAlign(31); // align right // label_sqrt->AddText("#sqrt{s} = 7 TeV"); label_sqrt->AddText(Form("%s, L = %s at #sqrt{s} = 8 TeV", leftText.c_str(), lumiText)); label_sqrt->Draw(); } else{ TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.04); latex->SetTextAlign(31); latex->SetTextAlign(11); // align left latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012"); latex->DrawLatex(0.60,0.96,Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV",intLumi)); } TLine *l1b=new TLine(); l1b->SetLineStyle(1); l1b->SetLineWidth(2.0); l1b->SetLineColor(kRed); //l1b->DrawLine(200.0,1.0,600.0,1.0); cMCMC->Update(); // cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.root"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.eps"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.png"); gPad->SetLogy(); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.eps"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.png"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.root"); // cMCMC->SaveAs("ClsLimit_1fb.png"); TFile *outfile=new TFile("AsymptoticCLs_TGraph.root","RECREATE"); outfile->cd(); if(unblind)grobslim_cls->Write(); grmedian_cls->Write(); outfile->Close(); }//end main
void probability(Float_t param = 1, Float_t x1 = 0.9, Float_t x2 = 1.3, Float_t over = 2,const char * com ="", Int_t N=20) { //create canvas for drawing TCanvas * c1 = new TCanvas("canprob","Pad response function",700,900); TPad * pad1 = new TPad("Theoretical probability","",0.05,0.22,0.95,0.95,21); pad1->Draw(); //create histogram with estimated occupancy //normalised to obtained occupancy at first pad Float_t y1=0; Float_t y2; char s[120]; sprintf(s,"1-exp(-[1]/x**%f)",over); cout<<s<<"\n"; TF1 *funr1 = new TF1("funr1",s,x1,x2); funr1->SetParameters(1,param); sprintf(s,"Probability according 1-exp(-%1.3f/x**%1.1f distribution)", param,over); pad1->cd(); TH1F * hOccuT = new TH1F("hOccuT",s,5*N,x1,x2); Float_t x=x1; Float_t y; for (Float_t i = 0;i<N+1;i++) { y = funr1->Eval(x); hOccuT->Fill(x,y); x+=(x2-x1)/Float_t(N); }; //fitting calculated dependence with linear fit and with //generic function pad1->cd(); sprintf(s,"[1]/(x**%1.1f)",over); TF1 *lin1 = new TF1("lin1","pol1",x1,x2); lin1->SetLineColor(2); lin1->SetLineWidth(5); lin1->SetLineStyle(1); hOccuT->Draw(); hOccuT->Fit("lin1","S+"); sprintf(s,"[1]/(x**%1.1f)",over); TF1 *funorig = new TF1("funorig",s,x1,x2); funorig->SetLineColor(3); funorig->SetLineWidth(5); funorig->SetLineStyle(2); hOccuT->Fit("funorig","S+"); //find minimum and maximum and scale histo if (y1 == 0) { Float_t ymin,ymax; y1=lin1->Eval(x2); y2=lin1->Eval(x1); ymin= funorig->Eval(x2); ymax= funorig->Eval(x1); if (ymin<y1) y1=ymin; if (ymax>y2) y2=ymax; } gStyle->SetOptFit(0); gStyle->SetOptStat(0); hOccuT->SetMaximum(y2); hOccuT->SetMinimum(y1); hOccuT->SetXTitle("r position [m]"); hOccuT->SetYTitle("probability"); //add comments to the histograms c1->cd(); TPaveText * comment = new TPaveText(0.05,0.03,0.95,0.20,"NDC"); comment->SetTextAlign(12); comment->SetFillColor(42); TText *title = comment->AddText("Estimation of occupancy dependence on R position"); title->SetTextSize(0.04); comment->AddText("Observed efect of probability saturation"); sprintf(s,"Supposed generic flux dependence : %1.3f/(x**%1.1f)",param,over); comment->AddText(s); comment->AddText("Probility : 1-exp(-flux*mean particle \"pad x time\" area)"); comment->AddText("Full line linear fit "); comment->AddText("Dashed line : fit by generic flux function "); comment->AddText(com); comment->Draw(); }
void pythia8(Int_t nev = 100, Int_t ndeb = 1) { const char *p8dataenv = gSystem->Getenv("PYTHIA8DATA"); if (!p8dataenv) { const char *p8env = gSystem->Getenv("PYTHIA8"); if (!p8env) { Error("pythia8.C", "Environment variable PYTHIA8 must contain path to pythia directory!"); return; } TString p8d = p8env; p8d += "/xmldoc"; gSystem->Setenv("PYTHIA8DATA", p8d); } const char* path = gSystem->ExpandPathName("$PYTHIA8DATA"); if (gSystem->AccessPathName(path)) { Error("pythia8.C", "Environment variable PYTHIA8DATA must contain path to $PYTHIA8/xmldoc directory !"); return; } // Load libraries #ifndef G__WIN32 // Pythia8 is a static library on Windows if (gSystem->Getenv("PYTHIA8")) { gSystem->Load("$PYTHIA8/lib/libpythia8"); } else { gSystem->Load("libpythia8"); } #endif gSystem->Load("libEG"); gSystem->Load("libEGPythia8"); // Histograms TH1F* etaH = new TH1F("etaH", "Pseudorapidity", 120, -12., 12.); TH1F* ptH = new TH1F("ptH", "pt", 50, 0., 10.); // Array of particles TClonesArray* particles = new TClonesArray("TParticle", 1000); // Create pythia8 object TPythia8* pythia8 = new TPythia8(); // Configure pythia8->ReadString("HardQCD:all = on"); // Initialize pythia8->Initialize(2212 /* p */, 2212 /* p */, 14000. /* TeV */); // Event loop for (Int_t iev = 0; iev < nev; iev++) { pythia8->GenerateEvent(); if (iev < ndeb) pythia8->EventListing(); pythia8->ImportParticles(particles,"All"); Int_t np = particles->GetEntriesFast(); // Particle loop for (Int_t ip = 0; ip < np; ip++) { TParticle* part = (TParticle*) particles->At(ip); Int_t ist = part->GetStatusCode(); // Positive codes are final particles. if (ist <= 0) continue; Int_t pdg = part->GetPdgCode(); Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge(); if (charge == 0.) continue; Float_t eta = part->Eta(); Float_t pt = part->Pt(); etaH->Fill(eta); if (pt > 0.) ptH->Fill(pt, 1./(2. * pt)); } } pythia8->PrintStatistics(); TCanvas* c1 = new TCanvas("c1","Pythia8 test example",800,800); c1->Divide(1, 2); c1->cd(1); etaH->Scale(5./Float_t(nev)); etaH->Draw(); etaH->SetXTitle("#eta"); etaH->SetYTitle("dN/d#eta"); c1->cd(2); gPad->SetLogy(); ptH->Scale(5./Float_t(nev)); ptH->Draw(); ptH->SetXTitle("p_{t} [GeV/c]"); ptH->SetYTitle("dN/dp_{t}^{2} [GeV/c]^{-2}"); }
void findFilterEnergyLoss::Loop() { Int_t energy = run_energy; Double_t alpha = 0.0014467; Double_t alpha_prime = 0.203815; Double_t p = 1.707283; Float_t run_thickness = 1; if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; TCanvas *c1 = new TCanvas("c1", "c1", 800, 600); TCanvas *c2 = new TCanvas("c2", "c2", 800, 600); TCanvas *c3 = new TCanvas("c3", "c3", 800, 600); TH1F *hEnergyLoss = new TH1F("hEnergyLoss", Form("Energy loss for a %d MeV proton beam on a %.1f mm aluminum foil", energy, run_thickness), 400, 0, 20); TH1F *hEnergy= new TH1F("hEnergy", Form("Final energy for a %d MeV proton beam on a %.1f mm aluminum foil", energy, run_thickness), 5000, 0, 250); TH2F *hEnergy2D = new TH2F("hEnergy2D", Form("Final energy for a %d MeV proton beam on focal vs x", energy), 128, -20, 20, 200, 0, 200); Int_t lastID = -1; Float_t sum_edep = 0; Float_t lastX = 0; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) { cout << "Aborting run at jentry = " << jentry << endl; break; } nb = fChain->GetEntry(jentry); nbytes += nb; // if (abs(posX) < 1 && abs(posY) < 1) { // continue; // } if (eventID != lastID) { hEnergyLoss->Fill(sum_edep); hEnergy->Fill(energy - sum_edep); hEnergy2D->Fill(lastX, energy - sum_edep); sum_edep = edep; } else sum_edep += edep; lastID = eventID; lastX = posX; } TF1 *fEnergy = new TF1("f_Energy", "gaus(0)", 0, energy+10); TF1 *fEnergyLoss = new TF1("f_EnergyLoss", "gaus(0)", 0, 30); // fEnergy->SetParameters(100, energy-10, 0.3); // fEnergyLoss->SetParameters(160, 10, 0.3); hEnergy->Fit("f_Energy"); hEnergyLoss->Fit("gaus", "M"); // fEnergyLoss->SetParLimits(1, finalLoss*0.8, finalLoss*1.2); // fEnergyLoss->SetParLimits(2, 0.05, 0.5); c1->cd(); hEnergy->SetXTitle("Final energy"); hEnergy->SetYTitle("Number of particles"); hEnergy->SetFillColor(kYellow - 10); hEnergy->SetLineColor(kBlack); hEnergy->Draw(); c2->cd(); hEnergyLoss->SetXTitle("Total energy loss"); hEnergyLoss->SetYTitle("Number of particles"); hEnergyLoss->Draw(); c3->cd(); hEnergy2D->SetXTitle("X position [mm]"); hEnergy2D->SetYTitle("Final energy [MeV]"); // hEnergy2D->Draw("COLZ"); cout << "For a " << energy << " MeV beam, the energy loss is " << Form("%.2f", fEnergyLoss->GetParameter(1)) << " +- " << Form("%.2f", fEnergyLoss->GetParameter(2)) << " MeV.\n"; }
/* ********************************************** */ void OHltRatePrinter::writeHistos(OHltConfig *cfg, OHltMenu *menu) { TString tableFileName = GetFileName(cfg, menu); TFile *fr = new TFile(tableFileName+TString(".root"),"recreate"); fr->cd(); int nTrig = (int)menu->GetTriggerSize(); int nL1Trig = (int)menu->GetL1TriggerSize(); TH1F *individual = new TH1F("individual","individual",nTrig,1,nTrig+1); TH1F *cumulative = new TH1F("cumulative","cumulative",nTrig,1,nTrig+1); TH1F *throughput = new TH1F("throughput","throughput",nTrig,1,nTrig+1); TH1F *eventsize = new TH1F("eventsize","eventsize",nTrig,1,nTrig+1); TH2F *overlap = new TH2F("overlap","overlap",nTrig,1,nTrig+1,nTrig,1,nTrig+1); TH1F *unique = new TH1F("unique","unique",nTrig,1,nTrig+1); int RunLSn = RatePerLS.size(); int RunMin = ivecMin(runID); int RunMax = ivecMax(runID); int LSMin = ivecMin(lumiSection); int LSMax = ivecMax(lumiSection); int RunLSmin = RunMin*10000 + LSMin; int RunLSmax = RunMax*10000 + LSMax; //cout<<">>>>>>>> "<<RunLSn<<" "<<RunMin<<" "<<RunMax<<" "<<LSMin<<" "<<LSMax<<endl; TH2F *individualPerLS = new TH2F("individualPerLS","individualPerLS",nTrig,1,nTrig+1, RunLSn,RunLSmin,RunLSmax); TH1F *totalPerLS = new TH1F("totalPerLS","totalPerLS",RunLSn,RunLSmin,RunLSmax); TH2F *hltprescalePerLS = new TH2F("HLTprescalePerLS","HLTprescalePerLS",nTrig,1,nTrig+1, RunLSn,RunLSmin,RunLSmax); TH2F *l1prescalePerLS = new TH2F("L1prescalePerLS","L1prescalePerLS", nL1Trig,1,nL1Trig+1, RunLSn,RunLSmin,RunLSmax); TH2F *totalprescalePerLS = new TH2F("totalprescalePerLS","totalprescalePerLS", nTrig,1,nTrig+1, RunLSn,RunLSmin,RunLSmax); TH2F *individualCountsPerLS = new TH2F("individualCountsPerLS","individualCountsPerLS",nTrig,1,nTrig+1, RunLSn,RunLSmin,RunLSmax); TH1F *totalCountsPerLS = new TH1F("totalCountsPerLS","totalCountsPerLS",RunLSn,RunLSmin,RunLSmax); TH1F *instLumiPerLS = new TH1F("instLumiPerLS","instLumiPerLS",RunLSn,RunLSmin,RunLSmax); float cumulRate = 0.; float cumulRateErr = 0.; float cuThru = 0.; float cuThruErr = 0.; for (unsigned int i=0; i<menu->GetTriggerSize(); i++) { cumulRate += spureRate[i]; cumulRateErr += pow(spureRateErr[i], fTwo); cuThru += spureRate[i] * menu->GetEventsize(i); cuThruErr += pow(spureRate[i]*menu->GetEventsize(i), fTwo); individual->SetBinContent(i+1, Rate[i]); individual->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); cumulative->SetBinContent(i+1, cumulRate); cumulative->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); unique->SetBinContent(i+1, pureRate[i]); unique->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); throughput->SetBinContent(i+1, cuThru); throughput->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); eventsize->SetBinContent(i+1, menu->GetEventsize(i)); eventsize->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); for (int j=0; j<RunLSn; j++) { individualPerLS->SetBinContent(i+1, j+1, RatePerLS[j][i]); individualCountsPerLS->SetBinContent(i+1, j+1, CountPerLS[j][i]); TString tstr = ""; tstr += runID[j]; tstr = tstr + " - "; tstr += lumiSection[j]; individualPerLS->GetYaxis()->SetBinLabel(j+1, tstr); individualPerLS->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); individualCountsPerLS->GetYaxis()->SetBinLabel(j+1, tstr); individualCountsPerLS->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); } } for (int j=0; j<RunLSn; j++) { TString tstr = ""; tstr += runID[j]; tstr = tstr + " - "; tstr += lumiSection[j]; totalPerLS->SetBinContent(j+1, totalRatePerLS[j]); totalPerLS->GetXaxis()->SetBinLabel(j+1, tstr); totalCountsPerLS->SetBinContent(j+1, totalCountPerLS[j]); totalCountsPerLS->GetXaxis()->SetBinLabel(j+1, tstr); instLumiPerLS->SetBinContent(j+1, LumiPerLS[j]); instLumiPerLS->GetXaxis()->SetBinLabel(j+1, tstr); // L1 for (unsigned int k=0; k<menu->GetL1TriggerSize(); k++) { l1prescalePerLS->SetBinContent(k+1, j+1, prescaleL1RefPerLS[j][k]); l1prescalePerLS->GetYaxis()->SetBinLabel(j+1, tstr); l1prescalePerLS->GetXaxis()->SetBinLabel(k+1, menu->GetL1TriggerName(k)); } // HLT for (unsigned int i=0; i<menu->GetTriggerSize(); i++) { hltprescalePerLS->SetBinContent(i+1, j+1, prescaleRefPerLS[j][i]); hltprescalePerLS->GetYaxis()->SetBinLabel(j+1, tstr); hltprescalePerLS->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); // HLT*L1 std::map<TString, std::vector<TString> > mapL1seeds = menu->GetL1SeedsOfHLTPathMap(); // mapping to all seeds vector<TString> vtmp; vector<int> itmp; typedef map< TString, vector<TString> > mymap; for (mymap::const_iterator it = mapL1seeds.begin(); it != mapL1seeds.end(); ++it) { if (it->first.CompareTo(menu->GetTriggerName(i)) == 0) { vtmp = it->second; if (it->second.size() > 1 || it->second.size() == 0) { // For OR'd L1 seeds, punt totalprescalePerLS->SetBinContent(i+1, j+1, -999); totalprescalePerLS->GetYaxis()->SetBinLabel(j+1, tstr); totalprescalePerLS->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); } else { // For a single L1 seed, loop over the map, find the online prescale, and multiply by the online HLT prescale TString l1seedname = (it->second)[0]; for (unsigned int k=0; k<menu->GetL1TriggerSize(); k++) { if (l1seedname == menu->GetL1TriggerName(k)) { totalprescalePerLS->SetBinContent( i+1, j+1, prescaleL1RefPerLS[j][k] * prescaleRefPerLS[j][i]); totalprescalePerLS->GetYaxis()->SetBinLabel(j+1, tstr); totalprescalePerLS->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); } } } } } } } for (unsigned int i=0; i<menu->GetTriggerSize(); i++) { for (unsigned int j=0; j<menu->GetTriggerSize(); j++) { overlap->SetBinContent(i+1, j+1, coMa[i][j]); overlap->GetXaxis()->SetBinLabel(i+1, menu->GetTriggerName(i)); overlap->GetYaxis()->SetBinLabel(j+1, menu->GetTriggerName(j)); } } individual->SetStats(0); individual->SetYTitle("Rate (Hz)"); individual->SetTitle("Individual trigger rate"); cumulative->SetStats(0); cumulative->SetYTitle("Rate (Hz)"); cumulative->SetTitle("Cumulative trigger rate"); overlap->SetStats(0); overlap->SetTitle("Overlap"); unique->SetStats(0); unique->SetYTitle("Rate (Hz)"); unique->SetTitle("Unique trigger rate"); individual->Write(); cumulative->Write(); eventsize->Write(); throughput->Write(); overlap->Write(); unique->Write(); individualPerLS->SetStats(0); individualPerLS->SetZTitle("Rate (Hz)"); individualPerLS->SetTitle("Individual trigger rate vs Run/LumiSection"); individualPerLS->Write(); totalPerLS->SetStats(0); totalPerLS->SetZTitle("Rate (Hz)"); totalPerLS->SetTitle("Total trigger rate vs Run/LumiSection"); totalPerLS->Write(); totalprescalePerLS->SetStats(0); totalprescalePerLS->SetZTitle("Prescale"); totalprescalePerLS->SetTitle("HLT*L1 Prescale vs Run/LumiSection"); totalprescalePerLS->Write(); hltprescalePerLS->SetStats(0); hltprescalePerLS->SetZTitle("Prescale"); hltprescalePerLS->SetTitle("HLT Prescale vs Run/LumiSection"); hltprescalePerLS->Write(); l1prescalePerLS->SetStats(0); l1prescalePerLS->SetZTitle("Prescale"); l1prescalePerLS->SetTitle("L1 Prescale vs Run/LumiSection"); l1prescalePerLS->Write(); individualCountsPerLS->SetStats(0); individualCountsPerLS->SetZTitle("Events selected"); individualCountsPerLS->SetTitle("Individual trigger counts vs Run/LumiSection"); individualCountsPerLS->Write(); totalCountsPerLS->SetStats(0); totalCountsPerLS->SetZTitle("Events selected"); totalCountsPerLS->SetTitle("Total trigger counts vs Run/LumiSection"); totalCountsPerLS->Write(); instLumiPerLS->SetStats(0); instLumiPerLS->SetZTitle("Events selected"); instLumiPerLS->SetTitle("Instantaneous lumi vs Run/LumiSection"); instLumiPerLS->Write(); fr->Close(); }
void plot_golfcourse(){ // TFile *fFREQ=new TFile("higgsCombineHZZ2L2Q_FREQ.20111127MMv2.root","READ"); TFile *fFREQ=new TFile("higgsCombineHZZ2L2Q_FREQ.20111129MMv2.root","READ"); TTree *t=(TTree*)fFREQ->Get("limit"); double mh,limit; float quant; t->SetBranchAddress("mh",&mh); t->SetBranchAddress("limit",&limit); t->SetBranchAddress("quantileExpected",&quant); vector<double> v_mh, v_median,v_68l,v_68h,v_95l,v_95h, v_obs; for(int i=0;i<t->GetEntries();i++){ t->GetEntry(i); // cout<<"i "<<i<<flush<<" m = "<<mh<<endl; // if(mh==600)cout<<"$$$$$$$$$ TREE 600 $$$$$$$$$$$$$$"<<endl; if(quant>-1.01&&quant<-0.99){ v_obs.push_back(limit); v_mh.push_back(mh); } else if(quant>0.02&&quant<0.03)v_95l.push_back(limit); else if(quant>0.15&&quant<0.17)v_68l.push_back(limit); else if(quant>0.49&&quant<0.51)v_median.push_back(limit); else if(quant>0.83&&quant<0.85)v_68h.push_back(limit); else if(quant>0.965&&quant<0.98)v_95h.push_back(limit); else {cout<<"Error! Quantile = "<<quant<<endl;} } cout<<"Out of the loop !"<<endl; //read in theoretical values from text files ifstream xsect_file("./xsect_higgs_173points_new.txt",ios::in); if (! xsect_file.is_open()){ cout<<"Failed to open file with xsections"<<endl;} float mHxs, CSgg, CSgg_p, CSgg_m, CSpdfgg_p,CSpdfgg_m,CSvbf, CSvbf_p, CSvbf_m,CSpdfvbf_p,CSpdfvbf_m, Gamma, BRHZZ, BRZZ2l2q; vector<float> v_mhxs, v_ggxs,v_vbfxs, v_ggtoterrh,v_ggtoterrl, v_vbftoterrh,v_vbftoterrl, v_gamma, v_brhzz, v_brzz2l2q; while(xsect_file.good()){ xsect_file >> mHxs>> CSgg>> CSgg_p >> CSgg_m >> CSpdfgg_p>> CSpdfgg_m>> CSvbf >> CSvbf_p >> CSvbf_m >> CSpdfvbf_p>>CSpdfvbf_m>>Gamma >> BRHZZ >> BRZZ2l2q; // if(mHxs==600)cout<<"~~~~~ 600 theor ~~~~~~~~~~~~~"<<endl; v_mhxs.push_back(mHxs); v_ggxs.push_back(CSgg*BRHZZ);//*BRZZ2l2q v_vbfxs.push_back(CSvbf); v_brhzz.push_back( BRHZZ); v_brzz2l2q.push_back(BRZZ2l2q); //sum up linearly theor errors v_ggtoterrh.push_back(1.0+CSgg_p+CSpdfgg_p); v_ggtoterrl.push_back(1.0+CSgg_m+CSpdfgg_m); } cout<<"Size of theor "<<v_mhxs.size()<<flush; /////////////// const int nMass= v_mh.size(); cout<<"SIZE SIZE SIZE "<<nMass<<endl; double mass[nMass],mass1[nMass],obs_lim_cls[nMass]; double medianD[nMass]; double up68err[nMass],down68err[nMass],up95err[nMass],down95err[nMass]; double ggxs[nMass], ggxs_uperr[nMass], ggxs_downerr[nMass]; int nMassEff=0,nMassEff1=0; int nM95=0; double mass95[nMass],median95[nMass]; int nexcluded=0; bool excl; for(int im=0;im<nMass;im++){ // cout<<"Array "<<im<<flush<<" m = "<<v_mh.at(im)<<flush; //protection against messed up jobs excl=false; if(v_68h.at(im)>=v_95h.at(im) || v_68l.at(im)<=v_95l.at(im) ){ cout<<"Point at M = "<<v_mh.at(im) <<" excluded"<<endl; nexcluded++; // continue; excl=true; } if(im%2==1)excl=true; //search for right index in theor vectors bool found=false; int indtmp=0,ind=-1; while(!found){ if(v_mhxs.at(indtmp)==v_mh.at(im)){found=true;ind=indtmp;} indtmp++; if(indtmp==v_mhxs.size()){ cout<<"m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl; break; } }//end while // if(v_mh.at(im)<226.0)found=false; if(!found){ // cout<<"(2) m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl; continue; } //cout<<" Found mass, xs= "<<v_ggxs.at(ind)<<endl; double xs=double(v_ggxs.at(ind)); mass[nMassEff]=v_mh.at(im); //if( mass[nMassEff]==600.0)cout<<"=============> 600 !!!"<<endl; obs_lim_cls[nMassEff]=v_obs.at(im); nMassEff++; if(!excl){ mass1[nMassEff1]=v_mh.at(im); medianD[nMassEff1]=v_median.at(im); up68err[nMassEff1]=(v_68h.at(im)-v_median.at(im)); down68err[nMassEff1]=(v_median.at(im)-v_68l.at(im)); ggxs[nMassEff1]=xs; ggxs_uperr[nMassEff1]=double( v_ggtoterrh.at(ind))*xs -xs ; ggxs_downerr[nMassEff1]=xs - double( v_ggtoterrl.at(ind))*xs; nMassEff1++; bool skip95= false;// skip95=v_mh.at(im)==204||v_mh.at(im)==208||v_mh.at(im)==212||v_mh.at(im)==214|| v_mh.at(im)==232 || v_mh.at(im)==240 || v_mh.at(im)==240 || v_mh.at(im)==244 || v_mh.at(im)==252 || v_mh.at(im)==264 || v_mh.at(im)==272 || v_mh.at(im)==288 ; // skip95=false; if(skip95 )continue; mass95[nM95]=v_mh.at(im); median95[nM95]=v_median.at(im); up95err[nM95]=(v_95h.at(im)-v_median.at(im)); down95err[nM95]=(v_median.at(im)-v_95l.at(im)); nM95++; } } cout<<"Excluded "<<nexcluded<<" sick mass points."<<endl; // cout<<"Working on TGraph"<<endl; TGraph *grobslim_cls=new TGraphAsymmErrors(nMassEff,mass,obs_lim_cls); grobslim_cls->SetName("LimitObservedCLs"); TGraph *grmedian_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD); grmedian_cls->SetName("LimitExpectedCLs"); TGraphAsymmErrors *gr68_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD,0,0,down68err,up68err); gr68_cls->SetName("Limit68CLs"); TGraphAsymmErrors *gr95_cls=new TGraphAsymmErrors(nM95,mass95,median95,0,0,down95err,up95err); gr95_cls->SetName("Limit95CLs"); TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff,mass,ggxs,0,0,ggxs_downerr,ggxs_uperr);//ggxs_downerr,ggxs_uperr); grthSM->SetName("SMXSection"); // cout<<"Plotting"<<endl; TCanvas *cMCMC=new TCanvas("c_lim_MCMC","canvas with limits for MCMC",800,800); cMCMC->cd(); cMCMC->SetGridx(1); cMCMC->SetGridy(1); // draw a frame to define the range TH1F *hr = cMCMC->DrawFrame(190.0,0.0,610.0,6.0,"frame1"); hr->SetXTitle("M_{H} [GeV]"); hr->SetYTitle("#sigma_{95%} / #sigma_{SM}");// #rightarrow 2l2q // cMCMC->GetFrame()->SetFillColor(21); //cMCMC->GetFrame()->SetBorderSize(12); gr95_cls->SetFillColor(kYellow); gr95_cls->SetFillStyle(1001);//solid gr95_cls->GetXaxis()->SetTitle("M_{H} [GeV]"); gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} / #sigma_{SM}");// #rightarrow 2l2q gr95_cls->GetXaxis()->SetRangeUser(200.0,600.0); gr95_cls->Draw("3"); gr68_cls->SetFillColor(kGreen); gr68_cls->SetFillStyle(1001);//solid gr68_cls->Draw("3same"); grmedian_cls->GetXaxis()->SetTitle("M_{H} [GeV]"); grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} / #sigma_{SM}");// #rightarrow 2l2q grmedian_cls->SetMarkerStyle(24);//25=hollow squre grmedian_cls->SetMarkerColor(kBlack); grmedian_cls->SetLineStyle(2); grmedian_cls->SetLineWidth(2); grmedian_cls->SetMinimum(0.0); grmedian_cls->SetMaximum(8.0); grobslim_cls->SetMarkerColor(kBlack); grobslim_cls->SetMarkerStyle(21);//24=hollow circle // grobslim_cls->SetMarkerSize(1.5); grobslim_cls->SetLineStyle(1); grobslim_cls->SetLineWidth(2); grthSM->SetLineColor(kRed); grthSM->SetLineWidth(2); grthSM->SetFillColor(kRed); grthSM->SetFillStyle(3344); // grthSM->Draw("L3same"); grmedian_cls->Draw("L"); grobslim_cls->Draw("LP"); TLine *l1=new TLine(); l1->SetLineStyle(1); l1->SetLineWidth(2.0); l1->SetLineColor(kRed); l1->DrawLine(210.0,1.0,610.0,1.0); cMCMC->Update(); // cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); //more graphics TLegend *leg = new TLegend(.35,.71,.90,.90); leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.03); // leg->SetBorderMode(0); leg->AddEntry(grobslim_cls, "CL_{S} Observed", "LP"); leg->AddEntry(grmedian_cls, "CL_{S} Expected", "L"); leg->AddEntry(gr68_cls, "CL_{S} Expected #pm 1#sigma", "LF"); leg->AddEntry(gr95_cls, "CL_{S} Expected #pm 2#sigma", "LF"); leg->AddEntry(grthSM, "SM", "L");// #rightarrow 2l2q leg->Draw(); TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.04); latex->SetTextAlign(31); latex->SetTextAlign(11); // align left latex->DrawLatex(0.18, 0.96, "CMS preliminary 2011"); latex->DrawLatex(0.60,0.96,Form("%.1f fb^{-1} at #sqrt{s} = 7 TeV",intLumi)); /* leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.05); */ TLine *l1b=new TLine(); l1b->SetLineStyle(1); l1b->SetLineWidth(2.0); l1b->SetLineColor(kRed); //l1b->DrawLine(200.0,1.0,600.0,1.0); cMCMC->Update(); // cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); // cMCMC->SaveAs("ClsLimit_1fb.eps"); // cMCMC->SaveAs("ClsLimit_1fb.png"); }//end main