47 #ifndef ROOT_TPolyMarker
71 #define SigmaToFWHM 2.35482
100 fBkgLevelRight1(0.0),
101 fBkgLevelRight2(0.0),
104 fPeakIntegralError(0.0),
105 fSubPeakIntegral(0.0),
119 fIsAGammaSourceRay(false),
120 fGammaSourceRay(0x0),
122 fEfficiencyGraph(0x0),
123 fEfficiencyFunc(0x0),
171 fBkgLevelRight1(0.0),
172 fBkgLevelRight2(0.0),
175 fPeakIntegralError(0.0),
176 fSubPeakIntegral(0.0),
190 fIsAGammaSourceRay(false),
191 fGammaSourceRay(0x0),
193 fEfficiencyGraph(0x0),
194 fEfficiencyFunc(0x0),
242 fBkgLevelRight1(0.0),
243 fBkgLevelRight2(0.0),
246 fPeakIntegralError(0.0),
247 fSubPeakIntegral(0.0),
255 fMarkerList(new TList()),
261 fIsAGammaSourceRay(false),
262 fGammaSourceRay(0x0),
264 fEfficiencyGraph(0x0),
265 fEfficiencyFunc(0x0),
273 SetPeakPoints(polyline);
303 fPosition(p.fPosition),
305 fBkgLeft1(p.fBkgLeft1),
306 fBkgLeft2(p.fBkgLeft2),
307 fBkgRight1(p.fBkgRight1),
308 fBkgRight2(p.fBkgRight2),
309 fBkgLevelLeft1(p.fBkgLevelLeft1),
310 fBkgLevelLeft2(p.fBkgLevelLeft2),
311 fBkgLevelRight1(p.fBkgLevelRight1),
312 fBkgLevelRight2(p.fBkgLevelRight2),
313 fBkgIntegral(p.fBkgIntegral),
314 fPeakIntegral(p.fPeakIntegral),
315 fPeakIntegralError(p.fPeakIntegralError),
316 fSubPeakIntegral(p.fSubPeakIntegral),
317 fBkgFlag(p.fBkgFlag),
318 fBinWidth(p.fBkgFlag),
320 fIsAGammaSourceRay(p.fIsAGammaSourceRay),
322 fEfficiencyGraph(p.fEfficiencyGraph),
323 fEfficiencyFunc(p.fEfficiencyFunc),
324 fRefArea(p.fRefArea),
325 fRefAreaError(p.fRefArea)
357 ((
Peak1D&)p).fPosition = fPosition;
358 ((
Peak1D&)p).fFWHM = fFWHM;
359 ((
Peak1D&)p).fBkgLeft1 = fBkgLeft1;
360 ((
Peak1D&)p).fBkgLeft2 = fBkgLeft2;
361 ((
Peak1D&)p).fBkgRight1 = fBkgRight1;
362 ((
Peak1D&)p).fBkgRight2 = fBkgRight2;
363 ((
Peak1D&)p).fBkgLevelLeft1 = fBkgLevelLeft1;
364 ((
Peak1D&)p).fBkgLevelLeft2 = fBkgLevelLeft2;
365 ((
Peak1D&)p).fBkgLevelRight1 = fBkgLevelRight1;
366 ((
Peak1D&)p).fBkgLevelRight2 = fBkgLevelRight2;
367 ((
Peak1D&)p).fBkgIntegral = fBkgIntegral;
368 ((
Peak1D&)p).fPeakIntegral = fPeakIntegral;
369 ((
Peak1D&)p).fPeakIntegralError = fPeakIntegralError;
370 ((
Peak1D&)p).fSubPeakIntegral = fSubPeakIntegral;
371 ((
Peak1D&)p).fBkgFlag = fBkgFlag;
375 ((
Peak1D&)p).fEfficiencyGraph = fEfficiencyGraph;
376 ((
Peak1D&)p).fEfficiencyFunc = fEfficiencyFunc;
377 ((
Peak1D&)p).fRefArea = fRefArea;
378 ((
Peak1D&)p).fRefAreaError = fRefAreaError;
387 delete ((
Peak1D&)p).fSigFunc;
388 ((
Peak1D&)p).fSigFunc =
new TF1(*fSigFunc);
390 delete ((
Peak1D&)p).fBkgFunc;
391 ((
Peak1D&)p).fBkgFunc =
new TF1(*fBkgFunc);
393 delete ((
Peak1D&)p).fPeakFunc;
394 ((
Peak1D&)p).fPeakFunc =
new TF1(*fPeakFunc);
396 delete ((
Peak1D&)p).fFitCombined;
397 ((
Peak1D&)p).fFitCombined =
new TF1(*fFitCombined);
403 ((
Peak1D&)p).InitPeakMarkers();
458 if ( x[0] < fBkgLeft1 || x[0] > fBkgRight2 ) {
463 if ( x[0] > fBkgLeft2 && x[0] < fBkgRight1 ) {
475 Double_t f =
fSigFunc->EvalPar(x, par);
485 TString FuncName =
fSigFunc->GetName();
487 if(FuncName.Contains(
"DTGaus") && FuncName.Contains(
"Step"))
497 ::memcpy(allpar,
fSigFunc->GetParameters(),
fSigFunc->GetNpar()*
sizeof(Double_t));
500 TString
tmp = Form(
"SigAndBkg_%p",
this);
506 gROOT->GetListOfFunctions()->Remove(
fPeakFunc);
519 void Peak1D::SetPeak(Double_t position, Double_t height, Double_t FWHM, Double_t intensity)
522 fPosition = position;
533 fPosition =
fSigFunc->GetParameter(3);
535 #if ROOT_VERSION_CODE > ROOT_VERSION(5,34,36)
549 fPosition = position;
581 if ( intensity <= 0.0 )
592 Double_t bgLevelLeft1, Double_t bgLevelLeft2, Double_t bgLevelRight1,Double_t bgLevelRight2)
597 fBkgRight1 = bgRight1;
598 fBkgRight2 = bgRight2;
600 fBkgLevelLeft1 = bgLevelLeft1;
601 fBkgLevelLeft2 = bgLevelLeft2;
602 fBkgLevelRight1 = bgLevelRight1;
603 fBkgLevelRight2 = bgLevelRight2;
609 void Peak1D::SetBackground( Double_t bgLeft1, Double_t bgLeft2, Double_t bgRight1, Double_t bgRight2,
const TH1 *h )
615 h->GetBinContent(h->GetXaxis()->FindFixBin(bgLeft1)),
616 h->GetBinContent(h->GetXaxis()->FindFixBin(bgLeft2)),
617 h->GetBinContent(h->GetXaxis()->FindFixBin(bgRight1)),
618 h->GetBinContent(h->GetXaxis()->FindFixBin(bgRight2)));
622 void Peak1D::ShiftPolyline(TPolyLine &poly, Double_t x, Double_t y)
624 for (Int_t i = 0; i < poly.GetN(); i++) {
631 void Peak1D::SetAllPointsinPolyline(TPolyLine &poly, Double_t x, Double_t y)
633 for (Int_t i = 0; i < poly.GetN(); i++) {
644 for (Int_t i = 0; i <
fMarkerList.GetEntries(); ++i) {
646 m->SetMarkerColor(color);
662 TString name = func->GetParName(0);
664 if (name !=
"height") {
665 fLog <<
error <<
"Wrong name or bad index for parameter 0 (height expected)" <<
nline;
668 name = func->GetParName(1);
670 if (name !=
"position") {
671 fLog <<
error <<
"Wrong name or bad index for parameter 1 (position expected)" <<
nline;
674 name = func->GetParName(2);
676 if (name !=
"fwhm") {
677 fLog <<
error <<
"Wrong name or bad index for parameter 2 (FWHM expected)" <<
nline;
687 TF1 *
tmp =
new TF1(*func);
689 name = Form(
"%s_Sig_%p",func->GetName(),
this);
690 tmp->SetName(name.Data());
693 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,3,4)
694 if ( !tmp->IsValid() ) {
696 if ( tmp->Compile() ) {
707 gROOT->GetListOfFunctions()->Remove(
fSigFunc);
719 Double_t xmin = 0, xmax = 0;
722 TString name = Form(
"%s_Sig_%p",nameFunc,
this);
725 Bool_t do_new_func =
true;
727 if ( name ==
fSigFunc->GetName() ) {
735 if (name.Contains(
"gaus")) {
737 xmin = fPosition - 3*fFWHM; xmax = fPosition + 3*fFWHM;
740 fSigFunc->SetParName(0,
"NumberOfPeaks");
741 fSigFunc->SetParName(1,
"UsingBkg");
743 fSigFunc->SetParName(3,
"Position");
746 fSigFunc->SetBit(TObject::kCannotPick);
747 gROOT->GetListOfFunctions()->Remove(
fSigFunc);
749 else if(name.Contains(
"land"))
751 xmin = fPosition - 3*fFWHM; xmax = fPosition + 10*fFWHM;
755 fSigFunc->SetBit(TObject::kCannotPick);
756 gROOT->GetListOfFunctions()->Remove(
fSigFunc);
758 else if(name.Contains(
"DSCB"))
760 xmin = fPosition - 5*fFWHM; xmax = fPosition + 5*fFWHM;
769 fSigFunc->SetBit(TObject::kCannotPick);
770 gROOT->GetListOfFunctions()->Remove(
fSigFunc);
772 else if(name.Contains(
"DTGaus"))
774 xmin = fPosition - 5*fFWHM; xmax = fPosition + 5*fFWHM;
776 if(name.Contains(
"Step"))
779 fSigFunc->SetParName(7,
"AmplitudeStep");
786 fSigFunc->SetParName(5,
"LeftTail");
787 fSigFunc->SetParName(6,
"RightTail");
789 fSigFunc->SetBit(TObject::kCannotPick);
790 gROOT->GetListOfFunctions()->Remove(
fSigFunc);
801 fSigFunc->SetParName(0,
"NumberOfPeaks");
802 fSigFunc->SetParName(1,
"UsingBkg");
804 fSigFunc->SetParName(3,
"Position");
810 fSigFunc->SetParameter(3, fPosition);
811 fSigFunc->SetParLimits(3, xmin, xmax);
813 fSigFunc->SetParLimits(4, fFWHM/2.,fFWHM*4);
817 if (
fSigFunc && (name.Contains(
"DSCB") ) )
828 else if (
fSigFunc && (name.Contains(
"DTGaus") ) )
836 if(name.Contains(
"Step"))
841 fSigFunc->SetParameter(1, h->GetBinContent(TMath::Min(h->FindBin(fPosition-4*fFWHM),h->FindBin(fPosition+4*fFWHM))));
865 TF1 *
tmp = (TF1*)func->Clone();
866 tmp->SetName(Form(
"%s_Bkg_%p",func->GetName(),
this));
869 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,3,4)
870 if ( !tmp->IsValid() ) {
872 if ( tmp->Compile() ) {
884 fBkgFunc->SetBit(TObject::kCannotPick);
885 gROOT->GetListOfFunctions()->Remove(
fBkgFunc);
899 TString namef = Form(
"%s_Bkg_%p",nameFunc,
this);
903 Bool_t do_new_func =
true;
905 TString
tmp = Form(
"%s_Bkg_%p",
fBkgFunc->GetName(),
this);
907 if ( tmp == namef ) {
913 if ( do_new_func ==
false )
917 if ( namef.Contains(
"cst") || namef.Contains(
"pol0") || ((TString)nameFunc) ==
"" || namef.Contains(
"-") ) {
918 fBkgFunc =
new TF1(namef.Data(),
"pol0", fBkgLeft1, fBkgRight2);
922 if ( namef.Contains(
"lin") || namef.Contains(
"pol1") )
923 fBkgFunc =
new TF1(namef.Data(),
"pol1", fBkgLeft1, fBkgRight2);
925 if ( namef.Contains(
"quad") || namef.Contains(
"pol2") )
926 fBkgFunc =
new TF1(namef.Data(),
"pol2", fBkgLeft1, fBkgRight2);
931 fBkgFunc =
new TF1(namef.Data(), nameFunc, fBkgLeft1, fBkgRight2);
933 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,3,4)
943 fBkgFunc =
new TF1(
"pol0_Bkg",
"pol0", fBkgLeft1, fBkgRight2);
946 <<
"Cannot define " << namef.Data() <<
" , pol0 is set instead" <<
dolog;
948 fBkgFunc->SetBit(TObject::kCannotPick);
949 gROOT->GetListOfFunctions()->Remove(
fBkgFunc);
977 return ( static_cast<TMarker*> (
fMarkerList.At(markerId)) );
986 if ( TVirtualPad::Pad() == 0x0 )
989 if ( TVirtualPad::Pad()->FindObject(
this) == 0x0 )
1002 std::vector<Gw::Peak1D *> allpeaks;
1003 PadManager::Collect<Gw::Peak1D>(allpeaks,TVirtualPad::Pad());
1005 TList peaks; peaks.SetOwner(
false);
1007 for (
size_t i = 0; i < allpeaks.size(); i++) {
1008 if ( allpeaks[i] ==
this )
1011 allpeaks[i]->SetSignalFunction(nameFunc);
1012 peaks.Add(allpeaks[i]);
1015 if ( peaks.GetSize() ) {
1016 fLog <<
" COMBINE called because several peaks are between this peaks limits : # "<< peaks.GetSize() <<
nline;
1020 Fit(h, optFit, optBkg);
1022 TIter next(&peaks); TObject *obj;
1023 while ( (obj = next()) ) {
1033 TString Opt(opt); TH1 *h = 0x0; Short_t choice = 0;
1037 if ( Opt.Contains(
"h") ) {
1042 if ( Opt.Contains(
"f") ) {
1047 if ( Opt.Contains(
"g") ) {
1051 Double_t position = 0.0, sig = 0.0, sig_bg = 0.0, bg1 = 0.0, bg2 = 0.0, bg_sig = 0.0, sig_err=0.;
1056 sig_bg = h->Integral(h->GetXaxis()->FindFixBin(fBkgLeft2),h->GetXaxis()->FindFixBin(fBkgRight1));
1058 bg1 = h->Integral(h->GetXaxis()->FindFixBin(fBkgLeft1),h->GetXaxis()->FindFixBin(fBkgLeft2));
1059 bg2 = h->Integral(h->GetXaxis()->FindFixBin(fBkgRight1),h->GetXaxis()->FindFixBin(fBkgRight2));
1062 Double_t slope = (fBkgLevelLeft2-fBkgLevelLeft1) / (fBkgLeft2-fBkgLeft1);
1063 Double_t offset = fBkgLevelLeft1 - slope*fBkgLeft1;
1068 for (Int_t i = h->GetXaxis()->FindFixBin(fBkgLeft2); i < h->GetXaxis()->FindFixBin(fBkgRight1); i++) {
1070 Double_t bin_cont = h->GetBinContent(i);
1071 Double_t bin_cent = h->GetBinCenter(i);
1073 sig += ( bin_cont - bin_cent*slope - offset );
1074 bg_sig += bin_cent*slope + offset;
1075 position += bin_cont*bin_cent;
1089 #if ROOT_VERSION_CODE > ROOT_VERSION(5,34,36)
1095 sig_err = 2*sqrt(sig);
1105 sig_bg =
fBkgFunc->Integral(fPosition-fFWHM/2., fPosition+fFWHM/2.)/
fBinWidth + sig;
1108 position = fPosition;
1115 sig_bg = h->Integral(h->GetXaxis()->FindFixBin(fPosition-fFWHM/2.),h->GetXaxis()->FindFixBin(fPosition+fFWHM/2.));
1117 bg1 = h->Integral(h->GetXaxis()->FindFixBin(fBkgLeft1),h->GetXaxis()->FindFixBin(fBkgLeft2));
1118 bg2 = h->Integral(h->GetXaxis()->FindFixBin(fBkgRight1),h->GetXaxis()->FindFixBin(fBkgRight2));
1121 Double_t slope = (fBkgLevelLeft2-fBkgLevelLeft1) / (fBkgLeft2-fBkgLeft1);
1122 Double_t offset = fBkgLevelLeft1 - slope*fBkgLeft1;
1127 for (Int_t i = h->GetXaxis()->FindFixBin(fPosition-fFWHM/2.); i < h->GetXaxis()->FindFixBin(fPosition+fFWHM/2.); i++) {
1129 Double_t bin_cont = h->GetBinContent(i);
1130 Double_t bin_cent = h->GetBinCenter(i);
1132 sig += ( bin_cont - bin_cent*slope - offset );
1133 bg_sig += bin_cent*slope + offset;
1134 position += bin_cont*bin_cent;
1148 if ( Opt.Contains(
"v") )
1150 fLog << setw(7)<<
"Mean" <<setw(20)<<
"Area_SIG"<<setw(20)<<
"Area_SIG+BG" <<setw(20)<<
"Area_BG" <<setw(20)<<
"Area_BG_LEFT"<<setw(20)<<
"Area_BG_RIGHT" <<
nline;
1151 fLog <<setprecision(6)<<setw(7)<<position <<setw(20)<<sig <<setw(20)<<sig_bg <<setw(20)<<sig_bg-sig <<setw(20)<<bg1<< setw(20)<<bg2 <<
nline;
1154 fBkgIntegral = bg1+bg2;
1155 fPeakIntegral = sig;
1156 fPeakIntegralError = sig_err;
1157 fSubPeakIntegral = bg_sig;
1169 if ( peakList->GetSize() == 0 )
1173 Bool_t is_signals =
true;
Peak1D *peak;
1175 TIter next(peakList);
1176 while ( (peak = (
Peak1D *)next()) ) {
1185 if ( is_signals ==
false ) {
1186 fLog <<
error <<
"At least one fitting function not defined, use SetSignalFunction() to set it" <<
dolog;
1191 TString obkg(optBkg); TF1 *bkg = 0x0; TH1 *lochist = h;
1196 while ( (peak = (
Peak1D *)next() ) ) {
1201 Bool_t do_bg_fit =
true;
1202 if ( obkg ==
"" || obkg.Contains(
"-") ) {
1204 bkg->SetParameter(0,0.0);
1208 lochist = (TH1*)h->Clone();
1214 bkg =
new TF1(
"Peak_bkg",
this, &
Peak1D::Bkg, h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax(),
fBkgFunc->GetNpar(),
"Peak1D",
"Bkg");
1217 lochist->Fit(bkg,
"RNQ");
1220 fBkgFunc->SetParameters(bkg->GetParameters());
1235 while ( (peak = (
Peak1D *)next() ) ) {
1237 peak->
SetBackground(fBkgLeft1, fBkgLeft2, fBkgRight1, fBkgRight2,
1249 Int_t NPeaks = peakList->GetSize()+1;
1250 Int_t NPar =
fSigFunc->GetNpar()-2;
1252 TString FuncName =
fSigFunc->GetName();
1254 TF1 *f = (TF1*)gROOT->FindObjectAny(Form(
"CombinedPeak_%p",
this));
1255 if(f != 0x0)
delete f;
1257 if(FuncName.Contains(
"gaus"))
1258 fFitCombined =
new TF1(Form(
"CombinedPeak_%p",
this),
this,&
Peak1D::Gaus,fBkgLeft1,fBkgRight2,2+NPar*NPeaks,
"Peak1D",
"Gaus");
1259 else if(FuncName.Contains(
"land"))
1260 fFitCombined =
new TF1(Form(
"CombinedPeak_%p",
this),
this,&
Peak1D::Landau,fBkgLeft1,fBkgRight2,2+NPar*NPeaks,
"Peak1D",
"Landau");
1261 else if(FuncName.Contains(
"DSCB"))
1263 else if(FuncName.Contains(
"DTGaus"))
1267 fLog <<
error <<
"Unkown fit function : "<<FuncName <<
" fit ignored !" <<
dolog;
1279 Int_t which_peak = 0;
1282 while ( which_peak ==0 || (peak = (
Peak1D *)next() ) )
1286 for(
int i=0 ; i<NPar ; i++)
1288 fFitCombined->SetParameter(2+NPar*which_peak+i,PeakFunc->GetParameter(i+2));
1290 PeakFunc->GetParLimits(i+2,min,max);
1291 fFitCombined->SetParLimits(2+NPar*which_peak+i,min,max);
1292 fFitCombined->SetParName(2+NPar*which_peak+i,Form(
"%s_%d",PeakFunc->GetParName(i+2),which_peak));
1298 TString roptFit(optFit);
1299 if ( ! roptFit.Contains(
"N") ) {
1302 if(!roptFit.Contains(
"V"))
1304 if ( !roptFit.Contains(
"Q")) {
1312 if(FuncName.Contains(
"DTGaus"))
1318 while ( which_peak == 0 || (peak = (
Peak1D *)next() ) )
1331 while ( which_peak == 0 || (peak = (
Peak1D *)next() ) )
1334 fFitCombined->SetParLimits(2+NPar*which_peak+3,-50,-0.5);
1338 fFitCombined->SetParLimits(2+NPar*which_peak+4,1.,50.);
1351 if ( roptFit.Contains(
"E") ) IntErr = 2*
fFitCombined->IntegralError(fPosition-4*fFWHM, fPosition+4*fFWHM)/
fBinWidth;
1352 else IntErr = 2*sqrt(TotInt);
1360 while ( which_peak == 0 || (peak = (
Peak1D *)next() ) )
1365 for (Int_t i = 0; i <
fBkgFunc->GetNpar(); i++)
1367 BckFunc->SetParameter(i,
fBkgFunc->GetParameter(i));
1368 BckFunc->SetParError(i,
fBkgFunc->GetParError(i));
1371 PeakFunc->FixParameter(0,1);
1372 PeakFunc->FixParameter(1,0);
1374 Int_t NPar =
fSigFunc->GetNpar()-2;
1375 for(
int i=0 ; i<NPar ; i++)
1377 PeakFunc->SetParameter(i+2,
fFitCombined->GetParameter(2+NPar*which_peak+i));
1378 PeakFunc->SetParError(i+2,
fFitCombined->GetParError(2+NPar*which_peak+i));
1392 if ( !roptFit.Contains(
"Q") )
1412 fLog <<
error <<
"Fitting function not defined, use SetSignalFunction() to set it" <<
dolog;
1417 TString obkg(optBkg); TF1 *bkg = 0x0; TH1 *lochist = h; Int_t nPar =
fSigFunc->GetNpar();
1421 Bool_t do_bg_fit =
true;
1422 if ( obkg ==
"" || obkg.Contains(
"-") ) {
1424 bkg->SetParameter(0,0.0);
1428 lochist = (TH1*)h->Clone();
1437 bkg =
new TF1(
"Peak_bkg",
this, &
Peak1D::Bkg, h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax(),
fBkgFunc->GetNpar(),
"Peak1D",
"Bkg");
1440 lochist->Fit(bkg,
"RNQ");
1443 fBkgFunc->SetParameters(bkg->GetParameters());
1459 TString roptFit(optFit);
1460 if ( ! roptFit.Contains(
"N") ) {
1463 if(!roptFit.Contains(
"V"))
1465 if ( !roptFit.Contains(
"Q")) {
1470 TString namesave =
fSigFunc->GetName();
1472 if(namesave.Contains(
"DTGaus") && namesave.Contains(
"Step"))
1473 fSigFunc->SetRange(fBkgLeft1,fBkgRight2);
1478 if(namesave.Contains(
"DTGaus"))
1484 lochist->Fit(
fSigFunc, roptFit.Data());
1488 fSigFunc->SetParLimits(5,-50,-0.1);
1493 if(namesave.Contains(
"Step"))
1495 fSigFunc->SetParameter(1, h->GetBinContent(TMath::Min(h->FindBin(fPosition-4*fFWHM),h->FindBin(fPosition+4*fFWHM))));
1502 lochist->Fit(
fSigFunc, roptFit.Data());
1504 if(namesave.Contains(
"DTGaus") && namesave.Contains(
"Step"))
1515 fPeakFunc->SetBit(TObject::kCannotPick);
1516 gROOT->GetListOfFunctions()->Remove(
fPeakFunc);
1537 if ( roptFit.Contains(
"E") )
Area(
"fe");
1547 if ( !roptFit.Contains(
"Q") )
1556 if(gPad != 0x0 && !roptFit.Contains(
"0"))
1565 void Peak1D::FitIsWithBkg(TH1* h, Option_t* optFit)
1570 TF1* bkg =
new TF1(
"Bkg",
this, &
Peak1D::Bkg, fBkgLeft1, fBkgRight2, nPar+2,
"Peak1D",
"Bkg");
1571 bkg->FixParameter(nPar, fBkgLeft2);
1572 bkg->FixParameter(nPar+1, fBkgRight1);
1575 for (Int_t i = 0; i < nPar; ++i)
1576 bkg->SetParameter(i,
fBkgFunc->GetParameter(i));
1578 h->Fit(bkg, optFit);
1581 fBkgFunc->SetParameters(bkg->GetParameters());
1582 fBkgLevelLeft2 =
fBkgFunc->Eval(fBkgLeft2);
1583 fBkgLevelRight1 =
fBkgFunc->Eval(fBkgRight1);
1587 TH1* lochist = (TH1*)h->Clone();
1598 if ( Opt.Contains(
"f") ) {
1600 cout << GetName() <<
" Fit results :"<<
endl;
1601 for(
int i=2 ; i<
fSigFunc->GetNpar() ; i++)
1603 if(((TString)
fSigFunc->GetParName(i)) ==
"AmplitudeStep")
1606 cout<<setw(10)<<
fSigFunc->GetParName(i)<<
": "<<setprecision(7)<<setw(10)<<
fSigFunc->GetParameter(i)<<
" ("<<setprecision(7)<<setw(10)<<2*
fSigFunc->GetParError(i)<<
")"<<
endl;
1608 cout<<setw(10)<<
"Area"<<
": "<<setprecision(7)<<setw(10)<<fPeakIntegral<<
" ("<<setprecision(7)<<setw(10)<<fPeakIntegralError<<
")"<<
endl;
1609 if(fEfficiencyGraph != 0x0 || fEfficiencyFunc != 0x0)
1613 if(fEfficiencyFunc != 0x0)
1614 Eval = fEfficiencyFunc->Eval(
fSigFunc->GetParameter(
"Position"));
1616 Eval = fEfficiencyGraph->Eval(
fSigFunc->GetParameter(
"Position"));
1618 Float_t CorrArea = fPeakIntegral/Eval;
1619 Float_t CorrAreaErr = CorrArea*sqrt(fPeakIntegralError/fPeakIntegral*fPeakIntegralError/fPeakIntegral+fEffRelError*fEffRelError);
1620 cout<<
"Efficiency corrected Area "<<CorrArea<<
" +- "<<CorrAreaErr<<
endl;
1624 CorrArea = fPeakIntegral/Eval/fRefArea;
1625 CorrAreaErr = CorrArea*sqrt(fPeakIntegralError/fPeakIntegral*fPeakIntegralError/fPeakIntegral+fRefAreaError/fRefArea*fRefAreaError/fRefArea+fEffRelError*fEffRelError);
1626 cout<<
"Efficiency corrected Area relative to ref"<<CorrArea<<
" +- "<<CorrAreaErr<<
endl;
1635 printf(
"Position: %5.1f FWHM: %5.1f Resolution: %6.2f %%\n", fPosition, fFWHM, 100.*fFWHM/fPosition);
1637 printf(
"Bkg left1: %5.1f Bkg left2: %5.1f Bkg right1: %5.1f Bkg right1: %5.1f\n",
1638 fBkgLeft1, fBkgLeft2, fBkgRight1, fBkgRight2);
1737 if ( !opt.Contains(
"!l") ) {
1751 if ( !opt.Contains(
"!l") )
1768 if ( !opt.Contains(
"!m") ) {
1786 if (tmp.Contains(
"g")) {
1789 if (tmp.Contains(
"p")) {
1800 if (tmp.Contains(
"g")) {
1803 if (tmp.Contains(
"p")) {
1807 TObject::SetDrawOption(opt);
1819 Int_t d1 = TMath::Min(dP, dL);
1820 Int_t d2 = TMath::Min(d1, dR);
1827 if (!gPad->IsEditable())
1860 case kButton1Motion:
1864 case kButton1Double:
1867 fCPolyline->ExecuteEvent(kButton1Down, px, py);
1873 Int_t how_many, which, sign; Double_t deltax, deltay, val;
1882 how_many = which = 0;
1883 for (Int_t i = 0; i <
fCPolyline->GetN() ; i++ ) {
1897 if ( how_many > 2 ) {
1905 if ( val > fBkgLeft2 && val < fBkgRight1 ) {
1937 val =
GetFWHM() + 2*sign*deltax;
1949 if ( how_many > 2 ) {
1953 Bool_t do_move =
false;
2019 return (fPosition > event->GetPosition()) ? 1 : -1;
2023 void Peak1D::SetPeakPoints(TPolyLine* polyline)
2035 for (Int_t i = 1; i < 3; ++i) {
2059 void Peak1D::SetModified(TPolyLine &p, Bool_t modif)
2061 p.SetBit(0x1000,modif);
2065 Bool_t Peak1D::IsModified(TPolyLine &p)
2067 return p.TestBit(0x1000);
2071 void Peak1D::SetPeakPoints()
2076 Double_t x[n], y[n];
2077 Double_t sigma = fFWHM/
SigmaToFWHM; Double_t base = ( fBkgLevelLeft2 + fBkgLevelRight1 )/2.;
2098 x[fgkPeakIdx-1] = fPosition - fFWHM/2.;
2099 y[fgkPeakIdx-1] =
fSigFunc->Eval(x[fgkPeakIdx-1]) +
fBkgFunc->Eval(x[fgkPeakIdx-1]);
2101 x[fgkPeakIdx+1] = fPosition + fFWHM/2.;
2102 y[fgkPeakIdx+1] =
fSigFunc->Eval(x[fgkPeakIdx+1]) +
fBkgFunc->Eval(x[fgkPeakIdx+1]);
2104 x[fgkPeakIdx-2] = fPosition - 2.5*sigma;
2105 x[fgkPeakIdx+2] = fPosition + 2.5*sigma;
2106 x[fgkPeakIdx-3] = fPosition - 3.5*sigma;
2107 x[fgkPeakIdx+3] = fPosition + 3.5*sigma;
2109 y[fgkPeakIdx-2] =
fSigFunc->Eval(x[fgkPeakIdx-2]) +
fBkgFunc->Eval(x[fgkPeakIdx-2]);
2110 y[fgkPeakIdx+2] =
fSigFunc->Eval(x[fgkPeakIdx+2]) +
fBkgFunc->Eval(x[fgkPeakIdx+2]);
2111 y[fgkPeakIdx-3] =
fSigFunc->Eval(x[fgkPeakIdx-3]) +
fBkgFunc->Eval(x[fgkPeakIdx-3]);
2112 y[fgkPeakIdx+3] =
fSigFunc->Eval(x[fgkPeakIdx+3]) +
fBkgFunc->Eval(x[fgkPeakIdx+3]);
2116 x[fgkPeakIdx-2] = fPosition - 2.5*sigma;
2117 x[fgkPeakIdx+2] = fPosition + 2.5*sigma;
2118 x[fgkPeakIdx-3] = fPosition - 3.5*sigma;
2119 x[fgkPeakIdx+3] = fPosition + 3.5*sigma;
2121 y[fgkPeakIdx-2] =
fHeight*4.39e-02 + base;
2122 y[fgkPeakIdx+2] =
fHeight*4.39e-02 + base;
2123 y[fgkPeakIdx-3] =
fHeight*2.187e-03 + base;
2124 y[fgkPeakIdx+3] =
fHeight*2.187e-03 + base;
2129 x[fgkPeakIdx-3] = x[fgkPeakIdx-2] = x[fgkPeakIdx-1];
2130 x[fgkPeakIdx+3] = x[fgkPeakIdx+2] = x[fgkPeakIdx+1];
2131 y[fgkPeakIdx-1] = y[fgkPeakIdx+1] = y[
fgkPeakIdx];
2146 void Peak1D::SetBkgPoints()
2153 Double_t xL[n], yL[n];
2154 Double_t xR[n], yR[n];
2163 yL[1] = fBkgLevelLeft1;
2164 yL[2] = fBkgLevelLeft2;
2173 yR[1] = fBkgLevelRight1;
2174 yR[2] = fBkgLevelRight2;
2186 void Peak1D::UpdatePeak()
2212 void Peak1D::UpdateBkg()
2234 void Peak1D::InitPeakMarkers()
2239 TMarker *m =
new TMarker();
2240 if ( i == fgkPeakIdx )
2241 m->SetMarkerStyle(23);
2243 m->SetMarkerStyle(20);
2256 int NSubPeaks = (int)pp[0];
2257 int UsingBG = (int)pp[1];
2261 if(UsingBG != 0.) f_tot +=
fBkgFunc->Eval(x);
2265 for(
int i=0 ; i<NSubPeaks ; i++)
2267 double Ampli = pp[2+i*Npar+0];
2268 double Mean = pp[2+i*Npar+1];
2269 double Sigma = pp[2+i*Npar+2]*1./sqrt(8.*log(2.));
2271 f_tot += Ampli*exp(-0.5*((x-Mean)/Sigma)*((x-Mean)/Sigma));
2283 int NSubPeaks = (int)pp[0];
2284 int UsingBG = (int)pp[1];
2288 if(UsingBG != 0.) f_tot +=
fBkgFunc->Eval(x);
2292 for(
int i=0 ; i<NSubPeaks ; i++)
2294 double Ampli = pp[2+i*Npar+0];
2295 double Mean = pp[2+i*Npar+1];
2296 double Sigma = pp[2+i*Npar+2]*1./sqrt(8.*log(2.));
2298 f_tot += 8*Ampli*TMath::Log(2)*TMath::Landau(x,Mean,Sigma);
2310 int NSubPeaks = (int)pp[0];
2311 int UsingBG = (int)pp[1];
2315 if(UsingBG != 0.) f_tot +=
fBkgFunc->Eval(x);
2319 for(
int i=0 ; i<NSubPeaks ; i++)
2323 double N = pp[2+i*Npar+0];
2324 double mu = pp[2+i*Npar+1];
2325 double sig = pp[2+i*Npar+2]*1./sqrt(8.*log(2.));
2327 double a1 = pp[2+i*Npar+3];
2328 double p1 = pp[2+i*Npar+4];
2329 double a2 = pp[2+i*Npar+5];
2330 double p2 = pp[2+i*Npar+6];
2332 double u = (x-mu)/sig;
2333 double A1 = TMath::Power(p1/TMath::Abs(a1),p1)*TMath::Exp(-a1*a1/2);
2334 double A2 = TMath::Power(p2/TMath::Abs(a2),p2)*TMath::Exp(-a2*a2/2);
2335 double B1 = p1/TMath::Abs(a1) - TMath::Abs(a1);
2336 double B2 = p2/TMath::Abs(a2) - TMath::Abs(a2);
2339 if (u<-a1) result *= A1*TMath::Power(B1-u,-p1);
2340 else if (u<a2) result *= TMath::Exp(-u*u/2);
2341 else result *= A2*TMath::Power(B2+u,-p2);
2355 int NSubPeaks = (int)pp[0];
2356 int UsingBG = (int)pp[1];
2360 if(UsingBG != 0.) f_tot +=
fBkgFunc->Eval(x);
2364 for(
int i=0 ; i<NSubPeaks ; i++)
2366 double Ampli = pp[2+i*Npar+0];
2367 double Mean = pp[2+i*Npar+1];
2368 double Sigma = pp[2+i*Npar+2]*1./sqrt(8.*log(2.));
2369 double Lambda = pp[2+i*Npar+3];
2370 double Rho = pp[2+i*Npar+4];
2373 double U = (x-Mean)/Sigma;
2374 double f_g = Ampli*TMath::Exp(-U*U*0.5);
2375 double f_lambda = Ampli*TMath::Exp(-0.5*Lambda*(2.*U-Lambda));
2376 double f_rho = Ampli*TMath::Exp(-0.5*Rho*(2.*U-Rho));
2377 double f_S = Ampli*S*1./((1+TMath::Exp(U))*(1+TMath::Exp(U)));
2379 if(U<Lambda) f_tot += f_lambda;
2380 else if(U>Rho) f_tot += f_rho;
2395 int NSubPeaks = (int)pp[0];
2401 Float_t Flat_BackGround = pp[1];
2403 f_tot += Flat_BackGround;
2405 for(
int i=0 ; i<NSubPeaks ; i++)
2407 Float_t Ampli = pp[2+i*Npar+0];
2408 Float_t Mean = pp[2+i*Npar+1];
2409 Float_t Sigma = pp[2+i*Npar+2]*1./sqrt(8.*log(2.));
2410 Float_t Lambda = pp[2+i*Npar+3];
2411 Float_t Rho = pp[2+i*Npar+4];
2412 Float_t S = pp[2+i*Npar+5];
2414 Float_t U = (x-Mean)/Sigma;
2415 Float_t f_g = Ampli*TMath::Exp(-U*U*0.5);
2416 Float_t f_lambda = Ampli*TMath::Exp(-0.5*Lambda*(2.*U-Lambda));
2417 Float_t f_rho = Ampli*TMath::Exp(-0.5*Rho*(2.*U-Rho));
2418 Float_t f_S = Ampli*S*1./((1+TMath::Exp(U))*(1+TMath::Exp(U)));
2420 if(U<Lambda) f_tot += f_lambda;
2421 else if(U>Rho) f_tot += f_rho;
2432 TF1 *f =
new TF1(Name,
"[0]+[1]*[2]*1./((1+TMath::Exp((x-[3])/[4]))*(1+TMath::Exp((x-[3])/[4])))",fBkgLeft1, fBkgRight2);
2433 f->SetParameters(
fSigFunc->GetParameter(1),
2439 f->SetBit(TObject::kCannotPick);
2440 gROOT->GetListOfFunctions()->Remove(f);
virtual Data_T GetError() const
return the error on the measured value
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Handle event in pad.
printf("******************************************************************** \n")
header file for PeakCreator.cpp
virtual void PaintFor(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax)
set attribute to paint this gate on the given histogram
void FitMenu(const char *nameFunc="gaus", Option_t *optFit="RN", Option_t *optBkg="pol1")
Fit with given function and background.
virtual void SetLineColorPeak(Color_t color)
void SetPeak(Double_t pos, Double_t height, Double_t fwhm, Double_t intensity=0)
Set peak members.
LogMessage & error(LogMessage &)
LogMessage & warning(LogMessage &)
double Landau(double *xx, double *pp)
Landau Fonction.
header file for PadManager.cpp
virtual TF1 * SignalAndBkgFunction()
Access to signal+Bkg function. Signa + Bkg must be set first, parameter are copied ! ...
void WithBkg(Bool_t with_bg=true)
toggle background (fit and display)
TPolyLine fCopyPolyline
current polyline
virtual void SetPosition(const Double_t position, Option_t *axis="X")
Set Position of peak.
virtual void SetFWHM(const Double_t FWHM, Option_t *axis="X")
Set FWHM of peak.
static Color_t fgMarkerColor
double Gaus(double *xx, double *pp)
Gaus Fonction.
TF1 * ExtractBkgFromDTGStep(TString Name)
Double_t fIntensity
intensity of the peak
Bool_t IsWithBkg() const
Test if peak defined with background.
virtual void SetFillColorBkg(Color_t color)
Set line attribute for bkg.
LogMessage & nline(LogMessage &)
static Style_t fgFillStylePeak
virtual void SetFillStylePeak(Style_t style)
static void HandleRefresh(TCanvas *canvas=0x0)
Handle modification of the range of the pad.
static const Int_t fgkPointsPeak
pointer to signal+ bkg function
static GateColor gGateColor
Double_t GetPeakIntegral() const
Get integral of peak after calling area method.
UShort_t fDimension
dimension of the peak
virtual Double_t GetHeight() const
Get height of peak.
Double_t SignalAndBkg(Double_t *x, Double_t *par)
functions used to really fit
virtual void EnableFit()
Set flag on to enable fit of the peak.
virtual void Print(Option_t *opt="") const
print current peak
virtual TF1 * PeakFunction()
Access to peak function ... don't delete it !
GammaSourceRay * fGammaSourceRay
Double_t Bkg(Double_t *x, Double_t *par)
void SetPeakIntegralError(Double_t IntErr)
virtual Color_t GetLineColorPeak()
Get line peak color.
virtual void Fit(TH1 *histo, Option_t *optFit="RN", Option_t *optBkg="pol1")
Fit peak with background.
static const Int_t fgkPointsBkg
virtual Double_t GetFWHM(Option_t *axis="X") const
Get FWHM of peak.
TList fMarkerList
current polyline before modification
LogMessage & dolog(LogMessage &)
Double_t fHeight
height of the Peak
virtual void Paint(Option_t *opt="")
Paint method.
virtual TF1 * SignalFunction()
Access to signal function ... don't delete it !
virtual Double_t GetPosition(Option_t *axis="X") const
Get position of peak.
virtual TMarker * GetMarker(Int_t markerId)
Get marker for a given Id.
virtual Bool_t FitFlag() const
Get flag for enable fit.
virtual void Print(Option_t *opt="f") const
Print current peak.
virtual void SetIntensity(const Double_t intensity)
Set intensity of peak.
virtual TF1 * BkgFunction()
Access to signal function ... don't delete it !
void SetHeight(const Double_t height)
Set height of peak.
void SetPeakFromFit()
Set peak members + polyline.
Measure< Double_t > * Energy
virtual void SetLineWidthPeak(Width_t width)
static Color_t fgFuncColor
double DoubleTailedGaussian(double *xx, double *pp)
Double tailed gaussian (Dino like)
static const Int_t fgkPeakIdx
void SetMarkerColor(Int_t color)
Set marker color of the peak polyline.
double DoubleSidedCrystalBallFct(double *xx, double *pp)
Double Sided Crystal Ball Fonction.
header file for a general 1D peak
virtual void SetBinWidth(Double_t width)
BinWidth of the fitted histogram for area correction.
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual void Area(Option_t *opt="h")
to get the Area (+bkg) of this peak
virtual void SetFillStyleBkg(Style_t style)
A BasePeak is defined by a height, intensity and a dimension of the peak.
Measure< Double_t > * Intensity
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance to object.
virtual void SetLineColorBkg(Color_t color)
virtual Int_t Compare(const TObject *obj) const
static Color_t fgLineColorBkg
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
void SetIntensity(const Double_t intensity)
Set Intensity of peak.
virtual void FitCombined(TH1 *histo, TList *peakList, Option_t *optFit="RN", Option_t *optBkg="pol1")
Fit multi-defined peak with a common background.
virtual void SetDrawAs(EDrawAs d)
Set drawing flag.
virtual void SetProcessMethod(const char *)
To set the current method.
static TH1 * GetHisto(TVirtualPad *pad=0x0, Option_t *op="")
look for an histogram into the pad
virtual void SetHeight(const Double_t height)
Set height of peak.
virtual void SetLineWidthBkg(Width_t width)
Short_t IsPointInBkg(Double_t x, Double_t=0)
to determine if a point is in bg. 0 likely in peak, 1 in bg, 2 outside bg
virtual TF1 * SetSignalFunction(const char *nameFunc="gaus", TH1 *h=0x0)
Set pre-defined function to fit the signal.
virtual std::string & GetProcessMethod()
To get the current method.
double DoubleTailedStepedGaussian(double *xx, double *pp)
Double tailed gaussian with step (Dino like)
TF1 * fFitCombined
pointer to signal+ bkg function
virtual void Copy(TObject &o) const
Assignment operator.
virtual TF1 * SetBkgFunction(const char *nameFunc="-")
Set pre-defined function for background during fit.
virtual void Draw(Option_t *opt="")
virtual void SetFillColorPeak(Color_t color)
Set line attribute for peak.
static Style_t fgFillStyleBkg
virtual void SetDrawOption(Option_t *option="")
Data_T GetValue() const
get the value, cannot be overloaded
void SetBackground(Double_t bgLeft1, Double_t bgLeft2, Double_t bgRight1, Double_t bgRight2, Double_t bgLevelLeft1, Double_t bgLevelLeft2, Double_t bgLevelRight1, Double_t bgLevelRight2)
Set background limits.
virtual void Copy(TObject &o) const