Changeset 2170
- Timestamp:
- 06/11/03 13:44:37 (22 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2168 r2170 1 1 -*-*- END OF LINE -*-*- 2 3 2003/06/11: Robert Wagner 4 5 * mhist/MHOnSubtraction.[h,cc] 6 - Some bugfixes, e.g. concerning binning of result histograms 7 - Improvements in output 2 8 3 9 -
trunk/MagicSoft/Mars/mhist/MHOnSubtraction.cc
r2164 r2170 26 26 ////////////////////////////////////////////////////////////////////////////// 27 27 // // 28 // MHOnSubtraction // 28 // MHOnSubtraction // 29 // // 29 30 // // 30 31 // extracts the gamma signal from a pure ON-signal given in an // 31 32 // ALPHA-Energy-Theta histogram. The class will take this histogram from // 32 // the parameter list and will provide a MHArray of MH3 histograms in // 33 // energy, one per theta bin. // 33 // the parameter list and will provide result histograms in the // 34 // parameter list. // 35 // // 36 // This class still is work in progress. // 37 // // 34 38 // // 35 39 ////////////////////////////////////////////////////////////////////////////// 36 40 37 // This part of MARS is code still evolving. Please do not remove commentary38 // parts and clearly state where and how you changed the code, if you did so.41 // This part of MARS is code still evolving. Please do not change the code 42 // without prior feedback by the author. 39 43 40 44 #include "MHOnSubtraction.h" … … 64 68 // Default Constructor. 65 69 // 66 MHOnSubtraction::MHOnSubtraction(const char *name, const char *title) : fMaxSignif(0), 67 fMaxRedChiSq(0), 68 fSlope(20.0) 70 MHOnSubtraction::MHOnSubtraction(const char *name, const char *title) : fMaxSignif(0), fMaxRedChiSq(0), fSlope(20.0) 69 71 { 70 72 fName = name ? name : "MHOnSubtraction"; … … 96 98 // measurements have to be provided. 97 99 // 100 // This function underestimates the true significance for it does not take 101 // into account errors on the event numbers. A more accurate variation wil 102 // be provided soon 103 // 98 104 Double_t MHOnSubtraction::CalcSignificance(Double_t nOn, Double_t nOff, Double_t theta) 99 105 { 100 101 if (nOn<=0) { 106 if (nOn<=0) 102 107 *fLog << warn << "Got " << nOn << " total events, " << flush; 103 } 104 105 if (nOff<=0) { 106 *fLog << warn << "Got " << nOff << " background events, " << flush; 107 } 108 108 if (nOff<=0) 109 *fLog << warn << "Got " << nOff << " background events, " << flush; 109 110 if (nOn<=0 || nOff<=0.0) { 110 111 *fLog << warn << "returning significance of 0.0" << endl; 111 112 return 0.0; 112 113 } 113 114 114 return sqrt(2*(nOn*log((1+theta)*nOn/(theta*(nOn+nOff))) 115 115 +nOff*log((1+theta)*(nOff/(nOn+nOff))))); … … 117 117 118 118 // ----------------------------------------------------------------------- 119 // 120 // This function takes a first look at a given ALPHA distribution 121 // and determines if a fit is applicable. 119 122 // 120 123 // Fits a given TH1 containing an ALPHA distribution with a combined … … 177 180 178 181 *fLog << dbg << "Plot contains " << 179 outerEvents << " outer ev (" << outerEvents/outerBins << "/bin), " << flush; 180 *fLog << dbg << 182 outerEvents << " outer ev (" << outerEvents/outerBins << "/bin), " << 181 183 innerEvents << " inner ev (" << innerEvents/innerBins << "/bin) " << endl; 182 184 183 185 if ((outerBinsZero!=0) || (innerBinsZero != 0)) 184 186 *fLog << warn << "There are "; 185 186 187 if (outerBinsZero != 0) 187 188 *fLog << dbg << outerBinsZero << " empty outer bins "; 188 189 189 if (innerBinsZero != 0) 190 190 *fLog << dbg <<innerBinsZero << " empty inner bins "; 191 192 191 if ((outerBinsZero!=0) || (innerBinsZero != 0)) 193 192 *fLog << endl; 194 193 195 194 if (outerEvents == 0.0) { 196 *fLog << warn << "No events in OFF region. Assuming background = 0" << endl;197 195 *fLog << warn << "No events in OFF region. Assuming background = 0" 196 << endl; 198 197 TF1 *po = new TF1("pol0"+funcName,"pol0(0)",-89.5,89.5); 199 198 po->SetLineWidth(2); … … 203 202 alphaHisto.GetListOfFunctions()->Add(po); 204 203 alphaHisto.SetLineColor(97); 205 alphaHisto.DrawCopy(); //rwagner 206 po->Draw("SAME"); 207 204 if (draw) { 205 alphaHisto.DrawCopy(); //rwagner 206 po->Draw("SAME"); 207 } 208 208 sigLiMa = 0; 209 209 lowerBin = 1; … … 213 213 return kFALSE; //No gaus fit applied 214 214 } 215 215 216 if (outerEvents/outerBins < 2.5) { 216 217 *fLog << warn << "Only " << /*setprecision(2) <<*/ outerEvents/outerBins … … 224 225 po->SetParameter(0,outerEvents/outerBins); 225 226 alphaHisto.GetListOfFunctions()->Add(po); 226 alphaHisto.DrawCopy(); //rwagner 227 po->Draw("SAME"); 227 if (draw) { 228 alphaHisto.DrawCopy(); //rwagner 229 po->Draw("SAME"); 230 } 228 231 229 232 Int_t centerBin = alphaHisto.GetXaxis()->FindBin((Double_t)0.0); … … 231 234 alphaHisto.GetNbinsX()- centerBin : centerBin; 232 235 233 234 236 Int_t lowerSignalEdge = centerBin; 235 237 for (Int_t i=3; i < maxBin; i++) { 236 if ((double)alphaHisto.GetBinContent(centerBin-i) < outerEvents/outerBins) { 238 if ((double)alphaHisto.GetBinContent(centerBin-i) 239 < outerEvents/outerBins) { 237 240 lowerSignalEdge = centerBin-i+1; 238 241 break; … … 243 246 Int_t upperSignalEdge = centerBin; 244 247 for (Int_t i=3; i < maxBin; i++) { 245 if ((double)alphaHisto.GetBinContent(centerBin+i) <= outerEvents/outerBins) { 248 if ((double)alphaHisto.GetBinContent(centerBin+i) 249 <= outerEvents/outerBins) { 246 250 upperSignalEdge=centerBin+i-1; 247 251 break; … … 251 255 252 256 double nOnInt = 0; 253 for (Int_t i=1; i < alphaHisto.GetNbinsX(); i++) {257 for (Int_t i=1; i < alphaHisto.GetNbinsX(); i++) 254 258 nOnInt += alphaHisto.GetBinContent(i) - outerEvents/outerBins; 255 }256 259 257 double nOffInt = (upperSignalEdge - lowerSignalEdge + 1) * (outerEvents/outerBins); 260 double nOffInt = (upperSignalEdge - lowerSignalEdge + 1) 261 * (outerEvents/outerBins); 258 262 259 263 sigLiMa = CalcSignificance(nOnInt, nOffInt, 1); 260 261 *fLog << inf << "Estimated significance is " << sigLiMa << " sigma " << endl; 264 265 if (sigLiMa < 3) 266 alphaHisto.SetLineColor(2); 267 268 269 *fLog << inf << "Estimated significance is " << sigLiMa 270 << " sigma " << endl; 262 271 *fLog << inf << "Signal region is " 263 << lowerBin << " < ALPHA < " << upperBin << " (Most likely you wanna ignore this)" << endl; 272 << lowerBin << " < ALPHA < " << upperBin 273 << " (Most likely you wanna ignore this)" << endl; 264 274 265 275 return kFALSE; //No gaus fit applied 266 267 276 } 268 277 … … 325 334 326 335 sigLiMa = CalcSignificance(nOnInt, nOffInt, 1); 327 328 *fLog << inf << "Fit estimates significance to be " << sigLiMa << " sigma " << endl; 336 // if (sigLiMa < 3) 337 // alphaHisto.SetLineColor(2); 338 339 340 *fLog << inf << "Fit estimates significance to be " 341 << sigLiMa << " sigma " << endl; 329 342 330 343 *fLog << inf << "Fit yields signal region to be " … … 336 349 } 337 350 351 352 353 354 338 355 // ----------------------------------------------------------------------- 339 356 // 340 357 // Does the actual extraction of the gamma signal. For performance 341 // reasons, the fit from MHOnSubtraction::FitHistogram is used and not redone. 358 // reasons, fits already done by MHOnSubtraction::FitHistogram are used 359 // and not redone. 342 360 // From it, a polynomial function for the background is evaluated and the 343 361 // gamma signal is extracted in the region given by lowerBin < ALPHA < … … 347 365 // 348 366 Bool_t MHOnSubtraction::ExtractSignal(TH1 &alphaHisto, Double_t &sigLiMa, 349 Double_t &lowerBin, Double_t &upperBin, 350 Double_t &gammaSignal, Double_t &errorGammaSignal, 351 Double_t &off, Double_t &errorOff, 352 Float_t signalRegionFactor, const Bool_t draw, TString funcName) 367 Double_t &lowerBin, Double_t &upperBin, 368 Double_t &gammaSignal, Double_t &errorGammaSignal, 369 Double_t &off, Double_t &errorOff, 370 Float_t signalRegionFactor, const Bool_t draw, TString funcName, 371 TPad *drawPad, Int_t drawBase) 353 372 { 354 373 TF1 *gausPol = alphaHisto.GetFunction("gauspol3"+funcName); … … 358 377 *fLog << err << "Fatal: ALPHA histogram has no gauspol or pol " 359 378 << " fit attached to it." << endl; 360 // if (draw) { 361 TPaveLabel* lab = new TPaveLabel(0.1,0.2,0.9,0.8,"(no fit)"); 362 lab->SetFillStyle(3000); 363 lab->SetBorderSize(0); 364 lab->DrawClone(); 365 lab->SetBit(kCanDelete); 366 367 // } 379 TPaveLabel* lab = new TPaveLabel(0.1,0.2,0.9,0.8,"(no fit)"); 380 lab->SetFillStyle(3000); 381 lab->SetBorderSize(0); 382 lab->DrawClone(); 383 lab->SetBit(kCanDelete); 368 384 return kFALSE; 369 385 } … … 414 430 415 431 if (pol) { 416 417 432 po = pol; 418 433 … … 449 464 } //for bin 450 465 eNOn = sqrt(eNOn); 451 452 466 453 467 // Evaluate background 454 468 … … 463 477 eNOff = sqrt(fabs(nOff)); 464 478 465 if (nOn==0) {// there should not be a negative number of signal events479 if (nOn==0) // there should not be a negative number of signal events 466 480 nOff=0; 467 } 468 481 469 482 if (nOff<0) { // there should not be a negative number of off events 470 483 nOff=0; … … 472 485 } 473 486 474 475 487 *fLog << inf << "nEvts = " << nOn << "+-" << eNOn << ", "; 476 488 … … 498 510 pt->SetBorderSize(0); 499 511 pt->SetTextAlign(12); 500 pt->Draw( );512 pt->Draw(""); 501 513 } 502 514 503 if (draw ) {515 if (draw||drawPad) { 504 516 // Plot significance vs alpha_cut 505 517 … … 507 519 Int_t maxBin = centerBin > alphaHisto.GetNbinsX()- centerBin ? 508 520 alphaHisto.GetNbinsX()- centerBin : centerBin; 509 510 521 511 522 const Int_t totalBins = centerBin; 512 523 Float_t alpha[totalBins]; 513 524 Float_t signi[totalBins]; 514 525 Float_t maxSigni = 0; 526 515 527 for (Int_t i=0; i < maxBin; i++) { 516 528 double nOn = 0; double eNOn = 0; … … 529 541 alphaHisto.GetXaxis()->GetBinLowEdge(centerBin-i))/2; 530 542 signi[i] = CalcSignificance(nOn, nOff, 1); 543 maxSigni = maxSigni > signi[i] ? maxSigni : signi[i]; 531 544 } 532 533 TCanvas *c3 = new TCanvas("c3"+funcName, "Significance vs ALPHA cut", 800,600); 534 c3->cd(); 545 546 if (!drawPad) { 547 TCanvas *c3 = new TCanvas("c3"+funcName, "Significance vs ALPHA cut", 800,600); 548 c3->cd(); 549 } 550 551 if (drawPad) 552 drawPad->cd(drawBase-1); 553 535 554 TGraph* gr = new TGraph(totalBins-2,alpha,signi); 536 gr->Draw("ACP"); 537 gr->GetXaxis()->SetTitle("|#alpha_{max}|"); 538 gr->GetYaxis()->SetTitle("Significance"); 555 TString drawOpt = "L"; 556 557 if (draw || (drawPad && fSigniPlotIndex == 0)) 558 drawOpt += "A"; 559 560 gr->Draw(drawOpt); 561 if (drawPad && fSigniPlotIndex == 0) { 562 gr->GetXaxis()->SetTitle("|#alpha_{max}|"); 563 gr->GetYaxis()->SetTitle("Significance"); 564 } 539 565 gr->SetMarkerStyle(2); 540 566 gr->SetMarkerSize(1); 541 gr->SetMarkerColor(4 );542 gr->SetLineColor(4 );543 gr->SetLineWidth( 2);567 gr->SetMarkerColor(4+fSigniPlotIndex); 568 gr->SetLineColor(4+fSigniPlotIndex); 569 gr->SetLineWidth(1); 544 570 gr->SetTitle("Significance vs ALPHA integration range"); 545 571 gr->Draw("LP"); 572 573 fSigniPlotIndex++; 574 546 575 } //draw 547 576 … … 724 753 // So now we can indeed extract the signal. 725 754 726 cout << "STARTIGN REAL CALC "<< endl;755 // cout << "STARTIGN REAL CALC "<< endl; 727 756 728 757 sumSigLiMa = 0; … … 757 786 758 787 //fit exponential function to data 759 TF1 *e = new TF1("expF","expo",0,5);788 TF1* e = new TF1("expF","expo",0,5); 760 789 e->SetLineWidth(3); 761 790 e->SetLineColor(thetaBin); … … 847 876 // ------------------------------------- 848 877 MBinning *binsmh3x = new MBinning("BinningMH3X"); 878 // dummy binning, real one follows some lines down 849 879 binsmh3x->SetEdgesLog(energyBins,aetHisto->GetYaxis()->GetBinLowEdge(1), 850 880 aetHisto->GetYaxis()->GetBinLowEdge(energyBins+1)); 851 881 parlist->AddToList(binsmh3x); 852 882 853 883 MBinning *binsmh3y = new MBinning("BinningMH3Y"); 884 // dummy binning, real one follows some lines down 854 885 binsmh3y->SetEdges(thetaBins,aetHisto->GetZaxis()->GetBinLowEdge(1), 855 886 aetHisto->GetZaxis()->GetBinLowEdge(thetaBins+1)); … … 894 925 signalTH2DHist.SetXTitle("E [GeV]"); 895 926 signalTH2DHist.SetYTitle("theta [deg]"); 927 signalHisto->SetBinning(&signalTH2DHist, aetHisto->GetYaxis(), aetHisto->GetZaxis()); 896 928 signalTH2DHist.Sumw2(); 897 929 … … 900 932 offTH2DHist.SetXTitle("E [GeV]"); 901 933 offTH2DHist.SetYTitle("theta [deg]"); 934 offHisto->SetBinning(&offTH2DHist, aetHisto->GetYaxis(), aetHisto->GetZaxis()); 902 935 offTH2DHist.Sumw2(); 903 936 … … 906 939 signifTH2DHist.SetXTitle("E [GeV]"); 907 940 signifTH2DHist.SetYTitle("theta [deg]"); 941 signifHisto->SetBinning(&signifTH2DHist, aetHisto->GetYaxis(), aetHisto->GetZaxis()); 908 942 signifTH2DHist.Sumw2(); 909 943 … … 1005 1039 1006 1040 c4->cd((energyBins+3)*(thetaBin-1)+2); 1007 1008 1041 sprintf(hname,"c4_%d",(energyBins+3)*(thetaBin-1)+2); 1009 1042 TPad* tp = (TPad*)(gROOT->FindObject(hname)); 1010 tp->SetLogx(); 1011 1043 tp->SetLogx(); 1012 1044 signalTH1DHist.SetLineColor(2); 1013 signalTH1DHist.DrawCopy(); 1014 1045 signalTH1DHist.DrawCopy(); 1015 1046 offTH1DHist.SetLineColor(4); 1016 offTH1DHist.DrawCopy("SAME"); 1017 1018 1047 offTH1DHist.DrawCopy("SAME"); 1019 1048 c4->Update(); 1020 1021 1022 1049 1023 1050 signalTH2DHist.SetEntries(signalTH2DHist.GetEntries()+signalTH1DHist.GetEntries()); 1024 1051 offTH2DHist.SetEntries(offTH2DHist.GetEntries()+offTH1DHist.GetEntries()); … … 1032 1059 } 1033 1060 1061 1034 1062 c4->Update(); 1035 1063 1036 1064 return kTRUE; 1037 1065 } … … 1084 1112 Bool_t MHOnSubtraction::TH2Calc(TH2 *aeHisto, MParList *parlist, const Bool_t draw, TPad *drawPad, Int_t drawBase) 1085 1113 { 1114 1115 fSigniPlotColor = 0; 1116 1086 1117 // Analyze aeHisto 1087 1118 // ------------------------------------- … … 1113 1144 signalHisto->SetTitle("Extracted Signal"); 1114 1145 parlist->AddToList(signalHisto); 1115 1146 signalHisto->SetBinning(&((TH1D&)signalHisto->GetHist()), 1147 aeHisto->GetYaxis()); 1148 1116 1149 offHisto = new MH3(1); // Off(E) 1117 1150 offHisto->SetName("MHOnSubtractionOff"); 1118 1151 offHisto->SetTitle("Off Signal"); 1119 1152 parlist->AddToList(offHisto); 1153 offHisto->SetBinning(&((TH1D&)offHisto->GetHist()), 1154 aeHisto->GetYaxis()); 1120 1155 1121 1156 signifHisto = new MH3(1); // Significance(E) … … 1123 1158 signifHisto->SetTitle("Significance"); 1124 1159 parlist->AddToList(signifHisto); 1160 signifHisto->SetBinning(&((TH1D&)signifHisto->GetHist()), 1161 aeHisto->GetYaxis()); 1162 1125 1163 } 1126 1164 if (fChiSquareHisto==0x0) … … 1142 1180 1143 1181 TH1F* alphaHisto[energyBins]; 1182 1183 fSigniPlotIndex = 0; // cf. ExtractSignal 1144 1184 1145 1185 for (Int_t energyBin = 1; energyBin < energyBins+1; energyBin++) { … … 1238 1278 sigLiMa, minLowerBin, maxUpperBin, 1239 1279 gammaSignal, errorGammaSignal, off, errorOff, (Float_t)3, drawFit, 1240 funcName );1280 funcName, drawPad, drawBase); 1241 1281 1242 1282 sumSigLiMa += sigLiMa; … … 1304 1344 // 1305 1345 // Extraction of Gamma signal is performed on a TH1 histogram in ALPHA 1346 // 1306 1347 // 1307 1348 Bool_t MHOnSubtraction::Calc(TH1 *aHisto, MParList *parlist, 1308 const Bool_t Draw, Float_t signalRegion)1349 const Bool_t draw, Float_t signalRegion) 1309 1350 { 1310 1351 // Find signal region and estimate significance … … 1323 1364 1324 1365 ExtractSignal(*aHisto, sigLiMa, lowerBin, upperBin, 1325 gammaSignal, errorGammaSignal, off, errorOff, (Float_t)3.0, kTRUE); 1366 gammaSignal, errorGammaSignal, off, errorOff, 1367 (Float_t)3.0, draw); 1326 1368 1327 1369 *fLog << inf << "Signal is " -
trunk/MagicSoft/Mars/mhist/MHOnSubtraction.h
r2164 r2170 17 17 #include "TPaveLabel.h" 18 18 #endif 19 #ifndef ROOT_TFile 20 #include "TFile.h" 21 #endif 22 19 23 20 24 … … 41 45 Double_t fSlope; // slope for exponential fit 42 46 Int_t fThetaBin; 47 Int_t fSigniPlotIndex; 48 Int_t fSigniPlotColor; 49 50 Bool_t CalcAET(TH3D *histon, MParList *parlist, const Bool_t Draw); 51 52 Bool_t FitHistogram(TH1 &alphaHisto, Double_t &sigLiMa, 53 Double_t &lowerBin, Double_t &upperBin, 54 Float_t signalRegionFactor = 3, const Bool_t draw = kFALSE, 55 TString funcName = ""); 56 57 Bool_t ExtractSignal(TH1 &alphaHisto, Double_t &sigLiMa, 58 Double_t &lowerBin, Double_t &upperBin, 59 Double_t &gammaSignal, Double_t &errorGammaSignal, 60 Double_t &off, Double_t &errorOff, 61 Float_t signalRegionFactor = 3, const Bool_t draw = kFALSE, 62 TString funcName = "", TPad *drawPad = 0, Int_t drawBase = 0); 63 64 43 65 44 66 public: … … 55 77 56 78 void SetExpoSlope(Double_t slope) { fSlope = slope; } 57 58 Bool_t FitHistogram(TH1 &alphaHisto, Double_t &sigLiMa,59 Double_t &lowerBin, Double_t &upperBin,60 Float_t signalRegionFactor = 3, const Bool_t draw = kFALSE,61 TString funcName = "");62 63 Bool_t ExtractSignal(TH1 &alphaHisto, Double_t &sigLiMa,64 Double_t &lowerBin, Double_t &upperBin,65 Double_t &gammaSignal, Double_t &errorGammaSignal,66 Double_t &off, Double_t &errorOff,67 Float_t signalRegionFactor = 3, const Bool_t draw = kFALSE,68 TString funcName = "");69 79 70 80 Bool_t Calc(MParList *parlist, const Bool_t Draw); 71 Bool_t CalcAET(TH3D *histon, MParList *parlist, const Bool_t Draw);72 81 73 82 Bool_t Calc(TH3 *histon, MParList *parlist, const Bool_t Draw); 74 Bool_t TH2Calc(TH2 *aeHisto, MParList *parlist, const Bool_t Draw, TPad *drawPad = 0, Int_t drawBase = 0); 83 Bool_t TH2Calc(TH2 *aeHisto, MParList *parlist, const Bool_t Draw, 84 TPad *drawPad = 0, Int_t drawBase = 0); 75 85 Bool_t Calc(TH1 *histon, MParList *parlist, const Bool_t Draw, 76 86 Float_t signalRegion = 0);
Note:
See TracChangeset
for help on using the changeset viewer.