StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
getAvgEff.C
1 
2 void getAvgEff(Char_t* signalFile="signalShapes.root", Bool_t onlyQuadB=true, Int_t diskNr=3)
3 {
4  gStyle->SetPalette(1);
5  gStyle->SetOptStat(0);
6  TFile f(signalFile);
7  //TFile f("signalShapes.root");
8  char buffer[100];
9  sprintf(buffer,"radioDiskEffLoose_%d",diskNr-1);
10  TH2D* h=(TH2D*)f.Get(buffer);
11  sprintf(buffer,"allCountsLooseDisk_%d",diskNr);//counting different for this histo
12  TH2D* hEff=(TH2D*)f.Get(buffer);
13  sprintf(buffer,"radioDiskNonEffLoose_%d",diskNr-1);
14  TH2D* hNonEff=(TH2D*)f.Get(buffer);
15 
16  Double_t max=h->GetXaxis()->GetXmax();
17  Double_t min=h->GetXaxis()->GetXmin();
18 
19  // cout <<"max: " << max << " min: " << min << " numBins: "<< h->GetNbinsX() <<endl;
20 
21  TH2D OverallEff("overallEff","overallEff",h->GetNbinsX(),min,max,h->GetNbinsY(),min,max);
22  OverallEff.GetXaxis()->SetTitle("x [cm]");
23  OverallEff.GetYaxis()->SetTitle("y [cm]");
24 Double_t eff=0;
25 Int_t count=0;
26 
27 
28  Int_t sumEff=0;
29  Int_t sumNonEff=0;
30 
31  Double_t overallErr=0;
32 for(Int_t i=1;i<h->GetNbinsX()+1;i++)
33  {
34  for(Int_t j=1;j<h->GetNbinsY()+1;j++)
35  {
37  if(onlyQuadB)
38  {
39  if(i<(h->GetNbinsX()-1)/2|| j>(h->GetNbinsY()-1)/2)
40  continue;
41  }
42  //Int_t gBin=h->GetBin(i,j);
43  // Double_t xpos=h->GetXaxis()->GetBinCenter(gBin);
44  // Double_t ypos=h->GetYaxis()->GetBinCenter(gBin);
45  // if(xpos<0 || ypos >0)
46  // continue;
47 
48 
49  Int_t numEff=hEff->GetBinContent(i,j);
50  Int_t numNonEff=hNonEff->GetBinContent(i,j);
51  Int_t numCounts=numEff+numNonEff;
52  Double_t efficiency=0;
53  if(numCounts>0)
54  {
55 
56  efficiency=(Double_t)numEff/(Double_t)numCounts;
57  }
58  if(numEff>0)
59  {
60  sumEff+=numEff;
61  sumNonEff+=numNonEff;
62  }
63 
64  OverallEff.SetBinContent(i,j,efficiency);
65 
66  if(numCounts>0)
67  {
68  //
69  Double_t relErr=999;
70  Double_t err=999;
71  if(numEff>0)
72  {
73  relErr=sqrt((1/(Double_t)(numEff+numNonEff)+1/(Double_t)numEff));
74  err=relErr*efficiency;
75 
76  }
77  else
78  {
79  err=1/sqrt(numNonEff);
80  }
81  eff+=efficiency/(err*err);
82  overallErr+=(1/(err*err));
83 
84  count++;
85  }
86  }
87  }
88  TCanvas c;
89  Double_t avgEff=sumEff/(Double_t)(sumEff+sumNonEff);
90  //binomial error, beware of 0
91  Double_t errOnEffNum=sqrt(avgEff*(1-avgEff)*(sumEff+sumNonEff));
92  Double_t altErr= ((Double_t)1/(Double_t)(sumEff+sumNonEff))*sqrt(sumEff*(Double_t)(1-sumEff/(sumEff+sumNonEff)));
93  sprintf(buffer,"Average Efficiency is %f +- %f",avgEff,altErr);
94  TLatex t1(-30,0,buffer);
95  OverallEff.Draw("colz");
96  t1.Draw();
97  c.SaveAs("overallEff.png");
98  c.SaveAs("overallEff.C");
99 //cout <<"avg eff: " << eff/count <<endl;
100 
101  cout <<"Hits found: " << sumEff <<" Hits not found: " << sumNonEff<< " efficiency: " <<avgEff<<" +- " << altErr<<endl;
102 }