10 Double_t langaufun(Double_t *x, Double_t *par) {
13 Double_t invsq2pi = 0.3989422804014;
14 Double_t mpshift = -0.22278298;
30 mpc = par[1] - mpshift * par[0];
33 xlow = x[0] - sc * par[3];
34 xupp = x[0] + sc * par[3];
36 step = (xupp-xlow) / np;
39 for(i=1.0; i<=np/2; i++) {
40 xx = xlow + (i-.5) * step;
41 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
42 sum += fland * TMath::Gaus(x[0],xx,par[3]);
44 xx = xupp - (i-.5) * step;
45 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
46 sum += fland * TMath::Gaus(x[0],xx,par[3]);
48 return ((par[2]*step*sum*invsq2pi/par[3]));
51 TF1 *langaufit(TH1F *his, Double_t *fitrange, Double_t *startvalues, Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams, Double_t *fiterrors)
71 sprintf(FunName,
"Fitfcn_%s",his->GetName());
73 cout<<
" NAME = "<<FunName<<endl;
74 TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
75 if (ffitold)
delete ffitold;
77 TF1 *ffit =
new TF1(FunName,langaufun,fitrange[0],fitrange[1],4);
78 ffit->SetParameters(startvalues);
79 ffit->SetParNames(
"Width",
"MP",
"Area",
"GSigma");
82 ffit->SetParLimits(i, parlimitslo[i], parlimitshi[i]);
85 his->Fit(FunName,
"RB0");
87 ffit->GetParameters(fitparams);
89 fiterrors[i] = ffit->GetParError(i);
95 Double_t background(Double_t *x, Double_t *par){
96 return (par[0]*TMath::Power(x[0],par[1]));
100 Double_t total_wconvo(Double_t *x, Double_t *par){
101 return (background(x,par) + langaufun(x,&par[2]));
104 void MIPfit_loop(
int rebinFactor= 10,
int minTow = 0,
int maxTow = 63,
int MIPrange=325, TString filename=
"minbias_checkmaker.root"){
106 TFile *file=
new TFile(filename);
107 TString outputFile=
"mip_fits.pdf";
108 TString openOutput=outputFile+
"(";
109 TString closeOutput=outputFile+
")";
111 cout<<
" YOU'RE READING IN..."<<filename<<endl;
112 cout<<
" YOU'RE READING OUT..."<<outputFile<<endl;
114 TH1F *h[64],*h_Clone[64];
115 TH1F *MIPbgsub1[64], *MIPbg[64];
116 TF1 *bg[64], *mip[64], *mipconvo, *mipconvo2;
117 TString title,mip_title,bg_title;
118 char mipbg_t[100],mipbg_n[100],mipbgsub_t[100],mipbgsub_n[100];
120 Int_t fitxmin=60, fitxmax=150;
123 TH1F *chisq_edge=
new TH1F(
"chiqr2",
"MIP Chisquare/DOF",100,0,10);
124 TH1F *chisq=
new TH1F(
"chiqr",
"MIP Chisquare/DOF",100,0,10);
126 float chisq_values[64];
127 float mostprob_values[64];
130 int towids[64]={7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24,39,38,37,36,35,34,33,32,47,46,45,44,43,42,41,40,55,54,53,52,51,50,49,48,63,62,61,60,59,58,57,56};
132 int edgetowids[15]={7,15,23,31,39,47,55,63,62,61,60,59,58,57,56};
133 float edgetowids_length=
sizeof(edgetowids)/
sizeof(edgetowids[0]);
135 for(
int id=minTow;
id<maxTow+1;
id++){
140 for(
int i=0; i<edgetowids_length; i++){
141 if(edgetowids[i]==
id){
147 bg_title=
"background_id";
149 bg[id]=
new TF1(bg_title,
"[0]*x^[1]",fitxmin,fitxmax);
153 title=
"adcsum_det1_id";
155 cout<<
"*****************************************"<<endl;
156 cout<<
"*****************************************"<<endl;
157 cout<<
"*********GETTING HISTOGRAM...#"<<
id<<endl;
158 h[id]=(TH1F*)file->Get(title);
159 h[id]->Rebin(rebinFactor);
161 x->SetTitle(
"ADC Sum");
162 x->SetRangeUser(20,900);
165 h_Clone[id]=(TH1F*)h[
id]->Clone();
168 sprintf(mipbg_t,
"mipbackground id%d",
id);
169 sprintf(mipbg_n,
"mipbackground_id%d",
id);
171 int nbinX_hold=h[id]->GetNbinsX();
172 const int nbinX=nbinX_hold;
173 float binwidth=h[id]->GetBinWidth(nbinX);
174 float hist_nbins=nbinX*rebinFactor;
175 float hist_range=binwidth*nbinX;
177 MIPbg[id]=
new TH1F(mipbg_n,mipbg_t,hist_nbins,0,hist_range);
178 MIPbg[id]->Rebin(rebinFactor);
181 sprintf(mipbgsub_t,
"mipbackground1_sub_id%d",
id);
182 sprintf(mipbgsub_n,
"mipbackground1_sub_id%d",
id);
183 MIPbgsub1[id]=
new TH1F(mipbgsub_n,mipbgsub_t,hist_nbins,0,hist_range);
184 MIPbgsub1[id]->Rebin(rebinFactor);
185 MIPbgsub1[id]->Sumw2();
188 h_Clone[id]->Fit(bg[
id],
"",
"",fitxmin,fitxmax);
192 bg[id]->GetParameters(&bgparam[0]);
193 float bgwidth=bgparam[0];
194 float bgmp=bgparam[1];
195 cout<<
"BG PARAMS: "<<bgwidth<<
" "<<bgmp<<endl;
198 for(
int j=0; j<=14;j++){
202 h_Clone[id]->Fit(bg[
id],
"",
"",fitxmin,fitxmax);
204 cout<<
"TRYING FITMAX= "<<fitxmax<<endl;
205 bg[id]->GetParameters(&bgparam[0]);
211 for(
int bin=4; bin<nbinX; bin++){
212 float XbinCenter=x->GetBinCenter(bin);
213 float bg_at_center=bg[id]->Eval(XbinCenter);
214 MIPbg[id]->SetBinContent(bin,bg_at_center);
216 MIPbgsub1[id]->Add(h[
id],MIPbg[
id],1,-1);
221 Double_t sv[4], pllo[4], plhi[4], fp[4], fpe[4];
224 float ncounts[nbinX];
225 for(
int bin=4; bin<nbinX; bin++){
226 ncounts[bin]=MIPbgsub1[id]->GetBinContent(bin);
228 float mostprob=ncounts[nbinX-1];
229 int mostprob_bin=nbinX-1;
231 mostprob_x=x->GetBinCenter(mostprob_bin);
234 for(
int i=nbinX-1; i>=0; i--){
236 if((ncounts[i]>mostprob)&&(flag<4)){
239 mostprob_x=x->GetBinCenter(mostprob_bin);
243 if(mostprob_x>MIPrange){
246 else if((ncounts[i]<=mostprob)&&(mostprob_bin!=nbinX-1)){
250 mostprob_x=x->GetBinCenter(mostprob_bin);
251 fr[0]=0.6*mostprob_x;
252 fr[1]=1.3*mostprob_x;
254 cout<<
"MIP FIT RANGE IS: "<< fr[0] <<
" -- "<<fr[1]<<endl;
256 pllo[0]=1; pllo[1]=0.6*mostprob_x; pllo[2]=10.0; pllo[3]=5.0;
257 plhi[0]=10; plhi[1]=1.3*mostprob_x; plhi[2]=8000.0; plhi[3]=100.0;
258 sv[0]=1; sv[1]=mostprob_x; sv[2]=1000.0; sv[3]=20;
261 mipconvo = langaufit(MIPbgsub1[
id],fr,sv,pllo,plhi,fp,fpe);
262 MIPbgsub1[id]->Fit(mipconvo,
"R+");
263 MIPbgsub1[id]->GetListOfFunctions()->Add(mipconvo);
264 mipconvo->SetNpx(10000);
267 mipconvo->GetParameters(¶m[0]);
268 float width=param[0];
271 float gsigma=param[3];
274 mipconvo->GetParameters(¶m2[0]);
275 float mpv2=param2[1];
276 mostprob_values[id]=mpv2;
280 float chi=mipconvo->GetChisquare();
281 float DOF=mipconvo->GetNDF();
282 float chiDOF=chi/DOF;
283 chisq_values[id]=chiDOF;
289 gStyle->SetOptStat(0);
290 TCanvas *c=
new TCanvas(
"c",
"mip fit",1100,900);
292 for (
int id =minTow;
id < maxTow+1;
id++)
298 x1=MIPbgsub1[id]->GetXaxis();
299 x1->SetTitle(
"ADC Sum");
300 x1->SetRangeUser(20,900);
302 MIPbgsub1[id]->Draw();
303 MIPbgsub1[id]->SetLineColor(kBlue);
307 c->Print(openOutput,
"pdf");
310 c->Print(closeOutput,
"pdf");
313 c->Print(outputFile,
"pdf");
319 TCanvas *d=
new TCanvas(
"d",
"av chisqr",1100,900);
320 chisq_edge->SetLineColor(kBlue);
322 chisq_edge->Draw(
"same");
323 d->Print(
"mip_chisqr.pdf");
327 TCanvas *e=
new TCanvas(
"e",
"mean values",1100,900);
328 TGraph* mean_vs_id=
new TGraph(64,id_list,mostprob_values);
329 mean_vs_id->GetXaxis()->SetTitle(
"Ecal Tower ID");
330 mean_vs_id->GetYaxis()->SetTitle(
"Most Prob. Value (ADCSum)");
331 mean_vs_id->SetMarkerStyle(21);
332 mean_vs_id->SetMarkerSize(2);
333 mean_vs_id->SetMarkerColor(2);
334 mean_vs_id->Draw(
"AP");
335 e->Print(
"mip_mpvs.pdf");