GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GSPlayerTUI.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "TSpectrum.h"
4 #include "TH1.h"
5 #include "TCanvas.h"
6 #include "KeySymbols.h"
7 #include "TContextMenu.h"
8 #include "TClass.h"
9 
10 #include "BashColor.h"
11 #include "TParameter.h"
12 #include "InnerNDB.h"
13 #include "PadManager.h"
14 #include "TMath.h"
15 #include "TGraphErrors.h"
16 #include "TList.h"
17 #include "TROOT.h"
18 #include "Peak1D.h"
19 #include "PeakCreator.h"
20 
21 #include "GSPlayerTUI.h"
22 
23 using namespace std;
24 using namespace Gw;
25 
29 
30 GSPlayerTUI::GSPlayerTUI(Bool_t verbose) :
31  TTask("GSPlayerTUI","GSPlayerTUI"),
32  fBashColor(new BashColor()),
33  fVerbose(verbose),
34  fNumberIterations(20),
35  fDirection(TSpectrum::kBackDecreasingWindow),
36  fStrDirection("BackDecreasingWindow"),
37  fFilterOrder(TSpectrum::kBackOrder8),
38  fStrFilterOrder("BackOrder8"),
39  fSmoothing(true),
40  fSmoothingWindow(TSpectrum::kBackSmoothing5),
41  fStrSmoothingWindow("BackSmoothing5"),
42  fCompton(true),
43  fRootSP(new RootSpectrumPlayer()),
44  fDataBase(new InnerNDB(verbose)),
45  fCurrentHist(0x0),
46  fSubtractHist(0x0),
47  fBackgroundHist(0x0),
48  fActiveBGAdjustment(false),
49  fActiveIt(false),
50  fActiveFilt(false),
51  fActivSmooth(false),
52  fIsConnected(false),
53  fConnectBSP(false),
54  fFWHMFormula("AGATA_FWHM"),
55  fContextMenu(0x0)
56 {
60 }
61 
63 
64 GSPlayerTUI::GSPlayerTUI(const char* name, const char *title, Bool_t verbose) :
65  TTask(name,title),
66  fBashColor(new BashColor()),
67  fVerbose(verbose),
68  fNumberIterations(20),
69  fDirection(TSpectrum::kBackDecreasingWindow),
70  fStrDirection("BackDecreasingWindow"),
71  fFilterOrder(TSpectrum::kBackOrder8),
72  fStrFilterOrder("BackOrder8"),
73  fSmoothing(true),
74  fSmoothingWindow(TSpectrum::kBackSmoothing5),
75  fStrSmoothingWindow("BackSmoothing5"),
76  fCompton(true),
77  fRootSP(new RootSpectrumPlayer()),
78  fDataBase(new InnerNDB(verbose)),
79  fCurrentHist(0x0),
80  fSubtractHist(0x0),
81  fBackgroundHist(0x0),
82  fActiveBGAdjustment(false),
83  fActiveIt(false),
84  fActiveFilt(false),
85  fActivSmooth(false),
86  fIsConnected(false),
87  fConnectBSP(true),
88  fFWHMFormula("AGATA_FWHM"),
89  fContextMenu(0x0)
90 {
95 }
96 
98 
100 {
101  if(fRootSP) delete fRootSP;
102  if(fDataBase) delete fDataBase;
103  if(fBashColor) delete fBashColor;
104  if(fSubtractHist) delete fSubtractHist;
106 }
107 
109 
110 void GSPlayerTUI::Exec(const char */*option*/)
111 {
112 }
113 
115 
116 void GSPlayerTUI::DefineBackground(int NumberIterations, int Direction,int FilterOrder,bool Smoothing,int smoothingWindow,bool Compton)
117 {
118  if(NumberIterations==-1)
119  {
120  NumberIterations = fNumberIterations;
121  Direction = fDirection;
122  FilterOrder = fFilterOrder;
123  Smoothing = fSmoothing;
124  smoothingWindow = fSmoothingWindow;
125  Compton = fCompton;
126  }
127 
128  fNumberIterations = NumberIterations;
129 
130  if(Direction == 0)
131  {
132  fDirection = TSpectrum::kBackIncreasingWindow;
133  fStrDirection = "BackIncreasingWindow";
134  }
135  else if(Direction == 1)
136  {
137  fDirection = TSpectrum::kBackDecreasingWindow;
138  fStrDirection = "BackDecreasingWindow";
139  }
140  else
141  {
142  fBashColor->SetWarningOut();
143  cout<<"Direction not valid, possible values :"<<endl;
144  cout<<" 0 ==> BackIncreasingWindow"<<endl;
145  cout<<" 1 ==> BackDecreasingWindow"<<endl;
146  cout<<" Default value is taken : BackDecreasingWindow"<<endl;
147  fDirection = TSpectrum::kBackDecreasingWindow;
148  fBashColor->ResetColor();
149  }
150 
151  if(FilterOrder == 0) fFilterOrder = TSpectrum::kBackOrder2;
152  else if(FilterOrder == 1) fFilterOrder = TSpectrum::kBackOrder4;
153  else if(FilterOrder == 2) fFilterOrder = TSpectrum::kBackOrder6;
154  else if(FilterOrder == 3) fFilterOrder = TSpectrum::kBackOrder8;
155  else
156  {
157  fBashColor->SetWarningOut();
158  cout<<"Filter order not valid, possible values :"<<endl;
159  cout<<" 0 ==> BackOrder2"<<endl;
160  cout<<" 1 ==> BackOrder4"<<endl;
161  cout<<" 2 ==> BackOrder6"<<endl;
162  cout<<" 3 ==> BackOrder8"<<endl;
163  cout<<" Default value is taken : BackOrder8"<<endl;
164  fBashColor->ResetColor();
165  fFilterOrder = TSpectrum::kBackOrder8;
166  }
167 
168  if(fFilterOrder == TSpectrum::kBackOrder2) fStrFilterOrder = "BackOrder2";
169  else if(fFilterOrder == TSpectrum::kBackOrder4) fStrFilterOrder = "BackOrder4";
170  else if(fFilterOrder == TSpectrum::kBackOrder6) fStrFilterOrder = "BackOrder6";
171  else if(fFilterOrder == TSpectrum::kBackOrder8) fStrFilterOrder = "BackOrder8";
172 
173  fSmoothing = Smoothing;
174 
175  if(smoothingWindow<3 || smoothingWindow>15 || !(smoothingWindow & 1))
176  {
177  fBashColor->SetWarningOut();
178  cout<<"Smoothing window not valid, possible values : 3, 5, 7, 9, 11, 13, 15"<<endl;
179  cout<<" Default value is taken : BackSmoothing5"<<endl;
180  fBashColor->ResetColor();
181  smoothingWindow = TSpectrum::kBackSmoothing5;
182  }
183 
184  fSmoothingWindow = smoothingWindow;
185  if(!fSmoothing) fStrSmoothingWindow = "NoSmoothing";
186  else if(fSmoothingWindow == TSpectrum::kBackSmoothing3) fStrSmoothingWindow = "BackSmoothing3";
187  else if(fSmoothingWindow == TSpectrum::kBackSmoothing5) fStrSmoothingWindow = "BackSmoothing5";
188  else if(fSmoothingWindow == TSpectrum::kBackSmoothing7) fStrSmoothingWindow = "BackSmoothing7";
189  else if(fSmoothingWindow == TSpectrum::kBackSmoothing9) fStrSmoothingWindow = "BackSmoothing9";
190  else if(fSmoothingWindow == TSpectrum::kBackSmoothing11) fStrSmoothingWindow = "BackSmoothing11";
191  else if(fSmoothingWindow == TSpectrum::kBackSmoothing13) fStrSmoothingWindow = "BackSmoothing13";
192  else if(fSmoothingWindow == TSpectrum::kBackSmoothing15) fStrSmoothingWindow = "BackSmoothing15";
193 
194  fCompton = Compton;
195 }
196 
198 
200 {
201  fBashColor->SetInfoOut();
202  cout<<endl;
203  cout<<"*********** background parameters ***********"<<endl;
204  cout<<" => Number of iterations : "<<fNumberIterations<<endl;
205  cout<<" => Directtion : "<<fStrDirection<<endl;
206  cout<<" => Filter Order : "<<fStrFilterOrder<<endl;
207  cout<<" => Smoothing : "<<fStrSmoothingWindow<<endl;
208  cout<<" => Compton : "<<fCompton<<endl;
209  cout<<"***********************************************"<<endl<<endl;
210  fBashColor->ResetColor();
211 }
212 
214 
216 {
217  if(!fCurrentHist) return 0x0;
218  if(!fBackgroundHist)
219  {
220  fBashColor->SetErrorOut();
221  cout<<"No background histogram built"<<endl;
222  fBashColor->ResetColor();
223  return 0x0;
224  }
225 
226  fSubtractHist = (TH1*)fCurrentHist->Clone((TString)fCurrentHist->GetName()+ "_NoBG");
227  fSubtractHist->Add(fBackgroundHist,-1.);
228  fSubtractHist->Draw(fCurrentHist->GetDrawOption());
229 
230  gPad->Modified();
231  gPad->Update();
232 
233  return fSubtractHist;
234 }
235 
237 
239 {
240  bool ok;
241 
242  if(fConnectBSP) ok = fRootSP->Connect(c);
243  else ok = true;
244 
245  if(ok)
246  {
247  if(c == 0x0) c = TVirtualPad::Pad()->GetCanvas();
248 
249  if ( c) {
250 
251  c->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
252  "Gw::GSPlayerTUI",
253  this,
254  "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
255 
256  fContextMenu = c->GetContextMenu();
257  }
258 
259  }
260 
262 
263  if(ok && c) fIsConnected = true;
264 
265  return ok;
266 }
267 
269 
271 {
272  bool ok;
273  if(fConnectBSP) ok = fRootSP->Disconnect(c);
274  else ok = true;
275 
276  if(ok)
277  {
278  if(c == 0x0) c = TVirtualPad::Pad()->GetCanvas();
279 
280  if ( c )
281  c->Disconnect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
282  this,
283  "HandleMovement(Int_t, Int_t, Int_t, TObject*)");
284 
285  fContextMenu = 0x0;
286  }
287 
288  if(ok && c) fIsConnected = false;
289 
290  return ok;
291 }
292 
294 
295 void GSPlayerTUI::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *select)
296 {
297 
298  // cout<<endl;
299  // cout<<"LasteventType = "<<fLasteventType<<" ; LasteventX = "<<fLasteventX<<" ; LasteventY = "<<fLasteventY<<endl;
300  // cout<<"eventType = "<<eventType<<" ; eventX = "<<eventX<<" ; eventY = "<<eventY<<" ; ObjectName = "<<select->GetName()<<endl;
301  // cout<<endl;
302 
303  if( eventType == kButton1Up && fLasteventType == kButton1Down)
304  {
305  if(select->InheritsFrom("TH1")) fCurrentHist = (TH1*)select;
306  }
307  if (eventType == kMouseMotion) {
308  // to keep track of the last mouse position
309  fLasteventX = eventX;
310  fLasteventY = eventY;
311  }
312 
313  bool CTRL = ( eventX == eventY-96);
314  EKeySym Key = (EKeySym)eventY;
315 
316  bool LastCTRL = ( fLasteventX == fLasteventY-96);
317  EKeySym LastKey = (EKeySym)fLasteventY;
318 
319 
320  if(eventType == kKeyPress)
321  {
322  if(Key == kKey_e && !CTRL && LastKey == kKey_b && !LastCTRL)
323  EvalBackground();
324  if(Key == kKey_s && !CTRL && LastKey == kKey_b && !LastCTRL)
326  }
327 
329 
330  if(eventType == kKeyPress && !fActiveBGAdjustment)
331  {
332  if(Key == kKey_b && !CTRL && LastKey == kKey_i && !LastCTRL)
333  {
334  InteractiveBGMode(true);
335  fLasteventY = 0;fLasteventX = 0;
336  }
337  }
339  if(eventType == kKeyPress && fActiveBGAdjustment)
340  {
342  if(Key == kKey_i && !CTRL && LastKey == kKey_s && !LastCTRL)
343  {
344  fActiveIt = true; fActiveFilt = false; fActivSmooth = false;
345  fLasteventY = 0;fLasteventX = 0;
346  }
348  if(Key == kKey_f && !CTRL && LastKey == kKey_s && !LastCTRL)
349  {
350  fActiveIt = false; fActiveFilt = true; fActivSmooth = false;
351  fLasteventY = 0;fLasteventX = 0;
352  }
354  if(Key == kKey_s && !CTRL && LastKey == kKey_s && !LastCTRL)
355  {
356  fActiveIt = false; fActiveFilt = false; fActivSmooth = true;
357  fLasteventY = 0;fLasteventX = 0;
358  }
360  if(Key == kKey_c && !CTRL && LastKey == kKey_s && !LastCTRL)
361  {
362  fCompton = !fCompton;
363  EvalBackground();
364  fLasteventY = 0;fLasteventX = 0;
365  }
367  if(Key == kKey_d && !CTRL && LastKey == kKey_s && !LastCTRL)
368  {
370  EvalBackground();
371  fLasteventY = 0;fLasteventX = 0;
372  }
373  }
374 
375  if( (eventType == kWheelUp || eventType == kWheelDown ) && fActiveBGAdjustment && (fActiveIt || fActiveFilt || fActivSmooth))
376  {
377  cout<<eventType<<endl;
378  Int_t value = TMath::Nint((5.5-(int)eventType)*2); //-1 pour down, +1 pour up
379  cout<<value<<endl;
380  if(fActiveIt)
381  {
384  }
385  if(fActiveFilt)
386  {
387  fFilterOrder += value;
388  if(fFilterOrder<=0) fFilterOrder = 0;
389  if(fFilterOrder>=3) fFilterOrder = 3;
390  }
391  if(fActivSmooth)
392  {
393  if(fSmoothing == false && value == 1)
394  {
395  fSmoothingWindow = 3;
396  fSmoothing = true;
397  }
398  else if(fSmoothingWindow == 3 && value == -1)
399  {
400  fSmoothing = false;
401  }
402  else if(fSmoothingWindow == 15 && value == 1) fSmoothingWindow = 15;
403  else
404  {
405  fSmoothingWindow += 2*value;
406  }
407  }
408  EvalBackground();
409  }
410 
412  if(eventY == 0 && eventX == 0 && fActiveBGAdjustment )
413  {
414  InteractiveBGMode(false);
415  fLasteventY = 0;fLasteventX = 0;
416  }
417 
418 
419  if(eventType == kKeyPress)
420  {
421  if(Key == kKey_s && !CTRL && LastKey == kKey_a && !LastCTRL)
422  {
423  TMethod* m = Class()->GetMethodAny("AddSourceFromNDB");
424  if (m != 0x0 && fContextMenu != 0x0)
425  fContextMenu->Action(this, m);
426  fLasteventY = 0;fLasteventX = 0;
427  }
428  if(Key == kKey_l && !CTRL && LastKey == kKey_s && !LastCTRL)
429  {
430  TMethod* m = Class()->GetMethodAny("SavePeakList");
431  if (m != 0x0 && fContextMenu != 0x0)
432  fContextMenu->Action(this, m);
433  fLasteventY = 0;fLasteventX = 0;
434  }
435  if(Key == kKey_l && !CTRL && LastKey == kKey_l && !LastCTRL)
436  {
437  TMethod* m = Class()->GetMethodAny("LoadPeakList");
438  if (m != 0x0 && fContextMenu != 0x0)
439  fContextMenu->Action(this, m);
440  fLasteventY = 0;fLasteventX = 0;
441  }
442 
443  if(Key == kKey_e && !CTRL && LastKey == kKey_p && !LastCTRL)
444  {
446  }
447 
448  if(Key == kKey_r && !CTRL && LastKey == kKey_s && !LastCTRL)
449  {
450  TMethod* m = Class()->GetMethodAny("SetRefpeak");
451  if (m != 0x0 && fContextMenu != 0x0)
452  fContextMenu->Action(this, m);
453  fLasteventY = 0;fLasteventX = 0;
454  }
455  }
456 
458 
459  if(eventType == kKeyPress && Key == kKey_h && !CTRL && LastKey == kKey_p && !LastCTRL)
460  {
461  fBashColor->SetInfoOut();
462  cout<<endl;
463  cout<<"[GSPlayerTUI] List of keybord commands:"<<endl;
464  cout<<" ** Print this help : p + h"<<endl;
465  cout<<endl;
466  cout<<" ** Histogram selection **"<<endl;
467  cout<<" ==> Click on a histogram make it the active histogram (the default one is the first histogram in the list of primitives of the active pad)"<<endl;
468  cout<<endl;
469  cout<<" ** Histogram operations **"<<endl;
470  cout<<" ==> b + e : background evaluation"<<endl;
471  cout<<" ==> b + s : background subtraction"<<endl;
472  cout<<endl;
473  cout<<" ** background operation **"<<endl;
474  cout<<" ==> i + b : Starting interactive background adjustment utility"<<endl;
475  if(fActiveBGAdjustment)
476  {
477  cout<<" If the background adjustment utility is on:"<<endl;
478  cout<<" ==> s + i : active the iterator variations by mouse wheel"<<endl;
479  cout<<" ==> s + f : active the filter order variations by mouse wheel"<<endl;
480  cout<<" ==> s + s : active the Smoothing windowd variations by mouse wheel"<<endl;
481  cout<<" ==> s + c : active/unactive compton"<<endl;
482  cout<<" ==> s + d : change direction (BackDecreasingWindow/BackIncreasingWindow)"<<endl;
483  cout<<" Press Escape key to exit the utility"<<endl;
484  }
485  cout<<endl;
486  cout<<" ** Peaks operations **"<<endl;
487  cout<<" ==> h + m : Hide markers"<<endl;
488  cout<<" ==> s + m : Show markers"<<endl;
489  cout<<" ==> a + s : Adding a gamma source from the nuclear database"<<endl;
490  cout<<" ==> f + a : Open fit all panel menu"<<endl;
491  cout<<" ==> a + p : Add a peak at mouse position"<<endl;
492  cout<<" ==> A + P : Add a peak + background at mouse position"<<endl;
493  cout<<" ==> CTRL ( A + P ) : Add a point to the graphical polyline"<<endl;
494  cout<<" ==> s + l : Save the peaks of the current pad the database"<<endl;
495  cout<<" ==> l + l : Load a peak list from the data base"<<endl;
496  cout<<" ==> c + a : Clear all (peaks + graphical polyline)"<<endl;
497  cout<<" ==> o + m : Open PeakCreator menu"<<endl;
498  cout<<endl;
499  cout<<" ==> c + 0 : Switch Color to default #0"<<endl;
500  cout<<" ==> c + 1 : Switch Color to default #0"<<endl;
501  cout<<" ==> c + 2 : Switch Color to default #0"<<endl;
502  cout<<" ==> c + 3 : Switch Color to default #0"<<endl;
503  cout<<endl;
504  cout<<endl;
505  cout<<" ** efficiency **"<<endl;
506  cout<<" ==> p + e : Plot efficiencies"<<endl;
507  fBashColor->ResetColor();
508  fLasteventY = 0;fLasteventX = 0;
509  }
510 
511  fLasteventType = eventType;
512  fLasteventX = eventX;
513  fLasteventY = eventY;
514  fLastSelectedObj = select;
515 
516 }
517 
518 void GSPlayerTUI::SetRefpeak(Float_t area, Float_t error)
519 {
520  if ( fRootSP->CollectPeaks() == 0 )
521  return;
522 
524 
525  TSeqCollection *PeakList = fRootSP->GetPeakList();
526 
527  BasePeak* peak = 0x0;
528  TIter next(PeakList);
529  while ( (peak = (Gw::BasePeak*)next()) )
530  {
531  if(peak->InheritsFrom("Peak1D"))
532  {
533  Peak1D *peak1D = (Peak1D*)peak;
534  peak1D->SetRefArea(area,error);
535  }
536  }
537 
538  GetPlayer()->GetPeakCreator()->SetRefArea(area,error);
539 }
540 
542 
544 {
545  if(fIsConnected) DisconnectCanvas();
546  if(ison)
547  {
548  fConnectBSP = false;
549  fActiveBGAdjustment = true;
550  fBashColor->SetInfoOut();
551  cout<<"[GSPlayerTUI] Starting background utility"<<endl;
552  cout<<"[GSPlayerTUI] Canvas connexions with other classes are closed for interferences reasons"<<endl;
553  cout<<" ==> s + i : active the iterator variations by mouse wheel"<<endl;
554  cout<<" ==> s + f : active the filter order variations by mouse wheel"<<endl;
555  cout<<" ==> s + s : active the Smoothing windowd variations by mouse wheel"<<endl;
556  cout<<" ==> s + c : active/unactive compton"<<endl;
557  cout<<" ==> s + d : change direction (BackDecreasingWindow/BackIncreasingWindow)"<<endl;
558  cout<<" Press Escape key to exit the utility"<<endl;
559  fBashColor->ResetColor();
560  EvalBackground();
561  }
562  else
563  {
564  fConnectBSP = true;
565  fActiveBGAdjustment = false;
566  fActiveIt = false; fActiveFilt = false; fActivSmooth = false;
567  fBashColor->SetInfoOut();
568  cout<<"[GSPlayerTUI] Ending interactive background adjustment utility !"<<endl;
569  cout<<"[GSPlayerTUI] Canvas connexions with other classes have been restored"<<endl;
570  fBashColor->ResetColor();
571  }
572  ConnectCanvas();
573 }
574 
576 
577 TH1 *GSPlayerTUI::EvalBackground(bool verbose)
578 {
580  if(fCurrentHist == 0x0) return 0x0;
581 
583  if(verbose) PrintBGParameters();
584 
585  TString Option = "same";
586 
587  if(fDirection == TSpectrum::kBackDecreasingWindow) Option += "BackDecreasingWindow";
588  else if(fDirection == TSpectrum::kBackIncreasingWindow) Option += "BackIncreasingWindow";
589 
590  if(fFilterOrder == TSpectrum::kBackOrder2) Option += "BackOrder2";
591  else if(fFilterOrder == TSpectrum::kBackOrder4) Option += "BackOrder4";
592  else if(fFilterOrder == TSpectrum::kBackOrder6) Option += "BackOrder6";
593  else if(fFilterOrder == TSpectrum::kBackOrder8) Option += "BackOrder8";
594 
595  if(!fSmoothing) Option += "nosmoothing";
596  else
597  {
598  if(fSmoothingWindow == TSpectrum::kBackSmoothing3) Option += "BackSmoothing3";
599  else if(fSmoothingWindow == TSpectrum::kBackSmoothing5) Option += "BackSmoothing5";
600  else if(fSmoothingWindow == TSpectrum::kBackSmoothing7) Option += "BackSmoothing7";
601  else if(fSmoothingWindow == TSpectrum::kBackSmoothing9) Option += "BackSmoothing9";
602  else if(fSmoothingWindow == TSpectrum::kBackSmoothing11) Option += "BackSmoothing11";
603  else if(fSmoothingWindow == TSpectrum::kBackSmoothing13) Option += "BackSmoothing13";
604  else if(fSmoothingWindow == TSpectrum::kBackSmoothing15) Option += "BackSmoothing15";
605  else Option += "nosmoothing";
606  }
607  if(fCompton) Option += "Compton";
608 
610 
611  TH1 *OldBG = (TH1*) gPad->GetListOfPrimitives()->FindObject((TString)fCurrentHist->GetName() + "_BG");
612  if(OldBG) delete OldBG;
613 
615 
616  gPad->Modified();
617  gPad->Update();
618 
619  return fBackgroundHist;
620 }
621 
623 
624 void GSPlayerTUI::SetFWHMFormula(TString name)
625 {
626  fFWHMFormula = name;
627  if(fRootSP)
628  {
630  }
631 }
632 
634 
635 void GSPlayerTUI::AddSourceFromNDB(const char *SourceName, double EMin, double IMin, const char *option)
636 {
637  if(gPad == 0x0)
638  {
639  TCanvas *c = ((TCanvas*)((TList*)gROOT->GetListOfClasses())->Last());
640  if(c != 0x0) gPad = c->cd(0);
641  if(gPad == 0x0) return;
642  }
643 
644  TString Opt = option;
645 
646  std::vector < GammaSourceRay* > GammaList = fDataBase->GetGammaSource(SourceName,EMin,0.,Opt);
647 
648  if(GammaList.size()==0)
649  return;
650 
652 
653  if(!gPad->GetListOfPrimitives()->FindObject(fCurrentHist->GetName()))
655 
656 
657  TList *listofPeaks = new TList;
658 
659  GammaSourceRay *PreviousGamma = 0x0;
660 
661  for(unsigned int i=0 ; i<GammaList.size() ; i++)
662  {
663  GammaSourceRay *Gamma = GammaList[i];
664  TString GammaName = Form("%s_%.0lf",Gamma->Emmiter.Data(),Gamma->Energy->GetValue());
665 
666  if(PreviousGamma != 0x0 && TMath::Abs(Gamma->Energy->GetValue()-PreviousGamma->Energy->GetValue())<1)
667  {
668  PreviousGamma->Energy->Set(0.5*(Gamma->Energy->GetValue()+PreviousGamma->Energy->GetValue()));
669  PreviousGamma->Energy->SetError(0.5*sqrt(Gamma->Energy->GetError()*Gamma->Energy->GetError()+PreviousGamma->Energy->GetError()*PreviousGamma->Energy->GetError()));
670 
671  PreviousGamma->Intensity->Set(Gamma->Intensity->GetValue()+PreviousGamma->Intensity->GetValue());
672  PreviousGamma->Intensity->SetError(sqrt(Gamma->Intensity->GetError()*Gamma->Intensity->GetError()+PreviousGamma->Intensity->GetError()*PreviousGamma->Intensity->GetError()));
673  }
674  else
675  {
676  Peak1D *Peak = (Peak1D*)fRootSP->GetPeakCreator()->CreatePeak(Gamma->Energy->GetValue(),"bg;ath");
677  Peak->SetNameTitle(GammaName,GammaName);
678  Peak->SetGammaSourceRay(Gamma);
679 
680  listofPeaks->Add(Peak);
681  }
682 
683  PreviousGamma = Gamma;
684  }
685 
686  const char* tab = "\t";
687 
688  fBashColor->SetInfoOut();
689  cout<<endl;
690  cout<<"************** Gamma source "<<SourceName<<" loaded for EGamma > "<<EMin<<" and I > "<<IMin<<endl;
691  cout<<endl;
692 
693  cout<<"DecayMode"<<tab<<
694  "Daughter"<<tab<<
695  "RadSubType"<<tab<<
696  "LifeTime"<<tab<<
697  "Energy"<<tab<<tab<<
698  "Intensity"<<endl;
699 
700  for(int i=0 ; i<listofPeaks->GetEntries() ; i++)
701  {
702  Peak1D *Peak = (Peak1D*)listofPeaks->At(i);
703 
704  GammaSourceRay *Gamma = Peak->GetGammaSourceRay();
705 
706  if(Gamma->Intensity->GetValue()<IMin)
707  {
708  listofPeaks->Remove(Peak);
709  gPad->GetListOfPrimitives()->Remove(Peak);
710  delete Peak;
711  i--;
712  }
713  else
714  {
715  cout<<Gamma->DecayMode<<tab<<tab<<
716  Gamma->Daughter<<tab<<tab<<
717  Gamma->RadSubType<<tab<<tab<<
718  Gamma->LifeTime->GetValue()<<"("<<
719  Gamma->LifeTime->GetError()<<")"<<tab<<
720  Gamma->Energy->GetValue()<<"("<<
721  Gamma->Energy->GetError()<<")"<<tab<<
722  Gamma->Intensity->GetValue()<<"("<<
723  Gamma->Intensity->GetError()<<")"<<endl;
724  }
725  }
726 
727 
728  cout<<"******************************************************"<<endl<<endl;
729 
730  fBashColor->ResetColor();
731 
732  gPad->Modified();
733  gPad->Update();
734 }
735 
736 
738 
739 void GSPlayerTUI::SavePeakList(const char *ListName)
740 {
741  TString Name = ListName;
742 
743  if ( fRootSP->CollectPeaks() == 0 )
744  return;
745 
747 
748  TSeqCollection *PeakList = fRootSP->GetPeakList();
749 
750  vector <double> Energies;
751 
752  BasePeak* peak = 0x0;
753  // save parameters
754  TIter next(PeakList);
755  while ( (peak = (Gw::BasePeak*)next()) ) {
756  Energies.push_back(peak->GetPosition());
757  }
758 
759  fDataBase->SaveGammaList(Name,Energies);
760 }
761 
763 
764 void GSPlayerTUI::LoadPeakList(const char *ListName, const char* opt)
765 {
766  TString Name = ListName;
767 
768  std::vector <double> Energies = fDataBase->LoadGammaList(Name);
769 
770  for(unsigned int i=0 ; i<Energies.size() ; i++)
771  {
772  double E = Energies[i];
773  TString GammaName = Form("%s_%.0lf",Name.Data(),E);
774 
776 
777  if(!gPad->GetListOfPrimitives()->FindObject(fCurrentHist->GetName()))
779 
781  Peak->SetNameTitle(GammaName,GammaName);
782  }
783 
784  if(Energies.size() == 0)
785  {
786  fBashColor->SetWarningOut();
787  cout<<"Empty gamma list !"<<endl;
788  fBashColor->ResetColor();
789  }
790 
791  gPad->Modified();
792  gPad->Update();
793 }
794 
796 {
797 
798  if ( fRootSP->CollectPeaks() == 0 )
799  return;
800 
802 
803  TSeqCollection *PeakList = fRootSP->GetPeakList();
804 
805  TGraphErrors *gr = new TGraphErrors;
806  gr->SetName("EfficiencyPlot");
807  gr->SetMarkerStyle(20);
808  gr->SetMarkerColor(kRed);
809 
810  BasePeak* peak = 0x0;
811  TIter next(PeakList);
812  while ( (peak = (Gw::BasePeak*)next()) )
813  {
814  if(peak->InheritsFrom("Peak1D"))
815  {
816  Peak1D *peak1D = (Peak1D*)peak;
817 
818  if(peak1D->IsAGammaSourceRay())
819  {
820  Float_t Area = peak1D->GetPeakIntegral();
821  Float_t AreaError = peak1D->GetPeakIntegralError();
822  Float_t BranchingRatio = peak1D->GetGammaSourceRay()->Intensity->GetValue();
823  Float_t BranchingRatioError = peak1D->GetGammaSourceRay()->Intensity->GetError();
824 
825  Float_t Energy = peak1D->GetGammaSourceRay()->Energy->GetValue();
826  Float_t EnergyError = peak1D->GetGammaSourceRay()->Energy->GetError();
827 
828 
829  cout<<"Source Information: "<<peak1D->GetGammaSourceRay()->Emmiter<<endl;
830  cout<<"Energy = "<<Energy<< "("<<EnergyError<<")"<<endl;
831  cout<<"BranchingRatio = "<<BranchingRatio<< "("<<BranchingRatioError<<")"<<endl;
832  cout<<"Area = "<<Area<< "("<<AreaError<<")"<<endl;
833 
834  gr->SetPoint(gr->GetN(),Energy,Area/(BranchingRatio/100.));
835  gr->SetPointError(gr->GetN()-1,EnergyError,AreaError/(BranchingRatio/100.));
836  }
837  }
838  }
839 
840  new TCanvas("EfficiencyPlot","EfficiencyPlot");
841  gr->Draw("ap");
842 }
843 
844 
845 
void SetDefaultPeakFWHM(const char *fname="PCG_FWHM")
virtual Data_T GetError() const
return the error on the measured value
Definition: Measure.h:109
virtual Double_t GetPosition(Option_t *axis="X") const =0
Get position of peak.
Int_t fLasteventType
Definition: GSPlayerTUI.h:55
header file for PeakCreator.cpp
void PrintBGParameters()
******************************************************************************************/// ...
GSPlayerTUI(Bool_t verbose=true)
*/
Definition: GSPlayerTUI.cpp:30
RootSpectrumPlayer class to handle root spectra using the interface of BasePeak.
virtual void SortPeakList(const Char_t *parName="Position", Bool_t sortDes=false)
sort peak list
virtual void Set(Data_T data)
set the measure and its error (default err=0)
Definition: Measure.h:66
LogMessage & error(LogMessage &)
void SetFWHMFormula(TString name)
******************************************************************************************/// ...
Gw::InnerNDB * fDataBase
Definition: GSPlayerTUI.h:65
header file for PadManager.cpp
void InteractiveBGMode(bool ison)
******************************************************************************************/// ...
TH1 * RemoveBackground()
******************************************************************************************/// ...
TString fFWHMFormula
Definition: GSPlayerTUI.h:83
void SetRefArea(Float_t a, Float_t ea)
Definition: PeakCreator.h:61
GammaSourceRay * GetGammaSourceRay()
Definition: Peak1D.h:393
TString fStrSmoothingWindow
Definition: GSPlayerTUI.h:48
void SetRefArea(Float_t a, Float_t ea)
Definition: Peak1D.h:408
Measure< Double_t > * LifeTime
Definition: NDB.h:51
virtual void SetNbIter(int nbiter)
Bool_t Disconnect(TCanvas *c=0x0)
Connect the Canvas to this to collect events.
void SetRefpeak(Float_t area, Float_t error)
UInt_t value[MaxValue]
Definition: ReadDaqAlone.C:29
Double_t GetPeakIntegral() const
Get integral of peak after calling area method.
Definition: Peak1D.h:261
void Peak()
Definition: Peak.C:3
TH1 * fBackgroundHist
Definition: GSPlayerTUI.h:71
virtual void SetHelpsPrintActive(bool on)
Definition: PeakCreator.h:95
TString Emmiter
Definition: NDB.h:46
TH1 * fCurrentHist
Definition: GSPlayerTUI.h:69
virtual void SetHelpsPrintActive(bool on)
virtual PeakCreator * GetPeakCreator()
TContextMenu * fContextMenu
context menu in canvas
Definition: GSPlayerTUI.h:89
void LoadPeakList(const char *ListName, const char *opt="bg;ath")
******************************************************************************************/// ...
void Collect(Bool_t do_collect=true)
if true, peak are collected on key board actions (type h for help)
void HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *select)
******************************************************************************************/// ...
TString DecayMode
Definition: NDB.h:48
bool ConnectCanvas(TCanvas *c=0x0)
******************************************************************************************/// ...
RootSpectrumPlayer * fRootSP
Definition: GSPlayerTUI.h:63
std::vector< Gw::GammaSourceRay * > GetGammaSource(TString SourceName, double EMin=100., double IMin=1., TString Opt="")
Definition: InnerNDB.cpp:152
Measure< Double_t > * Energy
Definition: NDB.h:52
TString fStrFilterOrder
Definition: GSPlayerTUI.h:41
ClassImp(BaseNucleus)
header file for a general 1D peak
TH1 * EvalBackground(bool verbose=true)
******************************************************************************************/// ...
ADF::LogMessage & endl(ADF::LogMessage &log)
virtual TSeqCollection * GetPeakList() const
Return the current collection of peaks.
virtual Int_t CollectPeaks(Option_t *opt="")
Collect the peaks from the current pad.
void PlotEfficiencies()
A BasePeak is defined by a height, intensity and a dimension of the peak.
Definition: BasePeak.h:19
Double_t GetPeakIntegralError() const
Definition: Peak1D.h:262
Measure< Double_t > * Intensity
Definition: NDB.h:53
TString Daughter
Definition: NDB.h:47
bool IsAGammaSourceRay()
Definition: Peak1D.h:392
virtual TH1 * Background(const TH1 *histo, Option_t *opt="")
Compute the background for that histogram.
std::vector< double > LoadGammaList(TString ListName)
Definition: InnerNDB.cpp:260
virtual void Exec(const char *)
******************************************************************************************/// ...
A graphical interface for placing schematic peak onto a 1D histogram with a given position...
Definition: Peak1D.h:79
void SavePeakList(const char *ListName="AX")
******************************************************************************************/// ...
TObject * fLastSelectedObj
Definition: GSPlayerTUI.h:58
bool DisconnectCanvas(TCanvas *c=0x0)
******************************************************************************************/// ...
TH1 * fSubtractHist
Definition: GSPlayerTUI.h:70
static TH1 * GetHisto(TVirtualPad *pad=0x0, Option_t *op="")
look for an histogram into the pad
Definition: PadManager.cpp:67
void SaveGammaList(TString ListName, std::vector< double > Energies)
Definition: InnerNDB.cpp:240
void DefineBackground()
Definition: GSPlayerTUI.h:99
virtual ~GSPlayerTUI()
******************************************************************************************/// ...
Definition: GSPlayerTUI.cpp:99
TString RadSubType
Definition: NDB.h:49
void SetGammaSourceRay(GammaSourceRay *gsr)
Definition: Peak1D.h:394
RootSpectrumPlayer * GetPlayer()
Definition: GSPlayerTUI.h:64
Bool_t Connect(TCanvas *c=0x0)
Connect the Canvas to this to collect events.
virtual void SetError(Data_T derr)
set the error of this value
Definition: Measure.h:111
TString fStrDirection
Definition: GSPlayerTUI.h:37
virtual BasePeak * CreatePeak(const TH1 *h, Double_t x, Option_t *opt="")
It creates a peak at position x for the 1D spectra.
void AddSourceFromNDB(const char *SourceName, double EMin=100., double IMin=1., const char *option="")
******************************************************************************************/// ...
Data_T GetValue() const
get the value, cannot be overloaded
Definition: Data.h:114