ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yangyong/combineICEE/gausfit.cc
Revision: 1.1
Committed: Tue Apr 10 20:03:11 2012 UTC (13 years, 1 month ago) by yangyong
Content type: text/plain
Branch: MAIN
CVS Tags: V2012comb, pi0etaee_laser20111122_eefloatalpha, HEAD
Log Message:
LaserTag:
EcalLaserAPDPNRatios_data_20111122_158851_180363
and alpha Tag ( for Endcap Only)
EcalLaserAlphas_lto420-620_progr_data_20111122

File Contents

# User Rev Content
1 yangyong 1.1
2    
3     TF1* fitgaus(TH1F *hist,float low, float high,float res[]){
4    
5     // Float_t rms = hist->GetRMS();
6     // Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
7     // gStyle->SetOptFit(111111);
8    
9     TF1 *f1 = new TF1("f1","gaus",low,high);
10    
11    
12    
13     hist->Fit("f1","RQ");
14     Float_t sigma = f1->GetParameter(2);
15     Float_t mean = f1->GetParameter(1);
16     float sigerr = f1->GetParError(2);
17     res[0] = mean;
18     res[1] = f1->GetParError(1);
19     res[2] = sigma;
20     res[3] = sigerr;
21     res[4] = mean;
22     res[5] = f1->GetParError(1);
23     res[6] = sigma;
24    
25    
26     return f1;
27    
28     }
29    
30    
31    
32     TF1* fitgausD(TH1D *hist,float low, float high,float res[]){
33    
34     // Float_t rms = hist->GetRMS();
35     // Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
36     // gStyle->SetOptFit(111111);
37    
38     TF1 *f1 = new TF1("f1","gaus",low,high);
39    
40    
41    
42    
43     hist->Fit("f1","RQ");
44     Float_t sigma = f1->GetParameter(2);
45     Float_t mean = f1->GetParameter(1);
46     float sigerr = f1->GetParError(2);
47     res[0] = mean;
48     res[1] = f1->GetParError(1);
49     res[3] = sigma;
50     res[2] = sigerr;
51     res[4] = mean;
52     res[5] = f1->GetParError(1);
53     res[6] = sigma;
54    
55    
56     return f1;
57    
58     }
59    
60    
61    
62    
63     TF1* fitgauswind(TH1F *hist, Float_t mins, Float_t maxs){
64    
65     float res[20];
66    
67    
68     Float_t rms = hist->GetRMS();
69     Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
70     ///gStyle->SetOptFit(111111);
71    
72     TF1 *f1 = new TF1("f1","gaus",maxbin-2*rms, maxbin+2*rms);
73     hist->Fit("f1","R0Q");
74     Float_t sigma = f1->GetParameter(2);
75     Float_t mean = f1->GetParameter(1);
76     // float sigerr = f1->GetParError(2);
77    
78     for( int ll=0; ll<10; ll++){
79     f1 = fitgaus(hist,mean-mins*sigma, mean+maxs*sigma,res);
80     if(fabs(sigma-res[6])>0.001){
81     sigma = res[6];
82     mean = res[4];
83     }
84     else
85     break;
86     }
87    
88     return f1;
89    
90     }
91    
92    
93     void fitgauswindRefit(TH1F *hist,float res[]){
94    
95     Float_t rms = hist->GetRMS();
96     Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
97     ///gStyle->SetOptFit(111111);
98    
99     TF1 *f1 = new TF1("f1","gaus",maxbin-2*rms, maxbin+2*rms);
100     hist->Fit("f1","RQ");
101    
102     Float_t sigma = f1->GetParameter(2);
103     Float_t mean = f1->GetParameter(1);
104    
105     TF1 *f2 = new TF1("f2","gaus",mean-5*sigma, mean+5*sigma);
106     for(int j=0;j<3; j++){
107     f2->SetParameter(j,f1->GetParameter(j));
108     }
109     hist->Fit("f2","RQ");
110    
111     sigma = f2->GetParameter(2);
112     mean = f2->GetParameter(1);
113     float sigerr = f2->GetParError(2);
114    
115     res[0] = mean;
116     res[1] = f2->GetParError(1);
117     res[2] = sigma;
118     res[3] = sigerr;
119     res[4] = mean;
120     res[5] = f2->GetParError(1);
121     res[6] = sigma;
122    
123     }
124    
125    
126    
127    
128     void fitgauswind2(TH1F *hist, Float_t mins, Float_t maxs,float res[]){
129    
130    
131     Float_t rms = hist->GetRMS();
132     Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
133     ///gStyle->SetOptFit(111111);
134    
135     TF1 *f1 = new TF1("f1","gaus",maxbin-2*rms, maxbin+2*rms);
136     hist->Fit("f1","R0Q");
137     Float_t sigma = f1->GetParameter(2);
138     Float_t mean = f1->GetParameter(1);
139     // float sigerr = f1->GetParError(2);
140    
141     for( int ll=0; ll<10; ll++){
142     f1 = fitgaus(hist,mean-mins*sigma, mean+maxs*sigma,res);
143     if(fabs(sigma-res[6])>0.001){
144     sigma = res[6];
145     mean = res[4];
146     }
147     else
148     break;
149     }
150    
151     // return f1;
152    
153     }
154    
155    
156    
157     void fitgauswindD(TH1D *hist, Float_t mins, Float_t maxs,float res[]){
158    
159    
160     Float_t rms = hist->GetRMS();
161     Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
162     ///gStyle->SetOptFit(111111);
163    
164     hist->GetXaxis()->SetRangeUser(maxbin-3*rms, maxbin+3*rms);
165    
166     // cout<<"maxbin: "<< maxbin <<" "<< maxbin-2*rms <<" "<< maxbin+2*rms <<endl;
167    
168    
169     TF1 *f1 = new TF1("f1","gaus",maxbin-2*rms, maxbin+2*rms);
170     hist->Fit("f1","R0Q");
171     Float_t sigma = f1->GetParameter(2);
172     Float_t mean = f1->GetParameter(1);
173     // float sigerr = f1->GetParError(2);
174    
175     //cout<<"maxbin_iter: "<< maxbin <<" "<< maxbin-2*rms <<" "<< maxbin+2*rms <<endl;
176    
177     for( int ll=0; ll<10; ll++){
178    
179     // cout<<"ll: "<<ll <<" "<< mean <<" "<< sigma <<endl;
180    
181     f1 = fitgausD(hist,mean-mins*sigma, mean+maxs*sigma,res);
182     if(fabs(sigma-res[6])>0.001){
183     sigma = res[6];
184     mean = res[4];
185     }
186     else
187     break;
188     }
189    
190     // return f1;
191    
192     }
193    
194    
195    
196     TF1* fitgausI(TH1I *hist,float low, float high,float res[]){
197    
198     // Float_t rms = hist->GetRMS();
199     // Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
200     // gStyle->SetOptFit(111111);
201    
202     TF1 *f1 = new TF1("f1","gaus",low,high);
203     hist->Fit("f1","RQ");
204     Float_t sigma = f1->GetParameter(2);
205     Float_t mean = f1->GetParameter(1);
206     float sigerr = f1->GetParError(2);
207     res[0] = mean;
208     res[1] = f1->GetParError(1);
209     res[3] = sigma;
210     res[2] = sigerr;
211     res[4] = mean;
212     res[5] = f1->GetParError(1);
213     res[6] = sigma;
214    
215    
216     return f1;
217    
218     }
219    
220     TF1* fitgauswindI(TH1I *hist, Float_t mins, Float_t maxs){
221    
222     float res[20];
223    
224    
225     Float_t rms = hist->GetRMS();
226     Float_t maxbin = hist->GetMaximumBin() * hist->GetBinWidth(1) +hist->GetXaxis()->GetXmin();
227     ///gStyle->SetOptFit(111111);
228    
229     TF1 *f1 = new TF1("f1","gaus",maxbin-2*rms, maxbin+2*rms);
230     hist->Fit("f1","R0Q");
231     Float_t sigma = f1->GetParameter(2);
232     Float_t mean = f1->GetParameter(1);
233     // float sigerr = f1->GetParError(2);
234    
235     for( int ll=0; ll<10; ll++){
236     f1 = fitgausI(hist,mean-mins*sigma, mean+maxs*sigma,res);
237     if(fabs(sigma-res[6])>0.001){
238     sigma = res[6];
239     mean = res[4];
240     }
241     else
242     break;
243     }
244    
245     return f1;
246    
247     }
248