Changeset 2176 for trunk/MagicSoft/Mars
- Timestamp:
- 06/15/03 10:31:36 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2173 r2176 1 1 -*-*- END OF LINE -*-*- 2 3 2003/06/13: Robert Wagner 4 * mhist/MHOnSubtraction.cc 5 - removed casts from double to Double_t found by gcc 3.3 6 - added MHOnSubtraction::CalcLightCurve, a methods towards a 7 lightcurve 8 2 9 3 10 2003/06/13: Thomas Bretz (making Mars work with gcc 3.3 on Suse 8.2) … … 112 119 * mreflector/MRflEvtData.cc, mreflector/MRflSinglePhoton.cc: 113 120 - fixed definition of Print 121 114 122 115 123 -
trunk/MagicSoft/Mars/NEWS
r2160 r2176 3 3 *** Version 0.9 4 4 5 - added signal subtraction for pure on data by means of fitting 6 the background in the off region or by performing a combined 7 signal/background fit. Provides necessary histograms for 8 obtaining energy spectra and a light curve. 9 5 10 - added classes to perform and study the selection of the 6 11 2nd Level Trigger on MC data (example in triglvl2.C macro) -
trunk/MagicSoft/Mars/mhist/MHOnSubtraction.cc
r2174 r2176 237 237 Int_t lowerSignalEdge = centerBin; 238 238 for (Int_t i=3; i < maxBin; i++) { 239 if (( double)alphaHisto.GetBinContent(centerBin-i)239 if ((Double_t)alphaHisto.GetBinContent(centerBin-i) 240 240 < outerEvents/outerBins) { 241 241 lowerSignalEdge = centerBin-i+1; … … 247 247 Int_t upperSignalEdge = centerBin; 248 248 for (Int_t i=3; i < maxBin; i++) { 249 if (( double)alphaHisto.GetBinContent(centerBin+i)249 if ((Double_t)alphaHisto.GetBinContent(centerBin+i) 250 250 <= outerEvents/outerBins) { 251 251 upperSignalEdge=centerBin+i-1; … … 255 255 if (centerBin>upperSignalEdge) upperSignalEdge=centerBin; 256 256 257 doublenOnInt = 0;257 Double_t nOnInt = 0; 258 258 for (Int_t i=1; i < alphaHisto.GetNbinsX(); i++) 259 259 nOnInt += alphaHisto.GetBinContent(i) - outerEvents/outerBins; 260 260 261 doublenOffInt = (upperSignalEdge - lowerSignalEdge + 1)261 Double_t nOffInt = (upperSignalEdge - lowerSignalEdge + 1) 262 262 * (outerEvents/outerBins); 263 263 … … 292 292 alphaHisto.SetDirectory(NULL); //rwagner 293 293 294 doublegausMean = gp->GetParameter(1);295 doublegausSigma = gp->GetParameter(2);294 Double_t gausMean = gp->GetParameter(1); 295 Double_t gausSigma = gp->GetParameter(2); 296 296 297 297 // TF1 *p3 = new TF1("p3"+funcName,"pol3(0)",-signalRegionFactor*gausSigma+gausMean, … … 315 315 // this allows us to 316 316 // (1) determine n_{ON}, n_{OFF} 317 doublescalingFactor =317 Double_t scalingFactor = 318 318 (alphaHisto.GetXaxis()->GetBinLowEdge(alphaHisto.GetNbinsX()+1) 319 319 - alphaHisto.GetXaxis()->GetBinLowEdge(1)) / alphaHisto.GetNbinsX(); 320 320 321 doublenOnInt = (gp->Integral(-signalRegionFactor*gausSigma+gausMean,321 Double_t nOnInt = (gp->Integral(-signalRegionFactor*gausSigma+gausMean, 322 322 signalRegionFactor*gausSigma+gausMean) / scalingFactor); 323 doublenOffInt = (p3->Integral(-signalRegionFactor*gausSigma+gausMean,323 Double_t nOffInt = (p3->Integral(-signalRegionFactor*gausSigma+gausMean, 324 324 signalRegionFactor*gausSigma+gausMean) / scalingFactor); 325 325 … … 390 390 391 391 if (gausPol) { 392 doublegausMean = gausPol->GetParameter(1);393 doublegausSigma = gausPol->GetParameter(2);392 Double_t gausMean = gausPol->GetParameter(1); 393 Double_t gausSigma = gausPol->GetParameter(2); 394 394 po = new TF1("po"+funcName,"pol3(0)", 395 395 -signalRegionFactor*gausSigma+gausMean, … … 455 455 } // pol 456 456 457 doublenOn = 0;458 doubleeNOn = 0;457 Double_t nOn = 0; 458 Double_t eNOn = 0; 459 459 460 460 Int_t binNumberLow = alphaHisto.GetXaxis()->FindBin(lowerBin); … … 469 469 // Evaluate background 470 470 471 doublenOff = 0;472 doubleeNOff = 0;471 Double_t nOff = 0; 472 Double_t eNOff = 0; 473 473 for (Int_t bin=binNumberLow; bin<binNumberHigh+1; bin++) { 474 474 Double_t x = .5*(alphaHisto.GetBinLowEdge(bin)+alphaHisto.GetBinLowEdge(bin+1)); … … 500 500 *fLog << inf << "Significance: "<<sigLiMa<<" sigma "<<endl; 501 501 502 if (draw) { 502 if (draw) { 503 503 TPaveText *pt = new TPaveText(0.11,.74,.57,.88,"NDC "); 504 504 char tx[60]; … … 514 514 pt->Draw(""); 515 515 } 516 517 516 if (draw||drawPad) { 517 518 518 // Plot significance vs alpha_cut 519 519 … … 528 528 529 529 for (Int_t i=0; i < maxBin; i++) { 530 double nOn = 0; doubleeNOn = 0;531 double nOff = 0; doubleeNOff = 0;530 Double_t nOn = 0; Double_t eNOn = 0; 531 Double_t nOff = 0; Double_t eNOff = 0; 532 532 for (Int_t bin=centerBin-i; bin<centerBin+i+1; bin++) { 533 533 nOn += alphaHisto.GetBinContent(bin); … … 802 802 thetaHisto.Fit("expF"); 803 803 804 doubleexpoSlope = e->GetParameter(1);804 Double_t expoSlope = e->GetParameter(1); 805 805 806 806 *fLog << inf << "Determined slope for energy distribution is " 807 807 << expoSlope << endl; 808 808 809 doubleintegralEvts =809 Double_t integralEvts = 810 810 e->Integral(aetHisto->GetYaxis()->GetBinLowEdge(1), 811 811 aetHisto->GetYaxis()->GetBinLowEdge(energyBins+1)); … … 1066 1066 return kTRUE; 1067 1067 } 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 // ----------------------------------------------------------------------- 1122 // 1123 // Extraction of Gamma signal is performed on a TH3D histogram in 1124 // ALPHA, Energy and Theta. Output to parameter list: TH2 histograms 1125 // in energy and Theta. 1126 // 1127 Bool_t MHOnSubtraction::CalcLightCurve(TH3 *aetHisto, MParList *parlist, const Bool_t draw) 1128 { 1129 // Analyze aetHisto 1130 // ------------------------------------- 1131 Int_t alphaBins = aetHisto->GetNbinsX(); 1132 Int_t energyBins = aetHisto->GetNbinsY(); 1133 Int_t timeBins = aetHisto->GetNbinsZ(); 1134 1135 *fLog << "Total events: " << aetHisto->GetEntries() << endl; 1136 *fLog << "Total energy bins: " << energyBins << endl; 1137 *fLog << "Total time bins: " << timeBins << endl; 1138 1139 // We output results in an array of histograms to the parameter list. 1140 // Create a template for such a histogram, needed by MH3 1141 // ------------------------------------- 1142 MBinning *binsmh3x = new MBinning("BinningMH3X"); 1143 // dummy binning, real one follows some lines down 1144 binsmh3x->SetEdges(timeBins,aetHisto->GetZaxis()->GetBinLowEdge(1), 1145 aetHisto->GetZaxis()->GetBinLowEdge(timeBins+1)); 1146 parlist->AddToList(binsmh3x); 1147 1148 MH3 *signalHisto = new MH3(1); // Signal(t) 1149 signalHisto->SetupFill(parlist); 1150 parlist->AddToList(signalHisto); 1151 signalHisto->SetName("MHOnSubtractionSignal"); 1152 signalHisto->SetTitle("Gamma Events"); 1153 1154 MH3 *offHisto = new MH3(1); // Off(t) 1155 offHisto->SetupFill(parlist); 1156 parlist->AddToList(offHisto); 1157 offHisto->SetName("MHOnSubtractionOff"); 1158 offHisto->SetTitle("Background Events"); 1159 1160 MH3 *signifHisto = new MH3(1); // Significance(t) 1161 signifHisto->SetupFill(parlist); 1162 parlist->AddToList(signifHisto); 1163 signifHisto->SetName("MHOnSubtractionSignif"); 1164 signifHisto->SetTitle("Significance"); 1165 1166 TH1D& signalTH1DHist = (TH1D&)signalHisto->GetHist(); 1167 TH1D& offTH1DHist = (TH1D&)offHisto->GetHist(); 1168 TH1D& signifTH1DHist = (TH1D&)signifHisto->GetHist(); 1169 1170 signalTH1DHist.Reset(); 1171 signalTH1DHist.SetTitle("Gamma Signal"); 1172 signalTH1DHist.SetXTitle("Time [MJD]"); 1173 signalTH1DHist.SetYTitle("Events"); 1174 signalHisto->SetBinning(&signalTH1DHist, aetHisto->GetZaxis()); 1175 signalTH1DHist.Sumw2(); 1176 1177 offTH1DHist.Reset(); 1178 offTH1DHist.SetTitle("Background Signal"); 1179 offTH1DHist.SetXTitle("Time [MJD]"); 1180 offTH1DHist.SetYTitle("Events"); 1181 offHisto->SetBinning(&offTH1DHist, aetHisto->GetZaxis()); 1182 offTH1DHist.Sumw2(); 1183 1184 signifTH1DHist.Reset(); 1185 signifTH1DHist.SetTitle("Significance"); 1186 signifTH1DHist.SetXTitle("Time [MJD]"); 1187 signifTH1DHist.SetYTitle("Significance #sigma"); 1188 signifHisto->SetBinning(&signifTH1DHist, aetHisto->GetZaxis()); 1189 signifTH1DHist.Sumw2(); 1190 1191 //The following histogram is an additional histogram needed for 1192 //the light curve 1193 1194 TCanvas *c4 = new TCanvas("c4", "MHOnSubtraction Detailed Result Plots", 800,600); 1195 c4->Divide(8,7,0,0,0); 1196 1197 1198 1199 // The following loop fixes a common integration region for each 1200 // energy bin and alerts when no significant excess is found. 1201 1202 Double_t minLowerBin = -10; // minimum integration range 1203 Double_t maxUpperBin = 10; // minimum integration range 1204 Double_t maxAlpha = 70; // maximum integration range 1205 Double_t sumSigLiMa = 0; 1206 1207 TH1F* alphaHisto[timeBins]; 1208 1209 for (Int_t timeBin = 1; timeBin < timeBins+1; timeBin++) { 1210 1211 *fLog << dbg << "--------------------------------------" << endl; 1212 *fLog << dbg << "Processing ALPHA plots for time bin " << timeBin << endl; 1213 *fLog << dbg << "--------------------------------------" << endl; 1214 1215 aetHisto->GetZaxis()->SetRange(timeBin, timeBin); 1216 1217 char hname[80]; 1218 sprintf(hname, "MHOnSubtractionTimeBin%d", timeBin); 1219 alphaHisto[timeBin-1] = 1220 new TH1F(hname, "ALPHA histogram", 1221 alphaBins,aetHisto->GetXaxis()->GetBinLowEdge(1), 1222 aetHisto->GetXaxis()->GetBinLowEdge(alphaBins+1)); 1223 alphaHisto[timeBin-1]->SetDirectory(NULL); 1224 alphaHisto[timeBin-1]->Sumw2(); 1225 alphaHisto[timeBin-1] = (TH1F*)aetHisto->Project3D("xe"); 1226 alphaHisto[timeBin-1]->SetName(hname); 1227 alphaHisto[timeBin-1]->SetDirectory(NULL); 1228 1229 sprintf(hname, "%6.0f < t < %6.0f", 1230 aetHisto->GetZaxis()->GetBinLowEdge(timeBin), 1231 aetHisto->GetZaxis()->GetBinLowEdge(timeBin+1)); 1232 *fLog << inf << "There are " << alphaHisto[timeBin-1]->GetEntries() 1233 << " entries in " << hname << endl; 1234 alphaHisto[timeBin-1]->SetTitle(hname); 1235 1236 // Find signal region and significance in histogram 1237 Double_t lowerBin, upperBin, sSigLiMa; 1238 char funcName[20]; 1239 sprintf(funcName, "%2d", timeBin); 1240 1241 Bool_t drawFit = kTRUE; 1242 1243 c4->cd(timeBin); 1244 // alphaHisto[timeBin-1]->SetMarkerColor(3); 1245 alphaHisto[timeBin-1]->DrawCopy(); 1246 1247 c4->Update(); 1248 1249 fSigniPlotColor = 0; 1250 ; 1251 Bool_t fit = FitHistogram(*alphaHisto[timeBin-1], sSigLiMa, 1252 lowerBin, upperBin, (Float_t)3.0, drawFit, 1253 funcName); 1254 1255 if (fit) { 1256 if (sSigLiMa < 3) 1257 *fLog << warn << "No significant excess for this bin (sigma="<< sSigLiMa <<")!"<<endl; 1258 sumSigLiMa+=sSigLiMa; 1259 1260 // Evaluate integration range 1261 lowerBin = (lowerBin < -maxAlpha) ? -maxAlpha : lowerBin; 1262 minLowerBin = (lowerBin < minLowerBin) ? lowerBin : minLowerBin; 1263 upperBin = (upperBin > maxAlpha) ? maxAlpha : upperBin; 1264 maxUpperBin = (upperBin > maxUpperBin) ? upperBin : maxUpperBin; 1265 } 1266 1267 1268 1269 1270 1271 1272 } //timeBin 1273 1274 *fLog << inf << "=> Integration range will be " << minLowerBin << " < ALPHA < " 1275 << maxUpperBin << "," << endl; 1276 *fLog << inf << " Summed estimated significance is " << sumSigLiMa << endl; 1277 1278 // we have an idea of what is going on in the ALPHA plot... 1279 // So now we can indeed extract the signal. 1280 1281 sumSigLiMa = 0; 1282 for (Int_t timeBin = 1; timeBin < timeBins+1; timeBin++) { 1283 *fLog << inf << "Processing ALPHA distribution for time bin " << timeBin << endl; 1284 if (alphaHisto[timeBin-1]->GetEntries() == 0) { 1285 *fLog << warn << "No attempt to extract a signal from 0 events." << endl; 1286 if (draw) { 1287 TPaveLabel* lab = new TPaveLabel(0.2,0.4,0.8,0.6,"-(nothing to extract)-"); 1288 lab->SetBorderSize(0); 1289 lab->Draw(); 1290 } 1291 } else { 1292 char funcName[20]; 1293 sprintf(funcName, "%2d", timeBin); 1294 1295 Double_t gammaSignal, errorGammaSignal, off, errorOff, sigLiMa; 1296 1297 Bool_t drawFit = kFALSE; 1298 1299 ExtractSignal(*alphaHisto[timeBin-1], 1300 sigLiMa, minLowerBin, maxUpperBin, 1301 gammaSignal, errorGammaSignal, off, errorOff, (Float_t)3, drawFit, 1302 funcName, NULL, 1/*drawBase*/); 1303 1304 sumSigLiMa += sigLiMa; 1305 1306 fMaxSignif = sigLiMa > fMaxSignif ? sigLiMa : fMaxSignif; 1307 1308 // Fill Signal 1309 TH1D &h = (TH1D&)(signalHisto->GetHist()); 1310 h.SetBinContent(timeBin, gammaSignal); 1311 h.SetBinError(timeBin, errorGammaSignal); 1312 h.SetEntries(h.GetEntries()+gammaSignal); 1313 1314 // Fill Off Events 1315 TH1D &ho = (TH1D&)(offHisto->GetHist()); 1316 ho.SetBinContent(timeBin, off); 1317 ho.SetBinError(timeBin, errorOff); 1318 ho.SetEntries(ho.GetEntries()+off); 1319 1320 // Fill Significance 1321 TH1D &hg = (TH1D&)(signifHisto->GetHist()); 1322 hg.SetBinContent(timeBin, sigLiMa); 1323 hg.SetEntries(hg.GetEntries()+sigLiMa); 1324 } 1325 1326 }//timeBin 1327 1328 *fLog << inf << "Summed significance is " << sumSigLiMa << endl; 1329 1330 1331 if (draw) { 1332 Double_t sigLiMa, lowerBin, upperBin; 1333 FitHistogram(*fSummedAlphaPlots, sigLiMa, lowerBin, upperBin); 1334 fSummedAlphaPlots->SetTitle("Cumulative ALPHA distribution"); 1335 1336 *fLog << inf << "Setting range for Significance histo " << fMaxSignif << endl; 1337 // fSignificanceHisto->GetXaxis()->SetRange(0,fMaxSignif+1); 1338 1339 // *fLog << inf << "Setting range for chisq histo " << fMaxRedChiSq << endl; 1340 // fChiSquareHisto->GetXaxis()->SetRange(0,fMaxRedChiSq+5); 1341 1342 fChiSquareHisto->DrawClone(); 1343 fSignificanceHisto->DrawClone(); 1344 fSummedAlphaPlots->DrawClone(); 1345 } 1346 1347 return kTRUE; 1348 } 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1068 1391 1069 1392
Note:
See TracChangeset
for help on using the changeset viewer.