BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
tau_mode.c File Reference
#include <stdlib.h>
#include <TSQLServer.h>
#include <TSQLResult.h>
#include <TSQLRow.h>

Go to the source code of this file.

Functions

Double_t BeamEnergyOnline (Int_t)
 
void tau_mode (int flag=0)
 

Function Documentation

◆ BeamEnergyOnline()

Double_t BeamEnergyOnline ( Int_t  runno)

Definition at line 236 of file tau_mode.c.

237{
238 Double_t dbe = 0; // initialization
239
240 // connect to the BESIII database
241 TSQLServer *db = TSQLServer::Connect("mysql://bes3db2.ihep.ac.cn", "guest", "guestpass");
242 // printf("Server info: %s\n", db->ServerInfo());
243
244 //Int_t runno = 33743;
245 //read beam energy from the online database 'run'
246 const char *ins = "select BER_PRB from run.RunParams where run_number = %d";
247 char sql[4096];
248 sprintf(sql, ins, runno);
249 TSQLResult *res = db->Query(sql);
250 if (res->GetRowCount() == 0) { // not found
251 printf("Cannot find the beam energy of run %d from the database.\n", runno);
252 delete res;
253 delete db;
254 return dbe;
255 }
256 TSQLRow *row = res->Next();
257 TString sbe = row->GetField(0); // beam energy of electron
258 dbe = atof(sbe); // convert string to float
259 // printf("beam energy is : %5.3f\n", dbe);
260 delete row;
261 delete res;
262 delete db;
263
264 return dbe;
265}

Referenced by tau_mode().

◆ tau_mode()

void tau_mode ( int  flag = 0)

Definition at line 16 of file tau_mode.c.

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 Int_t run = 0;
41 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;
42 Int_t nentries = 0;
43
44 data->SetBranchAddress("run",&run);
45 data->SetBranchAddress("time",&time);
46 data->SetBranchAddress("dltphi",&dltphi);
47 data->SetBranchAddress("costht1",&costht1);
48 data->SetBranchAddress("costht2",&costht2);
49 data->SetBranchAddress("e1",&e1);
50 data->SetBranchAddress("e2",&e2);
51 data->SetBranchAddress("etot",&etot);
52 data->SetBranchAddress("phi1",&phi1);
53 data->SetBranchAddress("phi2",&phi2);
54
55 data->GetEntry(0);
56 Int_t runno = run;
57 Double_t E_cms = 2*BeamEnergyOnline(run);
58 cout << "E_cms = " << E_cms << endl;
59
60 nentries = (Int_t)data->GetEntries();
61
62 Double_t timemin = 0.0,timemax = 0.0;
63 data->GetEntry(0);
64 timemin = time;
65 data->GetEntry((nentries - 1));
66 timemax = time;
67 Double_t difft = timemax-timemin;
68
69 Double_t dlt = 0.0,mean = 0.0,width = 0.0;
70 Double_t luminitial = 0.;
71 Double_t tau = 5000.;
72
73 if (difft<300.)
74 cout << "\nRuntime less than 300 " << endl;
75 else
76 {
77 //Fill the histogram of dltphi distribution
78 TH1F *dltphi1 = new TH1F("dltphi1","dltphi",150,-30,30);
79 for (Int_t i = 0;i<nentries;i++)
80 {
81 data->GetEntry(i);
82 bool cut = (e1/E_cms)>0.417&&(e1/E_cms)<0.491&&(e2/E_cms)>0.417&&(e2/E_cms)<0.491
83 &&fabs(costht1)<0.8&&fabs(costht2)<0.8
84 &&etot<E_cms+0.5;
85 if (cut)
86 {
87 dltphi1->Fill(dltphi);
88 }
89 }
90
91 //Fit the Di-photon peak and get the value of dlt
92 TF1* h1=new TF1("h1","gaus",-6,4);
93 dltphi1->Fit(h1,"R+");
94 dlt = h1->GetParameter(1);
95
96 //Fit the Bhabha peak and get the values of mean and width
97 TF1* h2=new TF1("h2","gaus",4,30);
98 dltphi1->Fit(h2,"R+");
99 mean = h2->GetParameter(1);
100 Double_t sigma = h2->GetParameter(2);
101 width = 3*sigma;
102
103 if (dlt<-6||dlt>4||mean<4||mean>30||(mean-dlt)-0.5*width<0)
104 cout << "\nSomething wrong with cut Bhabha entries. " << endl;
105 else
106 {
107 //Get 11 time nodes
108 Double_t xtime[11],lum[10];
109 for(Int_t i=0;i<11;i++)
110 {
111 xtime[i]=timemin+(difft/10.)*i;
112 }
113
114
115 //Get 10 histograms of dltphi distribution between time nodes
116 TH1D *hdltphi[10];
117 for(Int_t i=0;i<10;i++)
118 {
119 hdltphi[i] = new TH1D("","dltphi distribution",50,-50.,50.);
120 }
121 TH1 *htime = new TH1D("htime","time", 80, -10., 10.);
122
123 for(Int_t i=0;i<10;i++)
124 {
125 for(Int_t j=0;j<nentries;j++)
126 {
127 data->GetEntry(j);
128 bool lumcut = (e1/E_cms)>0.417&&(e2/E_cms)>0.417&&fabs(costht1)<0.8&&
129 fabs(costht2)<0.8&&fabs(dltphi-dlt)>(mean-dlt)-width&&
130 fabs(dltphi-dlt)<(mean-dlt)+width&&etot<E_cms+0.5;
131 if(lumcut&&time>xtime[i]&&time<xtime[i+1])
132 {
133 hdltphi[i]->Fill(dltphi);
134 }
135 }
136 }
137
138 //Get the average luminosity between time nodes
139 Int_t nevt[10];
140 Double_t x[10];
141 for(Int_t i=0;i<10;i++)
142 {
143 nevt[i] = hdltphi[i]->GetEntries();
144 x[i]=xtime[i+1]-xtime[0];
145 lum[i]=nevt[i];
146 }
147
148 //Set draw options and fit the luminosity curve
149 TCanvas *c2 = new TCanvas("c2"," ",700,500);
150 c2->SetFillColor(kWhite);
151 c2->SetGrid();
152
153 Int_t imin;
154 for(Int_t i=0;lum[i]<lum[i+1];i++)
155 {
156 imin = i+1;
157 }
158 Double_t lummax = lum[imin];
159 Double_t xmin = x[imin];
160 Double_t lumsum;
161 for(Int_t i=imin;i<10;i++)
162 {
163 lumsum += lum[i];
164 }
165 Double_t lumsum2 = lumsum*lumsum;
166
167 const Int_t n = 10;
168 TF1 *g1 = new TF1("g1","[0]*exp(-x/[1])",xmin,10000.);
169 g1->SetParameters(lummax,1e+4.);
170 g1->SetLineColor(2);
171 TGraph* gr = new TGraph(n,x,lum);
172 gr->SetLineColor(2);
173 gr->SetLineWidth(2);
174 gr->SetMarkerColor(4);
175 gr->SetMarkerStyle(21);
176 gr->SetTitle("BbLum");
177 gr->GetXaxis()->SetTitle("Time");
178 gr->GetYaxis()->SetTitle("Luminosity");
179 gr->Fit("g1","R");
180 gr->Draw("ap");
181
182 //pick the fit result
183 luminitial = g1->GetParameter(0);
184 tau = g1->GetParameter(1);
185 }
186 }
187
188
189 if (tau>99999.)
190 {
191 cout << "\nThe result of fit is terrible. " << endl << endl;
192 cout << "set the tau value = 99999" << endl;
193 tau = 99999;
194 }
195
196 if (difft<0.)
197 {
198 cout << "\nThe runtime is minus." << endl << endl;
199 difft = fabs(difft);
200 }
201
202 //Export the fit result
203 std::ofstream m_outputFile;
204 m_outputFile.open("YYYY/m_txt_dir/LumTau_XXXX.txt", ios_base::app);
205 m_outputFile<< runno <<" "<<difft<<" "<<luminitial<<" "<<(luminitial * exp(- 1.0 * difft / (tau)))<<" "<< tau <<endl;
206 m_outputFile.close();
207
208 if (flag!=0)
209 {
210 //Get the value of tau and print it
211 TString result = Form("tau = %6.2f",tau);
212 TText* text01 = new TText(0.7,0.8,result);
213 text01->SetNDC();
214 text01->Draw("same");
215 c2->Update();
216 c2->GetFrame()->SetFillColor(kWhite);
217 c2->GetFrame()->SetBorderSize(1);
218 c2->Modified();
219 c2->Print("lum_0000XXXX.ps");
220 }
221
222 if (flag!=0)
223 {
224 //Print some parameters
225 cout << "E_cms = " << E_cms << endl;
226 cout << "\nruntime = " << difft << endl;
227 cout << "\ndlt = " << dlt << endl;
228 cout << "mean = " << mean << endl;
229 cout << "width = " << width << endl;
230 cout << "\ntau = " << tau << endl << endl;
231 }
232}
Double_t timemax
const Int_t n
std::ofstream m_outputFile
Double_t phi2
TTree * data
Double_t lum[10]
TFile * f1
Double_t costht2
Double_t etot
TH1D * hdltphi[10]
TF1 * g1
Double_t x[10]
Double_t dltphi
Double_t phi1
Double_t timemin
TH1 * htime
Double_t costht1
Int_t nevt[10]
TGraph * gr
Double_t time
Double_t e1
Double_t xtime[11]
Int_t nentries
Double_t difft
Double_t e2
EvtComplex exp(const EvtComplex &c)
Definition: EvtComplex.hh:252
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
Definition: KarFin.h:27
Double_t BeamEnergyOnline(Int_t)
Definition: tau_mode.c:236