BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
tau_mode.c
Go to the documentation of this file.
1#include <stdlib.h>
2#ifndef __CINT__
3#include <TSQLServer.h>
4#include <TSQLResult.h>
5#include <TSQLRow.h>
6#endif
7
8//
9// get the online beam energy from the database for a specific run
10// within ROOT
12//
13
14Double_t BeamEnergyOnline(Int_t);
15
16void tau_mode(int flag=0)
17{
18 //Reset root
19 gROOT->Reset();
20
21 //Get the root file and E_cms
22 TFile *f1 = new TFile("YYYY/m_root_dir/LumTau_XXXX.root");
23 TTree *data =event;
24
25 if (flag!=0)
26 {
27 //Define the canvas
28 TCanvas *myCanvas = new TCanvas();
29 myCanvas->Divide(1,1);
30 TPad *c1_1 = new TPad("c1_1", "c1_1",0.01,0.01,0.99,0.99);
31 c1_1->Draw();
32 c1_1->cd();
33 c1_1->Range(0.425458,-114.842,0.674993,802.951);
34 c1_1->SetBorderSize(2);
35 c1_1->SetBottomMargin(0.125129);
36 c1_1->SetFrameFillColor(0);
37 }
38
39 //Initialize the variables and set the branches' address
40 Bool_t topup = false;
41 Int_t run = 0;
42 Double_t time = 0.0,dltphi = 0.0,costht1 = 0.0,costht2 = 0.0,e1 = 0.0,e2 = 0.0,etot = 0.0,phi1 = 0.0,phi2 = 0.0;
43 Int_t nentries = 0;
44
45 data->SetBranchAddress("topup", &topup);
46 data->SetBranchAddress("run",&run);
47 data->SetBranchAddress("time",&time);
48 data->SetBranchAddress("dltphi",&dltphi);
49 data->SetBranchAddress("costht1",&costht1);
50 data->SetBranchAddress("costht2",&costht2);
51 data->SetBranchAddress("e1",&e1);
52 data->SetBranchAddress("e2",&e2);
53 data->SetBranchAddress("etot",&etot);
54 data->SetBranchAddress("phi1",&phi1);
55 data->SetBranchAddress("phi2",&phi2);
56
57 data->GetEntry(0);
58 Int_t runno = run;
59 Double_t E_cms = 2*BeamEnergyOnline(run);
60 cout << "E_cms = " << E_cms << endl;
61
62 nentries = (Int_t)data->GetEntries();
63
64 Double_t timemin = 0.0,timemax = 0.0;
65 data->GetEntry(0);
66 timemin = time;
67 data->GetEntry((nentries - 1));
68 timemax = time;
69 Double_t difft = timemax-timemin;
70
71 Double_t dlt = 0.0,mean = 0.0,width = 0.0;
72 Double_t luminitial = 0.;
73 Double_t tau = 5000.;
74
75 if (difft<300.)
76 cout << "\nRuntime less than 300 " << endl;
77 else if (topup) { // topup mode
78 luminitial = 2000;
79 tau = 99999999;
80 }
81 else
82 {
83 //Fill the histogram of dltphi distribution
84 TH1F *dltphi1 = new TH1F("dltphi1","dltphi",150,-30,30);
85 for (Int_t i = 0;i<nentries;i++)
86 {
87 data->GetEntry(i);
88 bool cut = (e1/E_cms)>0.417&&(e1/E_cms)<0.491&&(e2/E_cms)>0.417&&(e2/E_cms)<0.491
89 &&fabs(costht1)<0.8&&fabs(costht2)<0.8
90 &&etot<E_cms+0.5;
91 if (cut)
92 {
93 dltphi1->Fill(dltphi);
94 }
95 }
96
97 //Fit the Di-photon peak and get the value of dlt
98 TF1* h1=new TF1("h1","gaus",-6,4);
99 dltphi1->Fit(h1,"R+");
100 dlt = h1->GetParameter(1);
101
102 //Fit the Bhabha peak and get the values of mean and width
103 TF1* h2=new TF1("h2","gaus",4,30);
104 dltphi1->Fit(h2,"R+");
105 mean = h2->GetParameter(1);
106 Double_t sigma = h2->GetParameter(2);
107 width = 3*sigma;
108
109 if (dlt<-6||dlt>4||mean<4||mean>30||(mean-dlt)-0.5*width<0)
110 cout << "\nSomething wrong with cut Bhabha entries. " << endl;
111 else
112 {
113 //Get 11 time nodes
114 Double_t xtime[11],lum[10];
115 for(Int_t i=0;i<11;i++)
116 {
117 xtime[i]=timemin+(difft/10.)*i;
118 }
119
120
121 //Get 10 histograms of dltphi distribution between time nodes
122 TH1D *hdltphi[10];
123 for(Int_t i=0;i<10;i++)
124 {
125 hdltphi[i] = new TH1D("","dltphi distribution",50,-50.,50.);
126 }
127 TH1 *htime = new TH1D("htime","time", 80, -10., 10.);
128
129 for(Int_t i=0;i<10;i++)
130 {
131 for(Int_t j=0;j<nentries;j++)
132 {
133 data->GetEntry(j);
134 bool lumcut = (e1/E_cms)>0.417&&(e2/E_cms)>0.417&&fabs(costht1)<0.8&&
135 fabs(costht2)<0.8&&fabs(dltphi-dlt)>(mean-dlt)-width&&
136 fabs(dltphi-dlt)<(mean-dlt)+width&&etot<E_cms+0.5;
137 if(lumcut&&time>xtime[i]&&time<xtime[i+1])
138 {
139 hdltphi[i]->Fill(dltphi);
140 }
141 }
142 }
143
144 //Get the average luminosity between time nodes
145 Int_t nevt[10];
146 Double_t x[10];
147 for(Int_t i=0;i<10;i++)
148 {
149 nevt[i] = hdltphi[i]->GetEntries();
150 x[i]=xtime[i+1]-xtime[0];
151 lum[i]=nevt[i];
152 }
153
154 //Set draw options and fit the luminosity curve
155 TCanvas *c2 = new TCanvas("c2"," ",700,500);
156 c2->SetFillColor(kWhite);
157 c2->SetGrid();
158
159 Int_t imin;
160 for(Int_t i=0;lum[i]<lum[i+1];i++)
161 {
162 imin = i+1;
163 }
164 Double_t lummax = lum[imin];
165 Double_t xmin = x[imin];
166 Double_t lumsum;
167 for(Int_t i=imin;i<10;i++)
168 {
169 lumsum += lum[i];
170 }
171 Double_t lumsum2 = lumsum*lumsum;
172
173 const Int_t n = 10;
174 TF1 *g1 = new TF1("g1","[0]*exp(-x/[1])",xmin,10000.);
175 g1->SetParameters(lummax,1e+4.);
176 g1->SetLineColor(2);
177 TGraph* gr = new TGraph(n,x,lum);
178 gr->SetLineColor(2);
179 gr->SetLineWidth(2);
180 gr->SetMarkerColor(4);
181 gr->SetMarkerStyle(21);
182 gr->SetTitle("BbLum");
183 gr->GetXaxis()->SetTitle("Time");
184 gr->GetYaxis()->SetTitle("Luminosity");
185 gr->Fit("g1","R");
186 gr->Draw("ap");
187
188 //pick the fit result
189 luminitial = g1->GetParameter(0);
190 tau = g1->GetParameter(1);
191 }
192 }
193
194
195 if (!topup && tau>99999.)
196 {
197 cout << "\nThe result of fit is terrible. " << endl << endl;
198 cout << "set the tau value = 99999" << endl;
199 tau = 99999;
200 }
201
202 if (difft<0.)
203 {
204 cout << "\nThe runtime is minus." << endl << endl;
205 difft = fabs(difft);
206 }
207
208 //Export the fit result
209 std::ofstream m_outputFile;
210 m_outputFile.open("YYYY/m_txt_dir/LumTau_XXXX.txt", ios_base::app);
211 m_outputFile<< runno <<" "<<difft<<" "<<luminitial<<" "<<(luminitial * exp(- 1.0 * difft / (tau)))<<" "<< tau <<endl;
212 m_outputFile.close();
213
214 if (flag!=0)
215 {
216 //Get the value of tau and print it
217 TString result = Form("tau = %6.2f",tau);
218 TText* text01 = new TText(0.7,0.8,result);
219 text01->SetNDC();
220 text01->Draw("same");
221 c2->Update();
222 c2->GetFrame()->SetFillColor(kWhite);
223 c2->GetFrame()->SetBorderSize(1);
224 c2->Modified();
225 c2->Print("lum_0000XXXX.ps");
226 }
227
228 if (flag!=0)
229 {
230 //Print some parameters
231 cout << "E_cms = " << E_cms << endl;
232 cout << "\nruntime = " << difft << endl;
233 cout << "\ndlt = " << dlt << endl;
234 cout << "mean = " << mean << endl;
235 cout << "width = " << width << endl;
236 cout << "\ntau = " << tau << endl << endl;
237 }
238}
239
240
241
242Double_t BeamEnergyOnline(Int_t runno)
243{
244 Double_t dbe = 0; // initialization
245
246 // connect to the BESIII database
247 TSQLServer *db = TSQLServer::Connect("mysql://bes3db2.ihep.ac.cn", "guest", "guestpass");
248 // printf("Server info: %s\n", db->ServerInfo());
249
250 //Int_t runno = 33743;
251 //read beam energy from the online database 'run'
252 const char *ins = "select BER_PRB from run.RunParams where run_number = %d";
253 char sql[4096];
254 sprintf(sql, ins, runno);
255 TSQLResult *res = db->Query(sql);
256 if (res->GetRowCount() == 0) { // not found
257 printf("Cannot find the beam energy of run %d from the database.\n", runno);
258 delete res;
259 delete db;
260 return dbe;
261 }
262 TSQLRow *row = res->Next();
263 TString sbe = row->GetField(0); // beam energy of electron
264 dbe = atof(sbe); // convert string to float
265 // printf("beam energy is : %5.3f\n", dbe);
266 delete row;
267 delete res;
268 delete db;
269
270 return dbe;
271}
272
273
TTree * sigma
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
double x[1000]
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
Char_t cut[200]
Definition: eff.cxx:63
Double_t BeamEnergyOnline(Int_t)
Definition: tau_mode.c:242
void tau_mode(int flag=0)
Definition: tau_mode.c:16