FairRoot/PandaRoot
analyse_phi_base.C
Go to the documentation of this file.
1 // --------------------------------------------------------------------
2 // counts different events for a cut
3 long int cntEvt(TTree *t1, TString cut, TString var="ev")
4 {
5  float fbev;
6  int ibev;
7 
8  TBranch *br = t1->GetBranch(var);
9  if (br==0) return 0;
10 
11  TString tit = br->GetTitle(); // should end with '/I' or '/F'
12 
13  t1->SetEventList(0);
14  t1->Draw(">>el",cut);
15  TEventList *el=(TEventList*)gROOT->FindObject("el");
16 
17  t1->SetBranchStatus("*",0);
18  t1->SetBranchStatus(var,1);
19 
20  // int or float branch
21  bool isint=tit.EndsWith("/I");
22 
23  if (isint)
24  t1->SetBranchAddress(var,&ibev);
25  else
26  t1->SetBranchAddress(var,&fbev);
27 
28  // last and current event number; counter
29  int lev = -1, cev=-1, cnt=0;
30  for (int i=0;i<el->GetN();++i)
31  {
32  t1->GetEvent(el->GetEntry(i));
33 
34  cev = isint ? ibev : fbev;
35 
36  if (lev!=cev) cnt++;
37  lev = cev;
38  }
39 
40  t1->SetBranchStatus("*",1);
41 
42  return cnt;
43 }
44 
45 // --------------------------------------------------------------------
46 
47 void confgraph(TGraph *g, TString tit, int col=1, int marker=20)
48 {
49  g->GetHistogram()->SetTitle(tit);
50  g->GetHistogram()->SetMinimum(0);
51  g->SetLineColor(col);
52  g->SetMarkerColor(col);
53  g->SetMarkerStyle(marker);
54  g->SetMarkerSize(1);
55  g->SetLineWidth(2);
56 }
57 
58 // --------------------------------------------------------------------
59 
60 TH1F* createHistoGraph(TGraph *g, TString tit="", double xmin=0, double xmax=0)
61 {
62  static int cnt=0;
63  if (tit=="") tit=g->GetTitle();
64 
65  double ymax = TMath::MaxElement(g->GetN(), g->GetY());
66  double dymax = g->GetErrorY(TMath::LocMax(g->GetN(), g->GetEY()));
67 
68  if (xmin>=xmax)
69  {
70  xmin = TMath::MinElement(g->GetN(), g->GetX());
71  xmax = TMath::MaxElement(g->GetN(), g->GetX());
72  }
73  TH1F *h=new TH1F(Form("h%03d",cnt++),tit,g->GetN(),xmin-0.5*(xmax-xmin)/g->GetN(), xmax+0.5*(xmax-xmin)/g->GetN());
74 
75  h->GetXaxis()->SetLabelSize(0.05);
76  h->GetXaxis()->SetTitleSize(0.05);
77  h->GetYaxis()->SetLabelSize(0.05);
78  h->GetYaxis()->SetTitleSize(0.05);
79  h->GetYaxis()->SetTitleOffset(1.4);
80 
81  h->SetMaximum((ymax+dymax)*1.05);
82  h->SetMinimum(0);
83 
84  h->SetStats(0);
85 
86  return h;
87 }
88 
89 // --------------------------------------------------------------------
90 
91 void analyse_phi_base(TString fname="ntp1_2phi_A.root", TString cut="abs(f4cxd0m+f4cxd1m-2.15)<0.15&&abs(f4cxd0m-1.02)<0.012&&abs(f4cxd1m-1.02)<0.012&chi24c<50", int sigmode=0, TString tit="")
92 {
93 /*
94 Found 553 files with pattern data/DPM2phi_A_EMC1 containing event info Sum of events = 859179654
95 Found 327 files with pattern data/DPM2phi_A_EMC5 containing event info Sum of events = 508041001
96 Found 294 files with pattern data/DPM2phi_A_EMC8 containing event info Sum of events = 456811794
97 Found 308 files with pattern data/DPM2phi_B_EMC1 containing event info Sum of events = 478549190
98 Found 346 files with pattern data/DPM2phi_B_EMC5 containing event info Sum of events = 537555935
99 Found 541 files with pattern data/DPM2phi_B_EMC8 containing event info Sum of events = 840537554
100 */
101 
102  std::map<long int,long int> evcnts =
103  { {1000,859179654}, {1001,1}, {1002,1}, {1003,1}, {1004,508041001}, {1005,1}, {1006,1}, {1007,456811794}, // Setup A, pbp -> 2phi
104  {1020,478549190}, {1021,1}, {1022,1}, {1023,1}, {1024,537555935}, {1025,1}, {1026,1}, {1027,840537554} // Setup B, pbp -> 2phi
105  };
106 
107 
108  //for ( auto x:evcnts) cout <<"mode "<<x.first<<" : "<<x.second<<endl;
109  //cout <<endl;
110 
111  if (cut=="") cut="1";
112 
113  int bkgmode = sigmode+1000;
114  //if (sigmode%100>19) bkgmode+=1;
115 
116  TFile *f = new TFile(fname);
117  TTree *t = (TTree*)f->Get("ntp1");
118 
119  TFile fana("anaPhi.root","UPDATE");
120 
121  TGraphErrors *g[4];
122  g[0] = new TGraphErrors(3);
123  g[1] = new TGraphErrors(3);
124  g[2] = new TGraphErrors(3);
125  g[3] = new TGraphErrors(3);
126 
127  confgraph(g[0], "signal to noise");
128  confgraph(g[1], "significance");
129  confgraph(g[2], "signal efficiency");
130  confgraph(g[3], "background efficiency");
131 
132  TF1 *f1=new TF1("f1","pol0",0,100.);
133  f1->SetParLimits(2,15,100);
134 
135  // -------------------------------------------------------------------
136  // Supermodul | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
137  // num Alveolen in theta | 1 | 3 | 3 | 3 | 3 | 3 | 2 |
138  // coverage from 22 to |140.0|133.4|113.8| 94.1| 74.4| 54.8| 35.1|
139  // -------------------------------------------------------------------
140 
141  // missing fraction in [%] of EMC = [ 1.0 - (tht_max - 22°)/118° ]* 100
142  double emc_rmv[8] = { 0., 6., 23., 39., 56., 72., 89., 100.};
143 
144  //TString lab[4] = { ";supermodules missing;S/B", ";supermodules missing;significance [#sigma]", ";supermodules missing;signal efficiency [%]", ";supermodules missing;background efficiency [%]"};
145  TString lab[4] = { ";EMC missing (polar #theta) [%];signal efficiency [%]", ";EMC missing (polar #theta) [%];background efficiency [%]", ";EMC missing (polar #theta) [%];S/B", ";EMC missing (polar #theta) [%];significance [#sigma]"};
146 
147 
148  TCanvas *c1 = new TCanvas("c1","c1",1000,800);
149  c1->Divide(2,2,0.0001,0.0001);
150 
151  double sig_S = 100;
152  double sig_B = 60e6;
153 
154  double Lint = 788*0.5;
155  double fBR = 0.489*0.489;
156 
157  double S_dat = sig_S * fBR * Lint;
158  double B_dat = sig_B * Lint;
159 
160  cout <<"S:B = "<<S_dat/B_dat<<" mode_S="<<sigmode<<" mode_B="<<bkgmode<<endl;
161 
162  int idxx[3] = {0, 4, 7};
163 
164  for (int jj=0;jj<3;++jj)
165  {
166  int i=idxx[jj];
167 
168  long int S0 = 1e5;
169  long int B0 = evcnts[sigmode+i+1000];
170 
171  cout <<"S0 = "<<S0<<" B0 = "<<B0<<endl;
172 
173  double fS = S_dat/S0;
174  double fB = B_dat/B0;
175 
176  TString sigcut = Form("%s && mode==%d", cut.Data(), sigmode+i);
177  TString bkgcut = Form("%s && mode==%d", cut.Data(), bkgmode+i);
178 
179 
180  double S = (double) cntEvt(t, sigcut);
181  double B = (double) cntEvt(t, bkgcut);
182  double dS = sqrt(S);
183  double dB = sqrt(B);
184 
185  cout <<i<<": S="<<S<<" B="<<B<<" --> S*"<<fS<<"="<<S*fS<<" B*"<<fB<<"="<<B*fB<<endl;
186 
187  double SN = S*fS/(B*fB);
188  double dSN = SN*sqrt(dS*dS/(S*S) + dB*dB/(B*B));
189 
190  g[2]->SetPoint(jj, emc_rmv[i], SN);
191  g[2]->SetPointError(jj, 0, dSN);
192 
193 
194  double Z = S*fS/sqrt(S*fS+B*fB);
195  double dZ = 0.5 * sqrt( ((fS*fS*S+2*fB*fS*B)*(fS*fS*S+2*fB*fS*B)*S + fS*fS*fB*fB*S*S*B)/pow(fS*S+fB*B,3)) ;//0.5 * sqrt( (pow(2*B*fB + S*fS,2)*S + fS*fS*S*S*B)/pow(fS*S+fB*B,3));
196 
197  g[3]->SetPoint(jj, emc_rmv[i], Z);
198  g[3]->SetPointError(jj, 0, dZ);
199 
200 
201  double effS = S/S0;
202  double deffS = effS*sqrt( 1./S + 1./S0 );
203 
204  g[0]->SetPoint(jj, emc_rmv[i], effS*100.);
205  g[0]->SetPointError(jj, 0, deffS*100.);
206 
207 
208  double effB = B/B0;
209  double deffB = effB*sqrt( 1./B + 1./B0 );
210 
211  g[1]->SetPoint(jj, emc_rmv[i], effB*100.);
212  g[1]->SetPointError(jj, 0, deffB*100.);
213  }
214 
215  TH1F *h[4];
216 
217  gStyle->SetOptFit(0);
218  gStyle->SetOptStat(0);
219 
220  TString plotnam[4]={"effs","effb","sn","sign"};
221 
222  for (int i=0;i<4;++i)
223  {
224  c1->cd(i+1);
225  gPad->SetTopMargin(0.10);
226  h[i] = createHistoGraph(g[i],tit+lab[i]);
227  h[i]->Draw();
228  g[i]->Draw("P same");
229 
230  f1->SetParameters(TMath::MaxElement(g[i]->GetN(), g[i]->GetY()),70, 10, TMath::MinElement(g[i]->GetN(), g[i]->GetY()));
231  if (i==1)
232  {
233  f1->SetParameters(TMath::MaxElement(g[i]->GetN(), g[i]->GetY()),120, -10, TMath::MinElement(g[i]->GetN(), g[i]->GetY()));
234  f1->SetParLimits(1,110,200);
235  }
236 
237 
238  //if (i<3)
239  g[i]->Fit("f1","q");
240  //else g[i]->Fit("f2");
241  g[i]->SetName(plotnam[i]+"_"+((TString)fname(6,5)));
242  g[i]->Write();
243  }
244 
245  fname.ReplaceAll(".root","");
246  cut.ReplaceAll("&&","_AND_");
247  cut.ReplaceAll("||","_OR_");
248  cut.ReplaceAll("!","_NOT_");
249  cut.ReplaceAll(">","_lg_");
250  cut.ReplaceAll("<","_sm_");
251  cut.ReplaceAll(".","_");
252 
253  c1->SaveAs(Form("fig/%s__%03d__%s.gif",fname.Data(), sigmode, cut.Data()));
254  c1->SaveAs(Form("fig/%s__%03d__%s.C",fname.Data(), sigmode, cut.Data()));
255 
256  fana.Close();
257 }
258 
259 
Int_t t1
Definition: hist-t7.C:106
void analyse_phi_base(TString fname="ntp1_2phi_A.root", TString cut="abs(f4cxd0m+f4cxd1m-2.15)<0.15&&abs(f4cxd0m-1.02)<0.012&&abs(f4cxd1m-1.02)<0.012&chi24c<50", int sigmode=0, TString tit="")
Int_t i
Definition: run_full.C:25
TF1 * f1
Definition: reco_analys2.C:50
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
Double_t xmax
int col
Definition: anaLmdDigi.C:67
TFile * g
double cut[MAX]
Definition: autocutx.C:36
TFile * f
Definition: bump_analys.C:12
c1
Definition: plot_dirc.C:35
void confgraph(TGraph *g, TString tit, int col=1, int marker=20)
Int_t cnt
Definition: hist-t7.C:106
double Z
Definition: anaLmdDigi.C:68
TTree * t
Definition: bump_analys.C:13
Double_t xmin
long int cntEvt(TTree *t1, TString cut, TString var="ev")
TH1F * createHistoGraph(TGraph *g, TString tit="", double xmin=0, double xmax=0)