FairRoot/PandaRoot
evaltrig.C
Go to the documentation of this file.
1 #include <algorithm>
2 #include <map>
3 #include <utility>
4 #include <iostream>
5 
6 #include "TFile.h"
7 #include "TTree.h"
8 #include "TString.h"
9 #include "TCanvas.h"
10 #include "TH1F.h"
11 #include "TH2F.h"
12 #include "TROOT.h"
13 #include "TEventList.h"
14 #include "TDirectory.h"
15 #include "TRegexp.h"
16 #include "TStyle.h"
17 #include "TColor.h"
18 #include "TPaletteAxis.h"
19 #include "TLegend.h"
20 #include "TKey.h"
21 #include "TGraph.h"
22 
23 const int nlines = 57;
24 
25 // maps energies to signal and background efficiencies
26 typedef std::map<double, TH1F*> Hmap;
27 typedef std::map<double, TH1F*>::iterator Hmapit;
28 std::map<int,int> codeidx;
29 
30 TGraph geff[100];
31 int cnt[]= {0,0,0,0,0,0,0,0};
32 
34 
35 // ---------------------------------------------------------------------
36 int modes[] = { 100, 101, 102, 103, 104,
37  110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
38  120, 121, 122, 123,
39  130, 131, 132, 133, 134, 135, 136, 137, 138,
40  140, 141, 150, 151,
41  200, 201, 220, 221, 222, 223, 224, 240, 241,
42  400, 410, 420, 421, 422,
43  500,
44  600, 601, 602, 620, 621, 622, 640, 641, 642, 660};
45 // BR in %
46 double BR[] = { 3.9, 13.9, 8.1, 2.0, 3.7,
47  2.4, 8.6, 5.0, 1.2, 2.3, 1.5, 5.3, 3.1, 0.76, 1.4,
48  9.4, 6.1, 4.8, 2.1,
49  2.6, 9.4, 5.5, 1.4, 2.5, 6.4, 4.1, 3.2, 1.4,
50  5.5, 5.6, 5.4, 5.5,
51  5.9, 5.9, 1.2, 1.7, 6e-5, 3.5, 1.9, 1.8, 1.7,
52  63.9, 51.4, 5.0, 3.4, 1.7,
53  48.9,
54  100., 100., 100., 100., 100., 100., 100., 100., 100., 100.};
55 
56 int panel[] = { 0, 0, 0, 0, 0,
57  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
58  2, 2, 2, 2,
59  3, 3, 3, 3, 3, 3, 3, 3, 3,
60  4, 4, 4, 4,
61  5, 5, 5, 5, 5, 5, 5, 5, 5,
62  6, 6, 6, 6, 6,
63  6,
64  7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
65 
66 TString datatype[] = {"D^{0}","D^{*0}","D^{#pm}","D^{*#pm}","D_{s}^{(*)#pm}","c#bar{c}","bayrons/#phi","e/#mu/#gamma"};
67 double range[] = { 2.5, 3.5, 3.0, 3.5, 3.5, 2.0, 2.0, 2.0 };
68 
69 int cols[10] = {1,2,4,6,kOrange+5,9,kGreen+2, kBlue+3,kCyan-2,kMagenta+2};
70 
71 // ---------------------------------------------------------------------
72 
73 void config_graph(TGraph *g, int m=0, TString name="")
74 {
75  int color=m;
76  if (m<10) color=cols[m];
77  g->SetMarkerStyle(m%15+20);
78  g->SetMarkerColor(1);
79  g->SetMarkerSize(1.2);
80  g->SetLineWidth(2);
81  g->SetLineColor(color);
82  g->SetMarkerColor(color);
83  g->SetName(name);
84 }
85 
86 // ---------------------------------------------------------------------
87 
88 void init()
89 {
90  for (int i=0;i<nlines;++i)
91  {
92  codeidx[modes[i]]=i;
93  config_graph(&geff[i],cnt[panel[i]]++,TString::Format("M%d",modes[i]));
94  }
95 
96  config_graph(&geff[nlines],0,"DPM");
97 }
98 
99 // ---------------------------------------------------------------------
100 
101 int evaltrig(TString fname="crosstag_histos.root", bool makeplots=0)
102 {
103  init();
104 
105  TFile *f = new TFile(fname,"READ");
106 
107  TKey *key;
108  TIter next(f->GetListOfKeys());
109 
110  TRegexp rsig("hsig[0-9][0-9][0-9]");
111  TRegexp rsigi("hsigi[0-9][0-9][0-9]");
112  TRegexp rbg("hbg[0-9][0-9][0-9]");
113 
114  while ( (key = (TKey*)next()) )
115  {
116  TObject *obj = key->ReadObj();
117  if (!obj->InheritsFrom("TH1F")) continue;
118 
119  TString name = obj->GetName();
120  TH1F* h = (TH1F*) obj;
121 
122  double en = TString(name(name.Length()-3,3)).Atof()/100.;
123 
124  if (name(rsig)!="") sigmap[en] = h;
125  else if (name(rsigi)!="") sigimap[en] = h;
126  else if (name(rbg)!="") bgmap[en] = h;
127  }
128 
129  int Nen = sigmap.size();
130  int i=1;
131 
132  TCanvas *c1 = new TCanvas("c1","histos",10,10,1800,500);
133  c1->Divide(Nen,2);
134 
135  for (Hmapit it=sigmap.begin(); it!=sigmap.end(); ++it)
136  {
137  TH1F *hs = it->second;
138  TH1F *hsi = sigimap[it->first];
139  TH1F *hb = bgmap[it->first];
140 
141  c1->cd(i); hs->Draw(); hsi->Draw("same");
142  c1->cd(i+Nen); hb->Draw();
143  i++;
144 
145  for (int j=1;j<hs->GetNbinsX()+1;++j)
146  {
147  TString modestr = hs->GetXaxis()->GetBinLabel(j);
148  if (modestr=="DPM")
149  {
150  TGraph &g = geff[nlines];
151  g.SetPoint(g.GetN(),it->first, hs->GetBinContent(j));
152  }
153  else
154  {
155  int mode = TString(modestr(1,3)).Atoi();
156  double eff = hs->GetBinContent(j);
157 
158  TGraph &g = geff[codeidx[mode]];
159  g.SetPoint(g.GetN(),it->first, eff);
160  }
161  }
162  }
163 
164  TCanvas *c2=new TCanvas("c2","sig eff",100,30,1600,800);
165  c2->Divide(4,2);
166 
167  TH1F *hdisp = new TH1F("hdisp","Signal Efficiencies",100,2.0,6.0);
168  hdisp->SetMaximum(100.);
169  hdisp->SetStats(0);
170  hdisp->SetXTitle("E_{cm} [GeV]");
171  hdisp->SetYTitle("total effciency [%]");
172  //hdisp->Draw();
173 
174  TLegend *leg[8];
175  for (i=0;i<8;++i)
176  {
177  c2->cd(i+1);
178  gPad->SetTopMargin(0.1);
179  gPad->SetGridx();
180  gPad->SetGridy();
181  hdisp->SetTitle("Signal efficiency: "+datatype[i]+" modes");
182  hdisp->GetXaxis()->SetRangeUser(range[i],6.0);
183  hdisp->DrawCopy();
184  if (i<7)
185  {
186  leg[i]=new TLegend(0.14,0.9-cnt[i]*0.07,0.4,0.9);
187  leg[i]->SetMargin(0.4);
188  }
189  else
190  {
191  leg[i]=new TLegend(0.14,0.12,0.9,0.45);
192  leg[i]->SetNColumns(3);
193  leg[i]->SetMargin(0.5);
194  }
195  }
196 
197  for (i=0;i<nlines;++i)
198  {
199  c2->cd(panel[i]+1);
200  geff[i].Draw("PL same");
201  leg[panel[i]]->AddEntry(geff[i].GetName(),geff[i].GetName(),"EPL");
202  }
203  for (i=0;i<8;++i)
204  {
205  c2->cd(i+1);
206  leg[i]->Draw("same");
207  }
208  c2->Update();
209 
210  TCanvas *c3=new TCanvas("c3","bg eff",150,40,700,500);
211  c3->cd();
212  gPad->SetGridx();
213  gPad->SetGridy();
214  hdisp->SetMaximum(0.5);
215  hdisp->SetMinimum(0.0);
216  hdisp->SetTitle("Background level");
217  hdisp->SetYTitle("acc. background [%]");
218  hdisp->DrawCopy();
219  geff[nlines].Draw("PL same");
220  TLine l;
221  l.SetLineColor(2);l.SetLineStyle(2);l.SetLineWidth(2);
222  l.DrawLine(2,0.1,6,0.1);
223 
224  if (makeplots)
225  {
226  c2->SaveAs("effsig_graphs.gif");
227  c2->SaveAs("effsig_graphs.pdf");
228 
229  c3->SaveAs("effbg_graphs.gif");
230  c3->SaveAs("effbg_graphs.pdf");
231  }
232  return 0;
233 }
234 
void config_graph(TGraph *g, int m=0, TString name="")
Definition: evaltrig.C:73
int modes[]
Definition: evaltrig.C:36
double range[]
Definition: evaltrig.C:67
int panel[]
Definition: evaltrig.C:56
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
int evaltrig(TString fname="crosstag_histos.root", bool makeplots=0)
Definition: evaltrig.C:101
TFile * g
TString datatype[]
Definition: evaltrig.C:66
c2
Definition: plot_dirc.C:39
const int nlines
Definition: evaltrig.C:23
Int_t mode
Definition: autocutx.C:47
std::map< double, TH1F * > Hmap
Definition: evaltrig.C:26
void init()
Definition: evaltrig.C:88
Hmap bgmap
Definition: evaltrig.C:33
TGraph geff[100]
Definition: evaltrig.C:30
int cols[10]
Definition: evaltrig.C:69
Hmap sigmap
Definition: evaltrig.C:33
TFile * f
Definition: bump_analys.C:12
int cnt[]
Definition: evaltrig.C:31
double BR[]
Definition: evaltrig.C:46
c1
Definition: plot_dirc.C:35
TString name
c3
Definition: plot_dirc.C:50
std::map< int, int > codeidx
Definition: evaltrig.C:28
Hmap sigimap
Definition: evaltrig.C:33
std::map< double, TH1F * >::iterator Hmapit
Definition: evaltrig.C:27
static int next[96]
Definition: ranlxd.cxx:374
PndAnaPidSelector *& obj