Hi, I couldn't make the attached script compiled with ACLiC. What I did is : root[0] .L drawGraph.C+ Then I got following message. /home/dwjang/work/scratch/RtgAnalyzer/filevT8NTe.cxx: In function `int G__filevT8NTe__0_26(G__value*, const char*, G__param*, int)': /home/dwjang/work/scratch/RtgAnalyzer/filevT8NTe.cxx:98: parse error before `*' token /home/dwjang/work/scratch/RtgAnalyzer/filevT8NTe.cxx: In function `int G__filevT8NTe__1_26(G__value*, const char*, G__param*, int)': /home/dwjang/work/scratch/RtgAnalyzer/filevT8NTe.cxx:103: parse error before `* ' token /home/dwjang/work/scratch/RtgAnalyzer/filevT8NTe.cxx: In function `int G__filevT8NTe__2_26(G__value*, const char*, G__param*, int)': /home/dwjang/work/scratch/RtgAnalyzer/filevT8NTe.cxx:108: parse error before `* ' token g++: /home/dwjang/work/scratch/RtgAnalyzer/./filevT8NTe.o: No such file or directory Error in <ACLiC>: Compilation failed! Thank you in advance. Dongwook Jang. //-------------------------------------------------------------------------- // File and Version Information: // $Id: drawGraph.C,v 1.12 2004/02/13 19:32:54 dwjang Exp $ // // Description: // root script for making fake rate canvases // // Usage: // root[0].x drawGraph.C // //------------------------------------------------------------------------ #ifndef __CINT__ #include "TFile.h" #include "TTree.h" #include "TString.h" #include "TH1F.h" #include "TH2F.h" #include "TF1.h" #include "TGraphErrors.h" #include "TCanvas.h" #include <iostream> using namespace std; #endif #define nEtBin 11 // bin : 0 1 2 3 4 5 6 7 8 9 10 // lowEdge : 15 20 25 30 35 40 50 60 80 100 150 const float xLowEdge[3][nEtBin] = { {15.0,20.0,25.0,30.0,35.0,40.0,45.0,50.0,55.0,60.0,70.0}, // for JET_20 {15.0,20.0,25.0,30.0,35.0,40.0,50.0,60.0,80.0,100.0,150.0}, // for JET_50 {15.0,20.0,25.0,30.0,35.0,40.0,50.0,60.0,80.0,100.0,150.0} // for JET_70 }; float DivError(float x1, float x2, float e1, float e2); TGraphErrors* FillGraph(TTree* tree, TString bName, int iJet, int whichJet); TGraphErrors* AddGraph(TGraphErrors* g1, TGraphErrors* g2); TGraphErrors* DivideGraph(TGraphErrors* g1, TGraphErrors* g2); void drawGraph(){ const int NJET = 3; TString jetTrig[NJET] = {"JET_20","JET_50","JET_70"}; TFile* nf[NJET]; TTree* nt[NJET][3]; // jet sample, different ntuples in a given sample float clusterEt_loose[NJET]; float clusterWidth_loose[NJET]; float clusterMass_loose[NJET]; float emFraction_loose[NJET]; float calIsoR_loose[NJET]; float isTrigger_loose[NJET]; float clusterEt_tight[NJET]; float clusterWidth_tight[NJET]; float clusterMass_tight[NJET]; float emFraction_tight[NJET]; float calIsoR_tight[NJET]; float isTrigger_tight[NJET]; float clusterEt_tight_calIsoR_n1[NJET]; float calIsoR_tight_calIsoR_n1[NJET]; float isTrigger_tight_calIsoR_n1[NJET]; TH1F* n_et = new TH1F("n_et","n_et",200,0,200); TH1F* d_et = new TH1F("d_et","d_et",200,0,200); TGraphErrors* g_clusterEt = new TGraphErrors(3*nEtBin); TGraphErrors* dg[NJET]; TGraphErrors* ng[NJET]; for(int i=0; i<NJET; i++){ nf[i] = new TFile("results/ntuples_FakeRate_"+jetTrig[i]+".root","READ"); nt[i][0] = (TTree*) nf[i]->Get("ntuple_loose"); // nt[i][0]->SetBranchAddress("clusterEt",&clusterEt_loose[i]); // nt[i][0]->SetBranchAddress("clusterWidth",&clusterWidth_loose[i]); // nt[i][0]->SetBranchAddress("clusterMass",&clusterMass_loose[i]); // nt[i][0]->SetBranchAddress("emFraction",&emFraction_loose[i]); // nt[i][0]->SetBranchAddress("calIsoR",&calIsoR_loose[i]); // nt[i][0]->SetBranchAddress("isTrigger",&isTrigger_loose[i]); dg[i] = FillGraph(nt[i][0],"clusterEt",i,0); Int_t nentries = (int) nt[i][0]->GetEntries(); for(int ev=0; ev<nentries; ev++){ nt[i][0]->GetEntry(ev); if(i==0) d_et->Fill(clusterEt_loose[0]); } nt[i][1] = (TTree*) nf[i]->Get("ntuple_tight"); // nt[i][1]->SetBranchAddress("clusterEt",&clusterEt_tight[i]); // nt[i][1]->SetBranchAddress("clusterWidth",&clusterWidth_tight[i]); // nt[i][1]->SetBranchAddress("clusterMass",&clusterMass_tight[i]); // nt[i][1]->SetBranchAddress("emFraction",&emFraction_tight[i]); // nt[i][1]->SetBranchAddress("calIsoR",&calIsoR_tight[i]); // nt[i][1]->SetBranchAddress("isTrigger",&isTrigger_tight[i]); ng[i] = FillGraph(nt[i][1],"clusterEt",i,0); nentries = (int) nt[i][1]->GetEntries(); for(int ev=0; ev<nentries; ev++){ nt[i][1]->GetEntry(ev); if(i==0) n_et->Fill(clusterEt_tight[0]); } nt[i][2] = (TTree*) nf[i]->Get("ntuple_tight_calIsoR_n1"); // nt[i][2]->SetBranchAddress("clusterEt",&clusterEt_tight_calIsoR_n1[i]); // nt[i][2]->SetBranchAddress("calIsoR",&calIsoR_tight_calIsoR_n1[i]); // nt[i][2]->SetBranchAddress("isTrigger",&isTrigger_tight_calIsoR_n1[i]); nentries = (int) nt[i][2]->GetEntries(); for(int ev=0; ev<nentries; ev++){ nt[i][2]->GetEntry(ev); } }// for i TGraphErrors* gg[NJET]; for(int i=0; i<NJET; i++){ gg[i] = DivideGraph(ng[i],dg[i]); gg[i]->SetMarkerStyle(20); gg[i]->SetMarkerColor(2+i); } TGraphErrors* g12 = AddGraph(gg[0],gg[1]); TGraphErrors* g = AddGraph(g12,gg[2]); TCanvas* can = new TCanvas("can","can",800,800); TH2F* back = new TH2F("rate","rate",200,0,200,100,0,0.5); can->Divide(2,2); can->cd(1); back->Draw(); gg[0]->Draw("P"); can->cd(2); back->Draw(); gg[1]->Draw("P"); can->cd(3); back->Draw(); gg[2]->Draw("P"); can->cd(4); back->Draw(); g->SetMarkerStyle(20); g->SetMarkerColor(1); g->Draw("P"); /* g->Fit("pol2","LER","",15.0,200.0); */ /* g->GetFunction("plo2")->Draw("same"); */ // Int_t nSection = 3; // Int_t *nGroup = new Int_t[nSection]; // Double_t *splitPoints = new Double_t[nSection+1]; // nGroup[0] = 5; // nGroup[1] = 25; // nGroup[2] = 50; // splitPoints[0] = 0.0; // splitPoints[1] = 50.0; // splitPoints[2] = 100.0; // splitPoints[3] = 200.0; // Rebin(n_et,nGroup,splitPoints,nSection); // Rebin(d_et,nGroup,splitPoints,nSection); // TH1F* r_et = Divide(n_et,d_et); // //r_et->Draw("et"); /* int n = 10; float x[10] = {1.0,2.1,3.0,3.9,4.1,2.5,3.0,7.1,8.0,4.1}; float y[10] = {3.0,4.0,5.0,3.5,3.1,2.0,5.1.4.4,3.7,2.8}; float xe[10] = {2.1,3.5,0.3,5.2,0.2,0.5,0.7,0.6,1.2,1.3}; float ye[10] = {1,1,1,1,1,1,1,1,1,1}; TCanvas* can = new TCanvas("can","can",600,600); can->Divide(1,2); can->cd(1); TGraphErrors* gr = new TGraphErrors(n,x,y,xe,ye); gr->SetMarkerStyle(20); gr->SetMarkerColor(2); gr->Draw("AP"); can->cd(2); TGraphErrors* gr2 = (TGraphErrors*) gr->Clone(); gr2->InsertPoint(); gr2->SetPoint(10,0.3,0.3); gr2->SetPointError(10,0.3,0.3); gr2->Draw("AP"); */ } //--------------------------------------------------------------- // function's implementation //--------------------------------------------------------------- float DivError(float x1, float x2, float e1, float e2){ // err(x1/x2) = (x1/x2) * sqrt(e1^2/x1^2 + e2^2/x2^2) float error = 0.0; if(x1 < 1.0e-6 || x2 < 1.0e-6) return error; error = x1/x2 * sqrt(e1*e1/x1/x1 + e2*e2/x2/x2); return error; } TGraphErrors* AddGraph(TGraphErrors* g1, TGraphErrors* g2){ // This is adding points to a new graph not computing addition Int_t n1 = g1->GetN(); Int_t n2 = g2->GetN(); Double_t* x1s = g1->GetX(); Double_t* x2s = g2->GetX(); Double_t* y1s = g1->GetY(); Double_t* y2s = g2->GetY(); Double_t* ex1s = g1->GetEX(); Double_t* ex2s = g2->GetEX(); Double_t* ey1s = g1->GetEY(); Double_t* ey2s = g2->GetEY(); const int nbins = n1 + n2; Double_t x[nbins], y[nbins], ex[nbins], ey[nbins]; for(int i=0; i<n1; i++){ x[i] = x1s[i]; y[i] = y1s[i]; ex[i] = ex1s[i]; ey[i] = ey1s[i]; } for(int i=0; i<n2; i++){ x[n1+i] = x2s[i]; y[n1+i] = y2s[i]; ex[n1+i] = ex2s[i]; ey[n1+i] = ey2s[i]; } return new TGraphErrors(nbins,x,y,ex,ey); } TGraphErrors* DivideGraph(TGraphErrors* g1, TGraphErrors* g2){ Int_t n1 = g1->GetN(); Int_t n2 = g2->GetN(); if(n1 != n2){ cout << "You are dividing graphs with different bins" << endl; return new TGraphErrors(1); } if(n1 != nEtBin){ cout << "Check graph binning" << endl; return new TGraphErrors(1); } // cout << "n1, n2 : " << n1 << ", " << n2 << endl; // cout << "g1, g2 address : " << g1 << ", " << g2 << endl; Double_t* x1s = g1->GetX(); Double_t* x2s = g2->GetX(); Double_t* y1s = g1->GetY(); Double_t* y2s = g2->GetY(); Double_t* ex1s = g1->GetEX(); Double_t* ex2s = g2->GetEX(); Double_t* ey1s = g1->GetEY(); Double_t* ey2s = g2->GetEY(); const int nbins = nEtBin; Double_t x[nbins], y[nbins], ex[nbins], ey[nbins]; for(int i=0; i<nbins; i++){ x[i] = y[i] = ex[i] = ey[i] = 0.0; // cout << i << "th x1s,x2s,y1s,y2s,ex1s,ex2s,ey1s,ey2s : " // << x1s[i] << ", " << x2s[i] << ", " << y1s[i] << ", " << y2s[i] << ", " // << ex1s[i] << ", " << ex2s[i] << ", " << ey1s[i] << ", " << ey2s[i] << endl; // error weighted average and gaussian error for x // x[i] = ex1s[i]*x1s[i] + ex2s[i]*x2s[i]; // if(ex1s[i] + ex2s[i] < 1.0e-6) x[i] = -1.0; // x[i] = x[i]/(ex1s[i] + ex2s[i]); x[i] = x2s[i]; ex[i] = sqrt(ex1s[i]*ex1s[i] + ex2s[i]*ex2s[i]); if(y2s[i] < 1.0e-6) y[i] = -1.0; y[i] = y1s[i]/y2s[i]; ey[i] = DivError(y1s[i],y2s[i],ey1s[i],ey2s[i]); // cout << i << "th x,y,ex,ey : " // << x[i] << ", " << y[i] << ", " << ex[i] << ", " << ey[i] << endl; } // cout << "nbins, x, y, ex, ey : " // << nbins << ", " << x[0] << ", " << y[0] << ", " << ex[0] << ", " << ey[0] << endl; return new TGraphErrors(nbins,x,y,ex,ey); } TGraphErrors* FillGraph(TTree* tree, TString bName, int iJet, int whichJet){ // input : tree, branchName // output : graph float xx = 0.0; float isTrigger = 0.0; tree->SetBranchAddress(bName,&xx); tree->SetBranchAddress("isTrigger",&isTrigger); float x[nEtBin],y[nEtBin],ex[nEtBin],ey[nEtBin]; for(int i=0; i<nEtBin; i++) x[i] = y[i] = ex[i] = ey[i] = 0.0; Int_t nentries = (int) tree->GetEntries(); for(int ev=0; ev<nentries; ev++){ tree->GetEntry(ev); if(TMath::Abs(isTrigger - whichJet) > 0.5) continue; if(xx < xLowEdge[iJet][0]) continue; else if(xx >= xLowEdge[iJet][nEtBin-1]){ x[nEtBin-1] += xx; y[nEtBin-1] += 1.0; continue; } for(int i=0; i<nEtBin-1; i++){ if(xx >= xLowEdge[iJet][i] && xx < xLowEdge[iJet][i+1]){ x[i] += xx; y[i] += 1.0; continue; } } } // put actual mean value to x // assign possion errors to ey for(int i=0; i<nEtBin; i++){ if(y[i] < 1.0e-6) x[i] = -1.0; else x[i] = x[i]/y[i]; ey[i] = sqrt(y[i]); } for(int ev=0; ev<nentries; ev++){ tree->GetEntry(ev); if(TMath::Abs(isTrigger - whichJet) > 0.5) continue; if(xx < xLowEdge[iJet][0]) continue; else if(xx >= xLowEdge[iJet][nEtBin-1]){ ex[nEtBin-1] += (xx-x[nEtBin-1])*(xx-x[nEtBin-1]); continue; } for(int i=0; i<nEtBin-1; i++){ if(xx >= xLowEdge[iJet][i] && xx < xLowEdge[iJet][i+1]){ ex[i] += (xx-x[i])*(xx-x[i]); } } } for(int i=0; i<nEtBin; i++){ if(y[i] < 1.0e-6) ex[i] = 0.0; else ex[i] = sqrt(ex[i])/y[i]; } return new TGraphErrors(nEtBin,x,y,ex,ey); }
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET