00001 int use_background=1;
00002 int x_end=4;
00003
00004 #define runB
00005
00006 #ifdef runA
00007 #define jan 1
00008
00009 float x[]={.00, .10, .20, .35, .50, .75, 1.0,
00010 .00,-.10,-.20,-.35,-.50,-.75,-1.0,.00,
00011 0,0,0,0,0,0,0,
00012 0,0,0,0,0,0,0,0};
00013 float y[]={0,0,0,0,0,0,0,
00014 0,0,0,0,0,0,0,0,
00015 .00, .10, .20, .35, .50, .75, 1.0,
00016 .00,-.10,-.20,-.35,-.50,-.75,-1.0,.00};
00017 int timediff[]={00,35,35,37,36,37,37,41,35,35,37,35,37,37,42,
00018 31,35,36,36,35,37,38,41,35,35,35,36,37,37,42};
00019 float Nblue=11349.49/107;
00020 float Nyellow=10274.33/107;
00021 int Nbunches=98;
00022 int max_time=1220;
00023 float kbb=1036758;
00024
00025 #endif
00026
00027 #ifdef runB
00028 #define jan 2
00029
00030 float x[]={.00, .15, .30, .45, .60, .75, .90,
00031 .00,-.15,-.30,-.45,-.60,-.75,-.90,.00,
00032 0,0,0,0,0,0,0,
00033 0,0,0,0,0,0,0,0};
00034 float y[]={0,0,0,0,0,0,0,
00035 0,0,0,0,0,0,0,0,
00036 .00, .15, .30, .45, .60, .75, .90,
00037 .00,-.15,-.30,-.45,-.60,-.75,-.90,.00};
00038 int timediff[]={00,36,37,36,36,36,36,41,36,36,36,36,36,36,41,
00039 31,36,35,36,36,36,36,41,37,36,36,36,36,36,41};
00040 float Nblue=10505.05/106;
00041 float Nyellow=10039.98/106;
00042 int Nbunches=96;
00043 int max_time=1400;
00044 float kbb=938419;
00045
00046 #endif // end of setup switch between runs
00047
00048 int integration_width=30;
00049 float *x_longname ,*y_longname ;
00050 bool extra_use;
00051
00052 float frequency=9.383/120.0;
00053
00054 Double_t gaus_stepping(Double_t *v, Double_t *par)
00055 {
00056 Double_t skfNN=par[0]/1e7*frequency*kbb;
00057
00058
00059
00060
00061
00062
00063 Double_t sx2=par[1];
00064 Double_t sy2=par[2];
00065 Double_t background=par[3];
00066
00067
00068 Int_t step=v[0];
00069 if (step>29)
00070 {
00071 printf("Requested step out of bounds, for drawing. This shouldn't be possible.\n");
00072 return -999;
00073 }
00074 Double_t dx=x [step];
00075 Double_t dy=y [step];
00076
00077 if (dx*dx>1.1 || dy*dy>1.1)
00078 {
00079 printf("v[0]=%f,step=%d ==> dx=%f, dy=%f\n",v[0],step,dx,dy);
00080 printf("Array out of bounds. Checking arrays:\n");
00081 for(int i=0;i<30;i++)
00082 printf("step=%d x=%1.2f y=%1.2f\n",i,x [i],y [i]);
00083 assert(1==2);
00084 }
00085
00086 if (dx*dx>(x[x_end]*x[x_end]*.95) || dy*dy>(x[x_end]*x[x_end]*.95))
00087 return use_background*background*integration_width;
00088
00089 if ((sx2*sy2)<0.00000001)
00090 {
00091 printf("gaus_Step with: 0=%f,1=%f,2=%f\n",skfNN,sx2,sy2);
00092 return 999;
00093 }
00094
00095
00096 Double_t sL= skfNN/(2*TMath::Pi()*sqrt(sx2*sy2));
00097
00098 Double_t val=sL*exp(-dx*dx/(2*sx2))*exp(-dy*dy/(2*sy2));
00099
00100
00101
00102
00103
00104
00105 return (val+background)*integration_width;
00106 }
00107
00108
00109
00110 void janNicePlot(TH1F * hin){
00111 printf("AAA\n");
00112 char txt[1000];
00113
00114 int runID=999999;
00115 float yMax=999;
00116 if(jan==1) {
00117 runID=10097097;
00118 yMax=1290;
00119 }
00120 if(jan==2) {
00121 runID=10103044;
00122 yMax=850;
00123 }
00124
00125 sprintf(txt,"BHT3 yield for R%d; vernier scan i-th step",runID);
00126 hin->SetTitle(txt);
00127 hin->SetMaximum(yMax);
00128 hin->SetMarkerStyle(8);
00129 hin->SetMarkerColor(kBlue);
00130
00131 sprintf(txt,"vernierR%dbht3_1gaus",runID);
00132 c2=new TCanvas(txt,txt,450,600);
00133 c2->cd();
00134
00135 TPad *cU,*cD; splitPadY(0.4,&cU,&cD);
00136 cU->cd();
00137 hin->SetStats(0);
00138 hin->Draw("e");
00139 gStyle->SetOptStat(0);
00140 gStyle->SetOptFit(11111);
00141
00142 TF1 *ff=hin->GetFunction("steppy"); assert(ff);
00143 float nb=hin->GetNbinsX();
00144
00145 TH1F *hdif=(TH1F*) hin->Clone();
00146 hdif->Reset();
00147 sprintf(txt,"yield residua; step index; data-fit");
00148 hdif->SetTitle(txt);
00149
00150 float par0=ff->GetParameter(0);
00151 float erPar0=ff->GetParError(0);
00152 float relEr=erPar0/par0;
00153 printf("par0=%f +/- %f , relEr=%f\n",par0,erPar0,relEr);
00154
00155 for(int k=1;k<=nb;k++) {
00156 float x=hin->GetBinCenter(k);
00157 float y=hin->GetBinContent(k);
00158 float ey=hin->GetBinError(k);
00159 float fy=ff->Eval(x);
00160 float eFit=relEr*fy;
00161 float totEr=sqrt(ey*ey+eFit*eFit);
00162
00163 hdif->SetBinContent(k,y-fy);
00164 hdif->SetBinError(k,totEr);
00165 }
00166 cD->cd();
00167 hdif->Draw("e");
00168 hdif->SetMaximum(yMax/10.);
00169 hdif->SetMinimum(-yMax/10.);
00170 ln=new TLine(0,0,30,0); ln->SetLineStyle(2);ln->Draw();ln->SetLineColor(kBlack);
00171
00172 }
00173
00174
00175 void splitPadY(float y, TPad **cU, TPad **cD) {
00176 (*cU) = new TPad("padD", "apdD",0,y+0.005,1.0,1.);
00177 (*cU)->Draw();
00178 (*cD) = new TPad("padU", "apdU",0.0,0.,1.,y);
00179 (*cD)->Draw();
00180
00181
00182
00183
00184
00185 }
00186
00187
00188
00189 void makeVernierScanFitFromHist(char * infile="temp.hist.root")
00190 {
00191 if(jan==1) infile="10097097.bht3.hist.root";
00192 if(jan==2) infile="10103044.bht3.hist.root";
00193
00194 TFile *f=new TFile(infile);
00195 TH1F* times=(TH1F*)(f->Get("time"));
00196
00197 float *xpos=x;
00198 float *ypos=y;
00199 int counts[30];
00200 int timestamp[30];
00201
00202 timestamp[0]=timediff[0];
00203 for (int i=1;i<30;i++)
00204 timestamp[i]=timediff[i]+timestamp[i-1];
00205
00206
00207
00208 TH1F *stamps=new TH1F("timestamps","timestamps",max_time,0,max_time);
00209
00210
00211
00212
00213
00214
00215 int best_value=0;
00216 int best_offset=-1;
00217
00218 int temp_value=0;
00219 TH1F *hOffset=new TH1F("offset","summed differential across big steps as a function of proposed offset;offset;dHz/dt",600,0,600);
00220 for (int i=4;i+timestamp[28]<max_time;i++)
00221 {
00222 temp_value=0;
00223 temp_value-=times->GetBinContent(i+timestamp[6]-2);
00224 temp_value-=times->GetBinContent(i+timestamp[6]-1);
00225 temp_value+=times->GetBinContent(i+timestamp[6]+1);
00226 temp_value+=times->GetBinContent(i+timestamp[6]+2);
00227
00228 temp_value-=times->GetBinContent(i+timestamp[13]-2);
00229 temp_value-=times->GetBinContent(i+timestamp[13]-1);
00230 temp_value+=times->GetBinContent(i+timestamp[13]+1);
00231 temp_value+=times->GetBinContent(i+timestamp[13]+2);
00232
00233 temp_value-=times->GetBinContent(i+timestamp[21]-2);
00234 temp_value-=times->GetBinContent(i+timestamp[21]-1);
00235 temp_value+=times->GetBinContent(i+timestamp[21]+1);
00236 temp_value+=times->GetBinContent(i+timestamp[21]+2);
00237
00238 temp_value-=times->GetBinContent(i+timestamp[28]-2);
00239 temp_value-=times->GetBinContent(i+timestamp[28]-1);
00240 temp_value+=times->GetBinContent(i+timestamp[28]+1);
00241 temp_value+=times->GetBinContent(i+timestamp[28]+2);
00242 hOffset->Fill(i,temp_value);
00243 if (temp_value>best_value)
00244 {
00245 best_value=temp_value;
00246 best_offset=i;
00247 }
00248 }
00249 hOffset->Draw();
00250 printf("Best offset is %d\n",best_offset);
00251
00252
00253
00254
00255 int end_offset=5;
00256 int start_offset=25;
00257
00258
00259 end_offset=16-integration_width/2;
00260 start_offset=end_offset+integration_width;
00261
00262 for (int i=0;i<30;i++)
00263 {
00264 counts[i]=0;
00265
00266
00267
00268
00269 for (int j=best_offset+timestamp[i]-start_offset;
00270 j<(best_offset+timestamp[i]-end_offset);j++)
00271 counts[i]+=times->GetBinContent(j);
00272 }
00273
00274 TH1F *idealized=new TH1F("idealized","counts vs step;step;counts",30,0,30);
00275
00276
00277
00278 for (int i=0;i<30;i++)
00279
00280
00281 idealized->Fill(i,counts[i]);
00282 idealized->GetYaxis()->SetRangeUser(0,1600);
00283
00284
00285
00286
00287
00288
00289
00290 float err_counts[30];
00291 for (int i=0;i<30;i++)
00292 err_counts[i]=sqrt(counts[i]);
00293
00294 float err_pos[30];
00295 for (int i=0;i<30;i++)
00296 err_pos[i]=0.01;
00297
00298 x_longname=xpos;
00299 y_longname=ypos;
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 TF1 *func=new TF1("steppy",gaus_stepping,0.1,29.9,4);
00314 func->SetParameters(2,0.25,0.25,.05);
00315
00316 func->SetParNames("sigma (nb)","#sigma_{X}^{2} (mm^{2})","#sigma_{Y}^{2^} (mm^{2})","background (Hz)");
00317
00318 func->SetParLimits(1,0.01,10);
00319 func->SetParLimits(2,0.01,10);
00320
00321
00322
00323 idealized->Fit("steppy");
00324
00325
00326
00327
00328
00329
00330 idealized->Draw("e");
00331
00332
00333 janNicePlot(idealized);
00334
00335 return;
00336
00337 Double_t a[1];
00338 Double_t b[]={4.997,.1733,-0.068,.1323,.1323};
00339 TF1 *copyfunc=new TF1("copy",gaus_stepping,0.1,29.9,4);
00340 copyfunc->SetParameters(b);
00341 copyfunc->Draw("SAME");
00342
00343 for (int w=0;w<30;w+=1)
00344 {
00345 a[0]=w;
00346 printf("bin=%f counts=%f, func=%f\n",w,gaus_stepping(a,b),func->Eval(w*1.0));
00347 }
00348
00349 return;
00350 }