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