Changeset 1293 for trunk/MagicSoft/Mars/mhist/MHEffOnTimeTheta.cc
- Timestamp:
- 04/24/02 13:47:29 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHEffOnTimeTheta.cc
r1265 r1293 26 26 ////////////////////////////////////////////////////////////////////////////// 27 27 // // 28 // MHEffOnTimeTheta //28 // MHEffOnTimeTheta // 29 29 // // 30 // calculates the effective on time for each bin in Theta // 30 31 // // 31 32 ////////////////////////////////////////////////////////////////////////////// 32 33 33 34 #include "MHEffOnTimeTheta.h" 35 36 #include <TStyle.h> 34 37 35 38 #include <TF1.h> … … 47 50 ClassImp(MHEffOnTimeTheta); 48 51 49 50 52 // -------------------------------------------------------------------------- 51 53 // 52 // Default Constructor. It sets name and title only. Typically you won't 53 // need to change this. 54 // Default Constructor. It sets name and title of the histograms. 54 55 // 55 56 MHEffOnTimeTheta::MHEffOnTimeTheta(const char *name, const char *title) 56 : fH ist()57 : fHEffOn() 57 58 { 58 59 // … … 62 63 fTitle = title ? title : "1-D histogram of Eff On Time"; 63 64 64 fHist.SetName("EffOn"); 65 fHist.SetTitle("Effective On Time Vs. Theta"); 66 67 fHist.SetDirectory(NULL); 68 69 fHist.SetXTitle("t_{eff} [s]"); 70 fHist.SetYTitle("\\Theta [\\circ]"); 71 } 72 65 // effective on time versus theta 66 fHEffOn.SetName("EffOn"); 67 fHEffOn.SetTitle("Effective On Time vs. Theta"); 68 69 fHEffOn.SetDirectory(NULL); 70 71 fHEffOn.SetXTitle("\\Theta [\\circ]"); 72 fHEffOn.SetYTitle("t-eff [s]"); 73 74 // chi2/NDF versus theta 75 fHChi2.SetName("Chi2/NDF"); 76 fHChi2.SetTitle("Chi2/NDF of OnTimeFit vs. Theta"); 77 78 fHChi2.SetDirectory(NULL); 79 80 fHChi2.SetXTitle("\\Theta [\\circ]"); 81 fHChi2.SetYTitle("chi2/NDF"); 82 83 // lambda versus theta 84 fHLambda.SetName("lambda"); 85 fHLambda.SetTitle("lambda of OnTimeFit vs. Theta"); 86 87 fHLambda.SetDirectory(NULL); 88 89 fHLambda.SetXTitle("\\Theta [\\circ]"); 90 fHLambda.SetYTitle("\\lambda [Hz]"); 91 92 // N0del versus theta 93 fHN0del.SetName("N0del"); 94 fHN0del.SetTitle("N0del of OnTimeFit vs. Theta"); 95 96 fHN0del.SetDirectory(NULL); 97 98 fHN0del.SetXTitle("\\Theta [\\circ]"); 99 fHN0del.SetYTitle("N0del"); 100 } 101 102 // ----------------------------------------------------------------------- 103 // 104 // Calculate the effective on time by fitting the distribution of 105 // time differences 106 // 73 107 void MHEffOnTimeTheta::Calc(TH2D *hist) 74 108 { 109 // nbins = number of Theta bins 75 110 const Int_t nbins = hist->GetNbinsY(); 76 111 77 for (int i=1; i< nbins; i++)112 for (int i=1; i<=nbins; i++) 78 113 { 79 //char txt[100]; 80 //sprintf(txt, "Name%d", 100*i); 81 //new TCanvas(txt, "Title"); 82 83 TH1D &h = *hist->ProjectionX("dTime-Distribution for fixed Time", i, i); 84 85 //hist->Draw(); 86 //gPad->SetLogy(); 87 88 Double_t Nmdel = h.Integral("width"); 89 Double_t mean = h.GetMean(); 90 91 TF1 func("Poisson", "[1] * [0] * exp(-[0] *x)", 92 mean, hist->GetXaxis()->GetXmax()); 93 94 func.SetParameter(0, 100); // [Hz] 95 func.SetParameter(1, Nmdel); 96 97 func.SetParLimits(0, 0, 1000); // [Hz] 98 func.SetParLimits(1, 0, 2*Nmdel); 99 100 func.SetParName(0, "lambda"); 101 func.SetParName(1, "Nmdel"); 102 103 h.Fit("Poisson", "RN"); 104 105 //func.SetRange(0, 0.1); // Range of Drawing 106 //func.DrawCopy("same"); 107 108 //cout << func.GetParameter(0) << " " << func.GetParameter(1) << endl; 109 110 Double_t lambda = func.GetParameter(0); 111 //Double_t a = func.GetParameter(1); 112 113 //cout << "t_eff = " << h->Integral()/lambda << " T(last)=" << time.GetTimeLo()*0.0001 << endl; 114 115 fHist.SetBinContent(i, h.Integral()/lambda); 114 // TH1D &h = *hist->ProjectionX("Calc-theta", i, i); 115 TH1D &h = *hist->ProjectionX("Calc-theta", i, i, "E"); 116 117 // Nmdel = Nm * binwidth, with Nm = number of observed events 118 const Double_t Nmdel = h.Integral("width"); 119 const Double_t Nm = h.Integral(); 120 // Double_t mean = h->GetMean(); 121 122 //................................................... 123 // determine range (yq[0], yq[1]) of time differences 124 // where fit should be performed; 125 // require a fraction >=xq[0] of all entries to lie below yq[0] 126 // and a fraction <=xq[1] of all entries to lie below yq[1]; 127 // within the range (yq[0], yq[1]) there must be no empty bin; 128 // choose pedestrian approach as long as GetQuantiles is not available 129 130 Double_t xq[2] = { 0.15, 0.95 }; 131 Double_t yq[2]; 132 133 // GetQuantiles doesn't seem to be available in root 3.01/06 134 // h->GetQuantiles(2,yq,xq); 135 136 const Double_t sumtot = h.Integral(); 137 const Int_t jbins = h.GetNbinsX(); 138 139 if (sumtot > 0.0) 140 { 141 Double_t sum1 = 0.0; 142 yq[0] = h.GetBinLowEdge(jbins+1); 143 for (int j=1; j<=jbins; j++) 144 { 145 if (sum1 >= xq[0]*sumtot) 146 { 147 yq[0] = h.GetBinLowEdge(j); 148 break; 149 } 150 sum1 += h.GetBinContent(j); 151 } 152 153 Double_t sum2 = 0.0; 154 yq[1] = h.GetBinLowEdge(jbins+1); 155 for (int j=1; j<=jbins; j++) 156 { 157 Double_t content = h.GetBinContent(j); 158 sum2 += content; 159 if (sum2 >= xq[1]*sumtot || content == 0.0) 160 { 161 yq[1] = h.GetBinLowEdge(j); 162 break; 163 } 164 } 165 166 //................................................... 167 168 // parameter 0 = lambda 169 // parameter 1 = N0*del with N0 = ideal number of events 170 // and del = bin width of time difference 171 TF1 func("Poisson", "[1] * [0] * exp(-[0] *x)", yq[0], yq[1]); 172 173 func.SetParameter(0, 100); // [Hz] 174 func.SetParameter(1, Nmdel); 175 176 func.SetParLimits(0, 0, 1000); // [Hz] 177 func.SetParLimits(1, 0, 10*Nmdel); 178 179 func.SetParName(0, "lambda"); 180 func.SetParName(1, "Nmdel"); 181 182 // options : 0 do not plot the function 183 // I use integral of function in bin rather than value at bin center 184 // R use the range specified in the function range 185 // Q quiet mode 186 h.Fit("Poisson", "0IRQ"); 187 188 // gPad->SetLogy(); 189 // gStyle->SetOptFit(1011); 190 // h->GetXaxis()->SetTitle("time difference [s]"); 191 // h->GetYaxis()->SetTitle("Counts"); 192 // h->DrawCopy(); 193 194 // func.SetRange(yq[0], yq[1]); // Range of Drawing 195 // func.DrawCopy("same"); 196 197 const Double_t lambda = func.GetParameter(0); 198 const Double_t N0del = func.GetParameter(1); 199 const Double_t chi2 = func.GetChisquare(); 200 const Int_t NDF = func.GetNDF(); 201 202 // was fit successful ? 203 if (NDF>0 && chi2<2.5*NDF) 204 { 205 // the effective on time is Nm/lambda 206 fHEffOn.SetBinContent(i, Nm/lambda); 207 208 // plot chi2/NDF of fit 209 fHChi2.SetBinContent(i, NDF ? chi2/NDF : 0.0); 210 211 // lambda of fit 212 fHLambda.SetBinContent(i, lambda); 213 214 // N0del of fit 215 fHN0del.SetBinContent(i, N0del); 216 217 delete &h; 218 continue; 219 } 220 } 221 222 fHEffOn.SetBinContent (i, 1.e-20); 223 fHChi2.SetBinContent (i, 1.e-20); 224 fHLambda.SetBinContent(i, 1.e-20); 225 fHN0del.SetBinContent (i, 1.e-20); 116 226 117 227 delete &h; … … 119 229 } 120 230 231 // ------------------------------------------------------------------------- 232 // 233 // Set the binnings and prepare the filling of the histograms 234 // 121 235 Bool_t MHEffOnTimeTheta::SetupFill(const MParList *plist) 122 236 { … … 128 242 } 129 243 130 SetBinning(&fHist, bins); 244 SetBinning(&fHEffOn, bins); 245 SetBinning(&fHChi2, bins); 246 SetBinning(&fHLambda, bins); 247 SetBinning(&fHN0del, bins); 248 249 fHEffOn.Sumw2(); 250 fHChi2.Sumw2(); 251 fHLambda.Sumw2(); 252 fHN0del.Sumw2(); 131 253 132 254 return kTRUE; 133 255 } 134 256 257 // ------------------------------------------------------------------------- 258 // 259 // Dummy Fill 260 // without it get the error message : 261 // Error: MHEffOnTimeTime() no default constructor FILE:macros/wowflux.C LINE:359 262 // *** Interpreter error recovered *** 263 // 264 Bool_t MHEffOnTimeTheta::Fill(const MParContainer *par) 265 { 266 return kTRUE; 267 } 268 // ------------------------------------------------------------------------- 269 // 270 // Draw a copy of the histogram 271 // 135 272 TObject *MHEffOnTimeTheta::DrawClone(Option_t *opt) const 136 273 { 137 TCanvas *c = MakeDefCanvas("EffOnTimeTheta", "t_eff vs. Theta"); 274 TCanvas &c = *MakeDefCanvas("EffOnTimeTheta", "Results from on time fit vs. Theta"); 275 276 c.Divide(2, 2); 138 277 139 278 gROOT->SetSelectedPad(NULL); 140 279 141 ((TH2&)fHist).DrawCopy(opt); 142 143 c->Modified(); 144 c->Update(); 145 146 return c; 147 } 148 280 c.cd(1); 281 ((TH2*)&fHEffOn)->DrawCopy(opt); 282 283 c.cd(2); 284 ((TH2*)&fHChi2)->DrawCopy(opt); 285 286 c.cd(3); 287 ((TH2*)&fHLambda)->DrawCopy(opt); 288 289 c.cd(4); 290 ((TH2*)&fHN0del)->DrawCopy(opt); 291 292 c.Modified(); 293 c.Update(); 294 295 return &c; 296 } 297 298 // ------------------------------------------------------------------------- 299 // 300 // Draw the histogram 301 // 149 302 void MHEffOnTimeTheta::Draw(Option_t *opt) 150 303 { 151 304 if (!gPad) 152 MakeDefCanvas("EffOnTimeTheta", "t_eff vs. Theta"); 153 154 fHist.Draw(opt); 305 MakeDefCanvas("EffOnTimeTheta", "Results from on time fit vs. Theta"); 306 307 gPad->Divide(2,2); 308 309 gPad->cd(1); 310 fHEffOn.Draw(opt); 311 312 gPad->cd(2); 313 fHChi2.Draw(opt); 314 315 gPad->cd(3); 316 fHLambda.Draw(opt); 317 318 gPad->cd(4); 319 fHN0del.Draw(opt); 155 320 156 321 gPad->Modified(); … … 159 324 160 325 161 Bool_t MHEffOnTimeTheta::Fill(const MParContainer *par) 162 { 163 return kTRUE; 164 } 165 326 327 328 329 330 331 332 333 334 335 336
Note:
See TracChangeset
for help on using the changeset viewer.