17{
18
19 gROOT->Reset();
20
21
22 TFile *f1 = new TFile("YYYY/m_root_dir/LumTau_XXXX.root");
23 TTree *data =event;
24
26 {
27
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
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;
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) {
78 luminitial = 2000;
79 tau = 99999999;
80 }
81 else
82 {
83
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;
92 {
93 dltphi1->Fill(dltphi);
94 }
95 }
96
97
98 TF1* h1=new TF1("h1","gaus",-6,4);
99 dltphi1->Fit(h1,"R+");
100 dlt = h1->GetParameter(1);
101
102
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);
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
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
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
145 Int_t nevt[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
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
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
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
215 {
216
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
229 {
230
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}
EvtComplex exp(const EvtComplex &c)
Double_t BeamEnergyOnline(Int_t)