#if 0 class track:public TObject{ public: track(){} TVector3 pthrown; TVector3 pfit; double likelihood; double chisq; double pt_pull; double theta_pull; double phi_pull; bool isreconstructable; int Nstereo; int Ncdc; int Nfdc; private: ClassDef(track,1); }; #endif //-------------------- // nightly2 //-------------------- void nightly2(void) { gROOT->Reset(); gStyle->SetPalette(1,NULL); gStyle->SetErrorX(0.0); TCanvas *c1 = new TCanvas("c1",""); c1->SetTickx(); c1->SetTicky(); c1->SetGridy(); // Plot Tracking Efficiency vs. theta for each momentum TH2D *axes = new TH2D("axes","Tracking efficiency vs. #theta", 100, 0.0,160.0, 100, 0.5, 1.2); axes->SetStats(0); axes->SetXTitle("Polar angle #theta (degrees)"); axes->SetYTitle("Tracking efficiency"); axes->Draw(); TLegend *leg = new TLegend(0.6, 0.15, 0.85, 0.40); double ptot[]={0.2, 0.5, 1.0, 2.0, 3.0}; int colors[]={kBlack, kRed, kBlue, kMagenta, kGreen}; int markers[]={20, 21, 22, 23, 28}; for(int i=0; i<4; i++){ char fname[256]; sprintf(fname, "hd_root_p%2.1f.root", ptot[i]); TH1D *h = MakeHisto(fname, ptot[i], (double)(i-2)*1.0); if(!h)continue; h->SetLineColor(colors[i]); h->SetMarkerColor(colors[i]); h->SetMarkerStyle(markers[i]); h->Draw("P E1 same"); char str[256]; sprintf(str, "%2.1f GeV/c", ptot[i]); leg->AddEntry(h, str); } leg->Draw(); AddStandardLabels(axes); c1->SaveAs("eff_vs_theta.gif"); c1->SaveAs("eff_vs_theta.pdf"); } //--------------- // MakeHisto //--------------- TH1D* MakeHisto(const char *fname, double ptot, double offset) { // Create histograms gROOT->cd(); char hname[256], hname_num[256], hname_den[256]; sprintf(hname, "eff_vs_theta_p%2.1f", ptot); TH1D *eff_vs_theta = new TH1D(hname,"", 30, 0.0+offset, 160.0+offset); sprintf(hname_num, "eff_vs_theta_p%2.1f_num", ptot); TH1D *eff_vs_theta_num = eff_vs_theta->Clone(hname_num); sprintf(hname_den, "eff_vs_theta_p%2.1f_den", ptot); TH1D *eff_vs_theta_den = eff_vs_theta->Clone(hname_den); // Open ROOT file and get tree TFile *ifile = new TFile(fname); ifile->cd("TRACKING"); TTree *trkeff = (TTree*)gROOT->FindObject("trkeff"); if(!trkeff)return NULL; // It turns out that the resolutions used to determine the pulls // could be off which in turn, leads to an inaccurate chisq // and an inaccurate efficiency. To avoid this, we first fit the // pulls to gaussians in order to determine thier sigmas (which // really should be 1). These are then used to scale the event // by event pulls such that they are equivalent to sigma=1 and // the chisq re-calculated for use in determining the efficiency. double sigma_pt_pull = 1.0; double sigma_theta_pull = 1.0; double sigma_phi_pull = 1.0; TCut cut1 = "isreconstructable==1"; // sigma pt_pull TH1D *pt_pull = new TH1D("pt_pull","",200, -10.0, 10.0); trkeff->Project("pt_pull","pt_pull", cut1); pt_pull->Fit("gaus","0Q"); sigma_pt_pull = pt_pull->GetFunction("gaus")->GetParameter(2); // sigma sigma_theta_pull TH1D *theta_pull = new TH1D("theta_pull","",200, -10.0, 10.0); trkeff->Project("theta_pull","theta_pull", cut1); theta_pull->Fit("gaus","0Q"); sigma_theta_pull = theta_pull->GetFunction("gaus")->GetParameter(2); // sigma pt_pull TH1D *phi_pull = new TH1D("phi_pull","",200, -10.0, 10.0); trkeff->Project("phi_pull","phi_pull", cut1); phi_pull->Fit("gaus","0Q"); sigma_phi_pull = phi_pull->GetFunction("gaus")->GetParameter(2); cout<<"sigma_pt_pull="<cd(); trkeff->Project(hname_num, "E.pthrown.Theta()*57.3", cut1 && cut2); trkeff->Project(hname_den, "E.pthrown.Theta()*57.3", cut1); eff_vs_theta->Divide(eff_vs_theta_num, eff_vs_theta_den); // Calculate error by adding errors of numerator and denominator // in parallel. Errors of numerator and denominator are just // sqrt of number of events. for(int bin=1; bin<=eff_vs_theta->GetNbinsX(); bin++){ double err_num = sqrt(eff_vs_theta_num->GetBinContent(bin)); double err_den = sqrt(eff_vs_theta_den->GetBinContent(bin)); if(err_num==0.0)err_num = 1.0; if(err_den==0.0)err_den = 1.0; double err = (1.0/err_num + 1.0/err_den)*eff_vs_theta->GetBinContent(bin); eff_vs_theta->SetBinError(bin, err); // For errors larger than 50%, set the content of the bin // to -100 so it is not displayed if(err>0.5)eff_vs_theta->SetBinContent(bin, -100.0); } // Close file delete ifile; return eff_vs_theta; } //---------------- // AddStandardLabels //---------------- void AddStandardLabels(TH2D *axes=NULL) { // This will draw a label or two on the // current plot using the NDC coordinates. // It is put here to make sure all plots have // a consistent labeling. // Get Date TDatime *t = new TDatime(); const char * month[]={"Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."}; char date[256]; sprintf(date, "%s %d, %d : NightlyTest2", month[t->GetMonth()-1], t->GetDay(), t->GetYear()); // Date, Author TLatex *lab = new TLatex(0.6, 0.61, date); ConvertFromNDC(lab, axes); lab->SetTextSize(0.03); lab->SetTextAlign(33); lab->Draw(); // SVN Revision lab = new TLatex(0.6, 0.56, "svn revision: current"); ConvertFromNDC(lab, axes); lab->SetTextSize(0.02); lab->SetTextAlign(31); lab->Draw(); // Candidate type lab = new TLatex(0.6, 0.535, "Candidates from finder"); ConvertFromNDC(lab, axes); lab->SetTextSize(0.02); lab->SetTextAlign(31); lab->Draw(); // Event type lab = new TLatex(0.6, 0.505, "Single #pi^{+} with MULS, LOSS, DRAY on"); ConvertFromNDC(lab, axes); lab->SetTextSize(0.03); lab->SetTextAlign(31); lab->Draw(); } //---------------- // ConvertFromNDC //---------------- void ConvertFromNDC(TLatex *obj, TH2D *h=NULL) { // Bugs in ROOT make it hard to plot labels consistently. // For 1D plots, the histogram axes define the coordinate // system. For 2D plots, we seem to be forced to use the // NDC. There does not seem to be an obvious way to tell // which we're using so we pass the information in in the // form of the "axes" histogram. If it is not NULL, then // we use it to define the limits. Otherwise, we do nothing. if(h==NULL)return; TAxis *xaxis = h->GetXaxis(); int Nbinsx = xaxis->GetNbins(); double xmin = xaxis->GetBinLowEdge(1); double xmax =xaxis->GetBinLowEdge(Nbinsx+1); TAxis *yaxis = h->GetYaxis(); int Nbinsy = yaxis->GetNbins(); double ymin = yaxis->GetBinLowEdge(1); double ymax = yaxis->GetBinLowEdge(Nbinsy+1); cout<<"xmin="<