23 #include <Riostream.h>
26 #ifndef ROOT_KeySymbols
27 #include "KeySymbols.h"
50 #include "TContextMenu.h"
57 #ifndef Gw_PeakCreator
65 TList PeakCreator::gPeakCreatorList; TF1 *PeakCreator::gDefaultFWHM = 0x0;
70 fEfficiencyGraph(0x0),
77 fDefaultPeakFWHM(0x0),
83 fIsHelpsPrintActive(true),
87 fDefaultPeak1D =
new Peak1D();
95 fEfficiencyGraph(0x0),
102 fDefaultPeakFWHM(0x0),
108 fIsHelpsPrintActive(true),
112 fDefaultPeak1D =
new Peak1D();
117 SetBit(TObject::kMustCleanup);
121 gPeakCreatorList.Add(
this);
135 {
delete fDefaultPeak1D; fDefaultPeak1D = 0x0; }
136 if (fDefaultPeakFWHM)
137 {
delete fDefaultPeakFWHM; fDefaultPeakFWHM = 0x0; }
149 if ( TVirtualPad::Pad() )
150 fCanvas = TVirtualPad::Pad()->GetCanvas();
158 fCanvas->Connect(
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
161 "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
163 fCanvas->Connect(
"Closed()",
176 fCanvas->Disconnect(
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
178 "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
180 fCanvas->Disconnect(
"Closed()",
184 gPeakCreatorList.Remove(
this);
194 return TVirtualPad::Pad();
206 TIter next(&gPeakCreatorList);
208 if ( pcreator->
GetCanvas() == locpad->GetCanvas() )
226 TIter next(&gPeakCreatorList);
228 if ( pcreator->
GetCanvas() == locpad->GetCanvas() ) {
242 PadManager::Collect<BasePeak>(listofpeaks,fCanvas->GetSelectedPad());
243 TIter nextp(&listofpeaks);
244 while ( (obj = nextp()) ) {
245 fCanvas->GetListOfPrimitives()->Remove(obj);
249 PadManager::Collect<TPolyLine>(listofpeaks,fCanvas->GetSelectedPad());
250 TIter nextpo(&listofpeaks);
251 while ( (obj = nextpo()) ) {
252 fCanvas->GetListOfPrimitives()->Remove(obj);
255 TList listoffunctions;
257 PadManager::Collect<TF1>(listoffunctions,fCanvas->GetSelectedPad());
258 TIter nextf(&listoffunctions);
259 while ( (obj = nextf()) ) {
260 fCanvas->GetListOfPrimitives()->Remove(obj);
262 listoffunctions.Clear();
268 fIsCollecting = do_collect;
284 TVirtualPad *pad = fCanvas->GetSelectedPad();
287 if ( !pad->IsEditable() ) {
290 if (eventType == kMouseMotion) {
292 fLastMouseX = eventX;
293 fLastMouseY = eventY;
295 if( eventType == kButton1Up ) {
298 if( eventType == kKeyPress) {
300 bool CTRL = ( eventX == eventY-96);
301 EKeySym Key = (EKeySym)eventY;
303 bool LastCTRL = ( fLastX == fLastY-96);
304 EKeySym LastKey = (EKeySym)fLastY;
306 if(Key == kKey_0 && !CTRL && LastKey == kKey_c && !LastCTRL)
308 fLog <<
info <<
"Current color/style for new peak is now style 0" <<
nline;
312 if(Key == kKey_1 && !CTRL && LastKey == kKey_c && !LastCTRL)
314 fLog <<
info <<
"Current color/style for new peak is now style 1" <<
nline;
318 if(Key == kKey_2 && !CTRL && LastKey == kKey_c && !LastCTRL)
320 fLog <<
info <<
"Current color/style for new peak is now style 2" <<
nline;
324 if(Key == kKey_3 && !CTRL && LastKey == kKey_c && !LastCTRL)
326 fLog <<
info <<
"Current color/style for new peak is now style 3" <<
nline;
330 if(Key == kKey_p && !CTRL && LastKey == kKey_a && !LastCTRL)
332 if ( fIsCollecting ) {
334 if ( peak && pad->GetFrame() )
335 peak->
PaintFor(pad->GetFrame()->GetX1(),pad->GetFrame()->GetX2(),pad->GetFrame()->GetY1(),pad->GetFrame()->GetY2());
339 if(Key == kKey_P && !CTRL && LastKey == kKey_A && !LastCTRL)
341 if ( fIsCollecting ) {
343 if ( peak && pad->GetFrame() )
344 peak->
PaintFor(pad->GetFrame()->GetX1(),pad->GetFrame()->GetX2(),pad->GetFrame()->GetY1(),pad->GetFrame()->GetY2());
348 if(Key == kKey_p && CTRL && LastKey == kKey_a && LastCTRL)
350 if ( fIsCollecting ) {
355 if(Key == kKey_a && !CTRL && LastKey == kKey_c && !LastCTRL)
360 if(Key == kKey_m && !CTRL && LastKey == kKey_o && !LastCTRL)
362 fCanvas->GetContextMenu()->Popup(fLastMouseX,fLastMouseY,
this,fCanvas,pad);
364 if(Key == kKey_h && !CTRL && fIsHelpsPrintActive)
367 fLog <<
"\ta: Add a peak at mouse position" <<
nline;
368 fLog <<
"\tA: Add a peak + background point at mouse position" <<
nline;
369 fLog <<
"\tp: Add a point to the graphical polyline" <<
nline;
370 fLog <<
"\t0: Switch Color to default #0" <<
nline;
371 fLog <<
"\t1: Switch Color to default #1" <<
nline;
372 fLog <<
"\t2: Switch Color to default #2" <<
nline;
373 fLog <<
"\t3: Switch Color to default #3" <<
nline;
374 fLog <<
"\tc: Clear all (peaks + graphical polyline)" <<
nline;
376 fLog <<
"\t>: Popup PeakCreator menu" <<
nline;
377 fLog <<
"\tM: Popup PeakCreator menu" <<
nline;
389 TCanvas *localCanvas = canvas;
392 if ( localCanvas == 0x0 ) {
393 if ( TVirtualPad::Pad() )
394 localCanvas = TVirtualPad::Pad()->GetCanvas();
396 if(localCanvas == 0x0)
return;
397 if(localCanvas->GetSelectedPad() == 0x0)
return;
399 TObject *obj; TFrame *frame;
BasePeak *apeak;
400 double xmin, xmax, ymin, ymax;
403 if ( (frame = localCanvas->GetSelectedPad()->GetFrame()) == 0x0 )
406 xmin = frame->GetX1();
407 xmax = frame->GetX2();
408 ymin = frame->GetY1();
409 ymax = frame->GetY2();
411 if(localCanvas->GetLogy())
413 ymin = TMath::Exp(frame->GetY1()*TMath::Log(10));
414 ymax = TMath::Exp(frame->GetY2()*TMath::Log(10));
416 if(localCanvas->GetLogx())
418 xmin = TMath::Exp(frame->GetX1()*TMath::Log(10));
419 xmax = TMath::Exp(frame->GetX2()*TMath::Log(10));
424 PadManager::Collect<BasePeak>(listofpeaks,localCanvas->GetSelectedPad());
427 TIter next(&listofpeaks);
428 while ( (obj = next()) ) {
429 apeak =
dynamic_cast<BasePeak *
> (obj);
432 apeak->
PaintFor(xmin,xmax,ymin,ymax);
434 localCanvas->GetSelectedPad()->Modified();
437 listofpeaks.Clear(
"nodelete");
442 if ( gROOT->GetListOfFunctions()->FindObject(
"PCG_FWHM") == 0x0 )
444 gDefaultFWHM =
new TF1(
"PCG_FWHM",
"[0]");
445 gDefaultFWHM->SetParameter(0,6.0);
448 if ( gROOT->GetListOfFunctions()->FindObject(
"AGATA_FWHM") == 0x0 )
457 new TF1(
"AGATA_FWHM",Form(
"(%lf-%lf)/(%lf-%lf)*(x-%lf)+%lf",FWHM2,FWHM1,E2,E1,E2,FWHM2));
470 TObject *o = gROOT->GetListOfFunctions()->FindObject(fname); TF1 *f;
474 f =
dynamic_cast<TF1 *
> (o);
476 if ( fDefaultPeakFWHM )
477 delete fDefaultPeakFWHM;
479 fDefaultPeakFWHM = (TF1 *)(f->Clone());
480 gROOT->GetListOfFunctions()->Remove(fDefaultPeakFWHM);
497 std::vector<Gw::Peak1D *> peaks_in_pad;
499 PadManager::Collect<Gw::Peak1D>(peaks_in_pad,locpad);
501 TString pname; Int_t i = 0;
503 pname = Form(
"Peak_%d",i++); Bool_t is_in =
false;
504 for (
size_t i = 0; i < peaks_in_pad.size(); i++) {
505 if ( pname == peaks_in_pad[i]->GetName() ) {
510 if ( is_in ==
false ) {
511 fDefaultPeak1D->SetName( pname.Data() );
520 peak->SetBit(TObject::kCanDelete);
521 peak->SetBit(TObject::kMustCleanup);
524 locpad->GetListOfPrimitives()->Add(peak,
"lm");
540 if (histo->GetDimension() == 0 || histo->GetDimension() > 1) {
542 fLog <<
error <<
"Dimension not handled" << histo->GetDimension() <<
dolog;
545 switch ( histo->GetDimension() ) {
550 fDefaultPeakFWHM->Eval(x);
552 if ( histo->GetXaxis()->GetXmax() < histo->GetXaxis()->GetXmin() + width )
553 width = ( histo->GetXaxis()->GetXmax() - histo->GetXaxis()->GetXmin() ) / 10.;
555 Int_t binmin = histo->GetXaxis()->FindFixBin(x-3*width);
556 Int_t binmax = histo->GetXaxis()->FindFixBin(x+3*width);
559 binmin = TMath::Max(1,binmin);
560 binmax = TMath::Min(histo->GetNbinsX(),binmax);
562 Double_t yminleft, yminright, ymin, ymax, ymax_abs; Int_t bin_ymax, bin_ymax_abs;
564 bin_ymax = bin_ymax_abs = histo->GetXaxis()->FindFixBin(x); ymax = ymax_abs = histo->GetBinContent(histo->GetXaxis()->FindFixBin(x));
566 yminleft = histo->GetBinContent(binmin);
567 yminright = histo->GetBinContent(binmax);
570 for (Int_t i = binmin ; i < binmax; i++) {
572 if ( histo->GetBinCenter(i) < x-width && histo->GetBinContent(i) < yminleft ) {
573 yminleft = histo->GetBinContent(i);
575 if ( histo->GetBinCenter(i) > x+width && histo->GetBinContent(i) < yminright ) {
576 yminright = histo->GetBinContent(i);
579 if ( histo->GetBinContent(i) > ymax && histo->GetBinCenter(i) > (x-0.4*width) && histo->GetBinCenter(i) < (x+0.4*width) )
580 { ymax = histo->GetBinContent(i); bin_ymax = i; }
582 if ( histo->GetBinContent(i) > ymax_abs )
583 { ymax_abs = histo->GetBinContent(i); bin_ymax_abs = i; }
587 if ( (ymax < yminleft || ymax < yminright) && !o.Contains(
"ath") )
600 ymin = (yminleft+yminright)/2;
604 dynamic_cast<Gw::Peak1D*
>(fDefaultPeak1D->Clone());
609 x+5*width, yminleft, yminleft, yminright, yminright );
616 if ( o.Contains(
"atp") )
617 rpeak->
SetPeak(x, ymax-ymin, width);
619 rpeak->
SetPeak(histo->GetBinCenter(bin_ymax), ymax-ymin, width);
621 if ( o.Contains(
"bg") )
626 if(fEfficiencyFunc != 0x0)
628 else if(fEfficiencyGraph != 0x0)
652 TPolyLine* line = 0x0;
653 TList* list = locpad->GetListOfPrimitives();
654 for (Int_t i = 0; i < list->GetEntries(); ++i) {
655 TString
tmp(list->At(i)->ClassName());
656 if (
tmp.CompareTo(
"TPolyLine") == 0 )
657 line = static_cast<TPolyLine*>(list->At(i));
661 line =
new TPolyLine(0);
663 line->SetBit(kCanDelete,
true); line->SetBit(kMustCleanup,
true);
665 line->SetLineWidth(2);
666 line->SetLineColor(kRed-5);
667 line->SetFillColor(kRed-5);
668 line->SetFillStyle(3010);
669 line->SetNextPoint(x,y);
671 locpad->GetListOfPrimitives()->Add(line,
"f");
674 else line->SetNextPoint(x,y);
void SetDefaultPeakFWHM(const char *fname="PCG_FWHM")
header file for PeakCreator.cpp
virtual void SetLineColorPeak(Color_t color)
void SetEfficiencyGraph(TGraph *gr, Float_t EffRelError=0.1)
void SetPeak(Double_t pos, Double_t height, Double_t fwhm, Double_t intensity=0)
Set peak members.
LogMessage & error(LogMessage &)
header file for PadManager.cpp
void WithBkg(Bool_t with_bg=true)
toggle background (fit and display)
void SetRefArea(Float_t a, Float_t ea)
void SetEfficiencyFunc(TF1 *f, Float_t EffRelError=0.1)
LogMessage & nline(LogMessage &)
static PeakCreator * AddPeakCreator(TVirtualPad *pad=0x0)
add a peak creator to the given pad. Current pad if argument is 0x0
static void HandleRefresh(TCanvas *canvas=0x0)
Handle modification of the range of the pad.
void HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *select)
Handle Movement.
static GateColor gGateColor
virtual void PaintFor(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax)=0
Set vis attribute to be painted in the following frame.
const TCanvas * GetCanvas() const
static const TF1 * GetConstGlobalPeakFWHM()
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
static TVirtualPad * PadforAction(TVirtualPad *pad=0x0)
Get Pad.
void SetGateMode(Bool_t ngate=true)
if true, peak are collected on key board actions (type h for help)
void Collect(Bool_t do_collect=true)
if true, peak are collected on key board actions (type h for help)
LogMessage & dolog(LogMessage &)
bool IsDebug(short debug_to_test) const
to test if the required debug level is lower that the global one
virtual void Clear(Option_t *="")
Clear: delete all peaks in canvas/pad depending on PadManager.
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()
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
static TF1 * GetGlobalPeakFWHM()
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 AddPointToPolyline(Double_t x, Double_t y, TVirtualPad *pad=0x0)
It adds a point to the polyline at position x,y in the current pad.
virtual void SetFillColorPeak(Color_t color)
Set line attribute for peak.
virtual BasePeak * CreatePeak(const TH1 *h, Double_t x, Option_t *opt="")
It creates a peak at position x for the 1D spectra.
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.