23 #include <Riostream.h>
26 #ifndef ROOT_KeySymbols
27 #include "KeySymbols.h"
38 #ifndef ROOT_TContextMenu
39 #include "TContextMenu.h"
70 #ifndef Gw_PeakCreator
74 #ifndef Gw_BaseSpectrumPlayer
85 : TNamed(
"SpectrumPlayer",
"Player for spectra"),
91 fIsHelpsPrintActive(true),
93 fLog(
"BaseSpectrumPlayer")
98 fInnerPeakList =
new TList(); fInnerPeakList->SetOwner(
true);
99 fPeakList = fInnerPeakList;
111 fInnerPeakList->Delete();
113 {
delete fInnerPeakList; fInnerPeakList = 0x0; }
122 if ( h->GetDimension() != 1) {
128 Int_t firstBin = h->GetXaxis()->GetFirst();
129 Int_t lastBin = h->GetXaxis()->GetLast();
131 Float_t low = h->GetBinCenter(firstBin);
132 Float_t high = h->GetBinCenter(lastBin);
138 fLog <<
info << Form(
"Peak %s not fitted cos out of zoom", peak->GetName()) <<
dolog;
148 TCanvas *localCanvas = canvas;
151 if ( canvas == 0x0 ) {
152 if ( TVirtualPad::Pad() )
153 localCanvas = TVirtualPad::Pad()->GetCanvas();
162 localCanvas->Connect(
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
163 "Gw::BaseSpectrumPlayer",
165 "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
183 return localCanvas != 0x0;
192 TCanvas *localCanvas = canvas;
195 if ( canvas == 0x0 ) {
196 if ( TVirtualPad::Pad() )
197 localCanvas = TVirtualPad::Pad()->GetCanvas();
203 if (localCanvas->Disconnect(
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
205 "HandleMovement(Int_t, Int_t, Int_t, TObject*)"))
217 return localCanvas != 0x0;
229 if( eventType == kKeyPress) {
231 Int_t keysym = eventY;
233 if((EKeySym)eventY == kKey_a && (EKeySym)eventX == kKey_a && (EKeySym)fLastY == kKey_f && (EKeySym)fLastX == kKey_f)
236 if((EKeySym)eventY == kKey_m && (EKeySym)eventX == kKey_m && (((EKeySym)fLastY == kKey_s && (EKeySym)fLastX == kKey_s) || ((EKeySym)fLastY == kKey_h && (EKeySym)fLastX == kKey_h)))
238 if(TVirtualPad::Pad() == 0x0)
return;
239 TList *list = TVirtualPad::Pad()->GetListOfPrimitives();
240 if(list==0x0)
return;
242 for(
int i=0 ; i<list->GetSize() ; i++)
244 TObject *o = list->At(i);
245 if(o->InheritsFrom(
"Gw::Peak1D"))
261 if ( (EKeySym)keysym == kKey_h && fIsHelpsPrintActive) {
263 fLog <<
"\tf + a: pop up fit panel menu" <<
nline;
268 fLastX = eventX; fLastY = eventY;
276 TMethod* m = Class()->GetMethod(
"FitAll",
"");
297 TString FuncName = nameFunc;
299 TString BackOpt = optBkg;
302 if(FuncName ==
"DTGaus" && BackOpt.Contains(
"Step"))
304 FuncName =
"DTGaus_Step";
308 TList peaks; peaks.SetOwner(
false);
325 if ( h->GetDimension() >= 2) {
332 for (Int_t i = 0; i <
GetPeakList()->GetEntries(); ++i)
335 for (Int_t i = 0; i <
GetPeakList()->GetEntries(); ++i) {
336 if (!IsUsed[i]) IsUsed[i] =
true;
340 if (opt.Contains(
"R") && !
IsInRange(h, peak))
continue;
342 for (Int_t j = i+1; j <
GetPeakList()->GetEntries(); ++j) {
344 if (opt.Contains(
"R") && !
IsInRange(h, peak2))
continue;
355 if (peaks.GetEntries() != 0)
357 if(FuncName ==
"DTGaus_Step")
364 for(
int j=0 ; j<peaks.GetEntries() ; j++)
365 ((
BasePeak*)peaks.At(j))->SetSignalFunction(FuncName,h);
368 peaks.Clear(
"nodelete");
372 peak->
Fit(h,optFit, BackOpt);
376 TIter next(&peaks); TObject *obj;
377 while ( (obj = next()) ) {
394 result->Draw(
"same");
415 col ? fPeakList = col : fPeakList =
dynamic_cast<TSeqCollection*
>(fInnerPeakList);
430 if (strncmp(name,
"DefaultPeak1D", strlen(name)) == 0 && value->InheritsFrom(
"Gw::BasePeak") ) {
478 Bool_t rename =
false;
479 for (Int_t i = 0; i <
GetPeakList()->GetEntries(); ++i) {
481 TString name(peak->GetName());
482 for (Int_t j = i+1; j <
GetPeakList()->GetEntries(); ++j) {
485 if (name.CompareTo(peak2->GetName()) == 0)
490 if (!force && !rename)
return false;
492 TIter next(fPeakList);
493 while ( (peak = (
BasePeak*) next()) ) {
494 peak->SetName( Form(
"%s%d", baseName, k++) );
503 if ( !fPeakList->FindObject(peak) )
504 fPeakList->Add(peak);
514 Int_t n = fPeakList->GetEntries();
516 Int_t* index =
new Int_t[n];
517 Double_t* par =
new Double_t[n];
519 TList*
tmp =
new TList();
520 tmp->SetOwner(
false);
523 TIter next(fPeakList);
525 if (strncmp(parName,
"Position", n) == 0)
527 if (strncmp(parName,
"FWHM", n) == 0)
529 if (strncmp(parName,
"Height", n) == 0)
535 TMath::Sort(n, par, index, sortDes);
538 fPeakList->Clear(
"nodelete");
541 for (i = 0; i < n; ++i ) {
542 peak =
static_cast<BasePeak*
>(tmp->At(index[i]));
543 fPeakList->AddLast(peak);
546 tmp->Clear(
"nodelete");
556 fPeakList->AppendPad();
563 if ( !TVirtualPad::Pad() ) {
570 if ( !opt.Contains(
"+") )
571 fPeakList->Clear(
"nodelete");
573 TObject *obj; Int_t i = 0;
575 TIter next(TVirtualPad::Pad()->GetListOfPrimitives());
576 while ( (obj = next()) ) {
577 if ( obj->InheritsFrom(
"Gw::BasePeak") ) {
578 if (!fPeakList->FindObject(obj)) {
581 fPeakList->Add(obj); i++;
592 fPeakList->Print(opt);
void SetDefaultPeakFWHM(const char *fname="PCG_FWHM")
void SetDefaultPeakFWHM(const char *="PCG_FWHM")
to change the definition of the formula for the width
virtual Double_t GetPosition(Option_t *axis="X") const =0
Get position of peak.
header file for PeakCreator.cpp
virtual TF1 * SetSignalFunction(const char *nameFunc="gaus", TH1 *h=0x0)=0
Set pre-defined function to fit the signal.
virtual void SortPeakList(const Char_t *parName="Position", Bool_t sortDes=false)
sort peak list
virtual void Fit(TH1 *h, Option_t *optFit="RN", Option_t *optBkg="lin")=0
Fit peak with background.
LogMessage & error(LogMessage &)
LogMessage & warning(LogMessage &)
virtual void AddCreatorToList()
virtual void DoBackground(TH1 *histo, Option_t *opt="")
Apply background substraction for that histogram.
BaseSpectrumPlayer to work on spectra.
virtual Bool_t RenamePeak(const Char_t *baseName="Peak", Bool_t force=false)
Sort all peaks and rename them.
LogMessage fLog
log message
BaseSpectrumPlayer()
default constructor
Bool_t Disconnect(TCanvas *c=0x0)
Connect the Canvas to this to collect events.
bool IsDrawAs(EDrawAs mode)
To test the draw mod ex: IsDrawAs(kGate)
LogMessage & nline(LogMessage &)
virtual Double_t GetHeight() const
Get height of peak.
header file for BaseSpectrumPlayer.cpp
virtual Short_t IsPointInBkg(Double_t x, Double_t y=0)=0
to determine if a point is in bg. 0 likely in peak, 1 in bg, 2 outside bg
virtual Int_t FindPeaks(Option_t *opt="")
Find peaks from the histo in the current pad and store them in the current collection.
virtual void PopupFitMenu()
Popup AddLink menu.
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
virtual void FitCombined(TH1 *h, TList *peakList, Option_t *optFit="RN", Option_t *optBkg="lin")=0
Fit multi-defined peak with a common background.
PeakCreator * fCreator
default PeakCreator
TContextMenu * fContextMenu
context menu in canvas
void Collect(Bool_t do_collect=true)
if true, peak are collected on key board actions (type h for help)
LogMessage & dolog(LogMessage &)
virtual ~BaseSpectrumPlayer()
void HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *)
Handle Movement.
Bool_t IsInRange(TH1 *h, BasePeak *peak)
check if peak is in range of drawn spectrum
virtual void SetPeakList(TSeqCollection *col=0x0)
set collection
virtual Double_t GetFWHM(Option_t *axis="X") const =0
Get FWHM of peak.
virtual void Print(Option_t *opt="") const
Print out informations concerning the parameters of that player.
virtual TSeqCollection * GetPeakList() const
Return the current collection of peaks.
virtual void AddPeak(BasePeak *peak)
Add a peak to the current collection (at the end)
virtual Int_t CollectPeaks(Option_t *opt="")
Collect the peaks from the current pad.
A BasePeak is defined by a height, intensity and a dimension of the peak.
static PeakCreator * IsPeakCreator(TVirtualPad *pad=0x0)
Check whether or not a PeakCreator is in this canvas.
virtual void Disconnect()
virtual void FitAll(const char *nameFunc="DTGaus", Option_t *optFit="RN", Option_t *optBkg="Step")
Fit all peaks using the spectrum in the current pad.
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
virtual void ShowPeakList() const
Show the list of peaks on the current pad.
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 TH1 * Background(const TH1 *, Option_t *)
Compute the background for that histogram.
virtual Bool_t SetParameter(const char *, Double_t)
To change the parameters for that algorithm.
Bool_t Connect(TCanvas *c=0x0)
Connect the Canvas to this to collect events.
virtual void SetDrawOption(Option_t *option="")